@arsedizioni/ars-utils 22.5.1 → 22.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,358 @@
1
+ import { Observable } from 'rxjs';
2
+ import * as _angular_core from '@angular/core';
3
+
4
+ /**
5
+ * Content of a shell message.
6
+ *
7
+ * Deliberately a subset of `InfoDialogData`: the shell speaks before a route exists, so it
8
+ * says one thing and offers one way out. Anything richer belongs to `DialogService`.
9
+ */
10
+ interface ShellMessageData {
11
+ /** Heading shown above the message. */
12
+ title?: string;
13
+ /** HTML body of the message. */
14
+ message: string;
15
+ /** Optional technical detail (a log, a stack trace) shown in a secondary panel. */
16
+ details?: string;
17
+ /** Label of the dismiss button. */
18
+ okCaption?: string;
19
+ /** Auto-dismiss delay in milliseconds; the message stays until dismissed when omitted. */
20
+ dismissAfter?: number;
21
+ /** Maximum width of the panel in pixels. */
22
+ width?: number;
23
+ }
24
+ /**
25
+ * Handle over an open shell message.
26
+ *
27
+ * Not a `MatDialogRef` — there is no Material here — but the two members a caller actually
28
+ * uses of one are the same, and mean the same thing, so moving a call site between
29
+ * `DialogService` and `ShellService` does not change how its result is awaited.
30
+ */
31
+ interface ShellMessageRef {
32
+ /**
33
+ * Closes the message. Does nothing when it has already been closed.
34
+ * @returns void
35
+ */
36
+ close(): void;
37
+ /**
38
+ * Emits once and completes when the message has been taken off the screen, whichever way it
39
+ * was dismissed — the button, Escape, the backdrop, the auto-dismiss timer, or a `close()`.
40
+ *
41
+ * Like `MatDialogRef.afterClosed()`, and like it in the corner case too: subscribing after
42
+ * the message is already gone completes without emitting, so it is not a way to ask whether
43
+ * it was closed.
44
+ * @returns An observable of the dismissal.
45
+ */
46
+ afterClosed(): Observable<void>;
47
+ }
48
+
49
+ /** Visual style of the busy indicator. */
50
+ type ShellBusyType = 'bar' | 'spinner' | 'wait' | 'hourglass';
51
+ /** Progress mode of the bar and of the spinner. */
52
+ type ShellBusyMode = 'determinate' | 'indeterminate';
53
+ /**
54
+ * Overlay that blocks interaction while an operation is running, in the four styles the
55
+ * applications use: progress bar, spinner, hourglass and bare wait.
56
+ *
57
+ * Reproduces `mat-progress-bar` and `mat-progress-spinner` in CSS and SVG rather than importing
58
+ * them, because this overlay is shown from the boot path — an HTTP interceptor calls it before
59
+ * any route exists — and `ui.shell` exists precisely so that path costs no Material.
60
+ *
61
+ * The instance is created once by {@link ShellService} and then reused: showing and hiding is a
62
+ * class on the host, never a `createComponent`, so the 40-odd calls a screen costs nothing.
63
+ */
64
+ declare class ShellBusyComponent {
65
+ /** Whether the overlay is on screen. Hidden with `display: none`, so it costs no layout. */
66
+ readonly visible: _angular_core.WritableSignal<boolean>;
67
+ /** Visual style of the indicator. */
68
+ readonly type: _angular_core.WritableSignal<ShellBusyType>;
69
+ /** Current progress value (0-100), used when {@link progressMode} is `'determinate'`. */
70
+ readonly progress: _angular_core.WritableSignal<number>;
71
+ /** Progress mode of the bar and of the spinner. */
72
+ readonly progressMode: _angular_core.WritableSignal<ShellBusyMode>;
73
+ /** Message displayed above the indicator. */
74
+ readonly message: _angular_core.WritableSignal<string>;
75
+ /** Circumference of the spinner circle, bound to `stroke-dasharray`. */
76
+ protected readonly circumference: number;
77
+ /** Length of the spinner arc still to be drawn, derived from {@link progress}. */
78
+ protected readonly dashOffset: _angular_core.Signal<number>;
79
+ /**
80
+ * Updates the overlay state.
81
+ *
82
+ * Same contract as the `BusyDialogComponent` it replaces, down to the two implicit rules that
83
+ * callers rely on: an empty message keeps the previous text (so `wait()` does not wipe it), and
84
+ * a progress above zero forces `'determinate'` whatever the caller passed.
85
+ * @param message - New message to display. An empty string preserves the current one.
86
+ * @param progress - Current progress value (0-100). Above zero it forces determinate mode.
87
+ * @param progressMode - Progress mode to use. Defaults to `'indeterminate'`.
88
+ * @param type - Visual style to use. Defaults to `'bar'`.
89
+ * @returns void
90
+ */
91
+ set(message: string, progress: number, progressMode?: ShellBusyMode, type?: ShellBusyType): void;
92
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ShellBusyComponent, never>;
93
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<ShellBusyComponent, "ars-shell-busy", never, {}, {}, never, never, true, never>;
94
+ }
95
+
96
+ /**
97
+ * Everything the application can say to the user without asking anything back: a message, an
98
+ * error, and the wait overlay. No Angular Material behind any of it.
99
+ *
100
+ * `DialogService` extends this class, so a route component injects `DialogService` and has both
101
+ * halves; shell, HTTP interceptors, route guards and app initializers inject `ShellService` and
102
+ * pay for neither `mat-dialog` nor `cdk/overlay` on the boot path — measured at 445 KB of the
103
+ * 905 KB initial bundle on myARS, more than every route of the application put together.
104
+ *
105
+ * The methods keep the parameter order of the `DialogService` ones they came from, so no call
106
+ * site changed when they moved here.
107
+ *
108
+ * ## Stacking
109
+ *
110
+ * Outside the CDK overlay stack the order is a fixed z-index: the busy overlay sits at 1090 and
111
+ * the message at 1100, both above the `cdk-overlay-container` (1000). So an error raised while a
112
+ * Material dialog is open lands on top of it, which is what an error should do, and the busy
113
+ * overlay covers the dialog it belongs to. The one case a fixed number cannot express is a dialog
114
+ * opened while the overlay is still up — `DialogService.open()` takes the busy away immediately
115
+ * rather than with the grace period, precisely so that case cannot happen.
116
+ */
117
+ declare class ShellService {
118
+ private readonly appRef;
119
+ private readonly environmentInjector;
120
+ private messageRef?;
121
+ private messageKind?;
122
+ private messageClosed?;
123
+ private previousOverflow?;
124
+ private previouslyFocused?;
125
+ private busyRef?;
126
+ private busyVisible;
127
+ private busyActionSubscription?;
128
+ private clearBusyTimer?;
129
+ /**
130
+ * Shows an informational message.
131
+ * @param message - HTML message to display.
132
+ * @param title - Heading. Defaults to `'Informazioni'`.
133
+ * @param okCaption - Dismiss button label. Defaults to `'Ok'`.
134
+ * @param width - Maximum panel width in pixels. Defaults to `500`.
135
+ * @param dismissAfter - Auto-close delay in milliseconds (optional).
136
+ * @param details - Optional secondary details text.
137
+ * @returns A handle over the open message, or `null` outside the browser.
138
+ */
139
+ info(message: string, title?: string, okCaption?: string, width?: number, dismissAfter?: number, details?: string): ShellMessageRef | null;
140
+ /**
141
+ * Shows an error message. When one is already on screen its content is replaced in place: a
142
+ * failing API answers many requests at once, and each of them must not add a panel of its own.
143
+ * @param message - HTML error message to display.
144
+ * @param log - Optional technical log or stack trace shown in the details panel.
145
+ * @param title - Heading. Defaults to `'Errore'`.
146
+ * @param okCaption - Dismiss button label. Defaults to `'Ok'`.
147
+ * @param width - Maximum panel width in pixels. Defaults to `500`.
148
+ * @param dismissAfter - Auto-close delay in milliseconds (optional).
149
+ * @returns A handle over the open message, or `null` outside the browser.
150
+ */
151
+ error(message: string, log?: string, title?: string, okCaption?: string, width?: number, dismissAfter?: number): ShellMessageRef | null;
152
+ /**
153
+ * Closes the message currently on screen, if any. Does not touch the busy overlay.
154
+ * @returns void
155
+ */
156
+ closeMessage(): void;
157
+ /**
158
+ * Opens the message panel, or updates the one already open when it is showing the same kind of
159
+ * message.
160
+ * @param kind - Whether this is an informational or an error message.
161
+ * @param data - The content to display.
162
+ * @returns A handle over the open message, or `null` outside the browser.
163
+ */
164
+ private showMessage;
165
+ /**
166
+ * Builds the handle returned to callers.
167
+ *
168
+ * The subject is captured now rather than read at call time, so `afterClosed()` keeps
169
+ * answering about the message this handle was given for, even once another one has taken
170
+ * its place on screen.
171
+ * @returns The handle over the message currently on screen.
172
+ */
173
+ private messageHandle;
174
+ /**
175
+ * Shows or updates the busy overlay.
176
+ *
177
+ * Called dozens of times per screen, so it creates nothing after the first time: the component
178
+ * is built once and then kept, and showing it again is a class on the host element. The state
179
+ * is written to signals and checked synchronously before returning, so the message on screen is
180
+ * always the last one asked for — a second `busy()` in the same task never leaves the previous
181
+ * text behind.
182
+ * @param message - Text to display. An empty string keeps the current one.
183
+ * @param progress - Progress value (`-1` = indeterminate). Defaults to `-1`.
184
+ * @param progressMode - Progress mode. Defaults to `'indeterminate'`.
185
+ * @param type - Visual style of the overlay. Defaults to `'bar'`.
186
+ * @param action - Optional observable; the overlay is dismissed when it first emits. It
187
+ * replaces the one passed to a previous call, which is unsubscribed.
188
+ * @returns `true` if the overlay was brought up by this call, `false` if it was already up.
189
+ */
190
+ setBusy(message: string, progress?: number, progressMode?: ShellBusyMode, type?: ShellBusyType, action?: Observable<unknown>): boolean;
191
+ /**
192
+ * Shows or updates the busy overlay using the progress-bar style.
193
+ * @param message - Text to display inside the overlay.
194
+ * @param progress - Progress value (`-1` = indeterminate). Defaults to `-1`.
195
+ * @param progressMode - Progress mode. Defaults to `'indeterminate'`.
196
+ * @param action - Optional observable; the overlay is dismissed when it emits.
197
+ * @returns `true` if the overlay was brought up by this call.
198
+ */
199
+ busy(message: string, progress?: number, progressMode?: ShellBusyMode, action?: Observable<unknown>): boolean;
200
+ /**
201
+ * Shows or updates the busy overlay using the spinner style.
202
+ * @param message - Text to display inside the overlay.
203
+ * @param progress - Progress value (`-1` = indeterminate). Defaults to `-1`.
204
+ * @param progressMode - Progress mode. Defaults to `'indeterminate'`.
205
+ * @param action - Optional observable; the overlay is dismissed when it emits.
206
+ * @returns `true` if the overlay was brought up by this call.
207
+ */
208
+ busySpinner(message: string, progress?: number, progressMode?: ShellBusyMode, action?: Observable<unknown>): boolean;
209
+ /**
210
+ * Shows or updates the busy overlay using the hourglass style.
211
+ * @param message - Text to display inside the overlay.
212
+ * @param action - Optional observable; the overlay is dismissed when it emits.
213
+ * @returns `true` if the overlay was brought up by this call.
214
+ */
215
+ busyHourglass(message: string, action?: Observable<unknown>): boolean;
216
+ /**
217
+ * Shows a bare wait indicator, with no panel and no message.
218
+ * @param action - Optional observable; the overlay is dismissed when it emits.
219
+ * @returns `true` if the overlay was brought up by this call.
220
+ */
221
+ wait(action?: Observable<unknown>): boolean;
222
+ /**
223
+ * Returns a {@link BusyTimer} that brings the overlay up only if the operation is still running
224
+ * after a debounce delay.
225
+ * @param message - Text to display. Defaults to `'Operazione in corso...'`.
226
+ * @param due - Delay in milliseconds before the overlay appears. Defaults to `100`.
227
+ * @returns A timer that must be disposed with `clear()` when the operation ends.
228
+ */
229
+ busyTimer(message?: string, due?: number): BusyTimer;
230
+ /**
231
+ * Takes the busy overlay away.
232
+ *
233
+ * By default it waits a short grace period, so that a chain of quick operations does not make
234
+ * the overlay blink between one and the next; any `setBusy()` in the meantime cancels the
235
+ * pending removal. Pass `true` when something is about to be drawn underneath it and the wait
236
+ * would be visible — that is what `DialogService.open()` does.
237
+ * @param immediate - When `true`, removes the overlay without waiting for the grace period.
238
+ * @returns void
239
+ */
240
+ clearBusy(immediate?: boolean): void;
241
+ /**
242
+ * Hides the busy overlay without destroying it, so the next call can reuse the instance.
243
+ * @returns void
244
+ */
245
+ private hideBusy;
246
+ /**
247
+ * Returns the busy component, creating and attaching it the first time it is needed.
248
+ * @returns The reused busy component reference.
249
+ */
250
+ private ensureBusy;
251
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ShellService, never>;
252
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<ShellService>;
253
+ }
254
+
255
+ /**
256
+ * Shows the busy overlay only if the operation is still running after a debounce delay, so that
257
+ * an operation that answers in 30 ms never makes the screen flash.
258
+ *
259
+ * Whoever creates one owns it: {@link clear} must be called when the operation ends, otherwise
260
+ * the overlay appears after the fact and stays.
261
+ */
262
+ declare class BusyTimer {
263
+ private readonly shellService;
264
+ private readonly subscription;
265
+ /**
266
+ * Arms the timer.
267
+ * @param shellService - The service that owns the overlay. A `DialogService` is accepted too,
268
+ * since it extends `ShellService`.
269
+ * @param due - Delay in milliseconds before the overlay appears. Defaults to `100`.
270
+ * @param message - Text to display. Defaults to `'Operazione in corso...'`.
271
+ */
272
+ constructor(shellService: ShellService, due?: number, message?: string);
273
+ /**
274
+ * Disarms the timer and takes the overlay away.
275
+ * @returns void
276
+ */
277
+ clear(): void;
278
+ }
279
+
280
+ /**
281
+ * The shell's message panel: a modal that looks like a Material dialog and owes nothing to
282
+ * Material.
283
+ *
284
+ * It exists because shell, interceptors, guards and app initializers must be able to say
285
+ * "the session is gone" before a single route has been loaded, and paying for `mat-dialog`,
286
+ * `cdk/overlay` and the rest of that stack on the boot path costs the initial bundle more
287
+ * than every route of the application put together. The look is matched through CSS custom
288
+ * properties (`--ars-*` first, Material's `--mat-sys-*` next, a literal last), so an
289
+ * application that themes Material gets the same surface here for free.
290
+ *
291
+ * Instantiated imperatively by {@link ShellService}, never declared in a template: that is
292
+ * what lets an interceptor open it.
293
+ */
294
+ declare class ShellMessageComponent {
295
+ /** Emitted when the user dismisses the message, whichever way they did it. */
296
+ readonly closed: _angular_core.OutputEmitterRef<void>;
297
+ private readonly panel;
298
+ private readonly okButton;
299
+ /** Unique id tying the panel to its heading for assistive technology. */
300
+ protected readonly titleId: string;
301
+ /** Current content, with the defaults the shell relies on already applied. */
302
+ protected readonly data: _angular_core.WritableSignal<ShellMessageData>;
303
+ /** True for a moment after a successful copy, so the button can acknowledge it. */
304
+ protected readonly copied: _angular_core.WritableSignal<boolean>;
305
+ private dismissTimer?;
306
+ private copiedTimer?;
307
+ private closing;
308
+ constructor();
309
+ /**
310
+ * Replaces the content shown by the panel and restarts the auto-dismiss timer.
311
+ *
312
+ * Called on an already open panel by `ShellService.error()` so that a burst of failures
313
+ * updates one message instead of stacking modals nobody can dismiss.
314
+ * @param data - The new content to display.
315
+ * @returns void
316
+ */
317
+ setData(data: ShellMessageData): void;
318
+ /**
319
+ * Dismisses the panel. Safe to call more than once: only the first call is announced.
320
+ * @returns void
321
+ */
322
+ close(): void;
323
+ /**
324
+ * Closes the panel on Escape, mirroring a Material dialog opened with the default config.
325
+ * @param e - The keyboard event captured at document level.
326
+ * @returns void
327
+ */
328
+ protected onKeydown(e: KeyboardEvent): void;
329
+ /**
330
+ * Keeps Tab inside the panel while the message is up.
331
+ *
332
+ * A hand-rolled two-element version of what `cdk/a11y` does, which is all this panel needs:
333
+ * it never holds more than the copy button and the dismiss button.
334
+ * @param e - The Tab keydown event.
335
+ * @returns void
336
+ */
337
+ private trapFocus;
338
+ /**
339
+ * (Re)schedules the auto-dismiss timer, cancelling any pending one so a timer armed for an
340
+ * earlier message can never close a newer one.
341
+ * @param dismissAfter - Delay in milliseconds; no-op when falsy.
342
+ * @returns void
343
+ */
344
+ private scheduleDismiss;
345
+ /**
346
+ * Copies the message and its details to the clipboard, as both HTML and plain text.
347
+ *
348
+ * Unlike `InfoDialogComponent` there is no toast to report the outcome — the shell has no
349
+ * toast — so the button itself acknowledges it for a moment.
350
+ * @returns A promise that resolves once the copy has been attempted.
351
+ */
352
+ protected copy(): Promise<void>;
353
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ShellMessageComponent, never>;
354
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<ShellMessageComponent, "ars-shell-message", never, {}, { "closed": "closed"; }, never, never, true, never>;
355
+ }
356
+
357
+ export { BusyTimer, ShellBusyComponent, ShellMessageComponent, ShellService };
358
+ export type { ShellBusyMode, ShellBusyType, ShellMessageData, ShellMessageRef };