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

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 +13 -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 +373 -2613
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +373 -2607
  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 +15 -8
  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 +152 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 2.0.0-next.6
4
+
5
+ ### Major Changes
6
+
7
+ - 532011d6: Restructured the Select component to make it atomic, the new composition is Select, SelectButton, SelectList and SelectOption.
8
+ - 39e778d8: Form will now render AutoField by default when no children are passed.
9
+
10
+ ### Minor Changes
11
+
12
+ - 532011d6: Select can now supports theming using the SuiSelect theme config.
13
+ - 6dd737ce: Select field now renders invalid state.
14
+ - c85541cb: AutoForm field props can now be overridden using the fields prop on Form
15
+
3
16
  ## 2.0.0-next.5
4
17
 
5
18
  ### Minor Changes
@@ -1,21 +1,368 @@
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';
9
+ import { JTDDataType } from 'ajv/dist/jtd';
10
+ 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
+ import { JSONSchemaType } from 'ajv';
1
14
  import { ajvResolver } from '@hookform/resolvers/ajv';
2
15
  export { ajvResolver } from '@hookform/resolvers/ajv';
3
- import { FieldResolver, CreateFormProps } from '@saas-ui/forms';
4
- import { JSONSchemaType } from 'ajv';
5
- export { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd';
6
16
 
7
- interface JsonSchemaFormReturn {
8
- schema: JSONSchemaType<unknown>;
9
- fieldResolver: FieldResolver;
10
- resolver: ReturnType<typeof ajvResolver>;
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 {
11
132
  }
12
- declare const jsonSchemaForm: (schema: JSONSchemaType<unknown>) => JsonSchemaFormReturn;
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
+
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;
13
348
 
14
349
  type ResolverArgs = Parameters<typeof ajvResolver>;
15
- interface CreateAjvFormProps extends CreateFormProps<any> {
350
+ interface CreateAjvFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
16
351
  schemaOptions?: ResolverArgs[1];
17
352
  resolverOptions?: ResolverArgs[2];
18
353
  }
19
- declare function createAjvForm(options?: CreateAjvFormProps): any;
354
+ /**
355
+ * Create a Form component with AJV validation that accepts JSON Type Definition schema
356
+ *
357
+ * @see Docs https://saas-ui.dev/docs/components/forms/form
358
+ * @see https://ajv.js.org/json-type-definition.html
359
+ */
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;
363
+
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>>;
20
367
 
21
- export { CreateAjvFormProps, createAjvForm, jsonSchemaForm };
368
+ export { CreateAjvFormProps, Form, ajvFieldResolver, createAjvForm };
package/dist/ajv/index.js CHANGED
@@ -4,28 +4,26 @@ var ajv = require('@hookform/resolvers/ajv');
4
4
  var forms = require('@saas-ui/forms');
5
5
 
6
6
  // ajv/src/ajv-resolver.ts
7
- var jsonSchemaFieldResolver = (schema) => {
7
+ var ajvFieldResolver = (schema) => {
8
8
  return forms.objectFieldResolver(schema.properties);
9
9
  };
10
- var jsonSchemaForm = (schema) => {
11
- return {
12
- schema,
13
- fieldResolver: jsonSchemaFieldResolver(schema),
14
- resolver: ajv.ajvResolver(schema)
15
- };
16
- };
17
10
  function createAjvForm(options) {
18
11
  return forms.createForm({
19
12
  resolver: (schema) => ajv.ajvResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
13
+ fieldResolver: ajvFieldResolver,
20
14
  ...options
21
15
  });
22
16
  }
23
17
 
18
+ // ajv/src/index.ts
19
+ var Form = createAjvForm();
20
+
24
21
  Object.defineProperty(exports, 'ajvResolver', {
25
22
  enumerable: true,
26
23
  get: function () { return ajv.ajvResolver; }
27
24
  });
25
+ exports.Form = Form;
26
+ exports.ajvFieldResolver = ajvFieldResolver;
28
27
  exports.createAjvForm = createAjvForm;
29
- exports.jsonSchemaForm = jsonSchemaForm;
30
28
  //# sourceMappingURL=out.js.map
31
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAMnD,IAAM,0BAA0B,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;AAQO,IAAM,iBAAiB,CAC5B,WACyB;AACzB,SAAO;AAAA,IACL;AAAA,IACA,eAAe,wBAAwB,MAAM;AAAA,IAC7C,UAAU,YAAY,MAAM;AAAA,EAC9B;AACF;;;ACzBA;AAAA,EACE;AAAA,OAIK;AAWA,SAAS,cAAc,SAAmC;AAC/D,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,GAAG;AAAA,EACL,CAAC;AAOH","sourcesContent":["import { ajvResolver } from '@hookform/resolvers/ajv'\nimport { objectFieldResolver, FieldResolver } from '@saas-ui/forms'\n\nimport { JSONSchemaType } from 'ajv'\n\nexport { ajvResolver }\n\nconst jsonSchemaFieldResolver = (schema: JSONSchemaType<unknown>) => {\n return objectFieldResolver(schema.properties)\n}\n\ninterface JsonSchemaFormReturn {\n schema: JSONSchemaType<unknown>\n fieldResolver: FieldResolver\n resolver: ReturnType<typeof ajvResolver>\n}\n\nexport const jsonSchemaForm = (\n schema: JSONSchemaType<unknown>\n): JsonSchemaFormReturn => {\n return {\n schema,\n fieldResolver: jsonSchemaFieldResolver(schema),\n resolver: ajvResolver(schema),\n }\n}\n","import {\n createForm,\n CreateFormProps,\n FieldValues,\n FormProps,\n} from '@saas-ui/forms'\nimport { ajvResolver } from './ajv-resolver'\nimport { JSONSchemaType } from 'ajv'\n\ntype ResolverArgs = Parameters<typeof ajvResolver>\n\nexport interface CreateAjvFormProps extends CreateFormProps<any> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport function createAjvForm(options?: CreateAjvFormProps): any {\n return createForm({\n resolver: (schema) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n ...options,\n }) as <\n TFieldValues extends FieldValues = FieldValues,\n TSchema extends JSONSchemaType<TFieldValues> = JSONSchemaType<TFieldValues>,\n TContext extends object = object\n >(\n props: FormProps<TFieldValues, TContext, TSchema>\n ) => React.ReactElement\n}\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,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,25 +1,22 @@
1
1
  import { ajvResolver } from '@hookform/resolvers/ajv';
2
2
  export { ajvResolver } from '@hookform/resolvers/ajv';
3
- import { createForm, objectFieldResolver } from '@saas-ui/forms';
3
+ import { objectFieldResolver, createForm } from '@saas-ui/forms';
4
4
 
5
5
  // ajv/src/ajv-resolver.ts
6
- var jsonSchemaFieldResolver = (schema) => {
6
+ var ajvFieldResolver = (schema) => {
7
7
  return objectFieldResolver(schema.properties);
8
8
  };
9
- var jsonSchemaForm = (schema) => {
10
- return {
11
- schema,
12
- fieldResolver: jsonSchemaFieldResolver(schema),
13
- resolver: ajvResolver(schema)
14
- };
15
- };
16
9
  function createAjvForm(options) {
17
10
  return createForm({
18
11
  resolver: (schema) => ajvResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
12
+ fieldResolver: ajvFieldResolver,
19
13
  ...options
20
14
  });
21
15
  }
22
16
 
23
- export { createAjvForm, jsonSchemaForm };
17
+ // ajv/src/index.ts
18
+ var Form = createAjvForm();
19
+
20
+ export { Form, ajvFieldResolver, createAjvForm };
24
21
  //# sourceMappingURL=out.js.map
25
22
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ajv/src/ajv-resolver.ts","../../ajv/src/create-ajv-form.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,2BAA0C;AAMnD,IAAM,0BAA0B,CAAC,WAAoC;AACnE,SAAO,oBAAoB,OAAO,UAAU;AAC9C;AAQO,IAAM,iBAAiB,CAC5B,WACyB;AACzB,SAAO;AAAA,IACL;AAAA,IACA,eAAe,wBAAwB,MAAM;AAAA,IAC7C,UAAU,YAAY,MAAM;AAAA,EAC9B;AACF;;;ACzBA;AAAA,EACE;AAAA,OAIK;AAWA,SAAS,cAAc,SAAmC;AAC/D,SAAO,WAAW;AAAA,IAChB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,GAAG;AAAA,EACL,CAAC;AAOH","sourcesContent":["import { ajvResolver } from '@hookform/resolvers/ajv'\nimport { objectFieldResolver, FieldResolver } from '@saas-ui/forms'\n\nimport { JSONSchemaType } from 'ajv'\n\nexport { ajvResolver }\n\nconst jsonSchemaFieldResolver = (schema: JSONSchemaType<unknown>) => {\n return objectFieldResolver(schema.properties)\n}\n\ninterface JsonSchemaFormReturn {\n schema: JSONSchemaType<unknown>\n fieldResolver: FieldResolver\n resolver: ReturnType<typeof ajvResolver>\n}\n\nexport const jsonSchemaForm = (\n schema: JSONSchemaType<unknown>\n): JsonSchemaFormReturn => {\n return {\n schema,\n fieldResolver: jsonSchemaFieldResolver(schema),\n resolver: ajvResolver(schema),\n }\n}\n","import {\n createForm,\n CreateFormProps,\n FieldValues,\n FormProps,\n} from '@saas-ui/forms'\nimport { ajvResolver } from './ajv-resolver'\nimport { JSONSchemaType } from 'ajv'\n\ntype ResolverArgs = Parameters<typeof ajvResolver>\n\nexport interface CreateAjvFormProps extends CreateFormProps<any> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport function createAjvForm(options?: CreateAjvFormProps): any {\n return createForm({\n resolver: (schema) =>\n ajvResolver(schema, options?.schemaOptions, options?.resolverOptions),\n ...options,\n }) as <\n TFieldValues extends FieldValues = FieldValues,\n TSchema extends JSONSchemaType<TFieldValues> = JSONSchemaType<TFieldValues>,\n TContext extends object = object\n >(\n props: FormProps<TFieldValues, TContext, TSchema>\n ) => React.ReactElement\n}\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,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"]}