@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/dist/index.mjs CHANGED
@@ -1009,13 +1009,21 @@ var WalkthroughOverlay = ({
1009
1009
  }
1010
1010
  };
1011
1011
  const next = () => {
1012
- var _a2;
1012
+ var _a2, _b2;
1013
1013
  const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
1014
1014
  const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
1015
1015
  if (typeof stepNextCb === "function") {
1016
1016
  stepNextCb();
1017
1017
  }
1018
1018
  const hasTrigger = !!step.triggerElOnNext;
1019
+ const afterNextDelay = (_b2 = step.delayAfterNext) != null ? _b2 : 0;
1020
+ const withDelay = (fn) => {
1021
+ if (afterNextDelay > 0) {
1022
+ setTimeout(fn, afterNextDelay);
1023
+ } else {
1024
+ fn();
1025
+ }
1026
+ };
1019
1027
  if (hasTrigger) {
1020
1028
  setPopoverHidden(true);
1021
1029
  setPopoverPos(null);
@@ -1037,18 +1045,28 @@ var WalkthroughOverlay = ({
1037
1045
  const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
1038
1046
  const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
1039
1047
  setValidSteps(newValidSteps);
1040
- if (!step.forceRecompute) {
1041
- skipNextRecomputeRef.current = true;
1042
- }
1048
+ skipNextRecomputeRef.current = true;
1043
1049
  setGlobalState((s) => ({
1044
1050
  ...s,
1045
1051
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
1046
1052
  }));
1053
+ if (step.forceRecompute) {
1054
+ setTimeout(() => {
1055
+ skipNextRecomputeRef.current = false;
1056
+ setGlobalState((s) => {
1057
+ if (!s.activeTour) return s;
1058
+ return {
1059
+ ...s,
1060
+ activeTour: { ...s.activeTour, _recompute: Date.now() }
1061
+ };
1062
+ });
1063
+ }, 500);
1064
+ }
1047
1065
  };
1048
1066
  const SETTLE_DELAY = 150;
1049
1067
  const alreadyExists = document.getElementById(nextElId);
1050
1068
  if (alreadyExists) {
1051
- setTimeout(() => injectAndAdvance(), SETTLE_DELAY);
1069
+ withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
1052
1070
  } else {
1053
1071
  waitingForElsRef.current = true;
1054
1072
  const observer = new MutationObserver(() => {
@@ -1056,7 +1074,7 @@ var WalkthroughOverlay = ({
1056
1074
  if (found) {
1057
1075
  observer.disconnect();
1058
1076
  waitingForElsRef.current = false;
1059
- setTimeout(() => injectAndAdvance(), SETTLE_DELAY);
1077
+ withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
1060
1078
  }
1061
1079
  });
1062
1080
  observer.observe(document.body, { childList: true, subtree: true });
@@ -1064,7 +1082,7 @@ var WalkthroughOverlay = ({
1064
1082
  observer.disconnect();
1065
1083
  if (waitingForElsRef.current) {
1066
1084
  waitingForElsRef.current = false;
1067
- advanceStep(hasTrigger);
1085
+ withDelay(() => advanceStep(hasTrigger));
1068
1086
  }
1069
1087
  }, 3e3);
1070
1088
  }
@@ -1075,7 +1093,13 @@ var WalkthroughOverlay = ({
1075
1093
  setTimeout(() => completeTour(), 300);
1076
1094
  return;
1077
1095
  }
1078
- advanceStep(hasTrigger);
1096
+ if (afterNextDelay > 0) {
1097
+ setPopoverHidden(true);
1098
+ setPopoverPos(null);
1099
+ withDelay(() => advanceStep(hasTrigger));
1100
+ } else {
1101
+ advanceStep(hasTrigger);
1102
+ }
1079
1103
  };
1080
1104
  const prev = () => {
1081
1105
  var _a2;