@mdxeditor/editor 1.14.3 → 2.0.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.
Files changed (202) hide show
  1. package/dist/MDXEditor.js +19 -25
  2. package/dist/RealmWithPlugins.js +36 -0
  3. package/dist/directive-editors/GenericDirectiveEditor.js +7 -4
  4. package/dist/index.d.ts +2590 -62
  5. package/dist/index.js +138 -66
  6. package/dist/jsx-editors/GenericJsxEditor.js +12 -9
  7. package/dist/plugins/codeblock/CodeBlockNode.js +5 -5
  8. package/dist/plugins/codeblock/index.js +37 -63
  9. package/dist/plugins/codemirror/CodeMirrorEditor.js +3 -2
  10. package/dist/plugins/codemirror/index.js +28 -45
  11. package/dist/plugins/core/GenericHTMLNode.js +9 -1
  12. package/dist/plugins/core/MdastHTMLNode.js +0 -1
  13. package/dist/plugins/core/NestedLexicalEditor.js +11 -10
  14. package/dist/plugins/core/PropertyPopover.js +3 -2
  15. package/dist/plugins/core/SharedHistoryPlugin.js +3 -3
  16. package/dist/plugins/core/index.js +426 -385
  17. package/dist/plugins/core/ui/DownshiftAutoComplete.js +3 -2
  18. package/dist/plugins/core/ui/PopoverUtils.js +3 -2
  19. package/dist/plugins/diff-source/DiffSourceWrapper.js +3 -4
  20. package/dist/plugins/diff-source/DiffViewer.js +7 -7
  21. package/dist/plugins/diff-source/SourceEditor.js +6 -6
  22. package/dist/plugins/diff-source/index.js +17 -52
  23. package/dist/plugins/directives/DirectiveNode.js +28 -5
  24. package/dist/plugins/directives/index.js +36 -43
  25. package/dist/plugins/frontmatter/FrontmatterEditor.js +20 -16
  26. package/dist/plugins/frontmatter/index.js +51 -62
  27. package/dist/plugins/headings/index.js +43 -49
  28. package/dist/plugins/image/ImageDialog.js +11 -7
  29. package/dist/plugins/image/ImageEditor.js +10 -7
  30. package/dist/plugins/image/ImageNode.js +27 -5
  31. package/dist/plugins/image/index.js +65 -72
  32. package/dist/plugins/jsx/LexicalJsxNode.js +3 -2
  33. package/dist/plugins/jsx/index.js +48 -60
  34. package/dist/plugins/link/index.js +15 -20
  35. package/dist/plugins/link-dialog/LinkDialog.js +17 -16
  36. package/dist/plugins/link-dialog/index.js +194 -216
  37. package/dist/plugins/lists/index.js +50 -65
  38. package/dist/plugins/markdown-shortcut/index.js +12 -15
  39. package/dist/plugins/quote/index.js +11 -19
  40. package/dist/plugins/sandpack/SandpackEditor.js +3 -2
  41. package/dist/plugins/sandpack/index.js +34 -50
  42. package/dist/plugins/sandpack/useCodeMirrorRef.js +7 -6
  43. package/dist/plugins/table/TableEditor.js +12 -13
  44. package/dist/plugins/table/TableNode.js +28 -0
  45. package/dist/plugins/table/index.js +32 -39
  46. package/dist/plugins/thematic-break/index.js +19 -32
  47. package/dist/plugins/toolbar/components/BlockTypeSelect.js +9 -8
  48. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +4 -4
  49. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +3 -2
  50. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +5 -5
  51. package/dist/plugins/toolbar/components/CodeToggle.js +4 -3
  52. package/dist/plugins/toolbar/components/CreateLink.js +6 -4
  53. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +5 -5
  54. package/dist/plugins/toolbar/components/InsertAdmonition.js +5 -3
  55. package/dist/plugins/toolbar/components/InsertCodeBlock.js +5 -3
  56. package/dist/plugins/toolbar/components/InsertFrontmatter.js +6 -5
  57. package/dist/plugins/toolbar/components/InsertImage.js +6 -5
  58. package/dist/plugins/toolbar/components/InsertSandpack.js +5 -4
  59. package/dist/plugins/toolbar/components/InsertTable.js +5 -3
  60. package/dist/plugins/toolbar/components/InsertThematicBreak.js +6 -4
  61. package/dist/plugins/toolbar/components/ListsToggle.js +5 -4
  62. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +9 -4
  63. package/dist/plugins/toolbar/components/UndoRedo.js +3 -3
  64. package/dist/plugins/toolbar/index.js +15 -31
  65. package/dist/plugins/toolbar/primitives/DialogButton.js +23 -24
  66. package/dist/plugins/toolbar/primitives/TooltipWrap.js +3 -2
  67. package/dist/plugins/toolbar/primitives/select.js +5 -4
  68. package/dist/plugins/toolbar/primitives/toolbar.js +10 -4
  69. package/dist/style.css +935 -571
  70. package/dist/styles/globals.css.js +1 -4
  71. package/dist/styles/lexical-theme.module.css.js +25 -19
  72. package/dist/styles/ui.module.css.js +103 -103
  73. package/package.json +64 -317
  74. package/dist/FormatConstants.d.ts +0 -9
  75. package/dist/MDXEditor.d.ts +0 -103
  76. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +0 -17
  77. package/dist/directive-editors/GenericDirectiveEditor.d.ts +0 -8
  78. package/dist/exportMarkdownFromLexical.d.ts +0 -138
  79. package/dist/gurx/index.d.ts +0 -3
  80. package/dist/gurx/react.d.ts +0 -152
  81. package/dist/gurx/react.js +0 -206
  82. package/dist/gurx/realm.d.ts +0 -148
  83. package/dist/gurx/realm.js +0 -489
  84. package/dist/gurx/realmFactory.d.ts +0 -79
  85. package/dist/gurx/realmFactory.js +0 -32
  86. package/dist/importMarkdownToLexical.d.ts +0 -101
  87. package/dist/jsx-editors/GenericJsxEditor.d.ts +0 -8
  88. package/dist/plugins/codeblock/CodeBlockNode.d.ts +0 -100
  89. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +0 -4
  90. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +0 -3
  91. package/dist/plugins/codeblock/index.d.ts +0 -787
  92. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +0 -3
  93. package/dist/plugins/codemirror/index.d.ts +0 -1038
  94. package/dist/plugins/core/GenericHTMLNode.d.ts +0 -38
  95. package/dist/plugins/core/Icon.d.ts +0 -6
  96. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.d.ts +0 -4
  97. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +0 -4
  98. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +0 -4
  99. package/dist/plugins/core/LexicalRootVisitor.d.ts +0 -4
  100. package/dist/plugins/core/LexicalTextVisitor.d.ts +0 -5
  101. package/dist/plugins/core/MdastBreakVisitor.d.ts +0 -3
  102. package/dist/plugins/core/MdastFormattingVisitor.d.ts +0 -4
  103. package/dist/plugins/core/MdastHTMLNode.d.ts +0 -13
  104. package/dist/plugins/core/MdastHTMLVisitor.d.ts +0 -3
  105. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +0 -3
  106. package/dist/plugins/core/MdastParagraphVisitor.d.ts +0 -3
  107. package/dist/plugins/core/MdastRootVisitor.d.ts +0 -3
  108. package/dist/plugins/core/MdastTextVisitor.d.ts +0 -3
  109. package/dist/plugins/core/NestedLexicalEditor.d.ts +0 -92
  110. package/dist/plugins/core/PropertyPopover.d.ts +0 -23
  111. package/dist/plugins/core/SharedHistoryPlugin.d.ts +0 -2
  112. package/dist/plugins/core/index.d.ts +0 -583
  113. package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +0 -15
  114. package/dist/plugins/core/ui/PopoverUtils.d.ts +0 -4
  115. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +0 -4
  116. package/dist/plugins/diff-source/DiffViewer.d.ts +0 -2
  117. package/dist/plugins/diff-source/SourceEditor.d.ts +0 -4
  118. package/dist/plugins/diff-source/index.d.ts +0 -725
  119. package/dist/plugins/directives/DirectiveNode.d.ts +0 -51
  120. package/dist/plugins/directives/DirectiveVisitor.d.ts +0 -4
  121. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +0 -3
  122. package/dist/plugins/directives/index.d.ts +0 -773
  123. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +0 -6
  124. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +0 -35
  125. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +0 -4
  126. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +0 -3
  127. package/dist/plugins/frontmatter/index.d.ts +0 -717
  128. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +0 -4
  129. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +0 -3
  130. package/dist/plugins/headings/index.d.ts +0 -707
  131. package/dist/plugins/image/ImageDialog.d.ts +0 -2
  132. package/dist/plugins/image/ImageEditor.d.ts +0 -10
  133. package/dist/plugins/image/ImageNode.d.ts +0 -65
  134. package/dist/plugins/image/ImageResizer.d.ts +0 -18
  135. package/dist/plugins/image/LexicalImageVisitor.d.ts +0 -4
  136. package/dist/plugins/image/MdastImageVisitor.d.ts +0 -6
  137. package/dist/plugins/image/index.d.ts +0 -804
  138. package/dist/plugins/jsx/LexicalJsxNode.d.ts +0 -54
  139. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +0 -4
  140. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +0 -3
  141. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +0 -3
  142. package/dist/plugins/jsx/index.d.ts +0 -779
  143. package/dist/plugins/link/AutoLinkPlugin.d.ts +0 -9
  144. package/dist/plugins/link/LexicalLinkVisitor.d.ts +0 -4
  145. package/dist/plugins/link/MdastLinkVisitor.d.ts +0 -3
  146. package/dist/plugins/link/index.d.ts +0 -101
  147. package/dist/plugins/link-dialog/LinkDialog.d.ts +0 -16
  148. package/dist/plugins/link-dialog/index.d.ts +0 -670
  149. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +0 -4
  150. package/dist/plugins/lists/LexicalListVisitor.d.ts +0 -4
  151. package/dist/plugins/lists/MdastListItemVisitor.d.ts +0 -3
  152. package/dist/plugins/lists/MdastListVisitor.d.ts +0 -3
  153. package/dist/plugins/lists/index.d.ts +0 -703
  154. package/dist/plugins/markdown-shortcut/index.d.ts +0 -80
  155. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +0 -4
  156. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +0 -3
  157. package/dist/plugins/quote/index.d.ts +0 -480
  158. package/dist/plugins/sandpack/SandpackEditor.d.ts +0 -7
  159. package/dist/plugins/sandpack/index.d.ts +0 -1077
  160. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +0 -4
  161. package/dist/plugins/table/LexicalTableVisitor.d.ts +0 -4
  162. package/dist/plugins/table/MdastTableVisitor.d.ts +0 -3
  163. package/dist/plugins/table/TableEditor.d.ts +0 -21
  164. package/dist/plugins/table/TableNode.d.ts +0 -52
  165. package/dist/plugins/table/index.d.ts +0 -704
  166. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +0 -4
  167. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +0 -3
  168. package/dist/plugins/thematic-break/index.d.ts +0 -693
  169. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +0 -6
  170. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +0 -5
  171. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +0 -6
  172. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +0 -7
  173. package/dist/plugins/toolbar/components/CodeToggle.d.ts +0 -6
  174. package/dist/plugins/toolbar/components/CreateLink.d.ts +0 -6
  175. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +0 -18
  176. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +0 -6
  177. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +0 -7
  178. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +0 -6
  179. package/dist/plugins/toolbar/components/InsertImage.d.ts +0 -6
  180. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +0 -6
  181. package/dist/plugins/toolbar/components/InsertTable.d.ts +0 -6
  182. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +0 -6
  183. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +0 -7
  184. package/dist/plugins/toolbar/components/ListsToggle.d.ts +0 -7
  185. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +0 -7
  186. package/dist/plugins/toolbar/components/UndoRedo.d.ts +0 -5
  187. package/dist/plugins/toolbar/index.d.ts +0 -564
  188. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +0 -40
  189. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +0 -8
  190. package/dist/plugins/toolbar/primitives/select.d.ts +0 -50
  191. package/dist/plugins/toolbar/primitives/toolbar.d.ts +0 -163
  192. package/dist/styles/lexicalTheme.d.ts +0 -2
  193. package/dist/utils/detectMac.d.ts +0 -3
  194. package/dist/utils/fp.d.ts +0 -47
  195. package/dist/utils/isPartOftheEditorUI.d.ts +0 -1
  196. package/dist/utils/lexicalHelpers.d.ts +0 -11
  197. package/dist/utils/makeHslTransparent.d.ts +0 -1
  198. package/dist/utils/mergeStyleAttributes.d.ts +0 -1
  199. package/dist/utils/uuid4.d.ts +0 -1
  200. package/dist/utils/voidEmitter.d.ts +0 -14
  201. package/dist/utils/whitespaceConversion.d.ts +0 -2
  202. package/dist/utils/whitespaceConversion.js +0 -9
