reactjs-tiptap-editor-pro 0.2.31 → 0.2.33
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/ColorPicker-MEAh4MhG.js +28181 -0
- package/lib/ColorPicker-ZncOwjAP.cjs +142 -0
- package/lib/extension-bundle.cjs +133 -0
- package/lib/extension-bundle.d.cts +947 -0
- package/lib/extension-bundle.d.ts +947 -0
- package/lib/extension-bundle.js +23921 -0
- package/lib/index.cjs +140 -0
- package/lib/index.d.cts +513 -0
- package/lib/index.d.ts +513 -0
- package/lib/index.js +3700 -0
- package/lib/locale-bundle-DiqW5jwb.cjs +1 -0
- package/lib/locale-bundle-DxCAtRDI.js +1487 -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/lucide-react-BFZtMawV.js +30462 -0
- package/lib/lucide-react-CMPhLW1m.cjs +7851 -0
- package/lib/style.css +1 -0
- package/package.json +58 -5
- package/src/components/ActionButton.tsx +0 -103
- package/src/components/ActionMenuButton.tsx +0 -76
- package/src/components/BubbleMenu.tsx +0 -93
- package/src/components/CharactorCount.tsx +0 -50
- package/src/components/ColorPicker.tsx +0 -272
- package/src/components/RichTextEditor.tsx +0 -212
- package/src/components/SizeSetter/SizeSetter.tsx +0 -102
- package/src/components/Toolbar.tsx +0 -108
- package/src/components/icons/Activity.tsx +0 -19
- package/src/components/icons/Animas.tsx +0 -24
- package/src/components/icons/AspectRatio.tsx +0 -13
- package/src/components/icons/Blockquote.tsx +0 -17
- package/src/components/icons/ColumnAddLeft.tsx +0 -7
- package/src/components/icons/ColumnAddRight.tsx +0 -7
- package/src/components/icons/DeleteColumn.tsx +0 -26
- package/src/components/icons/DeleteRow.tsx +0 -26
- package/src/components/icons/Direction.tsx +0 -7
- package/src/components/icons/Excalidraw.tsx +0 -7
- package/src/components/icons/ExportPdf.tsx +0 -8
- package/src/components/icons/ExportWord.tsx +0 -24
- package/src/components/icons/FileWordOutline.tsx +0 -13
- package/src/components/icons/Flag.tsx +0 -19
- package/src/components/icons/Food.tsx +0 -20
- package/src/components/icons/GIfIcon.tsx +0 -10
- package/src/components/icons/Icon.tsx +0 -30
- package/src/components/icons/ImportWord.tsx +0 -23
- package/src/components/icons/LeftToRight.tsx +0 -7
- package/src/components/icons/LineHeight.tsx +0 -13
- package/src/components/icons/MenuDown.tsx +0 -24
- package/src/components/icons/Mermaid.tsx +0 -13
- package/src/components/icons/NoFill.tsx +0 -7
- package/src/components/icons/Object.tsx +0 -24
- package/src/components/icons/RightToLeft.tsx +0 -7
- package/src/components/icons/SizeL.tsx +0 -9
- package/src/components/icons/SizeM.tsx +0 -13
- package/src/components/icons/SizeS.tsx +0 -13
- package/src/components/icons/Symbol.tsx +0 -19
- package/src/components/icons/Travel.tsx +0 -24
- package/src/components/icons/Twitter.tsx +0 -7
- package/src/components/icons/icons.ts +0 -212
- package/src/components/icons/index.ts +0 -12
- package/src/components/index.ts +0 -9
- package/src/components/menus/bubble.ts +0 -395
- package/src/components/menus/components/BubbleMenuContent.tsx +0 -15
- package/src/components/menus/components/BubbleMenuDrawer.tsx +0 -128
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +0 -91
- package/src/components/menus/components/BubbleMenuIframe.tsx +0 -143
- package/src/components/menus/components/BubbleMenuKatex.tsx +0 -136
- package/src/components/menus/components/BubbleMenuLink.tsx +0 -99
- package/src/components/menus/components/BubbleMenuMedia.tsx +0 -235
- package/src/components/menus/components/BubbleMenuMermaid.tsx +0 -128
- package/src/components/menus/components/BubbleMenuText.tsx +0 -102
- package/src/components/menus/components/BubbleMenuTwitter.tsx +0 -91
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +0 -59
- package/src/components/menus/components/ContentMenu.tsx +0 -396
- package/src/components/menus/components/TableBubbleMenu.tsx +0 -362
- package/src/components/menus/index.ts +0 -7
- package/src/components/ui/button.tsx +0 -56
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -128
- package/src/components/ui/dropdown-menu.tsx +0 -203
- package/src/components/ui/emoji-picker.tsx +0 -166
- package/src/components/ui/index.ts +0 -14
- package/src/components/ui/input.tsx +0 -25
- package/src/components/ui/label.tsx +0 -26
- package/src/components/ui/popover.tsx +0 -31
- package/src/components/ui/select.tsx +0 -162
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/textarea.tsx +0 -24
- package/src/components/ui/toast.tsx +0 -129
- package/src/components/ui/toaster.tsx +0 -44
- package/src/components/ui/toggle.tsx +0 -45
- package/src/components/ui/tooltip.tsx +0 -30
- package/src/components/ui/use-toast.ts +0 -197
- package/src/constants/index.ts +0 -223
- package/src/constants/resetCSS.ts +0 -139
- package/src/extension-bundle.ts +0 -2
- package/src/extensions/Attachment/Attachment.ts +0 -144
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +0 -69
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +0 -28
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +0 -155
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +0 -23
- package/src/extensions/Attachment/index.ts +0 -1
- package/src/extensions/BaseKit.ts +0 -253
- package/src/extensions/Blockquote/Blockquote.ts +0 -31
- package/src/extensions/Blockquote/index.ts +0 -1
- package/src/extensions/Bold/Bold.ts +0 -26
- package/src/extensions/Bold/index.ts +0 -1
- package/src/extensions/BulletList/BulletList.ts +0 -28
- package/src/extensions/BulletList/index.ts +0 -1
- package/src/extensions/Clear/Clear.ts +0 -24
- package/src/extensions/Clear/index.ts +0 -1
- package/src/extensions/Code/Code.ts +0 -26
- package/src/extensions/Code/index.ts +0 -1
- package/src/extensions/CodeBlock/CodeBlock.ts +0 -54
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +0 -66
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +0 -89
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +0 -81
- package/src/extensions/CodeBlock/highlighter.ts +0 -132
- package/src/extensions/CodeBlock/index.ts +0 -1
- package/src/extensions/CodeBlock/shiki-plugin.ts +0 -213
- package/src/extensions/Color/Color.ts +0 -52
- package/src/extensions/Color/components/ColorActionButton.tsx +0 -104
- package/src/extensions/Color/index.ts +0 -1
- package/src/extensions/Document/Document.ts +0 -8
- package/src/extensions/Document/index.ts +0 -1
- package/src/extensions/Drawer/Drawer.ts +0 -177
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +0 -85
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +0 -598
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +0 -500
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +0 -239
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +0 -238
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +0 -260
- package/src/extensions/Drawer/index.ts +0 -1
- package/src/extensions/Emoji/Emoji.ts +0 -146
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +0 -103
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +0 -1858
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +0 -61
- package/src/extensions/Emoji/index.ts +0 -1
- package/src/extensions/Excalidraw/Excalidraw.ts +0 -123
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +0 -138
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +0 -178
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +0 -43
- package/src/extensions/Excalidraw/index.ts +0 -1
- package/src/extensions/ExportPdf/ExportPdf.ts +0 -25
- package/src/extensions/ExportPdf/index.ts +0 -1
- package/src/extensions/ExportWord/ExportWord.ts +0 -87
- package/src/extensions/ExportWord/index.ts +0 -1
- package/src/extensions/FontFamily/FontFamily.ts +0 -64
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +0 -97
- package/src/extensions/FontFamily/index.ts +0 -1
- package/src/extensions/FontSize/FontSize.ts +0 -119
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +0 -84
- package/src/extensions/FontSize/index.ts +0 -1
- package/src/extensions/FormatPainter/FormatPainter.ts +0 -121
- package/src/extensions/FormatPainter/index.ts +0 -1
- package/src/extensions/Heading/Heading.ts +0 -57
- package/src/extensions/Heading/components/HeadingButton.tsx +0 -96
- package/src/extensions/Heading/index.ts +0 -1
- package/src/extensions/Highlight/Highlight.ts +0 -36
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +0 -108
- package/src/extensions/Highlight/index.ts +0 -1
- package/src/extensions/History/History.ts +0 -39
- package/src/extensions/History/components/HistoryActionButton.tsx +0 -74
- package/src/extensions/History/index.ts +0 -1
- package/src/extensions/HorizontalRule/HorizontalRule.ts +0 -42
- package/src/extensions/HorizontalRule/index.ts +0 -1
- package/src/extensions/Iframe/Iframe.ts +0 -140
- package/src/extensions/Iframe/components/IframeNodeView.tsx +0 -92
- package/src/extensions/Iframe/components/index.module.scss +0 -40
- package/src/extensions/Iframe/embed.ts +0 -487
- package/src/extensions/Iframe/index.ts +0 -1
- package/src/extensions/Image/Image.ts +0 -303
- package/src/extensions/Image/components/ActionImageButton.tsx +0 -186
- package/src/extensions/Image/components/ImageCropper.tsx +0 -198
- package/src/extensions/Image/components/ImageView.tsx +0 -271
- package/src/extensions/Image/index.ts +0 -1
- package/src/extensions/Image/store.ts +0 -15
- package/src/extensions/ImageGif/ImageGif.ts +0 -176
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +0 -138
- package/src/extensions/ImageGif/components/ImageGifView.tsx +0 -260
- package/src/extensions/ImageGif/index.ts +0 -1
- package/src/extensions/ImportWord/ImportWord.ts +0 -52
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +0 -151
- package/src/extensions/ImportWord/index.ts +0 -1
- package/src/extensions/Indent/Indent.ts +0 -110
- package/src/extensions/Indent/index.ts +0 -1
- package/src/extensions/Italic/Italic.ts +0 -29
- package/src/extensions/Italic/index.ts +0 -1
- package/src/extensions/Katex/Katex.ts +0 -109
- package/src/extensions/Katex/components/KatexActiveButton.tsx +0 -117
- package/src/extensions/Katex/components/KatexWrapper.tsx +0 -53
- package/src/extensions/Katex/index.ts +0 -1
- package/src/extensions/LineHeight/LineHeight.ts +0 -76
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +0 -93
- package/src/extensions/LineHeight/index.ts +0 -1
- package/src/extensions/Link/Link.ts +0 -92
- package/src/extensions/Link/components/LinkEditBlock.tsx +0 -110
- package/src/extensions/Link/components/LinkEditPopover.tsx +0 -46
- package/src/extensions/Link/components/LinkViewBlock.tsx +0 -54
- package/src/extensions/Link/index.ts +0 -1
- package/src/extensions/ListItem/ListItem.ts +0 -1
- package/src/extensions/ListItem/index.ts +0 -1
- package/src/extensions/Mention/Mention.ts +0 -100
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +0 -94
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +0 -38
- package/src/extensions/Mention/index.ts +0 -1
- package/src/extensions/Mermaid/Mermaid.ts +0 -177
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +0 -155
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +0 -151
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +0 -260
- package/src/extensions/Mermaid/index.ts +0 -1
- package/src/extensions/MoreMark/MoreMark.ts +0 -102
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +0 -97
- package/src/extensions/MoreMark/index.ts +0 -1
- package/src/extensions/MultiColumn/Column.ts +0 -36
- package/src/extensions/MultiColumn/MultiColumn.ts +0 -111
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +0 -22
- package/src/extensions/MultiColumn/index.ts +0 -3
- package/src/extensions/OrderedList/OrderedList.ts +0 -28
- package/src/extensions/OrderedList/index.ts +0 -1
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +0 -395
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +0 -190
- package/src/extensions/SearchAndReplace/index.ts +0 -1
- package/src/extensions/Selection/Selection.ts +0 -32
- package/src/extensions/Selection/index.ts +0 -1
- package/src/extensions/SlashCommand/SlashCommand.ts +0 -255
- package/src/extensions/SlashCommand/components/CommandsList.tsx +0 -180
- package/src/extensions/SlashCommand/groups.ts +0 -183
- package/src/extensions/SlashCommand/index.ts +0 -1
- package/src/extensions/SlashCommand/types.ts +0 -24
- package/src/extensions/Strike/Strike.ts +0 -26
- package/src/extensions/Strike/index.ts +0 -1
- package/src/extensions/Subscript/Subscript.ts +0 -88
- package/src/extensions/Subscript/index.ts +0 -1
- package/src/extensions/Table/Cell.ts +0 -131
- package/src/extensions/Table/Header.ts +0 -93
- package/src/extensions/Table/Row.ts +0 -8
- package/src/extensions/Table/Table.ts +0 -60
- package/src/extensions/Table/cell-background.ts +0 -112
- package/src/extensions/Table/components/CreateTablePopover.tsx +0 -132
- package/src/extensions/Table/components/TableActionButton.tsx +0 -42
- package/src/extensions/Table/index.ts +0 -6
- package/src/extensions/Table/utils.ts +0 -352
- package/src/extensions/TableOfContent/TableOfContent.ts +0 -124
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +0 -116
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +0 -27
- package/src/extensions/TableOfContent/components/index.module.scss +0 -40
- package/src/extensions/TableOfContent/index.ts +0 -1
- package/src/extensions/TaskList/TaskList.ts +0 -46
- package/src/extensions/TaskList/index.ts +0 -1
- package/src/extensions/TextAlign/TextAlign.ts +0 -68
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +0 -103
- package/src/extensions/TextAlign/index.ts +0 -1
- package/src/extensions/TextBubble/TextBubble.ts +0 -22
- package/src/extensions/TextBubble/components/TextDropdown.tsx +0 -146
- package/src/extensions/TextBubble/index.ts +0 -1
- package/src/extensions/TextDirection/TextDirection.ts +0 -97
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +0 -103
- package/src/extensions/TextDirection/index.ts +0 -1
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -71
- package/src/extensions/TrailingNode/index.ts +0 -1
- package/src/extensions/Twitter/Twitter.ts +0 -161
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +0 -68
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +0 -30
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +0 -41
- package/src/extensions/Twitter/index.ts +0 -1
- package/src/extensions/UnderLine/Underline.ts +0 -30
- package/src/extensions/UnderLine/index.ts +0 -1
- package/src/extensions/Video/Video.ts +0 -204
- package/src/extensions/Video/components/ActiveVideoButton.tsx +0 -191
- package/src/extensions/Video/index.ts +0 -1
- package/src/extensions/Video/store.ts +0 -15
- package/src/extensions/index.ts +0 -122
- package/src/hooks/useActive.tsx +0 -24
- package/src/hooks/useAttributes.tsx +0 -45
- package/src/hooks/useCopy.tsx +0 -20
- package/src/hooks/useEditorState.tsx +0 -23
- package/src/hooks/useExtension.tsx +0 -29
- package/src/index.ts +0 -8
- package/src/lib/utils.ts +0 -7
- package/src/locale-bundle.ts +0 -3
- package/src/locales/en.ts +0 -173
- package/src/locales/hu.ts +0 -173
- package/src/locales/index.tsx +0 -163
- package/src/locales/pt-br.ts +0 -173
- package/src/locales/vi.ts +0 -173
- package/src/locales/zh-cn.ts +0 -173
- package/src/plugins/DragHandle/index.ts +0 -375
- package/src/plugins/DragHandle/range.ts +0 -114
- package/src/plugins/DragHandle/utils.ts +0 -80
- package/src/plugins/image-upload.ts +0 -160
- package/src/store/ProviderRichText.tsx +0 -53
- package/src/store/editableEditor.ts +0 -15
- package/src/store/fast-context.tsx +0 -70
- package/src/store/store.ts +0 -35
- package/src/styles/ProseMirror.scss +0 -176
- package/src/styles/columns.scss +0 -23
- package/src/styles/editor.scss +0 -411
- package/src/styles/global.scss +0 -87
- package/src/styles/index.scss +0 -5
- package/src/styles/mention.scss +0 -6
- package/src/theme/theme.ts +0 -15
- package/src/types.ts +0 -271
- package/src/utils/_event.ts +0 -55
- package/src/utils/color.ts +0 -67
- package/src/utils/columns.ts +0 -142
- package/src/utils/customEvents/customEvents.ts +0 -18
- package/src/utils/customEvents/events.constant.ts +0 -11
- package/src/utils/delete-node.ts +0 -46
- package/src/utils/dom-dataset.ts +0 -121
- package/src/utils/download.ts +0 -17
- package/src/utils/dynamicCSS.ts +0 -192
- package/src/utils/editor-container-size.ts +0 -28
- package/src/utils/file.ts +0 -112
- package/src/utils/getRenderContainer.ts +0 -41
- package/src/utils/indent.ts +0 -99
- package/src/utils/is-mobile.ts +0 -57
- package/src/utils/json.ts +0 -18
- package/src/utils/line-height.ts +0 -109
- package/src/utils/lru-cache.ts +0 -145
- package/src/utils/mitt.ts +0 -114
- package/src/utils/node.ts +0 -92
- package/src/utils/pdf.ts +0 -72
- package/src/utils/plateform.ts +0 -49
- package/src/utils/shortId.ts +0 -5
- package/src/utils/storage.ts +0 -18
- package/src/utils/utils.ts +0 -71
- package/src/vite-env.d.ts +0 -3
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
import { ActionButton, Popover, PopoverContent, PopoverTrigger } from 'reactjs-tiptap-editor-pro/components';
|
|
5
|
-
import { EmojiPicker, EmojiPickerContent, EmojiPickerFooter, EmojiPickerSearch } from 'reactjs-tiptap-editor-pro/components/ui/emoji-picker';
|
|
6
|
-
|
|
7
|
-
interface IProps {
|
|
8
|
-
showClear?: boolean
|
|
9
|
-
onSelectEmoji: (arg: string) => void
|
|
10
|
-
children: React.ReactNode
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function EmojiPickerWrap({ onSelectEmoji, children }: IProps) {
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<Popover modal>
|
|
17
|
-
<PopoverTrigger asChild>
|
|
18
|
-
{children}
|
|
19
|
-
</PopoverTrigger>
|
|
20
|
-
|
|
21
|
-
<PopoverContent align="start"
|
|
22
|
-
className="size-full p-2"
|
|
23
|
-
hideWhenDetached
|
|
24
|
-
side="bottom"
|
|
25
|
-
>
|
|
26
|
-
<EmojiPicker
|
|
27
|
-
className="!h-[342px]"
|
|
28
|
-
onEmojiSelect={({ emoji }) => {
|
|
29
|
-
onSelectEmoji(emoji);
|
|
30
|
-
}}
|
|
31
|
-
>
|
|
32
|
-
<EmojiPickerSearch />
|
|
33
|
-
<EmojiPickerContent />
|
|
34
|
-
<EmojiPickerFooter />
|
|
35
|
-
</EmojiPicker>
|
|
36
|
-
</PopoverContent>
|
|
37
|
-
</Popover>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function EmojiPickerComponent({ editor, icon, ...props }: any) {
|
|
42
|
-
const setEmoji = useCallback(
|
|
43
|
-
(emoji: any) => {
|
|
44
|
-
const { selection } = editor.state;
|
|
45
|
-
const { $anchor } = selection;
|
|
46
|
-
return editor.chain().insertContentAt($anchor.pos, emoji).run();
|
|
47
|
-
},
|
|
48
|
-
[editor],
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<EmojiPickerWrap onSelectEmoji={setEmoji}>
|
|
53
|
-
<ActionButton
|
|
54
|
-
icon={icon}
|
|
55
|
-
tooltip={props?.tooltip}
|
|
56
|
-
/>
|
|
57
|
-
</EmojiPickerWrap>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default EmojiPickerComponent;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Emoji';
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { Node, mergeAttributes, nodeInputRule } from '@tiptap/core';
|
|
3
|
-
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
4
|
-
|
|
5
|
-
import { ExcalidrawActiveButton } from 'reactjs-tiptap-editor-pro/extensions/Excalidraw/components/ExcalidrawActiveButton';
|
|
6
|
-
import NodeViewExcalidraw from 'reactjs-tiptap-editor-pro/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw';
|
|
7
|
-
import { getDatasetAttribute, nodeAttrsToDataset } from 'reactjs-tiptap-editor-pro/utils/dom-dataset';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_MIND_DATA = { elements: [] };
|
|
10
|
-
|
|
11
|
-
export interface IExcalidrawAttrs {
|
|
12
|
-
defaultShowPicker?: boolean
|
|
13
|
-
createUser?: any
|
|
14
|
-
width?: number | string
|
|
15
|
-
height?: number
|
|
16
|
-
data?: Record<string, unknown>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare module '@tiptap/core' {
|
|
20
|
-
interface Commands<ReturnType> {
|
|
21
|
-
excalidraw: {
|
|
22
|
-
setExcalidraw: (attrs?: IExcalidrawAttrs) => ReturnType
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const Excalidraw = Node.create({
|
|
28
|
-
name: 'excalidraw',
|
|
29
|
-
group: 'block',
|
|
30
|
-
selectable: true,
|
|
31
|
-
atom: true,
|
|
32
|
-
draggable: true,
|
|
33
|
-
inline: false,
|
|
34
|
-
|
|
35
|
-
addAttributes() {
|
|
36
|
-
return {
|
|
37
|
-
defaultShowPicker: {
|
|
38
|
-
default: false,
|
|
39
|
-
},
|
|
40
|
-
createUser: {
|
|
41
|
-
default: null,
|
|
42
|
-
},
|
|
43
|
-
width: {
|
|
44
|
-
default: '100%',
|
|
45
|
-
parseHTML: getDatasetAttribute('width'),
|
|
46
|
-
},
|
|
47
|
-
height: {
|
|
48
|
-
default: 240,
|
|
49
|
-
parseHTML: getDatasetAttribute('height'),
|
|
50
|
-
},
|
|
51
|
-
data: {
|
|
52
|
-
default: DEFAULT_MIND_DATA,
|
|
53
|
-
parseHTML: getDatasetAttribute('data', true),
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
addOptions() {
|
|
59
|
-
return {
|
|
60
|
-
...this.parent?.(),
|
|
61
|
-
HTMLAttributes: {
|
|
62
|
-
class: 'excalidraw',
|
|
63
|
-
},
|
|
64
|
-
button: ({ editor }: any) => ({
|
|
65
|
-
component: ExcalidrawActiveButton,
|
|
66
|
-
componentProps: {
|
|
67
|
-
editor,
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
parseHTML() {
|
|
74
|
-
return [
|
|
75
|
-
{
|
|
76
|
-
tag: 'div[class=excalidraw]',
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
renderHTML({ HTMLAttributes, node }: any) {
|
|
82
|
-
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, nodeAttrsToDataset(node))];
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
addCommands() {
|
|
86
|
-
return {
|
|
87
|
-
setExcalidraw:
|
|
88
|
-
options =>
|
|
89
|
-
({ tr, commands, chain }) => {
|
|
90
|
-
options = options || {};
|
|
91
|
-
options.data = options.data || DEFAULT_MIND_DATA;
|
|
92
|
-
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
if (tr.selection?.node?.type?.name == this.name) {
|
|
95
|
-
return commands.updateAttributes(this.name, options);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return chain()
|
|
99
|
-
.insertContent({
|
|
100
|
-
type: this.name,
|
|
101
|
-
attrs: options,
|
|
102
|
-
})
|
|
103
|
-
.run();
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
addNodeView() {
|
|
109
|
-
return ReactNodeViewRenderer(NodeViewExcalidraw);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
addInputRules() {
|
|
113
|
-
return [
|
|
114
|
-
nodeInputRule({
|
|
115
|
-
find: /^\$excalidraw\$$/,
|
|
116
|
-
type: this.type,
|
|
117
|
-
getAttributes: () => {
|
|
118
|
-
return { width: '100%' };
|
|
119
|
-
},
|
|
120
|
-
}),
|
|
121
|
-
];
|
|
122
|
-
},
|
|
123
|
-
});
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
4
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
5
|
-
|
|
6
|
-
import type { Editor } from '@tiptap/core';
|
|
7
|
-
|
|
8
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components/ActionButton';
|
|
9
|
-
import { Button } from 'reactjs-tiptap-editor-pro/components/ui';
|
|
10
|
-
import { Dialog, DialogContent, DialogFooter, DialogTitle, DialogTrigger } from 'reactjs-tiptap-editor-pro/components/ui/dialog';
|
|
11
|
-
import { OPEN_EXCALIDRAW_SETTING_MODAL, cancelSubject, subject } from 'reactjs-tiptap-editor-pro/utils/_event';
|
|
12
|
-
|
|
13
|
-
interface IProps {
|
|
14
|
-
editor: Editor
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const ExcalidrawActiveButton: React.FC<IProps> = ({ editor }) => {
|
|
18
|
-
const [Excalidraw, setExcalidraw] = useState<any>(null);
|
|
19
|
-
const [data, setData] = useState({});
|
|
20
|
-
const [initialData, setInitialData] = useState({ elements: [], appState: { isLoading: false }, files: null });
|
|
21
|
-
const [visible, toggleVisible] = useState(false);
|
|
22
|
-
const [loading, toggleLoading] = useState(true);
|
|
23
|
-
const [error, setError] = useState<any>(null);
|
|
24
|
-
|
|
25
|
-
const renderEditor = useCallback(
|
|
26
|
-
(div: any) => {
|
|
27
|
-
if (!div)
|
|
28
|
-
return;
|
|
29
|
-
|
|
30
|
-
import('@excalidraw/excalidraw')
|
|
31
|
-
.then((res) => {
|
|
32
|
-
setExcalidraw(res.Excalidraw);
|
|
33
|
-
})
|
|
34
|
-
.catch(setError)
|
|
35
|
-
.finally(() => toggleLoading(false));
|
|
36
|
-
},
|
|
37
|
-
[toggleLoading],
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const renderExcalidraw: any = useCallback((app: any) => {
|
|
41
|
-
setTimeout(() => {
|
|
42
|
-
app.refresh();
|
|
43
|
-
});
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
const onChange = useCallback((elements: any, appState: any, files: any) => {
|
|
47
|
-
// appState.collaborators = [];
|
|
48
|
-
setData({
|
|
49
|
-
elements,
|
|
50
|
-
appState: { isLoading: false },
|
|
51
|
-
files,
|
|
52
|
-
});
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const save = useCallback(() => {
|
|
56
|
-
if (!Excalidraw) {
|
|
57
|
-
toggleVisible(false);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// const currentScrollTop = document.querySelector('main#js-tocs-container')?.scrollTop
|
|
62
|
-
editor.chain().focus().setExcalidraw({ data }).run();
|
|
63
|
-
// setTimeout(() => {
|
|
64
|
-
// // @ts-expect-error
|
|
65
|
-
// document.querySelector('main#js-tocs-container').scrollTop = currentScrollTop
|
|
66
|
-
// })
|
|
67
|
-
toggleVisible(false);
|
|
68
|
-
}, [Excalidraw, editor, data, toggleVisible]);
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const handler = (data: any) => {
|
|
72
|
-
toggleVisible(true);
|
|
73
|
-
data && setInitialData(data.data);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
subject(OPEN_EXCALIDRAW_SETTING_MODAL, handler);
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
cancelSubject(OPEN_EXCALIDRAW_SETTING_MODAL, handler);
|
|
80
|
-
};
|
|
81
|
-
}, [editor, toggleVisible]);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Dialog
|
|
85
|
-
onOpenChange={toggleVisible}
|
|
86
|
-
open={visible}
|
|
87
|
-
>
|
|
88
|
-
<DialogTrigger asChild>
|
|
89
|
-
<ActionButton
|
|
90
|
-
action={() => toggleVisible(true)}
|
|
91
|
-
icon="Excalidraw"
|
|
92
|
-
tooltip="Excalidraw"
|
|
93
|
-
/>
|
|
94
|
-
</DialogTrigger>
|
|
95
|
-
|
|
96
|
-
<DialogContent className="z-[99999] !max-w-[1300px]">
|
|
97
|
-
<DialogTitle>
|
|
98
|
-
Excalidraw
|
|
99
|
-
</DialogTitle>
|
|
100
|
-
|
|
101
|
-
<div style={{ height: '100%', borderWidth: 1 }}>
|
|
102
|
-
{loading && (
|
|
103
|
-
<p>
|
|
104
|
-
Loading...
|
|
105
|
-
</p>
|
|
106
|
-
)}
|
|
107
|
-
|
|
108
|
-
{error && <p>
|
|
109
|
-
{(error && error.message) || 'Error'}
|
|
110
|
-
</p>}
|
|
111
|
-
|
|
112
|
-
<div ref={renderEditor}
|
|
113
|
-
style={{ width: '100%', height: 600 }}
|
|
114
|
-
>
|
|
115
|
-
{!loading && !error && Excalidraw
|
|
116
|
-
? (
|
|
117
|
-
<Excalidraw initialData={initialData}
|
|
118
|
-
langCode="en"
|
|
119
|
-
onChange={onChange}
|
|
120
|
-
ref={renderExcalidraw}
|
|
121
|
-
/>
|
|
122
|
-
)
|
|
123
|
-
: null}
|
|
124
|
-
</div>
|
|
125
|
-
</div>
|
|
126
|
-
|
|
127
|
-
<DialogFooter>
|
|
128
|
-
<Button
|
|
129
|
-
onClick={save}
|
|
130
|
-
type="button"
|
|
131
|
-
>
|
|
132
|
-
Save changes
|
|
133
|
-
</Button>
|
|
134
|
-
</DialogFooter>
|
|
135
|
-
</DialogContent>
|
|
136
|
-
</Dialog>
|
|
137
|
-
);
|
|
138
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { NodeViewWrapper } from '@tiptap/react';
|
|
4
|
-
import clsx from 'clsx';
|
|
5
|
-
import deepEqual from 'deep-equal';
|
|
6
|
-
import { Resizable } from 're-resizable';
|
|
7
|
-
import VisibilitySensor from 'react-visibility-sensor';
|
|
8
|
-
|
|
9
|
-
// import { clamp, getEditorContainerDOMSize } from 'reactjs-tiptap-editor-pro/utils'
|
|
10
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components/ActionButton';
|
|
11
|
-
import { Excalidraw } from 'reactjs-tiptap-editor-pro/extensions/Excalidraw/Excalidraw';
|
|
12
|
-
import { clamp } from 'reactjs-tiptap-editor-pro/utils/utils';
|
|
13
|
-
|
|
14
|
-
import styles from './index.module.scss';
|
|
15
|
-
|
|
16
|
-
const MIN_ZOOM = 10;
|
|
17
|
-
const MAX_ZOOM = 200;
|
|
18
|
-
const ZOOM_STEP = 15;
|
|
19
|
-
|
|
20
|
-
const INHERIT_SIZE_STYLE = { width: '100%', height: '100%', maxWidth: '100%' };
|
|
21
|
-
|
|
22
|
-
function NodeViewExcalidraw({ editor, node, updateAttributes }: any) {
|
|
23
|
-
const exportToSvgRef: any = useRef(null);
|
|
24
|
-
// const isEditable = editor.isEditable
|
|
25
|
-
const isActive = editor.isActive(Excalidraw.name);
|
|
26
|
-
// const { width: maxWidth } = getEditorContainerDOMSize(editor)
|
|
27
|
-
const { data, width, height } = node.attrs;
|
|
28
|
-
const [Svg, setSvg] = useState<SVGElement | null>(null);
|
|
29
|
-
const [loading, toggleLoading] = useState(true);
|
|
30
|
-
const [error, setError] = useState<any>(null);
|
|
31
|
-
const [visible, toggleVisible] = useState(false);
|
|
32
|
-
const [zoom, setZoomState] = useState(100);
|
|
33
|
-
|
|
34
|
-
const onViewportChange = useCallback(
|
|
35
|
-
(visible: any) => {
|
|
36
|
-
if (visible) {
|
|
37
|
-
toggleVisible(true);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
[toggleVisible],
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const setZoom = useCallback((type: 'minus' | 'plus') => {
|
|
44
|
-
return () => {
|
|
45
|
-
setZoomState(currentZoom =>
|
|
46
|
-
clamp(type === 'minus' ? currentZoom - ZOOM_STEP : currentZoom + ZOOM_STEP, MIN_ZOOM, MAX_ZOOM),
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
}, []);
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
let isUnmount = false;
|
|
53
|
-
|
|
54
|
-
import('@excalidraw/excalidraw')
|
|
55
|
-
.then((res) => {
|
|
56
|
-
if (!isUnmount) {
|
|
57
|
-
exportToSvgRef.current = res.exportToSvg;
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
.catch(err => !isUnmount && setError(err))
|
|
61
|
-
.finally(() => !isUnmount && toggleLoading(false));
|
|
62
|
-
|
|
63
|
-
return () => {
|
|
64
|
-
isUnmount = true;
|
|
65
|
-
};
|
|
66
|
-
}, [toggleLoading, data]);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
let isUnmount = false;
|
|
70
|
-
|
|
71
|
-
const setContent = async () => {
|
|
72
|
-
if (isUnmount || loading || error || !visible || !data)
|
|
73
|
-
return;
|
|
74
|
-
|
|
75
|
-
const svg: SVGElement = await exportToSvgRef.current(data);
|
|
76
|
-
|
|
77
|
-
if (isUnmount)
|
|
78
|
-
return;
|
|
79
|
-
|
|
80
|
-
svg.setAttribute('width', '100%');
|
|
81
|
-
svg.setAttribute('height', '100%');
|
|
82
|
-
svg.setAttribute('display', 'block');
|
|
83
|
-
|
|
84
|
-
setSvg(svg);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
setContent();
|
|
88
|
-
|
|
89
|
-
return () => {
|
|
90
|
-
isUnmount = true;
|
|
91
|
-
};
|
|
92
|
-
}, [data, loading, error, visible]);
|
|
93
|
-
|
|
94
|
-
const onResize = (size: any) => {
|
|
95
|
-
updateAttributes({ width: size.width, height: size.height });
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<NodeViewWrapper className={clsx(styles.wrap, isActive && styles.isActive)}>
|
|
100
|
-
<VisibilitySensor onChange={onViewportChange}>
|
|
101
|
-
<Resizable
|
|
102
|
-
size={{ width: Number.parseInt(width), height: Number.parseInt(height) }}
|
|
103
|
-
onResizeStop={(e, direction, ref, d) => {
|
|
104
|
-
onResize({
|
|
105
|
-
width: Number.parseInt(width) + d.width,
|
|
106
|
-
height: Number.parseInt(height) + d.height,
|
|
107
|
-
});
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
<div
|
|
111
|
-
className={clsx(styles.renderWrap, 'render-wrapper')}
|
|
112
|
-
style={{ ...INHERIT_SIZE_STYLE, overflow: 'hidden' }}
|
|
113
|
-
>
|
|
114
|
-
{error && (
|
|
115
|
-
<div style={INHERIT_SIZE_STYLE}>
|
|
116
|
-
<p>
|
|
117
|
-
{error.message || error}
|
|
118
|
-
</p>
|
|
119
|
-
</div>
|
|
120
|
-
)}
|
|
121
|
-
|
|
122
|
-
{loading && <p>
|
|
123
|
-
Loading...
|
|
124
|
-
</p>}
|
|
125
|
-
|
|
126
|
-
{!loading && !error && visible && (
|
|
127
|
-
<div
|
|
128
|
-
dangerouslySetInnerHTML={{ __html: Svg?.outerHTML ?? '' }}
|
|
129
|
-
style={{
|
|
130
|
-
height: '100%',
|
|
131
|
-
maxHeight: '100%',
|
|
132
|
-
padding: 24,
|
|
133
|
-
overflow: 'hidden',
|
|
134
|
-
display: 'flex',
|
|
135
|
-
justifyContent: 'center',
|
|
136
|
-
alignItems: 'center',
|
|
137
|
-
transform: `scale(${zoom / 100})`,
|
|
138
|
-
transition: 'all ease-in-out .3s',
|
|
139
|
-
}}
|
|
140
|
-
/>
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
<div className={styles.title}>
|
|
144
|
-
{/* <Space>
|
|
145
|
-
<span className={styles.icon}>
|
|
146
|
-
<IconMind />
|
|
147
|
-
</span>
|
|
148
|
-
绘图
|
|
149
|
-
</Space> */}
|
|
150
|
-
</div>
|
|
151
|
-
|
|
152
|
-
<div className={styles.handlerWrap}>
|
|
153
|
-
<ActionButton
|
|
154
|
-
action={setZoom('minus')}
|
|
155
|
-
icon="ZoomOut"
|
|
156
|
-
tooltip="Zoom Out"
|
|
157
|
-
/>
|
|
158
|
-
|
|
159
|
-
<ActionButton
|
|
160
|
-
action={setZoom('plus')}
|
|
161
|
-
icon="ZoomIn"
|
|
162
|
-
tooltip="Zoom In"
|
|
163
|
-
/>
|
|
164
|
-
</div>
|
|
165
|
-
</div>
|
|
166
|
-
</Resizable>
|
|
167
|
-
</VisibilitySensor>
|
|
168
|
-
</NodeViewWrapper>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export default React.memo(NodeViewExcalidraw, (prevProps, nextProps) => {
|
|
173
|
-
if (deepEqual(prevProps.node.attrs, nextProps.node.attrs)) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return false;
|
|
178
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
.wrap {
|
|
2
|
-
position: relative;
|
|
3
|
-
max-width: 100%;
|
|
4
|
-
overflow: visible;
|
|
5
|
-
line-height: 0;
|
|
6
|
-
|
|
7
|
-
.renderWrap {
|
|
8
|
-
border: 1px dashed hsl(var(--border)) !important;
|
|
9
|
-
border-radius: 6px;
|
|
10
|
-
|
|
11
|
-
&::after {
|
|
12
|
-
background-color: transparent !important;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.title {
|
|
17
|
-
position: absolute;
|
|
18
|
-
top: 10px;
|
|
19
|
-
left: 10px;
|
|
20
|
-
z-index: 2;
|
|
21
|
-
|
|
22
|
-
.icon {
|
|
23
|
-
display: flex;
|
|
24
|
-
width: 18px;
|
|
25
|
-
height: 18px;
|
|
26
|
-
color: #fff;
|
|
27
|
-
background-color: #f80;
|
|
28
|
-
border-radius: 2px;
|
|
29
|
-
justify-content: center;
|
|
30
|
-
align-items: center;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.handlerWrap {
|
|
35
|
-
position: absolute;
|
|
36
|
-
right: 10px;
|
|
37
|
-
bottom: 10px;
|
|
38
|
-
z-index: 2;
|
|
39
|
-
padding: 2px 4px;
|
|
40
|
-
border: 1px solid hsl(var(--border));
|
|
41
|
-
border-radius: 6px;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Excalidraw';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
4
|
-
import { printEditorContent } from 'reactjs-tiptap-editor-pro/utils/pdf';
|
|
5
|
-
|
|
6
|
-
export const ExportPdf = Extension.create<any>({
|
|
7
|
-
name: 'exportPdf',
|
|
8
|
-
addOptions() {
|
|
9
|
-
return {
|
|
10
|
-
...this.parent?.(),
|
|
11
|
-
button: ({ editor, t }: any) => ({
|
|
12
|
-
component: ActionButton,
|
|
13
|
-
componentProps: {
|
|
14
|
-
action: () => {
|
|
15
|
-
printEditorContent(editor);
|
|
16
|
-
},
|
|
17
|
-
icon: 'ExportPdf',
|
|
18
|
-
tooltip: t('editor.exportPdf.tooltip'),
|
|
19
|
-
isActive: () => false,
|
|
20
|
-
disabled: false,
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ExportPdf';
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { Extension } from '@tiptap/core';
|
|
3
|
-
import { Packer, WidthType } from 'docx';
|
|
4
|
-
import { DocxSerializer, defaultMarks, defaultNodes } from 'prosemirror-docx';
|
|
5
|
-
|
|
6
|
-
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
-
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
8
|
-
import { downloadFromBlob } from 'reactjs-tiptap-editor-pro/utils/download';
|
|
9
|
-
|
|
10
|
-
declare module '@tiptap/core' {
|
|
11
|
-
interface Commands<ReturnType> {
|
|
12
|
-
exportWord: {
|
|
13
|
-
exportToWord: () => ReturnType
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export interface ExportWordOptions extends GeneralOptions<ExportWordOptions> {}
|
|
18
|
-
|
|
19
|
-
const nodeSerializer = {
|
|
20
|
-
...defaultNodes,
|
|
21
|
-
hardBreak: defaultNodes.hard_break,
|
|
22
|
-
codeBlock: defaultNodes.code_block,
|
|
23
|
-
orderedList: defaultNodes.ordered_list,
|
|
24
|
-
listItem: defaultNodes.list_item,
|
|
25
|
-
bulletList: defaultNodes.bullet_list,
|
|
26
|
-
horizontalRule: defaultNodes.horizontal_rule,
|
|
27
|
-
// Requirement Buffer on browser
|
|
28
|
-
image(state: any, node: any) {
|
|
29
|
-
// No image
|
|
30
|
-
state.renderInline(node);
|
|
31
|
-
state.closeBlock(node);
|
|
32
|
-
},
|
|
33
|
-
table(state: any, node: any) {
|
|
34
|
-
state.table(node, {
|
|
35
|
-
tableOptions: {
|
|
36
|
-
width: {
|
|
37
|
-
size: 100,
|
|
38
|
-
type: WidthType.PERCENTAGE,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const docxSerializer = new DocxSerializer(nodeSerializer, defaultMarks);
|
|
45
|
-
|
|
46
|
-
export const ExportWord = Extension.create<ExportWordOptions>({
|
|
47
|
-
name: 'exportWord',
|
|
48
|
-
addOptions() {
|
|
49
|
-
return {
|
|
50
|
-
...this.parent?.(),
|
|
51
|
-
button: ({ editor, t }: any) => ({
|
|
52
|
-
component: ActionButton,
|
|
53
|
-
componentProps: {
|
|
54
|
-
icon: 'ExportWord',
|
|
55
|
-
action: () => {
|
|
56
|
-
editor?.commands.exportToWord();
|
|
57
|
-
},
|
|
58
|
-
tooltip: t('editor.exportWord.tooltip'),
|
|
59
|
-
isActive: () => false,
|
|
60
|
-
disabled: false,
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
// @ts-expect-error
|
|
66
|
-
addCommands() {
|
|
67
|
-
return {
|
|
68
|
-
exportToWord:
|
|
69
|
-
() =>
|
|
70
|
-
async ({ editor }) => {
|
|
71
|
-
const opts: any = {
|
|
72
|
-
getImageBuffer: async (src: string) => {
|
|
73
|
-
const response = await fetch(src);
|
|
74
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
75
|
-
return new Uint8Array(arrayBuffer);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const wordDocument = docxSerializer.serialize(editor.state.doc as any, opts);
|
|
80
|
-
|
|
81
|
-
Packer.toBlob(wordDocument).then(blob => downloadFromBlob(new Blob([blob]), 'export-document.docx'));
|
|
82
|
-
|
|
83
|
-
return true;
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ExportWord';
|