Skip to main content

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 the Elements 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.
Parameters:
  • 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' or number[]; 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); use children for block elements.
  • options.match — Custom matcher when using at: 'next' or 'prev'.

updateElement

Updates properties (and optionally text) of an existing element.
Parameters:
  • 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).
Parameters:
  • 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.
Parameters:
  • 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.
Returns: Matching element or null.

getElements

Returns all elements of a type or matching a condition.
Parameters:
  • 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.
Returns: Array of elements; empty if none found.

getElementEntry

Returns element and its Slate path (NodeEntry).
Parameters:
  • 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].
Returns: [element, path] or null.

getElementPath

Returns the Slate path of an element instance.
Parameters:
  • editor — Editor instance (required).
  • options.blockId — ID of the block (required).
  • options.element — The element instance (required).
Returns: Path or null.

getElementRect

Returns the DOM bounding box for a Slate element (domRect and clientRects).
Parameters:
  • editor — Editor instance (required).
  • options.blockId — ID of the block (required).
  • options.element — Slate element instance (required).
Returns: Rects for the DOM node, or null if not resolved.

getParentElementPath

Returns the Slate path of an element’s parent.
Parameters:
  • editor — Editor instance (required).
  • options.blockId — ID of the block (required).
  • options.element — The element instance (required).
Returns: Parent path or null.

getElementChildren

Returns the children array of an element.
Parameters:
  • 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].
Returns: Children array or 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 with asRoot: true.
Parameters:
  • editor — Editor instance (required).
  • options.blockType — Plugin type name, PascalCase (required). E.g. 'Paragraph', 'Accordion', 'Image'.
Returns: The root 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.
Parameters:
  • editor — Editor instance (required).
  • options.blockId — ID of the block (required).
  • options.type — Element type (required).
  • options.path — Path to the element.
Returns: true if empty, false otherwise.