@lobehub/editor 3.3.1 → 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 (61) 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/codemirror-block/command/index.js +35 -4
  41. package/es/plugins/codemirror-block/index.d.ts +1 -0
  42. package/es/plugins/codemirror-block/index.js +5 -0
  43. package/es/plugins/codemirror-block/react/CodemirrorNode.js +8 -0
  44. package/es/plugins/codemirror-block/react/style.js +1 -1
  45. package/es/plugins/common/data-source/json-data-source.js +29 -3
  46. package/es/plugins/common/react/ReactPlainText.js +9 -0
  47. package/es/plugins/common/utils/index.d.ts +2 -1
  48. package/es/plugins/common/utils/index.js +33 -0
  49. package/es/plugins/litexml/command/index.js +9 -1
  50. package/es/plugins/litexml/data-source/litexml-data-source.js +12 -2
  51. package/es/plugins/litexml/plugin/index.js +41 -3
  52. package/es/plugins/litexml/utils/index.d.ts +2 -1
  53. package/es/plugins/litexml/utils/index.js +7 -1
  54. package/es/plugins/markdown/data-source/markdown-data-source.js +6 -25
  55. package/es/plugins/markdown/data-source/markdown-writer-context.d.ts +5 -1
  56. package/es/plugins/markdown/data-source/markdown-writer-context.js +27 -2
  57. package/es/plugins/markdown/service/shortcut.d.ts +7 -0
  58. package/es/react/hooks/useEditorState/index.js +47 -12
  59. package/es/types/kernel.d.ts +4 -0
  60. package/package.json +8 -2
  61. package/scripts/patch-lexical.js +39 -0
@@ -33,7 +33,7 @@ import { INodeHelper } from "../../../editor-kernel/inode/helper";
33
33
  import { INodeService } from "../../inode";
34
34
  import { createDebugLogger } from "../../../utils/debug";
35
35
  import { LitexmlService } from "../service/litexml-service";
36
- import { charToId, idToChar } from "../utils";
36
+ import { $parseSerializedNodeImpl, charToId, idToChar } from "../utils";
37
37
  var logger = createDebugLogger('plugin', 'litexml');
38
38
  var IXmlWriterContext = /*#__PURE__*/function () {
39
39
  function IXmlWriterContext() {
@@ -97,7 +97,17 @@ var LitexmlDataSource = /*#__PURE__*/function (_DataSource) {
97
97
  value: function read(editor, data) {
98
98
  try {
99
99
  var inode = this.readLiteXMLToInode(data);
100
- editor.setEditorState(editor.parseEditorState(inode));
100
+ var newState = editor.parseEditorState({
101
+ root: INodeHelper.createRootNode()
102
+ }, function (state) {
103
+ try {
104
+ var root = $parseSerializedNodeImpl(inode.root, editor, true, state);
105
+ state._nodeMap.set(root.getKey(), root);
106
+ } catch (error) {
107
+ console.error(error);
108
+ }
109
+ });
110
+ editor.setEditorState(newState);
101
111
  } catch (error) {
102
112
  logger.error('Failed to parse XML:', error);
103
113
  throw error;
@@ -14,6 +14,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
14
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
15
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
16
  import { KernelPlugin } from "../../../editor-kernel/plugin";
17
+ import { IMarkdownShortCutService } from "../../markdown";
17
18
  import { registerLiteXMLCommand } from "../command";
18
19
  import { registerLiteXMLDiffCommand } from "../command/diffCommand";
19
20
  import LitexmlDataSource from "../data-source/litexml-data-source";
@@ -74,11 +75,12 @@ export var LitexmlPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
74
75
  // Plugin initialization logic can be added here if needed
75
76
  this.register(registerLiteXMLCommand(editor, this.datasource));
76
77
  this.register(registerLiteXMLDiffCommand(editor));
77
- this.regiserLiteXml();
78
+ this.registerLiteXml();
79
+ this.registerMarkdown();
78
80
  }
79
81
  }, {
80
- key: "regiserLiteXml",
81
- value: function regiserLiteXml() {
82
+ key: "registerLiteXml",
83
+ value: function registerLiteXml() {
82
84
  this.service.registerXMLWriter(DiffNode.getType(), function (node, ctx, indent, nodeToXML) {
83
85
  var diffNode = node;
84
86
  var lines = [];
@@ -114,6 +116,42 @@ export var LitexmlPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
114
116
  };
115
117
  });
116
118
  }
119
+ }, {
120
+ key: "registerMarkdown",
121
+ value: function registerMarkdown() {
122
+ var markdownService = this.kernel.requireService(IMarkdownShortCutService);
123
+ markdownService === null || markdownService === void 0 || markdownService.registerMarkdownWriter(DiffNode.getType(), function (ctx, node) {
124
+ var diffNode = node;
125
+ switch (diffNode.diffType) {
126
+ case 'modify':
127
+ {
128
+ ctx.processChild(ctx, diffNode.getChildAtIndex(1));
129
+ break;
130
+ }
131
+ case 'add':
132
+ {
133
+ ctx.processChild(ctx, diffNode.getChildAtIndex(0));
134
+ break;
135
+ }
136
+ case 'remove':
137
+ {
138
+ break;
139
+ }
140
+ case 'listItemModify':
141
+ {
142
+ diffNode.getChildAtIndex(1).getChildren().forEach(function (child) {
143
+ ctx.processChild(ctx, child);
144
+ });
145
+ break;
146
+ }
147
+ default:
148
+ {
149
+ break;
150
+ }
151
+ }
152
+ return true;
153
+ });
154
+ }
117
155
  }]);
118
156
  return LitexmlPlugin;
119
157
  }(KernelPlugin), _defineProperty(_class, "pluginName", 'LitexmlPlugin'), _class);
