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

34 lines
802 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' {
interface Editor {
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-22 05:17:30 +08:00
// .commands(({ editor, type }) => ({
2020-09-22 15:08:08 +08:00
// bulletList: () => ({ commands }) => {
// return commands.toggleList(type, editor.schema.nodes.list_item)
2020-09-22 05:17:30 +08:00
// },
// }))
2020-09-11 04:29:15 +08:00
.keys(({ editor }) => ({
'Shift-Ctrl-8': () => editor.bulletList(),
}))
.inputRules(({ type }) => [
wrappingInputRule(/^\s*([-+*])\s$/, type),
])
.create()