react-grid-layout 1.2.5 → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- 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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,7 +11,7 @@ var React = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _lodash = _interopRequireDefault(require("lodash.isequal"));
13
13
 
14
- var _classnames = _interopRequireDefault(require("classnames"));
14
+ var _clsx = _interopRequireDefault(require("clsx"));
15
15
 
16
16
  var _utils = require("./utils");
17
17
 
@@ -27,43 +27,43 @@ 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
- 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; }
38
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
39
 
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; }
40
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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
 
56
56
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
57
57
 
58
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
58
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
59
59
 
60
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
60
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
61
61
 
62
62
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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,251 @@ 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: 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
+ preventCollision = _this$props.preventCollision;
150
+ var l = (0, _utils.getLayoutItem)(layout, i);
151
+ if (!l) return; // Create placeholder (display only)
152
+
153
+ var placeholder = {
154
+ w: l.w,
155
+ h: l.h,
156
+ x: l.x,
157
+ y: l.y,
158
+ placeholder: true,
159
+ i: i
160
+ }; // Move the element to the dragged location.
161
+
162
+ var isUserAction = true;
163
+ layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
164
+
165
+ _this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
166
+
167
+ _this.setState({
168
+ layout: allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols),
169
+ activeDrag: placeholder
170
+ });
171
+ });
172
+
173
+ _defineProperty(_assertThisInitialized(_this), "onDragStop", function (i, x, y, _ref3) {
174
+ var e = _ref3.e,
175
+ node = _ref3.node;
176
+ if (!_this.state.activeDrag) return;
177
+ var oldDragItem = _this.state.oldDragItem;
178
+ var layout = _this.state.layout;
179
+ var _this$props2 = _this.props,
180
+ cols = _this$props2.cols,
181
+ preventCollision = _this$props2.preventCollision,
182
+ allowOverlap = _this$props2.allowOverlap;
183
+ var l = (0, _utils.getLayoutItem)(layout, i);
184
+ if (!l) return; // Move the element here
185
+
186
+ var isUserAction = true;
187
+ layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(_this.props), cols, allowOverlap);
188
+
189
+ _this.props.onDragStop(layout, oldDragItem, l, null, e, node); // Set state
190
+
191
+
192
+ var newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols);
193
+ var oldLayout = _this.state.oldLayout;
194
+
195
+ _this.setState({
196
+ activeDrag: null,
197
+ layout: newLayout,
198
+ oldDragItem: null,
199
+ oldLayout: null
200
+ });
201
+
202
+ _this.onLayoutMaybeChanged(newLayout, oldLayout);
203
+ });
204
+
205
+ _defineProperty(_assertThisInitialized(_this), "onResizeStart", function (i, w, h, _ref4) {
206
+ var e = _ref4.e,
207
+ node = _ref4.node;
208
+ var layout = _this.state.layout;
209
+ var l = (0, _utils.getLayoutItem)(layout, i);
210
+ if (!l) return;
211
+
212
+ _this.setState({
213
+ oldResizeItem: (0, _utils.cloneLayoutItem)(l),
214
+ oldLayout: _this.state.layout
215
+ });
216
+
217
+ _this.props.onResizeStart(layout, l, l, null, e, node);
218
+ });
219
+
220
+ _defineProperty(_assertThisInitialized(_this), "onResize", function (i, w, h, _ref5) {
221
+ var e = _ref5.e,
222
+ node = _ref5.node;
223
+ var _this$state = _this.state,
224
+ layout = _this$state.layout,
225
+ oldResizeItem = _this$state.oldResizeItem;
226
+ var _this$props3 = _this.props,
227
+ cols = _this$props3.cols,
228
+ preventCollision = _this$props3.preventCollision,
229
+ allowOverlap = _this$props3.allowOverlap;
230
+
231
+ var _withLayoutItem = (0, _utils.withLayoutItem)(layout, i, function (l) {
232
+ // Something like quad tree should be used
233
+ // to find collisions faster
234
+ var hasCollisions;
235
+
236
+ if (preventCollision && !allowOverlap) {
237
+ var collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
238
+ w: w,
239
+ h: h
240
+ })).filter(function (layoutItem) {
241
+ return layoutItem.i !== l.i;
242
+ });
243
+ hasCollisions = collisions.length > 0; // If we're colliding, we need adjust the placeholder.
244
+
245
+ // If we're colliding, we need adjust the placeholder.
246
+ if (hasCollisions) {
247
+ // adjust w && h to maximum allowed space
248
+ var leastX = Infinity,
249
+ leastY = Infinity;
250
+ collisions.forEach(function (layoutItem) {
251
+ if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
252
+ if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
253
+ });
254
+ if (Number.isFinite(leastX)) l.w = leastX - l.x;
255
+ if (Number.isFinite(leastY)) l.h = leastY - l.y;
256
+ }
257
+ }
258
+
259
+ if (!hasCollisions) {
260
+ // Set new width and height.
261
+ l.w = w;
262
+ l.h = h;
263
+ }
264
+
265
+ return l;
266
+ }),
267
+ _withLayoutItem2 = _slicedToArray(_withLayoutItem, 2),
268
+ newLayout = _withLayoutItem2[0],
269
+ l = _withLayoutItem2[1]; // Shouldn't ever happen, but typechecking makes it necessary
270
+
271
+
272
+ if (!l) return; // Create placeholder element (display only)
273
+
274
+ var placeholder = {
275
+ w: l.w,
276
+ h: l.h,
277
+ x: l.x,
278
+ y: l.y,
279
+ static: true,
280
+ i: i
281
+ };
282
+
283
+ _this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node); // Re-compact the newLayout and set the drag placeholder.
284
+
285
+
286
+ _this.setState({
287
+ layout: allowOverlap ? newLayout : (0, _utils.compact)(newLayout, (0, _utils.compactType)(_this.props), cols),
288
+ activeDrag: placeholder
289
+ });
290
+ });
291
+
292
+ _defineProperty(_assertThisInitialized(_this), "onResizeStop", function (i, w, h, _ref6) {
293
+ var e = _ref6.e,
294
+ node = _ref6.node;
295
+ var _this$state2 = _this.state,
296
+ layout = _this$state2.layout,
297
+ oldResizeItem = _this$state2.oldResizeItem;
298
+ var _this$props4 = _this.props,
299
+ cols = _this$props4.cols,
300
+ allowOverlap = _this$props4.allowOverlap;
301
+ var l = (0, _utils.getLayoutItem)(layout, i);
302
+
303
+ _this.props.onResizeStop(layout, oldResizeItem, l, null, e, node); // Set state
304
+
305
+
306
+ var newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(_this.props), cols);
307
+ var oldLayout = _this.state.oldLayout;
308
+
309
+ _this.setState({
310
+ activeDrag: null,
311
+ layout: newLayout,
312
+ oldResizeItem: null,
313
+ oldLayout: null
314
+ });
315
+
316
+ _this.onLayoutMaybeChanged(newLayout, oldLayout);
317
+ });
318
+
124
319
  _defineProperty(_assertThisInitialized(_this), "onDragOver", function (e) {
125
320
  var _e$nativeEvent$target;
126
321
 
127
- // we should ignore events from layout's children in Firefox
322
+ e.preventDefault(); // Prevent any browser native action
323
+
324
+ e.stopPropagation(); // we should ignore events from layout's children in Firefox
128
325
  // to avoid unpredictable jumping of a dropping placeholder
129
326
  // FIXME remove this hack
327
+
130
328
  if (isFirefox && // $FlowIgnore can't figure this out
131
329
  !((_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
330
  return false;
135
331
  }
136
332
 
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;
333
+ var _this$props5 = _this.props,
334
+ droppingItem = _this$props5.droppingItem,
335
+ onDropDragOver = _this$props5.onDropDragOver,
336
+ margin = _this$props5.margin,
337
+ cols = _this$props5.cols,
338
+ rowHeight = _this$props5.rowHeight,
339
+ maxRows = _this$props5.maxRows,
340
+ width = _this$props5.width,
341
+ containerPadding = _this$props5.containerPadding,
342
+ transformScale = _this$props5.transformScale; // Allow user to customize the dropping item or short-circuit the drop based on the results
343
+ // of the `onDragOver(e: Event)` callback.
344
+
345
+ var onDragOverResult = onDropDragOver === null || onDropDragOver === void 0 ? void 0 : onDropDragOver(e);
346
+
347
+ if (onDragOverResult === false) {
348
+ if (_this.state.droppingDOMNode) {
349
+ _this.removeDroppingPlaceholder();
350
+ }
351
+
352
+ return false;
353
+ }
354
+
355
+ var finalDroppingItem = _objectSpread(_objectSpread({}, droppingItem), onDragOverResult);
356
+
145
357
  var layout = _this.state.layout; // This is relative to the DOM element that this event fired for.
146
358
 
147
359
  var _e$nativeEvent = e.nativeEvent,
148
360
  layerX = _e$nativeEvent.layerX,
149
361
  layerY = _e$nativeEvent.layerY;
150
362
  var droppingPosition = {
151
- left: layerX,
152
- top: layerY,
363
+ left: layerX / transformScale,
364
+ top: layerY / transformScale,
153
365
  e: e
154
366
  };
155
367
 
@@ -164,14 +376,14 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
164
376
  containerWidth: width,
165
377
  containerPadding: containerPadding || margin
166
378
  };
167
- var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, droppingItem.w, droppingItem.h);
379
+ var calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, finalDroppingItem.w, finalDroppingItem.h);
168
380
 
169
381
  _this.setState({
170
382
  droppingDOMNode: /*#__PURE__*/React.createElement("div", {
171
- key: droppingItem.i
383
+ key: finalDroppingItem.i
172
384
  }),
173
385
  droppingPosition: droppingPosition,
174
- layout: [].concat(_toConsumableArray(layout), [_objectSpread(_objectSpread({}, droppingItem), {}, {
386
+ layout: [].concat(_toConsumableArray(layout), [_objectSpread(_objectSpread({}, finalDroppingItem), {}, {
175
387
  x: calculatedPosition.x,
176
388
  y: calculatedPosition.y,
177
389
  static: false,
@@ -190,15 +402,12 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
190
402
  });
191
403
  }
192
404
  }
193
-
194
- e.stopPropagation();
195
- e.preventDefault();
196
405
  });
197
406
 
198
407
  _defineProperty(_assertThisInitialized(_this), "removeDroppingPlaceholder", function () {
199
- var _this$props2 = _this.props,
200
- droppingItem = _this$props2.droppingItem,
201
- cols = _this$props2.cols;
408
+ var _this$props6 = _this.props,
409
+ droppingItem = _this$props6.droppingItem,
410
+ cols = _this$props6.cols;
202
411
  var layout = _this.state.layout;
203
412
  var newLayout = (0, _utils.compact)(layout.filter(function (l) {
204
413
  return l.i !== droppingItem.i;
@@ -212,7 +421,9 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
212
421
  });
213
422
  });
214
423
 
215
- _defineProperty(_assertThisInitialized(_this), "onDragLeave", function () {
424
+ _defineProperty(_assertThisInitialized(_this), "onDragLeave", function (e) {
425
+ e.preventDefault(); // Prevent any browser native action
426
+
216
427
  _this.dragEnterCounter--; // onDragLeave can be triggered on each layout's child.
217
428
  // But we know that count of dragEnter and dragLeave events
218
429
  // will be balanced after leaving the layout's container
@@ -224,13 +435,17 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
224
435
  }
225
436
  });
226
437
 
227
- _defineProperty(_assertThisInitialized(_this), "onDragEnter", function () {
438
+ _defineProperty(_assertThisInitialized(_this), "onDragEnter", function (e) {
439
+ e.preventDefault(); // Prevent any browser native action
440
+
228
441
  _this.dragEnterCounter++;
229
442
  });
230
443
 
231
444
  _defineProperty(_assertThisInitialized(_this), "onDrop", function (e
232
445
  /*: Event*/
233
446
  ) {
447
+ e.preventDefault(); // Prevent any browser native action
448
+
234
449
  var droppingItem = _this.props.droppingItem;
235
450
  var layout = _this.state.layout;
236
451
  var item = layout.find(function (l) {
@@ -244,7 +459,6 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
244
459
  _this.props.onDrop(layout, item, e);
245
460
  });
246
461
 
247
- (0, _utils.autoBindHandlers)(_assertThisInitialized(_this), ["onDragStart", "onDrag", "onDragStop", "onResizeStart", "onResize", "onResizeStop"]);
248
462
  return _this;
249
463
  }
250
464
 
@@ -310,118 +524,6 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
310
524
  * @param {Element} node The current dragging DOM element
311
525
  */
312
526
 
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
527
  }, {
426
528
  key: "onLayoutMaybeChanged",
427
529
  value: function onLayoutMaybeChanged(newLayout
@@ -436,150 +538,26 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
436
538
  }
437
539
  }
438
540
  }, {
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
- }
541
+ key: "placeholder",
542
+ value:
562
543
  /**
563
544
  * Create a placeholder object.
564
545
  * @return {Element} Placeholder div.
565
546
  */
566
-
567
- }, {
568
- key: "placeholder",
569
- value: function placeholder()
547
+ function placeholder()
570
548
  /*: ?ReactElement<any>*/
571
549
  {
572
550
  var activeDrag = this.state.activeDrag;
573
551
  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
552
+ var _this$props7 = this.props,
553
+ width = _this$props7.width,
554
+ cols = _this$props7.cols,
555
+ margin = _this$props7.margin,
556
+ containerPadding = _this$props7.containerPadding,
557
+ rowHeight = _this$props7.rowHeight,
558
+ maxRows = _this$props7.maxRows,
559
+ useCSSTransforms = _this$props7.useCSSTransforms,
560
+ transformScale = _this$props7.transformScale; // {...this.state.activeDrag} is pretty slow, actually
583
561
 
584
562
  return /*#__PURE__*/React.createElement(_GridItem.default, {
585
563
  w: activeDrag.w,
@@ -619,22 +597,22 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
619
597
  if (!child || !child.key) return;
620
598
  var l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
621
599
  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;
600
+ var _this$props8 = this.props,
601
+ width = _this$props8.width,
602
+ cols = _this$props8.cols,
603
+ margin = _this$props8.margin,
604
+ containerPadding = _this$props8.containerPadding,
605
+ rowHeight = _this$props8.rowHeight,
606
+ maxRows = _this$props8.maxRows,
607
+ isDraggable = _this$props8.isDraggable,
608
+ isResizable = _this$props8.isResizable,
609
+ isBounded = _this$props8.isBounded,
610
+ useCSSTransforms = _this$props8.useCSSTransforms,
611
+ transformScale = _this$props8.transformScale,
612
+ draggableCancel = _this$props8.draggableCancel,
613
+ draggableHandle = _this$props8.draggableHandle,
614
+ resizeHandles = _this$props8.resizeHandles,
615
+ resizeHandle = _this$props8.resizeHandle;
638
616
  var _this$state3 = this.state,
639
617
  mounted = _this$state3.mounted,
640
618
  droppingPosition = _this$state3.droppingPosition; // Determine user manipulations possible.
@@ -691,12 +669,12 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
691
669
  {
692
670
  var _this2 = this;
693
671
 
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;
699
- var mergedClassName = (0, _classnames.default)(layoutClassName, className);
672
+ var _this$props9 = this.props,
673
+ className = _this$props9.className,
674
+ style = _this$props9.style,
675
+ isDroppable = _this$props9.isDroppable,
676
+ innerRef = _this$props9.innerRef;
677
+ var mergedClassName = (0, _clsx.default)(layoutClassName, className);
700
678
 
701
679
  var mergedStyle = _objectSpread({
702
680
  height: this.containerHeight()
@@ -742,7 +720,7 @@ var ReactGridLayout = /*#__PURE__*/function (_React$Component) {
742
720
 
743
721
 
744
722
  if (newLayoutBase) {
745
- var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps));
723
+ var newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps), nextProps.allowOverlap);
746
724
  return {
747
725
  layout: newLayout,
748
726
  // We need to save these props to state for using
@@ -782,6 +760,7 @@ _defineProperty(ReactGridLayout, "defaultProps", {
782
760
  isBounded: false,
783
761
  isDraggable: true,
784
762
  isResizable: true,
763
+ allowOverlap: false,
785
764
  isDroppable: false,
786
765
  useCSSTransforms: true,
787
766
  transformScale: 1,
@@ -801,5 +780,6 @@ _defineProperty(ReactGridLayout, "defaultProps", {
801
780
  onResizeStart: _utils.noop,
802
781
  onResize: _utils.noop,
803
782
  onResizeStop: _utils.noop,
804
- onDrop: _utils.noop
783
+ onDrop: _utils.noop,
784
+ onDropDragOver: _utils.noop
805
785
  });