Operation

API reference for operations in Plate.

An Operation is the lowest-level instructions that Plate editors use to apply changes to their internal state. Representing all changes as operations is what allows Plate 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

  • value any

    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
  • op Operation

    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
  • value any

    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
  • value any

    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
  • value any

    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
  • value any

    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
  • node N

    The node to insert.

  • path Path

    The path to insert at.

  • type 'insert_node'

    The operation type.

MergeNodeOperation

Attributes

Collapse all
  • path Path

    The path of the node to merge.

  • position number

    The position to merge at.

  • properties Partial<NodeProps<N>>

    The properties of the merged node.

  • type 'merge_node'

    The operation type.

MoveNodeOperation

Attributes

Collapse all
  • newPath Path

    The new path to move to.

  • path Path

    The path of the node to move.

  • type 'move_node'

    The operation type.

RemoveNodeOperation

Attributes

Collapse all
  • node N

    The node to remove.

  • path Path

    The path of the node.

  • type 'remove_node'

    The operation type.

SetNodeOperation

Attributes

Collapse all
  • newProperties Partial<NodeProps<N1>>

    The new properties to set.

  • path Path

    The path of the node.

  • properties Partial<NodeProps<N2>>

    The old properties.

  • type 'set_node'

    The operation type.

SplitNodeOperation

Attributes

Collapse all
  • path Path

    The path of the node to split.

  • position number

    The position to split at.

  • properties Partial<NodeProps<N>>

    The properties of the new split node.

  • type 'split_node'

    The operation type.

SetSelectionOperation

Attributes

Collapse all
  • newProperties Partial<TRange> | TRange | null

    The new selection properties.

  • properties Partial<TRange> | TRange | null

    The old selection properties.

  • type 'set_selection'

    The operation type.

InsertTextOperation

Attributes

Collapse all
  • offset number

    The offset to insert at.

  • path Path

    The path of the text node.

  • text string

    The text to insert.

  • type 'insert_text'

    The operation type.

RemoveTextOperation

Attributes

Collapse all
  • offset number

    The offset to remove from.

  • path Path

    The path of the text node.

  • text string

    The text being removed.

  • type 'remove_text'

    The operation type.