@tent-official/react-walkthrough 1.1.79 → 1.1.80

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.js CHANGED
@@ -567,7 +567,7 @@ var WalkthroughOverlay = ({
567
567
  prevColor,
568
568
  skipColor
569
569
  } = {}) => {
570
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
570
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
571
571
  injectKeyframes();
572
572
  const { activeTour } = useGlobalState();
573
573
  const instanceIdRef = react.useRef(null);
@@ -591,100 +591,99 @@ var WalkthroughOverlay = ({
591
591
  const [popoverHidden, setPopoverHidden] = react.useState(false);
592
592
  const displayStepRef = react.useRef(null);
593
593
  const displayPosRef = react.useRef(null);
594
- const delayDoneForRef = react.useRef(null);
594
+ const [validSteps, setValidSteps] = react.useState([]);
595
595
  const [isDelaying, setIsDelaying] = react.useState(false);
596
- const currentTourName = (_a = activeTour == null ? void 0 : activeTour.name) != null ? _a : null;
596
+ const waitingForElsRef = react.useRef(false);
597
+ const delayDoneForRef = react.useRef(null);
597
598
  react.useEffect(() => {
598
599
  var _a2;
599
600
  if (!activeTour) {
600
- delayDoneForRef.current = null;
601
- setIsDelaying(false);
602
- return;
603
- }
604
- if (delayDoneForRef.current === activeTour.name) return;
605
- const ms = (_a2 = activeTour.delay) != null ? _a2 : 0;
606
- if (ms <= 0) {
607
- delayDoneForRef.current = activeTour.name;
608
- return;
609
- }
610
- setIsDelaying(true);
611
- const timer = setTimeout(() => {
612
- delayDoneForRef.current = activeTour.name;
613
- setIsDelaying(false);
614
- }, ms);
615
- return () => clearTimeout(timer);
616
- }, [currentTourName, activeTour]);
617
- const [validSteps, setValidSteps] = react.useState([]);
618
- const waitingForElsRef = react.useRef(false);
619
- const elReadyRef = react.useRef(false);
620
- react.useEffect(() => {
621
- var _a2, _b2, _c2;
622
- if (!activeTour || isDelaying) {
623
601
  setValidSteps([]);
602
+ setIsDelaying(false);
624
603
  waitingForElsRef.current = false;
625
- elReadyRef.current = false;
604
+ delayDoneForRef.current = null;
626
605
  return;
627
606
  }
628
- waitingForElsRef.current = true;
607
+ let cancelled = false;
629
608
  const abortController = new AbortController();
630
609
  const compute = () => activeTour.steps.map((s, i) => ({ ...s, _originalIdx: i })).filter((s) => document.getElementById(resolveElId(s.el)));
631
- const found = compute();
632
- if (found.length > 0) {
633
- const currentStepIdx = (_a2 = activeTour.currentStep) != null ? _a2 : 0;
634
- const currentStepInFound = found.some((s) => s._originalIdx === currentStepIdx);
635
- if (currentStepInFound) {
610
+ const readElements = () => {
611
+ var _a3, _b2, _c2;
612
+ if (cancelled) return;
613
+ waitingForElsRef.current = true;
614
+ const found = compute();
615
+ if (found.length > 0) {
616
+ const currentStepIdx = (_a3 = activeTour.currentStep) != null ? _a3 : 0;
617
+ const currentStepInFound = found.some((s) => s._originalIdx === currentStepIdx);
618
+ if (currentStepInFound) {
619
+ setValidSteps(found);
620
+ waitingForElsRef.current = false;
621
+ return;
622
+ }
636
623
  setValidSteps(found);
637
- waitingForElsRef.current = false;
638
- elReadyRef.current = true;
624
+ const currentStepEl = (_b2 = activeTour.steps[currentStepIdx]) == null ? void 0 : _b2.el;
625
+ if (!currentStepEl) {
626
+ waitingForElsRef.current = false;
627
+ return;
628
+ }
629
+ readElement(currentStepEl, { signal: abortController.signal }).then((el) => {
630
+ if (el && !cancelled) {
631
+ waitingForElsRef.current = false;
632
+ setValidSteps(compute());
633
+ }
634
+ });
639
635
  return;
640
636
  }
641
- setValidSteps(found);
642
- elReadyRef.current = true;
643
- const currentStepEl = (_b2 = activeTour.steps[currentStepIdx]) == null ? void 0 : _b2.el;
644
- if (!currentStepEl) {
637
+ setValidSteps([]);
638
+ const firstStepEl = (_c2 = activeTour.steps[0]) == null ? void 0 : _c2.el;
639
+ if (!firstStepEl) {
645
640
  waitingForElsRef.current = false;
646
641
  return;
647
642
  }
648
- readElement(currentStepEl, { signal: abortController.signal }).then((el) => {
649
- if (el && !abortController.signal.aborted) {
650
- waitingForElsRef.current = false;
651
- setValidSteps(compute());
643
+ readElement(firstStepEl, { signal: abortController.signal }).then((el) => {
644
+ if (el && !cancelled) {
645
+ const updated = compute();
646
+ if (updated.length > 0) {
647
+ waitingForElsRef.current = false;
648
+ setValidSteps(updated);
649
+ }
652
650
  }
653
651
  });
652
+ };
653
+ const needsDelay = delayDoneForRef.current !== activeTour.name && ((_a2 = activeTour.delay) != null ? _a2 : 0) > 0;
654
+ if (needsDelay) {
655
+ setIsDelaying(true);
656
+ setValidSteps([]);
657
+ waitingForElsRef.current = true;
658
+ const timer = setTimeout(() => {
659
+ if (cancelled) return;
660
+ delayDoneForRef.current = activeTour.name;
661
+ setIsDelaying(false);
662
+ readElements();
663
+ }, activeTour.delay);
654
664
  return () => {
665
+ cancelled = true;
666
+ clearTimeout(timer);
655
667
  abortController.abort();
656
668
  waitingForElsRef.current = false;
657
669
  };
658
670
  }
659
- setValidSteps([]);
660
- const firstStepEl = (_c2 = activeTour.steps[0]) == null ? void 0 : _c2.el;
661
- if (!firstStepEl) {
662
- waitingForElsRef.current = false;
663
- elReadyRef.current = true;
664
- return;
665
- }
666
- readElement(firstStepEl, { signal: abortController.signal }).then((el) => {
667
- if (el && !abortController.signal.aborted) {
668
- const updated = compute();
669
- if (updated.length > 0) {
670
- waitingForElsRef.current = false;
671
- elReadyRef.current = true;
672
- setValidSteps(updated);
673
- }
674
- }
675
- });
671
+ delayDoneForRef.current = activeTour.name;
672
+ setIsDelaying(false);
673
+ readElements();
676
674
  return () => {
675
+ cancelled = true;
677
676
  abortController.abort();
678
677
  waitingForElsRef.current = false;
679
678
  };
680
- }, [activeTour, isDelaying]);
681
- const currentOriginalIdx = (_b = activeTour == null ? void 0 : activeTour.currentStep) != null ? _b : 0;
679
+ }, [activeTour]);
680
+ const currentOriginalIdx = (_a = activeTour == null ? void 0 : activeTour.currentStep) != null ? _a : 0;
682
681
  const currentValidPos = validSteps.findIndex(
683
682
  (s) => s._originalIdx === currentOriginalIdx
684
683
  );
685
684
  const rawStep = currentValidPos !== -1 ? validSteps[currentValidPos] : null;
686
685
  const step = isDelaying ? null : rawStep;
687
- const tourAnimationSpeed = (_c = activeTour == null ? void 0 : activeTour.animationSpeed) != null ? _c : 350;
686
+ const tourAnimationSpeed = (_b = activeTour == null ? void 0 : activeTour.animationSpeed) != null ? _b : 350;
688
687
  const { rect, isAnimating } = useAnimatedRect(step, tourAnimationSpeed, activeTour == null ? void 0 : activeTour.containerElement, !!activeTour, activeTour == null ? void 0 : activeTour.name);
689
688
  const completeTour = react.useCallback(() => {
690
689
  if (!activeTour) return;
@@ -696,7 +695,6 @@ var WalkthroughOverlay = ({
696
695
  react.useEffect(() => {
697
696
  if (!activeTour) return;
698
697
  if (isDelaying) return;
699
- if (!elReadyRef.current) return;
700
698
  if (currentValidPos !== -1) return;
701
699
  if (waitingForElsRef.current) return;
702
700
  if (validSteps.length === 0) {
@@ -853,10 +851,10 @@ var WalkthroughOverlay = ({
853
851
  }
854
852
  const totalSteps = validSteps.length;
855
853
  const isLast = currentValidPos === totalSteps - 1;
856
- const stepOffset = (_d = activeTour.displayStepOffset) != null ? _d : 0;
854
+ const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
857
855
  const displayCurrentStep = currentValidPos + 1 + stepOffset;
858
- const displayTotalSteps = (_e = activeTour.displayTotal) != null ? _e : totalSteps;
859
- const borderRadius = (_f = step.borderRadius) != null ? _f : 10;
856
+ const displayTotalSteps = (_d = activeTour.displayTotal) != null ? _d : totalSteps;
857
+ const borderRadius = (_e = step.borderRadius) != null ? _e : 10;
860
858
  const {
861
859
  isShowSkip = true,
862
860
  isShowPrev = true,
@@ -866,9 +864,9 @@ var WalkthroughOverlay = ({
866
864
  skipLabel: tourSkipLabel = "Skip",
867
865
  doneLabel = "Done"
868
866
  } = activeTour;
869
- const nextLabel = (_g = step.nextLabel) != null ? _g : tourNextLabel;
870
- const prevLabel = (_h = step.prevLabel) != null ? _h : tourPrevLabel;
871
- const skipLabel = (_i = step.skipLabel) != null ? _i : tourSkipLabel;
867
+ const nextLabel = (_f = step.nextLabel) != null ? _f : tourNextLabel;
868
+ const prevLabel = (_g = step.prevLabel) != null ? _g : tourPrevLabel;
869
+ const skipLabel = (_h = step.skipLabel) != null ? _h : tourSkipLabel;
872
870
  const next = () => {
873
871
  var _a2;
874
872
  const hasTrigger = !!step.triggerElOnNext;
@@ -999,7 +997,7 @@ var WalkthroughOverlay = ({
999
997
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
1000
998
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1001
999
  pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
1002
- ((_j = pStep.isShowStep) != null ? _j : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1000
+ ((_i = pStep.isShowStep) != null ? _i : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1003
1001
  pDisplayCurrentStep,
1004
1002
  "/",
1005
1003
  pDisplayTotalSteps
@@ -1024,7 +1022,7 @@ var WalkthroughOverlay = ({
1024
1022
  }
1025
1023
  ) }),
1026
1024
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
1027
- ((_k = pStep.isShowPrev) != null ? _k : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1025
+ ((_j = pStep.isShowPrev) != null ? _j : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1028
1026
  "button",
1029
1027
  {
1030
1028
  className: "wt-btn",