mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
b941eea6da
* added JSDocs for almost all extensions * start adding commands jsdocs * add jsdocs for rest of extensions * add jsdocs for Extensions * add js docs for all extensions * add more jsdocs * add js docs for node spec definitions
65 lines
1.3 KiB
TypeScript
65 lines
1.3 KiB
TypeScript
import { mergeAttributes, Node } from '@tiptap/core'
|
|
|
|
export interface ListItemOptions {
|
|
/**
|
|
* The HTML attributes for a list item node.
|
|
* @default {}
|
|
* @example { class: 'foo' }
|
|
*/
|
|
HTMLAttributes: Record<string, any>,
|
|
|
|
/**
|
|
* The node type for bulletList nodes
|
|
* @default 'bulletList'
|
|
* @example 'myCustomBulletList'
|
|
*/
|
|
bulletListTypeName: string
|
|
|
|
/**
|
|
* The node type for orderedList nodes
|
|
* @default 'orderedList'
|
|
* @example 'myCustomOrderedList'
|
|
*/
|
|
orderedListTypeName: string
|
|
}
|
|
|
|
/**
|
|
* This extension allows you to create list items.
|
|
* @see https://www.tiptap.dev/api/nodes/list-item
|
|
*/
|
|
export const ListItem = Node.create<ListItemOptions>({
|
|
name: 'listItem',
|
|
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
bulletListTypeName: 'bulletList',
|
|
orderedListTypeName: 'orderedList',
|
|
}
|
|
},
|
|
|
|
content: 'paragraph block*',
|
|
|
|
defining: true,
|
|
|
|
parseHTML() {
|
|
return [
|
|
{
|
|
tag: 'li',
|
|
},
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
|
|
}
|
|
},
|
|
})
|