You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.3 KiB
70 lines
1.3 KiB
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
|
|
|
|
export interface BulletListOptions {
|
|
itemTypeName: string,
|
|
HTMLAttributes: Record<string, any>,
|
|
}
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands<ReturnType> {
|
|
bulletList: {
|
|
/**
|
|
* Toggle a bullet list
|
|
*/
|
|
toggleBulletList: () => ReturnType,
|
|
}
|
|
}
|
|
}
|
|
|
|
export const inputRegex = /^\s*([-+*])\s$/
|
|
|
|
export const BulletList = Node.create<BulletListOptions>({
|
|
name: 'bulletList',
|
|
|
|
addOptions() {
|
|
return {
|
|
itemTypeName: 'listItem',
|
|
HTMLAttributes: {},
|
|
}
|
|
},
|
|
|
|
group: 'block list',
|
|
|
|
content() {
|
|
return `${this.options.itemTypeName}+`
|
|
},
|
|
|
|
parseHTML() {
|
|
return [
|
|
{ tag: 'ul' },
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
toggleBulletList: () => ({ commands }) => {
|
|
return commands.toggleList(this.name, this.options.itemTypeName)
|
|
},
|
|
}
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),
|
|
}
|
|
},
|
|
|
|
addInputRules() {
|
|
return [
|
|
wrappingInputRule({
|
|
find: inputRegex,
|
|
type: this.type,
|
|
}),
|
|
]
|
|
},
|
|
})
|