MCPcopy
hub / github.com/react-grid-layout/react-grid-layout / compactItemVertical

Function compactItemVertical

src/core/compactors.ts:90–116  ·  view source on GitHub ↗
(
  compareWith: Layout,
  l: LayoutItem,
  fullLayout: Layout,
  maxY: number
)

Source from the content-addressed store, hash-verified

88 * @returns The compacted item
89 */
90export function compactItemVertical(
91 compareWith: Layout,
92 l: LayoutItem,
93 fullLayout: Layout,
94 maxY: number
95): LayoutItem {
96 // Correct negative positions first
97 (l as Mutable<LayoutItem>).x = Math.max(l.x, 0);
98 (l as Mutable<LayoutItem>).y = Math.max(l.y, 0);
99
100 // Limit Y to the current bottom
101 (l as Mutable<LayoutItem>).y = Math.min(maxY, l.y);
102
103 // Move up as far as possible
104 while (l.y > 0 && !getFirstCollision(compareWith, l)) {
105 (l as Mutable<LayoutItem>).y--;
106 }
107
108 // Resolve collisions by moving down
109 let collision: LayoutItem | undefined;
110 while ((collision = getFirstCollision(compareWith, l)) !== undefined) {
111 resolveCompactionCollision(fullLayout, l, collision.y + collision.h, "y");
112 }
113
114 (l as Mutable<LayoutItem>).y = Math.max(l.y, 0);
115 return l;
116}
117
118/**
119 * Compact a single item horizontally (move left).

Callers 1

compactFunction · 0.85

Calls 2

getFirstCollisionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…