Editor Transforms

API reference for editor transformation operations in Plate.

Transforms are helper functions that manipulate a Plate document.

Node Operations

duplicateNodes

Duplicates nodes at a location and inserts them after that location.

OptionsDuplicateNodesOptions

  • ...options optional InsertNodesOptions

    insertNodes options.

  • at optional At

    Location to duplicate from and insert after. Defaults to selection.

  • block optional boolean

    If true, duplicates blocks above location. Ignored if nodes provided.

  • nodes optional NodeEntry[]

    Specific nodes to duplicate. Takes precedence over block.

insertFragment

Insert a fragment of nodes at a location.

Parameters

Collapse all
  • fragment N[]

    Fragment of nodes to insert.

  • options optional InsertFragmentOptions

OptionsInsertFragmentOptions

Collapse all
  • at optional At

    Location to insert at. Defaults to selection.

  • hanging optional boolean

    Whether range is hanging.

  • voids optional boolean

    Allow insertion in void nodes.

insertNode

Insert a single node atomically.

Parameters

Collapse all
  • node N

    Node to insert.

  • options optional InsertNodesOptions

insertNodes

Insert one or more nodes atomically.

Parameters

Collapse all
  • nodes N | N[]

    Node(s) to insert.

  • options optional InsertNodesOptions

OptionsInsertNodesOptions

Collapse all
  • ...options optional QueryOptions

    Common query options.

  • batchDirty optional boolean

  • hanging optional boolean

  • nextBlock optional boolean

    Insert after the current block if removeEmpty caused it to be removed.

  • removeEmpty optional QueryNodeOptions | boolean

    Remove the current block if empty. Defaults to removing an empty paragraph, but can be customized.

  • select optional boolean

    Select inserted nodes.

  • voids optional boolean

    Allow insertion in void nodes.

liftNodes

Lift nodes at the specified location upwards in the document tree. If necessary, the parent node is split.

OptionsLiftNodesOptions

Collapse all
  • ...options optional QueryOptions

  • mode optional 'highest' | 'lowest'

  • voids optional boolean

mergeNodes

Merge a node at the specified location with the previous node at the same depth. Resulting empty container nodes are removed.

OptionsMergeNodesOptions

Collapse all
  • ...options optional QueryOptions

  • hanging optional boolean

moveNodes

Move the nodes from an origin to a destination.

OptionsMoveNodesOptions

Collapse all
  • ...options optional QueryOptions

  • to Path

    Destination path.

  • children optional boolean

    Move only children of the node at the location.

  • fromIndex optional number

    Start index of the children to move. Default is 0.

  • mode optional 'highest' | 'lowest'

  • voids optional boolean

removeNodes

Remove nodes at a location.

OptionsRemoveNodesOptions

Collapse all
  • ...options optional QueryOptions

  • children optional boolean

    When true, remove all children of the node at the specified location.

  • hanging optional boolean

  • previousEmptyBlock optional boolean

    Remove the previous empty block if it exists.

  • mode optional 'highest' | 'lowest'

  • voids optional boolean

replaceNodes

Replace nodes at a location with new nodes.

Parameters

Collapse all
  • nodes N | N[]

    The new node(s) to insert.

  • options optional ReplaceNodesOptions

OptionsReplaceNodesOptions

Collapse all
  • ...options optional InsertNodesOptions

    insertNodes options.

  • children optional boolean

    Replace all children of the node at the specified location instead of the node itself.

  • removeNodes optional Omit<RemoveNodesOptions, 'at'>

    Options for removing nodes before the replacement.

reset

Reset the editor state including history, selection and children.

OptionsResetOptions

Collapse all
  • ...options optional ReplaceNodesOptions

    replaceNodes options.

  • children optional boolean

    When true, only reset the children without clearing history/operations.

setNodes

Set properties on nodes.

Parameters

Collapse all
  • props Partial<NodeProps<N>>

    Properties to set. Use undefined to unset.

  • options optional SetNodesOptions

OptionsSetNodesOptions

Collapse all
  • ...options optional QueryOptions

  • compare optional (prop: Partial<Descendant>, node: Partial<Descendant>) => boolean

  • hanging optional boolean

  • marks optional boolean

    When true, only apply to text nodes in non-void or markable void nodes.

  • merge optional (prop: Partial<Descendant>, node: Partial<Descendant>) => object

  • mode optional 'highest' | 'lowest'

  • split optional boolean

  • voids optional boolean

splitNodes

Split nodes at a location.

OptionsSplitNodesOptions

Collapse all
  • ...options optional QueryOptions

  • always optional boolean

  • height optional number

  • mode optional 'highest' | 'lowest'

  • voids optional boolean

toggleBlock

Toggle the block type at a location.

Parameters

