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 +10 -14
- package/.flowconfig +13 -1
- package/.travis.yml +3 -1
- package/CHANGELOG.md +66 -0
- package/README.md +47 -7
- package/__mocks__/react-grid-layout.js +2 -0
- package/build/GridItem.js +125 -211
- package/build/ReactGridLayout.js +142 -220
- package/build/ReactGridLayoutPropTypes.js +129 -0
- package/build/ResponsiveReactGridLayout.js +52 -44
- package/build/calculateUtils.js +177 -0
- package/build/components/WidthProvider.js +21 -11
- package/build/fastRGLPropsEqual.js +5 -0
- package/build/responsiveUtils.js +5 -5
- package/build/utils.js +77 -10
- package/css/styles.css +4 -0
- package/flow-typed/npm/classnames_v2.x.x.js +23 -0
- package/flow-typed/npm/enzyme_v3.x.x.js +143 -0
- package/flow-typed/npm/jest_v24.x.x.js +1182 -0
- package/lib/GridItem.jsx +125 -148
- package/lib/ReactGridLayout.jsx +83 -200
- package/lib/ReactGridLayoutPropTypes.js +179 -0
- package/lib/ResponsiveReactGridLayout.jsx +36 -28
- package/lib/calculateUtils.js +142 -0
- package/lib/components/WidthProvider.jsx +35 -16
- package/lib/fastRGLPropsEqual.js +46 -0
- package/lib/responsiveUtils.js +13 -20
- package/lib/utils.js +62 -10
- package/package.json +44 -29
package/build/utils.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.bottom = bottom;
|
|
|
7
7
|
exports.cloneLayout = cloneLayout;
|
|
8
8
|
exports.cloneLayoutItem = cloneLayoutItem;
|
|
9
9
|
exports.childrenEqual = childrenEqual;
|
|
10
|
+
exports.fastPositionEqual = fastPositionEqual;
|
|
10
11
|
exports.collides = collides;
|
|
11
12
|
exports.compact = compact;
|
|
12
13
|
exports.compactItem = compactItem;
|
|
@@ -25,8 +26,9 @@ exports.sortLayoutItemsByRowCol = sortLayoutItemsByRowCol;
|
|
|
25
26
|
exports.sortLayoutItemsByColRow = sortLayoutItemsByColRow;
|
|
26
27
|
exports.synchronizeLayoutWithChildren = synchronizeLayoutWithChildren;
|
|
27
28
|
exports.validateLayout = validateLayout;
|
|
29
|
+
exports.compactType = compactType;
|
|
28
30
|
exports.autoBindHandlers = autoBindHandlers;
|
|
29
|
-
exports.noop = void 0;
|
|
31
|
+
exports.noop = exports.fastRGLPropsEqual = void 0;
|
|
30
32
|
|
|
31
33
|
var _lodash = _interopRequireDefault(require("lodash.isequal"));
|
|
32
34
|
|
|
@@ -36,7 +38,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
36
38
|
|
|
37
39
|
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; }
|
|
38
40
|
|
|
39
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
41
|
+
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; }
|
|
40
42
|
|
|
41
43
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
42
44
|
|
|
@@ -121,6 +123,32 @@ function childrenEqual(a
|
|
|
121
123
|
return c.key;
|
|
122
124
|
}));
|
|
123
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* See `fastRGLPropsEqual.js`.
|
|
128
|
+
* We want this to run as fast as possible - it is called often - and to be
|
|
129
|
+
* resilient to new props that we add. So rather than call lodash.isEqual,
|
|
130
|
+
* which isn't suited to comparing props very well, we use this specialized
|
|
131
|
+
* function in conjunction with preval to generate the fastest possible comparison
|
|
132
|
+
* function, tuned for exactly our props.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
/*:: type FastRGLPropsEqual = (Object, Object, Function) => boolean;*/
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
var fastRGLPropsEqual
|
|
139
|
+
/*: FastRGLPropsEqual*/
|
|
140
|
+
= require("./fastRGLPropsEqual"); // Like the above, but a lot simpler.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
exports.fastRGLPropsEqual = fastRGLPropsEqual;
|
|
144
|
+
|
|
145
|
+
function fastPositionEqual(a
|
|
146
|
+
/*: Position*/
|
|
147
|
+
, b
|
|
148
|
+
/*: Position*/
|
|
149
|
+
) {
|
|
150
|
+
return a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height;
|
|
151
|
+
}
|
|
124
152
|
/**
|
|
125
153
|
* Given two layoutitems, check if they collide.
|
|
126
154
|
*/
|
|
@@ -149,6 +177,8 @@ function collides(l1
|
|
|
149
177
|
* Given a layout, compact it. This involves going down each y coordinate and removing gaps
|
|
150
178
|
* between items.
|
|
151
179
|
*
|
|
180
|
+
* Does not modify layout items (clones). Creates a new layout array.
|
|
181
|
+
*
|
|
152
182
|
* @param {Array} layout Layout.
|
|
153
183
|
* @param {Boolean} verticalCompact Whether or not to compact the layout
|
|
154
184
|
* vertically.
|
|
@@ -231,6 +261,9 @@ function resolveCompactionCollision(layout
|
|
|
231
261
|
}
|
|
232
262
|
/**
|
|
233
263
|
* Compact an item in the layout.
|
|
264
|
+
*
|
|
265
|
+
* Modifies item.
|
|
266
|
+
*
|
|
234
267
|
*/
|
|
235
268
|
|
|
236
269
|
|
|
@@ -289,6 +322,8 @@ function compactItem(compareWith
|
|
|
289
322
|
/**
|
|
290
323
|
* Given a layout, make sure all elements fit within its bounds.
|
|
291
324
|
*
|
|
325
|
+
* Modifies layout items.
|
|
326
|
+
*
|
|
292
327
|
* @param {Array} layout Layout array.
|
|
293
328
|
* @param {Number} bounds Number of columns.
|
|
294
329
|
*/
|
|
@@ -396,6 +431,8 @@ function getStatics(layout
|
|
|
396
431
|
/**
|
|
397
432
|
* Move an element. Responsible for doing cascading movements of other elements.
|
|
398
433
|
*
|
|
434
|
+
* Modifies layout items.
|
|
435
|
+
*
|
|
399
436
|
* @param {Array} layout Full layout to modify.
|
|
400
437
|
* @param {LayoutItem} l element to move.
|
|
401
438
|
* @param {Number} [x] X position in grid units.
|
|
@@ -422,7 +459,9 @@ function moveElement(layout
|
|
|
422
459
|
)
|
|
423
460
|
/*: Layout*/
|
|
424
461
|
{
|
|
425
|
-
|
|
462
|
+
// If this is static and not explicitly enabled as draggable,
|
|
463
|
+
// no move is possible, so we can short-circuit this immediately.
|
|
464
|
+
if (l.static && l.isDraggable !== true) return layout; // Short-circuit if nothing to do.
|
|
426
465
|
|
|
427
466
|
if (l.y === y && l.x === x) return layout;
|
|
428
467
|
log("Moving element ".concat(l.i, " to [").concat(String(x), ",").concat(String(y), "] from [").concat(l.x, ",").concat(l.y, "]"));
|
|
@@ -437,7 +476,8 @@ function moveElement(layout
|
|
|
437
476
|
// nearest collision.
|
|
438
477
|
|
|
439
478
|
var sorted = sortLayoutItems(layout, compactType);
|
|
440
|
-
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
|
+
|
|
441
481
|
if (movingUp) sorted = sorted.reverse();
|
|
442
482
|
var collisions = getAllCollisions(sorted, l); // There was a collision; abort
|
|
443
483
|
|
|
@@ -589,13 +629,20 @@ function sortLayoutItems(layout
|
|
|
589
629
|
{
|
|
590
630
|
if (compactType === "horizontal") return sortLayoutItemsByColRow(layout);else return sortLayoutItemsByRowCol(layout);
|
|
591
631
|
}
|
|
632
|
+
/**
|
|
633
|
+
* Sort layout items by row ascending and column ascending.
|
|
634
|
+
*
|
|
635
|
+
* Does not modify Layout.
|
|
636
|
+
*/
|
|
637
|
+
|
|
592
638
|
|
|
593
639
|
function sortLayoutItemsByRowCol(layout
|
|
594
640
|
/*: Layout*/
|
|
595
641
|
)
|
|
596
642
|
/*: Layout*/
|
|
597
643
|
{
|
|
598
|
-
|
|
644
|
+
// Slice to clone array as sort modifies
|
|
645
|
+
return layout.slice(0).sort(function (a, b) {
|
|
599
646
|
if (a.y > b.y || a.y === b.y && a.x > b.x) {
|
|
600
647
|
return 1;
|
|
601
648
|
} else if (a.y === b.y && a.x === b.x) {
|
|
@@ -606,13 +653,19 @@ function sortLayoutItemsByRowCol(layout
|
|
|
606
653
|
return -1;
|
|
607
654
|
});
|
|
608
655
|
}
|
|
656
|
+
/**
|
|
657
|
+
* Sort layout items by column ascending then row ascending.
|
|
658
|
+
*
|
|
659
|
+
* Does not modify Layout.
|
|
660
|
+
*/
|
|
661
|
+
|
|
609
662
|
|
|
610
663
|
function sortLayoutItemsByColRow(layout
|
|
611
664
|
/*: Layout*/
|
|
612
665
|
)
|
|
613
666
|
/*: Layout*/
|
|
614
667
|
{
|
|
615
|
-
return
|
|
668
|
+
return layout.slice(0).sort(function (a, b) {
|
|
616
669
|
if (a.x > b.x || a.x === b.x && a.y > b.y) {
|
|
617
670
|
return 1;
|
|
618
671
|
}
|
|
@@ -624,6 +677,8 @@ function sortLayoutItemsByColRow(layout
|
|
|
624
677
|
* Generate a layout using the initialLayout and children as a template.
|
|
625
678
|
* Missing entries will be added, extraneous ones will be truncated.
|
|
626
679
|
*
|
|
680
|
+
* Does not modify initialLayout.
|
|
681
|
+
*
|
|
627
682
|
* @param {Array} initialLayout Layout passed in through props.
|
|
628
683
|
* @param {String} breakpoint Current responsive breakpoint.
|
|
629
684
|
* @param {?String} compact Compaction option.
|
|
@@ -645,7 +700,7 @@ function synchronizeLayoutWithChildren(initialLayout
|
|
|
645
700
|
initialLayout = initialLayout || []; // Generate one layout item per child.
|
|
646
701
|
|
|
647
702
|
var layout
|
|
648
|
-
/*:
|
|
703
|
+
/*: LayoutItem[]*/
|
|
649
704
|
= [];
|
|
650
705
|
|
|
651
706
|
_react.default.Children.forEach(children, function (child
|
|
@@ -688,11 +743,10 @@ function synchronizeLayoutWithChildren(initialLayout
|
|
|
688
743
|
}); // Correct the layout.
|
|
689
744
|
|
|
690
745
|
|
|
691
|
-
|
|
746
|
+
var correctedLayout = correctBounds(layout, {
|
|
692
747
|
cols: cols
|
|
693
748
|
});
|
|
694
|
-
|
|
695
|
-
return layout;
|
|
749
|
+
return compact(correctedLayout, compactType, cols);
|
|
696
750
|
}
|
|
697
751
|
/**
|
|
698
752
|
* Validate a layout. Throws errors.
|
|
@@ -731,6 +785,19 @@ function validateLayout(layout
|
|
|
731
785
|
throw new Error("ReactGridLayout: " + contextName + "[" + i + "].static must be a boolean!");
|
|
732
786
|
}
|
|
733
787
|
}
|
|
788
|
+
} // Legacy support for verticalCompact: false
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
function compactType(props
|
|
792
|
+
/*: ?{ verticalCompact: boolean, compactType: CompactType }*/
|
|
793
|
+
)
|
|
794
|
+
/*: CompactType*/
|
|
795
|
+
{
|
|
796
|
+
var _ref3 = props || {},
|
|
797
|
+
verticalCompact = _ref3.verticalCompact,
|
|
798
|
+
compactType = _ref3.compactType;
|
|
799
|
+
|
|
800
|
+
return verticalCompact === false ? null : compactType;
|
|
734
801
|
} // Flow can't really figure this out, so we just use Object
|
|
735
802
|
|
|
736
803
|
|
package/css/styles.css
CHANGED
|
@@ -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
|
+
}
|