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

Function compact

src/core/compactors.ts:182–206  ·  view source on GitHub ↗
(layout: Layout, _cols: number)

Source from the content-addressed store, hash-verified

180 allowOverlap: false,
181
182 compact(layout: Layout, _cols: number): Layout {
183 const compareWith = getStatics(layout);
184 let maxY = bottom(compareWith);
185 const sorted = sortLayoutItemsByRowCol(layout);
186 const out: LayoutItem[] = new Array(layout.length);
187
188 for (let i = 0; i < sorted.length; i++) {
189 const sortedItem = sorted[i];
190 if (sortedItem === undefined) continue;
191
192 let l = cloneLayoutItem(sortedItem);
193
194 if (!l.static) {
195 l = compactItemVertical(compareWith, l, sorted, maxY);
196 maxY = Math.max(maxY, l.y + l.h);
197 compareWith.push(l);
198 }
199
200 const originalIndex = layout.indexOf(sortedItem);
201 out[originalIndex] = l;
202 l.moved = false;
203 }
204
205 return out;
206 }
207};
208
209// ============================================================================

Callers

nothing calls this directly

Calls 8

bottomFunction · 0.85
sortLayoutItemsByRowColFunction · 0.85
cloneLayoutItemFunction · 0.85
compactItemVerticalFunction · 0.85
sortLayoutItemsByColRowFunction · 0.85
compactItemHorizontalFunction · 0.85
cloneLayoutFunction · 0.85
getStaticsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…