react-grid-layout 1.1.0 → 1.2.2

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.
@@ -1,11 +1,13 @@
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); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.default = void 0;
7
9
 
8
- var _react = _interopRequireDefault(require("react"));
10
+ var React = _interopRequireWildcard(require("react"));
9
11
 
10
12
  var _lodash = _interopRequireDefault(require("lodash.isequal"));
11
13
 
@@ -21,7 +23,17 @@ var _ReactGridLayoutPropTypes = _interopRequireDefault(require("./ReactGridLayou
21
23
 
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
- 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); }
26
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
27
+
28
+ 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; }
29
+
30
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
+
32
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
+
34
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
35
+
36
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
37
 
26
38
  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; }
27
39
 
@@ -55,7 +67,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
55
67
 
56
68
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
57
69
 
58
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
70
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
59
71
 
60
72
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
61
73
 
@@ -109,13 +121,16 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
109
121
 
110
122
  _defineProperty(_assertThisInitialized(_this), "dragEnterCounter", 0);
111
123
 
112
- _defineProperty(_assertThisInitialized(_this), "onDragOver", function (e
113
- /*: DragOverEvent*/
114
- ) {
124
+ _defineProperty(_assertThisInitialized(_this), "onDragOver", function (e) {
125
+ var _e$nativeEvent$target;
126
+
115
127
  // we should ignore events from layout's children in Firefox
116
128
  // to avoid unpredictable jumping of a dropping placeholder
117
129
  // FIXME remove this hack
118
- if (isFirefox && e.nativeEvent.target.className.indexOf(layoutClassName) === -1) {
130
+ if (isFirefox && // $FlowIgnore can't figure this out
131
+ !((_e$nativeEvent$target = e.nativeEvent.target) !== null && _e$nativeEvent$target !== void 0 && _e$nativeEvent$target.classList.contains(layoutClassName))) {
132
+ // without this Firefox will not allow drop if currently over droppingItem
133
+ e.preventDefault();
119
134
  return false;
120
135
  }
121
136
 
@@ -152,7 +167,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
152
167
  var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, droppingItem.w, droppingItem.h);
153
168
 
154
169
  _this.setState({
155
- droppingDOMNode: /*#__PURE__*/_react.default.createElement("div", {
170
+ droppingDOMNode: /*#__PURE__*/React.createElement("div", {
156
171
  key: droppingItem.i
157
172
  }),
158
173
  droppingPosition: droppingPosition,
@@ -220,7 +235,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
220
235
  var layout = _this.state.layout;
221
236
  var item = layout.find(function (l) {
222
237
  return l.i === droppingItem.i;
223
- }); // reset gragEnter counter on drop
238
+ }); // reset dragEnter counter on drop
224
239
 
225
240
  _this.dragEnterCounter = 0;
226
241
 
@@ -249,7 +264,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
249
264
  /*: Props*/
250
265
  , nextState
251
266
  /*: State*/
252
- ) {
267
+ )
268
+ /*: boolean*/
269
+ {
253
270
  return (// NOTE: this is almost always unequal. Therefore the only way to get better performance
254
271
  // from SCU is if the user intentionally memoizes children. If they do, and they can
255
272
  // handle changes properly, performance will increase.
@@ -276,7 +293,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
276
293
 
277
294
  }, {
278
295
  key: "containerHeight",
279
- value: function containerHeight() {
296
+ value: function containerHeight()
297
+ /*: ?string*/
298
+ {
280
299
  if (!this.props.autoSize) return;
281
300
  var nbRow = (0, _utils.bottom)(this.state.layout);
282
301
  var containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
@@ -299,7 +318,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
299
318
  /*: number*/
300
319
  , y
301
320
  /*: number*/
302
- , _ref) {
321
+ , _ref)
322
+ /*: void*/
323
+ {
303
324
  var e = _ref.e,
304
325
  node = _ref.node;
305
326
  var layout = this.state.layout;
@@ -328,7 +349,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
328
349
  /*: number*/
329
350
  , y
330
351
  /*: number*/
331
- , _ref2) {
352
+ , _ref2)
353
+ /*: void*/
354
+ {
332
355
  var e = _ref2.e,
333
356
  node = _ref2.node;
334
357
  var oldDragItem = this.state.oldDragItem;
@@ -371,7 +394,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
371
394
  /*: number*/
372
395
  , y
373
396
  /*: number*/
374
- , _ref3) {
397
+ , _ref3)
398
+ /*: void*/
399
+ {
375
400
  var e = _ref3.e,
376
401
  node = _ref3.node;
377
402
  if (!this.state.activeDrag) return;
@@ -447,42 +472,48 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
447
472
  var _this$props4 = this.props,
448
473
  cols = _this$props4.cols,
449
474
  preventCollision = _this$props4.preventCollision;
450
- var l
451
- /*: ?LayoutItem*/
452
- = (0, _utils.getLayoutItem)(layout, i);
453
- if (!l) return; // Something like quad tree should be used
454
- // to find collisions faster
455
-
456
- var hasCollisions;
457
-
458
- if (preventCollision) {
459
- var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
460
- w: w,
461
- h: h
462
- })).filter(function (layoutItem) {
463
- return layoutItem.i !== l.i;
464
- });
465
- hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
466
-
467
- if (hasCollisions) {
468
- // adjust w && h to maximum allowed space
469
- var leastX = Infinity,
470
- leastY = Infinity;
471
- collisions.forEach(function (layoutItem) {
472
- if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
473
- if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
475
+
476
+ var _withLayoutItem = (0, _utils.withLayoutItem)(layout, i, function (l) {
477
+ // Something like quad tree should be used
478
+ // to find collisions faster
479
+ var hasCollisions;
480
+
481
+ if (preventCollision) {
482
+ var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
483
+ w: w,
484
+ h: h
485
+ })).filter(function (layoutItem) {
486
+ return layoutItem.i !== l.i;
474
487
  });
475
- if (Number.isFinite(leastX)) l.w = leastX - l.x;
476
- if (Number.isFinite(leastY)) l.h = leastY - l.y;
488
+ hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
489
+
490
+ if (hasCollisions) {
491
+ // adjust w && h to maximum allowed space
492
+ var leastX = Infinity,
493
+ leastY = Infinity;
494
+ collisions.forEach(function (layoutItem) {
495
+ if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
496
+ if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
497
+ });
498
+ if (Number.isFinite(leastX)) l.w = leastX - l.x;
499
+ if (Number.isFinite(leastY)) l.h = leastY - l.y;
500
+ }
477
501
  }
478
- }
479
502
 
480
- if (!hasCollisions) {
481
- // Set new width and height.
482
- l.w = w;
483
- l.h = h;
484
- } // Create placeholder element (display only)
503
+ if (!hasCollisions) {
504
+ // Set new width and height.
505
+ l.w = w;
506
+ l.h = h;
507
+ }
508
+
509
+ return l;
510
+ }),
511
+ _withLayoutItem2 = _slicedToArray(_withLayoutItem, 2),
512
+ newLayout = _withLayoutItem2[0],
513
+ l = _withLayoutItem2[1]; // Shouldn't ever happen, but typechecking makes it necessary
514
+
485
515
 
516
+ if (!l) return; // Create placeholder element (display only)
486
517
 
487
518
  var placeholder = {
488
519
  w: l.w,
@@ -492,10 +523,10 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
492
523
  static: true,
493
524
  i: i
494
525
  };
495
- this.props.onResize(layout, oldResizeItem, l, placeholder, e, node); // Re-compact the layout and set the drag placeholder.
526
+ this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node); // Re-compact the newLayout and set the drag placeholder.
496
527
 
497
528
  this.setState({
498
- layout: (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
529
+ layout: (0, _utils.compact)(newLayout, (0, _utils.compactType)(this.props), cols),
499
530
  activeDrag: placeholder
500
531
  });
501
532
  }
@@ -549,7 +580,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
549
580
  useCSSTransforms = _this$props5.useCSSTransforms,
550
581
  transformScale = _this$props5.transformScale; // {...this.state.activeDrag} is pretty slow, actually
551
582
 
552
- return /*#__PURE__*/_react.default.createElement(_GridItem.default, {
583
+ return /*#__PURE__*/React.createElement(_GridItem.default, {
553
584
  w: activeDrag.w,
554
585
  h: activeDrag.h,
555
586
  x: activeDrag.x,
@@ -567,7 +598,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
567
598
  isBounded: false,
568
599
  useCSSTransforms: useCSSTransforms,
569
600
  transformScale: transformScale
570
- }, /*#__PURE__*/_react.default.createElement("div", null));
601
+ }, /*#__PURE__*/React.createElement("div", null));
571
602
  }
572
603
  /**
573
604
  * Given a grid item, set its style attributes & surround in a <Draggable>.
@@ -601,7 +632,8 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
601
632
  transformScale = _this$props6.transformScale,
602
633
  draggableCancel = _this$props6.draggableCancel,
603
634
  draggableHandle = _this$props6.draggableHandle,
604
- resizeHandles = _this$props6.resizeHandles;
635
+ resizeHandles = _this$props6.resizeHandles,
636
+ resizeHandle = _this$props6.resizeHandle;
605
637
  var _this$state3 = this.state,
606
638
  mounted = _this$state3.mounted,
607
639
  droppingPosition = _this$state3.droppingPosition; // Determine user manipulations possible.
@@ -613,7 +645,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
613
645
  var resizeHandlesOptions = l.resizeHandles || resizeHandles; // isBounded set on child if set on parent, and child is not explicitly false
614
646
 
615
647
  var bounded = draggable && isBounded && l.isBounded !== false;
616
- return /*#__PURE__*/_react.default.createElement(_GridItem.default, {
648
+ return /*#__PURE__*/React.createElement(_GridItem.default, {
617
649
  containerWidth: width,
618
650
  cols: cols,
619
651
  margin: margin,
@@ -645,14 +677,17 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
645
677
  maxW: l.maxW,
646
678
  static: l.static,
647
679
  droppingPosition: isDroppingItem ? droppingPosition : undefined,
648
- resizeHandles: resizeHandlesOptions
680
+ resizeHandles: resizeHandlesOptions,
681
+ resizeHandle: resizeHandle
649
682
  }, child);
650
683
  } // Called while dragging an element. Part of browser native drag/drop API.
651
684
  // Native event target might be the layout itself, or an element within the layout.
652
685
 
653
686
  }, {
654
687
  key: "render",
655
- value: function render() {
688
+ value: function render()
689
+ /*: React.Element<"div">*/
690
+ {
656
691
  var _this2 = this;
657
692
 
658
693
  var _this$props7 = this.props,
@@ -666,7 +701,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
666
701
  height: this.containerHeight()
667
702
  }, style);
668
703
 
669
- return /*#__PURE__*/_react.default.createElement("div", {
704
+ return /*#__PURE__*/React.createElement("div", {
670
705
  ref: innerRef,
671
706
  className: mergedClassName,
672
707
  style: mergedStyle,
@@ -674,7 +709,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
674
709
  onDragLeave: isDroppable ? this.onDragLeave : _utils.noop,
675
710
  onDragEnter: isDroppable ? this.onDragEnter : _utils.noop,
676
711
  onDragOver: isDroppable ? this.onDragOver : _utils.noop
677
- }, _react.default.Children.map(this.props.children, function (child) {
712
+ }, React.Children.map(this.props.children, function (child) {
678
713
  return _this2.processGridItem(child);
679
714
  }), isDroppable && this.state.droppingDOMNode && this.processGridItem(this.state.droppingDOMNode, true), this.placeholder());
680
715
  }
@@ -684,7 +719,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
684
719
  /*: Props*/
685
720
  , prevState
686
721
  /*: State*/
687
- ) {
722
+ )
723
+ /*: $Shape<State> | null*/
724
+ {
688
725
  var newLayoutBase;
689
726
 
690
727
  if (prevState.activeDrag) {
@@ -720,7 +757,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
720
757
  }]);
721
758
 
722
759
  return ReactGridLayout;
723
- }(_react.default.Component);
760
+ }(React.Component);
724
761
 
725
762
  exports.default = ReactGridLayout;
726
763
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.resizeHandleType = exports.resizeHandlesType = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
@@ -11,6 +11,75 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
+ // Defines which resize handles should be rendered (default: 'se')
15
+ // Allows for any combination of:
16
+ // 's' - South handle (bottom-center)
17
+ // 'w' - West handle (left-center)
18
+ // 'e' - East handle (right-center)
19
+ // 'n' - North handle (top-center)
20
+ // 'sw' - Southwest handle (bottom-left)
21
+ // 'nw' - Northwest handle (top-left)
22
+ // 'se' - Southeast handle (bottom-right)
23
+ // 'ne' - Northeast handle (top-right)
24
+ var resizeHandlesType
25
+ /*: ReactPropsChainableTypeChecker*/
26
+ = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])); // Custom component for resize handles
27
+
28
+
29
+ exports.resizeHandlesType = resizeHandlesType;
30
+
31
+ var resizeHandleType
32
+ /*: ReactPropsChainableTypeChecker*/
33
+ = _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
34
+ /*:: export type Props = {|
35
+ className: string,
36
+ style: Object,
37
+ width: number,
38
+ autoSize: boolean,
39
+ cols: number,
40
+ draggableCancel: string,
41
+ draggableHandle: string,
42
+ verticalCompact: boolean,
43
+ compactType: CompactType,
44
+ layout: Layout,
45
+ margin: [number, number],
46
+ containerPadding: ?[number, number],
47
+ rowHeight: number,
48
+ maxRows: number,
49
+ isBounded: boolean,
50
+ isDraggable: boolean,
51
+ isResizable: boolean,
52
+ isDroppable: boolean,
53
+ preventCollision: boolean,
54
+ useCSSTransforms: boolean,
55
+ transformScale: number,
56
+ droppingItem: $Shape<LayoutItem>,
57
+ resizeHandles: ResizeHandles,
58
+ resizeHandle?: ResizeHandle,
59
+
60
+ // Callbacks
61
+ onLayoutChange: Layout => void,
62
+ onDrag: EventCallback,
63
+ onDragStart: EventCallback,
64
+ onDragStop: EventCallback,
65
+ onResize: EventCallback,
66
+ onResizeStart: EventCallback,
67
+ onResizeStop: EventCallback,
68
+ onDrop: (layout: Layout, item: ?LayoutItem, e: Event) => void,
69
+ children: ReactChildrenArray<ReactElement<any>>,
70
+ innerRef?: Ref<"div">
71
+ |};*/
72
+
73
+ /*:: export type DefaultProps = $Diff<
74
+ Props,
75
+ {
76
+ children: ReactChildrenArray<ReactElement<any>>,
77
+ width: number
78
+ }
79
+ >;*/
80
+
81
+
82
+ exports.resizeHandleType = resizeHandleType;
14
83
  var _default = {
15
84
  //
16
85
  // Basic props
@@ -39,7 +108,9 @@ var _default = {
39
108
  }
40
109
  },
