@saas-ui/forms 2.0.0-next.8 → 2.0.0-rc.22

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,112 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 2.0.0-rc.22
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7027d7c1]
8
+ - @saas-ui/core@2.0.0-rc.19
9
+
10
+ ## 2.0.0-next.21
11
+
12
+ ### Patch Changes
13
+
14
+ - @saas-ui/core@2.0.0-next.18
15
+
16
+ ## 2.0.0-next.20
17
+
18
+ ### Minor Changes
19
+
20
+ - a9ca90dd: Updated to Chakra UI 2.6.x
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [2b639656]
25
+ - @saas-ui/core@2.0.0-next.17
26
+
27
+ ## 2.0.0-next.19
28
+
29
+ ### Patch Changes
30
+
31
+ - @saas-ui/core@2.0.0-next.16
32
+
33
+ ## 2.0.0-next.18
34
+
35
+ ### Patch Changes
36
+
37
+ - 01ac442f: Fixed modal form handler type inference
38
+
39
+ ## 2.0.0-next.17
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [a5898c44]
44
+ - @saas-ui/core@2.0.0-next.15
45
+
46
+ ## 2.0.0-next.16
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [b8be6d41]
51
+ - @saas-ui/core@2.0.0-next.14
52
+
53
+ ## 2.0.0-next.15
54
+
55
+ ### Minor Changes
56
+
57
+ - 2d18cdc2: New createFormDialog function to create Zod or Yup specific FormDialogs
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [826c561a]
62
+ - @saas-ui/core@2.0.0-next.13
63
+
64
+ ## 2.0.0-next.14
65
+
66
+ ### Patch Changes
67
+
68
+ - Fix esm bundle import
69
+ - Updated dependencies
70
+ - @saas-ui/core@2.0.0-next.12
71
+
72
+ ## 2.0.0-next.13
73
+
74
+ ### Patch Changes
75
+
76
+ - Bump version
77
+ - 6c63217c: object and array field props can now be overridden using the fields prop
78
+ - Updated dependencies
79
+ - @saas-ui/core@2.0.0-next.11
80
+
81
+ ## 2.0.0-next.12
82
+
83
+ ### Patch Changes
84
+
85
+ - a7ef6dd9: Fixed issue where types for exports were not detected
86
+ - Updated dependencies [a7ef6dd9]
87
+ - @saas-ui/core@2.0.0-next.10
88
+
89
+ ## 2.0.0-next.11
90
+
91
+ ### Patch Changes
92
+
93
+ - @saas-ui/core@2.0.0-next.9
94
+
95
+ ## 2.0.0-next.10
96
+
97
+ ### Patch Changes
98
+
99
+ - @saas-ui/core@2.0.0-next.8
100
+
101
+ ## 2.0.0-next.9
102
+
103
+ ### Patch Changes
104
+
105
+ - 84e59fec: Form render prop Field now supports ref
106
+ - Updated dependencies [189190c6]
107
+ - Updated dependencies [1177329d]
108
+ - @saas-ui/core@2.0.0-next.7
109
+
3
110
  ## 2.0.0-next.8
4
111
 
5
112
  ### Patch Changes
@@ -89,6 +196,38 @@
89
196
  - Updated dependencies [3a15e8c8]
90
197
  - @saas-ui/core@2.0.0-next.0
91
198
 
199
+ ## 1.5.5
200
+
201
+ ### Patch Changes
202
+
203
+ - Fix types path
204
+ - Updated dependencies
205
+ - @saas-ui/button@1.4.2
206
+ - @saas-ui/input-right-button@1.4.2
207
+ - @saas-ui/number-input@1.4.2
208
+ - @saas-ui/password-input@1.4.2
209
+ - @saas-ui/pin-input@1.4.2
210
+ - @saas-ui/radio@1.4.3
211
+ - @saas-ui/react-utils@1.2.2
212
+ - @saas-ui/select@1.4.2
213
+ - @saas-ui/stepper@1.4.2
214
+
215
+ ## 1.5.4
216
+
217
+ ### Patch Changes
218
+
219
+ - b2302a3: Add types to package.json exports
220
+ - Updated dependencies [b2302a3]
221
+ - @saas-ui/button@1.4.1
222
+ - @saas-ui/input-right-button@1.4.1
223
+ - @saas-ui/number-input@1.4.1
224
+ - @saas-ui/password-input@1.4.1
225
+ - @saas-ui/pin-input@1.4.1
226
+ - @saas-ui/radio@1.4.2
227
+ - @saas-ui/react-utils@1.2.1
228
+ - @saas-ui/select@1.4.1
229
+ - @saas-ui/stepper@1.4.1
230
+
92
231
  ## 1.5.3
93
232
 
94
233
  ### Patch Changes
