@tent-official/react-walkthrough 1.4.0 → 1.4.2

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
@@ -119,6 +119,7 @@ Hook to register a walkthrough tour.
119
119
  | `displayStep` | `number` | — | Override the displayed step number for this step (display-only) |
120
120
  | `displayTotal` | `number` | — | Override the displayed total for this step (display-only) |
121
121
  | `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 |
122
+ | `delayAfterNext` | `number` | `0` | Delay in ms after clicking "Next" (after `onStepNext` and `triggerElOnNext` have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay |
122
123
 
123
124
  ### `IStepDescription`
124
125
 
package/dist/index.d.mts CHANGED
@@ -61,6 +61,8 @@ interface IWalkthroughStep {
61
61
  displayTotal?: number;
62
62
  /** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
63
63
  forceRecompute?: boolean;
64
+ /** Delay in milliseconds after clicking "Next" (after onStepNext and triggerElOnNext have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay. Default: 0 (no delay) */
65
+ delayAfterNext?: number;
64
66
  }
65
67
  /**
66
68
  * Options for the useWalkthrough hook.
package/dist/index.d.ts CHANGED
@@ -61,6 +61,8 @@ interface IWalkthroughStep {
61
61
  displayTotal?: number;
62
62
  /** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
63
63
  forceRecompute?: boolean;
64
+ /** Delay in milliseconds after clicking "Next" (after onStepNext and triggerElOnNext have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay. Default: 0 (no delay) */
65
+ delayAfterNext?: number;
64
66
  }
65
67
  /**
66
68
  * Options for the useWalkthrough hook.
package/dist/index.js CHANGED
@@ -1011,13 +1011,21 @@ var WalkthroughOverlay = ({
1011
1011
  }
1012
1012
  };
1013
1013
  const next = () => {
1014
- var _a2;
1014
+ var _a2, _b2;
1015
1015
  const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
1016
1016
  const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
1017
1017
  if (typeof stepNextCb === "function") {
1018
1018
  stepNextCb();
1019
1019
  }
1020
1020
  const hasTrigger = !!step.triggerElOnNext;
1021
+ const afterNextDelay = (_b2 = step.delayAfterNext) != null ? _b2 : 0;
1022
+ const withDelay = (fn) => {
1023
+ if (afterNextDelay > 0) {
1024
+ setTimeout(fn, afterNextDelay);
1025
+ } else {
1026
+ fn();
1027
+ }
1028
+ };
1021
1029
  if (hasTrigger) {
1022
1030
  setPopoverHidden(true);
1023
1031
  setPopoverPos(null);
@@ -1039,18 +1047,28 @@ var WalkthroughOverlay = ({
1039
1047
  const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
1040
1048
  const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
1041
1049
  setValidSteps(newValidSteps);
1042
- if (!step.forceRecompute) {
1043
- skipNextRecomputeRef.current = true;
1044
- }
1050
+ skipNextRecomputeRef.current = true;
1045
1051
  setGlobalState((s) => ({
1046
1052
  ...s,
1047
1053
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
1048
1054
  }));
1055
+ if (step.forceRecompute) {
1056
+ setTimeout(() => {
1057
+ skipNextRecomputeRef.current = false;
1058
+ setGlobalState((s) => {
1059
+ if (!s.activeTour) return s;
1060
+ return {
1061
+ ...s,
1062
+ activeTour: { ...s.activeTour, _recompute: Date.now() }
1063
+ };
1064
+ });
1065
+ }, 500);
1066
+ }
1049
1067
  };
1050
1068
  const SETTLE_DELAY = 150;
1051
1069
  const alreadyExists = document.getElementById(nextElId);
1052
1070
  if (alreadyExists) {
1053
- setTimeout(() => injectAndAdvance(), SETTLE_DELAY);
1071
+ withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
1054
1072
  } else {
1055
1073
  waitingForElsRef.current = true;
1056
1074
  const observer = new MutationObserver(() => {
@@ -1058,7 +1076,7 @@ var WalkthroughOverlay = ({
1058
1076
  if (found) {
1059
1077
  observer.disconnect();
1060
1078
  waitingForElsRef.current = false;
1061
- setTimeout(() => injectAndAdvance(), SETTLE_DELAY);
1079
+ withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
1062
1080
  }
1063
1081
  });
1064
1082
  observer.observe(document.body, { childList: true, subtree: true });
@@ -1066,7 +1084,7 @@ var WalkthroughOverlay = ({
1066
1084
  observer.disconnect();
1067
1085
  if (waitingForElsRef.current) {
1068
1086
  waitingForElsRef.current = false;
1069
- advanceStep(hasTrigger);
1087
+ withDelay(() => advanceStep(hasTrigger));
1070
1088
  }
1071
1089
  }, 3e3);
1072
1090
  }
@@ -1077,7 +1095,13 @@ var WalkthroughOverlay = ({
1077
1095
  setTimeout(() => completeTour(), 300);
1078
1096
  return;
1079
1097
  }
1080
- advanceStep(hasTrigger);
1098
+ if (afterNextDelay > 0) {
1099
+ setPopoverHidden(true);
1100
+ setPopoverPos(null);
1101
+ withDelay(() => advanceStep(hasTrigger));
1102
+ } else {
1103
+ advanceStep(hasTrigger);
1104
+ }
1081
1105
  };
1082
1106
  const prev = () => {
1083
1107
  var _a2;