react-grid-layout 1.2.0 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.flowconfig CHANGED
@@ -1,5 +1,5 @@
1
1
  [version]
2
- ^0.133.0
2
+ ^0.145.0
3
3
 
4
4
  [ignore]
5
5
  <PROJECT_ROOT>/build/.*
@@ -15,5 +15,6 @@ interfaces/
15
15
  flow-typed/
16
16
 
17
17
  [options]
18
+ sharedmemory.heap_size=3221225472
18
19
  emoji=true
19
20
  module.use_strict=true
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn lint-staged
5
+ make lint
6
+ make test
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Changelog
2
2
 
3
+ 1.2.4 (Mar 18, 2021)
4
+ ---
5
+
6
+ *This version fixes a serious render bug in `<WidthProvider>`. 1.2.3 should not be used.*
7
+
8
+ ### Bugfixes
9
+ - Fix failure to mount when layout is WidthProvider-wrapped and `measureBeforeMount` is `true`.
10
+ - Ref: [#1428](https://github.com/react-grid-layout/react-grid-layout/issues/1428)
11
+ - `<WidthProvider>` no longer updates grid with if it has been set to 0. This prevents unnecessary updates
12
+ if the grid is set to `display: none;`. Thanks @405go [#1427](https://github.com/react-grid-layout/react-grid-layout/pull/1427)
13
+
14
+ 1.2.3 (Mar 16, 2021)
15
+ ---
16
+
17
+ ### New Features
18
+ - React-Grid-Layout is now fully compatible with `<React.StrictMode>`.
19
+ - Usage of `ReactDOM` has been removed by using `React.createRef()` inside RGL, and the new [`nodeRef` prop](https://github.com/react-grid-layout/react-draggable/blob/master/CHANGELOG.md#440-may-12-2020) in `react-draggable`.
20
+
21
+ 1.2.2 (Mar 1, 2021)
22
+ ---
23
+
24
+ ### Bugfixes
25
+ - `onResize` as changed in 1.2.1 did not correctly save the layout. This is now fixed.
26
+ - As you might guess, we need more test coverage! PRs are very welcome, I'll buy you beers on Cashapp or Patreon or whatever you like.
27
+
28
+ 1.2.1 (Mar 1, 2021)
29
+ ---
30
+
31
+ ## Organization Changes
32
+
33
+ We have created the [React-Grid-Layout Organization](https://github.com/react-grid-layout)! Therefore the repository
34
+ [has moved](https://github.com/react-grid-layout/react-grid-layout).
35
+
36
+ This organization will grow as time goes on, and also contains the dependencies of RGL.
37
+
38
+ ### Bugfixes
39
+ - Use `classList` in Firefox onDragOver hack. [#1310](https://github.com/STRML/react-grid-layout/pull/1310)
40
+ - Fix `scale` property. As `scale` support was added to dependencies, this caused double-compensation for scale, causing the dragged element not to follow the cursor. [#1393](https://github.com/STRML/react-grid-layout/pull/1393)
41
+ - Fix horizontal compact mode issue where it inadventently would compact the bottom of the grid. This is not useful nor intended. Thanks @s4m3. [#1390](https://github.com/STRML/react-grid-layout/pull/1390)
42
+ - Fix `onLayoutChange` sometimes not triggering on resize. We weren't cloning the layout item before modifying it. Thanks @xcqwan. [#1289](https://github.com/react-grid-layout/react-grid-layout/pull/1289)
43
+
44
+ ### Internal Refactors
45
+ - Updated to the latest versions of all dependencies (enzyme, webpack, jest, flow).
46
+ - Held back React@17 as enzyme is [not yet ready](https://github.com/enzymejs/enzyme/issues/2429).
47
+
3
48
  1.2.0 (Nov 17, 2020)
4
49
  ---
5
50
 
package/README.md CHANGED
@@ -16,7 +16,7 @@ RGL is React-only and does not require jQuery.
16
16
  ![BitMEX UI](http://i.imgur.com/oo1NT6c.gif)
17
17
  > GIF from production usage on [BitMEX.com](https://www.bitmex.com)
18
18
 
19
- [**[Demo](https://strml.github.io/react-grid-layout/examples/0-showcase.html) | [Changelog](/CHANGELOG.md) | [CodeSandbox Editable demo](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js)**]
19
+ [**[Demo](https://react-grid-layout.github.io/react-grid-layout/) | [Changelog](/CHANGELOG.md) | [CodeSandbox Editable demo](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js)**]
20
20
 
21
21
  ## Table of Contents
22
22
 
@@ -36,24 +36,25 @@ RGL is React-only and does not require jQuery.
36
36
 
37
37
  ## Demos
38
38
 
39
- 1. [Showcase](https://strml.github.io/react-grid-layout/examples/0-showcase.html)
40
- 1. [Basic](https://strml.github.io/react-grid-layout/examples/1-basic.html)
41
- 1. [No Dragging/Resizing (Layout Only)](https://strml.github.io/react-grid-layout/examples/2-no-dragging.html)
42
- 1. [Messy Layout Autocorrect](https://strml.github.io/react-grid-layout/examples/3-messy.html)
43
- 1. [Layout Defined on Children](https://strml.github.io/react-grid-layout/examples/4-grid-property.html)
44
- 1. [Static Elements](https://strml.github.io/react-grid-layout/examples/5-static-elements.html)
45
- 1. [Adding/Removing Elements](https://strml.github.io/react-grid-layout/examples/6-dynamic-add-remove.html)
46
- 1. [Saving Layout to LocalStorage](https://strml.github.io/react-grid-layout/examples/7-localstorage.html)
47
- 1. [Saving a Responsive Layout to LocalStorage](https://strml.github.io/react-grid-layout/examples/8-localstorage-responsive.html)
48
- 1. [Minimum and Maximum Width/Height](https://strml.github.io/react-grid-layout/examples/9-min-max-wh.html)
49
- 1. [Dynamic Minimum and Maximum Width/Height](https://strml.github.io/react-grid-layout/examples/10-dynamic-min-max-wh.html)
50
- 1. [No Vertical Compacting (Free Movement)](https://strml.github.io/react-grid-layout/examples/11-no-vertical-compact.html)
51
- 1. [Prevent Collision](https://strml.github.io/react-grid-layout/examples/12-prevent-collision.html)
52
- 1. [Error Case](https://strml.github.io/react-grid-layout/examples/13-error-case.html)
53
- 1. [Toolbox](https://strml.github.io/react-grid-layout/examples/14-toolbox.html)
54
- 1. [Drag From Outside](https://strml.github.io/react-grid-layout/examples/15-drag-from-outside.html)
55
- 1. [Bounded Layout](https://strml.github.io/react-grid-layout/examples/16-bounded.html)
56
- 1. [Resizable Handles](https://strml.github.io/react-grid-layout/examples/17-resizable-handles.html)
39
+ 1. [Showcase](https://react-grid-layout.github.io/react-grid-layout/examples/0-showcase.html)
40
+ 1. [Basic](https://react-grid-layout.github.io/react-grid-layout/examples/1-basic.html)
41
+ 1. [No Dragging/Resizing (Layout Only)](https://react-grid-layout.github.io/react-grid-layout/examples/2-no-dragging.html)
42
+ 1. [Messy Layout Autocorrect](https://react-grid-layout.github.io/react-grid-layout/examples/3-messy.html)
43
+ 1. [Layout Defined on Children](https://react-grid-layout.github.io/react-grid-layout/examples/4-grid-property.html)
44
+ 1. [Static Elements](https://react-grid-layout.github.io/react-grid-layout/examples/5-static-elements.html)
45
+ 1. [Adding/Removing Elements](https://react-grid-layout.github.io/react-grid-layout/examples/6-dynamic-add-remove.html)
46
+ 1. [Saving Layout to LocalStorage](https://react-grid-layout.github.io/react-grid-layout/examples/7-localstorage.html)
47
+ 1. [Saving a Responsive Layout to LocalStorage](https://react-grid-layout.github.io/react-grid-layout/examples/8-localstorage-responsive.html)
48
+ 1. [Minimum and Maximum Width/Height](https://react-grid-layout.github.io/react-grid-layout/examples/9-min-max-wh.html)
49
+ 1. [Dynamic Minimum and Maximum Width/Height](https://react-grid-layout.github.io/react-grid-layout/examples/10-dynamic-min-max-wh.html)
50
+ 1. [No Vertical Compacting (Free Movement)](https://react-grid-layout.github.io/react-grid-layout/examples/11-no-vertical-compact.html)
51
+ 1. [Prevent Collision](https://react-grid-layout.github.io/react-grid-layout/examples/12-prevent-collision.html)
52
+ 1. [Error Case](https://react-grid-layout.github.io/react-grid-layout/examples/13-error-case.html)
53
+ 1. [Toolbox](https://react-grid-layout.github.io/react-grid-layout/examples/14-toolbox.html)
54
+ 1. [Drag From Outside](https://react-grid-layout.github.io/react-grid-layout/examples/15-drag-from-outside.html)
55
+ 1. [Bounded Layout](https://react-grid-layout.github.io/react-grid-layout/examples/16-bounded.html)
56
+ 1. [Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/17-resizable-handles.html)
57
+ 1. [Scaled Containers](https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html)
57
58
 
58
59
  #### Projects Using React-Grid-Layout
59
60
 
@@ -72,6 +73,7 @@ RGL is React-only and does not require jQuery.
72
73
  - [Quadency](https://quadency.com/)
73
74
  - [Hakkiri](https://www.hakkiri.io)
74
75
  - [Ubidots](https://help.ubidots.com/en/articles/2400308-create-dashboards-and-widgets)
76
+ - [Statsout](https://statsout.com/)
75
77
 
76
78
  *Know of others? Create a PR to let me know!*
77
79
 
@@ -90,11 +92,12 @@ RGL is React-only and does not require jQuery.
90
92
  * Separate layouts per responsive breakpoint
91
93
  * Grid Items placed using CSS Transforms
92
94
  * Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
95
+ * Compatibility with `<React.StrictMode>`
93
96
 
94
97
  |Version | Compatibility |
95
98
  |----------------|------------------|
96
- | >= 0.17.0 | React 0.16 |
97
- | >= 0.11.3 | React 0.14 & v15 |
99
+ | >= 0.17.0 | React 16 & 17 |
100
+ | >= 0.11.3 | React 0.14 & 15 |
98
101
  | >= 0.10.0 | React 0.14 |
99
102
  | 0.8. - 0.9.2 | React 0.13 |
100
103
  | < 0.8 | React 0.12 |
package/build/GridItem.js CHANGED
@@ -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
  });
@@ -7,8 +9,6 @@ exports.default = void 0;
7
9
 
8
10
  var _react = _interopRequireDefault(require("react"));
9
11
 
10
- var _reactDom = _interopRequireDefault(require("react-dom"));
11
-
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
14
  var _reactDraggable = require("react-draggable");
@@ -25,8 +25,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
- 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); }
29
-
30
28
  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; }
31
29
 
32
30
  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; }
@@ -47,7 +45,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
47
45
 
48
46
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
47
 
50
- 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; } }
48
+ 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; } }
51
49
 
52
50
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
51
 
@@ -78,13 +76,13 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
78
76
  className: ""
79
77
  });
80
78
 
81
- _defineProperty(_assertThisInitialized(_this), "currentNode", void 0);
79
+ _defineProperty(_assertThisInitialized(_this), "elementRef", /*#__PURE__*/_react.default.createRef());
82
80
 
83
- _defineProperty(_assertThisInitialized(_this), "onDragStart", function (e
84
- /*: Event*/
85
- , _ref) {
81
+ _defineProperty(_assertThisInitialized(_this), "onDragStart", function (e, _ref) {
86
82
  var node = _ref.node;
87
- var onDragStart = _this.props.onDragStart;
83
+ var _this$props = _this.props,
84
+ onDragStart = _this$props.onDragStart,
85
+ transformScale = _this$props.transformScale;
88
86
  if (!onDragStart) return;
89
87
  var newPosition
90
88
  /*: PartialPosition*/
@@ -97,10 +95,10 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
97
95
  if (!offsetParent) return;
98
96
  var parentRect = offsetParent.getBoundingClientRect();
99
97
  var clientRect = node.getBoundingClientRect();
100
- var cLeft = clientRect.left / _this.props.transformScale;
101
- var pLeft = parentRect.left / _this.props.transformScale;
102
- var cTop = clientRect.top / _this.props.transformScale;
103
- var pTop = parentRect.top / _this.props.transformScale;
98
+ var cLeft = clientRect.left / transformScale;
99
+ var pLeft = parentRect.left / transformScale;
100
+ var cTop = clientRect.top / transformScale;
101
+ var pTop = parentRect.top / transformScale;
104
102
  newPosition.left = cLeft - pLeft + offsetParent.scrollLeft;
105
103
  newPosition.top = cTop - pTop + offsetParent.scrollTop;
106
104
 
@@ -120,18 +118,12 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
120
118
  });
121
119
  });
122
120
 
123
- _defineProperty(_assertThisInitialized(_this), "onDrag", function (e
124
- /*: Event*/
125
- , _ref2) {
121
+ _defineProperty(_assertThisInitialized(_this), "onDrag", function (e, _ref2) {
126
122
  var node = _ref2.node,
127
123
  deltaX = _ref2.deltaX,
128
124
  deltaY = _ref2.deltaY;
129
- var _this$props = _this.props,
130
- onDrag = _this$props.onDrag,
131
- transformScale = _this$props.transformScale;
125
+ var onDrag = _this.props.onDrag;
132
126
  if (!onDrag) return;
133
- deltaX /= transformScale;
134
- deltaY /= transformScale;
135
127
 
136
128
  if (!_this.state.dragging) {
137
129
  throw new Error("onDrag called before onDragStart.");
@@ -187,9 +179,7 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
187
179
  });
188
180
  });
189
181
 
190
- _defineProperty(_assertThisInitialized(_this), "onDragStop", function (e
191
- /*: Event*/
192
- , _ref3) {
182
+ _defineProperty(_assertThisInitialized(_this), "onDragStop", function (e, _ref3) {
193
183
  var node = _ref3.node;
194
184
  var onDragStop = _this.props.onDragStop;
195
185
  if (!onDragStop) return;
@@ -227,27 +217,15 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
227
217
  });
228
218
  });
229
219
 
230
- _defineProperty(_assertThisInitialized(_this), "onResizeStop", function (e
231
- /*: Event*/
232
- , callbackData
233
- /*: { node: HTMLElement, size: Position }*/
234
- ) {
220
+ _defineProperty(_assertThisInitialized(_this), "onResizeStop", function (e, callbackData) {
235
221
  _this.onResizeHandler(e, callbackData, "onResizeStop");
236
222
  });
237
223
 
238
- _defineProperty(_assertThisInitialized(_this), "onResizeStart", function (e
239
- /*: Event*/
240
- , callbackData
241
- /*: { node: HTMLElement, size: Position }*/
242
- ) {
224
+ _defineProperty(_assertThisInitialized(_this), "onResizeStart", function (e, callbackData) {
243
225
  _this.onResizeHandler(e, callbackData, "onResizeStart");
244
226
  });
245
227
 
246
- _defineProperty(_assertThisInitialized(_this), "onResize", function (e
247
- /*: Event*/
248
- , callbackData
249
- /*: { node: HTMLElement, size: Position }*/
250
- ) {
228
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (e, callbackData) {
251
229
  _this.onResizeHandler(e, callbackData, "onResize");
252
230
  });
253
231
 
@@ -260,7 +238,9 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
260
238
  /*: Props*/
261
239
  , nextState
262
240
  /*: State*/
263
- ) {
241
+ )
242
+ /*: boolean*/
243
+ {
264
244
  // We can't deeply compare children. If the developer memoizes them, we can
265
245
  // use this optimization.
266
246
  if (this.props.children !== nextProps.children) return true;
@@ -291,26 +271,19 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
291
271
  ) {
292
272
  var droppingPosition = this.props.droppingPosition;
293
273
  if (!droppingPosition) return;
274
+ var node = this.elementRef.current; // Can't find DOM node (are we unmounted?)
275
+
276
+ if (!node) return;
294
277
  var prevDroppingPosition = prevProps.droppingPosition || {
295
278
  left: 0,
296
279
  top: 0
297
280
  };
298
281
  var dragging = this.state.dragging;
299
-
300
- if (!this.currentNode) {
301
- // eslint-disable-next-line react/no-find-dom-node
302
- this.currentNode = ((_reactDom.default.findDOMNode(this)
303
- /*: any*/
304
- )
305
- /*: HTMLElement*/
306
- );
307
- }
308
-
309
282
  var shouldDrag = dragging && droppingPosition.left !== prevDroppingPosition.left || droppingPosition.top !== prevDroppingPosition.top;
310
283
 
311
284
  if (!dragging) {
312
285
  this.onDragStart(droppingPosition.e, {
313
- node: this.currentNode,
286
+ node: node,
314
287
  deltaX: droppingPosition.left,
315
288
  deltaY: droppingPosition.top
316
289
  });
@@ -318,7 +291,7 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
318
291
  var deltaX = droppingPosition.left - dragging.left;
319
292
  var deltaY = droppingPosition.top - dragging.top;
320
293
  this.onDrag(droppingPosition.e, {
321
- node: this.currentNode,
294
+ node: node,
322
295
  deltaX: deltaX,
323
296
  deltaY: deltaY
324
297
  });
@@ -401,7 +374,8 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
401
374
  onStop: this.onDragStop,
402
375
  handle: this.props.handle,
403
376
  cancel: ".react-resizable-handle" + (this.props.cancel ? "," + this.props.cancel : ""),
404
- scale: this.props.transformScale
377
+ scale: this.props.transformScale,
378
+ nodeRef: this.elementRef
405
379
  }, child);
406
380
  }
407
381
  /**
@@ -442,7 +416,8 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
442
416
  var maxConstraints = [Math.min(maxes.width, maxWidth), Math.min(maxes.height, Infinity)];
443
417
  return /*#__PURE__*/_react.default.createElement(_reactResizable.Resizable, {
444
418
  draggableOpts: {
445
- disabled: !isResizable
419
+ disabled: !isResizable,
420
+ nodeRef: this.elementRef
446
421
  },
447
422
  className: isResizable ? undefined : "react-resizable-hide",
448
423
  width: position.width,
@@ -465,7 +440,7 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
465
440
 
466
441
  }, {
467
442
  key: "onResizeHandler",
468
-
443
+ value:
469
444
  /**
470
445
  * Wrapper around drag events to provide more useful data.
471
446
  * All drag events call the function with the given handler name,
@@ -474,11 +449,13 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
474
449
  * @param {String} handlerName Handler name to wrap.
475
450
  * @return {Function} Handler function.
476
451
  */
477
- value: function onResizeHandler(e
452
+ function onResizeHandler(e
478
453
  /*: Event*/
479
454
  , _ref4, handlerName
480
455
  /*: string*/
481
- ) {
456
+ )
457
+ /*: void*/
458
+ {
482
459
  var node = _ref4.node,
483
460
  size = _ref4.size;
484
461
  var handler = this.props[handlerName];
@@ -534,6 +511,7 @@ var GridItem = /*#__PURE__*/function (_React$Component) {
534
511
 
535
512
 
536
513
  var newChild = /*#__PURE__*/_react.default.cloneElement(child, {
514
+ ref: this.elementRef,
537
515
  className: (0, _classnames.default)("react-grid-item", child.props.className, this.props.className, {
538
516
  static: this.props.static,
539
517
  resizing: Boolean(this.state.resizing),