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

Collapse all

    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

Collapse all

    The operation to invert.

Returns

    Returns a new operation that undoes the original operation.

isOperation

Checks if a value is an Operation object.

Parameters

Collapse all

    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

Collapse all

    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

Collapse all

    The value to check.

Returns

    Returns true if the value is a selection operation.

isTextOperation

Checks if a value is a TextOperation object.

Parameters

Collapse all

    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

Collapse all

    • type: 'insert_node'
    • path: Path - Where to insert the node
    • node: Descendant - The node to insert

    • type: 'merge_node'
    • path: Path - The node to merge
    • position: number - The position to merge at
    • properties: Partial<NodeProps> - Properties of the merged node

    • type: 'move_node'
    • path: Path - The node to move
    • newPath: Path - Where to move the node

    • type: 'remove_node'
    • path: Path - The node to remove
    • node: Descendant - The node being removed

    • type: 'set_node'
    • path: Path - The node to update
    • properties: Partial<NodeProps> - The old properties
    • newProperties: Partial<NodeProps> - The new properties

    • type: 'split_node'
    • path: Path - The node to split
    • position: number - Where to split the node
    • properties: Partial<NodeProps> - Properties of the new node

TextOperation

Attributes

Collapse all

    • type: 'insert_text'
    • path: Path - The text node to modify
    • offset: number - Where to insert the text
    • text: string - The text to insert

    • type: 'remove_text'
    • path: Path - The text node to modify
    • offset: number - Where to remove the text
    • text: string - The text being removed

SelectionOperation

Attributes

Collapse all

    • type: 'set_selection'
    • properties: Partial<TRange> | null - The old selection
    • newProperties: Partial<TRange> | null - The new selection