tiptap/packages/extension-task-list/index.ts

39 lines
710 B
TypeScript
Raw Normal View History

import { Command, createNode, mergeAttributes } from '@tiptap/core'
2020-10-30 23:06:30 +08:00
const TaskList = createNode({
name: 'task_list',
2020-11-02 22:18:03 +08:00
group: 'block list',
content: 'task_item+',
parseHTML() {
return [
{
tag: 'ul[data-type="task_list"]',
priority: 51,
},
]
},
renderHTML({ attributes }) {
return ['ul', mergeAttributes(attributes, { 'data-type': 'task_list' }), 0]
},
addCommands() {
return {
taskList: (): Command => ({ commands }) => {
return commands.toggleList('task_list', 'task_item')
},
}
},
})
export default TaskList
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
TaskList: typeof TaskList,
}
}