@tent-official/react-walkthrough 1.1.98 → 1.1.100
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 +74 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -98
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -519,99 +519,52 @@ 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
|
-
}
|
|
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
|
|
548
530
|
};
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
const maxH = needsClamp ? Math.max(availableH, 60) : null;
|
|
553
|
-
return { top, left, ...maxH != null && { maxHeight: maxH } };
|
|
531
|
+
const fits = (dir) => {
|
|
532
|
+
if (dir === "top" || dir === "bottom") return space[dir] >= popoverH;
|
|
533
|
+
return space[dir] >= popoverW;
|
|
554
534
|
};
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
535
|
+
const buildResult = (dir) => {
|
|
536
|
+
let offsetX = 0;
|
|
537
|
+
let offsetY = 0;
|
|
538
|
+
let maxHeight = void 0;
|
|
539
|
+
if (dir === "top" || dir === "bottom") {
|
|
540
|
+
const popoverRight = rect.left + popoverW;
|
|
541
|
+
if (popoverRight > vw - EDGE_MARGIN) {
|
|
542
|
+
offsetX = vw - EDGE_MARGIN - popoverRight;
|
|
543
|
+
}
|
|
544
|
+
if (rect.left + offsetX < EDGE_MARGIN) {
|
|
545
|
+
offsetX = EDGE_MARGIN - rect.left;
|
|
546
|
+
}
|
|
547
|
+
if (space[dir] < popoverH) {
|
|
548
|
+
maxHeight = Math.max(space[dir], 60);
|
|
549
|
+
}
|
|
550
|
+
} else {
|
|
551
|
+
const popoverBottom = rect.top + popoverH;
|
|
552
|
+
if (popoverBottom > vh - EDGE_MARGIN) {
|
|
553
|
+
offsetY = vh - EDGE_MARGIN - popoverBottom;
|
|
554
|
+
}
|
|
555
|
+
if (rect.top + offsetY < EDGE_MARGIN) {
|
|
556
|
+
offsetY = EDGE_MARGIN - rect.top;
|
|
557
|
+
}
|
|
570
558
|
}
|
|
571
|
-
return {
|
|
559
|
+
return { dir, offsetX, offsetY, ...maxHeight != null && { maxHeight } };
|
|
572
560
|
};
|
|
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
|
-
}
|
|
561
|
+
if (preferred && fits(preferred)) return buildResult(preferred);
|
|
598
562
|
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
|
-
}
|
|
563
|
+
for (const d of order) {
|
|
564
|
+
if (fits(d)) return buildResult(d);
|
|
605
565
|
}
|
|
606
|
-
const best = [
|
|
607
|
-
|
|
608
|
-
{ dir: "top", space: spaceTop },
|
|
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;
|
|
566
|
+
const best = Object.entries(space).sort((a, b) => b[1] - a[1])[0][0];
|
|
567
|
+
return buildResult(best);
|
|
615
568
|
};
|
|
616
569
|
var WT_CONTAINER_ID = "wt-portal-root";
|
|
617
570
|
var getPortalContainer = () => {
|
|
@@ -643,7 +596,7 @@ var WalkthroughOverlay = ({
|
|
|
643
596
|
prevColor,
|
|
644
597
|
skipColor
|
|
645
598
|
} = {}) => {
|
|
646
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
599
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
647
600
|
injectKeyframes();
|
|
648
601
|
const { activeTour } = useGlobalState();
|
|
649
602
|
const instanceIdRef = react.useRef(null);
|
|
@@ -825,14 +778,14 @@ var WalkthroughOverlay = ({
|
|
|
825
778
|
return;
|
|
826
779
|
}
|
|
827
780
|
const measured = popoverRef.current.getBoundingClientRect();
|
|
828
|
-
const
|
|
781
|
+
const dirInfo = choosePopoverDir(
|
|
829
782
|
rect,
|
|
830
783
|
measured.width,
|
|
831
784
|
measured.height,
|
|
832
785
|
$popoverGap,
|
|
833
786
|
step.position
|
|
834
787
|
);
|
|
835
|
-
setPopoverPos(
|
|
788
|
+
setPopoverPos(dirInfo);
|
|
836
789
|
}, [rect, step, $popoverGap, isAnimating]);
|
|
837
790
|
react.useEffect(() => {
|
|
838
791
|
if (nextBtnRef.current) {
|
|
@@ -1077,18 +1030,41 @@ var WalkthroughOverlay = ({
|
|
|
1077
1030
|
displayPosRef.current = currentValidPos;
|
|
1078
1031
|
}
|
|
1079
1032
|
const ds = displayStepRef.current;
|
|
1033
|
+
const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
|
|
1034
|
+
const offsetX = (_j = popoverPos == null ? void 0 : popoverPos.offsetX) != null ? _j : 0;
|
|
1035
|
+
const offsetY = (_k = popoverPos == null ? void 0 : popoverPos.offsetY) != null ? _k : 0;
|
|
1036
|
+
const anchorStyle = popoverReady ? {
|
|
1037
|
+
position: "fixed",
|
|
1038
|
+
top: rect.top,
|
|
1039
|
+
left: rect.left,
|
|
1040
|
+
width: rect.width,
|
|
1041
|
+
height: rect.height,
|
|
1042
|
+
pointerEvents: "none",
|
|
1043
|
+
zIndex: 99999
|
|
1044
|
+
} : {
|
|
1045
|
+
position: "fixed",
|
|
1046
|
+
top: -9999,
|
|
1047
|
+
left: -9999,
|
|
1048
|
+
pointerEvents: "none",
|
|
1049
|
+
zIndex: 99999
|
|
1050
|
+
};
|
|
1051
|
+
const dirStyles = {
|
|
1052
|
+
bottom: { top: `calc(100% + ${$popoverGap}px)`, left: offsetX },
|
|
1053
|
+
top: { bottom: `calc(100% + ${$popoverGap}px)`, left: offsetX },
|
|
1054
|
+
right: { top: offsetY, left: `calc(100% + ${$popoverGap}px)` },
|
|
1055
|
+
left: { top: offsetY, right: `calc(100% + ${$popoverGap}px)` }
|
|
1056
|
+
};
|
|
1057
|
+
const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
|
|
1080
1058
|
const popoverStyle = popoverReady ? {
|
|
1081
|
-
|
|
1082
|
-
|
|
1059
|
+
position: "absolute",
|
|
1060
|
+
...dirStyles[dir],
|
|
1083
1061
|
width: popoverWidth,
|
|
1084
1062
|
minWidth: $popoverMinWidth,
|
|
1085
1063
|
padding: $popoverPadding,
|
|
1086
1064
|
borderRadius: $popoverBorderRadius,
|
|
1087
1065
|
fontFamily: "inherit",
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
overflowY: "auto"
|
|
1091
|
-
}
|
|
1066
|
+
pointerEvents: "auto",
|
|
1067
|
+
...maxHeightStyle
|
|
1092
1068
|
} : {
|
|
1093
1069
|
position: "fixed",
|
|
1094
1070
|
top: -9999,
|
|
@@ -1144,11 +1120,11 @@ var WalkthroughOverlay = ({
|
|
|
1144
1120
|
}
|
|
1145
1121
|
)
|
|
1146
1122
|
] }) }),
|
|
1147
|
-
/* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1123
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: anchorStyle, children: /* @__PURE__ */ jsxRuntime.jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1148
1124
|
/* @__PURE__ */ jsxRuntime.jsxs(PopoverBody, { children: [
|
|
1149
1125
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
|
|
1150
1126
|
pStep.title ? /* @__PURE__ */ jsxRuntime.jsx(PopoverTitle, { children: pStep.title }) : "",
|
|
1151
|
-
((
|
|
1127
|
+
((_l = pStep.isShowStep) != null ? _l : pIsShowStep) && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
|
|
1152
1128
|
pDisplayCurrentStep,
|
|
1153
1129
|
"/",
|
|
1154
1130
|
pDisplayTotalSteps
|
|
@@ -1173,7 +1149,7 @@ var WalkthroughOverlay = ({
|
|
|
1173
1149
|
}
|
|
1174
1150
|
) }),
|
|
1175
1151
|
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { children: [
|
|
1176
|
-
((
|
|
1152
|
+
((_m = pStep.isShowPrev) != null ? _m : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1177
1153
|
"button",
|
|
1178
1154
|
{
|
|
1179
1155
|
className: "wt-btn",
|
|
@@ -1194,7 +1170,7 @@ var WalkthroughOverlay = ({
|
|
|
1194
1170
|
)
|
|
1195
1171
|
] })
|
|
1196
1172
|
] })
|
|
1197
|
-
] })
|
|
1173
|
+
] }) })
|
|
1198
1174
|
] });
|
|
1199
1175
|
return reactDom.createPortal(
|
|
1200
1176
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ...portalEventHandlers, style: { pointerEvents: "auto" }, children: overlay }),
|