fix(grids): resize drag preview when rotating mid-drag
dnd-kit pins the DragOverlay container to the activator rect measured at drag start, so pressing R while dragging left the preview at the pre-rotation footprint (a square-ish box for elongated items). Pass the live rotated dimensions through the DragOverlay style prop, which is spread after the pinned rect, in all three R-to-rotate grids: garage vehicle bay, locker, and structure storage.
This commit is contained in:
parent
0453742f32
commit
7c135cd282
3 changed files with 49 additions and 5 deletions
|
|
@ -346,6 +346,16 @@ export function GarageGrid({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Drag preview must track mid-drag rotation: dnd-kit pins the overlay
|
||||||
|
// container to the activator rect captured at drag start, so we override
|
||||||
|
// its width/height via the style prop (spread after the pinned rect).
|
||||||
|
const overlayFp = activeItem
|
||||||
|
? {
|
||||||
|
width: pendingRotated ? activeItem.height : activeItem.width,
|
||||||
|
height: pendingRotated ? activeItem.width : activeItem.height,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DndContext
|
<DndContext
|
||||||
sensors={sensors}
|
sensors={sensors}
|
||||||
|
|
@ -406,9 +416,16 @@ export function GarageGrid({
|
||||||
{canEdit && <span className="ml-auto normal-case">drag to move · R to rotate</span>}
|
{canEdit && <span className="ml-auto normal-case">drag to move · R to rotate</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DragOverlay dropAnimation={null}>
|
<DragOverlay
|
||||||
|
dropAnimation={null}
|
||||||
|
style={
|
||||||
|
overlayFp
|
||||||
|
? { width: overlayFp.width * cellSize, height: overlayFp.height * cellSize }
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
{activeItem ? (
|
{activeItem ? (
|
||||||
<div className="rounded-md border border-primary/50 bg-card/95 shadow-xl">
|
<div className="h-full w-full rounded-md border border-primary/50 bg-card/95 shadow-xl">
|
||||||
<VehicleFace item={{ ...activeItem, rotated: pendingRotated }} cellSize={cellSize} dragging />
|
<VehicleFace item={{ ...activeItem, rotated: pendingRotated }} cellSize={cellSize} dragging />
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
|
||||||
|
|
@ -544,6 +544,13 @@ export function LockerGrid({
|
||||||
onSelectItem(null);
|
onSelectItem(null);
|
||||||
}, [onSelectItem]);
|
}, [onSelectItem]);
|
||||||
|
|
||||||
|
// Drag preview must track mid-drag rotation: dnd-kit pins the overlay
|
||||||
|
// container to the activator rect captured at drag start, so we override
|
||||||
|
// its width/height via the style prop (spread after the pinned rect).
|
||||||
|
const overlayFp = activeItem
|
||||||
|
? getLockerItemFootprint(activeItem.asset, pendingRotated)
|
||||||
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DndContext
|
<DndContext
|
||||||
sensors={sensors}
|
sensors={sensors}
|
||||||
|
|
@ -635,9 +642,16 @@ export function LockerGrid({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Tactical drag overlay */}
|
{/* Tactical drag overlay */}
|
||||||
<DragOverlay dropAnimation={null}>
|
<DragOverlay
|
||||||
|
dropAnimation={null}
|
||||||
|
style={
|
||||||
|
overlayFp
|
||||||
|
? { width: overlayFp.width * cellSize, height: overlayFp.height * cellSize }
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
{activeItem && (
|
{activeItem && (
|
||||||
<div className="rounded-sm border border-primary/50 bg-card shadow-lg ring-2 ring-primary/40">
|
<div className="h-full w-full rounded-sm border border-primary/50 bg-card shadow-lg ring-2 ring-primary/40">
|
||||||
<LockerItemFace
|
<LockerItemFace
|
||||||
asset={activeItem.asset}
|
asset={activeItem.asset}
|
||||||
quantity={activeItem.quantity}
|
quantity={activeItem.quantity}
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,20 @@ export function InventoryGrid({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DragOverlay dropAnimation={null}>
|
<DragOverlay
|
||||||
|
dropAnimation={null}
|
||||||
|
style={
|
||||||
|
activeItem
|
||||||
|
? (() => {
|
||||||
|
// dnd-kit pins the overlay container to the activator rect
|
||||||
|
// from drag start; override width/height so mid-drag rotation
|
||||||
|
// resizes the preview (style is spread after the pinned rect).
|
||||||
|
const fp = getItemFootprint(activeItem.resource as Resource, pendingRotated);
|
||||||
|
return { width: fp.width * cellSize - 2, height: fp.height * cellSize - 2 };
|
||||||
|
})()
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
{activeItem && (
|
{activeItem && (
|
||||||
<DragOverlayContent item={activeItem} cellSize={cellSize} rotated={pendingRotated} />
|
<DragOverlayContent item={activeItem} cellSize={cellSize} rotated={pendingRotated} />
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue