@korsolutions/guidon 1.0.1 → 1.0.3
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/dist/commonjs/babel.config.js +15 -0
- package/dist/commonjs/babel.config.js.map +1 -0
- package/dist/commonjs/bob.config.js +11 -0
- package/dist/commonjs/bob.config.js.map +1 -0
- package/dist/commonjs/components/GuidonOverlay.js +206 -0
- package/dist/commonjs/components/GuidonOverlay.js.map +1 -0
- package/dist/commonjs/components/GuidonProvider.js +157 -0
- package/dist/commonjs/components/GuidonProvider.js.map +1 -0
- package/dist/commonjs/components/GuidonTarget.js +110 -0
- package/dist/commonjs/components/GuidonTarget.js.map +1 -0
- package/dist/commonjs/components/GuidonTooltip.js +422 -0
- package/dist/commonjs/components/GuidonTooltip.js.map +1 -0
- package/dist/commonjs/components/index.js +40 -0
- package/dist/commonjs/components/index.js.map +1 -0
- package/dist/commonjs/hooks/index.js +13 -0
- package/dist/commonjs/hooks/index.js.map +1 -0
- package/dist/commonjs/hooks/useGuidonRef.js +132 -0
- package/dist/commonjs/hooks/useGuidonRef.js.map +1 -0
- package/dist/commonjs/index.js +143 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +1 -0
- package/dist/commonjs/persistence/adapters.js +213 -0
- package/dist/commonjs/persistence/adapters.js.map +1 -0
- package/dist/commonjs/persistence/hooks.js +153 -0
- package/dist/commonjs/persistence/hooks.js.map +1 -0
- package/dist/commonjs/persistence/index.js +28 -0
- package/dist/commonjs/persistence/index.js.map +1 -0
- package/dist/commonjs/store.js +314 -0
- package/dist/commonjs/store.js.map +1 -0
- package/dist/commonjs/tsconfig.json +32 -0
- package/dist/commonjs/types.js +6 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/module/babel.config.js +15 -0
- package/dist/module/babel.config.js.map +1 -0
- package/dist/module/bob.config.js +11 -0
- package/dist/module/bob.config.js.map +1 -0
- package/dist/module/components/GuidonOverlay.js +201 -0
- package/dist/module/components/GuidonOverlay.js.map +1 -0
- package/dist/module/components/GuidonProvider.js +152 -0
- package/dist/module/components/GuidonProvider.js.map +1 -0
- package/dist/module/components/GuidonTarget.js +106 -0
- package/dist/module/components/GuidonTarget.js.map +1 -0
- package/dist/module/components/GuidonTooltip.js +417 -0
- package/dist/module/components/GuidonTooltip.js.map +1 -0
- package/dist/module/components/index.js +7 -0
- package/dist/module/components/index.js.map +1 -0
- package/dist/module/hooks/index.js +4 -0
- package/dist/module/hooks/index.js.map +1 -0
- package/dist/module/hooks/useGuidonRef.js +129 -0
- package/dist/module/hooks/useGuidonRef.js.map +1 -0
- package/dist/module/index.js +17 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/persistence/adapters.js +203 -0
- package/dist/module/persistence/adapters.js.map +1 -0
- package/dist/module/persistence/hooks.js +148 -0
- package/dist/module/persistence/hooks.js.map +1 -0
- package/dist/module/persistence/index.js +5 -0
- package/dist/module/persistence/index.js.map +1 -0
- package/dist/module/store.js +304 -0
- package/dist/module/store.js.map +1 -0
- package/dist/module/tsconfig.json +32 -0
- package/dist/module/types.js +4 -0
- package/dist/module/types.js.map +1 -0
- package/dist/typescript/commonjs/components/GuidonOverlay.d.ts +9 -0
- package/dist/typescript/commonjs/components/GuidonOverlay.d.ts.map +1 -0
- package/dist/typescript/commonjs/components/GuidonProvider.d.ts +14 -0
- package/dist/typescript/commonjs/components/GuidonProvider.d.ts.map +1 -0
- package/dist/typescript/commonjs/components/GuidonTarget.d.ts +7 -0
- package/dist/typescript/commonjs/components/GuidonTarget.d.ts.map +1 -0
- package/dist/typescript/commonjs/components/GuidonTooltip.d.ts +24 -0
- package/dist/typescript/commonjs/components/GuidonTooltip.d.ts.map +1 -0
- package/dist/typescript/commonjs/components/index.d.ts +5 -0
- package/dist/typescript/commonjs/components/index.d.ts.map +1 -0
- package/dist/typescript/commonjs/hooks/index.d.ts +2 -0
- package/dist/typescript/commonjs/hooks/index.d.ts.map +1 -0
- package/dist/typescript/commonjs/hooks/useGuidonRef.d.ts +35 -0
- package/dist/typescript/commonjs/hooks/useGuidonRef.d.ts.map +1 -0
- package/dist/typescript/commonjs/index.d.ts +7 -0
- package/dist/typescript/commonjs/index.d.ts.map +1 -0
- package/dist/typescript/commonjs/package.json +1 -0
- package/dist/typescript/commonjs/persistence/adapters.d.ts +57 -0
- package/dist/typescript/commonjs/persistence/adapters.d.ts.map +1 -0
- package/dist/typescript/commonjs/persistence/hooks.d.ts +29 -0
- package/dist/typescript/commonjs/persistence/hooks.d.ts.map +1 -0
- package/dist/typescript/commonjs/persistence/index.d.ts +3 -0
- package/dist/typescript/commonjs/persistence/index.d.ts.map +1 -0
- package/dist/typescript/commonjs/store.d.ts +89 -0
- package/dist/typescript/commonjs/store.d.ts.map +1 -0
- package/dist/{index-D_JFvCIg.d.mts → typescript/commonjs/types.d.ts} +40 -104
- package/dist/typescript/commonjs/types.d.ts.map +1 -0
- package/dist/typescript/module/components/GuidonOverlay.d.ts +9 -0
- package/dist/typescript/module/components/GuidonOverlay.d.ts.map +1 -0
- package/dist/typescript/module/components/GuidonProvider.d.ts +14 -0
- package/dist/typescript/module/components/GuidonProvider.d.ts.map +1 -0
- package/dist/typescript/module/components/GuidonTarget.d.ts +7 -0
- package/dist/typescript/module/components/GuidonTarget.d.ts.map +1 -0
- package/dist/typescript/module/components/GuidonTooltip.d.ts +24 -0
- package/dist/typescript/module/components/GuidonTooltip.d.ts.map +1 -0
- package/dist/typescript/module/components/index.d.ts +5 -0
- package/dist/typescript/module/components/index.d.ts.map +1 -0
- package/dist/typescript/module/hooks/index.d.ts +2 -0
- package/dist/typescript/module/hooks/index.d.ts.map +1 -0
- package/dist/typescript/module/hooks/useGuidonRef.d.ts +35 -0
- package/dist/typescript/module/hooks/useGuidonRef.d.ts.map +1 -0
- package/dist/typescript/module/index.d.ts +7 -0
- package/dist/typescript/module/index.d.ts.map +1 -0
- package/dist/typescript/module/package.json +1 -0
- package/dist/typescript/module/persistence/adapters.d.ts +57 -0
- package/dist/typescript/module/persistence/adapters.d.ts.map +1 -0
- package/dist/typescript/module/persistence/hooks.d.ts +29 -0
- package/dist/typescript/module/persistence/hooks.d.ts.map +1 -0
- package/dist/typescript/module/persistence/index.d.ts +3 -0
- package/dist/typescript/module/persistence/index.d.ts.map +1 -0
- package/dist/typescript/module/store.d.ts +89 -0
- package/dist/typescript/module/store.d.ts.map +1 -0
- package/dist/{index-D_JFvCIg.d.ts → typescript/module/types.d.ts} +40 -104
- package/dist/typescript/module/types.d.ts.map +1 -0
- package/package.json +25 -13
- package/src/babel.config.js +18 -0
- package/src/bob.config.js +14 -0
- package/src/components/GuidonOverlay.tsx +60 -4
- package/src/components/GuidonProvider.tsx +29 -1
- package/src/components/GuidonTarget.tsx +41 -25
- package/src/components/GuidonTooltip.tsx +143 -9
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useGuidonRef.ts +154 -0
- package/src/index.ts +6 -0
- package/src/store.ts +68 -15
- package/src/tsconfig.json +32 -0
- package/src/types.ts +32 -2
- package/dist/index.d.mts +0 -128
- package/dist/index.d.ts +0 -128
- package/dist/index.js +0 -1097
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1072
- package/dist/index.mjs.map +0 -1
- package/dist/persistence/index.d.mts +0 -2
- package/dist/persistence/index.d.ts +0 -2
- package/dist/persistence/index.js +0 -300
- package/dist/persistence/index.js.map +0 -1
- package/dist/persistence/index.mjs +0 -291
- package/dist/persistence/index.mjs.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,1097 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
var reactNative = require('react-native');
|
|
5
|
-
var zustand = require('zustand');
|
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
var Animated = require('react-native-reanimated');
|
|
8
|
-
var Svg = require('react-native-svg');
|
|
9
|
-
var reactNativeSafeAreaContext = require('react-native-safe-area-context');
|
|
10
|
-
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
|
|
13
|
-
var Animated__default = /*#__PURE__*/_interopDefault(Animated);
|
|
14
|
-
var Svg__default = /*#__PURE__*/_interopDefault(Svg);
|
|
15
|
-
|
|
16
|
-
// src/components/GuidonTarget.tsx
|
|
17
|
-
var initialState = {
|
|
18
|
-
config: null,
|
|
19
|
-
isActive: false,
|
|
20
|
-
currentStepIndex: 0,
|
|
21
|
-
isCompleted: false,
|
|
22
|
-
targetMeasurements: {},
|
|
23
|
-
isLoading: false,
|
|
24
|
-
error: null
|
|
25
|
-
};
|
|
26
|
-
var useGuidonStore = zustand.create((set, get) => ({
|
|
27
|
-
...initialState,
|
|
28
|
-
configure: (config) => {
|
|
29
|
-
set({ config, currentStepIndex: 0, isCompleted: false });
|
|
30
|
-
},
|
|
31
|
-
start: () => {
|
|
32
|
-
const { config } = get();
|
|
33
|
-
if (!config || config.steps.length === 0) return;
|
|
34
|
-
set({ isActive: true, currentStepIndex: 0, isCompleted: false });
|
|
35
|
-
const firstStep = config.steps[0];
|
|
36
|
-
firstStep.onStepEnter?.();
|
|
37
|
-
config.onStepChange?.(0, firstStep);
|
|
38
|
-
},
|
|
39
|
-
next: () => {
|
|
40
|
-
const { config, currentStepIndex, isActive } = get();
|
|
41
|
-
if (!config || !isActive) return;
|
|
42
|
-
const currentStep = config.steps[currentStepIndex];
|
|
43
|
-
currentStep?.onStepExit?.();
|
|
44
|
-
if (currentStepIndex < config.steps.length - 1) {
|
|
45
|
-
const nextIndex = currentStepIndex + 1;
|
|
46
|
-
const nextStep = config.steps[nextIndex];
|
|
47
|
-
set({ currentStepIndex: nextIndex });
|
|
48
|
-
nextStep.onStepEnter?.();
|
|
49
|
-
config.onStepChange?.(nextIndex, nextStep);
|
|
50
|
-
} else {
|
|
51
|
-
get().complete();
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
previous: () => {
|
|
55
|
-
const { config, currentStepIndex, isActive } = get();
|
|
56
|
-
if (!config || !isActive || currentStepIndex === 0) return;
|
|
57
|
-
const currentStep = config.steps[currentStepIndex];
|
|
58
|
-
currentStep?.onStepExit?.();
|
|
59
|
-
const prevIndex = currentStepIndex - 1;
|
|
60
|
-
const prevStep = config.steps[prevIndex];
|
|
61
|
-
set({ currentStepIndex: prevIndex });
|
|
62
|
-
prevStep.onStepEnter?.();
|
|
63
|
-
config.onStepChange?.(prevIndex, prevStep);
|
|
64
|
-
},
|
|
65
|
-
goToStep: (index) => {
|
|
66
|
-
const { config, currentStepIndex, isActive } = get();
|
|
67
|
-
if (!config || !isActive) return;
|
|
68
|
-
if (index < 0 || index >= config.steps.length) return;
|
|
69
|
-
const currentStep = config.steps[currentStepIndex];
|
|
70
|
-
currentStep?.onStepExit?.();
|
|
71
|
-
const targetStep = config.steps[index];
|
|
72
|
-
set({ currentStepIndex: index });
|
|
73
|
-
targetStep.onStepEnter?.();
|
|
74
|
-
config.onStepChange?.(index, targetStep);
|
|
75
|
-
},
|
|
76
|
-
skip: () => {
|
|
77
|
-
const { config, currentStepIndex } = get();
|
|
78
|
-
if (!config) return;
|
|
79
|
-
const currentStep = config.steps[currentStepIndex];
|
|
80
|
-
currentStep?.onStepExit?.();
|
|
81
|
-
set({ isActive: false, isCompleted: false });
|
|
82
|
-
config.onSkip?.();
|
|
83
|
-
},
|
|
84
|
-
complete: () => {
|
|
85
|
-
const { config, currentStepIndex } = get();
|
|
86
|
-
if (!config) return;
|
|
87
|
-
const currentStep = config.steps[currentStepIndex];
|
|
88
|
-
currentStep?.onStepExit?.();
|
|
89
|
-
set({ isActive: false, isCompleted: true });
|
|
90
|
-
config.onComplete?.();
|
|
91
|
-
},
|
|
92
|
-
reset: () => {
|
|
93
|
-
set(initialState);
|
|
94
|
-
},
|
|
95
|
-
registerTarget: (targetId, measurements) => {
|
|
96
|
-
set((state) => ({
|
|
97
|
-
targetMeasurements: {
|
|
98
|
-
...state.targetMeasurements,
|
|
99
|
-
[targetId]: measurements
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
102
|
-
},
|
|
103
|
-
unregisterTarget: (targetId) => {
|
|
104
|
-
set((state) => {
|
|
105
|
-
const { [targetId]: _, ...rest } = state.targetMeasurements;
|
|
106
|
-
return { targetMeasurements: rest };
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
setLoading: (isLoading) => {
|
|
110
|
-
set({ isLoading });
|
|
111
|
-
},
|
|
112
|
-
setError: (error) => {
|
|
113
|
-
set({ error });
|
|
114
|
-
}
|
|
115
|
-
}));
|
|
116
|
-
var Guidon = {
|
|
117
|
-
/**
|
|
118
|
-
* Configure the walkthrough with steps and options
|
|
119
|
-
*/
|
|
120
|
-
configure: (config) => {
|
|
121
|
-
useGuidonStore.getState().configure(config);
|
|
122
|
-
},
|
|
123
|
-
/**
|
|
124
|
-
* Start the walkthrough
|
|
125
|
-
*/
|
|
126
|
-
start: () => {
|
|
127
|
-
useGuidonStore.getState().start();
|
|
128
|
-
},
|
|
129
|
-
/**
|
|
130
|
-
* Go to the next step
|
|
131
|
-
*/
|
|
132
|
-
next: () => {
|
|
133
|
-
useGuidonStore.getState().next();
|
|
134
|
-
},
|
|
135
|
-
/**
|
|
136
|
-
* Go to the previous step
|
|
137
|
-
*/
|
|
138
|
-
previous: () => {
|
|
139
|
-
useGuidonStore.getState().previous();
|
|
140
|
-
},
|
|
141
|
-
/**
|
|
142
|
-
* Go to a specific step by index
|
|
143
|
-
*/
|
|
144
|
-
goToStep: (index) => {
|
|
145
|
-
useGuidonStore.getState().goToStep(index);
|
|
146
|
-
},
|
|
147
|
-
/**
|
|
148
|
-
* Skip the walkthrough
|
|
149
|
-
*/
|
|
150
|
-
skip: () => {
|
|
151
|
-
useGuidonStore.getState().skip();
|
|
152
|
-
},
|
|
153
|
-
/**
|
|
154
|
-
* Complete the walkthrough
|
|
155
|
-
*/
|
|
156
|
-
complete: () => {
|
|
157
|
-
useGuidonStore.getState().complete();
|
|
158
|
-
},
|
|
159
|
-
/**
|
|
160
|
-
* Reset the walkthrough to initial state
|
|
161
|
-
*/
|
|
162
|
-
reset: () => {
|
|
163
|
-
useGuidonStore.getState().reset();
|
|
164
|
-
},
|
|
165
|
-
/**
|
|
166
|
-
* Check if the walkthrough is currently active
|
|
167
|
-
*/
|
|
168
|
-
isActive: () => {
|
|
169
|
-
return useGuidonStore.getState().isActive;
|
|
170
|
-
},
|
|
171
|
-
/**
|
|
172
|
-
* Check if the walkthrough has been completed
|
|
173
|
-
*/
|
|
174
|
-
isCompleted: () => {
|
|
175
|
-
return useGuidonStore.getState().isCompleted;
|
|
176
|
-
},
|
|
177
|
-
/**
|
|
178
|
-
* Get the current step index
|
|
179
|
-
*/
|
|
180
|
-
getCurrentStepIndex: () => {
|
|
181
|
-
return useGuidonStore.getState().currentStepIndex;
|
|
182
|
-
},
|
|
183
|
-
/**
|
|
184
|
-
* Get the current step
|
|
185
|
-
*/
|
|
186
|
-
getCurrentStep: () => {
|
|
187
|
-
const state = useGuidonStore.getState();
|
|
188
|
-
return state.config?.steps[state.currentStepIndex] ?? null;
|
|
189
|
-
},
|
|
190
|
-
/**
|
|
191
|
-
* Get all steps
|
|
192
|
-
*/
|
|
193
|
-
getSteps: () => {
|
|
194
|
-
return useGuidonStore.getState().config?.steps ?? [];
|
|
195
|
-
},
|
|
196
|
-
/**
|
|
197
|
-
* Subscribe to store changes
|
|
198
|
-
*/
|
|
199
|
-
subscribe: useGuidonStore.subscribe
|
|
200
|
-
};
|
|
201
|
-
var useGuidonActive = () => useGuidonStore((state) => state.isActive);
|
|
202
|
-
var useGuidonStep = () => useGuidonStore((state) => {
|
|
203
|
-
if (!state.config || !state.isActive) return null;
|
|
204
|
-
return state.config.steps[state.currentStepIndex];
|
|
205
|
-
});
|
|
206
|
-
var useGuidonProgress = () => useGuidonStore((state) => ({
|
|
207
|
-
currentStep: state.currentStepIndex + 1,
|
|
208
|
-
totalSteps: state.config?.steps.length ?? 0,
|
|
209
|
-
percentage: state.config ? (state.currentStepIndex + 1) / state.config.steps.length * 100 : 0
|
|
210
|
-
}));
|
|
211
|
-
var useTargetMeasurements = (targetId) => useGuidonStore(
|
|
212
|
-
(state) => state.targetMeasurements[targetId]
|
|
213
|
-
);
|
|
214
|
-
function GuidonTarget({
|
|
215
|
-
children,
|
|
216
|
-
targetId,
|
|
217
|
-
active = true
|
|
218
|
-
}) {
|
|
219
|
-
const viewRef = react.useRef(null);
|
|
220
|
-
const registerTarget = useGuidonStore((state) => state.registerTarget);
|
|
221
|
-
const unregisterTarget = useGuidonStore((state) => state.unregisterTarget);
|
|
222
|
-
const isActive = useGuidonStore((state) => state.isActive);
|
|
223
|
-
const config = useGuidonStore((state) => state.config);
|
|
224
|
-
const isTargetNeeded = isActive && config?.steps.some((step) => step.targetId === targetId);
|
|
225
|
-
const measureElement = react.useCallback(() => {
|
|
226
|
-
if (!viewRef.current || !active || !isTargetNeeded) return;
|
|
227
|
-
if (reactNative.Platform.OS === "web") {
|
|
228
|
-
const element = viewRef.current;
|
|
229
|
-
if (element && typeof element.getBoundingClientRect === "function") {
|
|
230
|
-
const rect = element.getBoundingClientRect();
|
|
231
|
-
const measurements = {
|
|
232
|
-
x: rect.left + window.scrollX,
|
|
233
|
-
y: rect.top + window.scrollY,
|
|
234
|
-
width: rect.width,
|
|
235
|
-
height: rect.height
|
|
236
|
-
};
|
|
237
|
-
registerTarget(targetId, measurements);
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
viewRef.current.measureInWindow((x, y, width, height) => {
|
|
241
|
-
if (width > 0 && height > 0) {
|
|
242
|
-
const measurements = { x, y, width, height };
|
|
243
|
-
registerTarget(targetId, measurements);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}, [targetId, active, isTargetNeeded, registerTarget]);
|
|
248
|
-
const handleLayout = react.useCallback(
|
|
249
|
-
(_event) => {
|
|
250
|
-
requestAnimationFrame(() => {
|
|
251
|
-
measureElement();
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
[measureElement]
|
|
255
|
-
);
|
|
256
|
-
react.useEffect(() => {
|
|
257
|
-
if (isTargetNeeded) {
|
|
258
|
-
const timer = setTimeout(() => {
|
|
259
|
-
measureElement();
|
|
260
|
-
}, 100);
|
|
261
|
-
return () => clearTimeout(timer);
|
|
262
|
-
}
|
|
263
|
-
}, [isTargetNeeded, measureElement]);
|
|
264
|
-
react.useEffect(() => {
|
|
265
|
-
if (reactNative.Platform.OS !== "web" || !isTargetNeeded) return;
|
|
266
|
-
const handleScroll = () => {
|
|
267
|
-
measureElement();
|
|
268
|
-
};
|
|
269
|
-
window.addEventListener("scroll", handleScroll, true);
|
|
270
|
-
window.addEventListener("resize", handleScroll);
|
|
271
|
-
return () => {
|
|
272
|
-
window.removeEventListener("scroll", handleScroll, true);
|
|
273
|
-
window.removeEventListener("resize", handleScroll);
|
|
274
|
-
};
|
|
275
|
-
}, [isTargetNeeded, measureElement]);
|
|
276
|
-
react.useEffect(() => {
|
|
277
|
-
return () => {
|
|
278
|
-
unregisterTarget(targetId);
|
|
279
|
-
};
|
|
280
|
-
}, [targetId, unregisterTarget]);
|
|
281
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
282
|
-
reactNative.View,
|
|
283
|
-
{
|
|
284
|
-
ref: viewRef,
|
|
285
|
-
onLayout: handleLayout,
|
|
286
|
-
collapsable: false,
|
|
287
|
-
children
|
|
288
|
-
}
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
var AnimatedSvg = Animated__default.default.createAnimatedComponent(Svg__default.default);
|
|
292
|
-
var DEFAULT_THEME = {
|
|
293
|
-
backdropColor: "#000000",
|
|
294
|
-
backdropOpacity: 0.75,
|
|
295
|
-
spotlightBorderRadius: 8,
|
|
296
|
-
spotlightPadding: 8
|
|
297
|
-
};
|
|
298
|
-
function GuidonOverlay({
|
|
299
|
-
theme = {},
|
|
300
|
-
animationDuration = 300,
|
|
301
|
-
onBackdropPress
|
|
302
|
-
}) {
|
|
303
|
-
const isActive = useGuidonStore((state) => state.isActive);
|
|
304
|
-
const config = useGuidonStore((state) => state.config);
|
|
305
|
-
const currentStepIndex = useGuidonStore((state) => state.currentStepIndex);
|
|
306
|
-
const targetMeasurements = useGuidonStore((state) => state.targetMeasurements);
|
|
307
|
-
const mergedTheme = { ...DEFAULT_THEME, ...theme };
|
|
308
|
-
const { width: screenWidth, height: screenHeight } = reactNative.Dimensions.get("window");
|
|
309
|
-
const currentStep = config?.steps[currentStepIndex];
|
|
310
|
-
const currentTargetId = currentStep?.targetId;
|
|
311
|
-
const measurements = currentTargetId ? targetMeasurements[currentTargetId] : void 0;
|
|
312
|
-
const spotlight = react.useMemo(() => {
|
|
313
|
-
if (!measurements) {
|
|
314
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
315
|
-
}
|
|
316
|
-
return {
|
|
317
|
-
x: measurements.x - mergedTheme.spotlightPadding,
|
|
318
|
-
y: measurements.y - mergedTheme.spotlightPadding,
|
|
319
|
-
width: measurements.width + mergedTheme.spotlightPadding * 2,
|
|
320
|
-
height: measurements.height + mergedTheme.spotlightPadding * 2
|
|
321
|
-
};
|
|
322
|
-
}, [measurements, mergedTheme.spotlightPadding]);
|
|
323
|
-
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
324
|
-
return {
|
|
325
|
-
opacity: Animated.withTiming(isActive && measurements ? 1 : 0, {
|
|
326
|
-
duration: animationDuration,
|
|
327
|
-
easing: Animated.Easing.inOut(Animated.Easing.ease)
|
|
328
|
-
})
|
|
329
|
-
};
|
|
330
|
-
}, [isActive, measurements, animationDuration]);
|
|
331
|
-
if (!isActive || !measurements) {
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
if (reactNative.Platform.OS === "web") {
|
|
335
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableWithoutFeedback, { onPress: onBackdropPress, children: /* @__PURE__ */ jsxRuntime.jsx(Animated__default.default.View, { style: [styles.container, animatedStyle], children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
336
|
-
"div",
|
|
337
|
-
{
|
|
338
|
-
style: {
|
|
339
|
-
position: "absolute",
|
|
340
|
-
inset: 0,
|
|
341
|
-
backgroundColor: mergedTheme.backdropColor,
|
|
342
|
-
opacity: mergedTheme.backdropOpacity,
|
|
343
|
-
clipPath: `polygon(
|
|
344
|
-
0% 0%,
|
|
345
|
-
0% 100%,
|
|
346
|
-
${spotlight.x}px 100%,
|
|
347
|
-
${spotlight.x}px ${spotlight.y}px,
|
|
348
|
-
${spotlight.x + spotlight.width}px ${spotlight.y}px,
|
|
349
|
-
${spotlight.x + spotlight.width}px ${spotlight.y + spotlight.height}px,
|
|
350
|
-
${spotlight.x}px ${spotlight.y + spotlight.height}px,
|
|
351
|
-
${spotlight.x}px 100%,
|
|
352
|
-
100% 100%,
|
|
353
|
-
100% 0%
|
|
354
|
-
)`
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
) }) });
|
|
358
|
-
}
|
|
359
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableWithoutFeedback, { onPress: onBackdropPress, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
360
|
-
AnimatedSvg,
|
|
361
|
-
{
|
|
362
|
-
style: [styles.container, animatedStyle],
|
|
363
|
-
width: screenWidth,
|
|
364
|
-
height: screenHeight,
|
|
365
|
-
viewBox: `0 0 ${screenWidth} ${screenHeight}`,
|
|
366
|
-
children: [
|
|
367
|
-
/* @__PURE__ */ jsxRuntime.jsx(Svg.Defs, { children: /* @__PURE__ */ jsxRuntime.jsxs(Svg.Mask, { id: "spotlight-mask", children: [
|
|
368
|
-
/* @__PURE__ */ jsxRuntime.jsx(Svg.Rect, { x: "0", y: "0", width: "100%", height: "100%", fill: "white" }),
|
|
369
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
370
|
-
Svg.Rect,
|
|
371
|
-
{
|
|
372
|
-
x: spotlight.x,
|
|
373
|
-
y: spotlight.y,
|
|
374
|
-
width: spotlight.width,
|
|
375
|
-
height: spotlight.height,
|
|
376
|
-
rx: mergedTheme.spotlightBorderRadius,
|
|
377
|
-
ry: mergedTheme.spotlightBorderRadius,
|
|
378
|
-
fill: "black"
|
|
379
|
-
}
|
|
380
|
-
)
|
|
381
|
-
] }) }),
|
|
382
|
-
/* @__PURE__ */ jsxRuntime.jsx(Svg.G, { mask: "url(#spotlight-mask)", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
383
|
-
Svg.Rect,
|
|
384
|
-
{
|
|
385
|
-
x: "0",
|
|
386
|
-
y: "0",
|
|
387
|
-
width: "100%",
|
|
388
|
-
height: "100%",
|
|
389
|
-
fill: mergedTheme.backdropColor,
|
|
390
|
-
fillOpacity: mergedTheme.backdropOpacity
|
|
391
|
-
}
|
|
392
|
-
) })
|
|
393
|
-
]
|
|
394
|
-
}
|
|
395
|
-
) });
|
|
396
|
-
}
|
|
397
|
-
var styles = reactNative.StyleSheet.create({
|
|
398
|
-
container: {
|
|
399
|
-
...reactNative.StyleSheet.absoluteFillObject,
|
|
400
|
-
zIndex: 999
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
var DEFAULT_THEME2 = {
|
|
404
|
-
tooltipBackgroundColor: "#ffffff",
|
|
405
|
-
tooltipBorderColor: "#e5e5e5",
|
|
406
|
-
tooltipBorderRadius: 12,
|
|
407
|
-
titleColor: "#1a1a1a",
|
|
408
|
-
descriptionColor: "#666666",
|
|
409
|
-
primaryColor: "#007AFF",
|
|
410
|
-
mutedColor: "#999999",
|
|
411
|
-
spotlightPadding: 8
|
|
412
|
-
};
|
|
413
|
-
var TOOLTIP_MARGIN = 16;
|
|
414
|
-
var TOOLTIP_WIDTH = 300;
|
|
415
|
-
function GuidonTooltip({
|
|
416
|
-
theme = {},
|
|
417
|
-
animationDuration = 300,
|
|
418
|
-
renderCustomTooltip,
|
|
419
|
-
labels = {}
|
|
420
|
-
}) {
|
|
421
|
-
const insets = reactNativeSafeAreaContext.useSafeAreaInsets();
|
|
422
|
-
const { width: screenWidth, height: screenHeight } = reactNative.Dimensions.get("window");
|
|
423
|
-
const isActive = useGuidonStore((state) => state.isActive);
|
|
424
|
-
const config = useGuidonStore((state) => state.config);
|
|
425
|
-
const currentStepIndex = useGuidonStore((state) => state.currentStepIndex);
|
|
426
|
-
const targetMeasurements = useGuidonStore((state) => state.targetMeasurements);
|
|
427
|
-
const next = useGuidonStore((state) => state.next);
|
|
428
|
-
const previous = useGuidonStore((state) => state.previous);
|
|
429
|
-
const skip = useGuidonStore((state) => state.skip);
|
|
430
|
-
const mergedTheme = { ...DEFAULT_THEME2, ...theme };
|
|
431
|
-
const mergedLabels = {
|
|
432
|
-
next: labels.next ?? "Next",
|
|
433
|
-
previous: labels.previous ?? "Back",
|
|
434
|
-
skip: labels.skip ?? "Skip",
|
|
435
|
-
finish: labels.finish ?? "Finish",
|
|
436
|
-
stepOf: labels.stepOf ?? ((c, t) => `${c} of ${t}`)
|
|
437
|
-
};
|
|
438
|
-
const currentStep = config?.steps[currentStepIndex];
|
|
439
|
-
const totalSteps = config?.steps.length ?? 0;
|
|
440
|
-
const isFirstStep = currentStepIndex === 0;
|
|
441
|
-
const isLastStep = currentStepIndex === totalSteps - 1;
|
|
442
|
-
const measurements = currentStep?.targetId ? targetMeasurements[currentStep.targetId] : void 0;
|
|
443
|
-
const tooltipPosition = react.useMemo(() => {
|
|
444
|
-
if (!measurements) {
|
|
445
|
-
return { top: screenHeight / 2, left: screenWidth / 2 - TOOLTIP_WIDTH / 2 };
|
|
446
|
-
}
|
|
447
|
-
measurements.y + measurements.height / 2;
|
|
448
|
-
const targetBottom = measurements.y + measurements.height + mergedTheme.spotlightPadding;
|
|
449
|
-
const targetTop = measurements.y - mergedTheme.spotlightPadding;
|
|
450
|
-
let position = currentStep?.tooltipPosition ?? "auto";
|
|
451
|
-
if (position === "auto") {
|
|
452
|
-
const spaceAbove = targetTop - insets.top;
|
|
453
|
-
const spaceBelow = screenHeight - targetBottom - insets.bottom;
|
|
454
|
-
position = spaceBelow >= 200 ? "bottom" : spaceAbove >= 200 ? "top" : "bottom";
|
|
455
|
-
}
|
|
456
|
-
let top;
|
|
457
|
-
let left = Math.max(
|
|
458
|
-
TOOLTIP_MARGIN,
|
|
459
|
-
Math.min(
|
|
460
|
-
measurements.x + measurements.width / 2 - TOOLTIP_WIDTH / 2,
|
|
461
|
-
screenWidth - TOOLTIP_WIDTH - TOOLTIP_MARGIN
|
|
462
|
-
)
|
|
463
|
-
);
|
|
464
|
-
if (position === "top") {
|
|
465
|
-
top = targetTop - TOOLTIP_MARGIN - 150;
|
|
466
|
-
} else {
|
|
467
|
-
top = targetBottom + TOOLTIP_MARGIN;
|
|
468
|
-
}
|
|
469
|
-
top = Math.max(insets.top + TOOLTIP_MARGIN, Math.min(top, screenHeight - 200 - insets.bottom));
|
|
470
|
-
return { top, left, position };
|
|
471
|
-
}, [measurements, screenWidth, screenHeight, insets, currentStep?.tooltipPosition, mergedTheme.spotlightPadding]);
|
|
472
|
-
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
473
|
-
return {
|
|
474
|
-
opacity: Animated.withTiming(isActive && measurements ? 1 : 0, {
|
|
475
|
-
duration: animationDuration,
|
|
476
|
-
easing: Animated.Easing.inOut(Animated.Easing.ease)
|
|
477
|
-
}),
|
|
478
|
-
transform: [
|
|
479
|
-
{
|
|
480
|
-
translateY: Animated.withSpring(isActive && measurements ? 0 : 20, {
|
|
481
|
-
damping: 15,
|
|
482
|
-
stiffness: 150
|
|
483
|
-
})
|
|
484
|
-
}
|
|
485
|
-
]
|
|
486
|
-
};
|
|
487
|
-
}, [isActive, measurements, animationDuration]);
|
|
488
|
-
if (!isActive || !currentStep || !measurements) {
|
|
489
|
-
return null;
|
|
490
|
-
}
|
|
491
|
-
if (renderCustomTooltip) {
|
|
492
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
493
|
-
Animated__default.default.View,
|
|
494
|
-
{
|
|
495
|
-
style: [
|
|
496
|
-
styles2.tooltipContainer,
|
|
497
|
-
{
|
|
498
|
-
top: tooltipPosition.top,
|
|
499
|
-
left: tooltipPosition.left,
|
|
500
|
-
width: TOOLTIP_WIDTH
|
|
501
|
-
},
|
|
502
|
-
animatedStyle
|
|
503
|
-
],
|
|
504
|
-
children: renderCustomTooltip({
|
|
505
|
-
step: currentStep,
|
|
506
|
-
currentIndex: currentStepIndex,
|
|
507
|
-
totalSteps,
|
|
508
|
-
onNext: next,
|
|
509
|
-
onPrevious: previous,
|
|
510
|
-
onSkip: skip
|
|
511
|
-
})
|
|
512
|
-
}
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
516
|
-
Animated__default.default.View,
|
|
517
|
-
{
|
|
518
|
-
style: [
|
|
519
|
-
styles2.tooltipContainer,
|
|
520
|
-
{
|
|
521
|
-
top: tooltipPosition.top,
|
|
522
|
-
left: tooltipPosition.left,
|
|
523
|
-
width: TOOLTIP_WIDTH,
|
|
524
|
-
backgroundColor: mergedTheme.tooltipBackgroundColor,
|
|
525
|
-
borderColor: mergedTheme.tooltipBorderColor,
|
|
526
|
-
borderRadius: mergedTheme.tooltipBorderRadius
|
|
527
|
-
},
|
|
528
|
-
animatedStyle
|
|
529
|
-
],
|
|
530
|
-
children: [
|
|
531
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles2.progressContainer, children: [
|
|
532
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.progressText, { color: mergedTheme.mutedColor }], children: mergedLabels.stepOf(currentStepIndex + 1, totalSteps) }),
|
|
533
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles2.progressDots, children: Array.from({ length: totalSteps }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
534
|
-
reactNative.View,
|
|
535
|
-
{
|
|
536
|
-
style: [
|
|
537
|
-
styles2.progressDot,
|
|
538
|
-
{
|
|
539
|
-
backgroundColor: i === currentStepIndex ? mergedTheme.primaryColor : mergedTheme.mutedColor,
|
|
540
|
-
opacity: i === currentStepIndex ? 1 : 0.3
|
|
541
|
-
}
|
|
542
|
-
]
|
|
543
|
-
},
|
|
544
|
-
i
|
|
545
|
-
)) })
|
|
546
|
-
] }),
|
|
547
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles2.content, children: [
|
|
548
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.title, { color: mergedTheme.titleColor }], children: currentStep.title }),
|
|
549
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.description, { color: mergedTheme.descriptionColor }], children: currentStep.description }),
|
|
550
|
-
currentStep.customContent
|
|
551
|
-
] }),
|
|
552
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles2.buttonContainer, children: [
|
|
553
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableOpacity, { onPress: skip, style: styles2.skipButton, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.skipText, { color: mergedTheme.mutedColor }], children: mergedLabels.skip }) }),
|
|
554
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles2.navButtons, children: [
|
|
555
|
-
!isFirstStep && /* @__PURE__ */ jsxRuntime.jsx(
|
|
556
|
-
reactNative.TouchableOpacity,
|
|
557
|
-
{
|
|
558
|
-
onPress: previous,
|
|
559
|
-
style: [styles2.navButton, styles2.backButton],
|
|
560
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.backButtonText, { color: mergedTheme.primaryColor }], children: mergedLabels.previous })
|
|
561
|
-
}
|
|
562
|
-
),
|
|
563
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
564
|
-
reactNative.TouchableOpacity,
|
|
565
|
-
{
|
|
566
|
-
onPress: next,
|
|
567
|
-
style: [
|
|
568
|
-
styles2.navButton,
|
|
569
|
-
styles2.nextButton,
|
|
570
|
-
{ backgroundColor: mergedTheme.primaryColor }
|
|
571
|
-
],
|
|
572
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles2.nextButtonText, children: isLastStep ? mergedLabels.finish : mergedLabels.next })
|
|
573
|
-
}
|
|
574
|
-
)
|
|
575
|
-
] })
|
|
576
|
-
] })
|
|
577
|
-
]
|
|
578
|
-
}
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
var styles2 = reactNative.StyleSheet.create({
|
|
582
|
-
tooltipContainer: {
|
|
583
|
-
position: "absolute",
|
|
584
|
-
zIndex: 1e3,
|
|
585
|
-
borderWidth: 1,
|
|
586
|
-
padding: 16,
|
|
587
|
-
...reactNative.Platform.select({
|
|
588
|
-
ios: {
|
|
589
|
-
shadowColor: "#000",
|
|
590
|
-
shadowOffset: { width: 0, height: 4 },
|
|
591
|
-
shadowOpacity: 0.15,
|
|
592
|
-
shadowRadius: 12
|
|
593
|
-
},
|
|
594
|
-
android: {
|
|
595
|
-
elevation: 8
|
|
596
|
-
},
|
|
597
|
-
web: {
|
|
598
|
-
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)"
|
|
599
|
-
}
|
|
600
|
-
})
|
|
601
|
-
},
|
|
602
|
-
progressContainer: {
|
|
603
|
-
flexDirection: "row",
|
|
604
|
-
alignItems: "center",
|
|
605
|
-
justifyContent: "space-between",
|
|
606
|
-
marginBottom: 12
|
|
607
|
-
},
|
|
608
|
-
progressText: {
|
|
609
|
-
fontSize: 12,
|
|
610
|
-
fontWeight: "500"
|
|
611
|
-
},
|
|
612
|
-
progressDots: {
|
|
613
|
-
flexDirection: "row",
|
|
614
|
-
gap: 4
|
|
615
|
-
},
|
|
616
|
-
progressDot: {
|
|
617
|
-
width: 6,
|
|
618
|
-
height: 6,
|
|
619
|
-
borderRadius: 3
|
|
620
|
-
},
|
|
621
|
-
content: {
|
|
622
|
-
marginBottom: 16
|
|
623
|
-
},
|
|
624
|
-
title: {
|
|
625
|
-
fontSize: 18,
|
|
626
|
-
fontWeight: "600",
|
|
627
|
-
marginBottom: 8
|
|
628
|
-
},
|
|
629
|
-
description: {
|
|
630
|
-
fontSize: 14,
|
|
631
|
-
lineHeight: 20
|
|
632
|
-
},
|
|
633
|
-
buttonContainer: {
|
|
634
|
-
flexDirection: "row",
|
|
635
|
-
alignItems: "center",
|
|
636
|
-
justifyContent: "space-between"
|
|
637
|
-
},
|
|
638
|
-
skipButton: {
|
|
639
|
-
paddingVertical: 8,
|
|
640
|
-
paddingHorizontal: 4
|
|
641
|
-
},
|
|
642
|
-
skipText: {
|
|
643
|
-
fontSize: 14
|
|
644
|
-
},
|
|
645
|
-
navButtons: {
|
|
646
|
-
flexDirection: "row",
|
|
647
|
-
gap: 8
|
|
648
|
-
},
|
|
649
|
-
navButton: {
|
|
650
|
-
paddingVertical: 10,
|
|
651
|
-
paddingHorizontal: 16,
|
|
652
|
-
borderRadius: 8
|
|
653
|
-
},
|
|
654
|
-
backButton: {
|
|
655
|
-
backgroundColor: "transparent"
|
|
656
|
-
},
|
|
657
|
-
backButtonText: {
|
|
658
|
-
fontSize: 14,
|
|
659
|
-
fontWeight: "600"
|
|
660
|
-
},
|
|
661
|
-
nextButton: {},
|
|
662
|
-
nextButtonText: {
|
|
663
|
-
color: "#ffffff",
|
|
664
|
-
fontSize: 14,
|
|
665
|
-
fontWeight: "600"
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
function useGuidonPersistence(adapter, guidonId) {
|
|
669
|
-
const [progress, setProgress] = react.useState(null);
|
|
670
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
671
|
-
const [error, setError] = react.useState(null);
|
|
672
|
-
react.useEffect(() => {
|
|
673
|
-
if (!adapter) {
|
|
674
|
-
setIsLoading(false);
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
let mounted = true;
|
|
678
|
-
const loadProgress = async () => {
|
|
679
|
-
try {
|
|
680
|
-
setIsLoading(true);
|
|
681
|
-
setError(null);
|
|
682
|
-
const data = await adapter.loadProgress(guidonId);
|
|
683
|
-
if (mounted) {
|
|
684
|
-
setProgress(data);
|
|
685
|
-
}
|
|
686
|
-
} catch (err) {
|
|
687
|
-
if (mounted) {
|
|
688
|
-
setError(err instanceof Error ? err.message : "Failed to load progress");
|
|
689
|
-
}
|
|
690
|
-
} finally {
|
|
691
|
-
if (mounted) {
|
|
692
|
-
setIsLoading(false);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
loadProgress();
|
|
697
|
-
return () => {
|
|
698
|
-
mounted = false;
|
|
699
|
-
};
|
|
700
|
-
}, [adapter, guidonId]);
|
|
701
|
-
const saveProgress = react.useCallback(
|
|
702
|
-
async (newProgress) => {
|
|
703
|
-
if (!adapter) return;
|
|
704
|
-
const fullProgress = {
|
|
705
|
-
...newProgress,
|
|
706
|
-
guidonId
|
|
707
|
-
};
|
|
708
|
-
try {
|
|
709
|
-
setError(null);
|
|
710
|
-
await adapter.saveProgress(fullProgress);
|
|
711
|
-
setProgress(fullProgress);
|
|
712
|
-
} catch (err) {
|
|
713
|
-
setError(err instanceof Error ? err.message : "Failed to save progress");
|
|
714
|
-
throw err;
|
|
715
|
-
}
|
|
716
|
-
},
|
|
717
|
-
[adapter, guidonId]
|
|
718
|
-
);
|
|
719
|
-
const clearProgress = react.useCallback(async () => {
|
|
720
|
-
if (!adapter?.clearProgress) return;
|
|
721
|
-
try {
|
|
722
|
-
setError(null);
|
|
723
|
-
await adapter.clearProgress(guidonId);
|
|
724
|
-
setProgress(null);
|
|
725
|
-
} catch (err) {
|
|
726
|
-
setError(err instanceof Error ? err.message : "Failed to clear progress");
|
|
727
|
-
throw err;
|
|
728
|
-
}
|
|
729
|
-
}, [adapter, guidonId]);
|
|
730
|
-
const markCompleted = react.useCallback(async () => {
|
|
731
|
-
const currentCount = progress?.completionCount ?? 0;
|
|
732
|
-
await saveProgress({
|
|
733
|
-
completed: true,
|
|
734
|
-
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
735
|
-
completionCount: currentCount + 1
|
|
736
|
-
});
|
|
737
|
-
}, [saveProgress, progress?.completionCount]);
|
|
738
|
-
const markStepViewed = react.useCallback(
|
|
739
|
-
async (stepIndex) => {
|
|
740
|
-
await saveProgress({
|
|
741
|
-
completed: progress?.completed ?? false,
|
|
742
|
-
lastStepIndex: stepIndex,
|
|
743
|
-
completedAt: progress?.completedAt,
|
|
744
|
-
completionCount: progress?.completionCount
|
|
745
|
-
});
|
|
746
|
-
},
|
|
747
|
-
[saveProgress, progress]
|
|
748
|
-
);
|
|
749
|
-
return {
|
|
750
|
-
progress,
|
|
751
|
-
isLoading,
|
|
752
|
-
error,
|
|
753
|
-
isCompleted: progress?.completed ?? false,
|
|
754
|
-
hasStarted: progress !== null,
|
|
755
|
-
saveProgress,
|
|
756
|
-
clearProgress,
|
|
757
|
-
markCompleted,
|
|
758
|
-
markStepViewed
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
function useShouldShowGuidon(adapter, guidonId, options) {
|
|
762
|
-
const { progress, isLoading } = useGuidonPersistence(adapter, guidonId);
|
|
763
|
-
const [shouldShow, setShouldShow] = react.useState(false);
|
|
764
|
-
const [isChecking, setIsChecking] = react.useState(true);
|
|
765
|
-
react.useEffect(() => {
|
|
766
|
-
if (isLoading) return;
|
|
767
|
-
const checkCondition = async () => {
|
|
768
|
-
setIsChecking(true);
|
|
769
|
-
if (options?.forceShow) {
|
|
770
|
-
setShouldShow(true);
|
|
771
|
-
setIsChecking(false);
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
if (progress?.completed) {
|
|
775
|
-
setShouldShow(false);
|
|
776
|
-
setIsChecking(false);
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
if (options?.additionalCondition) {
|
|
780
|
-
try {
|
|
781
|
-
const result = await options.additionalCondition();
|
|
782
|
-
setShouldShow(result);
|
|
783
|
-
} catch {
|
|
784
|
-
setShouldShow(true);
|
|
785
|
-
}
|
|
786
|
-
} else {
|
|
787
|
-
setShouldShow(true);
|
|
788
|
-
}
|
|
789
|
-
setIsChecking(false);
|
|
790
|
-
};
|
|
791
|
-
checkCondition();
|
|
792
|
-
}, [isLoading, progress?.completed, options?.forceShow, options?.additionalCondition]);
|
|
793
|
-
return {
|
|
794
|
-
shouldShow,
|
|
795
|
-
isChecking: isLoading || isChecking,
|
|
796
|
-
isCompleted: progress?.completed ?? false
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
var GuidonContext = react.createContext(null);
|
|
800
|
-
function useGuidonContext() {
|
|
801
|
-
const context = react.useContext(GuidonContext);
|
|
802
|
-
if (!context) {
|
|
803
|
-
throw new Error("useGuidonContext must be used within a GuidonProvider");
|
|
804
|
-
}
|
|
805
|
-
return context;
|
|
806
|
-
}
|
|
807
|
-
function GuidonProvider({
|
|
808
|
-
children,
|
|
809
|
-
config,
|
|
810
|
-
autoStart = true,
|
|
811
|
-
shouldStart,
|
|
812
|
-
persistenceAdapter,
|
|
813
|
-
portalComponent: Portal,
|
|
814
|
-
renderTooltip,
|
|
815
|
-
tooltipLabels,
|
|
816
|
-
onBackdropPress
|
|
817
|
-
}) {
|
|
818
|
-
const hasInitialized = react.useRef(false);
|
|
819
|
-
const isActive = useGuidonStore((state) => state.isActive);
|
|
820
|
-
const storeIsCompleted = useGuidonStore((state) => state.isCompleted);
|
|
821
|
-
const currentStepIndex = useGuidonStore((state) => state.currentStepIndex);
|
|
822
|
-
const configure = useGuidonStore((state) => state.configure);
|
|
823
|
-
const start = useGuidonStore((state) => state.start);
|
|
824
|
-
const skip = useGuidonStore((state) => state.skip);
|
|
825
|
-
const reset = useGuidonStore((state) => state.reset);
|
|
826
|
-
const {
|
|
827
|
-
isLoading,
|
|
828
|
-
isCompleted: persistedCompleted,
|
|
829
|
-
markCompleted,
|
|
830
|
-
markStepViewed,
|
|
831
|
-
clearProgress
|
|
832
|
-
} = useGuidonPersistence(persistenceAdapter, config.id);
|
|
833
|
-
const isCompleted = storeIsCompleted || persistedCompleted;
|
|
834
|
-
react.useEffect(() => {
|
|
835
|
-
const enhancedConfig = {
|
|
836
|
-
...config,
|
|
837
|
-
onComplete: async () => {
|
|
838
|
-
config.onComplete?.();
|
|
839
|
-
if (persistenceAdapter) {
|
|
840
|
-
await markCompleted();
|
|
841
|
-
}
|
|
842
|
-
},
|
|
843
|
-
onSkip: async () => {
|
|
844
|
-
config.onSkip?.();
|
|
845
|
-
if (persistenceAdapter) {
|
|
846
|
-
await markStepViewed(currentStepIndex);
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
onStepChange: async (stepIndex, step) => {
|
|
850
|
-
config.onStepChange?.(stepIndex, step);
|
|
851
|
-
if (persistenceAdapter) {
|
|
852
|
-
await markStepViewed(stepIndex);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
configure(enhancedConfig);
|
|
857
|
-
}, [config, configure, persistenceAdapter, markCompleted, markStepViewed, currentStepIndex]);
|
|
858
|
-
react.useEffect(() => {
|
|
859
|
-
if (!autoStart || hasInitialized.current || isLoading) return;
|
|
860
|
-
const checkAndStart = async () => {
|
|
861
|
-
hasInitialized.current = true;
|
|
862
|
-
if (persistedCompleted) return;
|
|
863
|
-
if (shouldStart) {
|
|
864
|
-
const should = await shouldStart();
|
|
865
|
-
if (!should) return;
|
|
866
|
-
}
|
|
867
|
-
setTimeout(() => {
|
|
868
|
-
start();
|
|
869
|
-
}, 500);
|
|
870
|
-
};
|
|
871
|
-
checkAndStart();
|
|
872
|
-
}, [autoStart, isLoading, persistedCompleted, shouldStart, start]);
|
|
873
|
-
const replay = react.useCallback(async () => {
|
|
874
|
-
if (persistenceAdapter) {
|
|
875
|
-
await clearProgress();
|
|
876
|
-
}
|
|
877
|
-
reset();
|
|
878
|
-
hasInitialized.current = false;
|
|
879
|
-
setTimeout(() => {
|
|
880
|
-
start();
|
|
881
|
-
}, 100);
|
|
882
|
-
}, [persistenceAdapter, clearProgress, reset, start]);
|
|
883
|
-
const manualStart = react.useCallback(() => {
|
|
884
|
-
if (!isActive && !isLoading) {
|
|
885
|
-
start();
|
|
886
|
-
}
|
|
887
|
-
}, [isActive, isLoading, start]);
|
|
888
|
-
const contextValue = {
|
|
889
|
-
start: manualStart,
|
|
890
|
-
skip,
|
|
891
|
-
reset,
|
|
892
|
-
replay,
|
|
893
|
-
isActive,
|
|
894
|
-
isCompleted,
|
|
895
|
-
isLoading
|
|
896
|
-
};
|
|
897
|
-
const overlayContent = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
898
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
899
|
-
GuidonOverlay,
|
|
900
|
-
{
|
|
901
|
-
theme: config.theme,
|
|
902
|
-
animationDuration: config.animationDuration,
|
|
903
|
-
onBackdropPress
|
|
904
|
-
}
|
|
905
|
-
),
|
|
906
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
907
|
-
GuidonTooltip,
|
|
908
|
-
{
|
|
909
|
-
theme: config.theme,
|
|
910
|
-
animationDuration: config.animationDuration,
|
|
911
|
-
renderCustomTooltip: renderTooltip,
|
|
912
|
-
labels: tooltipLabels
|
|
913
|
-
}
|
|
914
|
-
)
|
|
915
|
-
] });
|
|
916
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(GuidonContext.Provider, { value: contextValue, children: [
|
|
917
|
-
children,
|
|
918
|
-
Portal ? /* @__PURE__ */ jsxRuntime.jsx(Portal, { children: overlayContent }) : overlayContent
|
|
919
|
-
] });
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
// src/persistence/adapters.ts
|
|
923
|
-
var STORAGE_KEY_PREFIX = "@guidon:";
|
|
924
|
-
var createNoopAdapter = () => ({
|
|
925
|
-
loadProgress: async () => null,
|
|
926
|
-
saveProgress: async () => {
|
|
927
|
-
},
|
|
928
|
-
loadAllProgress: async () => ({}),
|
|
929
|
-
clearProgress: async () => {
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
var createMemoryAdapter = () => {
|
|
933
|
-
const store = {};
|
|
934
|
-
return {
|
|
935
|
-
loadProgress: async (guidonId) => store[guidonId] ?? null,
|
|
936
|
-
saveProgress: async (progress) => {
|
|
937
|
-
store[progress.guidonId] = progress;
|
|
938
|
-
},
|
|
939
|
-
loadAllProgress: async () => ({ ...store }),
|
|
940
|
-
clearProgress: async (guidonId) => {
|
|
941
|
-
delete store[guidonId];
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
};
|
|
945
|
-
var createLocalStorageAdapter = (keyPrefix = STORAGE_KEY_PREFIX) => ({
|
|
946
|
-
loadProgress: async (guidonId) => {
|
|
947
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
948
|
-
return null;
|
|
949
|
-
}
|
|
950
|
-
try {
|
|
951
|
-
const data = localStorage.getItem(`${keyPrefix}${guidonId}`);
|
|
952
|
-
return data ? JSON.parse(data) : null;
|
|
953
|
-
} catch {
|
|
954
|
-
return null;
|
|
955
|
-
}
|
|
956
|
-
},
|
|
957
|
-
saveProgress: async (progress) => {
|
|
958
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
|
-
try {
|
|
962
|
-
localStorage.setItem(
|
|
963
|
-
`${keyPrefix}${progress.guidonId}`,
|
|
964
|
-
JSON.stringify(progress)
|
|
965
|
-
);
|
|
966
|
-
} catch {
|
|
967
|
-
}
|
|
968
|
-
},
|
|
969
|
-
loadAllProgress: async () => {
|
|
970
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
971
|
-
return {};
|
|
972
|
-
}
|
|
973
|
-
const result = {};
|
|
974
|
-
try {
|
|
975
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
976
|
-
const key = localStorage.key(i);
|
|
977
|
-
if (key?.startsWith(keyPrefix)) {
|
|
978
|
-
const data = localStorage.getItem(key);
|
|
979
|
-
if (data) {
|
|
980
|
-
const progress = JSON.parse(data);
|
|
981
|
-
result[progress.guidonId] = progress;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
} catch {
|
|
986
|
-
}
|
|
987
|
-
return result;
|
|
988
|
-
},
|
|
989
|
-
clearProgress: async (guidonId) => {
|
|
990
|
-
if (typeof window === "undefined" || !window.localStorage) {
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
try {
|
|
994
|
-
localStorage.removeItem(`${keyPrefix}${guidonId}`);
|
|
995
|
-
} catch {
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
var createAsyncStorageAdapter = (asyncStorage, keyPrefix = STORAGE_KEY_PREFIX) => ({
|
|
1000
|
-
loadProgress: async (guidonId) => {
|
|
1001
|
-
try {
|
|
1002
|
-
const data = await asyncStorage.getItem(`${keyPrefix}${guidonId}`);
|
|
1003
|
-
return data ? JSON.parse(data) : null;
|
|
1004
|
-
} catch {
|
|
1005
|
-
return null;
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
saveProgress: async (progress) => {
|
|
1009
|
-
try {
|
|
1010
|
-
await asyncStorage.setItem(
|
|
1011
|
-
`${keyPrefix}${progress.guidonId}`,
|
|
1012
|
-
JSON.stringify(progress)
|
|
1013
|
-
);
|
|
1014
|
-
} catch {
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
loadAllProgress: async () => {
|
|
1018
|
-
const result = {};
|
|
1019
|
-
try {
|
|
1020
|
-
const allKeys = await asyncStorage.getAllKeys();
|
|
1021
|
-
const relevantKeys = allKeys.filter((key) => key.startsWith(keyPrefix));
|
|
1022
|
-
const pairs = await asyncStorage.multiGet(relevantKeys);
|
|
1023
|
-
for (const [, value] of pairs) {
|
|
1024
|
-
if (value) {
|
|
1025
|
-
const progress = JSON.parse(value);
|
|
1026
|
-
result[progress.guidonId] = progress;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
} catch {
|
|
1030
|
-
}
|
|
1031
|
-
return result;
|
|
1032
|
-
},
|
|
1033
|
-
clearProgress: async (guidonId) => {
|
|
1034
|
-
try {
|
|
1035
|
-
await asyncStorage.removeItem(`${keyPrefix}${guidonId}`);
|
|
1036
|
-
} catch {
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
var createApiAdapter = (handlers) => {
|
|
1041
|
-
const noopAdapter = createNoopAdapter();
|
|
1042
|
-
return {
|
|
1043
|
-
loadProgress: handlers.loadProgress ?? noopAdapter.loadProgress,
|
|
1044
|
-
saveProgress: handlers.saveProgress ?? noopAdapter.saveProgress,
|
|
1045
|
-
loadAllProgress: handlers.loadAllProgress ?? noopAdapter.loadAllProgress,
|
|
1046
|
-
clearProgress: handlers.clearProgress ?? noopAdapter.clearProgress
|
|
1047
|
-
};
|
|
1048
|
-
};
|
|
1049
|
-
var createCompositeAdapter = (adapters) => ({
|
|
1050
|
-
loadProgress: async (guidonId) => {
|
|
1051
|
-
for (const adapter of adapters) {
|
|
1052
|
-
const progress = await adapter.loadProgress(guidonId);
|
|
1053
|
-
if (progress) return progress;
|
|
1054
|
-
}
|
|
1055
|
-
return null;
|
|
1056
|
-
},
|
|
1057
|
-
saveProgress: async (progress) => {
|
|
1058
|
-
await Promise.all(adapters.map((adapter) => adapter.saveProgress(progress)));
|
|
1059
|
-
},
|
|
1060
|
-
loadAllProgress: async () => {
|
|
1061
|
-
const result = {};
|
|
1062
|
-
for (const adapter of adapters) {
|
|
1063
|
-
if (adapter.loadAllProgress) {
|
|
1064
|
-
const data = await adapter.loadAllProgress();
|
|
1065
|
-
Object.assign(result, data);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
return result;
|
|
1069
|
-
},
|
|
1070
|
-
clearProgress: async (guidonId) => {
|
|
1071
|
-
await Promise.all(
|
|
1072
|
-
adapters.map((adapter) => adapter.clearProgress?.(guidonId))
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
exports.Guidon = Guidon;
|
|
1078
|
-
exports.GuidonOverlay = GuidonOverlay;
|
|
1079
|
-
exports.GuidonProvider = GuidonProvider;
|
|
1080
|
-
exports.GuidonTarget = GuidonTarget;
|
|
1081
|
-
exports.GuidonTooltip = GuidonTooltip;
|
|
1082
|
-
exports.createApiAdapter = createApiAdapter;
|
|
1083
|
-
exports.createAsyncStorageAdapter = createAsyncStorageAdapter;
|
|
1084
|
-
exports.createCompositeAdapter = createCompositeAdapter;
|
|
1085
|
-
exports.createLocalStorageAdapter = createLocalStorageAdapter;
|
|
1086
|
-
exports.createMemoryAdapter = createMemoryAdapter;
|
|
1087
|
-
exports.createNoopAdapter = createNoopAdapter;
|
|
1088
|
-
exports.useGuidonActive = useGuidonActive;
|
|
1089
|
-
exports.useGuidonContext = useGuidonContext;
|
|
1090
|
-
exports.useGuidonPersistence = useGuidonPersistence;
|
|
1091
|
-
exports.useGuidonProgress = useGuidonProgress;
|
|
1092
|
-
exports.useGuidonStep = useGuidonStep;
|
|
1093
|
-
exports.useGuidonStore = useGuidonStore;
|
|
1094
|
-
exports.useShouldShowGuidon = useShouldShowGuidon;
|
|
1095
|
-
exports.useTargetMeasurements = useTargetMeasurements;
|
|
1096
|
-
//# sourceMappingURL=index.js.map
|
|
1097
|
-
//# sourceMappingURL=index.js.map
|