@nkzw/mdx-editor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/UPSTREAM.md +21 -0
  4. package/dist/EditorIcon.js +75 -0
  5. package/dist/FormatConstants.js +20 -0
  6. package/dist/MDXEditor.js +189 -0
  7. package/dist/MarkdownEditor.js +281 -0
  8. package/dist/PersistentMarkdownEditor.js +358 -0
  9. package/dist/RealmWithPlugins.js +35 -0
  10. package/dist/core.d.ts +3232 -0
  11. package/dist/core.js +354 -0
  12. package/dist/defaultSvgIcons.js +371 -0
  13. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
  14. package/dist/directive-editors/GenericDirectiveEditor.js +37 -0
  15. package/dist/exportMarkdownFromLexical.js +262 -0
  16. package/dist/horizontalRuleShortcut.js +37 -0
  17. package/dist/importMarkdownToLexical.js +172 -0
  18. package/dist/index.d.ts +86 -0
  19. package/dist/index.js +8 -0
  20. package/dist/jsx-editors/GenericJsxEditor.js +84 -0
  21. package/dist/mdastUtilHtmlComment.js +125 -0
  22. package/dist/persistence.d.ts +128 -0
  23. package/dist/persistence.js +4 -0
  24. package/dist/plugins/codeblock/CodeBlockNode.js +183 -0
  25. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  26. package/dist/plugins/codeblock/MdastCodeVisitor.js +23 -0
  27. package/dist/plugins/codeblock/findCodeBlockDescriptor.js +8 -0
  28. package/dist/plugins/codeblock/index.js +46 -0
  29. package/dist/plugins/codemirror/CodeMirrorEditor.js +145 -0
  30. package/dist/plugins/codemirror/index.js +115 -0
  31. package/dist/plugins/codemirror/useCodeMirrorRef.js +101 -0
  32. package/dist/plugins/core/GenericHTMLNode.js +118 -0
  33. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.js +15 -0
  34. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  35. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  36. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  37. package/dist/plugins/core/LexicalTextVisitor.js +160 -0
  38. package/dist/plugins/core/MdastBreakVisitor.js +10 -0
  39. package/dist/plugins/core/MdastFormattingVisitor.js +81 -0
  40. package/dist/plugins/core/MdastHTMLNode.js +120 -0
  41. package/dist/plugins/core/MdastHTMLVisitor.js +17 -0
  42. package/dist/plugins/core/MdastParagraphVisitor.js +23 -0
  43. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  44. package/dist/plugins/core/MdastTextVisitor.js +16 -0
  45. package/dist/plugins/core/NestedLexicalEditor.js +221 -0
  46. package/dist/plugins/core/PropertyPopover.js +75 -0
  47. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  48. package/dist/plugins/core/index.js +692 -0
  49. package/dist/plugins/core/ui/DownshiftAutoComplete.js +89 -0
  50. package/dist/plugins/core/ui/PopoverUtils.js +22 -0
  51. package/dist/plugins/diff-source/DiffSourceWrapper.js +24 -0
  52. package/dist/plugins/diff-source/DiffViewer.js +84 -0
  53. package/dist/plugins/diff-source/SourceEditor.js +60 -0
  54. package/dist/plugins/diff-source/index.js +27 -0
  55. package/dist/plugins/directives/DirectiveNode.js +107 -0
  56. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  57. package/dist/plugins/directives/MdastDirectiveVisitor.js +30 -0
  58. package/dist/plugins/directives/index.js +45 -0
  59. package/dist/plugins/frontmatter/FrontmatterEditor.js +137 -0
  60. package/dist/plugins/frontmatter/FrontmatterNode.js +70 -0
  61. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  62. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  63. package/dist/plugins/frontmatter/index.js +113 -0
  64. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  65. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  66. package/dist/plugins/headings/index.js +63 -0
  67. package/dist/plugins/image/EditImageToolbar.js +58 -0
  68. package/dist/plugins/image/ImageDialog.js +132 -0
  69. package/dist/plugins/image/ImageEditor.js +279 -0
  70. package/dist/plugins/image/ImageNode.js +187 -0
  71. package/dist/plugins/image/ImagePlaceholder.js +9 -0
  72. package/dist/plugins/image/ImageResizer.js +223 -0
  73. package/dist/plugins/image/LexicalImageVisitor.js +42 -0
  74. package/dist/plugins/image/MdastImageVisitor.js +91 -0
  75. package/dist/plugins/image/index.js +364 -0
  76. package/dist/plugins/jsx/LexicalJsxNode.js +103 -0
  77. package/dist/plugins/jsx/LexicalJsxVisitor.js +27 -0
  78. package/dist/plugins/jsx/LexicalMdxExpressionNode.js +130 -0
  79. package/dist/plugins/jsx/LexicalMdxExpressionVisitor.js +14 -0
  80. package/dist/plugins/jsx/MdastMdxExpressionVisitor.js +11 -0
  81. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  82. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +28 -0
  83. package/dist/plugins/jsx/index.js +97 -0
  84. package/dist/plugins/jsx/jsxTagName.js +7 -0
  85. package/dist/plugins/link/AutoLinkPlugin.js +18 -0
  86. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  87. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  88. package/dist/plugins/link/index.js +34 -0
  89. package/dist/plugins/link-dialog/LinkDialog.js +262 -0
  90. package/dist/plugins/link-dialog/index.js +304 -0
  91. package/dist/plugins/lists/CheckListPlugin.js +270 -0
  92. package/dist/plugins/lists/LexicalListItemVisitor.js +41 -0
  93. package/dist/plugins/lists/LexicalListVisitor.js +13 -0
  94. package/dist/plugins/lists/MdastListItemVisitor.js +11 -0
  95. package/dist/plugins/lists/MdastListVisitor.js +19 -0
  96. package/dist/plugins/lists/NotesListItemNode.js +22 -0
  97. package/dist/plugins/lists/index.js +111 -0
  98. package/dist/plugins/markdown-shortcut/index.js +114 -0
  99. package/dist/plugins/maxlength/index.js +36 -0
  100. package/dist/plugins/quote/LexicalQuoteVisitor.js +10 -0
  101. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  102. package/dist/plugins/quote/index.js +18 -0
  103. package/dist/plugins/remote/index.js +52 -0
  104. package/dist/plugins/search/index.js +360 -0
  105. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  106. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  107. package/dist/plugins/table/TableEditor.js +527 -0
  108. package/dist/plugins/table/TableNode.js +208 -0
  109. package/dist/plugins/table/index.js +66 -0
  110. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  111. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  112. package/dist/plugins/thematic-break/index.js +27 -0
  113. package/dist/plugins/toolbar/components/BlockTypeSelect.js +62 -0
  114. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +98 -0
  115. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +43 -0
  116. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +42 -0
  117. package/dist/plugins/toolbar/components/CodeToggle.js +21 -0
  118. package/dist/plugins/toolbar/components/CreateLink.js +24 -0
  119. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +42 -0
  120. package/dist/plugins/toolbar/components/HighlightToggle.js +28 -0
  121. package/dist/plugins/toolbar/components/InsertAdmonition.js +34 -0
  122. package/dist/plugins/toolbar/components/InsertCodeBlock.js +23 -0
  123. package/dist/plugins/toolbar/components/InsertFrontmatter.js +28 -0
  124. package/dist/plugins/toolbar/components/InsertImage.js +29 -0
  125. package/dist/plugins/toolbar/components/InsertTable.js +25 -0
  126. package/dist/plugins/toolbar/components/InsertThematicBreak.js +23 -0
  127. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +82 -0
  128. package/dist/plugins/toolbar/components/ListsToggle.js +29 -0
  129. package/dist/plugins/toolbar/components/UndoRedo.js +60 -0
  130. package/dist/plugins/toolbar/index.js +32 -0
  131. package/dist/plugins/toolbar/primitives/DialogButton.js +130 -0
  132. package/dist/plugins/toolbar/primitives/TooltipWrap.js +17 -0
  133. package/dist/plugins/toolbar/primitives/select.js +76 -0
  134. package/dist/plugins/toolbar/primitives/toolbar.js +144 -0
  135. package/dist/registerCodeBoundaryEscape.js +40 -0
  136. package/dist/styles/lexical-theme.module.css.js +62 -0
  137. package/dist/styles/lexicalTheme.js +32 -0
  138. package/dist/styles/ui.module.css.js +296 -0
  139. package/dist/styles.css +2838 -0
  140. package/dist/utils/detectMac.js +16 -0
  141. package/dist/utils/fp.js +44 -0
  142. package/dist/utils/isPartOftheEditorUI.js +12 -0
  143. package/dist/utils/lexicalHelpers.js +185 -0
  144. package/dist/utils/makeHslTransparent.js +6 -0
  145. package/dist/utils/mergeStyleAttributes.js +22 -0
  146. package/dist/utils/uuid4.js +10 -0
  147. package/dist/utils/voidEmitter.js +15 -0
  148. package/package.json +133 -0
