@mdxeditor/editor 3.0.8 → 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 (60) 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 +42 -24
  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 +49 -4
  21. package/dist/plugins/core/MdastFormattingVisitor.js +35 -59
  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 +34 -29
  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 +3 -2
@@ -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.8",
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",
@@ -117,7 +118,6 @@
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",
@@ -145,6 +145,7 @@
145
145
  "typedoc-plugin-markdown": "^4.0.2",
146
146
  "typedoc-plugin-no-inherit": "^1.4.0",
147
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
151
  "vite-plugin-dts": "^3.9.1",