reactjs-tiptap-editor-pro 0.2.31 → 0.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ColorPicker-MEAh4MhG.js +28181 -0
- package/lib/ColorPicker-ZncOwjAP.cjs +142 -0
- package/lib/extension-bundle.cjs +133 -0
- package/lib/extension-bundle.d.cts +947 -0
- package/lib/extension-bundle.d.ts +947 -0
- package/lib/extension-bundle.js +23921 -0
- package/lib/index.cjs +140 -0
- package/lib/index.d.cts +513 -0
- package/lib/index.d.ts +513 -0
- package/lib/index.js +3700 -0
- package/lib/locale-bundle-DiqW5jwb.cjs +1 -0
- package/lib/locale-bundle-DxCAtRDI.js +1487 -0
- package/lib/locale-bundle.cjs +1 -0
- package/lib/locale-bundle.d.cts +1140 -0
- package/lib/locale-bundle.d.ts +1140 -0
- package/lib/locale-bundle.js +9 -0
- package/lib/lucide-react-BFZtMawV.js +30462 -0
- package/lib/lucide-react-CMPhLW1m.cjs +7851 -0
- package/lib/style.css +1 -0
- package/package.json +58 -5
- package/src/components/ActionButton.tsx +0 -103
- package/src/components/ActionMenuButton.tsx +0 -76
- package/src/components/BubbleMenu.tsx +0 -93
- package/src/components/CharactorCount.tsx +0 -50
- package/src/components/ColorPicker.tsx +0 -272
- package/src/components/RichTextEditor.tsx +0 -212
- package/src/components/SizeSetter/SizeSetter.tsx +0 -102
- package/src/components/Toolbar.tsx +0 -108
- package/src/components/icons/Activity.tsx +0 -19
- package/src/components/icons/Animas.tsx +0 -24
- package/src/components/icons/AspectRatio.tsx +0 -13
- package/src/components/icons/Blockquote.tsx +0 -17
- package/src/components/icons/ColumnAddLeft.tsx +0 -7
- package/src/components/icons/ColumnAddRight.tsx +0 -7
- package/src/components/icons/DeleteColumn.tsx +0 -26
- package/src/components/icons/DeleteRow.tsx +0 -26
- package/src/components/icons/Direction.tsx +0 -7
- package/src/components/icons/Excalidraw.tsx +0 -7
- package/src/components/icons/ExportPdf.tsx +0 -8
- package/src/components/icons/ExportWord.tsx +0 -24
- package/src/components/icons/FileWordOutline.tsx +0 -13
- package/src/components/icons/Flag.tsx +0 -19
- package/src/components/icons/Food.tsx +0 -20
- package/src/components/icons/GIfIcon.tsx +0 -10
- package/src/components/icons/Icon.tsx +0 -30
- package/src/components/icons/ImportWord.tsx +0 -23
- package/src/components/icons/LeftToRight.tsx +0 -7
- package/src/components/icons/LineHeight.tsx +0 -13
- package/src/components/icons/MenuDown.tsx +0 -24
- package/src/components/icons/Mermaid.tsx +0 -13
- package/src/components/icons/NoFill.tsx +0 -7
- package/src/components/icons/Object.tsx +0 -24
- package/src/components/icons/RightToLeft.tsx +0 -7
- package/src/components/icons/SizeL.tsx +0 -9
- package/src/components/icons/SizeM.tsx +0 -13
- package/src/components/icons/SizeS.tsx +0 -13
- package/src/components/icons/Symbol.tsx +0 -19
- package/src/components/icons/Travel.tsx +0 -24
- package/src/components/icons/Twitter.tsx +0 -7
- package/src/components/icons/icons.ts +0 -212
- package/src/components/icons/index.ts +0 -12
- package/src/components/index.ts +0 -9
- package/src/components/menus/bubble.ts +0 -395
- package/src/components/menus/components/BubbleMenuContent.tsx +0 -15
- package/src/components/menus/components/BubbleMenuDrawer.tsx +0 -128
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +0 -91
- package/src/components/menus/components/BubbleMenuIframe.tsx +0 -143
- package/src/components/menus/components/BubbleMenuKatex.tsx +0 -136
- package/src/components/menus/components/BubbleMenuLink.tsx +0 -99
- package/src/components/menus/components/BubbleMenuMedia.tsx +0 -235
- package/src/components/menus/components/BubbleMenuMermaid.tsx +0 -128
- package/src/components/menus/components/BubbleMenuText.tsx +0 -102
- package/src/components/menus/components/BubbleMenuTwitter.tsx +0 -91
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +0 -59
- package/src/components/menus/components/ContentMenu.tsx +0 -396
- package/src/components/menus/components/TableBubbleMenu.tsx +0 -362
- package/src/components/menus/index.ts +0 -7
- package/src/components/ui/button.tsx +0 -56
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -128
- package/src/components/ui/dropdown-menu.tsx +0 -203
- package/src/components/ui/emoji-picker.tsx +0 -166
- package/src/components/ui/index.ts +0 -14
- package/src/components/ui/input.tsx +0 -25
- package/src/components/ui/label.tsx +0 -26
- package/src/components/ui/popover.tsx +0 -31
- package/src/components/ui/select.tsx +0 -162
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/textarea.tsx +0 -24
- package/src/components/ui/toast.tsx +0 -129
- package/src/components/ui/toaster.tsx +0 -44
- package/src/components/ui/toggle.tsx +0 -45
- package/src/components/ui/tooltip.tsx +0 -30
- package/src/components/ui/use-toast.ts +0 -197
- package/src/constants/index.ts +0 -223
- package/src/constants/resetCSS.ts +0 -139
- package/src/extension-bundle.ts +0 -2
- package/src/extensions/Attachment/Attachment.ts +0 -144
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +0 -69
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +0 -28
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +0 -155
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +0 -23
- package/src/extensions/Attachment/index.ts +0 -1
- package/src/extensions/BaseKit.ts +0 -253
- package/src/extensions/Blockquote/Blockquote.ts +0 -31
- package/src/extensions/Blockquote/index.ts +0 -1
- package/src/extensions/Bold/Bold.ts +0 -26
- package/src/extensions/Bold/index.ts +0 -1
- package/src/extensions/BulletList/BulletList.ts +0 -28
- package/src/extensions/BulletList/index.ts +0 -1
- package/src/extensions/Clear/Clear.ts +0 -24
- package/src/extensions/Clear/index.ts +0 -1
- package/src/extensions/Code/Code.ts +0 -26
- package/src/extensions/Code/index.ts +0 -1
- package/src/extensions/CodeBlock/CodeBlock.ts +0 -54
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +0 -66
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +0 -89
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +0 -81
- package/src/extensions/CodeBlock/highlighter.ts +0 -132
- package/src/extensions/CodeBlock/index.ts +0 -1
- package/src/extensions/CodeBlock/shiki-plugin.ts +0 -213
- package/src/extensions/Color/Color.ts +0 -52
- package/src/extensions/Color/components/ColorActionButton.tsx +0 -104
- package/src/extensions/Color/index.ts +0 -1
- package/src/extensions/Document/Document.ts +0 -8
- package/src/extensions/Document/index.ts +0 -1
- package/src/extensions/Drawer/Drawer.ts +0 -177
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +0 -85
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +0 -598
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +0 -500
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +0 -239
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +0 -238
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +0 -260
- package/src/extensions/Drawer/index.ts +0 -1
- package/src/extensions/Emoji/Emoji.ts +0 -146
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +0 -103
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +0 -1858
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +0 -61
- package/src/extensions/Emoji/index.ts +0 -1
- package/src/extensions/Excalidraw/Excalidraw.ts +0 -123
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +0 -138
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +0 -178
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +0 -43
- package/src/extensions/Excalidraw/index.ts +0 -1
- package/src/extensions/ExportPdf/ExportPdf.ts +0 -25
- package/src/extensions/ExportPdf/index.ts +0 -1
- package/src/extensions/ExportWord/ExportWord.ts +0 -87
- package/src/extensions/ExportWord/index.ts +0 -1
- package/src/extensions/FontFamily/FontFamily.ts +0 -64
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +0 -97
- package/src/extensions/FontFamily/index.ts +0 -1
- package/src/extensions/FontSize/FontSize.ts +0 -119
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +0 -84
- package/src/extensions/FontSize/index.ts +0 -1
- package/src/extensions/FormatPainter/FormatPainter.ts +0 -121
- package/src/extensions/FormatPainter/index.ts +0 -1
- package/src/extensions/Heading/Heading.ts +0 -57
- package/src/extensions/Heading/components/HeadingButton.tsx +0 -96
- package/src/extensions/Heading/index.ts +0 -1
- package/src/extensions/Highlight/Highlight.ts +0 -36
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +0 -108
- package/src/extensions/Highlight/index.ts +0 -1
- package/src/extensions/History/History.ts +0 -39
- package/src/extensions/History/components/HistoryActionButton.tsx +0 -74
- package/src/extensions/History/index.ts +0 -1
- package/src/extensions/HorizontalRule/HorizontalRule.ts +0 -42
- package/src/extensions/HorizontalRule/index.ts +0 -1
- package/src/extensions/Iframe/Iframe.ts +0 -140
- package/src/extensions/Iframe/components/IframeNodeView.tsx +0 -92
- package/src/extensions/Iframe/components/index.module.scss +0 -40
- package/src/extensions/Iframe/embed.ts +0 -487
- package/src/extensions/Iframe/index.ts +0 -1
- package/src/extensions/Image/Image.ts +0 -303
- package/src/extensions/Image/components/ActionImageButton.tsx +0 -186
- package/src/extensions/Image/components/ImageCropper.tsx +0 -198
- package/src/extensions/Image/components/ImageView.tsx +0 -271
- package/src/extensions/Image/index.ts +0 -1
- package/src/extensions/Image/store.ts +0 -15
- package/src/extensions/ImageGif/ImageGif.ts +0 -176
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +0 -138
- package/src/extensions/ImageGif/components/ImageGifView.tsx +0 -260
- package/src/extensions/ImageGif/index.ts +0 -1
- package/src/extensions/ImportWord/ImportWord.ts +0 -52
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +0 -151
- package/src/extensions/ImportWord/index.ts +0 -1
- package/src/extensions/Indent/Indent.ts +0 -110
- package/src/extensions/Indent/index.ts +0 -1
- package/src/extensions/Italic/Italic.ts +0 -29
- package/src/extensions/Italic/index.ts +0 -1
- package/src/extensions/Katex/Katex.ts +0 -109
- package/src/extensions/Katex/components/KatexActiveButton.tsx +0 -117
- package/src/extensions/Katex/components/KatexWrapper.tsx +0 -53
- package/src/extensions/Katex/index.ts +0 -1
- package/src/extensions/LineHeight/LineHeight.ts +0 -76
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +0 -93
- package/src/extensions/LineHeight/index.ts +0 -1
- package/src/extensions/Link/Link.ts +0 -92
- package/src/extensions/Link/components/LinkEditBlock.tsx +0 -110
- package/src/extensions/Link/components/LinkEditPopover.tsx +0 -46
- package/src/extensions/Link/components/LinkViewBlock.tsx +0 -54
- package/src/extensions/Link/index.ts +0 -1
- package/src/extensions/ListItem/ListItem.ts +0 -1
- package/src/extensions/ListItem/index.ts +0 -1
- package/src/extensions/Mention/Mention.ts +0 -100
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +0 -94
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +0 -38
- package/src/extensions/Mention/index.ts +0 -1
- package/src/extensions/Mermaid/Mermaid.ts +0 -177
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +0 -155
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +0 -151
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +0 -260
- package/src/extensions/Mermaid/index.ts +0 -1
- package/src/extensions/MoreMark/MoreMark.ts +0 -102
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +0 -97
- package/src/extensions/MoreMark/index.ts +0 -1
- package/src/extensions/MultiColumn/Column.ts +0 -36
- package/src/extensions/MultiColumn/MultiColumn.ts +0 -111
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +0 -22
- package/src/extensions/MultiColumn/index.ts +0 -3
- package/src/extensions/OrderedList/OrderedList.ts +0 -28
- package/src/extensions/OrderedList/index.ts +0 -1
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +0 -395
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +0 -190
- package/src/extensions/SearchAndReplace/index.ts +0 -1
- package/src/extensions/Selection/Selection.ts +0 -32
- package/src/extensions/Selection/index.ts +0 -1
- package/src/extensions/SlashCommand/SlashCommand.ts +0 -255
- package/src/extensions/SlashCommand/components/CommandsList.tsx +0 -180
- package/src/extensions/SlashCommand/groups.ts +0 -183
- package/src/extensions/SlashCommand/index.ts +0 -1
- package/src/extensions/SlashCommand/types.ts +0 -24
- package/src/extensions/Strike/Strike.ts +0 -26
- package/src/extensions/Strike/index.ts +0 -1
- package/src/extensions/Subscript/Subscript.ts +0 -88
- package/src/extensions/Subscript/index.ts +0 -1
- package/src/extensions/Table/Cell.ts +0 -131
- package/src/extensions/Table/Header.ts +0 -93
- package/src/extensions/Table/Row.ts +0 -8
- package/src/extensions/Table/Table.ts +0 -60
- package/src/extensions/Table/cell-background.ts +0 -112
- package/src/extensions/Table/components/CreateTablePopover.tsx +0 -132
- package/src/extensions/Table/components/TableActionButton.tsx +0 -42
- package/src/extensions/Table/index.ts +0 -6
- package/src/extensions/Table/utils.ts +0 -352
- package/src/extensions/TableOfContent/TableOfContent.ts +0 -124
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +0 -116
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +0 -27
- package/src/extensions/TableOfContent/components/index.module.scss +0 -40
- package/src/extensions/TableOfContent/index.ts +0 -1
- package/src/extensions/TaskList/TaskList.ts +0 -46
- package/src/extensions/TaskList/index.ts +0 -1
- package/src/extensions/TextAlign/TextAlign.ts +0 -68
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +0 -103
- package/src/extensions/TextAlign/index.ts +0 -1
- package/src/extensions/TextBubble/TextBubble.ts +0 -22
- package/src/extensions/TextBubble/components/TextDropdown.tsx +0 -146
- package/src/extensions/TextBubble/index.ts +0 -1
- package/src/extensions/TextDirection/TextDirection.ts +0 -97
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +0 -103
- package/src/extensions/TextDirection/index.ts +0 -1
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -71
- package/src/extensions/TrailingNode/index.ts +0 -1
- package/src/extensions/Twitter/Twitter.ts +0 -161
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +0 -68
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +0 -30
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +0 -41
- package/src/extensions/Twitter/index.ts +0 -1
- package/src/extensions/UnderLine/Underline.ts +0 -30
- package/src/extensions/UnderLine/index.ts +0 -1
- package/src/extensions/Video/Video.ts +0 -204
- package/src/extensions/Video/components/ActiveVideoButton.tsx +0 -191
- package/src/extensions/Video/index.ts +0 -1
- package/src/extensions/Video/store.ts +0 -15
- package/src/extensions/index.ts +0 -122
- package/src/hooks/useActive.tsx +0 -24
- package/src/hooks/useAttributes.tsx +0 -45
- package/src/hooks/useCopy.tsx +0 -20
- package/src/hooks/useEditorState.tsx +0 -23
- package/src/hooks/useExtension.tsx +0 -29
- package/src/index.ts +0 -8
- package/src/lib/utils.ts +0 -7
- package/src/locale-bundle.ts +0 -3
- package/src/locales/en.ts +0 -173
- package/src/locales/hu.ts +0 -173
- package/src/locales/index.tsx +0 -163
- package/src/locales/pt-br.ts +0 -173
- package/src/locales/vi.ts +0 -173
- package/src/locales/zh-cn.ts +0 -173
- package/src/plugins/DragHandle/index.ts +0 -375
- package/src/plugins/DragHandle/range.ts +0 -114
- package/src/plugins/DragHandle/utils.ts +0 -80
- package/src/plugins/image-upload.ts +0 -160
- package/src/store/ProviderRichText.tsx +0 -53
- package/src/store/editableEditor.ts +0 -15
- package/src/store/fast-context.tsx +0 -70
- package/src/store/store.ts +0 -35
- package/src/styles/ProseMirror.scss +0 -176
- package/src/styles/columns.scss +0 -23
- package/src/styles/editor.scss +0 -411
- package/src/styles/global.scss +0 -87
- package/src/styles/index.scss +0 -5
- package/src/styles/mention.scss +0 -6
- package/src/theme/theme.ts +0 -15
- package/src/types.ts +0 -271
- package/src/utils/_event.ts +0 -55
- package/src/utils/color.ts +0 -67
- package/src/utils/columns.ts +0 -142
- package/src/utils/customEvents/customEvents.ts +0 -18
- package/src/utils/customEvents/events.constant.ts +0 -11
- package/src/utils/delete-node.ts +0 -46
- package/src/utils/dom-dataset.ts +0 -121
- package/src/utils/download.ts +0 -17
- package/src/utils/dynamicCSS.ts +0 -192
- package/src/utils/editor-container-size.ts +0 -28
- package/src/utils/file.ts +0 -112
- package/src/utils/getRenderContainer.ts +0 -41
- package/src/utils/indent.ts +0 -99
- package/src/utils/is-mobile.ts +0 -57
- package/src/utils/json.ts +0 -18
- package/src/utils/line-height.ts +0 -109
- package/src/utils/lru-cache.ts +0 -145
- package/src/utils/mitt.ts +0 -114
- package/src/utils/node.ts +0 -92
- package/src/utils/pdf.ts +0 -72
- package/src/utils/plateform.ts +0 -49
- package/src/utils/shortId.ts +0 -5
- package/src/utils/storage.ts +0 -18
- package/src/utils/utils.ts +0 -71
- package/src/vite-env.d.ts +0 -3
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Plus } from 'lucide-react';
|
|
4
|
-
import { HexColorPicker } from 'react-colorful';
|
|
5
|
-
|
|
6
|
-
import { Button, Input, Popover, PopoverContent, PopoverTrigger, Separator } from 'reactjs-tiptap-editor-pro/components';
|
|
7
|
-
import { NoFill } from 'reactjs-tiptap-editor-pro/components/icons/NoFill';
|
|
8
|
-
import { COLORS_LIST as DEFAULT_COLORS_LIST } from 'reactjs-tiptap-editor-pro/constants';
|
|
9
|
-
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
10
|
-
|
|
11
|
-
export interface ColorPickerProps {
|
|
12
|
-
highlight?: boolean
|
|
13
|
-
disabled?: boolean
|
|
14
|
-
colors?: string[]
|
|
15
|
-
defaultColor?: string
|
|
16
|
-
children: React.ReactNode
|
|
17
|
-
onChange?: (color: string | undefined) => void
|
|
18
|
-
setSelectedColor?: (color: string | undefined) => void
|
|
19
|
-
selectedColor?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function ColorPicker(props: ColorPickerProps) {
|
|
23
|
-
const { t } = useLocale();
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
highlight = false,
|
|
27
|
-
disabled = false,
|
|
28
|
-
selectedColor,
|
|
29
|
-
setSelectedColor,
|
|
30
|
-
onChange,
|
|
31
|
-
colors = DEFAULT_COLORS_LIST,
|
|
32
|
-
} = props;
|
|
33
|
-
|
|
34
|
-
const chunkedColors = useMemo(() => {
|
|
35
|
-
const colorsArray = colors;
|
|
36
|
-
const chunked: string[][] = [];
|
|
37
|
-
for (let i = 0; i < colorsArray.length; i += 10) {
|
|
38
|
-
chunked.push(colorsArray.slice(i, i + 10));
|
|
39
|
-
}
|
|
40
|
-
return chunked;
|
|
41
|
-
}, [colors]);
|
|
42
|
-
|
|
43
|
-
const [recentColorsStore, setRecentColorsStore] = useState<string[]>([]);
|
|
44
|
-
|
|
45
|
-
const setRecentColor = (color: string) => {
|
|
46
|
-
const newRecentColors = [...recentColorsStore];
|
|
47
|
-
const index = newRecentColors.indexOf(color);
|
|
48
|
-
if (index !== -1) {
|
|
49
|
-
newRecentColors.splice(index, 1);
|
|
50
|
-
}
|
|
51
|
-
newRecentColors.unshift(color);
|
|
52
|
-
if (newRecentColors.length > 10) {
|
|
53
|
-
newRecentColors.pop();
|
|
54
|
-
}
|
|
55
|
-
setRecentColorsStore(newRecentColors);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
function setColor(color: string | undefined) {
|
|
59
|
-
if (color === undefined) {
|
|
60
|
-
// clear color
|
|
61
|
-
setSelectedColor?.(color);
|
|
62
|
-
onChange?.(color);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// check if color is correct
|
|
66
|
-
const isCorrectColor = /^#([\da-f]{3}){1,2}$/i.test(color);
|
|
67
|
-
if (isCorrectColor) {
|
|
68
|
-
setSelectedColor?.(color);
|
|
69
|
-
onChange?.(color);
|
|
70
|
-
setRecentColor(color);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<Popover modal>
|
|
76
|
-
<PopoverTrigger asChild
|
|
77
|
-
className="!p-0"
|
|
78
|
-
disabled={disabled}
|
|
79
|
-
>
|
|
80
|
-
{props?.children}
|
|
81
|
-
</PopoverTrigger>
|
|
82
|
-
|
|
83
|
-
<PopoverContent align="start"
|
|
84
|
-
className="size-full p-2"
|
|
85
|
-
hideWhenDetached
|
|
86
|
-
side="bottom"
|
|
87
|
-
>
|
|
88
|
-
<div className="flex flex-col">
|
|
89
|
-
{highlight
|
|
90
|
-
? (
|
|
91
|
-
<div
|
|
92
|
-
className="rd-1 flex cursor-pointer items-center gap-[4px] p-1 hover:bg-accent"
|
|
93
|
-
onClick={() => setColor(undefined)}
|
|
94
|
-
>
|
|
95
|
-
<NoFill />
|
|
96
|
-
|
|
97
|
-
<span className="ml-1 text-sm">
|
|
98
|
-
{t('editor.nofill')}
|
|
99
|
-
</span>
|
|
100
|
-
</div>
|
|
101
|
-
)
|
|
102
|
-
: (
|
|
103
|
-
<div
|
|
104
|
-
className="rd-1 flex cursor-pointer items-center gap-[4px] p-1 hover:bg-accent"
|
|
105
|
-
onClick={() => {
|
|
106
|
-
setColor(undefined);
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
<NoFill />
|
|
110
|
-
|
|
111
|
-
<span className="ml-1 text-sm">
|
|
112
|
-
{t('editor.default')}
|
|
113
|
-
</span>
|
|
114
|
-
</div>
|
|
115
|
-
)}
|
|
116
|
-
|
|
117
|
-
{chunkedColors.map((items: string[], index: number) => {
|
|
118
|
-
return (
|
|
119
|
-
<span className="relative flex h-auto w-full p-0 last:pb-2"
|
|
120
|
-
key={index}
|
|
121
|
-
>
|
|
122
|
-
{items.map((item: string, idx) => {
|
|
123
|
-
return (
|
|
124
|
-
<span
|
|
125
|
-
className="inline-block size-6 flex-[0_0_auto] cursor-pointer rounded-sm !border border-transparent p-0.5 hover:border-border hover:shadow-sm"
|
|
126
|
-
key={`sub-color-${idx}`}
|
|
127
|
-
onClick={() => setColor(item)}
|
|
128
|
-
>
|
|
129
|
-
<span
|
|
130
|
-
className="relative block size-[18px] rounded-[2px] border-transparent"
|
|
131
|
-
style={{
|
|
132
|
-
backgroundColor: item,
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
{item === selectedColor
|
|
136
|
-
? (
|
|
137
|
-
<svg
|
|
138
|
-
className="absolute -top-px left-px block size-3"
|
|
139
|
-
viewBox="0 0 18 18"
|
|
140
|
-
style={{
|
|
141
|
-
fill: 'rgb(255, 255, 255)',
|
|
142
|
-
}}
|
|
143
|
-
>
|
|
144
|
-
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path>
|
|
145
|
-
</svg>
|
|
146
|
-
)
|
|
147
|
-
: (
|
|
148
|
-
<svg
|
|
149
|
-
viewBox="0 0 18 18"
|
|
150
|
-
style={{
|
|
151
|
-
fill: 'rgb(255, 255, 255)',
|
|
152
|
-
display: 'none',
|
|
153
|
-
}}
|
|
154
|
-
>
|
|
155
|
-
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path>
|
|
156
|
-
</svg>
|
|
157
|
-
)}
|
|
158
|
-
</span>
|
|
159
|
-
</span>
|
|
160
|
-
);
|
|
161
|
-
})}
|
|
162
|
-
</span>
|
|
163
|
-
);
|
|
164
|
-
})}
|
|
165
|
-
|
|
166
|
-
<div>
|
|
167
|
-
<div className="my-1 text-sm">
|
|
168
|
-
{t('editor.recent')}
|
|
169
|
-
</div>
|
|
170
|
-
|
|
171
|
-
<span className="relative flex h-auto w-full p-0 last:pb-2">
|
|
172
|
-
{recentColorsStore?.map((item, index) => {
|
|
173
|
-
return (
|
|
174
|
-
<span
|
|
175
|
-
className="inline-block size-6 flex-[0_0_auto] cursor-pointer rounded-sm !border border-transparent p-0.5 hover:border-border hover:shadow-sm"
|
|
176
|
-
key={`sub-color-recent-${index}`}
|
|
177
|
-
onClick={() => setColor(item)}
|
|
178
|
-
>
|
|
179
|
-
<span
|
|
180
|
-
className="relative block size-[18px] rounded-[2px] border-transparent"
|
|
181
|
-
style={{
|
|
182
|
-
backgroundColor: item,
|
|
183
|
-
}}
|
|
184
|
-
>
|
|
185
|
-
<svg
|
|
186
|
-
viewBox="0 0 18 18"
|
|
187
|
-
style={{
|
|
188
|
-
fill: 'rgb(255, 255, 255)',
|
|
189
|
-
display: 'none',
|
|
190
|
-
}}
|
|
191
|
-
>
|
|
192
|
-
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path>
|
|
193
|
-
</svg>
|
|
194
|
-
</span>
|
|
195
|
-
</span>
|
|
196
|
-
);
|
|
197
|
-
})}
|
|
198
|
-
</span>
|
|
199
|
-
</div>
|
|
200
|
-
|
|
201
|
-
<AddMoreColor setColor={setColor} />
|
|
202
|
-
</div>
|
|
203
|
-
</PopoverContent>
|
|
204
|
-
</Popover>
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
interface AddMoreColorProps {
|
|
209
|
-
setColor: (color: string) => void
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function AddMoreColor({ setColor }: AddMoreColorProps) {
|
|
213
|
-
const [colorMore, setColorMore] = useState('#000000');
|
|
214
|
-
const [openColorMore, setOpenColorMore] = useState(false);
|
|
215
|
-
const { t } = useLocale();
|
|
216
|
-
|
|
217
|
-
useEffect(() => {
|
|
218
|
-
return () => {
|
|
219
|
-
setOpenColorMore(false);
|
|
220
|
-
};
|
|
221
|
-
}, []);
|
|
222
|
-
|
|
223
|
-
return (
|
|
224
|
-
<Popover open={openColorMore}>
|
|
225
|
-
<PopoverTrigger asChild>
|
|
226
|
-
<div
|
|
227
|
-
className="p-1.5 text-sm hover:cursor-pointer hover:bg-accent"
|
|
228
|
-
onClick={(e) => {
|
|
229
|
-
e.preventDefault();
|
|
230
|
-
setOpenColorMore(true);
|
|
231
|
-
}}
|
|
232
|
-
>
|
|
233
|
-
{t('editor.color.more')}
|
|
234
|
-
...
|
|
235
|
-
</div>
|
|
236
|
-
</PopoverTrigger>
|
|
237
|
-
|
|
238
|
-
<PopoverContent>
|
|
239
|
-
<div className="flex flex-col items-center justify-center">
|
|
240
|
-
<HexColorPicker color={colorMore}
|
|
241
|
-
onChange={setColorMore}
|
|
242
|
-
/>
|
|
243
|
-
|
|
244
|
-
<Input
|
|
245
|
-
className="mt-[8px] w-full"
|
|
246
|
-
type="text"
|
|
247
|
-
value={colorMore.slice(1)}
|
|
248
|
-
onChange={(e) => {
|
|
249
|
-
e.preventDefault();
|
|
250
|
-
setColorMore(`#${e.target.value}`);
|
|
251
|
-
}}
|
|
252
|
-
/>
|
|
253
|
-
</div>
|
|
254
|
-
|
|
255
|
-
<Separator className="my-[10px]" />
|
|
256
|
-
|
|
257
|
-
<Button
|
|
258
|
-
className="w-full"
|
|
259
|
-
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
|
|
260
|
-
e.preventDefault();
|
|
261
|
-
setColor(colorMore);
|
|
262
|
-
setOpenColorMore(false);
|
|
263
|
-
}}
|
|
264
|
-
>
|
|
265
|
-
<Plus size={16} />
|
|
266
|
-
</Button>
|
|
267
|
-
</PopoverContent>
|
|
268
|
-
</Popover>
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export { ColorPicker };
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { AnyExtension, Editor as CoreEditor } from '@tiptap/core';
|
|
4
|
-
import type { UseEditorOptions } from '@tiptap/react';
|
|
5
|
-
import { EditorContent, useEditor } from '@tiptap/react';
|
|
6
|
-
import { differenceBy, throttle } from 'lodash-es';
|
|
7
|
-
|
|
8
|
-
import { BubbleMenu, Toolbar, TooltipProvider } from 'reactjs-tiptap-editor-pro/components';
|
|
9
|
-
import CharactorCount from 'reactjs-tiptap-editor-pro/components/CharactorCount';
|
|
10
|
-
import { Toaster } from 'reactjs-tiptap-editor-pro/components/ui/toaster';
|
|
11
|
-
import { EDITOR_UPDATE_WATCH_THROTTLE_WAIT_TIME } from 'reactjs-tiptap-editor-pro/constants';
|
|
12
|
-
import { RESET_CSS } from 'reactjs-tiptap-editor-pro/constants/resetCSS';
|
|
13
|
-
import { editableEditorActions } from 'reactjs-tiptap-editor-pro/store/editableEditor';
|
|
14
|
-
import { ProviderRichText } from 'reactjs-tiptap-editor-pro/store/ProviderRichText';
|
|
15
|
-
import { themeActions } from 'reactjs-tiptap-editor-pro/theme/theme';
|
|
16
|
-
import type { BubbleMenuProps, ToolbarProps } from 'reactjs-tiptap-editor-pro/types';
|
|
17
|
-
import { removeCSS, updateCSS } from 'reactjs-tiptap-editor-pro/utils/dynamicCSS';
|
|
18
|
-
import { hasExtension } from 'reactjs-tiptap-editor-pro/utils/utils';
|
|
19
|
-
|
|
20
|
-
import '../styles/index.scss';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Interface for RichTextEditor component props
|
|
24
|
-
*/
|
|
25
|
-
export interface RichTextEditorProps {
|
|
26
|
-
/** Content of the editor */
|
|
27
|
-
content: string
|
|
28
|
-
/** Extensions for the editor */
|
|
29
|
-
extensions: AnyExtension[]
|
|
30
|
-
|
|
31
|
-
/** Output format */
|
|
32
|
-
output: 'html' | 'json' | 'text'
|
|
33
|
-
/** Model value */
|
|
34
|
-
modelValue?: string | object
|
|
35
|
-
/** Dark mode flag */
|
|
36
|
-
dark?: boolean
|
|
37
|
-
/** Dense mode flag */
|
|
38
|
-
dense?: boolean
|
|
39
|
-
/** Disabled flag */
|
|
40
|
-
disabled?: boolean
|
|
41
|
-
/** Label for the editor */
|
|
42
|
-
label?: string
|
|
43
|
-
/** Hide toolbar flag */
|
|
44
|
-
hideToolbar?: boolean
|
|
45
|
-
/** Disable bubble menu flag */
|
|
46
|
-
disableBubble?: boolean
|
|
47
|
-
/** Hide bubble menu flag */
|
|
48
|
-
hideBubble?: boolean
|
|
49
|
-
/** Remove default wrapper flag */
|
|
50
|
-
removeDefaultWrapper?: boolean
|
|
51
|
-
/** Maximum width */
|
|
52
|
-
maxWidth?: string | number
|
|
53
|
-
/** Minimum height */
|
|
54
|
-
minHeight?: string | number
|
|
55
|
-
/** Maximum height */
|
|
56
|
-
maxHeight?: string | number
|
|
57
|
-
/** Content class */
|
|
58
|
-
contentClass?: string | string[] | Record<string, any>
|
|
59
|
-
/** Content change callback */
|
|
60
|
-
onChangeContent?: (val: any) => void
|
|
61
|
-
/** Bubble menu props */
|
|
62
|
-
bubbleMenu?: BubbleMenuProps
|
|
63
|
-
/** Toolbar props */
|
|
64
|
-
toolbar?: ToolbarProps
|
|
65
|
-
|
|
66
|
-
/** Use editor options */
|
|
67
|
-
useEditorOptions?: UseEditorOptions
|
|
68
|
-
|
|
69
|
-
/** Use editor options */
|
|
70
|
-
resetCSS?: boolean
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function RichTextEditor(props: RichTextEditorProps, ref: React.ForwardedRef<{ editor: CoreEditor | null }>) {
|
|
74
|
-
const { content, extensions, useEditorOptions = {} } = props;
|
|
75
|
-
|
|
76
|
-
const id = useId();
|
|
77
|
-
|
|
78
|
-
const sortExtensions = useMemo(() => {
|
|
79
|
-
const diff = differenceBy(extensions, extensions, 'name');
|
|
80
|
-
const exts = extensions.map((k: any) => {
|
|
81
|
-
const find = extensions.find((ext: any) => ext.name === k.name);
|
|
82
|
-
if (!find) {
|
|
83
|
-
return k;
|
|
84
|
-
}
|
|
85
|
-
return k.configure(find.options);
|
|
86
|
-
});
|
|
87
|
-
return [...exts, ...diff].map((k, i) => k.configure({ sort: i }));
|
|
88
|
-
}, [extensions]);
|
|
89
|
-
|
|
90
|
-
const onValueChange = throttle((editor) => {
|
|
91
|
-
const output = getOutput(editor, props.output as any);
|
|
92
|
-
|
|
93
|
-
props?.onChangeContent?.(output as any);
|
|
94
|
-
}, EDITOR_UPDATE_WATCH_THROTTLE_WAIT_TIME);
|
|
95
|
-
|
|
96
|
-
const editor = useEditor({
|
|
97
|
-
extensions: sortExtensions,
|
|
98
|
-
content,
|
|
99
|
-
onUpdate: ({ editor }) => {
|
|
100
|
-
if (onValueChange)
|
|
101
|
-
onValueChange(editor);
|
|
102
|
-
},
|
|
103
|
-
...useEditorOptions,
|
|
104
|
-
}) as any;
|
|
105
|
-
|
|
106
|
-
useImperativeHandle(ref, () => {
|
|
107
|
-
return {
|
|
108
|
-
editor,
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
document.documentElement.classList.toggle('dark', props.dark);
|
|
114
|
-
themeActions.setTheme(id, props.dark ? 'dark' : 'light');
|
|
115
|
-
}, [props.dark]);
|
|
116
|
-
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
editor?.setEditable(!props?.disabled);
|
|
119
|
-
editableEditorActions.setDisable(id, !props?.disabled);
|
|
120
|
-
}, [editor, props?.disabled]);
|
|
121
|
-
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
if (props?.resetCSS !== false) {
|
|
124
|
-
updateCSS(RESET_CSS, 'react-tiptap-reset');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return () => {
|
|
128
|
-
removeCSS('react-tiptap-reset');
|
|
129
|
-
};
|
|
130
|
-
}, [props?.resetCSS]);
|
|
131
|
-
|
|
132
|
-
function getOutput(editor: CoreEditor, output: RichTextEditorProps['output']) {
|
|
133
|
-
if (props?.removeDefaultWrapper) {
|
|
134
|
-
if (output === 'html') {
|
|
135
|
-
return editor.isEmpty ? '' : editor.getHTML();
|
|
136
|
-
}
|
|
137
|
-
if (output === 'json') {
|
|
138
|
-
return editor.isEmpty ? {} : editor.getJSON();
|
|
139
|
-
}
|
|
140
|
-
if (output === 'text') {
|
|
141
|
-
return editor.isEmpty ? '' : editor.getText();
|
|
142
|
-
}
|
|
143
|
-
return '';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (output === 'html') {
|
|
147
|
-
return editor.getHTML();
|
|
148
|
-
}
|
|
149
|
-
if (output === 'json') {
|
|
150
|
-
return editor.getJSON();
|
|
151
|
-
}
|
|
152
|
-
if (output === 'text') {
|
|
153
|
-
return editor.getText();
|
|
154
|
-
}
|
|
155
|
-
return '';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
useLayoutEffect(() => {
|
|
159
|
-
if (editor) editor!.id = id;
|
|
160
|
-
}, [id, editor]);
|
|
161
|
-
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
return () => {
|
|
164
|
-
editor?.destroy?.();
|
|
165
|
-
};
|
|
166
|
-
}, []);
|
|
167
|
-
|
|
168
|
-
const hasExtensionValue = hasExtension(editor, 'characterCount');
|
|
169
|
-
|
|
170
|
-
if (!editor) {
|
|
171
|
-
return <></>;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
<div className="reactjs-tiptap-editor">
|
|
176
|
-
<ProviderRichText
|
|
177
|
-
id={id}
|
|
178
|
-
>
|
|
179
|
-
<TooltipProvider delayDuration={0}
|
|
180
|
-
disableHoverableContent
|
|
181
|
-
>
|
|
182
|
-
<div className="overflow-hidden rounded-[0.5rem] bg-background">
|
|
183
|
-
<div className="flex max-h-full w-full flex-col">
|
|
184
|
-
{!props?.hideToolbar && <Toolbar disabled={!!props?.disabled}
|
|
185
|
-
editor={editor}
|
|
186
|
-
toolbar={props.toolbar}
|
|
187
|
-
/>}
|
|
188
|
-
|
|
189
|
-
<EditorContent className={`relative ${props?.contentClass || ''}`}
|
|
190
|
-
editor={editor}
|
|
191
|
-
|
|
192
|
-
/>
|
|
193
|
-
|
|
194
|
-
{hasExtensionValue && <CharactorCount editor={editor}
|
|
195
|
-
extensions={extensions}
|
|
196
|
-
/>}
|
|
197
|
-
|
|
198
|
-
{!props?.hideBubble && <BubbleMenu bubbleMenu={props?.bubbleMenu}
|
|
199
|
-
disabled={props?.disabled}
|
|
200
|
-
editor={editor}
|
|
201
|
-
/>}
|
|
202
|
-
</div>
|
|
203
|
-
</div>
|
|
204
|
-
</TooltipProvider>
|
|
205
|
-
</ProviderRichText>
|
|
206
|
-
|
|
207
|
-
<Toaster />
|
|
208
|
-
</div>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export default forwardRef(RichTextEditor);
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { Button, Input, Label, Popover, PopoverContent, PopoverTrigger } from 'reactjs-tiptap-editor-pro/components/ui';
|
|
3
|
-
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
4
|
-
|
|
5
|
-
interface ISize {
|
|
6
|
-
width: number | string, height: number | string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface IProps {
|
|
10
|
-
width: number | string
|
|
11
|
-
maxWidth?: number | string
|
|
12
|
-
height: number | string
|
|
13
|
-
onOk: (arg: ISize) => void
|
|
14
|
-
children: React.ReactNode
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const containerStyle = { padding: '0 12px 12px' };
|
|
18
|
-
|
|
19
|
-
export const SizeSetter: React.FC<IProps> = ({ width, maxWidth, height, onOk, children }: any) => {
|
|
20
|
-
const { t } = useLocale();
|
|
21
|
-
|
|
22
|
-
const [form, setForm] = useState({
|
|
23
|
-
width: '',
|
|
24
|
-
height: '',
|
|
25
|
-
maxWidth: '',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
setForm({
|
|
30
|
-
width,
|
|
31
|
-
height,
|
|
32
|
-
maxWidth,
|
|
33
|
-
});
|
|
34
|
-
}, [height, maxWidth, width]);
|
|
35
|
-
|
|
36
|
-
function handleSubmit(event: any) {
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
event.stopPropagation();
|
|
39
|
-
onOk(form);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<Popover modal>
|
|
44
|
-
<PopoverTrigger asChild>
|
|
45
|
-
{children}
|
|
46
|
-
</PopoverTrigger>
|
|
47
|
-
|
|
48
|
-
<PopoverContent>
|
|
49
|
-
<div style={containerStyle}>
|
|
50
|
-
<form className="flex flex-col gap-2" onSubmit={handleSubmit}>
|
|
51
|
-
<Label className="mb-[6px]">
|
|
52
|
-
Width
|
|
53
|
-
</Label>
|
|
54
|
-
|
|
55
|
-
<div className="flex w-full max-w-sm items-center gap-1.5">
|
|
56
|
-
<div className="relative items-center w-full max-w-sm">
|
|
57
|
-
<Input
|
|
58
|
-
type="number"
|
|
59
|
-
value={form.width}
|
|
60
|
-
required
|
|
61
|
-
onChange={e => setForm({ ...form, width: e.target.value })}
|
|
62
|
-
/>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<Label className="mb-[6px]">
|
|
67
|
-
Max Width
|
|
68
|
-
</Label>
|
|
69
|
-
|
|
70
|
-
<div className="flex w-full max-w-sm items-center gap-1.5">
|
|
71
|
-
<div className="relative items-center w-full max-w-sm">
|
|
72
|
-
<Input
|
|
73
|
-
type="number"
|
|
74
|
-
value={form.maxWidth}
|
|
75
|
-
required
|
|
76
|
-
onChange={e => setForm({ ...form, maxWidth: e.target.value })}
|
|
77
|
-
/>
|
|
78
|
-
</div>
|
|
79
|
-
</div>
|
|
80
|
-
<Label className="mb-[6px]">
|
|
81
|
-
Height
|
|
82
|
-
</Label>
|
|
83
|
-
<div className="flex w-full max-w-sm items-center gap-1.5">
|
|
84
|
-
<div className="relative items-center w-full max-w-sm">
|
|
85
|
-
<Input
|
|
86
|
-
type="number"
|
|
87
|
-
value={form.height}
|
|
88
|
-
required
|
|
89
|
-
onChange={e => setForm({ ...form, height: e.target.value })}
|
|
90
|
-
/>
|
|
91
|
-
</div>
|
|
92
|
-
</div>
|
|
93
|
-
|
|
94
|
-
<Button type="submit" className="self-end mt-2">
|
|
95
|
-
{t('editor.link.dialog.button.apply')}
|
|
96
|
-
</Button>
|
|
97
|
-
</form>
|
|
98
|
-
</div>
|
|
99
|
-
</PopoverContent>
|
|
100
|
-
</Popover>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import type { Editor } from '@tiptap/core';
|
|
3
|
-
import type { ToolbarItemProps, ToolbarProps } from 'reactjs-tiptap-editor-pro/types';
|
|
4
|
-
|
|
5
|
-
import { Separator } from 'reactjs-tiptap-editor-pro/components';
|
|
6
|
-
import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
|
|
7
|
-
import { isFunction } from 'reactjs-tiptap-editor-pro/utils/utils';
|
|
8
|
-
|
|
9
|
-
export interface ToolbarComponentProps {
|
|
10
|
-
editor: Editor
|
|
11
|
-
disabled?: boolean
|
|
12
|
-
toolbar?: ToolbarProps
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function Toolbar({ editor, disabled, toolbar }: ToolbarComponentProps) {
|
|
16
|
-
const { t, lang } = useLocale();
|
|
17
|
-
|
|
18
|
-
const toolbarItems = useMemo(() => {
|
|
19
|
-
const extensions = [...editor.extensionManager.extensions];
|
|
20
|
-
const sortExtensions = extensions.sort((arr, acc) => {
|
|
21
|
-
const a = (arr.options).sort ?? -1;
|
|
22
|
-
const b = (acc.options).sort ?? -1;
|
|
23
|
-
return a - b;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
let menus: ToolbarItemProps[] = [];
|
|
27
|
-
|
|
28
|
-
for (const extension of sortExtensions) {
|
|
29
|
-
const {
|
|
30
|
-
button,
|
|
31
|
-
divider = false,
|
|
32
|
-
spacer = false,
|
|
33
|
-
toolbar = true,
|
|
34
|
-
} = extension.options;
|
|
35
|
-
if (!button || !isFunction(button) || !toolbar) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const _button: ToolbarItemProps['button'] | ToolbarItemProps['button'][] = button({
|
|
40
|
-
editor,
|
|
41
|
-
extension,
|
|
42
|
-
t,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(_button)) {
|
|
46
|
-
const menu: ToolbarItemProps[] = _button.map((k, i) => ({
|
|
47
|
-
button: k,
|
|
48
|
-
divider: i === _button.length - 1 ? divider : false,
|
|
49
|
-
spacer: i === 0 ? spacer : false,
|
|
50
|
-
type: extension.type,
|
|
51
|
-
name: extension.name,
|
|
52
|
-
}));
|
|
53
|
-
menus = [...menus, ...menu];
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
menus.push({
|
|
58
|
-
button: _button,
|
|
59
|
-
divider,
|
|
60
|
-
spacer,
|
|
61
|
-
type: extension.type,
|
|
62
|
-
name: extension.name,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return menus;
|
|
66
|
-
}, [editor, t, lang]);
|
|
67
|
-
|
|
68
|
-
const containerDom = (innerContent: React.ReactNode) => {
|
|
69
|
-
return (
|
|
70
|
-
<div
|
|
71
|
-
className="toolbar px-1 py-2 !border-b"
|
|
72
|
-
style={{
|
|
73
|
-
pointerEvents: disabled ? 'none' : 'auto',
|
|
74
|
-
opacity: disabled ? 0.5 : 1,
|
|
75
|
-
}}
|
|
76
|
-
>
|
|
77
|
-
<div className="relative flex flex-wrap h-auto gap-y-1 gap-x-1">
|
|
78
|
-
{innerContent}
|
|
79
|
-
</div>
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const dom = toolbarItems.map((item: ToolbarItemProps, key) => {
|
|
85
|
-
const ButtonComponent = item.button.component;
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<div className="flex items-center" key={`toolbar-item-${key}`}>
|
|
89
|
-
{item?.spacer && <Separator orientation="vertical" className="!h-[16px] !mx-[10px]" />}
|
|
90
|
-
|
|
91
|
-
<ButtonComponent
|
|
92
|
-
{...item.button.componentProps}
|
|
93
|
-
disabled={disabled || item?.button?.componentProps?.disabled}
|
|
94
|
-
/>
|
|
95
|
-
|
|
96
|
-
{item?.divider && <Separator orientation="vertical" className="!h-auto !mx-2" />}
|
|
97
|
-
</div>
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
if (toolbar && toolbar?.render) {
|
|
102
|
-
return toolbar.render({ editor, disabled: disabled || false }, toolbarItems, dom, containerDom);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return containerDom(dom);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export { Toolbar };
|