@mdxeditor/editor 3.21.5 → 3.22.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/index.d.ts CHANGED
@@ -1393,6 +1393,8 @@ export declare const inFocus$: NodeRef<boolean>;
1393
1393
 
1394
1394
  /* Excluded from this release type: initialMarkdown$ */
1395
1395
 
1396
+ export declare const initialMarkdownNormalize$: NodeRef<boolean>;
1397
+
1396
1398
  /* Excluded from this release type: INSERT_IMAGE_COMMAND */
1397
1399
 
1398
1400
  /**
@@ -2085,8 +2087,9 @@ export declare interface MDXEditorProps {
2085
2087
  /**
2086
2088
  * Triggered when the editor value changes. The callback is not throttled, you can use any throttling mechanism
2087
2089
  * if you intend to do auto-saving.
2090
+ * @param initialMarkdownNormalize - set to true if the change is triggered when the initial markdown is set. This can happen due to variety of reasons - for example, additional whitespace, bullet symbols different than the configured ones, etc.
2088
2091
  */
2089
- onChange?: (markdown: string) => void;
2092
+ onChange?: (markdown: string, initialMarkdownNormalize: boolean) => void;
2090
2093
  /**
2091
2094
  * Triggered when the markdown parser encounters an error. The payload includes the invalid source and the error message.
2092
2095
  */
@@ -2513,6 +2516,7 @@ export declare const Select: <T extends string>(props: {
2513
2516
  onChange: (value: T) => void;
2514
2517
  triggerTitle: string;
2515
2518
  placeholder: string;
2519
+ disabled?: boolean;
2516
2520
  items: ({
2517
2521
  label: string | JSX.Element;
2518
2522
  value: T;
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$, 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";
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$, initialMarkdownNormalize$, 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";
@@ -237,6 +237,7 @@ export {
237
237
  importVisitors$,
238
238
  inFocus$,
239
239
  initialMarkdown$,
240
+ initialMarkdownNormalize$,
240
241
  insertCodeBlock$,
241
242
  insertCodeMirror$,
242
243
  insertDecoratorNode$,
@@ -83,6 +83,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
83
83
  /* @__PURE__ */ React__default.createElement("div", { className: styles.codeMirrorToolbar }, /* @__PURE__ */ React__default.createElement(
84
84
  Select,
85
85
  {
86
+ disabled: readOnly,
86
87
  value: language,
87
88
  onChange: (language2) => {
88
89
  parentEditor.update(() => {
@@ -103,6 +104,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
103
104
  {
104
105
  className: styles.iconButton,
105
106
  type: "button",
107
+ disabled: readOnly,
106
108
  title: t("codeblock.delete", "Delete code block"),
107
109
  onClick: (e) => {
108
110
  e.preventDefault();
@@ -81,9 +81,15 @@ const currentSelection$ = Cell(null, (r) => {
81
81
  });
82
82
  const initialMarkdown$ = Cell("");
83
83
  const markdown$ = Cell("");
84
+ const initialMarkdownNormalize$ = Cell(false);
84
85
  const markdownSignal$ = Signal((r) => {
85
86
  r.link(markdown$, markdownSignal$);
86
- r.link(initialMarkdown$, markdown$);
87
+ r.sub(initialMarkdown$, (md) => {
88
+ r.pubIn({
89
+ [initialMarkdownNormalize$]: true,
90
+ [markdown$]: md
91
+ });
92
+ });
87
93
  });
88
94
  const mutableMarkdownSignal$ = Signal((r) => {
89
95
  r.link(
@@ -274,6 +280,7 @@ const createRootEditorSubscription$ = Appender(rootEditorSubscriptions$, (r, sig
274
280
  });
275
281
  });
276
282
  r.pub(markdown$, theNewMarkdownValue.trim());
283
+ r.pub(initialMarkdownNormalize$, false);
277
284
  });
278
285
  },
279
286
  (rootEditor) => {
@@ -508,7 +515,9 @@ const corePlugin = realmPlugin({
508
515
  [lexicalTheme$]: (params == null ? void 0 : params.lexicalTheme) ?? lexicalTheme
509
516
  });
510
517
  r.singletonSub(markdownErrorSignal$, params == null ? void 0 : params.onError);
511
- r.singletonSub(mutableMarkdownSignal$, params == null ? void 0 : params.onChange);
518
+ r.singletonSub(mutableMarkdownSignal$, (value) => {
519
+ params == null ? void 0 : params.onChange(value, r.getValue(initialMarkdownNormalize$));
520
+ });
512
521
  r.singletonSub(onBlur$, params == null ? void 0 : params.onBlur);
513
522
  if (!(params == null ? void 0 : params.suppressHtmlProcessing)) {
514
523
  r.pubIn({
@@ -558,7 +567,9 @@ const corePlugin = realmPlugin({
558
567
  [placeholder$]: params == null ? void 0 : params.placeholder,
559
568
  [readOnly$]: params == null ? void 0 : params.readOnly
560
569
  });
561
- realm.singletonSub(mutableMarkdownSignal$, params == null ? void 0 : params.onChange);
570
+ realm.singletonSub(mutableMarkdownSignal$, (value) => {
571
+ params == null ? void 0 : params.onChange(value, realm.getValue(initialMarkdownNormalize$));
572
+ });
562
573
  realm.singletonSub(onBlur$, params == null ? void 0 : params.onBlur);
563
574
  realm.singletonSub(markdownErrorSignal$, params == null ? void 0 : params.onError);
564
575
  }
@@ -611,6 +622,7 @@ export {
611
622
  importVisitors$,
612
623
  inFocus$,
613
624
  initialMarkdown$,
625
+ initialMarkdownNormalize$,
614
626
  insertDecoratorNode$,
615
627
  insertMarkdown$,
616
628
  jsxComponentDescriptors$,
@@ -21,6 +21,7 @@ const SandpackEditor = ({ nodeKey, code, focusEmitter, preset }) => {
21
21
  {
22
22
  className: styles.iconButton,
23
23
  type: "button",
24
+ disabled: readOnly,
24
25
  title: t("codeblock.delete", "Delete code block"),
25
26
  onClick: (e) => {
26
27
  e.preventDefault();
@@ -50,7 +50,7 @@ const SelectButtonTrigger = ({
50
50
  return /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, /* @__PURE__ */ React__default.createElement(RadixSelect.Trigger, { className: classNames(styles.toolbarButtonSelectTrigger, className), disabled: readOnly }, children, /* @__PURE__ */ React__default.createElement(RadixSelect.Icon, { className: styles.selectDropdownArrow }, iconComponentFor("arrow_drop_down"))));
51
51
  };
52
52
  const Select = (props) => {
53
- return /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: props.value || void 0, onValueChange: props.onChange }, /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: props.triggerTitle, placeholder: props.placeholder }), /* @__PURE__ */ React__default.createElement(SelectContent, null, props.items.map((item, index) => {
53
+ return /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: props.value || void 0, onValueChange: props.onChange, disabled: props.disabled }, /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: props.triggerTitle, placeholder: props.placeholder }), /* @__PURE__ */ React__default.createElement(SelectContent, null, props.items.map((item, index) => {
54
54
  if (item === "separator") {
55
55
  return /* @__PURE__ */ React__default.createElement(RadixSelect.Separator, { key: index });
56
56
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.21.5",
14
+ "version": "3.22.1",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",