/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import type { Klass, LexicalEditor } from './LexicalEditor.js'; import type { LexicalNode, MergeAdjacentConfig, NodeChildrenConfig } from './LexicalNode.js'; /** * @experimental node-structure * * The structural facts a node class declares in `$config()` (`inline`, * `children`, `mergeAdjacent`), each from the nearest class in its config * chain that declares it, and the values it declares `derived`. Keys no class * declares are absent; a `mergeAdjacent: false` declaration reads as absent * too. The object is frozen, and `derived` is a fresh copy on every call. */ export interface DeclaredNodeStructure { readonly inline?: boolean; readonly children?: NodeChildrenConfig; readonly mergeAdjacent?: MergeAdjacentConfig; /** * The schema fields and NodeState keys of the class declared `derived`: * the node's own code recomputes them, so tools that copy or compare a * node's data can leave them out. */ readonly derived: ReadonlySet; /** The class each key came from (for tools that check completeness). */ readonly declaredBy: { readonly inline?: Klass; readonly children?: Klass; readonly mergeAdjacent?: Klass; }; } /** * @experimental node-structure * * Returns the structural declarations of a node class. See * {@link DeclaredNodeStructure}. Depends on the class only. */ export declare function getDeclaredNodeStructure(klass: Klass): DeclaredNodeStructure; /** * @internal Not public API. * * Normalize the subtree rooted at `node` now, as `NodeStructureExtension` * does, bottom-up (which may split `node` in its parent), then merge `node` * (or what it was split into) with its equal siblings. * * The extension normalizes only updates that run transforms: code that * applies an update with `skipTransforms` calls this on what it changed, in * the same update. */ export declare function INTERNAL_$normalizeNodeStructure(node: LexicalNode): void; /** * @internal For `@lexical/extension`'s `NodeStructureExtension` and * `registerNodeStructure`; not public API. * * Enforce the structure node classes declare on `editor` (see * {@link StaticNodeConfigValue.children} and * {@link StaticNodeConfigValue.mergeAdjacent}), and mark every node dirty so * the current document is normalized too. Registrations are counted: the * normalization stops when the last one is disposed. * * Every class gets a transform that records the nodes written in the update, * and the root a transform, which Lexical runs last in each transform pass, * that normalizes from the root down along those nodes' ancestors, visiting * only them and what the repairs move (the first pass after registering * visits the whole document). * * An update applied with `skipTransforms` runs no transform, so it is not * normalized, and a later update repairs only what it changes itself, apart * from the root's inline children, which every update wraps, as core's own * shadow root transform does. Code that applies updates that way calls * {@link INTERNAL_$normalizeNodeStructure} on what it changed. * * @returns A function that disposes this registration */ export declare function INTERNAL_registerNodeStructure(editor: LexicalEditor): () => void; /** * @internal For Lexical's own code; not public API. * * Whether `editor` enforces declared node structure (`NodeStructureExtension` * or `registerNodeStructure` is registered on it). The transforms that also * restructure (the link, list and list item transforms, and core's shadow * root transform) use it to leave to the normalization what it does itself, * and the list and mdast importers to build directly what it keeps, where * the shape they build otherwise would leave something behind once it runs. * Reads a registry only, so code that imports it does not pull in the * normalization. */ export declare function INTERNAL_isNodeStructureEnforced(editor: LexicalEditor): boolean; /** * @internal * * Development check of a class's structural declarations, run when an * editor is created: `mergeAdjacent.by` must name known, non-derived values; * a declared `inline` must agree with an overridden `isInline()`; a class * that lists child classes and merges must list classes that hold inline * content (possibly with a nested instance of the class itself). * * Only keys the class declares in its own `$config()` are checked. A * declaration it merely inherits never throws: where the class contradicts * it, {@link getDeclaredNodeStructure} reads that key as undeclared. */ export declare function validateNodeStructure(klass: Klass): void;