@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,420 @@
1
+ import { createEmptyHistoryState } from "@lexical/react/LexicalHistoryPlugin.js";
2
+ import { $isHeadingNode } from "@lexical/rich-text";
3
+ import { $setBlocksType } from "@lexical/selection";
4
+ import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
5
+ import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, $setSelection, BLUR_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
6
+ import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
7
+ import { importMarkdownToLexical } from "../../importMarkdownToLexical.js";
8
+ import { LexicalLinebreakVisitor } from "./LexicalLinebreakVisitor.js";
9
+ import { LexicalParagraphVisitor } from "./LexicalParagraphVisitor.js";
10
+ import { LexicalRootVisitor } from "./LexicalRootVisitor.js";
11
+ import { LexicalTextVisitor } from "./LexicalTextVisitor.js";
12
+ import { MdastFormattingVisitor } from "./MdastFormattingVisitor.js";
13
+ import { MdastInlineCodeVisitor } from "./MdastInlineCodeVisitor.js";
14
+ import { MdastParagraphVisitor } from "./MdastParagraphVisitor.js";
15
+ import { MdastRootVisitor } from "./MdastRootVisitor.js";
16
+ import { MdastTextVisitor } from "./MdastTextVisitor.js";
17
+ import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
18
+ import { noop } from "../../utils/fp.js";
19
+ import { controlOrMeta } from "../../utils/detectMac.js";
20
+ import { MdastBreakVisitor } from "./MdastBreakVisitor.js";
21
+ import { system } from "../../gurx/realmFactory.js";
22
+ import { realmPlugin } from "../../gurx/react.js";
23
+ const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
24
+ const coreSystem = system((r) => {
25
+ function createAppendNodeFor(node) {
26
+ const appendNode = r.node();
27
+ r.link(
28
+ r.pipe(
29
+ appendNode,
30
+ r.o.withLatestFrom(node),
31
+ r.o.map(([newValue, values]) => {
32
+ if (values.includes(newValue)) {
33
+ return values;
34
+ }
35
+ return [...values, newValue];
36
+ })
37
+ ),
38
+ node
39
+ );
40
+ return appendNode;
41
+ }
42
+ const rootEditor = r.node(null);
43
+ const activeEditor = r.node(null, true);
44
+ const contentEditableClassName = r.node("");
45
+ const readOnly = r.node(false);
46
+ const placeholder = r.node("");
47
+ const autoFocus = r.node(false);
48
+ const inFocus = r.node(false, true);
49
+ const currentFormat = r.node(0, true);
50
+ const applyFormat = r.node();
51
+ const currentSelection = r.node(null);
52
+ const activeEditorSubscriptions = r.node([]);
53
+ const rootEditorSubscriptions = r.node([]);
54
+ const editorInFocus = r.node(null);
55
+ const onBlur = r.node();
56
+ const iconComponentFor = r.node((name) => {
57
+ throw new Error(`No icon component for ${name}`);
58
+ });
59
+ const rebind = () => r.o.scan((teardowns, [subs, activeEditorValue]) => {
60
+ teardowns.forEach((teardown) => {
61
+ if (!teardown) {
62
+ throw new Error("You have a subscription that does not return a teardown");
63
+ }
64
+ teardown();
65
+ });
66
+ return activeEditorValue ? subs.map((s) => s(activeEditorValue)) : [];
67
+ }, []);
68
+ r.pipe(r.combine(activeEditorSubscriptions, activeEditor), rebind());
69
+ r.pipe(r.combine(rootEditorSubscriptions, rootEditor), rebind());
70
+ const createRootEditorSubscription = createAppendNodeFor(rootEditorSubscriptions);
71
+ const createActiveEditorSubscription = createAppendNodeFor(activeEditorSubscriptions);
72
+ function handleSelectionChange() {
73
+ const selection = $getSelection();
74
+ if ($isRangeSelection(selection)) {
75
+ r.pubKeys({
76
+ currentSelection: selection,
77
+ currentFormat: selection.format
78
+ });
79
+ }
80
+ }
81
+ r.pub(createRootEditorSubscription, (theRootEditor) => {
82
+ return theRootEditor.registerCommand(
83
+ SELECTION_CHANGE_COMMAND,
84
+ (_, theActiveEditor) => {
85
+ r.pubIn({
86
+ [activeEditor.key]: theActiveEditor,
87
+ [inFocus.key]: true
88
+ });
89
+ if (theActiveEditor._parentEditor === null) {
90
+ theActiveEditor.getEditorState().read(() => {
91
+ r.pub(editorInFocus, {
92
+ rootNode: $getRoot(),
93
+ editorType: "lexical"
94
+ });
95
+ });
96
+ }
97
+ handleSelectionChange();
98
+ return false;
99
+ },
100
+ COMMAND_PRIORITY_CRITICAL
101
+ );
102
+ });
103
+ r.pub(createRootEditorSubscription, (theRootEditor) => {
104
+ return theRootEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, editorState }) => {
105
+ if (dirtyElements.size === 0 && dirtyLeaves.size === 0) {
106
+ return;
107
+ }
108
+ let theNewMarkdownValue;
109
+ editorState.read(() => {
110
+ theNewMarkdownValue = exportMarkdownFromLexical({
111
+ root: $getRoot(),
112
+ visitors: r.getValue(exportVisitors),
113
+ jsxComponentDescriptors: r.getValue(jsxComponentDescriptors),
114
+ toMarkdownExtensions: r.getValue(toMarkdownExtensions),
115
+ toMarkdownOptions: r.getValue(toMarkdownOptions),
116
+ jsxIsAvailable: r.getValue(jsxIsAvailable)
117
+ });
118
+ });
119
+ r.pub(markdown, theNewMarkdownValue.trim());
120
+ });
121
+ });
122
+ const initialMarkdown = r.node("");
123
+ const markdown = r.node("", true);
124
+ r.link(initialMarkdown, markdown);
125
+ const importVisitors = r.node([]);
126
+ const syntaxExtensions = r.node([]);
127
+ const mdastExtensions = r.node([]);
128
+ const usedLexicalNodes = r.node([]);
129
+ const exportVisitors = r.node([]);
130
+ const toMarkdownExtensions = r.node([]);
131
+ const toMarkdownOptions = r.node({}, true);
132
+ const jsxIsAvailable = r.node(false);
133
+ const jsxComponentDescriptors = r.node([]);
134
+ const editorRootElementRef = r.node(null);
135
+ const addLexicalNode = createAppendNodeFor(usedLexicalNodes);
136
+ const addImportVisitor = createAppendNodeFor(importVisitors);
137
+ const addSyntaxExtension = createAppendNodeFor(syntaxExtensions);
138
+ const addMdastExtension = createAppendNodeFor(mdastExtensions);
139
+ const addExportVisitor = createAppendNodeFor(exportVisitors);
140
+ const addToMarkdownExtension = createAppendNodeFor(toMarkdownExtensions);
141
+ const setMarkdown = r.node();
142
+ r.sub(
143
+ r.pipe(setMarkdown, r.o.withLatestFrom(rootEditor, importVisitors, mdastExtensions, syntaxExtensions, inFocus)),
144
+ ([theNewMarkdownValue, editor, importVisitors2, mdastExtensions2, syntaxExtensions2, inFocus2]) => {
145
+ editor == null ? void 0 : editor.update(() => {
146
+ $getRoot().clear();
147
+ importMarkdownToLexical({
148
+ root: $getRoot(),
149
+ visitors: importVisitors2,
150
+ mdastExtensions: mdastExtensions2,
151
+ markdown: theNewMarkdownValue,
152
+ syntaxExtensions: syntaxExtensions2
153
+ });
154
+ if (!inFocus2) {
155
+ $setSelection(null);
156
+ }
157
+ });
158
+ }
159
+ );
160
+ const initialRootEditorState = r.node((theRootEditor) => {
161
+ r.pub(rootEditor, theRootEditor);
162
+ r.pub(activeEditor, theRootEditor);
163
+ importMarkdownToLexical({
164
+ root: $getRoot(),
165
+ visitors: r.getValue(importVisitors),
166
+ mdastExtensions: r.getValue(mdastExtensions),
167
+ markdown: r.getValue(initialMarkdown),
168
+ syntaxExtensions: r.getValue(syntaxExtensions)
169
+ });
170
+ const autoFocusValue = r.getValue(autoFocus);
171
+ if (autoFocusValue) {
172
+ if (autoFocusValue === true) {
173
+ setTimeout(() => theRootEditor.focus(noop, { defaultSelection: "rootStart" }));
174
+ return;
175
+ }
176
+ setTimeout(
177
+ () => theRootEditor.focus(noop, {
178
+ defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
179
+ })
180
+ );
181
+ }
182
+ });
183
+ r.pub(createActiveEditorSubscription, (editor) => {
184
+ return editor.registerUpdateListener(({ editorState }) => {
185
+ editorState.read(() => {
186
+ handleSelectionChange();
187
+ });
188
+ });
189
+ });
190
+ r.pub(createActiveEditorSubscription, (theEditor) => {
191
+ return theEditor.registerCommand(
192
+ BLUR_COMMAND,
193
+ (payload) => {
194
+ var _a;
195
+ const theRootEditor = r.getValue(rootEditor);
196
+ if (theRootEditor) {
197
+ const movingOutside = !((_a = theRootEditor.getRootElement()) == null ? void 0 : _a.contains(payload.relatedTarget));
198
+ if (movingOutside) {
199
+ r.pubIn({
200
+ [inFocus.key]: false,
201
+ [onBlur.key]: payload
202
+ });
203
+ }
204
+ }
205
+ return false;
206
+ },
207
+ COMMAND_PRIORITY_CRITICAL
208
+ );
209
+ });
210
+ r.pub(createRootEditorSubscription, (theRootEditor) => {
211
+ return theRootEditor.registerCommand(
212
+ KEY_DOWN_COMMAND,
213
+ (event) => {
214
+ const { keyCode, ctrlKey, metaKey } = event;
215
+ if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey)) {
216
+ let shouldOverride = false;
217
+ theRootEditor.getEditorState().read(() => {
218
+ shouldOverride = $isDecoratorNode($getRoot().getFirstChild()) || $isDecoratorNode($getRoot().getLastChild());
219
+ });
220
+ if (shouldOverride) {
221
+ event.preventDefault();
222
+ event.stopImmediatePropagation();
223
+ theRootEditor.update(() => {
224
+ var _a;
225
+ const rootElement = theRootEditor.getRootElement();
226
+ (_a = window.getSelection()) == null ? void 0 : _a.selectAllChildren(rootElement);
227
+ rootElement.focus({
228
+ preventScroll: true
229
+ });
230
+ });
231
+ return true;
232
+ }
233
+ }
234
+ return false;
235
+ },
236
+ COMMAND_PRIORITY_CRITICAL
237
+ );
238
+ });
239
+ const composerChildren = r.node([]);
240
+ const addComposerChild = createAppendNodeFor(composerChildren);
241
+ const topAreaChildren = r.node([]);
242
+ const addTopAreaChild = createAppendNodeFor(topAreaChildren);
243
+ const editorWrappers = r.node([]);
244
+ const addEditorWrapper = createAppendNodeFor(editorWrappers);
245
+ const nestedEditorChildren = r.node([]);
246
+ const addNestedEditorChild = createAppendNodeFor(nestedEditorChildren);
247
+ const historyState = r.node(createEmptyHistoryState());
248
+ r.sub(r.pipe(applyFormat, r.o.withLatestFrom(activeEditor)), ([format, theEditor]) => {
249
+ theEditor == null ? void 0 : theEditor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
250
+ });
251
+ const currentBlockType = r.node("");
252
+ const applyBlockType = r.node();
253
+ r.sub(r.pipe(currentSelection, r.o.withLatestFrom(activeEditor)), ([selection, theEditor]) => {
254
+ if (!selection || !theEditor) {
255
+ return;
256
+ }
257
+ const anchorNode = selection.anchor.getNode();
258
+ let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
259
+ const parent = e.getParent();
260
+ return parent !== null && $isRootOrShadowRoot(parent);
261
+ });
262
+ if (element === null) {
263
+ element = anchorNode.getTopLevelElementOrThrow();
264
+ }
265
+ const elementKey = element.getKey();
266
+ const elementDOM = theEditor.getElementByKey(elementKey);
267
+ if (elementDOM !== null) {
268
+ const blockType = $isHeadingNode(element) ? element.getTag() : element.getType();
269
+ r.pub(currentBlockType, blockType);
270
+ }
271
+ });
272
+ const convertSelectionToNode = r.node();
273
+ r.sub(r.pipe(convertSelectionToNode, r.o.withLatestFrom(activeEditor)), ([factory, editor]) => {
274
+ editor == null ? void 0 : editor.update(() => {
275
+ const selection = $getSelection();
276
+ if ($isRangeSelection(selection)) {
277
+ $setBlocksType(selection, factory);
278
+ setTimeout(() => {
279
+ editor.focus();
280
+ });
281
+ }
282
+ });
283
+ });
284
+ const insertDecoratorNode = r.node();
285
+ r.sub(r.pipe(insertDecoratorNode, r.o.withLatestFrom(activeEditor)), ([nodeFactory, theEditor]) => {
286
+ theEditor == null ? void 0 : theEditor.focus(
287
+ () => {
288
+ theEditor.getEditorState().read(() => {
289
+ const selection = $getSelection();
290
+ if ($isRangeSelection(selection)) {
291
+ const focusNode = selection.focus.getNode();
292
+ if (focusNode !== null) {
293
+ theEditor.update(() => {
294
+ const node = nodeFactory();
295
+ if (node.isInline()) {
296
+ $insertNodes([node]);
297
+ if ($isRootOrShadowRoot(node.getParentOrThrow())) {
298
+ $wrapNodeInElement(node, $createParagraphNode).selectEnd();
299
+ }
300
+ } else {
301
+ $insertNodeToNearestRoot(node);
302
+ }
303
+ if ("select" in node && typeof node.select === "function") {
304
+ setTimeout(() => node.select());
305
+ }
306
+ });
307
+ }
308
+ }
309
+ });
310
+ },
311
+ { defaultSelection: "rootEnd" }
312
+ );
313
+ });
314
+ r.sub(r.pipe(readOnly, r.o.withLatestFrom(rootEditor)), ([readOnly2, theRootEditor]) => {
315
+ theRootEditor == null ? void 0 : theRootEditor.setEditable(!readOnly2);
316
+ });
317
+ return {
318
+ // state
319
+ activeEditor,
320
+ inFocus,
321
+ historyState,
322
+ currentSelection,
323
+ // jsx
324
+ jsxIsAvailable,
325
+ jsxComponentDescriptors,
326
+ // lexical editor
327
+ initialRootEditorState,
328
+ rootEditor,
329
+ createRootEditorSubscription,
330
+ createActiveEditorSubscription,
331
+ // import
332
+ importVisitors,
333
+ syntaxExtensions,
334
+ mdastExtensions,
335
+ usedLexicalNodes,
336
+ addImportVisitor,
337
+ addLexicalNode,
338
+ addSyntaxExtension,
339
+ addMdastExtension,
340
+ // export
341
+ toMarkdownExtensions,
342
+ toMarkdownOptions,
343
+ addToMarkdownExtension,
344
+ addExportVisitor,
345
+ exportVisitors,
346
+ // markdown strings
347
+ initialMarkdown,
348
+ setMarkdown,
349
+ markdown,
350
+ // DOM
351
+ editorRootElementRef,
352
+ contentEditableClassName,
353
+ placeholder,
354
+ autoFocus,
355
+ readOnly,
356
+ // child controls
357
+ composerChildren,
358
+ addComposerChild,
359
+ topAreaChildren,
360
+ addTopAreaChild,
361
+ nestedEditorChildren,
362
+ addNestedEditorChild,
363
+ editorWrappers,
364
+ addEditorWrapper,
365
+ // editor content state and commands
366
+ currentFormat,
367
+ editorInFocus,
368
+ applyFormat,
369
+ currentBlockType,
370
+ applyBlockType,
371
+ convertSelectionToNode,
372
+ insertDecoratorNode,
373
+ // Events
374
+ onBlur,
375
+ iconComponentFor
376
+ };
377
+ }, []);
378
+ const [
379
+ /** @internal */
380
+ corePlugin,
381
+ /** @internal */
382
+ corePluginHooks
383
+ ] = realmPlugin({
384
+ id: "core",
385
+ systemSpec: coreSystem,
386
+ applyParamsToSystem(realm, params) {
387
+ realm.pubKeys({
388
+ contentEditableClassName: params.contentEditableClassName,
389
+ toMarkdownOptions: params.toMarkdownOptions,
390
+ autoFocus: params.autoFocus,
391
+ placeholder: params.placeholder,
392
+ readOnly: params.readOnly
393
+ });
394
+ realm.singletonSubKey("markdown", params.onChange);
395
+ realm.singletonSubKey("onBlur", params.onBlur);
396
+ },
397
+ init(realm, params) {
398
+ realm.pubKey("initialMarkdown", params.initialMarkdown.trim());
399
+ realm.pubKey("iconComponentFor", params.iconComponentFor);
400
+ realm.pubKey("addImportVisitor", MdastRootVisitor);
401
+ realm.pubKey("addImportVisitor", MdastParagraphVisitor);
402
+ realm.pubKey("addImportVisitor", MdastTextVisitor);
403
+ realm.pubKey("addImportVisitor", MdastFormattingVisitor);
404
+ realm.pubKey("addImportVisitor", MdastInlineCodeVisitor);
405
+ realm.pubKey("addImportVisitor", MdastBreakVisitor);
406
+ realm.pubKey("addLexicalNode", ParagraphNode);
407
+ realm.pubKey("addLexicalNode", TextNode);
408
+ realm.pubKey("addExportVisitor", LexicalRootVisitor);
409
+ realm.pubKey("addExportVisitor", LexicalParagraphVisitor);
410
+ realm.pubKey("addExportVisitor", LexicalTextVisitor);
411
+ realm.pubKey("addExportVisitor", LexicalLinebreakVisitor);
412
+ realm.pubKey("addComposerChild", SharedHistoryPlugin);
413
+ }
414
+ });
415
+ export {
416
+ NESTED_EDITOR_UPDATED_COMMAND,
417
+ corePlugin,
418
+ corePluginHooks,
419
+ coreSystem
420
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { Control, UseFormSetValue, UseFormRegister } from 'react-hook-form';
3
+ interface DownshiftAutoCompleteProps {
4
+ suggestions: string[];
5
+ control: Control<any, any>;
6
+ setValue: UseFormSetValue<any>;
7
+ register: UseFormRegister<any>;
8
+ placeholder: string;
9
+ inputName: string;
10
+ autofocus?: boolean;
11
+ initialInputValue: string;
12
+ }
13
+ export declare const DownshiftAutoComplete: React.FC<DownshiftAutoCompleteProps>;
14
+ export declare const DownshiftAutoCompleteWithSuggestions: React.FC<DownshiftAutoCompleteProps>;
15
+ export {};
@@ -0,0 +1,83 @@
1
+ import { useCombobox } from "downshift";
2
+ import React__default from "react";
3
+ import { Controller } from "react-hook-form";
4
+ import styles from "../../../styles/ui.module.css.js";
5
+ import { corePluginHooks } from "../index.js";
6
+ const MAX_SUGGESTIONS = 20;
7
+ const DownshiftAutoComplete = (props) => {
8
+ if (props.suggestions.length > 0) {
9
+ return /* @__PURE__ */ React__default.createElement(DownshiftAutoCompleteWithSuggestions, { ...props });
10
+ } else {
11
+ return /* @__PURE__ */ React__default.createElement("input", { className: styles.textInput, size: 40, autoFocus: true, ...props.register(props.inputName) });
12
+ }
13
+ };
14
+ const DownshiftAutoCompleteWithSuggestions = ({
15
+ autofocus,
16
+ suggestions,
17
+ control,
18
+ inputName,
19
+ placeholder,
20
+ initialInputValue,
21
+ setValue
22
+ }) => {
23
+ const [items, setItems] = React__default.useState(suggestions.slice(0, MAX_SUGGESTIONS));
24
+ const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
25
+ const enableAutoComplete = suggestions.length > 0;
26
+ const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
27
+ initialInputValue,
28
+ onInputValueChange({ inputValue = "" }) {
29
+ setValue(inputName, inputValue);
30
+ inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
31
+ const matchingItems = [];
32
+ for (const suggestion of suggestions) {
33
+ if (suggestion.toLowerCase().includes(inputValue)) {
34
+ matchingItems.push(suggestion);
35
+ if (matchingItems.length >= MAX_SUGGESTIONS) {
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ setItems(matchingItems);
41
+ },
42
+ items,
43
+ itemToString(item) {
44
+ return item ?? "";
45
+ }
46
+ });
47
+ const dropdownIsVisible = isOpen && items.length > 0;
48
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.downshiftAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.downshiftInputWrapper }, /* @__PURE__ */ React__default.createElement(
49
+ Controller,
50
+ {
51
+ name: inputName,
52
+ control,
53
+ render: ({ field }) => {
54
+ const downshiftSrcProps = getInputProps();
55
+ return /* @__PURE__ */ React__default.createElement(
56
+ "input",
57
+ {
58
+ ...downshiftSrcProps,
59
+ name: field.name,
60
+ placeholder,
61
+ className: styles.downshiftInput,
62
+ size: 30,
63
+ "data-editor-dialog": true,
64
+ autoFocus: autofocus
65
+ }
66
+ );
67
+ }
68
+ }
69
+ ), enableAutoComplete && /* @__PURE__ */ React__default.createElement("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps() }, iconComponentFor("arrow_drop_down"))), /* @__PURE__ */ React__default.createElement("div", { className: styles.downshiftAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible }, items.map((item, index) => /* @__PURE__ */ React__default.createElement(
70
+ "li",
71
+ {
72
+ "data-selected": selectedItem === item,
73
+ "data-highlighted": highlightedIndex === index,
74
+ key: `${item}${index}`,
75
+ ...getItemProps({ item, index })
76
+ },
77
+ item
78
+ )))));
79
+ };
80
+ export {
81
+ DownshiftAutoComplete,
82
+ DownshiftAutoCompleteWithSuggestions
83
+ };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import * as RadixPopover from '@radix-ui/react-popover';
3
+ export declare const PopoverPortal: (props: RadixPopover.PopoverPortalProps) => React.JSX.Element;
4
+ export declare const PopoverContent: React.ForwardRefExoticComponent<Omit<RadixPopover.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<any>>;
@@ -0,0 +1,17 @@
1
+ import React__default from "react";
2
+ import * as RadixPopover from "@radix-ui/react-popover";
3
+ import { corePluginHooks } from "../index.js";
4
+ import styles from "../../../styles/ui.module.css.js";
5
+ const PopoverPortal = (props) => {
6
+ const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
7
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { ...props, container: editorRootElementRef == null ? void 0 : editorRootElementRef.current });
8
+ };
9
+ const PopoverContent = React__default.forwardRef(
10
+ (props, ref) => {
11
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Content, { ...props, className: styles.popoverContent, sideOffset: 5, side: "top", ref }, /* @__PURE__ */ React__default.createElement("span", { className: styles.popoverArrow }, /* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, null)), props.children);
12
+ }
13
+ );
14
+ export {
15
+ PopoverContent,
16
+ PopoverPortal
17
+ };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const DiffSourceWrapper: React.FC<{
3
+ children: React.ReactNode;
4
+ }>;
@@ -0,0 +1,11 @@
1
+ import React__default from "react";
2
+ import { diffSourcePluginHooks } from "./index.js";
3
+ import { DiffViewer } from "./DiffViewer.js";
4
+ import { SourceEditor } from "./SourceEditor.js";
5
+ const DiffSourceWrapper = ({ children }) => {
6
+ const [viewMode] = diffSourcePluginHooks.useEmitterValues("viewMode");
7
+ return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement("div", { style: { display: viewMode === "rich-text" ? "block" : "none" } }, children), viewMode === "diff" ? /* @__PURE__ */ React__default.createElement(DiffViewer, null) : null, viewMode === "source" ? /* @__PURE__ */ React__default.createElement(SourceEditor, null) : null);
8
+ };
9
+ export {
10
+ DiffSourceWrapper
11
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const DiffViewer: React.FC;
@@ -0,0 +1,59 @@
1
+ import React__default from "react";
2
+ import { diffSourcePluginHooks } from "./index.js";
3
+ import { corePluginHooks } from "../core/index.js";
4
+ import { MergeView } from "@codemirror/merge";
5
+ import { EditorState } from "@codemirror/state";
6
+ import { EditorView } from "@codemirror/view";
7
+ import { COMMON_STATE_CONFIG_EXTENSIONS } from "./SourceEditor.js";
8
+ const DiffViewer = () => {
9
+ const [newText] = corePluginHooks.useEmitterValues("markdown");
10
+ const [oldText] = diffSourcePluginHooks.useEmitterValues("diffMarkdown");
11
+ const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
12
+ return /* @__PURE__ */ React__default.createElement(CmMergeView, { oldMarkdown: oldText, newMarkdown: newText, onUpdate: updateMarkdown });
13
+ };
14
+ const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
15
+ const cmMergeViewRef = React__default.useRef(null);
16
+ const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
17
+ const ref = React__default.useCallback(
18
+ (el) => {
19
+ var _a;
20
+ if (el !== null) {
21
+ cmMergeViewRef.current = new MergeView({
22
+ renderRevertControl: () => {
23
+ const el2 = document.createElement("button");
24
+ el2.classList.add("cm-merge-revert");
25
+ el2.appendChild(document.createTextNode("⮕"));
26
+ return el2;
27
+ },
28
+ parent: el,
29
+ orientation: "a-b",
30
+ revertControls: "a-to-b",
31
+ gutter: true,
32
+ a: {
33
+ doc: oldMarkdown,
34
+ extensions: [...cmExtensions, ...COMMON_STATE_CONFIG_EXTENSIONS, EditorState.readOnly.of(true)]
35
+ },
36
+ b: {
37
+ doc: newMarkdown,
38
+ extensions: [
39
+ ...cmExtensions,
40
+ ...COMMON_STATE_CONFIG_EXTENSIONS,
41
+ EditorView.updateListener.of(({ state }) => {
42
+ const md = state.doc.toString();
43
+ onUpdate(md);
44
+ })
45
+ ]
46
+ }
47
+ });
48
+ } else {
49
+ (_a = cmMergeViewRef.current) == null ? void 0 : _a.destroy();
50
+ cmMergeViewRef.current = null;
51
+ }
52
+ },
53
+ [newMarkdown, oldMarkdown, onUpdate, cmExtensions]
54
+ );
55
+ return /* @__PURE__ */ React__default.createElement("div", { ref });
56
+ };
57
+ export {
58
+ DiffViewer
59
+ };
@@ -0,0 +1,4 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import React from 'react';
3
+ export declare const COMMON_STATE_CONFIG_EXTENSIONS: Extension[];
4
+ export declare const SourceEditor: () => React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { markdown } from "@codemirror/lang-markdown";
2
+ import { EditorState } from "@codemirror/state";
3
+ import { lineNumbers, EditorView } from "@codemirror/view";
4
+ import { basicLight } from "cm6-theme-basic-light";
5
+ import { basicSetup } from "codemirror";
6
+ import React__default from "react";
7
+ import { diffSourcePluginHooks } from "./index.js";
8
+ import { corePluginHooks } from "../core/index.js";
9
+ const COMMON_STATE_CONFIG_EXTENSIONS = [basicSetup, basicLight, markdown(), lineNumbers()];
10
+ const SourceEditor = () => {
11
+ const [markdown2, readOnly] = corePluginHooks.useEmitterValues("markdown", "readOnly");
12
+ const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
13
+ const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
14
+ const editorViewRef = React__default.useRef(null);
15
+ const ref = React__default.useCallback(
16
+ (el) => {
17
+ var _a;
18
+ if (el !== null) {
19
+ const extensions = [
20
+ // custom extensions should come first so that you can override the default extensions
21
+ ...cmExtensions,
22
+ ...COMMON_STATE_CONFIG_EXTENSIONS,
23
+ EditorView.updateListener.of(({ state }) => {
24
+ updateMarkdown(state.doc.toString());
25
+ })
26
+ ];
27
+ if (readOnly) {
28
+ extensions.push(EditorState.readOnly.of(true));
29
+ }
30
+ el.innerHTML = "";
31
+ editorViewRef.current = new EditorView({
32
+ parent: el,
33
+ state: EditorState.create({ doc: markdown2, extensions })
34
+ });
35
+ } else {
36
+ (_a = editorViewRef.current) == null ? void 0 : _a.destroy();
37
+ editorViewRef.current = null;
38
+ }
39
+ },
40
+ [markdown2, readOnly, updateMarkdown, cmExtensions]
41
+ );
42
+ return /* @__PURE__ */ React__default.createElement("div", { ref, className: "cm-sourceView" });
43
+ };
44
+ export {
45
+ COMMON_STATE_CONFIG_EXTENSIONS,
46
+ SourceEditor
47
+ };