@tent-official/react-walkthrough 1.3.0 → 1.3.4

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/dist/index.mjs CHANGED
@@ -221,12 +221,14 @@ var useWalkthrough = ({
221
221
  displayTotal,
222
222
  displayStepOffset,
223
223
  isClearLastPositionOnEnd = false,
224
- onStepNext
224
+ onStepNext,
225
+ onStepPrev
225
226
  }) => {
226
227
  const started = useRef(false);
227
228
  const onCompleteRef = useRef(onWalkthroughComplete);
228
229
  const handleWhenLastStepRef = useRef(handleWhenLastStep);
229
230
  const onStepNextRef = useRef(onStepNext);
231
+ const onStepPrevRef = useRef(onStepPrev);
230
232
  const conditionMet = startWhenCondition === void 0 ? true : typeof startWhenCondition === "function" ? startWhenCondition() : !!startWhenCondition;
231
233
  useEffect(() => {
232
234
  onCompleteRef.current = onWalkthroughComplete;
@@ -237,6 +239,9 @@ var useWalkthrough = ({
237
239
  useEffect(() => {
238
240
  onStepNextRef.current = onStepNext;
239
241
  }, [onStepNext]);
242
+ useEffect(() => {
243
+ onStepPrevRef.current = onStepPrev;
244
+ }, [onStepPrev]);
240
245
  const start = useCallback(() => {
241
246
  if (isDone(storageSuffix, name) || started.current) return;
242
247
  started.current = true;
@@ -261,7 +266,8 @@ var useWalkthrough = ({
261
266
  displayTotal,
262
267
  displayStepOffset,
263
268
  isClearLastPositionOnEnd,
264
- onStepNext: onStepNextRef.current
269
+ onStepNext: onStepNextRef.current,
270
+ onStepPrev: onStepPrevRef.current
265
271
  }
266
272
  });
267
273
  }, [
@@ -635,6 +641,7 @@ var WalkthroughOverlay = ({
635
641
  const popoverRef = useRef(null);
636
642
  const [popoverPos, setPopoverPos] = useState(null);
637
643
  const [popoverHidden, setPopoverHidden] = useState(false);
644
+ const [isDismissing, setIsDismissing] = useState(false);
638
645
  const displayStepRef = useRef(null);
639
646
  const displayPosRef = useRef(null);
640
647
  const [validSteps, setValidSteps] = useState([]);
@@ -647,6 +654,7 @@ var WalkthroughOverlay = ({
647
654
  if (!activeTour) {
648
655
  setValidSteps([]);
649
656
  setIsDelaying(false);
657
+ setIsDismissing(false);
650
658
  waitingForElsRef.current = false;
651
659
  delayDoneForRef.current = null;
652
660
  skipNextRecomputeRef.current = false;
@@ -846,6 +854,7 @@ var WalkthroughOverlay = ({
846
854
  setPopoverHidden(false);
847
855
  }, [popoverHidden, isAnimating, step, popoverPos]);
848
856
  if (!activeTour) return null;
857
+ if (isDismissing) return null;
849
858
  if (_activeOverlayId !== null && _activeOverlayId !== instanceIdRef.current) {
850
859
  return null;
851
860
  }
@@ -936,6 +945,7 @@ var WalkthroughOverlay = ({
936
945
  const hasMoreOriginalSteps = currentOrigIdx < activeTour.steps.length - 1;
937
946
  const effectiveIsLast = isLast && !(hasTrigger && hasMoreOriginalSteps);
938
947
  if (effectiveIsLast) {
948
+ setIsDismissing(true);
939
949
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
940
950
  completeTour();
941
951
  } else {
@@ -1048,8 +1058,7 @@ var WalkthroughOverlay = ({
1048
1058
  }
1049
1059
  return;
1050
1060
  }
1051
- setPopoverHidden(true);
1052
- setPopoverPos(null);
1061
+ setIsDismissing(true);
1053
1062
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
1054
1063
  setTimeout(() => completeTour(), 300);
1055
1064
  return;
@@ -1057,7 +1066,13 @@ var WalkthroughOverlay = ({
1057
1066
  advanceStep(hasTrigger);
1058
1067
  };
1059
1068
  const prev = () => {
1069
+ var _a2;
1060
1070
  if (currentValidPos > 0) {
1071
+ const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
1072
+ const stepPrevCb = (_a2 = activeTour.onStepPrev) == null ? void 0 : _a2[currentOrigIdx];
1073
+ if (typeof stepPrevCb === "function") {
1074
+ stepPrevCb();
1075
+ }
1061
1076
  setPopoverHidden(true);
1062
1077
  setPopoverPos(null);
1063
1078
  const prevStep = validSteps[currentValidPos - 1];
@@ -1068,6 +1083,7 @@ var WalkthroughOverlay = ({
1068
1083
  }
1069
1084
  };
1070
1085
  const skip = () => {
1086
+ setIsDismissing(true);
1071
1087
  completeTour();
1072
1088
  };
1073
1089
  const popoverWidth = clampSize(step.width, window.innerWidth);