react-grid-layout 0.16.4 → 0.17.1

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 ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ "presets": [
5
+ [
6
+ "@babel/preset-env",
7
+ {
8
+ targets: "> 0.25%, not dead",
9
+ }
10
+ ],
11
+ "@babel/react",
12
+ "@babel/preset-flow"
13
+ ],
14
+ "plugins": [
15
+ "@babel/plugin-transform-flow-comments",
16
+ "@babel/plugin-proposal-class-properties",
17
+ ],
18
+ "env": {
19
+ "test": {
20
+ "plugins": [
21
+ "espower"
22
+ ]
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,3 @@
1
+ > 0.25%
2
+ ie 11
3
+ not dead
package/.flowconfig CHANGED
@@ -1,5 +1,5 @@
1
1
  [version]
2
- 0.65.0
2
+ 0.110.1
3
3
 
4
4
  [ignore]
5
5
 
@@ -0,0 +1,2 @@
1
+ dist/
2
+ examples/
package/.prettierrc ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "printWidth": 80,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": false,
7
+ "quoteProps": "as-needed",
8
+ "jsxSingleQuote": false,
9
+ "trailingComma": "none",
10
+ "bracketSpacing": true,
11
+ "jsxBracketSameLine": false,
12
+ "arrowParens": "avoid",
13
+ "requirePragma": false,
14
+ "insertPragma": false,
15
+ "proseWrap": "preserve",
16
+ "htmlWhitespaceSensitivity": "css",
17
+ "endOfLine": "auto"
18
+ }
package/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: node_js
2
2
  node_js:
3
- - "6"
4
- - "7"
3
+ - "node"
4
+ - "lts/*"
5
5
  script:
6
6
  - make build test
7
7
  cache: yarn
package/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Changelog
2
2
 
3
+ 0.17.1 (Oct 29, 2019)
4
+ ----
5
+
6
+ ### Bugfixes
7
+
8
+ - Surround `navigator` check in `try/catch` to avoid problems with mocked navigators [#1057](https://github.com/STRML/react-grid-layout/pull/1054)
9
+ - TransformScale is not applied properly while dragging an element [#1046](https://github.com/STRML/react-grid-layout/pull/1054)
10
+
11
+ 0.17.0 (Oct 24, 2019)
12
+ ----
13
+
14
+ It's been 18 months since the last release, and this is a pretty large one! For references on the items below, see https://github.com/STRML/react-grid-layout/milestone/1?closed=1.
15
+
16
+ Thanks to @daynin and @n1ghtmare for taking an active role in maintaining RGL, and for giving it a much-needed shot in the arm, and thanks to the rest of our contributors.
17
+
18
+ ### New Features
19
+
20
+ - Added ability to drag items into the grid from outside. [#980](https://github.com/STRML/react-grid-layout/pull/980). See [the example](https://strml.github.io/react-grid-layout/examples/15-drag-from-outside.html).
21
+ - This is especially exciting as it opens up new "widget toolbox" use cases such as [Example 14](https://strml.github.io/react-grid-layout/examples/14-toolbox.html) with more intuitive interaction. Thanks @daynin.
22
+ - `transformScale` prop [#987](https://github.com/STRML/react-grid-layout/pull/987)
23
+ - `<ResponsiveReactGridLayout>` now supports margin-per-breakpoint [#1016](https://github.com/STRML/react-grid-layout/pull/1016)
24
+
25
+
26
+ ### Bugfixes
27
+
28
+ - `onWidthChange` only called on breakpoint changes [#770](https://github.com/STRML/react-grid-layout/pull/770)
29
+ - Various movement bugs when compaction is off [#766](https://github.com/STRML/react-grid-layout/pull/766)
30
+ - Don't fire `onDragStop` if an item is only clicked, not dragged [#1023](https://github.com/STRML/react-grid-layout/pull/1023)
31
+ - Fix infinite loop when dragging over a static element. [#1019](https://github.com/STRML/react-grid-layout/pull/1019)
32
+
33
+ ### Internal Refactors
34
+
35
+ - Both `react-draggable` and `react-resizable` dependencies are now React 16.9 compatible, as is now `react-grid-layout`.
36
+ - [RGL PR #990](https://github.com/STRML/react-grid-layout/pull/990)
37
+ - [react-resizable](https://github.com/STRML/react-resizable/pull/112/commits/541dee69b8e45d91a533855609472b481634edee)
38
+ - [react-draggable](https://github.com/mzabriskie/react-draggable/commit/fea778c8e89db2a4e1a35e563b65634f8146e7e4)
39
+ - Webpack 4 [#907](https://github.com/STRML/react-grid-layout/pull/907)
40
+ - Babel 7 [#1013](https://github.com/STRML/react-grid-layout/pull/1013)
41
+ - Flow 0.110 [#995](https://github.com/STRML/react-grid-layout/pull/995)
42
+ - Jest [#774](https://github.com/STRML/react-grid-layout/pull/774)
43
+ - Various build simplifications [#773](https://github.com/STRML/react-grid-layout/pull/773)
44
+ - Various PR bots - thanks @daynin
45
+
46
+ 0.16.6 (Mar 8, 2018)
47
+ ----
48
+
49
+ - Fixed collision issue where items below could rearrange on a move.
50
+ - The root cause was "teleportation", or practically the same bug that leads to Pac-Man going through
51
+ ghosts now and then. If a large element moves up by a few grid units, the space it vacates can suddenly
52
+ become occupiable by an element below it. Rather than the collision happening properly, they exchange spaces
53
+ atomically. The fix is to move items down one grid unit at a time to ensure
54
+ this rearrangement does not happen.
55
+ - Thanks @torkelo for your hard work on this for Grafana 5, which I very unfortunately managed to break
56
+ when refactoring for 0.16.1.
57
+ - Ref: #650, #739
58
+ - Added a "Toolbox" demo (thanks @jhob)
59
+
60
+ 0.16.5 (Feb 26, 2018)
61
+ ----
62
+
63
+ - Minor fix to `isUserAction` on certain types of compaction cascades (#714, #720, #729)
64
+
65
+ 0.16.4 (Feb 15, 2018)
66
+ ----
67
+
68
+ - Skip null items in processGridItem (#578)
69
+ - Resize is broken for grids with preventCollision: true, fixes #655 (#656)
70
+ - Minor refactoring
71
+
3
72
  0.16.3 (Jan 31, 2018)
4
73
  ----
5
74
 
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) | [WebpackBin Editable demo](https://www.webpackbin.com/bins/-Kvr2qCxorvGMgVMxkmI)**]
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)**]
20
20
 
21
21
  ## Table of Contents
22
22
 
@@ -46,6 +46,10 @@ RGL is React-only and does not require jQuery.
46
46
  1. [Minimum and Maximum Width/Height](https://strml.github.io/react-grid-layout/examples/9-min-max-wh.html)
47
47
  1. [Dynamic Minimum and Maximum Width/Height](https://strml.github.io/react-grid-layout/examples/10-dynamic-min-max-wh.html)
48
48
  1. [No Vertical Compacting (Free Movement)](https://strml.github.io/react-grid-layout/examples/11-no-vertical-compact.html)
49
+ 1. [Prevent Collision](https://strml.github.io/react-grid-layout/examples/12-prevent-collision.html)
50
+ 1. [Error Case](https://strml.github.io/react-grid-layout/examples/13-error-case.html)
51
+ 1. [Toolbox](https://strml.github.io/react-grid-layout/examples/14-toolbox.html)
52
+ 1. [Drag From Outside](https://strml.github.io/react-grid-layout/examples/15-drag-from-outside.html)
49
53
 
50
54
  #### Projects Using React-Grid-Layout
51
55
 
@@ -58,6 +62,10 @@ RGL is React-only and does not require jQuery.
58
62
  - [Stoplight](https://app.stoplight.io)
59
63
  - [Reflect](https://reflect.io)
60
64
  - [ez-Dashing](https://github.com/ylacaute/ez-Dashing)
65
+ - [Kibana](https://www.elastic.co/products/kibana)
66
+ - [Graphext](https://graphext.com/)
67
+ - [Monday](https://support.monday.com/hc/en-us/articles/360002187819-What-are-the-Dashboards-)
68
+ - [Quadency](https://quadency.com/)
61
69
 
62
70
  *Know of others? Create a PR to let me know!*
63
71
 
@@ -108,11 +116,11 @@ produce a grid with three items where:
108
116
  - item `b` will be restricted to a minimum width of 2 grid blocks and a maximum width of 4 grid blocks
109
117
  - users will be able to freely drag and resize item `c`
110
118
 
111
- ```javascript
112
- var ReactGridLayout = require('react-grid-layout');
119
+ ```js
120
+ import GridLayout from 'react-grid-layout';
113
121
 
114
- var MyFirstGrid = React.createClass({
115
- render: function() {
122
+ class MyFirstGrid extends React.Component {
123
+ render() {
116
124
  // layout is an array of objects, see the demo for more complete usage
117
125
  var layout = [
118
126
  {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
@@ -120,33 +128,34 @@ var MyFirstGrid = React.createClass({
120
128
  {i: 'c', x: 4, y: 0, w: 1, h: 2}
121
129
  ];
122
130
  return (
123
- <ReactGridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
131
+ <GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
124
132
  <div key="a">a</div>
125
133
  <div key="b">b</div>
126
134
  <div key="c">c</div>
127
- </ReactGridLayout>
135
+ </GridLayout>
128
136
  )
129
137
  }
130
- });
138
+ }
131
139
  ```
132
140
 
133
141
  You may also choose to set layout properties directly on the children:
134
142
 
135
- ```javascript
136
- var ReactGridLayout = require('react-grid-layout');
143
+ ```js
144
+ import GridLayout from 'react-grid-layout';
137
145
 
138
- var MyFirstGrid = React.createClass({
139
- render: function () {
146
+ class MyFirstGrid extends React.Component {
147
+ render() {
140
148
  return (
141
- <ReactGridLayout className="layout" cols={12} rowHeight={30} width={1200}>
149
+ <GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
142
150
  <div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}>a</div>
143
151
  <div key="b" data-grid={{x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}}>b</div>
144
152
  <div key="c" data-grid={{x: 4, y: 0, w: 1, h: 2}}>c</div>
145
- </ReactGridLayout>
153
+ </GridLayout>
146
154
  )
147
155
  }
148
- });
156
+ }
149
157
  ```
158
+
150
159
  ### Usage without Browserify/Webpack
151
160
 
152
161
  A module usable in a `<script>` tag is included [here](/dist/react-grid-layout.min.js). It uses a UMD shim and
@@ -156,21 +165,23 @@ excludes `React`, so it must be otherwise available in your application, either
156
165
 
157
166
  To make RGL responsive, use the `<ResponsiveReactGridLayout>` element:
158
167
 
159
- ```javascript
160
- var ResponsiveReactGridLayout = require('react-grid-layout').Responsive;
161
- //...
162
- render: function() {
163
- // {lg: layout1, md: layout2, ...}
164
- var layouts = getLayoutsFromSomewhere();
165
- return (
166
- <ResponsiveReactGridLayout className="layout" layouts={layouts}
167
- breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
168
- cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
169
- <div key="1">1</div>
170
- <div key="2">2</div>
171
- <div key="3">3</div>
172
- </ResponsiveReactGridLayout>
173
- )
168
+ ```js
169
+ import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
170
+
171
+ class MyResponsiveGrid extends React.Component {
172
+ render() {
173
+ // {lg: layout1, md: layout2, ...}
174
+ var layouts = getLayoutsFromSomewhere();
175
+ return (
176
+ <ResponsiveGridLayout className="layout" layouts={layouts}
177
+ breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
178
+ cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
179
+ <div key="1">1</div>
180
+ <div key="2">2</div>
181
+ <div key="3">3</div>
182
+ </ResponsiveGridLayout>
183
+ )
184
+ }
174
185
  }
175
186
  ```
176
187
 
@@ -191,23 +202,25 @@ Both `<ResponsiveReactGridLayout>` and `<ReactGridLayout>` take `width` to calcu
191
202
  positions on drag events. In simple cases a HOC `WidthProvider` can be used to automatically determine
192
203
  width upon initialization and window resize events.
193
204
 
194
- ```javascript
195
- import {Responsive, WidthProvider} from 'react-grid-layout';
196
- const ResponsiveReactGridLayout = WidthProvider(Responsive);
197
-
198
- //...
199
- render() {
200
- // {lg: layout1, md: layout2, ...}
201
- var layouts = getLayoutsFromSomewhere();
202
- return (
203
- <ResponsiveReactGridLayout className="layout" 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
- <div key="1">1</div>
207
- <div key="2">2</div>
208
- <div key="3">3</div>
209
- </ResponsiveReactGridLayout>
210
- )
205
+ ```js
206
+ import { Responsive, WidthProvider } from 'react-grid-layout';
207
+
208
+ const ResponsiveGridLayout = WidthProvider(Responsive);
209
+
210
+ class MyResponsiveGrid extends React.Component {
211
+ render() {
212
+ // {lg: layout1, md: layout2, ...}
213
+ var layouts = getLayoutsFromSomewhere();
214
+ return (
215
+ <ResponsiveGridLayout className="layout" layouts={layouts}
216
+ breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
217
+ cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}>
218
+ <div key="1">1</div>
219
+ <div key="2">2</div>
220
+ <div key="3">3</div>
221
+ </ResponsiveGridLayout>
222
+ )
223
+ }
211
224
  }
212
225
  ```
213
226
 
@@ -225,7 +238,7 @@ listens to window `'resize'` events. If you need more power and flexibility, try
225
238
 
226
239
  RGL supports the following properties (see the source for the final word on this):
227
240
 
228
- ```javascript
241
+ ```js
229
242
  //
230
243
  // Basic props
231
244
  //
@@ -274,6 +287,14 @@ containerPadding: ?[number, number] = margin,
274
287
  // if you like.
275
288
  rowHeight: ?number = 150,
276
289
 
290
+ // Configuration of a dropping element. Dropping element is a "virtual" element
291
+ // which appears when you drag over some element from outside.
292
+ // It can be changed by passing specific parameters:
293
+ // i - id of an element
294
+ // w - width of an element
295
+ // h - height of an element
296
+ droppingItem?: { i: string, w: number, h: number }
297
+
277
298
  //
278
299
  // Flags
279
300
  //
@@ -282,11 +303,26 @@ isResizable: ?boolean = true,
282
303
  // Uses CSS3 translate() instead of position top/left.
283
304
  // This makes about 6x faster paint performance
284
305
  useCSSTransforms: ?boolean = true,
306
+ // If parent DOM node of ResponsiveReactGridLayout or ReactGridLayout has "transform: scale(n)" css property,
307
+ // we should set scale coefficient to avoid render artefacts while dragging.
308
+ transformScale: ?number = 1,
285
309
 
286
310
  // If true, grid items won't change position when being
287
311
  // dragged over.
288
312
  preventCollision: ?boolean = false;
289
313
 
314
+ // If true, droppable elements (with `draggable={true}` attribute)
315
+ // can be dropped on the grid. It triggers "onDrop" callback
316
+ // with position and event object as parameters.
317
+ // It can be useful for dropping an element in a specific position
318
+ //
319
+ // NOTE: In case of using Firefox you should add
320
+ // `onDragStart={e => e.dataTransfer.setData('text/plain', '')}` attribute
321
+ // along with `draggable={true}` otherwise this feature will work incorrect.
322
+ // onDragStart attribute is required for Firefox for a dragging initialization
323
+ // @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
324
+ isDroppable: ?boolean = false
325
+
290
326
  //
291
327
  // Callbacks
292
328
  //
@@ -313,7 +349,9 @@ onResizeStart: ItemCallback,
313
349
  // Calls when resize movement happens.
314
350
  onResize: ItemCallback,
315
351
  // Calls when resize is complete.
316
- onResizeStop: ItemCallback
352
+ onResizeStop: ItemCallback,
353
+ // Calls when some element has been dropped
354
+ onDrop: (elemParams: { x: number, y: number, e: Event }) => void
317
355
  ```
318
356
 
319
357
  ### Responsive Grid Layout Props
@@ -321,7 +359,7 @@ onResizeStop: ItemCallback
321
359
  The responsive grid layout can be used instead. It supports all of the props above, excepting `layout`.
322
360
  The new properties and changes are:
323
361
 
324
- ```javascript
362
+ ```js
325
363
  // {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}
326
364
  // Breakpoint names are arbitrary but must match in the cols and layouts objects.
327
365
  breakpoints: ?Object = {lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0},
@@ -329,6 +367,15 @@ breakpoints: ?Object = {lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0},
329
367
  // # of cols. This is a breakpoint -> cols map, e.g. {lg: 12, md: 10, ...}
330
368
  cols: ?Object = {lg: 12, md: 10, sm: 6, xs: 4, xxs: 2},
331
369
 
370
+
371
+ // margin (in pixels). Can be specified either as horizontal and vertical margin, e.g. `[10, 10]` or as a breakpoint -> margin map, e.g. `{lg: [10, 10], md: [10, 10], ...}.
372
+ margin: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]}
373
+
374
+
375
+ // containerPadding (in pixels). Can be specified either as horizontal and vertical padding, e.g. `[10, 10]` or as a breakpoint -> containerPadding map, e.g. `{lg: [10, 10], md: [10, 10], ...}.
376
+ containerPadding: [number, number] | {[breakpoint: $Keys<breakpoints>]: [number, number]}
377
+
378
+
332
379
  // layouts is an object mapping breakpoints to layouts.
333
380
  // e.g. {lg: Layout, md: Layout, ...}
334
381
  layouts: {[key: $Keys<breakpoints>]: Layout}
@@ -368,7 +415,7 @@ Any `<GridItem>` properties defined directly will take precedence over globally-
368
415
  example, if the layout has the property `isDraggable: false`, but the grid item has the prop `isDraggable: true`, the item
369
416
  will be draggable.
370
417
 
371
- ```javascript
418
+ ```js
372
419
  {
373
420
 
374
421
  // A string corresponding to the component key
@@ -397,7 +444,7 @@ will be draggable.
397
444
 
398
445
  If you have a feature request, please add it as an issue or make a pull request.
399
446
 
400
- If you have a bug to report, please reproduce the bug in [WebpackBin](http://www.webpackbin.com/VymTE3zWG) to help
447
+ If you have a bug to report, please reproduce the bug in [CodeSandbox](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js) to help
401
448
  us easily isolate it.
402
449
 
403
450
  ## TODO List