@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,11 +1,11 @@
1
- import { coreSystem } from "../core/index.js";
2
- import { MdastHeadingVisitor } from "./MdastHeadingVisitor.js";
3
1
  import { $createHeadingNode, HeadingNode } from "@lexical/rich-text";
4
- import { LexicalHeadingVisitor } from "./LexicalHeadingVisitor.js";
2
+ import { Cell } from "@mdxeditor/gurx";
5
3
  import { KEY_DOWN_COMMAND, $createParagraphNode, COMMAND_PRIORITY_LOW } from "lexical";
4
+ import { realmPlugin } from "../../RealmWithPlugins.js";
6
5
  import { controlOrMeta } from "../../utils/detectMac.js";
7
- import { system } from "../../gurx/realmFactory.js";
8
- import { realmPlugin } from "../../gurx/react.js";
6
+ import { createRootEditorSubscription$, convertSelectionToNode$, addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$ } from "../core/index.js";
7
+ import { LexicalHeadingVisitor } from "./LexicalHeadingVisitor.js";
8
+ import { MdastHeadingVisitor } from "./MdastHeadingVisitor.js";
9
9
  const FORMATTING_KEYS = [48, 49, 50, 51, 52, 53, 54];
10
10
  const ALL_HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
11
11
  const CODE_TO_HEADING_LEVEL_MAP = {
@@ -16,54 +16,48 @@ const CODE_TO_HEADING_LEVEL_MAP = {
16
16
  53: 5,
17
17
  54: 6
18
18
  };
19
- const headingsSystem = system(
20
- (r, [{ createRootEditorSubscription, convertSelectionToNode }]) => {
21
- const allowedHeadingLevels = r.node(ALL_HEADING_LEVELS);
22
- r.pub(createRootEditorSubscription, (theRootEditor) => {
23
- return theRootEditor.registerCommand(
24
- KEY_DOWN_COMMAND,
25
- (event) => {
26
- const { keyCode, ctrlKey, metaKey, altKey } = event;
27
- if (FORMATTING_KEYS.includes(keyCode) && controlOrMeta(metaKey, ctrlKey) && altKey) {
28
- event.preventDefault();
29
- theRootEditor.update(() => {
30
- if (keyCode === 48) {
31
- r.pub(convertSelectionToNode, () => $createParagraphNode());
32
- } else {
33
- const allowedHeadingLevelsValues = r.getValue(allowedHeadingLevels);
34
- const requestedHeadingLevel = CODE_TO_HEADING_LEVEL_MAP[keyCode];
35
- if (!allowedHeadingLevelsValues.includes(requestedHeadingLevel)) {
36
- r.pub(convertSelectionToNode, () => $createHeadingNode(`h${requestedHeadingLevel}`));
37
- }
19
+ const allowedHeadingLevels$ = Cell(ALL_HEADING_LEVELS, (r) => {
20
+ r.pub(createRootEditorSubscription$, (theRootEditor) => {
21
+ return theRootEditor.registerCommand(
22
+ KEY_DOWN_COMMAND,
23
+ (event) => {
24
+ const { keyCode, ctrlKey, metaKey, altKey } = event;
25
+ if (FORMATTING_KEYS.includes(keyCode) && controlOrMeta(metaKey, ctrlKey) && altKey) {
26
+ event.preventDefault();
27
+ theRootEditor.update(() => {
28
+ if (keyCode === 48) {
29
+ r.pub(convertSelectionToNode$, () => $createParagraphNode());
30
+ } else {
31
+ const allowedHeadingLevels = r.getValue(allowedHeadingLevels$);
32
+ const requestedHeadingLevel = CODE_TO_HEADING_LEVEL_MAP[keyCode];
33
+ if (!allowedHeadingLevels.includes(requestedHeadingLevel)) {
34
+ r.pub(convertSelectionToNode$, () => $createHeadingNode(`h${requestedHeadingLevel}`));
38
35
  }
39
- });
40
- return true;
41
- }
42
- return false;
43
- },
44
- COMMAND_PRIORITY_LOW
45
- );
36
+ }
37
+ });
38
+ return true;
39
+ }
40
+ return false;
41
+ },
42
+ COMMAND_PRIORITY_LOW
43
+ );
44
+ });
45
+ });
46
+ const headingsPlugin = realmPlugin({
47
+ init(realm) {
48
+ realm.pubIn({
49
+ [addActivePlugin$]: "headings",
50
+ [addImportVisitor$]: MdastHeadingVisitor,
51
+ [addLexicalNode$]: HeadingNode,
52
+ [addExportVisitor$]: LexicalHeadingVisitor
46
53
  });
47
- return {
48
- allowedHeadingLevels
49
- };
50
- },
51
- [coreSystem]
52
- );
53
- const [headingsPlugin, headingsPluginHooks] = realmPlugin({
54
- id: "headings",
55
- systemSpec: headingsSystem,
56
- applyParamsToSystem(realm, params) {
57
- realm.pubKey("allowedHeadingLevels", (params == null ? void 0 : params.allowedHeadingLevels) ?? ALL_HEADING_LEVELS);
58
54
  },
59
- init: (realm) => {
60
- realm.pubKey("addImportVisitor", MdastHeadingVisitor);
61
- realm.pubKey("addLexicalNode", HeadingNode);
62
- realm.pubKey("addExportVisitor", LexicalHeadingVisitor);
55
+ update(realm, params) {
56
+ realm.pub(allowedHeadingLevels$, (params == null ? void 0 : params.allowedHeadingLevels) ?? ALL_HEADING_LEVELS);
63
57
  }
64
58
  });
65
59
  export {
66
- headingsPlugin,
67
- headingsPluginHooks,
68
- headingsSystem
60
+ ALL_HEADING_LEVELS,
61
+ allowedHeadingLevels$,
62
+ headingsPlugin
69
63
  };
@@ -3,14 +3,18 @@ import classNames from "classnames";
3
3
  import React__default from "react";
4
4
  import { useForm } from "react-hook-form";
5
5
  import styles from "../../styles/ui.module.css.js";
6
- import { corePluginHooks } from "../core/index.js";
7
- import { imagePluginHooks } from "./index.js";
6
+ import { editorRootElementRef$ } from "../core/index.js";
7
+ import { imageAutocompleteSuggestions$, imageDialogState$, saveImage$, closeImageDialog$ } from "./index.js";
8
8
  import { DownshiftAutoComplete } from "../core/ui/DownshiftAutoComplete.js";
9
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
9
10
  const ImageDialog = () => {
10
- const [imageAutocompleteSuggestions, state] = imagePluginHooks.useEmitterValues("imageAutocompleteSuggestions", "imageDialogState");
11
- const saveImage = imagePluginHooks.usePublisher("saveImage");
12
- const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
13
- const closeImageDialog = imagePluginHooks.usePublisher("closeImageDialog");
11
+ const [imageAutocompleteSuggestions, state, editorRootElementRef] = useCellValues(
12
+ imageAutocompleteSuggestions$,
13
+ imageDialogState$,
14
+ editorRootElementRef$
15
+ );
16
+ const saveImage = usePublisher(saveImage$);
17
+ const closeImageDialog = usePublisher(closeImageDialog$);
14
18
  const { register, handleSubmit, control, setValue, reset } = useForm({
15
19
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
16
20
  values: state.type === "editing" ? state.initialValues : {}
@@ -21,7 +25,7 @@ const ImageDialog = () => {
21
25
  open: state.type !== "inactive",
22
26
  onOpenChange: (open) => {
23
27
  if (!open) {
24
- closeImageDialog(true);
28
+ closeImageDialog();
25
29
  reset({ src: "", title: "", altText: "" });
26
30
  }
27
31
  }
@@ -4,11 +4,12 @@ import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection.
4
4
  import { mergeRegister } from "@lexical/utils";
5
5
  import classNames from "classnames";
6
6
  import { $isNodeSelection, $getSelection, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
7
- import { imagePluginHooks } from "./index.js";
7
+ import { disableImageResize$, imagePreviewHandler$, openEditImageDialog$ } from "./index.js";
8
8
  import styles from "../../styles/ui.module.css.js";
9
- import { corePluginHooks } from "../core/index.js";
9
+ import { iconComponentFor$ } from "../core/index.js";
10
10
  import { $isImageNode } from "./ImageNode.js";
11
11
  import ImageResizer from "./ImageResizer.js";
12
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
12
13
  const imageCache = /* @__PURE__ */ new Set();
13
14
  function useSuspenseImage(src) {
14
15
  if (!imageCache.has(src)) {
@@ -47,6 +48,12 @@ function LazyImage({
47
48
  );
48
49
  }
49
50
  function ImageEditor({ src, title, alt, nodeKey, width, height }) {
51
+ const [disableImageResize, imagePreviewHandler, iconComponentFor] = useCellValues(
52
+ disableImageResize$,
53
+ imagePreviewHandler$,
54
+ iconComponentFor$
55
+ );
56
+ const openEditImageDialog = usePublisher(openEditImageDialog$);
50
57
  const imageRef = React__default.useRef(null);
51
58
  const buttonRef = React__default.useRef(null);
52
59
  const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
@@ -54,12 +61,8 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
54
61
  const [selection, setSelection] = React__default.useState(null);
55
62
  const activeEditorRef = React__default.useRef(null);
56
63
  const [isResizing, setIsResizing] = React__default.useState(false);
57
- const [disableImageResize] = imagePluginHooks.useEmitterValues("disableImageResize");
58
- const [imagePreviewHandler] = imagePluginHooks.useEmitterValues("imagePreviewHandler");
59
64
  const [imageSource, setImageSource] = React__default.useState(null);
60
65
  const [initialImagePath, setInitialImagePath] = React__default.useState(null);
61
- const openEditImageDialog = imagePluginHooks.usePublisher("openEditImageDialog");
62
- const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
63
66
  const onDelete = React__default.useCallback(
64
67
  (payload) => {
65
68
  if (isSelected && $isNodeSelection($getSelection())) {
@@ -118,7 +121,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
118
121
  } else {
119
122
  setImageSource(src);
120
123
  }
121
- }, [src, imagePreviewHandler]);
124
+ }, [src, imagePreviewHandler, initialImagePath]);
122
125
  React__default.useEffect(() => {
123
126
  let isMounted = true;
124
127
  const unregister = mergeRegister(
@@ -16,12 +16,21 @@ function convertImageElement(domNode) {
16
16
  return null;
17
17
  }
18
18
  class ImageNode extends DecoratorNode {
19
+ /**
20
+ * Constructs a new {@link ImageNode} with the specified image parameters.
21
+ * Use {@link $createImageNode} to construct one.
22
+ */
19
23
  constructor(src, altText, title, width, height, key) {
20
24
  super(key);
25
+ /** @internal */
21
26
  __publicField(this, "__src");
27
+ /** @internal */
22
28
  __publicField(this, "__altText");
29
+ /** @internal */
23
30
  __publicField(this, "__title");
31
+ /** @internal */
24
32
  __publicField(this, "__width");
33
+ /** @internal */
25
34
  __publicField(this, "__height");
26
35
  this.__src = src;
27
36
  this.__title = title;
@@ -29,12 +38,15 @@ class ImageNode extends DecoratorNode {
29
38
  this.__width = width || "inherit";
30
39
  this.__height = height || "inherit";
31
40
  }
41
+ /** @internal */
32
42
  static getType() {
33
43
  return "image";
34
44
  }
45
+ /** @internal */
35
46
  static clone(node) {
36
47
  return new ImageNode(node.__src, node.__altText, node.__title, node.__width, node.__height, node.__key);
37
48
  }
49
+ /** @internal */
38
50
  static importJSON(serializedNode) {
39
51
  const { altText, title, src, width, height } = serializedNode;
40
52
  const node = $createImageNode({
@@ -46,6 +58,7 @@ class ImageNode extends DecoratorNode {
46
58
  });
47
59
  return node;
48
60
  }
61
+ /** @internal */
49
62
  exportDOM() {
50
63
  const element = document.createElement("img");
51
64
  element.setAttribute("src", this.__src);
@@ -61,6 +74,7 @@ class ImageNode extends DecoratorNode {
61
74
  }
62
75
  return { element };
63
76
  }
77
+ /** @internal */
64
78
  static importDOM() {
65
79
  return {
66
80
  img: () => ({
@@ -69,6 +83,7 @@ class ImageNode extends DecoratorNode {
69
83
  })
70
84
  };
71
85
  }
86
+ /** @internal */
72
87
  exportJSON() {
73
88
  return {
74
89
  altText: this.getAltText(),
@@ -80,11 +95,15 @@ class ImageNode extends DecoratorNode {
80
95
  version: 1
81
96
  };
82
97
  }
98
+ /**
99
+ * Sets the image dimensions
100
+ */
83
101
  setWidthAndHeight(width, height) {
84
102
  const writable = this.getWritable();
85
103
  writable.__width = width;
86
104
  writable.__height = height;
87
105
  }
106
+ /** @internal */
88
107
  createDOM(config) {
89
108
  const span = document.createElement("span");
90
109
  const theme = config.theme;
@@ -94,6 +113,7 @@ class ImageNode extends DecoratorNode {
94
113
  }
95
114
  return span;
96
115
  }
116
+ /** @internal */
97
117
  updateDOM() {
98
118
  return false;
99
119
  }
@@ -112,9 +132,6 @@ class ImageNode extends DecoratorNode {
112
132
  getWidth() {
113
133
  return this.__width;
114
134
  }
115
- hasExplicitDimensions() {
116
- return this.__width !== "inherit" || this.__height !== "inherit";
117
- }
118
135
  setTitle(title) {
119
136
  this.getWritable().__title = title;
120
137
  }
@@ -124,6 +141,11 @@ class ImageNode extends DecoratorNode {
124
141
  setAltText(altText) {
125
142
  this.getWritable().__altText = altText ?? "";
126
143
  }
144
+ /** @internal */
145
+ hasExplicitDimensions() {
146
+ return this.__width !== "inherit" || this.__height !== "inherit";
147
+ }
148
+ /** @internal */
127
149
  decorate(_parentEditor) {
128
150
  return /* @__PURE__ */ React__default.createElement(
129
151
  ImageEditor,
@@ -138,8 +160,8 @@ class ImageNode extends DecoratorNode {
138
160
  );
139
161
  }
140
162
  }
141
- function $createImageNode(options) {
142
- const { altText, title, src, key, width, height } = options;
163
+ function $createImageNode(params) {
164
+ const { altText, title, src, key, width, height } = params;
143
165
  return new ImageNode(src, altText, title, width, height, key);
144
166
  }
145
167
  function $isImageNode(node) {
@@ -1,37 +1,24 @@
1
+ import { realmPlugin } from "../../RealmWithPlugins.js";
1
2
  import { $wrapNodeInElement } from "@lexical/utils";
3
+ import { Signal, Cell, withLatestFrom, Action, mapTo, map } from "@mdxeditor/gurx";
2
4
  import { $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, createCommand, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
3
- import { coreSystem } from "../core/index.js";
4
- import { $createImageNode, $isImageNode, ImageNode } from "./ImageNode.js";
5
- import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
6
- import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
7
5
  import { CAN_USE_DOM } from "../../utils/detectMac.js";
6
+ import { rootEditor$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
8
7
  import { ImageDialog } from "./ImageDialog.js";
9
- import { system } from "../../gurx/realmFactory.js";
10
- import { realmPlugin } from "../../gurx/react.js";
11
- const imageSystem = system(
12
- (r, [{ rootEditor }]) => {
13
- const insertImage = r.node();
14
- const imageAutocompleteSuggestions = r.node([]);
15
- const disableImageResize = r.node(false);
16
- const imageUploadHandler = r.node(null);
17
- const imagePreviewHandler = r.node(null);
18
- const imageDialogState = r.node({ type: "inactive" });
19
- const openNewImageDialog = r.node();
20
- const openEditImageDialog = r.node();
21
- const closeImageDialog = r.node();
22
- const saveImage = r.node();
23
- r.link(r.pipe(closeImageDialog, r.o.mapTo({ type: "inactive" })), imageDialogState);
24
- r.link(r.pipe(openNewImageDialog, r.o.mapTo({ type: "new" })), imageDialogState);
25
- r.link(
26
- r.pipe(
27
- openEditImageDialog,
28
- r.o.map((payload) => ({ type: "editing", ...payload }))
29
- ),
30
- imageDialogState
31
- );
8
+ import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
9
+ import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
10
+ import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
11
+ const insertImage$ = Signal();
12
+ const imageAutocompleteSuggestions$ = Cell([]);
13
+ const disableImageResize$ = Cell(false);
14
+ const imageUploadHandler$ = Cell(null);
15
+ const imagePreviewHandler$ = Cell(null);
16
+ const imageDialogState$ = Cell(
17
+ { type: "inactive" },
18
+ (r) => {
32
19
  r.sub(
33
- r.pipe(saveImage, r.o.withLatestFrom(rootEditor, imageUploadHandler, imageDialogState)),
34
- ([values, theEditor, imageUploadHandler2, dialogState]) => {
20
+ r.pipe(saveImage$, withLatestFrom(rootEditor$, imageUploadHandler$, imageDialogState$)),
21
+ ([values, theEditor, imageUploadHandler, dialogState]) => {
35
22
  const handler = dialogState.type === "editing" ? (src) => {
36
23
  theEditor == null ? void 0 : theEditor.update(() => {
37
24
  const { nodeKey } = dialogState;
@@ -40,7 +27,7 @@ const imageSystem = system(
40
27
  imageNode.setAltText(values.altText);
41
28
  imageNode.setSrc(src);
42
29
  });
43
- r.pub(imageDialogState, { type: "inactive" });
30
+ r.pub(imageDialogState$, { type: "inactive" });
44
31
  } : (src) => {
45
32
  theEditor == null ? void 0 : theEditor.update(() => {
46
33
  const imageNode = $createImageNode({ altText: values.altText ?? "", src, title: values.title ?? "" });
@@ -49,10 +36,10 @@ const imageSystem = system(
49
36
  $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
50
37
  }
51
38
  });
52
- r.pub(imageDialogState, { type: "inactive" });
39
+ r.pub(imageDialogState$, { type: "inactive" });
53
40
  };
54
41
  if (values.file.length > 0) {
55
- imageUploadHandler2 == null ? void 0 : imageUploadHandler2(values.file.item(0)).then(handler).catch((e) => {
42
+ imageUploadHandler == null ? void 0 : imageUploadHandler(values.file.item(0)).then(handler).catch((e) => {
56
43
  throw e;
57
44
  });
58
45
  } else if (values.src) {
@@ -60,7 +47,7 @@ const imageSystem = system(
60
47
  }
61
48
  }
62
49
  );
63
- r.sub(rootEditor, (editor) => {
50
+ r.sub(rootEditor$, (editor) => {
64
51
  editor == null ? void 0 : editor.registerCommand(
65
52
  INSERT_IMAGE_COMMAND,
66
53
  (payload) => {
@@ -73,7 +60,7 @@ const imageSystem = system(
73
60
  },
74
61
  COMMAND_PRIORITY_EDITOR
75
62
  );
76
- const theUploadHandler = r.getValue(imageUploadHandler);
63
+ const theUploadHandler = r.getValue(imageUploadHandler$);
77
64
  editor == null ? void 0 : editor.registerCommand(
78
65
  DRAGSTART_COMMAND,
79
66
  (event) => {
@@ -91,7 +78,7 @@ const imageSystem = system(
91
78
  editor == null ? void 0 : editor.registerCommand(
92
79
  DROP_COMMAND,
93
80
  (event) => {
94
- return onDrop(event, editor, r.getValue(imageUploadHandler));
81
+ return onDrop(event, editor, r.getValue(imageUploadHandler$));
95
82
  },
96
83
  COMMAND_PRIORITY_HIGH
97
84
  );
@@ -107,7 +94,7 @@ const imageSystem = system(
107
94
  if (!cbPayload.length || cbPayload.length === 0) {
108
95
  return false;
109
96
  }
110
- const imageUploadHandlerValue = r.getValue(imageUploadHandler);
97
+ const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
111
98
  Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
112
99
  urls.forEach((url) => {
113
100
  editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
@@ -123,42 +110,40 @@ const imageSystem = system(
123
110
  COMMAND_PRIORITY_CRITICAL
124
111
  );
125
112
  });
126
- return {
127
- imageDialogState,
128
- saveImage,
129
- openNewImageDialog,
130
- openEditImageDialog,
131
- closeImageDialog,
132
- imageUploadHandler,
133
- imageAutocompleteSuggestions,
134
- disableImageResize,
135
- insertImage,
136
- imagePreviewHandler
137
- };
138
- },
139
- [coreSystem]
113
+ }
140
114
  );
141
- const [
142
- /** @internal */
143
- imagePlugin,
144
- /** @internal */
145
- imagePluginHooks
146
- ] = realmPlugin({
147
- id: "image",
148
- systemSpec: imageSystem,
149
- applyParamsToSystem: (realm, params) => {
150
- realm.pubKey("imageUploadHandler", (params == null ? void 0 : params.imageUploadHandler) || null);
151
- realm.pubKey("imageAutocompleteSuggestions", (params == null ? void 0 : params.imageAutocompleteSuggestions) || []);
152
- realm.pubKey("disableImageResize", Boolean(params == null ? void 0 : params.disableImageResize));
153
- realm.pubKey("imagePreviewHandler", (params == null ? void 0 : params.imagePreviewHandler) || null);
115
+ const openNewImageDialog$ = Action((r) => {
116
+ r.link(r.pipe(openNewImageDialog$, mapTo({ type: "new" })), imageDialogState$);
117
+ });
118
+ const openEditImageDialog$ = Signal((r) => {
119
+ r.link(
120
+ r.pipe(
121
+ openEditImageDialog$,
122
+ map((payload) => ({ type: "editing", ...payload }))
123
+ ),
124
+ imageDialogState$
125
+ );
126
+ });
127
+ const closeImageDialog$ = Action((r) => {
128
+ r.link(r.pipe(closeImageDialog$, mapTo({ type: "inactive" })), imageDialogState$);
129
+ });
130
+ const saveImage$ = Signal();
131
+ const imagePlugin = realmPlugin({
132
+ init(realm) {
133
+ realm.pubIn({
134
+ [addImportVisitor$]: [MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor],
135
+ [addLexicalNode$]: ImageNode,
136
+ [addExportVisitor$]: LexicalImageVisitor,
137
+ [addComposerChild$]: ImageDialog
138
+ });
154
139
  },
155
- init: (realm) => {
156
- realm.pubKey("addImportVisitor", MdastImageVisitor);
157
- realm.pubKey("addImportVisitor", MdastHtmlImageVisitor);
158
- realm.pubKey("addImportVisitor", MdastJsxImageVisitor);
159
- realm.pubKey("addLexicalNode", ImageNode);
160
- realm.pubKey("addExportVisitor", LexicalImageVisitor);
161
- realm.pubKey("addComposerChild", ImageDialog);
140
+ update(realm, params) {
141
+ realm.pubIn({
142
+ [imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) || null,
143
+ [imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) || [],
144
+ [disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
145
+ [imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) || null
146
+ });
162
147
  }
163
148
  });
164
149
  const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
@@ -294,7 +279,15 @@ export {
294
279
  $isImageNode,
295
280
  INSERT_IMAGE_COMMAND,
296
281
  ImageNode,
282
+ closeImageDialog$,
283
+ disableImageResize$,
284
+ imageAutocompleteSuggestions$,
285
+ imageDialogState$,
297
286
  imagePlugin,
298
- imagePluginHooks,
299
- imageSystem
287
+ imagePreviewHandler$,
288
+ imageUploadHandler$,
289
+ insertImage$,
290
+ openEditImageDialog$,
291
+ openNewImageDialog$,
292
+ saveImage$
300
293
  };
@@ -7,8 +7,9 @@ var __publicField = (obj, key, value) => {
7
7
  import { DecoratorNode } from "lexical";
8
8
  import React__default from "react";
9
9
  import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
10
- import { jsxPluginHooks } from "./index.js";
11
10
  import { voidEmitter } from "../../utils/voidEmitter.js";
11
+ import { useCellValue } from "@mdxeditor/gurx";
12
+ import { jsxComponentDescriptors$ } from "../core/index.js";
12
13
  class LexicalJsxNode extends DecoratorNode {
13
14
  constructor(mdastNode, key) {
14
15
  super(key);
@@ -68,7 +69,7 @@ class LexicalJsxNode extends DecoratorNode {
68
69
  }
69
70
  function JsxEditorContainer(props) {
70
71
  const { mdastNode } = props;
71
- const [jsxComponentDescriptors] = jsxPluginHooks.useEmitterValues("jsxComponentDescriptors");
72
+ const jsxComponentDescriptors = useCellValue(jsxComponentDescriptors$);
72
73
  const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name);
73
74
  if (!descriptor) {
74
75
  throw new Error(`No JSX descriptor found for ${mdastNode.name}`);
@@ -1,12 +1,12 @@
1
1
  import { mdxFromMarkdown, mdxToMarkdown } from "mdast-util-mdx";
2
2
  import { mdxjs } from "micromark-extension-mdxjs";
3
- import { coreSystem } from "../core/index.js";
3
+ import { insertDecoratorNode$, jsxIsAvailable$, addMdastExtension$, addSyntaxExtension$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addToMarkdownExtension$, jsxComponentDescriptors$ } from "../core/index.js";
4
4
  import { $createLexicalJsxNode, LexicalJsxNode } from "./LexicalJsxNode.js";
5
5
  import { LexicalJsxVisitor } from "./LexicalJsxVisitor.js";
6
6
  import { MdastMdxJsEsmVisitor } from "./MdastMdxJsEsmVisitor.js";
7
7
  import { MdastMdxJsxElementVisitor } from "./MdastMdxJsxElementVisitor.js";
8
- import { system } from "../../gurx/realmFactory.js";
9
- import { realmPlugin } from "../../gurx/react.js";
8
+ import { Signal, map } from "@mdxeditor/gurx";
9
+ import { realmPlugin } from "../../RealmWithPlugins.js";
10
10
  function isMdastJsxNode(node) {
11
11
  return node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement";
12
12
  }
@@ -17,66 +17,54 @@ function toMdastJsxAttributes(attributes) {
17
17
  value
18
18
  }));
19
19
  }
20
- const jsxSystem = system(
21
- (r, [{ insertDecoratorNode }]) => {
22
- const insertJsx = r.node();
23
- r.link(
24
- r.pipe(
25
- insertJsx,
26
- r.o.map(({ kind, name, children, props }) => {
27
- return () => {
28
- const attributes = toMdastJsxAttributes(props);
29
- if (kind === "flow") {
30
- return $createLexicalJsxNode({
31
- type: "mdxJsxFlowElement",
32
- name,
33
- children: children ?? [],
34
- attributes
35
- });
36
- } else {
37
- return $createLexicalJsxNode({
38
- type: "mdxJsxTextElement",
39
- name,
40
- children: children ?? [],
41
- attributes
42
- });
43
- }
44
- };
45
- })
46
- ),
47
- insertDecoratorNode
48
- );
49
- return {
50
- insertJsx
51
- };
52
- },
53
- [coreSystem]
54
- );
55
- const [
56
- /** @internal */
57
- jsxPlugin,
58
- /** @internal */
59
- jsxPluginHooks
60
- ] = realmPlugin({
61
- id: "jsx",
62
- systemSpec: jsxSystem,
63
- applyParamsToSystem: (realm, params) => {
64
- realm.pubKey("jsxComponentDescriptors", (params == null ? void 0 : params.jsxComponentDescriptors) || []);
20
+ const insertJsx$ = Signal((r) => {
21
+ r.link(
22
+ r.pipe(
23
+ insertJsx$,
24
+ map(({ kind, name, children, props }) => {
25
+ return () => {
26
+ const attributes = toMdastJsxAttributes(props);
27
+ if (kind === "flow") {
28
+ return $createLexicalJsxNode({
29
+ type: "mdxJsxFlowElement",
30
+ name,
31
+ children: children ?? [],
32
+ attributes
33
+ });
34
+ } else {
35
+ return $createLexicalJsxNode({
36
+ type: "mdxJsxTextElement",
37
+ name,
38
+ children: children ?? [],
39
+ attributes
40
+ });
41
+ }
42
+ };
43
+ })
44
+ ),
45
+ insertDecoratorNode$
46
+ );
47
+ });
48
+ const jsxPlugin = realmPlugin({
49
+ init: (realm) => {
50
+ realm.pubIn({
51
+ // import
52
+ [jsxIsAvailable$]: true,
53
+ [addMdastExtension$]: mdxFromMarkdown(),
54
+ [addSyntaxExtension$]: mdxjs(),
55
+ [addImportVisitor$]: [MdastMdxJsxElementVisitor, MdastMdxJsEsmVisitor],
56
+ // export
57
+ [addLexicalNode$]: LexicalJsxNode,
58
+ [addExportVisitor$]: LexicalJsxVisitor,
59
+ [addToMarkdownExtension$]: mdxToMarkdown()
60
+ });
65
61
  },
66
- init: (realm, _) => {
67
- realm.pubKey("jsxIsAvailable", true);
68
- realm.pubKey("addMdastExtension", mdxFromMarkdown());
69
- realm.pubKey("addSyntaxExtension", mdxjs());
70
- realm.pubKey("addImportVisitor", MdastMdxJsxElementVisitor);
71
- realm.pubKey("addImportVisitor", MdastMdxJsEsmVisitor);
72
- realm.pubKey("addLexicalNode", LexicalJsxNode);
73
- realm.pubKey("addExportVisitor", LexicalJsxVisitor);
74
- realm.pubKey("addToMarkdownExtension", mdxToMarkdown());
62
+ update(realm, params) {
63
+ realm.pub(jsxComponentDescriptors$, (params == null ? void 0 : params.jsxComponentDescriptors) || []);
75
64
  }
76
65
  });
77
66
  export {
67
+ insertJsx$,
78
68
  isMdastJsxNode,
79
- jsxPlugin,
80
- jsxPluginHooks,
81
- jsxSystem
69
+ jsxPlugin
82
70
  };