react-grid-layout 1.4.2 → 1.4.4
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/CHANGELOG.md +15 -0
- package/README.md +4 -2
- package/build/GridItem.js +11 -6
- package/build/ReactGridLayout.js +25 -13
- package/build/ReactGridLayoutPropTypes.js +5 -8
- package/build/ResponsiveReactGridLayout.js +2 -2
- package/build/components/WidthProvider.js +2 -2
- package/build/utils.js +14 -15
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/lib/GridItem.jsx +19 -6
- package/lib/ReactGridLayout.jsx +20 -4
- package/lib/utils.js +2 -2
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.4 (Nov 28, 2023)
|
|
4
|
+
|
|
5
|
+
### Bugfixes
|
|
6
|
+
|
|
7
|
+
- Fix position logic when draggable item is dragged into the grid. We no longer use the deprecated / non-standard `e.nativeEvent.layer{X,Y}` properties. [#1915](https://github.com/react-grid-layout/react-grid-layout/pull/1915)
|
|
8
|
+
- Fix drag values according to containerPadding. Previously, when dragging an item, the intuited position within the grid was *not* modified by `containerPadding`, causing it to off by that value. On most grids, this is only set to `[10, 10]`, so this may not have been noticeable, but for higher values it was very obvious. Thanks @hywlss9. [#1323](https://github.com/react-grid-layout/react-grid-layout/pull/1323)
|
|
9
|
+
- Various lint/dependency fixes.
|
|
10
|
+
|
|
11
|
+
## 1.4.3 (Nov 8, 2023)
|
|
12
|
+
|
|
13
|
+
### Bugfixes
|
|
14
|
+
|
|
15
|
+
- Set `activeDrag` in `onDragStart`. Fixes issues where, if no drag is performed, the `onDragStop` handler would error out and the drag would freeze. [#1923](https://github.com/react-grid-layout/react-grid-layout/pull/1923)
|
|
16
|
+
- THis fixes some broader issues with React 18 but testing library support is still not complete.
|
|
17
|
+
|
|
3
18
|
## 1.4.2 (Sep 22, 2023)
|
|
4
19
|
|
|
5
20
|
### Bugfixes
|
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ RGL is React-only and does not require jQuery.
|
|
|
58
58
|
1. [Scaled Containers](https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html)
|
|
59
59
|
1. [Allow Overlap](https://react-grid-layout.github.io/react-grid-layout/examples/19-allow-overlap.html)
|
|
60
60
|
1. [All Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/20-resizable-handles.html)
|
|
61
|
+
1. [Single Row Horizontal](https://react-grid-layout.github.io/react-grid-layout/examples/21-horizontal.html)
|
|
61
62
|
|
|
62
63
|
#### Projects Using React-Grid-Layout
|
|
63
64
|
|
|
@@ -78,6 +79,7 @@ RGL is React-only and does not require jQuery.
|
|
|
78
79
|
- [Ubidots](https://help.ubidots.com/en/articles/2400308-create-dashboards-and-widgets)
|
|
79
80
|
- [Statsout](https://statsout.com/)
|
|
80
81
|
- [Datto RMM](https://www.datto.com/uk/products/rmm/)
|
|
82
|
+
- [SquaredUp](https://squaredup.com/)
|
|
81
83
|
|
|
82
84
|
_Know of others? Create a PR to let me know!_
|
|
83
85
|
|
|
@@ -108,7 +110,7 @@ _Know of others? Create a PR to let me know!_
|
|
|
108
110
|
|
|
109
111
|
## Installation
|
|
110
112
|
|
|
111
|
-
Install the React-Grid-Layout [package](https://www.npmjs.org/package/react-grid-layout)
|
|
113
|
+
Install the React-Grid-Layout [package](https://www.npmjs.org/package/react-grid-layout) using [npm](https://www.npmjs.com/):
|
|
112
114
|
|
|
113
115
|
```bash
|
|
114
116
|
npm install react-grid-layout
|
|
@@ -297,7 +299,7 @@ draggableCancel: ?string = '',
|
|
|
297
299
|
draggableHandle: ?string = '',
|
|
298
300
|
|
|
299
301
|
// Compaction type.
|
|
300
|
-
compactType: ?('vertical' | 'horizontal') = 'vertical';
|
|
302
|
+
compactType: ?('vertical' | 'horizontal' | null) = 'vertical';
|
|
301
303
|
|
|
302
304
|
// Layout is an array of object with the format:
|
|
303
305
|
// {x: number, y: number, w: number, h: number}
|
package/build/GridItem.js
CHANGED
|
@@ -199,13 +199,14 @@ class GridItem extends _react.default.Component /*:: <Props, State>*/{
|
|
|
199
199
|
if (offsetParent) {
|
|
200
200
|
const {
|
|
201
201
|
margin,
|
|
202
|
-
rowHeight
|
|
202
|
+
rowHeight,
|
|
203
|
+
containerPadding
|
|
203
204
|
} = this.props;
|
|
204
205
|
const bottomBoundary = offsetParent.clientHeight - (0, _calculateUtils.calcGridItemWHPx)(h, rowHeight, margin[1]);
|
|
205
|
-
top = (0, _calculateUtils.clamp)(top, 0, bottomBoundary);
|
|
206
|
+
top = (0, _calculateUtils.clamp)(top - containerPadding[1], 0, bottomBoundary);
|
|
206
207
|
const colWidth = (0, _calculateUtils.calcGridColWidth)(positionParams);
|
|
207
208
|
const rightBoundary = containerWidth - (0, _calculateUtils.calcGridItemWHPx)(w, colWidth, margin[0]);
|
|
208
|
-
left = (0, _calculateUtils.clamp)(left, 0, rightBoundary);
|
|
209
|
+
left = (0, _calculateUtils.clamp)(left - containerPadding[0], 0, rightBoundary);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
const newPosition /*: PartialPosition*/ = {
|
|
@@ -217,10 +218,13 @@ class GridItem extends _react.default.Component /*:: <Props, State>*/{
|
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
// Call callback with this data
|
|
221
|
+
const {
|
|
222
|
+
containerPadding
|
|
223
|
+
} = this.props;
|
|
220
224
|
const {
|
|
221
225
|
x,
|
|
222
226
|
y
|
|
223
|
-
} = (0, _calculateUtils.calcXY)(positionParams, top, left, w, h);
|
|
227
|
+
} = (0, _calculateUtils.calcXY)(positionParams, top - containerPadding[1], left - containerPadding[0], w, h);
|
|
224
228
|
return onDrag.call(this, i, x, y, {
|
|
225
229
|
e,
|
|
226
230
|
node,
|
|
@@ -246,7 +250,8 @@ class GridItem extends _react.default.Component /*:: <Props, State>*/{
|
|
|
246
250
|
const {
|
|
247
251
|
w,
|
|
248
252
|
h,
|
|
249
|
-
i
|
|
253
|
+
i,
|
|
254
|
+
containerPadding
|
|
250
255
|
} = this.props;
|
|
251
256
|
const {
|
|
252
257
|
left,
|
|
@@ -262,7 +267,7 @@ class GridItem extends _react.default.Component /*:: <Props, State>*/{
|
|
|
262
267
|
const {
|
|
263
268
|
x,
|
|
264
269
|
y
|
|
265
|
-
} = (0, _calculateUtils.calcXY)(this.getPositionParams(), top, left, w, h);
|
|
270
|
+
} = (0, _calculateUtils.calcXY)(this.getPositionParams(), top - containerPadding[1], left - containerPadding[0], w, h);
|
|
266
271
|
return onDragStop.call(this, i, x, y, {
|
|
267
272
|
e,
|
|
268
273
|
node,
|
package/build/ReactGridLayout.js
CHANGED
|
@@ -12,8 +12,8 @@ var _calculateUtils = require("./calculateUtils");
|
|
|
12
12
|
var _GridItem = _interopRequireDefault(require("./GridItem"));
|
|
13
13
|
var _ReactGridLayoutPropTypes = _interopRequireDefault(require("./ReactGridLayoutPropTypes"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function _getRequireWildcardCache(
|
|
16
|
-
function _interopRequireWildcard(
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
18
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
19
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
@@ -97,9 +97,20 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
97
97
|
} = this.state;
|
|
98
98
|
const l = (0, _utils.getLayoutItem)(layout, i);
|
|
99
99
|
if (!l) return;
|
|
100
|
+
|
|
101
|
+
// Create placeholder (display only)
|
|
102
|
+
const placeholder = {
|
|
103
|
+
w: l.w,
|
|
104
|
+
h: l.h,
|
|
105
|
+
x: l.x,
|
|
106
|
+
y: l.y,
|
|
107
|
+
placeholder: true,
|
|
108
|
+
i: i
|
|
109
|
+
};
|
|
100
110
|
this.setState({
|
|
101
111
|
oldDragItem: (0, _utils.cloneLayoutItem)(l),
|
|
102
|
-
oldLayout: layout
|
|
112
|
+
oldLayout: layout,
|
|
113
|
+
activeDrag: placeholder
|
|
103
114
|
});
|
|
104
115
|
return this.props.onDragStart(layout, l, l, null, e, node);
|
|
105
116
|
});
|
|
@@ -222,7 +233,7 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
222
233
|
const {
|
|
223
234
|
oldResizeItem
|
|
224
235
|
} = this.state;
|
|
225
|
-
|
|
236
|
+
const {
|
|
226
237
|
layout
|
|
227
238
|
} = this.state;
|
|
228
239
|
const {
|
|
@@ -338,7 +349,6 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
338
349
|
// Called while dragging an element. Part of browser native drag/drop API.
|
|
339
350
|
// Native event target might be the layout itself, or an element within the layout.
|
|
340
351
|
_defineProperty(this, "onDragOver", e => {
|
|
341
|
-
var _e$nativeEvent$target;
|
|
342
352
|
e.preventDefault(); // Prevent any browser native action
|
|
343
353
|
e.stopPropagation();
|
|
344
354
|
|
|
@@ -347,7 +357,7 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
347
357
|
// FIXME remove this hack
|
|
348
358
|
if (isFirefox &&
|
|
349
359
|
// $FlowIgnore can't figure this out
|
|
350
|
-
!
|
|
360
|
+
!e.nativeEvent.target?.classList.contains(layoutClassName)) {
|
|
351
361
|
return false;
|
|
352
362
|
}
|
|
353
363
|
const {
|
|
@@ -363,7 +373,7 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
363
373
|
} = this.props;
|
|
364
374
|
// Allow user to customize the dropping item or short-circuit the drop based on the results
|
|
365
375
|
// of the `onDragOver(e: Event)` callback.
|
|
366
|
-
const onDragOverResult = onDropDragOver
|
|
376
|
+
const onDragOverResult = onDropDragOver?.(e);
|
|
367
377
|
if (onDragOverResult === false) {
|
|
368
378
|
if (this.state.droppingDOMNode) {
|
|
369
379
|
this.removeDroppingPlaceholder();
|
|
@@ -377,11 +387,13 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
377
387
|
const {
|
|
378
388
|
layout
|
|
379
389
|
} = this.state;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
390
|
+
|
|
391
|
+
// $FlowIgnore missing def
|
|
392
|
+
const gridRect = e.currentTarget.getBoundingClientRect(); // The grid's position in the viewport
|
|
393
|
+
|
|
394
|
+
// Calculate the mouse position relative to the grid
|
|
395
|
+
const layerX = e.clientX - gridRect.left;
|
|
396
|
+
const layerY = e.clientY - gridRect.top;
|
|
385
397
|
const droppingPosition = {
|
|
386
398
|
left: layerX / transformScale,
|
|
387
399
|
top: layerY / transformScale,
|
|
@@ -573,7 +585,7 @@ class ReactGridLayout extends React.Component /*:: <Props, State>*/{
|
|
|
573
585
|
x: activeDrag.x,
|
|
574
586
|
y: activeDrag.y,
|
|
575
587
|
i: activeDrag.i,
|
|
576
|
-
className:
|
|
588
|
+
className: `react-grid-placeholder ${this.state.resizing ? "placeholder-resizing" : ""}`,
|
|
577
589
|
containerWidth: width,
|
|
578
590
|
cols: cols,
|
|
579
591
|
margin: margin,
|
|
@@ -40,10 +40,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
40
40
|
// 'nw' - Northwest handle (top-left)
|
|
41
41
|
// 'se' - Southeast handle (bottom-right)
|
|
42
42
|
// 'ne' - Northeast handle (top-right)
|
|
43
|
-
const resizeHandleAxesType /*: ReactPropsChainableTypeChecker*/ = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"]));
|
|
43
|
+
const resizeHandleAxesType /*: ReactPropsChainableTypeChecker*/ = exports.resizeHandleAxesType = _propTypes.default.arrayOf(_propTypes.default.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"]));
|
|
44
44
|
// Custom component for resize handles
|
|
45
|
-
exports.
|
|
46
|
-
const resizeHandleType /*: ReactPropsChainableTypeChecker*/ = _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
|
|
45
|
+
const resizeHandleType /*: ReactPropsChainableTypeChecker*/ = exports.resizeHandleType = _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]);
|
|
47
46
|
/*:: export type Props = {|
|
|
48
47
|
className: string,
|
|
49
48
|
style: Object,
|
|
@@ -91,8 +90,7 @@ const resizeHandleType /*: ReactPropsChainableTypeChecker*/ = _propTypes.default
|
|
|
91
90
|
width: number
|
|
92
91
|
}
|
|
93
92
|
>;*/
|
|
94
|
-
exports.
|
|
95
|
-
var _default = {
|
|
93
|
+
var _default = exports.default = {
|
|
96
94
|
//
|
|
97
95
|
// Basic props
|
|
98
96
|
//
|
|
@@ -200,7 +198,7 @@ var _default = {
|
|
|
200
198
|
// Check children keys for duplicates. Throw if found.
|
|
201
199
|
const keys = {};
|
|
202
200
|
_react.default.Children.forEach(children, function (child) {
|
|
203
|
-
if (
|
|
201
|
+
if (child?.key == null) return;
|
|
204
202
|
if (keys[child.key]) {
|
|
205
203
|
throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
|
|
206
204
|
}
|
|
@@ -209,5 +207,4 @@ var _default = {
|
|
|
209
207
|
},
|
|
210
208
|
// Optional ref for getting a reference for the wrapping div.
|
|
211
209
|
innerRef: _propTypes.default.any
|
|
212
|
-
};
|
|
213
|
-
exports.default = _default;
|
|
210
|
+
};
|
|
@@ -11,8 +11,8 @@ var _utils = require("./utils");
|
|
|
11
11
|
var _responsiveUtils = require("./responsiveUtils");
|
|
12
12
|
var _ReactGridLayout = _interopRequireDefault(require("./ReactGridLayout"));
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
function _interopRequireWildcard(
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
17
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
18
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
@@ -9,8 +9,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
|
|
10
10
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
function _getRequireWildcardCache(
|
|
13
|
-
function _interopRequireWildcard(
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
15
15
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
package/build/utils.js
CHANGED
|
@@ -196,7 +196,7 @@ function cloneLayoutItem(layoutItem /*: LayoutItem*/) /*: LayoutItem*/{
|
|
|
196
196
|
* This will catch differences in keys, order, and length.
|
|
197
197
|
*/
|
|
198
198
|
function childrenEqual(a /*: ReactChildren*/, b /*: ReactChildren*/) /*: boolean*/{
|
|
199
|
-
return (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c
|
|
199
|
+
return (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c?.key), _react.default.Children.map(b, c => c?.key)) && (0, _fastEquals.deepEqual)(_react.default.Children.map(a, c => c?.props["data-grid"]), _react.default.Children.map(b, c => c?.props["data-grid"]));
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -208,10 +208,9 @@ function childrenEqual(a /*: ReactChildren*/, b /*: ReactChildren*/) /*: boolean
|
|
|
208
208
|
* function, tuned for exactly our props.
|
|
209
209
|
*/
|
|
210
210
|
/*:: type FastRGLPropsEqual = (Object, Object, Function) => boolean;*/
|
|
211
|
-
const fastRGLPropsEqual /*: FastRGLPropsEqual*/ = require("./fastRGLPropsEqual");
|
|
211
|
+
const fastRGLPropsEqual /*: FastRGLPropsEqual*/ = exports.fastRGLPropsEqual = require("./fastRGLPropsEqual");
|
|
212
212
|
|
|
213
213
|
// Like the above, but a lot simpler.
|
|
214
|
-
exports.fastRGLPropsEqual = fastRGLPropsEqual;
|
|
215
214
|
function fastPositionEqual(a /*: Position*/, b /*: Position*/) /*: boolean*/{
|
|
216
215
|
return a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height;
|
|
217
216
|
}
|
|
@@ -434,7 +433,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
434
433
|
|
|
435
434
|
// Short-circuit if nothing to do.
|
|
436
435
|
if (l.y === y && l.x === x) return layout;
|
|
437
|
-
log(
|
|
436
|
+
log(`Moving element ${l.i} to [${String(x)},${String(y)}] from [${l.x},${l.y}]`);
|
|
438
437
|
const oldX = l.x;
|
|
439
438
|
const oldY = l.y;
|
|
440
439
|
|
|
@@ -464,7 +463,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
464
463
|
// If we are preventing collision but not allowing overlap, we need to
|
|
465
464
|
// revert the position of this element so it goes to where it came from, rather
|
|
466
465
|
// than the user's desired location.
|
|
467
|
-
log(
|
|
466
|
+
log(`Collision prevented on ${l.i}, reverting.`);
|
|
468
467
|
l.x = oldX;
|
|
469
468
|
l.y = oldY;
|
|
470
469
|
l.moved = false;
|
|
@@ -474,7 +473,7 @@ function moveElement(layout /*: Layout*/, l /*: LayoutItem*/, x /*: ?number*/, y
|
|
|
474
473
|
// Move each item that collides away from this element.
|
|
475
474
|
for (let i = 0, len = collisions.length; i < len; i++) {
|
|
476
475
|
const collision = collisions[i];
|
|
477
|
-
log(
|
|
476
|
+
log(`Resolving collision between ${l.i} at [${l.x},${l.y}] and ${collision.i} at [${collision.x},${collision.y}]`);
|
|
478
477
|
|
|
479
478
|
// Short circuit so we can't infinite loop
|
|
480
479
|
if (collision.moved) continue;
|
|
@@ -524,7 +523,7 @@ function moveElementAwayFromCollision(layout /*: Layout*/, collidesWith /*: Layo
|
|
|
524
523
|
|
|
525
524
|
// No collision? If so, we can go up there; otherwise, we'll end up moving down as normal
|
|
526
525
|
if (!firstCollision) {
|
|
527
|
-
log(
|
|
526
|
+
log(`Doing reverse collision on ${itemToMove.i} up to [${fakeItem.x},${fakeItem.y}].`);
|
|
528
527
|
return moveElement(layout, itemToMove, compactH ? fakeItem.x : undefined, compactV ? fakeItem.y : undefined, isUserAction, preventCollision, compactType, cols);
|
|
529
528
|
} else if (collisionNorth && compactV) {
|
|
530
529
|
return moveElement(layout, itemToMove, undefined, collidesWith.y + 1, isUserAction, preventCollision, compactType, cols);
|
|
@@ -664,15 +663,15 @@ function setTransform(_ref5 /*:: */) /*: Object*/{
|
|
|
664
663
|
height
|
|
665
664
|
} /*: Position*/ = _ref5 /*: Position*/;
|
|
666
665
|
// Replace unitless items with px
|
|
667
|
-
const translate =
|
|
666
|
+
const translate = `translate(${left}px,${top}px)`;
|
|
668
667
|
return {
|
|
669
668
|
transform: translate,
|
|
670
669
|
WebkitTransform: translate,
|
|
671
670
|
MozTransform: translate,
|
|
672
671
|
msTransform: translate,
|
|
673
672
|
OTransform: translate,
|
|
674
|
-
width:
|
|
675
|
-
height:
|
|
673
|
+
width: `${width}px`,
|
|
674
|
+
height: `${height}px`,
|
|
676
675
|
position: "absolute"
|
|
677
676
|
};
|
|
678
677
|
}
|
|
@@ -684,10 +683,10 @@ function setTopLeft(_ref6 /*:: */) /*: Object*/{
|
|
|
684
683
|
height
|
|
685
684
|
} /*: Position*/ = _ref6 /*: Position*/;
|
|
686
685
|
return {
|
|
687
|
-
top:
|
|
688
|
-
left:
|
|
689
|
-
width:
|
|
690
|
-
height:
|
|
686
|
+
top: `${top}px`,
|
|
687
|
+
left: `${left}px`,
|
|
688
|
+
width: `${width}px`,
|
|
689
|
+
height: `${height}px`,
|
|
691
690
|
position: "absolute"
|
|
692
691
|
};
|
|
693
692
|
}
|
|
@@ -753,7 +752,7 @@ function synchronizeLayoutWithChildren(initialLayout /*: Layout*/, children /*:
|
|
|
753
752
|
const layout /*: LayoutItem[]*/ = [];
|
|
754
753
|
_react.default.Children.forEach(children, (child /*: ReactElement<any>*/) => {
|
|
755
754
|
// Child may not exist
|
|
756
|
-
if (
|
|
755
|
+
if (child?.key == null) return;
|
|
757
756
|
const exists = getLayoutItem(initialLayout, String(child.key));
|
|
758
757
|
const g = child.props["data-grid"];
|
|
759
758
|
// Don't overwrite the layout item if it's already in the initial layout.
|