0.7.13 • Published 5 years ago

slate-plain-serializer v0.7.13

Weekly downloads
116,817
License
MIT
Repository
github
Last release
5 years ago

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 and Immutable. It was inspired by libraries like Draft.js, Prosemirror and Quill.

🤖 Slate is currently in beta. Its core API is useable now, but you might need to pull request a fix or two for advanced use cases. Some of its APIs are not "finalized" and will (breaking) change over time as we discover better solutions.

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...

  • The editor's "schema" was hardcoded and hard to customize. Things like bold and italic were supported out of the box, but what about comments, or embeds, or even more domain-specific needs?

  • Transforming the documents programmatically was very convoluted. Writing as a user may have worked, but making programmatic changes, which is critical for building advanced behaviors, was needlessly complex.

  • Serializing to HTML, Markdown, etc. seemed like an afterthought. Simple things like transforming a document to HTML or Markdown involved writing lots of boilerplate code, for what seemed like very common use cases.

  • Re-inventing the view layer seemed inefficient and limiting. Most editors rolled their own views, instead of using existing technologies like React, so you have to learn a whole new system with new "gotchas".

  • Collaborative editing wasn't designed for in advance. Often the editor's internal representation of data made it impossible to use to for a realtime, collaborative editing use case without basically rewriting the editor.

  • The repositories were monolithic, not small and reusable. The code bases for many of the editors often didn't expose the internal tooling that could have been re-used by developers, leading to having to reinvent the wheel.

  • Building complex, nested documents was impossible. Many editors were designed around simplistic "flat" documents, making things like tables, embeds and captions difficult to reason about and sometimes impossible.

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—the core editor logic is even implemented as its own plugin. 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 doesn't assume anything 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. Stateless views and immutable data. By using React and Immutable.js, the Slate editor is built in a stateless fashion using immutable data structures, which leads to much easier to reason about code, and a much easier time writing plugins.

  6. Intuitive changes. Slate documents are edited using "changes", 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.

  7. Collaboration-ready data model. The data model Slate uses—specifically how changes 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.

  8. 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:

  • Plain text — showing the most basic case: a glorified <textarea>.
  • Rich text — showing the features you'd expect from a basic editor.
  • Auto-markdown — showing how to add key handlers for Markdown-like shortcuts.
  • Links — showing how wrap text in inline nodes with associated data.
  • Images — showing how to use void (text-less) nodes to add images.
  • Hovering menu — showing how a contextual hovering menu can be implemented.
  • Tables — showing how to nest blocks to render more advanced components.
  • Paste HTML — showing how to use an HTML serializer to handle pasted HTML.
  • Code Highlighting — showing how to use decorations to dynamically mark text.
  • See all the examples...

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

Plugins

Slate encourages you to write small, reusable modules. Check out the public ones you can use in your project!

Documentation

If you're using Slate for the first time, check out the Getting Started walkthroughs and the Guides to familiarize yourself with Slate's architecture and mental models. Once you've gotten familiar with those, you'll probably want to check out the full API Reference.

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:

PackageVersionSizeDescription
slatenpm.ionpm.ioSlate's core data model logic.
slate-base64-serializernpm.ionpm.ioA Base64 string serializer for Slate documents.
slate-html-serializernpm.ionpm.ioAn HTML serializer for Slate documents.
slate-hyperscriptnpm.ionpm.ioA hyperscript tool to write JSX Slate documents!
slate-plain-serializernpm.ionpm.ioA plain text serializer for Slate documents.
slate-prop-typesnpm.ionpm.ioReact prop types for checking Slate values.
slate-reactnpm.ionpm.ioReact components for rendering Slate editors.
slate-hotkeysnpm.ionpm.ioDetect common keypresses in a platform-agnostic way

Contributing!

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

Slate is MIT-licensed.

