slate README

The project's README from github.com/ianstormtaylor/slate. As one markdown file: README.md.

A completely customizable framework
for building rich text editors.


Why? · Principles · Demo · Examples · Documentation · Contributing!



Slate lets you build rich, intuitive editors like those in Medium, Dropbox Paper or Google Docs—which are becoming table stakes for applications on the web—without your codebase getting mired in complexity.

It can do this because all of its logic is implemented with a series of plugins, so you aren't ever constrained by what is or isn't in "core". You can think of it like a pluggable implementation of contenteditable built on top of React. It was inspired by libraries like Draft.js, Prosemirror and Quill.

🤖 Slate is currently in beta. Its core API is useable right now, but you might need to pull request improvements for advanced use cases, or fixes for some bugs. Some of its APIs are not "finalized" and will have breaking changes over time as we discover better solutions. There isn't currently a 1.0 release schedule, we're still getting the architecture right.

🤖 Slate is also contributor-driven. It is not backed by any huge company, which means that all contributions are voluntary and done by the people who need them. If you need something improved, added, or fixed, please contribute it yourself or no one will. And if you want to become a more active maintainer, let us know in the Slack channel.


Why?

Why create Slate? Well... (Beware: this section has a few of my opinions!)

Before creating Slate, I tried a lot of the other rich text libraries out there—Draft.js, Prosemirror, Quill, etc. What I found was that while getting simple examples to work was easy enough, once you started trying to build something like Medium, Dropbox Paper or Google Docs, you ran into deeper issues...

Of course not every editor exhibits all of these issues, but if you've tried using another editor you might have run into similar problems. To get around the limitations of their API's and achieve the user experience you're after, you have to resort to very hacky things. And some experiences are just plain impossible to achieve.

If that sounds familiar, you might like Slate.

Which brings me to how Slate solves all of that...


Principles

Slate tries to solve the question of "Why?" with a few principles:

  1. First-class plugins. The most important part of Slate is that plugins are first-class entities. That means you can completely customize the editing experience, to build complex editors like Medium's or Dropbox's, without having to fight against the library's assumptions.

  2. Schema-less core. Slate's core logic assumes very little about the schema of the data you'll be editing, which means that there are no assumptions baked into the library that'll trip you up when you need to go beyond the most basic use cases.

  3. Nested document model. The document model used for Slate is a nested, recursive tree, just like the DOM itself. This means that creating complex components like tables or nested block quotes are possible for advanced use cases. But it's also easy to keep it simple by only using a single level of hierarchy.

  4. Parallel to the DOM. Slate's data model is based on the DOM—the document is a nested tree, it uses selections and ranges, and it exposes all the standard event handlers. This means that advanced behaviors like tables or nested block quotes are possible. Pretty much anything you can do in the DOM, you can do in Slate.

  5. Intuitive commands. Slate documents are edited using "commands", that are designed to be high-level and extremely intuitive to write and read, so that custom functionality is as expressive as possible. This greatly increases your ability to reason about your code.

  6. Collaboration-ready data model. The data model Slate uses—specifically how operations are applied to the document—has been designed to allow for collaborative editing to be layered on top, so you won't need to rethink everything if you decide to make your editor collaborative.

  7. Clear "core" boundaries. With a plugin-first architecture, and a schema-less core, it becomes a lot clearer where the boundary is between "core" and "custom", which means that the core experience doesn't get bogged down in edge cases.


Demo

Check out the live demo of all of the examples!


Examples

To get a sense for how you might use Slate, check out a few of the examples:

If you have an idea for an example that shows a common use case, pull request it!


Documentation

If you're using Slate for the first time, check out the Getting Started walkthroughs and the Concepts to familiarize yourself with Slate's architecture and mental models.

If even that's not enough, you can always read the source itself, which is heavily commented.

There are also translations of the documentation into other languages:

If you're maintaining a translation, feel free to pull request it here!


Packages

Slate's codebase is monorepo managed with Lerna. It consists of a handful of packages—although you won't always use all of them. They are:

Package Version Size Description
slate Slate's core data model logic.
slate-history A plugin that adds undo/redo history to Slate.
slate-hyperscript A hyperscript tool to write JSX Slate documents!
slate-react React components for rendering Slate editors.

Contributing!

All contributions are super welcome! Check out the Contributing instructions for more info!

Slate is MIT-licensed.

slate (ianstormtaylor/slate)

Searching Database…

31.7K ·GitHub
这是什么?一个完全可自定义的框架,用来在浏览器里构建富文本编辑器——就是类似 Medium、Dropbox Paper 或 Google Docs 那样的编辑器——它构建在 React 之上,本质上是一个可插拔的 contenteditable。
也就是说它不是拿来就能用的现成编辑器组件?它是一个框架,不是做好的编辑器:所有逻辑都在插件里,核心代码几乎不对你的数据结构做任何预设,所以你可以自由组装自己需要的编辑体验,而不用跟内置的假设较劲。
我怎么把它加到项目里?把 slate 和 slate-react 这两个包添加到你的应用里,然后跟着 Getting Started 入门教程和 Concepts 概念文档走一遍,就能掌握 Slate 的架构和思维方式。
它是不是把我绑死在 React 上?是的——它构建在 React 之上,负责渲染编辑器的 React 组件由 slate-react 包提供,所以基本上必须用 React 技术栈。
它标着 beta——如果我现在就基于它开发,风险有多大?核心 API 现在就能用,但有些 API 还没定型,可能会以不兼容的方式变动,而且 1.0 版本也没有发布时间表。另外它完全靠社区贡献者维护,没有公司支持,高级场景的问题可能得自己动手解决。
既然已经有 Draft.js 和 ProseMirror 了,作者为什么还要做 Slate?在试用过 Draft.js、ProseMirror 和 Quill 之后,他总是撞上同样的问题:写死的数据结构、繁琐的程序化转换、序列化只是事后补上去的、需要自己写视图层,还有扁平的文档模型,让表格和嵌入内容变得很麻烦。
那些示例编辑器都能做什么?这个仓库自带可运行的示例,涵盖纯文本、富文本、Markdown 风格的快捷输入、行内节点、图片、悬浮工具栏、表格、通过 HTML 序列化器粘贴 HTML,以及 @ 提及功能——很好地展示了插件系统能覆盖的范围。
文档在底层是怎么建模的?采用与 DOM 对应的嵌套递归树结构:使用选区(selection)和范围(range),并暴露标准的事件处理器,所以表格、嵌套引用块这类复杂结构都是一等公民。操作(operation)的设计也考虑到了协作编辑,可以在此基础上叠加实现。
这个 monorepo 发布了哪些包,各自是干什么的?四个:slate(核心数据模型逻辑)、slate-react(用于渲染的 React 组件)、slate-history(撤销/重做插件)和 slate-hyperscript(用 JSX 编写 Slate 文档的工具)。
What are similar projects?ckeditor5, plate, lexical, tiptap, tinymce, BlockNote, pell, draft-js
Size
28.9 MB
Stars
31.7K
Age
10y
Commits · 90 Days