@@ -0,0 +1,120 @@
1
+ const MDX_NODE_TYPES = ["mdxJsxTextElement", "mdxJsxFlowElement"];
2
+ function isMdastHTMLNode(node) {
3
+ return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(node.name);
4
+ }
5
+ const htmlTags = [
6
+ "a",
7
+ "abbr",
8
+ "address",
9
+ "area",
10
+ "article",
11
+ "aside",
12
+ "audio",
13
+ "b",
14
+ "base",
15
+ "bdi",
16
+ "bdo",
17
+ "blockquote",
18
+ "body",
19
+ "br",
20
+ "button",
21
+ "canvas",
22
+ "caption",
23
+ "cite",
24
+ "code",
25
+ "col",
26
+ "colgroup",
27
+ "data",
28
+ "datalist",
29
+ "dd",
30
+ "del",
31
+ "details",
32
+ "dfn",
33
+ "dialog",
34
+ "div",
35
+ "dl",
36
+ "dt",
37
+ "em",
38
+ "embed",
39
+ "fieldset",
40
+ "figcaption",
41
+ "figure",
42
+ "footer",
43
+ "form",
44
+ "h1",
45
+ "h2",
46
+ "h3",
47
+ "h4",
48
+ "h5",
49
+ "h6",
50
+ "head",
51
+ "header",
52
+ "hgroup",
53
+ "hr",
54
+ "html",
55
+ "i",
56
+ "iframe",
57
+ // 'img',
58
+ "input",
59
+ "ins",
60
+ "kbd",
61
+ "label",
62
+ "legend",
63
+ "li",
64
+ "link",
65
+ "main",
66
+ "map",
67
+ "mark",
68
+ "meta",
69
+ "meter",
70
+ "nav",
71
+ "noscript",
72
+ "object",
73
+ "ol",
74
+ "optgroup",
75
+ "option",
76
+ "output",
77
+ "p",
78
+ "param",
79
+ "picture",
80
+ "pre",
81
+ "progress",
82
+ "q",
83
+ "rp",
84
+ "rt",
85
+ "ruby",
86
+ "s",
87
+ "samp",
88
+ "script",
89
+ "section",
90
+ "select",
91
+ "small",
92
+ "source",
93
+ "span",
94
+ "strong",
95
+ "style",
96
+ "sub",
97
+ "summary",
98
+ "sup",
99
+ "table",
100
+ "tbody",
101
+ "td",
102
+ "template",
103
+ "textarea",
104
+ "tfoot",
105
+ "th",
106
+ "thead",
107
+ "time",
108
+ "title",
109
+ "tr",
110
+ "track",
111
+ "u",
112
+ "ul",
113
+ "var",
114
+ "video",
115
+ "wbr"
116
+ ];
117
+ export {
118
+ htmlTags,
119
+ isMdastHTMLNode
120
+ };
@@ -0,0 +1,17 @@
1
+ import { $createGenericHTMLNode } from "./GenericHTMLNode.js";
2
+ import { isMdastHTMLNode } from "./MdastHTMLNode.js";
3
+ const MdastHTMLVisitor = {
4
+ testNode: isMdastHTMLNode,
5
+ visitNode: function({ mdastNode, actions, lexicalParent }) {
6
+ if (mdastNode.name === "span" && mdastNode.attributes.length === 1 && mdastNode.attributes[0].type === "mdxJsxAttribute" && mdastNode.attributes[0].name === "style") {
7
+ actions.addStyle(mdastNode.attributes[0].value, mdastNode);
8
+ actions.visitChildren(mdastNode, lexicalParent);
9
+ } else {
10
+ actions.addAndStepInto($createGenericHTMLNode(mdastNode.name, mdastNode.type, mdastNode.attributes));
11
+ }
12
+ },
13
+ priority: -100
14
+ };
15
+ export {
16
+ MdastHTMLVisitor
17
+ };
@@ -0,0 +1,23 @@
1
+ import { $isListItemNode } from "@lexical/list";
2
+ import { $createLineBreakNode, $createParagraphNode } from "lexical";
3
+ const lexicalTypesThatShouldSkipParagraphs = ["admonition"];
4
+ const MdastParagraphVisitor = {
5
+ testNode: "paragraph",
6
+ visitNode: function({ mdastNode, mdastParent, lexicalParent, actions }) {
7
+ const parentType = lexicalParent.getType();
8
+ const isListItem = $isListItemNode(lexicalParent);
9
+ if (isListItem || lexicalTypesThatShouldSkipParagraphs.includes(parentType)) {
10
+ const mdastNodeIndex = mdastParent?.children.indexOf(mdastNode) ?? -1;
11
+ const previousMdastSibling = mdastNodeIndex > 0 ? mdastParent?.children.at(mdastNodeIndex - 1) : void 0;
12
+ if (isListItem && previousMdastSibling?.type === "paragraph") {
13
+ lexicalParent.append($createLineBreakNode(), $createLineBreakNode());
14
+ }
15
+ actions.visitChildren(mdastNode, lexicalParent);
16
+ } else {
17
+ actions.addAndStepInto($createParagraphNode());
18
+ }
19
+ }
20
+ };
21
+ export {
22
+ MdastParagraphVisitor
23
+ };
@@ -0,0 +1,9 @@
1
+ const MdastRootVisitor = {
2
+ testNode: "root",
3
+ visitNode({ actions, mdastNode, lexicalParent }) {
4
+ actions.visitChildren(mdastNode, lexicalParent);
5
+ }
6
+ };
7
+ export {
8
+ MdastRootVisitor
9
+ };
@@ -0,0 +1,16 @@
1
+ import { $createTextNode } from "lexical";
2
+ const MdastTextVisitor = {
3
+ testNode: "text",
4
+ visitNode({ mdastNode, actions }) {
5
+ const node = $createTextNode(mdastNode.value);
6
+ node.setFormat(actions.getParentFormatting());
7
+ const style = actions.getParentStyle();
8
+ if (style !== "") {
9
+ node.setStyle(style);
10
+ }
11
+ actions.addAndStepInto(node);
12
+ }
13
+ };
14
+ export {
15
+ MdastTextVisitor
16
+ };
@@ -0,0 +1,221 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { createEditor, $getRoot, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL, $getNodeByKey, $addUpdateTag } from "lexical";
3
+ import React from "react";
4
+ import { rootEditor$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, jsxIsAvailable$, nestedEditorChildren$, lexicalTheme$, editorInFocus$, NESTED_EDITOR_UPDATED_COMMAND } from "./index.js";
5
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
6
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
7
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
8
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
9
+ import classNames from "classnames";
10
+ import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
11
+ import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
12
+ import styles from "../../styles/ui.module.css.js";
13
+ import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
14
+ import { mergeRegister } from "@lexical/utils";
15
+ import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
16
+ import { useRealm, useCellValues, usePublisher } from "@mdxeditor/gurx";
17
+ const NestedEditorsContext = React.createContext(void 0);
18
+ function useNestedEditorContext() {
19
+ const context = React.useContext(NestedEditorsContext);
20
+ if (!context) {
21
+ throw new Error("useNestedEditor must be used within a NestedEditorsProvider");
22
+ }
23
+ return context;
24
+ }
25
+ function useMdastNodeUpdater() {
26
+ const { parentEditor, mdastNode, lexicalNode } = useNestedEditorContext();
27
+ return function updateMdastNode(node) {
28
+ parentEditor.update(
29
+ () => {
30
+ $addUpdateTag("history-push");
31
+ const currentNode = $getNodeByKey(lexicalNode.getKey());
32
+ if (currentNode) {
33
+ currentNode.setMdastNode({ ...mdastNode, ...node });
34
+ }
35
+ },
36
+ { discrete: true }
37
+ );
38
+ parentEditor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
39
+ };
40
+ }
41
+ function useLexicalNodeRemove() {
42
+ const { parentEditor, lexicalNode } = useNestedEditorContext();
43
+ return () => {
44
+ parentEditor.update(() => {
45
+ const node = $getNodeByKey(lexicalNode.getKey());
46
+ node.selectNext();
47
+ node.remove();
48
+ });
49
+ };
50
+ }
51
+ const NestedLexicalEditor = function(props) {
52
+ const { getContent, getUpdatedMdastNode, contentEditableProps, block = false } = props;
53
+ const { mdastNode, lexicalNode, focusEmitter } = useNestedEditorContext();
54
+ const updateMdastNode = useMdastNodeUpdater();
55
+ const removeNode = useLexicalNodeRemove();
56
+ const content = getContent(mdastNode);
57
+ const realm = useRealm();
58
+ const [
59
+ rootEditor,
60
+ importVisitors,
61
+ exportVisitors,
62
+ usedLexicalNodes,
63
+ jsxComponentDescriptors,
64
+ directiveDescriptors,
65
+ codeBlockEditorDescriptors,
66
+ defaultCodeBlockLanguage,
67
+ jsxIsAvailable,
68
+ nestedEditorChildren,
69
+ lexicalTheme
70
+ ] = useCellValues(
71
+ rootEditor$,
72
+ importVisitors$,
73
+ exportVisitors$,
74
+ usedLexicalNodes$,
75
+ jsxComponentDescriptors$,
76
+ directiveDescriptors$,
77
+ codeBlockEditorDescriptors$,
78
+ defaultCodeBlockLanguage$,
79
+ jsxIsAvailable$,
80
+ nestedEditorChildren$,
81
+ lexicalTheme$
82
+ );
83
+ const setEditorInFocus = usePublisher(editorInFocus$);
84
+ const [editor] = React.useState(() => {
85
+ const editor2 = createEditor({
86
+ nodes: usedLexicalNodes,
87
+ theme: realm.getValue(lexicalTheme$),
88
+ namespace: "NestedEditor"
89
+ });
90
+ return editor2;
91
+ });
92
+ React.useEffect(() => {
93
+ focusEmitter.subscribe(() => {
94
+ editor.focus();
95
+ });
96
+ }, [editor, focusEmitter]);
97
+ React.useEffect(() => {
98
+ editor.update(() => {
99
+ $getRoot().clear();
100
+ let theContent = content;
101
+ if (block) {
102
+ if (theContent.length === 0) {
103
+ theContent = [{ type: "paragraph", children: [] }];
104
+ }
105
+ } else {
106
+ theContent = [{ type: "paragraph", children: content }];
107
+ }
108
+ importMdastTreeToLexical({
109
+ root: $getRoot(),
110
+ mdastRoot: {
111
+ type: "root",
112
+ children: theContent
113
+ },
114
+ visitors: importVisitors,
115
+ directiveDescriptors,
116
+ codeBlockEditorDescriptors,
117
+ defaultCodeBlockLanguage,
118
+ jsxComponentDescriptors
119
+ });
120
+ });
121
+ }, [editor, block, importVisitors]);
122
+ React.useEffect(() => {
123
+ function updateParentNode() {
124
+ editor.getEditorState().read(() => {
125
+ const mdast = exportLexicalTreeToMdast({
126
+ root: $getRoot(),
127
+ visitors: exportVisitors,
128
+ jsxComponentDescriptors,
129
+ jsxIsAvailable,
130
+ addImportStatements: false
131
+ });
132
+ const content2 = block ? mdast.children : mdast.children[0].children;
133
+ updateMdastNode(getUpdatedMdastNode(structuredClone(mdastNode), content2));
134
+ });
135
+ }
136
+ return mergeRegister(
137
+ editor.registerCommand(
138
+ FOCUS_COMMAND,
139
+ () => {
140
+ setEditorInFocus({ editorType: "lexical", rootNode: lexicalNode, editorRef: editor });
141
+ return false;
142
+ },
143
+ COMMAND_PRIORITY_LOW
144
+ ),
145
+ editor.registerCommand(
146
+ BLUR_COMMAND,
147
+ (payload) => {
148
+ const relatedTarget = payload.relatedTarget;
149
+ if (isPartOftheEditorUI(relatedTarget, rootEditor.getRootElement())) {
150
+ return false;
151
+ }
152
+ updateParentNode();
153
+ setEditorInFocus(null);
154
+ return true;
155
+ },
156
+ COMMAND_PRIORITY_EDITOR
157
+ ),
158
+ // triggered by codemirror
159
+ editor.registerCommand(
160
+ NESTED_EDITOR_UPDATED_COMMAND,
161
+ () => {
162
+ updateParentNode();
163
+ return true;
164
+ },
165
+ COMMAND_PRIORITY_EDITOR
166
+ ),
167
+ editor.registerCommand(
168
+ SELECTION_CHANGE_COMMAND,
169
+ () => {
170
+ setEditorInFocus({ editorType: "lexical", rootNode: lexicalNode, editorRef: editor });
171
+ return false;
172
+ },
173
+ COMMAND_PRIORITY_HIGH
174
+ ),
175
+ editor.registerCommand(
176
+ KEY_BACKSPACE_COMMAND,
177
+ (_, editor2) => {
178
+ const editorElement = editor2.getRootElement();
179
+ if (editorElement?.innerText === "\n") {
180
+ removeNode();
181
+ return true;
182
+ }
183
+ return false;
184
+ },
185
+ COMMAND_PRIORITY_CRITICAL
186
+ )
187
+ );
188
+ }, [
189
+ block,
190
+ editor,
191
+ exportVisitors,
192
+ getUpdatedMdastNode,
193
+ jsxComponentDescriptors,
194
+ jsxIsAvailable,
195
+ lexicalNode,
196
+ mdastNode,
197
+ removeNode,
198
+ setEditorInFocus,
199
+ updateMdastNode,
200
+ rootEditor
201
+ ]);
202
+ return /* @__PURE__ */ jsxs(LexicalNestedComposer, { initialEditor: editor, initialTheme: lexicalTheme, children: [
203
+ /* @__PURE__ */ jsx(
204
+ RichTextPlugin,
205
+ {
206
+ contentEditable: /* @__PURE__ */ jsx(ContentEditable, { ...contentEditableProps, className: classNames(styles.nestedEditor, contentEditableProps?.className) }),
207
+ placeholder: null,
208
+ ErrorBoundary: LexicalErrorBoundary
209
+ }
210
+ ),
211
+ /* @__PURE__ */ jsx(SharedHistoryPlugin, {}),
212
+ nestedEditorChildren.map((Child, index) => /* @__PURE__ */ jsx(Child, {}, index))
213
+ ] });
214
+ };
215
+ export {
216
+ NestedEditorsContext,
217
+ NestedLexicalEditor,
218
+ useLexicalNodeRemove,
219
+ useMdastNodeUpdater,
220
+ useNestedEditorContext
221
+ };
@@ -0,0 +1,75 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import * as RadixPopover from "@radix-ui/react-popover";
3
+ import React from "react";
4
+ import { useForm } from "react-hook-form";
5
+ import styles from "../../styles/ui.module.css.js";
6
+ import { useCellValue } from "@mdxeditor/gurx";
7
+ import { iconComponentFor$ } from "./index.js";
8
+ import { PopoverPortal, PopoverContent } from "./ui/PopoverUtils.js";
9
+ const PropertyPopover = ({ title, properties, onChange }) => {
10
+ const [open, setOpen] = React.useState(false);
11
+ const iconComponentFor = useCellValue(iconComponentFor$);
12
+ const { register, handleSubmit, reset } = useForm({ defaultValues: properties });
13
+ return /* @__PURE__ */ jsxs(
14
+ RadixPopover.Root,
15
+ {
16
+ open,
17
+ onOpenChange: (v) => {
18
+ setOpen(v);
19
+ },
20
+ children: [
21
+ /* @__PURE__ */ jsx(RadixPopover.Trigger, { className: styles.iconButton, children: /* @__PURE__ */ jsx("div", { children: iconComponentFor("settings") }) }),
22
+ /* @__PURE__ */ jsx(PopoverPortal, { children: /* @__PURE__ */ jsx(PopoverContent, { children: /* @__PURE__ */ jsxs(
23
+ "form",
24
+ {
25
+ onSubmit: (e) => {
26
+ void handleSubmit(onChange)(e);
27
+ setOpen(false);
28
+ e.preventDefault();
29
+ e.stopPropagation();
30
+ },
31
+ children: [
32
+ /* @__PURE__ */ jsxs("h3", { className: styles.propertyPanelTitle, children: [
33
+ title,
34
+ " Attributes"
35
+ ] }),
36
+ /* @__PURE__ */ jsxs("table", { className: styles.propertyEditorTable, children: [
37
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
38
+ /* @__PURE__ */ jsx("th", { className: styles.readOnlyColumnCell, children: "Attribute" }),
39
+ /* @__PURE__ */ jsx("th", { children: "Value" })
40
+ ] }) }),
41
+ /* @__PURE__ */ jsx("tbody", { children: Object.keys(properties).map((propName) => /* @__PURE__ */ jsxs("tr", { children: [
42
+ /* @__PURE__ */ jsxs("th", { className: styles.readOnlyColumnCell, children: [
43
+ " ",
44
+ propName,
45
+ " "
46
+ ] }),
47
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx("input", { ...register(propName), className: styles.propertyEditorInput }) })
48
+ ] }, propName)) }),
49
+ /* @__PURE__ */ jsx("tfoot", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: 2, children: /* @__PURE__ */ jsxs("div", { className: styles.buttonsFooter, children: [
50
+ /* @__PURE__ */ jsx("button", { type: "submit", className: styles.primaryButton, children: "Save" }),
51
+ /* @__PURE__ */ jsx(
52
+ "button",
53
+ {
54
+ type: "reset",
55
+ className: styles.secondaryButton,
56
+ onClick: (e) => {
57
+ e.preventDefault();
58
+ reset(properties);
59
+ setOpen(false);
60
+ },
61
+ children: "Cancel"
62
+ }
63
+ )
64
+ ] }) }) }) })
65
+ ] })
66
+ ]
67
+ }
68
+ ) }) })
69
+ ]
70
+ }
71
+ );
72
+ };
73
+ export {
74
+ PropertyPopover
75
+ };
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
3
+ import { historyState$ } from "./index.js";
4
+ import { useCellValue } from "@mdxeditor/gurx";
5
+ const SharedHistoryPlugin = () => {
6
+ return /* @__PURE__ */ jsx(HistoryPlugin, { externalHistoryState: useCellValue(historyState$) });
7
+ };
8
+ export {
9
+ SharedHistoryPlugin
10
+ };