@examind/block-types 0.1.18

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 (59) hide show
  1. package/README.md +40 -0
  2. package/package.json +21 -0
  3. package/types/examind/index.d.ts +12 -0
  4. package/types/examind/nodes/EssayQuestionNode.ts +16 -0
  5. package/types/examind/nodes/FillInTheBlankQuestionNode.ts +14 -0
  6. package/types/examind/nodes/FillInTheBlankSpaceNode.ts +21 -0
  7. package/types/examind/nodes/FinancialStatementQuestionNode.ts +46 -0
  8. package/types/examind/nodes/HorizontalRuleNode.ts +3 -0
  9. package/types/examind/nodes/ImageNode.ts +18 -0
  10. package/types/examind/nodes/JournalEntryQuestionNode.ts +32 -0
  11. package/types/examind/nodes/MatchingQuestionNode.ts +21 -0
  12. package/types/examind/nodes/MultipleOptionQuestionNode.ts +29 -0
  13. package/types/examind/nodes/ShortAnswerQuestionNode.ts +15 -0
  14. package/types/examind/nodes/SimulationQuestionNode.ts +15 -0
  15. package/types/examind/nodes/VariableNode.ts +24 -0
  16. package/types/index.ts +2 -0
  17. package/types/lexical/LexicalCommands.ts +159 -0
  18. package/types/lexical/LexicalConstants.ts +51 -0
  19. package/types/lexical/LexicalEditor.ts +597 -0
  20. package/types/lexical/LexicalEditorState.ts +30 -0
  21. package/types/lexical/LexicalEvents.ts +13 -0
  22. package/types/lexical/LexicalGC.ts +13 -0
  23. package/types/lexical/LexicalMutations.ts +10 -0
  24. package/types/lexical/LexicalNode.ts +460 -0
  25. package/types/lexical/LexicalNodeState.ts +379 -0
  26. package/types/lexical/LexicalNormalization.ts +9 -0
  27. package/types/lexical/LexicalReconciler.ts +13 -0
  28. package/types/lexical/LexicalSelection.ts +295 -0
  29. package/types/lexical/LexicalUpdateTags.ts +51 -0
  30. package/types/lexical/LexicalUpdates.ts +31 -0
  31. package/types/lexical/LexicalUtils.ts +304 -0
  32. package/types/lexical/index.ts +35 -0
  33. package/types/lexical/link/index.ts +125 -0
  34. package/types/lexical/list/LexicalListItemNode.ts +65 -0
  35. package/types/lexical/list/LexicalListNode.ts +56 -0
  36. package/types/lexical/list/checkList.ts +9 -0
  37. package/types/lexical/list/formatList.ts +69 -0
  38. package/types/lexical/list/index.ts +11 -0
  39. package/types/lexical/list/utils.ts +64 -0
  40. package/types/lexical/nodes/ArtificialNode.ts +12 -0
  41. package/types/lexical/nodes/LexicalDecoratorNode.ts +26 -0
  42. package/types/lexical/nodes/LexicalElementNode.ts +207 -0
  43. package/types/lexical/nodes/LexicalLineBreakNode.ts +25 -0
  44. package/types/lexical/nodes/LexicalParagraphNode.ts +31 -0
  45. package/types/lexical/nodes/LexicalRootNode.ts +30 -0
  46. package/types/lexical/nodes/LexicalTabNode.ts +28 -0
  47. package/types/lexical/nodes/LexicalTextNode.ts +288 -0
  48. package/types/lexical/rich-text/index.ts +53 -0
  49. package/types/lexical/table/LexicalTableCellNode.ts +72 -0
  50. package/types/lexical/table/LexicalTableCommands.ts +17 -0
  51. package/types/lexical/table/LexicalTableNode.ts +65 -0
  52. package/types/lexical/table/LexicalTableObserver.ts +108 -0
  53. package/types/lexical/table/LexicalTablePluginHelpers.ts +25 -0
  54. package/types/lexical/table/LexicalTableRowNode.ts +34 -0
  55. package/types/lexical/table/LexicalTableSelection.ts +74 -0
  56. package/types/lexical/table/LexicalTableSelectionHelpers.ts +40 -0
  57. package/types/lexical/table/LexicalTableUtils.ts +112 -0
  58. package/types/lexical/table/constants.ts +8 -0
  59. package/types/lexical/table/index.ts +16 -0
