MCPcopy Create free account
hub / github.com/AmazingAng/PolyWorld / buildPreviewRects

Function buildPreviewRects

src/hooks/usePanelDrag.ts:230–251  ·  view source on GitHub ↗
(
  metrics: ContainerMetrics,
  items: LayoutItem[],
  dragItem: LayoutItem,
  cols: number,
)

Source from the content-addressed store, hash-verified

228}
229
230function buildPreviewRects(
231 metrics: ContainerMetrics,
232 items: LayoutItem[],
233 dragItem: LayoutItem,
234 cols: number,
235) : PreviewCandidate[] {
236 return Array.from({ length: items.length + 1 }, (_, insertIndex) => {
237 const nextItems = [...items];
238 nextItems.splice(insertIndex, 0, dragItem);
239 const simulated = simulatePanels(metrics, nextItems, cols);
240 const placement = simulated[insertIndex];
241 if (!placement) return null;
242 return {
243 insertIndex,
244 previewRect: placement.rect,
245 row: placement.row,
246 col: placement.col,
247 colSpan: placement.colSpan,
248 rowSpan: placement.rowSpan,
249 };
250 }).filter((candidate): candidate is PreviewCandidate => Boolean(candidate));
251}
252
253function distanceToRect(clientX: number, clientY: number, rect: DOMRect) {
254 const dx = clientX < rect.left ? rect.left - clientX : clientX > rect.right ? clientX - rect.right : 0;

Callers 1

usePanelDragFunction · 0.85

Calls 1

simulatePanelsFunction · 0.85

Tested by

no test coverage detected