Elements API
The Elements API provides a high-level interface for working with elements inside blocks: insert, update, delete, and query. It abstracts Slate.js details so you can work with block content without low-level paths.Accessing the API
Methods are available on the editor instance (recommended) or via theElements namespace:
Prefer using methods on the editor instance for better TypeScript support and clearer code.
Type Definitions
Methods
insertElement
Creates and inserts a new element into a block.options.blockId— ID of the block (required).options.type— Element type, e.g.'accordion-list-item','link'(required).options.props— Properties for the new element; merged with plugin defaults.options.children— Child elements; if omitted, plugin defaults are used.options.at— Where to insert:'next'|'prev'|'start'|'end'ornumber[]; default: selection or[0].options.focus— Focus editor after insert; default:false.options.select— Select the inserted element; default:false.options.text— Text for inline elements (e.g. link); usechildrenfor block elements.options.match— Custom matcher when usingat: 'next'or'prev'.
updateElement
Updates properties (and optionally text) of an existing element.options.blockId— ID of the block (required).options.type— Element type to update (required).options.props— Props to set; merged with existing.options.text— New text for inline elements (link, mention); ignored for block elements.options.path— Direct Slate path; if omitted, uses selection (inline) or root (block).options.match— Custom matcher to find the element.
deleteElement
Removes an element or unwraps it (inline).options.blockId— ID of the block (required).options.type— Element type to delete (required).options.path— Direct Slate path; if omitted, uses selection (inline) or root (block).options.match— Custom matcher to find the element.options.mode— For inline only:'unwrap'(keep text, remove wrapper; default) or'remove'(remove element and content). Block elements are always fully removed.
getElement
Returns a single element by type, path, or matcher.options.blockId— ID of the block (required).options.type— Element type to find.options.path— Path:number[]or'selection'|'first'|'last'; default: selection or[0].options.match— Custom matcher; overrides type-based search.
null.
getElements
Returns all elements of a type or matching a condition.options.blockId— ID of the block (required).options.type— Element type to find.options.match— Custom matcher; use instead of or with type.
getElementEntry
Returns element and its Slate path as a tuple.options.blockId— ID of the block (required).options.type— Element type.options.path— Path to the element; default: selection or[0].
[element, path] or null.
getElementPath
Returns the Slate path of an element instance.options.blockId— ID of the block (required).options.element— The element instance to get the path for (required).
null.
getParentElementPath
Returns the Slate path of an element’s parent.options.blockId— ID of the block (required).options.element— The element instance (required).
null.
getElementChildren
Returns the children array of an element.options.blockId— ID of the block (required).options.type— Element type (required).options.path— Path to the element; default: selection or[0].
null.
isElementEmpty
Checks whether an element has no text content.options.blockId— ID of the block (required).options.type— Element type (required).options.path— Path to the element.
true if empty, false otherwise.