@mdxeditor/editor 0.0.1 → 0.0.4-development

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 (300) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +15 -75
  3. package/dist/FormatConstants.d.ts +9 -0
  4. package/dist/FormatConstants.js +10 -0
  5. package/dist/MDXEditor.d.ts +103 -0
  6. package/dist/MDXEditor.js +144 -0
  7. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
  8. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
  9. package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
  10. package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
  11. package/dist/exportMarkdownFromLexical.d.ts +138 -0
  12. package/dist/exportMarkdownFromLexical.js +239 -0
  13. package/dist/gurx/index.d.ts +3 -0
  14. package/dist/gurx/react.d.ts +152 -0
  15. package/dist/gurx/react.js +206 -0
  16. package/dist/gurx/realm.d.ts +148 -0
  17. package/dist/gurx/realm.js +489 -0
  18. package/dist/gurx/realmFactory.d.ts +79 -0
  19. package/dist/gurx/realmFactory.js +32 -0
  20. package/dist/icons/add_column.svg.js +5 -0
  21. package/dist/icons/add_photo.svg.js +5 -0
  22. package/dist/icons/add_row.svg.js +5 -0
  23. package/dist/icons/admonition.svg.js +5 -0
  24. package/dist/icons/arrow_drop_down.svg.js +5 -0
  25. package/dist/icons/check.svg.js +5 -0
  26. package/dist/icons/close.svg.js +5 -0
  27. package/dist/icons/code.svg.js +5 -0
  28. package/dist/icons/content_copy.svg.js +5 -0
  29. package/dist/icons/delete_big.svg.js +5 -0
  30. package/dist/icons/delete_small.svg.js +5 -0
  31. package/dist/icons/difference.svg.js +5 -0
  32. package/dist/icons/edit.svg.js +5 -0
  33. package/dist/icons/format_align_center.svg.js +5 -0
  34. package/dist/icons/format_align_left.svg.js +5 -0
  35. package/dist/icons/format_align_right.svg.js +5 -0
  36. package/dist/icons/format_bold.svg.js +5 -0
  37. package/dist/icons/format_italic.svg.js +5 -0
  38. package/dist/icons/format_list_bulleted.svg.js +5 -0
  39. package/dist/icons/format_list_checked.svg.js +5 -0
  40. package/dist/icons/format_list_numbered.svg.js +5 -0
  41. package/dist/icons/format_underlined.svg.js +5 -0
  42. package/dist/icons/frame_source.svg.js +5 -0
  43. package/dist/icons/frontmatter.svg.js +5 -0
  44. package/dist/icons/horizontal_rule.svg.js +5 -0
  45. package/dist/icons/insert_col_left.svg.js +5 -0
  46. package/dist/icons/insert_col_right.svg.js +5 -0
  47. package/dist/icons/insert_row_above.svg.js +5 -0
  48. package/dist/icons/insert_row_below.svg.js +5 -0
  49. package/dist/icons/link.svg.js +5 -0
  50. package/dist/icons/link_off.svg.js +5 -0
  51. package/dist/icons/markdown.svg.js +5 -0
  52. package/dist/icons/more_horiz.svg.js +5 -0
  53. package/dist/icons/more_vert.svg.js +5 -0
  54. package/dist/icons/open_in_new.svg.js +5 -0
  55. package/dist/icons/redo.svg.js +5 -0
  56. package/dist/icons/rich_text.svg.js +5 -0
  57. package/dist/icons/sandpack.svg.js +5 -0
  58. package/dist/icons/settings.svg.js +5 -0
  59. package/dist/icons/table.svg.js +5 -0
  60. package/dist/icons/undo.svg.js +5 -0
  61. package/dist/importMarkdownToLexical.d.ts +101 -0
  62. package/dist/importMarkdownToLexical.js +93 -0
  63. package/dist/index.d.ts +62 -726
  64. package/dist/index.js +207 -4501
  65. package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
  66. package/dist/jsx-editors/GenericJsxEditor.js +56 -0
  67. package/dist/plugins/codeblock/CodeBlockNode.d.ts +100 -0
  68. package/dist/plugins/codeblock/CodeBlockNode.js +158 -0
  69. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
  70. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  71. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
  72. package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
  73. package/dist/plugins/codeblock/index.d.ts +787 -0
  74. package/dist/plugins/codeblock/index.js +73 -0
  75. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
  76. package/dist/plugins/codemirror/CodeMirrorEditor.js +42 -0
  77. package/dist/plugins/codemirror/index.d.ts +1038 -0
  78. package/dist/plugins/codemirror/index.js +62 -0
  79. package/dist/plugins/core/GenericHTMLNode.d.ts +38 -0
  80. package/dist/plugins/core/GenericHTMLNode.js +117 -0
  81. package/dist/plugins/core/Icon.d.ts +6 -0
  82. package/dist/plugins/core/Icon.js +92 -0
  83. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.d.ts +4 -0
  84. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.js +15 -0
  85. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
  86. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  87. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
  88. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  89. package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
  90. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  91. package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
  92. package/dist/plugins/core/LexicalTextVisitor.js +102 -0
  93. package/dist/plugins/core/MdastBreakVisitor.d.ts +3 -0
  94. package/dist/plugins/core/MdastBreakVisitor.js +10 -0
  95. package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
  96. package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
  97. package/dist/plugins/core/MdastHTMLNode.d.ts +13 -0
  98. package/dist/plugins/core/MdastHTMLNode.js +122 -0
  99. package/dist/plugins/core/MdastHTMLVisitor.d.ts +3 -0
  100. package/dist/plugins/core/MdastHTMLVisitor.js +12 -0
  101. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
  102. package/dist/plugins/core/MdastInlineCodeVisitor.js +27 -0
  103. package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
  104. package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
  105. package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
  106. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  107. package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
  108. package/dist/plugins/core/MdastTextVisitor.js +10 -0
  109. package/dist/plugins/core/NestedLexicalEditor.d.ts +92 -0
  110. package/dist/plugins/core/NestedLexicalEditor.js +185 -0
  111. package/dist/plugins/core/PropertyPopover.d.ts +23 -0
  112. package/dist/plugins/core/PropertyPopover.js +39 -0
  113. package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
  114. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  115. package/dist/plugins/core/index.d.ts +583 -0
  116. package/dist/plugins/core/index.js +490 -0
  117. package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +15 -0
  118. package/dist/plugins/core/ui/DownshiftAutoComplete.js +83 -0
  119. package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
  120. package/dist/plugins/core/ui/PopoverUtils.js +17 -0
  121. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
  122. package/dist/plugins/diff-source/DiffSourceWrapper.js +14 -0
  123. package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
  124. package/dist/plugins/diff-source/DiffViewer.js +59 -0
  125. package/dist/plugins/diff-source/SourceEditor.d.ts +4 -0
  126. package/dist/plugins/diff-source/SourceEditor.js +53 -0
  127. package/dist/plugins/diff-source/index.d.ts +725 -0
  128. package/dist/plugins/diff-source/index.js +56 -0
  129. package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
  130. package/dist/plugins/directives/DirectiveNode.js +92 -0
  131. package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
  132. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  133. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
  134. package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
  135. package/dist/plugins/directives/index.d.ts +773 -0
  136. package/dist/plugins/directives/index.js +53 -0
  137. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
  138. package/dist/plugins/frontmatter/FrontmatterEditor.js +85 -0
  139. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
  140. package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
  141. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
  142. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  143. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
  144. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  145. package/dist/plugins/frontmatter/index.d.ts +717 -0
  146. package/dist/plugins/frontmatter/index.js +76 -0
  147. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
  148. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  149. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
  150. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  151. package/dist/plugins/headings/index.d.ts +707 -0
  152. package/dist/plugins/headings/index.js +69 -0
  153. package/dist/plugins/image/ImageDialog.d.ts +2 -0
  154. package/dist/plugins/image/ImageDialog.js +70 -0
  155. package/dist/plugins/image/ImageEditor.d.ts +10 -0
  156. package/dist/plugins/image/ImageEditor.js +227 -0
  157. package/dist/plugins/image/ImageNode.d.ts +65 -0
  158. package/dist/plugins/image/ImageNode.js +152 -0
  159. package/dist/plugins/image/ImageResizer.d.ts +18 -0
  160. package/dist/plugins/image/ImageResizer.js +214 -0
  161. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  162. package/dist/plugins/image/LexicalImageVisitor.js +35 -0
  163. package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
  164. package/dist/plugins/image/MdastImageVisitor.js +87 -0
  165. package/dist/plugins/image/index.d.ts +804 -0
  166. package/dist/plugins/image/index.js +300 -0
  167. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  168. package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
  169. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  170. package/dist/plugins/jsx/LexicalJsxVisitor.js +24 -0
  171. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  172. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  173. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  174. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  175. package/dist/plugins/jsx/index.d.ts +779 -0
  176. package/dist/plugins/jsx/index.js +82 -0
  177. package/dist/plugins/link/AutoLinkPlugin.d.ts +9 -0
  178. package/dist/plugins/link/AutoLinkPlugin.js +18 -0
  179. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  180. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  181. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  182. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  183. package/dist/plugins/link/index.d.ts +101 -0
  184. package/dist/plugins/link/index.js +33 -0
  185. package/dist/plugins/link-dialog/LinkDialog.d.ts +16 -0
  186. package/dist/plugins/link-dialog/LinkDialog.js +148 -0
  187. package/dist/plugins/link-dialog/index.d.ts +669 -0
  188. package/dist/plugins/link-dialog/index.js +254 -0
  189. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  190. package/dist/plugins/lists/LexicalListItemVisitor.js +23 -0
  191. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  192. package/dist/plugins/lists/LexicalListVisitor.js +13 -0
  193. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  194. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  195. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  196. package/dist/plugins/lists/MdastListVisitor.js +20 -0
  197. package/dist/plugins/lists/index.d.ts +703 -0
  198. package/dist/plugins/lists/index.js +122 -0
  199. package/dist/plugins/markdown-shortcut/index.d.ts +80 -0
  200. package/dist/plugins/markdown-shortcut/index.js +90 -0
  201. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  202. package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
  203. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  204. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  205. package/dist/plugins/quote/index.d.ts +480 -0
  206. package/dist/plugins/quote/index.js +26 -0
  207. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  208. package/dist/plugins/sandpack/SandpackEditor.js +37 -0
  209. package/dist/plugins/sandpack/index.d.ts +1077 -0
  210. package/dist/plugins/sandpack/index.js +93 -0
  211. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  212. package/dist/plugins/sandpack/useCodeMirrorRef.js +96 -0
  213. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  214. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  215. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  216. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  217. package/dist/plugins/table/TableEditor.d.ts +21 -0
  218. package/dist/plugins/table/TableEditor.js +388 -0
  219. package/dist/plugins/table/TableNode.d.ts +52 -0
  220. package/dist/plugins/table/TableNode.js +152 -0
  221. package/dist/plugins/table/index.d.ts +704 -0
  222. package/dist/plugins/table/index.js +69 -0
  223. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  224. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  225. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  226. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  227. package/dist/plugins/thematic-break/index.d.ts +693 -0
  228. package/dist/plugins/thematic-break/index.js +39 -0
  229. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
  230. package/dist/plugins/toolbar/components/BlockTypeSelect.js +54 -0
  231. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
  232. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +33 -0
  233. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
  234. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  235. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
  236. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  237. package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
  238. package/dist/plugins/toolbar/components/CodeToggle.js +19 -0
  239. package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
  240. package/dist/plugins/toolbar/components/CreateLink.js +20 -0
  241. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
  242. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +25 -0
  243. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
  244. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  245. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
  246. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  247. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
  248. package/dist/plugins/toolbar/components/InsertFrontmatter.js +24 -0
  249. package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
  250. package/dist/plugins/toolbar/components/InsertImage.js +14 -0
  251. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
  252. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  253. package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
  254. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  255. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
  256. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  257. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
  258. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  259. package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
  260. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  261. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
  262. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +31 -0
  263. package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
  264. package/dist/plugins/toolbar/components/UndoRedo.js +58 -0
  265. package/dist/plugins/toolbar/index.d.ts +564 -0
  266. package/dist/plugins/toolbar/index.js +40 -0
  267. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  268. package/dist/plugins/toolbar/primitives/DialogButton.js +114 -0
  269. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
  270. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  271. package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
  272. package/dist/plugins/toolbar/primitives/select.js +55 -0
  273. package/dist/plugins/toolbar/primitives/toolbar.d.ts +163 -0
  274. package/dist/plugins/toolbar/primitives/toolbar.js +115 -0
  275. package/dist/style.css +1093 -288
  276. package/dist/styles/globals.css.js +4 -0
  277. package/dist/styles/lexical-theme.module.css.js +62 -0
  278. package/dist/styles/lexicalTheme.d.ts +2 -0
  279. package/dist/styles/lexicalTheme.js +31 -0
  280. package/dist/styles/ui.module.css.js +311 -0
  281. package/dist/utils/detectMac.d.ts +3 -0
  282. package/dist/utils/detectMac.js +13 -0
  283. package/dist/utils/fp.d.ts +47 -0
  284. package/dist/utils/fp.js +44 -0
  285. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  286. package/dist/utils/isPartOftheEditorUI.js +12 -0
  287. package/dist/utils/lexicalHelpers.d.ts +11 -0
  288. package/dist/utils/lexicalHelpers.js +80 -0
  289. package/dist/utils/makeHslTransparent.d.ts +1 -0
  290. package/dist/utils/makeHslTransparent.js +6 -0
  291. package/dist/utils/mergeStyleAttributes.d.ts +1 -0
  292. package/dist/utils/mergeStyleAttributes.js +22 -0
  293. package/dist/utils/uuid4.d.ts +1 -0
  294. package/dist/utils/uuid4.js +10 -0
  295. package/dist/utils/voidEmitter.d.ts +14 -0
  296. package/dist/utils/voidEmitter.js +15 -0
  297. package/dist/utils/whitespaceConversion.d.ts +2 -0
  298. package/dist/utils/whitespaceConversion.js +9 -0
  299. package/package.json +326 -39
  300. package/dist/index.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>;
