Operation

API reference for operations in Slate.

An Operation is the lowest-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.

export type Operation<N extends Descendant = Descendant> =
  | NodeOperation<N>
  | SelectionOperation
  | TextOperation;

OperationApi

isNodeOperation

Check if a value is a NodeOperation object.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is a node operation.

inverse

Invert an operation, returning a new operation that will exactly undo the original when applied.

Parameters

Collapse all

    The operation to invert.

ReturnsOperation

    A new operation that undoes the original operation.

isOperation

Check if a value is an Operation object.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is an operation.

isOperationList

Check if a value is a list of Operation objects.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is an array of operations.

isSelectionOperation

Check if a value is a SelectionOperation object.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is a selection operation.

isTextOperation

Check if a value is a TextOperation object.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is a text operation.

Types

Operation

export type Operation<N extends Descendant = Descendant> =
  | NodeOperation<N>
  | SelectionOperation
  | TextOperation;

NodeOperation

A node operation modifies a node.

export type NodeOperation<N extends Descendant = Descendant> =
  | InsertNodeOperation<N>
  | MergeNodeOperation<N>
  | MoveNodeOperation
  | RemoveNodeOperation<N>
  | SetNodeOperation<N>
  | SplitNodeOperation<N>;

SelectionOperation

A selection operation modifies the selection.

export type SelectionOperation = SetSelectionOperation;

TextOperation

A text operation modifies text content.

export type TextOperation = InsertTextOperation | RemoveTextOperation;

InsertNodeOperation

Attributes

Collapse all

    The node to insert.

    The path to insert at.

    The operation type.

MergeNodeOperation

Attributes

Collapse all

    The path of the node to merge.

    The position to merge at.

    The properties of the merged node.

    The operation type.

MoveNodeOperation

Attributes

Collapse all

    The new path to move to.

    The path of the node to move.

    The operation type.

RemoveNodeOperation

Attributes

Collapse all

    The node to remove.

    The path of the node.

    The operation type.

SetNodeOperation

Attributes

Collapse all

    The new properties to set.

    The path of the node.

    The old properties.

    The operation type.

SplitNodeOperation

Attributes

Collapse all

    The path of the node to split.

    The position to split at.

    The properties of the new split node.

    The operation type.

SetSelectionOperation

Attributes

Collapse all

    The new selection properties.

    The old selection properties.

    The operation type.

InsertTextOperation

Attributes

Collapse all

    The offset to insert at.

    The path of the text node.

    The text to insert.

    The operation type.

RemoveTextOperation

Attributes

Collapse all

    The offset to remove from.

    The path of the text node.

    The text being removed.

    The operation type.