@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.mjs
CHANGED
|
@@ -534,27 +534,40 @@ var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
|
|
|
534
534
|
let offsetX = 0;
|
|
535
535
|
let offsetY = 0;
|
|
536
536
|
let maxHeight = void 0;
|
|
537
|
+
let align = "start";
|
|
537
538
|
if (dir === "top" || dir === "bottom") {
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
539
|
+
const rectCenter = rect.left + rect.width / 2;
|
|
540
|
+
align = rectCenter > vw / 2 ? "end" : "start";
|
|
541
|
+
if (align === "start") {
|
|
542
|
+
const popoverRight = rect.left + popoverW;
|
|
543
|
+
if (popoverRight > vw - EDGE_MARGIN) {
|
|
544
|
+
offsetX = vw - EDGE_MARGIN - popoverRight;
|
|
545
|
+
}
|
|
546
|
+
} else {
|
|
547
|
+
const popoverLeft = rect.left + rect.width - popoverW;
|
|
548
|
+
if (popoverLeft < EDGE_MARGIN) {
|
|
549
|
+
offsetX = EDGE_MARGIN - popoverLeft;
|
|
550
|
+
}
|
|
544
551
|
}
|
|
545
552
|
if (space[dir] < popoverH) {
|
|
546
553
|
maxHeight = Math.max(space[dir], 60);
|
|
547
554
|
}
|
|
548
555
|
} else {
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
556
|
+
const rectMiddle = rect.top + rect.height / 2;
|
|
557
|
+
align = rectMiddle > vh / 2 ? "end" : "start";
|
|
558
|
+
if (align === "start") {
|
|
559
|
+
const popoverBottom = rect.top + popoverH;
|
|
560
|
+
if (popoverBottom > vh - EDGE_MARGIN) {
|
|
561
|
+
offsetY = vh - EDGE_MARGIN - popoverBottom;
|
|
562
|
+
}
|
|
563
|
+
} else {
|
|
564
|
+
const popoverTop = rect.top + rect.height - popoverH;
|
|
565
|
+
if (popoverTop < EDGE_MARGIN) {
|
|
566
|
+
offsetY = EDGE_MARGIN - popoverTop;
|
|
567
|
+
}
|
|
555
568
|
}
|
|
556
569
|
}
|
|
557
|
-
return { dir, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
|
|
570
|
+
return { dir, align, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
|
|
558
571
|
};
|
|
559
572
|
if (preferred && fits(preferred)) return buildResult(preferred);
|
|
560
573
|
const order = ["bottom", "top", "right", "left"];
|
|
@@ -594,7 +607,7 @@ var WalkthroughOverlay = ({
|
|
|
594
607
|
prevColor,
|
|
595
608
|
skipColor
|
|
596
609
|
} = {}) => {
|
|
597
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
610
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
598
611
|
injectKeyframes();
|
|
599
612
|
const { activeTour } = useGlobalState();
|
|
600
613
|
const instanceIdRef = useRef(null);
|
|
@@ -896,9 +909,9 @@ var WalkthroughOverlay = ({
|
|
|
896
909
|
const totalSteps = validSteps.length;
|
|
897
910
|
const isLast = currentValidPos === totalSteps - 1;
|
|
898
911
|
const stepOffset = (_c = activeTour.displayStepOffset) != null ? _c : 0;
|
|
899
|
-
const displayCurrentStep = currentValidPos + 1 + stepOffset;
|
|
900
|
-
const displayTotalSteps = (
|
|
901
|
-
const borderRadius = (
|
|
912
|
+
const displayCurrentStep = (_d = step.displayStep) != null ? _d : currentValidPos + 1 + stepOffset;
|
|
913
|
+
const displayTotalSteps = (_f = (_e = step.displayTotal) != null ? _e : activeTour.displayTotal) != null ? _f : totalSteps;
|
|
914
|
+
const borderRadius = (_g = step.borderRadius) != null ? _g : 10;
|
|
902
915
|
const {
|
|
903
916
|
isShowSkip = true,
|
|
904
917
|
isShowPrev = true,
|
|
@@ -908,9 +921,9 @@ var WalkthroughOverlay = ({
|
|
|
908
921
|
skipLabel: tourSkipLabel = "Skip",
|
|
909
922
|
doneLabel = "Done"
|
|
910
923
|
} = activeTour;
|
|
911
|
-
const nextLabel = (
|
|
912
|
-
const prevLabel = (
|
|
913
|
-
const skipLabel = (
|
|
924
|
+
const nextLabel = (_h = step.nextLabel) != null ? _h : tourNextLabel;
|
|
925
|
+
const prevLabel = (_i = step.prevLabel) != null ? _i : tourPrevLabel;
|
|
926
|
+
const skipLabel = (_j = step.skipLabel) != null ? _j : tourSkipLabel;
|
|
914
927
|
const advanceStep = (hasTrigger) => {
|
|
915
928
|
var _a2;
|
|
916
929
|
const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
|
|
@@ -924,6 +937,43 @@ var WalkthroughOverlay = ({
|
|
|
924
937
|
setPopoverPos(null);
|
|
925
938
|
const nextValidStep = validSteps[currentValidPos + 1];
|
|
926
939
|
const nextOrigIdx = hasTrigger && !nextValidStep ? currentOrigIdx + 1 : (_a2 = nextValidStep == null ? void 0 : nextValidStep._originalIdx) != null ? _a2 : currentOrigIdx + 1;
|
|
940
|
+
const shouldForceRecompute = !!step.forceRecompute;
|
|
941
|
+
if (shouldForceRecompute) {
|
|
942
|
+
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
943
|
+
if (nextStepDef) {
|
|
944
|
+
const nextElId = resolveElId(nextStepDef.el);
|
|
945
|
+
const SETTLE_DELAY = 150;
|
|
946
|
+
const doAdvance = () => {
|
|
947
|
+
setGlobalState((s) => ({
|
|
948
|
+
...s,
|
|
949
|
+
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
950
|
+
}));
|
|
951
|
+
};
|
|
952
|
+
const alreadyExists = document.getElementById(nextElId);
|
|
953
|
+
if (alreadyExists) {
|
|
954
|
+
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
955
|
+
} else {
|
|
956
|
+
waitingForElsRef.current = true;
|
|
957
|
+
const observer = new MutationObserver(() => {
|
|
958
|
+
const found = document.getElementById(nextElId);
|
|
959
|
+
if (found) {
|
|
960
|
+
observer.disconnect();
|
|
961
|
+
waitingForElsRef.current = false;
|
|
962
|
+
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
966
|
+
setTimeout(() => {
|
|
967
|
+
observer.disconnect();
|
|
968
|
+
if (waitingForElsRef.current) {
|
|
969
|
+
waitingForElsRef.current = false;
|
|
970
|
+
doAdvance();
|
|
971
|
+
}
|
|
972
|
+
}, 3e3);
|
|
973
|
+
}
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
927
977
|
setGlobalState((s) => ({
|
|
928
978
|
...s,
|
|
929
979
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -953,7 +1003,9 @@ var WalkthroughOverlay = ({
|
|
|
953
1003
|
const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
|
|
954
1004
|
const newValidSteps = alreadyInValid ? validSteps : [...validSteps, nextStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
|
|
955
1005
|
setValidSteps(newValidSteps);
|
|
956
|
-
|
|
1006
|
+
if (!step.forceRecompute) {
|
|
1007
|
+
skipNextRecomputeRef.current = true;
|
|
1008
|
+
}
|
|
957
1009
|
setGlobalState((s) => ({
|
|
958
1010
|
...s,
|
|
959
1011
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -1028,22 +1080,10 @@ var WalkthroughOverlay = ({
|
|
|
1028
1080
|
displayPosRef.current = currentValidPos;
|
|
1029
1081
|
}
|
|
1030
1082
|
const ds = displayStepRef.current;
|
|
1031
|
-
const dir = (
|
|
1032
|
-
const
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1035
|
-
const dbgEl = document.getElementById(resolveElId(step.el));
|
|
1036
|
-
const dbgReal = dbgEl ? dbgEl.getBoundingClientRect() : null;
|
|
1037
|
-
console.log("[WT-DEBUG] anchor rect vs real element", {
|
|
1038
|
-
anchorRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
|
|
1039
|
-
realElement: dbgReal ? { top: dbgReal.top, left: dbgReal.left, width: dbgReal.width, height: dbgReal.height } : null,
|
|
1040
|
-
dir,
|
|
1041
|
-
offsetX,
|
|
1042
|
-
offsetY,
|
|
1043
|
-
popoverPos,
|
|
1044
|
-
containerElement: activeTour == null ? void 0 : activeTour.containerElement
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1083
|
+
const dir = (_k = popoverPos == null ? void 0 : popoverPos.dir) != null ? _k : "bottom";
|
|
1084
|
+
const align = (_l = popoverPos == null ? void 0 : popoverPos.align) != null ? _l : "start";
|
|
1085
|
+
const offsetX = (_m = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _m : 0;
|
|
1086
|
+
const offsetY = (_n = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _n : 0;
|
|
1047
1087
|
const anchorStyle = popoverReady ? {
|
|
1048
1088
|
position: "fixed",
|
|
1049
1089
|
top: rect.top,
|
|
@@ -1059,11 +1099,13 @@ var WalkthroughOverlay = ({
|
|
|
1059
1099
|
pointerEvents: "none",
|
|
1060
1100
|
zIndex: 99999
|
|
1061
1101
|
};
|
|
1102
|
+
const hAlign = align === "end" ? { right: offsetX } : { left: offsetX };
|
|
1103
|
+
const vAlign = align === "end" ? { bottom: offsetY } : { top: offsetY };
|
|
1062
1104
|
const dirStyles = {
|
|
1063
|
-
bottom: { top: `calc(100% + ${$popoverGap}px)`,
|
|
1064
|
-
top: { bottom: `calc(100% + ${$popoverGap}px)`,
|
|
1065
|
-
right: {
|
|
1066
|
-
left: {
|
|
1105
|
+
bottom: { top: `calc(100% + ${$popoverGap}px)`, ...hAlign },
|
|
1106
|
+
top: { bottom: `calc(100% + ${$popoverGap}px)`, ...hAlign },
|
|
1107
|
+
right: { left: `calc(100% + ${$popoverGap}px)`, ...vAlign },
|
|
1108
|
+
left: { right: `calc(100% + ${$popoverGap}px)`, ...vAlign }
|
|
1067
1109
|
};
|
|
1068
1110
|
const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
|
|
1069
1111
|
const popoverStyle = popoverReady ? {
|
|
@@ -1135,7 +1177,7 @@ var WalkthroughOverlay = ({
|
|
|
1135
1177
|
/* @__PURE__ */ jsxs(PopoverBody, { children: [
|
|
1136
1178
|
/* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
|
|
1137
1179
|
pStep.title ? /* @__PURE__ */ jsx(PopoverTitle, { children: pStep.title }) : "",
|
|
1138
|
-
((
|
|
1180
|
+
((_o = pStep.isShowStep) != null ? _o : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
|
|
1139
1181
|
pDisplayCurrentStep,
|
|
1140
1182
|
"/",
|
|
1141
1183
|
pDisplayTotalSteps
|
|
@@ -1160,7 +1202,7 @@ var WalkthroughOverlay = ({
|
|
|
1160
1202
|
}
|
|
1161
1203
|
) }),
|
|
1162
1204
|
/* @__PURE__ */ jsxs(ButtonGroup, { children: [
|
|
1163
|
-
((
|
|
1205
|
+
((_p = pStep.isShowPrev) != null ? _p : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
|
|
1164
1206
|
"button",
|
|
1165
1207
|
{
|
|
1166
1208
|
className: "wt-btn",
|