@dloizides/ui-tour 1.1.1 → 1.2.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 +10 -0
- package/README.md +4 -4
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -5
- package/dist/index.mjs.map +1 -1
- package/dist/playwright/index.d.mts +2 -0
- package/dist/playwright/index.d.ts +2 -0
- package/dist/playwright/index.js +18 -4
- package/dist/playwright/index.js.map +1 -1
- package/dist/playwright/index.mjs +18 -4
- package/dist/playwright/index.mjs.map +1 -1
- package/dist/testing/index.d.mts +4 -4
- package/dist/testing/index.d.ts +4 -4
- package/dist/testing/index.js +11 -6
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +11 -6
- package/dist/testing/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
- `vars` placeholders are filled in a step's `route` too (`/t/{tenantSlug}/register`). `expectValidTours(tours, translations, vars)` reports a route placeholder that `vars` does not fill.
|
|
6
|
+
- The engine counts the optional steps it skipped in a run: the caption carries `data-tour-skipped`, and `tour_finish` carries `skipped` (a number, no PII).
|
|
7
|
+
- `playAllToursInAuto` reads that count into `TourRunResult.skipped`; `expectAllToursPlay` fails a tour that skipped more than `maxSkippedRatio` x steps (default 0.25).
|
|
8
|
+
|
|
9
|
+
## 1.1.2
|
|
10
|
+
|
|
11
|
+
- `expectAllToursPlay` fails when the picker lists no tours (app not mounted before F2) and when `ids` names a tour the picker does not list.
|
|
12
|
+
|
|
3
13
|
## 1.1.0
|
|
4
14
|
|
|
5
15
|
- `@dloizides/ui-tour/expo`: `AppTours` (one-line setup: expo-router navigate, theme adapter `toTourTheme`, translated labels, Umami events, picker, first-run card) and `TourButton` ("Take a tour").
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Open the picker from a Help menu with `useTour().openPicker()`; F2 opens it anyw
|
|
|
59
59
|
| `findTarget`, `isForbiddenClick` | The element finder and the write-control rule used by the engine |
|
|
60
60
|
| `defaultTourLabels`, `formatLabel` | English defaults; pass translated `labels` (placeholders `{{p1}}`, `{{p2}}`) |
|
|
61
61
|
|
|
62
|
-
A step target is a testID string (`data-testid`) or `{ role, name, nth?, exact?, within? }` with role `button`, `heading`, `group`, `field` or `text`. `{name}` placeholders in a step are filled from `vars`.
|
|
62
|
+
A step target is a testID string (`data-testid`) or `{ role, name, nth?, exact?, within? }` with role `button`, `heading`, `group`, `field` or `text`. `{name}` placeholders in a step's `text`, `value` and `route` are filled from `vars`.
|
|
63
63
|
|
|
64
64
|
### Theme
|
|
65
65
|
|
|
@@ -114,7 +114,7 @@ import { TOURS } from '../tours';
|
|
|
114
114
|
| `target` | A testID (`open-payees`) or `{ role, name, nth?, exact?, within? }` |
|
|
115
115
|
| `text` | Translation key of the caption text; `{name}` placeholders come from `vars` |
|
|
116
116
|
| `action` | `StepAction.Click`, `Type` (needs `value`) or `None` |
|
|
117
|
-
| `route?` | Navigates there first |
|
|
117
|
+
| `route?` | Navigates there first; `{name}` placeholders come from `vars` (`/t/{tenantSlug}/register`) |
|
|
118
118
|
| `optional?` | Skipped when the target is absent |
|
|
119
119
|
| `wait?` | Extra wait in ms before the step |
|
|
120
120
|
|
|
@@ -131,7 +131,7 @@ import en from '../localization/locales/en.json';
|
|
|
131
131
|
it('every tour is valid', () => expectValidTours(TOURS, en));
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
It fails on a missing text key, a malformed target, a repeated id, a tour without steps
|
|
134
|
+
It fails on a missing text key, a malformed target, a repeated id, a tour without steps, a click on a write control or a route placeholder that `vars` does not fill. Pass the vars your routes use: `expectValidTours(TOURS, en, { tenantSlug: 'demo' })`.
|
|
135
135
|
|
|
136
136
|
```ts
|
|
137
137
|
import { expectAllToursPlay } from '@dloizides/ui-tour/playwright';
|
|
@@ -139,7 +139,7 @@ import { expectAllToursPlay } from '@dloizides/ui-tour/playwright';
|
|
|
139
139
|
test('every tour plays to the end in Auto', async ({ page }) => expectAllToursPlay(page));
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
It plays every tour in the picker in Auto and fails with `tour <id> step <n>/<m>: <reason>` (target missing, stuck, closed early, never started). The caption carries `data-tour-id`, `data-tour-step` and `data-tour-
|
|
142
|
+
It plays every tour in the picker in Auto and fails with `tour <id> step <n>/<m>: <reason>` (target missing, stuck, closed early, never started). The caption carries `data-tour-id`, `data-tour-step`, `data-tour-steps` and `data-tour-skipped` (optional steps the engine skipped this run) for runners; `tour_finish` events carry the same `skipped` count. A tour that skipped more than `maxSkippedRatio` x its steps (default 0.25) fails: `expectAllToursPlay(page, { maxSkippedRatio: 0.5 })`. `expo-router` and `@playwright/test` are optional peers.
|
|
143
143
|
|
|
144
144
|
## License
|
|
145
145
|
|
package/dist/index.d.mts
CHANGED
|
@@ -94,6 +94,7 @@ interface TourEvent {
|
|
|
94
94
|
type: TourEventType;
|
|
95
95
|
tourId: string;
|
|
96
96
|
mode: TourMode;
|
|
97
|
+
skipped?: number;
|
|
97
98
|
}
|
|
98
99
|
interface TourUser {
|
|
99
100
|
id: string;
|
|
@@ -168,8 +169,10 @@ interface TourControls {
|
|
|
168
169
|
active: ActiveTour | null;
|
|
169
170
|
paused: boolean;
|
|
170
171
|
pickerOpen: boolean;
|
|
172
|
+
skipped: number;
|
|
171
173
|
start: (tourId: string, mode: TourMode) => void;
|
|
172
174
|
next: () => void;
|
|
175
|
+
skipOptional: () => void;
|
|
173
176
|
back: () => void;
|
|
174
177
|
end: () => void;
|
|
175
178
|
togglePause: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ interface TourEvent {
|
|
|
94
94
|
type: TourEventType;
|
|
95
95
|
tourId: string;
|
|
96
96
|
mode: TourMode;
|
|
97
|
+
skipped?: number;
|
|
97
98
|
}
|
|
98
99
|
interface TourUser {
|
|
99
100
|
id: string;
|
|
@@ -168,8 +169,10 @@ interface TourControls {
|
|
|
168
169
|
active: ActiveTour | null;
|
|
169
170
|
paused: boolean;
|
|
170
171
|
pickerOpen: boolean;
|
|
172
|
+
skipped: number;
|
|
171
173
|
start: (tourId: string, mode: TourMode) => void;
|
|
172
174
|
next: () => void;
|
|
175
|
+
skipOptional: () => void;
|
|
173
176
|
back: () => void;
|
|
174
177
|
end: () => void;
|
|
175
178
|
togglePause: () => void;
|
package/dist/index.js
CHANGED
|
@@ -284,8 +284,10 @@ function inertTour(tours, theme, labels) {
|
|
|
284
284
|
active: null,
|
|
285
285
|
paused: false,
|
|
286
286
|
pickerOpen: false,
|
|
287
|
+
skipped: 0,
|
|
287
288
|
start: ignore,
|
|
288
289
|
next: ignore,
|
|
290
|
+
skipOptional: ignore,
|
|
289
291
|
back: ignore,
|
|
290
292
|
end: ignore,
|
|
291
293
|
togglePause: ignore,
|
|
@@ -411,7 +413,8 @@ async function perform(context, node) {
|
|
|
411
413
|
}
|
|
412
414
|
async function runStep(context) {
|
|
413
415
|
const { step } = context;
|
|
414
|
-
|
|
416
|
+
const route = step.route === void 0 ? void 0 : substitute(step.route, context.vars);
|
|
417
|
+
if (route !== void 0 && context.getPathname() !== route) context.navigate(route);
|
|
415
418
|
const node = await waitForTarget(step.target, context.vars, step.wait ?? context.timing.waitMs, context.isCancelled);
|
|
416
419
|
if (context.isCancelled()) return CANCELLED;
|
|
417
420
|
if (node === null) return { kind: step.optional === true ? "skip" /* Skip */ : "missing" /* Missing */ };
|
|
@@ -522,6 +525,8 @@ function useTourControls(options) {
|
|
|
522
525
|
const [active, setActiveState] = react.useState(() => loadSession(options.tours));
|
|
523
526
|
const [paused, setPaused] = react.useState(false);
|
|
524
527
|
const [pickerOpen, setPickerOpen] = react.useState(false);
|
|
528
|
+
const [skipped, setSkipped] = react.useState(0);
|
|
529
|
+
const skippedSteps = react.useRef(/* @__PURE__ */ new Set());
|
|
525
530
|
const activeRef = react.useRef(active);
|
|
526
531
|
const optionsRef = react.useRef(options);
|
|
527
532
|
optionsRef.current = options;
|
|
@@ -534,7 +539,8 @@ function useTourControls(options) {
|
|
|
534
539
|
const current = activeRef.current;
|
|
535
540
|
if (current === null) return;
|
|
536
541
|
const { onEvent, user } = optionsRef.current;
|
|
537
|
-
|
|
542
|
+
const event = { type, tourId: current.tourId, mode: current.mode };
|
|
543
|
+
onEvent?.(type === "tour_finish" /* Finish */ ? { ...event, skipped: skippedSteps.current.size } : event);
|
|
538
544
|
if (type === "tour_finish" /* Finish */ && user !== null) markOfferSeen(user.id);
|
|
539
545
|
setPaused(false);
|
|
540
546
|
setActive(null);
|
|
@@ -543,6 +549,8 @@ function useTourControls(options) {
|
|
|
543
549
|
if (!optionsRef.current.tours.some((tour) => tour.id === tourId)) return;
|
|
544
550
|
setPickerOpen(false);
|
|
545
551
|
setPaused(false);
|
|
552
|
+
skippedSteps.current = /* @__PURE__ */ new Set();
|
|
553
|
+
setSkipped(0);
|
|
546
554
|
setActive({ tourId, step: 0, mode });
|
|
547
555
|
optionsRef.current.onEvent?.({ type: "tour_start" /* Start */, tourId, mode });
|
|
548
556
|
}, [setActive]);
|
|
@@ -553,6 +561,13 @@ function useTourControls(options) {
|
|
|
553
561
|
if (tour === void 0 || current.step + 1 >= tour.steps.length) close("tour_finish" /* Finish */);
|
|
554
562
|
else setActive({ ...current, step: current.step + 1 });
|
|
555
563
|
}, [close, setActive]);
|
|
564
|
+
const skipOptional = react.useCallback(() => {
|
|
565
|
+
const current = activeRef.current;
|
|
566
|
+
if (current === null) return;
|
|
567
|
+
skippedSteps.current.add(current.step);
|
|
568
|
+
setSkipped(skippedSteps.current.size);
|
|
569
|
+
next();
|
|
570
|
+
}, [next]);
|
|
556
571
|
const back = react.useCallback(() => {
|
|
557
572
|
const current = activeRef.current;
|
|
558
573
|
if (current !== null && current.step > 0) setActive({ ...current, step: current.step - 1 });
|
|
@@ -561,13 +576,13 @@ function useTourControls(options) {
|
|
|
561
576
|
const togglePause = react.useCallback(() => setPaused((value) => !value), []);
|
|
562
577
|
const openPicker = react.useCallback(() => setPickerOpen(true), []);
|
|
563
578
|
const closePicker = react.useCallback(() => setPickerOpen(false), []);
|
|
564
|
-
return { active, paused, pickerOpen, start, next, back, end, togglePause, openPicker, closePicker };
|
|
579
|
+
return { active, paused, pickerOpen, skipped, start, next, skipOptional, back, end, togglePause, openPicker, closePicker };
|
|
565
580
|
}
|
|
566
581
|
|
|
567
582
|
// src/hooks/useTourEngine.ts
|
|
568
583
|
function useTourEngine(options) {
|
|
569
584
|
const controls = useTourControls(options);
|
|
570
|
-
const runner = useStepRunner({ ...options, active: controls.active, onSkip: controls.
|
|
585
|
+
const runner = useStepRunner({ ...options, active: controls.active, onSkip: controls.skipOptional });
|
|
571
586
|
const action = stepOf(options.tours, controls.active)?.action ?? null;
|
|
572
587
|
useTourKeys(controls);
|
|
573
588
|
useAutoAdvance(controls.active, runner.view.phase, controls.paused, options.timing.autoMs, controls.next);
|
|
@@ -750,7 +765,7 @@ function TourCaption() {
|
|
|
750
765
|
if (active === null || current === null || step === void 0) return null;
|
|
751
766
|
const missing = view.phase === "missing" /* Missing */;
|
|
752
767
|
const note = noteFor(tour);
|
|
753
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, role: "dialog", "aria-live": "polite", "aria-label": current.title, "data-testid": "tour-caption", "data-tour-id": current.id, "data-tour-step": stepIndex + 1, "data-tour-steps": current.steps.length, style: captionStyle(theme, position), children: [
|
|
768
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, role: "dialog", "aria-live": "polite", "aria-label": current.title, "data-testid": "tour-caption", "data-tour-id": current.id, "data-tour-step": stepIndex + 1, "data-tour-steps": current.steps.length, "data-tour-skipped": tour.skipped, style: captionStyle(theme, position), children: [
|
|
754
769
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: metaStyle(theme), children: formatLabel(labels.captionMeta, current.title, stepIndex + 1, current.steps.length, modeName(tour, active.mode)) }),
|
|
755
770
|
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-testid": "tour-text", children: substitute(step.text, tour.vars) }),
|
|
756
771
|
note !== "" ? /* @__PURE__ */ jsxRuntime.jsx("div", { "data-testid": "tour-note", style: noteStyle(theme), children: note }) : null,
|