import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' export interface BulletListOptions { HTMLAttributes: Record, } declare module '@tiptap/core' { interface Commands { bulletList: { /** * Toggle a bullet list */ toggleBulletList: () => ReturnType, } } } export const inputRegex = /^\s*([-+*])\s$/ export const BulletList = Node.create({ name: 'bulletList', defaultOptions: { HTMLAttributes: {}, }, group: 'block list', content: 'listItem+', parseHTML() { return [ { tag: 'ul' }, ] }, renderHTML({ HTMLAttributes }) { return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] }, addCommands() { return { toggleBulletList: () => ({ commands }) => { return commands.toggleList('bulletList', 'listItem') }, } }, addKeyboardShortcuts() { return { 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(), } }, addInputRules() { return [ wrappingInputRule({ find: inputRegex, type: this.type, }), ] }, })