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,146 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
import { Button, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger, icons } from 'reactjs-tiptap-editor-pro/components';
|
|
6
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
7
|
+
|
|
8
|
+
interface IPropsTextDropdown {
|
|
9
|
+
editor: any
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
color?: string
|
|
12
|
+
maxHeight?: string | number
|
|
13
|
+
icon?: any
|
|
14
|
+
tooltip?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function TextDropdown(props: IPropsTextDropdown) {
|
|
18
|
+
const { t } = useLocale();
|
|
19
|
+
|
|
20
|
+
const menus = useMemo(() => {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
name: 'paragraph',
|
|
24
|
+
label: t('editor.paragraph.tooltip'),
|
|
25
|
+
iconName: 'Heading1',
|
|
26
|
+
isActive: () =>
|
|
27
|
+
props.editor.isActive('paragraph')
|
|
28
|
+
&& !props.editor.isActive('orderedList')
|
|
29
|
+
&& !props.editor.isActive('bulletList')
|
|
30
|
+
&& !props.editor.isActive('taskList'),
|
|
31
|
+
action: () => props.editor.chain().focus().clearNodes().run(),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'heading1',
|
|
35
|
+
label: t('editor.heading.h1.tooltip'),
|
|
36
|
+
isActive: () => props.editor.isActive('heading', { level: 1 }),
|
|
37
|
+
iconName: 'Heading1',
|
|
38
|
+
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'heading2',
|
|
42
|
+
label: t('editor.heading.h2.tooltip'),
|
|
43
|
+
isActive: () => props.editor.isActive('heading', { level: 2 }),
|
|
44
|
+
iconName: 'Heading2',
|
|
45
|
+
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'heading3',
|
|
49
|
+
label: t('editor.heading.h3.tooltip'),
|
|
50
|
+
isActive: () => props.editor.isActive('heading', { level: 3 }),
|
|
51
|
+
iconName: 'Heading3',
|
|
52
|
+
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'bulletList',
|
|
56
|
+
label: t('editor.bulletlist.tooltip'),
|
|
57
|
+
isActive: () => props.editor.isActive('bulletList'),
|
|
58
|
+
iconName: 'List',
|
|
59
|
+
action: () => props.editor.chain().focus().clearNodes().toggleBulletList().run(),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'numberedList',
|
|
63
|
+
label: t('editor.orderedlist.tooltip'),
|
|
64
|
+
isActive: () => props.editor.isActive('orderedList'),
|
|
65
|
+
iconName: 'ListOrdered',
|
|
66
|
+
action: () => props.editor.chain().focus().clearNodes().toggleOrderedList().run(),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'taskList',
|
|
70
|
+
label: t('editor.tasklist.tooltip'),
|
|
71
|
+
isActive: () => props.editor.isActive('taskList'),
|
|
72
|
+
iconName: 'ListTodo',
|
|
73
|
+
action: () => props.editor.chain().focus().clearNodes().toggleTaskList().run(),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'blockquote',
|
|
77
|
+
label: t('editor.blockquote.tooltip'),
|
|
78
|
+
isActive: () => props.editor.isActive('blockquote'),
|
|
79
|
+
iconName: 'TextQuote',
|
|
80
|
+
action: () => props.editor.chain().focus().clearNodes().toggleBlockquote().run(),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'codeBlock',
|
|
84
|
+
label: t('editor.codeblock.tooltip'),
|
|
85
|
+
isActive: () => props.editor.isActive('codeBlock'),
|
|
86
|
+
iconName: 'Code2',
|
|
87
|
+
action: () => props.editor.chain().focus().clearNodes().toggleCodeBlock().run(),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}, [props.editor, t]);
|
|
91
|
+
|
|
92
|
+
const activeItem = useMemo(() => {
|
|
93
|
+
return (
|
|
94
|
+
menus.findLast(item => item.isActive()) ?? {
|
|
95
|
+
label: 'Empty',
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}, [menus]);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<DropdownMenu>
|
|
102
|
+
<DropdownMenuTrigger asChild>
|
|
103
|
+
<Button className="flex h-[32px] gap-1 px-1.5"
|
|
104
|
+
variant="ghost"
|
|
105
|
+
>
|
|
106
|
+
<span className="whitespace-nowrap text-sm font-normal">
|
|
107
|
+
{' '}
|
|
108
|
+
{activeItem?.label}
|
|
109
|
+
</span>
|
|
110
|
+
|
|
111
|
+
<ChevronDown className="size-4" />
|
|
112
|
+
</Button>
|
|
113
|
+
</DropdownMenuTrigger>
|
|
114
|
+
|
|
115
|
+
<DropdownMenuContent align="start"
|
|
116
|
+
className="w-full p-1"
|
|
117
|
+
hideWhenDetached
|
|
118
|
+
sideOffset={5}
|
|
119
|
+
>
|
|
120
|
+
{menus.map((item, index) => {
|
|
121
|
+
const Icon = icons[item.iconName as any];
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<DropdownMenuCheckboxItem
|
|
125
|
+
checked={item.isActive?.() || false}
|
|
126
|
+
className="cursor-pointer"
|
|
127
|
+
key={`text-bubble-${index}`}
|
|
128
|
+
onClick={() => item.action()}
|
|
129
|
+
>
|
|
130
|
+
<div className="flex items-center gap-2 px-2">
|
|
131
|
+
<Icon className="h3 w-3" />
|
|
132
|
+
|
|
133
|
+
<span>
|
|
134
|
+
{' '}
|
|
135
|
+
{item.label}
|
|
136
|
+
</span>
|
|
137
|
+
</div>
|
|
138
|
+
</DropdownMenuCheckboxItem>
|
|
139
|
+
);
|
|
140
|
+
})}
|
|
141
|
+
</DropdownMenuContent>
|
|
142
|
+
</DropdownMenu>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default TextDropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TextBubble';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { Extension } from '@tiptap/core';
|
|
3
|
+
|
|
4
|
+
import TextDirectionButton from 'reactjs-tiptap-editor-pro/extensions/TextDirection/components/TextDirectionButton';
|
|
5
|
+
|
|
6
|
+
const TextDirection = Extension.create({
|
|
7
|
+
name: 'text-direction',
|
|
8
|
+
addOptions() {
|
|
9
|
+
return {
|
|
10
|
+
...this.parent?.(),
|
|
11
|
+
types: ['heading', 'paragraph'],
|
|
12
|
+
directions: ['auto', 'ltr', 'rtl'],
|
|
13
|
+
defaultDirection: 'auto',
|
|
14
|
+
button({
|
|
15
|
+
editor,
|
|
16
|
+
extension,
|
|
17
|
+
t,
|
|
18
|
+
}: {
|
|
19
|
+
editor: any
|
|
20
|
+
extension: Extension
|
|
21
|
+
t: (...args: any[]) => string
|
|
22
|
+
}) {
|
|
23
|
+
const directions = (extension.options?.directions as any[]) || [];
|
|
24
|
+
|
|
25
|
+
const iconMap = {
|
|
26
|
+
auto: 'TextDirection',
|
|
27
|
+
ltr: 'LeftToRight',
|
|
28
|
+
rtl: 'RightToLeft',
|
|
29
|
+
} as any;
|
|
30
|
+
|
|
31
|
+
const items = directions.map(k => ({
|
|
32
|
+
title: t(`editor.textDirection.${k}.tooltip`),
|
|
33
|
+
icon: iconMap[k],
|
|
34
|
+
isActive: () => false,
|
|
35
|
+
action: () => {
|
|
36
|
+
if (k === 'auto') {
|
|
37
|
+
editor.commands?.unsetTextDirection?.();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
editor.commands?.setTextDirection?.(k);
|
|
42
|
+
},
|
|
43
|
+
disabled: false,
|
|
44
|
+
}));
|
|
45
|
+
const disabled = items.filter(k => k.disabled).length === items.length;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
component: TextDirectionButton,
|
|
49
|
+
componentProps: {
|
|
50
|
+
icon: 'TextDirection',
|
|
51
|
+
tooltip: t('editor.textDirection.tooltip'),
|
|
52
|
+
disabled,
|
|
53
|
+
items,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
addGlobalAttributes() {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
types: this.options.types,
|
|
63
|
+
attributes: {
|
|
64
|
+
dir: {
|
|
65
|
+
default: this.options.defaultDirection,
|
|
66
|
+
parseHTML: (element: any) => {
|
|
67
|
+
if (element.attributes.dir && this.options.directions.includes(element.attributes.dir)) {
|
|
68
|
+
return element.attributes.dir.value;
|
|
69
|
+
} else {
|
|
70
|
+
return this.options.defaultDirection;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
renderHTML: (attributes) => {
|
|
74
|
+
return { dir: attributes.dir };
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
},
|
|
81
|
+
// @ts-expect-error
|
|
82
|
+
addCommands() {
|
|
83
|
+
return {
|
|
84
|
+
setTextDirection: (direction: any) => ({ commands }: any) => {
|
|
85
|
+
if (!this.options.directions.includes(direction)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return this.options.types.every((type: any) => commands.updateAttributes(type, { dir: direction }));
|
|
89
|
+
},
|
|
90
|
+
unsetTextDirection: () => ({ commands }: any) => {
|
|
91
|
+
return this.options.types.every((type: any) => commands.resetAttributes(type, 'dir'));
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export { TextDirection };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ActionButton, IconComponent } from 'reactjs-tiptap-editor-pro/components';
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger, Toggle, Tooltip, TooltipContent, TooltipTrigger } from 'reactjs-tiptap-editor-pro/components/ui';
|
|
5
|
+
import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
+
import { getShortcutKey } from 'reactjs-tiptap-editor-pro/utils/plateform';
|
|
7
|
+
|
|
8
|
+
export interface Item {
|
|
9
|
+
title: string
|
|
10
|
+
icon?: any
|
|
11
|
+
isActive: NonNullable<ButtonViewReturnComponentProps['isActive']>
|
|
12
|
+
action?: ButtonViewReturnComponentProps['action']
|
|
13
|
+
style?: React.CSSProperties
|
|
14
|
+
shortcutKeys?: string[]
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
divider?: boolean
|
|
17
|
+
default?: boolean
|
|
18
|
+
}
|
|
19
|
+
interface IPropsTextDirectionButton {
|
|
20
|
+
editor: any
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
color?: string
|
|
23
|
+
maxHeight?: string | number
|
|
24
|
+
icon?: any
|
|
25
|
+
tooltip?: string
|
|
26
|
+
items?: Item[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function TextDirectionButton(props: IPropsTextDirectionButton) {
|
|
30
|
+
const active = useMemo(() => {
|
|
31
|
+
const find: any = props?.items?.find((k: any) => k.isActive());
|
|
32
|
+
if (find && !find.default) {
|
|
33
|
+
return {
|
|
34
|
+
...find,
|
|
35
|
+
icon: find.icon ? find.icon : props.icon,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const item: Item = {
|
|
39
|
+
title: props?.tooltip as any,
|
|
40
|
+
icon: props.icon,
|
|
41
|
+
isActive: () => false,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return item;
|
|
45
|
+
}, [props]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Popover modal>
|
|
49
|
+
<PopoverTrigger asChild
|
|
50
|
+
disabled={props?.disabled}
|
|
51
|
+
>
|
|
52
|
+
<ActionButton
|
|
53
|
+
customClass="!w-12 h-12"
|
|
54
|
+
disabled={props?.disabled}
|
|
55
|
+
icon={props?.icon}
|
|
56
|
+
tooltip={props?.tooltip}
|
|
57
|
+
>
|
|
58
|
+
<IconComponent className="ml-1 size-3 text-zinc-500"
|
|
59
|
+
name="MenuDown"
|
|
60
|
+
/>
|
|
61
|
+
</ActionButton>
|
|
62
|
+
</PopoverTrigger>
|
|
63
|
+
|
|
64
|
+
<PopoverContent
|
|
65
|
+
align="start"
|
|
66
|
+
className="flex w-full min-w-4 flex-row gap-1 !p-[4px]"
|
|
67
|
+
side="bottom"
|
|
68
|
+
>
|
|
69
|
+
{props?.items?.map((item, index) => {
|
|
70
|
+
return (
|
|
71
|
+
<Tooltip key={`text-align-${index}`}>
|
|
72
|
+
<TooltipTrigger asChild>
|
|
73
|
+
<Toggle
|
|
74
|
+
className="size-7 p-1"
|
|
75
|
+
data-state={active.title === item.title ? 'on' : 'off'}
|
|
76
|
+
onClick={item?.action}
|
|
77
|
+
pressed={active.title === item.title}
|
|
78
|
+
size="sm"
|
|
79
|
+
>
|
|
80
|
+
{item?.icon && <IconComponent name={item.icon} />}
|
|
81
|
+
</Toggle>
|
|
82
|
+
</TooltipTrigger>
|
|
83
|
+
|
|
84
|
+
<TooltipContent className="flex flex-col items-center">
|
|
85
|
+
<span>
|
|
86
|
+
{item.title}
|
|
87
|
+
</span>
|
|
88
|
+
|
|
89
|
+
{!!item.shortcutKeys?.length && (
|
|
90
|
+
<span>
|
|
91
|
+
{item.shortcutKeys?.map(item => getShortcutKey(item)).join(' ')}
|
|
92
|
+
</span>
|
|
93
|
+
)}
|
|
94
|
+
</TooltipContent>
|
|
95
|
+
</Tooltip>
|
|
96
|
+
);
|
|
97
|
+
})}
|
|
98
|
+
</PopoverContent>
|
|
99
|
+
</Popover>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default TextDirectionButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TextDirection';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { Extension } from '@tiptap/core';
|
|
3
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
function nodeEqualsType({ types, node }) {
|
|
7
|
+
return (Array.isArray(types) && types.includes(node.type)) || node.type === types;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Extension based on:
|
|
12
|
+
* - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js
|
|
13
|
+
* - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface TrailingNodeOptions {
|
|
17
|
+
node: string
|
|
18
|
+
notAfter: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const TrailingNode = Extension.create<TrailingNodeOptions>({
|
|
22
|
+
name: 'trailingNode',
|
|
23
|
+
|
|
24
|
+
addOptions() {
|
|
25
|
+
return {
|
|
26
|
+
node: 'paragraph',
|
|
27
|
+
notAfter: ['paragraph'],
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
addProseMirrorPlugins() {
|
|
32
|
+
const plugin = new PluginKey(this.name);
|
|
33
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes)
|
|
34
|
+
.map(([, value]) => value)
|
|
35
|
+
.filter(node => this.options.notAfter.includes(node.name));
|
|
36
|
+
|
|
37
|
+
return [
|
|
38
|
+
new Plugin({
|
|
39
|
+
key: plugin,
|
|
40
|
+
appendTransaction: (_, __, state) => {
|
|
41
|
+
const { doc, tr, schema } = state;
|
|
42
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
43
|
+
const endPosition = doc.content.size;
|
|
44
|
+
const type = schema.nodes[this.options.node];
|
|
45
|
+
|
|
46
|
+
if (!shouldInsertNodeAtEnd) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return tr.insert(endPosition, type.create());
|
|
51
|
+
},
|
|
52
|
+
state: {
|
|
53
|
+
init: (_, state) => {
|
|
54
|
+
const lastNode = state.tr.doc.lastChild;
|
|
55
|
+
|
|
56
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
57
|
+
},
|
|
58
|
+
apply: (tr, value) => {
|
|
59
|
+
if (!tr.docChanged) {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const lastNode = tr.doc.lastChild;
|
|
64
|
+
|
|
65
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
];
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TrailingNode';
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Node, mergeAttributes, nodePasteRule } from '@tiptap/core';
|
|
2
|
+
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
3
|
+
import NodeViewTweet from 'reactjs-tiptap-editor-pro/extensions/Twitter/components/NodeViewTweet';
|
|
4
|
+
import TwitterActiveButton from 'reactjs-tiptap-editor-pro/extensions/Twitter/components/TwitterActiveButton';
|
|
5
|
+
|
|
6
|
+
const TWITTER_REGEX_GLOBAL = /(https?:\/\/)?(www\.)?x\.com\/(\w{1,15})(\/status\/(\d+))?(\/\S*)?/g;
|
|
7
|
+
const TWITTER_REGEX = /^https?:\/\/(www\.)?x\.com\/(\w{1,15})(\/status\/(\d+))?(\/\S*)?$/;
|
|
8
|
+
|
|
9
|
+
function isValidTwitterUrl(url: string) {
|
|
10
|
+
return url.match(TWITTER_REGEX);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface TwitterOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Controls if the paste handler for tweets should be added.
|
|
16
|
+
* @default true
|
|
17
|
+
* @example false
|
|
18
|
+
*/
|
|
19
|
+
addPasteHandler: boolean
|
|
20
|
+
|
|
21
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
22
|
+
HTMLAttributes: Record<string, any>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Controls if the twitter node should be inline or not.
|
|
26
|
+
* @default false
|
|
27
|
+
* @example true
|
|
28
|
+
*/
|
|
29
|
+
inline: boolean
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The origin of the tweet.
|
|
33
|
+
* @default ''
|
|
34
|
+
* @example 'https://tiptap.dev'
|
|
35
|
+
*/
|
|
36
|
+
origin: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The options for setting a tweet.
|
|
41
|
+
*/
|
|
42
|
+
interface SetTweetOptions {
|
|
43
|
+
src: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module '@tiptap/core' {
|
|
47
|
+
interface Commands<ReturnType> {
|
|
48
|
+
twitter: {
|
|
49
|
+
/**
|
|
50
|
+
* Insert a tweet
|
|
51
|
+
* @param options The tweet attributes
|
|
52
|
+
* @example editor.commands.setTweet({ src: 'https://x.com/seanpk/status/1800145949580517852' })
|
|
53
|
+
*/
|
|
54
|
+
setTweet: (options: SetTweetOptions) => ReturnType
|
|
55
|
+
updateTweet: (options: SetTweetOptions) => ReturnType
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* This extension adds support for tweets.
|
|
62
|
+
*/
|
|
63
|
+
export const Twitter = Node.create<TwitterOptions>({
|
|
64
|
+
name: 'twitter',
|
|
65
|
+
draggable: true,
|
|
66
|
+
selectable: true,
|
|
67
|
+
|
|
68
|
+
addOptions() {
|
|
69
|
+
return {
|
|
70
|
+
addPasteHandler: true,
|
|
71
|
+
HTMLAttributes: {},
|
|
72
|
+
inline: false,
|
|
73
|
+
origin: '',
|
|
74
|
+
button: ({ editor, t }: any) => ({
|
|
75
|
+
component: TwitterActiveButton,
|
|
76
|
+
componentProps: {
|
|
77
|
+
action: (src: string) => {
|
|
78
|
+
editor.commands.setTweet({ src });
|
|
79
|
+
},
|
|
80
|
+
isActive: () => false,
|
|
81
|
+
disabled: false,
|
|
82
|
+
icon: 'Twitter',
|
|
83
|
+
tooltip: t('editor.twitter.tooltip'),
|
|
84
|
+
editor,
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
addNodeView() {
|
|
91
|
+
return ReactNodeViewRenderer(NodeViewTweet, { attrs: this.options.HTMLAttributes });
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
inline() {
|
|
95
|
+
return this.options.inline;
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
group() {
|
|
99
|
+
return this.options.inline ? 'inline' : 'block';
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
addAttributes() {
|
|
103
|
+
return {
|
|
104
|
+
src: {
|
|
105
|
+
default: null,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
parseHTML() {
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
tag: 'div[data-twitter]',
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
addCommands() {
|
|
119
|
+
return {
|
|
120
|
+
setTweet:
|
|
121
|
+
(options: SetTweetOptions) =>
|
|
122
|
+
({ commands }) => {
|
|
123
|
+
if (!isValidTwitterUrl(options.src)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return commands.insertContent({
|
|
128
|
+
type: this.name,
|
|
129
|
+
attrs: options,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
updateTweet: (options: SetTweetOptions) => ({ commands }: any) => {
|
|
133
|
+
if (!isValidTwitterUrl(options.src)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return commands.updateAttributes(this.name, { src: options.src });
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
addPasteRules() {
|
|
143
|
+
if (!this.options.addPasteHandler) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return [
|
|
148
|
+
nodePasteRule({
|
|
149
|
+
find: TWITTER_REGEX_GLOBAL,
|
|
150
|
+
type: this.type,
|
|
151
|
+
getAttributes: (match) => {
|
|
152
|
+
return { src: match.input };
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
];
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
renderHTML({ HTMLAttributes }) {
|
|
159
|
+
return ['div', mergeAttributes({ 'data-twitter': '' }, HTMLAttributes)];
|
|
160
|
+
},
|
|
161
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import { Button, Input, Label } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
+
import { Twitter } from 'reactjs-tiptap-editor-pro/extensions/Twitter/Twitter';
|
|
8
|
+
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
9
|
+
|
|
10
|
+
interface IPropsFormEditLinkTwitter {
|
|
11
|
+
editor: any
|
|
12
|
+
onSetLink: (src: string) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function FormEditLinkTwitter(props: IPropsFormEditLinkTwitter) {
|
|
16
|
+
const { t } = useLocale();
|
|
17
|
+
|
|
18
|
+
const [src, setSrc] = useState('');
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (props?.editor) {
|
|
22
|
+
const { src: srcInit } = props.editor?.getAttributes(Twitter.name);
|
|
23
|
+
|
|
24
|
+
if (srcInit) {
|
|
25
|
+
setSrc(srcInit);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, [props?.editor]);
|
|
29
|
+
|
|
30
|
+
function handleSubmit(event: any) {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
props?.onSetLink(src);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="border-neutral-200 rounded-lg !border bg-white p-2 shadow-sm dark:border-neutral-800 dark:bg-black">
|
|
38
|
+
<form className="flex flex-col gap-2"
|
|
39
|
+
onSubmit={handleSubmit}
|
|
40
|
+
>
|
|
41
|
+
<Label className="mb-[6px]">
|
|
42
|
+
{t('editor.link.dialog.text')}
|
|
43
|
+
</Label>
|
|
44
|
+
|
|
45
|
+
<div className="mb-[10px] flex w-full max-w-sm items-center gap-1.5">
|
|
46
|
+
<div className="relative w-full max-w-sm items-center">
|
|
47
|
+
<Input
|
|
48
|
+
className="w-80"
|
|
49
|
+
onChange={e => setSrc(e.target.value)}
|
|
50
|
+
placeholder="Text"
|
|
51
|
+
required
|
|
52
|
+
type="text"
|
|
53
|
+
value={src}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<Button className="mt-2 self-end"
|
|
59
|
+
type="submit"
|
|
60
|
+
>
|
|
61
|
+
{t('editor.link.dialog.button.apply')}
|
|
62
|
+
</Button>
|
|
63
|
+
</form>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default FormEditLinkTwitter;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { NodeViewWrapper, type ReactNodeViewRendererOptions } from '@tiptap/react';
|
|
3
|
+
import { Tweet } from 'react-tweet';
|
|
4
|
+
|
|
5
|
+
export const TWITTER_REGEX_GLOBAL = /(https?:\/\/)?(www\.)?x\.com\/(\w{1,15})(\/status\/(\d+))?(\/\S*)?/g;
|
|
6
|
+
export const TWITTER_REGEX = /^https?:\/\/(www\.)?x\.com\/(\w{1,15})(\/status\/(\d+))?(\/\S*)?$/;
|
|
7
|
+
|
|
8
|
+
export function isValidTwitterUrl(url: string) {
|
|
9
|
+
return url.match(TWITTER_REGEX);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function NodeViewTweet({ node }: { node: Partial<ReactNodeViewRendererOptions> }) {
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
const url = node?.attrs?.src || '';
|
|
15
|
+
const tweetId = url?.split('/').pop();
|
|
16
|
+
|
|
17
|
+
if (!tweetId) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<NodeViewWrapper>
|
|
23
|
+
<div data-twitter="">
|
|
24
|
+
<Tweet id={tweetId} />
|
|
25
|
+
</div>
|
|
26
|
+
</NodeViewWrapper>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default NodeViewTweet;
|