react-grid-layout 1.2.5 → 1.3.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.
@@ -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
  }
@@ -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); }
@@ -47,7 +49,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
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
@@ -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
  }
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
 
16
+ var _excluded = ["measureBeforeMount"];
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
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); }
@@ -37,7 +39,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
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,7 +127,7 @@ 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", {
@@ -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
  };
package/build/utils.js CHANGED
@@ -29,7 +29,6 @@ exports.sortLayoutItemsByColRow = sortLayoutItemsByColRow;
29
29
  exports.synchronizeLayoutWithChildren = synchronizeLayoutWithChildren;
30
30
  exports.validateLayout = validateLayout;
31
31
  exports.compactType = compactType;
32
- exports.autoBindHandlers = autoBindHandlers;
33
32
  exports.noop = exports.fastRGLPropsEqual = void 0;
34
33
 
35
34
  var _lodash = _interopRequireDefault(require("lodash.isequal"));
@@ -164,9 +163,9 @@ function childrenEqual(a
164
163
  /*: boolean*/
165
164
  {
166
165
  return (0, _lodash.default)(_react.default.Children.map(a, function (c) {
167
- return c.key;
166
+ return c === null || c === void 0 ? void 0 : c.key;
168
167
  }), _react.default.Children.map(b, function (c) {
169
- return c.key;
168
+ return c === null || c === void 0 ? void 0 : c.key;
170
169
  }));
171
170
  }
172
171
  /**
@@ -506,6 +505,8 @@ function moveElement(layout
506
505
  /*: CompactType*/
507
506
  , cols
508
507
  /*: number*/
508
+ , allowOverlap
509
+ /*: ?boolean*/
509
510
  )
510
511
  /*: Layout*/
511
512
  {
@@ -532,10 +533,13 @@ function moveElement(layout
532
533
  var collisions = getAllCollisions(sorted, l); // There was a collision; abort
533
534
 
534
535
  if (preventCollision && collisions.length) {
535
- log("Collision prevented on ".concat(l.i, ", reverting."));
536
- l.x = oldX;
537
- l.y = oldY;
538
- l.moved = false;
536
+ if (!allowOverlap) {
537
+ log("Collision prevented on ".concat(l.i, ", reverting."));
538
+ l.x = oldX;
539
+ l.y = oldY;
540
+ l.moved = false;
541
+ }
542
+
539
543
  return layout;
540
544
  } // Move each item that collides away from this element.
541
545
 
@@ -677,7 +681,8 @@ function sortLayoutItems(layout
677
681
  )
678
682
  /*: Layout*/
679
683
  {
680
- if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);else return sortLayoutItemsByRowCol(layout);
684
+ if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);
685
+ if (compactType === "vertical") return sortLayoutItemsByRowCol(layout);else return layout;
681
686
  }
682
687
  /**
683
688
  * Sort layout items by row ascending and column ascending.
@@ -744,6 +749,8 @@ function synchronizeLayoutWithChildren(initialLayout
744
749
  /*: number*/
745
750
  , compactType
746
751
  /*: CompactType*/
752
+ , allowOverlap
753
+ /*: ?boolean*/
747
754
  )
748
755
  /*: Layout*/
749
756
  {
@@ -755,14 +762,14 @@ function synchronizeLayoutWithChildren(initialLayout
755
762
 
756
763
  _react.default.Children.forEach(children, function (child
757
764
  /*: ReactElement<any>*/
758
- , i
759
- /*: number*/
760
765
  ) {
761
- // Don't overwrite if it already exists.
766
+ // Child may not exist
767
+ if ((child === null || child === void 0 ? void 0 : child.key) == null) return; // Don't overwrite if it already exists.
768
+
762
769
  var exists = getLayoutItem(initialLayout, String(child.key));
763
770
 
764
771
  if (exists) {
765
- layout[i] = cloneLayoutItem(exists);
772
+ layout.push(cloneLayoutItem(exists));
766
773
  } else {
767
774
  if (!isProduction && child.props._grid) {
768
775
  console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + // eslint-disable-line
@@ -777,19 +784,19 @@ function synchronizeLayoutWithChildren(initialLayout
777
784
  } // FIXME clone not really necessary here
778
785
 
779
786
 
780
- layout[i] = cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
787
+ layout.push(cloneLayoutItem(_objectSpread(_objectSpread({}, g), {}, {
781
788
  i: child.key
782
- }));
789
+ })));
783
790
  } else {
784
791
  // Nothing provided: ensure this is added to the bottom
785
792
  // FIXME clone not really necessary here
786
- layout[i] = cloneLayoutItem({
793
+ layout.push(cloneLayoutItem({
787
794
  w: 1,
788
795
  h: 1,
789
796
  x: 0,
790
797
  y: bottom(layout),
791
798
  i: String(child.key)
792
- });
799
+ }));
793
800
  }
794
801
  }
795
802
  }); // Correct the layout.
@@ -798,7 +805,7 @@ function synchronizeLayoutWithChildren(initialLayout
798
805
  var correctedLayout = correctBounds(layout, {
799
806
  cols: cols
800
807
  });
801
- return compact(correctedLayout, compactType, cols);
808
+ return allowOverlap ? correctedLayout : compact(correctedLayout, compactType, cols);
802
809
  }
803
810
  /**
804
811
  * Validate a layout. Throws errors.
@@ -850,19 +857,6 @@ function compactType(props
850
857
  compactType = _ref3.compactType;
851
858
 
852
859
  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
860
  }
867
861
 
868
862
  function log() {