@lobehub/editor 1.20.3 → 1.21.1

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.
@@ -1,8 +1,7 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
2
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
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
- import { $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
5
- import { $createCursorNode } from "../../common/node/cursor";
4
+ import { $createTextNode, $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
6
5
  import { $createLinkHighlightNode, $isLinkHighlightNode, getLinkHighlightNode } from "../node/link-highlight";
7
6
  export var INSERT_LINK_HIGHLIGHT_COMMAND = createCommand('INSERT_LINK_HIGHLIGHT_COMMAND');
8
7
  export function registerLinkHighlightCommand(editor) {
@@ -37,8 +36,11 @@ export function registerLinkHighlightCommand(editor) {
37
36
  }
38
37
 
39
38
  // Create link highlight with selected text
40
- var linkHighlightNode = $createLinkHighlightNode(selection.getTextContent());
41
- $insertNodes([linkHighlightNode, $createCursorNode()]);
39
+ var selectedText = selection.getTextContent();
40
+ var linkHighlightNode = $createLinkHighlightNode();
41
+ var textNode = $createTextNode(selectedText);
42
+ linkHighlightNode.append(textNode);
43
+ $insertNodes([linkHighlightNode]);
42
44
  linkHighlightNode.select();
43
45
  });
44
46
  return true;
@@ -1,29 +1,25 @@
1
- import { EditorConfig, LexicalEditor, LexicalNode, SerializedElementNode } from 'lexical';
2
- import { CardLikeElementNode } from "../../common/node/cursor";
1
+ import { EditorConfig, ElementNode, LexicalEditor, LexicalNode, SerializedElementNode } from 'lexical';
3
2
  export type SerializedLinkHighlightNode = SerializedElementNode;
4
- export declare class LinkHighlightNode extends CardLikeElementNode {
3
+ export declare class LinkHighlightNode extends ElementNode {
5
4
  static getType(): string;
6
5
  static clone(node: LinkHighlightNode): LinkHighlightNode;
7
6
  static importJSON(serializedNode: SerializedLinkHighlightNode): LinkHighlightNode;
8
- createDOM(config: EditorConfig, editor: LexicalEditor): HTMLElement;
7
+ createDOM(config: EditorConfig): HTMLElement;
9
8
  /**
10
9
  * Format URL to ensure it has proper protocol
11
10
  */
12
11
  private formatUrl;
13
- getDOMSlot(element: HTMLElement): import("lexical").ElementDOMSlot<HTMLElement>;
14
- canBeEmpty(): boolean;
15
- isCardLike(): boolean;
16
- isInline(): boolean;
17
- canIndent(): boolean;
18
- canInsertTextBefore(): boolean;
19
- canInsertTextAfter(): boolean;
12
+ canBeEmpty(): false;
13
+ isInline(): true;
14
+ canInsertTextBefore(): false;
15
+ canInsertTextAfter(): false;
20
16
  updateDOM(prevNode: LinkHighlightNode, dom: HTMLElement, config: EditorConfig): boolean;
21
17
  /**
22
18
  * Get the URL from the text content
23
19
  */
24
20
  getURL(): string;
25
21
  }
26
- export declare function $createLinkHighlightNode(textContent?: string): LinkHighlightNode;
22
+ export declare function $createLinkHighlightNode(): LinkHighlightNode;
27
23
  export declare function $isLinkHighlightNode(node: unknown): node is LinkHighlightNode;
28
- export declare function getLinkHighlightNode(node: LexicalNode): LexicalNode | null;
24
+ export declare function getLinkHighlightNode(node: LexicalNode): LinkHighlightNode | null;
29
25
  export declare function $isSelectionInLinkHighlight(editor: LexicalEditor): boolean;
@@ -4,8 +4,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
4
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
7
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
8
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
9
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -15,10 +13,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
15
13
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
14
  /* eslint-disable @typescript-eslint/no-use-before-define */
17
15
  import { addClassNamesToElement } from '@lexical/utils';
18
- import { $applyNodeReplacement, $createTextNode, $getSelection, $isNodeSelection, $isRangeSelection } from 'lexical';
19
- import { $createCursorNode, $isCursorNode, CardLikeElementNode } from "../../common/node/cursor";
20
- export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
21
- _inherits(LinkHighlightNode, _CardLikeElementNode);
16
+ import { $applyNodeReplacement, $getSelection, $isNodeSelection, $isRangeSelection, ElementNode } from 'lexical';
17
+ export var LinkHighlightNode = /*#__PURE__*/function (_ElementNode) {
18
+ _inherits(LinkHighlightNode, _ElementNode);
22
19
  var _super = _createSuper(LinkHighlightNode);
23
20
  function LinkHighlightNode() {
24
21
  _classCallCheck(this, LinkHighlightNode);
@@ -26,33 +23,17 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
26
23
  }
27
24
  _createClass(LinkHighlightNode, [{
28
25
  key: "createDOM",
29
- value: function createDOM(config, editor) {
30
- var _this = this;
31
- var element = document.createElement('span');
32
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
33
- element.setAttribute('data-lexical-key', this.getKey());
34
- var childContainer = document.createElement('ne-content');
35
- element.append(childContainer);
36
- addClassNamesToElement(element, config.theme.linkHighlight);
37
-
38
- // Add click handler to open link in new window
39
- element.addEventListener('click', function (event) {
40
- // Only handle left click without modifier keys
41
- if (event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey) {
42
- event.preventDefault();
43
- event.stopPropagation();
26
+ value: function createDOM(config) {
27
+ var element = document.createElement('a');
44
28
 
45
- // Read URL in editor context
46
- editor.read(function () {
47
- var url = _this.getURL();
48
- if (url) {
49
- // Format URL to ensure it has proper protocol
50
- var formattedUrl = _this.formatUrl(url);
51
- window.open(formattedUrl, '_blank', 'noopener,noreferrer');
52
- }
53
- });
54
- }
55
- });
29
+ // Set link attributes
30
+ var url = this.getURL();
31
+ if (url) {
32
+ element.href = this.formatUrl(url);
33
+ }
34
+ element.setAttribute('target', '_blank');
35
+ element.setAttribute('rel', 'noopener noreferrer');
36
+ addClassNamesToElement(element, config.theme.linkHighlight);
56
37
  return element;
57
38
  }
58
39
 
@@ -88,44 +69,25 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
88
69
  }
89
70
  return url;
90
71
  }
91
- }, {
92
- key: "getDOMSlot",
93
- value: function getDOMSlot(element) {
94
- var neContent = element.querySelector('ne-content');
95
- if (!neContent) {
96
- throw new Error('LinkHighlightNode: ne-content not found');
97
- }
98
- return _get(_getPrototypeOf(LinkHighlightNode.prototype), "getDOMSlot", this).call(this, element).withElement(neContent);
99
- }
100
72
  }, {
101
73
  key: "canBeEmpty",
102
74
  value: function canBeEmpty() {
103
75
  return false;
104
76
  }
105
- }, {
106
- key: "isCardLike",
107
- value: function isCardLike() {
108
- return true;
109
- }
110
77
  }, {
111
78
  key: "isInline",
112
79
  value: function isInline() {
113
80
  return true;
114
81
  }
115
- }, {
116
- key: "canIndent",
117
- value: function canIndent() {
118
- return false;
119
- }
120
82
  }, {
121
83
  key: "canInsertTextBefore",
122
84
  value: function canInsertTextBefore() {
123
- return true;
85
+ return false;
124
86
  }
125
87
  }, {
126
88
  key: "canInsertTextAfter",
127
89
  value: function canInsertTextAfter() {
128
- return true;
90
+ return false;
129
91
  }
130
92
  }, {
131
93
  key: "updateDOM",
@@ -135,6 +97,16 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
135
97
  if (prevTheme !== this) {
136
98
  addClassNamesToElement(dom, config.theme.linkHighlight);
137
99
  }
100
+
101
+ // Update href attribute if it's an anchor element
102
+ if (dom instanceof HTMLAnchorElement) {
103
+ var url = this.getURL();
104
+ if (url) {
105
+ dom.href = this.formatUrl(url);
106
+ } else {
107
+ dom.removeAttribute('href');
108
+ }
109
+ }
138
110
  return false;
139
111
  }
140
112
 
@@ -163,35 +135,20 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
163
135
  }
164
136
  }]);
