@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.
package/dist/lex4-editor.js
CHANGED
|
@@ -5675,50 +5675,73 @@ const EditorWithHandle = forwardRef(({ captureHistoryShortcutsOnWindow, onSave,
|
|
|
5675
5675
|
} = useDocument();
|
|
5676
5676
|
const { handleFactories } = useExtensions();
|
|
5677
5677
|
const t = useTranslations();
|
|
5678
|
-
const
|
|
5679
|
-
const
|
|
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
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5705
|
+
const handleRef = useRef({});
|
|
5706
|
+
const extensionMethodKeysRef = useRef([]);
|
|
5707
|
+
const handle = handleRef.current;
|
|
5708
|
+
handle.setHistorySidebarOpen = (open) => {
|
|
5709
|
+
setHistorySidebarOpen(open);
|
|
5710
|
+
};
|
|
5711
|
+
handle.toggleHistorySidebar = () => {
|
|
5712
|
+
setHistorySidebarOpen(!historySidebarOpenRef.current);
|
|
5713
|
+
};
|
|
5714
|
+
handle.insertDocumentContent = (documentToInsert) => {
|
|
5715
|
+
const currentActiveEditor = activeEditorRef.current;
|
|
5716
|
+
if (!currentActiveEditor || activeCaretRegionRef.current !== "body") {
|
|
5717
|
+
return false;
|
|
5718
|
+
}
|
|
5719
|
+
let inserted = false;
|
|
5720
|
+
runHistoryActionRef.current(
|
|
5721
|
+
{
|
|
5722
|
+
label: insertedDocumentContentLabelRef.current,
|
|
5723
|
+
source: "toolbar",
|
|
5724
|
+
region: "document"
|
|
5688
5725
|
},
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
return false;
|
|
5692
|
-
}
|
|
5693
|
-
let inserted = false;
|
|
5694
|
-
runHistoryAction(
|
|
5695
|
-
{
|
|
5696
|
-
label: t.history.actions.insertedDocumentContent,
|
|
5697
|
-
source: "toolbar",
|
|
5698
|
-
region: "document"
|
|
5699
|
-
},
|
|
5700
|
-
() => {
|
|
5701
|
-
inserted = insertDocumentContent(activeEditor, documentToInsert);
|
|
5702
|
-
}
|
|
5703
|
-
);
|
|
5704
|
-
return inserted;
|
|
5726
|
+
() => {
|
|
5727
|
+
inserted = insertDocumentContent(currentActiveEditor, documentToInsert);
|
|
5705
5728
|
}
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5729
|
+
);
|
|
5730
|
+
return inserted;
|
|
5731
|
+
};
|
|
5732
|
+
for (const key of extensionMethodKeysRef.current) {
|
|
5733
|
+
delete handle[key];
|
|
5734
|
+
}
|
|
5735
|
+
const extensionMethodKeys = [];
|
|
5736
|
+
for (const factory of handleFactories) {
|
|
5737
|
+
const methods = factory(extensionCtx);
|
|
5738
|
+
for (const [key, method] of Object.entries(methods)) {
|
|
5739
|
+
handle[key] = method;
|
|
5740
|
+
extensionMethodKeys.push(key);
|
|
5710
5741
|
}
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
activeEditor,
|
|
5715
|
-
extensionCtx,
|
|
5716
|
-
handleFactories,
|
|
5717
|
-
historySidebarOpen,
|
|
5718
|
-
runHistoryAction,
|
|
5719
|
-
setHistorySidebarOpen,
|
|
5720
|
-
t.history.actions.insertedDocumentContent
|
|
5721
|
-
]);
|
|
5742
|
+
}
|
|
5743
|
+
extensionMethodKeysRef.current = extensionMethodKeys;
|
|
5744
|
+
useImperativeHandle(ref, () => handle, []);
|
|
5722
5745
|
return /* @__PURE__ */ jsx(
|
|
5723
5746
|
EditorChrome,
|
|
5724
5747
|
{
|