reactjs-tiptap-editor-pro 0.2.28 → 0.2.30
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/package.json +4 -60
- package/src/components/ActionButton.tsx +103 -0
- package/src/components/ActionMenuButton.tsx +76 -0
- package/src/components/BubbleMenu.tsx +93 -0
- package/src/components/CharactorCount.tsx +50 -0
- package/src/components/ColorPicker.tsx +272 -0
- package/src/components/RichTextEditor.tsx +212 -0
- package/src/components/SizeSetter/SizeSetter.tsx +102 -0
- package/src/components/Toolbar.tsx +108 -0
- package/src/components/icons/Activity.tsx +19 -0
- package/src/components/icons/Animas.tsx +24 -0
- package/src/components/icons/AspectRatio.tsx +13 -0
- package/src/components/icons/Blockquote.tsx +17 -0
- package/src/components/icons/ColumnAddLeft.tsx +7 -0
- package/src/components/icons/ColumnAddRight.tsx +7 -0
- package/src/components/icons/DeleteColumn.tsx +26 -0
- package/src/components/icons/DeleteRow.tsx +26 -0
- package/src/components/icons/Direction.tsx +7 -0
- package/src/components/icons/Excalidraw.tsx +7 -0
- package/src/components/icons/ExportPdf.tsx +8 -0
- package/src/components/icons/ExportWord.tsx +24 -0
- package/src/components/icons/FileWordOutline.tsx +13 -0
- package/src/components/icons/Flag.tsx +19 -0
- package/src/components/icons/Food.tsx +20 -0
- package/src/components/icons/GIfIcon.tsx +10 -0
- package/src/components/icons/Icon.tsx +30 -0
- package/src/components/icons/ImportWord.tsx +23 -0
- package/src/components/icons/LeftToRight.tsx +7 -0
- package/src/components/icons/LineHeight.tsx +13 -0
- package/src/components/icons/MenuDown.tsx +24 -0
- package/src/components/icons/Mermaid.tsx +13 -0
- package/src/components/icons/NoFill.tsx +7 -0
- package/src/components/icons/Object.tsx +24 -0
- package/src/components/icons/RightToLeft.tsx +7 -0
- package/src/components/icons/SizeL.tsx +9 -0
- package/src/components/icons/SizeM.tsx +13 -0
- package/src/components/icons/SizeS.tsx +13 -0
- package/src/components/icons/Symbol.tsx +19 -0
- package/src/components/icons/Travel.tsx +24 -0
- package/src/components/icons/Twitter.tsx +7 -0
- package/src/components/icons/icons.ts +212 -0
- package/src/components/icons/index.ts +12 -0
- package/src/components/index.ts +9 -0
- package/src/components/menus/bubble.ts +395 -0
- package/src/components/menus/components/BubbleMenuContent.tsx +15 -0
- package/src/components/menus/components/BubbleMenuDrawer.tsx +128 -0
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +91 -0
- package/src/components/menus/components/BubbleMenuIframe.tsx +143 -0
- package/src/components/menus/components/BubbleMenuKatex.tsx +136 -0
- package/src/components/menus/components/BubbleMenuLink.tsx +99 -0
- package/src/components/menus/components/BubbleMenuMedia.tsx +235 -0
- package/src/components/menus/components/BubbleMenuMermaid.tsx +128 -0
- package/src/components/menus/components/BubbleMenuText.tsx +102 -0
- package/src/components/menus/components/BubbleMenuTwitter.tsx +91 -0
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +59 -0
- package/src/components/menus/components/ContentMenu.tsx +396 -0
- package/src/components/menus/components/TableBubbleMenu.tsx +362 -0
- package/src/components/menus/index.ts +7 -0
- package/src/components/ui/button.tsx +56 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/dialog.tsx +128 -0
- package/src/components/ui/dropdown-menu.tsx +203 -0
- package/src/components/ui/emoji-picker.tsx +166 -0
- package/src/components/ui/index.ts +14 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/select.tsx +162 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/toast.tsx +129 -0
- package/src/components/ui/toaster.tsx +44 -0
- package/src/components/ui/toggle.tsx +45 -0
- package/src/components/ui/tooltip.tsx +30 -0
- package/src/components/ui/use-toast.ts +197 -0
- package/src/constants/index.ts +223 -0
- package/src/constants/resetCSS.ts +139 -0
- package/src/extension-bundle.ts +2 -0
- package/src/extensions/Attachment/Attachment.ts +144 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +69 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +28 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +155 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +23 -0
- package/src/extensions/Attachment/index.ts +1 -0
- package/src/extensions/BaseKit.ts +253 -0
- package/src/extensions/Blockquote/Blockquote.ts +31 -0
- package/src/extensions/Blockquote/index.ts +1 -0
- package/src/extensions/Bold/Bold.ts +26 -0
- package/src/extensions/Bold/index.ts +1 -0
- package/src/extensions/BulletList/BulletList.ts +28 -0
- package/src/extensions/BulletList/index.ts +1 -0
- package/src/extensions/Clear/Clear.ts +24 -0
- package/src/extensions/Clear/index.ts +1 -0
- package/src/extensions/Code/Code.ts +26 -0
- package/src/extensions/Code/index.ts +1 -0
- package/src/extensions/CodeBlock/CodeBlock.ts +54 -0
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +66 -0
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +89 -0
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +81 -0
- package/src/extensions/CodeBlock/highlighter.ts +132 -0
- package/src/extensions/CodeBlock/index.ts +1 -0
- package/src/extensions/CodeBlock/shiki-plugin.ts +213 -0
- package/src/extensions/Color/Color.ts +52 -0
- package/src/extensions/Color/components/ColorActionButton.tsx +104 -0
- package/src/extensions/Color/index.ts +1 -0
- package/src/extensions/Document/Document.ts +8 -0
- package/src/extensions/Document/index.ts +1 -0
- package/src/extensions/Drawer/Drawer.ts +177 -0
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +85 -0
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +598 -0
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +500 -0
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +239 -0
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +238 -0
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +260 -0
- package/src/extensions/Drawer/index.ts +1 -0
- package/src/extensions/Emoji/Emoji.ts +146 -0
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +103 -0
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +1858 -0
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +61 -0
- package/src/extensions/Emoji/index.ts +1 -0
- package/src/extensions/Excalidraw/Excalidraw.ts +123 -0
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +138 -0
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +178 -0
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +43 -0
- package/src/extensions/Excalidraw/index.ts +1 -0
- package/src/extensions/ExportPdf/ExportPdf.ts +25 -0
- package/src/extensions/ExportPdf/index.ts +1 -0
- package/src/extensions/ExportWord/ExportWord.ts +87 -0
- package/src/extensions/ExportWord/index.ts +1 -0
- package/src/extensions/FontFamily/FontFamily.ts +64 -0
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +97 -0
- package/src/extensions/FontFamily/index.ts +1 -0
- package/src/extensions/FontSize/FontSize.ts +119 -0
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +84 -0
- package/src/extensions/FontSize/index.ts +1 -0
- package/src/extensions/FormatPainter/FormatPainter.ts +121 -0
- package/src/extensions/FormatPainter/index.ts +1 -0
- package/src/extensions/Heading/Heading.ts +57 -0
- package/src/extensions/Heading/components/HeadingButton.tsx +96 -0
- package/src/extensions/Heading/index.ts +1 -0
- package/src/extensions/Highlight/Highlight.ts +36 -0
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +108 -0
- package/src/extensions/Highlight/index.ts +1 -0
- package/src/extensions/History/History.ts +39 -0
- package/src/extensions/History/components/HistoryActionButton.tsx +74 -0
- package/src/extensions/History/index.ts +1 -0
- package/src/extensions/HorizontalRule/HorizontalRule.ts +42 -0
- package/src/extensions/HorizontalRule/index.ts +1 -0
- package/src/extensions/Iframe/Iframe.ts +140 -0
- package/src/extensions/Iframe/components/IframeNodeView.tsx +92 -0
- package/src/extensions/Iframe/components/index.module.scss +40 -0
- package/src/extensions/Iframe/embed.ts +487 -0
- package/src/extensions/Iframe/index.ts +1 -0
- package/src/extensions/Image/Image.ts +303 -0
- package/src/extensions/Image/components/ActionImageButton.tsx +186 -0
- package/src/extensions/Image/components/ImageCropper.tsx +198 -0
- package/src/extensions/Image/components/ImageView.tsx +271 -0
- package/src/extensions/Image/index.ts +1 -0
- package/src/extensions/Image/store.ts +15 -0
- package/src/extensions/ImageGif/ImageGif.ts +176 -0
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +138 -0
- package/src/extensions/ImageGif/components/ImageGifView.tsx +260 -0
- package/src/extensions/ImageGif/index.ts +1 -0
- package/src/extensions/ImportWord/ImportWord.ts +52 -0
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +151 -0
- package/src/extensions/ImportWord/index.ts +1 -0
- package/src/extensions/Indent/Indent.ts +110 -0
- package/src/extensions/Indent/index.ts +1 -0
- package/src/extensions/Italic/Italic.ts +29 -0
- package/src/extensions/Italic/index.ts +1 -0
- package/src/extensions/Katex/Katex.ts +109 -0
- package/src/extensions/Katex/components/KatexActiveButton.tsx +117 -0
- package/src/extensions/Katex/components/KatexWrapper.tsx +53 -0
- package/src/extensions/Katex/index.ts +1 -0
- package/src/extensions/LineHeight/LineHeight.ts +76 -0
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +93 -0
- package/src/extensions/LineHeight/index.ts +1 -0
- package/src/extensions/Link/Link.ts +92 -0
- package/src/extensions/Link/components/LinkEditBlock.tsx +110 -0
- package/src/extensions/Link/components/LinkEditPopover.tsx +46 -0
- package/src/extensions/Link/components/LinkViewBlock.tsx +54 -0
- package/src/extensions/Link/index.ts +1 -0
- package/src/extensions/ListItem/ListItem.ts +1 -0
- package/src/extensions/ListItem/index.ts +1 -0
- package/src/extensions/Mention/Mention.ts +100 -0
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +94 -0
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +38 -0
- package/src/extensions/Mention/index.ts +1 -0
- package/src/extensions/Mermaid/Mermaid.ts +177 -0
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +155 -0
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +151 -0
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +260 -0
- package/src/extensions/Mermaid/index.ts +1 -0
- package/src/extensions/MoreMark/MoreMark.ts +102 -0
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +97 -0
- package/src/extensions/MoreMark/index.ts +1 -0
- package/src/extensions/MultiColumn/Column.ts +36 -0
- package/src/extensions/MultiColumn/MultiColumn.ts +111 -0
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +22 -0
- package/src/extensions/MultiColumn/index.ts +3 -0
- package/src/extensions/OrderedList/OrderedList.ts +28 -0
- package/src/extensions/OrderedList/index.ts +1 -0
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +395 -0
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +190 -0
- package/src/extensions/SearchAndReplace/index.ts +1 -0
- package/src/extensions/Selection/Selection.ts +32 -0
- package/src/extensions/Selection/index.ts +1 -0
- package/src/extensions/SlashCommand/SlashCommand.ts +255 -0
- package/src/extensions/SlashCommand/components/CommandsList.tsx +180 -0
- package/src/extensions/SlashCommand/groups.ts +183 -0
- package/src/extensions/SlashCommand/index.ts +1 -0
- package/src/extensions/SlashCommand/types.ts +24 -0
- package/src/extensions/Strike/Strike.ts +26 -0
- package/src/extensions/Strike/index.ts +1 -0
- package/src/extensions/Subscript/Subscript.ts +88 -0
- package/src/extensions/Subscript/index.ts +1 -0
- package/src/extensions/Table/Cell.ts +131 -0
- package/src/extensions/Table/Header.ts +93 -0
- package/src/extensions/Table/Row.ts +8 -0
- package/src/extensions/Table/Table.ts +60 -0
- package/src/extensions/Table/cell-background.ts +112 -0
- package/src/extensions/Table/components/CreateTablePopover.tsx +132 -0
- package/src/extensions/Table/components/TableActionButton.tsx +42 -0
- package/src/extensions/Table/index.ts +6 -0
- package/src/extensions/Table/utils.ts +352 -0
- package/src/extensions/TableOfContent/TableOfContent.ts +124 -0
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +116 -0
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +27 -0
- package/src/extensions/TableOfContent/components/index.module.scss +40 -0
- package/src/extensions/TableOfContent/index.ts +1 -0
- package/src/extensions/TaskList/TaskList.ts +46 -0
- package/src/extensions/TaskList/index.ts +1 -0
- package/src/extensions/TextAlign/TextAlign.ts +68 -0
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +103 -0
- package/src/extensions/TextAlign/index.ts +1 -0
- package/src/extensions/TextBubble/TextBubble.ts +22 -0
- package/src/extensions/TextBubble/components/TextDropdown.tsx +146 -0
- package/src/extensions/TextBubble/index.ts +1 -0
- package/src/extensions/TextDirection/TextDirection.ts +97 -0
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +103 -0
- package/src/extensions/TextDirection/index.ts +1 -0
- package/src/extensions/TrailingNode/TrailingNode.ts +71 -0
- package/src/extensions/TrailingNode/index.ts +1 -0
- package/src/extensions/Twitter/Twitter.ts +161 -0
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +68 -0
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +30 -0
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +41 -0
- package/src/extensions/Twitter/index.ts +1 -0
- package/src/extensions/UnderLine/Underline.ts +30 -0
- package/src/extensions/UnderLine/index.ts +1 -0
- package/src/extensions/Video/Video.ts +204 -0
- package/src/extensions/Video/components/ActiveVideoButton.tsx +191 -0
- package/src/extensions/Video/index.ts +1 -0
- package/src/extensions/Video/store.ts +15 -0
- package/src/extensions/index.ts +122 -0
- package/src/hooks/useActive.tsx +24 -0
- package/src/hooks/useAttributes.tsx +45 -0
- package/src/hooks/useCopy.tsx +20 -0
- package/src/hooks/useEditorState.tsx +23 -0
- package/src/hooks/useExtension.tsx +29 -0
- package/src/index.ts +8 -0
- package/src/lib/utils.ts +7 -0
- package/src/locale-bundle.ts +3 -0
- package/src/locales/en.ts +173 -0
- package/src/locales/hu.ts +173 -0
- package/src/locales/index.tsx +163 -0
- package/src/locales/pt-br.ts +173 -0
- package/src/locales/vi.ts +173 -0
- package/src/locales/zh-cn.ts +173 -0
- package/src/plugins/DragHandle/index.ts +375 -0
- package/src/plugins/DragHandle/range.ts +114 -0
- package/src/plugins/DragHandle/utils.ts +80 -0
- package/src/plugins/image-upload.ts +160 -0
- package/src/store/ProviderRichText.tsx +53 -0
- package/src/store/editableEditor.ts +15 -0
- package/src/store/fast-context.tsx +70 -0
- package/src/store/store.ts +35 -0
- package/src/styles/ProseMirror.scss +176 -0
- package/src/styles/columns.scss +23 -0
- package/src/styles/editor.scss +411 -0
- package/src/styles/global.scss +87 -0
- package/src/styles/index.scss +5 -0
- package/src/styles/mention.scss +6 -0
- package/src/theme/theme.ts +15 -0
- package/src/types.ts +271 -0
- package/src/utils/_event.ts +55 -0
- package/src/utils/color.ts +67 -0
- package/src/utils/columns.ts +142 -0
- package/src/utils/customEvents/customEvents.ts +18 -0
- package/src/utils/customEvents/events.constant.ts +11 -0
- package/src/utils/delete-node.ts +46 -0
- package/src/utils/dom-dataset.ts +121 -0
- package/src/utils/download.ts +17 -0
- package/src/utils/dynamicCSS.ts +192 -0
- package/src/utils/editor-container-size.ts +28 -0
- package/src/utils/file.ts +112 -0
- package/src/utils/getRenderContainer.ts +41 -0
- package/src/utils/indent.ts +99 -0
- package/src/utils/is-mobile.ts +57 -0
- package/src/utils/json.ts +18 -0
- package/src/utils/line-height.ts +109 -0
- package/src/utils/lru-cache.ts +145 -0
- package/src/utils/mitt.ts +114 -0
- package/src/utils/node.ts +92 -0
- package/src/utils/pdf.ts +72 -0
- package/src/utils/plateform.ts +49 -0
- package/src/utils/shortId.ts +5 -0
- package/src/utils/storage.ts +18 -0
- package/src/utils/utils.ts +71 -0
- package/src/vite-env.d.ts +3 -0
- package/lib/RichTextEditor-BC85Dn21.js +0 -8826
- package/lib/RichTextEditor-Cxm0yJdr.cjs +0 -141
- package/lib/extension-bundle.cjs +0 -33
- package/lib/extension-bundle.d.cts +0 -947
- package/lib/extension-bundle.d.ts +0 -947
- package/lib/extension-bundle.js +0 -5755
- package/lib/index-DV-nXpU1.cjs +0 -1
- package/lib/index-M6H3FoBi.js +0 -1147
- package/lib/index.cjs +0 -1
- package/lib/index.d.cts +0 -511
- package/lib/index.d.ts +0 -511
- package/lib/index.js +0 -16
- package/lib/locale-bundle.cjs +0 -1
- package/lib/locale-bundle.d.cts +0 -1140
- package/lib/locale-bundle.d.ts +0 -1140
- package/lib/locale-bundle.js +0 -9
- package/lib/style.css +0 -1
- package/lib/tiptap-DkWHMWDt.js +0 -6061
- package/lib/tiptap-gBG-1T-V.cjs +0 -116
- package/lib/vendor-BJ0Yf78E.cjs +0 -8114
- package/lib/vendor-Cpa6z-M0.js +0 -67575
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import deepEqual from 'deep-equal';
|
|
4
|
+
|
|
5
|
+
import { ActionButton, Button, IconComponent, Input, Label, Popover, PopoverContent, PopoverTrigger, Switch } from '@/components';
|
|
6
|
+
import { SearchAndReplace } from '@/extensions/SearchAndReplace/SearchAndReplace';
|
|
7
|
+
import { useLocale } from '@/locales';
|
|
8
|
+
import { listenEvent } from '@/utils/customEvents/customEvents';
|
|
9
|
+
import { EVENTS } from '@/utils/customEvents/events.constant';
|
|
10
|
+
|
|
11
|
+
function SearchAndReplaceButton({ editor, ...props }: any) {
|
|
12
|
+
const { t } = useLocale();
|
|
13
|
+
|
|
14
|
+
const [currentIndex, setCurrentIndex] = useState(-1);
|
|
15
|
+
const [results, setResults] = useState([]);
|
|
16
|
+
const [searchValue, setSearchValue] = useState('');
|
|
17
|
+
const [replaceValue, setReplaceValue] = useState('');
|
|
18
|
+
const [visible, setVisible] = useState(false);
|
|
19
|
+
const [caseSensitive, setCaseSensitive] = useState(false);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!visible) {
|
|
23
|
+
setSearchValue('');
|
|
24
|
+
setReplaceValue('');
|
|
25
|
+
setCurrentIndex(-1);
|
|
26
|
+
setResults([]);
|
|
27
|
+
|
|
28
|
+
editor.commands.setSearchTerm('');
|
|
29
|
+
editor.commands.setReplaceTerm('');
|
|
30
|
+
}
|
|
31
|
+
}, [editor, visible]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!visible)
|
|
35
|
+
return;
|
|
36
|
+
if (editor && editor.commands && editor.commands.setSearchTerm) {
|
|
37
|
+
editor.commands.setSearchTerm(searchValue);
|
|
38
|
+
}
|
|
39
|
+
}, [visible, searchValue, editor]);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!visible)
|
|
43
|
+
return;
|
|
44
|
+
if (editor && editor.commands && editor.commands.setReplaceTerm) {
|
|
45
|
+
editor.commands.setReplaceTerm(replaceValue);
|
|
46
|
+
}
|
|
47
|
+
}, [visible, replaceValue, editor]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!editor)
|
|
51
|
+
return;
|
|
52
|
+
|
|
53
|
+
const searchExtension = editor.extensionManager.extensions.find((ext: any) => ext.name === SearchAndReplace.name);
|
|
54
|
+
|
|
55
|
+
if (!searchExtension)
|
|
56
|
+
return;
|
|
57
|
+
|
|
58
|
+
const listener = () => {
|
|
59
|
+
if (!visible)
|
|
60
|
+
return;
|
|
61
|
+
|
|
62
|
+
const currentIndex = searchExtension ? searchExtension.storage.currentIndex : -1;
|
|
63
|
+
const results = searchExtension ? searchExtension.storage.results : [];
|
|
64
|
+
setCurrentIndex(preIndex => (preIndex !== currentIndex ? currentIndex : preIndex));
|
|
65
|
+
setResults(prevResults => (deepEqual(prevResults, results) ? prevResults : results));
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
listenEvent(EVENTS.SEARCH_REPLCE, listener);
|
|
69
|
+
|
|
70
|
+
return () => {
|
|
71
|
+
if (!searchExtension)
|
|
72
|
+
return;
|
|
73
|
+
listenEvent(EVENTS.SEARCH_REPLCE, listener);
|
|
74
|
+
};
|
|
75
|
+
}, [visible, editor]);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Popover
|
|
79
|
+
onOpenChange={setVisible}
|
|
80
|
+
open={visible}
|
|
81
|
+
>
|
|
82
|
+
<PopoverTrigger
|
|
83
|
+
asChild
|
|
84
|
+
disabled={props?.disabled}
|
|
85
|
+
>
|
|
86
|
+
<ActionButton
|
|
87
|
+
disabled={props?.disabled}
|
|
88
|
+
isActive={props?.isActive}
|
|
89
|
+
tooltip={props?.tooltip}
|
|
90
|
+
>
|
|
91
|
+
<IconComponent name={props?.icon} />
|
|
92
|
+
</ActionButton>
|
|
93
|
+
</PopoverTrigger>
|
|
94
|
+
|
|
95
|
+
<PopoverContent
|
|
96
|
+
align="start"
|
|
97
|
+
className="w-full"
|
|
98
|
+
hideWhenDetached
|
|
99
|
+
side="bottom"
|
|
100
|
+
>
|
|
101
|
+
|
|
102
|
+
<div className="mb-[6px] flex items-center justify-between">
|
|
103
|
+
<Label>
|
|
104
|
+
{t('editor.search.dialog.text')}
|
|
105
|
+
</Label>
|
|
106
|
+
|
|
107
|
+
<span className="font-semibold">
|
|
108
|
+
{results.length > 0 ? `${currentIndex + 1}/${results.length}` : '0/0'}
|
|
109
|
+
</span>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div className="mb-[10px] flex w-full max-w-sm items-center gap-1.5">
|
|
113
|
+
<Input
|
|
114
|
+
autoFocus
|
|
115
|
+
className="w-full"
|
|
116
|
+
onChange={e => setSearchValue(e.target.value)}
|
|
117
|
+
placeholder="Text"
|
|
118
|
+
required
|
|
119
|
+
type="text"
|
|
120
|
+
value={searchValue}
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
<Button className="flex-1"
|
|
124
|
+
disabled={results.length === 0}
|
|
125
|
+
onClick={editor.commands.goToPrevSearchResult}
|
|
126
|
+
>
|
|
127
|
+
<IconComponent name="ChevronUp" />
|
|
128
|
+
</Button>
|
|
129
|
+
|
|
130
|
+
<Button className="flex-1"
|
|
131
|
+
disabled={results.length === 0}
|
|
132
|
+
onClick={editor.commands.goToNextSearchResult}
|
|
133
|
+
>
|
|
134
|
+
<IconComponent name="ChevronDown" />
|
|
135
|
+
</Button>
|
|
136
|
+
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<Label className="mb-[6px]">
|
|
140
|
+
{t('editor.replace.dialog.text')}
|
|
141
|
+
</Label>
|
|
142
|
+
|
|
143
|
+
<div className="mb-[5px] flex w-full max-w-sm items-center gap-1.5">
|
|
144
|
+
<div className="relative w-full max-w-sm items-center">
|
|
145
|
+
<Input
|
|
146
|
+
className="w-80"
|
|
147
|
+
onChange={e => setReplaceValue(e.target.value)}
|
|
148
|
+
placeholder="Text"
|
|
149
|
+
required
|
|
150
|
+
type="text"
|
|
151
|
+
value={replaceValue}
|
|
152
|
+
/>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div className="mb-[10px] flex items-center space-x-2">
|
|
157
|
+
<Switch
|
|
158
|
+
checked={caseSensitive}
|
|
159
|
+
onCheckedChange={(e: any) => {
|
|
160
|
+
setCaseSensitive(e);
|
|
161
|
+
editor.commands.setCaseSensitive(e);
|
|
162
|
+
}}
|
|
163
|
+
/>
|
|
164
|
+
|
|
165
|
+
<Label>
|
|
166
|
+
{t('editor.replace.caseSensitive')}
|
|
167
|
+
</Label>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div className="flex items-center gap-[10px]">
|
|
171
|
+
<Button className="flex-1"
|
|
172
|
+
disabled={results.length === 0}
|
|
173
|
+
onClick={editor.commands.replace}
|
|
174
|
+
>
|
|
175
|
+
{t('editor.replace.dialog.text')}
|
|
176
|
+
</Button>
|
|
177
|
+
|
|
178
|
+
<Button className="flex-1"
|
|
179
|
+
disabled={results.length === 0}
|
|
180
|
+
onClick={editor.commands.replaceAll}
|
|
181
|
+
>
|
|
182
|
+
{t('editor.replaceAll.dialog.text')}
|
|
183
|
+
</Button>
|
|
184
|
+
</div>
|
|
185
|
+
</PopoverContent>
|
|
186
|
+
</Popover>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export default SearchAndReplaceButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SearchAndReplace';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
4
|
+
|
|
5
|
+
export const Selection = Extension.create({
|
|
6
|
+
name: 'selection',
|
|
7
|
+
addProseMirrorPlugins() {
|
|
8
|
+
const { editor } = this;
|
|
9
|
+
return [
|
|
10
|
+
new Plugin({
|
|
11
|
+
key: new PluginKey('selection'),
|
|
12
|
+
props: {
|
|
13
|
+
decorations(state) {
|
|
14
|
+
if (state.selection.empty) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (editor.isFocused === true) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return DecorationSet.create(state.doc, [
|
|
21
|
+
Decoration.inline(state.selection.from, state.selection.to, {
|
|
22
|
+
class: 'selection',
|
|
23
|
+
}),
|
|
24
|
+
]);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export default Selection;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Selection';
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { Editor, Extensions, Range } from '@tiptap/core';
|
|
2
|
+
import { Extension } from '@tiptap/core';
|
|
3
|
+
import { PluginKey } from '@tiptap/pm/state';
|
|
4
|
+
import { ReactRenderer } from '@tiptap/react';
|
|
5
|
+
import type { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion';
|
|
6
|
+
import Suggestion from '@tiptap/suggestion';
|
|
7
|
+
import tippy from 'tippy.js';
|
|
8
|
+
|
|
9
|
+
import CommandsList from '@/extensions/SlashCommand/components/CommandsList';
|
|
10
|
+
|
|
11
|
+
import { renderGroups } from './groups';
|
|
12
|
+
import { type Group } from './types';
|
|
13
|
+
|
|
14
|
+
export interface SlashCommandOptions {
|
|
15
|
+
renderGroupItem?: (extension: Extensions[number], groups:Group[]) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const extensionName = 'slashCommand';
|
|
19
|
+
let popup: any;
|
|
20
|
+
export const SlashCommand = Extension.create<SlashCommandOptions>({
|
|
21
|
+
name: extensionName,
|
|
22
|
+
priority: 200,
|
|
23
|
+
onCreate() {
|
|
24
|
+
popup = tippy('body', {
|
|
25
|
+
interactive: true,
|
|
26
|
+
trigger: 'manual',
|
|
27
|
+
placement: 'bottom-start',
|
|
28
|
+
theme: 'slash-command',
|
|
29
|
+
maxWidth: '16rem',
|
|
30
|
+
offset: [16, 8],
|
|
31
|
+
popperOptions: {
|
|
32
|
+
strategy: 'fixed',
|
|
33
|
+
modifiers: [
|
|
34
|
+
{
|
|
35
|
+
name: 'flip',
|
|
36
|
+
enabled: false,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
addProseMirrorPlugins() {
|
|
44
|
+
return [
|
|
45
|
+
Suggestion({
|
|
46
|
+
editor: this.editor,
|
|
47
|
+
char: '/',
|
|
48
|
+
allowSpaces: true,
|
|
49
|
+
startOfLine: true,
|
|
50
|
+
pluginKey: new PluginKey(extensionName),
|
|
51
|
+
allow: ({ state, range }) => {
|
|
52
|
+
const $from = state.doc.resolve(range.from);
|
|
53
|
+
const isRootDepth = $from.depth === 1;
|
|
54
|
+
const isParagraph = $from.parent.type.name === 'paragraph';
|
|
55
|
+
const isStartOfNode = $from.parent.textContent?.charAt(0) === '/';
|
|
56
|
+
// TODO 行列内
|
|
57
|
+
const isInColumn = this.editor.isActive('column');
|
|
58
|
+
const afterContent = $from.parent.textContent?.slice(
|
|
59
|
+
Math.max(0, $from.parent.textContent?.indexOf('/')),
|
|
60
|
+
);
|
|
61
|
+
const isValidAfterContent = !afterContent?.endsWith(' ');
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
((isRootDepth && isParagraph && isStartOfNode)
|
|
65
|
+
|| (isInColumn && isParagraph && isStartOfNode))
|
|
66
|
+
&& isValidAfterContent
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
command: ({ editor, range, props }: { editor: Editor, range: Range, props: any }) => {
|
|
70
|
+
const { view } = editor;
|
|
71
|
+
props.action({ editor, range });
|
|
72
|
+
view.focus();
|
|
73
|
+
},
|
|
74
|
+
items: ({ query, editor }: { query: string, editor: Editor }) => {
|
|
75
|
+
// get options
|
|
76
|
+
// Filter commands
|
|
77
|
+
const groups = renderGroups(editor.extensionManager.extensions, this.options.renderGroupItem);
|
|
78
|
+
const withFilteredCommands = groups.map(group => ({
|
|
79
|
+
...group,
|
|
80
|
+
commands: group.commands
|
|
81
|
+
.filter((item) => {
|
|
82
|
+
const labelNormalized = item.label.toLowerCase().trim();
|
|
83
|
+
const queryNormalized = query.toLowerCase().trim();
|
|
84
|
+
|
|
85
|
+
if (item.aliases) {
|
|
86
|
+
const aliases = item.aliases.map(alias => alias.toLowerCase().trim());
|
|
87
|
+
const labelMatch = labelNormalized.match(queryNormalized);
|
|
88
|
+
const aliasMatch = aliases.some(alias => alias.match(queryNormalized));
|
|
89
|
+
|
|
90
|
+
return labelMatch || aliasMatch;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return labelNormalized.match(queryNormalized);
|
|
94
|
+
})
|
|
95
|
+
.filter(command =>
|
|
96
|
+
command.shouldBeHidden ? !command.shouldBeHidden(this.editor) : true,
|
|
97
|
+
),
|
|
98
|
+
}));
|
|
99
|
+
// Remove empty groups
|
|
100
|
+
const withoutEmptyGroups = withFilteredCommands.filter((group) => {
|
|
101
|
+
if (group.commands.length > 0) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false;
|
|
106
|
+
});
|
|
107
|
+
const withEnabledSettings = withoutEmptyGroups.map(group => ({
|
|
108
|
+
...group,
|
|
109
|
+
commands: group.commands.map(command => ({
|
|
110
|
+
...command,
|
|
111
|
+
isEnabled: true,
|
|
112
|
+
})),
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
return withEnabledSettings;
|
|
116
|
+
},
|
|
117
|
+
render: () => {
|
|
118
|
+
let component: any;
|
|
119
|
+
let scrollHandler: (() => void) | null = null;
|
|
120
|
+
return {
|
|
121
|
+
onStart: (props: SuggestionProps) => {
|
|
122
|
+
component = new ReactRenderer(CommandsList, {
|
|
123
|
+
props,
|
|
124
|
+
editor: props.editor,
|
|
125
|
+
});
|
|
126
|
+
const { view } = props.editor;
|
|
127
|
+
// const editorNode = view.dom as HTMLElement;
|
|
128
|
+
const getReferenceClientRect = () => {
|
|
129
|
+
if (!props.clientRect) {
|
|
130
|
+
return props.editor.storage[extensionName].rect;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const rect = props.clientRect();
|
|
134
|
+
|
|
135
|
+
if (!rect) {
|
|
136
|
+
return props.editor.storage[extensionName].rect;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let yPos = rect.y;
|
|
140
|
+
|
|
141
|
+
if (rect.top + component.element.offsetHeight + 40 > window.innerHeight) {
|
|
142
|
+
const diff = rect.top + component.element.offsetHeight - window.innerHeight + 40;
|
|
143
|
+
yPos = rect.y - diff;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen
|
|
147
|
+
// const editorXOffset = editorNode.getBoundingClientRect().x;
|
|
148
|
+
return new DOMRect(rect.x, yPos, rect.width, rect.height);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
scrollHandler = () => {
|
|
152
|
+
popup?.[0].setProps({
|
|
153
|
+
getReferenceClientRect,
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
view.dom.parentElement?.addEventListener('scroll', scrollHandler);
|
|
158
|
+
|
|
159
|
+
popup?.[0].setProps({
|
|
160
|
+
getReferenceClientRect,
|
|
161
|
+
appendTo: () => document.body,
|
|
162
|
+
content: component.element,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
popup?.[0].show();
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
onUpdate(props: SuggestionProps) {
|
|
169
|
+
component.updateProps(props);
|
|
170
|
+
|
|
171
|
+
const { view } = props.editor;
|
|
172
|
+
|
|
173
|
+
// const editorNode = view.dom as HTMLElement;
|
|
174
|
+
|
|
175
|
+
const getReferenceClientRect = () => {
|
|
176
|
+
if (!props.clientRect) {
|
|
177
|
+
return props.editor.storage[extensionName].rect;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const rect = props.clientRect();
|
|
181
|
+
|
|
182
|
+
if (!rect) {
|
|
183
|
+
return props.editor.storage[extensionName].rect;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Account for when the editor is bound inside a container that doesn't go all the way to the edge of the screen
|
|
187
|
+
return new DOMRect(rect.x, rect.y, rect.width, rect.height);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const scrollHandler = () => {
|
|
191
|
+
popup?.[0].setProps({
|
|
192
|
+
getReferenceClientRect,
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
view.dom.parentElement?.addEventListener('scroll', scrollHandler);
|
|
197
|
+
|
|
198
|
+
props.editor.storage[extensionName].rect = props.clientRect
|
|
199
|
+
? getReferenceClientRect()
|
|
200
|
+
: {
|
|
201
|
+
width: 0,
|
|
202
|
+
height: 0,
|
|
203
|
+
left: 0,
|
|
204
|
+
top: 0,
|
|
205
|
+
right: 0,
|
|
206
|
+
bottom: 0,
|
|
207
|
+
};
|
|
208
|
+
popup?.[0].setProps({
|
|
209
|
+
getReferenceClientRect,
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
onKeyDown(props: SuggestionKeyDownProps) {
|
|
214
|
+
if (props.event.key === 'Escape') {
|
|
215
|
+
popup?.[0].hide();
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (!popup?.[0].state.isShown) {
|
|
221
|
+
popup?.[0].show();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return component.ref?.onKeyDown(props);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
onExit(props) {
|
|
228
|
+
popup?.[0].hide();
|
|
229
|
+
if (scrollHandler) {
|
|
230
|
+
const { view } = props.editor;
|
|
231
|
+
view.dom.parentElement?.removeEventListener('scroll', scrollHandler);
|
|
232
|
+
}
|
|
233
|
+
component.destroy();
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
];
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
addStorage() {
|
|
242
|
+
return {
|
|
243
|
+
rect: {
|
|
244
|
+
width: 0,
|
|
245
|
+
height: 0,
|
|
246
|
+
left: 0,
|
|
247
|
+
top: 0,
|
|
248
|
+
right: 0,
|
|
249
|
+
bottom: 0,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export default SlashCommand;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
Fragment,
|
|
3
|
+
forwardRef,
|
|
4
|
+
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
|
|
10
|
+
import { IconComponent } from '@/components';
|
|
11
|
+
import { cn } from '@/lib/utils';
|
|
12
|
+
import { useLocale } from '@/locales';
|
|
13
|
+
|
|
14
|
+
function CommandsList(props: any, ref: any) {
|
|
15
|
+
// 选中的索引
|
|
16
|
+
const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);
|
|
17
|
+
const [selectedGroupIndex, setSelectedGroupIndex] = useState(0);
|
|
18
|
+
// 滚动ref
|
|
19
|
+
const scrollContainer = useRef<HTMLDivElement | null>(null);
|
|
20
|
+
|
|
21
|
+
const { t } = useLocale();
|
|
22
|
+
|
|
23
|
+
const activeItemRefs = useRef<(HTMLButtonElement | null)[]>([]);
|
|
24
|
+
|
|
25
|
+
useImperativeHandle(ref, () => {
|
|
26
|
+
return {
|
|
27
|
+
onKeyDown,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!scrollContainer.current) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const activeItemIndex = selectedGroupIndex * 1000 + selectedCommandIndex;
|
|
36
|
+
const activeItem = activeItemRefs.current[activeItemIndex];
|
|
37
|
+
if (activeItem) {
|
|
38
|
+
activeItem.scrollIntoView({
|
|
39
|
+
behavior: 'smooth',
|
|
40
|
+
block: 'nearest',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [selectedCommandIndex, selectedGroupIndex]);
|
|
44
|
+
|
|
45
|
+
function onKeyDown({ event }: any) {
|
|
46
|
+
if (event.key === 'ArrowUp') {
|
|
47
|
+
upHandler();
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (event.key === 'ArrowDown') {
|
|
52
|
+
downHandler();
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (event.key === 'Enter') {
|
|
57
|
+
enterHandler();
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function upHandler() {
|
|
65
|
+
if (props.items.length === 0) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
let newCommandIndex = selectedCommandIndex - 1;
|
|
69
|
+
let newGroupIndex = selectedGroupIndex;
|
|
70
|
+
|
|
71
|
+
if (newCommandIndex < 0) {
|
|
72
|
+
newGroupIndex = selectedGroupIndex - 1;
|
|
73
|
+
newCommandIndex = props.items[newGroupIndex]?.commands.length - 1 || 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (newGroupIndex < 0) {
|
|
77
|
+
newGroupIndex = props.items.length - 1;
|
|
78
|
+
newCommandIndex = props.items[newGroupIndex].commands.length - 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setSelectedCommandIndex(newCommandIndex);
|
|
82
|
+
setSelectedGroupIndex(newGroupIndex);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function downHandler() {
|
|
86
|
+
if (props.items.length === 0) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const commands = props.items[selectedGroupIndex].commands;
|
|
90
|
+
let newCommandIndex = selectedCommandIndex + 1;
|
|
91
|
+
let newGroupIndex = selectedGroupIndex;
|
|
92
|
+
|
|
93
|
+
if (commands.length - 1 < newCommandIndex) {
|
|
94
|
+
newCommandIndex = 0;
|
|
95
|
+
newGroupIndex = selectedGroupIndex + 1;
|
|
96
|
+
}
|
|
97
|
+
if (props.items.length - 1 < newGroupIndex) {
|
|
98
|
+
newGroupIndex = 0;
|
|
99
|
+
}
|
|
100
|
+
setSelectedCommandIndex(newCommandIndex);
|
|
101
|
+
setSelectedGroupIndex(newGroupIndex);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function enterHandler() {
|
|
105
|
+
if (props.items.length === 0 || selectedGroupIndex === -1 || selectedCommandIndex === -1) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
selectItem(selectedGroupIndex, selectedCommandIndex);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function selectItem(groupIndex: number, commandIndex: number) {
|
|
113
|
+
const command = props.items[groupIndex].commands[commandIndex];
|
|
114
|
+
props.command(command);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function createCommandClickHandler(groupIndex: number, commandIndex: number) {
|
|
118
|
+
selectItem(groupIndex, commandIndex);
|
|
119
|
+
}
|
|
120
|
+
function setActiveItemRef(groupIndex: number, commandIndex: number, el: any) {
|
|
121
|
+
activeItemRefs.current[groupIndex * 1000 + commandIndex] = el;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
className="mb-8 max-h-[min(80vh,24rem)] flex-wrap overflow-auto rounded-lg !border !border-neutral-200 !bg-white p-1 !text-black shadow-sm dark:!border-neutral-800 dark:!bg-black"
|
|
127
|
+
ref={scrollContainer}
|
|
128
|
+
>
|
|
129
|
+
{props?.items?.length
|
|
130
|
+
? (
|
|
131
|
+
<div className="grid min-w-48 grid-cols-1 gap-0.5">
|
|
132
|
+
{props?.items?.map((group: any, groupIndex: any) => {
|
|
133
|
+
return (
|
|
134
|
+
<Fragment key={`slash-${group.title}`}>
|
|
135
|
+
<div className="col-[1/-1] mx-2 mt-2 select-none text-[0.65rem] font-semibold uppercase tracking-wider !text-neutral-500 first:mt-0.5">
|
|
136
|
+
{group.title}
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
{group.commands.map((command: any, commandIndex: any) => {
|
|
140
|
+
return (
|
|
141
|
+
<button
|
|
142
|
+
key={`command-${commandIndex}`}
|
|
143
|
+
onClick={() => createCommandClickHandler(groupIndex, commandIndex)}
|
|
144
|
+
ref={el => setActiveItemRef(groupIndex, commandIndex, el)}
|
|
145
|
+
className={cn('flex items-center gap-3 px-2 py-1.5 text-sm !text-neutral-800 dark:!text-neutral-200 text-left w-full rounded-sm outline-none transition-colors !bg-transparent hover:!bg-accent ', {
|
|
146
|
+
'slash-command-active': selectedGroupIndex === groupIndex && selectedCommandIndex === commandIndex,
|
|
147
|
+
})}
|
|
148
|
+
>
|
|
149
|
+
{command.iconUrl && <img alt=""
|
|
150
|
+
className="size-6"
|
|
151
|
+
src={command.iconUrl}
|
|
152
|
+
/>}
|
|
153
|
+
|
|
154
|
+
{command.iconName && (
|
|
155
|
+
<IconComponent className="!mr-1 !text-lg"
|
|
156
|
+
name={command.iconName}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
|
|
160
|
+
{command.label}
|
|
161
|
+
</button>
|
|
162
|
+
);
|
|
163
|
+
})}
|
|
164
|
+
</Fragment>
|
|
165
|
+
);
|
|
166
|
+
})}
|
|
167
|
+
</div>
|
|
168
|
+
)
|
|
169
|
+
: (
|
|
170
|
+
<div className="p-3">
|
|
171
|
+
<span className="text-xs text-gray-800 dark:text-gray-100">
|
|
172
|
+
{t('editor.slash.empty')}
|
|
173
|
+
</span>
|
|
174
|
+
</div>
|
|
175
|
+
)}
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default forwardRef(CommandsList);
|