react-grid-layout 1.3.1 → 1.3.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.
Files changed (37) hide show
  1. package/.babelrc.js +3 -2
  2. package/.eslintignore +3 -0
  3. package/.prettierignore +1 -0
  4. package/CHANGELOG.md +358 -260
  5. package/README.md +68 -48
  6. package/build/utils.js +1 -10
  7. package/coverage/clover.xml +761 -0
  8. package/coverage/coverage-final.json +15 -0
  9. package/coverage/lcov-report/base.css +224 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/prettify.css +1 -0
  13. package/coverage/lcov-report/prettify.js +2 -0
  14. package/coverage/lcov-report/react-grid-layout/index-dev.js.html +104 -0
  15. package/coverage/lcov-report/react-grid-layout/lib/GridItem.jsx.html +2099 -0
  16. package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayout.jsx.html +2453 -0
  17. package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayoutPropTypes.js.html +833 -0
  18. package/coverage/lcov-report/react-grid-layout/lib/ResponsiveReactGridLayout.jsx.html +1133 -0
  19. package/coverage/lcov-report/react-grid-layout/lib/calculateUtils.js.html +557 -0
  20. package/coverage/lcov-report/react-grid-layout/lib/components/WidthProvider.jsx.html +410 -0
  21. package/coverage/lcov-report/react-grid-layout/lib/fastRGLPropsEqual.js.html +224 -0
  22. package/coverage/lcov-report/react-grid-layout/lib/responsiveUtils.js.html +440 -0
  23. package/coverage/lcov-report/react-grid-layout/lib/utils.js.html +2456 -0
  24. package/coverage/lcov-report/react-grid-layout/test/examples/0-showcase.jsx.html +521 -0
  25. package/coverage/lcov-report/react-grid-layout/test/examples/1-basic.jsx.html +284 -0
  26. package/coverage/lcov-report/react-grid-layout/test/examples/15-drag-from-outside.jsx.html +506 -0
  27. package/coverage/lcov-report/react-grid-layout/test/util/deepFreeze.js.html +248 -0
  28. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  29. package/coverage/lcov-report/sorter.js +196 -0
  30. package/coverage/lcov.info +1584 -0
  31. package/dist/react-grid-layout.min.js +1 -1
  32. package/dist/react-grid-layout.min.js.map +1 -1
  33. package/index.js +4 -2
  34. package/lib/GridItem.jsx +8 -3
  35. package/lib/utils.js +1 -15
  36. package/package.json +18 -6
  37. package/foo.html +0 -388
package/README.md CHANGED
@@ -14,6 +14,7 @@ or autogenerated.
14
14
  RGL is React-only and does not require jQuery.
15
15
 
