@mdxeditor/editor 0.9.0 → 0.10.0-alpha.2

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 (292) hide show
  1. package/dist/FormatConstants.d.ts +9 -0
  2. package/dist/FormatConstants.js +10 -0
  3. package/dist/MDXEditor.d.ts +31 -0
  4. package/dist/MDXEditor.js +105 -0
  5. package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +4 -0
  6. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
  7. package/dist/directive-editors/GenericDirectiveEditor.d.ts +3 -0
  8. package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
  9. package/dist/exportMarkdownFromLexical.d.ts +114 -0
  10. package/dist/exportMarkdownFromLexical.js +199 -0
  11. package/dist/gurx/index.d.ts +3 -0
  12. package/dist/gurx/react.d.ts +121 -0
  13. package/dist/gurx/react.js +112 -0
  14. package/dist/gurx/realm.d.ts +133 -0
  15. package/dist/gurx/realm.js +491 -0
  16. package/dist/gurx/realmFactory.d.ts +58 -0
  17. package/dist/gurx/realmFactory.js +28 -0
  18. package/dist/icons/add_column.svg.js +8 -0
  19. package/dist/icons/add_photo.svg.js +8 -0
  20. package/dist/icons/add_row.svg.js +8 -0
  21. package/dist/icons/arrow_drop_down.svg.js +8 -0
  22. package/dist/icons/arrow_right.svg.js +8 -0
  23. package/dist/icons/check.svg.js +8 -0
  24. package/dist/icons/close.svg.js +8 -0
  25. package/dist/icons/code.svg.js +8 -0
  26. package/dist/icons/content_copy.svg.js +8 -0
  27. package/dist/icons/delete.svg.js +8 -0
  28. package/dist/icons/delete_small.svg.js +8 -0
  29. package/dist/icons/deployed_code.svg.js +8 -0
  30. package/dist/icons/difference.svg.js +8 -0
  31. package/dist/icons/edit.svg.js +8 -0
  32. package/dist/icons/emergency_home.svg.js +8 -0
  33. package/dist/icons/format_align_center.svg.js +8 -0
  34. package/dist/icons/format_align_left.svg.js +8 -0
  35. package/dist/icons/format_align_right.svg.js +8 -0
  36. package/dist/icons/format_bold.svg.js +8 -0
  37. package/dist/icons/format_italic.svg.js +8 -0
  38. package/dist/icons/format_list_bulleted.svg.js +8 -0
  39. package/dist/icons/format_list_numbered.svg.js +8 -0
  40. package/dist/icons/format_underlined.svg.js +8 -0
  41. package/dist/icons/frame_source.svg.js +8 -0
  42. package/dist/icons/frontmatter.svg.js +8 -0
  43. package/dist/icons/horizontal_rule.svg.js +8 -0
  44. package/dist/icons/insert_col_left.svg.js +8 -0
  45. package/dist/icons/insert_col_right.svg.js +8 -0
  46. package/dist/icons/insert_row_above.svg.js +8 -0
  47. package/dist/icons/insert_row_below.svg.js +8 -0
  48. package/dist/icons/link.svg.js +8 -0
  49. package/dist/icons/link_off.svg.js +8 -0
  50. package/dist/icons/markdown.svg.js +8 -0
  51. package/dist/icons/more_horiz.svg.js +8 -0
  52. package/dist/icons/open_in_new.svg.js +8 -0
  53. package/dist/icons/redo.svg.js +8 -0
  54. package/dist/icons/rich_text.svg.js +8 -0
  55. package/dist/icons/settings.svg.js +8 -0
  56. package/dist/icons/table.svg.js +8 -0
  57. package/dist/icons/undo.svg.js +8 -0
  58. package/dist/importMarkdownToLexical.d.ts +84 -0
  59. package/dist/importMarkdownToLexical.js +65 -0
  60. package/dist/index.d.ts +49 -1094
  61. package/dist/index.js +133 -72
  62. package/dist/jsx-editors/GenericJsxEditor.d.ts +3 -0
  63. package/dist/jsx-editors/GenericJsxEditor.js +56 -0
  64. package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
  65. package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
  66. package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
  67. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
  68. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  69. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
  70. package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
  71. package/dist/plugins/codeblock/index.d.ts +604 -0
  72. package/dist/plugins/codeblock/index.js +73 -0
  73. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
  74. package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
  75. package/dist/plugins/codemirror/index.d.ts +786 -0
  76. package/dist/plugins/codemirror/index.js +62 -0
  77. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
  78. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  79. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
  80. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  81. package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
  82. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  83. package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
  84. package/dist/plugins/core/LexicalTextVisitor.js +85 -0
  85. package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
  86. package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
  87. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
  88. package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
  89. package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
  90. package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
  91. package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
  92. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  93. package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
  94. package/dist/plugins/core/MdastTextVisitor.js +10 -0
  95. package/dist/plugins/core/NestedLexicalEditor.d.ts +69 -0
  96. package/dist/plugins/core/NestedLexicalEditor.js +181 -0
  97. package/dist/plugins/core/PropertyPopover.d.ts +8 -0
  98. package/dist/plugins/core/PropertyPopover.js +36 -0
  99. package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
  100. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  101. package/dist/plugins/core/index.d.ts +419 -0
  102. package/dist/plugins/core/index.js +343 -0
  103. package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
  104. package/dist/plugins/core/ui/PopoverUtils.js +17 -0
  105. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
  106. package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
  107. package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
  108. package/dist/plugins/diff-source/DiffViewer.js +18 -0
  109. package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
  110. package/dist/plugins/diff-source/SourceEditor.js +27 -0
  111. package/dist/plugins/diff-source/index.d.ts +530 -0
  112. package/dist/plugins/diff-source/index.js +55 -0
  113. package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
  114. package/dist/plugins/directives/DirectiveNode.js +92 -0
  115. package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
  116. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  117. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
  118. package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
  119. package/dist/plugins/directives/index.d.ts +591 -0
  120. package/dist/plugins/directives/index.js +53 -0
  121. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
  122. package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
  123. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
  124. package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
  125. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
  126. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  127. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
  128. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  129. package/dist/plugins/frontmatter/index.d.ts +510 -0
  130. package/dist/plugins/frontmatter/index.js +53 -0
  131. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
  132. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  133. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
  134. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  135. package/dist/plugins/headings/index.d.ts +105 -0
  136. package/dist/plugins/headings/index.js +20 -0
  137. package/dist/plugins/image/ImageEditor.d.ts +9 -0
  138. package/dist/{ImageEditor-ad505654.js → plugins/image/ImageEditor.js} +40 -52
  139. package/dist/plugins/image/ImageNode.d.ts +63 -0
  140. package/dist/plugins/image/ImageNode.js +136 -0
  141. package/dist/plugins/image/ImageResizer.d.ts +18 -0
  142. package/dist/plugins/image/ImageResizer.js +214 -0
  143. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  144. package/dist/plugins/image/LexicalImageVisitor.js +36 -0
  145. package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
  146. package/dist/plugins/image/MdastImageVisitor.js +87 -0
  147. package/dist/plugins/image/index.d.ts +541 -0
  148. package/dist/plugins/image/index.js +246 -0
  149. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  150. package/dist/plugins/jsx/LexicalJsxNode.js +99 -0
  151. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  152. package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
  153. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  154. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  155. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  156. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  157. package/dist/plugins/jsx/index.d.ts +461 -0
  158. package/dist/plugins/jsx/index.js +37 -0
  159. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  160. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  161. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  162. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  163. package/dist/plugins/link/index.d.ts +108 -0
  164. package/dist/plugins/link/index.js +24 -0
  165. package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
  166. package/dist/plugins/link-dialog/LinkDialog.js +174 -0
  167. package/dist/plugins/link-dialog/index.d.ts +496 -0
  168. package/dist/plugins/link-dialog/index.js +242 -0
  169. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  170. package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
  171. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  172. package/dist/plugins/lists/LexicalListVisitor.js +14 -0
  173. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  174. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  175. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  176. package/dist/plugins/lists/MdastListVisitor.js +18 -0
  177. package/dist/plugins/lists/index.d.ts +521 -0
  178. package/dist/plugins/lists/index.js +111 -0
  179. package/dist/plugins/markdown-shortcut/index.d.ts +51 -0
  180. package/dist/plugins/markdown-shortcut/index.js +34 -0
  181. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  182. package/dist/plugins/quote/LexicalQuoteVisitor.js +14 -0
  183. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  184. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  185. package/dist/plugins/quote/index.d.ts +348 -0
  186. package/dist/plugins/quote/index.js +26 -0
  187. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  188. package/dist/plugins/sandpack/SandpackEditor.js +35 -0
  189. package/dist/plugins/sandpack/index.d.ts +826 -0
  190. package/dist/plugins/sandpack/index.js +93 -0
  191. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  192. package/dist/{useCodeMirrorRef-177e9901.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
  193. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  194. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  195. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  196. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  197. package/dist/plugins/table/TableEditor.d.ts +21 -0
  198. package/dist/plugins/table/TableEditor.js +384 -0
  199. package/dist/plugins/table/TableNode.d.ts +52 -0
  200. package/dist/plugins/table/TableNode.js +147 -0
  201. package/dist/plugins/table/index.d.ts +511 -0
  202. package/dist/plugins/table/index.js +59 -0
  203. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  204. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  205. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  206. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  207. package/dist/plugins/thematic-break/index.d.ts +510 -0
  208. package/dist/plugins/thematic-break/index.js +39 -0
  209. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +2 -0
  210. package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
  211. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +2 -0
  212. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
  213. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +2 -0
  214. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  215. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +2 -0
  216. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  217. package/dist/plugins/toolbar/components/CodeToggle.d.ts +2 -0
  218. package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
  219. package/dist/plugins/toolbar/components/CreateLink.d.ts +2 -0
  220. package/dist/plugins/toolbar/components/CreateLink.js +11 -0
  221. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +4 -0
  222. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
  223. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +2 -0
  224. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  225. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +2 -0
  226. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  227. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +2 -0
  228. package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
  229. package/dist/plugins/toolbar/components/InsertImage.d.ts +2 -0
  230. package/dist/plugins/toolbar/components/InsertImage.js +23 -0
  231. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +2 -0
  232. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  233. package/dist/plugins/toolbar/components/InsertTable.d.ts +2 -0
  234. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  235. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +2 -0
  236. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  237. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +2 -0
  238. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  239. package/dist/plugins/toolbar/components/ListsToggle.d.ts +2 -0
  240. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  241. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +2 -0
  242. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
  243. package/dist/plugins/toolbar/components/UndoRedo.d.ts +2 -0
  244. package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
  245. package/dist/plugins/toolbar/index.d.ts +416 -0
  246. package/dist/plugins/toolbar/index.js +39 -0
  247. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  248. package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
  249. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +5 -0
  250. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  251. package/dist/plugins/toolbar/primitives/select.d.ts +31 -0
  252. package/dist/plugins/toolbar/primitives/select.js +44 -0
  253. package/dist/plugins/toolbar/primitives/toolbar.d.ts +85 -0
  254. package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
  255. package/dist/style.css +556 -242
  256. package/dist/styles/globals.css.js +4 -0
  257. package/dist/styles/lexical-theme.module.css.js +53 -0
  258. package/dist/styles/lexicalTheme.d.ts +2 -0
  259. package/dist/styles/lexicalTheme.js +28 -0
  260. package/dist/styles/ui.module.css.js +257 -0
  261. package/dist/utils/detectMac.d.ts +2 -0
  262. package/dist/utils/detectMac.js +6 -0
  263. package/dist/utils/fp.d.ts +47 -0
  264. package/dist/utils/fp.js +10 -0
  265. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  266. package/dist/utils/isPartOftheEditorUI.js +12 -0
  267. package/dist/utils/lexicalHelpers.d.ts +11 -0
  268. package/dist/utils/lexicalHelpers.js +49 -0
  269. package/dist/utils/uuid4.d.ts +1 -0
  270. package/dist/utils/uuid4.js +10 -0
  271. package/dist/utils/voidEmitter.d.ts +14 -0
  272. package/dist/utils/voidEmitter.js +15 -0
  273. package/package.json +185 -14
  274. package/dist/CodeBlockEditor-ce4c85ed.js +0 -79
  275. package/dist/CodeBlockEditor-ed222322.cjs +0 -1
  276. package/dist/FrontmatterEditor-914aa241.cjs +0 -1
  277. package/dist/FrontmatterEditor-e2f25a6a.js +0 -118
  278. package/dist/ImageEditor-c4e65554.cjs +0 -1
  279. package/dist/JsxEditor-6cff258d.cjs +0 -1
  280. package/dist/JsxEditor-88d55ef8.js +0 -108
  281. package/dist/LeafDirectiveEditor-0e1328e6.cjs +0 -1
  282. package/dist/LeafDirectiveEditor-34ead530.js +0 -59
  283. package/dist/SandpackEditor-a999ca47.cjs +0 -1
  284. package/dist/SandpackEditor-b1e22784.js +0 -99
  285. package/dist/SourceEditor-0c46ec47.cjs +0 -1
  286. package/dist/SourceEditor-e509d0a5.js +0 -64
  287. package/dist/TableEditor-44bef804.js +0 -426
  288. package/dist/TableEditor-ced03ce4.cjs +0 -1
  289. package/dist/index-21fcefae.cjs +0 -1
  290. package/dist/index-ce0832cc.js +0 -4361
  291. package/dist/index.cjs +0 -1
  292. package/dist/useCodeMirrorRef-6cb866bd.cjs +0 -1
@@ -0,0 +1,246 @@
1
+ import { $wrapNodeInElement } from "@lexical/utils";
2
+ import { createCommand, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
3
+ import { coreSystem } from "../core/index.js";
4
+ import { $createImageNode, $isImageNode, ImageNode } from "./ImageNode.js";
5
+ import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
6
+ import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
7
+ import { CAN_USE_DOM } from "../../utils/detectMac.js";
8
+ import { system } from "../../gurx/realmFactory.js";
9
+ import { realmPlugin } from "../../gurx/react.js";
10
+ const imageSystem = system(
11
+ (r, [{ rootEditor }]) => {
12
+ const insertImage = r.node();
13
+ const imageAutocompleteSuggestions = r.node([]);
14
+ const imageUploadHandler = r.node((_) => {
15
+ throw new Error("Image upload handling is not implemented");
16
+ });
17
+ r.sub(r.pipe(insertImage, r.o.withLatestFrom(rootEditor)), ([src, theEditor]) => {
18
+ theEditor == null ? void 0 : theEditor.update(() => {
19
+ const imageNode = $createImageNode({ altText: "", src, title: "" });
20
+ $insertNodes([imageNode]);
21
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
22
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
23
+ }
24
+ });
25
+ });
26
+ r.sub(rootEditor, (editor) => {
27
+ editor == null ? void 0 : editor.registerCommand(
28
+ INSERT_IMAGE_COMMAND,
29
+ (payload) => {
30
+ const imageNode = $createImageNode(payload);
31
+ $insertNodes([imageNode]);
32
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
33
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
34
+ }
35
+ return true;
36
+ },
37
+ COMMAND_PRIORITY_EDITOR
38
+ );
39
+ editor == null ? void 0 : editor.registerCommand(
40
+ DRAGSTART_COMMAND,
41
+ (event) => {
42
+ return onDragStart(event);
43
+ },
44
+ COMMAND_PRIORITY_HIGH
45
+ );
46
+ editor == null ? void 0 : editor.registerCommand(
47
+ DRAGOVER_COMMAND,
48
+ (event) => {
49
+ return onDragover(event);
50
+ },
51
+ COMMAND_PRIORITY_LOW
52
+ );
53
+ editor == null ? void 0 : editor.registerCommand(
54
+ DROP_COMMAND,
55
+ (event) => {
56
+ return onDrop(event, editor, r.getValue(imageUploadHandler));
57
+ },
58
+ COMMAND_PRIORITY_HIGH
59
+ );
60
+ editor == null ? void 0 : editor.registerCommand(
61
+ PASTE_COMMAND,
62
+ (event) => {
63
+ var _a;
64
+ let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
65
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
66
+ if (!cbPayload.length || cbPayload.length === 0) {
67
+ return false;
68
+ }
69
+ const imageUploadHandlerValue = r.getValue(imageUploadHandler);
70
+ Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
71
+ urls.forEach((url) => {
72
+ r.pub(insertImage, url);
73
+ });
74
+ }).catch((e) => {
75
+ throw e;
76
+ });
77
+ return true;
78
+ },
79
+ COMMAND_PRIORITY_CRITICAL
80
+ );
81
+ });
82
+ return {
83
+ imageUploadHandler,
84
+ imageAutocompleteSuggestions,
85
+ insertImage
86
+ };
87
+ },
88
+ [coreSystem]
89
+ );
90
+ const defaultParams = {
91
+ imageUploadHandler: () => {
92
+ throw new Error("Image upload handling is not implemented");
93
+ }
94
+ };
95
+ const [
96
+ /** @internal */
97
+ imagePlugin,
98
+ /** @internal */
99
+ imagePluginHooks
100
+ ] = realmPlugin({
101
+ id: "image",
102
+ systemSpec: imageSystem,
103
+ applyParamsToSystem: (realm, params = defaultParams) => {
104
+ realm.pubKey("imageUploadHandler", params.imageUploadHandler);
105
+ realm.pubKey("imageAutocompleteSuggestions", params.imageAutocompleteSuggestions || []);
106
+ },
107
+ init: (realm) => {
108
+ realm.pubKey("addImportVisitor", MdastImageVisitor);
109
+ realm.pubKey("addImportVisitor", MdastHtmlImageVisitor);
110
+ realm.pubKey("addImportVisitor", MdastJsxImageVisitor);
111
+ realm.pubKey("addLexicalNode", ImageNode);
112
+ realm.pubKey("addExportVisitor", LexicalImageVisitor);
113
+ }
114
+ });
115
+ const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
116
+ const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
117
+ const TRANSPARENT_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
118
+ function onDragStart(event) {
119
+ const node = getImageNodeInSelection();
120
+ if (!node) {
121
+ return false;
122
+ }
123
+ const dataTransfer = event.dataTransfer;
124
+ if (!dataTransfer) {
125
+ return false;
126
+ }
127
+ dataTransfer.setData("text/plain", "_");
128
+ const img = document.createElement("img");
129
+ img.src = TRANSPARENT_IMAGE;
130
+ dataTransfer.setDragImage(img, 0, 0);
131
+ dataTransfer.setData(
132
+ "application/x-lexical-drag",
133
+ JSON.stringify({
134
+ data: {
135
+ altText: node.__altText,
136
+ title: node.__title,
137
+ key: node.getKey(),
138
+ src: node.__src
139
+ },
140
+ type: "image"
141
+ })
142
+ );
143
+ return true;
144
+ }
145
+ function onDragover(event) {
146
+ var _a;
147
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
148
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
149
+ if (cbPayload.length > 0) {
150
+ event.preventDefault();
151
+ return true;
152
+ }
153
+ const node = getImageNodeInSelection();
154
+ if (!node) {
155
+ return false;
156
+ }
157
+ if (!canDropImage(event)) {
158
+ event.preventDefault();
159
+ }
160
+ return true;
161
+ }
162
+ function onDrop(event, editor, imageUploadHandler) {
163
+ var _a;
164
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
165
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
166
+ if (cbPayload.length > 0) {
167
+ event.preventDefault();
168
+ Promise.all(cbPayload.map((image) => imageUploadHandler(image.getAsFile()))).then((urls) => {
169
+ urls.forEach((url) => {
170
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
171
+ src: url,
172
+ altText: ""
173
+ });
174
+ });
175
+ }).catch((e) => {
176
+ throw e;
177
+ });
178
+ return true;
179
+ }
180
+ const node = getImageNodeInSelection();
181
+ if (!node) {
182
+ return false;
183
+ }
184
+ const data = getDragImageData(event);
185
+ if (!data) {
186
+ return false;
187
+ }
188
+ event.preventDefault();
189
+ if (canDropImage(event)) {
190
+ const range = getDragSelection(event);
191
+ node.remove();
192
+ const rangeSelection = $createRangeSelection();
193
+ if (range !== null && range !== void 0) {
194
+ rangeSelection.applyDOMRange(range);
195
+ }
196
+ $setSelection(rangeSelection);
197
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, data);
198
+ }
199
+ return true;
200
+ }
201
+ function getImageNodeInSelection() {
202
+ const selection = $getSelection();
203
+ if (!$isNodeSelection(selection)) {
204
+ return null;
205
+ }
206
+ const nodes = selection.getNodes();
207
+ const node = nodes[0];
208
+ return $isImageNode(node) ? node : null;
209
+ }
210
+ function getDragImageData(event) {
211
+ var _a;
212
+ const dragData = (_a = event.dataTransfer) == null ? void 0 : _a.getData("application/x-lexical-drag");
213
+ if (!dragData) {
214
+ return null;
215
+ }
216
+ const { type, data } = JSON.parse(dragData);
217
+ if (type !== "image") {
218
+ return null;
219
+ }
220
+ return data;
221
+ }
222
+ function canDropImage(event) {
223
+ const target = event.target;
224
+ return !!(target && target instanceof HTMLElement && target.parentElement);
225
+ }
226
+ function getDragSelection(event) {
227
+ let range;
228
+ const target = event.target;
229
+ const targetWindow = target == null ? null : target.nodeType === 9 ? target.defaultView : target.ownerDocument.defaultView;
230
+ const domSelection = getDOMSelection(targetWindow);
231
+ if (document.caretRangeFromPoint) {
232
+ range = document.caretRangeFromPoint(event.clientX, event.clientY);
233
+ } else if (event.rangeParent && domSelection !== null) {
234
+ domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
235
+ range = domSelection.getRangeAt(0);
236
+ } else {
237
+ throw Error(`Cannot get the selection when dragging`);
238
+ }
239
+ return range;
240
+ }
241
+ export {
242
+ INSERT_IMAGE_COMMAND,
243
+ imagePlugin,
244
+ imagePluginHooks,
245
+ imageSystem
246
+ };
@@ -0,0 +1,54 @@
1
+ import type { EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
2
+ import { DecoratorNode } from 'lexical';
3
+ import React from 'react';
4
+ import { MdastJsx } from '.';
5
+ import { VoidEmitter } from '../../utils/voidEmitter';
6
+ /**
7
+ * A serialized representation of an {@link LexicalJsxNode}.
8
+ */
9
+ export type SerializedLexicalJsxNode = Spread<{
10
+ mdastNode: MdastJsx;
11
+ type: 'jsx';
12
+ version: 1;
13
+ }, SerializedLexicalNode>;
14
+ /**
15
+ * A lexical node that represents an image. Use {@link "$createLexicalJsxNode"} to construct one.
16
+ */
17
+ export declare class LexicalJsxNode extends DecoratorNode<JSX.Element> {
18
+ __mdastNode: MdastJsx;
19
+ __focusEmitter: {
20
+ publish: () => void;
21
+ subscribe: (cb: () => void) => void;
22
+ };
23
+ static getType(): string;
24
+ static clone(node: LexicalJsxNode): LexicalJsxNode;
25
+ static importJSON(serializedNode: SerializedLexicalJsxNode): LexicalJsxNode;
26
+ constructor(mdastNode: MdastJsx, key?: NodeKey);
27
+ getMdastNode(): MdastJsx;
28
+ exportJSON(): SerializedLexicalJsxNode;
29
+ createDOM(): HTMLElement;
30
+ updateDOM(): false;
31
+ setMdastNode(mdastNode: MdastJsx): void;
32
+ select: () => void;
33
+ decorate(parentEditor: LexicalEditor, config: EditorConfig): JSX.Element;
34
+ isInline(): boolean;
35
+ isKeyboardSelectable(): boolean;
36
+ }
37
+ export declare function JsxEditorContainer(props: {
38
+ /** The Lexical editor that contains the node */
39
+ parentEditor: LexicalEditor;
40
+ /** The Lexical node that is being edited */
41
+ lexicalJsxNode: LexicalJsxNode;
42
+ /** The MDAST node that is being edited */
43
+ mdastNode: MdastJsx;
44
+ config: EditorConfig;
45
+ focusEmitter: VoidEmitter;
46
+ }): React.JSX.Element;
47
+ /**
48
+ * Creates an {@link LexicalJsxNode}.
49
+ */
50
+ export declare function $createLexicalJsxNode(mdastNode: MdastJsx): LexicalJsxNode;
51
+ /**
52
+ * Retruns true if the node is an {@link LexicalJsxNode}.
53
+ */
54
+ export declare function $isLexicalJsxNode(node: LexicalNode | null | undefined): node is LexicalJsxNode;
@@ -0,0 +1,99 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { DecoratorNode } from "lexical";
8
+ import React__default from "react";
9
+ import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
10
+ import { jsxPluginHooks } from "./index.js";
11
+ import { voidEmitter } from "../../utils/voidEmitter.js";
12
+ class LexicalJsxNode extends DecoratorNode {
13
+ constructor(mdastNode, key) {
14
+ super(key);
15
+ __publicField(this, "__mdastNode");
16
+ __publicField(this, "__focusEmitter", voidEmitter());
17
+ __publicField(this, "select", () => {
18
+ this.__focusEmitter.publish();
19
+ });
20
+ this.__mdastNode = mdastNode;
21
+ }
22
+ static getType() {
23
+ return "jsx";
24
+ }
25
+ static clone(node) {
26
+ return new LexicalJsxNode(structuredClone(node.__mdastNode));
27
+ }
28
+ static importJSON(serializedNode) {
29
+ return $createLexicalJsxNode(serializedNode.mdastNode);
30
+ }
31
+ getMdastNode() {
32
+ return this.__mdastNode;
33
+ }
34
+ exportJSON() {
35
+ return {
36
+ mdastNode: this.getMdastNode(),
37
+ type: "jsx",
38
+ version: 1
39
+ };
40
+ }
41
+ createDOM() {
42
+ return document.createElement(this.__mdastNode.type === "mdxJsxTextElement" ? "span" : "div");
43
+ }
44
+ updateDOM() {
45
+ return false;
46
+ }
47
+ setMdastNode(mdastNode) {
48
+ this.getWritable().__mdastNode = mdastNode;
49
+ }
50
+ decorate(parentEditor, config) {
51
+ return /* @__PURE__ */ React__default.createElement(
52
+ JsxEditorContainer,
53
+ {
54
+ lexicalJsxNode: this,
55
+ config,
56
+ mdastNode: this.getMdastNode(),
57
+ parentEditor,
58
+ focusEmitter: this.__focusEmitter
59
+ }
60
+ );
61
+ }
62
+ isInline() {
63
+ return this.__mdastNode.type === "mdxJsxTextElement";
64
+ }
65
+ isKeyboardSelectable() {
66
+ return true;
67
+ }
68
+ }
69
+ function JsxEditorContainer(props) {
70
+ const { mdastNode } = props;
71
+ const [jsxComponentDescriptors] = jsxPluginHooks.useEmitterValues("jsxComponentDescriptors");
72
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name);
73
+ const Editor = descriptor.Editor;
74
+ return /* @__PURE__ */ React__default.createElement(
75
+ NestedEditorsContext.Provider,
76
+ {
77
+ value: {
78
+ config: props.config,
79
+ focusEmitter: props.focusEmitter,
80
+ mdastNode,
81
+ parentEditor: props.parentEditor,
82
+ lexicalNode: props.lexicalJsxNode
83
+ }
84
+ },
85
+ /* @__PURE__ */ React__default.createElement(Editor, { descriptor, mdastNode })
86
+ );
87
+ }
88
+ function $createLexicalJsxNode(mdastNode) {
89
+ return new LexicalJsxNode(mdastNode);
90
+ }
91
+ function $isLexicalJsxNode(node) {
92
+ return node instanceof LexicalJsxNode;
93
+ }
94
+ export {
95
+ $createLexicalJsxNode,
96
+ $isLexicalJsxNode,
97
+ JsxEditorContainer,
98
+ LexicalJsxNode
99
+ };
@@ -0,0 +1,4 @@
1
+ import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
2
+ import { LexicalJsxNode } from './LexicalJsxNode';
3
+ import { LexicalExportVisitor } from '../../exportMarkdownFromLexical';
4
+ export declare const LexicalJsxVisitor: LexicalExportVisitor<LexicalJsxNode, MdxJsxFlowElement | MdxJsxTextElement>;
@@ -0,0 +1,12 @@
1
+ import { $isLexicalJsxNode } from "./LexicalJsxNode.js";
2
+ const LexicalJsxVisitor = {
3
+ testLexicalNode: $isLexicalJsxNode,
4
+ visitLexicalNode({ actions, mdastParent, lexicalNode }) {
5
+ const mdastNode = lexicalNode.getMdastNode();
6
+ actions.registerReferredComponent(mdastNode.name);
7
+ actions.appendToParent(mdastParent, mdastNode);
8
+ }
9
+ };
10
+ export {
11
+ LexicalJsxVisitor
12
+ };
@@ -0,0 +1,3 @@
1
+ import { MdxjsEsm } from 'mdast-util-mdx';
2
+ import { MdastImportVisitor } from '../../importMarkdownToLexical';
3
+ export declare const MdastMdxJsEsmVisitor: MdastImportVisitor<MdxjsEsm>;
@@ -0,0 +1,8 @@
1
+ const MdastMdxJsEsmVisitor = {
2
+ testNode: "mdxjsEsm",
3
+ visitNode() {
4
+ }
5
+ };
6
+ export {
7
+ MdastMdxJsEsmVisitor
8
+ };
@@ -0,0 +1,3 @@
1
+ import { MdxJsxTextElement } from 'mdast-util-mdx';
2
+ import { MdastImportVisitor } from '../../importMarkdownToLexical';
3
+ export declare const MdastMdxJsxElementVisitor: MdastImportVisitor<MdxJsxTextElement>;
@@ -0,0 +1,12 @@
1
+ import { $createLexicalJsxNode } from "./LexicalJsxNode.js";
2
+ const MdastMdxJsxElementVisitor = {
3
+ testNode: (node) => {
4
+ return (node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement") && node.name !== "img";
5
+ },
6
+ visitNode({ lexicalParent, mdastNode }) {
7
+ lexicalParent.append($createLexicalJsxNode(mdastNode));
8
+ }
9
+ };
10
+ export {
11
+ MdastMdxJsxElementVisitor
12
+ };