@saas-ui/forms 2.0.0-next.2 → 2.0.0-next.20
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +188 -0
- package/README.md +53 -6
- package/dist/ajv/index.d.ts +24 -11
- package/dist/ajv/index.js +7 -9
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +7 -10
- package/dist/ajv/index.mjs.map +1 -1
- package/dist/index.d.ts +519 -280
- package/dist/index.js +777 -696
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +756 -676
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +525 -21
- package/dist/yup/index.js +21 -9
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +21 -10
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +525 -12
- package/dist/zod/index.js +21 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +21 -3
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +33 -10
- package/src/array-field.tsx +88 -48
- package/src/auto-form.tsx +7 -3
- package/src/base-field.tsx +54 -0
- package/src/create-field.tsx +144 -0
- package/src/create-form.tsx +68 -0
- package/src/create-step-form.tsx +100 -0
- package/src/default-fields.tsx +163 -0
- package/src/display-field.tsx +9 -11
- package/src/display-if.tsx +20 -13
- package/src/field-resolver.ts +10 -8
- package/src/field.tsx +18 -445
- package/src/fields-context.tsx +23 -0
- package/src/fields.tsx +34 -21
- package/src/form-context.tsx +84 -0
- package/src/form.tsx +77 -55
- package/src/index.ts +58 -4
- package/src/input-right-button/input-right-button.stories.tsx +1 -1
- package/src/input-right-button/input-right-button.tsx +0 -2
- package/src/layout.tsx +16 -11
- package/src/number-input/number-input.tsx +9 -5
- package/src/object-field.tsx +35 -13
- package/src/password-input/password-input.stories.tsx +23 -2
- package/src/password-input/password-input.tsx +6 -6
- package/src/pin-input/pin-input.tsx +1 -5
- package/src/radio/radio-input.stories.tsx +1 -1
- package/src/radio/radio-input.tsx +12 -10
- package/src/select/native-select.tsx +1 -4
- package/src/select/select-context.tsx +130 -0
- package/src/select/select.stories.tsx +116 -85
- package/src/select/select.test.tsx +1 -1
- package/src/select/select.tsx +162 -146
- package/src/step-form.tsx +76 -76
- package/src/submit-button.tsx +5 -1
- package/src/types.ts +149 -0
- package/src/use-array-field.tsx +9 -3
- package/src/use-step-form.tsx +54 -9
- package/src/utils.ts +23 -1
- package/src/watch-field.tsx +2 -6
- /package/src/radio/{radio.test.tsx → radio-input.test.tsx} +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,155 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 2.0.0-next.20
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- a9ca90dd: Updated to Chakra UI 2.6.x
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- Updated dependencies [2b639656]
|
12
|
+
- @saas-ui/core@2.0.0-next.17
|
13
|
+
|
14
|
+
## 2.0.0-next.19
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- @saas-ui/core@2.0.0-next.16
|
19
|
+
|
20
|
+
## 2.0.0-next.18
|
21
|
+
|
22
|
+
### Patch Changes
|
23
|
+
|
24
|
+
- 01ac442f: Fixed modal form handler type inference
|
25
|
+
|
26
|
+
## 2.0.0-next.17
|
27
|
+
|
28
|
+
### Patch Changes
|
29
|
+
|
30
|
+
- Updated dependencies [a5898c44]
|
31
|
+
- @saas-ui/core@2.0.0-next.15
|
32
|
+
|
33
|
+
## 2.0.0-next.16
|
34
|
+
|
35
|
+
### Patch Changes
|
36
|
+
|
37
|
+
- Updated dependencies [b8be6d41]
|
38
|
+
- @saas-ui/core@2.0.0-next.14
|
39
|
+
|
40
|
+
## 2.0.0-next.15
|
41
|
+
|
42
|
+
### Minor Changes
|
43
|
+
|
44
|
+
- 2d18cdc2: New createFormDialog function to create Zod or Yup specific FormDialogs
|
45
|
+
|
46
|
+
### Patch Changes
|
47
|
+
|
48
|
+
- Updated dependencies [826c561a]
|
49
|
+
- @saas-ui/core@2.0.0-next.13
|
50
|
+
|
51
|
+
## 2.0.0-next.14
|
52
|
+
|
53
|
+
### Patch Changes
|
54
|
+
|
55
|
+
- Fix esm bundle import
|
56
|
+
- Updated dependencies
|
57
|
+
- @saas-ui/core@2.0.0-next.12
|
58
|
+
|
59
|
+
## 2.0.0-next.13
|
60
|
+
|
61
|
+
### Patch Changes
|
62
|
+
|
63
|
+
- Bump version
|
64
|
+
- 6c63217c: object and array field props can now be overridden using the fields prop
|
65
|
+
- Updated dependencies
|
66
|
+
- @saas-ui/core@2.0.0-next.11
|
67
|
+
|
68
|
+
## 2.0.0-next.12
|
69
|
+
|
70
|
+
### Patch Changes
|
71
|
+
|
72
|
+
- a7ef6dd9: Fixed issue where types for exports were not detected
|
73
|
+
- Updated dependencies [a7ef6dd9]
|
74
|
+
- @saas-ui/core@2.0.0-next.10
|
75
|
+
|
76
|
+
## 2.0.0-next.11
|
77
|
+
|
78
|
+
### Patch Changes
|
79
|
+
|
80
|
+
- @saas-ui/core@2.0.0-next.9
|
81
|
+
|
82
|
+
## 2.0.0-next.10
|
83
|
+
|
84
|
+
### Patch Changes
|
85
|
+
|
86
|
+
- @saas-ui/core@2.0.0-next.8
|
87
|
+
|
88
|
+
## 2.0.0-next.9
|
89
|
+
|
90
|
+
### Patch Changes
|
91
|
+
|
92
|
+
- 84e59fec: Form render prop Field now supports ref
|
93
|
+
- Updated dependencies [189190c6]
|
94
|
+
- Updated dependencies [1177329d]
|
95
|
+
- @saas-ui/core@2.0.0-next.7
|
96
|
+
|
97
|
+
## 2.0.0-next.8
|
98
|
+
|
99
|
+
### Patch Changes
|
100
|
+
|
101
|
+
- 6d3f5717: Fix React import
|
102
|
+
|
103
|
+
## 2.0.0-next.7
|
104
|
+
|
105
|
+
### Patch Changes
|
106
|
+
|
107
|
+
- Updated dependencies [7052dad3]
|
108
|
+
- @saas-ui/core@2.0.0-next.6
|
109
|
+
|
110
|
+
## 2.0.0-next.6
|
111
|
+
|
112
|
+
### Major Changes
|
113
|
+
|
114
|
+
- 532011d6: Restructured the Select component to make it atomic, the new composition is Select, SelectButton, SelectList and SelectOption.
|
115
|
+
- 39e778d8: Form will now render AutoField by default when no children are passed.
|
116
|
+
|
117
|
+
### Minor Changes
|
118
|
+
|
119
|
+
- 532011d6: Select can now supports theming using the SuiSelect theme config.
|
120
|
+
- 6dd737ce: Select field now renders invalid state.
|
121
|
+
- c85541cb: AutoForm field props can now be overridden using the fields prop on Form
|
122
|
+
|
123
|
+
## 2.0.0-next.5
|
124
|
+
|
125
|
+
### Minor Changes
|
126
|
+
|
127
|
+
- a8ea24da: PasswordInput now accepts leftAddon property.
|
128
|
+
|
129
|
+
### Patch Changes
|
130
|
+
|
131
|
+
- Updated dependencies [61b27fa6]
|
132
|
+
- @saas-ui/core@2.0.0-next.5
|
133
|
+
|
134
|
+
## 2.0.0-next.4
|
135
|
+
|
136
|
+
### Patch Changes
|
137
|
+
|
138
|
+
- Updated dependencies [83f54180]
|
139
|
+
- Updated dependencies [ba61612f]
|
140
|
+
- Updated dependencies [83f54180]
|
141
|
+
- Updated dependencies [83f54180]
|
142
|
+
- Updated dependencies [83f54180]
|
143
|
+
- Updated dependencies [83f54180]
|
144
|
+
- Updated dependencies [27a68bca]
|
145
|
+
- @saas-ui/core@2.0.0-next.4
|
146
|
+
|
147
|
+
## 2.0.0-next.3
|
148
|
+
|
149
|
+
### Patch Changes
|
150
|
+
|
151
|
+
- @saas-ui/core@2.0.0-next.3
|
152
|
+
|
3
153
|
## 2.0.0-next.2
|
4
154
|
|
5
155
|
### Patch Changes
|
@@ -33,6 +183,44 @@
|
|
33
183
|
- Updated dependencies [3a15e8c8]
|
34
184
|
- @saas-ui/core@2.0.0-next.0
|
35
185
|
|
186
|
+
## 1.5.5
|
187
|
+
|
188
|
+
### Patch Changes
|
189
|
+
|
190
|
+
- Fix types path
|
191
|
+
- Updated dependencies
|
192
|
+
- @saas-ui/button@1.4.2
|
193
|
+
- @saas-ui/input-right-button@1.4.2
|
194
|
+
- @saas-ui/number-input@1.4.2
|
195
|
+
- @saas-ui/password-input@1.4.2
|
196
|
+
- @saas-ui/pin-input@1.4.2
|
197
|
+
- @saas-ui/radio@1.4.3
|
198
|
+
- @saas-ui/react-utils@1.2.2
|
199
|
+
- @saas-ui/select@1.4.2
|
200
|
+
- @saas-ui/stepper@1.4.2
|
201
|
+
|
202
|
+
## 1.5.4
|
203
|
+
|
204
|
+
### Patch Changes
|
205
|
+
|
206
|
+
- b2302a3: Add types to package.json exports
|
207
|
+
- Updated dependencies [b2302a3]
|
208
|
+
- @saas-ui/button@1.4.1
|
209
|
+
- @saas-ui/input-right-button@1.4.1
|
210
|
+
- @saas-ui/number-input@1.4.1
|
211
|
+
- @saas-ui/password-input@1.4.1
|
212
|
+
- @saas-ui/pin-input@1.4.1
|
213
|
+
- @saas-ui/radio@1.4.2
|
214
|
+
- @saas-ui/react-utils@1.2.1
|
215
|
+
- @saas-ui/select@1.4.1
|
216
|
+
- @saas-ui/stepper@1.4.1
|
217
|
+
|
218
|
+
## 1.5.3
|
219
|
+
|
220
|
+
### Patch Changes
|
221
|
+
|
222
|
+
- 382e095: InputRightButton no longer exported from forms package to prevent conflicts.
|
223
|
+
|
36
224
|
## 1.5.2
|
37
225
|
|
38
226
|
### Patch Changes
|
package/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# Forms Manager
|
2
2
|
|
3
|
-
Chakra UI
|
3
|
+
Powerfull forms library for Chakra UI.
|
4
|
+
Create typesafe React forms with speed.
|
4
5
|
|
5
|
-
|
6
|
+
Supports Zod, Yup and AJV for validation and form generation.
|
6
7
|
|
7
|
-
|
8
|
+
- [Docs](https://www.saas-ui.dev/docs/forms/form)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -16,9 +17,55 @@ $ yarn add @saas-ui/forms
|
|
16
17
|
$ npm i @saas-ui/forms --save
|
17
18
|
```
|
18
19
|
|
19
|
-
##
|
20
|
+
## Usage with Zod
|
20
21
|
|
21
|
-
|
22
|
+
### AutoForm
|
23
|
+
|
24
|
+
Generate forms from schema.
|
25
|
+
|
26
|
+
```tsx
|
27
|
+
import { createZodForm } from '@saas-ui/forms/zod'
|
28
|
+
|
29
|
+
const { AutoForm } = createZodForm()
|
30
|
+
|
31
|
+
const schema = z.object({
|
32
|
+
name: z.string(),
|
33
|
+
})
|
34
|
+
|
35
|
+
function App() {
|
36
|
+
const onSubmit = (data: z.infer<typeof schema>) => {}
|
37
|
+
return <AutoForm schema={schema} onSubmit={onSubmit} />
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
### Form
|
42
|
+
|
43
|
+
Create custom typesafe forms.
|
44
|
+
|
45
|
+
```tsx
|
46
|
+
import { FormLayout, createZodForm } from '@saas-ui/forms/zod'
|
47
|
+
|
48
|
+
const { Form, SubmitButton } = createZodForm()
|
49
|
+
|
50
|
+
const schema = z.object({
|
51
|
+
name: z.string()
|
52
|
+
})
|
53
|
+
|
54
|
+
function App() {
|
55
|
+
const onSubmit = (data: z.infer<typeof schema>) => {}
|
56
|
+
|
57
|
+
return (
|
58
|
+
<Form schema={schema} onSubmit={onSubmit}>
|
59
|
+
{({ Field }) => (
|
60
|
+
<FormLayout>
|
61
|
+
<Field name="name" type="text" />
|
62
|
+
<SubmitButton>Save</SubmitButton>
|
63
|
+
</FormLayotu>
|
64
|
+
)}
|
65
|
+
</Form>
|
66
|
+
)
|
67
|
+
}
|
68
|
+
```
|
22
69
|
|
23
70
|
## Source
|
24
71
|
|
package/dist/ajv/index.d.ts
CHANGED
@@ -1,21 +1,34 @@
|
|
1
|
+
import { FieldResolver, CreateFormProps, WithFields, FormProps } from '@saas-ui/forms';
|
1
2
|
import { ajvResolver } from '@hookform/resolvers/ajv';
|
2
3
|
export { ajvResolver } from '@hookform/resolvers/ajv';
|
3
|
-
import {
|
4
|
-
import { JSONSchemaType } from 'ajv';
|
4
|
+
import { JTDDataType } from 'ajv/dist/jtd';
|
5
5
|
export { JTDDataType, JTDSchemaType } from 'ajv/dist/jtd';
|
6
|
+
import { JSONSchemaType } from 'ajv';
|
6
7
|
|
7
|
-
|
8
|
-
schema: JSONSchemaType<unknown>;
|
9
|
-
fieldResolver: FieldResolver;
|
10
|
-
resolver: ReturnType<typeof ajvResolver>;
|
11
|
-
}
|
12
|
-
declare const jsonSchemaForm: (schema: JSONSchemaType<unknown>) => JsonSchemaFormReturn;
|
8
|
+
declare const ajvFieldResolver: (schema: JSONSchemaType<unknown>) => FieldResolver;
|
13
9
|
|
14
10
|
type ResolverArgs = Parameters<typeof ajvResolver>;
|
15
|
-
interface CreateAjvFormProps extends CreateFormProps {
|
11
|
+
interface CreateAjvFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
|
16
12
|
schemaOptions?: ResolverArgs[1];
|
17
13
|
resolverOptions?: ResolverArgs[2];
|
18
14
|
}
|
19
|
-
|
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
|
+
};
|
24
|
+
/**
|
25
|
+
* Create a Form component with AJV validation that accepts JSON Type Definition schema
|
26
|
+
*
|
27
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/form
|
28
|
+
* @see https://ajv.js.org/json-type-definition.html
|
29
|
+
*/
|
30
|
+
declare function createAjvForm<FieldDefs>(options?: CreateAjvFormProps<FieldDefs>): AjvFormType<FieldDefs, object, Record<string, any>>;
|
31
|
+
|
32
|
+
declare const Form: AjvFormType<unknown, object, Record<string, any>>;
|
20
33
|
|
21
|
-
export { CreateAjvFormProps,
|
34
|
+
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
|
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
|
package/dist/ajv/index.js.map
CHANGED
@@ -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;
|
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
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
import { ajvResolver } from '@hookform/resolvers/ajv';
|
2
2
|
export { ajvResolver } from '@hookform/resolvers/ajv';
|
3
|
-
import {
|
3
|
+
import { objectFieldResolver, createForm } from '@saas-ui/forms';
|
4
4
|
|
5
5
|
// ajv/src/ajv-resolver.ts
|
6
|
-
var
|
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
|
-
|
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
|
package/dist/ajv/index.mjs.map
CHANGED
@@ -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;
|
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"]}
|