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,395 @@
|
|
|
1
|
+
import { deleteSelection } from '@tiptap/pm/commands';
|
|
2
|
+
import type { Editor } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
import { ActionButton } from '@/components';
|
|
5
|
+
import { BUBBLE_TEXT_LIST, IMAGE_SIZE, VIDEO_SIZE } from '@/constants';
|
|
6
|
+
import { localeActions } from '@/locales';
|
|
7
|
+
import type { ButtonViewParams, ButtonViewReturn, ExtensionNameKeys } from '@/types';
|
|
8
|
+
|
|
9
|
+
/** Represents the size types for bubble images or videos */
|
|
10
|
+
type BubbleImageOrVideoSizeType = 'size-small' | 'size-medium' | 'size-large';
|
|
11
|
+
type ImageAlignments = 'left' | 'center' | 'right';
|
|
12
|
+
|
|
13
|
+
/** Represents the various types for bubble images */
|
|
14
|
+
type BubbleImageType =
|
|
15
|
+
| `image-${BubbleImageOrVideoSizeType}`
|
|
16
|
+
| `video-${BubbleImageOrVideoSizeType}`
|
|
17
|
+
| 'image'
|
|
18
|
+
| 'image-aspect-ratio'
|
|
19
|
+
| 'remove';
|
|
20
|
+
|
|
21
|
+
/** Represents the types for bubble videos */
|
|
22
|
+
type BubbleVideoType = 'video' | 'remove';
|
|
23
|
+
|
|
24
|
+
/** Represents the overall types for bubbles */
|
|
25
|
+
type BubbleAllType =
|
|
26
|
+
| BubbleImageType
|
|
27
|
+
| BubbleVideoType
|
|
28
|
+
| ExtensionNameKeys
|
|
29
|
+
| 'divider'
|
|
30
|
+
| (string & {});
|
|
31
|
+
|
|
32
|
+
/** Represents the key types for node types */
|
|
33
|
+
export type NodeTypeKey = 'image' | 'text' | 'video';
|
|
34
|
+
|
|
35
|
+
/** Represents the menu of bubble types for each node type */
|
|
36
|
+
export type BubbleTypeMenu = Partial<Record<NodeTypeKey, BubbleMenuItem[]>>;
|
|
37
|
+
|
|
38
|
+
/** Represents the menu of overall bubble types for each node type */
|
|
39
|
+
export type NodeTypeMenu = Partial<Record<NodeTypeKey, BubbleAllType[]>>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents the structure of a bubble menu item.
|
|
43
|
+
*/
|
|
44
|
+
export interface BubbleMenuItem extends ButtonViewReturn {
|
|
45
|
+
/** The type of the bubble item */
|
|
46
|
+
type: BubbleAllType
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Represents a function to generate a bubble menu
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Generates a bubble menu based on the provided options.
|
|
54
|
+
* @param {ButtonViewParams<T>} options - The options for generating the bubble menu.
|
|
55
|
+
* @returns {BubbleTypeMenu} The generated bubble menu.
|
|
56
|
+
*/
|
|
57
|
+
type BubbleView<T = any> = (options: ButtonViewParams<T>) => BubbleTypeMenu;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Represents the options for configuring bubbles.
|
|
61
|
+
* @interface BubbleOptions
|
|
62
|
+
* @template T
|
|
63
|
+
*/
|
|
64
|
+
export interface BubbleOptions<T> {
|
|
65
|
+
/** The menu of bubble types for each node type. */
|
|
66
|
+
list: NodeTypeMenu
|
|
67
|
+
/** The default list of bubble types. */
|
|
68
|
+
defaultBubbleList: any
|
|
69
|
+
/** The function to generate a bubble menu. */
|
|
70
|
+
button: BubbleView<T>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function imageSizeMenus(editor: Editor): BubbleMenuItem[] {
|
|
74
|
+
const types: BubbleImageOrVideoSizeType[] = ['size-small', 'size-medium', 'size-large'];
|
|
75
|
+
const icons: NonNullable<ButtonViewReturn['componentProps']['icon']>[] = [
|
|
76
|
+
'SizeS',
|
|
77
|
+
'SizeM',
|
|
78
|
+
'SizeL',
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
return types.map((size, i) => ({
|
|
82
|
+
type: `image-${size}`,
|
|
83
|
+
component: ActionButton,
|
|
84
|
+
componentProps: {
|
|
85
|
+
tooltip: localeActions.t(`editor.${size.replace('-', '.')}.tooltip` as any),
|
|
86
|
+
icon: icons[i],
|
|
87
|
+
action: () => editor.commands.updateImage({ width: IMAGE_SIZE[size] }),
|
|
88
|
+
isActive: () => editor.isActive('image', { width: IMAGE_SIZE[size] }),
|
|
89
|
+
},
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function imageGifSizeMenus(editor: Editor): BubbleMenuItem[] {
|
|
94
|
+
const types: BubbleImageOrVideoSizeType[] = ['size-small', 'size-medium', 'size-large'];
|
|
95
|
+
const icons: NonNullable<ButtonViewReturn['componentProps']['icon']>[] = [
|
|
96
|
+
'SizeS',
|
|
97
|
+
'SizeM',
|
|
98
|
+
'SizeL',
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
return types.map((size, i) => ({
|
|
102
|
+
type: `image-${size}`,
|
|
103
|
+
component: ActionButton,
|
|
104
|
+
componentProps: {
|
|
105
|
+
tooltip: localeActions.t(`editor.${size.replace('-', '.')}.tooltip` as any),
|
|
106
|
+
icon: icons[i],
|
|
107
|
+
action: () => editor.commands.updateImageGif({ width: IMAGE_SIZE[size] }),
|
|
108
|
+
isActive: () => editor.isActive('image', { width: IMAGE_SIZE[size] }),
|
|
109
|
+
},
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function imageAlignMenus(editor: Editor): BubbleMenuItem[] {
|
|
114
|
+
const types: ImageAlignments[] = ['left', 'center', 'right'];
|
|
115
|
+
const iconMap: any = {
|
|
116
|
+
left: 'AlignLeft',
|
|
117
|
+
center: 'AlignCenter',
|
|
118
|
+
right: 'AlignRight',
|
|
119
|
+
};
|
|
120
|
+
return types.map(k => ({
|
|
121
|
+
type: `image-${k}`,
|
|
122
|
+
component: ActionButton,
|
|
123
|
+
componentProps: {
|
|
124
|
+
tooltip: localeActions.t(`editor.textalign.${k}.tooltip`),
|
|
125
|
+
icon: iconMap[k],
|
|
126
|
+
action: () => editor.commands?.setAlignImage?.(k),
|
|
127
|
+
isActive: () => editor.isActive({ align: k }) || false,
|
|
128
|
+
disabled: false,
|
|
129
|
+
},
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function imageGifAlignMenus(editor: Editor): BubbleMenuItem[] {
|
|
134
|
+
const types: ImageAlignments[] = ['left', 'center', 'right'];
|
|
135
|
+
const iconMap: any = {
|
|
136
|
+
left: 'AlignLeft',
|
|
137
|
+
center: 'AlignCenter',
|
|
138
|
+
right: 'AlignRight',
|
|
139
|
+
};
|
|
140
|
+
return types.map(k => ({
|
|
141
|
+
type: `image-${k}`,
|
|
142
|
+
component: ActionButton,
|
|
143
|
+
componentProps: {
|
|
144
|
+
tooltip: localeActions.t(`editor.textalign.${k}.tooltip`),
|
|
145
|
+
icon: iconMap[k],
|
|
146
|
+
action: () => editor.commands?.setAlignImageGif?.(k),
|
|
147
|
+
isActive: () => editor.isActive({ align: k }) || false,
|
|
148
|
+
disabled: false,
|
|
149
|
+
},
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function imageMermaidAlignMenus(editor: Editor): BubbleMenuItem[] {
|
|
154
|
+
const types: ImageAlignments[] = ['left', 'center', 'right'];
|
|
155
|
+
const iconMap: any = {
|
|
156
|
+
left: 'AlignLeft',
|
|
157
|
+
center: 'AlignCenter',
|
|
158
|
+
right: 'AlignRight',
|
|
159
|
+
};
|
|
160
|
+
return types.map(k => ({
|
|
161
|
+
type: `image-${k}`,
|
|
162
|
+
component: ActionButton,
|
|
163
|
+
componentProps: {
|
|
164
|
+
tooltip: localeActions.t(`editor.textalign.${k}.tooltip`),
|
|
165
|
+
icon: iconMap[k],
|
|
166
|
+
action: () => editor.commands?.setAlignImageMermaid?.(k),
|
|
167
|
+
isActive: () => editor.isActive({ align: k }) || false,
|
|
168
|
+
disabled: false,
|
|
169
|
+
},
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function imageDrawerAlignMenus(editor: Editor): BubbleMenuItem[] {
|
|
174
|
+
const types: ImageAlignments[] = ['left', 'center', 'right'];
|
|
175
|
+
const iconMap: any = {
|
|
176
|
+
left: 'AlignLeft',
|
|
177
|
+
center: 'AlignCenter',
|
|
178
|
+
right: 'AlignRight',
|
|
179
|
+
};
|
|
180
|
+
return types.map(k => ({
|
|
181
|
+
type: `image-${k}`,
|
|
182
|
+
component: ActionButton,
|
|
183
|
+
componentProps: {
|
|
184
|
+
tooltip: localeActions.t(`editor.textalign.${k}.tooltip`),
|
|
185
|
+
icon: iconMap[k],
|
|
186
|
+
action: () => editor.commands?.setAlignImageDrawer?.(k),
|
|
187
|
+
isActive: () => editor.isActive({ align: k }) || false,
|
|
188
|
+
disabled: false,
|
|
189
|
+
},
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function videoSizeMenus(editor: Editor): BubbleMenuItem[] {
|
|
194
|
+
const types: BubbleImageOrVideoSizeType[] = ['size-small', 'size-medium', 'size-large'];
|
|
195
|
+
const icons: NonNullable<ButtonViewReturn['componentProps']['icon']>[] = [
|
|
196
|
+
'SizeS',
|
|
197
|
+
'SizeM',
|
|
198
|
+
'SizeL',
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
return types.map((size, i) => ({
|
|
202
|
+
type: `video-${size}`,
|
|
203
|
+
component: ActionButton,
|
|
204
|
+
componentProps: {
|
|
205
|
+
tooltip: localeActions.t(`editor.${size.replace('-', '.')}.tooltip` as any),
|
|
206
|
+
icon: icons[i],
|
|
207
|
+
action: () => editor.commands.updateVideo({ width: VIDEO_SIZE[size] }),
|
|
208
|
+
isActive: () => editor.isActive('video', { width: VIDEO_SIZE[size] }),
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
export function getBubbleImage(editor: Editor): BubbleMenuItem[] {
|
|
213
|
+
return [
|
|
214
|
+
{
|
|
215
|
+
type: 'flipX',
|
|
216
|
+
component: ActionButton,
|
|
217
|
+
componentProps: {
|
|
218
|
+
editor,
|
|
219
|
+
tooltip: localeActions.t('editor.tooltip.flipX'),
|
|
220
|
+
icon: 'FlipX',
|
|
221
|
+
action: () => {
|
|
222
|
+
const image = editor.getAttributes('image');
|
|
223
|
+
const { flipX } = image as any;
|
|
224
|
+
editor
|
|
225
|
+
.chain()
|
|
226
|
+
.focus(undefined, { scrollIntoView: false })
|
|
227
|
+
.updateImage({
|
|
228
|
+
flipX: !flipX,
|
|
229
|
+
})
|
|
230
|
+
.run();
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
type: 'flipY',
|
|
236
|
+
component: ActionButton,
|
|
237
|
+
componentProps: {
|
|
238
|
+
editor,
|
|
239
|
+
tooltip: localeActions.t('editor.tooltip.flipY'),
|
|
240
|
+
icon: 'FlipY',
|
|
241
|
+
action: () => {
|
|
242
|
+
const image = editor.getAttributes('image');
|
|
243
|
+
const { flipY } = image as any;
|
|
244
|
+
editor
|
|
245
|
+
.chain()
|
|
246
|
+
.focus(undefined, { scrollIntoView: false })
|
|
247
|
+
.updateImage({
|
|
248
|
+
flipY: !flipY,
|
|
249
|
+
})
|
|
250
|
+
.run();
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
...imageSizeMenus(editor),
|
|
255
|
+
...imageAlignMenus(editor),
|
|
256
|
+
{
|
|
257
|
+
type: 'remove',
|
|
258
|
+
component: ActionButton,
|
|
259
|
+
componentProps: {
|
|
260
|
+
editor,
|
|
261
|
+
tooltip: localeActions.t('editor.remove'),
|
|
262
|
+
icon: 'Trash2',
|
|
263
|
+
action: () => {
|
|
264
|
+
const { state, dispatch } = editor.view;
|
|
265
|
+
deleteSelection(state, dispatch);
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function getBubbleImageGif(editor: Editor): BubbleMenuItem[] {
|
|
273
|
+
return [
|
|
274
|
+
...imageGifSizeMenus(editor),
|
|
275
|
+
...imageGifAlignMenus(editor),
|
|
276
|
+
{
|
|
277
|
+
type: 'remove',
|
|
278
|
+
component: ActionButton,
|
|
279
|
+
componentProps: {
|
|
280
|
+
editor,
|
|
281
|
+
tooltip: localeActions.t('editor.remove'),
|
|
282
|
+
icon: 'Trash2',
|
|
283
|
+
action: () => {
|
|
284
|
+
const { state, dispatch } = editor.view;
|
|
285
|
+
deleteSelection(state, dispatch);
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function getBubbleMermaid(editor: Editor): BubbleMenuItem[] {
|
|
293
|
+
return [
|
|
294
|
+
...imageMermaidAlignMenus(editor),
|
|
295
|
+
{
|
|
296
|
+
type: 'edit',
|
|
297
|
+
component: ActionButton,
|
|
298
|
+
componentProps: {
|
|
299
|
+
editor,
|
|
300
|
+
tooltip: localeActions.t('editor.edit'),
|
|
301
|
+
icon: 'Pencil',
|
|
302
|
+
action: () => {
|
|
303
|
+
return true;
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
type: 'remove',
|
|
309
|
+
component: ActionButton,
|
|
310
|
+
componentProps: {
|
|
311
|
+
editor,
|
|
312
|
+
tooltip: localeActions.t('editor.remove'),
|
|
313
|
+
icon: 'Trash2',
|
|
314
|
+
action: () => {
|
|
315
|
+
const { state, dispatch } = editor.view;
|
|
316
|
+
deleteSelection(state, dispatch);
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function getBubbleDrawer(editor: Editor): BubbleMenuItem[] {
|
|
324
|
+
return [
|
|
325
|
+
...imageDrawerAlignMenus(editor),
|
|
326
|
+
{
|
|
327
|
+
type: 'edit',
|
|
328
|
+
component: ActionButton,
|
|
329
|
+
componentProps: {
|
|
330
|
+
editor,
|
|
331
|
+
tooltip: localeActions.t('editor.edit'),
|
|
332
|
+
icon: 'Pencil',
|
|
333
|
+
action: () => {
|
|
334
|
+
console.log('AAA');
|
|
335
|
+
|
|
336
|
+
return true;
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
type: 'remove',
|
|
342
|
+
component: ActionButton,
|
|
343
|
+
componentProps: {
|
|
344
|
+
editor,
|
|
345
|
+
tooltip: localeActions.t('editor.remove'),
|
|
346
|
+
icon: 'Trash2',
|
|
347
|
+
action: () => {
|
|
348
|
+
const { state, dispatch } = editor.view;
|
|
349
|
+
deleteSelection(state, dispatch);
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export function getBubbleVideo(editor: Editor): BubbleMenuItem[] {
|
|
357
|
+
return [
|
|
358
|
+
...videoSizeMenus(editor),
|
|
359
|
+
{
|
|
360
|
+
type: 'remove',
|
|
361
|
+
component: ActionButton,
|
|
362
|
+
componentProps: {
|
|
363
|
+
editor,
|
|
364
|
+
tooltip: localeActions.t('editor.remove'),
|
|
365
|
+
icon: 'Trash2',
|
|
366
|
+
action: () => {
|
|
367
|
+
const { state, dispatch } = editor.view;
|
|
368
|
+
deleteSelection(state, dispatch);
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Bubble menu text list
|
|
377
|
+
*/
|
|
378
|
+
export function getBubbleText(editor: Editor, t: any, list: string[] = BUBBLE_TEXT_LIST) {
|
|
379
|
+
return list.reduce((acc, type) => {
|
|
380
|
+
if (type === 'divider' && acc.length > 0) {
|
|
381
|
+
return [...acc, {
|
|
382
|
+
type: 'divider',
|
|
383
|
+
component: undefined,
|
|
384
|
+
componentProps: {},
|
|
385
|
+
}];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const ext = editor.extensionManager.extensions.find(ext => ext.name === type);
|
|
389
|
+
if (ext) {
|
|
390
|
+
return [...acc, ext.configure().options.button({ editor, t, extension: ext })];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return acc;
|
|
394
|
+
}, [] as BubbleMenuItem[]);
|
|
395
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
function BubbleMenuContent ({ children, vertical }: PropsWithChildren<{ vertical?:boolean }>) {
|
|
4
|
+
return (
|
|
5
|
+
<div className="pointer-events-auto w-auto select-none rounded-sm !border border-neutral-200 bg-background px-3 py-2 shadow-sm transition-all dark:border-neutral-800">
|
|
6
|
+
<div
|
|
7
|
+
className={`relative flex h-[26px] flex-nowrap items-center justify-start gap-[4px] whitespace-nowrap ${vertical ? 'h-max flex-col' : ''}`}
|
|
8
|
+
>
|
|
9
|
+
{children}
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default BubbleMenuContent;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Fragment, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Editor } from '@tiptap/react';
|
|
4
|
+
import { BubbleMenu as BubbleMenuReact } from '@tiptap/react';
|
|
5
|
+
|
|
6
|
+
import { Separator, getBubbleDrawer } from '@/components';
|
|
7
|
+
import { Drawer } from '@/extensions';
|
|
8
|
+
import { EditDrawerBlock } from '@/extensions/Drawer/components/EditDrawerBlock';
|
|
9
|
+
import { useAttributes } from '@/hooks/useAttributes';
|
|
10
|
+
import { useExtension } from '@/hooks/useExtension';
|
|
11
|
+
import { useLocale } from '@/locales';
|
|
12
|
+
|
|
13
|
+
interface IPropsBubbleMenu {
|
|
14
|
+
editor: Editor
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const tippyOptions = {
|
|
19
|
+
maxWidth: 'auto',
|
|
20
|
+
zIndex: 20,
|
|
21
|
+
appendTo: 'parent',
|
|
22
|
+
moveTransition: 'transform 0.1s ease-out',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function ItemA({ item, disabled, editor }: any) {
|
|
26
|
+
const Comp = item.component;
|
|
27
|
+
|
|
28
|
+
if (!Comp) {
|
|
29
|
+
return <></>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Fragment>
|
|
34
|
+
{item.type === 'divider'
|
|
35
|
+
? (
|
|
36
|
+
<Separator className="!mx-1 !my-2 !h-[16px]"
|
|
37
|
+
orientation="vertical"
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
: (
|
|
41
|
+
<Comp
|
|
42
|
+
{...item.componentProps}
|
|
43
|
+
disabled={disabled || item?.componentProps?.disabled}
|
|
44
|
+
editor={editor}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
</Fragment>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isDrawerNode(node: any) {
|
|
52
|
+
return node.type.name === 'drawer';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function BubbleMenuDrawer(props: IPropsBubbleMenu) {
|
|
56
|
+
const { lang } = useLocale();
|
|
57
|
+
|
|
58
|
+
const attrs = useAttributes<any>(props.editor, Drawer.name);
|
|
59
|
+
|
|
60
|
+
const extension = useExtension(props.editor, Drawer.name);
|
|
61
|
+
|
|
62
|
+
const shouldShow = ({ editor }: any) => {
|
|
63
|
+
const { selection } = editor.view.state;
|
|
64
|
+
const { $from, to } = selection;
|
|
65
|
+
let isDrawer = false;
|
|
66
|
+
|
|
67
|
+
editor.view.state.doc.nodesBetween($from.pos, to, (node: any) => {
|
|
68
|
+
if (isDrawerNode(node)) {
|
|
69
|
+
isDrawer = true;
|
|
70
|
+
return false; // Stop iteration if an mermaid is found
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return isDrawer;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const items = useMemo(() => {
|
|
78
|
+
if (props.disabled) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
return getBubbleDrawer(props.editor);
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [props.disabled, props.editor, lang]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<BubbleMenuReact
|
|
88
|
+
editor={props?.editor}
|
|
89
|
+
shouldShow={shouldShow}
|
|
90
|
+
tippyOptions={tippyOptions as any}
|
|
91
|
+
>
|
|
92
|
+
{items?.length
|
|
93
|
+
? (
|
|
94
|
+
<div className="pointer-events-auto w-auto select-none rounded-sm !border border-neutral-200 bg-background px-3 py-2 shadow-sm transition-all dark:border-neutral-800">
|
|
95
|
+
<div className="relative flex h-[26px] flex-nowrap items-center justify-start whitespace-nowrap">
|
|
96
|
+
{items?.map((item: any, key: any) => {
|
|
97
|
+
if (item.type === 'edit' && attrs?.src) {
|
|
98
|
+
return (
|
|
99
|
+
<EditDrawerBlock
|
|
100
|
+
attrs={attrs}
|
|
101
|
+
editor={props.editor}
|
|
102
|
+
extension={extension}
|
|
103
|
+
key={`bubbleMenu-drawer-${key}`}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ItemA
|
|
110
|
+
disabled={props.disabled}
|
|
111
|
+
editor={props.editor}
|
|
112
|
+
item={item}
|
|
113
|
+
key={`bubbleMenu-drawer-${key}`}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
})}
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
: (
|
|
121
|
+
<></>
|
|
122
|
+
)}
|
|
123
|
+
</BubbleMenuReact>
|
|
124
|
+
</>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { BubbleMenuDrawer };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { BubbleMenu } from '@tiptap/react';
|
|
4
|
+
import { useAttributes } from '@/hooks/useAttributes';
|
|
5
|
+
import { ActionButton } from '@/components/ActionButton';
|
|
6
|
+
import { SizeSetter } from '@/components/SizeSetter/SizeSetter';
|
|
7
|
+
import { useLocale } from '@/locales';
|
|
8
|
+
import type { IExcalidrawAttrs } from '@/extensions/Excalidraw';
|
|
9
|
+
import { Excalidraw } from '@/extensions/Excalidraw';
|
|
10
|
+
import { triggerOpenExcalidrawSettingModal } from '@/utils/_event';
|
|
11
|
+
import { deleteNode } from '@/utils/delete-node';
|
|
12
|
+
import { getEditorContainerDOMSize } from '@/utils/editor-container-size';
|
|
13
|
+
|
|
14
|
+
export function BubbleMenuExcalidraw({ editor }: any) {
|
|
15
|
+
const { t } = useLocale();
|
|
16
|
+
const { width: maxWidth } = getEditorContainerDOMSize(editor);
|
|
17
|
+
const attrs = useAttributes<IExcalidrawAttrs>(editor, Excalidraw.name, {
|
|
18
|
+
defaultShowPicker: false,
|
|
19
|
+
createUser: '',
|
|
20
|
+
width: 0,
|
|
21
|
+
height: 0,
|
|
22
|
+
});
|
|
23
|
+
const { defaultShowPicker, createUser, width, height } = attrs;
|
|
24
|
+
|
|
25
|
+
const setSize = useCallback(
|
|
26
|
+
(size: any) => {
|
|
27
|
+
editor
|
|
28
|
+
.chain()
|
|
29
|
+
.updateAttributes(Excalidraw.name, size)
|
|
30
|
+
.setNodeSelection(editor.state.selection.from)
|
|
31
|
+
.focus()
|
|
32
|
+
.run();
|
|
33
|
+
},
|
|
34
|
+
[editor],
|
|
35
|
+
);
|
|
36
|
+
const openEditLinkModal = useCallback(() => {
|
|
37
|
+
triggerOpenExcalidrawSettingModal(attrs);
|
|
38
|
+
}, [editor, attrs]);
|
|
39
|
+
const shouldShow = useCallback(() => editor.isActive(Excalidraw.name), [editor]);
|
|
40
|
+
const deleteMe = useCallback(() => deleteNode(Excalidraw.name, editor), [editor]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (defaultShowPicker) {
|
|
44
|
+
openEditLinkModal();
|
|
45
|
+
editor.chain().updateAttributes(Excalidraw.name, { defaultShowPicker: false }).focus().run();
|
|
46
|
+
}
|
|
47
|
+
}, [createUser, defaultShowPicker, editor, openEditLinkModal]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<BubbleMenu
|
|
51
|
+
className="bubble-menu"
|
|
52
|
+
editor={editor}
|
|
53
|
+
pluginKey="excalidraw-bubble-menu"
|
|
54
|
+
shouldShow={shouldShow}
|
|
55
|
+
tippyOptions={{
|
|
56
|
+
popperOptions: {
|
|
57
|
+
modifiers: [{ name: 'flip', enabled: false }],
|
|
58
|
+
},
|
|
59
|
+
placement: 'bottom-start',
|
|
60
|
+
offset: [-2, 16],
|
|
61
|
+
zIndex: 9999,
|
|
62
|
+
// onHidden: () => {
|
|
63
|
+
// toggleVisible(false)
|
|
64
|
+
// },
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<div className="w-auto px-3 py-2 transition-all !border rounded-sm shadow-sm pointer-events-auto select-none border-neutral-200 dark:border-neutral-800 bg-background">
|
|
68
|
+
|
|
69
|
+
<ActionButton
|
|
70
|
+
icon="Pencil"
|
|
71
|
+
action={openEditLinkModal}
|
|
72
|
+
tooltip={t('editor.edit')}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<SizeSetter width={width as any} maxWidth={maxWidth} height={height as any} onOk={setSize}>
|
|
76
|
+
<ActionButton
|
|
77
|
+
icon="Settings"
|
|
78
|
+
tooltip={t('editor.settings')}
|
|
79
|
+
/>
|
|
80
|
+
</SizeSetter>
|
|
81
|
+
|
|
82
|
+
<ActionButton
|
|
83
|
+
icon="Trash2"
|
|
84
|
+
action={deleteMe}
|
|
85
|
+
tooltip={t('editor.delete')}
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
</div>
|
|
89
|
+
</BubbleMenu>
|
|
90
|
+
);
|
|
91
|
+
}
|