From 5cb04c2d80cbda7674f42e753c29fbdf0ffea691 Mon Sep 17 00:00:00 2001 From: zjhong Date: Fri, 25 Sep 2026 14:22:13 +0800 Subject: [PATCH] fix: preserve responsive vertical positions --- .../src/components/GridCanvas.tsx | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/thingsvis-ui/src/components/GridCanvas.tsx b/packages/thingsvis-ui/src/components/GridCanvas.tsx index 385aa3e3..b8bb2a4c 100644 --- a/packages/thingsvis-ui/src/components/GridCanvas.tsx +++ b/packages/thingsvis-ui/src/components/GridCanvas.tsx @@ -7,7 +7,6 @@ import React, { } from 'react'; import { useSyncExternalStore } from 'react'; import type { KernelStore, KernelState, NodeState } from '@thingsvis/kernel'; -import { GridSystem } from '@thingsvis/kernel'; import type { GridSettings, WidgetMainModule, WidgetOverlayContext } from '@thingsvis/schema'; import { validateCanvasTheme } from '@thingsvis/schema'; import type { ActionRuntime } from '../engine/executeActions'; @@ -446,8 +445,7 @@ export const GridCanvas: React.FC = ({ // ── Responsive display map: scale + compact to prevent overlaps ─────────── // When effectiveCols < maxCols (a breakpoint fired), we: // 1. Proportionally scale each item's x/w from maxCols → effectiveCols - // 2. Run GridSystem.compact() to resolve any resulting overlaps by - // pushing colliding items down — producing true responsive reflow. + // 2. Preserve authored rows and push only colliding items down. // At the design-time column count, items render at their authored positions. const maxCols = effectiveSettings.cols; // design-time column count (e.g. 24) @@ -479,8 +477,26 @@ export const GridCanvas: React.FC = ({ return { id: node.id, x: s.x, y: s.y, w: s.w, h: s.h }; }); - const result = GridSystem.compact(scaledItems, effectiveCols); - return Object.fromEntries(result.items.map((item) => [item.id, item])); + const orderedItems = [...scaledItems].sort((a, b) => a.y - b.y || a.x - b.x); + const compactedItems: typeof scaledItems = []; + + for (const item of orderedItems) { + let y = item.y; + while ( + compactedItems.some( + (placed) => + item.x < placed.x + placed.w && + placed.x < item.x + item.w && + y < placed.y + placed.h && + placed.y < y + item.h, + ) + ) { + y++; + } + compactedItems.push({ ...item, y }); + } + + return Object.fromEntries(compactedItems.map((item) => [item.id, item])); }, [effectiveCols, maxCols, nodes]); /** Total canvas rows after responsive reflow (used for canvasMinH). */