@mdxeditor/editor 3.0.7 → 3.1.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.
Files changed (61) hide show
  1. package/dist/FormatConstants.js +6 -0
  2. package/dist/MDXEditor.js +1 -1
  3. package/dist/directive-editors/GenericDirectiveEditor.js +5 -7
  4. package/dist/exportMarkdownFromLexical.js +10 -7
  5. package/dist/icons/strikethrough_s.svg.js +5 -0
  6. package/dist/icons/subscript.svg.js +5 -0
  7. package/dist/icons/superscript.svg.js +5 -0
  8. package/dist/importMarkdownToLexical.js +3 -1
  9. package/dist/index.d.ts +133 -142
  10. package/dist/index.js +2 -1
  11. package/dist/jsx-editors/GenericJsxEditor.js +1 -1
  12. package/dist/mdastUtilHtmlComment.js +2 -2
  13. package/dist/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js +114 -0
  14. package/dist/node_modules/micromark-util-chunked/index.js +29 -0
  15. package/dist/node_modules/micromark-util-classify-character/index.js +12 -0
  16. package/dist/node_modules/micromark-util-resolve-all/index.js +15 -0
  17. package/dist/plugins/codeblock/index.js +2 -2
  18. package/dist/plugins/codemirror/index.js +4 -4
  19. package/dist/plugins/core/Icon.js +6 -0
  20. package/dist/plugins/core/LexicalTextVisitor.js +56 -10
  21. package/dist/plugins/core/MdastFormattingVisitor.js +66 -30
  22. package/dist/plugins/core/MdastHTMLNode.js +1 -2
  23. package/dist/plugins/core/NestedLexicalEditor.js +1 -1
  24. package/dist/plugins/core/PropertyPopover.js +28 -18
  25. package/dist/plugins/core/index.js +36 -39
  26. package/dist/plugins/core/ui/DownshiftAutoComplete.js +1 -1
  27. package/dist/plugins/directives/index.js +2 -2
  28. package/dist/plugins/frontmatter/FrontmatterEditor.js +48 -31
  29. package/dist/plugins/frontmatter/FrontmatterNode.js +5 -3
  30. package/dist/plugins/image/ImageDialog.js +1 -1
  31. package/dist/plugins/image/ImageEditor.js +8 -6
  32. package/dist/plugins/image/ImageNode.js +2 -2
  33. package/dist/plugins/image/MdastImageVisitor.js +3 -3
  34. package/dist/plugins/image/index.js +20 -20
  35. package/dist/plugins/jsx/index.js +1 -1
  36. package/dist/plugins/link-dialog/LinkDialog.js +13 -5
  37. package/dist/plugins/link-dialog/index.js +7 -8
  38. package/dist/plugins/lists/MdastListVisitor.js +1 -2
  39. package/dist/plugins/lists/index.js +1 -1
  40. package/dist/plugins/markdown-shortcut/index.js +4 -2
  41. package/dist/plugins/sandpack/SandpackEditor.js +1 -1
  42. package/dist/plugins/sandpack/index.js +2 -2
  43. package/dist/plugins/sandpack/useCodeMirrorRef.js +8 -8
  44. package/dist/plugins/table/TableEditor.js +67 -50
  45. package/dist/plugins/table/TableNode.js +2 -2
  46. package/dist/plugins/toolbar/components/BlockTypeSelect.js +3 -3
  47. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +79 -24
  48. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +1 -1
  49. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +1 -1
  50. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +3 -1
  51. package/dist/plugins/toolbar/components/InsertFrontmatter.js +3 -1
  52. package/dist/plugins/toolbar/components/InsertImage.js +12 -1
  53. package/dist/plugins/toolbar/components/InsertThematicBreak.js +10 -1
  54. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +2 -2
  55. package/dist/plugins/toolbar/primitives/DialogButton.js +1 -1
  56. package/dist/plugins/toolbar/primitives/select.js +3 -1
  57. package/dist/plugins/toolbar/primitives/toolbar.js +17 -3
  58. package/dist/utils/detectMac.js +1 -1
  59. package/dist/utils/isPartOftheEditorUI.js +1 -1
  60. package/package.json +9 -8
  61. package/dist/plugins/core/MdastInlineCodeVisitor.js +0 -27
