@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,9 +1,9 @@
1
- import { coreSystem } from "../core/index.js";
1
+ import { currentSelection$, activeEditor$, rootEditor$, addActivePlugin$, addMdastExtension$, addSyntaxExtension$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addToMarkdownExtension$, addComposerChild$, addNestedEditorChild$ } from "../core/index.js";
2
2
  import { MdastListVisitor } from "./MdastListVisitor.js";
3
3
  import { MdastListItemVisitor } from "./MdastListItemVisitor.js";
4
4
  import { LexicalListVisitor } from "./LexicalListVisitor.js";
5
5
  import { LexicalListItemVisitor } from "./LexicalListItemVisitor.js";
6
- import { $isListNode, ListNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_CHECK_LIST_COMMAND, REMOVE_LIST_COMMAND, ListItemNode, $getListDepth, $isListItemNode } from "@lexical/list";
6
+ import { $isListNode, ListNode, ListItemNode, $getListDepth, $isListItemNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_CHECK_LIST_COMMAND, REMOVE_LIST_COMMAND } from "@lexical/list";
7
7
  import { $isRootOrShadowRoot, INDENT_CONTENT_COMMAND, COMMAND_PRIORITY_CRITICAL, $getSelection, $isRangeSelection, $isElementNode } from "lexical";
8
8
  import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin.js";
9
9
  import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin.js";
@@ -11,75 +11,60 @@ import { ListPlugin } from "@lexical/react/LexicalListPlugin.js";
11
11
  import { $findMatchingParent, $getNearestNodeOfType } from "@lexical/utils";
12
12
  import { gfmTaskListItem } from "micromark-extension-gfm-task-list-item";
13
13
  import { gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown } from "mdast-util-gfm-task-list-item";
14
- import { system } from "../../gurx/realmFactory.js";
15
- import { realmPlugin } from "../../gurx/react.js";
14
+ import { Cell, withLatestFrom, Signal } from "@mdxeditor/gurx";
15
+ import { realmPlugin } from "../../RealmWithPlugins.js";
16
16
  const ListTypeCommandMap = /* @__PURE__ */ new Map([
17
17
  ["number", INSERT_ORDERED_LIST_COMMAND],
18
18
  ["bullet", INSERT_UNORDERED_LIST_COMMAND],
19
19
  ["check", INSERT_CHECK_LIST_COMMAND],
20
20
  ["", REMOVE_LIST_COMMAND]
21
21
  ]);