41
110
  // Choose vertical or hotizontal compaction
42
- compactType: _propTypes.default.oneOf(["vertical", "horizontal"]),
111
+ compactType: (_propTypes.default.oneOf(["vertical", "horizontal"])
112
+ /*: ReactPropsChainableTypeChecker*/
113
+ ),
43
114
  // layout is an array of object with the format:
44
115
  // {x: Number, y: Number, w: Number, h: Number, i: String}
45
116
  layout: function layout(props
@@ -55,9 +126,13 @@ var _default = {
55
126
  // Grid Dimensions
56
127
  //
57
128
  // Margin between items [x, y] in px
58
- margin: _propTypes.default.arrayOf(_propTypes.default.number),
129
+ margin: (_propTypes.default.arrayOf(_propTypes.default.number)
130
+ /*: ReactPropsChainableTypeChecker*/
131
+ ),
59
132
  // Padding inside the container [x, y] in px
60
- containerPadding: _propTypes.default.arrayOf(_propTypes.default.number),
133
+ containerPadding: (_propTypes.default.arrayOf(_propTypes.default.number)
134
+ /*: ReactPropsChainableTypeChecker*/
135
+ ),
61
136
  // Rows have a static height, but you can change this based on breakpoints if you like
62
137
  rowHeight: _propTypes.default.number,
63
138
  // Default Infinity, but you can specify a max here if you like.
@@ -80,17 +155,9 @@ var _default = {
80
155
  transformScale: _propTypes.default.number,
81
156
  // If true, an external element can trigger onDrop callback with a specific grid position as a parameter
82
157
  isDroppable: _propTypes.default.bool,
83
- // Defines which resize handles should be rendered (default: 'se')
84
- // Allows for any combination of:
85
- // 's' - South handle (bottom-center)
86
- // 'w' - West handle (left-center)
87
- // 'e' - East handle (right-center)
88
- // 'n' - North handle (top-center)
89
- // 'sw' - Southwest handle (bottom-left)
90
- // 'nw' - Northwest handle (top-left)
91
- // 'se' - Southeast handle (bottom-right)
92
- // 'ne' - Northeast handle (top-right)
93
- resizeHandles: _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])),
158
+ // Resize handle options
159
+ resizeHandles: resizeHandlesType,
160
+ resizeHandle: resizeHandleType,
94
161
  //
