@mdxeditor/editor 3.32.3 → 3.34.0
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
|
|
@@ -10,14 +10,27 @@ import styles from "../../styles/ui.module.css.js";
|
|
|
10
10
|
import { readOnly$ } from "../core/index.js";
|
|
11
11
|
import { $isImageNode } from "./ImageNode.js";
|
|
12
12
|
import ImageResizer from "./ImageResizer.js";
|
|
13
|
+
const BROKEN_IMG_URI = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(
|
|
14
|
+
/* xml */
|
|
15
|
+
`
|
|
16
|
+
<svg id="imgLoadError" xmlns="http://www.w3.org/2000/svg" width="100" height="100">
|
|
17
|
+
<rect x="0" y="0" width="100" height="100" fill="none" stroke="red" stroke-width="4" stroke-dasharray="4" />
|
|
18
|
+
<text x="50" y="55" text-anchor="middle" font-size="20" fill="red">⚠️</text>
|
|
19
|
+
</svg>
|
|
20
|
+
`
|
|
21
|
+
);
|
|
13
22
|
const imgCache = {
|
|
14
23
|
__cache: {},
|
|
15
24
|
read(src) {
|
|
16
25
|
if (!this.__cache[src]) {
|
|
17
26
|
this.__cache[src] = new Promise((resolve) => {
|
|
18
27
|
const img = new Image();
|
|
28
|
+
img.onerror = () => {
|
|
29
|
+
this.__cache[src] = BROKEN_IMG_URI;
|
|
30
|
+
resolve();
|
|
31
|
+
};
|
|
19
32
|
img.onload = () => {
|
|
20
|
-
this.__cache[src] =
|
|
33
|
+
this.__cache[src] = src;
|
|
21
34
|
resolve();
|
|
22
35
|
};
|
|
23
36
|
img.src = src;
|
|
@@ -38,13 +51,12 @@ function LazyImage({
|
|
|
38
51
|
width,
|
|
39
52
|
height
|
|
40
53
|
}) {
|
|
41
|
-
void imgCache.read(src);
|
|
42
54
|
return /* @__PURE__ */ React__default.createElement(
|
|
43
55
|
"img",
|
|
44
56
|
{
|
|
45
57
|
className: className ?? void 0,
|
|
46
58
|
alt,
|
|
47
|
-
src,
|
|
59
|
+
src: imgCache.read(src),
|
|
48
60
|
title,
|
|
49
61
|
ref: imageRef,
|
|
50
62
|
draggable: "false",
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "3.
|
|
14
|
+
"version": "3.34.0",
|
|
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",
|