@mdxeditor/editor 3.18.0 → 3.19.1

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
@@ -1,7 +1,7 @@
1
- import { useCellValue, useCellValues, usePublisher, useRealm } from "@mdxeditor/gurx";
1
+ import { useCellValue, usePublisher, useCellValues, useRealm } from "@mdxeditor/gurx";
2
2
  import React__default from "react";
3
3
  import { RealmWithPlugins } from "./RealmWithPlugins.js";
4
- import { corePlugin, rootEditor$, useTranslation, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, insertMarkdown$ } from "./plugins/core/index.js";
4
+ import { corePlugin, rootEditor$, useTranslation, contentEditableRef$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, insertMarkdown$ } from "./plugins/core/index.js";
5
5
  import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
6
6
  import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
7
7
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin.js";
@@ -20,6 +20,10 @@ const LexicalProvider = ({ children }) => {
20
20
  };
21
21
  const RichTextEditor = () => {
22
22
  const t = useTranslation();
23
+ const setContentEditableRef = usePublisher(contentEditableRef$);
24
+ const onRef = (_contentEditableRef) => {
25
+ setContentEditableRef({ current: _contentEditableRef });
26
+ };
23
27
  const [contentEditableClassName, spellCheck, composerChildren, topAreaChildren, editorWrappers, placeholder] = useCellValues(
24
28
  contentEditableClassName$,
25
29
  spellCheck$,
@@ -31,14 +35,14 @@ const RichTextEditor = () => {
31
35
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, topAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), /* @__PURE__ */ React__default.createElement(RenderRecursiveWrappers, { wrappers: editorWrappers }, /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.rootContentEditableWrapper, "mdxeditor-root-contenteditable") }, /* @__PURE__ */ React__default.createElement(
32
36
  RichTextPlugin,
33
37
  {
34
- contentEditable: /* @__PURE__ */ React__default.createElement(
38
+ contentEditable: /* @__PURE__ */ React__default.createElement("div", { ref: onRef }, /* @__PURE__ */ React__default.createElement(
35
39
  ContentEditable,
36
40
  {
37
41
  className: classNames(styles.contentEditable, contentEditableClassName),
38
42
  ariaLabel: t("contentArea.editableMarkdown", "editable markdown"),
39
43
  spellCheck
40
44
  }
41
- ),
45
+ )),
42
46
  placeholder: /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.contentEditable, styles.placeholder, contentEditableClassName) }, /* @__PURE__ */ React__default.createElement("p", null, placeholder)),
43
47
  ErrorBoundary: LexicalErrorBoundary
44
48
  }
@@ -81,6 +81,7 @@ function importMdastTreeToLexical({ root, mdastRoot, visitors, ...descriptors })
81
81
  mdastNode,
82
82
  lexicalParent,
83
83
  mdastParent,
84
+ descriptors,
84
85
  actions: {
85
86
  visitChildren,
86
87
  addAndStepInto(lexicalNode) {
package/dist/index.d.ts CHANGED
@@ -632,6 +632,12 @@ export declare interface ConditionalContentsOption {
632
632
  */
633
633
  export declare const contentEditableClassName$: NodeRef<string>;
634
634
 
635
+ /**
636
+ * A reference to the content editable element.
637
+ * @group Core
638
+ */
639
+ export declare const contentEditableRef$: NodeRef<default_2.RefObject<HTMLDivElement> | null>;
640
+
635
641
  /**
636
642
  * Returns true if the user is pressing the control key on Windows or the meta key on Mac.
637
643
  * @group Utils
@@ -1940,9 +1946,9 @@ export declare interface MdastImportVisitor<UN extends Mdast.Nodes> {
1940
1946
  /**
1941
1947
  * The test function that determines if this visitor should be used for the given node.
1942
1948
  * As a convenience, you can also pass a string here, which will be compared to the node's type.
1943
- * @param options - the registered descriptors for composite nodes (jsx, directives, code blocks).
1949
+ * @param descriptors - the registered descriptors for composite nodes (jsx, directives, code blocks).
1944
1950
  */
1945
- testNode: ((mdastNode: Mdast.Nodes, options: Descriptors) => boolean) | string;
1951
+ testNode: ((mdastNode: Mdast.Nodes, descriptors: Descriptors) => boolean) | string;
1946
1952
  visitNode(params: {
1947
1953
  /**
1948
1954
  * The node that is currently being visited.
@@ -1956,6 +1962,10 @@ export declare interface MdastImportVisitor<UN extends Mdast.Nodes> {
1956
1962
  * The parent lexical node to which the results of the processing should be added.
1957
1963
  */
1958
1964
  lexicalParent: LexicalNode;
1965
+ /**
1966
+ * The descriptors for composite nodes (jsx, directives, code blocks).
1967
+ */
1968
+ descriptors: Descriptors;
1959
1969
  /**
1960
1970
  * A set of convenience utilities that can be used to add nodes to the lexical tree.
1961
1971
  */
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$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, 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$, contentEditableRef$, 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$, spellCheck$, 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";
@@ -189,6 +189,7 @@ export {
189
189
  compose,
190
190
  composerChildren$,
191
191
  contentEditableClassName$,
192
+ contentEditableRef$,
192
193
  controlOrMeta,
193
194
  convertSelectionToNode$,
194
195
  corePlugin,
@@ -108,6 +108,7 @@ const jsxComponentDescriptors$ = Cell([]);
108
108
  const directiveDescriptors$ = Cell([]);
109
109
  const codeBlockEditorDescriptors$ = Cell([]);
110
110
  const editorRootElementRef$ = Cell(null);
111
+ const contentEditableRef$ = Cell(null);
111
112
  const addLexicalNode$ = Appender(usedLexicalNodes$);
112
113
  const addImportVisitor$ = Appender(importVisitors$);
113
114
  const addSyntaxExtension$ = Appender(syntaxExtensions$);
@@ -592,6 +593,7 @@ export {
592
593
  codeBlockEditorDescriptors$,
593
594
  composerChildren$,
594
595
  contentEditableClassName$,
596
+ contentEditableRef$,
595
597
  convertSelectionToNode$,
596
598
  corePlugin,
597
599
  createActiveEditorSubscription$,
@@ -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
- lexicalParent.append($createLexicalJsxNode(mdastNode));
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
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.18.0",
14
+ "version": "3.19.1",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",