Elements API
The Elements API provides element-level operations inside blocks: insert, update, delete, and query. It sits below the Blocks API and works on nodes within a block’s content.Accessing the API
Import theElements namespace from @yoopta/editor:
The same functions are exported by name (
insertElement, getElement, …). The YooEditor instance also exposes them without the first editor argument (e.g. editor.insertElement({ ... })).Type Definitions
Methods
insertElement
Creates and inserts a new element into a block.editor— Editor instance (required).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.editor— Editor instance (required).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— 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).editor— Editor instance (required).options.blockId— ID of the block (required).options.type— Element type to delete (required).options.path— Slate path; if omitted, uses selection (inline) or root (block).options.match— Custom matcher to find the element.options.mode— For inline only:'unwrap'(default) or'remove'. Block elements are always fully removed.
getElement
Returns a single element by type, path, or matcher.editor— Editor instance (required).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.editor— Editor instance (required).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 (NodeEntry).
editor— Editor instance (required).options.blockId— ID of the block (required).options.type— Element type.options.path— Path:number[]or'selection'|'first'|'last'; default: selection or[0].
[element, path] or null.
getElementPath
Returns the Slate path of an element instance.editor— Editor instance (required).options.blockId— ID of the block (required).options.element— The element instance (required).
null.
getElementRect
Returns the DOM bounding box for a Slate element (domRect and clientRects).
editor— Editor instance (required).options.blockId— ID of the block (required).options.element— Slate element instance (required).
null if not resolved.
getParentElementPath
Returns the Slate path of an element’s parent.editor— Editor instance (required).options.blockId— ID of the block (required).options.element— The element instance (required).
null.
getElementChildren
Returns the children array of an element.editor— Editor instance (required).options.blockId— ID of the block (required).options.type— Element type (required).options.path— Path to the element; default: selection or[0].
null.
getRootElement
Returns the root element definition for a given block type (plugin). Each plugin defines one or more elements — the root is either the only element in the map, or the one marked withasRoot: true.
editor— Editor instance (required).options.blockType— Plugin type name, PascalCase (required). E.g.'Paragraph','Accordion','Image'.
PluginElement definition, or undefined if the plugin doesn’t exist, has no elements, or no element is marked as root in a multi-element plugin.
isElementEmpty
Checks whether an element has no text content.editor— Editor instance (required).options.blockId— ID of the block (required).options.type— Element type (required).options.path— Path to the element.
true if empty, false otherwise.

