@mdxeditor/editor 0.0.0-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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/dist/FormatConstants.d.ts +9 -0
  4. package/dist/FormatConstants.js +10 -0
  5. package/dist/MDXEditor.d.ts +92 -0
  6. package/dist/MDXEditor.js +142 -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 +133 -0
  12. package/dist/exportMarkdownFromLexical.js +202 -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/check_small.svg.js +5 -0
  27. package/dist/icons/close.svg.js +5 -0
  28. package/dist/icons/code.svg.js +5 -0
  29. package/dist/icons/code_block.svg.js +5 -0
  30. package/dist/icons/content_copy.svg.js +5 -0
  31. package/dist/icons/delete_big.svg.js +5 -0
  32. package/dist/icons/delete_small.svg.js +5 -0
  33. package/dist/icons/difference.svg.js +5 -0
  34. package/dist/icons/edit.svg.js +5 -0
  35. package/dist/icons/format_align_center.svg.js +5 -0
  36. package/dist/icons/format_align_left.svg.js +5 -0
  37. package/dist/icons/format_align_right.svg.js +5 -0
  38. package/dist/icons/format_bold.svg.js +5 -0
  39. package/dist/icons/format_italic.svg.js +5 -0
  40. package/dist/icons/format_list_bulleted.svg.js +7 -0
  41. package/dist/icons/format_list_checked.svg.js +5 -0
  42. package/dist/icons/format_list_numbered.svg.js +5 -0
  43. package/dist/icons/format_underlined.svg.js +5 -0
  44. package/dist/icons/frontmatter.svg.js +5 -0
  45. package/dist/icons/horizontal_rule.svg.js +5 -0
  46. package/dist/icons/insert_col_left.svg.js +5 -0
  47. package/dist/icons/insert_col_right.svg.js +5 -0
  48. package/dist/icons/insert_row_above.svg.js +5 -0
  49. package/dist/icons/insert_row_below.svg.js +5 -0
  50. package/dist/icons/link.svg.js +5 -0
  51. package/dist/icons/link_off.svg.js +5 -0
  52. package/dist/icons/markdown.svg.js +5 -0
  53. package/dist/icons/more_horiz.svg.js +5 -0
  54. package/dist/icons/more_vert.svg.js +5 -0
  55. package/dist/icons/open_in_new.svg.js +5 -0
  56. package/dist/icons/redo.svg.js +5 -0
  57. package/dist/icons/rich_text.svg.js +5 -0
  58. package/dist/icons/sandpack.svg.js +5 -0
  59. package/dist/icons/settings.svg.js +7 -0
  60. package/dist/icons/table.svg.js +5 -0
  61. package/dist/icons/undo.svg.js +5 -0
  62. package/dist/importMarkdownToLexical.d.ts +91 -0
  63. package/dist/importMarkdownToLexical.js +69 -0
  64. package/dist/index.d.ts +54 -0
  65. package/dist/index.js +175 -0
  66. package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
  67. package/dist/jsx-editors/GenericJsxEditor.js +56 -0
  68. package/dist/plugins/codeblock/CodeBlockNode.d.ts +100 -0
  69. package/dist/plugins/codeblock/CodeBlockNode.js +158 -0
  70. package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
  71. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  72. package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
  73. package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
  74. package/dist/plugins/codeblock/index.d.ts +697 -0
  75. package/dist/plugins/codeblock/index.js +73 -0
  76. package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
  77. package/dist/plugins/codemirror/CodeMirrorEditor.js +42 -0
  78. package/dist/plugins/codemirror/index.d.ts +912 -0
  79. package/dist/plugins/codemirror/index.js +62 -0
  80. package/dist/plugins/core/Icon.d.ts +6 -0
  81. package/dist/plugins/core/Icon.js +94 -0
  82. package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
  83. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  84. package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
  85. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  86. package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
  87. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  88. package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
  89. package/dist/plugins/core/LexicalTextVisitor.js +85 -0
  90. package/dist/plugins/core/MdastBreakVisitor.d.ts +3 -0
  91. package/dist/plugins/core/MdastBreakVisitor.js +10 -0
  92. package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
  93. package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
  94. package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
  95. package/dist/plugins/core/MdastInlineCodeVisitor.js +27 -0
  96. package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
  97. package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
  98. package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
  99. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  100. package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
  101. package/dist/plugins/core/MdastTextVisitor.js +10 -0
  102. package/dist/plugins/core/NestedLexicalEditor.d.ts +92 -0
  103. package/dist/plugins/core/NestedLexicalEditor.js +180 -0
  104. package/dist/plugins/core/PropertyPopover.d.ts +23 -0
  105. package/dist/plugins/core/PropertyPopover.js +39 -0
  106. package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
  107. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  108. package/dist/plugins/core/index.d.ts +506 -0
  109. package/dist/plugins/core/index.js +420 -0
  110. package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +15 -0
  111. package/dist/plugins/core/ui/DownshiftAutoComplete.js +83 -0
  112. package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
  113. package/dist/plugins/core/ui/PopoverUtils.js +17 -0
  114. package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
  115. package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
  116. package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
  117. package/dist/plugins/diff-source/DiffViewer.js +59 -0
  118. package/dist/plugins/diff-source/SourceEditor.d.ts +4 -0
  119. package/dist/plugins/diff-source/SourceEditor.js +47 -0
  120. package/dist/plugins/diff-source/index.d.ts +635 -0
  121. package/dist/plugins/diff-source/index.js +57 -0
  122. package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
  123. package/dist/plugins/directives/DirectiveNode.js +92 -0
  124. package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
  125. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  126. package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
  127. package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
  128. package/dist/plugins/directives/index.d.ts +683 -0
  129. package/dist/plugins/directives/index.js +53 -0
  130. package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
  131. package/dist/plugins/frontmatter/FrontmatterEditor.js +85 -0
  132. package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
  133. package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
  134. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
  135. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  136. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
  137. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  138. package/dist/plugins/frontmatter/index.d.ts +627 -0
  139. package/dist/plugins/frontmatter/index.js +76 -0
  140. package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
  141. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  142. package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
  143. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  144. package/dist/plugins/headings/index.d.ts +617 -0
  145. package/dist/plugins/headings/index.js +69 -0
  146. package/dist/plugins/image/ImageDialog.d.ts +2 -0
  147. package/dist/plugins/image/ImageDialog.js +70 -0
  148. package/dist/plugins/image/ImageEditor.d.ts +10 -0
  149. package/dist/plugins/image/ImageEditor.js +227 -0
  150. package/dist/plugins/image/ImageNode.d.ts +65 -0
  151. package/dist/plugins/image/ImageNode.js +152 -0
  152. package/dist/plugins/image/ImageResizer.d.ts +18 -0
  153. package/dist/plugins/image/ImageResizer.js +214 -0
  154. package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
  155. package/dist/plugins/image/LexicalImageVisitor.js +35 -0
  156. package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
  157. package/dist/plugins/image/MdastImageVisitor.js +87 -0
  158. package/dist/plugins/image/index.d.ts +714 -0
  159. package/dist/plugins/image/index.js +300 -0
  160. package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
  161. package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
  162. package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
  163. package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
  164. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
  165. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  166. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
  167. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
  168. package/dist/plugins/jsx/index.d.ts +688 -0
  169. package/dist/plugins/jsx/index.js +78 -0
  170. package/dist/plugins/link/AutoLinkPlugin.d.ts +9 -0
  171. package/dist/plugins/link/AutoLinkPlugin.js +18 -0
  172. package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
  173. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  174. package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
  175. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  176. package/dist/plugins/link/index.d.ts +92 -0
  177. package/dist/plugins/link/index.js +33 -0
  178. package/dist/plugins/link-dialog/LinkDialog.d.ts +16 -0
  179. package/dist/plugins/link-dialog/LinkDialog.js +148 -0
  180. package/dist/plugins/link-dialog/index.d.ts +595 -0
  181. package/dist/plugins/link-dialog/index.js +260 -0
  182. package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
  183. package/dist/plugins/lists/LexicalListItemVisitor.js +23 -0
  184. package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
  185. package/dist/plugins/lists/LexicalListVisitor.js +13 -0
  186. package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
  187. package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
  188. package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
  189. package/dist/plugins/lists/MdastListVisitor.js +20 -0
  190. package/dist/plugins/lists/index.d.ts +613 -0
  191. package/dist/plugins/lists/index.js +119 -0
  192. package/dist/plugins/markdown-shortcut/index.d.ts +71 -0
  193. package/dist/plugins/markdown-shortcut/index.js +90 -0
  194. package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
  195. package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
  196. package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
  197. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  198. package/dist/plugins/quote/index.d.ts +417 -0
  199. package/dist/plugins/quote/index.js +26 -0
  200. package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
  201. package/dist/plugins/sandpack/SandpackEditor.js +37 -0
  202. package/dist/plugins/sandpack/index.d.ts +951 -0
  203. package/dist/plugins/sandpack/index.js +93 -0
  204. package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
  205. package/dist/plugins/sandpack/useCodeMirrorRef.js +96 -0
  206. package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
  207. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  208. package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
  209. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  210. package/dist/plugins/table/TableEditor.d.ts +21 -0
  211. package/dist/plugins/table/TableEditor.js +388 -0
  212. package/dist/plugins/table/TableNode.d.ts +52 -0
  213. package/dist/plugins/table/TableNode.js +152 -0
  214. package/dist/plugins/table/index.d.ts +614 -0
  215. package/dist/plugins/table/index.js +69 -0
  216. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
  217. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  218. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
  219. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  220. package/dist/plugins/thematic-break/index.d.ts +603 -0
  221. package/dist/plugins/thematic-break/index.js +39 -0
  222. package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
  223. package/dist/plugins/toolbar/components/BlockTypeSelect.js +54 -0
  224. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
  225. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +33 -0
  226. package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
  227. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
  228. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
  229. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
  230. package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
  231. package/dist/plugins/toolbar/components/CodeToggle.js +19 -0
  232. package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
  233. package/dist/plugins/toolbar/components/CreateLink.js +20 -0
  234. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
  235. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +25 -0
  236. package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
  237. package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
  238. package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
  239. package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
  240. package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
  241. package/dist/plugins/toolbar/components/InsertFrontmatter.js +24 -0
  242. package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
  243. package/dist/plugins/toolbar/components/InsertImage.js +14 -0
  244. package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
  245. package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
  246. package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
  247. package/dist/plugins/toolbar/components/InsertTable.js +20 -0
  248. package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
  249. package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
  250. package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
  251. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
  252. package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
  253. package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
  254. package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
  255. package/dist/plugins/toolbar/components/ShowSandpackInfo.js +31 -0
  256. package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
  257. package/dist/plugins/toolbar/components/UndoRedo.js +58 -0
  258. package/dist/plugins/toolbar/index.d.ts +492 -0
  259. package/dist/plugins/toolbar/index.js +40 -0
  260. package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
  261. package/dist/plugins/toolbar/primitives/DialogButton.js +114 -0
  262. package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
  263. package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
  264. package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
  265. package/dist/plugins/toolbar/primitives/select.js +55 -0
  266. package/dist/plugins/toolbar/primitives/toolbar.d.ts +163 -0
  267. package/dist/plugins/toolbar/primitives/toolbar.js +115 -0
  268. package/dist/style.css +1715 -0
  269. package/dist/styles/globals.css.js +4 -0
  270. package/dist/styles/lexical-theme.module.css.js +62 -0
  271. package/dist/styles/lexicalTheme.d.ts +2 -0
  272. package/dist/styles/lexicalTheme.js +31 -0
  273. package/dist/styles/ui.module.css.js +308 -0
  274. package/dist/utils/detectMac.d.ts +3 -0
  275. package/dist/utils/detectMac.js +13 -0
  276. package/dist/utils/fp.d.ts +47 -0
  277. package/dist/utils/fp.js +14 -0
  278. package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
  279. package/dist/utils/isPartOftheEditorUI.js +12 -0
  280. package/dist/utils/lexicalHelpers.d.ts +11 -0
  281. package/dist/utils/lexicalHelpers.js +62 -0
  282. package/dist/utils/uuid4.d.ts +1 -0
  283. package/dist/utils/uuid4.js +10 -0
  284. package/dist/utils/voidEmitter.d.ts +14 -0
  285. package/dist/utils/voidEmitter.js +15 -0
  286. package/package.json +435 -0
