react-grid-layout 1.5.1 → 1.5.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/.babelrc.js +1 -1
- package/CHANGELOG.md +21 -8
- package/README.md +1 -0
- package/build/GridItem.js +10 -14
- package/build/ReactGridLayout.js +19 -23
- package/build/ReactGridLayoutPropTypes.js +2 -2
- package/build/ResponsiveReactGridLayout.js +27 -25
- package/build/components/WidthProvider.js +19 -16
- package/build/utils.js +35 -27
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/lib/GridItem.jsx +3 -3
- package/lib/utils.js +20 -4
- package/package.json +22 -15
- package/yarn-error.log +7780 -0
package/build/utils.js
CHANGED
|
@@ -34,7 +34,12 @@ exports.validateLayout = validateLayout;
|
|
|
34
34
|
exports.withLayoutItem = withLayoutItem;
|
|
35
35
|
var _fastEquals = require("fast-equals");
|
|
36
36
|
var _react = _interopRequireDefault(require("react"));
|
|
37
|
-
function _interopRequireDefault(
|
|
37
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
38
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
39
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
40
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
41
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
42
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
38
43
|
/*:: import type {
|
|
39
44
|
ChildrenArray as ReactChildrenArray,
|
|
40
45
|
Element as ReactElement
|
|
@@ -196,7 +201,7 @@ function cloneLayoutItem(layoutItem /*: LayoutItem*/) /*: LayoutItem*/{
|
|
|
196
201
|
* This will catch differences in keys, order, and length.
|
|
197
202
|
*/
|
|
198
203
|
function childrenEqual(a /*: ReactChildren*/, b /*: ReactChildren*/) /*: boolean*/{
|
|
199
|
-
return (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c
|
|
204
|
+
return (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c === null || c === void 0 ? void 0 : c.key), _react.default.Children.map(b, c => c === null || c === void 0 ? void 0 : c.key)) && (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c === null || c === void 0 ? void 0 : c.props["data-grid"]), _react.default.Children.map(b, c => c === null || c === void 0 ? void 0 : c.props["data-grid"]));
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
/**
|
|
@@ -242,6 +247,8 @@ function collides(l1 /*: LayoutItem*/, l2 /*: LayoutItem*/) /*: boolean*/{
|
|
|
242
247
|
function compact(layout /*: Layout*/, compactType /*: CompactType*/, cols /*: number*/, allowOverlap /*: ?boolean*/) /*: Layout*/{
|
|
243
248
|
// Statics go in the compareWith array right away so items flow around them.
|
|
244
249
|
const compareWith = getStatics(layout);
|
|
250
|
+
// We keep track of the bottom position.
|
|
251
|
+
let b = bottom(compareWith);
|
|
245
252
|
// We go through the items by row and column.
|
|
246
253
|
const sorted = sortLayoutItems(layout, compactType);
|
|
247
254
|
// Holding for new items.
|
|
@@ -251,7 +258,8 @@ function compact(layout /*: Layout*/, compactType /*: CompactType*/, cols /*: nu
|
|
|
251
258
|
|
|
252
259
|
// Don't move static elements
|
|
253
260
|
if (!l.static) {
|
|
254
|
-
l = compactItem(compareWith, l, compactType, cols, sorted, allowOverlap);
|
|
261
|
+
l = compactItem(compareWith, l, compactType, cols, sorted, allowOverlap, b);
|
|
262
|
+
b = Math.max(b, l.y + l.h);
|
|
255
263
|
|
|
256
264
|
// Add to comparison array. We only collide with items before this one.
|
|
257
265
|
// Statics are already in this array.
|
|
@@ -302,14 +310,18 @@ function resolveCompactionCollision(layout /*: Layout*/, item /*: LayoutItem*/,
|
|
|
302
310
|
* Modifies item.
|
|
303
311
|
*
|
|
304
312
|
*/
|
|
305
|
-
function compactItem(compareWith /*: Layout*/, l /*: LayoutItem*/, compactType /*: CompactType*/, cols /*: number*/, fullLayout /*: Layout*/, allowOverlap /*: ?boolean*/) /*: LayoutItem*/{
|
|
313
|
+
function compactItem(compareWith /*: Layout*/, l /*: LayoutItem*/, compactType /*: CompactType*/, cols /*: number*/, fullLayout /*: Layout*/, allowOverlap /*: ?boolean*/, b /*: ?number*/) /*: LayoutItem*/{
|
|
306
314
|
const compactV = compactType === "vertical";
|
|
307
315
|
const compactH = compactType === "horizontal";
|
|
308
316
|
if (compactV) {
|
|
309
317
|
// Bottom 'y' possible is the bottom of the layout.
|
|
310
318
|
// This allows you to do nice stuff like specify {y: Infinity}
|
|
311
319
|
// This is here because the layout must be sorted in order to get the correct bottom `y`.
|
|
312
|
-
|
|
320
|
+
if (typeof b === "number") {
|
|
321
|
+
l.y = Math.min(b, l.y);
|
|
322
|
+
} else {
|
|
323
|
+
l.y = Math.min(bottom(compareWith), l.y);
|
|
324
|
+
}
|
|
313
325
|
// Move the element up as far as it can go without colliding.
|
|
314
326
|
while (l.y > 0 && !getFirstCollision(compareWith, l)) {
|
|
315
327
|
l.y--;
|
|
@@ -433,7 +445,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
433
445
|
|
|
434
446
|
// Short-circuit if nothing to do.
|
|
435
447
|
if (l.y === y && l.x === x) return layout;
|
|
436
|
-
log(
|
|
448
|
+
log("Moving element ".concat(l.i, " to [").concat(String(x), ",").concat(String(y), "] from [").concat(l.x, ",").concat(l.y, "]"));
|
|
437
449
|
const oldX = l.x;
|
|
438
450
|
const oldY = l.y;
|
|
439
451
|
|
|
@@ -463,7 +475,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
463
475
|
// If we are preventing collision but not allowing overlap, we need to
|
|
464
476
|
// revert the position of this element so it goes to where it came from, rather
|
|
465
477
|
// than the user's desired location.
|
|
466
|
-
log(
|
|
478
|
+
log("Collision prevented on ".concat(l.i, ", reverting."));
|
|
467
479
|
l.x = oldX;
|
|
468
480
|
l.y = oldY;
|
|
469
481
|
l.moved = false;
|
|
@@ -473,7 +485,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
473
485
|
// Move each item that collides away from this element.
|
|
474
486
|
for (let i = 0, len = collisions.length; i < len; i++) {
|
|
475
487
|
const collision = collisions[i];
|
|
476
|
-
log(
|
|
488
|
+
log("Resolving collision between ".concat(l.i, " at [").concat(l.x, ",").concat(l.y, "] and ").concat(collision.i, " at [").concat(collision.x, ",").concat(collision.y, "]"));
|
|
477
489
|
|
|
478
490
|
// Short circuit so we can't infinite loop
|
|
479
491
|
if (collision.moved) continue;
|
|
@@ -523,10 +535,10 @@ function moveElementAwayFromCollision(layout /*: Layout*/, collidesWith /*: Layo
|
|
|
523
535
|
|
|
524
536
|
// No collision? If so, we can go up there; otherwise, we'll end up moving down as normal
|
|
525
537
|
if (!firstCollision) {
|
|
526
|
-
log(
|
|
538
|
+
log("Doing reverse collision on ".concat(itemToMove.i, " up to [").concat(fakeItem.x, ",").concat(fakeItem.y, "]."));
|
|
527
539
|
return moveElement(layout, itemToMove, compactH ? fakeItem.x : undefined, compactV ? fakeItem.y : undefined, isUserAction, preventCollision, compactType, cols);
|
|
528
540
|
} else if (collisionNorth && compactV) {
|
|
529
|
-
return moveElement(layout, itemToMove, undefined,
|
|
541
|
+
return moveElement(layout, itemToMove, undefined, itemToMove.y + 1, isUserAction, preventCollision, compactType, cols);
|
|
530
542
|
} else if (collisionNorth && compactType == null) {
|
|
531
543
|
collidesWith.y = itemToMove.y;
|
|
532
544
|
itemToMove.y = itemToMove.y + itemToMove.h;
|
|
@@ -650,10 +662,7 @@ function resizeItemInDirection(direction /*: ResizeHandleAxis*/, currentSize /*:
|
|
|
650
662
|
const ordinalHandler = ordinalResizeHandlerMap[direction];
|
|
651
663
|
// Shouldn't be possible given types; that said, don't fail hard
|
|
652
664
|
if (!ordinalHandler) return newSize;
|
|
653
|
-
return ordinalHandler(currentSize, {
|
|
654
|
-
...currentSize,
|
|
655
|
-
...newSize
|
|
656
|
-
}, containerWidth);
|
|
665
|
+
return ordinalHandler(currentSize, _objectSpread(_objectSpread({}, currentSize), newSize), containerWidth);
|
|
657
666
|
}
|
|
658
667
|
function setTransform(_ref5 /*:: */) /*: Object*/{
|
|
659
668
|
let {
|
|
@@ -663,15 +672,15 @@ function setTransform(_ref5 /*:: */) /*: Object*/{
|
|
|
663
672
|
height
|
|
664
673
|
} /*: Position*/ = _ref5 /*: Position*/;
|
|
665
674
|
// Replace unitless items with px
|
|
666
|
-
const translate =
|
|
675
|
+
const translate = "translate(".concat(left, "px,").concat(top, "px)");
|
|
667
676
|
return {
|
|
668
677
|
transform: translate,
|
|
669
678
|
WebkitTransform: translate,
|
|
670
679
|
MozTransform: translate,
|
|
671
680
|
msTransform: translate,
|
|
672
681
|
OTransform: translate,
|
|
673
|
-
width:
|
|
674
|
-
height:
|
|
682
|
+
width: "".concat(width, "px"),
|
|
683
|
+
height: "".concat(height, "px"),
|
|
675
684
|
position: "absolute"
|
|
676
685
|
};
|
|
677
686
|
}
|
|
@@ -683,10 +692,10 @@ function setTopLeft(_ref6 /*:: */) /*: Object*/{
|
|
|
683
692
|
height
|
|
684
693
|
} /*: Position*/ = _ref6 /*: Position*/;
|
|
685
694
|
return {
|
|
686
|
-
top:
|
|
687
|
-
left:
|
|
688
|
-
width:
|
|
689
|
-
height:
|
|
695
|
+
top: "".concat(top, "px"),
|
|
696
|
+
left: "".concat(left, "px"),
|
|
697
|
+
width: "".concat(width, "px"),
|
|
698
|
+
height: "".concat(height, "px"),
|
|
690
699
|
position: "absolute"
|
|
691
700
|
};
|
|
692
701
|
}
|
|
@@ -752,7 +761,7 @@ function synchronizeLayoutWithChildren(initialLayout /*: Layout*/, children /*:
|
|
|
752
761
|
const layout /*: LayoutItem[]*/ = [];
|
|
753
762
|
_react.default.Children.forEach(children, (child /*: ReactElement<any>*/) => {
|
|
754
763
|
// Child may not exist
|
|
755
|
-
if (child
|
|
764
|
+
if ((child === null || child === void 0 ? void 0 : child.key) == null) return;
|
|
756
765
|
const exists = getLayoutItem(initialLayout, String(child.key));
|
|
757
766
|
const g = child.props["data-grid"];
|
|
758
767
|
// Don't overwrite the layout item if it's already in the initial layout.
|
|
@@ -766,10 +775,9 @@ function synchronizeLayoutWithChildren(initialLayout /*: Layout*/, children /*:
|
|
|
766
775
|
validateLayout([g], "ReactGridLayout.children");
|
|
767
776
|
}
|
|
768
777
|
// FIXME clone not really necessary here
|
|
769
|
-
layout.push(cloneLayoutItem({
|
|
770
|
-
...g,
|
|
778
|
+
layout.push(cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
|
|
771
779
|
i: child.key
|
|
772
|
-
}));
|
|
780
|
+
})));
|
|
773
781
|
} else {
|
|
774
782
|
// Nothing provided: ensure this is added to the bottom
|
|
775
783
|
// FIXME clone not really necessary here
|
|
@@ -808,11 +816,11 @@ function validateLayout(layout /*: Layout*/) /*: void*/{
|
|
|
808
816
|
const key = subProps[j];
|
|
809
817
|
const value = item[key];
|
|
810
818
|
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
811
|
-
throw new Error(
|
|
819
|
+
throw new Error("ReactGridLayout: ".concat(contextName, "[").concat(i, "].").concat(key, " must be a number! Received: ").concat(value, " (").concat(typeof value, ")"));
|
|
812
820
|
}
|
|
813
821
|
}
|
|
814
822
|
if (typeof item.i !== "undefined" && typeof item.i !== "string") {
|
|
815
|
-
throw new Error(
|
|
823
|
+
throw new Error("ReactGridLayout: ".concat(contextName, "[").concat(i, "].i must be a string! Received: ").concat(item.i, " (").concat(typeof item.i, ")"));
|
|
816
824
|
}
|
|
817
825
|
}
|
|
818
826
|
}
|