@tent-official/react-walkthrough 1.1.97 → 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 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -517,73 +517,27 @@ var clampSize = (value, max) => {
|
|
|
517
517
|
return clamped;
|
|
518
518
|
};
|
|
519
519
|
var EDGE_MARGIN = 8;
|
|
520
|
-
var
|
|
520
|
+
var choosePopoverDir = (rect, popoverW, popoverH, gap, preferred) => {
|
|
521
521
|
const vw = window.innerWidth;
|
|
522
522
|
const vh = window.innerHeight;
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
const spaceLeft = rect.left - gap - EDGE_MARGIN;
|
|
529
|
-
const positions = {
|
|
530
|
-
bottom: {
|
|
531
|
-
top: rect.top + rect.height + gap,
|
|
532
|
-
left: clampLeft(rect.left)
|
|
533
|
-
},
|
|
534
|
-
top: {
|
|
535
|
-
top: rect.top - popoverH - gap,
|
|
536
|
-
left: clampLeft(rect.left)
|
|
537
|
-
},
|
|
538
|
-
right: {
|
|
539
|
-
top: clampTopH(rect.top),
|
|
540
|
-
left: rect.left + rect.width + gap
|
|
541
|
-
},
|
|
542
|
-
left: {
|
|
543
|
-
top: clampTopH(rect.top),
|
|
544
|
-
left: rect.left - popoverW - gap
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
const fitsInViewport = (pos) => pos.top >= EDGE_MARGIN && pos.left >= EDGE_MARGIN && pos.top + popoverH <= vh - EDGE_MARGIN && pos.left + popoverW <= vw - EDGE_MARGIN;
|
|
548
|
-
const buildResult = (top, left, availableH) => {
|
|
549
|
-
const needsClamp = availableH < popoverH;
|
|
550
|
-
const maxH = needsClamp ? Math.max(availableH, 60) : null;
|
|
551
|
-
return { top, left, ...maxH != null && { maxHeight: maxH } };
|
|
523
|
+
const space = {
|
|
524
|
+
bottom: vh - (rect.top + rect.height + gap) - EDGE_MARGIN,
|
|
525
|
+
top: rect.top - gap - EDGE_MARGIN,
|
|
526
|
+
right: vw - (rect.left + rect.width + gap) - EDGE_MARGIN,
|
|
527
|
+
left: rect.left - gap - EDGE_MARGIN
|
|
552
528
|
};
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const anchorTop = rect.top + rect.height + gap;
|
|
557
|
-
return buildResult(anchorTop, clampLeft(pos.left), vh - anchorTop - EDGE_MARGIN);
|
|
558
|
-
}
|
|
559
|
-
if (dir === "top") {
|
|
560
|
-
const availH = spaceTop;
|
|
561
|
-
const effectiveH = Math.min(popoverH, availH);
|
|
562
|
-
const anchorTop = rect.top - gap - effectiveH;
|
|
563
|
-
const finalTop = Math.max(EDGE_MARGIN, anchorTop);
|
|
564
|
-
return buildResult(finalTop, clampLeft(pos.left), availH);
|
|
565
|
-
}
|
|
566
|
-
if (dir === "right" || dir === "left") {
|
|
567
|
-
return buildResult(clampTopH(pos.top), pos.left, vh - EDGE_MARGIN * 2);
|
|
568
|
-
}
|
|
569
|
-
return { top: pos.top, left: pos.left };
|
|
529
|
+
const fits = (dir) => {
|
|
530
|
+
if (dir === "top" || dir === "bottom") return space[dir] >= popoverH;
|
|
531
|
+
return space[dir] >= popoverW;
|
|
570
532
|
};
|
|
571
|
-
if (preferred &&
|
|
572
|
-
return buildForDir(preferred);
|
|
573
|
-
}
|
|
533
|
+
if (preferred && fits(preferred)) return { dir: preferred };
|
|
574
534
|
const order = ["bottom", "top", "right", "left"];
|
|
575
|
-
for (const
|
|
576
|
-
if (
|
|
577
|
-
return buildForDir(dir);
|
|
578
|
-
}
|
|
535
|
+
for (const d of order) {
|
|
536
|
+
if (fits(d)) return { dir: d };
|
|
579
537
|
}
|
|
580
|
-
const best = [
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
{ dir: "right", space: spaceRight },
|
|
584
|
-
{ dir: "left", space: spaceLeft }
|
|
585
|
-
].sort((a, b) => b.space - a.space)[0].dir;
|
|
586
|
-
return buildForDir(best);
|
|
538
|
+
const best = Object.entries(space).sort((a, b) => b[1] - a[1])[0][0];
|
|
539
|
+
const maxH = best === "top" || best === "bottom" ? Math.max(space[best], 60) : Math.max(vh - EDGE_MARGIN * 2, 60);
|
|
540
|
+
return { dir: best, maxHeight: maxH };
|
|
587
541
|
};
|
|
588
542
|
var WT_CONTAINER_ID = "wt-portal-root";
|
|
589
543
|
var getPortalContainer = () => {
|
|
@@ -615,7 +569,7 @@ var WalkthroughOverlay = ({
|
|
|
615
569
|
prevColor,
|
|
616
570
|
skipColor
|
|
617
571
|
} = {}) => {
|
|
618
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
572
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
619
573
|
injectKeyframes();
|
|
620
574
|
const { activeTour } = useGlobalState();
|
|
621
575
|
const instanceIdRef = useRef(null);
|
|
@@ -797,14 +751,14 @@ var WalkthroughOverlay = ({
|
|
|
797
751
|
return;
|
|
798
752
|
}
|
|
799
753
|
const measured = popoverRef.current.getBoundingClientRect();
|
|
800
|
-
const
|
|
754
|
+
const dirInfo = choosePopoverDir(
|
|
801
755
|
rect,
|
|
802
756
|
measured.width,
|
|
803
757
|
measured.height,
|
|
804
758
|
$popoverGap,
|
|
805
759
|
step.position
|
|
806
760
|
);
|
|
807
|
-
setPopoverPos(
|
|
761
|
+
setPopoverPos(dirInfo);
|
|
808
762
|
}, [rect, step, $popoverGap, isAnimating]);
|
|
809
763
|
useEffect(() => {
|
|
810
764
|
if (nextBtnRef.current) {
|
|
@@ -1049,18 +1003,39 @@ var WalkthroughOverlay = ({
|
|
|
1049
1003
|
displayPosRef.current = currentValidPos;
|
|
1050
1004
|
}
|
|
1051
1005
|
const ds = displayStepRef.current;
|
|
1006
|
+
const dir = (_i = popoverPos == null ? void 0 : popoverPos.dir) != null ? _i : "bottom";
|
|
1007
|
+
const anchorStyle = popoverReady ? {
|
|
1008
|
+
position: "fixed",
|
|
1009
|
+
top: rect.top,
|
|
1010
|
+
left: rect.left,
|
|
1011
|
+
width: rect.width,
|
|
1012
|
+
height: rect.height,
|
|
1013
|
+
pointerEvents: "none",
|
|
1014
|
+
zIndex: 99999
|
|
1015
|
+
} : {
|
|
1016
|
+
position: "fixed",
|
|
1017
|
+
top: -9999,
|
|
1018
|
+
left: -9999,
|
|
1019
|
+
pointerEvents: "none",
|
|
1020
|
+
zIndex: 99999
|
|
1021
|
+
};
|
|
1022
|
+
const dirStyles = {
|
|
1023
|
+
bottom: { top: `calc(100% + ${$popoverGap}px)`, left: 0 },
|
|
1024
|
+
top: { bottom: `calc(100% + ${$popoverGap}px)`, left: 0 },
|
|
1025
|
+
right: { top: 0, left: `calc(100% + ${$popoverGap}px)` },
|
|
1026
|
+
left: { top: 0, right: `calc(100% + ${$popoverGap}px)` }
|
|
1027
|
+
};
|
|
1028
|
+
const maxHeightStyle = (popoverPos == null ? void 0 : popoverPos.maxHeight) != null ? { maxHeight: popoverPos.maxHeight, overflowY: "auto" } : {};
|
|
1052
1029
|
const popoverStyle = popoverReady ? {
|
|
1053
|
-
|
|
1054
|
-
|
|
1030
|
+
position: "absolute",
|
|
1031
|
+
...dirStyles[dir],
|
|
1055
1032
|
width: popoverWidth,
|
|
1056
1033
|
minWidth: $popoverMinWidth,
|
|
1057
1034
|
padding: $popoverPadding,
|
|
1058
1035
|
borderRadius: $popoverBorderRadius,
|
|
1059
1036
|
fontFamily: "inherit",
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
overflowY: "auto"
|
|
1063
|
-
}
|
|
1037
|
+
pointerEvents: "auto",
|
|
1038
|
+
...maxHeightStyle
|
|
1064
1039
|
} : {
|
|
1065
1040
|
position: "fixed",
|
|
1066
1041
|
top: -9999,
|
|
@@ -1116,11 +1091,11 @@ var WalkthroughOverlay = ({
|
|
|
1116
1091
|
}
|
|
1117
1092
|
)
|
|
1118
1093
|
] }) }),
|
|
1119
|
-
/* @__PURE__ */ jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1094
|
+
/* @__PURE__ */ jsx("div", { style: anchorStyle, children: /* @__PURE__ */ jsxs(PopoverContainer, { ref: popoverRef, style: popoverStyle, children: [
|
|
1120
1095
|
/* @__PURE__ */ jsxs(PopoverBody, { children: [
|
|
1121
1096
|
/* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "row", justifyContent: "space-between" }, children: [
|
|
1122
1097
|
pStep.title ? /* @__PURE__ */ jsx(PopoverTitle, { children: pStep.title }) : "",
|
|
1123
|
-
((
|
|
1098
|
+
((_j = pStep.isShowStep) != null ? _j : pIsShowStep) && /* @__PURE__ */ jsxs("span", { style: { color: "#a1a1aa", fontSize: "12px", fontWeight: "400" }, children: [
|
|
1124
1099
|
pDisplayCurrentStep,
|
|
1125
1100
|
"/",
|
|
1126
1101
|
pDisplayTotalSteps
|
|
@@ -1145,7 +1120,7 @@ var WalkthroughOverlay = ({
|
|
|
1145
1120
|
}
|
|
1146
1121
|
) }),
|
|
1147
1122
|
/* @__PURE__ */ jsxs(ButtonGroup, { children: [
|
|
1148
|
-
((
|
|
1123
|
+
((_k = pStep.isShowPrev) != null ? _k : pIsShowPrev) && pCurrentValidPos > 0 && /* @__PURE__ */ jsx(
|
|
1149
1124
|
"button",
|
|
1150
1125
|
{
|
|
1151
1126
|
className: "wt-btn",
|
|
@@ -1166,7 +1141,7 @@ var WalkthroughOverlay = ({
|
|
|
1166
1141
|
)
|
|
1167
1142
|
] })
|
|
1168
1143
|
] })
|
|
1169
|
-
] })
|
|
1144
|
+
] }) })
|
|
1170
1145
|
] });
|
|
1171
1146
|
return createPortal(
|
|
1172
1147
|
/* @__PURE__ */ jsx("div", { ...portalEventHandlers, style: { pointerEvents: "auto" }, children: overlay }),
|