feat(@vben/plugins): tiptap 支持图片上传功能

- 新增 imageUpload 配置项,支持自定义上传接口
- 支持文件选择、拖拽、粘贴三种上传方式
- 上传中显示 blob 预览图 + loading spinner / 进度条
- 支持 accept 和 maxSize 文件校验
- 支持 onUploadError 自定义错误处理
- 未配置 imageUpload 时保持原有 URL 插入行为不变
- 使用 NodeView 实现实时 DOM 控制的进度展示
This commit is contained in:
yuan.ji
2026-04-27 13:42:36 +08:00
parent 36d7dc23fa
commit 4ca2f1c6e8
11 changed files with 2727 additions and 2408 deletions

View File

@@ -1,6 +1,6 @@
import type { Editor } from '@tiptap/vue-3';
import type { ToolbarAction, ToolbarMenuItem } from './types';
import type { ImageUploadOptions, ToolbarAction, ToolbarMenuItem } from './types';
import {
AlignCenter,
@@ -155,7 +155,9 @@ async function handleImageAction(editor: Editor) {
editor.chain().focus().setImage({ src: nextUrl }).run();
}
export function createToolbarGroups(): ToolbarAction[][] {
export function createToolbarGroups(
imageUpload?: ImageUploadOptions,
): ToolbarAction[][] {
const headingMenuItems = createHeadingMenuItems();
return [
@@ -278,6 +280,25 @@ export function createToolbarGroups(): ToolbarAction[][] {
action: (editor) => handleImageAction(editor),
icon: ImagePlus,
label: $t('ui.tiptap.toolbar.image'),
...(imageUpload
? {
action: () => {},
menu: {
items: [
{
action: (editor) => (editor.commands as any).uploadImage(),
label: $t('ui.tiptap.toolbar.imageUpload'),
shortLabel: 'UPL',
},
{
action: (editor) => handleImageAction(editor),
label: $t('ui.tiptap.toolbar.imageUrl'),
shortLabel: 'URL',
},
],
},
}
: {}),
},
],
[