@m4l/components 0.1.76 → 0.1.78

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 (133) hide show
  1. package/@types/export.d.ts +22 -3
  2. package/components/AccountPopover/{index.47cf6c43.js → index.7e76dbb7.js} +8 -7
  3. package/components/AppBar/{index.f04f5e45.js → index.06858422.js} +8 -7
  4. package/components/CommonActions/components/ActionCancel/{index.453c2d24.js → index.d536ccfa.js} +2 -2
  5. package/components/CommonActions/components/ActionFormCancel/{index.c2a2fd55.js → index.a915b105.js} +19 -19
  6. package/components/CommonActions/components/ActionFormIntro/{index.25d33912.js → index.14e65d6c.js} +2 -2
  7. package/components/CommonActions/components/ActionIntro/{index.c653a266.js → index.aa1648eb.js} +2 -2
  8. package/components/CommonActions/components/Actions/{index.e376a68e.js → index.52125041.js} +17 -18
  9. package/components/DataGrid/{index.ffaf000e.js → index.9fb3e6a1.js} +40 -31
  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/constants.d.ts +1 -0
  13. package/components/DynamicFilter/contexts/DynamicFilterContext/store.d.ts +6 -1
  14. package/components/DynamicFilter/{index.d7c03a61.js → index.d1a2e2d1.js} +54 -47
  15. package/components/DynamicFilter/tests/contants.d.ts +2 -3
  16. package/components/DynamicFilter/types.d.ts +4 -0
  17. package/components/GridLayout/GridLayout.d.ts +6 -0
  18. package/components/GridLayout/Responsive/index.0905a698.js +353 -0
  19. package/components/GridLayout/WidthProvider/index.9a26dfe4.js +65 -0
  20. package/components/GridLayout/calculateUtils.d.ts +42 -0
  21. package/components/GridLayout/index.d.ts +6 -0
  22. package/components/GridLayout/index.da6fd387.js +1410 -0
  23. package/components/GridLayout/subcomponents/GridItem/index.d.ts +26 -0
  24. package/components/GridLayout/subcomponents/GridItem/types.d.ts +78 -0
  25. package/components/GridLayout/subcomponents/Responsive/index.d.ts +3 -0
  26. package/components/GridLayout/subcomponents/Responsive/responsiveUtils.d.ts +64 -0
  27. package/components/GridLayout/subcomponents/Responsive/types.d.ts +69 -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.a019742c.js} +8 -7
  32. package/components/Icon/{index.9dae8337.js → index.9fcd1476.js} +1 -1
  33. package/components/LanguagePopover/{index.938c6675.js → index.98b63dcb.js} +8 -7
  34. package/components/LinearProgressIndeterminate/{index.d34d398f.js → index.60dabc06.js} +1 -1
  35. package/components/ModalDialog/{index.d9c5d400.js → index.d9937d46.js} +8 -56
  36. package/components/NavLink/{index.21c8fd90.js → index.a5dea6d3.js} +8 -7
  37. package/components/ObjectLogs/{index.a2709fc2.js → index.d9d20b9d.js} +27 -21
  38. package/components/ObjectLogs/types.d.ts +1 -0
  39. package/components/PaperForm/{index.5e1bc99f.js → index.ba38a0bd.js} +1 -1
  40. package/components/Period/{index.526791a3.js → index.7b94c418.js} +22 -23
  41. package/components/PropertyValue/constants.d.ts +3 -0
  42. package/components/PropertyValue/{index.8a1adf3e.js → index.45c73161.js} +17 -11
  43. package/components/PropertyValue/types.d.ts +2 -1
  44. package/components/Resizeable/{index.f6e48e56.js → index.9a9c79a4.js} +1 -1
  45. package/components/SideBar/{index.9e1a5b96.js → index.2f497e6c.js} +5 -5
  46. package/components/areas/components/AreasAdmin/classes/index.d.ts +1 -1
  47. package/components/areas/components/AreasAdmin/classes/types.d.ts +5 -0
  48. package/components/areas/components/AreasAdmin/{index.946eebb9.js → index.43ecd998.js} +167 -81
  49. package/components/areas/components/AreasAdmin/subcomponents/AreaChip/types.d.ts +0 -1
  50. package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/index.d.ts +3 -0
  51. package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/types.d.ts +3 -0
  52. package/components/areas/components/AreasViewer/classes/index.d.ts +1 -1
  53. package/components/areas/components/AreasViewer/classes/types.d.ts +3 -0
  54. package/components/areas/components/AreasViewer/{index.bf4191ea.js → index.14e62059.js} +326 -345
  55. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/index.d.ts +1 -1
  56. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/index.d.ts +2 -2
  57. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/index.d.ts +1 -7
  58. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/index.d.ts +3 -0
  59. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/types.d.ts +2 -0
  60. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/types.d.ts +6 -0
  61. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/types.d.ts +1 -1
  62. package/components/areas/components/index.a87653a9.js +29 -0
  63. package/components/areas/contexts/AreasContext/helper.d.ts +8 -16
  64. package/components/areas/contexts/AreasContext/{index.f0397b7c.js → index.02c4e7be.js} +262 -336
  65. package/components/areas/contexts/AreasContext/types.d.ts +22 -20
  66. package/components/areas/contexts/{index.1809650a.js → index.1ff9b360.js} +1 -1
  67. package/components/areas/{dictionary.3fabae50.js → dictionary.afb7e3d9.js} +5 -2
  68. package/components/areas/dictionary.d.ts +4 -1
  69. package/components/areas/hooks/useAreas/{index.40917e99.js → index.85e4b2e2.js} +1 -1
  70. package/components/areas/{icons.19cde4b4.js → icons.8266ccc8.js} +5 -1
  71. package/components/areas/icons.d.ts +4 -0
  72. package/components/areas/{index.9bd48013.js → index.d1dcccf5.js} +12 -11
  73. package/components/areas/types.d.ts +29 -22
  74. package/components/formatters/BooleanFormatter/{index.431dc923.js → index.e8de8e4c.js} +1 -1
  75. package/components/formatters/{index.e1af75e6.js → index.67aeb049.js} +2 -2
  76. package/components/hook-form/RHFAutocomplete/{index.a063dc44.js → index.6aa51705.js} +25 -13
  77. package/components/hook-form/RHFAutocompleteAsync/{index.ddfd9cc9.js → index.1a3dfe5f.js} +1 -1
  78. package/components/hook-form/RHFCheckbox/{index.7e7f220b.js → index.a08a65b3.js} +1 -1
  79. package/components/hook-form/RHFDateTime/{index.d330709b.js → index.4d671108.js} +10 -9
  80. package/components/hook-form/RHFPeriod/{index.e2b1293b.js → index.39b4be49.js} +2 -2
  81. package/components/hook-form/RHFTextField/{index.e5336d09.js → index.9004e898.js} +5 -5
  82. package/components/hook-form/RHFUpload/{index.17e7f9eb.js → index.bed8573e.js} +9 -11
  83. package/components/index.d.ts +1 -0
  84. package/components/modal/{WindowBase.7acb9f1d.js → WindowBase.a0c0b322.js} +10 -9
  85. package/components/modal/{WindowConfirm.9b829837.js → WindowConfirm.6c063f2d.js} +19 -19
  86. package/components/modal/classes/index.d.ts +1 -0
  87. package/components/modal/classes/types.d.ts +1 -0
  88. package/components/modal/{index.1b25b61d.js → index.00efea85.js} +19 -17
  89. package/components/mui_extended/Accordion/constants.d.ts +1 -0
  90. package/components/mui_extended/Accordion/{index.3faafd8b.js → index.9877f7bf.js} +8 -9
  91. package/components/mui_extended/Accordion/types.d.ts +1 -0
  92. package/components/mui_extended/Badge/Badge.d.ts +3 -0
  93. package/components/mui_extended/Badge/classes/constants.d.ts +1 -0
  94. package/components/mui_extended/Badge/classes/index.d.ts +6 -0
  95. package/components/mui_extended/Badge/classes/types.d.ts +6 -0
  96. package/components/mui_extended/Badge/index.8c2b8b66.js +36 -0
  97. package/components/mui_extended/Badge/index.d.ts +2 -0
  98. package/components/mui_extended/Badge/tests/constants.d.ts +1 -0
  99. package/components/mui_extended/Badge/tests/utils.d.ts +2 -0
  100. package/components/mui_extended/Badge/types.d.ts +4 -0
  101. package/components/mui_extended/Button/{index.fdb5dcbd.js → index.4288f9fc.js} +8 -3
  102. package/components/mui_extended/IconButton/{index.1a9d4fa5.js → index.12f1a3c3.js} +4 -1
  103. package/components/mui_extended/MenuActions/{index.ba1da3b3.js → index.43a2e1ae.js} +41 -13
  104. package/components/mui_extended/MenuActions/index.d.ts +3 -2
  105. package/components/mui_extended/MenuActions/types.d.ts +9 -0
  106. package/components/mui_extended/Pager/{index.67bda2c5.js → index.2f6d6d7d.js} +1 -1
  107. package/components/mui_extended/Tab/constant.d.ts +1 -0
  108. package/components/mui_extended/Tab/{index.9e2f6e34.js → index.7c82e43d.js} +5 -6
  109. package/components/mui_extended/Tab/types.d.ts +1 -0
  110. package/components/mui_extended/{index.73e536de.js → index.0e2ff642.js} +8 -7
  111. package/components/mui_extended/index.d.ts +1 -0
  112. package/contexts/ModalContext/{index.699f95fa.js → index.e9a7ba4a.js} +1 -1
  113. package/hooks/useModal/{index.7b7d26ba.js → index.8e85f7ae.js} +1 -1
  114. package/index.js +228 -214
  115. package/node_modules.d73a220d.js +363 -0
  116. package/package.json +4 -3
  117. package/{react-draggable.6d7949a3.js → react-draggable.7abb5d0a.js} +3 -2
  118. package/{react-resizable.b6f8e04a.js → react-resizable.ba08699a.js} +13 -12
  119. package/test/getNameDataTestId.d.ts +1 -0
  120. package/utils/{index.008b4c2a.js → index.c43a95f4.js} +0 -15
  121. package/vendor.e353394b.js +124 -0
  122. package/components/DynamicFilter/tests/types.d.ts +0 -2
  123. package/components/DynamicFilter/tests/utils.d.ts +0 -2
  124. package/components/PropertyValue/tests/constants.d.ts +0 -1
  125. package/components/PropertyValue/tests/utils.d.ts +0 -2
  126. package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/WindowPopUp/index.d.ts +0 -4
  127. package/components/areas/components/index.2bb534cb.js +0 -28
  128. package/components/modal/ModalDialog/types.d.ts +0 -7
  129. package/components/mui_extended/Accordion/tests/constants.d.ts +0 -1
  130. package/components/mui_extended/Accordion/tests/utils.d.ts +0 -2
  131. package/components/mui_extended/Tab/tests/constants.d.ts +0 -1
  132. package/components/mui_extended/Tab/tests/utils.d.ts +0 -2
  133. /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/types.d.ts +0 -0
