@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/README.md
CHANGED
|
@@ -118,8 +118,8 @@ Hook to register a walkthrough tour.
|
|
|
118
118
|
| `skipLabel` | `string` | — | Override tour-level `skipLabel` for this step |
|
|
119
119
|
| `displayStep` | `number` | — | Override the displayed step number for this step (display-only) |
|
|
120
120
|
| `displayTotal` | `number` | — | Override the displayed total for this step (display-only) |
|
|
121
|
-
| `forceRecompute` | `boolean` | — | When `true`, forces a DOM re-read before advancing to the next step. Useful when the next element is conditionally rendered and needs a layout update to appear |
|
|
122
121
|
| `delayAfterNext` | `number` | `0` | Delay in ms after clicking "Next" (after `onStepNext` and `triggerElOnNext` have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay |
|
|
122
|
+
| `nextEl` | `string` | — | DOM element ID to look for after `delayAfterNext` completes. If found, advances to the step that owns it. If not found, skips to the next valid step. Supports `#id` or `id` format |
|
|
123
123
|
|
|
124
124
|
### `IStepDescription`
|
|
125
125
|
|
package/dist/index.d.mts
CHANGED
|
@@ -59,10 +59,10 @@ interface IWalkthroughStep {
|
|
|
59
59
|
displayStep?: number;
|
|
60
60
|
/** Override the displayed total step count for this specific step (display-only, does not affect logic). If omitted, uses the tour-level displayTotal or actual count */
|
|
61
61
|
displayTotal?: number;
|
|
62
|
-
/** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
|
|
63
|
-
forceRecompute?: boolean;
|
|
64
62
|
/** Delay in milliseconds after clicking "Next" (after onStepNext and triggerElOnNext have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay. Default: 0 (no delay) */
|
|
65
63
|
delayAfterNext?: number;
|
|
64
|
+
/** DOM element ID to look for after delayAfterNext completes. If the element is found in the DOM, the tour advances to the step that owns it. If not found, the step is skipped and the tour moves to the next valid step. Supports "#id" or "id" format. */
|
|
65
|
+
nextEl?: string;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Options for the useWalkthrough hook.
|
package/dist/index.d.ts
CHANGED
|
@@ -59,10 +59,10 @@ interface IWalkthroughStep {
|
|
|
59
59
|
displayStep?: number;
|
|
60
60
|
/** Override the displayed total step count for this specific step (display-only, does not affect logic). If omitted, uses the tour-level displayTotal or actual count */
|
|
61
61
|
displayTotal?: number;
|
|
62
|
-
/** When true, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible. Default: false */
|
|
63
|
-
forceRecompute?: boolean;
|
|
64
62
|
/** Delay in milliseconds after clicking "Next" (after onStepNext and triggerElOnNext have fired) before advancing to the next step. The overlay stays visible with the popover hidden during the delay. Default: 0 (no delay) */
|
|
65
63
|
delayAfterNext?: number;
|
|
64
|
+
/** DOM element ID to look for after delayAfterNext completes. If the element is found in the DOM, the tour advances to the step that owns it. If not found, the step is skipped and the tour moves to the next valid step. Supports "#id" or "id" format. */
|
|
65
|
+
nextEl?: string;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Options for the useWalkthrough hook.
|
package/dist/index.js
CHANGED
|
@@ -967,43 +967,6 @@ var WalkthroughOverlay = ({
|
|
|
967
967
|
setPopoverPos(null);
|
|
968
968
|
const nextValidStep = validSteps[currentValidPos + 1];
|
|
969
969
|
const nextOrigIdx = hasTrigger && !nextValidStep ? currentOrigIdx + 1 : (_a2 = nextValidStep == null ? void 0 : nextValidStep._originalIdx) != null ? _a2 : currentOrigIdx + 1;
|
|
970
|
-
const shouldForceRecompute = !!step.forceRecompute;
|
|
971
|
-
if (shouldForceRecompute) {
|
|
972
|
-
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
973
|
-
if (nextStepDef) {
|
|
974
|
-
const nextElId = resolveElId(nextStepDef.el);
|
|
975
|
-
const SETTLE_DELAY = 150;
|
|
976
|
-
const doAdvance = () => {
|
|
977
|
-
setGlobalState((s) => ({
|
|
978
|
-
...s,
|
|
979
|
-
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
980
|
-
}));
|
|
981
|
-
};
|
|
982
|
-
const alreadyExists = document.getElementById(nextElId);
|
|
983
|
-
if (alreadyExists) {
|
|
984
|
-
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
985
|
-
} else {
|
|
986
|
-
waitingForElsRef.current = true;
|
|
987
|
-
const observer = new MutationObserver(() => {
|
|
988
|
-
const found = document.getElementById(nextElId);
|
|
989
|
-
if (found) {
|
|
990
|
-
observer.disconnect();
|
|
991
|
-
waitingForElsRef.current = false;
|
|
992
|
-
setTimeout(() => doAdvance(), SETTLE_DELAY);
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
996
|
-
setTimeout(() => {
|
|
997
|
-
observer.disconnect();
|
|
998
|
-
if (waitingForElsRef.current) {
|
|
999
|
-
waitingForElsRef.current = false;
|
|
1000
|
-
doAdvance();
|
|
1001
|
-
}
|
|
1002
|
-
}, 3e3);
|
|
1003
|
-
}
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
970
|
setGlobalState((s) => ({
|
|
1008
971
|
...s,
|
|
1009
972
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
@@ -1019,6 +982,7 @@ var WalkthroughOverlay = ({
|
|
|
1019
982
|
}
|
|
1020
983
|
const hasTrigger = !!step.triggerElOnNext;
|
|
1021
984
|
const afterNextDelay = (_b2 = step.delayAfterNext) != null ? _b2 : 0;
|
|
985
|
+
const nextElId = step.nextEl ? resolveElId(step.nextEl) : null;
|
|
1022
986
|
const withDelay = (fn) => {
|
|
1023
987
|
if (afterNextDelay > 0) {
|
|
1024
988
|
setTimeout(fn, afterNextDelay);
|
|
@@ -1026,6 +990,43 @@ var WalkthroughOverlay = ({
|
|
|
1026
990
|
fn();
|
|
1027
991
|
}
|
|
1028
992
|
};
|
|
993
|
+
const advanceWithNextEl = () => {
|
|
994
|
+
const SETTLE_DELAY = 150;
|
|
995
|
+
const targetEl = document.getElementById(nextElId);
|
|
996
|
+
if (targetEl) {
|
|
997
|
+
let targetStepIdx = -1;
|
|
998
|
+
for (let i = currentOrigIdx + 1; i < activeTour.steps.length; i++) {
|
|
999
|
+
if (resolveElId(activeTour.steps[i].el) === nextElId) {
|
|
1000
|
+
targetStepIdx = i;
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (targetStepIdx !== -1) {
|
|
1005
|
+
const targetStepDef = activeTour.steps[targetStepIdx];
|
|
1006
|
+
const targetStepWithIdx = { ...targetStepDef, _originalIdx: targetStepIdx };
|
|
1007
|
+
const alreadyInValid = validSteps.some((s) => s._originalIdx === targetStepIdx);
|
|
1008
|
+
const newValidSteps = alreadyInValid ? validSteps : [...validSteps, targetStepWithIdx].sort((a, b) => a._originalIdx - b._originalIdx);
|
|
1009
|
+
setValidSteps(newValidSteps);
|
|
1010
|
+
skipNextRecomputeRef.current = true;
|
|
1011
|
+
setTimeout(() => {
|
|
1012
|
+
setGlobalState((s) => ({
|
|
1013
|
+
...s,
|
|
1014
|
+
activeTour: { ...s.activeTour, currentStep: targetStepIdx }
|
|
1015
|
+
}));
|
|
1016
|
+
}, SETTLE_DELAY);
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const nextValid = validSteps.find((s) => s._originalIdx > currentOrigIdx);
|
|
1021
|
+
if (nextValid) {
|
|
1022
|
+
setGlobalState((s) => ({
|
|
1023
|
+
...s,
|
|
1024
|
+
activeTour: { ...s.activeTour, currentStep: nextValid._originalIdx }
|
|
1025
|
+
}));
|
|
1026
|
+
} else {
|
|
1027
|
+
completeTour();
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1029
1030
|
if (hasTrigger) {
|
|
1030
1031
|
setPopoverHidden(true);
|
|
1031
1032
|
setPopoverPos(null);
|
|
@@ -1037,11 +1038,14 @@ var WalkthroughOverlay = ({
|
|
|
1037
1038
|
triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
|
1038
1039
|
triggerTarget.click();
|
|
1039
1040
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1041
|
+
if (nextElId) {
|
|
1042
|
+
withDelay(() => advanceWithNextEl());
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const nextOrigIdx = currentOrigIdx + 1;
|
|
1042
1046
|
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
1043
1047
|
if (nextStepDef) {
|
|
1044
|
-
const
|
|
1048
|
+
const nextStepElId = resolveElId(nextStepDef.el);
|
|
1045
1049
|
const injectAndAdvance = () => {
|
|
1046
1050
|
const nextStepWithIdx = { ...nextStepDef, _originalIdx: nextOrigIdx };
|
|
1047
1051
|
const alreadyInValid = validSteps.some((s) => s._originalIdx === nextOrigIdx);
|
|
@@ -1052,27 +1056,15 @@ var WalkthroughOverlay = ({
|
|
|
1052
1056
|
...s,
|
|
1053
1057
|
activeTour: { ...s.activeTour, currentStep: nextOrigIdx }
|
|
1054
1058
|
}));
|
|
1055
|
-
if (step.forceRecompute) {
|
|
1056
|
-
setTimeout(() => {
|
|
1057
|
-
skipNextRecomputeRef.current = false;
|
|
1058
|
-
setGlobalState((s) => {
|
|
1059
|
-
if (!s.activeTour) return s;
|
|
1060
|
-
return {
|
|
1061
|
-
...s,
|
|
1062
|
-
activeTour: { ...s.activeTour, _recompute: Date.now() }
|
|
1063
|
-
};
|
|
1064
|
-
});
|
|
1065
|
-
}, 500);
|
|
1066
|
-
}
|
|
1067
1059
|
};
|
|
1068
1060
|
const SETTLE_DELAY = 150;
|
|
1069
|
-
const alreadyExists = document.getElementById(
|
|
1061
|
+
const alreadyExists = document.getElementById(nextStepElId);
|
|
1070
1062
|
if (alreadyExists) {
|
|
1071
1063
|
withDelay(() => setTimeout(() => injectAndAdvance(), SETTLE_DELAY));
|
|
1072
1064
|
} else {
|
|
1073
1065
|
waitingForElsRef.current = true;
|
|
1074
1066
|
const observer = new MutationObserver(() => {
|
|
1075
|
-
const found = document.getElementById(
|
|
1067
|
+
const found = document.getElementById(nextStepElId);
|
|
1076
1068
|
if (found) {
|
|
1077
1069
|
observer.disconnect();
|
|
1078
1070
|
waitingForElsRef.current = false;
|
|
@@ -1095,6 +1087,12 @@ var WalkthroughOverlay = ({
|
|
|
1095
1087
|
setTimeout(() => completeTour(), 300);
|
|
1096
1088
|
return;
|
|
1097
1089
|
}
|
|
1090
|
+
if (nextElId) {
|
|
1091
|
+
setPopoverHidden(true);
|
|
1092
|
+
setPopoverPos(null);
|
|
1093
|
+
withDelay(() => advanceWithNextEl());
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1098
1096
|
if (afterNextDelay > 0) {
|
|
1099
1097
|
setPopoverHidden(true);
|
|
1100
1098
|
setPopoverPos(null);
|