95
162
  // Callbacks
96
163
  //
@@ -114,11 +181,13 @@ var _default = {
114
181
  //
115
182
  // Other validations
116
183
  //
117
- droppingItem: _propTypes.default.shape({
184
+ droppingItem: (_propTypes.default.shape({
118
185
  i: _propTypes.default.string.isRequired,
119
186
  w: _propTypes.default.number.isRequired,
120
187
  h: _propTypes.default.number.isRequired
121
- }),
188
+ })
189
+ /*: ReactPropsChainableTypeChecker*/
190
+ ),
122
191
  // Children must not have duplicate keys.
123
192
  children: function children(props
124
193
  /*: Props*/
@@ -1,5 +1,7 @@
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); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -23,8 +25,6 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
23
25
 
24
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; }
25
27
 
26
- 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); }
27
-
28
28
  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
29
 
30
30
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
@@ -51,7 +51,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
51
51
 
52
52
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
53
53
 
54
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
54
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
55
55
 
56
56
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
57
57
 
@@ -78,15 +78,16 @@ function getIndentationValue
78
78
  )
79
79
  /*: T*/
80
80
  {
81
- // $FlowIssue doesn't seem to understand this
82
- if (param == null) return null;
81
+ // $FlowIgnore TODO fix this typedef
82
+ if (param == null) return null; // $FlowIgnore TODO fix this typedef
83
+
83
84
  return Array.isArray(param) ? param : param[breakpoint];
84
85
  }
