@apia/dashboard-controller 5.0.0 → 5.0.3

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 (178) hide show
  1. package/dist/actions/externalFirePanelAction.d.ts +6 -0
  2. package/dist/actions/externalFirePanelAction.d.ts.map +1 -0
  3. package/dist/actions/externalFirePanelAction.js +12 -0
  4. package/dist/actions/externalFirePanelAction.js.map +1 -0
  5. package/dist/actions/firePanelAction.d.ts +6 -0
  6. package/dist/actions/firePanelAction.d.ts.map +1 -0
  7. package/dist/actions/firePanelAction.js +76 -0
  8. package/dist/actions/firePanelAction.js.map +1 -0
  9. package/dist/actions/useActionEventHandlers.d.ts +10 -0
  10. package/dist/actions/useActionEventHandlers.d.ts.map +1 -0
  11. package/dist/actions/useActionEventHandlers.js +67 -0
  12. package/dist/actions/useActionEventHandlers.js.map +1 -0
  13. package/dist/actions/usePanelActions.d.ts +65 -0
  14. package/dist/actions/usePanelActions.d.ts.map +1 -0
  15. package/dist/actions/usePanelActions.js +55 -0
  16. package/dist/actions/usePanelActions.js.map +1 -0
  17. package/dist/actions/usePanelIsLoading.d.ts +4 -0
  18. package/dist/actions/usePanelIsLoading.d.ts.map +1 -0
  19. package/dist/actions/usePanelIsLoading.js +14 -0
  20. package/dist/actions/usePanelIsLoading.js.map +1 -0
  21. package/dist/actions/usePanelNetworkState.d.ts +8 -0
  22. package/dist/actions/usePanelNetworkState.d.ts.map +1 -0
  23. package/dist/actions/usePanelNetworkState.js +21 -0
  24. package/dist/actions/usePanelNetworkState.js.map +1 -0
  25. package/dist/common/usePanelIdentity.d.ts +10 -0
  26. package/dist/common/usePanelIdentity.d.ts.map +1 -0
  27. package/dist/common/usePanelIdentity.js +12 -0
  28. package/dist/common/usePanelIdentity.js.map +1 -0
  29. package/dist/config/parametersStore.d.ts +15 -0
  30. package/dist/config/parametersStore.d.ts.map +1 -0
  31. package/dist/config/parametersStore.js +27 -0
  32. package/dist/config/parametersStore.js.map +1 -0
  33. package/dist/config/saveParameters.d.ts +11 -0
  34. package/dist/config/saveParameters.d.ts.map +1 -0
  35. package/dist/config/saveParameters.js +16 -0
  36. package/dist/config/saveParameters.js.map +1 -0
  37. package/dist/config/usePanelConfig.js +49 -0
  38. package/dist/config/usePanelConfig.js.map +1 -0
  39. package/dist/config/usePanelParametersSelector.d.ts +25 -0
  40. package/dist/config/usePanelParametersSelector.d.ts.map +1 -0
  41. package/dist/config/usePanelParametersSelector.js +17 -0
  42. package/dist/config/usePanelParametersSelector.js.map +1 -0
  43. package/dist/dashboard/ContainerNotFound.js +14 -0
  44. package/dist/dashboard/ContainerNotFound.js.map +1 -0
  45. package/dist/dashboard/DashboardContext.d.ts +6 -0
  46. package/dist/dashboard/DashboardContext.d.ts.map +1 -0
  47. package/dist/dashboard/DashboardContext.js +12 -0
  48. package/dist/dashboard/DashboardContext.js.map +1 -0
  49. package/dist/dashboard/DashboardPanel.d.ts +48 -0
  50. package/dist/dashboard/DashboardPanel.d.ts.map +1 -0
  51. package/dist/dashboard/DashboardPanel.js +264 -0
  52. package/dist/dashboard/DashboardPanel.js.map +1 -0
  53. package/dist/dashboard/DashboardPanelContext.d.ts +6 -0
  54. package/dist/dashboard/DashboardPanelContext.d.ts.map +1 -0
  55. package/dist/dashboard/DashboardPanelContext.js +12 -0
  56. package/dist/dashboard/DashboardPanelContext.js.map +1 -0
  57. package/dist/dashboard/DashboardPanelsBootstraper.d.ts +33 -0
  58. package/dist/dashboard/DashboardPanelsBootstraper.d.ts.map +1 -0
  59. package/dist/dashboard/DashboardPanelsBootstraper.js +135 -0
  60. package/dist/dashboard/DashboardPanelsBootstraper.js.map +1 -0
  61. package/dist/dashboard/DashboardRouter.d.ts +30 -0
  62. package/dist/dashboard/DashboardRouter.d.ts.map +1 -0
  63. package/dist/dashboard/DashboardRouter.js +74 -0
  64. package/dist/dashboard/DashboardRouter.js.map +1 -0
  65. package/dist/dashboard/PanelNotFound.js +17 -0
  66. package/dist/dashboard/PanelNotFound.js.map +1 -0
  67. package/dist/dashboard/dashboard.d.ts +28 -0
  68. package/dist/dashboard/dashboard.d.ts.map +1 -0
  69. package/dist/dashboard/dashboard.js +174 -0
  70. package/dist/dashboard/dashboard.js.map +1 -0
  71. package/dist/eventsController/eventsController.d.ts +11 -0
  72. package/dist/eventsController/eventsController.d.ts.map +1 -0
  73. package/dist/eventsController/eventsController.js +57 -0
  74. package/dist/eventsController/eventsController.js.map +1 -0
  75. package/dist/eventsController/types.d.ts +21 -0
  76. package/dist/eventsController/types.d.ts.map +1 -0
  77. package/dist/eventsController/usePanelFireEvent.d.ts +13 -0
  78. package/dist/eventsController/usePanelFireEvent.d.ts.map +1 -0
  79. package/dist/eventsController/usePanelFireEvent.js +21 -0
  80. package/dist/eventsController/usePanelFireEvent.js.map +1 -0
  81. package/dist/eventsController/usePanelOnEvent.d.ts +12 -0
  82. package/dist/eventsController/usePanelOnEvent.d.ts.map +1 -0
  83. package/dist/eventsController/usePanelOnEvent.js +14 -0
  84. package/dist/eventsController/usePanelOnEvent.js.map +1 -0
  85. package/dist/index.d.ts +31 -459
  86. package/dist/index.js +28 -2241
  87. package/dist/index.js.map +1 -1
  88. package/dist/panelsStore/createPanelStore.d.ts +16 -0
  89. package/dist/panelsStore/createPanelStore.d.ts.map +1 -0
  90. package/dist/panelsStore/createPanelStore.js +58 -0
  91. package/dist/panelsStore/createPanelStore.js.map +1 -0
  92. package/dist/panelsStore/panelsStore.js +59 -0
  93. package/dist/panelsStore/panelsStore.js.map +1 -0
  94. package/dist/panelsStore/usePanelSelector.js +32 -0
  95. package/dist/panelsStore/usePanelSelector.js.map +1 -0
  96. package/dist/panelsUtil/usePanelChangeTitle.d.ts +7 -0
  97. package/dist/panelsUtil/usePanelChangeTitle.d.ts.map +1 -0
  98. package/dist/panelsUtil/usePanelChangeTitle.js +19 -0
  99. package/dist/panelsUtil/usePanelChangeTitle.js.map +1 -0
  100. package/dist/panelsUtil/usePanelTitleAction.d.ts +5 -0
  101. package/dist/panelsUtil/usePanelTitleAction.d.ts.map +1 -0
  102. package/dist/panelsUtil/usePanelTitleAction.js +48 -0
  103. package/dist/panelsUtil/usePanelTitleAction.js.map +1 -0
  104. package/dist/position/usePanelPosition.d.ts +13 -0
  105. package/dist/position/usePanelPosition.d.ts.map +1 -0
  106. package/dist/position/usePanelPosition.js +40 -0
  107. package/dist/position/usePanelPosition.js.map +1 -0
  108. package/dist/splash/events/Dragleave.js +15 -0
  109. package/dist/splash/events/Dragleave.js.map +1 -0
  110. package/dist/splash/events/Dragover.js +120 -0
  111. package/dist/splash/events/Dragover.js.map +1 -0
  112. package/dist/splash/events/Dragstart.js +65 -0
  113. package/dist/splash/events/Dragstart.js.map +1 -0
  114. package/dist/splash/events/Drop.js +66 -0
  115. package/dist/splash/events/Drop.js.map +1 -0
  116. package/dist/splash/panels/DefaultPanelWrapper/CollapseButton.js +31 -0
  117. package/dist/splash/panels/DefaultPanelWrapper/CollapseButton.js.map +1 -0
  118. package/dist/splash/panels/DefaultPanelWrapper/NetworkState.d.ts +8 -0
  119. package/dist/splash/panels/DefaultPanelWrapper/NetworkState.d.ts.map +1 -0
  120. package/dist/splash/panels/DefaultPanelWrapper/NetworkState.js +28 -0
  121. package/dist/splash/panels/DefaultPanelWrapper/NetworkState.js.map +1 -0
  122. package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.d.ts +10 -0
  123. package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.d.ts.map +1 -0
  124. package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.js +32 -0
  125. package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.js.map +1 -0
  126. package/dist/splash/panels/DefaultPanelWrapper/RefreshButton.js +35 -0
  127. package/dist/splash/panels/DefaultPanelWrapper/RefreshButton.js.map +1 -0
  128. package/dist/splash/panels/DefaultPanelWrapper/SettingsButton.js +45 -0
  129. package/dist/splash/panels/DefaultPanelWrapper/SettingsButton.js.map +1 -0
  130. package/dist/splash/panels/DefaultPanelWrapper/index.js +82 -0
  131. package/dist/splash/panels/DefaultPanelWrapper/index.js.map +1 -0
  132. package/dist/splash/panels/EmptyPanelWrapper/index.d.ts +6 -0
  133. package/dist/splash/panels/EmptyPanelWrapper/index.d.ts.map +1 -0
  134. package/dist/splash/panels/EmptyPanelWrapper/index.js +10 -0
  135. package/dist/splash/panels/EmptyPanelWrapper/index.js.map +1 -0
  136. package/dist/splash/panels/LandingPagePanelWrapper.d.ts +6 -0
  137. package/dist/splash/panels/LandingPagePanelWrapper.d.ts.map +1 -0
  138. package/dist/splash/panels/LandingPagePanelWrapper.js +49 -0
  139. package/dist/splash/panels/LandingPagePanelWrapper.js.map +1 -0
  140. package/dist/splash/panels/PanelContext/PanelFooter.d.ts +9 -0
  141. package/dist/splash/panels/PanelContext/PanelFooter.d.ts.map +1 -0
  142. package/dist/splash/panels/PanelContext/PanelFooter.js +72 -0
  143. package/dist/splash/panels/PanelContext/PanelFooter.js.map +1 -0
  144. package/dist/splash/panels/PanelContext/index.d.ts +46 -0
  145. package/dist/splash/panels/PanelContext/index.d.ts.map +1 -0
  146. package/dist/splash/panels/PanelContext/index.js +66 -0
  147. package/dist/splash/panels/PanelContext/index.js.map +1 -0
  148. package/dist/splash/panels/PanelContext/usePanelContextLayout.d.ts +6 -0
  149. package/dist/splash/panels/PanelContext/usePanelContextLayout.d.ts.map +1 -0
  150. package/dist/splash/panels/PanelContext/usePanelContextLayout.js +38 -0
  151. package/dist/splash/panels/PanelContext/usePanelContextLayout.js.map +1 -0
  152. package/dist/splash/panels/PanelContext/usePanelFooter.d.ts +11 -0
  153. package/dist/splash/panels/PanelContext/usePanelFooter.d.ts.map +1 -0
  154. package/dist/splash/panels/PanelContext/usePanelFooter.js +35 -0
  155. package/dist/splash/panels/PanelContext/usePanelFooter.js.map +1 -0
  156. package/dist/splash/panels/PanelContext/useYieldPanelIsReady.d.ts +45 -0
  157. package/dist/splash/panels/PanelContext/useYieldPanelIsReady.d.ts.map +1 -0
  158. package/dist/splash/panels/PanelContext/useYieldPanelIsReady.js +12 -0
  159. package/dist/splash/panels/PanelContext/useYieldPanelIsReady.js.map +1 -0
  160. package/dist/splash/panels/PanelErrorBoundary.js +53 -0
  161. package/dist/splash/panels/PanelErrorBoundary.js.map +1 -0
  162. package/dist/splash/panels/PanelIdentifier.d.ts +16 -0
  163. package/dist/splash/panels/PanelIdentifier.d.ts.map +1 -0
  164. package/dist/splash/panels/PanelIdentifier.js +19 -0
  165. package/dist/splash/panels/PanelIdentifier.js.map +1 -0
  166. package/dist/splash/util/DragAndDrop.js +244 -0
  167. package/dist/splash/util/DragAndDrop.js.map +1 -0
  168. package/dist/splash/util/getColumnAreas.js +19 -0
  169. package/dist/splash/util/getColumnAreas.js.map +1 -0
  170. package/dist/splash/util/isCursorInArea.js +13 -0
  171. package/dist/splash/util/isCursorInArea.js.map +1 -0
  172. package/dist/types.d.ts +30 -0
  173. package/dist/types.d.ts.map +1 -0
  174. package/dist/util.d.ts +8 -0
  175. package/dist/util.d.ts.map +1 -0
  176. package/dist/util.js +55 -0
  177. package/dist/util.js.map +1 -0
  178. package/package.json +9 -8
