2020-11-25 16:50:54 +08:00
|
|
|
import { Node, mergeAttributes } from '@tiptap/core'
|
2020-09-11 04:29:15 +08:00
|
|
|
|
2020-11-13 23:44:22 +08:00
|
|
|
export interface ListItemOptions {
|
|
|
|
HTMLAttributes: {
|
|
|
|
[key: string]: any
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-08 04:32:50 +08:00
|
|
|
export const ListItem = Node.create({
|
2020-11-04 03:57:09 +08:00
|
|
|
name: 'listItem',
|
2020-10-22 18:34:49 +08:00
|
|
|
|
2020-11-13 23:44:22 +08:00
|
|
|
defaultOptions: <ListItemOptions>{
|
|
|
|
HTMLAttributes: {},
|
|
|
|
},
|
|
|
|
|
2020-12-03 22:11:47 +08:00
|
|
|
content: 'paragraph block*',
|
2020-10-22 18:34:49 +08:00
|
|
|
|
|
|
|
defining: true,
|
|
|
|
|
|
|
|
parseHTML() {
|
|
|
|
return [
|
2020-10-30 20:19:06 +08:00
|
|
|
{
|
|
|
|
tag: 'li',
|
|
|
|
},
|
2020-10-22 18:34:49 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
2020-11-13 23:07:20 +08:00
|
|
|
renderHTML({ HTMLAttributes }) {
|
2020-11-25 16:50:54 +08:00
|
|
|
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
2020-10-22 18:34:49 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
addKeyboardShortcuts() {
|
|
|
|
return {
|
2020-11-13 18:42:04 +08:00
|
|
|
Enter: () => this.editor.commands.splitListItem('listItem'),
|
|
|
|
Tab: () => this.editor.commands.sinkListItem('listItem'),
|
|
|
|
'Shift-Tab': () => this.editor.commands.liftListItem('listItem'),
|
2020-10-22 18:34:49 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|