@mdxeditor/editor 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +60 -0
- package/dist/MDXEditor.js +105 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +114 -0
- package/dist/exportMarkdownFromLexical.js +199 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +121 -0
- package/dist/gurx/react.js +112 -0
- package/dist/gurx/realm.d.ts +133 -0
- package/dist/gurx/realm.js +491 -0
- package/dist/gurx/realmFactory.d.ts +58 -0
- package/dist/gurx/realmFactory.js +28 -0
- package/dist/icons/add_column.svg.js +8 -0
- package/dist/icons/add_photo.svg.js +8 -0
- package/dist/icons/add_row.svg.js +8 -0
- package/dist/icons/arrow_drop_down.svg.js +8 -0
- package/dist/icons/arrow_right.svg.js +8 -0
- package/dist/icons/check.svg.js +8 -0
- package/dist/icons/close.svg.js +8 -0
- package/dist/icons/code.svg.js +8 -0
- package/dist/icons/content_copy.svg.js +8 -0
- package/dist/icons/delete.svg.js +8 -0
- package/dist/icons/delete_small.svg.js +8 -0
- package/dist/icons/deployed_code.svg.js +8 -0
- package/dist/icons/difference.svg.js +8 -0
- package/dist/icons/edit.svg.js +8 -0
- package/dist/icons/emergency_home.svg.js +8 -0
- package/dist/icons/format_align_center.svg.js +8 -0
- package/dist/icons/format_align_left.svg.js +8 -0
- package/dist/icons/format_align_right.svg.js +8 -0
- package/dist/icons/format_bold.svg.js +8 -0
- package/dist/icons/format_italic.svg.js +8 -0
- package/dist/icons/format_list_bulleted.svg.js +8 -0
- package/dist/icons/format_list_numbered.svg.js +8 -0
- package/dist/icons/format_underlined.svg.js +8 -0
- package/dist/icons/frame_source.svg.js +8 -0
- package/dist/icons/frontmatter.svg.js +8 -0
- package/dist/icons/horizontal_rule.svg.js +8 -0
- package/dist/icons/insert_col_left.svg.js +8 -0
- package/dist/icons/insert_col_right.svg.js +8 -0
- package/dist/icons/insert_row_above.svg.js +8 -0
- package/dist/icons/insert_row_below.svg.js +8 -0
- package/dist/icons/link.svg.js +8 -0
- package/dist/icons/link_off.svg.js +8 -0
- package/dist/icons/markdown.svg.js +8 -0
- package/dist/icons/more_horiz.svg.js +8 -0
- package/dist/icons/open_in_new.svg.js +8 -0
- package/dist/icons/redo.svg.js +8 -0
- package/dist/icons/rich_text.svg.js +8 -0
- package/dist/icons/settings.svg.js +8 -0
- package/dist/icons/table.svg.js +8 -0
- package/dist/icons/undo.svg.js +8 -0
- package/dist/importMarkdownToLexical.d.ts +84 -0
- package/dist/importMarkdownToLexical.js +65 -0
- package/dist/index.d.ts +49 -1105
- package/dist/index.js +140 -72
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
- package/dist/plugins/codeblock/index.d.ts +617 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
- package/dist/plugins/codemirror/index.d.ts +800 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
- package/dist/plugins/core/LexicalTextVisitor.js +85 -0
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
- package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastTextVisitor.js +10 -0
- package/dist/plugins/core/NestedLexicalEditor.d.ts +96 -0
- package/dist/plugins/core/NestedLexicalEditor.js +181 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -0
- package/dist/plugins/core/PropertyPopover.js +36 -0
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.d.ts +423 -0
- package/dist/plugins/core/index.js +346 -0
- package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
- package/dist/plugins/core/ui/PopoverUtils.js +17 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
- package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
- package/dist/plugins/diff-source/DiffViewer.js +18 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
- package/dist/plugins/diff-source/SourceEditor.js +27 -0
- package/dist/plugins/diff-source/index.d.ts +544 -0
- package/dist/plugins/diff-source/index.js +55 -0
- package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
- package/dist/plugins/directives/DirectiveNode.js +92 -0
- package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
- package/dist/plugins/directives/index.d.ts +603 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.d.ts +523 -0
- package/dist/plugins/frontmatter/index.js +53 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.d.ts +118 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +9 -0
- package/dist/{ImageEditor-3725ebef.js → plugins/image/ImageEditor.js} +40 -52
- package/dist/plugins/image/ImageNode.d.ts +63 -0
- package/dist/plugins/image/ImageNode.js +136 -0
- package/dist/plugins/image/ImageResizer.d.ts +18 -0
- package/dist/plugins/image/ImageResizer.js +214 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +36 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
- package/dist/plugins/image/MdastImageVisitor.js +87 -0
- package/dist/plugins/image/index.d.ts +557 -0
- package/dist/plugins/image/index.js +246 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
- package/dist/plugins/jsx/index.d.ts +599 -0
- package/dist/plugins/jsx/index.js +59 -0
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.d.ts +68 -0
- package/dist/plugins/link/index.js +22 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
- package/dist/plugins/link-dialog/LinkDialog.js +174 -0
- package/dist/plugins/link-dialog/index.d.ts +508 -0
- package/dist/plugins/link-dialog/index.js +242 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
- package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListVisitor.js +13 -0
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
- package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListVisitor.js +18 -0
- package/dist/plugins/lists/index.d.ts +533 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +63 -0
- package/dist/plugins/markdown-shortcut/index.js +34 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.d.ts +361 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +35 -0
- package/dist/plugins/sandpack/index.d.ts +839 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-0def7994.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
- package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.d.ts +21 -0
- package/dist/plugins/table/TableEditor.js +384 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +147 -0
- package/dist/plugins/table/index.d.ts +523 -0
- package/dist/plugins/table/index.js +59 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.d.ts +523 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +11 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +23 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
- package/dist/plugins/toolbar/index.d.ts +428 -0
- package/dist/plugins/toolbar/index.js +39 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
- package/dist/plugins/toolbar/primitives/select.js +44 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +160 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
- package/dist/style.css +556 -249
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +53 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +28 -0
- package/dist/styles/ui.module.css.js +254 -0
- package/dist/utils/detectMac.d.ts +2 -0
- package/dist/utils/detectMac.js +6 -0
- package/dist/utils/fp.d.ts +47 -0
- package/dist/utils/fp.js +10 -0
- package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.d.ts +11 -0
- package/dist/utils/lexicalHelpers.js +49 -0
- package/dist/utils/uuid4.d.ts +1 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.d.ts +14 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/package.json +246 -14
- package/dist/CodeBlockEditor-6488d3ea.cjs +0 -1
- package/dist/CodeBlockEditor-884743e8.js +0 -79
- package/dist/FrontmatterEditor-435d0430.js +0 -118
- package/dist/FrontmatterEditor-95b69d31.cjs +0 -1
- package/dist/ImageEditor-43997418.cjs +0 -1
- package/dist/JsxEditor-1b8aa6c6.cjs +0 -1
- package/dist/JsxEditor-b2e4afc2.js +0 -108
- package/dist/LeafDirectiveEditor-792cbb83.js +0 -59
- package/dist/LeafDirectiveEditor-c0daefa4.cjs +0 -1
- package/dist/SandpackEditor-56a51f80.js +0 -100
- package/dist/SandpackEditor-a09311db.cjs +0 -1
- package/dist/SourceEditor-1fc83319.cjs +0 -1
- package/dist/SourceEditor-32f2b4d8.js +0 -64
- package/dist/TableEditor-616848bc.cjs +0 -1
- package/dist/TableEditor-777ac58a.js +0 -426
- package/dist/index-51585eed.cjs +0 -1
- package/dist/index-d34aa66b.js +0 -4361
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-8f68c999.cjs +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as Dialog from "@radix-ui/react-dialog";
|
|
2
|
+
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import { useCombobox } from "downshift";
|
|
6
|
+
import DropDownIcon from "../../../icons/arrow_drop_down.svg.js";
|
|
7
|
+
import CheckIcon from "../../../icons/check.svg.js";
|
|
8
|
+
import CloseIcon from "../../../icons/close.svg.js";
|
|
9
|
+
import { corePluginHooks } from "../../core/index.js";
|
|
10
|
+
import styles from "../../../styles/ui.module.css.js";
|
|
11
|
+
import { TooltipWrap } from "./TooltipWrap.js";
|
|
12
|
+
const MAX_SUGGESTIONS = 20;
|
|
13
|
+
const DialogButton = React__default.forwardRef(
|
|
14
|
+
({ autocompleteSuggestions = [], submitButtonTitle, dialogInputPlaceholder, onSubmit, tooltipTitle, buttonContent }, forwardedRef) => {
|
|
15
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
16
|
+
const [open, setOpen] = React__default.useState(false);
|
|
17
|
+
const onSubmitCallback = React__default.useCallback(
|
|
18
|
+
(value) => {
|
|
19
|
+
onSubmit(value);
|
|
20
|
+
setOpen(false);
|
|
21
|
+
},
|
|
22
|
+
[onSubmit]
|
|
23
|
+
);
|
|
24
|
+
return /* @__PURE__ */ React__default.createElement(Dialog.Root, { open, onOpenChange: setOpen }, /* @__PURE__ */ React__default.createElement(Dialog.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title: tooltipTitle }, buttonContent))), /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.dialogContent }, /* @__PURE__ */ React__default.createElement(
|
|
25
|
+
DialogForm,
|
|
26
|
+
{
|
|
27
|
+
submitButtonTitle,
|
|
28
|
+
autocompleteSuggestions,
|
|
29
|
+
onSubmitCallback,
|
|
30
|
+
dialogInputPlaceholder
|
|
31
|
+
}
|
|
32
|
+
))));
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
const DialogForm = ({ autocompleteSuggestions, onSubmitCallback, dialogInputPlaceholder, submitButtonTitle }) => {
|
|
36
|
+
const [items, setItems] = React__default.useState(autocompleteSuggestions.slice(0, MAX_SUGGESTIONS));
|
|
37
|
+
const enableAutoComplete = autocompleteSuggestions.length > 0;
|
|
38
|
+
const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
|
|
39
|
+
initialInputValue: "",
|
|
40
|
+
onInputValueChange({ inputValue }) {
|
|
41
|
+
inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
|
|
42
|
+
const matchingItems = [];
|
|
43
|
+
for (const suggestion of autocompleteSuggestions) {
|
|
44
|
+
if (suggestion.toLowerCase().includes(inputValue)) {
|
|
45
|
+
matchingItems.push(suggestion);
|
|
46
|
+
if (matchingItems.length >= MAX_SUGGESTIONS) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
setItems(matchingItems);
|
|
52
|
+
},
|
|
53
|
+
items,
|
|
54
|
+
itemToString(item) {
|
|
55
|
+
return item ?? "";
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const onSubmitEH = (e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
onSubmitCallback(selectedItem || "");
|
|
61
|
+
};
|
|
62
|
+
const onKeyDownEH = React__default.useCallback(
|
|
63
|
+
(e) => {
|
|
64
|
+
var _a;
|
|
65
|
+
if (e.key === "Escape") {
|
|
66
|
+
(_a = e.target.form) == null ? void 0 : _a.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 dropdownIsVisible = isOpen && items.length > 0;
|
|
83
|
+
return /* @__PURE__ */ React__default.createElement("form", { onSubmit: onSubmitEH, className: classNames(styles.linkDialogEditForm) }, /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogInputContainer }, /* @__PURE__ */ React__default.createElement("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.linkDialogInputWrapper }, /* @__PURE__ */ React__default.createElement(
|
|
84
|
+
"input",
|
|
85
|
+
{
|
|
86
|
+
placeholder: dialogInputPlaceholder,
|
|
87
|
+
className: styles.linkDialogInput,
|
|
88
|
+
...inputProps,
|
|
89
|
+
autoFocus: true,
|
|
90
|
+
size: 30,
|
|
91
|
+
"data-editor-dialog": true
|
|
92
|
+
}
|
|
93
|
+
), enableAutoComplete && /* @__PURE__ */ React__default.createElement("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps() }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))), /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible }, items.map((item, index) => /* @__PURE__ */ React__default.createElement(
|
|
94
|
+
"li",
|
|
95
|
+
{
|
|
96
|
+
"data-selected": selectedItem === item,
|
|
97
|
+
"data-highlighted": highlightedIndex === index,
|
|
98
|
+
key: `${item}${index}`,
|
|
99
|
+
...getItemProps({ item, index })
|
|
100
|
+
},
|
|
101
|
+
item
|
|
102
|
+
))))), /* @__PURE__ */ React__default.createElement(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
type: "submit",
|
|
106
|
+
title: submitButtonTitle,
|
|
107
|
+
"aria-label": submitButtonTitle,
|
|
108
|
+
className: classNames(styles.actionButton, styles.primaryActionButton)
|
|
109
|
+
},
|
|
110
|
+
/* @__PURE__ */ React__default.createElement(CheckIcon, null)
|
|
111
|
+
), /* @__PURE__ */ React__default.createElement(Dialog.Close, { className: styles.actionButton }, /* @__PURE__ */ React__default.createElement(CloseIcon, null)));
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
DialogButton
|
|
115
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A small styled wrapper around the radix-ui tooltip, that lets you display an instan tooltip on hover.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TooltipWrap: React.ForwardRefExoticComponent<{
|
|
6
|
+
title: string;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Tooltip from "@radix-ui/react-tooltip";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import styles from "../../../styles/ui.module.css.js";
|
|
5
|
+
import { corePluginHooks } from "../../core/index.js";
|
|
6
|
+
const TooltipWrap = React__default.forwardRef(({ title, children }, ref) => {
|
|
7
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
8
|
+
return /* @__PURE__ */ React__default.createElement(Tooltip.Provider, { delayDuration: 100 }, /* @__PURE__ */ React__default.createElement(Tooltip.Root, null, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { ref, asChild: true }, /* @__PURE__ */ React__default.createElement("span", null, children)), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 10 }, title))));
|
|
9
|
+
});
|
|
10
|
+
export {
|
|
11
|
+
TooltipWrap
|
|
12
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const SelectItem: React.ForwardRefExoticComponent<{
|
|
6
|
+
className?: string | undefined;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
value: string;
|
|
9
|
+
} & React.RefAttributes<HTMLDivElement | null>>;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const SelectTrigger: React.FC<{
|
|
14
|
+
title: string;
|
|
15
|
+
placeholder: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare const SelectContent: React.FC<{
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
className?: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare const SelectButtonTrigger: React.FC<{
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
title: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* The properties of the {@link Select} React component.
|
|
35
|
+
*/
|
|
36
|
+
export interface SelectProps<T extends string> {
|
|
37
|
+
value: T;
|
|
38
|
+
onChange: (value: T) => void;
|
|
39
|
+
triggerTitle: string;
|
|
40
|
+
placeholder: string;
|
|
41
|
+
items: ({
|
|
42
|
+
label: string;
|
|
43
|
+
value: T;
|
|
44
|
+
} | 'separator')[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A toolbar primitive you can use to build dropdowns, such as the block type select.
|
|
48
|
+
* See {@link SelectProps} for more details.
|
|
49
|
+
*/
|
|
50
|
+
export declare const Select: <T extends string>(props: SelectProps<T>) => React.JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import * as RadixSelect from "@radix-ui/react-select";
|
|
3
|
+
import DropDownIcon from "../../../icons/arrow_drop_down.svg.js";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import styles from "../../../styles/ui.module.css.js";
|
|
6
|
+
import { TooltipWrap } from "./TooltipWrap.js";
|
|
7
|
+
import { corePluginHooks } from "../../core/index.js";
|
|
8
|
+
const SelectItem = React__default.forwardRef(
|
|
9
|
+
({ children, className, ...props }, forwardedRef) => {
|
|
10
|
+
return /* @__PURE__ */ React__default.createElement(RadixSelect.Item, { ...props, ref: forwardedRef, className: classNames(className, styles.selectItem) }, /* @__PURE__ */ React__default.createElement(RadixSelect.ItemText, null, children));
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
const SelectTrigger = ({ title, placeholder, className }) => {
|
|
14
|
+
return /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, /* @__PURE__ */ React__default.createElement(RadixSelect.Trigger, { "aria-label": placeholder, className: classNames(styles.selectTrigger, className), "data-toolbar-item": true }, /* @__PURE__ */ React__default.createElement(RadixSelect.Value, { placeholder }), /* @__PURE__ */ React__default.createElement(RadixSelect.Icon, { className: styles.selectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))));
|
|
15
|
+
};
|
|
16
|
+
const SelectContent = ({
|
|
17
|
+
children,
|
|
18
|
+
className = styles.selectContainer
|
|
19
|
+
}) => {
|
|
20
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
21
|
+
return /* @__PURE__ */ React__default.createElement(RadixSelect.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(RadixSelect.Content, { className, onCloseAutoFocus: (e) => e.preventDefault(), position: "popper" }, /* @__PURE__ */ React__default.createElement(RadixSelect.Viewport, { "data-editor-dropdown": true }, children)));
|
|
22
|
+
};
|
|
23
|
+
const SelectButtonTrigger = ({
|
|
24
|
+
children,
|
|
25
|
+
title,
|
|
26
|
+
className
|
|
27
|
+
}) => {
|
|
28
|
+
return /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, /* @__PURE__ */ React__default.createElement(RadixSelect.Trigger, { className: classNames(styles.toolbarButtonSelectTrigger, className) }, children, /* @__PURE__ */ React__default.createElement(RadixSelect.Icon, { className: styles.selectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))));
|
|
29
|
+
};
|
|
30
|
+
const Select = (props) => {
|
|
31
|
+
return /* @__PURE__ */ React__default.createElement(RadixSelect.Root, { value: props.value, onValueChange: props.onChange }, /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: props.triggerTitle, placeholder: props.placeholder }), /* @__PURE__ */ React__default.createElement(SelectContent, null, props.items.map((item, index) => {
|
|
32
|
+
if (item === "separator") {
|
|
33
|
+
return /* @__PURE__ */ React__default.createElement(RadixSelect.Separator, { key: index });
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ React__default.createElement(SelectItem, { key: index, value: item.value }, item.label);
|
|
36
|
+
})));
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
Select,
|
|
40
|
+
SelectButtonTrigger,
|
|
41
|
+
SelectContent,
|
|
42
|
+
SelectItem,
|
|
43
|
+
SelectTrigger
|
|
44
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as RadixToolbar from '@radix-ui/react-toolbar';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { EditorInFocus } from '../../core';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const Root: (props: RadixToolbar.ToolbarProps & React.RefAttributes<HTMLDivElement>) => React.JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* A toolbar button primitive.
|
|
10
|
+
*/
|
|
11
|
+
export declare const Button: React.ForwardRefExoticComponent<Omit<RadixToolbar.ToolbarButtonProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<object>>;
|
|
12
|
+
/**
|
|
13
|
+
* A toolbar button with a custom toolbar primitive.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ButtonWithTooltip: ({ title, children, ...props }: Omit<RadixToolbar.ToolbarButtonProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<object> & {
|
|
16
|
+
title: string;
|
|
17
|
+
}) => React.JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare const ToolbarToggleItem: React.ForwardRefExoticComponent<Omit<RadixToolbar.ToolbarToggleItemProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<object>>;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const SingleToggleGroup: React.ForwardRefExoticComponent<(Omit<RadixToolbar.ToolbarToggleGroupSingleProps & React.RefAttributes<HTMLDivElement>, "ref"> | Omit<RadixToolbar.ToolbarToggleGroupMultipleProps & React.RefAttributes<HTMLDivElement>, "ref">) & React.RefAttributes<object>>;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare const ToggleSingleGroupWithItem: React.ForwardRefExoticComponent<Omit<RadixToolbar.ToolbarToggleGroupSingleProps, "type"> & {
|
|
30
|
+
on: boolean;
|
|
31
|
+
title: string;
|
|
32
|
+
disabled?: boolean | undefined;
|
|
33
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
34
|
+
/**
|
|
35
|
+
* A toolbar primitive that allows you to build an UI with multiple non-exclusive toggle groups, like the bold/italic/underline toggle.
|
|
36
|
+
*/
|
|
37
|
+
export declare const MultipleChoiceToggleGroup: React.FC<{
|
|
38
|
+
items: {
|
|
39
|
+
title: string;
|
|
40
|
+
contents: React.ReactNode;
|
|
41
|
+
active: boolean;
|
|
42
|
+
onChange: (active: boolean) => void;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
}[];
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* The properties of the {@link SingleChoiceToggleGroup} React component.
|
|
48
|
+
*/
|
|
49
|
+
export interface SingleChoiceToggleGroupProps<T extends string> {
|
|
50
|
+
items: {
|
|
51
|
+
title: string;
|
|
52
|
+
value: T;
|
|
53
|
+
contents: React.ReactNode;
|
|
54
|
+
}[];
|
|
55
|
+
onChange: (value: T) => void;
|
|
56
|
+
value: T;
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A toolbar primitive that allows you to build an UI with multiple exclusive toggle groups, like the list type toggle.
|
|
61
|
+
*/
|
|
62
|
+
export declare const SingleChoiceToggleGroup: <T extends string>({ value, onChange, className, items }: SingleChoiceToggleGroupProps<T>) => React.JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* The properties of the {@link ButtonOrDropdownButton} React component.
|
|
65
|
+
*/
|
|
66
|
+
export interface ButtonOrDropdownButtonProps<T extends string> {
|
|
67
|
+
/**
|
|
68
|
+
* The contents of the button - usually an icon.
|
|
69
|
+
*/
|
|
70
|
+
children: React.ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* The title used for the tooltip.
|
|
73
|
+
*/
|
|
74
|
+
title: string;
|
|
75
|
+
/**
|
|
76
|
+
* The function to execute when the button is clicked or an item is chosen from the dropdown.
|
|
77
|
+
* If there is only one item in the dropdown, the value will be an empty string.
|
|
78
|
+
*/
|
|
79
|
+
onChoose: (value: T) => void;
|
|
80
|
+
/**
|
|
81
|
+
* The items to show in the dropdown.
|
|
82
|
+
*/
|
|
83
|
+
items: {
|
|
84
|
+
/**
|
|
85
|
+
* The value to pass to the `onChoose` function when this item is chosen.
|
|
86
|
+
*/
|
|
87
|
+
value: T;
|
|
88
|
+
/**
|
|
89
|
+
* The label to show in the dropdown.
|
|
90
|
+
*/
|
|
91
|
+
label: string;
|
|
92
|
+
}[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Use this primitive to create a toolbar button that can be either a button or a dropdown, depending on the number of items passed.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link ButtonOrDropdownButtonProps} for the properties of the React component.
|
|
98
|
+
*/
|
|
99
|
+
export declare const ButtonOrDropdownButton: <T extends string>(props: ButtonOrDropdownButtonProps<T>) => React.JSX.Element;
|
|
100
|
+
/**
|
|
101
|
+
* An object that describes a possible option to be displayed in the {@link ConditionalContents} component.
|
|
102
|
+
*/
|
|
103
|
+
export type ConditionalContentsOption = {
|
|
104
|
+
/**
|
|
105
|
+
* A function that returns `true` if the option should be displayed for the current editor in focus.
|
|
106
|
+
*/
|
|
107
|
+
when: (rootNode: EditorInFocus | null) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The contents to display if the `when` function returns `true`.
|
|
110
|
+
*/
|
|
111
|
+
contents: () => React.ReactNode;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* A default option to be displayed in the {@link ConditionalContents} component if none of the other options match.
|
|
115
|
+
*/
|
|
116
|
+
export type FallBackOption = {
|
|
117
|
+
/**
|
|
118
|
+
* The contents to display
|
|
119
|
+
*/
|
|
120
|
+
fallback: () => React.ReactNode;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The properties of the {@link ConditionalContents} React component.
|
|
124
|
+
*/
|
|
125
|
+
export interface ConditionalContentsProps {
|
|
126
|
+
/**
|
|
127
|
+
* A set of options that define the contents to show based on the editor that is in focus.
|
|
128
|
+
* Can be either a {@link ConditionalContentsOption} or a {@link FallBackOption}.
|
|
129
|
+
* See the {@link ConditionalContents} documentation for an example.
|
|
130
|
+
*/
|
|
131
|
+
options: (ConditionalContentsOption | FallBackOption)[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A toolbar primitive that allows you to show different contents based on the editor that is in focus.
|
|
135
|
+
* Useful for code editors that have different features and don't support rich text formatting.
|
|
136
|
+
* @example
|
|
137
|
+
* ```tsx
|
|
138
|
+
* <ConditionalContents
|
|
139
|
+
* options={[
|
|
140
|
+
* { when: (editor) => editor?.editorType === 'codeblock', contents: () => <ChangeCodeMirrorLanguage /> },
|
|
141
|
+
* { when: (editor) => editor?.editorType === 'sandpack', contents: () => <ShowSandpackInfo /> },
|
|
142
|
+
* {
|
|
143
|
+
* fallback: () => (
|
|
144
|
+
* <>
|
|
145
|
+
* <UndoRedo />
|
|
146
|
+
* <BoldItalicUnderlineToggles />
|
|
147
|
+
* <InsertCodeBlock />
|
|
148
|
+
* </>
|
|
149
|
+
* )
|
|
150
|
+
* }
|
|
151
|
+
* ]}
|
|
152
|
+
* />
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare const ConditionalContents: React.FC<ConditionalContentsProps>;
|
|
156
|
+
/**
|
|
157
|
+
* A toolbar primitive that allows you to show a separator between toolbar items.
|
|
158
|
+
* By default, the separator is styled as vertical line.
|
|
159
|
+
*/
|
|
160
|
+
export declare const Separator: React.ForwardRefExoticComponent<RadixToolbar.ToolbarSeparatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as RadixSelect from "@radix-ui/react-select";
|
|
2
|
+
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import React__default from "react";
|
|
5
|
+
import styles from "../../../styles/ui.module.css.js";
|
|
6
|
+
import { TooltipWrap } from "./TooltipWrap.js";
|
|
7
|
+
import { SelectButtonTrigger, SelectContent, SelectItem } from "./select.js";
|
|
8
|
+
import { corePluginHooks } from "../../core/index.js";
|
|
9
|
+
function decorate(Component, decoratedProps) {
|
|
10
|
+
return (props) => {
|
|
11
|
+
const className = classNames(decoratedProps.className, props.className);
|
|
12
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...decoratedProps, ...props, className });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function decorateWithRef(Component, decoratedProps) {
|
|
16
|
+
return React__default.forwardRef((props, ref) => {
|
|
17
|
+
const className = classNames(decoratedProps.className, props.className);
|
|
18
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...decoratedProps, ...props, className, ref });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function addTooltipToChildren(Component) {
|
|
22
|
+
return ({ title, children, ...props }) => {
|
|
23
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...props }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, children));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const Root = decorate(RadixToolbar.Root, { className: styles.toolbarRoot });
|
|
27
|
+
const Button = decorateWithRef(RadixToolbar.Button, { className: styles.toolbarButton, "data-toolbar-item": true });
|
|
28
|
+
const ButtonWithTooltip = addTooltipToChildren(Button);
|
|
29
|
+
const ToolbarToggleItem = decorateWithRef(RadixToolbar.ToggleItem, {
|
|
30
|
+
className: styles.toolbarToggleItem,
|
|
31
|
+
"data-toolbar-item": true
|
|
32
|
+
});
|
|
33
|
+
const SingleToggleGroup = decorateWithRef(RadixToolbar.ToggleGroup, {
|
|
34
|
+
type: "single",
|
|
35
|
+
className: styles.toolbarToggleSingleGroup
|
|
36
|
+
});
|
|
37
|
+
const ToggleSingleGroupWithItem = React__default.forwardRef(({ on, title, children, disabled, ...props }, forwardedRef) => {
|
|
38
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
39
|
+
RadixToolbar.ToggleGroup,
|
|
40
|
+
{
|
|
41
|
+
type: "single",
|
|
42
|
+
className: styles.toolbarToggleSingleGroup,
|
|
43
|
+
...props,
|
|
44
|
+
value: on ? "on" : "off",
|
|
45
|
+
ref: forwardedRef
|
|
46
|
+
},
|
|
47
|
+
/* @__PURE__ */ React__default.createElement(ToolbarToggleItem, { title, value: "on", disabled }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title }, children))
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
const MultipleChoiceToggleGroup = ({ items }) => {
|
|
51
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.toolbarGroupOfGroups }, items.map((item, index) => /* @__PURE__ */ React__default.createElement(
|
|
52
|
+
ToggleSingleGroupWithItem,
|
|
53
|
+
{
|
|
54
|
+
key: index,
|
|
55
|
+
title: item.title,
|
|
56
|
+
on: item.active,
|
|
57
|
+
onValueChange: (v) => item.onChange(v === "on"),
|
|
58
|
+
disabled: item.disabled
|
|
59
|
+
},
|
|
60
|
+
item.contents
|
|
61
|
+
)));
|
|
62
|
+
};
|
|
63
|
+
const SingleChoiceToggleGroup = ({ value, onChange, className, items }) => {
|
|
64
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.toolbarGroupOfGroups }, /* @__PURE__ */ React__default.createElement(
|
|
65
|
+
RadixToolbar.ToggleGroup,
|
|
66
|
+
{
|
|
67
|
+
type: "single",
|
|
68
|
+
className: classNames(styles.toolbarToggleSingleGroup, className),
|
|
69
|
+
onValueChange: onChange,
|
|
70
|
+
value: value || "",
|
|
71
|
+
onFocus: (e) => e.preventDefault()
|
|
72
|
+
},
|
|
73
|
+
items.map((item, index) => /* @__PURE__ */ React__default.createElement(ToolbarToggleItem, { key: index, value: item.value }, /* @__PURE__ */ React__default.createElement(TooltipWrap, { title: item.title }, item.contents)))
|
|
74
|
+
));
|
|
75
|
+
};
|
|
76
|
+
const ButtonOrDropdownButton = (props) => {
|
|
77
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, props.items.length === 1 ? /* @__PURE__ */ React__default.createElement(ButtonWithTooltip, { title: props.title, onClick: () => props.onChoose("") }, 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)))));
|
|
78
|
+
};
|
|
79
|
+
function isConditionalContentsOption(option) {
|
|
80
|
+
return Object.hasOwn(option, "when");
|
|
81
|
+
}
|
|
82
|
+
const ConditionalContents = ({ options }) => {
|
|
83
|
+
const [editorInFocus] = corePluginHooks.useEmitterValues("editorInFocus");
|
|
84
|
+
const contents = React__default.useMemo(() => {
|
|
85
|
+
const option = options.find((option2) => {
|
|
86
|
+
if (isConditionalContentsOption(option2)) {
|
|
87
|
+
if (option2.when(editorInFocus)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return option ? isConditionalContentsOption(option) ? option.contents() : option.fallback() : null;
|
|
95
|
+
}, [options, editorInFocus]);
|
|
96
|
+
return /* @__PURE__ */ React__default.createElement("div", { style: { display: "flex" } }, contents);
|
|
97
|
+
};
|
|
98
|
+
const Separator = RadixToolbar.Separator;
|
|
99
|
+
export {
|
|
100
|
+
Button,
|
|
101
|
+
ButtonOrDropdownButton,
|
|
102
|
+
ButtonWithTooltip,
|
|
103
|
+
ConditionalContents,
|
|
104
|
+
MultipleChoiceToggleGroup,
|
|
105
|
+
Root,
|
|
106
|
+
Separator,
|
|
107
|
+
SingleChoiceToggleGroup,
|
|
108
|
+
SingleToggleGroup,
|
|
109
|
+
ToggleSingleGroupWithItem,
|
|
110
|
+
ToolbarToggleItem
|
|
111
|
+
};
|