@@ -1,5 +1,6 @@
1
+ import type { EditorState } from 'lexical';
1
2
  import { LexicalEditor, LexicalNode } from 'lexical';
2
- export declare function $parseSerializedNodeImpl(serializedNode: any, editor: LexicalEditor): LexicalNode;
3
+ export declare function $parseSerializedNodeImpl(serializedNode: any, editor: LexicalEditor, keepId?: boolean, state?: EditorState | null): LexicalNode;
3
4
  export declare function $cloneNode(node: LexicalNode, editor: LexicalEditor): LexicalNode;
4
5
  export declare function idToChar(id: string | number): string;
5
6
  export declare function charToId(char: string): string;
@@ -3,6 +3,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
3
3
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
4
  import { $isElementNode } from 'lexical';
5
5
  export function $parseSerializedNodeImpl(serializedNode, editor) {
6
+ var keepId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
7
+ var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
6
8
  var type = serializedNode.type;
7
9
  var registeredNode = editor._nodes.get(type);
8
10
  if (registeredNode === undefined) {
@@ -13,6 +15,10 @@ export function $parseSerializedNodeImpl(serializedNode, editor) {
13
15
  throw new Error("LexicalNode: Node ".concat(nodeClass.name, " does not implement .importJSON()."));
14
16
  }
15
17
  var node = nodeClass.importJSON(serializedNode);
18
+ if (keepId && serializedNode.id) {
19
+ node.__key = serializedNode.id;
20
+ state === null || state === void 0 || state._nodeMap.set(node.__key, node);
21
+ }
16
22
  var children = serializedNode.children;
17
23
  if ($isElementNode(node) && Array.isArray(children)) {
18
24
  var _iterator = _createForOfIteratorHelper(children),
@@ -20,7 +26,7 @@ export function $parseSerializedNodeImpl(serializedNode, editor) {
20
26
  try {
21
27
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
22
28
  var serializedJSONChildNode = _step.value;
23
- var childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor);
29
+ var childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor, keepId, state);
24
30
  node.append(childNode);
25
31
  }
26
32
  } catch (err) {
@@ -60,25 +60,6 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
60
60
  key: "write",
61
61
  value: function write(editor, options) {
62
62
  var _this2 = this;
63
- var processChild = function processChild(parentCtx, child) {
64
- var writer = _this2.markdownService.markdownWriters[child.getType()];
65
- var currentCtx = parentCtx;
66
- if ($isElementNode(child)) {
67
- currentCtx = currentCtx.newChild();
68
- }
69
- var skipChildren = false;
70
- if (writer) {
71
- skipChildren = writer(currentCtx, child);
72
- }
73
- if (skipChildren) {
74
- return;
75
- }
76
- if ($isElementNode(child)) {
77
- child.getChildren().forEach(function (child) {
78
- return processChild(currentCtx, child);
79
- });
80
- }
81
- };
82
63
  if (options !== null && options !== void 0 && options.selection) {
83
64
  return editor.getEditorState().read(function () {
84
65
  var selection = $getSelection();
@@ -193,10 +174,10 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
193
174
  root: _rootNode
194
175
  });
195
176
  var _lexicalRootNode = _editorState._nodeMap.get('root');
196
- var _rootCtx = new MarkdownWriterContext();
177
+ var _rootCtx = new MarkdownWriterContext(_this2.markdownService);
197
178
  return _editorState.read(function () {
198
179
  _lexicalRootNode.getChildren().forEach(function (child) {
199
- return processChild(_rootCtx, child);
180
+ return _rootCtx.processChild(_rootCtx, child);
200
181
  });
201
182
  return _rootCtx.toString();
202
183
  });
@@ -221,10 +202,10 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
221
202
  root: rootNode
222
203
  });
223
204
  var lexicalRootNode = editorState._nodeMap.get('root');
224
- var rootCtx = new MarkdownWriterContext();
205
+ var rootCtx = new MarkdownWriterContext(_this2.markdownService);
225
206
  return editorState.read(function () {
226
207
  lexicalRootNode.getChildren().forEach(function (child) {
227
- return processChild(rootCtx, child);
208
+ return rootCtx.processChild(rootCtx, child);
228
209
  });
229
210
  return rootCtx.toString();
230
211
  });
@@ -232,9 +213,9 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
232
213
  }
233
214
  return editor.getEditorState().read(function () {
234
215
  var rootNode = $getRoot();
235
- var rootCtx = new MarkdownWriterContext();
216
+ var rootCtx = new MarkdownWriterContext(_this2.markdownService);
236
217
  rootNode.getChildren().forEach(function (child) {
237
- return processChild(rootCtx, child);
218
+ return rootCtx.processChild(rootCtx, child);
238
219
  });
239
220
  return rootCtx.toString();
240
221
  });
@@ -1,12 +1,16 @@
1
- import { IMarkdownWriterContext } from '../service/shortcut';
1
+ import { LexicalNode } from 'lexical';
2
+ import { IMarkdownWriterContext, MarkdownShortCutService } from '../service/shortcut';
2
3
  export declare class MarkdownWriterContext implements IMarkdownWriterContext {
3
4
  private before;
4
5
  private after;
5
6
  private children;
7
+ private markdownService;
6
8
  private processor?;
9
+ constructor(markdownService?: MarkdownShortCutService);
7
10
  appendLine(line: string): void;
8
11
  newChild(): MarkdownWriterContext;
9
12
  wrap(before: string, after: string): void;
10
13
  addProcessor(processor: (before: string, content: string, after: string) => string): void;
11
14
  toString(): string;
15
+ processChild(parentCtx: IMarkdownWriterContext, child: LexicalNode): void;
12
16
  }
@@ -5,13 +5,16 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ import { $isElementNode } from 'lexical';
8
9
  export var MarkdownWriterContext = /*#__PURE__*/function () {
9
- function MarkdownWriterContext() {
10
+ function MarkdownWriterContext(markdownService) {
10
11
  _classCallCheck(this, MarkdownWriterContext);
11
12
  _defineProperty(this, "before", '');
12
13
  _defineProperty(this, "after", '');
13
14
  _defineProperty(this, "children", []);
15
+ _defineProperty(this, "markdownService", void 0);
14
16
  _defineProperty(this, "processor", void 0);
17
+ this.markdownService = markdownService;
15
18
  }
16
19
  _createClass(MarkdownWriterContext, [{
17
20
  key: "appendLine",
@@ -21,7 +24,7 @@ export var MarkdownWriterContext = /*#__PURE__*/function () {
21
24
  }, {
22
25
  key: "newChild",
23
26
  value: function newChild() {
24
- var child = new MarkdownWriterContext();
27
+ var child = new MarkdownWriterContext(this.markdownService);
25
28
  this.children.push(child);
26
29
  return child;
27
30
  }
@@ -46,6 +49,28 @@ export var MarkdownWriterContext = /*#__PURE__*/function () {
46
49
  return child.toString();
47
50
  }).join(''), this.after) : content;
48
51
  }
52
+ }, {
53
+ key: "processChild",
54
+ value: function processChild(parentCtx, child) {
55
+ var _this = this;
56
+ var writer = this.markdownService.markdownWriters[child.getType()];
57
+ var currentCtx = parentCtx;
58
+ if ($isElementNode(child)) {
59
+ currentCtx = currentCtx.newChild();
60
+ }
61
+ var skipChildren = false;
62
+ if (writer) {
63
+ skipChildren = writer(currentCtx, child);
64
+ }
65
+ if (skipChildren) {
66
+ return;
67
+ }
68
+ if ($isElementNode(child)) {
69
+ child.getChildren().forEach(function (child) {
70
+ return _this.processChild(currentCtx, child);
71
+ });
72
+ }
73
+ }
49
74
  }]);
50
75
  return MarkdownWriterContext;
51
76
  }();
