`) reports as captured too.
*
* The walk aborts at the first DOM node that corresponds to a Lexical
* node in `editor` — that boundary is the implicit owner of the subtree's
* selection, so a captureSelection marker above it (in non-Lexical
* scaffolding around the editor) does not leak in.
*
* DecoratorNode DOM is marked with `setDOMUnmanaged({captureSelection:
* true})` by the reconciler, so decorator subtrees also report as
* captured here.
*
* @experimental
*/
export declare function isDOMCapturingSelection(elementDom: Node & LexicalPrivateDOM, editor: LexicalEditor): boolean;
/**
* @internal
*
* Object.hasOwn ponyfill
*/
/**
* @internal
*/
export declare function hasOwnStaticMethod(klass: Klass
, k: keyof Klass): boolean;
export interface OwnStaticNodeConfig {
klass: Klass;
ownNodeType: undefined | string;
ownNodeConfig: undefined | StaticNodeConfigValue;
/**
* Whether `klass` declared `$config()` itself.
*
* `ownNodeConfig` is the config the class *resolves* to, which for a class
* that declared none is its ancestor's — reached through the inherited
* method, and a fresh object each time, since `$config()` builds its result
* per call. Anything walking the chain has to tell the two apart or it
* attributes an ancestor's declarations to the subclass and counts them
* twice; see {@link iterStaticNodeConfigChain}.
*/
declaresOwnConfig: boolean;
}
/**
* Whether the compact form omits `value` for the property named `key` — see
* {@link CompiledNodeClass.isCompactDefault}.
*
* @internal
*/
export type CompactDefaultTest = (key: string, value: unknown) => boolean;
/**
* How `klass` reaches one direction of a serialized property: the
* {@link SchemaField} unchanged when the direct field access holds, and the
* name of the accessor it stands in for when it does not.
*
* A `SchemaField` that names a `method` is saying the two are equivalent *for
* the class that declared it*. A subclass that overrides that method has said
* otherwise, and it wins: before the property had a schema both JSON methods
* went through the accessor, so overriding one changed the node's
* serialization, and compiling the accessor away would silently take that back.
*
* The comparison resolves through each prototype chain, so it catches an
* override anywhere between the declaring class and this one.
*
* `conventional` is the `get`/`set` name for this direction, used
* when the field names no `method` of its own — which is the common case, and
* why nearly every declaration can leave it out. A class that has no such
* method defers to nothing, because both prototypes then resolve `undefined`
* and compare equal; there is no separate way to say "bypass the accessor",
* and deliberately so: a subclass that overrode one always meant to be asked.
*
* Shared with the codegen in `scripts/generate-node-json.mjs`, which has to
* make the identical choice or its literal would describe a different node.
*
* @internal
*/
export declare function resolveSchemaField(klass: Klass, key: string, accessor: T, conventional: string): T | string;
/**
* The default setter name for a serialized property, e.g. `foo` → `setFoo`.
*
* Exported for the same reason {@link resolveSchemaField} is: the codegen in
* `scripts/generate-node-json.mjs` has to derive the identical name, and a
* second copy of the rule is a second thing that can drift.
*
* @internal
*/
export declare function defaultSetterName(key: string): string;
/**
* The default getter name for a serialized property, e.g. `foo` → `getFoo`.
*
* @see {@link defaultSetterName}
* @internal
*/
export declare function defaultGetterName(key: string): string;
/**
* The serialization schema fields and flat NodeStates a node class serializes,
* composed across its config chain. Every consumer of "what does this class
* serialize" derives from this one walk so they cannot disagree about
* precedence: a subclass field overrides an ancestor's, while a re-declared
* flat state keeps the ancestor's config (matching createSharedNodeState).
*
* @internal
*/
export interface ComposedSchema {
/**
* Fields ordered most-derived first — the order properties are written in,
* which the hand-written exportJSON methods this replaces also produced for
* the core classes, and which some tests compare as strings.
*/
readonly fieldsDerivedFirst: readonly (readonly [
string,
AnySerializationSchema
])[];
/**
* The same fields ordered ancestors first — the order setters are applied
* in, so a base property is set before the subclass properties that may
* depend on it.
*/
readonly fieldsBaseFirst: readonly (readonly [
string,
AnySerializationSchema
])[];
/** Flat NodeStates, ancestors first. */
readonly flatStates: readonly AnyStateConfig[];
/**
* The class whose `$config` declared each field's winning schema, which is
* where {@link SchemaFieldBase.method} is measured from: a method the declaring
* class and the node's class resolve differently is one somebody overrode in
* between.
*/
readonly declaredBy: ReadonlyMap>;
/**
* The same winning schemas by key, which is what a class's generated code
* is built from at registration: the lookup tables it reads are these
* schemas' own objects, so the generated module holds no copy of any.
*/
readonly fields: ComposedSchemaFields;
}
/**
* The composed serialization schema of a node class, compiled once per class.
*
* @internal
*/
export declare function getComposedSchema(klass: Klass): ComposedSchema;
/**
* Every node-specific property of a class's serialized JSON — its composed
* serialization schema fields plus any flat NodeState whose value schema is
* introspectable — keyed by serialized property name.
*
* @internal
*/
export declare function getComposedSchemaFields(klass: Klass): Record;
/**
* The accessor `klass` reads a serialized property through: `null` for a
* property declared import-only, the {@link SchemaGetterField} when the direct
* field access holds, and otherwise the name of the getter method.
*
* This is the whole of the export direction's resolution rule, in one place:
* {@link compileGetters} builds the walk's table from it, and the codegen in
* `scripts/generate-node-json.mjs` emits its literal from it, so the two
* cannot describe different nodes.
*
* @internal
*/
export declare function resolveGetterAccessor(klass: Klass, key: string, schema: AnySerializationSchema): null | string | SchemaGetterField;
/**
* The setter mirror of {@link resolveGetterAccessor}.
*
* @internal
*/
export declare function resolveSetterAccessor(klass: Klass, key: string, schema: AnySerializationSchema): null | string | SchemaSetterField;
/**
* Write the serialized properties a node's schema declares, reading each
* through its getter. A getter that returns `undefined` omits the property:
* absent and explicitly-undefined are indistinguishable once the JSON is
* stringified, so this is how an optional (or conditionally persisted)
* property is expressed.
*
* Compaction is applied here rather than as a pass over the finished object:
* with `compact`, a property the parser derives is skipped without calling its
* getter at all, and one whose value equals the schema default parsing would
* restore is simply not written. That leaves nothing for a later pass to
* inspect, so a node that generates its own `exportJSON` can inline the same
* decisions and never consult the schema at runtime.
*
* A field is read off `node` as given, with no `getLatest()`. Serializing a
* graph only needs to resolve its root: every node the walk reaches after that
* comes from the EditorState's node map — `$getRoot()`, `getChildren()`,
* `$getSlot()` — so it is already the current version. (An ephemeral node, such
* as the sliced clone the clipboard walk exports, is deliberately not in the
* map, and reading it as given is the only correct thing to do.)
*
* @internal
*/
export declare function $writeJSONGetters(node: LexicalNode, json: {
[key: string]: unknown;
}, compact: boolean): void;
/**
* The generated JSON functions `klass` runs (see {@link resolveGenerated}), or
* `null`. For tests, which need to know whether a comparison against the walk
* is comparing anything.
*
* @internal
*/
export declare function getGeneratedJSON(klass: Klass): null | GeneratedJSON;
/**
* The schema-driven walk's export of `node` in the form asked for, without
* NodeState, in the key order the generated exporters reproduce. The legacy
* form is `children` first for an element, then every property the schema
* declares through {@link $writeJSONGetters}, then `type` and `version` — the
* order it has always had. The compact form is new and leads with `type`, so
* a node reads type-first and generated code can allocate the object on its
* fixed keys; key order is part of neither format, since parsing reads
* properties by name. What {@link LexicalNode.exportJSON} runs for a class
* without generated code, and what generated code is checked against.
*
* @internal
*/
export declare function $walkExportJSON(node: LexicalNode, compact: boolean): {
[key: string]: unknown;
};
/**
* What the generated exporter writes for `node` in the form asked for, or
* `undefined` when its class has no generated code for that form and the
* schema-driven walk has to run instead.
*
* A generated exporter is only ever right for the exact accessors its class
* resolves, which is what {@link resolveGenerated} settled at registration.
* Both forms are generated — which properties the compact one drops depends on
* a node's values, but the rule does not, so each form is its own
* straight-line function. NodeState is not part of either: what a node carries
* is not known when the code is generated, so {@link LexicalNode.exportJSON}
* appends it to this result and to the walk's alike.
*
* @internal
*/
/**
* What a node exports in the form asked for: the generated exporter where its
* class has one for that form, and the schema-driven walk otherwise.
*
* One function because both halves start by resolving the class record, and
* asking twice — once to find there is no generated code, once to walk —
* repeated a WeakMap read and, in DEV, the own-field validation, per node per
* export. That is the path every node whose class the generator could not
* compile takes, which is most nodes outside the core.
*
* @internal
*/
export declare function $exportNodeJSONOnce(node: LexicalNode, compact: boolean): {
[key: string]: unknown;
};
export declare function $generatedExportJSON(node: LexicalNode, compact: boolean): undefined | {
[key: string]: unknown;
};
/**
* Apply a serialized node to one this update has just constructed, which is
* what {@link LexicalNode.importJSON} does after building the node.
*
* The difference from {@link LexicalNode.updateFromJSON} is the `getWritable()`
* that one opens with. It has to: it is public API and may be handed any node,
* from any version, at any point in an update. A node `importJSON` just built
* is none of those things — {@link $setNodeKey} put it in the node map, in the
* dirty set and in `_cloneNotNeeded` a moment earlier, so it already *is* the
* writable latest version and `getWritable()` can only re-derive what the
* constructor established: resolve the latest by key, re-mark a node that is
* already dirty, and walk parents it does not yet have.
*
* That cost is per node and the parse path pays it for every node in the
* document, which is why this exists rather than the caller simply chaining
* `updateFromJSON`. The node a replacement returns is fresh in the same sense —
* {@link $applyNodeReplacement} requires it to carry a key of its own — so it
* qualifies too.
*
* @internal
*/
export declare function $applyImportJSON(node: T, serializedNode: LexicalParseJSON): T;
/**
* Apply a node's compiled serialization schema (see {@link compileSetters}),
* returning the (writable) node: flat NodeState first, then the schema's
* properties — through the class's generated parser when it has one, and
* otherwise by calling each property's setter with its parsed value. Used by
* the base {@link LexicalNode.updateFromJSON} so a node that declares a
* serialization schema needs no `updateFromJSON` boilerplate.
*
* @internal
*/
export declare function $applyJSONSetters(node: T, serializedNode: {
readonly [key: string]: unknown;
}): T;
/**
* {@link $applyJSONSetters} with the generated parser left out — the
* schema-driven walk alone — which is what generated code is checked against.
*
* @internal
*/
export declare function $walkJSONSetters(node: T, serializedNode: {
readonly [key: string]: unknown;
}): T;
/** @internal */
export declare function getStaticNodeConfig(klass: Klass): OwnStaticNodeConfig;
/**
* Whether `isInline` (an `isInline` method found on a prototype) was
* synthesized from a `$config({inline})` declaration.
*
* @internal
*/
export declare function isSynthesizedIsInline(isInline: unknown): boolean;
/**
* Whether `klass` wrote its own `afterCloneFrom`, rather than taking the one
* its schema implies.
*
* For a code generator deciding whether to *attach* the copy half: a class that
* wrote its own keeps it, so a generated function handed to it through
* `$config` would be shipped and never called. The function is still worth
* generating — `ElementNode` and `CodeNode` import and call it, so what they
* write by hand is only the fields no schema describes — it is the attachment
* that is pointless. Asked of the class itself rather than of the prototype,
* because after one registration every class in a chain has an own
* `afterCloneFrom` and only the marker says which kind.
*
* @internal
*/
export declare function declaresOwnAfterCloneFrom(klass: Klass): boolean;
/**
* The node fields a class carries across a clone: the ones its own `$config`
* declares, less any an ancestor declares too.
*
* A class re-declares an inherited property to change how it is *serialized* —
* `TabNode` restates `text`, `detail` and `mode` for their accessors and
* narrower domains — which makes it the owner of that key in its own
* composition and in every subclass's. Where it is *stored* does not change,
* though, and the ancestor's `afterCloneFrom` already ran by then and is
* responsible for the fields it declares, so assigning them a second time
* writes the same values again for nothing.
*
* The ancestor's declarations are what is subtracted, not the fields it
* actually assigns, and the two are the same set transitively: an ancestor
* that skipped a field skipped it because *its* own ancestor declares it, and
* that class is in this chain too.
*
* Shared with the codegen in `scripts/shared/generateNodeJSON.mjs`, which emits
* the straight-line form of exactly this list, so the two cannot disagree about
* which class carries which field.
*
* @internal
*/
export declare function ownSchemaFields(klass: Klass): readonly string[];
/**
* Collect all configuration for this class and its superclasses
*
* @internal
*/
export declare function iterStaticNodeConfigChain(klass: Klass): Iterable;
/**
* Build a map from each registered node type to the set of registered node
* types that are it or extend it (including the type itself). For every node
* class in `nodes`, its prototype chain is walked and the class's own type is
* added to the bucket of each registered ancestor type it inherits from.
*
* The result lets callers expand a base node type to all of its registered
* subclass types up front, so a subclass instance can be matched by type
* without a runtime `instanceof`.
*
* @experimental
*/
export declare function getRegisteredSubtypeMap(nodes: Iterable>): Map>;
/**
* Create an node from its class.
*
* This directly constructs the final `withKlass` node type, skipping the
* intermediate steps where each replaced node would be created and then
* immediately discarded — once per configured replacement of that node.
*
* A deprecated `replace` given without a `withKlass` is the one case that
* cannot be resolved ahead of construction, since only its `with` function
* knows what to build. Such a replacement is still applied, the old way, to
* the node this constructs.
*
* This does not support any arguments to the constructor.
* Setters can be used to initialize your node, and they can
* be chained. You can of course write your own mutliple-argument functions
* to wrap that.
*
* @example
* ```ts
* function $createTokenText(text: string): TextNode {
* return $create(TextNode).setTextContent(text).setMode('token');
* }
* ```
*/
export declare function $create(klass: Klass): T;
/**
* Starts with a node and moves up the tree (toward the root node) to find a matching node based on
* the search parameters of the findFn. (Consider JavaScripts' .find() function where a testing function must be
* passed as an argument. eg. if( (node) => node.__type === 'div') ) return true; otherwise return false
* @param startingNode - The node where the search starts.
* @param findFn - A testing function that returns true if the current node satisfies the testing parameters.
* @returns `startingNode` or one of its ancestors that matches the `findFn` predicate and is not the `RootNode`, or `null` if no match was found.
*/
export declare const $findMatchingParent: {
(startingNode: LexicalNode, findFn: (node: LexicalNode) => node is T): T | null;
(startingNode: LexicalNode, findFn: (node: LexicalNode) => boolean): LexicalNode | null;
};
/** Builds an ordered array of child node keys for the given ElementNode by walking its linked-list pointers. */
export declare function $createChildrenArray(element: ElementNode, nodeMap: null | NodeMap): NodeKey[];
/**
* Look up the superclass of this class, prefer
* {@link iterStaticNodeConfigChain} when implementing loops.
*
* @internal
*/
export declare function getSuperclassOf(klass: Klass): null | Klass;