@mdxeditor/editor 0.10.1 → 0.11.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 (293) hide show
  1. package/README.md +4 -3
  2. package/dist/FormatConstants.d.ts +9 -0
  3. package/dist/FormatConstants.js +10 -0
  4. package/dist/MDXEditor.d.ts +60 -0
  5. package/dist/MDXEditor.js +105 -0
  6. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
  7. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
  8. package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -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 -1105
  62. package/dist/index.js +140 -72
  63. package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -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 +617 -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 +800 -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 +96 -0
  97. package/dist/plugins/core/NestedLexicalEditor.js +181 -0
  98. package/dist/plugins/core/PropertyPopover.d.ts +23 -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 +423 -0
  103. package/dist/plugins/core/index.js +346 -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 +27 -0
  112. package/dist/plugins/diff-source/index.d.ts +544 -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 +603 -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 +523 -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 +118 -0
  137. package/dist/plugins/headings/index.js +20 -0
  138. package/dist/plugins/image/ImageEditor.d.ts +9 -0
  139. package/dist/{ImageEditor-8db2f131.js → plugins/image/ImageEditor.js} +40 -52
  140. package/dist/plugins/image/ImageNode.d.ts +63 -0
  141. package/dist/plugins/image/ImageNode.js +136 -0
  142. package/dist/plugins/image/ImageResizer.d.ts +18 -0
  143. package/dist/plugins/image/ImageResizer.js +214 -0
  144. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  145. package/dist/plugins/image/LexicalImageVisitor.js +36 -0
  146. package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
  147. package/dist/plugins/image/MdastImageVisitor.js +87 -0
  148. package/dist/plugins/image/index.d.ts +557 -0
  149. package/dist/plugins/image/index.js +246 -0
  150. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  151. package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
  152. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  153. package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
  154. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  155. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  156. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  157. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  158. package/dist/plugins/jsx/index.d.ts +599 -0
  159. package/dist/plugins/jsx/index.js +59 -0
  160. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  161. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  162. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  163. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  164. package/dist/plugins/link/index.d.ts +68 -0
  165. package/dist/plugins/link/index.js +22 -0
  166. package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
  167. package/dist/plugins/link-dialog/LinkDialog.js +174 -0
  168. package/dist/plugins/link-dialog/index.d.ts +508 -0
  169. package/dist/plugins/link-dialog/index.js +242 -0
  170. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  171. package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
  172. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  173. package/dist/plugins/lists/LexicalListVisitor.js +13 -0
  174. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  175. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  176. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  177. package/dist/plugins/lists/MdastListVisitor.js +18 -0
  178. package/dist/plugins/lists/index.d.ts +533 -0
  179. package/dist/plugins/lists/index.js +111 -0
  180. package/dist/plugins/markdown-shortcut/index.d.ts +63 -0
  181. package/dist/plugins/markdown-shortcut/index.js +34 -0
  182. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  183. package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
  184. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  185. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  186. package/dist/plugins/quote/index.d.ts +361 -0
  187. package/dist/plugins/quote/index.js +26 -0
  188. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  189. package/dist/plugins/sandpack/SandpackEditor.js +35 -0
  190. package/dist/plugins/sandpack/index.d.ts +839 -0
  191. package/dist/plugins/sandpack/index.js +93 -0
  192. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  193. package/dist/{useCodeMirrorRef-5356dfa5.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
  194. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  195. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  196. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  197. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  198. package/dist/plugins/table/TableEditor.d.ts +21 -0
  199. package/dist/plugins/table/TableEditor.js +384 -0
  200. package/dist/plugins/table/TableNode.d.ts +52 -0
  201. package/dist/plugins/table/TableNode.js +147 -0
  202. package/dist/plugins/table/index.d.ts +523 -0
  203. package/dist/plugins/table/index.js +59 -0
  204. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  205. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  206. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  207. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  208. package/dist/plugins/thematic-break/index.d.ts +523 -0
  209. package/dist/plugins/thematic-break/index.js +39 -0
  210. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
  211. package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
  212. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
  213. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
  214. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
  215. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  216. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
  217. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  218. package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
  219. package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
  220. package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
  221. package/dist/plugins/toolbar/components/CreateLink.js +11 -0
  222. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
  223. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
  224. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
  225. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  226. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
  227. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  228. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
  229. package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
  230. package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
  231. package/dist/plugins/toolbar/components/InsertImage.js +23 -0
  232. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
  233. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  234. package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
  235. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  236. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
  237. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  238. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
  239. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  240. package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
  241. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  242. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
  243. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
  244. package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
  245. package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
  246. package/dist/plugins/toolbar/index.d.ts +428 -0
  247. package/dist/plugins/toolbar/index.js +39 -0
  248. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  249. package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
  250. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
  251. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  252. package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
  253. package/dist/plugins/toolbar/primitives/select.js +44 -0
  254. package/dist/plugins/toolbar/primitives/toolbar.d.ts +160 -0
  255. package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
  256. package/dist/style.css +556 -249
  257. package/dist/styles/globals.css.js +4 -0
  258. package/dist/styles/lexical-theme.module.css.js +53 -0
  259. package/dist/styles/lexicalTheme.d.ts +2 -0
  260. package/dist/styles/lexicalTheme.js +28 -0
  261. package/dist/styles/ui.module.css.js +254 -0
  262. package/dist/utils/detectMac.d.ts +2 -0
  263. package/dist/utils/detectMac.js +6 -0
  264. package/dist/utils/fp.d.ts +47 -0
  265. package/dist/utils/fp.js +10 -0
  266. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  267. package/dist/utils/isPartOftheEditorUI.js +12 -0
  268. package/dist/utils/lexicalHelpers.d.ts +11 -0
  269. package/dist/utils/lexicalHelpers.js +49 -0
  270. package/dist/utils/uuid4.d.ts +1 -0
  271. package/dist/utils/uuid4.js +10 -0
  272. package/dist/utils/voidEmitter.d.ts +14 -0
  273. package/dist/utils/voidEmitter.js +15 -0
  274. package/package.json +246 -14
  275. package/dist/CodeBlockEditor-02116cba.js +0 -79
  276. package/dist/CodeBlockEditor-1c7b46dc.cjs +0 -1
  277. package/dist/FrontmatterEditor-37a4c091.cjs +0 -1
  278. package/dist/FrontmatterEditor-988a8fb6.js +0 -118
  279. package/dist/ImageEditor-524159e9.cjs +0 -1
  280. package/dist/JsxEditor-606e9d86.js +0 -108
  281. package/dist/JsxEditor-98a94a9d.cjs +0 -1
  282. package/dist/LeafDirectiveEditor-38a73f5c.js +0 -59
  283. package/dist/LeafDirectiveEditor-dfa1ce78.cjs +0 -1
  284. package/dist/SandpackEditor-90425f26.cjs +0 -1
  285. package/dist/SandpackEditor-c771b4d0.js +0 -100
  286. package/dist/SourceEditor-19eb2c9e.js +0 -64
  287. package/dist/SourceEditor-46ed1f77.cjs +0 -1
  288. package/dist/TableEditor-4a993dab.cjs +0 -1
  289. package/dist/TableEditor-c28b3ca2.js +0 -426
  290. package/dist/index-1ab1a12e.js +0 -4363
  291. package/dist/index-8217810f.cjs +0 -1
  292. package/dist/index.cjs +0 -1
  293. package/dist/useCodeMirrorRef-7055e7de.cjs +0 -1
@@ -0,0 +1,93 @@
1
+ import React__default from "react";
2
+ import { coreSystem } from "../core/index.js";
3
+ import { codeBlockSystem } from "../codeblock/index.js";
4
+ import { SandpackEditor } from "./SandpackEditor.js";
5
+ import { system } from "../../gurx/realmFactory.js";
6
+ import { realmPlugin } from "../../gurx/react.js";
7
+ const defaultSnippetContent = `
8
+ export default function App() {
9
+ return (
10
+ <div className="App">
11
+ <h1>Hello CodeSandbox</h1>
12
+ <h2>Start editing to see some magic happen!</h2>
13
+ </div>
14
+ );
15
+ }
16
+ `;
17
+ const defaultSandpackConfig = {
18
+ defaultPreset: "react",
19
+ presets: [
20
+ {
21
+ name: "react",
22
+ meta: "live react",
23
+ label: "React",
24
+ sandpackTemplate: "react",
25
+ sandpackTheme: "light",
26
+ snippetFileName: "/App.js",
27
+ snippetLanguage: "jsx",
28
+ initialSnippetContent: defaultSnippetContent
29
+ }
30
+ ]
31
+ };
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", {
74
+ match(_language, meta) {
75
+ return meta == null ? void 0 : meta.startsWith("live");
76
+ },
77
+ priority: 1,
78
+ Editor(props) {
79
+ const [config] = sandpackPluginHooks.useEmitterValues("sandpackConfig");
80
+ const preset = config.presets.find((preset2) => preset2.meta === props.meta);
81
+ if (!preset) {
82
+ throw new Error(`No sandpack preset found with ${props.meta}`);
83
+ }
84
+ return /* @__PURE__ */ React__default.createElement(SandpackEditor, { ...props, preset });
85
+ }
86
+ });
87
+ }
88
+ });
89
+ export {
90
+ sandpackPlugin,
91
+ sandpackPluginHooks,
92
+ sandpackSystem
93
+ };
@@ -0,0 +1,4 @@
1
+ import { CodeMirrorRef } from '@codesandbox/sandpack-react/dist/components/CodeEditor/CodeMirror';
2
+ import React from 'react';
3
+ import { VoidEmitter } from '../../utils/voidEmitter';
4
+ export declare function useCodeMirrorRef(nodeKey: string, editorType: 'codeblock' | 'sandpack', language: string, focusEmitter: VoidEmitter): React.RefObject<CodeMirrorRef>;
@@ -1,15 +1,20 @@
1
1
  import { $getNodeByKey, $createParagraphNode } from "lexical";
