@mdxeditor/editor 3.44.3 → 3.45.1
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/index.d.ts
CHANGED
|
@@ -2308,9 +2308,9 @@ export declare interface MDXEditorProps {
|
|
|
2308
2308
|
*/
|
|
2309
2309
|
suppressSharedHistory?: boolean;
|
|
2310
2310
|
/**
|
|
2311
|
-
* The initial state of the lexical editor.
|
|
2311
|
+
* The initial state of the lexical editor. Pass null to disable any initiation.
|
|
2312
2312
|
*/
|
|
2313
|
-
editorState?: EditorState | undefined;
|
|
2313
|
+
editorState?: EditorState | undefined | null;
|
|
2314
2314
|
}
|
|
2315
2315
|
|
|
2316
2316
|
/**
|
|
@@ -9,6 +9,7 @@ import { lineNumbers, keymap, EditorView } from "@codemirror/view";
|
|
|
9
9
|
import { indentWithTab } from "@codemirror/commands";
|
|
10
10
|
import { basicLight } from "cm6-theme-basic-light";
|
|
11
11
|
import { basicSetup } from "codemirror";
|
|
12
|
+
import { $setSelection } from "lexical";
|
|
12
13
|
import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$ } from "./index.js";
|
|
13
14
|
import { useCodeMirrorRef } from "../sandpack/useCodeMirrorRef.js";
|
|
14
15
|
import { Select } from "../toolbar/primitives/select.js";
|
|
@@ -45,6 +46,13 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
45
46
|
EditorView.lineWrapping,
|
|
46
47
|
EditorView.updateListener.of(({ state }) => {
|
|
47
48
|
setCodeRef.current(state.doc.toString());
|
|
49
|
+
}),
|
|
50
|
+
EditorView.domEventHandlers({
|
|
51
|
+
focus: () => {
|
|
52
|
+
parentEditor.update(() => {
|
|
53
|
+
$setSelection(null);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
48
56
|
})
|
|
49
57
|
];
|
|
50
58
|
if (readOnly) {
|
|
@@ -543,7 +543,7 @@ const corePlugin = realmPlugin({
|
|
|
543
543
|
},
|
|
544
544
|
postInit(r, params) {
|
|
545
545
|
const newEditor = createEditor({
|
|
546
|
-
...(params
|
|
546
|
+
// ...(params?.editorState ? { editorState: params.editorState } : {}),
|
|
547
547
|
editable: (params == null ? void 0 : params.readOnly) !== true,
|
|
548
548
|
namespace: "MDXEditor",
|
|
549
549
|
nodes: r.getValue(usedLexicalNodes$),
|
|
@@ -552,24 +552,26 @@ const corePlugin = realmPlugin({
|
|
|
552
552
|
},
|
|
553
553
|
theme: r.getValue(lexicalTheme$)
|
|
554
554
|
});
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
if (autoFocusValue
|
|
555
|
+
if ((params == null ? void 0 : params.editorState) !== null) {
|
|
556
|
+
newEditor.update(() => {
|
|
557
|
+
const markdown = (params == null ? void 0 : params.initialMarkdown.trim()) ?? "";
|
|
558
|
+
tryImportingMarkdown(r, $getRoot(), markdown);
|
|
559
|
+
const autoFocusValue = params == null ? void 0 : params.autoFocus;
|
|
560
|
+
if (autoFocusValue) {
|
|
561
|
+
if (autoFocusValue === true) {
|
|
562
|
+
setTimeout(() => {
|
|
563
|
+
newEditor.focus(noop, { defaultSelection: "rootStart" });
|
|
564
|
+
});
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
561
567
|
setTimeout(() => {
|
|
562
|
-
newEditor.focus(noop, {
|
|
568
|
+
newEditor.focus(noop, {
|
|
569
|
+
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
570
|
+
});
|
|
563
571
|
});
|
|
564
|
-
return;
|
|
565
572
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
569
|
-
});
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
+
});
|
|
574
|
+
}
|
|
573
575
|
r.pub(rootEditor$, newEditor);
|
|
574
576
|
r.pub(activeEditor$, newEditor);
|
|
575
577
|
},
|