@apia/dashboard-controller 4.0.102 → 5.0.1

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