@mdxeditor/editor 3.19.0 → 3.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1946,9 +1946,9 @@ export declare interface MdastImportVisitor<UN extends Mdast.Nodes> {
|
|
|
1946
1946
|
/**
|
|
1947
1947
|
* The test function that determines if this visitor should be used for the given node.
|
|
1948
1948
|
* As a convenience, you can also pass a string here, which will be compared to the node's type.
|
|
1949
|
-
* @param
|
|
1949
|
+
* @param descriptors - the registered descriptors for composite nodes (jsx, directives, code blocks).
|
|
1950
1950
|
*/
|
|
1951
|
-
testNode: ((mdastNode: Mdast.Nodes,
|
|
1951
|
+
testNode: ((mdastNode: Mdast.Nodes, descriptors: Descriptors) => boolean) | string;
|
|
1952
1952
|
visitNode(params: {
|
|
1953
1953
|
/**
|
|
1954
1954
|
* The node that is currently being visited.
|
|
@@ -1962,6 +1962,10 @@ export declare interface MdastImportVisitor<UN extends Mdast.Nodes> {
|
|
|
1962
1962
|
* The parent lexical node to which the results of the processing should be added.
|
|
1963
1963
|
*/
|
|
1964
1964
|
lexicalParent: LexicalNode;
|
|
1965
|
+
/**
|
|
1966
|
+
* The descriptors for composite nodes (jsx, directives, code blocks).
|
|
1967
|
+
*/
|
|
1968
|
+
descriptors: Descriptors;
|
|
1965
1969
|
/**
|
|
1966
1970
|
* A set of convenience utilities that can be used to add nodes to the lexical tree.
|
|
1967
1971
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { $createParagraphNode } from "lexical";
|
|
1
2
|
import { $createLexicalJsxNode } from "./LexicalJsxNode.js";
|
|
2
3
|
const MdastMdxJsxElementVisitor = {
|
|
3
4
|
testNode: (node, { jsxComponentDescriptors }) => {
|
|
@@ -7,8 +8,16 @@ const MdastMdxJsxElementVisitor = {
|
|
|
7
8
|
}
|
|
8
9
|
return false;
|
|
9
10
|
},
|
|
10
|
-
visitNode({ lexicalParent, mdastNode }) {
|
|
11
|
-
|
|
11
|
+
visitNode({ lexicalParent, mdastNode, descriptors: { jsxComponentDescriptors } }) {
|
|
12
|
+
const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name) ?? jsxComponentDescriptors.find((descriptor2) => descriptor2.name === "*");
|
|
13
|
+
if ((descriptor == null ? void 0 : descriptor.kind) === "text" && mdastNode.type === "mdxJsxFlowElement") {
|
|
14
|
+
const patchedNode = { ...mdastNode, type: "mdxJsxTextElement" };
|
|
15
|
+
const paragraph = $createParagraphNode();
|
|
16
|
+
paragraph.append($createLexicalJsxNode(patchedNode));
|
|
17
|
+
lexicalParent.append(paragraph);
|
|
18
|
+
} else {
|
|
19
|
+
lexicalParent.append($createLexicalJsxNode(mdastNode));
|
|
20
|
+
}
|
|
12
21
|
},
|
|
13
22
|
priority: -200
|
|
14
23
|
};
|