2021-01-21 06:53:53 +08:00
|
|
|
import { Node, mergeAttributes } from '@tiptap/core'
|
2021-01-21 06:42:01 +08:00
|
|
|
|
2021-01-21 06:53:53 +08:00
|
|
|
export interface TableCellOptions {
|
2021-04-21 15:43:31 +08:00
|
|
|
HTMLAttributes: Record<string, any>,
|
2021-01-21 06:53:53 +08:00
|
|
|
}
|
2021-04-21 15:43:31 +08:00
|
|
|
|
2021-02-11 01:25:08 +08:00
|
|
|
export const TableCell = Node.create<TableCellOptions>({
|
2021-01-23 06:33:08 +08:00
|
|
|
name: 'tableCell',
|
2021-01-21 06:53:53 +08:00
|
|
|
|
2021-02-11 01:25:08 +08:00
|
|
|
defaultOptions: {
|
2021-01-21 06:53:53 +08:00
|
|
|
HTMLAttributes: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
content: 'block+',
|
2021-01-21 07:16:45 +08:00
|
|
|
|
2021-01-22 07:07:31 +08:00
|
|
|
addAttributes() {
|
|
|
|
return {
|
|
|
|
colspan: {
|
|
|
|
default: 1,
|
|
|
|
},
|
|
|
|
rowspan: {
|
|
|
|
default: 1,
|
|
|
|
},
|
|
|
|
colwidth: {
|
|
|
|
default: null,
|
2021-03-05 19:13:49 +08:00
|
|
|
parseHTML: element => {
|
|
|
|
const colwidth = element.getAttribute('colwidth')
|
|
|
|
const value = colwidth
|
|
|
|
? [parseInt(colwidth, 10)]
|
|
|
|
: null
|
|
|
|
|
|
|
|
return {
|
|
|
|
colwidth: value,
|
|
|
|
}
|
|
|
|
},
|
2021-01-22 07:07:31 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-01-21 07:16:45 +08:00
|
|
|
|
|
|
|
tableRole: 'cell',
|
|
|
|
|
2021-01-21 06:53:53 +08:00
|
|
|
isolating: true,
|
|
|
|
|
|
|
|
parseHTML() {
|
2021-01-24 05:48:34 +08:00
|
|
|
return [
|
|
|
|
{ tag: 'td' },
|
|
|
|
]
|
2021-01-21 06:53:53 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
|
|
},
|
|
|
|
|
2021-01-21 06:42:01 +08:00
|
|
|
})
|