@@ -0,0 +1,597 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { EditorState, SerializedEditorState } from './LexicalEditorState';
8
+ import type { DOMConversion, DOMConversionMap, DOMExportOutput, DOMExportOutputMap, NodeKey } from './LexicalNode';
9
+ import { LexicalNode } from './LexicalNode';
10
+ import { UpdateTag } from './LexicalUpdateTags';
11
+ export type Spread<T1, T2> = Omit<T2, keyof T1> & T1;
12
+ export type KlassConstructor<Cls extends GenericConstructor<any>> = GenericConstructor<InstanceType<Cls>> & {
13
+ [k in keyof Cls]: Cls[k];
14
+ };
15
+ type GenericConstructor<T> = new (...args: any[]) => T;
16
+ export type Klass<T extends LexicalNode> = InstanceType<T['constructor']> extends T ? T['constructor'] : GenericConstructor<T> & T['constructor'];
17
+ export type EditorThemeClassName = string;
18
+ export type TextNodeThemeClasses = {
19
+ base?: EditorThemeClassName;
20
+ bold?: EditorThemeClassName;
21
+ code?: EditorThemeClassName;
22
+ highlight?: EditorThemeClassName;
23
+ italic?: EditorThemeClassName;
24
+ lowercase?: EditorThemeClassName;
25
+ uppercase?: EditorThemeClassName;
26
+ capitalize?: EditorThemeClassName;
27
+ strikethrough?: EditorThemeClassName;
28
+ subscript?: EditorThemeClassName;
29
+ superscript?: EditorThemeClassName;
30
+ underline?: EditorThemeClassName;
31
+ underlineStrikethrough?: EditorThemeClassName;
32
+ [key: string]: EditorThemeClassName | undefined;
33
+ };
34
+ export type EditorUpdateOptions = {
35
+ onUpdate?: () => void;
36
+ skipTransforms?: true;
37
+ tag?: UpdateTag | UpdateTag[];
38
+ discrete?: true;
39
+ /** @internal */
40
+ event?: undefined | UIEvent | Event | null;
41
+ };
42
+ export type EditorSetOptions = {
43
+ tag?: string;
44
+ };
45
+ export type EditorFocusOptions = {
46
+ defaultSelection?: 'rootStart' | 'rootEnd';
47
+ };
48
+ export type EditorThemeClasses = {
49
+ blockCursor?: EditorThemeClassName;
50
+ characterLimit?: EditorThemeClassName;
51
+ code?: EditorThemeClassName;
52
+ codeHighlight?: Record<string, EditorThemeClassName>;
53
+ hashtag?: EditorThemeClassName;
54
+ specialText?: EditorThemeClassName;
55
+ heading?: {
56
+ h1?: EditorThemeClassName;
57
+ h2?: EditorThemeClassName;
58
+ h3?: EditorThemeClassName;
59
+ h4?: EditorThemeClassName;
60
+ h5?: EditorThemeClassName;
61
+ h6?: EditorThemeClassName;
62
+ };
63
+ hr?: EditorThemeClassName;
64
+ hrSelected?: EditorThemeClassName;
65
+ image?: EditorThemeClassName;
66
+ link?: EditorThemeClassName;
67
+ list?: {
68
+ ul?: EditorThemeClassName;
69
+ ulDepth?: Array<EditorThemeClassName>;
70
+ ol?: EditorThemeClassName;
71
+ olDepth?: Array<EditorThemeClassName>;
72
+ checklist?: EditorThemeClassName;
73
+ listitem?: EditorThemeClassName;
74
+ listitemChecked?: EditorThemeClassName;
75
+ listitemUnchecked?: EditorThemeClassName;
76
+ nested?: {
77
+ list?: EditorThemeClassName;
78
+ listitem?: EditorThemeClassName;
79
+ };
80
+ };
81
+ ltr?: EditorThemeClassName;
82
+ mark?: EditorThemeClassName;
83
+ markOverlap?: EditorThemeClassName;
84
+ paragraph?: EditorThemeClassName;
85
+ quote?: EditorThemeClassName;
86
+ root?: EditorThemeClassName;
87
+ rtl?: EditorThemeClassName;
88
+ tab?: EditorThemeClassName;
89
+ table?: EditorThemeClassName;
90
+ tableAddColumns?: EditorThemeClassName;
91
+ tableAddRows?: EditorThemeClassName;
92
+ tableCellActionButton?: EditorThemeClassName;
93
+ tableCellActionButtonContainer?: EditorThemeClassName;
94
+ tableCellSelected?: EditorThemeClassName;
95
+ tableCell?: EditorThemeClassName;
96
+ tableCellHeader?: EditorThemeClassName;
97
+ tableCellResizer?: EditorThemeClassName;
98
+ tableRow?: EditorThemeClassName;
99
+ tableScrollableWrapper?: EditorThemeClassName;
100
+ tableSelected?: EditorThemeClassName;
101
+ tableSelection?: EditorThemeClassName;
102
+ text?: TextNodeThemeClasses;
103
+ embedBlock?: {
104
+ base?: EditorThemeClassName;
105
+ focus?: EditorThemeClassName;
106
+ };
107
+ indent?: EditorThemeClassName;
108
+ [key: string]: any;
109
+ };
110
+ export type EditorConfig = {
111
+ disableEvents?: boolean;
112
+ namespace: string;
113
+ theme: EditorThemeClasses;
114
+ };
115
+ export type LexicalNodeReplacement = {
116
+ replace: Klass<LexicalNode>;
117
+ with: <T extends {
118
+ new (...args: any): any;
119
+ }>(node: InstanceType<T>) => LexicalNode;
120
+ withKlass?: Klass<LexicalNode>;
121
+ };
122
+ export type HTMLConfig = {
123
+ export?: DOMExportOutputMap;
124
+ import?: DOMConversionMap;
125
+ };
126
+ export type CreateEditorArgs = {
127
+ disableEvents?: boolean;
128
+ editorState?: EditorState;
129
+ namespace?: string;
130
+ nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
131
+ onError?: ErrorHandler;
132
+ parentEditor?: LexicalEditor;
133
+ editable?: boolean;
134
+ theme?: EditorThemeClasses;
135
+ html?: HTMLConfig;
136
+ };
137
+ export type RegisteredNodes = Map<string, RegisteredNode>;
138
+ export type RegisteredNode = {
139
+ klass: Klass<LexicalNode>;
140
+ transforms: Set<Transform<LexicalNode>>;
141
+ replace: null | ((node: LexicalNode) => LexicalNode);
142
+ replaceWithKlass: null | Klass<LexicalNode>;
143
+ exportDOM?: (editor: LexicalEditor, targetNode: LexicalNode) => DOMExportOutput;
144
+ };
145
+ export type Transform<T extends LexicalNode> = (node: T) => void;
146
+ export type ErrorHandler = (error: Error) => void;
147
+ export type MutationListeners = Map<MutationListener, Klass<LexicalNode>>;
148
+ export type MutatedNodes = Map<Klass<LexicalNode>, Map<NodeKey, NodeMutation>>;
149
+ export type NodeMutation = 'created' | 'updated' | 'destroyed';
150
+ export interface MutationListenerOptions {
151
+ /**
152
+ * Skip the initial call of the listener with pre-existing DOM nodes.
153
+ *
154
+ * The default was previously true for backwards compatibility with <= 0.16.1
155
+ * but this default has been changed to false as of 0.21.0.
156
+ */
157
+ skipInitialization?: boolean;
158
+ }
159
+ /**
160
+ * The payload passed to an UpdateListener
161
+ */
162
+ export interface UpdateListenerPayload {
163
+ /**
164
+ * A Map of NodeKeys of ElementNodes to a boolean that is true
165
+ * if the node was intentionally mutated ('unintentional' mutations
166
+ * are triggered when an indirect descendant is marked dirty)
167
+ */
168
+ dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>;
169
+ /**
170
+ * A Set of NodeKeys of all nodes that were marked dirty that
171
+ * do not inherit from ElementNode.
172
+ */
173
+ dirtyLeaves: Set<NodeKey>;
174
+ /**
175
+ * The new EditorState after all updates have been processed,
176
+ * equivalent to `editor.getEditorState()`
177
+ */
178
+ editorState: EditorState;
179
+ /**
180
+ * The Map of LexicalNode constructors to a `Map<NodeKey, NodeMutation>`,
181
+ * this is useful when you have a mutation listener type use cases that
182
+ * should apply to all or most nodes. Will be null if no DOM was mutated,
183
+ * such as when only the selection changed. Note that this will be empty
184
+ * unless at least one MutationListener is explicitly registered
185
+ * (any MutationListener is sufficient to compute the mutatedNodes Map
186
+ * for all nodes).
187
+ *
188
+ * Added in v0.28.0
189
+ */
190
+ mutatedNodes: null | MutatedNodes;
191
+ /**
192
+ * For advanced use cases only.
193
+ *
194
+ * Tracks the keys of TextNode descendants that have been merged
195
+ * with their siblings by normalization. Note that these keys may
196
+ * not exist in either editorState or prevEditorState and generally
197
+ * this is only used for conflict resolution edge cases in collab.
198
+ */
199
+ normalizedNodes: Set<NodeKey>;
200
+ /**
201
+ * The previous EditorState that is being discarded
202
+ */
203
+ prevEditorState: EditorState;
204
+ /**
205
+ * The set of tags added with update options or {@link $addUpdateTag},
206
+ * node that this includes all tags that were processed in this
207
+ * reconciliation which may have been added by separate updates.
208
+ */
209
+ tags: Set<string>;
210
+ }
211
+ /**
212
+ * A listener that gets called after the editor is updated
213
+ */
214
+ export type UpdateListener = (payload: UpdateListenerPayload) => void;
215
+ export type DecoratorListener<T = never> = (decorator: Record<NodeKey, T>) => void;
216
+ export type RootListener = (rootElement: null | HTMLElement, prevRootElement: null | HTMLElement) => void;
217
+ export type TextContentListener = (text: string) => void;
218
+ export type MutationListener = (nodes: Map<NodeKey, NodeMutation>, payload: {
219
+ updateTags: Set<string>;
220
+ dirtyLeaves: Set<string>;
221
+ prevEditorState: EditorState;
222
+ }) => void;
223
+ export type CommandListener<P> = (payload: P, editor: LexicalEditor) => boolean;
224
+ export type EditableListener = (editable: boolean) => void;
225
+ export type CommandListenerPriority = 0 | 1 | 2 | 3 | 4;
226
+ export declare const COMMAND_PRIORITY_EDITOR = 0;
227
+ export declare const COMMAND_PRIORITY_LOW = 1;
228
+ export declare const COMMAND_PRIORITY_NORMAL = 2;
229
+ export declare const COMMAND_PRIORITY_HIGH = 3;
230
+ export declare const COMMAND_PRIORITY_CRITICAL = 4;
231
+ export type LexicalCommand<TPayload> = {
232
+ type?: string;
233
+ };
234
+ /**
235
+ * Type helper for extracting the payload type from a command.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * const MY_COMMAND = createCommand<SomeType>();
240
+ *
241
+ * // ...
242
+ *
243
+ * editor.registerCommand(MY_COMMAND, payload => {
244
+ * // Type of `payload` is inferred here. But lets say we want to extract a function to delegate to
245
+ * $handleMyCommand(editor, payload);
246
+ * return true;
247
+ * });
248
+ *
249
+ * function $handleMyCommand(editor: LexicalEditor, payload: CommandPayloadType<typeof MY_COMMAND>) {
250
+ * // `payload` is of type `SomeType`, extracted from the command.
251
+ * }
252
+ * ```
253
+ */
254
+ export type CommandPayloadType<TCommand extends LexicalCommand<unknown>> = TCommand extends LexicalCommand<infer TPayload> ? TPayload : never;
255
+ type Commands = Map<LexicalCommand<unknown>, Array<Set<CommandListener<unknown>>>>;
256
+ export interface Listeners {
257
+ decorator: Set<DecoratorListener<any>>;
258
+ mutation: MutationListeners;
259
+ editable: Set<EditableListener>;
260
+ root: Set<RootListener>;
261
+ textcontent: Set<TextContentListener>;
262
+ update: Set<UpdateListener>;
263
+ }
264
+ export type SetListeners = {
265
+ [K in keyof Listeners as Listeners[K] extends Set<(...args: any[]) => void> ? K : never]: Listeners[K] extends Set<(...args: infer Args) => void> ? Args : never;
266
+ };
267
+ export type TransformerType = 'text' | 'decorator' | 'element' | 'root';
268
+ type IntentionallyMarkedAsDirtyElement = boolean;
269
+ type DOMConversionCache = Map<string, Array<(node: Node) => DOMConversion | null>>;
270
+ export type SerializedEditor = {
271
+ editorState: SerializedEditorState;
272
+ };
273
+ export declare function resetEditor(editor: LexicalEditor, prevRootElement: null | HTMLElement, nextRootElement: null | HTMLElement, pendingEditorState: EditorState): void;
274
+ /**
275
+ * Creates a new LexicalEditor attached to a single contentEditable (provided in the config). This is
276
+ * the lowest-level initialization API for a LexicalEditor. If you're using React or another framework,
277
+ * consider using the appropriate abstractions, such as LexicalComposer
278
+ * @param editorConfig - the editor configuration.
279
+ * @returns a LexicalEditor instance
280
+ */
281
+ export declare function createEditor(editorConfig?: CreateEditorArgs): LexicalEditor;
282
+ export declare class LexicalEditor {
283
+ ['constructor']: KlassConstructor<typeof LexicalEditor>;
284
+ /** The version with build identifiers for this editor (since 0.17.1) */
285
+ static version: string | undefined;
286
+ /** @internal */
287
+ _headless: boolean;
288
+ /** @internal */
289
+ _parentEditor: null | LexicalEditor;
290
+ /** @internal */
291
+ _rootElement: null | HTMLElement;
292
+ /** @internal */
293
+ _editorState: EditorState;
294
+ /** @internal */
295
+ _pendingEditorState: null | EditorState;
296
+ /** @internal */
297
+ _compositionKey: null | NodeKey;
298
+ /** @internal */
299
+ _deferred: Array<() => void>;
300
+ /** @internal */
301
+ _keyToDOMMap: Map<NodeKey, HTMLElement>;
302
+ /** @internal */
303
+ _updates: Array<[() => void, EditorUpdateOptions | undefined]>;
304
+ /** @internal */
305
+ _updating: boolean;
306
+ /** @internal */
307
+ _listeners: Listeners;
308
+ /** @internal */
309
+ _commands: Commands;
310
+ /** @internal */
311
+ _nodes: RegisteredNodes;
312
+ /** @internal */
313
+ _decorators: Record<NodeKey, unknown>;
314
+ /** @internal */
315
+ _pendingDecorators: null | Record<NodeKey, unknown>;
316
+ /** @internal */
317
+ _config: EditorConfig;
318
+ /** @internal */
319
+ _dirtyType: 0 | 1 | 2;
320
+ /** @internal */
321
+ _cloneNotNeeded: Set<NodeKey>;
322
+ /** @internal */
323
+ _dirtyLeaves: Set<NodeKey>;
324
+ /** @internal */
325
+ _dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>;
326
+ /** @internal */
327
+ _normalizedNodes: Set<NodeKey>;
328
+ /** @internal */
329
+ _updateTags: Set<UpdateTag>;
330
+ /** @internal */
331
+ _observer: null | MutationObserver;
332
+ /** @internal */
333
+ _key: string;
334
+ /** @internal */
335
+ _onError: ErrorHandler;
336
+ /** @internal */
337
+ _htmlConversions: DOMConversionCache;
338
+ /** @internal */
339
+ _window: null | Window;
340
+ /** @internal */
341
+ _editable: boolean;
342
+ /** @internal */
343
+ _blockCursorElement: null | HTMLDivElement;
344
+ /** @internal */
345
+ _createEditorArgs?: undefined | CreateEditorArgs;
346
+ /** @internal */
347
+ constructor(editorState: EditorState, parentEditor: null | LexicalEditor, nodes: RegisteredNodes, config: EditorConfig, onError: ErrorHandler, htmlConversions: DOMConversionCache, editable: boolean, createEditorArgs?: CreateEditorArgs);
348
+ /**
349
+ *
350
+ * @returns true if the editor is currently in "composition" mode due to receiving input
351
+ * through an IME, or 3P extension, for example. Returns false otherwise.
352
+ */
353
+ isComposing(): boolean;
354
+ /**
355
+ * Registers a listener for Editor update event. Will trigger the provided callback
356
+ * each time the editor goes through an update (via {@link LexicalEditor.update}) until the
357
+ * teardown function is called.
358
+ *
359
+ * @returns a teardown function that can be used to cleanup the listener.
360
+ */
361
+ registerUpdateListener(listener: UpdateListener): () => void;
362
+ /**
363
+ * Registers a listener for for when the editor changes between editable and non-editable states.
364
+ * Will trigger the provided callback each time the editor transitions between these states until the
365
+ * teardown function is called.
366
+ *
367
+ * @returns a teardown function that can be used to cleanup the listener.
368
+ */
369
+ registerEditableListener(listener: EditableListener): () => void;
370
+ /**
371
+ * Registers a listener for when the editor's decorator object changes. The decorator object contains
372
+ * all DecoratorNode keys -> their decorated value. This is primarily used with external UI frameworks.
373
+ *
374
+ * Will trigger the provided callback each time the editor transitions between these states until the
375
+ * teardown function is called.
376
+ *
377
+ * @returns a teardown function that can be used to cleanup the listener.
378
+ */
379
+ registerDecoratorListener<T>(listener: DecoratorListener<T>): () => void;
380
+ /**
381
+ * Registers a listener for when Lexical commits an update to the DOM and the text content of
382
+ * the editor changes from the previous state of the editor. If the text content is the
383
+ * same between updates, no notifications to the listeners will happen.
384
+ *
385
+ * Will trigger the provided callback each time the editor transitions between these states until the
386
+ * teardown function is called.
387
+ *
388
+ * @returns a teardown function that can be used to cleanup the listener.
389
+ */
390
+ registerTextContentListener(listener: TextContentListener): () => void;
391
+ /**
392
+ * Registers a listener for when the editor's root DOM element (the content editable
393
+ * Lexical attaches to) changes. This is primarily used to attach event listeners to the root
394
+ * element. The root listener function is executed directly upon registration and then on
395
+ * any subsequent update.
396
+ *
397
+ * Will trigger the provided callback each time the editor transitions between these states until the
398
+ * teardown function is called.
399
+ *
400
+ * @returns a teardown function that can be used to cleanup the listener.
401
+ */
402
+ registerRootListener(listener: RootListener): () => void;
403
+ /**
404
+ * Registers a listener that will trigger anytime the provided command
405
+ * is dispatched with {@link LexicalEditor.dispatch}, subject to priority.
406
+ * Listeners that run at a higher priority can "intercept" commands and
407
+ * prevent them from propagating to other handlers by returning true.
408
+ *
409
+ * Listeners are always invoked in an {@link LexicalEditor.update} and can
410
+ * call dollar functions.
411
+ *
412
+ * Listeners registered at the same priority level will run
413
+ * deterministically in the order of registration.
414
+ *
415
+ * @param command - the command that will trigger the callback.
416
+ * @param listener - the function that will execute when the command is dispatched.
417
+ * @param priority - the relative priority of the listener. 0 | 1 | 2 | 3 | 4
418
+ * (or {@link COMMAND_PRIORITY_EDITOR} |
419
+ * {@link COMMAND_PRIORITY_LOW} |
420
+ * {@link COMMAND_PRIORITY_NORMAL} |
421
+ * {@link COMMAND_PRIORITY_HIGH} |
422
+ * {@link COMMAND_PRIORITY_CRITICAL})
423
+ * @returns a teardown function that can be used to cleanup the listener.
424
+ */
425
+ registerCommand<P>(command: LexicalCommand<P>, listener: CommandListener<P>, priority: CommandListenerPriority): () => void;
426
+ /**
427
+ * Registers a listener that will run when a Lexical node of the provided class is
428
+ * mutated. The listener will receive a list of nodes along with the type of mutation
429
+ * that was performed on each: created, destroyed, or updated.
430
+ *
431
+ * One common use case for this is to attach DOM event listeners to the underlying DOM nodes as Lexical nodes are created.
432
+ * {@link LexicalEditor.getElementByKey} can be used for this.
433
+ *
434
+ * If any existing nodes are in the DOM, and skipInitialization is not true, the listener
435
+ * will be called immediately with an updateTag of 'registerMutationListener' where all
436
+ * nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option
437
+ * (whose default was previously true for backwards compatibility with &lt;=0.16.1 but has been changed to false as of 0.21.0).
438
+ *
439
+ * @param klass - The class of the node that you want to listen to mutations on.
440
+ * @param listener - The logic you want to run when the node is mutated.
441
+ * @param options - see {@link MutationListenerOptions}
442
+ * @returns a teardown function that can be used to cleanup the listener.
443
+ */
444
+ registerMutationListener(klass: Klass<LexicalNode>, listener: MutationListener, options?: MutationListenerOptions): () => void;
445
+ /** @internal */
446
+ private getRegisteredNode;
447
+ /** @internal */
448
+ private resolveRegisteredNodeAfterReplacements;
449
+ /** @internal */
450
+ private initializeMutationListener;
451
+ /** @internal */
452
+ private registerNodeTransformToKlass;
453
+ /**
454
+ * Registers a listener that will run when a Lexical node of the provided class is
455
+ * marked dirty during an update. The listener will continue to run as long as the node
456
+ * is marked dirty. There are no guarantees around the order of transform execution!
457
+ *
458
+ * Watch out for infinite loops. See [Node Transforms](https://lexical.dev/docs/concepts/transforms)
459
+ * @param klass - The class of the node that you want to run transforms on.
460
+ * @param listener - The logic you want to run when the node is updated.
461
+ * @returns a teardown function that can be used to cleanup the listener.
462
+ */
463
+ registerNodeTransform<T extends LexicalNode>(klass: Klass<T>, listener: Transform<T>): () => void;
464
+ /**
465
+ * Used to assert that a certain node is registered, usually by plugins to ensure nodes that they
466
+ * depend on have been registered.
467
+ * @returns True if the editor has registered the provided node type, false otherwise.
468
+ */
469
+ hasNode<T extends Klass<LexicalNode>>(node: T): boolean;
470
+ /**
471
+ * Used to assert that certain nodes are registered, usually by plugins to ensure nodes that they
472
+ * depend on have been registered.
473
+ * @returns True if the editor has registered all of the provided node types, false otherwise.
474
+ */
475
+ hasNodes<T extends Klass<LexicalNode>>(nodes: Array<T>): boolean;
476
+ /**
477
+ * Dispatches a command of the specified type with the specified payload.
478
+ * This triggers all command listeners (set by {@link LexicalEditor.registerCommand})
479
+ * for this type, passing them the provided payload. The command listeners
480
+ * will be triggered in an implicit {@link LexicalEditor.update}, unless
481
+ * this was invoked from inside an update in which case that update context
482
+ * will be re-used (as if this was a dollar function itself).
483
+ * @param type - the type of command listeners to trigger.
484
+ * @param payload - the data to pass as an argument to the command listeners.
485
+ */
486
+ dispatchCommand<TCommand extends LexicalCommand<unknown>>(type: TCommand, payload: CommandPayloadType<TCommand>): boolean;
487
+ /**
488
+ * Gets a map of all decorators in the editor.
489
+ * @returns A mapping of call decorator keys to their decorated content
490
+ */
491
+ getDecorators<T>(): Record<NodeKey, T>;
492
+ /**
493
+ *
494
+ * @returns the current root element of the editor. If you want to register
495
+ * an event listener, do it via {@link LexicalEditor.registerRootListener}, since
496
+ * this reference may not be stable.
497
+ */
498
+ getRootElement(): null | HTMLElement;
499
+ /**
500
+ * Gets the key of the editor
501
+ * @returns The editor key
502
+ */
503
+ getKey(): string;
504
+ /**
505
+ * Imperatively set the root contenteditable element that Lexical listens
506
+ * for events on.
507
+ */
508
+ setRootElement(nextRootElement: null | HTMLElement): void;
509
+ /**
510
+ * Gets the underlying HTMLElement associated with the LexicalNode for the given key.
511
+ * @returns the HTMLElement rendered by the LexicalNode associated with the key.
512
+ * @param key - the key of the LexicalNode.
513
+ */
514
+ getElementByKey(key: NodeKey): HTMLElement | null;
515
+ /**
516
+ * Gets the active editor state.
517
+ * @returns The editor state
518
+ */
519
+ getEditorState(): EditorState;
520
+ /**
521
+ * Imperatively set the EditorState. Triggers reconciliation like an update.
522
+ * @param editorState - the state to set the editor
523
+ * @param options - options for the update.
524
+ */
525
+ setEditorState(editorState: EditorState, options?: EditorSetOptions): void;
526
+ /**
527
+ * Parses a SerializedEditorState (usually produced by {@link EditorState.toJSON}) and returns
528
+ * and EditorState object that can be, for example, passed to {@link LexicalEditor.setEditorState}. Typically,
529
+ * deserialization from JSON stored in a database uses this method.
530
+ * @param maybeStringifiedEditorState
531
+ * @param updateFn
532
+ * @returns
533
+ */
534
+ parseEditorState(maybeStringifiedEditorState: string | SerializedEditorState, updateFn?: () => void): EditorState;
535
+ /**
536
+ * Executes a read of the editor's state, with the
537
+ * editor context available (useful for exporting and read-only DOM
538
+ * operations). Much like update, but prevents any mutation of the
539
+ * editor's state. Any pending updates will be flushed immediately before
540
+ * the read.
541
+ * @param callbackFn - A function that has access to read-only editor state.
542
+ */
543
+ read<T>(callbackFn: () => T): T;
544
+ /**
545
+ * Executes an update to the editor state. The updateFn callback is the ONLY place
546
+ * where Lexical editor state can be safely mutated.
547
+ * @param updateFn - A function that has access to writable editor state.
548
+ * @param options - A bag of options to control the behavior of the update.
549
+ * @param options.onUpdate - A function to run once the update is complete.
550
+ * Useful for synchronizing updates in some cases.
551
+ * @param options.skipTransforms - Setting this to true will suppress all node
552
+ * transforms for this update cycle.
553
+ * @param options.tag - A tag to identify this update, in an update listener, for instance.
554
+ * Some tags are reserved by the core and control update behavior in different ways.
555
+ * @param options.discrete - If true, prevents this update from being batched, forcing it to
556
+ * run synchronously.
557
+ */
558
+ update(updateFn: () => void, options?: EditorUpdateOptions): void;
559
+ /**
560
+ * Focuses the editor by marking the existing selection as dirty, or by
561
+ * creating a new selection at `defaultSelection` if one does not already
562
+ * exist. If you want to force a specific selection, you should call
563
+ * `root.selectStart()` or `root.selectEnd()` in an update.
564
+ *
565
+ * @param callbackFn - A function to run after the editor is focused.
566
+ * @param options - A bag of options
567
+ * @param options.defaultSelection - Where to move selection when the editor is
568
+ * focused. Can be rootStart, rootEnd, or undefined. Defaults to rootEnd.
569
+ */
570
+ focus(callbackFn?: () => void, options?: EditorFocusOptions): void;
571
+ /**
572
+ * Removes focus from the editor.
573
+ */
574
+ blur(): void;
575
+ /**
576
+ * Returns true if the editor is editable, false otherwise.
577
+ * @returns True if the editor is editable, false otherwise.
578
+ */
579
+ isEditable(): boolean;
580
+ /**
581
+ * Sets the editable property of the editor. When false, the
582
+ * editor will not listen for user events on the underling contenteditable.
583
+ * @param editable - the value to set the editable mode to.
584
+ */
585
+ setEditable(editable: boolean): void;
586
+ /**
587
+ * Returns a JSON-serializable javascript object NOT a JSON string.
588
+ * You still must call JSON.stringify (or something else) to turn the
589
+ * state into a string you can transfer over the wire and store in a database.
590
+ *
591
+ * See {@link LexicalNode.exportJSON}
592
+ *
593
+ * @returns A JSON-serializable javascript object
594
+ */
595
+ toJSON(): SerializedEditor;
596
+ }
597
+ export {};
@@ -0,0 +1,30 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalEditor } from './LexicalEditor';
8
+ import type { NodeMap, SerializedLexicalNode } from './LexicalNode';
9
+ import type { BaseSelection } from './LexicalSelection';
10
+ import type { SerializedRootNode } from './nodes/LexicalRootNode';
11
+ export interface SerializedEditorState<T extends SerializedLexicalNode = SerializedLexicalNode> {
12
+ root: SerializedRootNode<T>;
13
+ }
14
+ export declare function editorStateHasDirtySelection(editorState: EditorState, editor: LexicalEditor): boolean;
15
+ export declare function cloneEditorState(current: EditorState): EditorState;
16
+ export declare function createEmptyEditorState(): EditorState;
17
+ export interface EditorStateReadOptions {
18
+ editor?: LexicalEditor | null;
19
+ }
20
+ export declare class EditorState {
21
+ _nodeMap: NodeMap;
22
+ _selection: null | BaseSelection;
23
+ _flushSync: boolean;
24
+ _readOnly: boolean;
25
+ constructor(nodeMap: NodeMap, selection?: null | BaseSelection);
26
+ isEmpty(): boolean;
27
+ read<V>(callbackFn: () => V, options?: EditorStateReadOptions): V;
28
+ clone(selection?: null | BaseSelection): EditorState;
29
+ toJSON(): SerializedEditorState;
30
+ }
@@ -0,0 +1,13 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalEditor } from './LexicalEditor';
8
+ import type { NodeKey } from './LexicalNode';
9
+ export type EventHandler = (event: Event, editor: LexicalEditor) => void;
10
+ export declare function addRootElementEvents(rootElement: HTMLElement, editor: LexicalEditor): void;
11
+ export declare function removeRootElementEvents(rootElement: HTMLElement): void;
12
+ export declare function markSelectionChangeFromDOMUpdate(): void;
13
+ export declare function markCollapsedSelectionFormat(format: number, style: string, offset: number, key: NodeKey, timeStamp: number): void;
@@ -0,0 +1,13 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalEditor } from './LexicalEditor';
8
+ import type { EditorState } from './LexicalEditorState';
9
+ import type { NodeKey } from './LexicalNode';
10
+ export declare function $garbageCollectDetachedDecorators(editor: LexicalEditor, pendingEditorState: EditorState): void;
11
+ type IntentionallyMarkedAsDirtyElement = boolean;
12
+ export declare function $garbageCollectDetachedNodes(prevEditorState: EditorState, editorState: EditorState, dirtyLeaves: Set<NodeKey>, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>): void;
13
+ export {};
@@ -0,0 +1,10 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalEditor } from './LexicalEditor';
8
+ export declare function getIsProcessingMutations(): boolean;
9
+ export declare function flushRootMutations(editor: LexicalEditor): void;
10
+ export declare function initMutationObserver(editor: LexicalEditor): void;