@mdxeditor/editor 0.8.0 → 0.10.0-alpha.1

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 (288) hide show
  1. package/README.md +2 -2
  2. package/dist/FormatConstants.d.ts +9 -0
  3. package/dist/FormatConstants.js +10 -0
  4. package/dist/MDXEditor.d.ts +31 -0
  5. package/dist/MDXEditor.js +105 -0
  6. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +4 -0
  7. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
  8. package/dist/directive-editors/GenericDirectiveEditor.d.ts +3 -0
  9. package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
  10. package/dist/exportMarkdownFromLexical.d.ts +114 -0
  11. package/dist/exportMarkdownFromLexical.js +199 -0
  12. package/dist/gurx/index.d.ts +3 -0
  13. package/dist/gurx/react.d.ts +121 -0
  14. package/dist/gurx/react.js +112 -0
  15. package/dist/gurx/realm.d.ts +133 -0
  16. package/dist/gurx/realm.js +491 -0
  17. package/dist/gurx/realmFactory.d.ts +58 -0
  18. package/dist/gurx/realmFactory.js +28 -0
  19. package/dist/icons/add_column.svg.js +8 -0
  20. package/dist/icons/add_photo.svg.js +8 -0
  21. package/dist/icons/add_row.svg.js +8 -0
  22. package/dist/icons/arrow_drop_down.svg.js +8 -0
  23. package/dist/icons/arrow_right.svg.js +8 -0
  24. package/dist/icons/check.svg.js +8 -0
  25. package/dist/icons/close.svg.js +8 -0
  26. package/dist/icons/code.svg.js +8 -0
  27. package/dist/icons/content_copy.svg.js +8 -0
  28. package/dist/icons/delete.svg.js +8 -0
  29. package/dist/icons/delete_small.svg.js +8 -0
  30. package/dist/icons/deployed_code.svg.js +8 -0
  31. package/dist/icons/difference.svg.js +8 -0
  32. package/dist/icons/edit.svg.js +8 -0
  33. package/dist/icons/emergency_home.svg.js +8 -0
  34. package/dist/icons/format_align_center.svg.js +8 -0
  35. package/dist/icons/format_align_left.svg.js +8 -0
  36. package/dist/icons/format_align_right.svg.js +8 -0
  37. package/dist/icons/format_bold.svg.js +8 -0
  38. package/dist/icons/format_italic.svg.js +8 -0
  39. package/dist/icons/format_list_bulleted.svg.js +8 -0
  40. package/dist/icons/format_list_numbered.svg.js +8 -0
  41. package/dist/icons/format_underlined.svg.js +8 -0
  42. package/dist/icons/frame_source.svg.js +8 -0
  43. package/dist/icons/frontmatter.svg.js +8 -0
  44. package/dist/icons/horizontal_rule.svg.js +8 -0
  45. package/dist/icons/insert_col_left.svg.js +8 -0
  46. package/dist/icons/insert_col_right.svg.js +8 -0
  47. package/dist/icons/insert_row_above.svg.js +8 -0
  48. package/dist/icons/insert_row_below.svg.js +8 -0
  49. package/dist/icons/link.svg.js +8 -0
  50. package/dist/icons/link_off.svg.js +8 -0
  51. package/dist/icons/markdown.svg.js +8 -0
  52. package/dist/icons/more_horiz.svg.js +8 -0
  53. package/dist/icons/open_in_new.svg.js +8 -0
  54. package/dist/icons/redo.svg.js +8 -0
  55. package/dist/icons/rich_text.svg.js +8 -0
  56. package/dist/icons/settings.svg.js +8 -0
  57. package/dist/icons/table.svg.js +8 -0
  58. package/dist/icons/undo.svg.js +8 -0
  59. package/dist/importMarkdownToLexical.d.ts +84 -0
  60. package/dist/importMarkdownToLexical.js +65 -0
  61. package/dist/index.d.ts +49 -973
  62. package/dist/index.js +133 -66
  63. package/dist/jsx-editors/GenericJsxEditor.d.ts +3 -0
  64. package/dist/jsx-editors/GenericJsxEditor.js +56 -0
  65. package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
  66. package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
  67. package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
  68. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
  69. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  70. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
  71. package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
  72. package/dist/plugins/codeblock/index.d.ts +604 -0
  73. package/dist/plugins/codeblock/index.js +73 -0
  74. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
  75. package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
  76. package/dist/plugins/codemirror/index.d.ts +786 -0
  77. package/dist/plugins/codemirror/index.js +62 -0
  78. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
  79. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  80. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
  81. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  82. package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
  83. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  84. package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
  85. package/dist/plugins/core/LexicalTextVisitor.js +85 -0
  86. package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
  87. package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
  88. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
  89. package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
  90. package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
  91. package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
  92. package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
  93. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  94. package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
  95. package/dist/plugins/core/MdastTextVisitor.js +10 -0
  96. package/dist/plugins/core/NestedLexicalEditor.d.ts +69 -0
  97. package/dist/plugins/core/NestedLexicalEditor.js +181 -0
  98. package/dist/plugins/core/PropertyPopover.d.ts +8 -0
  99. package/dist/plugins/core/PropertyPopover.js +36 -0
  100. package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
  101. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  102. package/dist/plugins/core/index.d.ts +419 -0
  103. package/dist/plugins/core/index.js +343 -0
  104. package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
  105. package/dist/plugins/core/ui/PopoverUtils.js +17 -0
  106. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
  107. package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
  108. package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
  109. package/dist/plugins/diff-source/DiffViewer.js +18 -0
  110. package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
  111. package/dist/plugins/diff-source/SourceEditor.js +25 -0
  112. package/dist/plugins/diff-source/index.d.ts +530 -0
  113. package/dist/plugins/diff-source/index.js +55 -0
  114. package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
  115. package/dist/plugins/directives/DirectiveNode.js +92 -0
  116. package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
  117. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  118. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
  119. package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
  120. package/dist/plugins/directives/index.d.ts +591 -0
  121. package/dist/plugins/directives/index.js +53 -0
  122. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
  123. package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
  124. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
  125. package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
  126. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
  127. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  128. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
  129. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  130. package/dist/plugins/frontmatter/index.d.ts +510 -0
  131. package/dist/plugins/frontmatter/index.js +53 -0
  132. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
  133. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  134. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
  135. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  136. package/dist/plugins/headings/index.d.ts +105 -0
  137. package/dist/plugins/headings/index.js +20 -0
  138. package/dist/plugins/image/ImageEditor.d.ts +7 -0
  139. package/dist/{ImageEditor-5f203a1c.js → plugins/image/ImageEditor.js} +12 -46
  140. package/dist/plugins/image/ImageNode.d.ts +53 -0
  141. package/dist/plugins/image/ImageNode.js +108 -0
  142. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  143. package/dist/plugins/image/LexicalImageVisitor.js +15 -0
  144. package/dist/plugins/image/MdastImageVisitor.d.ts +3 -0
  145. package/dist/plugins/image/MdastImageVisitor.js +16 -0
  146. package/dist/plugins/image/index.d.ts +541 -0
  147. package/dist/plugins/image/index.js +244 -0
  148. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  149. package/dist/plugins/jsx/LexicalJsxNode.js +99 -0
  150. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  151. package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
  152. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  153. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  154. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  155. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  156. package/dist/plugins/jsx/index.d.ts +461 -0
  157. package/dist/plugins/jsx/index.js +37 -0
  158. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  159. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  160. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  161. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  162. package/dist/plugins/link/index.d.ts +108 -0
  163. package/dist/plugins/link/index.js +24 -0
  164. package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
  165. package/dist/plugins/link-dialog/LinkDialog.js +174 -0
  166. package/dist/plugins/link-dialog/index.d.ts +496 -0
  167. package/dist/plugins/link-dialog/index.js +242 -0
  168. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  169. package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
  170. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  171. package/dist/plugins/lists/LexicalListVisitor.js +14 -0
  172. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  173. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  174. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  175. package/dist/plugins/lists/MdastListVisitor.js +18 -0
  176. package/dist/plugins/lists/index.d.ts +521 -0
  177. package/dist/plugins/lists/index.js +111 -0
  178. package/dist/plugins/markdown-shortcut/index.d.ts +51 -0
  179. package/dist/plugins/markdown-shortcut/index.js +34 -0
  180. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  181. package/dist/plugins/quote/LexicalQuoteVisitor.js +14 -0
  182. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  183. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  184. package/dist/plugins/quote/index.d.ts +348 -0
  185. package/dist/plugins/quote/index.js +26 -0
  186. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  187. package/dist/plugins/sandpack/SandpackEditor.js +35 -0
  188. package/dist/plugins/sandpack/index.d.ts +826 -0
  189. package/dist/plugins/sandpack/index.js +93 -0
  190. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  191. package/dist/{useCodeMirrorRef-ff0c2781.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
  192. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  193. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  194. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  195. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  196. package/dist/plugins/table/TableEditor.d.ts +21 -0
  197. package/dist/{TableEditor-bb94be2b.js → plugins/table/TableEditor.js} +109 -161
  198. package/dist/plugins/table/TableNode.d.ts +52 -0
  199. package/dist/plugins/table/TableNode.js +147 -0
  200. package/dist/plugins/table/index.d.ts +511 -0
  201. package/dist/plugins/table/index.js +59 -0
  202. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  203. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  204. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  205. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  206. package/dist/plugins/thematic-break/index.d.ts +510 -0
  207. package/dist/plugins/thematic-break/index.js +39 -0
  208. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +2 -0
  209. package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
  210. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +2 -0
  211. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
  212. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +2 -0
  213. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  214. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +2 -0
  215. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  216. package/dist/plugins/toolbar/components/CodeToggle.d.ts +2 -0
  217. package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
  218. package/dist/plugins/toolbar/components/CreateLink.d.ts +2 -0
  219. package/dist/plugins/toolbar/components/CreateLink.js +11 -0
  220. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +4 -0
  221. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
  222. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +2 -0
  223. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  224. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +2 -0
  225. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  226. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +2 -0
  227. package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
  228. package/dist/plugins/toolbar/components/InsertImage.d.ts +2 -0
  229. package/dist/plugins/toolbar/components/InsertImage.js +23 -0
  230. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +2 -0
  231. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  232. package/dist/plugins/toolbar/components/InsertTable.d.ts +2 -0
  233. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  234. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +2 -0
  235. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  236. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +2 -0
  237. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  238. package/dist/plugins/toolbar/components/ListsToggle.d.ts +2 -0
  239. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  240. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +2 -0
  241. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
  242. package/dist/plugins/toolbar/components/UndoRedo.d.ts +2 -0
  243. package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
  244. package/dist/plugins/toolbar/index.d.ts +416 -0
  245. package/dist/plugins/toolbar/index.js +39 -0
  246. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  247. package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
  248. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +5 -0
  249. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  250. package/dist/plugins/toolbar/primitives/select.d.ts +31 -0
  251. package/dist/plugins/toolbar/primitives/select.js +44 -0
  252. package/dist/plugins/toolbar/primitives/toolbar.d.ts +85 -0
  253. package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
  254. package/dist/style.css +480 -240
  255. package/dist/styles/globals.css.js +4 -0
  256. package/dist/styles/lexical-theme.module.css.js +53 -0
  257. package/dist/styles/lexicalTheme.d.ts +2 -0
  258. package/dist/styles/lexicalTheme.js +28 -0
  259. package/dist/styles/ui.module.css.js +227 -0
  260. package/dist/utils/detectMac.d.ts +2 -0
  261. package/dist/utils/detectMac.js +6 -0
  262. package/dist/utils/fp.d.ts +47 -0
  263. package/dist/utils/fp.js +10 -0
  264. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  265. package/dist/utils/isPartOftheEditorUI.js +12 -0
  266. package/dist/utils/lexicalHelpers.d.ts +11 -0
  267. package/dist/utils/lexicalHelpers.js +49 -0
  268. package/dist/utils/uuid4.d.ts +1 -0
  269. package/dist/utils/uuid4.js +10 -0
  270. package/dist/utils/voidEmitter.d.ts +14 -0
  271. package/dist/utils/voidEmitter.js +15 -0
  272. package/package.json +184 -14
  273. package/dist/CodeBlockEditor-59b65408.js +0 -78
  274. package/dist/CodeBlockEditor-5ae8b0a9.cjs +0 -1
  275. package/dist/FrontmatterEditor-2b27f5a7.js +0 -117
  276. package/dist/FrontmatterEditor-74ad4eb7.cjs +0 -1
  277. package/dist/ImageEditor-e5fd6b26.cjs +0 -1
  278. package/dist/JsxEditor-95724372.cjs +0 -1
  279. package/dist/JsxEditor-f061cc75.js +0 -108
  280. package/dist/SandpackEditor-37261889.cjs +0 -1
  281. package/dist/SandpackEditor-ce901c3c.js +0 -98
  282. package/dist/SourceEditor-6135bf63.cjs +0 -1
  283. package/dist/SourceEditor-e499b8bb.js +0 -63
  284. package/dist/TableEditor-4d00f956.cjs +0 -1
  285. package/dist/index-383c60bb.cjs +0 -1
  286. package/dist/index-470693d8.js +0 -4095
  287. package/dist/index.cjs +0 -1
  288. package/dist/useCodeMirrorRef-72d8430b.cjs +0 -1
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # MDX Editor
1
+ # MDXEditor
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/@mdxeditor/editor)
4
4
  ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@mdxeditor/editor)
