@saas-ui/forms 2.0.0-next.9 → 2.0.0-rc.23
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +139 -0
- package/dist/ajv/index.d.ts +15 -350
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs.map +1 -1
- package/dist/index.d.ts +182 -144
- package/dist/index.js +202 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -148
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +218 -274
- package/dist/yup/index.js +22 -6
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +20 -5
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +246 -303
- package/dist/zod/index.js +16 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +17 -3
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +20 -6
- package/src/array-field.tsx +6 -3
- package/src/create-form.tsx +33 -19
- package/src/create-step-form.tsx +100 -0
- package/src/form-context.tsx +1 -1
- package/src/form.tsx +12 -10
- package/src/index.ts +20 -6
- package/src/object-field.tsx +22 -5
- package/src/select/select.tsx +2 -2
- package/src/step-form.tsx +52 -70
- package/src/types.ts +8 -3
- package/src/use-step-form.tsx +54 -9
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,112 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 2.0.0-rc.23
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Bump version
|
8
|
+
- Updated dependencies [7027d7c1]
|
9
|
+
- Updated dependencies
|
10
|
+
- @saas-ui/core@2.0.0-rc.20
|
11
|
+
|
12
|
+
## 2.0.0-rc.22
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- Updated dependencies [7027d7c1]
|
17
|
+
- @saas-ui/core@2.0.0-rc.19
|
18
|
+
|
19
|
+
## 2.0.0-next.21
|
20
|
+
|
21
|
+
### Patch Changes
|
22
|
+
|
23
|
+
- @saas-ui/core@2.0.0-next.18
|
24
|
+
|
25
|
+
## 2.0.0-next.20
|
26
|
+
|
27
|
+
### Minor Changes
|
28
|
+
|
29
|
+
- a9ca90dd: Updated to Chakra UI 2.6.x
|
30
|
+
|
31
|
+
### Patch Changes
|
32
|
+
|
33
|
+
- Updated dependencies [2b639656]
|
34
|
+
- @saas-ui/core@2.0.0-next.17
|
35
|
+
|
36
|
+
## 2.0.0-next.19
|
37
|
+
|
38
|
+
### Patch Changes
|
39
|
+
|
40
|
+
- @saas-ui/core@2.0.0-next.16
|
41
|
+
|
42
|
+
## 2.0.0-next.18
|
43
|
+
|
44
|
+
### Patch Changes
|
45
|
+
|
46
|
+
- 01ac442f: Fixed modal form handler type inference
|
47
|
+
|
48
|
+
## 2.0.0-next.17
|
49
|
+
|
50
|
+
### Patch Changes
|
51
|
+
|
52
|
+
- Updated dependencies [a5898c44]
|
53
|
+
- @saas-ui/core@2.0.0-next.15
|
54
|
+
|
55
|
+
## 2.0.0-next.16
|
56
|
+
|
57
|
+
### Patch Changes
|
58
|
+
|
59
|
+
- Updated dependencies [b8be6d41]
|
60
|
+
- @saas-ui/core@2.0.0-next.14
|
61
|
+
|
62
|
+
## 2.0.0-next.15
|
63
|
+
|
64
|
+
### Minor Changes
|
65
|
+
|
66
|
+
- 2d18cdc2: New createFormDialog function to create Zod or Yup specific FormDialogs
|
67
|
+
|
68
|
+
### Patch Changes
|
69
|
+
|
70
|
+
- Updated dependencies [826c561a]
|
71
|
+
- @saas-ui/core@2.0.0-next.13
|
72
|
+
|
73
|
+
## 2.0.0-next.14
|
74
|
+
|
75
|
+
### Patch Changes
|
76
|
+
|
77
|
+
- Fix esm bundle import
|
78
|
+
- Updated dependencies
|
79
|
+
- @saas-ui/core@2.0.0-next.12
|
80
|
+
|
81
|
+
## 2.0.0-next.13
|
82
|
+
|
83
|
+
### Patch Changes
|
84
|
+
|
85
|
+
- Bump version
|
86
|
+
- 6c63217c: object and array field props can now be overridden using the fields prop
|
87
|
+
- Updated dependencies
|
88
|
+
- @saas-ui/core@2.0.0-next.11
|
89
|
+
|
90
|
+
## 2.0.0-next.12
|
91
|
+
|
92
|
+
### Patch Changes
|
93
|
+
|
94
|
+
- a7ef6dd9: Fixed issue where types for exports were not detected
|
95
|
+
- Updated dependencies [a7ef6dd9]
|
96
|
+
- @saas-ui/core@2.0.0-next.10
|
97
|
+
|
98
|
+
## 2.0.0-next.11
|
99
|
+
|
100
|
+
### Patch Changes
|
101
|
+
|
102
|
+
- @saas-ui/core@2.0.0-next.9
|
103
|
+
|
104
|
+
## 2.0.0-next.10
|
105
|
+
|
106
|
+
### Patch Changes
|
107
|
+
|
108
|
+
- @saas-ui/core@2.0.0-next.8
|
109
|
+
|
3
110
|
## 2.0.0-next.9
|
4
111
|
|
5
112
|
### Patch Changes
|
@@ -98,6 +205,38 @@
|
|
98
205
|
- Updated dependencies [3a15e8c8]
|
99
206
|
- @saas-ui/core@2.0.0-next.0
|
100
207
|
|
208
|
+
## 1.5.5
|
209
|
+
|
210
|
+
### Patch Changes
|
211
|
+
|
212
|
+
- Fix types path
|
213
|
+
- Updated dependencies
|
214
|
+
- @saas-ui/button@1.4.2
|
215
|
+
- @saas-ui/input-right-button@1.4.2
|
216
|
+
- @saas-ui/number-input@1.4.2
|
217
|
+
- @saas-ui/password-input@1.4.2
|
218
|
+
- @saas-ui/pin-input@1.4.2
|
219
|
+
- @saas-ui/radio@1.4.3
|
220
|
+
- @saas-ui/react-utils@1.2.2
|
221
|
+
- @saas-ui/select@1.4.2
|
222
|
+
- @saas-ui/stepper@1.4.2
|
223
|
+
|
224
|
+
## 1.5.4
|
225
|
+
|
226
|
+
### Patch Changes
|
227
|
+
|
228
|
+
- b2302a3: Add types to package.json exports
|
229
|
+
- Updated dependencies [b2302a3]
|
230
|
+
- @saas-ui/button@1.4.1
|
231
|
+
- @saas-ui/input-right-button@1.4.1
|
232
|
+
- @saas-ui/number-input@1.4.1
|
233
|
+
- @saas-ui/password-input@1.4.1
|
234
|
+
- @saas-ui/pin-input@1.4.1
|
235
|
+
- @saas-ui/radio@1.4.2
|
236
|
+
- @saas-ui/react-utils@1.2.1
|
237
|
+
- @saas-ui/select@1.4.1
|
238
|
+
- @saas-ui/stepper@1.4.1
|
239
|
+
|
101
240
|
## 1.5.3
|
102
241
|
|
103
242
|
### Patch Changes
|
package/dist/ajv/index.d.ts
CHANGED
@@ -1,369 +1,34 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
|
4
|
-
import { HTMLChakraProps, ButtonProps, TextareaProps, SwitchProps, CheckboxProps, FormControlProps, ResponsiveValue, InputProps, RadioGroupProps, MenuProps, SelectProps as SelectProps$1, UsePinInputProps, SystemProps, NumberInputProps as NumberInputProps$1, StackDirection, MenuItemOptionProps, RadioProps } from '@chakra-ui/react';
|
5
|
-
import { FocusableElement } from '@chakra-ui/utils';
|
6
|
-
import * as react_hook_form from 'react-hook-form';
|
7
|
-
import { FieldValues, UseFormProps, FieldPath, UseFormReturn, WatchObserver, SubmitHandler, SubmitErrorHandler, RegisterOptions, UseFieldArrayReturn } from 'react-hook-form';
|
8
|
-
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
9
|
-
import * as ajv_dist_jtd from 'ajv/dist/jtd';
|
1
|
+
import { FieldResolver, CreateFormProps, WithFields, FormProps } from '@saas-ui/forms';
|
2
|
+
import { ajvResolver } from '@hookform/resolvers/ajv';
|
3
|
+
export { ajvResolver } from '@hookform/resolvers/ajv';
|
10
4
|
import { JTDDataType } from 'ajv/dist/jtd';
|
11
5
|
export { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd';
|
12
|
-
import * as _saas_ui_forms from '@saas-ui/forms';
|
13
|
-
import { FieldResolver as FieldResolver$1, CreateFormProps, WithFields as WithFields$1, FormProps as FormProps$1 } from '@saas-ui/forms';
|
14
6
|
import { JSONSchemaType } from 'ajv';
|
15
|
-
import { ajvResolver } from '@hookform/resolvers/ajv';
|
16
|
-
export { ajvResolver } from '@hookform/resolvers/ajv';
|
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$1.ReactNode;
|
44
|
-
/**
|
45
|
-
* Render a custom decrement icon.
|
46
|
-
*/
|
47
|
-
decrementIcon?: React$1.ReactNode;
|
48
|
-
}
|
49
|
-
interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
|
50
|
-
}
|
51
|
-
|
52
|
-
interface PasswordOptions {
|
53
|
-
viewIcon?: React$1__default.ReactNode;
|
54
|
-
viewOffIcon?: React$1__default.ReactNode;
|
55
|
-
leftAddon?: React$1__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$1__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$1.ReactNode;
|
138
|
-
rightAddon?: React$1.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$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
150
|
-
email: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
151
|
-
url: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
152
|
-
phone: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
153
|
-
number: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
154
|
-
password: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
155
|
-
textarea: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
156
|
-
switch: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
157
|
-
select: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
158
|
-
checkbox: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
159
|
-
radio: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
160
|
-
pin: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
161
|
-
'native-select': React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
162
|
-
};
|
163
|
-
type DefaultFields = typeof defaultFieldTypes;
|
164
7
|
|
165
|
-
|
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 FieldPathWithArray<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = TName | ArrayFieldPath<TName>;
|
210
|
-
type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
211
|
-
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
212
|
-
type?: K;
|
213
|
-
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
214
|
-
}>;
|
215
|
-
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
216
|
-
type FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
|
217
|
-
type DefaultFieldOverrides = {
|
218
|
-
submit?: SubmitButtonProps;
|
219
|
-
[key: string]: any;
|
220
|
-
};
|
221
|
-
type FieldOverrides<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
222
|
-
[K in FieldPathWithArray<TFieldValues, TName>]?: Omit<MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>, 'name'>;
|
223
|
-
};
|
224
|
-
type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs> = TFormProps extends FormProps<infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
|
225
|
-
children?: FormChildren<FieldDefs, TFieldValues, TContext>;
|
226
|
-
fields?: FieldOverrides<FieldDefs, TFieldValues> & {
|
227
|
-
submit?: SubmitButtonProps;
|
228
|
-
};
|
229
|
-
} : never;
|
230
|
-
|
231
|
-
type FieldResolver = {
|
232
|
-
getFields(): BaseFieldProps[];
|
233
|
-
getNestedFields(name: string): BaseFieldProps[];
|
234
|
-
};
|
235
|
-
|
236
|
-
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
237
|
-
children: React$1.ReactElement;
|
238
|
-
name: TName;
|
239
|
-
defaultValue?: unknown;
|
240
|
-
isDisabled?: boolean;
|
241
|
-
isExact?: boolean;
|
242
|
-
condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
|
243
|
-
}
|
244
|
-
|
245
|
-
interface UseArrayFieldReturn extends UseFieldArrayReturn {
|
246
|
-
/**
|
247
|
-
* The array field name
|
248
|
-
*/
|
249
|
-
name: string;
|
250
|
-
/**
|
251
|
-
* The default value for new items
|
252
|
-
*/
|
253
|
-
defaultValue: Record<string, any>;
|
254
|
-
/**
|
255
|
-
* Min amount of items
|
256
|
-
*/
|
257
|
-
min?: number;
|
258
|
-
/**
|
259
|
-
* Max amount of items
|
260
|
-
*/
|
261
|
-
max?: number;
|
262
|
-
}
|
263
|
-
interface ArrayFieldOptions<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
264
|
-
/**
|
265
|
-
* The field name
|
266
|
-
*/
|
267
|
-
name: TName;
|
268
|
-
/**
|
269
|
-
* Default value for new values in the array
|
270
|
-
*/
|
271
|
-
defaultValue?: Record<string, any>;
|
272
|
-
/**
|
273
|
-
* Default key name for rows, change this if your data uses a different 'id' field
|
274
|
-
* @default "id"
|
275
|
-
*/
|
276
|
-
keyName?: string;
|
277
|
-
min?: number;
|
278
|
-
max?: number;
|
279
|
-
}
|
280
|
-
interface ArrayFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ArrayFieldOptions<TFieldValues, TName>, Omit<BaseFieldProps<TFieldValues, TName>, 'name' | 'defaultValue' | 'children'> {
|
281
|
-
children: MaybeRenderProp<ArrayField[]>;
|
282
|
-
}
|
283
|
-
interface ArrayField {
|
284
|
-
id: string;
|
285
|
-
[key: string]: unknown;
|
286
|
-
}
|
287
|
-
/**
|
288
|
-
* The wrapper component that composes the default ArrayField functionality.
|
289
|
-
*
|
290
|
-
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
291
|
-
*/
|
292
|
-
declare const ArrayField: ((props: ArrayFieldProps & {
|
293
|
-
ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
|
294
|
-
}) => React$1.ReactElement) & {
|
295
|
-
displayName: string;
|
296
|
-
};
|
297
|
-
|
298
|
-
interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
|
299
|
-
name: TName;
|
300
|
-
children: React$1.ReactNode;
|
301
|
-
columns?: ResponsiveValue<number>;
|
302
|
-
spacing?: ResponsiveValue<string | number>;
|
303
|
-
}
|
304
|
-
|
305
|
-
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
|
306
|
-
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
307
|
-
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
308
|
-
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
309
|
-
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
310
|
-
}
|
311
|
-
interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> {
|
312
|
-
/**
|
313
|
-
* The form schema.
|
314
|
-
*/
|
315
|
-
schema?: TSchema;
|
316
|
-
/**
|
317
|
-
* Triggers when any of the field change.
|
318
|
-
*/
|
319
|
-
onChange?: WatchObserver<TFieldValues>;
|
320
|
-
/**
|
321
|
-
* The submit handler.
|
322
|
-
*/
|
323
|
-
onSubmit: SubmitHandler<TFieldValues>;
|
324
|
-
/**
|
325
|
-
* Triggers when there are validation errors.
|
326
|
-
*/
|
327
|
-
onError?: SubmitErrorHandler<TFieldValues>;
|
328
|
-
/**
|
329
|
-
* The Hook Form state ref.
|
330
|
-
*/
|
331
|
-
formRef?: React$1.RefObject<UseFormReturn<TFieldValues, TContext>>;
|
332
|
-
/**
|
333
|
-
* The form children, can be a render prop or a ReactNode.
|
334
|
-
*/
|
335
|
-
children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
|
336
|
-
/**
|
337
|
-
* The field resolver, used to resolve the fields from schemas.
|
338
|
-
*/
|
339
|
-
fieldResolver?: FieldResolver;
|
340
|
-
/**
|
341
|
-
* Field overrides
|
342
|
-
*/
|
343
|
-
fields?: DefaultFieldOverrides;
|
344
|
-
}
|
345
|
-
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> {
|
346
|
-
}
|
347
|
-
|
348
|
-
declare const ajvFieldResolver: (schema: JSONSchemaType<unknown>) => FieldResolver$1;
|
8
|
+
declare const ajvFieldResolver: (schema: JSONSchemaType<unknown>) => FieldResolver;
|
349
9
|
|
350
10
|
type ResolverArgs = Parameters<typeof ajvResolver>;
|
351
11
|
interface CreateAjvFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
|
352
12
|
schemaOptions?: ResolverArgs[1];
|
353
13
|
resolverOptions?: ResolverArgs[2];
|
354
14
|
}
|
15
|
+
type ParseJsonSchema<T> = T extends {
|
16
|
+
type: 'object';
|
17
|
+
} ? JTDDataType<T> extends infer R ? R extends object ? R : never : never : never;
|
18
|
+
type AjvFormType<FieldDefs, ExtraProps = object, JsonSchema extends Record<string, any> = Record<string, any>> = (<TSchema extends JsonSchema = JsonSchema, TFieldValues extends ParseJsonSchema<TSchema> = ParseJsonSchema<TSchema>, TContext extends object = object>(props: WithFields<FormProps<TSchema, TFieldValues, TContext>, FieldDefs> & {
|
19
|
+
ref?: React.ForwardedRef<HTMLFormElement>;
|
20
|
+
} & ExtraProps) => React.ReactElement) & {
|
21
|
+
displayName?: string;
|
22
|
+
id?: string;
|
23
|
+
};
|
355
24
|
/**
|
356
25
|
* Create a Form component with AJV validation that accepts JSON Type Definition schema
|
357
26
|
*
|
358
27
|
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
359
28
|
* @see https://ajv.js.org/json-type-definition.html
|
360
29
|
*/
|
361
|
-
declare function createAjvForm<FieldDefs>(options?: CreateAjvFormProps<FieldDefs>): <
|
362
|
-
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
363
|
-
}) => React.ReactElement;
|
30
|
+
declare function createAjvForm<FieldDefs>(options?: CreateAjvFormProps<FieldDefs>): AjvFormType<FieldDefs, object, Record<string, any>>;
|
364
31
|
|
365
|
-
declare const Form: <
|
366
|
-
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
367
|
-
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>;
|
32
|
+
declare const Form: AjvFormType<unknown, object, Record<string, any>>;
|
368
33
|
|
369
34
|
export { CreateAjvFormProps, Form, ajvFieldResolver, createAjvForm };
|
package/dist/ajv/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts","../../ajv/src/index.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAM5C,IAAM,mBAAmB,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;;;ACTA;AAAA,EACE;AAAA,
|
1
|
+
{"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts","../../ajv/src/index.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAM5C,IAAM,mBAAmB,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;;;ACTA;AAAA,EACE;AAAA,OAKK;AA0CA,SAAS,cACd,SACA;AACA,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AACH;;;AClDO,IAAM,OAAO,cAAc","sourcesContent":["import { ajvResolver } from '@hookform/resolvers/ajv'\nimport { objectFieldResolver, FieldResolver } from '@saas-ui/forms'\n\nimport { JSONSchemaType } from 'ajv'\n\nexport { ajvResolver }\n\nexport const ajvFieldResolver = (schema: JSONSchemaType<unknown>) => {\n return objectFieldResolver(schema.properties)\n}\n","import {\n createForm,\n CreateFormProps,\n FieldValues,\n FormProps,\n WithFields,\n} from '@saas-ui/forms'\nimport { ajvFieldResolver, ajvResolver } from './ajv-resolver'\nimport { JTDDataType } from 'ajv/dist/jtd'\ntype ResolverArgs = Parameters<typeof ajvResolver>\n\nexport interface CreateAjvFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\ntype ParseJsonSchema<T> = T extends { type: 'object' }\n ? JTDDataType<T> extends infer R\n ? R extends object\n ? R\n : never\n : never\n : never\n\nexport type AjvFormType<\n FieldDefs,\n ExtraProps = object,\n JsonSchema extends Record<string, any> = Record<string, any>\n> = (<\n TSchema extends JsonSchema = JsonSchema,\n TFieldValues extends ParseJsonSchema<TSchema> = ParseJsonSchema<TSchema>,\n TContext extends object = object\n>(\n props: WithFields<FormProps<TSchema, TFieldValues, TContext>, FieldDefs> & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\n/**\n * Create a Form component with AJV validation that accepts JSON Type Definition schema\n *\n * @see Docs https://saas-ui.dev/docs/components/forms/form\n * @see https://ajv.js.org/json-type-definition.html\n */\nexport function createAjvForm<FieldDefs>(\n options?: CreateAjvFormProps<FieldDefs>\n) {\n return createForm({\n resolver: (schema: any) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: ajvFieldResolver,\n ...options,\n }) as AjvFormType<FieldDefs>\n}\n","export * from './ajv-resolver'\nexport { createAjvForm } from './create-ajv-form'\nexport type { CreateAjvFormProps } from './create-ajv-form'\nexport type { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd'\n\nimport { createAjvForm } from './create-ajv-form'\n\nexport const Form = createAjvForm()\n"]}
|
package/dist/ajv/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts","../../ajv/src/index.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAM5C,IAAM,mBAAmB,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;;;ACTA;AAAA,EACE;AAAA,
|
1
|
+
{"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts","../../ajv/src/index.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAM5C,IAAM,mBAAmB,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;;;ACTA;AAAA,EACE;AAAA,OAKK;AA0CA,SAAS,cACd,SACA;AACA,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AACH;;;AClDO,IAAM,OAAO,cAAc","sourcesContent":["import { ajvResolver } from '@hookform/resolvers/ajv'\nimport { objectFieldResolver, FieldResolver } from '@saas-ui/forms'\n\nimport { JSONSchemaType } from 'ajv'\n\nexport { ajvResolver }\n\nexport const ajvFieldResolver = (schema: JSONSchemaType<unknown>) => {\n return objectFieldResolver(schema.properties)\n}\n","import {\n createForm,\n CreateFormProps,\n FieldValues,\n FormProps,\n WithFields,\n} from '@saas-ui/forms'\nimport { ajvFieldResolver, ajvResolver } from './ajv-resolver'\nimport { JTDDataType } from 'ajv/dist/jtd'\ntype ResolverArgs = Parameters<typeof ajvResolver>\n\nexport interface CreateAjvFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\ntype ParseJsonSchema<T> = T extends { type: 'object' }\n ? JTDDataType<T> extends infer R\n ? R extends object\n ? R\n : never\n : never\n : never\n\nexport type AjvFormType<\n FieldDefs,\n ExtraProps = object,\n JsonSchema extends Record<string, any> = Record<string, any>\n> = (<\n TSchema extends JsonSchema = JsonSchema,\n TFieldValues extends ParseJsonSchema<TSchema> = ParseJsonSchema<TSchema>,\n TContext extends object = object\n>(\n props: WithFields<FormProps<TSchema, TFieldValues, TContext>, FieldDefs> & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\n/**\n * Create a Form component with AJV validation that accepts JSON Type Definition schema\n *\n * @see Docs https://saas-ui.dev/docs/components/forms/form\n * @see https://ajv.js.org/json-type-definition.html\n */\nexport function createAjvForm<FieldDefs>(\n options?: CreateAjvFormProps<FieldDefs>\n) {\n return createForm({\n resolver: (schema: any) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: ajvFieldResolver,\n ...options,\n }) as AjvFormType<FieldDefs>\n}\n","export * from './ajv-resolver'\nexport { createAjvForm } from './create-ajv-form'\nexport type { CreateAjvFormProps } from './create-ajv-form'\nexport type { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd'\n\nimport { createAjvForm } from './create-ajv-form'\n\nexport const Form = createAjvForm()\n"]}
|