@sguisse/react-grid-layout 2.2.3-sguisse.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/css/styles.css +120 -0
- package/dist/ResponsiveGridLayout-B_6TXsWM.d.ts +80 -0
- package/dist/ResponsiveGridLayout-Bin5MBC3.d.mts +80 -0
- package/dist/calculate-CoBSgofg.d.mts +196 -0
- package/dist/calculate-K0IBpu53.d.ts +196 -0
- package/dist/chunk-7BT7XXIT.js +74 -0
- package/dist/chunk-G3PAJYGP.mjs +72 -0
- package/dist/chunk-ITLZ7N2R.mjs +456 -0
- package/dist/chunk-J4LTYI7L.js +485 -0
- package/dist/chunk-KKV4ZCG4.mjs +583 -0
- package/dist/chunk-LQOPWRJR.js +623 -0
- package/dist/chunk-O3KX3VYW.mjs +1 -0
- package/dist/chunk-STBCV65G.js +3159 -0
- package/dist/chunk-UZL6BMXQ.mjs +3146 -0
- package/dist/chunk-ZJHF4QM5.js +2 -0
- package/dist/core.d.mts +160 -0
- package/dist/core.d.ts +160 -0
- package/dist/core.js +268 -0
- package/dist/core.mjs +3 -0
- package/dist/extras.d.mts +208 -0
- package/dist/extras.d.ts +208 -0
- package/dist/extras.js +388 -0
- package/dist/extras.mjs +380 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +152 -0
- package/dist/index.mjs +5 -0
- package/dist/legacy.d.mts +163 -0
- package/dist/legacy.d.ts +163 -0
- package/dist/legacy.js +331 -0
- package/dist/legacy.mjs +319 -0
- package/dist/position-BeP60S5h.d.ts +316 -0
- package/dist/position-CeG3Nr4z.d.mts +316 -0
- package/dist/react.d.mts +214 -0
- package/dist/react.d.ts +214 -0
- package/dist/react.js +94 -0
- package/dist/react.mjs +5 -0
- package/dist/responsive-D4zBXLkH.d.ts +145 -0
- package/dist/responsive-DQi_9rBi.d.mts +145 -0
- package/dist/types-Dbg8jAWj.d.mts +458 -0
- package/dist/types-Dbg8jAWj.d.ts +458 -0
- package/index-dev.js +23 -0
- package/index.js +8 -0
- package/package.json +238 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/core/calculate.ts
|
|
11
|
+
function calcGridColWidth(positionParams) {
|
|
12
|
+
const { margin, containerPadding, containerWidth, cols } = positionParams;
|
|
13
|
+
return (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols;
|
|
14
|
+
}
|
|
15
|
+
function getGridPixelSteps(positionParams) {
|
|
16
|
+
const { margin, rowHeight } = positionParams;
|
|
17
|
+
return {
|
|
18
|
+
stepX: calcGridColWidth(positionParams) + margin[0],
|
|
19
|
+
stepY: rowHeight + margin[1]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function calcGridItemWHPx(gridUnits, colOrRowSize, marginPx) {
|
|
23
|
+
if (!Number.isFinite(gridUnits)) return gridUnits;
|
|
24
|
+
return Math.round(
|
|
25
|
+
colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function calcGridItemPosition(positionParams, x, y, w, h, dragPosition, resizePosition) {
|
|
29
|
+
const { margin, containerPadding, rowHeight } = positionParams;
|
|
30
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
31
|
+
let width;
|
|
32
|
+
let height;
|
|
33
|
+
let top;
|
|
34
|
+
let left;
|
|
35
|
+
if (resizePosition) {
|
|
36
|
+
width = Math.round(resizePosition.width);
|
|
37
|
+
height = Math.round(resizePosition.height);
|
|
38
|
+
} else {
|
|
39
|
+
width = calcGridItemWHPx(w, colWidth, margin[0]);
|
|
40
|
+
height = calcGridItemWHPx(h, rowHeight, margin[1]);
|
|
41
|
+
}
|
|
42
|
+
if (dragPosition) {
|
|
43
|
+
top = Math.round(dragPosition.top);
|
|
44
|
+
left = Math.round(dragPosition.left);
|
|
45
|
+
} else if (resizePosition) {
|
|
46
|
+
top = Math.round(resizePosition.top);
|
|
47
|
+
left = Math.round(resizePosition.left);
|
|
48
|
+
} else {
|
|
49
|
+
top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
|
|
50
|
+
left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
|
|
51
|
+
}
|
|
52
|
+
if (!dragPosition && !resizePosition) {
|
|
53
|
+
if (Number.isFinite(w)) {
|
|
54
|
+
const siblingLeft = Math.round(
|
|
55
|
+
(colWidth + margin[0]) * (x + w) + containerPadding[0]
|
|
56
|
+
);
|
|
57
|
+
const actualMarginRight = siblingLeft - left - width;
|
|
58
|
+
if (actualMarginRight !== margin[0]) {
|
|
59
|
+
width += actualMarginRight - margin[0];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (Number.isFinite(h)) {
|
|
63
|
+
const siblingTop = Math.round(
|
|
64
|
+
(rowHeight + margin[1]) * (y + h) + containerPadding[1]
|
|
65
|
+
);
|
|
66
|
+
const actualMarginBottom = siblingTop - top - height;
|
|
67
|
+
if (actualMarginBottom !== margin[1]) {
|
|
68
|
+
height += actualMarginBottom - margin[1];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { top, left, width, height };
|
|
73
|
+
}
|
|
74
|
+
function calcXY(positionParams, top, left, w, h) {
|
|
75
|
+
const { margin, containerPadding, cols, rowHeight, maxRows } = positionParams;
|
|
76
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
77
|
+
let x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
|
|
78
|
+
let y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
|
|
79
|
+
x = clamp(x, 0, cols - w);
|
|
80
|
+
y = clamp(y, 0, maxRows - h);
|
|
81
|
+
return { x, y };
|
|
82
|
+
}
|
|
83
|
+
function calcXYRaw(positionParams, top, left) {
|
|
84
|
+
const { margin, containerPadding, rowHeight } = positionParams;
|
|
85
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
86
|
+
const x = Math.round((left - containerPadding[0]) / (colWidth + margin[0]));
|
|
87
|
+
const y = Math.round((top - containerPadding[1]) / (rowHeight + margin[1]));
|
|
88
|
+
return { x, y };
|
|
89
|
+
}
|
|
90
|
+
function calcWH(positionParams, width, height, x, y, handle) {
|
|
91
|
+
const { margin, maxRows, cols, rowHeight } = positionParams;
|
|
92
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
93
|
+
const w = Math.round((width + margin[0]) / (colWidth + margin[0]));
|
|
94
|
+
const h = Math.round((height + margin[1]) / (rowHeight + margin[1]));
|
|
95
|
+
let _w = clamp(w, 0, cols - x);
|
|
96
|
+
let _h = clamp(h, 0, maxRows - y);
|
|
97
|
+
if (handle === "sw" || handle === "w" || handle === "nw") {
|
|
98
|
+
_w = clamp(w, 0, cols);
|
|
99
|
+
}
|
|
100
|
+
if (handle === "nw" || handle === "n" || handle === "ne") {
|
|
101
|
+
_h = clamp(h, 0, maxRows);
|
|
102
|
+
}
|
|
103
|
+
return { w: _w, h: _h };
|
|
104
|
+
}
|
|
105
|
+
function calcWHRaw(positionParams, width, height) {
|
|
106
|
+
const { margin, rowHeight } = positionParams;
|
|
107
|
+
const colWidth = calcGridColWidth(positionParams);
|
|
108
|
+
const w = Math.max(
|
|
109
|
+
1,
|
|
110
|
+
Math.round((width + margin[0]) / (colWidth + margin[0]))
|
|
111
|
+
);
|
|
112
|
+
const h = Math.max(
|
|
113
|
+
1,
|
|
114
|
+
Math.round((height + margin[1]) / (rowHeight + margin[1]))
|
|
115
|
+
);
|
|
116
|
+
return { w, h };
|
|
117
|
+
}
|
|
118
|
+
function clamp(num, lowerBound, upperBound) {
|
|
119
|
+
return Math.max(Math.min(num, upperBound), lowerBound);
|
|
120
|
+
}
|
|
121
|
+
function calcGridCellDimensions(config) {
|
|
122
|
+
const {
|
|
123
|
+
width,
|
|
124
|
+
cols,
|
|
125
|
+
rowHeight,
|
|
126
|
+
margin = [10, 10],
|
|
127
|
+
containerPadding
|
|
128
|
+
} = config;
|
|
129
|
+
const padding = containerPadding ?? margin;
|
|
130
|
+
const cellWidth = (width - padding[0] * 2 - margin[0] * (cols - 1)) / cols;
|
|
131
|
+
const cellHeight = rowHeight;
|
|
132
|
+
return {
|
|
133
|
+
cellWidth,
|
|
134
|
+
cellHeight,
|
|
135
|
+
offsetX: padding[0],
|
|
136
|
+
offsetY: padding[1],
|
|
137
|
+
gapX: margin[0],
|
|
138
|
+
gapY: margin[1],
|
|
139
|
+
cols,
|
|
140
|
+
containerWidth: width
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/core/collision.ts
|
|
145
|
+
function getCollisionBounds(item) {
|
|
146
|
+
return {
|
|
147
|
+
left: item.x,
|
|
148
|
+
right: item.x + item.w,
|
|
149
|
+
top: item.y,
|
|
150
|
+
bottom: item.y + item.h
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function collidesBounds(bounds, item) {
|
|
154
|
+
if (bounds.right <= item.x) return false;
|
|
155
|
+
if (bounds.left >= item.x + item.w) return false;
|
|
156
|
+
if (bounds.bottom <= item.y) return false;
|
|
157
|
+
if (bounds.top >= item.y + item.h) return false;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
function collides(l1, l2) {
|
|
161
|
+
if (l1.i === l2.i) return false;
|
|
162
|
+
return collidesBounds(getCollisionBounds(l1), l2);
|
|
163
|
+
}
|
|
164
|
+
function getFirstCollision(layout, layoutItem) {
|
|
165
|
+
for (let i = 0; i < layout.length; i++) {
|
|
166
|
+
const item = layout[i];
|
|
167
|
+
if (item !== void 0 && collides(item, layoutItem)) {
|
|
168
|
+
return item;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
function getAllCollisions(layout, layoutItem) {
|
|
174
|
+
return layout.filter((l) => collides(l, layoutItem));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/core/sort.ts
|
|
178
|
+
function sortLayoutItems(layout, compactType) {
|
|
179
|
+
if (compactType === "horizontal") {
|
|
180
|
+
return sortLayoutItemsByColRow(layout);
|
|
181
|
+
}
|
|
182
|
+
if (compactType === "vertical") {
|
|
183
|
+
return sortLayoutItemsByRowCol(layout);
|
|
184
|
+
}
|
|
185
|
+
if (compactType === "wrap") {
|
|
186
|
+
return sortLayoutItemsByRowCol(layout);
|
|
187
|
+
}
|
|
188
|
+
return [...layout];
|
|
189
|
+
}
|
|
190
|
+
function sortLayoutItemsByRowCol(layout) {
|
|
191
|
+
return [...layout].sort((a, b) => {
|
|
192
|
+
if (a.y !== b.y) {
|
|
193
|
+
return a.y - b.y;
|
|
194
|
+
}
|
|
195
|
+
return a.x - b.x;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function sortLayoutItemsByColRow(layout) {
|
|
199
|
+
return [...layout].sort((a, b) => {
|
|
200
|
+
if (a.x !== b.x) {
|
|
201
|
+
return a.x - b.x;
|
|
202
|
+
}
|
|
203
|
+
return a.y - b.y;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/core/layout.ts
|
|
208
|
+
function bottom(layout) {
|
|
209
|
+
let max = 0;
|
|
210
|
+
for (let i = 0; i < layout.length; i++) {
|
|
211
|
+
const item = layout[i];
|
|
212
|
+
if (item !== void 0) {
|
|
213
|
+
const bottomY = item.y + item.h;
|
|
214
|
+
if (bottomY > max) max = bottomY;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return max;
|
|
218
|
+
}
|
|
219
|
+
function getLayoutItem(layout, id) {
|
|
220
|
+
for (let i = 0; i < layout.length; i++) {
|
|
221
|
+
const item = layout[i];
|
|
222
|
+
if (item !== void 0 && item.i === id) {
|
|
223
|
+
return item;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
function getStatics(layout) {
|
|
229
|
+
return layout.filter((l) => l.static === true);
|
|
230
|
+
}
|
|
231
|
+
function cloneLayoutItem(layoutItem) {
|
|
232
|
+
return {
|
|
233
|
+
i: layoutItem.i,
|
|
234
|
+
x: layoutItem.x,
|
|
235
|
+
y: layoutItem.y,
|
|
236
|
+
w: layoutItem.w,
|
|
237
|
+
h: layoutItem.h,
|
|
238
|
+
minW: layoutItem.minW,
|
|
239
|
+
maxW: layoutItem.maxW,
|
|
240
|
+
minH: layoutItem.minH,
|
|
241
|
+
maxH: layoutItem.maxH,
|
|
242
|
+
moved: Boolean(layoutItem.moved),
|
|
243
|
+
static: Boolean(layoutItem.static),
|
|
244
|
+
isDraggable: layoutItem.isDraggable,
|
|
245
|
+
isResizable: layoutItem.isResizable,
|
|
246
|
+
resizeHandles: layoutItem.resizeHandles,
|
|
247
|
+
constraints: layoutItem.constraints,
|
|
248
|
+
isBounded: layoutItem.isBounded
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function cloneLayout(layout) {
|
|
252
|
+
function createLayoutSnapshot(l) {
|
|
253
|
+
const ids = [];
|
|
254
|
+
for (let i = 0; i < l.length; i++) {
|
|
255
|
+
const item = l[i];
|
|
256
|
+
if (item !== void 0) {
|
|
257
|
+
ids.push(item.i);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { itemCount: l.length, bottom: bottom(l), ids };
|
|
261
|
+
}
|
|
262
|
+
void createLayoutSnapshot(layout);
|
|
263
|
+
const newLayout = new Array(layout.length);
|
|
264
|
+
for (let i = 0; i < layout.length; i++) {
|
|
265
|
+
const item = layout[i];
|
|
266
|
+
if (item !== void 0) {
|
|
267
|
+
newLayout[i] = cloneLayoutItem(item);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return newLayout;
|
|
271
|
+
}
|
|
272
|
+
function modifyLayout(layout, layoutItem) {
|
|
273
|
+
const newLayout = new Array(layout.length);
|
|
274
|
+
for (let i = 0; i < layout.length; i++) {
|
|
275
|
+
const item = layout[i];
|
|
276
|
+
if (item !== void 0) {
|
|
277
|
+
if (layoutItem.i === item.i) {
|
|
278
|
+
newLayout[i] = layoutItem;
|
|
279
|
+
} else {
|
|
280
|
+
newLayout[i] = item;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return newLayout;
|
|
285
|
+
}
|
|
286
|
+
function withLayoutItem(layout, itemKey, cb) {
|
|
287
|
+
let item = getLayoutItem(layout, itemKey);
|
|
288
|
+
if (!item) {
|
|
289
|
+
return [[...layout], null];
|
|
290
|
+
}
|
|
291
|
+
item = cb(cloneLayoutItem(item));
|
|
292
|
+
const newLayout = modifyLayout(layout, item);
|
|
293
|
+
return [newLayout, item];
|
|
294
|
+
}
|
|
295
|
+
function correctBounds(layout, bounds) {
|
|
296
|
+
const collidesWith = getStatics(layout);
|
|
297
|
+
for (let i = 0; i < layout.length; i++) {
|
|
298
|
+
const l = layout[i];
|
|
299
|
+
if (l === void 0) continue;
|
|
300
|
+
if (l.x + l.w > bounds.cols) {
|
|
301
|
+
l.x = bounds.cols - l.w;
|
|
302
|
+
}
|
|
303
|
+
if (l.x < 0) {
|
|
304
|
+
l.x = 0;
|
|
305
|
+
l.w = bounds.cols;
|
|
306
|
+
}
|
|
307
|
+
if (!l.static) {
|
|
308
|
+
collidesWith.push(l);
|
|
309
|
+
} else {
|
|
310
|
+
while (getFirstCollision(collidesWith, l)) {
|
|
311
|
+
l.y++;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return layout;
|
|
316
|
+
}
|
|
317
|
+
function moveElement(layout, l, x, y, isUserAction, preventCollision, compactType, cols, allowOverlap) {
|
|
318
|
+
if (l.static && l.isDraggable !== true) {
|
|
319
|
+
return [...layout];
|
|
320
|
+
}
|
|
321
|
+
if (l.y === y && l.x === x) {
|
|
322
|
+
return [...layout];
|
|
323
|
+
}
|
|
324
|
+
const oldX = l.x;
|
|
325
|
+
const oldY = l.y;
|
|
326
|
+
if (typeof x === "number") l.x = x;
|
|
327
|
+
if (typeof y === "number") l.y = y;
|
|
328
|
+
l.moved = true;
|
|
329
|
+
let sorted = sortLayoutItems(layout, compactType);
|
|
330
|
+
const movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false;
|
|
331
|
+
if (movingUp) {
|
|
332
|
+
sorted = sorted.reverse();
|
|
333
|
+
}
|
|
334
|
+
const collisions = getAllCollisions(sorted, l);
|
|
335
|
+
const hasCollisions = collisions.length > 0;
|
|
336
|
+
if (hasCollisions && allowOverlap) {
|
|
337
|
+
return cloneLayout(layout);
|
|
338
|
+
}
|
|
339
|
+
if (hasCollisions && preventCollision) {
|
|
340
|
+
l.x = oldX;
|
|
341
|
+
l.y = oldY;
|
|
342
|
+
l.moved = false;
|
|
343
|
+
return layout;
|
|
344
|
+
}
|
|
345
|
+
let resultLayout = [...layout];
|
|
346
|
+
for (let i = 0; i < collisions.length; i++) {
|
|
347
|
+
const collision = collisions[i];
|
|
348
|
+
if (collision === void 0) continue;
|
|
349
|
+
if (collision.moved) continue;
|
|
350
|
+
if (collision.static) {
|
|
351
|
+
resultLayout = moveElementAwayFromCollision(
|
|
352
|
+
resultLayout,
|
|
353
|
+
collision,
|
|
354
|
+
l,
|
|
355
|
+
isUserAction,
|
|
356
|
+
compactType);
|
|
357
|
+
} else {
|
|
358
|
+
resultLayout = moveElementAwayFromCollision(
|
|
359
|
+
resultLayout,
|
|
360
|
+
l,
|
|
361
|
+
collision,
|
|
362
|
+
isUserAction,
|
|
363
|
+
compactType);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return resultLayout;
|
|
367
|
+
}
|
|
368
|
+
function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, compactType, cols) {
|
|
369
|
+
const compactH = compactType === "horizontal";
|
|
370
|
+
const compactV = compactType === "vertical";
|
|
371
|
+
const preventCollision = collidesWith.static;
|
|
372
|
+
if (isUserAction) {
|
|
373
|
+
isUserAction = false;
|
|
374
|
+
const fakeItem = {
|
|
375
|
+
x: compactH ? Math.max(collidesWith.x - itemToMove.w, 0) : itemToMove.x,
|
|
376
|
+
y: compactV ? Math.max(collidesWith.y - itemToMove.h, 0) : itemToMove.y,
|
|
377
|
+
w: itemToMove.w,
|
|
378
|
+
h: itemToMove.h,
|
|
379
|
+
i: "-1"
|
|
380
|
+
};
|
|
381
|
+
const firstCollision = getFirstCollision(layout, fakeItem);
|
|
382
|
+
const collisionNorth = firstCollision !== void 0 && firstCollision.y + firstCollision.h > collidesWith.y;
|
|
383
|
+
const collisionWest = firstCollision !== void 0 && collidesWith.x + collidesWith.w > firstCollision.x;
|
|
384
|
+
if (!firstCollision) {
|
|
385
|
+
return moveElement(
|
|
386
|
+
layout,
|
|
387
|
+
itemToMove,
|
|
388
|
+
compactH ? fakeItem.x : void 0,
|
|
389
|
+
compactV ? fakeItem.y : void 0,
|
|
390
|
+
isUserAction,
|
|
391
|
+
preventCollision,
|
|
392
|
+
compactType);
|
|
393
|
+
}
|
|
394
|
+
if (collisionNorth && compactV) {
|
|
395
|
+
return moveElement(
|
|
396
|
+
layout,
|
|
397
|
+
itemToMove,
|
|
398
|
+
void 0,
|
|
399
|
+
itemToMove.y + 1,
|
|
400
|
+
isUserAction,
|
|
401
|
+
preventCollision,
|
|
402
|
+
compactType);
|
|
403
|
+
}
|
|
404
|
+
if (collisionNorth && compactType === null) {
|
|
405
|
+
collidesWith.y = itemToMove.y;
|
|
406
|
+
itemToMove.y = itemToMove.y + itemToMove.h;
|
|
407
|
+
return [...layout];
|
|
408
|
+
}
|
|
409
|
+
if (collisionWest && compactH) {
|
|
410
|
+
return moveElement(
|
|
411
|
+
layout,
|
|
412
|
+
collidesWith,
|
|
413
|
+
itemToMove.x,
|
|
414
|
+
void 0,
|
|
415
|
+
isUserAction,
|
|
416
|
+
preventCollision,
|
|
417
|
+
compactType);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const newX = compactH ? itemToMove.x + 1 : void 0;
|
|
421
|
+
const newY = compactV ? itemToMove.y + 1 : void 0;
|
|
422
|
+
if (newX === void 0 && newY === void 0) {
|
|
423
|
+
return [...layout];
|
|
424
|
+
}
|
|
425
|
+
return moveElement(
|
|
426
|
+
layout,
|
|
427
|
+
itemToMove,
|
|
428
|
+
newX,
|
|
429
|
+
newY,
|
|
430
|
+
isUserAction,
|
|
431
|
+
preventCollision,
|
|
432
|
+
compactType);
|
|
433
|
+
}
|
|
434
|
+
function validateLayout(layout, contextName = "Layout") {
|
|
435
|
+
const requiredProps = ["x", "y", "w", "h"];
|
|
436
|
+
if (!Array.isArray(layout)) {
|
|
437
|
+
throw new Error(`${contextName} must be an array!`);
|
|
438
|
+
}
|
|
439
|
+
for (let i = 0; i < layout.length; i++) {
|
|
440
|
+
const item = layout[i];
|
|
441
|
+
if (item === void 0) continue;
|
|
442
|
+
for (const key of requiredProps) {
|
|
443
|
+
const value = item[key];
|
|
444
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
445
|
+
throw new Error(
|
|
446
|
+
`ReactGridLayout: ${contextName}[${i}].${key} must be a number! Received: ${String(value)} (${typeof value})`
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (item.i !== void 0 && typeof item.i !== "string") {
|
|
451
|
+
throw new Error(
|
|
452
|
+
`ReactGridLayout: ${contextName}[${i}].i must be a string! Received: ${String(item.i)} (${typeof item.i})`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
exports.__require = __require;
|
|
459
|
+
exports.bottom = bottom;
|
|
460
|
+
exports.calcGridCellDimensions = calcGridCellDimensions;
|
|
461
|
+
exports.calcGridColWidth = calcGridColWidth;
|
|
462
|
+
exports.calcGridItemPosition = calcGridItemPosition;
|
|
463
|
+
exports.calcGridItemWHPx = calcGridItemWHPx;
|
|
464
|
+
exports.calcWH = calcWH;
|
|
465
|
+
exports.calcWHRaw = calcWHRaw;
|
|
466
|
+
exports.calcXY = calcXY;
|
|
467
|
+
exports.calcXYRaw = calcXYRaw;
|
|
468
|
+
exports.clamp = clamp;
|
|
469
|
+
exports.cloneLayout = cloneLayout;
|
|
470
|
+
exports.cloneLayoutItem = cloneLayoutItem;
|
|
471
|
+
exports.collides = collides;
|
|
472
|
+
exports.correctBounds = correctBounds;
|
|
473
|
+
exports.getAllCollisions = getAllCollisions;
|
|
474
|
+
exports.getFirstCollision = getFirstCollision;
|
|
475
|
+
exports.getGridPixelSteps = getGridPixelSteps;
|
|
476
|
+
exports.getLayoutItem = getLayoutItem;
|
|
477
|
+
exports.getStatics = getStatics;
|
|
478
|
+
exports.modifyLayout = modifyLayout;
|
|
479
|
+
exports.moveElement = moveElement;
|
|
480
|
+
exports.moveElementAwayFromCollision = moveElementAwayFromCollision;
|
|
481
|
+
exports.sortLayoutItems = sortLayoutItems;
|
|
482
|
+
exports.sortLayoutItemsByColRow = sortLayoutItemsByColRow;
|
|
483
|
+
exports.sortLayoutItemsByRowCol = sortLayoutItemsByRowCol;
|
|
484
|
+
exports.validateLayout = validateLayout;
|
|
485
|
+
exports.withLayoutItem = withLayoutItem;
|