5
5
 
6
6
  > Because markdown editing can be even more delightful.
7
7
 
8
- MDX Editor is an open-source React component that allows users to author markdown documents naturally. Just like in Google docs or Notion. [See the live demo](https://mdxeditor.dev/editor/demo) that has the default features turned on. It supports most (if not all) of the markdown syntax, including tables, images, code blocks, etc. It also allows users to edit JSX components with a dedicated property editor.
8
+ MDXEditor is an open-source React component that allows users to author markdown documents naturally. Just like in Google docs or Notion. [See the live demo](https://mdxeditor.dev/editor/demo) that has the default features turned on. It supports the core markdown syntax and certain extensions, including tables, images, code blocks, etc. It also allows users to edit JSX components with a dedicated property editor.
9
9
 
10
10
  ```jsx
11
11
  import {MDXEditor} from '@mdxeditor/editor';
@@ -0,0 +1,9 @@
1
+ export declare const DEFAULT_FORMAT: 0;
2
+ export declare const IS_BOLD: 1;
3
+ export declare const IS_ITALIC: 2;
4
+ export declare const IS_STRIKETHROUGH: 4;
5
+ export declare const IS_UNDERLINE: 8;
6
+ export declare const IS_CODE: 16;
7
+ export declare const IS_SUBSCRIPT: 32;
8
+ export declare const IS_SUPERSCRIPT: 64;
9
+ export declare const IS_HIGHLIGHT: 128;
@@ -0,0 +1,10 @@
1
+ const IS_BOLD = 1;
2
+ const IS_ITALIC = 2;
3
+ const IS_UNDERLINE = 8;
4
+ const IS_CODE = 16;
5
+ export {
6
+ IS_BOLD,
7
+ IS_CODE,
8
+ IS_ITALIC,
9
+ IS_UNDERLINE
10
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { RealmPluginInitializer } from './gurx';
3
+ import { ToMarkdownOptions } from './exportMarkdownFromLexical';
4
+ export interface MDXEditorProps {
5
+ contentEditableClassName?: string;
6
+ markdown: string;
7
+ onChange?: (markdown: string) => void;
8
+ toMarkdownOptions?: ToMarkdownOptions;
9
+ plugins?: React.ComponentProps<typeof RealmPluginInitializer>['plugins'];
10
+ className?: string;
11
+ }
12
+ /**
13
+ * The interface for the {@link MDXEditor} object reference.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const mdxEditorRef = React.useRef<MDXEditorMethods>(null)
18
+ * <MDXEditor ref={mdxEditorRef} />
19
+ * ```
20
+ */
21
+ export interface MDXEditorMethods {
22
+ /**
23
+ * Gets the current markdown value.
24
+ */
25
+ getMarkdown: () => string;
26
+ /**
27
+ * Updates the markdown value of the editor.
28
+ */
29
+ setMarkdown: (value: string) => void;
30
+ }
31
+ export declare const MDXEditor: React.ForwardRefExoticComponent<MDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
@@ -0,0 +1,105 @@
1
+ import React__default from "react";
2
+ import { corePlugin, corePluginHooks } from "./plugins/core/index.js";
3
+ import { lexicalTheme } from "./styles/lexicalTheme.js";
4
+ import { LexicalComposer } from "@lexical/react/LexicalComposer";
5
+ import styles from "./styles/ui.module.css.js";
6
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
7
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
8
+ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
9
+ import classNames from "classnames";
10
+ import { noop } from "./utils/fp.js";
11
+ import { RealmPluginInitializer } from "./gurx/react.js";
12
+ const LexicalProvider = ({ children }) => {
13
+ const [initialRootEditorState, nodes] = corePluginHooks.useEmitterValues("initialRootEditorState", "usedLexicalNodes");
14
+ return /* @__PURE__ */ React__default.createElement(
15
+ LexicalComposer,
16
+ {
17
+ initialConfig: {
18
+ editorState: initialRootEditorState,
19
+ namespace: "MDXEditor",
20
+ theme: lexicalTheme,
21
+ nodes,
22
+ onError: (error) => {
23
+ throw error;
24
+ }
25
+ }
26
+ },
27
+ children
28
+ );
29
+ };
30
+ const RichTextEditor = () => {
31
+ const [contentEditableClassName, composerChildren, topAreaChildren, editorWrappers] = corePluginHooks.useEmitterValues(
32
+ "contentEditableClassName",
33
+ "composerChildren",
34
+ "topAreaChildren",
35
+ "editorWrappers"
36
+ );
37
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, topAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), /* @__PURE__ */ React__default.createElement(RenderRecurisveWrappers, { wrappers: editorWrappers }, /* @__PURE__ */ React__default.createElement(
38
+ RichTextPlugin,
39
+ {
40
+ contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { className: classNames(styles.contentEditable, contentEditableClassName) }),
41
+ placeholder: /* @__PURE__ */ React__default.createElement("div", null),
42
+ ErrorBoundary: LexicalErrorBoundary
43
+ }
44
+ )), composerChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
45
+ };
46
+ const DEFAULT_MARKDOWN_OPTIONS = {
47
+ listItemIndent: "one"
48
+ };
49
+ const RenderRecurisveWrappers = ({
50
+ wrappers,
51
+ children
52
+ }) => {
53
+ if (wrappers.length === 0) {
54
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children);
55
+ }
56
+ const Wrapper = wrappers[0];
57
+ return /* @__PURE__ */ React__default.createElement(Wrapper, null, /* @__PURE__ */ React__default.createElement(RenderRecurisveWrappers, { wrappers: wrappers.slice(1) }, children));
58
+ };
59
+ const EditorRootElement = ({ children, className }) => {
60
+ const editorRootElementRef = React__default.useRef(null);
61
+ const setEditorRootElementRef = corePluginHooks.usePublisher("editorRootElementRef");
62
+ React__default.useEffect(() => {
63
+ setEditorRootElementRef(editorRootElementRef);
64
+ }, [editorRootElementRef, setEditorRootElementRef]);
65
+ return /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.editorRoot, styles.editorWrapper, className), ref: editorRootElementRef }, children);
66
+ };
67
+ const Methods = ({ mdxRef }) => {
68
+ const realm = corePluginHooks.useRealmContext();
69
+ React__default.useImperativeHandle(
70
+ mdxRef,
71
+ () => {
72
+ return {
73
+ getMarkdown: () => {
74
+ return realm.getKeyValue("markdown");
75
+ },
76
+ setMarkdown: (markdown) => {
77
+ realm.pubKey("setMarkdown", markdown);
78
+ }
79
+ };
80
+ },
81
+ [realm]
82
+ );
83
+ return null;
84
+ };
85
+ const MDXEditor = React__default.forwardRef((props, ref) => {
86
+ return /* @__PURE__ */ React__default.createElement(
87
+ RealmPluginInitializer,
88
+ {
89
+ plugins: [
90
+ corePlugin({
91
+ contentEditableClassName: props.contentEditableClassName ?? "",
92
+ initialMarkdown: props.markdown,
93
+ onChange: props.onChange ?? noop,
94
+ toMarkdownOptions: props.toMarkdownOptions ?? DEFAULT_MARKDOWN_OPTIONS
95
+ }),
96
+ ...props.plugins || []
97
+ ]
98
+ },
99
+ /* @__PURE__ */ React__default.createElement(EditorRootElement, null, /* @__PURE__ */ React__default.createElement(LexicalProvider, null, /* @__PURE__ */ React__default.createElement(RichTextEditor, null))),
100
+ /* @__PURE__ */ React__default.createElement(Methods, { mdxRef: ref })
101
+ );
102
+ });
103
+ export {
104
+ MDXEditor
105
+ };
@@ -0,0 +1,4 @@
1
+ import { DirectiveDescriptor } from '../plugins/directives';
2
+ export declare const ADMONITION_TYPES: readonly ["note", "tip", "danger", "info", "caution"];
3
+ export type AdmonitionKind = (typeof ADMONITION_TYPES)[number];
4
+ export declare const AdmonitionDirectiveDescriptor: DirectiveDescriptor;
@@ -0,0 +1,29 @@
1
+ import React__default from "react";
2
+ import { useNestedEditorContext, NestedLexicalEditor } from "../plugins/core/NestedLexicalEditor.js";
3
+ const ADMONITION_TYPES = ["note", "tip", "danger", "info", "caution"];
4
+ const AdmonitionDirectiveDescriptor = {
5
+ name: "admonition",
6
+ attributes: [],
7
+ hasChildren: true,
8
+ testNode(node) {
9
+ return ADMONITION_TYPES.includes(node.name);
10
+ },
11
+ Editor({ mdastNode }) {
12
+ const {
13
+ config: { theme },
14
+ focusEmitter
15
+ } = useNestedEditorContext();
16
+ return /* @__PURE__ */ React__default.createElement("div", { className: theme.admonition[mdastNode.name] }, /* @__PURE__ */ React__default.createElement(
17
+ NestedLexicalEditor,
18
+ {
19
+ focusEmitter,
20
+ getContent: (node) => node.children,
21
+ getUpdatedMdastNode: (mdastNode2, children) => ({ ...mdastNode2, children })
22
+ }
23
+ ));
24
+ }
25
+ };
26
+ export {
27
+ ADMONITION_TYPES,
28
+ AdmonitionDirectiveDescriptor
29
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { DirectiveEditorProps } from '../plugins/directives';
3
+ export declare const GenericDirectiveEditor: React.FC<DirectiveEditorProps>;
@@ -0,0 +1,32 @@
1
+ import React__default from "react";
2
+ import { useMdastNodeUpdater, NestedLexicalEditor } from "../plugins/core/NestedLexicalEditor.js";
3
+ import { PropertyPopover } from "../plugins/core/PropertyPopover.js";
4
+ import styles from "../styles/ui.module.css.js";
5
+ const GenericDirectiveEditor = ({ mdastNode, descriptor }) => {
6
+ const updateMdastNode = useMdastNodeUpdater();
7
+ const properties = React__default.useMemo(() => {
8
+ return descriptor.attributes.reduce((acc, attributeName) => {
9
+ acc[attributeName] = (mdastNode.attributes || {})[attributeName] || "";
10
+ return acc;
11
+ }, {});
12
+ }, [mdastNode, descriptor]);
13
+ const onChange = React__default.useCallback(
14
+ (values) => {
15
+ updateMdastNode({ attributes: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== "")) });
16
+ },
17
+ [updateMdastNode]
18
+ );
19
+ return /* @__PURE__ */ React__default.createElement("div", { className: mdastNode.type === "textDirective" ? styles.inlineEditor : styles.blockEditor }, descriptor.attributes.length == 0 && descriptor.hasChildren && mdastNode.type !== "textDirective" ? /* @__PURE__ */ React__default.createElement("span", { className: styles.genericComponentName }, mdastNode.name) : null, descriptor.attributes.length > 0 ? /* @__PURE__ */ React__default.createElement(PropertyPopover, { properties, title: mdastNode.name || "", onChange }) : null, descriptor.hasChildren ? /* @__PURE__ */ React__default.createElement(
20
+ NestedLexicalEditor,
21
+ {
22
+ block: mdastNode.type === "containerDirective",
23
+ getContent: (node) => node.children,
24
+ getUpdatedMdastNode: (mdastNode2, children) => {
25
+ return { ...mdastNode2, children };
26
+ }
27
+ }
28
+ ) : /* @__PURE__ */ React__default.createElement("span", { className: styles.genericComponentName }, mdastNode.name));
29
+ };
30
+ export {
31
+ GenericDirectiveEditor
32
+ };
@@ -0,0 +1,114 @@
1
+ import { LexicalNode, RootNode as LexicalRootNode } from 'lexical';
2
+ import * as Mdast from 'mdast';
3
+ import { Options as ToMarkdownOptions } from 'mdast-util-to-markdown';
4
+ import type { JsxComponentDescriptor } from './plugins/jsx';
5
+ export type { Options as ToMarkdownOptions } from 'mdast-util-to-markdown';
6
+ /**
7
+ * A set of covenience utilities to manipulate the mdast tree when processing lexical nodes.
8
+ */
9
+ export interface LexicalVisitActions<T extends LexicalNode> {
10
+ /**
11
+ * Iterate over the immediate children of a lexical node with the given mdast node as a parent.
12
+ */
13
+ visitChildren(node: T, mdastParent: Mdast.Parent): void;
14
+ /**
15
+ * Create a new mdast node with the given type, and props.
16
+ * Iterate over the immediate children of the current lexical node with the new mdast node as a parent.
17
+ * @param hasChildren - true by default. Pass false to skip iterating over the lexical node children.
18
+ */
19
+ addAndStepInto(type: string, props?: Record<string, unknown>, hasChildren?: boolean): void;
20
+ /**
21
+ * Append a new mdast node to a parent node.
22
+ * @param parentNode - the mdast parent node to append the new node to.
23
+ * @param node - the mdast node to append.
24
+ */
25
+ appendToParent<T extends Mdast.Parent>(parentNode: T, node: T['children'][number]): T['children'][number] | Mdast.Root;
26
+ /**
27
+ * Used when processing JSX nodes so that later, the correct import statement can be added to the document.
28
+ * @param componentName - the name of the component that has to be imported.
29
+ * @see {@link JsxComponentDescriptor}
30
+ */
31
+ registerReferredComponent(componentName: string): void;
32
+ }
33
+ /**
34
+ * The params passed to the {@link LexicalExportVisitor.visitLexicalNode} method.
35
+ */
36
+ export interface LexicalNodeVisitParams<T extends LexicalNode> {
37
+ /**
38
+ * The lexical node that is being visited.
39
+ */
40
+ lexicalNode: T;
41
+ /**
42
+ * The mdast parent node that the result of the lexical node conversion should be appended to.
43
+ */
44
+ mdastParent: Mdast.Parent;
45
+ /**
46
+ * A set of actions that can be used to manipulate the mdast tree.
47
+ * These are "convenience" utilities that avoid the repetitive boilerplate of creating mdast nodes.
48
+ */
49
+ actions: LexicalVisitActions<T>;
50
+ }
51
+ /**
52
+ * Implement this interface in order to process mdast node(s) into a lexical tree.
53
+ * This is part of the process that converts the editor contents to markdown.
54
+ */
55
+ export interface LexicalExportVisitor<LN extends LexicalNode, UN extends Mdast.Content> {
56
+ /**
57
+ * Return true if the given node is of the type that this visitor can process.
58
+ * You can safely use the node type guard functions (as in $isParagraphNode, $isLinkNode, etc.) here.
59
+ */
60
+ testLexicalNode?(lexicalNode: LexicalNode): lexicalNode is LN;
61
+ /**
62
+ * Process the given node and manipulate the mdast tree accordingly.
63
+ * @see {@link LexicalNodeVisitParams} and {@link LexicalVisitActions} for more information.
64
+ */
65
+ visitLexicalNode?(params: LexicalNodeVisitParams<LN>): void;
66
+ /**
67
+ * Return true if the current node should be joined with the previous node.
68
+ * This is necessary due to some inconsistencies between the lexical tree and the mdast tree when it comes to formatting.
69
+ */
70
+ shouldJoin?(prevNode: Mdast.Content, currentNode: UN): boolean;
71
+ /**
72
+ * Join the current node with the previous node, returning the resulting new node
73
+ * For this to be called by the tree walk, shouldJoin must return true.
74
+ */
75
+ join?<T extends Mdast.Content>(prevNode: T, currentNode: T): T;
76
+ }
77
+ export type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Content>;
78
+ export interface ExportLexicalTreeOptions {
79
+ root: LexicalRootNode;
80
+ visitors: LexicalVisitor[];
81
+ jsxComponentDescriptors: JsxComponentDescriptor[];
82
+ jsxIsAvailable: boolean;
83
+ }
84
+ export declare function exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors, jsxIsAvailable }: ExportLexicalTreeOptions): Mdast.Root;
85
+ export type ToMarkdownExtension = NonNullable<ToMarkdownOptions['extensions']>[number];
86
+ export interface ExportMarkdownFromLexicalOptions extends ExportLexicalTreeOptions {
87
+ visitors: LexicalVisitor[];
88
+ /**
89
+ * the markdown extensions to use
90
+ */
91
+ toMarkdownExtensions: ToMarkdownExtension[];
92
+ /**
93
+ * The options to pass to `toMarkdown`
94
+ */
95
+ toMarkdownOptions: ToMarkdownOptions;
96
+ }
97
+ /**
98
+ * Configures how the lexical tree is converted to a mdast tree and then to markdown.
99
+ */
100
+ export interface LexicalConvertOptions {
101
+ /**
102
+ * The visitors to use when processing the lexical tree
103
+ */
104
+ visitors?: LexicalVisitor[];
105
+ /**
106
+ * the markdown extensions to use
107
+ */
108
+ toMarkdownExtensions?: ToMarkdownExtension[];
109
+ /**
110
+ * The options to pass to `toMarkdown`
111
+ */
112
+ toMarkdownOptions?: ToMarkdownOptions;
113
+ }
114
+ export declare function exportMarkdownFromLexical({ root, toMarkdownOptions, toMarkdownExtensions, visitors, jsxComponentDescriptors, jsxIsAvailable }: ExportMarkdownFromLexicalOptions): string;
@@ -0,0 +1,199 @@
1
+ import { $isElementNode } from "lexical";
2
+ import { toMarkdown } from "mdast-util-to-markdown";
3
+ function isParent(node) {
4
+ return node.children instanceof Array;
5
+ }
6
+ function exportLexicalTreeToMdast({
7
+ root,
8
+ visitors,
9
+ jsxComponentDescriptors,
10
+ jsxIsAvailable
11
+ }) {
12
+ let unistRoot = null;
13
+ const referredComponents = /* @__PURE__ */ new Set();
14
+ visit(root, null);
15
+ function registerReferredComponent(componentName) {
16
+ referredComponents.add(componentName);
17
+ }
18
+ function appendToParent(parentNode, node) {
19
+ if (unistRoot === null) {
20
+ unistRoot = node;
21
+ return unistRoot;
22
+ }
23
+ if (!isParent(parentNode)) {
24
+ throw new Error("Attempting to append children to a non-parent");
25
+ }
26
+ const siblings = parentNode.children;
27
+ const prevSibling = siblings.at(-1);
28
+ if (prevSibling) {
29
+ const joinVisitor = visitors.find((visitor) => {
30
+ var _a;
31
+ return (_a = visitor.shouldJoin) == null ? void 0 : _a.call(visitor, prevSibling, node);
32
+ });
33
+ if (joinVisitor) {
34
+ const joinedNode = joinVisitor.join(prevSibling, node);
35
+ siblings.splice(siblings.length - 1, 1, joinedNode);
36
+ return joinedNode;
37
+ }
38
+ }
39
+ siblings.push(node);
40
+ return node;
41
+ }
42
+ function visitChildren(lexicalNode, parentNode) {
43
+ lexicalNode.getChildren().forEach((lexicalChild) => {
44
+ visit(lexicalChild, parentNode);
45
+ });
46
+ }
47
+ function visit(lexicalNode, mdastParent) {
48
+ var _a;
49
+ const visitor = visitors.find((visitor2) => {
50
+ var _a2;
51
+ return (_a2 = visitor2.testLexicalNode) == null ? void 0 : _a2.call(visitor2, lexicalNode);
52
+ });
53
+ if (!visitor) {
54
+ throw new Error(`no lexical visitor found for ${lexicalNode.getType()}`, {
55
+ cause: lexicalNode
56
+ });
57
+ }
58
+ (_a = visitor.visitLexicalNode) == null ? void 0 : _a.call(visitor, {
59
+ lexicalNode,
60
+ mdastParent,
61
+ actions: {
62
+ addAndStepInto(type, props = {}, hasChildren = true) {
63
+ const newNode = {
64
+ type,
65
+ ...props,
66
+ ...hasChildren ? { children: [] } : {}
67
+ };
68
+ appendToParent(mdastParent, newNode);
69
+ if ($isElementNode(lexicalNode) && hasChildren) {
70
+ visitChildren(lexicalNode, newNode);
71
+ }
72
+ },
73
+ appendToParent,
74
+ visitChildren,
75
+ registerReferredComponent
76
+ }
77
+ });
78
+ }
79
+ if (unistRoot === null) {
80
+ throw new Error("traversal ended with no root element");
81
+ }
82
+ const importsMap = /* @__PURE__ */ new Map();
83
+ const defaultImportsMap = /* @__PURE__ */ new Map();
84
+ for (const componentName of referredComponents) {
85
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === componentName);
86
+ if (!descriptor) {
87
+ throw new Error(`Component ${componentName} is used but not imported`);
88
+ }
89
+ if (descriptor.defaultExport) {
90
+ defaultImportsMap.set(componentName, descriptor.source);
91
+ } else {
92
+ const { source } = descriptor;
93
+ const existing = importsMap.get(source);
94
+ if (existing) {
95
+ existing.push(componentName);
96
+ } else {
97
+ importsMap.set(source, [componentName]);
98
+ }
99
+ }
100
+ }
101
+ const imports = Array.from(importsMap).map(([source, componentNames]) => {
102
+ return {
103
+ type: "mdxjsEsm",
104
+ value: `import { ${componentNames.join(", ")} } from '${source}'`
105
+ };
106
+ });
107
+ imports.push(
108
+ ...Array.from(defaultImportsMap).map(([componentName, source]) => {
109
+ return {
110
+ type: "mdxjsEsm",
111
+ value: `import ${componentName} from '${source}'`
112
+ };
113
+ })
114
+ );
115
+ const typedRoot = unistRoot;
116
+ const frontmatter = typedRoot.children.find((child) => child.type === "yaml");
117
+ if (frontmatter) {
118
+ typedRoot.children.splice(typedRoot.children.indexOf(frontmatter) + 1, 0, ...imports);
119
+ } else {
120
+ typedRoot.children.unshift(...imports);
121
+ }
122
+ fixWrappingWhitespace(typedRoot, []);
123
+ if (!jsxIsAvailable) {
124
+ convertUnderlineJsxToHtml(typedRoot);
125
+ }
126
+ return typedRoot;
127
+ }
128
+ function convertUnderlineJsxToHtml(node) {
129
+ if (Object.hasOwn(node, "children")) {
130
+ const nodeAsParent = node;
131
+ const newChildren = [];
132
+ nodeAsParent.children.forEach((child) => {
133
+ if (child.type === "mdxJsxTextElement" && child.name === "u") {
134
+ newChildren.push(...[{ type: "html", value: "<u>" }, ...child.children, { type: "html", value: "</u>" }]);
135
+ } else {
136
+ newChildren.push(child);
137
+ convertUnderlineJsxToHtml(child);
138
+ }
139
+ });
140
+ nodeAsParent.children = newChildren;
141
+ }
142
+ }
143
+ const TRAILING_WHITESPACE_REGEXP = /\s+$/;
144
+ const LEADING_WHITESPACE_REGEXP = /^\s+/;
145
+ function fixWrappingWhitespace(node, parentChain) {
146
+ if (node.type === "strong" || node.type === "emphasis") {
147
+ const lastChild = node.children.at(-1);
148
+ if ((lastChild == null ? void 0 : lastChild.type) === "text") {
149
+ const trailingWhitespace = lastChild.value.match(TRAILING_WHITESPACE_REGEXP);
150
+ if (trailingWhitespace) {
151
+ lastChild.value = lastChild.value.replace(TRAILING_WHITESPACE_REGEXP, "");
152
+ const parent = parentChain.at(-1);
153
+ if (parent) {
154
+ parent.children.splice(parent.children.indexOf(node) + 1, 0, {
155
+ type: "text",
156
+ value: trailingWhitespace[0]
157
+ });
158
+ fixWrappingWhitespace(parent, parentChain.slice(0, -1));
159
+ }
160
+ }
161
+ }
162
+ const firstChild = node.children.at(0);
163
+ if ((firstChild == null ? void 0 : firstChild.type) === "text") {
164
+ const leadingWhitespace = firstChild.value.match(LEADING_WHITESPACE_REGEXP);
165
+ if (leadingWhitespace) {
166
+ firstChild.value = firstChild.value.replace(LEADING_WHITESPACE_REGEXP, "");
167
+ const parent = parentChain.at(-1);
168
+ if (parent) {
169
+ parent.children.splice(parent.children.indexOf(node), 0, {
170
+ type: "text",
171
+ value: leadingWhitespace[0]
172
+ });
173
+ fixWrappingWhitespace(parent, parentChain.slice(0, -1));
174
+ }
175
+ }
176
+ }
177
+ }
178
+ if (Object.hasOwn(node, "children")) {
179
+ const nodeAsParent = node;
180
+ nodeAsParent.children.forEach((child) => fixWrappingWhitespace(child, [...parentChain, nodeAsParent]));
181
+ }
182
+ }
183
+ function exportMarkdownFromLexical({
184
+ root,
185
+ toMarkdownOptions,
186
+ toMarkdownExtensions,
187
+ visitors,
188
+ jsxComponentDescriptors,
189
+ jsxIsAvailable
190
+ }) {
191
+ return toMarkdown(exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors, jsxIsAvailable }), {
192
+ extensions: toMarkdownExtensions,
193
+ ...toMarkdownOptions
194
+ });
195
+ }
196
+ export {
197
+ exportLexicalTreeToMdast,
198
+ exportMarkdownFromLexical
199
+ };
@@ -0,0 +1,3 @@
1
+ export * from './realm';
2
+ export * from './react';
3
+ export * from './realmFactory';