165
137
  return LinkHighlightNode;
166
- }(CardLikeElementNode);
167
- export function $createLinkHighlightNode(textContent) {
168
- var linkHighlightNode = $applyNodeReplacement(new LinkHighlightNode());
169
- var cursorNode = $createCursorNode();
170
- linkHighlightNode.append(cursorNode);
171
- if (textContent) {
172
- linkHighlightNode.append($createTextNode(textContent));
173
- }
174
- return linkHighlightNode;
138
+ }(ElementNode);
139
+ export function $createLinkHighlightNode() {
140
+ return $applyNodeReplacement(new LinkHighlightNode());
175
141
  }
176
142
  export function $isLinkHighlightNode(node) {
177
143
  return node instanceof LinkHighlightNode;
178
144
  }
179
145
  export function getLinkHighlightNode(node) {
180
- if ($isCursorNode(node)) {
181
- var parent = node.getParent();
182
- if ($isLinkHighlightNode(parent)) {
183
- return parent;
184
- }
185
- if ($isLinkHighlightNode(node.getNextSibling())) {
186
- return node.getNextSibling();
187
- }
188
- if ($isLinkHighlightNode(node.getPreviousSibling())) {
189
- return node.getPreviousSibling();
190
- }
191
- return null;
146
+ if ($isLinkHighlightNode(node)) {
147
+ return node;
192
148
  }
193
- if ($isLinkHighlightNode(node.getParent())) {
194
- return node.getParent();
149
+ var parent = node.getParent();
150
+ if ($isLinkHighlightNode(parent)) {
151
+ return parent;
195
152
  }
196
153
  return null;
197
154
  }
@@ -204,19 +161,15 @@ export function $isSelectionInLinkHighlight(editor) {
204
161
  if ($isRangeSelection(selection)) {
205
162
  var focusNode = selection.focus.getNode();
206
163
  var anchorNode = selection.anchor.getNode();
207
- var linkHighlight = getLinkHighlightNode(focusNode);
208
- if (linkHighlight !== getLinkHighlightNode(anchorNode)) {
209
- return false;
210
- }
211
- if ($isLinkHighlightNode(linkHighlight)) {
212
- return true;
213
- }
214
- return false;
215
- } else if ($isNodeSelection(selection)) {
164
+ var focusLinkHighlight = getLinkHighlightNode(focusNode);
165
+ var anchorLinkHighlight = getLinkHighlightNode(anchorNode);
166
+
167
+ // Both nodes should be in the same link-highlight node
168
+ return focusLinkHighlight !== null && anchorLinkHighlight !== null && focusLinkHighlight === anchorLinkHighlight;
169
+ }
170
+ if ($isNodeSelection(selection)) {
216
171
  var nodes = selection.getNodes();
217
- if (nodes.length === 1 && $isLinkHighlightNode(nodes[0])) {
218
- return true;
219
- }
172
+ return nodes.length === 1 && $isLinkHighlightNode(nodes[0]);
220
173
  }
221
174
  return false;
222
175
  });
@@ -19,10 +19,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
19
19
  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; }
