@lobehub/editor 3.3.2 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/es/editor-kernel/index.d.ts +1 -0
  2. package/es/editor-kernel/index.js +3 -1
  3. package/es/editor-kernel/kernel.js +1 -0
  4. package/es/editor-kernel/lexical/Lexical.dev.js +3052 -0
  5. package/es/editor-kernel/lexical/Lexical.dev.mjs +15365 -0
  6. package/es/editor-kernel/lexical/Lexical.js +7634 -0
  7. package/es/editor-kernel/lexical/Lexical.mjs +7258 -0
  8. package/es/editor-kernel/lexical/LexicalCommands.d.ts +175 -0
  9. package/es/editor-kernel/lexical/LexicalConstants.d.ts +54 -0
  10. package/es/editor-kernel/lexical/LexicalEditor.d.ts +672 -0
  11. package/es/editor-kernel/lexical/LexicalEditorState.d.ts +39 -0
  12. package/es/editor-kernel/lexical/LexicalEvents.d.ts +22 -0
  13. package/es/editor-kernel/lexical/LexicalGC.d.ts +23 -0
  14. package/es/editor-kernel/lexical/LexicalMutations.d.ts +12 -0
  15. package/es/editor-kernel/lexical/LexicalNode.d.ts +689 -0
  16. package/es/editor-kernel/lexical/LexicalNodeState.d.ts +569 -0
  17. package/es/editor-kernel/lexical/LexicalNormalization.d.ts +11 -0
  18. package/es/editor-kernel/lexical/LexicalReconciler.d.ts +28 -0
  19. package/es/editor-kernel/lexical/LexicalSelection.d.ts +368 -0
  20. package/es/editor-kernel/lexical/LexicalUpdateTags.d.ts +67 -0
  21. package/es/editor-kernel/lexical/LexicalUpdates.d.ts +72 -0
  22. package/es/editor-kernel/lexical/LexicalUtils.d.ts +492 -0
  23. package/es/editor-kernel/lexical/caret/LexicalCaret.d.ts +635 -0
  24. package/es/editor-kernel/lexical/caret/LexicalCaretUtils.d.ts +224 -0
  25. package/es/editor-kernel/lexical/extension-core/defineExtension.d.ts +126 -0
  26. package/es/editor-kernel/lexical/extension-core/index.d.ts +38 -0
  27. package/es/editor-kernel/lexical/extension-core/internal.d.ts +32 -0
  28. package/es/editor-kernel/lexical/extension-core/safeCast.d.ts +15 -0
  29. package/es/editor-kernel/lexical/extension-core/shallowMergeConfig.d.ts +20 -0
  30. package/es/editor-kernel/lexical/extension-core/types.d.ts +371 -0
  31. package/es/editor-kernel/lexical/index.d.ts +368 -0
  32. package/es/editor-kernel/lexical/nodes/ArtificialNode.d.ts +16 -0
  33. package/es/editor-kernel/lexical/nodes/LexicalDecoratorNode.d.ts +32 -0
  34. package/es/editor-kernel/lexical/nodes/LexicalElementNode.d.ts +235 -0
  35. package/es/editor-kernel/lexical/nodes/LexicalLineBreakNode.d.ts +30 -0
  36. package/es/editor-kernel/lexical/nodes/LexicalParagraphNode.d.ts +39 -0
  37. package/es/editor-kernel/lexical/nodes/LexicalRootNode.d.ts +35 -0
  38. package/es/editor-kernel/lexical/nodes/LexicalTabNode.d.ts +30 -0
  39. package/es/editor-kernel/lexical/nodes/LexicalTextNode.d.ts +311 -0
  40. package/es/plugins/common/data-source/json-data-source.js +29 -3
  41. package/es/plugins/common/react/ReactPlainText.js +9 -0
  42. package/es/plugins/common/utils/index.d.ts +2 -1
  43. package/es/plugins/common/utils/index.js +33 -0
  44. package/es/plugins/litexml/command/index.js +9 -1
  45. package/es/plugins/litexml/data-source/litexml-data-source.js +12 -2
  46. package/es/plugins/litexml/plugin/index.js +41 -3
  47. package/es/plugins/litexml/utils/index.d.ts +2 -1
  48. package/es/plugins/litexml/utils/index.js +7 -1
  49. package/es/plugins/markdown/data-source/markdown-data-source.js +6 -25
  50. package/es/plugins/markdown/data-source/markdown-writer-context.d.ts +5 -1
  51. package/es/plugins/markdown/data-source/markdown-writer-context.js +27 -2
  52. package/es/plugins/markdown/service/shortcut.d.ts +7 -0
  53. package/es/types/kernel.d.ts +4 -0
  54. package/package.json +8 -2
  55. package/scripts/patch-lexical.js +39 -0
