uni-manager 0.0.78 → 0.1.0

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.
@@ -0,0 +1,69 @@
1
+ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
2
+
3
+ class UniErrorManager {
4
+ /* ------------------------------------------------------------------------------- */
5
+ /* ------------------------------------ Store ------------------------------------ */
6
+ /* ------------------------------------------------------------------------------- */
7
+ /** Store privato (Subject) */
8
+ static { this.store = new BehaviorSubject(new Map()); }
9
+ /** Store pubblico (Observable) */
10
+ static { this.store$ = UniErrorManager.store.asObservable(); }
11
+ /** Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable */
12
+ static get currentValue() {
13
+ return UniErrorManager.store.getValue();
14
+ }
15
+ /* ------------------------------------------------------------------------------- */
16
+ /* -------------------------------- Metodi: store -------------------------------- */
17
+ /* ------------------------------------------------------------------------------- */
18
+ /**
19
+ * Aggiunge o aggiorna un errore nello store.
20
+ * Se l'errore esiste già (stesso ID), incrementa il contatore 'count'.
21
+ */
22
+ static add(id, error) {
23
+ // Recupera l'ultimo stato (Map)
24
+ const oldMap = UniErrorManager.currentValue;
25
+ // Tenta di recuperare l'oggetto corrente
26
+ const oldItem = oldMap.get(id);
27
+ // Crea il nuovo oggetto
28
+ const newItemMap = {
29
+ ...error,
30
+ count: oldItem ? oldItem.count + 1 : 1,
31
+ };
32
+ // Crea una nuova istanza della Map
33
+ const newMap = new Map(oldMap);
34
+ newMap.set(id, newItemMap);
35
+ // Aggiorna il nuovo stato notificando l'observer
36
+ UniErrorManager.store.next(newMap);
37
+ }
38
+ /**
39
+ * Rimuove un errore tramite ID
40
+ */
41
+ static remove(id) {
42
+ // Recupera l'ultimo stato (Map)
43
+ const oldMap = UniErrorManager.currentValue;
44
+ // Controllo: se non è presente l'item allora termina
45
+ if (!oldMap.has(id))
46
+ return;
47
+ // Crea una nuova istanza della Map
48
+ const newMap = new Map(oldMap);
49
+ newMap.delete(id);
50
+ // Aggiorna il nuovo stato notificando l'observer
51
+ UniErrorManager.store.next(newMap);
52
+ }
53
+ /**
54
+ * Svuota completamente la lista degli errori
55
+ */
56
+ static removeAll() {
57
+ // Crea una nuova istanza della Map
58
+ const newMap = new Map();
59
+ // Aggiorna il nuovo stato notificando l'observer
60
+ UniErrorManager.store.next(newMap);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Generated bundle index. Do not edit.
66
+ */
67
+
68
+ export { UniErrorManager };
69
+ //# sourceMappingURL=uni-manager-error.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uni-manager-error.mjs","sources":["../../../projects/uni-manager/error/manager.ts","../../../projects/uni-manager/error/uni-manager-error.ts"],"sourcesContent":["import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';\r\nimport { Observable } from 'rxjs/internal/Observable';\r\nimport type { IUniFeError } from 'uni-error/fe';\r\nimport type { IUniHttpError } from 'uni-error/http';\r\n\r\nexport class UniErrorManager {\r\n /* ------------------------------------------------------------------------------- */\r\n /* ------------------------------------ Store ------------------------------------ */\r\n /* ------------------------------------------------------------------------------- */\r\n /** Store privato (Subject) */\r\n private static store = new BehaviorSubject<Map<string, IUniFeError | IUniHttpError>>(new Map());\r\n\r\n /** Store pubblico (Observable) */\r\n public static store$: Observable<Map<string, IUniFeError | IUniHttpError>> =\r\n UniErrorManager.store.asObservable();\r\n\r\n /** Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable */\r\n public static get currentValue(): Map<string, IUniFeError | IUniHttpError> {\r\n return UniErrorManager.store.getValue();\r\n }\r\n\r\n /* ------------------------------------------------------------------------------- */\r\n /* -------------------------------- Metodi: store -------------------------------- */\r\n /* ------------------------------------------------------------------------------- */\r\n /**\r\n * Aggiunge o aggiorna un errore nello store.\r\n * Se l'errore esiste già (stesso ID), incrementa il contatore 'count'.\r\n */\r\n public static add(id: string, error: IUniHttpError | IUniFeError): void {\r\n // Recupera l'ultimo stato (Map)\r\n const oldMap = UniErrorManager.currentValue;\r\n\r\n // Tenta di recuperare l'oggetto corrente\r\n const oldItem = oldMap.get(id);\r\n\r\n // Crea il nuovo oggetto\r\n const newItemMap: IUniFeError | IUniHttpError = {\r\n ...error,\r\n count: oldItem ? oldItem.count + 1 : 1,\r\n };\r\n\r\n // Crea una nuova istanza della Map\r\n const newMap = new Map(oldMap);\r\n newMap.set(id, newItemMap);\r\n\r\n // Aggiorna il nuovo stato notificando l'observer\r\n UniErrorManager.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Rimuove un errore tramite ID\r\n */\r\n public static remove(id: string): void {\r\n // Recupera l'ultimo stato (Map)\r\n const oldMap = UniErrorManager.currentValue;\r\n\r\n // Controllo: se non è presente l'item allora termina\r\n if (!oldMap.has(id)) return;\r\n\r\n // Crea una nuova istanza della Map\r\n const newMap = new Map(oldMap);\r\n newMap.delete(id);\r\n\r\n // Aggiorna il nuovo stato notificando l'observer\r\n UniErrorManager.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Svuota completamente la lista degli errori\r\n */\r\n public static removeAll(): void {\r\n // Crea una nuova istanza della Map\r\n const newMap = new Map();\r\n\r\n // Aggiorna il nuovo stato notificando l'observer\r\n UniErrorManager.store.next(newMap);\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;MAKa,eAAe,CAAA;;;;;aAKX,IAAA,CAAA,KAAK,GAAG,IAAI,eAAe,CAA2C,IAAI,GAAG,EAAE,CAAC,CAAC;;AAGlF,IAAA,SAAA,IAAA,CAAA,MAAM,GAClB,eAAe,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;;AAGhC,IAAA,WAAW,YAAY,GAAA;AAC5B,QAAA,OAAO,eAAe,CAAC,KAAK,CAAC,QAAQ,EAAE;IACzC;;;;AAKA;;;AAGG;AACI,IAAA,OAAO,GAAG,CAAC,EAAU,EAAE,KAAkC,EAAA;;AAE9D,QAAA,MAAM,MAAM,GAAG,eAAe,CAAC,YAAY;;QAG3C,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;;AAG9B,QAAA,MAAM,UAAU,GAAgC;AAC9C,YAAA,GAAG,KAAK;AACR,YAAA,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC;SACvC;;AAGD,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC9B,QAAA,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC;;AAG1B,QAAA,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACpC;AAEA;;AAEG;IACI,OAAO,MAAM,CAAC,EAAU,EAAA;;AAE7B,QAAA,MAAM,MAAM,GAAG,eAAe,CAAC,YAAY;;AAG3C,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE;;AAGrB,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC9B,QAAA,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;;AAGjB,QAAA,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACpC;AAEA;;AAEG;AACI,IAAA,OAAO,SAAS,GAAA;;AAErB,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE;;AAGxB,QAAA,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACpC;;;AC5EF;;AAEG;;;;"}
@@ -0,0 +1,82 @@
1
+ class UniFileManager {
2
+ /**
3
+ * Apre un file (es. PDF, immagine) in una nuova scheda del browser
4
+ * Il contenuto viene caricato all'interno di un iframe per garantire compatibilità di visualizzazione
5
+ */
6
+ static openInNewTab(data) {
7
+ if (!data || !data.url)
8
+ return;
9
+ const newWindow = window.open('', '_blank');
10
+ if (!newWindow)
11
+ return;
12
+ newWindow.document.title = data.name;
13
+ // Crea l'iframe e lo aggiunge al body della nuova finestra
14
+ const iframe = this.createIframe(newWindow.document, data.url, '100%', '100%');
15
+ newWindow.document.body.style.margin = '0';
16
+ newWindow.document.body.append(iframe);
17
+ // Rimuove l'oggetto URL dalla memoria dopo un tempo congruo per il caricamento
18
+ setTimeout(() => URL.revokeObjectURL(data.url), 3000);
19
+ }
20
+ /**
21
+ * Stampa un file aprendo il dialogo di stampa nativo del sistema
22
+ * Utilizza un iframe invisibile per non interrompere la navigazione
23
+ */
24
+ static openInPrintPreview(data) {
25
+ if (!data || !data.url)
26
+ return;
27
+ // Crea l'iframe come elemento fisso e nascosto (dimensioni zero)
28
+ const iframe = this.createIframe(document, data.url, '0', '0');
29
+ iframe.style.position = 'fixed';
30
+ iframe.style.bottom = '0';
31
+ document.body.append(iframe);
32
+ // Attende il completamento del caricamento del file nell'iframe
33
+ iframe.addEventListener('load', () => {
34
+ // Attesa supplementare per consentire il rendering del PDF
35
+ setTimeout(() => {
36
+ iframe.contentWindow?.focus();
37
+ iframe.contentWindow?.print();
38
+ // Rimozione dell'iframe dal DOM e pulizia della memoria
39
+ setTimeout(() => {
40
+ iframe.remove();
41
+ URL.revokeObjectURL(data.url);
42
+ }, 1000);
43
+ }, 1000);
44
+ });
45
+ }
46
+ /**
47
+ * Scarica un file localmente sul dispositivo dell'utente
48
+ */
49
+ static download(data) {
50
+ if (!data || !data.url)
51
+ return;
52
+ const link = document.createElement('a');
53
+ link.href = data.url;
54
+ // Specifica il nome con cui il file verrà salvato
55
+ link.download = data.name;
56
+ // Opzionale: assicura che il link non sia visibile
57
+ link.style.display = 'none';
58
+ document.body.append(link);
59
+ link.click();
60
+ // Pulizia: rimuove l'elemento e revoca l'URL
61
+ setTimeout(() => {
62
+ link.remove();
63
+ URL.revokeObjectURL(data.url);
64
+ }, 100);
65
+ }
66
+ /* ----------------------------- Utils ----------------------------- */
67
+ static createIframe(doc, url, width, height) {
68
+ const iframe = doc.createElement('iframe');
69
+ iframe.src = url;
70
+ iframe.style.width = width;
71
+ iframe.style.height = height;
72
+ iframe.style.border = 'none';
73
+ return iframe;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Generated bundle index. Do not edit.
79
+ */
80
+
81
+ export { UniFileManager };
82
+ //# sourceMappingURL=uni-manager-file.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uni-manager-file.mjs","sources":["../../../projects/uni-manager/file/manager.ts","../../../projects/uni-manager/file/uni-manager-file.ts"],"sourcesContent":["import type { FileDatasource } from './model';\r\n\r\nexport class UniFileManager {\r\n /**\r\n * Apre un file (es. PDF, immagine) in una nuova scheda del browser\r\n * Il contenuto viene caricato all'interno di un iframe per garantire compatibilità di visualizzazione\r\n */\r\n public static openInNewTab(data: FileDatasource | undefined): void {\r\n if (!data || !data.url) return;\r\n\r\n const newWindow = window.open('', '_blank');\r\n if (!newWindow) return;\r\n\r\n newWindow.document.title = data.name;\r\n\r\n // Crea l'iframe e lo aggiunge al body della nuova finestra\r\n const iframe = this.createIframe(newWindow.document, data.url, '100%', '100%');\r\n newWindow.document.body.style.margin = '0';\r\n newWindow.document.body.append(iframe);\r\n\r\n // Rimuove l'oggetto URL dalla memoria dopo un tempo congruo per il caricamento\r\n setTimeout(() => URL.revokeObjectURL(data.url), 3000);\r\n }\r\n\r\n /**\r\n * Stampa un file aprendo il dialogo di stampa nativo del sistema\r\n * Utilizza un iframe invisibile per non interrompere la navigazione\r\n */\r\n public static openInPrintPreview(data: FileDatasource | undefined): void {\r\n if (!data || !data.url) return;\r\n\r\n // Crea l'iframe come elemento fisso e nascosto (dimensioni zero)\r\n const iframe = this.createIframe(document, data.url, '0', '0');\r\n iframe.style.position = 'fixed';\r\n iframe.style.bottom = '0';\r\n document.body.append(iframe);\r\n\r\n // Attende il completamento del caricamento del file nell'iframe\r\n iframe.addEventListener('load', (): void => {\r\n // Attesa supplementare per consentire il rendering del PDF\r\n setTimeout(() => {\r\n iframe.contentWindow?.focus();\r\n iframe.contentWindow?.print();\r\n\r\n // Rimozione dell'iframe dal DOM e pulizia della memoria\r\n setTimeout(() => {\r\n iframe.remove();\r\n URL.revokeObjectURL(data.url);\r\n }, 1000);\r\n }, 1000);\r\n });\r\n }\r\n\r\n /**\r\n * Scarica un file localmente sul dispositivo dell'utente\r\n */\r\n public static download(data: FileDatasource | undefined): void {\r\n if (!data || !data.url) return;\r\n\r\n const link = document.createElement('a');\r\n link.href = data.url;\r\n\r\n // Specifica il nome con cui il file verrà salvato\r\n link.download = data.name;\r\n\r\n // Opzionale: assicura che il link non sia visibile\r\n link.style.display = 'none';\r\n\r\n document.body.append(link);\r\n link.click();\r\n\r\n // Pulizia: rimuove l'elemento e revoca l'URL\r\n setTimeout(() => {\r\n link.remove();\r\n URL.revokeObjectURL(data.url);\r\n }, 100);\r\n }\r\n\r\n /* ----------------------------- Utils ----------------------------- */\r\n private static createIframe(\r\n doc: Document,\r\n url: string,\r\n width: string,\r\n height: string,\r\n ): HTMLIFrameElement {\r\n const iframe = doc.createElement('iframe');\r\n iframe.src = url;\r\n iframe.style.width = width;\r\n iframe.style.height = height;\r\n iframe.style.border = 'none';\r\n return iframe;\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"MAEa,cAAc,CAAA;AACzB;;;AAGG;IACI,OAAO,YAAY,CAAC,IAAgC,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE;QAExB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC;AAC3C,QAAA,IAAI,CAAC,SAAS;YAAE;QAEhB,SAAS,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI;;AAGpC,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC;QAC9E,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,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