move inputrule from task_list to task_item
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { createNode, mergeAttributes } from '@tiptap/core'
|
import { createNode, mergeAttributes } from '@tiptap/core'
|
||||||
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
|
export const inputRegex = /^\s*(\[([ |x])\])\s$/
|
||||||
|
|
||||||
export interface TaskItemOptions {
|
export interface TaskItemOptions {
|
||||||
nested: boolean,
|
nested: boolean,
|
||||||
@@ -94,6 +97,18 @@ const TaskItem = createNode({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addInputRules() {
|
||||||
|
return [
|
||||||
|
wrappingInputRule(
|
||||||
|
inputRegex,
|
||||||
|
this.type,
|
||||||
|
match => ({
|
||||||
|
checked: match[match.length - 1] === 'x',
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export default TaskItem
|
export default TaskItem
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import { Command, createNode, mergeAttributes } from '@tiptap/core'
|
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({
|
const TaskList = createNode({
|
||||||
name: 'task_list',
|
name: 'task_list',
|
||||||
@@ -33,12 +29,6 @@ const TaskList = createNode({
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addInputRules() {
|
|
||||||
return [
|
|
||||||
wrappingInputRule(inputRegex, this.type),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export default TaskList
|
export default TaskList
|
||||||
|
|||||||
Reference in New Issue
Block a user