@@ -0,0 +1,689 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { type DecoratorNode, type ElementNode, NODE_STATE_KEY } from '.';
9
+ import { PROTOTYPE_CONFIG_METHOD } from './LexicalConstants';
10
+ import type { EditorConfig, Klass, KlassConstructor, LexicalEditor } from './LexicalEditor';
11
+ import {
12
+ type NodeState,
13
+ type NodeStateJSON,
14
+ type Prettify,
15
+ type RequiredNodeStateConfig,
16
+ } from './LexicalNodeState';
17
+ import type { BaseSelection, RangeSelection } from './LexicalSelection';
18
+
19
+ export type NodeMap = Map<NodeKey, LexicalNode>;
20
+ /**
21
+ * The base type for all serialized nodes
22
+ */
23
+ export type SerializedLexicalNode = {
24
+ /** The type string used by the Node class */
25
+ type: string;
26
+ /** A numeric version for this schema, defaulting to 1, but not generally recommended for use */
27
+ version: number;
28
+ /**
29
+ * Any state persisted with the NodeState API that is not
30
+ * configured for flat storage
31
+ */
32
+ [NODE_STATE_KEY]?: Record<string, unknown>;
33
+ };
34
+ /**
35
+ * EXPERIMENTAL
36
+ * The configuration of a node returned by LexicalNode.$config()
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * class CustomText extends TextNode {
41
+ * $config() {
42
+ * return this.config('custom-text', {extends: TextNode}};
43
+ * }
44
+ * }
45
+ * ```
46
+ */
47
+ export interface StaticNodeConfigValue<T extends LexicalNode, Type extends string> {
48
+ /**
49
+ * The exact type of T.getType(), e.g. 'text' - the method itself must
50
+ * have a more generic 'string' type to be compatible wtih subclassing.
51
+ */
52
+ readonly type?: Type;
53
+ /**
54
+ * An alternative to the internal static transform() method
55
+ * that provides better type inference. If implemented this
56
+ * transform will be registered for this class and any subclass.
57
+ */
58
+ readonly $transform?: (node: T) => void;
59
+ /**
60
+ * An alternative to the static importJSON() method
61
+ * that provides better type inference.
62
+ */
63
+ readonly $importJSON?: (serializedNode: SerializedLexicalNode) => T;
64
+ /**
65
+ * An alternative to the static importDOM() method
66
+ */
67
+ readonly importDOM?: DOMConversionMap;
68
+ /**
69
+ * EXPERIMENTAL
70
+ *
71
+ * An array of RequiredNodeStateConfig to initialize your node with
72
+ * its state requirements. This may be used to configure serialization of
73
+ * that state.
74
+ *
75
+ * This function will be called (at most) once per editor initialization,
76
+ * directly on your node's prototype. It must not depend on any state
77
+ * initialized in the constructor.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const flatState = createState("flat", {parse: parseNumber});
82
+ * const nestedState = createState("nested", {parse: parseNumber});
83
+ * class MyNode extends TextNode {
84
+ * $config() {
85
+ * return this.config(
86
+ * 'my-node',
87
+ * {
88
+ * extends: TextNode,
89
+ * stateConfigs: [
90
+ * { stateConfig: flatState, flat: true},
91
+ * nestedState,
92
+ * ]
93
+ * },
94
+ * );
95
+ * }
96
+ * }
97
+ * ```
98
+ */
99
+ readonly stateConfigs?: readonly RequiredNodeStateConfig[];
100
+ /**
101
+ * If specified, this must be the exact superclass of the node. It is not
102
+ * checked at compile time and it is provided automatically at runtime.
103
+ *
104
+ * You would want to specify this when you are extending a node that
105
+ * has non-trivial configuration in its $config such
106
+ * as required state. If you do not specify this, the inferred
107
+ * types for your node class might be missing some of that.
108
+ */
109
+ readonly extends?: Klass<LexicalNode>;
110
+ }
111
+ /**
112
+ * This is the type of LexicalNode.$config() that can be
113
+ * overridden by subclasses.
114
+ */
115
+ export type BaseStaticNodeConfig = {
116
+ readonly [K in string]?: StaticNodeConfigValue<LexicalNode, string>;
117
+ };
118
+ /**
119
+ * Used to extract the node and type from a StaticNodeConfigRecord
120
+ */
121
+ export type StaticNodeConfig<T extends LexicalNode, Type extends string> = BaseStaticNodeConfig & {
122
+ readonly [K in Type]?: StaticNodeConfigValue<T, Type>;
123
+ };
124
+ /**
125
+ * Any StaticNodeConfigValue (for generics and collections)
126
+ */
127
+ export type AnyStaticNodeConfigValue = StaticNodeConfigValue<any, any>;
128
+ /**
129
+ * @internal
130
+ *
131
+ * This is the more specific type than BaseStaticNodeConfig that a subclass
132
+ * should return from $config()
133
+ */
134
+ export type StaticNodeConfigRecord<
135
+ Type extends string,
136
+ Config extends AnyStaticNodeConfigValue,
137
+ > = BaseStaticNodeConfig & {
138
+ readonly [K in Type]?: Config;
139
+ };
140
+ /**
141
+ * Extract the type from a node based on its $config
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * type TextNodeType = GetStaticNodeType<TextNode>;
146
+ * // ? 'text'
147
+ * ```
148
+ */
149
+ export type GetStaticNodeType<T extends LexicalNode> =
150
+ ReturnType<T[typeof PROTOTYPE_CONFIG_METHOD]> extends StaticNodeConfig<T, infer Type>
151
+ ? Type
152
+ : string;
153
+ /**
154
+ * The most precise type we can infer for the JSON that will
155
+ * be produced by T.exportJSON().
156
+ *
157
+ * Do not use this for the return type of T.exportJSON()! It must be
158
+ * a more generic type to be compatible with subclassing.
159
+ */
160
+ export type LexicalExportJSON<T extends LexicalNode> = Prettify<
161
+ Omit<ReturnType<T['exportJSON']>, 'type'> & {
162
+ type: GetStaticNodeType<T>;
163
+ } & NodeStateJSON<T>
164
+ >;
165
+ /**
166
+ * Omit the children, type, and version properties from the given SerializedLexicalNode definition.
167
+ */
168
+ export type LexicalUpdateJSON<T extends SerializedLexicalNode> = Omit<
169
+ T,
170
+ 'children' | 'type' | 'version'
171
+ >;
172
+ /** @internal */
173
+ export interface LexicalPrivateDOM {
174
+ __lexicalTextContent?: string | undefined | null;
175
+ __lexicalLineBreak?: HTMLBRElement | HTMLImageElement | undefined | null;
176
+ __lexicalDirTextContent?: string | undefined | null;
177
+ __lexicalDir?: 'ltr' | 'rtl' | null | undefined;
178
+ __lexicalUnmanaged?: boolean | undefined;
179
+ }
180
+ export declare function $removeNode(
181
+ nodeToRemove: LexicalNode,
182
+ restoreSelection: boolean,
183
+ preserveEmptyParent?: boolean,
184
+ ): void;
185
+ export type DOMConversionProp<T extends HTMLElement> = (node: T) => DOMConversion<T> | null;
186
+ export type DOMConversionPropByTagName<K extends string> = DOMConversionProp<
187
+ K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement
188
+ >;
189
+ export type DOMConversionTagNameMap<K extends string> = {
190
+ [NodeName in K]?: DOMConversionPropByTagName<NodeName>;
191
+ };
192
+ /**
193
+ * An identity function that will infer the type of DOM nodes
194
+ * based on tag names to make it easier to construct a
195
+ * DOMConversionMap.
196
+ */
197
+ export declare function buildImportMap<K extends string>(importMap: {
198
+ [NodeName in K]: DOMConversionPropByTagName<NodeName>;
199
+ }): DOMConversionMap;
200
+ export type DOMConversion<T extends HTMLElement = HTMLElement> = {
201
+ conversion: DOMConversionFn<T>;
202
+ priority?: 0 | 1 | 2 | 3 | 4;
203
+ };
204
+ export type DOMConversionFn<T extends HTMLElement = HTMLElement> = (
205
+ element: T,
206
+ ) => DOMConversionOutput | null;
207
+ export type DOMChildConversion = (
208
+ lexicalNode: LexicalNode,
209
+ parentLexicalNode: LexicalNode | null | undefined,
210
+ ) => LexicalNode | null | undefined;
211
+ export type DOMConversionMap<T extends HTMLElement = HTMLElement> = Record<
212
+ NodeName,
213
+ DOMConversionProp<T>
214
+ >;
215
+ type NodeName = string;
216
+ export type DOMConversionOutput = {
217
+ after?: (childLexicalNodes: Array<LexicalNode>) => Array<LexicalNode>;
218
+ forChild?: DOMChildConversion;
219
+ node: null | LexicalNode | Array<LexicalNode>;
220
+ };
221
+ export type DOMExportOutputMap = Map<
222
+ Klass<LexicalNode>,
223
+ (editor: LexicalEditor, target: LexicalNode) => DOMExportOutput
224
+ >;
225
+ export type DOMExportOutput = {
226
+ after?: (
227
+ generatedElement: HTMLElement | DocumentFragment | Text | null | undefined,
228
+ ) => HTMLElement | DocumentFragment | Text | null | undefined;
229
+ element: HTMLElement | DocumentFragment | Text | null;
230
+ };
231
+ export type NodeKey = string;
232
+ declare const EPHEMERAL: unique symbol;
233
+ /**
234
+ * @internal
235
+ * @param node any LexicalNode
236
+ * @returns true if the node was created with {@link $cloneWithPropertiesEphemeral}
237
+ */
238
+ export declare function $isEphemeral(
239
+ node: LexicalNode & {
240
+ readonly [EPHEMERAL]?: boolean;
241
+ },
242
+ ): boolean;
243
+ /**
244
+ * @internal
245
+ * Mark this node as ephemeral, its instance always returns this
246
+ * for getLatest and getWritable. It must not be added to an EditorState.
247
+ */
248
+ export declare function $markEphemeral<T extends LexicalNode>(
249
+ node: T & {
250
+ [EPHEMERAL]?: boolean;
251
+ },
252
+ ): T;
253
+ export declare class LexicalNode {
254
+ /** @internal Allow us to look up the type including static props */
255
+ ['constructor']: KlassConstructor<typeof LexicalNode>;
256
+ /** @internal */
257
+ __type: string;
258
+ /** @internal */
259
+ __key: string;
260
+ /** @internal */
261
+ __parent: null | NodeKey;
262
+ /** @internal */
263
+ __prev: null | NodeKey;
264
+ /** @internal */
265
+ __next: null | NodeKey;
266
+ /** @internal */
267
+ __state?: NodeState<this>;
268
+ /**
269
+ * Returns the string type of this node. Every node must
270
+ * implement this and it MUST BE UNIQUE amongst nodes registered
271
+ * on the editor.
272
+ *
273
+ */
274
+ static getType(): string;
275
+ /**
276
+ * Clones this node, creating a new node with a different key
277
+ * and adding it to the EditorState (but not attaching it anywhere!). All nodes must
278
+ * implement this method.
279
+ *
280
+ */
281
+ static clone(_data: unknown): LexicalNode;
282
+ /**
283
+ * Override this to implement the new static node configuration protocol,
284
+ * this method is called directly on the prototype and must not depend
285
+ * on anything initialized in the constructor. Generally it should be
286
+ * a trivial implementation.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * class MyNode extends TextNode {
291
+ * $config() {
292
+ * return this.config('my-node', {extends: TextNode});
293
+ * }
294
+ * }
295
+ * ```
296
+ */
297
+ $config(): BaseStaticNodeConfig;
298
+ /**
299
+ * This is a convenience method for $config that
300
+ * aids in type inference. See {@link LexicalNode.$config}
301
+ * for example usage.
302
+ */
303
+ config<Type extends string, Config extends StaticNodeConfigValue<this, Type>>(
304
+ type: Type,
305
+ config: Config,
306
+ ): StaticNodeConfigRecord<Type, Config>;
307
+ /**
308
+ * Perform any state updates on the clone of prevNode that are not already
309
+ * handled by the constructor call in the static clone method. If you have
310
+ * state to update in your clone that is not handled directly by the
311
+ * constructor, it is advisable to override this method but it is required
312
+ * to include a call to `super.afterCloneFrom(prevNode)` in your
313
+ * implementation. This is only intended to be called by
314
+ * {@link $cloneWithProperties} function or via a super call.
315
+ *
316
+ * @example
317
+ * ```ts
318
+ * class ClassesTextNode extends TextNode {
319
+ * // Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
320
+ * __classes = new Set<string>();
321
+ * static clone(node: ClassesTextNode): ClassesTextNode {
322
+ * // The inherited TextNode constructor is used here, so
323
+ * // classes is not set by this method.
324
+ * return new ClassesTextNode(node.__text, node.__key);
325
+ * }
326
+ * afterCloneFrom(node: this): void {
327
+ * // This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
328
+ * // for necessary state updates
329
+ * super.afterCloneFrom(node);
330
+ * this.__addClasses(node.__classes);
331
+ * }
332
+ * // This method is a private implementation detail, it is not
333
+ * // suitable for the public API because it does not call getWritable
334
+ * __addClasses(classNames: Iterable<string>): this {
335
+ * for (const className of classNames) {
336
+ * this.__classes.add(className);
337
+ * }
338
+ * return this;
339
+ * }
340
+ * addClass(...classNames: string[]): this {
341
+ * return this.getWritable().__addClasses(classNames);
342
+ * }
343
+ * removeClass(...classNames: string[]): this {
344
+ * const node = this.getWritable();
345
+ * for (const className of classNames) {
346
+ * this.__classes.delete(className);
347
+ * }
348
+ * return this;
349
+ * }
350
+ * getClasses(): Set<string> {
351
+ * return this.getLatest().__classes;
352
+ * }
353
+ * }
354
+ * ```
355
+ *
356
+ */
357
+ afterCloneFrom(prevNode: this): void;
358
+ static importDOM?: () => DOMConversionMap<any> | null;
359
+ constructor(key?: NodeKey);
360
+ /**
361
+ * Returns the string type of this node.
362
+ */
363
+ getType(): string;
364
+ isInline(): boolean;
365
+ /**
366
+ * Returns true if there is a path between this node and the RootNode, false otherwise.
367
+ * This is a way of determining if the node is "attached" EditorState. Unattached nodes
368
+ * won't be reconciled and will ultimately be cleaned up by the Lexical GC.
369
+ */
370
+ isAttached(): boolean;
371
+ /**
372
+ * Returns true if this node is contained within the provided Selection., false otherwise.
373
+ * Relies on the algorithms implemented in {@link BaseSelection.getNodes} to determine
374
+ * what's included.
375
+ *
376
+ * @param selection - The selection that we want to determine if the node is in.
377
+ */
378
+ isSelected(selection?: null | BaseSelection): boolean;
379
+ /**
380
+ * Returns this nodes key.
381
+ */
382
+ getKey(): NodeKey;
383
+ /**
384
+ * Returns the zero-based index of this node within the parent.
385
+ */
386
+ getIndexWithinParent(): number;
387
+ /**
388
+ * Returns the parent of this node, or null if none is found.
389
+ */
390
+ getParent<T extends ElementNode>(): T | null;
391
+ /**
392
+ * Returns the parent of this node, or throws if none is found.
393
+ */
394
+ getParentOrThrow<T extends ElementNode>(): T;
395
+ /**
396
+ * Returns the highest (in the EditorState tree)
397
+ * non-root ancestor of this node, or null if none is found. See {@link lexical!$isRootOrShadowRoot}
398
+ * for more information on which Elements comprise "roots".
399
+ */
400
+ getTopLevelElement(): ElementNode | DecoratorNode<unknown> | null;
401
+ /**
402
+ * Returns the highest (in the EditorState tree)
403
+ * non-root ancestor of this node, or throws if none is found. See {@link lexical!$isRootOrShadowRoot}
404
+ * for more information on which Elements comprise "roots".
405
+ */
406
+ getTopLevelElementOrThrow(): ElementNode | DecoratorNode<unknown>;
407
+ /**
408
+ * Returns a list of the every ancestor of this node,
409
+ * all the way up to the RootNode.
410
+ *
411
+ */
412
+ getParents(): Array<ElementNode>;
413
+ /**
414
+ * Returns a list of the keys of every ancestor of this node,
415
+ * all the way up to the RootNode.
416
+ *
417
+ */
418
+ getParentKeys(): Array<NodeKey>;
419
+ /**
420
+ * Returns the "previous" siblings - that is, the node that comes
421
+ * before this one in the same parent.
422
+ *
423
+ */
424
+ getPreviousSibling<T extends LexicalNode>(): T | null;
425
+ /**
426
+ * Returns the "previous" siblings - that is, the nodes that come between
427
+ * this one and the first child of it's parent, inclusive.
428
+ *
429
+ */
430
+ getPreviousSiblings<T extends LexicalNode>(): Array<T>;
431
+ /**
432
+ * Returns the "next" siblings - that is, the node that comes
433
+ * after this one in the same parent
434
+ *
435
+ */
436
+ getNextSibling<T extends LexicalNode>(): T | null;
437
+ /**
438
+ * Returns all "next" siblings - that is, the nodes that come between this
439
+ * one and the last child of it's parent, inclusive.
440
+ *
441
+ */
442
+ getNextSiblings<T extends LexicalNode>(): Array<T>;
443
+ /**
444
+ * @deprecated use {@link $getCommonAncestor}
445
+ *
446
+ * Returns the closest common ancestor of this node and the provided one or null
447
+ * if one cannot be found.
448
+ *
449
+ * @param node - the other node to find the common ancestor of.
450
+ */
451
+ getCommonAncestor<T extends ElementNode = ElementNode>(node: LexicalNode): T | null;
452
+ /**
453
+ * Returns true if the provided node is the exact same one as this node, from Lexical's perspective.
454
+ * Always use this instead of referential equality.
455
+ *
456
+ * @param object - the node to perform the equality comparison on.
457
+ */
458
+ is(object: LexicalNode | null | undefined): boolean;
459
+ /**
460
+ * Returns true if this node logically precedes the target node in the
461
+ * editor state, false otherwise (including if there is no common ancestor).
462
+ *
463
+ * Note that this notion of isBefore is based on post-order; a descendant
464
+ * node is always before its ancestors. See also
465
+ * {@link $getCommonAncestor} and {@link $comparePointCaretNext} for
466
+ * more flexible ways to determine the relative positions of nodes.
467
+ *
468
+ * @param targetNode - the node we're testing to see if it's after this one.
469
+ */
470
+ isBefore(targetNode: LexicalNode): boolean;
471
+ /**
472
+ * Returns true if this node is an ancestor of and distinct from the target node, false otherwise.
473
+ *
474
+ * @param targetNode - the would-be child node.
475
+ */
476
+ isParentOf(targetNode: LexicalNode): boolean;
477
+ /**
478
+ * Returns a list of nodes that are between this node and
479
+ * the target node in the EditorState.
480
+ *
481
+ * @param targetNode - the node that marks the other end of the range of nodes to be returned.
482
+ */
483
+ getNodesBetween(targetNode: LexicalNode): Array<LexicalNode>;
484
+ /**
485
+ * Returns true if this node has been marked dirty during this update cycle.
486
+ *
487
+ */
488
+ isDirty(): boolean;
489
+ /**
490
+ * Returns the latest version of the node from the active EditorState.
491
+ * This is used to avoid getting values from stale node references.
492
+ *
493
+ */
494
+ getLatest(): this;
495
+ /**
496
+ * Returns a mutable version of the node using {@link $cloneWithProperties}
497
+ * if necessary. Will throw an error if called outside of a Lexical Editor
498
+ * {@link LexicalEditor.update} callback.
499
+ *
500
+ */
501
+ getWritable(): this;
502
+ /**
503
+ * Returns the text content of the node. Override this for
504
+ * custom nodes that should have a representation in plain text
505
+ * format (for copy + paste, for example)
506
+ *
507
+ */
508
+ getTextContent(): string;
509
+ /**
510
+ * Returns the length of the string produced by calling getTextContent on this node.
511
+ *
512
+ */
513
+ getTextContentSize(): number;
514
+ /**
515
+ * Called during the reconciliation process to determine which nodes
516
+ * to insert into the DOM for this Lexical Node.
517
+ *
518
+ * This method must return exactly one HTMLElement. Nested elements are not supported.
519
+ *
520
+ * Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.
521
+ *
522
+ * @param _config - allows access to things like the EditorTheme (to apply classes) during reconciliation.
523
+ * @param _editor - allows access to the editor for context during reconciliation.
524
+ *
525
+ * */
526
+ createDOM(_config: EditorConfig, _editor: LexicalEditor): HTMLElement;
527
+ /**
528
+ * Called when a node changes and should update the DOM
529
+ * in whatever way is necessary to make it align with any changes that might
530
+ * have happened during the update.
531
+ *
532
+ * Returning "true" here will cause lexical to unmount and recreate the DOM node
533
+ * (by calling createDOM). You would need to do this if the element tag changes,
534
+ * for instance.
535
+ *
536
+ * */
537
+ updateDOM(_prevNode: unknown, _dom: HTMLElement, _config: EditorConfig): boolean;
538
+ /**
539
+ * Controls how the this node is serialized to HTML. This is important for
540
+ * copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces,
541
+ * in which case the primary transfer format is HTML. It's also important if you're serializing
542
+ * to HTML for any other reason via {@link @lexical/html!$generateHtmlFromNodes}. You could
543
+ * also use this method to build your own HTML renderer.
544
+ *
545
+ * */
546
+ exportDOM(editor: LexicalEditor): DOMExportOutput;
547
+ /**
548
+ * Controls how the this node is serialized to JSON. This is important for
549
+ * copy and paste between Lexical editors sharing the same namespace. It's also important
550
+ * if you're serializing to JSON for persistent storage somewhere.
551
+ * See [Serialization & Deserialization](https://lexical.dev/docs/concepts/serialization#lexical---html).
552
+ *
553
+ * */
554
+ exportJSON(): SerializedLexicalNode;
555
+ /**
556
+ * Controls how the this node is deserialized from JSON. This is usually boilerplate,
557
+ * but provides an abstraction between the node implementation and serialized interface that can
558
+ * be important if you ever make breaking changes to a node schema (by adding or removing properties).
559
+ * See [Serialization & Deserialization](https://lexical.dev/docs/concepts/serialization#lexical---html).
560
+ *
561
+ * */
562
+ static importJSON(_serializedNode: SerializedLexicalNode): LexicalNode;
563
+ /**
564
+ * Update this LexicalNode instance from serialized JSON. It's recommended
565
+ * to implement as much logic as possible in this method instead of the
566
+ * static importJSON method, so that the functionality can be inherited in subclasses.
567
+ *
568
+ * The LexicalUpdateJSON utility type should be used to ignore any type, version,
569
+ * or children properties in the JSON so that the extended JSON from subclasses
570
+ * are acceptable parameters for the super call.
571
+ *
572
+ * If overridden, this method must call super.
573
+ *
574
+ * @example
575
+ * ```ts
576
+ * class MyTextNode extends TextNode {
577
+ * // ...
578
+ * static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
579
+ * return $createMyTextNode()
580
+ * .updateFromJSON(serializedNode);
581
+ * }
582
+ * updateFromJSON(
583
+ * serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
584
+ * ): this {
585
+ * return super.updateFromJSON(serializedNode)
586
+ * .setMyProperty(serializedNode.myProperty);
587
+ * }
588
+ * }
589
+ * ```
590
+ **/
591
+ updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedLexicalNode>): this;
592
+ /**
593
+ * @experimental
594
+ *
595
+ * Registers the returned function as a transform on the node during
596
+ * Editor initialization. Most such use cases should be addressed via
597
+ * the {@link LexicalEditor.registerNodeTransform} API.
598
+ *
599
+ * Experimental - use at your own risk.
600
+ */
601
+ static transform(): ((node: LexicalNode) => void) | null;
602
+ /**
603
+ * Removes this LexicalNode from the EditorState. If the node isn't re-inserted
604
+ * somewhere, the Lexical garbage collector will eventually clean it up.
605
+ *
606
+ * @param preserveEmptyParent - If falsy, the node's parent will be removed if
607
+ * it's empty after the removal operation. This is the default behavior, subject to
608
+ * other node heuristics such as {@link ElementNode#canBeEmpty}
609
+ * */
610
+ remove(preserveEmptyParent?: boolean): void;
611
+ /**
612
+ * Replaces this LexicalNode with the provided node, optionally transferring the children
613
+ * of the replaced node to the replacing node.
614
+ *
615
+ * @param replaceWith - The node to replace this one with.
616
+ * @param includeChildren - Whether or not to transfer the children of this node to the replacing node.
617
+ * */
618
+ replace<N extends LexicalNode>(replaceWith: N, includeChildren?: boolean): N;
619
+ /**
620
+ * Inserts a node after this LexicalNode (as the next sibling).
621
+ *
622
+ * @param nodeToInsert - The node to insert after this one.
623
+ * @param restoreSelection - Whether or not to attempt to resolve the
624
+ * selection to the appropriate place after the operation is complete.
625
+ * */
626
+ insertAfter(nodeToInsert: LexicalNode, restoreSelection?: boolean): LexicalNode;
627
+ /**
628
+ * Inserts a node before this LexicalNode (as the previous sibling).
629
+ *
630
+ * @param nodeToInsert - The node to insert before this one.
631
+ * @param restoreSelection - Whether or not to attempt to resolve the
632
+ * selection to the appropriate place after the operation is complete.
633
+ * */
634
+ insertBefore(nodeToInsert: LexicalNode, restoreSelection?: boolean): LexicalNode;
635
+ /**
636
+ * Whether or not this node has a required parent. Used during copy + paste operations
637
+ * to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without
638
+ * a ListNode parent or TextNodes with a ParagraphNode parent.
639
+ *
640
+ * */
641
+ isParentRequired(): boolean;
642
+ /**
643
+ * The creation logic for any required parent. Should be implemented if {@link isParentRequired} returns true.
644
+ *
645
+ * */
646
+ createParentElementNode(): ElementNode;
647
+ selectStart(): RangeSelection;
648
+ selectEnd(): RangeSelection;
649
+ /**
650
+ * Moves selection to the previous sibling of this node, at the specified offsets.
651
+ *
652
+ * @param anchorOffset - The anchor offset for selection.
653
+ * @param focusOffset - The focus offset for selection
654
+ * */
655
+ selectPrevious(anchorOffset?: number, focusOffset?: number): RangeSelection;
656
+ /**
657
+ * Moves selection to the next sibling of this node, at the specified offsets.
658
+ *
659
+ * @param anchorOffset - The anchor offset for selection.
660
+ * @param focusOffset - The focus offset for selection
661
+ * */
662
+ selectNext(anchorOffset?: number, focusOffset?: number): RangeSelection;
663
+ /**
664
+ * Marks a node dirty, triggering transforms and
665
+ * forcing it to be reconciled during the update cycle.
666
+ *
667
+ * */
668
+ markDirty(): void;
669
+ /**
670
+ * @internal
671
+ *
672
+ * When the reconciler detects that a node was mutated, this method
673
+ * may be called to restore the node to a known good state.
674
+ */
675
+ reconcileObservedMutation(dom: HTMLElement, editor: LexicalEditor): void;
676
+ }
677
+ /**
678
+ * Insert a series of nodes after this LexicalNode (as next siblings)
679
+ *
680
+ * @param firstToInsert - The first node to insert after this one.
681
+ * @param lastToInsert - The last node to insert after this one. Must be a
682
+ * later sibling of FirstNode. If not provided, it will be its last sibling.
683
+ */
684
+ export declare function insertRangeAfter(
685
+ node: LexicalNode,
686
+ firstToInsert: LexicalNode,
687
+ lastToInsert?: LexicalNode,
688
+ ): void;
689
+ export {};