22
- const listsSystem = system(
23
- (r, [{ activeEditor, currentSelection }]) => {
24
- const currentListType = r.node("");
25
- const applyListType = r.node();
26
- r.sub(r.pipe(applyListType, r.o.withLatestFrom(activeEditor)), ([listType, theEditor]) => {
27
- theEditor == null ? void 0 : theEditor.dispatchCommand(ListTypeCommandMap.get(listType), void 0);
22
+ const currentListType$ = Cell("", (r) => {
23
+ r.sub(r.pipe(currentSelection$, withLatestFrom(activeEditor$)), ([selection, theEditor]) => {
24
+ if (!selection || !theEditor) {
25
+ return;
26
+ }
27
+ const anchorNode = selection.anchor.getNode();
28
+ let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
29
+ const parent = e.getParent();
30
+ return parent !== null && $isRootOrShadowRoot(parent);
28
31
  });
29
- r.sub(r.pipe(currentSelection, r.o.withLatestFrom(activeEditor)), ([selection, theEditor]) => {
30
- if (!selection || !theEditor) {
31
- return;
32
- }
33
- const anchorNode = selection.anchor.getNode();
34
- let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
35
- const parent = e.getParent();
36
- return parent !== null && $isRootOrShadowRoot(parent);
37
- });
38
- if (element === null) {
39
- element = anchorNode.getTopLevelElementOrThrow();
40
- }
41
- const elementKey = element.getKey();
42
- const elementDOM = theEditor.getElementByKey(elementKey);
43
- if (elementDOM !== null) {
44
- if ($isListNode(element)) {
45
- const parentList = $getNearestNodeOfType(anchorNode, ListNode);
46
- const type = parentList ? parentList.getListType() : element.getListType();
47
- r.pub(currentListType, type);
48
- } else {
49
- r.pub(currentListType, null);
50
- }
32
+ if (element === null) {
33
+ element = anchorNode.getTopLevelElementOrThrow();
34
+ }
35
+ const elementKey = element.getKey();
36
+ const elementDOM = theEditor.getElementByKey(elementKey);
37
+ if (elementDOM !== null) {
38
+ if ($isListNode(element)) {
39
+ const parentList = $getNearestNodeOfType(anchorNode, ListNode);
40
+ const type = parentList ? parentList.getListType() : element.getListType();
41
+ r.pub(currentListType$, type);
42
+ } else {
43
+ r.pub(currentListType$, "");
51
44
  }
52
- });
53
- return { currentListType, applyListType };
54
- },
55
- [coreSystem]
56
- );
57
- const [
58
- /** @internal */
59
- listsPlugin,
60
- /** @internal */
61
- listsPluginHooks
62
- ] = realmPlugin({
63
- id: "lists",
64
- systemSpec: listsSystem,
65
- init: (realm) => {
45
+ }
46
+ });
47
+ });
48
+ const applyListType$ = Signal((r) => {
49
+ r.sub(r.pipe(applyListType$, withLatestFrom(activeEditor$)), ([listType, theEditor]) => {
50
+ theEditor == null ? void 0 : theEditor.dispatchCommand(ListTypeCommandMap.get(listType), void 0);
51
+ });
52
+ });
53
+ const listsPlugin = realmPlugin({
54
+ init(realm) {
66
55
  var _a;
67
- realm.pubKey("addMdastExtension", gfmTaskListItemFromMarkdown);
68
- realm.pubKey("addSyntaxExtension", gfmTaskListItem);
69
- realm.pubKey("addImportVisitor", MdastListVisitor);
70
- realm.pubKey("addImportVisitor", MdastListItemVisitor);
71
- realm.pubKey("addLexicalNode", ListItemNode);
72
- realm.pubKey("addLexicalNode", ListNode);
73
- realm.pubKey("addExportVisitor", LexicalListVisitor);
74
- realm.pubKey("addExportVisitor", LexicalListItemVisitor);
75
- realm.pubKey("addToMarkdownExtension", gfmTaskListItemToMarkdown);
76
- (_a = realm.getKeyValue("rootEditor")) == null ? void 0 : _a.registerCommand(INDENT_CONTENT_COMMAND, () => !isIndentPermitted(7), COMMAND_PRIORITY_CRITICAL);
77
- realm.pubKey("addComposerChild", TabIndentationPlugin);
78
- realm.pubKey("addComposerChild", ListPlugin);
79
- realm.pubKey("addComposerChild", CheckListPlugin);
80
- realm.pubKey("addNestedEditorChild", TabIndentationPlugin);
81
- realm.pubKey("addNestedEditorChild", ListPlugin);
82
- realm.pubKey("addNestedEditorChild", CheckListPlugin);
56
+ (_a = realm.getValue(rootEditor$)) == null ? void 0 : _a.registerCommand(INDENT_CONTENT_COMMAND, () => !isIndentPermitted(7), COMMAND_PRIORITY_CRITICAL);
57
+ realm.pubIn({
58
+ [addActivePlugin$]: "lists",
59
+ [addMdastExtension$]: gfmTaskListItemFromMarkdown(),
60
+ [addSyntaxExtension$]: gfmTaskListItem(),
61
+ [addImportVisitor$]: [MdastListVisitor, MdastListItemVisitor],
62
+ [addLexicalNode$]: [ListItemNode, ListNode],
63
+ [addExportVisitor$]: [LexicalListVisitor, LexicalListItemVisitor],
64
+ [addToMarkdownExtension$]: gfmTaskListItemToMarkdown(),
65
+ [addComposerChild$]: [TabIndentationPlugin, ListPlugin, CheckListPlugin],
66
+ [addNestedEditorChild$]: [TabIndentationPlugin, ListPlugin, CheckListPlugin]
67
+ });
83
68
  }
84
69
  });
85
70
  function getElementNodesInSelection(selection) {
@@ -116,7 +101,7 @@ function isIndentPermitted(maxDepth) {
116
101
  return totalDepth <= maxDepth;
117
102
  }
118
103
  export {
119
- listsPlugin,
120
- listsPluginHooks,
121
- listsSystem
104
+ applyListType$,
105
+ currentListType$,
106
+ listsPlugin
122
107
  };
@@ -1,23 +1,20 @@
1
+ import { realmPlugin } from "../../RealmWithPlugins.js";
1
2
  import { QUOTE, LINK, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST, CODE, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE } from "@lexical/markdown";
2
3
  import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin.js";
4
+ import { HeadingNode, $isHeadingNode, $createHeadingNode } from "@lexical/rich-text";
3
5
  import React__default from "react";
4
6
  import { CodeBlockNode, $createCodeBlockNode } from "../codeblock/CodeBlockNode.js";
5
- import { coreSystem } from "../core/index.js";
6
- import { HeadingNode, $isHeadingNode, $createHeadingNode } from "@lexical/rich-text";
7
- import { realmPlugin } from "../../gurx/react.js";
8
- import { system } from "../../gurx/realmFactory.js";
9
- const [markdownShortcutPlugin] = realmPlugin({
10
- id: "markdown-shortcut",
11
- dependencies: [],
12
- systemSpec: system((_) => ({}), [coreSystem]),
13
- init: (realm, _, pluginIds) => {
14
- const allowedHeadingLevels = pluginIds.includes("headings") ? (
15
- // @ts-expect-error we query the realm for the allowed heading levels
16
- realm.getKeyValue("allowedHeadingLevels")
17
- ) : [];
7
+ import { activePlugins$, addComposerChild$, addNestedEditorChild$ } from "../core/index.js";
8
+ import { allowedHeadingLevels$ } from "../headings/index.js";
9
+ const markdownShortcutPlugin = realmPlugin({
10
+ init(realm) {
11
+ const pluginIds = realm.getValue(activePlugins$);
12
+ const allowedHeadingLevels = pluginIds.includes("headings") ? realm.getValue(allowedHeadingLevels$) : [];
18
13
  const transformers = pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels);
19
- realm.pubKey("addComposerChild", () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers }));
20
- realm.pubKey("addNestedEditorChild", () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers }));
14
+ realm.pubIn({
15
+ [addComposerChild$]: () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers }),
16
+ [addNestedEditorChild$]: () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers })
17
+ });
21
18
  }
