react-grid-layout 1.2.5 → 1.3.0

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.
@@ -27,29 +27,29 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
27
27
 
28
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
29
 
30
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
30
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
31
31
 
32
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
32
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
33
 
34
- function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
34
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
35
35
 
36
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
37
37
 
38
38
  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; }
39
39
 
40
40
  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; }
41
41
 
42
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
42
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
43
 
44
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
44
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
45
45
 
46
46
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
47
47
 
48
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
48
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
49
49
 
50
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
50
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
51
51
 
52
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
52
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
53
53
 
54
54
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
55
 
@@ -63,7 +63,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
63
63
 
64
64
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
65
65
 
66
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
66
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
67
67
 
68
68
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
69
69
 
@@ -92,25 +92,21 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
92
92
 
93
93
  var _super = _createSuper(ReactGridLayout);
94
94
 
95
- // TODO publish internal ReactClass displayName transform
96
- // Refactored to another module to make way for preval
97
- function ReactGridLayout(props
98
- /*: Props*/
99
- , context
100
- /*: any*/
101
- )
102
- /*: void*/
103
- {
95
+ function ReactGridLayout() {
104
96
  var _this;
105
97
 
106
98
  _classCallCheck(this, ReactGridLayout);
107
99
 
108
- _this = _super.call(this, props, context);
100
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
101
+ args[_key] = arguments[_key];
102
+ }
103
+
104
+ _this = _super.call.apply(_super, [this].concat(args));
109
105
 
110
106
  _defineProperty(_assertThisInitialized(_this), "state", {
111
107
  activeDrag: null,
112
108
  layout: (0, _utils.synchronizeLayoutWithChildren)(_this.props.layout, _this.props.children, _this.props.cols, // Legacy support for verticalCompact: false
113
- (0, _utils.compactType)(_this.props)),
109
+ (0, _utils.compactType)(_this.props), _this.props.allowOverlap),
114
110
  mounted: false,
115
111
  oldDragItem: null,
116
112
  oldLayout: null,
@@ -121,35 +117,250 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
121
117
 
122
118
  _defineProperty(_assertThisInitialized(_this), "dragEnterCounter", 0);
123
119
 
120
+ _defineProperty(_assertThisInitialized(_this), "onDragStart", function (i
121
+ /*: string*/
122
+ , x
123
+ /*: number*/
124
+ , y
125
+ /*: number*/
126
+ , _ref) {
127
+ var e = _ref.e,
128
+ node = _ref.node;
129
+ var layout = _this.state.layout;
130
+ var l = (0, _utils.getLayoutItem)(layout, i);
131
+ if (!l) return;
132
+
133
+ _this.setState({
134
+ oldDragItem: (0, _utils.cloneLayoutItem)(l),
135
+ oldLayout: _this.state.layout
136
+ });
137
+
138
+ return _this.props.onDragStart(layout, l, l, null, e, node);
139
+ });
140
+
141
+ _defineProperty(_assertThisInitialized(_this), "onDrag", function (i, x, y, _ref2) {
142
+ var e = _ref2.e,
143
+ node = _ref2.node;
144
+ var oldDragItem = _this.state.oldDragItem;
145
+ var layout = _this.state.layout;
146
+ var _this$props = _this.props,
147
+ cols = _this$props.cols,
148
+ allowOverlap = _this$props.allowOverlap;
149
+ var l = (0, _utils.getLayoutItem)(layout, i);
150
+ if (!l) return; // Create placeholder (display only)
151
+
152
+ var placeholder = {
153
+ w: l.w,
154
+ h: l.h,
155
+ x: l.x,
156
+ y: l.y,
157
+ placeholder: true,
158
+ i: i
159
+ }; // Move the element to the dragged location.
160
+
161
+ var isUserAction = true;
162
+ layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, _this.props.preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
163
+
164
+ _this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
165
+
166
+ _this.setState({
167
+ layout: allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols),
168
+ activeDrag: placeholder
169
+ });
170
+ });
171
+
172
+ _defineProperty(_assertThisInitialized(_this), "onDragStop", function (i, x, y, _ref3) {
173
+ var e = _ref3.e,
174
+ node = _ref3.node;
175
+ if (!_this.state.activeDrag) return;
176
+ var oldDragItem = _this.state.oldDragItem;
177
+ var layout = _this.state.layout;
178
+ var _this$props2 = _this.props,
179
+ cols = _this$props2.cols,
180
+ preventCollision = _this$props2.preventCollision,
181
+ allowOverlap = _this$props2.allowOverlap;
182
+ var l = (0, _utils.getLayoutItem)(layout, i);
183
+ if (!l) return; // Move the element here
184
+
185
+ var isUserAction = true;
186
+ layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
187
+
188
+ _this.props.onDragStop(layout, oldDragItem, l, null, e, node); // Set state
189
+
190
+
191
+ var newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols);
192
+ var oldLayout = _this.state.oldLayout;
193
+
194
+ _this.setState({
195
+ activeDrag: null,
196
+ layout: newLayout,
197
+ oldDragItem: null,
198
+ oldLayout: null
199
+ });
200
+
201
+ _this.onLayoutMaybeChanged(newLayout, oldLayout);
202
+ });
203
+
204
+ _defineProperty(_assertThisInitialized(_this), "onResizeStart", function (i, w, h, _ref4) {
205
+ var e = _ref4.e,
206
+ node = _ref4.node;
207
+ var layout = _this.state.layout;
208
+ var l = (0, _utils.getLayoutItem)(layout, i);
209
+ if (!l) return;
210
+
211
+ _this.setState({
212
+ oldResizeItem: (0, _utils.cloneLayoutItem)(l),
213
+ oldLayout: _this.state.layout
214
+ });
215
+
216
+ _this.props.onResizeStart(layout, l, l, null, e, node);
217
+ });
218
+
219
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (i, w, h, _ref5) {
220
+ var e = _ref5.e,
221
+ node = _ref5.node;
222
+ var _this$state = _this.state,
223
+ layout = _this$state.layout,
224
+ oldResizeItem = _this$state.oldResizeItem;
225
+ var _this$props3 = _this.props,
226
+ cols = _this$props3.cols,
227
+ preventCollision = _this$props3.preventCollision,
228
+ allowOverlap = _this$props3.allowOverlap;
229
+
230
+ var _withLayoutItem = (0, _utils.withLayoutItem)(layout, i, function (l) {
231
+ // Something like quad tree should be used
232
+ // to find collisions faster
233
+ var hasCollisions;
234
+
235
+ if (preventCollision && !allowOverlap) {
236
+ var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
237
+ w: w,
238
+ h: h
239
+ })).filter(function (layoutItem) {
240
+ return layoutItem.i !== l.i;
241
+ });
242
+ hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
243
+
244
+ // If we're colliding, we need adjust the placeholder.
245
+ if (hasCollisions) {
246
+ // adjust w && h to maximum allowed space
247
+ var leastX = Infinity,
248
+ leastY = Infinity;
249
+ collisions.forEach(function (layoutItem) {
250
+ if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
251
+ if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
252
+ });
253
+ if (Number.isFinite(leastX)) l.w = leastX - l.x;
254
+ if (Number.isFinite(leastY)) l.h = leastY - l.y;
255
+ }
256
+ }
257
+
258
+ if (!hasCollisions) {
259
+ // Set new width and height.
260
+ l.w = w;
261
+ l.h = h;
262
+ }
263
+
264
+ return l;
265
+ }),
266
+ _withLayoutItem2 = _slicedToArray(_withLayoutItem, 2),
267
+ newLayout = _withLayoutItem2[0],
268
+ l = _withLayoutItem2[1]; // Shouldn't ever happen, but typechecking makes it necessary
269
+
270
+
271
+ if (!l) return; // Create placeholder element (display only)
272
+
273
+ var placeholder = {
274
+ w: l.w,
275
+ h: l.h,
276
+ x: l.x,
277
+ y: l.y,
278
+ static: true,
279
+ i: i
280
+ };
281
+
282
+ _this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node); // Re-compact the newLayout and set the drag placeholder.
283
+
284
+
285
+ _this.setState({
286
+ layout: allowOverlap ? newLayout : (0, _utils.compact)(newLayout, (0, _utils.compactType)(_this.props), cols),
287
+ activeDrag: placeholder
288
+ });
289
+ });
290
+
291
+ _defineProperty(_assertThisInitialized(_this), "onResizeStop", function (i, w, h, _ref6) {
292
+ var e = _ref6.e,
293
+ node = _ref6.node;
294
+ var _this$state2 = _this.state,
295
+ layout = _this$state2.layout,
296
+ oldResizeItem = _this$state2.oldResizeItem;
297
+ var _this$props4 = _this.props,
298
+ cols = _this$props4.cols,
299
+ allowOverlap = _this$props4.allowOverlap;
300
+ var l = (0, _utils.getLayoutItem)(layout, i);
301
+
302
+ _this.props.onResizeStop(layout, oldResizeItem, l, null, e, node); // Set state
303
+
304
+
305
+ var newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols);
306
+ var oldLayout = _this.state.oldLayout;
307
+
308
+ _this.setState({
309
+ activeDrag: null,
310
+ layout: newLayout,
311
+ oldResizeItem: null,
312
+ oldLayout: null
313
+ });
314
+
315
+ _this.onLayoutMaybeChanged(newLayout, oldLayout);
316
+ });
317
+
124
318
  _defineProperty(_assertThisInitialized(_this), "onDragOver", function (e) {
125
319
  var _e$nativeEvent$target;
126
320
 
127
- // we should ignore events from layout's children in Firefox
321
+ e.preventDefault(); // Prevent any browser native action
322
+
323
+ e.stopPropagation(); // we should ignore events from layout's children in Firefox
128
324
  // to avoid unpredictable jumping of a dropping placeholder
129
325
  // FIXME remove this hack
326
+
130
327
  if (isFirefox && // $FlowIgnore can't figure this out
131
328
  !((_e$nativeEvent$target = e.nativeEvent.target) !== null && _e$nativeEvent$target !== void 0 && _e$nativeEvent$target.classList.contains(layoutClassName))) {
132
- // without this Firefox will not allow drop if currently over droppingItem
133
- e.preventDefault();
134
329
  return false;
135
330
  }
136
331
 
137
- var _this$props = _this.props,
138
- droppingItem = _this$props.droppingItem,
139
- margin = _this$props.margin,
140
- cols = _this$props.cols,
141
- rowHeight = _this$props.rowHeight,
142
- maxRows = _this$props.maxRows,
143
- width = _this$props.width,
144
- containerPadding = _this$props.containerPadding;
332
+ var _this$props5 = _this.props,
333
+ droppingItem = _this$props5.droppingItem,
334
+ onDropDragOver = _this$props5.onDropDragOver,
335
+ margin = _this$props5.margin,
336
+ cols = _this$props5.cols,
337
+ rowHeight = _this$props5.rowHeight,
338
+ maxRows = _this$props5.maxRows,
339
+ width = _this$props5.width,
340
+ containerPadding = _this$props5.containerPadding,
341
+ transformScale = _this$props5.transformScale; // Allow user to customize the dropping item or short-circuit the drop based on the results
342
+ // of the `onDragOver(e: Event)` callback.
343
+
344
+ var onDragOverResult = onDropDragOver === null || onDropDragOver === void 0 ? void 0 : onDropDragOver(e);
345
+
346
+ if (onDragOverResult === false) {
347
+ if (_this.state.droppingDOMNode) {
348
+ _this.removeDroppingPlaceholder();
349
+ }
350
+
351
+ return false;
352
+ }
353
+
354
+ var finalDroppingItem = _objectSpread(_objectSpread({}, droppingItem), onDragOverResult);
355
+
145
356
  var layout = _this.state.layout; // This is relative to the DOM element that this event fired for.
146
357
 
147
358
  var _e$nativeEvent = e.nativeEvent,
148
359
  layerX = _e$nativeEvent.layerX,
149
360
  layerY = _e$nativeEvent.layerY;
150
361
  var droppingPosition = {
151
- left: layerX,
152
- top: layerY,
362
+ left: layerX / transformScale,
363
+ top: layerY / transformScale,
153
364
  e: e
154
365
  };
155
366
 
@@ -164,14 +375,14 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
164
375
  containerWidth: width,
165
376
  containerPadding: containerPadding || margin
166
377
  };
167
- var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, droppingItem.w, droppingItem.h);
378
+ var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, finalDroppingItem.w, finalDroppingItem.h);
168
379
 
