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/ReactGridLayout.js
CHANGED
|
@@ -7,23 +7,25 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
10
|
var _lodash = _interopRequireDefault(require("lodash.isequal"));
|
|
13
11
|
|
|
14
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
13
|
|
|
16
14
|
var _utils = require("./utils");
|
|
17
15
|
|
|
16
|
+
var _calculateUtils = require("./calculateUtils");
|
|
17
|
+
|
|
18
18
|
var _GridItem = _interopRequireDefault(require("./GridItem"));
|
|
19
19
|
|
|
20
|
+
var _ReactGridLayoutPropTypes = _interopRequireDefault(require("./ReactGridLayoutPropTypes"));
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
24
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
23
25
|
|
|
24
26
|
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; }
|
|
25
27
|
|
|
26
|
-
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; }
|
|
28
|
+
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; }
|
|
27
29
|
|
|
28
30
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
29
31
|
|
|
@@ -52,23 +54,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
52
54
|
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; }
|
|
53
55
|
|
|
54
56
|
// End Types
|
|
55
|
-
var compactType = function compactType(props
|
|
56
|
-
/*: Props*/
|
|
57
|
-
)
|
|
58
|
-
/*: CompactType*/
|
|
59
|
-
{
|
|
60
|
-
var _ref = props || {},
|
|
61
|
-
verticalCompact = _ref.verticalCompact,
|
|
62
|
-
compactType = _ref.compactType;
|
|
63
|
-
|
|
64
|
-
return verticalCompact === false ? null : compactType;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
57
|
var layoutClassName = "react-grid-layout";
|
|
68
58
|
var isFirefox = false; // Try...catch will protect from navigator not existing (e.g. node) or a bad implementation of navigator
|
|
69
59
|
|
|
70
60
|
try {
|
|
71
|
-
isFirefox = navigator.userAgent
|
|
61
|
+
isFirefox = /firefox/i.test(navigator.userAgent);
|
|
72
62
|
} catch (e) {}
|
|
73
63
|
/* Ignore */
|
|
74
64
|
|
|
@@ -83,6 +73,7 @@ function (_React$Component) {
|
|
|
83
73
|
_inherits(ReactGridLayout, _React$Component);
|
|
84
74
|
|
|
85
75
|
// TODO publish internal ReactClass displayName transform
|
|
76
|
+
// Refactored to another module to make way for preval
|
|
86
77
|
function ReactGridLayout(props
|
|
87
78
|
/*: Props*/
|
|
88
79
|
, context
|
|
@@ -99,7 +90,7 @@ function (_React$Component) {
|
|
|
99
90
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
100
91
|
activeDrag: null,
|
|
101
92
|
layout: (0, _utils.synchronizeLayoutWithChildren)(_this.props.layout, _this.props.children, _this.props.cols, // Legacy support for verticalCompact: false
|
|
102
|
-
compactType(_this.props)),
|
|
93
|
+
(0, _utils.compactType)(_this.props)),
|
|
103
94
|
mounted: false,
|
|
104
95
|
oldDragItem: null,
|
|
105
96
|
oldLayout: null,
|
|
@@ -115,39 +106,66 @@ function (_React$Component) {
|
|
|
115
106
|
) {
|
|
116
107
|
// we should ignore events from layout's children in Firefox
|
|
117
108
|
// to avoid unpredictable jumping of a dropping placeholder
|
|
118
|
-
|
|
109
|
+
// FIXME remove this hack
|
|
110
|
+
if (isFirefox && e.nativeEvent.target.className.indexOf(layoutClassName) === -1) {
|
|
119
111
|
return false;
|
|
120
112
|
}
|
|
121
113
|
|
|
122
|
-
var
|
|
123
|
-
|
|
114
|
+
var _this$props = _this.props,
|
|
115
|
+
droppingItem = _this$props.droppingItem,
|
|
116
|
+
margin = _this$props.margin,
|
|
117
|
+
cols = _this$props.cols,
|
|
118
|
+
rowHeight = _this$props.rowHeight,
|
|
119
|
+
maxRows = _this$props.maxRows,
|
|
120
|
+
width = _this$props.width,
|
|
121
|
+
containerPadding = _this$props.containerPadding;
|
|
122
|
+
var layout = _this.state.layout; // This is relative to the DOM element that this event fired for.
|
|
123
|
+
|
|
124
124
|
var _e$nativeEvent = e.nativeEvent,
|
|
125
125
|
layerX = _e$nativeEvent.layerX,
|
|
126
126
|
layerY = _e$nativeEvent.layerY;
|
|
127
127
|
var droppingPosition = {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
left: layerX,
|
|
129
|
+
top: layerY,
|
|
130
130
|
e: e
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
if (!_this.state.droppingDOMNode) {
|
|
134
|
+
var positionParams
|
|
135
|
+
/*: PositionParams*/
|
|
136
|
+
= {
|
|
137
|
+
cols: cols,
|
|
138
|
+
margin: margin,
|
|
139
|
+
maxRows: maxRows,
|
|
140
|
+
rowHeight: rowHeight,
|
|
141
|
+
containerWidth: width,
|
|
142
|
+
containerPadding: containerPadding || margin
|
|
143
|
+
};
|
|
144
|
+
var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, droppingItem.w, droppingItem.h);
|
|
145
|
+
|
|
134
146
|
_this.setState({
|
|
135
147
|
droppingDOMNode: _react.default.createElement("div", {
|
|
136
148
|
key: droppingItem.i
|
|
137
149
|
}),
|
|
138
150
|
droppingPosition: droppingPosition,
|
|
139
151
|
layout: [].concat(_toConsumableArray(layout), [_objectSpread({}, droppingItem, {
|
|
140
|
-
x:
|
|
141
|
-
y:
|
|
152
|
+
x: calculatedPosition.x,
|
|
153
|
+
y: calculatedPosition.y,
|
|
142
154
|
static: false,
|
|
143
155
|
isDraggable: true
|
|
144
156
|
})])
|
|
145
157
|
});
|
|
146
158
|
} else if (_this.state.droppingPosition) {
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
var _this$state$droppingP = _this.state.droppingPosition,
|
|
160
|
+
left = _this$state$droppingP.left,
|
|
161
|
+
top = _this$state$droppingP.top;
|
|
162
|
+
var shouldUpdatePosition = left != layerX || top != layerY;
|
|
163
|
+
|
|
164
|
+
if (shouldUpdatePosition) {
|
|
165
|
+
_this.setState({
|
|
166
|
+
droppingPosition: droppingPosition
|
|
167
|
+
});
|
|
168
|
+
}
|
|
151
169
|
}
|
|
152
170
|
|
|
153
171
|
e.stopPropagation();
|
|
@@ -155,13 +173,13 @@ function (_React$Component) {
|
|
|
155
173
|
});
|
|
156
174
|
|
|
157
175
|
_defineProperty(_assertThisInitialized(_this), "removeDroppingPlaceholder", function () {
|
|
158
|
-
var _this$
|
|
159
|
-
droppingItem = _this$
|
|
160
|
-
cols = _this$
|
|
176
|
+
var _this$props2 = _this.props,
|
|
177
|
+
droppingItem = _this$props2.droppingItem,
|
|
178
|
+
cols = _this$props2.cols;
|
|
161
179
|
var layout = _this.state.layout;
|
|
162
180
|
var newLayout = (0, _utils.compact)(layout.filter(function (l) {
|
|
163
181
|
return l.i !== droppingItem.i;
|
|
164
|
-
}), compactType(_this.props), cols);
|
|
182
|
+
}), (0, _utils.compactType)(_this.props), cols);
|
|
165
183
|
|
|
166
184
|
_this.setState({
|
|
167
185
|
layout: newLayout,
|
|
@@ -187,17 +205,19 @@ function (_React$Component) {
|
|
|
187
205
|
_this.dragEnterCounter++;
|
|
188
206
|
});
|
|
189
207
|
|
|
190
|
-
_defineProperty(_assertThisInitialized(_this), "onDrop", function (
|
|
208
|
+
_defineProperty(_assertThisInitialized(_this), "onDrop", function (e
|
|
209
|
+
/*: Event*/
|
|
210
|
+
) {
|
|
191
211
|
var droppingItem = _this.props.droppingItem;
|
|
192
212
|
var layout = _this.state.layout;
|
|
193
213
|
|
|
194
|
-
var
|
|
214
|
+
var _ref = layout.find(function (l) {
|
|
195
215
|
return l.i === droppingItem.i;
|
|
196
216
|
}) || {},
|
|
197
|
-
x =
|
|
198
|
-
y =
|
|
199
|
-
w =
|
|
200
|
-
h =
|
|
217
|
+
x = _ref.x,
|
|
218
|
+
y = _ref.y,
|
|
219
|
+
w = _ref.w,
|
|
220
|
+
h = _ref.h; // reset gragEnter counter on drop
|
|
201
221
|
|
|
202
222
|
|
|
203
223
|
_this.dragEnterCounter = 0;
|
|
@@ -208,7 +228,8 @@ function (_React$Component) {
|
|
|
208
228
|
x: x,
|
|
209
229
|
y: y,
|
|
210
230
|
w: w,
|
|
211
|
-
h: h
|
|
231
|
+
h: h,
|
|
232
|
+
e: e
|
|
212
233
|
});
|
|
213
234
|
});
|
|
214
235
|
|
|
@@ -226,6 +247,19 @@ function (_React$Component) {
|
|
|
226
247
|
|
|
227
248
|
this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
|
|
228
249
|
}
|
|
250
|
+
}, {
|
|
251
|
+
key: "shouldComponentUpdate",
|
|
252
|
+
value: function shouldComponentUpdate(nextProps
|
|
253
|
+
/*: Props*/
|
|
254
|
+
, nextState
|
|
255
|
+
/*: State*/
|
|
256
|
+
) {
|
|
257
|
+
return (// NOTE: this is almost always unequal. Therefore the only way to get better performance
|
|
258
|
+
// from SCU is if the user intentionally memoizes children. If they do, and they can
|
|
259
|
+
// handle changes properly, performance will increase.
|
|
260
|
+
this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _lodash.default) || this.state.activeDrag !== nextState.activeDrag || this.state.droppingPosition !== nextState.droppingPosition
|
|
261
|
+
);
|
|
262
|
+
}
|
|
229
263
|
}, {
|
|
230
264
|
key: "componentDidUpdate",
|
|
231
265
|
value: function componentDidUpdate(prevProps
|
|
@@ -269,9 +303,9 @@ function (_React$Component) {
|
|
|
269
303
|
/*: number*/
|
|
270
304
|
, y
|
|
271
305
|
/*: number*/
|
|
272
|
-
,
|
|
273
|
-
var e =
|
|
274
|
-
node =
|
|
306
|
+
, _ref2) {
|
|
307
|
+
var e = _ref2.e,
|
|
308
|
+
node = _ref2.node;
|
|
275
309
|
var layout = this.state.layout;
|
|
276
310
|
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
277
311
|
if (!l) return;
|
|
@@ -298,9 +332,9 @@ function (_React$Component) {
|
|
|
298
332
|
/*: number*/
|
|
299
333
|
, y
|
|
300
334
|
/*: number*/
|
|
301
|
-
,
|
|
302
|
-
var e =
|
|
303
|
-
node =
|
|
335
|
+
, _ref3) {
|
|
336
|
+
var e = _ref3.e,
|
|
337
|
+
node = _ref3.node;
|
|
304
338
|
var oldDragItem = this.state.oldDragItem;
|
|
305
339
|
var layout = this.state.layout;
|
|
306
340
|
var cols = this.props.cols;
|
|
@@ -317,10 +351,10 @@ function (_React$Component) {
|
|
|
317
351
|
}; // Move the element to the dragged location.
|
|
318
352
|
|
|
319
353
|
var isUserAction = true;
|
|
320
|
-
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, this.props.preventCollision, compactType(this.props), cols);
|
|
354
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, this.props.preventCollision, (0, _utils.compactType)(this.props), cols);
|
|
321
355
|
this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
|
|
322
356
|
this.setState({
|
|
323
|
-
layout: (0, _utils.compact)(layout, compactType(this.props), cols),
|
|
357
|
+
layout: (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
|
|
324
358
|
activeDrag: placeholder
|
|
325
359
|
});
|
|
326
360
|
}
|
|
@@ -341,26 +375,23 @@ function (_React$Component) {
|
|
|
341
375
|
/*: number*/
|
|
342
376
|
, y
|
|
343
377
|
/*: number*/
|
|
344
|
-
,
|
|
345
|
-
var e =
|
|
346
|
-
node =
|
|
378
|
+
, _ref4) {
|
|
379
|
+
var e = _ref4.e,
|
|
380
|
+
node = _ref4.node;
|
|
381
|
+
if (!this.state.activeDrag) return;
|
|
347
382
|
var oldDragItem = this.state.oldDragItem;
|
|
348
383
|
var layout = this.state.layout;
|
|
349
|
-
var _this$
|
|
350
|
-
cols = _this$
|
|
351
|
-
preventCollision = _this$
|
|
384
|
+
var _this$props3 = this.props,
|
|
385
|
+
cols = _this$props3.cols,
|
|
386
|
+
preventCollision = _this$props3.preventCollision;
|
|
352
387
|
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
353
388
|
if (!l) return; // Move the element here
|
|
354
389
|
|
|
355
390
|
var isUserAction = true;
|
|
356
|
-
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, compactType(this.props), cols);
|
|
391
|
+
layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols);
|
|
392
|
+
this.props.onDragStop(layout, oldDragItem, l, null, e, node); // Set state
|
|
357
393
|
|
|
358
|
-
|
|
359
|
-
this.props.onDragStop(layout, oldDragItem, l, null, e, node);
|
|
360
|
-
} // Set state
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
var newLayout = (0, _utils.compact)(layout, compactType(this.props), cols);
|
|
394
|
+
var newLayout = (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
|
|
364
395
|
var oldLayout = this.state.oldLayout;
|
|
365
396
|
this.setState({
|
|
366
397
|
activeDrag: null,
|
|
@@ -391,9 +422,9 @@ function (_React$Component) {
|
|
|
391
422
|
/*: number*/
|
|
392
423
|
, h
|
|
393
424
|
/*: number*/
|
|
394
|
-
,
|
|
395
|
-
var e =
|
|
396
|
-
node =
|
|
425
|
+
, _ref5) {
|
|
426
|
+
var e = _ref5.e,
|
|
427
|
+
node = _ref5.node;
|
|
397
428
|
var layout = this.state.layout;
|
|
398
429
|
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
399
430
|
if (!l) return;
|
|
@@ -411,15 +442,15 @@ function (_React$Component) {
|
|
|
411
442
|
/*: number*/
|
|
412
443
|
, h
|
|
413
444
|
/*: number*/
|
|
414
|
-
,
|
|
415
|
-
var e =
|
|
416
|
-
node =
|
|
445
|
+
, _ref6) {
|
|
446
|
+
var e = _ref6.e,
|
|
447
|
+
node = _ref6.node;
|
|
417
448
|
var _this$state = this.state,
|
|
418
449
|
layout = _this$state.layout,
|
|
419
450
|
oldResizeItem = _this$state.oldResizeItem;
|
|
420
|
-
var _this$
|
|
421
|
-
cols = _this$
|
|
422
|
-
preventCollision = _this$
|
|
451
|
+
var _this$props4 = this.props,
|
|
452
|
+
cols = _this$props4.cols,
|
|
453
|
+
preventCollision = _this$props4.preventCollision;
|
|
423
454
|
var l
|
|
424
455
|
/*: ?LayoutItem*/
|
|
425
456
|
= (0, _utils.getLayoutItem)(layout, i);
|
|
@@ -468,7 +499,7 @@ function (_React$Component) {
|
|
|
468
499
|
this.props.onResize(layout, oldResizeItem, l, placeholder, e, node); // Re-compact the layout and set the drag placeholder.
|
|
469
500
|
|
|
470
501
|
this.setState({
|
|
471
|
-
layout: (0, _utils.compact)(layout, compactType(this.props), cols),
|
|
502
|
+
layout: (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
|
|
472
503
|
activeDrag: placeholder
|
|
473
504
|
});
|
|
474
505
|
}
|
|
@@ -480,9 +511,9 @@ function (_React$Component) {
|
|
|
480
511
|
/*: number*/
|
|
481
512
|
, h
|
|
482
513
|
/*: number*/
|
|
483
|
-
,
|
|
484
|
-
var e =
|
|
485
|
-
node =
|
|
514
|
+
, _ref7) {
|
|
515
|
+
var e = _ref7.e,
|
|
516
|
+
node = _ref7.node;
|
|
486
517
|
var _this$state2 = this.state,
|
|
487
518
|
layout = _this$state2.layout,
|
|
488
519
|
oldResizeItem = _this$state2.oldResizeItem;
|
|
@@ -490,7 +521,7 @@ function (_React$Component) {
|
|
|
490
521
|
var l = (0, _utils.getLayoutItem)(layout, i);
|
|
491
522
|
this.props.onResizeStop(layout, oldResizeItem, l, null, e, node); // Set state
|
|
492
523
|
|
|
493
|
-
var newLayout = (0, _utils.compact)(layout, compactType(this.props), cols);
|
|
524
|
+
var newLayout = (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
|
|
494
525
|
var oldLayout = this.state.oldLayout;
|
|
495
526
|
this.setState({
|
|
496
527
|
activeDrag: null,
|
|
@@ -512,15 +543,15 @@ function (_React$Component) {
|
|
|
512
543
|
{
|
|
513
544
|
var activeDrag = this.state.activeDrag;
|
|
514
545
|
if (!activeDrag) return null;
|
|
515
|
-
var _this$
|
|
516
|
-
width = _this$
|
|
517
|
-
cols = _this$
|
|
518
|
-
margin = _this$
|
|
519
|
-
containerPadding = _this$
|
|
520
|
-
rowHeight = _this$
|
|
521
|
-
maxRows = _this$
|
|
522
|
-
useCSSTransforms = _this$
|
|
523
|
-
transformScale = _this$
|
|
546
|
+
var _this$props5 = this.props,
|
|
547
|
+
width = _this$props5.width,
|
|
548
|
+
cols = _this$props5.cols,
|
|
549
|
+
margin = _this$props5.margin,
|
|
550
|
+
containerPadding = _this$props5.containerPadding,
|
|
551
|
+
rowHeight = _this$props5.rowHeight,
|
|
552
|
+
maxRows = _this$props5.maxRows,
|
|
553
|
+
useCSSTransforms = _this$props5.useCSSTransforms,
|
|
554
|
+
transformScale = _this$props5.transformScale; // {...this.state.activeDrag} is pretty slow, actually
|
|
524
555
|
|
|
525
556
|
return _react.default.createElement(_GridItem.default, {
|
|
526
557
|
w: activeDrag.w,
|
|
@@ -559,25 +590,27 @@ function (_React$Component) {
|
|
|
559
590
|
if (!child || !child.key) return;
|
|
560
591
|
var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
|
|
561
592
|
if (!l) return null;
|
|
562
|
-
var _this$
|
|
563
|
-
width = _this$
|
|
564
|
-
cols = _this$
|
|
565
|
-
margin = _this$
|
|
566
|
-
containerPadding = _this$
|
|
567
|
-
rowHeight = _this$
|
|
568
|
-
maxRows = _this$
|
|
569
|
-
isDraggable = _this$
|
|
570
|
-
isResizable = _this$
|
|
571
|
-
useCSSTransforms = _this$
|
|
572
|
-
transformScale = _this$
|
|
573
|
-
draggableCancel = _this$
|
|
574
|
-
draggableHandle = _this$
|
|
593
|
+
var _this$props6 = this.props,
|
|
594
|
+
width = _this$props6.width,
|
|
595
|
+
cols = _this$props6.cols,
|
|
596
|
+
margin = _this$props6.margin,
|
|
597
|
+
containerPadding = _this$props6.containerPadding,
|
|
598
|
+
rowHeight = _this$props6.rowHeight,
|
|
599
|
+
maxRows = _this$props6.maxRows,
|
|
600
|
+
isDraggable = _this$props6.isDraggable,
|
|
601
|
+
isResizable = _this$props6.isResizable,
|
|
602
|
+
useCSSTransforms = _this$props6.useCSSTransforms,
|
|
603
|
+
transformScale = _this$props6.transformScale,
|
|
604
|
+
draggableCancel = _this$props6.draggableCancel,
|
|
605
|
+
draggableHandle = _this$props6.draggableHandle;
|
|
575
606
|
var _this$state3 = this.state,
|
|
576
607
|
mounted = _this$state3.mounted,
|
|
577
|
-
droppingPosition = _this$state3.droppingPosition; //
|
|
608
|
+
droppingPosition = _this$state3.droppingPosition; // Determine user manipulations possible.
|
|
609
|
+
// If an item is static, it can't be manipulated by default.
|
|
610
|
+
// Any properties defined directly on the grid item will take precedence.
|
|
578
611
|
|
|
579
|
-
var draggable =
|
|
580
|
-
var resizable =
|
|
612
|
+
var draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
|
|
613
|
+
var resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
|
|
581
614
|
return _react.default.createElement(_GridItem.default, {
|
|
582
615
|
containerWidth: width,
|
|
583
616
|
cols: cols,
|
|
@@ -610,16 +643,18 @@ function (_React$Component) {
|
|
|
610
643
|
static: l.static,
|
|
611
644
|
droppingPosition: isDroppingItem ? droppingPosition : undefined
|
|
612
645
|
}, child);
|
|
613
|
-
}
|
|
646
|
+
} // Called while dragging an element. Part of browser native drag/drop API.
|
|
647
|
+
// Native event target might be the layout itself, or an element within the layout.
|
|
648
|
+
|
|
614
649
|
}, {
|
|
615
650
|
key: "render",
|
|
616
651
|
value: function render() {
|
|
617
652
|
var _this2 = this;
|
|
618
653
|
|
|
619
|
-
var _this$
|
|
620
|
-
className = _this$
|
|
621
|
-
style = _this$
|
|
622
|
-
isDroppable = _this$
|
|
654
|
+
var _this$props7 = this.props,
|
|
655
|
+
className = _this$props7.className,
|
|
656
|
+
style = _this$props7.style,
|
|
657
|
+
isDroppable = _this$props7.isDroppable;
|
|
623
658
|
var mergedClassName = (0, _classnames.default)(layoutClassName, className);
|
|
624
659
|
|
|
625
660
|
var mergedStyle = _objectSpread({
|
|
@@ -663,7 +698,7 @@ function (_React$Component) {
|
|
|
663
698
|
|
|
664
699
|
|
|
665
700
|
if (newLayoutBase) {
|
|
666
|
-
var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, compactType(nextProps));
|
|
701
|
+
var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps));
|
|
667
702
|
return {
|
|
668
703
|
layout: newLayout,
|
|
669
704
|
// We need to save these props to state for using
|
|
@@ -685,120 +720,7 @@ exports.default = ReactGridLayout;
|
|
|
685
720
|
|
|
686
721
|
_defineProperty(ReactGridLayout, "displayName", "ReactGridLayout");
|
|
687
722
|
|
|
688
|
-
_defineProperty(ReactGridLayout, "propTypes",
|
|
689
|
-
//
|
|
690
|
-
// Basic props
|
|
691
|
-
//
|
|
692
|
-
className: _propTypes.default.string,
|
|
693
|
-
style: _propTypes.default.object,
|
|
694
|
-
// This can be set explicitly. If it is not set, it will automatically
|
|
695
|
-
// be set to the container width. Note that resizes will *not* cause this to adjust.
|
|
696
|
-
// If you need that behavior, use WidthProvider.
|
|
697
|
-
width: _propTypes.default.number,
|
|
698
|
-
// If true, the container height swells and contracts to fit contents
|
|
699
|
-
autoSize: _propTypes.default.bool,
|
|
700
|
-
// # of cols.
|
|
701
|
-
cols: _propTypes.default.number,
|
|
702
|
-
// A selector that will not be draggable.
|
|
703
|
-
draggableCancel: _propTypes.default.string,
|
|
704
|
-
// A selector for the draggable handler
|
|
705
|
-
draggableHandle: _propTypes.default.string,
|
|
706
|
-
// Deprecated
|
|
707
|
-
verticalCompact: function verticalCompact(props
|
|
708
|
-
/*: Props*/
|
|
709
|
-
) {
|
|
710
|
-
if (props.verticalCompact === false && process.env.NODE_ENV !== "production") {
|
|
711
|
-
console.warn( // eslint-disable-line no-console
|
|
712
|
-
"`verticalCompact` on <ReactGridLayout> is deprecated and will be removed soon. " + 'Use `compactType`: "horizontal" | "vertical" | null.');
|
|
713
|
-
}
|
|
714
|
-
},
|
|
715
|
-
// Choose vertical or hotizontal compaction
|
|
716
|
-
compactType: _propTypes.default.oneOf(["vertical", "horizontal"]),
|
|
717
|
-
// layout is an array of object with the format:
|
|
718
|
-
// {x: Number, y: Number, w: Number, h: Number, i: String}
|
|
719
|
-
layout: function layout(props
|
|
720
|
-
/*: Props*/
|
|
721
|
-
) {
|
|
722
|
-
var layout = props.layout; // I hope you're setting the data-grid property on the grid items
|
|
723
|
-
|
|
724
|
-
if (layout === undefined) return;
|
|
725
|
-
(0, _utils.validateLayout)(layout, "layout");
|
|
726
|
-
},
|
|
727
|
-
//
|
|
728
|
-
// Grid Dimensions
|
|
729
|
-
//
|
|
730
|
-
// Margin between items [x, y] in px
|
|
731
|
-
margin: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
732
|
-
// Padding inside the container [x, y] in px
|
|
733
|
-
containerPadding: _propTypes.default.arrayOf(_propTypes.default.number),
|
|
734
|
-
// Rows have a static height, but you can change this based on breakpoints if you like
|
|
735
|
-
rowHeight: _propTypes.default.number,
|
|
736
|
-
// Default Infinity, but you can specify a max here if you like.
|
|
737
|
-
// Note that this isn't fully fleshed out and won't error if you specify a layout that
|
|
738
|
-
// extends beyond the row capacity. It will, however, not allow users to drag/resize
|
|
739
|
-
// an item past the barrier. They can push items beyond the barrier, though.
|
|
740
|
-
// Intentionally not documented for this reason.
|
|
741
|
-
maxRows: _propTypes.default.number,
|
|
742
|
-
//
|
|
743
|
-
// Flags
|
|
744
|
-
//
|
|
745
|
-
isDraggable: _propTypes.default.bool,
|
|
746
|
-
isResizable: _propTypes.default.bool,
|
|
747
|
-
// If true, grid items won't change position when being dragged over.
|
|
748
|
-
preventCollision: _propTypes.default.bool,
|
|
749
|
-
// Use CSS transforms instead of top/left
|
|
750
|
-
useCSSTransforms: _propTypes.default.bool,
|
|
751
|
-
// parent layout transform scale
|
|
752
|
-
transformScale: _propTypes.default.number,
|
|
753
|
-
// If true, an external element can trigger onDrop callback with a specific grid position as a parameter
|
|
754
|
-
isDroppable: _propTypes.default.bool,
|
|
755
|
-
//
|
|
756
|
-
// Callbacks
|
|
757
|
-
//
|
|
758
|
-
// Callback so you can save the layout. Calls after each drag & resize stops.
|
|
759
|
-
onLayoutChange: _propTypes.default.func,
|
|
760
|
-
// Calls when drag starts. Callback is of the signature (layout, oldItem, newItem, placeholder, e, ?node).
|
|
761
|
-
// All callbacks below have the same signature. 'start' and 'stop' callbacks omit the 'placeholder'.
|
|
762
|
-
onDragStart: _propTypes.default.func,
|
|
763
|
-
// Calls on each drag movement.
|
|
764
|
-
onDrag: _propTypes.default.func,
|
|
765
|
-
// Calls when drag is complete.
|
|
766
|
-
onDragStop: _propTypes.default.func,
|
|
767
|
-
//Calls when resize starts.
|
|
768
|
-
onResizeStart: _propTypes.default.func,
|
|
769
|
-
// Calls when resize movement happens.
|
|
770
|
-
onResize: _propTypes.default.func,
|
|
771
|
-
// Calls when resize is complete.
|
|
772
|
-
onResizeStop: _propTypes.default.func,
|
|
773
|
-
// Calls when some element is dropped.
|
|
774
|
-
onDrop: _propTypes.default.func,
|
|
775
|
-
//
|
|
776
|
-
// Other validations
|
|
777
|
-
//
|
|
778
|
-
droppingItem: _propTypes.default.shape({
|
|
779
|
-
i: _propTypes.default.string.isRequired,
|
|
780
|
-
w: _propTypes.default.number.isRequired,
|
|
781
|
-
h: _propTypes.default.number.isRequired
|
|
782
|
-
}),
|
|
783
|
-
// Children must not have duplicate keys.
|
|
784
|
-
children: function children(props
|
|
785
|
-
/*: Props*/
|
|
786
|
-
, propName
|
|
787
|
-
/*: string*/
|
|
788
|
-
) {
|
|
789
|
-
var children = props[propName]; // Check children keys for duplicates. Throw if found.
|
|
790
|
-
|
|
791
|
-
var keys = {};
|
|
792
|
-
|
|
793
|
-
_react.default.Children.forEach(children, function (child) {
|
|
794
|
-
if (keys[child.key]) {
|
|
795
|
-
throw new Error('Duplicate child key "' + child.key + '" found! This will cause problems in ReactGridLayout.');
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
keys[child.key] = true;
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
});
|
|
723
|
+
_defineProperty(ReactGridLayout, "propTypes", _ReactGridLayoutPropTypes.default);
|
|
802
724
|
|
|
803
725
|
_defineProperty(ReactGridLayout, "defaultProps", {
|
|
804
726
|
autoSize: true,
|