react-grid-layout 1.2.1 → 1.2.5
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/.flowconfig +1 -1
- package/CHANGELOG.md +40 -0
- package/README.md +6 -7
- package/build/GridItem.js +13 -19
- package/build/ReactGridLayout.js +53 -40
- package/build/ReactGridLayoutPropTypes.js +5 -5
- package/build/ResponsiveReactGridLayout.js +3 -3
- package/build/components/WidthProvider.js +27 -23
- package/build/utils.js +52 -3
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.LICENSE.txt +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/lib/GridItem.jsx +18 -14
- package/lib/ReactGridLayout.jsx +49 -46
- package/lib/ReactGridLayoutPropTypes.js +11 -6
- package/lib/components/WidthProvider.jsx +35 -23
- package/lib/utils.js +36 -0
- package/package.json +26 -21
- package/.husky/pre-commit +0 -6
- package/.travis.yml +0 -9
package/lib/GridItem.jsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import React from "react";
|
|
3
|
-
import ReactDOM from "react-dom";
|
|
4
3
|
import PropTypes from "prop-types";
|
|
5
4
|
import { DraggableCore } from "react-draggable";
|
|
6
5
|
import { Resizable } from "react-resizable";
|
|
@@ -14,7 +13,7 @@ import {
|
|
|
14
13
|
clamp
|
|
15
14
|
} from "./calculateUtils";
|
|
16
15
|
import {
|
|
17
|
-
|
|
16
|
+
resizeHandleAxesType,
|
|
18
17
|
resizeHandleType
|
|
19
18
|
} from "./ReactGridLayoutPropTypes";
|
|
20
19
|
import classNames from "classnames";
|
|
@@ -29,7 +28,11 @@ import type {
|
|
|
29
28
|
} from "./utils";
|
|
30
29
|
|
|
31
30
|
import type { PositionParams } from "./calculateUtils";
|
|
32
|
-
import type {
|
|
31
|
+
import type {
|
|
32
|
+
ResizeHandleAxis,
|
|
33
|
+
ResizeHandle,
|
|
34
|
+
ReactRef
|
|
35
|
+
} from "./ReactGridLayoutPropTypes";
|
|
33
36
|
|
|
34
37
|
type PartialPosition = { top: number, left: number };
|
|
35
38
|
type GridItemCallback<Data: GridDragEvent | GridResizeEvent> = (
|
|
@@ -79,7 +82,7 @@ type Props = {
|
|
|
79
82
|
maxH: number,
|
|
80
83
|
i: string,
|
|
81
84
|
|
|
82
|
-
resizeHandles?:
|
|
85
|
+
resizeHandles?: ResizeHandleAxis[],
|
|
83
86
|
resizeHandle?: ResizeHandle,
|
|
84
87
|
|
|
85
88
|
onDrag?: GridItemCallback<GridDragEvent>,
|
|
@@ -156,7 +159,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
156
159
|
i: PropTypes.string.isRequired,
|
|
157
160
|
|
|
158
161
|
// Resize handle options
|
|
159
|
-
resizeHandles:
|
|
162
|
+
resizeHandles: resizeHandleAxesType,
|
|
160
163
|
resizeHandle: resizeHandleType,
|
|
161
164
|
|
|
162
165
|
// Functions
|
|
@@ -208,7 +211,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
208
211
|
className: ""
|
|
209
212
|
};
|
|
210
213
|
|
|
211
|
-
|
|
214
|
+
elementRef: ReactRef<HTMLDivElement> = React.createRef();
|
|
212
215
|
|
|
213
216
|
shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
|
|
214
217
|
// We can't deeply compare children. If the developer memoizes them, we can
|
|
@@ -251,6 +254,9 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
251
254
|
moveDroppingItem(prevProps: Props) {
|
|
252
255
|
const { droppingPosition } = this.props;
|
|
253
256
|
if (!droppingPosition) return;
|
|
257
|
+
const node = this.elementRef.current;
|
|
258
|
+
// Can't find DOM node (are we unmounted?)
|
|
259
|
+
if (!node) return;
|
|
254
260
|
|
|
255
261
|
const prevDroppingPosition = prevProps.droppingPosition || {
|
|
256
262
|
left: 0,
|
|
@@ -258,18 +264,13 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
258
264
|
};
|
|
259
265
|
const { dragging } = this.state;
|
|
260
266
|
|
|
261
|
-
if (!this.currentNode) {
|
|
262
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
263
|
-
this.currentNode = ((ReactDOM.findDOMNode(this): any): HTMLElement);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
267
|
const shouldDrag =
|
|
267
268
|
(dragging && droppingPosition.left !== prevDroppingPosition.left) ||
|
|
268
269
|
droppingPosition.top !== prevDroppingPosition.top;
|
|
269
270
|
|
|
270
271
|
if (!dragging) {
|
|
271
272
|
this.onDragStart(droppingPosition.e, {
|
|
272
|
-
node
|
|
273
|
+
node,
|
|
273
274
|
deltaX: droppingPosition.left,
|
|
274
275
|
deltaY: droppingPosition.top
|
|
275
276
|
});
|
|
@@ -278,7 +279,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
278
279
|
const deltaY = droppingPosition.top - dragging.top;
|
|
279
280
|
|
|
280
281
|
this.onDrag(droppingPosition.e, {
|
|
281
|
-
node
|
|
282
|
+
node,
|
|
282
283
|
deltaX,
|
|
283
284
|
deltaY
|
|
284
285
|
});
|
|
@@ -348,6 +349,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
348
349
|
(this.props.cancel ? "," + this.props.cancel : "")
|
|
349
350
|
}
|
|
350
351
|
scale={this.props.transformScale}
|
|
352
|
+
nodeRef={this.elementRef}
|
|
351
353
|
>
|
|
352
354
|
{child}
|
|
353
355
|
</DraggableCore>
|
|
@@ -392,8 +394,9 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
392
394
|
];
|
|
393
395
|
return (
|
|
394
396
|
<Resizable
|
|
397
|
+
// These are opts for the resize handle itself
|
|
395
398
|
draggableOpts={{
|
|
396
|
-
disabled: !isResizable
|
|
399
|
+
disabled: !isResizable,
|
|
397
400
|
}}
|
|
398
401
|
className={isResizable ? undefined : "react-resizable-hide"}
|
|
399
402
|
width={position.width}
|
|
@@ -630,6 +633,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
630
633
|
|
|
631
634
|
// Create the child element. We clone the existing element but modify its className and style.
|
|
632
635
|
let newChild = React.cloneElement(child, {
|
|
636
|
+
ref: this.elementRef,
|
|
633
637
|
className: classNames(
|
|
634
638
|
"react-grid-item",
|
|
635
639
|
child.props.className,
|
package/lib/ReactGridLayout.jsx
CHANGED
|
@@ -9,13 +9,14 @@ import {
|
|
|
9
9
|
childrenEqual,
|
|
10
10
|
cloneLayoutItem,
|
|
11
11
|
compact,
|
|
12
|
+
compactType,
|
|
13
|
+
fastRGLPropsEqual,
|
|
14
|
+
getAllCollisions,
|
|
12
15
|
getLayoutItem,
|
|
13
16
|
moveElement,
|
|
14
|
-
synchronizeLayoutWithChildren,
|
|
15
|
-
getAllCollisions,
|
|
16
|
-
compactType,
|
|
17
17
|
noop,
|
|
18
|
-
|
|
18
|
+
synchronizeLayoutWithChildren,
|
|
19
|
+
withLayoutItem
|
|
19
20
|
} from "./utils";
|
|
20
21
|
|
|
21
22
|
import { calcXY } from "./calculateUtils";
|
|
@@ -255,7 +256,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
255
256
|
{ e, node }: GridDragEvent
|
|
256
257
|
): void {
|
|
257
258
|
const { layout } = this.state;
|
|
258
|
-
|
|
259
|
+
const l = getLayoutItem(layout, i);
|
|
259
260
|
if (!l) return;
|
|
260
261
|
|
|
261
262
|
this.setState({
|
|
@@ -278,11 +279,11 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
278
279
|
const { oldDragItem } = this.state;
|
|
279
280
|
let { layout } = this.state;
|
|
280
281
|
const { cols } = this.props;
|
|
281
|
-
|
|
282
|
+
const l = getLayoutItem(layout, i);
|
|
282
283
|
if (!l) return;
|
|
283
284
|
|
|
284
285
|
// Create placeholder (display only)
|
|
285
|
-
|
|
286
|
+
const placeholder = {
|
|
286
287
|
w: l.w,
|
|
287
288
|
h: l.h,
|
|
288
289
|
x: l.x,
|
|
@@ -372,7 +373,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
372
373
|
|
|
373
374
|
onResizeStart(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
|
|
374
375
|
const { layout } = this.state;
|
|
375
|
-
|
|
376
|
+
const l = getLayoutItem(layout, i);
|
|
376
377
|
if (!l) return;
|
|
377
378
|
|
|
378
379
|
this.setState({
|
|
@@ -386,44 +387,46 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
386
387
|
onResize(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
|
|
387
388
|
const { layout, oldResizeItem } = this.state;
|
|
388
389
|
const { cols, preventCollision } = this.props;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
if (
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
415
|
-
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
390
|
+
|
|
391
|
+
const [newLayout, l] = withLayoutItem(layout, i, l => {
|
|
392
|
+
// Something like quad tree should be used
|
|
393
|
+
// to find collisions faster
|
|
394
|
+
let hasCollisions;
|
|
395
|
+
if (preventCollision) {
|
|
396
|
+
const collisions = getAllCollisions(layout, { ...l, w, h }).filter(
|
|
397
|
+
layoutItem => layoutItem.i !== l.i
|
|
398
|
+
);
|
|
399
|
+
hasCollisions = collisions.length > 0;
|
|
400
|
+
|
|
401
|
+
// If we're colliding, we need adjust the placeholder.
|
|
402
|
+
if (hasCollisions) {
|
|
403
|
+
// adjust w && h to maximum allowed space
|
|
404
|
+
let leastX = Infinity,
|
|
405
|
+
leastY = Infinity;
|
|
406
|
+
collisions.forEach(layoutItem => {
|
|
407
|
+
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
408
|
+
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
412
|
+
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
413
|
+
}
|
|
416
414
|
}
|
|
417
|
-
}
|
|
418
415
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
416
|
+
if (!hasCollisions) {
|
|
417
|
+
// Set new width and height.
|
|
418
|
+
l.w = w;
|
|
419
|
+
l.h = h;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return l;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// Shouldn't ever happen, but typechecking makes it necessary
|
|
426
|
+
if (!l) return;
|
|
424
427
|
|
|
425
428
|
// Create placeholder element (display only)
|
|
426
|
-
|
|
429
|
+
const placeholder = {
|
|
427
430
|
w: l.w,
|
|
428
431
|
h: l.h,
|
|
429
432
|
x: l.x,
|
|
@@ -432,11 +435,11 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
432
435
|
i: i
|
|
433
436
|
};
|
|
434
437
|
|
|
435
|
-
this.props.onResize(
|
|
438
|
+
this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node);
|
|
436
439
|
|
|
437
|
-
// Re-compact the
|
|
440
|
+
// Re-compact the newLayout and set the drag placeholder.
|
|
438
441
|
this.setState({
|
|
439
|
-
layout: compact(
|
|
442
|
+
layout: compact(newLayout, compactType(this.props), cols),
|
|
440
443
|
activeDrag: placeholder
|
|
441
444
|
});
|
|
442
445
|
}
|
|
@@ -444,7 +447,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
444
447
|
onResizeStop(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
|
|
445
448
|
const { layout, oldResizeItem } = this.state;
|
|
446
449
|
const { cols } = this.props;
|
|
447
|
-
|
|
450
|
+
const l = getLayoutItem(layout, i);
|
|
448
451
|
|
|
449
452
|
this.props.onResizeStop(layout, oldResizeItem, l, null, e, node);
|
|
450
453
|
|
|
@@ -8,11 +8,16 @@ import type {
|
|
|
8
8
|
} from "react";
|
|
9
9
|
import type { EventCallback, CompactType, Layout, LayoutItem } from "./utils";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
export type
|
|
11
|
+
// util
|
|
12
|
+
export type ReactRef<T: HTMLElement> = {|
|
|
13
|
+
+current: T | null
|
|
14
|
+
|};
|
|
15
|
+
|
|
16
|
+
export type ResizeHandleAxis = "s" | "w" | "e" | "n" | "sw" | "nw" | "se" | "ne";
|
|
13
17
|
export type ResizeHandle =
|
|
14
18
|
| ReactElement<any>
|
|
15
|
-
| ((resizeHandleAxis: ResizeHandleAxis) => ReactElement<any>);
|
|
19
|
+
| ((resizeHandleAxis: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>);
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
// Defines which resize handles should be rendered (default: 'se')
|
|
18
23
|
// Allows for any combination of:
|
|
@@ -24,7 +29,7 @@ export type ResizeHandle =
|
|
|
24
29
|
// 'nw' - Northwest handle (top-left)
|
|
25
30
|
// 'se' - Southeast handle (bottom-right)
|
|
26
31
|
// 'ne' - Northeast handle (top-right)
|
|
27
|
-
export const
|
|
32
|
+
export const resizeHandleAxesType: ReactPropsChainableTypeChecker = PropTypes.arrayOf(
|
|
28
33
|
PropTypes.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])
|
|
29
34
|
);
|
|
30
35
|
// Custom component for resize handles
|
|
@@ -55,7 +60,7 @@ export type Props = {|
|
|
|
55
60
|
useCSSTransforms: boolean,
|
|
56
61
|
transformScale: number,
|
|
57
62
|
droppingItem: $Shape<LayoutItem>,
|
|
58
|
-
resizeHandles:
|
|
63
|
+
resizeHandles: ResizeHandleAxis[],
|
|
59
64
|
resizeHandle?: ResizeHandle,
|
|
60
65
|
|
|
61
66
|
// Callbacks
|
|
@@ -164,7 +169,7 @@ export default {
|
|
|
164
169
|
isDroppable: PropTypes.bool,
|
|
165
170
|
|
|
166
171
|
// Resize handle options
|
|
167
|
-
resizeHandles:
|
|
172
|
+
resizeHandles: resizeHandleAxesType,
|
|
168
173
|
resizeHandle: resizeHandleType,
|
|
169
174
|
|
|
170
175
|
//
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import type { ReactRef } from "../ReactGridLayoutPropTypes";
|
|
5
6
|
|
|
6
7
|
type WPDefaultProps = {|
|
|
7
8
|
measureBeforeMount: boolean
|
|
@@ -18,29 +19,27 @@ type WPState = {|
|
|
|
18
19
|
width: number
|
|
19
20
|
|};
|
|
20
21
|
|
|
22
|
+
type ComposedProps<Config> = {|
|
|
23
|
+
...Config,
|
|
24
|
+
measureBeforeMount?: boolean,
|
|
25
|
+
className?: string,
|
|
26
|
+
style?: Object,
|
|
27
|
+
width?: number
|
|
28
|
+
|};
|
|
29
|
+
|
|
30
|
+
const layoutClassName = "react-grid-layout";
|
|
31
|
+
|
|
21
32
|
/*
|
|
22
33
|
* A simple HOC that provides facility for listening to container resizes.
|
|
23
34
|
*
|
|
24
35
|
* The Flow type is pretty janky here. I can't just spread `WPProps` into this returned object - I wish I could - but it triggers
|
|
25
36
|
* a flow bug of some sort that causes it to stop typechecking.
|
|
26
37
|
*/
|
|
27
|
-
export default function
|
|
38
|
+
export default function WidthProvideRGL<Config>(
|
|
28
39
|
ComposedComponent: React.AbstractComponent<Config>
|
|
29
|
-
): React.AbstractComponent<{
|
|
30
|
-
...Config,
|
|
31
|
-
measureBeforeMount?: boolean,
|
|
32
|
-
className?: string,
|
|
33
|
-
style?: Object,
|
|
34
|
-
width?: number
|
|
35
|
-
|}> {
|
|
40
|
+
): React.AbstractComponent<ComposedProps<Config>> {
|
|
36
41
|
return class WidthProvider extends React.Component<
|
|
37
|
-
|
|
38
|
-
...Config,
|
|
39
|
-
measureBeforeMount?: boolean,
|
|
40
|
-
className?: string,
|
|
41
|
-
style?: Object,
|
|
42
|
-
width?: number
|
|
43
|
-
|},
|
|
42
|
+
ComposedProps<Config>,
|
|
44
43
|
WPState
|
|
45
44
|
> {
|
|
46
45
|
static defaultProps: WPDefaultProps = {
|
|
@@ -53,15 +52,15 @@ export default function WidthProvider<Config>(
|
|
|
53
52
|
measureBeforeMount: PropTypes.bool
|
|
54
53
|
};
|
|
55
54
|
|
|
56
|
-
state = {
|
|
55
|
+
state: WPState = {
|
|
57
56
|
width: 1280
|
|
58
57
|
};
|
|
59
58
|
|
|
59
|
+
elementRef: ReactRef<HTMLDivElement> = React.createRef();
|
|
60
60
|
mounted: boolean = false;
|
|
61
61
|
|
|
62
62
|
componentDidMount() {
|
|
63
63
|
this.mounted = true;
|
|
64
|
-
|
|
65
64
|
window.addEventListener("resize", this.onWindowResize);
|
|
66
65
|
// Call to properly set the breakpoint and resize the elements.
|
|
67
66
|
// Note that if you're doing a full-width element, this can get a little wonky if a scrollbar
|
|
@@ -76,21 +75,34 @@ export default function WidthProvider<Config>(
|
|
|
76
75
|
|
|
77
76
|
onWindowResize = () => {
|
|
78
77
|
if (!this.mounted) return;
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
const node = this.elementRef.current; // Flow casts this to Text | Element
|
|
79
|
+
// fix: grid position error when node or parentNode display is none by window resize
|
|
80
|
+
// #924 #1084
|
|
81
|
+
if (node instanceof HTMLElement && node.offsetWidth) {
|
|
82
82
|
this.setState({ width: node.offsetWidth });
|
|
83
|
+
}
|
|
83
84
|
};
|
|
84
85
|
|
|
85
86
|
render() {
|
|
86
87
|
const { measureBeforeMount, ...rest } = this.props;
|
|
87
88
|
if (measureBeforeMount && !this.mounted) {
|
|
88
89
|
return (
|
|
89
|
-
<div
|
|
90
|
+
<div
|
|
91
|
+
className={classNames(this.props.className, layoutClassName)}
|
|
92
|
+
style={this.props.style}
|
|
93
|
+
// $FlowIgnore ref types
|
|
94
|
+
ref={this.elementRef}
|
|
95
|
+
/>
|
|
90
96
|
);
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
return
|
|
99
|
+
return (
|
|
100
|
+
<ComposedComponent
|
|
101
|
+
innerRef={this.elementRef}
|
|
102
|
+
{...rest}
|
|
103
|
+
{...this.state}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
94
106
|
}
|
|
95
107
|
};
|
|
96
108
|
}
|
package/lib/utils.js
CHANGED
|
@@ -102,6 +102,35 @@ export function cloneLayout(layout: Layout): Layout {
|
|
|
102
102
|
return newLayout;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// Modify a layoutItem inside a layout. Returns a new Layout,
|
|
106
|
+
// does not mutate. Carries over all other LayoutItems unmodified.
|
|
107
|
+
export function modifyLayout(layout: Layout, layoutItem: LayoutItem): Layout {
|
|
108
|
+
const newLayout = Array(layout.length);
|
|
109
|
+
for (let i = 0, len = layout.length; i < len; i++) {
|
|
110
|
+
if (layoutItem.i === layout[i].i) {
|
|
111
|
+
newLayout[i] = layoutItem;
|
|
112
|
+
} else {
|
|
113
|
+
newLayout[i] = layout[i];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return newLayout;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Function to be called to modify a layout item.
|
|
120
|
+
// Does defensive clones to ensure the layout is not modified.
|
|
121
|
+
export function withLayoutItem(
|
|
122
|
+
layout: Layout,
|
|
123
|
+
itemKey: string,
|
|
124
|
+
cb: LayoutItem => LayoutItem
|
|
125
|
+
): [Layout, ?LayoutItem] {
|
|
126
|
+
let item = getLayoutItem(layout, itemKey);
|
|
127
|
+
if (!item) return [layout, null];
|
|
128
|
+
item = cb(cloneLayoutItem(item)); // defensive clone then modify
|
|
129
|
+
// FIXME could do this faster if we already knew the index
|
|
130
|
+
layout = modifyLayout(layout, item);
|
|
131
|
+
return [layout, item];
|
|
132
|
+
}
|
|
133
|
+
|
|
105
134
|
// Fast path to cloning, since this is monomorphic
|
|
106
135
|
export function cloneLayoutItem(layoutItem: LayoutItem): LayoutItem {
|
|
107
136
|
return {
|
|
@@ -299,6 +328,11 @@ export function compactItem(
|
|
|
299
328
|
l.y++;
|
|
300
329
|
}
|
|
301
330
|
}
|
|
331
|
+
|
|
332
|
+
// Ensure that there are no negative positions
|
|
333
|
+
l.y = Math.max(l.y, 0);
|
|
334
|
+
l.x = Math.max(l.x, 0);
|
|
335
|
+
|
|
302
336
|
return l;
|
|
303
337
|
}
|
|
304
338
|
|
|
@@ -667,9 +701,11 @@ export function synchronizeLayoutWithChildren(
|
|
|
667
701
|
if (!isProduction) {
|
|
668
702
|
validateLayout([g], "ReactGridLayout.children");
|
|
669
703
|
}
|
|
704
|
+
// FIXME clone not really necessary here
|
|
670
705
|
layout[i] = cloneLayoutItem({ ...g, i: child.key });
|
|
671
706
|
} else {
|
|
672
707
|
// Nothing provided: ensure this is added to the bottom
|
|
708
|
+
// FIXME clone not really necessary here
|
|
673
709
|
layout[i] = cloneLayoutItem({
|
|
674
710
|
w: 1,
|
|
675
711
|
h: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-grid-layout",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,53 +35,58 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/STRML/react-grid-layout",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"classnames": "2.
|
|
38
|
+
"classnames": "2.3.1",
|
|
39
39
|
"lodash.isequal": "^4.0.0",
|
|
40
40
|
"prop-types": "^15.0.0",
|
|
41
41
|
"react-draggable": "^4.0.0",
|
|
42
|
-
"react-resizable": "^
|
|
42
|
+
"react-resizable": "^3.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.13.
|
|
46
|
-
"@babel/core": "^7.
|
|
45
|
+
"@babel/cli": "^7.13.16",
|
|
46
|
+
"@babel/core": "^7.14.0",
|
|
47
47
|
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
|
48
48
|
"@babel/plugin-transform-flow-comments": "^7.12.13",
|
|
49
|
-
"@babel/preset-env": "^7.
|
|
50
|
-
"@babel/preset-flow": "^7.
|
|
51
|
-
"@babel/preset-react": "^7.
|
|
52
|
-
"@babel/register": "^7.13.
|
|
49
|
+
"@babel/preset-env": "^7.14.1",
|
|
50
|
+
"@babel/preset-flow": "^7.13.13",
|
|
51
|
+
"@babel/preset-react": "^7.13.13",
|
|
52
|
+
"@babel/register": "^7.13.16",
|
|
53
|
+
"@webpack-cli/serve": "^1.4.0",
|
|
53
54
|
"babel-eslint": "^10.1.0",
|
|
54
55
|
"babel-jest": "^26.6.3",
|
|
55
56
|
"babel-loader": "^8.2.2",
|
|
56
57
|
"babel-plugin-preval": "^5.0.0",
|
|
57
|
-
"css-loader": "^5.
|
|
58
|
+
"css-loader": "^5.2.4",
|
|
58
59
|
"ejs": "^3.1.6",
|
|
59
60
|
"enzyme": "^3.11.0",
|
|
60
61
|
"enzyme-adapter-react-16": "^1.15.6",
|
|
61
|
-
"enzyme-to-json": "^3.6.
|
|
62
|
-
"eslint": "^7.
|
|
63
|
-
"eslint-plugin-flowtype": "^5.
|
|
64
|
-
"eslint-plugin-mocha": "^8.
|
|
65
|
-
"eslint-plugin-react": "^7.
|
|
62
|
+
"enzyme-to-json": "^3.6.2",
|
|
63
|
+
"eslint": "^7.26.0",
|
|
64
|
+
"eslint-plugin-flowtype": "^5.7.2",
|
|
65
|
+
"eslint-plugin-mocha": "^8.1.0",
|
|
66
|
+
"eslint-plugin-react": "^7.23.2",
|
|
66
67
|
"exports-loader": "^2.0.0",
|
|
67
|
-
"flow-bin": "^0.
|
|
68
|
-
"husky": "^
|
|
68
|
+
"flow-bin": "^0.150.1",
|
|
69
|
+
"husky": "^6.0.0",
|
|
69
70
|
"imports-loader": "^2.0.0",
|
|
70
71
|
"jest": "^26.6.3",
|
|
71
|
-
"lint-staged": "^
|
|
72
|
+
"lint-staged": "^11.0.0",
|
|
72
73
|
"lodash": "^4.17.21",
|
|
73
74
|
"opener": "^1.5.2",
|
|
74
|
-
"prettier": "^2.
|
|
75
|
+
"prettier": "^2.3.0",
|
|
75
76
|
"react": "^16.13.1",
|
|
76
77
|
"react-dom": "^16.13.1",
|
|
77
78
|
"react-hot-loader": "^4.13.0",
|
|
78
79
|
"react-transform-hmr": "^1.0.2",
|
|
79
80
|
"style-loader": "^2.0.0",
|
|
80
81
|
"timsort": "^0.3.0",
|
|
81
|
-
"webpack": "^5.
|
|
82
|
-
"webpack-cli": "^4.
|
|
82
|
+
"webpack": "^5.36.2",
|
|
83
|
+
"webpack-cli": "^4.7.0",
|
|
83
84
|
"webpack-dev-server": "^3.11.2"
|
|
84
85
|
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": ">= 16.3.0",
|
|
88
|
+
"react-dom": ">= 16.3.0"
|
|
89
|
+
},
|
|
85
90
|
"publishConfig": {
|
|
86
91
|
"registry": "https://registry.npmjs.org"
|
|
87
92
|
},
|
package/.husky/pre-commit
DELETED