@umituz/react-native-ai-generation-content 1.75.2 → 1.75.3
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/package.json +1 -1
- package/src/domains/generation/wizard/infrastructure/utils/credit-value-extractors.ts +27 -6
- package/src/domains/generation/wizard/infrastructure/utils/wizard-data-validators.ts +13 -18
- package/src/domains/generation/wizard/presentation/hooks/useWizardFlowHandlers.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.75.
|
|
3
|
+
"version": "1.75.3",
|
|
4
4
|
"description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -2,24 +2,42 @@
|
|
|
2
2
|
* Credit Value Extractors
|
|
3
3
|
* Pure utility functions to extract and normalize values from customData
|
|
4
4
|
* Single Responsibility: Data transformation for credit calculation
|
|
5
|
+
*
|
|
6
|
+
* Handles both raw values and selection format objects:
|
|
7
|
+
* - Raw: "4s", 4, "480p"
|
|
8
|
+
* - Selection format: { uri: "4s", selection: "4s" | 4, previewUrl: "" }
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Unwrap selection format to get the actual value
|
|
13
|
+
* Selection steps store data as { uri, selection, previewUrl } objects
|
|
5
14
|
*/
|
|
15
|
+
function unwrapSelection(value: unknown): unknown {
|
|
16
|
+
if (typeof value === "object" && value !== null && "selection" in value) {
|
|
17
|
+
return (value as Record<string, unknown>).selection;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
6
21
|
|
|
7
22
|
/**
|
|
8
23
|
* Extract duration value from customData
|
|
9
24
|
* Handles both number and string formats ("4s", "5s", "6s")
|
|
25
|
+
* Also handles selection format objects from wizard steps
|
|
10
26
|
*
|
|
11
27
|
* @param value - Raw value from customData
|
|
12
28
|
* @returns Normalized duration number, or undefined if invalid
|
|
13
29
|
*/
|
|
14
30
|
export function extractDuration(value: unknown): number | undefined {
|
|
31
|
+
const unwrapped = unwrapSelection(value);
|
|
32
|
+
|
|
15
33
|
// Already a number
|
|
16
|
-
if (typeof
|
|
17
|
-
return
|
|
34
|
+
if (typeof unwrapped === "number" && unwrapped > 0) {
|
|
35
|
+
return unwrapped;
|
|
18
36
|
}
|
|
19
37
|
|
|
20
38
|
// String format: "4s", "5s", "6s" → parse to number
|
|
21
|
-
if (typeof
|
|
22
|
-
const match =
|
|
39
|
+
if (typeof unwrapped === "string") {
|
|
40
|
+
const match = unwrapped.match(/^(\d+)s?$/);
|
|
23
41
|
if (match) {
|
|
24
42
|
const parsed = parseInt(match[1], 10);
|
|
25
43
|
return parsed > 0 ? parsed : undefined;
|
|
@@ -32,13 +50,16 @@ export function extractDuration(value: unknown): number | undefined {
|
|
|
32
50
|
/**
|
|
33
51
|
* Extract resolution value from customData
|
|
34
52
|
* Validates against allowed values
|
|
53
|
+
* Also handles selection format objects from wizard steps
|
|
35
54
|
*
|
|
36
55
|
* @param value - Raw value from customData
|
|
37
56
|
* @returns Normalized resolution string, or undefined if invalid
|
|
38
57
|
*/
|
|
39
58
|
export function extractResolution(value: unknown): "480p" | "720p" | undefined {
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
const unwrapped = unwrapSelection(value);
|
|
60
|
+
|
|
61
|
+
if (unwrapped === "480p" || unwrapped === "720p") {
|
|
62
|
+
return unwrapped;
|
|
42
63
|
}
|
|
43
64
|
return undefined;
|
|
44
65
|
}
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
* Wizard Data Validators
|
|
3
3
|
* Centralized validation utilities for wizard generation data
|
|
4
4
|
* DRY: Used across AIGenerateScreen, TextToVideoWizardScreen, ImageToVideoWizardScreen
|
|
5
|
+
*
|
|
6
|
+
* Handles both raw values and selection format objects from wizard steps:
|
|
7
|
+
* - Raw: 4, "480p"
|
|
8
|
+
* - Selection format: { uri: "4s", selection: 4, previewUrl: "" }
|
|
5
9
|
*/
|
|
6
10
|
|
|
11
|
+
import { extractDuration, extractResolution } from "./credit-value-extractors";
|
|
12
|
+
|
|
7
13
|
export interface ValidationResult<T> {
|
|
8
14
|
value?: T;
|
|
9
15
|
error?: string;
|
|
@@ -18,11 +24,11 @@ export interface ValidationResult<T> {
|
|
|
18
24
|
export function validateDuration(
|
|
19
25
|
data: Record<string, unknown>,
|
|
20
26
|
): ValidationResult<number> {
|
|
21
|
-
const duration = data.duration
|
|
27
|
+
const duration = extractDuration(data.duration);
|
|
22
28
|
|
|
23
|
-
if (!duration
|
|
29
|
+
if (!duration) {
|
|
24
30
|
return {
|
|
25
|
-
error: `Invalid duration: ${duration}. Must be a positive number.`,
|
|
31
|
+
error: `Invalid duration: ${JSON.stringify(data.duration)}. Must be a positive number.`,
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
34
|
|
|
@@ -38,24 +44,13 @@ export function validateDuration(
|
|
|
38
44
|
export function validateResolution(
|
|
39
45
|
data: Record<string, unknown>,
|
|
40
46
|
): ValidationResult<"480p" | "720p"> {
|
|
41
|
-
const
|
|
47
|
+
const resolution = extractResolution(data.resolution);
|
|
42
48
|
|
|
43
|
-
if (!
|
|
49
|
+
if (!resolution) {
|
|
44
50
|
return {
|
|
45
|
-
error: `Invalid resolution: ${
|
|
51
|
+
error: `Invalid resolution: ${JSON.stringify(data.resolution)}. Must be "480p" or "720p".`,
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
if (resolutionValue === "480p") {
|
|
51
|
-
return { value: "480p" };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (resolutionValue === "720p") {
|
|
55
|
-
return { value: "720p" };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
error: `Invalid resolution value: "${resolutionValue}". Must be "480p" or "720p".`,
|
|
60
|
-
};
|
|
55
|
+
return { value: resolution };
|
|
61
56
|
}
|
|
@@ -94,8 +94,11 @@ export function useWizardFlowHandlers(props: UseWizardFlowHandlersProps) {
|
|
|
94
94
|
else previousStep();
|
|
95
95
|
}, [currentStepIndex, previousStep, onBack]);
|
|
96
96
|
|
|
97
|
-
const handleNextStep = useCallback(() => {
|
|
97
|
+
const handleNextStep = useCallback((additionalData?: Record<string, unknown>) => {
|
|
98
98
|
const nextStepDef = flowSteps[currentStepIndex + 1];
|
|
99
|
+
// Merge additionalData to avoid stale closure issue
|
|
100
|
+
// When called from handlePhotoContinue, customData in closure may not include the just-set value
|
|
101
|
+
const mergedData = additionalData ? { ...customData, ...additionalData } : customData;
|
|
99
102
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
100
103
|
console.log("[handleNextStep] Called", {
|
|
101
104
|
currentStepIndex,
|
|
@@ -103,14 +106,15 @@ export function useWizardFlowHandlers(props: UseWizardFlowHandlersProps) {
|
|
|
103
106
|
nextStepId: nextStepDef?.id,
|
|
104
107
|
totalSteps: flowSteps.length,
|
|
105
108
|
hasOnGenerationStart: !!onGenerationStart,
|
|
109
|
+
dataKeys: Object.keys(mergedData),
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
if (nextStepDef?.type === StepType.GENERATING && onGenerationStart) {
|
|
109
|
-
onGenerationStart(
|
|
113
|
+
onGenerationStart(mergedData, nextStep, handleGenerationError);
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
116
|
nextStep();
|
|
113
|
-
}, [currentStepIndex, flowSteps, customData, onGenerationStart, nextStep]);
|
|
117
|
+
}, [currentStepIndex, flowSteps, customData, onGenerationStart, nextStep, handleGenerationError]);
|
|
114
118
|
|
|
115
119
|
const handlePhotoContinue = useCallback(
|
|
116
120
|
(stepId: string, image: UploadedImage) => {
|
|
@@ -118,7 +122,8 @@ export function useWizardFlowHandlers(props: UseWizardFlowHandlersProps) {
|
|
|
118
122
|
console.log("[handlePhotoContinue] Called", { stepId, hasImage: !!image, currentStepIndex });
|
|
119
123
|
}
|
|
120
124
|
setCustomData(stepId, image);
|
|
121
|
-
|
|
125
|
+
// Pass the just-set data to avoid stale closure issue
|
|
126
|
+
handleNextStep({ [stepId]: image });
|
|
122
127
|
},
|
|
123
128
|
[setCustomData, handleNextStep, currentStepIndex],
|
|
124
129
|
);
|