1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-23 16:55:23 +01:00
2016-07-28 11:13:12 -07:00

3.8 KiB

State

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.

Properties

State({
  document: Document,
  selection: Selection
})

document

Document

The current document of the state.

selection

Selection

The current selection of the state.

Computed Properties

These properties aren't supplied when creating a State, but are instead computed based on the current document and selection.

{edge}Text

Text

Get the leaf Text node at {edge}. Where {edge} is one of: anchor, focus, start or end.

{edge}Block

Block

Get the leaf Block node at {edge}. Where {edge} is one of: anchor, focus, start or end.

marks

Set

Get a set of the Marks in the current selection.

blocks

List

Get a list of the lowest-depth Block nodes in the current selection.

fragment

Document

Get a Document fragment of the current selection.

inlines

List

Get a list of the lowest-depth Inline nodes in the current selection.

texts

List

Get a list of the Text nodes in the current selection.

hasUndos

Boolean

Whether there are undoable snapshots to revert to in the history.

hasRedos

Boolean

Whether there are redoable snapshots to revert to in the history.

Selection-like Properties

These properties are exact proxies of their Selection equivalents.

{edge}Key

String

Get the current key at an {edge}. Where {edge} is one of: anchor, focus, start or end.

{edge}Offset

Number

Get the current offset at an {edge}. Where {edge} is one of: anchor, focus, start or end.

isBackward

Boolean

Whether the current selection is backward.

isBlurred

Boolean

Whether the current selection is blurred.

isCollapsed

Boolean

Whether the current selection is collapsed.

isExpanded

Boolean

Whether the current selection is expanded.

isFocused

Boolean

Whether the current selection is focused.

isForward

Boolean

Whether the current selection is forward.

Static Methods

State.create

State.create(properties: Object) => State

Create a new State instance with properties.

Methods

transform

transform() => Transform

Create a new Transform that acts on the current state.