@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,569 @@
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 {
9
+ type Klass,
10
+ type LexicalNode,
11
+ type LexicalNodeConfig,
12
+ type LexicalUpdateJSON,
13
+ NODE_STATE_KEY,
14
+ type SerializedLexicalNode,
15
+ type Spread,
16
+ type StaticNodeConfigRecord,
17
+ } from '.';
18
+ import { PROTOTYPE_CONFIG_METHOD } from './LexicalConstants';
19
+
20
+ /**
21
+ * Get the value type (V) from a StateConfig
22
+ */
23
+ export type StateConfigValue<S extends AnyStateConfig> =
24
+ S extends StateConfig<infer _K, infer V> ? V : never;
25
+ /**
26
+ * Get the key type (K) from a StateConfig
27
+ */
28
+ export type StateConfigKey<S extends AnyStateConfig> =
29
+ S extends StateConfig<infer K, infer _V> ? K : never;
30
+ /**
31
+ * A value type, or an updater for that value type. For use with
32
+ * {@link $setState} or any user-defined wrappers around it.
33
+ */
34
+ export type ValueOrUpdater<V> = V | ((prevValue: V) => V);
35
+ /**
36
+ * A type alias to make it easier to define setter methods on your node class
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const fooState = createState("foo", { parse: ... });
41
+ * class MyClass extends TextNode {
42
+ * // ...
43
+ * setFoo(valueOrUpdater: StateValueOrUpdater<typeof fooState>): this {
44
+ * return $setState(this, fooState, valueOrUpdater);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export type StateValueOrUpdater<Cfg extends AnyStateConfig> = ValueOrUpdater<StateConfigValue<Cfg>>;
50
+ export interface NodeStateConfig<S extends AnyStateConfig> {
51
+ stateConfig: S;
52
+ flat?: boolean;
53
+ }
54
+ export type RequiredNodeStateConfig = NodeStateConfig<AnyStateConfig> | AnyStateConfig;
55
+ export type StateConfigJSON<S> =
56
+ S extends StateConfig<infer K, infer V>
57
+ ? {
58
+ [Key in K]?: V;
59
+ }
60
+ : Record<never, never>;
61
+ export type RequiredNodeStateConfigJSON<
62
+ Config extends RequiredNodeStateConfig,
63
+ Flat extends boolean,
64
+ > = StateConfigJSON<
65
+ Config extends NodeStateConfig<infer S>
66
+ ? Spread<
67
+ Config,
68
+ {
69
+ flat: false;
70
+ }
71
+ > extends {
72
+ flat: Flat;
73
+ }
74
+ ? S
75
+ : never
76
+ : false extends Flat
77
+ ? Config
78
+ : never
79
+ >;
80
+ export type Prettify<T> = {
81
+ [K in keyof T]: T[K];
82
+ } & {};
83
+ export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
84
+ x: infer R,
85
+ ) => any
86
+ ? R
87
+ : never;
88
+ export type CollectStateJSON<
89
+ Tuple extends readonly RequiredNodeStateConfig[],
90
+ Flat extends boolean,
91
+ > = UnionToIntersection<
92
+ {
93
+ [K in keyof Tuple]: RequiredNodeStateConfigJSON<Tuple[K], Flat>;
94
+ }[number]
95
+ >;
96
+ type GetStaticNodeConfig<T extends LexicalNode> =
97
+ ReturnType<T[typeof PROTOTYPE_CONFIG_METHOD]> extends infer Record
98
+ ? Record extends StaticNodeConfigRecord<infer Type, infer Config>
99
+ ? Config & {
100
+ readonly type: Type;
101
+ }
102
+ : never
103
+ : never;
104
+ type GetStaticNodeConfigs<T extends LexicalNode> =
105
+ GetStaticNodeConfig<T> extends infer OwnConfig
106
+ ? OwnConfig extends never
107
+ ? []
108
+ : OwnConfig extends {
109
+ extends: Klass<infer Parent>;
110
+ }
111
+ ? GetStaticNodeConfig<Parent> extends infer ParentNodeConfig
112
+ ? ParentNodeConfig extends never
113
+ ? [OwnConfig]
114
+ : [OwnConfig, ...GetStaticNodeConfigs<Parent>]
115
+ : OwnConfig
116
+ : [OwnConfig]
117
+ : [];
118
+ type CollectStateConfigs<Configs> = Configs extends [infer OwnConfig, ...infer ParentConfigs]
119
+ ? OwnConfig extends {
120
+ stateConfigs: infer StateConfigs;
121
+ }
122
+ ? StateConfigs extends readonly RequiredNodeStateConfig[]
123
+ ? [...StateConfigs, ...CollectStateConfigs<ParentConfigs>]
124
+ : CollectStateConfigs<ParentConfigs>
125
+ : CollectStateConfigs<ParentConfigs>
126
+ : [];
127
+ export type GetNodeStateConfig<T extends LexicalNode> = CollectStateConfigs<
128
+ GetStaticNodeConfigs<T>
129
+ >;
130
+ /**
131
+ * The NodeState JSON produced by this LexicalNode
132
+ */
133
+ export type NodeStateJSON<T extends LexicalNode> = Prettify<
134
+ {
135
+ [NODE_STATE_KEY]?: Prettify<CollectStateJSON<GetNodeStateConfig<T>, false>>;
136
+ } & CollectStateJSON<GetNodeStateConfig<T>, true>
137
+ >;
138
+ /**
139
+ * Configure a value to be used with StateConfig.
140
+ *
141
+ * The value type should be inferred from the definition of parse.
142
+ *
143
+ * If the value type is not JSON serializable, then unparse must also be provided.
144
+ *
145
+ * Values should be treated as immutable, much like React.useState. Mutating
146
+ * stored values directly will cause unpredictable behavior, is not supported,
147
+ * and may trigger errors in the future.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const numberOrNullState = createState('numberOrNull', {parse: (v) => typeof v === 'number' ? v : null});
152
+ * // ^? State<'numberOrNull', StateValueConfig<number | null>>
153
+ * const numberState = createState('number', {parse: (v) => typeof v === 'number' ? v : 0});
154
+ * // ^? State<'number', StateValueConfig<number>>
155
+ * ```
156
+ *
157
+ * Only the parse option is required, it is generally not useful to
158
+ * override `unparse` or `isEqual`. However, if you are using
159
+ * non-primitive types such as Array, Object, Date, or something
160
+ * more exotic then you would want to override this. In these
161
+ * cases you might want to reach for third party libraries.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * const isoDateState = createState('isoDate', {
166
+ * parse: (v): null | Date => {
167
+ * const date = typeof v === 'string' ? new Date(v) : null;
168
+ * return date && !isNaN(date.valueOf()) ? date : null;
169
+ * }
170
+ * isEqual: (a, b) => a === b || (a && b && a.valueOf() === b.valueOf()),
171
+ * unparse: (v) => v && v.toString()
172
+ * });
173
+ * ```
174
+ *
175
+ * You may find it easier to write a parse function using libraries like
176
+ * zod, valibot, ajv, Effect, TypeBox, etc. perhaps with a wrapper function.
177
+ */
178
+ export interface StateValueConfig<V> {
179
+ /**
180
+ * This function must return a default value when called with undefined,
181
+ * otherwise it should parse the given JSON value to your type V. Note
182
+ * that it is not required to copy or clone the given value, you can
183
+ * pass it directly through if it matches the expected type.
184
+ *
185
+ * When you encounter an invalid value, it's up to you to decide
186
+ * as to whether to ignore it and return the default value,
187
+ * return some non-default error value, or throw an error.
188
+ *
189
+ * It is possible for V to include undefined, but if it does, then
190
+ * it should also be considered the default value since undefined
191
+ * can not be serialized to JSON so it is indistinguishable from the
192
+ * default.
193
+ *
194
+ * Similarly, if your V is a function, then usage of {@link $setState}
195
+ * must use an updater function because your type will be indistinguishable
196
+ * from an updater function.
197
+ */
198
+ parse: (jsonValue: unknown) => V;
199
+ /**
200
+ * This is optional and for advanced use cases only.
201
+ *
202
+ * You may specify a function that converts V back to JSON.
203
+ * This is mandatory when V is not a JSON serializable type.
204
+ */
205
+ unparse?: (parsed: V) => unknown;
206
+ /**
207
+ * This is optional and for advanced use cases only.
208
+ *
209
+ * Used to define the equality function so you can use an Array or Object
210
+ * as V and still omit default values from the exported JSON.
211
+ *
212
+ * The default is `Object.is`, but something like `fast-deep-equal` might be
213
+ * more appropriate for your use case.
214
+ */
215
+ isEqual?: (a: V, b: V) => boolean;
216
+ }
217
+ /**
218
+ * The return value of {@link createState}, for use with
219
+ * {@link $getState} and {@link $setState}.
220
+ */
221
+ export declare class StateConfig<K extends string, V> {
222
+ /** The string key used when serializing this state to JSON */
223
+ readonly key: K;
224
+ /** The parse function from the StateValueConfig passed to createState */
225
+ readonly parse: (value?: unknown) => V;
226
+ /**
227
+ * The unparse function from the StateValueConfig passed to createState,
228
+ * with a default that is simply a pass-through that assumes the value is
229
+ * JSON serializable.
230
+ */
231
+ readonly unparse: (value: V) => unknown;
232
+ /**
233
+ * An equality function from the StateValueConfig, with a default of
234
+ * Object.is.
235
+ */
236
+ readonly isEqual: (a: V, b: V) => boolean;
237
+ /**
238
+ * The result of `stateValueConfig.parse(undefined)`, which is computed only
239
+ * once and used as the default value. When the current value `isEqual` to
240
+ * the `defaultValue`, it will not be serialized to JSON.
241
+ */
242
+ readonly defaultValue: V;
243
+ constructor(key: K, stateValueConfig: StateValueConfig<V>);
244
+ }
245
+ /**
246
+ * For advanced use cases, using this type is not recommended unless
247
+ * it is required (due to TypeScript's lack of features like
248
+ * higher-kinded types).
249
+ *
250
+ * A {@link StateConfig} type with any key and any value that can be
251
+ * used in situations where the key and value type can not be known,
252
+ * such as in a generic constraint when working with a collection of
253
+ * StateConfig.
254
+ *
255
+ * {@link StateConfigKey} and {@link StateConfigValue} will be
256
+ * useful when this is used as a generic constraint.
257
+ */
258
+ export type AnyStateConfig = StateConfig<any, any>;
259
+ /**
260
+ * Create a StateConfig for the given string key and StateValueConfig.
261
+ *
262
+ * The key must be locally unique. In dev you will get a key collision error
263
+ * when you use two separate StateConfig on the same node with the same key.
264
+ *
265
+ * The returned StateConfig value should be used with {@link $getState} and
266
+ * {@link $setState}.
267
+ *
268
+ * @param key The key to use
269
+ * @param valueConfig Configuration for the value type
270
+ * @returns a StateConfig
271
+ *
272
+ * @__NO_SIDE_EFFECTS__
273
+ */
274
+ export declare function createState<K extends string, V>(
275
+ key: K,
276
+ valueConfig: StateValueConfig<V>,
277
+ ): StateConfig<K, V>;
278
+ /**
279
+ * The accessor for working with node state. This will read the value for the
280
+ * state on the given node, and will return `stateConfig.defaultValue` if the
281
+ * state has never been set on this node.
282
+ *
283
+ * The `version` parameter is optional and should generally be `'latest'`,
284
+ * consistent with the behavior of other node methods and functions,
285
+ * but for certain use cases such as `updateDOM` you may have a need to
286
+ * use `'direct'` to read the state from a previous version of the node.
287
+ *
288
+ * For very advanced use cases, you can expect that 'direct' does not
289
+ * require an editor state, just like directly accessing other properties
290
+ * of a node without an accessor (e.g. `textNode.__text`).
291
+ *
292
+ * @param node Any LexicalNode
293
+ * @param stateConfig The configuration of the state to read
294
+ * @param version The default value 'latest' will read the latest version of the node state, 'direct' will read the version that is stored on this LexicalNode which not reflect the version used in the current editor state
295
+ * @returns The current value from the state, or the default value provided by the configuration.
296
+ */
297
+ export declare function $getState<K extends string, V>(
298
+ node: LexicalNode,
299
+ stateConfig: StateConfig<K, V>,
300
+ version?: 'latest' | 'direct',
301
+ ): V;
302
+ /**
303
+ * Given two versions of a node and a stateConfig, compare their state values
304
+ * using `$getState(nodeVersion, stateConfig, 'direct')`.
305
+ * If the values are equal according to `stateConfig.isEqual`, return `null`,
306
+ * otherwise return `[value, prevValue]`.
307
+ *
308
+ * This is useful for implementing updateDOM. Note that the `'direct'`
309
+ * version argument is used for both nodes.
310
+ *
311
+ * @param node Any LexicalNode
312
+ * @param prevNode A previous version of node
313
+ * @param stateConfig The configuration of the state to read
314
+ * @returns `[value, prevValue]` if changed, otherwise `null`
315
+ */
316
+ export declare function $getStateChange<T extends LexicalNode, K extends string, V>(
317
+ node: T,
318
+ prevNode: T,
319
+ stateConfig: StateConfig<K, V>,
320
+ ): null | [value: V, prevValue: V];
321
+ /**
322
+ * Set the state defined by stateConfig on node. Like with `React.useState`
323
+ * you may directly specify the value or use an updater function that will
324
+ * be called with the previous value of the state on that node (which will
325
+ * be the `stateConfig.defaultValue` if not set).
326
+ *
327
+ * When an updater function is used, the node will only be marked dirty if
328
+ * `stateConfig.isEqual(prevValue, value)` is false.
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * const toggle = createState('toggle', {parse: Boolean});
333
+ * // set it direction
334
+ * $setState(node, counterState, true);
335
+ * // use an updater
336
+ * $setState(node, counterState, (prev) => !prev);
337
+ * ```
338
+ *
339
+ * @param node The LexicalNode to set the state on
340
+ * @param stateConfig The configuration for this state
341
+ * @param valueOrUpdater The value or updater function
342
+ * @returns node
343
+ */
344
+ export declare function $setState<Node extends LexicalNode, K extends string, V>(
345
+ node: Node,
346
+ stateConfig: StateConfig<K, V>,
347
+ valueOrUpdater: ValueOrUpdater<V>,
348
+ ): Node;
349
+ /**
350
+ * @internal
351
+ *
352
+ * Opaque state to be stored on the editor's RegisterNode for use by NodeState
353
+ */
354
+ export type SharedNodeState = {
355
+ sharedConfigMap: SharedConfigMap;
356
+ flatKeys: Set<string>;
357
+ };
358
+ /**
359
+ * @internal
360
+ *
361
+ * Create the state to store on RegisteredNode
362
+ */
363
+ export declare function createSharedNodeState(nodeConfig: LexicalNodeConfig): SharedNodeState;
364
+ type KnownStateMap = Map<AnyStateConfig, unknown>;
365
+ type UnknownStateRecord = Record<string, unknown>;
366
+ /**
367
+ * @internal
368
+ *
369
+ * A Map of string keys to state configurations to be shared across nodes
370
+ * and/or node versions.
371
+ */
372
+ type SharedConfigMap = Map<string, AnyStateConfig>;
373
+ /**
374
+ * @internal
375
+ */
376
+ export declare class NodeState<T extends LexicalNode> {
377
+ /**
378
+ * @internal
379
+ *
380
+ * Track the (versioned) node that this NodeState was created for, to
381
+ * facilitate copy-on-write for NodeState. When a LexicalNode is cloned,
382
+ * it will *reference* the NodeState from its prevNode. From the nextNode
383
+ * you can continue to read state without copying, but the first $setState
384
+ * will trigger a copy of the prevNode's NodeState with the node property
385
+ * updated.
386
+ */
387
+ readonly node: LexicalNode;
388
+ /**
389
+ * @internal
390
+ *
391
+ * State that has already been parsed in a get state, so it is safe. (can be returned with
392
+ * just a cast since the proof was given before).
393
+ *
394
+ * Note that it uses StateConfig, so in addition to (1) the CURRENT VALUE, it has access to
395
+ * (2) the State key (3) the DEFAULT VALUE and (4) the PARSE FUNCTION
396
+ */
397
+ readonly knownState: KnownStateMap;
398
+ /**
399
+ * @internal
400
+ *
401
+ * A copy of serializedNode[NODE_STATE_KEY] that is made when JSON is
402
+ * imported but has not been parsed yet.
403
+ *
404
+ * It stays here until a get state requires us to parse it, and since we
405
+ * then know the value is safe we move it to knownState.
406
+ *
407
+ * Note that since only string keys are used here, we can only allow this
408
+ * state to pass-through on export or on the next version since there is
409
+ * no known value configuration. This pass-through is to support scenarios
410
+ * where multiple versions of the editor code are working in parallel so
411
+ * an old version of your code doesnt erase metadata that was
412
+ * set by a newer version of your code.
413
+ */
414
+ unknownState: undefined | UnknownStateRecord;
415
+ /**
416
+ * @internal
417
+ *
418
+ * This sharedNodeState is preserved across all instances of a given
419
+ * node type in an editor and remains writable. It is how keys are resolved
420
+ * to configuration.
421
+ */
422
+ readonly sharedNodeState: SharedNodeState;
423
+ /**
424
+ * @internal
425
+ *
426
+ * The count of known or unknown keys in this state, ignoring the
427
+ * intersection between the two sets.
428
+ */
429
+ size: number;
430
+ /**
431
+ * @internal
432
+ */
433
+ constructor(
434
+ node: T,
435
+ sharedNodeState: SharedNodeState,
436
+ unknownState?: undefined | UnknownStateRecord,
437
+ knownState?: KnownStateMap,
438
+ size?: number | undefined,
439
+ );
440
+ /**
441
+ * @internal
442
+ *
443
+ * Get the value from knownState, or parse it from unknownState
444
+ * if it contains the given key.
445
+ *
446
+ * Updates the sharedConfigMap when no known state is found.
447
+ * Updates unknownState and knownState when an unknownState is parsed.
448
+ */
449
+ getValue<K extends string, V>(stateConfig: StateConfig<K, V>): V;
450
+ /**
451
+ * @internal
452
+ *
453
+ * Used only for advanced use cases, such as collab. The intent here is to
454
+ * allow you to diff states with a more stable interface than the properties
455
+ * of this class.
456
+ */
457
+ getInternalState(): [
458
+ (
459
+ | {
460
+ readonly [k in string]: unknown;
461
+ }
462
+ | undefined
463
+ ),
464
+ ReadonlyMap<AnyStateConfig, unknown>,
465
+ ];
466
+ /**
467
+ * Encode this NodeState to JSON in the format that its node expects.
468
+ * This returns `{[NODE_STATE_KEY]?: UnknownStateRecord}` rather than
469
+ * `UnknownStateRecord | undefined` so that we can support flattening
470
+ * specific entries in the future when nodes can declare what
471
+ * their required StateConfigs are.
472
+ */
473
+ toJSON(): NodeStateJSON<T>;
474
+ /**
475
+ * @internal
476
+ *
477
+ * A NodeState is writable when the node to update matches
478
+ * the node associated with the NodeState. This basically
479
+ * mirrors how the EditorState NodeMap works, but in a
480
+ * bottom-up organization rather than a top-down organization.
481
+ *
482
+ * This allows us to implement the same "copy on write"
483
+ * pattern for state, without having the state version
484
+ * update every time the node version changes (e.g. when
485
+ * its parent or siblings change).
486
+ *
487
+ * @param node The node to associate with the state
488
+ * @returns The next writable state
489
+ */
490
+ getWritable(node: T): NodeState<T>;
491
+ /** @internal */
492
+ updateFromKnown<K extends string, V>(stateConfig: StateConfig<K, V>, value: V): void;
493
+ /**
494
+ * @internal
495
+ *
496
+ * This is intended for advanced use cases only, such
497
+ * as collab or dev tools.
498
+ *
499
+ * Update a single key value pair from unknown state,
500
+ * parsing it if the key is known to this node. This is
501
+ * basically like updateFromJSON, but the effect is
502
+ * isolated to a single entry.
503
+ *
504
+ * @param k The string key from an UnknownStateRecord
505
+ * @param v The unknown value from an UnknownStateRecord
506
+ */
507
+ updateFromUnknown(k: string, v: unknown): void;
508
+ /**
509
+ * @internal
510
+ *
511
+ * Reset all existing state to default or empty values,
512
+ * and perform any updates from the given unknownState.
513
+ *
514
+ * This is used when initializing a node's state from JSON,
515
+ * or when resetting a node's state from JSON.
516
+ *
517
+ * @param unknownState The new state in serialized form
518
+ */
519
+ updateFromJSON(unknownState: undefined | UnknownStateRecord): void;
520
+ }
521
+ /**
522
+ * @internal
523
+ *
524
+ * Only for direct use in very advanced integrations, such as lexical-yjs.
525
+ * Typically you would only use {@link createState}, {@link $getState}, and
526
+ * {@link $setState}. This is effectively the preamble for {@link $setState}.
527
+ */
528
+ export declare function $getWritableNodeState<T extends LexicalNode>(node: T): NodeState<T>;
529
+ /**
530
+ * @internal
531
+ *
532
+ * Get the SharedNodeState for a node on this editor
533
+ */
534
+ export declare function $getSharedNodeState<T extends LexicalNode>(node: T): SharedNodeState;
535
+ /**
536
+ * @internal
537
+ *
538
+ * This is used to implement LexicalNode.updateFromJSON and is
539
+ * not intended to be exported from the package.
540
+ *
541
+ * @param node any LexicalNode
542
+ * @param unknownState undefined or a serialized State
543
+ * @returns A writable version of node, with the state set.
544
+ */
545
+ export declare function $updateStateFromJSON<T extends LexicalNode>(
546
+ node: T,
547
+ serialized: LexicalUpdateJSON<SerializedLexicalNode>,
548
+ ): T;
549
+ /**
550
+ * @internal
551
+ *
552
+ * Return true if the two nodes have equivalent NodeState, to be used
553
+ * to determine when TextNode are being merged, not a lot of use cases
554
+ * otherwise.
555
+ */
556
+ export declare function nodeStatesAreEquivalent<T extends LexicalNode>(
557
+ a: undefined | NodeState<T>,
558
+ b: undefined | NodeState<T>,
559
+ ): boolean;
560
+ /**
561
+ * @internal
562
+ *
563
+ * Clones the NodeState for a given node. Handles aliasing if the state references the from node.
564
+ */
565
+ export declare function $cloneNodeState<T extends LexicalNode>(
566
+ from: T,
567
+ to: T,
568
+ ): undefined | NodeState<T>;
569
+ export {};
@@ -0,0 +1,11 @@
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 { RangeSelection, TextNode } from '.';
9
+
10
+ export declare function $normalizeTextNode(textNode: TextNode): void;
11
+ export declare function $normalizeSelection(selection: RangeSelection): RangeSelection;
@@ -0,0 +1,28 @@
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 { LexicalEditor, MutatedNodes } from './LexicalEditor';
9
+ import { EditorState } from './LexicalEditorState';
10
+ import type { NodeKey } from './LexicalNode';
11
+ import type { ElementNode } from './nodes/LexicalElementNode';
12
+
13
+ type IntentionallyMarkedAsDirtyElement = boolean;
14
+ export declare function $getReconciledDirection(node: ElementNode): 'ltr' | 'rtl' | 'auto' | null;
15
+ export declare function $reconcileRoot(
16
+ prevEditorState: EditorState,
17
+ nextEditorState: EditorState,
18
+ editor: LexicalEditor,
19
+ dirtyType: 0 | 1 | 2,
20
+ dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
21
+ dirtyLeaves: Set<NodeKey>,
22
+ ): MutatedNodes;
23
+ export declare function storeDOMWithKey(
24
+ key: NodeKey,
25
+ dom: HTMLElement,
26
+ editor: LexicalEditor,
27
+ ): void;
28
+ export {};