@mdxeditor/editor 2.4.0 → 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/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
@@ -1669,8 +1671,18 @@ export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Roo
1669
1671
  * @group Link Dialog
1670
1672
  */
1671
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
+ */
1672
1677
  LinkDialog?: (() => JSX.Element) | undefined;
1678
+ /**
1679
+ * If passed, the link input field will autocomplete using the published suggestions.
1680
+ */
1673
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;
1674
1686
  } | undefined) => RealmPlugin;
1675
1687
 
1676
1688
  /**
@@ -2086,6 +2098,8 @@ export declare function noop(): void;
2086
2098
  */
2087
2099
  export declare const onBlur$: NodeRef<FocusEvent>;
2088
2100
 
2101
+ /* Excluded from this release type: onClickLinkCallback$ */
2102
+
2089
2103
  /**
2090
2104
  * Emits when the window is resized.
2091
2105
  * @group Utils
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLang
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$,
@@ -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.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",