@tent-official/react-walkthrough 1.3.3 → 1.3.5

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 CHANGED
@@ -93,6 +93,7 @@ Hook to register a walkthrough tour.
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
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() }` |
96
+ | `onStepPrev` | `Record<number, () => void>` | — | Map of original step index → callback. Fires when the user clicks "Back" from that step. Example: `{ 1: () => closeDropdown(), 3: () => cleanup() }` |
96
97
 
97
98
  **Returns:** `{ start: () => void }`
98
99
 
package/dist/index.d.mts CHANGED
@@ -105,6 +105,8 @@ interface IUseWalkthroughOptions {
105
105
  isClearLastPositionOnEnd?: boolean;
106
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
107
  onStepNext?: Record<number, () => void>;
108
+ /** Callbacks fired when the user clicks "Back" on a specific step. The key is the original step index (0-based). Called right before going back to the previous step. Example: `onStepPrev: { 1: () => closeDropdown(), 3: () => cleanup() }` */
109
+ onStepPrev?: Record<number, () => void>;
108
110
  }
109
111
  /**
110
112
  * Return value of the useWalkthrough hook.
package/dist/index.d.ts CHANGED
@@ -105,6 +105,8 @@ interface IUseWalkthroughOptions {
105
105
  isClearLastPositionOnEnd?: boolean;
106
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
107
  onStepNext?: Record<number, () => void>;
108
+ /** Callbacks fired when the user clicks "Back" on a specific step. The key is the original step index (0-based). Called right before going back to the previous step. Example: `onStepPrev: { 1: () => closeDropdown(), 3: () => cleanup() }` */
109
+ onStepPrev?: Record<number, () => void>;
108
110
  }
109
111
  /**
110
112
  * Return value of the useWalkthrough hook.
package/dist/index.js CHANGED
@@ -223,12 +223,14 @@ var useWalkthrough = ({
223
223
  displayTotal,
224
224
  displayStepOffset,
225
225
  isClearLastPositionOnEnd = false,
226
- onStepNext
226
+ onStepNext,
227
+ onStepPrev
227
228
  }) => {
228
229
  const started = react.useRef(false);
229
230
  const onCompleteRef = react.useRef(onWalkthroughComplete);
230
231
  const handleWhenLastStepRef = react.useRef(handleWhenLastStep);
231
232
  const onStepNextRef = react.useRef(onStepNext);
233
+ const onStepPrevRef = react.useRef(onStepPrev);
232
234
  const conditionMet = startWhenCondition === void 0 ? true : typeof startWhenCondition === "function" ? startWhenCondition() : !!startWhenCondition;
233
235
  react.useEffect(() => {
234
236
  onCompleteRef.current = onWalkthroughComplete;
@@ -239,6 +241,9 @@ var useWalkthrough = ({
239
241
  react.useEffect(() => {
240
242
  onStepNextRef.current = onStepNext;
241
243
  }, [onStepNext]);
244
+ react.useEffect(() => {
245
+ onStepPrevRef.current = onStepPrev;
246
+ }, [onStepPrev]);
242
247
  const start = react.useCallback(() => {
243
248
  if (isDone(storageSuffix, name) || started.current) return;
244
249
  started.current = true;
@@ -263,7 +268,8 @@ var useWalkthrough = ({
263
268
  displayTotal,
264
269
  displayStepOffset,
265
270
  isClearLastPositionOnEnd,
266
- onStepNext: onStepNextRef.current
271
+ onStepNext: onStepNextRef.current,
272
+ onStepPrev: onStepPrevRef.current
267
273
  }
268
274
  });
269
275
  }, [
@@ -645,6 +651,7 @@ var WalkthroughOverlay = ({
645
651
  const waitingForElsRef = react.useRef(false);
646
652
  const delayDoneForRef = react.useRef(null);
647
653
  const skipNextRecomputeRef = react.useRef(false);
654
+ const prevActiveTourNameRef = react.useRef(null);
648
655
  react.useEffect(() => {
649
656
  var _a2;
650
657
  if (!activeTour) {
@@ -654,8 +661,15 @@ var WalkthroughOverlay = ({
654
661
  waitingForElsRef.current = false;
655
662
  delayDoneForRef.current = null;
656
663
  skipNextRecomputeRef.current = false;
664
+ prevActiveTourNameRef.current = null;
657
665
  return;
658
666
  }
667
+ if (activeTour.name !== prevActiveTourNameRef.current) {
668
+ prevActiveTourNameRef.current = activeTour.name;
669
+ if (isDismissing) {
670
+ setIsDismissing(false);
671
+ }
672
+ }
659
673
  if (skipNextRecomputeRef.current) {
660
674
  skipNextRecomputeRef.current = false;
661
675
  return;
@@ -1062,7 +1076,13 @@ var WalkthroughOverlay = ({
1062
1076
  advanceStep(hasTrigger);
1063
1077
  };
1064
1078
  const prev = () => {
1079
+ var _a2;
1065
1080
  if (currentValidPos > 0) {
1081
+ const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
1082
+ const stepPrevCb = (_a2 = activeTour.onStepPrev) == null ? void 0 : _a2[currentOrigIdx];
1083
+ if (typeof stepPrevCb === "function") {
1084
+ stepPrevCb();
1085
+ }
1066
1086
  setPopoverHidden(true);
1067
1087
  setPopoverPos(null);
1068
1088
  const prevStep = validSteps[currentValidPos - 1];