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