2022-06-08 20:10:25 +08:00
|
|
|
import { mergeAttributes, Node } from '@tiptap/core'
|
2021-01-22 07:16:58 +08:00
|
|
|
|
|
|
|
export interface TableHeaderOptions {
|
2021-04-21 15:43:31 +08:00
|
|
|
HTMLAttributes: Record<string, any>,
|
2021-01-22 07:16:58 +08:00
|
|
|
}
|
2021-02-11 01:25:08 +08:00
|
|
|
export const TableHeader = Node.create<TableHeaderOptions>({
|
2021-01-23 06:33:08 +08:00
|
|
|
name: 'tableHeader',
|
2021-01-22 07:16:58 +08:00
|
|
|
|
2021-10-27 00:31:13 +08:00
|
|
|
addOptions() {
|
|
|
|
return {
|
|
|
|
HTMLAttributes: {},
|
|
|
|
}
|
2021-01-22 07:16:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
content: 'block+',
|
|
|
|
|
|
|
|
addAttributes() {
|
|
|
|
return {
|
|
|
|
colspan: {
|
|
|
|
default: 1,
|
|
|
|
},
|
|
|
|
rowspan: {
|
|
|
|
default: 1,
|
|
|
|
},
|
|
|
|
colwidth: {
|
|
|
|
default: null,
|
2021-03-29 02:19:17 +08:00
|
|
|
parseHTML: element => {
|
|
|
|
const colwidth = element.getAttribute('colwidth')
|
|
|
|
const value = colwidth
|
|
|
|
? [parseInt(colwidth, 10)]
|
|
|
|
: null
|
|
|
|
|
2021-09-09 05:53:44 +08:00
|
|
|
return value
|
2021-03-29 02:19:17 +08:00
|
|
|
},
|
2021-01-22 07:16:58 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tableRole: 'header_cell',
|
|
|
|
|
|
|
|
isolating: true,
|
|
|
|
|
|
|
|
parseHTML() {
|
2021-01-24 05:48:34 +08:00
|
|
|
return [
|
|
|
|
{ tag: 'th' },
|
|
|
|
]
|
2021-01-22 07:16:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|