reactjs-tiptap-editor-pro 0.2.30 → 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 +60 -4
- 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,155 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-constant-binary-expression */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
5
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { NodeViewWrapper } from '@tiptap/react';
|
|
8
|
-
import clsx from 'clsx';
|
|
9
|
-
|
|
10
|
-
import { ActionButton } from '@/components';
|
|
11
|
-
import { useLocale } from '@/locales';
|
|
12
|
-
import { useEditableEditor } from '@/store/editableEditor';
|
|
13
|
-
import { extractFileExtension, extractFilename, normalizeFileSize } from '@/utils/file';
|
|
14
|
-
|
|
15
|
-
import { getFileTypeIcon } from './FileIcon';
|
|
16
|
-
import styles from './index.module.scss';
|
|
17
|
-
|
|
18
|
-
export function NodeViewAttachment({ editor, node, updateAttributes, deleteNode, extension }: any) {
|
|
19
|
-
const $upload: any = useRef<HTMLInputElement>(null);
|
|
20
|
-
|
|
21
|
-
const isEditable = useEditableEditor();
|
|
22
|
-
|
|
23
|
-
const { hasTrigger, fileName, fileSize, fileExt, fileType, url, error } = node.attrs;
|
|
24
|
-
const [loading, setLoading] = useState(false);
|
|
25
|
-
const { t } = useLocale();
|
|
26
|
-
|
|
27
|
-
const upload = extension?.options?.upload;
|
|
28
|
-
|
|
29
|
-
const selectFile = useCallback(() => {
|
|
30
|
-
if (!isEditable || url)
|
|
31
|
-
return;
|
|
32
|
-
isEditable && $upload.current.click();
|
|
33
|
-
}, [isEditable, url]);
|
|
34
|
-
|
|
35
|
-
const handleFile = useCallback(
|
|
36
|
-
async (e: any) => {
|
|
37
|
-
const file = e.target.files && e.target.files[0];
|
|
38
|
-
if (!file)
|
|
39
|
-
return;
|
|
40
|
-
|
|
41
|
-
const fileInfo = {
|
|
42
|
-
fileName: extractFilename(file.name),
|
|
43
|
-
fileSize: file.size,
|
|
44
|
-
fileType: file.type,
|
|
45
|
-
fileExt: extractFileExtension(file.name),
|
|
46
|
-
};
|
|
47
|
-
setLoading(true);
|
|
48
|
-
|
|
49
|
-
// if (file.size > FILE_CHUNK_SIZE) {
|
|
50
|
-
// toggleShowProgress(true)
|
|
51
|
-
// }
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const url = await upload(file);
|
|
55
|
-
updateAttributes({ ...fileInfo, url });
|
|
56
|
-
setLoading(false);
|
|
57
|
-
} catch (error: any) {
|
|
58
|
-
updateAttributes({ error: `File upload fail: ${error && error.message}` || 'Unknown error' });
|
|
59
|
-
setLoading(false);
|
|
60
|
-
|
|
61
|
-
$upload.current.value = '';
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
[setLoading, updateAttributes],
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!url && !hasTrigger) {
|
|
69
|
-
selectFile();
|
|
70
|
-
updateAttributes({ hasTrigger: true });
|
|
71
|
-
}
|
|
72
|
-
}, [url, hasTrigger, selectFile, updateAttributes]);
|
|
73
|
-
|
|
74
|
-
const onDeleteAttachment = useCallback(() => deleteNode(), [editor]);
|
|
75
|
-
|
|
76
|
-
if (isEditable && !url) {
|
|
77
|
-
return (
|
|
78
|
-
<NodeViewWrapper>
|
|
79
|
-
<div className={clsx(styles.wrap, 'render-wrapper')}>
|
|
80
|
-
<p onClick={selectFile}
|
|
81
|
-
style={{ cursor: 'pointer' }}
|
|
82
|
-
>
|
|
83
|
-
{loading
|
|
84
|
-
? (
|
|
85
|
-
<span>
|
|
86
|
-
{t('editor.attachment.uploading')}
|
|
87
|
-
</span>
|
|
88
|
-
)
|
|
89
|
-
: (
|
|
90
|
-
<span>
|
|
91
|
-
{t('editor.attachment.please_upload')}
|
|
92
|
-
</span>
|
|
93
|
-
)}
|
|
94
|
-
</p>
|
|
95
|
-
|
|
96
|
-
<input hidden
|
|
97
|
-
onChange={handleFile}
|
|
98
|
-
ref={$upload}
|
|
99
|
-
type="file"
|
|
100
|
-
/>
|
|
101
|
-
</div>
|
|
102
|
-
</NodeViewWrapper>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (url) {
|
|
107
|
-
return (
|
|
108
|
-
<NodeViewWrapper>
|
|
109
|
-
<div className={clsx(styles.wrap, 'render-wrapper')}
|
|
110
|
-
onClick={selectFile}
|
|
111
|
-
>
|
|
112
|
-
<div className="flex items-center gap-[4px]">
|
|
113
|
-
<span>
|
|
114
|
-
{getFileTypeIcon(fileType)}
|
|
115
|
-
</span>
|
|
116
|
-
|
|
117
|
-
<span>
|
|
118
|
-
{fileName}
|
|
119
|
-
.
|
|
120
|
-
{fileExt}
|
|
121
|
-
</span>
|
|
122
|
-
|
|
123
|
-
<span>
|
|
124
|
-
(
|
|
125
|
-
{normalizeFileSize(fileSize)}
|
|
126
|
-
)
|
|
127
|
-
</span>
|
|
128
|
-
</div>
|
|
129
|
-
|
|
130
|
-
<ActionButton
|
|
131
|
-
action={onDeleteAttachment}
|
|
132
|
-
icon="Trash2"
|
|
133
|
-
tooltip={t('editor.delete')}
|
|
134
|
-
/>
|
|
135
|
-
</div>
|
|
136
|
-
</NodeViewWrapper>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (error !== 'null') {
|
|
141
|
-
return (
|
|
142
|
-
<NodeViewWrapper>
|
|
143
|
-
<div className={clsx(styles.wrap, 'render-wrapper')}
|
|
144
|
-
onClick={selectFile}
|
|
145
|
-
>
|
|
146
|
-
<p>
|
|
147
|
-
{error}
|
|
148
|
-
</p>
|
|
149
|
-
</div>
|
|
150
|
-
</NodeViewWrapper>
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return <></>;
|
|
155
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.attachment, /* for browser ready HTML */
|
|
2
|
-
.wrap { /* for NodeView */
|
|
3
|
-
border-width: 1px !important;
|
|
4
|
-
border-radius: 4px;
|
|
5
|
-
padding: 10px;
|
|
6
|
-
display: flex;
|
|
7
|
-
align-items: center;
|
|
8
|
-
justify-content: space-between;
|
|
9
|
-
margin: 10px 0;
|
|
10
|
-
|
|
11
|
-
:global {
|
|
12
|
-
.attachment__icon {
|
|
13
|
-
width: 32px;
|
|
14
|
-
text-align: center;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.attachment__icon svg {
|
|
18
|
-
width: 32px;
|
|
19
|
-
display: inline-block;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Attachment';
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import type { AnyExtension } from '@tiptap/core';
|
|
3
|
-
import { Extension } from '@tiptap/core';
|
|
4
|
-
import type { CharacterCountOptions } from '@tiptap/extension-character-count';
|
|
5
|
-
import CharacterCount from '@tiptap/extension-character-count';
|
|
6
|
-
import type { DropcursorOptions } from '@tiptap/extension-dropcursor';
|
|
7
|
-
import { Dropcursor } from '@tiptap/extension-dropcursor';
|
|
8
|
-
import type { FocusOptions } from '@tiptap/extension-focus';
|
|
9
|
-
import Focus from '@tiptap/extension-focus';
|
|
10
|
-
import { Gapcursor } from '@tiptap/extension-gapcursor';
|
|
11
|
-
import type { HardBreakOptions } from '@tiptap/extension-hard-break';
|
|
12
|
-
import { HardBreak } from '@tiptap/extension-hard-break';
|
|
13
|
-
import type { ListItemOptions } from '@tiptap/extension-list-item';
|
|
14
|
-
import { ListItem } from '@tiptap/extension-list-item';
|
|
15
|
-
import type { ParagraphOptions } from '@tiptap/extension-paragraph';
|
|
16
|
-
import { Paragraph } from '@tiptap/extension-paragraph';
|
|
17
|
-
import type { PlaceholderOptions } from '@tiptap/extension-placeholder';
|
|
18
|
-
import { Placeholder } from '@tiptap/extension-placeholder';
|
|
19
|
-
import { Text } from '@tiptap/extension-text';
|
|
20
|
-
import type { TextStyleOptions } from '@tiptap/extension-text-style';
|
|
21
|
-
import { TextStyle } from '@tiptap/extension-text-style';
|
|
22
|
-
|
|
23
|
-
import { Document } from '@/extensions/Document';
|
|
24
|
-
import { Column, MultiColumn } from '@/extensions/MultiColumn';
|
|
25
|
-
import { Selection } from '@/extensions/Selection';
|
|
26
|
-
import type { TextBubbleOptions } from '@/extensions/TextBubble';
|
|
27
|
-
import { TextBubble } from '@/extensions/TextBubble';
|
|
28
|
-
import type { TrailingNodeOptions } from '@/extensions/TrailingNode';
|
|
29
|
-
import { TrailingNode } from '@/extensions/TrailingNode';
|
|
30
|
-
import { localeActions } from '@/locales';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Represents the interface for options in the base toolkit.
|
|
34
|
-
*/
|
|
35
|
-
export interface BaseKitOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Whether to enable the document option
|
|
38
|
-
*
|
|
39
|
-
* @default true
|
|
40
|
-
*/
|
|
41
|
-
document: false
|
|
42
|
-
/**
|
|
43
|
-
* Whether to enable the document option
|
|
44
|
-
*
|
|
45
|
-
* @default false
|
|
46
|
-
*/
|
|
47
|
-
multiColumn?: boolean
|
|
48
|
-
/**
|
|
49
|
-
* Whether to enable the text option
|
|
50
|
-
*
|
|
51
|
-
* @default true
|
|
52
|
-
*/
|
|
53
|
-
text: false
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Whether to enable the Gapcursor
|
|
57
|
-
*
|
|
58
|
-
* @default true
|
|
59
|
-
*/
|
|
60
|
-
gapcursor: false
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Dropcursor options or false, indicating whether to enable the drop cursor
|
|
64
|
-
*
|
|
65
|
-
* @default true
|
|
66
|
-
*/
|
|
67
|
-
dropcursor: Partial<DropcursorOptions> | false
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* character count options or false, indicating whether to enable character count
|
|
71
|
-
*
|
|
72
|
-
* @default true
|
|
73
|
-
*/
|
|
74
|
-
characterCount: Partial<CharacterCountOptions> | false
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* HardBreak options or false, indicating whether to enable hard breaks
|
|
78
|
-
*
|
|
79
|
-
* @default true
|
|
80
|
-
*/
|
|
81
|
-
hardBreak: Partial<HardBreakOptions> | false
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Placeholder options or false, indicating whether to enable placeholders
|
|
85
|
-
*
|
|
86
|
-
* @default true
|
|
87
|
-
*/
|
|
88
|
-
placeholder: Partial<PlaceholderOptions> | false
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Paragraph options or false, indicating whether to enable paragraph functionality
|
|
92
|
-
*
|
|
93
|
-
* @default true
|
|
94
|
-
*/
|
|
95
|
-
paragraph: Partial<ParagraphOptions> | false
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Focus options or false, indicating whether to enable focus functionality
|
|
99
|
-
*
|
|
100
|
-
* @default true
|
|
101
|
-
*/
|
|
102
|
-
focus: Partial<FocusOptions> | false
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* ListItem options or false, indicating whether to enable list item functionality
|
|
106
|
-
*
|
|
107
|
-
* @default true
|
|
108
|
-
*/
|
|
109
|
-
listItem: Partial<ListItemOptions> | false
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Text Style options or false, indicating whether to enable text style functionality
|
|
113
|
-
*
|
|
114
|
-
* @default true
|
|
115
|
-
*/
|
|
116
|
-
textStyle: Partial<TextStyleOptions> | false
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Bubble options, taking `BubbleOptions<BaseKitOptions>` as parameters, indicating whether to enable the bubble functionality
|
|
120
|
-
*/
|
|
121
|
-
// bubble: Partial<BubbleOptions<BaseKitOptions>>;
|
|
122
|
-
bubble: any
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Iframe options or false, indicating whether to enable the iframe
|
|
126
|
-
*
|
|
127
|
-
* @default true
|
|
128
|
-
*/
|
|
129
|
-
// iframe: Partial<IframeOptions> | false;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Trailing node options or false, indicating whether to enable the trailing node
|
|
133
|
-
*
|
|
134
|
-
* @default true
|
|
135
|
-
*/
|
|
136
|
-
trailingNode: Partial<TrailingNodeOptions> | false
|
|
137
|
-
/**
|
|
138
|
-
* textBubble options or false, indicating whether to enable the textBubble
|
|
139
|
-
*
|
|
140
|
-
* @default true
|
|
141
|
-
*/
|
|
142
|
-
textBubble: Partial<TextBubbleOptions> | false
|
|
143
|
-
/**
|
|
144
|
-
* selection options or false, indicating whether to enable the selection
|
|
145
|
-
*
|
|
146
|
-
* @default true
|
|
147
|
-
*/
|
|
148
|
-
selection: any | false
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const BaseKit = Extension.create<BaseKitOptions>({
|
|
152
|
-
name: 'base-kit',
|
|
153
|
-
|
|
154
|
-
addExtensions() {
|
|
155
|
-
const extensions: AnyExtension[] = [];
|
|
156
|
-
|
|
157
|
-
if (this.options.document !== false) {
|
|
158
|
-
extensions.push(Document.configure());
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (this.options.placeholder !== false) {
|
|
162
|
-
extensions.push(
|
|
163
|
-
Placeholder.configure({
|
|
164
|
-
placeholder: ({ node, pos, editor }) => {
|
|
165
|
-
if (node?.type?.name === 'columns' || node?.content?.size !== 0) {
|
|
166
|
-
return '';
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (node?.type?.name === 'heading') {
|
|
170
|
-
// @ts-expect-error
|
|
171
|
-
return `${localeActions.t(`editor.heading.h${node.attrs.level}.tooltip`)}`;
|
|
172
|
-
}
|
|
173
|
-
if (node?.type?.name === 'codeBlock' || node?.type?.name === 'table') {
|
|
174
|
-
return '';
|
|
175
|
-
}
|
|
176
|
-
if (editor.extensionManager.extensions.some(ext => ext.name === 'slashCommand')) {
|
|
177
|
-
return localeActions.t('editor.slash');
|
|
178
|
-
}
|
|
179
|
-
if (pos === 0) {
|
|
180
|
-
return localeActions.t('editor.content');
|
|
181
|
-
}
|
|
182
|
-
return localeActions.t('editor.content');
|
|
183
|
-
},
|
|
184
|
-
...this.options.placeholder,
|
|
185
|
-
}),
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (this.options.focus !== false) {
|
|
190
|
-
extensions.push(
|
|
191
|
-
Focus.configure({
|
|
192
|
-
className: 'focus',
|
|
193
|
-
...this.options.focus,
|
|
194
|
-
}),
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (this.options.text !== false) {
|
|
199
|
-
extensions.push(Text.configure());
|
|
200
|
-
}
|
|
201
|
-
if (this.options.textBubble !== false) {
|
|
202
|
-
extensions.push(TextBubble.configure());
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (this.options.gapcursor !== false) {
|
|
206
|
-
extensions.push(Gapcursor.configure());
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (this.options.dropcursor !== false) {
|
|
210
|
-
extensions.push(
|
|
211
|
-
Dropcursor.configure({
|
|
212
|
-
...this.options.dropcursor,
|
|
213
|
-
width: 2,
|
|
214
|
-
class: 'ProseMirror-dropcursor border-black',
|
|
215
|
-
}),
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (this.options.characterCount !== false) {
|
|
220
|
-
extensions.push(CharacterCount.configure(this.options.characterCount));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (this.options.paragraph !== false) {
|
|
224
|
-
extensions.push(Paragraph.configure(this.options.paragraph));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (this.options.hardBreak !== false) {
|
|
228
|
-
extensions.push(HardBreak.configure(this.options.hardBreak));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (this.options.listItem !== false) {
|
|
232
|
-
extensions.push(ListItem.configure(this.options.listItem));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (this.options.textStyle !== false) {
|
|
236
|
-
extensions.push(TextStyle.configure(this.options.textStyle));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (this.options.trailingNode !== false) {
|
|
240
|
-
extensions.push(TrailingNode.configure(this.options.trailingNode));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (this.options.selection !== false) {
|
|
244
|
-
extensions.push(Selection);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (this.options.multiColumn !== false) {
|
|
248
|
-
extensions.push(Column, MultiColumn);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return extensions;
|
|
252
|
-
},
|
|
253
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { BlockquoteOptions as TiptapBlockquoteOptions } from '@tiptap/extension-blockquote';
|
|
2
|
-
import { Blockquote as TiptapBlockquote } from '@tiptap/extension-blockquote';
|
|
3
|
-
|
|
4
|
-
import { ActionButton } from '@/components';
|
|
5
|
-
import type { GeneralOptions } from '@/types';
|
|
6
|
-
|
|
7
|
-
export interface BlockquoteOptions
|
|
8
|
-
extends TiptapBlockquoteOptions,
|
|
9
|
-
GeneralOptions<BlockquoteOptions> {}
|
|
10
|
-
|
|
11
|
-
export const Blockquote = TiptapBlockquote.extend<BlockquoteOptions>({
|
|
12
|
-
addOptions() {
|
|
13
|
-
return {
|
|
14
|
-
...this.parent?.(),
|
|
15
|
-
HTMLAttributes: {
|
|
16
|
-
class: 'blockquote',
|
|
17
|
-
},
|
|
18
|
-
button: ({ editor, t }: any) => ({
|
|
19
|
-
component: ActionButton,
|
|
20
|
-
componentProps: {
|
|
21
|
-
action: () => editor.commands.toggleBlockquote(),
|
|
22
|
-
isActive: () => editor.isActive('blockquote') || false,
|
|
23
|
-
disabled: !editor.can().toggleBlockquote(),
|
|
24
|
-
icon: 'TextQuote',
|
|
25
|
-
shortcutKeys: ['shift', 'mod', 'B'],
|
|
26
|
-
tooltip: t('editor.blockquote.tooltip'),
|
|
27
|
-
},
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Blockquote';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { BoldOptions as TiptapImageOptions } from '@tiptap/extension-bold';
|
|
2
|
-
import { Bold as TiptapBold } from '@tiptap/extension-bold';
|
|
3
|
-
|
|
4
|
-
import { ActionButton } from '@/components';
|
|
5
|
-
import type { GeneralOptions } from '@/types';
|
|
6
|
-
|
|
7
|
-
export interface BoldOptions extends TiptapImageOptions, GeneralOptions<BoldOptions> {}
|
|
8
|
-
|
|
9
|
-
export const Bold = TiptapBold.extend<BoldOptions>({
|
|
10
|
-
addOptions() {
|
|
11
|
-
return {
|
|
12
|
-
...this.parent?.(),
|
|
13
|
-
button: ({ editor, t }: any) => ({
|
|
14
|
-
component: ActionButton,
|
|
15
|
-
componentProps: {
|
|
16
|
-
action: () => editor.commands.toggleBold(),
|
|
17
|
-
isActive: () => editor.isActive('bold') || false,
|
|
18
|
-
disabled: !editor.can().toggleBold(),
|
|
19
|
-
icon: 'Bold',
|
|
20
|
-
shortcutKeys: ['mod', 'B'],
|
|
21
|
-
tooltip: t('editor.bold.tooltip'),
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Bold';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { BulletListOptions as TiptapBulletListOptions } from '@tiptap/extension-bullet-list';
|
|
2
|
-
import { BulletList as TiptapBulletList } from '@tiptap/extension-bullet-list';
|
|
3
|
-
|
|
4
|
-
import { ActionButton } from '@/components';
|
|
5
|
-
import type { GeneralOptions } from '@/types';
|
|
6
|
-
|
|
7
|
-
export interface BulletListOptions
|
|
8
|
-
extends TiptapBulletListOptions,
|
|
9
|
-
GeneralOptions<BulletListOptions> {}
|
|
10
|
-
|
|
11
|
-
export const BulletList = TiptapBulletList.extend<BulletListOptions>({
|
|
12
|
-
addOptions() {
|
|
13
|
-
return {
|
|
14
|
-
...this.parent?.(),
|
|
15
|
-
button: ({ editor, t }) => ({
|
|
16
|
-
component: ActionButton,
|
|
17
|
-
componentProps: {
|
|
18
|
-
action: () => editor.commands.toggleBulletList(),
|
|
19
|
-
isActive: () => editor.isActive('bulletList') || false,
|
|
20
|
-
disabled: false,
|
|
21
|
-
shortcutKeys: ['shift', 'mod', '8'],
|
|
22
|
-
icon: 'List',
|
|
23
|
-
tooltip: t('editor.bulletlist.tooltip'),
|
|
24
|
-
},
|
|
25
|
-
}),
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BulletList';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
import { ActionButton } from '@/components';
|
|
4
|
-
import type { GeneralOptions } from '@/types';
|
|
5
|
-
|
|
6
|
-
export interface ClearOptions extends GeneralOptions<ClearOptions> {}
|
|
7
|
-
|
|
8
|
-
export const Clear = Node.create<ClearOptions>({
|
|
9
|
-
name: 'clear',
|
|
10
|
-
addOptions() {
|
|
11
|
-
return {
|
|
12
|
-
...this.parent?.(),
|
|
13
|
-
button: ({ editor, t }) => ({
|
|
14
|
-
component: ActionButton,
|
|
15
|
-
componentProps: {
|
|
16
|
-
action: () => editor.chain().focus().clearNodes().unsetAllMarks().run(),
|
|
17
|
-
disabled: !editor.can().chain().focus().clearNodes().unsetAllMarks().run(),
|
|
18
|
-
icon: 'Eraser',
|
|
19
|
-
tooltip: t('editor.clear.tooltip'),
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Clear';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { CodeOptions as TiptapCodeOptions } from '@tiptap/extension-code';
|
|
2
|
-
import { Code as TiptapCode } from '@tiptap/extension-code';
|
|
3
|
-
|
|
4
|
-
import { ActionButton } from '@/components';
|
|
5
|
-
import type { GeneralOptions } from '@/types';
|
|
6
|
-
|
|
7
|
-
export interface CodeOptions extends TiptapCodeOptions, GeneralOptions<CodeOptions> {}
|
|
8
|
-
|
|
9
|
-
export const Code = TiptapCode.extend<CodeOptions>({
|
|
10
|
-
addOptions() {
|
|
11
|
-
return {
|
|
12
|
-
...this.parent?.(),
|
|
13
|
-
button: ({ editor, t }) => ({
|
|
14
|
-
component: ActionButton,
|
|
15
|
-
componentProps: {
|
|
16
|
-
action: () => editor.commands.toggleCode(),
|
|
17
|
-
isActive: () => editor.isActive('code') || false,
|
|
18
|
-
disabled: !editor.can().toggleCode(),
|
|
19
|
-
icon: 'Code',
|
|
20
|
-
shortcutKeys: ['mod', 'E'],
|
|
21
|
-
tooltip: t('editor.code.tooltip'),
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Code';
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { BundledLanguage, BundledTheme } from 'shiki';
|
|
2
|
-
import type { CodeBlockOptions as CodeBlockExtOptions } from '@tiptap/extension-code-block';
|
|
3
|
-
import CodeBlockExt from '@tiptap/extension-code-block';
|
|
4
|
-
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
5
|
-
import type { GeneralOptions } from '@/types';
|
|
6
|
-
import { ShikiPlugin } from '@/extensions/CodeBlock/shiki-plugin';
|
|
7
|
-
import CodeBlockActiveButton from '@/extensions/CodeBlock/components/CodeBlockActiveButton';
|
|
8
|
-
import { DEFAULT_LANGUAGE_CODE_BLOCK } from '@/constants';
|
|
9
|
-
import { NodeViewCodeBlock } from '@/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock';
|
|
10
|
-
|
|
11
|
-
export interface CodeBlockOptions
|
|
12
|
-
extends GeneralOptions<CodeBlockExtOptions> {
|
|
13
|
-
languages?: BundledLanguage[]
|
|
14
|
-
defaultTheme: BundledTheme
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const CodeBlock = CodeBlockExt.extend<CodeBlockOptions>({
|
|
18
|
-
addOptions() {
|
|
19
|
-
return {
|
|
20
|
-
...this.parent?.(),
|
|
21
|
-
languages: [],
|
|
22
|
-
button: ({ editor, t, extension }: any) => {
|
|
23
|
-
const languages = extension?.options?.languages?.length ? extension?.options?.languages : DEFAULT_LANGUAGE_CODE_BLOCK;
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
component: CodeBlockActiveButton,
|
|
27
|
-
componentProps: {
|
|
28
|
-
action: (language = 'js') => editor.commands.setCodeBlock({
|
|
29
|
-
language,
|
|
30
|
-
}),
|
|
31
|
-
isActive: () => editor.isActive('codeBlock') || false,
|
|
32
|
-
disabled: !editor.can().toggleCodeBlock(),
|
|
33
|
-
icon: 'Code2',
|
|
34
|
-
tooltip: t('editor.codeblock.tooltip'),
|
|
35
|
-
languages,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
addNodeView() {
|
|
42
|
-
return ReactNodeViewRenderer(NodeViewCodeBlock);
|
|
43
|
-
},
|
|
44
|
-
addProseMirrorPlugins() {
|
|
45
|
-
return [
|
|
46
|
-
...(this.parent?.() || []),
|
|
47
|
-
ShikiPlugin({
|
|
48
|
-
name: this.name,
|
|
49
|
-
defaultLanguage: null,
|
|
50
|
-
defaultTheme: this.options.defaultTheme,
|
|
51
|
-
}),
|
|
52
|
-
];
|
|
53
|
-
},
|
|
54
|
-
});
|