2021-06-05 03:56:29 +08:00
|
|
|
import { Node, mergeAttributes } from '@tiptap/core'
|
2020-11-13 23:44:22 +08:00
|
|
|
|
|
|
|
export interface ParagraphOptions {
|
2021-04-21 15:43:31 +08:00
|
|
|
HTMLAttributes: Record<string, any>,
|
2020-11-13 23:44:22 +08:00
|
|
|
}
|
2020-03-06 03:30:58 +08:00
|
|
|
|
2021-02-10 16:59:35 +08:00
|
|
|
declare module '@tiptap/core' {
|
2021-06-05 03:56:29 +08:00
|
|
|
interface Commands<ReturnType> {
|
2021-02-16 18:27:58 +08:00
|
|
|
paragraph: {
|
|
|
|
/**
|
|
|
|
* Toggle a paragraph
|
|
|
|
*/
|
2021-06-05 03:56:29 +08:00
|
|
|
setParagraph: () => ReturnType,
|
2021-02-16 18:27:58 +08:00
|
|
|
}
|
2021-02-10 16:59:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 01:25:08 +08:00
|
|
|
export const Paragraph = Node.create<ParagraphOptions>({
|
2020-10-21 21:17:05 +08:00
|
|
|
name: 'paragraph',
|
|
|
|
|
2021-04-08 00:29:16 +08:00
|
|
|
priority: 1000,
|
|
|
|
|
2021-02-11 01:25:08 +08:00
|
|
|
defaultOptions: {
|
2020-11-14 16:23:47 +08:00
|
|
|
HTMLAttributes: {},
|
|
|
|
},
|
2020-11-13 23:44:22 +08:00
|
|
|
|
2020-10-21 21:17:05 +08:00
|
|
|
group: 'block',
|
|
|
|
|
|
|
|
content: 'inline*',
|
2020-10-12 16:32:54 +08:00
|
|
|
|
2020-10-10 04:59:25 +08:00
|
|
|
parseHTML() {
|
|
|
|
return [
|
|
|
|
{ tag: 'p' },
|
|
|
|
]
|
2020-10-21 21:17:05 +08:00
|
|
|
},
|
2020-10-10 04:59:25 +08:00
|
|
|
|
2020-11-13 23:07:20 +08:00
|
|
|
renderHTML({ HTMLAttributes }) {
|
2020-11-25 16:50:54 +08:00
|
|
|
return ['p', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
2020-10-21 21:17:05 +08:00
|
|
|
},
|
2020-10-22 15:42:28 +08:00
|
|
|
|
2020-10-22 17:14:44 +08:00
|
|
|
addCommands() {
|
2020-10-22 15:42:28 +08:00
|
|
|
return {
|
2021-02-10 16:59:35 +08:00
|
|
|
setParagraph: () => ({ commands }) => {
|
2021-08-10 22:59:09 +08:00
|
|
|
return commands.setNode('paragraph')
|
2020-10-22 15:42:28 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-22 17:14:44 +08:00
|
|
|
addKeyboardShortcuts() {
|
2020-10-22 15:42:28 +08:00
|
|
|
return {
|
2020-11-18 19:29:24 +08:00
|
|
|
'Mod-Alt-0': () => this.editor.commands.setParagraph(),
|
2020-10-22 15:42:28 +08:00
|
|
|
}
|
|
|
|
},
|
2020-10-21 21:17:05 +08:00
|
|
|
})
|