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

39 lines
704 B
TypeScript
Raw Normal View History

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