@saas-ui/forms 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/dist/ajv/index.d.mts +34 -0
- package/dist/ajv/index.d.ts +1 -1
- package/dist/index.d.mts +908 -0
- package/dist/index.d.ts +53 -31
- package/dist/index.js +111 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -50
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.mts +254 -0
- package/dist/yup/index.d.ts +72 -476
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.mts +279 -0
- package/dist/zod/index.d.ts +71 -474
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +5 -3
- package/src/base-field.tsx +29 -7
- package/src/create-field.tsx +38 -32
- package/src/create-form.tsx +30 -12
- package/src/create-step-form.tsx +23 -9
- package/src/fields-context.tsx +17 -7
- package/src/form.tsx +31 -9
- package/src/index.ts +2 -1
- package/src/types.ts +66 -42
- package/src/use-array-field.tsx +3 -2
package/src/types.ts
CHANGED
@@ -20,10 +20,10 @@ export type ShallowMerge<A, B> = Omit<A, keyof B> & B
|
|
20
20
|
type Split<S extends string, D extends string> = string extends S
|
21
21
|
? string[]
|
22
22
|
: S extends ''
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
? []
|
24
|
+
: S extends `${infer T}${D}${infer U}`
|
25
|
+
? [T, ...Split<U, D>]
|
26
|
+
: [S]
|
27
27
|
|
28
28
|
type MapPath<T extends string[]> = T extends [infer U, ...infer R]
|
29
29
|
? U extends string
|
@@ -41,7 +41,7 @@ export type ArrayFieldPath<Name extends string> = Name extends string
|
|
41
41
|
|
42
42
|
export interface BaseFieldProps<
|
43
43
|
TFieldValues extends FieldValues = FieldValues,
|
44
|
-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues
|
44
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
45
45
|
> extends Omit<FormControlProps, 'label' | 'type' | 'onChange'> {
|
46
46
|
/**
|
47
47
|
* The field name
|
@@ -79,28 +79,43 @@ export interface BaseFieldProps<
|
|
79
79
|
placeholder?: string
|
80
80
|
}
|
81
81
|
|
82
|
+
export type GetBaseField<TProps extends object = object> = () => {
|
83
|
+
extraProps: string[]
|
84
|
+
BaseField: React.FC<
|
85
|
+
Omit<BaseFieldProps, 'name'> & {
|
86
|
+
name: string
|
87
|
+
children: React.ReactNode
|
88
|
+
} & TProps
|
89
|
+
>
|
90
|
+
}
|
91
|
+
|
82
92
|
type FieldPathWithArray<
|
83
93
|
TFieldValues extends FieldValues,
|
84
|
-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues
|
94
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
85
95
|
> = TName | ArrayFieldPath<TName>
|
86
96
|
|
87
97
|
export type MergeFieldProps<
|
88
98
|
FieldDefs,
|
89
99
|
TFieldValues extends FieldValues = FieldValues,
|
90
|
-
|
100
|
+
TExtraFieldProps extends object = object,
|
101
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
91
102
|
> = ValueOf<{
|
92
103
|
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props>
|
93
|
-
? { type?: K } & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>>
|
104
|
+
? { type?: K } & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> &
|
105
|
+
TExtraFieldProps
|
94
106
|
: never
|
95
107
|
}>
|
96
108
|
|
97
|
-
export type FieldProps<
|
98
|
-
|
109
|
+
export type FieldProps<
|
110
|
+
TFieldValues extends FieldValues = FieldValues,
|
111
|
+
TExtraFieldProps extends object = object,
|
112
|
+
> = MergeFieldProps<DefaultFields, TFieldValues, TExtraFieldProps>
|
99
113
|
|
100
114
|
export type FormChildren<
|
101
115
|
FieldDefs,
|
102
116
|
TFieldValues extends FieldValues = FieldValues,
|
103
|
-
TContext extends object = object
|
117
|
+
TContext extends object = object,
|
118
|
+
TExtraFieldProps extends object = object,
|
104
119
|
> = MaybeRenderProp<
|
105
120
|
FormRenderContext<
|
106
121
|
TFieldValues,
|
@@ -109,7 +124,8 @@ export type FormChildren<
|
|
109
124
|
FieldDefs extends never
|
110
125
|
? DefaultFields
|
111
126
|
: ShallowMerge<DefaultFields, FieldDefs>,
|
112
|
-
TFieldValues
|
127
|
+
TFieldValues,
|
128
|
+
TExtraFieldProps
|
113
129
|
>
|
114
130
|
>
|
115
131
|
>
|
@@ -122,7 +138,7 @@ export type DefaultFieldOverrides = {
|
|
122
138
|
type MergeOverrideFieldProps<
|
123
139
|
FieldDefs,
|
124
140
|
TFieldValues extends FieldValues = FieldValues,
|
125
|
-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues
|
141
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
126
142
|
> = ValueOf<{
|
127
143
|
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props>
|
128
144
|
? { type?: K } & Omit<
|
@@ -135,7 +151,7 @@ type MergeOverrideFieldProps<
|
|
135
151
|
export type FieldOverrides<
|
136
152
|
FieldDefs,
|
137
153
|
TFieldValues extends FieldValues = FieldValues,
|
138
|
-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues
|
154
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
139
155
|
> = {
|
140
156
|
[K in FieldPathWithArray<TFieldValues, TName>]?:
|
141
157
|
| MergeOverrideFieldProps<
|
@@ -155,28 +171,35 @@ export type FieldOverrides<
|
|
155
171
|
}
|
156
172
|
|
157
173
|
export type WithFields<
|
158
|
-
TFormProps extends FormProps<any, any, any, any>,
|
174
|
+
TFormProps extends FormProps<any, any, any, any, any>,
|
159
175
|
FieldDefs,
|
160
|
-
ExtraOverrides = object
|
161
|
-
> =
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
176
|
+
ExtraOverrides = object,
|
177
|
+
> =
|
178
|
+
TFormProps extends FormProps<
|
179
|
+
infer TSchema,
|
180
|
+
infer TFieldValues,
|
181
|
+
infer TContext,
|
182
|
+
infer TExtraFieldProps
|
183
|
+
>
|
184
|
+
? Omit<TFormProps, 'children' | 'fields'> & {
|
185
|
+
children?: FormChildren<
|
186
|
+
FieldDefs,
|
187
|
+
TFieldValues,
|
188
|
+
TContext,
|
189
|
+
TExtraFieldProps
|
190
|
+
>
|
191
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
192
|
+
submit?: SubmitButtonProps
|
193
|
+
} & ExtraOverrides
|
194
|
+
}
|
195
|
+
: never
|
173
196
|
|
174
197
|
// StepForm types
|
175
198
|
export type StepFormChildren<
|
176
199
|
FieldDefs,
|
177
200
|
TSteps extends StepsOptions<any> = StepsOptions<any>,
|
178
201
|
TFieldValues extends FieldValues = FieldValues,
|
179
|
-
TContext extends object = object
|
202
|
+
TContext extends object = object,
|
180
203
|
> = MaybeRenderProp<
|
181
204
|
StepFormRenderContext<
|
182
205
|
TSteps,
|
@@ -194,16 +217,17 @@ export type StepFormChildren<
|
|
194
217
|
export type WithStepFields<
|
195
218
|
TStepFormProps extends UseStepFormProps<any, any, any>,
|
196
219
|
FieldDefs,
|
197
|
-
ExtraOverrides = object
|
198
|
-
> =
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
220
|
+
ExtraOverrides = object,
|
221
|
+
> =
|
222
|
+
TStepFormProps extends UseStepFormProps<
|
223
|
+
infer TSteps,
|
224
|
+
infer TFieldValues,
|
225
|
+
infer TContext
|
226
|
+
>
|
227
|
+
? Omit<TStepFormProps, 'children' | 'fields'> & {
|
228
|
+
children?: StepFormChildren<FieldDefs, TSteps, TFieldValues, TContext>
|
229
|
+
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
230
|
+
submit?: SubmitButtonProps
|
231
|
+
} & ExtraOverrides
|
232
|
+
}
|
233
|
+
: never
|
package/src/use-array-field.tsx
CHANGED
@@ -64,7 +64,7 @@ export const [ArrayFieldRowProvider, useArrayFieldRowContext] =
|
|
64
64
|
|
65
65
|
export interface ArrayFieldOptions<
|
66
66
|
TFieldValues extends FieldValues = FieldValues,
|
67
|
-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues
|
67
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
68
68
|
> {
|
69
69
|
/**
|
70
70
|
* The field name
|
@@ -91,12 +91,13 @@ export const useArrayField = ({
|
|
91
91
|
max,
|
92
92
|
}: ArrayFieldOptions) => {
|
93
93
|
const { control } = useFormContext()
|
94
|
+
|
94
95
|
const context = useFieldArray({
|
95
96
|
control,
|
96
97
|
name,
|
97
98
|
keyName,
|
98
99
|
})
|
99
|
-
|
100
|
+
console.log(context)
|
100
101
|
return {
|
101
102
|
...context,
|
102
103
|
name,
|