mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-21 15:28:09 +08:00
34 lines
766 B
TypeScript
34 lines
766 B
TypeScript
import { Command, Node } from '@tiptap/core'
|
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
|
|
|
export type BulletListCommand = () => Command
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Commands {
|
|
bulletList: BulletListCommand,
|
|
}
|
|
}
|
|
|
|
export default new Node()
|
|
.name('bullet_list')
|
|
.schema(() => ({
|
|
content: 'list_item+',
|
|
group: 'block',
|
|
parseDOM: [
|
|
{ tag: 'ul' },
|
|
],
|
|
toDOM: () => ['ul', 0],
|
|
}))
|
|
.commands(({ name }) => ({
|
|
bulletList: () => ({ commands }) => {
|
|
return commands.toggleList(name, 'list_item')
|
|
},
|
|
}))
|
|
.keys(({ editor }) => ({
|
|
'Shift-Control-8': () => editor.bulletList(),
|
|
}))
|
|
.inputRules(({ type }) => [
|
|
wrappingInputRule(/^\s*([-+*])\s$/, type),
|
|
])
|
|
.create()
|