MCPcopy
hub / github.com/jbaysolutions/vue-grid-layout / compact

Function compact

src/helpers/utils.js:81–109  ·  view source on GitHub ↗
(layout: Layout, verticalCompact: Boolean, minPositions)

Source from the content-addressed store, hash-verified

79 * @return {Array} Compacted Layout.
80 */
81export function compact(layout: Layout, verticalCompact: Boolean, minPositions): Layout {
82 // Statics go in the compareWith array right away so items flow around them.
83 const compareWith = getStatics(layout);
84 // We go through the items by row and column.
85 const sorted = sortLayoutItemsByRowCol(layout);
86 // Holding for new items.
87 const out = Array(layout.length);
88
89 for (let i = 0, len = sorted.length; i < len; i++) {
90 let l = sorted[i];
91
92 // Don't move static elements
93 if (!l.static) {
94 l = compactItem(compareWith, l, verticalCompact, minPositions);
95
96 // Add to comparison array. We only collide with items before this one.
97 // Statics are already in this array.
98 compareWith.push(l);
99 }
100
101 // Add to output array to make sure they still come out in the right order.
102 out[layout.indexOf(l)] = l;
103
104 // Clear moved flag, if it exists.
105 l.moved = false;
106 }
107
108 return out;
109}
110
111/**
112 * Compact an item in the layout.

Callers 4

compactAndMoveFunction · 0.90
utils.spec.jsFile · 0.90
generateResponsiveLayoutFunction · 0.90

Calls 3

getStaticsFunction · 0.85
sortLayoutItemsByRowColFunction · 0.85
compactItemFunction · 0.85

Tested by 1

compactAndMoveFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…