reactjs-tiptap-editor-pro 0.2.29 → 0.2.31
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 +5 -58
- 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-BwbqJLnA.cjs +0 -141
- package/lib/RichTextEditor-iGJ6-rbq.js +0 -8833
- 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 -513
- package/lib/index.d.ts +0 -513
- 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,303 @@
|
|
|
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 'reactjs-tiptap-editor-pro/extensions/Image/components/ActionImageButton';
|
|
8
|
+
import ImageView from 'reactjs-tiptap-editor-pro/extensions/Image/components/ImageView';
|
|
9
|
+
import { UploadImagesPlugin, createImageUpload, handleImageDrop, handleImagePaste } from 'reactjs-tiptap-editor-pro/plugins/image-upload';
|
|
10
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/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;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ActionButton, Button, Checkbox, Input, Label, Tabs, TabsContent, TabsList, TabsTrigger } from 'reactjs-tiptap-editor-pro/components';
|
|
4
|
+
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from 'reactjs-tiptap-editor-pro/components/ui/dialog';
|
|
5
|
+
import { ImageCropper } from 'reactjs-tiptap-editor-pro/extensions/Image/components/ImageCropper';
|
|
6
|
+
import Image from 'reactjs-tiptap-editor-pro/extensions/Image/Image';
|
|
7
|
+
import { actionDialogImage } from 'reactjs-tiptap-editor-pro/extensions/Image/store';
|
|
8
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
9
|
+
import { listenEvent } from 'reactjs-tiptap-editor-pro/utils/customEvents/customEvents';
|
|
10
|
+
import { EVENTS } from 'reactjs-tiptap-editor-pro/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;
|
|
@@ -0,0 +1,198 @@
|
|
|
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 'reactjs-tiptap-editor-pro/components';
|
|
9
|
+
import { Button } from 'reactjs-tiptap-editor-pro/components/ui/button';
|
|
10
|
+
import {
|
|
11
|
+
Dialog,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogTitle,
|
|
15
|
+
DialogTrigger,
|
|
16
|
+
} from 'reactjs-tiptap-editor-pro/components/ui/dialog';
|
|
17
|
+
import { Image as ExtensionImage } from 'reactjs-tiptap-editor-pro/extensions';
|
|
18
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
19
|
+
import { dataURLtoFile, readImageAsBase64 } from 'reactjs-tiptap-editor-pro/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
|
+
}
|