@@ -1,368 +1,34 @@
1
- import * as React$1 from 'react';
2
- import React$1__default from 'react';
3
- import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
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 * as react_hook_form from 'react-hook-form';
6
- import { FieldValues, UseFormProps, FieldPath, UseFormReturn, WatchObserver, SubmitHandler, SubmitErrorHandler, RegisterOptions, UseFieldArrayReturn } from 'react-hook-form';
7
- import { MaybeRenderProp } from '@chakra-ui/react-utils';
8
- 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';
9
4
  import { JTDDataType } from 'ajv/dist/jtd';
10
5
  export { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd';
11
- import * as _saas_ui_forms from '@saas-ui/forms';
12
- import { FieldResolver as FieldResolver$1, CreateFormProps, WithFields as WithFields$1, FormProps as FormProps$1 } from '@saas-ui/forms';
13
6
  import { JSONSchemaType } from 'ajv';
14
- import { ajvResolver } from '@hookform/resolvers/ajv';
15
- export { ajvResolver } from '@hookform/resolvers/ajv';
16
-
17
- interface SubmitButtonProps extends ButtonProps {
18
- /**
19
- * Disable the submit button if the form is untouched.
20
- *
21
- * Change the default behavior by updating
22
- * `SubmitButton.defaultProps.disableIfUntouched`
23
- */
24
- disableIfUntouched?: boolean;
25
- /**
26
- * Disable the submit button if the form is invalid.
27
- *
28
- * Change the default behavior by updating
29
- * `SubmitButton.defaultProps.disableIfInvalid`
30
- */
31
- disableIfInvalid?: boolean;
32
- }
33
-
34
- interface NumberInputOptions {
35
- /**
36
- * Hide the stepper.
37
- */
38
- hideStepper?: boolean;
39
- /**
40
- * Render a custom increment icon.
41
- */
42
- incrementIcon?: React$1.ReactNode;
43
- /**
44
- * Render a custom decrement icon.
45
- */
46
- decrementIcon?: React$1.ReactNode;
47
- }
48
- interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
49
- }
50
-
51
- interface PasswordOptions {
52
- viewIcon?: React$1__default.ReactNode;
53
- viewOffIcon?: React$1__default.ReactNode;
54
- leftAddon?: React$1__default.ReactNode;
55
- }
56
- interface PasswordInputProps extends InputProps, PasswordOptions {
57
- }
58
-
59
- interface RadioOption extends Omit<RadioProps, 'value' | 'label'>, FieldOption {
60
- }
61
- type RadioOptions = FieldOptions<RadioOption>;
62
- interface RadioInputOptions {
63
- options: RadioOptions;
64
- spacing?: SystemProps['margin'];
65
- direction?: StackDirection;
66
- }
67
- interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputOptions {
68
- }
69
-
70
- interface SelectOptions {
71
- /**
72
- * The name of the input field in a native form.
73
- */
74
- name: string;
75
- /**
76
- * The value of the select field.
77
- */
78
- value?: string | string[];
79
- /**
80
- * The initial value of the select field.
81
- */
82
- defaultValue?: string | string[];
83
- /**
84
- * The callback invoked when the value of the select field changes.
85
- * @param value The value of the select field.
86
- */
87
- onChange?: (value: string | string[]) => void;
88
- /**
89
- * The placeholder text when there's no value.
90
- */
91
- placeholder?: string;
92
- /**
93
- * If `true`, the select will be disabled.
94
- */
95
- isDisabled?: boolean;
96
- /**
97
- * An array of options
98
- * If you leave this empty the children prop will be rendered.
99
- */
100
- options?: FieldOptions<SelectOption>;
101
- /**
102
- * Enable multiple select.
103
- */
104
- multiple?: boolean;
105
- /**
106
- * The function used to render the value of the select field.
107
- * @param value The value of the select field.
108
- * @returns The rendered value.
109
- */
110
- renderValue?: (value: string | string[]) => React$1__default.ReactNode;
111
- }
112
-
113
- interface SelectProps extends Omit<MenuProps, 'children'>, SelectOptions {
114
- }
115
- interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
116
- }
117
- /**
118
- * An option in a select list
119
- *
120
- * @see https://saas-ui.dev/docs/components/forms/select
121
- */
122
- declare const SelectOption: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", MenuItemOptionProps>;
123
-
124
- interface Option$1 {
125
- value: string;
126
- label?: string;
127
- }
128
- interface NativeSelectOptions {
129
- options?: Option$1[];
130
- }
131
- interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
132
- }
133
-
134
- interface InputFieldProps extends InputProps {
135
- type?: string;
136
- leftAddon?: React$1.ReactNode;
137
- rightAddon?: React$1.ReactNode;
138
- }
139
- interface NumberInputFieldProps extends NumberInputProps {
140
- type: 'number';
141
- }
142
- interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
143
- pinLength?: number;
144
- pinType?: 'alphanumeric' | 'number';
145
- spacing?: SystemProps['margin'];
146
- }
147
- declare const defaultFieldTypes: {
148
- text: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
149
- email: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
150
- url: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
151
- phone: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
152
- number: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
153
- password: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
154
- textarea: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
155
- switch: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
156
- select: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
157
- checkbox: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
158
- radio: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
159
- pin: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
160
- 'native-select': React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
161
- };
162
- type DefaultFields = typeof defaultFieldTypes;
163
7
 
