@tent-official/react-walkthrough 1.1.102 → 1.2.0

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.d.mts CHANGED
@@ -52,6 +52,12 @@ interface IWalkthroughStep {
52
52
  prevLabel?: string;
53
53
  /** Override tour-level skipLabel for this specific step. If omitted, uses the tour-level value */
54
54
  skipLabel?: string;
55
+ /** Override the displayed current step number for this specific step (display-only, does not affect logic). If omitted, uses the calculated value from tour-level settings */
56
+ displayStep?: number;
57
+ /** Override the displayed total step count for this specific step (display-only, does not affect logic). If omitted, uses the tour-level displayTotal or actual count */
58
+ displayTotal?: number;
59
+ /** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
60
+ forceRecompute?: boolean;
55
61
  }
56
62
  /**
57
63
  * Options for the useWalkthrough hook.
package/dist/index.d.ts CHANGED
@@ -52,6 +52,12 @@ interface IWalkthroughStep {
52
52
  prevLabel?: string;
53
53
  /** Override tour-level skipLabel for this specific step. If omitted, uses the tour-level value */
54
54
  skipLabel?: string;
55
+ /** Override the displayed current step number for this specific step (display-only, does not affect logic). If omitted, uses the calculated value from tour-level settings */
56
+ displayStep?: number;
57
+ /** Override the displayed total step count for this specific step (display-only, does not affect logic). If omitted, uses the tour-level displayTotal or actual count */
58
+ displayTotal?: number;
59
+ /** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
60
+ forceRecompute?: boolean;
55
61
  }
56
62
  /**
57
63
  * Options for the useWalkthrough hook.
package/dist/index.js CHANGED
@@ -609,7 +609,7 @@ var WalkthroughOverlay = ({
609
609
  prevColor,
610
610
  skipColor
611
611
  } = {}) => {
612
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
612
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
613
613
  injectKeyframes();
614
614
  const { activeTour } = useGlobalState();
615
615
  const instanceIdRef = react.useRef(null);
@@ -911,9 +911,9 @@ var WalkthroughOverlay = ({
911
911
  const totalSteps = validSteps.length;
912
912
  const isLast = currentValidPos === totalSteps - 1;
913
913
  const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
914
- const displayCurrentStep = currentValidPos + 1 + stepOffset;
915
- const displayTotalSteps = (_d = activeTour.displayTotal) != null ? _d : totalSteps;
916
- const borderRadius = (_e = step.borderRadius) != null ? _e : 10;
914
+ const displayCurrentStep = (_d = step.displayStep) != null ? _d : currentValidPos + 1 + stepOffset;
915
+ const displayTotalSteps = (_f = (_e = step.displayTotal) != null ? _e : activeTour.displayTotal) != null ? _f : totalSteps;
916
+ const borderRadius = (_g = step.borderRadius) != null ? _g : 10;
917
917
  const {
918
918
  isShowSkip = true,
919
919
  isShowPrev = true,
@@ -923,9 +923,9 @@ var WalkthroughOverlay = ({
923
923
  skipLabel: tourSkipLabel = "Skip",
924
924
  doneLabel = "Done"
925
925
  } = activeTour;
926
- const nextLabel = (_f = step.nextLabel) != null ? _f : tourNextLabel;
927
- const prevLabel = (_g = step.prevLabel) != null ? _g : tourPrevLabel;
928
- const skipLabel = (_h = step.skipLabel) != null ? _h : tourSkipLabel;
926
+ const nextLabel = (_h = step.nextLabel) != null ? _h : tourNextLabel;
927
+ const prevLabel = (_i = step.prevLabel) != null ? _i : tourPrevLabel;
928
+ const skipLabel = (_j = step.skipLabel) != null ? _j : tourSkipLabel;
929
929
  const advanceStep = (hasTrigger) => {
930
930
  var _a2;
931
931
  const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
@@ -939,6 +939,43 @@ var WalkthroughOverlay = ({
939
939
  setPopoverPos(null);
940
940
  const nextValidStep = validSteps[currentValidPos + 1];
941
941
  const nextOrigIdx = hasTrigger && !nextValidStep ? currentOrigIdx + 1 : (_a2 = nextValidStep == null ? void 0 : nextValidStep._originalIdx) != null ? _a2 : currentOrigIdx + 1;
942
+ const shouldForceRecompute = !!step.forceRecompute;
943
+ if (shouldForceRecompute) {
944
+ const nextStepDef = activeTour.steps[nextOrigIdx];
945
+ if (nextStepDef) {
946
+ const nextElId = resolveElId(nextStepDef.el);
947
+ const SETTLE_DELAY = 150;
948
+ const doAdvance = () => {
949
+ setGlobalState((s) => ({
950
+ ...s,
951
+ activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
952
+ }));
953
+ };
954
+ const alreadyExists = document.getElementById(nextElId);
955
+ if (alreadyExists) {
956
+ setTimeout(() => doAdvance(), SETTLE_DELAY);
957
+ } else {
958
+ waitingForElsRef.current = true;
959
+ const observer = new MutationObserver(() => {
960
+ const found = document.getElementById(nextElId);
961
+ if (found) {
962
+ observer.disconnect();
963
+ waitingForElsRef.current = false;
964
+ setTimeout(() => doAdvance(), SETTLE_DELAY);
965
+ }
966
+ });
967
+ observer.observe(document.body, { childList: true, subtree: true });
968
+ setTimeout(() => {
969
+ observer.disconnect();
970
+ if (waitingForElsRef.current) {
971
+ waitingForElsRef.current = false;
972
+ doAdvance();
973
+ }
974
+ }, 3e3);
975
+ }
976
+ return;
977
+ }
978
+ }
942
979
  setGlobalState((s) => ({
943
980
  ...s,
944
981
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
@@ -968,7 +1005,9 @@ var WalkthroughOverlay = ({
968
1005
  const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
969
1006
  const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
970
1007
  setValidSteps(newValidSteps);
971
- skipNextRecomputeRef.current = true;
1008
+ if (!step.forceRecompute) {
1009
+ skipNextRecomputeRef.current = true;
1010
+ }
972
1011
  setGlobalState((s) => ({
973
1012
  ...s,
974
1013
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
@@ -1043,10 +1082,10 @@ var WalkthroughOverlay = ({
1043
1082
  displayPosRef.current = currentValidPos;
1044
1083
  }
1045
1084
  const ds = displayStepRef.current;
1046
- const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
1047
- const align = (_j = popoverPos == null ? void 0 : popoverPos.align) != null ? _j : "start";
1048
- const offsetX = (_k = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _k : 0;
1049
- const offsetY = (_l = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _l : 0;
1085
+ const dir = (_k = popoverPos == null ? void 0 : popoverPos.dir) != null ? _k : "bottom";
1086
+ const align = (_l = popoverPos == null ? void 0 : popoverPos.align) != null ? _l : "start";
1087
+ const offsetX = (_m = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _m : 0;
1088
+ const offsetY = (_n = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _n : 0;
1050
1089
  const anchorStyle = popoverReady ? {
1051
1090
  position: "fixed",
1052
1091
  top: rect.top,
@@ -1140,7 +1179,7 @@ var WalkthroughOverlay = ({
1140
1179
  /* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
1141
1180
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1142
1181
  pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
1143
- ((_m = pStep.isShowStep) != null ? _m : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1182
+ ((_o = pStep.isShowStep) != null ? _o : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1144
1183
  pDisplayCurrentStep,
1145
1184
  "/",
1146
1185
  pDisplayTotalSteps
@@ -1165,7 +1204,7 @@ var WalkthroughOverlay = ({
1165
1204
  }
1166
1205
  ) }),
1167
1206
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
1168
- ((_n = pStep.isShowPrev) != null ? _n : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1207
+ ((_p = pStep.isShowPrev) != null ? _p : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1169
1208
  "button",
1170
1209
  {
1171
1210
  className: "wt-btn",