feat(dees-dashboardgrid): enhance drag-and-drop functionality with preview state and previous position tracking

This commit is contained in:
2025-09-18 08:05:41 +00:00
parent 6f9c92a866
commit 0de4283fae
4 changed files with 110 additions and 20 deletions

View File

@@ -129,6 +129,7 @@ export const resolveWidgetPlacement = (
widgetId: string,
next: { x: number; y: number; w?: number; h?: number },
columns: number,
previousPosition?: DashboardLayoutItem,
): PlacementResult | null => {
const sourceWidgets = cloneWidgets(widgets);
const moving = sourceWidgets.find(widget => widget.id === widgetId);
@@ -160,8 +161,9 @@ export const resolveWidgetPlacement = (
if (!other.locked && !other.noMove && other.w === moving.w && other.h === moving.h) {
const otherClone = sourceWidgets.find(widget => widget.id === other.id);
if (otherClone) {
otherClone.x = original.x;
otherClone.y = original.y;
const swapTarget = previousPosition ?? original;
otherClone.x = swapTarget.x;
otherClone.y = swapTarget.y;
return { widgets: sourceWidgets, movedWidgets: [moving.id, otherClone.id], swappedWith: otherClone.id };
}
}