Appearance
类型化容器 TypedContainer
带类型标记的区块容器,常用于「例题」「文稿」等场景。容器类型通过 options 配置,存储在节点的 type 属性中(渲染为 data-type)。
用法
ts
import { TypedContainer } from '@qingpai/core'
const editor = new Editor({
extensions: [
TypedContainer.configure({
options: [
{ label: '例题', value: 'example' },
{ label: '文稿', value: 'manuscript' },
],
}),
],
})配置项
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
options | { label: string, value: string }[] | [] | 容器类型选项;label 渲染为容器左上角标签,value 存入 type 属性 |
节点结构
content model 为 '(paragraph|table)+'——容器内只允许段落和表格,且 isolating: true,容器内外选区相互隔离。
渲染为 <div class="qp-typed-container" data-type="manuscript">…</div>(NodeView 附加卡片样式与类型标签)。
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
type | string | '' | 容器类型,渲染为 data-type,须在 options 中定义 |
命令
| 命令 | 说明 |
|---|---|
setTypedContainer({ type }) | 将当前节点转换为指定类型的容器 |
insertTypedContainer({ type, pos? }) | 插入一个包含空段落的指定类型容器;不传 pos 时插入到当前选区 |
deleteTypedContainer() | 删除当前容器 |
ts
editor.commands.insertTypedContainer({ type: 'example' })配套 UI
| 名称 | 说明 |
|---|---|
BlocksDropdown | 区块类型切换下拉(段落 / 标题 / 各容器类型) |