react-grid-layout 1.2.3 → 1.3.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.resizeHandleType = exports.resizeHandlesType = void 0;
6
+ exports.resizeHandleType = exports.resizeHandleAxesType = exports.default = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
@@ -21,12 +21,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
  // 'nw' - Northwest handle (top-left)
22
22
  // 'se' - Southeast handle (bottom-right)
23
23
  // 'ne' - Northeast handle (top-right)
24
- var resizeHandlesType
24
+ var resizeHandleAxesType
25
25
  /*: ReactPropsChainableTypeChecker*/
26
26
  = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])); // Custom component for resize handles
27
27
 
28
28
 
29
- exports.resizeHandlesType = resizeHandlesType;
29
+ exports.resizeHandleAxesType = resizeHandleAxesType;
30
30
 
31
31
  var resizeHandleType
32
32
  /*: ReactPropsChainableTypeChecker*/
@@ -54,8 +54,9 @@ var resizeHandleType
54
54
  useCSSTransforms: boolean,
55
55
  transformScale: number,
56
56
  droppingItem: $Shape<LayoutItem>,
57
- resizeHandles: ResizeHandles,
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
@@ -156,7 +160,7 @@ var _default = {
156
160
  // If true, an external element can trigger onDrop callback with a specific grid position as a parameter
157
161
  isDroppable: _propTypes.default.bool,
158
162
  // Resize handle options
159
- resizeHandles: resizeHandlesType,
163
+ resizeHandles: resizeHandleAxesType,
160
164
  resizeHandle: resizeHandleType,
161
165
  //
162
166
  // Callbacks
@@ -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,11 +19,13 @@ 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
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
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); }
25
27
 
26
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
29
 
28
30
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
29
31
 
@@ -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,11 +11,15 @@ var React = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
+ var _clsx = _interopRequireDefault(require("clsx"));
15
+
16
+ var _excluded = ["measureBeforeMount"];
17
+
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
19
 
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
20
+ 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); }
17
21
 
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
23
 
20
24
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
25
 
@@ -27,15 +31,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
27
31
 
28
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); } }
29
33
 
30
- 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; }
31
35
 
32
- 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); }
33
37
 
34
38
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
35
39
 
36
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); }; }
37
41
 
38
- 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); }
39
43
 
40
44
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
41
45
 
@@ -45,12 +49,14 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
45
49
 
46
50
  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; }
47
51
 
52
+ var layoutClassName = "react-grid-layout";
48
53
  /*
49
54
  * A simple HOC that provides facility for listening to container resizes.
50
55
  *
51
56
  * The Flow type is pretty janky here. I can't just spread `WPProps` into this returned object - I wish I could - but it triggers
52
57
  * a flow bug of some sort that causes it to stop typechecking.
53
58
  */
59
+
54
60
  function WidthProvideRGL
55
61
  /*:: <Config>*/