2
2
  import React__default from "react";
3
- import { u as useEmitterValues, a as usePublisher } from "./index-1ab1a12e.js";
4
- function useCodeMirrorRef(nodeKey, editorType, language) {
5
- const [activeEditor] = useEmitterValues("activeEditor");
6
- const setActiveEditorType = usePublisher("activeEditorType");
3
+ import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
4
+ import { corePluginHooks } from "../core/index.js";
5
+ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
6
+ const [theEditor] = corePluginHooks.useEmitterValues("activeEditor");
7
+ const setEditorInFocus = corePluginHooks.usePublisher("editorInFocus");
7
8
  const codeMirrorRef = React__default.useRef(null);
9
+ const { lexicalNode } = useCodeBlockEditorContext();
8
10
  const atBottom = React__default.useRef(false);
9
11
  const atTop = React__default.useRef(false);
10
12
  const onFocusHandler = React__default.useCallback(() => {
11
- setActiveEditorType({ type: editorType, nodeKey });
12
- }, [nodeKey, setActiveEditorType, editorType]);
13
+ setEditorInFocus({
14
+ editorType,
15
+ rootNode: lexicalNode
16
+ });
17
+ }, [editorType, lexicalNode, setEditorInFocus]);
13
18
  const onKeyDownHandler = React__default.useCallback(
14
19
  (e) => {
15
20
  var _a, _b, _c, _d;
@@ -22,7 +27,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
22
27
  if (!atBottom.current) {
23
28
  atBottom.current = true;
24
29
  } else {
25
- activeEditor == null ? void 0 : activeEditor.update(() => {
30
+ theEditor == null ? void 0 : theEditor.update(() => {
26
31
  var _a2, _b2;
27
32
  const node = $getNodeByKey(nodeKey);
28
33
  const nextSibling = node.getNextSibling();
@@ -45,7 +50,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
45
50
  if (!atTop.current) {
46
51
  atTop.current = true;
47
52
  } else {
48
- activeEditor == null ? void 0 : activeEditor.update(() => {
53
+ theEditor == null ? void 0 : theEditor.update(() => {
49
54
  var _a2, _b2;
50
55
  const node = $getNodeByKey(nodeKey);
51
56
  const previousSibling = node.getPreviousSibling();
@@ -62,7 +67,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
62
67
  e.stopPropagation();
63
68
  }
64
69
  },
65
- [activeEditor, nodeKey]
70
+ [theEditor, nodeKey]
66
71
  );
67
72
  React__default.useEffect(() => {
68
73
  const codeMirror = codeMirrorRef.current;
@@ -77,8 +82,15 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
77
82
  (_b = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _b.contentDOM.removeEventListener("keydown", onKeyDownHandler);
78
83
  };
79
84
  }, [codeMirrorRef, onFocusHandler, onKeyDownHandler, language]);
85
+ React__default.useEffect(() => {
86
+ focusEmitter.subscribe(() => {
87
+ var _a, _b;
88
+ (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
89
+ onFocusHandler();
90
+ });
91
+ }, [focusEmitter, codeMirrorRef, nodeKey, onFocusHandler]);
80
92
  return codeMirrorRef;
81
93
  }
82
94
  export {
83
- useCodeMirrorRef as u
95
+ useCodeMirrorRef
84
96
  };
@@ -0,0 +1,4 @@
1
+ import * as Mdast from 'mdast';
2
+ import { TableNode } from './TableNode';
3
+ import { LexicalExportVisitor } from '../../exportMarkdownFromLexical';
4
+ export declare const LexicalTableVisitor: LexicalExportVisitor<TableNode, Mdast.Table>;
@@ -0,0 +1,10 @@
1
+ import { $isTableNode } from "./TableNode.js";
2
+ const LexicalTableVisitor = {
3
+ testLexicalNode: $isTableNode,
4
+ visitLexicalNode({ actions, mdastParent, lexicalNode }) {
5
+ actions.appendToParent(mdastParent, lexicalNode.getMdastNode());
6
+ }
7
+ };
8
+ export {
9
+ LexicalTableVisitor
10
+ };
@@ -0,0 +1,3 @@
1
+ import * as Mdast from 'mdast';
2
+ import { MdastImportVisitor } from '../../importMarkdownToLexical';
3
+ export declare const MdastTableVisitor: MdastImportVisitor<Mdast.Table>;
@@ -0,0 +1,10 @@
1
+ import { $createTableNode } from "./TableNode.js";
2
+ const MdastTableVisitor = {
3
+ testNode: "table",
4
+ visitNode({ mdastNode, lexicalParent }) {
5
+ lexicalParent.append($createTableNode(mdastNode));
6
+ }
7
+ };
8
+ export {
9
+ MdastTableVisitor
10
+ };
@@ -0,0 +1,21 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ import * as Mdast from 'mdast';
3
+ import React from 'react';
4
+ import { TableNode } from './TableNode';
5
+ export interface TableEditorProps {
6
+ parentEditor: LexicalEditor;
7
+ lexicalTable: TableNode;
8
+ mdastNode: Mdast.Table;
9
+ }
10
+ export declare const TableEditor: React.FC<TableEditorProps>;
11
+ export interface CellProps {
12
+ parentEditor: LexicalEditor;
13
+ lexicalTable: TableNode;
14
+ contents: Mdast.PhrasingContent[];
15
+ colIndex: number;
16
+ rowIndex: number;
17
+ align?: Mdast.AlignType;
18
+ activeCell: [number, number] | null;
19
+ setActiveCell: (cell: [number, number] | null) => void;
20
+ focus: boolean;
21
+ }
@@ -0,0 +1,384 @@
1
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
2
+ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
3
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
4
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
5
+ import * as RadixPopover from "@radix-ui/react-popover";
6
+ import { $createParagraphNode, createEditor, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND } from "lexical";
7
+ import React__default from "react";
8
+ import { lexicalTheme } from "../../styles/lexicalTheme.js";
9
+ import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
10
+ import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
11
+ import AddColumnIcon from "../../icons/add_column.svg.js";
12
+ import AddRowIcon from "../../icons/add_row.svg.js";
13
+ import DeleteSmallIcon from "../../icons/delete_small.svg.js";
14
+ import AlignCenterIcon from "../../icons/format_align_center.svg.js";
15
+ import AlignLeftIcon from "../../icons/format_align_left.svg.js";
16
+ import AlignRightIcon from "../../icons/format_align_right.svg.js";
17
+ import InsertColLeftIcon from "../../icons/insert_col_left.svg.js";
18
+ import InsertColRightIcon from "../../icons/insert_col_right.svg.js";
19
+ import InsertRowAboveIcon from "../../icons/insert_row_above.svg.js";
20
+ import InsertRowBelowIcon from "../../icons/insert_row_below.svg.js";
21
+ import MoreHorizIcon from "../../icons/more_horiz.svg.js";
22
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
23
+ import classNames from "classnames";
24
+ import styles from "../../styles/ui.module.css.js";
25
+ import { corePluginHooks } from "../core/index.js";
26
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
27
+ import { mergeRegister } from "@lexical/utils";
28
+ import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
29
+ const AlignToTailwindClassMap = {
30
+ center: styles.centeredCell,
31
+ left: styles.leftAlignedCell,
32
+ right: styles.rightAlignedCell
33
+ };
34
+ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
35
+ const [activeCell, setActiveCell] = React__default.useState(null);
36
+ const setActiveCellWithBoundaries = React__default.useCallback(
37
+ (cell) => {
38
+ const colCount = lexicalTable.getColCount();
39
+ if (cell === null) {
40
+ setActiveCell(null);
41
+ return;
42
+ }
43
+ let [colIndex, rowIndex] = cell;
44
+ if (colIndex > colCount - 1) {
45
+ colIndex = 0;
46
+ rowIndex++;
47
+ }
48
+ if (colIndex < 0) {
49
+ colIndex = colCount - 1;
50
+ rowIndex -= 1;
51
+ }
52
+ if (rowIndex > lexicalTable.getRowCount() - 1) {
53
+ setActiveCell(null);
54
+ parentEditor.update(() => {
55
+ const nextSibling = lexicalTable.getLatest().getNextSibling();
56
+ if (nextSibling) {
57
+ lexicalTable.getLatest().selectNext();
58
+ } else {
59
+ const newParagraph = $createParagraphNode();
60
+ lexicalTable.insertAfter(newParagraph);
61
+ newParagraph.select();
62
+ }
63
+ });
64
+ return;
65
+ }
66
+ if (rowIndex < 0) {
67
+ setActiveCell(null);
68
+ parentEditor.update(() => {
69
+ lexicalTable.getLatest().selectPrevious();
70
+ });
71
+ return;
72
+ }
73
+ setActiveCell([colIndex, rowIndex]);
74
+ },
75
+ [lexicalTable, parentEditor]
76
+ );
77
+ React__default.useEffect(() => {
78
+ lexicalTable.focusEmitter.subscribe(setActiveCellWithBoundaries);
79
+ }, [lexicalTable, setActiveCellWithBoundaries]);
80
+ const addRowToBottom = React__default.useCallback(
81
+ (e) => {
82
+ e.preventDefault();
83
+ parentEditor.update(() => {
84
+ lexicalTable.addRowToBottom();
85
+ setActiveCell([0, lexicalTable.getRowCount()]);
86
+ });
87
+ },
88
+ [parentEditor, lexicalTable]
89
+ );
90
+ const addColumnToRight = React__default.useCallback(
91
+ (e) => {
92
+ e.preventDefault();
93
+ parentEditor.update(() => {
94
+ lexicalTable.addColumnToRight();
95
+ setActiveCell([lexicalTable.getColCount(), 0]);
96
+ });
97
+ },
98
+ [parentEditor, lexicalTable]
99
+ );
100
+ const [highlightedCoordinates, setHighlightedCoordinates] = React__default.useState([-1, -1]);
101
+ const onTableMouseOver = React__default.useCallback((e) => {
102
+ let tableCell = e.target;
103
+ while (tableCell && !["TH", "TD"].includes(tableCell.tagName)) {
104
+ if (tableCell === e.currentTarget) {
105
+ return;
106
+ }
107
+ tableCell = tableCell.parentElement;
108
+ }
109
+ if (tableCell === null) {
110
+ return;
111
+ }
112
+ const tableRow = tableCell.parentElement;
113
+ const tableContainer = tableRow.parentElement;
114
+ const colIndex = tableContainer.tagName === "TFOOT" ? -1 : Array.from(tableRow.children).indexOf(tableCell);
115
+ const rowIndex = tableCell.tagName === "TH" ? -1 : Array.from(tableRow.parentElement.children).indexOf(tableRow);
116
+ setHighlightedCoordinates([colIndex, rowIndex]);
117
+ }, []);
118
+ return /* @__PURE__ */ React__default.createElement("table", { className: styles.tableEditor, onMouseOver: onTableMouseOver, onMouseLeave: () => setHighlightedCoordinates([-1, -1]) }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
119
+ const align = mdastNode.align || [];
120
+ const currentColumnAlign = align[colIndex] || "left";
121
+ const className = AlignToTailwindClassMap[currentColumnAlign];
122
+ return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
123
+ }), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
124
+ "button",
125
+ {
126
+ className: styles.iconButton,
127
+ type: "button",
128
+ title: "Delete table",
129
+ onClick: (e) => {
130
+ e.preventDefault();
131
+ parentEditor.update(() => {
132
+ lexicalTable.selectNext();
133
+ lexicalTable.remove();
134
+ });
135
+ }
136
+ },
137
+ /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)
138
+ )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
139
+ return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
140
+ ColumnEditor,
141
+ {
142
+ ...{
143
+ setActiveCellWithBoundaries,
144
+ parentEditor,
145
+ colIndex,
146
+ highlightedCoordinates,
147
+ lexicalTable,
148
+ align: (mdastNode.align || [])[colIndex]
149
+ }
150
+ }
151
+ ));
152
+ }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))), /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
153
+ return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, /* @__PURE__ */ React__default.createElement("td", { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
154
+ var _a;
155
+ return /* @__PURE__ */ React__default.createElement(
156
+ Cell,
157
+ {
158
+ align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
159
+ key: colIndex,
160
+ contents: mdastCell.children,
161
+ setActiveCell: setActiveCellWithBoundaries,
162
+ ...{
163
+ rowIndex,
164
+ colIndex,
165
+ lexicalTable,
166
+ parentEditor,
167
+ activeCell
168
+ }
169
+ }
170
+ );
171
+ }), rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, /* @__PURE__ */ React__default.createElement(AddColumnIcon, null))));
172
+ })), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, /* @__PURE__ */ React__default.createElement(AddRowIcon, null))), /* @__PURE__ */ React__default.createElement("th", null))));
173
+ };
174
+ const Cell = ({ align, ...props }) => {
175
+ const { activeCell, setActiveCell } = props;
176
+ const isActive = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
177
+ const className = AlignToTailwindClassMap[align || "left"];
178
+ return /* @__PURE__ */ React__default.createElement(
179
+ "td",
180
+ {
181
+ className,
182
+ "data-active": isActive,
183
+ onClick: () => {
184
+ setActiveCell([props.colIndex, props.rowIndex]);
185
+ }
186
+ },
187
+ /* @__PURE__ */ React__default.createElement(CellEditor, { ...props, focus: isActive })
188
+ );
189
+ };
190
+ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
191
+ const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, rootEditor] = corePluginHooks.useEmitterValues(
192
+ "importVisitors",
193
+ "exportVisitors",
194
+ "usedLexicalNodes",
195
+ "jsxComponentDescriptors",
196
+ "jsxIsAvailable",
197
+ "rootEditor"
198
+ );
199
+ const [editor] = React__default.useState(() => {
200
+ const editor2 = createEditor({
201
+ nodes: usedLexicalNodes,
202
+ theme: lexicalTheme
203
+ });
204
+ editor2.update(() => {
205
+ importMdastTreeToLexical({
206
+ root: $getRoot(),
207
+ mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
208
+ visitors: importVisitors
209
+ });
210
+ });
211
+ return editor2;
212
+ });
213
+ const saveAndFocus = React__default.useCallback(
214
+ (nextCell) => {
215
+ editor.getEditorState().read(() => {
216
+ const mdast = exportLexicalTreeToMdast({
217
+ root: $getRoot(),
218
+ jsxComponentDescriptors,
219
+ visitors: exportVisitors,
220
+ jsxIsAvailable
221
+ });
222
+ parentEditor.update(() => {
223
+ lexicalTable.updateCellContents(colIndex, rowIndex, mdast.children[0].children);
224
+ });
225
+ });
226
+ setActiveCell(nextCell);
227
+ },
228
+ [colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable, lexicalTable, parentEditor, rowIndex, setActiveCell]
229
+ );
230
+ React__default.useEffect(() => {
231
+ return mergeRegister(
232
+ editor.registerCommand(
233
+ KEY_TAB_COMMAND,
234
+ (payload) => {
235
+ payload.preventDefault();
236
+ const nextCell = payload.shiftKey ? [colIndex - 1, rowIndex] : [colIndex + 1, rowIndex];
237
+ saveAndFocus(nextCell);
238
+ return true;
239
+ },
240
+ COMMAND_PRIORITY_CRITICAL
241
+ ),
242
+ editor.registerCommand(
243
+ FOCUS_COMMAND,
244
+ () => {
245
+ setActiveCell([colIndex, rowIndex]);
246
+ return false;
247
+ },
248
+ COMMAND_PRIORITY_LOW
249
+ ),
250
+ editor.registerCommand(
251
+ KEY_ENTER_COMMAND,
252
+ (payload) => {
253
+ payload == null ? void 0 : payload.preventDefault();
254
+ const nextCell = (payload == null ? void 0 : payload.shiftKey) ? [colIndex, rowIndex - 1] : [colIndex, rowIndex + 1];
255
+ saveAndFocus(nextCell);
256
+ return true;
257
+ },
258
+ COMMAND_PRIORITY_CRITICAL
259
+ ),
260
+ editor.registerCommand(
261
+ BLUR_COMMAND,
262
+ (payload) => {
263
+ const relatedTarget = payload.relatedTarget;
264
+ if (isPartOftheEditorUI(relatedTarget, rootEditor.getRootElement())) {
265
+ return false;
266
+ }
267
+ saveAndFocus(null);
268
+ return true;
269
+ },
270
+ COMMAND_PRIORITY_CRITICAL
271
+ )
272
+ );
273
+ }, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
274
+ React__default.useEffect(() => {
275
+ focus && (editor == null ? void 0 : editor.focus());
276
+ }, [focus, editor]);
277
+ return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(HistoryPlugin, null));
278
+ };
279
+ const ColumnEditor = ({
280
+ parentEditor,
281
+ highlightedCoordinates,
282
+ align,
283
+ lexicalTable,
284
+ colIndex,
285
+ setActiveCellWithBoundaries
286
+ }) => {
287
+ const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
288
+ const insertColumnAt = React__default.useCallback(
289
+ (colIndex2) => {
290
+ parentEditor.update(() => {
291
+ lexicalTable.insertColumnAt(colIndex2);
292
+ });
293
+ setActiveCellWithBoundaries([colIndex2, 0]);
294
+ },
295
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
296
+ );
297
+ const deleteColumnAt = React__default.useCallback(
298
+ (colIndex2) => {
299
+ parentEditor.update(() => {
300
+ lexicalTable.deleteColumnAt(colIndex2);
301
+ });
302
+ },
303
+ [parentEditor, lexicalTable]
304
+ );
305
+ const setColumnAlign = React__default.useCallback(
306
+ (colIndex2, align2) => {
307
+ parentEditor.update(() => {
308
+ lexicalTable.setColumnAlign(colIndex2, align2);
309
+ });
310
+ },
311
+ [parentEditor, lexicalTable]
312
+ );
313
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
314
+ RadixPopover.PopoverTrigger,
315
+ {
316
+ className: styles.tableColumnEditorTrigger,
317
+ "data-active": highlightedCoordinates[0] === colIndex + 1,
318
+ title: "Column menu"
319
+ },
320
+ /* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)
321
+ ), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
322
+ RadixPopover.PopoverContent,
323
+ {
324
+ className: classNames(styles.tableColumnEditorPopoverContent),
325
+ onOpenAutoFocus: (e) => e.preventDefault(),
326
+ sideOffset: 5,
327
+ side: "top"
328
+ },
329
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(
330
+ RadixToolbar.ToggleGroup,
331
+ {
332
+ className: styles.toggleGroupRoot,
333
+ onValueChange: (value) => {
334
+ setColumnAlign(colIndex, value);
335
+ },
336
+ value: align || "left",
337
+ type: "single",
338
+ "aria-label": "Text alignment"
339
+ },
340
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "left", title: "Align left" }, /* @__PURE__ */ React__default.createElement(AlignLeftIcon, null)),
341
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "center", title: "Align center" }, /* @__PURE__ */ React__default.createElement(AlignCenterIcon, null)),
342
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "right", title: "Align right" }, /* @__PURE__ */ React__default.createElement(AlignRightIcon, null))
343
+ ), /* @__PURE__ */ React__default.createElement(RadixToolbar.Separator, null), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex), title: "Insert a column to the left of this one" }, /* @__PURE__ */ React__default.createElement(InsertColLeftIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex + 1), title: "Insert a column to the right of this one" }, /* @__PURE__ */ React__default.createElement(InsertColRightIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteColumnAt.bind(null, colIndex), title: "Delete this column" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
344
+ )));
345
+ };
346
+ const RowEditor = ({
347
+ parentEditor,
348
+ highlightedCoordinates,
349
+ lexicalTable,
350
+ rowIndex,
351
+ setActiveCellWithBoundaries
352
+ }) => {
353
+ const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
354
+ const insertRowAt = React__default.useCallback(
355
+ (rowIndex2) => {
356
+ parentEditor.update(() => {
357
+ lexicalTable.insertRowAt(rowIndex2);
358
+ });
359
+ setActiveCellWithBoundaries([0, rowIndex2]);
360
+ },
361
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
362
+ );
363
+ const deleteRowAt = React__default.useCallback(
364
+ (rowIndex2) => {
365
+ parentEditor.update(() => {
366
+ lexicalTable.deleteRowAt(rowIndex2);
367
+ });
368
+ },
369
+ [parentEditor, lexicalTable]
370
+ );
371
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(RadixPopover.PopoverTrigger, { className: styles.tableColumnEditorTrigger, "data-active": highlightedCoordinates[1] === rowIndex }, /* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
372
+ RadixPopover.PopoverContent,
373
+ {
374
+ className: classNames(styles.tableColumnEditorPopoverContent),
375
+ onOpenAutoFocus: (e) => e.preventDefault(),
376
+ sideOffset: 5,
377
+ side: "bottom"
378
+ },
379
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex), title: "Insert a row above this one" }, /* @__PURE__ */ React__default.createElement(InsertRowAboveIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex + 1), title: "Insert a row below this one" }, /* @__PURE__ */ React__default.createElement(InsertRowBelowIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteRowAt.bind(null, rowIndex), title: "Delete this row" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
380
+ )));
381
+ };
382
+ export {
383
+ TableEditor
384
+ };
@@ -0,0 +1,52 @@
1
+ /// <reference types="react" />
2
+ import { DecoratorNode, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
3
+ import * as Mdast from 'mdast';
4
+ /**
5
+ * A serialized representation of a {@link TableNode}.
6
+ */
7
+ export type SerializedTableNode = Spread<{
8
+ mdastNode: Mdast.Table;
9
+ }, SerializedLexicalNode>;
10
+ type CoordinatesSubscription = (coords: [colIndex: number, rowIndex: number]) => void;
11
+ /**
12
+ * A lexical node that represents a table, with features specific to the markdown tables.
13
+ * Use {@link "$createTableNode"} to construct one.
14
+ */
15
+ export declare class TableNode extends DecoratorNode<JSX.Element> {
16
+ __mdastNode: Mdast.Table;
17
+ focusEmitter: {
18
+ publish: (coords: [colIndex: number, rowIndex: number]) => void;
19
+ subscribe: (cb: CoordinatesSubscription) => void;
20
+ };
21
+ static getType(): string;
22
+ static clone(node: TableNode): TableNode;
23
+ static importJSON(serializedNode: SerializedTableNode): TableNode;
24
+ exportJSON(): SerializedTableNode;
25
+ getMdastNode(): Mdast.Table;
26
+ getRowCount(): number;
27
+ getColCount(): number;
28
+ constructor(mdastNode?: Mdast.Table, key?: NodeKey);
29
+ createDOM(): HTMLElement;
30
+ updateDOM(): false;
31
+ updateCellContents(colIndex: number, rowIndex: number, children: Mdast.PhrasingContent[]): void;
32
+ insertColumnAt(colIndex: number): void;
33
+ deleteColumnAt(colIndex: number): void;
34
+ insertRowAt(y: number): void;
35
+ deleteRowAt(rowIndex: number): void;
36
+ addRowToBottom(): void;
37
+ addColumnToRight(): void;
38
+ setColumnAlign(colIndex: number, align: Mdast.AlignType): void;
39
+ decorate(parentEditor: LexicalEditor): JSX.Element;
40
+ select(coords?: [colIndex: number, rowIndex: number]): void;
41
+ isInline(): false;
42
+ }
43
+ /**
44
+ * Retruns true if the given node is a {@link TableNode}.
45
+ */
46
+ export declare function $isTableNode(node: LexicalNode | null | undefined): node is TableNode;
47
+ /**
48
+ * Creates a {@link TableNode}
49
+ * @param mdastNode - The mdast node to create the {@link TableNode} from.
50
+ */
51
+ export declare function $createTableNode(mdastNode: Mdast.Table): TableNode;
52
+ export {};