@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,371 @@
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 { CreateEditorArgs, EditorState, LexicalEditor } from 'lexical';
9
+
10
+ import type {
11
+ LexicalExtensionInternal,
12
+ configTypeSymbol,
13
+ initTypeSymbol,
14
+ outputTypeSymbol,
15
+ peerDependencySymbol,
16
+ } from './internal';
17
+
18
+ /**
19
+ * Any concrete {@link LexicalExtension}
20
+ */
21
+ export type AnyLexicalExtension = LexicalExtension<any, string, any, any>;
22
+ /**
23
+ * Any {@link LexicalExtension} or {@link NormalizedLexicalExtensionArgument}
24
+ */
25
+ export type AnyLexicalExtensionArgument =
26
+ | AnyLexicalExtension
27
+ | AnyNormalizedLexicalExtensionArgument;
28
+ /**
29
+ * The default extension configuration of an empty object
30
+ */
31
+ export type ExtensionConfigBase = Record<never, never>;
32
+ /**
33
+ * The result of {@link declarePeerDependency}, a tuple of a peer dependency
34
+ * name and its associated configuration.
35
+ */
36
+ export type NormalizedPeerDependency<Extension extends AnyLexicalExtension> = [
37
+ Extension['name'],
38
+ Partial<LexicalExtensionConfig<Extension>> | undefined,
39
+ ] & {
40
+ readonly [peerDependencySymbol]?: Extension;
41
+ };
42
+ /**
43
+ * A tuple of `[extension, ...configOverrides]`
44
+ */
45
+ export type NormalizedLexicalExtensionArgument<
46
+ Config extends ExtensionConfigBase,
47
+ Name extends string,
48
+ Output,
49
+ Init,
50
+ > = [LexicalExtension<Config, Name, Output, Init>, ...Partial<Config>[]];
51
+ /**
52
+ * Any {@link NormalizedLexicalExtensionArgument}
53
+ */
54
+ export type AnyNormalizedLexicalExtensionArgument = NormalizedLexicalExtensionArgument<
55
+ any,
56
+ string,
57
+ any,
58
+ any
59
+ >;
60
+ /**
61
+ * An object that the init method can use to access the
62
+ * configuration for extension dependencies
63
+ */
64
+ export interface ExtensionInitState {
65
+ /**
66
+ * Get the result of a peerDependency by name, if it exists
67
+ * (must be a peerDependency of this extension)
68
+ */
69
+ getPeer: <Dependency extends AnyLexicalExtension = never>(
70
+ name: Dependency['name'],
71
+ ) => undefined | Omit<LexicalExtensionDependency<Dependency>, 'output' | 'init'>;
72
+ /**
73
+ * Get the configuration of a dependency by extension
74
+ * (must be a direct dependency of this extension)
75
+ */
76
+ getDependency: <Dependency extends AnyLexicalExtension>(
77
+ dep: Dependency,
78
+ ) => Omit<LexicalExtensionDependency<Dependency>, 'output' | 'init'>;
79
+ /**
80
+ * Get the names of any direct dependents of this
81
+ * Extension, typically only used for error messages.
82
+ */
83
+ getDirectDependentNames: () => ReadonlySet<string>;
84
+ /**
85
+ * Get the names of all peer dependencies of this
86
+ * Extension, even if they do not exist in the builder,
87
+ * typically only used for devtools.
88
+ */
89
+ getPeerNameSet: () => ReadonlySet<string>;
90
+ }
91
+ export interface ExtensionBuildState<Init> extends Omit<
92
+ ExtensionInitState,
93
+ 'getPeer' | 'getDependency'
94
+ > {
95
+ /**
96
+ * Get the result of a peerDependency by name, if it exists
97
+ * (must be a peerDependency of this extension)
98
+ */
99
+ getPeer: <Dependency extends AnyLexicalExtension = never>(
100
+ name: Dependency['name'],
101
+ ) => undefined | LexicalExtensionDependency<Dependency>;
102
+ /**
103
+ * Get the configuration of a dependency by extension
104
+ * (must be a direct dependency of this extension)
105
+ */
106
+ getDependency: <Dependency extends AnyLexicalExtension>(
107
+ dep: Dependency,
108
+ ) => LexicalExtensionDependency<Dependency>;
109
+ /**
110
+ * The result of the init function
111
+ */
112
+ getInitResult: () => Init;
113
+ }
114
+ /**
115
+ * An object that the register method can use to detect unmount and access the
116
+ * configuration for extension dependencies
117
+ */
118
+ export interface ExtensionRegisterState<Init, Output> extends ExtensionBuildState<Init> {
119
+ /** An AbortSignal that is aborted when this LexicalEditor registration is disposed */
120
+ getSignal: () => AbortSignal;
121
+ /**
122
+ * The result of the output function
123
+ */
124
+ getOutput: () => Output;
125
+ }
126
+ /**
127
+ * A {@link LexicalExtension} or {@link NormalizedLexicalExtensionArgument} (extension with config overrides)
128
+ */
129
+ export type LexicalExtensionArgument<
130
+ Config extends ExtensionConfigBase,
131
+ Name extends string,
132
+ Output,
133
+ Init,
134
+ > =
135
+ | LexicalExtension<Config, Name, Output, Init>
136
+ | NormalizedLexicalExtensionArgument<Config, Name, Output, Init>;
137
+ export interface LexicalExtensionDependency<out Dependency extends AnyLexicalExtension> {
138
+ init: LexicalExtensionInit<Dependency>;
139
+ config: LexicalExtensionConfig<Dependency>;
140
+ output: LexicalExtensionOutput<Dependency>;
141
+ }
142
+ /**
143
+ * An Extension is a composable unit of LexicalEditor configuration
144
+ * (nodes, theme, etc) used to create an editor, plus runtime behavior
145
+ * that is registered after the editor is created.
146
+ *
147
+ * An Extension may depend on other Extensions, and provide functionality to other
148
+ * extensions through its config.
149
+ */
150
+ export interface LexicalExtension<
151
+ Config extends ExtensionConfigBase,
152
+ Name extends string,
153
+ Output,
154
+ Init,
155
+ >
156
+ extends InitialEditorConfig, LexicalExtensionInternal<Config, Output, Init> {
157
+ /** The name of the Extension, must be unique */
158
+ readonly name: Name;
159
+ /**
160
+ * Extension names that must not be loaded with this Extension.
161
+ * If this extension and any of the conflicting extensions are configured
162
+ * in the same editor then a runtime error will be thrown instead of
163
+ * creating the editor. This is used to prevent extensions with incompatible
164
+ * and overlapping functionality from being registered concurrently, such as
165
+ * PlainTextExtension and RichTextExtension.
166
+ **/
167
+ conflictsWith?: string[];
168
+ /** Other Extensions that this Extension depends on, can also be used to configure them */
169
+ dependencies?: AnyLexicalExtensionArgument[];
170
+ /**
171
+ * Other Extensions, by name, that this Extension can optionally depend on or
172
+ * configure, if they are directly depended on by another Extension
173
+ */
174
+ peerDependencies?: NormalizedPeerDependency<AnyLexicalExtension>[];
175
+ /**
176
+ * The default configuration specific to this Extension. This Config may be
177
+ * seen by this Extension, or any Extension that uses it as a dependency.
178
+ *
179
+ * The config may be mutated on register, this is particularly useful
180
+ * for vending functionality to other Extensions that depend on this Extension.
181
+ */
182
+ config?: Config;
183
+ /**
184
+ * By default, Config is shallow merged `{...a, ...b}` with
185
+ * {@link shallowMergeConfig}, if your Extension requires other strategies
186
+ * (such as concatenating an Array) you can implement it here.
187
+ *
188
+ * @example
189
+ * Merging an array
190
+ * ```js
191
+ * const extension = defineExtension({
192
+ * // ...
193
+ * mergeConfig(config, overrides) {
194
+ * const merged = shallowMergeConfig(config, overrides);
195
+ * if (Array.isArray(overrides.decorators)) {
196
+ * merged.decorators = [...config.decorators, ...overrides.decorators];
197
+ * }
198
+ * return merged;
199
+ * }
200
+ * });
201
+ * ```
202
+ *
203
+ * @param config - The current configuration
204
+ * @param overrides - The partial configuration to merge
205
+ * @returns The merged configuration
206
+ */
207
+ mergeConfig?: (config: Config, overrides: Partial<Config>) => Config;
208
+ /**
209
+ * Perform any necessary initialization before the editor is created,
210
+ * this runs after all configuration overrides for both the editor this
211
+ * this extension have been merged. May be used validate the editor
212
+ * configuration.
213
+ *
214
+ * @param editorConfig - The in-progress editor configuration (mutable)
215
+ * @param config - The merged configuration specific to this extension (mutable)
216
+ * @param state - An object containing methods for accessing the merged
217
+ * configuration of dependencies and peerDependencies
218
+ */
219
+ init?: (editorConfig: InitialEditorConfig, config: Config, state: ExtensionInitState) => Init;
220
+ /**
221
+ * Perform any tasks that require a LexicalEditor instance, but before
222
+ * registration has taken place. May provide output to be used by
223
+ * dependencies or the application (commands, components, etc.).
224
+ * This will only be run once, and any work performed by the output
225
+ * function must not require cleanup.
226
+ */
227
+ build?: (editor: LexicalEditor, config: Config, state: ExtensionBuildState<Init>) => Output;
228
+ /**
229
+ * Add behavior to the editor (register transforms, listeners, etc.) after
230
+ * the Editor is created, but before its initial state is set.
231
+ * The register function may also mutate the config
232
+ * in-place to expose data to other extensions that use it as a dependency.
233
+ *
234
+ * @param editor - The editor this Extension is being registered with
235
+ * @param config - The merged configuration specific to this Extension
236
+ * @param state - An object containing an AbortSignal that can be
237
+ * used, and methods for accessing the merged configuration of
238
+ * dependencies and peerDependencies
239
+ * @returns A clean-up function
240
+ */
241
+ register?: (
242
+ editor: LexicalEditor,
243
+ config: Config,
244
+ state: ExtensionRegisterState<Init, Output>,
245
+ ) => () => void;
246
+ /**
247
+ * Run any code that must happen after initialization of the
248
+ * editor state (which happens after all register calls).
249
+ *
250
+ * @param editor - The editor this Extension is being registered with
251
+ * @param config - The merged configuration specific to this Extension
252
+ * @param state - An object containing an AbortSignal that can be
253
+ * used, and methods for accessing the merged configuration of
254
+ * dependencies and peerDependencies
255
+ * @returns A clean-up function
256
+ */
257
+ afterRegistration?: (
258
+ editor: LexicalEditor,
259
+ config: Config,
260
+ state: ExtensionRegisterState<Init, Output>,
261
+ ) => () => void;
262
+ }
263
+ /**
264
+ * Extract the Config type from an Extension
265
+ */
266
+ export type LexicalExtensionConfig<Extension extends AnyLexicalExtension> = NonNullable<
267
+ Extension[configTypeSymbol]
268
+ >;
269
+ /**
270
+ * Extract the Name type from an Extension
271
+ */
272
+ export type LexicalExtensionName<Extension extends AnyLexicalExtension> = Extension['name'];
273
+ /**
274
+ * Extract the Output type from an Extension
275
+ */
276
+ export type LexicalExtensionOutput<Extension extends AnyLexicalExtension> = NonNullable<
277
+ Extension[outputTypeSymbol]
278
+ >;
279
+ /**
280
+ * Extract the Init type from an Extension
281
+ */
282
+ export type LexicalExtensionInit<Extension extends AnyLexicalExtension> = NonNullable<
283
+ Extension[initTypeSymbol]
284
+ >;
285
+ /**
286
+ * An Extension that has an OutputComponent of the given type (e.g. React.ComponentType)
287
+ */
288
+ export type OutputComponentExtension<ComponentType> = LexicalExtension<
289
+ any,
290
+ any,
291
+ {
292
+ Component: ComponentType;
293
+ },
294
+ any
295
+ >;
296
+ /**
297
+ * A handle to the editor with an attached dispose function
298
+ */
299
+ export interface LexicalEditorWithDispose extends LexicalEditor, Disposable {
300
+ /**
301
+ * Dispose the editor and perform all clean-up
302
+ * (also available as Symbol.dispose via Disposable)
303
+ */
304
+ dispose: () => void;
305
+ }
306
+ /**
307
+ * All of the possible ways to initialize $initialEditorState:
308
+ * - `null` an empty state, the default
309
+ * - `string` an EditorState serialized to JSON
310
+ * - `EditorState` an EditorState that has been deserialized already (not just parsed JSON)
311
+ * - `((editor: LexicalEditor) => void)` A function that is called with the editor for you to mutate it
312
+ */
313
+ export type InitialEditorStateType =
314
+ | null
315
+ | string
316
+ | EditorState
317
+ | ((editor: LexicalEditor) => void);
318
+ export interface InitialEditorConfig {
319
+ /**
320
+ * @internal Disable root element events (for internal Meta use)
321
+ */
322
+ disableEvents?: CreateEditorArgs['disableEvents'];
323
+ /**
324
+ * Used when this editor is nested inside of another editor
325
+ */
326
+ parentEditor?: CreateEditorArgs['parentEditor'];
327
+ /**
328
+ * The namespace of this Editor. If two editors share the same
329
+ * namespace, JSON will be the clipboard interchange format.
330
+ * Otherwise HTML will be used.
331
+ */
332
+ namespace?: CreateEditorArgs['namespace'];
333
+ /**
334
+ * The nodes that this Extension adds to the Editor configuration, will be
335
+ * merged with other Extensions.
336
+ *
337
+ * Can be a function to defer the access of the nodes to editor construction
338
+ * which may be useful in cases when the node and extension are defined in
339
+ * different modules and have depenendencies on each other, depending on the
340
+ * bundler configuration.
341
+ */
342
+ nodes?: CreateEditorArgs['nodes'] | (() => CreateEditorArgs['nodes']);
343
+ /**
344
+ * EditorThemeClasses that will be deep merged with other Extensions
345
+ */
346
+ theme?: CreateEditorArgs['theme'];
347
+ /**
348
+ * Overrides for HTML serialization (exportDOM) and
349
+ * deserialization (importDOM) that does not require subclassing and node
350
+ * replacement
351
+ */
352
+ html?: CreateEditorArgs['html'];
353
+ /**
354
+ * Whether the initial state of the editor is editable or not
355
+ */
356
+ editable?: CreateEditorArgs['editable'];
357
+ /**
358
+ * The editor will catch errors that happen during updates and
359
+ * reconciliation and call this. It defaults to
360
+ * `(error) => { throw error }`.
361
+ *
362
+ * @param error - The Error object
363
+ * @param editor - The editor that this error came from
364
+ */
365
+ onError?: (error: Error, editor: LexicalEditor) => void;
366
+ /**
367
+ * The initial EditorState as a JSON string, an EditorState, or a function
368
+ * to update the editor (once).
369
+ */
370
+ $initialEditorState?: InitialEditorStateType;
371
+ }