Operation
API reference for operations in Slate.
Operation
objects define the low-level instructions that Slate editors use to apply changes to their internal state. Representing all changes as operations is what allows Slate editors to easily implement history, collaboration, and other features.
Operation
Find the corresponding documentation in the Slate docs.
isNodeOperation
Checks if a value is a NodeOperation
object.
Parameters
The value to check.
Returns
Returns true
if the value is a node operation.
inverse
Inverts an operation, returning a new operation that will exactly undo the original when applied.
Parameters
The operation to invert.
Returns
Returns a new operation that undoes the original operation.
isOperation
Checks if a value is an Operation
object.
Parameters
The value to check.
Returns
Returns true
if the value is an operation.
isOperationList
Checks if a value is a list of Operation
objects.
Parameters
The value to check.
Returns
Returns true
if the value is an array of operations.
isSelectionOperation
Checks if a value is a SelectionOperation
object.
Parameters
The value to check.
Returns
Returns true
if the value is a selection operation.
isTextOperation
Checks if a value is a TextOperation
object.
Parameters
The value to check.
Returns
Returns true
if the value is a text operation.
Types
Operation
The base operation type that represents any change to the editor state. Operations can be one of three types:
- NodeOperation: Operations that modify nodes (insert, merge, move, remove, set, split)
- SelectionOperation: Operations that modify the selection state
- TextOperation: Operations that modify text content (insert, remove)
NodeOperation
Attributes
type: 'insert_node'
path: Path
- Where to insert the nodenode: Descendant
- The node to inserttype: 'merge_node'
path: Path
- The node to mergeposition: number
- The position to merge atproperties: Partial<NodeProps>
- Properties of the merged nodetype: 'move_node'
path: Path
- The node to movenewPath: Path
- Where to move the nodetype: 'remove_node'
path: Path
- The node to removenode: Descendant
- The node being removedtype: 'set_node'
path: Path
- The node to updateproperties: Partial<NodeProps>
- The old propertiesnewProperties: Partial<NodeProps>
- The new propertiestype: 'split_node'
path: Path
- The node to splitposition: number
- Where to split the nodeproperties: Partial<NodeProps>
- Properties of the new node
TextOperation
Attributes
type: 'insert_text'
path: Path
- The text node to modifyoffset: number
- Where to insert the texttext: string
- The text to inserttype: 'remove_text'
path: Path
- The text node to modifyoffset: number
- Where to remove the texttext: string
- The text being removed
SelectionOperation
Attributes
type: 'set_selection'
properties: Partial<TRange> | null
- The old selectionnewProperties: Partial<TRange> | null
- The new selection