@@ -15,6 +15,13 @@ export interface IMarkdownWriterContext {
15
15
  * @returns
16
16
  */
17
17
  appendLine: (line: string) => void;
18
+ /**
19
+ * Control child node to markdown
20
+ * @param parentCtx
21
+ * @param child
22
+ * @returns
23
+ */
24
+ processChild: (parentCtx: IMarkdownWriterContext, child: LexicalNode) => void;
18
25
  /**
19
26
  * Wrap child elements
20
27
  * @param before
@@ -16,6 +16,7 @@ import { noop } from "../../../editor-kernel";
16
16
  import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
17
17
  import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
18
18
  import { UPDATE_CODEBLOCK_LANG } from "../../../plugins/codeblock";
19
+ import { $createCodeMirrorNode, $isCodeMirrorNode } from "../../../plugins/codemirror-block/node/CodeMirrorNode";
19
20
  import { $isRootTextContentEmpty } from "../../../plugins/common/utils";
20
21
  import { INSERT_LINK_HIGHLIGHT_COMMAND } from "../../../plugins/link-highlight/command";
21
22
  import { $isLinkHighlightNode } from "../../../plugins/link-highlight/node/link-highlight";
@@ -137,9 +138,18 @@ export function useEditorState(editor) {
137
138
  var parent = node.getParent();
138
139
  // Check for both Link and LinkHighlight nodes
139
140
  setIsLink($isLinkNode(parent) || $isLinkNode(node) || $isLinkHighlightNode(parent) || $isLinkHighlightNode(node));
140
- var isCodeBlock = $isCodeNode(element) && $isCodeNode(focusElement) && elementKey === focusElement.getKey();
141
+ // Support both CodeNode (from codeblock plugin) and CodeMirrorNode (from codemirror-block plugin)
142
+ var isLexicalCodeBlock = $isCodeNode(element) && $isCodeNode(focusElement) && elementKey === focusElement.getKey();
143
+ var isCodeMirrorBlock = $isCodeMirrorNode(element) && $isCodeMirrorNode(focusElement) && elementKey === focusElement.getKey();
144
+ var isCodeBlock = isLexicalCodeBlock || isCodeMirrorBlock;
141
145
  setIsInCodeblok(isCodeBlock);
142
- setCodeblockLang(isCodeBlock ? element.getLanguage() : '');
146
+ if (isLexicalCodeBlock) {
147
+ setCodeblockLang(element.getLanguage());
148
+ } else if (isCodeMirrorBlock) {
149
+ setCodeblockLang(element.lang);
150
+ } else {
151
+ setCodeblockLang('');
152
+ }
143
153
  var _isBlockquote = $isQuoteNode(element) && $isQuoteNode(focusElement) && elementKey === focusElement.getKey();
144
154
  setIsInBlockquote(_isBlockquote);
145
155
  if (elementDOM !== null) {
@@ -222,21 +232,46 @@ export function useEditorState(editor) {
222
232
  if (blockType !== 'code') {
223
233
  var _editor$getLexicalEdi2;
224
234
  editor === null || editor === void 0 || (_editor$getLexicalEdi2 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi2 === void 0 || _editor$getLexicalEdi2.update(function () {
235
+ var _lexicalEditor$_nodes;
225
236
  var selection = $getSelection();
226
237
  if (!selection) {
227
238
  return;
228
239
  }
229
- if (!$isRangeSelection(selection) || selection.isCollapsed()) {
230
- $setBlocksType(selection, function () {
231
- return $createCodeNode();
232
- });
240
+
241
+ // Try to use CodeMirrorNode if available, otherwise fall back to CodeNode
242
+ var lexicalEditor = editor === null || editor === void 0 ? void 0 : editor.getLexicalEditor();
243
+ var hasCodeMirrorNode = lexicalEditor ? lexicalEditor._nodes.has('code') && ((_lexicalEditor$_nodes = lexicalEditor._nodes.get('code')) === null || _lexicalEditor$_nodes === void 0 ? void 0 : _lexicalEditor$_nodes.klass.name) === 'CodeMirrorNode' : false;
244
+ if (hasCodeMirrorNode) {
245
+ // Use CodeMirrorNode
246
+ if (!$isRangeSelection(selection) || selection.isCollapsed()) {
247
+ var textContent = selection.getTextContent();
248
+ var codeMirrorNode = $createCodeMirrorNode('plain', textContent);
249
+ var nodeSelection = $createNodeSelection();
250
+ nodeSelection.add(codeMirrorNode.getKey());
251
+ selection.insertNodes([codeMirrorNode]);
252
+ $setSelection(nodeSelection);
253
+ } else {
254
+ var _textContent = selection.getTextContent();
255
+ var _codeMirrorNode = $createCodeMirrorNode('plain', _textContent);
256
+ selection.insertNodes([_codeMirrorNode]);
257
+ var _nodeSelection = $createNodeSelection();
258
+ _nodeSelection.add(_codeMirrorNode.getKey());
259
+ $setSelection(_nodeSelection);
260
+ }
233
261
  } else {
234
- var textContent = selection.getTextContent();
235
- var codeNode = $createCodeNode();
236
- selection.insertNodes([codeNode]);
237
- selection = $getSelection();
238
- if ($isRangeSelection(selection)) {
239
- selection.insertRawText(textContent);
262
+ // Use original CodeNode
263
+ if (!$isRangeSelection(selection) || selection.isCollapsed()) {
264
+ $setBlocksType(selection, function () {
265
+ return $createCodeNode();
266
+ });
267
+ } else {
268
+ var _textContent2 = selection.getTextContent();
269
+ var codeNode = $createCodeNode();
270
+ selection.insertNodes([codeNode]);
271
+ selection = $getSelection();
272
+ if ($isRangeSelection(selection)) {
273
+ selection.insertRawText(_textContent2);
274
+ }
240
275
  }
241
276
  }
242
277
  });
@@ -19,6 +19,10 @@ export type IServiceID<Service> = {
19
19
  __serviceType?: Service;
20
20
  };
21
21
  export interface IKernelEventMap {
22
+ /**
23
+ * Document change event
24
+ */
25
+ documentChange: (type: string, content: any) => void;
22
26
  /**
23
27
  * Editor editable state change event
24
28
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.3.1",
3
+ "version": "3.4.0",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -25,6 +25,7 @@
25
25
  "types": "es/index.d.ts",
26
26
  "files": [
27
27
  "es",
28
+ "scripts/patch-lexical.js",
28
29
  "react.d.ts",
29
30
  "react.js"
30
31
  ],
@@ -70,5 +71,10 @@
70
71
  "react": "^19.0.0",
71
72
  "react-dom": "^19.0.0"
72
73
  },
73
- "packageManager": "pnpm@10.20.0"
74
+ "packageManager": "pnpm@10.20.0",
75
+ "pnpm": {
76
+ "overrides": {
77
+ "chalk": "^4.1.2"
78
+ }
79
+ }
74
80
  }
@@ -0,0 +1,39 @@
1
+ /* eslint-disable unicorn/no-process-exit */
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+
5
+ const sourceDir = path.resolve(__dirname, '../src/editor-kernel/lexical');
6
+ const esSourceDir = path.resolve(__dirname, '../es/editor-kernel/lexical');
7
+ const targetDir = path.resolve(__dirname, '../node_modules/lexical');
8
+
9
+ if (!fs.existsSync(targetDir)) {
10
+ console.warn('node_modules/lexical not found, skipping patch.');
11
+ process.exit(0);
12
+ }
13
+
14
+ const realSourceDir = fs.existsSync(esSourceDir) ? esSourceDir : sourceDir;
15
+
16
+ if (!fs.existsSync(realSourceDir)) {
17
+ console.warn('No source directory found for lexical patch.');
18
+ process.exit(0);
19
+ }
20
+
21
+ function copyToLexical(dir, target) {
22
+ const files = fs.readdirSync(dir);
23
+
24
+ files.forEach((file) => {
25
+ const sourceFile = path.join(dir, file);
26
+ const targetFile = path.join(target, file);
27
+ if (fs.statSync(sourceFile).isDirectory()) {
28
+ copyToLexical(sourceFile, targetFile);
29
+ return;
30
+ }
31
+
32
+ if (fs.existsSync(sourceFile)) {
33
+ fs.copyFileSync(sourceFile, targetFile);
34
+ console.log(`Overwrote ${file} in node_modules/lexical/`);
35
+ }
36
+ });
37
+ }
38
+
39
+ copyToLexical(realSourceDir, targetDir);