From fd79d5e4fa56a90ceefabd624937658cb6e7008f Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 17 Mar 2026 19:43:00 +0100 Subject: [PATCH] fix: prevent grid table overflow when union columns exceed zone bbox When union columns from multiple content zones are applied, column boundaries can span wider than any single zone's bbox. Using zone.bbox_px.w as the scale reference caused the total scaled width to exceed the container, pushing the table off-screen. Now uses the actual total column width sum as the scale reference, guaranteeing columns always fit within the container. Co-Authored-By: Claude Opus 4.6 --- admin-lehrer/components/grid-editor/GridTable.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/admin-lehrer/components/grid-editor/GridTable.tsx b/admin-lehrer/components/grid-editor/GridTable.tsx index e76c979..a5dfe82 100644 --- a/admin-lehrer/components/grid-editor/GridTable.tsx +++ b/admin-lehrer/components/grid-editor/GridTable.tsx @@ -52,13 +52,18 @@ export function GridTable({ // ---------------------------------------------------------------- // Compute column widths from OCR measurements // ---------------------------------------------------------------- - const zoneWidthPx = zone.bbox_px.w || layoutMetrics?.page_width_px || 1 - const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1 - - // Column widths in original pixels, then scaled to container + // Use the actual total column span as reference width — NOT zone.bbox_px.w. + // When union columns are applied across content zones, column boundaries + // can extend beyond the zone's bbox, causing overflow if we scale by + // the smaller zone width. const [colWidthOverrides, setColWidthOverrides] = useState(null) const columnWidthsPx = zone.columns.map((col) => col.x_max_px - col.x_min_px) + const totalColWidthPx = columnWidthsPx.reduce((sum, w) => sum + w, 0) + const zoneWidthPx = totalColWidthPx > 0 + ? totalColWidthPx + : (zone.bbox_px.w || layoutMetrics?.page_width_px || 1) + const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1 const effectiveColWidths = (colWidthOverrides ?? columnWidthsPx).map( (w) => Math.max(MIN_COL_WIDTH, w * scale),