@mdxeditor/editor 1.11.2 → 1.11.3
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.
|
@@ -91,11 +91,12 @@ export interface ExportLexicalTreeOptions {
|
|
|
91
91
|
visitors: LexicalVisitor[];
|
|
92
92
|
jsxComponentDescriptors: JsxComponentDescriptor[];
|
|
93
93
|
jsxIsAvailable: boolean;
|
|
94
|
+
addImportStatements?: boolean;
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* @internal
|
|
97
98
|
*/
|
|
98
|
-
export declare function exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors, jsxIsAvailable }: ExportLexicalTreeOptions): Mdast.Root;
|
|
99
|
+
export declare function exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors, jsxIsAvailable, addImportStatements }: ExportLexicalTreeOptions): Mdast.Root;
|
|
99
100
|
/**
|
|
100
101
|
* @internal
|
|
101
102
|
*/
|
|
@@ -9,7 +9,8 @@ function exportLexicalTreeToMdast({
|
|
|
9
9
|
root,
|
|
10
10
|
visitors,
|
|
11
11
|
jsxComponentDescriptors,
|
|
12
|
-
jsxIsAvailable
|
|
12
|
+
jsxIsAvailable,
|
|
13
|
+
addImportStatements = true
|
|
13
14
|
}) {
|
|
14
15
|
let unistRoot = null;
|
|
15
16
|
const referredComponents = /* @__PURE__ */ new Set();
|
|
@@ -120,10 +121,12 @@ function exportLexicalTreeToMdast({
|
|
|
120
121
|
);
|
|
121
122
|
const typedRoot = unistRoot;
|
|
122
123
|
const frontmatter = typedRoot.children.find((child) => child.type === "yaml");
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if (addImportStatements) {
|
|
125
|
+
if (frontmatter) {
|
|
126
|
+
typedRoot.children.splice(typedRoot.children.indexOf(frontmatter) + 1, 0, ...imports);
|
|
127
|
+
} else {
|
|
128
|
+
typedRoot.children.unshift(...imports);
|
|
129
|
+
}
|
|
127
130
|
}
|
|
128
131
|
fixWrappingWhitespace(typedRoot, []);
|
|
129
132
|
collapseNestedHtmlTags(typedRoot);
|
|
@@ -133,7 +136,7 @@ function exportLexicalTreeToMdast({
|
|
|
133
136
|
return typedRoot;
|
|
134
137
|
}
|
|
135
138
|
function collapseNestedHtmlTags(node) {
|
|
136
|
-
if ("children" in node) {
|
|
139
|
+
if ("children" in node && node.children) {
|
|
137
140
|
if (isMdastHTMLNode(node) && node.children.length === 1) {
|
|
138
141
|
const onlyChild = node.children[0];
|
|
139
142
|
if (onlyChild.type === "mdxJsxTextElement" && onlyChild.name === "span") {
|
|
@@ -212,7 +215,7 @@ function fixWrappingWhitespace(node, parentChain) {
|
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
|
-
if (
|
|
218
|
+
if ("children" in node && node.children) {
|
|
216
219
|
const nodeAsParent = node;
|
|
217
220
|
nodeAsParent.children.forEach((child) => fixWrappingWhitespace(child, [...parentChain, nodeAsParent]));
|
|
218
221
|
}
|
|
@@ -3,12 +3,13 @@ import { IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE } from "../../FormatConstants
|
|
|
3
3
|
function isMdastText(mdastNode) {
|
|
4
4
|
return mdastNode.type === "text";
|
|
5
5
|
}
|
|
6
|
+
const JOINABLE_TAGS = ["u", "span"];
|
|
6
7
|
const LexicalTextVisitor = {
|
|
7
8
|
shouldJoin: (prevNode, currentNode) => {
|
|
8
9
|
if (["text", "emphasis", "strong"].includes(prevNode.type)) {
|
|
9
10
|
return prevNode.type === currentNode.type;
|
|
10
11
|
}
|
|
11
|
-
if (prevNode.type === "mdxJsxTextElement" && currentNode.type === "mdxJsxTextElement") {
|
|
12
|
+
if (prevNode.type === "mdxJsxTextElement" && currentNode.type === "mdxJsxTextElement" && JOINABLE_TAGS.includes(currentNode.name)) {
|
|
12
13
|
const currentMdxNode = currentNode;
|
|
13
14
|
return prevNode.name === currentMdxNode.name && JSON.stringify(prevNode.attributes) === JSON.stringify(currentMdxNode.attributes);
|
|
14
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $addUpdateTag, $getNodeByKey, createEditor, $getRoot, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL } from "lexical";
|
|
2
2
|
import React__default from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { NESTED_EDITOR_UPDATED_COMMAND, corePluginHooks } from "./index.js";
|
|
4
4
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
|
|
5
5
|
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
|
|
6
6
|
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer.js";
|
|
@@ -23,13 +23,17 @@ function useNestedEditorContext() {
|
|
|
23
23
|
function useMdastNodeUpdater() {
|
|
24
24
|
const { parentEditor, mdastNode, lexicalNode } = useNestedEditorContext();
|
|
25
25
|
return function updateMdastNode(node) {
|
|
26
|
-
parentEditor.update(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
currentNode
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
parentEditor.update(
|
|
27
|
+
() => {
|
|
28
|
+
$addUpdateTag("history-push");
|
|
29
|
+
const currentNode = $getNodeByKey(lexicalNode.getKey());
|
|
30
|
+
if (currentNode) {
|
|
31
|
+
currentNode.setMdastNode({ ...mdastNode, ...node });
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{ discrete: true }
|
|
35
|
+
);
|
|
36
|
+
parentEditor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
|
|
33
37
|
};
|
|
34
38
|
}
|
|
35
39
|
function useLexicalNodeRemove() {
|
|
@@ -98,7 +102,8 @@ const NestedLexicalEditor = function(props) {
|
|
|
98
102
|
root: $getRoot(),
|
|
99
103
|
visitors: exportVisitors,
|
|
100
104
|
jsxComponentDescriptors,
|
|
101
|
-
jsxIsAvailable
|
|
105
|
+
jsxIsAvailable,
|
|
106
|
+
addImportStatements: false
|
|
102
107
|
});
|
|
103
108
|
const content2 = block ? mdast.children : mdast.children[0].children;
|
|
104
109
|
updateMdastNode(getUpdatedMdastNode(structuredClone(mdastNode), content2));
|