react-grid-layout 0.16.2 → 0.16.6
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 +33 -0
- package/README.md +4 -1
- package/build/GridItem.js +1 -1
- package/build/GridItem.js.flow +1 -1
- package/build/ReactGridLayout.js +31 -10
- package/build/ReactGridLayout.js.flow +33 -12
- package/build/components/WidthProvider.js +12 -6
- package/build/components/WidthProvider.js.flow +14 -12
- package/build/utils.js +25 -29
- package/build/utils.js.flow +22 -25
- package/interfaces/classnames.js +8 -8
- package/package.json +20 -20
package/.flowconfig
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
0.16.6 (Mar 8, 2018)
|
|
4
|
+
----
|
|
5
|
+
|
|
6
|
+
- Fixed collision issue where items below could rearrange on a move.
|
|
7
|
+
- The root cause was "teleportation", or practically the same bug that leads to Pac-Man going through
|
|
8
|
+
ghosts now and then. If a large element moves up by a few grid units, the space it vacates can suddenly
|
|
9
|
+
become occupiable by an element below it. Rather than the collision happening properly, they exchange spaces
|
|
10
|
+
atomically. The fix is to move items down one grid unit at a time to ensure
|
|
11
|
+
this rearrangement does not happen.
|
|
12
|
+
- Thanks @torkelo for your hard work on this for Grafana 5, which I very unfortunately managed to break
|
|
13
|
+
when refactoring for 0.16.1.
|
|
14
|
+
- Ref: #650, #739
|
|
15
|
+
- Added a "Toolbox" demo (thanks @jhob)
|
|
16
|
+
|
|
17
|
+
0.16.5 (Feb 26, 2018)
|
|
18
|
+
----
|
|
19
|
+
|
|
20
|
+
- Minor fix to `isUserAction` on certain types of compaction cascades (#714, #720, #729)
|
|
21
|
+
|
|
22
|
+
0.16.4 (Feb 15, 2018)
|
|
23
|
+
----
|
|
24
|
+
|
|
25
|
+
- Skip null items in processGridItem (#578)
|
|
26
|
+
- Resize is broken for grids with preventCollision: true, fixes #655 (#656)
|
|
27
|
+
- Minor refactoring
|
|
28
|
+
|
|
29
|
+
0.16.3 (Jan 31, 2018)
|
|
30
|
+
----
|
|
31
|
+
|
|
32
|
+
- Fix overriding of `onStart` behaviour (#707, thanks @ersel)
|
|
33
|
+
- Fixed Flow type of WidthProvider
|
|
34
|
+
- Devdep updates
|
|
35
|
+
|
|
3
36
|
0.16.2 (Dec 17, 2017)
|
|
4
37
|
----
|
|
5
38
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# React-Grid-Layout
|
|
2
2
|
|
|
3
3
|
[](https://travis-ci.org/STRML/react-grid-layout)
|
|
4
|
+
[](https://cdnjs.com/libraries/react-grid-layout)
|
|
4
5
|
[](https://www.npmjs.org/package/react-grid-layout)
|
|
5
6
|
[]()
|
|
6
7
|
|
|
@@ -46,16 +47,18 @@ RGL is React-only and does not require jQuery.
|
|
|
46
47
|
1. [Dynamic Minimum and Maximum Width/Height](https://strml.github.io/react-grid-layout/examples/10-dynamic-min-max-wh.html)
|
|
47
48
|
1. [No Vertical Compacting (Free Movement)](https://strml.github.io/react-grid-layout/examples/11-no-vertical-compact.html)
|
|
48
49
|
|
|
49
|
-
#### Projects
|
|
50
|
+
#### Projects Using React-Grid-Layout
|
|
50
51
|
|
|
51
52
|
- [BitMEX](https://www.bitmex.com/)
|
|
52
53
|
- [AWS CloudFront Dashboards](https://aws.amazon.com/blogs/aws/cloudwatch-dashboards-create-use-customized-metrics-views/)
|
|
54
|
+
- [Grafana](https://grafana.com/)
|
|
53
55
|
- [Metabase](http://www.metabase.com/)
|
|
54
56
|
- [HubSpot](http://www.hubspot.com)
|
|
55
57
|
- [ComNetViz](http://www.grotto-networking.com/ComNetViz/ComNetViz.html)
|
|
56
58
|
- [Stoplight](https://app.stoplight.io)
|
|
57
59
|
- [Reflect](https://reflect.io)
|
|
58
60
|
- [ez-Dashing](https://github.com/ylacaute/ez-Dashing)
|
|
61
|
+
- [Kibana](https://www.elastic.co/products/kibana)
|
|
59
62
|
|
|
60
63
|
*Know of others? Create a PR to let me know!*
|
|
61
64
|
|
package/build/GridItem.js
CHANGED
|
@@ -331,7 +331,7 @@ var GridItem = function (_React$Component) {
|
|
|
331
331
|
x = _calcXY.x,
|
|
332
332
|
y = _calcXY.y;
|
|
333
333
|
|
|
334
|
-
handler.call(_this2, _this2.props.i, x, y, { e: e, node: node, newPosition: newPosition });
|
|
334
|
+
return handler.call(_this2, _this2.props.i, x, y, { e: e, node: node, newPosition: newPosition });
|
|
335
335
|
};
|
|
336
336
|
};
|
|
337
337
|
|
package/build/GridItem.js.flow
CHANGED
|
@@ -415,7 +415,7 @@ export default class GridItem extends React.Component<Props, State> {
|
|
|
415
415
|
|
|
416
416
|
const { x, y } = this.calcXY(newPosition.top, newPosition.left);
|
|
417
417
|
|
|
418
|
-
handler.call(this, this.props.i, x, y, { e, node, newPosition });
|
|
418
|
+
return handler.call(this, this.props.i, x, y, { e, node, newPosition });
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
421
|
|
package/build/ReactGridLayout.js
CHANGED
|
@@ -126,7 +126,7 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
126
126
|
oldLayout: this.state.layout
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
this.props.onDragStart(layout, l, l, null, e, node);
|
|
129
|
+
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
/**
|
|
@@ -249,19 +249,40 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
249
249
|
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
250
250
|
if (!l) return;
|
|
251
251
|
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
// Something like quad tree should be used
|
|
253
|
+
// to find collisions faster
|
|
254
|
+
var hasCollisions = void 0;
|
|
255
|
+
if (preventCollision) {
|
|
256
|
+
var collisions = (0, _utils.getAllCollisions)(layout, _extends({}, l, { w: w, h: h })).filter(function (layoutItem) {
|
|
257
|
+
return layoutItem.i !== l.i;
|
|
258
|
+
});
|
|
259
|
+
hasCollisions = collisions.length > 0;
|
|
260
|
+
|
|
261
|
+
// If we're colliding, we need adjust the placeholder.
|
|
262
|
+
if (hasCollisions) {
|
|
263
|
+
// adjust w && h to maximum allowed space
|
|
264
|
+
var leastX = Infinity,
|
|
265
|
+
leastY = Infinity;
|
|
266
|
+
collisions.forEach(function (layoutItem) {
|
|
267
|
+
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
268
|
+
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
272
|
+
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
273
|
+
}
|
|
255
274
|
}
|
|
256
275
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
276
|
+
if (!hasCollisions) {
|
|
277
|
+
// Set new width and height.
|
|
278
|
+
l.w = w;
|
|
279
|
+
l.h = h;
|
|
280
|
+
}
|
|
260
281
|
|
|
261
282
|
// Create placeholder element (display only)
|
|
262
283
|
var placeholder = {
|
|
263
|
-
w: w,
|
|
264
|
-
h: h,
|
|
284
|
+
w: l.w,
|
|
285
|
+
h: l.h,
|
|
265
286
|
x: l.x,
|
|
266
287
|
y: l.y,
|
|
267
288
|
static: true,
|
|
@@ -355,7 +376,7 @@ var ReactGridLayout = function (_React$Component) {
|
|
|
355
376
|
|
|
356
377
|
|
|
357
378
|
ReactGridLayout.prototype.processGridItem = function processGridItem(child) {
|
|
358
|
-
if (!child.key) return;
|
|
379
|
+
if (!child || !child.key) return;
|
|
359
380
|
var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
|
|
360
381
|
if (!l) return null;
|
|
361
382
|
var _props4 = this.props,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
moveElement,
|
|
14
14
|
synchronizeLayoutWithChildren,
|
|
15
15
|
validateLayout,
|
|
16
|
-
|
|
16
|
+
getAllCollisions,
|
|
17
17
|
noop
|
|
18
18
|
} from "./utils";
|
|
19
19
|
import GridItem from "./GridItem";
|
|
@@ -331,7 +331,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
331
331
|
oldLayout: this.state.layout
|
|
332
332
|
});
|
|
333
333
|
|
|
334
|
-
this.props.onDragStart(layout, l, l, null, e, node);
|
|
334
|
+
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
/**
|
|
@@ -446,22 +446,43 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
446
446
|
onResize(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
|
|
447
447
|
const { layout, oldResizeItem } = this.state;
|
|
448
448
|
const { cols, preventCollision } = this.props;
|
|
449
|
-
|
|
449
|
+
const l: ?LayoutItem = getLayoutItem(layout, i);
|
|
450
450
|
if (!l) return;
|
|
451
451
|
|
|
452
|
-
//
|
|
453
|
-
|
|
454
|
-
|
|
452
|
+
// Something like quad tree should be used
|
|
453
|
+
// to find collisions faster
|
|
454
|
+
let hasCollisions;
|
|
455
|
+
if (preventCollision) {
|
|
456
|
+
const collisions = getAllCollisions(layout, { ...l, w, h }).filter(
|
|
457
|
+
layoutItem => layoutItem.i !== l.i
|
|
458
|
+
);
|
|
459
|
+
hasCollisions = collisions.length > 0;
|
|
460
|
+
|
|
461
|
+
// If we're colliding, we need adjust the placeholder.
|
|
462
|
+
if (hasCollisions) {
|
|
463
|
+
// adjust w && h to maximum allowed space
|
|
464
|
+
let leastX = Infinity,
|
|
465
|
+
leastY = Infinity;
|
|
466
|
+
collisions.forEach(layoutItem => {
|
|
467
|
+
if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
|
|
468
|
+
if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
if (Number.isFinite(leastX)) l.w = leastX - l.x;
|
|
472
|
+
if (Number.isFinite(leastY)) l.h = leastY - l.y;
|
|
473
|
+
}
|
|
455
474
|
}
|
|
456
475
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
476
|
+
if (!hasCollisions) {
|
|
477
|
+
// Set new width and height.
|
|
478
|
+
l.w = w;
|
|
479
|
+
l.h = h;
|
|
480
|
+
}
|
|
460
481
|
|
|
461
482
|
// Create placeholder element (display only)
|
|
462
483
|
var placeholder = {
|
|
463
|
-
w: w,
|
|
464
|
-
h: h,
|
|
484
|
+
w: l.w,
|
|
485
|
+
h: l.h,
|
|
465
486
|
x: l.x,
|
|
466
487
|
y: l.y,
|
|
467
488
|
static: true,
|
|
@@ -544,7 +565,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
|
|
|
544
565
|
* @return {Element} Element wrapped in draggable and properly placed.
|
|
545
566
|
*/
|
|
546
567
|
processGridItem(child: ReactElement<any>): ?ReactElement<any> {
|
|
547
|
-
if (!child.key) return;
|
|
568
|
+
if (!child || !child.key) return;
|
|
548
569
|
const l = getLayoutItem(this.state.layout, String(child.key));
|
|
549
570
|
if (!l) return null;
|
|
550
571
|
const {
|
|
@@ -4,6 +4,8 @@ exports.__esModule = true;
|
|
|
4
4
|
|
|
5
5
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
6
6
|
|
|
7
|
+
exports.default = WidthProvider;
|
|
8
|
+
|
|
7
9
|
var _react = require("react");
|
|
8
10
|
|
|
9
11
|
var _react2 = _interopRequireDefault(_react);
|
|
@@ -18,6 +20,8 @@ var _reactDom2 = _interopRequireDefault(_reactDom);
|
|
|
18
20
|
|
|
19
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
22
|
|
|
23
|
+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
24
|
+
|
|
21
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
26
|
|
|
23
27
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
@@ -27,7 +31,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
27
31
|
/*
|
|
28
32
|
* A simple HOC that provides facility for listening to container resizes.
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
function WidthProvider(ComposedComponent) {
|
|
31
35
|
var _class, _temp2;
|
|
32
36
|
|
|
33
37
|
return _temp2 = _class = function (_React$Component) {
|
|
@@ -68,11 +72,15 @@ var WidthProvider = function WidthProvider(ComposedComponent) {
|
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
WidthProvider.prototype.render = function render() {
|
|
71
|
-
|
|
75
|
+
var _props = this.props,
|
|
76
|
+
measureBeforeMount = _props.measureBeforeMount,
|
|
77
|
+
rest = _objectWithoutProperties(_props, ["measureBeforeMount"]);
|
|
78
|
+
|
|
79
|
+
if (measureBeforeMount && !this.mounted) {
|
|
72
80
|
return _react2.default.createElement("div", { className: this.props.className, style: this.props.style });
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
return _react2.default.createElement(ComposedComponent, _extends({},
|
|
83
|
+
return _react2.default.createElement(ComposedComponent, _extends({}, rest, this.state));
|
|
76
84
|
};
|
|
77
85
|
|
|
78
86
|
return WidthProvider;
|
|
@@ -83,6 +91,4 @@ var WidthProvider = function WidthProvider(ComposedComponent) {
|
|
|
83
91
|
// rendering, to prevent any unsightly resizing.
|
|
84
92
|
measureBeforeMount: _propTypes2.default.bool
|
|
85
93
|
}, _temp2;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
exports.default = WidthProvider;
|
|
94
|
+
}
|
|
@@ -4,24 +4,26 @@ import PropTypes from "prop-types";
|
|
|
4
4
|
import ReactDOM from "react-dom";
|
|
5
5
|
import type { ComponentType as ReactComponentType } from "react";
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type WPProps = {
|
|
8
8
|
className?: string,
|
|
9
9
|
measureBeforeMount: boolean,
|
|
10
10
|
style?: Object
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
type
|
|
13
|
+
type WPState = {
|
|
14
14
|
width: number
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
/*
|
|
18
18
|
* A simple HOC that provides facility for listening to container resizes.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
export default function WidthProvider<
|
|
21
|
+
Props,
|
|
22
|
+
ComposedProps: { ...Props, ...WPProps }
|
|
23
|
+
>(
|
|
24
|
+
ComposedComponent: ReactComponentType<Props>
|
|
25
|
+
): ReactComponentType<ComposedProps> {
|
|
26
|
+
return class WidthProvider extends React.Component<ComposedProps, WPState> {
|
|
25
27
|
static defaultProps = {
|
|
26
28
|
measureBeforeMount: false
|
|
27
29
|
};
|
|
@@ -32,7 +34,7 @@ const WidthProvider: ProviderT = ComposedComponent =>
|
|
|
32
34
|
measureBeforeMount: PropTypes.bool
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
state
|
|
37
|
+
state = {
|
|
36
38
|
width: 1280
|
|
37
39
|
};
|
|
38
40
|
|
|
@@ -62,14 +64,14 @@ const WidthProvider: ProviderT = ComposedComponent =>
|
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
render() {
|
|
65
|
-
|
|
67
|
+
const { measureBeforeMount, ...rest } = this.props;
|
|
68
|
+
if (measureBeforeMount && !this.mounted) {
|
|
66
69
|
return (
|
|
67
70
|
<div className={this.props.className} style={this.props.style} />
|
|
68
71
|
);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
return <ComposedComponent {...
|
|
74
|
+
return <ComposedComponent {...rest} {...this.state} />;
|
|
72
75
|
}
|
|
73
76
|
};
|
|
74
|
-
|
|
75
|
-
export default WidthProvider;
|
|
77
|
+
}
|
package/build/utils.js
CHANGED
|
@@ -162,10 +162,13 @@ function resolveCompactionCollision(layout, item, moveToCoord, axis) {
|
|
|
162
162
|
// Go through each item we collide with.
|
|
163
163
|
for (var _i4 = itemIndex + 1; _i4 < layout.length; _i4++) {
|
|
164
164
|
var otherItem = layout[_i4];
|
|
165
|
-
|
|
166
165
|
// Ignore static items
|
|
167
166
|
if (otherItem.static) continue;
|
|
168
167
|
|
|
168
|
+
// Optimization: we can break early if we know we're past this el
|
|
169
|
+
// We can do this b/c it's a sorted layout
|
|
170
|
+
if (otherItem.y > item.y + item.h) break;
|
|
171
|
+
|
|
169
172
|
if (collides(item, otherItem)) {
|
|
170
173
|
resolveCompactionCollision(layout, otherItem, moveToCoord + item[sizeProp], axis);
|
|
171
174
|
}
|
|
@@ -296,17 +299,17 @@ function getStatics(layout) {
|
|
|
296
299
|
*/
|
|
297
300
|
function moveElement(layout, l, x, y, isUserAction, preventCollision, compactType, cols) {
|
|
298
301
|
if (l.static) return layout;
|
|
299
|
-
log("Moving element " + l.i + " to [" + x + "," + y + "] from [" + l.x + "," + l.y + "]");
|
|
300
302
|
|
|
301
303
|
// Short-circuit if nothing to do.
|
|
302
304
|
if (l.y === y && l.x === x) return layout;
|
|
303
305
|
|
|
306
|
+
log("Moving element " + l.i + " to [" + String(x) + "," + String(y) + "] from [" + l.x + "," + l.y + "]");
|
|
304
307
|
var oldX = l.x;
|
|
305
308
|
var oldY = l.y;
|
|
306
309
|
|
|
307
310
|
// This is quite a bit faster than extending the object
|
|
308
|
-
l.x = x;
|
|
309
|
-
l.y = y;
|
|
311
|
+
if (typeof x === 'number') l.x = x;
|
|
312
|
+
if (typeof y === 'number') l.y = y;
|
|
310
313
|
l.moved = true;
|
|
311
314
|
|
|
312
315
|
// If this collides with anything, move it.
|
|
@@ -314,7 +317,7 @@ function moveElement(layout, l, x, y, isUserAction, preventCollision, compactTyp
|
|
|
314
317
|
// to ensure, in the case of multiple collisions, that we're getting the
|
|
315
318
|
// nearest collision.
|
|
316
319
|
var sorted = sortLayoutItems(layout, compactType);
|
|
317
|
-
var movingUp = compactType === "vertical" ? oldY >= y : compactType === "horizontal" ? oldX >= x : false;
|
|
320
|
+
var movingUp = compactType === "vertical" && typeof y === 'number' ? oldY >= y : compactType === "horizontal" && typeof x === 'number' ? oldX >= x : false;
|
|
318
321
|
if (movingUp) sorted = sorted.reverse();
|
|
319
322
|
var collisions = getAllCollisions(sorted, l);
|
|
320
323
|
|
|
@@ -363,33 +366,26 @@ function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAc
|
|
|
363
366
|
// We only do this on the main collision as this can get funky in cascades and cause
|
|
364
367
|
// unwanted swapping behavior.
|
|
365
368
|
if (isUserAction) {
|
|
369
|
+
// Reset isUserAction flag because we're not in the main collision anymore.
|
|
370
|
+
isUserAction = false;
|
|
371
|
+
|
|
366
372
|
// Make a mock item so we don't modify the item here, only modify in moveElement.
|
|
367
373
|
var fakeItem = {
|
|
368
374
|
x: compactH ? Math.max(collidesWith.x - itemToMove.w, 0) : itemToMove.x,
|
|
369
|
-
y:
|
|
375
|
+
y: compactV ? Math.max(collidesWith.y - itemToMove.h, 0) : itemToMove.y,
|
|
370
376
|
w: itemToMove.w,
|
|
371
377
|
h: itemToMove.h,
|
|
372
378
|
i: "-1"
|
|
373
379
|
};
|
|
374
380
|
|
|
375
|
-
// This makes it feel a bit more precise by waiting to swap for just a bit when moving up.
|
|
376
|
-
|
|
377
|
-
var _ref = compactType === "horizontal" ? ["x", "w"] : ["y", "h"],
|
|
378
|
-
axis = _ref[0],
|
|
379
|
-
dimension = _ref[1];
|
|
380
|
-
|
|
381
|
-
var shouldSkip = false &&
|
|
382
|
-
// Our collision is below the item to move, and only encroaches by 25% of its dimension; ignore
|
|
383
|
-
collidesWith[axis] > itemToMove[axis] && collidesWith[axis] - itemToMove[axis] > itemToMove[dimension] / 4;
|
|
384
|
-
|
|
385
381
|
// No collision? If so, we can go up there; otherwise, we'll end up moving down as normal
|
|
386
|
-
if (!
|
|
382
|
+
if (!getFirstCollision(layout, fakeItem)) {
|
|
387
383
|
log("Doing reverse collision on " + itemToMove.i + " up to [" + fakeItem.x + "," + fakeItem.y + "].");
|
|
388
|
-
return moveElement(layout, itemToMove, fakeItem.x, fakeItem.y, isUserAction, preventCollision, compactType, cols);
|
|
384
|
+
return moveElement(layout, itemToMove, compactH ? fakeItem.x : undefined, compactV ? fakeItem.y : undefined, isUserAction, preventCollision, compactType, cols);
|
|
389
385
|
}
|
|
390
386
|
}
|
|
391
387
|
|
|
392
|
-
return moveElement(layout, itemToMove, compactH ?
|
|
388
|
+
return moveElement(layout, itemToMove, compactH ? itemToMove.x + 1 : undefined, compactV ? itemToMove.y + 1 : undefined, isUserAction, preventCollision, compactType, cols);
|
|
393
389
|
}
|
|
394
390
|
|
|
395
391
|
/**
|
|
@@ -402,11 +398,11 @@ function perc(num) {
|
|
|
402
398
|
return num * 100 + "%";
|
|
403
399
|
}
|
|
404
400
|
|
|
405
|
-
function setTransform(
|
|
406
|
-
var top =
|
|
407
|
-
left =
|
|
408
|
-
width =
|
|
409
|
-
height =
|
|
401
|
+
function setTransform(_ref) {
|
|
402
|
+
var top = _ref.top,
|
|
403
|
+
left = _ref.left,
|
|
404
|
+
width = _ref.width,
|
|
405
|
+
height = _ref.height;
|
|
410
406
|
|
|
411
407
|
// Replace unitless items with px
|
|
412
408
|
var translate = "translate(" + left + "px," + top + "px)";
|
|
@@ -422,11 +418,11 @@ function setTransform(_ref2) {
|
|
|
422
418
|
};
|
|
423
419
|
}
|
|
424
420
|
|
|
425
|
-
function setTopLeft(
|
|
426
|
-
var top =
|
|
427
|
-
left =
|
|
428
|
-
width =
|
|
429
|
-
height =
|
|
421
|
+
function setTopLeft(_ref2) {
|
|
422
|
+
var top = _ref2.top,
|
|
423
|
+
left = _ref2.left,
|
|
424
|
+
width = _ref2.width,
|
|
425
|
+
height = _ref2.height;
|
|
430
426
|
|
|
431
427
|
return {
|
|
432
428
|
top: top + "px",
|
package/build/utils.js.flow
CHANGED
|
@@ -190,10 +190,13 @@ function resolveCompactionCollision(
|
|
|
190
190
|
// Go through each item we collide with.
|
|
191
191
|
for (let i = itemIndex + 1; i < layout.length; i++) {
|
|
192
192
|
const otherItem = layout[i];
|
|
193
|
-
|
|
194
193
|
// Ignore static items
|
|
195
194
|
if (otherItem.static) continue;
|
|
196
195
|
|
|
196
|
+
// Optimization: we can break early if we know we're past this el
|
|
197
|
+
// We can do this b/c it's a sorted layout
|
|
198
|
+
if (otherItem.y > (item.y + item.h)) break;
|
|
199
|
+
|
|
197
200
|
if (collides(item, otherItem)) {
|
|
198
201
|
resolveCompactionCollision(
|
|
199
202
|
layout,
|
|
@@ -342,25 +345,25 @@ export function getStatics(layout: Layout): Array<LayoutItem> {
|
|
|
342
345
|
export function moveElement(
|
|
343
346
|
layout: Layout,
|
|
344
347
|
l: LayoutItem,
|
|
345
|
-
x: number,
|
|
346
|
-
y: number,
|
|
348
|
+
x: ?number,
|
|
349
|
+
y: ?number,
|
|
347
350
|
isUserAction: ?boolean,
|
|
348
351
|
preventCollision: ?boolean,
|
|
349
352
|
compactType: CompactType,
|
|
350
|
-
cols: number
|
|
353
|
+
cols: number,
|
|
351
354
|
): Layout {
|
|
352
355
|
if (l.static) return layout;
|
|
353
|
-
log(`Moving element ${l.i} to [${x},${y}] from [${l.x},${l.y}]`);
|
|
354
356
|
|
|
355
357
|
// Short-circuit if nothing to do.
|
|
356
358
|
if (l.y === y && l.x === x) return layout;
|
|
357
359
|
|
|
360
|
+
log(`Moving element ${l.i} to [${String(x)},${String(y)}] from [${l.x},${l.y}]`);
|
|
358
361
|
const oldX = l.x;
|
|
359
362
|
const oldY = l.y;
|
|
360
363
|
|
|
361
364
|
// This is quite a bit faster than extending the object
|
|
362
|
-
l.x = x;
|
|
363
|
-
l.y = y;
|
|
365
|
+
if (typeof x === 'number') l.x = x;
|
|
366
|
+
if (typeof y === 'number') l.y = y;
|
|
364
367
|
l.moved = true;
|
|
365
368
|
|
|
366
369
|
// If this collides with anything, move it.
|
|
@@ -369,9 +372,9 @@ export function moveElement(
|
|
|
369
372
|
// nearest collision.
|
|
370
373
|
let sorted = sortLayoutItems(layout, compactType);
|
|
371
374
|
const movingUp =
|
|
372
|
-
compactType === "vertical"
|
|
373
|
-
|
|
374
|
-
|
|
375
|
+
compactType === "vertical" && typeof y === 'number' ? oldY >= y
|
|
376
|
+
: compactType === "horizontal" && typeof x === 'number' ? oldX >= x
|
|
377
|
+
: false;
|
|
375
378
|
if (movingUp) sorted = sorted.reverse();
|
|
376
379
|
const collisions = getAllCollisions(sorted, l);
|
|
377
380
|
|
|
@@ -445,26 +448,20 @@ export function moveElementAwayFromCollision(
|
|
|
445
448
|
// We only do this on the main collision as this can get funky in cascades and cause
|
|
446
449
|
// unwanted swapping behavior.
|
|
447
450
|
if (isUserAction) {
|
|
451
|
+
// Reset isUserAction flag because we're not in the main collision anymore.
|
|
452
|
+
isUserAction = false;
|
|
453
|
+
|
|
448
454
|
// Make a mock item so we don't modify the item here, only modify in moveElement.
|
|
449
455
|
const fakeItem: LayoutItem = {
|
|
450
456
|
x: compactH ? Math.max(collidesWith.x - itemToMove.w, 0) : itemToMove.x,
|
|
451
|
-
y:
|
|
457
|
+
y: compactV ? Math.max(collidesWith.y - itemToMove.h, 0) : itemToMove.y,
|
|
452
458
|
w: itemToMove.w,
|
|
453
459
|
h: itemToMove.h,
|
|
454
460
|
i: "-1"
|
|
455
461
|
};
|
|
456
462
|
|
|
457
|
-
// This makes it feel a bit more precise by waiting to swap for just a bit when moving up.
|
|
458
|
-
const [axis, dimension] =
|
|
459
|
-
compactType === "horizontal" ? ["x", "w"] : ["y", "h"];
|
|
460
|
-
const shouldSkip =
|
|
461
|
-
false &&
|
|
462
|
-
// Our collision is below the item to move, and only encroaches by 25% of its dimension; ignore
|
|
463
|
-
(collidesWith[axis] > itemToMove[axis] &&
|
|
464
|
-
collidesWith[axis] - itemToMove[axis] > itemToMove[dimension] / 4);
|
|
465
|
-
|
|
466
463
|
// No collision? If so, we can go up there; otherwise, we'll end up moving down as normal
|
|
467
|
-
if (!
|
|
464
|
+
if (!getFirstCollision(layout, fakeItem)) {
|
|
468
465
|
log(
|
|
469
466
|
`Doing reverse collision on ${itemToMove.i} up to [${fakeItem.x},${
|
|
470
467
|
fakeItem.y
|
|
@@ -473,8 +470,8 @@ export function moveElementAwayFromCollision(
|
|
|
473
470
|
return moveElement(
|
|
474
471
|
layout,
|
|
475
472
|
itemToMove,
|
|
476
|
-
fakeItem.x,
|
|
477
|
-
fakeItem.y,
|
|
473
|
+
compactH ? fakeItem.x : undefined,
|
|
474
|
+
compactV ? fakeItem.y : undefined,
|
|
478
475
|
isUserAction,
|
|
479
476
|
preventCollision,
|
|
480
477
|
compactType,
|
|
@@ -486,8 +483,8 @@ export function moveElementAwayFromCollision(
|
|
|
486
483
|
return moveElement(
|
|
487
484
|
layout,
|
|
488
485
|
itemToMove,
|
|
489
|
-
compactH ?
|
|
490
|
-
compactV ?
|
|
486
|
+
compactH ? itemToMove.x + 1 : undefined,
|
|
487
|
+
compactV ? itemToMove.y + 1 : undefined,
|
|
491
488
|
isUserAction,
|
|
492
489
|
preventCollision,
|
|
493
490
|
compactType,
|
package/interfaces/classnames.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// flow-typed version: 94e9f7e0a4/classnames_v2.x.x/flow_>=v0.28.x
|
|
3
3
|
|
|
4
4
|
type $npm$classnames$Classes =
|
|
5
|
-
string
|
|
6
|
-
{[className: string]: ?boolean }
|
|
7
|
-
Array<string>
|
|
8
|
-
void
|
|
9
|
-
null
|
|
5
|
+
| string
|
|
6
|
+
| { [className: string]: ?boolean }
|
|
7
|
+
| Array<string>
|
|
8
|
+
| void
|
|
9
|
+
| null;
|
|
10
10
|
|
|
11
|
-
declare module
|
|
12
|
-
declare
|
|
11
|
+
declare module "classnames" {
|
|
12
|
+
declare module.exports: (
|
|
13
13
|
...classes: Array<$npm$classnames$Classes>
|
|
14
|
-
)
|
|
14
|
+
) => string;
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-grid-layout",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.6",
|
|
4
4
|
"description": "A draggable and resizable grid layout with responsive breakpoints, for React.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"classnames": "2.x",
|
|
40
40
|
"lodash.isequal": "^4.0.0",
|
|
41
41
|
"prop-types": "15.x",
|
|
42
|
-
"react-draggable": "
|
|
43
|
-
"react-resizable": "
|
|
42
|
+
"react-draggable": "3.x",
|
|
43
|
+
"react-resizable": "1.x"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"babel-cli": "^6.24.1",
|
|
47
47
|
"babel-core": "^6.24.1",
|
|
48
|
-
"babel-eslint": "^8.
|
|
49
|
-
"babel-jest": "^
|
|
48
|
+
"babel-eslint": "^8.2.1",
|
|
49
|
+
"babel-jest": "^22.2.2",
|
|
50
50
|
"babel-loader": "^7.1.2",
|
|
51
|
-
"babel-plugin-espower": "^2.
|
|
51
|
+
"babel-plugin-espower": "^2.4.0",
|
|
52
52
|
"babel-plugin-react-transform": "^3.0.0",
|
|
53
53
|
"babel-plugin-transform-react-constant-elements": "^6.5.0",
|
|
54
54
|
"babel-plugin-transform-react-inline-elements": "^6.6.5",
|
|
@@ -56,30 +56,30 @@
|
|
|
56
56
|
"babel-preset-es2015": "^6.24.1",
|
|
57
57
|
"babel-preset-react": "^6.24.1",
|
|
58
58
|
"babel-preset-stage-1": "^6.24.1",
|
|
59
|
-
"css-loader": "^0.28.
|
|
59
|
+
"css-loader": "^0.28.9",
|
|
60
60
|
"ejs": "^2.4.1",
|
|
61
|
-
"eslint": "^4.
|
|
62
|
-
"eslint-plugin-flowtype": "^2.
|
|
61
|
+
"eslint": "^4.17.0",
|
|
62
|
+
"eslint-plugin-flowtype": "^2.44.0",
|
|
63
63
|
"eslint-plugin-mocha": "^4.11.0",
|
|
64
|
-
"eslint-plugin-react": "^7.
|
|
65
|
-
"exports-loader": "^0.
|
|
66
|
-
"flow-bin": "^0.
|
|
64
|
+
"eslint-plugin-react": "^7.6.1",
|
|
65
|
+
"exports-loader": "^0.7.0",
|
|
66
|
+
"flow-bin": "^0.65.0",
|
|
67
67
|
"husky": "^0.14.3",
|
|
68
68
|
"imports-loader": "^0.7.1",
|
|
69
|
-
"jest-cli": "^
|
|
70
|
-
"lint-staged": "^6.
|
|
71
|
-
"lodash": "^4.
|
|
69
|
+
"jest-cli": "^22.3.0",
|
|
70
|
+
"lint-staged": "^6.1.0",
|
|
71
|
+
"lodash": "^4.17.5",
|
|
72
72
|
"opener": "^1.4.3",
|
|
73
73
|
"power-assert": "^1.4.4",
|
|
74
|
-
"prettier": "^1.
|
|
74
|
+
"prettier": "^1.10.2",
|
|
75
75
|
"react": "^16.2.0",
|
|
76
76
|
"react-dom": "^16.2.0",
|
|
77
|
-
"react-hot-loader": "^1.3
|
|
77
|
+
"react-hot-loader": "^3.1.3",
|
|
78
78
|
"react-transform-hmr": "^1.0.2",
|
|
79
|
-
"style-loader": "^0.
|
|
79
|
+
"style-loader": "^0.20.2",
|
|
80
80
|
"valiquire": "^0.3.0",
|
|
81
|
-
"webpack": "^3.
|
|
82
|
-
"webpack-dev-server": "^2.
|
|
81
|
+
"webpack": "^3.11.0",
|
|
82
|
+
"webpack-dev-server": "^2.11.1"
|
|
83
83
|
},
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"registry": "https://registry.npmjs.org"
|