169
380
  _this.setState({
170
381
  droppingDOMNode: /*#__PURE__*/React.createElement("div", {
171
- key: droppingItem.i
382
+ key: finalDroppingItem.i
172
383
  }),
173
384
  droppingPosition: droppingPosition,
174
- layout: [].concat(_toConsumableArray(layout), [_objectSpread(_objectSpread({}, droppingItem), {}, {
385
+ layout: [].concat(_toConsumableArray(layout), [_objectSpread(_objectSpread({}, finalDroppingItem), {}, {
175
386
  x: calculatedPosition.x,
176
387
  y: calculatedPosition.y,
177
388
  static: false,
@@ -190,15 +401,12 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
190
401
  });
191
402
  }
192
403
  }
193
-
194
- e.stopPropagation();
195
- e.preventDefault();
196
404
  });
197
405
 
198
406
  _defineProperty(_assertThisInitialized(_this), "removeDroppingPlaceholder", function () {
199
- var _this$props2 = _this.props,
200
- droppingItem = _this$props2.droppingItem,
201
- cols = _this$props2.cols;
407
+ var _this$props6 = _this.props,
408
+ droppingItem = _this$props6.droppingItem,
409
+ cols = _this$props6.cols;
202
410
  var layout = _this.state.layout;
203
411
  var newLayout = (0, _utils.compact)(layout.filter(function (l) {
204
412
  return l.i !== droppingItem.i;
@@ -212,7 +420,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
212
420
  });
213
421
  });
214
422
 
215
- _defineProperty(_assertThisInitialized(_this), "onDragLeave", function () {
423
+ _defineProperty(_assertThisInitialized(_this), "onDragLeave", function (e) {
424
+ e.preventDefault(); // Prevent any browser native action
425
+
216
426
  _this.dragEnterCounter--; // onDragLeave can be triggered on each layout's child.
217
427
  // But we know that count of dragEnter and dragLeave events
218
428
  // will be balanced after leaving the layout's container
@@ -224,13 +434,17 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
224
434
  }
225
435
  });
226
436
 
227
- _defineProperty(_assertThisInitialized(_this), "onDragEnter", function () {
437
+ _defineProperty(_assertThisInitialized(_this), "onDragEnter", function (e) {
438
+ e.preventDefault(); // Prevent any browser native action
439
+
228
440
  _this.dragEnterCounter++;
229
441
  });
230
442
 
231
443
  _defineProperty(_assertThisInitialized(_this), "onDrop", function (e
232
444
  /*: Event*/
233
445
  ) {
446
+ e.preventDefault(); // Prevent any browser native action
447
+
234
448
  var droppingItem = _this.props.droppingItem;
235
449
  var layout = _this.state.layout;
236
450
  var item = layout.find(function (l) {
@@ -244,7 +458,6 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
244
458
  _this.props.onDrop(layout, item, e);
245
459
  });
246
460
 
247
- (0, _utils.autoBindHandlers)(_assertThisInitialized(_this), ["onDragStart", "onDrag", "onDragStop", "onResizeStart", "onResize", "onResizeStop"]);
248
461
  return _this;
249
462
  }
250
463
 
@@ -310,118 +523,6 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
310
523
  * @param {Element} node The current dragging DOM element
311
524
  */
312
525
 
313
- }, {
314
- key: "onDragStart",
315
- value: function onDragStart(i
316
- /*: string*/
317
- , x
318
- /*: number*/
319
- , y
320
- /*: number*/
321
- , _ref)
322
- /*: void*/
323
- {
324
- var e = _ref.e,
325
- node = _ref.node;
326
- var layout = this.state.layout;
327
- var l = (0, _utils.getLayoutItem)(layout, i);
328
- if (!l) return;
329
- this.setState({
330
- oldDragItem: (0, _utils.cloneLayoutItem)(l),
331
- oldLayout: this.state.layout
332
- });
333
- return this.props.onDragStart(layout, l, l, null, e, node);
334
- }
335
- /**
336
- * Each drag movement create a new dragelement and move the element to the dragged location
337
- * @param {String} i Id of the child
338
- * @param {Number} x X position of the move
339
- * @param {Number} y Y position of the move
340
- * @param {Event} e The mousedown event
341
- * @param {Element} node The current dragging DOM element
342
- */
343
-
344
- }, {
345
- key: "onDrag",
346
- value: function onDrag(i
347
- /*: string*/
348
- , x
349
- /*: number*/
350
- , y
351
- /*: number*/
352
- , _ref2)
353
- /*: void*/
354
- {
355
- var e = _ref2.e,
356
- node = _ref2.node;
357
- var oldDragItem = this.state.oldDragItem;
358
- var layout = this.state.layout;
359
- var cols = this.props.cols;
360
- var l = (0, _utils.getLayoutItem)(layout, i);
361
- if (!l) return; // Create placeholder (display only)
362
-
363
- var placeholder = {
364
- w: l.w,
365
- h: l.h,
366
- x: l.x,
367
- y: l.y,
368
- placeholder: true,
369
- i: i
370
- }; // Move the element to the dragged location.
371
-
372
- var isUserAction = true;
373
- layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, this.props.preventCollision, (0, _utils.compactType)(this.props), cols);
374
- this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
375
- this.setState({
376
- layout: (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
377
- activeDrag: placeholder
378
- });
379
- }
380
- /**
381
- * When dragging stops, figure out which position the element is closest to and update its x and y.
382
- * @param {String} i Index of the child.
383
- * @param {Number} x X position of the move
384
- * @param {Number} y Y position of the move
385
- * @param {Event} e The mousedown event
386
- * @param {Element} node The current dragging DOM element
387
- */
388
-
389
- }, {
390
- key: "onDragStop",
391
- value: function onDragStop(i
392
- /*: string*/
393
- , x
394
- /*: number*/
395
- , y
396
- /*: number*/
397
- , _ref3)
398
- /*: void*/
399
- {
400
- var e = _ref3.e,
401
- node = _ref3.node;
402
- if (!this.state.activeDrag) return;
403
- var oldDragItem = this.state.oldDragItem;
404
- var layout = this.state.layout;
405
- var _this$props3 = this.props,
406
- cols = _this$props3.cols,
407
- preventCollision = _this$props3.preventCollision;
408
- var l = (0, _utils.getLayoutItem)(layout, i);
409
- if (!l) return; // Move the element here
410
-
411
- var isUserAction = true;
412
- layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols);
413
- this.props.onDragStop(layout, oldDragItem, l, null, e, node); // Set state
414
-
415
- var newLayout = (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
416
- var oldLayout = this.state.oldLayout;
417
- this.setState({
418
- activeDrag: null,
419
- layout: newLayout,
420
- oldDragItem: null,
421
- oldLayout: null
422
- });
423
- this.onLayoutMaybeChanged(newLayout, oldLayout);
424
- }
425
526
  }, {
426
527
  key: "onLayoutMaybeChanged",
427
528
  value: function onLayoutMaybeChanged(newLayout
@@ -436,150 +537,26 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
436
537
  }
437
538
  }
438
539
  }, {
439
- key: "onResizeStart",
440
- value: function onResizeStart(i
441
- /*: string*/
442
- , w
443
- /*: number*/
444
- , h
445
- /*: number*/
446
- , _ref4) {
447
- var e = _ref4.e,
448
- node = _ref4.node;
449
- var layout = this.state.layout;
450
- var l = (0, _utils.getLayoutItem)(layout, i);
451
- if (!l) return;
452
- this.setState({
453
- oldResizeItem: (0, _utils.cloneLayoutItem)(l),
454
- oldLayout: this.state.layout
455
- });
456
- this.props.onResizeStart(layout, l, l, null, e, node);
457
- }
458
- }, {
459
- key: "onResize",
460
- value: function onResize(i
461
- /*: string*/
462
- , w
463
- /*: number*/
464
- , h
465
- /*: number*/
466
- , _ref5) {
467
- var e = _ref5.e,
468
- node = _ref5.node;
469
- var _this$state = this.state,
470
- layout = _this$state.layout,
471
- oldResizeItem = _this$state.oldResizeItem;
472
- var _this$props4 = this.props,
473
- cols = _this$props4.cols,
474
- preventCollision = _this$props4.preventCollision;
475
-
476
- var _withLayoutItem = (0, _utils.withLayoutItem)(layout, i, function (l) {
477
- // Something like quad tree should be used
478
- // to find collisions faster
479
- var hasCollisions;
480
-
481
- if (preventCollision) {
482
- var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
483
- w: w,
484
- h: h
485
- })).filter(function (layoutItem) {
486
- return layoutItem.i !== l.i;
487
- });
488
- hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
489
-
490
- // If we're colliding, we need adjust the placeholder.
491
- if (hasCollisions) {
492
- // adjust w && h to maximum allowed space
493
- var leastX = Infinity,
494
- leastY = Infinity;
495
- collisions.forEach(function (layoutItem) {
496
- if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
497
- if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
498
- });
499
- if (Number.isFinite(leastX)) l.w = leastX - l.x;
500
- if (Number.isFinite(leastY)) l.h = leastY - l.y;
501
- }
502
- }
503
-
504
- if (!hasCollisions) {
505
- // Set new width and height.
506
- l.w = w;
507
- l.h = h;
508
- }
509
-
510
- return l;
511
- }),
512
- _withLayoutItem2 = _slicedToArray(_withLayoutItem, 2),
513
- newLayout = _withLayoutItem2[0],
514
- l = _withLayoutItem2[1]; // Shouldn't ever happen, but typechecking makes it necessary
515
-
516
-
517
- if (!l) return; // Create placeholder element (display only)
518
-
519
- var placeholder = {
520
- w: l.w,
521
- h: l.h,
522
- x: l.x,
523
- y: l.y,
524
- static: true,
525
- i: i
526
- };
527
- this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node); // Re-compact the newLayout and set the drag placeholder.
528
-
529
- this.setState({
530
- layout: (0, _utils.compact)(newLayout, (0, _utils.compactType)(this.props), cols),
531
- activeDrag: placeholder
532
- });
533
- }
534
- }, {
535
- key: "onResizeStop",
536
- value: function onResizeStop(i
537
- /*: string*/
538
- , w
539
- /*: number*/
540
- , h
541
- /*: number*/
542
- , _ref6) {
543
- var e = _ref6.e,
544
- node = _ref6.node;
545
- var _this$state2 = this.state,
546
- layout = _this$state2.layout,
547
- oldResizeItem = _this$state2.oldResizeItem;
548
- var cols = this.props.cols;
549
- var l = (0, _utils.getLayoutItem)(layout, i);
550
- this.props.onResizeStop(layout, oldResizeItem, l, null, e, node); // Set state
551
-
552
- var newLayout = (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
553
- var oldLayout = this.state.oldLayout;
554
- this.setState({
555
- activeDrag: null,
556
- layout: newLayout,
557
- oldResizeItem: null,
558
- oldLayout: null
559
- });
560
- this.onLayoutMaybeChanged(newLayout, oldLayout);
561
- }
540
+ key: "placeholder",
541
+ value:
562
542
  /**
563
543
  * Create a placeholder object.
564
544
  * @return {Element} Placeholder div.
565
545
  */
566
-
567
- }, {
568
- key: "placeholder",
569
- value: function placeholder()
546
+ function placeholder()
570
547
  /*: ?ReactElement<any>*/
571
548
  {
572
549
  var activeDrag = this.state.activeDrag;
573
550
  if (!activeDrag) return null;
574
- var _this$props5 = this.props,
575
- width = _this$props5.width,
576
- cols = _this$props5.cols,
577
- margin = _this$props5.margin,
578
- containerPadding = _this$props5.containerPadding,
579
- rowHeight = _this$props5.rowHeight,
580
- maxRows = _this$props5.maxRows,
581
- useCSSTransforms = _this$props5.useCSSTransforms,
582
- transformScale = _this$props5.transformScale; // {...this.state.activeDrag} is pretty slow, actually
551
+ var _this$props7 = this.props,
552
+ width = _this$props7.width,
553
+ cols = _this$props7.cols,
554
+ margin = _this$props7.margin,
555
+ containerPadding = _this$props7.containerPadding,
556
+ rowHeight = _this$props7.rowHeight,
557
+ maxRows = _this$props7.maxRows,
558
+ useCSSTransforms = _this$props7.useCSSTransforms,
559
+ transformScale = _this$props7.transformScale; // {...this.state.activeDrag} is pretty slow, actually
583
560
 
584
561
  return /*#__PURE__*/React.createElement(_GridItem.default, {
585
562
  w: activeDrag.w,
@@ -619,22 +596,22 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
619
596
  if (!child || !child.key) return;
620
597
  var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
621
598
  if (!l) return null;
622
- var _this$props6 = this.props,
623
- width = _this$props6.width,
624
- cols = _this$props6.cols,
625
- margin = _this$props6.margin,
626
- containerPadding = _this$props6.containerPadding,
627
- rowHeight = _this$props6.rowHeight,
628
- maxRows = _this$props6.maxRows,
629
- isDraggable = _this$props6.isDraggable,
630
- isResizable = _this$props6.isResizable,
631
- isBounded = _this$props6.isBounded,
632
- useCSSTransforms = _this$props6.useCSSTransforms,
633
- transformScale = _this$props6.transformScale,
634
- draggableCancel = _this$props6.draggableCancel,
635
- draggableHandle = _this$props6.draggableHandle,
636
- resizeHandles = _this$props6.resizeHandles,
637
- resizeHandle = _this$props6.resizeHandle;
599
+ var _this$props8 = this.props,
600
+ width = _this$props8.width,
601
+ cols = _this$props8.cols,
602
+ margin = _this$props8.margin,
603
+ containerPadding = _this$props8.containerPadding,
604
+ rowHeight = _this$props8.rowHeight,
605
+ maxRows = _this$props8.maxRows,
606
+ isDraggable = _this$props8.isDraggable,
607
+ isResizable = _this$props8.isResizable,
608
+ isBounded = _this$props8.isBounded,
609
+ useCSSTransforms = _this$props8.useCSSTransforms,
610
+ transformScale = _this$props8.transformScale,
611
+ draggableCancel = _this$props8.draggableCancel,
612
+ draggableHandle = _this$props8.draggableHandle,
613
+ resizeHandles = _this$props8.resizeHandles,
614
+ resizeHandle = _this$props8.resizeHandle;
638
615
  var _this$state3 = this.state,
639
616
  mounted = _this$state3.mounted,
640
617
  droppingPosition = _this$state3.droppingPosition; // Determine user manipulations possible.
@@ -691,11 +668,11 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
691
668
  {
692
669
  var _this2 = this;
693
670
 
694
- var _this$props7 = this.props,
695
- className = _this$props7.className,
696
- style = _this$props7.style,
697
- isDroppable = _this$props7.isDroppable,
698
- innerRef = _this$props7.innerRef;
671
+ var _this$props9 = this.props,
672
+ className = _this$props9.className,
673
+ style = _this$props9.style,
674
+ isDroppable = _this$props9.isDroppable,
675
+ innerRef = _this$props9.innerRef;
699
676
  var mergedClassName = (0, _classnames.default)(layoutClassName, className);
700
677
 
701
678
  var mergedStyle = _objectSpread({
@@ -742,7 +719,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
742
719
 
743
720
 
744
721
  if (newLayoutBase) {
745
- var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps));
722
+ var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps), nextProps.allowOverlap);
746
723
  return {
747
724
  layout: newLayout,
748
725
  // We need to save these props to state for using
@@ -782,6 +759,7 @@ _defineProperty(ReactGridLayout, "defaultProps", {
782
759
  isBounded: false,
783
760
  isDraggable: true,
784
761
  isResizable: true,
762
+ allowOverlap: false,
785
763
  isDroppable: false,
786
764
  useCSSTransforms: true,
787
765
  transformScale: 1,
@@ -801,5 +779,6 @@ _defineProperty(ReactGridLayout, "defaultProps", {
801
779
  onResizeStart: _utils.noop,
802
780
  onResize: _utils.noop,
803
781
  onResizeStop: _utils.noop,
804
- onDrop: _utils.noop
782
+ onDrop: _utils.noop,
783
+ onDropDragOver: _utils.noop
805
784
  });