react-grid-layout 0.17.1 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.babelrc.js CHANGED
@@ -1,25 +1,21 @@
1
- 'use strict';
1
+ // @flow
2
+
3
+ const es6Compat = process.env.BABEL_ES_COMPAT === "6" || process.env.NODE_ENV === "test";
2
4
 
3
5
  module.exports = {
4
- "presets": [
6
+ presets: [
5
7
  [
6
8
  "@babel/preset-env",
7
9
  {
8
- targets: "> 0.25%, not dead",
9
- }
10
+ targets: es6Compat ? "maintained node versions" : "> 0.25%, not dead"
11
+ },
10
12
  ],
11
13
  "@babel/react",
12
14
  "@babel/preset-flow"
13
15
  ],
14
- "plugins": [
16
+ plugins: [
15
17
  "@babel/plugin-transform-flow-comments",
16
18
  "@babel/plugin-proposal-class-properties",
17
- ],
18
- "env": {
19
- "test": {
20
- "plugins": [
21
- "espower"
22
- ]
23
- }
24
- }
25
- }
19
+ "babel-plugin-preval"
20
+ ]
21
+ };
package/.flowconfig CHANGED
@@ -1,11 +1,23 @@
1
1
  [version]
2
- 0.110.1
2
+ ^0.119.0
3
3
 
4
4
  [ignore]
5
+ <PROJECT_ROOT>/build/.*
6
+ <PROJECT_ROOT>/dist/.*
7
+ # Speeds parsing:
8
+ .*/node_modules/@babel.*
9
+ .*/node_modules/babel.*
5
10
 
6
11
  [include]
7
12
 
8
13
  [libs]
9
14
  interfaces/
15
+ flow-typed/
10
16
 
11
17
  [options]
18
+ emoji=true
19
+ module.use_strict=true
20
+ suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowFixMe.*
21
+ suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowBug.*
22
+ suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIgnore.*
23
+ suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowNative.*
package/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: node_js
2
2
  node_js:
3
- - "node"
3
+ - 8
4
+ - 10
5
+ - 12
4
6
  - "lts/*"
5
7
  script:
6
8
  - make build test
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # Changelog
2
2
 
