MCPcopy Index your code
hub / github.com/react-grid-layout/react-grid-layout / compactItemHorizontal

Function compactItemHorizontal

src/core/compactors.ts:131–164  ·  view source on GitHub ↗
(
  compareWith: Layout,
  l: LayoutItem,
  cols: number,
  fullLayout: Layout
)

Source from the content-addressed store, hash-verified

129 * @returns The compacted item
130 */
131export function compactItemHorizontal(
132 compareWith: Layout,
133 l: LayoutItem,
134 cols: number,
135 fullLayout: Layout
136): LayoutItem {
137 // Correct negative positions first
138 (l as Mutable<LayoutItem>).x = Math.max(l.x, 0);
139 (l as Mutable<LayoutItem>).y = Math.max(l.y, 0);
140
141 // Move left as far as possible
142 while (l.x > 0 && !getFirstCollision(compareWith, l)) {
143 (l as Mutable<LayoutItem>).x--;
144 }
145
146 // Resolve collisions
147 let collision: LayoutItem | undefined;
148 while ((collision = getFirstCollision(compareWith, l)) !== undefined) {
149 resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x");
150
151 // Horizontal overflow: wrap to next row
152 if (l.x + l.w > cols) {
153 (l as Mutable<LayoutItem>).x = cols - l.w;
154 (l as Mutable<LayoutItem>).y++;
155
156 while (l.x > 0 && !getFirstCollision(compareWith, l)) {
157 (l as Mutable<LayoutItem>).x--;
158 }
159 }
160 }
161
162 (l as Mutable<LayoutItem>).x = Math.max(l.x, 0);
163 return l;
164}
165
166// ============================================================================
167// Vertical Compactor

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…