@nkzw/mdx-editor 0.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 (148) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/UPSTREAM.md +21 -0
  4. package/dist/EditorIcon.js +75 -0
  5. package/dist/FormatConstants.js +20 -0
  6. package/dist/MDXEditor.js +189 -0
  7. package/dist/MarkdownEditor.js +281 -0
  8. package/dist/PersistentMarkdownEditor.js +358 -0
  9. package/dist/RealmWithPlugins.js +35 -0
  10. package/dist/core.d.ts +3232 -0
  11. package/dist/core.js +354 -0
  12. package/dist/defaultSvgIcons.js +371 -0
  13. package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
  14. package/dist/directive-editors/GenericDirectiveEditor.js +37 -0
  15. package/dist/exportMarkdownFromLexical.js +262 -0
  16. package/dist/horizontalRuleShortcut.js +37 -0
  17. package/dist/importMarkdownToLexical.js +172 -0
  18. package/dist/index.d.ts +86 -0
  19. package/dist/index.js +8 -0
  20. package/dist/jsx-editors/GenericJsxEditor.js +84 -0
  21. package/dist/mdastUtilHtmlComment.js +125 -0
  22. package/dist/persistence.d.ts +128 -0
  23. package/dist/persistence.js +4 -0
  24. package/dist/plugins/codeblock/CodeBlockNode.js +183 -0
  25. package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
  26. package/dist/plugins/codeblock/MdastCodeVisitor.js +23 -0
  27. package/dist/plugins/codeblock/findCodeBlockDescriptor.js +8 -0
  28. package/dist/plugins/codeblock/index.js +46 -0
  29. package/dist/plugins/codemirror/CodeMirrorEditor.js +145 -0
  30. package/dist/plugins/codemirror/index.js +115 -0
  31. package/dist/plugins/codemirror/useCodeMirrorRef.js +101 -0
  32. package/dist/plugins/core/GenericHTMLNode.js +118 -0
  33. package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.js +15 -0
  34. package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
  35. package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
  36. package/dist/plugins/core/LexicalRootVisitor.js +10 -0
  37. package/dist/plugins/core/LexicalTextVisitor.js +160 -0
  38. package/dist/plugins/core/MdastBreakVisitor.js +10 -0
  39. package/dist/plugins/core/MdastFormattingVisitor.js +81 -0
  40. package/dist/plugins/core/MdastHTMLNode.js +120 -0
  41. package/dist/plugins/core/MdastHTMLVisitor.js +17 -0
  42. package/dist/plugins/core/MdastParagraphVisitor.js +23 -0
  43. package/dist/plugins/core/MdastRootVisitor.js +9 -0
  44. package/dist/plugins/core/MdastTextVisitor.js +16 -0
  45. package/dist/plugins/core/NestedLexicalEditor.js +221 -0
  46. package/dist/plugins/core/PropertyPopover.js +75 -0
  47. package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
  48. package/dist/plugins/core/index.js +692 -0
  49. package/dist/plugins/core/ui/DownshiftAutoComplete.js +89 -0
  50. package/dist/plugins/core/ui/PopoverUtils.js +22 -0
  51. package/dist/plugins/diff-source/DiffSourceWrapper.js +24 -0
  52. package/dist/plugins/diff-source/DiffViewer.js +84 -0
  53. package/dist/plugins/diff-source/SourceEditor.js +60 -0
  54. package/dist/plugins/diff-source/index.js +27 -0
  55. package/dist/plugins/directives/DirectiveNode.js +107 -0
  56. package/dist/plugins/directives/DirectiveVisitor.js +10 -0
  57. package/dist/plugins/directives/MdastDirectiveVisitor.js +30 -0
  58. package/dist/plugins/directives/index.js +45 -0
  59. package/dist/plugins/frontmatter/FrontmatterEditor.js +137 -0
  60. package/dist/plugins/frontmatter/FrontmatterNode.js +70 -0
  61. package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
  62. package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
  63. package/dist/plugins/frontmatter/index.js +113 -0
  64. package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
  65. package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
  66. package/dist/plugins/headings/index.js +63 -0
  67. package/dist/plugins/image/EditImageToolbar.js +58 -0
  68. package/dist/plugins/image/ImageDialog.js +132 -0
  69. package/dist/plugins/image/ImageEditor.js +279 -0
  70. package/dist/plugins/image/ImageNode.js +187 -0
  71. package/dist/plugins/image/ImagePlaceholder.js +9 -0
  72. package/dist/plugins/image/ImageResizer.js +223 -0
  73. package/dist/plugins/image/LexicalImageVisitor.js +42 -0
  74. package/dist/plugins/image/MdastImageVisitor.js +91 -0
  75. package/dist/plugins/image/index.js +364 -0
  76. package/dist/plugins/jsx/LexicalJsxNode.js +103 -0
  77. package/dist/plugins/jsx/LexicalJsxVisitor.js +27 -0
  78. package/dist/plugins/jsx/LexicalMdxExpressionNode.js +130 -0
  79. package/dist/plugins/jsx/LexicalMdxExpressionVisitor.js +14 -0
  80. package/dist/plugins/jsx/MdastMdxExpressionVisitor.js +11 -0
  81. package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
  82. package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +28 -0
  83. package/dist/plugins/jsx/index.js +97 -0
  84. package/dist/plugins/jsx/jsxTagName.js +7 -0
  85. package/dist/plugins/link/AutoLinkPlugin.js +18 -0
  86. package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
  87. package/dist/plugins/link/MdastLinkVisitor.js +14 -0
  88. package/dist/plugins/link/index.js +34 -0
  89. package/dist/plugins/link-dialog/LinkDialog.js +262 -0
  90. package/dist/plugins/link-dialog/index.js +304 -0
  91. package/dist/plugins/lists/CheckListPlugin.js +270 -0
  92. package/dist/plugins/lists/LexicalListItemVisitor.js +41 -0
  93. package/dist/plugins/lists/LexicalListVisitor.js +13 -0
  94. package/dist/plugins/lists/MdastListItemVisitor.js +11 -0
  95. package/dist/plugins/lists/MdastListVisitor.js +19 -0
  96. package/dist/plugins/lists/NotesListItemNode.js +22 -0
  97. package/dist/plugins/lists/index.js +111 -0
  98. package/dist/plugins/markdown-shortcut/index.js +114 -0
  99. package/dist/plugins/maxlength/index.js +36 -0
  100. package/dist/plugins/quote/LexicalQuoteVisitor.js +10 -0
  101. package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
  102. package/dist/plugins/quote/index.js +18 -0
  103. package/dist/plugins/remote/index.js +52 -0
  104. package/dist/plugins/search/index.js +360 -0
  105. package/dist/plugins/table/LexicalTableVisitor.js +10 -0
  106. package/dist/plugins/table/MdastTableVisitor.js +10 -0
  107. package/dist/plugins/table/TableEditor.js +527 -0
  108. package/dist/plugins/table/TableNode.js +208 -0
  109. package/dist/plugins/table/index.js +66 -0
  110. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
  111. package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
  112. package/dist/plugins/thematic-break/index.js +27 -0
  113. package/dist/plugins/toolbar/components/BlockTypeSelect.js +62 -0
  114. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +98 -0
  115. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +43 -0
  116. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +42 -0
  117. package/dist/plugins/toolbar/components/CodeToggle.js +21 -0
  118. package/dist/plugins/toolbar/components/CreateLink.js +24 -0
  119. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +42 -0
  120. package/dist/plugins/toolbar/components/HighlightToggle.js +28 -0
  121. package/dist/plugins/toolbar/components/InsertAdmonition.js +34 -0
  122. package/dist/plugins/toolbar/components/InsertCodeBlock.js +23 -0
  123. package/dist/plugins/toolbar/components/InsertFrontmatter.js +28 -0
  124. package/dist/plugins/toolbar/components/InsertImage.js +29 -0
  125. package/dist/plugins/toolbar/components/InsertTable.js +25 -0
  126. package/dist/plugins/toolbar/components/InsertThematicBreak.js +23 -0
  127. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +82 -0
  128. package/dist/plugins/toolbar/components/ListsToggle.js +29 -0
  129. package/dist/plugins/toolbar/components/UndoRedo.js +60 -0
  130. package/dist/plugins/toolbar/index.js +32 -0
  131. package/dist/plugins/toolbar/primitives/DialogButton.js +130 -0
  132. package/dist/plugins/toolbar/primitives/TooltipWrap.js +17 -0
  133. package/dist/plugins/toolbar/primitives/select.js +76 -0
  134. package/dist/plugins/toolbar/primitives/toolbar.js +144 -0
  135. package/dist/registerCodeBoundaryEscape.js +40 -0
  136. package/dist/styles/lexical-theme.module.css.js +62 -0
  137. package/dist/styles/lexicalTheme.js +32 -0
  138. package/dist/styles/ui.module.css.js +296 -0
  139. package/dist/styles.css +2838 -0
  140. package/dist/utils/detectMac.js +16 -0
  141. package/dist/utils/fp.js +44 -0
  142. package/dist/utils/isPartOftheEditorUI.js +12 -0
  143. package/dist/utils/lexicalHelpers.js +185 -0
  144. package/dist/utils/makeHslTransparent.js +6 -0
  145. package/dist/utils/mergeStyleAttributes.js +22 -0
  146. package/dist/utils/uuid4.js +10 -0
  147. package/dist/utils/voidEmitter.js +15 -0
  148. package/package.json +133 -0
