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,109 @@
|
|
|
1
|
+
import { Node, mergeAttributes, nodeInputRule } from '@tiptap/core';
|
|
2
|
+
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
import KatexActiveButton from 'reactjs-tiptap-editor-pro/extensions/Katex/components/KatexActiveButton';
|
|
5
|
+
import { KatexWrapper } from 'reactjs-tiptap-editor-pro/extensions/Katex/components/KatexWrapper';
|
|
6
|
+
|
|
7
|
+
export interface IKatexAttrs {
|
|
8
|
+
text?: string
|
|
9
|
+
defaultShowPicker?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IKatexOptions {
|
|
13
|
+
HTMLAttributes: Record<string, any>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getDatasetAttribute(attribute: string) {
|
|
17
|
+
return (element: any) => {
|
|
18
|
+
return element.getAttribute(attribute);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module '@tiptap/core' {
|
|
23
|
+
interface Commands<ReturnType> {
|
|
24
|
+
katex: {
|
|
25
|
+
setKatex: (arg?: IKatexAttrs) => ReturnType
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Katex = Node.create<IKatexOptions>({
|
|
31
|
+
name: 'katex',
|
|
32
|
+
group: 'inline',
|
|
33
|
+
inline: true,
|
|
34
|
+
defining: true,
|
|
35
|
+
draggable: true,
|
|
36
|
+
selectable: true,
|
|
37
|
+
|
|
38
|
+
addOptions() {
|
|
39
|
+
return {
|
|
40
|
+
HTMLAttributes: {
|
|
41
|
+
class: 'katex',
|
|
42
|
+
},
|
|
43
|
+
button: ({ editor, t }: any) => {
|
|
44
|
+
return {
|
|
45
|
+
component: KatexActiveButton,
|
|
46
|
+
componentProps: {
|
|
47
|
+
editor,
|
|
48
|
+
action: () => {
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
isActive: () => false,
|
|
52
|
+
disabled: false,
|
|
53
|
+
icon: 'KatexIcon',
|
|
54
|
+
tooltip: t('editor.katex.tooltip'),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
addAttributes() {
|
|
62
|
+
return {
|
|
63
|
+
text: {
|
|
64
|
+
default: '',
|
|
65
|
+
parseHTML: getDatasetAttribute('text'),
|
|
66
|
+
},
|
|
67
|
+
defaultShowPicker: {
|
|
68
|
+
default: false,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
parseHTML() {
|
|
74
|
+
return [{ tag: 'span.katex' }];
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
renderHTML({ HTMLAttributes }) {
|
|
78
|
+
return ['span', mergeAttributes((this.options && this.options.HTMLAttributes) || {}, HTMLAttributes)];
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
addCommands() {
|
|
82
|
+
return {
|
|
83
|
+
setKatex:
|
|
84
|
+
options =>
|
|
85
|
+
({ commands }) => {
|
|
86
|
+
return commands.insertContent({
|
|
87
|
+
type: this.name,
|
|
88
|
+
attrs: options,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
addInputRules() {
|
|
95
|
+
return [
|
|
96
|
+
nodeInputRule({
|
|
97
|
+
find: /^\$katex\$$/,
|
|
98
|
+
type: this.type,
|
|
99
|
+
getAttributes: () => {
|
|
100
|
+
return { defaultShowPicker: true };
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
];
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
addNodeView() {
|
|
107
|
+
return ReactNodeViewRenderer(KatexWrapper);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import katex from 'katex';
|
|
4
|
+
import { HelpCircle } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
import { ActionButton, Button, Label, Popover, PopoverContent, PopoverTrigger } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
+
import { Textarea } from 'reactjs-tiptap-editor-pro/components/ui/textarea';
|
|
8
|
+
import type { IKatexAttrs } from 'reactjs-tiptap-editor-pro/extensions/Katex/Katex';
|
|
9
|
+
import { Katex } from 'reactjs-tiptap-editor-pro/extensions/Katex/Katex';
|
|
10
|
+
import { useAttributes } from 'reactjs-tiptap-editor-pro/hooks/useAttributes';
|
|
11
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
12
|
+
|
|
13
|
+
function KatexActiveButton({ editor, ...props }: any) {
|
|
14
|
+
const { t } = useLocale();
|
|
15
|
+
|
|
16
|
+
const attrs = useAttributes<IKatexAttrs>(editor, Katex.name, {
|
|
17
|
+
text: '',
|
|
18
|
+
defaultShowPicker: false,
|
|
19
|
+
});
|
|
20
|
+
const { text, defaultShowPicker } = attrs;
|
|
21
|
+
|
|
22
|
+
const [currentValue, setCurrentValue] = useState('');
|
|
23
|
+
|
|
24
|
+
const submit = useCallback(() => {
|
|
25
|
+
editor.chain().focus().setKatex({ text: currentValue }).run();
|
|
26
|
+
setCurrentValue('');
|
|
27
|
+
}, [editor, currentValue]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (defaultShowPicker) {
|
|
31
|
+
editor.chain().updateAttributes(Katex.name, { defaultShowPicker: false }).focus().run();
|
|
32
|
+
}
|
|
33
|
+
}, [editor, defaultShowPicker]);
|
|
34
|
+
|
|
35
|
+
const formatText = useMemo(() => {
|
|
36
|
+
try {
|
|
37
|
+
return katex.renderToString(`${currentValue}`);
|
|
38
|
+
} catch {
|
|
39
|
+
return currentValue;
|
|
40
|
+
}
|
|
41
|
+
}, [currentValue]);
|
|
42
|
+
|
|
43
|
+
const previewContent = useMemo(
|
|
44
|
+
() => {
|
|
45
|
+
if (`${currentValue}`.trim()) {
|
|
46
|
+
return (
|
|
47
|
+
<span contentEditable={false}
|
|
48
|
+
dangerouslySetInnerHTML={{ __html: formatText || '' }}
|
|
49
|
+
>
|
|
50
|
+
</span>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return null;
|
|
55
|
+
},
|
|
56
|
+
[currentValue, formatText],
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Popover modal>
|
|
61
|
+
<PopoverTrigger asChild>
|
|
62
|
+
<ActionButton
|
|
63
|
+
icon={props?.icon}
|
|
64
|
+
tooltip={props?.tooltip}
|
|
65
|
+
/>
|
|
66
|
+
</PopoverTrigger>
|
|
67
|
+
|
|
68
|
+
<PopoverContent align="start"
|
|
69
|
+
className="size-full p-2"
|
|
70
|
+
hideWhenDetached
|
|
71
|
+
side="bottom"
|
|
72
|
+
>
|
|
73
|
+
<Label className="mb-[6px]">
|
|
74
|
+
{t('editor.formula.dialog.text')}
|
|
75
|
+
</Label>
|
|
76
|
+
|
|
77
|
+
<div className="mb-[16px] flex w-full max-w-sm items-center gap-1.5">
|
|
78
|
+
<div className="relative w-full max-w-sm">
|
|
79
|
+
<Textarea
|
|
80
|
+
autoFocus
|
|
81
|
+
className="w-full"
|
|
82
|
+
defaultValue={text}
|
|
83
|
+
onChange={e => setCurrentValue(e.target.value)}
|
|
84
|
+
placeholder="Text"
|
|
85
|
+
required
|
|
86
|
+
rows={3}
|
|
87
|
+
value={currentValue}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
{previewContent && (
|
|
93
|
+
<div className="my-[10px] max-w-[286px] overflow-auto whitespace-nowrap rounded-[6px] !border p-[10px]">
|
|
94
|
+
{previewContent}
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
|
|
98
|
+
<div className="flex items-center justify-between gap-[6px]">
|
|
99
|
+
<Button className="flex-1"
|
|
100
|
+
onClick={submit}
|
|
101
|
+
>
|
|
102
|
+
Submit
|
|
103
|
+
</Button>
|
|
104
|
+
|
|
105
|
+
<a href="https://katex.org/docs/supported"
|
|
106
|
+
rel="noreferrer noopener"
|
|
107
|
+
target="_blank"
|
|
108
|
+
>
|
|
109
|
+
<HelpCircle size={16} />
|
|
110
|
+
</a>
|
|
111
|
+
</div>
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</Popover>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default KatexActiveButton;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { NodeViewWrapper } from '@tiptap/react';
|
|
4
|
+
|
|
5
|
+
import katex from 'katex';
|
|
6
|
+
import { useTheme } from 'reactjs-tiptap-editor-pro/theme/theme';
|
|
7
|
+
import { convertColorToRGBA } from 'reactjs-tiptap-editor-pro/utils/color';
|
|
8
|
+
|
|
9
|
+
export function KatexWrapper({ node }: any) {
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
const { text } = node.attrs;
|
|
12
|
+
|
|
13
|
+
const backgroundColor = useMemo(() => {
|
|
14
|
+
const color = 'rgb(254, 242, 237)';
|
|
15
|
+
if (theme === 'dark')
|
|
16
|
+
return convertColorToRGBA(color, 0.75);
|
|
17
|
+
return color;
|
|
18
|
+
}, [theme]);
|
|
19
|
+
|
|
20
|
+
const formatText = useMemo(() => {
|
|
21
|
+
try {
|
|
22
|
+
return katex.renderToString(`${text}`);
|
|
23
|
+
} catch {
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
}, [text]);
|
|
27
|
+
|
|
28
|
+
const content = useMemo(
|
|
29
|
+
() =>
|
|
30
|
+
text.trim()
|
|
31
|
+
? (
|
|
32
|
+
<span contentEditable={false} dangerouslySetInnerHTML={{ __html: formatText }}></span>
|
|
33
|
+
)
|
|
34
|
+
: (
|
|
35
|
+
<span contentEditable={false}>
|
|
36
|
+
Not enter a formula
|
|
37
|
+
</span>
|
|
38
|
+
),
|
|
39
|
+
[text, formatText],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<NodeViewWrapper
|
|
44
|
+
style={{
|
|
45
|
+
display: 'inline-block',
|
|
46
|
+
backgroundColor,
|
|
47
|
+
}}
|
|
48
|
+
as="span"
|
|
49
|
+
>
|
|
50
|
+
{content}
|
|
51
|
+
</NodeViewWrapper>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Katex';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { Editor } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_LINE_HEIGHT, DEFAULT_LINE_HEIGHT_LIST } from 'reactjs-tiptap-editor-pro/constants';
|
|
5
|
+
import LineHeightDropdown from 'reactjs-tiptap-editor-pro/extensions/LineHeight/components/LineHeightDropdown';
|
|
6
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
7
|
+
import { createLineHeightCommand } from 'reactjs-tiptap-editor-pro/utils/line-height';
|
|
8
|
+
|
|
9
|
+
export interface LineHeightOptions extends GeneralOptions<LineHeightOptions> {
|
|
10
|
+
types: string[]
|
|
11
|
+
lineHeights: string[]
|
|
12
|
+
defaultHeight: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@tiptap/core' {
|
|
16
|
+
interface Commands<ReturnType> {
|
|
17
|
+
lineHeight: {
|
|
18
|
+
setLineHeight: (lineHeight: string) => ReturnType
|
|
19
|
+
unsetLineHeight: () => ReturnType
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const LineHeight = Extension.create<LineHeightOptions>({
|
|
25
|
+
name: 'lineHeight',
|
|
26
|
+
addOptions() {
|
|
27
|
+
return {
|
|
28
|
+
...this.parent?.(),
|
|
29
|
+
types: ['paragraph', 'heading', 'list_item', 'todo_item'],
|
|
30
|
+
lineHeights: DEFAULT_LINE_HEIGHT_LIST,
|
|
31
|
+
defaultHeight: DEFAULT_LINE_HEIGHT,
|
|
32
|
+
button({ editor, t }: { editor: Editor, t: any }) {
|
|
33
|
+
return {
|
|
34
|
+
component: LineHeightDropdown,
|
|
35
|
+
componentProps: {
|
|
36
|
+
editor,
|
|
37
|
+
tooltip: t('editor.lineheight.tooltip'),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
addGlobalAttributes() {
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
types: this.options.types,
|
|
48
|
+
attributes: {
|
|
49
|
+
lineHeight: {
|
|
50
|
+
default: null,
|
|
51
|
+
parseHTML: (element) => {
|
|
52
|
+
return element.style.lineHeight || this.options.defaultHeight;
|
|
53
|
+
},
|
|
54
|
+
renderHTML: (attributes) => {
|
|
55
|
+
if (attributes.lineHeight === this.options.defaultHeight || !attributes.lineHeight) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
return { style: `line-height: ${attributes.lineHeight}` };
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
addCommands() {
|
|
67
|
+
return {
|
|
68
|
+
setLineHeight: lineHeight => createLineHeightCommand(lineHeight),
|
|
69
|
+
unsetLineHeight:
|
|
70
|
+
() =>
|
|
71
|
+
({ commands }) => {
|
|
72
|
+
return this.options.types.every(type => commands.resetAttributes(type, 'lineHeight'));
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ActionButton,
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
DropdownMenuCheckboxItem,
|
|
7
|
+
DropdownMenuContent,
|
|
8
|
+
DropdownMenuTrigger,
|
|
9
|
+
IconComponent,
|
|
10
|
+
} from 'reactjs-tiptap-editor-pro/components';
|
|
11
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
12
|
+
import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
|
|
13
|
+
|
|
14
|
+
interface IPropsLineHeightDropdown {
|
|
15
|
+
editor: any
|
|
16
|
+
icon?: any
|
|
17
|
+
tooltip?: string
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
action?: ButtonViewReturnComponentProps['action']
|
|
20
|
+
isActive?: ButtonViewReturnComponentProps['isActive']
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function percentageToDecimal(percentageString: any) {
|
|
24
|
+
const percentage = Number.parseFloat(percentageString.replace('%', ''));
|
|
25
|
+
const decimal = percentage / 100;
|
|
26
|
+
return decimal;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function LineHeightDropdown(props: IPropsLineHeightDropdown) {
|
|
30
|
+
const { t } = useLocale();
|
|
31
|
+
const [value, setValue] = useState('default');
|
|
32
|
+
|
|
33
|
+
function toggleLightheight(key: string) {
|
|
34
|
+
if (key === 'default') {
|
|
35
|
+
props.editor.commands.unsetLineHeight();
|
|
36
|
+
} else {
|
|
37
|
+
props.editor.commands.setLineHeight(key);
|
|
38
|
+
}
|
|
39
|
+
setValue(key);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const LineHeights = useMemo(() => {
|
|
43
|
+
const lineHeightOptions = props.editor.extensionManager.extensions.find(
|
|
44
|
+
(e: any) => e.name === 'lineHeight',
|
|
45
|
+
)!.options;
|
|
46
|
+
const a = lineHeightOptions.lineHeights;
|
|
47
|
+
const b = a.map((item: any) => ({
|
|
48
|
+
label: percentageToDecimal(item),
|
|
49
|
+
value: item,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
b.unshift({
|
|
53
|
+
label: t('editor.default'),
|
|
54
|
+
value: 'default',
|
|
55
|
+
});
|
|
56
|
+
return b;
|
|
57
|
+
}, [props]);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<DropdownMenu>
|
|
61
|
+
<DropdownMenuTrigger asChild
|
|
62
|
+
disabled={props?.disabled}
|
|
63
|
+
>
|
|
64
|
+
<ActionButton
|
|
65
|
+
customClass="!w-12 h-12"
|
|
66
|
+
disabled={props?.disabled}
|
|
67
|
+
icon="LineHeight"
|
|
68
|
+
tooltip={props?.tooltip}
|
|
69
|
+
>
|
|
70
|
+
<IconComponent className="ml-1 size-3 text-zinc-500"
|
|
71
|
+
name="MenuDown"
|
|
72
|
+
/>
|
|
73
|
+
</ActionButton>
|
|
74
|
+
</DropdownMenuTrigger>
|
|
75
|
+
|
|
76
|
+
<DropdownMenuContent className="min-w-24">
|
|
77
|
+
{LineHeights?.map((item: any, index: any) => {
|
|
78
|
+
return (
|
|
79
|
+
<DropdownMenuCheckboxItem
|
|
80
|
+
checked={item.value === value}
|
|
81
|
+
key={`lineHeight-${index}`}
|
|
82
|
+
onClick={() => toggleLightheight(item.value)}
|
|
83
|
+
>
|
|
84
|
+
{item.label}
|
|
85
|
+
</DropdownMenuCheckboxItem>
|
|
86
|
+
);
|
|
87
|
+
})}
|
|
88
|
+
</DropdownMenuContent>
|
|
89
|
+
</DropdownMenu>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default LineHeightDropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LineHeight';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getMarkRange, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import type { LinkOptions as TiptapLinkOptions } from '@tiptap/extension-link';
|
|
3
|
+
import { Link as TiptapLink } from '@tiptap/extension-link';
|
|
4
|
+
import { Plugin, TextSelection } from '@tiptap/pm/state';
|
|
5
|
+
import type { EditorView } from '@tiptap/pm/view';
|
|
6
|
+
|
|
7
|
+
import LinkEditPopover from 'reactjs-tiptap-editor-pro/extensions/Link/components/LinkEditPopover';
|
|
8
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
9
|
+
|
|
10
|
+
export interface LinkOptions extends TiptapLinkOptions, GeneralOptions<LinkOptions> {}
|
|
11
|
+
|
|
12
|
+
export const Link = TiptapLink.extend<LinkOptions>({
|
|
13
|
+
inclusive: false,
|
|
14
|
+
parseHTML() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
tag: 'a[href]:not([data-type="button"]):not([href *= "javascript:" i])',
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
},
|
|
21
|
+
renderHTML({ HTMLAttributes }) {
|
|
22
|
+
return [
|
|
23
|
+
'a',
|
|
24
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
25
|
+
class: 'link',
|
|
26
|
+
}),
|
|
27
|
+
0,
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
addOptions() {
|
|
32
|
+
return {
|
|
33
|
+
...this.parent?.(),
|
|
34
|
+
openOnClick: true,
|
|
35
|
+
button: ({ editor, t }) => {
|
|
36
|
+
return {
|
|
37
|
+
component: LinkEditPopover,
|
|
38
|
+
componentProps: {
|
|
39
|
+
editor,
|
|
40
|
+
action: (value) => {
|
|
41
|
+
const { link, text, openInNewTab } = value as any;
|
|
42
|
+
editor
|
|
43
|
+
.chain()
|
|
44
|
+
.extendMarkRange('link')
|
|
45
|
+
.insertContent({
|
|
46
|
+
type: 'text',
|
|
47
|
+
text,
|
|
48
|
+
marks: [
|
|
49
|
+
{
|
|
50
|
+
type: 'link',
|
|
51
|
+
attrs: {
|
|
52
|
+
href: link,
|
|
53
|
+
target: openInNewTab ? '_blank' : '',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
})
|
|
58
|
+
.setLink({ href: link })
|
|
59
|
+
.focus()
|
|
60
|
+
.run();
|
|
61
|
+
},
|
|
62
|
+
id: 'linkk',
|
|
63
|
+
isActive: () => editor.isActive('link') || false,
|
|
64
|
+
disabled: !editor.can().setLink({ href: '' }),
|
|
65
|
+
icon: 'Link',
|
|
66
|
+
tooltip: t('editor.link.tooltip'),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
addProseMirrorPlugins() {
|
|
74
|
+
return [
|
|
75
|
+
new Plugin({
|
|
76
|
+
props: {
|
|
77
|
+
handleClick: (view: EditorView, pos: number) => {
|
|
78
|
+
const { schema, doc, tr } = view.state;
|
|
79
|
+
const range = getMarkRange(doc.resolve(pos), schema.marks.link);
|
|
80
|
+
if (!range) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const $start = doc.resolve(range.from);
|
|
84
|
+
const $end = doc.resolve(range.to);
|
|
85
|
+
const transaction = tr.setSelection(new TextSelection($start, $end));
|
|
86
|
+
view.dispatch(transaction);
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
];
|
|
91
|
+
},
|
|
92
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable no-unsafe-optional-chaining */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import { Button, IconComponent, Input, Label, Switch } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
8
|
+
|
|
9
|
+
interface IPropsLinkEditBlock {
|
|
10
|
+
editor: any
|
|
11
|
+
onSetLink: (link: string, text?: string, openInNewTab?: boolean) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function LinkEditBlock(props: IPropsLinkEditBlock) {
|
|
15
|
+
const { t } = useLocale();
|
|
16
|
+
|
|
17
|
+
const [form, setForm] = useState({
|
|
18
|
+
text: '',
|
|
19
|
+
link: '',
|
|
20
|
+
});
|
|
21
|
+
const [openInNewTab, setOpenInNewTab] = useState<boolean>(false);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (props?.editor) {
|
|
25
|
+
const { href: link, target } = props.editor?.getAttributes('link');
|
|
26
|
+
|
|
27
|
+
const { from, to } = props.editor.state.selection;
|
|
28
|
+
const text = props.editor.state.doc.textBetween(from, to, ' ');
|
|
29
|
+
setForm({
|
|
30
|
+
link,
|
|
31
|
+
text,
|
|
32
|
+
});
|
|
33
|
+
setOpenInNewTab(target === '_blank');
|
|
34
|
+
}
|
|
35
|
+
}, [props?.editor]);
|
|
36
|
+
|
|
37
|
+
function handleSubmit(event: any) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
event.stopPropagation();
|
|
40
|
+
props?.onSetLink(form.link, form.text, openInNewTab);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="border-neutral-200 rounded-lg !border bg-white p-2 shadow-sm dark:border-neutral-800 dark:bg-black">
|
|
45
|
+
<form className="flex flex-col gap-2"
|
|
46
|
+
onSubmit={handleSubmit}
|
|
47
|
+
>
|
|
48
|
+
<Label className="mb-[6px]">
|
|
49
|
+
{t('editor.link.dialog.text')}
|
|
50
|
+
</Label>
|
|
51
|
+
|
|
52
|
+
<div className="mb-[10px] flex w-full max-w-sm items-center gap-1.5">
|
|
53
|
+
<div className="relative w-full max-w-sm items-center">
|
|
54
|
+
<Input
|
|
55
|
+
className="w-80"
|
|
56
|
+
onChange={e => setForm({ ...form, text: e.target.value })}
|
|
57
|
+
placeholder="Text"
|
|
58
|
+
required
|
|
59
|
+
type="text"
|
|
60
|
+
value={form.text}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<Label className="mb-[6px]">
|
|
66
|
+
{t('editor.link.dialog.link')}
|
|
67
|
+
</Label>
|
|
68
|
+
|
|
69
|
+
<div className="flex w-full max-w-sm items-center gap-1.5">
|
|
70
|
+
<div className="relative w-full max-w-sm items-center">
|
|
71
|
+
<Input
|
|
72
|
+
className="pl-10"
|
|
73
|
+
onChange={e => setForm({ ...form, link: e.target.value })}
|
|
74
|
+
required
|
|
75
|
+
type="url"
|
|
76
|
+
value={form.link}
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<span className="absolute inset-y-0 start-0 flex items-center justify-center px-2">
|
|
80
|
+
<IconComponent className="size-5 text-muted-foreground"
|
|
81
|
+
name="Link"
|
|
82
|
+
/>
|
|
83
|
+
</span>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<div className="flex items-center space-x-2">
|
|
88
|
+
<Label>
|
|
89
|
+
{t('editor.link.dialog.openInNewTab')}
|
|
90
|
+
</Label>
|
|
91
|
+
|
|
92
|
+
<Switch
|
|
93
|
+
checked={openInNewTab}
|
|
94
|
+
onCheckedChange={(e) => {
|
|
95
|
+
setOpenInNewTab(e);
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<Button className="mt-2 self-end"
|
|
101
|
+
type="submit"
|
|
102
|
+
>
|
|
103
|
+
{t('editor.link.dialog.button.apply')}
|
|
104
|
+
</Button>
|
|
105
|
+
</form>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default LinkEditBlock;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ActionButton, IconComponent, Popover, PopoverContent, PopoverTrigger } from 'reactjs-tiptap-editor-pro/components';
|
|
4
|
+
import LinkEditBlock from 'reactjs-tiptap-editor-pro/extensions/Link/components/LinkEditBlock';
|
|
5
|
+
import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
+
|
|
7
|
+
interface IPropsLinkEditPopover {
|
|
8
|
+
editor: any
|
|
9
|
+
icon?: any
|
|
10
|
+
title?: string
|
|
11
|
+
tooltip?: string
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
shortcutKeys?: string[]
|
|
14
|
+
isActive?: ButtonViewReturnComponentProps['isActive']
|
|
15
|
+
action?: ButtonViewReturnComponentProps['action']
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function LinkEditPopover(props: IPropsLinkEditPopover) {
|
|
19
|
+
const [open, setOpen] = useState(false);
|
|
20
|
+
|
|
21
|
+
function onSetLink(link: string, text?: string, openInNewTab?: boolean) {
|
|
22
|
+
if (props.action) {
|
|
23
|
+
props.action({ link, text, openInNewTab });
|
|
24
|
+
setOpen(false);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Popover modal open={open} onOpenChange={setOpen}>
|
|
30
|
+
<PopoverTrigger disabled={props?.disabled} asChild>
|
|
31
|
+
<ActionButton
|
|
32
|
+
tooltip={props?.tooltip}
|
|
33
|
+
isActive={props?.isActive}
|
|
34
|
+
disabled={props?.disabled}
|
|
35
|
+
>
|
|
36
|
+
<IconComponent name={props?.icon} />
|
|
37
|
+
</ActionButton>
|
|
38
|
+
</PopoverTrigger>
|
|
39
|
+
<PopoverContent hideWhenDetached className="w-full" align="start" side="bottom">
|
|
40
|
+
<LinkEditBlock editor={props.editor} onSetLink={onSetLink} />
|
|
41
|
+
</PopoverContent>
|
|
42
|
+
</Popover>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default LinkEditPopover;
|