@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/dist/index.d.cts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Rect {
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
type MissingTargetPolicy = 'skip' | 'wait' | 'error';
|
|
11
|
+
type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
12
|
+
interface Step {
|
|
13
|
+
/** Logical key carried by the data-guide attribute on the targeted element. */
|
|
14
|
+
target: string;
|
|
15
|
+
/** Route pattern on which the step is valid. Accepts :param and *. */
|
|
16
|
+
route?: string;
|
|
17
|
+
/** Concrete path to navigate to. Defaults to route when route is literal. */
|
|
18
|
+
navigateTo?: string;
|
|
19
|
+
placement?: Placement;
|
|
20
|
+
/** Lets the user interact with the page during the step. */
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
title?: string;
|
|
23
|
+
titleKey?: string;
|
|
24
|
+
body?: string;
|
|
25
|
+
bodyKey?: string;
|
|
26
|
+
/** Overrides the global policy for this step. */
|
|
27
|
+
onMissingTarget?: MissingTargetPolicy;
|
|
28
|
+
}
|
|
29
|
+
interface Tour {
|
|
30
|
+
id: string;
|
|
31
|
+
steps: Step[];
|
|
32
|
+
}
|
|
33
|
+
type TourStatus = 'idle' | 'running' | 'paused' | 'completed';
|
|
34
|
+
interface TourProgress {
|
|
35
|
+
status: 'in-progress' | 'completed';
|
|
36
|
+
stepIndex: number;
|
|
37
|
+
}
|
|
38
|
+
interface GuideStorage {
|
|
39
|
+
read(tourId: string): Promise<TourProgress | null>;
|
|
40
|
+
write(tourId: string, progress: TourProgress): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
type GuideEvent = {
|
|
43
|
+
type: 'tour:start';
|
|
44
|
+
tourId: string;
|
|
45
|
+
stepIndex: number;
|
|
46
|
+
} | {
|
|
47
|
+
type: 'tour:complete';
|
|
48
|
+
tourId: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'tour:stop';
|
|
51
|
+
tourId: string;
|
|
52
|
+
stepIndex: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'step:show';
|
|
55
|
+
tourId: string;
|
|
56
|
+
stepIndex: number;
|
|
57
|
+
target: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'target:missing';
|
|
60
|
+
tourId: string;
|
|
61
|
+
stepIndex: number;
|
|
62
|
+
target: string;
|
|
63
|
+
};
|
|
64
|
+
type Translate = (key: string) => string;
|
|
65
|
+
|
|
66
|
+
declare function createMemoryStorage(initial?: Record<string, TourProgress>): GuideStorage;
|
|
67
|
+
declare function createBrowserStorage(namespace?: string): GuideStorage;
|
|
68
|
+
|
|
69
|
+
declare function isLiteralRoute(pattern: string): boolean;
|
|
70
|
+
declare function matchRoute(pattern: string, pathname: string): boolean;
|
|
71
|
+
|
|
72
|
+
interface TourState {
|
|
73
|
+
tourId: string | null;
|
|
74
|
+
stepIndex: number;
|
|
75
|
+
status: TourStatus;
|
|
76
|
+
}
|
|
77
|
+
type TourAction = {
|
|
78
|
+
type: 'START';
|
|
79
|
+
tourId: string;
|
|
80
|
+
stepIndex: number;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'NEXT';
|
|
83
|
+
stepCount: number;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'PREVIOUS';
|
|
86
|
+
} | {
|
|
87
|
+
type: 'PAUSE';
|
|
88
|
+
} | {
|
|
89
|
+
type: 'RESUME';
|
|
90
|
+
} | {
|
|
91
|
+
type: 'STOP';
|
|
92
|
+
};
|
|
93
|
+
declare const initialTourState: TourState;
|
|
94
|
+
declare function tourReducer(state: TourState, action: TourAction): TourState;
|
|
95
|
+
|
|
96
|
+
interface UseTargetElementOptions {
|
|
97
|
+
timeoutMs?: number;
|
|
98
|
+
attribute?: string;
|
|
99
|
+
}
|
|
100
|
+
declare function useTargetElement(target: string | null, options?: UseTargetElementOptions): {
|
|
101
|
+
element: HTMLElement | null;
|
|
102
|
+
timedOut: boolean;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
declare function useElementRect(element: HTMLElement | null): Rect | null;
|
|
106
|
+
|
|
107
|
+
interface UseFocusTrapOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Element that receives focus on entry. 'first' takes the first focusable element; 'container'
|
|
110
|
+
* takes the container itself, which must then carry tabIndex={-1}. Defaults to 'first'.
|
|
111
|
+
*/
|
|
112
|
+
initialFocus?: 'first' | 'container';
|
|
113
|
+
}
|
|
114
|
+
declare function useFocusTrap(container: HTMLElement | null, active: boolean, options?: UseFocusTrapOptions): void;
|
|
115
|
+
declare function useAnnouncer(): (message: string) => void;
|
|
116
|
+
declare function usePrefersReducedMotion(): boolean;
|
|
117
|
+
|
|
118
|
+
interface ActiveStep {
|
|
119
|
+
tourId: string;
|
|
120
|
+
step: Step;
|
|
121
|
+
stepIndex: number;
|
|
122
|
+
stepCount: number;
|
|
123
|
+
element: HTMLElement | null;
|
|
124
|
+
rect: Rect | null;
|
|
125
|
+
title: string;
|
|
126
|
+
body: string;
|
|
127
|
+
isFirst: boolean;
|
|
128
|
+
isLast: boolean;
|
|
129
|
+
next: () => void;
|
|
130
|
+
previous: () => void;
|
|
131
|
+
stop: () => void;
|
|
132
|
+
}
|
|
133
|
+
interface GuideContextValue {
|
|
134
|
+
state: TourState;
|
|
135
|
+
activeStep: ActiveStep | null;
|
|
136
|
+
start: (tourId: string, options?: {
|
|
137
|
+
from?: number;
|
|
138
|
+
resume?: boolean;
|
|
139
|
+
}) => Promise<void>;
|
|
140
|
+
next: () => void;
|
|
141
|
+
previous: () => void;
|
|
142
|
+
stop: () => void;
|
|
143
|
+
}
|
|
144
|
+
declare const GuideContext: react.Context<GuideContextValue | null>;
|
|
145
|
+
interface GuideProviderProps {
|
|
146
|
+
tours: Tour[];
|
|
147
|
+
children: ReactNode;
|
|
148
|
+
navigate?: (path: string) => void;
|
|
149
|
+
location?: string;
|
|
150
|
+
storage?: GuideStorage;
|
|
151
|
+
translate?: Translate;
|
|
152
|
+
onEvent?: (event: GuideEvent) => void;
|
|
153
|
+
onMissingTarget?: MissingTargetPolicy;
|
|
154
|
+
targetTimeoutMs?: number;
|
|
155
|
+
}
|
|
156
|
+
declare function GuideProvider({ tours, children, navigate, location, storage, translate, onEvent, onMissingTarget, targetTimeoutMs, }: GuideProviderProps): react.JSX.Element;
|
|
157
|
+
|
|
158
|
+
interface UseTourResult {
|
|
159
|
+
start: (options?: {
|
|
160
|
+
from?: number;
|
|
161
|
+
resume?: boolean;
|
|
162
|
+
}) => Promise<void>;
|
|
163
|
+
next: () => void;
|
|
164
|
+
previous: () => void;
|
|
165
|
+
stop: () => void;
|
|
166
|
+
status: TourStatus;
|
|
167
|
+
stepIndex: number;
|
|
168
|
+
}
|
|
169
|
+
declare function useTour(tourId: string): UseTourResult;
|
|
170
|
+
|
|
171
|
+
declare function findMissingTargets(tour: Tour, location: string | undefined, attribute?: string): string[];
|
|
172
|
+
|
|
173
|
+
declare function useGuideStep(): ActiveStep | null;
|
|
174
|
+
|
|
175
|
+
export { type ActiveStep, GuideContext, type GuideContextValue, type GuideEvent, GuideProvider, type GuideProviderProps, type GuideStorage, type MissingTargetPolicy, type Placement, type Rect, type Step, type Tour, type TourAction, type TourProgress, type TourState, type TourStatus, type Translate, type UseFocusTrapOptions, type UseTargetElementOptions, type UseTourResult, createBrowserStorage, createMemoryStorage, findMissingTargets, initialTourState, isLiteralRoute, matchRoute, tourReducer, useAnnouncer, useElementRect, useFocusTrap, useGuideStep, usePrefersReducedMotion, useTargetElement, useTour };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Rect {
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
type MissingTargetPolicy = 'skip' | 'wait' | 'error';
|
|
11
|
+
type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
12
|
+
interface Step {
|
|
13
|
+
/** Logical key carried by the data-guide attribute on the targeted element. */
|
|
14
|
+
target: string;
|
|
15
|
+
/** Route pattern on which the step is valid. Accepts :param and *. */
|
|
16
|
+
route?: string;
|
|
17
|
+
/** Concrete path to navigate to. Defaults to route when route is literal. */
|
|
18
|
+
navigateTo?: string;
|
|
19
|
+
placement?: Placement;
|
|
20
|
+
/** Lets the user interact with the page during the step. */
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
title?: string;
|
|
23
|
+
titleKey?: string;
|
|
24
|
+
body?: string;
|
|
25
|
+
bodyKey?: string;
|
|
26
|
+
/** Overrides the global policy for this step. */
|
|
27
|
+
onMissingTarget?: MissingTargetPolicy;
|
|
28
|
+
}
|
|
29
|
+
interface Tour {
|
|
30
|
+
id: string;
|
|
31
|
+
steps: Step[];
|
|
32
|
+
}
|
|
33
|
+
type TourStatus = 'idle' | 'running' | 'paused' | 'completed';
|
|
34
|
+
interface TourProgress {
|
|
35
|
+
status: 'in-progress' | 'completed';
|
|
36
|
+
stepIndex: number;
|
|
37
|
+
}
|
|
38
|
+
interface GuideStorage {
|
|
39
|
+
read(tourId: string): Promise<TourProgress | null>;
|
|
40
|
+
write(tourId: string, progress: TourProgress): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
type GuideEvent = {
|
|
43
|
+
type: 'tour:start';
|
|
44
|
+
tourId: string;
|
|
45
|
+
stepIndex: number;
|
|
46
|
+
} | {
|
|
47
|
+
type: 'tour:complete';
|
|
48
|
+
tourId: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'tour:stop';
|
|
51
|
+
tourId: string;
|
|
52
|
+
stepIndex: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'step:show';
|
|
55
|
+
tourId: string;
|
|
56
|
+
stepIndex: number;
|
|
57
|
+
target: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'target:missing';
|
|
60
|
+
tourId: string;
|
|
61
|
+
stepIndex: number;
|
|
62
|
+
target: string;
|
|
63
|
+
};
|
|
64
|
+
type Translate = (key: string) => string;
|
|
65
|
+
|
|
66
|
+
declare function createMemoryStorage(initial?: Record<string, TourProgress>): GuideStorage;
|
|
67
|
+
declare function createBrowserStorage(namespace?: string): GuideStorage;
|
|
68
|
+
|
|
69
|
+
declare function isLiteralRoute(pattern: string): boolean;
|
|
70
|
+
declare function matchRoute(pattern: string, pathname: string): boolean;
|
|
71
|
+
|
|
72
|
+
interface TourState {
|
|
73
|
+
tourId: string | null;
|
|
74
|
+
stepIndex: number;
|
|
75
|
+
status: TourStatus;
|
|
76
|
+
}
|
|
77
|
+
type TourAction = {
|
|
78
|
+
type: 'START';
|
|
79
|
+
tourId: string;
|
|
80
|
+
stepIndex: number;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'NEXT';
|
|
83
|
+
stepCount: number;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'PREVIOUS';
|
|
86
|
+
} | {
|
|
87
|
+
type: 'PAUSE';
|
|
88
|
+
} | {
|
|
89
|
+
type: 'RESUME';
|
|
90
|
+
} | {
|
|
91
|
+
type: 'STOP';
|
|
92
|
+
};
|
|
93
|
+
declare const initialTourState: TourState;
|
|
94
|
+
declare function tourReducer(state: TourState, action: TourAction): TourState;
|
|
95
|
+
|
|
96
|
+
interface UseTargetElementOptions {
|
|
97
|
+
timeoutMs?: number;
|
|
98
|
+
attribute?: string;
|
|
99
|
+
}
|
|
100
|
+
declare function useTargetElement(target: string | null, options?: UseTargetElementOptions): {
|
|
101
|
+
element: HTMLElement | null;
|
|
102
|
+
timedOut: boolean;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
declare function useElementRect(element: HTMLElement | null): Rect | null;
|
|
106
|
+
|
|
107
|
+
interface UseFocusTrapOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Element that receives focus on entry. 'first' takes the first focusable element; 'container'
|
|
110
|
+
* takes the container itself, which must then carry tabIndex={-1}. Defaults to 'first'.
|
|
111
|
+
*/
|
|
112
|
+
initialFocus?: 'first' | 'container';
|
|
113
|
+
}
|
|
114
|
+
declare function useFocusTrap(container: HTMLElement | null, active: boolean, options?: UseFocusTrapOptions): void;
|
|
115
|
+
declare function useAnnouncer(): (message: string) => void;
|
|
116
|
+
declare function usePrefersReducedMotion(): boolean;
|
|
117
|
+
|
|
118
|
+
interface ActiveStep {
|
|
119
|
+
tourId: string;
|
|
120
|
+
step: Step;
|
|
121
|
+
stepIndex: number;
|
|
122
|
+
stepCount: number;
|
|
123
|
+
element: HTMLElement | null;
|
|
124
|
+
rect: Rect | null;
|
|
125
|
+
title: string;
|
|
126
|
+
body: string;
|
|
127
|
+
isFirst: boolean;
|
|
128
|
+
isLast: boolean;
|
|
129
|
+
next: () => void;
|
|
130
|
+
previous: () => void;
|
|
131
|
+
stop: () => void;
|
|
132
|
+
}
|
|
133
|
+
interface GuideContextValue {
|
|
134
|
+
state: TourState;
|
|
135
|
+
activeStep: ActiveStep | null;
|
|
136
|
+
start: (tourId: string, options?: {
|
|
137
|
+
from?: number;
|
|
138
|
+
resume?: boolean;
|
|
139
|
+
}) => Promise<void>;
|
|
140
|
+
next: () => void;
|
|
141
|
+
previous: () => void;
|
|
142
|
+
stop: () => void;
|
|
143
|
+
}
|
|
144
|
+
declare const GuideContext: react.Context<GuideContextValue | null>;
|
|
145
|
+
interface GuideProviderProps {
|
|
146
|
+
tours: Tour[];
|
|
147
|
+
children: ReactNode;
|
|
148
|
+
navigate?: (path: string) => void;
|
|
149
|
+
location?: string;
|
|
150
|
+
storage?: GuideStorage;
|
|
151
|
+
translate?: Translate;
|
|
152
|
+
onEvent?: (event: GuideEvent) => void;
|
|
153
|
+
onMissingTarget?: MissingTargetPolicy;
|
|
154
|
+
targetTimeoutMs?: number;
|
|
155
|
+
}
|
|
156
|
+
declare function GuideProvider({ tours, children, navigate, location, storage, translate, onEvent, onMissingTarget, targetTimeoutMs, }: GuideProviderProps): react.JSX.Element;
|
|
157
|
+
|
|
158
|
+
interface UseTourResult {
|
|
159
|
+
start: (options?: {
|
|
160
|
+
from?: number;
|
|
161
|
+
resume?: boolean;
|
|
162
|
+
}) => Promise<void>;
|
|
163
|
+
next: () => void;
|
|
164
|
+
previous: () => void;
|
|
165
|
+
stop: () => void;
|
|
166
|
+
status: TourStatus;
|
|
167
|
+
stepIndex: number;
|
|
168
|
+
}
|
|
169
|
+
declare function useTour(tourId: string): UseTourResult;
|
|
170
|
+
|
|
171
|
+
declare function findMissingTargets(tour: Tour, location: string | undefined, attribute?: string): string[];
|
|
172
|
+
|
|
173
|
+
declare function useGuideStep(): ActiveStep | null;
|
|
174
|
+
|
|
175
|
+
export { type ActiveStep, GuideContext, type GuideContextValue, type GuideEvent, GuideProvider, type GuideProviderProps, type GuideStorage, type MissingTargetPolicy, type Placement, type Rect, type Step, type Tour, type TourAction, type TourProgress, type TourState, type TourStatus, type Translate, type UseFocusTrapOptions, type UseTargetElementOptions, type UseTourResult, createBrowserStorage, createMemoryStorage, findMissingTargets, initialTourState, isLiteralRoute, matchRoute, tourReducer, useAnnouncer, useElementRect, useFocusTrap, useGuideStep, usePrefersReducedMotion, useTargetElement, useTour };
|