@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.
- package/@types/export.d.ts +19 -0
- package/components/AccountPopover/{index.47cf6c43.js → index.3a79c395.js} +7 -6
- package/components/AppBar/{index.f04f5e45.js → index.71b38ee9.js} +7 -6
- package/components/CommonActions/components/ActionCancel/{index.453c2d24.js → index.b748a38e.js} +2 -2
- package/components/CommonActions/components/ActionFormCancel/{index.c2a2fd55.js → index.27ad09e1.js} +18 -18
- package/components/CommonActions/components/ActionFormIntro/{index.25d33912.js → index.2556f054.js} +2 -2
- package/components/CommonActions/components/ActionIntro/{index.c653a266.js → index.a7d92e66.js} +2 -2
- package/components/CommonActions/components/Actions/{index.e376a68e.js → index.3eba9d91.js} +16 -17
- package/components/DataGrid/{index.ffaf000e.js → index.545b492f.js} +42 -30
- package/components/DataGrid/types.d.ts +5 -1
- package/components/DraggableWindow/{index.b08af1dc.js → index.c702d3f2.js} +1 -1
- package/components/DynamicFilter/{index.d7c03a61.js → index.d7be0f37.js} +40 -33
- package/components/DynamicFilter/subcomponents/InnerForHooks/index.d.ts +2 -1
- package/components/DynamicFilter/subcomponents/InnerForHooks/types.d.ts +2 -0
- package/components/DynamicFilter/tests/contants.d.ts +1 -1
- package/components/DynamicFilter/types.d.ts +4 -0
- package/components/GridLayout/GridLayout.d.ts +6 -0
- package/components/GridLayout/Responsive/index.a12a8cec.js +335 -0
- package/components/GridLayout/WidthProvider/index.8ff65909.js +67 -0
- package/components/GridLayout/calculateUtils.d.ts +42 -0
- package/components/GridLayout/index.4ba3767a.js +1400 -0
- package/components/GridLayout/index.d.ts +6 -0
- package/components/GridLayout/subcomponents/GridItem/index.d.ts +25 -0
- package/components/GridLayout/subcomponents/GridItem/types.d.ts +76 -0
- package/components/GridLayout/subcomponents/Responsive/index.d.ts +3 -0
- package/components/GridLayout/subcomponents/Responsive/responsiveUtils.d.ts +61 -0
- package/components/GridLayout/subcomponents/Responsive/types.d.ts +71 -0
- package/components/GridLayout/subcomponents/WidthProvider/index.d.ts +16 -0
- package/components/GridLayout/types.d.ts +355 -0
- package/components/GridLayout/utils.d.ts +123 -0
- package/components/HelperText/{index.9864f773.js → index.ef31df1f.js} +7 -6
- package/components/Icon/{index.9dae8337.js → index.ecb63e65.js} +1 -1
- package/components/LanguagePopover/{index.938c6675.js → index.0023d069.js} +7 -6
- package/components/LinearProgressIndeterminate/{index.d34d398f.js → index.60dabc06.js} +1 -1
- package/components/ModalDialog/{index.d9c5d400.js → index.d880e685.js} +8 -56
- package/components/NavLink/{index.21c8fd90.js → index.cd92eceb.js} +7 -6
- package/components/ObjectLogs/{index.a2709fc2.js → index.f174c542.js} +19 -19
- package/components/PaperForm/{index.5e1bc99f.js → index.1bd86ee5.js} +1 -1
- package/components/Period/{index.526791a3.js → index.711db043.js} +21 -22
- package/components/Resizeable/{index.f6e48e56.js → index.9a9c79a4.js} +1 -1
- package/components/SideBar/{index.9e1a5b96.js → index.c5ce0bad.js} +5 -5
- package/components/areas/components/AreasAdmin/classes/index.d.ts +1 -1
- package/components/areas/components/AreasAdmin/classes/types.d.ts +2 -0
- package/components/areas/components/AreasAdmin/{index.946eebb9.js → index.cc4cbf56.js} +120 -46
- package/components/areas/components/AreasAdmin/subcomponents/AreaChip/types.d.ts +0 -1
- package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/index.d.ts +3 -0
- package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/PanelWindowPopUp/types.d.ts +3 -0
- package/components/areas/components/AreasViewer/classes/index.d.ts +1 -1
- package/components/areas/components/AreasViewer/classes/types.d.ts +2 -0
- package/components/areas/components/AreasViewer/{index.bf4191ea.js → index.9c2aaaeb.js} +258 -259
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/index.d.ts +1 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/index.d.ts +2 -2
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/index.d.ts +1 -7
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/index.d.ts +3 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/WindowPopUpsList/types.d.ts +2 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/types.d.ts +6 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/types.d.ts +1 -1
- package/components/areas/components/{index.2bb534cb.js → index.0f7ac464.js} +11 -10
- package/components/areas/contexts/AreasContext/helper.d.ts +6 -16
- package/components/areas/contexts/AreasContext/{index.f0397b7c.js → index.c8147e8e.js} +244 -339
- package/components/areas/contexts/AreasContext/types.d.ts +23 -20
- package/components/areas/contexts/{index.1809650a.js → index.02336412.js} +1 -1
- package/components/areas/{dictionary.3fabae50.js → dictionary.afb7e3d9.js} +5 -2
- package/components/areas/dictionary.d.ts +4 -1
- package/components/areas/hooks/useAreas/{index.40917e99.js → index.3406a6cb.js} +1 -1
- package/components/areas/{icons.19cde4b4.js → icons.8266ccc8.js} +5 -1
- package/components/areas/icons.d.ts +4 -0
- package/components/areas/{index.9bd48013.js → index.6f2e5dab.js} +11 -10
- package/components/areas/types.d.ts +30 -22
- package/components/formatters/BooleanFormatter/{index.431dc923.js → index.5268b024.js} +1 -1
- package/components/formatters/{index.e1af75e6.js → index.137169d8.js} +2 -2
- package/components/hook-form/RHFAutocomplete/{index.a063dc44.js → index.ac2b1fae.js} +8 -7
- package/components/hook-form/RHFAutocompleteAsync/{index.ddfd9cc9.js → index.8b4ccc8d.js} +1 -1
- package/components/hook-form/RHFCheckbox/{index.7e7f220b.js → index.acef119c.js} +1 -1
- package/components/hook-form/RHFDateTime/{index.d330709b.js → index.5b080342.js} +9 -8
- package/components/hook-form/RHFPeriod/{index.e2b1293b.js → index.5304e3bd.js} +2 -2
- package/components/hook-form/RHFTextField/{index.e5336d09.js → index.e751dca7.js} +5 -5
- package/components/hook-form/RHFUpload/{index.17e7f9eb.js → index.25db0511.js} +8 -7
- package/components/index.d.ts +1 -0
- package/components/modal/{WindowBase.7acb9f1d.js → WindowBase.850ea31a.js} +9 -8
- package/components/modal/{WindowConfirm.9b829837.js → WindowConfirm.cb37bc58.js} +18 -18
- package/components/modal/classes/index.d.ts +1 -0
- package/components/modal/classes/types.d.ts +1 -0
- package/components/modal/{index.1b25b61d.js → index.a0978193.js} +18 -16
- package/components/mui_extended/Accordion/{index.3faafd8b.js → index.12b1339a.js} +2 -2
- package/components/mui_extended/Badge/Badge.d.ts +3 -0
- package/components/mui_extended/Badge/classes/constants.d.ts +1 -0
- package/components/mui_extended/Badge/classes/index.d.ts +6 -0
- package/components/mui_extended/Badge/classes/types.d.ts +6 -0
- package/components/mui_extended/Badge/index.8c2b8b66.js +36 -0
- package/components/mui_extended/Badge/index.d.ts +2 -0
- package/components/mui_extended/Badge/tests/constants.d.ts +1 -0
- package/components/mui_extended/Badge/tests/utils.d.ts +2 -0
- package/components/mui_extended/Badge/types.d.ts +4 -0
- package/components/mui_extended/Button/{index.fdb5dcbd.js → index.4288f9fc.js} +8 -3
- package/components/mui_extended/IconButton/{index.1a9d4fa5.js → index.fc5b7c2d.js} +1 -1
- package/components/mui_extended/MenuActions/{index.ba1da3b3.js → index.f5b1c022.js} +28 -9
- package/components/mui_extended/MenuActions/types.d.ts +8 -0
- package/components/mui_extended/Pager/{index.67bda2c5.js → index.435af0df.js} +1 -1
- package/components/mui_extended/{index.73e536de.js → index.83979b6a.js} +7 -6
- package/components/mui_extended/index.d.ts +1 -0
- package/contexts/ModalContext/{index.699f95fa.js → index.dee85a61.js} +1 -1
- package/hooks/useModal/{index.7b7d26ba.js → index.de522a10.js} +1 -1
- package/index.js +94 -83
- package/node_modules.d73a220d.js +363 -0
- package/package.json +4 -3
- package/{react-draggable.6d7949a3.js → react-draggable.7abb5d0a.js} +3 -2
- package/{react-resizable.b6f8e04a.js → react-resizable.ba08699a.js} +13 -12
- package/utils/{index.008b4c2a.js → index.c43a95f4.js} +0 -15
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/WindowPopUp/index.d.ts +0 -4
- package/components/modal/ModalDialog/types.d.ts +0 -7
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/{GridLayout → AreaGridLayout}/types.d.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field } from '../types';
|
|
2
|
-
export declare const DYNAMICFILTER_TEST_ID = "
|
|
2
|
+
export declare const DYNAMICFILTER_TEST_ID = "M4LDynamicFilter";
|
|
3
3
|
export declare const PREFIX_TEST_ATTRIBUTE = "data-test";
|
|
4
4
|
export declare const TEST_PROP_FIELDS: string;
|
|
5
5
|
export declare const TEST_FIELDS: Field[];
|
|
@@ -213,4 +213,8 @@ export interface DynamicFilterProps {
|
|
|
213
213
|
* "onChangeFilters" Handler que se dispara cuando el filtro cambia en automatico, o cuando es manual y se presion a el boton de filtrar
|
|
214
214
|
*/
|
|
215
215
|
onChangeFilters: OnChangeFilters;
|
|
216
|
+
/**
|
|
217
|
+
* "dataTestId" Propiedad única que permite crear un selector atributo necesario para las pruebas del componente.
|
|
218
|
+
*/
|
|
219
|
+
dataTestId?: string;
|
|
216
220
|
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { c as cloneLayoutItem, a as cloneLayout, b as compact, d as correctBounds, G as GridLayout, n as noop } from "../index.4ba3767a.js";
|
|
2
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
3
|
+
import { useFirstRender } from "@m4l/graphics";
|
|
4
|
+
import { d as deepEqual } from "../../../node_modules.d73a220d.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function getBreakpointFromWidth(breakpoints, width) {
|
|
7
|
+
const sorted = sortBreakpoints(breakpoints);
|
|
8
|
+
let matching = sorted[0];
|
|
9
|
+
for (let i = 1, len = sorted.length; i < len; i++) {
|
|
10
|
+
const breakpointName = sorted[i];
|
|
11
|
+
if (width > breakpoints[breakpointName])
|
|
12
|
+
matching = breakpointName;
|
|
13
|
+
}
|
|
14
|
+
return matching;
|
|
15
|
+
}
|
|
16
|
+
function getColsFromBreakpoint(breakpoint, cols) {
|
|
17
|
+
if (!cols[breakpoint]) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"ResponsiveReactGridLayout: `cols` entry for breakpoint " + breakpoint + " is missing!"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return cols[breakpoint];
|
|
23
|
+
}
|
|
24
|
+
function findOrGenerateResponsiveLayout(layouts, breakpoints, breakpoint, lastBreakpoint, cols, compactType, brekpointsCols, colapsedHeight, colapsedItems) {
|
|
25
|
+
let layout = layouts[breakpoint];
|
|
26
|
+
const breakpointsSorted = sortBreakpoints(breakpoints);
|
|
27
|
+
const indexBreakointInit = breakpointsSorted.indexOf(breakpoint);
|
|
28
|
+
let compareBreakpoint;
|
|
29
|
+
console.log("findOrGenerateResponsiveLayout start", layout);
|
|
30
|
+
if (!layout) {
|
|
31
|
+
if (lastBreakpoint !== breakpoint && layouts[lastBreakpoint]) {
|
|
32
|
+
compareBreakpoint = lastBreakpoint;
|
|
33
|
+
} else {
|
|
34
|
+
const rotatedBreakpoints = [
|
|
35
|
+
...breakpointsSorted.splice(indexBreakointInit),
|
|
36
|
+
...breakpointsSorted.reverse()
|
|
37
|
+
];
|
|
38
|
+
console.log("findOrGenerateResponsiveLayout rotatedBreakpoints ", rotatedBreakpoints);
|
|
39
|
+
for (let i = 0, len = rotatedBreakpoints.length; i < len; i++) {
|
|
40
|
+
const b = rotatedBreakpoints[i];
|
|
41
|
+
if (layouts[b]) {
|
|
42
|
+
console.log("findOrGenerateResponsiveLayout above I*:", i, b);
|
|
43
|
+
compareBreakpoint = b;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
console.log("findOrGenerateResponsiveLayout compareBreakpoint ", compareBreakpoint);
|
|
49
|
+
if (compareBreakpoint) {
|
|
50
|
+
layout = [];
|
|
51
|
+
for (let i = 0, len = layouts[compareBreakpoint].length; i < len; i++) {
|
|
52
|
+
const li = cloneLayoutItem(layouts[compareBreakpoint][i]);
|
|
53
|
+
if (brekpointsCols[compareBreakpoint]) {
|
|
54
|
+
const newW = Math.round(li.w * cols / brekpointsCols[compareBreakpoint]);
|
|
55
|
+
console.log(
|
|
56
|
+
`findOrGenerateResponsiveLayout li:${li.i}, actual: ${li.w} -> new: ${newW} `,
|
|
57
|
+
compareBreakpoint
|
|
58
|
+
);
|
|
59
|
+
li.w = newW;
|
|
60
|
+
}
|
|
61
|
+
layout.push(li);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!layout) {
|
|
65
|
+
layout = [];
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
layout = cloneLayout(layout);
|
|
69
|
+
}
|
|
70
|
+
console.log("findOrGenerateResponsiveLayout layout filtrado:", layout);
|
|
71
|
+
layout = cloneLayout(layout);
|
|
72
|
+
for (let index = 0; index < layout.length; index++) {
|
|
73
|
+
const element = layout[index];
|
|
74
|
+
element.colapsed = false;
|
|
75
|
+
if (colapsedItems && colapsedItems[element.i]) {
|
|
76
|
+
element.colapsed = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
console.log("findOrGenerateResponsiveLayout layout clonado:", layout);
|
|
80
|
+
const ret = compact(
|
|
81
|
+
correctBounds(layout, { cols }, colapsedHeight),
|
|
82
|
+
compactType,
|
|
83
|
+
cols,
|
|
84
|
+
colapsedHeight
|
|
85
|
+
);
|
|
86
|
+
console.log("findOrGenerateResponsiveLayout layout ret **:", ret);
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
89
|
+
function sortBreakpoints(breakpoints) {
|
|
90
|
+
const keys = Object.keys(breakpoints);
|
|
91
|
+
return keys.sort(function(a, b) {
|
|
92
|
+
return breakpoints[a] - breakpoints[b];
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function getIndentationValue(param, breakpoint) {
|
|
96
|
+
if (!param)
|
|
97
|
+
return [0, 0];
|
|
98
|
+
return Array.isArray(param) ? param : param[breakpoint];
|
|
99
|
+
}
|
|
100
|
+
function addLayoutItemToBreakPointIfNoExists(layouts, breakpoint, layoutItem, cols, margin, containerPadding, rowHeight, containerHeight) {
|
|
101
|
+
if (!layouts[breakpoint])
|
|
102
|
+
return;
|
|
103
|
+
if (layouts[breakpoint].findIndex((l) => l.i === layoutItem.i) === -1) {
|
|
104
|
+
const l = cloneLayoutItem(layoutItem);
|
|
105
|
+
const heigthUnits = containerHeight !== void 0 ? (containerHeight + getIndentationValue(margin, breakpoint)[1] - 2 * getIndentationValue(containerPadding, breakpoint)[1]) / (rowHeight + getIndentationValue(margin, breakpoint)[1]) : l.h;
|
|
106
|
+
if (l.freeMove) {
|
|
107
|
+
l.x = Math.round(cols[breakpoint] / 4);
|
|
108
|
+
l.y = Math.round(heigthUnits / 4);
|
|
109
|
+
l.w = Math.round(cols[breakpoint] / 2);
|
|
110
|
+
l.h = heigthUnits / 2;
|
|
111
|
+
} else {
|
|
112
|
+
l.w = cols[breakpoint];
|
|
113
|
+
l.h = Math.round(heigthUnits * 0.8);
|
|
114
|
+
}
|
|
115
|
+
if (breakpoint === "xxs") {
|
|
116
|
+
if (l.freeMove) {
|
|
117
|
+
l.visible = false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (l.freeMove) {
|
|
121
|
+
layouts[breakpoint].push(l);
|
|
122
|
+
} else {
|
|
123
|
+
layouts[breakpoint].unshift(l);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function addLayoutItemToBreakPoints(layouts, layoutItem, cols, margin, containerPadding, rowHeight, containerHeight) {
|
|
128
|
+
const newLayouts = {};
|
|
129
|
+
for (const key in layouts) {
|
|
130
|
+
const layoutBreakpoint = cloneLayout(layouts[key]);
|
|
131
|
+
newLayouts[key] = layoutBreakpoint;
|
|
132
|
+
addLayoutItemToBreakPointIfNoExists(
|
|
133
|
+
newLayouts,
|
|
134
|
+
key,
|
|
135
|
+
layoutItem,
|
|
136
|
+
cols,
|
|
137
|
+
margin,
|
|
138
|
+
containerPadding,
|
|
139
|
+
rowHeight,
|
|
140
|
+
containerHeight
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return newLayouts;
|
|
144
|
+
}
|
|
145
|
+
function cloneLayouts(layouts, layoutItemReplaceProps) {
|
|
146
|
+
console.log("cloneLayout");
|
|
147
|
+
const newLayouts = {};
|
|
148
|
+
for (const breakPoint in layouts) {
|
|
149
|
+
newLayouts[breakPoint] = cloneLayout(layouts[breakPoint], layoutItemReplaceProps);
|
|
150
|
+
}
|
|
151
|
+
return newLayouts;
|
|
152
|
+
}
|
|
153
|
+
function generateInitialState(props) {
|
|
154
|
+
const {
|
|
155
|
+
width,
|
|
156
|
+
breakpoint,
|
|
157
|
+
breakpoints,
|
|
158
|
+
containerPadding = [10, 10],
|
|
159
|
+
containerMargin = [10, 10],
|
|
160
|
+
layouts: defaultLayouts = {},
|
|
161
|
+
cols,
|
|
162
|
+
compactType = null,
|
|
163
|
+
colapsedItems,
|
|
164
|
+
colapsedHeight = 2
|
|
165
|
+
} = props;
|
|
166
|
+
const newBreakpoint = breakpoint || getBreakpointFromWidth(breakpoints, width);
|
|
167
|
+
const colNo = getColsFromBreakpoint(newBreakpoint, cols);
|
|
168
|
+
let fireOnLoadLayoutChange = true;
|
|
169
|
+
const initialLayout = findOrGenerateResponsiveLayout(defaultLayouts, breakpoints, newBreakpoint, newBreakpoint, colNo, compactType, {
|
|
170
|
+
[newBreakpoint]: colNo
|
|
171
|
+
}, colapsedHeight, colapsedItems);
|
|
172
|
+
if (defaultLayouts[newBreakpoint]) {
|
|
173
|
+
if (deepEqual(defaultLayouts[newBreakpoint], initialLayout)) {
|
|
174
|
+
fireOnLoadLayoutChange = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const ret = {
|
|
178
|
+
layout: initialLayout,
|
|
179
|
+
breakpoint: newBreakpoint,
|
|
180
|
+
cols: colNo,
|
|
181
|
+
contaierMargin: getIndentationValue(containerMargin, newBreakpoint),
|
|
182
|
+
contaierPadding: getIndentationValue(containerPadding, newBreakpoint),
|
|
183
|
+
fireOnLoadLayoutChange
|
|
184
|
+
};
|
|
185
|
+
console.log("generateInitialState", ret, initialLayout);
|
|
186
|
+
return ret;
|
|
187
|
+
}
|
|
188
|
+
function Responsive(props) {
|
|
189
|
+
const {
|
|
190
|
+
width,
|
|
191
|
+
height,
|
|
192
|
+
breakpoint,
|
|
193
|
+
compactType = null,
|
|
194
|
+
breakpoints = {
|
|
195
|
+
lg: 1200,
|
|
196
|
+
md: 996,
|
|
197
|
+
sm: 768,
|
|
198
|
+
xs: 480,
|
|
199
|
+
xxs: 1
|
|
200
|
+
},
|
|
201
|
+
cols = {
|
|
202
|
+
lg: 12,
|
|
203
|
+
md: 10,
|
|
204
|
+
sm: 6,
|
|
205
|
+
xs: 4,
|
|
206
|
+
xxs: 2
|
|
207
|
+
},
|
|
208
|
+
containerPadding = [10, 10],
|
|
209
|
+
containerMargin = [10, 10],
|
|
210
|
+
layouts = {},
|
|
211
|
+
onBreakpointChange = noop,
|
|
212
|
+
onLayoutChange = noop,
|
|
213
|
+
onContainerChange = noop,
|
|
214
|
+
layoutItemRender,
|
|
215
|
+
colapsedItems,
|
|
216
|
+
colapsedHeight = 2,
|
|
217
|
+
...other
|
|
218
|
+
} = props;
|
|
219
|
+
const [currentState, setCurrentState] = useState(() => generateInitialState(props));
|
|
220
|
+
const refLayouts = useRef({
|
|
221
|
+
layouts: {
|
|
222
|
+
...layouts,
|
|
223
|
+
[currentState.breakpoint]: currentState.layout
|
|
224
|
+
},
|
|
225
|
+
breakpoint: currentState.breakpoint,
|
|
226
|
+
breakpoints,
|
|
227
|
+
colapsedItems,
|
|
228
|
+
width,
|
|
229
|
+
height
|
|
230
|
+
});
|
|
231
|
+
const isFirstRender = useFirstRender([width, height, layouts]);
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
console.log("useEffect componente", currentState.fireOnLoadLayoutChange);
|
|
234
|
+
onContainerChange({
|
|
235
|
+
containerWidth: refLayouts.current.width,
|
|
236
|
+
containerHeight: refLayouts.current.height,
|
|
237
|
+
containerMargin: currentState.contaierMargin,
|
|
238
|
+
containerPadding: currentState.contaierPadding,
|
|
239
|
+
breakpoint: currentState.breakpoint,
|
|
240
|
+
cols: currentState.cols
|
|
241
|
+
});
|
|
242
|
+
if (currentState.fireOnLoadLayoutChange) {
|
|
243
|
+
onLayoutChange(currentState.layout, {
|
|
244
|
+
...layouts,
|
|
245
|
+
[currentState.breakpoint]: currentState.layout
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return () => {
|
|
249
|
+
console.debug("destruccion del componente");
|
|
250
|
+
};
|
|
251
|
+
}, []);
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
if (isFirstRender) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const newBreakpoint = breakpoint || getBreakpointFromWidth(breakpoints, width);
|
|
257
|
+
const newCols = getColsFromBreakpoint(newBreakpoint, cols);
|
|
258
|
+
const lastBreakpoint = currentState.breakpoint;
|
|
259
|
+
const newLayouts = {
|
|
260
|
+
...layouts
|
|
261
|
+
};
|
|
262
|
+
let newContainerMargin = currentState.contaierMargin;
|
|
263
|
+
let newContainerPadding = currentState.contaierPadding;
|
|
264
|
+
console.debug("useEffect responsive newLayouts es igual:", deepEqual(layouts, refLayouts.current.layouts), refLayouts.current.layouts);
|
|
265
|
+
if (newBreakpoint !== currentState.breakpoint || newCols !== currentState.cols || breakpoints !== refLayouts.current.breakpoints || colapsedItems !== refLayouts.current.colapsedItems || !deepEqual(layouts, refLayouts.current.layouts)) {
|
|
266
|
+
console.debug("useEffect responsive con cambio de algo", newBreakpoint, lastBreakpoint);
|
|
267
|
+
newContainerMargin = getIndentationValue(containerMargin, newBreakpoint);
|
|
268
|
+
newContainerPadding = getIndentationValue(containerPadding, newBreakpoint);
|
|
269
|
+
if (!(lastBreakpoint in newLayouts)) {
|
|
270
|
+
console.error("useEffect casi imposible", lastBreakpoint, newLayouts);
|
|
271
|
+
newLayouts[lastBreakpoint] = cloneLayout(currentState.layout);
|
|
272
|
+
}
|
|
273
|
+
const layout = findOrGenerateResponsiveLayout(newLayouts, breakpoints, newBreakpoint, lastBreakpoint, newCols, compactType, cols, colapsedHeight, colapsedItems);
|
|
274
|
+
newLayouts[newBreakpoint] = layout;
|
|
275
|
+
if (newBreakpoint !== currentState.breakpoint) {
|
|
276
|
+
onBreakpointChange(newBreakpoint, newCols, width, height);
|
|
277
|
+
}
|
|
278
|
+
refLayouts.current.layouts = newLayouts;
|
|
279
|
+
refLayouts.current.breakpoint = newBreakpoint;
|
|
280
|
+
refLayouts.current.breakpoints = breakpoints;
|
|
281
|
+
refLayouts.current.colapsedItems = colapsedItems;
|
|
282
|
+
console.debug("useEffect responsive****", layout);
|
|
283
|
+
setCurrentState({
|
|
284
|
+
breakpoint: newBreakpoint,
|
|
285
|
+
layout,
|
|
286
|
+
cols: newCols,
|
|
287
|
+
contaierMargin: newContainerMargin,
|
|
288
|
+
contaierPadding: newContainerPadding
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
onContainerChange({
|
|
292
|
+
containerWidth: width,
|
|
293
|
+
containerHeight: height,
|
|
294
|
+
containerMargin: newContainerMargin,
|
|
295
|
+
containerPadding: newContainerPadding,
|
|
296
|
+
breakpoint: newBreakpoint,
|
|
297
|
+
cols: newCols
|
|
298
|
+
});
|
|
299
|
+
}, [width, height, layouts, breakpoint, breakpoints, colapsedItems]);
|
|
300
|
+
const localOnLayoutChange = useCallback((newlayout) => {
|
|
301
|
+
console.log("localOnLayoutChange layouts antes de iniciar", refLayouts.current.layouts, newlayout);
|
|
302
|
+
try {
|
|
303
|
+
refLayouts.current.layouts[refLayouts.current.breakpoint] = cloneLayout(newlayout);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
console.warn("localOnLayoutChange error");
|
|
306
|
+
}
|
|
307
|
+
setCurrentState((prev) => ({
|
|
308
|
+
...prev,
|
|
309
|
+
layout: cloneLayout(newlayout)
|
|
310
|
+
}));
|
|
311
|
+
onLayoutChange(newlayout, {
|
|
312
|
+
...refLayouts.current.layouts
|
|
313
|
+
});
|
|
314
|
+
}, [onLayoutChange]);
|
|
315
|
+
console.log("Render ResponsiveReactGridLayout: ", layouts, currentState, width, height);
|
|
316
|
+
return /* @__PURE__ */ jsx(GridLayout, {
|
|
317
|
+
width,
|
|
318
|
+
height,
|
|
319
|
+
colapsedHeight,
|
|
320
|
+
layoutItemRender,
|
|
321
|
+
containerMargin: currentState.contaierMargin,
|
|
322
|
+
containerPadding: getIndentationValue(containerPadding, currentState.breakpoint),
|
|
323
|
+
onLayoutChange: localOnLayoutChange,
|
|
324
|
+
layout: currentState.layout,
|
|
325
|
+
cols: currentState.cols,
|
|
326
|
+
compactType,
|
|
327
|
+
...other
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
export {
|
|
331
|
+
Responsive as R,
|
|
332
|
+
addLayoutItemToBreakPointIfNoExists as a,
|
|
333
|
+
addLayoutItemToBreakPoints as b,
|
|
334
|
+
cloneLayouts as c
|
|
335
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useRef, useState, useMemo, useCallback, useEffect } from "react";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { throttle } from "lodash";
|
|
4
|
+
import { useResizeObserver } from "@m4l/graphics";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
const THROTTLE_RESIZE_TIME = 200;
|
|
7
|
+
const layoutClassName = "react-grid-layout";
|
|
8
|
+
function WidthProvider(ComposedComponent) {
|
|
9
|
+
return (props) => {
|
|
10
|
+
const {
|
|
11
|
+
measureBeforeMount = true,
|
|
12
|
+
...rest
|
|
13
|
+
} = props;
|
|
14
|
+
const refMounted = useRef(false);
|
|
15
|
+
const [currentState, setCurrentState] = useState({
|
|
16
|
+
mounted: false,
|
|
17
|
+
width: 1280,
|
|
18
|
+
height: 100
|
|
19
|
+
});
|
|
20
|
+
const onWindowResizeMemo = useMemo(() => () => {
|
|
21
|
+
const node = elementRef.current;
|
|
22
|
+
if (node instanceof HTMLElement && node.offsetWidth) {
|
|
23
|
+
console.log("onWindowResize*******************************", node.offsetWidth, node.offsetHeight);
|
|
24
|
+
setCurrentState((prev) => ({
|
|
25
|
+
...prev,
|
|
26
|
+
width: node.offsetWidth,
|
|
27
|
+
height: node.offsetHeight
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
const throttleResize = throttle(onWindowResizeMemo, THROTTLE_RESIZE_TIME, {
|
|
32
|
+
leading: false,
|
|
33
|
+
trailing: true
|
|
34
|
+
});
|
|
35
|
+
const onResize = useCallback((_target) => {
|
|
36
|
+
throttleResize();
|
|
37
|
+
}, []);
|
|
38
|
+
const elementRef = useResizeObserver(onResize);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setCurrentState((prev) => ({
|
|
41
|
+
...prev,
|
|
42
|
+
mounted: true
|
|
43
|
+
}));
|
|
44
|
+
refMounted.current = true;
|
|
45
|
+
onWindowResizeMemo();
|
|
46
|
+
return () => {
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
if (measureBeforeMount && !currentState.mounted) {
|
|
50
|
+
return /* @__PURE__ */ jsx("div", {
|
|
51
|
+
className: clsx(props.className, layoutClassName),
|
|
52
|
+
style: props.style,
|
|
53
|
+
ref: elementRef
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
console.log("Render with provider");
|
|
57
|
+
return /* @__PURE__ */ jsx(ComposedComponent, {
|
|
58
|
+
innerRef: elementRef,
|
|
59
|
+
width: currentState.width,
|
|
60
|
+
height: currentState.height,
|
|
61
|
+
...rest
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
WidthProvider as W
|
|
67
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { GridItemState, Maximize } from './subcomponents/GridItem/types';
|
|
2
|
+
import { Position, PositionParams } from './types';
|
|
3
|
+
export declare function calcGridColWidth(positionParams: PositionParams): number;
|
|
4
|
+
export declare function calcGridItemWHPx(gridUnits: number, colOrRowSize: number, marginPx: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* Return position on the page given an x, y, w, h.
|
|
7
|
+
* left, top, width, height are all in pixels.
|
|
8
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
|
|
9
|
+
* @param {Number} x X coordinate in grid units.
|
|
10
|
+
* @param {Number} y Y coordinate in grid units.
|
|
11
|
+
* @param {Number} w W coordinate in grid units.
|
|
12
|
+
* @param {Number} h H coordinate in grid units.
|
|
13
|
+
* @return {Position} Object containing coords.
|
|
14
|
+
*/
|
|
15
|
+
export declare function calcGridItemPosition(positionParams: PositionParams, x: number, y: number, w: number, h: number, maximize: Maximize, state?: GridItemState): Position;
|
|
16
|
+
/**
|
|
17
|
+
* Translate x and y coordinates from pixels to grid units.
|
|
18
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calculations.
|
|
19
|
+
* @param {Number} top Top position (relative to parent) in pixels.
|
|
20
|
+
* @param {Number} left Left position (relative to parent) in pixels.
|
|
21
|
+
* @param {Number} w W coordinate in grid units.
|
|
22
|
+
* @param {Number} h H coordinate in grid units.
|
|
23
|
+
* @return {Object} x and y in grid units.
|
|
24
|
+
*/
|
|
25
|
+
export declare function calcXY(positionParams: PositionParams, top: number, left: number, w: number, h: number): {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Given a height and width in pixel values, calculate grid units.
|
|
31
|
+
* @param {PositionParams} positionParams Parameters of grid needed for coordinates calcluations.
|
|
32
|
+
* @param {Number} height Height in pixels.
|
|
33
|
+
* @param {Number} width Width in pixels.
|
|
34
|
+
* @param {Number} x X coordinate in grid units.
|
|
35
|
+
* @param {Number} y Y coordinate in grid units.
|
|
36
|
+
* @return {Object} w, h as grid units.
|
|
37
|
+
*/
|
|
38
|
+
export declare function calcWH(positionParams: PositionParams, width: number, height: number, x: number, y: number): {
|
|
39
|
+
w: number;
|
|
40
|
+
h: number;
|
|
41
|
+
};
|
|
42
|
+
export declare function clamp(num: number, lowerBound: number, upperBound: number): number;
|