@@ -20,7 +20,7 @@ const SandpackEditor = ({ nodeKey, code, focusEmitter, preset }) => {
20
20
  theme: preset.sandpackTheme,
21
21
  files: {
22
22
  [preset.snippetFileName]: code,
23
- ...Object.entries(preset.files || {}).reduce(
23
+ ...Object.entries(preset.files ?? {}).reduce(
24
24
  (acc, [filePath, fileContents]) => ({ ...acc, ...{ [filePath]: { code: fileContents, readOnly: true } } }),
25
25
  {}
26
26
  )
@@ -40,8 +40,8 @@ const insertSandpack$ = Signal((r) => {
40
40
  throw new Error(`No sandpack preset found with name ${presetName}`);
41
41
  }
42
42
  return {
43
- code: preset.initialSnippetContent || "",
44
- language: preset.snippetLanguage || "jsx",
43
+ code: preset.initialSnippetContent ?? "",
44
+ language: preset.snippetLanguage ?? "jsx",
45
45
  meta: preset.meta
46
46
  };
47
47
  })
@@ -20,7 +20,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
20
20
  (e) => {
21
21
  var _a, _b, _c, _d;
22
22
  if (e.key === "ArrowDown") {
23
- const state = (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.state;
23
+ const state = (_b = (_a = codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.state;
24
24
  if (state) {
25
25
  const docLength = state.doc.length;
26
26
  const selectionEnd = state.selection.ranges[0].to;
@@ -33,7 +33,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
33
33
  const node = $getNodeByKey(nodeKey);
34
34
  const nextSibling = node.getNextSibling();
35
35
  if (nextSibling) {
36
- (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
36
+ (_b2 = (_a2 = codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
37
37
  node.selectNext();
38
38
  } else {
39
39
  node.insertAfter($createParagraphNode());
@@ -44,7 +44,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
44
44
  }
45
45
  }
46
46
  } else if (e.key === "ArrowUp") {
47
- const state = (_d = (_c = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _c.getCodemirror()) == null ? void 0 : _d.state;
47
+ const state = (_d = (_c = codeMirrorRef.current) == null ? void 0 : _c.getCodemirror()) == null ? void 0 : _d.state;
48
48
  if (state) {
49
49
  const selectionStart = state.selection.ranges[0].from;
50
50
  if (selectionStart === 0) {
@@ -56,7 +56,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
56
56
  const node = $getNodeByKey(nodeKey);
57
57
  const previousSibling = node.getPreviousSibling();
58
58
  if (previousSibling) {
59
- (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
59
+ (_b2 = (_a2 = codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
60
60
  node.selectPrevious();
61
61
  }
62
62
  });
@@ -73,9 +73,9 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
73
73
  React__default.useEffect(() => {
74
74
  const codeMirror = codeMirrorRef.current;
75
75
  setTimeout(() => {
76
- var _a, _b, _c, _d;
77
- (_b = (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM) == null ? void 0 : _b.addEventListener("focus", onFocusHandler);
78
- (_d = (_c = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _c.contentDOM) == null ? void 0 : _d.addEventListener("keydown", onKeyDownHandler);
76
+ var _a, _b;
77
+ (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM.addEventListener("focus", onFocusHandler);
78
+ (_b = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _b.contentDOM.addEventListener("keydown", onKeyDownHandler);
79
79
  }, 300);
80
80
  return () => {
81
81
  var _a, _b;
@@ -86,7 +86,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
86
86
  React__default.useEffect(() => {
87
87
  focusEmitter.subscribe(() => {
88
88
  var _a, _b;
89
- (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
89
+ (_b = (_a = codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
90
90
  onFocusHandler();
91
91
  });
92
92
  }, [focusEmitter, codeMirrorRef, nodeKey, onFocusHandler]);
@@ -122,67 +122,80 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
122
122
  setHighlightedCoordinates([colIndex, rowIndex]);
123
123
  }, []);
124
124
  const t = useTranslation();
125
- return /* @__PURE__ */ React__default.createElement("table", { className: styles.tableEditor, onMouseOver: onTableMouseOver, onMouseLeave: () => setHighlightedCoordinates([-1, -1]) }, /* @__PURE__ */ React__default.createElement("colgroup", null, readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
126
- const align = mdastNode.align || [];
127
- const currentColumnAlign = align[colIndex] || "left";
128
- const className = AlignToTailwindClassMap[currentColumnAlign];
129
- return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
130
- }), readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null)), readOnly || /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
131
- "button",
125
+ return /* @__PURE__ */ React__default.createElement(
126
+ "table",
132
127
  {
133
- className: styles.iconButton,
134
- type: "button",
135
- title: t("table.deleteTable", "Delete table"),
136
- onClick: (e) => {
137
- e.preventDefault();
138
- parentEditor.update(() => {
139
- lexicalTable.selectNext();
140
- lexicalTable.remove();
141
- });
128
+ className: styles.tableEditor,
129
+ onMouseOver: onTableMouseOver,
130
+ onMouseLeave: () => {
131
+ setHighlightedCoordinates([-1, -1]);
142
132
  }
143
133
  },
144
- iconComponentFor("delete_small")
145
- )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
146
- return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
147
- ColumnEditor,
134
+ /* @__PURE__ */ React__default.createElement("colgroup", null, readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
135
+ const align = mdastNode.align ?? [];
136
+ const currentColumnAlign = align[colIndex] ?? "left";
137
+ const className = AlignToTailwindClassMap[currentColumnAlign];
138
+ return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
139
+ }), readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null)),
140
+ readOnly || /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
141
+ "button",
148
142
  {
149
- ...{
150
- setActiveCellWithBoundaries,
151
- parentEditor,
152
- colIndex,
153
- highlightedCoordinates,
154
- lexicalTable,
155
- align: (mdastNode.align || [])[colIndex]
143
+ className: styles.iconButton,
144
+ type: "button",
145
+ title: t("table.deleteTable", "Delete table"),
146
+ onClick: (e) => {
147
+ e.preventDefault();
148
+ parentEditor.update(() => {
149
+ lexicalTable.selectNext();
150
+ lexicalTable.remove();
151
+ });
156
152
  }
157
- }
158
- ));
159
- }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))), /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
160
- const CellElement = getCellType(rowIndex);
161
- return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, readOnly || /* @__PURE__ */ React__default.createElement(CellElement, { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
162
- var _a;
163
- return /* @__PURE__ */ React__default.createElement(
164
- Cell,
153
+ },
154
+ iconComponentFor("delete_small")
155
+ )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
156
+ return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
157
+ ColumnEditor,
165
158
  {
166
- align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
167
- key: getCellKey(mdastCell),
168
- contents: mdastCell.children,
169
- setActiveCell: setActiveCellWithBoundaries,
170
159
  ...{
171
- rowIndex,
160
+ setActiveCellWithBoundaries,
161
+ parentEditor,
172
162
  colIndex,
163
+ highlightedCoordinates,
173
164
  lexicalTable,
174
- parentEditor,
175
- activeCell: readOnly ? [-1, -1] : activeCell
165
+ align: (mdastNode.align ?? [])[colIndex]
176
166
  }
177
167
  }
178
- );
179
- }), readOnly || rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, iconComponentFor("add_column"))));
180
- })), readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null))));
168
+ ));
169
+ }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))),
170
+ /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
171
+ const CellElement = getCellType(rowIndex);
172
+ return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, readOnly || /* @__PURE__ */ React__default.createElement(CellElement, { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
173
+ var _a;
174
+ return /* @__PURE__ */ React__default.createElement(
175
+ Cell,
176
+ {
177
+ align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
178
+ key: getCellKey(mdastCell),
179
+ contents: mdastCell.children,
180
+ setActiveCell: setActiveCellWithBoundaries,
181
+ ...{
182
+ rowIndex,
183
+ colIndex,
184
+ lexicalTable,
185
+ parentEditor,
186
+ activeCell: readOnly ? [-1, -1] : activeCell
187
+ }
188
+ }
189
+ );
190
+ }), readOnly || rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, iconComponentFor("add_column"))));
191
+ })),
192
+ readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null)))
193
+ );
181
194
  };