164
- type FieldOption = {
165
- label?: string;
166
- value: string;
167
- };
168
- type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
169
- type ValueOf<T> = T[keyof T];
170
- type ShallowMerge<A, B> = Omit<A, keyof B> & B;
171
- 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];
172
- 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> : ''}` : '' : '';
173
- type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
174
- type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
175
- interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
176
- /**
177
- * The field name
178
- */
179
- name: TName | ArrayFieldPath<TName>;
180
- /**
181
- * The field label
182
- */
183
- label?: string;
184
- /**
185
- * Hide the field label
186
- */
187
- hideLabel?: boolean;
188
- /**
189
- * Field help text
190
- */
191
- help?: string;
192
- /**
193
- * React hook form rules
194
- */
195
- rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
196
- /**
197
- * Build-in types:
198
- * text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
199
- *
200
- * Will default to a text field if there is no matching type.
201
- */
202
- type?: string;
203
- /**
204
- * The input placeholder
205
- */
206
- placeholder?: string;
207
- }
208
- type FieldPathWithArray<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = TName | ArrayFieldPath<TName>;
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 FormChildren<FieldDefs, TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = MaybeRenderProp<FormRenderContext<TFieldValues, TContext, MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>>>;
216
- type DefaultFieldOverrides = {
217
- submit?: SubmitButtonProps;
218
- [key: string]: any;
219
- };
220
- type FieldOverrides<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
221
- [K in FieldPathWithArray<TFieldValues, TName>]?: Omit<MergeFieldProps<FieldDefs extends never ? DefaultFields : ShallowMerge<DefaultFields, FieldDefs>, TFieldValues>, 'name'>;
222
- };
223
- type WithFields<TFormProps extends FormProps<any, any, any, any>, FieldDefs> = TFormProps extends FormProps<infer TFieldValues, infer TContext> ? Omit<TFormProps, 'children' | 'fields'> & {
224
- children?: FormChildren<FieldDefs, TFieldValues, TContext>;
225
- fields?: FieldOverrides<FieldDefs, TFieldValues> & {
226
- submit?: SubmitButtonProps;
227
- };
228
- } : never;
229
-
230
- type FieldResolver = {
231
- getFields(): BaseFieldProps[];
232
- getNestedFields(name: string): BaseFieldProps[];
233
- };
234
-
235
- interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
236
- children: React$1.ReactElement;
237
- name: TName;
238
- defaultValue?: unknown;
239
- isDisabled?: boolean;
240
- isExact?: boolean;
241
- condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
242
- }
243
-
244
- interface UseArrayFieldReturn extends UseFieldArrayReturn {
245
- /**
246
- * The array field name
247
- */
248
- name: string;
249
- /**
250
- * The default value for new items
251
- */
252
- defaultValue: Record<string, any>;
253
- /**
254
- * Min amount of items
255
- */
256
- min?: number;
257
- /**
258
- * Max amount of items
259
- */
260
- max?: number;
261
- }
262
- interface ArrayFieldOptions<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
263
- /**
264
- * The field name
265
- */
266
- name: TName;
267
- /**
268
- * Default value for new values in the array
269
- */
270
- defaultValue?: Record<string, any>;
271
- /**
272
- * Default key name for rows, change this if your data uses a different 'id' field
273
- * @default "id"
274
- */
275
- keyName?: string;
276
- min?: number;
277
- max?: number;
278
- }
279
- interface ArrayFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ArrayFieldOptions<TFieldValues, TName>, Omit<BaseFieldProps<TFieldValues, TName>, 'name' | 'defaultValue' | 'children'> {
280
- children: MaybeRenderProp<ArrayField[]>;
281
- }
282
- interface ArrayField {
283
- id: string;
284
- [key: string]: unknown;
285
- }
286
- /**
287
- * The wrapper component that composes the default ArrayField functionality.
288
- *
289
- * @see Docs https://saas-ui.dev/docs/components/forms/array-field
290
- */
291
- declare const ArrayField: ((props: ArrayFieldProps & {
292
- ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
293
- }) => React$1.ReactElement) & {
294
- displayName: string;
295
- };
296
-
297
- interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
298
- name: TName;
299
- children: React$1.ReactNode;
300
- columns?: ResponsiveValue<number>;
301
- spacing?: ResponsiveValue<string | number>;
302
- }
303
-
304
- interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
305
- Field: React$1.FC<TFieldTypes>;
306
- DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
307
- ArrayField: React$1.FC<ArrayFieldProps<TFieldValues>>;
308
- ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
309
- }
310
- interface FormOptions<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TSchema = any, TFieldTypes = FieldProps<TFieldValues>> {
311
- /**
312
- * The form schema.
313
- */
314
- schema?: TSchema;
315
- /**
316
- * Triggers when any of the field change.
317
- */
318
- onChange?: WatchObserver<TFieldValues>;
319
- /**
320
- * The submit handler.
321
- */
322
- onSubmit: SubmitHandler<TFieldValues>;
323
- /**
324
- * Triggers when there are validation errors.
325
- */
326
- onError?: SubmitErrorHandler<TFieldValues>;
327
- /**
328
- * The Hook Form state ref.
329
- */
330
- formRef?: React$1.RefObject<UseFormReturn<TFieldValues, TContext>>;
331
- /**
332
- * The form children, can be a render prop or a ReactNode.
333
- */
334
- children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
335
- /**
336
- * The field resolver, used to resolve the fields from schemas.
337
- */
338
- fieldResolver?: FieldResolver;
339
- /**
340
- * Field overrides
341
- */
342
- fields?: DefaultFieldOverrides;
343
- }
344
- 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> {
345
- }
346
-
347
- declare const ajvFieldResolver: (schema: JSONSchemaType<unknown>) => FieldResolver$1;
8
+ declare const ajvFieldResolver: (schema: JSONSchemaType<unknown>) => FieldResolver;
348
9
 
349
10
  type ResolverArgs = Parameters<typeof ajvResolver>;
350
11
  interface CreateAjvFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
351
12
  schemaOptions?: ResolverArgs[1];
352
13
  resolverOptions?: ResolverArgs[2];
353
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
+ };
354
24
  /**
355
25
  * Create a Form component with AJV validation that accepts JSON Type Definition schema
356
26
  *
357
27
  * @see Docs https://saas-ui.dev/docs/components/forms/form
358
28
  * @see https://ajv.js.org/json-type-definition.html
359
29
  */
360
- declare function createAjvForm<FieldDefs>(options?: CreateAjvFormProps<FieldDefs>): <TSchema extends Record<string, any>, TContext extends object = object, TJSONSchema = JTDDataType<TSchema>>(props: WithFields$1<FormProps$1<TJSONSchema, TContext, TSchema, _saas_ui_forms.FieldProps<TJSONSchema>>, FieldDefs> & {
361
- ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
362
- }) => React.ReactElement;
30
+ declare function createAjvForm<FieldDefs>(options?: CreateAjvFormProps<FieldDefs>): AjvFormType<FieldDefs, object, Record<string, any>>;
363
31
 
364
- declare const Form: <TSchema extends Record<string, any>, TContext extends object = object, TJSONSchema = ajv_dist_jtd.JTDDataType<TSchema>>(props: WithFields<FormProps<TJSONSchema, TContext, TSchema, FieldProps<TJSONSchema>>, unknown> & {
365
- ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
366
- }) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>;
32
+ declare const Form: AjvFormType<unknown, object, Record<string, any>>;
367
33
 
368
34
  export { CreateAjvFormProps, Form, ajvFieldResolver, createAjvForm };
@@ -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,OAIK;AAiBA,SAAS,cACd,SACA;AACA,SAAO,WAAgB;AAAA,IACrB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAUH;;;ACjCO,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 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\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<any>({\n resolver: (schema) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: ajvFieldResolver,\n ...options,\n }) as <\n TSchema extends Record<string, any>,\n TContext extends object = object,\n TJSONSchema = JTDDataType<TSchema>\n >(\n /** @ts-expect-error @todo properly fix these types */\n props: WithFields<FormProps<TJSONSchema, TContext, TSchema>, FieldDefs> & {\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n ) => React.ReactElement\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"]}
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"]}
@@ -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,OAIK;AAiBA,SAAS,cACd,SACA;AACA,SAAO,WAAgB;AAAA,IACrB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAUH;;;ACjCO,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 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\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<any>({\n resolver: (schema) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: ajvFieldResolver,\n ...options,\n }) as <\n TSchema extends Record<string, any>,\n TContext extends object = object,\n TJSONSchema = JTDDataType<TSchema>\n >(\n /** @ts-expect-error @todo properly fix these types */\n props: WithFields<FormProps<TJSONSchema, TContext, TSchema>, FieldDefs> & {\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n ) => React.ReactElement\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"]}
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"]}