Loading...
功能特性
- 为图片、视频、音频文件等媒体元素添加标题说明
- 通过方向键在区块内选择标题
- 使用文本区域组件进行内联标题编辑
套件使用
安装
最快捷的方式是使用MediaKit
套件,它包含预配置的CaptionPlugin
以及媒体插件和它们的Plate UI组件。
Caption
: 为媒体元素渲染标题组件
添加套件
import { createPlateEditor } from 'platejs/react';
import { MediaKit } from '@/components/editor/plugins/media-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件
...MediaKit,
],
});
手动配置
安装
pnpm add @platejs/caption
添加插件
import { CaptionPlugin } from '@platejs/caption/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
CaptionPlugin,
],
});
配置插件
配置哪些媒体插件应支持标题功能:
import { KEYS } from 'platejs';
import { CaptionPlugin } from '@platejs/caption/react';
import {
AudioPlugin,
FilePlugin,
ImagePlugin,
MediaEmbedPlugin,
VideoPlugin,
} from '@platejs/media/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
ImagePlugin,
VideoPlugin,
AudioPlugin,
FilePlugin,
MediaEmbedPlugin,
CaptionPlugin.configure({
options: {
query: {
allow: [KEYS.img, KEYS.video, KEYS.audio, KEYS.file, KEYS.mediaEmbed],
},
},
}),
],
});
query.allow
: 支持标题功能的插件键名数组
插件
CaptionPlugin
为媒体元素添加标题功能的插件。
类型
TCaptionElement
继承自TElement
。