react-grid-layout 1.5.3 → 2.0.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.
Files changed (95) hide show
  1. package/README.md +1074 -432
  2. package/css/styles.css +6 -4
  3. package/dist/ResponsiveGridLayout-CH4s0tKj.d.ts +124 -0
  4. package/dist/ResponsiveGridLayout-D6lFRE3f.d.mts +124 -0
  5. package/dist/calculate-CwYDW8na.d.mts +168 -0
  6. package/dist/calculate-mgLpNJ5O.d.ts +168 -0
  7. package/dist/chunk-2KUHNJXF.mjs +90 -0
  8. package/dist/chunk-2KUHNJXF.mjs.map +1 -0
  9. package/dist/chunk-3WO4SAYB.js +868 -0
  10. package/dist/chunk-3WO4SAYB.js.map +1 -0
  11. package/dist/chunk-4HNUMWQK.mjs +822 -0
  12. package/dist/chunk-4HNUMWQK.mjs.map +1 -0
  13. package/dist/chunk-BFTKGAP3.js +1309 -0
  14. package/dist/chunk-BFTKGAP3.js.map +1 -0
  15. package/dist/chunk-F6NQPYKT.js +98 -0
  16. package/dist/chunk-F6NQPYKT.js.map +1 -0
  17. package/dist/chunk-H5KMDLY3.js +434 -0
  18. package/dist/chunk-H5KMDLY3.js.map +1 -0
  19. package/dist/chunk-PBQSHIID.js +4 -0
  20. package/dist/chunk-PBQSHIID.js.map +1 -0
  21. package/dist/chunk-R35HZZTA.mjs +1300 -0
  22. package/dist/chunk-R35HZZTA.mjs.map +1 -0
  23. package/dist/chunk-ZCXE6SR5.mjs +428 -0
  24. package/dist/chunk-ZCXE6SR5.mjs.map +1 -0
  25. package/dist/chunk-ZWN22PS2.mjs +3 -0
  26. package/dist/chunk-ZWN22PS2.mjs.map +1 -0
  27. package/dist/core.d.mts +33 -0
  28. package/dist/core.d.ts +33 -0
  29. package/dist/core.js +218 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/core.mjs +5 -0
  32. package/dist/core.mjs.map +1 -0
  33. package/dist/extras.d.mts +78 -0
  34. package/dist/extras.d.ts +78 -0
  35. package/dist/extras.js +91 -0
  36. package/dist/extras.js.map +1 -0
  37. package/dist/extras.mjs +89 -0
  38. package/dist/extras.mjs.map +1 -0
  39. package/dist/index.d.mts +7 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +154 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/index.mjs +7 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/dist/legacy.d.mts +163 -0
  46. package/dist/legacy.d.ts +163 -0
  47. package/dist/legacy.js +319 -0
  48. package/dist/legacy.js.map +1 -0
  49. package/dist/legacy.mjs +307 -0
  50. package/dist/legacy.mjs.map +1 -0
  51. package/dist/position-BmN1z36J.d.mts +319 -0
  52. package/dist/position-Dk2b4ZMS.d.ts +319 -0
  53. package/dist/react.d.mts +351 -0
  54. package/dist/react.d.ts +351 -0
  55. package/dist/react.js +96 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/react.mjs +7 -0
  58. package/dist/react.mjs.map +1 -0
  59. package/dist/responsive-C4L1ESlm.d.ts +145 -0
  60. package/dist/responsive-CJxefsYw.d.mts +145 -0
  61. package/dist/types-Cxf4nHNr.d.mts +375 -0
  62. package/dist/types-Cxf4nHNr.d.ts +375 -0
  63. package/index-dev.js +8 -0
  64. package/package.json +132 -40
  65. package/.babelrc.js +0 -22
  66. package/.browserslistrc +0 -3
  67. package/.eslintignore +0 -4
  68. package/.flowconfig +0 -20
  69. package/.prettierignore +0 -4
  70. package/.prettierrc +0 -17
  71. package/CHANGELOG.md +0 -985
  72. package/build/GridItem.js +0 -638
  73. package/build/ReactGridLayout.js +0 -741
  74. package/build/ReactGridLayoutPropTypes.js +0 -210
  75. package/build/ResponsiveReactGridLayout.js +0 -297
  76. package/build/calculateUtils.js +0 -165
  77. package/build/components/WidthProvider.js +0 -115
  78. package/build/fastRGLPropsEqual.js +0 -5
  79. package/build/responsiveUtils.js +0 -101
  80. package/build/utils.js +0 -842
  81. package/dist/react-grid-layout.min.js +0 -2
  82. package/dist/react-grid-layout.min.js.map +0 -1
  83. package/index.js.flow +0 -8
  84. package/ip_fetcher +0 -0
  85. package/ip_fetcher.c +0 -47
  86. package/lib/GridItem.jsx +0 -689
  87. package/lib/ReactGridLayout.jsx +0 -855
  88. package/lib/ReactGridLayoutPropTypes.js +0 -241
  89. package/lib/ResponsiveReactGridLayout.jsx +0 -349
  90. package/lib/calculateUtils.js +0 -169
  91. package/lib/components/WidthProvider.jsx +0 -110
  92. package/lib/fastRGLPropsEqual.js +0 -46
  93. package/lib/responsiveUtils.js +0 -118
  94. package/lib/utils.js +0 -995
  95. package/yarn-error.log +0 -7780
