@mdxeditor/editor 3.45.0 → 3.46.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
@@ -1,16 +1,16 @@
1
1
  import { usePublisher, useCellValue, useCellValues, useRealm } from "@mdxeditor/gurx";
2
2
  import React__default from "react";
3
- import { RealmWithPlugins } from "./RealmWithPlugins.js";
4
3
  import { corePlugin, editorRootElementRef$, rootEditor$, useTranslation, contentEditableRef$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, bottomAreaChildren$, insertMarkdown$, setMarkdown$, viewMode$, markdownSourceEditorValue$, markdown$ } from "./plugins/core/index.js";
4
+ import { RealmWithPlugins } from "./RealmWithPlugins.js";
5
+ import { createLexicalComposerContext, LexicalComposerContext } from "@lexical/react/LexicalComposerContext";
5
6
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
7
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
6
8
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
7
9
  import classNames from "classnames";
10
+ import { defaultSvgIcons } from "./defaultSvgIcons.js";
8
11
  import { lexicalTheme } from "./styles/lexicalTheme.js";
9
12
  import styles from "./styles/ui.module.css.js";
10
13
  import { noop } from "./utils/fp.js";
11
- import { createLexicalComposerContext, LexicalComposerContext } from "@lexical/react/LexicalComposerContext";
12
- import { defaultSvgIcons } from "./defaultSvgIcons.js";
13
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
14
14
  const LexicalProvider = ({ children }) => {
15
15
  const rootEditor = useCellValue(rootEditor$);
16
16
  const composerContextValue = React__default.useMemo(() => {
@@ -141,7 +141,9 @@ const MDXEditor = React__default.forwardRef((props, ref) => {
141
141
  trim: props.trim ?? true,
142
142
  lexicalTheme: props.lexicalTheme,
143
143
  ..."editorState" in props ? { editorState: props.editorState } : {},
144
- suppressSharedHistory: props.suppressSharedHistory ?? false
144
+ suppressSharedHistory: props.suppressSharedHistory ?? false,
145
+ additionalLexicalNodes: props.additionalLexicalNodes ?? [],
146
+ lexicalEditorNamespace: props.lexicalEditorNamespace ?? "MDXEditor"
145
147
  }),
146
148
  ...props.plugins ?? []
147
149
  ]
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ import * as lexical from 'lexical';
22
22
  import { LexicalCommand } from 'lexical';
23
23
  import { LexicalEditor } from 'lexical';
24
24
  import { LexicalNode } from 'lexical';
25
+ import { LexicalNodeReplacement } from 'lexical';
25
26
  import { LinkNode } from '@lexical/link';
26
27
  import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
27
28
  import { ListType } from '@lexical/list';
@@ -202,11 +203,13 @@ export declare const addExportVisitor$: NodeRef< LexicalVisitor | LexicalVisitor
202
203
  */
203
204
  export declare const addImportVisitor$: NodeRef<MdastImportVisitor<Mdast.Nodes> | MdastImportVisitor<Mdast.Nodes>[]>;
204
205
 
206
+ export declare type AdditionalLexicalNode = KlassConstructor<typeof LexicalNode> | LexicalNodeReplacement;
207
+
205
208
  /**
206
209
  * Registers a lexical node to be used in the editor.
207
210
  * @group Core
208
211
  */
209
- export declare const addLexicalNode$: NodeRef< KlassConstructor<typeof LexicalNode> | KlassConstructor<typeof LexicalNode>[]>;
212
+ export declare const addLexicalNode$: NodeRef<KlassConstructor<typeof LexicalNode> | KlassConstructor<typeof LexicalNode>[]>;
210
213
 
211
214
  /**
212
215
  * Adds a mdast extension to the markdown parser.
@@ -2311,6 +2314,14 @@ export declare interface MDXEditorProps {
2311
2314
  * The initial state of the lexical editor. Pass null to disable any initiation.
2312
2315
  */
2313
2316
  editorState?: EditorState | undefined | null;
2317
+ /**
2318
+ * Additional lexical nodes to include in the editor.
2319
+ */
2320
+ additionalLexicalNodes?: AdditionalLexicalNode[];
2321
+ /**
2322
+ * The lexical editor namespace.
2323
+ */
2324
+ lexicalEditorNamespace?: string;
2314
2325
  }
2315
2326
 
2316
2327
  /**
@@ -3041,7 +3052,7 @@ export declare function useCodeBlockEditorContext(): CodeBlockEditorContextValue
3041
3052
  * Contains the currently registered lexical nodes.
3042
3053
  * @group Core
3043
3054
  */
3044
- export declare const usedLexicalNodes$: NodeRef< KlassConstructor<typeof LexicalNode>[]>;
3055
+ export declare const usedLexicalNodes$: NodeRef<KlassConstructor<typeof LexicalNode>[]>;
3045
3056
 
3046
3057
  export declare function useEditorSearch(): {
3047
3058
  next: () => void;
@@ -9,6 +9,7 @@ import { lineNumbers, keymap, EditorView } from "@codemirror/view";
9
9
  import { indentWithTab } from "@codemirror/commands";
10
10
  import { basicLight } from "cm6-theme-basic-light";
11
11
  import { basicSetup } from "codemirror";
12
+ import { $setSelection } from "lexical";
12
13
  import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$ } from "./index.js";
13
14
  import { useCodeMirrorRef } from "../sandpack/useCodeMirrorRef.js";
14
15
  import { Select } from "../toolbar/primitives/select.js";
@@ -45,6 +46,13 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
45
46
  EditorView.lineWrapping,
46
47
  EditorView.updateListener.of(({ state }) => {
47
48
  setCodeRef.current(state.doc.toString());
49
+ }),
50
+ EditorView.domEventHandlers({
51
+ focus: () => {
52
+ parentEditor.update(() => {
53
+ $setSelection(null);
54
+ });
55
+ }
48
56
  })
49
57
  ];
50
58
  if (readOnly) {
@@ -545,8 +545,8 @@ const corePlugin = realmPlugin({
545
545
  const newEditor = createEditor({
546
546
  // ...(params?.editorState ? { editorState: params.editorState } : {}),
547
547
  editable: (params == null ? void 0 : params.readOnly) !== true,
548
- namespace: "MDXEditor",
549
- nodes: r.getValue(usedLexicalNodes$),
548
+ namespace: (params == null ? void 0 : params.lexicalEditorNamespace) ?? "MDXEditor",
549
+ nodes: [...r.getValue(usedLexicalNodes$), ...(params == null ? void 0 : params.additionalLexicalNodes) ?? []],
550
550
  onError: (error) => {
551
551
  throw error;
552
552
  },
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.45.0",
14
+ "version": "3.46.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",