@@ -0,0 +1,96 @@
1
+ import { $getNodeByKey, $createParagraphNode } from "lexical";
2
+ import React__default from "react";
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");
8
+ const codeMirrorRef = React__default.useRef(null);
9
+ const { lexicalNode } = useCodeBlockEditorContext();
10
+ const atBottom = React__default.useRef(false);
11
+ const atTop = React__default.useRef(false);
12
+ const onFocusHandler = React__default.useCallback(() => {
13
+ setEditorInFocus({
14
+ editorType,
15
+ rootNode: lexicalNode
16
+ });
17
+ }, [editorType, lexicalNode, setEditorInFocus]);
18
+ const onKeyDownHandler = React__default.useCallback(
19
+ (e) => {
20
+ var _a, _b, _c, _d;
21
+ if (e.key === "ArrowDown") {
22
+ const state = (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.state;
23
+ if (state) {
24
+ const docLength = state.doc.length;
25
+ const selectionEnd = state.selection.ranges[0].to;
26
+ if (docLength === selectionEnd) {
27
+ if (!atBottom.current) {
28
+ atBottom.current = true;
29
+ } else {
30
+ theEditor == null ? void 0 : theEditor.update(() => {
31
+ var _a2, _b2;
32
+ const node = $getNodeByKey(nodeKey);
33
+ const nextSibling = node.getNextSibling();
34
+ if (nextSibling) {
35
+ (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
36
+ node.selectNext();
37
+ } else {
38
+ node.insertAfter($createParagraphNode());
39
+ }
40
+ });
41
+ atBottom.current = false;
42
+ }
43
+ }
44
+ }
45
+ } else if (e.key === "ArrowUp") {
46
+ const state = (_d = (_c = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _c.getCodemirror()) == null ? void 0 : _d.state;
47
+ if (state) {
48
+ const selectionStart = state.selection.ranges[0].from;
49
+ if (selectionStart === 0) {
50
+ if (!atTop.current) {
51
+ atTop.current = true;
52
+ } else {
53
+ theEditor == null ? void 0 : theEditor.update(() => {
54
+ var _a2, _b2;
55
+ const node = $getNodeByKey(nodeKey);
56
+ const previousSibling = node.getPreviousSibling();
57
+ if (previousSibling) {
58
+ (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
59
+ node.selectPrevious();
60
+ }
61
+ });
62
+ atTop.current = false;
63
+ }
64
+ }
65
+ }
66
+ } else if (e.key === "Enter") {
67
+ e.stopPropagation();
68
+ }
69
+ },
70
+ [theEditor, nodeKey]
71
+ );
72
+ React__default.useEffect(() => {
73
+ const codeMirror = codeMirrorRef.current;
74
+ setTimeout(() => {
75
+ var _a, _b, _c, _d;
76
+ (_b = (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM) == null ? void 0 : _b.addEventListener("focus", onFocusHandler);
77
+ (_d = (_c = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _c.contentDOM) == null ? void 0 : _d.addEventListener("keydown", onKeyDownHandler);
78
+ }, 100);
79
+ return () => {
80
+ var _a, _b;
81
+ (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM.removeEventListener("focus", onFocusHandler);
82
+ (_b = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _b.contentDOM.removeEventListener("keydown", onKeyDownHandler);
83
+ };
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]);
92
+ return codeMirrorRef;
93
+ }
94
+ export {
95
+ useCodeMirrorRef
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,388 @@
1
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
2
+ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
3
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer.js";
4
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin.js";
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 { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
9
+ import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
10
+ import { lexicalTheme } from "../../styles/lexicalTheme.js";
11
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin.js";
12
+ import { mergeRegister } from "@lexical/utils";
13
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
14
+ import classNames from "classnames";
15
+ import styles from "../../styles/ui.module.css.js";
16
+ import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
17
+ import { uuidv4 } from "../../utils/uuid4.js";
18
+ import { corePluginHooks } from "../core/index.js";
19
+ const AlignToTailwindClassMap = {
20
+ center: styles.centeredCell,
21
+ left: styles.leftAlignedCell,
22
+ right: styles.rightAlignedCell
23
+ };
24
+ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
25
+ const [activeCell, setActiveCell] = React__default.useState(null);
26
+ const [iconComponentFor, readOnly] = corePluginHooks.useEmitterValues("iconComponentFor", "readOnly");
27
+ const getCellKey = React__default.useMemo(() => {
28
+ const cellKeyMap = /* @__PURE__ */ new WeakMap();
29
+ return (cell) => {
30
+ if (!cellKeyMap.has(cell)) {
31
+ cellKeyMap.set(cell, uuidv4());
32
+ }
33
+ return cellKeyMap.get(cell);
34
+ };
35
+ }, []);
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)), readOnly || /* @__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
+ iconComponentFor("delete_small")
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 }, readOnly || /* @__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: getCellKey(mdastCell),
160
+ contents: mdastCell.children,
161
+ setActiveCell: setActiveCellWithBoundaries,
162
+ ...{
163
+ rowIndex,
164
+ colIndex,
165
+ lexicalTable,
166
+ parentEditor,
167
+ activeCell: readOnly ? [-1, -1] : activeCell
168
+ }
169
+ }
170
+ );
171
+ }), readOnly || 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 }, iconComponentFor("add_column"))));
172
+ })), readOnly || /* @__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 }, iconComponentFor("add_row"))), /* @__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 [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
289
+ const insertColumnAt = React__default.useCallback(
290
+ (colIndex2) => {
291
+ parentEditor.update(() => {
292
+ lexicalTable.insertColumnAt(colIndex2);
293
+ });
294
+ setActiveCellWithBoundaries([colIndex2, 0]);
295
+ },
296
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
297
+ );
298
+ const deleteColumnAt = React__default.useCallback(
299
+ (colIndex2) => {
300
+ parentEditor.update(() => {
301
+ lexicalTable.deleteColumnAt(colIndex2);
302
+ });
303
+ },
304
+ [parentEditor, lexicalTable]
305
+ );
306
+ const setColumnAlign = React__default.useCallback(
307
+ (colIndex2, align2) => {
308
+ parentEditor.update(() => {
309
+ lexicalTable.setColumnAlign(colIndex2, align2);
310
+ });
311
+ },
312
+ [parentEditor, lexicalTable]
313
+ );
314
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
315
+ RadixPopover.PopoverTrigger,
316
+ {
317
+ className: styles.tableColumnEditorTrigger,
318
+ "data-active": highlightedCoordinates[0] === colIndex + 1,
319
+ title: "Column menu"
320
+ },
321
+ iconComponentFor("more_horiz")
322
+ ), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
323
+ RadixPopover.PopoverContent,
324
+ {
325
+ className: classNames(styles.tableColumnEditorPopoverContent),
326
+ onOpenAutoFocus: (e) => e.preventDefault(),
327
+ sideOffset: 5,
328
+ side: "top"
329
+ },
330
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(
331
+ RadixToolbar.ToggleGroup,
332
+ {
333
+ className: styles.toggleGroupRoot,
334
+ onValueChange: (value) => {
335
+ setColumnAlign(colIndex, value);
336
+ },
337
+ value: align || "left",
338
+ type: "single",
339
+ "aria-label": "Text alignment"
340
+ },
341
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "left", title: "Align left" }, iconComponentFor("format_align_left")),
342
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "center", title: "Align center" }, iconComponentFor("format_align_center")),
343
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "right", title: "Align right" }, iconComponentFor("format_align_right"))
344
+ ), /* @__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" }, iconComponentFor("insert_col_left")), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex + 1), title: "Insert a column to the right of this one" }, iconComponentFor("insert_col_right")), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteColumnAt.bind(null, colIndex), title: "Delete this column" }, iconComponentFor("delete_small"))),
345
+ /* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, { className: styles.popoverArrow })
346
+ )));
347
+ };
348
+ const RowEditor = ({
349
+ parentEditor,
350
+ highlightedCoordinates,
351
+ lexicalTable,
352
+ rowIndex,
353
+ setActiveCellWithBoundaries
354
+ }) => {
355
+ const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
356
+ const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
357
+ const insertRowAt = React__default.useCallback(
358
+ (rowIndex2) => {
359
+ parentEditor.update(() => {
360
+ lexicalTable.insertRowAt(rowIndex2);
361
+ });
362
+ setActiveCellWithBoundaries([0, rowIndex2]);
363
+ },
364
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
365
+ );
366
+ const deleteRowAt = React__default.useCallback(
367
+ (rowIndex2) => {
368
+ parentEditor.update(() => {
369
+ lexicalTable.deleteRowAt(rowIndex2);
370
+ });
371
+ },
372
+ [parentEditor, lexicalTable]
373
+ );
374
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(RadixPopover.PopoverTrigger, { className: styles.tableColumnEditorTrigger, "data-active": highlightedCoordinates[1] === rowIndex }, iconComponentFor("more_horiz")), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
375
+ RadixPopover.PopoverContent,
376
+ {
377
+ className: classNames(styles.tableColumnEditorPopoverContent),
378
+ onOpenAutoFocus: (e) => e.preventDefault(),
379
+ sideOffset: 5,
380
+ side: "bottom"
381
+ },
382
+ /* @__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" }, iconComponentFor("insert_row_above")), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex + 1), title: "Insert a row below this one" }, iconComponentFor("insert_row_below")), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteRowAt.bind(null, rowIndex), title: "Delete this row" }, iconComponentFor("delete_small"))),
383
+ /* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, { className: styles.popoverArrow })
384
+ )));
385
+ };
386
+ export {
387
+ TableEditor
388
+ };