@marianmeres/stuic 3.36.0 → 3.37.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.
|
@@ -51,7 +51,7 @@ export interface TourShellContext {
|
|
|
51
51
|
isLast: boolean;
|
|
52
52
|
next: () => void;
|
|
53
53
|
prev: () => void;
|
|
54
|
-
skip: () => void
|
|
54
|
+
skip: () => void | Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Options for `createTour`.
|
|
@@ -72,6 +72,16 @@ export interface TourOptions {
|
|
|
72
72
|
onEnd?: () => void;
|
|
73
73
|
/** Called when tour is skipped by the user */
|
|
74
74
|
onSkip?: () => void;
|
|
75
|
+
/**
|
|
76
|
+
* If provided, called before skipping. Return (or resolve) `false` to cancel the skip.
|
|
77
|
+
* Works for both the Skip button and Escape key.
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* // with createConfirm helper
|
|
81
|
+
* confirmSkip: () => confirm("Are you sure you want to skip the tutorial?")
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
confirmSkip?: () => boolean | Promise<boolean>;
|
|
75
85
|
/** Called on every step change */
|
|
76
86
|
onStepChange?: (step: TourStepDef, index: number) => void;
|
|
77
87
|
/**
|
|
@@ -116,7 +126,7 @@ export declare function createTour(options: TourOptions): {
|
|
|
116
126
|
start: () => void;
|
|
117
127
|
next: () => void;
|
|
118
128
|
prev: () => void;
|
|
119
|
-
skip: () => void
|
|
129
|
+
skip: () => Promise<void>;
|
|
120
130
|
reset: () => void;
|
|
121
131
|
_register: (id: string, el: HTMLElement) => void;
|
|
122
132
|
_unregister: (id: string) => void;
|
|
@@ -51,12 +51,12 @@ export function createTour(options) {
|
|
|
51
51
|
// Escape key listener — active only while tour is running
|
|
52
52
|
$effect(() => {
|
|
53
53
|
if (active && options.closeOnEscape !== false) {
|
|
54
|
-
const handler = (e) => {
|
|
54
|
+
const handler = async (e) => {
|
|
55
55
|
if (e.key === "Escape") {
|
|
56
56
|
e.preventDefault();
|
|
57
57
|
e.stopPropagation();
|
|
58
58
|
e.stopImmediatePropagation();
|
|
59
|
-
skip();
|
|
59
|
+
await skip();
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
document.addEventListener("keydown", handler);
|
|
@@ -176,7 +176,9 @@ export function createTour(options) {
|
|
|
176
176
|
if (currentIndex > 0)
|
|
177
177
|
advanceTo(currentIndex - 1);
|
|
178
178
|
}
|
|
179
|
-
function skip() {
|
|
179
|
+
async function skip() {
|
|
180
|
+
if (options.confirmSkip && !(await options.confirmSkip()))
|
|
181
|
+
return;
|
|
180
182
|
currentIndex = -1;
|
|
181
183
|
store?.set(options.storageKey, "skipped");
|
|
182
184
|
options.onSkip?.();
|