@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,224 @@
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 { LexicalNode } from '../LexicalNode';
9
+ import { type PointType, type RangeSelection } from '../LexicalSelection';
10
+ import { type ElementNode } from '../nodes/LexicalElementNode';
11
+ import { type TextNode } from '../nodes/LexicalTextNode';
12
+ import type {
13
+ CaretDirection,
14
+ CaretRange,
15
+ NodeCaret,
16
+ PointCaret,
17
+ RootMode,
18
+ SiblingCaret,
19
+ TextPointCaret,
20
+ } from './LexicalCaret';
21
+
22
+ /**
23
+ * @param point
24
+ * @returns a PointCaret for the point
25
+ */
26
+ export declare function $caretFromPoint<D extends CaretDirection>(
27
+ point: Pick<PointType, 'type' | 'key' | 'offset'>,
28
+ direction: D,
29
+ ): PointCaret<D>;
30
+ /**
31
+ * Update the given point in-place from the PointCaret
32
+ *
33
+ * @param point the point to set
34
+ * @param caret the caret to set the point from
35
+ */
36
+ export declare function $setPointFromCaret<D extends CaretDirection>(
37
+ point: PointType,
38
+ caret: PointCaret<D>,
39
+ ): void;
40
+ /**
41
+ * Set a RangeSelection on the editor from the given CaretRange
42
+ *
43
+ * @returns The new RangeSelection
44
+ */
45
+ export declare function $setSelectionFromCaretRange(caretRange: CaretRange): RangeSelection;
46
+ /**
47
+ * Update the points of a RangeSelection based on the given PointCaret.
48
+ */
49
+ export declare function $updateRangeSelectionFromCaretRange(
50
+ selection: RangeSelection,
51
+ caretRange: CaretRange,
52
+ ): void;
53
+ /**
54
+ * Get a pair of carets for a RangeSelection.
55
+ *
56
+ * If the focus is before the anchor, then the direction will be
57
+ * 'previous', otherwise the direction will be 'next'.
58
+ */
59
+ export declare function $caretRangeFromSelection(selection: RangeSelection): CaretRange;
60
+ /**
61
+ * Given a SiblingCaret we can always compute a caret that points to the
62
+ * origin of that caret in the same direction. The adjacent caret of the
63
+ * returned caret will be equivalent to the given caret.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * siblingCaret.is($rewindSiblingCaret(siblingCaret).getAdjacentCaret())
68
+ * ```
69
+ *
70
+ * @param caret The caret to "rewind"
71
+ * @returns A new caret (ChildCaret or SiblingCaret) with the same direction
72
+ */
73
+ export declare function $rewindSiblingCaret<T extends LexicalNode, D extends CaretDirection>(
74
+ caret: SiblingCaret<T, D>,
75
+ ): NodeCaret<D>;
76
+ /**
77
+ * Remove all text and nodes in the given range. If the range spans multiple
78
+ * blocks then the remaining contents of the later block will be merged with
79
+ * the earlier block.
80
+ *
81
+ * @param initialRange The range to remove text and nodes from
82
+ * @param sliceMode If 'preserveEmptyTextPointCaret' it will leave an empty TextPointCaret at the anchor for insert if one exists, otherwise empty slices will be removed
83
+ * @returns The new collapsed range (biased towards the earlier node)
84
+ */
85
+ export declare function $removeTextFromCaretRange<D extends CaretDirection>(
86
+ initialRange: CaretRange<D>,
87
+ sliceMode?: 'removeEmptySlices' | 'preserveEmptyTextSliceCaret',
88
+ ): CaretRange<D>;
89
+ /**
90
+ * Normalize a caret to the deepest equivalent PointCaret.
91
+ * This will return a TextPointCaret with the offset set according
92
+ * to the direction if given a caret with a TextNode origin
93
+ * or a caret with an ElementNode origin with the deepest ChildCaret
94
+ * having an adjacent TextNode.
95
+ *
96
+ * If given a TextPointCaret, it will be returned, as no normalization
97
+ * is required when an offset is already present.
98
+ *
99
+ * @param initialCaret
100
+ * @returns The normalized PointCaret
101
+ */
102
+ export declare function $normalizeCaret<D extends CaretDirection>(
103
+ initialCaret: PointCaret<D>,
104
+ ): PointCaret<D>;
105
+ declare const PointCaretIsExtendableBrand: unique symbol;
106
+ /**
107
+ * Determine whether the TextPointCaret's offset can be extended further without leaving the TextNode.
108
+ * Returns false if the given caret is not a TextPointCaret or the offset can not be moved further in
109
+ * direction.
110
+ *
111
+ * @param caret A PointCaret
112
+ * @returns true if caret is a TextPointCaret with an offset that is not at the end of the text given the direction.
113
+ */
114
+ export declare function $isExtendableTextPointCaret<D extends CaretDirection>(
115
+ caret: PointCaret<D>,
116
+ ): caret is TextPointCaret<TextNode, D> & {
117
+ [PointCaretIsExtendableBrand]: never;
118
+ };
119
+ /**
120
+ * Return the caret if it's in the given direction, otherwise return
121
+ * caret.getFlipped().
122
+ *
123
+ * @param caret Any PointCaret
124
+ * @param direction The desired direction
125
+ * @returns A PointCaret in direction
126
+ */
127
+ export declare function $getCaretInDirection<
128
+ Caret extends PointCaret<CaretDirection>,
129
+ D extends CaretDirection,
130
+ >(
131
+ caret: Caret,
132
+ direction: D,
133
+ ):
134
+ | NodeCaret<D>
135
+ | (Caret extends TextPointCaret<TextNode, CaretDirection> ? TextPointCaret<TextNode, D> : never);
136
+ /**
137
+ * Return the range if it's in the given direction, otherwise
138
+ * construct a new range using a flipped focus as the anchor
139
+ * and a flipped anchor as the focus. This transformation
140
+ * preserves the section of the document that it's working
141
+ * with, but reverses the order of iteration.
142
+ *
143
+ * @param range Any CaretRange
144
+ * @param direction The desired direction
145
+ * @returns A CaretRange in direction
146
+ */
147
+ export declare function $getCaretRangeInDirection<D extends CaretDirection>(
148
+ range: CaretRange<CaretDirection>,
149
+ direction: D,
150
+ ): CaretRange<D>;
151
+ /**
152
+ * Get a caret pointing at the child at the given index, or the last
153
+ * caret in that node if out of bounds.
154
+ *
155
+ * @param parent An ElementNode
156
+ * @param index The index of the origin for the caret
157
+ * @returns A caret pointing towards the node at that index
158
+ */
159
+ export declare function $getChildCaretAtIndex<D extends CaretDirection>(
160
+ parent: ElementNode,
161
+ index: number,
162
+ direction: D,
163
+ ): NodeCaret<D>;
164
+ /**
165
+ * Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
166
+ * R -> P -> T1, T2
167
+ * -> P2
168
+ * returns T2 for node T1, P2 for node T2, and null for node P2.
169
+ * @param startCaret The initial caret
170
+ * @param rootMode The root mode, 'root' (default) or 'shadowRoot'
171
+ * @returns An array (tuple) containing the found caret and the depth difference, or null, if this node doesn't exist.
172
+ */
173
+ export declare function $getAdjacentSiblingOrParentSiblingCaret<D extends CaretDirection>(
174
+ startCaret: NodeCaret<D>,
175
+ rootMode?: RootMode,
176
+ ): null | [NodeCaret<D>, number];
177
+ /**
178
+ * Get the adjacent nodes to initialCaret in the given direction.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * expect($getAdjacentNodes($getChildCaret(parent, 'next'))).toEqual(parent.getChildren());
183
+ * expect($getAdjacentNodes($getChildCaret(parent, 'previous'))).toEqual(parent.getChildren().reverse());
184
+ * expect($getAdjacentNodes($getSiblingCaret(node, 'next'))).toEqual(node.getNextSiblings());
185
+ * expect($getAdjacentNodes($getSiblingCaret(node, 'previous'))).toEqual(node.getPreviousSiblings().reverse());
186
+ * ```
187
+ *
188
+ * @param initialCaret The caret to start at (the origin will not be included)
189
+ * @returns An array of siblings.
190
+ */
191
+ export declare function $getAdjacentNodes(initialCaret: NodeCaret<CaretDirection>): LexicalNode[];
192
+ export declare function $splitTextPointCaret<D extends CaretDirection>(
193
+ textPointCaret: TextPointCaret<TextNode, D>,
194
+ ): NodeCaret<D>;
195
+ export interface SplitAtPointCaretNextOptions {
196
+ /** The function to create the right side of a split ElementNode (default {@link $copyNode}) */
197
+ $copyElementNode?: (node: ElementNode) => ElementNode;
198
+ /** The function to split a TextNode (default {@link $splitTextPointCaret}) */
199
+ $splitTextPointCaretNext?: (caret: TextPointCaret<TextNode, 'next'>) => NodeCaret<'next'>;
200
+ /** If the parent matches rootMode a split will not occur, default is 'shadowRoot' */
201
+ rootMode?: RootMode;
202
+ /**
203
+ * If element.canBeEmpty() and would create an empty split, this function will be
204
+ * called with the element and 'first' | 'last'. If it returns false, the empty
205
+ * split will not be created. Default is `() => true` to always split when possible.
206
+ */
207
+ $shouldSplit?: (node: ElementNode, edge: 'first' | 'last') => boolean;
208
+ }
209
+ /**
210
+ * Split a node at a PointCaret and return a NodeCaret at that point, or null if the
211
+ * node can't be split. This is non-recursive and will only perform at most one split.
212
+ *
213
+ * @returns The NodeCaret pointing to the location of the split (or null if a split is not possible)
214
+ */
215
+ export declare function $splitAtPointCaretNext(
216
+ pointCaret: PointCaret<'next'>,
217
+ {
218
+ $copyElementNode,
219
+ $splitTextPointCaretNext,
220
+ rootMode,
221
+ $shouldSplit,
222
+ }?: SplitAtPointCaretNextOptions,
223
+ ): null | NodeCaret<'next'>;
224
+ export {};
@@ -0,0 +1,126 @@
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 {
9
+ AnyLexicalExtension,
10
+ ExtensionConfigBase,
11
+ LexicalExtension,
12
+ LexicalExtensionConfig,
13
+ NormalizedLexicalExtensionArgument,
14
+ NormalizedPeerDependency,
15
+ } from './types';
16
+
17
+ /**
18
+ * @experimental
19
+ * Define a LexicalExtension from the given object literal. TypeScript will
20
+ * infer Config and Name in most cases, but you may want to use
21
+ * {@link safeCast} for config if there are default fields or varying types.
22
+ *
23
+ * @param extension - The LexicalExtension
24
+ * @returns The unmodified extension argument (this is only an inference helper)
25
+ *
26
+ * @example
27
+ * Basic example
28
+ * ```ts
29
+ * export const MyExtension = defineExtension({
30
+ * // Extension names must be unique in an editor
31
+ * name: "my",
32
+ * nodes: [MyNode],
33
+ * });
34
+ * ```
35
+ *
36
+ * @example
37
+ * Extension with optional configuration
38
+ * ```ts
39
+ * export interface ConfigurableConfig {
40
+ * optional?: string;
41
+ * required: number;
42
+ * }
43
+ * export const ConfigurableExtension = defineExtension({
44
+ * name: "configurable",
45
+ * // The Extension's config must satisfy the full config type,
46
+ * // but using the Extension as a dependency never requires
47
+ * // configuration and any partial of the config can be specified
48
+ * config: safeCast<ConfigurableConfig>({ required: 1 }),
49
+ * });
50
+ * ```
51
+ *
52
+ * @__NO_SIDE_EFFECTS__
53
+ */
54
+ export declare function defineExtension<
55
+ Config extends ExtensionConfigBase,
56
+ Name extends string,
57
+ Output,
58
+ Init,
59
+ >(
60
+ extension: LexicalExtension<Config, Name, Output, Init>,
61
+ ): LexicalExtension<Config, Name, Output, Init>;
62
+ /**
63
+ * @experimental
64
+ * Override a partial of the configuration of an Extension, to be used
65
+ * in the dependencies array of another extension, or as
66
+ * an argument to {@link buildEditorFromExtensions}.
67
+ *
68
+ * Before building the editor, configurations will be merged using
69
+ * `extension.mergeConfig(extension, config)` or {@link shallowMergeConfig} if
70
+ * this is not directly implemented by the Extension.
71
+ *
72
+ * @param args - An extension followed by one or more config partials for that extension
73
+ * @returns `[extension, config, ...configs]`
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * export const ReactDecoratorExtension = defineExtension({
78
+ * name: "react-decorator",
79
+ * dependencies: [
80
+ * configExtension(ReactExtension, {
81
+ * decorators: [<ReactDecorator />]
82
+ * }),
83
+ * ],
84
+ * });
85
+ * ```
86
+ *
87
+ * @__NO_SIDE_EFFECTS__
88
+ */
89
+ export declare function configExtension<
90
+ Config extends ExtensionConfigBase,
91
+ Name extends string,
92
+ Output,
93
+ Init,
94
+ >(
95
+ ...args: NormalizedLexicalExtensionArgument<Config, Name, Output, Init>
96
+ ): NormalizedLexicalExtensionArgument<Config, Name, Output, Init>;
97
+ /**
98
+ * @experimental
99
+ * Used to declare a peer dependency of an extension in a type-safe way,
100
+ * requires the type parameter. The most common use case for peer dependencies
101
+ * is to avoid a direct import dependency, so you would want to use a
102
+ * type import or the import type (shown in below examples).
103
+ *
104
+ * @param name - The extension's name
105
+ * @param config - An optional config override
106
+ * @returns NormalizedPeerDependency
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import type {FooExtension} from "foo";
111
+ *
112
+ * export const PeerExtension = defineExtension({
113
+ * name: 'PeerExtension',
114
+ * peerDependencies: [
115
+ * declarePeerDependency<FooExtension>("foo"),
116
+ * declarePeerDependency<typeof import("bar").BarExtension>("bar", {config: "bar"}),
117
+ * ],
118
+ * });
119
+ * ```
120
+ *
121
+ * @__NO_SIDE_EFFECTS__
122
+ */
123
+ export declare function declarePeerDependency<Extension extends AnyLexicalExtension = never>(
124
+ name: Extension['name'],
125
+ config?: Partial<LexicalExtensionConfig<Extension>>,
126
+ ): NormalizedPeerDependency<Extension>;
@@ -0,0 +1,38 @@
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
+ export { configExtension, declarePeerDependency, defineExtension } from './defineExtension';
9
+ export {
10
+ type configTypeSymbol,
11
+ type initTypeSymbol,
12
+ type LexicalExtensionInternal,
13
+ type outputTypeSymbol,
14
+ } from './internal';
15
+ export { safeCast } from './safeCast';
16
+ export { shallowMergeConfig } from './shallowMergeConfig';
17
+ export {
18
+ type AnyLexicalExtension,
19
+ type AnyLexicalExtensionArgument,
20
+ type AnyNormalizedLexicalExtensionArgument,
21
+ type ExtensionBuildState,
22
+ type ExtensionConfigBase,
23
+ type ExtensionInitState,
24
+ type ExtensionRegisterState,
25
+ type InitialEditorConfig,
26
+ type InitialEditorStateType,
27
+ type LexicalEditorWithDispose,
28
+ type LexicalExtension,
29
+ type LexicalExtensionArgument,
30
+ type LexicalExtensionConfig,
31
+ type LexicalExtensionDependency,
32
+ type LexicalExtensionInit,
33
+ type LexicalExtensionName,
34
+ type LexicalExtensionOutput,
35
+ type NormalizedLexicalExtensionArgument,
36
+ type NormalizedPeerDependency,
37
+ type OutputComponentExtension,
38
+ } from './types';
@@ -0,0 +1,32 @@
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
+ /** @internal */
9
+ export declare const peerDependencySymbol: unique symbol;
10
+ /** @internal */
11
+ export type peerDependencySymbol = typeof peerDependencySymbol;
12
+ /** @internal */
13
+ export declare const configTypeSymbol: unique symbol;
14
+ /** @internal */
15
+ export type configTypeSymbol = typeof configTypeSymbol;
16
+ /** @internal */
17
+ export declare const outputTypeSymbol: unique symbol;
18
+ /** @internal */
19
+ export type outputTypeSymbol = typeof outputTypeSymbol;
20
+ /** @internal */
21
+ export declare const initTypeSymbol: unique symbol;
22
+ /** @internal */
23
+ export type initTypeSymbol = typeof initTypeSymbol;
24
+ /** @internal */
25
+ export interface LexicalExtensionInternal<Config, Output, Init> {
26
+ /** @internal */
27
+ readonly [configTypeSymbol]?: Config;
28
+ /** @internal */
29
+ readonly [outputTypeSymbol]?: Output;
30
+ /** @internal */
31
+ readonly [initTypeSymbol]?: Init;
32
+ }
@@ -0,0 +1,15 @@
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
+ /**
9
+ * Explicitly and safely cast a value to a specific type when inference or
10
+ * satisfies isn't going to work as expected (often useful for the config
11
+ * property with {@link defineExtension})
12
+ *
13
+ * @__NO_SIDE_EFFECTS__
14
+ */
15
+ export declare function safeCast<T>(value: T): T;
@@ -0,0 +1,20 @@
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 { ExtensionConfigBase } from './types';
9
+
10
+ /**
11
+ * The default merge strategy for extension configuration is a shallow merge.
12
+ *
13
+ * @param config - A full config
14
+ * @param overrides - A partial config of overrides
15
+ * @returns config if there are no overrides, otherwise `{...config, ...overrides}`
16
+ */
17
+ export declare function shallowMergeConfig<T extends ExtensionConfigBase>(
18
+ config: T,
19
+ overrides?: Partial<T>,
20
+ ): T;