@yurikilian/lex4 1.5.3 → 1.5.5

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":"Lex4Editor.d.ts","sourceRoot":"","sources":["../../src/components/Lex4Editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0E,MAAM,OAAO,CAAC;AAC/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkB/D,OAAO,eAAe,CAAC;AAsUvB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,0FA+BrB,CAAC"}
1
+ {"version":3,"file":"Lex4Editor.d.ts","sourceRoot":"","sources":["../../src/components/Lex4Editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0E,MAAM,OAAO,CAAC;AAC/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkB/D,OAAO,eAAe,CAAC;AAoWvB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,0FA+BrB,CAAC"}
@@ -5677,50 +5677,73 @@ const EditorWithHandle = React.forwardRef(({ captureHistoryShortcutsOnWindow, on
5677
5677
  } = useDocument();
5678
5678
  const { handleFactories } = useExtensions();
5679
5679
  const t = useTranslations();
5680
- const getDocument = React.useCallback(() => doc, [doc]);
5681
- const getActiveEditor = React.useCallback(() => activeEditor, [activeEditor]);
5680
+ const documentRef = React.useRef(doc);
5681
+ const activeEditorRef = React.useRef(activeEditor);
5682
+ const activeCaretRegionRef = React.useRef(activeCaretPosition == null ? void 0 : activeCaretPosition.region);
5683
+ const historySidebarOpenRef = React.useRef(historySidebarOpen);
5684
+ const runHistoryActionRef = React.useRef(runHistoryAction);
5685
+ const insertedDocumentContentLabelRef = React.useRef(t.history.actions.insertedDocumentContent);
5686
+ React.useEffect(() => {
5687
+ documentRef.current = doc;
5688
+ }, [doc]);
5689
+ React.useEffect(() => {
5690
+ activeEditorRef.current = activeEditor;
5691
+ }, [activeEditor]);
5692
+ React.useEffect(() => {
5693
+ activeCaretRegionRef.current = activeCaretPosition == null ? void 0 : activeCaretPosition.region;
5694
+ }, [activeCaretPosition == null ? void 0 : activeCaretPosition.region]);
5695
+ React.useEffect(() => {
5696
+ historySidebarOpenRef.current = historySidebarOpen;
5697
+ }, [historySidebarOpen]);
5698
+ React.useEffect(() => {
5699
+ runHistoryActionRef.current = runHistoryAction;
5700
+ }, [runHistoryAction]);
5701
+ React.useEffect(() => {
5702
+ insertedDocumentContentLabelRef.current = t.history.actions.insertedDocumentContent;
5703
+ }, [t.history.actions.insertedDocumentContent]);
5704
+ const getDocument = React.useCallback(() => documentRef.current, []);
5705
+ const getActiveEditor = React.useCallback(() => activeEditorRef.current, []);
5682
5706
  const extensionCtx = useExtensionContext(getDocument, getActiveEditor);
5683
- React.useImperativeHandle(ref, () => {
5684
- const handle = {
5685
- setHistorySidebarOpen: (open) => {
5686
- setHistorySidebarOpen(open);
5687
- },
5688
- toggleHistorySidebar: () => {
5689
- setHistorySidebarOpen(!historySidebarOpen);
5707
+ const handleRef = React.useRef({});
5708
+ const extensionMethodKeysRef = React.useRef([]);
5709
+ const handle = handleRef.current;
5710
+ handle.setHistorySidebarOpen = (open) => {
5711
+ setHistorySidebarOpen(open);
5712
+ };
5713
+ handle.toggleHistorySidebar = () => {
5714
+ setHistorySidebarOpen(!historySidebarOpenRef.current);
5715
+ };
5716
+ handle.insertDocumentContent = (documentToInsert) => {
5717
+ const currentActiveEditor = activeEditorRef.current;
5718
+ if (!currentActiveEditor || activeCaretRegionRef.current !== "body") {
5719
+ return false;
5720
+ }
5721
+ let inserted = false;
5722
+ runHistoryActionRef.current(
5723
+ {
5724
+ label: insertedDocumentContentLabelRef.current,
5725
+ source: "toolbar",
5726
+ region: "document"
5690
5727
  },
5691
- insertDocumentContent: (documentToInsert) => {
5692
- if (!activeEditor || (activeCaretPosition == null ? void 0 : activeCaretPosition.region) !== "body") {
5693
- return false;
5694
- }
5695
- let inserted = false;
5696
- runHistoryAction(
5697
- {
5698
- label: t.history.actions.insertedDocumentContent,
5699
- source: "toolbar",
5700
- region: "document"
5701
- },
5702
- () => {
5703
- inserted = insertDocumentContent(activeEditor, documentToInsert);
5704
- }
5705
- );
5706
- return inserted;
5728
+ () => {
5729
+ inserted = insertDocumentContent(currentActiveEditor, documentToInsert);
5707
5730
  }
5708
- };
5709
- for (const factory of handleFactories) {
5710
- const methods = factory(extensionCtx);
5711
- Object.assign(handle, methods);
5731
+ );
5732
+ return inserted;
5733
+ };
5734
+ for (const key of extensionMethodKeysRef.current) {
5735
+ delete handle[key];
5736
+ }
5737
+ const extensionMethodKeys = [];
5738
+ for (const factory of handleFactories) {
5739
+ const methods = factory(extensionCtx);
5740
+ for (const [key, method] of Object.entries(methods)) {
5741
+ handle[key] = method;
5742
+ extensionMethodKeys.push(key);
5712
5743
  }
5713
- return handle;
5714
- }, [
5715
- activeCaretPosition == null ? void 0 : activeCaretPosition.region,
5716
- activeEditor,
5717
- extensionCtx,
5718
- handleFactories,
5719
- historySidebarOpen,
5720
- runHistoryAction,
5721
- setHistorySidebarOpen,
5722
- t.history.actions.insertedDocumentContent
5723
- ]);
5744
+ }
5745
+ extensionMethodKeysRef.current = extensionMethodKeys;
5746
+ React.useImperativeHandle(ref, () => handle, []);
5724
5747
  return /* @__PURE__ */ jsxRuntime.jsx(
5725
5748
  EditorChrome,
5726
5749
  {