@@ -1,741 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- var _fastEquals = require("fast-equals");
9
- var _clsx = _interopRequireDefault(require("clsx"));
10
- var _utils = require("./utils");
11
- var _calculateUtils = require("./calculateUtils");
12
- var _GridItem = _interopRequireDefault(require("./GridItem"));
13
- var _ReactGridLayoutPropTypes = _interopRequireDefault(require("./ReactGridLayoutPropTypes"));
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
- /*:: import type {
22
- ChildrenArray as ReactChildrenArray,
23
- Element as ReactElement
24
- } from "react";*/
25
- /*:: import type {
26
- CompactType,
27
- GridResizeEvent,
28
- GridDragEvent,
29
- DragOverEvent,
30
- Layout,
31
- DroppingPosition,
32
- LayoutItem
33
- } from "./utils";*/
34
- // Types
35
- /*:: import type { PositionParams } from "./calculateUtils";*/
36
- /*:: type State = {
37
- activeDrag: ?LayoutItem,
38
- layout: Layout,
39
- mounted: boolean,
40
- oldDragItem: ?LayoutItem,
41
- oldLayout: ?Layout,
42
- oldResizeItem: ?LayoutItem,
43
- resizing: boolean,
44
- droppingDOMNode: ?ReactElement<any>,
45
- droppingPosition?: DroppingPosition,
46
- // Mirrored props
47
- children: ReactChildrenArray<ReactElement<any>>,
48
- compactType?: CompactType,
49
- propsLayout?: Layout
50
- };*/
51
- /*:: import type { Props, DefaultProps } from "./ReactGridLayoutPropTypes";*/
52
- // End Types
53
- const layoutClassName = "react-grid-layout";
54
- let isFirefox = false;
55
- // Try...catch will protect from navigator not existing (e.g. node) or a bad implementation of navigator
56
- try {
57
- isFirefox = /firefox/i.test(navigator.userAgent);
58
- } catch (e) {
59
- /* Ignore */
60
- }
61
-
62
- /**
63
- * A reactive, fluid grid layout with draggable, resizable components.
64
- */
65
-
66
- class ReactGridLayout extends React.Component /*:: <Props, State>*/{
67
- constructor() {
68
- super(...arguments);
69
- _defineProperty(this, "state", {
70
- activeDrag: null,
71
- layout: (0, _utils.synchronizeLayoutWithChildren)(this.props.layout, this.props.children, this.props.cols,
72
- // Legacy support for verticalCompact: false
73
- (0, _utils.compactType)(this.props), this.props.allowOverlap),
74
- mounted: false,
75
- oldDragItem: null,
76
- oldLayout: null,
77
- oldResizeItem: null,
78
- resizing: false,
79
- droppingDOMNode: null,
80
- children: []
81
- });
82
- _defineProperty(this, "dragEnterCounter", 0);
83
- /**
84
- * When dragging starts
85
- * @param {String} i Id of the child
86
- * @param {Number} x X position of the move
87
- * @param {Number} y Y position of the move
88
- * @param {Event} e The mousedown event
89
- * @param {Element} node The current dragging DOM element
90
- */
91
- _defineProperty(this, "onDragStart", (i /*: string*/, x /*: number*/, y /*: number*/, _ref /*:: */) => {
92
- let {
93
- e,
94
- node
95
- } /*: GridDragEvent*/ = _ref /*: GridDragEvent*/;
96
- const {
97
- layout
98
- } = this.state;
99
- const l = (0, _utils.getLayoutItem)(layout, i);
100
- if (!l) return;
101
-
102
- // Create placeholder (display only)
103
- const placeholder = {
104
- w: l.w,
105
- h: l.h,
106
- x: l.x,
107
- y: l.y,
108
- placeholder: true,
109
- i: i
110
- };
111
- this.setState({
112
- oldDragItem: (0, _utils.cloneLayoutItem)(l),
113
- oldLayout: layout,
114
- activeDrag: placeholder
115
- });
116
- return this.props.onDragStart(layout, l, l, null, e, node);
117
- });
118
- /**
119
- * Each drag movement create a new dragelement and move the element to the dragged location
120
- * @param {String} i Id of the child
121
- * @param {Number} x X position of the move
122
- * @param {Number} y Y position of the move
123
- * @param {Event} e The mousedown event
124
- * @param {Element} node The current dragging DOM element
125
- */
126
- _defineProperty(this, "onDrag", (i, x, y, _ref2) => {
127
- let {
128
- e,
129
- node
130
- } = _ref2;
131
- const {
132
- oldDragItem
133
- } = this.state;
134
- let {
135
- layout
136
- } = this.state;
137
- const {
138
- cols,
139
- allowOverlap,
140
- preventCollision
141
- } = this.props;
142
- const l = (0, _utils.getLayoutItem)(layout, i);
143
- if (!l) return;
144
-
145
- // Create placeholder (display only)
146
- const placeholder = {
147
- w: l.w,
148
- h: l.h,
149
- x: l.x,
150
- y: l.y,
151
- placeholder: true,
152
- i: i
153
- };
154
-
155
- // Move the element to the dragged location.
156
- const isUserAction = true;
157
- layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
158
- this.props.onDrag(layout, oldDragItem, l, placeholder, e, node);
159
- this.setState({
160
- layout: allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols),
161
- activeDrag: placeholder
162
- });
163
- });
164
- /**
165
- * When dragging stops, figure out which position the element is closest to and update its x and y.
166
- * @param {String} i Index of the child.
167
- * @param {Number} x X position of the move
168
- * @param {Number} y Y position of the move
169
- * @param {Event} e The mousedown event
170
- * @param {Element} node The current dragging DOM element
171
- */
172
- _defineProperty(this, "onDragStop", (i, x, y, _ref3) => {
173
- let {
174
- e,
175
- node
176
- } = _ref3;
177
- if (!this.state.activeDrag) return;
178
- const {
179
- oldDragItem
180
- } = this.state;
181
- let {
182
- layout
183
- } = this.state;
184
- const {
185
- cols,
186
- preventCollision,
187
- allowOverlap
188
- } = this.props;
189
- const l = (0, _utils.getLayoutItem)(layout, i);
190
- if (!l) return;
191
-
192
- // Move the element here
193
- const isUserAction = true;
194
- layout = (0, _utils.moveElement)(layout, l, x, y, isUserAction, preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
195
-
196
- // Set state
197
- const newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
198
- this.props.onDragStop(newLayout, oldDragItem, l, null, e, node);
199
- const {
200
- oldLayout
201
- } = this.state;
202
- this.setState({
203
- activeDrag: null,
204
- layout: newLayout,
205
- oldDragItem: null,
206
- oldLayout: null
207
- });
208
- this.onLayoutMaybeChanged(newLayout, oldLayout);
209
- });
210
- _defineProperty(this, "onResizeStart", (i, w, h, _ref4) => {
211
- let {
212
- e,
213
- node
214
- } = _ref4;
215
- const {
216
- layout
217
- } = this.state;
218
- const l = (0, _utils.getLayoutItem)(layout, i);
219
- if (!l) return;
220
- this.setState({
221
- oldResizeItem: (0, _utils.cloneLayoutItem)(l),
222
- oldLayout: this.state.layout,
223
- resizing: true
224
- });
225
- this.props.onResizeStart(layout, l, l, null, e, node);
226
- });
227
- _defineProperty(this, "onResize", (i, w, h, _ref5) => {
228
- let {
229
- e,
230
- node,
231
- size,
232
- handle
233
- } = _ref5;
234
- const {
235
- oldResizeItem
236
- } = this.state;
237
- const {
238
- layout
239
- } = this.state;
240
- const {
241
- cols,
242
- preventCollision,
243
- allowOverlap
244
- } = this.props;
245
- let shouldMoveItem = false;
246
- let finalLayout;
247
- let x;
248
- let y;
249
- const [newLayout, l] = (0, _utils.withLayoutItem)(layout, i, l => {
250
- let hasCollisions;
251
- x = l.x;
252
- y = l.y;
253
- if (["sw", "w", "nw", "n", "ne"].indexOf(handle) !== -1) {
254
- if (["sw", "nw", "w"].indexOf(handle) !== -1) {
255
- x = l.x + (l.w - w);
256
- w = l.x !== x && x < 0 ? l.w : w;
257
- x = x < 0 ? 0 : x;
258
- }
259
- if (["ne", "n", "nw"].indexOf(handle) !== -1) {
260
- y = l.y + (l.h - h);
261
- h = l.y !== y && y < 0 ? l.h : h;
262
- y = y < 0 ? 0 : y;
263
- }
264
- shouldMoveItem = true;
265
- }
266
-
267
- // Something like quad tree should be used
268
- // to find collisions faster
269
- if (preventCollision && !allowOverlap) {
270
- const collisions = (0, _utils.getAllCollisions)(layout, _objectSpread(_objectSpread({}, l), {}, {
271
- w,
272
- h,
273
- x,
274
- y
275
- })).filter(layoutItem => layoutItem.i !== l.i);
276
- hasCollisions = collisions.length > 0;
277
-
278
- // If we're colliding, we need adjust the placeholder.
279
- if (hasCollisions) {
280
- // Reset layoutItem dimensions if there were collisions
281
- y = l.y;
282
- h = l.h;
283
- x = l.x;
284
- w = l.w;
285
- shouldMoveItem = false;
286
- }
287
- }
288
- l.w = w;
289
- l.h = h;
290
- return l;
291
- });
292
-
293
- // Shouldn't ever happen, but typechecking makes it necessary
294
- if (!l) return;
295
- finalLayout = newLayout;
296
- if (shouldMoveItem) {
297
- // Move the element to the new position.
298
- const isUserAction = true;
299
- finalLayout = (0, _utils.moveElement)(newLayout, l, x, y, isUserAction, this.props.preventCollision, (0, _utils.compactType)(this.props), cols, allowOverlap);
300
- }
301
-
302
- // Create placeholder element (display only)
303
- const placeholder = {
304
- w: l.w,
305
- h: l.h,
306
- x: l.x,
307
- y: l.y,
308
- static: true,
309
- i: i
310
- };
311
- this.props.onResize(finalLayout, oldResizeItem, l, placeholder, e, node);
312
-
313
- // Re-compact the newLayout and set the drag placeholder.
314
- this.setState({
315
- layout: allowOverlap ? finalLayout : (0, _utils.compact)(finalLayout, (0, _utils.compactType)(this.props), cols),
316
- activeDrag: placeholder
317
- });
318
- });
319
- _defineProperty(this, "onResizeStop", (i, w, h, _ref6) => {
320
- let {
321
- e,
322
- node
323
- } = _ref6;
324
- const {
325
- layout,
326
- oldResizeItem
327
- } = this.state;
328
- const {
329
- cols,
330
- allowOverlap
331
- } = this.props;
332
- const l = (0, _utils.getLayoutItem)(layout, i);
333
-
334
- // Set state
335
- const newLayout = allowOverlap ? layout : (0, _utils.compact)(layout, (0, _utils.compactType)(this.props), cols);
336
- this.props.onResizeStop(newLayout, oldResizeItem, l, null, e, node);
337
- const {
338
- oldLayout
339
- } = this.state;
340
- this.setState({
341
- activeDrag: null,
342
- layout: newLayout,
343
- oldResizeItem: null,
344
- oldLayout: null,
345
- resizing: false
346
- });
347
- this.onLayoutMaybeChanged(newLayout, oldLayout);
348
- });
349
- // Called while dragging an element. Part of browser native drag/drop API.
350
- // Native event target might be the layout itself, or an element within the layout.
351
- _defineProperty(this, "onDragOver", e => {
352
- var _e$nativeEvent$target;
353
- e.preventDefault(); // Prevent any browser native action
354
- e.stopPropagation();
355
-
356
- // we should ignore events from layout's children in Firefox
357
- // to avoid unpredictable jumping of a dropping placeholder
358
- // FIXME remove this hack
359
- if (isFirefox &&
360
- // $FlowIgnore can't figure this out
361
- !((_e$nativeEvent$target = e.nativeEvent.target) !== null && _e$nativeEvent$target !== void 0 && _e$nativeEvent$target.classList.contains(layoutClassName))) {
362
- return false;
363
- }
364
- const {
365
- droppingItem,
366
- onDropDragOver,
367
- margin,
368
- cols,
369
- rowHeight,
370
- maxRows,
371
- width,
372
- containerPadding,
373
- transformScale
374
- } = this.props;
375
- // Allow user to customize the dropping item or short-circuit the drop based on the results
376
- // of the `onDragOver(e: Event)` callback.
377
- const onDragOverResult = onDropDragOver === null || onDropDragOver === void 0 ? void 0 : onDropDragOver(e);
378
- if (onDragOverResult === false) {
379
- if (this.state.droppingDOMNode) {
380
- this.removeDroppingPlaceholder();
381
- }
382
- return false;
383
- }
384
- const finalDroppingItem = _objectSpread(_objectSpread({}, droppingItem), onDragOverResult);
385
- const {
386
- layout
387
- } = this.state;
388
-
389
- // $FlowIgnore missing def
390
- const gridRect = e.currentTarget.getBoundingClientRect(); // The grid's position in the viewport
391
-
392
- // Calculate the mouse position relative to the grid
393
- const layerX = e.clientX - gridRect.left;
394
- const layerY = e.clientY - gridRect.top;
395
- const droppingPosition = {
396
- left: layerX / transformScale,
397
- top: layerY / transformScale,
398
- e
399
- };
400
- if (!this.state.droppingDOMNode) {
401
- const positionParams /*: PositionParams*/ = {
402
- cols,
403
- margin,
404
- maxRows,
405
- rowHeight,
406
- containerWidth: width,
407
- containerPadding: containerPadding || margin
408
- };
409
- const calculatedPosition = (0, _calculateUtils.calcXY)(positionParams, layerY, layerX, finalDroppingItem.w, finalDroppingItem.h);
410
- this.setState({
411
- droppingDOMNode: /*#__PURE__*/React.createElement("div", {
412
- key: finalDroppingItem.i
413
- }),
414
- droppingPosition,
415
- layout: [...layout, _objectSpread(_objectSpread({}, finalDroppingItem), {}, {
416
- x: calculatedPosition.x,
417
- y: calculatedPosition.y,
418
- static: false,
419
- isDraggable: true
420
- })]
421
- });
422
- } else if (this.state.droppingPosition) {
423
- const {
424
- left,
425
- top
426
- } = this.state.droppingPosition;
427
- const shouldUpdatePosition = left != layerX || top != layerY;
428
- if (shouldUpdatePosition) {
429
- this.setState({
430
- droppingPosition
431
- });
432
- }
433
- }
434
- });
435
- _defineProperty(this, "removeDroppingPlaceholder", () => {
436
- const {
437
- droppingItem,
438
- cols
439
- } = this.props;
440
- const {
441
- layout
442
- } = this.state;
443
- const newLayout = (0, _utils.compact)(layout.filter(l => l.i !== droppingItem.i), (0, _utils.compactType)(this.props), cols, this.props.allowOverlap);
444
- this.setState({
445
- layout: newLayout,
446
- droppingDOMNode: null,
447
- activeDrag: null,
448
- droppingPosition: undefined
449
- });
450
- });
451
- _defineProperty(this, "onDragLeave", e => {
452
- e.preventDefault(); // Prevent any browser native action
453
- e.stopPropagation();
454
- this.dragEnterCounter--;
455
-
456
- // onDragLeave can be triggered on each layout's child.
457
- // But we know that count of dragEnter and dragLeave events
458
- // will be balanced after leaving the layout's container
459
- // so we can increase and decrease count of dragEnter and
460
- // when it'll be equal to 0 we'll remove the placeholder
461
- if (this.dragEnterCounter === 0) {
462
- this.removeDroppingPlaceholder();
463
- }
464
- });
465
- _defineProperty(this, "onDragEnter", e => {
466
- e.preventDefault(); // Prevent any browser native action
467
- e.stopPropagation();
468
- this.dragEnterCounter++;
469
- });
470
- _defineProperty(this, "onDrop", (e /*: Event*/) => {
471
- e.preventDefault(); // Prevent any browser native action
472
- e.stopPropagation();
473
- const {
474
- droppingItem
475
- } = this.props;
476
- const {
477
- layout
478
- } = this.state;
479
- const item = layout.find(l => l.i === droppingItem.i);
480
-
481
- // reset dragEnter counter on drop
482
- this.dragEnterCounter = 0;
483
- this.removeDroppingPlaceholder();
484
- this.props.onDrop(layout, item, e);
485
- });
486
- }
487
- componentDidMount() {
488
- this.setState({
489
- mounted: true
490
- });
491
- // Possibly call back with layout on mount. This should be done after correcting the layout width
492
- // to ensure we don't rerender with the wrong width.
493
- this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
494
- }
495
- static getDerivedStateFromProps(nextProps /*: Props*/, prevState /*: State*/) /*: $Shape<State> | null*/{
496
- let newLayoutBase;
497
- if (prevState.activeDrag) {
498
- return null;
499
- }
500
-
501
- // Legacy support for compactType
502
- // Allow parent to set layout directly.
503
- if (!(0, _fastEquals.deepEqual)(nextProps.layout, prevState.propsLayout) || nextProps.compactType !== prevState.compactType) {
504
- newLayoutBase = nextProps.layout;
505
- } else if (!(0, _utils.childrenEqual)(nextProps.children, prevState.children)) {
506
- // If children change, also regenerate the layout. Use our state
507
- // as the base in case because it may be more up to date than
508
- // what is in props.
509
- newLayoutBase = prevState.layout;
510
- }
511
-
512
- // We need to regenerate the layout.
513
- if (newLayoutBase) {
514
- const newLayout = (0, _utils.synchronizeLayoutWithChildren)(newLayoutBase, nextProps.children, nextProps.cols, (0, _utils.compactType)(nextProps), nextProps.allowOverlap);
515
- return {
516
- layout: newLayout,
517
- // We need to save these props to state for using
518
- // getDerivedStateFromProps instead of componentDidMount (in which we would get extra rerender)
519
- compactType: nextProps.compactType,
520
- children: nextProps.children,
521
- propsLayout: nextProps.layout
522
- };
523
- }
524
- return null;
525
- }
526
- shouldComponentUpdate(nextProps /*: Props*/, nextState /*: State*/) /*: boolean*/{
527
- return (
528
- // NOTE: this is almost always unequal. Therefore the only way to get better performance
529
- // from SCU is if the user intentionally memoizes children. If they do, and they can
530
- // handle changes properly, performance will increase.
531
- this.props.children !== nextProps.children || !(0, _utils.fastRGLPropsEqual)(this.props, nextProps, _fastEquals.deepEqual) || this.state.activeDrag !== nextState.activeDrag || this.state.mounted !== nextState.mounted || this.state.droppingPosition !== nextState.droppingPosition
532
- );
533
- }
534
- componentDidUpdate(prevProps /*: Props*/, prevState /*: State*/) {
535
- if (!this.state.activeDrag) {
536
- const newLayout = this.state.layout;
537
- const oldLayout = prevState.layout;
538
- this.onLayoutMaybeChanged(newLayout, oldLayout);
539
- }
540
- }
541
-
542
- /**
543
- * Calculates a pixel value for the container.
544
- * @return {String} Container height in pixels.
545
- */
546
- containerHeight() /*: ?string*/{
547
- if (!this.props.autoSize) return;
548
- const nbRow = (0, _utils.bottom)(this.state.layout);
549
- const containerPaddingY = this.props.containerPadding ? this.props.containerPadding[1] : this.props.margin[1];
550
- return nbRow * this.props.rowHeight + (nbRow - 1) * this.props.margin[1] + containerPaddingY * 2 + "px";
551
- }
552
- onLayoutMaybeChanged(newLayout /*: Layout*/, oldLayout /*: ?Layout*/) {
553
- if (!oldLayout) oldLayout = this.state.layout;
554
- if (!(0, _fastEquals.deepEqual)(oldLayout, newLayout)) {
555
- this.props.onLayoutChange(newLayout);
556
- }
557
- }
558
- /**
559
- * Create a placeholder object.
560
- * @return {Element} Placeholder div.
561
- */
562
- placeholder() /*: ?ReactElement<any>*/{
563
- const {
564
- activeDrag
565
- } = this.state;
566
- if (!activeDrag) return null;
567
- const {
568
- width,
569
- cols,
570
- margin,
571
- containerPadding,
572
- rowHeight,
573
- maxRows,
574
- useCSSTransforms,
575
- transformScale
576
- } = this.props;
577
-
578
- // {...this.state.activeDrag} is pretty slow, actually
579
- return /*#__PURE__*/React.createElement(_GridItem.default, {
580
- w: activeDrag.w,
581
- h: activeDrag.h,
582
- x: activeDrag.x,
583
- y: activeDrag.y,
584
- i: activeDrag.i,
585
- className: "react-grid-placeholder ".concat(this.state.resizing ? "placeholder-resizing" : ""),
586
- containerWidth: width,
587
- cols: cols,
588
- margin: margin,
589
- containerPadding: containerPadding || margin,
590
- maxRows: maxRows,
591
- rowHeight: rowHeight,
592
- isDraggable: false,
593
- isResizable: false,
594
- isBounded: false,
595
- useCSSTransforms: useCSSTransforms,
596
- transformScale: transformScale
597
- }, /*#__PURE__*/React.createElement("div", null));
598
- }
599
-
600
- /**
601
- * Given a grid item, set its style attributes & surround in a <Draggable>.
602
- * @param {Element} child React element.
603
- * @return {Element} Element wrapped in draggable and properly placed.
604
- */
605
- processGridItem(child /*: ReactElement<any>*/, isDroppingItem /*: boolean*/) /*: ?ReactElement<any>*/{
606
- if (!child || !child.key) return;
607
- const l = (0, _utils.getLayoutItem)(this.state.layout, String(child.key));
608
- if (!l) return null;
609
- const {
610
- width,
611
- cols,
612
- margin,
613
- containerPadding,
614
- rowHeight,
615
- maxRows,
616
- isDraggable,
617
- isResizable,
618
- isBounded,
619
- useCSSTransforms,
620
- transformScale,
621
- draggableCancel,
622
- draggableHandle,
623
- resizeHandles,
624
- resizeHandle
625
- } = this.props;
626
- const {
627
- mounted,
628
- droppingPosition
629
- } = this.state;
630
-
631
- // Determine user manipulations possible.
632
- // If an item is static, it can't be manipulated by default.
633
- // Any properties defined directly on the grid item will take precedence.
634
- const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
635
- const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
636
- const resizeHandlesOptions = l.resizeHandles || resizeHandles;
637
-
638
- // isBounded set on child if set on parent, and child is not explicitly false
639
- const bounded = draggable && isBounded && l.isBounded !== false;
640
- return /*#__PURE__*/React.createElement(_GridItem.default, {
641
- containerWidth: width,
642
- cols: cols,
643
- margin: margin,
644
- containerPadding: containerPadding || margin,
645
- maxRows: maxRows,
646
- rowHeight: rowHeight,
647
- cancel: draggableCancel,
648
- handle: draggableHandle,
649
- onDragStop: this.onDragStop,
650
- onDragStart: this.onDragStart,
651
- onDrag: this.onDrag,
652
- onResizeStart: this.onResizeStart,
653
- onResize: this.onResize,
654
- onResizeStop: this.onResizeStop,
655
- isDraggable: draggable,
656
- isResizable: resizable,
657
- isBounded: bounded,
658
- useCSSTransforms: useCSSTransforms && mounted,
659
- usePercentages: !mounted,
660
- transformScale: transformScale,
661
- w: l.w,
662
- h: l.h,
663
- x: l.x,
664
- y: l.y,
665
- i: l.i,
666
- minH: l.minH,
667
- minW: l.minW,
668
- maxH: l.maxH,
669
- maxW: l.maxW,
670
- static: l.static,
671
- droppingPosition: isDroppingItem ? droppingPosition : undefined,
672
- resizeHandles: resizeHandlesOptions,
673
- resizeHandle: resizeHandle
674
- }, child);
675
- }
676
- render() /*: React.Element<"div">*/{
677
- const {
678
- className,
679
- style,
680
- isDroppable,
681
- innerRef
682
- } = this.props;
683
- const mergedClassName = (0, _clsx.default)(layoutClassName, className);
684
- const mergedStyle = _objectSpread({
685
- height: this.containerHeight()
686
- }, style);
687
- return /*#__PURE__*/React.createElement("div", {
688
- ref: innerRef,
689
- className: mergedClassName,
690
- style: mergedStyle,
691
- onDrop: isDroppable ? this.onDrop : _utils.noop,
692
- onDragLeave: isDroppable ? this.onDragLeave : _utils.noop,
693
- onDragEnter: isDroppable ? this.onDragEnter : _utils.noop,
694
- onDragOver: isDroppable ? this.onDragOver : _utils.noop
695
- }, React.Children.map(this.props.children, child => this.processGridItem(child)), isDroppable && this.state.droppingDOMNode && this.processGridItem(this.state.droppingDOMNode, true), this.placeholder());
696
- }
697
- }
698
- exports.default = ReactGridLayout;
699
- // TODO publish internal ReactClass displayName transform
700
- _defineProperty(ReactGridLayout, "displayName", "ReactGridLayout");
701
- // Refactored to another module to make way for preval
702
- _defineProperty(ReactGridLayout, "propTypes", _ReactGridLayoutPropTypes.default);
703
- _defineProperty(ReactGridLayout, "defaultProps", {
704
- autoSize: true,
705
- cols: 12,
706
- className: "",
707
- style: {},
708
- draggableHandle: "",
709
- draggableCancel: "",
710
- containerPadding: null,
711
- rowHeight: 150,
712
- maxRows: Infinity,
713
- // infinite vertical growth
714
- layout: [],
715
- margin: [10, 10],
716
- isBounded: false,
717
- isDraggable: true,
718
- isResizable: true,
719
- allowOverlap: false,
720
- isDroppable: false,
721
- useCSSTransforms: true,
722
- transformScale: 1,
723
- verticalCompact: true,
724
- compactType: "vertical",
725
- preventCollision: false,
726
- droppingItem: {
727
- i: "__dropping-elem__",
728
- h: 1,
729
- w: 1
730
- },
731
- resizeHandles: ["se"],
732
- onLayoutChange: _utils.noop,
733
- onDragStart: _utils.noop,
734
- onDrag: _utils.noop,
735
- onDragStop: _utils.noop,
736
- onResizeStart: _utils.noop,
737
- onResize: _utils.noop,
738
- onResizeStop: _utils.noop,
739
- onDrop: _utils.noop,
740
- onDropDragOver: _utils.noop
741
- });