@tent-official/react-walkthrough 1.1.98 → 1.1.99
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 +49 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -519,99 +519,27 @@ var clampSize = (value, max) => {
|
|
|
519
519
|
return clamped;
|
|
520
520
|
};
|
|
521
521
|
var EDGE_MARGIN = 8;
|
|
522
|
-
var
|
|
522
|
+
var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
|
|
523
523
|
const vw = window.innerWidth;
|
|
524
524
|
const vh = window.innerHeight;
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const spaceLeft = rect.left - gap - EDGE_MARGIN;
|
|
531
|
-
const positions = {
|
|
532
|
-
bottom: {
|
|
533
|
-
top: rect.top + rect.height + gap,
|
|
534
|
-
left: clampLeft(rect.left)
|
|
535
|
-
},
|
|
536
|
-
top: {
|
|
537
|
-
top: rect.top - popoverH - gap,
|
|
538
|
-
left: clampLeft(rect.left)
|
|
539
|
-
},
|
|
540
|
-
right: {
|
|
541
|
-
top: clampTopH(rect.top),
|
|
542
|
-
left: rect.left + rect.width + gap
|
|
543
|
-
},
|
|
544
|
-
left: {
|
|
545
|
-
top: clampTopH(rect.top),
|
|
546
|
-
left: rect.left - popoverW - gap
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
const fitsInViewport = (pos) => pos.top >= EDGE_MARGIN && pos.left >= EDGE_MARGIN && pos.top + popoverH <= vh - EDGE_MARGIN && pos.left + popoverW <= vw - EDGE_MARGIN;
|
|
550
|
-
const buildResult = (top, left, availableH) => {
|
|
551
|
-
const needsClamp = availableH < popoverH;
|
|
552
|
-
const maxH = needsClamp ? Math.max(availableH, 60) : null;
|
|
553
|
-
return { top, left, ...maxH != null && { maxHeight: maxH } };
|
|
525
|
+
const space = {
|
|
526
|
+
bottom: vh - (rect.top + rect.height + gap) - EDGE_MARGIN,
|
|
527
|
+
top: rect.top - gap - EDGE_MARGIN,
|
|
528
|
+
right: vw - (rect.left + rect.width + gap) - EDGE_MARGIN,
|
|
529
|
+
left: rect.left - gap - EDGE_MARGIN
|
|
554
530
|
};
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const anchorTop = rect.top + rect.height + gap;
|
|
559
|
-
return buildResult(anchorTop, clampLeft(pos.left), vh - anchorTop - EDGE_MARGIN);
|
|
560
|
-
}
|
|
561
|
-
if (dir === "top") {
|
|
562
|
-
const availH = spaceTop;
|
|
563
|
-
const effectiveH = Math.min(popoverH, availH);
|
|
564
|
-
const anchorTop = rect.top - gap - effectiveH;
|
|
565
|
-
const finalTop = Math.max(EDGE_MARGIN, anchorTop);
|
|
566
|
-
return buildResult(finalTop, clampLeft(pos.left), availH);
|
|
567
|
-
}
|
|
568
|
-
if (dir === "right" || dir === "left") {
|
|
569
|
-
return buildResult(clampTopH(pos.top), pos.left, vh - EDGE_MARGIN * 2);
|
|
570
|
-
}
|
|
571
|
-
return { top: pos.top, left: pos.left };
|
|
531
|
+
const fits = (dir) => {
|
|
532
|
+
if (dir === "top" || dir === "bottom") return space[dir] >= popoverH;
|
|
533
|
+
return space[dir] >= popoverW;
|
|
572
534
|
};
|
|
573
|
-
|
|
574
|
-
rect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
|
|
575
|
-
popoverW,
|
|
576
|
-
popoverH,
|
|
577
|
-
gap,
|
|
578
|
-
preferred,
|
|
579
|
-
vw,
|
|
580
|
-
vh,
|
|
581
|
-
spaceTop,
|
|
582
|
-
spaceBottom,
|
|
583
|
-
spaceRight,
|
|
584
|
-
spaceLeft,
|
|
585
|
-
fits: {
|
|
586
|
-
bottom: fitsInViewport(positions.bottom),
|
|
587
|
-
top: fitsInViewport(positions.top),
|
|
588
|
-
right: fitsInViewport(positions.right),
|
|
589
|
-
left: fitsInViewport(positions.left)
|
|
590
|
-
},
|
|
591
|
-
positions
|
|
592
|
-
});
|
|
593
|
-
if (preferred && positions[preferred] && fitsInViewport(positions[preferred])) {
|
|
594
|
-
const result2 = buildForDir(preferred);
|
|
595
|
-
console.log("[WT-DEBUG] chosen:", preferred, "(preferred)", result2);
|
|
596
|
-
return result2;
|
|
597
|
-
}
|
|
535
|
+
if (preferred && fits(preferred)) return { dir: preferred };
|
|
598
536
|
const order = ["bottom", "top", "right", "left"];
|
|
599
|
-
for (const
|
|
600
|
-
if (
|
|
601
|
-
const result2 = buildForDir(dir);
|
|
602
|
-
console.log("[WT-DEBUG] chosen:", dir, "(fits)", result2);
|
|
603
|
-
return result2;
|
|
604
|
-
}
|
|
537
|
+
for (const d of order) {
|
|
538
|
+
if (fits(d)) return { dir: d };
|
|
605
539
|
}
|
|
606
|
-
const best = [
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
{ dir: "right", space: spaceRight },
|
|
610
|
-
{ dir: "left", space: spaceLeft }
|
|
611
|
-
].sort((a, b) => b.space - a.space)[0].dir;
|
|
612
|
-
const result = buildForDir(best);
|
|
613
|
-
console.log("[WT-DEBUG] chosen:", best, "(fallback)", result);
|
|
614
|
-
return result;
|
|
540
|
+
const best = Object.entries(space).sort((a, b) => b[1] - a[1])[0][0];
|
|
541
|
+
const maxH = best === "top" || best === "bottom" ? Math.max(space[best], 60) : Math.max(vh - EDGE_MARGIN * 2, 60);
|
|
542
|
+
return { dir: best, maxHeight: maxH };
|
|
615
543
|
};
|
|
616
544
|
var WT_CONTAINER_ID = "wt-portal-root";
|
|
617
545
|
var getPortalContainer = () => {
|
|
@@ -643,7 +571,7 @@ var WalkthroughOverlay = ({
|
|
|
643
571
|
prevColor,
|
|
644
572
|
skipColor
|
|
645
573
|
} = {}) => {
|
|
646
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
574
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
647
575
|
injectKeyframes();
|
|
648
576
|
const { activeTour } = useGlobalState();
|
|
649
577
|
const instanceIdRef = react.useRef(null);
|
|
@@ -825,14 +753,14 @@ var WalkthroughOverlay = ({
|
|
|
825
753
|
return;
|
|
826
754
|
}
|
|
827
755
|
const measured = popoverRef.current.getBoundingClientRect();
|
|
828
|
-
const
|
|
756
|
+
const dirInfo = choosePopoverDir(
|
|
829
757
|
rect,
|
|
830
758
|
measured.width,
|
|
831
759
|
measured.height,
|
|
832
760
|
$popoverGap,
|
|
833
761
|
step.position
|
|
834
762
|
);
|
|
835
|
-
setPopoverPos(
|
|
763
|
+
setPopoverPos(dirInfo);
|
|
836
764
|
}, [rect, step, $popoverGap, isAnimating]);
|
|
837
765
|
react.useEffect(() => {
|
|
838
766
|
if (nextBtnRef.current) {
|
|
@@ -1077,18 +1005,39 @@ var WalkthroughOverlay = ({
|
|
|
1077
1005
|
displayPosRef.current = currentValidPos;
|
|
1078
1006
|
}
|
|
1079
1007
|
const ds = displayStepRef.current;
|
|
1008
|
+
const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
|
|
1009
|
+
const anchorStyle = popoverReady ? {
|
|
1010
|
+
position: "fixed",
|
|
1011
|
+
top: rect.top,
|
|
1012
|
+
left: rect.left,
|
|
1013
|
+
width: rect.width,
|
|
1014
|
+
height: rect.height,
|
|
1015
|
+
pointerEvents: "none",
|
|
1016
|
+
zIndex: 99999
|
|
1017
|
+
} : {
|
|
1018
|
+
position: "fixed",
|
|
1019
|
+
top: -9999,
|
|
1020
|
+
left: -9999,
|
|
1021
|
+
pointerEvents: "none",
|
|
1022
|
+
zIndex: 99999
|
|
1023
|
+
};
|
|
1024
|
+
const dirStyles = {
|
|
1025
|
+
bottom: { top: `calc(100% + ${$popoverGap}px)`, left: 0 },
|
|
1026
|
+
top: { bottom: `calc(100% + ${$popoverGap}px)`, left: 0 },
|
|
1027
|
+
right: { top: 0, left: `calc(100% + ${$popoverGap}px)` },
|
|
1028
|
+
left: { top: 0, right: `calc(100% + ${$popoverGap}px)` }
|
|
1029
|
+
};
|
|
1030
|
+
const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
|
|
1080
1031
|
const popoverStyle = popoverReady ? {
|
|
1081
|
-
|
|
1082
|
-
|
|
1032
|
+
position: "absolute",
|
|
1033
|
+
...dirStyles[dir],
|
|
1083
1034
|
width: popoverWidth,
|
|
1084
1035
|
minWidth: $popoverMinWidth,
|
|
1085
1036
|
padding: $popoverPadding,
|
|
1086
1037
|
borderRadius: $popoverBorderRadius,
|
|
1087
1038
|
fontFamily: "inherit",
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
overflowY: "auto"
|
|
1091
|
-
}
|
|
1039
|
+
pointerEvents: "auto",
|
|
1040
|
+
...maxHeightStyle
|
|
1092
1041
|
} : {
|
|
1093
1042
|
position: "fixed",
|
|
1094
1043
|
top: -9999,
|
|
@@ -1144,11 +1093,11 @@ var WalkthroughOverlay = ({
|
|
|
1144
1093
|
}
|
|
1145
1094
|
)
|
|
1146
1095
|
] }) }),
|
|
1147
|
-
/* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1096
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: anchorStyle, children: /* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1148
1097
|
/* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
|
|
1149
1098
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
|
|
1150
1099
|
pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
|
|
1151
|
-
((
|
|
1100
|
+
((_j = pStep.isShowStep) != null ? _j : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
|
|
1152
1101
|
pDisplayCurrentStep,
|
|
1153
1102
|
"/",
|
|
1154
1103
|
pDisplayTotalSteps
|
|
@@ -1173,7 +1122,7 @@ var WalkthroughOverlay = ({
|
|
|
1173
1122
|
}
|
|
1174
1123
|
) }),
|
|
1175
1124
|
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
|
|
1176
|
-
((
|
|
1125
|
+
((_k = pStep.isShowPrev) != null ? _k : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1177
1126
|
"button",
|
|
1178
1127
|
{
|
|
1179
1128
|
className: "wt-btn",
|
|
@@ -1194,7 +1143,7 @@ var WalkthroughOverlay = ({
|
|
|
1194
1143
|
)
|
|
1195
1144
|
] })
|
|
1196
1145
|
] })
|
|
1197
|
-
] })
|
|
1146
|
+
] }) })
|
|
1198
1147
|
] });
|
|
1199
1148
|
return reactDom.createPortal(
|
|
1200
1149
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ...portalEventHandlers, style: { pointerEvents: "auto" }, children: overlay }),
|