@mdxeditor/editor 2.3.9 → 2.5.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/MDXEditor.js +3 -3
- package/dist/index.d.ts +33 -1
- package/dist/index.js +4 -2
- package/dist/plugins/codeblock/CodeBlockNode.js +4 -1
- package/dist/plugins/codeblock/index.js +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +2 -2
- package/dist/plugins/link-dialog/LinkDialog.js +10 -3
- package/dist/plugins/link-dialog/index.js +3 -0
- package/package.json +1 -1
package/dist/MDXEditor.js
CHANGED
|
@@ -37,7 +37,7 @@ const RichTextEditor = () => {
|
|
|
37
37
|
editorWrappers$,
|
|
38
38
|
placeholder$
|
|
39
39
|
);
|
|
40
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, topAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), /* @__PURE__ */ React__default.createElement(
|
|
40
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, topAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), /* @__PURE__ */ React__default.createElement(RenderRecursiveWrappers, { wrappers: editorWrappers }, /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.rootContentEditableWrapper) }, /* @__PURE__ */ React__default.createElement(
|
|
41
41
|
RichTextPlugin,
|
|
42
42
|
{
|
|
43
43
|
contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { className: classNames(styles.contentEditable, contentEditableClassName) }),
|
|
@@ -56,7 +56,7 @@ const IconFallback = () => {
|
|
|
56
56
|
const defaultIconComponentFor = (name) => {
|
|
57
57
|
return /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: /* @__PURE__ */ React__default.createElement(IconFallback, null) }, /* @__PURE__ */ React__default.createElement(DefaultIcon, { name }));
|
|
58
58
|
};
|
|
59
|
-
const
|
|
59
|
+
const RenderRecursiveWrappers = ({
|
|
60
60
|
wrappers,
|
|
61
61
|
children
|
|
62
62
|
}) => {
|
|
@@ -64,7 +64,7 @@ const RenderRecurisveWrappers = ({
|
|
|
64
64
|
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children);
|
|
65
65
|
}
|
|
66
66
|
const Wrapper = wrappers[0];
|
|
67
|
-
return /* @__PURE__ */ React__default.createElement(Wrapper, null, /* @__PURE__ */ React__default.createElement(
|
|
67
|
+
return /* @__PURE__ */ React__default.createElement(Wrapper, null, /* @__PURE__ */ React__default.createElement(RenderRecursiveWrappers, { wrappers: wrappers.slice(1) }, children));
|
|
68
68
|
};
|
|
69
69
|
const EditorRootElement = ({ children, className }) => {
|
|
70
70
|
const editorRootElementRef = React__default.useRef(null);
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ import { ReactNode } from 'react';
|
|
|
67
67
|
import { Realm } from '@mdxeditor/gurx';
|
|
68
68
|
import { RootNode } from 'lexical';
|
|
69
69
|
import { SandpackProvider } from '@codesandbox/sandpack-react';
|
|
70
|
+
import { SandpackThemeProp } from '@codesandbox/sandpack-react/types';
|
|
70
71
|
import { SerializedElementNode } from 'lexical';
|
|
71
72
|
import { SerializedLexicalNode } from 'lexical';
|
|
72
73
|
import { Spread } from 'lexical';
|
|
@@ -385,6 +386,8 @@ export declare const ChangeAdmonitionType: () => React_2.JSX.Element;
|
|
|
385
386
|
*/
|
|
386
387
|
export declare const ChangeCodeMirrorLanguage: () => React_2.JSX.Element;
|
|
387
388
|
|
|
389
|
+
export declare type ClickLinkCallback = (url: string) => void;
|
|
390
|
+
|
|
388
391
|
/**
|
|
389
392
|
* Close the image dialog.
|
|
390
393
|
* @group Image
|
|
@@ -473,6 +476,10 @@ export declare interface CodeBlockEditorProps {
|
|
|
473
476
|
* Note: you don't need to unsubscribe, the emiter has a single subscription model.
|
|
474
477
|
*/
|
|
475
478
|
focusEmitter: VoidEmitter;
|
|
479
|
+
/**
|
|
480
|
+
* The theme CodeMirrorEditor used.
|
|
481
|
+
*/
|
|
482
|
+
theme: SandpackThemeProp;
|
|
476
483
|
}
|
|
477
484
|
|
|
478
485
|
/**
|
|
@@ -530,9 +537,13 @@ export declare const codeBlockPlugin: (params?: {
|
|
|
530
537
|
* The default language to use when creating a new code block if no language is passed.
|
|
531
538
|
*/
|
|
532
539
|
defaultCodeBlockLanguage?: string | undefined;
|
|
540
|
+
/**
|
|
541
|
+
* The theme of CodeMirrorEditor
|
|
542
|
+
*/
|
|
543
|
+
theme?: SandpackThemeProp | undefined;
|
|
533
544
|
} | undefined) => RealmPlugin;
|
|
534
545
|
|
|
535
|
-
|
|
546
|
+
export declare const CodeMirrorEditor: ({ language, nodeKey, code, focusEmitter, theme }: CodeBlockEditorProps) => React_2.JSX.Element;
|
|
536
547
|
|
|
537
548
|
/**
|
|
538
549
|
* A plugin that adds lets users edit code blocks with CodeMirror.
|
|
@@ -1660,8 +1671,18 @@ export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Roo
|
|
|
1660
1671
|
* @group Link Dialog
|
|
1661
1672
|
*/
|
|
1662
1673
|
export declare const linkDialogPlugin: (params?: {
|
|
1674
|
+
/**
|
|
1675
|
+
* If passed, the link dialog will be rendered using this component instead of the default one.
|
|
1676
|
+
*/
|
|
1663
1677
|
LinkDialog?: (() => JSX.Element) | undefined;
|
|
1678
|
+
/**
|
|
1679
|
+
* If passed, the link input field will autocomplete using the published suggestions.
|
|
1680
|
+
*/
|
|
1664
1681
|
linkAutocompleteSuggestions?: string[] | undefined;
|
|
1682
|
+
/**
|
|
1683
|
+
* If set, clicking on the link in the preview popup will call this callback instead of opening the link.
|
|
1684
|
+
*/
|
|
1685
|
+
onClickLinkCallback?: ClickLinkCallback | undefined;
|
|
1665
1686
|
} | undefined) => RealmPlugin;
|
|
1666
1687
|
|
|
1667
1688
|
/**
|
|
@@ -2077,6 +2098,8 @@ export declare function noop(): void;
|
|
|
2077
2098
|
*/
|
|
2078
2099
|
export declare const onBlur$: NodeRef<FocusEvent>;
|
|
2079
2100
|
|
|
2101
|
+
/* Excluded from this release type: onClickLinkCallback$ */
|
|
2102
|
+
|
|
2080
2103
|
/**
|
|
2081
2104
|
* Emits when the window is resized.
|
|
2082
2105
|
* @group Utils
|
|
@@ -2483,6 +2506,15 @@ export declare function tap<T>(arg: T, proc: (arg: T) => unknown): T;
|
|
|
2483
2506
|
*/
|
|
2484
2507
|
export declare const thematicBreakPlugin: (params?: unknown) => RealmPlugin;
|
|
2485
2508
|
|
|
2509
|
+
/**
|
|
2510
|
+
* The theme CodeMirrorEditor used.
|
|
2511
|
+
* It can be "light" | "dark" | "auto",
|
|
2512
|
+
* or the theme in "@codesandbox/sandpack-themes" package,
|
|
2513
|
+
* or you can also custom one,
|
|
2514
|
+
* learn more https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
2515
|
+
*/
|
|
2516
|
+
export declare const theme$: NodeRef<SandpackThemeProp>;
|
|
2517
|
+
|
|
2486
2518
|
/**
|
|
2487
2519
|
* Takes a value and applies a function to it.
|
|
2488
2520
|
* @group Utils
|
package/dist/index.js
CHANGED
|
@@ -17,11 +17,11 @@ import { GenericJsxEditor } from "./jsx-editors/GenericJsxEditor.js";
|
|
|
17
17
|
import { insertSandpack$, sandpackConfig$, sandpackPlugin } from "./plugins/sandpack/index.js";
|
|
18
18
|
import { codeBlockLanguages$, codeMirrorPlugin, insertCodeMirror$ } from "./plugins/codemirror/index.js";
|
|
19
19
|
import { CodeMirrorEditor } from "./plugins/codemirror/CodeMirrorEditor.js";
|
|
20
|
-
import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$ } from "./plugins/codeblock/index.js";
|
|
20
|
+
import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$, theme$ } from "./plugins/codeblock/index.js";
|
|
21
21
|
import { directivesPlugin, insertDirective$ } from "./plugins/directives/index.js";
|
|
22
22
|
import { ADMONITION_TYPES, AdmonitionDirectiveDescriptor } from "./directive-editors/AdmonitionDirectiveDescriptor.js";
|
|
23
23
|
import { GenericDirectiveEditor } from "./directive-editors/GenericDirectiveEditor.js";
|
|
24
|
-
import { applyLinkChanges$, cancelLinkEdit$, linkAutocompleteSuggestions$, linkDialogPlugin, linkDialogState$, onWindowChange$, openLinkEditDialog$, removeLink$, switchFromPreviewToLinkEdit$, updateLink$ } from "./plugins/link-dialog/index.js";
|
|
24
|
+
import { applyLinkChanges$, cancelLinkEdit$, linkAutocompleteSuggestions$, linkDialogPlugin, linkDialogState$, onClickLinkCallback$, onWindowChange$, openLinkEditDialog$, removeLink$, switchFromPreviewToLinkEdit$, updateLink$ } from "./plugins/link-dialog/index.js";
|
|
25
25
|
import { toolbarContents$, toolbarPlugin } from "./plugins/toolbar/index.js";
|
|
26
26
|
import { cmExtensions$, diffMarkdown$, diffSourcePlugin } from "./plugins/diff-source/index.js";
|
|
27
27
|
import { markdownShortcutPlugin } from "./plugins/markdown-shortcut/index.js";
|
|
@@ -246,6 +246,7 @@ export {
|
|
|
246
246
|
nestedEditorChildren$,
|
|
247
247
|
noop,
|
|
248
248
|
onBlur$,
|
|
249
|
+
onClickLinkCallback$,
|
|
249
250
|
onWindowChange$,
|
|
250
251
|
openEditImageDialog$,
|
|
251
252
|
openLinkEditDialog$,
|
|
@@ -268,6 +269,7 @@ export {
|
|
|
268
269
|
tablePlugin,
|
|
269
270
|
tap,
|
|
270
271
|
thematicBreakPlugin,
|
|
272
|
+
theme$,
|
|
271
273
|
thrush,
|
|
272
274
|
toMarkdownExtensions$,
|
|
273
275
|
toMarkdownOptions$,
|
|
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { useCellValue } from "@mdxeditor/gurx";
|
|
8
8
|
import { DecoratorNode } from "lexical";
|
|
9
9
|
import React__default from "react";
|
|
10
|
+
import { theme$ } from "./index.js";
|
|
10
11
|
import { voidEmitter } from "../../utils/voidEmitter.js";
|
|
11
12
|
import { codeBlockEditorDescriptors$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
|
|
12
13
|
class CodeBlockNode extends DecoratorNode {
|
|
@@ -87,7 +88,8 @@ class CodeBlockNode extends DecoratorNode {
|
|
|
87
88
|
language: this.getLanguage(),
|
|
88
89
|
codeBlockNode: this,
|
|
89
90
|
nodeKey: this.getKey(),
|
|
90
|
-
focusEmitter: this.__focusEmitter
|
|
91
|
+
focusEmitter: this.__focusEmitter,
|
|
92
|
+
theme: "auto"
|
|
91
93
|
}
|
|
92
94
|
);
|
|
93
95
|
}
|
|
@@ -140,6 +142,7 @@ const CodeBlockEditorContainer = (props) => {
|
|
|
140
142
|
}
|
|
141
143
|
const Editor = descriptor.Editor;
|
|
142
144
|
const { codeBlockNode: _, parentEditor: __, ...restProps } = props;
|
|
145
|
+
restProps.theme = useCellValue(theme$);
|
|
143
146
|
return /* @__PURE__ */ React__default.createElement(CodeBlockEditorContextProvider, { parentEditor: props.parentEditor, lexicalNode: props.codeBlockNode }, /* @__PURE__ */ React__default.createElement(Editor, { ...restProps }));
|
|
144
147
|
};
|
|
145
148
|
function $createCodeBlockNode(options) {
|
|
@@ -6,6 +6,7 @@ import { $isCodeBlockNode, useCodeBlockEditorContext } from "./CodeBlockNode.js"
|
|
|
6
6
|
import { Cell, Signal, withLatestFrom, map } from "@mdxeditor/gurx";
|
|
7
7
|
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
8
8
|
const defaultCodeBlockLanguage$ = Cell("");
|
|
9
|
+
const theme$ = Cell("auto");
|
|
9
10
|
const insertCodeBlock$ = Signal((r) => {
|
|
10
11
|
r.link(
|
|
11
12
|
r.pipe(
|
|
@@ -22,6 +23,7 @@ const appendCodeBlockEditorDescriptor$ = Appender(codeBlockEditorDescriptors$);
|
|
|
22
23
|
const codeBlockPlugin = realmPlugin({
|
|
23
24
|
update(realm, params) {
|
|
24
25
|
realm.pub(defaultCodeBlockLanguage$, (params == null ? void 0 : params.defaultCodeBlockLanguage) || "");
|
|
26
|
+
realm.pub(theme$, (params == null ? void 0 : params.theme) || "auto");
|
|
25
27
|
},
|
|
26
28
|
init(realm, params) {
|
|
27
29
|
realm.pubIn({
|
|
@@ -41,5 +43,6 @@ export {
|
|
|
41
43
|
codeBlockPlugin,
|
|
42
44
|
defaultCodeBlockLanguage$,
|
|
43
45
|
insertCodeBlock$,
|
|
46
|
+
theme$,
|
|
44
47
|
useCodeBlockEditorContext
|
|
45
48
|
};
|
|
@@ -5,7 +5,7 @@ import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
|
|
|
5
5
|
import { readOnly$ } from "../core/index.js";
|
|
6
6
|
import { useCodeMirrorRef } from "../sandpack/useCodeMirrorRef.js";
|
|
7
7
|
import { useCellValue } from "@mdxeditor/gurx";
|
|
8
|
-
const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
8
|
+
const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter, theme }) => {
|
|
9
9
|
const codeMirrorRef = useCodeMirrorRef(nodeKey, "codeblock", "jsx", focusEmitter);
|
|
10
10
|
const readOnly = useCellValue(readOnly$);
|
|
11
11
|
const { setCode } = useCodeBlockEditorContext();
|
|
@@ -23,7 +23,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
23
23
|
e.stopPropagation();
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
-
/* @__PURE__ */ React__default.createElement(SandpackProvider,
|
|
26
|
+
/* @__PURE__ */ React__default.createElement(SandpackProvider, { theme }, /* @__PURE__ */ React__default.createElement(
|
|
27
27
|
CodeEditor,
|
|
28
28
|
{
|
|
29
29
|
readOnly,
|
|
@@ -7,7 +7,7 @@ import styles from "../../styles/ui.module.css.js";
|
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import { createCommand } from "lexical";
|
|
9
9
|
import { useForm } from "react-hook-form";
|
|
10
|
-
import { linkDialogState$, linkAutocompleteSuggestions$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
|
|
10
|
+
import { linkDialogState$, linkAutocompleteSuggestions$, onClickLinkCallback$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
|
|
11
11
|
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
12
12
|
createCommand();
|
|
13
13
|
function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggestions }) {
|
|
@@ -55,12 +55,13 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
const LinkDialog = () => {
|
|
58
|
-
const [editorRootElementRef, activeEditor, iconComponentFor, linkDialogState, linkAutocompleteSuggestions] = useCellValues(
|
|
58
|
+
const [editorRootElementRef, activeEditor, iconComponentFor, linkDialogState, linkAutocompleteSuggestions, onClickLinkCallback] = useCellValues(
|
|
59
59
|
editorRootElementRef$,
|
|
60
60
|
activeEditor$,
|
|
61
61
|
iconComponentFor$,
|
|
62
62
|
linkDialogState$,
|
|
63
|
-
linkAutocompleteSuggestions
|
|
63
|
+
linkAutocompleteSuggestions$,
|
|
64
|
+
onClickLinkCallback$
|
|
64
65
|
);
|
|
65
66
|
const publishWindowChange = usePublisher(onWindowChange$);
|
|
66
67
|
const updateLink = usePublisher(updateLink$);
|
|
@@ -119,6 +120,12 @@ const LinkDialog = () => {
|
|
|
119
120
|
className: styles.linkDialogPreviewAnchor,
|
|
120
121
|
href: linkDialogState.url,
|
|
121
122
|
...urlIsExternal ? { target: "_blank", rel: "noreferrer" } : {},
|
|
123
|
+
onClick: (e) => {
|
|
124
|
+
if (onClickLinkCallback !== null) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
onClickLinkCallback(linkDialogState.url);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
122
129
|
title: urlIsExternal ? `Open ${linkDialogState.url} in new window` : linkDialogState.url
|
|
123
130
|
},
|
|
124
131
|
/* @__PURE__ */ React__default.createElement("span", null, linkDialogState.url),
|
|
@@ -213,9 +213,11 @@ const openLinkEditDialog$ = Action((r) => {
|
|
|
213
213
|
);
|
|
214
214
|
});
|
|
215
215
|
const linkAutocompleteSuggestions$ = Cell([]);
|
|
216
|
+
const onClickLinkCallback$ = Cell(null);
|
|
216
217
|
const linkDialogPlugin = realmPlugin({
|
|
217
218
|
init(r, params) {
|
|
218
219
|
r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) || LinkDialog);
|
|
220
|
+
r.pub(onClickLinkCallback$, (params == null ? void 0 : params.onClickLinkCallback) ?? null);
|
|
219
221
|
},
|
|
220
222
|
update(r, params = {}) {
|
|
221
223
|
r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions || []);
|
|
@@ -227,6 +229,7 @@ export {
|
|
|
227
229
|
linkAutocompleteSuggestions$,
|
|
228
230
|
linkDialogPlugin,
|
|
229
231
|
linkDialogState$,
|
|
232
|
+
onClickLinkCallback$,
|
|
230
233
|
onWindowChange$,
|
|
231
234
|
openLinkEditDialog$,
|
|
232
235
|
removeLink$,
|