@tent-official/react-walkthrough 1.2.0 → 1.3.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/README.md +8 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ Hook to register a walkthrough tour.
|
|
|
92
92
|
| `displayTotal` | `number` | — | Override the total step count displayed in the step counter (display-only, does not affect logic) |
|
|
93
93
|
| `displayStepOffset` | `number` | `0` | Offset added to the displayed current step number (display-only, does not affect logic). e.g. `displayStepOffset: 3` with 3 real steps shows 4/total → 5/total → 6/total |
|
|
94
94
|
| `isClearLastPositionOnEnd` | `boolean` | `false` | When `true`, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight from this tour's last position |
|
|
95
|
+
| `onStepNext` | `Record<number, () => void>` | — | Map of original step index → callback. Fires when the user clicks "Next" from that step. Example: `{ 0: () => console.log("left step 0"), 2: () => doSomething() }` |
|
|
95
96
|
|
|
96
97
|
**Returns:** `{ start: () => void }`
|
|
97
98
|
|
|
@@ -113,6 +114,9 @@ Hook to register a walkthrough tour.
|
|
|
113
114
|
| `nextLabel` | `string` | — | Override tour-level `nextLabel` for this step |
|
|
114
115
|
| `prevLabel` | `string` | — | Override tour-level `prevLabel` for this step |
|
|
115
116
|
| `skipLabel` | `string` | — | Override tour-level `skipLabel` for this step |
|
|
117
|
+
| `displayStep` | `number` | — | Override the displayed step number for this step (display-only) |
|
|
118
|
+
| `displayTotal` | `number` | — | Override the displayed total for this step (display-only) |
|
|
119
|
+
| `forceRecompute` | `boolean` | — | When `true`, forces a DOM re-read before advancing to the next step. Useful when the next element is conditionally rendered and needs a layout update to appear |
|
|
116
120
|
|
|
117
121
|
### `IStepDescription`
|
|
118
122
|
|
|
@@ -254,6 +258,10 @@ The popover automatically positions itself to stay within the viewport:
|
|
|
254
258
|
|
|
255
259
|
The popover also waits for the target element to be scrolled into view before appearing.
|
|
256
260
|
|
|
261
|
+
## Instant Dismiss
|
|
262
|
+
|
|
263
|
+
When the user clicks **Done** on the last step (or **Skip** at any step), the highlight and popover vanish **instantly** in the same render frame — no lingering overlay or flash.
|
|
264
|
+
|
|
257
265
|
## License
|
|
258
266
|
|
|
259
267
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -103,6 +103,8 @@ interface IUseWalkthroughOptions {
|
|
|
103
103
|
displayStepOffset?: number;
|
|
104
104
|
/** When true, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight FROM this tour's last position. Default: false */
|
|
105
105
|
isClearLastPositionOnEnd?: boolean;
|
|
106
|
+
/** Callbacks fired when the user clicks "Next" on a specific step. The key is the original step index (0-based). Called right before advancing to the next step. Example: `onStepNext: { 0: () => openDropdown(), 2: () => fetchData() }` */
|
|
107
|
+
onStepNext?: Record<number, () => void>;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Return value of the useWalkthrough hook.
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ interface IUseWalkthroughOptions {
|
|
|
103
103
|
displayStepOffset?: number;
|
|
104
104
|
/** When true, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight FROM this tour's last position. Default: false */
|
|
105
105
|
isClearLastPositionOnEnd?: boolean;
|
|
106
|
+
/** Callbacks fired when the user clicks "Next" on a specific step. The key is the original step index (0-based). Called right before advancing to the next step. Example: `onStepNext: { 0: () => openDropdown(), 2: () => fetchData() }` */
|
|
107
|
+
onStepNext?: Record<number, () => void>;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Return value of the useWalkthrough hook.
|
package/dist/index.js
CHANGED
|
@@ -222,11 +222,13 @@ var useWalkthrough = ({
|
|
|
222
222
|
animationSpeed = 350,
|
|
223
223
|
displayTotal,
|
|
224
224
|
displayStepOffset,
|
|
225
|
-
isClearLastPositionOnEnd = false
|
|
225
|
+
isClearLastPositionOnEnd = false,
|
|
226
|
+
onStepNext
|
|
226
227
|
}) => {
|
|
227
228
|
const started = react.useRef(false);
|
|
228
229
|
const onCompleteRef = react.useRef(onWalkthroughComplete);
|
|
229
230
|
const handleWhenLastStepRef = react.useRef(handleWhenLastStep);
|
|
231
|
+
const onStepNextRef = react.useRef(onStepNext);
|
|
230
232
|
const conditionMet = startWhenCondition === void 0 ? true : typeof startWhenCondition === "function" ? startWhenCondition() : !!startWhenCondition;
|
|
231
233
|
react.useEffect(() => {
|
|
232
234
|
onCompleteRef.current = onWalkthroughComplete;
|
|
@@ -234,6 +236,9 @@ var useWalkthrough = ({
|
|
|
234
236
|
react.useEffect(() => {
|
|
235
237
|
handleWhenLastStepRef.current = handleWhenLastStep;
|
|
236
238
|
}, [handleWhenLastStep]);
|
|
239
|
+
react.useEffect(() => {
|
|
240
|
+
onStepNextRef.current = onStepNext;
|
|
241
|
+
}, [onStepNext]);
|
|
237
242
|
const start = react.useCallback(() => {
|
|
238
243
|
if (isDone(storageSuffix, name) || started.current) return;
|
|
239
244
|
started.current = true;
|
|
@@ -257,7 +262,8 @@ var useWalkthrough = ({
|
|
|
257
262
|
animationSpeed,
|
|
258
263
|
displayTotal,
|
|
259
264
|
displayStepOffset,
|
|
260
|
-
isClearLastPositionOnEnd
|
|
265
|
+
isClearLastPositionOnEnd,
|
|
266
|
+
onStepNext: onStepNextRef.current
|
|
261
267
|
}
|
|
262
268
|
});
|
|
263
269
|
}, [
|
|
@@ -631,6 +637,7 @@ var WalkthroughOverlay = ({
|
|
|
631
637
|
const popoverRef = react.useRef(null);
|
|
632
638
|
const [popoverPos, setPopoverPos] = react.useState(null);
|
|
633
639
|
const [popoverHidden, setPopoverHidden] = react.useState(false);
|
|
640
|
+
const [isDismissing, setIsDismissing] = react.useState(false);
|
|
634
641
|
const displayStepRef = react.useRef(null);
|
|
635
642
|
const displayPosRef = react.useRef(null);
|
|
636
643
|
const [validSteps, setValidSteps] = react.useState([]);
|
|
@@ -643,6 +650,7 @@ var WalkthroughOverlay = ({
|
|
|
643
650
|
if (!activeTour) {
|
|
644
651
|
setValidSteps([]);
|
|
645
652
|
setIsDelaying(false);
|
|
653
|
+
setIsDismissing(false);
|
|
646
654
|
waitingForElsRef.current = false;
|
|
647
655
|
delayDoneForRef.current = null;
|
|
648
656
|
skipNextRecomputeRef.current = false;
|
|
@@ -842,6 +850,7 @@ var WalkthroughOverlay = ({
|
|
|
842
850
|
setPopoverHidden(false);
|
|
843
851
|
}, [popoverHidden, isAnimating, step, popoverPos]);
|
|
844
852
|
if (!activeTour) return null;
|
|
853
|
+
if (isDismissing) return null;
|
|
845
854
|
if (_activeOverlayId !== null && _activeOverlayId !== instanceIdRef.current) {
|
|
846
855
|
return null;
|
|
847
856
|
}
|
|
@@ -932,6 +941,7 @@ var WalkthroughOverlay = ({
|
|
|
932
941
|
const hasMoreOriginalSteps = currentOrigIdx < activeTour.steps.length - 1;
|
|
933
942
|
const effectiveIsLast = isLast && !(hasTrigger && hasMoreOriginalSteps);
|
|
934
943
|
if (effectiveIsLast) {
|
|
944
|
+
setIsDismissing(true);
|
|
935
945
|
if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
|
|
936
946
|
completeTour();
|
|
937
947
|
} else {
|
|
@@ -983,6 +993,12 @@ var WalkthroughOverlay = ({
|
|
|
983
993
|
}
|
|
984
994
|
};
|
|
985
995
|
const next = () => {
|
|
996
|
+
var _a2;
|
|
997
|
+
const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
|
|
998
|
+
const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
|
|
999
|
+
if (typeof stepNextCb === "function") {
|
|
1000
|
+
stepNextCb();
|
|
1001
|
+
}
|
|
986
1002
|
const hasTrigger = !!step.triggerElOnNext;
|
|
987
1003
|
if (hasTrigger) {
|
|
988
1004
|
setPopoverHidden(true);
|
|
@@ -995,8 +1011,8 @@ var WalkthroughOverlay = ({
|
|
|
995
1011
|
triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
|
996
1012
|
triggerTarget.click();
|
|
997
1013
|
}
|
|
998
|
-
const
|
|
999
|
-
const nextOrigIdx =
|
|
1014
|
+
const currentOrigIdx2 = validSteps[currentValidPos]._originalIdx;
|
|
1015
|
+
const nextOrigIdx = currentOrigIdx2 + 1;
|
|
1000
1016
|
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
1001
1017
|
if (nextStepDef) {
|
|
1002
1018
|
const nextElId = resolveElId(nextStepDef.el);
|
|
@@ -1038,8 +1054,7 @@ var WalkthroughOverlay = ({
|
|
|
1038
1054
|
}
|
|
1039
1055
|
return;
|
|
1040
1056
|
}
|
|
1041
|
-
|
|
1042
|
-
setPopoverPos(null);
|
|
1057
|
+
setIsDismissing(true);
|
|
1043
1058
|
if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
|
|
1044
1059
|
setTimeout(() => completeTour(), 300);
|
|
1045
1060
|
return;
|
|
@@ -1058,6 +1073,7 @@ var WalkthroughOverlay = ({
|
|
|
1058
1073
|
}
|
|
1059
1074
|
};
|
|
1060
1075
|
const skip = () => {
|
|
1076
|
+
setIsDismissing(true);
|
|
1061
1077
|
completeTour();
|
|
1062
1078
|
};
|
|
1063
1079
|
const popoverWidth = clampSize(step.width, window.innerWidth);
|