1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-17 21:49:20 +01:00
slate/Readme.md

148 lines
12 KiB
Markdown
Raw Normal View History

2016-06-28 08:42:38 -07:00
2016-06-28 09:17:55 -07:00
2016-07-12 21:34:31 -07:00
<p align="center"><img src="./docs/banner.png" /></p>
2016-06-28 08:42:38 -07:00
2016-07-06 16:31:28 -07:00
<p align="center">A <em>completely</em> customizable framework <br/>for building rich text editors in the browser.</p>
<br/>
2016-06-28 14:44:46 -07:00
2016-07-13 14:27:02 -07:00
<p align="center"><a href="#why"><strong>Why?</strong></a> · <a href="#principles"><strong>Principles</strong></a> · <a href="#examples"><strong>Examples</strong></a> · <a href="#plugins"><strong>Plugins</strong></a> · <a href="#documentation"><strong>Documentation</strong></a> · <a href="./Contributing.md"><strong>Contributing!</strong></a></p>
2016-07-06 16:31:28 -07:00
<br/>
2016-06-28 08:51:15 -07:00
2016-07-06 16:48:01 -07:00
Slate lets you build rich, intuitive editors like those in [Medium](https://medium.com/), [Dropbox Paper](https://www.dropbox.com/paper) or [Canvas](https://usecanvas.com/)—which are becoming table stakes for applications on the web—without your codebase getting mired in complexity.
2016-07-06 16:45:01 -07:00
2016-07-12 22:37:05 -07:00
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](https://facebook.github.io/react/) and [Immutable](https://facebook.github.io/immutable-js/). It was inspired by libraries like [Draft.js](https://facebook.github.io/draft-js/), [Prosemirror](http://prosemirror.net/) and [Quill](http://quilljs.com/).
2016-06-28 09:28:26 -07:00
2016-07-12 22:57:24 -07:00
_**Slate is currently in beta**. It's useable now, but you might need to pull request a fix or two for advanced use cases._
2016-06-28 08:42:38 -07:00
2016-07-13 14:27:02 -07:00
<br/>
### Why?
2016-07-13 14:30:15 -07:00
Why create Slate? Well... _(Beware: this section has a few of [my](https://github.com/ianstormtaylor) opinions!)_
2016-07-13 14:27:02 -07:00
2016-07-13 14:55:41 -07:00
Before creating Slate, I tried a lot of the other rich text libraries out there. What I found was that while getting simple examples to work might be possible, once you start trying to build something like [Medium](https://medium.com/), [Dropbox Paper](https://www.dropbox.com/paper) or [Canvas](https://usecanvas.com/), you have to resort to very hacky things to get the user experience you want. And some experiences are just impossible. On the way, your codebase becomes harder and harder to maintain.
2016-07-13 14:27:02 -07:00
Here's how Slate compares to some of the existing editors out there:
2016-07-13 14:30:55 -07:00
- [**Draft.js**](https://facebook.github.io/draft-js/) — Slate borrowed a few concepts from Draft.js, namely its event system, its use of Immutable.js and React, and its goal of being a "framework" for creating editors. It also borrowed its plugin-centric design from the [Draft.js Plugins]() project. But the issues I ran into while using Draft.js were: that lots of the logic around the schema is hardcoded in "core" and difficult to customize, that the transform API is complex to use and not suited to collaborative editing in the future, that serialization isn't considered by the core library in a nice way, that the flat document model made certain behaviors impossible, and that lots of the API feels very heavy to work with.
2016-07-13 14:27:02 -07:00
2016-07-13 14:30:55 -07:00
- [**Prosemirror**](http://prosemirror.net/) — Slate borrowed a few concepts from Prosemirror, namely its nested document tree, and its transform model. But the issues I ran into while using it were: that the API is hard to understand, that the codebase wasn't structured around common node module practices, that lots of magic was built into the core library that was hard to customize, that toolbars and buttons are too tied to the editor itself, and that the documentation isn't great. (It's still in beta though!)
2016-07-13 14:27:02 -07:00
2016-07-13 14:30:55 -07:00
- [**Quill**](http://quilljs.com/) — I never used Quill directly, so my hesitations about it are solely from considering it in early stages. The issues I see with it are: that the concept of "toolbars" is too coupled with the editor itself, that the configuration is too coupled to HTML classes and DOM nodes, that the idea of "formats" and "toolbars" being linked is limiting, and generally that too much "core" logic is given special priviledges and is hard to customize.
2016-07-13 14:27:02 -07:00
2016-07-13 14:30:55 -07:00
- [**Trix**](https://trix-editor.org/) — I never used Trix directly either, so my issues with it are solely from considering it in early stages. The issues I found with it are: that it aims to be simple by limiting functionality instead of by limiting its own scope, that many behaviors are just impossible to implement with it, that it's too coupled to the DOM, and that the flat document model is limiting.
2016-07-13 14:27:02 -07:00
2016-07-13 14:32:04 -07:00
Of course those are my own opinions, but if you've tried using any of those libraries you might have run into similar problems. Which brings me to how Slate solves all of that...
2016-07-13 14:27:02 -07:00
2016-07-06 16:35:24 -07:00
<br/>
2016-07-06 16:35:45 -07:00
### Principles
2016-06-28 08:42:38 -07:00
2016-07-13 14:27:02 -07:00
Slate tries to solve the question of "[Why?](#why)" with a few principles:
2016-06-30 10:43:24 -07:00
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 Canvas's without having to fight against the library's assumptions.
2016-06-28 08:42:38 -07:00
2016-06-28 14:51:21 -07:00
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 basic usage.
2016-06-28 09:27:00 -07:00
2016-06-30 10:43:24 -07:00
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 hierachy.
2016-06-28 14:38:05 -07:00
2016-07-12 10:47:48 -07:00
4. **Stateless 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 better performance, and also a much easier time writing plugins.
2016-06-28 14:38:05 -07:00
2016-07-11 12:34:22 -07:00
5. **Intuitive transforms.** Slate's content is edited using "transforms", that are designed to be extremely intuitive to use, so that writing plugins and custom functionality is as simple as possible.
2016-07-12 10:47:48 -07:00
6. **Collaboration-ready data model.** The data model Slate uses—specifically how transforms 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. (More work is required on this!)
2016-06-28 14:38:05 -07:00
2016-07-13 14:33:10 -07:00
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.
2016-07-13 14:27:02 -07:00
2016-06-28 14:38:05 -07:00
2016-07-06 16:35:24 -07:00
<br/>
2016-07-06 16:35:45 -07:00
### Examples
2016-06-28 08:42:38 -07:00
2016-06-28 09:27:00 -07:00
To get a sense for how you might use Slate, check out a few of the examples:
2016-06-28 08:42:38 -07:00
2016-07-12 21:34:31 -07:00
- [**Plain text**](./examples/plain-text) — showing the most basic case: a glorified `<textarea>`.
- [**Rich text**](./examples/rich-text) — showing the features you'd expect from a basic editor.
- [**Auto-markdown**](./examples/auto-markdown) — showing how to add key handlers for Markdown-like shortcuts.
- [**Links**](./examples/links) — showing how wrap text in inline nodes with associated data.
- [**Images**](./examples/images) — showing how to use void (text-less) nodes to add images.
- [**Hovering menu**](./examples/hovering-menu) — showing how a contextual hovering menu can be implemented.
- [**Tables**](./examples/tables) — showing how to nest blocks to render more advanced components.
- [**Paste HTML**](./examples/paste-html) — showing how to use an HTML serializer to handle pasted HTML.
- [**Code Highlighting**](./examples/code-highlighting) — showing how to use decorators to dynamically mark text.
2016-06-28 09:27:00 -07:00
2016-06-28 15:53:10 -07:00
If you have an idea for an example that shows a common use case, pull request it!
2016-06-28 09:27:00 -07:00
2016-07-12 16:46:40 -07:00
<br/>
### Plugins
2016-07-12 16:47:12 -07:00
Slate encourages you to write small, reusable modules. Check out the public ones you can use in your project!
2016-07-12 16:46:40 -07:00
2016-07-13 13:47:14 -07:00
- [`slate-auto-replace-text`](https://github.com/ianstormtaylor/slate-auto-replace-text) auto-replaces a string of text when typed. Useful for "smart" typography!
2016-07-13 13:45:57 -07:00
- [`slate-collapse-on-escape`](https://github.com/ianstormtaylor/slate-collapse-on-escape) simply collapses the selection when `escape` is pressed.
- [`slate-paste-linkify`](https://github.com/ianstormtaylor/slate-paste-linkify) wraps the selected text in a link when a URL is pasted from the clipboard.
2016-07-13 13:49:50 -07:00
- [`slate-soft-break`](https://github.com/ianstormtaylor/slate-soft-break) adds a soft break when `enter` is pressed.
2016-07-13 13:47:14 -07:00
- [**View all plugins...**](https://github.com/ianstormtaylor/slate/wiki)
2016-07-12 16:46:40 -07:00
2016-07-06 16:35:24 -07:00
<br/>
2016-07-06 16:35:45 -07:00
### Documentation
2016-06-28 09:35:51 -07:00
2016-07-08 12:32:49 -07:00
If you're using Slate for the first time, check out the [Getting Started](./docs/guides/installing-slate.md) guides and the [Core Concepts](./docs/concepts) 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](./docs/reference).
2016-06-28 15:53:10 -07:00
2016-07-12 21:34:31 -07:00
- [**Guides**](./docs/guides)
- [Installing Slate](./docs/guides/installing-slate.md)
- [Adding Event Handlers](./docs/guides/adding-event-handlers.md)
- [Defining Custom Block Nodes](./docs/guides/defining-custom-block-nodes.md)
- [Applying Custom Formatting](./docs/guides/applying-custom-formatting.md)
- [Using Plugins](./docs/guides/using-plugins.md)
2016-07-11 12:34:22 -07:00
- Saving to a Database
2016-07-12 21:34:31 -07:00
- Adding a Hovering Menu
- Rendering Adjacent Elements in Components
2016-07-13 14:37:08 -07:00
- Adding Images Using Void Nodes
2016-07-12 21:34:31 -07:00
- [**Concepts**](./docs/concepts)
2016-07-12 22:14:12 -07:00
- [Statelessness & Immutability](./docs/concepts/statelessness-and-immutability.md)
- [The Document Model](./docs/concepts/the-document-model.md)
- [The Selection Model](./docs/concepts/the-selection-model.md)
- [Plugins](./docs/concepts/plugins.md)
2016-07-12 21:34:31 -07:00
- [**Reference**](./docs/reference)
2016-07-12 22:14:12 -07:00
- Components
2016-07-12 21:34:31 -07:00
- [Editor](./docs/reference/components/editor.md)
- [Placeholder](./docs/reference/components/placeholder.md)
2016-07-12 22:14:12 -07:00
- Models
2016-07-12 21:34:31 -07:00
- [Block](./docs/reference/models/block.md)
- [Character](./docs/reference/models/character.md)
- [Data](./docs/reference/data.md)
- [Document](./docs/reference/models/document.md)
- [Inline](./docs/reference/models/inline.md)
- [Mark](./docs/reference/mark.md)
- [Node](./docs/reference/models/node.md)
- [Selection](./docs/reference/models/selection.md)
- [State](./docs/reference/models/state.md)
- [Text](./docs/reference/text.md)
- [Transform](./docs/reference/models/transform.md)
2016-07-12 22:14:12 -07:00
- Plugins
2016-07-12 21:34:31 -07:00
- [Plugins](./docs/reference/plugins/plugins.md)
- [Core](./docs/reference/plugins/core.md)
2016-07-06 16:27:37 -07:00
If even that's not enough, you can always [read the source itself](./lib), which is explained along with a handful of readme's.
2016-07-06 17:22:45 -07:00
2016-07-12 22:28:24 -07:00
<br/>
### Contributing
2016-07-12 22:31:12 -07:00
All contributions are super welcome! Check out the [Contributing instructions](./Contributing.md) for more info!
2016-07-12 22:28:24 -07:00
2016-07-06 17:22:45 -07:00
<br/>
### License
2016-07-12 17:02:42 -07:00
The MIT License
2016-07-06 17:22:45 -07:00
2016-07-12 17:02:42 -07:00
Copyright &copy; 2016, [Ian Storm Taylor](https://ianstormtaylor.com)
2016-07-06 17:22:45 -07:00
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.