@saas-ui/forms 0.5.0 → 0.6.0-next.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +51 -0
- package/dist/array-field.d.ts +3 -3
- package/dist/array-field.d.ts.map +1 -1
- package/dist/auto-form.d.ts +2 -1
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/field-resolver.d.ts +8 -0
- package/dist/field-resolver.d.ts.map +1 -0
- package/dist/field.d.ts +3 -2
- package/dist/field.d.ts.map +1 -1
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/form.d.ts +3 -3
- package/dist/form.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.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/step-form.d.ts +5 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/use-array-field.d.ts +1 -1
- package/dist/use-step-form.d.ts +3 -0
- package/dist/use-step-form.d.ts.map +1 -1
- package/package.json +21 -13
- package/src/array-field.tsx +56 -45
- package/src/auto-form.tsx +6 -5
- package/src/field-resolver.ts +39 -0
- package/src/field.tsx +3 -2
- package/src/fields.tsx +45 -30
- package/src/form.tsx +6 -13
- package/src/index.ts +1 -1
- package/src/step-form.tsx +8 -3
- package/src/use-array-field.tsx +1 -1
- package/src/use-step-form.tsx +6 -3
- package/yup/package.json +17 -0
- package/dist/resolvers/yup.d.ts +0 -12
- package/dist/resolvers/yup.d.ts.map +0 -1
- package/src/resolvers/yup.ts +0 -79
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,56 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 0.6.0-next.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 9391c44: BREAKING: Removed yup dependency from forms and fixed peer dependency issues.
|
8
|
+
|
9
|
+
<Form> doesn't accept a Yup `schema` any more by default.
|
10
|
+
|
11
|
+
Use a schema resolver to use schema support. All hookform resolvers are supported.
|
12
|
+
|
13
|
+
```
|
14
|
+
import {yupResolver} from '@hookform/resolvers/yup'
|
15
|
+
|
16
|
+
<Form resolver={yupResolver(schema)} />
|
17
|
+
```
|
18
|
+
|
19
|
+
AutoForm only supports Yup for now and has a new API.
|
20
|
+
|
21
|
+
```
|
22
|
+
import { yupForm } from '@saas-ui/forms/yup'
|
23
|
+
|
24
|
+
<AutoForm {...yupForm(schema)} />
|
25
|
+
```
|
26
|
+
|
27
|
+
### Patch Changes
|
28
|
+
|
29
|
+
- Updated dependencies [9391c44]
|
30
|
+
- @saas-ui/button@0.4.0-next.0
|
31
|
+
- @saas-ui/select@0.4.0-next.0
|
32
|
+
- @saas-ui/input-right-button@0.3.1-next.0
|
33
|
+
- @saas-ui/password-input@0.3.1-next.0
|
34
|
+
|
35
|
+
## 0.5.3
|
36
|
+
|
37
|
+
### Patch Changes
|
38
|
+
|
39
|
+
- 9245460: Make sure Field ref is focusable
|
40
|
+
|
41
|
+
## 0.5.2
|
42
|
+
|
43
|
+
### Patch Changes
|
44
|
+
|
45
|
+
- 0f67f76: Fixed circular dependency
|
46
|
+
|
47
|
+
## 0.5.1
|
48
|
+
|
49
|
+
### Patch Changes
|
50
|
+
|
51
|
+
- c610881: Fixed a type error
|
52
|
+
- a26aa7c: ArrayField context can now be accessed using ref.
|
53
|
+
|
3
54
|
## 0.5.0
|
4
55
|
|
5
56
|
### Minor Changes
|
package/dist/array-field.d.ts
CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
2
2
|
import { ResponsiveValue } from '@chakra-ui/system';
|
3
3
|
import { ButtonProps } from '@saas-ui/button';
|
4
4
|
import { FieldProps } from './field';
|
5
|
-
import { ArrayFieldOptions } from './use-array-field';
|
5
|
+
import { ArrayFieldOptions, UseArrayFieldReturn } from './use-array-field';
|
6
6
|
interface ArrayField {
|
7
7
|
id: string;
|
8
8
|
[key: string]: unknown;
|
@@ -38,11 +38,11 @@ export declare const ArrayFieldRemoveButton: React.FC<ButtonProps>;
|
|
38
38
|
export declare const ArrayFieldAddButton: React.FC<ButtonProps>;
|
39
39
|
export interface ArrayFieldProps extends ArrayFieldOptions, Omit<FieldProps, 'defaultValue'> {
|
40
40
|
}
|
41
|
-
export declare const ArrayField: React.
|
41
|
+
export declare const ArrayField: React.ForwardRefExoticComponent<ArrayFieldProps & React.RefAttributes<UseArrayFieldReturn>>;
|
42
42
|
export interface ArrayFieldRowsProps {
|
43
43
|
children: (fields: ArrayField[]) => React.ReactElement | null;
|
44
44
|
}
|
45
45
|
export declare const ArrayFieldRows: ({ children, }: ArrayFieldRowsProps) => React.ReactElement | null;
|
46
|
-
export declare const ArrayFieldContainer: React.
|
46
|
+
export declare const ArrayFieldContainer: React.ForwardRefExoticComponent<ArrayFieldProps & React.RefAttributes<UseArrayFieldReturn>>;
|
47
47
|
export {};
|
48
48
|
//# sourceMappingURL=array-field.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"array-field.d.ts","sourceRoot":"","sources":["../src/array-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EAAc,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAa,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,EAKL,iBAAiB,
|
1
|
+
{"version":3,"file":"array-field.d.ts","sourceRoot":"","sources":["../src/array-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EAAc,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAa,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,EAKL,iBAAiB,EAKjB,mBAAmB,EACpB,MAAM,mBAAmB,CAAA;AAE1B,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,UAAU,kBAAkB;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IAC1C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CActD,CAAA;AAED,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAkBlE,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAmB/D,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CASxD,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAUrD,CAAA;AAED,MAAM,WAAW,eACf,SAAQ,iBAAiB,EACvB,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC;CAAG;AAEvC,eAAO,MAAM,UAAU,6FAqBtB,CAAA;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAC9D;AAED,eAAO,MAAM,cAAc,kBAExB,mBAAmB,KAAG,MAAM,YAAY,GAAG,IAG7C,CAAA;AAED,eAAO,MAAM,mBAAmB,6FAgC/B,CAAA"}
|
package/dist/auto-form.d.ts
CHANGED
@@ -2,8 +2,9 @@ import * as React from 'react';
|
|
2
2
|
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
3
3
|
import { FormProps } from './form';
|
4
4
|
interface AutoFormOptions {
|
5
|
-
schema: any;
|
6
5
|
submitLabel?: false | string;
|
6
|
+
schema: any;
|
7
|
+
fieldResolver?: any;
|
7
8
|
}
|
8
9
|
export interface AutoFormProps<TFieldValues extends FieldValues> extends Omit<FormProps<TFieldValues>, 'schema'>, AutoFormOptions {
|
9
10
|
}
|
package/dist/auto-form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auto-form.d.ts","sourceRoot":"","sources":["../src/auto-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"auto-form.d.ts","sourceRoot":"","sources":["../src/auto-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKxC,UAAU,eAAe;IACvB,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,GAAG,CAAA;CACpB;AAED,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,CAC7D,SAAQ,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,EAC7C,eAAe;CAAG;AAEtB,eAAO,MAAM,QAAQ;;MAoBhB,MAAM,YAAY,CAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { FieldProps } from './field';
|
2
|
+
export declare type FieldResolver = {
|
3
|
+
getFields(): FieldProps[];
|
4
|
+
getNestedFields(name: string): FieldProps[];
|
5
|
+
};
|
6
|
+
export declare type FormSchema = Record<string, any>;
|
7
|
+
export declare const defaultFieldResolver: (schema: FormSchema) => FieldResolver;
|
8
|
+
//# sourceMappingURL=field-resolver.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"field-resolver.d.ts","sourceRoot":"","sources":["../src/field-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIpC,oBAAY,aAAa,GAAG;IAC1B,SAAS,IAAI,UAAU,EAAE,CAAA;IACzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;CAC5C,CAAA;AAGD,oBAAY,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAU5C,eAAO,MAAM,oBAAoB,WAAY,UAAU,KAAG,aAkBzD,CAAA"}
|
package/dist/field.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { RegisterOptions, FieldValues, FieldPath } from 'react-hook-form';
|
3
|
-
import {
|
3
|
+
import { FormControlProps } from '@chakra-ui/react';
|
4
|
+
import { FocusableElement } from '@chakra-ui/utils';
|
4
5
|
export interface Option {
|
5
6
|
value: string;
|
6
7
|
label?: string;
|
@@ -60,7 +61,7 @@ export declare const BaseField: React.FC<FieldProps>;
|
|
60
61
|
export declare const Field: <TFieldValues extends FieldValues>(props: FieldProps<TFieldValues, import("react-hook-form").Path<TFieldValues>> & {
|
61
62
|
[key: string]: unknown;
|
62
63
|
} & {
|
63
|
-
ref?: React.ForwardedRef<
|
64
|
+
ref?: React.ForwardedRef<FocusableElement> | undefined;
|
64
65
|
}) => React.ReactElement;
|
65
66
|
export declare const withControlledInput: (InputComponent: any) => import("@chakra-ui/react").ComponentWithAs<any, FieldProps<FieldValues, string>>;
|
66
67
|
export declare const withUncontrolledInput: (InputComponent: any) => import("@chakra-ui/react").ComponentWithAs<any, FieldProps<FieldValues, string>>;
|
package/dist/field.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAKL,eAAe,EACf,WAAW,EACX,SAAS,EACV,MAAM,iBAAiB,CAAA;AAExB,OAAO,
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAKL,eAAe,EACf,WAAW,EACX,SAAS,EACV,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAIL,gBAAgB,EASjB,MAAM,kBAAkB,CAAA;AAOzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,oBAAY,UAAU,GAAG,IAAI,CAC3B,eAAe,EACf,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CACnE,CAAA;AAED,oBAAY,UAAU,GAClB,MAAM,GACN,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,GACR,eAAe,GACf,UAAU,GACV,OAAO,GACP,QAAQ,GACR,KAAK,GACL,MAAM,CAAA;AAEV,MAAM,WAAW,UAAU,CACzB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,CAC/D,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,CAAC;IAChD;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IACX;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,CACV,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,EACpC,eAAe,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAC5D,CAAA;IACD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAqBD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CAwB1C,CAAA;AACD,eAAO,MAAM,KAAK;;;;MAkBb,MAAM,YAAY,CAAA;AA0DvB,eAAO,MAAM,mBAAmB,mBAAoB,GAAG,qFAqBtD,CAAA;AAED,eAAO,MAAM,qBAAqB,mBAAoB,GAAG,qFAgBxD,CAAA;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,SACtB,MAAM,aACD,MAAM,EAAE,CAAC,GAAG,CAAC,qMAsBzB,CAAA;AAID,eAAO,MAAM,UAAU,kJAAmC,CAAA;AAC1D,eAAO,MAAM,gBAAgB,kJAE3B,CAAA;AACF,eAAO,MAAM,kBAAkB,kJAA+C,CAAA;AAC9E,eAAO,MAAM,aAAa,kJAA0C,CAAA;AACpE,eAAO,MAAM,WAAW,kJAavB,CAAA;AACD,eAAO,MAAM,WAAW,kJAEtB,CAAA;AACF,eAAO,MAAM,aAAa,kJAYzB,CAAA;AACD,eAAO,MAAM,UAAU,kJAErB,CAAA;AACF,eAAO,MAAM,QAAQ,kJAEnB,CAAA;AACF,eAAO,MAAM,iBAAiB,kJAI7B,CAAA"}
|
package/dist/fields.d.ts
CHANGED
package/dist/fields.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGhD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAYD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAwCxC,CAAA"}
|
package/dist/form.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { HTMLChakraProps } from '@chakra-ui/react';
|
3
3
|
import { UseFormProps, UseFormReturn, FieldValues, SubmitHandler, SubmitErrorHandler } from 'react-hook-form';
|
4
|
-
export type { UseFormReturn };
|
4
|
+
export type { UseFormReturn, FieldValues, SubmitHandler };
|
5
5
|
interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
6
6
|
/**
|
7
7
|
* The form schema, currently supports Yup schema only.
|
@@ -20,12 +20,12 @@ interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
20
20
|
*/
|
21
21
|
formRef?: React.MutableRefObject<HTMLFormElement>;
|
22
22
|
}
|
23
|
-
export interface FormProps<TFieldValues extends FieldValues = FieldValues> extends UseFormProps<TFieldValues>, Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>, FormOptions<TFieldValues> {
|
24
|
-
}
|
25
23
|
/**
|
26
24
|
* @todo Figure out how to pass down FieldValues to all Field components,
|
27
25
|
* if at all possible.
|
28
26
|
*/
|
27
|
+
export interface FormProps<TFieldValues extends FieldValues = FieldValues> extends UseFormProps<TFieldValues>, Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>, FormOptions<TFieldValues> {
|
28
|
+
}
|
29
29
|
export declare const Form: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
|
30
30
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
31
31
|
}) => React.ReactElement;
|
package/dist/form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AAExB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA;AAEzD,UAAU,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW;IAClE;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAA;CAClD;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,YAAY,CAAC,YAAY,CAAC,EAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,EACrD,WAAW,CAAC,YAAY,CAAC;CAAG;AAEhC,eAAO,MAAM,IAAI;;MAyDZ,MAAM,YAAY,CAAA"}
|
package/dist/index.d.ts
CHANGED
@@ -11,6 +11,7 @@ export * from './object-field';
|
|
11
11
|
export * from './display-if';
|
12
12
|
export * from './step-form';
|
13
13
|
export * from './use-step-form';
|
14
|
+
export * from './field-resolver';
|
14
15
|
export * from '@saas-ui/input-right-button';
|
15
16
|
export type { FieldErrors } from 'react-hook-form';
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,6BAA6B,CAAA;AAE3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),o=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),l=require("@saas-ui/select"),u=require("yup"),s=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),p=require("@chakra-ui/icons"),f=require("@saas-ui/button"),d=require("@chakra-ui/react-utils"),m=require("@saas-ui/react-utils"),v=require("@saas-ui/input-right-button");function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var y=/*#__PURE__*/h(e);function b(){return b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},b.apply(this,arguments)}function _(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var g=["name","label","placeholder"],E=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},S=["name","label","help","variant","hideLabel","children"],F=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],C=["name","rules"],j=["ref"],w=["name","rules"],A=["ref"],O=["label"],N=["label"],k={},I=function(e){var n=e.name,a=e.label,o=e.help,i=e.variant,l=e.hideLabel,u=e.children,s=_(e,S),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return y.createElement(r.FormControl,b({variant:i},s,{isInvalid:!!c}),a&&!l?/*#__PURE__*/y.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/y.createElement(r.Box,null,u,!o||null!=c&&c.message?null:/*#__PURE__*/y.createElement(r.FormHelperText,null,o),(null==c?void 0:c.message)&&/*#__PURE__*/y.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},R=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return y.createElement(k[void 0===r?"text":r]||k.text,b({ref:t},e))}),P=function(e){return r.forwardRef(function(n,a){var o=n.name,i=n.rules,l=_(n,C),u=t.useFormContext();/*#__PURE__*/return y.createElement(t.Controller,{name:o,control:u.control,rules:i,render:function(t){var n=t.field,o=n.ref,i=_(n,j);/*#__PURE__*/return y.createElement(e,b({},i,l,{ref:r.useMergeRefs(a,o)}))}})})},L=function(e){return r.forwardRef(function(n,a){var o=n.name,i=n.rules,l=_(n,w),u=(0,t.useFormContext().register)(o,i),s=u.ref,c=_(u,A);/*#__PURE__*/return y.createElement(e,b({},c,l,{ref:r.useMergeRefs(a,s)}))})},V=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,o=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,l=t.help,u=t.isDisabled,s=t.isInvalid,c=t.isReadOnly,p=t.isRequired,f=t.rules,d=t.variant,m=_(t,F),v=b({required:p},f);/*#__PURE__*/return y.createElement(o,{name:n,label:i,help:l,hideLabel:a,isDisabled:u,isInvalid:s,isReadOnly:c,isRequired:p,variant:d},/*#__PURE__*/y.createElement(e,b({ref:r,name:n,label:i,rules:v},m)))});return i.displayName=n,i}(null!=n&&n.isControlled?P(t):L(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return k[e]=a,a},B=V("text",r.Input),z=V("number",n.NumberInput,{isControlled:!0}),D=V("password",a.PasswordInput),q=V("textarea",r.Textarea),T=V("switch",r.forwardRef(function(e,t){var n=e.label,a=_(e,O);/*#__PURE__*/return y.createElement(r.Switch,b({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=V("select",l.Select,{isControlled:!0}),U=V("checkbox",r.forwardRef(function(e,t){var n=e.label,a=_(e,N);/*#__PURE__*/return y.createElement(r.Checkbox,b({ref:t},a),n)}),{hideLabel:!0}),$=V("radio",o.RadioInput,{isControlled:!0}),G=V("pin",i.PinInput,{isControlled:!0}),W=V("native-select",l.NativeSelect,{isControlled:!0}),H=function(e){var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},J=function(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return x(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(r=n()).done;){var a,o=r.value;if(null!=(a=o.OPTIONS)&&a.params[t])return o.OPTIONS.params[t]}},K=function(e){var t,r=[];for(var n in t="array"===e.type?e.innerType.fields:e.fields){var a=t[n],o={};"array"===a.type&&(o.min=J(a,"min"),o.max=J(a,"max")),r.push(b({name:n,label:a.spec.label||n,type:H(a)},o))}return r},Q=["children"],X=function(e){/*#__PURE__*/return y.createElement(r.chakra.div,null,e.children)},Y=function(e){var t,n,a,o=e.children,i=_(e,Q),l=b({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return y.createElement(r.SimpleGrid,l,y.Children.map(o,function(e){return y.isValidElement(e)?/*#__PURE__*/y.createElement(X,null,e):e}))},Z=function(e,t){return y.Children.map(t,function(t){return y.isValidElement(t)&&t.props.name?y.cloneElement(t,b({},t.props,{name:e+"."+t.props.name})):t})},ee=d.createContext({name:"ArrayFieldContext"}),te=ee[0],re=ee[1],ne=d.createContext({name:"ArrayFieldRowContext"}),ae=ne[0],oe=ne[1],ie=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,o=e.keyName,i=e.min,l=e.max,u=t.useFormContext();return b({},t.useFieldArray({control:u.control,name:r,keyName:o}),{name:r,defaultValue:a,min:i,max:l})},le=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=re(),o=a.name,i=a.remove,l=a.fields;return y.useEffect(function(){n(o)},[]),{index:r,isFirst:0===r,isLast:r===l.length-1,name:o+"."+r,remove:y.useCallback(function(){n(o),i(r)},[r])}},ue=function(){var e=oe(),t=e.isFirst,r=e.remove,n=re(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},se=function(){var e=re(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ce=["children","columns","spacing"],pe=["children"],fe=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return y.createElement(ve,{index:e.index},/*#__PURE__*/y.createElement(me,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/y.createElement(he,null))},me=function(e){var t=e.children,r=e.columns,n=e.spacing,a=_(e,ce),o=oe().name;/*#__PURE__*/return y.createElement(Y,b({flex:"1",columns:r,gridGap:n,mr:"2"},a),Z(o,t))},ve=function(e){var t=e.children,r=le({index:e.index});/*#__PURE__*/return y.createElement(ae,{value:r},/*#__PURE__*/y.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},he=function(e){/*#__PURE__*/return y.createElement(f.IconButton,b({icon:/*#__PURE__*/y.createElement(p.MinusIcon,null),"aria-label":"Remove row"},ue(),e))},ye=function(e){/*#__PURE__*/return y.createElement(f.IconButton,b({icon:/*#__PURE__*/y.createElement(p.AddIcon,null),"aria-label":"Add row",float:"right"},se(),e))},be=function(e){var t=e.children,r=_(e,pe);/*#__PURE__*/return y.createElement(xe,r,/*#__PURE__*/y.createElement(_e,null,function(e){/*#__PURE__*/return y.createElement(y.Fragment,null,e.map(function(e,r){/*#__PURE__*/return y.createElement(de,{key:e.id,index:r},t)}))}),/*#__PURE__*/y.createElement(ye,null))},_e=function(e){return(0,e.children)(re().fields)},xe=function(e){var t=e.name,r=e.defaultValue,n=e.keyName,a=e.min,o=e.max,i=e.children,l=_(e,fe),u=ie({name:t,defaultValue:r,keyName:n,min:a,max:o});/*#__PURE__*/return y.createElement(te,{value:u},/*#__PURE__*/y.createElement(I,b({name:t},l),i))},ge=["name","label","hideLabel","children","columns","spacing"],Ee=function(e){var t=r.useStyles();/*#__PURE__*/return y.createElement(r.FormLabel,b({as:"legend",sx:t.legend},e))},Se=function(e){var t=e.name,n=e.label,a=e.hideLabel,o=e.children,i=e.columns,l=e.spacing,u=_(e,ge);/*#__PURE__*/return y.createElement(r.FormControl,b({name:t,as:"fieldset"},u),/*#__PURE__*/y.createElement(Ee,{display:a?"none":"block"},n),/*#__PURE__*/y.createElement(Y,{columns:i,gridGap:l},Z(t,o)))},Fe=["name","type"],Ce=["schema"],je=["name","type","defaultValue"],we=function(e,t){return K(function(e,t){return u.reach(e,t)}(e,t)).map(function(e){var t=e.name,r=e.type,n=_(e,Fe);/*#__PURE__*/return y.createElement(R,b({key:t,name:t,type:r},n))})},Ae=function(e){var t=e.schema,r=_(e,Ce);/*#__PURE__*/return y.createElement(Y,r,K(t).map(function(e){var r=e.name,n=e.type,a=_(e,je);return"array"===n?/*#__PURE__*/y.createElement(be,b({name:r},a),we(t,r)):"object"===n?/*#__PURE__*/y.createElement(Se,b({name:r},a),we(t,r)):/*#__PURE__*/y.createElement(R,b({key:r,name:r,type:n},a))}))},Oe=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ne=r.forwardRef(function(e,n){var a=e.mode,o=void 0===a?"all":a,i=e.resolver,l=e.reValidateMode,u=e.shouldFocusError,c=e.shouldUnregister,p=e.shouldUseNativeValidation,f=e.criteriaMode,d=e.delayError,m=e.schema,v=e.defaultValues,h=e.onSubmit,x=e.onError,g=e.formRef,E=e.children,S=_(e,Oe),F={mode:o,resolver:i,defaultValues:v,reValidateMode:l,shouldFocusError:u,shouldUnregister:c,shouldUseNativeValidation:p,criteriaMode:f,delayError:d};m&&(F.resolver=s.yupResolver(m));var C=t.useForm(F),j=C.handleSubmit;return y.useImperativeHandle(n,function(){return C},[n,C]),/*#__PURE__*/y.createElement(t.FormProvider,C,/*#__PURE__*/y.createElement(r.chakra.form,b({ref:g,onSubmit:j(h,x)},S),E))}),ke=["children","disableIfUntouched","disableIfInvalid"],Ie=c.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,o=e.disableIfInvalid,i=_(e,ke),l=t.useFormContext().formState;/*#__PURE__*/return y.createElement(f.Button,b({type:"submit",isLoading:l.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!l.isDirty||o&&!l.isValid},i),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Re,Pe,Le=["schema","submitLabel"],Ve=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,o=_(e,Le);/*#__PURE__*/return y.createElement(Ne,b({},o,{schema:r,ref:t}),/*#__PURE__*/y.createElement(Y,null,/*#__PURE__*/y.createElement(Ae,{schema:r}),a&&/*#__PURE__*/y.createElement(Ie,{label:a})))}),Be="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ze(e){return"function"==typeof e}Re=function(e,t){var r="__lodash_hash_undefined__",n=9007199254740991,a="[object Arguments]",o="[object Function]",i="[object Object]",l=/^\[object .+?Constructor\]$/,u=/^(?:0|[1-9]\d*)$/,s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s[a]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s[o]=s["[object Map]"]=s["[object Number]"]=s[i]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1;var c="object"==typeof Be&&Be&&Be.Object===Object&&Be,p="object"==typeof self&&self&&self.Object===Object&&self,f=c||p||Function("return this")(),d=t&&!t.nodeType&&t,m=d&&e&&!e.nodeType&&e,v=m&&m.exports===d,h=v&&c.process,y=function(){try{return m&&m.require&&m.require("util").types||h&&h.binding&&h.binding("util")}catch(e){}}(),b=y&&y.isTypedArray;function _(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var x,g,E,S=Array.prototype,F=Object.prototype,C=f["__core-js_shared__"],j=Function.prototype.toString,w=F.hasOwnProperty,A=(x=/[^.]+$/.exec(C&&C.keys&&C.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"",O=F.toString,N=j.call(Object),k=RegExp("^"+j.call(w).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),I=v?f.Buffer:void 0,R=f.Symbol,P=f.Uint8Array,L=(g=Object.getPrototypeOf,E=Object,function(e){return g(E(e))}),V=Object.create,B=F.propertyIsEnumerable,z=S.splice,D=R?R.toStringTag:void 0,q=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),T=I?I.isBuffer:void 0,M=Math.max,U=Date.now,$=ie(f,"Map"),G=ie(Object,"create"),W=function(){function e(){}return function(t){if(!be(t))return{};if(V)return V(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();function H(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function J(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function K(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Q(e){var t=this.__data__=new J(e);this.size=t.size}function X(e,t,r){(void 0!==r&&!pe(e[t],r)||void 0===r&&!(t in e))&&ee(e,t,r)}function Y(e,t,r){var n=e[t];w.call(e,t)&&pe(n,r)&&(void 0!==r||t in e)||ee(e,t,r)}function Z(e,t){for(var r=e.length;r--;)if(pe(e[r][0],t))return r;return-1}function ee(e,t,r){"__proto__"==t&&q?q(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function te(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":D&&D in Object(e)?function(e){var t=w.call(e,D),r=e[D];try{e[D]=void 0;var n=!0}catch(e){}var a=O.call(e);return n&&(t?e[D]=r:delete e[D]),a}(e):function(e){return O.call(e)}(e)}function re(e){return _e(e)&&te(e)==a}function ne(e,t,r,n,a){e!==t&&function(e,t,r){for(var n=-1,a=Object(e),o=r(e),i=o.length;i--;){var l=o[++n];if(!1===t(a[l],l))break}}(t,function(o,l){if(a||(a=new Q),be(o))!function(e,t,r,n,a,o,l){var u=se(e,r),s=se(t,r),c=l.get(s);if(c)X(e,r,c);else{var p,f,d,m,v=o?o(u,s,r+"",e,t,l):void 0,h=void 0===v;if(h){var y=de(s),b=!y&&ve(s),_=!y&&!b&&xe(s);v=s,y||b||_?de(u)?v=u:_e(m=u)&&me(m)?v=function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}(u):b?(h=!1,v=s.slice()):_?(h=!1,d=new(f=(p=s).buffer).constructor(f.byteLength),new P(d).set(new P(f)),v=new p.constructor(d,p.byteOffset,p.length)):v=[]:function(e){if(!_e(e)||te(e)!=i)return!1;var t=L(e);if(null===t)return!0;var r=w.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&j.call(r)==N}(s)||fe(s)?(v=u,fe(u)?v=function(e){return function(e,t,r,n){var a=!r;r||(r={});for(var o=-1,i=t.length;++o<i;){var l=t[o],u=void 0;void 0===u&&(u=e[l]),a?ee(r,l,u):Y(r,l,u)}return r}(e,ge(e))}(u):be(u)&&!he(u)||(v=function(e){return"function"!=typeof e.constructor||ue(e)?{}:W(L(e))}(s))):h=!1}h&&(l.set(s,v),a(v,s,n,o,l),l.delete(s)),X(e,r,v)}}(e,t,l,r,ne,n,a);else{var u=n?n(se(e,l),o,l+"",e,t,a):void 0;void 0===u&&(u=o),X(e,l,u)}},ge)}H.prototype.clear=function(){this.__data__=G?G(null):{},this.size=0},H.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},H.prototype.get=function(e){var t=this.__data__;if(G){var n=t[e];return n===r?void 0:n}return w.call(t,e)?t[e]:void 0},H.prototype.has=function(e){var t=this.__data__;return G?void 0!==t[e]:w.call(t,e)},H.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=G&&void 0===t?r:t,this},J.prototype.clear=function(){this.__data__=[],this.size=0},J.prototype.delete=function(e){var t=this.__data__,r=Z(t,e);return!(r<0||(r==t.length-1?t.pop():z.call(t,r,1),--this.size,0))},J.prototype.get=function(e){var t=this.__data__,r=Z(t,e);return r<0?void 0:t[r][1]},J.prototype.has=function(e){return Z(this.__data__,e)>-1},J.prototype.set=function(e,t){var r=this.__data__,n=Z(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this},K.prototype.clear=function(){this.size=0,this.__data__={hash:new H,map:new($||J),string:new H}},K.prototype.delete=function(e){var t=oe(this,e).delete(e);return this.size-=t?1:0,t},K.prototype.get=function(e){return oe(this,e).get(e)},K.prototype.has=function(e){return oe(this,e).has(e)},K.prototype.set=function(e,t){var r=oe(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this},Q.prototype.clear=function(){this.__data__=new J,this.size=0},Q.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Q.prototype.get=function(e){return this.__data__.get(e)},Q.prototype.has=function(e){return this.__data__.has(e)},Q.prototype.set=function(e,t){var r=this.__data__;if(r instanceof J){var n=r.__data__;if(!$||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new K(n)}return r.set(e,t),this.size=r.size,this};var ae=q?function(e,t){return q(e,"toString",{configurable:!0,enumerable:!1,value:(r=t,function(){return r}),writable:!0});var r}:Fe;function oe(e,t){var r,n,a=e.__data__;return("string"==(n=typeof(r=t))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?a["string"==typeof t?"string":"hash"]:a.map}function ie(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){return!(!be(e)||function(e){return!!A&&A in e}(e))&&(he(e)?k:l).test(function(e){if(null!=e){try{return j.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}(r)?r:void 0}function le(e,t){var r=typeof e;return!!(t=null==t?n:t)&&("number"==r||"symbol"!=r&&u.test(e))&&e>-1&&e%1==0&&e<t}function ue(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||F)}function se(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var ce=function(e){var t=0,r=0;return function(){var n=U(),a=16-(n-r);if(r=n,a>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(ae);function pe(e,t){return e===t||e!=e&&t!=t}var fe=re(function(){return arguments}())?re:function(e){return _e(e)&&w.call(e,"callee")&&!B.call(e,"callee")},de=Array.isArray;function me(e){return null!=e&&ye(e.length)&&!he(e)}var ve=T||function(){return!1};function he(e){if(!be(e))return!1;var t=te(e);return t==o||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function ye(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=n}function be(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function _e(e){return null!=e&&"object"==typeof e}var xe=b?function(e){return function(t){return e(t)}}(b):function(e){return _e(e)&&ye(e.length)&&!!s[te(e)]};function ge(e){return me(e)?function(e,t){var r=de(e),n=!r&&fe(e),a=!r&&!n&&ve(e),o=!r&&!n&&!a&&xe(e),i=r||n||a||o,l=i?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],u=l.length;for(var s in e)i&&("length"==s||a&&("offset"==s||"parent"==s)||o&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||le(s,u))||l.push(s);return l}(e):function(e){if(!be(e))return function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t}(e);var t=ue(e),r=[];for(var n in e)("constructor"!=n||!t&&w.call(e,n))&&r.push(n);return r}(e)}var Ee,Se=(Ee=function(e,t,r,n){ne(e,t,r,n)},function(e,t){return ce(function(e,t,r){return t=M(void 0===t?e.length-1:t,0),function(){for(var n=arguments,a=-1,o=M(n.length-t,0),i=Array(o);++a<o;)i[a]=n[t+a];a=-1;for(var l=Array(t+1);++a<t;)l[a]=n[a];return l[t]=r(i),_(e,this,l)}}(e,void 0,Fe),e+"")}(function(e,t){var r=-1,n=t.length,a=n>1?t[n-1]:void 0,o=n>2?t[2]:void 0;for(a=Ee.length>3&&"function"==typeof a?(n--,a):void 0,o&&function(e,t,r){if(!be(r))return!1;var n=typeof t;return!!("number"==n?me(r)&&le(t,r.length):"string"==n&&t in r)&&pe(r[t],e)}(t[0],t[1],o)&&(a=n<3?void 0:a,n=1),e=Object(e);++r<n;){var i=t[r];i&&Ee(e,i,r,a)}return e}));function Fe(e){return e}e.exports=Se},Re(Pe={exports:{}},Pe.exports);var De="production"!==process.env.NODE_ENV;process;var qe=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function Te(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){t.some(function(t){return null==t||t(e),null==e?void 0:e.defaultPrevented})}}Object.freeze(["base","sm","md","lg","xl","2xl"]);var Me="production"!==process.env.NODE_ENV;process;var Ue=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function $e(){return $e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},$e.apply(this,arguments)}function Ge(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}Object.freeze(["base","sm","md","lg","xl","2xl"]);var We=d.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),He=We[0],Je=We[1];function Ke(e){var t=e.step,r=y.useState(-1),n=r[0],a=r[1],o=y.useRef([]),i=y.useState(Date.now())[1],l=y.useCallback(function(e){var t=[].concat(o.current);-1===t.indexOf(e)&&t.push(e),o.current=t,i(Date.now())},[o,i]),u=function(e){var t=o.current.indexOf(e);-1!==t&&a(t)};return y.useLayoutEffect(function(){"string"==typeof t?u(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:o,activeStep:o.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===o.current.length-1,isCompleted:n>=o.current.length,setIndex:a,setStep:u,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:l,unregisterStep:function(e){o.current=o.current.slice(o.current.indexOf(e),1)}}}function Qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Je(),o=a.registerStep,i=a.unregisterStep,l=a.activeStep;return y.useEffect(function(){if(t)return o(t),function(){i(t)}},[]),{isActive:t?l===t:r,isCompleted:n}}var Xe=["children","orientation"],Ye=["children","orientation","stepComponent"],Ze=["children","isOpen"],et=["icon","isActive","isCompleted","className"],tt=["title","icon","isActive","isCompleted"],rt=["isActive"],nt=c.forwardRef(function(e,t){var r=c.useMultiStyleConfig("Stepper",e),n=c.omitThemingProps(e),a=n.children,o=n.orientation,i=Ge(n,Xe),l=Ke(e),u=$e({display:"flex",flexDirection:"column"},r.container);return y.createElement(c.StylesProvider,{value:r},/*#__PURE__*/y.createElement(He,{value:l},/*#__PURE__*/y.createElement(c.chakra.div,$e({ref:t,__css:u},i,{className:Ue("saas-stepper__container",e.className)}),/*#__PURE__*/y.createElement(at,{orientation:o},a))))});Me&&(nt.displayName="Stepper");var at=function(e){var t,r,n=e.children,a=e.orientation,o=e.stepComponent,i=Ge(e,Ye),l=c.useStyles(),u=Je().activeIndex,s=$e({display:"flex",flexDirection:"row",alignItems:"center"},l.steps),p="vertical"===a,f=o||lt,d=m.getChildrenOfType(n,f),v=d.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/y.createElement(f,$e({key:r},t.props,{icon:t.props.icon||r+1,isActive:u===r,isCompleted:t.props.isCompleted||u>r}))),"vertical"===a&&e.push(/*#__PURE__*/y.createElement(ot,{isOpen:u===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/y.createElement(ut,{key:"separator-"+r,isActive:r<u})),e},[]),h=m.getChildOfType(n,ct),b=u>=d.length?h:p?null:null==(t=d[u])||null==(r=t.props)?void 0:r.children;return y.createElement(y.Fragment,null,/*#__PURE__*/y.createElement(c.chakra.div,$e({__css:s},i,{className:Ue("saas-stepper__steps",e.className)}),v),b&&/*#__PURE__*/y.createElement(ot,null,b))};Me&&(at.displayName="StepperSteps");var ot=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,o=Ge(e,Ze),i=c.useStyles();return y.createElement(c.chakra.div,$e({__css:i.content},o,{className:Ue("saas-stepper__content",e.className)}),/*#__PURE__*/y.createElement(r.Collapse,{in:a},t))};Me&&(ot.displayName="StepperContent");var it=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,o=Ge(e,et),i=$e({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},c.useStyles().icon);return t=n?/*#__PURE__*/y.createElement(p.Icon,{as:p.CheckIcon}):r,/*#__PURE__*/y.createElement(c.chakra.div,$e({__css:i},o,{className:Ue("saas-stepper__icon",a)}),t)};Me&&(it.displayName="StepperIcon");var lt=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,o=Ge(e,tt),i=Qe(e),l=$e({display:"flex",alignItems:"center",flexDirection:"row"},c.useStyles().step);return y.createElement(c.chakra.div,$e({__css:l,"data-active":i.isActive,"data-completed":i.isCompleted},o,{className:Ue("saas-stepper__step",e.className)}),/*#__PURE__*/y.createElement(it,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/y.createElement(st,null,t))};Me&&(lt.displayName="StepperStep");var ut=function(e){var t=e.isActive,r=Ge(e,rt),n=$e({flex:1,borderTopWidth:"1px",mx:2},c.useStyles().separator);return y.createElement(c.chakra.div,$e({"data-active":t},r,{className:Ue("saas-stepper__separator",e.className),__css:n}))};Me&&(ut.displayName="StepperSeparator");var st=function(e){var t=c.useStyles();return y.createElement(c.chakra.p,$e({},e,{__css:t.title,className:Ue("saas-stepper__title",e.className)}))};Me&&(st.displayName="StepperStepTitle");var ct=function(e){var t=c.useStyles();return y.createElement(c.chakra.div,$e({__css:t.completed},e,{className:Ue("saas-stepper__completed",e.className)}))};Me&&(ct.displayName="StepperCompleted");var pt=d.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),ft=pt[0],dt=pt[1];function mt(e){var t=Ke(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,o=y.useState({}),i=o[0],l=o[1],u=y.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(b({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),s=y.useCallback(function(e){var t=i[r];return{onSubmit:u,schema:null==t?void 0:t.schema}},[i,u,r]),c=y.useCallback(function(e){l(function(t){var r;return b({},t,((r={})[e.name]=e,r))})},[i]);return b({getFormProps:s,updateStep:c,steps:i},t)}function vt(e){var t=e.name,r=e.schema,n=Qe({name:t}),a=dt(),o=a.steps,i=a.updateStep;return y.useEffect(function(){i({name:t,schema:r})},[t,r]),b({},n,o[t]||{})}var ht=["children","onSubmit"],yt=["getFormProps"],bt=["name","schema","children","className"],_t=["label","submitLabel"],xt=y.forwardRef(function(e,t){var r=e.children,n=_(e,ht),a=mt(e),o=a.getFormProps,i=_(a,yt),l=y.useMemo(function(){return i},[i]);/*#__PURE__*/return y.createElement(He,{value:l},/*#__PURE__*/y.createElement(ft,{value:l},/*#__PURE__*/y.createElement(Ne,b({ref:t},n,o(e)),function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return ze(e)?e.apply(void 0,r):e}(r,a))))}),gt=function(e){var t=e.name,r=e.schema,n=e.children,a=e.className,o=_(e,bt);return vt({name:t,schema:r}).isActive?/*#__PURE__*/y.createElement(c.chakra.div,b({},o,{className:qe("saas-form__step",a)}),n):null};De&&(gt.displayName="FormStep");var Et=function(e){var t=Je(),r=t.prevStep;/*#__PURE__*/return y.createElement(f.Button,b({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:qe("saas-form__prev-button",e.className),onClick:Te(e.onClick,r)}))};De&&(Et.displayName="PrevButton");var St=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,o=_(e,_t),i=Je(),l=i.isCompleted;/*#__PURE__*/return y.createElement(Ie,b({isDisabled:l,label:i.isLastStep||l?a:r},o,{className:qe("saas-form__next-button",e.className)}))};De&&(St.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=xe,exports.ArrayFieldProvider=te,exports.ArrayFieldRemoveButton=he,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=ve,exports.ArrayFieldRowFields=me,exports.ArrayFieldRowProvider=ae,exports.ArrayFieldRows=_e,exports.AutoForm=Ve,exports.BaseField=I,exports.CheckboxField=U,exports.DisplayField=function(e){var t=e.name,n=e.label,a=_(e,g);/*#__PURE__*/return y.createElement(r.FormControl,a,n?/*#__PURE__*/y.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/y.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/y.createElement(E,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=R,exports.Fields=Ae,exports.Form=Ne,exports.FormLayout=Y,exports.FormLegend=Ee,exports.FormStep=gt,exports.FormStepper=function(e){var t=c.useMultiStyleConfig("Stepper",e),r=y.Children.map(e.children,function(e){if(y.isValidElement(e)&&(null==e?void 0:e.type)===gt){var t=vt(e.props);/*#__PURE__*/return y.createElement(lt,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return y.createElement(c.StylesProvider,{value:t},/*#__PURE__*/y.createElement(at,b({mb:"4"},e),r))},exports.FormValue=E,exports.InputField=B,exports.NativeSelectField=W,exports.NextButton=St,exports.NumberInputField=z,exports.ObjectField=Se,exports.PasswordInputFIeld=D,exports.PinField=G,exports.PrevButton=Et,exports.RadioField=$,exports.SelectField=M,exports.StepForm=xt,exports.StepFormProvider=ft,exports.SubmitButton=Ie,exports.SwitchField=T,exports.TextareaField=q,exports.registerFieldType=V,exports.useArrayField=ie,exports.useArrayFieldAddButton=se,exports.useArrayFieldContext=re,exports.useArrayFieldRemoveButton=ue,exports.useArrayFieldRow=le,exports.useArrayFieldRowContext=oe,exports.useFormStep=vt,exports.useStepForm=mt,exports.useStepFormContext=dt,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(v).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return v[e]}})});
|
1
|
+
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("@chakra-ui/system"),u=require("@chakra-ui/icons"),c=require("@saas-ui/button"),m=require("@chakra-ui/react-utils"),d=require("@chakra-ui/utils"),p=require("@saas-ui/react-utils"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var h=/*#__PURE__*/v(e);function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var b=["name","label","placeholder"],y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},F=["name","label","help","variant","hideLabel","children"],S=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],C=["ref"],g=["name","rules"],N=["ref"],k=["label"],R=["label"],w={},I=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=E(e,F),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return h.createElement(r.FormControl,x({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},A=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return h.createElement(w[void 0===r?"text":r]||w.text,x({ref:t},e))}),V=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,_),s=t.useFormContext();/*#__PURE__*/return h.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=E(n,C);/*#__PURE__*/return h.createElement(e,x({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},O=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,g),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=E(s,N);/*#__PURE__*/return h.createElement(e,x({},c,o,{ref:r.useMergeRefs(a,u)}))})},D=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=E(t,S),v=x({required:m},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/h.createElement(e,x({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?V(t):O(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return w[e]=a,a},P=D("text",r.Input),L=D("number",n.NumberInput,{isControlled:!0}),j=D("password",a.PasswordInput),q=D("textarea",r.Textarea),B=D("switch",r.forwardRef(function(e,t){var n=e.label,a=E(e,k);/*#__PURE__*/return h.createElement(r.Switch,x({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=D("select",o.Select,{isControlled:!0}),T=D("checkbox",r.forwardRef(function(e,t){var n=e.label,a=E(e,R);/*#__PURE__*/return h.createElement(r.Checkbox,x({ref:t},a),n)}),{hideLabel:!0}),U=D("radio",l.RadioInput,{isControlled:!0}),H=D("pin",i.PinInput,{isControlled:!0}),G=D("native-select",o.NativeSelect,{isControlled:!0}),z=["children"],W=function(e){/*#__PURE__*/return h.createElement(r.chakra.div,null,e.children)},J=function(e){var t,n,a,l=e.children,i=E(e,z),o=x({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return h.createElement(r.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(W,null,e):e}))},K=function(e,t){return h.Children.map(t,function(t){return h.isValidElement(t)&&t.props.name?h.cloneElement(t,x({},t.props,{name:e+"."+t.props.name})):t})},Q=m.createContext({name:"ArrayFieldContext"}),X=Q[0],Y=Q[1],Z=m.createContext({name:"ArrayFieldRowContext"}),$=Z[0],ee=Z[1],te=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return x({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},re=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=Y(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:h.useCallback(function(){n(l),i(r)},[r])}},ne=function(){var e=ee(),t=e.isFirst,r=e.remove,n=Y(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},ae=function(){var e=Y(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},le=["children","columns","spacing"],ie=["children"],oe=["name","defaultValue","keyName","min","max","children"],se=function(e){/*#__PURE__*/return h.createElement(ce,{index:e.index},/*#__PURE__*/h.createElement(ue,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(me,null))},ue=function(e){var t=e.children,r=e.columns,n=e.spacing,a=E(e,le),l=ee().name;/*#__PURE__*/return h.createElement(J,x({flex:"1",columns:r,gridGap:n,mr:"2"},a),K(l,t))},ce=function(e){var t=e.children,r=re({index:e.index});/*#__PURE__*/return h.createElement($,{value:r},/*#__PURE__*/h.createElement(s.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},me=function(e){/*#__PURE__*/return h.createElement(c.IconButton,x({icon:/*#__PURE__*/h.createElement(u.MinusIcon,null),"aria-label":"Remove row"},ne(),e))},de=function(e){/*#__PURE__*/return h.createElement(c.IconButton,x({icon:/*#__PURE__*/h.createElement(u.AddIcon,null),"aria-label":"Add row",float:"right"},ae(),e))},pe=h.forwardRef(function(e,t){var r=e.children,n=E(e,ie);/*#__PURE__*/return h.createElement(ve,x({ref:t},n),/*#__PURE__*/h.createElement(fe,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(se,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(de,null))}),fe=function(e){return(0,e.children)(Y().fields)},ve=h.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=E(e,oe),u=te({name:r,defaultValue:n,keyName:a,min:l,max:i});return h.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/h.createElement(X,{value:u},/*#__PURE__*/h.createElement(I,x({name:r},s),o))}),he=["name","label","hideLabel","children","columns","spacing"],xe=function(e){var t=r.useStyles();/*#__PURE__*/return h.createElement(r.FormLabel,x({as:"legend",sx:t.legend},e))},Ee=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=E(e,he);/*#__PURE__*/return h.createElement(r.FormControl,x({name:t,as:"fieldset"},s),/*#__PURE__*/h.createElement(xe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(J,{columns:i,gridGap:o},K(t,l)))},be=function(e){return Object.entries(e).map(function(e){return x({name:e[0]},e[1])})},ye=function(e){return{getFields:function(){return be(e)},getNestedFields:function(t){var r,n=d.get(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?be(n.items.properties):"object"===n.type?be(n.properties):[n.items]:[]}}},Fe=["name","type"],Se=["schema","fieldResolver"],_e=["name","type","defaultValue"],Ce=function(e,t){var r;return null==(r=e.getNestedFields(t))?void 0:r.map(function(e,t){var r=e.name,n=e.type,a=E(e,Fe);/*#__PURE__*/return h.createElement(A,x({key:r||t,name:r,type:n},a))})},ge=function(e){var t=e.schema,r=e.fieldResolver,n=E(e,Se),a=h.useMemo(function(){return r||ye(t)},[t,r]);/*#__PURE__*/return h.createElement(J,n,a.getFields().map(function(e){var t=e.name,r=e.type,n=E(e,_e);return"array"===r?/*#__PURE__*/h.createElement(pe,x({key:t,name:t},n),Ce(a,t)):"object"===r?/*#__PURE__*/h.createElement(Ee,x({key:t,name:t},n),Ce(a,t)):/*#__PURE__*/h.createElement(A,x({key:t,name:t,type:r},n))}))},Ne=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],ke=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,u=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,d=e.delayError,p=e.defaultValues,f=e.onSubmit,v=e.onError,b=e.formRef,y=e.children,F=E(e,Ne),S=t.useForm({mode:l,resolver:i,defaultValues:p,reValidateMode:o,shouldFocusError:s,shouldUnregister:u,shouldUseNativeValidation:c,criteriaMode:m,delayError:d}),_=S.handleSubmit;return h.useImperativeHandle(n,function(){return S},[n,S]),/*#__PURE__*/h.createElement(t.FormProvider,S,/*#__PURE__*/h.createElement(r.chakra.form,x({ref:b,onSubmit:_(f,v)},F),y))}),Re=["children","disableIfUntouched","disableIfInvalid"],we=s.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=E(e,Re),o=t.useFormContext().formState;/*#__PURE__*/return h.createElement(c.Button,x({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});we.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ie=["schema","submitLabel","fieldResolver"],Ae=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=E(e,Ie);/*#__PURE__*/return h.createElement(ke,x({},i,{ref:t}),/*#__PURE__*/h.createElement(J,null,/*#__PURE__*/h.createElement(ge,{schema:r,fieldResolver:l}),a&&/*#__PURE__*/h.createElement(we,{label:a})))});function Ve(){return Ve=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(this,arguments)}function Oe(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var De=m.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Pe=De[0],Le=De[1];function je(e){var t=e.step,r=h.useState(-1),n=r[0],a=r[1],l=h.useRef([]),i=h.useState(Date.now())[1],o=h.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return h.useLayoutEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Le(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return h.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var Be=["children","orientation"],Me=["children","orientation","stepComponent"],Te=["children","isOpen"],Ue=["icon","isActive","isCompleted","className"],He=["title","icon","isActive","isCompleted"],Ge=["isActive"],ze=s.forwardRef(function(e,t){var r=s.useMultiStyleConfig("Stepper",e),n=s.omitThemingProps(e),a=n.children,l=n.orientation,i=Oe(n,Be),o=je(e),u=Ve({display:"flex",flexDirection:"column"},r.container);return h.createElement(s.StylesProvider,{value:r},/*#__PURE__*/h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(s.chakra.div,Ve({ref:t,__css:u},i,{className:d.cx("saas-stepper__container",e.className)}),/*#__PURE__*/h.createElement(We,{orientation:l},a))))});d.__DEV__&&(ze.displayName="Stepper");var We=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=Oe(e,Me),o=s.useStyles(),u=Le().activeIndex,c=Ve({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),m="vertical"===a,f=l||Qe,v=p.getChildrenOfType(n,f),x=v.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/h.createElement(f,Ve({key:r},t.props,{icon:t.props.icon||r+1,isActive:u===r,isCompleted:t.props.isCompleted||u>r}))),"vertical"===a&&e.push(/*#__PURE__*/h.createElement(Je,{key:"content-"+r,isOpen:u===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/h.createElement(Xe,{key:"separator-"+r,isActive:r<u})),e},[]),E=p.getChildOfType(n,Ze),b=u>=v.length?E:m?null:/*#__PURE__*/h.createElement(Je,null,null==(t=v[u])||null==(r=t.props)?void 0:r.children);return h.createElement(h.Fragment,null,/*#__PURE__*/h.createElement(s.chakra.div,Ve({__css:c},i,{className:d.cx("saas-stepper__steps",e.className)}),x),b)};d.__DEV__&&(We.displayName="StepperSteps");var Je=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=Oe(e,Te),i=s.useStyles();return h.createElement(s.chakra.div,Ve({__css:i.content},l,{className:d.cx("saas-stepper__content",e.className)}),/*#__PURE__*/h.createElement(r.Collapse,{in:a},t))};d.__DEV__&&(Je.displayName="StepperContent");var Ke=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=Oe(e,Ue),i=Ve({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},s.useStyles().icon);return t=n?/*#__PURE__*/h.createElement(u.Icon,{as:u.CheckIcon}):r,/*#__PURE__*/h.createElement(s.chakra.div,Ve({__css:i},l,{className:d.cx("saas-stepper__icon",a)}),t)};d.__DEV__&&(Ke.displayName="StepperIcon");var Qe=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=Oe(e,He),i=qe(e),o=Ve({display:"flex",alignItems:"center",flexDirection:"row"},s.useStyles().step);return h.createElement(s.chakra.div,Ve({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:d.cx("saas-stepper__step",e.className)}),/*#__PURE__*/h.createElement(Ke,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/h.createElement(Ye,null,t))};d.__DEV__&&(Qe.displayName="StepperStep");var Xe=function(e){var t=e.isActive,r=Oe(e,Ge),n=Ve({flex:1,borderTopWidth:"1px",mx:2},s.useStyles().separator);return h.createElement(s.chakra.div,Ve({"data-active":t},r,{className:d.cx("saas-stepper__separator",e.className),__css:n}))};d.__DEV__&&(Xe.displayName="StepperSeparator");var Ye=function(e){var t=s.useStyles();return h.createElement(s.chakra.p,Ve({},e,{__css:t.title,className:d.cx("saas-stepper__title",e.className)}))};d.__DEV__&&(Ye.displayName="StepperStepTitle");var Ze=function(e){var t=s.useStyles();return h.createElement(s.chakra.div,Ve({__css:t.completed},e,{className:d.cx("saas-stepper__completed",e.className)}))};d.__DEV__&&(Ze.displayName="StepperCompleted");var $e=m.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),et=$e[0],tt=$e[1];function rt(e){var t=je(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=h.useState({}),i=l[0],o=l[1],s=h.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(x({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=h.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[i,s,r]),c=h.useCallback(function(e){o(function(t){var r;return x({},t,((r={})[e.name]=e,r))})},[i]);return x({getFormProps:u,updateStep:c,steps:i},t)}function nt(e){var t=e.name,r=e.schema,n=e.resolver,a=qe({name:t}),l=tt(),i=l.steps,o=l.updateStep;return h.useEffect(function(){o({name:t,schema:r,resolver:n})},[t,r]),x({},a,i[t]||{name:t,schema:r})}var at=["children","onSubmit"],lt=["getFormProps"],it=["name","schema","resolver","children","className"],ot=["label","submitLabel"],st=h.forwardRef(function(e,t){var r=e.children,n=E(e,at),a=rt(e),l=a.getFormProps,i=E(a,lt),o=h.useMemo(function(){return i},[i]);/*#__PURE__*/return h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(et,{value:o},/*#__PURE__*/h.createElement(ke,x({ref:t},n,l(e)),d.runIfFn(r,a))))}),ut=function(e){var t=e.name,r=e.schema,n=e.resolver,a=e.children,l=e.className,i=E(e,it);return nt({name:t,schema:r,resolver:n}).isActive?/*#__PURE__*/h.createElement(s.chakra.div,x({},i,{className:d.cx("saas-form__step",l)}),a):null};d.__DEV__&&(ut.displayName="FormStep");var ct=function(e){var t=Le(),r=t.prevStep;/*#__PURE__*/return h.createElement(c.Button,x({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:d.cx("saas-form__prev-button",e.className),onClick:d.callAllHandlers(e.onClick,r)}))};d.__DEV__&&(ct.displayName="PrevButton");var mt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=E(e,ot),i=Le(),o=i.isCompleted;/*#__PURE__*/return h.createElement(we,x({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:d.cx("saas-form__next-button",e.className)}))};d.__DEV__&&(mt.displayName="NextButton"),exports.ArrayField=pe,exports.ArrayFieldAddButton=de,exports.ArrayFieldContainer=ve,exports.ArrayFieldProvider=X,exports.ArrayFieldRemoveButton=me,exports.ArrayFieldRow=se,exports.ArrayFieldRowContainer=ce,exports.ArrayFieldRowFields=ue,exports.ArrayFieldRowProvider=$,exports.ArrayFieldRows=fe,exports.AutoForm=Ae,exports.BaseField=I,exports.CheckboxField=T,exports.DisplayField=function(e){var t=e.name,n=e.label,a=E(e,b);/*#__PURE__*/return h.createElement(r.FormControl,a,n?/*#__PURE__*/h.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/h.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/h.createElement(y,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=A,exports.Fields=ge,exports.Form=ke,exports.FormLayout=J,exports.FormLegend=xe,exports.FormStep=ut,exports.FormStepper=function(e){var t=s.useMultiStyleConfig("Stepper",e),r=h.Children.map(e.children,function(e){if(h.isValidElement(e)&&(null==e?void 0:e.type)===ut){var t=nt(e.props);/*#__PURE__*/return h.createElement(Qe,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return h.createElement(s.StylesProvider,{value:t},/*#__PURE__*/h.createElement(We,x({mb:"4"},e),r))},exports.FormValue=y,exports.InputField=P,exports.NativeSelectField=G,exports.NextButton=mt,exports.NumberInputField=L,exports.ObjectField=Ee,exports.PasswordInputFIeld=j,exports.PinField=H,exports.PrevButton=ct,exports.RadioField=U,exports.SelectField=M,exports.StepForm=st,exports.StepFormProvider=et,exports.SubmitButton=we,exports.SwitchField=B,exports.TextareaField=q,exports.defaultFieldResolver=ye,exports.registerFieldType=D,exports.useArrayField=te,exports.useArrayFieldAddButton=ae,exports.useArrayFieldContext=Y,exports.useArrayFieldRemoveButton=ne,exports.useArrayFieldRow=re,exports.useArrayFieldRowContext=ee,exports.useFormStep=nt,exports.useStepForm=rt,exports.useStepFormContext=tt,exports.withControlledInput=V,exports.withUncontrolledInput=O,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
2
2
|
//# sourceMappingURL=index.js.map
|