Skip to main content

ElementDOMSlot

class

A utility class for managing the DOM children of an ElementNode. Extends DOMSlot with ElementNode-specific scaffolding — the reconciler-managed line break that keeps empty elements selectable, and the offset / index resolution helpers needed when mapping DOM selections onto lexical positions. The base `before` / `after` boundaries and the children mutation helpers (`insertChild`, `removeChild`, …) live on DOMSlot.

class ElementDOMSlot<T extends HTMLElement = HTMLElement>

Import

import { ElementDOMSlot } from '@modular/sdk/editor';

Members10

after
Node | null

Lower boundary: the lexical-managed range starts after this node.

before
Node | null

Upper boundary: the lexical-managed range ends before this node.

element
T

The content-bearing element of the node's DOM.

getFirstChild()
() => ChildNode | null

Returns the first managed child (the first node in `this.element` that is not a non-lexical prelude / decoration), or `null` if there is none. Subclasses may override to also skip reconciler-managed scaffolding such as the managed line break.

insertChild()
(dom: Node) => this

Insert the given node before `this.before` (if defined) or append it to `this.element` otherwise. Subclasses may override to respect additional boundaries (e.g. `ElementDOMSlot` also keeps the managed line break at the end).

removeChild()
(dom: Node) => this

Remove the given child from `this.element`. Throws if it was not a child.

replaceChild()
(dom: Node, prevDom: Node) => this

Replace `prevDom` with `dom`. Throws if `prevDom` is not a child.

withAfter()
(after: Node | undefined | null) => ElementDOMSlot<T>

Return a new slot with `after` updated, preserving subclass type.

withBefore()
(before: Node | undefined | null) => ElementDOMSlot<T>

Return a new slot with `before` updated, preserving subclass type.

withElement()
<ElementType extends HTMLElement>(element: ElementType) => ElementDOMSlot<ElementType>

Return a new slot with `element` updated, preserving subclass type.