56
62
  (ComposedComponent
@@ -82,10 +88,15 @@ function WidthProvideRGL
82
88
 
83
89
  _defineProperty(_assertThisInitialized(_this), "elementRef", /*#__PURE__*/React.createRef());
84
90
 
91
+ _defineProperty(_assertThisInitialized(_this), "mounted", false);
92
+
85
93
  _defineProperty(_assertThisInitialized(_this), "onWindowResize", function () {
94
+ if (!_this.mounted) return;
86
95
  var node = _this.elementRef.current; // Flow casts this to Text | Element
96
+ // fix: grid position error when node or parentNode display is none by window resize
97
+ // #924 #1084
87
98
 
88
- if (node instanceof HTMLElement) {
99
+ if (node instanceof HTMLElement && node.offsetWidth) {
89
100
  _this.setState({
90
101
  width: node.offsetWidth
91
102
  });
@@ -98,6 +109,7 @@ function WidthProvideRGL
98
109
  _createClass(WidthProvider, [{
99
110
  key: "componentDidMount",
100
111
  value: function componentDidMount() {
112
+ this.mounted = true;
101
113
  window.addEventListener("resize", this.onWindowResize); // Call to properly set the breakpoint and resize the elements.
102
114
  // Note that if you're doing a full-width element, this can get a little wonky if a scrollbar
103
115
  // appears because of the grid. In that case, fire your own resize event, or set `overflow: scroll` on your body.
@@ -107,6 +119,7 @@ function WidthProvideRGL
107
119
  }, {
108
120
  key: "componentWillUnmount",
109
121
  value: function componentWillUnmount() {
122
+ this.mounted = false;
110
123
  window.removeEventListener("resize", this.onWindowResize);
111
124
  }
112
125
  }, {
@@ -114,16 +127,16 @@ function WidthProvideRGL
114
127
  value: function render() {
115
128
  var _this$props = this.props,
116
129
  measureBeforeMount = _this$props.measureBeforeMount,
117
- rest = _objectWithoutProperties(_this$props, ["measureBeforeMount"]);
118
-
119
- if (measureBeforeMount && !this.elementRef.current
120
- /* unmounted */
121
- ) {
122
- return /*#__PURE__*/React.createElement("div", {
123
- className: this.props.className,
124
- style: this.props.style
125
- });
126
- }
130
+ rest = _objectWithoutProperties(_this$props, _excluded);
131
+
132
+ if (measureBeforeMount && !this.mounted) {
133
+ return /*#__PURE__*/React.createElement("div", {
134
+ className: (0, _clsx.default)(this.props.className, layoutClassName),
135
+ style: this.props.style // $FlowIgnore ref types
136
+ ,
137
+ ref: this.elementRef
138
+ });
139
+ }
127
140
 
128
141
  return /*#__PURE__*/React.createElement(ComposedComponent, _extends({
129
142
  innerRef: 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
  /**
@@ -362,8 +362,11 @@ function compactItem(compareWith
362
362
  l.x = cols - l.w;
363
363
  l.y++;
364
364
  }
365
- }
365
+ } // Ensure that there are no negative positions
366
366
 
367
+
368
+ l.y = Math.max(l.y, 0);
369
+ l.x = Math.max(l.x, 0);
367
370
  return l;
368
371
  }
369
372
  /**
@@ -503,6 +506,8 @@ function moveElement(layout
503
506
  /*: CompactType*/
504
507
  , cols
505
508
  /*: number*/
509
+ , allowOverlap
510
+ /*: ?boolean*/
506
511
  )
507
512
  /*: Layout*/
508
513
  {
@@ -526,14 +531,23 @@ function moveElement(layout
526
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
527
532
 
528
533
  if (movingUp) sorted = sorted.reverse();
529
- var collisions = getAllCollisions(sorted, l); // There was a collision; abort
530
-
531
- 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.
532
546
  log("Collision prevented on ".concat(l.i, ", reverting."));
533
547
  l.x = oldX;
534
548
  l.y = oldY;
535
549
  l.moved = false;
536
- return layout;
550
+ return layout; // did not change so don't clone
537
551
  } // Move each item that collides away from this element.
538
552
 
539
553
 
@@ -674,7 +688,8 @@ function sortLayoutItems(layout
674
688
  )
675
689
  /*: Layout*/
676
690
  {
677
- 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;
678
693
  }
679
694
  /**
680
695
  * Sort layout items by row ascending and column ascending.
@@ -741,6 +756,8 @@ function synchronizeLayoutWithChildren(initialLayout
741
756
  /*: number*/
742
757
  , compactType
743
758
  /*: CompactType*/
759
+ , allowOverlap
760
+ /*: ?boolean*/
744
761
  )
745
762
  /*: Layout*/
746
763
  {
@@ -752,14 +769,14 @@ function synchronizeLayoutWithChildren(initialLayout
752
769
 
753
770
  _react.default.Children.forEach(children, function (child
754
771
  /*: ReactElement<any>*/
755
- , i
756
- /*: number*/
757
772
  ) {
758
- // 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
+
759
776
  var exists = getLayoutItem(initialLayout, String(child.key));
760
777
 
761
778
  if (exists) {
762
- layout[i] = cloneLayoutItem(exists);
779
+ layout.push(cloneLayoutItem(exists));
763
780
  } else {
764
781
  if (!isProduction && child.props._grid) {
765
782
  console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + // eslint-disable-line
@@ -774,19 +791,19 @@ function synchronizeLayoutWithChildren(initialLayout
774
791
  } // FIXME clone not really necessary here
775
792
 
776
793
 
777
- layout[i] = cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
794
+ layout.push(cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
778
795
  i: child.key
779
- }));
796
+ })));
780
797
  } else {
781
798
  // Nothing provided: ensure this is added to the bottom
782
799
  // FIXME clone not really necessary here
783
- layout[i] = cloneLayoutItem({
800
+ layout.push(cloneLayoutItem({
784
801
  w: 1,
785
802
  h: 1,
786
803
  x: 0,
787
804
  y: bottom(layout),
788
805
  i: String(child.key)
789
- });
806
+ }));
790
807
  }
791
808
  }
792
809
  }); // Correct the layout.
@@ -795,7 +812,7 @@ function synchronizeLayoutWithChildren(initialLayout
795
812
  var correctedLayout = correctBounds(layout, {
796
813
  cols: cols
797
814
  });
798
- return compact(correctedLayout, compactType, cols);
815
+ return allowOverlap ? correctedLayout : compact(correctedLayout, compactType, cols);
799
816
  }
800
817
  /**
801
818
  * Validate a layout. Throws errors.
@@ -847,19 +864,6 @@ function compactType(props
847
864
  compactType = _ref3.compactType;
848
865
 
849
866
  return verticalCompact === false ? null : compactType;
850
- } // Flow can't really figure this out, so we just use Object
851
-
852
-
853
- function autoBindHandlers(el
854
- /*: Object*/
855
- , fns
856
- /*: Array<string>*/
857
- )
858
- /*: void*/
859
- {
860
- fns.forEach(function (key) {
861
- return el[key] = el[key].bind(el);
862
- });
863
867
  }
864
868
 
865
869
  function log() {