Collapse all
  • type string

    The block type to toggle.

  • options optional ToggleBlockOptions

OptionsToggleBlockOptions

Collapse all
  • ...options optional SetNodesOptions

    Options to pass to setNodes.

  • defaultType optional string

    The default block type when untoggling. Defaults to paragraph.

  • someOptions optional EditorNodesOptions

    Options for determining if the block is active.

  • wrap optional boolean

    If true, toggles wrapping with type. Otherwise, sets the block type directly.

unsetNodes

Remove properties from nodes.

Parameters

Collapse all
  • props string | string[]

    Property key(s) to remove.

  • options optional UnsetNodesOptions

OptionsUnsetNodesOptions

Collapse all
  • ...options optional QueryOptions

  • hanging optional boolean

  • mode optional 'highest' | 'lowest'

  • split optional boolean

  • voids optional boolean

unwrapNodes

Unwrap a node at a location. If necessary, the parent node is split.

OptionsUnwrapNodesOptions

Collapse all
  • ...options optional QueryOptions

  • hanging optional boolean

  • split optional boolean

  • mode optional 'highest' | 'lowest'

  • voids optional boolean

wrapNodes

Wrap nodes at a location in the element container.

Parameters

Collapse all
  • element N

    The wrapper element.

  • options optional WrapNodesOptions

OptionsWrapNodesOptions

Collapse all
  • ...options optional QueryOptions

  • children optional boolean

    When true, wrap all children into a single container element.

  • hanging optional boolean

  • mode optional 'highest' | 'lowest'

  • split optional boolean

  • voids optional boolean

Text Operations

delete

Delete text at a location.

OptionsDeleteTextOptions

Collapse all
  • at optional At

  • distance optional number

    Number of characters (or other unit) to delete. Default is 1.

  • hanging optional boolean

  • reverse optional boolean

    If true, delete backward.

  • unit optional 'character' | 'word' | 'line' | 'block'

    Unit to delete by.

  • voids optional boolean

deleteBackward

Delete text backward.

Parameters

Collapse all
  • unit optional 'character' | 'word' | 'line' | 'block'

    Defaults to 'character'.

deleteForward

Delete text forward.

Parameters

Collapse all
  • unit optional 'character' | 'word' | 'line' | 'block'

    Defaults to 'character'.

deleteFragment

Delete a fragment of nodes.

OptionsEditorFragmentDeletionOptions

Collapse all
  • direction optional 'forward' | 'backward'

    Direction to delete.

insertText

Insert text at a location, optionally with marks. The behavior depends on the provided options:

  1. If at is specified in options, inserts at that location regardless of selection
  2. Otherwise, if there's a selection:
    • If marks is true (default) and editor has marks, inserts text with those marks
    • If no marks, inserts plain text
  3. If neither at nor selection exists, no text is inserted

Parameters

Collapse all
  • text string

    Text to insert.

  • options optional InsertTextOptions

OptionsInsertTextOptions

Collapse all
  • at optional TLocation

    Location to insert text at. Takes precedence over current selection.

  • voids optional boolean

    Whether to allow insertion in void nodes.

  • marks optional boolean

    • Default: true When true and editor has marks, the inserted text will include those marks. When false, inserts plain text without marks.

insertBreak

Insert a block break at the current selection.

insertSoftBreak

Insert a soft break at the current selection. A soft break is a new line in the current block.

deselect

Unset the selection.

move

Move the selection's point forward or backward.

Optionsobject

Collapse all
  • distance optional number

    How many units to move. Defaults to 1.

  • unit optional 'offset' | 'character' | 'word' | 'line'

    Defaults to 'character'.

  • reverse optional boolean

    Move backward if true.

  • edge optional 'anchor' | 'focus' | 'start' | 'end'

    Which edge to move.

Mark Operations

addMark

Add a custom property to the leaf text nodes within non-void nodes or void nodes that editor.markableVoid() allows in the current selection. If the selection is currently collapsed, the marks will be added to the editor.marks property instead, and applied when text is inserted next.

Parameters

Collapse all
  • key string

    Mark key to add.

  • value any

    Value for the mark.

addMarks

Add multiple marks to the current selection.

editor.tf.addMarks({ bold: true, italic: true })
editor.tf.addMarks({ bold: subscript }, { remove: 'superscript' })
editor.tf.addMarks({ bold: true }, { remove: ['italic', 'underline'] })

Parameters

Collapse all
  • marks Record<string, any>

    Key-value pairs of mark props.

  • options optional AddMarksOptions

OptionsAddMarksOptions

Collapse all
  • remove optional string[] | string

    Mark keys to remove first. For mutually exclusive marks, e.g. subscript/superscript.

removeMark

Remove a mark from text in the selection.

Parameters

Collapse all
  • key string

    Mark key to remove.

removeMarks

