@mdxeditor/editor 0.9.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 (289) hide show
  1. package/dist/FormatConstants.d.ts +9 -0
  2. package/dist/FormatConstants.js +10 -0
  3. package/dist/MDXEditor.d.ts +31 -0
  4. package/dist/MDXEditor.js +105 -0
  5. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +4 -0
  6. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
  7. package/dist/directive-editors/GenericDirectiveEditor.d.ts +3 -0
  8. package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
  9. package/dist/exportMarkdownFromLexical.d.ts +114 -0
  10. package/dist/exportMarkdownFromLexical.js +199 -0
  11. package/dist/gurx/index.d.ts +3 -0
  12. package/dist/gurx/react.d.ts +121 -0
  13. package/dist/gurx/react.js +112 -0
  14. package/dist/gurx/realm.d.ts +133 -0
  15. package/dist/gurx/realm.js +491 -0
  16. package/dist/gurx/realmFactory.d.ts +58 -0
  17. package/dist/gurx/realmFactory.js +28 -0
  18. package/dist/icons/add_column.svg.js +8 -0
  19. package/dist/icons/add_photo.svg.js +8 -0
  20. package/dist/icons/add_row.svg.js +8 -0
  21. package/dist/icons/arrow_drop_down.svg.js +8 -0
  22. package/dist/icons/arrow_right.svg.js +8 -0
  23. package/dist/icons/check.svg.js +8 -0
  24. package/dist/icons/close.svg.js +8 -0
  25. package/dist/icons/code.svg.js +8 -0
  26. package/dist/icons/content_copy.svg.js +8 -0
  27. package/dist/icons/delete.svg.js +8 -0
  28. package/dist/icons/delete_small.svg.js +8 -0
  29. package/dist/icons/deployed_code.svg.js +8 -0
  30. package/dist/icons/difference.svg.js +8 -0
  31. package/dist/icons/edit.svg.js +8 -0
  32. package/dist/icons/emergency_home.svg.js +8 -0
  33. package/dist/icons/format_align_center.svg.js +8 -0
  34. package/dist/icons/format_align_left.svg.js +8 -0
  35. package/dist/icons/format_align_right.svg.js +8 -0
  36. package/dist/icons/format_bold.svg.js +8 -0
  37. package/dist/icons/format_italic.svg.js +8 -0
  38. package/dist/icons/format_list_bulleted.svg.js +8 -0
  39. package/dist/icons/format_list_numbered.svg.js +8 -0
  40. package/dist/icons/format_underlined.svg.js +8 -0
  41. package/dist/icons/frame_source.svg.js +8 -0
  42. package/dist/icons/frontmatter.svg.js +8 -0
  43. package/dist/icons/horizontal_rule.svg.js +8 -0
  44. package/dist/icons/insert_col_left.svg.js +8 -0
  45. package/dist/icons/insert_col_right.svg.js +8 -0
  46. package/dist/icons/insert_row_above.svg.js +8 -0
  47. package/dist/icons/insert_row_below.svg.js +8 -0
  48. package/dist/icons/link.svg.js +8 -0
  49. package/dist/icons/link_off.svg.js +8 -0
  50. package/dist/icons/markdown.svg.js +8 -0
  51. package/dist/icons/more_horiz.svg.js +8 -0
  52. package/dist/icons/open_in_new.svg.js +8 -0
  53. package/dist/icons/redo.svg.js +8 -0
  54. package/dist/icons/rich_text.svg.js +8 -0
  55. package/dist/icons/settings.svg.js +8 -0
  56. package/dist/icons/table.svg.js +8 -0
  57. package/dist/icons/undo.svg.js +8 -0
  58. package/dist/importMarkdownToLexical.d.ts +84 -0
  59. package/dist/importMarkdownToLexical.js +65 -0
  60. package/dist/index.d.ts +49 -1094
  61. package/dist/index.js +133 -72
  62. package/dist/jsx-editors/GenericJsxEditor.d.ts +3 -0
  63. package/dist/jsx-editors/GenericJsxEditor.js +56 -0
  64. package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
  65. package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
  66. package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
  67. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
  68. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  69. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
  70. package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
  71. package/dist/plugins/codeblock/index.d.ts +604 -0
  72. package/dist/plugins/codeblock/index.js +73 -0
  73. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
  74. package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
  75. package/dist/plugins/codemirror/index.d.ts +786 -0
  76. package/dist/plugins/codemirror/index.js +62 -0
  77. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
  78. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  79. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
  80. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  81. package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
  82. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  83. package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
  84. package/dist/plugins/core/LexicalTextVisitor.js +85 -0
  85. package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
  86. package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
  87. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
  88. package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
  89. package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
  90. package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
  91. package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
  92. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  93. package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
  94. package/dist/plugins/core/MdastTextVisitor.js +10 -0
  95. package/dist/plugins/core/NestedLexicalEditor.d.ts +69 -0
  96. package/dist/plugins/core/NestedLexicalEditor.js +181 -0
  97. package/dist/plugins/core/PropertyPopover.d.ts +8 -0
  98. package/dist/plugins/core/PropertyPopover.js +36 -0
  99. package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
  100. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  101. package/dist/plugins/core/index.d.ts +419 -0
  102. package/dist/plugins/core/index.js +343 -0
  103. package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
  104. package/dist/plugins/core/ui/PopoverUtils.js +17 -0
  105. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
  106. package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
  107. package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
  108. package/dist/plugins/diff-source/DiffViewer.js +18 -0
  109. package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
  110. package/dist/plugins/diff-source/SourceEditor.js +25 -0
  111. package/dist/plugins/diff-source/index.d.ts +530 -0
  112. package/dist/plugins/diff-source/index.js +55 -0
  113. package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
  114. package/dist/plugins/directives/DirectiveNode.js +92 -0
  115. package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
  116. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  117. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
  118. package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
  119. package/dist/plugins/directives/index.d.ts +591 -0
  120. package/dist/plugins/directives/index.js +53 -0
  121. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
  122. package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
  123. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
  124. package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
  125. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
  126. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  127. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
  128. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  129. package/dist/plugins/frontmatter/index.d.ts +510 -0
  130. package/dist/plugins/frontmatter/index.js +53 -0
  131. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
  132. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  133. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
  134. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  135. package/dist/plugins/headings/index.d.ts +105 -0
  136. package/dist/plugins/headings/index.js +20 -0
  137. package/dist/plugins/image/ImageEditor.d.ts +7 -0
  138. package/dist/{ImageEditor-ad505654.js → plugins/image/ImageEditor.js} +12 -47
  139. package/dist/plugins/image/ImageNode.d.ts +53 -0
  140. package/dist/plugins/image/ImageNode.js +108 -0
  141. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  142. package/dist/plugins/image/LexicalImageVisitor.js +15 -0
  143. package/dist/plugins/image/MdastImageVisitor.d.ts +3 -0
  144. package/dist/plugins/image/MdastImageVisitor.js +16 -0
  145. package/dist/plugins/image/index.d.ts +541 -0
  146. package/dist/plugins/image/index.js +244 -0
  147. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  148. package/dist/plugins/jsx/LexicalJsxNode.js +99 -0
  149. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  150. package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
  151. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  152. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  153. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  154. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  155. package/dist/plugins/jsx/index.d.ts +461 -0
  156. package/dist/plugins/jsx/index.js +37 -0
  157. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  158. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  159. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  160. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  161. package/dist/plugins/link/index.d.ts +108 -0
  162. package/dist/plugins/link/index.js +24 -0
  163. package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
  164. package/dist/plugins/link-dialog/LinkDialog.js +174 -0
  165. package/dist/plugins/link-dialog/index.d.ts +496 -0
  166. package/dist/plugins/link-dialog/index.js +242 -0
  167. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  168. package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
  169. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  170. package/dist/plugins/lists/LexicalListVisitor.js +14 -0
  171. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  172. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  173. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  174. package/dist/plugins/lists/MdastListVisitor.js +18 -0
  175. package/dist/plugins/lists/index.d.ts +521 -0
  176. package/dist/plugins/lists/index.js +111 -0
  177. package/dist/plugins/markdown-shortcut/index.d.ts +51 -0
  178. package/dist/plugins/markdown-shortcut/index.js +34 -0
  179. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  180. package/dist/plugins/quote/LexicalQuoteVisitor.js +14 -0
  181. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  182. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  183. package/dist/plugins/quote/index.d.ts +348 -0
  184. package/dist/plugins/quote/index.js +26 -0
  185. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  186. package/dist/plugins/sandpack/SandpackEditor.js +35 -0
  187. package/dist/plugins/sandpack/index.d.ts +826 -0
  188. package/dist/plugins/sandpack/index.js +93 -0
  189. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  190. package/dist/{useCodeMirrorRef-177e9901.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
  191. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  192. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  193. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  194. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  195. package/dist/plugins/table/TableEditor.d.ts +21 -0
  196. package/dist/{TableEditor-44bef804.js → plugins/table/TableEditor.js} +109 -161
  197. package/dist/plugins/table/TableNode.d.ts +52 -0
  198. package/dist/plugins/table/TableNode.js +147 -0
  199. package/dist/plugins/table/index.d.ts +511 -0
  200. package/dist/plugins/table/index.js +59 -0
  201. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  202. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  203. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  204. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  205. package/dist/plugins/thematic-break/index.d.ts +510 -0
  206. package/dist/plugins/thematic-break/index.js +39 -0
  207. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +2 -0
  208. package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
  209. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +2 -0
  210. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
  211. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +2 -0
  212. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  213. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +2 -0
  214. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  215. package/dist/plugins/toolbar/components/CodeToggle.d.ts +2 -0
  216. package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
  217. package/dist/plugins/toolbar/components/CreateLink.d.ts +2 -0
  218. package/dist/plugins/toolbar/components/CreateLink.js +11 -0
  219. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +4 -0
  220. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
  221. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +2 -0
  222. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  223. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +2 -0
  224. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  225. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +2 -0
  226. package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
  227. package/dist/plugins/toolbar/components/InsertImage.d.ts +2 -0
  228. package/dist/plugins/toolbar/components/InsertImage.js +23 -0
  229. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +2 -0
  230. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  231. package/dist/plugins/toolbar/components/InsertTable.d.ts +2 -0
  232. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  233. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +2 -0
  234. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  235. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +2 -0
  236. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  237. package/dist/plugins/toolbar/components/ListsToggle.d.ts +2 -0
  238. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  239. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +2 -0
  240. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
  241. package/dist/plugins/toolbar/components/UndoRedo.d.ts +2 -0
  242. package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
  243. package/dist/plugins/toolbar/index.d.ts +416 -0
  244. package/dist/plugins/toolbar/index.js +39 -0
  245. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  246. package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
  247. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +5 -0
  248. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  249. package/dist/plugins/toolbar/primitives/select.d.ts +31 -0
  250. package/dist/plugins/toolbar/primitives/select.js +44 -0
  251. package/dist/plugins/toolbar/primitives/toolbar.d.ts +85 -0
  252. package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
  253. package/dist/style.css +480 -240
  254. package/dist/styles/globals.css.js +4 -0
  255. package/dist/styles/lexical-theme.module.css.js +53 -0
  256. package/dist/styles/lexicalTheme.d.ts +2 -0
  257. package/dist/styles/lexicalTheme.js +28 -0
  258. package/dist/styles/ui.module.css.js +227 -0
  259. package/dist/utils/detectMac.d.ts +2 -0
  260. package/dist/utils/detectMac.js +6 -0
  261. package/dist/utils/fp.d.ts +47 -0
  262. package/dist/utils/fp.js +10 -0
  263. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  264. package/dist/utils/isPartOftheEditorUI.js +12 -0
  265. package/dist/utils/lexicalHelpers.d.ts +11 -0
  266. package/dist/utils/lexicalHelpers.js +49 -0
  267. package/dist/utils/uuid4.d.ts +1 -0
  268. package/dist/utils/uuid4.js +10 -0
  269. package/dist/utils/voidEmitter.d.ts +14 -0
  270. package/dist/utils/voidEmitter.js +15 -0
  271. package/package.json +184 -14
  272. package/dist/CodeBlockEditor-ce4c85ed.js +0 -79
  273. package/dist/CodeBlockEditor-ed222322.cjs +0 -1
  274. package/dist/FrontmatterEditor-914aa241.cjs +0 -1
  275. package/dist/FrontmatterEditor-e2f25a6a.js +0 -118
  276. package/dist/ImageEditor-c4e65554.cjs +0 -1
  277. package/dist/JsxEditor-6cff258d.cjs +0 -1
  278. package/dist/JsxEditor-88d55ef8.js +0 -108
  279. package/dist/LeafDirectiveEditor-0e1328e6.cjs +0 -1
  280. package/dist/LeafDirectiveEditor-34ead530.js +0 -59
  281. package/dist/SandpackEditor-a999ca47.cjs +0 -1
  282. package/dist/SandpackEditor-b1e22784.js +0 -99
  283. package/dist/SourceEditor-0c46ec47.cjs +0 -1
  284. package/dist/SourceEditor-e509d0a5.js +0 -64
  285. package/dist/TableEditor-ced03ce4.cjs +0 -1
  286. package/dist/index-21fcefae.cjs +0 -1
  287. package/dist/index-ce0832cc.js +0 -4361
  288. package/dist/index.cjs +0 -1
  289. package/dist/useCodeMirrorRef-6cb866bd.cjs +0 -1
@@ -0,0 +1,53 @@
1
+ import { coreSystem } from "../core/index.js";
2
+ import { directive } from "micromark-extension-directive";
3
+ import { directiveFromMarkdown, directiveToMarkdown } from "mdast-util-directive";
4
+ import { $createDirectiveNode, DirectiveNode } from "./DirectiveNode.js";
5
+ import { DirectiveVisitor } from "./DirectiveVisitor.js";
6
+ 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) || []);
39
+ },
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);
47
+ }
48
+ });
49
+ export {
50
+ directivesPlugin,
51
+ directivesPluginHooks,
52
+ directivesSystem
53
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface FrontmatterEditorProps {
3
+ yaml: string;
4
+ onChange: (yaml: string) => void;
5
+ }
6
+ export declare const FrontmatterEditor: ({ yaml, onChange }: FrontmatterEditorProps) => React.JSX.Element;
@@ -0,0 +1,69 @@
1
+ import classNames from "classnames";
2
+ import YamlParser from "js-yaml";
3
+ import React__default from "react";
4
+ import { useForm, useFieldArray } from "react-hook-form";
5
+ import DropDownIcon from "../../icons/arrow_drop_down.svg.js";
6
+ import ArrowRight from "../../icons/arrow_right.svg.js";
7
+ import DeleteIcon from "../../icons/delete.svg.js";
8
+ import styles from "../../styles/ui.module.css.js";
9
+ const FrontmatterEditor = ({ yaml, onChange }) => {
10
+ const [expanded, setExpanded] = React__default.useState(true);
11
+ const yamlConfig = React__default.useMemo(() => {
12
+ if (!yaml) {
13
+ return [];
14
+ }
15
+ return Object.entries(YamlParser.load(yaml)).map(([key, value]) => ({ key, value }));
16
+ }, [yaml]);
17
+ const { register, control, watch } = useForm({
18
+ defaultValues: {
19
+ yamlConfig
20
+ }
21
+ });
22
+ const { fields, append, remove } = useFieldArray({
23
+ control,
24
+ name: "yamlConfig"
25
+ });
26
+ React__default.useEffect(() => {
27
+ const subscription = watch(({ yamlConfig: yamlConfig2 }) => {
28
+ const yaml2 = yamlConfig2.reduce((acc, { key, value }) => {
29
+ if (key && value) {
30
+ acc[key] = value;
31
+ }
32
+ return acc;
33
+ }, {});
34
+ onChange(YamlParser.dump(yaml2).trim());
35
+ });
36
+ return () => subscription.unsubscribe();
37
+ }, [watch, onChange]);
38
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.frontmatterWrapper, "data-expanded": expanded, "data-editor-type": "frontmatter" }, /* @__PURE__ */ React__default.createElement(
39
+ "button",
40
+ {
41
+ className: styles.frontmatterToggleButton,
42
+ onClick: (e) => {
43
+ e.preventDefault();
44
+ setExpanded((v) => !v);
45
+ }
46
+ },
47
+ expanded ? /* @__PURE__ */ React__default.createElement(DropDownIcon, null) : /* @__PURE__ */ React__default.createElement(ArrowRight, null),
48
+ "Document frontmatter"
49
+ ), expanded && /* @__PURE__ */ React__default.createElement("form", null, /* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, "Key"), /* @__PURE__ */ React__default.createElement("th", null, "Value"), /* @__PURE__ */ React__default.createElement("th", null))), /* @__PURE__ */ React__default.createElement("tbody", null, fields.map((item, index) => {
50
+ return /* @__PURE__ */ React__default.createElement("tr", { key: item.id }, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.key`, { required: true }), autofocusIfEmpty: true })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.value`, { required: true }) })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("button", { type: "button", onClick: () => remove(index), className: styles.iconButton }, /* @__PURE__ */ React__default.createElement(DeleteIcon, null))));
51
+ })), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
52
+ "button",
53
+ {
54
+ className: styles.primaryButton,
55
+ type: "button",
56
+ onClick: () => {
57
+ append({ key: "", value: "" });
58
+ }
59
+ },
60
+ "Add new key"
61
+ )))))));
62
+ };
63
+ const TableInput = React__default.forwardRef(({ className, autofocusIfEmpty, ...props }, ref) => {
64
+ props.autoFocus = Boolean(!props.value && autofocusIfEmpty);
65
+ return /* @__PURE__ */ React__default.createElement("input", { className: classNames(styles.propertyEditorInput, className), ...props, ref });
66
+ });
67
+ export {
68
+ FrontmatterEditor
69
+ };
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { DecoratorNode, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
3
+ /**
4
+ * A serialized representation of an {@link FrontmatterNode}.
5
+ */
6
+ export type SerializedFrontmatterNode = Spread<{
7
+ yaml: string;
8
+ version: 1;
9
+ }, SerializedLexicalNode>;
10
+ /**
11
+ * Represents {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | the frontmatter} of the markdown document.
12
+ * Use {@link "$createFrontmatterNode"} to construct one.
13
+ */
14
+ export declare class FrontmatterNode extends DecoratorNode<JSX.Element> {
15
+ __yaml: string;
16
+ static getType(): string;
17
+ static clone(node: FrontmatterNode): FrontmatterNode;
18
+ static importJSON(serializedNode: SerializedFrontmatterNode): FrontmatterNode;
19
+ constructor(code: string, key?: NodeKey);
20
+ exportJSON(): SerializedFrontmatterNode;
21
+ createDOM(_config: EditorConfig): HTMLDivElement;
22
+ updateDOM(): false;
23
+ getYaml(): string;
24
+ setYaml(yaml: string): void;
25
+ decorate(editor: LexicalEditor): JSX.Element;
26
+ }
27
+ /**
28
+ * Creates a {@link FrontmatterNode}.
29
+ * @param yaml - The YAML string of the frontmatter.
30
+ */
31
+ export declare function $createFrontmatterNode(yaml: string): FrontmatterNode;
32
+ /**
33
+ * Returns `true` if the given node is a {@link FrontmatterNode}.
34
+ */
35
+ export declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node is FrontmatterNode;
@@ -0,0 +1,71 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { DecoratorNode } from "lexical";
8
+ import React__default from "react";
9
+ import { FrontmatterEditor } from "./FrontmatterEditor.js";
10
+ class FrontmatterNode extends DecoratorNode {
11
+ constructor(code, key) {
12
+ super(key);
13
+ __publicField(this, "__yaml");
14
+ this.__yaml = code;
15
+ }
16
+ static getType() {
17
+ return "frontmatter";
18
+ }
19
+ static clone(node) {
20
+ return new FrontmatterNode(node.__yaml, node.__key);
21
+ }
22
+ static importJSON(serializedNode) {
23
+ const { yaml } = serializedNode;
24
+ const node = $createFrontmatterNode(yaml);
25
+ return node;
26
+ }
27
+ exportJSON() {
28
+ return {
29
+ yaml: this.getYaml(),
30
+ type: "frontmatter",
31
+ version: 1
32
+ };
33
+ }
34
+ // View
35
+ createDOM(_config) {
36
+ return document.createElement("div");
37
+ }
38
+ updateDOM() {
39
+ return false;
40
+ }
41
+ getYaml() {
42
+ return this.getLatest().__yaml;
43
+ }
44
+ setYaml(yaml) {
45
+ if (yaml !== this.__yaml) {
46
+ this.getWritable().__yaml = yaml;
47
+ }
48
+ }
49
+ decorate(editor) {
50
+ return /* @__PURE__ */ React__default.createElement(
51
+ FrontmatterEditor,
52
+ {
53
+ yaml: this.getYaml(),
54
+ onChange: (yaml) => editor == null ? void 0 : editor.update(() => {
55
+ this.setYaml(yaml);
56
+ })
57
+ }
58
+ );
59
+ }
60
+ }
61
+ function $createFrontmatterNode(yaml) {
62
+ return new FrontmatterNode(yaml);
63
+ }
64
+ function $isFrontmatterNode(node) {
65
+ return node instanceof FrontmatterNode;
66
+ }
67
+ export {
68
+ $createFrontmatterNode,
69
+ $isFrontmatterNode,
70
+ FrontmatterNode
71
+ };
@@ -0,0 +1,4 @@
1
+ import * as Mdast from 'mdast';
2
+ import { LexicalExportVisitor } from '../../exportMarkdownFromLexical';
3
+ import { FrontmatterNode } from './FrontmatterNode';
4
+ export declare const LexicalFrontmatterVisitor: LexicalExportVisitor<FrontmatterNode, Mdast.YAML>;
@@ -0,0 +1,10 @@
1
+ import { $isFrontmatterNode } from "./FrontmatterNode.js";
2
+ const LexicalFrontmatterVisitor = {
3
+ testLexicalNode: $isFrontmatterNode,
4
+ visitLexicalNode: ({ actions, lexicalNode }) => {
5
+ actions.addAndStepInto("yaml", { value: lexicalNode.getYaml() });
6
+ }
7
+ };
8
+ export {
9
+ LexicalFrontmatterVisitor
10
+ };
@@ -0,0 +1,3 @@
1
+ import * as Mdast from 'mdast';
2
+ import { MdastImportVisitor } from '../../importMarkdownToLexical';
3
+ export declare const MdastFrontmatterVisitor: MdastImportVisitor<Mdast.YAML>;
@@ -0,0 +1,10 @@
1
+ import { $createFrontmatterNode } from "./FrontmatterNode.js";
2
+ const MdastFrontmatterVisitor = {
3
+ testNode: "yaml",
4
+ visitNode({ mdastNode, actions }) {
5
+ actions.addAndStepInto($createFrontmatterNode(mdastNode.value));
6
+ }
7
+ };
8
+ export {
9
+ MdastFrontmatterVisitor
10
+ };