@korsolutions/guidon 1.0.16 → 1.0.17
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/README.md +72 -167
- package/dist/commonjs/components/GuidonOverlay.js +9 -20
- package/dist/commonjs/components/GuidonOverlay.js.map +1 -1
- package/dist/commonjs/components/GuidonProvider.js +11 -77
- package/dist/commonjs/components/GuidonProvider.js.map +1 -1
- package/dist/commonjs/components/GuidonTooltip.js +48 -55
- package/dist/commonjs/components/GuidonTooltip.js.map +1 -1
- package/dist/commonjs/components/index.js +2 -2
- package/dist/commonjs/components/index.js.map +1 -1
- package/dist/commonjs/hooks/useGuidonRef.js +7 -7
- package/dist/commonjs/hooks/useGuidonRef.js.map +1 -1
- package/dist/commonjs/store.js +27 -70
- package/dist/commonjs/store.js.map +1 -1
- package/dist/module/components/GuidonOverlay.js +14 -25
- package/dist/module/components/GuidonOverlay.js.map +1 -1
- package/dist/module/components/GuidonProvider.js +12 -78
- package/dist/module/components/GuidonProvider.js.map +1 -1
- package/dist/module/components/GuidonTooltip.js +53 -60
- package/dist/module/components/GuidonTooltip.js.map +1 -1
- package/dist/module/components/index.js +2 -2
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/hooks/useGuidonRef.js +7 -7
- package/dist/module/hooks/useGuidonRef.js.map +1 -1
- package/dist/module/store.js +27 -70
- package/dist/module/store.js.map +1 -1
- package/dist/typescript/commonjs/components/GuidonOverlay.d.ts +1 -1
- package/dist/typescript/commonjs/components/GuidonOverlay.d.ts.map +1 -1
- package/dist/typescript/commonjs/components/GuidonProvider.d.ts +4 -4
- package/dist/typescript/commonjs/components/GuidonProvider.d.ts.map +1 -1
- package/dist/typescript/commonjs/components/GuidonTooltip.d.ts +1 -1
- package/dist/typescript/commonjs/components/GuidonTooltip.d.ts.map +1 -1
- package/dist/typescript/commonjs/components/index.d.ts +4 -4
- package/dist/typescript/commonjs/components/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/hooks/useGuidonRef.d.ts.map +1 -1
- package/dist/typescript/commonjs/store.d.ts +9 -21
- package/dist/typescript/commonjs/store.d.ts.map +1 -1
- package/dist/typescript/commonjs/types.d.ts +7 -14
- package/dist/typescript/commonjs/types.d.ts.map +1 -1
- package/dist/typescript/module/components/GuidonOverlay.d.ts +1 -1
- package/dist/typescript/module/components/GuidonOverlay.d.ts.map +1 -1
- package/dist/typescript/module/components/GuidonProvider.d.ts +4 -4
- package/dist/typescript/module/components/GuidonProvider.d.ts.map +1 -1
- package/dist/typescript/module/components/GuidonTooltip.d.ts +1 -1
- package/dist/typescript/module/components/GuidonTooltip.d.ts.map +1 -1
- package/dist/typescript/module/components/index.d.ts +4 -4
- package/dist/typescript/module/components/index.d.ts.map +1 -1
- package/dist/typescript/module/hooks/useGuidonRef.d.ts.map +1 -1
- package/dist/typescript/module/store.d.ts +9 -21
- package/dist/typescript/module/store.d.ts.map +1 -1
- package/dist/typescript/module/types.d.ts +7 -14
- package/dist/typescript/module/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/GuidonOverlay.tsx +28 -29
- package/src/components/GuidonProvider.tsx +46 -111
- package/src/components/GuidonTooltip.tsx +125 -91
- package/src/components/index.ts +4 -4
- package/src/hooks/useGuidonRef.ts +23 -8
- package/src/store.ts +44 -75
- package/src/types.ts +7 -14
package/src/store.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { useShallow } from "zustand/react/shallow";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
GuidonConfig,
|
|
5
|
+
GuidonStore,
|
|
6
|
+
GuidonTheme,
|
|
7
|
+
GuidonTours,
|
|
8
|
+
GuidonToursConfig,
|
|
9
|
+
TargetMeasurements,
|
|
10
|
+
} from "./types";
|
|
4
11
|
|
|
5
12
|
const initialState = {
|
|
6
13
|
tours: {} as GuidonTours,
|
|
@@ -21,67 +28,44 @@ const initialState = {
|
|
|
21
28
|
export const useGuidonStore = create<GuidonStore>((set, get) => ({
|
|
22
29
|
...initialState,
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
const { config: existingConfig } = get();
|
|
26
|
-
|
|
27
|
-
// Skip if same config reference (prevents re-renders from resetting)
|
|
28
|
-
if (existingConfig === config) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
console.log("[Guidon] configure() called - resetting to step 0");
|
|
33
|
-
set({ config, currentStepIndex: 0, isCompleted: false });
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
configureTours: (config: GuidonToursConfig | GuidonTours) => {
|
|
37
|
-
// Support both new GuidonToursConfig format and legacy GuidonTours format
|
|
38
|
-
const isNewFormat = 'tours' in config && typeof config.tours === 'object';
|
|
39
|
-
|
|
40
|
-
const tours = isNewFormat
|
|
41
|
-
? (config as GuidonToursConfig).tours
|
|
42
|
-
: config as GuidonTours;
|
|
43
|
-
const globalTheme = isNewFormat
|
|
44
|
-
? (config as GuidonToursConfig).theme
|
|
45
|
-
: undefined;
|
|
46
|
-
const globalAnimationDuration = isNewFormat
|
|
47
|
-
? (config as GuidonToursConfig).animationDuration
|
|
48
|
-
: undefined;
|
|
49
|
-
|
|
31
|
+
configureTours: (config: GuidonToursConfig) => {
|
|
50
32
|
const { tours: existingTours } = get();
|
|
51
33
|
|
|
52
34
|
// Skip if same tours reference (prevents re-renders from resetting)
|
|
53
|
-
if (existingTours === tours) {
|
|
35
|
+
if (existingTours === config.tours) {
|
|
54
36
|
return;
|
|
55
37
|
}
|
|
56
38
|
|
|
57
|
-
console.log(
|
|
58
|
-
|
|
39
|
+
console.log(
|
|
40
|
+
"[Guidon] configureTours() called with tours:",
|
|
41
|
+
Object.keys(config.tours),
|
|
42
|
+
);
|
|
43
|
+
set({
|
|
44
|
+
tours: config.tours,
|
|
45
|
+
globalTheme: config.theme,
|
|
46
|
+
globalAnimationDuration: config.animationDuration,
|
|
47
|
+
});
|
|
59
48
|
},
|
|
60
49
|
|
|
61
|
-
start: (tourId
|
|
62
|
-
const { tours,
|
|
50
|
+
start: (tourId: string) => {
|
|
51
|
+
const { tours, globalTheme, globalAnimationDuration } = get();
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!tourConfig) {
|
|
69
|
-
console.log(`[Guidon] start() - tour "${tourId}" not found`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
// Merge global theme/duration with tour-specific settings
|
|
73
|
-
config = {
|
|
74
|
-
...tourConfig,
|
|
75
|
-
theme: { ...globalTheme, ...tourConfig.theme },
|
|
76
|
-
animationDuration: tourConfig.animationDuration ?? globalAnimationDuration,
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
// Fall back to legacy single config
|
|
80
|
-
config = legacyConfig;
|
|
53
|
+
const tourConfig = tours[tourId] ?? null;
|
|
54
|
+
if (!tourConfig) {
|
|
55
|
+
console.log(`[Guidon] start() - tour "${tourId}" not found`);
|
|
56
|
+
return;
|
|
81
57
|
}
|
|
82
58
|
|
|
59
|
+
// Merge global theme/duration with tour-specific settings
|
|
60
|
+
const config: GuidonConfig = {
|
|
61
|
+
...tourConfig,
|
|
62
|
+
theme: { ...globalTheme, ...tourConfig.theme },
|
|
63
|
+
animationDuration:
|
|
64
|
+
tourConfig.animationDuration ?? globalAnimationDuration,
|
|
65
|
+
};
|
|
66
|
+
|
|
83
67
|
console.log("[Guidon] start() called", {
|
|
84
|
-
tourId
|
|
68
|
+
tourId,
|
|
85
69
|
hasConfig: !!config,
|
|
86
70
|
stepCount: config?.steps.length ?? 0,
|
|
87
71
|
});
|
|
@@ -100,7 +84,7 @@ export const useGuidonStore = create<GuidonStore>((set, get) => ({
|
|
|
100
84
|
activeTourId: tourId ?? null,
|
|
101
85
|
isActive: true,
|
|
102
86
|
currentStepIndex: 0,
|
|
103
|
-
isCompleted: false
|
|
87
|
+
isCompleted: false,
|
|
104
88
|
});
|
|
105
89
|
|
|
106
90
|
// Call onStepEnter for the first step
|
|
@@ -268,17 +252,8 @@ export const useGuidonStore = create<GuidonStore>((set, get) => ({
|
|
|
268
252
|
*/
|
|
269
253
|
export const Guidon = {
|
|
270
254
|
/**
|
|
271
|
-
* Configure
|
|
272
|
-
*/
|
|
273
|
-
configure: (config: GuidonConfig) => {
|
|
274
|
-
useGuidonStore.getState().configure(config);
|
|
275
|
-
},
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Configure multiple named tours.
|
|
279
|
-
* Accepts either GuidonToursConfig (with global theme) or legacy GuidonTours format.
|
|
255
|
+
* Configure multiple named tours with optional global theme.
|
|
280
256
|
* @example
|
|
281
|
-
* // New format with global theme
|
|
282
257
|
* Guidon.configureTours({
|
|
283
258
|
* theme: { primaryColor: '#007AFF' },
|
|
284
259
|
* tours: {
|
|
@@ -286,24 +261,17 @@ export const Guidon = {
|
|
|
286
261
|
* profile: { id: 'profile', steps: [...] },
|
|
287
262
|
* },
|
|
288
263
|
* });
|
|
289
|
-
*
|
|
290
|
-
* // Legacy format (still supported)
|
|
291
|
-
* Guidon.configureTours({
|
|
292
|
-
* explore: { id: 'explore', steps: [...] },
|
|
293
|
-
* profile: { id: 'profile', steps: [...] },
|
|
294
|
-
* });
|
|
295
264
|
*/
|
|
296
|
-
configureTours: (config: GuidonToursConfig
|
|
265
|
+
configureTours: (config: GuidonToursConfig) => {
|
|
297
266
|
useGuidonStore.getState().configureTours(config);
|
|
298
267
|
},
|
|
299
268
|
|
|
300
269
|
/**
|
|
301
|
-
* Start a tour by ID
|
|
270
|
+
* Start a tour by ID
|
|
302
271
|
* @example
|
|
303
272
|
* Guidon.start('explore'); // Start the 'explore' tour
|
|
304
|
-
* Guidon.start(); // Start legacy single config
|
|
305
273
|
*/
|
|
306
|
-
start: (tourId
|
|
274
|
+
start: (tourId: string) => {
|
|
307
275
|
useGuidonStore.getState().start(tourId);
|
|
308
276
|
},
|
|
309
277
|
|
|
@@ -371,7 +339,7 @@ export const Guidon = {
|
|
|
371
339
|
},
|
|
372
340
|
|
|
373
341
|
/**
|
|
374
|
-
* Get the currently active tour ID
|
|
342
|
+
* Get the currently active tour ID
|
|
375
343
|
*/
|
|
376
344
|
getActiveTourId: () => {
|
|
377
345
|
return useGuidonStore.getState().activeTourId;
|
|
@@ -439,7 +407,7 @@ export const useTargetMeasurements = (targetId: string) =>
|
|
|
439
407
|
useGuidonStore((state: GuidonStore) => state.targetMeasurements[targetId]);
|
|
440
408
|
|
|
441
409
|
/**
|
|
442
|
-
* Hook to check if the
|
|
410
|
+
* Hook to check if the Guidon is waiting for a target element to mount
|
|
443
411
|
* Returns null if not active, not waiting, or if it's a floating step
|
|
444
412
|
*/
|
|
445
413
|
export const useWaitingState = () =>
|
|
@@ -450,7 +418,7 @@ export const useWaitingState = () =>
|
|
|
450
418
|
const currentStep = state.config.steps[state.currentStepIndex];
|
|
451
419
|
const targetId = currentStep?.targetId;
|
|
452
420
|
|
|
453
|
-
// Floating step
|
|
421
|
+
// Floating step therefore not waiting
|
|
454
422
|
if (!targetId) return null;
|
|
455
423
|
|
|
456
424
|
const hasMeasurements = !!state.targetMeasurements[targetId];
|
|
@@ -464,7 +432,8 @@ export const useWaitingState = () =>
|
|
|
464
432
|
);
|
|
465
433
|
|
|
466
434
|
/**
|
|
467
|
-
* Hook to check if the current step is a floating step
|
|
435
|
+
* Hook to check if the current step is a floating step,
|
|
436
|
+
* i.e. has no targetId and is centered on device
|
|
468
437
|
*/
|
|
469
438
|
export const useIsFloatingStep = () =>
|
|
470
439
|
useGuidonStore((state: GuidonStore) => {
|
package/src/types.ts
CHANGED
|
@@ -186,10 +186,8 @@ export interface GuidonTooltipRenderProps {
|
|
|
186
186
|
*/
|
|
187
187
|
export interface GuidonProviderProps {
|
|
188
188
|
children: ReactNode;
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
/** Whether to auto-start when the component mounts */
|
|
192
|
-
autoStart?: boolean;
|
|
189
|
+
/** Tour ID to auto-start when the provider mounts */
|
|
190
|
+
autoStart?: string;
|
|
193
191
|
/** Condition function to determine if guidon should start */
|
|
194
192
|
shouldStart?: () => boolean | Promise<boolean>;
|
|
195
193
|
/** Persistence adapter for saving/loading progress */
|
|
@@ -279,7 +277,7 @@ export interface GuidonState {
|
|
|
279
277
|
globalAnimationDuration?: number;
|
|
280
278
|
/** ID of the currently active tour */
|
|
281
279
|
activeTourId: string | null;
|
|
282
|
-
/** Currently active guidon config (derived from tours + activeTourId
|
|
280
|
+
/** Currently active guidon config (derived from tours + activeTourId) */
|
|
283
281
|
config: GuidonConfig | null;
|
|
284
282
|
/** Whether the guidon is currently active */
|
|
285
283
|
isActive: boolean;
|
|
@@ -303,15 +301,10 @@ export interface GuidonState {
|
|
|
303
301
|
* Internal store actions
|
|
304
302
|
*/
|
|
305
303
|
export interface GuidonActions {
|
|
306
|
-
/** Configure
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
|
|
310
|
-
* Accepts either GuidonToursConfig (with global theme) or legacy GuidonTours format.
|
|
311
|
-
*/
|
|
312
|
-
configureTours: (config: GuidonToursConfig | GuidonTours) => void;
|
|
313
|
-
/** Start a tour by ID, or the legacy single config if no ID provided */
|
|
314
|
-
start: (tourId?: string) => void;
|
|
304
|
+
/** Configure multiple named tours with global theme support */
|
|
305
|
+
configureTours: (config: GuidonToursConfig) => void;
|
|
306
|
+
/** Start a tour by ID */
|
|
307
|
+
start: (tourId: string) => void;
|
|
315
308
|
/** Stop the current tour without completing it */
|
|
316
309
|
stop: () => void;
|
|
317
310
|
/** Go to the next step */
|