@bozelljacobs/ext-field-editor-rich-text@usemarkup/markup-text-editor@mkiloyan/renderer-react@infinitebrahmanuniverse/nolb-slat@everything-registry/sub-chunk-2779iruka-rich-text-editor@itoa/fields-contentcustom-react-jsonschema-form-material-uirich-maple-markdowntungtung-super-editortungtung-test-modulelidong-slate-reactmeedan-check-react-jsonschema-form-material-uijfrolich-slate-reactmuxi-slate-reactmarkdown-serializermarkdown-wineory-editor-plugins-slateolymp-slatepdf-embedreact-page-nm-plugins-slatereact-slate-markdownreact-slate-medium-editornetlify-cms-widget-markdownnetlify-cms-widget-markdown-papandreounetlify-cms-widget-markdown-with-underlinenetlify-cms-bitbucketnetlify-cms-runetlify-cms-extendedreact-jsonschema-form-material-uireact-jsonschema-form-advancedquery-fieldslate-code-serializerslate-entity-labelerslate-mention-editorsjq-slate-reactslate-react-zhslate-react-41slate-react-androidslate-react-asslate-react-test2slate-react-tsslate-react-for-kbslate-react-iframeslate-react-legacyslate-react-patch-androidsilk-editorsilk-editor-testskorzh-slate-reacttypebear-test-publish@astrocoders/netlify-cms@alifd/ice-pro-scaffold@alifd/ice-content-editor-block@aykamko/slate-react@blink-mind/plugin-simple-text-editor@blink-mind/renderer-react@canvas-medical/typeahead@citizensadvice/react-rich-text-editor@bonio-tw/slate-reactyuankui-slate-reactxr-widget-markdown@favish/ory-editor-plugins-slate@fernandobandeira/ory-editor-plugins-slate@hdnha11/slate-react@happyiterating/slate-react@forgettingpasswords/netlify-cms-widget-markdown@hugo-team/slate-react@icedesign/content-editor-block@icedesign/cms-scaffold@igloo-be/netlify-cms-widget-markdown@icedesign/scaffold-cms@icedesign/project-management-admin@icedesign/task-management-admin-scaffold@filou/slate@gem-mine/slate@eliumhq/slate-react@grafana/ui@grafarg/ui@grafana/slate-react@ksimons/slate-react@leadsimple/slate-react@lennym/slate-react@makeflow/slate-react@marti.planellas/slate-react@ngx-slate/core@nologis/rich-editor@encrypt-s/netlify-cms@mattkrick/slate-react@keystonejs/fields-content@kancloud/slate-react@karma.run/editor-plugin-slate@kaydelaney/slate-react@jaapfrolich/rich-markdown-editor@jaapfrolich/slate-react@koikorn/field-content@keystone-next/fields-content-legacy@jfrolich/rich-markdown-editor@jfrolich/slate-react@jfrolich/slate-react2@react-jsonschema-form-custom/material-ui-fy2ybeyiz
0.7.13

5 years ago

0.7.12

5 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.39

6 years ago

0.6.38

6 years ago

0.6.37

6 years ago

0.6.36

6 years ago

0.6.35

6 years ago

0.6.34

6 years ago

0.6.33

6 years ago

0.6.32

6 years ago

0.6.31

6 years ago

0.6.30

6 years ago

0.6.29

6 years ago

0.6.28

6 years ago

0.6.27

6 years ago

0.6.26

6 years ago

0.6.25

6 years ago

0.6.24

6 years ago

0.6.23

6 years ago

0.6.22

6 years ago

0.6.21

6 years ago

0.6.20

6 years ago

0.6.19

6 years ago

0.6.18

6 years ago

0.6.17

6 years ago

0.6.16

6 years ago

0.6.15

6 years ago

0.6.14

6 years ago

0.6.13

6 years ago

0.6.12

6 years ago

0.6.11

6 years ago

0.6.10

6 years ago

0.6.9

6 years ago

0.6.8

6 years ago

0.6.7

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.41

6 years ago

0.5.40

6 years ago

0.5.39

6 years ago

0.5.38

6 years ago

0.5.37

6 years ago

0.5.36

6 years ago

0.5.35

6 years ago

0.5.34

6 years ago

0.5.33

6 years ago

0.5.32

6 years ago

0.5.31

6 years ago

0.5.30

6 years ago

0.5.29

6 years ago

0.5.28

6 years ago

0.5.27

6 years ago

0.5.26

6 years ago

0.5.25

6 years ago

0.5.24

6 years ago

0.5.23

6 years ago

0.5.22

6 years ago

0.5.21

6 years ago

0.5.20

6 years ago

0.5.19

6 years ago

0.5.18

6 years ago

0.5.17

7 years ago

0.5.16

7 years ago

0.5.15

7 years ago

0.5.14

7 years ago

0.5.13

7 years ago

0.5.12

7 years ago

0.5.11

7 years ago

0.5.10

7 years ago

0.5.9

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.16

7 years ago

0.4.15

7 years ago

0.4.14

7 years ago

0.4.13

7 years ago

0.4.12

7 years ago

0.4.11

7 years ago

0.4.10

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago