@mdxeditor/editor 3.15.0 → 3.17.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.
package/dist/MDXEditor.js CHANGED
@@ -128,7 +128,8 @@ const MDXEditor = React__default.forwardRef((props, ref) => {
128
128
  suppressHtmlProcessing: props.suppressHtmlProcessing ?? false,
129
129
  onError: props.onError ?? noop,
130
130
  translation: props.translation ?? defaultTranslation,
131
- trim: props.trim ?? true
131
+ trim: props.trim ?? true,
132
+ lexicalTheme: props.lexicalTheme
132
133
  }),
133
134
  ...props.plugins ?? []
134
135
  ]
@@ -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
@@ -6,6 +6,7 @@ import { Directives } from 'mdast-util-directive';
6
6
  import { DOMConversionMap } from 'lexical';
7
7
  import { DOMExportOutput } from 'lexical';
8
8
  import { EditorConfig } from 'lexical';
9
+ import { EditorThemeClasses } from 'lexical';
9
10
  import { ElementNode } from 'lexical';
10
11
  import { Extension } from 'micromark-util-types';
11
12
  import { Extension as Extension_2 } from '@codemirror/state';
@@ -54,6 +55,12 @@ export declare function $createCodeBlockNode(options: Partial<CreateCodeBlockNod
54
55
  */
55
56
  export declare function $createDirectiveNode(mdastNode: Directives, key?: NodeKey): DirectiveNode;
56
57
 
58
+ /**
59
+ * Creates a {@link FrontmatterNode}.
60
+ * @param yaml - The YAML string of the frontmatter.
61
+ */
62
+ export declare function $createFrontmatterNode(yaml: string): FrontmatterNode;
63
+
57
64
  /**
58
65
  * Creates a new {@link GenericHTMLNode} with the specified MDAST HTML node as the object to edit.
59
66
  * @group HTML
@@ -86,6 +93,11 @@ export declare function $isCodeBlockNode(node: LexicalNode | null | undefined):
86
93
  */
87
94
  export declare function $isDirectiveNode(node: LexicalNode | null | undefined): node is DirectiveNode;
88
95
 
96
+ /**
97
+ * Returns `true` if the given node is a {@link FrontmatterNode}.
98
+ */
99
+ export declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node is FrontmatterNode;
100
+
89
101
  /**
90
102
  * Determines if the specified node is a {@link GenericHTMLNode}.
91
103
  * @group HTML
@@ -1114,6 +1126,24 @@ export declare function fromWithinEditorRead<T>(editor: LexicalEditor, fn: () =>
1114
1126
  */
1115
1127
  export declare const frontmatterDialogOpen$: NodeRef<boolean>;
1116
1128
 
1129
+ /**
1130
+ * Represents {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | the frontmatter} of the markdown document.
1131
+ * Use {@link "$createFrontmatterNode"} to construct one.
1132
+ */
1133
+ export declare class FrontmatterNode extends DecoratorNode<JSX.Element> {
1134
+ __yaml: string;
1135
+ static getType(): string;
1136
+ static clone(node: FrontmatterNode): FrontmatterNode;
1137
+ static importJSON(serializedNode: SerializedFrontmatterNode): FrontmatterNode;
1138
+ constructor(code: string, key?: NodeKey);
1139
+ exportJSON(): SerializedFrontmatterNode;
1140
+ createDOM(_config: EditorConfig): HTMLDivElement;
1141
+ updateDOM(): false;
1142
+ getYaml(): string;
1143
+ setYaml(yaml: string): void;
1144
+ decorate(editor: LexicalEditor): JSX.Element;
1145
+ }
1146
+
1117
1147
  /**
1118
1148
  * A plugin that adds support for frontmatter.
1119
1149
  * @group Frontmatter
@@ -1561,8 +1591,9 @@ export declare function joinProc(...procs: (() => unknown)[]): () => void;
1561
1591
  */
1562
1592
  export declare interface JsxComponentDescriptor {
1563
1593
  /**
1564
- * The tag name. For example: 'div', 'span', 'MyComponent'.
1594
+ * The tag name. For example: 'div', 'span', 'MyComponent'. Use '*' for any tag.
1565
1595
  * Note: For fragments, use null.
1596
+ *
1566
1597
  */
1567
1598
  name: string | null;
1568
1599
  /**
@@ -1757,6 +1788,10 @@ export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends
1757
1788
  priority?: number;
1758
1789
  }
1759
1790
 
1791
+ export declare const lexicalTheme$: NodeRef<EditorThemeClasses>;
1792
+
1793
+ export declare const lexicalTheme: EditorThemeClasses;
1794
+
1760
1795
  /**
1761
1796
  * A generic visitor that can be used to process any lexical node.
1762
1797
  * @group Markdown Processing
@@ -2084,6 +2119,10 @@ export declare interface MDXEditorProps {
2084
2119
  * Whether to apply trim() to the initial markdown input (default: true)
2085
2120
  */
2086
2121
  trim?: boolean;
2122
+ /**
2123
+ * A custom lexical theme to use for the editor.
2124
+ */
2125
+ lexicalTheme?: EditorThemeClasses;
2087
2126
  }
2088
2127
 
2089
2128
  /**
@@ -2489,6 +2528,14 @@ export declare type SerializedDirectiveNode = Spread<{
2489
2528
  version: 1;
2490
2529
  }, SerializedLexicalNode>;
2491
2530
 
2531
+ /**
2532
+ * A serialized representation of an {@link FrontmatterNode}.
2533
+ */
2534
+ export declare type SerializedFrontmatterNode = Spread<{
2535
+ yaml: string;
2536
+ version: 1;
2537
+ }, SerializedLexicalNode>;
2538
+
2492
2539
  /**
2493
2540
  * A serialized representation of a {@link GenericHTMLNode}.
2494
2541
  * @group HTML
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { MDXEditor } from "./MDXEditor.js";
4
4
  import { defaultSvgIcons } from "./defaultSvgIcons.js";
5
5
  import { MarkdownParseError, UnrecognizedMarkdownConstructError, importMarkdownToLexical, importMdastTreeToLexical } from "./importMarkdownToLexical.js";
6
6
  import { exportLexicalTreeToMdast, exportMarkdownFromLexical } from "./exportMarkdownFromLexical.js";
7
- import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
7
+ import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
8
8
  import { ALL_HEADING_LEVELS, allowedHeadingLevels$, headingsPlugin } from "./plugins/headings/index.js";
9
9
  import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-break/index.js";
10
10
  import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
@@ -60,20 +60,24 @@ import { uuidv4 } from "./utils/uuid4.js";
60
60
  import { voidEmitter } from "./utils/voidEmitter.js";
61
61
  import { RealmWithPlugins, realmPlugin } from "./RealmWithPlugins.js";
62
62
  import { DEFAULT_FORMAT, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE } from "./FormatConstants.js";
63
+ import { lexicalTheme } from "./styles/lexicalTheme.js";
63
64
  import { htmlTags, isMdastHTMLNode } from "./plugins/core/MdastHTMLNode.js";
64
65
  import { $createGenericHTMLNode, $isGenericHTMLNode, GenericHTMLNode, TYPE_NAME } from "./plugins/core/GenericHTMLNode.js";
65
66
  import { $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
66
67
  import { $createImageNode, $isImageNode, ImageNode } from "./plugins/image/ImageNode.js";
68
+ import { $createFrontmatterNode, $isFrontmatterNode, FrontmatterNode } from "./plugins/frontmatter/FrontmatterNode.js";
67
69
  import { $createCodeBlockNode, $isCodeBlockNode, CodeBlockNode, useCodeBlockEditorContext } from "./plugins/codeblock/CodeBlockNode.js";
68
70
  import { $createDirectiveNode, $isDirectiveNode, DirectiveNode } from "./plugins/directives/DirectiveNode.js";
69
71
  export {
70
72
  $createCodeBlockNode,
71
73
  $createDirectiveNode,
74
+ $createFrontmatterNode,
72
75
  $createGenericHTMLNode,
73
76
  $createImageNode,
74
77
  $createTableNode,
75
78
  $isCodeBlockNode,
76
79
  $isDirectiveNode,
80
+ $isFrontmatterNode,
77
81
  $isGenericHTMLNode,
78
82
  $isImageNode,
79
83
  $isTableNode,
@@ -99,6 +103,7 @@ export {
99
103
  DialogButton,
100
104
  DiffSourceToggleWrapper,
101
105
  DirectiveNode,
106
+ FrontmatterNode,
102
107
  GenericDirectiveEditor,
103
108
  GenericHTMLNode,
104
109
  GenericJsxEditor,
@@ -249,6 +254,8 @@ export {
249
254
  jsxComponentDescriptors$,
250
255
  jsxIsAvailable$,
251
256
  jsxPlugin,
257
+ lexicalTheme,
258
+ lexicalTheme$,
252
259
  linkAutocompleteSuggestions$,
253
260
  linkDialogPlugin,
254
261
  linkDialogState$,
@@ -470,6 +470,7 @@ const addActivePlugin$ = Appender(activePlugins$);
470
470
  const translation$ = Cell(() => {
471
471
  throw new Error("No translation function provided");
472
472
  });
473
+ const lexicalTheme$ = Cell(lexicalTheme);
473
474
  const corePlugin = realmPlugin({
474
475
  init(r, params) {
475
476
  const initialMarkdown = (params == null ? void 0 : params.initialMarkdown) ?? "";
@@ -497,7 +498,8 @@ const corePlugin = realmPlugin({
497
498
  [translation$]: params == null ? void 0 : params.translation,
498
499
  [addMdastExtension$]: gfmStrikethroughFromMarkdown(),
499
500
  [addSyntaxExtension$]: gfmStrikethrough(),
500
- [addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown()]
501
+ [addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown()],
502
+ [lexicalTheme$]: (params == null ? void 0 : params.lexicalTheme) ?? lexicalTheme
501
503
  });
502
504
  r.singletonSub(markdownErrorSignal$, params == null ? void 0 : params.onError);
503
505
  r.singletonSub(mutableMarkdownSignal$, params == null ? void 0 : params.onChange);
@@ -518,7 +520,7 @@ const corePlugin = realmPlugin({
518
520
  onError: (error) => {
519
521
  throw error;
520
522
  },
521
- theme: lexicalTheme
523
+ theme: r.getValue(lexicalTheme$)
522
524
  });
523
525
  newEditor.update(() => {
524
526
  const markdown = (params == null ? void 0 : params.initialMarkdown.trim()) ?? "";
@@ -605,6 +607,7 @@ export {
605
607
  insertMarkdown$,
606
608
  jsxComponentDescriptors$,
607
609
  jsxIsAvailable$,
610
+ lexicalTheme$,
608
611
  markdown$,
609
612
  markdownErrorSignal$,
610
613
  markdownProcessingError$,
@@ -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.17.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",