22
19
  });
23
20
  const createBlockNode = (createNode) => {
@@ -1,26 +1,18 @@
1
- import { coreSystem } from "../core/index.js";
2
1
  import { QuoteNode } from "@lexical/rich-text";
3
2
  import { MdastBlockQuoteVisitor } from "./MdastBlockQuoteVisitor.js";
4
3
  import { LexicalQuoteVisitor } from "./LexicalQuoteVisitor.js";
5
- import { realmPlugin } from "../../gurx/react.js";
6
- import { system } from "../../gurx/realmFactory.js";
7
- const [
8
- /** @internal */
9
- quotePlugin,
10
- /** @internal */
11
- quotePluginHooks
12
- ] = realmPlugin({
13
- id: "quote",
14
- systemSpec: system(() => {
15
- return {};
16
- }, [coreSystem]),
17
- init: (realm) => {
18
- realm.pubKey("addImportVisitor", MdastBlockQuoteVisitor);
19
- realm.pubKey("addLexicalNode", QuoteNode);
20
- realm.pubKey("addExportVisitor", LexicalQuoteVisitor);
4
+ import { realmPlugin } from "../../RealmWithPlugins.js";
5
+ import { addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$ } from "../core/index.js";
6
+ const quotePlugin = realmPlugin({
7
+ init(realm) {
8
+ realm.pubIn({
9
+ [addActivePlugin$]: "quote",
10
+ [addImportVisitor$]: MdastBlockQuoteVisitor,
11
+ [addLexicalNode$]: QuoteNode,
12
+ [addExportVisitor$]: LexicalQuoteVisitor
13
+ });
21
14
  }
22
15
  });
23
16
  export {
24
- quotePlugin,
25
- quotePluginHooks
17
+ quotePlugin
26
18
  };
@@ -2,7 +2,8 @@ import React__default from "react";
2
2
  import { useCodeMirrorRef } from "./useCodeMirrorRef.js";
3
3
  import { SandpackProvider, SandpackLayout, SandpackCodeEditor, SandpackPreview, useSandpack } from "@codesandbox/sandpack-react";
4
4
  import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
5
- import { corePluginHooks } from "../core/index.js";
5
+ import { readOnly$ } from "../core/index.js";
6
+ import { useCellValue } from "@mdxeditor/gurx";
6
7
  const CodeUpdateEmitter = ({ onChange, snippetFileName }) => {
7
8
  const { sandpack } = useSandpack();
8
9
  onChange(sandpack.files[snippetFileName].code);
@@ -10,7 +11,7 @@ const CodeUpdateEmitter = ({ onChange, snippetFileName }) => {
10
11
  };
11
12
  const SandpackEditor = ({ nodeKey, code, focusEmitter, preset }) => {
12
13
  const codeMirrorRef = useCodeMirrorRef(nodeKey, "sandpack", "jsx", focusEmitter);
13
- const [readOnly] = corePluginHooks.useEmitterValues("readOnly");
14
+ const readOnly = useCellValue(readOnly$);
14
15
  const { setCode } = useCodeBlockEditorContext();
15
16
  return /* @__PURE__ */ React__default.createElement(
16
17
  SandpackProvider,
@@ -1,9 +1,8 @@
1
1
  import React__default from "react";
2
- import { coreSystem } from "../core/index.js";
3
- import { codeBlockSystem } from "../codeblock/index.js";
2
+ import { insertCodeBlock$, appendCodeBlockEditorDescriptor$ } from "../codeblock/index.js";
4
3
  import { SandpackEditor } from "./SandpackEditor.js";
5
- import { system } from "../../gurx/realmFactory.js";
6
- import { realmPlugin } from "../../gurx/react.js";
4
+ import { Cell, Signal, withLatestFrom, map, useCellValue } from "@mdxeditor/gurx";
5
+ import { realmPlugin } from "../../RealmWithPlugins.js";
7
6
  const defaultSnippetContent = `
8
7
  export default function App() {
9
8
  return (
@@ -29,54 +28,36 @@ const defaultSandpackConfig = {
29
28
  }
30
29
  ]
31
30
  };
32
- const sandpackSystem = system(
33
- (r, [, { insertCodeBlock }]) => {
34
- const sandpackConfig = r.node(defaultSandpackConfig);
35
- const insertSandpack = r.node();
36
- r.link(
37
- r.pipe(
38
- insertSandpack,
39
- r.o.withLatestFrom(sandpackConfig),
40
- r.o.map(([presetName, sandpackConfig2]) => {
41
- const preset = presetName ? sandpackConfig2.presets.find((preset2) => preset2.name === presetName) : sandpackConfig2.presets.find((preset2) => preset2.name == sandpackConfig2.defaultPreset);
42
- if (!preset) {
43
- throw new Error(`No sandpack preset found with name ${presetName}`);
44
- }
45
- return {
46
- code: preset.initialSnippetContent || "",
47
- language: preset.snippetLanguage || "jsx",
48
- meta: preset.meta
49
- };
50
- })
51
- ),
52
- insertCodeBlock
53
- );
54
- return {
55
- insertSandpack,
56
- sandpackConfig
57
- };
58
- },
59
- [coreSystem, codeBlockSystem]
60
- );
61
- const [
62
- /** @internal */
63
- sandpackPlugin,
64
- /** @internal */
65
- sandpackPluginHooks
66
- ] = realmPlugin({
67
- id: "sandpack",
68
- systemSpec: sandpackSystem,
69
- applyParamsToSystem(r, params) {
70
- r.pubKey("sandpackConfig", params.sandpackConfig);
71
- },
72
- init(r) {
73
- r.pubKey("appendCodeBlockEditorDescriptor", {
31
+ const sandpackConfig$ = Cell(defaultSandpackConfig);
32
+ const insertSandpack$ = Signal((r) => {
33
+ r.link(
34
+ r.pipe(
35
+ insertSandpack$,
36
+ withLatestFrom(sandpackConfig$),
37
+ map(([presetName, sandpackConfig]) => {
38
+ const preset = presetName ? sandpackConfig.presets.find((preset2) => preset2.name === presetName) : sandpackConfig.presets.find((preset2) => preset2.name == sandpackConfig.defaultPreset);
39
+ if (!preset) {
40
+ throw new Error(`No sandpack preset found with name ${presetName}`);
41
+ }
42
+ return {
43
+ code: preset.initialSnippetContent || "",
44
+ language: preset.snippetLanguage || "jsx",
45
+ meta: preset.meta
46
+ };
47
+ })
48
+ ),
49
+ insertCodeBlock$
50
+ );
51
+ });
52
+ const sandpackPlugin = realmPlugin({
53
+ init(realm) {
54
+ realm.pub(appendCodeBlockEditorDescriptor$, {
74
55
  match(_language, meta) {
75
56
  return meta == null ? void 0 : meta.startsWith("live");
76
57
  },
77
58
  priority: 1,
78
59
  Editor(props) {
79
- const [config] = sandpackPluginHooks.useEmitterValues("sandpackConfig");
60
+ const config = useCellValue(sandpackConfig$);
80
61
  const preset = config.presets.find((preset2) => preset2.meta === props.meta);
81
62
  if (!preset) {
82
63
  throw new Error(`No sandpack preset found with ${props.meta}`);
@@ -84,10 +65,13 @@ const [
84
65
  return /* @__PURE__ */ React__default.createElement(SandpackEditor, { ...props, preset });
85
66
  }
86
67
  });
68
+ },
69
+ update(realm, params) {
70
+ realm.pub(sandpackConfig$, params == null ? void 0 : params.sandpackConfig);
87
71
  }
88
72
  });
89
73
  export {
90
- sandpackPlugin,
91
- sandpackPluginHooks,
92
- sandpackSystem
74
+ insertSandpack$,
75
+ sandpackConfig$,
76
+ sandpackPlugin
93
77
  };
@@ -1,10 +1,11 @@
1
1
  import { $getNodeByKey, $createParagraphNode } from "lexical";
2
2
  import React__default from "react";
3
3
  import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
4
- import { corePluginHooks } from "../core/index.js";
4
+ import { activeEditor$, editorInFocus$ } from "../core/index.js";
5
+ import { useCellValue, usePublisher } from "@mdxeditor/gurx";
5
6
  function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
6
- const [theEditor] = corePluginHooks.useEmitterValues("activeEditor");
7
- const setEditorInFocus = corePluginHooks.usePublisher("editorInFocus");
7
+ const activeEditor = useCellValue(activeEditor$);
8
+ const setEditorInFocus = usePublisher(editorInFocus$);
8
9
  const codeMirrorRef = React__default.useRef(null);
9
10
  const { lexicalNode } = useCodeBlockEditorContext();
10
11
  const atBottom = React__default.useRef(false);
@@ -27,7 +28,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
27
28
  if (!atBottom.current) {
28
29
  atBottom.current = true;
29
30
  } else {
30
- theEditor == null ? void 0 : theEditor.update(() => {
31
+ activeEditor == null ? void 0 : activeEditor.update(() => {
31
32
  var _a2, _b2;
32
33
  const node = $getNodeByKey(nodeKey);
33
34
  const nextSibling = node.getNextSibling();
@@ -50,7 +51,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
50
51
  if (!atTop.current) {
51
52
  atTop.current = true;
52
53
  } else {
53
- theEditor == null ? void 0 : theEditor.update(() => {
54
+ activeEditor == null ? void 0 : activeEditor.update(() => {
54
55
  var _a2, _b2;
55
56
  const node = $getNodeByKey(nodeKey);
56
57
  const previousSibling = node.getPreviousSibling();
@@ -67,7 +68,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
67
68
  e.stopPropagation();
68
69
  }
69
70
  },
70
- [theEditor, nodeKey]
71
+ [activeEditor, nodeKey]
71
72
  );
72
73
  React__default.useEffect(() => {
73
74
  const codeMirror = codeMirrorRef.current;
@@ -15,7 +15,8 @@ import classNames from "classnames";
15
15
  import styles from "../../styles/ui.module.css.js";
16
16
  import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
17
17
  import { uuidv4 } from "../../utils/uuid4.js";
18
- import { corePluginHooks } from "../core/index.js";
18
+ import { iconComponentFor$, readOnly$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, jsxIsAvailable$, rootEditor$, editorRootElementRef$ } from "../core/index.js";
19
+ import { useCellValues } from "@mdxeditor/gurx";
19
20
  const AlignToTailwindClassMap = {
20
21
  center: styles.centeredCell,
21
22
  left: styles.leftAlignedCell,
@@ -23,7 +24,7 @@ const AlignToTailwindClassMap = {
23
24
  };
24
25
  const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
25
26
  const [activeCell, setActiveCell] = React__default.useState(null);
26
- const [iconComponentFor, readOnly] = corePluginHooks.useEmitterValues("iconComponentFor", "readOnly");
27
+ const [iconComponentFor, readOnly] = useCellValues(iconComponentFor$, readOnly$);
27
28
  const getCellKey = React__default.useMemo(() => {
28
29
  return (cell) => {
29
30
  if (!cell.__cacheKey) {
@@ -187,13 +188,13 @@ const Cell = ({ align, ...props }) => {
187
188
  );
188
189
  };
189
190
  const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
190
- const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, rootEditor] = corePluginHooks.useEmitterValues(
191
- "importVisitors",
192
- "exportVisitors",
193
- "usedLexicalNodes",
194
- "jsxComponentDescriptors",
195
- "jsxIsAvailable",
196
- "rootEditor"
191
+ const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, rootEditor] = useCellValues(
192
+ importVisitors$,
193
+ exportVisitors$,
194
+ usedLexicalNodes$,
195
+ jsxComponentDescriptors$,
196
+ jsxIsAvailable$,
197
+ rootEditor$
197
198
  );
198
199
  const [editor] = React__default.useState(() => {
199
200
  const editor2 = createEditor({
@@ -283,8 +284,7 @@ const ColumnEditor = ({
283
284
  colIndex,
284
285
  setActiveCellWithBoundaries
285
286
  }) => {
286
- const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
287
- const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
287
+ const [editorRootElementRef, iconComponentFor] = useCellValues(editorRootElementRef$, iconComponentFor$);
288
288
  const insertColumnAt = React__default.useCallback(
289
289
  (colIndex2) => {
290
290
  parentEditor.update(() => {
@@ -351,8 +351,7 @@ const RowEditor = ({
351
351
  rowIndex,
352
352
  setActiveCellWithBoundaries
353
353
  }) => {
354
- const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
355
- const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
354
+ const [editorRootElementRef, iconComponentFor] = useCellValues(editorRootElementRef$, iconComponentFor$);
356
355
  const insertRowAt = React__default.useCallback(
357
356
  (rowIndex2) => {
358
357
  parentEditor.update(() => {
@@ -21,21 +21,31 @@ function coordinatesEmitter() {
21
21
  };
22
22
  }
23
23
  class TableNode extends DecoratorNode {
24
+ /**
25
+ * Constructs a new {@link TableNode} with the specified MDAST table node as the object to edit.
26
+ * See {@link https://github.com/micromark/micromark-extension-gfm-table | micromark/micromark-extension-gfm-table} for more information on the MDAST table node.
27
+ */
24
28
  constructor(mdastNode, key) {
25
29
  super(key);
30
+ /** @internal */
26
31
  __publicField(this, "__mdastNode");
32
+ /** @internal */
27
33
  __publicField(this, "focusEmitter", coordinatesEmitter());
28
34
  this.__mdastNode = mdastNode || { type: "table", children: [] };
29
35
  }
36
+ /** @internal */
30
37
  static getType() {
31
38
  return "table";
32
39
  }
40
+ /** @internal */
33
41
  static clone(node) {
34
42
  return new TableNode(structuredClone(node.__mdastNode), node.__key);
35
43
  }
44
+ /** @internal */
36
45
  static importJSON(serializedNode) {
37
46
  return $createTableNode(serializedNode.mdastNode);
38
47
  }
48
+ /** @internal */
39
49
  exportJSON() {
40
50
  return {
41
51
  mdastNode: structuredClone(this.__mdastNode),
@@ -43,22 +53,34 @@ class TableNode extends DecoratorNode {
43
53
  version: 1
44
54
  };
45
55
  }
56
+ /**
57
+ * Returns the mdast node that this node is constructed from.
58
+ */
46
59
  getMdastNode() {
47
60
  return this.__mdastNode;
48
61
  }
62
+ /**
63
+ * Returns the number of rows in the table.
64
+ */
49
65
  getRowCount() {
50
66
  return this.__mdastNode.children.length;
51
67
  }
68
+ /**
69
+ * Returns the number of columns in the table.
70
+ */
52
71
  getColCount() {
53
72
  var _a;
54
73
  return ((_a = this.__mdastNode.children[0]) == null ? void 0 : _a.children.length) || 0;
55
74
  }
75
+ /** @internal */
56
76
  createDOM() {
57
77
  return document.createElement("div");
58
78
  }
79
+ /** @internal */
59
80
  updateDOM() {
60
81
  return false;
61
82
  }
83
+ /** @internal */
62
84
  updateCellContents(colIndex, rowIndex, children) {
63
85
  const self = this.getWritable();
64
86
  const table = self.__mdastNode;
@@ -129,12 +151,18 @@ class TableNode extends DecoratorNode {
129
151
  }
130
152
  table.align[colIndex] = align;
131
153
  }
154
+ /** @internal */
132
155
  decorate(parentEditor) {
133
156
  return /* @__PURE__ */ React__default.createElement(TableEditor, { lexicalTable: this, mdastNode: this.__mdastNode, parentEditor });
134
157
  }
158
+ /**
159
+ * Focuses the table cell at the specified coordinates.
160
+ * Pass `undefined` to remove the focus.
161
+ */
135
162
  select(coords) {
136
163
  this.focusEmitter.publish(coords || [0, 0]);
137
164
  }
165
+ /** @internal */
138
166
  isInline() {
139
167
  return false;
140
168
  }
@@ -1,11 +1,12 @@
1
+ import { realmPlugin } from "../../RealmWithPlugins.js";
2
+ import { Signal, map } from "@mdxeditor/gurx";
1
3
  import { gfmTableFromMarkdown, gfmTableToMarkdown } from "mdast-util-gfm-table";
2
4
  import { gfmTable } from "micromark-extension-gfm-table";
3
- import { coreSystem } from "../core/index.js";
5
+ import { insertDecoratorNode$, addMdastExtension$, addSyntaxExtension$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addToMarkdownExtension$ } from "../core/index.js";
4
6
  import { LexicalTableVisitor } from "./LexicalTableVisitor.js";
5
7
  import { MdastTableVisitor } from "./MdastTableVisitor.js";
6
8
  import { $createTableNode, TableNode } from "./TableNode.js";
7
- import { system } from "../../gurx/realmFactory.js";
8
- import { realmPlugin } from "../../gurx/react.js";
9
+ import { $isTableNode } from "./TableNode.js";
9
10
  function seedTable(rows = 1, columns = 1) {
10
11
  const table = {
11
12
  type: "table",
@@ -27,43 +28,35 @@ function seedTable(rows = 1, columns = 1) {
27
28
  }
28
29
  return table;
29
30
  }
30
- const tableSystem = system(
31
- (r, [{ insertDecoratorNode }]) => {
32
- const insertTable = r.node();
33
- r.link(
34
- r.pipe(
35
- insertTable,
36
- r.o.map(({ rows, columns }) => {
37
- return () => $createTableNode(seedTable(rows, columns));
38
- })
39
- ),
40
- insertDecoratorNode
41
- );
42
- return {
43
- insertTable
44
- };
45
- },
46
- [coreSystem]
47
- );
48
- const [
49
- /** @internal */
50
- tablePlugin,
51
- /** @internal */
52
- tablePluginHooks
53
- ] = realmPlugin({
54
- id: "table",
55
- systemSpec: tableSystem,
56
- init: (realm) => {
57
- realm.pubKey("addMdastExtension", gfmTableFromMarkdown);
58
- realm.pubKey("addSyntaxExtension", gfmTable);
59
- realm.pubKey("addImportVisitor", MdastTableVisitor);
60
- realm.pubKey("addLexicalNode", TableNode);
61
- realm.pubKey("addExportVisitor", LexicalTableVisitor);
62
- realm.pubKey("addToMarkdownExtension", gfmTableToMarkdown({ tableCellPadding: true, tablePipeAlign: true }));
31
+ const insertTable$ = Signal((r) => {
32
+ r.link(
33
+ r.pipe(
34
+ insertTable$,
35
+ map(({ rows, columns }) => {
36
+ return () => $createTableNode(seedTable(rows, columns));
37
+ })
38
+ ),
39
+ insertDecoratorNode$
40
+ );
41
+ });
42
+ const tablePlugin = realmPlugin({
43
+ init(realm) {
44
+ realm.pubIn({
45
+ // import
46
+ [addMdastExtension$]: gfmTableFromMarkdown(),
47
+ [addSyntaxExtension$]: gfmTable(),
48
+ [addImportVisitor$]: MdastTableVisitor,
49
+ // export
50
+ [addLexicalNode$]: TableNode,
51
+ [addExportVisitor$]: LexicalTableVisitor,
52
+ [addToMarkdownExtension$]: gfmTableToMarkdown({ tableCellPadding: true, tablePipeAlign: true })
53
+ });
63
54
  }
64
55
  });
65
56
  export {
66
- tablePlugin,
67
- tablePluginHooks,
68
- tableSystem
57
+ $createTableNode,
58
+ $isTableNode,
59
+ TableNode,
60
+ insertTable$,
61
+ tablePlugin
69
62
  };