2020-10-22 18:34:49 +08:00
|
|
|
import { Command, createNode } from '@tiptap/core'
|
2020-09-11 04:29:15 +08:00
|
|
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
|
|
|
|
2020-10-30 23:06:30 +08:00
|
|
|
export const inputRegex = /^\s*([-+*])\s$/
|
|
|
|
|
2020-10-23 04:40:40 +08:00
|
|
|
const BulletList = createNode({
|
2020-11-04 03:57:09 +08:00
|
|
|
name: 'bulletList',
|
2020-10-22 18:34:49 +08:00
|
|
|
|
2020-11-02 22:18:03 +08:00
|
|
|
group: 'block list',
|
2020-10-22 18:34:49 +08:00
|
|
|
|
2020-11-04 03:57:09 +08:00
|
|
|
content: 'listItem+',
|
2020-10-30 20:19:06 +08:00
|
|
|
|
2020-10-22 18:34:49 +08:00
|
|
|
parseHTML() {
|
|
|
|
return [
|
2020-09-11 04:29:15 +08:00
|
|
|
{ tag: 'ul' },
|
2020-10-22 18:34:49 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ attributes }) {
|
|
|
|
return ['ul', attributes, 0]
|
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2020-10-23 04:40:40 +08:00
|
|
|
bulletList: (): Command => ({ commands }) => {
|
2020-11-04 03:57:09 +08:00
|
|
|
return commands.toggleList('bulletList', 'listItem')
|
2020-10-22 18:34:49 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addKeyboardShortcuts() {
|
|
|
|
return {
|
|
|
|
'Shift-Control-8': () => this.editor.bulletList(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
|
|
|
return [
|
2020-10-30 23:06:30 +08:00
|
|
|
wrappingInputRule(inputRegex, this.type),
|
2020-10-22 18:34:49 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
2020-10-23 04:40:40 +08:00
|
|
|
|
|
|
|
export default BulletList
|
|
|
|
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
|
|
interface AllExtensions {
|
|
|
|
BulletList: typeof BulletList,
|
|
|
|
}
|
|
|
|
}
|