Skip to content

Commit

Permalink
pref: add additional attributes and colgroup for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Jan 11, 2024
1 parent 5f0ac9f commit 9ae5f28
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions console/packages/editor/src/extensions/table/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import TiptapTable, { type TableOptions } from "@tiptap/extension-table";
import { isActive, type Editor, type Range } from "@/tiptap/vue-3";
import type {
Node as ProseMirrorNode,
NodeView,
EditorState,
import TiptapTable, {
type TableOptions,
createColGroup,
} from "@tiptap/extension-table";
import {
isActive,
type Editor,
type Range,
mergeAttributes,
} from "@/tiptap/vue-3";
import {
type Node as ProseMirrorNode,
type NodeView,
type EditorState,
type DOMOutputSpec,
} from "@/tiptap/pm";
import TableCell from "./table-cell";
import TableRow from "./table-row";
Expand Down Expand Up @@ -375,6 +384,26 @@ const Table = TiptapTable.extend<ExtensionOptions & TableOptions>({
},
};
},

renderHTML({ node, HTMLAttributes }) {
const { colgroup, tableWidth, tableMinWidth } = createColGroup(
node,
this.options.cellMinWidth
);

const table: DOMOutputSpec = [
"table",
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
style: tableWidth
? `width: ${tableWidth}`
: `minWidth: ${tableMinWidth}`,
}),
colgroup,
["tbody", 0],
];

return table;
},
}).configure({ resizable: true });

export default Table;

0 comments on commit 9ae5f28

Please sign in to comment.