diff --git a/console/packages/editor/package.json b/console/packages/editor/package.json index 956402965d..0245ad9127 100644 --- a/console/packages/editor/package.json +++ b/console/packages/editor/package.json @@ -68,7 +68,7 @@ "@tiptap/extension-strike": "^2.1.15", "@tiptap/extension-subscript": "^2.1.15", "@tiptap/extension-superscript": "^2.1.15", - "@tiptap/extension-table": "^2.1.15", + "@tiptap/extension-table": "2.2.0-rc.8", "@tiptap/extension-table-row": "^2.1.15", "@tiptap/extension-task-item": "^2.1.15", "@tiptap/extension-task-list": "^2.1.15", diff --git a/console/packages/editor/src/extensions/table/index.ts b/console/packages/editor/src/extensions/table/index.ts index 3ad90ea66d..4586257b54 100644 --- a/console/packages/editor/src/extensions/table/index.ts +++ b/console/packages/editor/src/extensions/table/index.ts @@ -1,14 +1,19 @@ -import TiptapTable, { type TableOptions } from "@tiptap/extension-table"; +import TiptapTable, { + type TableOptions, + createColGroup, +} from "@tiptap/extension-table"; import { isActive, type Editor, type Range, + mergeAttributes, isNodeActive, } from "@/tiptap/vue-3"; -import type { - Node as ProseMirrorNode, - NodeView, - EditorState, +import { + type Node as ProseMirrorNode, + type NodeView, + type EditorState, + type DOMOutputSpec, } from "@/tiptap/pm"; import TableCell from "./table-cell"; import TableRow from "./table-row"; @@ -419,6 +424,30 @@ const Table = TiptapTable.extend({ "Mod-Backspace": () => handleBackspace(), }; }, + + renderHTML({ node, HTMLAttributes }) { + const { colgroup, tableWidth, tableMinWidth } = createColGroup( + node, + this.options.cellMinWidth + ); + + const table: DOMOutputSpec = [ + "div", + { style: "overflow-x: auto; overflow-y: hidden;" }, + [ + "table", + mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { + style: tableWidth + ? `width: ${tableWidth}` + : `minWidth: ${tableMinWidth}`, + }), + colgroup, + ["tbody", 0], + ], + ]; + + return table; + }, }).configure({ resizable: true }); export default Table; diff --git a/console/pnpm-lock.yaml b/console/pnpm-lock.yaml index 9881ade70d..11df834c16 100644 --- a/console/pnpm-lock.yaml +++ b/console/pnpm-lock.yaml @@ -524,8 +524,8 @@ importers: specifier: ^2.1.15 version: 2.1.15(@tiptap/core@2.1.15) '@tiptap/extension-table': - specifier: ^2.1.15 - version: 2.1.15(@tiptap/core@2.1.15)(@tiptap/pm@2.1.15) + specifier: 2.2.0-rc.8 + version: 2.2.0-rc.8(@tiptap/core@2.1.15)(@tiptap/pm@2.1.15) '@tiptap/extension-table-row': specifier: ^2.1.15 version: 2.1.15(@tiptap/core@2.1.15) @@ -6039,8 +6039,8 @@ packages: '@tiptap/core': 2.1.15(@tiptap/pm@2.1.15) dev: false - /@tiptap/extension-table@2.1.15(@tiptap/core@2.1.15)(@tiptap/pm@2.1.15): - resolution: {integrity: sha512-7mEytHrY7eLaJHyHNwC5l7IXHMTBF2HydCX/sF5Z3oNh63bCGWo/5NjvW6fjJd9B6KQ5yH5ec+gO7uPaf/555w==} + /@tiptap/extension-table@2.2.0-rc.8(@tiptap/core@2.1.15)(@tiptap/pm@2.1.15): + resolution: {integrity: sha512-o/w+vVG0DIXU6Aal5OXJC/GHwkfazJZ8egBV1dHKyXV2hV4FAmAYpcGQyCpixtZxMTMVq3Ck1kFrbU9v5CqUQQ==} peerDependencies: '@tiptap/core': ^2.0.0 '@tiptap/pm': ^2.0.0