@mdxeditor/editor 1.4.4 → 1.6.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/README.md CHANGED
@@ -9,7 +9,7 @@ MDXEditor is an open-source React component that allows users to author markdown
9
9
  The component supports the core markdown syntax and certain extensions, including tables, images, code blocks, etc. It also allows users to edit JSX components with a built-in JSX editor or a custom one.
10
10
 
11
11
  ```jsx
12
- import {MDXEditor, headingsPlugin()} from '@mdxeditor/editor';
12
+ import {MDXEditor, headingsPlugin} from '@mdxeditor/editor';
13
13
 
14
14
  export default function App() {
15
15
  return <MDXEditor markdown={'# Hello World'} plugins={[headingsPlugin()]} />;
@@ -81,7 +81,6 @@ export declare function realm(): {
81
81
  <T1_14, T2_13, T3_12, T4_11, T5_10, T6_9, T7_8, T8_7, T9_6, T10_5, T11_4, T12_3, T13_3, T14_2, T15_1, T16>(nodes_0: RN<T1_14>, nodes_1: RN<T2_13>, nodes_2: RN<T3_12>, nodes_3: RN<T4_11>, nodes_4: RN<T5_10>, nodes_5: RN<T6_9>, nodes_6: RN<T7_8>, nodes_7: RN<T8_7>, nodes_8: RN<T9_6>, nodes_9: RN<T10_5>, nodes_10: RN<T11_4>, nodes_11: RN<T12_3>, nodes_12: RN<T13_3>, nodes_13: RN<T14_2>, nodes_14: RN<T15_1>, nodes_15: RN<T16>): RN<[T1_14, T2_13, T3_12, T4_11, T5_10, T6_9, T7_8, T8_7, T9_6, T10_5, T11_4, T12_3, T13_3, T14_2, T15_1, T16]>;
82
82
  };
83
83
  connect: <T extends unknown[] = unknown[]>({ sources, pulls, map, sink: { key: sink } }: RealmProjectionSpec<T>) => void;
84
- debug: () => void;
85
84
  derive: <T_1>(source: RealmNode<T_1>, initial: T_1) => RealmNode<T_1>;
86
85
  getKeyValue: (key: string) => unknown;
87
86
  getValue: <T_2>(node: RN<T_2>) => T_2;
@@ -218,11 +218,6 @@ function realm() {
218
218
  });
219
219
  executionMaps.clear();
220
220
  }
221
- function debug() {
222
- Object.entries(labels).forEach(([name, value]) => {
223
- state.get(value.key);
224
- });
225
- }
226
221
  function pub(...args) {
227
222
  const map2 = {};
228
223
  for (let index = 0; index < args.length; index += 2) {
@@ -452,7 +447,6 @@ function realm() {
452
447
  return {
453
448
  combine,
454
449
  connect,
455
- debug,
456
450
  derive,
457
451
  getKeyValue,
458
452
  getValue,
@@ -13,7 +13,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
13
13
  (_b = (_a = codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.dom.addEventListener("paste", (e) => {
14
14
  e.stopPropagation();
15
15
  });
16
- }, [codeMirrorRef]);
16
+ }, [codeMirrorRef, language]);
17
17
  return /* @__PURE__ */ React__default.createElement(
18
18
  "div",
19
19
  {
@@ -13,6 +13,7 @@ const DiffViewer = () => {
13
13
  };
14
14
  const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
15
15
  const cmMergeViewRef = React__default.useRef(null);
16
+ const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
16
17
  const ref = React__default.useCallback(
17
18
  (el) => {
18
19
  var _a;
@@ -30,11 +31,12 @@ const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
30
31
  gutter: true,
31
32
  a: {
32
33
  doc: oldMarkdown,
33
- extensions: [...COMMON_STATE_CONFIG_EXTENSIONS, EditorState.readOnly.of(true)]
34
+ extensions: [...cmExtensions, ...COMMON_STATE_CONFIG_EXTENSIONS, EditorState.readOnly.of(true)]
34
35
  },
35
36
  b: {
36
37
  doc: newMarkdown,
37
38
  extensions: [
39
+ ...cmExtensions,
38
40
  ...COMMON_STATE_CONFIG_EXTENSIONS,
39
41
  EditorView.updateListener.of(({ state }) => {
40
42
  const md = state.doc.toString();
@@ -48,7 +50,7 @@ const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
48
50
  cmMergeViewRef.current = null;
49
51
  }
50
52
  },
51
- [newMarkdown, oldMarkdown, onUpdate]
53
+ [newMarkdown, oldMarkdown, onUpdate, cmExtensions]
52
54
  );
53
55
  return /* @__PURE__ */ React__default.createElement("div", { ref });
54
56
  };
@@ -9,6 +9,7 @@ import { corePluginHooks } from "../core/index.js";
9
9
  const COMMON_STATE_CONFIG_EXTENSIONS = [basicSetup, basicLight, markdown(), lineNumbers()];
10
10
  const SourceEditor = () => {
11
11
  const [markdown2, readOnly] = corePluginHooks.useEmitterValues("markdown", "readOnly");
12
+ const [cmExtensions] = diffSourcePluginHooks.useEmitterValues("cmExtensions");
12
13
  const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
13
14
  const editorViewRef = React__default.useRef(null);
14
15
  const ref = React__default.useCallback(
@@ -16,6 +17,8 @@ const SourceEditor = () => {
16
17
  var _a;
17
18
  if (el !== null) {
18
19
  const extensions = [
20
+ // custom extensions should come first so that you can override the default extensions
21
+ ...cmExtensions,
19
22
  ...COMMON_STATE_CONFIG_EXTENSIONS,
20
23
  EditorView.updateListener.of(({ state }) => {
21
24
  updateMarkdown(state.doc.toString());
@@ -34,7 +37,7 @@ const SourceEditor = () => {
34
37
  editorViewRef.current = null;
35
38
  }
36
39
  },
37
- [markdown2, readOnly, updateMarkdown]
40
+ [markdown2, readOnly, updateMarkdown, cmExtensions]
38
41
  );
39
42
  return /* @__PURE__ */ React__default.createElement("div", { ref, className: "cm-sourceView" });
40
43
  };
@@ -11,6 +11,7 @@ import type { HistoryState } from '@lexical/history';
11
11
  import type { LexicalEditor, RangeSelection, Klass, LexicalNode, TextFormatType, ElementNode, DecoratorNode } from 'lexical';
12
12
  import type { SystemSpec, Realm, RealmNode, PluginConstructor, TypedRealm, ValueForKey, SystemKeys, ValuesForKeys, SystemDict } from '../../gurx';
13
13
  /// <reference types="react" />
14
+ import { Extension } from '@codemirror/state';
14
15
  /** @internal */
15
16
  export type ViewMode = 'rich-text' | 'source' | 'diff';
16
17
  /** @internal */
@@ -128,7 +129,13 @@ export declare const diffSourceSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
128
129
  viewMode: RealmNode<ViewMode>;
129
130
  diffMarkdown: RealmNode<string>;
130
131
  markdownSourceEditorValue: RealmNode<string>;
132
+ cmExtensions: RealmNode<Extension[]>;
131
133
  }>;
134
+ export interface DiffSourcePluginParams {
135
+ viewMode?: ViewMode;
136
+ diffMarkdown?: string;
137
+ codeMirrorExtensions?: Extension[];
138
+ }
132
139
  export declare const
133
140
  /** @internal */
134
141
  diffSourcePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
@@ -245,16 +252,15 @@ diffSourcePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
245
252
  viewMode: RealmNode<ViewMode>;
246
253
  diffMarkdown: RealmNode<string>;
247
254
  markdownSourceEditorValue: RealmNode<string>;
248
- }>, {
249
- viewMode?: ViewMode | undefined;
250
- diffMarkdown?: string | undefined;
251
- }>,
255
+ cmExtensions: RealmNode<Extension[]>;
256
+ }>, DiffSourcePluginParams>,
252
257
  /** @internal */
253
258
  diffSourcePluginHooks: {
254
259
  useRealmContext: () => TypedRealm<{
255
260
  viewMode: RealmNode<ViewMode>;
256
261
  diffMarkdown: RealmNode<string>;
257
262
  markdownSourceEditorValue: RealmNode<string>;
263
+ cmExtensions: RealmNode<Extension[]>;
258
264
  } & {
259
265
  activeEditor: RealmNode<LexicalEditor | null>;
260
266
  inFocus: RealmNode<boolean>;
@@ -311,10 +317,11 @@ diffSourcePluginHooks: {
311
317
  insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
312
318
  onBlur: RealmNode<FocusEvent>;
313
319
  }>;
314
- useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown">(key: K, callback: (value: ValueForKey<{
320
+ useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown" | "cmExtensions">(key: K, callback: (value: ValueForKey<{
315
321
  viewMode: RealmNode<ViewMode>;
316
322
  diffMarkdown: RealmNode<string>;
317
323
  markdownSourceEditorValue: RealmNode<string>;
324
+ cmExtensions: RealmNode<Extension[]>;
318
325
  } & {
319
326
  activeEditor: RealmNode<LexicalEditor | null>;
320
327
  inFocus: RealmNode<boolean>;
@@ -375,6 +382,7 @@ diffSourcePluginHooks: {
375
382
  viewMode: RealmNode<ViewMode>;
376
383
  diffMarkdown: RealmNode<string>;
377
384
  markdownSourceEditorValue: RealmNode<string>;
385
+ cmExtensions: RealmNode<Extension[]>;
378
386
  } & {
379
387
  activeEditor: RealmNode<LexicalEditor | null>;
380
388
  inFocus: RealmNode<boolean>;
@@ -434,6 +442,7 @@ diffSourcePluginHooks: {
434
442
  viewMode: RealmNode<ViewMode>;
435
443
  diffMarkdown: RealmNode<string>;
436
444
  markdownSourceEditorValue: RealmNode<string>;
445
+ cmExtensions: RealmNode<Extension[]>;
437
446
  } & {
438
447
  activeEditor: RealmNode<LexicalEditor | null>;
439
448
  inFocus: RealmNode<boolean>;
@@ -494,6 +503,7 @@ diffSourcePluginHooks: {
494
503
  viewMode: RealmNode<ViewMode>;
495
504
  diffMarkdown: RealmNode<string>;
496
505
  markdownSourceEditorValue: RealmNode<string>;
506
+ cmExtensions: RealmNode<Extension[]>;
497
507
  } & {
498
508
  activeEditor: RealmNode<LexicalEditor | null>;
499
509
  inFocus: RealmNode<boolean>;
@@ -550,10 +560,11 @@ diffSourcePluginHooks: {
550
560
  insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
551
561
  onBlur: RealmNode<FocusEvent>;
552
562
  }>) => void;
553
- usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown">(key: K_2) => (value: ValueForKey<{
563
+ usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown" | "cmExtensions">(key: K_2) => (value: ValueForKey<{
554
564
  viewMode: RealmNode<ViewMode>;
555
565
  diffMarkdown: RealmNode<string>;
556
566
  markdownSourceEditorValue: RealmNode<string>;
567
+ cmExtensions: RealmNode<Extension[]>;
557
568
  } & {
558
569
  activeEditor: RealmNode<LexicalEditor | null>;
559
570
  inFocus: RealmNode<boolean>;
@@ -6,6 +6,7 @@ const diffSourceSystem = system(
6
6
  (r, [{ markdown, setMarkdown }]) => {
7
7
  const diffMarkdown = r.node("");
8
8
  const markdownSourceEditorValue = r.node("");
9
+ const cmExtensions = r.node([]);
9
10
  r.link(markdown, markdownSourceEditorValue);
10
11
  const viewMode = r.node("rich-text");
11
12
  r.sub(
@@ -28,7 +29,7 @@ const diffSourceSystem = system(
28
29
  }
29
30
  }
30
31
  );
31
- return { viewMode, diffMarkdown, markdownSourceEditorValue };
32
+ return { viewMode, diffMarkdown, markdownSourceEditorValue, cmExtensions };
32
33
  },
33
34
  [coreSystem]
34
35
  );
@@ -45,6 +46,7 @@ const [
45
46
  },
46
47
  init(r, params) {
47
48
  r.pubKey("diffMarkdown", (params == null ? void 0 : params.diffMarkdown) || "");
49
+ r.pubKey("cmExtensions", (params == null ? void 0 : params.codeMirrorExtensions) || []);
48
50
  r.pubKey("addEditorWrapper", DiffSourceWrapper);
49
51
  }
50
52
  });
@@ -73,11 +73,19 @@ export interface JsxEditorProps {
73
73
  mdastNode: MdastJsx;
74
74
  descriptor: JsxComponentDescriptor;
75
75
  }
76
- interface InsertJsxPayload {
76
+ type JsxTextPayload = {
77
+ kind: 'text';
77
78
  name: string;
78
- kind: 'flow' | 'text';
79
79
  props: Record<string, string>;
80
- }
80
+ children?: MdxJsxTextElement['children'];
81
+ };
82
+ type JsxFlowPayload = {
83
+ kind: 'flow';
84
+ name: string;
85
+ props: Record<string, string>;
86
+ children?: MdxJsxFlowElement['children'];
87
+ };
88
+ type InsertJsxPayload = JsxTextPayload | JsxFlowPayload;
81
89
  /** @internal */
82
90
  export declare const jsxSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
83
91
  activeEditor: RealmNode<LexicalEditor | null>;
@@ -7,19 +7,38 @@ import { MdastMdxJsEsmVisitor } from "./MdastMdxJsEsmVisitor.js";
7
7
  import { MdastMdxJsxElementVisitor } from "./MdastMdxJsxElementVisitor.js";
8
8
  import { system } from "../../gurx/realmFactory.js";
9
9
  import { realmPlugin } from "../../gurx/react.js";
10
+ function toMdastJsxAttributes(attributes) {
11
+ return Object.entries(attributes).map(([name, value]) => ({
12
+ type: "mdxJsxAttribute",
13
+ name,
14
+ value
15
+ }));
16
+ }
10
17
  const jsxSystem = system(
11
18
  (r, [{ insertDecoratorNode }]) => {
12
19
  const insertJsx = r.node();
13
20
  r.link(
14
21
  r.pipe(
15
22
  insertJsx,
16
- r.o.map(({ name, kind, props }) => {
17
- return () => $createLexicalJsxNode({
18
- name,
19
- type: kind === "flow" ? "mdxJsxFlowElement" : "mdxJsxTextElement",
20
- attributes: Object.entries(props).map(([name2, value]) => ({ type: "mdxJsxAttribute", name: name2, value })),
21
- children: []
22
- });
23
+ r.o.map(({ kind, name, children, props }) => {
24
+ return () => {
25
+ const attributes = toMdastJsxAttributes(props);
26
+ if (kind === "flow") {
27
+ return $createLexicalJsxNode({
28
+ type: "mdxJsxFlowElement",
29
+ name,
30
+ children: children ?? [],
31
+ attributes
32
+ });
33
+ } else {
34
+ return $createLexicalJsxNode({
35
+ type: "mdxJsxTextElement",
36
+ name,
37
+ children: children ?? [],
38
+ attributes
39
+ });
40
+ }
41
+ };
23
42
  })
24
43
  ),
25
44
  insertDecoratorNode
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "private": false,
10
10
  "sideEffects": false,
11
11
  "type": "module",
12
- "version": "1.4.4",
12
+ "version": "1.6.0",
13
13
  "description": "React component for rich text markdown editing",
14
14
  "scripts": {
15
15
  "build": "vite build",
@@ -110,6 +110,7 @@
110
110
  "@typescript-eslint/parser": "^6.7.2",
111
111
  "@vitejs/plugin-react": "^4.0.0",
112
112
  "autoprefixer": "^10.4.14",
113
+ "cm6-theme-basic-dark": "^0.2.0",
113
114
  "eslint": "^8.41.0",
114
115
  "eslint-config-prettier": "^8.8.0",
115
116
  "eslint-config-standard-with-typescript": "^39.1.0",