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,260 @@
|
|
|
1
|
+
/* eslint-disable no-unsafe-optional-chaining */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { NodeViewWrapper } from '@tiptap/react';
|
|
6
|
+
import { clamp, isNumber, throttle } from 'lodash-es';
|
|
7
|
+
|
|
8
|
+
import { IMAGE_MAX_SIZE, IMAGE_MIN_SIZE, IMAGE_THROTTLE_WAIT_TIME } from 'reactjs-tiptap-editor-pro/constants';
|
|
9
|
+
|
|
10
|
+
interface Size {
|
|
11
|
+
width: number
|
|
12
|
+
height: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const ResizeDirection = {
|
|
16
|
+
TOP_LEFT: 'tl',
|
|
17
|
+
TOP_RIGHT: 'tr',
|
|
18
|
+
BOTTOM_LEFT: 'bl',
|
|
19
|
+
BOTTOM_RIGHT: 'br',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function ImageGifView(props: any) {
|
|
23
|
+
const [maxSize, setMaxSize] = useState<Size>({
|
|
24
|
+
width: IMAGE_MAX_SIZE,
|
|
25
|
+
height: IMAGE_MAX_SIZE,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const [originalSize, setOriginalSize] = useState({
|
|
29
|
+
width: 0,
|
|
30
|
+
height: 0,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const [resizeDirections] = useState<string[]>([
|
|
34
|
+
ResizeDirection.TOP_LEFT,
|
|
35
|
+
ResizeDirection.TOP_RIGHT,
|
|
36
|
+
ResizeDirection.BOTTOM_LEFT,
|
|
37
|
+
ResizeDirection.BOTTOM_RIGHT,
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const [resizing, setResizing] = useState<boolean>(false);
|
|
41
|
+
|
|
42
|
+
const [resizerState, setResizerState] = useState({
|
|
43
|
+
x: 0,
|
|
44
|
+
y: 0,
|
|
45
|
+
w: 0,
|
|
46
|
+
h: 0,
|
|
47
|
+
dir: '',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { align } = props?.node?.attrs;
|
|
51
|
+
|
|
52
|
+
const imgAttrs = useMemo(() => {
|
|
53
|
+
const { src, alt, width: w, height: h } = props?.node?.attrs;
|
|
54
|
+
|
|
55
|
+
const width = isNumber(w) ? `${w}px` : w;
|
|
56
|
+
const height = isNumber(h) ? `${h}px` : h;
|
|
57
|
+
return {
|
|
58
|
+
src: src || undefined,
|
|
59
|
+
alt: alt || undefined,
|
|
60
|
+
style: {
|
|
61
|
+
width: width || undefined,
|
|
62
|
+
height: height || undefined,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}, [props?.node?.attrs]);
|
|
66
|
+
|
|
67
|
+
const imageMaxStyle = useMemo(() => {
|
|
68
|
+
const {
|
|
69
|
+
style: { width },
|
|
70
|
+
} = imgAttrs;
|
|
71
|
+
|
|
72
|
+
return { width: width === '100%' ? width : undefined };
|
|
73
|
+
}, [imgAttrs]);
|
|
74
|
+
|
|
75
|
+
function onImageLoad(e: Record<string, any>) {
|
|
76
|
+
setOriginalSize({
|
|
77
|
+
width: e.target.width,
|
|
78
|
+
height: e.target.height,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// https://github.com/scrumpy/tiptap/issues/361#issuecomment-540299541
|
|
83
|
+
function selectImage() {
|
|
84
|
+
const { editor, getPos } = props;
|
|
85
|
+
editor.commands.setNodeSelection(getPos());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const getMaxSize = useCallback(
|
|
89
|
+
throttle(() => {
|
|
90
|
+
const { editor } = props;
|
|
91
|
+
const { width } = getComputedStyle(editor.view.dom);
|
|
92
|
+
setMaxSize((prev) => {
|
|
93
|
+
return {
|
|
94
|
+
...prev,
|
|
95
|
+
width: Number.parseInt(width, 10),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}, IMAGE_THROTTLE_WAIT_TIME),
|
|
99
|
+
[props?.editor],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
function onMouseDown(e: MouseEvent, dir: string) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
|
|
106
|
+
const originalWidth = originalSize.width;
|
|
107
|
+
const originalHeight = originalSize.height;
|
|
108
|
+
const aspectRatio = originalWidth / originalHeight;
|
|
109
|
+
|
|
110
|
+
let width = Number(props.node.attrs.width);
|
|
111
|
+
let height = Number(props.node.attrs.height);
|
|
112
|
+
const maxWidth = maxSize.width;
|
|
113
|
+
|
|
114
|
+
if (width && !height) {
|
|
115
|
+
width = width > maxWidth ? maxWidth : width;
|
|
116
|
+
height = Math.round(width / aspectRatio);
|
|
117
|
+
} else if (height && !width) {
|
|
118
|
+
width = Math.round(height * aspectRatio);
|
|
119
|
+
width = width > maxWidth ? maxWidth : width;
|
|
120
|
+
} else if (!width && !height) {
|
|
121
|
+
width = originalWidth > maxWidth ? maxWidth : originalWidth;
|
|
122
|
+
height = Math.round(width / aspectRatio);
|
|
123
|
+
} else {
|
|
124
|
+
width = width > maxWidth ? maxWidth : width;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
setResizing(true);
|
|
128
|
+
|
|
129
|
+
setResizerState({
|
|
130
|
+
x: e.clientX,
|
|
131
|
+
y: e.clientY,
|
|
132
|
+
w: width,
|
|
133
|
+
h: height,
|
|
134
|
+
dir,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const onMouseMove = useCallback(
|
|
139
|
+
throttle((e: MouseEvent) => {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
e.stopPropagation();
|
|
142
|
+
|
|
143
|
+
if (!resizing) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const { x, w, dir } = resizerState;
|
|
148
|
+
|
|
149
|
+
const dx = (e.clientX - x) * (/l/.test(dir) ? -1 : 1);
|
|
150
|
+
// const dy = (e.clientY - y) * (/t/.test(dir) ? -1 : 1)
|
|
151
|
+
|
|
152
|
+
const width = clamp(w + dx, IMAGE_MIN_SIZE, maxSize.width);
|
|
153
|
+
const height = null;
|
|
154
|
+
|
|
155
|
+
props.updateAttributes({
|
|
156
|
+
width,
|
|
157
|
+
height,
|
|
158
|
+
});
|
|
159
|
+
}, IMAGE_THROTTLE_WAIT_TIME),
|
|
160
|
+
[resizing, resizerState, maxSize, props.updateAttributes],
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const onMouseUp = useCallback(
|
|
164
|
+
(e: MouseEvent) => {
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
if (!resizing) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setResizerState({
|
|
172
|
+
x: 0,
|
|
173
|
+
y: 0,
|
|
174
|
+
w: 0,
|
|
175
|
+
h: 0,
|
|
176
|
+
dir: '',
|
|
177
|
+
});
|
|
178
|
+
setResizing(false);
|
|
179
|
+
|
|
180
|
+
selectImage();
|
|
181
|
+
},
|
|
182
|
+
[resizing, selectImage],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const onEvents = useCallback(() => {
|
|
186
|
+
document?.addEventListener('mousemove', onMouseMove, true);
|
|
187
|
+
document?.addEventListener('mouseup', onMouseUp, true);
|
|
188
|
+
}, [onMouseMove, onMouseUp]);
|
|
189
|
+
|
|
190
|
+
const offEvents = useCallback(() => {
|
|
191
|
+
document?.removeEventListener('mousemove', onMouseMove, true);
|
|
192
|
+
document?.removeEventListener('mouseup', onMouseUp, true);
|
|
193
|
+
}, [onMouseMove, onMouseUp]);
|
|
194
|
+
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (resizing) {
|
|
197
|
+
onEvents();
|
|
198
|
+
} else {
|
|
199
|
+
offEvents();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return () => {
|
|
203
|
+
offEvents();
|
|
204
|
+
};
|
|
205
|
+
}, [resizing, onEvents, offEvents]);
|
|
206
|
+
|
|
207
|
+
const resizeOb: ResizeObserver = useMemo(() => {
|
|
208
|
+
return new ResizeObserver(() => getMaxSize());
|
|
209
|
+
}, [getMaxSize]);
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
resizeOb.observe(props.editor.view.dom);
|
|
213
|
+
|
|
214
|
+
return () => {
|
|
215
|
+
resizeOb.disconnect();
|
|
216
|
+
};
|
|
217
|
+
}, [props.editor.view.dom, resizeOb]);
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<NodeViewWrapper className="image-view"
|
|
221
|
+
style={{ ...imageMaxStyle, width: '100%', textAlign: align }}
|
|
222
|
+
>
|
|
223
|
+
<div
|
|
224
|
+
data-drag-handle
|
|
225
|
+
draggable="true"
|
|
226
|
+
style={imageMaxStyle}
|
|
227
|
+
className={`image-view__body ${props?.selected ? 'image-view__body--focused' : ''} ${
|
|
228
|
+
resizing ? 'image-view__body--resizing' : ''
|
|
229
|
+
}`}
|
|
230
|
+
>
|
|
231
|
+
<img
|
|
232
|
+
alt={imgAttrs.alt}
|
|
233
|
+
className="image-view__body__image block"
|
|
234
|
+
height="auto"
|
|
235
|
+
onClick={selectImage}
|
|
236
|
+
onLoad={onImageLoad}
|
|
237
|
+
src={imgAttrs.src}
|
|
238
|
+
style={imgAttrs.style}
|
|
239
|
+
/>
|
|
240
|
+
|
|
241
|
+
{props?.editor.view.editable && (props?.selected || resizing) && (
|
|
242
|
+
<div className="image-resizer">
|
|
243
|
+
{resizeDirections?.map((direction) => {
|
|
244
|
+
return (
|
|
245
|
+
<span
|
|
246
|
+
className={`image-resizer__handler image-resizer__handler--${direction}`}
|
|
247
|
+
key={`image-dir-${direction}`}
|
|
248
|
+
onMouseDown={(e: any) => onMouseDown(e, direction)}
|
|
249
|
+
>
|
|
250
|
+
</span>
|
|
251
|
+
);
|
|
252
|
+
})}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
</NodeViewWrapper>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export default ImageGifView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImageGif';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-named-default
|
|
2
|
+
import type { default as Mammoth } from 'mammoth';
|
|
3
|
+
|
|
4
|
+
import { Extension } from '@tiptap/core';
|
|
5
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
+
|
|
7
|
+
import ImportWordButton from 'reactjs-tiptap-editor-pro/extensions/ImportWord/components/ImportWordButton';
|
|
8
|
+
|
|
9
|
+
export interface ImportWordOptions extends GeneralOptions<ImportWordOptions> {
|
|
10
|
+
/** Function for converting Word files to HTML */
|
|
11
|
+
convert?: (file: File) => Promise<string>
|
|
12
|
+
|
|
13
|
+
/** Function for uploading images */
|
|
14
|
+
upload?: (files: File[]) => Promise<unknown>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* File Size limit(10 MB)
|
|
18
|
+
*
|
|
19
|
+
* @default 1024 * 1024 * 10
|
|
20
|
+
*/
|
|
21
|
+
limit?: number
|
|
22
|
+
mammothOptions?: Parameters<typeof Mammoth['convertToHtml']>[1]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ImportWord = Extension.create<ImportWordOptions>({
|
|
26
|
+
name: 'importWord',
|
|
27
|
+
addOptions() {
|
|
28
|
+
return {
|
|
29
|
+
...this.parent?.(),
|
|
30
|
+
upload: undefined,
|
|
31
|
+
convert: undefined,
|
|
32
|
+
limit: 1024 * 1024 * 10, // 10 MB
|
|
33
|
+
button: ({ editor, extension, t }) => {
|
|
34
|
+
const { convert, limit, mammothOptions } = extension.options;
|
|
35
|
+
return {
|
|
36
|
+
component: ImportWordButton,
|
|
37
|
+
componentProps: {
|
|
38
|
+
editor,
|
|
39
|
+
convert,
|
|
40
|
+
limit,
|
|
41
|
+
mammothOptions,
|
|
42
|
+
action: () => editor.commands.setHorizontalRule(),
|
|
43
|
+
disabled: !editor.can().setHorizontalRule(),
|
|
44
|
+
icon: 'Word',
|
|
45
|
+
shortcutKeys: ['alt', 'mod', 'S'],
|
|
46
|
+
tooltip: t('editor.importWord.tooltip'),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Editor } from '@tiptap/core';
|
|
4
|
+
import mammoth from 'mammoth';
|
|
5
|
+
|
|
6
|
+
import { ActionButton, useToast } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
8
|
+
import { hasExtension } from 'reactjs-tiptap-editor-pro/utils/utils';
|
|
9
|
+
|
|
10
|
+
function base64ToBlob(base64: any, mimeType: any) {
|
|
11
|
+
const byteCharacters = atob(base64.split(',')[1]);
|
|
12
|
+
const byteNumbers = Array.from({ length: byteCharacters.length });
|
|
13
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
14
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
15
|
+
}
|
|
16
|
+
const byteArray = new Uint8Array(byteNumbers as any);
|
|
17
|
+
return new Blob([byteArray], { type: mimeType });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function blobToFile(blob: any, fileName: any) {
|
|
21
|
+
return new File([blob], fileName, { type: blob.type });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ImportWordButtonProps {
|
|
25
|
+
editor: Editor
|
|
26
|
+
disabled?: boolean
|
|
27
|
+
icon?: string
|
|
28
|
+
tooltip?: string
|
|
29
|
+
shortcutKeys?: string[]
|
|
30
|
+
action?: () => boolean
|
|
31
|
+
convert?: (file: File) => Promise<string>
|
|
32
|
+
limit?: number
|
|
33
|
+
mammothOptions?: any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function ImportWordButton(props: ImportWordButtonProps) {
|
|
37
|
+
const { toast } = useToast();
|
|
38
|
+
const { t } = useLocale();
|
|
39
|
+
const [loading, setLoading] = useState(false);
|
|
40
|
+
const fileInput = useRef<HTMLInputElement>(null);
|
|
41
|
+
|
|
42
|
+
function triggerFileInput() {
|
|
43
|
+
fileInput.current?.click();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleFileChange(event: any) {
|
|
47
|
+
const file = event.target.files[0];
|
|
48
|
+
if (!file) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (file.size > props.limit!) {
|
|
52
|
+
toast({
|
|
53
|
+
variant: 'destructive',
|
|
54
|
+
title: t('editor.importWord.limitSize'),
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
importWord(file);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function filerImage(html: string) {
|
|
62
|
+
const parser = new DOMParser();
|
|
63
|
+
const doc = parser.parseFromString(html, 'text/html');
|
|
64
|
+
const images = doc.querySelectorAll('img');
|
|
65
|
+
if (images.length === 0) {
|
|
66
|
+
return doc.body.innerHTML;
|
|
67
|
+
}
|
|
68
|
+
const hasImage = hasExtension(props.editor, 'image');
|
|
69
|
+
if (hasImage) {
|
|
70
|
+
const uploadOptions = props.editor.extensionManager.extensions.find(
|
|
71
|
+
extension => extension.name === 'importWord',
|
|
72
|
+
)?.options;
|
|
73
|
+
if (uploadOptions && typeof uploadOptions.upload === 'function') {
|
|
74
|
+
const files: File[] = [];
|
|
75
|
+
// convert base64 image to blob file
|
|
76
|
+
for (const img of images) {
|
|
77
|
+
const originalSrc = img.getAttribute('src');
|
|
78
|
+
const blob = base64ToBlob(originalSrc, 'image/jpeg');
|
|
79
|
+
const file = blobToFile(blob, 'image.jpeg');
|
|
80
|
+
files.push(file);
|
|
81
|
+
}
|
|
82
|
+
const uploadRes = await uploadOptions.upload(files);
|
|
83
|
+
// images
|
|
84
|
+
for (const [i, img] of images.entries()) {
|
|
85
|
+
img.setAttribute('src', uploadRes[i].src);
|
|
86
|
+
const parent = img.parentElement;
|
|
87
|
+
if (parent?.tagName === 'P') {
|
|
88
|
+
parent.insertAdjacentElement('beforebegin', img);
|
|
89
|
+
if (!parent.hasChildNodes() && parent.textContent === '') {
|
|
90
|
+
parent.remove();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return doc.body.innerHTML;
|
|
95
|
+
} else {
|
|
96
|
+
console.warn('Image Upload method found, skip image conversion');
|
|
97
|
+
return doc.body.innerHTML;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
console.error('Image extension not found, unable to convert image');
|
|
101
|
+
return doc.body.innerHTML;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function importWord(importFile: File) {
|
|
106
|
+
setLoading(true);
|
|
107
|
+
try {
|
|
108
|
+
if (props.convert) {
|
|
109
|
+
const result = await props.convert(importFile);
|
|
110
|
+
handleResult(result);
|
|
111
|
+
} else {
|
|
112
|
+
const arrayBuffer = await importFile.arrayBuffer();
|
|
113
|
+
// TODO: add messages
|
|
114
|
+
const { value } = await mammoth.convertToHtml(
|
|
115
|
+
{ arrayBuffer },
|
|
116
|
+
props?.mammothOptions,
|
|
117
|
+
);
|
|
118
|
+
handleResult(value);
|
|
119
|
+
}
|
|
120
|
+
} finally {
|
|
121
|
+
setLoading(false);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function handleResult(htmlResult: string) {
|
|
125
|
+
const html = await filerImage(htmlResult);
|
|
126
|
+
props.editor.chain().setContent(html, true).run();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<div>
|
|
131
|
+
<ActionButton action={triggerFileInput}
|
|
132
|
+
disabled={props?.disabled}
|
|
133
|
+
icon={props?.icon}
|
|
134
|
+
loading={loading}
|
|
135
|
+
tooltip={props?.tooltip}
|
|
136
|
+
/>
|
|
137
|
+
|
|
138
|
+
<input
|
|
139
|
+
accept=".docx"
|
|
140
|
+
onChange={handleFileChange}
|
|
141
|
+
ref={fileInput}
|
|
142
|
+
type="file"
|
|
143
|
+
style={{
|
|
144
|
+
display: 'none',
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export default ImportWordButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImportWord';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { Editor } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
5
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
+
import { IndentProps, createIndentCommand } from 'reactjs-tiptap-editor-pro/utils/indent';
|
|
7
|
+
|
|
8
|
+
export interface IndentOptions extends GeneralOptions<IndentOptions> {
|
|
9
|
+
types: string[]
|
|
10
|
+
minIndent: number
|
|
11
|
+
maxIndent: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '@tiptap/core' {
|
|
15
|
+
interface Commands<ReturnType> {
|
|
16
|
+
indent: {
|
|
17
|
+
/**
|
|
18
|
+
* Set the indent attribute
|
|
19
|
+
*/
|
|
20
|
+
indent: () => ReturnType
|
|
21
|
+
/**
|
|
22
|
+
* Set the outdent attribute
|
|
23
|
+
*/
|
|
24
|
+
outdent: () => ReturnType
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Indent = Extension.create<IndentOptions>({
|
|
30
|
+
name: 'indent',
|
|
31
|
+
addOptions() {
|
|
32
|
+
return {
|
|
33
|
+
...this.parent?.(),
|
|
34
|
+
types: ['paragraph', 'heading', 'blockquote'],
|
|
35
|
+
minIndent: IndentProps.min,
|
|
36
|
+
maxIndent: IndentProps.max,
|
|
37
|
+
button({ editor, t }: { editor: Editor, t: (...args: any[]) => string }) {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
component: ActionButton,
|
|
41
|
+
componentProps: {
|
|
42
|
+
action: () => {
|
|
43
|
+
editor.commands.indent();
|
|
44
|
+
},
|
|
45
|
+
shortcutKeys: ['Tab'],
|
|
46
|
+
icon: 'IndentIncrease',
|
|
47
|
+
tooltip: t('editor.indent.tooltip'),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
component: ActionButton,
|
|
52
|
+
componentProps: {
|
|
53
|
+
action: () => {
|
|
54
|
+
editor.commands.outdent();
|
|
55
|
+
},
|
|
56
|
+
shortcutKeys: ['Shift', 'Tab'],
|
|
57
|
+
icon: 'IndentDecrease',
|
|
58
|
+
tooltip: t('editor.outdent.tooltip'),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
addGlobalAttributes() {
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
types: this.options.types,
|
|
70
|
+
attributes: {
|
|
71
|
+
indent: {
|
|
72
|
+
default: 0,
|
|
73
|
+
parseHTML: (element) => {
|
|
74
|
+
const identAttr = element.dataset.indent;
|
|
75
|
+
return (identAttr ? Number.parseInt(identAttr, 10) : 0) || 0;
|
|
76
|
+
},
|
|
77
|
+
renderHTML: (attributes) => {
|
|
78
|
+
if (!attributes.indent) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
return { 'data-indent': attributes.indent };
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
addCommands() {
|
|
90
|
+
return {
|
|
91
|
+
indent: () =>
|
|
92
|
+
createIndentCommand({
|
|
93
|
+
delta: IndentProps.more,
|
|
94
|
+
types: this.options.types,
|
|
95
|
+
}),
|
|
96
|
+
outdent: () =>
|
|
97
|
+
createIndentCommand({
|
|
98
|
+
delta: IndentProps.less,
|
|
99
|
+
types: this.options.types,
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
addKeyboardShortcuts() {
|
|
105
|
+
return {
|
|
106
|
+
'Tab': () => this.editor.commands.indent(),
|
|
107
|
+
'Shift-Tab': () => this.editor.commands.outdent(),
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Indent';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { ItalicOptions as TiptapItalicOptions } from '@tiptap/extension-italic';
|
|
3
|
+
import TiptapItalic from '@tiptap/extension-italic';
|
|
4
|
+
|
|
5
|
+
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
6
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
7
|
+
|
|
8
|
+
export interface ItalicOptions extends TiptapItalicOptions, GeneralOptions<ItalicOptions> {}
|
|
9
|
+
|
|
10
|
+
export const Italic = TiptapItalic.extend<ItalicOptions>({
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
...this.parent?.(),
|
|
14
|
+
button({ editor, t }: { editor: Editor, t: (...args: any[]) => string }) {
|
|
15
|
+
return {
|
|
16
|
+
component: ActionButton,
|
|
17
|
+
componentProps: {
|
|
18
|
+
action: () => editor.commands.toggleItalic(),
|
|
19
|
+
isActive: () => editor.isActive('italic') || false,
|
|
20
|
+
disabled: !editor.can().toggleItalic(),
|
|
21
|
+
shortcutKeys: ['mod', 'I'],
|
|
22
|
+
icon: 'Italic',
|
|
23
|
+
tooltip: t('editor.italic.tooltip'),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Italic';
|