react-grid-layout 2.0.0 → 2.1.1
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/README.md +117 -28
- package/css/styles.css +0 -1
- package/dist/{ResponsiveGridLayout-D6lFRE3f.d.mts → ResponsiveGridLayout-BkHF9YHa.d.mts} +10 -1
- package/dist/{ResponsiveGridLayout-CH4s0tKj.d.ts → ResponsiveGridLayout-CLn16-X3.d.ts} +10 -1
- package/dist/{calculate-CwYDW8na.d.mts → calculate-DsVTldEE.d.ts} +30 -2
- package/dist/{calculate-mgLpNJ5O.d.ts → calculate-DwbL1D06.d.mts} +30 -2
- package/dist/chunk-526JND3R.mjs +3 -0
- package/dist/{chunk-ZWN22PS2.mjs.map → chunk-526JND3R.mjs.map} +1 -1
- package/dist/chunk-7ELO5FRW.js +4 -0
- package/dist/{chunk-PBQSHIID.js.map → chunk-7ELO5FRW.js.map} +1 -1
- package/dist/chunk-AWM66AWF.mjs +422 -0
- package/dist/chunk-AWM66AWF.mjs.map +1 -0
- package/dist/chunk-BJFPTW5Q.js +449 -0
- package/dist/chunk-BJFPTW5Q.js.map +1 -0
- package/dist/{chunk-4HNUMWQK.mjs → chunk-FLITZMQC.mjs} +198 -311
- package/dist/chunk-FLITZMQC.mjs.map +1 -0
- package/dist/{chunk-ZCXE6SR5.mjs → chunk-LIKX67MZ.mjs} +7 -5
- package/dist/chunk-LIKX67MZ.mjs.map +1 -0
- package/dist/{chunk-R35HZZTA.mjs → chunk-PLWMASMX.mjs} +208 -90
- package/dist/chunk-PLWMASMX.mjs.map +1 -0
- package/dist/{chunk-BFTKGAP3.js → chunk-RB2IKK5B.js} +260 -142
- package/dist/chunk-RB2IKK5B.js.map +1 -0
- package/dist/{chunk-3WO4SAYB.js → chunk-WWS3M5Y3.js} +238 -355
- package/dist/chunk-WWS3M5Y3.js.map +1 -0
- package/dist/{chunk-H5KMDLY3.js → chunk-YQQYHEEG.js} +43 -41
- package/dist/chunk-YQQYHEEG.js.map +1 -0
- package/dist/core.d.mts +159 -6
- package/dist/core.d.ts +159 -6
- package/dist/core.js +145 -85
- package/dist/core.mjs +3 -3
- package/dist/extras.d.mts +133 -3
- package/dist/extras.d.ts +133 -3
- package/dist/extras.js +373 -2
- package/dist/extras.js.map +1 -1
- package/dist/extras.mjs +367 -2
- package/dist/extras.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +64 -64
- package/dist/index.mjs +5 -5
- package/dist/legacy.d.mts +2 -2
- package/dist/legacy.d.ts +2 -2
- package/dist/legacy.js +26 -25
- package/dist/legacy.js.map +1 -1
- package/dist/legacy.mjs +16 -15
- package/dist/legacy.mjs.map +1 -1
- package/dist/{position-Dk2b4ZMS.d.ts → position-CXNzFxI0.d.mts} +18 -7
- package/dist/{position-BmN1z36J.d.mts → position-Dk0FRWA9.d.ts} +18 -7
- package/dist/react.d.mts +11 -5
- package/dist/react.d.ts +11 -5
- package/dist/react.js +38 -38
- package/dist/react.mjs +5 -5
- package/dist/{responsive-CJxefsYw.d.mts → responsive-BB5d98xz.d.mts} +1 -1
- package/dist/{responsive-C4L1ESlm.d.ts → responsive-BXI-GCXG.d.ts} +1 -1
- package/dist/{types-Cxf4nHNr.d.mts → types-CokovIMH.d.mts} +98 -4
- package/dist/{types-Cxf4nHNr.d.ts → types-CokovIMH.d.ts} +98 -4
- package/index-dev.js +16 -0
- package/package.json +5 -3
- package/dist/chunk-2KUHNJXF.mjs +0 -90
- package/dist/chunk-2KUHNJXF.mjs.map +0 -1
- package/dist/chunk-3WO4SAYB.js.map +0 -1
- package/dist/chunk-4HNUMWQK.mjs.map +0 -1
- package/dist/chunk-BFTKGAP3.js.map +0 -1
- package/dist/chunk-F6NQPYKT.js +0 -98
- package/dist/chunk-F6NQPYKT.js.map +0 -1
- package/dist/chunk-H5KMDLY3.js.map +0 -1
- package/dist/chunk-PBQSHIID.js +0 -4
- package/dist/chunk-R35HZZTA.mjs.map +0 -1
- package/dist/chunk-ZCXE6SR5.mjs.map +0 -1
- package/dist/chunk-ZWN22PS2.mjs +0 -3
|
@@ -1,3 +1,168 @@
|
|
|
1
|
+
import { bottom, sortLayoutItems, cloneLayoutItem, getStatics, collides, getFirstCollision, cloneLayout, sortLayoutItemsByRowCol, sortLayoutItemsByColRow, correctBounds } from './chunk-AWM66AWF.mjs';
|
|
2
|
+
|
|
3
|
+
// src/core/constraints.ts
|
|
4
|
+
function clamp(value, min, max) {
|
|
5
|
+
return Math.max(min, Math.min(max, value));
|
|
6
|
+
}
|
|
7
|
+
var gridBounds = {
|
|
8
|
+
name: "gridBounds",
|
|
9
|
+
constrainPosition(item, x, y, { cols, maxRows }) {
|
|
10
|
+
return {
|
|
11
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
12
|
+
y: clamp(y, 0, Math.max(0, maxRows - item.h))
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
constrainSize(item, w, h, handle, { cols, maxRows }) {
|
|
16
|
+
const maxW = handle === "w" || handle === "nw" || handle === "sw" ? item.x + item.w : cols - item.x;
|
|
17
|
+
const maxH = handle === "n" || handle === "nw" || handle === "ne" ? item.y + item.h : maxRows - item.y;
|
|
18
|
+
return {
|
|
19
|
+
w: clamp(w, 1, Math.max(1, maxW)),
|
|
20
|
+
h: clamp(h, 1, Math.max(1, maxH))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var minMaxSize = {
|
|
25
|
+
name: "minMaxSize",
|
|
26
|
+
constrainSize(item, w, h) {
|
|
27
|
+
return {
|
|
28
|
+
w: clamp(w, item.minW ?? 1, item.maxW ?? Infinity),
|
|
29
|
+
h: clamp(h, item.minH ?? 1, item.maxH ?? Infinity)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var containerBounds = {
|
|
34
|
+
name: "containerBounds",
|
|
35
|
+
constrainPosition(item, x, y, { cols, maxRows, containerHeight, rowHeight, margin }) {
|
|
36
|
+
const visibleRows = containerHeight > 0 ? Math.floor((containerHeight + margin[1]) / (rowHeight + margin[1])) : maxRows;
|
|
37
|
+
return {
|
|
38
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
39
|
+
y: clamp(y, 0, Math.max(0, visibleRows - item.h))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var boundedX = {
|
|
44
|
+
name: "boundedX",
|
|
45
|
+
constrainPosition(item, x, y, { cols }) {
|
|
46
|
+
return {
|
|
47
|
+
x: clamp(x, 0, Math.max(0, cols - item.w)),
|
|
48
|
+
y
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var boundedY = {
|
|
53
|
+
name: "boundedY",
|
|
54
|
+
constrainPosition(item, x, y, { maxRows }) {
|
|
55
|
+
return {
|
|
56
|
+
x,
|
|
57
|
+
y: clamp(y, 0, Math.max(0, maxRows - item.h))
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function aspectRatio(ratio) {
|
|
62
|
+
return {
|
|
63
|
+
name: `aspectRatio(${ratio})`,
|
|
64
|
+
constrainSize(_item, w, _h, _handle, context) {
|
|
65
|
+
const { cols, containerWidth, rowHeight, margin } = context;
|
|
66
|
+
const colWidth = (containerWidth - margin[0] * (cols - 1)) / cols;
|
|
67
|
+
const pixelWidth = colWidth * w + margin[0] * Math.max(0, w - 1);
|
|
68
|
+
const pixelHeight = pixelWidth / ratio;
|
|
69
|
+
const h = Math.max(
|
|
70
|
+
1,
|
|
71
|
+
Math.round((pixelHeight + margin[1]) / (rowHeight + margin[1]))
|
|
72
|
+
);
|
|
73
|
+
return { w, h };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function snapToGrid(stepX, stepY = stepX) {
|
|
78
|
+
if (stepX <= 0 || stepY <= 0) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`snapToGrid: step values must be positive (got stepX=${stepX}, stepY=${stepY})`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
name: `snapToGrid(${stepX}, ${stepY})`,
|
|
85
|
+
constrainPosition(_item, x, y) {
|
|
86
|
+
return {
|
|
87
|
+
x: Math.round(x / stepX) * stepX,
|
|
88
|
+
y: Math.round(y / stepY) * stepY
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function minSize(minW, minH) {
|
|
94
|
+
return {
|
|
95
|
+
name: `minSize(${minW}, ${minH})`,
|
|
96
|
+
constrainSize(_item, w, h) {
|
|
97
|
+
return {
|
|
98
|
+
w: Math.max(minW, w),
|
|
99
|
+
h: Math.max(minH, h)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function maxSize(maxW, maxH) {
|
|
105
|
+
return {
|
|
106
|
+
name: `maxSize(${maxW}, ${maxH})`,
|
|
107
|
+
constrainSize(_item, w, h) {
|
|
108
|
+
return {
|
|
109
|
+
w: Math.min(maxW, w),
|
|
110
|
+
h: Math.min(maxH, h)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var defaultConstraints = [gridBounds, minMaxSize];
|
|
116
|
+
function applyPositionConstraints(constraints, item, x, y, context) {
|
|
117
|
+
let result = { x, y };
|
|
118
|
+
for (const constraint of constraints) {
|
|
119
|
+
if (constraint.constrainPosition) {
|
|
120
|
+
result = constraint.constrainPosition(item, result.x, result.y, context);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (item.constraints) {
|
|
124
|
+
for (const constraint of item.constraints) {
|
|
125
|
+
if (constraint.constrainPosition) {
|
|
126
|
+
result = constraint.constrainPosition(
|
|
127
|
+
item,
|
|
128
|
+
result.x,
|
|
129
|
+
result.y,
|
|
130
|
+
context
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
function applySizeConstraints(constraints, item, w, h, handle, context) {
|
|
138
|
+
let result = { w, h };
|
|
139
|
+
for (const constraint of constraints) {
|
|
140
|
+
if (constraint.constrainSize) {
|
|
141
|
+
result = constraint.constrainSize(
|
|
142
|
+
item,
|
|
143
|
+
result.w,
|
|
144
|
+
result.h,
|
|
145
|
+
handle,
|
|
146
|
+
context
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (item.constraints) {
|
|
151
|
+
for (const constraint of item.constraints) {
|
|
152
|
+
if (constraint.constrainSize) {
|
|
153
|
+
result = constraint.constrainSize(
|
|
154
|
+
item,
|
|
155
|
+
result.w,
|
|
156
|
+
result.h,
|
|
157
|
+
handle,
|
|
158
|
+
context
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
1
166
|
// src/core/position.ts
|
|
2
167
|
function setTransform({
|
|
3
168
|
top,
|
|
@@ -191,314 +356,28 @@ var defaultDropConfig = {
|
|
|
191
356
|
defaultItem: { w: 1, h: 1 }
|
|
192
357
|
};
|
|
193
358
|
|
|
194
|
-
// src/core/collision.ts
|
|
195
|
-
function collides(l1, l2) {
|
|
196
|
-
if (l1.i === l2.i) return false;
|
|
197
|
-
if (l1.x + l1.w <= l2.x) return false;
|
|
198
|
-
if (l1.x >= l2.x + l2.w) return false;
|
|
199
|
-
if (l1.y + l1.h <= l2.y) return false;
|
|
200
|
-
if (l1.y >= l2.y + l2.h) return false;
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
function getFirstCollision(layout, layoutItem) {
|
|
204
|
-
for (let i = 0; i < layout.length; i++) {
|
|
205
|
-
const item = layout[i];
|
|
206
|
-
if (item !== void 0 && collides(item, layoutItem)) {
|
|
207
|
-
return item;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return void 0;
|
|
211
|
-
}
|
|
212
|
-
function getAllCollisions(layout, layoutItem) {
|
|
213
|
-
return layout.filter((l) => collides(l, layoutItem));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/core/sort.ts
|
|
217
|
-
function sortLayoutItems(layout, compactType) {
|
|
218
|
-
if (compactType === "horizontal") {
|
|
219
|
-
return sortLayoutItemsByColRow(layout);
|
|
220
|
-
}
|
|
221
|
-
if (compactType === "vertical") {
|
|
222
|
-
return sortLayoutItemsByRowCol(layout);
|
|
223
|
-
}
|
|
224
|
-
return [...layout];
|
|
225
|
-
}
|
|
226
|
-
function sortLayoutItemsByRowCol(layout) {
|
|
227
|
-
return [...layout].sort((a, b) => {
|
|
228
|
-
if (a.y !== b.y) {
|
|
229
|
-
return a.y - b.y;
|
|
230
|
-
}
|
|
231
|
-
return a.x - b.x;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
function sortLayoutItemsByColRow(layout) {
|
|
235
|
-
return [...layout].sort((a, b) => {
|
|
236
|
-
if (a.x !== b.x) {
|
|
237
|
-
return a.x - b.x;
|
|
238
|
-
}
|
|
239
|
-
return a.y - b.y;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/core/layout.ts
|
|
244
|
-
function bottom(layout) {
|
|
245
|
-
let max = 0;
|
|
246
|
-
for (let i = 0; i < layout.length; i++) {
|
|
247
|
-
const item = layout[i];
|
|
248
|
-
if (item !== void 0) {
|
|
249
|
-
const bottomY = item.y + item.h;
|
|
250
|
-
if (bottomY > max) max = bottomY;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return max;
|
|
254
|
-
}
|
|
255
|
-
function getLayoutItem(layout, id) {
|
|
256
|
-
for (let i = 0; i < layout.length; i++) {
|
|
257
|
-
const item = layout[i];
|
|
258
|
-
if (item !== void 0 && item.i === id) {
|
|
259
|
-
return item;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return void 0;
|
|
263
|
-
}
|
|
264
|
-
function getStatics(layout) {
|
|
265
|
-
return layout.filter((l) => l.static === true);
|
|
266
|
-
}
|
|
267
|
-
function cloneLayoutItem(layoutItem) {
|
|
268
|
-
return {
|
|
269
|
-
i: layoutItem.i,
|
|
270
|
-
x: layoutItem.x,
|
|
271
|
-
y: layoutItem.y,
|
|
272
|
-
w: layoutItem.w,
|
|
273
|
-
h: layoutItem.h,
|
|
274
|
-
minW: layoutItem.minW,
|
|
275
|
-
maxW: layoutItem.maxW,
|
|
276
|
-
minH: layoutItem.minH,
|
|
277
|
-
maxH: layoutItem.maxH,
|
|
278
|
-
moved: Boolean(layoutItem.moved),
|
|
279
|
-
static: Boolean(layoutItem.static),
|
|
280
|
-
isDraggable: layoutItem.isDraggable,
|
|
281
|
-
isResizable: layoutItem.isResizable,
|
|
282
|
-
resizeHandles: layoutItem.resizeHandles,
|
|
283
|
-
isBounded: layoutItem.isBounded
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
function cloneLayout(layout) {
|
|
287
|
-
const newLayout = new Array(layout.length);
|
|
288
|
-
for (let i = 0; i < layout.length; i++) {
|
|
289
|
-
const item = layout[i];
|
|
290
|
-
if (item !== void 0) {
|
|
291
|
-
newLayout[i] = cloneLayoutItem(item);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return newLayout;
|
|
295
|
-
}
|
|
296
|
-
function modifyLayout(layout, layoutItem) {
|
|
297
|
-
const newLayout = new Array(layout.length);
|
|
298
|
-
for (let i = 0; i < layout.length; i++) {
|
|
299
|
-
const item = layout[i];
|
|
300
|
-
if (item !== void 0) {
|
|
301
|
-
if (layoutItem.i === item.i) {
|
|
302
|
-
newLayout[i] = layoutItem;
|
|
303
|
-
} else {
|
|
304
|
-
newLayout[i] = item;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return newLayout;
|
|
309
|
-
}
|
|
310
|
-
function withLayoutItem(layout, itemKey, cb) {
|
|
311
|
-
let item = getLayoutItem(layout, itemKey);
|
|
312
|
-
if (!item) {
|
|
313
|
-
return [[...layout], null];
|
|
314
|
-
}
|
|
315
|
-
item = cb(cloneLayoutItem(item));
|
|
316
|
-
const newLayout = modifyLayout(layout, item);
|
|
317
|
-
return [newLayout, item];
|
|
318
|
-
}
|
|
319
|
-
function correctBounds(layout, bounds) {
|
|
320
|
-
const collidesWith = getStatics(layout);
|
|
321
|
-
for (let i = 0; i < layout.length; i++) {
|
|
322
|
-
const l = layout[i];
|
|
323
|
-
if (l === void 0) continue;
|
|
324
|
-
if (l.x + l.w > bounds.cols) {
|
|
325
|
-
l.x = bounds.cols - l.w;
|
|
326
|
-
}
|
|
327
|
-
if (l.x < 0) {
|
|
328
|
-
l.x = 0;
|
|
329
|
-
l.w = bounds.cols;
|
|
330
|
-
}
|
|
331
|
-
if (!l.static) {
|
|
332
|
-
collidesWith.push(l);
|
|
333
|
-
} else {
|
|
334
|
-
while (getFirstCollision(collidesWith, l)) {
|
|
335
|
-
l.y++;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return layout;
|
|
340
|
-
}
|
|
341
|
-
function moveElement(layout, l, x, y, isUserAction, preventCollision, compactType, cols, allowOverlap) {
|
|
342
|
-
if (l.static && l.isDraggable !== true) {
|
|
343
|
-
return [...layout];
|
|
344
|
-
}
|
|
345
|
-
if (l.y === y && l.x === x) {
|
|
346
|
-
return [...layout];
|
|
347
|
-
}
|
|
348
|
-
const oldX = l.x;
|
|
349
|
-
const oldY = l.y;
|
|
350
|
-
if (typeof x === "number") l.x = x;
|
|
351
|
-
if (typeof y === "number") l.y = y;
|
|
352
|
-
l.moved = true;
|
|
353
|
-
let sorted = sortLayoutItems(layout, compactType);
|
|
354
|
-
const movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false;
|
|
355
|
-
if (movingUp) {
|
|
356
|
-
sorted = sorted.reverse();
|
|
357
|
-
}
|
|
358
|
-
const collisions = getAllCollisions(sorted, l);
|
|
359
|
-
const hasCollisions = collisions.length > 0;
|
|
360
|
-
if (hasCollisions && allowOverlap) {
|
|
361
|
-
return cloneLayout(layout);
|
|
362
|
-
}
|
|
363
|
-
if (hasCollisions && preventCollision) {
|
|
364
|
-
l.x = oldX;
|
|
365
|
-
l.y = oldY;
|
|
366
|
-
l.moved = false;
|
|
367
|
-
return layout;
|
|
368
|
-
}
|
|
369
|
-
let resultLayout = [...layout];
|
|
370
|
-
for (let i = 0; i < collisions.length; i++) {
|
|
371
|
-
const collision = collisions[i];
|
|
372
|
-
if (collision === void 0) continue;
|
|
373
|
-
if (collision.moved) continue;
|
|
374
|
-
if (collision.static) {
|
|
375
|
-
resultLayout = moveElementAwayFromCollision(
|
|
376
|
-
resultLayout,
|
|
377
|
-
collision,
|
|
378
|
-
l,
|
|
379
|
-
isUserAction,
|
|
380
|
-
compactType);
|
|
381
|
-
} else {
|
|
382
|
-
resultLayout = moveElementAwayFromCollision(
|
|
383
|
-
resultLayout,
|
|
384
|
-
l,
|
|
385
|
-
collision,
|
|
386
|
-
isUserAction,
|
|
387
|
-
compactType);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return resultLayout;
|
|
391
|
-
}
|
|
392
|
-
function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, compactType, cols) {
|
|
393
|
-
const compactH = compactType === "horizontal";
|
|
394
|
-
const compactV = compactType === "vertical";
|
|
395
|
-
const preventCollision = collidesWith.static;
|
|
396
|
-
if (isUserAction) {
|
|
397
|
-
isUserAction = false;
|
|
398
|
-
const fakeItem = {
|
|
399
|
-
x: compactH ? Math.max(collidesWith.x - itemToMove.w, 0) : itemToMove.x,
|
|
400
|
-
y: compactV ? Math.max(collidesWith.y - itemToMove.h, 0) : itemToMove.y,
|
|
401
|
-
w: itemToMove.w,
|
|
402
|
-
h: itemToMove.h,
|
|
403
|
-
i: "-1"
|
|
404
|
-
};
|
|
405
|
-
const firstCollision = getFirstCollision(layout, fakeItem);
|
|
406
|
-
const collisionNorth = firstCollision !== void 0 && firstCollision.y + firstCollision.h > collidesWith.y;
|
|
407
|
-
const collisionWest = firstCollision !== void 0 && collidesWith.x + collidesWith.w > firstCollision.x;
|
|
408
|
-
if (!firstCollision) {
|
|
409
|
-
return moveElement(
|
|
410
|
-
layout,
|
|
411
|
-
itemToMove,
|
|
412
|
-
compactH ? fakeItem.x : void 0,
|
|
413
|
-
compactV ? fakeItem.y : void 0,
|
|
414
|
-
isUserAction,
|
|
415
|
-
preventCollision,
|
|
416
|
-
compactType);
|
|
417
|
-
}
|
|
418
|
-
if (collisionNorth && compactV) {
|
|
419
|
-
return moveElement(
|
|
420
|
-
layout,
|
|
421
|
-
itemToMove,
|
|
422
|
-
void 0,
|
|
423
|
-
itemToMove.y + 1,
|
|
424
|
-
isUserAction,
|
|
425
|
-
preventCollision,
|
|
426
|
-
compactType);
|
|
427
|
-
}
|
|
428
|
-
if (collisionNorth && compactType === null) {
|
|
429
|
-
collidesWith.y = itemToMove.y;
|
|
430
|
-
itemToMove.y = itemToMove.y + itemToMove.h;
|
|
431
|
-
return [...layout];
|
|
432
|
-
}
|
|
433
|
-
if (collisionWest && compactH) {
|
|
434
|
-
return moveElement(
|
|
435
|
-
layout,
|
|
436
|
-
collidesWith,
|
|
437
|
-
itemToMove.x,
|
|
438
|
-
void 0,
|
|
439
|
-
isUserAction,
|
|
440
|
-
preventCollision,
|
|
441
|
-
compactType);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
const newX = compactH ? itemToMove.x + 1 : void 0;
|
|
445
|
-
const newY = compactV ? itemToMove.y + 1 : void 0;
|
|
446
|
-
if (newX === void 0 && newY === void 0) {
|
|
447
|
-
return [...layout];
|
|
448
|
-
}
|
|
449
|
-
return moveElement(
|
|
450
|
-
layout,
|
|
451
|
-
itemToMove,
|
|
452
|
-
newX,
|
|
453
|
-
newY,
|
|
454
|
-
isUserAction,
|
|
455
|
-
preventCollision,
|
|
456
|
-
compactType);
|
|
457
|
-
}
|
|
458
|
-
function validateLayout(layout, contextName = "Layout") {
|
|
459
|
-
const requiredProps = ["x", "y", "w", "h"];
|
|
460
|
-
if (!Array.isArray(layout)) {
|
|
461
|
-
throw new Error(`${contextName} must be an array!`);
|
|
462
|
-
}
|
|
463
|
-
for (let i = 0; i < layout.length; i++) {
|
|
464
|
-
const item = layout[i];
|
|
465
|
-
if (item === void 0) continue;
|
|
466
|
-
for (const key of requiredProps) {
|
|
467
|
-
const value = item[key];
|
|
468
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
469
|
-
throw new Error(
|
|
470
|
-
`ReactGridLayout: ${contextName}[${i}].${key} must be a number! Received: ${String(value)} (${typeof value})`
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (item.i !== void 0 && typeof item.i !== "string") {
|
|
475
|
-
throw new Error(
|
|
476
|
-
`ReactGridLayout: ${contextName}[${i}].i must be a string! Received: ${String(item.i)} (${typeof item.i})`
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
359
|
// src/core/compact-compat.ts
|
|
483
360
|
function getStatics2(layout) {
|
|
484
361
|
return layout.filter((l) => l.static);
|
|
485
362
|
}
|
|
486
363
|
var heightWidth = { x: "w", y: "h" };
|
|
487
|
-
function resolveCompactionCollision(layout, item, moveToCoord, axis) {
|
|
364
|
+
function resolveCompactionCollision(layout, item, moveToCoord, axis, hasStatics) {
|
|
488
365
|
const sizeProp = heightWidth[axis];
|
|
489
366
|
item[axis] += 1;
|
|
490
367
|
const itemIndex = layout.findIndex((l) => l.i === item.i);
|
|
368
|
+
const layoutHasStatics = hasStatics ?? getStatics2(layout).length > 0;
|
|
491
369
|
for (let i = itemIndex + 1; i < layout.length; i++) {
|
|
492
370
|
const otherItem = layout[i];
|
|
493
371
|
if (otherItem === void 0) continue;
|
|
494
372
|
if (otherItem.static) continue;
|
|
495
|
-
if (otherItem.y > item.y + item.h) break;
|
|
373
|
+
if (!layoutHasStatics && otherItem.y > item.y + item.h) break;
|
|
496
374
|
if (collides(item, otherItem)) {
|
|
497
375
|
resolveCompactionCollision(
|
|
498
376
|
layout,
|
|
499
377
|
otherItem,
|
|
500
378
|
moveToCoord + item[sizeProp],
|
|
501
|
-
axis
|
|
379
|
+
axis,
|
|
380
|
+
layoutHasStatics
|
|
502
381
|
);
|
|
503
382
|
}
|
|
504
383
|
}
|
|
@@ -507,22 +386,24 @@ function resolveCompactionCollision(layout, item, moveToCoord, axis) {
|
|
|
507
386
|
function compactItemInternal(compareWith, l, compactType, cols, fullLayout, allowOverlap, b) {
|
|
508
387
|
const compactV = compactType === "vertical";
|
|
509
388
|
const compactH = compactType === "horizontal";
|
|
510
|
-
if (
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
l.y
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
l.x
|
|
389
|
+
if (!allowOverlap) {
|
|
390
|
+
if (compactV) {
|
|
391
|
+
if (typeof b === "number") {
|
|
392
|
+
l.y = Math.min(b, l.y);
|
|
393
|
+
} else {
|
|
394
|
+
l.y = Math.min(bottom(compareWith), l.y);
|
|
395
|
+
}
|
|
396
|
+
while (l.y > 0 && !getFirstCollision(compareWith, l)) {
|
|
397
|
+
l.y--;
|
|
398
|
+
}
|
|
399
|
+
} else if (compactH) {
|
|
400
|
+
while (l.x > 0 && !getFirstCollision(compareWith, l)) {
|
|
401
|
+
l.x--;
|
|
402
|
+
}
|
|
522
403
|
}
|
|
523
404
|
}
|
|
524
405
|
let collision;
|
|
525
|
-
while ((collision = getFirstCollision(compareWith, l)) !== void 0 && !
|
|
406
|
+
while ((collision = getFirstCollision(compareWith, l)) !== void 0 && !allowOverlap) {
|
|
526
407
|
if (compactH) {
|
|
527
408
|
resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x");
|
|
528
409
|
} else {
|
|
@@ -581,21 +462,23 @@ function compactItem(compareWith, l, compactType, cols, fullLayout, allowOverlap
|
|
|
581
462
|
}
|
|
582
463
|
|
|
583
464
|
// src/core/compactors.ts
|
|
584
|
-
function resolveCompactionCollision2(layout, item, moveToCoord, axis) {
|
|
465
|
+
function resolveCompactionCollision2(layout, item, moveToCoord, axis, hasStatics) {
|
|
585
466
|
const sizeProp = axis === "x" ? "w" : "h";
|
|
586
467
|
item[axis] += 1;
|
|
587
468
|
const itemIndex = layout.findIndex((l) => l.i === item.i);
|
|
469
|
+
const layoutHasStatics = hasStatics ?? getStatics(layout).length > 0;
|
|
588
470
|
for (let i = itemIndex + 1; i < layout.length; i++) {
|
|
589
471
|
const otherItem = layout[i];
|
|
590
472
|
if (otherItem === void 0) continue;
|
|
591
473
|
if (otherItem.static) continue;
|
|
592
|
-
if (otherItem.y > item.y + item.h) break;
|
|
474
|
+
if (!layoutHasStatics && otherItem.y > item.y + item.h) break;
|
|
593
475
|
if (collides(item, otherItem)) {
|
|
594
476
|
resolveCompactionCollision2(
|
|
595
477
|
layout,
|
|
596
478
|
otherItem,
|
|
597
479
|
moveToCoord + item[sizeProp],
|
|
598
|
-
axis
|
|
480
|
+
axis,
|
|
481
|
+
layoutHasStatics
|
|
599
482
|
);
|
|
600
483
|
}
|
|
601
484
|
}
|
|
@@ -728,13 +611,17 @@ var horizontalOverlapCompactor = {
|
|
|
728
611
|
return cloneLayout(layout);
|
|
729
612
|
}
|
|
730
613
|
};
|
|
614
|
+
var noOverlapCompactor = {
|
|
615
|
+
...noCompactor,
|
|
616
|
+
allowOverlap: true
|
|
617
|
+
};
|
|
731
618
|
function getCompactor(compactType, allowOverlap = false, preventCollision = false) {
|
|
732
619
|
let baseCompactor;
|
|
733
620
|
if (allowOverlap) {
|
|
734
621
|
if (compactType === "vertical") baseCompactor = verticalOverlapCompactor;
|
|
735
622
|
else if (compactType === "horizontal")
|
|
736
623
|
baseCompactor = horizontalOverlapCompactor;
|
|
737
|
-
else baseCompactor =
|
|
624
|
+
else baseCompactor = noOverlapCompactor;
|
|
738
625
|
} else {
|
|
739
626
|
if (compactType === "vertical") baseCompactor = verticalCompactor;
|
|
740
627
|
else if (compactType === "horizontal") baseCompactor = horizontalCompactor;
|
|
@@ -817,6 +704,6 @@ function getIndentationValue(value, breakpoint) {
|
|
|
817
704
|
return [10, 10];
|
|
818
705
|
}
|
|
819
706
|
|
|
820
|
-
export { absoluteStrategy,
|
|
821
|
-
//# sourceMappingURL=chunk-
|
|
822
|
-
//# sourceMappingURL=chunk-
|
|
707
|
+
export { absoluteStrategy, applyPositionConstraints, applySizeConstraints, aspectRatio, boundedX, boundedY, compact, compactItem, compactItemHorizontal, compactItemVertical, containerBounds, createScaledStrategy, defaultConstraints, defaultDragConfig, defaultDropConfig, defaultGridConfig, defaultPositionStrategy, defaultResizeConfig, findOrGenerateResponsiveLayout, getBreakpointFromWidth, getColsFromBreakpoint, getCompactor, getIndentationValue, gridBounds, horizontalCompactor, horizontalOverlapCompactor, maxSize, minMaxSize, minSize, noCompactor, noOverlapCompactor, perc, resizeItemInDirection, resolveCompactionCollision2 as resolveCompactionCollision, setTopLeft, setTransform, snapToGrid, sortBreakpoints, transformStrategy, verticalCompactor, verticalOverlapCompactor };
|
|
708
|
+
//# sourceMappingURL=chunk-FLITZMQC.mjs.map
|
|
709
|
+
//# sourceMappingURL=chunk-FLITZMQC.mjs.map
|