mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-03-05 21:49:06 +01:00
#### Is this adding or improving a _feature_ or fixing a _bug_? Feature. #### What's the new behavior? This pull request adds paths to `Range` objects, including the selection. The paths and keys are kept in sync automatically, so that you can use whichever is ideal for your use case. This should allow us to use paths for lots of the internal logic, which are much quicker to work with than keys since they avoid having to lookup the key in the document and can just traverse right to the node in question. #### How does this change work? `Range` objects have two new properties: ```js range.anchorPath range.focusPath ``` (Eventually these will be `range.anchor.path` and `range.focus.path` when points are introduced.) When operations occur and whenever ranges are created/normalized, the paths are updated and kept in sync with the keys. #### Have you checked that...? <!-- Please run through this checklist for your pull request: --> * [x] The new code matches the existing patterns and styles. * [x] The tests pass with `yarn test`. * [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.) * [x] The relevant examples still work. (Run examples with `yarn watch`.) #### Does this fix any issues or need any specific reviewers? Fixes: https://github.com/ianstormtaylor/slate/issues/1408 Fixes: https://github.com/ianstormtaylor/slate/issues/1567
Examples
This directory contains a set of examples that give you an idea for how you might use Slate to implement your own editor. Take a look around!
- Plain text — showing the most basic case: a glorified
<textarea>
. - Rich text — showing the features you'd expect from a basic editor.
- Forced Layout - showing how to use schema rules to enforce document structure
- 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 decorators to dynamically mark text.
- ...and more!
If you have an idea for an example that shows a common use case, pull request it!
Running the Examples
To get the examples running on your machine, you need to have the Slate repository cloned to your computer. After that, you need to cd
into the directory where you cloned it, and install the dependencies with yarn
and build the monorepo:
yarn install
yarn build
Then start the watcher and examples server:
yarn start
Now you can open up http://localhost:8080
in your browser and you'll see the examples site. Any changes you make to the source code will be immediately reflected when you refresh the page. You can open the examples URL quickly with:
yarn open