@mdxeditor/editor 3.33.0 → 3.34.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.
|
@@ -5,7 +5,8 @@ import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
|
|
|
5
5
|
import { useTranslation, readOnly$, iconComponentFor$ } from "../core/index.js";
|
|
6
6
|
import { languages } from "@codemirror/language-data";
|
|
7
7
|
import { EditorState } from "@codemirror/state";
|
|
8
|
-
import { lineNumbers, EditorView } from "@codemirror/view";
|
|
8
|
+
import { lineNumbers, keymap, EditorView } from "@codemirror/view";
|
|
9
|
+
import { indentWithTab } from "@codemirror/commands";
|
|
9
10
|
import { basicLight } from "cm6-theme-basic-light";
|
|
10
11
|
import { basicSetup } from "codemirror";
|
|
11
12
|
import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$ } from "./index.js";
|
|
@@ -33,12 +34,14 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
33
34
|
getCodemirror: () => editorViewRef.current
|
|
34
35
|
};
|
|
35
36
|
React__default.useEffect(() => {
|
|
37
|
+
const el = elRef.current;
|
|
36
38
|
void (async () => {
|
|
37
39
|
const extensions = [
|
|
38
40
|
...codeMirrorExtensions,
|
|
39
41
|
basicSetup,
|
|
40
42
|
basicLight,
|
|
41
43
|
lineNumbers(),
|
|
44
|
+
keymap.of([indentWithTab]),
|
|
42
45
|
EditorView.lineWrapping,
|
|
43
46
|
EditorView.updateListener.of(({ state }) => {
|
|
44
47
|
setCodeRef.current(state.doc.toString());
|
|
@@ -60,64 +63,59 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
el.innerHTML = "";
|
|
64
67
|
editorViewRef.current = new EditorView({
|
|
65
|
-
parent:
|
|
68
|
+
parent: el,
|
|
66
69
|
state: EditorState.create({ doc: code, extensions })
|
|
67
70
|
});
|
|
71
|
+
el.addEventListener("keydown", stopPropagationHandler);
|
|
68
72
|
})();
|
|
69
73
|
return () => {
|
|
70
74
|
var _a;
|
|
71
75
|
(_a = editorViewRef.current) == null ? void 0 : _a.destroy();
|
|
72
76
|
editorViewRef.current = null;
|
|
77
|
+
el.removeEventListener("keydown", stopPropagationHandler);
|
|
73
78
|
};
|
|
74
79
|
}, [readOnly, language]);
|
|
75
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
76
|
-
|
|
80
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.codeMirrorWrapper }, /* @__PURE__ */ React__default.createElement("div", { className: styles.codeMirrorToolbar }, /* @__PURE__ */ React__default.createElement(
|
|
81
|
+
Select,
|
|
77
82
|
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
disabled: readOnly,
|
|
87
|
-
value: language,
|
|
88
|
-
onChange: (language2) => {
|
|
89
|
-
parentEditor.update(() => {
|
|
90
|
-
lexicalNode.setLanguage(language2 === EMPTY_VALUE ? "" : language2);
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
parentEditor.update(() => {
|
|
93
|
-
lexicalNode.getLatest().select();
|
|
94
|
-
});
|
|
83
|
+
disabled: readOnly,
|
|
84
|
+
value: language,
|
|
85
|
+
onChange: (language2) => {
|
|
86
|
+
parentEditor.update(() => {
|
|
87
|
+
lexicalNode.setLanguage(language2 === EMPTY_VALUE ? "" : language2);
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
parentEditor.update(() => {
|
|
90
|
+
lexicalNode.getLatest().select();
|
|
95
91
|
});
|
|
96
92
|
});
|
|
97
|
-
}
|
|
98
|
-
triggerTitle: t("codeBlock.selectLanguage", "Select code block language"),
|
|
99
|
-
placeholder: t("codeBlock.inlineLanguage", "Language"),
|
|
100
|
-
items: Object.entries(codeBlockLanguages).map(([value, label]) => ({ value: value ? value : EMPTY_VALUE, label }))
|
|
101
|
-
}
|
|
102
|
-
), /* @__PURE__ */ React__default.createElement(
|
|
103
|
-
"button",
|
|
104
|
-
{
|
|
105
|
-
className: styles.iconButton,
|
|
106
|
-
type: "button",
|
|
107
|
-
disabled: readOnly,
|
|
108
|
-
title: t("codeblock.delete", "Delete code block"),
|
|
109
|
-
onClick: (e) => {
|
|
110
|
-
e.preventDefault();
|
|
111
|
-
parentEditor.update(() => {
|
|
112
|
-
lexicalNode.remove();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
93
|
+
});
|
|
115
94
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
95
|
+
triggerTitle: t("codeBlock.selectLanguage", "Select code block language"),
|
|
96
|
+
placeholder: t("codeBlock.inlineLanguage", "Language"),
|
|
97
|
+
items: Object.entries(codeBlockLanguages).map(([value, label]) => ({ value: value ? value : EMPTY_VALUE, label }))
|
|
98
|
+
}
|
|
99
|
+
), /* @__PURE__ */ React__default.createElement(
|
|
100
|
+
"button",
|
|
101
|
+
{
|
|
102
|
+
className: styles.iconButton,
|
|
103
|
+
type: "button",
|
|
104
|
+
disabled: readOnly,
|
|
105
|
+
title: t("codeblock.delete", "Delete code block"),
|
|
106
|
+
onClick: (e) => {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
parentEditor.update(() => {
|
|
109
|
+
lexicalNode.remove();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
iconComponentFor("delete_small")
|
|
114
|
+
)), /* @__PURE__ */ React__default.createElement("div", { ref: elRef }));
|
|
120
115
|
};
|
|
116
|
+
function stopPropagationHandler(ev) {
|
|
117
|
+
ev.stopPropagation();
|
|
118
|
+
}
|
|
121
119
|
export {
|
|
122
120
|
COMMON_STATE_CONFIG_EXTENSIONS,
|
|
123
121
|
CodeMirrorEditor
|
|
@@ -50,7 +50,7 @@ const SelectButtonTrigger = ({
|
|
|
50
50
|
return /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, /* @__PURE__ */ React__default.createElement(RadixSelect.Trigger, { className: classNames(styles.toolbarButtonSelectTrigger, className), disabled: readOnly }, children, /* @__PURE__ */ React__default.createElement(RadixSelect.Icon, { className: styles.selectDropdownArrow }, iconComponentFor("arrow_drop_down"))));
|
|
51
51
|
};
|
|
52
52
|
const Select = (props) => {
|
|
53
|
-
return /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: props.value ||
|
|
53
|
+
return /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: props.value || "", onValueChange: props.onChange, disabled: props.disabled }, /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: props.triggerTitle, placeholder: props.placeholder }), /* @__PURE__ */ React__default.createElement(SelectContent, null, props.items.map((item, index) => {
|
|
54
54
|
if (item === "separator") {
|
|
55
55
|
return /* @__PURE__ */ React__default.createElement(RadixSelect.Separator, { key: index });
|
|
56
56
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "3.
|
|
14
|
+
"version": "3.34.1",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@codemirror/commands": "^6.2.4",
|
|
40
41
|
"@codemirror/lang-markdown": "^6.2.3",
|
|
41
42
|
"@codemirror/language-data": "^6.5.1",
|
|
42
43
|
"@codemirror/merge": "^6.4.0",
|