react-grid-layout 1.2.5 → 1.3.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.resizeHandleType = exports.resizeHandleAxesType = void 0;
6
+ exports.resizeHandleType = exports.resizeHandleAxesType = exports.default = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
@@ -56,6 +56,7 @@ var resizeHandleType
56
56
  droppingItem: $Shape<LayoutItem>,
57
57
  resizeHandles: ResizeHandleAxis[],
58
58
  resizeHandle?: ResizeHandle,
59
+ allowOverlap: boolean,
59
60
 
60
61
  // Callbacks
61
62
  onLayoutChange: Layout => void,
@@ -65,6 +66,7 @@ var resizeHandleType
65
66
  onResize: EventCallback,
66
67
  onResizeStart: EventCallback,
67
68
  onResizeStop: EventCallback,
69
+ onDropDragOver: (e: DragOverEvent) => ?({| w?: number, h?: number |} | false),
68
70
  onDrop: (layout: Layout, item: ?LayoutItem, e: Event) => void,
69
71
  children: ReactChildrenArray<ReactElement<any>>,
70
72
  innerRef?: Ref<"div">
@@ -147,6 +149,8 @@ var _default = {
147
149
  isBounded: _propTypes.default.bool,
148
150
  isDraggable: _propTypes.default.bool,
149
151
  isResizable: _propTypes.default.bool,
152
+ // If true, grid can be placed one over the other.
153
+ allowOverlap: _propTypes.default.bool,
150
154
  // If true, grid items won't change position when being dragged over.
151
155
  preventCollision: _propTypes.default.bool,
152
156
  // Use CSS transforms instead of top/left
@@ -199,6 +203,8 @@ var _default = {
199
203
  var keys = {};
200
204
 
201
205
  _react.default.Children.forEach(children, function (child) {
206
+ if ((child === null || child === void 0 ? void 0 : child.key) == null) return;
207
+
202
208
  if (keys[child.key]) {
203
209
  throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
204
210
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -19,6 +19,8 @@ var _responsiveUtils = require("./responsiveUtils");
19
19
 
20
20
  var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
21
21
 
22
+ var _excluded = ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"];
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -31,23 +33,23 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
31
33
 
32
34
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
35
 
34
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
36
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
37
 
36
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
38
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
37
39
 
38
40
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
39
41
 
40
42
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
41
43
 
42
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
44
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
43
45
 
44
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
46
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
45
47
 
46
48
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
47
49
 
48
50
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
49
51
 
50
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
52
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
51
53
 
52
54
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
53
55
 
@@ -57,6 +59,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
57
59
 
58
60
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
59
61
 
62
+ // $FlowFixMe[method-unbinding]
60
63
  var type = function type(obj) {
61
64
  return Object.prototype.toString.call(obj);
62
65
  };
@@ -117,6 +120,7 @@ function getIndentationValue
117
120
  /*:: type DefaultProps = Pick<
118
121
  Props<>,
119
122
  {|
123
+ allowOverlap: 0,
120
124
  breakpoints: 0,
121
125
  cols: 0,
122
126
  containerPadding: 0,
@@ -220,7 +224,7 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
220
224
 
221
225
  var layout = (0, _responsiveUtils.findOrGenerateResponsiveLayout)(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType); // This adds missing items.
222
226
 
223
- layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType); // Store the new layout.
227
+ layout = (0, _utils.synchronizeLayoutWithChildren)(layout, this.props.children, newCols, compactType, this.props.allowOverlap); // Store the new layout.
224
228
 
225
229
  newLayouts[newBreakpoint] = layout; // callbacks
226
230
 
@@ -254,7 +258,7 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
254
258
  onBreakpointChange = _this$props3.onBreakpointChange,
255
259
  onLayoutChange = _this$props3.onLayoutChange,
256
260
  onWidthChange = _this$props3.onWidthChange,
257
- other = _objectWithoutProperties(_this$props3, ["breakpoint", "breakpoints", "cols", "layouts", "margin", "containerPadding", "onBreakpointChange", "onLayoutChange", "onWidthChange"]);
261
+ other = _objectWithoutProperties(_this$props3, _excluded);
258
262
  /* eslint-enable no-unused-vars */
259
263
 
260
264
 
@@ -307,6 +311,7 @@ _defineProperty(ResponsiveReactGridLayout, "propTypes", {
307
311
  breakpoint: _propTypes.default.string,
308
312
  // {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}
309
313
  breakpoints: _propTypes.default.object,
314
+ allowOverlap: _propTypes.default.bool,
310
315
  // # of cols. This is a breakpoint -> cols map
311
316
  cols: _propTypes.default.object,
312
317
  // # of margin. This is a breakpoint -> margin map
@@ -377,6 +382,7 @@ _defineProperty(ResponsiveReactGridLayout, "defaultProps", {
377
382
  },
378
383
  layouts: {},
379
384
  margin: [10, 10],
385
+ allowOverlap: false,
380
386
  onBreakpointChange: _utils.noop,
381
387
  onLayoutChange: _utils.noop,
382
388
  onWidthChange: _utils.noop
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.calcGridColWidth = calcGridColWidth;
7
- exports.calcGridItemWHPx = calcGridItemWHPx;
8
7
  exports.calcGridItemPosition = calcGridItemPosition;
9
- exports.calcXY = calcXY;
8
+ exports.calcGridItemWHPx = calcGridItemWHPx;
10
9
  exports.calcWH = calcWH;
10
+ exports.calcXY = calcXY;
11
11
  exports.clamp = clamp;
12
12
 
13
13
  /*:: import type { Position } from "./utils";*/
@@ -88,9 +88,9 @@ function calcGridItemPosition(positionParams
88
88
  out.height = Math.round(state.resizing.height);
89
89
  } // Otherwise, calculate from grid units.
90
90
  else {
91
- out.width = calcGridItemWHPx(w, colWidth, margin[0]);
92
- out.height = calcGridItemWHPx(h, rowHeight, margin[1]);
93
- } // If dragging, use the exact width and height as returned from dragging callbacks.
91
+ out.width = calcGridItemWHPx(w, colWidth, margin[0]);
92
+ out.height = calcGridItemWHPx(h, rowHeight, margin[1]);
93
+ } // If dragging, use the exact width and height as returned from dragging callbacks.
94
94
 
95
95
 
96
96
  if (state && state.dragging) {
@@ -98,9 +98,9 @@ function calcGridItemPosition(positionParams
98
98
  out.left = Math.round(state.dragging.left);
99
99
  } // Otherwise, calculate from grid units.
100
100
  else {
101
- out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
102
- out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
103
- }
101
+ out.top = Math.round((rowHeight + margin[1]) * y + containerPadding[1]);
102
+ out.left = Math.round((colWidth + margin[0]) * x + containerPadding[0]);
103
+ }
104
104
 
105
105
  return out;
106
106
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,7 +11,9 @@ var React = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
- var _classnames = _interopRequireDefault(require("classnames"));
14
+ var _clsx = _interopRequireDefault(require("clsx"));
15
+
16
+ var _excluded = ["measureBeforeMount"];
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
@@ -29,15 +31,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
29
31
 
30
32
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
31
33
 
32
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
34
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
33
35
 
34
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
36
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
35
37
 
36
38
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
39
 
38
40
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
39
41
 
40
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
42
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
41
43
 
42
44
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
43
45
 
@@ -125,11 +127,11 @@ function WidthProvideRGL
125
127
  value: function render() {
126
128
  var _this$props = this.props,
127
129
  measureBeforeMount = _this$props.measureBeforeMount,
128
- rest = _objectWithoutProperties(_this$props, ["measureBeforeMount"]);
130
+ rest = _objectWithoutProperties(_this$props, _excluded);
129
131
 
130
132
  if (measureBeforeMount && !this.mounted) {
131
133
  return /*#__PURE__*/React.createElement("div", {
132
- className: (0, _classnames.default)(this.props.className, layoutClassName),
134
+ className: (0, _clsx.default)(this.props.className, layoutClassName),
133
135
  style: this.props.style // $FlowIgnore ref types
134
136
  ,
135
137
  ref: this.elementRef
@@ -1,5 +1,5 @@
1
1
  // this file was prevaled
2
2
  module.exports = function fastRGLPropsEqual(a, b, isEqualImpl) {
3
3
  if (a === b) return true;
4
- return a.className === b.className && isEqualImpl(a.style, b.style) && a.width === b.width && a.autoSize === b.autoSize && a.cols === b.cols && a.draggableCancel === b.draggableCancel && a.draggableHandle === b.draggableHandle && isEqualImpl(a.verticalCompact, b.verticalCompact) && isEqualImpl(a.compactType, b.compactType) && isEqualImpl(a.layout, b.layout) && isEqualImpl(a.margin, b.margin) && isEqualImpl(a.containerPadding, b.containerPadding) && a.rowHeight === b.rowHeight && a.maxRows === b.maxRows && a.isBounded === b.isBounded && a.isDraggable === b.isDraggable && a.isResizable === b.isResizable && a.preventCollision === b.preventCollision && a.useCSSTransforms === b.useCSSTransforms && a.transformScale === b.transformScale && a.isDroppable === b.isDroppable && isEqualImpl(a.resizeHandles, b.resizeHandles) && isEqualImpl(a.resizeHandle, b.resizeHandle) && a.onLayoutChange === b.onLayoutChange && a.onDragStart === b.onDragStart && a.onDrag === b.onDrag && a.onDragStop === b.onDragStop && a.onResizeStart === b.onResizeStart && a.onResize === b.onResize && a.onResizeStop === b.onResizeStop && a.onDrop === b.onDrop && isEqualImpl(a.droppingItem, b.droppingItem) && isEqualImpl(a.innerRef, b.innerRef);
4
+ return a.className === b.className && isEqualImpl(a.style, b.style) && a.width === b.width && a.autoSize === b.autoSize && a.cols === b.cols && a.draggableCancel === b.draggableCancel && a.draggableHandle === b.draggableHandle && isEqualImpl(a.verticalCompact, b.verticalCompact) && isEqualImpl(a.compactType, b.compactType) && isEqualImpl(a.layout, b.layout) && isEqualImpl(a.margin, b.margin) && isEqualImpl(a.containerPadding, b.containerPadding) && a.rowHeight === b.rowHeight && a.maxRows === b.maxRows && a.isBounded === b.isBounded && a.isDraggable === b.isDraggable && a.isResizable === b.isResizable && a.allowOverlap === b.allowOverlap && a.preventCollision === b.preventCollision && a.useCSSTransforms === b.useCSSTransforms && a.transformScale === b.transformScale && a.isDroppable === b.isDroppable && isEqualImpl(a.resizeHandles, b.resizeHandles) && isEqualImpl(a.resizeHandle, b.resizeHandle) && a.onLayoutChange === b.onLayoutChange && a.onDragStart === b.onDragStart && a.onDrag === b.onDrag && a.onDragStop === b.onDragStop && a.onResizeStart === b.onResizeStart && a.onResize === b.onResize && a.onResizeStop === b.onResizeStop && a.onDrop === b.onDrop && isEqualImpl(a.droppingItem, b.droppingItem) && isEqualImpl(a.innerRef, b.innerRef);
5
5
  };
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.findOrGenerateResponsiveLayout = findOrGenerateResponsiveLayout;
6
7
  exports.getBreakpointFromWidth = getBreakpointFromWidth;
7
8
  exports.getColsFromBreakpoint = getColsFromBreakpoint;
8
- exports.findOrGenerateResponsiveLayout = findOrGenerateResponsiveLayout;
9
9
  exports.sortBreakpoints = sortBreakpoints;
10
10
 
11
11
  var _utils = require("./utils");
package/build/utils.js CHANGED
@@ -4,33 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bottom = bottom;
7
+ exports.childrenEqual = childrenEqual;
7
8
  exports.cloneLayout = cloneLayout;
8
- exports.modifyLayout = modifyLayout;
9
- exports.withLayoutItem = withLayoutItem;
10
9
  exports.cloneLayoutItem = cloneLayoutItem;
11
- exports.childrenEqual = childrenEqual;
12
- exports.fastPositionEqual = fastPositionEqual;
13
10
  exports.collides = collides;
14
11
  exports.compact = compact;
15
12
  exports.compactItem = compactItem;
13
+ exports.compactType = compactType;
16
14
  exports.correctBounds = correctBounds;
17
- exports.getLayoutItem = getLayoutItem;
18
- exports.getFirstCollision = getFirstCollision;
15
+ exports.fastPositionEqual = fastPositionEqual;
16
+ exports.fastRGLPropsEqual = void 0;
19
17
  exports.getAllCollisions = getAllCollisions;
18
+ exports.getFirstCollision = getFirstCollision;
19
+ exports.getLayoutItem = getLayoutItem;
20
20
  exports.getStatics = getStatics;
21
+ exports.modifyLayout = modifyLayout;
21
22
  exports.moveElement = moveElement;
22
23
  exports.moveElementAwayFromCollision = moveElementAwayFromCollision;
24
+ exports.noop = void 0;
23
25
  exports.perc = perc;
24
- exports.setTransform = setTransform;
25
26
  exports.setTopLeft = setTopLeft;
27
+ exports.setTransform = setTransform;
26
28
  exports.sortLayoutItems = sortLayoutItems;
27
- exports.sortLayoutItemsByRowCol = sortLayoutItemsByRowCol;
28
29
  exports.sortLayoutItemsByColRow = sortLayoutItemsByColRow;
30
+ exports.sortLayoutItemsByRowCol = sortLayoutItemsByRowCol;
29
31
  exports.synchronizeLayoutWithChildren = synchronizeLayoutWithChildren;
30
32
  exports.validateLayout = validateLayout;
31
- exports.compactType = compactType;
32
- exports.autoBindHandlers = autoBindHandlers;
33
- exports.noop = exports.fastRGLPropsEqual = void 0;
33
+ exports.withLayoutItem = withLayoutItem;
34
34
 
35
35
  var _lodash = _interopRequireDefault(require("lodash.isequal"));
36
36
 
@@ -38,9 +38,9 @@ var _react = _interopRequireDefault(require("react"));
38
38
 
39
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
40
 
41
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
41
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
42
42
 
43
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
43
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
44
44
 
45
45
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
46
46
 
@@ -164,9 +164,9 @@ function childrenEqual(a
164
164
  /*: boolean*/
165
165
  {
166
166
  return (0, _lodash.default)(_react.default.Children.map(a, function (c) {
167
- return c.key;
167
+ return c === null || c === void 0 ? void 0 : c.key;
168
168
  }), _react.default.Children.map(b, function (c) {
169
- return c.key;
169
+ return c === null || c === void 0 ? void 0 : c.key;
170
170
  }));
171
171
  }
172
172
  /**
@@ -506,6 +506,8 @@ function moveElement(layout
506
506
  /*: CompactType*/
507
507
  , cols
508
508
  /*: number*/
509
+ , allowOverlap
510
+ /*: ?boolean*/
509
511
  )
510
512
  /*: Layout*/
511
513
  {
@@ -529,14 +531,23 @@ function moveElement(layout
529
531
  var movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false; // $FlowIgnore acceptable modification of read-only array as it was recently cloned
530
532
 
531
533
  if (movingUp) sorted = sorted.reverse();
532
- var collisions = getAllCollisions(sorted, l); // There was a collision; abort
533
-
534
- if (preventCollision && collisions.length) {
534
+ var collisions = getAllCollisions(sorted, l);
535
+ var hasCollisions = collisions.length > 0; // We may have collisions. We can short-circuit if we've turned off collisions or
536
+ // allowed overlap.
537
+
538
+ if (hasCollisions && allowOverlap) {
539
+ // Easy, we don't need to resolve collisions. But we *did* change the layout,
540
+ // so clone it on the way out.
541
+ return cloneLayout(layout);
542
+ } else if (hasCollisions && preventCollision) {
543
+ // If we are preventing collision but not allowing overlap, we need to
544
+ // revert the position of this element so it goes to where it came from, rather
545
+ // than the user's desired location.
535
546
  log("Collision prevented on ".concat(l.i, ", reverting."));
536
547
  l.x = oldX;
537
548
  l.y = oldY;
538
549
  l.moved = false;
539
- return layout;
550
+ return layout; // did not change so don't clone
540
551
  } // Move each item that collides away from this element.
541
552
 
542
553
 
@@ -677,7 +688,8 @@ function sortLayoutItems(layout
677
688
  )
678
689
  /*: Layout*/
679
690
  {
680
- if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);else return sortLayoutItemsByRowCol(layout);
691
+ if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);
692
+ if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);else return layout;
681
693
  }
682
694
  /**
683
695
  * Sort layout items by row ascending and column ascending.
@@ -744,6 +756,8 @@ function synchronizeLayoutWithChildren(initialLayout
744
756
  /*: number*/
745
757
  , compactType
746
758
  /*: CompactType*/
759
+ , allowOverlap
760
+ /*: ?boolean*/
747
761
  )
748
762
  /*: Layout*/
749
763
  {
@@ -755,18 +769,17 @@ function synchronizeLayoutWithChildren(initialLayout
755
769
 
756
770
  _react.default.Children.forEach(children, function (child
757
771
  /*: ReactElement<any>*/
758
- , i
759
- /*: number*/
760
772
  ) {
761
- // Don't overwrite if it already exists.
773
+ // Child may not exist
774
+ if ((child === null || child === void 0 ? void 0 : child.key) == null) return; // Don't overwrite if it already exists.
775
+
762
776
  var exists = getLayoutItem(initialLayout, String(child.key));
763
777
 
764
778
  if (exists) {
765
- layout[i] = cloneLayoutItem(exists);
779
+ layout.push(cloneLayoutItem(exists));
766
780
  } else {
767
781
  if (!isProduction && child.props._grid) {
768
- console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + // eslint-disable-line
769
- "Please use `data-grid` or add your properties directly to the `layout`.");
782
+ console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + "Please use `data-grid` or add your properties directly to the `layout`.");
770
783
  }
771
784
 
772
785
  var g = child.props["data-grid"] || child.props._grid; // Hey, this item has a data-grid property, use it.
@@ -777,19 +790,19 @@ function synchronizeLayoutWithChildren(initialLayout
777
790
  } // FIXME clone not really necessary here
778
791
 
779
792
 
780
- layout[i] = cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
793
+ layout.push(cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
781
794
  i: child.key
782
- }));
795
+ })));
783
796
  } else {
784
797
  // Nothing provided: ensure this is added to the bottom
785
798
  // FIXME clone not really necessary here
786
- layout[i] = cloneLayoutItem({
799
+ layout.push(cloneLayoutItem({
787
800
  w: 1,
788
801
  h: 1,
789
802
  x: 0,
790
803
  y: bottom(layout),
791
804
  i: String(child.key)
792
- });
805
+ }));
793
806
  }
794
807
  }
795
808
  }); // Correct the layout.
@@ -798,7 +811,7 @@ function synchronizeLayoutWithChildren(initialLayout
798
811
  var correctedLayout = correctBounds(layout, {
799
812
  cols: cols
800
813
  });
801
- return compact(correctedLayout, compactType, cols);
814
+ return allowOverlap ? correctedLayout : compact(correctedLayout, compactType, cols);
802
815
  }
803
816
  /**
804
817
  * Validate a layout. Throws errors.
@@ -828,14 +841,6 @@ function validateLayout(layout
828
841
  throw new Error("ReactGridLayout: " + contextName + "[" + i + "]." + subProps[j] + " must be a number!");
829
842
  }
830
843
  }
831
-
832
- if (item.i && typeof item.i !== "string") {
833
- throw new Error("ReactGridLayout: " + contextName + "[" + i + "].i must be a string!");
834
- }
835
-
836
- if (item.static !== undefined && typeof item.static !== "boolean") {
837
- throw new Error("ReactGridLayout: " + contextName + "[" + i + "].static must be a boolean!");
838
- }
839
844
  }
840
845
  } // Legacy support for verticalCompact: false
841
846
 
@@ -850,19 +855,6 @@ function compactType(props
850
855
  compactType = _ref3.compactType;
851
856
 
852
857
  return verticalCompact === false ? null : compactType;
853
- } // Flow can't really figure this out, so we just use Object
854
-
855
-
856
- function autoBindHandlers(el
857
- /*: Object*/
858
- , fns
859
- /*: Array<string>*/
860
- )
861
- /*: void*/
862
- {
863
- fns.forEach(function (key) {
864
- return el[key] = el[key].bind(el);
865
- });
866
858
  }
867
859
 
868
860
  function log() {