@glowhop/core-tour 1.3.1 → 1.5.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.
- package/CHANGELOG.md +193 -0
- package/README.md +3 -3
- package/builder/index.d.ts +15 -16
- package/config/index.d.ts +1 -1
- package/config/index.js +164 -135
- package/config/types.d.ts +27 -19
- package/definition/step-props.d.ts +9 -1
- package/definition/types.d.ts +10 -10
- package/definition/workflow-definition.d.ts +4 -7
- package/dom/tour-view-driver.d.ts +134 -3
- package/elements/base.d.ts +24 -2
- package/elements/popover.d.ts +23 -6
- package/index.d.ts +1 -1
- package/index.js +896 -503
- package/package.json +6 -4
- package/runtime/active-step.d.ts +18 -55
- package/runtime/tour-controller.d.ts +48 -12
- package/state/focus-guard.d.ts +15 -0
- package/types/index.d.ts +187 -86
- package/utils/options.d.ts +13 -1
- package/utils/utils.d.ts +16 -8
package/types/index.d.ts
CHANGED
|
@@ -16,32 +16,70 @@ export interface TargetResolverContext {
|
|
|
16
16
|
}
|
|
17
17
|
/** Configures step-level interaction behavior and error handling. */
|
|
18
18
|
export interface StepBehavior {
|
|
19
|
-
/** Allow user interaction with the page
|
|
19
|
+
/** Allow user interaction with the target: the page is no longer inert and pointer events reach the target through the cutout, while the dimmed area still catches clicks. Change it during the step with `context.props.update({ behavior: { allowInteraction } })`. @default false */
|
|
20
20
|
allowInteraction?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
/** Leave the page scrollable while the step is shown; set `false` to lock it. Change it during the step with `context.props.update({ behavior: { allowScroll } })`. @default true */
|
|
22
|
+
allowScroll?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Focus the popover's Advance control (Back when going back) when the step is shown. Set `false`
|
|
25
|
+
* to never move focus during the step: it stays where it is, on the body when a modal step
|
|
26
|
+
* makes the page inert, and placing it is up to you. Focus that leaves the popover and target
|
|
27
|
+
* is still pulled back, and focus returns to where it was when the tour ends. @default true
|
|
28
|
+
*/
|
|
29
|
+
autoFocus?: boolean;
|
|
30
|
+
/** Scroll the target into view when the step is entered. @default true */
|
|
31
|
+
autoScroll?: boolean;
|
|
32
|
+
/** What the step does when its target cannot be found. */
|
|
33
|
+
missingTarget?: MissingTargetOptions;
|
|
27
34
|
/** Scroll behavior options. */
|
|
28
35
|
scroll?: ScrollOptions;
|
|
29
|
-
/** Timeout in ms to wait for target to appear before applying missingTargetStrategy. @default 3000 */
|
|
30
|
-
targetTimeout?: number;
|
|
31
36
|
/**
|
|
32
37
|
* Behavior when the dimmed overlay backdrop (outside the cutout around the
|
|
33
38
|
* target) is clicked: `"advance"` moves to the next step, `"cancel"` ends
|
|
34
39
|
* the tour, `"none"` ignores the click. Has no effect when
|
|
35
|
-
* `allowInteraction` is `true
|
|
36
|
-
* there is no modal backdrop to click.
|
|
40
|
+
* `allowInteraction` is `true`: clicks on the dimmed area are then ignored.
|
|
37
41
|
* @default "none"
|
|
38
42
|
*/
|
|
39
43
|
overlayClick?: "none" | "advance" | "cancel";
|
|
40
44
|
}
|
|
45
|
+
/** How a step handles a target that cannot be found. */
|
|
46
|
+
export interface MissingTargetOptions {
|
|
47
|
+
/**
|
|
48
|
+
* `"wait"` retries until `timeout`, `"skip"` moves past the step, `"error"` fails the tour,
|
|
49
|
+
* `"detached"` shows the popover centered in the viewport over a backdrop that covers the whole
|
|
50
|
+
* screen. A detached step has no pointer and no cutout, does not scroll, keeps the page blocked
|
|
51
|
+
* even when `allowInteraction` is `true`, and binds no `targetEvents`; its `context.target` is the
|
|
52
|
+
* document's `<body>`.
|
|
53
|
+
* @default "error"
|
|
54
|
+
*/
|
|
55
|
+
strategy?: "wait" | "skip" | "error" | "detached";
|
|
56
|
+
/** How long to look for the target with the `"wait"` strategy, in milliseconds. @default 3000 */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
41
59
|
/** Placement directions for positioning the pointer or popover around the target. */
|
|
42
60
|
export type TryOrderOptions = "top" | "bottom" | "left" | "right";
|
|
43
61
|
/** A resolved placement direction, including `"center"` for centered positioning. */
|
|
44
62
|
export type ResolvedPlacement = TryOrderOptions | "center";
|
|
63
|
+
/** One CSS class, or several. A string may hold several space-separated classes. */
|
|
64
|
+
export type ClassValue = string | readonly string[];
|
|
65
|
+
/**
|
|
66
|
+
* Classes added to the tour components while a step is shown, one entry per component.
|
|
67
|
+
*
|
|
68
|
+
* They are added to the classes passed to the component itself, never replacing them. A step's entry
|
|
69
|
+
* overrides the workflow's entry for the same component; the components the step leaves out keep the
|
|
70
|
+
* workflow's classes.
|
|
71
|
+
*/
|
|
72
|
+
export interface TourClassNames {
|
|
73
|
+
overlay?: ClassValue;
|
|
74
|
+
popover?: ClassValue;
|
|
75
|
+
pointer?: ClassValue;
|
|
76
|
+
header?: ClassValue;
|
|
77
|
+
content?: ClassValue;
|
|
78
|
+
footer?: ClassValue;
|
|
79
|
+
advance?: ClassValue;
|
|
80
|
+
previous?: ClassValue;
|
|
81
|
+
cancel?: ClassValue;
|
|
82
|
+
}
|
|
45
83
|
/** Base configuration for animated elements. */
|
|
46
84
|
export interface BaseOptions {
|
|
47
85
|
/** Enable or disable animations. */
|
|
@@ -51,8 +89,8 @@ export interface BaseOptions {
|
|
|
51
89
|
}
|
|
52
90
|
/** Configures the pointer indicator that highlights the target element. */
|
|
53
91
|
export interface IndicatorOptions extends BaseOptions {
|
|
54
|
-
/** Hide the indicator. @default false */
|
|
55
|
-
|
|
92
|
+
/** Hide the indicator. It only shows on steps that allow interaction. @default false */
|
|
93
|
+
hidden?: boolean;
|
|
56
94
|
/** Gap between the target and the indicator in pixels. */
|
|
57
95
|
gap?: number;
|
|
58
96
|
/** Placement preference order when positioning the indicator. @default ["left", "right", "top", "bottom"] */
|
|
@@ -72,7 +110,7 @@ export interface OverlayOptions extends BaseOptions {
|
|
|
72
110
|
/** Configures the arrow that points from the popover to the target. */
|
|
73
111
|
export interface PopoverArrowOptions {
|
|
74
112
|
/** Hide the arrow. @default false */
|
|
75
|
-
|
|
113
|
+
hidden?: boolean;
|
|
76
114
|
/** Color of the arrow (CSS color). */
|
|
77
115
|
color?: string;
|
|
78
116
|
/** Size of the arrow in pixels. @default 12 */
|
|
@@ -90,11 +128,41 @@ export interface PopoverArrowOptions {
|
|
|
90
128
|
*/
|
|
91
129
|
styleNonce?: string;
|
|
92
130
|
/**
|
|
93
|
-
*
|
|
131
|
+
* Inject the built-in arrow `<style>` element. Set `false` to provide the
|
|
94
132
|
* equivalent rules yourself through whatever channel your CSP allows, such
|
|
95
133
|
* as an external stylesheet.
|
|
134
|
+
* @default true
|
|
96
135
|
*/
|
|
97
|
-
|
|
136
|
+
autoStyles?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Whether the user may run a tour control. `"enabled"` is the default. New states may be added in
|
|
140
|
+
* a minor version.
|
|
141
|
+
*/
|
|
142
|
+
export type TourControlState = "enabled" | "disabled";
|
|
143
|
+
/** One navigation command: whether the user may run it and the keys that run it. */
|
|
144
|
+
export interface TourControl {
|
|
145
|
+
/**
|
|
146
|
+
* `"disabled"` blocks the command everywhere the tour UI offers it: its button is disabled, and
|
|
147
|
+
* its keys and `overlayClick` do nothing. Navigation through the tour API and the step context
|
|
148
|
+
* stays available. To hide a button, give it a class through `classNames`.
|
|
149
|
+
* @default "enabled"
|
|
150
|
+
*/
|
|
151
|
+
state?: TourControlState;
|
|
152
|
+
/** Keys that run the command while the step is shown. An empty array turns them off. */
|
|
153
|
+
keys?: readonly string[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The advance, previous and cancel commands. A step's controls override the workflow ones field by
|
|
157
|
+
* field: a step that only sets `advance.state` keeps the workflow's `advance.keys`.
|
|
158
|
+
*/
|
|
159
|
+
export interface TourControls {
|
|
160
|
+
/** @default { state: "enabled", keys: ["Enter", "ArrowRight"] } */
|
|
161
|
+
advance?: TourControl;
|
|
162
|
+
/** @default { state: "enabled", keys: ["ArrowLeft", "Backspace"] } */
|
|
163
|
+
previous?: TourControl;
|
|
164
|
+
/** @default { state: "enabled", keys: ["Escape"] } */
|
|
165
|
+
cancel?: TourControl;
|
|
98
166
|
}
|
|
99
167
|
/** Configures the popover box that displays content for each step. */
|
|
100
168
|
export interface PopoverOptions extends BaseOptions {
|
|
@@ -102,47 +170,20 @@ export interface PopoverOptions extends BaseOptions {
|
|
|
102
170
|
placementTryOrder?: readonly TryOrderOptions[];
|
|
103
171
|
/** Arrow configuration. */
|
|
104
172
|
arrow?: PopoverArrowOptions;
|
|
105
|
-
/** Hide the footer section. @default false */
|
|
106
|
-
hideFooter?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Disables only previous-button and previous-keyboard controls. Programmatic
|
|
109
|
-
* navigation through the tour API and step context remains available.
|
|
110
|
-
*/
|
|
111
|
-
disablePreviousButton?: boolean;
|
|
112
|
-
/** Hide the previous button. @default false */
|
|
113
|
-
hidePreviousButton?: boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Disables only advance-button and advance-keyboard controls. Programmatic
|
|
116
|
-
* navigation through the tour API and step context remains available.
|
|
117
|
-
*/
|
|
118
|
-
disableAdvanceButton?: boolean;
|
|
119
|
-
/** Hide the advance button. @default false */
|
|
120
|
-
hideAdvanceButton?: boolean;
|
|
121
173
|
/** Gap between the target and the popover in pixels. @default 16 */
|
|
122
174
|
gap?: number;
|
|
123
|
-
/** Keyboard shortcuts for navigation. */
|
|
124
|
-
keyboardShortcuts?: {
|
|
125
|
-
/**
|
|
126
|
-
* Keys that trigger previous step. @default ["ArrowLeft", "Backspace"]
|
|
127
|
-
*/
|
|
128
|
-
previous?: readonly string[];
|
|
129
|
-
/**
|
|
130
|
-
* Keys that trigger advance step. @default ["Enter", "ArrowRight"]
|
|
131
|
-
*/
|
|
132
|
-
advance?: readonly string[];
|
|
133
|
-
/**
|
|
134
|
-
* Keys that trigger cancel. @default ["Escape"]
|
|
135
|
-
*/
|
|
136
|
-
cancel?: readonly string[];
|
|
137
|
-
};
|
|
138
175
|
}
|
|
139
176
|
/**
|
|
140
|
-
*
|
|
177
|
+
* How a step scrolls its target into view, on entrance and after the user scrolled away.
|
|
141
178
|
*
|
|
142
179
|
* A step scrolls only when part of its target falls outside the viewport, and
|
|
143
180
|
* does not wait for the scroll before presenting: the spotlight appears at once
|
|
144
181
|
* and tracks the target as the page travels, and the popover and pointer enter
|
|
145
182
|
* when the page has come to rest.
|
|
183
|
+
*
|
|
184
|
+
* While the user scrolls, the popover and pointer step aside and the spotlight
|
|
185
|
+
* keeps following the target. Once the page is still they come back, after
|
|
186
|
+
* `returnDelay` scrolls the target back into view if it was left outside it.
|
|
146
187
|
*/
|
|
147
188
|
export interface ScrollOptions {
|
|
148
189
|
/** Scroll animation. Forced to `"instant"` when the user prefers reduced motion. @default "smooth" */
|
|
@@ -151,6 +192,12 @@ export interface ScrollOptions {
|
|
|
151
192
|
block?: "start" | "center" | "end" | "nearest";
|
|
152
193
|
/** Horizontal alignment of the target in the viewport. @default "nearest" */
|
|
153
194
|
inline?: "start" | "center" | "end" | "nearest";
|
|
195
|
+
/**
|
|
196
|
+
* Milliseconds to wait, once the user stops scrolling with part of the target outside the
|
|
197
|
+
* viewport, before scrolling it back into view. `false` leaves the page where the user put it.
|
|
198
|
+
* Ignored when `autoScroll` is `false`. @default 500
|
|
199
|
+
*/
|
|
200
|
+
returnDelay?: number | false;
|
|
154
201
|
}
|
|
155
202
|
/** Animation timing configuration. */
|
|
156
203
|
export interface AnimationOptions {
|
|
@@ -165,8 +212,8 @@ export interface AnimationOptions {
|
|
|
165
212
|
export interface LifecycleHookContext<T> {
|
|
166
213
|
/**
|
|
167
214
|
* The step associated with this lifecycle transition:
|
|
168
|
-
* - `onStart`: the
|
|
169
|
-
* `null` if the workflow has no steps.
|
|
215
|
+
* - `onStart`: the step `start()` starts on (the `startAt` step, or the first
|
|
216
|
+
* step), or `null` if the workflow has no steps.
|
|
170
217
|
* - `onCancel`: the step the tour is currently on when cancellation is
|
|
171
218
|
* requested. Always non-null in practice, since a step is always active
|
|
172
219
|
* at the point a tour can be cancelled.
|
|
@@ -190,15 +237,6 @@ export interface LifecycleHookContext<T> {
|
|
|
190
237
|
}
|
|
191
238
|
/** Options for starting a tour workflow. */
|
|
192
239
|
export interface StartOptions<T> {
|
|
193
|
-
/** Allow users to cancel the tour. @default true */
|
|
194
|
-
cancellable?: boolean;
|
|
195
|
-
/**
|
|
196
|
-
* Leaves page scroll available while the tour is active. Set `false` to lock
|
|
197
|
-
* scroll instead, restoring it on finish, cancel, error, or dispose.
|
|
198
|
-
*
|
|
199
|
-
* @default true
|
|
200
|
-
*/
|
|
201
|
-
allowScroll?: boolean;
|
|
202
240
|
/** Default overlay options for all steps. */
|
|
203
241
|
overlay?: OverlayOptions;
|
|
204
242
|
/** Default popover options for all steps. */
|
|
@@ -209,6 +247,10 @@ export interface StartOptions<T> {
|
|
|
209
247
|
animated?: boolean;
|
|
210
248
|
/** Default step behavior for all steps. */
|
|
211
249
|
behavior?: StepBehavior;
|
|
250
|
+
/** Default controls for all steps. See `TourControls`. */
|
|
251
|
+
controls?: TourControls;
|
|
252
|
+
/** Classes added to the tour components on every step. See `TourClassNames`. */
|
|
253
|
+
classNames?: TourClassNames;
|
|
212
254
|
/** Lifecycle hook called when the tour starts. */
|
|
213
255
|
onStart?: (context: LifecycleHookContext<T>) => void | Promise<void>;
|
|
214
256
|
/** Lifecycle hook called when the tour is cancelled. */
|
|
@@ -225,12 +267,22 @@ export interface StartOptions<T> {
|
|
|
225
267
|
}
|
|
226
268
|
/** Update to step properties, either as a full replacement or via a function. */
|
|
227
269
|
export type StepPropsUpdate<T> = ReadonlyStepProps<T> | ((current: ReadonlyStepProps<T>) => ReadonlyStepProps<T>);
|
|
270
|
+
/**
|
|
271
|
+
* Partial change to step properties, for `StepPropsStore.update`. Fields it leaves out are kept.
|
|
272
|
+
* `data` is merged key by key; `overlay`, `popover`, `indicator`, `behavior` and `controls` are
|
|
273
|
+
* merged the way step options merge over workflow defaults; arrays such as `placementTryOrder` or
|
|
274
|
+
* `keys` are replaced. `classNames` is merged per component: a component it names gets exactly the
|
|
275
|
+
* classes given.
|
|
276
|
+
*/
|
|
277
|
+
export type StepPropsPatch<T> = Partial<ReadonlyStepProps<T>>;
|
|
228
278
|
/** Store for the current step's properties. */
|
|
229
279
|
export interface StepPropsStore<T> {
|
|
230
280
|
/** Get the current step properties. */
|
|
231
281
|
get(): ReadonlyStepProps<T>;
|
|
232
|
-
/**
|
|
282
|
+
/** Replace the current step properties. */
|
|
233
283
|
set(update: StepPropsUpdate<T>): void;
|
|
284
|
+
/** Merge a partial change into the current step properties. See `StepPropsPatch`. */
|
|
285
|
+
update(patch: StepPropsPatch<T> | ((current: ReadonlyStepProps<T>) => StepPropsPatch<T>)): void;
|
|
234
286
|
/** Subscribe to changes in step properties. Returns an unsubscribe function. */
|
|
235
287
|
subscribe(listener: (props: ReadonlyStepProps<T>) => void): () => void;
|
|
236
288
|
}
|
|
@@ -242,17 +294,39 @@ export interface StepContext<T> {
|
|
|
242
294
|
cancel(): Promise<void>;
|
|
243
295
|
/** Navigate to the previous step. */
|
|
244
296
|
previous(): Promise<void>;
|
|
245
|
-
/**
|
|
297
|
+
/**
|
|
298
|
+
* Navigate to the step with this id, skipping the steps in between. Stops the remaining actions
|
|
299
|
+
* of this step, like `advance()`. Throws when no step has this id.
|
|
300
|
+
*/
|
|
301
|
+
goTo(id: string): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* The direction of the navigation that entered this step. Captured when the context is created, so
|
|
304
|
+
* it does not change while the step's callbacks run.
|
|
305
|
+
*/
|
|
306
|
+
readonly direction: TourDirection;
|
|
307
|
+
/** The step properties as initially configured, before any `props.set()`. */
|
|
308
|
+
readonly initialProps: ReadonlyStepProps<T>;
|
|
309
|
+
/** The DOM element being highlighted for this step, or the document's `<body>` for a detached step. */
|
|
246
310
|
readonly target: HTMLElement;
|
|
247
311
|
/** Store for reading and updating the current step's properties. */
|
|
248
312
|
readonly props: StepPropsStore<T>;
|
|
249
313
|
/** Signal that aborts when the step is exited or the tour is cancelled. */
|
|
250
314
|
readonly signal: AbortSignal;
|
|
251
315
|
}
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Context passed to the `beforeEnter` and `beforeLeave` step hooks. It has no navigation methods:
|
|
318
|
+
* a transition is already in progress when these hooks run. `direction` is the direction of that
|
|
319
|
+
* navigation, so the step being left and the step being entered see the same value.
|
|
320
|
+
*/
|
|
321
|
+
export interface StepHookContext<T> extends Omit<StepContext<T>, "advance" | "cancel" | "goTo" | "previous"> {
|
|
322
|
+
/**
|
|
323
|
+
* Call it synchronously, or before the hook's returned promise resolves, to stop the navigation.
|
|
324
|
+
* The tour stays on the step it was on and emits nothing: `beforeLeave` keeps the step, and
|
|
325
|
+
* `beforeEnter` does not show the next one. When `beforeEnter` aborts the first step of `start()`,
|
|
326
|
+
* the tour goes back to `idle`, like an `onStart` abort.
|
|
327
|
+
*/
|
|
328
|
+
abort(): void;
|
|
329
|
+
}
|
|
256
330
|
/** Context passed to target event handlers. */
|
|
257
331
|
export type StepEventContext<T> = StepContext<T>;
|
|
258
332
|
/** Options for the waitUntil step action. */
|
|
@@ -268,16 +342,16 @@ export type StepActionResult = boolean | void;
|
|
|
268
342
|
export type StepAction<T> = (context: StepContext<T>) => Promise<StepActionResult> | StepActionResult;
|
|
269
343
|
/** A step action or a delay in milliseconds. */
|
|
270
344
|
export type StepActionInstruction<T> = StepAction<T> | number;
|
|
271
|
-
/** A callback that runs before
|
|
272
|
-
export type
|
|
345
|
+
/** A callback that runs before a step is entered or left (`beforeEnter` / `beforeLeave`). */
|
|
346
|
+
export type StepHookAction<T> = (context: StepHookContext<T>) => void | Promise<void>;
|
|
273
347
|
/** Handler for an event fired on the target element during a step. */
|
|
274
|
-
export interface
|
|
348
|
+
export interface TargetEventHandler<TStepProps, TEvent extends Event = Event> {
|
|
275
349
|
/** Event name(s) to listen for. */
|
|
276
350
|
event: string;
|
|
277
351
|
/** Callback invoked when the event fires. */
|
|
278
352
|
callback: (event: TEvent, context: StepEventContext<TStepProps>) => void | Promise<void>;
|
|
279
353
|
}
|
|
280
|
-
/** Tour lifecycle status. */
|
|
354
|
+
/** Tour lifecycle status. New statuses may be added in a minor release: keep a default branch when switching over it. */
|
|
281
355
|
export type TourStatus = "idle" | "starting" | "transitioning" | "active" | "finished" | "cancelled" | "error" | "disposed";
|
|
282
356
|
/** Direction of tour navigation. */
|
|
283
357
|
export type TourDirection = "advance" | "previous";
|
|
@@ -316,6 +390,17 @@ export interface TourState<T> {
|
|
|
316
390
|
readonly isLastStep: boolean;
|
|
317
391
|
/** Current status of the tour. */
|
|
318
392
|
readonly status: TourStatus;
|
|
393
|
+
/**
|
|
394
|
+
* Whether a navigation is waiting for the next step's target to resolve, i.e. an async resolver
|
|
395
|
+
* or the `"wait"` missing-target strategy. The step being left stays on screen meanwhile, and its
|
|
396
|
+
* advance control is refused, so a UI can show the wait instead of looking idle.
|
|
397
|
+
*/
|
|
398
|
+
readonly awaitingTarget: boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Whether `hidePopover()` hid the popover of the running tour. `false` again after
|
|
401
|
+
* `showPopover()`, and whenever a tour starts or ends.
|
|
402
|
+
*/
|
|
403
|
+
readonly popoverHidden: boolean;
|
|
319
404
|
/** Error encountered during the tour, if any. */
|
|
320
405
|
readonly error: Error | null;
|
|
321
406
|
}
|
|
@@ -331,22 +416,37 @@ export interface GlowTour<T> {
|
|
|
331
416
|
/** Create a new workflow builder with the given name. */
|
|
332
417
|
create(name: string, options?: StartOptions<T>): WorkflowBuilder<T>;
|
|
333
418
|
/** Run a workflow, optionally starting at a specific step. */
|
|
334
|
-
|
|
419
|
+
start(workflow: WorkflowDefinition<T>, options?: RunOptions): Promise<void>;
|
|
335
420
|
/** Advance to the next step. */
|
|
336
421
|
advance(): Promise<void>;
|
|
337
422
|
/** Go to the previous step. */
|
|
338
423
|
previous(): Promise<void>;
|
|
339
|
-
/**
|
|
340
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Go to the step with this id, skipping the steps in between. Does nothing while a transition is
|
|
426
|
+
* in progress or when that step is already shown. Throws when no step has this id.
|
|
427
|
+
*/
|
|
428
|
+
goTo(id: string): Promise<void>;
|
|
341
429
|
/** Cancel the current tour. */
|
|
342
430
|
cancel(): Promise<void>;
|
|
431
|
+
/**
|
|
432
|
+
* Show the popover again after `hidePopover()`, and move focus into it when the step auto
|
|
433
|
+
* focuses. Does nothing when no tour is running.
|
|
434
|
+
*/
|
|
435
|
+
showPopover(): void;
|
|
436
|
+
/**
|
|
437
|
+
* Hide the popover of the running tour. The overlay, the indicator and the scroll lock stay; the
|
|
438
|
+
* page is no longer inert, focus leaves the popover for the target, and the keyboard shortcuts
|
|
439
|
+
* do nothing until `showPopover()`. The popover stays hidden across steps, until `showPopover()`
|
|
440
|
+
* or the end of the tour. Does nothing when no tour is running.
|
|
441
|
+
*/
|
|
442
|
+
hidePopover(): void;
|
|
343
443
|
/** Dispose the tour and free resources. */
|
|
344
444
|
dispose(): void;
|
|
345
445
|
/** Observable store of the current tour state. */
|
|
346
446
|
readonly state: ReadonlyTourState<T>;
|
|
347
447
|
}
|
|
348
448
|
/**
|
|
349
|
-
* Per-run options. Unlike `StartOptions`, these belong to one `
|
|
449
|
+
* Per-run options. Unlike `StartOptions`, these belong to one `start()` call and
|
|
350
450
|
* are never baked into the reusable workflow definition.
|
|
351
451
|
*/
|
|
352
452
|
export interface RunOptions {
|
|
@@ -365,13 +465,15 @@ export interface RunOptions {
|
|
|
365
465
|
/**
|
|
366
466
|
* What triggered a transition.
|
|
367
467
|
*
|
|
368
|
-
* `"api"` covers every call your own code makes
|
|
369
|
-
* `
|
|
370
|
-
*
|
|
468
|
+
* `"api"` covers every call your own code makes: `advance()`, `previous()`,
|
|
469
|
+
* `goTo()`, `cancel()`, and the same methods on the context of a step action.
|
|
470
|
+
* The other three are the user acting on the tour UI directly.
|
|
471
|
+
*
|
|
472
|
+
* New sources may be added in a minor release: keep a default branch when switching over it.
|
|
371
473
|
*/
|
|
372
474
|
export type TourEventSource = "api" | "trigger" | "keyboard" | "overlay";
|
|
373
|
-
/** Name of a monitoring event. */
|
|
374
|
-
export type TourEventType = "tour:start" | "step:enter" | "step:leave" | "tour:complete" | "tour:cancel" | "tour:error";
|
|
475
|
+
/** Name of a monitoring event. New events may be added in a minor release: keep a default branch when switching over it. */
|
|
476
|
+
export type TourEventType = "tour:start" | "step:enter" | "step:leave" | "step:skip" | "tour:complete" | "tour:cancel" | "tour:error";
|
|
375
477
|
/**
|
|
376
478
|
* A monitoring event, as handed to `onEvent`.
|
|
377
479
|
*
|
|
@@ -402,7 +504,7 @@ export interface TourEvent {
|
|
|
402
504
|
* How long the thing this event names had been running, in milliseconds.
|
|
403
505
|
*
|
|
404
506
|
* For `step:leave`, the time spent on that step. For `tour:complete`,
|
|
405
|
-
* `tour:cancel` and `tour:error`, the time since `
|
|
507
|
+
* `tour:cancel` and `tour:error`, the time since `start()` was called. For
|
|
406
508
|
* `tour:start` and `step:enter` — the beginnings — always `0`.
|
|
407
509
|
*/
|
|
408
510
|
readonly durationMs: number;
|
|
@@ -444,11 +546,6 @@ export type StepParameters<T> = {
|
|
|
444
546
|
id: string;
|
|
445
547
|
/** The target element or selector for this step. */
|
|
446
548
|
target: TargetResolver;
|
|
447
|
-
/**
|
|
448
|
-
* Reset step properties to initial values when entering this step.
|
|
449
|
-
* @default true
|
|
450
|
-
*/
|
|
451
|
-
resetPropsOnEnter?: boolean;
|
|
452
549
|
/** Overlay options for this step (overrides workflow defaults). */
|
|
453
550
|
overlay?: OverlayOptions;
|
|
454
551
|
/** Popover options for this step (overrides workflow defaults). */
|
|
@@ -457,8 +554,12 @@ export type StepParameters<T> = {
|
|
|
457
554
|
indicator?: IndicatorOptions;
|
|
458
555
|
/** Step behavior (overrides workflow defaults). */
|
|
459
556
|
behavior?: StepBehavior;
|
|
460
|
-
/**
|
|
461
|
-
|
|
557
|
+
/** Navigation controls for this step (overrides workflow defaults field by field). See `TourControls`. */
|
|
558
|
+
controls?: TourControls;
|
|
559
|
+
/** Classes added to the tour components on this step (overrides workflow defaults per component). See `TourClassNames`. */
|
|
560
|
+
classNames?: TourClassNames;
|
|
561
|
+
/** The title content for this step. Without a title, the popover is named by its content. */
|
|
562
|
+
title?: T;
|
|
462
563
|
/** The body content for this step. */
|
|
463
564
|
content: T;
|
|
464
565
|
/** Arbitrary data associated with this step. */
|
package/utils/options.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeepReadonly, ReadonlyStepProps } from "../definition";
|
|
2
|
+
import type { AnimationOptions, IndicatorOptions, OverlayOptions, PopoverOptions, ScrollOptions, StepBehavior, StepPropsPatch, TourControls } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Merges a partial change into step props: fields it leaves out are kept, `data` is merged key by
|
|
5
|
+
* key, `overlay` / `popover` / `indicator` / `behavior` / `controls` go through their option merges,
|
|
6
|
+
* `classNames` is merged per component, and arrays are replaced.
|
|
7
|
+
* Builds a step's initial props over the workflow defaults, and backs `StepPropsStore.update`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeStepProps<T>(base: StepPropsPatch<T>, patch: StepPropsPatch<T>): ReadonlyStepProps<T>;
|
|
2
10
|
export declare function mergeOverlayOptions(defaults?: OverlayOptions, overrides?: OverlayOptions): OverlayOptions | undefined;
|
|
3
11
|
export declare function mergeIndicatorOptions(defaults?: IndicatorOptions, overrides?: IndicatorOptions): IndicatorOptions | undefined;
|
|
4
12
|
export declare function mergePopoverOptions(defaults?: PopoverOptions, overrides?: PopoverOptions): PopoverOptions | undefined;
|
|
5
13
|
export declare function mergeScrollOptions(defaults?: ScrollOptions, overrides?: ScrollOptions): ScrollOptions | undefined;
|
|
6
14
|
export declare function mergeAnimationOptions(defaults?: AnimationOptions, overrides?: AnimationOptions): AnimationOptions | undefined;
|
|
7
15
|
export declare function mergeStepBehavior(defaults?: StepBehavior, overrides?: StepBehavior): StepBehavior | undefined;
|
|
16
|
+
/** Whether a control is enabled, so its button, keys and `overlayClick` may run its command. */
|
|
17
|
+
export declare function isControlAvailable(props: {
|
|
18
|
+
readonly controls?: DeepReadonly<TourControls>;
|
|
19
|
+
} | undefined, command: "advance" | "previous" | "cancel"): boolean;
|
package/utils/utils.d.ts
CHANGED
|
@@ -10,15 +10,16 @@ export declare function isNode(value: unknown, context?: Node | null): value is
|
|
|
10
10
|
* `getBoundingClientRect()` reports coordinates in.
|
|
11
11
|
*
|
|
12
12
|
* Deliberately not `innerWidth`/`innerHeight`: those measure the *visual*
|
|
13
|
-
* viewport, which on mobile shrinks and grows with the
|
|
14
|
-
*
|
|
15
|
-
* `viewBox` against its own
|
|
16
|
-
* `
|
|
17
|
-
* bands and a cutout that no longer
|
|
13
|
+
* viewport on some engines, which on mobile shrinks and grows with the
|
|
14
|
+
* browser's URL bar and pinch zoom, and on desktop includes the classic
|
|
15
|
+
* scrollbar. Either gap skews the overlay's `viewBox` against its own
|
|
16
|
+
* `100%`-sized box, and the default `preserveAspectRatio` then scales and
|
|
17
|
+
* centres the backdrop — leaving undimmed bands and a cutout that no longer
|
|
18
|
+
* lines up with its target.
|
|
18
19
|
*/
|
|
19
20
|
export declare function viewportDimensions(context?: Node | null): {
|
|
20
|
-
width: number;
|
|
21
21
|
height: number;
|
|
22
|
+
width: number;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* The box the overlay `<svg>` is actually painted into, in CSS pixels.
|
|
@@ -36,8 +37,8 @@ export declare function viewportDimensions(context?: Node | null): {
|
|
|
36
37
|
* yet — detached nodes, server-rendered markup, test doubles.
|
|
37
38
|
*/
|
|
38
39
|
export declare function paintedBoxDimensions(element?: Element | null): {
|
|
39
|
-
width: number;
|
|
40
40
|
height: number;
|
|
41
|
+
width: number;
|
|
41
42
|
};
|
|
42
43
|
export declare function isInViewport(rect: {
|
|
43
44
|
left: number;
|
|
@@ -55,7 +56,14 @@ export declare function roundedRectPath(rect: RectGeometry, viewport: {
|
|
|
55
56
|
padding: number;
|
|
56
57
|
radius: number;
|
|
57
58
|
}, context?: Node | null): string;
|
|
59
|
+
/** Whether a target resolution is still pending, i.e. the resolver returned a promise. */
|
|
60
|
+
export declare function isPendingTarget(value: HTMLElement | null | Promise<HTMLElement | null>): value is Promise<HTMLElement | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a step's target. Deliberately not `async`: a selector or an element target settles
|
|
63
|
+
* synchronously, and only a resolver that returns a promise hands back something to wait on.
|
|
64
|
+
* Callers use {@link isPendingTarget} to tell the two apart, and a tour that has to wait says so.
|
|
65
|
+
*/
|
|
58
66
|
export declare function resolveTargetElement(target: TargetResolver, options: {
|
|
59
67
|
readonly document?: Document;
|
|
60
68
|
readonly signal: AbortSignal;
|
|
61
|
-
}, path?: string): Promise<HTMLElement | null>;
|
|
69
|
+
}, path?: string): HTMLElement | null | Promise<HTMLElement | null>;
|