@saas-ui/forms 2.0.0-next.5 → 2.0.0-next.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/ajv/index.d.ts +358 -11
  3. package/dist/ajv/index.js +7 -9
  4. package/dist/ajv/index.js.map +1 -1
  5. package/dist/ajv/index.mjs +7 -10
  6. package/dist/ajv/index.mjs.map +1 -1
  7. package/dist/index.d.ts +296 -194
  8. package/dist/index.js +345 -2584
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +347 -2580
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/yup/index.d.ts +573 -106
  13. package/dist/yup/index.js +6 -10
  14. package/dist/yup/index.js.map +1 -1
  15. package/dist/yup/index.mjs +4 -8
  16. package/dist/yup/index.mjs.map +1 -1
  17. package/dist/zod/index.d.ts +490 -14
  18. package/dist/zod/index.js +5 -0
  19. package/dist/zod/index.js.map +1 -1
  20. package/dist/zod/index.mjs +5 -1
  21. package/dist/zod/index.mjs.map +1 -1
  22. package/package.json +16 -9
  23. package/src/array-field.tsx +34 -17
  24. package/src/base-field.tsx +4 -9
  25. package/src/create-field.tsx +2 -1
  26. package/src/create-form.tsx +33 -10
  27. package/src/default-fields.tsx +21 -4
  28. package/src/display-field.tsx +1 -2
  29. package/src/display-if.tsx +14 -8
  30. package/src/field-resolver.ts +10 -8
  31. package/src/field.tsx +6 -3
  32. package/src/fields.tsx +16 -13
  33. package/src/form-context.tsx +84 -0
  34. package/src/form.tsx +44 -17
  35. package/src/index.ts +17 -15
  36. package/src/object-field.tsx +6 -2
  37. package/src/password-input/password-input.tsx +1 -1
  38. package/src/select/select-context.tsx +130 -0
  39. package/src/select/select.stories.tsx +116 -85
  40. package/src/select/select.tsx +154 -142
  41. package/src/types.ts +59 -6
  42. package/src/use-array-field.tsx +9 -3
  43. package/src/utils.ts +8 -1
  44. package/src/watch-field.tsx +2 -6
@@ -1,15 +1,339 @@
1
- import * as _saas_ui_forms from '@saas-ui/forms';
2
- import { FieldProps, FormProps, CreateFormProps } from '@saas-ui/forms';
3
- import * as z from 'zod';
4
- import { z as z$1 } from 'zod';
5
- import * as react_hook_form from 'react-hook-form';
6
1
  import * as _chakra_ui_checkbox_dist_checkbox from '@chakra-ui/checkbox/dist/checkbox';
7
2
  import * as _chakra_ui_switch_dist_switch from '@chakra-ui/switch/dist/switch';
8
3
  import * as _chakra_ui_textarea_dist_textarea from '@chakra-ui/textarea/dist/textarea';
4
+ import * as react_hook_form from 'react-hook-form';
5
+ import { FieldValues, FieldPath, RegisterOptions, UseFormReturn, UseFormProps, WatchObserver, SubmitHandler, SubmitErrorHandler, UseFieldArrayReturn } from 'react-hook-form';
9
6
  import * as react from 'react';
7
+ import react__default from 'react';
8
+ import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
9
+ import { ButtonProps, InputProps, RadioGroupProps, MenuProps, SelectProps as SelectProps$1, UsePinInputProps, SystemProps, FormControlProps, HTMLChakraProps, NumberInputProps as NumberInputProps$1, StackDirection, MenuItemOptionProps, ResponsiveValue, TextareaProps, SwitchProps, CheckboxProps, RadioProps } from '@chakra-ui/react';
10
+ import { MaybeRenderProp } from '@chakra-ui/react-utils';
11
+ import * as zod from 'zod';
12
+ import { z } from 'zod';
13
+ import * as _saas_ui_forms from '@saas-ui/forms';
14
+ import { FieldProps as FieldProps$1, FormProps as FormProps$1, CreateFormProps } from '@saas-ui/forms';
10
15
  import { zodResolver } from '@hookform/resolvers/zod';
11
16
  export { zodResolver } from '@hookform/resolvers/zod';
12
17
 
