Skip to main content

DOMSlot

class

Base class for DOM slots — a pointer to the content-bearing element of a node's DOM, plus optional `before` / `after` boundaries marking where the lexical-managed content sits inside that element. For ElementNode children management see ElementDOMSlot. For non-Element nodes (TextNode, LineBreakNode, DecoratorNode) the slot still supports an internal `before` / `after` so subclasses can prepend or append non-lexical siblings around the content node and the reconciler / `setTextContent` route the actual content through the slot.

class DOMSlot<T extends HTMLElement = HTMLElement>

Import

import { DOMSlot } 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) => DOMSlot<T>

Return a new slot with `after` updated.

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

Return a new slot with `before` updated.

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

Return a new slot with `element` updated.