mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-25 10:17:49 +08:00
56 lines
1008 B
TypeScript
56 lines
1008 B
TypeScript
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
|
|
|
export interface TaskListOptions {
|
|
HTMLAttributes: Record<string, any>,
|
|
}
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands {
|
|
taskList: {
|
|
/**
|
|
* Toggle a task list
|
|
*/
|
|
toggleTaskList: () => Command,
|
|
}
|
|
}
|
|
}
|
|
|
|
export const TaskList = Node.create<TaskListOptions>({
|
|
name: 'taskList',
|
|
|
|
defaultOptions: {
|
|
HTMLAttributes: {},
|
|
},
|
|
|
|
group: 'block list',
|
|
|
|
content: 'taskItem+',
|
|
|
|
parseHTML() {
|
|
return [
|
|
{
|
|
tag: 'ul[data-type="taskList"]',
|
|
priority: 51,
|
|
},
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['ul', mergeAttributes(HTMLAttributes, { 'data-type': 'taskList' }), 0]
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
toggleTaskList: () => ({ commands }) => {
|
|
return commands.toggleList('taskList', 'taskItem')
|
|
},
|
|
}
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-Shift-9': () => this.editor.commands.toggleTaskList(),
|
|
}
|
|
},
|
|
})
|