85
86
  /*:: type State = {
86
87
  layout: Layout,
87
88
  breakpoint: string,
88
89
  cols: number,
89
- layouts?: { [key: string]: Layout }
90
+ layouts?: ResponsiveLayout<string>
90
91
  };*/
91
92
 
92
93
  /*:: type Props<Breakpoint: string = string> = {|
@@ -104,7 +105,7 @@ function getIndentationValue
104
105
 
105
106
  // Callbacks
106
107
  onBreakpointChange: (Breakpoint, cols: number) => void,
107
- onLayoutChange: (Layout, { [key: Breakpoint]: Layout }) => void,
108
+ onLayoutChange: OnLayoutChangeCallback,
108
109
  onWidthChange: (
109
110
  containerWidth: number,
110
111
  margin: [number, number],
@@ -113,6 +114,20 @@ function getIndentationValue
113
114
  ) => void
114
115
  |};*/
115
116
 
117
+ /*:: type DefaultProps = Pick<
118
+ Props<>,
119
+ {|
120
+ breakpoints: 0,
121
+ cols: 0,
122
+ containerPadding: 0,
123
+ layouts: 0,
124
+ margin: 0,
125
+ onBreakpointChange: 0,
126
+ onLayoutChange: 0,
127
+ onWidthChange: 0
128
+ |}
129
+ >;*/
130
+
116
131
 
