react-grid-layout 0.18.2 → 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,12 +1,14 @@
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
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"
package/.flowconfig CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  [libs]
14
14
  interfaces/
15
+ flow-typed/
15
16
 
16
17
  [options]
17
18
  emoji=true
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,14 @@
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
+
3
12
  0.18.2 (Feb 26, 2020)
4
13
  ----
5
14
 
package/README.md CHANGED
@@ -468,9 +468,9 @@ shouldComponentUpdate(nextProps: Props, nextState: State) {
468
468
  If you memoize your children, you can take advantage of this, and reap faster rerenders. For example:
469
469
 
470
470
  ```js
471
- function MyGrid() {
472
- const children = React.useMemo((count) => {
473
- return new Array(count).fill(undefined).map((val, idx) => {
471
+ function MyGrid(props) {
472
+ const children = React.useMemo(() => {
473
+ return new Array(props.count).fill(undefined).map((val, idx) => {
474
474
  return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
475
475
  });
476
476
  }, [props.count]);
@@ -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');
package/build/GridItem.js CHANGED
@@ -217,12 +217,18 @@ function (_React$Component) {
217
217
  ) {
218
218
  // We can't deeply compare children. If the developer memoizes them, we can
219
219
  // use this optimization.
220
- if (this.props.children !== nextProps.children) return true; // TODO memoize these calculations so they don't take so long?
220
+ if (this.props.children !== nextProps.children) return true;
221
+ if (this.props.droppingPosition !== nextProps.droppingPosition) return true; // TODO memoize these calculations so they don't take so long?
221
222
 
222
223
  var oldPosition = (0, _calculateUtils.calcGridItemPosition)(this.getPositionParams(this.props), this.props.x, this.props.y, this.props.w, this.props.h, this.state);
223
224
  var newPosition = (0, _calculateUtils.calcGridItemPosition)(this.getPositionParams(nextProps), nextProps.x, nextProps.y, nextProps.w, nextProps.h, nextState);
224
225
  return !(0, _utils.fastPositionEqual)(oldPosition, newPosition) || this.props.useCSSTransforms !== nextProps.useCSSTransforms;
225
226
  }
227
+ }, {
228
+ key: "componentDidMount",
229
+ value: function componentDidMount() {
230
+ this.moveDroppingItem({});
231
+ }
226
232
  }, {
227
233
  key: "componentDidUpdate",
228
234
  value: function componentDidUpdate(prevProps
@@ -238,13 +244,13 @@ function (_React$Component) {
238
244
  /*: Props*/
239
245
  ) {
240
246
  var droppingPosition = this.props.droppingPosition;
241
- var prevDroppingPosition = prevProps.droppingPosition;
247
+ if (!droppingPosition) return;
248
+ var prevDroppingPosition = prevProps.droppingPosition || {
249
+ left: 0,
250
+ top: 0
251
+ };
242
252
  var dragging = this.state.dragging;
243
253
 
244
- if (!droppingPosition || !prevDroppingPosition) {
245
- return;
246
- }
247
-
248
254
  if (!this.currentNode) {
249
255
  // eslint-disable-next-line react/no-find-dom-node
250
256
  this.currentNode = ((_reactDom.default.findDOMNode(this)
@@ -257,7 +257,7 @@ function (_React$Component) {
257
257
  return (// NOTE: this is almost always unequal. Therefore the only way to get better performance
258
258
  // from SCU is if the user intentionally memoizes children. If they do, and they can
259
259
  // handle changes properly, performance will increase.
260
- this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _lodash.default) || !(0, _lodash.default)(this.state.activeDrag, nextState.activeDrag)
260
+ this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _lodash.default) || this.state.activeDrag !== nextState.activeDrag || this.state.droppingPosition !== nextState.droppingPosition
261
261
  );
262
262
  }
263
263
  }, {
@@ -84,9 +84,9 @@ function getIndentationValue(param
84
84
 
85
85
  // Responsive config
86
86
  breakpoint?: ?Breakpoint,
87
- breakpoints: { [key: Breakpoint]: number },
87
+ breakpoints: Breakpoints<Breakpoint>,
88
88
  cols: { [key: Breakpoint]: number },
89
- layouts: { [key: Breakpoint]: Layout },
89
+ layouts: ResponsiveLayout<Breakpoint>,
90
90
  width: number,
91
91
  margin: { [key: Breakpoint]: [number, number] } | [number, number],
92
92
  containerPadding: { [key: Breakpoint]: [number, number] } | [number, number],
@@ -18,7 +18,7 @@ var _utils = require("./utils");
18
18
  * @return {String} Highest breakpoint that is less than width.
19
19
  */
20
20
  function getBreakpointFromWidth(breakpoints
21
- /*: Breakpoints*/
21
+ /*: Breakpoints<Breakpoint>*/
22
22
  , width
23
23
  /*: number*/
24
24
  )
@@ -45,7 +45,7 @@ function getBreakpointFromWidth(breakpoints
45
45
  function getColsFromBreakpoint(breakpoint
46
46
  /*: Breakpoint*/
47
47
  , cols
48
- /*: Breakpoints*/
48
+ /*: Breakpoints<Breakpoint>*/
49
49
  )
50
50
  /*: number*/
51
51
  {
@@ -72,9 +72,9 @@ function getColsFromBreakpoint(breakpoint
72
72
 
73
73
 
74
74
  function findOrGenerateResponsiveLayout(layouts
75
- /*: ResponsiveLayout*/
75
+ /*: ResponsiveLayout<Breakpoint>*/
76
76
  , breakpoints
77
- /*: Breakpoints*/
77
+ /*: Breakpoints<Breakpoint>*/
78
78
  , breakpoint
79
79
  /*: Breakpoint*/
80
80
  , lastBreakpoint
@@ -118,7 +118,7 @@ function findOrGenerateResponsiveLayout(layouts
118
118
 
119
119
 
120
120
  function sortBreakpoints(breakpoints
121
- /*: Breakpoints*/
121
+ /*: Breakpoints<Breakpoint>*/
122
122
  )
123
123
  /*: Array<Breakpoint>*/
124
124
  {
package/build/utils.js CHANGED
@@ -177,6 +177,8 @@ function collides(l1
177
177
  * Given a layout, compact it. This involves going down each y coordinate and removing gaps
178
178
  * between items.
179
179
  *
180
+ * Does not modify layout items (clones). Creates a new layout array.
181
+ *
180
182
  * @param {Array} layout Layout.
181
183
  * @param {Boolean} verticalCompact Whether or not to compact the layout
182
184
  * vertically.
@@ -259,6 +261,9 @@ function resolveCompactionCollision(layout
259
261
  }
260
262
  /**
261
263
  * Compact an item in the layout.
264
+ *
265
+ * Modifies item.
266
+ *
262
267
  */
263
268
 
264
269
 
@@ -317,6 +322,8 @@ function compactItem(compareWith
317
322
  /**
318
323
  * Given a layout, make sure all elements fit within its bounds.
319
324
  *
325
+ * Modifies layout items.
326
+ *
320
327
  * @param {Array} layout Layout array.
321
328
  * @param {Number} bounds Number of columns.
322
329
  */
@@ -424,6 +431,8 @@ function getStatics(layout
424
431
  /**
425
432
  * Move an element. Responsible for doing cascading movements of other elements.
426
433
  *
434
+ * Modifies layout items.
435
+ *
427
436
  * @param {Array} layout Full layout to modify.
428
437
  * @param {LayoutItem} l element to move.
429
438
  * @param {Number} [x] X position in grid units.
@@ -467,7 +476,8 @@ function moveElement(layout
467
476
  // nearest collision.
468
477
 
469
478
  var sorted = sortLayoutItems(layout, compactType);
470
- var movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false;
479
+ var movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false; // $FlowIgnore acceptable modification of read-only array as it was recently cloned
480
+
471
481
  if (movingUp) sorted = sorted.reverse();
472
482
  var collisions = getAllCollisions(sorted, l); // There was a collision; abort
473
483
 
@@ -619,13 +629,20 @@ function sortLayoutItems(layout
619
629
  {
620
630
  if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);else return sortLayoutItemsByRowCol(layout);
621
631
  }
632
+ /**
633
+ * Sort layout items by row ascending and column ascending.
634
+ *
635
+ * Does not modify Layout.
636
+ */
637
+
622
638
 
623
639
  function sortLayoutItemsByRowCol(layout
624
640
  /*: Layout*/
625
641
  )
626
642
  /*: Layout*/
627
643
  {
628
- return [].concat(layout).sort(function (a, b) {
644
+ // Slice to clone array as sort modifies
645
+ return layout.slice(0).sort(function (a, b) {
629
646
  if (a.y > b.y || a.y === b.y && a.x > b.x) {
630
647
  return 1;
631
648
  } else if (a.y === b.y && a.x === b.x) {
@@ -636,13 +653,19 @@ function sortLayoutItemsByRowCol(layout
636
653
  return -1;
637
654
  });
638
655
  }
656
+ /**
657
+ * Sort layout items by column ascending then row ascending.
658
+ *
659
+ * Does not modify Layout.
660
+ */
661
+
639
662
 
640
663
  function sortLayoutItemsByColRow(layout
641
664
  /*: Layout*/
642
665
  )
643
666
  /*: Layout*/
644
667
  {
645
- return [].concat(layout).sort(function (a, b) {
668
+ return layout.slice(0).sort(function (a, b) {
646
669
  if (a.x > b.x || a.x === b.x && a.y > b.y) {
647
670
  return 1;
648
671
  }
@@ -654,6 +677,8 @@ function sortLayoutItemsByColRow(layout
654
677
  * Generate a layout using the initialLayout and children as a template.
655
678
  * Missing entries will be added, extraneous ones will be truncated.
656
679
  *
680
+ * Does not modify initialLayout.
681
+ *
657
682
  * @param {Array} initialLayout Layout passed in through props.
658
683
  * @param {String} breakpoint Current responsive breakpoint.
659
684
  * @param {?String} compact Compaction option.
@@ -675,7 +700,7 @@ function synchronizeLayoutWithChildren(initialLayout
675
700
  initialLayout = initialLayout || []; // Generate one layout item per child.
676
701
 
677
702
  var layout
678
- /*: Layout*/
703
+ /*: LayoutItem[]*/
679
704
  = [];
680
705
 
681
706
  _react.default.Children.forEach(children, function (child
@@ -718,11 +743,10 @@ function synchronizeLayoutWithChildren(initialLayout
718
743
  }); // Correct the layout.
719
744
 
720
745
 
721
- layout = correctBounds(layout, {
746
+ var correctedLayout = correctBounds(layout, {
722
747
  cols: cols
723
748
  });
724
- layout = compact(layout, compactType, cols);
725
- return layout;
749
+ return compact(correctedLayout, compactType, cols);
726
750
  }
727
751
  /**
728
752
  * Validate a layout. Throws errors.
@@ -0,0 +1,23 @@
1
+ // flow-typed signature: a00cf41b09af4862583460529d5cfcb9
2
+ // flow-typed version: c6154227d1/classnames_v2.x.x/flow_>=v0.104.x
3
+
4
+ type $npm$classnames$Classes =
5
+ | string
6
+ | { [className: string]: *, ... }
7
+ | false
8
+ | void
9
+ | null;
10
+
11
+ declare module "classnames" {
12
+ declare module.exports: (
13
+ ...classes: Array<$npm$classnames$Classes | $npm$classnames$Classes[]>
14
+ ) => string;
15
+ }
16
+
17
+ declare module "classnames/bind" {
18
+ declare module.exports: $Exports<"classnames">;
19
+ }
20
+
21
+ declare module "classnames/dedupe" {
22
+ declare module.exports: $Exports<"classnames">;
23
+ }
@@ -0,0 +1,143 @@
1
+ // flow-typed signature: 931d5482afcb022bcbddb841fd08d683
2
+ // flow-typed version: 5175c53189/enzyme_v3.x.x/flow_>=v0.104.x
3
+
4
+ declare module "enzyme" {
5
+ declare type PredicateFunction<T: Wrapper<*>> = (
6
+ wrapper: T,
7
+ index: number
8
+ ) => boolean;
9
+ declare type UntypedSelector = string | { [key: string]: number|string|boolean, ... };
10
+ declare type EnzymeSelector = UntypedSelector | React$ElementType;
11
+
12
+ // CheerioWrapper is a type alias for an actual cheerio instance
13
+ // TODO: Reference correct type from cheerio's type declarations
14
+ declare type CheerioWrapper = any;
15
+
16
+ declare class Wrapper<RootComponent> {
17
+ equals(node: React$Element<any>): boolean,
18
+ find(selector: UntypedSelector): this,
19
+ find<T: React$ElementType>(selector: T): ReactWrapper<T>,
20
+ findWhere(predicate: PredicateFunction<this>): this,
21
+ filter(selector: UntypedSelector): this,
22
+ filter<T: React$ElementType>(selector: T): ReactWrapper<T>,
23
+ filterWhere(predicate: PredicateFunction<this>): this,
24
+ hostNodes(): this,
25
+ contains(nodes: React$Node): boolean,
26
+ containsMatchingElement(node: React$Node): boolean,
27
+ containsAllMatchingElements(nodes: React$Node): boolean,
28
+ containsAnyMatchingElements(nodes: React$Node): boolean,
29
+ dive(option?: { context?: Object, ... }): this,
30
+ exists(selector?: EnzymeSelector): boolean,
31
+ isEmptyRender(): boolean,
32
+ matchesElement(node: React$Node): boolean,
33
+ hasClass(className: string): boolean,
34
+ is(selector: EnzymeSelector): boolean,
35
+ isEmpty(): boolean,
36
+ not(selector: EnzymeSelector): this,
37
+ children(selector?: UntypedSelector): this,
38
+ children<T: React$ElementType>(selector: T): ReactWrapper<T>,
39
+ childAt(index: number): this,
40
+ parents(selector?: UntypedSelector): this,
41
+ parents<T: React$ElementType>(selector: T): ReactWrapper<T>,
42
+ parent(): this,
43
+ closest(selector: UntypedSelector): this,
44
+ closest<T: React$ElementType>(selector: T): ReactWrapper<T>,
45
+ render(): CheerioWrapper,
46
+ renderProp(propName: string): (...args: Array<any>) => this,
47
+ unmount(): this,
48
+ text(): string,
49
+ html(): string,
50
+ invoke(propName: string): (...args: $ReadOnlyArray<any>) => mixed,
51
+ get(index: number): React$Node,
52
+ getDOMNode(): HTMLElement | HTMLInputElement,
53
+ at(index: number): this,
54
+ first(): this,
55
+ last(): this,
56
+ state(key?: string): any,
57
+ context(key?: string): any,
58
+ props(): Object,
59
+ prop(key: string): any,
60
+ key(): string,
61
+ simulate(event: string, ...args: Array<any>): this,
62
+ simulateError(error: Error): this,
63
+ slice(begin?: number, end?: number): this,
64
+ setState(state: {...}, callback?: () => void): this,
65
+ setProps(props: {...}, callback?: () => void): this,
66
+ setContext(context: Object): this,
67
+ instance(): React$ElementRef<RootComponent>,
68
+ update(): this,
69
+ debug(options?: Object): string,
70
+ type(): string | Function | null,
71
+ name(): string,
72
+ forEach(fn: (node: this, index: number) => mixed): this,
73
+ map<T>(fn: (node: this, index: number) => T): Array<T>,
74
+ reduce<T>(
75
+ fn: (value: T, node: this, index: number) => T,
76
+ initialValue?: T
77
+ ): Array<T>,
78
+ reduceRight<T>(
79
+ fn: (value: T, node: this, index: number) => T,
80
+ initialValue?: T
81
+ ): Array<T>,
82
+ some(selector: EnzymeSelector): boolean,
83
+ someWhere(predicate: PredicateFunction<this>): boolean,
84
+ every(selector: EnzymeSelector): boolean,
85
+ everyWhere(predicate: PredicateFunction<this>): boolean,
86
+ length: number
87
+ }
88
+
89
+ declare class ReactWrapper<T> extends Wrapper<T> {
90
+ constructor(nodes: React$Element<T>, root: any, options?: ?Object): ReactWrapper<T>,
91
+ mount(): this,
92
+ ref(refName: string): this,
93
+ detach(): void
94
+ }
95
+
96
+ declare class ShallowWrapper<T> extends Wrapper<T> {
97
+ constructor(
98
+ nodes: React$Element<T>,
99
+ root: any,
100
+ options?: ?Object
101
+ ): ShallowWrapper<T>,
102
+ equals(node: React$Node): boolean,
103
+ shallow(options?: { context?: Object, ... }): ShallowWrapper<T>,
104
+ getElement(): React$Node,
105
+ getElements(): Array<React$Node>
106
+ }
107
+
108
+ declare function shallow<T>(
109
+ node: React$Element<T>,
110
+ options?: {
111
+ context?: Object,
112
+ disableLifecycleMethods?: boolean,
113
+ ...
114
+ }
115
+ ): ShallowWrapper<T>;
116
+ declare function mount<T>(
117
+ node: React$Element<T>,
118
+ options?: {
119
+ context?: Object,
120
+ attachTo?: HTMLElement,
121
+ childContextTypes?: Object,
122
+ ...
123
+ }
124
+ ): ReactWrapper<T>;
125
+ declare function render(
126
+ node: React$Node,
127
+ options?: { context?: Object, ... }
128
+ ): CheerioWrapper;
129
+
130
+ declare module.exports: {
131
+ configure(options: {
132
+ Adapter?: any,
133
+ disableLifecycleMethods?: boolean,
134
+ ...
135
+ }): void,
136
+ render: typeof render,
137
+ mount: typeof mount,
138
+ shallow: typeof shallow,
139
+ ShallowWrapper: typeof ShallowWrapper,
140
+ ReactWrapper: typeof ReactWrapper,
141
+ ...
142
+ };
143
+ }