@mdxeditor/editor 2.10.0 → 2.11.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.
package/dist/index.d.ts
CHANGED
|
@@ -818,6 +818,11 @@ export declare const diffSourcePlugin: (params?: {
|
|
|
818
818
|
* Optional, additional CodeMirror extensions to load in the diff/source mode.
|
|
819
819
|
*/
|
|
820
820
|
codeMirrorExtensions?: Extension_2[] | undefined;
|
|
821
|
+
/**
|
|
822
|
+
* Set the diff editor to read-only.
|
|
823
|
+
* @default false
|
|
824
|
+
*/
|
|
825
|
+
readOnlyDiff?: boolean | undefined;
|
|
821
826
|
} | undefined) => RealmPlugin;
|
|
822
827
|
|
|
823
828
|
/**
|
|
@@ -2204,6 +2209,8 @@ export declare const quotePlugin: (params?: unknown) => RealmPlugin;
|
|
|
2204
2209
|
*/
|
|
2205
2210
|
export declare const readOnly$: NodeRef<boolean>;
|
|
2206
2211
|
|
|
2212
|
+
/* Excluded from this release type: readOnlyDiff$ */
|
|
2213
|
+
|
|
2207
2214
|
/**
|
|
2208
2215
|
* A plugin for the editor.
|
|
2209
2216
|
* @group Core
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import { ADMONITION_TYPES, AdmonitionDirectiveDescriptor } from "./directive-edi
|
|
|
24
24
|
import { GenericDirectiveEditor } from "./directive-editors/GenericDirectiveEditor.js";
|
|
25
25
|
import { applyLinkChanges$, cancelLinkEdit$, linkAutocompleteSuggestions$, linkDialogPlugin, linkDialogState$, onClickLinkCallback$, onWindowChange$, openLinkEditDialog$, removeLink$, switchFromPreviewToLinkEdit$, updateLink$ } from "./plugins/link-dialog/index.js";
|
|
26
26
|
import { toolbarContents$, toolbarPlugin } from "./plugins/toolbar/index.js";
|
|
27
|
-
import { cmExtensions$, diffMarkdown$, diffSourcePlugin } from "./plugins/diff-source/index.js";
|
|
27
|
+
import { cmExtensions$, diffMarkdown$, diffSourcePlugin, readOnlyDiff$ } from "./plugins/diff-source/index.js";
|
|
28
28
|
import { markdownShortcutPlugin } from "./plugins/markdown-shortcut/index.js";
|
|
29
29
|
import { BlockTypeSelect } from "./plugins/toolbar/components/BlockTypeSelect.js";
|
|
30
30
|
import { BoldItalicUnderlineToggles } from "./plugins/toolbar/components/BoldItalicUnderlineToggles.js";
|
|
@@ -260,6 +260,7 @@ export {
|
|
|
260
260
|
prop,
|
|
261
261
|
quotePlugin,
|
|
262
262
|
readOnly$,
|
|
263
|
+
readOnlyDiff$,
|
|
263
264
|
realmPlugin,
|
|
264
265
|
removeFrontmatter$,
|
|
265
266
|
removeLink$,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import { diffMarkdown$, cmExtensions$ } from "./index.js";
|
|
3
|
-
import { markdown$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
|
|
2
|
+
import { diffMarkdown$, readOnlyDiff$, cmExtensions$ } from "./index.js";
|
|
3
|
+
import { markdown$, readOnly$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
|
|
4
4
|
import { MergeView } from "@codemirror/merge";
|
|
5
5
|
import { EditorState } from "@codemirror/state";
|
|
6
6
|
import { EditorView } from "@codemirror/view";
|
|
@@ -13,7 +13,7 @@ function setContent(view, content) {
|
|
|
13
13
|
}
|
|
14
14
|
const DiffViewer = () => {
|
|
15
15
|
const realm = useRealm();
|
|
16
|
-
const [newMarkdown, oldMarkdown] = useCellValues(markdown$, diffMarkdown$);
|
|
16
|
+
const [newMarkdown, oldMarkdown, readOnly, readOnlyDiff] = useCellValues(markdown$, diffMarkdown$, readOnly$, readOnlyDiff$);
|
|
17
17
|
const onUpdate = usePublisher(markdownSourceEditorValue$);
|
|
18
18
|
const elRef = React__default.useRef(null);
|
|
19
19
|
const cmMergeViewRef = React__default.useRef(null);
|
|
@@ -32,16 +32,23 @@ const DiffViewer = () => {
|
|
|
32
32
|
});
|
|
33
33
|
}, [realm]);
|
|
34
34
|
React__default.useEffect(() => {
|
|
35
|
-
|
|
35
|
+
const isReadOnly = readOnly || readOnlyDiff;
|
|
36
|
+
const revertParams = isReadOnly ? {
|
|
37
|
+
renderRevertControl: void 0,
|
|
38
|
+
revertControls: void 0
|
|
39
|
+
} : {
|
|
36
40
|
renderRevertControl: () => {
|
|
37
41
|
const el = document.createElement("button");
|
|
38
42
|
el.classList.add("cm-merge-revert");
|
|
39
43
|
el.appendChild(document.createTextNode("⮕"));
|
|
40
44
|
return el;
|
|
41
45
|
},
|
|
46
|
+
revertControls: "a-to-b"
|
|
47
|
+
};
|
|
48
|
+
cmMergeViewRef.current = new MergeView({
|
|
49
|
+
...revertParams,
|
|
42
50
|
parent: elRef.current,
|
|
43
51
|
orientation: "a-b",
|
|
44
|
-
revertControls: "a-to-b",
|
|
45
52
|
gutter: true,
|
|
46
53
|
a: {
|
|
47
54
|
doc: oldMarkdown,
|
|
@@ -52,6 +59,7 @@ const DiffViewer = () => {
|
|
|
52
59
|
extensions: [
|
|
53
60
|
...cmExtensions,
|
|
54
61
|
...COMMON_STATE_CONFIG_EXTENSIONS,
|
|
62
|
+
EditorState.readOnly.of(isReadOnly),
|
|
55
63
|
EditorView.updateListener.of(({ state }) => {
|
|
56
64
|
const md = state.doc.toString();
|
|
57
65
|
onUpdate(md);
|
|
@@ -4,21 +4,24 @@ import { Cell } from "@mdxeditor/gurx";
|
|
|
4
4
|
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
5
5
|
const diffMarkdown$ = Cell("");
|
|
6
6
|
const cmExtensions$ = Cell([]);
|
|
7
|
+
const readOnlyDiff$ = Cell(false);
|
|
7
8
|
const diffSourcePlugin = realmPlugin({
|
|
8
9
|
update: (r, params) => {
|
|
9
|
-
r.pub(diffMarkdown$, (params == null ? void 0 : params.diffMarkdown)
|
|
10
|
+
r.pub(diffMarkdown$, (params == null ? void 0 : params.diffMarkdown) ?? "");
|
|
10
11
|
},
|
|
11
12
|
init(r, params) {
|
|
12
13
|
r.pubIn({
|
|
13
|
-
[diffMarkdown$]: (params == null ? void 0 : params.diffMarkdown)
|
|
14
|
-
[cmExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions)
|
|
14
|
+
[diffMarkdown$]: (params == null ? void 0 : params.diffMarkdown) ?? "",
|
|
15
|
+
[cmExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
|
|
15
16
|
[addEditorWrapper$]: DiffSourceWrapper,
|
|
16
|
-
[
|
|
17
|
+
[readOnlyDiff$]: (params == null ? void 0 : params.readOnlyDiff) ?? false,
|
|
18
|
+
[viewMode$]: (params == null ? void 0 : params.viewMode) ?? "rich-text"
|
|
17
19
|
});
|
|
18
20
|
}
|
|
19
21
|
});
|
|
20
22
|
export {
|
|
21
23
|
cmExtensions$,
|
|
22
24
|
diffMarkdown$,
|
|
23
|
-
diffSourcePlugin
|
|
25
|
+
diffSourcePlugin,
|
|
26
|
+
readOnlyDiff$
|
|
24
27
|
};
|