@haklex/rich-plugin-block-handle 0.59.1 → 0.60.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.
@@ -1 +1 @@
1
- {"version":3,"file":"blockSelectionUtils.d.ts","sourceRoot":"","sources":["../src/blockSelectionUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAUL,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AA+BjB,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,EAC3C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,IAAI,CAIN;AAED,wBAAgB,wCAAwC,CACtD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,YAAY,CAad;AAED,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAkCpF;AAED,wBAAgB,wCAAwC,CACtD,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,OAAO,CAqBT;AAiBD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,WAAW,EAAE,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxB;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAkC1F;AAED,wBAAgB,uCAAuC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAW3F;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CASjF;AAED,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,CAI9E;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,CAE/E;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASpE;AA8BD,wBAAgB,wCAAwC,CACtD,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,YAAY,GACzB,OAAO,CA2CT;AAED,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,YAAY,GACzB,OAAO,CAKT"}
1
+ {"version":3,"file":"blockSelectionUtils.d.ts","sourceRoot":"","sources":["../src/blockSelectionUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAaL,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAyDjB,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,EAC3C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,IAAI,CAIN;AAED,wBAAgB,wCAAwC,CACtD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,YAAY,CAad;AAED,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAkCpF;AAED,wBAAgB,wCAAwC,CACtD,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,OAAO,CAqBT;AAiBD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,WAAW,EAAE,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxB;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAkC1F;AAED,wBAAgB,uCAAuC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAW3F;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CASjF;AAED,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,CAI9E;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,CAE/E;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASpE;AA8BD,wBAAgB,wCAAwC,CACtD,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,YAAY,GACzB,OAAO,CA2CT;AAED,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,YAAY,GACzB,OAAO,CAKT"}
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuTrigger, detectPlatform } from "@haklex/rich-editor-ui";
2
2
  import { usePortalTheme } from "@haklex/rich-style-token";
3
3
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
- import { $createNodeSelection, $createParagraphNode, $createTabNode, $createTextNode, $getNearestNodeFromDOMNode, $getNodeByKey, $getRoot, $getSelection, $isElementNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isTextNode, $parseSerializedNode, $setSelection, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, PASTE_COMMAND, PASTE_TAG, REMOVE_TEXT_COMMAND, SELECT_ALL_COMMAND } from "lexical";
4
+ import { $createNodeSelection, $createParagraphNode, $createTabNode, $createTextNode, $getNearestNodeFromDOMNode, $getNodeByKey, $getRoot, $getSelection, $isElementNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isTextNode, $parseSerializedNode, $setSelection, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, COPY_COMMAND, CUT_COMMAND, DELETE_CHARACTER_COMMAND, DRAGOVER_COMMAND, DRAGSTART_COMMAND, DROP_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, PASTE_COMMAND, PASTE_TAG, REMOVE_TEXT_COMMAND, SELECT_ALL_COMMAND, createEditor } from "lexical";
5
5
  import { ArrowDown, ArrowUp, Copy, GripVertical, Plus, Trash2 } from "lucide-react";
6
6
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
7
  import { createPortal } from "react-dom";
@@ -11,7 +11,8 @@ import { $createCodeNode } from "@lexical/code-core";
11
11
  import { $isListNode, INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from "@lexical/list";
12
12
  import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode } from "@lexical/rich-text";
13
13
  import { $setBlocksType } from "@lexical/selection";
14
- import { $generateNodesFromDOM } from "@lexical/html";
14
+ import { useEditorBlock } from "@haklex/rich-editor";
15
+ import { $generateHtmlFromNodes, $generateNodesFromDOM } from "@lexical/html";
15
16
  //#region src/BlockMenu.tsx
16
17
  var TURN_INTO_ITEMS = TURN_INTO_COMMAND_IDS.map((id) => getCommandMeta(id));
17
18
  function BlockMenu({ currentType, onDelete, onDuplicate, onMoveDown, onMoveUp, onTurnInto }) {
@@ -260,8 +261,22 @@ function serializeNodeWithChildren(node) {
260
261
  if ($isElementNode(node)) serialized.children = node.getChildren().map(serializeNodeWithChildren);
261
262
  return serialized;
262
263
  }
263
- function getHtmlFromTopLevelNodes(editor, nodes) {
264
- return nodes.map((node) => editor.getElementByKey(node.getKey())?.outerHTML ?? "").filter(Boolean).join("\n");
264
+ function getHtmlFromTopLevelNodes(editor, nodes, serializedNodes) {
265
+ const html = nodes.map((node) => editor.getElementByKey(node.getKey())?.outerHTML ?? "").filter(Boolean).join("\n");
266
+ if (html || nodes.length === 0) return html;
267
+ if (nodes.length === $getRoot().getChildrenSize()) return $generateHtmlFromNodes(editor, null);
268
+ const source = editor;
269
+ const detached = createEditor({
270
+ html: source._config.html,
271
+ namespace: source._config.namespace,
272
+ nodes: [...source._nodes.values()].map(({ klass }) => klass),
273
+ onError: (error) => {
274
+ throw error;
275
+ },
276
+ theme: source._config.theme
277
+ });
278
+ detached.update(() => $getRoot().append(...serializedNodes.map($parseSerializedNode)), { discrete: true });
279
+ return detached.getEditorState().read(() => $generateHtmlFromNodes(detached, null));
265
280
  }
266
281
  function setBlockClipboardDataTransfer(dataTransfer, clipboardData) {
267
282
  for (const [mimeType, value] of Object.entries(clipboardData)) dataTransfer.setData(mimeType, value);
@@ -329,7 +344,7 @@ function selectTopLevelNode(node, placement) {
329
344
  function buildBlockClipboardData(editor, nodes) {
330
345
  const namespace = editor._config.namespace;
331
346
  const serializedNodes = nodes.map(serializeNodeWithChildren);
332
- const html = getHtmlFromTopLevelNodes(editor, nodes);
347
+ const html = getHtmlFromTopLevelNodes(editor, nodes, serializedNodes);
333
348
  return {
334
349
  "application/x-lexical-editor": JSON.stringify({
335
350
  namespace,
@@ -473,11 +488,25 @@ function useBlockSelection(editor) {
473
488
  const focusKeyRef = useRef(null);
474
489
  const blockSelectionKeysRef = useRef(/* @__PURE__ */ new Set());
475
490
  const latestBlockClipboardDataRef = useRef(null);
491
+ const documentBlocks = useEditorBlock()?.documentBlocks;
476
492
  const clearBlockSelectionState = useCallback(() => {
477
493
  blockSelectionKeysRef.current = /* @__PURE__ */ new Set();
478
494
  anchorKeyRef.current = null;
479
495
  focusKeyRef.current = null;
480
- }, []);
496
+ documentBlocks?.clear();
497
+ }, [documentBlocks]);
498
+ const isDocumentSelection = useCallback(() => (documentBlocks?.keys().length ?? 0) > 0, [documentBlocks]);
499
+ const $getDocumentNodes = useCallback(() => (documentBlocks?.keys() ?? []).flatMap((key) => $getNodeByKey(key) ?? []), [documentBlocks]);
500
+ const deleteDocumentBlocks = useCallback(() => {
501
+ if (!documentBlocks) return;
502
+ documentBlocks.editor.update(() => removeTopLevelNodesAndRestoreSelection($getDocumentNodes()), { discrete: true });
503
+ clearBlockSelectionState();
504
+ documentBlocks.focusSelection();
505
+ }, [
506
+ $getDocumentNodes,
507
+ clearBlockSelectionState,
508
+ documentBlocks
509
+ ]);
481
510
  const getTopLevelNodesByKeys = useCallback((keys) => {
482
511
  if (keys.size === 0) return [];
483
512
  return $getRoot().getChildren().filter((node) => keys.has(node.getKey()));
@@ -499,6 +528,20 @@ function useBlockSelection(editor) {
499
528
  const replaceBlockSelectionWithDataTransfer = useCallback((dataTransfer) => {
500
529
  if (!hasInsertableClipboardData(dataTransfer)) return false;
501
530
  let handled = false;
531
+ if (documentBlocks && isDocumentSelection()) {
532
+ const master = documentBlocks.editor;
533
+ master.update(() => {
534
+ handled = replaceTopLevelNodesWithDataTransfer(master, $getDocumentNodes(), dataTransfer);
535
+ }, {
536
+ discrete: true,
537
+ tag: PASTE_TAG
538
+ });
539
+ if (handled) {
540
+ clearBlockSelectionState();
541
+ documentBlocks.focusSelection();
542
+ }
543
+ return handled;
544
+ }
502
545
  editor.update(() => {
503
546
  const nodes = getOwnedSelectionNodes();
504
547
  if (nodes.length === 0) return;
@@ -510,19 +553,32 @@ function useBlockSelection(editor) {
510
553
  });
511
554
  return handled;
512
555
  }, [
556
+ $getDocumentNodes,
513
557
  clearBlockSelectionState,
558
+ documentBlocks,
514
559
  editor,
515
- getOwnedSelectionNodes
560
+ getOwnedSelectionNodes,
561
+ isDocumentSelection
516
562
  ]);
517
563
  const getCurrentBlockClipboardData = useCallback(() => {
518
564
  let clipboardData = null;
565
+ if (documentBlocks && isDocumentSelection()) {
566
+ const master = documentBlocks.editor;
567
+ return master.getEditorState().read(() => buildBlockClipboardData(master, $getDocumentNodes()));
568
+ }
519
569
  editor.getEditorState().read(() => {
520
570
  const nodes = getOwnedSelectionNodes();
521
571
  if (nodes.length === 0) return;
522
572
  clipboardData = buildBlockClipboardData(editor, nodes);
523
573
  });
524
574
  return clipboardData;
525
- }, [editor, getOwnedSelectionNodes]);
575
+ }, [
576
+ $getDocumentNodes,
577
+ documentBlocks,
578
+ editor,
579
+ getOwnedSelectionNodes,
580
+ isDocumentSelection
581
+ ]);
526
582
  const deleteBlocksByKeys = useCallback((keys) => {
527
583
  editor.update(() => {
528
584
  const nodes = getTopLevelNodesByKeys(new Set(keys));
@@ -537,6 +593,16 @@ function useBlockSelection(editor) {
537
593
  ]);
538
594
  useEffect(() => {
539
595
  let prevKeys = /* @__PURE__ */ new Set();
596
+ const paint = (topLevelKeys) => {
597
+ const topLevelKeySet = new Set(topLevelKeys);
598
+ const highlightKeys = new Set([...blockSelectionKeysRef.current, ...documentBlocks?.islandKeys(editor) ?? []].filter((key) => topLevelKeySet.has(key)));
599
+ for (const key of prevKeys) if (!highlightKeys.has(key)) editor.getElementByKey(key)?.classList.remove(blockSelected);
600
+ for (const key of highlightKeys) if (!prevKeys.has(key)) editor.getElementByKey(key)?.classList.add(blockSelected);
601
+ prevKeys = highlightKeys;
602
+ };
603
+ const repaint = () => paint(editor.getEditorState().read($getTopLevelKeys));
604
+ const unsubscribe = documentBlocks?.subscribe(repaint);
605
+ repaint();
540
606
  const unregister = editor.registerUpdateListener(({ editorState }) => {
541
607
  if (!editor.getRootElement()) return;
542
608
  const nextKeys = /* @__PURE__ */ new Set();
@@ -574,17 +640,18 @@ function useBlockSelection(editor) {
574
640
  }
575
641
  }
576
642
  }
577
- const topLevelKeySet = new Set(topLevelKeys);
578
- const highlightKeys = blockSelectionKeysRef.current.size > 0 ? new Set([...blockSelectionKeysRef.current].filter((key) => topLevelKeySet.has(key))) : /* @__PURE__ */ new Set();
579
- for (const key of prevKeys) if (!highlightKeys.has(key)) editor.getElementByKey(key)?.classList.remove(blockSelected);
580
- for (const key of highlightKeys) if (!prevKeys.has(key)) editor.getElementByKey(key)?.classList.add(blockSelected);
581
- prevKeys = highlightKeys;
643
+ paint(topLevelKeys);
582
644
  });
583
645
  return () => {
646
+ unsubscribe?.();
584
647
  unregister();
585
648
  for (const key of prevKeys) editor.getElementByKey(key)?.classList.remove(blockSelected);
586
649
  };
587
- }, [clearBlockSelectionState, editor]);
650
+ }, [
651
+ clearBlockSelectionState,
652
+ documentBlocks,
653
+ editor
654
+ ]);
588
655
  useEffect(() => {
589
656
  const rootEl = editor.getRootElement();
590
657
  if (!rootEl) return;
@@ -659,7 +726,14 @@ function useBlockSelection(editor) {
659
726
  if (!$isNodeSelection(sel)) return false;
660
727
  const children = $getRoot().getChildren();
661
728
  const focusIdx = children.findIndex((c) => c.getKey() === focusKeyRef.current);
662
- if (focusIdx === -1 || focusIdx >= children.length - 1) return false;
729
+ if (focusIdx === -1) return false;
730
+ if (documentBlocks && (isDocumentSelection() || focusIdx >= children.length - 1)) {
731
+ event.preventDefault();
732
+ if (!isDocumentSelection()) documentBlocks.select(editor, anchorKeyRef.current, focusKeyRef.current);
733
+ documentBlocks.extend(1);
734
+ return true;
735
+ }
736
+ if (focusIdx >= children.length - 1) return false;
663
737
  event.preventDefault();
664
738
  focusKeyRef.current = children[focusIdx + 1].getKey();
665
739
  $selectBlockRange(anchorKeyRef.current, focusKeyRef.current);
@@ -675,7 +749,14 @@ function useBlockSelection(editor) {
675
749
  if (!$isNodeSelection(sel)) return false;
676
750
  const children = $getRoot().getChildren();
677
751
  const focusIdx = children.findIndex((c) => c.getKey() === focusKeyRef.current);
678
- if (focusIdx === -1 || focusIdx <= 0) return false;
752
+ if (focusIdx === -1) return false;
753
+ if (documentBlocks && (isDocumentSelection() || focusIdx <= 0)) {
754
+ event.preventDefault();
755
+ if (!isDocumentSelection()) documentBlocks.select(editor, anchorKeyRef.current, focusKeyRef.current);
756
+ documentBlocks.extend(-1);
757
+ return true;
758
+ }
759
+ if (focusIdx <= 0) return false;
679
760
  event.preventDefault();
680
761
  focusKeyRef.current = children[focusIdx - 1].getKey();
681
762
  $selectBlockRange(anchorKeyRef.current, focusKeyRef.current);
@@ -688,7 +769,10 @@ function useBlockSelection(editor) {
688
769
  const unregSelectAll = editor.registerCommand(SELECT_ALL_COMMAND, () => {
689
770
  if (blockSelectionKeysRef.current.size > 0) {
690
771
  const allKeys = $getRoot().getChildren().map((c) => c.getKey());
691
- if (blockSelectionKeysRef.current.size >= allKeys.length) return true;
772
+ if (blockSelectionKeysRef.current.size >= allKeys.length) {
773
+ documentBlocks?.selectAll();
774
+ return true;
775
+ }
692
776
  anchorKeyRef.current = allKeys[0];
693
777
  focusKeyRef.current = allKeys.at(-1);
694
778
  blockSelectionKeysRef.current = new Set(allKeys);
@@ -759,15 +843,16 @@ function useBlockSelection(editor) {
759
843
  }, COMMAND_PRIORITY_CRITICAL);
760
844
  const unregCut = editor.registerCommand(CUT_COMMAND, (event) => {
761
845
  const clipboardEvent = event && typeof event === "object" && "clipboardData" in event ? event : null;
846
+ const inDocument = isDocumentSelection();
762
847
  let keysToDelete = [];
763
- let clipboardData = null;
764
- editor.getEditorState().read(() => {
848
+ let clipboardData = inDocument ? getCurrentBlockClipboardData() : null;
849
+ if (!inDocument) editor.getEditorState().read(() => {
765
850
  const nodes = getOwnedSelectionNodes();
766
851
  if (nodes.length === 0) return;
767
852
  clipboardData = buildBlockClipboardData(editor, nodes);
768
853
  keysToDelete = nodes.map((node) => node.getKey());
769
854
  });
770
- if (keysToDelete.length === 0 || !clipboardData) return false;
855
+ if (!inDocument && keysToDelete.length === 0 || !clipboardData) return false;
771
856
  latestBlockClipboardDataRef.current = clipboardData;
772
857
  if (clipboardEvent?.clipboardData) {
773
858
  clipboardEvent.preventDefault();
@@ -776,7 +861,8 @@ function useBlockSelection(editor) {
776
861
  if (event && typeof event === "object" && "preventDefault" in event && typeof event.preventDefault === "function") event.preventDefault();
777
862
  writeBlockClipboardDataToNativeClipboard(editor, clipboardData);
778
863
  }
779
- deleteBlocksByKeys(keysToDelete);
864
+ if (inDocument) deleteDocumentBlocks();
865
+ else deleteBlocksByKeys(keysToDelete);
780
866
  return true;
781
867
  }, COMMAND_PRIORITY_CRITICAL);
782
868
  const unregPaste = editor.registerCommand(PASTE_COMMAND, (event) => {
@@ -784,6 +870,11 @@ function useBlockSelection(editor) {
784
870
  if (!clipboardData) return false;
785
871
  const dataTransferOnly = isDataTransferOnlyPasteEvent(event);
786
872
  if (!(dataTransferOnly ? hasInsertableClipboardData(clipboardData) : hasPasteableClipboardData(clipboardData))) return false;
873
+ if (isDocumentSelection()) {
874
+ if (!replaceBlockSelectionWithDataTransfer(clipboardData)) return false;
875
+ if (event && typeof event === "object" && "preventDefault" in event && typeof event.preventDefault === "function") event.preventDefault();
876
+ return true;
877
+ }
787
878
  const nodes = getOwnedSelectionNodes();
788
879
  if (nodes.length === 0) return false;
789
880
  removeTopLevelNodesAndCreatePasteTarget(nodes);
@@ -795,6 +886,11 @@ function useBlockSelection(editor) {
795
886
  return false;
796
887
  }, COMMAND_PRIORITY_CRITICAL);
797
888
  const handleDeleteBlocks = (payload) => {
889
+ if (isDocumentSelection()) {
890
+ if (payload && typeof payload !== "boolean" && "preventDefault" in payload && typeof payload.preventDefault === "function") payload.preventDefault();
891
+ deleteDocumentBlocks();
892
+ return true;
893
+ }
798
894
  let keysToDelete = [];
799
895
  editor.getEditorState().read(() => {
800
896
  keysToDelete = getOwnedSelectionNodes().map((node) => node.getKey());
@@ -825,12 +921,16 @@ function useBlockSelection(editor) {
825
921
  }, [
826
922
  clearBlockSelectionState,
827
923
  deleteBlocksByKeys,
924
+ deleteDocumentBlocks,
925
+ documentBlocks,
828
926
  editor,
829
927
  getCurrentBlockClipboardData,
830
928
  getOwnedSelectionNodes,
929
+ isDocumentSelection,
831
930
  replaceBlockSelectionWithDataTransfer
832
931
  ]);
833
932
  const selectBlock = useCallback((nodeKey, shiftKey) => {
933
+ documentBlocks?.clear();
834
934
  editor.update(() => {
835
935
  if (shiftKey && anchorKeyRef.current) {
836
936
  focusKeyRef.current = nodeKey;
@@ -852,7 +952,7 @@ function useBlockSelection(editor) {
852
952
  $setSelection(sel);
853
953
  }
854
954
  });
855
- }, [editor]);
955
+ }, [documentBlocks, editor]);
856
956
  const getSelectedKeys = useCallback(() => {
857
957
  if (blockSelectionKeysRef.current.size === 0) return [];
858
958
  let keys = [];
@@ -1 +1 @@
1
- {"version":3,"file":"useBlockSelection.d.ts","sourceRoot":"","sources":["../src/useBlockSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAqBL,KAAK,aAAa,EAOnB,MAAM,SAAS,CAAC;AAkFjB,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa;2BAuoBzC,MAAM,YAAY,OAAO;2BA6BG,MAAM,EAAE;kCAwB1C,OAAO;6CAZQ,MAAM,GAAG,IAAI;EAiBnC"}
1
+ {"version":3,"file":"useBlockSelection.d.ts","sourceRoot":"","sources":["../src/useBlockSelection.ts"],"names":[],"mappings":"AACA,OAAO,EAsBL,KAAK,aAAa,EAOnB,MAAM,SAAS,CAAC;AAkFjB,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa;2BA4vBzC,MAAM,YAAY,OAAO;2BA8BG,MAAM,EAAE;kCAwB1C,OAAO;6CAZQ,MAAM,GAAG,IAAI;EAiBnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-plugin-block-handle",
3
- "version": "0.59.1",
3
+ "version": "0.60.0",
4
4
  "description": "Block handle plugin with add button and context menu",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,9 +42,9 @@
42
42
  "vite": "^8.3.4"
43
43
  },
44
44
  "peerDependencies": {
45
- "@haklex/rich-editor": "^0.59.1",
46
- "@haklex/rich-editor-ui": "^0.59.1",
47
- "@haklex/rich-style-token": "^0.59.1",
45
+ "@haklex/rich-editor": "^0.60.0",
46
+ "@haklex/rich-editor-ui": "^0.60.0",
47
+ "@haklex/rich-style-token": "^0.60.0",
48
48
  "@lexical/html": "^0.52.0",
49
49
  "@lexical/list": "^0.52.0",
50
50
  "@lexical/react": "^0.52.0",