@tent-official/react-walkthrough 1.1.79 → 1.1.81

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,9 +695,13 @@ 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;
700
+ const currentStepDef = activeTour.steps[currentOriginalIdx];
701
+ if (currentStepDef) {
702
+ const elInDom = document.getElementById(resolveElId(currentStepDef.el));
703
+ if (elInDom) return;
704
+ }
702
705
  if (validSteps.length === 0) {
703
706
  completeTour();
704
707
  return;
@@ -853,10 +856,10 @@ var WalkthroughOverlay = ({
853
856
  }
854
857
  const totalSteps = validSteps.length;
855
858
  const isLast = currentValidPos === totalSteps - 1;
856
- const stepOffset = (_d = activeTour.displayStepOffset) != null ? _d : 0;
859
+ const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
857
860
  const displayCurrentStep = currentValidPos + 1 + stepOffset;
858
- const displayTotalSteps = (_e = activeTour.displayTotal) != null ? _e : totalSteps;
859
- const borderRadius = (_f = step.borderRadius) != null ? _f : 10;
861
+ const displayTotalSteps = (_d = activeTour.displayTotal) != null ? _d : totalSteps;
862
+ const borderRadius = (_e = step.borderRadius) != null ? _e : 10;
860
863
  const {
861
864
  isShowSkip = true,
862
865
  isShowPrev = true,
@@ -866,22 +869,11 @@ var WalkthroughOverlay = ({
866
869
  skipLabel: tourSkipLabel = "Skip",
867
870
  doneLabel = "Done"
868
871
  } = 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;
872
- const next = () => {
872
+ const nextLabel = (_f = step.nextLabel) != null ? _f : tourNextLabel;
873
+ const prevLabel = (_g = step.prevLabel) != null ? _g : tourPrevLabel;
874
+ const skipLabel = (_h = step.skipLabel) != null ? _h : tourSkipLabel;
875
+ const advanceStep = (hasTrigger) => {
873
876
  var _a2;
874
- const hasTrigger = !!step.triggerElOnNext;
875
- if (hasTrigger) {
876
- const triggerTarget = typeof step.triggerElOnNext === "string" ? document.getElementById(resolveElId(step.triggerElOnNext)) : document.getElementById(resolveElId(step.el));
877
- if (triggerTarget) {
878
- triggerTarget.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, cancelable: true, button: 0, ctrlKey: false, pointerId: 1, pointerType: "mouse" }));
879
- triggerTarget.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }));
880
- triggerTarget.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, cancelable: true, button: 0, ctrlKey: false, pointerId: 1, pointerType: "mouse" }));
881
- triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
882
- triggerTarget.click();
883
- }
884
- }
885
877
  const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
886
878
  const hasMoreOriginalSteps = currentOrigIdx < activeTour.steps.length - 1;
887
879
  const effectiveIsLast = isLast && !(hasTrigger && hasMoreOriginalSteps);
@@ -897,6 +889,50 @@ var WalkthroughOverlay = ({
897
889
  }));
898
890
  }
899
891
  };
892
+ const next = () => {
893
+ const hasTrigger = !!step.triggerElOnNext;
894
+ if (hasTrigger) {
895
+ const triggerTarget = typeof step.triggerElOnNext === "string" ? document.getElementById(resolveElId(step.triggerElOnNext)) : document.getElementById(resolveElId(step.el));
896
+ if (triggerTarget) {
897
+ triggerTarget.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, cancelable: true, button: 0, ctrlKey: false, pointerId: 1, pointerType: "mouse" }));
898
+ triggerTarget.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }));
899
+ triggerTarget.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, cancelable: true, button: 0, ctrlKey: false, pointerId: 1, pointerType: "mouse" }));
900
+ triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
901
+ triggerTarget.click();
902
+ }
903
+ const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
904
+ const nextOrigIdx = currentOrigIdx + 1;
905
+ const nextStepDef = activeTour.steps[nextOrigIdx];
906
+ if (nextStepDef) {
907
+ const nextElId = resolveElId(nextStepDef.el);
908
+ const alreadyExists = document.getElementById(nextElId);
909
+ if (alreadyExists) {
910
+ advanceStep(hasTrigger);
911
+ } else {
912
+ setPopoverHidden(true);
913
+ waitingForElsRef.current = true;
914
+ const observer = new MutationObserver(() => {
915
+ const found = document.getElementById(nextElId);
916
+ if (found) {
917
+ observer.disconnect();
918
+ waitingForElsRef.current = false;
919
+ advanceStep(hasTrigger);
920
+ }
921
+ });
922
+ observer.observe(document.body, { childList: true, subtree: true });
923
+ setTimeout(() => {
924
+ observer.disconnect();
925
+ if (waitingForElsRef.current) {
926
+ waitingForElsRef.current = false;
927
+ advanceStep(hasTrigger);
928
+ }
929
+ }, 3e3);
930
+ }
931
+ return;
932
+ }
933
+ }
934
+ advanceStep(hasTrigger);
935
+ };
900
936
  const prev = () => {
901
937
  if (currentValidPos > 0) {
902
938
  setPopoverHidden(true);
@@ -999,7 +1035,7 @@ var WalkthroughOverlay = ({
999
1035
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
1000
1036
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1001
1037
  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: [
1038
+ ((_i = pStep.isShowStep) != null ? _i : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1003
1039
  pDisplayCurrentStep,
1004
1040
  "/",
1005
1041
  pDisplayTotalSteps
@@ -1024,7 +1060,7 @@ var WalkthroughOverlay = ({
1024
1060
  }
1025
1061
  ) }),
1026
1062
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
1027
- ((_k = pStep.isShowPrev) != null ? _k : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1063
+ ((_j = pStep.isShowPrev) != null ? _j : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1028
1064
  "button",
1029
1065
  {
1030
1066
  className: "wt-btn",