@mdxeditor/editor 1.14.2 → 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 (203) hide show
  1. package/dist/MDXEditor.js +20 -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/MdastListItemVisitor.js +3 -2
  38. package/dist/plugins/lists/index.js +50 -65
  39. package/dist/plugins/markdown-shortcut/index.js +12 -15
  40. package/dist/plugins/quote/index.js +11 -19
  41. package/dist/plugins/sandpack/SandpackEditor.js +3 -2
  42. package/dist/plugins/sandpack/index.js +34 -50
  43. package/dist/plugins/sandpack/useCodeMirrorRef.js +7 -6
  44. package/dist/plugins/table/TableEditor.js +12 -13
  45. package/dist/plugins/table/TableNode.js +28 -0
  46. package/dist/plugins/table/index.js +32 -39
  47. package/dist/plugins/thematic-break/index.js +19 -32
  48. package/dist/plugins/toolbar/components/BlockTypeSelect.js +9 -8
  49. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +4 -4
  50. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +3 -2
  51. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +5 -5
  52. package/dist/plugins/toolbar/components/CodeToggle.js +4 -3
  53. package/dist/plugins/toolbar/components/CreateLink.js +6 -4
  54. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +5 -5
  55. package/dist/plugins/toolbar/components/InsertAdmonition.js +5 -3
  56. package/dist/plugins/toolbar/components/InsertCodeBlock.js +5 -3
  57. package/dist/plugins/toolbar/components/InsertFrontmatter.js +6 -5
  58. package/dist/plugins/toolbar/components/InsertImage.js +6 -5
  59. package/dist/plugins/toolbar/components/InsertSandpack.js +5 -4
  60. package/dist/plugins/toolbar/components/InsertTable.js +5 -3
  61. package/dist/plugins/toolbar/components/InsertThematicBreak.js +6 -4
  62. package/dist/plugins/toolbar/components/ListsToggle.js +5 -4
  63. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +9 -4
  64. package/dist/plugins/toolbar/components/UndoRedo.js +3 -3
  65. package/dist/plugins/toolbar/index.js +15 -31
  66. package/dist/plugins/toolbar/primitives/DialogButton.js +23 -24
  67. package/dist/plugins/toolbar/primitives/TooltipWrap.js +3 -2
  68. package/dist/plugins/toolbar/primitives/select.js +5 -4
  69. package/dist/plugins/toolbar/primitives/toolbar.js +10 -4
  70. package/dist/style.css +937 -570
  71. package/dist/styles/globals.css.js +1 -4
  72. package/dist/styles/lexical-theme.module.css.js +25 -19
  73. package/dist/styles/ui.module.css.js +106 -103
  74. package/package.json +64 -317
  75. package/dist/FormatConstants.d.ts +0 -9
  76. package/dist/MDXEditor.d.ts +0 -103
  77. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +0 -17
  78. package/dist/directive-editors/GenericDirectiveEditor.d.ts +0 -8
  79. package/dist/exportMarkdownFromLexical.d.ts +0 -138
  80. package/dist/gurx/index.d.ts +0 -3
  81. package/dist/gurx/react.d.ts +0 -152
  82. package/dist/gurx/react.js +0 -206
  83. package/dist/gurx/realm.d.ts +0 -148
  84. package/dist/gurx/realm.js +0 -489
  85. package/dist/gurx/realmFactory.d.ts +0 -79
  86. package/dist/gurx/realmFactory.js +0 -32
  87. package/dist/importMarkdownToLexical.d.ts +0 -101
  88. package/dist/jsx-editors/GenericJsxEditor.d.ts +0 -8
  89. package/dist/plugins/codeblock/CodeBlockNode.d.ts +0 -100
  90. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +0 -4
  91. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +0 -3
  92. package/dist/plugins/codeblock/index.d.ts +0 -787
  93. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +0 -3
  94. package/dist/plugins/codemirror/index.d.ts +0 -1038
  95. package/dist/plugins/core/GenericHTMLNode.d.ts +0 -38
  96. package/dist/plugins/core/Icon.d.ts +0 -6
  97. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.d.ts +0 -4
  98. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +0 -4
  99. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +0 -4
  100. package/dist/plugins/core/LexicalRootVisitor.d.ts +0 -4
  101. package/dist/plugins/core/LexicalTextVisitor.d.ts +0 -5
  102. package/dist/plugins/core/MdastBreakVisitor.d.ts +0 -3
  103. package/dist/plugins/core/MdastFormattingVisitor.d.ts +0 -4
  104. package/dist/plugins/core/MdastHTMLNode.d.ts +0 -13
  105. package/dist/plugins/core/MdastHTMLVisitor.d.ts +0 -3
  106. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +0 -3
  107. package/dist/plugins/core/MdastParagraphVisitor.d.ts +0 -3
  108. package/dist/plugins/core/MdastRootVisitor.d.ts +0 -3
  109. package/dist/plugins/core/MdastTextVisitor.d.ts +0 -3
  110. package/dist/plugins/core/NestedLexicalEditor.d.ts +0 -92
  111. package/dist/plugins/core/PropertyPopover.d.ts +0 -23
  112. package/dist/plugins/core/SharedHistoryPlugin.d.ts +0 -2
  113. package/dist/plugins/core/index.d.ts +0 -583
  114. package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +0 -15
  115. package/dist/plugins/core/ui/PopoverUtils.d.ts +0 -4
  116. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +0 -4
  117. package/dist/plugins/diff-source/DiffViewer.d.ts +0 -2
  118. package/dist/plugins/diff-source/SourceEditor.d.ts +0 -4
  119. package/dist/plugins/diff-source/index.d.ts +0 -725
  120. package/dist/plugins/directives/DirectiveNode.d.ts +0 -51
  121. package/dist/plugins/directives/DirectiveVisitor.d.ts +0 -4
  122. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +0 -3
  123. package/dist/plugins/directives/index.d.ts +0 -773
  124. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +0 -6
  125. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +0 -35
  126. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +0 -4
  127. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +0 -3
  128. package/dist/plugins/frontmatter/index.d.ts +0 -717
  129. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +0 -4
  130. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +0 -3
  131. package/dist/plugins/headings/index.d.ts +0 -707
  132. package/dist/plugins/image/ImageDialog.d.ts +0 -2
  133. package/dist/plugins/image/ImageEditor.d.ts +0 -10
  134. package/dist/plugins/image/ImageNode.d.ts +0 -65
  135. package/dist/plugins/image/ImageResizer.d.ts +0 -18
  136. package/dist/plugins/image/LexicalImageVisitor.d.ts +0 -4
  137. package/dist/plugins/image/MdastImageVisitor.d.ts +0 -6
  138. package/dist/plugins/image/index.d.ts +0 -804
  139. package/dist/plugins/jsx/LexicalJsxNode.d.ts +0 -54
  140. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +0 -4
  141. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +0 -3
  142. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +0 -3
  143. package/dist/plugins/jsx/index.d.ts +0 -779
  144. package/dist/plugins/link/AutoLinkPlugin.d.ts +0 -9
  145. package/dist/plugins/link/LexicalLinkVisitor.d.ts +0 -4
  146. package/dist/plugins/link/MdastLinkVisitor.d.ts +0 -3
  147. package/dist/plugins/link/index.d.ts +0 -101
  148. package/dist/plugins/link-dialog/LinkDialog.d.ts +0 -16
  149. package/dist/plugins/link-dialog/index.d.ts +0 -670
  150. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +0 -4
  151. package/dist/plugins/lists/LexicalListVisitor.d.ts +0 -4
  152. package/dist/plugins/lists/MdastListItemVisitor.d.ts +0 -3
  153. package/dist/plugins/lists/MdastListVisitor.d.ts +0 -3
  154. package/dist/plugins/lists/index.d.ts +0 -703
  155. package/dist/plugins/markdown-shortcut/index.d.ts +0 -80
  156. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +0 -4
  157. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +0 -3
  158. package/dist/plugins/quote/index.d.ts +0 -480
  159. package/dist/plugins/sandpack/SandpackEditor.d.ts +0 -7
  160. package/dist/plugins/sandpack/index.d.ts +0 -1077
  161. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +0 -4
  162. package/dist/plugins/table/LexicalTableVisitor.d.ts +0 -4
  163. package/dist/plugins/table/MdastTableVisitor.d.ts +0 -3
  164. package/dist/plugins/table/TableEditor.d.ts +0 -21
  165. package/dist/plugins/table/TableNode.d.ts +0 -52
  166. package/dist/plugins/table/index.d.ts +0 -704
  167. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +0 -4
  168. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +0 -3
  169. package/dist/plugins/thematic-break/index.d.ts +0 -693
  170. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +0 -6
  171. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +0 -5
  172. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +0 -6
  173. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +0 -7
  174. package/dist/plugins/toolbar/components/CodeToggle.d.ts +0 -6
  175. package/dist/plugins/toolbar/components/CreateLink.d.ts +0 -6
  176. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +0 -18
  177. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +0 -6
  178. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +0 -7
  179. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +0 -6
  180. package/dist/plugins/toolbar/components/InsertImage.d.ts +0 -6
  181. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +0 -6
  182. package/dist/plugins/toolbar/components/InsertTable.d.ts +0 -6
  183. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +0 -6
  184. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +0 -7
  185. package/dist/plugins/toolbar/components/ListsToggle.d.ts +0 -7
  186. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +0 -7
  187. package/dist/plugins/toolbar/components/UndoRedo.d.ts +0 -5
  188. package/dist/plugins/toolbar/index.d.ts +0 -564
  189. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +0 -40
  190. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +0 -8
  191. package/dist/plugins/toolbar/primitives/select.d.ts +0 -50
  192. package/dist/plugins/toolbar/primitives/toolbar.d.ts +0 -163
  193. package/dist/styles/lexicalTheme.d.ts +0 -2
  194. package/dist/utils/detectMac.d.ts +0 -3
  195. package/dist/utils/fp.d.ts +0 -47
  196. package/dist/utils/isPartOftheEditorUI.d.ts +0 -1
  197. package/dist/utils/lexicalHelpers.d.ts +0 -11
  198. package/dist/utils/makeHslTransparent.d.ts +0 -1
  199. package/dist/utils/mergeStyleAttributes.d.ts +0 -1
  200. package/dist/utils/uuid4.d.ts +0 -1
  201. package/dist/utils/voidEmitter.d.ts +0 -14
  202. package/dist/utils/whitespaceConversion.d.ts +0 -2
  203. package/dist/utils/whitespaceConversion.js +0 -9
