@saas-ui/forms 1.5.3 → 2.0.0-next.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -2
- package/dist/ajv/index.d.ts +21 -2
- package/dist/ajv/index.js +31 -2
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +25 -0
- package/dist/ajv/index.mjs.map +1 -0
- package/dist/index.d.ts +606 -18
- package/dist/index.js +1251 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1140 -0
- package/dist/index.mjs.map +1 -0
- package/dist/yup/index.d.ts +41 -2
- package/dist/yup/index.js +95 -2
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +86 -0
- package/dist/yup/index.mjs.map +1 -0
- package/dist/zod/index.d.ts +38 -2
- package/dist/zod/index.js +95 -2
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +85 -0
- package/dist/zod/index.mjs.map +1 -0
- package/package.json +18 -28
- package/src/array-field.tsx +20 -13
- package/src/auto-form.tsx +13 -19
- package/src/field-resolver.ts +1 -1
- package/src/field.tsx +4 -9
- package/src/fields.tsx +1 -3
- package/src/form.tsx +69 -25
- package/src/index.ts +3 -0
- package/src/input-right-button/index.ts +1 -0
- package/src/input-right-button/input-right-button.stories.tsx +47 -0
- package/src/input-right-button/input-right-button.test.tsx +12 -0
- package/src/input-right-button/input-right-button.tsx +26 -0
- package/src/layout.tsx +1 -1
- package/src/number-input/index.ts +1 -0
- package/src/number-input/number-input.stories.tsx +39 -0
- package/src/number-input/number-input.test.tsx +6 -0
- package/src/number-input/number-input.tsx +56 -0
- package/src/object-field.tsx +1 -1
- package/src/password-input/index.ts +1 -0
- package/src/password-input/password-input.stories.tsx +50 -0
- package/src/password-input/password-input.test.tsx +20 -0
- package/src/password-input/password-input.tsx +69 -0
- package/src/pin-input/index.ts +1 -0
- package/src/pin-input/pin-input.stories.tsx +38 -0
- package/src/pin-input/pin-input.test.tsx +6 -0
- package/src/pin-input/pin-input.tsx +50 -0
- package/src/radio/index.ts +1 -0
- package/src/radio/radio-input.stories.tsx +45 -0
- package/src/radio/radio-input.tsx +58 -0
- package/src/radio/radio.test.tsx +6 -0
- package/src/select/index.ts +2 -0
- package/src/select/native-select.tsx +42 -0
- package/src/select/select.stories.tsx +144 -0
- package/src/select/select.test.tsx +8 -0
- package/src/select/select.tsx +185 -0
- package/src/step-form.tsx +24 -13
- package/src/submit-button.tsx +32 -38
- package/src/use-step-form.tsx +1 -1
- package/ajv/package.json +0 -28
- package/dist/ajv/ajv-resolver.d.ts +0 -11
- package/dist/ajv/ajv-resolver.d.ts.map +0 -1
- package/dist/ajv/index.d.ts.map +0 -1
- package/dist/ajv/index.modern.mjs +0 -2
- package/dist/ajv/index.modern.mjs.map +0 -1
- package/dist/array-field.d.ts +0 -64
- package/dist/array-field.d.ts.map +0 -1
- package/dist/auto-form.d.ts +0 -32
- package/dist/auto-form.d.ts.map +0 -1
- package/dist/display-field.d.ts +0 -10
- package/dist/display-field.d.ts.map +0 -1
- package/dist/display-if.d.ts +0 -15
- package/dist/display-if.d.ts.map +0 -1
- package/dist/field-resolver.d.ts +0 -13
- package/dist/field-resolver.d.ts.map +0 -1
- package/dist/field.d.ts +0 -147
- package/dist/field.d.ts.map +0 -1
- package/dist/fields.d.ts +0 -9
- package/dist/fields.d.ts.map +0 -1
- package/dist/form.d.ts +0 -44
- package/dist/form.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/layout.d.ts +0 -14
- package/dist/layout.d.ts.map +0 -1
- package/dist/object-field.d.ts +0 -12
- package/dist/object-field.d.ts.map +0 -1
- package/dist/step-form.d.ts +0 -38
- package/dist/step-form.d.ts.map +0 -1
- package/dist/submit-button.d.ts +0 -20
- package/dist/submit-button.d.ts.map +0 -1
- package/dist/use-array-field.d.ts +0 -95
- package/dist/use-array-field.d.ts.map +0 -1
- package/dist/use-step-form.d.ts +0 -40
- package/dist/use-step-form.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/watch-field.d.ts +0 -11
- package/dist/watch-field.d.ts.map +0 -1
- package/dist/yup/index.d.ts.map +0 -1
- package/dist/yup/index.modern.mjs +0 -2
- package/dist/yup/index.modern.mjs.map +0 -1
- package/dist/yup/yup-resolver.d.ts +0 -29
- package/dist/yup/yup-resolver.d.ts.map +0 -1
- package/dist/zod/index.d.ts.map +0 -1
- package/dist/zod/index.modern.mjs +0 -2
- package/dist/zod/index.modern.mjs.map +0 -1
- package/dist/zod/zod-resolver.d.ts +0 -35
- package/dist/zod/zod-resolver.d.ts.map +0 -1
- package/yup/package.json +0 -26
- package/zod/package.json +0 -27
@@ -1,95 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
import { UseFieldArrayReturn } from 'react-hook-form';
|
3
|
-
export interface UseArrayFieldReturn extends UseFieldArrayReturn {
|
4
|
-
/**
|
5
|
-
* The array field name
|
6
|
-
*/
|
7
|
-
name: string;
|
8
|
-
/**
|
9
|
-
* The default value for new items
|
10
|
-
*/
|
11
|
-
defaultValue: Record<string, any>;
|
12
|
-
/**
|
13
|
-
* Min amount of items
|
14
|
-
*/
|
15
|
-
min?: number;
|
16
|
-
/**
|
17
|
-
* Max amount of items
|
18
|
-
*/
|
19
|
-
max?: number;
|
20
|
-
}
|
21
|
-
export declare const ArrayFieldProvider: React.Provider<UseArrayFieldReturn>, useArrayFieldContext: () => UseArrayFieldReturn;
|
22
|
-
export interface UseArrayFieldRowReturn {
|
23
|
-
/**
|
24
|
-
* Name of the array field including the index, eg 'field.0'
|
25
|
-
*/
|
26
|
-
name: string;
|
27
|
-
/**
|
28
|
-
* The field index
|
29
|
-
*/
|
30
|
-
index: number;
|
31
|
-
/**
|
32
|
-
* Remove this array item
|
33
|
-
*/
|
34
|
-
remove: () => void;
|
35
|
-
/**
|
36
|
-
* True if this is the first item
|
37
|
-
*/
|
38
|
-
isFirst: boolean;
|
39
|
-
/**
|
40
|
-
* True if this is the last item
|
41
|
-
*/
|
42
|
-
isLast: boolean;
|
43
|
-
}
|
44
|
-
export declare const ArrayFieldRowProvider: React.Provider<UseArrayFieldRowReturn>, useArrayFieldRowContext: () => UseArrayFieldRowReturn;
|
45
|
-
export interface ArrayFieldOptions {
|
46
|
-
/**
|
47
|
-
* The field name
|
48
|
-
*/
|
49
|
-
name: string;
|
50
|
-
/**
|
51
|
-
* Default value for new values in the array
|
52
|
-
*/
|
53
|
-
defaultValue?: Record<string, any>;
|
54
|
-
/**
|
55
|
-
* Default key name for rows, change this if your data uses a different 'id' field
|
56
|
-
* @default "id"
|
57
|
-
*/
|
58
|
-
keyName?: string;
|
59
|
-
min?: number;
|
60
|
-
max?: number;
|
61
|
-
}
|
62
|
-
export declare const useArrayField: ({ name, defaultValue, keyName, min, max, }: ArrayFieldOptions) => {
|
63
|
-
name: string;
|
64
|
-
defaultValue: Record<string, any>;
|
65
|
-
min: number | undefined;
|
66
|
-
max: number | undefined;
|
67
|
-
swap: import("react-hook-form").UseFieldArraySwap;
|
68
|
-
move: import("react-hook-form").UseFieldArrayMove;
|
69
|
-
prepend: import("react-hook-form").UseFieldArrayPrepend<import("react-hook-form").FieldValues, string>;
|
70
|
-
append: import("react-hook-form").UseFieldArrayAppend<import("react-hook-form").FieldValues, string>;
|
71
|
-
remove: import("react-hook-form").UseFieldArrayRemove;
|
72
|
-
insert: import("react-hook-form").UseFieldArrayInsert<import("react-hook-form").FieldValues, string>;
|
73
|
-
update: import("react-hook-form").UseFieldArrayUpdate<import("react-hook-form").FieldValues, string>;
|
74
|
-
replace: import("react-hook-form").UseFieldArrayReplace<import("react-hook-form").FieldValues, string>;
|
75
|
-
fields: Record<string, string>[];
|
76
|
-
};
|
77
|
-
export interface UseArrayFieldRowProps {
|
78
|
-
index: number;
|
79
|
-
}
|
80
|
-
export declare const useArrayFieldRow: ({ index }: UseArrayFieldRowProps) => {
|
81
|
-
index: number;
|
82
|
-
isFirst: boolean;
|
83
|
-
isLast: boolean;
|
84
|
-
name: string;
|
85
|
-
remove: () => void;
|
86
|
-
};
|
87
|
-
export declare const useArrayFieldRemoveButton: () => {
|
88
|
-
onClick: () => void;
|
89
|
-
isDisabled: boolean;
|
90
|
-
};
|
91
|
-
export declare const useArrayFieldAddButton: () => {
|
92
|
-
onClick: () => void;
|
93
|
-
isDisabled: boolean;
|
94
|
-
};
|
95
|
-
//# sourceMappingURL=use-array-field.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"use-array-field.d.ts","sourceRoot":"","sources":["../src/use-array-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAGL,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AAIxB,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACjC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAO,kBAAkB,uCAAE,oBAAoB,2BAGlD,CAAA;AAEJ,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,eAAO,MAAO,qBAAqB,0CAAE,uBAAuB,8BAGxD,CAAA;AAEJ,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,aAAa,+CAMvB,iBAAiB;;;;;;;;;;;;;;CAenB,CAAA;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,gBAAgB,cAAe,qBAAqB;;;;;;CAmBhE,CAAA;AAED,eAAO,MAAM,yBAAyB;;;CAUrC,CAAA;AAED,eAAO,MAAM,sBAAsB;;;CAYlC,CAAA"}
|
package/dist/use-step-form.d.ts
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
import { FieldValues, SubmitHandler } from 'react-hook-form';
|
3
|
-
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
4
|
-
import { UseStepperProps, UseStepperReturn } from '@saas-ui/stepper';
|
5
|
-
export interface StepState {
|
6
|
-
name: string;
|
7
|
-
schema?: any;
|
8
|
-
resolver?: any;
|
9
|
-
isActive?: boolean;
|
10
|
-
isCompleted?: boolean;
|
11
|
-
onSubmit?: FormStepSubmitHandler;
|
12
|
-
}
|
13
|
-
export type FormStepSubmitHandler<TFieldValues extends FieldValues = FieldValues> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>;
|
14
|
-
export interface StepFormContext extends UseStepperReturn {
|
15
|
-
updateStep(state: StepState): void;
|
16
|
-
steps: Record<string, StepState>;
|
17
|
-
}
|
18
|
-
export declare const StepFormProvider: React.Provider<StepFormContext>, useStepFormContext: () => StepFormContext;
|
19
|
-
import { FormProps } from './form';
|
20
|
-
export interface UseStepFormProps<TFieldValues extends FieldValues = FieldValues> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<TFieldValues>, 'children'> {
|
21
|
-
children: MaybeRenderProp<UseStepFormReturn<TFieldValues>>;
|
22
|
-
}
|
23
|
-
export interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
24
|
-
getFormProps(): {
|
25
|
-
onSubmit: SubmitHandler<TFieldValues>;
|
26
|
-
schema?: any;
|
27
|
-
resolver?: any;
|
28
|
-
};
|
29
|
-
updateStep(step: any): void;
|
30
|
-
steps: Record<string, any>;
|
31
|
-
}
|
32
|
-
export declare function useStepForm<TFieldValues extends FieldValues = FieldValues>(props: UseStepFormProps<TFieldValues>): UseStepFormReturn<TFieldValues>;
|
33
|
-
export interface UseFormStepProps {
|
34
|
-
name: string;
|
35
|
-
schema?: any;
|
36
|
-
resolver?: any;
|
37
|
-
onSubmit?: FormStepSubmitHandler;
|
38
|
-
}
|
39
|
-
export declare function useFormStep(props: UseFormStepProps): StepState;
|
40
|
-
//# sourceMappingURL=use-step-form.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"use-step-form.d.ts","sourceRoot":"","sources":["../src/use-step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,EAAiB,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAGL,eAAe,EACf,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,qBAAqB,CAAA;CACjC;AAED,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,IAC5C,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEpE,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CACjC;AAED,eAAO,MAAO,gBAAgB,mCAAE,kBAAkB,uBAK9C,CAAA;AAEJ,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAElC,MAAM,WAAW,gBAAgB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,CAC9C,SAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,EACvC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC;IAC3C,QAAQ,EAAE,eAAe,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAA;CAC3D;AAED,MAAM,WAAW,iBAAiB,CAChC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC9C,SAAQ,gBAAgB;IACxB,YAAY,IAAI;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;QACrC,MAAM,CAAC,EAAE,GAAG,CAAA;QACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;KACf,CAAA;IACD,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC3B;AAED,wBAAgB,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,EACxE,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC,GACpC,iBAAiB,CAAC,YAAY,CAAC,CA8DjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,QAAQ,CAAC,EAAE,qBAAqB,CAAA;CACjC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAc9D"}
|
package/dist/utils.d.ts
DELETED
@@ -1,3 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
export declare const mapNestedFields: (name: string, children: React.ReactNode) => (string | number | React.ReactFragment | React.ReactElement<unknown, string | React.JSXElementConstructor<any>>)[] | null | undefined;
|
3
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,eAAO,MAAM,eAAe,SAAU,MAAM,YAAY,MAAM,SAAS,0IAUtE,CAAA"}
|
package/dist/watch-field.d.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
3
|
-
export interface WatchFieldProps<Value = unknown, TFieldValues extends FieldValues = FieldValues> {
|
4
|
-
name: string;
|
5
|
-
defaultValue?: Value;
|
6
|
-
isDisabled?: boolean;
|
7
|
-
isExact?: boolean;
|
8
|
-
children: (value: Value, form: UseFormReturn<TFieldValues>) => React.ReactElement | void;
|
9
|
-
}
|
10
|
-
export declare const WatchField: <Value = unknown, TFieldValues extends FieldValues = FieldValues>(props: WatchFieldProps<Value, TFieldValues>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
11
|
-
//# sourceMappingURL=watch-field.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"watch-field.d.ts","sourceRoot":"","sources":["../src/watch-field.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAEX,aAAa,EAEd,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,eAAe,CAC9B,KAAK,GAAG,OAAO,EACf,YAAY,SAAS,WAAW,GAAG,WAAW;IAE9C,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,CACR,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,aAAa,CAAC,YAAY,CAAC,KAC9B,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAC/B;AAED,eAAO,MAAM,UAAU,iNAiBtB,CAAA"}
|
package/dist/yup/index.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../yup/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import{reach as e}from"yup";import{yupResolver as r}from"@hookform/resolvers/yup";export{yupResolver}from"@hookform/resolvers/yup";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},t.apply(this,arguments)}const a=e=>{var r;if(null!=(r=e.spec.meta)&&r.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"}},s=(e,r)=>{for(const a of e.tests){var t;if(null!=(t=a.OPTIONS)&&t.params[r])return a.OPTIONS.params[r]}},n=e=>{const r=[];let n={};n="array"===e.type?e.innerType.fields:e.fields;for(const e in n){const o=n[e],p={};"array"===o.type&&(p.min=s(o,"min"),p.max=s(o,"max")),r.push(t({name:e,label:o.spec.label||e,type:a(o)},p))}return r},o=(r,t)=>e(r,t),p=e=>({getFields:()=>n(e),getNestedFields:r=>n(o(e,r))}),l=(e,t={},a={})=>({schema:e,resolver:r(e,t,a),fieldResolver:p(e)});export{n as getFieldsFromSchema,o as getNestedSchema,p as yupFieldResolver,l as yupForm};
|
2
|
-
//# sourceMappingURL=index.modern.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["field","_field$spec$meta","spec","meta","type","getArrayOption","name","test","tests","_test$OPTIONS","OPTIONS","params","schema","fields","schemaFields","innerType","options","min","max","push","label","getType","getNestedSchema","path","reach","yupFieldResolver","getFields","getFieldsFromSchema","getNestedFields","yupForm","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"uWAaA,QAAiBA,IACf,IAAAC,EAAA,GAAI,OAAJA,EAAID,EAAME,KAAKC,OAAXF,EAAiBG,KACnB,OAAOJ,EAAME,KAAKC,KAAKC,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,OAAM,EAICC,EAAG,CAACL,EAAYM,KAClC,IAAK,MAAUC,OAAUC,MAAO,CAAA,IAAAC,EAC9B,GAAI,SAAAF,EAAKG,UAALD,EAAcE,OAAOL,GAAO,OAAWC,EAACG,QAAQC,OAAOL,EAC5D,KASiCM,IAClC,MAAYC,EAAG,GAEf,IAAgBC,EAAwB,GAGtCA,EAFkB,UAAhBF,EAAOR,KAEMQ,EAAOG,UAAUF,OAEjBD,EAAOC,OAGxB,IAAK,MAAMP,KAAoBQ,EAAE,CAC/B,MAAMd,EAAQc,EAAaR,KAEF,CAAE,EACR,UAAfN,EAAMI,OACRY,EAAQC,IAAMZ,EAAeL,EAAO,OACpCgB,EAAQE,IAAMb,EAAeL,EAAO,QAGtCa,EAAOM,KACLb,EAAAA,CAAAA,OACAc,MAAOpB,EAAME,KAAKkB,OAASd,EAC3BF,KAAMiB,EAAQrB,IACXgB,GAEN,CACD,OACFH,GAE4BS,EAAG,CAACV,EAAyBW,IAC3CC,EAACZ,EAAQW,GAGME,EAAIb,IACxB,CACLc,UAAS,IACmBC,EAACf,GAE7BgB,gBAAgBtB,GACPqB,EAAoBL,EAAgBV,EAAQN,MAKrCuB,EAAG,CACrBjB,EACAkB,EAAgB,CAAE,EAClBC,EAAkB,CAAA,KAEX,CACLnB,SACAoB,SAAUC,EAAYrB,EAAQkB,EAAeC,GAC7CG,cAAeT,EAAiBb"}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { AnyObjectSchema } from 'yup';
|
2
|
-
import { yupResolver } from '@hookform/resolvers/yup';
|
3
|
-
import { FieldProps } from '@saas-ui/forms';
|
4
|
-
export { yupResolver };
|
5
|
-
export type Options = {
|
6
|
-
min?: number;
|
7
|
-
max?: number;
|
8
|
-
};
|
9
|
-
/**
|
10
|
-
* A helper function to render forms automatically based on a Yup schema
|
11
|
-
*
|
12
|
-
* @param schema The Yup schema
|
13
|
-
* @returns {FieldProps[]}
|
14
|
-
*/
|
15
|
-
export declare const getFieldsFromSchema: (schema: AnyObjectSchema) => FieldProps[];
|
16
|
-
export declare const getNestedSchema: (schema: AnyObjectSchema, path: string) => any;
|
17
|
-
export declare const yupFieldResolver: (schema: AnyObjectSchema) => {
|
18
|
-
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
19
|
-
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
20
|
-
};
|
21
|
-
export declare const yupForm: (schema: AnyObjectSchema, schemaOptions?: {}, resolverOptions?: {}) => {
|
22
|
-
schema: AnyObjectSchema;
|
23
|
-
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: import("@saas-ui/forms").ResolverOptions<TFieldValues>) => Promise<import("@saas-ui/forms").ResolverResult<TFieldValues>>;
|
24
|
-
fieldResolver: {
|
25
|
-
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
26
|
-
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
27
|
-
};
|
28
|
-
};
|
29
|
-
//# sourceMappingURL=yup-resolver.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"yup-resolver.d.ts","sourceRoot":"","sources":["../../yup/src/yup-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,eAAe,EAAE,MAAM,KAAK,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AA6BD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,+BAA8B,UAAU,EA4BvE,CAAA;AAED,eAAO,MAAM,eAAe,kCAAmC,MAAM,QAEpE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA"}
|
package/dist/zod/index.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../zod/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import{zodResolver as e}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import{get as r}from"@chakra-ui/utils";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}const o=e=>{switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},n=(e,r)=>{var t;return null==(t=e._def[r])?void 0:t.value},a=e=>{const r=[];let a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(const e in a){const s=a[e],d={};"ZodArray"===s._def.typeName&&(d.min=n(s,"minLength"),d.max=n(s,"maxLength"));const i=s.description&&c(s.description);r.push(t({name:e,label:(null==i?void 0:i.label)||s.description||e,type:(null==i?void 0:i.type)||o(s)},d))}return r},s=(e,t)=>r(e._def.shape(),t),d=e=>({getFields:()=>a(e),getNestedFields:r=>a(s(e,r))}),i=(r,t={},o={})=>({schema:r,resolver:e(r,t,o),fieldResolver:d(r)}),l=e=>JSON.stringify(e),c=e=>{try{return JSON.parse(e)}catch(r){return e}};export{a as getFieldsFromSchema,s as getNestedSchema,d as zodFieldResolver,i as zodForm,l as zodMeta,c as zodParseMeta};
|
2
|
-
//# sourceMappingURL=index.modern.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["field","_def","typeName","name","_field$_def$name","value","schema","schemaFields","type","shape","options","min","getArrayOption","max","meta","description","zodParseMeta","fields","push","label","getType","path","zodFieldResolver","getFields","getFieldsFromSchema","getNestedFields","getNestedSchema","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","zodMeta","JSON","stringify","parse","e"],"mappings":"kXAYA,QAAiBA,IACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,OAAM,IAII,CAACF,EAAYG,KAClC,IAAAC,EAAA,OAAuB,OAAvBA,EAAOJ,EAAMC,KAAKE,SAAK,EAAhBC,EAAkBC,SASSC,IAClC,QAA6B,GAE7B,IAAIC,EAAoC,CAAE,EAC1C,GAA6B,aAAzBD,EAAOL,KAAKC,SACdK,EAAeD,EAAOL,KAAKO,KAAKC,UACvBH,IAAyB,cAAzBA,EAAOL,KAAKC,SAGrB,SAFAK,EAAeD,EAAOL,KAAKQ,OAG5B,CAED,IAAK,MAAMN,KAAQI,EAAc,CAC/B,QAAcA,EAAaJ,GAErBO,EAAmB,CAAA,EACG,aAAxBV,EAAMC,KAAKC,WACbQ,EAAQC,IAAMC,EAAeZ,EAAO,aACpCU,EAAQG,IAAMD,EAAeZ,EAAO,cAGtC,MAAMc,EAAOd,EAAMe,aAAeC,EAAahB,EAAMe,aAErDE,EAAOC,QACLf,OACAgB,OAAW,MAAJL,OAAI,EAAJA,EAAMK,QAASnB,EAAMe,aAAeZ,EAC3CK,YAAMM,SAAAA,EAAMN,OAAQY,EAAQpB,IACzBU,GAEN,CACD,OACFO,KAE+B,CAACX,EAAsBe,MACzCf,EAAOL,KAAKQ,QAASY,GAGrBC,EAA4ChB,IAChD,CACLiB,UAAS,IACmBC,EAAClB,GAE7BmB,gBAAgBtB,KACauB,EAAgBpB,EAAQH,QAKlC,CACrBG,EACAqB,EAAgB,CAAE,EAClBC,EAAkB,CAAA,KAEX,CACLtB,SACAuB,SAAUC,EAAYxB,EAAQqB,EAAeC,GAC7CG,cAAeT,EAAiBhB,KAShB0B,EAAIlB,GACXmB,KAACC,UAAUpB,GAGCE,EAAIF,IAC3B,IACE,YAAYqB,MAAMrB,EAGnB,CAFC,MAAOsB,GACP,OACDtB,CAAA"}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import * as z from 'zod';
|
2
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
3
|
-
import { FieldProps } from '@saas-ui/forms';
|
4
|
-
export { zodResolver };
|
5
|
-
export type Options = {
|
6
|
-
min?: number;
|
7
|
-
max?: number;
|
8
|
-
};
|
9
|
-
/**
|
10
|
-
* A helper function to render forms automatically based on a Yup schema
|
11
|
-
*
|
12
|
-
* @param schema The Yup schema
|
13
|
-
* @returns {FieldProps[]}
|
14
|
-
*/
|
15
|
-
export declare const getFieldsFromSchema: (schema: z.ZodTypeAny) => FieldProps[];
|
16
|
-
export declare const getNestedSchema: (schema: z.ZodTypeAny, path: string) => any;
|
17
|
-
export declare const zodFieldResolver: <T extends z.ZodTypeAny>(schema: T) => {
|
18
|
-
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
19
|
-
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
20
|
-
};
|
21
|
-
export declare const zodForm: <T extends z.ZodTypeAny>(schema: T, schemaOptions?: {}, resolverOptions?: {}) => {
|
22
|
-
schema: T;
|
23
|
-
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: import("@saas-ui/forms").ResolverOptions<TFieldValues>) => Promise<import("@saas-ui/forms").ResolverResult<TFieldValues>>;
|
24
|
-
fieldResolver: {
|
25
|
-
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
26
|
-
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
27
|
-
};
|
28
|
-
};
|
29
|
-
export interface ZodMeta {
|
30
|
-
label: string;
|
31
|
-
type?: string;
|
32
|
-
}
|
33
|
-
export declare const zodMeta: (meta: ZodMeta) => string;
|
34
|
-
export declare const zodParseMeta: (meta: string) => any;
|
35
|
-
//# sourceMappingURL=zod-resolver.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"zod-resolver.d.ts","sourceRoot":"","sources":["../../zod/src/zod-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAsBD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,WAAY,EAAE,UAAU,KAAG,UAAU,EA+BpE,CAAA;AAED,eAAO,MAAM,eAAe,WAAY,EAAE,UAAU,QAAQ,MAAM,QAEjE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,OAAO,SAAU,OAAO,WAEpC,CAAA;AAED,eAAO,MAAM,YAAY,SAAU,MAAM,QAMxC,CAAA"}
|
package/yup/package.json
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "yup-resolver",
|
3
|
-
"description": "Saas UI Forms field resolver: yup",
|
4
|
-
"version": "1.0.0",
|
5
|
-
"private": true,
|
6
|
-
"exports": {
|
7
|
-
".": {
|
8
|
-
"require": "./../dist/yup/index.js",
|
9
|
-
"import": "./../dist/yup/index.modern.mjs"
|
10
|
-
},
|
11
|
-
"./src": {
|
12
|
-
"default": "./src/index.ts"
|
13
|
-
}
|
14
|
-
},
|
15
|
-
"source": "./src/index.ts",
|
16
|
-
"main": "../dist/yup/index.js",
|
17
|
-
"module": "../dist/yup/index.modern.mjs",
|
18
|
-
"types": "../dist/yup/index.d.ts",
|
19
|
-
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
20
|
-
"license": "MIT",
|
21
|
-
"peerDependencies": {
|
22
|
-
"@hookform/resolvers": "^2.9.3",
|
23
|
-
"react-hook-form": "^7.33.1",
|
24
|
-
"yup": "^0.32.11"
|
25
|
-
}
|
26
|
-
}
|
package/zod/package.json
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "zod-resolver",
|
3
|
-
"description": "Saas UI Forms field resolver: zod",
|
4
|
-
"version": "1.0.0",
|
5
|
-
"private": true,
|
6
|
-
"exports": {
|
7
|
-
".": {
|
8
|
-
"require": "./../dist/zod/index.js",
|
9
|
-
"import": "./../dist/zod/index.modern.mjs"
|
10
|
-
},
|
11
|
-
"./src": {
|
12
|
-
"default": "./src/index.ts"
|
13
|
-
}
|
14
|
-
},
|
15
|
-
"source": "./src/index.ts",
|
16
|
-
"main": "../dist/zod/index.js",
|
17
|
-
"module": "../dist/zod/index.modern.mjs",
|
18
|
-
"types": "../dist/zod/index.d.ts",
|
19
|
-
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
20
|
-
"license": "MIT",
|
21
|
-
"peerDependencies": {
|
22
|
-
"@chakra-ui/utils": "^2.0.2",
|
23
|
-
"@hookform/resolvers": "^2.9.3",
|
24
|
-
"react-hook-form": "^7.33.1",
|
25
|
-
"zod": "^3.17.3"
|
26
|
-
}
|
27
|
-
}
|