@yurikilian/lex4 1.5.3 → 1.5.4

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.
@@ -5675,8 +5675,32 @@ const EditorWithHandle = forwardRef(({ captureHistoryShortcutsOnWindow, onSave,
5675
5675
  } = useDocument();
5676
5676
  const { handleFactories } = useExtensions();
5677
5677
  const t = useTranslations();
5678
- const getDocument = useCallback(() => doc, [doc]);
5679
- const getActiveEditor = useCallback(() => activeEditor, [activeEditor]);
5678
+ const documentRef = useRef(doc);
5679
+ const activeEditorRef = useRef(activeEditor);
5680
+ const activeCaretRegionRef = useRef(activeCaretPosition == null ? void 0 : activeCaretPosition.region);
5681
+ const historySidebarOpenRef = useRef(historySidebarOpen);
5682
+ const runHistoryActionRef = useRef(runHistoryAction);
5683
+ const insertedDocumentContentLabelRef = useRef(t.history.actions.insertedDocumentContent);
5684
+ useEffect(() => {
5685
+ documentRef.current = doc;
5686
+ }, [doc]);
5687
+ useEffect(() => {
5688
+ activeEditorRef.current = activeEditor;
5689
+ }, [activeEditor]);
5690
+ useEffect(() => {
5691
+ activeCaretRegionRef.current = activeCaretPosition == null ? void 0 : activeCaretPosition.region;
5692
+ }, [activeCaretPosition == null ? void 0 : activeCaretPosition.region]);
5693
+ useEffect(() => {
5694
+ historySidebarOpenRef.current = historySidebarOpen;
5695
+ }, [historySidebarOpen]);
5696
+ useEffect(() => {
5697
+ runHistoryActionRef.current = runHistoryAction;
5698
+ }, [runHistoryAction]);
5699
+ useEffect(() => {
5700
+ insertedDocumentContentLabelRef.current = t.history.actions.insertedDocumentContent;
5701
+ }, [t.history.actions.insertedDocumentContent]);
5702
+ const getDocument = useCallback(() => documentRef.current, []);
5703
+ const getActiveEditor = useCallback(() => activeEditorRef.current, []);
5680
5704
  const extensionCtx = useExtensionContext(getDocument, getActiveEditor);
5681
5705
  useImperativeHandle(ref, () => {
5682
5706
  const handle = {
@@ -5684,21 +5708,22 @@ const EditorWithHandle = forwardRef(({ captureHistoryShortcutsOnWindow, onSave,
5684
5708
  setHistorySidebarOpen(open);
5685
5709
  },
5686
5710
  toggleHistorySidebar: () => {
5687
- setHistorySidebarOpen(!historySidebarOpen);
5711
+ setHistorySidebarOpen(!historySidebarOpenRef.current);
5688
5712
  },
5689
5713
  insertDocumentContent: (documentToInsert) => {
5690
- if (!activeEditor || (activeCaretPosition == null ? void 0 : activeCaretPosition.region) !== "body") {
5714
+ const currentActiveEditor = activeEditorRef.current;
5715
+ if (!currentActiveEditor || activeCaretRegionRef.current !== "body") {
5691
5716
  return false;
5692
5717
  }
5693
5718
  let inserted = false;
5694
- runHistoryAction(
5719
+ runHistoryActionRef.current(
5695
5720
  {
5696
- label: t.history.actions.insertedDocumentContent,
5721
+ label: insertedDocumentContentLabelRef.current,
5697
5722
  source: "toolbar",
5698
5723
  region: "document"
5699
5724
  },
5700
5725
  () => {
5701
- inserted = insertDocumentContent(activeEditor, documentToInsert);
5726
+ inserted = insertDocumentContent(currentActiveEditor, documentToInsert);
5702
5727
  }
5703
5728
  );
5704
5729
  return inserted;
@@ -5709,16 +5734,7 @@ const EditorWithHandle = forwardRef(({ captureHistoryShortcutsOnWindow, onSave,
5709
5734
  Object.assign(handle, methods);
5710
5735
  }
5711
5736
  return handle;
5712
- }, [
5713
- activeCaretPosition == null ? void 0 : activeCaretPosition.region,
5714
- activeEditor,
5715
- extensionCtx,
5716
- handleFactories,
5717
- historySidebarOpen,
5718
- runHistoryAction,
5719
- setHistorySidebarOpen,
5720
- t.history.actions.insertedDocumentContent
5721
- ]);
5737
+ }, [extensionCtx, handleFactories, setHistorySidebarOpen]);
5722
5738
  return /* @__PURE__ */ jsx(
5723
5739
  EditorChrome,
5724
5740
  {