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