@rocapine/react-native-onboarding 1.57.4 → 1.59.0
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.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/hooks/index.d.ts +1 -0
- package/dist/infra/hooks/index.d.ts.map +1 -1
- package/dist/infra/hooks/index.js +3 -1
- package/dist/infra/hooks/index.js.map +1 -1
- package/dist/infra/hooks/useOnboardingStart.d.ts +12 -0
- package/dist/infra/hooks/useOnboardingStart.d.ts.map +1 -0
- package/dist/infra/hooks/useOnboardingStart.js +23 -0
- package/dist/infra/hooks/useOnboardingStart.js.map +1 -0
- package/dist/infra/hooks/useOnboardingStep.d.ts +1 -0
- package/dist/infra/hooks/useOnboardingStep.d.ts.map +1 -1
- package/dist/infra/hooks/useOnboardingStep.js +4 -1
- package/dist/infra/hooks/useOnboardingStep.js.map +1 -1
- package/dist/infra/provider/OnboardingProvider.d.ts +31 -3
- package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
- package/dist/infra/provider/OnboardingProvider.js +20 -1
- package/dist/infra/provider/OnboardingProvider.js.map +1 -1
- package/dist/infra/provider/index.d.ts +1 -1
- package/dist/infra/provider/index.d.ts.map +1 -1
- package/dist/infra/provider/index.js.map +1 -1
- package/dist/onboarding-example.d.ts +10 -0
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +8 -0
- package/dist/onboarding-example.js.map +1 -1
- package/dist/resolveNextStepNumber.d.ts +3 -1
- package/dist/resolveNextStepNumber.d.ts.map +1 -1
- package/dist/resolveNextStepNumber.js +10 -1
- package/dist/resolveNextStepNumber.js.map +1 -1
- package/dist/resolveStartStepNumber.d.ts +14 -0
- package/dist/resolveStartStepNumber.d.ts.map +1 -0
- package/dist/resolveStartStepNumber.js +23 -0
- package/dist/resolveStartStepNumber.js.map +1 -0
- package/dist/steps/common.types.d.ts +8 -0
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +14 -2
- package/dist/steps/common.types.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/resolveNextStepNumber.test.ts +59 -0
- package/src/__tests__/resolveStartStepNumber.test.ts +41 -0
- package/src/index.ts +2 -0
- package/src/infra/hooks/index.ts +1 -0
- package/src/infra/hooks/useOnboardingStart.ts +39 -0
- package/src/infra/hooks/useOnboardingStep.ts +5 -0
- package/src/infra/provider/OnboardingProvider.tsx +57 -2
- package/src/infra/provider/index.ts +2 -0
- package/src/onboarding-example.ts +8 -0
- package/src/resolveNextStepNumber.ts +9 -1
- package/src/resolveStartStepNumber.ts +23 -0
- package/src/steps/common.types.ts +14 -1
- package/src/types.ts +7 -0
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveNextStepNumber = resolveNextStepNumber;
|
|
4
4
|
const evaluateCondition_1 = require("./evaluateCondition");
|
|
5
|
+
const common_types_1 = require("./steps/common.types");
|
|
5
6
|
/**
|
|
6
7
|
* Resolves the 1-indexed step number to navigate to after the current step.
|
|
7
|
-
* Returns null when the onboarding should end
|
|
8
|
+
* Returns null when the onboarding should end — either the branching pattern
|
|
9
|
+
* resolved to the reserved end sentinel (`ONBOARDING_END_STEP_ID`) or there is
|
|
10
|
+
* no next step (last step / no valid target).
|
|
8
11
|
*
|
|
9
12
|
* @param currentStep - The step that just completed
|
|
10
13
|
* @param variables - Global variable store (build a merged copy before calling if you just set a variable)
|
|
@@ -24,11 +27,17 @@ function resolveNextStepNumber(currentStep, variables, steps) {
|
|
|
24
27
|
if (branch.targetStepId === currentStep.id)
|
|
25
28
|
continue;
|
|
26
29
|
if (branch.condition === null || (0, evaluateCondition_1.evaluateCondition)(branch.condition, variables)) {
|
|
30
|
+
// A matching branch that targets the end sentinel ends the onboarding.
|
|
31
|
+
if (branch.targetStepId === common_types_1.ONBOARDING_END_STEP_ID)
|
|
32
|
+
return null;
|
|
27
33
|
const idx = steps.findIndex((s) => s.id === branch.targetStepId);
|
|
28
34
|
if (idx !== -1)
|
|
29
35
|
return idx + 1;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
38
|
+
// Default target ends the onboarding when it is the end sentinel.
|
|
39
|
+
if (nextStep.defaultTargetStepId === common_types_1.ONBOARDING_END_STEP_ID)
|
|
40
|
+
return null;
|
|
32
41
|
if (nextStep.defaultTargetStepId !== currentStep.id) {
|
|
33
42
|
const defaultIdx = steps.findIndex((s) => s.id === nextStep.defaultTargetStepId);
|
|
34
43
|
if (defaultIdx !== -1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveNextStepNumber.js","sourceRoot":"","sources":["../src/resolveNextStepNumber.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resolveNextStepNumber.js","sourceRoot":"","sources":["../src/resolveNextStepNumber.ts"],"names":[],"mappings":";;AAcA,sDAkCC;AA/CD,2DAAwD;AACxD,uDAA8D;AAE9D;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CACnC,WAAyB,EACzB,SAA8B,EAC9B,KAAqB;IAErB,MAAM,UAAU,GAAG,GAAkB,EAAE;QACrC,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,WAAW,CAAC,EAAE,CAAC,CAAC;QAC5D,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACvD,OAAO,GAAG,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC;IAEF,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;IAEjC,IAAI,QAAQ,IAAI,IAAI;QAAE,OAAO,UAAU,EAAE,CAAC;IAE1C,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,YAAY,KAAK,WAAW,CAAC,EAAE;YAAE,SAAS;QACrD,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,IAAI,IAAA,qCAAiB,EAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YAChF,uEAAuE;YACvE,IAAI,MAAM,CAAC,YAAY,KAAK,qCAAsB;gBAAE,OAAO,IAAI,CAAC;YAChE,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,YAAY,CAAC,CAAC;YACjE,IAAI,GAAG,KAAK,CAAC,CAAC;gBAAE,OAAO,GAAG,GAAG,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,IAAI,QAAQ,CAAC,mBAAmB,KAAK,qCAAsB;QAAE,OAAO,IAAI,CAAC;IAEzE,IAAI,QAAQ,CAAC,mBAAmB,KAAK,WAAW,CAAC,EAAE,EAAE,CAAC;QACpD,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QACjF,IAAI,UAAU,KAAK,CAAC,CAAC;YAAE,OAAO,UAAU,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseStepType } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the 1-indexed step number the onboarding should start on.
|
|
4
|
+
*
|
|
5
|
+
* Reads the (optional, unique) `startStepId` first. Falls back to the first
|
|
6
|
+
* step in the array when `startStepId` is absent or references a step that is
|
|
7
|
+
* not present — mirroring `resolveNextStepNumber`'s unknown-id guard and
|
|
8
|
+
* preserving legacy positional-start behavior.
|
|
9
|
+
*
|
|
10
|
+
* @param steps - Full ordered steps array
|
|
11
|
+
* @param startStepId - Optional id of the unique start step (from onboarding metadata)
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveStartStepNumber(steps: BaseStepType[], startStepId?: string): number;
|
|
14
|
+
//# sourceMappingURL=resolveStartStepNumber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStartStepNumber.d.ts","sourceRoot":"","sources":["../src/resolveStartStepNumber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,YAAY,EAAE,EACrB,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAMR"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveStartStepNumber = resolveStartStepNumber;
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the 1-indexed step number the onboarding should start on.
|
|
6
|
+
*
|
|
7
|
+
* Reads the (optional, unique) `startStepId` first. Falls back to the first
|
|
8
|
+
* step in the array when `startStepId` is absent or references a step that is
|
|
9
|
+
* not present — mirroring `resolveNextStepNumber`'s unknown-id guard and
|
|
10
|
+
* preserving legacy positional-start behavior.
|
|
11
|
+
*
|
|
12
|
+
* @param steps - Full ordered steps array
|
|
13
|
+
* @param startStepId - Optional id of the unique start step (from onboarding metadata)
|
|
14
|
+
*/
|
|
15
|
+
function resolveStartStepNumber(steps, startStepId) {
|
|
16
|
+
if (startStepId) {
|
|
17
|
+
const idx = steps.findIndex((s) => s.id === startStepId);
|
|
18
|
+
if (idx !== -1)
|
|
19
|
+
return idx + 1; // 1-indexed
|
|
20
|
+
}
|
|
21
|
+
return 1; // fallback: first positional step (legacy)
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=resolveStartStepNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStartStepNumber.js","sourceRoot":"","sources":["../src/resolveStartStepNumber.ts"],"names":[],"mappings":";;AAaA,wDASC;AApBD;;;;;;;;;;GAUG;AACH,SAAgB,sBAAsB,CACpC,KAAqB,EACrB,WAAoB;IAEpB,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,WAAW,CAAC,CAAC;QACzD,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,YAAY;IAC9C,CAAC;IACD,OAAO,CAAC,CAAC,CAAC,2CAA2C;AACvD,CAAC"}
|
|
@@ -211,6 +211,14 @@ export declare const NextStepSchema: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
|
211
211
|
}, z.core.$strip>>>;
|
|
212
212
|
}, z.core.$strip>>>;
|
|
213
213
|
export type NextStep = z.infer<typeof NextStepSchema>;
|
|
214
|
+
/**
|
|
215
|
+
* Reserved `targetStepId` / `defaultTargetStepId` value that ends the onboarding.
|
|
216
|
+
* When branching resolves to this sentinel, `resolveNextStepNumber` returns
|
|
217
|
+
* `null` (completion) instead of a step number — so a branch or the default
|
|
218
|
+
* target can end the flow from any step, with no trailing screen required.
|
|
219
|
+
* It is not a real step id; no step should use it as its `id`.
|
|
220
|
+
*/
|
|
221
|
+
export declare const ONBOARDING_END_STEP_ID = "__END__";
|
|
214
222
|
export declare const BaseStepTypeSchema: z.ZodObject<{
|
|
215
223
|
id: z.ZodString;
|
|
216
224
|
name: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.d.ts","sourceRoot":"","sources":["../../src/steps/common.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAA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ACrC,CAAC;AAEnC,eAAO,MAAM,oBAAoB,0IAK/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;iBAc5B,CAAC;AACL,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,KAAK,CAAC,aAAa,GAAG,cAAc,CAAC,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAO1D,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;iBAGvB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;mBAMX,CAAC;AACjB,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAIhD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa7B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseStepTypeSchema = exports.NextStepSchema = exports.BranchSchema = exports.ConditionGroupSchema = exports.LeafConditionSchema = exports.ConditionValueSchema = exports.isUnaryConditionOperator = exports.UNARY_CONDITION_OPERATORS = exports.ConditionOperatorSchema = exports.ButtonActionSchema = exports.SetVariableButtonActionSchema = exports.CustomButtonActionSchema = exports.HapticStyleSchema = exports.ButtonSectionSchema = exports.InfoBoxSchema = exports.SocialProofSchema = exports.MediaSourceSchema = exports.CustomPayloadSchema = void 0;
|
|
3
|
+
exports.BaseStepTypeSchema = exports.ONBOARDING_END_STEP_ID = exports.NextStepSchema = exports.BranchSchema = exports.ConditionGroupSchema = exports.LeafConditionSchema = exports.ConditionValueSchema = exports.isUnaryConditionOperator = exports.UNARY_CONDITION_OPERATORS = exports.ConditionOperatorSchema = exports.ButtonActionSchema = exports.SetVariableButtonActionSchema = exports.CustomButtonActionSchema = exports.HapticStyleSchema = exports.ButtonSectionSchema = exports.InfoBoxSchema = exports.SocialProofSchema = exports.MediaSourceSchema = exports.CustomPayloadSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.CustomPayloadSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any()).nullish();
|
|
6
6
|
exports.MediaSourceSchema = zod_1.z.union([
|
|
@@ -127,9 +127,21 @@ exports.NextStepSchema = zod_1.z
|
|
|
127
127
|
})
|
|
128
128
|
.nullable()
|
|
129
129
|
.default(null);
|
|
130
|
+
/**
|
|
131
|
+
* Reserved `targetStepId` / `defaultTargetStepId` value that ends the onboarding.
|
|
132
|
+
* When branching resolves to this sentinel, `resolveNextStepNumber` returns
|
|
133
|
+
* `null` (completion) instead of a step number — so a branch or the default
|
|
134
|
+
* target can end the flow from any step, with no trailing screen required.
|
|
135
|
+
* It is not a real step id; no step should use it as its `id`.
|
|
136
|
+
*/
|
|
137
|
+
exports.ONBOARDING_END_STEP_ID = "__END__";
|
|
130
138
|
// ── Base step schema ──────────────────────────────────────────────────────────
|
|
131
139
|
exports.BaseStepTypeSchema = zod_1.z.object({
|
|
132
|
-
id
|
|
140
|
+
// A step id may not collide with the reserved end sentinel — otherwise the
|
|
141
|
+
// step would be unreachable (branching to it ends the flow instead).
|
|
142
|
+
id: zod_1.z.string().refine((v) => v !== exports.ONBOARDING_END_STEP_ID, {
|
|
143
|
+
message: `"${exports.ONBOARDING_END_STEP_ID}" is reserved as the onboarding end sentinel and cannot be used as a step id`,
|
|
144
|
+
}),
|
|
133
145
|
name: zod_1.z.string(),
|
|
134
146
|
displayProgressHeader: zod_1.z.boolean(),
|
|
135
147
|
customPayload: exports.CustomPayloadSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../src/steps/common.types.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAE9D,QAAA,iBAAiB,GAAG,OAAC,CAAC,KAAK,CAAC;IACvC,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;KACxB,CAAC;IACF,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;KAChB,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;IACxB,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AAa,EAAE,2BAAmB,CAAC,QAAQ,EAAE;IAC7C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAC9B,QAAQ,EAAE,sBAAc;CACzB,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -45,6 +45,13 @@ export interface OnboardingMetadata {
|
|
|
45
45
|
audienceOrder?: number;
|
|
46
46
|
locale?: string;
|
|
47
47
|
draft?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Id of the unique step the onboarding starts on. Read first to resolve the
|
|
50
|
+
* entry point (see `resolveStartStepNumber`). Optional; when absent or when it
|
|
51
|
+
* references a missing step, the flow falls back to the first step in `steps`
|
|
52
|
+
* (legacy behavior).
|
|
53
|
+
*/
|
|
54
|
+
startStepId?: string;
|
|
48
55
|
}
|
|
49
56
|
export type FontWeightKey = "regular" | "medium" | "semibold" | "bold" | "extrabold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
|
|
50
57
|
export type FontFamilyManifest = Partial<Record<FontWeightKey, string>>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,6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CAAC;IAC/B,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,GAAG,gBAAgB,EAAE,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAEpE,MAAM,WAAW,UAAU,CAAC,QAAQ,SAAS,YAAY,GAAG,YAAY;IACtE,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.0",
|
|
4
4
|
"description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -281,6 +281,65 @@ describe("self-loop guard", () => {
|
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
// End sentinel (ONBOARDING_END_STEP_ID = "__END__")
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
describe("end sentinel target", () => {
|
|
289
|
+
it("returns null when defaultTargetStepId is the end sentinel", () => {
|
|
290
|
+
const step = makeStep("s1", {
|
|
291
|
+
nextStep: { defaultTargetStepId: "__END__", branches: [] },
|
|
292
|
+
});
|
|
293
|
+
expect(resolveNextStepNumber(step, {}, steps)).toBe(null);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("returns null when a matching branch targets the end sentinel", () => {
|
|
297
|
+
const step = makeStep("s1", {
|
|
298
|
+
nextStep: {
|
|
299
|
+
defaultTargetStepId: "s2",
|
|
300
|
+
branches: [
|
|
301
|
+
{ condition: { variable: "purchased", operator: "eq", value: "true" }, targetStepId: "__END__" },
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
expect(resolveNextStepNumber(step, { purchased: "true" }, steps)).toBe(null);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("takes a real branch over the sentinel default when the condition matches", () => {
|
|
309
|
+
const step = makeStep("s1", {
|
|
310
|
+
nextStep: {
|
|
311
|
+
defaultTargetStepId: "__END__",
|
|
312
|
+
branches: [
|
|
313
|
+
{ condition: { variable: "purchased", operator: "eq", value: "true" }, targetStepId: "s3" },
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
expect(resolveNextStepNumber(step, { purchased: "true" }, steps)).toBe(3);
|
|
318
|
+
// condition false → falls through to the sentinel default → end
|
|
319
|
+
expect(resolveNextStepNumber(step, { purchased: "false" }, steps)).toBe(null);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("ends from a sentinel branch even when the step is not positionally last", () => {
|
|
323
|
+
const step = makeStep("s2", {
|
|
324
|
+
nextStep: { defaultTargetStepId: "__END__", branches: [] },
|
|
325
|
+
});
|
|
326
|
+
expect(resolveNextStepNumber(step, {}, steps)).toBe(null);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("a non-matching sentinel branch does not end the flow", () => {
|
|
330
|
+
const step = makeStep("s1", {
|
|
331
|
+
nextStep: {
|
|
332
|
+
defaultTargetStepId: "s2",
|
|
333
|
+
branches: [
|
|
334
|
+
{ condition: { variable: "x", operator: "eq", value: "never" }, targetStepId: "__END__" },
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
// branch condition false → sentinel ignored → default target s2
|
|
339
|
+
expect(resolveNextStepNumber(step, { x: "other" }, steps)).toBe(2);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
284
343
|
// ---------------------------------------------------------------------------
|
|
285
344
|
// Edge cases
|
|
286
345
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { resolveStartStepNumber } from "../resolveStartStepNumber";
|
|
3
|
+
import type { BaseStepType } from "../types";
|
|
4
|
+
|
|
5
|
+
function makeStep(id: string, overrides: Partial<BaseStepType> = {}): BaseStepType {
|
|
6
|
+
return {
|
|
7
|
+
id,
|
|
8
|
+
type: "Question",
|
|
9
|
+
name: id,
|
|
10
|
+
displayProgressHeader: true,
|
|
11
|
+
nextStep: null,
|
|
12
|
+
...overrides,
|
|
13
|
+
} as BaseStepType;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const steps = [makeStep("s1"), makeStep("s2"), makeStep("s3")];
|
|
17
|
+
|
|
18
|
+
describe("resolveStartStepNumber", () => {
|
|
19
|
+
it("returns the 1-indexed position of the startStepId when present", () => {
|
|
20
|
+
expect(resolveStartStepNumber(steps, "s2")).toBe(2);
|
|
21
|
+
expect(resolveStartStepNumber(steps, "s3")).toBe(3);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns 1 for the first step id", () => {
|
|
25
|
+
expect(resolveStartStepNumber(steps, "s1")).toBe(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("falls back to 1 when startStepId is undefined (legacy)", () => {
|
|
29
|
+
expect(resolveStartStepNumber(steps)).toBe(1);
|
|
30
|
+
expect(resolveStartStepNumber(steps, undefined)).toBe(1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("falls back to 1 when startStepId references a missing step", () => {
|
|
34
|
+
expect(resolveStartStepNumber(steps, "does-not-exist")).toBe(1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("falls back to 1 for an empty steps array", () => {
|
|
38
|
+
expect(resolveStartStepNumber([], "s1")).toBe(1);
|
|
39
|
+
expect(resolveStartStepNumber([])).toBe(1);
|
|
40
|
+
});
|
|
41
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type { OnboardingNavigationAdapter } from "./infra/navigation/types";
|
|
|
54
54
|
export { expoRouterAdapter } from "./infra/navigation/expoRouterAdapter";
|
|
55
55
|
// Branching
|
|
56
56
|
export { resolveNextStepNumber } from "./resolveNextStepNumber";
|
|
57
|
+
export { resolveStartStepNumber } from "./resolveStartStepNumber";
|
|
57
58
|
export { evaluateCondition, evaluateLeaf, isConditionGroup } from "./evaluateCondition";
|
|
58
59
|
export type { Condition } from "./evaluateCondition";
|
|
59
60
|
export type {
|
|
@@ -74,4 +75,5 @@ export {
|
|
|
74
75
|
ConditionValueSchema,
|
|
75
76
|
UNARY_CONDITION_OPERATORS,
|
|
76
77
|
isUnaryConditionOperator,
|
|
78
|
+
ONBOARDING_END_STEP_ID,
|
|
77
79
|
} from "./steps/common.types";
|
package/src/infra/hooks/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useOnboardingStep } from "./useOnboardingStep";
|
|
2
|
+
export { useOnboardingStart } from "./useOnboardingStart";
|
|
2
3
|
export { useOnboarding } from "./useOnboarding";
|
|
3
4
|
export { useOnboardingHeaderHeight } from "./useOnboardingHeaderHeight";
|
|
4
5
|
export { useOnboardingNavigation } from "./useOnboardingNavigation";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useSuspenseQuery } from "@tanstack/react-query";
|
|
3
|
+
import { OnboardingProgressContext } from "../provider/OnboardingProvider";
|
|
4
|
+
import { getOnboardingQuery } from "../queries/getOnboarding.query";
|
|
5
|
+
import { BaseStepType, Onboarding } from "../../types";
|
|
6
|
+
import { OnboardingStepType } from "../../steps/types";
|
|
7
|
+
import { resolveStartStepNumber } from "../../resolveStartStepNumber";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the entry point of the onboarding. Suspends on the onboarding query
|
|
11
|
+
* (like `useOnboardingStep`) so the payload is guaranteed loaded, then returns
|
|
12
|
+
* the 1-indexed `startStepNumber` derived from `metadata.startStepId` (falling
|
|
13
|
+
* back to the first step). Use it in the entry route to navigate to the start.
|
|
14
|
+
*/
|
|
15
|
+
export const useOnboardingStart = <
|
|
16
|
+
StepType extends BaseStepType = OnboardingStepType
|
|
17
|
+
>(): {
|
|
18
|
+
startStepNumber: number;
|
|
19
|
+
} => {
|
|
20
|
+
const { client, locale, customAudienceParams, setOnboarding } = useContext(
|
|
21
|
+
OnboardingProgressContext
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const { data } = useSuspenseQuery<Onboarding<StepType>>(
|
|
25
|
+
getOnboardingQuery<StepType>(
|
|
26
|
+
client,
|
|
27
|
+
locale,
|
|
28
|
+
customAudienceParams,
|
|
29
|
+
setOnboarding as (onboarding: Onboarding<StepType>) => void
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const startStepNumber = resolveStartStepNumber(
|
|
34
|
+
data.steps,
|
|
35
|
+
data.metadata?.startStepId
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return { startStepNumber };
|
|
39
|
+
};
|
|
@@ -17,6 +17,7 @@ export const useOnboardingStep = <
|
|
|
17
17
|
stepsLength: number;
|
|
18
18
|
onboardingMetadata: OnboardingMetadata;
|
|
19
19
|
steps: StepType[];
|
|
20
|
+
completeOnboarding: () => void;
|
|
20
21
|
} => {
|
|
21
22
|
// Get all config from context
|
|
22
23
|
const {
|
|
@@ -27,6 +28,7 @@ export const useOnboardingStep = <
|
|
|
27
28
|
setTotalSteps,
|
|
28
29
|
setOnboarding,
|
|
29
30
|
navigation,
|
|
31
|
+
completeOnboarding,
|
|
30
32
|
} = useContext(OnboardingProgressContext);
|
|
31
33
|
|
|
32
34
|
// Build query with config from context
|
|
@@ -53,6 +55,8 @@ export const useOnboardingStep = <
|
|
|
53
55
|
);
|
|
54
56
|
|
|
55
57
|
const step = steps[stepNumber - 1];
|
|
58
|
+
// Positional last step (kept for back-compat; not branch-aware). The true end
|
|
59
|
+
// is signaled by resolveNextStepNumber(...) === null (e.g. the end sentinel).
|
|
56
60
|
const isLastStep = stepNumber >= steps.length;
|
|
57
61
|
const stepsLength = steps.length;
|
|
58
62
|
|
|
@@ -62,5 +66,6 @@ export const useOnboardingStep = <
|
|
|
62
66
|
stepsLength,
|
|
63
67
|
onboardingMetadata,
|
|
64
68
|
steps,
|
|
69
|
+
completeOnboarding,
|
|
65
70
|
};
|
|
66
71
|
};
|
|
@@ -2,7 +2,7 @@ import { createContext, useCallback, useEffect, useRef, useState } from "react";
|
|
|
2
2
|
import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { OnboardingStudioClient } from "../../OnboardingStudioClient";
|
|
4
4
|
import { getOnboardingQuery } from "../queries/getOnboarding.query";
|
|
5
|
-
import { Onboarding } from "../../types";
|
|
5
|
+
import { Onboarding, OnboardingMetadata } from "../../types";
|
|
6
6
|
import { OnboardingStepType } from "../../steps/types";
|
|
7
7
|
import { ComposableVariableEntry } from "../../steps/ComposableScreen/types";
|
|
8
8
|
import { FontLoaderGate } from "./FontLoader";
|
|
@@ -21,10 +21,32 @@ const queryClient = new QueryClient({
|
|
|
21
21
|
|
|
22
22
|
export type CustomActionHandler = (args: {
|
|
23
23
|
variables: Record<string, ComposableVariableEntry | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Write to the live ComposableScreen variable context. Mirrors the declarative
|
|
26
|
+
* `{ type: "setVariable" }` action: it updates both the render store (so
|
|
27
|
+
* `renderWhen` / `{{interpolation}}` react) and the branching store (so a
|
|
28
|
+
* following `"continue"` in the same action list branches on the new value via
|
|
29
|
+
* `resolveNextStepNumber`). `entry` is `{ value, label?, kind? }`.
|
|
30
|
+
*/
|
|
31
|
+
setVariable: (name: string, entry: ComposableVariableEntry) => void;
|
|
24
32
|
}) => void | Promise<void>;
|
|
25
33
|
|
|
26
34
|
export type CustomActions = Record<string, CustomActionHandler>;
|
|
27
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Context passed to `onComplete` when the onboarding ends. Carries the collected
|
|
38
|
+
* variable store and the onboarding metadata. All end nodes are equivalent, so
|
|
39
|
+
* no terminal-step identity is reported.
|
|
40
|
+
*/
|
|
41
|
+
export type OnboardingCompletionContext = {
|
|
42
|
+
variables: Record<string, any>;
|
|
43
|
+
metadata: OnboardingMetadata | undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type OnboardingCompleteHandler = (
|
|
47
|
+
ctx: OnboardingCompletionContext
|
|
48
|
+
) => void | Promise<void>;
|
|
49
|
+
|
|
28
50
|
interface OnboardingProviderProps {
|
|
29
51
|
children: React.ReactNode;
|
|
30
52
|
client: OnboardingStudioClient;
|
|
@@ -34,7 +56,8 @@ interface OnboardingProviderProps {
|
|
|
34
56
|
* Map of named handlers invokable from ComposableScreen Button `actions`
|
|
35
57
|
* with `{ type: "custom", function: <name>, variables?: [...] }`. Handlers
|
|
36
58
|
* receive the requested variables filtered from the live ComposableScreen
|
|
37
|
-
* variable map
|
|
59
|
+
* variable map, a `setVariable` setter to write back into the context, and
|
|
60
|
+
* may return a Promise.
|
|
38
61
|
*/
|
|
39
62
|
customActions?: CustomActions;
|
|
40
63
|
/**
|
|
@@ -50,6 +73,14 @@ interface OnboardingProviderProps {
|
|
|
50
73
|
* support a different navigation library. Must be a stable reference.
|
|
51
74
|
*/
|
|
52
75
|
navigation?: OnboardingNavigationAdapter;
|
|
76
|
+
/**
|
|
77
|
+
* Called when the onboarding completes — i.e. the host reaches a terminal
|
|
78
|
+
* step and invokes `completeOnboarding()` (see the headless
|
|
79
|
+
* `OnboardingProgressContext` / `useOnboardingStep`). Receives the collected
|
|
80
|
+
* `variables` and the onboarding `metadata`. Use it to run post-onboarding
|
|
81
|
+
* logic (mark onboarding done, navigate to paywall/home, etc.). Optional.
|
|
82
|
+
*/
|
|
83
|
+
onComplete?: OnboardingCompleteHandler;
|
|
53
84
|
}
|
|
54
85
|
|
|
55
86
|
interface OnboardingDataGateProps {
|
|
@@ -103,6 +134,7 @@ export const OnboardingProvider = ({
|
|
|
103
134
|
customActions = {},
|
|
104
135
|
fontsFallback,
|
|
105
136
|
navigation = expoRouterAdapter,
|
|
137
|
+
onComplete,
|
|
106
138
|
}: OnboardingProviderProps) => {
|
|
107
139
|
const [activeStep, setActiveStep] = useState({
|
|
108
140
|
number: 0,
|
|
@@ -125,6 +157,26 @@ export const OnboardingProvider = ({
|
|
|
125
157
|
}, []);
|
|
126
158
|
const getVariables = useCallback(() => variablesRef.current, []);
|
|
127
159
|
|
|
160
|
+
// Fires the host `onComplete` with a synchronous snapshot of the collected
|
|
161
|
+
// variables (from the ref, so an answer written via `setVariable` immediately
|
|
162
|
+
// before completing is included) plus the onboarding metadata. Host calls this
|
|
163
|
+
// on the terminal branch instead of inferring completion from a null next step.
|
|
164
|
+
const completeOnboarding = useCallback(() => {
|
|
165
|
+
if (!onComplete) {
|
|
166
|
+
// The terminal branch called completeOnboarding() but no handler is wired,
|
|
167
|
+
// so nothing advances — the user is left on the last screen. Warn instead
|
|
168
|
+
// of failing silently; navigation on completion is the host's job.
|
|
169
|
+
console.warn(
|
|
170
|
+
"[onboarding] completeOnboarding() was called but no `onComplete` handler is set on <OnboardingProvider>. The onboarding will not advance — pass `onComplete` to handle completion (e.g. navigate away)."
|
|
171
|
+
);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
onComplete({
|
|
175
|
+
variables: variablesRef.current,
|
|
176
|
+
metadata: onboarding?.metadata,
|
|
177
|
+
});
|
|
178
|
+
}, [onComplete, onboarding]);
|
|
179
|
+
|
|
128
180
|
return (
|
|
129
181
|
<QueryClientProvider client={queryClient}>
|
|
130
182
|
<OnboardingProgressContext.Provider
|
|
@@ -143,6 +195,7 @@ export const OnboardingProvider = ({
|
|
|
143
195
|
variables,
|
|
144
196
|
setVariable,
|
|
145
197
|
getVariables,
|
|
198
|
+
completeOnboarding,
|
|
146
199
|
customActions,
|
|
147
200
|
navigation,
|
|
148
201
|
}}
|
|
@@ -176,6 +229,7 @@ export const OnboardingProgressContext = createContext<{
|
|
|
176
229
|
variables: Record<string, any>;
|
|
177
230
|
setVariable: (name: string, value: any) => void;
|
|
178
231
|
getVariables: () => Record<string, any>;
|
|
232
|
+
completeOnboarding: () => void;
|
|
179
233
|
customActions: CustomActions;
|
|
180
234
|
navigation: OnboardingNavigationAdapter;
|
|
181
235
|
}>({
|
|
@@ -193,6 +247,7 @@ export const OnboardingProgressContext = createContext<{
|
|
|
193
247
|
variables: {},
|
|
194
248
|
setVariable: () => { },
|
|
195
249
|
getVariables: () => ({}),
|
|
250
|
+
completeOnboarding: () => { },
|
|
196
251
|
customActions: {},
|
|
197
252
|
navigation: expoRouterAdapter,
|
|
198
253
|
});
|
|
@@ -8,6 +8,8 @@ export const onboardingExample = {
|
|
|
8
8
|
audienceName: undefined,
|
|
9
9
|
audienceOrder: undefined,
|
|
10
10
|
draft: true,
|
|
11
|
+
// Explicit entry node (equals steps[0] here, so behavior is unchanged).
|
|
12
|
+
startStepId: "welcome",
|
|
11
13
|
},
|
|
12
14
|
fonts: {
|
|
13
15
|
Inter: {
|
|
@@ -1220,6 +1222,12 @@ export const onboardingExample = {
|
|
|
1220
1222
|
customPayload: {},
|
|
1221
1223
|
continueButtonLabel: "Continue",
|
|
1222
1224
|
displayProgressHeader: false,
|
|
1225
|
+
// Explicit end via the branching sentinel — continuing from here completes
|
|
1226
|
+
// the onboarding (resolveNextStepNumber returns null for "__END__").
|
|
1227
|
+
nextStep: {
|
|
1228
|
+
defaultTargetStepId: "__END__",
|
|
1229
|
+
branches: [],
|
|
1230
|
+
},
|
|
1223
1231
|
},
|
|
1224
1232
|
],
|
|
1225
1233
|
configuration: {},
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { BaseStepType } from "./types";
|
|
2
2
|
import { evaluateCondition } from "./evaluateCondition";
|
|
3
|
+
import { ONBOARDING_END_STEP_ID } from "./steps/common.types";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Resolves the 1-indexed step number to navigate to after the current step.
|
|
6
|
-
* Returns null when the onboarding should end
|
|
7
|
+
* Returns null when the onboarding should end — either the branching pattern
|
|
8
|
+
* resolved to the reserved end sentinel (`ONBOARDING_END_STEP_ID`) or there is
|
|
9
|
+
* no next step (last step / no valid target).
|
|
7
10
|
*
|
|
8
11
|
* @param currentStep - The step that just completed
|
|
9
12
|
* @param variables - Global variable store (build a merged copy before calling if you just set a variable)
|
|
@@ -27,11 +30,16 @@ export function resolveNextStepNumber(
|
|
|
27
30
|
for (const branch of nextStep.branches) {
|
|
28
31
|
if (branch.targetStepId === currentStep.id) continue;
|
|
29
32
|
if (branch.condition === null || evaluateCondition(branch.condition, variables)) {
|
|
33
|
+
// A matching branch that targets the end sentinel ends the onboarding.
|
|
34
|
+
if (branch.targetStepId === ONBOARDING_END_STEP_ID) return null;
|
|
30
35
|
const idx = steps.findIndex((s) => s.id === branch.targetStepId);
|
|
31
36
|
if (idx !== -1) return idx + 1;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
// Default target ends the onboarding when it is the end sentinel.
|
|
41
|
+
if (nextStep.defaultTargetStepId === ONBOARDING_END_STEP_ID) return null;
|
|
42
|
+
|
|
35
43
|
if (nextStep.defaultTargetStepId !== currentStep.id) {
|
|
36
44
|
const defaultIdx = steps.findIndex((s) => s.id === nextStep.defaultTargetStepId);
|
|
37
45
|
if (defaultIdx !== -1) return defaultIdx + 1;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BaseStepType } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the 1-indexed step number the onboarding should start on.
|
|
5
|
+
*
|
|
6
|
+
* Reads the (optional, unique) `startStepId` first. Falls back to the first
|
|
7
|
+
* step in the array when `startStepId` is absent or references a step that is
|
|
8
|
+
* not present — mirroring `resolveNextStepNumber`'s unknown-id guard and
|
|
9
|
+
* preserving legacy positional-start behavior.
|
|
10
|
+
*
|
|
11
|
+
* @param steps - Full ordered steps array
|
|
12
|
+
* @param startStepId - Optional id of the unique start step (from onboarding metadata)
|
|
13
|
+
*/
|
|
14
|
+
export function resolveStartStepNumber(
|
|
15
|
+
steps: BaseStepType[],
|
|
16
|
+
startStepId?: string
|
|
17
|
+
): number {
|
|
18
|
+
if (startStepId) {
|
|
19
|
+
const idx = steps.findIndex((s) => s.id === startStepId);
|
|
20
|
+
if (idx !== -1) return idx + 1; // 1-indexed
|
|
21
|
+
}
|
|
22
|
+
return 1; // fallback: first positional step (legacy)
|
|
23
|
+
}
|