@tent-official/react-walkthrough 1.1.102 → 1.3.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.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
  }, [
@@ -607,7 +613,7 @@ var WalkthroughOverlay = ({
607
613
  prevColor,
608
614
  skipColor
609
615
  } = {}) => {
610
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
616
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
611
617
  injectKeyframes();
612
618
  const { activeTour } = useGlobalState();
613
619
  const instanceIdRef = useRef(null);
@@ -909,9 +915,9 @@ var WalkthroughOverlay = ({
909
915
  const totalSteps = validSteps.length;
910
916
  const isLast = currentValidPos === totalSteps - 1;
911
917
  const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
912
- const displayCurrentStep = currentValidPos + 1 + stepOffset;
913
- const displayTotalSteps = (_d = activeTour.displayTotal) != null ? _d : totalSteps;
914
- const borderRadius = (_e = step.borderRadius) != null ? _e : 10;
918
+ const displayCurrentStep = (_d = step.displayStep) != null ? _d : currentValidPos + 1 + stepOffset;
919
+ const displayTotalSteps = (_f = (_e = step.displayTotal) != null ? _e : activeTour.displayTotal) != null ? _f : totalSteps;
920
+ const borderRadius = (_g = step.borderRadius) != null ? _g : 10;
915
921
  const {
916
922
  isShowSkip = true,
917
923
  isShowPrev = true,
@@ -921,9 +927,9 @@ var WalkthroughOverlay = ({
921
927
  skipLabel: tourSkipLabel = "Skip",
922
928
  doneLabel = "Done"
923
929
  } = activeTour;
924
- const nextLabel = (_f = step.nextLabel) != null ? _f : tourNextLabel;
925
- const prevLabel = (_g = step.prevLabel) != null ? _g : tourPrevLabel;
926
- const skipLabel = (_h = step.skipLabel) != null ? _h : tourSkipLabel;
930
+ const nextLabel = (_h = step.nextLabel) != null ? _h : tourNextLabel;
931
+ const prevLabel = (_i = step.prevLabel) != null ? _i : tourPrevLabel;
932
+ const skipLabel = (_j = step.skipLabel) != null ? _j : tourSkipLabel;
927
933
  const advanceStep = (hasTrigger) => {
928
934
  var _a2;
929
935
  const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
@@ -937,6 +943,43 @@ var WalkthroughOverlay = ({
937
943
  setPopoverPos(null);
938
944
  const nextValidStep = validSteps[currentValidPos + 1];
939
945
  const nextOrigIdx = hasTrigger && !nextValidStep ? currentOrigIdx + 1 : (_a2 = nextValidStep == null ? void 0 : nextValidStep._originalIdx) != null ? _a2 : currentOrigIdx + 1;
946
+ const shouldForceRecompute = !!step.forceRecompute;
947
+ if (shouldForceRecompute) {
948
+ const nextStepDef = activeTour.steps[nextOrigIdx];
949
+ if (nextStepDef) {
950
+ const nextElId = resolveElId(nextStepDef.el);
951
+ const SETTLE_DELAY = 150;
952
+ const doAdvance = () => {
953
+ setGlobalState((s) => ({
954
+ ...s,
955
+ activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
956
+ }));
957
+ };
958
+ const alreadyExists = document.getElementById(nextElId);
959
+ if (alreadyExists) {
960
+ setTimeout(() => doAdvance(), SETTLE_DELAY);
961
+ } else {
962
+ waitingForElsRef.current = true;
963
+ const observer = new MutationObserver(() => {
964
+ const found = document.getElementById(nextElId);
965
+ if (found) {
966
+ observer.disconnect();
967
+ waitingForElsRef.current = false;
968
+ setTimeout(() => doAdvance(), SETTLE_DELAY);
969
+ }
970
+ });
971
+ observer.observe(document.body, { childList: true, subtree: true });
972
+ setTimeout(() => {
973
+ observer.disconnect();
974
+ if (waitingForElsRef.current) {
975
+ waitingForElsRef.current = false;
976
+ doAdvance();
977
+ }
978
+ }, 3e3);
979
+ }
980
+ return;
981
+ }
982
+ }
940
983
  setGlobalState((s) => ({
941
984
  ...s,
942
985
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
@@ -944,6 +987,12 @@ var WalkthroughOverlay = ({
944
987
  }
945
988
  };
946
989
  const next = () => {
990
+ var _a2;
991
+ const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
992
+ const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
993
+ if (typeof stepNextCb === "function") {
994
+ stepNextCb();
995
+ }
947
996
  const hasTrigger = !!step.triggerElOnNext;
948
997
  if (hasTrigger) {
949
998
  setPopoverHidden(true);
@@ -956,8 +1005,8 @@ var WalkthroughOverlay = ({
956
1005
  triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
957
1006
  triggerTarget.click();
958
1007
  }
959
- const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
960
- const nextOrigIdx = currentOrigIdx + 1;
1008
+ const currentOrigIdx2 = validSteps[currentValidPos]._originalIdx;
1009
+ const nextOrigIdx = currentOrigIdx2 + 1;
961
1010
  const nextStepDef = activeTour.steps[nextOrigIdx];
962
1011
  if (nextStepDef) {
963
1012
  const nextElId = resolveElId(nextStepDef.el);
@@ -966,7 +1015,9 @@ var WalkthroughOverlay = ({
966
1015
  const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
967
1016
  const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
968
1017
  setValidSteps(newValidSteps);
969
- skipNextRecomputeRef.current = true;
1018
+ if (!step.forceRecompute) {
1019
+ skipNextRecomputeRef.current = true;
1020
+ }
970
1021
  setGlobalState((s) => ({
971
1022
  ...s,
972
1023
  activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
@@ -1041,10 +1092,10 @@ var WalkthroughOverlay = ({
1041
1092
  displayPosRef.current = currentValidPos;
1042
1093
  }
1043
1094
  const ds = displayStepRef.current;
1044
- const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
1045
- const align = (_j = popoverPos == null ? void 0 : popoverPos.align) != null ? _j : "start";
1046
- const offsetX = (_k = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _k : 0;
1047
- const offsetY = (_l = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _l : 0;
1095
+ const dir = (_k = popoverPos == null ? void 0 : popoverPos.dir) != null ? _k : "bottom";
1096
+ const align = (_l = popoverPos == null ? void 0 : popoverPos.align) != null ? _l : "start";
1097
+ const offsetX = (_m = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _m : 0;
1098
+ const offsetY = (_n = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _n : 0;
1048
1099
  const anchorStyle = popoverReady ? {
1049
1100
  position: "fixed",
1050
1101
  top: rect.top,
@@ -1138,7 +1189,7 @@ var WalkthroughOverlay = ({
1138
1189
  /* @__PURE__ */ jsxs(PopoverBody, { children: [
1139
1190
  /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
1140
1191
  pStep.title ? /* @__PURE__ */ jsx(PopoverTitle, { children: pStep.title }) : "",
1141
- ((_m = pStep.isShowStep) != null ? _m : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1192
+ ((_o = pStep.isShowStep) != null ? _o : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
1142
1193
  pDisplayCurrentStep,
1143
1194
  "/",
1144
1195
  pDisplayTotalSteps
@@ -1163,7 +1214,7 @@ var WalkthroughOverlay = ({
1163
1214
  }
1164
1215
  ) }),
1165
1216
  /* @__PURE__ */ jsxs(ButtonGroup, { children: [
1166
- ((_n = pStep.isShowPrev) != null ? _n : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
1217
+ ((_p = pStep.isShowPrev) != null ? _p : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
1167
1218
  "button",
1168
1219
  {
1169
1220
  className: "wt-btn",