@mdxeditor/editor 2.4.0 → 2.5.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.
package/README.md CHANGED
@@ -10,6 +10,7 @@ The component supports the core markdown syntax and certain extensions, includin
10
10
 
11
11
  ```jsx
12
12
  import {MDXEditor, headingsPlugin} from '@mdxeditor/editor';
13
+ import '@mdxeditor/editor/style.css';
13
14
 
14
15
  export default function App() {
15
16
  return <MDXEditor markdown={'# Hello World'} plugins={[headingsPlugin()]} />;
@@ -21,7 +22,11 @@ The best place to get started using the component is the [documentation](https:/
21
22
 
22
23
  ## Help and support
23
24
 
24
- Should you encounter any issues, please [create an issue](https://github.com/mdx-editor/editor/issues), but check if there's something similar already open first.
25
+ If you find a bug, check if something similar is not reported already in the [issues](https://github.com/mdx-editor/editor/issues). If not, [create a new issue](https://github.com/mdx-editor/editor/issues/new?assignees=&labels=bug&projects=&template=1.bug.md&title=%5BBUG%5D).
26
+
27
+ If you're integrating the component in your commercial project and need dedicated assistance with your issues in exchange of sponsorship, [contact me over email](mailto:petyo@mdxeditor.dev).
28
+
29
+ If you want to discuss ideas [join the Discord server](https://discord.gg/4q7U2Hc) or start a discussion in the [Discussions](https://github.com/mdx-editor/editor/discussions) section.
25
30
 
26
31
  ## License
27
32
 
package/dist/index.d.ts CHANGED
@@ -386,6 +386,8 @@ export declare const ChangeAdmonitionType: () => React_2.JSX.Element;
386
386
  */
387
387
  export declare const ChangeCodeMirrorLanguage: () => React_2.JSX.Element;
388
388
 
389
+ export declare type ClickLinkCallback = (url: string) => void;
390
+
389
391
  /**
390
392
  * Close the image dialog.
391
393
  * @group Image
@@ -474,10 +476,6 @@ export declare interface CodeBlockEditorProps {
474
476
  * Note: you don't need to unsubscribe, the emiter has a single subscription model.
475
477
  */
476
478
  focusEmitter: VoidEmitter;
477
- /**
478
- * The theme CodeMirrorEditor used.
479
- */
480
- theme: SandpackThemeProp;
481
479
  }
482
480
 
483
481
  /**
@@ -535,13 +533,9 @@ export declare const codeBlockPlugin: (params?: {
535
533
  * The default language to use when creating a new code block if no language is passed.
536
534
  */
537
535
  defaultCodeBlockLanguage?: string | undefined;
538
- /**
539
- * The theme of CodeMirrorEditor
540
- */
541
- theme?: SandpackThemeProp | undefined;
542
536
  } | undefined) => RealmPlugin;
543
537
 
544
- export declare const CodeMirrorEditor: ({ language, nodeKey, code, focusEmitter, theme }: CodeBlockEditorProps) => React_2.JSX.Element;
538
+ export declare const CodeMirrorEditor: ({ language, nodeKey, code, focusEmitter }: CodeBlockEditorProps) => React_2.JSX.Element;
545
539
 
546
540
  /**
547
541
  * A plugin that adds lets users edit code blocks with CodeMirror.
@@ -549,8 +543,21 @@ export declare const CodeMirrorEditor: ({ language, nodeKey, code, focusEmitter,
549
543
  */
550
544
  export declare const codeMirrorPlugin: (params?: {
551
545
  codeBlockLanguages: Record<string, string>;
546
+ /**
547
+ * The theme of CodeMirrorEditor
548
+ */
549
+ theme?: SandpackThemeProp | undefined;
552
550
  } | undefined) => RealmPlugin;
553
551
 
552
+ /**
553
+ * The theme CodeMirrorEditor used.
554
+ * It can be "light" | "dark" | "auto",
555
+ * or the theme in "@codesandbox/sandpack-themes" package,
556
+ * or you can also custom one,
557
+ * learn more https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
558
+ */
559
+ export declare const codeMirrorTheme$: NodeRef<SandpackThemeProp>;
560
+
554
561
  /**
555
562
  * A toolbar component that lets the user toggle code formatting.
556
563
  * Use for inline `code` elements (like variables, methods, etc).
@@ -1669,8 +1676,18 @@ export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Roo
1669
1676
  * @group Link Dialog
1670
1677
  */
1671
1678
  export declare const linkDialogPlugin: (params?: {
1679
+ /**
1680
+ * If passed, the link dialog will be rendered using this component instead of the default one.
1681
+ */
1672
1682
  LinkDialog?: (() => JSX.Element) | undefined;
1683
+ /**
1684
+ * If passed, the link input field will autocomplete using the published suggestions.
1685
+ */
1673
1686
  linkAutocompleteSuggestions?: string[] | undefined;
1687
+ /**
1688
+ * If set, clicking on the link in the preview popup will call this callback instead of opening the link.
1689
+ */
1690
+ onClickLinkCallback?: ClickLinkCallback | undefined;
1674
1691
  } | undefined) => RealmPlugin;
1675
1692
 
1676
1693
  /**
@@ -2086,6 +2103,8 @@ export declare function noop(): void;
2086
2103
  */
2087
2104
  export declare const onBlur$: NodeRef<FocusEvent>;
2088
2105
 
2106
+ /* Excluded from this release type: onClickLinkCallback$ */
2107
+
2089
2108
  /**
2090
2109
  * Emits when the window is resized.
2091
2110
  * @group Utils
@@ -2492,15 +2511,6 @@ export declare function tap<T>(arg: T, proc: (arg: T) => unknown): T;
2492
2511
  */
2493
2512
  export declare const thematicBreakPlugin: (params?: unknown) => RealmPlugin;
2494
2513
 
2495
- /**
2496
- * The theme CodeMirrorEditor used.
2497
- * It can be "light" | "dark" | "auto",
2498
- * or the theme in "@codesandbox/sandpack-themes" package,
2499
- * or you can also custom one,
2500
- * learn more https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
2501
- */
2502
- export declare const theme$: NodeRef<SandpackThemeProp>;
2503
-
2504
2514
  /**
2505
2515
  * Takes a value and applies a function to it.
2506
2516
  * @group Utils
package/dist/index.js CHANGED
@@ -15,13 +15,13 @@ import { quotePlugin } from "./plugins/quote/index.js";
15
15
  import { insertJsx$, isMdastJsxNode, jsxPlugin } from "./plugins/jsx/index.js";
16
16
  import { GenericJsxEditor } from "./jsx-editors/GenericJsxEditor.js";
17
17
  import { insertSandpack$, sandpackConfig$, sandpackPlugin } from "./plugins/sandpack/index.js";
18
- import { codeBlockLanguages$, codeMirrorPlugin, insertCodeMirror$ } from "./plugins/codemirror/index.js";
18
+ import { codeBlockLanguages$, codeMirrorPlugin, codeMirrorTheme$, insertCodeMirror$ } from "./plugins/codemirror/index.js";
19
19
  import { CodeMirrorEditor } from "./plugins/codemirror/CodeMirrorEditor.js";
20
- import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$, theme$ } from "./plugins/codeblock/index.js";
20
+ import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$ } 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";
@@ -164,6 +164,7 @@ export {
164
164
  codeBlockLanguages$,
165
165
  codeBlockPlugin,
166
166
  codeMirrorPlugin,
167
+ codeMirrorTheme$,
167
168
  compose,
168
169
  composerChildren$,
169
170
  contentEditableClassName$,
@@ -246,6 +247,7 @@ export {
246
247
  nestedEditorChildren$,
247
248
  noop,
248
249
  onBlur$,
250
+ onClickLinkCallback$,
249
251
  onWindowChange$,
250
252
  openEditImageDialog$,
251
253
  openLinkEditDialog$,
@@ -268,7 +270,6 @@ export {
268
270
  tablePlugin,
269
271
  tap,
270
272
  thematicBreakPlugin,
271
- theme$,
272
273
  thrush,
273
274
  toMarkdownExtensions$,
274
275
  toMarkdownOptions$,
@@ -7,7 +7,6 @@ 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";
11
10
  import { voidEmitter } from "../../utils/voidEmitter.js";
12
11
  import { codeBlockEditorDescriptors$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
13
12
  class CodeBlockNode extends DecoratorNode {
@@ -88,8 +87,7 @@ class CodeBlockNode extends DecoratorNode {
88
87
  language: this.getLanguage(),
89
88
  codeBlockNode: this,
90
89
  nodeKey: this.getKey(),
91
- focusEmitter: this.__focusEmitter,
92
- theme: "auto"
90
+ focusEmitter: this.__focusEmitter
93
91
  }
94
92
  );
95
93
  }
@@ -142,7 +140,6 @@ const CodeBlockEditorContainer = (props) => {
142
140
  }
143
141
  const Editor = descriptor.Editor;
144
142
  const { codeBlockNode: _, parentEditor: __, ...restProps } = props;
145
- restProps.theme = useCellValue(theme$);
146
143
  return /* @__PURE__ */ React__default.createElement(CodeBlockEditorContextProvider, { parentEditor: props.parentEditor, lexicalNode: props.codeBlockNode }, /* @__PURE__ */ React__default.createElement(Editor, { ...restProps }));
147
144
  };
148
145
  function $createCodeBlockNode(options) {
@@ -6,7 +6,6 @@ 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");
10
9
  const insertCodeBlock$ = Signal((r) => {
11
10
  r.link(
12
11
  r.pipe(
@@ -23,7 +22,6 @@ const appendCodeBlockEditorDescriptor$ = Appender(codeBlockEditorDescriptors$);
23
22
  const codeBlockPlugin = realmPlugin({
24
23
  update(realm, params) {
25
24
  realm.pub(defaultCodeBlockLanguage$, (params == null ? void 0 : params.defaultCodeBlockLanguage) || "");
26
- realm.pub(theme$, (params == null ? void 0 : params.theme) || "auto");
27
25
  },
28
26
  init(realm, params) {
29
27
  realm.pubIn({
@@ -43,6 +41,5 @@ export {
43
41
  codeBlockPlugin,
44
42
  defaultCodeBlockLanguage$,
45
43
  insertCodeBlock$,
46
- theme$,
47
44
  useCodeBlockEditorContext
48
45
  };
@@ -4,10 +4,11 @@ import styles from "../../styles/ui.module.css.js";
4
4
  import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
5
5
  import { readOnly$ } from "../core/index.js";
6
6
  import { useCodeMirrorRef } from "../sandpack/useCodeMirrorRef.js";
7
- import { useCellValue } from "@mdxeditor/gurx";
8
- const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter, theme }) => {
7
+ import { useCellValues } from "@mdxeditor/gurx";
8
+ import { codeMirrorTheme$ } from "./index.js";
9
+ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
9
10
  const codeMirrorRef = useCodeMirrorRef(nodeKey, "codeblock", "jsx", focusEmitter);
10
- const readOnly = useCellValue(readOnly$);
11
+ const [readOnly, theme] = useCellValues(readOnly$, codeMirrorTheme$);
11
12
  const { setCode } = useCodeBlockEditorContext();
12
13
  React__default.useEffect(() => {
13
14
  var _a, _b;
@@ -24,13 +24,18 @@ const insertCodeMirror$ = Signal((r) => {
24
24
  insertCodeBlock$
25
25
  );
26
26
  });
27
+ const codeMirrorTheme$ = Cell("auto");
27
28
  const codeMirrorPlugin = realmPlugin({
28
29
  update(r, params) {
29
- r.pub(codeBlockLanguages$, params == null ? void 0 : params.codeBlockLanguages);
30
+ r.pubIn({
31
+ [codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
32
+ [codeMirrorTheme$]: (params == null ? void 0 : params.theme) || "auto"
33
+ });
30
34
  },
31
35
  init(r, params) {
32
36
  r.pubIn({
33
37
  [codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
38
+ [codeMirrorTheme$]: (params == null ? void 0 : params.theme) || "auto",
34
39
  [appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor((params == null ? void 0 : params.codeBlockLanguages) || {})
35
40
  });
36
41
  }
@@ -47,5 +52,6 @@ function buildCodeBlockDescriptor(codeBlockLanguages) {
47
52
  export {
48
53
  codeBlockLanguages$,
49
54
  codeMirrorPlugin,
55
+ codeMirrorTheme$,
50
56
  insertCodeMirror$
51
57
  };
@@ -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$,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "2.4.0",
14
+ "version": "2.5.1",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",