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