mn-angular-lib 2.0.60 → 2.0.62
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/fesm2022/mn-angular-lib-tour.mjs +775 -0
- package/fesm2022/mn-angular-lib-tour.mjs.map +1 -0
- package/fesm2022/mn-angular-lib.mjs +1 -0
- package/package.json +5 -1
- package/tour/src/mn-tour/mn-tour-overlay.css +199 -0
- package/types/mn-angular-lib-tour.d.ts +332 -0
- package/types/mn-angular-lib.d.ts +1 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { OnDestroy, Signal } from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* One stop of a tour.
|
|
5
|
+
*
|
|
6
|
+
* The library knows nothing about routing, modules or storage: the caller passes texts that are
|
|
7
|
+
* already translated, and uses {@link before} to get the page into the state the step needs
|
|
8
|
+
* (navigate, switch a tab, open a drawer).
|
|
9
|
+
*/
|
|
10
|
+
export type MnTourStep = {
|
|
11
|
+
/**
|
|
12
|
+
* Value of the `data-tour` attribute on the element to highlight (`'nav-book'` highlights
|
|
13
|
+
* `[data-tour="nav-book"]`). Omit it for a centred card with the page dimmed, such as a
|
|
14
|
+
* welcome or final card.
|
|
15
|
+
*/
|
|
16
|
+
target?: string;
|
|
17
|
+
/** Small line above the title (e.g. the tour name). */
|
|
18
|
+
kicker?: string;
|
|
19
|
+
/** The step's title. Also the card's accessible name. */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Short explanation. Also the card's accessible description. */
|
|
22
|
+
body: string;
|
|
23
|
+
/**
|
|
24
|
+
* Runs before the step is shown, after the previous step's {@link after}. Awaited, so it can
|
|
25
|
+
* navigate and return once the router has settled; the tour then still waits for the target
|
|
26
|
+
* to appear. A step with `before` is treated as a page change: the highlight fades out, jumps
|
|
27
|
+
* and fades back in instead of gliding. A `before` that throws skips the step.
|
|
28
|
+
*/
|
|
29
|
+
before?: () => void | Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Runs when the tour leaves this step, in either direction or because the tour ended (e.g. to
|
|
32
|
+
* close a drawer that {@link before} opened). Awaited; a throw is ignored.
|
|
33
|
+
*/
|
|
34
|
+
after?: () => void | Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
/** The "next tour" block on a tour's final card. */
|
|
37
|
+
export type MnTourNextTour = {
|
|
38
|
+
/** Heading of the block (e.g. "Volgende rondleiding"). */
|
|
39
|
+
kicker?: string;
|
|
40
|
+
/** Name of the next tour. */
|
|
41
|
+
title: string;
|
|
42
|
+
/** Secondary line, e.g. its length ("7 stappen"). */
|
|
43
|
+
meta?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A small text link on a tour's final card, e.g. to the module's help topic. Pressing it ends
|
|
47
|
+
* the tour as `completed` (with `startNext: false`) and then calls {@link run}.
|
|
48
|
+
*/
|
|
49
|
+
export type MnTourFinalLink = {
|
|
50
|
+
/** The link's text (e.g. "Meer over wedstrijden in de help"). */
|
|
51
|
+
label: string;
|
|
52
|
+
/** Called once the tour has ended, e.g. to navigate to the help topic. */
|
|
53
|
+
run: () => void | Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Every label the tour card renders. The library ships no strings of its own, so all of them
|
|
57
|
+
* come from the caller, already translated.
|
|
58
|
+
*/
|
|
59
|
+
export type MnTourLabels = {
|
|
60
|
+
/** The small text link at the top right that ends the tour (e.g. "Overslaan"). */
|
|
61
|
+
skip: string;
|
|
62
|
+
/** Back one step (e.g. "Vorige"). */
|
|
63
|
+
previous: string;
|
|
64
|
+
/** Forward one step (e.g. "Volgende"). */
|
|
65
|
+
next: string;
|
|
66
|
+
/** Primary button on the last step when there is no next tour (e.g. "Klaar"). */
|
|
67
|
+
done: string;
|
|
68
|
+
/** Secondary button on the last step when a next tour is offered (e.g. "Sluiten"). */
|
|
69
|
+
close: string;
|
|
70
|
+
/** Primary button on the last step when a next tour is offered (e.g. "Start volgende"). */
|
|
71
|
+
startNext: string;
|
|
72
|
+
/**
|
|
73
|
+
* Screen-reader text for the progress dots, given the 1-based position and the number of
|
|
74
|
+
* steps (e.g. `(n, total) => \`Stap ${n} van ${total}\``).
|
|
75
|
+
*/
|
|
76
|
+
stepLabel: (step: number, total: number) => string;
|
|
77
|
+
};
|
|
78
|
+
/** What a tour is started with. */
|
|
79
|
+
export type MnTourOptions = {
|
|
80
|
+
/** The stops, in order. */
|
|
81
|
+
steps: readonly MnTourStep[];
|
|
82
|
+
/** Every label the card renders. */
|
|
83
|
+
labels: MnTourLabels;
|
|
84
|
+
/** Optional block on the final card that offers the next tour. */
|
|
85
|
+
nextTour?: MnTourNextTour;
|
|
86
|
+
/** Optional text link on the final card, shown under the body (above a next-tour block). */
|
|
87
|
+
finalLink?: MnTourFinalLink;
|
|
88
|
+
/** Index of the first step to show (default 0), e.g. to resume a tour. */
|
|
89
|
+
startAt?: number;
|
|
90
|
+
/** How long a step waits for its target to appear before it is skipped (default 4000 ms). */
|
|
91
|
+
targetTimeoutMs?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Called when a step is skipped because its target never appeared or its `before` threw, so
|
|
94
|
+
* the app can log a stale marker.
|
|
95
|
+
*/
|
|
96
|
+
onStepMissing?: (index: number, step: MnTourStep, reason: 'target-not-found' | 'before-failed') => void;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* How a tour ended. `step` is the 0-based index (into `steps`) of the step that was on screen.
|
|
100
|
+
*
|
|
101
|
+
* - `completed`: the last step's primary or secondary button, or Volgende when every later step
|
|
102
|
+
* turned out missing (then `step` is the last step that was shown). `startNext` is true when
|
|
103
|
+
* the user chose the next tour from the final card.
|
|
104
|
+
* - `skipped`: the skip link, or Escape.
|
|
105
|
+
* - `closed`: ended from outside through `MnTourRef.close()` (e.g. the user navigated away), or
|
|
106
|
+
* by starting another tour or offer. `step` is -1 when no step had been shown yet, which also
|
|
107
|
+
* happens when every step of the tour was missing: the user saw nothing, so there is nothing
|
|
108
|
+
* to resume.
|
|
109
|
+
*/
|
|
110
|
+
export type MnTourOutcome = {
|
|
111
|
+
status: 'completed';
|
|
112
|
+
step: number;
|
|
113
|
+
startNext: boolean;
|
|
114
|
+
} | {
|
|
115
|
+
status: 'skipped';
|
|
116
|
+
step: number;
|
|
117
|
+
} | {
|
|
118
|
+
status: 'closed';
|
|
119
|
+
step: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Where an offer card appears: `centred` with the page dimmed (the general tour's welcome
|
|
123
|
+
* offer), or `corner`, bottom-right with the page left undimmed and usable (a module tour).
|
|
124
|
+
*/
|
|
125
|
+
export type MnTourOfferPlacement = 'centred' | 'corner';
|
|
126
|
+
/** What an offer card is opened with. */
|
|
127
|
+
export type MnTourOfferOptions = {
|
|
128
|
+
/** Where the card appears. */
|
|
129
|
+
placement: MnTourOfferPlacement;
|
|
130
|
+
/** Small line above the title. */
|
|
131
|
+
kicker?: string;
|
|
132
|
+
/** The offer's title (e.g. "Rondleiding: wedstrijden organiseren"). */
|
|
133
|
+
title: string;
|
|
134
|
+
/** Short explanation, e.g. the tour's length. */
|
|
135
|
+
body: string;
|
|
136
|
+
/** Button labels. */
|
|
137
|
+
labels: {
|
|
138
|
+
/** Declines the offer (e.g. "Niet nu"). */
|
|
139
|
+
dismiss: string;
|
|
140
|
+
/** Accepts it (e.g. "Rondleiding starten" / "Start"). */
|
|
141
|
+
accept: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* How an offer ended: `accepted` / `dismissed` by its buttons (Escape dismisses), or `closed`
|
|
146
|
+
* from outside through `MnTourOfferRef.close()` without an answer.
|
|
147
|
+
*/
|
|
148
|
+
export type MnTourOfferOutcome = {
|
|
149
|
+
status: 'accepted';
|
|
150
|
+
} | {
|
|
151
|
+
status: 'dismissed';
|
|
152
|
+
} | {
|
|
153
|
+
status: 'closed';
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* The library's motion timings (ms). Exported so an app's own motion and tests can line up
|
|
157
|
+
* with them. Under `prefers-reduced-motion` every one of them is skipped.
|
|
158
|
+
*/
|
|
159
|
+
export declare const MN_TOUR_MOTION: {
|
|
160
|
+
/** The highlight and the card glide between two stops on the same page. */
|
|
161
|
+
readonly glideMs: 450;
|
|
162
|
+
/** The highlight and the dim fade in after a page, tab or drawer change (ease-out). */
|
|
163
|
+
readonly fadeInMs: 450;
|
|
164
|
+
/** The highlight and the dim fade out before a page change, and at the end. */
|
|
165
|
+
readonly fadeOutMs: 200;
|
|
166
|
+
/** The card's content fades out, and the new content in, over this each. */
|
|
167
|
+
readonly contentFadeMs: 120;
|
|
168
|
+
};
|
|
169
|
+
/** A running tour, as returned by {@link MnTourService.start}. */
|
|
170
|
+
export declare class MnTourRef {
|
|
171
|
+
readonly result: Promise<MnTourOutcome>;
|
|
172
|
+
readonly step: Signal<number>;
|
|
173
|
+
private readonly closeFn;
|
|
174
|
+
/**
|
|
175
|
+
* @param result Settles once, with how the tour ended.
|
|
176
|
+
* @param step The 0-based index of the step on screen (-1 before the first one shows). Read it
|
|
177
|
+
* synchronously to persist "the last step reached" when the page unloads mid-tour.
|
|
178
|
+
* @param closeFn Ends the tour from outside.
|
|
179
|
+
*/
|
|
180
|
+
constructor(result: Promise<MnTourOutcome>, step: Signal<number>, closeFn: () => void);
|
|
181
|
+
/** Ends the tour without an answer from the user (outcome `closed`). Idempotent. */
|
|
182
|
+
close(): void;
|
|
183
|
+
}
|
|
184
|
+
/** An open offer card, as returned by {@link MnTourService.offer}. */
|
|
185
|
+
export declare class MnTourOfferRef {
|
|
186
|
+
readonly result: Promise<MnTourOfferOutcome>;
|
|
187
|
+
private readonly closeFn;
|
|
188
|
+
/**
|
|
189
|
+
* @param result Settles once, with the user's answer.
|
|
190
|
+
* @param closeFn Removes the card without an answer.
|
|
191
|
+
*/
|
|
192
|
+
constructor(result: Promise<MnTourOfferOutcome>, closeFn: () => void);
|
|
193
|
+
/** Removes the card without an answer (outcome `closed`). Idempotent. */
|
|
194
|
+
close(): void;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Runs guided tours: a highlight around `[data-tour="…"]` elements and a card that walks the user
|
|
198
|
+
* through them, plus the offer card that proposes a tour.
|
|
199
|
+
*
|
|
200
|
+
* The service knows nothing about routing, modules or storage. The caller passes translated
|
|
201
|
+
* texts, moves the app between steps with each step's `before()`, and persists what the returned
|
|
202
|
+
* outcome reports. One tour or offer is on screen at a time; starting another closes the current
|
|
203
|
+
* one. Starting a tour straight from an accepted offer (or from a final card's "Start volgende")
|
|
204
|
+
* reuses the card already on screen instead of removing and re-adding it.
|
|
205
|
+
*
|
|
206
|
+
* Motion (D10): between two targets on the same page the highlight and the card glide (450 ms).
|
|
207
|
+
* A step with `before()`, a step after a centred card and a step after a missing one fade the
|
|
208
|
+
* highlight out (200 ms), jump, and fade in (450 ms, ease-out). The card's content crossfades
|
|
209
|
+
* (120 ms out, 120 ms in). Under `prefers-reduced-motion` there is no glide and no fade.
|
|
210
|
+
*
|
|
211
|
+
* Keyboard: Escape skips (on an offer: declines), ArrowRight and Enter go forward, ArrowLeft goes
|
|
212
|
+
* back. Focus moves into the card and returns where it was when the tour ends. The corner offer
|
|
213
|
+
* is the exception: it does not take focus, because it appears unasked on a page the user is
|
|
214
|
+
* working on; it is still reachable with Tab, and Escape works once focus is inside it.
|
|
215
|
+
*/
|
|
216
|
+
export declare class MnTourService implements OnDestroy {
|
|
217
|
+
private readonly appRef;
|
|
218
|
+
private readonly injector;
|
|
219
|
+
/** The mounted overlay, or null. */
|
|
220
|
+
private overlayRef;
|
|
221
|
+
/** The tour or offer on screen, or null. */
|
|
222
|
+
private session;
|
|
223
|
+
/** Pending fade-out or removal of the overlay. */
|
|
224
|
+
private teardownTimer;
|
|
225
|
+
/** Where focus was before the overlay appeared, restored when it goes. */
|
|
226
|
+
private returnFocus;
|
|
227
|
+
/** Undoes the listeners that keep the highlight on its target. */
|
|
228
|
+
private stopTrackingFn;
|
|
229
|
+
/** Document keydown listener, registered only while the overlay exists. */
|
|
230
|
+
private readonly onKeyDown;
|
|
231
|
+
/** Window resize listener, registered only while the overlay exists. */
|
|
232
|
+
private readonly onResize;
|
|
233
|
+
/**
|
|
234
|
+
* Starts a tour. A tour or offer already on screen is closed first (its outcome `closed`).
|
|
235
|
+
* @param options The steps, labels and optional next-tour block.
|
|
236
|
+
* @returns A ref whose `result` settles with how the tour ended.
|
|
237
|
+
*/
|
|
238
|
+
start(options: MnTourOptions): MnTourRef;
|
|
239
|
+
/**
|
|
240
|
+
* Shows an offer card. A tour or offer already on screen is closed first.
|
|
241
|
+
* @param options Placement, texts and button labels.
|
|
242
|
+
* @returns A ref whose `result` settles with the user's answer.
|
|
243
|
+
*/
|
|
244
|
+
offer(options: MnTourOfferOptions): MnTourOfferRef;
|
|
245
|
+
/** Whether a tour or an offer is on screen. */
|
|
246
|
+
isActive(): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Whether the viewport is below `lg`, where the card is a bottom sheet. Public so a test (or
|
|
249
|
+
* an app with its own breakpoint logic) can override it.
|
|
250
|
+
*/
|
|
251
|
+
isCompactViewport(): boolean;
|
|
252
|
+
/** Whether the user asked for reduced motion. Public so a test can override it. */
|
|
253
|
+
prefersReducedMotion(): boolean;
|
|
254
|
+
/** Removes the overlay if the service itself is destroyed (an app or test teardown). */
|
|
255
|
+
ngOnDestroy(): void;
|
|
256
|
+
/** Steps through the tour: from the current step to `to`, skipping missing steps in `dir`. */
|
|
257
|
+
private go;
|
|
258
|
+
/**
|
|
259
|
+
* {@link go} without the re-entrance guard.
|
|
260
|
+
* @param allowFallback When going back finds nothing, re-show the current step once.
|
|
261
|
+
*/
|
|
262
|
+
private advance;
|
|
263
|
+
/** Puts step `i` on screen: content, highlight, card position, focus and tracking. */
|
|
264
|
+
private present;
|
|
265
|
+
/** Sets the highlight's box and, beside a target, the card's position. */
|
|
266
|
+
private place;
|
|
267
|
+
/**
|
|
268
|
+
* Fades the highlight and the dim out (200 ms), and the card too unless it is a bottom sheet,
|
|
269
|
+
* which stays put. Returns at once when nothing was visible.
|
|
270
|
+
*/
|
|
271
|
+
private fadeOut;
|
|
272
|
+
/** Ends a tour once: runs the current step's `after`, settles the result, removes the overlay. */
|
|
273
|
+
private endTour;
|
|
274
|
+
/** Settles an offer once and removes the overlay unless a tour takes it over. */
|
|
275
|
+
private answerOffer;
|
|
276
|
+
/** Closes whatever is on screen, without an answer. */
|
|
277
|
+
private closeCurrent;
|
|
278
|
+
/** Runs the `after` of the step that was last shown, once. A throw is ignored. */
|
|
279
|
+
private runAfter;
|
|
280
|
+
/** Records a step as missing and tells the caller. */
|
|
281
|
+
private markMissing;
|
|
282
|
+
/** Reacts to the card's controls. */
|
|
283
|
+
private onAction;
|
|
284
|
+
/** Keyboard: Escape skips/declines, ArrowRight/Enter forward, ArrowLeft back. */
|
|
285
|
+
private handleKey;
|
|
286
|
+
/** Whether step `i` is the last one. */
|
|
287
|
+
private isLastStep;
|
|
288
|
+
/** Whether there is an earlier step not known to be missing. */
|
|
289
|
+
private hasPrevious;
|
|
290
|
+
/** The card's content for step `i`. */
|
|
291
|
+
private stepView;
|
|
292
|
+
/** Where a step's card goes at the current viewport width. */
|
|
293
|
+
private stepVariant;
|
|
294
|
+
/** Where an offer's card goes at the current viewport width. */
|
|
295
|
+
private offerVariant;
|
|
296
|
+
/**
|
|
297
|
+
* Scrolls the target into view if it is not fully visible: centred on desktop, and clear of
|
|
298
|
+
* the sheet on a phone (a temporary `scroll-margin` makes the browser leave room for it).
|
|
299
|
+
*/
|
|
300
|
+
private scrollIntoView;
|
|
301
|
+
/**
|
|
302
|
+
* Keeps the highlight on its target while the page scrolls or the target reflows. Scroll is
|
|
303
|
+
* listened for on the document in the capture phase: the app's scroll container is usually a
|
|
304
|
+
* layout element, whose scroll events never reach `window`.
|
|
305
|
+
*/
|
|
306
|
+
private startTracking;
|
|
307
|
+
/** Undoes {@link startTracking}. */
|
|
308
|
+
private stopTracking;
|
|
309
|
+
/**
|
|
310
|
+
* Re-measures after a scroll, a resize or a reflow: the card's variant (the viewport may have
|
|
311
|
+
* crossed `lg`), the highlight and the card's position. A change during a glide retargets it;
|
|
312
|
+
* otherwise it is instant, so the ring never lags behind the page.
|
|
313
|
+
*/
|
|
314
|
+
private reposition;
|
|
315
|
+
/** The overlay, created and attached on first use; a pending teardown is cancelled. */
|
|
316
|
+
private ensureOverlay;
|
|
317
|
+
/** The overlay, recreated if a teardown raced ahead of a late step. */
|
|
318
|
+
private overlay;
|
|
319
|
+
/**
|
|
320
|
+
* Removes the overlay after a session ends, unless another one starts first: after a macrotask
|
|
321
|
+
* (so a tour started from an accepted offer's `then` keeps the card), fade out, then destroy.
|
|
322
|
+
*/
|
|
323
|
+
private scheduleTeardown;
|
|
324
|
+
/** Detaches and destroys the overlay, drops the listeners and gives focus back. */
|
|
325
|
+
private destroyOverlay;
|
|
326
|
+
/** Synchronously renders the overlay, so it can be measured right after a state change. */
|
|
327
|
+
private render;
|
|
328
|
+
/** Waits `ms`, or not at all under reduced motion. */
|
|
329
|
+
private wait;
|
|
330
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MnTourService, never>;
|
|
331
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
332
|
+
}
|
|
@@ -7,6 +7,7 @@ export * from "mn-angular-lib/forms";
|
|
|
7
7
|
export * from "mn-angular-lib/collection";
|
|
8
8
|
export * from "mn-angular-lib/tab";
|
|
9
9
|
export * from "mn-angular-lib/segmented";
|
|
10
|
+
export * from "mn-angular-lib/tour";
|
|
10
11
|
export * from "mn-angular-lib/rich-text-editor";
|
|
11
12
|
export * from "mn-angular-lib/display";
|
|
12
13
|
export * from "mn-angular-lib/calendar-core";
|