finform-react-builder 1.4.0 → 1.5.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/components/FinForm/apiUtils.d.ts +38 -0
- package/dist/components/FinForm/index.d.ts +2 -1
- package/dist/components/FinForm/types.d.ts +48 -6
- package/dist/index.es.js +5559 -3578
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ApiConfig } from './types';
|
|
2
|
+
export interface ApiResponse<T = any> {
|
|
3
|
+
data: T;
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ApiError {
|
|
8
|
+
message: string;
|
|
9
|
+
status?: number;
|
|
10
|
+
statusText?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetches data from an API endpoint using React Query
|
|
14
|
+
*/
|
|
15
|
+
export declare function fetchApiData(apiConfig: ApiConfig, baseUrl?: string, defaultHeaders?: Record<string, string>, dependentValues?: Record<string, any>): Promise<Array<{
|
|
16
|
+
label: string;
|
|
17
|
+
value: string | number;
|
|
18
|
+
}>>;
|
|
19
|
+
/**
|
|
20
|
+
* React Query hook for fetching API data with caching - only fetches on user interaction
|
|
21
|
+
*/
|
|
22
|
+
export declare function useApiData(apiConfig: ApiConfig | null, baseUrl?: string, defaultHeaders?: Record<string, string>, dependentValues?: Record<string, any>, // Changed from formData to dependentValues
|
|
23
|
+
enabled?: boolean): import('@tanstack/react-query').UseQueryResult<{
|
|
24
|
+
label: string;
|
|
25
|
+
value: string | number;
|
|
26
|
+
}[], Error>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a field has API configuration
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasApiConfig(field: any): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the API configuration from a field
|
|
33
|
+
*/
|
|
34
|
+
export declare function getApiConfig(field: any): ApiConfig | null;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a field should be shown based on conditional logic
|
|
37
|
+
*/
|
|
38
|
+
export declare function shouldShowField(field: any, formData: Record<string, any>): boolean;
|
|
@@ -4,4 +4,5 @@ export { StepNavigation } from './StepNavigation';
|
|
|
4
4
|
export { ImageComponent } from './ImageComponent';
|
|
5
5
|
export { CustomButtons } from './CustomButtons';
|
|
6
6
|
export { generateSchema } from './generateSchema';
|
|
7
|
-
export
|
|
7
|
+
export { fetchApiData, hasApiConfig, getApiConfig, shouldShowField, useApiData } from './apiUtils';
|
|
8
|
+
export type { FieldConfig, ValidationRule, FormButton, ButtonGroup, FormTitle, FormTheme, FinFormProps, ApiConfig, } from './types';
|
|
@@ -4,16 +4,31 @@ export interface ValidationRule {
|
|
|
4
4
|
required?: boolean;
|
|
5
5
|
minLength?: number;
|
|
6
6
|
maxLength?: number;
|
|
7
|
-
min?: number;
|
|
8
|
-
max?: number;
|
|
7
|
+
min?: number | string;
|
|
8
|
+
max?: number | string;
|
|
9
9
|
custom?: (value: any) => boolean | string;
|
|
10
10
|
}
|
|
11
|
+
export interface ApiConfig {
|
|
12
|
+
endpoint: string;
|
|
13
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
14
|
+
valueField?: string;
|
|
15
|
+
labelField?: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
params?: Record<string, any>;
|
|
18
|
+
body?: any;
|
|
19
|
+
transform?: (data: any[]) => Array<{
|
|
20
|
+
label: string;
|
|
21
|
+
value: string | number;
|
|
22
|
+
}>;
|
|
23
|
+
dependsOn?: string;
|
|
24
|
+
conditional?: boolean;
|
|
25
|
+
}
|
|
11
26
|
export interface BaseField {
|
|
12
27
|
id?: string;
|
|
13
28
|
title?: string;
|
|
14
29
|
name: string;
|
|
15
30
|
label: string;
|
|
16
|
-
type: 'text' | 'email' | 'password' | 'number' | 'select' | 'checkbox' | 'toggle' | 'radio' | 'switch' | 'autocomplete' | 'date' | 'textarea' | 'image' | 'title' | 'section';
|
|
31
|
+
type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'select' | 'checkbox' | 'toggle' | 'radio' | 'switch' | 'autocomplete' | 'date' | 'textarea' | 'image' | 'title' | 'section';
|
|
17
32
|
placeholder?: string;
|
|
18
33
|
required?: boolean;
|
|
19
34
|
disabled?: boolean;
|
|
@@ -26,9 +41,16 @@ export interface BaseField {
|
|
|
26
41
|
md?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
27
42
|
lg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
28
43
|
xl?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
44
|
+
api_endpoint?: string;
|
|
45
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
46
|
+
value_field?: string;
|
|
47
|
+
label_field?: string;
|
|
48
|
+
depends_on?: string;
|
|
49
|
+
conditional?: boolean;
|
|
50
|
+
apiConfig?: ApiConfig;
|
|
29
51
|
}
|
|
30
52
|
export interface TextField extends BaseField {
|
|
31
|
-
type: 'text' | 'email' | 'password' | 'textarea';
|
|
53
|
+
type: 'text' | 'email' | 'password' | 'tel' | 'textarea';
|
|
32
54
|
minLength?: number;
|
|
33
55
|
maxLength?: number;
|
|
34
56
|
pattern?: string;
|
|
@@ -40,10 +62,18 @@ export interface NumberField extends BaseField {
|
|
|
40
62
|
}
|
|
41
63
|
export interface SelectField extends BaseField {
|
|
42
64
|
type: 'select';
|
|
43
|
-
options
|
|
65
|
+
options?: Array<{
|
|
44
66
|
label: string;
|
|
45
67
|
value: string | number;
|
|
46
68
|
}>;
|
|
69
|
+
default?: string | number;
|
|
70
|
+
api_endpoint?: string;
|
|
71
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
72
|
+
value_field?: string;
|
|
73
|
+
label_field?: string;
|
|
74
|
+
depends_on?: string;
|
|
75
|
+
conditional?: boolean;
|
|
76
|
+
apiConfig?: ApiConfig;
|
|
47
77
|
}
|
|
48
78
|
export interface CheckboxField extends BaseField {
|
|
49
79
|
type: 'checkbox';
|
|
@@ -67,13 +97,20 @@ export interface SwitchField extends BaseField {
|
|
|
67
97
|
}
|
|
68
98
|
export interface AutocompleteField extends BaseField {
|
|
69
99
|
type: 'autocomplete';
|
|
70
|
-
options
|
|
100
|
+
options?: Array<{
|
|
71
101
|
label: string;
|
|
72
102
|
value: string | number;
|
|
73
103
|
}>;
|
|
74
104
|
multiple?: boolean;
|
|
75
105
|
freeSolo?: boolean;
|
|
76
106
|
filterOptions?: boolean;
|
|
107
|
+
api_endpoint?: string;
|
|
108
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
109
|
+
value_field?: string;
|
|
110
|
+
label_field?: string;
|
|
111
|
+
depends_on?: string;
|
|
112
|
+
conditional?: boolean;
|
|
113
|
+
apiConfig?: ApiConfig;
|
|
77
114
|
}
|
|
78
115
|
export interface DateField extends BaseField {
|
|
79
116
|
type: 'date';
|
|
@@ -156,6 +193,8 @@ export interface FinFormProps {
|
|
|
156
193
|
showSubmitButton?: boolean;
|
|
157
194
|
buttons?: FormButton[];
|
|
158
195
|
buttonGroup?: ButtonGroup;
|
|
196
|
+
baseUrl?: string;
|
|
197
|
+
apiHeaders?: Record<string, string>;
|
|
159
198
|
isMultiStep?: boolean;
|
|
160
199
|
currentStep?: number;
|
|
161
200
|
onStepChange?: (currentStep: number, totalSteps: number) => void;
|
|
@@ -169,6 +208,9 @@ export interface FieldRendererProps {
|
|
|
169
208
|
field: FieldConfig;
|
|
170
209
|
control: any;
|
|
171
210
|
errors: any;
|
|
211
|
+
baseUrl?: string;
|
|
212
|
+
apiHeaders?: Record<string, string>;
|
|
213
|
+
formData?: Record<string, any>;
|
|
172
214
|
}
|
|
173
215
|
export interface StepNavigationProps {
|
|
174
216
|
currentStep: number;
|