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