import { State } from 'slate'
A State
is the top-level representation of data in Slate, containing both a Document
and a Selection
. It's what you need to paste into the Slate <Editor>
to render something onto the page.
All transforms to the document and selection are also performed through the state object, so that they can stay in sync, and be propagated to its internal history of undo/redo state.
For convenience, in addition to transforms, many of the Selection
and Document
properties are exposed as proxies on the State
object.
State({
document: Document,
selection: Selection
})
Document
The current document of the state.
Selection
The current selection of the state.
These properties aren't supplied when creating a State
, but are instead computed based on the current document
and selection
.
Text
Get the leaf Text
node at {edge}
. Where {edge}
is one of: anchor
, focus
, start
or end
.
Block
Get the leaf Block
node at {edge}
. Where {edge}
is one of: anchor
, focus
, start
or end
.
Set
Get a set of the Marks
in the current selection.
List
Get a list of the lowest-depth Block
nodes in the current selection.
Document
Get a Document
fragment of the current selection.
List
Get a list of the lowest-depth Inline
nodes in the current selection.
List
Get a list of the Text
nodes in the current selection.
These properties are exact proxies of their Selection
equivalents.
String
Get the current key at an {edge}
. Where {edge}
is one of: anchor
, focus
, start
or end
.
String
Get the current offset at an {edge}
. Where {edge}
is one of: anchor
, focus
, start
or end
.
Boolean
Whether the current selection is backward.
Boolean
Whether the current selection is blurred.
Boolean
Whether the current selection is collapsed.
Boolean
Whether the current selection is expanded.
Boolean
Whether the current selection is focused.
Boolean
Whether the current selection is forward.
State.create(properties: Object) => State
Create a new State
instance with properties
.
transform() => Transform
Create a new Transform
that acts on the current state.