@tent-official/react-walkthrough 1.4.2 → 1.5.1
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/README.md +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -965,43 +965,6 @@ var WalkthroughOverlay = ({
|
|
|
965
965
|
setPopoverPos(null);
|
|
966
966
|
const nextValidStep = validSteps[currentValidPos + 1];
|
|
967
967
|
const nextOrigIdx = hasTrigger && !nextValidStep ? currentOrigIdx + 1 : (_a2 = nextValidStep == null ? void 0 : nextValidStep._originalIdx) != null ? _a2 : currentOrigIdx + 1;
|
|
968
|
-
const shouldForceRecompute = !!step.forceRecompute;
|
|
969
|
-
if (shouldForceRecompute) {
|
|
970
|
-
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
971
|
-
if (nextStepDef) {
|
|
972
|
-
const nextElId = resolveElId(nextStepDef.el);
|
|
973
|
-
const SETTLE_DELAY = 150;
|
|
974
|
-
const doAdvance = () => {
|
|
975
|
-
setGlobalState((s) => ({
|
|
976
|
-
...s,
|
|
977
|
-
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
978
|
-
}));
|
|
979
|
-
};
|
|
980
|
-
const alreadyExists = document.getElementById(nextElId);
|
|
981
|
-
if (alreadyExists) {
|
|
982
|
-
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
983
|
-
} else {
|
|
984
|
-
waitingForElsRef.current = true;
|
|
985
|
-
const observer = new MutationObserver(() => {
|
|
986
|
-
const found = document.getElementById(nextElId);
|
|
987
|
-
if (found) {
|
|
988
|
-
observer.disconnect();
|
|
989
|
-
waitingForElsRef.current = false;
|
|
990
|
-
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
994
|
-
setTimeout(() => {
|
|
995
|
-
observer.disconnect();
|
|
996
|
-
if (waitingForElsRef.current) {
|
|
997
|
-
waitingForElsRef.current = false;
|
|
998
|
-
doAdvance();
|
|
999
|
-
}
|
|
1000
|
-
}, 3e3);
|
|
1001
|
-
}
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
968
|
setGlobalState((s) => ({
|
|
1006
969
|
...s,
|
|
1007
970
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -1017,6 +980,7 @@ var WalkthroughOverlay = ({
|
|
|
1017
980
|
}
|
|
1018
981
|
const hasTrigger = !!step.triggerElOnNext;
|
|
1019
982
|
const afterNextDelay = (_b2 = step.delayAfterNext) != null ? _b2 : 0;
|
|
983
|
+
const nextElId = step.nextEl ? resolveElId(step.nextEl) : null;
|
|
1020
984
|
const withDelay = (fn) => {
|
|
1021
985
|
if (afterNextDelay > 0) {
|
|
1022
986
|
setTimeout(fn, afterNextDelay);
|
|
@@ -1024,6 +988,43 @@ var WalkthroughOverlay = ({
|
|
|
1024
988
|
fn();
|
|
1025
989
|
}
|
|
1026
990
|
};
|
|
991
|
+
const advanceWithNextEl = () => {
|
|
992
|
+
const SETTLE_DELAY = 150;
|
|
993
|
+
const targetEl = document.getElementById(nextElId);
|
|
994
|
+
if (targetEl) {
|
|
995
|
+
let targetStepIdx = -1;
|
|
996
|
+
for (let i = currentOrigIdx + 1; i < activeTour.steps.length; i++) {
|
|
997
|
+
if (resolveElId(activeTour.steps[i].el) === nextElId) {
|
|
998
|
+
targetStepIdx = i;
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (targetStepIdx !== -1) {
|
|
1003
|
+
const targetStepDef = activeTour.steps[targetStepIdx];
|
|
1004
|
+
const targetStepWithIdx = { ...targetStepDef, _originalIdx: targetStepIdx };
|
|
1005
|
+
const alreadyInValid = validSteps.some((s) => s._originalIdx === targetStepIdx);
|
|
1006
|
+
const newValidSteps = alreadyInValid ? validSteps : [...validSteps, targetStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
|
|
1007
|
+
setValidSteps(newValidSteps);
|
|
1008
|
+
skipNextRecomputeRef.current = true;
|
|
1009
|
+
setTimeout(() => {
|
|
1010
|
+
setGlobalState((s) => ({
|
|
1011
|
+
...s,
|
|
1012
|
+
activeTour: { ...s.activeTour, currentStep: targetStepIdx }
|
|
1013
|
+
}));
|
|
1014
|
+
}, SETTLE_DELAY);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const nextValid = validSteps.find((s) => s._originalIdx > currentOrigIdx);
|
|
1019
|
+
if (nextValid) {
|
|
1020
|
+
setGlobalState((s) => ({
|
|
1021
|
+
...s,
|
|
1022
|
+
activeTour: { ...s.activeTour, currentStep: nextValid._originalIdx }
|
|
1023
|
+
}));
|
|
1024
|
+
} else {
|
|
1025
|
+
completeTour();
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1027
1028
|
if (hasTrigger) {
|
|
1028
1029
|
setPopoverHidden(true);
|
|
1029
1030
|
setPopoverPos(null);
|
|
@@ -1035,11 +1036,14 @@ var WalkthroughOverlay = ({
|
|
|
1035
1036
|
triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
|
1036
1037
|
triggerTarget.click();
|
|
1037
1038
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1039
|
+
if (nextElId) {
|
|
1040
|
+
withDelay(() => advanceWithNextEl());
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const nextOrigIdx = currentOrigIdx + 1;
|
|
1040
1044
|
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
1041
1045
|
if (nextStepDef) {
|
|
1042
|
-
const
|
|
1046
|
+
const nextStepElId = resolveElId(nextStepDef.el);
|
|
1043
1047
|
const injectAndAdvance = () => {
|
|
1044
1048
|
const nextStepWithIdx = { ...nextStepDef, _originalIdx: nextOrigIdx };
|
|
1045
1049
|
const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
|
|
@@ -1050,27 +1054,15 @@ var WalkthroughOverlay = ({
|
|
|
1050
1054
|
...s,
|
|
1051
1055
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
1052
1056
|
}));
|
|
1053
|
-
if (step.forceRecompute) {
|
|
1054
|
-
setTimeout(() => {
|
|
1055
|
-
skipNextRecomputeRef.current = false;
|
|
1056
|
-
setGlobalState((s) => {
|
|
1057
|
-
if (!s.activeTour) return s;
|
|
1058
|
-
return {
|
|
1059
|
-
...s,
|
|
1060
|
-
activeTour: { ...s.activeTour, _recompute: Date.now() }
|
|
1061
|
-
};
|
|
1062
|
-
});
|
|
1063
|
-
}, 500);
|
|
1064
|
-
}
|
|
1065
1057
|
};
|
|
1066
1058
|
const SETTLE_DELAY = 150;
|
|
1067
|
-
const alreadyExists = document.getElementById(
|
|
1059
|
+
const alreadyExists = document.getElementById(nextStepElId);
|
|
1068
1060
|
if (alreadyExists) {
|
|
1069
1061
|
withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
|
|
1070
1062
|
} else {
|
|
1071
1063
|
waitingForElsRef.current = true;
|
|
1072
1064
|
const observer = new MutationObserver(() => {
|
|
1073
|
-
const found = document.getElementById(
|
|
1065
|
+
const found = document.getElementById(nextStepElId);
|
|
1074
1066
|
if (found) {
|
|
1075
1067
|
observer.disconnect();
|
|
1076
1068
|
waitingForElsRef.current = false;
|
|
@@ -1093,6 +1085,12 @@ var WalkthroughOverlay = ({
|
|
|
1093
1085
|
setTimeout(() => completeTour(), 300);
|
|
1094
1086
|
return;
|
|
1095
1087
|
}
|
|
1088
|
+
if (nextElId) {
|
|
1089
|
+
setPopoverHidden(true);
|
|
1090
|
+
setPopoverPos(null);
|
|
1091
|
+
withDelay(() => advanceWithNextEl());
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1096
1094
|
if (afterNextDelay > 0) {
|
|
1097
1095
|
setPopoverHidden(true);
|
|
1098
1096
|
setPopoverPos(null);
|