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
package/build/GridItem.js DELETED
@@ -1,638 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _reactDom = require("react-dom");
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _reactDraggable = require("react-draggable");
11
- var _reactResizable = require("react-resizable");
12
- var _utils = require("./utils");
13
- var _calculateUtils = require("./calculateUtils");
14
- var _ReactGridLayoutPropTypes = require("./ReactGridLayoutPropTypes");
15
- var _clsx = _interopRequireDefault(require("clsx"));
16
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
- 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; }
18
- 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; }
19
- 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; }
20
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
21
- 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); }
22
- /*:: import type { Element as ReactElement, Node as ReactNode } from "react";*/
23
- /*:: import type {
24
- ReactDraggableCallbackData,
25
- GridDragEvent,
26
- GridResizeEvent,
27
- DroppingPosition,
28
- Position,
29
- ResizeHandleAxis
30
- } from "./utils";*/
31
- /*:: import type { PositionParams } from "./calculateUtils";*/
32
- /*:: import type { ResizeHandle, ReactRef } from "./ReactGridLayoutPropTypes";*/
33
- /*:: type PartialPosition = { top: number, left: number };*/
34
- /*:: type GridItemCallback<Data: GridDragEvent | GridResizeEvent> = (
35
- i: string,
36
- w: number,
37
- h: number,
38
- Data
39
- ) => void;*/
40
- /*:: type ResizeCallbackData = {
41
- node: HTMLElement,
42
- size: Position,
43
- handle: ResizeHandleAxis
44
- };*/
45
- /*:: type GridItemResizeCallback = (
46
- e: Event,
47
- data: ResizeCallbackData,
48
- position: Position
49
- ) => void;*/
50
- /*:: type State = {
51
- resizing: ?{ top: number, left: number, width: number, height: number },
52
- dragging: ?{ top: number, left: number },
53
- className: string
54
- };*/
55
- /*:: type Props = {
56
- children: ReactElement<any>,
57
- cols: number,
58
- containerWidth: number,
59
- margin: [number, number],
60
- containerPadding: [number, number],
61
- rowHeight: number,
62
- maxRows: number,
63
- isDraggable: boolean,
64
- isResizable: boolean,
65
- isBounded: boolean,
66
- static?: boolean,
67
- useCSSTransforms?: boolean,
68
- usePercentages?: boolean,
69
- transformScale: number,
70
- droppingPosition?: DroppingPosition,
71
-
72
- className: string,
73
- style?: Object,
74
- // Draggability
75
- cancel: string,
76
- handle: string,
77
-
78
- x: number,
79
- y: number,
80
- w: number,
81
- h: number,
82
-
83
- minW: number,
84
- maxW: number,
85
- minH: number,
86
- maxH: number,
87
- i: string,
88
-
89
- resizeHandles?: ResizeHandleAxis[],
90
- resizeHandle?: ResizeHandle,
91
-
92
- onDrag?: GridItemCallback<GridDragEvent>,
93
- onDragStart?: GridItemCallback<GridDragEvent>,
94
- onDragStop?: GridItemCallback<GridDragEvent>,
95
- onResize?: GridItemCallback<GridResizeEvent>,
96
- onResizeStart?: GridItemCallback<GridResizeEvent>,
97
- onResizeStop?: GridItemCallback<GridResizeEvent>
98
- };*/
99
- /*:: type DefaultProps = {
100
- className: string,
101
- cancel: string,
102
- handle: string,
103
- minH: number,
104
- minW: number,
105
- maxH: number,
106
- maxW: number,
107
- transformScale: number
108
- };*/
109
- /**
110
- * An individual item within a ReactGridLayout.
111
- */
112
- class GridItem extends _react.default.Component /*:: <Props, State>*/{
113
- constructor() {
114
- super(...arguments);
115
- _defineProperty(this, "state", {
116
- resizing: null,
117
- dragging: null,
118
- className: ""
119
- });
120
- _defineProperty(this, "elementRef", /*#__PURE__*/_react.default.createRef());
121
- /**
122
- * onDragStart event handler
123
- * @param {Event} e event data
124
- * @param {Object} callbackData an object with node, delta and position information
125
- */
126
- _defineProperty(this, "onDragStart", (e, _ref) => {
127
- let {
128
- node
129
- } = _ref;
130
- const {
131
- onDragStart,
132
- transformScale
133
- } = this.props;
134
- if (!onDragStart) return;
135
- const newPosition /*: PartialPosition*/ = {
136
- top: 0,
137
- left: 0
138
- };
139
-
140
- // TODO: this wont work on nested parents
141
- const {
142
- offsetParent
143
- } = node;
144
- if (!offsetParent) return;
145
- const parentRect = offsetParent.getBoundingClientRect();
146
- const clientRect = node.getBoundingClientRect();
147
- const cLeft = clientRect.left / transformScale;
148
- const pLeft = parentRect.left / transformScale;
149
- const cTop = clientRect.top / transformScale;
150
- const pTop = parentRect.top / transformScale;
151
- newPosition.left = cLeft - pLeft + offsetParent.scrollLeft;
152
- newPosition.top = cTop - pTop + offsetParent.scrollTop;
153
- this.setState({
154
- dragging: newPosition
155
- });
156
-
157
- // Call callback with this data
158
- const {
159
- x,
160
- y
161
- } = (0, _calculateUtils.calcXY)(this.getPositionParams(), newPosition.top, newPosition.left, this.props.w, this.props.h);
162
- return onDragStart.call(this, this.props.i, x, y, {
163
- e,
164
- node,
165
- newPosition
166
- });
167
- });
168
- /**
169
- * onDrag event handler
170
- * @param {Event} e event data
171
- * @param {Object} callbackData an object with node, delta and position information
172
- * @param {boolean} dontFlush if true, will not call flushSync
173
- */
174
- _defineProperty(this, "onDrag", (e, _ref2, dontFlush) => {
175
- let {
176
- node,
177
- deltaX,
178
- deltaY
179
- } = _ref2;
180
- const {
181
- onDrag
182
- } = this.props;
183
- if (!onDrag) return;
184
- if (!this.state.dragging) {
185
- throw new Error("onDrag called before onDragStart.");
186
- }
187
- let top = this.state.dragging.top + deltaY;
188
- let left = this.state.dragging.left + deltaX;
189
- const {
190
- isBounded,
191
- i,
192
- w,
193
- h,
194
- containerWidth
195
- } = this.props;
196
- const positionParams = this.getPositionParams();
197
-
198
- // Boundary calculations; keeps items within the grid
199
- if (isBounded) {
200
- const {
201
- offsetParent
202
- } = node;
203
- if (offsetParent) {
204
- const {
205
- margin,
206
- rowHeight
207
- } = this.props;
208
- const bottomBoundary = offsetParent.clientHeight - (0, _calculateUtils.calcGridItemWHPx)(h, rowHeight, margin[1]);
209
- top = (0, _calculateUtils.clamp)(top, 0, bottomBoundary);
210
- const colWidth = (0, _calculateUtils.calcGridColWidth)(positionParams);
211
- const rightBoundary = containerWidth - (0, _calculateUtils.calcGridItemWHPx)(w, colWidth, margin[0]);
212
- left = (0, _calculateUtils.clamp)(left, 0, rightBoundary);
213
- }
214
- }
215
- const newPosition /*: PartialPosition*/ = {
216
- top,
217
- left
218
- };
219
-
220
- // dontFlush is set if we're calling from inside
221
- if (dontFlush) {
222
- this.setState({
223
- dragging: newPosition
224
- });
225
- } else {
226
- (0, _reactDom.flushSync)(() => {
227
- this.setState({
228
- dragging: newPosition
229
- });
230
- });
231
- }
232
-
233
- // Call callback with this data
234
- const {
235
- x,
236
- y
237
- } = (0, _calculateUtils.calcXY)(positionParams, top, left, w, h);
238
- return onDrag.call(this, i, x, y, {
239
- e,
240
- node,
241
- newPosition
242
- });
243
- });
244
- /**
245
- * onDragStop event handler
246
- * @param {Event} e event data
247
- * @param {Object} callbackData an object with node, delta and position information
248
- */
249
- _defineProperty(this, "onDragStop", (e, _ref3) => {
250
- let {
251
- node
252
- } = _ref3;
253
- const {
254
- onDragStop
255
- } = this.props;
256
- if (!onDragStop) return;
257
- if (!this.state.dragging) {
258
- throw new Error("onDragEnd called before onDragStart.");
259
- }
260
- const {
261
- w,
262
- h,
263
- i
264
- } = this.props;
265
- const {
266
- left,
267
- top
268
- } = this.state.dragging;
269
- const newPosition /*: PartialPosition*/ = {
270
- top,
271
- left
272
- };
273
- this.setState({
274
- dragging: null
275
- });
276
- const {
277
- x,
278
- y
279
- } = (0, _calculateUtils.calcXY)(this.getPositionParams(), top, left, w, h);
280
- return onDragStop.call(this, i, x, y, {
281
- e,
282
- node,
283
- newPosition
284
- });
285
- });
286
- /**
287
- * onResizeStop event handler
288
- * @param {Event} e event data
289
- * @param {Object} callbackData an object with node and size information
290
- */
291
- _defineProperty(this, "onResizeStop", (e, callbackData, position) => this.onResizeHandler(e, callbackData, position, "onResizeStop"));
292
- // onResizeStart event handler
293
- _defineProperty(this, "onResizeStart", (e, callbackData, position) => this.onResizeHandler(e, callbackData, position, "onResizeStart"));
294
- // onResize event handler
295
- _defineProperty(this, "onResize", (e, callbackData, position) => this.onResizeHandler(e, callbackData, position, "onResize"));
296
- }
297
- shouldComponentUpdate(nextProps /*: Props*/, nextState /*: State*/) /*: boolean*/{
298
- // We can't deeply compare children. If the developer memoizes them, we can
299
- // use this optimization.
300
- if (this.props.children !== nextProps.children) return true;
301
- if (this.props.droppingPosition !== nextProps.droppingPosition) return true;
302
- // TODO memoize these calculations so they don't take so long?
303
- const oldPosition = (0, _calculateUtils.calcGridItemPosition)(this.getPositionParams(this.props), this.props.x, this.props.y, this.props.w, this.props.h, this.state);
304
- const newPosition = (0, _calculateUtils.calcGridItemPosition)(this.getPositionParams(nextProps), nextProps.x, nextProps.y, nextProps.w, nextProps.h, nextState);
305
- return !(0, _utils.fastPositionEqual)(oldPosition, newPosition) || this.props.useCSSTransforms !== nextProps.useCSSTransforms;
306
- }
307
- componentDidMount() {
308
- this.moveDroppingItem({});
309
- }
310
- componentDidUpdate(prevProps /*: Props*/) {
311
- this.moveDroppingItem(prevProps);
312
- }
313
-
314
- // When a droppingPosition is present, this means we should fire a move event, as if we had moved
315
- // this element by `x, y` pixels.
316
- moveDroppingItem(prevProps /*: Props*/) {
317
- const {
318
- droppingPosition
319
- } = this.props;
320
- if (!droppingPosition) return;
321
- const node = this.elementRef.current;
322
- // Can't find DOM node (are we unmounted?)
323
- if (!node) return;
324
- const prevDroppingPosition = prevProps.droppingPosition || {
325
- left: 0,
326
- top: 0
327
- };
328
- const {
329
- dragging
330
- } = this.state;
331
- const shouldDrag = dragging && droppingPosition.left !== prevDroppingPosition.left || droppingPosition.top !== prevDroppingPosition.top;
332
- if (!dragging) {
333
- this.onDragStart(droppingPosition.e, {
334
- node,
335
- deltaX: droppingPosition.left,
336
- deltaY: droppingPosition.top
337
- });
338
- } else if (shouldDrag) {
339
- const deltaX = droppingPosition.left - dragging.left;
340
- const deltaY = droppingPosition.top - dragging.top;
341
- this.onDrag(droppingPosition.e, {
342
- node,
343
- deltaX,
344
- deltaY
345
- }, true // dontFLush: avoid flushSync to temper warnings
346
- );
347
- }
348
- }
349
- getPositionParams() /*: PositionParams*/{
350
- let props /*: Props*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
351
- return {
352
- cols: props.cols,
353
- containerPadding: props.containerPadding,
354
- containerWidth: props.containerWidth,
355
- margin: props.margin,
356
- maxRows: props.maxRows,
357
- rowHeight: props.rowHeight
358
- };
359
- }
360
-
361
- /**
362
- * This is where we set the grid item's absolute placement. It gets a little tricky because we want to do it
363
- * well when server rendering, and the only way to do that properly is to use percentage width/left because
364
- * we don't know exactly what the browser viewport is.
365
- * Unfortunately, CSS Transforms, which are great for performance, break in this instance because a percentage
366
- * left is relative to the item itself, not its container! So we cannot use them on the server rendering pass.
367
- *
368
- * @param {Object} pos Position object with width, height, left, top.
369
- * @return {Object} Style object.
370
- */
371
- createStyle(pos /*: Position*/) /*: { [key: string]: ?string }*/{
372
- const {
373
- usePercentages,
374
- containerWidth,
375
- useCSSTransforms
376
- } = this.props;
377
- let style;
378
- // CSS Transforms support (default)
379
- if (useCSSTransforms) {
380
- style = (0, _utils.setTransform)(pos);
381
- } else {
382
- // top,left (slow)
383
- style = (0, _utils.setTopLeft)(pos);
384
-
385
- // This is used for server rendering.
386
- if (usePercentages) {
387
- style.left = (0, _utils.perc)(pos.left / containerWidth);
388
- style.width = (0, _utils.perc)(pos.width / containerWidth);
389
- }
390
- }
391
- return style;
392
- }
393
-
394
- /**
395
- * Mix a Draggable instance into a child.
396
- * @param {Element} child Child element.
397
- * @return {Element} Child wrapped in Draggable.
398
- */
399
- mixinDraggable(child /*: ReactElement<any>*/, isDraggable /*: boolean*/) /*: ReactElement<any>*/{
400
- return /*#__PURE__*/_react.default.createElement(_reactDraggable.DraggableCore, {
401
- disabled: !isDraggable,
402
- onStart: this.onDragStart,
403
- onDrag: this.onDrag,
404
- onStop: this.onDragStop,
405
- handle: this.props.handle,
406
- cancel: ".react-resizable-handle" + (this.props.cancel ? "," + this.props.cancel : ""),
407
- scale: this.props.transformScale,
408
- nodeRef: this.elementRef
409
- }, child);
410
- }
411
-
412
- /**
413
- * Utility function to setup callback handler definitions for
414
- * similarily structured resize events.
415
- */
416
- curryResizeHandler(position /*: Position*/, handler /*: Function*/) /*: Function*/{
417
- return (e /*: Event*/, data /*: ResizeCallbackData*/) => /*: Function*/handler(e, data, position);
418
- }
419
-
420
- /**
421
- * Mix a Resizable instance into a child.
422
- * @param {Element} child Child element.
423
- * @param {Object} position Position object (pixel values)
424
- * @return {Element} Child wrapped in Resizable.
425
- */
426
- mixinResizable(child /*: ReactElement<any>*/, position /*: Position*/, isResizable /*: boolean*/) /*: ReactElement<any>*/{
427
- const {
428
- cols,
429
- minW,
430
- minH,
431
- maxW,
432
- maxH,
433
- transformScale,
434
- resizeHandles,
435
- resizeHandle
436
- } = this.props;
437
- const positionParams = this.getPositionParams();
438
-
439
- // This is the max possible width - doesn't go to infinity because of the width of the window
440
- const maxWidth = (0, _calculateUtils.calcGridItemPosition)(positionParams, 0, 0, cols, 0).width;
441
-
442
- // Calculate min/max constraints using our min & maxes
443
- const mins = (0, _calculateUtils.calcGridItemPosition)(positionParams, 0, 0, minW, minH);
444
- const maxes = (0, _calculateUtils.calcGridItemPosition)(positionParams, 0, 0, maxW, maxH);
445
- const minConstraints = [mins.width, mins.height];
446
- const maxConstraints = [Math.min(maxes.width, maxWidth), Math.min(maxes.height, Infinity)];
447
- return /*#__PURE__*/_react.default.createElement(_reactResizable.Resizable
448
- // These are opts for the resize handle itself
449
- , {
450
- draggableOpts: {
451
- disabled: !isResizable
452
- },
453
- className: isResizable ? undefined : "react-resizable-hide",
454
- width: position.width,
455
- height: position.height,
456
- minConstraints: minConstraints,
457
- maxConstraints: maxConstraints,
458
- onResizeStop: this.curryResizeHandler(position, this.onResizeStop),
459
- onResizeStart: this.curryResizeHandler(position, this.onResizeStart),
460
- onResize: this.curryResizeHandler(position, this.onResize),
461
- transformScale: transformScale,
462
- resizeHandles: resizeHandles,
463
- handle: resizeHandle
464
- }, child);
465
- }
466
- /**
467
- * Wrapper around resize events to provide more useful data.
468
- */
469
- onResizeHandler(e /*: Event*/, _ref4 /*:: */,
470
- // 'size' is updated position
471
- position /*: Position*/,
472
- // existing position
473
- handlerName /*: string*/) /*: void*/{
474
- let {
475
- node,
476
- size,
477
- handle
478
- } /*: ResizeCallbackData*/ = _ref4 /*: ResizeCallbackData*/;
479
- const handler = this.props[handlerName];
480
- if (!handler) return;
481
- const {
482
- x,
483
- y,
484
- i,
485
- maxH,
486
- minH,
487
- containerWidth
488
- } = this.props;
489
- const {
490
- minW,
491
- maxW
492
- } = this.props;
493
-
494
- // Clamping of dimensions based on resize direction
495
- let updatedSize = size;
496
- if (node) {
497
- updatedSize = (0, _utils.resizeItemInDirection)(handle, position, size, containerWidth);
498
- (0, _reactDom.flushSync)(() => {
499
- this.setState({
500
- resizing: handlerName === "onResizeStop" ? null : updatedSize
501
- });
502
- });
503
- }
504
-
505
- // Get new XY based on pixel size
506
- let {
507
- w,
508
- h
509
- } = (0, _calculateUtils.calcWH)(this.getPositionParams(), updatedSize.width, updatedSize.height, x, y, handle);
510
-
511
- // Min/max capping.
512
- // minW should be at least 1 (TODO propTypes validation?)
513
- w = (0, _calculateUtils.clamp)(w, Math.max(minW, 1), maxW);
514
- h = (0, _calculateUtils.clamp)(h, minH, maxH);
515
- handler.call(this, i, w, h, {
516
- e,
517
- node,
518
- size: updatedSize,
519
- handle
520
- });
521
- }
522
- render() /*: ReactNode*/{
523
- const {
524
- x,
525
- y,
526
- w,
527
- h,
528
- isDraggable,
529
- isResizable,
530
- droppingPosition,
531
- useCSSTransforms
532
- } = this.props;
533
- const pos = (0, _calculateUtils.calcGridItemPosition)(this.getPositionParams(), x, y, w, h, this.state);
534
- const child = _react.default.Children.only(this.props.children);
535
-
536
- // Create the child element. We clone the existing element but modify its className and style.
537
- let newChild = /*#__PURE__*/_react.default.cloneElement(child, {
538
- ref: this.elementRef,
539
- className: (0, _clsx.default)("react-grid-item", child.props.className, this.props.className, {
540
- static: this.props.static,
541
- resizing: Boolean(this.state.resizing),
542
- "react-draggable": isDraggable,
543
- "react-draggable-dragging": Boolean(this.state.dragging),
544
- dropping: Boolean(droppingPosition),
545
- cssTransforms: useCSSTransforms
546
- }),
547
- // We can set the width and height on the child, but unfortunately we can't set the position.
548
- style: _objectSpread(_objectSpread(_objectSpread({}, this.props.style), child.props.style), this.createStyle(pos))
549
- });
550
-
551
- // Resizable support. This is usually on but the user can toggle it off.
552
- newChild = this.mixinResizable(newChild, pos, isResizable);
553
-
554
- // Draggable support. This is always on, except for with placeholders.
555
- newChild = this.mixinDraggable(newChild, isDraggable);
556
- return newChild;
557
- }
558
- }
559
- exports.default = GridItem;
560
- _defineProperty(GridItem, "propTypes", {
561
- // Children must be only a single element
562
- children: _propTypes.default.element,
563
- // General grid attributes
564
- cols: _propTypes.default.number.isRequired,
565
- containerWidth: _propTypes.default.number.isRequired,
566
- rowHeight: _propTypes.default.number.isRequired,
567
- margin: _propTypes.default.array.isRequired,
568
- maxRows: _propTypes.default.number.isRequired,
569
- containerPadding: _propTypes.default.array.isRequired,
570
- // These are all in grid units
571
- x: _propTypes.default.number.isRequired,
572
- y: _propTypes.default.number.isRequired,
573
- w: _propTypes.default.number.isRequired,
574
- h: _propTypes.default.number.isRequired,
575
- // All optional
576
- minW: function (props /*: Props*/, propName /*: string*/) {
577
- const value = props[propName];
578
- if (typeof value !== "number") return new Error("minWidth not Number");
579
- if (value > props.w || value > props.maxW) return new Error("minWidth larger than item width/maxWidth");
580
- },
581
- maxW: function (props /*: Props*/, propName /*: string*/) {
582
- const value = props[propName];
583
- if (typeof value !== "number") return new Error("maxWidth not Number");
584
- if (value < props.w || value < props.minW) return new Error("maxWidth smaller than item width/minWidth");
585
- },
586
- minH: function (props /*: Props*/, propName /*: string*/) {
587
- const value = props[propName];
588
- if (typeof value !== "number") return new Error("minHeight not Number");
589
- if (value > props.h || value > props.maxH) return new Error("minHeight larger than item height/maxHeight");
590
- },
591
- maxH: function (props /*: Props*/, propName /*: string*/) {
592
- const value = props[propName];
593
- if (typeof value !== "number") return new Error("maxHeight not Number");
594
- if (value < props.h || value < props.minH) return new Error("maxHeight smaller than item height/minHeight");
595
- },
596
- // ID is nice to have for callbacks
597
- i: _propTypes.default.string.isRequired,
598
- // Resize handle options
599
- resizeHandles: _ReactGridLayoutPropTypes.resizeHandleAxesType,
600
- resizeHandle: _ReactGridLayoutPropTypes.resizeHandleType,
601
- // Functions
602
- onDragStop: _propTypes.default.func,
603
- onDragStart: _propTypes.default.func,
604
- onDrag: _propTypes.default.func,
605
- onResizeStop: _propTypes.default.func,
606
- onResizeStart: _propTypes.default.func,
607
- onResize: _propTypes.default.func,
608
- // Flags
609
- isDraggable: _propTypes.default.bool.isRequired,
610
- isResizable: _propTypes.default.bool.isRequired,
611
- isBounded: _propTypes.default.bool.isRequired,
612
- static: _propTypes.default.bool,
613
- // Use CSS transforms instead of top/left
614
- useCSSTransforms: _propTypes.default.bool.isRequired,
615
- transformScale: _propTypes.default.number,
616
- // Others
617
- className: _propTypes.default.string,
618
- // Selector for draggable handle
619
- handle: _propTypes.default.string,
620
- // Selector for draggable cancel (see react-draggable)
621
- cancel: _propTypes.default.string,
622
- // Current position of a dropping element
623
- droppingPosition: _propTypes.default.shape({
624
- e: _propTypes.default.object.isRequired,
625
- left: _propTypes.default.number.isRequired,
626
- top: _propTypes.default.number.isRequired
627
- })
628
- });
629
- _defineProperty(GridItem, "defaultProps", {
630
- className: "",
631
- cancel: "",
632
- handle: "",
633
- minH: 1,
634
- minW: 1,
635
- maxH: Infinity,
636
- maxW: Infinity,
637
- transformScale: 1
638
- });