尾节点扩展
该扩展在编辑器的最后一个块节点后添加一个节点。这对于添加尾节点,如占位符或按钮,可能会很有用。
安装
npm install @tiptap/extensions用法
import { Editor } from '@tiptap/core'
import { TrailingNode } from '@tiptap/extensions'
new Editor({
extensions: [TrailingNode],
})设置
node
应在文档末尾插入的节点类型。当未设置此项时,尾节点扩展会向 ProseMirror schema 查询其定义的回退节点(通常是默认块节点),但你可以通过 node 选项覆盖此行为。当你定义了自定义文档结构时,这一点尤为重要——请参阅强制内容结构示例了解自定义文档如何影响默认回退节点。
默认值:undefined
TrailingNode.configure({
node: 'paragraph',
})notAfter
在这些节点类型之后不应插入尾节点。
默认值:['paragraph']
TrailingNode.configure({
node: 'paragraph',
notAfter: ['heading', 'blockquote'],
})在事务中跳过尾节点创建
你可以通过在特定事务上设置 skipTrailingNode 元标志来跳过该事务的自动尾节点插入。
editor
.chain()
.command(({ tr }) => {
tr.setMeta('skipTrailingNode', true)
return true
})
.run()当你故意想让某个事务在离开文档时不留下额外的尾节点时,这会很有用。
源代码
packages/extensions/src/trailing-node/
最小安装
import { Editor } from '@tiptap/core'
import { TrailingNode } from '@tiptap/extensions/trailing-node'
new Editor({
extensions: [TrailingNode],
})