182
195
  const Cell = ({ align, ...props }) => {
183
196
  const { activeCell, setActiveCell } = props;
184
197
  const isActive = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
185
- const className = AlignToTailwindClassMap[align || "left"];
198
+ const className = AlignToTailwindClassMap[align ?? "left"];
186
199
  const CellElement = getCellType(props.rowIndex);
187
200
  return /* @__PURE__ */ React__default.createElement(
188
201
  CellElement,
@@ -307,7 +320,7 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
307
320
  );
308
321
  }, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
309
322
  React__default.useEffect(() => {
310
- focus && (editor == null ? void 0 : editor.focus());
323
+ focus && editor.focus();
311
324
  }, [focus, editor]);
312
325
  return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(HistoryPlugin, null));
313
326
  };
@@ -358,7 +371,9 @@ const ColumnEditor = ({
358
371
  RadixPopover.PopoverContent,
359
372
  {
360
373
  className: classNames(styles.tableColumnEditorPopoverContent),
361
- onOpenAutoFocus: (e) => e.preventDefault(),
374
+ onOpenAutoFocus: (e) => {
375
+ e.preventDefault();
376
+ },
362
377
  sideOffset: 5,
363
378
  side: "top"
364
379
  },
@@ -369,7 +384,7 @@ const ColumnEditor = ({
369
384
  onValueChange: (value) => {
370
385
  setColumnAlign(colIndex, value);
371
386
  },
372
- value: align || "left",
387
+ value: align ?? "left",
373
388
  type: "single",
374
389
  "aria-label": t("table.textAlignment", "Text alignment")
375
390
  },
@@ -432,7 +447,9 @@ const RowEditor = ({
432
447
  RadixPopover.PopoverContent,
433
448
  {
434
449
  className: classNames(styles.tableColumnEditorPopoverContent),
435
- onOpenAutoFocus: (e) => e.preventDefault(),
450
+ onOpenAutoFocus: (e) => {
451
+ e.preventDefault();
452
+ },
436
453
  sideOffset: 5,
437
454
  side: "bottom"
438
455
  },
@@ -31,7 +31,7 @@ class TableNode extends DecoratorNode {
31
31
  __publicField(this, "__mdastNode");
32
32
  /** @internal */
33
33
  __publicField(this, "focusEmitter", coordinatesEmitter());
34
- this.__mdastNode = mdastNode || { type: "table", children: [] };
34
+ this.__mdastNode = mdastNode ?? { type: "table", children: [] };
35
35
  }
36
36
  /** @internal */
37
37
  static getType() {
@@ -160,7 +160,7 @@ class TableNode extends DecoratorNode {
160
160
  * Pass `undefined` to remove the focus.
161
161
  */
162
162
  select(coords) {
163
- this.focusEmitter.publish(coords || [0, 0]);
163
+ this.focusEmitter.publish(coords ?? [0, 0]);
164
164
  }
165
165
  /** @internal */
166
166
  isInline() {
@@ -41,10 +41,10 @@ const BlockTypeSelect = () => {
41
41
  case "paragraph":
42
42
  convertSelectionToNode(() => $createParagraphNode());
43
43
  break;
44
+ case "":
45
+ break;
44
46
  default:
45
- if (blockType == "")
46
- ;
47
- else if (blockType.startsWith("h")) {
47
+ if (blockType.startsWith("h")) {
48
48
  convertSelectionToNode(() => $createHeadingNode(blockType));
49
49
  } else {
50
50
  throw new Error(`Unknown block type: ${blockType}`);
@@ -1,34 +1,89 @@
1
- import { currentFormat$, iconComponentFor$, applyFormat$, useTranslation } from "../../core/index.js";
1
+ import { useTranslation, currentFormat$, iconComponentFor$, applyFormat$ } from "../../core/index.js";
2
2
  import { useCellValues, usePublisher } from "@mdxeditor/gurx";
3
3
  import React__default from "react";
4
- import { IS_BOLD, IS_ITALIC, IS_UNDERLINE } from "../../../FormatConstants.js";
5
- import { MultipleChoiceToggleGroup } from "../primitives/toolbar.js";
6
- const BoldItalicUnderlineToggles = () => {
4
+ import { IS_BOLD, IS_ITALIC, IS_UNDERLINE, IS_STRIKETHROUGH, IS_SUPERSCRIPT, IS_SUBSCRIPT } from "../../../FormatConstants.js";
5
+ import { ToggleSingleGroupWithItem } from "../primitives/toolbar.js";
6
+ import styles from "../../../styles/ui.module.css.js";
7
+ const FormatButton = ({ format, addTitle, removeTitle, icon, style, formatName }) => {
7
8
  const [currentFormat, iconComponentFor] = useCellValues(currentFormat$, iconComponentFor$);
8
9
  const applyFormat = usePublisher(applyFormat$);
9
- const t = useTranslation();
10
- const boldIsOn = (currentFormat & IS_BOLD) !== 0;
11
- const italicIsOn = (currentFormat & IS_ITALIC) !== 0;
12
- const underlineIsOn = (currentFormat & IS_UNDERLINE) !== 0;
13
- const boldTitle = boldIsOn ? t("toolbar.removeBold", "Remove bold") : t("toolbar.bold", "Bold");
14
- const italicTitle = italicIsOn ? t("toolbar.removeItalic", "Remove italic") : t("toolbar.italic", "Italic");
15
- const underlineTitle = underlineIsOn ? t("toolbar.removeUnderline", "Remove underline") : t("toolbar.underline", "Underline");
10
+ const active = (currentFormat & format) !== 0;
16
11
  return /* @__PURE__ */ React__default.createElement(
17
- MultipleChoiceToggleGroup,
12
+ ToggleSingleGroupWithItem,
18
13
  {
19
- items: [
20
- { title: boldTitle, contents: iconComponentFor("format_bold"), active: boldIsOn, onChange: applyFormat.bind(null, "bold") },
21
- { title: italicTitle, contents: iconComponentFor("format_italic"), active: italicIsOn, onChange: applyFormat.bind(null, "italic") },
22
- {
23
- title: underlineTitle,
24
- contents: /* @__PURE__ */ React__default.createElement("div", { style: { transform: "translateY(2px)" } }, iconComponentFor("format_underlined")),
25
- active: underlineIsOn,
26
- onChange: applyFormat.bind(null, "underline")
27
- }
28
- ]
29
- }
14
+ title: active ? removeTitle : addTitle,
15
+ on: active,
16
+ onValueChange: () => {
17
+ applyFormat(formatName);
18
+ }
19
+ },
20
+ /* @__PURE__ */ React__default.createElement("div", { style }, iconComponentFor(icon))
30
21
  );
31
22
  };
23
+ const BoldItalicUnderlineToggles = () => {
24
+ const t = useTranslation();
25
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.toolbarGroupOfGroups }, /* @__PURE__ */ React__default.createElement(
26
+ FormatButton,
27
+ {
28
+ format: IS_BOLD,
29
+ addTitle: t("toolbar.bold", "Bold"),
30
+ removeTitle: t("toolbar.removeBold", "Remove bold"),
31
+ icon: "format_bold",
32
+ formatName: "bold"
33
+ }
34
+ ), /* @__PURE__ */ React__default.createElement(
35
+ FormatButton,
36
+ {
37
+ format: IS_ITALIC,
38
+ addTitle: t("toolbar.italic", "Italic"),
39
+ removeTitle: t("toolbar.removeItalic", "Remove italic"),
40
+ icon: "format_italic",
41
+ formatName: "italic"
42
+ }
43
+ ), /* @__PURE__ */ React__default.createElement(
44
+ FormatButton,
45
+ {
46
+ format: IS_UNDERLINE,
47
+ addTitle: t("toolbar.underline", "Underline"),
48
+ removeTitle: t("toolbar.removeUnderline", "Remove underline"),
49
+ icon: "format_underlined",
50
+ formatName: "underline",
51
+ style: { transform: "translateY(2px)" }
52
+ }
53
+ ));
54
+ };
55
+ const StrikeThroughSupSubToggles = () => {
56
+ const t = useTranslation();
57
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.toolbarGroupOfGroups }, /* @__PURE__ */ React__default.createElement(
58
+ FormatButton,
59
+ {
60
+ format: IS_STRIKETHROUGH,
61
+ addTitle: t("toolbar.strikethrough", "Strikethrough"),
62
+ removeTitle: t("toolbar.removeStrikethrough", "Remove strikethrough"),
63
+ icon: "strikeThrough",
64
+ formatName: "strikethrough"
65
+ }
66
+ ), /* @__PURE__ */ React__default.createElement(
67
+ FormatButton,
68
+ {
69
+ format: IS_SUPERSCRIPT,
70
+ addTitle: t("toolbar.superscript", "Superscript"),
71
+ removeTitle: t("toolbar.removeSuperscript", "Remove superscript"),
72
+ icon: "superscript",
73
+ formatName: "superscript"
74
+ }
75
+ ), /* @__PURE__ */ React__default.createElement(
76
+ FormatButton,
77
+ {
78
+ format: IS_SUBSCRIPT,
79
+ addTitle: t("toolbar.subscript", "Subscript"),
80
+ removeTitle: t("toolbar.removeSubscript", "Remove subscript"),
81
+ icon: "subscript",
82
+ formatName: "subscript"
83
+ }
84
+ ));
85
+ };
32
86
  export {
33
- BoldItalicUnderlineToggles
87
+ BoldItalicUnderlineToggles,
88
+ StrikeThroughSupSubToggles
34
89
  };
@@ -25,7 +25,7 @@ const ChangeAdmonitionType = () => {
25
25
  rootEditor == null ? void 0 : rootEditor.update(() => {
26
26
  admonitionNode.setMdastNode({ ...admonitionNode.getMdastNode(), name });
27
27
  setTimeout(() => {
28
- rootEditor == null ? void 0 : rootEditor.update(() => {
28
+ rootEditor.update(() => {
29
29
  admonitionNode.getLatest().select();
30
30
  });
31
31
  }, 80);
@@ -21,7 +21,7 @@ const ChangeCodeMirrorLanguage = () => {
21
21
  theEditor == null ? void 0 : theEditor.update(() => {
22
22
  codeBlockNode.setLanguage(language === EMPTY_VALUE ? "" : language);
23
23
  setTimeout(() => {
24
- theEditor == null ? void 0 : theEditor.update(() => {
24
+ theEditor.update(() => {
25
25
  codeBlockNode.getLatest().select();
26
26
  });
27
27
  });
@@ -26,7 +26,9 @@ const DiffSourceToggleWrapper = ({
26
26
  className: styles.diffSourceToggle,
27
27
  value: viewMode,
28
28
  items: toggleGroupItems,
29
- onChange: (value) => changeViewMode(value || "rich-text")
29
+ onChange: (value) => {
30
+ changeViewMode(value === "" ? "rich-text" : value);
31
+ }
30
32
  }
31
33
  )));
32
34
  };
@@ -16,7 +16,9 @@ const InsertFrontmatter = () => {
16
16
  className: classNames({
17
17
  [styles.activeToolbarButton]: hasFrontmatter
18
18
  }),
19
- onClick: () => insertFrontmatter()
19
+ onClick: () => {
20
+ insertFrontmatter();
21
+ }
20
22
  },
21
23
  iconComponentFor("frontmatter")
22
24
  );
@@ -9,7 +9,18 @@ const InsertImage = React__default.forwardRef((_, forwardedRef) => {
9
9
  const openNewImageDialog = usePublisher(openNewImageDialog$);
10
10
  const [readOnly, iconComponentFor] = useCellValues(readOnly$, iconComponentFor$);
11
11
  const t = useTranslation();
12
- return /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ref: forwardedRef, disabled: readOnly, onClick: () => openNewImageDialog() }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title: t("toolbar.image", "Insert image") }, iconComponentFor("add_photo")));
12
+ return /* @__PURE__ */ React__default.createElement(
13
+ RadixToolbar.Button,
14
+ {
15
+ className: styles.toolbarButton,
16
+ ref: forwardedRef,
17
+ disabled: readOnly,
18
+ onClick: () => {
19
+ openNewImageDialog();
20
+ }
21
+ },
22
+ /* @__PURE__ */ React__default.createElement(TooltipWrap, { title: t("toolbar.image", "Insert image") }, iconComponentFor("add_photo"))
23
+ );
13
24
  });
14
25
  export {
15
26
  InsertImage
@@ -7,7 +7,16 @@ const InsertThematicBreak = () => {
7
7
  const insertThematicBreak = usePublisher(insertThematicBreak$);
8
8
  const iconComponentFor = useCellValue(iconComponentFor$);
9
9
  const t = useTranslation();
10
- return /* @__PURE__ */ React__default.createElement(ButtonWithTooltip, { title: t("toolbar.thematicBreak", "Insert thematic break"), onClick: () => insertThematicBreak() }, iconComponentFor("horizontal_rule"));
10
+ return /* @__PURE__ */ React__default.createElement(
11
+ ButtonWithTooltip,
12
+ {
13
+ title: t("toolbar.thematicBreak", "Insert thematic break"),
14
+ onClick: () => {
15
+ insertThematicBreak();
16
+ }
17
+ },
18
+ iconComponentFor("horizontal_rule")
19
+ );
11
20
  };
12
21
  export {
13
22
  InsertThematicBreak
@@ -1,7 +1,7 @@
1
1
  import React__default from "react";
2
2
  import { ConditionalContents, Separator } from "../primitives/toolbar.js";
3
3
  import { BlockTypeSelect } from "./BlockTypeSelect.js";
4
- import { BoldItalicUnderlineToggles } from "./BoldItalicUnderlineToggles.js";
4
+ import { BoldItalicUnderlineToggles, StrikeThroughSupSubToggles } from "./BoldItalicUnderlineToggles.js";
5
5
  import { ChangeAdmonitionType } from "./ChangeAdmonitionType.js";
6
6
  import { ChangeCodeMirrorLanguage } from "./ChangeCodeMirrorLanguage.js";
7
7
  import { CodeToggle } from "./CodeToggle.js";
@@ -32,7 +32,7 @@ const KitchenSinkToolbar = () => {
32
32
  { when: (editor) => (editor == null ? void 0 : editor.editorType) === "codeblock", contents: () => /* @__PURE__ */ React__default.createElement(ChangeCodeMirrorLanguage, null) },
33
33
  { when: (editor) => (editor == null ? void 0 : editor.editorType) === "sandpack", contents: () => /* @__PURE__ */ React__default.createElement(ShowSandpackInfo, null) },
34
34
  {
35
- fallback: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(UndoRedo, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(BoldItalicUnderlineToggles, null), /* @__PURE__ */ React__default.createElement(CodeToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(ListsToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(
35
+ fallback: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(UndoRedo, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(BoldItalicUnderlineToggles, null), /* @__PURE__ */ React__default.createElement(CodeToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(StrikeThroughSupSubToggles, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(ListsToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(
36
36
  ConditionalContents,
37
37
  {
38
38
  options: [{ when: whenInAdmonition, contents: () => /* @__PURE__ */ React__default.createElement(ChangeAdmonitionType, null) }, { fallback: () => /* @__PURE__ */ React__default.createElement(BlockTypeSelect, null) }]
@@ -35,7 +35,7 @@ const DialogForm = ({ autocompleteSuggestions, onSubmitCallback, dialogInputPlac
35
35
  const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
36
36
  initialInputValue: "",
37
37
  onInputValueChange({ inputValue }) {
38
- inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
38
+ inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) ?? "";
39
39
  const matchingItems = [];
40
40
  for (const suggestion of autocompleteSuggestions) {
41
41
  if (suggestion.toLowerCase().includes(inputValue)) {
@@ -33,7 +33,9 @@ const SelectContent = ({
33
33
  RadixSelect.Content,
34
34
  {
35
35
  className: classNames(className, "mdxeditor-select-content"),
36
- onCloseAutoFocus: (e) => e.preventDefault(),
36
+ onCloseAutoFocus: (e) => {
37
+ e.preventDefault();
38
+ },
37
39
  position: "popper"
38
40
  },
39
41
  /* @__PURE__ */ React__default.createElement(RadixSelect.Viewport, { "data-editor-dropdown": true }, children)
@@ -58,7 +58,9 @@ const MultipleChoiceToggleGroup = ({ items }) => {
58
58
  key: index,
59
59
  title: item.title,
60
60
  on: item.active,
61
- onValueChange: (v) => item.onChange(v === "on"),
61
+ onValueChange: (v) => {
62
+ item.onChange(v === "on");
63
+ },
62
64
  disabled: item.disabled
63
65
  },
64
66
  item.contents
@@ -77,14 +79,26 @@ const SingleChoiceToggleGroup = ({
77
79
  className: classNames(styles.toolbarToggleSingleGroup, className),
78
80
  onValueChange: onChange,
79
81
  value: value || "",
80
- onFocus: (e) => e.preventDefault()
82
+ onFocus: (e) => {
83
+ e.preventDefault();
84
+ }
81
85
  },
82
86
  items.map((item, index) => /* @__PURE__ */ React__default.createElement(ToolbarToggleItem, { key: index, value: item.value }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title: item.title }, item.contents)))
83
87
  ));
84
88
  };
85
89
  const ButtonOrDropdownButton = (props) => {
86
90
  const readOnly = useCellValue(readOnly$);
87
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, props.items.length === 1 ? /* @__PURE__ */ React__default.createElement(ButtonWithTooltip, { title: props.title, onClick: () => props.onChoose(""), disabled: readOnly }, props.children) : /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: "", onValueChange: props.onChoose }, /* @__PURE__ */ React__default.createElement(SelectButtonTrigger, { title: props.title }, props.children), /* @__PURE__ */ React__default.createElement(SelectContent, { className: styles.toolbarButtonDropdownContainer }, props.items.map((item, index) => /* @__PURE__ */ React__default.createElement(SelectItem, { key: index, value: item.value }, item.label)))));
91
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, props.items.length === 1 ? /* @__PURE__ */ React__default.createElement(
92
+ ButtonWithTooltip,
93
+ {
94
+ title: props.title,
95
+ onClick: () => {
96
+ props.onChoose("");
97
+ },
98
+ disabled: readOnly
99
+ },
100
+ props.children
101
+ ) : /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: "", onValueChange: props.onChoose }, /* @__PURE__ */ React__default.createElement(SelectButtonTrigger, { title: props.title }, props.children), /* @__PURE__ */ React__default.createElement(SelectContent, { className: styles.toolbarButtonDropdownContainer }, props.items.map((item, index) => /* @__PURE__ */ React__default.createElement(SelectItem, { key: index, value: item.value }, item.label)))));
88
102
  };
89
103
  function isConditionalContentsOption(option) {
90
104
  return Object.hasOwn(option, "when");
@@ -1,4 +1,4 @@
1
- const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1
+ const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document.createElement !== "undefined";
2
2
  const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
3
3
  function controlOrMeta(metaKey, ctrlKey) {
4
4
  if (IS_APPLE) {
@@ -2,7 +2,7 @@ function isPartOftheEditorUI(element, editorRoot) {
2
2
  if (element === null || element === editorRoot) {
3
3
  return false;
4
4
  }
5
- if (element.dataset["editorDialog"] !== void 0 || element.dataset["toolbarItem"] !== void 0 || element.dataset["editorDropdown"]) {
5
+ if (element.dataset.editorDialog !== void 0 || element.dataset.toolbarItem !== void 0 || element.dataset.editorDropdown) {
6
6
  return true;
7
7
  }
8
8
  return isPartOftheEditorUI(element.parentElement, editorRoot);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.0.7",
14
+ "version": "3.1.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",
@@ -69,6 +69,7 @@
69
69
  "mdast-util-directive": "^3.0.0",
70
70
  "mdast-util-from-markdown": "^2.0.0",
71
71
  "mdast-util-frontmatter": "^2.0.1",
72
+ "mdast-util-gfm-strikethrough": "^2.0.0",
72
73
  "mdast-util-gfm-table": "^2.0.0",
73
74
  "mdast-util-gfm-task-list-item": "^2.0.0",
74
75
  "mdast-util-mdx": "^3.0.0",
@@ -109,15 +110,14 @@
109
110
  "@types/react": "^18.2.7",
110
111
  "@types/react-dom": "^18.2.4",
111
112
  "@types/unist": "^3.0.2",
112
- "@typescript-eslint/eslint-plugin": "^6.17.0",
113
- "@typescript-eslint/parser": "^6.17.0",
113
+ "@typescript-eslint/eslint-plugin": "^7.9.0",
114
+ "@typescript-eslint/parser": "^7.9.0",
114
115
  "@vitejs/plugin-react": "^4.0.0",
115
116
  "@vitejs/plugin-react-swc": "^3.5.0",
116
117
  "autoprefixer": "^10.4.14",
117
118
  "cm6-theme-basic-dark": "^0.2.0",
118
119
  "eslint": "^8.56.0",
119
120
  "eslint-config-prettier": "^9.1.0",
120
- "eslint-config-standard-with-typescript": "^43.0.0",
121
121
  "eslint-plugin-html": "^7.1.0",
122
122
  "eslint-plugin-import": "^2.29.1",
123
123
  "eslint-plugin-json": "^3.1.0",
@@ -141,13 +141,14 @@
141
141
  "semantic-release": "^21.0.5",
142
142
  "svgo": "^3.0.2",
143
143
  "terser": "^5.26.0",
144
- "typedoc": "^0.25.6",
145
- "typedoc-plugin-markdown": "^3.17.1",
144
+ "typedoc": "^0.25.13",
145
+ "typedoc-plugin-markdown": "^4.0.2",
146
146
  "typedoc-plugin-no-inherit": "^1.4.0",
147
- "typescript": "^5.3.3",
147
+ "typescript": "^5.4.5",
148
+ "typescript-eslint": "^7.9.0",
148
149
  "typescript-plugin-css-modules": "^5.0.2",
149
150
  "vite": "^5.0.10",
150
- "vite-plugin-dts": "^3.7.0",
151
+ "vite-plugin-dts": "^3.9.1",
151
152
  "vite-plugin-svgr": "^4.2.0",
152
153
  "vite-tsconfig-paths": "^4.2.3",
153
154
  "vitest": "^1.1.1"