2023-08-31 08:11:41 +00:00
|
|
|
import { TableCell } from "@tiptap/extension-table-cell";
|
|
|
|
|
|
|
|
export const CustomTableCell = TableCell.extend({
|
|
|
|
addAttributes() {
|
|
|
|
return {
|
|
|
|
...this.parent?.(),
|
|
|
|
isHeader: {
|
|
|
|
default: false,
|
2023-09-03 13:20:30 +00:00
|
|
|
parseHTML: (element) => {
|
|
|
|
isHeader: element.tagName === "TD";
|
|
|
|
},
|
|
|
|
renderHTML: (attributes) => {
|
|
|
|
tag: attributes.isHeader ? "th" : "td";
|
|
|
|
},
|
2023-08-31 08:11:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
if (HTMLAttributes.isHeader) {
|
|
|
|
return [
|
|
|
|
"th",
|
|
|
|
{
|
|
|
|
...HTMLAttributes,
|
|
|
|
class: `relative ${HTMLAttributes.class}`,
|
|
|
|
},
|
2023-09-03 13:20:30 +00:00
|
|
|
["span", { class: "absolute top-0 right-0" }],
|
2023-08-31 08:11:41 +00:00
|
|
|
0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return ["td", HTMLAttributes, 0];
|
|
|
|
},
|
|
|
|
});
|