@m4l/components 0.1.76 → 0.1.77

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 (112) hide show
  1. package/@types/export.d.ts +19 -0
  2. package/components/AccountPopover/{index.47cf6c43.js → index.3a79c395.js} +7 -6
  3. package/components/AppBar/{index.f04f5e45.js → index.71b38ee9.js} +7 -6
  4. package/components/CommonActions/components/ActionCancel/{index.453c2d24.js → index.b748a38e.js} +2 -2
  5. package/components/CommonActions/components/ActionFormCancel/{index.c2a2fd55.js → index.27ad09e1.js} +18 -18
  6. package/components/CommonActions/components/ActionFormIntro/{index.25d33912.js → index.2556f054.js} +2 -2
  7. package/components/CommonActions/components/ActionIntro/{index.c653a266.js → index.a7d92e66.js} +2 -2
  8. package/components/CommonActions/components/Actions/{index.e376a68e.js → index.3eba9d91.js} +16 -17
  9. package/components/DataGrid/{index.ffaf000e.js → index.545b492f.js} +42 -30
  10. package/components/DataGrid/types.d.ts +5 -1
  11. package/components/DraggableWindow/{index.b08af1dc.js → index.c702d3f2.js} +1 -1
  12. package/components/DynamicFilter/{index.d7c03a61.js → index.d7be0f37.js} +40 -33
  13. package/components/DynamicFilter/subcomponents/InnerForHooks/index.d.ts +2 -1
  14. package/components/DynamicFilter/subcomponents/InnerForHooks/types.d.ts +2 -0
  15. package/components/DynamicFilter/tests/contants.d.ts +1 -1
  16. package/components/DynamicFilter/types.d.ts +4 -0
  17. package/components/GridLayout/GridLayout.d.ts +6 -0
  18. package/components/GridLayout/Responsive/index.a12a8cec.js +335 -0
  19. package/components/GridLayout/WidthProvider/index.8ff65909.js +67 -0
  20. package/components/GridLayout/calculateUtils.d.ts +42 -0
  21. package/components/GridLayout/index.4ba3767a.js +1400 -0
  22. package/components/GridLayout/index.d.ts +6 -0
  23. package/components/GridLayout/subcomponents/GridItem/index.d.ts +25 -0
  24. package/components/GridLayout/subcomponents/GridItem/types.d.ts +76 -0
  25. package/components/GridLayout/subcomponents/Responsive/index.d.ts +3 -0
  26. package/components/GridLayout/subcomponents/Responsive/responsiveUtils.d.ts +61 -0
  27. package/components/GridLayout/subcomponents/Responsive/types.d.ts +71 -0
  28. package/components/GridLayout/subcomponents/WidthProvider/index.d.ts +16 -0
  29. package/components/GridLayout/types.d.ts +355 -0
  30. package/components/GridLayout/utils.d.ts +123 -0
  31. package/components/HelperText/{index.9864f773.js → index.ef31df1f.js} +7 -6
  32. package/components/Icon/{index.9dae8337.js → index.ecb63e65.js} +1 -1
  33. package/components/LanguagePopover/{index.938c6675.js → index.0023d069.js} +7 -6
  34. package/components/LinearProgressIndeterminate/{index.d34d398f.js → index.60dabc06.js} +1 -1
  35. package/components/ModalDialog/{index.d9c5d400.js → index.d880e685.js} +8 -56
  36. package/components/NavLink/{index.21c8fd90.js → index.cd92eceb.js} +7 -6
  37. package/components/ObjectLogs/{index.a2709fc2.js → index.f174c542.js} +19 -19
  38. package/components/PaperForm/{index.5e1bc99f.js → index.1bd86ee5.js} +1 -1
  39. package/components/Period/{index.526791a3.js → index.711db043.js} +21 -22
  40. package/components/Resizeable/{index.f6e48e56.js → index.9a9c79a4.js} +1 -1
  41. package/components/SideBar/{index.9e1a5b96.js → index.c5ce0bad.js} +5 -5
  42. package/components/areas/components/AreasAdmin/classes/index.d.ts +1 -1
  43. package/components/areas/components/AreasAdmin/classes/types.d.ts +2 -0
  44. package/components/areas/components/AreasAdmin/{index.946eebb9.js → index.cc4cbf56.js} +120 -46
  45. package/components/areas/components/AreasAdmin/subcomponents/AreaChip/types.d.ts +0 -1
  46. package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/index.d.ts +3 -0
  47. package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/types.d.ts +3 -0
  48. package/components/areas/components/AreasViewer/classes/index.d.ts +1 -1
  49. package/components/areas/components/AreasViewer/classes/types.d.ts +2 -0
  50. package/components/areas/components/AreasViewer/{index.bf4191ea.js → index.9c2aaaeb.js} +258 -259
  51. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/index.d.ts +1 -1
  52. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/index.d.ts +2 -2
  53. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/index.d.ts +1 -7
  54. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/index.d.ts +3 -0
  55. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/types.d.ts +2 -0
  56. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/types.d.ts +6 -0
  57. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/types.d.ts +1 -1
  58. package/components/areas/components/{index.2bb534cb.js → index.0f7ac464.js} +11 -10
  59. package/components/areas/contexts/AreasContext/helper.d.ts +6 -16
  60. package/components/areas/contexts/AreasContext/{index.f0397b7c.js → index.c8147e8e.js} +244 -339
  61. package/components/areas/contexts/AreasContext/types.d.ts +23 -20
  62. package/components/areas/contexts/{index.1809650a.js → index.02336412.js} +1 -1
  63. package/components/areas/{dictionary.3fabae50.js → dictionary.afb7e3d9.js} +5 -2
  64. package/components/areas/dictionary.d.ts +4 -1
  65. package/components/areas/hooks/useAreas/{index.40917e99.js → index.3406a6cb.js} +1 -1
  66. package/components/areas/{icons.19cde4b4.js → icons.8266ccc8.js} +5 -1
  67. package/components/areas/icons.d.ts +4 -0
  68. package/components/areas/{index.9bd48013.js → index.6f2e5dab.js} +11 -10
  69. package/components/areas/types.d.ts +30 -22
  70. package/components/formatters/BooleanFormatter/{index.431dc923.js → index.5268b024.js} +1 -1
  71. package/components/formatters/{index.e1af75e6.js → index.137169d8.js} +2 -2
  72. package/components/hook-form/RHFAutocomplete/{index.a063dc44.js → index.ac2b1fae.js} +8 -7
  73. package/components/hook-form/RHFAutocompleteAsync/{index.ddfd9cc9.js → index.8b4ccc8d.js} +1 -1
  74. package/components/hook-form/RHFCheckbox/{index.7e7f220b.js → index.acef119c.js} +1 -1
  75. package/components/hook-form/RHFDateTime/{index.d330709b.js → index.5b080342.js} +9 -8
  76. package/components/hook-form/RHFPeriod/{index.e2b1293b.js → index.5304e3bd.js} +2 -2
  77. package/components/hook-form/RHFTextField/{index.e5336d09.js → index.e751dca7.js} +5 -5
  78. package/components/hook-form/RHFUpload/{index.17e7f9eb.js → index.25db0511.js} +8 -7
  79. package/components/index.d.ts +1 -0
  80. package/components/modal/{WindowBase.7acb9f1d.js → WindowBase.850ea31a.js} +9 -8
  81. package/components/modal/{WindowConfirm.9b829837.js → WindowConfirm.cb37bc58.js} +18 -18
  82. package/components/modal/classes/index.d.ts +1 -0
  83. package/components/modal/classes/types.d.ts +1 -0
  84. package/components/modal/{index.1b25b61d.js → index.a0978193.js} +18 -16
  85. package/components/mui_extended/Accordion/{index.3faafd8b.js → index.12b1339a.js} +2 -2
  86. package/components/mui_extended/Badge/Badge.d.ts +3 -0
  87. package/components/mui_extended/Badge/classes/constants.d.ts +1 -0
  88. package/components/mui_extended/Badge/classes/index.d.ts +6 -0
  89. package/components/mui_extended/Badge/classes/types.d.ts +6 -0
  90. package/components/mui_extended/Badge/index.8c2b8b66.js +36 -0
  91. package/components/mui_extended/Badge/index.d.ts +2 -0
  92. package/components/mui_extended/Badge/tests/constants.d.ts +1 -0
  93. package/components/mui_extended/Badge/tests/utils.d.ts +2 -0
  94. package/components/mui_extended/Badge/types.d.ts +4 -0
  95. package/components/mui_extended/Button/{index.fdb5dcbd.js → index.4288f9fc.js} +8 -3
  96. package/components/mui_extended/IconButton/{index.1a9d4fa5.js → index.fc5b7c2d.js} +1 -1
  97. package/components/mui_extended/MenuActions/{index.ba1da3b3.js → index.f5b1c022.js} +28 -9
  98. package/components/mui_extended/MenuActions/types.d.ts +8 -0
  99. package/components/mui_extended/Pager/{index.67bda2c5.js → index.435af0df.js} +1 -1
  100. package/components/mui_extended/{index.73e536de.js → index.83979b6a.js} +7 -6
  101. package/components/mui_extended/index.d.ts +1 -0
  102. package/contexts/ModalContext/{index.699f95fa.js → index.dee85a61.js} +1 -1
  103. package/hooks/useModal/{index.7b7d26ba.js → index.de522a10.js} +1 -1
  104. package/index.js +94 -83
  105. package/node_modules.d73a220d.js +363 -0
  106. package/package.json +4 -3
  107. package/{react-draggable.6d7949a3.js → react-draggable.7abb5d0a.js} +3 -2
  108. package/{react-resizable.b6f8e04a.js → react-resizable.ba08699a.js} +13 -12
  109. package/utils/{index.008b4c2a.js → index.c43a95f4.js} +0 -15
  110. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/WindowPopUp/index.d.ts +0 -4
  111. package/components/modal/ModalDialog/types.d.ts +0 -7
  112. /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/types.d.ts +0 -0