@@ -0,0 +1,28 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { IS_HIGHLIGHT } from "../../../FormatConstants.js";
3
+ import { currentFormat$, iconComponentFor$, applyFormat$, useTranslation } from "../../core/index.js";
4
+ import { MultipleChoiceToggleGroup } from "../primitives/toolbar.js";
5
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
6
+ const HighlightToggle = () => {
7
+ const [currentFormat, iconComponentFor] = useCellValues(currentFormat$, iconComponentFor$);
8
+ const applyFormat = usePublisher(applyFormat$);
9
+ const t = useTranslation();
10
+ const highlightIsOn = (currentFormat & IS_HIGHLIGHT) !== 0;
11
+ const title = highlightIsOn ? t("toolbar.removeHighlight", "Remove highlight") : t("toolbar.highlight", "Highlight");
12
+ return /* @__PURE__ */ jsx(
13
+ MultipleChoiceToggleGroup,
14
+ {
15
+ items: [
16
+ {
17
+ title,
18
+ contents: iconComponentFor("format_highlight"),
19
+ active: highlightIsOn,
20
+ onChange: applyFormat.bind(null, "highlight")
21
+ }
22
+ ]
23
+ }
24
+ );
25
+ };
26
+ export {
27
+ HighlightToggle
28
+ };
@@ -0,0 +1,34 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { ButtonOrDropdownButton } from "../primitives/toolbar.js";
4
+ import { insertDirective$ } from "../../directives/index.js";
5
+ import { ADMONITION_TYPES } from "../../../directive-editors/AdmonitionDirectiveDescriptor.js";
6
+ import { usePublisher, useCellValue } from "@mdxeditor/gurx";
7
+ import { iconComponentFor$, useTranslation } from "../../core/index.js";
8
+ import { admonitionLabelsMap } from "./ChangeAdmonitionType.js";
9
+ const InsertAdmonition = () => {
10
+ const insertDirective = usePublisher(insertDirective$);
11
+ const iconComponentFor = useCellValue(iconComponentFor$);
12
+ const t = useTranslation();
13
+ const items = React.useMemo(() => {
14
+ const labels = admonitionLabelsMap(t);
15
+ return ADMONITION_TYPES.map((type) => ({ value: type, label: labels[type] }));
16
+ }, [t]);
17
+ return /* @__PURE__ */ jsx(
18
+ ButtonOrDropdownButton,
19
+ {
20
+ title: t("toolbar.admonition", "Insert Admonition"),
21
+ onChoose: (admonitionName) => {
22
+ insertDirective({
23
+ type: "containerDirective",
24
+ name: admonitionName
25
+ });
26
+ },
27
+ items,
28
+ children: iconComponentFor("admonition")
29
+ }
30
+ );
31
+ };
32
+ export {
33
+ InsertAdmonition
34
+ };
@@ -0,0 +1,23 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { ButtonWithTooltip } from "../primitives/toolbar.js";
3
+ import { insertCodeBlock$ } from "../../codeblock/index.js";
4
+ import { usePublisher, useCellValue } from "@mdxeditor/gurx";
5
+ import { iconComponentFor$, useTranslation } from "../../core/index.js";
6
+ const InsertCodeBlock = () => {
7
+ const insertCodeBlock = usePublisher(insertCodeBlock$);
8
+ const iconComponentFor = useCellValue(iconComponentFor$);
9
+ const t = useTranslation();
10
+ return /* @__PURE__ */ jsx(
11
+ ButtonWithTooltip,
12
+ {
13
+ title: t("toolbar.codeBlock", "Insert Code Block"),
14
+ onClick: () => {
15
+ insertCodeBlock({});
16
+ },
17
+ children: iconComponentFor("frame_source")
18
+ }
19
+ );
20
+ };
21
+ export {
22
+ InsertCodeBlock
23
+ };
@@ -0,0 +1,28 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { ButtonWithTooltip } from "../primitives/toolbar.js";
3
+ import { insertFrontmatter$, hasFrontmatter$ } from "../../frontmatter/index.js";
4
+ import styles from "../../../styles/ui.module.css.js";
5
+ import classNames from "classnames";
6
+ import { usePublisher, useCellValues } from "@mdxeditor/gurx";
7
+ import { iconComponentFor$, useTranslation } from "../../core/index.js";
8
+ const InsertFrontmatter = () => {
9
+ const insertFrontmatter = usePublisher(insertFrontmatter$);
10
+ const [hasFrontmatter, iconComponentFor] = useCellValues(hasFrontmatter$, iconComponentFor$);
11
+ const t = useTranslation();
12
+ return /* @__PURE__ */ jsx(
13
+ ButtonWithTooltip,
14
+ {
15
+ title: hasFrontmatter ? t("toolbar.editFrontmatter", "Edit frontmatter") : t("toolbar.insertFrontmatter", "Insert frontmatter"),
16
+ className: classNames({
17
+ [styles.activeToolbarButton]: hasFrontmatter
18
+ }),
19
+ onClick: () => {
20
+ insertFrontmatter();
21
+ },
22
+ children: iconComponentFor("frontmatter")
23
+ }
24
+ );
25
+ };
26
+ export {
27
+ InsertFrontmatter
28
+ };
@@ -0,0 +1,29 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { openNewImageDialog$ } from "../../image/index.js";
4
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
5
+ import styles from "../../../styles/ui.module.css.js";
6
+ import { readOnly$, iconComponentFor$, useTranslation } from "../../core/index.js";
7
+ import { TooltipWrap } from "../primitives/TooltipWrap.js";
8
+ import { usePublisher, useCellValues } from "@mdxeditor/gurx";
9
+ const InsertImage = React.forwardRef((_, forwardedRef) => {
10
+ const openNewImageDialog = usePublisher(openNewImageDialog$);
11
+ const [readOnly, iconComponentFor] = useCellValues(readOnly$, iconComponentFor$);
12
+ const t = useTranslation();
13
+ return /* @__PURE__ */ jsx(
14
+ RadixToolbar.Button,
15
+ {
16
+ "aria-label": t("toolbar.image", "Insert image"),
17
+ className: styles.toolbarButton,
18
+ ref: forwardedRef,
19
+ disabled: readOnly,
20
+ onClick: () => {
21
+ openNewImageDialog();
22
+ },
23
+ children: /* @__PURE__ */ jsx(TooltipWrap, { title: t("toolbar.image", "Insert image"), children: iconComponentFor("add_photo") })
24
+ }
25
+ );
26
+ });
27
+ export {
28
+ InsertImage
29
+ };
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { ButtonWithTooltip } from "../primitives/toolbar.js";
3
+ import { insertTable$ } from "../../table/index.js";
4
+ import { useCellValue, usePublisher } from "@mdxeditor/gurx";
5
+ import { iconComponentFor$, useTranslation, editorInTable$ } from "../../core/index.js";
6
+ const InsertTable = () => {
7
+ const iconComponentFor = useCellValue(iconComponentFor$);
8
+ const insertTable = usePublisher(insertTable$);
9
+ const t = useTranslation();
10
+ const isDisabled = useCellValue(editorInTable$);
11
+ return /* @__PURE__ */ jsx(
12
+ ButtonWithTooltip,
13
+ {
14
+ title: t("toolbar.table", "Insert Table"),
15
+ onClick: () => {
16
+ insertTable({ rows: 3, columns: 3 });
17
+ },
18
+ ...isDisabled ? { "aria-disabled": true, "data-disabled": true, disabled: true } : {},
19
+ children: iconComponentFor("table")
20
+ }
21
+ );
22
+ };
23
+ export {
24
+ InsertTable
25
+ };
@@ -0,0 +1,23 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { insertThematicBreak$ } from "../../thematic-break/index.js";
3
+ import { ButtonWithTooltip } from "../primitives/toolbar.js";
4
+ import { usePublisher, useCellValue } from "@mdxeditor/gurx";
5
+ import { iconComponentFor$, useTranslation } from "../../core/index.js";
6
+ const InsertThematicBreak = () => {
7
+ const insertThematicBreak = usePublisher(insertThematicBreak$);
8
+ const iconComponentFor = useCellValue(iconComponentFor$);
9
+ const t = useTranslation();
10
+ return /* @__PURE__ */ jsx(
11
+ ButtonWithTooltip,
12
+ {
13
+ title: t("toolbar.thematicBreak", "Insert thematic break"),
14
+ onClick: () => {
15
+ insertThematicBreak();
16
+ },
17
+ children: iconComponentFor("horizontal_rule")
18
+ }
19
+ );
20
+ };
21
+ export {
22
+ InsertThematicBreak
23
+ };
@@ -0,0 +1,82 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { ConditionalContents, Separator } from "../primitives/toolbar.js";
3
+ import { BlockTypeSelect } from "./BlockTypeSelect.js";
4
+ import { BoldItalicUnderlineToggles, StrikeThroughSupSubToggles } from "./BoldItalicUnderlineToggles.js";
5
+ import { ChangeAdmonitionType } from "./ChangeAdmonitionType.js";
6
+ import { ChangeCodeMirrorLanguage } from "./ChangeCodeMirrorLanguage.js";
7
+ import { CodeToggle } from "./CodeToggle.js";
8
+ import { DiffSourceToggleWrapper } from "./DiffSourceToggleWrapper.js";
9
+ import { InsertAdmonition } from "./InsertAdmonition.js";
10
+ import { InsertCodeBlock } from "./InsertCodeBlock.js";
11
+ import { InsertFrontmatter } from "./InsertFrontmatter.js";
12
+ import { InsertImage } from "./InsertImage.js";
13
+ import { InsertTable } from "./InsertTable.js";
14
+ import { InsertThematicBreak } from "./InsertThematicBreak.js";
15
+ import { ListsToggle } from "./ListsToggle.js";
16
+ import { UndoRedo } from "./UndoRedo.js";
17
+ import { CreateLink } from "./CreateLink.js";
18
+ import { HighlightToggle } from "./HighlightToggle.js";
19
+ function whenInAdmonition(editorInFocus) {
20
+ const node = editorInFocus?.rootNode;
21
+ if (!node || node.getType() !== "directive") {
22
+ return false;
23
+ }
24
+ return ["note", "tip", "danger", "info", "caution"].includes(node.getMdastNode().name);
25
+ }
26
+ const KitchenSinkToolbar = () => {
27
+ return /* @__PURE__ */ jsx(DiffSourceToggleWrapper, { children: /* @__PURE__ */ jsx(
28
+ ConditionalContents,
29
+ {
30
+ options: [
31
+ { when: (editor) => editor?.editorType === "codeblock", contents: () => /* @__PURE__ */ jsx(ChangeCodeMirrorLanguage, {}) },
32
+ {
33
+ fallback: () => /* @__PURE__ */ jsxs(Fragment, { children: [
34
+ /* @__PURE__ */ jsx(UndoRedo, {}),
35
+ /* @__PURE__ */ jsx(Separator, {}),
36
+ /* @__PURE__ */ jsx(BoldItalicUnderlineToggles, {}),
37
+ /* @__PURE__ */ jsx(CodeToggle, {}),
38
+ /* @__PURE__ */ jsx(HighlightToggle, {}),
39
+ /* @__PURE__ */ jsx(Separator, {}),
40
+ /* @__PURE__ */ jsx(StrikeThroughSupSubToggles, {}),
41
+ /* @__PURE__ */ jsx(Separator, {}),
42
+ /* @__PURE__ */ jsx(ListsToggle, {}),
43
+ /* @__PURE__ */ jsx(Separator, {}),
44
+ /* @__PURE__ */ jsx(
45
+ ConditionalContents,
46
+ {
47
+ options: [{ when: whenInAdmonition, contents: () => /* @__PURE__ */ jsx(ChangeAdmonitionType, {}) }, { fallback: () => /* @__PURE__ */ jsx(BlockTypeSelect, {}) }]
48
+ }
49
+ ),
50
+ /* @__PURE__ */ jsx(Separator, {}),
51
+ /* @__PURE__ */ jsx(CreateLink, {}),
52
+ /* @__PURE__ */ jsx(InsertImage, {}),
53
+ /* @__PURE__ */ jsx(Separator, {}),
54
+ /* @__PURE__ */ jsx(InsertTable, {}),
55
+ /* @__PURE__ */ jsx(InsertThematicBreak, {}),
56
+ /* @__PURE__ */ jsx(Separator, {}),
57
+ /* @__PURE__ */ jsx(InsertCodeBlock, {}),
58
+ /* @__PURE__ */ jsx(
59
+ ConditionalContents,
60
+ {
61
+ options: [
62
+ {
63
+ when: (editorInFocus) => !whenInAdmonition(editorInFocus),
64
+ contents: () => /* @__PURE__ */ jsxs(Fragment, { children: [
65
+ /* @__PURE__ */ jsx(Separator, {}),
66
+ /* @__PURE__ */ jsx(InsertAdmonition, {})
67
+ ] })
68
+ }
69
+ ]
70
+ }
71
+ ),
72
+ /* @__PURE__ */ jsx(Separator, {}),
73
+ /* @__PURE__ */ jsx(InsertFrontmatter, {})
74
+ ] })
75
+ }
76
+ ]
77
+ }
78
+ ) });
79
+ };
80
+ export {
81
+ KitchenSinkToolbar
82
+ };
@@ -0,0 +1,29 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { currentListType$, applyListType$ } from "../../lists/index.js";
3
+ import { SingleChoiceToggleGroup } from "../primitives/toolbar.js";
4
+ import { useCellValues, usePublisher } from "@mdxeditor/gurx";
5
+ import { iconComponentFor$, editorInTable$, useTranslation } from "../../core/index.js";
6
+ const ICON_NAME_MAP = {
7
+ bullet: "format_list_bulleted",
8
+ number: "format_list_numbered",
9
+ check: "format_list_checked"
10
+ };
11
+ const ListsToggle = ({ options = ["bullet", "number", "check"] }) => {
12
+ const [currentListType, iconComponentFor, inTable] = useCellValues(currentListType$, iconComponentFor$, editorInTable$);
13
+ const applyListType = usePublisher(applyListType$);
14
+ const t = useTranslation();
15
+ const LIST_TITLE_MAP = {
16
+ bullet: t("toolbar.bulletedList", "Bulleted list"),
17
+ number: t("toolbar.numberedList", "Numbered list"),
18
+ check: t("toolbar.checkList", "Check list")
19
+ };
20
+ const items = options.map((type) => ({
21
+ value: type,
22
+ title: LIST_TITLE_MAP[type],
23
+ contents: iconComponentFor(ICON_NAME_MAP[type])
24
+ }));
25
+ return /* @__PURE__ */ jsx(SingleChoiceToggleGroup, { value: currentListType || "", items, onChange: applyListType, disabled: inTable });
26
+ };
27
+ export {
28
+ ListsToggle
29
+ };
@@ -0,0 +1,60 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { mergeRegister } from "@lexical/utils";
3
+ import { useCellValues } from "@mdxeditor/gurx";
4
+ import { CAN_UNDO_COMMAND, COMMAND_PRIORITY_CRITICAL, CAN_REDO_COMMAND, UNDO_COMMAND, REDO_COMMAND } from "lexical";
5
+ import React from "react";
6
+ import { IS_APPLE } from "../../../utils/detectMac.js";
7
+ import { iconComponentFor$, activeEditor$, useTranslation } from "../../core/index.js";
8
+ import { MultipleChoiceToggleGroup } from "../primitives/toolbar.js";
9
+ const UndoRedo = () => {
10
+ const [iconComponentFor, activeEditor] = useCellValues(iconComponentFor$, activeEditor$);
11
+ const [canUndo, setCanUndo] = React.useState(false);
12
+ const [canRedo, setCanRedo] = React.useState(false);
13
+ const t = useTranslation();
14
+ React.useEffect(() => {
15
+ if (activeEditor) {
16
+ return mergeRegister(
17
+ activeEditor.registerCommand(
18
+ CAN_UNDO_COMMAND,
19
+ (payload) => {
20
+ setCanUndo(payload);
21
+ return false;
22
+ },
23
+ COMMAND_PRIORITY_CRITICAL
24
+ ),
25
+ activeEditor.registerCommand(
26
+ CAN_REDO_COMMAND,
27
+ (payload) => {
28
+ setCanRedo(payload);
29
+ return false;
30
+ },
31
+ COMMAND_PRIORITY_CRITICAL
32
+ )
33
+ );
34
+ }
35
+ }, [activeEditor]);
36
+ return /* @__PURE__ */ jsx(
37
+ MultipleChoiceToggleGroup,
38
+ {
39
+ items: [
40
+ {
41
+ title: t("toolbar.undo", "Undo {{shortcut}}", { shortcut: IS_APPLE ? "⌘Z" : "Ctrl+Z" }),
42
+ disabled: !canUndo,
43
+ contents: iconComponentFor("undo"),
44
+ active: false,
45
+ onChange: () => activeEditor?.dispatchCommand(UNDO_COMMAND, void 0)
46
+ },
47
+ {
48
+ title: t("toolbar.redo", "Redo {{shortcut}}", { shortcut: IS_APPLE ? "⌘Y" : "Ctrl+Y" }),
49
+ disabled: !canRedo,
50
+ contents: iconComponentFor("redo"),
51
+ active: false,
52
+ onChange: () => activeEditor?.dispatchCommand(REDO_COMMAND, void 0)
53
+ }
54
+ ]
55
+ }
56
+ );
57
+ };
58
+ export {
59
+ UndoRedo
60
+ };
@@ -0,0 +1,32 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { realmPlugin } from "../../RealmWithPlugins.js";
3
+ import { Cell, useCellValues } from "@mdxeditor/gurx";
4
+ import { addBottomAreaChild$, addTopAreaChild$, readOnly$ } from "../core/index.js";
5
+ import { Root } from "./primitives/toolbar.js";
6
+ const toolbarContents$ = Cell(() => null);
7
+ const toolbarClassName$ = Cell("");
8
+ const DEFAULT_TOOLBAR_CONTENTS = () => {
9
+ return "This is an empty toolbar. Pass `{toolbarContents: () => { return <>toolbar components</> }}` to the toolbarPlugin to customize it.";
10
+ };
11
+ const toolbarPlugin = realmPlugin({
12
+ init(realm, params) {
13
+ const toolbarPositionSymbol = params?.toolbarPosition === "bottom" ? addBottomAreaChild$ : addTopAreaChild$;
14
+ realm.pubIn({
15
+ [toolbarContents$]: params?.toolbarContents ?? DEFAULT_TOOLBAR_CONTENTS,
16
+ [toolbarClassName$]: params?.toolbarClassName ?? "",
17
+ [toolbarPositionSymbol]: () => {
18
+ const [toolbarContents, readOnly, toolbarClassName] = useCellValues(toolbarContents$, readOnly$, toolbarClassName$);
19
+ return /* @__PURE__ */ jsx(Root, { className: toolbarClassName, readOnly, children: toolbarContents() });
20
+ }
21
+ });
22
+ },
23
+ update(realm, params) {
24
+ realm.pub(toolbarContents$, params?.toolbarContents ?? DEFAULT_TOOLBAR_CONTENTS);
25
+ realm.pub(toolbarClassName$, params?.toolbarClassName ?? "");
26
+ }
27
+ });
28
+ export {
29
+ toolbarClassName$,
30
+ toolbarContents$,
31
+ toolbarPlugin
32
+ };
@@ -0,0 +1,130 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import * as Dialog from "@radix-ui/react-dialog";
3
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
4
+ import React from "react";
5
+ import classNames from "classnames";
6
+ import { useCombobox } from "downshift";
7
+ import { editorRootElementRef$, readOnly$, iconComponentFor$, useTranslation } from "../../core/index.js";
8
+ import styles from "../../../styles/ui.module.css.js";
9
+ import { TooltipWrap } from "./TooltipWrap.js";
10
+ import { useCellValues, useCellValue } from "@mdxeditor/gurx";
11
+ const MAX_SUGGESTIONS = 20;
12
+ const DialogButton = React.forwardRef(({ autocompleteSuggestions = [], submitButtonTitle, dialogInputPlaceholder, onSubmit, tooltipTitle, buttonContent }, forwardedRef) => {
13
+ const [editorRootElementRef, readOnly] = useCellValues(editorRootElementRef$, readOnly$);
14
+ const [open, setOpen] = React.useState(false);
15
+ const onSubmitCallback = React.useCallback(
16
+ (value) => {
17
+ onSubmit(value);
18
+ setOpen(false);
19
+ },
20
+ [onSubmit]
21
+ );
22
+ return /* @__PURE__ */ jsxs(Dialog.Root, { open, onOpenChange: setOpen, children: [
23
+ /* @__PURE__ */ jsx(Dialog.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(RadixToolbar.Button, { "aria-label": tooltipTitle, className: styles.toolbarButton, ref: forwardedRef, disabled: readOnly, children: /* @__PURE__ */ jsx(TooltipWrap, { title: tooltipTitle, children: buttonContent }) }) }),
24
+ /* @__PURE__ */ jsxs(Dialog.Portal, { container: editorRootElementRef?.current, children: [
25
+ /* @__PURE__ */ jsx(Dialog.Overlay, { className: styles.dialogOverlay }),
26
+ /* @__PURE__ */ jsx(Dialog.Content, { className: styles.dialogContent, children: /* @__PURE__ */ jsx(
27
+ DialogForm,
28
+ {
29
+ submitButtonTitle,
30
+ autocompleteSuggestions,
31
+ onSubmitCallback,
32
+ dialogInputPlaceholder
33
+ }
34
+ ) })
35
+ ] })
36
+ ] });
37
+ });
38
+ const DialogForm = ({ autocompleteSuggestions, onSubmitCallback, dialogInputPlaceholder, submitButtonTitle }) => {
39
+ const [items, setItems] = React.useState(autocompleteSuggestions.slice(0, MAX_SUGGESTIONS));
40
+ const iconComponentFor = useCellValue(iconComponentFor$);
41
+ const t = useTranslation();
42
+ const enableAutoComplete = autocompleteSuggestions.length > 0;
43
+ const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
44
+ initialInputValue: "",
45
+ onInputValueChange({ inputValue }) {
46
+ inputValue = inputValue?.toLowerCase() ?? "";
47
+ const matchingItems = [];
48
+ for (const suggestion of autocompleteSuggestions) {
49
+ if (suggestion.toLowerCase().includes(inputValue)) {
50
+ matchingItems.push(suggestion);
51
+ if (matchingItems.length >= MAX_SUGGESTIONS) {
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ setItems(matchingItems);
57
+ },
58
+ items,
59
+ itemToString(item) {
60
+ return item ?? "";
61
+ }
62
+ });
63
+ const onKeyDownEH = React.useCallback(
64
+ (e) => {
65
+ if (e.key === "Escape") {
66
+ e.target.form?.reset();
67
+ } else if (e.key === "Enter" && (!isOpen || items.length === 0)) {
68
+ e.preventDefault();
69
+ onSubmitCallback(e.target.value);
70
+ }
71
+ },
72
+ [isOpen, items, onSubmitCallback]
73
+ );
74
+ const downshiftInputProps = getInputProps();
75
+ const inputProps = {
76
+ ...downshiftInputProps,
77
+ onKeyDown: (e) => {
78
+ onKeyDownEH(e);
79
+ downshiftInputProps.onKeyDown(e);
80
+ }
81
+ };
82
+ const onSubmitEH = (e) => {
83
+ e.preventDefault();
84
+ e.stopPropagation();
85
+ onSubmitCallback(inputProps.value);
86
+ };
87
+ const dropdownIsVisible = isOpen && items.length > 0;
88
+ return /* @__PURE__ */ jsxs("form", { onSubmit: onSubmitEH, className: classNames(styles.dialogForm), children: [
89
+ /* @__PURE__ */ jsxs("div", { className: styles.linkDialogInputContainer, children: [
90
+ /* @__PURE__ */ jsxs("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.linkDialogInputWrapper, children: [
91
+ /* @__PURE__ */ jsx(
92
+ "input",
93
+ {
94
+ placeholder: dialogInputPlaceholder,
95
+ className: styles.linkDialogInput,
96
+ ...inputProps,
97
+ autoFocus: true,
98
+ size: 30,
99
+ "data-editor-dialog": true
100
+ }
101
+ ),
102
+ enableAutoComplete && /* @__PURE__ */ jsx("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps(), children: iconComponentFor("arrow_drop_down") })
103
+ ] }),
104
+ /* @__PURE__ */ jsx("div", { className: styles.downshiftAutocompleteContainer, children: /* @__PURE__ */ jsx("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible, children: items.map((item, index) => /* @__PURE__ */ jsx(
105
+ "li",
106
+ {
107
+ "data-selected": selectedItem === item,
108
+ "data-highlighted": highlightedIndex === index,
109
+ ...getItemProps({ item, index }),
110
+ children: item
111
+ },
112
+ `${item}${index}`
113
+ )) }) })
114
+ ] }),
115
+ /* @__PURE__ */ jsx(
116
+ "button",
117
+ {
118
+ type: "submit",
119
+ title: submitButtonTitle,
120
+ "aria-label": submitButtonTitle,
121
+ className: classNames(styles.actionButton, styles.primaryActionButton),
122
+ children: iconComponentFor("check")
123
+ }
124
+ ),
125
+ /* @__PURE__ */ jsx(Dialog.Close, { "aria-label": t("dialog.close", "Close dialog"), className: styles.actionButton, children: iconComponentFor("close") })
126
+ ] });
127
+ };
128
+ export {
129
+ DialogButton
130
+ };
@@ -0,0 +1,17 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import * as Tooltip from "@radix-ui/react-tooltip";
3
+ import classNames from "classnames";
4
+ import React from "react";
5
+ import styles from "../../../styles/ui.module.css.js";
6
+ import { useCellValue } from "@mdxeditor/gurx";
7
+ import { editorRootElementRef$ } from "../../core/index.js";
8
+ const TooltipWrap = React.forwardRef(({ title, children }, ref) => {
9
+ const editorRootElementRef = useCellValue(editorRootElementRef$);
10
+ return /* @__PURE__ */ jsx(Tooltip.Provider, { delayDuration: 100, children: /* @__PURE__ */ jsxs(Tooltip.Root, { children: [
11
+ /* @__PURE__ */ jsx(Tooltip.Trigger, { ref, asChild: true, children: /* @__PURE__ */ jsx("span", { className: styles.tooltipTrigger, children }) }),
12
+ /* @__PURE__ */ jsx(Tooltip.Portal, { container: editorRootElementRef?.current, children: /* @__PURE__ */ jsx(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 10, children: title }) })
13
+ ] }) });
14
+ });
15
+ export {
16
+ TooltipWrap
17
+ };
@@ -0,0 +1,76 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import * as RadixSelect from "@radix-ui/react-select";
4
+ import classNames from "classnames";
5
+ import { EditorIcon } from "../../../EditorIcon.js";
6
+ import styles from "../../../styles/ui.module.css.js";
7
+ import { TooltipWrap } from "./TooltipWrap.js";
8
+ import { readOnly$, editorRootElementRef$ } from "../../core/index.js";
9
+ import { useCellValue } from "@mdxeditor/gurx";
10
+ const SelectItem = React.forwardRef(
11
+ ({ children, className, ...props }, forwardedRef) => {
12
+ return /* @__PURE__ */ jsx(RadixSelect.Item, { ...props, ref: forwardedRef, className: classNames(className, styles.selectItem), children: /* @__PURE__ */ jsx(RadixSelect.ItemText, { children }) });
13
+ }
14
+ );
15
+ const SelectTrigger = ({ title, placeholder, className }) => {
16
+ const readOnly = useCellValue(readOnly$);
17
+ return /* @__PURE__ */ jsx(TooltipWrap, { title, children: /* @__PURE__ */ jsxs(
18
+ RadixSelect.Trigger,
19
+ {
20
+ "aria-label": placeholder,
21
+ className: classNames(styles.selectTrigger, className),
22
+ "data-toolbar-item": true,
23
+ disabled: readOnly,
24
+ children: [
25
+ /* @__PURE__ */ jsx(RadixSelect.Value, { placeholder }),
26
+ /* @__PURE__ */ jsx(RadixSelect.Icon, { className: styles.selectDropdownArrow, children: /* @__PURE__ */ jsx(EditorIcon, { name: "chevron-down" }) })
27
+ ]
28
+ }
29
+ ) });
30
+ };
31
+ const SelectContent = ({
32
+ children,
33
+ className = styles.selectContainer
34
+ }) => {
35
+ const editorRootElementRef = useCellValue(editorRootElementRef$);
36
+ return /* @__PURE__ */ jsx(RadixSelect.Portal, { container: editorRootElementRef?.current, children: /* @__PURE__ */ jsx(
37
+ RadixSelect.Content,
38
+ {
39
+ className: classNames(className, "mdxeditor-select-content"),
40
+ onCloseAutoFocus: (e) => {
41
+ e.preventDefault();
42
+ },
43
+ position: "popper",
44
+ children: /* @__PURE__ */ jsx(RadixSelect.Viewport, { "data-editor-dropdown": true, style: { maxHeight: "var(--radix-select-content-available-height)" }, children })
45
+ }
46
+ ) });
47
+ };
48
+ const SelectButtonTrigger = ({
49
+ children,
50
+ title,
51
+ className
52
+ }) => {
53
+ const readOnly = useCellValue(readOnly$);
54
+ return /* @__PURE__ */ jsx(TooltipWrap, { title, children: /* @__PURE__ */ jsxs(RadixSelect.Trigger, { "aria-label": title, className: classNames(styles.toolbarButtonSelectTrigger, className), disabled: readOnly, children: [
55
+ children,
56
+ /* @__PURE__ */ jsx(RadixSelect.Icon, { className: styles.selectDropdownArrow, children: /* @__PURE__ */ jsx(EditorIcon, { name: "chevron-down" }) })
57
+ ] }) });
58
+ };
59
+ const Select = (props) => {
60
+ return /* @__PURE__ */ jsxs(RadixSelect.Root, { value: props.value || "", onValueChange: props.onChange, disabled: props.disabled, children: [
61
+ /* @__PURE__ */ jsx(SelectTrigger, { title: props.triggerTitle, placeholder: props.placeholder }),
62
+ /* @__PURE__ */ jsx(SelectContent, { children: props.items.map((item, index) => {
63
+ if (item === "separator") {
64
+ return /* @__PURE__ */ jsx(RadixSelect.Separator, {}, index);
65
+ }
66
+ return /* @__PURE__ */ jsx(SelectItem, { value: item.value, children: item.label }, index);
67
+ }) })
68
+ ] });
69
+ };
70
+ export {
71
+ Select,
72
+ SelectButtonTrigger,
73
+ SelectContent,
74
+ SelectItem,
75
+ SelectTrigger
76
+ };