@dloizides/ui-tour 0.0.0-stage → 1.0.1

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 ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1
4
+
5
+ - Show me and Auto clicks reach the control a real pointer would hit: a React Native Web switch or checkbox wrapper now toggles its input instead of swallowing the click.
6
+
7
+ ## 1.0.0
8
+
9
+ - First release: `TourProvider`, `useTour`, `TourPicker`, `FirstRunOffer`, `validateTours`, `findTarget`, `isForbiddenClick`.
10
+ - Guide me, Show me and Auto modes; write controls (Save, Submit, Approve, Reject, Delete, Reset, Pay, Send) are never clicked.
11
+ - Route changes through the app's `navigate`; a reload resumes the same step from sessionStorage.
12
+ - All colours, radius and font come from the `theme` prop; all text from the `labels` prop.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dloizides
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
- # Temporary Holding Version
1
+ # @dloizides/ui-tour
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ In-app guided tours for React Native Web apps. Three modes:
4
+
5
+ - **Guide me**: the page is dimmed, the target is ringed, the user clicks it (or presses Next / Right arrow).
6
+ - **Show me**: a themed cursor moves to the target and clicks or types by itself, then waits for Next.
7
+ - **Auto**: like Show me, and advances on its own every 2 s; Space pauses.
8
+
9
+ Write controls (Save, Submit, Approve, Reject, Delete, Reset, Pay, Send) are never clicked. Only a tour flagged `allowSave`, in an app that passes `allowWrites`, may press a plain "Save".
10
+
11
+ Web only. On native (`Platform.OS !== 'web'`) the provider renders its children and the tour API does nothing.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @dloizides/ui-tour
17
+ ```
18
+
19
+ Peers: `react`, `react-dom`, `react-native` (with `react-native-web`).
20
+
21
+ ## Quick start
22
+
23
+ ```tsx
24
+ import { FirstRunOffer, StepAction, TargetRole, TourPicker, TourProvider, validateTours } from '@dloizides/ui-tour';
25
+ import type { Tour } from '@dloizides/ui-tour';
26
+
27
+ const tours: Tour[] = [
28
+ {
29
+ id: 'payees',
30
+ title: 'Add a payee',
31
+ category: 'Payments',
32
+ steps: [
33
+ { route: '/payees', target: 'payees-add-button', text: 'Open the new payee form', action: StepAction.Click },
34
+ { target: { role: TargetRole.Field, name: 'Name' }, text: 'Type the payee name', action: StepAction.Type, value: 'Demo Payee' },
35
+ ],
36
+ },
37
+ ];
38
+
39
+ validateTours(tours);
40
+
41
+ <TourProvider tours={tours} navigate={router.push} theme={tourTheme} user={user} onEvent={trackTourEvent} labels={tourLabels}>
42
+ <App />
43
+ <TourPicker />
44
+ <FirstRunOffer />
45
+ </TourProvider>;
46
+ ```
47
+
48
+ Open the picker from a Help menu with `useTour().openPicker()`; F2 opens it anywhere.
49
+
50
+ ## API
51
+
52
+ | Export | What it is |
53
+ |---|---|
54
+ | `TourProvider` | `tours`, `navigate`, `theme`, `onEvent?`, `user?`, `labels?`, `allowWrites?`, `vars?`, `timing?`, `getPathname?`, `children` |
55
+ | `useTour()` | `start(tourId, mode)`, `next`, `back`, `end`, `togglePause`, `openPicker`, `closePicker`, `active`, `pickerOpen`, `tours` |
56
+ | `TourPicker` | Tours grouped by category, collapsible, step count, Guide me / Show me / Auto per tour; focus starts on the first tour |
57
+ | `FirstRunOffer` | `tourId?`, `mode?`: a dismissible card shown once per user; dismissing or finishing a tour hides it for good |
58
+ | `validateTours(tours)` | `{ valid, errors[] }`: every step needs a target and text; type steps need a value; ids are unique |
59
+ | `findTarget`, `isForbiddenClick` | The element finder and the write-control rule used by the engine |
60
+ | `defaultTourLabels`, `formatLabel` | English defaults; pass translated `labels` (placeholders `{{p1}}`, `{{p2}}`) |
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`.
63
+
64
+ ### Theme
65
+
66
+ Every colour comes from the `theme` prop; map it from your design tokens or tenant theme:
67
+
68
+ `accent`, `onAccent`, `surface`, `onSurface`, `muted`, `scrim`, `divider`, `radius`, `fontFamily`.
69
+
70
+ ### Events
71
+
72
+ `onEvent({ type, tourId, mode })` with `type` one of `tour_start`, `tour_finish`, `tour_quit`. No personal data is sent.
73
+
74
+ ### Routes and reload
75
+
76
+ Steps with a `route` call your `navigate` (never a full page load). The tour state lives in `sessionStorage`, so a reload resumes the same step. A missing target is awaited for 8 s; an `optional` step is then skipped, a required one shows "This step isn't available here" with Skip and End.
77
+
78
+ ## License
79
+
80
+ MIT
@@ -0,0 +1,208 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+
3
+ interface TourLabels {
4
+ pickerTitle: string;
5
+ pickerIntro: string;
6
+ groupTitle: string;
7
+ close: string;
8
+ guideMe: string;
9
+ showMe: string;
10
+ auto: string;
11
+ stepCount: string;
12
+ captionMeta: string;
13
+ modeGuide: string;
14
+ modeShow: string;
15
+ modeAuto: string;
16
+ back: string;
17
+ next: string;
18
+ skip: string;
19
+ end: string;
20
+ unavailable: string;
21
+ refused: string;
22
+ paused: string;
23
+ autoPlaying: string;
24
+ guideHint: string;
25
+ continueHint: string;
26
+ offerTitle: string;
27
+ offerBody: string;
28
+ offerStart: string;
29
+ offerDismiss: string;
30
+ }
31
+ declare const defaultTourLabels: TourLabels;
32
+ declare function formatLabel(template: string, ...params: Array<string | number>): string;
33
+
34
+ declare enum StepAction {
35
+ Click = "click",
36
+ Type = "type",
37
+ None = "none"
38
+ }
39
+
40
+ declare enum StepPhase {
41
+ Idle = "idle",
42
+ Loading = "loading",
43
+ Ready = "ready",
44
+ Missing = "missing",
45
+ Refused = "refused"
46
+ }
47
+
48
+ declare enum TargetRole {
49
+ Button = "button",
50
+ Heading = "heading",
51
+ Group = "group",
52
+ Field = "field",
53
+ Text = "text"
54
+ }
55
+
56
+ declare enum TourEventType {
57
+ Start = "tour_start",
58
+ Finish = "tour_finish",
59
+ Quit = "tour_quit"
60
+ }
61
+
62
+ declare enum TourMode {
63
+ Guide = "guide",
64
+ Show = "show",
65
+ Auto = "auto"
66
+ }
67
+
68
+ interface RoleTarget {
69
+ role: TargetRole;
70
+ name: string | RegExp;
71
+ nth?: number;
72
+ exact?: boolean;
73
+ within?: string;
74
+ }
75
+ type StepTarget = string | RoleTarget;
76
+ interface TourStep {
77
+ route?: string;
78
+ target: StepTarget;
79
+ text: string;
80
+ action: StepAction;
81
+ value?: string;
82
+ optional?: boolean;
83
+ wait?: number;
84
+ }
85
+ interface Tour {
86
+ id: string;
87
+ title: string;
88
+ category: string;
89
+ persona?: string;
90
+ allowSave?: boolean;
91
+ steps: TourStep[];
92
+ }
93
+ interface TourEvent {
94
+ type: TourEventType;
95
+ tourId: string;
96
+ mode: TourMode;
97
+ }
98
+ interface TourUser {
99
+ id: string;
100
+ }
101
+ type TourVars = Record<string, string | undefined>;
102
+ interface TourTheme {
103
+ accent: string;
104
+ onAccent: string;
105
+ surface: string;
106
+ onSurface: string;
107
+ muted: string;
108
+ scrim: string;
109
+ divider: string;
110
+ radius: number;
111
+ fontFamily: string;
112
+ }
113
+ interface TourTiming {
114
+ autoMs: number;
115
+ waitMs: number;
116
+ cursorMs: number;
117
+ typeMs: number;
118
+ guideAdvanceMs: number;
119
+ }
120
+ interface ActiveTour {
121
+ tourId: string;
122
+ step: number;
123
+ mode: TourMode;
124
+ }
125
+ interface Point {
126
+ x: number;
127
+ y: number;
128
+ }
129
+ interface TargetRect {
130
+ left: number;
131
+ top: number;
132
+ width: number;
133
+ height: number;
134
+ }
135
+ interface StepView {
136
+ phase: StepPhase;
137
+ rect: TargetRect | null;
138
+ refusedName: string;
139
+ }
140
+
141
+ interface TourProviderProps {
142
+ tours: readonly Tour[];
143
+ navigate: (route: string) => void;
144
+ theme: TourTheme;
145
+ onEvent?: (event: TourEvent) => void;
146
+ user?: TourUser | null;
147
+ labels?: Partial<TourLabels>;
148
+ allowWrites?: boolean;
149
+ vars?: TourVars;
150
+ timing?: Partial<TourTiming>;
151
+ getPathname?: () => string;
152
+ children?: ReactNode;
153
+ }
154
+ /** Runs guided tours over the app (web only); on native it renders children and the tour API does nothing. */
155
+ declare function TourProvider(props: TourProviderProps): ReactElement;
156
+
157
+ /** Tour list grouped by category; opens from `openPicker()` or F2, focus lands on the first tour. */
158
+ declare function TourPicker(): ReactElement | null;
159
+
160
+ interface FirstRunOfferProps {
161
+ tourId?: string;
162
+ mode?: TourMode;
163
+ }
164
+ /** Dismissible "take a tour" card, shown once per signed-in user; starts `tourId` or opens the picker. */
165
+ declare function FirstRunOffer({ tourId, mode }: FirstRunOfferProps): ReactElement | null;
166
+
167
+ interface TourControls {
168
+ active: ActiveTour | null;
169
+ paused: boolean;
170
+ pickerOpen: boolean;
171
+ start: (tourId: string, mode: TourMode) => void;
172
+ next: () => void;
173
+ back: () => void;
174
+ end: () => void;
175
+ togglePause: () => void;
176
+ openPicker: () => void;
177
+ closePicker: () => void;
178
+ }
179
+
180
+ interface TourContextValue extends TourControls {
181
+ tours: readonly Tour[];
182
+ theme: TourTheme;
183
+ labels: TourLabels;
184
+ user: TourUser | null;
185
+ vars: TourVars;
186
+ view: StepView;
187
+ cursor: Point | null;
188
+ ripple: Point | null;
189
+ }
190
+ /** Returns the tour controls and state; must be called inside `TourProvider`. */
191
+ declare function useTour(): TourContextValue;
192
+
193
+ interface TourValidation {
194
+ valid: boolean;
195
+ errors: string[];
196
+ }
197
+ /** Checks tour data and lists every problem found; `valid` is true only when the list is empty. */
198
+ declare function validateTours(tours: readonly Tour[]): TourValidation;
199
+
200
+ /** Finds the first visible element for a step target: a testID string or a role and accessible name. */
201
+ declare function findTarget(target: StepTarget, vars?: TourVars): Element | null;
202
+
203
+ /** True when a control's accessible name marks it as a write action the tour must never click. */
204
+ declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
205
+
206
+ declare const DEFAULT_TIMING: TourTiming;
207
+
208
+ export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, formatLabel, isForbiddenClick, useTour, validateTours };
@@ -0,0 +1,208 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+
3
+ interface TourLabels {
4
+ pickerTitle: string;
5
+ pickerIntro: string;
6
+ groupTitle: string;
7
+ close: string;
8
+ guideMe: string;
9
+ showMe: string;
10
+ auto: string;
11
+ stepCount: string;
12
+ captionMeta: string;
13
+ modeGuide: string;
14
+ modeShow: string;
15
+ modeAuto: string;
16
+ back: string;
17
+ next: string;
18
+ skip: string;
19
+ end: string;
20
+ unavailable: string;
21
+ refused: string;
22
+ paused: string;
23
+ autoPlaying: string;
24
+ guideHint: string;
25
+ continueHint: string;
26
+ offerTitle: string;
27
+ offerBody: string;
28
+ offerStart: string;
29
+ offerDismiss: string;
30
+ }
31
+ declare const defaultTourLabels: TourLabels;
32
+ declare function formatLabel(template: string, ...params: Array<string | number>): string;
33
+
34
+ declare enum StepAction {
35
+ Click = "click",
36
+ Type = "type",
37
+ None = "none"
38
+ }
39
+
40
+ declare enum StepPhase {
41
+ Idle = "idle",
42
+ Loading = "loading",
43
+ Ready = "ready",
44
+ Missing = "missing",
45
+ Refused = "refused"
46
+ }
47
+
48
+ declare enum TargetRole {
49
+ Button = "button",
50
+ Heading = "heading",
51
+ Group = "group",
52
+ Field = "field",
53
+ Text = "text"
54
+ }
55
+
56
+ declare enum TourEventType {
57
+ Start = "tour_start",
58
+ Finish = "tour_finish",
59
+ Quit = "tour_quit"
60
+ }
61
+
62
+ declare enum TourMode {
63
+ Guide = "guide",
64
+ Show = "show",
65
+ Auto = "auto"
66
+ }
67
+
68
+ interface RoleTarget {
69
+ role: TargetRole;
70
+ name: string | RegExp;
71
+ nth?: number;
72
+ exact?: boolean;
73
+ within?: string;
74
+ }
75
+ type StepTarget = string | RoleTarget;
76
+ interface TourStep {
77
+ route?: string;
78
+ target: StepTarget;
79
+ text: string;
80
+ action: StepAction;
81
+ value?: string;
82
+ optional?: boolean;
83
+ wait?: number;
84
+ }
85
+ interface Tour {
86
+ id: string;
87
+ title: string;
88
+ category: string;
89
+ persona?: string;
90
+ allowSave?: boolean;
91
+ steps: TourStep[];
92
+ }
93
+ interface TourEvent {
94
+ type: TourEventType;
95
+ tourId: string;
96
+ mode: TourMode;
97
+ }
98
+ interface TourUser {
99
+ id: string;
100
+ }
101
+ type TourVars = Record<string, string | undefined>;
102
+ interface TourTheme {
103
+ accent: string;
104
+ onAccent: string;
105
+ surface: string;
106
+ onSurface: string;
107
+ muted: string;
108
+ scrim: string;
109
+ divider: string;
110
+ radius: number;
111
+ fontFamily: string;
112
+ }
113
+ interface TourTiming {
114
+ autoMs: number;
115
+ waitMs: number;
116
+ cursorMs: number;
117
+ typeMs: number;
118
+ guideAdvanceMs: number;
119
+ }
120
+ interface ActiveTour {
121
+ tourId: string;
122
+ step: number;
123
+ mode: TourMode;
124
+ }
125
+ interface Point {
126
+ x: number;
127
+ y: number;
128
+ }
129
+ interface TargetRect {
130
+ left: number;
131
+ top: number;
132
+ width: number;
133
+ height: number;
134
+ }
135
+ interface StepView {
136
+ phase: StepPhase;
137
+ rect: TargetRect | null;
138
+ refusedName: string;
139
+ }
140
+
141
+ interface TourProviderProps {
142
+ tours: readonly Tour[];
143
+ navigate: (route: string) => void;
144
+ theme: TourTheme;
145
+ onEvent?: (event: TourEvent) => void;
146
+ user?: TourUser | null;
147
+ labels?: Partial<TourLabels>;
148
+ allowWrites?: boolean;
149
+ vars?: TourVars;
150
+ timing?: Partial<TourTiming>;
151
+ getPathname?: () => string;
152
+ children?: ReactNode;
153
+ }
154
+ /** Runs guided tours over the app (web only); on native it renders children and the tour API does nothing. */
155
+ declare function TourProvider(props: TourProviderProps): ReactElement;
156
+
157
+ /** Tour list grouped by category; opens from `openPicker()` or F2, focus lands on the first tour. */
158
+ declare function TourPicker(): ReactElement | null;
159
+
160
+ interface FirstRunOfferProps {
161
+ tourId?: string;
162
+ mode?: TourMode;
163
+ }
164
+ /** Dismissible "take a tour" card, shown once per signed-in user; starts `tourId` or opens the picker. */
165
+ declare function FirstRunOffer({ tourId, mode }: FirstRunOfferProps): ReactElement | null;
166
+
167
+ interface TourControls {
168
+ active: ActiveTour | null;
169
+ paused: boolean;
170
+ pickerOpen: boolean;
171
+ start: (tourId: string, mode: TourMode) => void;
172
+ next: () => void;
173
+ back: () => void;
174
+ end: () => void;
175
+ togglePause: () => void;
176
+ openPicker: () => void;
177
+ closePicker: () => void;
178
+ }
179
+
180
+ interface TourContextValue extends TourControls {
181
+ tours: readonly Tour[];
182
+ theme: TourTheme;
183
+ labels: TourLabels;
184
+ user: TourUser | null;
185
+ vars: TourVars;
186
+ view: StepView;
187
+ cursor: Point | null;
188
+ ripple: Point | null;
189
+ }
190
+ /** Returns the tour controls and state; must be called inside `TourProvider`. */
191
+ declare function useTour(): TourContextValue;
192
+
193
+ interface TourValidation {
194
+ valid: boolean;
195
+ errors: string[];
196
+ }
197
+ /** Checks tour data and lists every problem found; `valid` is true only when the list is empty. */
198
+ declare function validateTours(tours: readonly Tour[]): TourValidation;
199
+
200
+ /** Finds the first visible element for a step target: a testID string or a role and accessible name. */
201
+ declare function findTarget(target: StepTarget, vars?: TourVars): Element | null;
202
+
203
+ /** True when a control's accessible name marks it as a write action the tour must never click. */
204
+ declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
205
+
206
+ declare const DEFAULT_TIMING: TourTiming;
207
+
208
+ export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, formatLabel, isForbiddenClick, useTour, validateTours };