20
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
21
  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); }
22
- import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
22
+ import { $createTextNode, $getSelection, $isRangeSelection, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
23
23
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
24
24
  import { KernelPlugin } from "../../../editor-kernel/plugin";
25
- import { $createCursorNode, cursorNodeSerialized } from "../../common/node/cursor";
26
25
  import { IMarkdownShortCutService, MARKDOWN_READER_LEVEL_HIGH } from "../../markdown/service/shortcut";
27
26
  import { createDebugLogger } from "../../../utils/debug";
28
27
  import { registerLinkHighlightCommand } from "../command";
@@ -77,9 +76,10 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
77
76
  editor.update(function () {
78
77
  var selection = $getSelection();
79
78
  if ($isRangeSelection(selection)) {
80
- var linkHighlightNode = $createLinkHighlightNode(data);
81
- var cursorNode = $createCursorNode();
82
- selection.insertNodes([linkHighlightNode, cursorNode]);
79
+ var linkHighlightNode = $createLinkHighlightNode();
80
+ var textNode = $createTextNode(data);
81
+ linkHighlightNode.append(textNode);
82
+ selection.insertNodes([linkHighlightNode]);
83
83
  }
84
84
  });
85
85
  return true;
@@ -95,7 +95,7 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
95
95
 
96
96
  // Register markdown writer for <link> format
97
97
  markdownService.registerMarkdownWriter(LinkHighlightNode.getType(), function (ctx, node) {
98
- ctx.appendLine("<".concat(node.getTextContent(), ">"));
98
+ ctx.appendLine(node.getTextContent());
99
99
  return true;
100
100
  });
101
101
 
@@ -110,10 +110,10 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
110
110
  return;
111
111
  }
112
112
  _this2.logger.debug('Converting markdown auto-link to LinkHighlightNode:', url);
113
- var linkHighlightNode = $createLinkHighlightNode(url);
114
- var cursorNode = $createCursorNode();
113
+ var linkHighlightNode = $createLinkHighlightNode();
114
+ var textNodeContent = $createTextNode(url);
115
+ linkHighlightNode.append(textNodeContent);
115
116
  textNode.replace(linkHighlightNode);
116
- linkHighlightNode.insertAfter(cursorNode);
117
117
  return undefined;
118
118
  },
119
119
  trigger: '>',
@@ -129,14 +129,14 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
129
129
  if (match) {
130
130
  var url = match[1].replaceAll(/[\u200B-\u200D\u2060\uFEFF]/g, '');
131
131
  _this2.logger.debug('Converting HTML auto-link to LinkHighlightNode:', url);
132
- return [INodeHelper.createElementNode('linkHighlight', {
133
- children: [cursorNodeSerialized, INodeHelper.createTextNode(url, {})],
132
+ return INodeHelper.createElementNode('linkHighlight', {
133
+ children: [INodeHelper.createTextNode(url, {})],
134
134
  direction: 'ltr',
135
135
  format: '',
136
136
  indent: 0,
137
137
  type: 'linkHighlight',
138
138
  version: 1
139
- }), cursorNodeSerialized];
139
+ });
140
140
  }
