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,303 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { mergeAttributes } from '@tiptap/core';
|
|
3
|
-
import TiptapImage from '@tiptap/extension-image';
|
|
4
|
-
import { Plugin } from '@tiptap/pm/state';
|
|
5
|
-
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
6
|
-
|
|
7
|
-
import ActionImageButton from '@/extensions/Image/components/ActionImageButton';
|
|
8
|
-
import ImageView from '@/extensions/Image/components/ImageView';
|
|
9
|
-
import { UploadImagesPlugin, createImageUpload, handleImageDrop, handleImagePaste } from '@/plugins/image-upload';
|
|
10
|
-
import type { GeneralOptions } from '@/types';
|
|
11
|
-
|
|
12
|
-
export interface SetImageAttrsOptions {
|
|
13
|
-
src?: string
|
|
14
|
-
/** The alternative text for the image. */
|
|
15
|
-
alt?: string
|
|
16
|
-
/** The caption of the image. */
|
|
17
|
-
caption?: string
|
|
18
|
-
/** The width of the image. */
|
|
19
|
-
width?: number | string | null
|
|
20
|
-
/** The alignment of the image. */
|
|
21
|
-
align?: 'left' | 'center' | 'right'
|
|
22
|
-
/** Whether the image is inline. */
|
|
23
|
-
inline?: boolean
|
|
24
|
-
/** image FlipX */
|
|
25
|
-
flipX?: boolean
|
|
26
|
-
/** image FlipY */
|
|
27
|
-
flipY?: boolean
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const DEFAULT_OPTIONS: any = {
|
|
31
|
-
acceptMimes: ['image/jpeg', 'image/gif', 'image/png', 'image/jpg'],
|
|
32
|
-
maxSize: 1024 * 1024 * 5, // 5MB
|
|
33
|
-
resourceImage: 'both',
|
|
34
|
-
defaultInline: false,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
declare module '@tiptap/core' {
|
|
38
|
-
interface Commands<ReturnType> {
|
|
39
|
-
imageUpload: {
|
|
40
|
-
/**
|
|
41
|
-
* Add an image
|
|
42
|
-
*/
|
|
43
|
-
setImageInline: (options: Partial<SetImageAttrsOptions>) => ReturnType
|
|
44
|
-
/**
|
|
45
|
-
* Update an image
|
|
46
|
-
*/
|
|
47
|
-
updateImage: (options: Partial<SetImageAttrsOptions>) => ReturnType
|
|
48
|
-
/**
|
|
49
|
-
* Set image alignment
|
|
50
|
-
*/
|
|
51
|
-
setAlignImage: (align: 'left' | 'center' | 'right') => ReturnType
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface IImageOptions extends GeneralOptions<IImageOptions> {
|
|
57
|
-
/** Function for uploading files */
|
|
58
|
-
upload?: (file: File) => Promise<string>
|
|
59
|
-
|
|
60
|
-
HTMLAttributes?: any
|
|
61
|
-
|
|
62
|
-
acceptMimes?: string[]
|
|
63
|
-
maxSize?: number
|
|
64
|
-
|
|
65
|
-
/** The source URL of the image */
|
|
66
|
-
resourceImage: 'upload' | 'link' | 'both'
|
|
67
|
-
defaultInline?: boolean
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const Image = TiptapImage.extend<IImageOptions>({
|
|
71
|
-
group: 'inline',
|
|
72
|
-
inline: true,
|
|
73
|
-
defining: true,
|
|
74
|
-
draggable: true,
|
|
75
|
-
selectable: true,
|
|
76
|
-
|
|
77
|
-
addOptions() {
|
|
78
|
-
return {
|
|
79
|
-
...DEFAULT_OPTIONS,
|
|
80
|
-
...this.parent?.(),
|
|
81
|
-
upload: () => Promise.reject('Image Upload Function'),
|
|
82
|
-
button: ({
|
|
83
|
-
editor,
|
|
84
|
-
extension,
|
|
85
|
-
t,
|
|
86
|
-
}: {
|
|
87
|
-
editor: any
|
|
88
|
-
extension: any
|
|
89
|
-
t: (key: string) => string
|
|
90
|
-
}) => ({
|
|
91
|
-
component: ActionImageButton,
|
|
92
|
-
componentProps: {
|
|
93
|
-
action: () => {
|
|
94
|
-
return true;
|
|
95
|
-
},
|
|
96
|
-
upload: extension.options.upload,
|
|
97
|
-
/* If setImage is not available(when Image Component is not imported), the button is disabled */
|
|
98
|
-
disabled: !editor.can().setImage?.({}),
|
|
99
|
-
icon: 'ImageUp',
|
|
100
|
-
tooltip: t('editor.image.tooltip'),
|
|
101
|
-
editor,
|
|
102
|
-
},
|
|
103
|
-
}),
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
addAttributes() {
|
|
107
|
-
return {
|
|
108
|
-
...this.parent?.(),
|
|
109
|
-
flipX: {
|
|
110
|
-
default: false,
|
|
111
|
-
},
|
|
112
|
-
flipY: {
|
|
113
|
-
default: false,
|
|
114
|
-
},
|
|
115
|
-
width: {
|
|
116
|
-
default: null,
|
|
117
|
-
parseHTML: (element) => {
|
|
118
|
-
const width = element.style.width || element.getAttribute('width') || null;
|
|
119
|
-
return !width ? null : Number.parseInt(width, 10);
|
|
120
|
-
},
|
|
121
|
-
renderHTML: (attributes) => {
|
|
122
|
-
return {
|
|
123
|
-
width: attributes.width,
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
align: {
|
|
128
|
-
default: 'center',
|
|
129
|
-
parseHTML: element => element.getAttribute('align'),
|
|
130
|
-
renderHTML: (attributes) => {
|
|
131
|
-
return {
|
|
132
|
-
align: attributes.align,
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
inline: {
|
|
137
|
-
default: false,
|
|
138
|
-
parseHTML: element => Boolean(element.getAttribute('inline')),
|
|
139
|
-
renderHTML: (attributes) => {
|
|
140
|
-
return {
|
|
141
|
-
inline: attributes.inline,
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
addNodeView() {
|
|
149
|
-
return ReactNodeViewRenderer(ImageView);
|
|
150
|
-
},
|
|
151
|
-
addCommands() {
|
|
152
|
-
return {
|
|
153
|
-
...this.parent?.(),
|
|
154
|
-
setImageInline: (options: any) => ({ commands }: any) => {
|
|
155
|
-
return commands.insertContent({
|
|
156
|
-
type: this.name,
|
|
157
|
-
attrs: {
|
|
158
|
-
...options,
|
|
159
|
-
inline: options.inline ?? this.options.defaultInline,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
updateImage:
|
|
164
|
-
options =>
|
|
165
|
-
({ commands }) => {
|
|
166
|
-
return commands.updateAttributes(this.name, options);
|
|
167
|
-
},
|
|
168
|
-
setAlignImage:
|
|
169
|
-
align =>
|
|
170
|
-
({ commands }) => {
|
|
171
|
-
return commands.updateAttributes(this.name, { align });
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
renderHTML({ HTMLAttributes }) {
|
|
176
|
-
const { flipX, flipY, align, inline } = HTMLAttributes;
|
|
177
|
-
|
|
178
|
-
const transformStyle
|
|
179
|
-
= flipX || flipY ? `transform: rotateX(${flipX ? '180' : '0'}deg) rotateY(${flipY ? '180' : '0'}deg);` : '';
|
|
180
|
-
|
|
181
|
-
const textAlignStyle = align ? `text-align: ${align};` : '';
|
|
182
|
-
|
|
183
|
-
return [
|
|
184
|
-
inline ? 'span' : 'div',
|
|
185
|
-
{
|
|
186
|
-
style: textAlignStyle,
|
|
187
|
-
class: 'image',
|
|
188
|
-
},
|
|
189
|
-
[
|
|
190
|
-
'img',
|
|
191
|
-
mergeAttributes(
|
|
192
|
-
{
|
|
193
|
-
height: 'auto',
|
|
194
|
-
style: transformStyle,
|
|
195
|
-
},
|
|
196
|
-
this.options.HTMLAttributes,
|
|
197
|
-
HTMLAttributes,
|
|
198
|
-
),
|
|
199
|
-
],
|
|
200
|
-
];
|
|
201
|
-
},
|
|
202
|
-
parseHTML() {
|
|
203
|
-
return [
|
|
204
|
-
{
|
|
205
|
-
tag: 'span.image img',
|
|
206
|
-
getAttrs: (img) => {
|
|
207
|
-
const element = img?.parentElement;
|
|
208
|
-
|
|
209
|
-
const width = img?.getAttribute('width');
|
|
210
|
-
|
|
211
|
-
const flipX = img?.getAttribute('flipx') || false;
|
|
212
|
-
const flipY = img?.getAttribute('flipy') || false;
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
src: img?.getAttribute('src'),
|
|
216
|
-
alt: img?.getAttribute('alt'),
|
|
217
|
-
caption: img?.getAttribute('caption'),
|
|
218
|
-
width: width ? Number.parseInt(width, 10) : null,
|
|
219
|
-
align: img?.getAttribute('align') || element?.style?.textAlign || null,
|
|
220
|
-
inline: img?.getAttribute('inline') || false,
|
|
221
|
-
flipX: flipX === 'true',
|
|
222
|
-
flipY: flipY === 'true',
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
tag: 'div[class=image]',
|
|
228
|
-
getAttrs: (element) => {
|
|
229
|
-
const img = element.querySelector('img');
|
|
230
|
-
|
|
231
|
-
const width = img?.getAttribute('width');
|
|
232
|
-
const flipX = img?.getAttribute('flipx') || false;
|
|
233
|
-
const flipY = img?.getAttribute('flipy') || false;
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
src: img?.getAttribute('src'),
|
|
237
|
-
alt: img?.getAttribute('alt'),
|
|
238
|
-
caption: img?.getAttribute('caption'),
|
|
239
|
-
width: width ? Number.parseInt(width, 10) : null,
|
|
240
|
-
align: img?.getAttribute('align') || element.style.textAlign || null,
|
|
241
|
-
inline: img?.getAttribute('inline') || false,
|
|
242
|
-
flipX: flipX === 'true',
|
|
243
|
-
flipY: flipY === 'true',
|
|
244
|
-
};
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
];
|
|
248
|
-
},
|
|
249
|
-
addProseMirrorPlugins() {
|
|
250
|
-
const validateFile = (file: File): boolean => {
|
|
251
|
-
// @ts-expect-error
|
|
252
|
-
if (!this.options.acceptMimes.includes(file.type)) {
|
|
253
|
-
// toast({ description: t.value('editor.imageUpload.fileTypeNotSupported'), duration: 2000 });
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
// @ts-expect-error
|
|
257
|
-
if (file.size > this.options.maxSize) {
|
|
258
|
-
// toast({
|
|
259
|
-
// description: `${t.value('editor.imageUpload.fileSizeTooBig')} ${formatFileSize(
|
|
260
|
-
// this.options.maxSize,
|
|
261
|
-
// )}.`,
|
|
262
|
-
// duration: 2000,
|
|
263
|
-
// });
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const uploadFn = createImageUpload({
|
|
270
|
-
validateFn: validateFile,
|
|
271
|
-
onUpload: this.options.upload as any,
|
|
272
|
-
// postUpload: this.options.postUpload,
|
|
273
|
-
defaultInline: this.options.defaultInline,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
return [
|
|
277
|
-
new Plugin({
|
|
278
|
-
props: {
|
|
279
|
-
handlePaste: (view, event) => {
|
|
280
|
-
if (!event.clipboardData) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
const items = [...(event.clipboardData.files || [])];
|
|
284
|
-
if (items.some(x => x.type === 'text/html')) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
return handleImagePaste(view, event, uploadFn);
|
|
288
|
-
},
|
|
289
|
-
handleDrop: (view, event, _, moved) => {
|
|
290
|
-
if (!(event instanceof DragEvent) || !event.dataTransfer) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
handleImageDrop(view, event, moved, uploadFn);
|
|
294
|
-
return false;
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
}),
|
|
298
|
-
UploadImagesPlugin(),
|
|
299
|
-
];
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
export default Image;
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { ActionButton, Button, Checkbox, Input, Label, Tabs, TabsContent, TabsList, TabsTrigger } from '@/components';
|
|
4
|
-
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
|
5
|
-
import { ImageCropper } from '@/extensions/Image/components/ImageCropper';
|
|
6
|
-
import Image from '@/extensions/Image/Image';
|
|
7
|
-
import { actionDialogImage } from '@/extensions/Image/store';
|
|
8
|
-
import { useLocale } from '@/locales';
|
|
9
|
-
import { listenEvent } from '@/utils/customEvents/customEvents';
|
|
10
|
-
import { EVENTS } from '@/utils/customEvents/events.constant';
|
|
11
|
-
|
|
12
|
-
function ActionImageButton(props: any) {
|
|
13
|
-
const { t } = useLocale();
|
|
14
|
-
const [open, setOpen] = useState(false);
|
|
15
|
-
|
|
16
|
-
const handleUploadImage = (evt: any) => {
|
|
17
|
-
setOpen(evt.detail);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const [link, setLink] = useState<string>('');
|
|
21
|
-
const fileInput = useRef<HTMLInputElement>(null);
|
|
22
|
-
|
|
23
|
-
const [imageInline, setImageInline] = useState(props.editor.extensionManager.extensions.find(
|
|
24
|
-
(extension: any) => extension.name === Image.name,
|
|
25
|
-
)?.options.defaultInline || false);
|
|
26
|
-
|
|
27
|
-
const uploadOptions = useMemo(() => {
|
|
28
|
-
const uploadOptions = props.editor.extensionManager.extensions.find(
|
|
29
|
-
(extension: any) => extension.name === Image.name,
|
|
30
|
-
)?.options;
|
|
31
|
-
|
|
32
|
-
return uploadOptions;
|
|
33
|
-
}, [props.editor]);
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
const rm1 = listenEvent(EVENTS.UPLOAD_IMAGE(props.editor.id), handleUploadImage);
|
|
37
|
-
|
|
38
|
-
return () => {
|
|
39
|
-
rm1();
|
|
40
|
-
};
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
async function handleFile(event: any) {
|
|
44
|
-
const files = event?.target?.files;
|
|
45
|
-
if (!props.editor || props.editor.isDestroyed || files.length === 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const file = files[0];
|
|
50
|
-
|
|
51
|
-
let src = '';
|
|
52
|
-
if (uploadOptions.upload) {
|
|
53
|
-
src = await uploadOptions.upload(file);
|
|
54
|
-
} else {
|
|
55
|
-
src = URL.createObjectURL(file);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
props.editor.chain().focus().setImageInline({ src, inline: imageInline }).run();
|
|
59
|
-
setOpen(false);
|
|
60
|
-
setImageInline(false);
|
|
61
|
-
}
|
|
62
|
-
function handleLink(e: any) {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
e.stopPropagation();
|
|
65
|
-
|
|
66
|
-
props.editor.chain().focus().setImageInline({ src: link, inline: imageInline }).run();
|
|
67
|
-
setOpen(false);
|
|
68
|
-
setImageInline(false);
|
|
69
|
-
setLink('');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function handleClick(e: any) {
|
|
73
|
-
e.preventDefault();
|
|
74
|
-
fileInput.current?.click();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<Dialog
|
|
79
|
-
onOpenChange={setOpen}
|
|
80
|
-
open={open}
|
|
81
|
-
>
|
|
82
|
-
<DialogTrigger asChild>
|
|
83
|
-
<ActionButton
|
|
84
|
-
action={() => setOpen(true)}
|
|
85
|
-
icon={props.icon}
|
|
86
|
-
tooltip={props.tooltip}
|
|
87
|
-
/>
|
|
88
|
-
</DialogTrigger>
|
|
89
|
-
|
|
90
|
-
<DialogContent>
|
|
91
|
-
<DialogTitle>
|
|
92
|
-
{t('editor.image.dialog.title')}
|
|
93
|
-
</DialogTitle>
|
|
94
|
-
|
|
95
|
-
<Tabs
|
|
96
|
-
activationMode="manual"
|
|
97
|
-
defaultValue={
|
|
98
|
-
uploadOptions.resourceImage === 'both' || uploadOptions.resourceImage === 'upload'
|
|
99
|
-
? 'upload'
|
|
100
|
-
: 'link'
|
|
101
|
-
}
|
|
102
|
-
>
|
|
103
|
-
<TabsList className="grid w-full grid-cols-2">
|
|
104
|
-
{uploadOptions.resourceImage === 'both' || uploadOptions.resourceImage === 'upload'
|
|
105
|
-
? (
|
|
106
|
-
<TabsTrigger value="upload">
|
|
107
|
-
{t('editor.image.dialog.tab.upload')}
|
|
108
|
-
</TabsTrigger>
|
|
109
|
-
)
|
|
110
|
-
: <></>}
|
|
111
|
-
|
|
112
|
-
{uploadOptions.resourceImage === 'both' || uploadOptions.resourceImage === 'link'
|
|
113
|
-
? (
|
|
114
|
-
<TabsTrigger value="link">
|
|
115
|
-
{t('editor.image.dialog.tab.url')}
|
|
116
|
-
</TabsTrigger>
|
|
117
|
-
)
|
|
118
|
-
: <></>}
|
|
119
|
-
</TabsList>
|
|
120
|
-
|
|
121
|
-
<div className="my-[10px] flex items-center gap-[4px]">
|
|
122
|
-
<Checkbox
|
|
123
|
-
checked={imageInline}
|
|
124
|
-
onCheckedChange={(v) => {
|
|
125
|
-
setImageInline(v as boolean);
|
|
126
|
-
}}
|
|
127
|
-
/>
|
|
128
|
-
|
|
129
|
-
<Label>
|
|
130
|
-
{t('editor.link.dialog.inline')}
|
|
131
|
-
</Label>
|
|
132
|
-
</div>
|
|
133
|
-
|
|
134
|
-
<TabsContent value="upload">
|
|
135
|
-
<div className="flex items-center gap-[10px]">
|
|
136
|
-
<Button className="mt-1 w-full"
|
|
137
|
-
onClick={handleClick}
|
|
138
|
-
size="sm"
|
|
139
|
-
>
|
|
140
|
-
{t('editor.image.dialog.tab.upload')}
|
|
141
|
-
</Button>
|
|
142
|
-
|
|
143
|
-
<ImageCropper
|
|
144
|
-
editor={props.editor}
|
|
145
|
-
imageInline={imageInline}
|
|
146
|
-
onClose={() => actionDialogImage.setOpen(props.editor.id, false)}
|
|
147
|
-
/>
|
|
148
|
-
</div>
|
|
149
|
-
|
|
150
|
-
<input
|
|
151
|
-
accept="image/*"
|
|
152
|
-
multiple
|
|
153
|
-
onChange={handleFile}
|
|
154
|
-
ref={fileInput}
|
|
155
|
-
type="file"
|
|
156
|
-
style={{
|
|
157
|
-
display: 'none',
|
|
158
|
-
}}
|
|
159
|
-
/>
|
|
160
|
-
</TabsContent>
|
|
161
|
-
|
|
162
|
-
<TabsContent value="link">
|
|
163
|
-
<form onSubmit={handleLink}>
|
|
164
|
-
<div className="flex items-center gap-2">
|
|
165
|
-
<Input
|
|
166
|
-
autoFocus
|
|
167
|
-
onChange={e => setLink(e.target.value)}
|
|
168
|
-
placeholder={t('editor.image.dialog.placeholder')}
|
|
169
|
-
required
|
|
170
|
-
type="url"
|
|
171
|
-
value={link}
|
|
172
|
-
/>
|
|
173
|
-
|
|
174
|
-
<Button type="submit">
|
|
175
|
-
{t('editor.image.dialog.button.apply')}
|
|
176
|
-
</Button>
|
|
177
|
-
</div>
|
|
178
|
-
</form>
|
|
179
|
-
</TabsContent>
|
|
180
|
-
</Tabs>
|
|
181
|
-
</DialogContent>
|
|
182
|
-
</Dialog>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export default ActionImageButton;
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import ReactCrop, {
|
|
4
|
-
type Crop,
|
|
5
|
-
type PixelCrop,
|
|
6
|
-
} from 'react-image-crop';
|
|
7
|
-
|
|
8
|
-
import { IconComponent } from '@/components';
|
|
9
|
-
import { Button } from '@/components/ui/button';
|
|
10
|
-
import {
|
|
11
|
-
Dialog,
|
|
12
|
-
DialogContent,
|
|
13
|
-
DialogFooter,
|
|
14
|
-
DialogTitle,
|
|
15
|
-
DialogTrigger,
|
|
16
|
-
} from '@/components/ui/dialog';
|
|
17
|
-
import { Image as ExtensionImage } from '@/extensions';
|
|
18
|
-
import { useLocale } from '@/locales';
|
|
19
|
-
import { dataURLtoFile, readImageAsBase64 } from '@/utils/file';
|
|
20
|
-
|
|
21
|
-
export function ImageCropper({ editor, imageInline, onClose }: any) {
|
|
22
|
-
const { t } = useLocale();
|
|
23
|
-
|
|
24
|
-
const [dialogOpen, setDialogOpen] = useState(false);
|
|
25
|
-
|
|
26
|
-
const imgRef = React.useRef<HTMLImageElement | null>(null);
|
|
27
|
-
|
|
28
|
-
const [crop, setCrop] = React.useState<Crop>();
|
|
29
|
-
const [croppedImageUrl, setCroppedImageUrl] = React.useState<string>('');
|
|
30
|
-
const fileInput = useRef<HTMLInputElement>(null);
|
|
31
|
-
const [urlUpload, setUrlUpload] = useState<any>({
|
|
32
|
-
src: '',
|
|
33
|
-
file: null,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
function onCropComplete(crop: PixelCrop) {
|
|
37
|
-
if (imgRef.current && crop.width && crop.height) {
|
|
38
|
-
const croppedImageUrl = getCroppedImg(imgRef.current, crop);
|
|
39
|
-
setCroppedImageUrl(croppedImageUrl);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function getCroppedImg(image: HTMLImageElement, crop: PixelCrop): string {
|
|
44
|
-
const canvas = document.createElement('canvas');
|
|
45
|
-
const scaleX = image.naturalWidth / image.width;
|
|
46
|
-
const scaleY = image.naturalHeight / image.height;
|
|
47
|
-
|
|
48
|
-
canvas.width = crop.width * scaleX;
|
|
49
|
-
canvas.height = crop.height * scaleY;
|
|
50
|
-
|
|
51
|
-
const ctx = canvas.getContext('2d');
|
|
52
|
-
|
|
53
|
-
if (ctx) {
|
|
54
|
-
ctx.imageSmoothingEnabled = false;
|
|
55
|
-
|
|
56
|
-
ctx.drawImage(
|
|
57
|
-
image,
|
|
58
|
-
crop.x * scaleX,
|
|
59
|
-
crop.y * scaleY,
|
|
60
|
-
crop.width * scaleX,
|
|
61
|
-
crop.height * scaleY,
|
|
62
|
-
0,
|
|
63
|
-
0,
|
|
64
|
-
crop.width * scaleX,
|
|
65
|
-
crop.height * scaleY,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return canvas.toDataURL('image/png', 1.0);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function onCrop() {
|
|
73
|
-
try {
|
|
74
|
-
const fileCrop = dataURLtoFile(croppedImageUrl, urlUpload?.file?.name || 'image.png');
|
|
75
|
-
|
|
76
|
-
const uploadOptions = editor.extensionManager.extensions.find(
|
|
77
|
-
(extension: any) => extension.name === ExtensionImage.name,
|
|
78
|
-
)?.options;
|
|
79
|
-
|
|
80
|
-
let src = '';
|
|
81
|
-
if (uploadOptions.upload) {
|
|
82
|
-
src = await uploadOptions.upload(fileCrop);
|
|
83
|
-
} else {
|
|
84
|
-
src = URL.createObjectURL(fileCrop);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
editor.chain().focus().setImageInline({ src, inline: imageInline }).run();
|
|
88
|
-
|
|
89
|
-
setDialogOpen(false);
|
|
90
|
-
|
|
91
|
-
setUrlUpload({
|
|
92
|
-
src: '',
|
|
93
|
-
file: null,
|
|
94
|
-
});
|
|
95
|
-
onClose();
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.log('Error cropping image', error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function handleClick(e: any) {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
fileInput.current?.click();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const handleFile = async (event: any) => {
|
|
107
|
-
const files = event?.target?.files;
|
|
108
|
-
if (!editor || editor.isDestroyed || files.length === 0) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const file = files[0];
|
|
112
|
-
|
|
113
|
-
const base64 = await readImageAsBase64(file);
|
|
114
|
-
|
|
115
|
-
setDialogOpen(true);
|
|
116
|
-
setUrlUpload({
|
|
117
|
-
src: base64.src,
|
|
118
|
-
file,
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<>
|
|
124
|
-
<Button className="mt-1 w-full"
|
|
125
|
-
onClick={handleClick}
|
|
126
|
-
size="sm"
|
|
127
|
-
>
|
|
128
|
-
{t('editor.image.dialog.tab.uploadCrop')}
|
|
129
|
-
</Button>
|
|
130
|
-
|
|
131
|
-
<Dialog open={dialogOpen}>
|
|
132
|
-
<DialogTrigger />
|
|
133
|
-
|
|
134
|
-
<DialogContent>
|
|
135
|
-
<DialogTitle>
|
|
136
|
-
{t('editor.image.dialog.tab.uploadCrop')}
|
|
137
|
-
</DialogTitle>
|
|
138
|
-
|
|
139
|
-
<div>
|
|
140
|
-
{urlUpload.src && (
|
|
141
|
-
<ReactCrop
|
|
142
|
-
className="w-full"
|
|
143
|
-
crop={crop}
|
|
144
|
-
onChange={c => setCrop(c)}
|
|
145
|
-
onComplete={c => onCropComplete(c)}
|
|
146
|
-
>
|
|
147
|
-
<img
|
|
148
|
-
alt="Crop me"
|
|
149
|
-
ref={imgRef}
|
|
150
|
-
src={urlUpload.src}
|
|
151
|
-
/>
|
|
152
|
-
</ReactCrop>
|
|
153
|
-
)}
|
|
154
|
-
</div>
|
|
155
|
-
|
|
156
|
-
<DialogFooter>
|
|
157
|
-
<Button
|
|
158
|
-
onClick={() => {
|
|
159
|
-
setDialogOpen(false);
|
|
160
|
-
setUrlUpload({
|
|
161
|
-
src: '',
|
|
162
|
-
file: null,
|
|
163
|
-
});
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
166
|
-
{t('editor.imageUpload.cancel')}
|
|
167
|
-
|
|
168
|
-
<IconComponent className="ml-[4px]"
|
|
169
|
-
name="Trash2"
|
|
170
|
-
/>
|
|
171
|
-
</Button>
|
|
172
|
-
|
|
173
|
-
<Button className="w-fit"
|
|
174
|
-
onClick={onCrop}
|
|
175
|
-
>
|
|
176
|
-
{t('editor.imageUpload.crop')}
|
|
177
|
-
|
|
178
|
-
<IconComponent className="ml-[4px]"
|
|
179
|
-
name="Crop"
|
|
180
|
-
/>
|
|
181
|
-
</Button>
|
|
182
|
-
</DialogFooter>
|
|
183
|
-
</DialogContent>
|
|
184
|
-
</Dialog>
|
|
185
|
-
|
|
186
|
-
<input
|
|
187
|
-
accept="image/*"
|
|
188
|
-
multiple
|
|
189
|
-
onChange={handleFile}
|
|
190
|
-
ref={fileInput}
|
|
191
|
-
type="file"
|
|
192
|
-
style={{
|
|
193
|
-
display: 'none',
|
|
194
|
-
}}
|
|
195
|
-
/>
|
|
196
|
-
</>
|
|
197
|
-
);
|
|
198
|
-
}
|