Remove marks from text nodes in the current selection or from editor.marks. The behavior depends on the selection state and options:

  1. If selection is expanded or is in a markable void node:
    • Remove specified mark keys from text nodes
  2. If selection is collapsed and no custom range provided:
    • Remove specified keys from editor.marks
    • If no keys specified, clear all marks from editor.marks
  3. If custom range provided (at option):
    • Only remove marks from text nodes in that range
editor.tf.removeMarks()             // remove all marks
editor.tf.removeMarks('bold')       // remove the 'bold' mark
editor.tf.removeMarks(['bold','italic'])
editor.tf.removeMarks('bold', { at: range })

Parameters

Collapse all
  • keys optional string | string[]

    Mark key(s) to remove. If not provided and selection is collapsed, clears all marks from editor.marks.

  • options optional RemoveMarksOptions

OptionsRemoveMarksOptions

Collapse all
  • ...options optional UnsetNodesOptions

  • at optional TRange

    Custom range to remove marks from. Takes precedence over current selection.

  • shouldChange optional boolean

    • Default: true Whether to trigger onChange when modifying editor.marks.
  • split optional boolean

    Whether to split nodes when removing marks.

  • match optional (node: Node, path: Path) => boolean

    Custom function to filter which nodes to remove marks from.

  • voids optional boolean

    Whether to allow removing marks from void nodes.

toggleMark

Toggle a mark on or off in the current selection. If the mark exists, removes it. If it doesn't exist:

  1. Removes any specified marks in the remove option
  2. Adds the mark with value true
editor.tf.toggleMark('bold')                                // Toggle bold on/off
editor.tf.toggleMark('subscript', { remove: 'superscript'}) // Remove superscript before adding subscript

Parameters

Collapse all
  • key string

    The mark key to toggle.

  • options optional ToggleMarkOptions

OptionsToggleMarkOptions

Collapse all
  • remove optional string[] | string

    Mark key(s) to remove before adding the mark. Useful for mutually exclusive marks like subscript/superscript. The specified mark key is always removed in addition to these marks.

Selection

collapse

Collapse the selection to a point.

Optionsobject

Collapse all
  • edge optional 'anchor' | 'focus' | 'start' | 'end'

    Edge to collapse to. Defaults to 'anchor'.

deselect

Unset the current selection.

move

Move the selection's point.

Optionsobject

Collapse all
  • distance optional number

    Defaults to 1.

  • unit optional 'offset' | 'character' | 'word' | 'line'

    Defaults to 'character'.

  • reverse optional boolean

    If true, move backward.

  • edge optional 'anchor' | 'focus' | 'start' | 'end'

    Which edge to move.

select

Set the selection to a new value specified by at. When a selection already exists, this method just calls setSelection.

editor.tf.select(at)
editor.tf.select(at, { edge: 'end' })
editor.tf.select(at, { edge: 'start' })

Parameters

Collapse all
  • at At

    Location to select.

  • options optional SelectOptions

OptionsSelectOptions

Collapse all
  • edge optional 'start' | 'end'

    Select the start or end edge above at.

  • focus optional boolean

    Focus the editor before selecting.

  • next optional boolean

    Select the start of the next sibling.

  • previous optional boolean

    Select the end of the previous sibling.

setPoint

Set new properties on one of the selection's points.

Parameters

Collapse all
  • props Partial<Point>

    Point properties to update.

  • options optional object

Optionsobject

Collapse all
  • edge optional 'anchor' | 'focus' | 'start' | 'end'

    Which edge of the selection to set.

setSelection

Set new properties on an active selection. Since the value is a Partial<Range>, this method can only handle updates to an existing selection. If there is no active selection the operation will be void. Use select if you'd like to create a selection when there is none.

Parameters

Collapse all
  • props Partial<TRange>

    A partial range to update existing selection properties.

DOM Operations

blur

Blur the editor.

deselectDOM

Deselect the editor's DOM selection in addition to deselect.

focus

Focus the editor.

editor.tf.focus()
editor.tf.focus({ edge: 'end' })
editor.tf.focus({ edge: 'endEditor' })

OptionsFocusOptions

Collapse all
  • at optional At

    Select this location before focusing.

  • edge optional 'start' | 'startEditor' | 'end' | 'endEditor'

    Focus at the edge of the location or the editor.

  • retries optional number

    Number of attempts to refocus.

insertData

Insert data from a DataTransfer into the editor. Calls:

  1. insertFragmentData(editor: ReactEditor, data: DataTransfer)
  2. insertTextData(editor: ReactEditor, data: DataTransfer)

Parameters

Collapse all
  • data DataTransfer

    Data to insert from clipboard or drag event.

insertFragmentData

Insert fragment data from a DataTransfer into the editor.

Parameters

Collapse all
  • data DataTransfer

    Data to parse as fragment.

