@m4l/components 0.1.69 → 0.1.70
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 +7 -1
- package/components/CommonActions/components/ActionCancel/{index.e83053da.js → index.9d521b2a.js} +2 -2
- package/components/CommonActions/components/ActionFormCancel/{index.ca378b0a.js → index.4756457f.js} +25 -13
- package/components/CommonActions/components/ActionFormIntro/{index.fa2107df.js → index.40321b1b.js} +2 -2
- package/components/CommonActions/components/ActionIntro/{index.b8d5c8ee.js → index.1ba5b02b.js} +3 -3
- package/components/CommonActions/components/Actions/{index.1b2a0921.js → index.154d7cb6.js} +23 -13
- package/components/DataGrid/{index.75ea6038.js → index.2f4a0e64.js} +21 -19
- package/components/DynamicFilter/{index.aaeea668.js → index.789ab474.js} +36 -40
- package/components/HelperText/{index.742d547d.js → index.a69e9509.js} +8 -8
- package/components/Icon/{index.952f0635.js → index.caaed284.js} +2 -2
- package/components/Image/{index.f30f79f0.js → index.82a6cd46.js} +1 -1
- package/components/LanguagePopover/{index.526e544e.js → index.5af28b9e.js} +9 -9
- package/components/ModalDialog/{index.4d663d0a.js → index.cdfd1ae8.js} +5 -5
- package/components/NavLink/{index.92008184.js → index.251fcf0d.js} +9 -9
- package/components/NoItemSelected/{index.6f2952ab.js → index.3b9d16e3.js} +1 -1
- package/components/ObjectLogs/{index.d1eee18b.js → index.57ea68b3.js} +17 -15
- package/components/PaperForm/{index.e9db704b.js → index.d2d492ea.js} +1 -1
- package/components/Period/{index.3ff6f53b.js → index.fbf074d3.js} +24 -14
- package/components/Resizeable/{index.ff97422e.js → index.aafda79e.js} +1 -1
- package/components/SideBar/{index.365f64f0.js → index.3bc6a634.js} +10 -24
- package/components/areas/components/AreasAdmin/classes/types.d.ts +1 -0
- package/components/areas/components/AreasAdmin/subcomponents/AreaChip/types.d.ts +1 -0
- package/components/areas/components/AreasViewer/classes/types.d.ts +1 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/index.d.ts +2 -2
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/GridLayout/index.d.ts +2 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/GridLayout/types.d.ts +3 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/InnerForHooks/index.d.ts +2 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/InnerForHooks/types.d.ts +3 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/PanelWindows/index.d.ts +2 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/PanelWindows/types.d.ts +3 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/index.d.ts +1 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/styles.d.ts +2 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Component/index.d.ts +4 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Component/types.d.ts +9 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/helper.d.ts +3 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/index.d.ts +9 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/Header/subcomponents/MainActions/index.d.ts +6 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/MicroFrontend/index.d.ts +4 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/index.d.ts +2 -2
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/MicroFrontend/subcomponents/MFLoader/types.d.ts +8 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/MicroFrontend/types.d.ts +8 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/types.d.ts +2 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/types.d.ts +4 -0
- package/components/areas/components/{index.ffb147c7.js → index.359c2b18.js} +443 -1069
- package/components/areas/components/index.d.ts +1 -1
- package/components/areas/contexts/AreasContext/helper.d.ts +59 -0
- package/components/areas/contexts/AreasContext/index.de8b4e78.js +1015 -0
- package/components/areas/contexts/AreasContext/store.d.ts +1 -2
- package/components/areas/contexts/AreasContext/types.d.ts +86 -13
- package/components/areas/contexts/DynamicMFParmsContext/index.1607c78e.js +42 -0
- package/components/areas/contexts/DynamicMFParmsContext/index.d.ts +8 -0
- package/components/areas/{components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts → contexts}/DynamicMFParmsContext/store.d.ts +3 -9
- package/components/areas/contexts/WindowToolsMFContext/index.8f3e2a04.js +20 -0
- package/components/areas/{components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts → contexts}/WindowToolsMFContext/types.d.ts +3 -2
- package/components/areas/contexts/index.771827bb.js +2 -0
- package/components/areas/contexts/index.d.ts +4 -4
- package/components/areas/dictionary.d.ts +1 -0
- package/components/areas/hooks/index.ae8d8631.js +13 -0
- package/components/areas/hooks/useArea/index.2adbe001.js +12 -0
- package/components/areas/hooks/useDynamicMFParameters/index.d.ts +3 -9
- package/components/areas/hooks/useDynamicMFParameters/{index.7ce7176f.js → index.e52c5392.js} +1 -1
- package/components/areas/hooks/useWindowToolsMF/index.d.ts +1 -1
- package/components/areas/icons.d.ts +3 -0
- package/components/areas/{index.20cbd7b7.js → index.8a58bcbf.js} +14 -8
- package/components/areas/types.d.ts +32 -23
- package/components/formatters/BooleanFormatter/{index.d5e21bdd.js → index.7eb0498c.js} +1 -1
- package/components/formatters/{index.650243bb.js → index.f6b9ed01.js} +2 -2
- package/components/hook-form/RHFAutocomplete/{index.21377a2c.js → index.09c400c3.js} +10 -10
- package/components/hook-form/RHFAutocompleteAsync/{index.8c7e0842.js → index.e8acff04.js} +2 -2
- package/components/hook-form/RHFCheckbox/{index.83902d07.js → index.70310f35.js} +3 -3
- package/components/hook-form/RHFDateTime/{index.166250d8.js → index.7b815072.js} +9 -9
- package/components/hook-form/RHFPeriod/{index.61baf76f.js → index.3c7d393c.js} +2 -2
- package/components/hook-form/RHFTextField/{index.55687a39.js → index.d4c39859.js} +6 -7
- package/components/hook-form/RHFUpload/{index.eb4d0dac.js → index.31044674.js} +1 -1
- package/components/modal/WindowBase/subcomponents/Header/types.d.ts +1 -1
- package/components/modal/WindowBase/types.d.ts +1 -0
- package/components/modal/{WindowBase.7ce0b21e.js → WindowBase.6a40a945.js} +28 -21
- package/components/modal/{WindowConfirm.7ae1326f.js → WindowConfirm.e21763cb.js} +17 -15
- package/components/modal/index.438777d9.js +34 -0
- package/components/mui_extended/Accordion/{index.51feece8.js → index.437bb3f8.js} +2 -2
- package/components/mui_extended/Button/{index.b34c8b68.js → index.f8ce9ccd.js} +3 -3
- package/components/mui_extended/IconButton/{index.917f0d3c.js → index.57824447.js} +1 -3
- package/components/mui_extended/MenuActions/{index.651dec44.js → index.37043326.js} +2 -2
- package/components/mui_extended/Pager/{index.e0663072.js → index.eeed3bd5.js} +1 -1
- package/components/mui_extended/Typography/{index.79e2b06f.js → index.b3c6e71c.js} +1 -1
- package/components/mui_extended/index.dacbb059.js +19 -0
- package/contexts/ModalContext/{index.76d5ccee.js → index.8e3cd7a8.js} +1 -1
- package/contexts/index.d.ts +1 -1
- package/hooks/useModal/{index.043e419b.js → index.d590f506.js} +1 -1
- package/index.js +96 -94
- package/package.json +3 -4
- package/{react-draggable.de1aac90.js → react-draggable.0d64c8b1.js} +1 -1
- package/{react-resizable.e0470767.js → react-resizable.8307e056.js} +2 -2
- package/utils/{index.b5c62ef0.js → index.a2312a73.js} +1 -1
- package/{vendor.6a33c6d2.js → vendor.8edaef93.js} +47 -45
- package/components/areas/components/AreasViewer/subcomponents/Area/contexts/AreaContext/helper.d.ts +0 -39
- package/components/areas/components/AreasViewer/subcomponents/Area/contexts/AreaContext/index.d.ts +0 -20
- package/components/areas/components/AreasViewer/subcomponents/Area/contexts/AreaContext/store.d.ts +0 -11
- package/components/areas/components/AreasViewer/subcomponents/Area/contexts/AreaContext/types.d.ts +0 -82
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts/DynamicMFParmsContext/index.d.ts +0 -14
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts/WindowContext/helper.d.ts +0 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts/WindowContext/index.d.ts +0 -13
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts/WindowContext/store.d.ts +0 -36
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts/WindowContext/types.d.ts +0 -5
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/index.d.ts +0 -4
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/Component/index.d.ts +0 -8
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/Header/helper.d.ts +0 -3
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/Header/index.d.ts +0 -2
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/Header/subcomponents/MainActions/index.d.ts +0 -2
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/MicroFrontend/index.d.ts +0 -4
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/InnerForHooks/subcomponents/MicroFrontend/types.d.ts +0 -8
- package/components/areas/contexts/AreasContext/index.7c12b512.js +0 -230
- package/components/areas/contexts/index.1a823ffb.js +0 -2
- package/components/areas/hooks/index.d09ea7de.js +0 -26
- package/components/areas/hooks/useArea/index.3a0d4b8c.js +0 -34
- package/components/areas/hooks/useArea/index.d.ts +0 -11
- package/components/areas/hooks/useWindow/index.d.ts +0 -11
- package/components/modal/index.d6dcd1b1.js +0 -24
- package/components/mui_extended/index.8b30e8c8.js +0 -19
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/Header → Header}/skeleton.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/Header → Header}/styles.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/index.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/styles.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/subcomponents/NotFound/index.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/subcomponents/NotFound/styles.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/subcomponents/NotFound/types.d.ts +0 -0
- /package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/subcomponents/{InnerForHooks/subcomponents/MicroFrontend → MicroFrontend}/subcomponents/MFLoader/subcomponents/LoadingMF/types.d.ts +0 -0
- /package/components/areas/{components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts → contexts}/DynamicMFParmsContext/types.d.ts +0 -0
- /package/components/areas/{components/AreasViewer/subcomponents/Area/subcomponents/Window/contexts → contexts}/WindowToolsMFContext/index.d.ts +0 -0
|
@@ -0,0 +1,1015 @@
|
|
|
1
|
+
import { createContext, useRef, useCallback, useEffect } from "react";
|
|
2
|
+
import { createStore, useStore } from "zustand";
|
|
3
|
+
import { shallow } from "zustand/shallow";
|
|
4
|
+
import { useResponsiveDesktop, useFirstRender } from "@m4l/graphics";
|
|
5
|
+
import { useHostTools, useModuleDictionary, useNetwork, useModuleSkeleton, EmitEvents } from "@m4l/core";
|
|
6
|
+
import { devtools } from "zustand/middleware";
|
|
7
|
+
import { immer } from "zustand/middleware/immer";
|
|
8
|
+
import { u as useAreasViewerUtilityClasses, a as useAreasAdminUtilityClasses, b as areasViewerClasses } from "../../components/index.359c2b18.js";
|
|
9
|
+
import { g as getAreasDictionary } from "../../index.8a58bcbf.js";
|
|
10
|
+
import { c as createDynamicMFStore } from "../DynamicMFParmsContext/index.1607c78e.js";
|
|
11
|
+
import { debounce, cloneDeep } from "lodash";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
const ROW_HEIGTH_GRIDLAYOUT = 20;
|
|
14
|
+
const CONTAINER_PADDING_GRIDLAYOUT = 3;
|
|
15
|
+
const MARGIN_GRIDLAYOUT = 5;
|
|
16
|
+
const DEBOUCED_SAVE_TIME = 500;
|
|
17
|
+
const THROTTLE_RESIZE_TIME = 300;
|
|
18
|
+
const COOKIE_BREAKPOINT_LAYOUTS = "layoutPros";
|
|
19
|
+
const COOKIE_WINDOWS = "windows";
|
|
20
|
+
const BREAKPOINT_SIZES = { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 };
|
|
21
|
+
const NORMALIZED_COLS = { lg: 24, md: 20, sm: 12, xs: 8, xxs: 1 };
|
|
22
|
+
const MAXIMIZED_COLS = { lg: 24, md: 20, sm: 12, xs: 8, xxs: 1 };
|
|
23
|
+
const DEFAULT_AREA = {
|
|
24
|
+
status: "init",
|
|
25
|
+
zPopUpIndex: 0,
|
|
26
|
+
breakPointsLayouts: {},
|
|
27
|
+
beforeMaximizebreakpointsLayouts: {},
|
|
28
|
+
windowsLayouts: [],
|
|
29
|
+
windowsPopUps: [],
|
|
30
|
+
hashWindowsPopups: {},
|
|
31
|
+
hashWindowsLayouts: {},
|
|
32
|
+
currentLayoutId: "",
|
|
33
|
+
currentPopUpId: "",
|
|
34
|
+
breakpoints: BREAKPOINT_SIZES,
|
|
35
|
+
cols: NORMALIZED_COLS
|
|
36
|
+
};
|
|
37
|
+
const addArea = (state) => {
|
|
38
|
+
const areaId = `area_${new Date().getTime()}_${(Math.random() * 1e3).toFixed(0)}`;
|
|
39
|
+
const name = `${state.getLabel(getAreasDictionary("label_new_area"))} ${state.areas.length + 1}`;
|
|
40
|
+
const newArea = {
|
|
41
|
+
id: areaId,
|
|
42
|
+
name,
|
|
43
|
+
loadWindows: false,
|
|
44
|
+
viewMode: state.ownerState.isMobile ? "single" : "multiple",
|
|
45
|
+
...DEFAULT_AREA
|
|
46
|
+
};
|
|
47
|
+
state.areas.push(newArea);
|
|
48
|
+
state.hashAreas[areaId] = newArea;
|
|
49
|
+
if (state.loadAreasFromNetwork) {
|
|
50
|
+
state.networkOperation({
|
|
51
|
+
method: "POST",
|
|
52
|
+
endPoint: `areas`,
|
|
53
|
+
data: { id: areaId, name },
|
|
54
|
+
toastSuccess: false,
|
|
55
|
+
toastError: false
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return areaId;
|
|
59
|
+
};
|
|
60
|
+
const updateOwnerStateClasses = (state) => {
|
|
61
|
+
state.viwerClasses = useAreasViewerUtilityClasses(state.ownerState);
|
|
62
|
+
state.adminClasses = useAreasAdminUtilityClasses(state.ownerState);
|
|
63
|
+
};
|
|
64
|
+
const getParmsFromValue = (key, data) => {
|
|
65
|
+
try {
|
|
66
|
+
if (Array.isArray(data)) {
|
|
67
|
+
let ob = data.find((f) => f.id === key);
|
|
68
|
+
if (ob) {
|
|
69
|
+
ob = JSON.parse(ob.value);
|
|
70
|
+
}
|
|
71
|
+
return ob;
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
}
|
|
75
|
+
return void 0;
|
|
76
|
+
};
|
|
77
|
+
function setAddBreakPoints(state, newLayout) {
|
|
78
|
+
const layoutsBreakPoints = state.breakPointsLayouts;
|
|
79
|
+
const beforeMaximizebreakpointsLayouts = state.beforeMaximizebreakpointsLayouts;
|
|
80
|
+
for (const key in layoutsBreakPoints) {
|
|
81
|
+
const layoutBreakpoint = layoutsBreakPoints[key];
|
|
82
|
+
layoutBreakpoint.unshift(newLayout);
|
|
83
|
+
}
|
|
84
|
+
if (state.viewMode === "single") {
|
|
85
|
+
for (const key in beforeMaximizebreakpointsLayouts) {
|
|
86
|
+
const beforeLayoutBreakpoint = beforeMaximizebreakpointsLayouts[key];
|
|
87
|
+
beforeLayoutBreakpoint.push(newLayout);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return layoutsBreakPoints;
|
|
91
|
+
}
|
|
92
|
+
function deleteLayoutFromBreakPoints(state, layoutId) {
|
|
93
|
+
const layoutsBreakPoints = state.breakPointsLayouts;
|
|
94
|
+
for (const key in layoutsBreakPoints) {
|
|
95
|
+
const layoutBreakpoint = layoutsBreakPoints[key];
|
|
96
|
+
for (let index = 0; index < layoutBreakpoint.length; index++) {
|
|
97
|
+
const l = layoutBreakpoint[index];
|
|
98
|
+
if (l.i === layoutId) {
|
|
99
|
+
layoutBreakpoint.splice(index, 1);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function setBreakPointsMaximized(state, layoutId) {
|
|
106
|
+
const layoutsBreakPoints = state.breakPointsLayouts;
|
|
107
|
+
const container = document.getElementsByClassName(
|
|
108
|
+
`${areasViewerClasses.areaGridLayout}-${state.id}`
|
|
109
|
+
)[0];
|
|
110
|
+
console.log("setBreakPointsMaximized", container);
|
|
111
|
+
if (container) {
|
|
112
|
+
const clientHeight = container.clientHeight;
|
|
113
|
+
for (const key in layoutsBreakPoints) {
|
|
114
|
+
const layoutBreakpoint = layoutsBreakPoints[key];
|
|
115
|
+
const cols = key in MAXIMIZED_COLS ? MAXIMIZED_COLS[key] : 1;
|
|
116
|
+
const heigthUnits = (clientHeight + MARGIN_GRIDLAYOUT - 2 * CONTAINER_PADDING_GRIDLAYOUT) / (ROW_HEIGTH_GRIDLAYOUT + MARGIN_GRIDLAYOUT);
|
|
117
|
+
for (let index = 0; index < layoutBreakpoint.length; index++) {
|
|
118
|
+
const l = layoutBreakpoint[index];
|
|
119
|
+
if (l.i === layoutId) {
|
|
120
|
+
l.x = 0;
|
|
121
|
+
l.y = 0;
|
|
122
|
+
l.h = heigthUnits;
|
|
123
|
+
l.w = cols;
|
|
124
|
+
l.minW = 0;
|
|
125
|
+
l.maxW = cols;
|
|
126
|
+
l.minH = 0;
|
|
127
|
+
l.maxH = heigthUnits;
|
|
128
|
+
l.isResizable = false;
|
|
129
|
+
l.isDraggable = false;
|
|
130
|
+
} else {
|
|
131
|
+
l.x = 0;
|
|
132
|
+
l.y = 1;
|
|
133
|
+
l.h = 0;
|
|
134
|
+
l.w = 0;
|
|
135
|
+
l.minW = 0;
|
|
136
|
+
l.maxW = 0;
|
|
137
|
+
l.minH = 0;
|
|
138
|
+
l.maxH = 0;
|
|
139
|
+
}
|
|
140
|
+
l.isResizable = false;
|
|
141
|
+
l.isDraggable = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return layoutsBreakPoints;
|
|
146
|
+
}
|
|
147
|
+
function getDataFromResponse(data, state, areaId) {
|
|
148
|
+
const newBreakPointsLayouts = getParmsFromValue(COOKIE_BREAKPOINT_LAYOUTS, data);
|
|
149
|
+
const windows = getParmsFromValue(COOKIE_WINDOWS, data);
|
|
150
|
+
const newWindowsLayouts = [];
|
|
151
|
+
const newHashWindowLayouts = {};
|
|
152
|
+
if (windows) {
|
|
153
|
+
for (const key in windows) {
|
|
154
|
+
const element = windows[key];
|
|
155
|
+
if (element && element["layoutProps"] && element["mfProps"] && element["emergeType"] === "layout" && element["winType"] === "microfrontend") {
|
|
156
|
+
element["layoutProps"].i = key;
|
|
157
|
+
newWindowsLayouts.push(element["layoutProps"]);
|
|
158
|
+
const onClose = state.areaActions.closeWindowLayout;
|
|
159
|
+
newHashWindowLayouts[key] = {
|
|
160
|
+
...element,
|
|
161
|
+
windowId: key,
|
|
162
|
+
emergeType: "layout",
|
|
163
|
+
areaId,
|
|
164
|
+
dynamicMFStore: createDynamicMFStore({
|
|
165
|
+
dynamicMFParameters: element.dynamicParams,
|
|
166
|
+
windowId: key
|
|
167
|
+
}),
|
|
168
|
+
onClose: () => onClose(areaId, key),
|
|
169
|
+
status: "init",
|
|
170
|
+
moduleActions: [],
|
|
171
|
+
cookies: { moduleCookies: {}, windowCookies: {} },
|
|
172
|
+
loading: false
|
|
173
|
+
};
|
|
174
|
+
state.hashWindows[key] = newHashWindowLayouts[key];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
newBreakPointsLayouts,
|
|
180
|
+
newWindowsLayouts,
|
|
181
|
+
newHashWindowLayouts
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function getCookiesContainer(data, containerId) {
|
|
185
|
+
const cookies = {};
|
|
186
|
+
try {
|
|
187
|
+
if (Array.isArray(data)) {
|
|
188
|
+
for (let i = 0; i < data.length; i++) {
|
|
189
|
+
if (data[i]?.container_id === containerId && data[i]?.id) {
|
|
190
|
+
cookies[data[i]?.id] = JSON.parse(data[i].value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
}
|
|
196
|
+
return cookies;
|
|
197
|
+
}
|
|
198
|
+
const createAreasStore = (initProps) => {
|
|
199
|
+
const startProps = {
|
|
200
|
+
viwerClasses: useAreasViewerUtilityClasses(initProps.ownerState),
|
|
201
|
+
adminClasses: useAreasAdminUtilityClasses(initProps.ownerState),
|
|
202
|
+
currentAreaId: "",
|
|
203
|
+
currentModuleId: "",
|
|
204
|
+
areas: [],
|
|
205
|
+
hashAreas: {},
|
|
206
|
+
hashWindows: {},
|
|
207
|
+
hashWindowsModals: {},
|
|
208
|
+
windowsModals: [],
|
|
209
|
+
...initProps
|
|
210
|
+
};
|
|
211
|
+
return createStore(
|
|
212
|
+
devtools(
|
|
213
|
+
immer((set, get) => ({
|
|
214
|
+
...startProps,
|
|
215
|
+
areasActions: {
|
|
216
|
+
init: () => {
|
|
217
|
+
if (get().ownerState.status === "init") {
|
|
218
|
+
if (!get().loadAreasFromNetwork) {
|
|
219
|
+
get().areasActions.addArea();
|
|
220
|
+
set((state) => {
|
|
221
|
+
state.ownerState.status = "loaded";
|
|
222
|
+
updateOwnerStateClasses(state);
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
set((state) => {
|
|
226
|
+
state.ownerState.status = "loading";
|
|
227
|
+
updateOwnerStateClasses(state);
|
|
228
|
+
state.networkOperation({
|
|
229
|
+
method: "GET",
|
|
230
|
+
endPoint: `areas`,
|
|
231
|
+
parms: {},
|
|
232
|
+
toastSuccess: false
|
|
233
|
+
}).then((response) => {
|
|
234
|
+
set((otherState) => {
|
|
235
|
+
if (response?.data && Array.isArray(response.data) && response.data.length > 0) {
|
|
236
|
+
for (let i = 0; i < response.data.length; i++) {
|
|
237
|
+
const newArea = {
|
|
238
|
+
...DEFAULT_AREA,
|
|
239
|
+
...response.data[i],
|
|
240
|
+
loadWindows: true,
|
|
241
|
+
viewMode: otherState.ownerState.isMobile ? "single" : "multiple"
|
|
242
|
+
};
|
|
243
|
+
otherState.areas.push(newArea);
|
|
244
|
+
otherState.hashAreas[newArea.id] = newArea;
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
addArea(otherState);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}).finally(() => {
|
|
251
|
+
set((state2) => {
|
|
252
|
+
state2.ownerState.status = "loaded";
|
|
253
|
+
updateOwnerStateClasses(state2);
|
|
254
|
+
});
|
|
255
|
+
if (get().areas.length > 0) {
|
|
256
|
+
get().areasActions.selectArea(get().areas[0].id);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
addArea: () => {
|
|
264
|
+
let newId = "";
|
|
265
|
+
set((state) => {
|
|
266
|
+
newId = addArea(state);
|
|
267
|
+
});
|
|
268
|
+
get().areasActions.selectArea(newId);
|
|
269
|
+
return newId;
|
|
270
|
+
},
|
|
271
|
+
deleteArea: (areaId) => {
|
|
272
|
+
let selectNewAreaId = "";
|
|
273
|
+
set((state) => {
|
|
274
|
+
const removeIndex = state.areas.findIndex((area) => area.id === areaId);
|
|
275
|
+
if (removeIndex > -1) {
|
|
276
|
+
for (const key in state.hashWindows) {
|
|
277
|
+
if (state.hashWindows[key].areaId === areaId) {
|
|
278
|
+
delete state.hashWindows[key];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
state.areas.splice(removeIndex, 1);
|
|
282
|
+
delete state.hashAreas[areaId];
|
|
283
|
+
}
|
|
284
|
+
if (state.currentAreaId === areaId) {
|
|
285
|
+
if (state.areas.length > 0) {
|
|
286
|
+
selectNewAreaId = state.areas[0].id;
|
|
287
|
+
} else {
|
|
288
|
+
state.currentAreaId = "";
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (state.loadAreasFromNetwork) {
|
|
292
|
+
state.networkOperation({
|
|
293
|
+
method: "DELETE",
|
|
294
|
+
endPoint: `areas/${areaId}`,
|
|
295
|
+
parms: {},
|
|
296
|
+
toastSuccess: false,
|
|
297
|
+
toastError: false
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
if (selectNewAreaId) {
|
|
302
|
+
get().areasActions.selectArea(selectNewAreaId);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
selectArea: (areaId) => {
|
|
306
|
+
set((state) => {
|
|
307
|
+
state.currentAreaId = areaId;
|
|
308
|
+
if (state.hashAreas[areaId].currentLayoutId) {
|
|
309
|
+
state.currentModuleId = state.hashWindows[state.hashAreas[areaId].currentLayoutId].moduleId;
|
|
310
|
+
} else {
|
|
311
|
+
state.currentModuleId = "";
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
if (get().hashAreas[areaId].status === "init") {
|
|
315
|
+
if (get().hashAreas[areaId].loadWindows) {
|
|
316
|
+
get().areaActions.loadWindowsFromApi(areaId);
|
|
317
|
+
} else {
|
|
318
|
+
set((state) => {
|
|
319
|
+
state.hashAreas[areaId].status = "loaded";
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (get().hashAreas[areaId].singleId !== void 0) {
|
|
324
|
+
get().areaActions.resizeMaximixedLayout(areaId);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
setHandlerGetLabel: (newHandler) => {
|
|
328
|
+
set((state) => {
|
|
329
|
+
state.getLabel = newHandler;
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
setExternalState: (newExternalState) => {
|
|
333
|
+
set((state) => {
|
|
334
|
+
state.ownerState = { ...state.ownerState, ...newExternalState };
|
|
335
|
+
updateOwnerStateClasses(state);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
areaActions: {
|
|
340
|
+
addWindow: (newWindowProps) => {
|
|
341
|
+
const windowId = `${get().currentAreaId}_window_${new Date().getTime()}_${(Math.random() * 1e3).toFixed(0)}`;
|
|
342
|
+
if (newWindowProps.emergeType === "layout") {
|
|
343
|
+
get().areaActions.addWindowLayout(
|
|
344
|
+
get().currentAreaId,
|
|
345
|
+
windowId,
|
|
346
|
+
newWindowProps
|
|
347
|
+
);
|
|
348
|
+
} else if (newWindowProps.emergeType === "popup") {
|
|
349
|
+
get().areaActions.addWindowPopUp(
|
|
350
|
+
get().currentAreaId,
|
|
351
|
+
windowId,
|
|
352
|
+
newWindowProps
|
|
353
|
+
);
|
|
354
|
+
} else if (newWindowProps.emergeType === "modal") {
|
|
355
|
+
get().areaActions.addWindowModal(
|
|
356
|
+
get().currentAreaId,
|
|
357
|
+
windowId,
|
|
358
|
+
newWindowProps
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
closeWindowModal: (removeModalId) => {
|
|
363
|
+
set((state) => {
|
|
364
|
+
const removeIndex = state.windowsModals.findIndex(
|
|
365
|
+
(w) => w === removeModalId
|
|
366
|
+
);
|
|
367
|
+
if (removeIndex > -1) {
|
|
368
|
+
state.windowsModals.splice(removeIndex, 1);
|
|
369
|
+
}
|
|
370
|
+
delete state.hashWindows[removeModalId];
|
|
371
|
+
delete state.hashWindowsModals[removeModalId];
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
addWindowModal: (areaId, windowId, newWindowModalProps) => {
|
|
375
|
+
set((state) => {
|
|
376
|
+
const dynamicMFStore = createDynamicMFStore({
|
|
377
|
+
dynamicMFParameters: newWindowModalProps.dynamicParams,
|
|
378
|
+
windowId
|
|
379
|
+
});
|
|
380
|
+
state.windowsModals.push(windowId);
|
|
381
|
+
state.hashWindowsModals[windowId] = {
|
|
382
|
+
...newWindowModalProps,
|
|
383
|
+
areaId,
|
|
384
|
+
windowId,
|
|
385
|
+
status: "init",
|
|
386
|
+
moduleActions: [],
|
|
387
|
+
cookies: { moduleCookies: {}, windowCookies: {} },
|
|
388
|
+
loading: false,
|
|
389
|
+
onClose: get().areaActions.closeWindowModal,
|
|
390
|
+
dynamicMFStore
|
|
391
|
+
};
|
|
392
|
+
state.hashWindows[windowId] = state.hashWindowsModals[windowId];
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
closeWindowPopUp: (areaId, removePopUpId) => {
|
|
396
|
+
set((state) => {
|
|
397
|
+
const area = state.hashAreas[areaId];
|
|
398
|
+
if (!area) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const removeIndex = area.windowsPopUps.findIndex(
|
|
402
|
+
(wpId) => wpId === removePopUpId
|
|
403
|
+
);
|
|
404
|
+
if (removeIndex > -1) {
|
|
405
|
+
area.windowsPopUps.splice(removeIndex, 1);
|
|
406
|
+
}
|
|
407
|
+
delete area.hashWindowsPopups[removePopUpId];
|
|
408
|
+
delete state.hashWindows[removePopUpId];
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
selectWindowPopUp: (areaId, popUpId) => {
|
|
412
|
+
set((state) => {
|
|
413
|
+
state.hashAreas[areaId].zPopUpIndex++;
|
|
414
|
+
state.hashAreas[areaId].currentPopUpId = popUpId;
|
|
415
|
+
state.hashAreas[areaId].zPopUpIndex++;
|
|
416
|
+
state.hashAreas[areaId].currentPopUpId = popUpId;
|
|
417
|
+
state.hashAreas[areaId].hashWindowsPopups[popUpId].zIndex = state.hashAreas[areaId].zPopUpIndex;
|
|
418
|
+
if (state.hashAreas[areaId].hashWindowsPopups[popUpId].parentLayoutId && state.hashAreas[areaId].hashWindowsPopups[popUpId].parentLayoutId !== "") {
|
|
419
|
+
state.hashAreas[areaId].currentLayoutId = state.hashAreas[areaId].hashWindowsPopups[popUpId].parentLayoutId;
|
|
420
|
+
} else {
|
|
421
|
+
state.hashAreas[areaId].currentLayoutId = "";
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
setTimeout(() => {
|
|
425
|
+
const container = document.getElementsByClassName(
|
|
426
|
+
`${areasViewerClasses.areaGridLayoutPanelContainer}-${areaId}`
|
|
427
|
+
)[0];
|
|
428
|
+
const element = document.getElementsByClassName(
|
|
429
|
+
`${areasViewerClasses.windowPopupRoot}-${popUpId}`
|
|
430
|
+
)[0];
|
|
431
|
+
if (element && container) {
|
|
432
|
+
const { top, left } = element.getBoundingClientRect();
|
|
433
|
+
const { top: containerTop, left: containerLeft } = container.getBoundingClientRect();
|
|
434
|
+
container.scrollTop = container.scrollTop + top - containerTop;
|
|
435
|
+
container.scrollLeft = container.scrollLeft + left - containerLeft;
|
|
436
|
+
}
|
|
437
|
+
}, 100);
|
|
438
|
+
},
|
|
439
|
+
addWindowPopUp: (areaId, windowId, newWindowPopupProps) => {
|
|
440
|
+
let popUpId = windowId;
|
|
441
|
+
set((state) => {
|
|
442
|
+
const area = state.hashAreas[areaId];
|
|
443
|
+
if (!area) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (newWindowPopupProps.replaceMeId) {
|
|
447
|
+
for (const key in area.hashWindowsPopups) {
|
|
448
|
+
const WindoPopUp = area.hashWindowsPopups[key];
|
|
449
|
+
if (WindoPopUp.replaceMeId === newWindowPopupProps.replaceMeId) {
|
|
450
|
+
popUpId = key;
|
|
451
|
+
area.hashWindowsPopups[key].dynamicMFStore.getState().actions.changeData(newWindowPopupProps.dynamicParams);
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (popUpId === windowId) {
|
|
457
|
+
const dynamicMFStore = createDynamicMFStore({
|
|
458
|
+
dynamicMFParameters: newWindowPopupProps.dynamicParams,
|
|
459
|
+
windowId
|
|
460
|
+
});
|
|
461
|
+
area.windowsPopUps.push(windowId);
|
|
462
|
+
area.hashWindowsPopups[windowId] = {
|
|
463
|
+
...newWindowPopupProps,
|
|
464
|
+
emergeType: "popup",
|
|
465
|
+
windowId,
|
|
466
|
+
areaId,
|
|
467
|
+
onClose: (removePopUpId) => get().areaActions.closeWindowPopUp(areaId, removePopUpId),
|
|
468
|
+
zIndex: area.zPopUpIndex,
|
|
469
|
+
status: "init",
|
|
470
|
+
moduleActions: [],
|
|
471
|
+
cookies: { moduleCookies: {}, windowCookies: {} },
|
|
472
|
+
loading: false,
|
|
473
|
+
dynamicMFStore
|
|
474
|
+
};
|
|
475
|
+
state.hashWindows[windowId] = area.hashWindowsPopups[windowId];
|
|
476
|
+
area.currentPopUpId = windowId;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
get().areaActions.selectWindowPopUp(areaId, popUpId);
|
|
480
|
+
},
|
|
481
|
+
closeWindowLayout: (areaId, removeLayoutId) => {
|
|
482
|
+
set((state) => {
|
|
483
|
+
const area = state.hashAreas[areaId];
|
|
484
|
+
if (!area) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const removeIndex = area.windowsLayouts.findIndex(
|
|
488
|
+
(gl) => gl.i === removeLayoutId
|
|
489
|
+
);
|
|
490
|
+
if (removeIndex > -1) {
|
|
491
|
+
area.windowsLayouts.splice(removeIndex, 1);
|
|
492
|
+
}
|
|
493
|
+
deleteLayoutFromBreakPoints(area, removeLayoutId);
|
|
494
|
+
delete state.hashWindows[removeLayoutId];
|
|
495
|
+
delete area.hashWindowsLayouts[removeLayoutId];
|
|
496
|
+
});
|
|
497
|
+
get().areaActions.saveLayouts(areaId);
|
|
498
|
+
if (get().hashAreas[areaId].singleId === removeLayoutId) {
|
|
499
|
+
get().areaActions.maximizeLayout(areaId);
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
addWindowLayout: (areaId, windowId, newWindow) => {
|
|
503
|
+
const newLayout = {
|
|
504
|
+
...newWindow.layoutProps,
|
|
505
|
+
i: windowId,
|
|
506
|
+
isDraggable: true,
|
|
507
|
+
isResizable: true,
|
|
508
|
+
winType: newWindow.winType
|
|
509
|
+
};
|
|
510
|
+
set((state) => {
|
|
511
|
+
const area = state.hashAreas[areaId];
|
|
512
|
+
if (!area) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const dynamicMFStore = createDynamicMFStore({
|
|
516
|
+
dynamicMFParameters: newWindow.dynamicParams,
|
|
517
|
+
windowId
|
|
518
|
+
});
|
|
519
|
+
area.windowsLayouts.push(newLayout);
|
|
520
|
+
area.hashWindowsLayouts[windowId] = {
|
|
521
|
+
...newWindow,
|
|
522
|
+
areaId,
|
|
523
|
+
windowId,
|
|
524
|
+
emergeType: "layout",
|
|
525
|
+
onClose: (removeLayoutId) => {
|
|
526
|
+
get().areaActions.closeWindowLayout(areaId, removeLayoutId);
|
|
527
|
+
},
|
|
528
|
+
status: "init",
|
|
529
|
+
moduleActions: [],
|
|
530
|
+
cookies: { moduleCookies: {}, windowCookies: {} },
|
|
531
|
+
loading: false,
|
|
532
|
+
dynamicMFStore
|
|
533
|
+
};
|
|
534
|
+
state.hashWindows[windowId] = area.hashWindowsLayouts[windowId];
|
|
535
|
+
setAddBreakPoints(area, newLayout);
|
|
536
|
+
});
|
|
537
|
+
get().areaActions.selectWindowLayout(areaId, windowId);
|
|
538
|
+
if (get().hashAreas[areaId].viewMode === "single" || newWindow?.openType === "maximized") {
|
|
539
|
+
get().areaActions.maximizeLayout(areaId, windowId);
|
|
540
|
+
}
|
|
541
|
+
get().areaActions.saveLayouts(areaId);
|
|
542
|
+
get().areaActions.bouncedSaveBreakpointsLayouts(areaId);
|
|
543
|
+
},
|
|
544
|
+
saveLayouts: (areaId) => {
|
|
545
|
+
let nrKeys = 0;
|
|
546
|
+
const area = get().hashAreas[areaId];
|
|
547
|
+
if (!area) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const saveObjetc = {};
|
|
551
|
+
for (const key in area.hashWindowsLayouts) {
|
|
552
|
+
const element = area.hashWindowsLayouts[key];
|
|
553
|
+
if (element.winType === "microfrontend") {
|
|
554
|
+
const newElement = { ...element };
|
|
555
|
+
delete newElement.onClose;
|
|
556
|
+
delete newElement.devCookies;
|
|
557
|
+
saveObjetc[key] = newElement;
|
|
558
|
+
nrKeys++;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (nrKeys > 0) {
|
|
562
|
+
get().networkOperation({
|
|
563
|
+
method: "PUT",
|
|
564
|
+
endPoint: `cookies/${area.id}/${COOKIE_WINDOWS}`,
|
|
565
|
+
data: {
|
|
566
|
+
value: JSON.stringify(saveObjetc)
|
|
567
|
+
},
|
|
568
|
+
toastSuccess: false,
|
|
569
|
+
toastError: false
|
|
570
|
+
});
|
|
571
|
+
} else {
|
|
572
|
+
get().networkOperation({
|
|
573
|
+
method: "DELETE",
|
|
574
|
+
endPoint: `cookies`,
|
|
575
|
+
data: { f: [{ n: "container_id", o: "c", o1: area.id }] },
|
|
576
|
+
toastSuccess: false,
|
|
577
|
+
toastError: false
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
bouncedSaveBreakpointsLayouts: debounce(
|
|
582
|
+
(areaId) => {
|
|
583
|
+
const purgedLayouts = {
|
|
584
|
+
...get().hashAreas[areaId].viewMode === "multiple" ? get().hashAreas[areaId].breakPointsLayouts : get().hashAreas[areaId].beforeMaximizebreakpointsLayouts
|
|
585
|
+
};
|
|
586
|
+
const finalLayouts = {};
|
|
587
|
+
for (const key in purgedLayouts) {
|
|
588
|
+
const element = purgedLayouts[key];
|
|
589
|
+
purgedLayouts[key] = element.filter((l) => {
|
|
590
|
+
if (l.i === "none") {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
if (get().hashAreas[areaId].hashWindowsLayouts[l.i]) {
|
|
594
|
+
return true;
|
|
595
|
+
}
|
|
596
|
+
return false;
|
|
597
|
+
});
|
|
598
|
+
if (purgedLayouts[key].length > 0) {
|
|
599
|
+
finalLayouts[key] = purgedLayouts[key];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (Object.keys(finalLayouts).length > 0) {
|
|
603
|
+
get().networkOperation({
|
|
604
|
+
method: "PUT",
|
|
605
|
+
endPoint: `cookies/${get().hashAreas[areaId].id}/${COOKIE_BREAKPOINT_LAYOUTS}`,
|
|
606
|
+
data: {
|
|
607
|
+
value: JSON.stringify(finalLayouts)
|
|
608
|
+
},
|
|
609
|
+
toastSuccess: false,
|
|
610
|
+
toastError: false
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
DEBOUCED_SAVE_TIME
|
|
615
|
+
),
|
|
616
|
+
onBreakpointsLayoutsChange: (areaId, _currentLayouts, newAllLayouts) => {
|
|
617
|
+
set((state) => {
|
|
618
|
+
state.hashAreas[areaId].breakPointsLayouts = newAllLayouts;
|
|
619
|
+
});
|
|
620
|
+
if (!get().hashAreas[areaId].singleId) {
|
|
621
|
+
get().areaActions.bouncedSaveBreakpointsLayouts(areaId);
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
selectWindowLayout: (areaId, layoutId) => {
|
|
625
|
+
set((state) => {
|
|
626
|
+
const area = state.hashAreas[areaId];
|
|
627
|
+
area.currentLayoutId = layoutId;
|
|
628
|
+
state.currentModuleId = state.hashWindows[layoutId].moduleId;
|
|
629
|
+
if (area.currentPopUpId !== "" && area.hashWindowsPopups[area.currentPopUpId]) {
|
|
630
|
+
const windowPopup = area.hashWindowsPopups[area.currentPopUpId];
|
|
631
|
+
if (windowPopup.parentLayoutId !== layoutId) {
|
|
632
|
+
area.currentPopUpId = "";
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
},
|
|
637
|
+
maximizeLayout: (areaId, layoutId) => {
|
|
638
|
+
let finalLayoutId = layoutId;
|
|
639
|
+
set((state) => {
|
|
640
|
+
const area = state.hashAreas[areaId];
|
|
641
|
+
if (!area)
|
|
642
|
+
return;
|
|
643
|
+
if (area.viewMode === "multiple") {
|
|
644
|
+
area.beforeMaximizebreakpointsLayouts = cloneDeep(
|
|
645
|
+
area.breakPointsLayouts
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
if (!finalLayoutId) {
|
|
649
|
+
if (area.windowsLayouts.length > 0) {
|
|
650
|
+
finalLayoutId = area.windowsLayouts[0].i;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
area.viewMode = "single";
|
|
654
|
+
area.singleId = finalLayoutId;
|
|
655
|
+
setTimeout(() => {
|
|
656
|
+
set((state2) => {
|
|
657
|
+
setBreakPointsMaximized(
|
|
658
|
+
state2.hashAreas[areaId],
|
|
659
|
+
finalLayoutId
|
|
660
|
+
);
|
|
661
|
+
});
|
|
662
|
+
}, 100);
|
|
663
|
+
});
|
|
664
|
+
if (finalLayoutId) {
|
|
665
|
+
get().areaActions.selectWindowLayout(areaId, finalLayoutId);
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
resizeMaximixedLayout: (areaId) => {
|
|
669
|
+
set((state) => {
|
|
670
|
+
const area = state.hashAreas[areaId];
|
|
671
|
+
if (!area)
|
|
672
|
+
return;
|
|
673
|
+
if (areaId !== state.currentAreaId) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
if (area.viewMode === "single" && area.currentLayoutId !== "") {
|
|
677
|
+
console.log("Rezigning", areaId);
|
|
678
|
+
const layoutsBreakPoints = area.breakPointsLayouts;
|
|
679
|
+
const container = document.getElementsByClassName(
|
|
680
|
+
`${areasViewerClasses.areaGridLayout}-${area.id}`
|
|
681
|
+
)[0];
|
|
682
|
+
window.dispatchEvent(new Event("resize"));
|
|
683
|
+
for (const key in layoutsBreakPoints) {
|
|
684
|
+
const layoutBreakpoint = layoutsBreakPoints[key];
|
|
685
|
+
if (layoutBreakpoint) {
|
|
686
|
+
const clientHeight = container.clientHeight;
|
|
687
|
+
const heigthUnits = (clientHeight + MARGIN_GRIDLAYOUT - 2 * CONTAINER_PADDING_GRIDLAYOUT) / (ROW_HEIGTH_GRIDLAYOUT + MARGIN_GRIDLAYOUT);
|
|
688
|
+
for (let index = 0; index < layoutBreakpoint.length; index++) {
|
|
689
|
+
const l = layoutBreakpoint[index];
|
|
690
|
+
if (l.i === area.currentLayoutId) {
|
|
691
|
+
l.h = heigthUnits;
|
|
692
|
+
l.maxH = heigthUnits;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
},
|
|
700
|
+
normalizeLayouts: (areaId) => {
|
|
701
|
+
set((state) => {
|
|
702
|
+
if (state.ownerState.isMobile)
|
|
703
|
+
return;
|
|
704
|
+
if (!state.ownerState.isMobile && state.hashAreas[areaId].viewMode === "single") {
|
|
705
|
+
state.hashAreas[areaId].viewMode = "multiple";
|
|
706
|
+
state.hashAreas[areaId].singleId = void 0;
|
|
707
|
+
state.hashAreas[areaId].breakPointsLayouts = state.hashAreas[areaId].beforeMaximizebreakpointsLayouts;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
},
|
|
711
|
+
loadWindowsFromApi: (areaId) => {
|
|
712
|
+
const area = get().hashAreas[areaId];
|
|
713
|
+
if (!area) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (area.status !== "init") {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (!get().loadAreasFromNetwork || !area.loadWindows) {
|
|
720
|
+
set((state) => {
|
|
721
|
+
state.hashAreas[areaId].status = "loaded";
|
|
722
|
+
});
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
set((state) => {
|
|
726
|
+
state.hashAreas[areaId].status = "loading";
|
|
727
|
+
});
|
|
728
|
+
get().networkOperation({
|
|
729
|
+
method: "GET",
|
|
730
|
+
endPoint: `cookies`,
|
|
731
|
+
parms: { f: [{ n: "container_id", o: "e", o1: areaId }] },
|
|
732
|
+
toastSuccess: false,
|
|
733
|
+
toastError: false
|
|
734
|
+
}).then((response) => {
|
|
735
|
+
const area2 = get().hashAreas[areaId];
|
|
736
|
+
if (!area2) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
set((state) => {
|
|
740
|
+
const area3 = state.hashAreas[areaId];
|
|
741
|
+
const {
|
|
742
|
+
newBreakPointsLayouts,
|
|
743
|
+
newWindowsLayouts,
|
|
744
|
+
newHashWindowLayouts
|
|
745
|
+
} = getDataFromResponse(response.data, state, areaId);
|
|
746
|
+
area3.breakPointsLayouts = newBreakPointsLayouts;
|
|
747
|
+
if (area.viewMode === "single") {
|
|
748
|
+
area3.beforeMaximizebreakpointsLayouts = newBreakPointsLayouts;
|
|
749
|
+
}
|
|
750
|
+
area3.windowsLayouts = newWindowsLayouts;
|
|
751
|
+
area3.hashWindowsLayouts = newHashWindowLayouts;
|
|
752
|
+
area3.status = "loaded";
|
|
753
|
+
});
|
|
754
|
+
if (get().hashAreas[areaId].windowsLayouts.length > 0) {
|
|
755
|
+
get().areaActions.selectWindowLayout(
|
|
756
|
+
areaId,
|
|
757
|
+
get().hashAreas[areaId].windowsLayouts[0].i
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
console.log("loadWindowsFromApi", area2.viewMode);
|
|
761
|
+
if (area2.viewMode === "single") {
|
|
762
|
+
get().areaActions.maximizeLayout(area2.id);
|
|
763
|
+
}
|
|
764
|
+
}).catch((_response) => {
|
|
765
|
+
set((state) => {
|
|
766
|
+
state.hashAreas[areaId].status = "loaded";
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
windowActions: {
|
|
772
|
+
setActions: (windowId, newActions, version) => {
|
|
773
|
+
set((state) => {
|
|
774
|
+
if (state.hashWindows[windowId]) {
|
|
775
|
+
state.hashWindows[windowId].moduleActions = cloneDeep(newActions);
|
|
776
|
+
state.hashWindows[windowId].version = version;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
},
|
|
780
|
+
getCookie: (windowId, id) => {
|
|
781
|
+
if (get().hashWindows[windowId]) {
|
|
782
|
+
return get().hashWindows[windowId].cookies.windowCookies[id] || get().hashWindows[windowId].cookies.moduleCookies[id];
|
|
783
|
+
}
|
|
784
|
+
return {};
|
|
785
|
+
},
|
|
786
|
+
getCookies: (windowId, type) => {
|
|
787
|
+
if (get().hashWindows[windowId]) {
|
|
788
|
+
if (type === "window") {
|
|
789
|
+
return get().hashWindows[windowId].cookies.windowCookies;
|
|
790
|
+
} else {
|
|
791
|
+
return get().hashWindows[windowId].cookies.moduleCookies;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return {};
|
|
795
|
+
},
|
|
796
|
+
setCookie: (windowId, id, type, cookie) => {
|
|
797
|
+
set((state) => {
|
|
798
|
+
const hW = state.hashWindows[windowId];
|
|
799
|
+
if (hW) {
|
|
800
|
+
get().networkOperation({
|
|
801
|
+
method: "PUT",
|
|
802
|
+
endPoint: `cookies/${type === "module" ? hW.moduleId : windowId}/${id}`,
|
|
803
|
+
data: {
|
|
804
|
+
value: JSON.stringify(cookie)
|
|
805
|
+
},
|
|
806
|
+
toastSuccess: false,
|
|
807
|
+
toastError: false
|
|
808
|
+
});
|
|
809
|
+
if (type === "window") {
|
|
810
|
+
hW.cookies.windowCookies[id] = cookie;
|
|
811
|
+
} else {
|
|
812
|
+
hW.cookies.moduleCookies[id] = cookie;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
},
|
|
817
|
+
close: (windowId) => {
|
|
818
|
+
const hW = get().hashWindows[windowId];
|
|
819
|
+
if (hW) {
|
|
820
|
+
const onClose = hW.onClose;
|
|
821
|
+
if (onClose) {
|
|
822
|
+
onClose(hW.windowId);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
setLoading: (windowId, isLoading) => {
|
|
827
|
+
set((state) => {
|
|
828
|
+
if (state.hashWindows[windowId]) {
|
|
829
|
+
state.hashWindows[windowId].loading = isLoading;
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
loadCookiesFromApi: (windowId) => {
|
|
834
|
+
const hW = get().hashWindows[windowId];
|
|
835
|
+
if (hW) {
|
|
836
|
+
if (hW.status === "init") {
|
|
837
|
+
set((state) => {
|
|
838
|
+
state.hashWindows[windowId].status = "loading";
|
|
839
|
+
});
|
|
840
|
+
get().networkOperation({
|
|
841
|
+
method: "GET",
|
|
842
|
+
endPoint: `cookies`,
|
|
843
|
+
parms: {
|
|
844
|
+
f: [
|
|
845
|
+
{ n: "container_id", o: "e", o1: hW.windowId },
|
|
846
|
+
{ n: "container_id", o: "e", o1: hW.moduleId }
|
|
847
|
+
]
|
|
848
|
+
},
|
|
849
|
+
toastSuccess: false,
|
|
850
|
+
toastError: false
|
|
851
|
+
}).then((response) => {
|
|
852
|
+
set((state) => {
|
|
853
|
+
const hWs = state.hashWindows[windowId];
|
|
854
|
+
if (hWs) {
|
|
855
|
+
hWs.cookies.moduleCookies = getCookiesContainer(
|
|
856
|
+
response.data,
|
|
857
|
+
hWs.moduleId
|
|
858
|
+
);
|
|
859
|
+
hWs.cookies.windowCookies = getCookiesContainer(
|
|
860
|
+
response.data,
|
|
861
|
+
windowId
|
|
862
|
+
);
|
|
863
|
+
hWs.status = "loaded";
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}).catch((_response) => {
|
|
867
|
+
set((state) => {
|
|
868
|
+
if (state.hashWindows[windowId]) {
|
|
869
|
+
state.hashWindows[windowId].status = "loaded";
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
saveModuleCookies: (windowId) => {
|
|
877
|
+
const hW = get().hashWindows[windowId];
|
|
878
|
+
if (hW) {
|
|
879
|
+
for (const key in hW.cookies.windowCookies) {
|
|
880
|
+
const cookie = hW.cookies.windowCookies[key];
|
|
881
|
+
get().networkOperation({
|
|
882
|
+
method: "PUT",
|
|
883
|
+
endPoint: `cookies/${hW.moduleId}/${key}`,
|
|
884
|
+
data: {
|
|
885
|
+
value: JSON.stringify(cookie)
|
|
886
|
+
},
|
|
887
|
+
toastSuccess: false,
|
|
888
|
+
toastError: false
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
resetModuleCookies: (windowId) => {
|
|
894
|
+
const hW = get().hashWindows[windowId];
|
|
895
|
+
if (hW) {
|
|
896
|
+
get().networkOperation({
|
|
897
|
+
method: "DELETE",
|
|
898
|
+
endPoint: `cookies`,
|
|
899
|
+
data: {
|
|
900
|
+
f: [
|
|
901
|
+
{
|
|
902
|
+
n: "id",
|
|
903
|
+
o: "c",
|
|
904
|
+
o1: hW.moduleId
|
|
905
|
+
}
|
|
906
|
+
]
|
|
907
|
+
},
|
|
908
|
+
toastSuccess: false,
|
|
909
|
+
toastError: false
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
})),
|
|
915
|
+
{ name: `Areas store` }
|
|
916
|
+
)
|
|
917
|
+
);
|
|
918
|
+
};
|
|
919
|
+
const AreasContext = createContext(null);
|
|
920
|
+
function AreasProvider(props) {
|
|
921
|
+
const {
|
|
922
|
+
children,
|
|
923
|
+
loadAreasFromNetwork,
|
|
924
|
+
loadCookiesFromNetwork,
|
|
925
|
+
onLoad,
|
|
926
|
+
onSelectLayout
|
|
927
|
+
} = props;
|
|
928
|
+
const {
|
|
929
|
+
events_add_listener,
|
|
930
|
+
events_remove_listener
|
|
931
|
+
} = useHostTools();
|
|
932
|
+
const {
|
|
933
|
+
getLabel
|
|
934
|
+
} = useModuleDictionary();
|
|
935
|
+
const {
|
|
936
|
+
networkOperation
|
|
937
|
+
} = useNetwork();
|
|
938
|
+
const isDesktop = useResponsiveDesktop();
|
|
939
|
+
const isSkeleton = useModuleSkeleton();
|
|
940
|
+
const isFirstRender = useFirstRender([getLabel]);
|
|
941
|
+
const areasStoreRef = useRef();
|
|
942
|
+
if (!areasStoreRef.current) {
|
|
943
|
+
areasStoreRef.current = createAreasStore({
|
|
944
|
+
getLabel,
|
|
945
|
+
loadAreasFromNetwork,
|
|
946
|
+
loadCookiesFromNetwork,
|
|
947
|
+
networkOperation,
|
|
948
|
+
ownerState: {
|
|
949
|
+
status: "init",
|
|
950
|
+
isMobile: !isDesktop,
|
|
951
|
+
isSkeleton
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
areasStoreRef.current?.getState().areasActions.init();
|
|
955
|
+
}
|
|
956
|
+
const status = useStore(areasStoreRef.current, (state) => state.ownerState.status, shallow);
|
|
957
|
+
const currentModuleId = useStore(areasStoreRef.current, (state) => state.currentModuleId);
|
|
958
|
+
const refCurrentModuleId = useRef("");
|
|
959
|
+
const {
|
|
960
|
+
setHandlerGetLabel,
|
|
961
|
+
setExternalState
|
|
962
|
+
} = useStore(areasStoreRef.current, (state) => state.areasActions, shallow);
|
|
963
|
+
const addWindow = useCallback((newWindow) => {
|
|
964
|
+
const currentArea = areasStoreRef.current?.getState().currentAreaId;
|
|
965
|
+
const areas = areasStoreRef.current?.getState().areas;
|
|
966
|
+
if (currentArea && areas) {
|
|
967
|
+
areasStoreRef.current?.getState().areaActions.addWindow(newWindow);
|
|
968
|
+
}
|
|
969
|
+
}, []);
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
if (status === "loaded") {
|
|
972
|
+
onLoad && onLoad();
|
|
973
|
+
}
|
|
974
|
+
}, [status]);
|
|
975
|
+
useEffect(() => {
|
|
976
|
+
if (status === "loaded") {
|
|
977
|
+
if (currentModuleId !== refCurrentModuleId.current) {
|
|
978
|
+
onSelectLayout && onSelectLayout(currentModuleId);
|
|
979
|
+
refCurrentModuleId.current = currentModuleId;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}, [currentModuleId, status]);
|
|
983
|
+
useEffect(() => {
|
|
984
|
+
if (!isFirstRender) {
|
|
985
|
+
setHandlerGetLabel(getLabel);
|
|
986
|
+
}
|
|
987
|
+
}, [getLabel]);
|
|
988
|
+
useEffect(() => {
|
|
989
|
+
events_add_listener(EmitEvents.EMMIT_EVENT_HOST_EMERGE_WINDOW, addWindow);
|
|
990
|
+
return () => {
|
|
991
|
+
events_remove_listener(EmitEvents.EMMIT_EVENT_HOST_EMERGE_WINDOW, addWindow);
|
|
992
|
+
};
|
|
993
|
+
}, []);
|
|
994
|
+
useEffect(() => {
|
|
995
|
+
if (isFirstRender) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
setExternalState({
|
|
999
|
+
isMobile: !isDesktop,
|
|
1000
|
+
isSkeleton
|
|
1001
|
+
});
|
|
1002
|
+
}, [isDesktop, isSkeleton]);
|
|
1003
|
+
return /* @__PURE__ */ jsx(AreasContext.Provider, {
|
|
1004
|
+
value: areasStoreRef.current,
|
|
1005
|
+
children
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
export {
|
|
1009
|
+
AreasContext as A,
|
|
1010
|
+
CONTAINER_PADDING_GRIDLAYOUT as C,
|
|
1011
|
+
MARGIN_GRIDLAYOUT as M,
|
|
1012
|
+
ROW_HEIGTH_GRIDLAYOUT as R,
|
|
1013
|
+
THROTTLE_RESIZE_TIME as T,
|
|
1014
|
+
AreasProvider as a
|
|
1015
|
+
};
|