tiptap/packages/extension-bullet-list/index.ts

34 lines
766 B
TypeScript
Raw Normal View History

2020-09-22 15:08:08 +08:00
import { Command, Node } from '@tiptap/core'
2020-09-11 04:29:15 +08:00
import { wrappingInputRule } from 'prosemirror-inputrules'
2020-09-22 15:08:08 +08:00
export type BulletListCommand = () => Command
2020-09-11 04:29:15 +08:00
declare module '@tiptap/core/src/Editor' {
2020-09-22 16:49:38 +08:00
interface Commands {
2020-09-22 15:08:08 +08:00
bulletList: BulletListCommand,
2020-09-11 04:29:15 +08:00
}
}
export default new Node()
.name('bullet_list')
.schema(() => ({
content: 'list_item+',
group: 'block',
parseDOM: [
{ tag: 'ul' },
],
toDOM: () => ['ul', 0],
}))
2020-09-23 02:39:24 +08:00
.commands(({ name }) => ({
bulletList: () => ({ commands }) => {
return commands.toggleList(name, 'list_item')
},
}))
2020-09-11 04:29:15 +08:00
.keys(({ editor }) => ({
'Shift-Control-8': () => editor.bulletList(),
2020-09-11 04:29:15 +08:00
}))
.inputRules(({ type }) => [
wrappingInputRule(/^\s*([-+*])\s$/, type),
])
.create()