3
+ 0.18.3 (Mar 16, 2020)
4
+ ----
5
+
6
+ ### Bugfixes
7
+ - Fix `shouldComponentUpdate` interfering with droppability ([#1152](https://github.com/STRML/react-grid-layout/issues/1152))
8
+
9
+ ### Internal Changes
10
+ - New Enzyme test suite added to prevent regression. If you have time, we could really use more test cases that reflect your use cases!
11
+
12
+ 0.18.2 (Feb 26, 2020)
13
+ ----
14
+
15
+ ### Bugfixes
16
+ - `shouldComponentUpdate`:
17
+ - A too-aggressive implementation of `shouldComponentUpdate` was shipped in 0.18.0-0.18.1 ([#1123](https://github.com/STRML/react-grid-layout/pull/1123)), which did not compare the `children` object. While this works well in many simple implementations of RGL, it breaks in more complex applications.
18
+ - Reference equality of `props.children` and `nextProps.children` is now added to `<ReactGridLayout>` and `<GridItem>`. If you wish to take advantage of the performance improvements from the `shouldComponentUpdate` work, memoize your children.
19
+ - A section has been added to the [README](/README.md#Performance) explaining how this works.
20
+ - Fixed [#1150](https://github.com/STRML/react-grid-layout/issues/1150), [#1151](https://github.com/STRML/react-grid-layout/issues/1151).
21
+
22
+ 0.18.1 (Feb 25, 2020)
23
+ ----
24
+
25
+ This release contains typedef changes only.
26
+
27
+ ### Bugfixes
28
+ - Flow types:
29
+ - Make Props to `<ReactGridLayout>` and `<ResponsiveReactGridLayout>` exact.
30
+ - Fix loss of props refinement when passing through `WidthProvider`.
31
+ - Fix Flow errors as surfaced in [#1138](https://github.com/STRML/react-grid-layout/pull/1138).
32
+ - Modify examples to use types so that the above type error can't resurface
33
+
34
+ 0.18.0 (Feb 25, 2020)
35
+ ----
36
+
37
+ Thanks to all of our maintainers for this big release. 0.18.0 contains a large number of bugfixes that users have been asking for. Please read the full list so you know what to expect. Some of the biggest improvements include fixing changes of `isResizable`/`isDraggable` without a remount ([#892](https://github.com/STRML/react-grid-layout/pull/892)), fixes to prop changes on `ResponsiveReactGridLayout` ([#1090](https://github.com/STRML/react-grid-layout/pull/1090)), `shouldComponentUpdate` improvements for speed ([#1123](https://github.com/STRML/react-grid-layout/pull/1123)), improvements to droppability ([#1127](https://github.com/STRML/react-grid-layout/pull/1127)), and much more.
38
+
39
+ ### (Potentially) Breaking Changes
40
+
41
+ - You can now locally set `isDraggable`/`isResizable` on a `static` item and it will have that property. This could be useful, but be sure to check your layouts if you use `static`. Relates to [#1060](https://github.com/STRML/react-grid-layout/pull/1060).
42
+ - `shouldComponentUpdate` is now implemented on major components to improve render speed while you manipulate the layout. In our testing there are no issues. If you encounter one, please open an issue asap and we'll get it fixed. See [#1123](https://github.com/STRML/react-grid-layout/pull/1123).
43
+
44
+ ### New Features
45
+
46
+ - You can now manipulate `isDraggable`/`isResizable` without the child component remounting. We do this by always rendering the child `<Resizable>` and `<Draggable>` wrappers, optionally in a `disabled` state. This feature has been heavily requested. [#892](https://github.com/STRML/react-grid-layout/pull/892)
47
+ - The event is now passed as `e` on the `onDrop` callback. [#1065](https://github.com/STRML/react-grid-layout/pull/1065)
48
+ - Pass `transformScale` to `Resizable`. [#1075](https://github.com/STRML/react-grid-layout/pull/1075)
49
+
50
+ ### Bugfixes
51
+
52
+ - Fix handling of width changes in `ResponsiveReactGridLayout`. [#1090](https://github.com/STRML/react-grid-layout/pull/1090)
53
+ - Fixes ignored changes of breakpoints and columns. See also [issue #1083](https://github.com/STRML/react-grid-layout/issues/1083).
54
+ - Forbid layout change on click without drag. [#1044](https://github.com/STRML/react-grid-layout/pull/1044)
55
+ - Do not mutate `layouts` prop. [#1064](https://github.com/STRML/react-grid-layout/pull/1064)
56
+ - Ensure locally set `isDraggable`/`isResizable` on a `GridItem` overrides the global setting on the layout. [#1060](https://github.com/STRML/react-grid-layout/pull/1060)
57
+ - Avoid additional element jumping when an item is dropped. [#1127](https://github.com/STRML/react-grid-layout/issues/1127)
58
+ - Don't use `String#includes` for Firefox test. [#1096](https://github.com/STRML/react-grid-layout/pull/1096)
59
+
60
+ ### Internal Refactors
61
+
62
+ - Added `shouldComponentUpdate` to major elements for speed. Significant [performance improvements](https://github.com/STRML/react-grid-layout/pull/1032#issuecomment-541604763) while dragging. Started in [#1032](https://github.com/STRML/react-grid-layout/pull/1032) and finished in [#1123](https://github.com/STRML/react-grid-layout/pull/1123).
63
+ - A [fun trick for the curious](https://github.com/STRML/react-grid-layout/blob/44e200067b3640c3230f5511e8624a7c629d2f9a/lib/fastRGLPropsEqual.js).
64
+ - Internal refactor of dropping capability. It is now more predictable and uses similar unit labels (`left`, `top`) to other features. [#1128](https://github.com/STRML/react-grid-layout/issues/1128)
65
+ - Upgrade devDependencies.
66
+ - Remove ESPower from test suite (not useful with Jest).
67
+
68
+
3
69
  0.17.1 (Oct 29, 2019)
4
70
  ----
5
71
 
package/README.md CHANGED
@@ -29,6 +29,8 @@ RGL is React-only and does not require jQuery.
29
29
  - [Grid Layout Props](#grid-layout-props)
30
30
  - [Responsive Grid Layout Props](#responsive-grid-layout-props)
31
31
  - [Grid Item Props](#grid-item-props)
32
+ - [User Recipes](../../wiki/Users-recipes)
33
+ - [Performance](#performance)
32
34
  - [Contribute](#contribute)
33
35
  - [TODO List](#todo-list)
34
36
 
@@ -66,6 +68,7 @@ RGL is React-only and does not require jQuery.
66
68
  - [Graphext](https://graphext.com/)
67
69
  - [Monday](https://support.monday.com/hc/en-us/articles/360002187819-What-are-the-Dashboards-)
68
70
  - [Quadency](https://quadency.com/)
71
+ - [Hakkiri](https://www.hakkiri.io)
69
72
 
70
73
  *Know of others? Create a PR to let me know!*
71
74
 
@@ -87,6 +90,7 @@ RGL is React-only and does not require jQuery.
87
90
 
88
91
  |Version | Compatibility |
89
92
  |----------------|------------------|
93
+ | >= 0.17.0 | React 0.16 |
90
94
  | >= 0.11.3 | React 0.14 & v15 |
91
95
  | >= 0.10.0 | React 0.14 |
92
96
  | 0.8. - 0.9.2 | React 0.13 |
@@ -122,7 +126,7 @@ import GridLayout from 'react-grid-layout';
122
126
  class MyFirstGrid extends React.Component {
123
127
  render() {
124
128
  // layout is an array of objects, see the demo for more complete usage
125
- var layout = [
129
+ const layout = [
126
130
  {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
127
131
  {i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4},
128
132
  {i: 'c', x: 4, y: 0, w: 1, h: 2}
@@ -171,7 +175,7 @@ import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
171
175
  class MyResponsiveGrid extends React.Component {
172
176
  render() {
173
177
  // {lg: layout1, md: layout2, ...}
174
- var layouts = getLayoutsFromSomewhere();
178
+ const layouts = getLayoutsFromSomewhere();
175
179
  return (
176
180
  <ResponsiveGridLayout className="layout" layouts={layouts}
177
181
  breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
@@ -287,7 +291,7 @@ containerPadding: ?[number, number] = margin,
287
291
  // if you like.
288
292
  rowHeight: ?number = 150,
289
293
 
290
- // Configuration of a dropping element. Dropping element is a "virtual" element
294
+ // Configuration of a dropping element. Dropping element is a "virtual" element
291
295
  // which appears when you drag over some element from outside.
292
296
  // It can be changed by passing specific parameters:
293
297
  // i - id of an element
@@ -311,9 +315,9 @@ transformScale: ?number = 1,
311
315
  // dragged over.
312
316
  preventCollision: ?boolean = false;
313
317
 
314
- // If true, droppable elements (with `draggable={true}` attribute)
318
+ // If true, droppable elements (with `draggable={true}` attribute)
315
319
  // can be dropped on the grid. It triggers "onDrop" callback
316
- // with position and event object as parameters.
320
+ // with position and event object as parameters.
317
321
  // It can be useful for dropping an element in a specific position
318
322
  //
319
323
  // NOTE: In case of using Firefox you should add
@@ -351,7 +355,7 @@ onResize: ItemCallback,
351
355
  // Calls when resize is complete.
352
356
  onResizeStop: ItemCallback,
353
357
  // Calls when some element has been dropped
354
- onDrop: (elemParams: { x: number, y: number, e: Event }) => void
358
+ onDrop: (elemParams: { x: number, y: number, w: number, h: number, e: Event }) => void
355
359
  ```
356
360
 
357
361
  ### Responsive Grid Layout Props
@@ -413,7 +417,7 @@ are out of range.
413
417
 
414
418
  Any `<GridItem>` properties defined directly will take precedence over globally-set options. For
415
419
  example, if the layout has the property `isDraggable: false`, but the grid item has the prop `isDraggable: true`, the item
416
- will be draggable.
420
+ will be draggable, even if the item is marked `static: true`.
417
421
 
418
422
  ```js
419
423
  {
@@ -440,6 +444,42 @@ will be draggable.
440
444
  }
441
445
  ```
442
446
 
447
+ ### Performance
448
+
449
+ `<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:
450
+
451
+
452
+ ```js
453
+ // lib/ReactGridLayout.jsx
454
+ // ...
455
+ shouldComponentUpdate(nextProps: Props, nextState: State) {
456
+ return (
457
+ // NOTE: this is almost always unequal. Therefore the only way to get better performance
458
+ // from SCU is if the user intentionally memoizes children. If they do, and they can
459
+ // handle changes properly, performance will increase.
460
+ this.props.children !== nextProps.children ||
461
+ !fastRGLPropsEqual(this.props, nextProps, isEqual) ||
462
+ !isEqual(this.state.activeDrag, nextState.activeDrag)
463
+ );
464
+ }
465
+ // ...
466
+ ```
467
+
468
+ If you memoize your children, you can take advantage of this, and reap faster rerenders. For example:
469
+
470
+ ```js
471
+ function MyGrid(props) {
472
+ const children = React.useMemo(() => {
473
+ return new Array(props.count).fill(undefined).map((val, idx) => {
474
+ return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
475
+ });
476
+ }, [props.count]);
477
+ return <ReactGridLayout cols={12}>{children}</ReactGridLayout>;
478
+ }
479
+ ```
480
+
481
+ Because the `children` prop doesn't change between rerenders, updates to `<MyGrid>` won't result in new renders, improving performance.
482
+
443
483
  ## Contribute
444
484
 
445
485
  If you have a feature request, please add it as an issue or make a pull request.
@@ -0,0 +1,2 @@
1
+ // Used by jest as it requires some example files, which pull from 'react-grid-layout'
2
+ module.exports = require('../index-dev');