@apollovisionlabs/guide-core 0.1.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/LICENSE +21 -0
- package/README.md +222 -0
- package/dist/index.cjs +540 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +175 -0
- package/dist/index.d.ts +175 -0
- package/dist/index.mjs +507 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Apollo Vision Labs
|
|
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
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# guide
|
|
2
|
+
|
|
3
|
+
`guide` is a headless React library for building in-app product tours. `@apollovisionlabs/guide-core` owns the
|
|
4
|
+
state machine, target resolution, routing, persistence and accessibility concerns, and exposes
|
|
5
|
+
them as hooks with no rendering opinion. `@apollovisionlabs/guide-mui` consumes those hooks to render a tour with
|
|
6
|
+
[MUI](https://mui.com) components (a spotlight overlay and a popover), so you get a complete tour
|
|
7
|
+
out of the box, or you can render your own UI on top of `@apollovisionlabs/guide-core` directly.
|
|
8
|
+
|
|
9
|
+
This repository includes a runnable demo. From the repo root, run `pnpm --filter demo dev` and
|
|
10
|
+
open `http://localhost:5173` to try a three-page tour end to end.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @apollovisionlabs/guide-core @apollovisionlabs/guide-mui @mui/material @emotion/react @emotion/styled
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`@apollovisionlabs/guide-mui` depends on `@apollovisionlabs/guide-core`, so both are needed to render the default UI. If you only
|
|
19
|
+
want the state machine and plan to render your own popover and spotlight, `@apollovisionlabs/guide-core` alone is
|
|
20
|
+
enough.
|
|
21
|
+
|
|
22
|
+
## Minimal example
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { GuideProvider, type Tour } from '@apollovisionlabs/guide-core'
|
|
26
|
+
import { GuideTour } from '@apollovisionlabs/guide-mui'
|
|
27
|
+
|
|
28
|
+
const tour: Tour = {
|
|
29
|
+
id: 'welcome',
|
|
30
|
+
steps: [
|
|
31
|
+
{
|
|
32
|
+
target: 'sidebar.projects',
|
|
33
|
+
title: 'Your projects',
|
|
34
|
+
body: 'Everything you create is grouped under a project.',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function App() {
|
|
40
|
+
return (
|
|
41
|
+
<GuideProvider tours={[tour]}>
|
|
42
|
+
<Sidebar />
|
|
43
|
+
<GuideTour />
|
|
44
|
+
</GuideProvider>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function Sidebar() {
|
|
49
|
+
// The target string is matched against the data-guide attribute, not a CSS selector or a ref.
|
|
50
|
+
return <nav data-guide="sidebar.projects">Projects</nav>
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Start the tour from anywhere under the provider with `useTour('welcome').start()`.
|
|
55
|
+
|
|
56
|
+
Declare tours as module constants, as above, rather than as literals built inside a component.
|
|
57
|
+
The provider compares step objects by identity, so a tour rebuilt on every render prevents the
|
|
58
|
+
missing-target policy below from ever firing.
|
|
59
|
+
|
|
60
|
+
## `GuideTour` props
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `labels` | `Partial<{ next, previous, finish, close }>` | `{ next: 'Next', previous: 'Back', finish: 'Finish', close: 'Close' }` | The popover's button labels. Defaults are English; override any subset. See "Translations". |
|
|
65
|
+
| `zIndex` | `number` | `theme.zIndex.modal` | Stacking level of the spotlight; the popover sits one above it. |
|
|
66
|
+
| `padding` | `number` | `8` | Margin, in pixels, between the highlighted element and the edge of the spotlight hole. |
|
|
67
|
+
| `radius` | `number` | `8` | Corner radius, in pixels, of the spotlight hole. |
|
|
68
|
+
|
|
69
|
+
## `GuideProvider` props
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
| --- | --- | --- | --- |
|
|
73
|
+
| `tours` | `Tour[]` | none | The tours available to `start()`. Tour ids must be unique. |
|
|
74
|
+
| `children` | `ReactNode` | none | Your application. |
|
|
75
|
+
| `navigate` | `(path: string) => void` | none | Called when a step declares a page it needs. Required for multi-page tours. |
|
|
76
|
+
| `location` | `string` | none | The current pathname, used to decide whether a step's target should be on screen. Required for multi-page tours. |
|
|
77
|
+
| `storage` | `GuideStorage` | none | Persists tour progress. See "Persistence". |
|
|
78
|
+
| `translate` | `(key: string) => string` | none | Resolves `titleKey` / `bodyKey` on steps. See "Translations". |
|
|
79
|
+
| `onEvent` | `(event: GuideEvent) => void` | none | Called for every lifecycle event. See "Events". |
|
|
80
|
+
| `onMissingTarget` | `'skip' \| 'wait' \| 'error'` | `'wait'` | Default policy when a step's target never appears. Overridable per step. |
|
|
81
|
+
| `targetTimeoutMs` | `number` | `5000` | How long to wait for a target before applying the missing-target policy. |
|
|
82
|
+
|
|
83
|
+
## Multi-page tours
|
|
84
|
+
|
|
85
|
+
A step can declare the route it belongs to and, when it isn't the current one, where to navigate:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
{
|
|
89
|
+
target: 'projects.create',
|
|
90
|
+
route: '/projects',
|
|
91
|
+
navigateTo: '/projects',
|
|
92
|
+
title: 'Create a project',
|
|
93
|
+
body: 'This step lives on another page, and you were moved here automatically.',
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`route` accepts `:param` segments and a trailing `*` wildcard, and is only used to decide whether
|
|
98
|
+
the current page already satisfies the step. `navigateTo` is the concrete path passed to
|
|
99
|
+
`navigate`; when it is omitted and `route` is a literal path (no `:` or `*`), that route is used as
|
|
100
|
+
the destination.
|
|
101
|
+
|
|
102
|
+
## Persistence
|
|
103
|
+
|
|
104
|
+
`GuideStorage` is the two-method interface the provider reads from and writes to:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
interface GuideStorage {
|
|
108
|
+
read(tourId: string): Promise<TourProgress | null>
|
|
109
|
+
write(tourId: string, progress: TourProgress): Promise<void>
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`@apollovisionlabs/guide-core` ships `createMemoryStorage()` for tests and `createBrowserStorage(namespace?)` for
|
|
114
|
+
`localStorage`. Neither talks to a server. An implementation backed by your own API looks like
|
|
115
|
+
this:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import type { GuideStorage, TourProgress } from '@apollovisionlabs/guide-core'
|
|
119
|
+
|
|
120
|
+
function createServerStorage(): GuideStorage {
|
|
121
|
+
return {
|
|
122
|
+
async read(tourId) {
|
|
123
|
+
const response = await fetch(`/api/tours/${tourId}/progress`)
|
|
124
|
+
if (!response.ok) return null
|
|
125
|
+
return (await response.json()) as TourProgress
|
|
126
|
+
},
|
|
127
|
+
async write(tourId, progress) {
|
|
128
|
+
await fetch(`/api/tours/${tourId}/progress`, {
|
|
129
|
+
method: 'PUT',
|
|
130
|
+
headers: { 'Content-Type': 'application/json' },
|
|
131
|
+
body: JSON.stringify(progress),
|
|
132
|
+
})
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Pass it as the `storage` prop. The provider reads on `start()` (unless an explicit `from` step
|
|
139
|
+
index is passed, or `resume: false` is passed) and writes whenever a running tour advances or
|
|
140
|
+
completes.
|
|
141
|
+
|
|
142
|
+
## Translations
|
|
143
|
+
|
|
144
|
+
Every step's own text is supplied by the consumer. A step can set `title` / `body` directly, or
|
|
145
|
+
`titleKey` / `bodyKey` plus a `translate` function on `GuideProvider`; the key is passed through
|
|
146
|
+
your translation library and the result is displayed. When a key is set without a `translate`
|
|
147
|
+
prop, the raw key is shown instead, so wiring `translate` is required for `titleKey` / `bodyKey`
|
|
148
|
+
to resolve to real strings.
|
|
149
|
+
|
|
150
|
+
The popover's own chrome is the one exception: `@apollovisionlabs/guide-mui` ships English default labels
|
|
151
|
+
(`Next`, `Back`, `Finish`, `Close`), so the buttons read correctly out of the box. Every one of
|
|
152
|
+
them is overridable through the `labels` prop on `GuideTour`: pass the labels in your language
|
|
153
|
+
and nothing English remains:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
<GuideTour labels={{ next: 'Suivant', previous: 'Retour', finish: 'Terminer', close: 'Fermer' }} />
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Events
|
|
160
|
+
|
|
161
|
+
`onEvent` on `GuideProvider` receives every lifecycle event as a discriminated union:
|
|
162
|
+
|
|
163
|
+
| Event | Payload | When |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| `tour:start` | `{ tourId, stepIndex }` | `start()` is called. |
|
|
166
|
+
| `tour:complete` | `{ tourId }` | `next()` is called on the last step. |
|
|
167
|
+
| `tour:stop` | `{ tourId, stepIndex }` | The tour is stopped before completion. |
|
|
168
|
+
| `step:show` | `{ tourId, stepIndex, target }` | A step's target is resolved and the step becomes visible. |
|
|
169
|
+
| `target:missing` | `{ tourId, stepIndex, target }` | A step's target didn't appear within `targetTimeoutMs`. |
|
|
170
|
+
|
|
171
|
+
## Accessibility
|
|
172
|
+
|
|
173
|
+
- The current step position is announced through a visually-hidden `aria-live="polite"` region,
|
|
174
|
+
so screen reader users hear "2 / 4" as the tour advances.
|
|
175
|
+
- The step popover traps keyboard focus and is exposed as `role="dialog"` with
|
|
176
|
+
`aria-labelledby` / `aria-describedby`, except for a step marked `interactive: true`, which
|
|
177
|
+
deliberately does **not** trap focus, so the user can tab or click past the popover to reach the
|
|
178
|
+
element they're asked to interact with.
|
|
179
|
+
- `Escape` stops the tour, `ArrowRight` advances, `ArrowLeft` goes back. All three are ignored
|
|
180
|
+
while focus is in a text input, so typing isn't hijacked.
|
|
181
|
+
- The highlighted element receives `aria-describedby`, pointing at the step's body text.
|
|
182
|
+
- The spotlight respects `prefers-reduced-motion` and disables its transition when set.
|
|
183
|
+
|
|
184
|
+
## Missing targets
|
|
185
|
+
|
|
186
|
+
Each step is checked against its `target` (matched by a `data-guide` attribute) for up to
|
|
187
|
+
`targetTimeoutMs` (default 5 seconds, per-provider). If the target never appears, the step's own
|
|
188
|
+
`onMissingTarget` (or the provider's `onMissingTarget`, which defaults to `'wait'`) decides what
|
|
189
|
+
happens: `'skip'` moves to the next step, `'error'` stops the tour, and `'wait'` (the default)
|
|
190
|
+
pauses and resumes automatically if the target appears later, for instance after a slow async
|
|
191
|
+
render.
|
|
192
|
+
|
|
193
|
+
## Compatibility
|
|
194
|
+
|
|
195
|
+
| | Supported |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| React | 19 |
|
|
198
|
+
| MUI (`@apollovisionlabs/guide-mui` only) | 7, 9 |
|
|
199
|
+
| Rendering | ESM and CommonJS, with `"use client"` for Next's App Router |
|
|
200
|
+
|
|
201
|
+
## Prior art
|
|
202
|
+
|
|
203
|
+
The spotlight-and-popover approach is inspired by [driver.js](https://driverjs.com) (MIT), as are
|
|
204
|
+
[react-joyride](https://github.com/gilbarbara/react-joyride) (MIT) and
|
|
205
|
+
[reactour](https://github.com/elrumordelaluz/reactour) (MIT). `guide` differs from all three mainly
|
|
206
|
+
in splitting the state machine (`@apollovisionlabs/guide-core`) from rendering (`@apollovisionlabs/guide-mui`), so the logic can be
|
|
207
|
+
reused with a different design system. Contributors must also read the licence discipline in
|
|
208
|
+
`CONTRIBUTING.md` before looking at any other tour library.
|
|
209
|
+
|
|
210
|
+
## Documentation
|
|
211
|
+
|
|
212
|
+
This file is the public API reference. Everything else lives in the repository:
|
|
213
|
+
|
|
214
|
+
- [`ARCHITECTURE.md`](ARCHITECTURE.md): how the packages are layered and how the mechanisms work.
|
|
215
|
+
- [`CONTRIBUTING.md`](CONTRIBUTING.md): prerequisites, commands, conventions, licence discipline.
|
|
216
|
+
- [`INFRA.md`](INFRA.md): build, continuous integration, and the state of the release path.
|
|
217
|
+
- [`SECURITY.md`](SECURITY.md): reporting, supported versions, what the packages touch.
|
|
218
|
+
- [`docs/index.md`](docs/index.md): the full documentation map: playbooks, decisions, references.
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
MIT. See [LICENSE](LICENSE).
|