tiptap/packages/extension-list-item/src/index.ts

50 lines
846 B
TypeScript
Raw Normal View History

import { Node } 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
},
}
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-11-02 22:18:03 +08:00
content: '(paragraph|list?)+',
2020-10-22 18:34:49 +08:00
defining: true,
parseHTML() {
return [
{
tag: 'li',
},
2020-10-22 18:34:49 +08:00
]
},
2020-11-13 23:07:20 +08:00
renderHTML({ HTMLAttributes }) {
return ['li', HTMLAttributes, 0]
2020-10-22 18:34:49 +08:00
},
addKeyboardShortcuts() {
return {
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
}
},
})
2020-10-23 04:40:40 +08:00
export default ListItem
2020-11-16 22:40:05 +08:00
declare global {
namespace Tiptap {
interface AllExtensions {
ListItem: typeof ListItem,
}
2020-10-23 04:40:40 +08:00
}
}