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,61 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Emoji';
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Excalidraw';
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ExportPdf';
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ExportWord';
|