@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/dist/index.mjs CHANGED
@@ -220,11 +220,13 @@ var useWalkthrough = ({
220
220
  animationSpeed = 350,
221
221
  displayTotal,
222
222
  displayStepOffset,
223
- isClearLastPositionOnEnd = false
223
+ isClearLastPositionOnEnd = false,
224
+ onStepNext
224
225
  }) => {
225
226
  const started = useRef(false);
226
227
  const onCompleteRef = useRef(onWalkthroughComplete);
227
228
  const handleWhenLastStepRef = useRef(handleWhenLastStep);
229
+ const onStepNextRef = useRef(onStepNext);
228
230
  const conditionMet = startWhenCondition === void 0 ? true : typeof startWhenCondition === "function" ? startWhenCondition() : !!startWhenCondition;
229
231
  useEffect(() => {
230
232
  onCompleteRef.current = onWalkthroughComplete;
@@ -232,6 +234,9 @@ var useWalkthrough = ({
232
234
  useEffect(() => {
233
235
  handleWhenLastStepRef.current = handleWhenLastStep;
234
236
  }, [handleWhenLastStep]);
237
+ useEffect(() => {
238
+ onStepNextRef.current = onStepNext;
239
+ }, [onStepNext]);
235
240
  const start = useCallback(() => {
236
241
  if (isDone(storageSuffix, name) || started.current) return;
237
242
  started.current = true;
@@ -255,7 +260,8 @@ var useWalkthrough = ({
255
260
  animationSpeed,
256
261
  displayTotal,
257
262
  displayStepOffset,
258
- isClearLastPositionOnEnd
263
+ isClearLastPositionOnEnd,
264
+ onStepNext: onStepNextRef.current
259
265
  }
260
266
  });
261
267
  }, [
@@ -629,6 +635,7 @@ var WalkthroughOverlay = ({
629
635
  const popoverRef = useRef(null);
630
636
  const [popoverPos, setPopoverPos] = useState(null);
631
637
  const [popoverHidden, setPopoverHidden] = useState(false);
638
+ const [isDismissing, setIsDismissing] = useState(false);
632
639
  const displayStepRef = useRef(null);
633
640
  const displayPosRef = useRef(null);
634
641
  const [validSteps, setValidSteps] = useState([]);
@@ -641,6 +648,7 @@ var WalkthroughOverlay = ({
641
648
  if (!activeTour) {
642
649
  setValidSteps([]);
643
650
  setIsDelaying(false);
651
+ setIsDismissing(false);
644
652
  waitingForElsRef.current = false;
645
653
  delayDoneForRef.current = null;
646
654
  skipNextRecomputeRef.current = false;
@@ -840,6 +848,7 @@ var WalkthroughOverlay = ({
840
848
  setPopoverHidden(false);
841
849
  }, [popoverHidden, isAnimating, step, popoverPos]);
842
850
  if (!activeTour) return null;
851
+ if (isDismissing) return null;
843
852
  if (_activeOverlayId !== null && _activeOverlayId !== instanceIdRef.current) {
844
853
  return null;
845
854
  }
@@ -930,6 +939,7 @@ var WalkthroughOverlay = ({
930
939
  const hasMoreOriginalSteps = currentOrigIdx < activeTour.steps.length - 1;
931
940
  const effectiveIsLast = isLast && !(hasTrigger && hasMoreOriginalSteps);
932
941
  if (effectiveIsLast) {
942
+ setIsDismissing(true);
933
943
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
934
944
  completeTour();
935
945
  } else {
@@ -981,6 +991,12 @@ var WalkthroughOverlay = ({
981
991
  }
982
992
  };
983
993
  const next = () => {
994
+ var _a2;
995
+ const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
996
+ const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
997
+ if (typeof stepNextCb === "function") {
998
+ stepNextCb();
999
+ }
984
1000
  const hasTrigger = !!step.triggerElOnNext;
985
1001
  if (hasTrigger) {
986
1002
  setPopoverHidden(true);
@@ -993,8 +1009,8 @@ var WalkthroughOverlay = ({
993
1009
  triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
994
1010
  triggerTarget.click();
995
1011
  }
996
- const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
997
- const nextOrigIdx = currentOrigIdx + 1;
1012
+ const currentOrigIdx2 = validSteps[currentValidPos]._originalIdx;
1013
+ const nextOrigIdx = currentOrigIdx2 + 1;
998
1014
  const nextStepDef = activeTour.steps[nextOrigIdx];
999
1015
  if (nextStepDef) {
1000
1016
  const nextElId = resolveElId(nextStepDef.el);
@@ -1036,8 +1052,7 @@ var WalkthroughOverlay = ({
1036
1052
  }
1037
1053
  return;
1038
1054
  }
1039
- setPopoverHidden(true);
1040
- setPopoverPos(null);
1055
+ setIsDismissing(true);
1041
1056
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
1042
1057
  setTimeout(() => completeTour(), 300);
1043
1058
  return;
@@ -1056,6 +1071,7 @@ var WalkthroughOverlay = ({
1056
1071
  }
1057
1072
  };
1058
1073
  const skip = () => {
1074
+ setIsDismissing(true);
1059
1075
  completeTour();
1060
1076
  };
1061
1077
  const popoverWidth = clampSize(step.width, window.innerWidth);