@@ -0,0 +1,300 @@
1
+ import { $wrapNodeInElement } from "@lexical/utils";
2
+ import { $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, createCommand, $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 { ImageDialog } from "./ImageDialog.js";
9
+ import { system } from "../../gurx/realmFactory.js";
10
+ import { realmPlugin } from "../../gurx/react.js";
11
+ const imageSystem = system(
12
+ (r, [{ rootEditor }]) => {
13
+ const insertImage = r.node();
14
+ const imageAutocompleteSuggestions = r.node([]);
15
+ const disableImageResize = r.node(false);
16
+ const imageUploadHandler = r.node(null);
17
+ const imagePreviewHandler = r.node(null);
18
+ const imageDialogState = r.node({ type: "inactive" });
19
+ const openNewImageDialog = r.node();
20
+ const openEditImageDialog = r.node();
21
+ const closeImageDialog = r.node();
22
+ const saveImage = r.node();
23
+ r.link(r.pipe(closeImageDialog, r.o.mapTo({ type: "inactive" })), imageDialogState);
24
+ r.link(r.pipe(openNewImageDialog, r.o.mapTo({ type: "new" })), imageDialogState);
25
+ r.link(
26
+ r.pipe(
27
+ openEditImageDialog,
28
+ r.o.map((payload) => ({ type: "editing", ...payload }))
29
+ ),
30
+ imageDialogState
31
+ );
32
+ r.sub(
33
+ r.pipe(saveImage, r.o.withLatestFrom(rootEditor, imageUploadHandler, imageDialogState)),
34
+ ([values, theEditor, imageUploadHandler2, dialogState]) => {
35
+ const handler = dialogState.type === "editing" ? (src) => {
36
+ theEditor == null ? void 0 : theEditor.update(() => {
37
+ const { nodeKey } = dialogState;
38
+ const imageNode = $getNodeByKey(nodeKey);
39
+ imageNode.setTitle(values.title);
40
+ imageNode.setAltText(values.altText);
41
+ imageNode.setSrc(src);
42
+ });
43
+ r.pub(imageDialogState, { type: "inactive" });
44
+ } : (src) => {
45
+ theEditor == null ? void 0 : theEditor.update(() => {
46
+ const imageNode = $createImageNode({ altText: values.altText ?? "", src, title: values.title ?? "" });
47
+ $insertNodes([imageNode]);
48
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
49
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
50
+ }
51
+ });
52
+ r.pub(imageDialogState, { type: "inactive" });
53
+ };
54
+ if (values.file.length > 0) {
55
+ imageUploadHandler2 == null ? void 0 : imageUploadHandler2(values.file.item(0)).then(handler).catch((e) => {
56
+ throw e;
57
+ });
58
+ } else if (values.src) {
59
+ handler(values.src);
60
+ }
61
+ }
62
+ );
63
+ r.sub(rootEditor, (editor) => {
64
+ editor == null ? void 0 : editor.registerCommand(
65
+ INSERT_IMAGE_COMMAND,
66
+ (payload) => {
67
+ const imageNode = $createImageNode(payload);
68
+ $insertNodes([imageNode]);
69
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
70
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
71
+ }
72
+ return true;
73
+ },
74
+ COMMAND_PRIORITY_EDITOR
75
+ );
76
+ const theUploadHandler = r.getValue(imageUploadHandler);
77
+ editor == null ? void 0 : editor.registerCommand(
78
+ DRAGSTART_COMMAND,
79
+ (event) => {
80
+ return onDragStart(event);
81
+ },
82
+ COMMAND_PRIORITY_HIGH
83
+ );
84
+ editor == null ? void 0 : editor.registerCommand(
85
+ DRAGOVER_COMMAND,
86
+ (event) => {
87
+ return onDragover(event);
88
+ },
89
+ COMMAND_PRIORITY_LOW
90
+ );
91
+ editor == null ? void 0 : editor.registerCommand(
92
+ DROP_COMMAND,
93
+ (event) => {
94
+ return onDrop(event, editor, r.getValue(imageUploadHandler));
95
+ },
96
+ COMMAND_PRIORITY_HIGH
97
+ );
98
+ if (theUploadHandler === null) {
99
+ return;
100
+ }
101
+ editor == null ? void 0 : editor.registerCommand(
102
+ PASTE_COMMAND,
103
+ (event) => {
104
+ var _a;
105
+ let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
106
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
107
+ if (!cbPayload.length || cbPayload.length === 0) {
108
+ return false;
109
+ }
110
+ const imageUploadHandlerValue = r.getValue(imageUploadHandler);
111
+ Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
112
+ urls.forEach((url) => {
113
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
114
+ src: url,
115
+ altText: ""
116
+ });
117
+ });
118
+ }).catch((e) => {
119
+ throw e;
120
+ });
121
+ return true;
122
+ },
123
+ COMMAND_PRIORITY_CRITICAL
124
+ );
125
+ });
126
+ return {
127
+ imageDialogState,
128
+ saveImage,
129
+ openNewImageDialog,
130
+ openEditImageDialog,
131
+ closeImageDialog,
132
+ imageUploadHandler,
133
+ imageAutocompleteSuggestions,
134
+ disableImageResize,
135
+ insertImage,
136
+ imagePreviewHandler
137
+ };
138
+ },
139
+ [coreSystem]
140
+ );
141
+ const [
142
+ /** @internal */
143
+ imagePlugin,
144
+ /** @internal */
145
+ imagePluginHooks
146
+ ] = realmPlugin({
147
+ id: "image",
148
+ systemSpec: imageSystem,
149
+ applyParamsToSystem: (realm, params) => {
150
+ realm.pubKey("imageUploadHandler", (params == null ? void 0 : params.imageUploadHandler) || null);
151
+ realm.pubKey("imageAutocompleteSuggestions", (params == null ? void 0 : params.imageAutocompleteSuggestions) || []);
152
+ realm.pubKey("disableImageResize", Boolean(params == null ? void 0 : params.disableImageResize));
153
+ realm.pubKey("imagePreviewHandler", (params == null ? void 0 : params.imagePreviewHandler) || null);
154
+ },
155
+ init: (realm) => {
156
+ realm.pubKey("addImportVisitor", MdastImageVisitor);
157
+ realm.pubKey("addImportVisitor", MdastHtmlImageVisitor);
158
+ realm.pubKey("addImportVisitor", MdastJsxImageVisitor);
159
+ realm.pubKey("addLexicalNode", ImageNode);
160
+ realm.pubKey("addExportVisitor", LexicalImageVisitor);
161
+ realm.pubKey("addComposerChild", ImageDialog);
162
+ }
163
+ });
164
+ const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
165
+ const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
166
+ const TRANSPARENT_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
167
+ function onDragStart(event) {
168
+ const node = getImageNodeInSelection();
169
+ if (!node) {
170
+ return false;
171
+ }
172
+ const dataTransfer = event.dataTransfer;
173
+ if (!dataTransfer) {
174
+ return false;
175
+ }
176
+ dataTransfer.setData("text/plain", "_");
177
+ const img = document.createElement("img");
178
+ img.src = TRANSPARENT_IMAGE;
179
+ dataTransfer.setDragImage(img, 0, 0);
180
+ dataTransfer.setData(
181
+ "application/x-lexical-drag",
182
+ JSON.stringify({
183
+ data: {
184
+ altText: node.__altText,
185
+ title: node.__title,
186
+ key: node.getKey(),
187
+ src: node.__src
188
+ },
189
+ type: "image"
190
+ })
191
+ );
192
+ return true;
193
+ }
194
+ function onDragover(event) {
195
+ var _a;
196
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
197
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
198
+ if (cbPayload.length > 0) {
199
+ event.preventDefault();
200
+ return true;
201
+ }
202
+ const node = getImageNodeInSelection();
203
+ if (!node) {
204
+ return false;
205
+ }
206
+ if (!canDropImage(event)) {
207
+ event.preventDefault();
208
+ }
209
+ return true;
210
+ }
211
+ function onDrop(event, editor, imageUploadHandler) {
212
+ var _a;
213
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
214
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
215
+ if (cbPayload.length > 0) {
216
+ if (imageUploadHandler !== null) {
217
+ event.preventDefault();
218
+ Promise.all(cbPayload.map((image) => imageUploadHandler(image.getAsFile()))).then((urls) => {
219
+ urls.forEach((url) => {
220
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
221
+ src: url,
222
+ altText: ""
223
+ });
224
+ });
225
+ }).catch((e) => {
226
+ throw e;
227
+ });
228
+ return true;
229
+ }
230
+ }
231
+ const node = getImageNodeInSelection();
232
+ if (!node) {
233
+ return false;
234
+ }
235
+ const data = getDragImageData(event);
236
+ if (!data) {
237
+ return false;
238
+ }
239
+ event.preventDefault();
240
+ if (canDropImage(event)) {
241
+ const range = getDragSelection(event);
242
+ node.remove();
243
+ const rangeSelection = $createRangeSelection();
244
+ if (range !== null && range !== void 0) {
245
+ rangeSelection.applyDOMRange(range);
246
+ }
247
+ $setSelection(rangeSelection);
248
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, data);
249
+ }
250
+ return true;
251
+ }
252
+ function getImageNodeInSelection() {
253
+ const selection = $getSelection();
254
+ if (!$isNodeSelection(selection)) {
255
+ return null;
256
+ }
257
+ const nodes = selection.getNodes();
258
+ const node = nodes[0];
259
+ return $isImageNode(node) ? node : null;
260
+ }
261
+ function getDragImageData(event) {
262
+ var _a;
263
+ const dragData = (_a = event.dataTransfer) == null ? void 0 : _a.getData("application/x-lexical-drag");
264
+ if (!dragData) {
265
+ return null;
266
+ }
267
+ const { type, data } = JSON.parse(dragData);
268
+ if (type !== "image") {
269
+ return null;
270
+ }
271
+ return data;
272
+ }
273
+ function canDropImage(event) {
274
+ const target = event.target;
275
+ return !!(target && target instanceof HTMLElement && target.parentElement);
276
+ }
277
+ function getDragSelection(event) {
278
+ let range;
279
+ const target = event.target;
280
+ const targetWindow = target == null ? null : target.nodeType === 9 ? target.defaultView : target.ownerDocument.defaultView;
281
+ const domSelection = getDOMSelection(targetWindow);
282
+ if (document.caretRangeFromPoint) {
283
+ range = document.caretRangeFromPoint(event.clientX, event.clientY);
284
+ } else if (event.rangeParent && domSelection !== null) {
285
+ domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
286
+ range = domSelection.getRangeAt(0);
287
+ } else {
288
+ throw Error(`Cannot get the selection when dragging`);
289
+ }
290
+ return range;
291
+ }
292
+ export {
293
+ $createImageNode,
294
+ $isImageNode,
295
+ INSERT_IMAGE_COMMAND,
296
+ ImageNode,
297
+ imagePlugin,
298
+ imagePluginHooks,
299
+ imageSystem
300
+ };
@@ -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,102 @@
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
+ if (!descriptor) {
74
+ throw new Error(`No JSX descriptor found for ${mdastNode.name}`);
75
+ }
76
+ const Editor = descriptor.Editor;
77
+ return /* @__PURE__ */ React__default.createElement(
78
+ NestedEditorsContext.Provider,
79
+ {
80
+ value: {
81
+ config: props.config,
82
+ focusEmitter: props.focusEmitter,
83
+ mdastNode,
84
+ parentEditor: props.parentEditor,
85
+ lexicalNode: props.lexicalJsxNode
86
+ }
87
+ },
88
+ /* @__PURE__ */ React__default.createElement(Editor, { descriptor, mdastNode })
89
+ );
90
+ }
91
+ function $createLexicalJsxNode(mdastNode) {
92
+ return new LexicalJsxNode(mdastNode);
93
+ }
94
+ function $isLexicalJsxNode(node) {
95
+ return node instanceof LexicalJsxNode;
96
+ }
97
+ export {
98
+ $createLexicalJsxNode,
99
+ $isLexicalJsxNode,
100
+ JsxEditorContainer,
101
+ LexicalJsxNode
102
+ };
@@ -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
+ };