@lobehub/editor 4.27.2 → 4.27.3
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.
|
@@ -63,7 +63,7 @@ function useEditorState(editor) {
|
|
|
63
63
|
setIsStrikethrough(selection.hasFormat("strikethrough"));
|
|
64
64
|
setIsSubscript(selection.hasFormat("subscript"));
|
|
65
65
|
setIsSuperscript(selection.hasFormat("superscript"));
|
|
66
|
-
setIsCode($isSelectionInCodeInline(lexicalEditor));
|
|
66
|
+
setIsCode(!!lexicalEditor && $isSelectionInCodeInline(lexicalEditor));
|
|
67
67
|
const anchorNode = selection.anchor.getNode();
|
|
68
68
|
const focusNode = selection.focus.getNode();
|
|
69
69
|
const element = $findTopLevelElement(anchorNode);
|
|
@@ -274,12 +274,17 @@ function useEditorState(editor) {
|
|
|
274
274
|
$updateToolbar();
|
|
275
275
|
});
|
|
276
276
|
}, 500);
|
|
277
|
+
const debounceUpdateListener = debounce(({ editorState }) => {
|
|
278
|
+
editorState.read(() => {
|
|
279
|
+
$updateToolbar();
|
|
280
|
+
});
|
|
281
|
+
}, 500);
|
|
282
|
+
const cancelPending = () => {
|
|
283
|
+
debounceUpdate.cancel();
|
|
284
|
+
debounceUpdateListener.cancel();
|
|
285
|
+
};
|
|
277
286
|
const handleLexicalEditor = (lexicalEditor) => {
|
|
278
|
-
cleanup = mergeRegister(lexicalEditor.registerUpdateListener(
|
|
279
|
-
editorState.read(() => {
|
|
280
|
-
$updateToolbar();
|
|
281
|
-
});
|
|
282
|
-
}, 500)), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
287
|
+
cleanup = mergeRegister(lexicalEditor.registerUpdateListener(debounceUpdateListener), lexicalEditor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
283
288
|
if (lexicalEditor.isComposing()) return false;
|
|
284
289
|
debounceUpdate();
|
|
285
290
|
return false;
|
|
@@ -295,11 +300,16 @@ function useEditorState(editor) {
|
|
|
295
300
|
if (!lexicalEditor) {
|
|
296
301
|
editor.on("initialized", handleLexicalEditor);
|
|
297
302
|
return () => {
|
|
303
|
+
cancelPending();
|
|
298
304
|
cleanup();
|
|
299
305
|
editor.off("initialized", handleLexicalEditor);
|
|
300
306
|
};
|
|
301
307
|
}
|
|
302
|
-
|
|
308
|
+
handleLexicalEditor(lexicalEditor);
|
|
309
|
+
return () => {
|
|
310
|
+
cancelPending();
|
|
311
|
+
cleanup();
|
|
312
|
+
};
|
|
303
313
|
}, [editor, $updateToolbar]);
|
|
304
314
|
return useMemo(() => ({
|
|
305
315
|
blockType,
|
package/package.json
CHANGED