@tent-official/react-walkthrough 1.1.101 → 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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +85 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
@@ -536,27 +536,40 @@ var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
|
|
|
536
536
|
let offsetX = 0;
|
|
537
537
|
let offsetY = 0;
|
|
538
538
|
let maxHeight = void 0;
|
|
539
|
+
let align = "start";
|
|
539
540
|
if (dir === "top" || dir === "bottom") {
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
541
|
+
const rectCenter = rect.left + rect.width / 2;
|
|
542
|
+
align = rectCenter > vw / 2 ? "end" : "start";
|
|
543
|
+
if (align === "start") {
|
|
544
|
+
const popoverRight = rect.left + popoverW;
|
|
545
|
+
if (popoverRight > vw - EDGE_MARGIN) {
|
|
546
|
+
offsetX = vw - EDGE_MARGIN - popoverRight;
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
const popoverLeft = rect.left + rect.width - popoverW;
|
|
550
|
+
if (popoverLeft < EDGE_MARGIN) {
|
|
551
|
+
offsetX = EDGE_MARGIN - popoverLeft;
|
|
552
|
+
}
|
|
546
553
|
}
|
|
547
554
|
if (space[dir] < popoverH) {
|
|
548
555
|
maxHeight = Math.max(space[dir], 60);
|
|
549
556
|
}
|
|
550
557
|
} else {
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
558
|
+
const rectMiddle = rect.top + rect.height / 2;
|
|
559
|
+
align = rectMiddle > vh / 2 ? "end" : "start";
|
|
560
|
+
if (align === "start") {
|
|
561
|
+
const popoverBottom = rect.top + popoverH;
|
|
562
|
+
if (popoverBottom > vh - EDGE_MARGIN) {
|
|
563
|
+
offsetY = vh - EDGE_MARGIN - popoverBottom;
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
const popoverTop = rect.top + rect.height - popoverH;
|
|
567
|
+
if (popoverTop < EDGE_MARGIN) {
|
|
568
|
+
offsetY = EDGE_MARGIN - popoverTop;
|
|
569
|
+
}
|
|
557
570
|
}
|
|
558
571
|
}
|
|
559
|
-
return { dir, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
|
|
572
|
+
return { dir, align, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
|
|
560
573
|
};
|
|
561
574
|
if (preferred && fits(preferred)) return buildResult(preferred);
|
|
562
575
|
const order = ["bottom", "top", "right", "left"];
|
|
@@ -596,7 +609,7 @@ var WalkthroughOverlay = ({
|
|
|
596
609
|
prevColor,
|
|
597
610
|
skipColor
|
|
598
611
|
} = {}) => {
|
|
599
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
612
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
600
613
|
injectKeyframes();
|
|
601
614
|
const { activeTour } = useGlobalState();
|
|
602
615
|
const instanceIdRef = react.useRef(null);
|
|
@@ -898,9 +911,9 @@ var WalkthroughOverlay = ({
|
|
|
898
911
|
const totalSteps = validSteps.length;
|
|
899
912
|
const isLast = currentValidPos === totalSteps - 1;
|
|
900
913
|
const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
|
|
901
|
-
const displayCurrentStep = currentValidPos + 1 + stepOffset;
|
|
902
|
-
const displayTotalSteps = (
|
|
903
|
-
const borderRadius = (
|
|
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;
|
|
904
917
|
const {
|
|
905
918
|
isShowSkip = true,
|
|
906
919
|
isShowPrev = true,
|
|
@@ -910,9 +923,9 @@ var WalkthroughOverlay = ({
|
|
|
910
923
|
skipLabel: tourSkipLabel = "Skip",
|
|
911
924
|
doneLabel = "Done"
|
|
912
925
|
} = activeTour;
|
|
913
|
-
const nextLabel = (
|
|
914
|
-
const prevLabel = (
|
|
915
|
-
const skipLabel = (
|
|
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;
|
|
916
929
|
const advanceStep = (hasTrigger) => {
|
|
917
930
|
var _a2;
|
|
918
931
|
const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
|
|
@@ -926,6 +939,43 @@ var WalkthroughOverlay = ({
|
|
|
926
939
|
setPopoverPos(null);
|
|
927
940
|
const nextValidStep = validSteps[currentValidPos + 1];
|
|
928
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
|
+
}
|
|
929
979
|
setGlobalState((s) => ({
|
|
930
980
|
...s,
|
|
931
981
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -955,7 +1005,9 @@ var WalkthroughOverlay = ({
|
|
|
955
1005
|
const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
|
|
956
1006
|
const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
|
|
957
1007
|
setValidSteps(newValidSteps);
|
|
958
|
-
|
|
1008
|
+
if (!step.forceRecompute) {
|
|
1009
|
+
skipNextRecomputeRef.current = true;
|
|
1010
|
+
}
|
|
959
1011
|
setGlobalState((s) => ({
|
|
960
1012
|
...s,
|
|
961
1013
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -1030,22 +1082,10 @@ var WalkthroughOverlay = ({
|
|
|
1030
1082
|
displayPosRef.current = currentValidPos;
|
|
1031
1083
|
}
|
|
1032
1084
|
const ds = displayStepRef.current;
|
|
1033
|
-
const dir = (
|
|
1034
|
-
const
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
const dbgEl = document.getElementById(resolveElId(step.el));
|
|
1038
|
-
const dbgReal = dbgEl ? dbgEl.getBoundingClientRect() : null;
|
|
1039
|
-
console.log("[WT-DEBUG] anchor rect vs real element", {
|
|
1040
|
-
anchorRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
|
|
1041
|
-
realElement: dbgReal ? { top: dbgReal.top, left: dbgReal.left, width: dbgReal.width, height: dbgReal.height } : null,
|
|
1042
|
-
dir,
|
|
1043
|
-
offsetX,
|
|
1044
|
-
offsetY,
|
|
1045
|
-
popoverPos,
|
|
1046
|
-
containerElement: activeTour == null ? void 0 : activeTour.containerElement
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
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;
|
|
1049
1089
|
const anchorStyle = popoverReady ? {
|
|
1050
1090
|
position: "fixed",
|
|
1051
1091
|
top: rect.top,
|
|
@@ -1061,11 +1101,13 @@ var WalkthroughOverlay = ({
|
|
|
1061
1101
|
pointerEvents: "none",
|
|
1062
1102
|
zIndex: 99999
|
|
1063
1103
|
};
|
|
1104
|
+
const hAlign = align === "end" ? { right: offsetX } : { left: offsetX };
|
|
1105
|
+
const vAlign = align === "end" ? { bottom: offsetY } : { top: offsetY };
|
|
1064
1106
|
const dirStyles = {
|
|
1065
|
-
bottom: { top: `calc(100% + ${$popoverGap}px)`,
|
|
1066
|
-
top: { bottom: `calc(100% + ${$popoverGap}px)`,
|
|
1067
|
-
right: {
|
|
1068
|
-
left: {
|
|
1107
|
+
bottom: { top: `calc(100% + ${$popoverGap}px)`, ...hAlign },
|
|
1108
|
+
top: { bottom: `calc(100% + ${$popoverGap}px)`, ...hAlign },
|
|
1109
|
+
right: { left: `calc(100% + ${$popoverGap}px)`, ...vAlign },
|
|
1110
|
+
left: { right: `calc(100% + ${$popoverGap}px)`, ...vAlign }
|
|
1069
1111
|
};
|
|
1070
1112
|
const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
|
|
1071
1113
|
const popoverStyle = popoverReady ? {
|
|
@@ -1137,7 +1179,7 @@ var WalkthroughOverlay = ({
|
|
|
1137
1179
|
/* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
|
|
1138
1180
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
|
|
1139
1181
|
pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
|
|
1140
|
-
((
|
|
1182
|
+
((_o = pStep.isShowStep) != null ? _o : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
|
|
1141
1183
|
pDisplayCurrentStep,
|
|
1142
1184
|
"/",
|
|
1143
1185
|
pDisplayTotalSteps
|
|
@@ -1162,7 +1204,7 @@ var WalkthroughOverlay = ({
|
|
|
1162
1204
|
}
|
|
1163
1205
|
) }),
|
|
1164
1206
|
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
|
|
1165
|
-
((
|
|
1207
|
+
((_p = pStep.isShowPrev) != null ? _p : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1166
1208
|
"button",
|
|
1167
1209
|
{
|
|
1168
1210
|
className: "wt-btn",
|