package/dist/index.js CHANGED
@@ -1,2242 +1,29 @@
1
- import { ApiaApi, makeApiaUrl } from '@apia/api';
2
- import { EventEmitter, useMount, useImperativeComponentEvents, getLabel, makeImperativeComponent, toBoolean, parseXmlAsync, isChild, getSpecificParent, ucfirst, downloadUrl, useLatest } from '@apia/util';
3
- import { createContext, useMemo, useContext, useState, useEffect, useCallback, useRef, useDeferredValue, Suspense, lazy, Component, startTransition } from 'react';
4
- import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
5
- import { Icon } from '@apia/icons';
6
- import { spacingLayouts, Box, getVariant, Heading, makeStyledComponent, Paragraph } from '@apia/theme';
7
- import { shallowEqual } from 'react-redux';
8
- import { injectReducers, createSlice, shallowEqual as shallowEqual$1 } from '@apia/store';
9
- import { IconButton, AutoEllipsis, SimpleButton } from '@apia/components';
10
- import { createPortal } from 'react-dom';
11
-
12
- const PanelIdentifierContext = createContext(void 0);
13
- const PanelIdentifier = ({
14
- children,
15
- name,
16
- id,
17
- title,
18
- type
19
- }) => {
20
- const contextValue = useMemo(() => {
21
- return { panelName: name, panelId: id, panelTitle: title, panelType: type };
22
- }, []);
23
- return /* @__PURE__ */ jsx(PanelIdentifierContext.Provider, { value: contextValue, children });
24
- };
25
-
26
- function usePanelIdentity() {
27
- const context = useContext(PanelIdentifierContext);
28
- if (!context)
29
- throw new Error("Trying to access an unexistent PanelIdentifierContext");
30
- return context;
31
- }
32
-
33
- class PanelPositionEmitter extends EventEmitter {
34
- }
35
- const panelPositionEmitter = new PanelPositionEmitter();
36
- function usePanelPosition() {
37
- const { panelId } = usePanelIdentity();
38
- const [position, setPosition] = useState();
39
- useEffect(() => {
40
- return panelPositionEmitter.on("panelUpdate", (ev) => {
41
- if (ev.panelId === panelId)
42
- setPosition({ containerId: ev.containerId, position: ev.newPosition });
43
- });
44
- }, [panelId]);
45
- return position;
46
- }
47
- async function updatePanelPosition(panelId, containerId, newPosition) {
48
- const result = await ApiaApi.post(
49
- makeApiaUrl({
50
- action: "panelMove",
51
- pnlId: panelId,
52
- containerId,
53
- newPosition
54
- })
55
- );
56
- const hasUpdated = result?.data && !result.hasError && !result.hasMessages;
57
- if (hasUpdated)
58
- panelPositionEmitter.emit("panelUpdate", {
59
- panelId,
60
- containerId,
61
- newPosition
62
- });
63
- return hasUpdated;
64
- }
65
-
66
- const DashboardPanelContext = createContext(null);
67
- function useDashboardPanel() {
68
- const context = useContext(DashboardPanelContext);
69
- if (!context)
70
- throw new Error("There is no DashboardPanelContext");
71
- return context;
72
- }
73
-
74
- var __defProp$7 = Object.defineProperty;
75
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
76
- var __publicField$7 = (obj, key, value) => {
77
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
78
- return value;
79
- };
80
- const panelActionsEmitter = new class PanelActionsEmitter {
81
- constructor() {
82
- __publicField$7(this, "listeners", {});
83
- __publicField$7(this, "on", (panelId, action, cb) => {
84
- if (!this.listeners[panelId])
85
- this.listeners[panelId] = {};
86
- if (!this.listeners[panelId][action])
87
- this.listeners[panelId][action] = [];
88
- this.listeners[panelId][action].push(cb);
89
- return () => {
90
- this.listeners[panelId][action] = this.listeners[panelId][action].filter(
91
- (current) => current !== cb
92
- );
93
- };
94
- });
95
- __publicField$7(this, "emit", (panelId, action, data) => {
96
- this.listeners[panelId]?.[action]?.forEach((current) => {
97
- window.requestAnimationFrame(() => {
98
- current({ action, panelId, data });
99
- });
100
- });
101
- });
102
- }
103
- }();
104
- function usePanelActions(actionsHandler) {
105
- const { panelId } = usePanelIdentity();
106
- useMount(() => {
107
- const subscriptions = [];
108
- Object.entries(actionsHandler ?? {}).forEach(([action, handler]) => {
109
- subscriptions.push(
110
- panelActionsEmitter.on(panelId, action, (res) => {
111
- handler(res.data);
112
- })
113
- );
114
- });
115
- return () => {
116
- subscriptions.forEach((unsubscribe) => unsubscribe());
117
- };
118
- });
119
- const panel = useDashboardPanel();
120
- return panel.fireAction;
121
- }
122
-
123
- class PanelNetworkStateEmitter extends EventEmitter {
124
- }
125
- const panelNetworkStateEmitter = new PanelNetworkStateEmitter();
126
- const usePanelNetworkState = () => {
127
- const [isConnected, setIsConnected] = useState(true);
128
- const { panelId } = usePanelIdentity();
129
- useEffect(() => {
130
- return panelNetworkStateEmitter.on("stateChange", (ev) => {
131
- if (ev.panelId === panelId && ev.isConnected !== isConnected)
132
- setIsConnected(ev.isConnected);
133
- });
134
- }, [isConnected, panelId]);
135
- return isConnected;
136
- };
137
-
138
- var __defProp$6 = Object.defineProperty;
139
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
140
- var __publicField$6 = (obj, key, value) => {
141
- __defNormalProp$6(obj, key + "" , value);
142
- return value;
143
- };
144
- function identifierAfitsOnB(a, b) {
145
- for (const key of Object.keys(a)) {
146
- if (a[key] !== b[key])
147
- return false;
148
- }
149
- return true;
150
- }
151
- const eventsController = new class EventsController {
152
- constructor() {
153
- __publicField$6(this, "callbacks", []);
154
- }
155
- broadcast(eventType, payload) {
156
- const origin = {
157
- panelId: "broadcast",
158
- panelName: "broadcast",
159
- panelType: "broadcast",
160
- panelTitle: "broadcast"
161
- };
162
- this.callbacks.forEach(({ callback, ...current }) => {
163
- if (eventType === current.eventType) {
164
- callback({ ...origin, eventType, payload });
165
- }
166
- });
167
- }
168
- fireEvent(origin, eventType, payload) {
169
- if ([origin.panelId, origin.panelName, origin.panelType].includes("*"))
170
- throw new Error(
171
- "Broadcast is not allowed through fireEvent, use broadcast instead"
172
- );
173
- this.callbacks.forEach(({ callback, ...current }) => {
174
- if (identifierAfitsOnB(current, { ...origin, eventType })) {
175
- callback({ ...origin, eventType, payload });
176
- }
177
- });
178
- }
179
- onEvent(distinction, callback) {
180
- const register = {
181
- ...distinction,
182
- callback
183
- };
184
- this.callbacks.push(register);
185
- return () => {
186
- this.callbacks = this.callbacks.filter((current) => {
187
- return current !== register;
188
- });
189
- };
190
- }
191
- }();
192
-
193
- function usePanelFireEvent() {
194
- const { panelId, panelName, panelType, panelTitle } = usePanelIdentity();
195
- const fireEvent = useCallback(
196
- (eventType, payload) => {
197
- eventsController.fireEvent(
198
- { panelId, panelName, panelType, panelTitle },
199
- eventType,
200
- payload
201
- );
202
- },
203
- [panelId, panelName, panelType, panelTitle]
204
- );
205
- return fireEvent;
206
- }
207
-
208
- function usePanelOnEvent(distinction, callback) {
209
- useEffect(() => {
210
- const unsuscriber = eventsController.onEvent(distinction, callback);
211
- return () => {
212
- unsuscriber();
213
- };
214
- });
215
- }
216
-
217
- function changePanelTitle(identifier, newTitle) {
218
- eventsController.fireEvent(identifier, "__changePanelTitle__", newTitle);
219
- }
220
- function usePanelChangeTitle() {
221
- const fireEvent = usePanelFireEvent();
222
- return useCallback(
223
- (newTitle) => {
224
- fireEvent("__changePanelTitle__", newTitle);
225
- },
226
- [fireEvent]
227
- );
228
- }
229
-
230
- function changePanelFooter(panelId, footer) {
231
- eventsController.fireEvent(
232
- { panelId },
233
- "changeFooter",
234
- footer
235
- );
236
- }
237
- function usePanelFooter({
238
- initialData
239
- }) {
240
- const identifier = usePanelIdentity();
241
- const [footer, setFooter] = useState(
242
- initialData?.footer?.footer?.text || initialData?.footer?.footer?.force ? initialData?.footer?.footer : null
243
- );
244
- const handleFooterClick = useCallback(
245
- (ev) => {
246
- if (footer)
247
- handleAction(identifier, ev, footer);
248
- },
249
- [footer, identifier]
250
- );
251
- usePanelOnEvent(
252
- { eventType: "changeFooter", panelId: identifier.panelId },
253
- (ev) => {
254
- if (!ev.payload.text && !ev.payload.force)
255
- setFooter(null);
256
- else
257
- setFooter(ev.payload);
258
- }
259
- );
260
- return { footer, handleFooterClick };
261
- }
262
-
263
- const paramsSlice = createSlice({
264
- initialState: {},
265
- name: "panelParameters",
266
- reducers: {
267
- udpate(state, {
268
- payload
269
- }) {
270
- if (!state[payload.panelId])
271
- state[payload.panelId] = {};
272
- state[payload.panelId] = {
273
- ...state[payload.panelId],
274
- ...payload.parameters
275
- };
276
- }
277
- }
278
- });
279
- const { store, useSelector } = injectReducers({
280
- panelParameters: paramsSlice.reducer
281
- });
282
- const parametersActions = paramsSlice.actions;
283
-
284
- function saveParameters(panelId, parameters, refresh = true) {
285
- store.dispatch(parametersActions.udpate({ panelId, parameters }));
286
- if (refresh) {
287
- panelActionsEmitter.emit(panelId, "configurationApply", {
288
- data: parameters
289
- });
290
- firePanelAction(panelId, "refresh");
291
- }
292
- }
293
-
294
- const DashboardContext = createContext(null);
295
- function useDashboardContext() {
296
- const context = useContext(DashboardContext);
297
- if (!context)
298
- throw new Error("There is no Dashboard context");
299
- return context;
300
- }
301
-
302
- const RefreshButton = (props) => {
303
- const [isDisabled, setIsDisabled] = useState(false);
304
- const isLoading = usePanelIsLoading();
305
- const dispatch = usePanelActions();
306
- useImperativeComponentEvents({
307
- disable(newDisabledValue) {
308
- setIsDisabled(newDisabledValue);
309
- }
310
- });
311
- return /* @__PURE__ */ jsx(
312
- IconButton,
313
- {
314
- icon: "Refresh",
315
- variant: "buttons.icon-outline",
316
- className: "panel__iconButton",
317
- size: "Md",
318
- onClick: useCallback(() => {
319
- void dispatch({ action: "refresh" });
320
- }, [dispatch]),
321
- title: getLabel("lblRefreshPnl", { text: { TOK1: props.title } }).text,
322
- isLoading,
323
- disabled: isDisabled
324
- }
325
- );
326
- };
327
-
328
- class ConfigEmitter extends EventEmitter {
329
- }
330
- new ConfigEmitter();
331
- function usePanelConfig() {
332
- const { panelId } = usePanelIdentity();
333
- return function config() {
334
- void ApiaApi.post(
335
- makeApiaUrl({
336
- action: "panelEdit",
337
- pnlId: panelId
338
- }),
339
- {
340
- handleLoad: true,
341
- modalConfiguration: {
342
- async onFieldChange(element, handler) {
343
- if (element.onChange === "refresh") {
344
- await ApiaApi.post(
345
- makeApiaUrl({
346
- action: "panelEditConfirm",
347
- pnlId: panelId
348
- }),
349
- {
350
- postData: { [`${element.name}`]: element.value },
351
- postDataTreatement: "stringify"
352
- }
353
- );
354
- const newForm = await ApiaApi.post(
355
- makeApiaUrl({
356
- action: "panelEdit",
357
- pnlId: panelId
358
- })
359
- );
360
- if (newForm?.data) {
361
- handler.assignForm(newForm.data);
362
- }
363
- }
364
- }
365
- }
366
- }
367
- );
368
- };
369
- }
370
-
371
- const SettingsButton = (props) => {
372
- const { panelId } = usePanelIdentity();
373
- const configure = usePanelConfig();
374
- const [isDisabled, setIsDisabled] = useState(false);
375
- useImperativeComponentEvents({
376
- disable(newDisabledValue) {
377
- setIsDisabled(newDisabledValue);
378
- }
379
- });
380
- usePanelActions({
381
- refresh() {
382
- panelButtonsActions(panelId, "disable", false);
383
- }
384
- });
385
- const openSettings = useCallback(() => {
386
- try {
387
- configure();
388
- } catch (e) {
389
- }
390
- }, [configure]);
391
- return /* @__PURE__ */ jsx(
392
- IconButton,
393
- {
394
- icon: "Settings",
395
- size: "Md",
396
- variant: "buttons.icon-outline",
397
- className: "panel__iconButton",
398
- onClick: openSettings,
399
- title: getLabel("lblOpenPnlConf", { text: { TOK1: props.title } }).text,
400
- disabled: isDisabled
401
- }
402
- );
403
- };
404
-
405
- const [, panelButtonsActions, PanelButtons] = makeImperativeComponent()({
406
- Component: (props) => {
407
- return /* @__PURE__ */ jsxs(Fragment, { children: [
408
- props.isRefreshable && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(RefreshButton, { ...props }) }),
409
- props.isConfigurable && /* @__PURE__ */ jsx(SettingsButton, { title: props.title })
410
- ] });
411
- }
412
- });
413
-
414
- function usePanelContextLayout() {
415
- const elRef = useRef(null);
416
- const layoutRef = useRef("clever");
417
- const clearClassNames = useCallback(() => {
418
- spacingLayouts.forEach(
419
- (current) => elRef.current?.querySelector(".panel__content")?.classList.remove(current)
420
- );
421
- }, []);
422
- const setRef = useCallback(
423
- (el) => {
424
- if (el instanceof HTMLDivElement) {
425
- elRef.current = el;
426
- clearClassNames();
427
- (el?.querySelector(".panel__content")).classList.add(
428
- layoutRef.current
429
- );
430
- }
431
- },
432
- [clearClassNames]
433
- );
434
- const setLayout = useCallback(
435
- (layout) => {
436
- if (layoutRef.current === layout)
437
- return;
438
- layoutRef.current = layout;
439
- clearClassNames();
440
- elRef.current?.querySelector(".panel__content")?.classList.add(layoutRef.current);
441
- },
442
- [clearClassNames]
443
- );
444
- return { ref: setRef, setLayout };
445
- }
446
-
447
- function useYieldPanelIsReady() {
448
- const { setRef } = usePanelContext();
449
- useMount(() => {
450
- setRef({});
451
- });
452
- }
453
-
454
- const PanelContext = createContext(null);
455
- function usePanelContext() {
456
- const context = useContext(PanelContext);
457
- if (!context)
458
- throw new Error("No panel wrapper context defined");
459
- return context;
460
- }
461
- const PanelContextProvider = ({
462
- children,
463
- value
464
- }) => {
465
- return /* @__PURE__ */ jsx(PanelContext.Provider, { value, children });
466
- };
467
- function useMakePanelContext(panelProps) {
468
- const identifier = usePanelIdentity();
469
- const setTitle = useCallback(
470
- (newTitle) => {
471
- changePanelTitle(identifier, newTitle);
472
- },
473
- [identifier]
474
- );
475
- const { ref, setLayout } = usePanelContextLayout();
476
- const [title, setTitleState] = useState(panelProps.title);
477
- usePanelOnEvent(
478
- { eventType: "changeTitle", panelId: identifier.panelId },
479
- (ev) => {
480
- setTitleState(ev.payload);
481
- }
482
- );
483
- const { footer, handleFooterClick } = usePanelFooter(panelProps);
484
- const [footerContent, setFooterContent] = useState(null);
485
- const dispatch = usePanelActions();
486
- const hasRefreshedOnStartup = useRef(false);
487
- const dashboard = useDashboardContext();
488
- const setRef = useCallback(
489
- (el) => {
490
- if (el && !hasRefreshedOnStartup.current) {
491
- hasRefreshedOnStartup.current = true;
492
- if (panelProps.refreshOnStart) {
493
- void dispatch({ action: "refresh" }).then(() => {
494
- dashboard.bootstrapper.setPanelHasLoaded(identifier.panelId);
495
- });
496
- } else {
497
- dashboard.bootstrapper.setPanelHasLoaded(identifier.panelId);
498
- }
499
- }
500
- },
501
- [
502
- dashboard.bootstrapper,
503
- dispatch,
504
- identifier.panelId,
505
- panelProps.refreshOnStart
506
- ]
507
- );
508
- const contextValue = useMemo(
509
- () => ({ setFooterContent, setTitle, setLayout, panelProps, setRef }),
510
- [setTitle, setLayout, panelProps, setRef]
511
- );
512
- return { footerContent, title, footer, handleFooterClick, contextValue, ref };
513
- }
514
-
515
- const PanelFooter = ({
516
- footerContent,
517
- isRefreshable,
518
- footer,
519
- handleFooterClick,
520
- force
521
- }) => {
522
- const [lastUpdate, setLastUpdate] = useState(0);
523
- usePanelActions({
524
- refresh() {
525
- setLastUpdate(Date.now());
526
- }
527
- });
528
- return /* @__PURE__ */ jsx(Fragment, { children: (isRefreshable || footer || force) && /* @__PURE__ */ jsxs("div", { className: "panel__footer", children: [
529
- footerContent ?? (footer && (!footer.action || footer.actionBehavior === "DO_NOTHING") && /* @__PURE__ */ jsx("div", { className: "panel__footer__text", children: /* @__PURE__ */ jsx(
530
- AutoEllipsis,
531
- {
532
- overrideStyles: (el) => {
533
- const styles = window.getComputedStyle(
534
- el.closest(".panel__footer")
535
- );
536
- const width = Number.parseInt(styles.width, 10);
537
- const padding = Number.parseInt(styles.paddingLeft, 10) + Number.parseInt(styles.paddingRight, 10);
538
- return {
539
- width: `${width - padding}px`
540
- };
541
- },
542
- children: footer.text
543
- }
544
- ) })),
545
- footer?.action && footer.actionBehavior !== "DO_NOTHING" && /* @__PURE__ */ jsx(
546
- SimpleButton,
547
- {
548
- onClick: handleFooterClick,
549
- onDoubleClick: handleFooterClick,
550
- variant: "link",
551
- className: "panel__footer__text",
552
- children: /* @__PURE__ */ jsx(
553
- AutoEllipsis,
554
- {
555
- overrideStyles: (el) => {
556
- const styles = window.getComputedStyle(
557
- el.closest(".panel__footer")
558
- );
559
- const width = Number.parseInt(styles.width, 10);
560
- const padding = Number.parseInt(styles.paddingLeft, 10) + Number.parseInt(styles.paddingRight, 10);
561
- return {
562
- width: `${width - padding}px`
563
- };
564
- },
565
- children: footer.text
566
- }
567
- )
568
- }
569
- ),
570
- !footer && /* @__PURE__ */ jsx("div", {}),
571
- lastUpdate > 0 && /* @__PURE__ */ jsxs(Box, { className: "lastUpdate__wrapper", children: [
572
- new Date(lastUpdate).toLocaleDateString(),
573
- " ",
574
- new Date(lastUpdate).toLocaleTimeString()
575
- ] })
576
- ] }) });
577
- };
578
-
579
- const DefaultPanelWrapper = ({ children, ...props }) => {
580
- const { panelId, panelName, panelType } = usePanelIdentity();
581
- const { contextValue, title, ref, ...footerProps } = useMakePanelContext(props);
582
- const panelTitleDescription = usePanelTitleDescription();
583
- const panelImage = usePanelImage() ?? props.image;
584
- const showHeader = props.showTitle || props.isConfigurable || props.isRefreshable || panelImage;
585
- const isLoading = usePanelIsLoading();
586
- return /* @__PURE__ */ jsx(Box, { ...getVariant("layout.common.dashboards.panel"), children: /* @__PURE__ */ jsx(PanelContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
587
- "div",
588
- {
589
- ref,
590
- className: `panel__container ${isLoading ? "isLoading" : ""}`,
591
- "data-panelname": panelName,
592
- "data-paneltype": panelType,
593
- "data-panelid": panelId,
594
- children: [
595
- showHeader && /* @__PURE__ */ jsxs(
596
- "div",
597
- {
598
- draggable: props.canMove,
599
- className: `panel__header ${props.canMove ? "drag_panel_container" : ""}`,
600
- children: [
601
- /* @__PURE__ */ jsxs(
602
- "div",
603
- {
604
- className: "panel__header__left",
605
- sx: {
606
- maxWidth: "80%",
607
- overflow: "hidden",
608
- whiteSpace: "nowrap"
609
- },
610
- children: [
611
- panelImage && !panelImage.match("(^.+null$)") && /* @__PURE__ */ jsx("img", { src: panelImage, className: "panel__icon" }),
612
- /* @__PURE__ */ jsxs(AutoEllipsis, { children: [
613
- props.showTitle && /* @__PURE__ */ jsx(
614
- "span",
615
- {
616
- className: "panel__title",
617
- title: panelTitleDescription ?? title,
618
- children: title
619
- }
620
- ),
621
- /* @__PURE__ */ jsx(NetworkState, { title })
622
- ] })
623
- ]
624
- }
625
- ),
626
- /* @__PURE__ */ jsx("div", { className: `panel__header__buttons`, children: /* @__PURE__ */ jsx(PanelButtons, { ...props, id: panelId }) })
627
- ]
628
- }
629
- ),
630
- /* @__PURE__ */ jsx("div", { className: "panel__content", children }),
631
- /* @__PURE__ */ jsx(PanelFooter, { isRefreshable: props.isRefreshable, ...footerProps })
632
- ]
633
- }
634
- ) }) });
635
- };
636
-
637
- var __defProp$5 = Object.defineProperty;
638
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
639
- var __publicField$5 = (obj, key, value) => {
640
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
641
- return value;
642
- };
643
- var __accessCheck$4 = (obj, member, msg) => {
644
- if (!member.has(obj))
645
- throw TypeError("Cannot " + msg);
646
- };
647
- var __privateGet$4 = (obj, member, getter) => {
648
- __accessCheck$4(obj, member, "read from private field");
649
- return member.get(obj);
650
- };
651
- var __privateAdd$4 = (obj, member, value) => {
652
- if (member.has(obj))
653
- throw TypeError("Cannot add the same private member more than once");
654
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
655
- };
656
- var __privateSet$2 = (obj, member, value, setter) => {
657
- __accessCheck$4(obj, member, "write to private field");
658
- member.set(obj, value);
659
- return value;
660
- };
661
- var _hasLoadedAll, _bootstrappedPanels, _hasLoaded, _initTimestamp, _timeoutTreshold, _checkAllHasLoaded, _removeSkeletons;
662
- class DashboardPanelsBootstraper {
663
- constructor(dashboard) {
664
- this.dashboard = dashboard;
665
- __privateAdd$4(this, _hasLoadedAll, false);
666
- __privateAdd$4(this, _bootstrappedPanels, {});
667
- __privateAdd$4(this, _hasLoaded, {});
668
- __privateAdd$4(this, _initTimestamp, Date.now());
669
- __privateAdd$4(this, _timeoutTreshold, (window.DASH_COURTAIN_TRESHOLD ?? 5) * 1e3);
670
- __privateAdd$4(this, _checkAllHasLoaded, () => {
671
- if (__privateGet$4(this, _hasLoadedAll))
672
- return true;
673
- const keys = Object.keys(__privateGet$4(this, _bootstrappedPanels));
674
- const hasLoadedAllPanels = !keys.find(
675
- (current) => !__privateGet$4(this, _hasLoaded)[current] && this.dashboard.getPanel(current).isVisible
676
- );
677
- const hasTimedOutLoading = Date.now() - __privateGet$4(this, _initTimestamp) > __privateGet$4(this, _timeoutTreshold);
678
- if (hasLoadedAllPanels || hasTimedOutLoading) {
679
- if (hasTimedOutLoading) {
680
- const nonBootstrappedPanels = Object.keys(__privateGet$4(this, _bootstrappedPanels)).filter((current) => !__privateGet$4(this, _hasLoaded)[current]).map((panelId) => {
681
- const panelProps = this.dashboard.getPanel(panelId).props;
682
- return panelProps;
683
- });
684
- console.warn(
685
- `The courtain was removed because of timeout, check that all panels are reporting according to useYieldPanelIsReady's documentation.
686
-
687
- It might have happened that all panels are reporting but the browser was too busy to handle all of them in time, in order to determine what is actually happen you can raise the DASH_COURTAIN_TRESHOLD to a very large number, like 20 for example.`,
688
- { nonBootstrappedPanels }
689
- );
690
- }
691
- __privateSet$2(this, _hasLoadedAll, true);
692
- __privateGet$4(this, _removeSkeletons).call(this);
693
- return true;
694
- }
695
- return false;
696
- });
697
- __privateAdd$4(this, _removeSkeletons, () => {
698
- const skeleton = document.querySelector(
699
- "#DashLayoutCourtain"
700
- );
701
- const dashContent = document.querySelector(
702
- "#DashLayoutContent"
703
- );
704
- skeleton.style.display = "none";
705
- dashContent.style.visibility = "initial";
706
- skeleton.remove();
707
- });
708
- /**
709
- * El bootstraper se basa en dos elementos: setHasLoadedInitialData y
710
- * SuspendPanelUntilDashboardReady.
711
- *
712
- * El funcionamiento es muy elemental: Cada panel utiliza el Suspend como
713
- * wrapper y éste registra el id del panel en un array de paneles pendientes
714
- * por cargar.
715
- *
716
- * Una vez que todos los paneles cargaron, el suspense retoma su tarea y
717
- * renderiza el panel normalmente.
718
- */
719
- __publicField$5(this, "setPanelHasLoaded", (panelId) => {
720
- __privateGet$4(this, _hasLoaded)[panelId] = true;
721
- this.dashboard.getPanel(panelId).setHasLoaded();
722
- });
723
- __publicField$5(this, "SuspendPanelUntilDashbordReady", ({
724
- children,
725
- panelId
726
- }) => {
727
- const [hasBootstraped, setHasBootstraped] = useState(false);
728
- const deferredHasBootstraped = useDeferredValue(hasBootstraped);
729
- __privateGet$4(this, _bootstrappedPanels)[panelId] = true;
730
- const LoadWaiter = useCallback(() => {
731
- if (!__privateGet$4(this, _checkAllHasLoaded).call(this))
732
- void new Promise((resolve) => {
733
- const interval = setInterval(() => {
734
- if (__privateGet$4(this, _checkAllHasLoaded).call(this)) {
735
- resolve();
736
- clearInterval(interval);
737
- }
738
- }, 300);
739
- });
740
- return null;
741
- }, []);
742
- if (!deferredHasBootstraped)
743
- return /* @__PURE__ */ jsx(
744
- "div",
745
- {
746
- ref: (el) => {
747
- if (el)
748
- setHasBootstraped(true);
749
- }
750
- }
751
- );
752
- return /* @__PURE__ */ jsxs(Suspense, { fallback: null, children: [
753
- children,
754
- /* @__PURE__ */ jsx(LoadWaiter, {})
755
- ] });
756
- });
757
- }
758
- }
759
- _hasLoadedAll = new WeakMap();
760
- _bootstrappedPanels = new WeakMap();
761
- _hasLoaded = new WeakMap();
762
- _initTimestamp = new WeakMap();
763
- _timeoutTreshold = new WeakMap();
764
- _checkAllHasLoaded = new WeakMap();
765
- _removeSkeletons = new WeakMap();
766
-
767
- const PanelNotFound = () => {
768
- const props = usePanelIdentity();
769
- useYieldPanelIsReady();
770
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Heading, { children: [
771
- "Panel not found: ",
772
- props.panelType
773
- ] }) });
774
- };
775
-
776
- const ContainerNotFound = () => {
777
- const props = usePanelIdentity();
778
- return /* @__PURE__ */ jsxs(Heading, { children: [
779
- "Container not found for panel: ",
780
- props.panelName
781
- ] });
782
- };
783
-
784
- const importedContainers = {};
785
- const importedPanels = {};
786
- function importContainer(path) {
787
- if (!importedContainers[path])
788
- importedContainers[path] = lazy(() => {
789
- return new Promise((resolve) => {
790
- import(
791
- /* webpackChunkName: "[request]" */
792
- /* webpackInclude: /\.tsx?$/ */
793
- /* webpackPreload: true */
794
- `/containers/${path}`
795
- ).then((result) => {
796
- resolve(result.default);
797
- }).catch((e) => {
798
- console.error(e);
799
- resolve({
800
- default: ContainerNotFound
801
- });
802
- });
803
- });
804
- });
805
- return importedContainers[path];
806
- }
807
- function importPanel(path) {
808
- if (!importedPanels[path])
809
- importedPanels[path] = lazy(() => {
810
- return new Promise((resolve) => {
811
- import(
812
- /* webpackChunkName: "[request]" */
813
- /* webpackInclude: /\.tsx?$/ */
814
- /* webpackPreload: true */
815
- `/panels/${path}`
816
- ).then(
817
- (result) => {
818
- resolve(result.default);
819
- }
820
- ).catch((e) => {
821
- console.error(e);
822
- resolve({
823
- default: PanelNotFound
824
- });
825
- });
826
- });
827
- });
828
- return importedPanels[path];
829
- }
830
-
831
- var __defProp$4 = Object.defineProperty;
832
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
833
- var __publicField$4 = (obj, key, value) => {
834
- __defNormalProp$4(obj, key + "" , value);
835
- return value;
836
- };
837
- const Error2 = makeStyledComponent(
838
- "Error",
839
- "layout.panels.error",
840
- {
841
- ".panelError__wrapper": {
842
- display: "flex",
843
- flexDirection: "column",
844
- gap: 3,
845
- h3: {
846
- color: "palette.error.main"
847
- }
848
- }
849
- },
850
- ({ error }) => {
851
- return /* @__PURE__ */ jsxs(Box, { className: "panelError__wrapper", children: [
852
- /* @__PURE__ */ jsx(Heading, { as: "h3", children: "Oops! Something went wrong" }),
853
- /* @__PURE__ */ jsx(Heading, { as: "h4", children: "Error:" }),
854
- /* @__PURE__ */ jsx(Paragraph, { children: error })
855
- ] });
856
- }
857
- );
858
- class PanelErrorBoundary extends Component {
859
- constructor() {
860
- super(...arguments);
861
- __publicField$4(this, "state", {
862
- hasError: false,
863
- errorMessage: ""
864
- });
865
- }
866
- static getDerivedStateFromError(error) {
867
- if (!(error instanceof Promise))
868
- return { hasError: true, errorMessage: String(error) };
869
- }
870
- render() {
871
- if (this.state.hasError) {
872
- return /* @__PURE__ */ jsx(Error2, { error: this.state.errorMessage });
873
- }
874
- return this.props.children;
875
- }
876
- }
877
-
878
- var __defProp$3 = Object.defineProperty;
879
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
880
- var __publicField$3 = (obj, key, value) => {
881
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
882
- return value;
883
- };
884
- var __accessCheck$3 = (obj, member, msg) => {
885
- if (!member.has(obj))
886
- throw TypeError("Cannot " + msg);
887
- };
888
- var __privateGet$3 = (obj, member, getter) => {
889
- __accessCheck$3(obj, member, "read from private field");
890
- return getter ? getter.call(obj) : member.get(obj);
891
- };
892
- var __privateAdd$3 = (obj, member, value) => {
893
- if (member.has(obj))
894
- throw TypeError("Cannot add the same private member more than once");
895
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
896
- };
897
- var _elements, _loaders;
898
- const noData = { initialData: {} };
899
- function parameterValue(value) {
900
- if (value === "true")
901
- return true;
902
- if (value === "false")
903
- return false;
904
- return value;
905
- }
906
- class DashboardPanel extends EventEmitter {
907
- constructor({
908
- id,
909
- dashboard,
910
- PanelContainer: PanelContainer2
911
- }) {
912
- super();
913
- __publicField$3(this, "dashboard");
914
- __publicField$3(this, "hasInited", false);
915
- __publicField$3(this, "hasLoaded", false);
916
- __publicField$3(this, "id");
917
- __publicField$3(this, "initialData", null);
918
- __publicField$3(this, "isVisible", false);
919
- __publicField$3(this, "portal");
920
- __publicField$3(this, "props", {});
921
- __privateAdd$3(this, _elements, {
922
- props: () => {
923
- const panelData = document.querySelector(
924
- `panel-props[id="${this.id}"]`
925
- );
926
- if (!panelData) {
927
- console.error("Panel with no id:", this.id);
928
- throw new Error("A panel has no data element in the DOM.");
929
- }
930
- return panelData;
931
- }
932
- });
933
- __privateAdd$3(this, _loaders, {
934
- loadAll: () => {
935
- void __privateGet$3(this, _loaders).initialData();
936
- __privateGet$3(this, _loaders).parameters();
937
- __privateGet$3(this, _loaders).props();
938
- },
939
- initialData: () => {
940
- const panelContent = this.getContainer();
941
- const xml = panelContent.innerHTML.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
942
- panelContent.innerHTML = "";
943
- this.initialData = parseXmlAsync(xml.replace(/<!--?[^>]+>/, ""));
944
- return this.initialData;
945
- },
946
- parameters: () => {
947
- if (store.getState().panelParameters[this.id])
948
- return;
949
- const panelData = __privateGet$3(this, _elements).props();
950
- const options = Object.fromEntries(
951
- [...panelData.querySelectorAll("panel-option")].map(
952
- (current) => {
953
- return [
954
- current.getAttribute("name"),
955
- parameterValue(current.getAttribute("value"))
956
- ];
957
- }
958
- )
959
- );
960
- const parameters = Object.fromEntries(
961
- [...panelData.querySelectorAll("panel-parameter")].map(
962
- (current) => {
963
- return [
964
- current.getAttribute("name"),
965
- parameterValue(current.getAttribute("value"))
966
- ];
967
- }
968
- )
969
- );
970
- saveParameters(this.id, Object.assign(options, parameters), false);
971
- },
972
- props: () => {
973
- const panelData = __privateGet$3(this, _elements).props();
974
- const panel = this.getContainer();
975
- const props = {
976
- id: this.id,
977
- canMove: toBoolean(panelData.getAttribute("canMove")),
978
- hasRss: toBoolean(panelData.getAttribute("hasRss")),
979
- image: panelData.getAttribute("imagePath"),
980
- isConfigurable: toBoolean(panelData.getAttribute("isConfigurable")),
981
- isRefreshable: toBoolean(panelData.getAttribute("isRefreshable")),
982
- name: panelData.getAttribute("name"),
983
- refreshOnHome: toBoolean(panelData.getAttribute("refreshOnHome")),
984
- refreshOnStart: toBoolean(panelData.getAttribute("refreshOnStart")),
985
- showTitle: toBoolean(panelData.getAttribute("showTitle")),
986
- title: panelData.getAttribute("title"),
987
- type: panel.dataset.panel
988
- };
989
- this.props = props;
990
- }
991
- });
992
- __publicField$3(this, "fireAction", ({ action, ...parameters }, options) => {
993
- if (!this.isVisible)
994
- return new Promise((resolve) => resolve(null));
995
- const postData = {};
996
- Object.entries(parameters).forEach(([name, value]) => {
997
- postData[`p_${name}`] = value;
998
- });
999
- return new Promise((resolve, reject) => {
1000
- firePanelAction(this.id, action, postData, {
1001
- ...options,
1002
- onComplete(hasSucceed, data) {
1003
- options?.onComplete?.(hasSucceed, data);
1004
- if (hasSucceed) {
1005
- resolve(data);
1006
- } else
1007
- reject();
1008
- }
1009
- });
1010
- });
1011
- });
1012
- __publicField$3(this, "PanelElement", ({
1013
- ActualPanelContainer,
1014
- Element
1015
- }) => {
1016
- const [resolvedInitialData, setResolvedInitialData] = useState(null);
1017
- const [isVisible, setIsVisible] = useState(this.isVisible);
1018
- useMount(() => {
1019
- void this.initialData?.then((data) => {
1020
- setResolvedInitialData(data ?? noData);
1021
- });
1022
- return this.on(
1023
- "isVisible",
1024
- (ev) => setIsVisible((current) => ev || current)
1025
- );
1026
- });
1027
- if (resolvedInitialData === null || resolvedInitialData === noData)
1028
- return null;
1029
- return /* @__PURE__ */ jsx(DashboardPanelContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PanelIdentifier, { ...this.props, children: /* @__PURE__ */ jsx(
1030
- ActualPanelContainer,
1031
- {
1032
- ...this.props,
1033
- initialData: resolvedInitialData,
1034
- children: /* @__PURE__ */ jsx(
1035
- this.dashboard.bootstrapper.SuspendPanelUntilDashbordReady,
1036
- {
1037
- panelId: this.id,
1038
- children: /* @__PURE__ */ jsx(PanelErrorBoundary, { children: isVisible ? /* @__PURE__ */ jsx(Element, { initialData: resolvedInitialData }) : null })
1039
- }
1040
- )
1041
- }
1042
- ) }) });
1043
- });
1044
- this.dashboard = dashboard;
1045
- this.id = id;
1046
- __privateGet$3(this, _loaders).loadAll();
1047
- this.portal = createPortal(
1048
- /* @__PURE__ */ jsx(
1049
- this.PanelElement,
1050
- {
1051
- ActualPanelContainer: PanelContainer2,
1052
- Element: importPanel(this.props.type)
1053
- }
1054
- ),
1055
- this.getContainer(),
1056
- this.id
1057
- );
1058
- }
1059
- getContainer() {
1060
- const panel = document.querySelector(
1061
- `[data-id="${this.id}"][data-panel]`
1062
- );
1063
- if (!panel) {
1064
- console.error("Panel not found in dom:", this.id);
1065
- throw new Error("Panel not found in DOM.");
1066
- }
1067
- return panel;
1068
- }
1069
- getParameters() {
1070
- return store.getState().panelParameters[this.id];
1071
- }
1072
- hide() {
1073
- const container = this.getContainer();
1074
- container.style.display = "none";
1075
- container.ariaHidden = "true";
1076
- this.isVisible = false;
1077
- this.emit("isVisible", this.isVisible);
1078
- }
1079
- refresh() {
1080
- return this.fireAction({ action: "refresh" });
1081
- }
1082
- setHasLoaded() {
1083
- this.hasLoaded = true;
1084
- this.emit("hasLoaded", true);
1085
- }
1086
- show() {
1087
- const container = this.getContainer();
1088
- container.style.display = "block";
1089
- container.ariaHidden = "false";
1090
- this.hasInited = true;
1091
- this.isVisible = true;
1092
- this.emit("isVisible", this.isVisible);
1093
- }
1094
- }
1095
- _elements = new WeakMap();
1096
- _loaders = new WeakMap();
1097
-
1098
- function dragleave(_ev, DragAndDrop2) {
1099
- const ev = _ev;
1100
- if (ev.relatedTarget === null || isChild(ev.relatedTarget, (current) => {
1101
- return current.parentElement === null && current === document.getRootNode() && current.dataset.splash === void 0;
1102
- })) {
1103
- const shadows = document.querySelectorAll(".apia_panel_falseDiv");
1104
- shadows.forEach((el) => el.remove());
1105
- DragAndDrop2.draggingPanel?.setAttribute("style", "");
1106
- }
1107
- }
1108
-
1109
- const isCursorInArea = ({
1110
- top,
1111
- bottom,
1112
- left,
1113
- right,
1114
- cursorX,
1115
- cursorY
1116
- }) => {
1117
- return top <= cursorY && cursorY <= bottom && left <= cursorX && cursorX <= right;
1118
- };
1119
-
1120
- const getColumnAreas = (specificPanel) => {
1121
- return {
1122
- top: {
1123
- top: specificPanel.panelTop,
1124
- bottom: specificPanel.panelTop + specificPanel.panelHeight / 2,
1125
- left: specificPanel.panelLeft,
1126
- right: specificPanel.panelRight
1127
- },
1128
- bottom: {
1129
- top: specificPanel.panelBottom - specificPanel.panelHeight / 2,
1130
- bottom: specificPanel.panelBottom,
1131
- right: specificPanel.panelRight,
1132
- left: specificPanel.panelLeft
1133
- }
1134
- };
1135
- };
1136
-
1137
- function dragover(event, DragAndDrop2) {
1138
- const ev = event;
1139
- ev.preventDefault();
1140
- DragAndDrop2.timeout = -1;
1141
- if ((ev.clientX !== DragAndDrop2.dragoverPosition.x || ev.clientY !== DragAndDrop2.dragoverPosition.y) && DragAndDrop2.draggingPanelId !== "" && DragAndDrop2.shadowDiv) {
1142
- DragAndDrop2.clearTimeout();
1143
- DragAndDrop2.currentBottomPanel = DragAndDrop2.findBottomPanel(
1144
- ev.clientX,
1145
- ev.clientY + DragAndDrop2.currentScroll
1146
- );
1147
- DragAndDrop2.dragoverPosition.x = ev.clientX;
1148
- DragAndDrop2.dragoverPosition.y = ev.clientY;
1149
- const snapshotSection = DragAndDrop2.findBottomSection(
1150
- ev.clientX,
1151
- ev.clientY + DragAndDrop2.currentScroll
1152
- );
1153
- if (DragAndDrop2.shadowDivData && isCursorInArea({
1154
- cursorX: ev.clientX,
1155
- cursorY: ev.clientY + DragAndDrop2.currentScroll,
1156
- bottom: DragAndDrop2.shadowDivData?.panelBottom,
1157
- top: DragAndDrop2.shadowDivData?.panelTop,
1158
- left: DragAndDrop2.shadowDivData?.panelLeft,
1159
- right: DragAndDrop2.shadowDivData?.panelRight
1160
- })) {
1161
- return;
1162
- }
1163
- if (DragAndDrop2.currentBottomPanel && snapshotSection) {
1164
- const bottomPanel = DragAndDrop2.splash.querySelector(
1165
- `[data-panel][data-id='${DragAndDrop2.currentBottomPanel.id}']`
1166
- );
1167
- const draggingPanel = DragAndDrop2.splash.querySelector(
1168
- `[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
1169
- );
1170
- const bottomSection = DragAndDrop2.splash.querySelector(
1171
- `[data-locationid='${snapshotSection.sectionId}']`
1172
- );
1173
- if (bottomSection) {
1174
- if (isCursorInArea({
1175
- cursorX: ev.clientX,
1176
- cursorY: ev.clientY + DragAndDrop2.currentScroll,
1177
- ...getColumnAreas({
1178
- ...DragAndDrop2.currentBottomPanel,
1179
- panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,
1180
- panelRight: bottomSection?.getBoundingClientRect().right ?? 0
1181
- }).top
1182
- })) {
1183
- if (draggingPanel) {
1184
- draggingPanel.setAttribute("style", "display: none; height: 0;");
1185
- }
1186
- if (bottomPanel && snapshotSection) {
1187
- if (bottomSection) {
1188
- DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
1189
- DragAndDrop2.debounceBefore(
1190
- bottomPanel,
1191
- DragAndDrop2.shadowDiv,
1192
- bottomSection
1193
- );
1194
- DragAndDrop2.snapshot();
1195
- DragAndDrop2.clearTimeout();
1196
- }
1197
- }
1198
- } else if (isCursorInArea({
1199
- cursorX: ev.clientX,
1200
- cursorY: ev.clientY + DragAndDrop2.currentScroll,
1201
- ...getColumnAreas({
1202
- ...DragAndDrop2.currentBottomPanel,
1203
- panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,
1204
- panelRight: bottomSection?.getBoundingClientRect().right ?? 0
1205
- }).bottom
1206
- })) {
1207
- const bottomPanel2 = DragAndDrop2.splash.querySelector(
1208
- `[data-panel][data-id='${DragAndDrop2.currentBottomPanel.id}']`
1209
- );
1210
- const draggingPanel2 = DragAndDrop2.splash.querySelector(
1211
- `[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
1212
- );
1213
- if (draggingPanel2) {
1214
- draggingPanel2.setAttribute("style", "display: none;");
1215
- }
1216
- if (bottomPanel2 && snapshotSection) {
1217
- const bottomSection2 = DragAndDrop2.splash.querySelector(
1218
- `[data-locationid='${snapshotSection.sectionId}']`
1219
- );
1220
- if (bottomSection2) {
1221
- DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
1222
- DragAndDrop2.debounceAfter(DragAndDrop2.shadowDiv, bottomPanel2);
1223
- DragAndDrop2.snapshot();
1224
- DragAndDrop2.clearTimeout();
1225
- }
1226
- }
1227
- }
1228
- }
1229
- } else if (!DragAndDrop2.currentBottomPanel && snapshotSection) {
1230
- const bottomSection = DragAndDrop2.splash.querySelector(
1231
- `[data-locationid='${snapshotSection.sectionId}']`
1232
- );
1233
- if (bottomSection) {
1234
- const draggingPanel = DragAndDrop2.splash.querySelector(
1235
- `[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
1236
- );
1237
- if (draggingPanel) {
1238
- draggingPanel.setAttribute("style", "display: none;");
1239
- }
1240
- DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
1241
- DragAndDrop2.debounceAppend(
1242
- bottomSection,
1243
- DragAndDrop2.shadowDiv
1244
- );
1245
- DragAndDrop2.snapshot();
1246
- DragAndDrop2.clearTimeout();
1247
- }
1248
- }
1249
- }
1250
- }
1251
-
1252
- function dragstart(ev, el, DragAndDrop2) {
1253
- if (!(el instanceof HTMLElement))
1254
- return;
1255
- DragAndDrop2.drawMinimap();
1256
- DragAndDrop2.sectionData = [];
1257
- const targetPanel = getSpecificParent(
1258
- ev.target,
1259
- (current) => !!current.dataset?.id && !!current.dataset?.panel
1260
- );
1261
- ev?.dataTransfer?.setData("text", targetPanel?.dataset.id);
1262
- if (targetPanel) {
1263
- DragAndDrop2.placeholderImage = targetPanel.cloneNode(true);
1264
- DragAndDrop2.placeholderImage.style.position = "fixed";
1265
- DragAndDrop2.placeholderImage.style.top = "-10000000.45px";
1266
- const children = DragAndDrop2.placeholderImage.querySelectorAll("*");
1267
- children.forEach((current) => current.style.overflow = "hidden");
1268
- document.body.append(DragAndDrop2.placeholderImage);
1269
- ev?.dataTransfer?.setDragImage(DragAndDrop2.placeholderImage, 0, 0);
1270
- }
1271
- if (ev.dataTransfer) {
1272
- ev.dataTransfer.effectAllowed = "move";
1273
- }
1274
- setTimeout(() => {
1275
- const targetSection = getSpecificParent(
1276
- ev.target,
1277
- (current) => !!current.dataset?.locationid
1278
- );
1279
- const sections = DragAndDrop2.body?.querySelectorAll("[data-locationid]");
1280
- const emptySectionsId = [];
1281
- sections?.forEach((sec) => {
1282
- if (sec.children.length === 0) {
1283
- emptySectionsId.push(sec.dataset.locationid ?? "");
1284
- }
1285
- });
1286
- emptySectionsId.forEach((emptySecId) => {
1287
- const section = DragAndDrop2.body?.querySelector(
1288
- `[data-locationid="${emptySecId}"]`
1289
- );
1290
- if (section) {
1291
- section.setAttribute("style", "padding: 10px; border:2px dashed #ccc");
1292
- }
1293
- });
1294
- DragAndDrop2.snapshot();
1295
- if (targetPanel) {
1296
- DragAndDrop2.draggingPanelSectionId = targetSection?.dataset.locationid ?? "";
1297
- DragAndDrop2.draggingPanelId = targetPanel.dataset.id;
1298
- DragAndDrop2.draggingPanel = targetPanel;
1299
- }
1300
- if (DragAndDrop2.draggingPanelId === "") {
1301
- return;
1302
- }
1303
- const falseDiv = targetPanel?.cloneNode(true);
1304
- falseDiv.style.opacity = `50%`;
1305
- falseDiv.style.width = `100%`;
1306
- falseDiv.style.height = `auto`;
1307
- falseDiv.style.backgroundColor = `rgba(0,0,0,0.1)`;
1308
- falseDiv.className = "apia_panel_falseDiv";
1309
- DragAndDrop2.shadowDiv = falseDiv;
1310
- }, 0);
1311
- }
1312
-
1313
- function Drop(event, DragAndDrop2) {
1314
- if (DragAndDrop2.body) {
1315
- const ev = event;
1316
- const data = ev?.dataTransfer?.getData("text");
1317
- const sections = DragAndDrop2.body?.querySelectorAll("[data-locationid]");
1318
- sections.forEach((sec) => {
1319
- sec.setAttribute("style", "");
1320
- });
1321
- const draggingPanel = DragAndDrop2.body.querySelector(
1322
- `[data-panel][data-id="${DragAndDrop2.draggingPanelId}"]:not(.apia_panel_falseDiv)`
1323
- );
1324
- if (draggingPanel) {
1325
- draggingPanel.setAttribute("style", "");
1326
- }
1327
- const falseDiv = document.querySelector(".apia_panel_falseDiv");
1328
- if (data) {
1329
- const child = document.querySelector(
1330
- `[data-panel][data-id="${data}"]:not(.apia_panel_falseDiv)`
1331
- );
1332
- sections.forEach((sec) => {
1333
- if (sec.children.length === 1) {
1334
- sec.setAttribute("style", "");
1335
- }
1336
- });
1337
- if (falseDiv) {
1338
- const newSection = getSpecificParent(
1339
- falseDiv,
1340
- (current) => !!current.dataset.locationid
1341
- );
1342
- if (newSection) {
1343
- const panelsArray = Array.from(newSection.children);
1344
- const childId = child.dataset.id;
1345
- if (childId) {
1346
- const index = panelsArray.filter(
1347
- (panel) => !(panel.dataset.id === childId && !panel.classList.contains(
1348
- "apia_panel_falseDiv"
1349
- ))
1350
- ).findIndex(
1351
- (panel) => panel.dataset.id === childId && panel.classList.contains(
1352
- "apia_panel_falseDiv"
1353
- )
1354
- );
1355
- if (typeof index === "number" && newSection.dataset.locationid) {
1356
- void updatePanelPosition(
1357
- childId,
1358
- newSection.dataset.locationid,
1359
- index + 1
1360
- );
1361
- }
1362
- }
1363
- }
1364
- falseDiv.replaceWith(child);
1365
- }
1366
- }
1367
- DragAndDrop2.draggingPanelId = "";
1368
- DragAndDrop2.panelData = [];
1369
- DragAndDrop2.drawMinimap();
1370
- DragAndDrop2.removePlaceholder();
1371
- }
1372
- }
1373
-
1374
- var __defProp$2 = Object.defineProperty;
1375
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1376
- var __publicField$2 = (obj, key, value) => {
1377
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1378
- return value;
1379
- };
1380
- var __accessCheck$2 = (obj, member, msg) => {
1381
- if (!member.has(obj))
1382
- throw TypeError("Cannot " + msg);
1383
- };
1384
- var __privateGet$2 = (obj, member, getter) => {
1385
- __accessCheck$2(obj, member, "read from private field");
1386
- return getter ? getter.call(obj) : member.get(obj);
1387
- };
1388
- var __privateAdd$2 = (obj, member, value) => {
1389
- if (member.has(obj))
1390
- throw TypeError("Cannot add the same private member more than once");
1391
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1392
- };
1393
- var __privateSet$1 = (obj, member, value, setter) => {
1394
- __accessCheck$2(obj, member, "write to private field");
1395
- member.set(obj, value);
1396
- return value;
1397
- };
1398
- var _unsuscribers;
1399
- class DragAndDrop {
1400
- constructor() {
1401
- __privateAdd$2(this, _unsuscribers, []);
1402
- __publicField$2(this, "bootstrap", () => {
1403
- __privateGet$2(this, _unsuscribers).forEach((unsuscribe) => unsuscribe());
1404
- __privateSet$1(this, _unsuscribers, []);
1405
- this.body.addEventListener("dragover", this.dragOver);
1406
- this.body.addEventListener("drop", this.drop);
1407
- __privateGet$2(this, _unsuscribers).push(() => {
1408
- this.body.removeEventListener("dragover", this.dragOver);
1409
- this.body.removeEventListener("drop", this.drop);
1410
- });
1411
- if (this.splash) {
1412
- this.splash.addEventListener("dragleave", this.dragLeave);
1413
- this.splash.addEventListener("dragenter", this.dragEnter);
1414
- this.body.addEventListener("dragenter", this.dragEnter);
1415
- __privateGet$2(this, _unsuscribers).push(() => {
1416
- this.splash.removeEventListener("dragleave", this.dragLeave);
1417
- this.splash.removeEventListener("dragenter", this.dragEnter);
1418
- this.body.removeEventListener("dragenter", this.dragEnter);
1419
- });
1420
- }
1421
- this.panels.map((el) => {
1422
- const dragHandler = (ev) => {
1423
- if (ev.target.closest(".drag_panel_container")) {
1424
- this.dragStart(ev, el);
1425
- }
1426
- };
1427
- el.addEventListener("dragstart", dragHandler);
1428
- __privateGet$2(this, _unsuscribers).push(() => {
1429
- el.removeEventListener("dragstart", dragHandler);
1430
- });
1431
- return el;
1432
- });
1433
- });
1434
- __publicField$2(this, "panelData", []);
1435
- __publicField$2(this, "minimap", null);
1436
- __publicField$2(this, "timeout", -1);
1437
- __publicField$2(this, "sectionData", []);
1438
- __publicField$2(this, "body", document.querySelector("[data-layout]"));
1439
- __publicField$2(this, "splash", document.querySelector("[data-splash]"));
1440
- __publicField$2(this, "dragoverPosition", { x: 0, y: 0 });
1441
- __publicField$2(this, "shadowDivData", null);
1442
- __publicField$2(this, "shadowDiv", null);
1443
- __publicField$2(this, "placeholderImage", null);
1444
- __publicField$2(this, "panels", [
1445
- ...document.querySelectorAll("[data-panel][data-id]")
1446
- ]);
1447
- __publicField$2(this, "currentScroll", document.scrollingElement?.scrollTop ?? 0);
1448
- __publicField$2(this, "draggingPanel", null);
1449
- __publicField$2(this, "draggingPanelId", "");
1450
- __publicField$2(this, "draggingPanelSectionId", "");
1451
- __publicField$2(this, "currentBottomPanel");
1452
- __publicField$2(this, "updateMinimap", () => {
1453
- const frameElement = document.querySelector(".windowFrame");
1454
- if (frameElement) {
1455
- frameElement.style.top = `${(document.scrollingElement?.scrollTop ?? 0) * Number(frameElement.dataset.aspect)}px`;
1456
- }
1457
- });
1458
- __publicField$2(this, "removePlaceholder", () => {
1459
- this.clearTimeout();
1460
- const falseDivs = document.querySelectorAll(".apia_panel_falseDiv");
1461
- falseDivs.forEach((el) => {
1462
- el.remove();
1463
- });
1464
- this.placeholderImage?.remove();
1465
- this.placeholderImage = null;
1466
- });
1467
- __publicField$2(this, "clearTimeout", () => {
1468
- clearTimeout(this.timeout);
1469
- });
1470
- __publicField$2(this, "debounceAppend", (target, child) => {
1471
- if (!this.draggingPanelId)
1472
- return;
1473
- if (this.timeout === -1) {
1474
- target.appendChild(child);
1475
- }
1476
- clearTimeout(this.timeout);
1477
- this.timeout = setTimeout(() => {
1478
- target.appendChild(child);
1479
- }, 500);
1480
- });
1481
- __publicField$2(this, "debounceBefore", (reference, child, container) => {
1482
- if (!this.draggingPanelId)
1483
- return;
1484
- if (this.timeout === -1)
1485
- container.insertBefore(child, reference);
1486
- clearTimeout(this.timeout);
1487
- this.timeout = setTimeout(() => {
1488
- container.insertBefore(child, reference);
1489
- }, 500);
1490
- });
1491
- __publicField$2(this, "debounceAfter", (child, reference) => {
1492
- if (!this.draggingPanelId)
1493
- return;
1494
- if (this.timeout === -1)
1495
- reference.after(child);
1496
- clearTimeout(this.timeout);
1497
- this.timeout = setTimeout(() => {
1498
- reference.after(child);
1499
- }, 500);
1500
- });
1501
- __publicField$2(this, "dragOver", (event) => {
1502
- dragover(event, this);
1503
- this.updateMinimap();
1504
- });
1505
- __publicField$2(this, "dragStart", (ev, el) => {
1506
- dragstart(ev, el, this);
1507
- });
1508
- __publicField$2(this, "dragLeave", (_ev) => {
1509
- dragleave(_ev, this);
1510
- });
1511
- __publicField$2(this, "dragEnter", (_ev) => {
1512
- _ev.preventDefault();
1513
- });
1514
- __publicField$2(this, "drop", (event) => {
1515
- Drop(event, this);
1516
- });
1517
- __publicField$2(this, "snapshot", () => {
1518
- this.panelData = [];
1519
- const innerPanels = this.body.querySelectorAll(
1520
- "[data-panel][data-id]"
1521
- );
1522
- innerPanels.forEach((panel) => {
1523
- if (panel.classList.contains("apia_panel_falseDiv")) {
1524
- this.shadowDivData = {
1525
- id: panel.getAttribute("data-id") ?? "",
1526
- isShadow: true,
1527
- panelBottom: panel.getBoundingClientRect().bottom + this.currentScroll,
1528
- panelTop: panel.getBoundingClientRect().top + this.currentScroll,
1529
- panelRight: panel.getBoundingClientRect().right,
1530
- panelLeft: panel.getBoundingClientRect().left,
1531
- panelWidth: panel.getBoundingClientRect().width,
1532
- panelHeight: panel.getBoundingClientRect().height,
1533
- row: getSpecificParent(
1534
- panel,
1535
- (current) => !!current.dataset.locationid
1536
- )?.classList.contains("apia_section_row") ?? false,
1537
- sectionId: getSpecificParent(
1538
- panel,
1539
- (current) => !!current.dataset.locationid
1540
- )?.dataset.locationid ?? 0
1541
- };
1542
- }
1543
- if (this.panelData.every((innerPanel) => {
1544
- return innerPanel.id !== panel.getAttribute("data-id") && !panel.classList.contains("apia_panel_falseDiv");
1545
- })) {
1546
- this.panelData.push({
1547
- isShadow: panel.classList.contains("apia_panel_falseDiv"),
1548
- panelBottom: panel.getBoundingClientRect().bottom + this.currentScroll,
1549
- panelTop: panel.getBoundingClientRect().top + this.currentScroll,
1550
- panelRight: panel.getBoundingClientRect().right,
1551
- panelLeft: panel.getBoundingClientRect().left,
1552
- panelWidth: panel.getBoundingClientRect().width,
1553
- panelHeight: panel.getBoundingClientRect().height,
1554
- row: getSpecificParent(
1555
- panel,
1556
- (current) => !!current.dataset.locationid
1557
- )?.classList.contains("apia_section_row") ?? false,
1558
- sectionId: getSpecificParent(
1559
- panel,
1560
- (current) => !!current.dataset.locationid
1561
- )?.dataset.locationid ?? 0,
1562
- id: getSpecificParent(
1563
- panel,
1564
- (current) => !!current.dataset.id
1565
- )?.dataset.id ?? 0
1566
- });
1567
- }
1568
- });
1569
- this.sectionData = [];
1570
- const sections = this.body?.querySelectorAll("[data-locationid]");
1571
- sections?.forEach((sec) => {
1572
- if (this.sectionData.every(
1573
- (innerSection) => innerSection.sectionId !== sec.getAttribute("data-locationid")
1574
- )) {
1575
- this.sectionData.push({
1576
- sectionBottom: sec.getBoundingClientRect().bottom + this.currentScroll,
1577
- sectionLeft: sec.getBoundingClientRect().left,
1578
- sectionTop: sec.getBoundingClientRect().top + this.currentScroll,
1579
- sectionRight: sec.getBoundingClientRect().right,
1580
- sectionWidth: sec.getBoundingClientRect().width,
1581
- sectionHeight: sec.getBoundingClientRect().height,
1582
- sectionId: getSpecificParent(
1583
- sec,
1584
- (current) => !!current.dataset.locationid
1585
- )?.dataset.locationid ?? 0
1586
- });
1587
- }
1588
- });
1589
- this.drawMinimap();
1590
- });
1591
- __publicField$2(this, "findBottomPanel", (x, y) => {
1592
- const bottomPanel = this.panelData.find((panel) => {
1593
- return panel.panelBottom >= y && panel.panelTop <= y && panel.panelLeft <= x && panel.panelRight >= x;
1594
- });
1595
- return bottomPanel;
1596
- });
1597
- __publicField$2(this, "findBottomSection", (x, y) => {
1598
- const bottomSection = this.sectionData.find((sec) => {
1599
- return sec.sectionBottom >= y && sec.sectionTop <= y && sec.sectionLeft <= x && sec.sectionRight >= x;
1600
- });
1601
- return bottomSection;
1602
- });
1603
- }
1604
- drawMinimap() {
1605
- return;
1606
- }
1607
- }
1608
- _unsuscribers = new WeakMap();
1609
-
1610
- var __defProp$1 = Object.defineProperty;
1611
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1612
- var __publicField$1 = (obj, key, value) => {
1613
- __defNormalProp$1(obj, key + "" , value);
1614
- return value;
1615
- };
1616
- var __accessCheck$1 = (obj, member, msg) => {
1617
- if (!member.has(obj))
1618
- throw TypeError("Cannot " + msg);
1619
- };
1620
- var __privateGet$1 = (obj, member, getter) => {
1621
- __accessCheck$1(obj, member, "read from private field");
1622
- return getter ? getter.call(obj) : member.get(obj);
1623
- };
1624
- var __privateAdd$1 = (obj, member, value) => {
1625
- if (member.has(obj))
1626
- throw TypeError("Cannot add the same private member more than once");
1627
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1628
- };
1629
- var _matchLocation, _evalRoutes;
1630
- class Router extends EventEmitter {
1631
- constructor() {
1632
- super();
1633
- __privateAdd$1(this, _matchLocation, (regexp) => {
1634
- const path = "/" + (window.location.href.replaceAll("%20", " ").match(new RegExp(`${window.CONTEXT}/?([^?]+)?(?:\\?.*)?`))?.[1] ?? "");
1635
- return path.match(regexp);
1636
- });
1637
- __privateAdd$1(this, _evalRoutes, (routes) => {
1638
- for (let i = 0; i < routes.length; i++) {
1639
- const match = __privateGet$1(this, _matchLocation).call(this, routes[i].route);
1640
- if (match) {
1641
- return { route: routes[i], match };
1642
- }
1643
- }
1644
- });
1645
- /**
1646
- * Se evaluarán las rutas en orden y la primera en coincidir será tomada como
1647
- * resultado del cambio de ruta.
1648
- *
1649
- * Las rutas provistas deberán matchear contra el path actual. El path actual
1650
- * es la porción de la ruta luego del dominio y el contexto. Ejemplo:
1651
- *
1652
- * http://localhost/apia => path='/'
1653
- * http://localhost/apia/spa/categories/comidas/1 => path='/spa/categories/comidas/1'
1654
- */
1655
- __publicField$1(this, "useSwitch", (routes) => {
1656
- const lastMatch = useRef(null);
1657
- useMount(() => {
1658
- const result = __privateGet$1(this, _evalRoutes).call(this, routes);
1659
- if (result) {
1660
- result.route.callback(result.match);
1661
- }
1662
- return this.on("newRoute", () => {
1663
- const result2 = __privateGet$1(this, _evalRoutes).call(this, routes);
1664
- if (result2 && !shallowEqual(result2.match, lastMatch.current)) {
1665
- result2.route.callback(result2.match);
1666
- }
1667
- });
1668
- });
1669
- });
1670
- window.addEventListener("popstate", () => {
1671
- this.emit("newRoute", window.location.href);
1672
- });
1673
- }
1674
- }
1675
- _matchLocation = new WeakMap();
1676
- _evalRoutes = new WeakMap();
1677
-
1678
- var __defProp = Object.defineProperty;
1679
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1680
- var __publicField = (obj, key, value) => {
1681
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1682
- return value;
1683
- };
1684
- var __accessCheck = (obj, member, msg) => {
1685
- if (!member.has(obj))
1686
- throw TypeError("Cannot " + msg);
1687
- };
1688
- var __privateGet = (obj, member, getter) => {
1689
- __accessCheck(obj, member, "read from private field");
1690
- return getter ? getter.call(obj) : member.get(obj);
1691
- };
1692
- var __privateAdd = (obj, member, value) => {
1693
- if (member.has(obj))
1694
- throw TypeError("Cannot add the same private member more than once");
1695
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1696
- };
1697
- var __privateSet = (obj, member, value, setter) => {
1698
- __accessCheck(obj, member, "write to private field");
1699
- member.set(obj, value);
1700
- return value;
1701
- };
1702
- var _currentScene, _dragAndDrop, _PanelContainer, _panelsRenderedPortals, _loadPanels, _Context, _suscribeToEvents, _usePanelsList, _SceneRenderer;
1703
- class Dashboard extends EventEmitter {
1704
- constructor(panelsContainer = DefaultPanelWrapper, urlContext) {
1705
- super();
1706
- this.urlContext = urlContext;
1707
- __publicField(this, "bootstrapper", new DashboardPanelsBootstraper(this));
1708
- __publicField(this, "panels", null);
1709
- __publicField(this, "router", new Router());
1710
- __publicField(this, "scenes", {});
1711
- __privateAdd(this, _currentScene, "/");
1712
- __privateAdd(this, _dragAndDrop, new DragAndDrop());
1713
- __privateAdd(this, _PanelContainer, DefaultPanelWrapper);
1714
- __privateAdd(this, _panelsRenderedPortals, []);
1715
- __publicField(this, "getPanel", (id) => this.panels?.[id]);
1716
- __publicField(this, "getPanelByName", (name) => Object.values(this.panels ?? {}).find(
1717
- (current) => current.props.name === name
1718
- ));
1719
- __privateAdd(this, _loadPanels, () => {
1720
- this.panels = {};
1721
- const panelsElements = document.querySelectorAll(
1722
- "[data-panel]"
1723
- );
1724
- Array.from(panelsElements).forEach((current) => {
1725
- let container = __privateGet(this, _PanelContainer);
1726
- const customContainer = current.dataset.panelContainer;
1727
- if (customContainer) {
1728
- container = importContainer(current.dataset.panelContainer);
1729
- }
1730
- const panel = new DashboardPanel({
1731
- dashboard: this,
1732
- PanelContainer: container,
1733
- id: current.dataset.id
1734
- });
1735
- let panelPath = panel.getParameters().PAR_SPA_PATH || "*";
1736
- if (panelPath === "/")
1737
- panelPath = `/${this.urlContext}`;
1738
- if (panelPath !== "*")
1739
- panel.hide();
1740
- else
1741
- panel.show();
1742
- const paths = panelPath.split(",");
1743
- paths.forEach((currentPath) => {
1744
- if (!this.scenes[currentPath])
1745
- this.scenes[currentPath] = [];
1746
- this.scenes[currentPath].push(panel.props.id);
1747
- });
1748
- this.panels[panel.props.id] = panel;
1749
- __privateGet(this, _panelsRenderedPortals).push(panel.portal);
1750
- });
1751
- __privateGet(this, _dragAndDrop).bootstrap();
1752
- });
1753
- __privateAdd(this, _Context, ({ children }) => {
1754
- return /* @__PURE__ */ jsx(DashboardContext.Provider, { value: this, children });
1755
- });
1756
- __privateAdd(this, _suscribeToEvents, () => {
1757
- eventsController.onEvent({ eventType: "dashboard__focus" }, () => {
1758
- Object.values(this.panels ?? {}).forEach((current) => {
1759
- if (current.props.refreshOnHome) {
1760
- void current.refresh();
1761
- }
1762
- });
1763
- });
1764
- });
1765
- __privateAdd(this, _usePanelsList, () => {
1766
- const [panels, setPanels] = useState(null);
1767
- const deferredPanels = useDeferredValue(panels);
1768
- useMount(() => {
1769
- this.loadScene();
1770
- setPanels(__privateGet(this, _panelsRenderedPortals));
1771
- });
1772
- this.router.useSwitch([
1773
- {
1774
- route: new RegExp(`(?:/spa)?/(\\w+)`),
1775
- callback: (result) => {
1776
- this.loadScene(result[1]);
1777
- }
1778
- },
1779
- {
1780
- route: new RegExp(`/`),
1781
- callback: () => {
1782
- this.loadScene("/");
1783
- }
1784
- }
1785
- ]);
1786
- return deferredPanels;
1787
- });
1788
- __privateAdd(this, _SceneRenderer, () => {
1789
- const Context = __privateGet(this, _Context);
1790
- const panels = __privateGet(this, _usePanelsList).call(this);
1791
- return /* @__PURE__ */ jsx(Context, { children: panels });
1792
- });
1793
- __publicField(this, "loadScene", (scene = __privateGet(this, _currentScene)) => {
1794
- let actualScene = scene;
1795
- if (!actualScene.startsWith("/"))
1796
- actualScene = `/${actualScene}`;
1797
- if (!this.panels)
1798
- __privateGet(this, _loadPanels).call(this);
1799
- if (!this.scenes[actualScene])
1800
- this.scenes[actualScene] = [];
1801
- this.scenes[__privateGet(this, _currentScene)].forEach((scenePanelId) => {
1802
- if (!this.scenes[actualScene].includes(scenePanelId))
1803
- this.panels?.[scenePanelId]?.hide();
1804
- });
1805
- this.scenes[actualScene].forEach((scenePanelIds) => {
1806
- const panel = this.panels?.[scenePanelIds];
1807
- if (panel) {
1808
- panel.show();
1809
- if (panel.hasInited && panel.props.refreshOnStart)
1810
- void panel.refresh();
1811
- }
1812
- });
1813
- __privateSet(this, _currentScene, actualScene);
1814
- return __privateGet(this, _panelsRenderedPortals);
1815
- });
1816
- __publicField(this, "Component", () => {
1817
- const R = __privateGet(this, _SceneRenderer);
1818
- return /* @__PURE__ */ jsx(R, {});
1819
- });
1820
- __privateSet(this, _currentScene, `/`);
1821
- __privateSet(this, _PanelContainer, panelsContainer ?? __privateGet(this, _PanelContainer));
1822
- __privateGet(this, _suscribeToEvents).call(this);
1823
- }
1824
- }
1825
- _currentScene = new WeakMap();
1826
- _dragAndDrop = new WeakMap();
1827
- _PanelContainer = new WeakMap();
1828
- _panelsRenderedPortals = new WeakMap();
1829
- _loadPanels = new WeakMap();
1830
- _Context = new WeakMap();
1831
- _suscribeToEvents = new WeakMap();
1832
- _usePanelsList = new WeakMap();
1833
- _SceneRenderer = new WeakMap();
1834
-
1835
- function usePanelParametersSelector(selector, panelName) {
1836
- const { panelId } = usePanelIdentity();
1837
- const dashboard = useDashboardContext();
1838
- const id = panelName !== void 0 ? dashboard.getPanelByName(panelName)?.id ?? "" : panelId;
1839
- return useSelector((global) => {
1840
- const currentParams = global.panelParameters[id];
1841
- return selector(currentParams ?? {});
1842
- }, shallowEqual);
1843
- }
1844
-
1845
- const panelActionParameterName = "__panelTitleAction";
1846
- const panelImageParameterName = "__panelImageAction";
1847
- const panelDescriptionParameterName = "__panelTitleDescription";
1848
- function setPanelTitleAction(panelId, newAction) {
1849
- store.dispatch(
1850
- parametersActions.udpate({
1851
- panelId,
1852
- parameters: { [panelActionParameterName]: newAction }
1853
- })
1854
- );
1855
- }
1856
- function setPanelTitleDescritpion(panelId, newDescription) {
1857
- store.dispatch(
1858
- parametersActions.udpate({
1859
- panelId,
1860
- parameters: { [panelDescriptionParameterName]: newDescription }
1861
- })
1862
- );
1863
- }
1864
- function setPanelImageAction(panelId, newImage) {
1865
- store.dispatch(
1866
- parametersActions.udpate({
1867
- panelId,
1868
- parameters: { [panelImageParameterName]: newImage }
1869
- })
1870
- );
1871
- }
1872
- function usePanelTitleAction() {
1873
- return usePanelParametersSelector(
1874
- (current) => current[panelActionParameterName]
1875
- );
1876
- }
1877
- function usePanelImage() {
1878
- return usePanelParametersSelector(
1879
- (current) => current[panelImageParameterName]
1880
- );
1881
- }
1882
- function usePanelTitleDescription() {
1883
- return usePanelParametersSelector(
1884
- (current) => current[panelDescriptionParameterName]
1885
- );
1886
- }
1887
-
1888
- function firePanelAction(panelId, action, parameters, options) {
1889
- const postData = { p_action: action, ...parameters };
1890
- panelActionsEmitter.emit(panelId, `pre${ucfirst(action)}`, null);
1891
- void ApiaApi.post(
1892
- makeApiaUrl({
1893
- action: "panelAction",
1894
- pnlId: panelId
1895
- }),
1896
- { postData, postDataTreatement: "stringify", ...options?.requestConfig }
1897
- ).then((result) => {
1898
- if (result?.status !== 200) {
1899
- console.log("ERROR", panelId);
1900
- panelNetworkStateEmitter.emit("stateChange", {
1901
- panelId,
1902
- isConnected: false
1903
- });
1904
- } else {
1905
- panelNetworkStateEmitter.emit("stateChange", {
1906
- panelId,
1907
- isConnected: true
1908
- });
1909
- }
1910
- try {
1911
- if (result) {
1912
- startTransition(() => {
1913
- if (result?.data?.title) {
1914
- changePanelTitle(
1915
- { panelId },
1916
- result?.data?.title
1917
- );
1918
- }
1919
- if (result?.data?.footer) {
1920
- changePanelFooter(
1921
- panelId,
1922
- result?.data?.footer
1923
- );
1924
- }
1925
- if (result?.data?.titleAction) {
1926
- setPanelTitleAction(panelId, result?.data?.titleAction);
1927
- }
1928
- setPanelImageAction(panelId, result?.data?.image ?? "");
1929
- if (result?.data?.titleDescription) {
1930
- setPanelTitleDescritpion(
1931
- panelId,
1932
- result?.data?.titleDescription
1933
- );
1934
- }
1935
- options?.onComplete?.(true, result);
1936
- panelActionsEmitter.emit(panelId, action, result);
1937
- });
1938
- } else
1939
- options?.onComplete?.(false, null);
1940
- } catch (e) {
1941
- console.error(e);
1942
- }
1943
- }).catch((e) => {
1944
- console.error(e);
1945
- panelNetworkStateEmitter.emit("stateChange", {
1946
- panelId,
1947
- isConnected: false
1948
- });
1949
- options?.onComplete?.(false, null);
1950
- });
1951
- }
1952
-
1953
- function handleAction(panelIdentifier, event, action) {
1954
- if (event.type === "dblclick" && action.actionSource === "DOUBLE_CLICK" || (event.type === "click" || event.type === "mousedown") && action.actionSource === "CLICK" || event.type === "keydown" && event.code === "Enter") {
1955
- if (action?.action) {
1956
- switch (action.actionBehavior) {
1957
- case "CALL_AJAX_URL":
1958
- void ApiaApi.post(action.action, { handleLoad: true });
1959
- break;
1960
- case "DO_NOTHING":
1961
- break;
1962
- case "NAVIGATE_URL":
1963
- window.location.assign(action.action);
1964
- break;
1965
- case "OPEN_TAB":
1966
- window.top?.tabsController.openTabByUrl(
1967
- action.additionalData || action.text,
1968
- action.action
1969
- );
1970
- break;
1971
- case "RUN_ACTION":
1972
- firePanelAction(
1973
- panelIdentifier.panelId,
1974
- action.action,
1975
- {},
1976
- { requestConfig: { handleLoad: true } }
1977
- );
1978
- break;
1979
- case "FIRE_EVENT":
1980
- eventsController.fireEvent(
1981
- panelIdentifier,
1982
- action.action,
1983
- JSON.parse(action.additionalData)
1984
- );
1985
- break;
1986
- case "DOWNLOAD":
1987
- downloadUrl(action.action);
1988
- break;
1989
- default:
1990
- console.error("Unknown action behavior: ", action);
1991
- }
1992
- }
1993
- }
1994
- }
1995
-
1996
- const externalFirePanelAction = (panelId, { action, ...parameters }, options) => {
1997
- const postData = {};
1998
- Object.entries(parameters).forEach(([name, value]) => {
1999
- postData[`p_${name}`] = value;
2000
- });
2001
- firePanelAction(panelId, action, postData, options);
2002
- };
2003
-
2004
- function usePanelIsLoading() {
2005
- const [isLoading, setIsLoading] = useState(false);
2006
- usePanelActions({
2007
- preRefresh: () => setIsLoading(true),
2008
- refresh: () => setIsLoading(false)
2009
- });
2010
- return isLoading;
2011
- }
2012
-
2013
- const useActionEventHandlers = () => {
2014
- const identifier = usePanelIdentity();
2015
- const onClick = useCallback(
2016
- (ev) => {
2017
- return (action) => {
2018
- if (action.actionSource !== "CLICK")
2019
- return;
2020
- handleAction(identifier, ev, action);
2021
- };
2022
- },
2023
- [identifier]
2024
- );
2025
- const onDoubleClick = useCallback(
2026
- (ev) => {
2027
- return (action) => {
2028
- if (action.actionSource !== "DOUBLE_CLICK")
2029
- return;
2030
- handleAction(identifier, ev, action);
2031
- };
2032
- },
2033
- [identifier]
2034
- );
2035
- const onKeyDown = useCallback(
2036
- (ev) => {
2037
- return (action) => {
2038
- if (ev.code !== "Enter")
2039
- return;
2040
- handleAction(identifier, ev, action);
2041
- };
2042
- },
2043
- [identifier]
2044
- );
2045
- return { onClick, onDoubleClick, onKeyDown };
2046
- };
2047
-
2048
- const NetworkState = ({ title }) => {
2049
- const isConnected = usePanelNetworkState();
2050
- return /* @__PURE__ */ jsx(Fragment, { children: !isConnected && /* @__PURE__ */ jsx(
2051
- Icon,
2052
- {
2053
- tabIndex: 0,
2054
- title: getLabel("lblTestDBNoOk", {
2055
- text: {
2056
- TOK1: title
2057
- }
2058
- }).text,
2059
- "aria-label": getLabel("lblTestDBNoOk", {
2060
- text: {
2061
- TOK1: title
2062
- }
2063
- }).text,
2064
- name: "Alert"
2065
- }
2066
- ) });
2067
- };
2068
-
2069
- const LandingPagePanelWrapper = ({
2070
- children,
2071
- ...props
2072
- }) => {
2073
- const { panelId, panelName, panelType } = usePanelIdentity();
2074
- const { contextValue, title, ref, ...footerProps } = useMakePanelContext(props);
2075
- const panelTitleAction = usePanelTitleAction();
2076
- const panelTitleDescription = usePanelTitleDescription();
2077
- const dashboard = useDashboardContext();
2078
- if (dashboard.getPanel(panelId).props.hasRss)
2079
- console.log(dashboard.getPanel(panelId).props);
2080
- return /* @__PURE__ */ jsx(PanelContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
2081
- "div",
2082
- {
2083
- className: "panel__container",
2084
- "data-panelname": panelName,
2085
- "data-paneltype": panelType,
2086
- "data-panelid": panelId,
2087
- ref,
2088
- children: [
2089
- /* @__PURE__ */ jsx("div", { className: "panel__header", children: /* @__PURE__ */ jsxs("div", { className: "panel__header__left", children: [
2090
- props.showTitle && /* @__PURE__ */ jsx("span", { className: "panel__title", children: panelTitleAction ? /* @__PURE__ */ jsx(
2091
- "a",
2092
- {
2093
- title: panelTitleDescription,
2094
- className: "panel__title__link",
2095
- href: panelTitleAction,
2096
- children: title
2097
- }
2098
- ) : title }),
2099
- /* @__PURE__ */ jsx(NetworkState, { title })
2100
- ] }) }),
2101
- /* @__PURE__ */ jsx("div", { className: "panel__content", children }),
2102
- /* @__PURE__ */ jsx(PanelFooter, { isRefreshable: false, ...footerProps })
2103
- ]
2104
- }
2105
- ) });
2106
- };
2107
-
2108
- const EmptyPanelWrapper = (props) => {
2109
- const { contextValue } = useMakePanelContext(props);
2110
- return /* @__PURE__ */ jsx(PanelContextProvider, { value: contextValue, children: props.children });
2111
- };
2112
-
2113
- const reducers = {};
2114
- function initPanelTypeUpdater(panelType) {
2115
- if (!reducers[panelType]) {
2116
- reducers[panelType] = {
2117
- defaultReducer: (panelsState, payload) => {
2118
- Object.assign(panelsState, payload);
2119
- }
2120
- };
2121
- }
2122
- }
2123
- function registerReducers(panelType, newReducers) {
2124
- initPanelTypeUpdater(panelType);
2125
- Object.assign(reducers[panelType], newReducers);
2126
- }
2127
- function initPanelState(state, panelType, panelId, initialState) {
2128
- if (!state[panelType]) {
2129
- state[panelType] = {};
2130
- }
2131
- if (!state[panelType][panelId])
2132
- state[panelType][panelId] = {};
2133
- state[panelType][panelId] = initialState;
2134
- }
2135
- const panelsSlice = createSlice({
2136
- name: "panelsSlice",
2137
- initialState: {},
2138
- reducers: {
2139
- initState(state, {
2140
- payload: { panelId, panelType, initialState }
2141
- }) {
2142
- if (!state[panelType]?.[panelId]) {
2143
- initPanelState(state, panelType, panelId, initialState);
2144
- state[panelType][panelId] = initialState;
2145
- }
2146
- },
2147
- updatePanelStore(state, {
2148
- payload: { data, panelId, panelType, reducer, initialState }
2149
- }) {
2150
- if (!state[panelType]?.[panelId]) {
2151
- initPanelState(state, panelType, panelId, initialState ?? {});
2152
- }
2153
- const panelsStore2 = state[panelType][panelId];
2154
- initPanelTypeUpdater(panelType);
2155
- if (!reducers[panelType][reducer ?? "default"]) {
2156
- return;
2157
- }
2158
- const currentReducer = reducers[panelType][reducer ?? "default"];
2159
- currentReducer(panelsStore2, data);
2160
- }
2161
- }
2162
- });
2163
- const { useSelector: usePanelStoreSelector, store: panelsStore } = injectReducers({
2164
- panelsSlice: panelsSlice.reducer
2165
- });
2166
- const panelsActions = panelsSlice.actions;
2167
-
2168
- const undefinedObject = {};
2169
- function usePanelSelector(panelType, panelName, initialState, selector, comparator = shallowEqual$1) {
2170
- const { panelId } = usePanelIdentity();
2171
- if (!panelId)
2172
- throw new Error(`Cannot find panel with name ${panelName}`);
2173
- const storeState = panelsStore.getState().panelsSlice[panelType];
2174
- const [selection, setSelection] = useState(
2175
- initialState ? selector(storeState?.[panelId] ?? initialState) : {}
2176
- );
2177
- const previousSelected = useRef(
2178
- selection ?? undefinedObject
2179
- );
2180
- usePanelStoreSelector((global) => {
2181
- const newState = global.panelsSlice[panelType]?.[panelId];
2182
- if (newState !== void 0) {
2183
- const newSelected = selector(newState);
2184
- if (previousSelected.current === undefinedObject || !comparator(previousSelected.current, newSelected)) {
2185
- previousSelected.current = newSelected;
2186
- setSelection(newSelected);
2187
- }
2188
- }
2189
- });
2190
- return selection;
2191
- }
2192
-
2193
- function createPanelStore(panelType, initialState, reducers) {
2194
- const useSelector = (panelName, selector, comparator = shallowEqual$1) => {
2195
- const dashboard = useDashboardContext();
2196
- const props = useMemo(
2197
- () => dashboard.getPanelByName(panelName)?.props,
2198
- [dashboard, panelName]
2199
- );
2200
- const propsRef = useLatest(props);
2201
- useEffect(() => {
2202
- panelsStore.dispatch(
2203
- panelsActions.initState({
2204
- panelType,
2205
- panelId: propsRef.current.id,
2206
- initialState
2207
- })
2208
- );
2209
- }, []);
2210
- return usePanelSelector(
2211
- panelType,
2212
- panelName,
2213
- initialState,
2214
- selector,
2215
- comparator
2216
- );
2217
- };
2218
- registerReducers(panelType, reducers);
2219
- const usePanelDispatcher = () => {
2220
- const { panelName: contextPanelName } = usePanelIdentity();
2221
- const dispatchers = {};
2222
- const dashboard = useDashboardContext();
2223
- Object.entries(reducers).forEach(([name]) => {
2224
- dispatchers[name] = (payload, panelName) => {
2225
- const props = dashboard.getPanelByName(panelName ?? contextPanelName)?.props;
2226
- panelsStore.dispatch(
2227
- panelsActions.updatePanelStore({
2228
- panelId: props.id,
2229
- panelType,
2230
- data: { payload },
2231
- reducer: name
2232
- })
2233
- );
2234
- };
2235
- });
2236
- return dispatchers;
2237
- };
2238
- return [usePanelDispatcher, useSelector];
2239
- }
2240
-
2241
- export { Dashboard, EmptyPanelWrapper, LandingPagePanelWrapper, NetworkState, PanelButtons, PanelContextProvider, PanelFooter, PanelIdentifier, PanelIdentifierContext, changePanelTitle, createPanelStore, eventsController, externalFirePanelAction, handleAction, store as parametersStore, saveParameters, useActionEventHandlers, useDashboardContext, useDashboardPanel, useMakePanelContext, usePanelActions, usePanelChangeTitle, usePanelContext, usePanelFireEvent, usePanelIdentity, usePanelImage, usePanelIsLoading, usePanelNetworkState, usePanelOnEvent, usePanelParametersSelector, usePanelPosition, usePanelTitleDescription, useYieldPanelIsReady };
1
+ export { usePanelPosition } from './position/usePanelPosition.js';
2
+ export { LandingPagePanelWrapper } from './splash/panels/LandingPagePanelWrapper.js';
3
+ export { PanelIdentifier, PanelIdentifierContext } from './splash/panels/PanelIdentifier.js';
4
+ export { PanelContextProvider, useMakePanelContext, usePanelContext } from './splash/panels/PanelContext/index.js';
5
+ export { EmptyPanelWrapper } from './splash/panels/EmptyPanelWrapper/index.js';
6
+ export { useYieldPanelIsReady } from './splash/panels/PanelContext/useYieldPanelIsReady.js';
7
+ export { useActionEventHandlers } from './actions/useActionEventHandlers.js';
8
+ export { externalFirePanelAction } from './actions/externalFirePanelAction.js';
9
+ export { usePanelActions } from './actions/usePanelActions.js';
10
+ export { usePanelIsLoading } from './actions/usePanelIsLoading.js';
11
+ export { usePanelNetworkState } from './actions/usePanelNetworkState.js';
12
+ export { handleAction } from '@apia/util';
13
+ export { usePanelIdentity } from './common/usePanelIdentity.js';
14
+ export { usePanelParametersSelector } from './config/usePanelParametersSelector.js';
15
+ export { saveParameters } from './config/saveParameters.js';
16
+ export { parametersStore } from './config/parametersStore.js';
17
+ export { Dashboard } from './dashboard/dashboard.js';
18
+ export { useDashboardContext } from './dashboard/DashboardContext.js';
19
+ export { useDashboardPanel } from './dashboard/DashboardPanelContext.js';
20
+ export { usePanelFireEvent } from './eventsController/usePanelFireEvent.js';
21
+ export { usePanelOnEvent } from './eventsController/usePanelOnEvent.js';
22
+ export { eventsController } from './eventsController/eventsController.js';
23
+ export { changePanelTitle, usePanelChangeTitle } from './panelsUtil/usePanelChangeTitle.js';
24
+ export { createPanelStore } from './panelsStore/createPanelStore.js';
25
+ export { usePanelImage, usePanelTitleDescription } from './panelsUtil/usePanelTitleAction.js';
26
+ export { PanelButtons } from './splash/panels/DefaultPanelWrapper/PanelButtons.js';
27
+ export { PanelFooter } from './splash/panels/PanelContext/PanelFooter.js';
28
+ export { NetworkState } from './splash/panels/DefaultPanelWrapper/NetworkState.js';
2242
29
  //# sourceMappingURL=index.js.map