The Editor API provides a set of helper functions for querying and manipulating the editor state.
Common Options
At
A location reference in the editor. Can be either a Location or a Node.
type At = TLocation | TNode
When a Node is passed, its path will be found using editor.api.findPath()
. This allows you to reference a location by either:
Example:
// Using a location
editor.api.nodes({ at: [0, 0] }) // Path location
editor.api.nodes({ at: { path: [0], offset: 0 } }) // Point location
editor.api.nodes({ at: { anchor: point1, focus: point2 } }) // Range location
// Using a node reference
const node = editor.children[0]
editor.api.nodes({ at: node }) // Will find node's path internally
Match
A predicate for matching nodes. The predicate can be either:
- A function that takes a
node
and itspath
and returns aboolean
- An object where each key-value pair must match the node's properties
- Values can be single values or arrays of values to match against
Example:
// Function predicate
editor.api.nodes({
match: (node) => node.type === 'p'
})
// Object predicate
editor.api.nodes({
match: { type: 'p' }
})
// Object predicate with multiple possible values
editor.api.nodes({
match: { type: ['p', 'h1'] }
})
QueryMode
Mode for querying nodes in a hierarchy.
mode optional 'all' | 'highest' | 'lowest'
'all'
(default): Return all matching nodes'highest'
: In a hierarchy of nodes, only return the highest-level matching nodes'lowest'
: In a hierarchy of nodes, only return the lowest-level matching nodes
Example:
// Given this structure: // - blockquote (matches) // - paragraph (matches) // - text // mode: 'all' returns both blockquote and paragraph editor.api.nodes({ match: { type: ['blockquote', 'paragraph'] }, mode: 'all' }) // mode: 'highest' returns only blockquote editor.api.nodes({ match: { type: ['blockquote', 'paragraph'] }, mode: 'highest' }) // mode: 'lowest' returns only paragraph editor.api.nodes({ match: { type: ['blockquote', 'paragraph'] }, mode: 'lowest' })
QueryOptions
Common options for querying nodes in the editor.
at optional At
Where to start querying from. Defaults to current editor selection.
block optional boolean
Match block nodes. When true, only matches block elements.
empty optional boolean
Match empty/non-empty nodes.
- When true, matches only empty nodes
- When false, matches only non-empty nodes
id optional boolean | string
Match the node by id.
- When true, matches all nodes with an id
- When string, matches nodes with that specific id
match optional Predicate<NodeIn<V>>
Custom function or object to match nodes.
- Function:
(node, path) => boolean
- Object: Key-value pairs that should match the node
- Function:
text optional boolean
Match text nodes. When true, matches only text nodes.
editor.api
above
Get the matching ancestor above a location in the document.
block
Get the block at a location or find the first block that matches options.
Blocks are typically top-level nodes, so this is a common way to retrieve the ancestor block.
editor.api.block() // Get block above selection
editor.api.block({ above: true }) // Get block above selection
editor.api.block({ at: [0, 0] }) // Get block at [0, 0]
editor.api.block({ at: [0, 0], above: true }) // Get block at [0]
editor.api.block({ highest: true }) // Get highest block at selection
...options optional QueryOptions<V>
Common query options for matching blocks.
at optional At | Span
The location to query at. Defaults to current selection.
ignoreNonSelectable optional boolean
Whether to ignore non-selectable nodes during traversal.
reverse optional boolean
Whether to traverse in reverse order.
universal optional boolean
Whether to ensure the operation works universally across all nodes.
above optional boolean
If true, get the block above the location. Ignored if
at
is not a block path.highest optional boolean
If true, get the highest block at the location (root-level block).
mode optional QueryMode
Query mode for matching blocks.
voids optional boolean
Whether to include void nodes in the search.
blocks
Returns all matching blocks.
...options optional QueryOptions<V>
Common query options for matching blocks.
at optional At | Span
The location to query at. Defaults to current selection.
ignoreNonSelectable optional boolean
Whether to ignore non-selectable nodes during traversal.
reverse optional boolean
Whether to traverse in reverse order.
universal optional boolean
Whether to ensure the operation works universally across all nodes.
mode optional QueryMode
Query mode for matching blocks.
voids optional boolean
Whether to include void nodes in the search.
edgeBlocks
Returns the edge blocks above a location (default: selection).
Useful for retrieving the start and end block of a range.
...options optional QueryOptions<V>
Common query options for matching blocks.
at optional At | Span
The location to get edge blocks from. Defaults to current selection.
ignoreNonSelectable optional boolean
Whether to ignore non-selectable nodes during traversal.
reverse optional boolean
Whether to traverse in reverse order.
universal optional boolean
Whether to ensure the operation works universally across all nodes.
mode optional QueryMode
Query mode for matching blocks.
voids optional boolean
Whether to include void nodes in the search.
first
Get the first node at a location.
fragment
Get the fragment at a location or selection.
getFragment
Returns the fragment at the current selection. Used when cutting or copying, as an example, to get the fragment at the current selection.
hasBlocks
Check if a node has block children.
hasInlines
Check if a node has inline and text children.
hasMark
Check if mark is active at selection.
hasPath
Check if a path exists in the editor.
hasTexts
Check if a node has text children.
isAt
Check if a location (point/range) is at a specific position.
// For ranges:
editor.api.isAt({ text: true }) // Check if range is in a single text node
editor.api.isAt({ block: true }) // Check if range is in a single block
editor.api.isAt({ blocks: true }) // Check if range is across multiple blocks
editor.api.isAt({ start: true }) // Check if range starts at block start
editor.api.isAt({ end: true }) // Check if range ends at block end
// For points:
editor.api.isAt({ word: true }) // Check relative to word boundaries
editor.api.isAt({ start: true }) // Check if at start
editor.api.isAt({ end: true }) // Check if at end
at optional At
The location to check. Defaults to current selection.
text optional boolean
Check if range is in a single text node.
block optional boolean
Check if range is in a single block.
blocks optional boolean
Check if range is across multiple blocks.
start optional boolean
Check if at start position.
end optional boolean
Check if at end position.
word optional boolean
Check relative to word boundaries.
isCollapsed
Check if the selection is collapsed (start and end points are the same).
isEdge
Check if a point is an edge of a location.
isEditorEnd
Check if selection is at editor end.
isEmpty
Check if an element is empty, accounting for void nodes.
editor.api.isEmpty() // Check if editor is empty
editor.api.isEmpty(at) // Check if nodes at location are empty
editor.api.isEmpty(at, { after: true }) // Check if text after location is empty
editor.api.isEmpty(at, { block: true }) // Check if block above location is empty
isEnd
Check if a point is the end point of a location.
isExpanded
Check if the selection is expanded (start and end points are different).
isNormalizing
Check if the editor is currently normalizing after each operation.
isStart
Check if a point is the start point of a location.
isSelected
Check if a path is selected by the current selection.
leaf
Get the leaf text node at a location.
levels
Iterate through all levels at a location. This includes all ancestors up to the root editor node.
last
Get the last node at a location.
mark
Returns the selection mark value by key.
marks
Get the marks that would be added to text at the current selection.
next
Get the matching node in the branch of the document after a location.
...options optional QueryOptions<V>
Common query options for matching nodes.
at optional At | Span
The location to start searching from. Defaults to current selection.
mode optional QueryMode
Query mode for matching nodes.
voids optional boolean
Whether to include void nodes in the search.
from optional 'after' | 'child'
'after'
: Start from point after current location'child'
: Start from the first child of current path
node
Get the node at a location or find the first node that matches options.
nodes
Iterate through all nodes in the editor that match the given options.
...options optional QueryOptions<V>
Common query options for matching nodes.
at optional At | Span
Where to start iterating. Defaults to editor selection.
ignoreNonSelectable optional boolean
Whether to ignore non-selectable nodes during traversal.
reverse optional boolean
Whether to traverse in reverse order.
universal optional boolean
Whether to ensure the operation works universally across all nodes.
mode optional QueryMode
'all'
: Return all matching nodes'highest'
: Return highest-level matching nodes'lowest'
: Return lowest-level matching nodes
voids optional boolean
Whether to include void nodes in the search.
parent
Get the parent node of a location.
previous
Get the matching node in the branch of the document before a location.
...options optional QueryOptions<V>
Common query options for matching nodes.
at optional At | Span
The location to start searching from. Defaults to current selection.
mode optional QueryMode
Query mode for matching nodes.
voids optional boolean
Whether to include void nodes in the search.
sibling optional boolean
Whether to get the previous sibling node instead of any previous node.
from optional 'before' | 'parent'
'before'
: Start from point before current location'parent'
: Start from parent of current location
prop
Get a property value from a list of nodes. Returns undefined
if the property value is not consistent across all nodes.
nodes TElement[]
The list of nodes to get the property value from.
key optional string
The property key to get from the nodes.
defaultValue optional string
Default value to return if property is not found.
getProp optional (node: DescendantIn<V>) => any
Custom function to extract property value from a node.
mode optional 'all' | 'block' | 'text'
'all'
: Get property from all nodes'block'
: Get property from the first block node'text'
: Get property from the first text node
string
Get the text string content of a location.
void
Match a void node in the current branch of the editor.
Location
findPath
Find the path of a Plate node in the editor.
...options optional QueryOptions<Value>
Common query options for finding nodes.
ignoreNonSelectable optional boolean
Whether to ignore non-selectable nodes during traversal.
reverse optional boolean
Whether to traverse in reverse order.
universal optional boolean
Whether to ensure the operation works universally across all nodes.
mode optional QueryMode
Query mode for finding nodes.
voids optional boolean
Whether to include void nodes in the search.
path
Get the path of a location.
point
Get the start
or end
(default is start
) point of a location.
positions
Iterate through all possible point positions in the document.
at optional At
Where to start iterating. Defaults to editor selection.
unit optional TextUnitAdjustment
'offset'
: Moves to the next offset Point'character'
: Moves to the next character'word'
: Moves to the position after the next word'line'
| 'block': Moves between block boundaries
reverse optional boolean
When true returns positions in reverse order.
voids optional boolean
Whether to include positions inside void nodes.
ignoreNonSelectable optional boolean
Whether to skip positions in non-selectable nodes.
nodesRange
Returns the range spanning the given node entries.
range
Create a range between two locations.
start
Get the start point of a location.
unhangRange
Convert a range into a non-hanging one.
A "hanging" range is one created by the browser's "triple-click" selection behavior. When triple-clicking a block, the browser selects from the start of that block to the start of the next block. The range thus "hangs over" into the next block. If unhangRange
is given such a range, it moves the end backwards until it's in a non-empty text node that precedes the hanging block.
Note that unhangRange
is designed for the specific purpose of fixing triple-clicked blocks, and therefore currently has a number of caveats:
- It does not modify the start of the range; only the end. For example, it does not "unhang" a selection that starts at the end of a previous block.
- It only does anything if the start block is fully selected. For example, it does not handle ranges created by double-clicking the end of a paragraph (which browsers treat by selecting from the end of that paragraph to the start of the next).
Element
elementReadOnly
Check if an element is read-only.
isBlock
Check if a value is a block Element
object.
isInline
Check if a value is an inline Element
object.
isSelectable
Check if a value is a selectable Element
object.
isVoid
Check if an element is void.
markableVoid
Check if an element is a markable void element.
Ref
pathRef
Create a mutable ref for a Path
.
pathRefs
Get the set of currently tracked path refs of the editor.
pointRef
Create a mutable ref for a Point
.
pointRefs
Get the set of currently tracked point refs of the editor.
rangeRef
Create a mutable ref for a Range
.
affinity optional RangeDirection | null
The direction to resolve the ref when ambiguous:
'forward'
: Resolve both points forward'backward'
: Resolve both points backward'outward'
: Resolve start backward and end forward'inward'
: Resolve start forward and end backwardnull
: Do not resolve to any position
rangeRefs
Get the set of currently tracked range refs of the editor.
DOM
findDocumentOrShadowRoot
Find the document or shadow root from the editor.
findEventRange
Get the target range from a DOM event.
findKey
Find a key for a Plate node. Returns an instance of Key
which looks like { id: string }
.
getWindow
Get the window object from the editor.
hasDOMNode
Check if a DOM node is within the editor.
hasEditableTarget
Check if a DOM target is editable.
hasRange
Check if the editor has a range.
hasSelectableTarget
Check if a DOM target is selectable.
hasTarget
Check if a DOM target exists.
isComposing
Check if the user is currently composing inside the editor.
isFocused
Check if the editor is focused.
isReadOnly
Check if the editor is in read-only mode.
toDOMNode
Find the native DOM element from a Plate node.
toDOMPoint
Find a native DOM selection point from a Plate point.
toDOMRange
Find a native DOM range from a Plate range.
toSlateNode
Find a Plate node from a native DOM element.
toSlatePoint
Find a Plate point from a DOM selection point.
toSlateRange
Find a Plate range from a DOM range.
Callback
onChange
Called when there is a change in the editor.
Core
getDirtyPaths
Get the paths that need to be normalized after an operation.
shouldNormalizeNode
Override this method to prevent normalizing a specific node. Defaults to returning true
.
setNormalizing
Manually control the editor's normalizing state.
shouldNormalize
Controls whether the editor should normalize after an operation. Override this method to prevent normalizing in certain situations.
History
isMerging
Get the merge flag's current value.
isSaving
Get the saving flag's current value.
isSplittingOnce
Get the splitting flag's current value.
Utils
create.block
Default block factory for creating new block elements.
create.value
Default value factory for creating new editor values.
On This Page
Common OptionsAt
MatchQueryMode
QueryOptions
editor.api
above
block
blocks
edgeBlocks
first
fragment
getFragment
hasBlocks
hasInlines
hasMark
hasPath
hasTexts
isAt
isCollapsed
isEdge
isEditorEnd
isEmpty
isEnd
isExpanded
isNormalizing
isStart
isSelected
leaf
levels
last
mark
marks
next
node
nodes
parent
previous
prop
string
void
LocationfindPath
path
point
positions
nodesRange
range
start
unhangRange
ElementelementReadOnly
isBlock
isInline
isSelectable
isVoid
markableVoid
RefpathRef
pathRefs
pointRef
pointRefs
rangeRef
rangeRefs
DOMfindDocumentOrShadowRoot
findEventRange
findKey
getWindow
hasDOMNode
hasEditableTarget
hasRange
hasSelectableTarget
hasTarget
isComposing
isFocused
isReadOnly
toDOMNode
toDOMPoint
toDOMRange
toSlateNode
toSlatePoint
toSlateRange
CallbackonChange
CoregetDirtyPaths
shouldNormalizeNode
setNormalizing
shouldNormalize
HistoryisMerging
isSaving
isSplittingOnce
Utilscreate.block
create.value