@@ -2,7 +2,8 @@ import { useCombobox } from "downshift";
2
2
  import React__default from "react";
3
3
  import { Controller } from "react-hook-form";
4
4
  import styles from "../../../styles/ui.module.css.js";
5
- import { corePluginHooks } from "../index.js";
5
+ import { iconComponentFor$ } from "../index.js";
6
+ import { useCellValue } from "@mdxeditor/gurx";
6
7
  const MAX_SUGGESTIONS = 20;
7
8
  const DownshiftAutoComplete = (props) => {
8
9
  if (props.suggestions.length > 0) {
@@ -21,7 +22,7 @@ const DownshiftAutoCompleteWithSuggestions = ({
21
22
  setValue
22
23
  }) => {
23
24
  const [items, setItems] = React__default.useState(suggestions.slice(0, MAX_SUGGESTIONS));
24
- const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
25
+ const iconComponentFor = useCellValue(iconComponentFor$);
25
26
  const enableAutoComplete = suggestions.length > 0;
26
27
  const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
27
28
  initialInputValue,
@@ -1,9 +1,10 @@
1
1
  import React__default from "react";
2
2
  import * as RadixPopover from "@radix-ui/react-popover";
3
- import { corePluginHooks } from "../index.js";
3
+ import { editorRootElementRef$ } from "../index.js";
4
4
  import styles from "../../../styles/ui.module.css.js";
5
+ import { useCellValue } from "@mdxeditor/gurx";
5
6
  const PopoverPortal = (props) => {
6
- const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
7
+ const editorRootElementRef = useCellValue(editorRootElementRef$);
7
8
  return /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { ...props, container: editorRootElementRef == null ? void 0 : editorRootElementRef.current });
8
9
  };
9
10
  const PopoverContent = React__default.forwardRef(
@@ -1,12 +1,11 @@
1
1
  import React__default from "react";
2
- import { diffSourcePluginHooks } from "./index.js";
3
2
  import { DiffViewer } from "./DiffViewer.js";
4
3
  import { SourceEditor } from "./SourceEditor.js";
5
- import { corePluginHooks } from "../core/index.js";
4
+ import { markdownProcessingError$, viewMode$ } from "../core/index.js";
6
5
  import styles from "../../styles/ui.module.css.js";
6
+ import { useCellValues } from "@mdxeditor/gurx";
7
7
  const DiffSourceWrapper = ({ children }) => {
8
- const [error] = corePluginHooks.useEmitterValues("markdownProcessingError");
9
- const [viewMode] = diffSourcePluginHooks.useEmitterValues("viewMode");
8
+ const [error, viewMode] = useCellValues(markdownProcessingError$, viewMode$);
10
9
  return /* @__PURE__ */ React__default.createElement("div", null, error ? /* @__PURE__ */ React__default.createElement("div", { className: styles.markdownParseError }, /* @__PURE__ */ React__default.createElement("p", null, error.error, "."), /* @__PURE__ */ React__default.createElement("p", null, "You can fix the errors in source mode and switch to rich text mode when you are ready.")) : null, /* @__PURE__ */ React__default.createElement("div", { style: { display: viewMode === "rich-text" && error == null ? "block" : "none" } }, children), viewMode === "diff" ? /* @__PURE__ */ React__default.createElement(DiffViewer, null) : null, viewMode === "source" ? /* @__PURE__ */ React__default.createElement(SourceEditor, null) : null);
11
10
  };
12
11
  export {
@@ -1,20 +1,20 @@
1
1
  import React__default from "react";
2
- import { diffSourcePluginHooks } from "./index.js";
3
- import { corePluginHooks } from "../core/index.js";
2
+ import { diffMarkdown$, cmExtensions$ } from "./index.js";
3
+ import { markdown$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
4
4
  import { MergeView } from "@codemirror/merge";
5
5
  import { EditorState } from "@codemirror/state";
6
6
  import { EditorView } from "@codemirror/view";
7
7
  import { COMMON_STATE_CONFIG_EXTENSIONS } from "./SourceEditor.js";
8
+ import { useCellValues, usePublisher, useCellValue } from "@mdxeditor/gurx";
8
9
  const DiffViewer = () => {
9
- const [newText] = corePluginHooks.useEmitterValues("markdown");
10
- const [oldText] = diffSourcePluginHooks.useEmitterValues("diffMarkdown");
11
- const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
10
+ const [newText, oldText] = useCellValues(markdown$, diffMarkdown$);
11
+ const updateMarkdown = usePublisher(markdownSourceEditorValue$);
12
12
  return /* @__PURE__ */ React__default.createElement(CmMergeView, { oldMarkdown: oldText, newMarkdown: newText, onUpdate: updateMarkdown });
13
13
  };
14
14
  const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
15
15
  const cmMergeViewRef = React__default.useRef(null);
16
- const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
17
- const triggerOnBlur = corePluginHooks.usePublisher("onBlur");
16
+ const cmExtensions = useCellValue(cmExtensions$);
17
+ const triggerOnBlur = usePublisher(onBlur$);
18
18
  const ref = React__default.useCallback(
19
19
  (el) => {
20
20
  var _a;
@@ -4,8 +4,9 @@ import { lineNumbers, EditorView } from "@codemirror/view";
4
4
  import { basicLight } from "cm6-theme-basic-light";
5
5
  import { basicSetup } from "codemirror";
6
6
  import React__default from "react";
7
- import { diffSourcePluginHooks } from "./index.js";
8
- import { corePluginHooks } from "../core/index.js";
7
+ import { cmExtensions$ } from "./index.js";
8
+ import { markdown$, readOnly$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
9
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
9
10
  const COMMON_STATE_CONFIG_EXTENSIONS = [
10
11
  basicSetup,
11
12
  basicLight,
@@ -14,10 +15,9 @@ const COMMON_STATE_CONFIG_EXTENSIONS = [
14
15
  EditorView.lineWrapping
15
16
  ];
16
17
  const SourceEditor = () => {
17
- const [markdown2, readOnly] = corePluginHooks.useEmitterValues("markdown", "readOnly");
18
- const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
19
- const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
20
- const triggerOnBlur = corePluginHooks.usePublisher("onBlur");
18
+ const [markdown2, readOnly, cmExtensions] = useCellValues(markdown$, readOnly$, cmExtensions$);
19
+ const updateMarkdown = usePublisher(markdownSourceEditorValue$);
20
+ const triggerOnBlur = usePublisher(onBlur$);
21
21
  const editorViewRef = React__default.useRef(null);
22
22
  const ref = React__default.useCallback(
23
23
  (el) => {
@@ -1,59 +1,24 @@
1
- import { coreSystem } from "../core/index.js";
1
+ import { addEditorWrapper$, viewMode$ } from "../core/index.js";
2
2
  import { DiffSourceWrapper } from "./DiffSourceWrapper.js";
3
- import { system } from "../../gurx/realmFactory.js";
4
- import { realmPlugin } from "../../gurx/react.js";
5
- const diffSourceSystem = system(
6
- (r, [{ markdown, setMarkdown, markdownSignal }]) => {
7
- const diffMarkdown = r.node("");
8
- const markdownSourceEditorValue = r.node("");
9
- const cmExtensions = r.node([]);
10
- r.link(markdown, markdownSourceEditorValue);
11
- r.link(markdownSourceEditorValue, markdownSignal);
12
- const viewMode = r.node("rich-text");
13
- r.sub(
14
- r.pipe(
15
- viewMode,
16
- r.o.scan(
17
- (prev, next) => {
18
- return {
19
- current: prev.next,
20
- next
21
- };
22
- },
23
- { current: "rich-text", next: "rich-text" }
24
- ),
25
- r.o.withLatestFrom(markdownSourceEditorValue)
26
- ),
27
- ([{ current }, markdownSourceFromEditor]) => {
28
- if (current === "source" || current === "diff") {
29
- r.pub(setMarkdown, markdownSourceFromEditor);
30
- }
31
- }
32
- );
33
- return { viewMode, diffMarkdown, markdownSourceEditorValue, cmExtensions };
34
- },
35
- [coreSystem]
36
- );
37
- const [
38
- /** @internal */
39
- diffSourcePlugin,
40
- /** @internal */
41
- diffSourcePluginHooks
42
- ] = realmPlugin({
43
- id: "diff-source",
44
- systemSpec: diffSourceSystem,
45
- applyParamsToSystem: (r, params) => {
46
- r.pubKey("diffMarkdown", (params == null ? void 0 : params.diffMarkdown) || "");
3
+ import { Cell } from "@mdxeditor/gurx";
4
+ import { realmPlugin } from "../../RealmWithPlugins.js";
5
+ const diffMarkdown$ = Cell("");
6
+ const cmExtensions$ = Cell([]);
7
+ const diffSourcePlugin = realmPlugin({
8
+ update: (r, params) => {
9
+ r.pub(diffMarkdown$, (params == null ? void 0 : params.diffMarkdown) || "");
47
10
  },
48
11
  init(r, params) {
49
- r.pubKey("diffMarkdown", (params == null ? void 0 : params.diffMarkdown) || "");
50
- r.pubKey("cmExtensions", (params == null ? void 0 : params.codeMirrorExtensions) || []);
51
- r.pubKey("addEditorWrapper", DiffSourceWrapper);
52
- r.pubKey("viewMode", (params == null ? void 0 : params.viewMode) || "rich-text");
12
+ r.pubIn({
13
+ [diffMarkdown$]: (params == null ? void 0 : params.diffMarkdown) || "",
14
+ [cmExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) || [],
15
+ [addEditorWrapper$]: DiffSourceWrapper,
16
+ [viewMode$]: (params == null ? void 0 : params.viewMode) || "rich-text"
17
+ });
53
18
  }
54
19
  });
55
20
  export {
56
- diffSourcePlugin,
57
- diffSourcePluginHooks,
58
- diffSourceSystem
21
+ cmExtensions$,
22
+ diffMarkdown$,
23
+ diffSourcePlugin
59
24
  };
@@ -7,32 +7,48 @@ var __publicField = (obj, key, value) => {
7
7
  import React__default from "react";
8
8
  import { DecoratorNode } from "lexical";
9
9
  import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
10
- import { directivesPluginHooks } from "./index.js";
10
+ import { directiveDescriptors$ } from "./index.js";
11
11
  import { voidEmitter } from "../../utils/voidEmitter.js";
12
+ import { useCellValues } from "@mdxeditor/gurx";
12
13
  let GENERATION = 0;
13
14
  class DirectiveNode extends DecoratorNode {
15
+ /**
16
+ * Constructs a new {@link DirectiveNode} with the specified MDAST directive node as the object to edit.
17
+ */
14
18
  constructor(mdastNode, key) {
15
19
  super(key);
20
+ /** @internal */
16
21
  __publicField(this, "__mdastNode");
22
+ /** @internal */
17
23
  __publicField(this, "__focusEmitter", voidEmitter());
24
+ /**
25
+ * Focuses the direcitive editor.
26
+ */
18
27
  __publicField(this, "select", () => {
19
28
  this.__focusEmitter.publish();
20
29
  });
21
30
  this.__mdastNode = mdastNode;
22
31
  this.generation = GENERATION++;
23
32
  }
33
+ /** @internal */
24
34
  static getType() {
25
35
  return "directive";
26
36
  }
37
+ /** @internal */
27
38
  static clone(node) {
28
39
  return new DirectiveNode(structuredClone(node.__mdastNode), node.__key);
29
40
  }
41
+ /** @internal */
30
42
  static importJSON(serializedNode) {
31
43
  return $createDirectiveNode(serializedNode.mdastNode);
32
44
  }
45
+ /**
46
+ * Returns the MDAST node that is being edited.
47
+ */
33
48
  getMdastNode() {
34
49
  return this.__mdastNode;
35
50
  }
51
+ /** @internal */
36
52
  exportJSON() {
37
53
  return {
38
54
  mdastNode: structuredClone(this.__mdastNode),
@@ -40,15 +56,21 @@ class DirectiveNode extends DecoratorNode {
40
56
  version: 1
41
57
  };
42
58
  }
59
+ /** @internal */
43
60
  createDOM() {
44
61
  return document.createElement(this.__mdastNode.type === "textDirective" ? "span" : "div");
45
62
  }
63
+ /** @internal */
46
64
  updateDOM() {
47
65
  return false;
48
66
  }
67
+ /**
68
+ * Sets a new MDAST node to edit.
69
+ */
49
70
  setMdastNode(mdastNode) {
50
71
  this.getWritable().__mdastNode = mdastNode;
51
72
  }
73
+ /** @internal */
52
74
  decorate(parentEditor, config) {
53
75
  return /* @__PURE__ */ React__default.createElement(
54
76
  DirectiveEditorContainer,
@@ -61,23 +83,25 @@ class DirectiveNode extends DecoratorNode {
61
83
  }
62
84
  );
63
85
  }
86
+ /** @internal */
64
87
  isInline() {
65
88
  return this.__mdastNode.type === "textDirective";
66
89
  }
90
+ /** @internal */
67
91
  isKeyboardSelectable() {
68
92
  return true;
69
93
  }
70
94
  }
71
- function DirectiveEditorContainer(props) {
95
+ const DirectiveEditorContainer = (props) => {
72
96
  const { mdastNode } = props;
73
- const [directiveDescriptors] = directivesPluginHooks.useEmitterValues("directiveDescriptors");
97
+ const [directiveDescriptors] = useCellValues(directiveDescriptors$);
74
98
  const descriptor = directiveDescriptors.find((descriptor2) => descriptor2.testNode(mdastNode));
75
99
  if (!descriptor) {
76
100
  throw new Error(`No descriptor found for directive ${mdastNode.name}`);
77
101
  }
78
102
  const Editor = descriptor.Editor;
79
103
  return /* @__PURE__ */ React__default.createElement(NestedEditorsContext.Provider, { value: props }, /* @__PURE__ */ React__default.createElement(Editor, { descriptor, mdastNode, lexicalNode: props.lexicalNode, parentEditor: props.parentEditor }));
80
- }
104
+ };
81
105
  function $createDirectiveNode(mdastNode, key) {
82
106
  return new DirectiveNode(mdastNode, key);
83
107
  }
@@ -87,6 +111,5 @@ function $isDirectiveNode(node) {
87
111
  export {
88
112
  $createDirectiveNode,
89
113
  $isDirectiveNode,
90
- DirectiveEditorContainer,
91
114
  DirectiveNode
92
115
  };
@@ -1,53 +1,46 @@
1
- import { coreSystem } from "../core/index.js";
2
- import { directive } from "micromark-extension-directive";
1
+ import { realmPlugin } from "../../RealmWithPlugins.js";
2
+ import { insertDecoratorNode$, addMdastExtension$, addSyntaxExtension$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addToMarkdownExtension$ } from "../core/index.js";
3
+ import { Cell, Signal, map } from "@mdxeditor/gurx";
3
4
  import { directiveFromMarkdown, directiveToMarkdown } from "mdast-util-directive";
5
+ import { directive } from "micromark-extension-directive";
4
6
  import { $createDirectiveNode, DirectiveNode } from "./DirectiveNode.js";
7
+ import { $isDirectiveNode } from "./DirectiveNode.js";
5
8
  import { DirectiveVisitor } from "./DirectiveVisitor.js";
6
9
  import { MdastDirectiveVisitor } from "./MdastDirectiveVisitor.js";
7
- import { system } from "../../gurx/realmFactory.js";
8
- import { realmPlugin } from "../../gurx/react.js";
9
- const directivesSystem = system(
10
- (r, [{ insertDecoratorNode }]) => {
11
- const directiveDescriptors = r.node([]);
12
- const insertDirective = r.node();
13
- r.link(
14
- r.pipe(
15
- insertDirective,
16
- r.o.map((payload) => {
17
- return () => $createDirectiveNode({ children: [], ...payload });
18
- })
19
- ),
20
- insertDecoratorNode
21
- );
22
- return {
23
- directiveDescriptors,
24
- insertDirective
25
- };
26
- },
27
- [coreSystem]
28
- );
29
- const [
30
- /** @internal */
31
- directivesPlugin,
32
- /** @internal */
33
- directivesPluginHooks
34
- ] = realmPlugin({
35
- id: "directives",
36
- systemSpec: directivesSystem,
37
- applyParamsToSystem: (realm, params) => {
38
- realm.pubKey("directiveDescriptors", (params == null ? void 0 : params.directiveDescriptors) || []);
10
+ const directiveDescriptors$ = Cell([]);
11
+ const insertDirective$ = Signal((r) => {
12
+ r.link(
13
+ r.pipe(
14
+ insertDirective$,
15
+ map((payload) => {
16
+ return () => $createDirectiveNode({ children: [], ...payload });
17
+ })
18
+ ),
19
+ insertDecoratorNode$
20
+ );
21
+ });
22
+ const directivesPlugin = realmPlugin({
23
+ update: (realm, params) => {
24
+ realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors) || []);
39
25
  },
40
- init: (realm, _) => {
41
- realm.pubKey("addMdastExtension", directiveFromMarkdown);
42
- realm.pubKey("addSyntaxExtension", directive());
43
- realm.pubKey("addImportVisitor", MdastDirectiveVisitor);
44
- realm.pubKey("addLexicalNode", DirectiveNode);
45
- realm.pubKey("addExportVisitor", DirectiveVisitor);
46
- realm.pubKey("addToMarkdownExtension", directiveToMarkdown);
26
+ init: (realm) => {
27
+ realm.pubIn({
28
+ // import
29
+ [addMdastExtension$]: directiveFromMarkdown(),
30
+ [addSyntaxExtension$]: directive(),
31
+ [addImportVisitor$]: MdastDirectiveVisitor,
32
+ // export
33
+ [addLexicalNode$]: DirectiveNode,
34
+ [addExportVisitor$]: DirectiveVisitor,
35
+ [addToMarkdownExtension$]: directiveToMarkdown()
36
+ });
47
37
  }
48
38
  });
49
39
  export {
40
+ $createDirectiveNode,
41
+ $isDirectiveNode,
42
+ DirectiveNode,
43
+ directiveDescriptors$,
50
44
  directivesPlugin,
51
- directivesPluginHooks,
52
- directivesSystem
45
+ insertDirective$
53
46
  };
@@ -3,18 +3,19 @@ import classNames from "classnames";
3
3
  import YamlParser from "js-yaml";
4
4
  import React__default from "react";
5
5
  import { useForm, useFieldArray } from "react-hook-form";
6
- import { frontmatterPluginHooks } from "./index.js";
6
+ import { frontmatterDialogOpen$, removeFrontmatter$ } from "./index.js";
7
7
  import styles from "../../styles/ui.module.css.js";
8
- import { corePluginHooks } from "../core/index.js";
8
+ import { readOnly$, editorRootElementRef$, iconComponentFor$ } from "../core/index.js";
9
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
9
10
  const FrontmatterEditor = ({ yaml, onChange }) => {
10
- const [readOnly, editorRootElementRef, iconComponentFor] = corePluginHooks.useEmitterValues(
11
- "readOnly",
12
- "editorRootElementRef",
13
- "iconComponentFor"
11
+ const [readOnly, editorRootElementRef, iconComponentFor, frontmatterDialogOpen] = useCellValues(
12
+ readOnly$,
13
+ editorRootElementRef$,
14
+ iconComponentFor$,
15
+ frontmatterDialogOpen$
14
16
  );
15
- const [frontmatterDialogOpen] = frontmatterPluginHooks.useEmitterValues("frontmatterDialogOpen");
16
- const setFrontmatterDialogOpen = frontmatterPluginHooks.usePublisher("frontmatterDialogOpen");
17
- const removeFrontmatter = frontmatterPluginHooks.usePublisher("removeFrontmatter");
17
+ const setFrontmatterDialogOpen = usePublisher(frontmatterDialogOpen$);
18
+ const removeFrontmatter = usePublisher(removeFrontmatter$);
18
19
  const yamlConfig = React__default.useMemo(() => {
19
20
  if (!yaml) {
20
21
  return [];
@@ -33,16 +34,19 @@ const FrontmatterEditor = ({ yaml, onChange }) => {
33
34
  const onSubmit = React__default.useCallback(
34
35
  ({ yamlConfig: yamlConfig2 }) => {
35
36
  if (yamlConfig2.length === 0) {
36
- removeFrontmatter(true);
37
+ removeFrontmatter();
37
38
  setFrontmatterDialogOpen(false);
38
39
  return;
39
40
  }
40
- const yaml2 = yamlConfig2.reduce((acc, { key, value }) => {
41
- if (key && value) {
42
- acc[key] = value;
43
- }
44
- return acc;
45
- }, {});
41
+ const yaml2 = yamlConfig2.reduce(
42
+ (acc, { key, value }) => {
43
+ if (key && value) {
44
+ acc[key] = value;
45
+ }
46
+ return acc;
47
+ },
48
+ {}
49
+ );
46
50
  onChange(YamlParser.dump(yaml2).trim());
47
51
  setFrontmatterDialogOpen(false);
48
52
  },
@@ -1,76 +1,65 @@
1
- import { coreSystem } from "../core/index.js";
1
+ import { realmPlugin } from "../../RealmWithPlugins.js";
2
+ import { rootEditor$, createRootEditorSubscription$, addMdastExtension$, addSyntaxExtension$, addLexicalNode$, addImportVisitor$, addExportVisitor$, addToMarkdownExtension$ } from "../core/index.js";
3
+ import { Cell, Action, withLatestFrom } from "@mdxeditor/gurx";
4
+ import { $getRoot } from "lexical";
2
5
  import { frontmatterFromMarkdown, frontmatterToMarkdown } from "mdast-util-frontmatter";
3
6
  import { frontmatter } from "micromark-extension-frontmatter";
4
- import { MdastFrontmatterVisitor } from "./MdastFrontmatterVisitor.js";
5
- import { LexicalFrontmatterVisitor } from "./LexicalFrontmatterVisitor.js";
6
- import { $getRoot } from "lexical";
7
7
  import { $isFrontmatterNode, $createFrontmatterNode, FrontmatterNode } from "./FrontmatterNode.js";
8
- import { system } from "../../gurx/realmFactory.js";
9
- import { realmPlugin } from "../../gurx/react.js";
10
- const frontmatterSystem = system(
11
- (r, [{ rootEditor, createRootEditorSubscription }]) => {
12
- const insertFrontmatter = r.node();
13
- const removeFrontmatter = r.node();
14
- const frontmatterDialogOpen = r.node(false);
15
- const hasFrontmatter = r.node(false);
16
- r.sub(r.pipe(insertFrontmatter, r.o.withLatestFrom(rootEditor)), ([, theEditor]) => {
17
- theEditor == null ? void 0 : theEditor.update(() => {
18
- const firstItem = $getRoot().getFirstChild();
19
- if (!$isFrontmatterNode(firstItem)) {
20
- const fmNode = $createFrontmatterNode('"": ""');
21
- if (firstItem) {
22
- firstItem.insertBefore(fmNode);
23
- } else {
24
- $getRoot().append(fmNode);
25
- }
8
+ import { LexicalFrontmatterVisitor } from "./LexicalFrontmatterVisitor.js";
9
+ import { MdastFrontmatterVisitor } from "./MdastFrontmatterVisitor.js";
10
+ const frontmatterDialogOpen$ = Cell(false);
11
+ const insertFrontmatter$ = Action((r) => {
12
+ r.sub(r.pipe(insertFrontmatter$, withLatestFrom(rootEditor$)), ([, rootEditor]) => {
13
+ rootEditor == null ? void 0 : rootEditor.update(() => {
14
+ const firstItem = $getRoot().getFirstChild();
15
+ if (!$isFrontmatterNode(firstItem)) {
16
+ const fmNode = $createFrontmatterNode('"": ""');
17
+ if (firstItem) {
18
+ firstItem.insertBefore(fmNode);
19
+ } else {
20
+ $getRoot().append(fmNode);
26
21
  }
27
- });
28
- r.pub(frontmatterDialogOpen, true);
22
+ }
29
23
  });
30
- r.sub(r.pipe(removeFrontmatter, r.o.withLatestFrom(rootEditor)), ([, theEditor]) => {
31
- theEditor == null ? void 0 : theEditor.update(() => {
32
- const firstItem = $getRoot().getFirstChild();
33
- if ($isFrontmatterNode(firstItem)) {
34
- firstItem.remove();
35
- }
36
- });
37
- r.pub(frontmatterDialogOpen, false);
24
+ r.pub(frontmatterDialogOpen$, true);
25
+ });
26
+ });
27
+ const removeFrontmatter$ = Action((r) => {
28
+ r.sub(r.pipe(removeFrontmatter$, withLatestFrom(rootEditor$)), ([, rootEditor]) => {
29
+ rootEditor == null ? void 0 : rootEditor.update(() => {
30
+ const firstItem = $getRoot().getFirstChild();
31
+ if ($isFrontmatterNode(firstItem)) {
32
+ firstItem.remove();
33
+ }
38
34
  });
39
- r.pub(createRootEditorSubscription, (rootEditor2) => {
40
- return rootEditor2.registerUpdateListener(({ editorState }) => {
41
- editorState.read(() => {
42
- r.pub(hasFrontmatter, $isFrontmatterNode($getRoot().getFirstChild()));
43
- });
35
+ r.pub(frontmatterDialogOpen$, false);
36
+ });
37
+ });
38
+ const hasFrontmatter$ = Cell(false, (r) => {
39
+ r.pub(createRootEditorSubscription$, (rootEditor) => {
40
+ return rootEditor.registerUpdateListener(({ editorState }) => {
41
+ editorState.read(() => {
42
+ r.pub(hasFrontmatter$, $isFrontmatterNode($getRoot().getFirstChild()));
44
43
  });
45
44
  });
46
- return {
47
- insertFrontmatter,
48
- removeFrontmatter,
49
- hasFrontmatter,
50
- frontmatterDialogOpen
51
- };
52
- },
53
- [coreSystem]
54
- );
55
- const [
56
- /** @internal */
57
- frontmatterPlugin,
58
- /** @internal */
59
- frontmatterPluginHooks
60
- ] = realmPlugin({
61
- id: "frontmatter",
62
- systemSpec: frontmatterSystem,
45
+ });
46
+ });
47
+ const frontmatterPlugin = realmPlugin({
63
48
  init: (realm) => {
64
- realm.pubKey("addMdastExtension", frontmatterFromMarkdown("yaml"));
65
- realm.pubKey("addSyntaxExtension", frontmatter());
66
- realm.pubKey("addLexicalNode", FrontmatterNode);
67
- realm.pubKey("addImportVisitor", MdastFrontmatterVisitor);
68
- realm.pubKey("addExportVisitor", LexicalFrontmatterVisitor);
69
- realm.pubKey("addToMarkdownExtension", frontmatterToMarkdown("yaml"));
49
+ realm.pubIn({
50
+ [addMdastExtension$]: frontmatterFromMarkdown("yaml"),
51
+ [addSyntaxExtension$]: frontmatter(),
52
+ [addLexicalNode$]: FrontmatterNode,
53
+ [addImportVisitor$]: MdastFrontmatterVisitor,
54
+ [addExportVisitor$]: LexicalFrontmatterVisitor,
55
+ [addToMarkdownExtension$]: frontmatterToMarkdown("yaml")
56
+ });
70
57
  }
71
58
  });
72
59
  export {
60
+ frontmatterDialogOpen$,
73
61
  frontmatterPlugin,
74
- frontmatterPluginHooks,
75
- frontmatterSystem
62
+ hasFrontmatter$,
63
+ insertFrontmatter$,
64
+ removeFrontmatter$
76
65
  };