react-grid-layout 1.5.3 → 2.0.0

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.
Files changed (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
@@ -0,0 +1,822 @@
1
+ // src/core/position.ts
2
+ function setTransform({
3
+ top,
4
+ left,
5
+ width,
6
+ height
7
+ }) {
8
+ const translate = `translate(${left}px,${top}px)`;
9
+ return {
10
+ transform: translate,
11
+ WebkitTransform: translate,
12
+ MozTransform: translate,
13
+ msTransform: translate,
14
+ OTransform: translate,
15
+ width: `${width}px`,
16
+ height: `${height}px`,
17
+ position: "absolute"
18
+ };
19
+ }
20
+ function setTopLeft({
21
+ top,
22
+ left,
23
+ width,
24
+ height
25
+ }) {
26
+ return {
27
+ top: `${top}px`,
28
+ left: `${left}px`,
29
+ width: `${width}px`,
30
+ height: `${height}px`,
31
+ position: "absolute"
32
+ };
33
+ }
34
+ function perc(num) {
35
+ return num * 100 + "%";
36
+ }
37
+ function constrainWidth(left, currentWidth, newWidth, containerWidth) {
38
+ return left + newWidth > containerWidth ? currentWidth : newWidth;
39
+ }
40
+ function constrainHeight(top, currentHeight, newHeight) {
41
+ return top < 0 ? currentHeight : newHeight;
42
+ }
43
+ function constrainLeft(left) {
44
+ return Math.max(0, left);
45
+ }
46
+ function constrainTop(top) {
47
+ return Math.max(0, top);
48
+ }
49
+ var resizeNorth = (currentSize, newSize, _containerWidth) => {
50
+ const { left, height, width } = newSize;
51
+ const top = currentSize.top - (height - currentSize.height);
52
+ return {
53
+ left,
54
+ width,
55
+ height: constrainHeight(top, currentSize.height, height),
56
+ top: constrainTop(top)
57
+ };
58
+ };
59
+ var resizeEast = (currentSize, newSize, containerWidth) => {
60
+ const { top, left, height, width } = newSize;
61
+ return {
62
+ top,
63
+ height,
64
+ width: constrainWidth(
65
+ currentSize.left,
66
+ currentSize.width,
67
+ width,
68
+ containerWidth
69
+ ),
70
+ left: constrainLeft(left)
71
+ };
72
+ };
73
+ var resizeWest = (currentSize, newSize, _containerWidth) => {
74
+ const { top, height, width } = newSize;
75
+ const left = currentSize.left + currentSize.width - width;
76
+ if (left < 0) {
77
+ return {
78
+ height,
79
+ width: currentSize.left + currentSize.width,
80
+ top: constrainTop(top),
81
+ left: 0
82
+ };
83
+ }
84
+ return {
85
+ height,
86
+ width,
87
+ top: constrainTop(top),
88
+ left
89
+ };
90
+ };
91
+ var resizeSouth = (currentSize, newSize, _containerWidth) => {
92
+ const { top, left, height, width } = newSize;
93
+ return {
94
+ width,
95
+ left,
96
+ height: constrainHeight(top, currentSize.height, height),
97
+ top: constrainTop(top)
98
+ };
99
+ };
100
+ var resizeNorthEast = (currentSize, newSize, containerWidth) => resizeNorth(
101
+ currentSize,
102
+ resizeEast(currentSize, newSize, containerWidth));
103
+ var resizeNorthWest = (currentSize, newSize, containerWidth) => resizeNorth(
104
+ currentSize,
105
+ resizeWest(currentSize, newSize));
106
+ var resizeSouthEast = (currentSize, newSize, containerWidth) => resizeSouth(
107
+ currentSize,
108
+ resizeEast(currentSize, newSize, containerWidth));
109
+ var resizeSouthWest = (currentSize, newSize, containerWidth) => resizeSouth(
110
+ currentSize,
111
+ resizeWest(currentSize, newSize));
112
+ var resizeHandlerMap = {
113
+ n: resizeNorth,
114
+ ne: resizeNorthEast,
115
+ e: resizeEast,
116
+ se: resizeSouthEast,
117
+ s: resizeSouth,
118
+ sw: resizeSouthWest,
119
+ w: resizeWest,
120
+ nw: resizeNorthWest
121
+ };
122
+ function resizeItemInDirection(direction, currentSize, newSize, containerWidth) {
123
+ const handler = resizeHandlerMap[direction];
124
+ if (!handler) {
125
+ return newSize;
126
+ }
127
+ return handler(currentSize, { ...currentSize, ...newSize }, containerWidth);
128
+ }
129
+ var transformStrategy = {
130
+ type: "transform",
131
+ scale: 1,
132
+ calcStyle(pos) {
133
+ return setTransform(pos);
134
+ },
135
+ calcDragPosition(clientX, clientY, offsetX, offsetY) {
136
+ return {
137
+ left: clientX - offsetX,
138
+ top: clientY - offsetY
139
+ };
140
+ }
141
+ };
142
+ var absoluteStrategy = {
143
+ type: "absolute",
144
+ scale: 1,
145
+ calcStyle(pos) {
146
+ return setTopLeft(pos);
147
+ },
148
+ calcDragPosition(clientX, clientY, offsetX, offsetY) {
149
+ return {
150
+ left: clientX - offsetX,
151
+ top: clientY - offsetY
152
+ };
153
+ }
154
+ };
155
+ function createScaledStrategy(scale) {
156
+ return {
157
+ type: "transform",
158
+ scale,
159
+ calcStyle(pos) {
160
+ return setTransform(pos);
161
+ },
162
+ calcDragPosition(clientX, clientY, offsetX, offsetY) {
163
+ return {
164
+ left: (clientX - offsetX) / scale,
165
+ top: (clientY - offsetY) / scale
166
+ };
167
+ }
168
+ };
169
+ }
170
+ var defaultPositionStrategy = transformStrategy;
171
+
172
+ // src/core/types.ts
173
+ var defaultGridConfig = {
174
+ cols: 12,
175
+ rowHeight: 150,
176
+ margin: [10, 10],
177
+ containerPadding: null,
178
+ maxRows: Infinity
179
+ };
180
+ var defaultDragConfig = {
181
+ enabled: true,
182
+ bounded: false,
183
+ threshold: 3
184
+ };
185
+ var defaultResizeConfig = {
186
+ enabled: true,
187
+ handles: ["se"]
188
+ };
189
+ var defaultDropConfig = {
190
+ enabled: false,
191
+ defaultItem: { w: 1, h: 1 }
192
+ };
193
+
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
+ // src/core/compact-compat.ts
483
+ function getStatics2(layout) {
484
+ return layout.filter((l) => l.static);
485
+ }
486
+ var heightWidth = { x: "w", y: "h" };
487
+ function resolveCompactionCollision(layout, item, moveToCoord, axis) {
488
+ const sizeProp = heightWidth[axis];
489
+ item[axis] += 1;
490
+ const itemIndex = layout.findIndex((l) => l.i === item.i);
491
+ for (let i = itemIndex + 1; i < layout.length; i++) {
492
+ const otherItem = layout[i];
493
+ if (otherItem === void 0) continue;
494
+ if (otherItem.static) continue;
495
+ if (otherItem.y > item.y + item.h) break;
496
+ if (collides(item, otherItem)) {
497
+ resolveCompactionCollision(
498
+ layout,
499
+ otherItem,
500
+ moveToCoord + item[sizeProp],
501
+ axis
502
+ );
503
+ }
504
+ }
505
+ item[axis] = moveToCoord;
506
+ }
507
+ function compactItemInternal(compareWith, l, compactType, cols, fullLayout, allowOverlap, b) {
508
+ const compactV = compactType === "vertical";
509
+ const compactH = compactType === "horizontal";
510
+ if (compactV) {
511
+ if (typeof b === "number") {
512
+ l.y = Math.min(b, l.y);
513
+ } else {
514
+ l.y = Math.min(bottom(compareWith), l.y);
515
+ }
516
+ while (l.y > 0 && !getFirstCollision(compareWith, l)) {
517
+ l.y--;
518
+ }
519
+ } else if (compactH) {
520
+ while (l.x > 0 && !getFirstCollision(compareWith, l)) {
521
+ l.x--;
522
+ }
523
+ }
524
+ let collision;
525
+ while ((collision = getFirstCollision(compareWith, l)) !== void 0 && !(compactType === null && allowOverlap)) {
526
+ if (compactH) {
527
+ resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x");
528
+ } else {
529
+ resolveCompactionCollision(fullLayout, l, collision.y + collision.h, "y");
530
+ }
531
+ if (compactH && l.x + l.w > cols) {
532
+ l.x = cols - l.w;
533
+ l.y++;
534
+ while (l.x > 0 && !getFirstCollision(compareWith, l)) {
535
+ l.x--;
536
+ }
537
+ }
538
+ }
539
+ l.y = Math.max(l.y, 0);
540
+ l.x = Math.max(l.x, 0);
541
+ return l;
542
+ }
543
+ function compact(layout, compactType, cols, allowOverlap) {
544
+ const compareWith = getStatics2(layout);
545
+ let b = bottom(compareWith);
546
+ const sorted = sortLayoutItems(layout, compactType);
547
+ const out = new Array(layout.length);
548
+ for (let i = 0; i < sorted.length; i++) {
549
+ const sortedItem = sorted[i];
550
+ if (sortedItem === void 0) continue;
551
+ let l = cloneLayoutItem(sortedItem);
552
+ if (!l.static) {
553
+ l = compactItemInternal(
554
+ compareWith,
555
+ l,
556
+ compactType,
557
+ cols,
558
+ sorted,
559
+ allowOverlap,
560
+ b
561
+ );
562
+ b = Math.max(b, l.y + l.h);
563
+ compareWith.push(l);
564
+ }
565
+ const originalIndex = layout.indexOf(sortedItem);
566
+ out[originalIndex] = l;
567
+ l.moved = false;
568
+ }
569
+ return out;
570
+ }
571
+ function compactItem(compareWith, l, compactType, cols, fullLayout, allowOverlap, maxY) {
572
+ return compactItemInternal(
573
+ compareWith,
574
+ cloneLayoutItem(l),
575
+ compactType,
576
+ cols,
577
+ fullLayout,
578
+ allowOverlap,
579
+ maxY
580
+ );
581
+ }
582
+
583
+ // src/core/compactors.ts
584
+ function resolveCompactionCollision2(layout, item, moveToCoord, axis) {
585
+ const sizeProp = axis === "x" ? "w" : "h";
586
+ item[axis] += 1;
587
+ const itemIndex = layout.findIndex((l) => l.i === item.i);
588
+ for (let i = itemIndex + 1; i < layout.length; i++) {
589
+ const otherItem = layout[i];
590
+ if (otherItem === void 0) continue;
591
+ if (otherItem.static) continue;
592
+ if (otherItem.y > item.y + item.h) break;
593
+ if (collides(item, otherItem)) {
594
+ resolveCompactionCollision2(
595
+ layout,
596
+ otherItem,
597
+ moveToCoord + item[sizeProp],
598
+ axis
599
+ );
600
+ }
601
+ }
602
+ item[axis] = moveToCoord;
603
+ }
604
+ function compactItemVertical(compareWith, l, fullLayout, maxY) {
605
+ l.y = Math.min(maxY, l.y);
606
+ while (l.y > 0 && !getFirstCollision(compareWith, l)) {
607
+ l.y--;
608
+ }
609
+ let collision;
610
+ while ((collision = getFirstCollision(compareWith, l)) !== void 0) {
611
+ resolveCompactionCollision2(fullLayout, l, collision.y + collision.h, "y");
612
+ }
613
+ l.y = Math.max(l.y, 0);
614
+ return l;
615
+ }
616
+ function compactItemHorizontal(compareWith, l, cols, fullLayout) {
617
+ while (l.x > 0 && !getFirstCollision(compareWith, l)) {
618
+ l.x--;
619
+ }
620
+ let collision;
621
+ while ((collision = getFirstCollision(compareWith, l)) !== void 0) {
622
+ resolveCompactionCollision2(fullLayout, l, collision.x + collision.w, "x");
623
+ if (l.x + l.w > cols) {
624
+ l.x = cols - l.w;
625
+ l.y++;
626
+ while (l.x > 0 && !getFirstCollision(compareWith, l)) {
627
+ l.x--;
628
+ }
629
+ }
630
+ }
631
+ l.x = Math.max(l.x, 0);
632
+ return l;
633
+ }
634
+ var verticalCompactor = {
635
+ type: "vertical",
636
+ allowOverlap: false,
637
+ compact(layout, _cols) {
638
+ const compareWith = getStatics(layout);
639
+ let maxY = bottom(compareWith);
640
+ const sorted = sortLayoutItemsByRowCol(layout);
641
+ const out = new Array(layout.length);
642
+ for (let i = 0; i < sorted.length; i++) {
643
+ const sortedItem = sorted[i];
644
+ if (sortedItem === void 0) continue;
645
+ let l = cloneLayoutItem(sortedItem);
646
+ if (!l.static) {
647
+ l = compactItemVertical(compareWith, l, sorted, maxY);
648
+ maxY = Math.max(maxY, l.y + l.h);
649
+ compareWith.push(l);
650
+ }
651
+ const originalIndex = layout.indexOf(sortedItem);
652
+ out[originalIndex] = l;
653
+ l.moved = false;
654
+ }
655
+ return out;
656
+ },
657
+ onMove(layout, item, x, y, _cols) {
658
+ const newLayout = cloneLayout(layout);
659
+ const movedItem = newLayout.find((l) => l.i === item.i);
660
+ if (movedItem) {
661
+ movedItem.x = x;
662
+ movedItem.y = y;
663
+ movedItem.moved = true;
664
+ }
665
+ return newLayout;
666
+ }
667
+ };
668
+ var horizontalCompactor = {
669
+ type: "horizontal",
670
+ allowOverlap: false,
671
+ compact(layout, cols) {
672
+ const compareWith = getStatics(layout);
673
+ const sorted = sortLayoutItemsByColRow(layout);
674
+ const out = new Array(layout.length);
675
+ for (let i = 0; i < sorted.length; i++) {
676
+ const sortedItem = sorted[i];
677
+ if (sortedItem === void 0) continue;
678
+ let l = cloneLayoutItem(sortedItem);
679
+ if (!l.static) {
680
+ l = compactItemHorizontal(compareWith, l, cols, sorted);
681
+ compareWith.push(l);
682
+ }
683
+ const originalIndex = layout.indexOf(sortedItem);
684
+ out[originalIndex] = l;
685
+ l.moved = false;
686
+ }
687
+ return out;
688
+ },
689
+ onMove(layout, item, x, y, _cols) {
690
+ const newLayout = cloneLayout(layout);
691
+ const movedItem = newLayout.find((l) => l.i === item.i);
692
+ if (movedItem) {
693
+ movedItem.x = x;
694
+ movedItem.y = y;
695
+ movedItem.moved = true;
696
+ }
697
+ return newLayout;
698
+ }
699
+ };
700
+ var noCompactor = {
701
+ type: null,
702
+ allowOverlap: false,
703
+ compact(layout, _cols) {
704
+ return cloneLayout(layout);
705
+ },
706
+ onMove(layout, item, x, y, _cols) {
707
+ const newLayout = cloneLayout(layout);
708
+ const movedItem = newLayout.find((l) => l.i === item.i);
709
+ if (movedItem) {
710
+ movedItem.x = x;
711
+ movedItem.y = y;
712
+ movedItem.moved = true;
713
+ }
714
+ return newLayout;
715
+ }
716
+ };
717
+ var verticalOverlapCompactor = {
718
+ ...verticalCompactor,
719
+ allowOverlap: true,
720
+ compact(layout, _cols) {
721
+ return cloneLayout(layout);
722
+ }
723
+ };
724
+ var horizontalOverlapCompactor = {
725
+ ...horizontalCompactor,
726
+ allowOverlap: true,
727
+ compact(layout, _cols) {
728
+ return cloneLayout(layout);
729
+ }
730
+ };
731
+ function getCompactor(compactType, allowOverlap = false, preventCollision = false) {
732
+ let baseCompactor;
733
+ if (allowOverlap) {
734
+ if (compactType === "vertical") baseCompactor = verticalOverlapCompactor;
735
+ else if (compactType === "horizontal")
736
+ baseCompactor = horizontalOverlapCompactor;
737
+ else baseCompactor = noCompactor;
738
+ } else {
739
+ if (compactType === "vertical") baseCompactor = verticalCompactor;
740
+ else if (compactType === "horizontal") baseCompactor = horizontalCompactor;
741
+ else baseCompactor = noCompactor;
742
+ }
743
+ if (preventCollision) {
744
+ return { ...baseCompactor, preventCollision };
745
+ }
746
+ return baseCompactor;
747
+ }
748
+
749
+ // src/core/responsive.ts
750
+ function sortBreakpoints(breakpoints) {
751
+ const keys = Object.keys(breakpoints);
752
+ return keys.sort((a, b) => breakpoints[a] - breakpoints[b]);
753
+ }
754
+ function getBreakpointFromWidth(breakpoints, width) {
755
+ const sorted = sortBreakpoints(breakpoints);
756
+ let matching = sorted[0];
757
+ if (matching === void 0) {
758
+ throw new Error("No breakpoints defined");
759
+ }
760
+ for (let i = 1; i < sorted.length; i++) {
761
+ const breakpointName = sorted[i];
762
+ if (breakpointName === void 0) continue;
763
+ const breakpointWidth = breakpoints[breakpointName];
764
+ if (width > breakpointWidth) {
765
+ matching = breakpointName;
766
+ }
767
+ }
768
+ return matching;
769
+ }
770
+ function getColsFromBreakpoint(breakpoint, cols) {
771
+ const colCount = cols[breakpoint];
772
+ if (colCount === void 0) {
773
+ throw new Error(
774
+ `ResponsiveReactGridLayout: \`cols\` entry for breakpoint ${String(breakpoint)} is missing!`
775
+ );
776
+ }
777
+ return colCount;
778
+ }
779
+ function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBreakpoint, cols, compactType) {
780
+ const existingLayout = layouts[breakpoint];
781
+ if (existingLayout) {
782
+ return cloneLayout(existingLayout);
783
+ }
784
+ let layout = layouts[lastBreakpoint];
785
+ const breakpointsSorted = sortBreakpoints(breakpoints);
786
+ const breakpointsAbove = breakpointsSorted.slice(
787
+ breakpointsSorted.indexOf(breakpoint)
788
+ );
789
+ for (let i = 0; i < breakpointsAbove.length; i++) {
790
+ const b = breakpointsAbove[i];
791
+ if (b === void 0) continue;
792
+ const layoutForBreakpoint = layouts[b];
793
+ if (layoutForBreakpoint) {
794
+ layout = layoutForBreakpoint;
795
+ break;
796
+ }
797
+ }
798
+ const clonedLayout = cloneLayout(layout || []);
799
+ return compact(correctBounds(clonedLayout, { cols }), compactType, cols);
800
+ }
801
+ function getIndentationValue(value, breakpoint) {
802
+ if (Array.isArray(value)) {
803
+ return value;
804
+ }
805
+ const breakpointMap = value;
806
+ const breakpointValue = breakpointMap[breakpoint];
807
+ if (breakpointValue !== void 0) {
808
+ return breakpointValue;
809
+ }
810
+ const keys = Object.keys(breakpointMap);
811
+ for (const key of keys) {
812
+ const v = breakpointMap[key];
813
+ if (v !== void 0) {
814
+ return v;
815
+ }
816
+ }
817
+ return [10, 10];
818
+ }
819
+
820
+ export { absoluteStrategy, bottom, cloneLayout, cloneLayoutItem, collides, compact, compactItem, compactItemHorizontal, compactItemVertical, correctBounds, createScaledStrategy, defaultDragConfig, defaultDropConfig, defaultGridConfig, defaultPositionStrategy, defaultResizeConfig, findOrGenerateResponsiveLayout, getAllCollisions, getBreakpointFromWidth, getColsFromBreakpoint, getCompactor, getFirstCollision, getIndentationValue, getLayoutItem, getStatics, horizontalCompactor, horizontalOverlapCompactor, modifyLayout, moveElement, moveElementAwayFromCollision, noCompactor, perc, resizeItemInDirection, resolveCompactionCollision2 as resolveCompactionCollision, setTopLeft, setTransform, sortBreakpoints, sortLayoutItems, sortLayoutItemsByColRow, sortLayoutItemsByRowCol, transformStrategy, validateLayout, verticalCompactor, verticalOverlapCompactor, withLayoutItem };
821
+ //# sourceMappingURL=chunk-4HNUMWQK.mjs.map
822
+ //# sourceMappingURL=chunk-4HNUMWQK.mjs.map