fix(@vben/plugins): 修复 tiptap 重复注册扩展警告 (#7917)
StarterKit v3.22.0 已默认包含 Document、Link、Underline 扩展,
与单独导入产生重复注册,导致控制台警告:
[tiptap warn]: Duplicate extension names found: ['link', 'doc', 'underline']
- 移除 Document 单独导入和使用,StarterKit 已内置
- 移除 Underline 单独导入和使用,StarterKit 已内置
- StarterKit 配置中添加 link: false,禁用内置 Link,
保留自定义配置的 Link.configure({...})
master^2
parent
42d82875ce
commit
b5f79db321
|
|
@ -9,14 +9,12 @@ import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { alert } from '@vben-core/popup-ui';
|
import { alert } from '@vben-core/popup-ui';
|
||||||
|
|
||||||
import Document from '@tiptap/extension-document';
|
|
||||||
import Highlight from '@tiptap/extension-highlight';
|
import Highlight from '@tiptap/extension-highlight';
|
||||||
import Image from '@tiptap/extension-image';
|
import Image from '@tiptap/extension-image';
|
||||||
import Link from '@tiptap/extension-link';
|
import Link from '@tiptap/extension-link';
|
||||||
import Placeholder from '@tiptap/extension-placeholder';
|
import Placeholder from '@tiptap/extension-placeholder';
|
||||||
import TextAlign from '@tiptap/extension-text-align';
|
import TextAlign from '@tiptap/extension-text-align';
|
||||||
import { Color, TextStyle } from '@tiptap/extension-text-style';
|
import { Color, TextStyle } from '@tiptap/extension-text-style';
|
||||||
import Underline from '@tiptap/extension-underline';
|
|
||||||
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
||||||
import StarterKit from '@tiptap/starter-kit';
|
import StarterKit from '@tiptap/starter-kit';
|
||||||
|
|
||||||
|
|
@ -274,30 +272,30 @@ function createCustomImage(
|
||||||
...this.parent?.(),
|
...this.parent?.(),
|
||||||
uploadImage:
|
uploadImage:
|
||||||
() =>
|
() =>
|
||||||
({ editor: cmdEditor }: { editor: CoreEditor }) => {
|
({ editor: cmdEditor }: { editor: CoreEditor }) => {
|
||||||
const input = document.createElement('input');
|
const input = document.createElement('input');
|
||||||
input.type = 'file';
|
input.type = 'file';
|
||||||
input.accept = imageUpload.accept ?? DEFAULT_ACCEPT;
|
input.accept = imageUpload.accept ?? DEFAULT_ACCEPT;
|
||||||
input.style.display = 'none';
|
input.style.display = 'none';
|
||||||
|
|
||||||
input.addEventListener('change', () => {
|
input.addEventListener('change', () => {
|
||||||
const file = input.files?.[0];
|
const file = input.files?.[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
const error = validateFile(file, imageUpload);
|
const error = validateFile(file, imageUpload);
|
||||||
if (error) {
|
if (error) {
|
||||||
handleUploadError(new Error(error), imageUpload);
|
handleUploadError(new Error(error), imageUpload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
createUploadProcess(cmdEditor, file, imageUpload, blobUrlTracker);
|
createUploadProcess(cmdEditor, file, imageUpload, blobUrlTracker);
|
||||||
input.remove();
|
input.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.body.append(input);
|
document.body.append(input);
|
||||||
input.click();
|
input.click();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -405,13 +403,12 @@ export function createDefaultTiptapExtensions(
|
||||||
options: VbenTiptapExtensionOptions = {},
|
options: VbenTiptapExtensionOptions = {},
|
||||||
): Extensions {
|
): Extensions {
|
||||||
return [
|
return [
|
||||||
Document,
|
|
||||||
StarterKit.configure({
|
StarterKit.configure({
|
||||||
heading: {
|
heading: {
|
||||||
levels: [1, 2, 3, 4],
|
levels: [1, 2, 3, 4],
|
||||||
},
|
},
|
||||||
|
link: false,
|
||||||
}),
|
}),
|
||||||
Underline,
|
|
||||||
TextAlign.configure({
|
TextAlign.configure({
|
||||||
types: ['heading', 'paragraph'],
|
types: ['heading', 'paragraph'],
|
||||||
}),
|
}),
|
||||||
|
|
@ -431,20 +428,20 @@ export function createDefaultTiptapExtensions(
|
||||||
}),
|
}),
|
||||||
options.imageUpload
|
options.imageUpload
|
||||||
? createCustomImage(
|
? createCustomImage(
|
||||||
options.imageUpload,
|
options.imageUpload,
|
||||||
options._blobUrlTracker,
|
options._blobUrlTracker,
|
||||||
).configure({
|
).configure({
|
||||||
allowBase64: true,
|
allowBase64: true,
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
class: 'vben-tiptap__image',
|
class: 'vben-tiptap__image',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: Image.configure({
|
: Image.configure({
|
||||||
allowBase64: true,
|
allowBase64: true,
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
class: 'vben-tiptap__image',
|
class: 'vben-tiptap__image',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
Placeholder.configure({
|
Placeholder.configure({
|
||||||
placeholder: options.placeholder ?? $t('ui.tiptap.placeholder'),
|
placeholder: options.placeholder ?? $t('ui.tiptap.placeholder'),
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue