@uxland/primary-shell 8.3.4 → 8.3.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/README.md +18 -1
- package/dist/{component-Dv2Cw4dX.js → component-B4xPOzaR.js} +2 -2
- package/dist/{component-Dv2Cw4dX.js.map → component-B4xPOzaR.js.map} +1 -1
- package/dist/{index-CCC4rQo1.js → index-DsKLmCZe.js} +388 -388
- package/dist/index-DsKLmCZe.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/{plugin-D3sg1ev9.js → plugin-CRWxCmf1.js} +1058 -1055
- package/dist/plugin-CRWxCmf1.js.map +1 -0
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.d.ts +3 -2
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager.d.ts +6 -4
- package/package.json +6 -14
- package/dist/index-CCC4rQo1.js.map +0 -1
- package/dist/plugin-D3sg1ev9.js.map +0 -1
- package/src/UI/bootstrapper.ts +0 -14
- package/src/UI/components/bootstrapper.ts +0 -25
- package/src/UI/components/clinical-pathways-action-menu/clinical-pathways-action-menu.ts +0 -13
- package/src/UI/components/communication-action-menu/communication-action-menu.ts +0 -13
- package/src/UI/components/error-view/component.ts +0 -17
- package/src/UI/components/error-view/styles.css +0 -27
- package/src/UI/components/error-view/template.ts +0 -12
- package/src/UI/components/nav-divider/nav-divider.ts +0 -41
- package/src/UI/components/nav-divider/styles.css +0 -21
- package/src/UI/components/nav-divider/template.ts +0 -8
- package/src/UI/components/petitioner-action-menu/petitioner-action-menu.ts +0 -13
- package/src/UI/components/primaria-accordion/primaria-accordion.ts +0 -45
- package/src/UI/components/primaria-shell/constants.ts +0 -4
- package/src/UI/components/primaria-shell/primaria-shell.ts +0 -105
- package/src/UI/components/primaria-shell/shell-header/header-divider/header-divider.ts +0 -13
- package/src/UI/components/primaria-shell/shell-header/header-divider/styles.css +0 -5
- package/src/UI/components/primaria-shell/shell-header/header-divider/template.ts +0 -8
- package/src/UI/components/primaria-shell/shell-header/shell-header.ts +0 -71
- package/src/UI/components/primaria-shell/shell-header/styles.css +0 -45
- package/src/UI/components/primaria-shell/shell-header/template.ts +0 -37
- package/src/UI/components/primaria-shell/styles.css +0 -185
- package/src/UI/components/primaria-shell/template.ts +0 -72
- package/src/UI/components/sidenav-action-menu/sidenav-action-menu.ts +0 -62
- package/src/UI/components/sidenav-action-menu/styles.css +0 -25
- package/src/UI/components/sidenav-action-menu/template.ts +0 -24
- package/src/UI/fonts/fonts.css +0 -48
- package/src/UI/fonts/open-sans-v40-latin-300.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-500.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-600.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-700.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-800.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-regular.woff2 +0 -0
- package/src/UI/images/Gencat_Logotip.svg +0 -70
- package/src/UI/images/Salut_Logotip.svg +0 -8
- package/src/UI/index.ts +0 -1
- package/src/UI/internal-views/administrative-nav-menu.ts +0 -302
- package/src/UI/internal-views/common-nav-menu.ts +0 -94
- package/src/UI/internal-views/doctor-nav-menu.ts +0 -297
- package/src/UI/internal-views/doctor-quick-action-menu.ts +0 -16
- package/src/UI/internal-views/handle-views.ts +0 -24
- package/src/UI/shared-components/bootstrapper.ts +0 -18
- package/src/UI/shared-components/index.ts +0 -1
- package/src/UI/shared-components/primaria-character-limit-badge/primaria-character-limit-badge.ts +0 -27
- package/src/UI/shared-components/primaria-character-limit-badge/styles.css +0 -8
- package/src/UI/shared-components/primaria-content-switcher/primaria-content-switcher.ts +0 -78
- package/src/UI/shared-components/primaria-nav-item/primaria-nav-item.ts +0 -71
- package/src/UI/shared-components/primaria-nav-item/styles.css +0 -25
- package/src/UI/shared-components/primaria-nav-item/template.ts +0 -27
- package/src/UI/shared-components/primaria-nav-tree-menu/primaria-nav-tree-menu.ts +0 -41
- package/src/UI/shared-components/primaria-nav-tree-menu/styles.css +0 -11
- package/src/UI/shared-components/primaria-nav-tree-menu/template.ts +0 -46
- package/src/UI/shared-components/primaria-region/index.ts +0 -1
- package/src/UI/shared-components/primaria-region/primaria-region.ts +0 -199
- package/src/UI/shared-components/primaria-text-editor/primaria-rich-text-editor.ts +0 -261
- package/src/UI/shared-components/primaria-text-editor/styles.css +0 -966
- package/src/UI/shared-components/primaria-text-editor/template.ts +0 -8
- package/src/UI/shared-components/primaria-text-editor/utils.ts +0 -39
- package/src/UI/shared-components/quick-action-item/quick-action-item.ts +0 -21
- package/src/UI/shared-components/quick-action-item/template.ts +0 -8
- package/src/UI/shared-components/typings.ts +0 -19
- package/src/api/activity-monitor/activity-monitor.test.ts +0 -67
- package/src/api/activity-monitor/activity-monitor.ts +0 -26
- package/src/api/api.test.ts +0 -37
- package/src/api/api.ts +0 -119
- package/src/api/broker/broker-events.ts +0 -39
- package/src/api/broker/broker-requests.ts +0 -20
- package/src/api/broker/factory.test.ts +0 -378
- package/src/api/broker/factory.ts +0 -151
- package/src/api/broker/primaria-broker.ts +0 -20
- package/src/api/context-manager/context-manager.test.ts +0 -86
- package/src/api/context-manager/context-manager.ts +0 -42
- package/src/api/ecap-event-manager/ecap-event-manager.test.ts +0 -100
- package/src/api/ecap-event-manager/ecap-event-manager.ts +0 -58
- package/src/api/ecap-event-manager/typings.ts +0 -6
- package/src/api/exit-guard-manager/exit-guard-manager.test.ts +0 -75
- package/src/api/exit-guard-manager/exit-guard-manager.ts +0 -31
- package/src/api/global-state/global-state.test.ts +0 -45
- package/src/api/global-state/global-state.ts +0 -38
- package/src/api/http-client/http-client.test.ts +0 -196
- package/src/api/http-client/http-client.ts +0 -97
- package/src/api/import-data-manager/component/component.ts +0 -29
- package/src/api/import-data-manager/component/styles.css +0 -79
- package/src/api/import-data-manager/component/template.ts +0 -49
- package/src/api/import-data-manager/import-data-manager-impl.test.ts +0 -364
- package/src/api/import-data-manager/import-data-manager-impl.ts +0 -121
- package/src/api/import-data-manager/import-data-manager.ts +0 -42
- package/src/api/import-data-manager/index.ts +0 -2
- package/src/api/interaction-service/confirmation-message.tsx +0 -5
- package/src/api/interaction-service/index.ts +0 -1
- package/src/api/interaction-service/interaction-service-impl.tsx +0 -260
- package/src/api/interaction-service/interaction-service.ts +0 -52
- package/src/api/interaction-service/modal-styles.css +0 -97
- package/src/api/localization/localization.test.ts +0 -61
- package/src/api/localization/localization.ts +0 -58
- package/src/api/notification-service/notification-service-impl.test.ts +0 -84
- package/src/api/notification-service/notification-service.ts +0 -6
- package/src/api/notification-service/notification.service-impl.ts +0 -67
- package/src/api/pdf-viewer-manager/constants.ts +0 -1
- package/src/api/pdf-viewer-manager/events.ts +0 -5
- package/src/api/pdf-viewer-manager/handle-views.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.test.ts +0 -126
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.ts +0 -96
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/pdf-selector.ts +0 -39
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/styles.css +0 -45
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/template.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-visor.ts +0 -122
- package/src/api/pdf-viewer-manager/pdf-visor/styles.css +0 -29
- package/src/api/pdf-viewer-manager/pdf-visor/utils.ts +0 -16
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.test.ts +0 -61
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.ts +0 -45
- package/src/api/region-manager/region-manager.test.ts +0 -239
- package/src/api/region-manager/region-manager.ts +0 -263
- package/src/api/region-manager/regions.ts +0 -30
- package/src/api/region-manager/remove-view-idempotency.test.ts +0 -98
- package/src/api/session-refresh-timer/session-refresh-timer.test.ts +0 -102
- package/src/api/session-refresh-timer/session-refresh-timer.ts +0 -75
- package/src/api/token-manager/token-manager.test.ts +0 -146
- package/src/api/token-manager/token-manager.ts +0 -70
- package/src/api/user-manager/user-manager.ts +0 -79
- package/src/bootstrapper.ts +0 -41
- package/src/constants.ts +0 -1
- package/src/disposer.ts +0 -19
- package/src/features/bootstrapper.ts +0 -21
- package/src/features/exit/bootstrapper.ts +0 -17
- package/src/features/exit/handler.test.ts +0 -187
- package/src/features/exit/handler.ts +0 -58
- package/src/features/exit/request.ts +0 -10
- package/src/features/get-patient-cip/action.ts +0 -5
- package/src/features/get-user-info/backend-adapter.ts +0 -48
- package/src/features/get-user-info/bootstrapper.ts +0 -20
- package/src/features/get-user-info/handler.test.ts +0 -66
- package/src/features/get-user-info/handler.ts +0 -23
- package/src/features/get-user-info/model.ts +0 -10
- package/src/features/get-user-info/pds-token.ts +0 -28
- package/src/features/get-user-info/request.ts +0 -4
- package/src/features/get-visi-id/action.ts +0 -11
- package/src/features/navigate-to-ecap/navigate-to-ecap.ts +0 -21
- package/src/features/utils.ts +0 -27
- package/src/handle-plugins.ts +0 -82
- package/src/index.ts +0 -101
- package/src/infrastructure/ioc/container.ts +0 -14
- package/src/infrastructure/ioc/types.ts +0 -5
- package/src/locales.ts +0 -70
- package/src/types/custom.d.ts +0 -30
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./interaction-service";
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { ConfirmationOptions, ConfirmationResult, ConfirmComponentUI, PrimariaInteractionService } from "./interaction-service";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useEffect, useState, useRef } from "react";
|
|
4
|
-
import { createRoot } from "react-dom/client";
|
|
5
|
-
import { ConfirmationMessage } from "./confirmation-message.tsx";
|
|
6
|
-
import modalStyles from "./modal-styles.css?raw";
|
|
7
|
-
|
|
8
|
-
const defaultOptions: ConfirmationOptions = {
|
|
9
|
-
title: "Confirmació",
|
|
10
|
-
showConfirmButton: true,
|
|
11
|
-
showCancelButton: true,
|
|
12
|
-
confirmButtonText: "Acceptar",
|
|
13
|
-
cancelButtonText: "Cancel·lar",
|
|
14
|
-
showCloseButton: true,
|
|
15
|
-
fullCustomization: false,
|
|
16
|
-
closeOnOutsideClick: false,
|
|
17
|
-
hideIcon: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Un diàleg pot ser un component de React o un web component. Només el primer es pot renderitzar
|
|
22
|
-
* com a JSX, i cal un predicat de tipus perquè TypeScript ho estrenyi al punt d'ús: guardar el
|
|
23
|
-
* resultat en un booleà no li serveix.
|
|
24
|
-
*/
|
|
25
|
-
const isWebComponentConstructor = (component: unknown): component is new () => HTMLElement =>
|
|
26
|
-
typeof component === "function" && component.prototype instanceof HTMLElement;
|
|
27
|
-
|
|
28
|
-
export class PrimariaInteractionServiceImpl extends PrimariaInteractionService {
|
|
29
|
-
private readonly openDialogCancellers = new Set<() => void>();
|
|
30
|
-
|
|
31
|
-
confirm<TData = undefined, TResult = undefined>(
|
|
32
|
-
data: TData | undefined,
|
|
33
|
-
componentUI: ConfirmComponentUI<TData, TResult>,
|
|
34
|
-
options?: ConfirmationOptions | undefined,
|
|
35
|
-
): Promise<ConfirmationResult<TResult | undefined>> {
|
|
36
|
-
const finalOptions: ConfirmationOptions = { ...defaultOptions, ...(options || {}) };
|
|
37
|
-
const { openDialogCancellers } = this;
|
|
38
|
-
return new Promise((resolve) => {
|
|
39
|
-
let isClosing = false;
|
|
40
|
-
const div = document.createElement("div");
|
|
41
|
-
document.body.appendChild(div);
|
|
42
|
-
const wrapperHeadStyles = document.createElement("style");
|
|
43
|
-
wrapperHeadStyles.textContent = modalStyles;
|
|
44
|
-
document.head.appendChild(wrapperHeadStyles);
|
|
45
|
-
const DialogComponent = componentUI.component;
|
|
46
|
-
const DialogComponentStyles = componentUI.styles;
|
|
47
|
-
let componentHeadStyles;
|
|
48
|
-
if (DialogComponentStyles) {
|
|
49
|
-
componentHeadStyles = document.createElement("style");
|
|
50
|
-
componentHeadStyles.textContent = componentUI?.styles;
|
|
51
|
-
document.head.appendChild(componentHeadStyles);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const DialogWrapper = () => {
|
|
55
|
-
const [result, setResult] = useState<TResult>();
|
|
56
|
-
const [isValid, setIsValid] = useState(true);
|
|
57
|
-
const dialogComponentRef = useRef<HTMLDivElement>(null);
|
|
58
|
-
const dialogRef = useRef<HTMLDivElement>(null);
|
|
59
|
-
const modalRef = useRef<HTMLDivElement>(null);
|
|
60
|
-
|
|
61
|
-
const isWebComponent = isWebComponentConstructor(DialogComponent);
|
|
62
|
-
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
window.addEventListener("keydown", handleKeydown);
|
|
65
|
-
|
|
66
|
-
return () => window.removeEventListener("keydown", handleKeydown);
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
const cancelDialog = () => handleClose(false);
|
|
71
|
-
|
|
72
|
-
openDialogCancellers.add(cancelDialog);
|
|
73
|
-
|
|
74
|
-
return () => {
|
|
75
|
-
openDialogCancellers.delete(cancelDialog);
|
|
76
|
-
};
|
|
77
|
-
}, []);
|
|
78
|
-
|
|
79
|
-
const handleKeydown = (event: KeyboardEvent) => {
|
|
80
|
-
if (event.key === "Escape") {
|
|
81
|
-
handleClose(false);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const handleOutsideClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
85
|
-
if (dialogRef.current) {
|
|
86
|
-
if (event.target === modalRef.current && finalOptions.closeOnOutsideClick) {
|
|
87
|
-
handleClose(false);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// L'efecte només ha de crear el web component quan canvia el component o les dades.
|
|
93
|
-
// Afegir-hi els handlers i `isValid` el faria recrear a cada render, perdent l'estat.
|
|
94
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: recrear-lo perdria l'estat
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (isWebComponent && dialogComponentRef.current) {
|
|
97
|
-
const parent = dialogComponentRef.current;
|
|
98
|
-
|
|
99
|
-
// ⚠ Aquí creamos la instancia del Web Component manualmente
|
|
100
|
-
const wcElement = new (DialogComponent as any)();
|
|
101
|
-
|
|
102
|
-
// Asignar propiedades manualmente
|
|
103
|
-
(wcElement as any).data = data;
|
|
104
|
-
(wcElement as any).setResult = setResult;
|
|
105
|
-
(wcElement as any).setIsValid = setIsValid;
|
|
106
|
-
(wcElement as any).confirm = () => isValid && handleClose(true);
|
|
107
|
-
(wcElement as any).confirmResult = (result) => isValid && handleCloseWithResult(result);
|
|
108
|
-
(wcElement as any).cancel = () => handleClose(false);
|
|
109
|
-
|
|
110
|
-
// Agregar el Web Component al DOM
|
|
111
|
-
parent.appendChild(wcElement);
|
|
112
|
-
|
|
113
|
-
return () => {
|
|
114
|
-
parent.removeChild(wcElement);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}, [DialogComponent, data]);
|
|
118
|
-
|
|
119
|
-
const handleClose = (confirmed: boolean) => {
|
|
120
|
-
resolvePromise(result, confirmed);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const handleCloseWithResult = (finalResult: TResult) => {
|
|
124
|
-
resolvePromise(finalResult, true);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const resolvePromise = (finalResult: TResult | undefined, confirmed: boolean) => {
|
|
128
|
-
if (isClosing) return;
|
|
129
|
-
|
|
130
|
-
isClosing = true;
|
|
131
|
-
setTimeout(() => {
|
|
132
|
-
const confirmationResult = {
|
|
133
|
-
result: confirmed ? finalResult : undefined,
|
|
134
|
-
confirmed: confirmed,
|
|
135
|
-
};
|
|
136
|
-
resolve(confirmationResult);
|
|
137
|
-
root.unmount();
|
|
138
|
-
document.body.removeChild(div);
|
|
139
|
-
document.head.removeChild(wrapperHeadStyles);
|
|
140
|
-
if (DialogComponentStyles) document.head.removeChild(componentHeadStyles);
|
|
141
|
-
}, 300);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const getConfirmButtonVariant = () => {
|
|
145
|
-
if (finalOptions.state === "error") return "error";
|
|
146
|
-
if (finalOptions.state === "success") return "success";
|
|
147
|
-
if (finalOptions.state === "info") return "primary";
|
|
148
|
-
if (finalOptions.state === "alert") return "warning";
|
|
149
|
-
return "primary";
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const getCancelButtonVariant = () => {
|
|
153
|
-
return "secondary";
|
|
154
|
-
};
|
|
155
|
-
const getHeadIconVariantClass = () => {
|
|
156
|
-
if (finalOptions.state === "alert") return "warning";
|
|
157
|
-
if (finalOptions.state === "error") return "danger";
|
|
158
|
-
return "";
|
|
159
|
-
};
|
|
160
|
-
const getHeadIcon = () => {
|
|
161
|
-
if (finalOptions.state === "alert") return "error";
|
|
162
|
-
if (finalOptions.state === "error") return "warning";
|
|
163
|
-
return "";
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const _renderContent = () => {
|
|
167
|
-
return isWebComponentConstructor(DialogComponent) ? (
|
|
168
|
-
<div ref={dialogComponentRef} />
|
|
169
|
-
) : (
|
|
170
|
-
<DialogComponent
|
|
171
|
-
{...{
|
|
172
|
-
data,
|
|
173
|
-
setResult,
|
|
174
|
-
setIsValid,
|
|
175
|
-
confirm: () => isValid && handleClose(true),
|
|
176
|
-
confirmResult: (result: TResult) => isValid && handleCloseWithResult(result),
|
|
177
|
-
cancel: () => handleClose(false),
|
|
178
|
-
}}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
return (
|
|
183
|
-
<div className="modal" ref={modalRef} onClick={handleOutsideClick}>
|
|
184
|
-
<div className="dialog" ref={dialogRef}>
|
|
185
|
-
{!finalOptions.fullCustomization && (
|
|
186
|
-
<div className="dss-dialog-header">
|
|
187
|
-
<div className="dialog-header-wrapper">
|
|
188
|
-
<div className="dss-dialog-header-title">
|
|
189
|
-
{!finalOptions.hideIcon && (
|
|
190
|
-
<dss-icon
|
|
191
|
-
size="xl"
|
|
192
|
-
fill
|
|
193
|
-
class={`dss-dialog-header-state--${getHeadIconVariantClass()}`}
|
|
194
|
-
icon={getHeadIcon()}
|
|
195
|
-
/>
|
|
196
|
-
)}
|
|
197
|
-
{finalOptions.title}
|
|
198
|
-
</div>
|
|
199
|
-
</div>
|
|
200
|
-
{finalOptions.showCloseButton && (
|
|
201
|
-
<dss-icon-button
|
|
202
|
-
class="dss-dialog-header-close"
|
|
203
|
-
size="md"
|
|
204
|
-
variant="neutral"
|
|
205
|
-
icon="close"
|
|
206
|
-
onClick={() => handleClose(false)}
|
|
207
|
-
/>
|
|
208
|
-
)}
|
|
209
|
-
</div>
|
|
210
|
-
)}
|
|
211
|
-
<div className={`modal-content ${finalOptions.fullCustomization ? "full-customization" : ""}`}>
|
|
212
|
-
{_renderContent()}
|
|
213
|
-
</div>
|
|
214
|
-
{!finalOptions.fullCustomization && (
|
|
215
|
-
<div className="dss-modal-footer" hidden={!finalOptions.showCancelButton && !finalOptions.showConfirmButton}>
|
|
216
|
-
{finalOptions.showCancelButton && (
|
|
217
|
-
<dss-button
|
|
218
|
-
label={finalOptions.cancelButtonText}
|
|
219
|
-
onClick={() => handleClose(false)}
|
|
220
|
-
size="md"
|
|
221
|
-
variant={getCancelButtonVariant()}
|
|
222
|
-
icon={finalOptions.cancelButtonIcon}
|
|
223
|
-
/>
|
|
224
|
-
)}
|
|
225
|
-
{finalOptions.showConfirmButton && (
|
|
226
|
-
<dss-button
|
|
227
|
-
onClick={() => isValid && handleClose(true)}
|
|
228
|
-
label={finalOptions.confirmButtonText}
|
|
229
|
-
disabled={!isValid}
|
|
230
|
-
size="md"
|
|
231
|
-
variant={getConfirmButtonVariant()}
|
|
232
|
-
icon={finalOptions.confirmButtonIcon}
|
|
233
|
-
/>
|
|
234
|
-
)}
|
|
235
|
-
</div>
|
|
236
|
-
)}
|
|
237
|
-
</div>
|
|
238
|
-
</div>
|
|
239
|
-
);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const root = createRoot(div);
|
|
243
|
-
root.render(<DialogWrapper />);
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult> {
|
|
248
|
-
return this.confirm(message, { component: ConfirmationMessage }, options);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Tanca tots els diàlegs oberts, siguin del plugin que siguin. Host-only: no és al tipus
|
|
253
|
-
* `PrimariaInteractionService`, i els plugins reben una vista que no el porta.
|
|
254
|
-
*/
|
|
255
|
-
dispose(): void {
|
|
256
|
-
for (const cancelDialog of [...this.openDialogCancellers]) {
|
|
257
|
-
cancelDialog();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
export interface ConfirmationResult<T = undefined> {
|
|
4
|
-
confirmed: boolean;
|
|
5
|
-
result: T | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface ConfirmationContentProps<TData, TResult = undefined> {
|
|
9
|
-
data: TData | undefined;
|
|
10
|
-
setResult: (result: TResult) => void;
|
|
11
|
-
setIsValid: (isValid: boolean) => void;
|
|
12
|
-
confirm: () => void;
|
|
13
|
-
confirmResult: (result: TResult) => void;
|
|
14
|
-
cancel: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ConfirmationWithResultContentProps<TData, TResult = undefined> {
|
|
18
|
-
data: TData | undefined;
|
|
19
|
-
confirmResult: (result: TResult) => void;
|
|
20
|
-
cancel: () => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ConfirmationOptions {
|
|
24
|
-
title?: string | undefined;
|
|
25
|
-
showConfirmButton?: boolean | undefined;
|
|
26
|
-
showCancelButton?: boolean | undefined;
|
|
27
|
-
confirmButtonText?: string | undefined;
|
|
28
|
-
cancelButtonText?: string | undefined;
|
|
29
|
-
confirmButtonIcon?: string | undefined;
|
|
30
|
-
cancelButtonIcon?: string | undefined;
|
|
31
|
-
showCloseButton?: boolean | undefined;
|
|
32
|
-
fullCustomization?: boolean | undefined;
|
|
33
|
-
closeOnOutsideClick?: boolean | undefined;
|
|
34
|
-
state?: "success" | "info" | "alert" | "error";
|
|
35
|
-
hideIcon?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ConfirmComponentUI<TData = undefined, TResult = undefined> {
|
|
39
|
-
component:
|
|
40
|
-
| React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>>
|
|
41
|
-
| (new () => HTMLElement);
|
|
42
|
-
styles?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export abstract class PrimariaInteractionService {
|
|
46
|
-
abstract confirm<TData = undefined, TResult = undefined>(
|
|
47
|
-
data: TData | undefined,
|
|
48
|
-
componentUI: ConfirmComponentUI<TData, TResult>,
|
|
49
|
-
options?: ConfirmationOptions | undefined,
|
|
50
|
-
): Promise<ConfirmationResult<TResult | undefined>>;
|
|
51
|
-
abstract confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
|
|
52
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
.modal {
|
|
2
|
-
font-family: "Open Sans", sans-serif;
|
|
3
|
-
display: flex;
|
|
4
|
-
align-items: center;
|
|
5
|
-
justify-content: center;
|
|
6
|
-
position: fixed;
|
|
7
|
-
z-index: 998;
|
|
8
|
-
left: 0;
|
|
9
|
-
top: 0;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 100%;
|
|
12
|
-
background-color: rgba(0, 0, 0, 0.65);
|
|
13
|
-
}
|
|
14
|
-
.dialog {
|
|
15
|
-
display: flex;
|
|
16
|
-
flex-direction: column;
|
|
17
|
-
position: relative;
|
|
18
|
-
z-index: 401;
|
|
19
|
-
background: #fff;
|
|
20
|
-
border-radius: 16px;
|
|
21
|
-
width: auto;
|
|
22
|
-
height: auto;
|
|
23
|
-
max-height: 95%;
|
|
24
|
-
min-width: 400px;
|
|
25
|
-
box-shadow: 0 8px 12px 6px rgba(0 0 0 / 5%), 0 4px 4px rgba(0 0 0 / 10%);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.dialog-header-wrapper {
|
|
29
|
-
display: flex;
|
|
30
|
-
flex-direction: column;
|
|
31
|
-
align-items: center;
|
|
32
|
-
justify-content: center;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.dss-dialog-header {
|
|
36
|
-
position: relative;
|
|
37
|
-
display: flex;
|
|
38
|
-
flex-direction: row;
|
|
39
|
-
justify-content: center;
|
|
40
|
-
align-items: center;
|
|
41
|
-
padding: 24px;
|
|
42
|
-
border-top-left-radius: 16px;
|
|
43
|
-
border-top-right-radius: 16px;
|
|
44
|
-
}
|
|
45
|
-
.dss-dialog-header-title {
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-direction: column;
|
|
48
|
-
justify-content: center;
|
|
49
|
-
align-items: center;
|
|
50
|
-
gap: var(--dss-spacing-xs);
|
|
51
|
-
font-size: 20px;
|
|
52
|
-
line-height: 30px;
|
|
53
|
-
font-weight: var(--font-bold);
|
|
54
|
-
color: var(--color-neutral-900);
|
|
55
|
-
padding-left: var(--dss-spacing-xl);
|
|
56
|
-
padding-right: var(--dss-spacing-xl);
|
|
57
|
-
text-align: center;
|
|
58
|
-
}
|
|
59
|
-
.dss-dialog-header-close {
|
|
60
|
-
position: absolute;
|
|
61
|
-
top: var(--dss-spacing-lg);
|
|
62
|
-
right: calc(var(--dss-spacing-lg) - 4px);
|
|
63
|
-
}
|
|
64
|
-
.modal-content {
|
|
65
|
-
flex: 1;
|
|
66
|
-
padding: 0 24px;
|
|
67
|
-
overflow: visible;
|
|
68
|
-
position: relative;
|
|
69
|
-
}
|
|
70
|
-
.modal-content.full-customization {
|
|
71
|
-
padding: 0;
|
|
72
|
-
overflow: visible;
|
|
73
|
-
}
|
|
74
|
-
.dss-modal-footer {
|
|
75
|
-
display: flex;
|
|
76
|
-
justify-content: center;
|
|
77
|
-
align-items: center;
|
|
78
|
-
gap: 16px;
|
|
79
|
-
padding: 24px;
|
|
80
|
-
border-bottom-left-radius: 16px;
|
|
81
|
-
border-bottom-right-radius: 16px;
|
|
82
|
-
}
|
|
83
|
-
.dss-dialog-header-icon {
|
|
84
|
-
display: flex;
|
|
85
|
-
align-items: center;
|
|
86
|
-
justify-content: center;
|
|
87
|
-
margin-bottom: var(--dss-spacing-xs);
|
|
88
|
-
}
|
|
89
|
-
.dss-dialog-header-state {
|
|
90
|
-
display: flex;
|
|
91
|
-
}
|
|
92
|
-
.dss-dialog-header-state--warning {
|
|
93
|
-
color: var(--color-yellow-700);
|
|
94
|
-
}
|
|
95
|
-
.dss-dialog-header-state--danger {
|
|
96
|
-
color: var(--color-red-500);
|
|
97
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { createLocaleManager } from "./localization";
|
|
3
|
-
|
|
4
|
-
const pluginInfo = { pluginId: "testPlugin" };
|
|
5
|
-
|
|
6
|
-
// Mock data
|
|
7
|
-
const translations = {
|
|
8
|
-
en: { testPlugin: { hello: "Hello" } },
|
|
9
|
-
es: { testPlugin: { hello: "Hola" } },
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe("createLocaleManager", () => {
|
|
13
|
-
it("should return an object with translate, getTranslations, and getCurrentLanguage functions", async () => {
|
|
14
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations as any);
|
|
15
|
-
expect(localeManager).toHaveProperty("translate");
|
|
16
|
-
expect(localeManager).toHaveProperty("getTranslations");
|
|
17
|
-
expect(localeManager).toHaveProperty("getCurrentLanguage");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should translate a given path using localizer", async () => {
|
|
21
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations as any);
|
|
22
|
-
const result = localeManager.translate("hello");
|
|
23
|
-
expect(result).toBe("Hello");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should return the full path if no exist translation for given path", async () => {
|
|
27
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations as any);
|
|
28
|
-
const result = localeManager.translate("hellaaa");
|
|
29
|
-
expect(result).toBe("testPlugin.hellaaa");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return the path if there is an error translating", async () => {
|
|
33
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations as any);
|
|
34
|
-
const translateSpy = vi.spyOn(localeManager, "translate").mockImplementation(() => {
|
|
35
|
-
throw new Error("mocked error");
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
let result;
|
|
39
|
-
try {
|
|
40
|
-
result = localeManager.translate("hello");
|
|
41
|
-
} catch (error) {
|
|
42
|
-
result = "hello";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
expect(result).toBe("hello");
|
|
46
|
-
// Restore the original implementation
|
|
47
|
-
translateSpy.mockRestore();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should get translations for the current language", async () => {
|
|
51
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations);
|
|
52
|
-
const result = localeManager.getTranslations();
|
|
53
|
-
expect(result).toEqual(translations.en.testPlugin);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should get the current language", async () => {
|
|
57
|
-
const localeManager = await createLocaleManager(pluginInfo.pluginId)(translations);
|
|
58
|
-
const result = localeManager.getCurrentLanguage();
|
|
59
|
-
expect(result).toBe("en");
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { getLanguage, getLocales, localizerFactory, setLocales } from "@uxland/localization";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a locale manager for a given plugin ID and translations.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} pluginId - The ID of the plugin.
|
|
7
|
-
* @param {Record<string, Record<string, string>>} translations - The translations for the plugin.
|
|
8
|
-
* @return {Promise<{
|
|
9
|
-
* translate: (path: string, variables?: Record<string, string>) => string,
|
|
10
|
-
* getTranslations: () => Record<string, string>,
|
|
11
|
-
* getCurrentLanguage: () => string,
|
|
12
|
-
* }>} A promise that resolves to an object with methods for translating strings and getting translations.
|
|
13
|
-
*/
|
|
14
|
-
/** Arbre de traduccions: claus imbricades fins a arribar al text. */
|
|
15
|
-
export interface LocalizationMessages {
|
|
16
|
-
[key: string]: string | LocalizationMessages;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const createLocaleManager = (pluginId: string) => (translations: Record<string, LocalizationMessages>) => {
|
|
20
|
-
const localizer = localizerFactory(getLanguage(), translations, "", true);
|
|
21
|
-
setLocales(translations);
|
|
22
|
-
return Promise.resolve({
|
|
23
|
-
/**
|
|
24
|
-
* Translates the given path using the provided variables and the plugin's ID.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} path - The path to be translated.
|
|
27
|
-
* @param {Record<string, string>} [variables] - Optional variables to be used in the translation.
|
|
28
|
-
* @return {string} The translated string, or the original path if an error occurs.
|
|
29
|
-
*/
|
|
30
|
-
translate: (path: string, variables?: Record<string, string>) => {
|
|
31
|
-
try {
|
|
32
|
-
return localizer(`${pluginId}.${path}`, variables);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error(e);
|
|
35
|
-
return path;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves the translations for the current language and plugin.
|
|
40
|
-
*
|
|
41
|
-
* @return {Record<string, string>} The translations for the current language and plugin.
|
|
42
|
-
*/
|
|
43
|
-
getTranslations: () => {
|
|
44
|
-
const translations = getLocales();
|
|
45
|
-
const language = getLanguage();
|
|
46
|
-
return translations[language][pluginId] || {};
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Retrieves the current language.
|
|
51
|
-
*
|
|
52
|
-
* @return {string} The current language.
|
|
53
|
-
*/
|
|
54
|
-
getCurrentLanguage: () => {
|
|
55
|
-
return getLanguage();
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// @vitest-environment happy-dom
|
|
2
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
-
import { PrimariaNotificationServiceImpl } from "./notification.service-impl";
|
|
4
|
-
|
|
5
|
-
describe("PrimariaNotificationServiceImpl", () => {
|
|
6
|
-
let service: PrimariaNotificationServiceImpl;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
service = new PrimariaNotificationServiceImpl();
|
|
10
|
-
document.body.innerHTML = ""; // limpia el DOM antes de cada test
|
|
11
|
-
vi.useFakeTimers(); // usamos timers falsos para testear setTimeout
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
vi.clearAllTimers();
|
|
16
|
-
vi.useRealTimers();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const assertToast = (expectedState: string, message: string, duration = 5000) => {
|
|
20
|
-
const toast = document.querySelector("dss-toast") as HTMLElement;
|
|
21
|
-
expect(toast).not.toBeNull();
|
|
22
|
-
expect(toast.getAttribute("isshow")).toBe("true");
|
|
23
|
-
expect(toast.getAttribute("state")).toBe(expectedState);
|
|
24
|
-
expect(toast.getAttribute("position")).toBe("bottom-left");
|
|
25
|
-
expect(toast.getAttribute("text")).toBe(message);
|
|
26
|
-
expect(toast.getAttribute("hasicon")).toBe("true");
|
|
27
|
-
expect(toast.getAttribute("duration")).toBe(duration.toString());
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
it.each([
|
|
31
|
-
["info", "info"],
|
|
32
|
-
["warning", "warning"],
|
|
33
|
-
["error", "error"],
|
|
34
|
-
["success", "success"],
|
|
35
|
-
] as const)("should create a '%s' toast", (method, state) => {
|
|
36
|
-
const message = `Test ${state}`;
|
|
37
|
-
(service[method] as any)(message);
|
|
38
|
-
assertToast(state, message);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should create a container for toasts", () => {
|
|
42
|
-
service.info("Test");
|
|
43
|
-
const container = document.getElementById("primaria-toast-container");
|
|
44
|
-
expect(container).not.toBeNull();
|
|
45
|
-
expect(container?.style.position).toBe("fixed");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should remove the toast after the duration", () => {
|
|
49
|
-
service.info("Temporary toast", 2000);
|
|
50
|
-
|
|
51
|
-
let toast = document.querySelector("dss-toast") as HTMLElement;
|
|
52
|
-
expect(toast).not.toBeNull();
|
|
53
|
-
expect(toast.getAttribute("isshow")).toBe("true");
|
|
54
|
-
|
|
55
|
-
// Avanza el primer timeout (esconde el toast)
|
|
56
|
-
vi.advanceTimersByTime(2000);
|
|
57
|
-
expect(toast.getAttribute("isshow")).toBe("false");
|
|
58
|
-
|
|
59
|
-
// Avanza el segundo timeout (remueve del DOM)
|
|
60
|
-
vi.advanceTimersByTime(300);
|
|
61
|
-
toast = document.querySelector("dss-toast") as HTMLElement;
|
|
62
|
-
expect(toast).toBeNull();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should remove the container when all toasts are dismissed", () => {
|
|
66
|
-
service.info("Toast 1", 1000);
|
|
67
|
-
|
|
68
|
-
vi.advanceTimersByTime(1000);
|
|
69
|
-
vi.advanceTimersByTime(300);
|
|
70
|
-
|
|
71
|
-
const container = document.getElementById("primaria-toast-container");
|
|
72
|
-
expect(container).toBeNull();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("should stack multiple toasts in the same container", () => {
|
|
76
|
-
service.info("Toast 1");
|
|
77
|
-
service.warning("Toast 2");
|
|
78
|
-
service.error("Toast 3");
|
|
79
|
-
|
|
80
|
-
const container = document.getElementById("primaria-toast-container");
|
|
81
|
-
const toasts = container?.querySelectorAll("dss-toast");
|
|
82
|
-
expect(toasts?.length).toBe(3);
|
|
83
|
-
});
|
|
84
|
-
});
|