Skip to main content

$getSelectionSlotFrame

function

Returns the slot frame that `selection` lives in, or null when it is outside any slot (or there is no selection). Thin wrapper over $getSlotFrame that picks the node to anchor the walk on. Selection-driven exporters walk this frame instead of the root's children: a selection wholly inside a slot subtree never includes its host (slots are shadow-root isolated), so a root-children walk would miss the selected nodes entirely and produce an empty payload (cut = data loss). Every selection type participates. A RangeSelection anchors on its anchor point; anything else (NodeSelection, TableSelection, or an app-defined BaseSelection) anchors on the first node it reports, which is where a click that selects a decorator or a table nested in a slot is handled. `NodeSelection.getNodes()[0]` is the first node by insertion order (the internal `_nodes` Set's iteration order), not document order. For the common single-node case this is the only node and the frame is unambiguous. A multi-node selection that straddles a slot boundary is currently undefined — slots are shadow-isolated, so straddling is already invalid construction, and we pick the first node's frame rather than asserting.

function $getSelectionSlotFrame(selection: null | BaseSelection): LexicalNode | null

Import

import { $getSelectionSlotFrame } from '@modular/sdk/editor';