117
132
  var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
118
133
  _inherits(ResponsiveReactGridLayout, _React$Component);
@@ -177,12 +192,12 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
177
192
 
178
193
  }, {
179
194
  key: "onWidthChange",
180
-
195
+ value:
181
196
  /**
182
197
  * When the width changes work through breakpoints and reset state with the new width & breakpoint.
183
198
  * Width changes are necessary to figure out the widget widths.
184
199
  */
185
- value: function onWidthChange(prevProps
200
+ function onWidthChange(prevProps
186
201
  /*: Props<*>*/
187
202
  ) {
188
203
  var _this$props2 = this.props,
@@ -225,7 +240,9 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
225
240
  }
226
241
  }, {
227
242
  key: "render",
228
- value: function render() {
243
+ value: function render()
244
+ /*: React.Element<typeof ReactGridLayout>*/
245
+ {
229
246
  /* eslint-disable no-unused-vars */
230
247
  var _this$props3 = this.props,
231
248
  breakpoint = _this$props3.breakpoint,
@@ -242,6 +259,7 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
242
259
 
243
260
 
244
261
  return /*#__PURE__*/React.createElement(_ReactGridLayout.default, _extends({}, other, {
262
+ // $FlowIgnore should allow nullable here due to DefaultProps
245
263
  margin: getIndentationValue(margin, this.state.breakpoint),
246
264
  containerPadding: getIndentationValue(containerPadding, this.state.breakpoint),
247
265
  onLayoutChange: this.onLayoutChange,
@@ -255,7 +273,9 @@ var ResponsiveReactGridLayout = /*#__PURE__*/function (_React$Component) {
255
273
  /*: Props<*>*/
256
274
  , prevState
257
275
  /*: State*/
258
- ) {
276
+ )
277
+ /*: ?$Shape<State>*/
278
+ {
259
279
  if (!(0, _lodash.default)(nextProps.layouts, prevState.layouts)) {
260
280
  // Allow parent to set layouts directly.
261
281
  var breakpoint = prevState.breakpoint,
@@ -348,8 +368,6 @@ _defineProperty(ResponsiveReactGridLayout, "defaultProps", {
348
368
  xs: 4,
349
369
  xxs: 2
350
370
  },
351
- layouts: {},
352
- margin: [10, 10],
353
371
  containerPadding: {
354
372
  lg: null,
355
373
  md: null,
@@ -357,6 +375,8 @@ _defineProperty(ResponsiveReactGridLayout, "defaultProps", {
357
375
  xs: null,
358
376
  xxs: null
359
377
  },
378
+ layouts: {},
379
+ margin: [10, 10],
360
380
  onBreakpointChange: _utils.noop,
361
381
  onLayoutChange: _utils.noop,
362
382
  onWidthChange: _utils.noop
@@ -43,7 +43,9 @@ function calcGridItemWHPx(gridUnits
43
43
  /*: number*/
44
44
  , marginPx
45
45
  /*: number*/
46
- ) {
46
+ )
47
+ /*: number*/
48
+ {
47
49
  // 0 * Infinity === NaN, which causes problems with resize contraints
48
50
  if (!Number.isFinite(gridUnits)) return gridUnits;
49
51
  return Math.round(colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx);
@@ -198,6 +200,8 @@ function clamp(num
198
200
  /*: number*/
199
201
  , upperBound
200
202
  /*: number*/
201
- ) {
203
+ )
204
+ /*: number*/
205
+ {
202
206
  return Math.max(Math.min(num, upperBound), lowerBound);
203
207
  }
@@ -1,5 +1,7 @@
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); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -17,8 +19,6 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
17
19
 
18
20
  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; }
19
21
 
20
- 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); }
21
-
22
22
  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); }
23
23
 
24
24
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
@@ -41,7 +41,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
41
41
 
42
42
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
43
43
 
44
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
44
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
45
45
 
46
46
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
47
47