reactjs-tiptap-editor-pro 0.2.29 → 0.2.30
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 +4 -60
- 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,239 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { Editor } from '@tiptap/core';
|
|
5
|
+
import {
|
|
6
|
+
makeDropdownToolbar,
|
|
7
|
+
Editor as Editor4,
|
|
8
|
+
} from 'easydrawer';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import svg64 from 'svg64';
|
|
11
|
+
|
|
12
|
+
import { ActionButton } from '@/components/ActionButton';
|
|
13
|
+
import { Button } from '@/components/ui';
|
|
14
|
+
import { Dialog, DialogContent, DialogFooter, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
|
15
|
+
import ControlDrawer from '@/extensions/Drawer/components/ControlDrawer/ControlDrawer';
|
|
16
|
+
import { dataURLtoFile } from '@/utils/file';
|
|
17
|
+
import { shortId } from '@/utils/shortId';
|
|
18
|
+
|
|
19
|
+
interface IProps {
|
|
20
|
+
editor: Editor, upload?: any
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let clear = false;
|
|
24
|
+
|
|
25
|
+
export const DrawerActiveButton: React.FC<IProps> = ({ editor, upload }) => {
|
|
26
|
+
const [visible, toggleVisible] = useState(false);
|
|
27
|
+
const refEditor = useRef<Editor4 | null>(null);
|
|
28
|
+
const refWidget = useRef<any>(null);
|
|
29
|
+
|
|
30
|
+
const mermaidInit = () => {
|
|
31
|
+
const init = async () => {
|
|
32
|
+
const parentElement = document.querySelector('#easydrawer');
|
|
33
|
+
|
|
34
|
+
if (!parentElement) return;
|
|
35
|
+
|
|
36
|
+
refEditor.current = new Editor4(parentElement as any, {
|
|
37
|
+
wheelEventsEnabled: false,
|
|
38
|
+
disableZoom: true,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
refWidget.current = makeDropdownToolbar(refEditor.current);
|
|
42
|
+
refWidget.current.addDefaultToolWidgets();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
init();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (visible) {
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
mermaidInit();
|
|
52
|
+
}, 200);
|
|
53
|
+
}
|
|
54
|
+
}, [visible]);
|
|
55
|
+
|
|
56
|
+
const setSvg = async () => {
|
|
57
|
+
if (refEditor.current) {
|
|
58
|
+
const svg = refEditor.current.toSVG() as unknown as HTMLElement;
|
|
59
|
+
const contentHtml = svg.outerHTML;
|
|
60
|
+
// const { width, height } = svg.getBoundingClientRect();
|
|
61
|
+
const name = `drawer-${shortId()}.svg`;
|
|
62
|
+
|
|
63
|
+
let src = svg64(svg.outerHTML);
|
|
64
|
+
|
|
65
|
+
if (upload) {
|
|
66
|
+
const file = dataURLtoFile(src, name);
|
|
67
|
+
src = await upload(file);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
editor
|
|
71
|
+
?.chain()
|
|
72
|
+
.focus()
|
|
73
|
+
.setDrawer(
|
|
74
|
+
{
|
|
75
|
+
type: 'drawer',
|
|
76
|
+
src,
|
|
77
|
+
alt: encodeURIComponent(contentHtml),
|
|
78
|
+
width: 426,
|
|
79
|
+
height: 212
|
|
80
|
+
},
|
|
81
|
+
!!contentHtml,
|
|
82
|
+
)
|
|
83
|
+
.run();
|
|
84
|
+
}
|
|
85
|
+
toggleVisible(false);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const setColorPen = (color: string) => {
|
|
89
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[2] as any;
|
|
90
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-1');
|
|
91
|
+
|
|
92
|
+
if (penTool && shapeWidget) {
|
|
93
|
+
penTool.setColor(color);
|
|
94
|
+
shapeWidget.serializeState();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const setThicknessPen = (thickness: number) => {
|
|
99
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[2] as any;
|
|
100
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-1');
|
|
101
|
+
|
|
102
|
+
if (penTool && shapeWidget) {
|
|
103
|
+
penTool.setThickness(thickness);
|
|
104
|
+
shapeWidget.serializeState();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const setColorHighlight = (color: string) => {
|
|
109
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[3] as any;
|
|
110
|
+
|
|
111
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-2');
|
|
112
|
+
|
|
113
|
+
if (penTool && shapeWidget) {
|
|
114
|
+
penTool.setColor(color);
|
|
115
|
+
shapeWidget.serializeState();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const changeShape = (type: any) => {
|
|
120
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
121
|
+
|
|
122
|
+
if (shapeWidget) {
|
|
123
|
+
shapeWidget.setShapeType(type);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const changeColorShape = (color: string) => {
|
|
128
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
129
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
130
|
+
|
|
131
|
+
if (penTool && shapeWidget) {
|
|
132
|
+
penTool.setColor(color);
|
|
133
|
+
shapeWidget.serializeState();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const onThicknessChange = (v: any) => {
|
|
138
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
139
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
140
|
+
|
|
141
|
+
if (penTool && shapeWidget) {
|
|
142
|
+
penTool.setThickness(v);
|
|
143
|
+
shapeWidget.serializeState();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const changeBorderColorShape = (color: string) => {
|
|
148
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
149
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
150
|
+
|
|
151
|
+
if (penTool && shapeWidget) {
|
|
152
|
+
penTool.setBorderColor(color);
|
|
153
|
+
shapeWidget.serializeState();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const onUndo =() => {
|
|
158
|
+
if (clear) {
|
|
159
|
+
while (refEditor.current!.history.redoStackSize > 0) {
|
|
160
|
+
refEditor.current!.history.redo();
|
|
161
|
+
}
|
|
162
|
+
clear = false;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
refEditor.current!.history.undo();
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const onRedo =() => {
|
|
170
|
+
if (clear) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
refEditor.current!.history.redo();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const onClear =() => {
|
|
178
|
+
if (clear) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
while (refEditor.current!.history.undoStackSize > 0) {
|
|
183
|
+
onUndo();
|
|
184
|
+
}
|
|
185
|
+
clear = true;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<Dialog
|
|
190
|
+
onOpenChange={toggleVisible}
|
|
191
|
+
open={visible}
|
|
192
|
+
>
|
|
193
|
+
<DialogTrigger asChild>
|
|
194
|
+
<ActionButton
|
|
195
|
+
action={() => toggleVisible(true)}
|
|
196
|
+
icon="PencilRuler"
|
|
197
|
+
tooltip="Drawer"
|
|
198
|
+
/>
|
|
199
|
+
</DialogTrigger>
|
|
200
|
+
|
|
201
|
+
<DialogContent className="z-[99999] !max-w-[1300px]">
|
|
202
|
+
<DialogTitle>
|
|
203
|
+
Drawer
|
|
204
|
+
</DialogTitle>
|
|
205
|
+
|
|
206
|
+
<div style={{ height: '600px', width: '100%', borderWidth: 1, background: 'white', position: 'relative' }}>
|
|
207
|
+
<div
|
|
208
|
+
className='size-full'
|
|
209
|
+
id='easydrawer'
|
|
210
|
+
>
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<ControlDrawer
|
|
214
|
+
changeBorderColorShape={changeBorderColorShape}
|
|
215
|
+
changeColorShape={changeColorShape}
|
|
216
|
+
changeShape={changeShape}
|
|
217
|
+
onClear={onClear}
|
|
218
|
+
onRedo={onRedo}
|
|
219
|
+
onThicknessChange={onThicknessChange}
|
|
220
|
+
onUndo={onUndo}
|
|
221
|
+
refEditor={refEditor}
|
|
222
|
+
setColorHighlight={setColorHighlight}
|
|
223
|
+
setColorPen={setColorPen}
|
|
224
|
+
setThicknessPen={setThicknessPen}
|
|
225
|
+
/>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
<DialogFooter>
|
|
229
|
+
<Button
|
|
230
|
+
onClick={setSvg}
|
|
231
|
+
type="button"
|
|
232
|
+
>
|
|
233
|
+
Save changes
|
|
234
|
+
</Button>
|
|
235
|
+
</DialogFooter>
|
|
236
|
+
</DialogContent>
|
|
237
|
+
</Dialog>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
makeDropdownToolbar,
|
|
6
|
+
Editor as Editor4,
|
|
7
|
+
} from 'easydrawer';
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import svg64 from 'svg64';
|
|
10
|
+
|
|
11
|
+
import { ActionButton } from '@/components/ActionButton';
|
|
12
|
+
import { Button } from '@/components/ui';
|
|
13
|
+
import { Dialog, DialogContent, DialogFooter, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
|
14
|
+
import ControlDrawer from '@/extensions/Drawer/components/ControlDrawer/ControlDrawer';
|
|
15
|
+
import { dataURLtoFile } from '@/utils/file';
|
|
16
|
+
import { shortId } from '@/utils/shortId';
|
|
17
|
+
|
|
18
|
+
let clear = false;
|
|
19
|
+
|
|
20
|
+
export function EditDrawerBlock ({ editor, attrs, extension }: any) {
|
|
21
|
+
const [visible, toggleVisible] = useState(false);
|
|
22
|
+
const refEditor = useRef<Editor4 | null>(null);
|
|
23
|
+
const refWidget = useRef<any>(null);
|
|
24
|
+
const { alt, align } = attrs;
|
|
25
|
+
const upload = extension?.options.upload;
|
|
26
|
+
|
|
27
|
+
const mermaidInit = () => {
|
|
28
|
+
const init = async () => {
|
|
29
|
+
const parentElement = document.querySelector('#easydrawer');
|
|
30
|
+
|
|
31
|
+
if (!parentElement) return;
|
|
32
|
+
|
|
33
|
+
refEditor.current = new Editor4(parentElement as any, {
|
|
34
|
+
wheelEventsEnabled: false,
|
|
35
|
+
disableZoom: true,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
refWidget.current = makeDropdownToolbar(refEditor.current);
|
|
39
|
+
refWidget.current.addDefaultToolWidgets();
|
|
40
|
+
|
|
41
|
+
refEditor.current.loadFromSVG(decodeURIComponent(alt));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
init();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (visible) {
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
mermaidInit();
|
|
51
|
+
}, 200);
|
|
52
|
+
}
|
|
53
|
+
}, [visible]);
|
|
54
|
+
|
|
55
|
+
const setSvg = async () => {
|
|
56
|
+
if (refEditor.current) {
|
|
57
|
+
const svg = refEditor.current.toSVG() as unknown as HTMLElement;
|
|
58
|
+
const contentHtml = svg.outerHTML;
|
|
59
|
+
const name = `drawer-${shortId()}.svg`;
|
|
60
|
+
|
|
61
|
+
let src = svg64(svg.outerHTML);
|
|
62
|
+
|
|
63
|
+
if (upload) {
|
|
64
|
+
const file = dataURLtoFile(src, name);
|
|
65
|
+
src = await upload(file);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
editor
|
|
69
|
+
?.chain()
|
|
70
|
+
.focus()
|
|
71
|
+
.setDrawer(
|
|
72
|
+
{
|
|
73
|
+
type: 'drawer',
|
|
74
|
+
src,
|
|
75
|
+
alt: encodeURIComponent(contentHtml),
|
|
76
|
+
width: 426,
|
|
77
|
+
height: 212
|
|
78
|
+
},
|
|
79
|
+
!!contentHtml,
|
|
80
|
+
)
|
|
81
|
+
.run();
|
|
82
|
+
editor?.commands.setAlignImageDrawer(align);
|
|
83
|
+
}
|
|
84
|
+
toggleVisible(false);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const setColorPen = (color: string) => {
|
|
88
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[2] as any;
|
|
89
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-1');
|
|
90
|
+
|
|
91
|
+
if (penTool && shapeWidget) {
|
|
92
|
+
penTool.setColor(color);
|
|
93
|
+
shapeWidget.serializeState();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const setThicknessPen = (thickness: number) => {
|
|
98
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[2] as any;
|
|
99
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-1');
|
|
100
|
+
|
|
101
|
+
if (penTool && shapeWidget) {
|
|
102
|
+
penTool.setThickness(thickness);
|
|
103
|
+
shapeWidget.serializeState();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const setColorHighlight = (color: string) => {
|
|
108
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[3] as any;
|
|
109
|
+
|
|
110
|
+
const shapeWidget = refWidget.current.getWidgetById('pen-2');
|
|
111
|
+
|
|
112
|
+
if (penTool && shapeWidget) {
|
|
113
|
+
penTool.setColor(color);
|
|
114
|
+
shapeWidget.serializeState();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const changeShape = (type: any) => {
|
|
119
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
120
|
+
|
|
121
|
+
if (shapeWidget) {
|
|
122
|
+
shapeWidget.setShapeType(type);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const changeColorShape = (color: string) => {
|
|
127
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
128
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
129
|
+
|
|
130
|
+
if (penTool && shapeWidget) {
|
|
131
|
+
penTool.setColor(color);
|
|
132
|
+
shapeWidget.serializeState();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onThicknessChange = (v: any) => {
|
|
137
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
138
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
139
|
+
|
|
140
|
+
if (penTool && shapeWidget) {
|
|
141
|
+
penTool.setThickness(v);
|
|
142
|
+
shapeWidget.serializeState();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const changeBorderColorShape = (color: string) => {
|
|
147
|
+
const penTool = refEditor.current!.toolController.getPrimaryTools()[5] as any;
|
|
148
|
+
const shapeWidget = refWidget.current.getWidgetById('shape');
|
|
149
|
+
|
|
150
|
+
if (penTool && shapeWidget) {
|
|
151
|
+
penTool.setBorderColor(color);
|
|
152
|
+
shapeWidget.serializeState();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const onUndo =() => {
|
|
157
|
+
if (clear) {
|
|
158
|
+
while (refEditor.current!.history.redoStackSize > 0) {
|
|
159
|
+
refEditor.current!.history.redo();
|
|
160
|
+
}
|
|
161
|
+
clear = false;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
refEditor.current!.history.undo();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const onRedo =() => {
|
|
169
|
+
if (clear) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
refEditor.current!.history.redo();
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const onClear =() => {
|
|
177
|
+
if (clear) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
while (refEditor.current!.history.undoStackSize > 0) {
|
|
182
|
+
onUndo();
|
|
183
|
+
}
|
|
184
|
+
clear = true;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<Dialog
|
|
189
|
+
onOpenChange={toggleVisible}
|
|
190
|
+
open={visible}
|
|
191
|
+
>
|
|
192
|
+
<DialogTrigger asChild>
|
|
193
|
+
<ActionButton
|
|
194
|
+
action={() => toggleVisible(true)}
|
|
195
|
+
icon="Pencil"
|
|
196
|
+
tooltip="Edit Drawer"
|
|
197
|
+
/>
|
|
198
|
+
</DialogTrigger>
|
|
199
|
+
|
|
200
|
+
<DialogContent className="z-[99999] !max-w-[1300px]">
|
|
201
|
+
<DialogTitle>
|
|
202
|
+
Edit Drawer
|
|
203
|
+
</DialogTitle>
|
|
204
|
+
|
|
205
|
+
<div style={{ height: '100%', borderWidth: 1, background: 'white', position: 'relative' }}>
|
|
206
|
+
<div
|
|
207
|
+
className='size-full'
|
|
208
|
+
id='easydrawer'
|
|
209
|
+
>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<ControlDrawer
|
|
213
|
+
changeBorderColorShape={changeBorderColorShape}
|
|
214
|
+
changeColorShape={changeColorShape}
|
|
215
|
+
changeShape={changeShape}
|
|
216
|
+
onClear={onClear}
|
|
217
|
+
onRedo={onRedo}
|
|
218
|
+
onThicknessChange={onThicknessChange}
|
|
219
|
+
onUndo={onUndo}
|
|
220
|
+
refEditor={refEditor}
|
|
221
|
+
setColorHighlight={setColorHighlight}
|
|
222
|
+
setColorPen={setColorPen}
|
|
223
|
+
setThicknessPen={setThicknessPen}
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<DialogFooter>
|
|
228
|
+
<Button
|
|
229
|
+
onClick={setSvg}
|
|
230
|
+
type="button"
|
|
231
|
+
>
|
|
232
|
+
Save changes
|
|
233
|
+
</Button>
|
|
234
|
+
</DialogFooter>
|
|
235
|
+
</DialogContent>
|
|
236
|
+
</Dialog>
|
|
237
|
+
);
|
|
238
|
+
}
|