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