@mdxeditor/editor 2.3.6 → 2.3.8
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,5 +1,5 @@
|
|
|
1
1
|
import { factorySpace } from "micromark-factory-space";
|
|
2
|
-
import { markdownLineEnding } from "
|
|
2
|
+
import { markdownLineEnding } from "micromark-util-character";
|
|
3
3
|
import { codes, types } from "micromark-util-symbol";
|
|
4
4
|
function commentFromMarkdown(_options) {
|
|
5
5
|
return {
|
|
@@ -5,61 +5,73 @@ import { MergeView } from "@codemirror/merge";
|
|
|
5
5
|
import { EditorState } from "@codemirror/state";
|
|
6
6
|
import { EditorView } from "@codemirror/view";
|
|
7
7
|
import { COMMON_STATE_CONFIG_EXTENSIONS } from "./SourceEditor.js";
|
|
8
|
-
import { useCellValues, usePublisher, useCellValue } from "@mdxeditor/gurx";
|
|
8
|
+
import { useRealm, useCellValues, usePublisher, useCellValue } from "@mdxeditor/gurx";
|
|
9
|
+
function setContent(view, content) {
|
|
10
|
+
if (view !== void 0) {
|
|
11
|
+
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: content } });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
9
14
|
const DiffViewer = () => {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
|
|
15
|
+
const realm = useRealm();
|
|
16
|
+
const [newMarkdown, oldMarkdown] = useCellValues(markdown$, diffMarkdown$);
|
|
17
|
+
const onUpdate = usePublisher(markdownSourceEditorValue$);
|
|
18
|
+
const elRef = React__default.useRef(null);
|
|
15
19
|
const cmMergeViewRef = React__default.useRef(null);
|
|
16
20
|
const cmExtensions = useCellValue(cmExtensions$);
|
|
17
21
|
const triggerOnBlur = usePublisher(onBlur$);
|
|
18
|
-
|
|
19
|
-
(
|
|
22
|
+
React__default.useEffect(() => {
|
|
23
|
+
return realm.sub(diffMarkdown$, (newDiffMarkdown) => {
|
|
24
|
+
var _a;
|
|
25
|
+
setContent((_a = cmMergeViewRef.current) == null ? void 0 : _a.a, newDiffMarkdown);
|
|
26
|
+
});
|
|
27
|
+
}, [realm]);
|
|
28
|
+
React__default.useEffect(() => {
|
|
29
|
+
return realm.sub(markdown$, (newMarkdown2) => {
|
|
20
30
|
var _a;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(_a = cmMergeViewRef.current) == null ? void 0 : _a.destroy();
|
|
57
|
-
cmMergeViewRef.current = null;
|
|
31
|
+
setContent((_a = cmMergeViewRef.current) == null ? void 0 : _a.b, newMarkdown2);
|
|
32
|
+
});
|
|
33
|
+
}, [realm]);
|
|
34
|
+
React__default.useEffect(() => {
|
|
35
|
+
cmMergeViewRef.current = new MergeView({
|
|
36
|
+
renderRevertControl: () => {
|
|
37
|
+
const el = document.createElement("button");
|
|
38
|
+
el.classList.add("cm-merge-revert");
|
|
39
|
+
el.appendChild(document.createTextNode("⮕"));
|
|
40
|
+
return el;
|
|
41
|
+
},
|
|
42
|
+
parent: elRef.current,
|
|
43
|
+
orientation: "a-b",
|
|
44
|
+
revertControls: "a-to-b",
|
|
45
|
+
gutter: true,
|
|
46
|
+
a: {
|
|
47
|
+
doc: oldMarkdown,
|
|
48
|
+
extensions: [...cmExtensions, ...COMMON_STATE_CONFIG_EXTENSIONS, EditorState.readOnly.of(true)]
|
|
49
|
+
},
|
|
50
|
+
b: {
|
|
51
|
+
doc: newMarkdown,
|
|
52
|
+
extensions: [
|
|
53
|
+
...cmExtensions,
|
|
54
|
+
...COMMON_STATE_CONFIG_EXTENSIONS,
|
|
55
|
+
EditorView.updateListener.of(({ state }) => {
|
|
56
|
+
const md = state.doc.toString();
|
|
57
|
+
onUpdate(md);
|
|
58
|
+
}),
|
|
59
|
+
EditorView.focusChangeEffect.of((_, focused) => {
|
|
60
|
+
if (!focused) {
|
|
61
|
+
triggerOnBlur(new FocusEvent("blur"));
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
})
|
|
65
|
+
]
|
|
58
66
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
});
|
|
68
|
+
return () => {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = cmMergeViewRef.current) == null ? void 0 : _a.destroy();
|
|
71
|
+
cmMergeViewRef.current = null;
|
|
72
|
+
};
|
|
73
|
+
}, [onUpdate, cmExtensions]);
|
|
74
|
+
return /* @__PURE__ */ React__default.createElement("div", { ref: elRef });
|
|
63
75
|
};
|
|
64
76
|
export {
|
|
65
77
|
DiffViewer
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "2.3.
|
|
14
|
+
"version": "2.3.8",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"micromark-extension-mdx-md": "^2.0.0",
|
|
82
82
|
"micromark-extension-mdxjs": "^3.0.0",
|
|
83
83
|
"micromark-factory-space": "^2.0.0",
|
|
84
|
+
"micromark-util-character": "^2.0.1",
|
|
84
85
|
"micromark-util-symbol": "^2.0.0",
|
|
85
86
|
"react-hook-form": "^7.44.2",
|
|
86
87
|
"unidiff": "^1.0.2"
|