@saas-ui/forms 0.6.0-next.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +26 -12
- package/dist/auto-form.d.ts +5 -2
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/field-resolver.d.ts +7 -2
- package/dist/field-resolver.d.ts.map +1 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/form.d.ts +9 -3
- package/dist/form.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/yup/index.js +2 -0
- package/dist/yup/index.js.map +1 -0
- package/dist/yup/index.modern.js +2 -0
- package/dist/yup/index.modern.js.map +1 -0
- package/dist/yup/src/index.d.ts +2 -0
- package/dist/yup/src/index.d.ts.map +1 -0
- package/dist/yup/src/yup.d.ts +25 -0
- package/dist/yup/src/yup.d.ts.map +1 -0
- package/package.json +8 -12
- package/src/auto-form.tsx +4 -3
- package/src/field-resolver.ts +10 -5
- package/src/fields.tsx +2 -2
- package/src/form.tsx +25 -2
- package/yup/package.json +11 -4
package/src/fields.tsx
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import * as React from 'react'
|
2
2
|
|
3
|
+
import { Form } from './form'
|
3
4
|
import { FormLayout } from './layout'
|
4
5
|
import { Field, FieldProps } from './field'
|
5
6
|
|
6
7
|
import { ArrayField } from './array-field'
|
7
8
|
import { ObjectField } from './object-field'
|
8
9
|
import { FieldResolver } from './field-resolver'
|
9
|
-
import { defaultFieldResolver } from './field-resolver'
|
10
10
|
|
11
11
|
export interface FieldsProps {
|
12
12
|
schema: any
|
@@ -29,7 +29,7 @@ export const Fields: React.FC<FieldsProps> = ({
|
|
29
29
|
...props
|
30
30
|
}) => {
|
31
31
|
const resolver = React.useMemo(
|
32
|
-
() => fieldResolver ||
|
32
|
+
() => fieldResolver || Form.getFieldResolver(schema),
|
33
33
|
[schema, fieldResolver]
|
34
34
|
)
|
35
35
|
|
package/src/form.tsx
CHANGED
@@ -10,7 +10,11 @@ import {
|
|
10
10
|
FieldValues,
|
11
11
|
SubmitHandler,
|
12
12
|
SubmitErrorHandler,
|
13
|
+
UnpackNestedValue,
|
14
|
+
ResolverOptions,
|
15
|
+
ResolverResult,
|
13
16
|
} from 'react-hook-form'
|
17
|
+
import { objectFieldResolver, FieldResolver } from './field-resolver'
|
14
18
|
|
15
19
|
export type { UseFormReturn, FieldValues, SubmitHandler }
|
16
20
|
|
@@ -77,6 +81,10 @@ export const Form = forwardRef(
|
|
77
81
|
delayError,
|
78
82
|
}
|
79
83
|
|
84
|
+
if (schema && !resolver) {
|
85
|
+
form.resolver = Form.getResolver?.(schema)
|
86
|
+
}
|
87
|
+
|
80
88
|
const methods = useForm<TFieldValues>(form)
|
81
89
|
const { handleSubmit } = methods
|
82
90
|
|
@@ -95,8 +103,23 @@ export const Form = forwardRef(
|
|
95
103
|
</FormProvider>
|
96
104
|
)
|
97
105
|
}
|
98
|
-
) as <TFieldValues extends FieldValues>(
|
106
|
+
) as (<TFieldValues extends FieldValues>(
|
99
107
|
props: FormProps<TFieldValues> & {
|
100
108
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>
|
101
109
|
}
|
102
|
-
) => React.ReactElement
|
110
|
+
) => React.ReactElement) & {
|
111
|
+
getResolver?: GetResolver
|
112
|
+
getFieldResolver: GetFieldResolver
|
113
|
+
}
|
114
|
+
|
115
|
+
Form.getFieldResolver = objectFieldResolver
|
116
|
+
|
117
|
+
export type GetResolver = (
|
118
|
+
schema: any
|
119
|
+
) => <TFieldValues extends FieldValues, TContext>(
|
120
|
+
values: UnpackNestedValue<TFieldValues>,
|
121
|
+
context: TContext | undefined,
|
122
|
+
options: ResolverOptions<TFieldValues>
|
123
|
+
) => Promise<ResolverResult<TFieldValues>>
|
124
|
+
|
125
|
+
export type GetFieldResolver = (schema: any) => FieldResolver
|
package/yup/package.json
CHANGED
@@ -3,10 +3,17 @@
|
|
3
3
|
"description": "Saas UI Forms field resolver: yup",
|
4
4
|
"version": "1.0.0",
|
5
5
|
"private": true,
|
6
|
-
"source": "src/index.ts",
|
7
|
-
"
|
8
|
-
|
9
|
-
|
6
|
+
"source": "./src/index.ts",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"require": "./../dist/yup/index.js",
|
10
|
+
"types": "./../dist/yup/src/index.d.ts",
|
11
|
+
"default": "./../dist/yup/index.modern.js"
|
12
|
+
}
|
13
|
+
},
|
14
|
+
"main": "../dist/yup/index.js",
|
15
|
+
"module": "../dist/yup/index.modern.js",
|
16
|
+
"types": "../dist/yup/src/index.d.ts",
|
10
17
|
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
11
18
|
"license": "MIT",
|
12
19
|
"peerDependencies": {
|