reactjs-tiptap-editor-pro 0.2.30 → 0.2.32
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/lib/RichTextEditor-BwbqJLnA.cjs +141 -0
- package/lib/RichTextEditor-iGJ6-rbq.js +8833 -0
- package/lib/extension-bundle.cjs +33 -0
- package/lib/extension-bundle.d.cts +947 -0
- package/lib/extension-bundle.d.ts +947 -0
- package/lib/extension-bundle.js +5755 -0
- package/lib/index-DV-nXpU1.cjs +1 -0
- package/lib/index-M6H3FoBi.js +1147 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +513 -0
- package/lib/index.d.ts +513 -0
- package/lib/index.js +16 -0
- package/lib/locale-bundle.cjs +1 -0
- package/lib/locale-bundle.d.cts +1140 -0
- package/lib/locale-bundle.d.ts +1140 -0
- package/lib/locale-bundle.js +9 -0
- package/lib/style.css +1 -0
- package/lib/tiptap-DkWHMWDt.js +6061 -0
- package/lib/tiptap-gBG-1T-V.cjs +116 -0
- package/lib/vendor-BJ0Yf78E.cjs +8114 -0
- package/lib/vendor-Cpa6z-M0.js +67575 -0
- package/package.json +60 -4
- package/src/components/ActionButton.tsx +0 -103
- package/src/components/ActionMenuButton.tsx +0 -76
- package/src/components/BubbleMenu.tsx +0 -93
- package/src/components/CharactorCount.tsx +0 -50
- package/src/components/ColorPicker.tsx +0 -272
- package/src/components/RichTextEditor.tsx +0 -212
- package/src/components/SizeSetter/SizeSetter.tsx +0 -102
- package/src/components/Toolbar.tsx +0 -108
- package/src/components/icons/Activity.tsx +0 -19
- package/src/components/icons/Animas.tsx +0 -24
- package/src/components/icons/AspectRatio.tsx +0 -13
- package/src/components/icons/Blockquote.tsx +0 -17
- package/src/components/icons/ColumnAddLeft.tsx +0 -7
- package/src/components/icons/ColumnAddRight.tsx +0 -7
- package/src/components/icons/DeleteColumn.tsx +0 -26
- package/src/components/icons/DeleteRow.tsx +0 -26
- package/src/components/icons/Direction.tsx +0 -7
- package/src/components/icons/Excalidraw.tsx +0 -7
- package/src/components/icons/ExportPdf.tsx +0 -8
- package/src/components/icons/ExportWord.tsx +0 -24
- package/src/components/icons/FileWordOutline.tsx +0 -13
- package/src/components/icons/Flag.tsx +0 -19
- package/src/components/icons/Food.tsx +0 -20
- package/src/components/icons/GIfIcon.tsx +0 -10
- package/src/components/icons/Icon.tsx +0 -30
- package/src/components/icons/ImportWord.tsx +0 -23
- package/src/components/icons/LeftToRight.tsx +0 -7
- package/src/components/icons/LineHeight.tsx +0 -13
- package/src/components/icons/MenuDown.tsx +0 -24
- package/src/components/icons/Mermaid.tsx +0 -13
- package/src/components/icons/NoFill.tsx +0 -7
- package/src/components/icons/Object.tsx +0 -24
- package/src/components/icons/RightToLeft.tsx +0 -7
- package/src/components/icons/SizeL.tsx +0 -9
- package/src/components/icons/SizeM.tsx +0 -13
- package/src/components/icons/SizeS.tsx +0 -13
- package/src/components/icons/Symbol.tsx +0 -19
- package/src/components/icons/Travel.tsx +0 -24
- package/src/components/icons/Twitter.tsx +0 -7
- package/src/components/icons/icons.ts +0 -212
- package/src/components/icons/index.ts +0 -12
- package/src/components/index.ts +0 -9
- package/src/components/menus/bubble.ts +0 -395
- package/src/components/menus/components/BubbleMenuContent.tsx +0 -15
- package/src/components/menus/components/BubbleMenuDrawer.tsx +0 -128
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +0 -91
- package/src/components/menus/components/BubbleMenuIframe.tsx +0 -143
- package/src/components/menus/components/BubbleMenuKatex.tsx +0 -136
- package/src/components/menus/components/BubbleMenuLink.tsx +0 -99
- package/src/components/menus/components/BubbleMenuMedia.tsx +0 -235
- package/src/components/menus/components/BubbleMenuMermaid.tsx +0 -128
- package/src/components/menus/components/BubbleMenuText.tsx +0 -102
- package/src/components/menus/components/BubbleMenuTwitter.tsx +0 -91
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +0 -59
- package/src/components/menus/components/ContentMenu.tsx +0 -396
- package/src/components/menus/components/TableBubbleMenu.tsx +0 -362
- package/src/components/menus/index.ts +0 -7
- package/src/components/ui/button.tsx +0 -56
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -128
- package/src/components/ui/dropdown-menu.tsx +0 -203
- package/src/components/ui/emoji-picker.tsx +0 -166
- package/src/components/ui/index.ts +0 -14
- package/src/components/ui/input.tsx +0 -25
- package/src/components/ui/label.tsx +0 -26
- package/src/components/ui/popover.tsx +0 -31
- package/src/components/ui/select.tsx +0 -162
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/textarea.tsx +0 -24
- package/src/components/ui/toast.tsx +0 -129
- package/src/components/ui/toaster.tsx +0 -44
- package/src/components/ui/toggle.tsx +0 -45
- package/src/components/ui/tooltip.tsx +0 -30
- package/src/components/ui/use-toast.ts +0 -197
- package/src/constants/index.ts +0 -223
- package/src/constants/resetCSS.ts +0 -139
- package/src/extension-bundle.ts +0 -2
- package/src/extensions/Attachment/Attachment.ts +0 -144
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +0 -69
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +0 -28
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +0 -155
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +0 -23
- package/src/extensions/Attachment/index.ts +0 -1
- package/src/extensions/BaseKit.ts +0 -253
- package/src/extensions/Blockquote/Blockquote.ts +0 -31
- package/src/extensions/Blockquote/index.ts +0 -1
- package/src/extensions/Bold/Bold.ts +0 -26
- package/src/extensions/Bold/index.ts +0 -1
- package/src/extensions/BulletList/BulletList.ts +0 -28
- package/src/extensions/BulletList/index.ts +0 -1
- package/src/extensions/Clear/Clear.ts +0 -24
- package/src/extensions/Clear/index.ts +0 -1
- package/src/extensions/Code/Code.ts +0 -26
- package/src/extensions/Code/index.ts +0 -1
- package/src/extensions/CodeBlock/CodeBlock.ts +0 -54
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +0 -66
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +0 -89
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +0 -81
- package/src/extensions/CodeBlock/highlighter.ts +0 -132
- package/src/extensions/CodeBlock/index.ts +0 -1
- package/src/extensions/CodeBlock/shiki-plugin.ts +0 -213
- package/src/extensions/Color/Color.ts +0 -52
- package/src/extensions/Color/components/ColorActionButton.tsx +0 -104
- package/src/extensions/Color/index.ts +0 -1
- package/src/extensions/Document/Document.ts +0 -8
- package/src/extensions/Document/index.ts +0 -1
- package/src/extensions/Drawer/Drawer.ts +0 -177
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +0 -85
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +0 -598
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +0 -500
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +0 -239
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +0 -238
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +0 -260
- package/src/extensions/Drawer/index.ts +0 -1
- package/src/extensions/Emoji/Emoji.ts +0 -146
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +0 -103
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +0 -1858
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +0 -61
- package/src/extensions/Emoji/index.ts +0 -1
- package/src/extensions/Excalidraw/Excalidraw.ts +0 -123
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +0 -138
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +0 -178
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +0 -43
- package/src/extensions/Excalidraw/index.ts +0 -1
- package/src/extensions/ExportPdf/ExportPdf.ts +0 -25
- package/src/extensions/ExportPdf/index.ts +0 -1
- package/src/extensions/ExportWord/ExportWord.ts +0 -87
- package/src/extensions/ExportWord/index.ts +0 -1
- package/src/extensions/FontFamily/FontFamily.ts +0 -64
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +0 -97
- package/src/extensions/FontFamily/index.ts +0 -1
- package/src/extensions/FontSize/FontSize.ts +0 -119
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +0 -84
- package/src/extensions/FontSize/index.ts +0 -1
- package/src/extensions/FormatPainter/FormatPainter.ts +0 -121
- package/src/extensions/FormatPainter/index.ts +0 -1
- package/src/extensions/Heading/Heading.ts +0 -57
- package/src/extensions/Heading/components/HeadingButton.tsx +0 -96
- package/src/extensions/Heading/index.ts +0 -1
- package/src/extensions/Highlight/Highlight.ts +0 -36
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +0 -108
- package/src/extensions/Highlight/index.ts +0 -1
- package/src/extensions/History/History.ts +0 -39
- package/src/extensions/History/components/HistoryActionButton.tsx +0 -74
- package/src/extensions/History/index.ts +0 -1
- package/src/extensions/HorizontalRule/HorizontalRule.ts +0 -42
- package/src/extensions/HorizontalRule/index.ts +0 -1
- package/src/extensions/Iframe/Iframe.ts +0 -140
- package/src/extensions/Iframe/components/IframeNodeView.tsx +0 -92
- package/src/extensions/Iframe/components/index.module.scss +0 -40
- package/src/extensions/Iframe/embed.ts +0 -487
- package/src/extensions/Iframe/index.ts +0 -1
- package/src/extensions/Image/Image.ts +0 -303
- package/src/extensions/Image/components/ActionImageButton.tsx +0 -186
- package/src/extensions/Image/components/ImageCropper.tsx +0 -198
- package/src/extensions/Image/components/ImageView.tsx +0 -271
- package/src/extensions/Image/index.ts +0 -1
- package/src/extensions/Image/store.ts +0 -15
- package/src/extensions/ImageGif/ImageGif.ts +0 -176
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +0 -138
- package/src/extensions/ImageGif/components/ImageGifView.tsx +0 -260
- package/src/extensions/ImageGif/index.ts +0 -1
- package/src/extensions/ImportWord/ImportWord.ts +0 -52
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +0 -151
- package/src/extensions/ImportWord/index.ts +0 -1
- package/src/extensions/Indent/Indent.ts +0 -110
- package/src/extensions/Indent/index.ts +0 -1
- package/src/extensions/Italic/Italic.ts +0 -29
- package/src/extensions/Italic/index.ts +0 -1
- package/src/extensions/Katex/Katex.ts +0 -109
- package/src/extensions/Katex/components/KatexActiveButton.tsx +0 -117
- package/src/extensions/Katex/components/KatexWrapper.tsx +0 -53
- package/src/extensions/Katex/index.ts +0 -1
- package/src/extensions/LineHeight/LineHeight.ts +0 -76
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +0 -93
- package/src/extensions/LineHeight/index.ts +0 -1
- package/src/extensions/Link/Link.ts +0 -92
- package/src/extensions/Link/components/LinkEditBlock.tsx +0 -110
- package/src/extensions/Link/components/LinkEditPopover.tsx +0 -46
- package/src/extensions/Link/components/LinkViewBlock.tsx +0 -54
- package/src/extensions/Link/index.ts +0 -1
- package/src/extensions/ListItem/ListItem.ts +0 -1
- package/src/extensions/ListItem/index.ts +0 -1
- package/src/extensions/Mention/Mention.ts +0 -100
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +0 -94
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +0 -38
- package/src/extensions/Mention/index.ts +0 -1
- package/src/extensions/Mermaid/Mermaid.ts +0 -177
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +0 -155
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +0 -151
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +0 -260
- package/src/extensions/Mermaid/index.ts +0 -1
- package/src/extensions/MoreMark/MoreMark.ts +0 -102
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +0 -97
- package/src/extensions/MoreMark/index.ts +0 -1
- package/src/extensions/MultiColumn/Column.ts +0 -36
- package/src/extensions/MultiColumn/MultiColumn.ts +0 -111
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +0 -22
- package/src/extensions/MultiColumn/index.ts +0 -3
- package/src/extensions/OrderedList/OrderedList.ts +0 -28
- package/src/extensions/OrderedList/index.ts +0 -1
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +0 -395
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +0 -190
- package/src/extensions/SearchAndReplace/index.ts +0 -1
- package/src/extensions/Selection/Selection.ts +0 -32
- package/src/extensions/Selection/index.ts +0 -1
- package/src/extensions/SlashCommand/SlashCommand.ts +0 -255
- package/src/extensions/SlashCommand/components/CommandsList.tsx +0 -180
- package/src/extensions/SlashCommand/groups.ts +0 -183
- package/src/extensions/SlashCommand/index.ts +0 -1
- package/src/extensions/SlashCommand/types.ts +0 -24
- package/src/extensions/Strike/Strike.ts +0 -26
- package/src/extensions/Strike/index.ts +0 -1
- package/src/extensions/Subscript/Subscript.ts +0 -88
- package/src/extensions/Subscript/index.ts +0 -1
- package/src/extensions/Table/Cell.ts +0 -131
- package/src/extensions/Table/Header.ts +0 -93
- package/src/extensions/Table/Row.ts +0 -8
- package/src/extensions/Table/Table.ts +0 -60
- package/src/extensions/Table/cell-background.ts +0 -112
- package/src/extensions/Table/components/CreateTablePopover.tsx +0 -132
- package/src/extensions/Table/components/TableActionButton.tsx +0 -42
- package/src/extensions/Table/index.ts +0 -6
- package/src/extensions/Table/utils.ts +0 -352
- package/src/extensions/TableOfContent/TableOfContent.ts +0 -124
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +0 -116
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +0 -27
- package/src/extensions/TableOfContent/components/index.module.scss +0 -40
- package/src/extensions/TableOfContent/index.ts +0 -1
- package/src/extensions/TaskList/TaskList.ts +0 -46
- package/src/extensions/TaskList/index.ts +0 -1
- package/src/extensions/TextAlign/TextAlign.ts +0 -68
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +0 -103
- package/src/extensions/TextAlign/index.ts +0 -1
- package/src/extensions/TextBubble/TextBubble.ts +0 -22
- package/src/extensions/TextBubble/components/TextDropdown.tsx +0 -146
- package/src/extensions/TextBubble/index.ts +0 -1
- package/src/extensions/TextDirection/TextDirection.ts +0 -97
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +0 -103
- package/src/extensions/TextDirection/index.ts +0 -1
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -71
- package/src/extensions/TrailingNode/index.ts +0 -1
- package/src/extensions/Twitter/Twitter.ts +0 -161
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +0 -68
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +0 -30
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +0 -41
- package/src/extensions/Twitter/index.ts +0 -1
- package/src/extensions/UnderLine/Underline.ts +0 -30
- package/src/extensions/UnderLine/index.ts +0 -1
- package/src/extensions/Video/Video.ts +0 -204
- package/src/extensions/Video/components/ActiveVideoButton.tsx +0 -191
- package/src/extensions/Video/index.ts +0 -1
- package/src/extensions/Video/store.ts +0 -15
- package/src/extensions/index.ts +0 -122
- package/src/hooks/useActive.tsx +0 -24
- package/src/hooks/useAttributes.tsx +0 -45
- package/src/hooks/useCopy.tsx +0 -20
- package/src/hooks/useEditorState.tsx +0 -23
- package/src/hooks/useExtension.tsx +0 -29
- package/src/index.ts +0 -8
- package/src/lib/utils.ts +0 -7
- package/src/locale-bundle.ts +0 -3
- package/src/locales/en.ts +0 -173
- package/src/locales/hu.ts +0 -173
- package/src/locales/index.tsx +0 -163
- package/src/locales/pt-br.ts +0 -173
- package/src/locales/vi.ts +0 -173
- package/src/locales/zh-cn.ts +0 -173
- package/src/plugins/DragHandle/index.ts +0 -375
- package/src/plugins/DragHandle/range.ts +0 -114
- package/src/plugins/DragHandle/utils.ts +0 -80
- package/src/plugins/image-upload.ts +0 -160
- package/src/store/ProviderRichText.tsx +0 -53
- package/src/store/editableEditor.ts +0 -15
- package/src/store/fast-context.tsx +0 -70
- package/src/store/store.ts +0 -35
- package/src/styles/ProseMirror.scss +0 -176
- package/src/styles/columns.scss +0 -23
- package/src/styles/editor.scss +0 -411
- package/src/styles/global.scss +0 -87
- package/src/styles/index.scss +0 -5
- package/src/styles/mention.scss +0 -6
- package/src/theme/theme.ts +0 -15
- package/src/types.ts +0 -271
- package/src/utils/_event.ts +0 -55
- package/src/utils/color.ts +0 -67
- package/src/utils/columns.ts +0 -142
- package/src/utils/customEvents/customEvents.ts +0 -18
- package/src/utils/customEvents/events.constant.ts +0 -11
- package/src/utils/delete-node.ts +0 -46
- package/src/utils/dom-dataset.ts +0 -121
- package/src/utils/download.ts +0 -17
- package/src/utils/dynamicCSS.ts +0 -192
- package/src/utils/editor-container-size.ts +0 -28
- package/src/utils/file.ts +0 -112
- package/src/utils/getRenderContainer.ts +0 -41
- package/src/utils/indent.ts +0 -99
- package/src/utils/is-mobile.ts +0 -57
- package/src/utils/json.ts +0 -18
- package/src/utils/line-height.ts +0 -109
- package/src/utils/lru-cache.ts +0 -145
- package/src/utils/mitt.ts +0 -114
- package/src/utils/node.ts +0 -92
- package/src/utils/pdf.ts +0 -72
- package/src/utils/plateform.ts +0 -49
- package/src/utils/shortId.ts +0 -5
- package/src/utils/storage.ts +0 -18
- package/src/utils/utils.ts +0 -71
- package/src/vite-env.d.ts +0 -3
|
@@ -1,190 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SearchAndReplace';
|
|
@@ -1,32 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Selection';
|
|
@@ -1,255 +0,0 @@
|
|
|
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;
|
|
@@ -1,180 +0,0 @@
|
|
|
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);
|