@mdxeditor/editor 3.15.0 → 3.16.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.
@@ -86,7 +86,7 @@ function exportLexicalTreeToMdast({
86
86
  const importsMap = /* @__PURE__ */ new Map();
87
87
  const defaultImportsMap = /* @__PURE__ */ new Map();
88
88
  for (const componentName of referredComponents) {
89
- const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === componentName);
89
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === componentName) ?? jsxComponentDescriptors.find((descriptor2) => descriptor2.name === "*");
90
90
  if (!descriptor) {
91
91
  throw new Error(`Component ${componentName} is used but not imported`);
92
92
  }
package/dist/index.d.ts CHANGED
@@ -54,6 +54,12 @@ export declare function $createCodeBlockNode(options: Partial<CreateCodeBlockNod
54
54
  */
55
55
  export declare function $createDirectiveNode(mdastNode: Directives, key?: NodeKey): DirectiveNode;
56
56
 
57
+ /**
58
+ * Creates a {@link FrontmatterNode}.
59
+ * @param yaml - The YAML string of the frontmatter.
60
+ */
61
+ export declare function $createFrontmatterNode(yaml: string): FrontmatterNode;
62
+
57
63
  /**
58
64
  * Creates a new {@link GenericHTMLNode} with the specified MDAST HTML node as the object to edit.
59
65
  * @group HTML
@@ -86,6 +92,11 @@ export declare function $isCodeBlockNode(node: LexicalNode | null | undefined):
86
92
  */
87
93
  export declare function $isDirectiveNode(node: LexicalNode | null | undefined): node is DirectiveNode;
88
94
 
95
+ /**
96
+ * Returns `true` if the given node is a {@link FrontmatterNode}.
97
+ */
98
+ export declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node is FrontmatterNode;
99
+
89
100
  /**
90
101
  * Determines if the specified node is a {@link GenericHTMLNode}.
91
102
  * @group HTML
@@ -1114,6 +1125,24 @@ export declare function fromWithinEditorRead<T>(editor: LexicalEditor, fn: () =>
1114
1125
  */
1115
1126
  export declare const frontmatterDialogOpen$: NodeRef<boolean>;
1116
1127
 
1128
+ /**
1129
+ * Represents {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | the frontmatter} of the markdown document.
1130
+ * Use {@link "$createFrontmatterNode"} to construct one.
1131
+ */
1132
+ export declare class FrontmatterNode extends DecoratorNode<JSX.Element> {
1133
+ __yaml: string;
1134
+ static getType(): string;
1135
+ static clone(node: FrontmatterNode): FrontmatterNode;
1136
+ static importJSON(serializedNode: SerializedFrontmatterNode): FrontmatterNode;
1137
+ constructor(code: string, key?: NodeKey);
1138
+ exportJSON(): SerializedFrontmatterNode;
1139
+ createDOM(_config: EditorConfig): HTMLDivElement;
1140
+ updateDOM(): false;
1141
+ getYaml(): string;
1142
+ setYaml(yaml: string): void;
1143
+ decorate(editor: LexicalEditor): JSX.Element;
1144
+ }
1145
+
1117
1146
  /**
1118
1147
  * A plugin that adds support for frontmatter.
1119
1148
  * @group Frontmatter
@@ -1561,8 +1590,9 @@ export declare function joinProc(...procs: (() => unknown)[]): () => void;
1561
1590
  */
1562
1591
  export declare interface JsxComponentDescriptor {
1563
1592
  /**
1564
- * The tag name. For example: 'div', 'span', 'MyComponent'.
1593
+ * The tag name. For example: 'div', 'span', 'MyComponent'. Use '*' for any tag.
1565
1594
  * Note: For fragments, use null.
1595
+ *
1566
1596
  */
1567
1597
  name: string | null;
1568
1598
  /**
@@ -2489,6 +2519,14 @@ export declare type SerializedDirectiveNode = Spread<{
2489
2519
  version: 1;
2490
2520
  }, SerializedLexicalNode>;
2491
2521
 
2522
+ /**
2523
+ * A serialized representation of an {@link FrontmatterNode}.
2524
+ */
2525
+ export declare type SerializedFrontmatterNode = Spread<{
2526
+ yaml: string;
2527
+ version: 1;
2528
+ }, SerializedLexicalNode>;
2529
+
2492
2530
  /**
2493
2531
  * A serialized representation of a {@link GenericHTMLNode}.
2494
2532
  * @group HTML
package/dist/index.js CHANGED
@@ -64,16 +64,19 @@ import { htmlTags, isMdastHTMLNode } from "./plugins/core/MdastHTMLNode.js";
64
64
  import { $createGenericHTMLNode, $isGenericHTMLNode, GenericHTMLNode, TYPE_NAME } from "./plugins/core/GenericHTMLNode.js";
65
65
  import { $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
66
66
  import { $createImageNode, $isImageNode, ImageNode } from "./plugins/image/ImageNode.js";
67
+ import { $createFrontmatterNode, $isFrontmatterNode, FrontmatterNode } from "./plugins/frontmatter/FrontmatterNode.js";
67
68
  import { $createCodeBlockNode, $isCodeBlockNode, CodeBlockNode, useCodeBlockEditorContext } from "./plugins/codeblock/CodeBlockNode.js";
68
69
  import { $createDirectiveNode, $isDirectiveNode, DirectiveNode } from "./plugins/directives/DirectiveNode.js";
69
70
  export {
70
71
  $createCodeBlockNode,
71
72
  $createDirectiveNode,
73
+ $createFrontmatterNode,
72
74
  $createGenericHTMLNode,
73
75
  $createImageNode,
74
76
  $createTableNode,
75
77
  $isCodeBlockNode,
76
78
  $isDirectiveNode,
79
+ $isFrontmatterNode,
77
80
  $isGenericHTMLNode,
78
81
  $isImageNode,
79
82
  $isTableNode,
@@ -99,6 +102,7 @@ export {
99
102
  DialogButton,
100
103
  DiffSourceToggleWrapper,
101
104
  DirectiveNode,
105
+ FrontmatterNode,
102
106
  GenericDirectiveEditor,
103
107
  GenericHTMLNode,
104
108
  GenericJsxEditor,
@@ -57,6 +57,9 @@ const frontmatterPlugin = realmPlugin({
57
57
  }
58
58
  });
59
59
  export {
60
+ $createFrontmatterNode,
61
+ $isFrontmatterNode,
62
+ FrontmatterNode,
60
63
  frontmatterDialogOpen$,
61
64
  frontmatterPlugin,
62
65
  hasFrontmatter$,
@@ -70,7 +70,7 @@ class LexicalJsxNode extends DecoratorNode {
70
70
  function JsxEditorContainer(props) {
71
71
  const { mdastNode } = props;
72
72
  const jsxComponentDescriptors = useCellValue(jsxComponentDescriptors$);
73
- const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name);
73
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name) ?? jsxComponentDescriptors.find((descriptor2) => descriptor2.name === "*");
74
74
  if (!descriptor) {
75
75
  throw new Error(`No JSX descriptor found for ${mdastNode.name}`);
76
76
  }
@@ -2,7 +2,7 @@ import { $createLexicalJsxNode } from "./LexicalJsxNode.js";
2
2
  const MdastMdxJsxElementVisitor = {
3
3
  testNode: (node, { jsxComponentDescriptors }) => {
4
4
  if (node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement") {
5
- const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === node.name);
5
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === node.name) ?? jsxComponentDescriptors.find((descriptor2) => descriptor2.name === "*");
6
6
  return descriptor !== void 0;
7
7
  }
8
8
  return false;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.15.0",
14
+ "version": "3.16.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",