@@ -0,0 +1,1400 @@
1
+ import React__default, { useRef, useEffect, useState, useCallback, useMemo } from "react";
2
+ import { d as deepEqual } from "../../node_modules.d73a220d.js";
3
+ import clsx from "clsx";
4
+ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
5
+ import { D as DraggableCore_1 } from "../../react-draggable.7abb5d0a.js";
6
+ import { R as Resizable, r as react_resizable_css } from "../../react-resizable.ba08699a.js";
7
+ import { styled } from "@mui/material/styles";
8
+ import "@m4l/graphics";
9
+ import "lodash";
10
+ const noop = () => {
11
+ };
12
+ function bottom(layout, colapsedHeight) {
13
+ let max = 0, bottomY;
14
+ for (let i = 0, len = layout.length; i < len; i++) {
15
+ bottomY = layout[i].y + getLayoutItemH(layout[i], colapsedHeight);
16
+ if (bottomY > max)
17
+ max = bottomY;
18
+ }
19
+ return max;
20
+ }
21
+ function cloneLayoutItem(layoutItem, layoutItemReplaceProps) {
22
+ return {
23
+ w: layoutItem.w,
24
+ h: layoutItem.h,
25
+ x: layoutItem.x,
26
+ y: layoutItem.y,
27
+ i: layoutItem.i,
28
+ minW: layoutItem.minW,
29
+ maxW: layoutItem.maxW,
30
+ minH: layoutItem.minH,
31
+ maxH: layoutItem.maxH,
32
+ moved: Boolean(layoutItem.moved),
33
+ static: Boolean(layoutItem.static),
34
+ isDraggable: layoutItem.isDraggable,
35
+ isResizable: layoutItem.isResizable,
36
+ resizeHandles: layoutItem.resizeHandles,
37
+ isBounded: layoutItem.isBounded,
38
+ freeMove: layoutItem.freeMove,
39
+ colapsed: layoutItem.colapsed,
40
+ ...layoutItemReplaceProps
41
+ };
42
+ }
43
+ function cloneLayout(layout, layoutItemReplaceProps) {
44
+ console.log("cloneLayout");
45
+ const newLayout = Array(layout.length);
46
+ for (let i = 0, len = layout.length; i < len; i++) {
47
+ newLayout[i] = cloneLayoutItem(layout[i], layoutItemReplaceProps);
48
+ }
49
+ return newLayout;
50
+ }
51
+ function collides(l1, l2, colapsedHeight) {
52
+ if (l1.i === l2.i)
53
+ return false;
54
+ if (l1.x + l1.w <= l2.x)
55
+ return false;
56
+ if (l1.x >= l2.x + l2.w)
57
+ return false;
58
+ if (l1.y + getLayoutItemH(l1, colapsedHeight) <= l2.y)
59
+ return false;
60
+ if (l1.y >= l2.y + getLayoutItemH(l2, colapsedHeight))
61
+ return false;
62
+ return true;
63
+ }
64
+ function compactItem(compareWith, l, compactType, cols, fullLayout, colapsedHeight, allowOverlap) {
65
+ const compactV = compactType === "vertical";
66
+ const compactH = compactType === "horizontal";
67
+ if (compactV) {
68
+ l.y = Math.min(bottom(compareWith, colapsedHeight), l.y);
69
+ while (l.y > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
70
+ l.y--;
71
+ }
72
+ } else if (compactH) {
73
+ while (l.x > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
74
+ l.x--;
75
+ }
76
+ }
77
+ let collidesItem;
78
+ while ((collidesItem = getFirstCollision(compareWith, l, colapsedHeight)) && !(compactType === null && allowOverlap)) {
79
+ if (compactH) {
80
+ resolveCompactionCollision(
81
+ fullLayout,
82
+ l,
83
+ collidesItem.x + collidesItem.w,
84
+ "x",
85
+ colapsedHeight
86
+ );
87
+ } else {
88
+ resolveCompactionCollision(
89
+ fullLayout,
90
+ l,
91
+ collidesItem.y + getLayoutItemH(collidesItem, colapsedHeight),
92
+ "y",
93
+ colapsedHeight
94
+ );
95
+ }
96
+ if (compactH && l.x + l.w > cols) {
97
+ l.x = cols - l.w;
98
+ l.y++;
99
+ while (l.x > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
100
+ l.x--;
101
+ }
102
+ }
103
+ }
104
+ l.y = Math.max(l.y, 0);
105
+ l.x = Math.max(l.x, 0);
106
+ return l;
107
+ }
108
+ function compact(layout, compactType, cols, colapsedHeight, allowOverlap) {
109
+ const layoutToCompact = layout.filter((l) => !l.freeMove);
110
+ const layoutFreeMov = layout.filter((l) => l?.freeMove);
111
+ console.log(`Compacting`, layoutToCompact, layoutFreeMov);
112
+ const compareWith = getStatics(layoutToCompact);
113
+ const sorted = sortLayoutItems(layoutToCompact, compactType);
114
+ const out = Array(layoutToCompact.length);
115
+ for (let i = 0, len = sorted.length; i < len; i++) {
116
+ let l = cloneLayoutItem(sorted[i]);
117
+ if (!l.static) {
118
+ l = compactItem(
119
+ compareWith,
120
+ l,
121
+ compactType,
122
+ cols,
123
+ sorted,
124
+ colapsedHeight,
125
+ allowOverlap
126
+ );
127
+ compareWith.push(l);
128
+ }
129
+ out[layoutToCompact.indexOf(sorted[i])] = l;
130
+ l.moved = false;
131
+ }
132
+ return out.concat(layoutFreeMov);
133
+ }
134
+ function getLayoutItem(layout, id) {
135
+ for (let i = 0, len = layout.length; i < len; i++) {
136
+ if (layout[i].i === id)
137
+ return layout[i];
138
+ }
139
+ return void 0;
140
+ }
141
+ function getStatics(layout) {
142
+ return layout.filter((l) => l.static);
143
+ }
144
+ function getAllCollisions(layout, layoutItem, colapsedHeight) {
145
+ return layout.filter((l) => collides(l, layoutItem, colapsedHeight));
146
+ }
147
+ function getFirstCollision(layout, layoutItem, colapsedHeight) {
148
+ for (let i = 0, len = layout.length; i < len; i++) {
149
+ if (collides(layout[i], layoutItem, colapsedHeight))
150
+ return layout[i];
151
+ }
152
+ return void 0;
153
+ }
154
+ function modifyLayout(layout, layoutItem) {
155
+ const newLayout = Array(layout.length);
156
+ for (let i = 0, len = layout.length; i < len; i++) {
157
+ if (layoutItem.i === layout[i].i) {
158
+ newLayout[i] = layoutItem;
159
+ } else {
160
+ newLayout[i] = layout[i];
161
+ }
162
+ }
163
+ return newLayout;
164
+ }
165
+ function moveElementAwayFromCollision(layout, collidesWith, itemToMove, isUserAction, compactType, cols, colapsedHeight) {
166
+ const compactH = compactType === "horizontal";
167
+ const compactV = compactType !== "horizontal";
168
+ const preventCollision = collidesWith.static;
169
+ if (isUserAction) {
170
+ isUserAction = false;
171
+ const fakeItem = {
172
+ x: compactH ? Math.max(collidesWith.x - itemToMove.w, 0) : itemToMove.x,
173
+ y: compactV ? Math.max(collidesWith.y - getLayoutItemH(itemToMove, colapsedHeight), 0) : itemToMove.y,
174
+ w: itemToMove.w,
175
+ h: getLayoutItemH(itemToMove, colapsedHeight),
176
+ i: "-1"
177
+ };
178
+ if (!getFirstCollision(layout, fakeItem, colapsedHeight)) {
179
+ return moveElement(
180
+ layout,
181
+ itemToMove,
182
+ compactH ? fakeItem.x : void 0,
183
+ compactV ? fakeItem.y : void 0,
184
+ isUserAction,
185
+ !!preventCollision,
186
+ compactType,
187
+ cols,
188
+ colapsedHeight,
189
+ false
190
+ );
191
+ }
192
+ }
193
+ return moveElement(
194
+ layout,
195
+ itemToMove,
196
+ compactH ? itemToMove.x + 1 : void 0,
197
+ compactV ? itemToMove.y + 1 : void 0,
198
+ isUserAction,
199
+ !!preventCollision,
200
+ compactType,
201
+ cols,
202
+ colapsedHeight,
203
+ false
204
+ );
205
+ }
206
+ function moveElement(layout, l, x, y, isUserAction, preventCollision, compactType, cols, colapsedHeight, allowOverlap) {
207
+ if (l.static && l.isDraggable !== true)
208
+ return layout;
209
+ if (l.y === y && l.x === x)
210
+ return layout;
211
+ const oldX = l.x;
212
+ const oldY = l.y;
213
+ if (typeof x === "number")
214
+ l.x = x;
215
+ if (typeof y === "number")
216
+ l.y = y;
217
+ l.moved = true;
218
+ let sorted = sortLayoutItems(layout, compactType);
219
+ const movingUp = compactType === "vertical" && typeof y === "number" ? oldY >= y : compactType === "horizontal" && typeof x === "number" ? oldX >= x : false;
220
+ if (movingUp)
221
+ sorted = sorted.reverse();
222
+ const collisions = getAllCollisions(sorted, l, colapsedHeight);
223
+ const hasCollisions = collisions.length > 0;
224
+ if (hasCollisions && allowOverlap) {
225
+ return cloneLayout(layout);
226
+ } else if (hasCollisions && preventCollision) {
227
+ l.x = oldX;
228
+ l.y = oldY;
229
+ l.moved = false;
230
+ return layout;
231
+ }
232
+ for (let i = 0, len = collisions.length; i < len; i++) {
233
+ const collision = collisions[i];
234
+ if (collision.moved)
235
+ continue;
236
+ if (collision.static) {
237
+ layout = moveElementAwayFromCollision(
238
+ layout,
239
+ collision,
240
+ l,
241
+ isUserAction,
242
+ compactType,
243
+ cols,
244
+ colapsedHeight
245
+ );
246
+ } else {
247
+ layout = moveElementAwayFromCollision(
248
+ layout,
249
+ l,
250
+ collision,
251
+ isUserAction,
252
+ compactType,
253
+ cols,
254
+ colapsedHeight
255
+ );
256
+ }
257
+ }
258
+ return layout;
259
+ }
260
+ function perc(num) {
261
+ return num * 100 + "%";
262
+ }
263
+ function resolveCompactionCollision(layout, item, moveToCoord, axis, colapsedHeight) {
264
+ item[axis] += 1;
265
+ const itemIndex = layout.map((layoutItem) => {
266
+ return layoutItem.i;
267
+ }).indexOf(item.i);
268
+ for (let i = itemIndex + 1; i < layout.length; i++) {
269
+ const otherItem = layout[i];
270
+ if (otherItem.static)
271
+ continue;
272
+ if (otherItem.y > item.y + getLayoutItemH(item, colapsedHeight))
273
+ break;
274
+ if (collides(item, otherItem, colapsedHeight)) {
275
+ resolveCompactionCollision(
276
+ layout,
277
+ otherItem,
278
+ moveToCoord + (axis === "x" ? item.w : getLayoutItemH(item, colapsedHeight)),
279
+ axis,
280
+ colapsedHeight
281
+ );
282
+ }
283
+ }
284
+ item[axis] = moveToCoord;
285
+ }
286
+ function setTransform({ top, left, width, height }) {
287
+ const translate = `translate(${left}px,${top}px)`;
288
+ return {
289
+ transform: translate,
290
+ WebkitTransform: translate,
291
+ MozTransform: translate,
292
+ msTransform: translate,
293
+ OTransform: translate,
294
+ width: `${width}px`,
295
+ height: `${height}px`,
296
+ position: "absolute"
297
+ };
298
+ }
299
+ function setTopLeft({ top, left, width, height }) {
300
+ return {
301
+ top: `${top}px`,
302
+ left: `${left}px`,
303
+ width: `${width}px`,
304
+ height: `${height}px`,
305
+ position: "absolute"
306
+ };
307
+ }
308
+ function sortLayoutItemsByRowCol(layout) {
309
+ return layout.slice(0).sort(function(a, b) {
310
+ if (a.y > b.y || a.y === b.y && a.x > b.x) {
311
+ return 1;
312
+ } else if (a.y === b.y && a.x === b.x) {
313
+ return 0;
314
+ }
315
+ return -1;
316
+ });
317
+ }
318
+ function sortLayoutItemsByColRow(layout) {
319
+ return layout.slice(0).sort(function(a, b) {
320
+ if (a.x > b.x || a.x === b.x && a.y > b.y) {
321
+ return 1;
322
+ }
323
+ return -1;
324
+ });
325
+ }
326
+ function sortLayoutItems(layout, compactType) {
327
+ if (compactType === "horizontal")
328
+ return sortLayoutItemsByColRow(layout);
329
+ if (compactType === "vertical")
330
+ return sortLayoutItemsByRowCol(layout);
331
+ else
332
+ return layout;
333
+ }
334
+ function withLayoutItem(layout, itemKey, cb) {
335
+ let item = getLayoutItem(layout, itemKey);
336
+ if (!item)
337
+ return [layout, void 0];
338
+ item = cb(cloneLayoutItem(item));
339
+ layout = modifyLayout(layout, item);
340
+ return [layout, item];
341
+ }
342
+ function correctBounds(layout, bounds, colapsedHeight) {
343
+ const collidesWith = getStatics(layout);
344
+ for (let i = 0, len = layout.length; i < len; i++) {
345
+ const l = layout[i];
346
+ if (l.x + l.w > bounds.cols)
347
+ l.x = bounds.cols - l.w;
348
+ if (l.x < 0) {
349
+ l.x = 0;
350
+ l.w = bounds.cols;
351
+ }
352
+ if (!l.static)
353
+ collidesWith.push(l);
354
+ else {
355
+ while (getFirstCollision(collidesWith, l, colapsedHeight)) {
356
+ l.y++;
357
+ }
358
+ }
359
+ }
360
+ return layout;
361
+ }
362
+ function getH(h, colapsedHeight, colapsed) {
363
+ if (colapsed) {
364
+ return colapsedHeight;
365
+ }
366
+ return h;
367
+ }
368
+ function getLayoutItemH(layoutItem, colapsedHeight) {
369
+ return getH(layoutItem.h, colapsedHeight, layoutItem.colapsed);
370
+ }
371
+ function calcGridColWidth(positionParams) {
372
+ const { containerMargin: margin, containerPadding, containerWidth, cols } = positionParams;
373
+ return (containerWidth - margin[0] * (cols - 1) - containerPadding[0] * 2) / cols;
374
+ }
375
+ function calcGridItemWHPx(gridUnits, colOrRowSize, marginPx) {
376
+ if (!Number.isFinite(gridUnits))
377
+ return gridUnits;
378
+ return Math.round(colOrRowSize * gridUnits + Math.max(0, gridUnits - 1) * marginPx);
379
+ }
380
+ function calcGridItemPosition(positionParams, x, y, w, h, maximize, state) {
381
+ const {
382
+ containerMargin,
383
+ containerPadding,
384
+ rowHeight
385
+ } = positionParams;
386
+ const colWidth = calcGridColWidth(positionParams);
387
+ const out = {};
388
+ if (state && state.resizing) {
389
+ out.width = Math.round(state.resizing.width);
390
+ out.height = Math.round(state.resizing.height);
391
+ } else {
392
+ if (maximize === "maximize_me") {
393
+ out.width = positionParams.containerWidth - 2 * containerPadding[0] - 2;
394
+ out.height = positionParams.containerHeight - 2 * containerPadding[1] - 2;
395
+ console.log(
396
+ "calcGridItemPosition top,left",
397
+ out,
398
+ maximize,
399
+ positionParams.containerHeight
400
+ );
401
+ } else {
402
+ console.log(
403
+ "calcGridItemPosition top,left",
404
+ out,
405
+ maximize,
406
+ containerMargin,
407
+ positionParams.containerHeight
408
+ );
409
+ out.width = calcGridItemWHPx(w, colWidth, containerMargin[0]);
410
+ out.height = calcGridItemWHPx(h, rowHeight, containerMargin[1]);
411
+ }
412
+ }
413
+ if (state && state.dragging) {
414
+ out.top = Math.round(state.dragging.top);
415
+ out.left = Math.round(state.dragging.left);
416
+ } else {
417
+ if (maximize === "maximize_me") {
418
+ out.left = containerPadding[0];
419
+ out.top = containerPadding[1];
420
+ } else {
421
+ out.left = Math.round((colWidth + containerMargin[0]) * x + containerPadding[0]);
422
+ out.top = Math.round((rowHeight + containerMargin[1]) * y + containerPadding[1]);
423
+ }
424
+ }
425
+ return out;
426
+ }
427
+ function calcXY(positionParams, top, left, w, h) {
428
+ const { containerMargin: margin, cols, rowHeight, maxRows } = positionParams;
429
+ const colWidth = calcGridColWidth(positionParams);
430
+ let x = Math.round((left - margin[0]) / (colWidth + margin[0]));
431
+ let y = Math.round((top - margin[1]) / (rowHeight + margin[1]));
432
+ x = clamp(x, 0, cols - w);
433
+ y = clamp(y, 0, maxRows - h);
434
+ return { x, y };
435
+ }
436
+ function calcWH(positionParams, width, height, x, y) {
437
+ const { containerMargin: margin, maxRows, cols, rowHeight } = positionParams;
438
+ const colWidth = calcGridColWidth(positionParams);
439
+ let w = Math.round((width + margin[0]) / (colWidth + margin[0]));
440
+ let h = Math.round((height + margin[1]) / (rowHeight + margin[1]));
441
+ w = clamp(w, 0, cols - x);
442
+ h = clamp(h, 0, maxRows - y);
443
+ return { w, h };
444
+ }
445
+ function clamp(num, lowerBound, upperBound) {
446
+ return Math.max(Math.min(num, upperBound), lowerBound);
447
+ }
448
+ function GridItem(props) {
449
+ const {
450
+ type,
451
+ i,
452
+ x,
453
+ y,
454
+ w,
455
+ h,
456
+ cols,
457
+ isBounded,
458
+ margin,
459
+ maxRows,
460
+ rowHeight,
461
+ containerWidth,
462
+ containerHeight,
463
+ containerPadding,
464
+ className = "",
465
+ cancel = "",
466
+ handle = "",
467
+ minH = 1,
468
+ minW = 1,
469
+ maxH = Infinity,
470
+ maxW = Infinity,
471
+ isResizable,
472
+ isDraggable,
473
+ onDragStart,
474
+ onDrag,
475
+ onDragStop,
476
+ onFreeMoveClick,
477
+ layoutItemRender: ComponentItemRender,
478
+ resizeHandles,
479
+ resizeHandle,
480
+ transformScale = 1,
481
+ useCSSTransforms = true,
482
+ usePercentages,
483
+ style,
484
+ freeMove,
485
+ maximize = "none",
486
+ colapsed,
487
+ colapsedHeight = 1.5
488
+ } = props;
489
+ const refProps = useRef({
490
+ cols,
491
+ x,
492
+ y,
493
+ w,
494
+ h: getH(h, colapsedHeight, colapsed),
495
+ minW,
496
+ maxW,
497
+ minH,
498
+ maxH,
499
+ containerWidth,
500
+ containerHeight,
501
+ margin,
502
+ containerPadding,
503
+ rowHeight,
504
+ maxRows,
505
+ colapsed
506
+ });
507
+ useEffect(() => {
508
+ refProps.current = {
509
+ cols,
510
+ x,
511
+ y,
512
+ w,
513
+ h: getH(h, colapsedHeight, colapsed),
514
+ minW,
515
+ maxW,
516
+ minH,
517
+ maxH,
518
+ containerWidth,
519
+ containerHeight,
520
+ margin,
521
+ containerPadding,
522
+ rowHeight,
523
+ maxRows,
524
+ colapsed
525
+ };
526
+ }, [cols, x, y, w, h, minW, maxW, minH, maxH, containerWidth, containerHeight, margin, containerPadding, rowHeight, maxRows, colapsed, colapsedHeight]);
527
+ const [currentState, setCurrentState] = useState({
528
+ resizing: void 0,
529
+ dragging: void 0,
530
+ className: ""
531
+ });
532
+ const refState = useRef({
533
+ resizing: void 0,
534
+ dragging: void 0,
535
+ className: ""
536
+ });
537
+ const elementRef = useRef(null);
538
+ const getPositionParams = useCallback((preferContainerWidth, preferContainerHeight) => {
539
+ return {
540
+ cols: refProps.current.cols,
541
+ containerPadding: refProps.current.containerPadding,
542
+ containerWidth: preferContainerWidth || refProps.current.containerWidth,
543
+ containerHeight: preferContainerHeight || refProps.current.containerHeight,
544
+ containerMargin: refProps.current.margin,
545
+ maxRows: refProps.current.maxRows,
546
+ rowHeight: refProps.current.rowHeight
547
+ };
548
+ }, []);
549
+ useEffect(() => {
550
+ console.log("useEffect Grid Item****", i);
551
+ return () => {
552
+ console.log(`*** useEffect Grid Item: ${i} [cleanUP] **** type:${type}`);
553
+ };
554
+ }, []);
555
+ const createStyle = (pos2) => {
556
+ let newStyle;
557
+ if (useCSSTransforms) {
558
+ newStyle = setTransform(pos2);
559
+ } else {
560
+ newStyle = setTopLeft(pos2);
561
+ if (usePercentages) {
562
+ newStyle.left = perc(pos2.left / containerWidth);
563
+ newStyle.width = perc(pos2.width / containerWidth);
564
+ }
565
+ }
566
+ return newStyle;
567
+ };
568
+ const gridItemOnDragStart = useCallback((e, {
569
+ node
570
+ }) => {
571
+ if (!onDragStart)
572
+ return;
573
+ const newPosition = {
574
+ top: 0,
575
+ left: 0
576
+ };
577
+ const {
578
+ offsetParent
579
+ } = node;
580
+ if (!offsetParent)
581
+ return;
582
+ const parentRect = offsetParent.getBoundingClientRect();
583
+ const clientRect = node.getBoundingClientRect();
584
+ const cLeft = clientRect.left / transformScale;
585
+ const pLeft = parentRect.left / transformScale;
586
+ const cTop = clientRect.top / transformScale;
587
+ const pTop = parentRect.top / transformScale;
588
+ newPosition.left = cLeft - pLeft + offsetParent.scrollLeft;
589
+ newPosition.top = cTop - pTop + offsetParent.scrollTop;
590
+ setCurrentState((prev) => ({
591
+ ...prev,
592
+ dragging: newPosition
593
+ }));
594
+ refState.current.dragging = newPosition;
595
+ const {
596
+ x: newX,
597
+ y: newY
598
+ } = calcXY(getPositionParams(), newPosition.top, newPosition.left, refProps.current.w, refProps.current.h);
599
+ onDragStart(i, newX, newY, {
600
+ e,
601
+ node,
602
+ newPosition
603
+ });
604
+ }, []);
605
+ const gridItemOnDrag = useCallback((e, {
606
+ node,
607
+ deltaX,
608
+ deltaY
609
+ }) => {
610
+ if (!onDrag)
611
+ return;
612
+ if (!refState.current.dragging) {
613
+ console.warn("gridItemOnDrag onDrag called before onDragStart");
614
+ return;
615
+ }
616
+ let top = refState.current.dragging.top + deltaY;
617
+ let left = refState.current.dragging.left + deltaX;
618
+ const positionParams = getPositionParams();
619
+ if (isBounded) {
620
+ const {
621
+ offsetParent
622
+ } = node;
623
+ if (offsetParent) {
624
+ const bottomBoundary = offsetParent.clientHeight - calcGridItemWHPx(refProps.current.h, refProps.current.rowHeight, refProps.current.margin[1]);
625
+ top = clamp(top, 0, bottomBoundary);
626
+ const colWidth = calcGridColWidth(positionParams);
627
+ const rightBoundary = containerWidth - calcGridItemWHPx(refProps.current.w, colWidth, refProps.current.margin[0]);
628
+ left = clamp(left, 0, rightBoundary);
629
+ }
630
+ }
631
+ const newPosition = {
632
+ top,
633
+ left
634
+ };
635
+ refState.current.dragging = newPosition;
636
+ const {
637
+ x: newX,
638
+ y: newY
639
+ } = calcXY(positionParams, top, left, refProps.current.w, refProps.current.h);
640
+ onDrag(i, newX, newY, {
641
+ e,
642
+ node,
643
+ newPosition
644
+ });
645
+ setCurrentState((prev) => ({
646
+ ...prev,
647
+ dragging: newPosition
648
+ }));
649
+ }, []);
650
+ const gridItemOnDragStop = useCallback((e, {
651
+ node
652
+ }) => {
653
+ if (!onDragStop)
654
+ return;
655
+ if (!refState.current.dragging) {
656
+ console.warn("onDragEnd called before onDragStart");
657
+ return;
658
+ }
659
+ const {
660
+ left,
661
+ top
662
+ } = refState.current.dragging;
663
+ const newPosition = {
664
+ top,
665
+ left
666
+ };
667
+ setCurrentState((prev) => ({
668
+ ...prev,
669
+ dragging: void 0
670
+ }));
671
+ refState.current.dragging = void 0;
672
+ const {
673
+ x: newX,
674
+ y: newY
675
+ } = calcXY(getPositionParams(), top, left, refProps.current.w, refProps.current.h);
676
+ return onDragStop(i, newX, newY, {
677
+ e,
678
+ node,
679
+ newPosition
680
+ });
681
+ }, []);
682
+ const onResizeHandler = useCallback((e, {
683
+ node,
684
+ size
685
+ }, handlerName) => {
686
+ const handler = props[handlerName];
687
+ if (!handler) {
688
+ console.error("no puede irse por aca");
689
+ return;
690
+ }
691
+ if (colapsed) {
692
+ console.error("no puede tener resize");
693
+ return;
694
+ }
695
+ let {
696
+ w: newW,
697
+ h: newH
698
+ } = calcWH(getPositionParams(), size.width, size.height, refProps.current.x, refProps.current.y);
699
+ const newMinW = Math.max(refProps.current.minW, 1);
700
+ const newMaxW = Math.min(refProps.current.maxW, refProps.current.cols - refProps.current.x);
701
+ newW = clamp(newW, newMinW, newMaxW);
702
+ newH = clamp(newH, refProps.current.minH, refProps.current.maxH);
703
+ setCurrentState((prev) => ({
704
+ ...prev,
705
+ resizing: handlerName === "onResizeStop" ? void 0 : size
706
+ }));
707
+ handler(i, newW, newH, {
708
+ e,
709
+ node,
710
+ size
711
+ });
712
+ }, []);
713
+ const localOnResizeStop = useCallback((e, callbackData) => {
714
+ onResizeHandler(e, callbackData, "onResizeStop");
715
+ }, []);
716
+ const localOnResizeStart = useCallback((e, callbackData) => {
717
+ onResizeHandler(e, callbackData, "onResizeStart");
718
+ }, []);
719
+ const localFreeMoveOnClick = useCallback(() => {
720
+ if (!onFreeMoveClick)
721
+ return;
722
+ onFreeMoveClick(i);
723
+ }, []);
724
+ const mixinResizable = useCallback((child, position, positionParams) => {
725
+ const maxWidth = calcGridItemPosition(positionParams, 0, 0, cols - x, 0, maximize).width;
726
+ const mins = calcGridItemPosition(positionParams, 0, 0, minW, minH, maximize);
727
+ const maxes = calcGridItemPosition(positionParams, 0, 0, maxW, maxH, maximize);
728
+ const minConstraints = [mins.width, mins.height];
729
+ const maxConstraints = [Math.min(maxes.width, maxWidth), Math.min(maxes.height, Infinity)];
730
+ return /* @__PURE__ */ jsx(
731
+ Resizable,
732
+ {
733
+ draggableOpts: {
734
+ disabled: !isResizable || maximize !== "none" || colapsed
735
+ },
736
+ className: isResizable ? void 0 : "react-resizable-hide",
737
+ width: position.width,
738
+ height: position.height,
739
+ minConstraints,
740
+ maxConstraints,
741
+ onResizeStop: localOnResizeStop,
742
+ onResizeStart: localOnResizeStart,
743
+ onResize: localOnResize,
744
+ transformScale,
745
+ resizeHandles,
746
+ handle: resizeHandle,
747
+ children: child
748
+ }
749
+ );
750
+ }, [cols, x, minW, minH, maxW, maxH, isResizable, transformScale, resizeHandles, resizeHandle, maximize, colapsed]);
751
+ const mixinDraggable = useCallback((child) => {
752
+ return /* @__PURE__ */ jsx(DraggableCore_1, {
753
+ disabled: !isDraggable || maximize !== "none",
754
+ onStart: gridItemOnDragStart,
755
+ onDrag: gridItemOnDrag,
756
+ onStop: gridItemOnDragStop,
757
+ handle,
758
+ cancel: ".react-resizable-handle" + (cancel ? "," + cancel : ""),
759
+ scale: transformScale,
760
+ nodeRef: elementRef,
761
+ children: child
762
+ });
763
+ }, [isDraggable, handle, transformScale, cancel, maximize]);
764
+ const localOnResize = useCallback((e, callbackData) => {
765
+ onResizeHandler(e, callbackData, "onResize");
766
+ }, []);
767
+ const positionParms = getPositionParams(containerWidth, containerHeight);
768
+ const pos = calcGridItemPosition(positionParms, x, y, w, getH(h, colapsedHeight, colapsed), maximize, currentState);
769
+ const classNameFinal = clsx("react-grid-item", className, {
770
+ type,
771
+ static: props.static,
772
+ resizing: Boolean(currentState.resizing),
773
+ "react-draggable": isDraggable,
774
+ "react-maximize-me": maximize === "maximize_me",
775
+ "react-maximize-other": maximize === "maximize_other",
776
+ "react-colapsed": colapsed,
777
+ "react-popover": freeMove,
778
+ "react-draggable-dragging": Boolean(currentState.dragging),
779
+ cssTransforms: useCSSTransforms
780
+ });
781
+ const styleFinal = {
782
+ ...style,
783
+ ...createStyle(pos)
784
+ };
785
+ const memoLayouItemRender = useMemo(() => {
786
+ return /* @__PURE__ */ jsx(ComponentItemRender, {
787
+ type,
788
+ i
789
+ });
790
+ }, [type, i]);
791
+ const baseGridItem = /* @__PURE__ */ jsx("div", {
792
+ className: classNameFinal,
793
+ ref: elementRef,
794
+ style: styleFinal,
795
+ role: "presentation",
796
+ onClick: localFreeMoveOnClick,
797
+ children: memoLayouItemRender
798
+ });
799
+ const gridItem = mixinDraggable(mixinResizable(baseGridItem, pos, getPositionParams()));
800
+ console.log(`Render Grid Item: ${i} type:${type} ==> {x,y,w,h}:{${x},${y},${w},${getH(h, colapsedHeight, colapsed)}} - containerHeight:${containerHeight}`);
801
+ return /* @__PURE__ */ jsx(Fragment, {
802
+ children: gridItem
803
+ });
804
+ }
805
+ const MemonizedGridItem = React__default.memo(GridItem, (prevProps, nextProps) => {
806
+ return deepEqual(prevProps, nextProps);
807
+ });
808
+ const GridLayoutRoot = styled("div")`
809
+ /* height: 100%; */
810
+ overflow: auto;
811
+ /* flex-grow: 1; */
812
+ position: relative;
813
+ transition: height 200ms ease;
814
+ border: 1px dashed gray; //TODO:Para borrar
815
+
816
+ .react-grid-item {
817
+ transition: all 200ms ease;
818
+ transition-property: left, top;
819
+ }
820
+ .react-grid-item img {
821
+ pointer-events: none;
822
+ user-select: none;
823
+ }
824
+ .react-grid-item.cssTransforms {
825
+ transition-property: transform;
826
+ }
827
+ .react-grid-item.react-maximize-other {
828
+ display: none;
829
+ }
830
+
831
+ .react-grid-item.react-popover {
832
+ z-index: 1;
833
+ will-change: width, height;
834
+ }
835
+ .react-grid-item.resizing {
836
+ z-index: 2;
837
+ will-change: width, height;
838
+ }
839
+
840
+ .react-grid-item.react-draggable-dragging {
841
+ transition: none;
842
+ z-index: 4;
843
+ will-change: transform;
844
+ }
845
+
846
+ .react-grid-item.dropping {
847
+ visibility: hidden;
848
+ }
849
+
850
+ .react-grid-item.react-grid-placeholder {
851
+ background: green;
852
+ opacity: 0.2;
853
+ transition-duration: 100ms;
854
+ z-index: 3;
855
+ -webkit-user-select: none;
856
+ -moz-user-select: none;
857
+ -ms-user-select: none;
858
+ -o-user-select: none;
859
+ user-select: none;
860
+ }
861
+
862
+ .react-grid-item > .react-resizable-handle {
863
+ position: absolute;
864
+ width: 20px;
865
+ height: 20px;
866
+ }
867
+
868
+ .react-grid-item > .react-resizable-handle::after {
869
+ content: '';
870
+ position: absolute;
871
+ right: 3px;
872
+ bottom: 3px;
873
+ width: 5px;
874
+ height: 5px;
875
+ border-right: 2px solid rgba(0, 0, 0, 0.4);
876
+ border-bottom: 2px solid rgba(0, 0, 0, 0.4);
877
+ }
878
+
879
+ .react-resizable-hide > .react-resizable-handle {
880
+ display: none;
881
+ }
882
+
883
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-sw {
884
+ bottom: 0;
885
+ left: 0;
886
+ cursor: sw-resize;
887
+ transform: rotate(90deg);
888
+ }
889
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-se {
890
+ bottom: 0;
891
+ right: 0;
892
+ cursor: se-resize;
893
+ }
894
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-nw {
895
+ top: 0;
896
+ left: 0;
897
+ cursor: nw-resize;
898
+ transform: rotate(180deg);
899
+ }
900
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-ne {
901
+ top: 0;
902
+ right: 0;
903
+ cursor: ne-resize;
904
+ transform: rotate(270deg);
905
+ }
906
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-w,
907
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-e {
908
+ top: 50%;
909
+ margin-top: -10px;
910
+ cursor: ew-resize;
911
+ }
912
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-w {
913
+ left: 0;
914
+ transform: rotate(135deg);
915
+ }
916
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-e {
917
+ right: 0;
918
+ transform: rotate(315deg);
919
+ }
920
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-n,
921
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-s {
922
+ left: 50%;
923
+ margin-left: -10px;
924
+ cursor: ns-resize;
925
+ }
926
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-n {
927
+ top: 0;
928
+ transform: rotate(225deg);
929
+ }
930
+ .react-grid-item > .react-resizable-handle.react-resizable-handle-s {
931
+ bottom: 0;
932
+ transform: rotate(45deg);
933
+ }
934
+ .react-grid-item.react-maximize-me > .react-resizable-handle {
935
+ display: none;
936
+ }
937
+ ${react_resizable_css}
938
+ `;
939
+ const layoutClassName = "react-grid-layout";
940
+ function GridLayout(props) {
941
+ const {
942
+ innerRef,
943
+ autoSize = true,
944
+ cols = 12,
945
+ className = "",
946
+ style = {},
947
+ draggableHandle = "",
948
+ draggableCancel = "",
949
+ containerPadding = null,
950
+ rowHeight = 150,
951
+ maxRows = Infinity,
952
+ layout = [],
953
+ containerMargin = [10, 10],
954
+ isBounded = false,
955
+ isDraggable = true,
956
+ isResizable = true,
957
+ allowOverlap = false,
958
+ useCSSTransforms = true,
959
+ transformScale = 1,
960
+ compactType = null,
961
+ preventCollision = false,
962
+ resizeHandles = ["se"],
963
+ resizeHandle,
964
+ layoutItemRender: LayoutItemRender,
965
+ width = 1280,
966
+ height = 720,
967
+ onLayoutChange = noop,
968
+ onDragStart = noop,
969
+ onDrag = noop,
970
+ onDragStop = noop,
971
+ onResizeStart = noop,
972
+ onResize = noop,
973
+ onResizeStop = noop,
974
+ maximizeId,
975
+ colapsedHeight = 2
976
+ } = props;
977
+ const [currentState, setCurrentState] = useState({
978
+ mounted: false
979
+ });
980
+ const [finalLayoutRender, setFinalLayoutRender] = useState(layout);
981
+ const refState = useRef({
982
+ layout,
983
+ mounted: false,
984
+ oldDragItem: void 0,
985
+ oldLayout: void 0,
986
+ oldResizeItem: void 0
987
+ });
988
+ useEffect(() => {
989
+ setCurrentState({
990
+ mounted: true
991
+ });
992
+ }, []);
993
+ useEffect(() => {
994
+ if (!deepEqual(finalLayoutRender, layout)) {
995
+ console.debug("****useEffect cambio de layout****", layout);
996
+ refState.current.layout = layout;
997
+ setFinalLayoutRender(layout);
998
+ } else {
999
+ console.debug("****useEffect cambio de layout sin cambios****");
1000
+ }
1001
+ }, [layout]);
1002
+ const containerHeight = () => {
1003
+ if (!autoSize)
1004
+ return;
1005
+ const nbRow = bottom(finalLayoutRender, colapsedHeight);
1006
+ const containerPaddingY = containerPadding ? containerPadding[1] : containerMargin[1];
1007
+ console.log("containerHeight", nbRow, containerPaddingY, containerMargin[1], rowHeight);
1008
+ return nbRow * rowHeight + (nbRow - 1) * containerMargin[1] + containerPaddingY * 2 + "px";
1009
+ };
1010
+ const localOnDragStart = useCallback((i, _x, _y, gridDragEvent) => {
1011
+ const {
1012
+ layout: layout2
1013
+ } = refState.current;
1014
+ const {
1015
+ e,
1016
+ node
1017
+ } = gridDragEvent;
1018
+ const l = getLayoutItem(layout2, i);
1019
+ if (!l)
1020
+ return;
1021
+ refState.current = {
1022
+ ...refState.current,
1023
+ oldDragItem: cloneLayoutItem(l),
1024
+ oldLayout: [...layout2]
1025
+ };
1026
+ return onDragStart(layout2, l, l, void 0, e, node);
1027
+ }, []);
1028
+ const onLayoutMaybeChanged = useCallback((newLayout, oldLayout) => {
1029
+ console.log("onLayoutMaybeChanged", deepEqual(oldLayout, newLayout));
1030
+ if (!oldLayout) {
1031
+ oldLayout = refState.current.layout;
1032
+ }
1033
+ setFinalLayoutRender(newLayout);
1034
+ if (!deepEqual(oldLayout, newLayout)) {
1035
+ onLayoutChange(newLayout);
1036
+ }
1037
+ }, []);
1038
+ const localOnDrag = useCallback((i, x, y, gridDragEvent) => {
1039
+ const {
1040
+ oldDragItem,
1041
+ layout: layout2
1042
+ } = refState.current;
1043
+ const {
1044
+ e,
1045
+ node
1046
+ } = gridDragEvent;
1047
+ const l = getLayoutItem(layout2, i);
1048
+ if (!l)
1049
+ return;
1050
+ const newPlaceholder = {
1051
+ w: l.w,
1052
+ h: getLayoutItemH(l, colapsedHeight),
1053
+ x: l.x,
1054
+ y: l.y,
1055
+ placeholder: true,
1056
+ i
1057
+ };
1058
+ const isUserAction = true;
1059
+ try {
1060
+ let newLayout;
1061
+ if (!l.freeMove) {
1062
+ newLayout = moveElement(layout2, l, x, y, isUserAction, preventCollision, compactType, cols, colapsedHeight, allowOverlap);
1063
+ } else {
1064
+ newLayout = cloneLayout(layout2);
1065
+ console.log("localOnDrag", l.i, l.freeMove, x, y);
1066
+ const nl = getLayoutItem(newLayout, i);
1067
+ newPlaceholder.x = x;
1068
+ newPlaceholder.y = y;
1069
+ if (nl) {
1070
+ nl.x = x;
1071
+ nl.y = y;
1072
+ }
1073
+ }
1074
+ onDrag(newLayout, oldDragItem, l, newPlaceholder, e, node);
1075
+ const finalLayout = allowOverlap || l.freeMove ? newLayout : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1076
+ refState.current = {
1077
+ ...refState.current,
1078
+ layout: finalLayout,
1079
+ activeDrag: newPlaceholder
1080
+ };
1081
+ console.log(`GridLayout localOnDrag i:${i} placeHolder:{${newPlaceholder.x},${newPlaceholder.y},${newPlaceholder.w},${newPlaceholder.h}}`);
1082
+ setCurrentState((prev) => ({
1083
+ ...prev,
1084
+ activeDrag: newPlaceholder
1085
+ }));
1086
+ setFinalLayoutRender([...finalLayout]);
1087
+ } catch (error) {
1088
+ console.warn("GridLayout error capturado");
1089
+ }
1090
+ }, []);
1091
+ const localOnDragStop = useCallback((i, x, y, {
1092
+ e,
1093
+ node
1094
+ }) => {
1095
+ if (!refState.current.activeDrag)
1096
+ return;
1097
+ const {
1098
+ oldDragItem,
1099
+ layout: layout2,
1100
+ oldLayout
1101
+ } = refState.current;
1102
+ const l = getLayoutItem(layout2, i);
1103
+ if (!l)
1104
+ return;
1105
+ let newLayout;
1106
+ const isUserAction = true;
1107
+ if (!l.freeMove) {
1108
+ newLayout = moveElement(layout2, l, x, y, isUserAction, preventCollision, compactType, cols, colapsedHeight, allowOverlap);
1109
+ } else {
1110
+ newLayout = cloneLayout(layout2);
1111
+ const nl = getLayoutItem(newLayout, i);
1112
+ if (nl) {
1113
+ nl.x = x;
1114
+ nl.y = y;
1115
+ const index = newLayout.indexOf(nl);
1116
+ if (index !== -1 && index !== newLayout.length - 1) {
1117
+ newLayout.splice(index, 1);
1118
+ newLayout.push(nl);
1119
+ }
1120
+ }
1121
+ }
1122
+ onDragStop(layout2, oldDragItem, l, void 0, e, node);
1123
+ const finalLayout = allowOverlap ? newLayout || l.freeMove : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1124
+ setCurrentState((prev) => ({
1125
+ ...prev,
1126
+ activeDrag: void 0
1127
+ }));
1128
+ console.log(`GridLayout localOnDragStop i:${i}`, finalLayout);
1129
+ onLayoutMaybeChanged(finalLayout, oldLayout);
1130
+ refState.current = {
1131
+ ...refState.current,
1132
+ layout: finalLayout,
1133
+ oldDragItem: void 0,
1134
+ oldLayout: void 0,
1135
+ activeDrag: void 0
1136
+ };
1137
+ }, []);
1138
+ const localOnResizeStart = useCallback((i, _w, _h, {
1139
+ e,
1140
+ node
1141
+ }) => {
1142
+ const {
1143
+ layout: layout2
1144
+ } = refState.current;
1145
+ const l = getLayoutItem(layout2, i);
1146
+ if (!l)
1147
+ return;
1148
+ refState.current = {
1149
+ ...refState.current,
1150
+ oldResizeItem: cloneLayoutItem(l),
1151
+ oldLayout: [...refState.current.layout]
1152
+ };
1153
+ onResizeStart(layout2, l, l, void 0, e, node);
1154
+ }, []);
1155
+ const localOnResize = useCallback((i, w, h, {
1156
+ e,
1157
+ node
1158
+ }) => {
1159
+ const {
1160
+ layout: layout2,
1161
+ oldResizeItem
1162
+ } = refState.current;
1163
+ console.log("GridLayout localOnResize 1");
1164
+ let newLayout;
1165
+ let l;
1166
+ if (!oldResizeItem?.freeMove) {
1167
+ const [tempLayout, templ] = withLayoutItem(cloneLayout(layout2), i, (l2) => {
1168
+ let hasCollisions;
1169
+ if (preventCollision && !allowOverlap) {
1170
+ const collisions = getAllCollisions(layout2, {
1171
+ ...l2,
1172
+ w,
1173
+ h
1174
+ }, colapsedHeight).filter((layoutItem) => layoutItem.i !== l2.i);
1175
+ hasCollisions = collisions.length > 0;
1176
+ if (hasCollisions) {
1177
+ let leastX = Infinity, leastY = Infinity;
1178
+ collisions.forEach((layoutItem) => {
1179
+ if (layoutItem.x > l2.x)
1180
+ leastX = Math.min(leastX, layoutItem.x);
1181
+ if (layoutItem.y > l2.y)
1182
+ leastY = Math.min(leastY, layoutItem.y);
1183
+ });
1184
+ if (Number.isFinite(leastX))
1185
+ l2.w = leastX - l2.x;
1186
+ if (Number.isFinite(leastY))
1187
+ l2.h = leastY - l2.y;
1188
+ }
1189
+ }
1190
+ if (!hasCollisions) {
1191
+ l2.w = w;
1192
+ l2.h = h;
1193
+ }
1194
+ return l2;
1195
+ });
1196
+ newLayout = tempLayout;
1197
+ l = templ;
1198
+ } else {
1199
+ newLayout = cloneLayout(layout2);
1200
+ l = getLayoutItem(newLayout, i);
1201
+ if (l) {
1202
+ l.w = w;
1203
+ l.h = h;
1204
+ }
1205
+ }
1206
+ if (!l)
1207
+ return;
1208
+ console.log(`GridLayout localOnResize i:${l.i} {x,y,w,h}:{${l.x},${l.y},${l.w},${l.h}}`);
1209
+ const newPlaceholder = {
1210
+ w: l.w,
1211
+ h: l.h,
1212
+ x: l.x,
1213
+ y: l.y,
1214
+ static: true,
1215
+ i
1216
+ };
1217
+ try {
1218
+ const finalLayout = allowOverlap || l.freeMove ? newLayout : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1219
+ refState.current = {
1220
+ ...refState.current,
1221
+ layout: finalLayout,
1222
+ activeDrag: newPlaceholder
1223
+ };
1224
+ setFinalLayoutRender(finalLayout);
1225
+ setCurrentState((prev) => ({
1226
+ ...prev,
1227
+ activeDrag: newPlaceholder
1228
+ }));
1229
+ onResize(newLayout, oldResizeItem, l, newPlaceholder, e, node);
1230
+ } catch (error) {
1231
+ console.log("GridLayout localOnResize capturado");
1232
+ }
1233
+ }, []);
1234
+ const localOnResizeStop = useCallback((i, _w, _h, {
1235
+ e,
1236
+ node
1237
+ }) => {
1238
+ const {
1239
+ layout: layout2,
1240
+ oldResizeItem,
1241
+ oldLayout
1242
+ } = refState.current;
1243
+ const l = getLayoutItem(layout2, i);
1244
+ if (l) {
1245
+ onResizeStop(layout2, oldResizeItem, l, void 0, e, node);
1246
+ }
1247
+ console.log("GridLayout localOnResizeStop 1");
1248
+ const finalLayout = allowOverlap || l?.freeMove ? layout2 : compact(layout2, compactType, cols, colapsedHeight, allowOverlap);
1249
+ if (l && l?.freeMove) {
1250
+ const index = finalLayout.indexOf(l);
1251
+ if (index !== -1 && index !== finalLayout.length - 1) {
1252
+ finalLayout.splice(index, 1);
1253
+ finalLayout.push(l);
1254
+ }
1255
+ }
1256
+ refState.current = {
1257
+ ...refState.current,
1258
+ layout: [...finalLayout],
1259
+ oldResizeItem: void 0,
1260
+ oldLayout: void 0,
1261
+ activeDrag: void 0
1262
+ };
1263
+ console.log("GridLayout localOnResizeStop 2");
1264
+ setCurrentState((prev) => ({
1265
+ ...prev,
1266
+ activeDrag: void 0
1267
+ }));
1268
+ console.log("GridLayout localOnResizeStop 3");
1269
+ onLayoutMaybeChanged(finalLayout, oldLayout);
1270
+ console.log("GridLayout localOnResizeStop 4");
1271
+ }, []);
1272
+ const localFreeMoveOnClick = useCallback((i) => {
1273
+ const {
1274
+ layout: layout2
1275
+ } = refState.current;
1276
+ let l = getLayoutItem(layout2, i);
1277
+ if (l && l?.freeMove) {
1278
+ const index = layout2.indexOf(l);
1279
+ if (index !== -1 && index !== layout2.length - 1) {
1280
+ const newLayout = cloneLayout(layout2);
1281
+ console.debug("GridLalocalFreeMoveOnClick");
1282
+ l = getLayoutItem(newLayout, i);
1283
+ if (l) {
1284
+ newLayout.splice(index, 1);
1285
+ newLayout.push(l);
1286
+ refState.current = {
1287
+ ...refState.current,
1288
+ layout: newLayout
1289
+ };
1290
+ setFinalLayoutRender(newLayout);
1291
+ onLayoutChange(newLayout);
1292
+ }
1293
+ }
1294
+ }
1295
+ }, []);
1296
+ const placeholder = () => {
1297
+ const {
1298
+ activeDrag
1299
+ } = currentState;
1300
+ if (!activeDrag)
1301
+ return null;
1302
+ return /* @__PURE__ */ jsx(MemonizedGridItem, {
1303
+ type: "placeholder",
1304
+ layoutItemRender: LayoutItemRender,
1305
+ w: activeDrag.w,
1306
+ h: activeDrag.h,
1307
+ x: activeDrag.x,
1308
+ y: activeDrag.y,
1309
+ i: activeDrag.i,
1310
+ className: "react-grid-placeholder",
1311
+ containerWidth: width,
1312
+ containerHeight: height,
1313
+ cols,
1314
+ margin: containerMargin,
1315
+ containerPadding: containerPadding || containerMargin,
1316
+ maxRows,
1317
+ rowHeight,
1318
+ isDraggable: false,
1319
+ isResizable: false,
1320
+ isBounded: false,
1321
+ useCSSTransforms,
1322
+ transformScale,
1323
+ cancel: "",
1324
+ handle: "",
1325
+ minW: 0,
1326
+ maxW: 0,
1327
+ minH: 0,
1328
+ maxH: 0,
1329
+ maximize: "none",
1330
+ colapsed: activeDrag.colapsed,
1331
+ colapsedHeight
1332
+ });
1333
+ };
1334
+ const processGridItem = useCallback((l, isMounted) => {
1335
+ const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
1336
+ const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
1337
+ const resizeHandlesOptions = l.resizeHandles || resizeHandles;
1338
+ const bounded = draggable && isBounded && l.isBounded !== false;
1339
+ const mximize = maximizeId ? maximizeId === l.i ? "maximize_me" : "maximize_other" : "none";
1340
+ return /* @__PURE__ */ jsx(MemonizedGridItem, {
1341
+ type: "layoutItem",
1342
+ layoutItemRender: LayoutItemRender,
1343
+ containerWidth: width,
1344
+ containerHeight: height,
1345
+ cols,
1346
+ margin: containerMargin,
1347
+ containerPadding: containerPadding || containerMargin,
1348
+ maxRows,
1349
+ rowHeight,
1350
+ cancel: draggableCancel,
1351
+ handle: draggableHandle,
1352
+ onDragStart: localOnDragStart,
1353
+ onDrag: localOnDrag,
1354
+ onDragStop: localOnDragStop,
1355
+ onResizeStart: localOnResizeStart,
1356
+ onResize: localOnResize,
1357
+ onResizeStop: localOnResizeStop,
1358
+ onFreeMoveClick: localFreeMoveOnClick,
1359
+ isDraggable: draggable,
1360
+ isResizable: resizable,
1361
+ isBounded: bounded,
1362
+ useCSSTransforms: useCSSTransforms && isMounted,
1363
+ usePercentages: !isMounted,
1364
+ transformScale,
1365
+ w: l.w,
1366
+ h: l.h,
1367
+ x: l.x,
1368
+ y: l.y,
1369
+ i: l.i,
1370
+ minH: l.minH,
1371
+ minW: l.minW,
1372
+ maxH: l.maxH,
1373
+ maxW: l.maxW,
1374
+ static: l.static,
1375
+ resizeHandles: resizeHandlesOptions,
1376
+ resizeHandle,
1377
+ maximize: mximize,
1378
+ colapsed: l.colapsed,
1379
+ colapsedHeight
1380
+ }, l.i);
1381
+ }, [width, height, cols, containerMargin, containerPadding, maxRows, rowHeight, draggableCancel, draggableHandle, isDraggable, isResizable, isBounded, useCSSTransforms, transformScale, resizeHandles, resizeHandle, maximizeId]);
1382
+ const mergedStyle = {
1383
+ height: containerHeight(),
1384
+ ...style
1385
+ };
1386
+ return /* @__PURE__ */ jsxs(GridLayoutRoot, {
1387
+ className: clsx(layoutClassName, className),
1388
+ style: mergedStyle,
1389
+ ref: innerRef,
1390
+ children: [finalLayoutRender.map((li) => processGridItem(li, !!currentState.mounted)), placeholder()]
1391
+ });
1392
+ }
1393
+ export {
1394
+ GridLayout as G,
1395
+ cloneLayout as a,
1396
+ compact as b,
1397
+ cloneLayoutItem as c,
1398
+ correctBounds as d,
1399
+ noop as n
1400
+ };