mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-22 08:07:50 +08:00
51 lines
952 B
TypeScript
51 lines
952 B
TypeScript
import { Command, createNode, mergeAttributes } from '@tiptap/core'
|
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
|
|
|
// TODO: add suport for [ ] and [x]
|
|
export const inputRegex = /^\s*(\[ \])\s$/
|
|
|
|
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')
|
|
},
|
|
}
|
|
},
|
|
|
|
addInputRules() {
|
|
return [
|
|
wrappingInputRule(inputRegex, this.type),
|
|
]
|
|
},
|
|
})
|
|
|
|
export default TaskList
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface AllExtensions {
|
|
TaskList: typeof TaskList,
|
|
}
|
|
}
|