18
+ interface SubmitButtonProps extends ButtonProps {
19
+ /**
20
+ * Disable the submit button if the form is untouched.
21
+ *
22
+ * Change the default behavior by updating
23
+ * `SubmitButton.defaultProps.disableIfUntouched`
24
+ */
25
+ disableIfUntouched?: boolean;
26
+ /**
27
+ * Disable the submit button if the form is invalid.
28
+ *
29
+ * Change the default behavior by updating
30
+ * `SubmitButton.defaultProps.disableIfInvalid`
31
+ */
32
+ disableIfInvalid?: boolean;
33
+ }
34
+
35
+ interface NumberInputOptions {
36
+ /**
37
+ * Hide the stepper.
38
+ */
39
+ hideStepper?: boolean;
40
+ /**
41
+ * Render a custom increment icon.
42
+ */
43
+ incrementIcon?: react.ReactNode;
44
+ /**
45
+ * Render a custom decrement icon.
46
+ */
47
+ decrementIcon?: react.ReactNode;
48
+ }
49
+ interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
50
+ }
51
+
52
+ interface PasswordOptions {
53
+ viewIcon?: react__default.ReactNode;
54
+ viewOffIcon?: react__default.ReactNode;
55
+ leftAddon?: react__default.ReactNode;
56
+ }
57
+ interface PasswordInputProps extends InputProps, PasswordOptions {
58
+ }
59
+
60
+ interface RadioOption extends Omit<RadioProps, 'value' | 'label'>, FieldOption {
61
+ }
62
+ type RadioOptions = FieldOptions<RadioOption>;
63
+ interface RadioInputOptions {
64
+ options: RadioOptions;
65
+ spacing?: SystemProps['margin'];
66
+ direction?: StackDirection;
67
+ }
68
+ interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputOptions {
69
+ }
70
+
71
+ interface SelectOptions {
72
+ /**
73
+ * The name of the input field in a native form.
74
+ */
75
+ name: string;
76
+ /**
77
+ * The value of the select field.
78
+ */
79
+ value?: string | string[];
80
+ /**
81
+ * The initial value of the select field.
82
+ */
83
+ defaultValue?: string | string[];
84
+ /**
85
+ * The callback invoked when the value of the select field changes.
86
+ * @param value The value of the select field.
87
+ */
88
+ onChange?: (value: string | string[]) => void;
89
+ /**
90
+ * The placeholder text when there's no value.
91
+ */
92
+ placeholder?: string;
93
+ /**
94
+ * If `true`, the select will be disabled.
95
+ */
96
+ isDisabled?: boolean;
97
+ /**
98
+ * An array of options
99
+ * If you leave this empty the children prop will be rendered.
100
+ */
101
+ options?: FieldOptions<SelectOption>;
102
+ /**
103
+ * Enable multiple select.
104
+ */
105
+ multiple?: boolean;
106
+ /**
107
+ * The function used to render the value of the select field.
108
+ * @param value The value of the select field.
109
+ * @returns The rendered value.
110
+ */
111
+ renderValue?: (value: string | string[]) => react__default.ReactNode;
112
+ }
113
+
114
+ interface SelectProps extends Omit<MenuProps, 'children'>, SelectOptions {
115
+ }
116
+ interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
117
+ }
118
+ /**
119
+ * An option in a select list
120
+ *
121
+ * @see https://saas-ui.dev/docs/components/forms/select
122
+ */
123
+ declare const SelectOption: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", MenuItemOptionProps>;
124
+
125
+ interface Option$1 {
126
+ value: string;
127
+ label?: string;
128
+ }
129
+ interface NativeSelectOptions {
130
+ options?: Option$1[];
131
+ }
132
+ interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
133
+ }
134
+
135
+ interface InputFieldProps extends InputProps {
136
+ type?: string;
137
+ leftAddon?: react.ReactNode;
138
+ rightAddon?: react.ReactNode;
139
+ }
140
+ interface NumberInputFieldProps extends NumberInputProps {
141
+ type: 'number';
142
+ }
143
+ interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
144
+ pinLength?: number;
145
+ pinType?: 'alphanumeric' | 'number';
146
+ spacing?: SystemProps['margin'];
147
+ }
148
+ declare const defaultFieldTypes: {
149
+ text: react.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
150
+ email: react.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
151
+ url: react.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
152
+ phone: react.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
153
+ number: react.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
154
+ password: react.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
155
+ textarea: react.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
156
+ switch: react.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
157
+ select: react.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
158
+ checkbox: react.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
159
+ radio: react.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
160
+ pin: react.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
161
+ 'native-select': react.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
162
+ };
163
+ type DefaultFields = typeof defaultFieldTypes;
164
+
165
+ type FieldOption = {
166
+ label?: string;
167
+ value: string;
168
+ };
169
+ type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
170
+ type ValueOf<T> = T[keyof T];
171
+ type ShallowMerge<A, B> = Omit<A, keyof B> & B;
172
+ type Split<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
173
+ type MapPath<T extends string[]> = T extends [infer U, ...infer R] ? U extends string ? `${U extends `${number}` ? '$' : U}${R[0] extends string ? '.' : ''}${R extends string[] ? MapPath<R> : ''}` : '' : '';
174
+ type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
175
+ type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
176
+ interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
177
+ /**
178
+ * The field name
179
+ */
180
+ name: TName | ArrayFieldPath<TName>;
181
+ /**
182
+ * The field label
183
+ */
184
+ label?: string;
185
+ /**
186
+ * Hide the field label
187
+ */
188
+ hideLabel?: boolean;
189
+ /**
190
+ * Field help text
191
+ */
192
+ help?: string;
193
+ /**
194
+ * React hook form rules
195
+ */
196
+ rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
197
+ /**
198
+ * Build-in types:
199
+ * text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
200
+ *
201
+ * Will default to a text field if there is no matching type.
202
+ */
203
+ type?: string;
204
+ /**
205
+ * The input placeholder
206
+ */
207
+ placeholder?: string;
208
+ }
209
+ type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
210
+ [K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
211
+ type?: K;
212
+ } & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
213
+ }>;
214
+ type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
215
+ type DefaultFieldOverrides = {
216
+ submit?: SubmitButtonProps;
217
+ [key: string]: any;
218
+ };
219
+
220
+ type FieldResolver = {
221
+ getFields(): BaseFieldProps[];
222
+ getNestedFields(name: string): BaseFieldProps[];
223
+ };
224
+
225
+ interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
226
+ children: react.ReactElement;
227
+ name: TName;
228
+ defaultValue?: unknown;
229
+ isDisabled?: boolean;
230
+ isExact?: boolean;
231
+ condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
232
+ }
233
+
234
+ interface UseArrayFieldReturn extends UseFieldArrayReturn {
235
+ /**
236
+ * The array field name
237
+ */
238
+ name: string;
239
+ /**
240
+ * The default value for new items
241
+ */
242
+ defaultValue: Record<string, any>;
243
+ /**
244
+ * Min amount of items
245
+ */
246
+ min?: number;
247
+ /**
248
+ * Max amount of items
249
+ */
250
+ max?: number;
251
+ }
252
+ interface ArrayFieldOptions<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
253
+ /**
254
+ * The field name
255
+ */
256
+ name: TName;
257
+ /**
258
+ * Default value for new values in the array
259
+ */
260
+ defaultValue?: Record<string, any>;
261
+ /**
262
+ * Default key name for rows, change this if your data uses a different 'id' field
263
+ * @default "id"
264
+ */
265
+ keyName?: string;
266
+ min?: number;
267
+ max?: number;
268
+ }
269
+ interface ArrayFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ArrayFieldOptions<TFieldValues, TName>, Omit<BaseFieldProps<TFieldValues, TName>, 'name' | 'defaultValue' | 'children'> {
270
+ children: MaybeRenderProp<ArrayField[]>;
271
+ }
272
+ interface ArrayField {
273
+ id: string;
274
+ [key: string]: unknown;
275
+ }
276
+ /**
277
+ * The wrapper component that composes the default ArrayField functionality.
278
+ *
279
+ * @see Docs https://saas-ui.dev/docs/components/forms/array-field
280
+ */
281
+ declare const ArrayField: ((props: ArrayFieldProps & {
282
+ ref?: react.ForwardedRef<UseArrayFieldReturn>;
283
+ }) => react.ReactElement) & {
284
+ displayName: string;
285
+ };
286
+
287
+ interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
288
+ name: TName;
289
+ children: react.ReactNode;
290
+ columns?: ResponsiveValue<number>;
291
+ spacing?: ResponsiveValue<string | number>;
292
+ }
293
+
294
+ interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
295
+ Field: react.FC<TFieldTypes>;
296
+ DisplayIf: react.FC<DisplayIfProps<TFieldValues>>;
297
+ ArrayField: react.FC<ArrayFieldProps<TFieldValues>>;
298
+ ObjectField: react.FC<ObjectFieldProps<TFieldValues>>;
299
+ }
300
+ interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> {
301
+ /**
302
+ * The form schema.
303
+ */
304
+ schema?: TSchema;
305
+ /**
306
+ * Triggers when any of the field change.
307
+ */
308
+ onChange?: WatchObserver<TFieldValues>;
309
+ /**
310
+ * The submit handler.
311
+ */
312
+ onSubmit: SubmitHandler<TFieldValues>;
313
+ /**
314
+ * Triggers when there are validation errors.
315
+ */
316
+ onError?: SubmitErrorHandler<TFieldValues>;
317
+ /**
318
+ * The Hook Form state ref.
319
+ */
320
+ formRef?: react.RefObject<UseFormReturn<TFieldValues, TContext>>;
321
+ /**
322
+ * The form children, can be a render prop or a ReactNode.
323
+ */
324
+ children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
325
+ /**
326
+ * The field resolver, used to resolve the fields from schemas.
327
+ */
328
+ fieldResolver?: FieldResolver;
329
+ /**
330
+ * Field overrides
331
+ */
332
+ fields?: DefaultFieldOverrides;
333
+ }
334
+ interface FormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TFieldValues, TContext, TSchema, TFieldTypes> {
335
+ }
336
+
13
337
  type Options = {
14
338
  min?: number;
15
339
  max?: number;
@@ -20,11 +344,11 @@ type Options = {
20
344
  * @param schema The Yup schema
21
345
  * @returns {FieldProps[]}
22
346
  */
23
- declare const getFieldsFromSchema: (schema: z.ZodTypeAny) => FieldProps[];
24
- declare const getNestedSchema: (schema: z.ZodTypeAny, path: string) => any;
25
- declare const zodFieldResolver: <T extends z.ZodTypeAny>(schema: T) => {
26
- getFields(): FieldProps<_saas_ui_forms.FieldValues>[];
27
- getNestedFields(name: string): FieldProps<_saas_ui_forms.FieldValues>[];
347
+ declare const getFieldsFromSchema: (schema: zod.ZodTypeAny) => FieldProps$1[];
348
+ declare const getNestedSchema: (schema: zod.ZodTypeAny, path: string) => any;
349
+ declare const zodFieldResolver: <T extends zod.ZodTypeAny>(schema: T) => {
350
+ getFields(): FieldProps$1<_saas_ui_forms.FieldValues>[];
351
+ getNestedFields(name: string): FieldProps$1<_saas_ui_forms.FieldValues>[];
28
352
  };
29
353
  interface ZodMeta {
30
354
  label: string;
@@ -38,8 +362,8 @@ interface CreateZodFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
38
362
  schemaOptions?: ResolverArgs[1];
39
363
  resolverOptions?: ResolverArgs[2];
40
364
  }
41
- declare const createZodForm: <FieldDefs>(options?: CreateZodFormProps<FieldDefs> | undefined) => <TSchema extends z$1.AnyZodObject = z$1.AnyZodObject, TContext extends object = object>(props: Omit<FormProps<z$1.TypeOf<TSchema>, TContext, TSchema, _saas_ui_forms.FieldProps<z$1.TypeOf<TSchema>>>, "children"> & {
42
- children: react.ReactNode | ((props: _saas_ui_forms.FormRenderContext<z$1.TypeOf<TSchema>, TContext, ((FieldDefs extends never ? {
365
+ declare const createZodForm: <FieldDefs>(options?: CreateZodFormProps<FieldDefs> | undefined) => <TSchema extends z.AnyZodObject = z.AnyZodObject, TContext extends object = object>(props: Omit<FormProps$1<z.TypeOf<TSchema>, TContext, TSchema, _saas_ui_forms.FieldProps<z.TypeOf<TSchema>>>, "children" | "fields"> & {
366
+ children?: react.ReactNode | ((props: _saas_ui_forms.FormRenderContext<z.TypeOf<TSchema>, TContext, ((FieldDefs extends never ? {
43
367
  text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
44
368
  email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
45
369
  url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
@@ -97,7 +421,7 @@ declare const createZodForm: <FieldDefs>(options?: CreateZodFormProps<FieldDefs>
97
421
  'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
98
422
  }, keyof FieldDefs> & FieldDefs)[K] extends react.FC<infer Props> ? {
99
423
  type?: K | undefined;
100
- } & Omit<Props, keyof _saas_ui_forms.BaseFieldProps<TFieldValues, react_hook_form.Path<TFieldValues>>> & _saas_ui_forms.BaseFieldProps<z$1.TypeOf<TSchema>, react_hook_form.Path<z$1.TypeOf<TSchema>>> : never; } : never)[keyof (FieldDefs extends never ? {
424
+ } & Omit<Props, keyof _saas_ui_forms.BaseFieldProps<TFieldValues, TName>> & _saas_ui_forms.BaseFieldProps<z.TypeOf<TSchema>, react_hook_form.Path<z.TypeOf<TSchema>>> : never; } : never)[keyof (FieldDefs extends never ? {
101
425
  text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
102
426
  email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
103
427
  url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
@@ -126,6 +450,158 @@ declare const createZodForm: <FieldDefs>(options?: CreateZodFormProps<FieldDefs>
126
450
  pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
127
451
  'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
128
452
  }, keyof FieldDefs> & FieldDefs)]>) => react.ReactNode);
453
+ fields?: ({ [K_1 in react_hook_form.Path<z.TypeOf<TSchema>> | (react_hook_form.Path<z.TypeOf<TSchema>> extends infer T_1 ? T_1 extends react_hook_form.Path<z.TypeOf<TSchema>> ? T_1 extends string ? (string extends T_1 ? (T_1 & string)[] : T_1 extends infer T_2 ? T_2 extends T_1 ? T_2 extends "" ? [] : T_2 extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...any] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [T_2] : never : never) extends infer T_4 ? T_4 extends (string extends T_1 ? (T_1 & string)[] : T_1 extends infer T_2 ? T_2 extends T_1 ? T_2 extends "" ? [] : T_2 extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_3}.${infer U}` ? [T_3, ...any] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [T_2] : never : never) ? T_4 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_5 ? T_5 extends R ? T_5 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_6 ? T_6 extends R ? T_6 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_7 ? T_7 extends R ? T_7 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_8 ? T_8 extends R ? T_8 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_9 ? T_9 extends R ? T_9 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_10 ? T_10 extends R ? T_10 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_11 ? T_11 extends R ? T_11 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_12 ? T_12 extends R ? T_12 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_13 ? T_13 extends R ? T_13 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_14 ? T_14 extends R ? T_14 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? any : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : never : never : never)]?: Omit<((FieldDefs extends never ? {
454
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
455
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
456
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
457
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
458
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
459
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
460
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
461
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
462
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
463
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
464
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
465
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
466
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
467
+ } : Omit<{
468
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
469
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
470
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
471
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
472
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
473
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
474
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
475
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
476
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
477
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
478
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
479
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
480
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
481
+ }, keyof FieldDefs> & FieldDefs) extends infer T_15 ? { [K_2 in keyof T_15]: (FieldDefs extends never ? {
482
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
483
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
484
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
485
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
486
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
487
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
488
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
489
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
490
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
491
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
492
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
493
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
494
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
495
+ } : Omit<{
496
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
497
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
498
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
499
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
500
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
501
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
502
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
503
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
504
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
505
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
506
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
507
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
508
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
509
+ }, keyof FieldDefs> & FieldDefs)[K_2] extends react.FC<infer Props> ? {
510
+ type?: K_2 | undefined;
511
+ } & Omit<Props, keyof _saas_ui_forms.BaseFieldProps<TFieldValues, TName>> & _saas_ui_forms.BaseFieldProps<z.TypeOf<TSchema>, react_hook_form.Path<z.TypeOf<TSchema>>> : never; } : never)[keyof (FieldDefs extends never ? {
512
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
513
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
514
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
515
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
516
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
517
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
518
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
519
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
520
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
521
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
522
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
523
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
524
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
525
+ } : Omit<{
526
+ text: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
527
+ email: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
528
+ url: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
529
+ phone: react.FC<_saas_ui_forms.InputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
530
+ number: react.FC<_saas_ui_forms.NumberInputFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
531
+ password: react.FC<_saas_ui_forms.PasswordInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
532
+ textarea: react.FC<_chakra_ui_textarea_dist_textarea.TextareaProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
533
+ switch: react.FC<_chakra_ui_switch_dist_switch.SwitchProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
534
+ select: react.FC<_saas_ui_forms.SelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
535
+ checkbox: react.FC<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
536
+ radio: react.FC<_saas_ui_forms.RadioInputProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
537
+ pin: react.FC<_saas_ui_forms.PinFieldProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
538
+ 'native-select': react.FC<_saas_ui_forms.NativeSelectProps & _saas_ui_forms.BaseFieldProps<_saas_ui_forms.FieldValues, string>>;
539
+ }, keyof FieldDefs> & FieldDefs)], "name"> | undefined; } & {
540
+ submit?: _saas_ui_forms.SubmitButtonProps | undefined;
541
+ }) | undefined;
542
+ } & {
543
+ ref?: react.ForwardedRef<HTMLFormElement> | undefined;
129
544
  }) => React.ReactElement;
130
545
 
131
- export { Options, ZodMeta, createZodForm, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
546
+ declare const Form: <TSchema extends zod.AnyZodObject = zod.AnyZodObject, TContext extends object = object>(props: Omit<FormProps<zod.TypeOf<TSchema>, TContext, TSchema, FieldProps<zod.TypeOf<TSchema>>>, "children" | "fields"> & {
547
+ children?: react.ReactNode | ((props: FormRenderContext<zod.TypeOf<TSchema>, TContext, ({
548
+ type?: "number" | undefined;
549
+ } & Omit<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
550
+ type?: "text" | undefined;
551
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
552
+ type?: "email" | undefined;
553
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
554
+ type?: "url" | undefined;
555
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
556
+ type?: "phone" | undefined;
557
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
558
+ type?: "password" | undefined;
559
+ } & Omit<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
560
+ type?: "textarea" | undefined;
561
+ } & Omit<_chakra_ui_textarea_dist_textarea.TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
562
+ type?: "switch" | undefined;
563
+ } & Omit<_chakra_ui_switch_dist_switch.SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
564
+ type?: "select" | undefined;
565
+ } & Omit<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
566
+ type?: "checkbox" | undefined;
567
+ } & Omit<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
568
+ type?: "radio" | undefined;
569
+ } & Omit<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
570
+ type?: "pin" | undefined;
571
+ } & Omit<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
572
+ type?: "native-select" | undefined;
573
+ } & Omit<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>)>) => react.ReactNode);
574
+ fields?: ({ [K in react_hook_form.Path<zod.TypeOf<TSchema>> | (react_hook_form.Path<zod.TypeOf<TSchema>> extends infer T ? T extends react_hook_form.Path<zod.TypeOf<TSchema>> ? T extends string ? (string extends T ? (T & string)[] : T extends infer T_1 ? T_1 extends T ? T_1 extends "" ? [] : T_1 extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...any] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [T_1] : never : never) extends infer T_3 ? T_3 extends (string extends T ? (T & string)[] : T extends infer T_1 ? T_1 extends T ? T_1 extends "" ? [] : T_1 extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...string extends U ? (U & string)[] : U extends "" ? [] : U extends `${infer T_2}.${infer U}` ? [T_2, ...any] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [U]] : [T_1] : never : never) ? T_3 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_4 ? T_4 extends R ? T_4 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_5 ? T_5 extends R ? T_5 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_6 ? T_6 extends R ? T_6 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_7 ? T_7 extends R ? T_7 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_8 ? T_8 extends R ? T_8 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_9 ? T_9 extends R ? T_9 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_10 ? T_10 extends R ? T_10 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_11 ? T_11 extends R ? T_11 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_12 ? T_12 extends R ? T_12 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? R extends infer T_13 ? T_13 extends R ? T_13 extends [infer U_1, ...infer R] ? U_1 extends string ? `${U_1 extends `${number}` ? "$" : U_1}${R[0] extends string ? "." : ""}${R extends string[] ? any : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : ""}` : "" : "" : never : never : never : never : never)]?: Omit<({
575
+ type?: "number" | undefined;
576
+ } & Omit<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
577
+ type?: "text" | undefined;
578
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
579
+ type?: "email" | undefined;
580
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
581
+ type?: "url" | undefined;
582
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
583
+ type?: "phone" | undefined;
584
+ } & Omit<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
585
+ type?: "password" | undefined;
586
+ } & Omit<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
587
+ type?: "textarea" | undefined;
588
+ } & Omit<_chakra_ui_textarea_dist_textarea.TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
589
+ type?: "switch" | undefined;
590
+ } & Omit<_chakra_ui_switch_dist_switch.SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
591
+ type?: "select" | undefined;
592
+ } & Omit<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
593
+ type?: "checkbox" | undefined;
594
+ } & Omit<_chakra_ui_checkbox_dist_checkbox.CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
595
+ type?: "radio" | undefined;
596
+ } & Omit<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
597
+ type?: "pin" | undefined;
598
+ } & Omit<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>) | ({
599
+ type?: "native-select" | undefined;
600
+ } & Omit<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>, keyof BaseFieldProps<TFieldValues, TName>> & BaseFieldProps<zod.TypeOf<TSchema>, react_hook_form.Path<zod.TypeOf<TSchema>>>), "name"> | undefined; } & {
601
+ submit?: SubmitButtonProps | undefined;
602
+ }) | undefined;
603
+ } & {
604
+ ref?: react.ForwardedRef<HTMLFormElement> | undefined;
605
+ }) => react.ReactElement<any, string | react.JSXElementConstructor<any>>;
606
+
607
+ export { Form, Options, ZodMeta, createZodForm, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
package/dist/zod/index.js CHANGED
@@ -77,14 +77,19 @@ var zodParseMeta = (meta) => {
77
77
  var createZodForm = (options) => {
78
78
  return forms.createForm({
79
79
  resolver: (schema) => zod.zodResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
80
+ fieldResolver: zodFieldResolver,
80
81
  ...options
81
82
  });
82
83
  };
83
84
 
85
+ // zod/src/index.ts
86
+ var Form = createZodForm();
87
+
84
88
  Object.defineProperty(exports, 'zodResolver', {
85
89
  enumerable: true,
86
90
  get: function () { return zod.zodResolver; }
87
91
  });
92
+ exports.Form = Form;
88
93
  exports.createZodForm = createZodForm;
89
94
  exports.getFieldsFromSchema = getFieldsFromSchema;
90
95
  exports.getNestedSchema = getNestedSchema;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../zod/src/zod-resolver.ts","../../zod/src/create-zod-form.ts"],"names":[],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAUpB,IAAM,UAAU,CAAC,UAAwB;AACvC,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AA5BrD;AA6BE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AACzE,QAAM,SAAuB,CAAC;AAE9B,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,KAAK,aAAa,YAAY;AACvC,mBAAe,OAAO,KAAK,KAAK;AAAA,EAClC,WAAW,OAAO,KAAK,aAAa,aAAa;AAC/C,mBAAe,OAAO,KAAK,MAAM;AAAA,EACnC,OAAO;AACL,WAAO;AAAA,EACT;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,UAAmB,CAAC;AAC1B,QAAI,MAAM,KAAK,aAAa,YAAY;AACtC,cAAQ,MAAM,eAAe,OAAO,WAAW;AAC/C,cAAQ,MAAM,eAAe,OAAO,WAAW;AAAA,IACjD;AAEA,UAAM,OAAO,MAAM,eAAe,aAAa,MAAM,WAAW;AAEhE,WAAO,KAAK;AAAA,MACV;AAAA,MACA,QAAO,6BAAM,UAAS,MAAM,eAAe;AAAA,MAC3C,OAAM,6BAAM,SAAQ,QAAQ,KAAK;AAAA,MACjC,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAC,QAAsB,SAAiB;AACrE,SAAO,IAAI,OAAO,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,mBAAmB,CAAyB,WAAc;AACrE,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AAOO,IAAM,UAAU,CAAC,SAAkB;AACxC,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEO,IAAM,eAAe,CAAC,SAAiB;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAP;AACA,WAAO;AAAA,EACT;AACF;;;ACrGA;AAAA,EACE;AAAA,OAIK;AAYA,IAAM,gBAAgB,CAC3B,YACG;AACH,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,GAAG;AAAA,EACL,CAAC;AAMH","sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n} from '@saas-ui/forms'\nimport { zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport const createZodForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n return createForm({\n resolver: (schema) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n ...options,\n }) as <\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TContext extends object = object\n >(\n props: WithFields<FormProps<z.infer<TSchema>, TContext, TSchema>, FieldDefs>\n ) => React.ReactElement\n}\n"]}
1
+ {"version":3,"sources":["../../zod/src/zod-resolver.ts","../../zod/src/create-zod-form.ts","../../zod/src/index.ts"],"names":[],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AAUpB,IAAM,UAAU,CAAC,UAAwB;AACvC,UAAQ,MAAM,KAAK,UAAU;AAAA,IAC3B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AA5BrD;AA6BE,UAAO,WAAM,KAAK,IAAI,MAAf,mBAAkB;AAC3B;AAQO,IAAM,sBAAsB,CAAC,WAAuC;AACzE,QAAM,SAAuB,CAAC;AAE9B,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,KAAK,aAAa,YAAY;AACvC,mBAAe,OAAO,KAAK,KAAK;AAAA,EAClC,WAAW,OAAO,KAAK,aAAa,aAAa;AAC/C,mBAAe,OAAO,KAAK,MAAM;AAAA,EACnC,OAAO;AACL,WAAO;AAAA,EACT;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,UAAmB,CAAC;AAC1B,QAAI,MAAM,KAAK,aAAa,YAAY;AACtC,cAAQ,MAAM,eAAe,OAAO,WAAW;AAC/C,cAAQ,MAAM,eAAe,OAAO,WAAW;AAAA,IACjD;AAEA,UAAM,OAAO,MAAM,eAAe,aAAa,MAAM,WAAW;AAEhE,WAAO,KAAK;AAAA,MACV;AAAA,MACA,QAAO,6BAAM,UAAS,MAAM,eAAe;AAAA,MAC3C,OAAM,6BAAM,SAAQ,QAAQ,KAAK;AAAA,MACjC,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAC,QAAsB,SAAiB;AACrE,SAAO,IAAI,OAAO,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,mBAAmB,CAAyB,WAAc;AACrE,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;AAOO,IAAM,UAAU,CAAC,SAAkB;AACxC,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEO,IAAM,eAAe,CAAC,SAAiB;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,SAAS,GAAP;AACA,WAAO;AAAA,EACT;AACF;;;ACrGA;AAAA,EACE;AAAA,OAIK;AAYA,IAAM,gBAAgB,CAC3B,YACG;AACH,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAWH;;;ACvBO,IAAM,OAAO,cAAc","sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n","import {\n createForm,\n CreateFormProps,\n WithFields,\n FormProps,\n} from '@saas-ui/forms'\nimport { zodFieldResolver, zodResolver } from './zod-resolver'\nimport { z } from 'zod'\n\ntype ResolverArgs = Parameters<typeof zodResolver>\n\nexport interface CreateZodFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport const createZodForm = <FieldDefs>(\n options?: CreateZodFormProps<FieldDefs>\n) => {\n return createForm({\n resolver: (schema) =>\n zodResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: zodFieldResolver,\n ...options,\n }) as <\n TSchema extends z.AnyZodObject = z.AnyZodObject,\n TContext extends object = object\n >(\n props: WithFields<\n FormProps<z.infer<TSchema>, TContext, TSchema>,\n FieldDefs\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n ) => React.ReactElement\n}\n","export {\n zodResolver,\n getFieldsFromSchema,\n getNestedSchema,\n zodFieldResolver,\n zodMeta,\n zodParseMeta,\n} from './zod-resolver'\nexport type { Options, ZodMeta } from './zod-resolver'\nexport { createZodForm } from './create-zod-form'\n\nimport { createZodForm } from './create-zod-form'\n\nexport const Form = createZodForm()\n"]}
@@ -76,10 +76,14 @@ var zodParseMeta = (meta) => {
76
76
  var createZodForm = (options) => {
77
77
  return createForm({
78
78
  resolver: (schema) => zodResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
79
+ fieldResolver: zodFieldResolver,
79
80
  ...options
80
81
  });
81
82
  };
82
83
 
83
- export { createZodForm, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
84
+ // zod/src/index.ts
85
+ var Form = createZodForm();
86
+
87
+ export { Form, createZodForm, getFieldsFromSchema, getNestedSchema, zodFieldResolver, zodMeta, zodParseMeta };
84
88
  //# sourceMappingURL=out.js.map
85
89
  //# sourceMappingURL=index.mjs.map