reactjs-tiptap-editor-pro 0.2.31 → 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 +58 -5
- 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,395 +0,0 @@
|
|
|
1
|
-
import { deleteSelection } from '@tiptap/pm/commands';
|
|
2
|
-
import type { Editor } from '@tiptap/react';
|
|
3
|
-
|
|
4
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
5
|
-
import { BUBBLE_TEXT_LIST, IMAGE_SIZE, VIDEO_SIZE } from 'reactjs-tiptap-editor-pro/constants';
|
|
6
|
-
import { localeActions } from 'reactjs-tiptap-editor-pro/locales';
|
|
7
|
-
import type { ButtonViewParams, ButtonViewReturn, ExtensionNameKeys } from 'reactjs-tiptap-editor-pro/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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,128 +0,0 @@
|
|
|
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 'reactjs-tiptap-editor-pro/components';
|
|
7
|
-
import { Drawer } from 'reactjs-tiptap-editor-pro/extensions';
|
|
8
|
-
import { EditDrawerBlock } from 'reactjs-tiptap-editor-pro/extensions/Drawer/components/EditDrawerBlock';
|
|
9
|
-
import { useAttributes } from 'reactjs-tiptap-editor-pro/hooks/useAttributes';
|
|
10
|
-
import { useExtension } from 'reactjs-tiptap-editor-pro/hooks/useExtension';
|
|
11
|
-
import { useLocale } from 'reactjs-tiptap-editor-pro/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 };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
import { BubbleMenu } from '@tiptap/react';
|
|
4
|
-
import { useAttributes } from 'reactjs-tiptap-editor-pro/hooks/useAttributes';
|
|
5
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components/ActionButton';
|
|
6
|
-
import { SizeSetter } from 'reactjs-tiptap-editor-pro/components/SizeSetter/SizeSetter';
|
|
7
|
-
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
8
|
-
import type { IExcalidrawAttrs } from 'reactjs-tiptap-editor-pro/extensions/Excalidraw';
|
|
9
|
-
import { Excalidraw } from 'reactjs-tiptap-editor-pro/extensions/Excalidraw';
|
|
10
|
-
import { triggerOpenExcalidrawSettingModal } from 'reactjs-tiptap-editor-pro/utils/_event';
|
|
11
|
-
import { deleteNode } from 'reactjs-tiptap-editor-pro/utils/delete-node';
|
|
12
|
-
import { getEditorContainerDOMSize } from 'reactjs-tiptap-editor-pro/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
|
-
}
|