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-23 04:40:40 +08:00
|
|
|
const BulletList = createNode({
|
2020-10-22 18:34:49 +08:00
|
|
|
name: 'bullet_list',
|
|
|
|
|
|
|
|
content: 'list_item+',
|
|
|
|
|
|
|
|
group: 'block',
|
|
|
|
|
|
|
|
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-10-22 18:34:49 +08:00
|
|
|
return commands.toggleList('bullet_list', 'list_item')
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addKeyboardShortcuts() {
|
|
|
|
return {
|
|
|
|
'Shift-Control-8': () => this.editor.bulletList(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
|
|
|
return [
|
|
|
|
wrappingInputRule(/^\s*([-+*])\s$/, this.type),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
2020-10-23 04:40:40 +08:00
|
|
|
|
|
|
|
export default BulletList
|
|
|
|
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
|
|
interface AllExtensions {
|
|
|
|
BulletList: typeof BulletList,
|
|
|
|
}
|
|
|
|
}
|