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

52 lines
915 B
TypeScript
Raw Normal View History

2020-11-16 06:25:25 +08:00
import { Command, NodeExtension, mergeAttributes } from '@tiptap/core'
2020-10-30 23:06:30 +08:00
2020-11-13 23:44:22 +08:00
export interface TaskListOptions {
HTMLAttributes: {
[key: string]: any
},
}
2020-11-16 06:25:25 +08:00
const TaskList = NodeExtension.create({
2020-11-05 21:51:34 +08:00
name: 'taskList',
2020-11-13 23:44:22 +08:00
defaultOptions: <TaskListOptions>{
HTMLAttributes: {},
},
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,
},
]
},
2020-11-13 23:07:20 +08:00
renderHTML({ HTMLAttributes }) {
return ['ul', mergeAttributes(HTMLAttributes, { 'data-type': 'taskList' }), 0]
},
addCommands() {
return {
2020-11-13 22:08:30 +08:00
/**
* Toggle a task list
*/
taskList: (): Command => ({ commands }) => {
2020-11-05 21:51:34 +08:00
return commands.toggleList('taskList', 'taskItem')
},
}
},
})
export default TaskList
2020-11-11 04:18:22 +08:00
declare module '@tiptap/core' {
interface AllExtensions {
TaskList: typeof TaskList,
}
}