@m4l/components 0.1.69 → 0.1.71

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