@@ -0,0 +1,1410 @@
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 { i as isEqualLayout } from "./Responsive/index.0905a698.js";
5
+ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
6
+ import { D as DraggableCore_1 } from "../../react-draggable.7abb5d0a.js";
7
+ import { R as Resizable, r as react_resizable_css } from "../../react-resizable.ba08699a.js";
8
+ import { styled } from "@mui/material/styles";
9
+ import "@m4l/graphics";
10
+ import "lodash";
11
+ const noop = () => {
12
+ };
13
+ function bottom(layout, colapsedHeight) {
14
+ let max = 0, bottomY;
15
+ for (let i = 0, len = layout.length; i < len; i++) {
16
+ bottomY = layout[i].y + getLayoutItemH(layout[i], colapsedHeight);
17
+ if (bottomY > max)
18
+ max = bottomY;
19
+ }
20
+ return max;
21
+ }
22
+ function cloneLayoutItem(layoutItem, layoutItemReplaceProps) {
23
+ return {
24
+ w: layoutItem.w,
25
+ h: layoutItem.h,
26
+ x: layoutItem.x,
27
+ y: layoutItem.y,
28
+ i: layoutItem.i,
29
+ minW: layoutItem.minW,
30
+ maxW: layoutItem.maxW,
31
+ minH: layoutItem.minH,
32
+ maxH: layoutItem.maxH,
33
+ moved: Boolean(layoutItem.moved),
34
+ static: Boolean(layoutItem.static),
35
+ isDraggable: layoutItem.isDraggable,
36
+ isResizable: layoutItem.isResizable,
37
+ resizeHandles: layoutItem.resizeHandles,
38
+ isBounded: layoutItem.isBounded,
39
+ freeMove: layoutItem.freeMove,
40
+ colapsed: layoutItem.colapsed,
41
+ visible: layoutItem.visible,
42
+ ...layoutItemReplaceProps
43
+ };
44
+ }
45
+ function cloneLayout(layout, layoutItemReplaceProps) {
46
+ const newLayout = Array(layout.length);
47
+ for (let i = 0, len = layout.length; i < len; i++) {
48
+ newLayout[i] = cloneLayoutItem(layout[i], layoutItemReplaceProps);
49
+ }
50
+ return newLayout;
51
+ }
52
+ function collides(l1, l2, colapsedHeight) {
53
+ if (l1.i === l2.i)
54
+ return false;
55
+ if (l1.x + l1.w <= l2.x)
56
+ return false;
57
+ if (l1.x >= l2.x + l2.w)
58
+ return false;
59
+ if (l1.y + getLayoutItemH(l1, colapsedHeight) <= l2.y)
60
+ return false;
61
+ if (l1.y >= l2.y + getLayoutItemH(l2, colapsedHeight))
62
+ return false;
63
+ return true;
64
+ }
65
+ function compactItem(compareWith, l, compactType, cols, fullLayout, colapsedHeight, allowOverlap) {
66
+ const compactV = compactType === "vertical";
67
+ const compactH = compactType === "horizontal";
68
+ if (compactV) {
69
+ l.y = Math.min(bottom(compareWith, colapsedHeight), l.y);
70
+ while (l.y > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
71
+ l.y--;
72
+ }
73
+ } else if (compactH) {
74
+ while (l.x > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
75
+ l.x--;
76
+ }
77
+ }
78
+ let collidesItem;
79
+ while ((collidesItem = getFirstCollision(compareWith, l, colapsedHeight)) && !(compactType === null && allowOverlap)) {
80
+ if (compactH) {
81
+ resolveCompactionCollision(
82
+ fullLayout,
83
+ l,
84
+ collidesItem.x + collidesItem.w,
85
+ "x",
86
+ colapsedHeight
87
+ );
88
+ } else {
89
+ resolveCompactionCollision(
90
+ fullLayout,
91
+ l,
92
+ collidesItem.y + getLayoutItemH(collidesItem, colapsedHeight),
93
+ "y",
94
+ colapsedHeight
95
+ );
96
+ }
97
+ if (compactH && l.x + l.w > cols) {
98
+ l.x = cols - l.w;
99
+ l.y++;
100
+ while (l.x > 0 && !getFirstCollision(compareWith, l, colapsedHeight)) {
101
+ l.x--;
102
+ }
103
+ }
104
+ }
105
+ l.y = Math.max(l.y, 0);
106
+ l.x = Math.max(l.x, 0);
107
+ return l;
108
+ }
109
+ function compact(layout, compactType, cols, colapsedHeight, allowOverlap) {
110
+ const layoutToCompact = layout.filter((l) => !l.freeMove);
111
+ const layoutFreeMov = layout.filter((l) => l?.freeMove);
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
+ } else {
396
+ out.width = calcGridItemWHPx(w, colWidth, containerMargin[0]);
397
+ out.height = calcGridItemWHPx(h, rowHeight, containerMargin[1]);
398
+ }
399
+ }
400
+ if (state && state.dragging) {
401
+ out.top = Math.round(state.dragging.top);
402
+ out.left = Math.round(state.dragging.left);
403
+ } else {
404
+ if (maximize === "maximize_me") {
405
+ out.left = containerPadding[0];
406
+ out.top = containerPadding[1];
407
+ } else {
408
+ out.left = Math.round((colWidth + containerMargin[0]) * x + containerPadding[0]);
409
+ out.top = Math.round((rowHeight + containerMargin[1]) * y + containerPadding[1]);
410
+ }
411
+ }
412
+ return out;
413
+ }
414
+ function calcXY(positionParams, top, left, w, h) {
415
+ const { containerMargin: margin, cols, rowHeight, maxRows } = positionParams;
416
+ const colWidth = calcGridColWidth(positionParams);
417
+ let x = Math.round((left - margin[0]) / (colWidth + margin[0]));
418
+ let y = Math.round((top - margin[1]) / (rowHeight + margin[1]));
419
+ x = clamp(x, 0, cols - w);
420
+ y = clamp(y, 0, maxRows - h);
421
+ return { x, y };
422
+ }
423
+ function calcWH(positionParams, width, height, x, y) {
424
+ const { containerMargin: margin, maxRows, cols, rowHeight } = positionParams;
425
+ const colWidth = calcGridColWidth(positionParams);
426
+ let w = Math.round((width + margin[0]) / (colWidth + margin[0]));
427
+ let h = Math.round((height + margin[1]) / (rowHeight + margin[1]));
428
+ w = clamp(w, 0, cols - x);
429
+ h = clamp(h, 0, maxRows - y);
430
+ return { w, h };
431
+ }
432
+ function clamp(num, lowerBound, upperBound) {
433
+ return Math.max(Math.min(num, upperBound), lowerBound);
434
+ }
435
+ function GridItem(props) {
436
+ const {
437
+ type,
438
+ i,
439
+ x,
440
+ y,
441
+ w,
442
+ h,
443
+ cols,
444
+ isBounded,
445
+ margin,
446
+ maxRows,
447
+ rowHeight,
448
+ containerWidth,
449
+ containerHeight,
450
+ containerPadding,
451
+ className = "",
452
+ cancel = "",
453
+ handle = "",
454
+ minH = 1,
455
+ minW = 1,
456
+ maxH = Infinity,
457
+ maxW = Infinity,
458
+ isResizable,
459
+ isDraggable,
460
+ onDragStart,
461
+ onDrag,
462
+ onDragStop,
463
+ onFreeMoveClick,
464
+ layoutItemRender: ComponentItemRender,
465
+ resizeHandles,
466
+ resizeHandle,
467
+ transformScale = 1,
468
+ useCSSTransforms = true,
469
+ usePercentages,
470
+ style,
471
+ freeMove,
472
+ maximize = "none",
473
+ colapsed,
474
+ colapsedHeight = 1.5,
475
+ visible = true
476
+ } = props;
477
+ const refProps = useRef({
478
+ cols,
479
+ x,
480
+ y,
481
+ w,
482
+ h: getH(h, colapsedHeight, colapsed),
483
+ minW,
484
+ maxW,
485
+ minH,
486
+ maxH,
487
+ containerWidth,
488
+ containerHeight,
489
+ margin,
490
+ containerPadding,
491
+ rowHeight,
492
+ maxRows,
493
+ colapsed
494
+ });
495
+ useEffect(() => {
496
+ refProps.current = {
497
+ cols,
498
+ x,
499
+ y,
500
+ w,
501
+ h: getH(h, colapsedHeight, colapsed),
502
+ minW,
503
+ maxW,
504
+ minH,
505
+ maxH,
506
+ containerWidth,
507
+ containerHeight,
508
+ margin,
509
+ containerPadding,
510
+ rowHeight,
511
+ maxRows,
512
+ colapsed
513
+ };
514
+ }, [cols, x, y, w, h, minW, maxW, minH, maxH, containerWidth, containerHeight, margin, containerPadding, rowHeight, maxRows, colapsed, colapsedHeight]);
515
+ const [currentState, setCurrentState] = useState({
516
+ resizing: void 0,
517
+ dragging: void 0,
518
+ className: ""
519
+ });
520
+ const refState = useRef({
521
+ resizing: void 0,
522
+ dragging: void 0,
523
+ className: ""
524
+ });
525
+ const elementRef = useRef(null);
526
+ const getPositionParams = useCallback((preferContainerWidth, preferContainerHeight) => {
527
+ return {
528
+ cols: refProps.current.cols,
529
+ containerPadding: refProps.current.containerPadding,
530
+ containerWidth: preferContainerWidth || refProps.current.containerWidth,
531
+ containerHeight: preferContainerHeight || refProps.current.containerHeight,
532
+ containerMargin: refProps.current.margin,
533
+ maxRows: refProps.current.maxRows,
534
+ rowHeight: refProps.current.rowHeight
535
+ };
536
+ }, []);
537
+ useEffect(() => {
538
+ return () => {
539
+ };
540
+ }, []);
541
+ const createStyle = (pos2) => {
542
+ let newStyle;
543
+ if (useCSSTransforms) {
544
+ newStyle = setTransform(pos2);
545
+ } else {
546
+ newStyle = setTopLeft(pos2);
547
+ if (usePercentages) {
548
+ newStyle.left = perc(pos2.left / containerWidth);
549
+ newStyle.width = perc(pos2.width / containerWidth);
550
+ }
551
+ }
552
+ return newStyle;
553
+ };
554
+ const gridItemOnDragStart = useCallback((e, {
555
+ node
556
+ }) => {
557
+ if (!onDragStart)
558
+ return;
559
+ const newPosition = {
560
+ top: 0,
561
+ left: 0
562
+ };
563
+ const {
564
+ offsetParent
565
+ } = node;
566
+ if (!offsetParent)
567
+ return;
568
+ const parentRect = offsetParent.getBoundingClientRect();
569
+ const clientRect = node.getBoundingClientRect();
570
+ const cLeft = clientRect.left / transformScale;
571
+ const pLeft = parentRect.left / transformScale;
572
+ const cTop = clientRect.top / transformScale;
573
+ const pTop = parentRect.top / transformScale;
574
+ newPosition.left = cLeft - pLeft + offsetParent.scrollLeft;
575
+ newPosition.top = cTop - pTop + offsetParent.scrollTop;
576
+ setCurrentState((prev) => ({
577
+ ...prev,
578
+ dragging: newPosition
579
+ }));
580
+ refState.current.dragging = newPosition;
581
+ const {
582
+ x: newX,
583
+ y: newY
584
+ } = calcXY(getPositionParams(), newPosition.top, newPosition.left, refProps.current.w, refProps.current.h);
585
+ onDragStart(i, newX, newY, {
586
+ e,
587
+ node,
588
+ newPosition
589
+ });
590
+ }, []);
591
+ const gridItemOnDrag = useCallback((e, {
592
+ node,
593
+ deltaX,
594
+ deltaY
595
+ }) => {
596
+ if (!onDrag)
597
+ return;
598
+ if (!refState.current.dragging) {
599
+ console.warn("gridItemOnDrag onDrag called before onDragStart");
600
+ return;
601
+ }
602
+ let top = refState.current.dragging.top + deltaY;
603
+ let left = refState.current.dragging.left + deltaX;
604
+ const positionParams = getPositionParams();
605
+ if (isBounded) {
606
+ const {
607
+ offsetParent
608
+ } = node;
609
+ if (offsetParent) {
610
+ const bottomBoundary = offsetParent.clientHeight - calcGridItemWHPx(refProps.current.h, refProps.current.rowHeight, refProps.current.margin[1]);
611
+ top = clamp(top, 0, bottomBoundary);
612
+ const colWidth = calcGridColWidth(positionParams);
613
+ const rightBoundary = containerWidth - calcGridItemWHPx(refProps.current.w, colWidth, refProps.current.margin[0]);
614
+ left = clamp(left, 0, rightBoundary);
615
+ }
616
+ }
617
+ const newPosition = {
618
+ top,
619
+ left
620
+ };
621
+ refState.current.dragging = newPosition;
622
+ const {
623
+ x: newX,
624
+ y: newY
625
+ } = calcXY(positionParams, top, left, refProps.current.w, refProps.current.h);
626
+ onDrag(i, newX, newY, {
627
+ e,
628
+ node,
629
+ newPosition
630
+ });
631
+ setCurrentState((prev) => ({
632
+ ...prev,
633
+ dragging: newPosition
634
+ }));
635
+ }, []);
636
+ const gridItemOnDragStop = useCallback((e, {
637
+ node
638
+ }) => {
639
+ if (!onDragStop)
640
+ return;
641
+ if (!refState.current.dragging) {
642
+ console.warn("onDragEnd called before onDragStart");
643
+ return;
644
+ }
645
+ const {
646
+ left,
647
+ top
648
+ } = refState.current.dragging;
649
+ const newPosition = {
650
+ top,
651
+ left
652
+ };
653
+ setCurrentState((prev) => ({
654
+ ...prev,
655
+ dragging: void 0
656
+ }));
657
+ refState.current.dragging = void 0;
658
+ const {
659
+ x: newX,
660
+ y: newY
661
+ } = calcXY(getPositionParams(), top, left, refProps.current.w, refProps.current.h);
662
+ return onDragStop(i, newX, newY, {
663
+ e,
664
+ node,
665
+ newPosition
666
+ });
667
+ }, []);
668
+ const onResizeHandler = useCallback((e, {
669
+ node,
670
+ size
671
+ }, handlerName) => {
672
+ const handler = props[handlerName];
673
+ if (!handler) {
674
+ console.error("no puede irse por aca");
675
+ return;
676
+ }
677
+ if (colapsed) {
678
+ console.error("no puede tener resize");
679
+ return;
680
+ }
681
+ let {
682
+ w: newW,
683
+ h: newH
684
+ } = calcWH(getPositionParams(), size.width, size.height, refProps.current.x, refProps.current.y);
685
+ const newMinW = Math.max(refProps.current.minW, 1);
686
+ const newMaxW = Math.min(refProps.current.maxW, refProps.current.cols - refProps.current.x);
687
+ newW = clamp(newW, newMinW, newMaxW);
688
+ newH = clamp(newH, refProps.current.minH, refProps.current.maxH);
689
+ setCurrentState((prev) => ({
690
+ ...prev,
691
+ resizing: handlerName === "onResizeStop" ? void 0 : size
692
+ }));
693
+ handler(i, newW, newH, {
694
+ e,
695
+ node,
696
+ size
697
+ });
698
+ }, []);
699
+ const localOnResizeStop = useCallback((e, callbackData) => {
700
+ onResizeHandler(e, callbackData, "onResizeStop");
701
+ }, []);
702
+ const localOnResizeStart = useCallback((e, callbackData) => {
703
+ onResizeHandler(e, callbackData, "onResizeStart");
704
+ }, []);
705
+ const localFreeMoveOnClick = useCallback(() => {
706
+ if (!onFreeMoveClick)
707
+ return;
708
+ onFreeMoveClick(i);
709
+ }, []);
710
+ const mixinResizable = useCallback((child, position, positionParams) => {
711
+ const maxWidth = calcGridItemPosition(positionParams, 0, 0, cols - x, 0, maximize).width;
712
+ const mins = calcGridItemPosition(positionParams, 0, 0, minW, minH, maximize);
713
+ const maxes = calcGridItemPosition(positionParams, 0, 0, maxW, maxH, maximize);
714
+ const minConstraints = [mins.width, mins.height];
715
+ const maxConstraints = [Math.min(maxes.width, maxWidth), Math.min(maxes.height, Infinity)];
716
+ return /* @__PURE__ */ jsx(
717
+ Resizable,
718
+ {
719
+ draggableOpts: {
720
+ disabled: !isResizable || maximize !== "none" || colapsed
721
+ },
722
+ className: isResizable ? void 0 : "react-resizable-hide",
723
+ width: position.width,
724
+ height: position.height,
725
+ minConstraints,
726
+ maxConstraints,
727
+ onResizeStop: localOnResizeStop,
728
+ onResizeStart: localOnResizeStart,
729
+ onResize: localOnResize,
730
+ transformScale,
731
+ resizeHandles,
732
+ handle: resizeHandle,
733
+ children: child
734
+ }
735
+ );
736
+ }, [cols, x, minW, minH, maxW, maxH, isResizable, transformScale, resizeHandles, resizeHandle, maximize, colapsed]);
737
+ const mixinDraggable = useCallback((child) => {
738
+ return /* @__PURE__ */ jsx(DraggableCore_1, {
739
+ disabled: !isDraggable || maximize !== "none",
740
+ onStart: gridItemOnDragStart,
741
+ onDrag: gridItemOnDrag,
742
+ onStop: gridItemOnDragStop,
743
+ handle,
744
+ cancel: ".react-resizable-handle" + (cancel ? "," + cancel : ""),
745
+ scale: transformScale,
746
+ nodeRef: elementRef,
747
+ children: child
748
+ });
749
+ }, [isDraggable, handle, transformScale, cancel, maximize]);
750
+ const localOnResize = useCallback((e, callbackData) => {
751
+ onResizeHandler(e, callbackData, "onResize");
752
+ }, []);
753
+ const positionParms = getPositionParams(containerWidth, containerHeight);
754
+ const pos = calcGridItemPosition(positionParms, x, y, w, getH(h, colapsedHeight, colapsed), maximize, currentState);
755
+ const classNameFinal = clsx("M4LGridItem", className, {
756
+ type,
757
+ static: props.static,
758
+ resizing: Boolean(currentState.resizing),
759
+ "react-draggable": isDraggable,
760
+ "react-maximize-me": maximize === "maximize_me",
761
+ "react-maximize-other": maximize === "maximize_other",
762
+ "react-colapsed": colapsed,
763
+ M4LGridItemPopup: freeMove,
764
+ "react-draggable-dragging": Boolean(currentState.dragging),
765
+ M4LColapsed: colapsed,
766
+ M4LResizeHide: colapsed,
767
+ M4LInvisible: !visible,
768
+ cssTransforms: useCSSTransforms
769
+ });
770
+ const styleFinal = {
771
+ ...style,
772
+ ...createStyle(pos)
773
+ };
774
+ const memoLayouItemRender = useMemo(() => {
775
+ return /* @__PURE__ */ jsx(ComponentItemRender, {
776
+ type,
777
+ i
778
+ });
779
+ }, [type, i]);
780
+ const baseGridItem = /* @__PURE__ */ jsx("div", {
781
+ className: classNameFinal,
782
+ ref: elementRef,
783
+ style: styleFinal,
784
+ role: "presentation",
785
+ onClick: localFreeMoveOnClick,
786
+ children: memoLayouItemRender
787
+ });
788
+ const gridItem = mixinDraggable(mixinResizable(baseGridItem, pos, getPositionParams()));
789
+ return /* @__PURE__ */ jsx(Fragment, {
790
+ children: gridItem
791
+ });
792
+ }
793
+ const MemonizedGridItem = React__default.memo(GridItem, (prevProps, nextProps) => {
794
+ return deepEqual(prevProps, nextProps);
795
+ });
796
+ const GridLayoutRoot = styled("div")`
797
+ /* height: 100%; */
798
+ overflow: auto;
799
+ /* flex-grow: 1; */
800
+ position: relative;
801
+ transition: height 200ms ease;
802
+ border: 1px dashed gray; //TODO:Para borrar
803
+
804
+ .M4LGridItem {
805
+ transition: all 200ms ease;
806
+ transition-property: left, top;
807
+ }
808
+ .M4LGridItem img {
809
+ pointer-events: none;
810
+ user-select: none;
811
+ }
812
+ .M4LGridItem.cssTransforms {
813
+ transition-property: transform;
814
+ }
815
+ .M4LGridItem.react-maximize-other {
816
+ display: none;
817
+ }
818
+
819
+ .M4LGridItem.M4LGridItemPopup {
820
+ z-index: 1;
821
+ will-change: width, height;
822
+ }
823
+ .M4LGridItem.resizing {
824
+ z-index: 2000;
825
+ will-change: width, height;
826
+ }
827
+
828
+ .M4LGridItem.react-draggable-dragging {
829
+ transition: none;
830
+ z-index: 4000;
831
+ will-change: transform;
832
+ }
833
+
834
+ .M4LGridItem.dropping {
835
+ visibility: hidden;
836
+ }
837
+
838
+ .M4LGridItem.react-grid-placeholder {
839
+ background: green;
840
+ opacity: 0.2;
841
+ transition-duration: 100ms;
842
+ z-index: 300000;
843
+ -webkit-user-select: none;
844
+ -moz-user-select: none;
845
+ -ms-user-select: none;
846
+ -o-user-select: none;
847
+ user-select: none;
848
+ }
849
+
850
+ .M4LGridItem > .react-resizable-handle {
851
+ position: absolute;
852
+ width: 20px;
853
+ height: 20px;
854
+ }
855
+
856
+ .M4LGridItem > .react-resizable-handle::after {
857
+ content: '';
858
+ position: absolute;
859
+ right: 3px;
860
+ bottom: 3px;
861
+ width: 5px;
862
+ height: 5px;
863
+ border-right: 2px solid rgba(0, 0, 0, 0.4);
864
+ border-bottom: 2px solid rgba(0, 0, 0, 0.4);
865
+ }
866
+
867
+ .react-resizable-hide > .react-resizable-handle {
868
+ display: none;
869
+ }
870
+
871
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-sw {
872
+ bottom: 0;
873
+ left: 0;
874
+ cursor: sw-resize;
875
+ transform: rotate(90deg);
876
+ }
877
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-se {
878
+ bottom: 0;
879
+ right: 0;
880
+ cursor: se-resize;
881
+ }
882
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-nw {
883
+ top: 0;
884
+ left: 0;
885
+ cursor: nw-resize;
886
+ transform: rotate(180deg);
887
+ }
888
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-ne {
889
+ top: 0;
890
+ right: 0;
891
+ cursor: ne-resize;
892
+ transform: rotate(270deg);
893
+ }
894
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-w,
895
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-e {
896
+ top: 50%;
897
+ margin-top: -10px;
898
+ cursor: ew-resize;
899
+ }
900
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-w {
901
+ left: 0;
902
+ transform: rotate(135deg);
903
+ }
904
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-e {
905
+ right: 0;
906
+ transform: rotate(315deg);
907
+ }
908
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-n,
909
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-s {
910
+ left: 50%;
911
+ margin-left: -10px;
912
+ cursor: ns-resize;
913
+ }
914
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-n {
915
+ top: 0;
916
+ transform: rotate(225deg);
917
+ }
918
+ .M4LGridItem > .react-resizable-handle.react-resizable-handle-s {
919
+ bottom: 0;
920
+ transform: rotate(45deg);
921
+ }
922
+ .M4LGridItem.react-maximize-me > .react-resizable-handle,
923
+ .M4LGridItem.M4LResizeHide > .react-resizable-handle {
924
+ display: none;
925
+ }
926
+ .M4LGridItem.M4LInvisible {
927
+ display: none;
928
+ }
929
+
930
+ ${react_resizable_css}
931
+ `;
932
+ const layoutClassName = "M4LGridLayout";
933
+ function GridLayout(props) {
934
+ const {
935
+ innerRef,
936
+ autoSize = true,
937
+ cols = 12,
938
+ className = "",
939
+ style = {},
940
+ draggableHandle = "",
941
+ draggableCancel = "",
942
+ containerPadding = null,
943
+ rowHeight = 150,
944
+ maxRows = Infinity,
945
+ layout = [],
946
+ containerMargin = [10, 10],
947
+ isBounded = false,
948
+ isDraggable = true,
949
+ isResizable = true,
950
+ allowOverlap = false,
951
+ useCSSTransforms = true,
952
+ transformScale = 1,
953
+ compactType = null,
954
+ preventCollision = false,
955
+ resizeHandles = ["se"],
956
+ resizeHandle,
957
+ layoutItemRender: LayoutItemRender,
958
+ width = 1280,
959
+ height = 720,
960
+ onLayoutChange = noop,
961
+ onDragStart = noop,
962
+ onDrag = noop,
963
+ onDragStop = noop,
964
+ onResizeStart = noop,
965
+ onResize = noop,
966
+ onResizeStop = noop,
967
+ maximizeId,
968
+ colapsedHeight = 2
969
+ } = props;
970
+ const [currentState, setCurrentState] = useState({
971
+ mounted: false
972
+ });
973
+ const [finalLayoutRender, setFinalLayoutRender] = useState(layout);
974
+ const [zIndexes, setzIndexes] = useState(() => {
975
+ return layout.filter((li) => li.freeMove).map((lmap) => lmap.i);
976
+ });
977
+ const refZindexes = useRef(zIndexes);
978
+ const refState = useRef({
979
+ layout,
980
+ mounted: false,
981
+ oldDragItem: void 0,
982
+ oldLayout: void 0,
983
+ oldResizeItem: void 0
984
+ });
985
+ useEffect(() => {
986
+ setCurrentState({
987
+ mounted: true
988
+ });
989
+ }, []);
990
+ useEffect(() => {
991
+ if (!isEqualLayout(finalLayoutRender, layout)) {
992
+ console.debug("****useEffect GridLayout cambio de layout****", layout);
993
+ const newLayout = cloneLayout(layout);
994
+ const newzIndexes = [...zIndexes];
995
+ for (let index = 0; index < newLayout.length; index++) {
996
+ const li = newLayout[index];
997
+ if (li.freeMove && newzIndexes.indexOf(li.i) === -1) {
998
+ newzIndexes.push(li.i);
999
+ }
1000
+ }
1001
+ refState.current.layout = newLayout;
1002
+ setFinalLayoutRender(newLayout);
1003
+ if (newzIndexes.length !== zIndexes.length) {
1004
+ setzIndexes(newzIndexes);
1005
+ refZindexes.current = newzIndexes;
1006
+ }
1007
+ } else {
1008
+ console.debug("****useEffect cambio de layout sin cambios****");
1009
+ }
1010
+ }, [layout]);
1011
+ const containerHeight = () => {
1012
+ if (!autoSize)
1013
+ return;
1014
+ const nbRow = bottom(finalLayoutRender, colapsedHeight);
1015
+ const containerPaddingY = containerPadding ? containerPadding[1] : containerMargin[1];
1016
+ return nbRow * rowHeight + (nbRow - 1) * containerMargin[1] + containerPaddingY * 2 + "px";
1017
+ };
1018
+ const localOnDragStart = useCallback((i, _x, _y, gridDragEvent) => {
1019
+ const {
1020
+ layout: layout2
1021
+ } = refState.current;
1022
+ const {
1023
+ e,
1024
+ node
1025
+ } = gridDragEvent;
1026
+ const l = getLayoutItem(layout2, i);
1027
+ if (!l)
1028
+ return;
1029
+ refState.current = {
1030
+ ...refState.current,
1031
+ oldDragItem: cloneLayoutItem(l),
1032
+ oldLayout: [...layout2]
1033
+ };
1034
+ console.log("localOnDragStart");
1035
+ return onDragStart(layout2, l, l, void 0, e, node);
1036
+ }, []);
1037
+ const onLayoutMaybeChanged = useCallback((newLayout, oldLayout) => {
1038
+ console.log("onLayoutMaybeChanged", deepEqual(oldLayout, newLayout));
1039
+ if (!oldLayout) {
1040
+ oldLayout = refState.current.layout;
1041
+ }
1042
+ setFinalLayoutRender(newLayout);
1043
+ if (!isEqualLayout(oldLayout, newLayout)) {
1044
+ onLayoutChange(newLayout);
1045
+ }
1046
+ }, []);
1047
+ const localOnDrag = useCallback((i, x, y, gridDragEvent) => {
1048
+ const {
1049
+ oldDragItem,
1050
+ layout: layout2
1051
+ } = refState.current;
1052
+ const {
1053
+ e,
1054
+ node
1055
+ } = gridDragEvent;
1056
+ const l = getLayoutItem(layout2, i);
1057
+ if (!l)
1058
+ return;
1059
+ const newPlaceholder = {
1060
+ w: l.w,
1061
+ h: getLayoutItemH(l, colapsedHeight),
1062
+ x: l.x,
1063
+ y: l.y,
1064
+ placeholder: true,
1065
+ i
1066
+ };
1067
+ const isUserAction = true;
1068
+ try {
1069
+ let newLayout;
1070
+ if (!l.freeMove) {
1071
+ newLayout = moveElement(layout2, l, x, y, isUserAction, preventCollision, compactType, cols, colapsedHeight, allowOverlap);
1072
+ } else {
1073
+ l.x = x;
1074
+ l.y = y;
1075
+ newPlaceholder.x = x;
1076
+ newPlaceholder.y = y;
1077
+ newLayout = cloneLayout(layout2);
1078
+ }
1079
+ onDrag(newLayout, oldDragItem, l, newPlaceholder, e, node);
1080
+ const finalLayout = allowOverlap || l.freeMove ? newLayout : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1081
+ refState.current = {
1082
+ ...refState.current,
1083
+ layout: finalLayout,
1084
+ activeDrag: newPlaceholder
1085
+ };
1086
+ setCurrentState((prev) => ({
1087
+ ...prev,
1088
+ activeDrag: newPlaceholder
1089
+ }));
1090
+ setFinalLayoutRender([...finalLayout]);
1091
+ if (gridDragEvent.e.type !== "touchmove") {
1092
+ gridDragEvent.e.preventDefault();
1093
+ }
1094
+ gridDragEvent.e.stopPropagation();
1095
+ } catch (error) {
1096
+ console.warn("GridLayout error capturado");
1097
+ }
1098
+ }, []);
1099
+ const localOnDragStop = useCallback((i, x, y, {
1100
+ e,
1101
+ node
1102
+ }) => {
1103
+ if (!refState.current.activeDrag)
1104
+ return;
1105
+ const {
1106
+ oldDragItem,
1107
+ layout: layout2,
1108
+ oldLayout
1109
+ } = refState.current;
1110
+ const l = getLayoutItem(layout2, i);
1111
+ if (!l)
1112
+ return;
1113
+ let newLayout;
1114
+ const isUserAction = true;
1115
+ if (!l.freeMove) {
1116
+ newLayout = moveElement(layout2, l, x, y, isUserAction, preventCollision, compactType, cols, colapsedHeight, allowOverlap);
1117
+ } else {
1118
+ l.x = x;
1119
+ l.y = y;
1120
+ newLayout = cloneLayout(layout2);
1121
+ const nl = getLayoutItem(newLayout, i);
1122
+ if (nl) {
1123
+ nl.x = x;
1124
+ nl.y = y;
1125
+ }
1126
+ }
1127
+ onDragStop(layout2, oldDragItem, l, void 0, e, node);
1128
+ const finalLayout = allowOverlap ? newLayout || l.freeMove : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1129
+ setCurrentState((prev) => ({
1130
+ ...prev,
1131
+ activeDrag: void 0
1132
+ }));
1133
+ onLayoutMaybeChanged(finalLayout, oldLayout);
1134
+ refState.current = {
1135
+ ...refState.current,
1136
+ layout: finalLayout,
1137
+ oldDragItem: void 0,
1138
+ oldLayout: void 0,
1139
+ activeDrag: void 0
1140
+ };
1141
+ console.log("localOnDragStop");
1142
+ e.preventDefault();
1143
+ e.stopPropagation();
1144
+ }, []);
1145
+ const localOnResizeStart = useCallback((i, _w, _h, {
1146
+ e,
1147
+ node
1148
+ }) => {
1149
+ const {
1150
+ layout: layout2
1151
+ } = refState.current;
1152
+ const l = getLayoutItem(layout2, i);
1153
+ if (!l)
1154
+ return;
1155
+ refState.current = {
1156
+ ...refState.current,
1157
+ oldResizeItem: cloneLayoutItem(l),
1158
+ oldLayout: [...refState.current.layout]
1159
+ };
1160
+ onResizeStart(layout2, l, l, void 0, e, node);
1161
+ }, []);
1162
+ const localOnResize = useCallback((i, w, h, {
1163
+ e,
1164
+ node
1165
+ }) => {
1166
+ const {
1167
+ layout: layout2,
1168
+ oldResizeItem
1169
+ } = refState.current;
1170
+ let newLayout;
1171
+ let l;
1172
+ if (!oldResizeItem?.freeMove) {
1173
+ const [tempLayout, templ] = withLayoutItem(cloneLayout(layout2), i, (l2) => {
1174
+ let hasCollisions;
1175
+ if (preventCollision && !allowOverlap) {
1176
+ const collisions = getAllCollisions(layout2, {
1177
+ ...l2,
1178
+ w,
1179
+ h
1180
+ }, colapsedHeight).filter((layoutItem) => layoutItem.i !== l2.i);
1181
+ hasCollisions = collisions.length > 0;
1182
+ if (hasCollisions) {
1183
+ let leastX = Infinity, leastY = Infinity;
1184
+ collisions.forEach((layoutItem) => {
1185
+ if (layoutItem.x > l2.x)
1186
+ leastX = Math.min(leastX, layoutItem.x);
1187
+ if (layoutItem.y > l2.y)
1188
+ leastY = Math.min(leastY, layoutItem.y);
1189
+ });
1190
+ if (Number.isFinite(leastX))
1191
+ l2.w = leastX - l2.x;
1192
+ if (Number.isFinite(leastY))
1193
+ l2.h = leastY - l2.y;
1194
+ }
1195
+ }
1196
+ if (!hasCollisions) {
1197
+ l2.w = w;
1198
+ l2.h = h;
1199
+ }
1200
+ return l2;
1201
+ });
1202
+ newLayout = tempLayout;
1203
+ l = templ;
1204
+ } else {
1205
+ newLayout = cloneLayout(layout2);
1206
+ l = getLayoutItem(newLayout, i);
1207
+ if (l) {
1208
+ l.w = w;
1209
+ l.h = h;
1210
+ }
1211
+ }
1212
+ if (!l)
1213
+ return;
1214
+ const newPlaceholder = {
1215
+ w: l.w,
1216
+ h: l.h,
1217
+ x: l.x,
1218
+ y: l.y,
1219
+ static: true,
1220
+ i
1221
+ };
1222
+ try {
1223
+ const finalLayout = allowOverlap || l.freeMove ? newLayout : compact(newLayout, compactType, cols, colapsedHeight, allowOverlap);
1224
+ refState.current = {
1225
+ ...refState.current,
1226
+ layout: finalLayout,
1227
+ activeDrag: newPlaceholder
1228
+ };
1229
+ setFinalLayoutRender(finalLayout);
1230
+ setCurrentState((prev) => ({
1231
+ ...prev,
1232
+ activeDrag: newPlaceholder
1233
+ }));
1234
+ onResize(newLayout, oldResizeItem, l, newPlaceholder, e, node);
1235
+ } catch (error) {
1236
+ }
1237
+ }, []);
1238
+ const localOnResizeStop = useCallback((i, _w, _h, {
1239
+ e,
1240
+ node
1241
+ }) => {
1242
+ const {
1243
+ layout: layout2,
1244
+ oldResizeItem,
1245
+ oldLayout
1246
+ } = refState.current;
1247
+ const l = getLayoutItem(layout2, i);
1248
+ if (l) {
1249
+ onResizeStop(layout2, oldResizeItem, l, void 0, e, node);
1250
+ }
1251
+ const finalLayout = allowOverlap || l?.freeMove ? layout2 : compact(layout2, compactType, cols, colapsedHeight, allowOverlap);
1252
+ if (l && l?.freeMove) {
1253
+ const index = finalLayout.indexOf(l);
1254
+ if (index !== -1 && index !== finalLayout.length - 1) {
1255
+ finalLayout.splice(index, 1);
1256
+ finalLayout.push(l);
1257
+ }
1258
+ }
1259
+ refState.current = {
1260
+ ...refState.current,
1261
+ layout: [...finalLayout],
1262
+ oldResizeItem: void 0,
1263
+ oldLayout: void 0,
1264
+ activeDrag: void 0
1265
+ };
1266
+ setCurrentState((prev) => ({
1267
+ ...prev,
1268
+ activeDrag: void 0
1269
+ }));
1270
+ onLayoutMaybeChanged(finalLayout, oldLayout);
1271
+ }, []);
1272
+ const localFreeMoveOnClick = useCallback((i) => {
1273
+ const {
1274
+ layout: layout2
1275
+ } = refState.current;
1276
+ const index = refZindexes.current.indexOf(i);
1277
+ const l = getLayoutItem(layout2, i);
1278
+ console.log("localFreeMoveOnClick", index, l?.freeMove);
1279
+ if (l && l?.freeMove) {
1280
+ console.log("localFreeMoveOnClick", index, refZindexes.current.length);
1281
+ if (index !== refZindexes.current.length - 1 || index === -1) {
1282
+ const newIndexes = [...refZindexes.current];
1283
+ if (index !== -1) {
1284
+ newIndexes.splice(index, 1);
1285
+ }
1286
+ newIndexes.push(i);
1287
+ refZindexes.current = newIndexes;
1288
+ setzIndexes(newIndexes);
1289
+ }
1290
+ }
1291
+ }, []);
1292
+ const placeholder = () => {
1293
+ const {
1294
+ activeDrag
1295
+ } = currentState;
1296
+ if (!activeDrag)
1297
+ return null;
1298
+ return /* @__PURE__ */ jsx(MemonizedGridItem, {
1299
+ type: "placeholder",
1300
+ layoutItemRender: LayoutItemRender,
1301
+ w: activeDrag.w,
1302
+ h: activeDrag.h,
1303
+ x: activeDrag.x,
1304
+ y: activeDrag.y,
1305
+ i: activeDrag.i,
1306
+ className: "react-grid-placeholder",
1307
+ containerWidth: width,
1308
+ containerHeight: height,
1309
+ cols,
1310
+ margin: containerMargin,
1311
+ containerPadding: containerPadding || containerMargin,
1312
+ maxRows,
1313
+ rowHeight,
1314
+ isDraggable: false,
1315
+ isResizable: false,
1316
+ isBounded: false,
1317
+ useCSSTransforms,
1318
+ transformScale,
1319
+ cancel: "",
1320
+ handle: "",
1321
+ minW: 0,
1322
+ maxW: 0,
1323
+ minH: 0,
1324
+ maxH: 0,
1325
+ maximize: "none",
1326
+ colapsed: activeDrag.colapsed,
1327
+ colapsedHeight
1328
+ });
1329
+ };
1330
+ const processGridItem = useCallback((l, isMounted) => {
1331
+ const draggable = typeof l.isDraggable === "boolean" ? l.isDraggable : !l.static && isDraggable;
1332
+ const resizable = typeof l.isResizable === "boolean" ? l.isResizable : !l.static && isResizable;
1333
+ const resizeHandlesOptions = l.resizeHandles || resizeHandles;
1334
+ const bounded = draggable && isBounded && l.isBounded !== false;
1335
+ const mximize = maximizeId ? maximizeId === l.i ? "maximize_me" : "maximize_other" : "none";
1336
+ let zIndex = void 0;
1337
+ let style2;
1338
+ if (l.freeMove) {
1339
+ zIndex = zIndexes.indexOf(l.i);
1340
+ if (zIndex !== -1) {
1341
+ zIndex = zIndex + 1;
1342
+ style2 = {
1343
+ zIndex
1344
+ };
1345
+ }
1346
+ }
1347
+ return /* @__PURE__ */ jsx(MemonizedGridItem, {
1348
+ type: "layoutItem",
1349
+ layoutItemRender: LayoutItemRender,
1350
+ containerWidth: width,
1351
+ containerHeight: height,
1352
+ cols,
1353
+ margin: containerMargin,
1354
+ containerPadding: containerPadding || containerMargin,
1355
+ maxRows,
1356
+ rowHeight,
1357
+ cancel: draggableCancel,
1358
+ handle: draggableHandle,
1359
+ onDragStart: localOnDragStart,
1360
+ onDrag: localOnDrag,
1361
+ onDragStop: localOnDragStop,
1362
+ onResizeStart: localOnResizeStart,
1363
+ onResize: localOnResize,
1364
+ onResizeStop: localOnResizeStop,
1365
+ onFreeMoveClick: localFreeMoveOnClick,
1366
+ isDraggable: draggable,
1367
+ isResizable: resizable,
1368
+ isBounded: bounded,
1369
+ useCSSTransforms: useCSSTransforms && isMounted,
1370
+ usePercentages: !isMounted,
1371
+ transformScale,
1372
+ w: l.w,
1373
+ h: l.h,
1374
+ x: l.x,
1375
+ y: l.y,
1376
+ i: l.i,
1377
+ minH: l.minH,
1378
+ minW: l.minW,
1379
+ maxH: l.maxH,
1380
+ maxW: l.maxW,
1381
+ static: l.static,
1382
+ resizeHandles: resizeHandlesOptions,
1383
+ resizeHandle,
1384
+ maximize: mximize,
1385
+ freeMove: l.freeMove,
1386
+ colapsed: l.colapsed,
1387
+ visible: l.visible,
1388
+ colapsedHeight,
1389
+ style: style2
1390
+ }, l.i);
1391
+ }, [width, height, cols, containerMargin, containerPadding, maxRows, rowHeight, draggableCancel, draggableHandle, isDraggable, isResizable, isBounded, useCSSTransforms, transformScale, resizeHandles, resizeHandle, maximizeId, zIndexes]);
1392
+ const mergedStyle = {
1393
+ height: containerHeight(),
1394
+ ...style
1395
+ };
1396
+ return /* @__PURE__ */ jsxs(GridLayoutRoot, {
1397
+ className: clsx(layoutClassName, className),
1398
+ style: mergedStyle,
1399
+ ref: innerRef,
1400
+ children: [finalLayoutRender.map((li) => processGridItem(li, !!currentState.mounted)), placeholder()]
1401
+ });
1402
+ }
1403
+ export {
1404
+ GridLayout as G,
1405
+ cloneLayout as a,
1406
+ compact as b,
1407
+ cloneLayoutItem as c,
1408
+ correctBounds as d,
1409
+ noop as n
1410
+ };