141
141
 
142
142
  // Not an auto-link, let other handlers process it
@@ -164,16 +164,14 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
164
164
  // If text matches URL exactly (auto-link syntax), convert to LinkHighlightNode
165
165
  if (textContent === url) {
166
166
  _this2.logger.debug('Converting markdown auto-link to LinkHighlightNode:', url);
167
- // Return array with LinkHighlightNode and trailing cursor
168
- // Structure matches CodeNode: [node with internal cursor + text, external cursor]
169
- return [INodeHelper.createElementNode('linkHighlight', {
170
- children: [cursorNodeSerialized, INodeHelper.createTextNode(url, {})],
167
+ return INodeHelper.createElementNode('linkHighlight', {
168
+ children: [INodeHelper.createTextNode(url, {})],
171
169
  direction: 'ltr',
172
170
  format: '',
173
171
  indent: 0,
174
172
  type: 'linkHighlight',
175
173
  version: 1
176
- }), cursorNodeSerialized];
174
+ });
177
175
  }
178
176
 
179
177
  // Otherwise, let standard Link plugin handle it
@@ -2,9 +2,8 @@ var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
- var css = _ref.css,
6
- token = _ref.token;
5
+ var css = _ref.css;
7
6
  return {
8
- linkHighlight: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: inline;\n\n padding: 2px;\n\n color: ", ";\n text-decoration: none;\n\n transition: all 0.2s ease;\n\n &:hover {\n color: ", ";\n text-decoration: underline;\n }\n\n ne-content {\n display: inline;\n }\n "])), token.colorLink, token.colorLinkHover)
7
+ linkHighlight: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: unset;\n\n margin-block: 1em;\n margin-inline: 0;\n padding: 2px;\n border: none;\n "])))
9
8
  };
10
9
  });
@@ -164,6 +164,13 @@ function convertMdastToLexical(node, index, ctx) {
164
164
  ret.push(convertMdastToLexical(child, index, ctx, markdownReaders));
165
165
  return ret;
166
166
  }, []).filter(Boolean).flat();
167
+ while (htmlStack.length > 0) {
168
+ var _children3;
169
+ var tag = htmlStack.shift();
170
+ ctx.pop();
171
+ // @ts-expect-error not error
172
+ (_children3 = _children).push.apply(_children3, [INodeHelper.createTextNode(tag === null || tag === void 0 ? void 0 : tag.node.value)].concat(_toConsumableArray(tag.children)));
173
+ }
167
174
  }
168
175
  if (markdownReaders[node.type]) {
169
176
  var reader = markdownReaders[node.type];
@@ -10,6 +10,7 @@ import { $createQuoteNode, $isHeadingNode, $isQuoteNode } from '@lexical/rich-te
10
10
  import { $setBlocksType } from '@lexical/selection';
11
11
  import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
12
12
  import { $createNodeSelection, $getSelection, $isParagraphNode, $isRangeSelection, $setSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
13
+ import { debounce } from 'lodash-es';
13
14
  import { useCallback, useEffect, useMemo, useState } from 'react';
14
15
  import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
15
16
  import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
@@ -369,14 +370,22 @@ export function useEditorState(editor) {
369
370
  if (!editor) return;
370
371
  var lexicalEditor = editor.getLexicalEditor();
371
372
  var cleanup = function cleanup() {};
373
+ var debounceUpdate = debounce(function () {
374
+ lexicalEditor === null || lexicalEditor === void 0 || lexicalEditor.read(function () {
375
+ $updateToolbar();
376
+ });
377
+ }, 500);
372
378
  var handleLexicalEditor = function handleLexicalEditor(lexicalEditor) {
373
- cleanup = mergeRegister(lexicalEditor.registerUpdateListener(function (_ref) {
379
+ cleanup = mergeRegister(lexicalEditor.registerUpdateListener(debounce(function (_ref) {
374
380
  var editorState = _ref.editorState;
375
381
  editorState.read(function () {
376
382
  $updateToolbar();
377
383
  });
378
- }), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
379
- $updateToolbar();
384
+ }, 500)), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
385
+ if (lexicalEditor.isComposing()) {
386
+ return false;
387
+ }
388
+ debounceUpdate();
380
389
  return false;
381
390
  }, COMMAND_PRIORITY_LOW), lexicalEditor.registerCommand(CAN_UNDO_COMMAND, function (payload) {
382
391
  setCanUndo(payload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.20.3",
3
+ "version": "1.21.1",
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",