Editor
All of the behaviors, content and state of a Slate editor is rollup up into a single, top-level Editor
object. It has an interface of:
Slightly more complex than the others, because it contains all of the top-level functions that define your custom, domain-specific behaviors.
The children
property contains the document tree of nodes that make up the editor's content.
The selection
property contains the user's current selection, if any.
And the operations
property contains all of the operations that have been applied since the last "change" was flushed. (Since Slate batches operations up into ticks of the event loop.)
Overriding Behaviors
In previous guides we've already hinted at this, but you can overriding any of the behaviors of an editor by overriding it's function properties.
For example, if you want define link elements that are inline nodes:
Or maybe you want to define a custom command:
Or you can even define custom "normalizations" that take place to ensure that links obey certain constraints:
Whenever you override behaviors, be sure to call in to the existing functions as a fallback mechanism for the default behavior. Unless you really do want to completely remove the default behaviors (which is rarely a good idea).
Helper Functions
The Editor
interface, like all Slate interfaces, exposes helper functions that are useful when implementing certain behaviors. There are many, many editor-related helpers. For example:
There are also many iterator-based helpers, for example:
Another special group of helper functions exposed on the Editor
interface are the "transform" helpers. They are the lower-level functions that commands use to define their behaviors. For example:
The editor-specific helpers are the ones you'll use most often when working with Slate editors, so it pays to become very familiar with them.
Last updated