@mdxeditor/editor 1.5.0 → 1.7.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
  {
@@ -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
@@ -11,6 +11,16 @@ import type { LexicalEditor, RangeSelection, Klass, LexicalNode, TextFormatType,
11
11
  import type { SystemSpec, Realm, RealmNode, PluginConstructor, TypedRealm, ValueForKey, SystemKeys, ValuesForKeys, SystemDict } from '../../gurx';
12
12
  /// <reference types="react" />
13
13
  import * as Mdast from 'mdast';
14
+ type InsertTablePayload = {
15
+ /**
16
+ * The nunber of rows of the table.
17
+ */
18
+ rows?: number;
19
+ /**
20
+ * The nunber of columns of the table.
21
+ */
22
+ columns?: number;
23
+ };
14
24
  /** @internal */
15
25
  export declare const tableSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
16
26
  activeEditor: RealmNode<LexicalEditor | null>;
@@ -123,7 +133,7 @@ export declare const tableSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
123
133
  insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
124
134
  onBlur: RealmNode<FocusEvent>;
125
135
  }]) => {
126
- insertTable: RealmNode<true>;
136
+ insertTable: RealmNode<InsertTablePayload>;
127
137
  }>;
128
138
  export declare const
129
139
  /** @internal */
@@ -238,12 +248,12 @@ tablePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
238
248
  insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
239
249
  onBlur: RealmNode<FocusEvent>;
240
250
  }]) => {
241
- insertTable: RealmNode<true>;
251
+ insertTable: RealmNode<InsertTablePayload>;
242
252
  }>, object>,
243
253
  /** @internal */
244
254
  tablePluginHooks: {
245
255
  useRealmContext: () => TypedRealm<{
246
- insertTable: RealmNode<true>;
256
+ insertTable: RealmNode<InsertTablePayload>;
247
257
  } & {
248
258
  activeEditor: RealmNode<LexicalEditor | null>;
249
259
  inFocus: RealmNode<boolean>;
@@ -301,7 +311,7 @@ tablePluginHooks: {
301
311
  onBlur: RealmNode<FocusEvent>;
302
312
  }>;
303
313
  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" | "insertTable">(key: K, callback: (value: ValueForKey<{
304
- insertTable: RealmNode<true>;
314
+ insertTable: RealmNode<InsertTablePayload>;
305
315
  } & {
306
316
  activeEditor: RealmNode<LexicalEditor | null>;
307
317
  inFocus: RealmNode<boolean>;
@@ -359,7 +369,7 @@ tablePluginHooks: {
359
369
  onBlur: RealmNode<FocusEvent>;
360
370
  }, K>) => void) => void;
361
371
  useEmitterValues: <K_1 extends SystemKeys<{
362
- insertTable: RealmNode<true>;
372
+ insertTable: RealmNode<InsertTablePayload>;
363
373
  } & {
364
374
  activeEditor: RealmNode<LexicalEditor | null>;
365
375
  inFocus: RealmNode<boolean>;
@@ -416,7 +426,7 @@ tablePluginHooks: {
416
426
  insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
417
427
  onBlur: RealmNode<FocusEvent>;
418
428
  }>>(...keys: K_1) => ValuesForKeys<{
419
- insertTable: RealmNode<true>;
429
+ insertTable: RealmNode<InsertTablePayload>;
420
430
  } & {
421
431
  activeEditor: RealmNode<LexicalEditor | null>;
422
432
  inFocus: RealmNode<boolean>;
@@ -474,7 +484,7 @@ tablePluginHooks: {
474
484
  onBlur: RealmNode<FocusEvent>;
475
485
  }, K_1>;
476
486
  usePubKeys: () => (values: SystemDict<{
477
- insertTable: RealmNode<true>;
487
+ insertTable: RealmNode<InsertTablePayload>;
478
488
  } & {
479
489
  activeEditor: RealmNode<LexicalEditor | null>;
480
490
  inFocus: RealmNode<boolean>;
@@ -532,7 +542,7 @@ tablePluginHooks: {
532
542
  onBlur: RealmNode<FocusEvent>;
533
543
  }>) => void;
534
544
  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" | "insertTable">(key: K_2) => (value: ValueForKey<{
535
- insertTable: RealmNode<true>;
545
+ insertTable: RealmNode<InsertTablePayload>;
536
546
  } & {
537
547
  activeEditor: RealmNode<LexicalEditor | null>;
538
548
  inFocus: RealmNode<boolean>;
@@ -590,3 +600,4 @@ tablePluginHooks: {
590
600
  onBlur: RealmNode<FocusEvent>;
591
601
  }, K_2>) => void;
592
602
  };
603
+ export {};
@@ -6,16 +6,26 @@ import { MdastTableVisitor } from "./MdastTableVisitor.js";
6
6
  import { $createTableNode, TableNode } from "./TableNode.js";
7
7
  import { system } from "../../gurx/realmFactory.js";
8
8
  import { realmPlugin } from "../../gurx/react.js";
9
- function seedTable() {
10
- return {
9
+ function seedTable(rows = 1, columns = 1) {
10
+ const table = {
11
11
  type: "table",
12
- children: [
13
- {
14
- type: "tableRow",
15
- children: [{ type: "tableCell", children: [] }]
16
- }
17
- ]
12
+ children: []
18
13
  };
14
+ for (let i = 0; i < rows; i++) {
15
+ const tableRow = {
16
+ type: "tableRow",
17
+ children: []
18
+ };
19
+ for (let j = 0; j < columns; j++) {
20
+ const cell = {
21
+ type: "tableCell",
22
+ children: []
23
+ };
24
+ tableRow.children.push(cell);
25
+ }
26
+ table.children.push(tableRow);
27
+ }
28
+ return table;
19
29
  }
20
30
  const tableSystem = system(
21
31
  (r, [{ insertDecoratorNode }]) => {
@@ -23,8 +33,8 @@ const tableSystem = system(
23
33
  r.link(
24
34
  r.pipe(
25
35
  insertTable,
26
- r.o.mapTo(() => {
27
- return $createTableNode(seedTable());
36
+ r.o.map(({ rows, columns }) => {
37
+ return () => $createTableNode(seedTable(rows, columns));
28
38
  })
29
39
  ),
30
40
  insertDecoratorNode
@@ -9,7 +9,7 @@ const InsertTable = () => {
9
9
  {
10
10
  title: "Insert table",
11
11
  onClick: () => {
12
- insertTable(true);
12
+ insertTable({ rows: 3, columns: 3 });
13
13
  }
14
14
  },
15
15
  /* @__PURE__ */ React__default.createElement(TableIcon, null)
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "private": false,
10
10
  "sideEffects": false,
11
11
  "type": "module",
12
- "version": "1.5.0",
12
+ "version": "1.7.0",
13
13
  "description": "React component for rich text markdown editing",
14
14
  "scripts": {
15
15
  "build": "vite build",