16
16
  ![BitMEX UI](http://i.imgur.com/oo1NT6c.gif)
17
+
17
18
  > GIF from production usage on [BitMEX.com](https://www.bitmex.com)
18
19
 
19
20
  [**[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)**]
@@ -77,32 +78,32 @@ RGL is React-only and does not require jQuery.
77
78
  - [Statsout](https://statsout.com/)
78
79
  - [Datto RMM](https://www.datto.com/uk/products/rmm/)
79
80
 
80
- *Know of others? Create a PR to let me know!*
81
+ _Know of others? Create a PR to let me know!_
81
82
 
82
83
  ## Features
83
84
 
84
- * 100% React - no jQuery
85
- * Compatible with server-rendered apps
86
- * Draggable widgets
87
- * Resizable widgets
88
- * Static widgets
89
- * Configurable packing: horizontal, vertical, or off
90
- * Bounds checking for dragging and resizing
91
- * Widgets may be added or removed without rebuilding grid
92
- * Layout can be serialized and restored
93
- * Responsive breakpoints
94
- * Separate layouts per responsive breakpoint
95
- * Grid Items placed using CSS Transforms
96
- * Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
97
- * Compatibility with `<React.StrictMode>`
98
-
99
- |Version | Compatibility |
100
- |----------------|------------------|
101
- | >= 0.17.0 | React 16 & 17 |
102
- | >= 0.11.3 | React 0.14 & 15 |
103
- | >= 0.10.0 | React 0.14 |
104
- | 0.8. - 0.9.2 | React 0.13 |
105
- | < 0.8 | React 0.12 |
85
+ - 100% React - no jQuery
86
+ - Compatible with server-rendered apps
87
+ - Draggable widgets
88
+ - Resizable widgets
89
+ - Static widgets
90
+ - Configurable packing: horizontal, vertical, or off
91
+ - Bounds checking for dragging and resizing
92
+ - Widgets may be added or removed without rebuilding grid
93
+ - Layout can be serialized and restored
94
+ - Responsive breakpoints
95
+ - Separate layouts per responsive breakpoint
96
+ - Grid Items placed using CSS Transforms
97
+ - Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
98
+ - Compatibility with `<React.StrictMode>`
99
+
100
+ | Version | Compatibility |
101
+ | ------------ | --------------- |
102
+ | >= 0.17.0 | React 16 & 17 |
103
+ | >= 0.11.3 | React 0.14 & 15 |
104
+ | >= 0.10.0 | React 0.14 |
105
+ | 0.8. - 0.9.2 | React 0.13 |
106
+ | < 0.8 | React 0.12 |
106
107
 
107
108
  ## Installation
108
109
 
@@ -129,23 +130,29 @@ produce a grid with three items where:
129
130
  - users will be able to freely drag and resize item `c`
130
131
 
131
132
  ```js
132
- import GridLayout from 'react-grid-layout';
133
+ import GridLayout from "react-grid-layout";
133
134
 
134
135
  class MyFirstGrid extends React.Component {
135
136
  render() {
136
137
  // layout is an array of objects, see the demo for more complete usage
137
138
  const layout = [
138
- {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
139
- {i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4},
140
- {i: 'c', x: 4, y: 0, w: 1, h: 2}
139
+ { i: "a", x: 0, y: 0, w: 1, h: 2, static: true },
140
+ { i: "b", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
141
+ { i: "c", x: 4, y: 0, w: 1, h: 2 }
141
142
  ];
142
143
  return (
143
- <GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
144
+ <GridLayout
145
+ className="layout"
146
+ layout={layout}
147
+ cols={12}
148
+ rowHeight={30}
149
+ width={1200}
150
+ >
144
151
  <div key="a">a</div>
145
152
  <div key="b">b</div>
146
153
  <div key="c">c</div>
147
154
  </GridLayout>
148
- )
155
+ );
149
156
  }
150
157
  }
151
158
  ```
@@ -153,17 +160,23 @@ class MyFirstGrid extends React.Component {
153
160
  You may also choose to set layout properties directly on the children:
154
161
 
155
162
  ```js
156
- import GridLayout from 'react-grid-layout';
163
+ import GridLayout from "react-grid-layout";
157
164
 
158
165
  class MyFirstGrid extends React.Component {
159
166
  render() {
160
167
  return (
161
168
  <GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
162
- <div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}>a</div>
163
- <div key="b" data-grid={{x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}}>b</div>
164
- <div key="c" data-grid={{x: 4, y: 0, w: 1, h: 2}}>c</div>
169
+ <div key="a" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}>
170
+ a
171
+ </div>
172
+ <div key="b" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}>
173
+ b
174
+ </div>
175
+ <div key="c" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}>
176
+ c
177
+ </div>
165
178
  </GridLayout>
166
- )
179
+ );
167
180
  }
168
181
  }
169
182
  ```
@@ -178,21 +191,24 @@ excludes `React`, so it must be otherwise available in your application, either
178
191
  To make RGL responsive, use the `<ResponsiveReactGridLayout>` element:
179
192
 
180
193
  ```js
181
- import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
194
+ import { Responsive as ResponsiveGridLayout } from "react-grid-layout";
182
195
 
183
196
  class MyResponsiveGrid extends React.Component {
184
197
  render() {
185
198
  // {lg: layout1, md: layout2, ...}
186
199
  const layouts = getLayoutsFromSomewhere();
187
200
  return (
188
- <ResponsiveGridLayout className="layout" layouts={layouts}
189
- breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
190
- cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
201
+ <ResponsiveGridLayout
202
+ className="layout"
203
+ layouts={layouts}
204
+ breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
205
+ cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
206
+ >
191
207
  <div key="1">1</div>
192
208
  <div key="2">2</div>
193
209
  <div key="3">3</div>
194
210
  </ResponsiveGridLayout>
195
- )
211
+ );
196
212
  }
197
213
  }
198
214
  ```
@@ -215,7 +231,7 @@ positions on drag events. In simple cases a HOC `WidthProvider` can be used to a
215
231
  width upon initialization and window resize events.
216
232
 
217
233
  ```js
218
- import { Responsive, WidthProvider } from 'react-grid-layout';
234
+ import { Responsive, WidthProvider } from "react-grid-layout";
219
235
 
220
236
  const ResponsiveGridLayout = WidthProvider(Responsive);
221
237
 
@@ -224,14 +240,17 @@ class MyResponsiveGrid extends React.Component {
224
240
  // {lg: layout1, md: layout2, ...}
225
241
  var layouts = getLayoutsFromSomewhere();
226
242
  return (
227
- <ResponsiveGridLayout className="layout" layouts={layouts}
228
- breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
229
- cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
243
+ <ResponsiveGridLayout
244
+ className="layout"
245
+ layouts={layouts}
246
+ breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
247
+ cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
248
+ >
230
249
  <div key="1">1</div>
231
250
  <div key="2">2</div>
232
251
  <div key="3">3</div>
233
252
  </ResponsiveGridLayout>
234
- )
253
+ );
235
254
  }
236
255
  }
237
256
  ```
@@ -396,7 +415,9 @@ onDropDragOver: (e: DragOverEvent) => ?({|w?: number, h?: number|} | false),
396
415
 
397
416
  // Ref for getting a reference for the grid's wrapping div.
398
417
  // You can use this instead of a regular ref and the deprecated `ReactDOM.findDOMNode()`` function.
399
- innerRef: ?React.Ref<"div">,
418
+ // Note that this type is React.Ref<HTMLDivElement> in TypeScript, Flow has a bug here
419
+ // https://github.com/facebook/flow/issues/8671#issuecomment-862634865
420
+ innerRef: {current: null | HTMLDivElement},
400
421
  ```
401
422
 
402
423
  ### Responsive Grid Layout Props
@@ -494,7 +515,6 @@ will be draggable, even if the item is marked `static: true`.
494
515
 
495
516
  `<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:
496
517
 
497
-
498
518
  ```js
499
519
  // lib/ReactGridLayout.jsx
500
520
  // ...
@@ -517,7 +537,7 @@ If you memoize your children, you can take advantage of this, and reap faster re
517
537
  function MyGrid(props) {
518
538
  const children = React.useMemo(() => {
519
539
  return new Array(props.count).fill(undefined).map((val, idx) => {
520
- return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
540
+ return <div key={idx} data-grid={{ x: idx, y: 1, w: 1, h: 1 }} />;
521
541
  });
522
542
  }, [props.count]);
523
543
  return <ReactGridLayout cols={12}>{children}</ReactGridLayout>;
@@ -540,7 +560,7 @@ const CustomGridItemComponent = React.forwardRef(({style, className, ...props},
540
560
  return (
541
561
  <div style={{ /* styles */, ...style}} className={className} ref={ref}>
542
562
  {/* Some other content */}
543
- </div>
563
+ </div>
544
564
  );
545
565
  }
546
566
  ```
package/build/utils.js CHANGED
@@ -779,8 +779,7 @@ function synchronizeLayoutWithChildren(initialLayout
779
779
  layout.push(cloneLayoutItem(exists));
780
780
  } else {
781
781
  if (!isProduction && child.props._grid) {
782
- console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + // eslint-disable-line
783
- "Please use `data-grid` or add your properties directly to the `layout`.");
782
+ console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + "Please use `data-grid` or add your properties directly to the `layout`.");
784
783
  }
785
784
 
786
785
  var g = child.props["data-grid"] || child.props._grid; // Hey, this item has a data-grid property, use it.
@@ -842,14 +841,6 @@ function validateLayout(layout
842
841
  throw new Error("ReactGridLayout: " + contextName + "[" + i + "]." + subProps[j] + " must be a number!");
843
842
  }
844
843
  }
845
-
846
- if (item.i && typeof item.i !== "string") {
847
- throw new Error("ReactGridLayout: " + contextName + "[" + i + "].i must be a string!");
848
- }
849
-
850
- if (item.static !== undefined && typeof item.static !== "boolean") {
851
- throw new Error("ReactGridLayout: " + contextName + "[" + i + "].static must be a boolean!");
852
- }
853
844
  }
854
845
  } // Legacy support for verticalCompact: false
855
846