tiptap/packages/extension-task-list/index.ts
2020-10-30 16:51:25 +01:00

41 lines
720 B
TypeScript

import { Command, createNode, mergeAttributes } from '@tiptap/core'
const TaskList = createNode({
name: 'task_list',
list: true,
group: 'block',
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,
}
}