@@ -1,33 +1,28 @@
1
1
  import React__default from "react";
2
- import { coreSystem } from "../core/index.js";
3
2
  import { MdastLinkVisitor } from "./MdastLinkVisitor.js";
4
3
  import { LexicalLinkVisitor } from "./LexicalLinkVisitor.js";
5
4
  import { LinkNode, AutoLinkNode } from "@lexical/link";
6
5
  import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin.js";
7
6
  import { LexicalAutoLinkPlugin } from "./AutoLinkPlugin.js";
8
- import { system } from "../../gurx/realmFactory.js";
9
- import { realmPlugin } from "../../gurx/react.js";
10
- const linkSystem = system(
11
- (r) => {
12
- const disableAutoLink = r.node(false);
13
- return { disableAutoLink };
14
- },
15
- [coreSystem]
16
- );
17
- const [linkPlugin] = realmPlugin({
18
- id: "link",
19
- systemSpec: linkSystem,
20
- init: (realm, params) => {
7
+ import { Cell } from "@mdxeditor/gurx";
8
+ import { realmPlugin } from "../../RealmWithPlugins.js";
9
+ import { addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
10
+ const disableAutoLink$ = Cell(false);
11
+ const linkPlugin = realmPlugin({
12
+ init(realm, params) {
21
13
  const disableAutoLink = Boolean(params == null ? void 0 : params.disableAutoLink);
22
- realm.pubKey("addImportVisitor", MdastLinkVisitor);
23
- realm.pubKey("addLexicalNode", LinkNode);
24
- realm.pubKey("addLexicalNode", AutoLinkNode);
25
- realm.pubKey("addExportVisitor", LexicalLinkVisitor);
26
- realm.pubKey("disableAutoLink", disableAutoLink);
27
14
  const linkPluginProps = (params == null ? void 0 : params.validateUrl) ? { validateUrl: params.validateUrl } : {};
28
- realm.pubKey("addComposerChild", () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(LinkPlugin, { ...linkPluginProps }), disableAutoLink ? null : /* @__PURE__ */ React__default.createElement(LexicalAutoLinkPlugin, null)));
15
+ realm.pubIn({
16
+ [addActivePlugin$]: "link",
17
+ [addImportVisitor$]: MdastLinkVisitor,
18
+ [addLexicalNode$]: [LinkNode, AutoLinkNode],
19
+ [addExportVisitor$]: LexicalLinkVisitor,
20
+ [disableAutoLink$]: disableAutoLink,
21
+ [addComposerChild$]: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(LinkPlugin, { ...linkPluginProps }), disableAutoLink ? null : /* @__PURE__ */ React__default.createElement(LexicalAutoLinkPlugin, null))
22
+ });
29
23
  }
30
24
  });
31
25
  export {
26
+ disableAutoLink$,
32
27
  linkPlugin
33
28
  };
@@ -1,13 +1,14 @@
1
1
  import * as RadixPopover from "@radix-ui/react-popover";
2
2
  import * as Tooltip from "@radix-ui/react-tooltip";
3
3
  import React__default from "react";
4
- import { corePluginHooks } from "../core/index.js";
4
+ import { editorRootElementRef$, activeEditor$, iconComponentFor$ } from "../core/index.js";
5
5
  import { DownshiftAutoComplete } from "../core/ui/DownshiftAutoComplete.js";
6
6
  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 { linkDialogPluginHooks } from "./index.js";
10
+ import { linkDialogState$, linkAutocompleteSuggestions$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
11
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
11
12
  createCommand();
12
13
  function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggestions }) {
13
14
  const {
@@ -54,18 +55,18 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
54
55
  );
55
56
  }
56
57
  const LinkDialog = () => {
57
- const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
58
- const publishWindowChange = linkDialogPluginHooks.usePublisher("onWindowChange");
59
- const [activeEditor] = corePluginHooks.useEmitterValues("activeEditor");
60
- const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
61
- const [linkDialogState, linkAutocompleteSuggestions] = linkDialogPluginHooks.useEmitterValues(
62
- "linkDialogState",
63
- "linkAutocompleteSuggestions"
58
+ const [editorRootElementRef, activeEditor, iconComponentFor, linkDialogState, linkAutocompleteSuggestions] = useCellValues(
59
+ editorRootElementRef$,
60
+ activeEditor$,
61
+ iconComponentFor$,
62
+ linkDialogState$,
63
+ linkAutocompleteSuggestions$
64
64
  );
65
- const updateLink = linkDialogPluginHooks.usePublisher("updateLink");
66
- const cancelLinkEdit = linkDialogPluginHooks.usePublisher("cancelLinkEdit");
67
- const switchFromPreviewToLinkEdit = linkDialogPluginHooks.usePublisher("switchFromPreviewToLinkEdit");
68
- const removeLink = linkDialogPluginHooks.usePublisher("removeLink");
65
+ const publishWindowChange = usePublisher(onWindowChange$);
66
+ const updateLink = usePublisher(updateLink$);
67
+ const cancelLinkEdit = usePublisher(cancelLinkEdit$);
68
+ const switchFromPreviewToLinkEdit = usePublisher(switchFromPreviewToLinkEdit$);
69
+ const removeLink = usePublisher(removeLink$);
69
70
  React__default.useEffect(() => {
70
71
  const update = () => {
71
72
  activeEditor == null ? void 0 : activeEditor.getEditorState().read(() => {
@@ -108,7 +109,7 @@ const LinkDialog = () => {
108
109
  url: linkDialogState.url,
109
110
  title: linkDialogState.title,
110
111
  onSubmit: updateLink,
111
- onCancel: cancelLinkEdit.bind(null, true),
112
+ onCancel: cancelLinkEdit.bind(null),
112
113
  linkAutocompleteSuggestions
113
114
  }
114
115
  ),
@@ -122,7 +123,7 @@ const LinkDialog = () => {
122
123
  },
123
124
  /* @__PURE__ */ React__default.createElement("span", null, linkDialogState.url),
124
125
  urlIsExternal && iconComponentFor("open_in_new")
125
- ), /* @__PURE__ */ React__default.createElement(ActionButton, { onClick: () => switchFromPreviewToLinkEdit(true), title: "Edit link URL", "aria-label": "Edit link URL" }, iconComponentFor("edit")), /* @__PURE__ */ React__default.createElement(Tooltip.Provider, null, /* @__PURE__ */ React__default.createElement(Tooltip.Root, { open: copyUrlTooltipOpen }, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(
126
+ ), /* @__PURE__ */ React__default.createElement(ActionButton, { onClick: () => switchFromPreviewToLinkEdit(), title: "Edit link URL", "aria-label": "Edit link URL" }, iconComponentFor("edit")), /* @__PURE__ */ React__default.createElement(Tooltip.Provider, null, /* @__PURE__ */ React__default.createElement(Tooltip.Root, { open: copyUrlTooltipOpen }, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(
126
127
  ActionButton,
127
128
  {
128
129
  title: "Copy to clipboard",
@@ -135,7 +136,7 @@ const LinkDialog = () => {
135
136
  }
136
137
  },
137
138
  copyUrlTooltipOpen ? iconComponentFor("check") : iconComponentFor("content_copy")
138
- )), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 5 }, "Copied!", /* @__PURE__ */ React__default.createElement(Tooltip.Arrow, null))))), /* @__PURE__ */ React__default.createElement(ActionButton, { title: "Remove link", "aria-label": "Remove link", onClick: () => removeLink(true) }, iconComponentFor("link_off"))),
139
+ )), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 5 }, "Copied!", /* @__PURE__ */ React__default.createElement(Tooltip.Arrow, null))))), /* @__PURE__ */ React__default.createElement(ActionButton, { title: "Remove link", "aria-label": "Remove link", onClick: () => removeLink() }, iconComponentFor("link_off"))),
139
140
  /* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, { className: styles.popoverArrow })
140
141
  )));
141
142
  };
@@ -1,11 +1,11 @@
1
1
  import { TOGGLE_LINK_COMMAND, $isLinkNode } from "@lexical/link";
2
- import { $isRangeSelection, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, COMMAND_PRIORITY_HIGH, $createTextNode, $insertNodes } from "lexical";
2
+ import { KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, $createTextNode, $insertNodes } from "lexical";
3
3
  import { IS_APPLE } from "../../utils/detectMac.js";
4
4
  import { getSelectionRectangle, getSelectedNode } from "../../utils/lexicalHelpers.js";
5
- import { coreSystem } from "../core/index.js";
5
+ import { createActiveEditorSubscription$, activeEditor$, currentSelection$, addComposerChild$ } from "../core/index.js";
6
6
  import { LinkDialog } from "./LinkDialog.js";
7
- import { system } from "../../gurx/realmFactory.js";
8
- import { realmPlugin } from "../../gurx/react.js";
7
+ import { Signal, Cell, withLatestFrom, map, Action, filter } from "@mdxeditor/gurx";
8
+ import { realmPlugin } from "../../RealmWithPlugins.js";
9
9
  function getLinkNodeInSelection(selection) {
10
10
  if (!selection) {
11
11
  return null;
@@ -22,236 +22,214 @@ function getLinkNodeInSelection(selection) {
22
22
  }
23
23
  return null;
24
24
  }
25
- const linkDialogSystem = system(
26
- (r, [{ activeEditor, currentSelection, createActiveEditorSubscription }]) => {
27
- const dialogState = r.node(false);
28
- const onWindowChange = r.node();
29
- const linkDialogState = r.node({ type: "inactive" }, true);
30
- const updateLink = r.node();
31
- const cancelLinkEdit = r.node();
32
- const applyLinkChanges = r.node();
33
- const switchFromPreviewToLinkEdit = r.node();
34
- const removeLink = r.node();
35
- const openLinkEditDialog = r.node();
36
- const linkAutocompleteSuggestions = r.node([]);
37
- r.sub(
38
- r.pipe(
39
- openLinkEditDialog,
40
- r.o.withLatestFrom(currentSelection, activeEditor),
41
- r.o.filter(([, selection]) => $isRangeSelection(selection))
42
- ),
43
- ([, selection, editor]) => {
44
- editor == null ? void 0 : editor.focus(() => {
45
- editor == null ? void 0 : editor.getEditorState().read(() => {
46
- const node = getLinkNodeInSelection(selection);
47
- const rectangle = getSelectionRectangle(editor);
48
- if (node) {
49
- r.pub(linkDialogState, {
50
- type: "edit",
51
- initialUrl: node.getURL(),
52
- initialTitle: node.getTitle() || "",
53
- url: node.getURL(),
54
- title: node.getTitle() || "",
55
- linkNodeKey: node.getKey(),
56
- rectangle
57
- });
58
- } else {
59
- r.pub(linkDialogState, {
60
- type: "edit",
61
- initialUrl: "",
62
- initialTitle: "",
63
- title: "",
64
- url: "",
65
- linkNodeKey: "",
66
- rectangle
67
- });
68
- }
69
- });
70
- });
71
- }
25
+ const onWindowChange$ = Signal();
26
+ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
27
+ r.pub(createActiveEditorSubscription$, (editor) => {
28
+ return editor.registerCommand(
29
+ KEY_ESCAPE_COMMAND,
30
+ () => {
31
+ const state = r.getValue(linkDialogState$);
32
+ if (state.type === "preview") {
33
+ r.pub(linkDialogState$, { type: "inactive" });
34
+ return true;
35
+ }
36
+ return false;
37
+ },
38
+ COMMAND_PRIORITY_LOW
72
39
  );
73
- r.sub(r.pipe(removeLink, r.o.withLatestFrom(activeEditor)), ([, editor]) => {
74
- editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
75
- });
76
- r.pub(createActiveEditorSubscription, (editor) => {
77
- return editor.registerCommand(
78
- KEY_ESCAPE_COMMAND,
79
- () => {
80
- const state = r.getValue(linkDialogState);
81
- if (state.type === "preview") {
82
- r.pub(linkDialogState, { type: "inactive" });
40
+ });
41
+ r.pub(createActiveEditorSubscription$, (editor) => {
42
+ return editor.registerCommand(
43
+ KEY_MODIFIER_COMMAND,
44
+ (event) => {
45
+ if (event.key === "k" && (IS_APPLE ? event.metaKey : event.ctrlKey)) {
46
+ const selection = $getSelection();
47
+ if ($isRangeSelection(selection)) {
48
+ r.pub(openLinkEditDialog$);
49
+ event.stopPropagation();
50
+ event.preventDefault();
83
51
  return true;
52
+ } else {
53
+ return false;
84
54
  }
85
- return false;
86
- },
87
- COMMAND_PRIORITY_LOW
88
- );
89
- });
90
- r.pub(createActiveEditorSubscription, (editor) => {
91
- return editor.registerCommand(
92
- KEY_MODIFIER_COMMAND,
93
- (event) => {
94
- if (event.key === "k" && (IS_APPLE ? event.metaKey : event.ctrlKey)) {
95
- const selection = $getSelection();
96
- if ($isRangeSelection(selection)) {
97
- r.pub(openLinkEditDialog, true);
98
- event.stopPropagation();
99
- event.preventDefault();
100
- return true;
101
- } else {
102
- return false;
55
+ }
56
+ return false;
57
+ },
58
+ COMMAND_PRIORITY_HIGH
59
+ );
60
+ });
61
+ r.link(
62
+ r.pipe(
63
+ switchFromPreviewToLinkEdit$,
64
+ withLatestFrom(linkDialogState$),
65
+ map(([, state]) => {
66
+ if (state.type === "preview") {
67
+ return {
68
+ type: "edit",
69
+ initialUrl: state.url,
70
+ url: state.url,
71
+ title: state.title,
72
+ linkNodeKey: state.linkNodeKey,
73
+ rectangle: state.rectangle
74
+ };
75
+ } else {
76
+ throw new Error("Cannot switch to edit mode when not in preview mode");
77
+ }
78
+ })
79
+ ),
80
+ linkDialogState$
81
+ );
82
+ r.sub(r.pipe(updateLink$, withLatestFrom(activeEditor$, linkDialogState$, currentSelection$)), ([payload, editor, state, selection]) => {
83
+ const url = payload.url.trim();
84
+ const title = payload.title.trim();
85
+ if (url.trim() !== "") {
86
+ if (selection == null ? void 0 : selection.isCollapsed()) {
87
+ const linkContent = title || url;
88
+ editor == null ? void 0 : editor.update(
89
+ () => {
90
+ if (!getLinkNodeInSelection(selection)) {
91
+ const node = $createTextNode(linkContent);
92
+ $insertNodes([node]);
93
+ node.select();
103
94
  }
104
- }
105
- return false;
106
- },
107
- COMMAND_PRIORITY_HIGH
108
- );
109
- });
110
- r.link(
111
- r.pipe(
112
- switchFromPreviewToLinkEdit,
113
- r.o.withLatestFrom(linkDialogState),
114
- r.o.map(([, state]) => {
115
- if (state.type === "preview") {
95
+ },
96
+ { discrete: true }
97
+ );
98
+ }
99
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
100
+ r.pub(linkDialogState$, {
101
+ type: "preview",
102
+ linkNodeKey: state.linkNodeKey,
103
+ rectangle: state.rectangle,
104
+ title,
105
+ url
106
+ });
107
+ } else {
108
+ if (state.type === "edit" && state.initialUrl !== "") {
109
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
110
+ }
111
+ r.pub(linkDialogState$, {
112
+ type: "inactive"
113
+ });
114
+ }
115
+ });
116
+ r.link(
117
+ r.pipe(
118
+ cancelLinkEdit$,
119
+ withLatestFrom(linkDialogState$, activeEditor$),
120
+ map(([, state, editor]) => {
121
+ if (state.type === "edit") {
122
+ editor == null ? void 0 : editor.focus();
123
+ if (state.initialUrl === "") {
116
124
  return {
117
- type: "edit",
118
- initialUrl: state.url,
119
- url: state.url,
120
- title: state.title,
125
+ type: "inactive"
126
+ };
127
+ } else {
128
+ return {
129
+ type: "preview",
130
+ url: state.initialUrl,
121
131
  linkNodeKey: state.linkNodeKey,
122
132
  rectangle: state.rectangle
123
133
  };
124
- } else {
125
- throw new Error("Cannot switch to edit mode when not in preview mode");
126
- }
127
- })
128
- ),
129
- linkDialogState
130
- );
131
- r.sub(
132
- r.pipe(updateLink, r.o.withLatestFrom(activeEditor, linkDialogState, currentSelection)),
133
- ([payload, editor, state, selection]) => {
134
- const url = payload.url.trim();
135
- const title = payload.title.trim();
136
- if (url.trim() !== "") {
137
- if (selection == null ? void 0 : selection.isCollapsed()) {
138
- const linkContent = title || url;
139
- editor == null ? void 0 : editor.update(
140
- () => {
141
- if (!getLinkNodeInSelection(selection)) {
142
- const node = $createTextNode(linkContent);
143
- $insertNodes([node]);
144
- node.select();
145
- }
146
- },
147
- { discrete: true }
148
- );
149
134
  }
150
- editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
151
- r.pub(linkDialogState, {
152
- type: "preview",
153
- linkNodeKey: state.linkNodeKey,
154
- rectangle: state.rectangle,
155
- title,
156
- url
157
- });
158
135
  } else {
159
- if (state.type === "edit" && state.initialUrl !== "") {
160
- editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
161
- }
162
- r.pub(linkDialogState, {
163
- type: "inactive"
164
- });
136
+ throw new Error("Cannot cancel edit when not in edit mode");
165
137
  }
166
- }
167
- );
168
- r.link(
169
- r.pipe(
170
- cancelLinkEdit,
171
- r.o.withLatestFrom(linkDialogState, activeEditor),
172
- r.o.map(([, state, editor]) => {
173
- if (state.type === "edit") {
174
- editor == null ? void 0 : editor.focus();
175
- if (state.initialUrl === "") {
176
- return {
177
- type: "inactive"
178
- };
179
- } else {
180
- return {
181
- type: "preview",
182
- url: state.initialUrl,
183
- linkNodeKey: state.linkNodeKey,
184
- rectangle: state.rectangle
185
- };
186
- }
138
+ })
139
+ ),
140
+ linkDialogState$
141
+ );
142
+ r.link(
143
+ r.pipe(
144
+ r.combine(currentSelection$, onWindowChange$),
145
+ withLatestFrom(activeEditor$, linkDialogState$),
146
+ map(([[selection], activeEditor]) => {
147
+ if ($isRangeSelection(selection) && activeEditor) {
148
+ const node = getLinkNodeInSelection(selection);
149
+ if (node) {
150
+ return {
151
+ type: "preview",
152
+ url: node.getURL(),
153
+ linkNodeKey: node.getKey(),
154
+ title: node.getTitle(),
155
+ rectangle: getSelectionRectangle(activeEditor)
156
+ };
187
157
  } else {
188
- throw new Error("Cannot cancel edit when not in edit mode");
158
+ return { type: "inactive" };
189
159
  }
190
- })
191
- ),
192
- linkDialogState
193
- );
194
- r.link(
195
- r.pipe(
196
- r.combine(currentSelection, onWindowChange),
197
- r.o.withLatestFrom(activeEditor, linkDialogState),
198
- r.o.map(([[selection], activeEditor2]) => {
199
- if ($isRangeSelection(selection) && activeEditor2) {
200
- const node = getLinkNodeInSelection(selection);
201
- if (node) {
202
- return {
203
- type: "preview",
204
- url: node.getURL(),
205
- linkNodeKey: node.getKey(),
206
- title: node.getTitle(),
207
- rectangle: getSelectionRectangle(activeEditor2)
208
- };
209
- } else {
210
- return {
211
- type: "inactive"
212
- };
213
- }
160
+ } else {
161
+ return { type: "inactive" };
162
+ }
163
+ })
164
+ ),
165
+ linkDialogState$
166
+ );
167
+ });
168
+ const updateLink$ = Signal();
169
+ const cancelLinkEdit$ = Action();
170
+ const applyLinkChanges$ = Action();
171
+ const switchFromPreviewToLinkEdit$ = Action();
172
+ const removeLink$ = Action((r) => {
173
+ r.sub(r.pipe(removeLink$, withLatestFrom(activeEditor$)), ([, editor]) => {
174
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
175
+ });
176
+ });
177
+ const openLinkEditDialog$ = Action((r) => {
178
+ r.sub(
179
+ r.pipe(
180
+ openLinkEditDialog$,
181
+ withLatestFrom(currentSelection$, activeEditor$),
182
+ filter(([, selection]) => $isRangeSelection(selection))
183
+ ),
184
+ ([, selection, editor]) => {
185
+ editor == null ? void 0 : editor.focus(() => {
186
+ editor == null ? void 0 : editor.getEditorState().read(() => {
187
+ const node = getLinkNodeInSelection(selection);
188
+ const rectangle = getSelectionRectangle(editor);
189
+ if (node) {
190
+ r.pub(linkDialogState$, {
191
+ type: "edit",
192
+ initialUrl: node.getURL(),
193
+ initialTitle: node.getTitle() || "",
194
+ url: node.getURL(),
195
+ title: node.getTitle() || "",
196
+ linkNodeKey: node.getKey(),
197
+ rectangle
198
+ });
214
199
  } else {
215
- return {
216
- type: "inactive"
217
- };
200
+ r.pub(linkDialogState$, {
201
+ type: "edit",
202
+ initialUrl: "",
203
+ initialTitle: "",
204
+ title: "",
205
+ url: "",
206
+ linkNodeKey: "",
207
+ rectangle
208
+ });
218
209
  }
219
- })
220
- ),
221
- linkDialogState
222
- );
223
- return {
224
- dialogState,
225
- onWindowChange,
226
- linkDialogState,
227
- updateLink,
228
- switchFromPreviewToLinkEdit,
229
- cancelLinkEdit,
230
- removeLink,
231
- openLinkEditDialog,
232
- applyLinkChanges,
233
- linkAutocompleteSuggestions
234
- };
235
- },
236
- [coreSystem]
237
- );
238
- const [
239
- /** @internal */
240
- linkDialogPlugin,
241
- /** @internal */
242
- linkDialogPluginHooks
243
- ] = realmPlugin({
244
- id: "link-dialog",
245
- dependencies: ["link"],
246
- systemSpec: linkDialogSystem,
247
- applyParamsToSystem(r, params = {}) {
248
- r.pubKey("linkAutocompleteSuggestions", params.linkAutocompleteSuggestions || []);
249
- },
210
+ });
211
+ });
212
+ }
213
+ );
214
+ });
215
+ const linkAutocompleteSuggestions$ = Cell([]);
216
+ const linkDialogPlugin = realmPlugin({
250
217
  init(r, params) {
251
- r.pubKey("addComposerChild", (params == null ? void 0 : params.LinkDialog) || LinkDialog);
218
+ r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) || LinkDialog);
219
+ },
220
+ update(r, params = {}) {
221
+ r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions || []);
252
222
  }
253
223
  });
254
224
  export {
225
+ applyLinkChanges$,
226
+ cancelLinkEdit$,
227
+ linkAutocompleteSuggestions$,
255
228
  linkDialogPlugin,
256
- linkDialogPluginHooks
229
+ linkDialogState$,
230
+ onWindowChange$,
231
+ openLinkEditDialog$,
232
+ removeLink$,
233
+ switchFromPreviewToLinkEdit$,
234
+ updateLink$
257
235
  };