reactjs-tiptap-editor-pro 0.2.31 → 0.2.32
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/RichTextEditor-BwbqJLnA.cjs +141 -0
- package/lib/RichTextEditor-iGJ6-rbq.js +8833 -0
- package/lib/extension-bundle.cjs +33 -0
- package/lib/extension-bundle.d.cts +947 -0
- package/lib/extension-bundle.d.ts +947 -0
- package/lib/extension-bundle.js +5755 -0
- package/lib/index-DV-nXpU1.cjs +1 -0
- package/lib/index-M6H3FoBi.js +1147 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +513 -0
- package/lib/index.d.ts +513 -0
- package/lib/index.js +16 -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/style.css +1 -0
- package/lib/tiptap-DkWHMWDt.js +6061 -0
- package/lib/tiptap-gBG-1T-V.cjs +116 -0
- package/lib/vendor-BJ0Yf78E.cjs +8114 -0
- package/lib/vendor-Cpa6z-M0.js +67575 -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,66 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { BundledLanguage } from 'shiki';
|
|
4
|
-
import {
|
|
5
|
-
ActionButton,
|
|
6
|
-
DropdownMenu,
|
|
7
|
-
DropdownMenuContent,
|
|
8
|
-
DropdownMenuItem,
|
|
9
|
-
DropdownMenuTrigger,
|
|
10
|
-
} from 'reactjs-tiptap-editor-pro/components';
|
|
11
|
-
import { MAP_LANGUAGE_CODE_LABELS } from 'reactjs-tiptap-editor-pro/constants';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
editor: any
|
|
15
|
-
disabled?: boolean
|
|
16
|
-
color?: string
|
|
17
|
-
shortcutKeys?: string[]
|
|
18
|
-
maxHeight?: string | number
|
|
19
|
-
tooltip?: string
|
|
20
|
-
languages?: BundledLanguage[]
|
|
21
|
-
action: (language: string) => void
|
|
22
|
-
icon?: any
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function CodeBlockActiveButton({ action, languages, ...props }: Props) {
|
|
26
|
-
const onClick = (language: string) => {
|
|
27
|
-
action(language);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const langs = useMemo(() => {
|
|
31
|
-
return languages?.map((language) => {
|
|
32
|
-
const title = MAP_LANGUAGE_CODE_LABELS[language] || language;
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
title,
|
|
36
|
-
// icon: language.icon,
|
|
37
|
-
language,
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}, [languages]);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<DropdownMenu>
|
|
44
|
-
<DropdownMenuTrigger disabled={props?.disabled} asChild>
|
|
45
|
-
<ActionButton
|
|
46
|
-
tooltip={props?.tooltip}
|
|
47
|
-
disabled={props?.disabled}
|
|
48
|
-
icon={props?.icon}
|
|
49
|
-
/>
|
|
50
|
-
</DropdownMenuTrigger>
|
|
51
|
-
<DropdownMenuContent className="w-full !max-h-[180px] !overflow-y-scroll">
|
|
52
|
-
{langs?.map((item: any) => {
|
|
53
|
-
return (
|
|
54
|
-
<DropdownMenuItem key={`codeblock-${item.title}`} onClick={() => onClick(item.language)}>
|
|
55
|
-
<div className="h-full ml-1">
|
|
56
|
-
{item.title}
|
|
57
|
-
</div>
|
|
58
|
-
</DropdownMenuItem>
|
|
59
|
-
);
|
|
60
|
-
})}
|
|
61
|
-
</DropdownMenuContent>
|
|
62
|
-
</DropdownMenu>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default CodeBlockActiveButton;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useMemo, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react';
|
|
4
|
-
import clsx from 'clsx';
|
|
5
|
-
import { Copy, CopyCheck } from 'lucide-react';
|
|
6
|
-
|
|
7
|
-
import { IconComponent } from 'reactjs-tiptap-editor-pro/components';
|
|
8
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from 'reactjs-tiptap-editor-pro/components/ui/select';
|
|
9
|
-
import { DEFAULT_LANGUAGE_CODE_BLOCK } from 'reactjs-tiptap-editor-pro/constants';
|
|
10
|
-
import { CodeBlock } from 'reactjs-tiptap-editor-pro/extensions';
|
|
11
|
-
import useCopy from 'reactjs-tiptap-editor-pro/hooks/useCopy';
|
|
12
|
-
import { useEditableEditor } from 'reactjs-tiptap-editor-pro/store/editableEditor';
|
|
13
|
-
import { deleteNode } from 'reactjs-tiptap-editor-pro/utils/delete-node';
|
|
14
|
-
|
|
15
|
-
import styles from './index.module.scss';
|
|
16
|
-
|
|
17
|
-
export function NodeViewCodeBlock({ editor, node: { attrs }, updateAttributes, extension }: any) {
|
|
18
|
-
const { isCopied, copyToClipboard } = useCopy();
|
|
19
|
-
|
|
20
|
-
const listLang = useMemo(() => {
|
|
21
|
-
return extension.options.languages?.length ? extension.options.languages : DEFAULT_LANGUAGE_CODE_BLOCK;
|
|
22
|
-
}, [extension.options.languages]);
|
|
23
|
-
|
|
24
|
-
const isEditable = useEditableEditor();
|
|
25
|
-
|
|
26
|
-
const isPrint = editor?.options?.editorProps?.print;
|
|
27
|
-
const { language: defaultLanguage } = attrs;
|
|
28
|
-
const $container: any = useRef<HTMLPreElement>(null);
|
|
29
|
-
|
|
30
|
-
const deleteMe = useCallback(() => deleteNode(CodeBlock.name, editor), [editor]);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<NodeViewWrapper className={clsx(styles.wrap, !isPrint && styles.maxHeight, 'render-wrapper')}>
|
|
34
|
-
|
|
35
|
-
<div className={clsx(styles.blockInfo, {
|
|
36
|
-
[styles.blockInfoEditable]: !isEditable,
|
|
37
|
-
})}
|
|
38
|
-
|
|
39
|
-
>
|
|
40
|
-
<span
|
|
41
|
-
className={clsx(styles.btnCopy, isCopied && styles.copied)}
|
|
42
|
-
onClick={() => copyToClipboard($container.current.innerText)}
|
|
43
|
-
>
|
|
44
|
-
{!isCopied ? <Copy size={16} /> : <CopyCheck size={16} />}
|
|
45
|
-
</span>
|
|
46
|
-
|
|
47
|
-
<span
|
|
48
|
-
className={styles.btnDelete}
|
|
49
|
-
onClick={deleteMe}
|
|
50
|
-
>
|
|
51
|
-
<IconComponent
|
|
52
|
-
name="Trash2"
|
|
53
|
-
/>
|
|
54
|
-
</span>
|
|
55
|
-
|
|
56
|
-
<div className={styles.selectLang}>
|
|
57
|
-
<Select
|
|
58
|
-
defaultValue={defaultLanguage || 'auto'}
|
|
59
|
-
disabled={!isEditable}
|
|
60
|
-
onValueChange={value => updateAttributes({ language: value })}
|
|
61
|
-
>
|
|
62
|
-
<SelectTrigger>
|
|
63
|
-
<SelectValue placeholder="Language" />
|
|
64
|
-
</SelectTrigger>
|
|
65
|
-
|
|
66
|
-
<SelectContent className="max-h-60 overflow-y-auto">
|
|
67
|
-
<SelectItem value="auto">
|
|
68
|
-
Auto
|
|
69
|
-
</SelectItem>
|
|
70
|
-
|
|
71
|
-
{listLang.map((lang: any, index: any) => (
|
|
72
|
-
<SelectItem key={`code-lang-${index}`}
|
|
73
|
-
value={lang}
|
|
74
|
-
>
|
|
75
|
-
{lang.charAt(0).toUpperCase() + lang.slice(1)}
|
|
76
|
-
</SelectItem>
|
|
77
|
-
))}
|
|
78
|
-
</SelectContent>
|
|
79
|
-
</Select>
|
|
80
|
-
</div>
|
|
81
|
-
|
|
82
|
-
</div>
|
|
83
|
-
|
|
84
|
-
<pre ref={$container}>
|
|
85
|
-
<NodeViewContent as="code" />
|
|
86
|
-
</pre>
|
|
87
|
-
</NodeViewWrapper>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
.wrap {
|
|
2
|
-
position: relative;
|
|
3
|
-
|
|
4
|
-
code {
|
|
5
|
-
margin: 0 !important;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
pre {
|
|
9
|
-
margin: 10px 0 !important;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
&.maxHeight {
|
|
13
|
-
code {
|
|
14
|
-
max-height: 370px;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
&:hover {
|
|
19
|
-
.btnCopy,
|
|
20
|
-
.btnDelete {
|
|
21
|
-
opacity: 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.blockInfo {
|
|
27
|
-
display: flex;
|
|
28
|
-
align-items: center;
|
|
29
|
-
position: absolute;
|
|
30
|
-
z-index: 2;
|
|
31
|
-
top: 5px;
|
|
32
|
-
right: 5px;
|
|
33
|
-
gap: 8px;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.blockInfoEditable {
|
|
37
|
-
display: none;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.selectLang {
|
|
41
|
-
cursor: pointer;
|
|
42
|
-
transition: all .3s;
|
|
43
|
-
border-radius: 4px;
|
|
44
|
-
border-width: 0px !important;
|
|
45
|
-
|
|
46
|
-
> button {
|
|
47
|
-
padding: 0px !important;
|
|
48
|
-
height: initial !important;
|
|
49
|
-
outline: none !important;
|
|
50
|
-
border: none !important;
|
|
51
|
-
outline-offset: 0px !important;
|
|
52
|
-
color: white !important;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.SelectContent {
|
|
56
|
-
max-height: 200px;
|
|
57
|
-
overflow-y: auto;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.btnCopy {
|
|
62
|
-
color: #ebebebbf;
|
|
63
|
-
cursor: pointer;
|
|
64
|
-
transition: all 0.3s;
|
|
65
|
-
opacity: 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.copied {
|
|
69
|
-
color: rgb(125, 207, 2);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.btnDelete {
|
|
73
|
-
color: #ebebebbf;
|
|
74
|
-
cursor: pointer;
|
|
75
|
-
transition: all 0.3s;
|
|
76
|
-
opacity: 0;
|
|
77
|
-
|
|
78
|
-
&:hover {
|
|
79
|
-
color: #ff4d4f;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BundledLanguage,
|
|
3
|
-
BundledTheme,
|
|
4
|
-
Highlighter,
|
|
5
|
-
} from 'shiki';
|
|
6
|
-
import {
|
|
7
|
-
bundledLanguages,
|
|
8
|
-
bundledThemes,
|
|
9
|
-
createHighlighter,
|
|
10
|
-
} from 'shiki';
|
|
11
|
-
import { findChildren } from '@tiptap/core';
|
|
12
|
-
import type { Node as ProsemirrorNode } from '@tiptap/pm/model';
|
|
13
|
-
|
|
14
|
-
let highlighter: Highlighter | undefined;
|
|
15
|
-
let highlighterPromise: Promise<void> | undefined;
|
|
16
|
-
const loadingLanguages = new Set<BundledLanguage>();
|
|
17
|
-
const loadingThemes = new Set<BundledTheme>();
|
|
18
|
-
|
|
19
|
-
interface HighlighterOptions {
|
|
20
|
-
themes: (BundledTheme | null | undefined)[]
|
|
21
|
-
languages: (BundledLanguage | null | undefined)[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function resetHighlighter() {
|
|
25
|
-
highlighter = undefined;
|
|
26
|
-
highlighterPromise = undefined;
|
|
27
|
-
loadingLanguages.clear();
|
|
28
|
-
loadingThemes.clear();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getShiki() {
|
|
32
|
-
return highlighter;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Load the highlighter. Makes sure the highlighter is only loaded once.
|
|
37
|
-
*/
|
|
38
|
-
export function loadHighlighter(opts: HighlighterOptions) {
|
|
39
|
-
if (!highlighter && !highlighterPromise) {
|
|
40
|
-
const themes = opts.themes.filter(
|
|
41
|
-
(theme): theme is BundledTheme => !!theme && theme in bundledThemes,
|
|
42
|
-
);
|
|
43
|
-
const langs = opts.languages.filter(
|
|
44
|
-
(lang): lang is BundledLanguage => !!lang && lang in bundledLanguages,
|
|
45
|
-
);
|
|
46
|
-
highlighterPromise = createHighlighter({ themes, langs }).then((h) => {
|
|
47
|
-
highlighter = h;
|
|
48
|
-
});
|
|
49
|
-
return highlighterPromise;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (highlighterPromise) {
|
|
53
|
-
return highlighterPromise;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Loads a theme if it's valid and not yet loaded.
|
|
59
|
-
* @returns true or false depending on if it got loaded.
|
|
60
|
-
*/
|
|
61
|
-
export async function loadTheme(theme: BundledTheme) {
|
|
62
|
-
if (
|
|
63
|
-
highlighter
|
|
64
|
-
&& !highlighter.getLoadedThemes().includes(theme)
|
|
65
|
-
&& !loadingThemes.has(theme)
|
|
66
|
-
&& theme in bundledThemes
|
|
67
|
-
) {
|
|
68
|
-
loadingThemes.add(theme);
|
|
69
|
-
await highlighter.loadTheme(theme);
|
|
70
|
-
loadingThemes.delete(theme);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Loads a language if it's valid and not yet loaded
|
|
79
|
-
* @returns true or false depending on if it got loaded.
|
|
80
|
-
*/
|
|
81
|
-
export async function loadLanguage(language: BundledLanguage) {
|
|
82
|
-
if (
|
|
83
|
-
highlighter
|
|
84
|
-
&& !highlighter.getLoadedLanguages().includes(language)
|
|
85
|
-
&& !loadingLanguages.has(language)
|
|
86
|
-
&& language in bundledLanguages
|
|
87
|
-
) {
|
|
88
|
-
loadingLanguages.add(language);
|
|
89
|
-
await highlighter.loadLanguage(language);
|
|
90
|
-
loadingLanguages.delete(language);
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Initializes the highlighter based on the prosemirror document,
|
|
99
|
-
* with the themes and languages in the document.
|
|
100
|
-
*/
|
|
101
|
-
export async function initHighlighter({
|
|
102
|
-
doc,
|
|
103
|
-
name,
|
|
104
|
-
defaultTheme,
|
|
105
|
-
defaultLanguage,
|
|
106
|
-
}: {
|
|
107
|
-
doc: ProsemirrorNode
|
|
108
|
-
name: string
|
|
109
|
-
defaultLanguage: BundledLanguage | null | undefined
|
|
110
|
-
defaultTheme: BundledTheme
|
|
111
|
-
}) {
|
|
112
|
-
const codeBlocks = findChildren(doc, node => node.type.name === name);
|
|
113
|
-
|
|
114
|
-
const themes = [
|
|
115
|
-
...codeBlocks.map(block => block.node.attrs.theme as BundledTheme),
|
|
116
|
-
defaultTheme,
|
|
117
|
-
];
|
|
118
|
-
const languages = [
|
|
119
|
-
...codeBlocks.map(block => block.node.attrs.language as BundledLanguage),
|
|
120
|
-
defaultLanguage,
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
if (!highlighter) {
|
|
124
|
-
const loader = loadHighlighter({ languages, themes });
|
|
125
|
-
await loader;
|
|
126
|
-
} else {
|
|
127
|
-
await Promise.all([
|
|
128
|
-
...themes.flatMap(theme => loadTheme(theme)),
|
|
129
|
-
...languages.flatMap(language => !!language && loadLanguage(language)),
|
|
130
|
-
]);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './CodeBlock';
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { findChildren } from '@tiptap/core';
|
|
3
|
-
import type { Node as ProsemirrorNode } from '@tiptap/pm/model';
|
|
4
|
-
import type { PluginView } from '@tiptap/pm/state';
|
|
5
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
6
|
-
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
7
|
-
import type { BundledLanguage, BundledTheme } from 'shiki';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
getShiki,
|
|
11
|
-
initHighlighter,
|
|
12
|
-
loadLanguage,
|
|
13
|
-
loadTheme,
|
|
14
|
-
} from './highlighter';
|
|
15
|
-
|
|
16
|
-
/** Create code decorations for the current document */
|
|
17
|
-
function getDecorations({
|
|
18
|
-
doc,
|
|
19
|
-
name,
|
|
20
|
-
defaultTheme,
|
|
21
|
-
defaultLanguage,
|
|
22
|
-
}: {
|
|
23
|
-
doc: ProsemirrorNode
|
|
24
|
-
name: string
|
|
25
|
-
defaultLanguage: BundledLanguage | null | undefined
|
|
26
|
-
defaultTheme: BundledTheme
|
|
27
|
-
}) {
|
|
28
|
-
const decorations: Decoration[] = [];
|
|
29
|
-
|
|
30
|
-
const codeBlocks = findChildren(doc, node => node.type.name === name);
|
|
31
|
-
|
|
32
|
-
codeBlocks.forEach((block) => {
|
|
33
|
-
let from = block.pos + 1;
|
|
34
|
-
let language = block.node.attrs.language || defaultLanguage;
|
|
35
|
-
const theme = block.node.attrs.theme || defaultTheme;
|
|
36
|
-
|
|
37
|
-
const highlighter = getShiki();
|
|
38
|
-
|
|
39
|
-
if (!highlighter)
|
|
40
|
-
return;
|
|
41
|
-
|
|
42
|
-
if (!highlighter.getLoadedLanguages().includes(language)) {
|
|
43
|
-
language = 'plaintext';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const themeToApply = highlighter.getLoadedThemes().includes(theme)
|
|
47
|
-
? theme
|
|
48
|
-
: highlighter.getLoadedThemes()[0];
|
|
49
|
-
|
|
50
|
-
const tokens = highlighter.codeToTokensBase(block.node.textContent, {
|
|
51
|
-
lang: language,
|
|
52
|
-
theme: themeToApply,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
for (const line of tokens) {
|
|
56
|
-
for (const token of line) {
|
|
57
|
-
const to = from + token.content.length;
|
|
58
|
-
|
|
59
|
-
const decoration = Decoration.inline(from, to, {
|
|
60
|
-
style: `color: ${token.color}`,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
decorations.push(decoration);
|
|
64
|
-
|
|
65
|
-
from = to;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
from += 1;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return DecorationSet.create(doc, decorations);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function ShikiPlugin({
|
|
76
|
-
name,
|
|
77
|
-
defaultLanguage,
|
|
78
|
-
defaultTheme,
|
|
79
|
-
}: {
|
|
80
|
-
name: string
|
|
81
|
-
defaultLanguage: BundledLanguage | null | undefined
|
|
82
|
-
defaultTheme: BundledTheme
|
|
83
|
-
}) {
|
|
84
|
-
//@ts-expect-error
|
|
85
|
-
const shikiPlugin = new Plugin<any>({
|
|
86
|
-
key: new PluginKey('shiki'),
|
|
87
|
-
|
|
88
|
-
view(view) {
|
|
89
|
-
// This small view is just for initial async handling
|
|
90
|
-
class ShikiPluginView implements PluginView {
|
|
91
|
-
constructor() {
|
|
92
|
-
this.initDecorations();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
update() {
|
|
96
|
-
this.checkUndecoratedBlocks();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
destroy() {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Initialize shiki async, and then highlight initial document
|
|
104
|
-
async initDecorations() {
|
|
105
|
-
const doc = view.state.doc;
|
|
106
|
-
await initHighlighter({ doc, name, defaultLanguage, defaultTheme });
|
|
107
|
-
const tr = view.state.tr.setMeta('shikiPluginForceDecoration', true);
|
|
108
|
-
view.dispatch(tr);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// When new codeblocks were added and they have missing themes or
|
|
112
|
-
// languages, load those and then add code decorations once again.
|
|
113
|
-
async checkUndecoratedBlocks() {
|
|
114
|
-
const codeBlocks = findChildren(
|
|
115
|
-
view.state.doc,
|
|
116
|
-
node => node.type.name === name,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Load missing themes or languages when necessary.
|
|
120
|
-
// loadStates is an array with booleans depending on if a theme/lang
|
|
121
|
-
// got loaded.
|
|
122
|
-
const loadStates = await Promise.all(
|
|
123
|
-
codeBlocks.flatMap(block => [
|
|
124
|
-
loadTheme(block.node.attrs.theme),
|
|
125
|
-
loadLanguage(block.node.attrs.language),
|
|
126
|
-
]),
|
|
127
|
-
);
|
|
128
|
-
const didLoadSomething = loadStates.includes(true);
|
|
129
|
-
|
|
130
|
-
// The asynchronous nature of this is potentially prone to
|
|
131
|
-
// race conditions. Imma just hope it's fine lol
|
|
132
|
-
|
|
133
|
-
if (didLoadSomething) {
|
|
134
|
-
const tr = view.state.tr.setMeta('shikiPluginForceDecoration', true);
|
|
135
|
-
view.dispatch(tr);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return new ShikiPluginView();
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
state: {
|
|
144
|
-
init: (_, { doc }) => {
|
|
145
|
-
return getDecorations({
|
|
146
|
-
doc,
|
|
147
|
-
name,
|
|
148
|
-
defaultLanguage,
|
|
149
|
-
defaultTheme,
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
apply: (transaction, decorationSet, oldState, newState) => {
|
|
153
|
-
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
154
|
-
const newNodeName = newState.selection.$head.parent.type.name;
|
|
155
|
-
const oldNodes = findChildren(
|
|
156
|
-
oldState.doc,
|
|
157
|
-
node => node.type.name === name,
|
|
158
|
-
);
|
|
159
|
-
const newNodes = findChildren(
|
|
160
|
-
newState.doc,
|
|
161
|
-
node => node.type.name === name,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const didChangeSomeCodeBlock
|
|
165
|
-
= transaction.docChanged
|
|
166
|
-
// Apply decorations if:
|
|
167
|
-
// selection includes named node,
|
|
168
|
-
&& ([oldNodeName, newNodeName].includes(name)
|
|
169
|
-
// OR transaction adds/removes named node,
|
|
170
|
-
|| newNodes.length !== oldNodes.length
|
|
171
|
-
// OR transaction has changes that completely encapsulte a node
|
|
172
|
-
// (for example, a transaction that affects the entire document).
|
|
173
|
-
// Such transactions can happen during collab syncing via y-prosemirror, for example.
|
|
174
|
-
|| transaction.steps.some((step: any) => {
|
|
175
|
-
return (
|
|
176
|
-
step.from !== undefined
|
|
177
|
-
&& step.to !== undefined
|
|
178
|
-
&& oldNodes.some((node) => {
|
|
179
|
-
return (
|
|
180
|
-
node.pos >= step.from
|
|
181
|
-
&& node.pos + node.node.nodeSize <= step.to
|
|
182
|
-
);
|
|
183
|
-
})
|
|
184
|
-
);
|
|
185
|
-
}));
|
|
186
|
-
|
|
187
|
-
// only create code decoration when it's necessary to do so
|
|
188
|
-
if (
|
|
189
|
-
transaction.getMeta('shikiPluginForceDecoration')
|
|
190
|
-
|| didChangeSomeCodeBlock
|
|
191
|
-
) {
|
|
192
|
-
return getDecorations({
|
|
193
|
-
doc: transaction.doc,
|
|
194
|
-
name,
|
|
195
|
-
defaultLanguage,
|
|
196
|
-
defaultTheme,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
props: {
|
|
205
|
-
//@ts-expect-error
|
|
206
|
-
decorations(state) {
|
|
207
|
-
return shikiPlugin.getState(state);
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return shikiPlugin;
|
|
213
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import TiptapColor from '@tiptap/extension-color';
|
|
2
|
-
import type { ColorOptions as TiptapColorOptions } from '@tiptap/extension-color';
|
|
3
|
-
|
|
4
|
-
import ColorActionButton from 'reactjs-tiptap-editor-pro/extensions/Color/components/ColorActionButton';
|
|
5
|
-
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
-
|
|
7
|
-
export interface ColorOptions extends TiptapColorOptions, GeneralOptions<ColorOptions> {
|
|
8
|
-
/**
|
|
9
|
-
* An array of color options to display in the color picker
|
|
10
|
-
*/
|
|
11
|
-
colors?: string[]
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The default color to use when no color is selected
|
|
15
|
-
*/
|
|
16
|
-
defaultColor?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const Color = TiptapColor.extend<ColorOptions>({
|
|
20
|
-
addOptions() {
|
|
21
|
-
return {
|
|
22
|
-
...this.parent?.(),
|
|
23
|
-
button({ editor, t, extension }) {
|
|
24
|
-
return {
|
|
25
|
-
component: ColorActionButton,
|
|
26
|
-
componentProps: {
|
|
27
|
-
colors: extension.options.colors,
|
|
28
|
-
defaultColor: extension.options.defaultColor,
|
|
29
|
-
action: (color?: unknown) => {
|
|
30
|
-
if (color === undefined) {
|
|
31
|
-
editor.chain().focus().unsetColor().run();
|
|
32
|
-
}
|
|
33
|
-
if (typeof color === 'string') {
|
|
34
|
-
editor.chain().focus().setColor(color).run();
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
isActive: () => {
|
|
38
|
-
const { color } = editor.getAttributes('textStyle');
|
|
39
|
-
if (!color) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
return editor.isActive({ color }) || false;
|
|
43
|
-
},
|
|
44
|
-
editor,
|
|
45
|
-
disabled: !editor.can().setColor(''),
|
|
46
|
-
tooltip: t('editor.color.tooltip'),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|