insertTextData

Insert text data from a DataTransfer into the editor.

Parameters

Collapse all
  • data DataTransfer

    Text data to insert.

setFragmentData

Sets data from the currently selected fragment on a DataTransfer.

Parameters

Collapse all
  • data DataTransfer

    DataTransfer to store the fragment.

History Operations

redo

Redo to the next saved state.

undo

Undo to the previous saved state.

setSplittingOnce

Parameters

Collapse all
  • value boolean

    Whether the next operation should split into a new batch in history.

withMerging

Apply a series of changes inside a synchronous fn, These operations will be merged into the previous history.

Parameters

Collapse all
  • fn () => void

    Batched changes to merge into the previous history point.

withNewBatch

Apply a series of changes inside a synchronous fn, ensuring that the first operation starts a new batch in the history. Subsequent operations will be merged as usual.

Parameters

Collapse all
  • fn () => void

    Batched changes in a new history point.

withoutMerging

Apply a series of changes inside a synchronous fn, without merging any of the new operations into previous save point in the history.

Parameters

Collapse all
  • fn () => void

    Changes not merged into any existing history point.

withoutSaving

Apply a series of changes inside a synchronous fn, without saving any of their operations into the history.

Parameters

Collapse all
  • fn () => void

    Changes not saved into history at all.

Core Operations

apply

Apply an operation in the editor.

Parameters

Collapse all
  • operation Operation<N>

    Operation to apply.

normalizeNode

Normalize a node according to the editor's schema.

Parameters

Collapse all
  • entry NodeEntry<N>

    The node entry to normalize.

  • options optional { operation?: Operation }

Options{ operation?: Operation }

Collapse all
  • operation optional Operation

    The triggering operation.

normalize

Normalize dirty nodes in the editor.

OptionsEditorNormalizeOptions

Collapse all
  • force optional boolean

    When true, forcibly re-normalize all nodes.

  • operation optional Operation

withoutNormalizing

Call a function, deferring normalization until after it completes.

Parameters

Collapse all
  • fn () => void

    A synchronous function to execute without normalization in between operations.

Returnsboolean

    True if normalization was performed afterwards.

Keyboard Shortcuts

moveLine

Handle ArrowUp and ArrowDown keyboard events.

Parameters

Collapse all
  • options { reverse: boolean }

    • reverse: true for ArrowUp
    • reverse: false for ArrowDown

Returnsboolean | void

    Return true to prevent default browser behavior, false to allow it.

Default behavior: Returns false (allows Plate's default line movement).

Usage:

const plugin = createPlatePlugin({
  key: 'myPlugin',
}).overrideEditor(() => ({
  transforms: {
    moveLine: ({ reverse }) => {
      // Custom line movement logic
      if (reverse) {
        // Handle ArrowUp
      } else {
        // Handle ArrowDown  
      }
      return true; // Prevent default
    },
  },
}));

tab

Handle Tab and Shift+Tab keyboard events.

Parameters

Collapse all
  • options { reverse: boolean }

    • reverse: false for Tab
    • reverse: true for Shift+Tab

Returnsboolean | void

    Return true to prevent default browser behavior, false to allow it.

Default behavior: Returns false (allows default browser tab navigation).

Usage:

const plugin = createPlatePlugin({
  key: 'myPlugin',
}).overrideEditor(() => ({
  transforms: {
    tab: ({ reverse }) => {
      if (reverse) {
        // Handle Shift+Tab (usually outdent)
        editor.tf.outdent();
      } else {
        // Handle Tab (usually indent)
        editor.tf.indent();
      }
      return true; // Prevent default
    },
  },
}));

selectAll

Handle Cmd+A / Ctrl+A keyboard events.

Returnsboolean | void

    Return true to prevent default browser behavior, false to allow it.

Default behavior: Returns false (allows default browser select all).

Usage:

const plugin = createPlatePlugin({
  key: 'myPlugin',
}).overrideEditor(() => ({
  transforms: {
    selectAll: () => {
      // Custom select all logic
      const blockEntry = editor.api.block();
      if (blockEntry) {
        editor.tf.select(blockEntry[1]);
        return true; // Prevent default
      }
      return false; // Allow default
    },
  },
}));

escape

Handle Escape keyboard events.

Returnsboolean | void

    Return true to prevent default browser behavior, false to allow it.

Default behavior: Returns false (allows default browser escape handling).

Usage:

const plugin = createPlatePlugin({
  key: 'myPlugin',
}).overrideEditor(() => ({
  transforms: {
    escape: () => {
      // Custom escape logic (e.g., exit special mode)
      if (editor.api.inSpecialMode()) {
        editor.tf.exitSpecialMode();
        return true; // Prevent default
      }
      return false; // Allow default
    },
  },
}));