@mantine-vue/form 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/types.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ import type { Ref } from 'vue';
2
+ export type FormErrors = Record<string, any>;
3
+ export type FormStatus = Record<string, boolean>;
4
+ export type FormMode = 'controlled' | 'uncontrolled';
5
+ export type OnSubmitPreventDefault = 'always' | 'never' | 'validation-failed';
6
+ export interface ReorderPayload {
7
+ from: number;
8
+ to: number;
9
+ }
10
+ export type FormRule<Value, Values> = (value: Value, values: Values, path: string) => any;
11
+ export type FormRulesRecord<Values> = {
12
+ [K in keyof Values]?: Values[K] extends ReadonlyArray<infer ListValue> ? Partial<Record<keyof ListValue, FormRule<any, Values> | FormRulesRecord<any>>> | FormRule<Values[K], Values> : Values[K] extends Record<string, any> ? FormRulesRecord<Values[K]> | FormRule<Values[K], Values> : FormRule<Values[K], Values>;
13
+ } & Record<PropertyKey, any>;
14
+ export interface UseFormInput<Values extends Record<string, any>, TransformedValues = Values> {
15
+ name?: string;
16
+ mode?: FormMode;
17
+ initialValues?: Values;
18
+ initialErrors?: FormErrors;
19
+ initialDirty?: FormStatus;
20
+ initialTouched?: FormStatus;
21
+ clearInputErrorOnChange?: boolean;
22
+ validateInputOnChange?: boolean | string[];
23
+ validateInputOnBlur?: boolean | string[];
24
+ validate?: FormRulesRecord<Values> | ((values: Values) => FormErrors);
25
+ transformValues?: (values: Values) => TransformedValues;
26
+ onValuesChange?: (values: Values, previous: Values) => void;
27
+ enhanceGetInputProps?: (payload: {
28
+ inputProps: Record<string, any>;
29
+ field: keyof Values | string;
30
+ options: GetInputPropsOptions;
31
+ form: UseFormReturnType<Values, TransformedValues>;
32
+ }) => Record<string, any> | undefined | void;
33
+ onSubmitPreventDefault?: OnSubmitPreventDefault;
34
+ touchTrigger?: 'focus' | 'change';
35
+ cascadeUpdates?: boolean;
36
+ }
37
+ export interface GetInputPropsOptions {
38
+ type?: 'input' | 'checkbox' | 'radio';
39
+ withError?: boolean;
40
+ withFocus?: boolean;
41
+ value?: any;
42
+ }
43
+ export interface UseFormReturnType<Values extends Record<string, any>, TransformedValues = Values> {
44
+ values: Ref<Values>;
45
+ initialized: Ref<boolean>;
46
+ errors: Ref<FormErrors>;
47
+ touched: Ref<FormStatus>;
48
+ dirty: Ref<FormStatus>;
49
+ submitting: Ref<boolean>;
50
+ watch: (path: keyof Values | string, subscriber: (input: {
51
+ previousValue: any;
52
+ value: any;
53
+ touched: boolean;
54
+ dirty: boolean;
55
+ }) => void) => () => void;
56
+ getValues: () => Values;
57
+ getInitialValues: () => Values;
58
+ setInitialValues: (values: Values) => void;
59
+ setValues: (values: Partial<Values> | ((values: Values) => Partial<Values>)) => void;
60
+ setFieldValue: (path: keyof Values | string, value: any, options?: {
61
+ forceUpdate?: boolean;
62
+ }) => void;
63
+ reset: () => void;
64
+ onReset: (event?: Event) => void;
65
+ resetField: (path: keyof Values | string) => void;
66
+ initialize: (values: Values) => void;
67
+ setSubmitting: (submitting: boolean | ((submitting: boolean) => boolean)) => void;
68
+ setErrors: (errors: FormErrors | ((errors: FormErrors) => FormErrors)) => void;
69
+ setFieldError: (path: keyof Values | string, error: any) => void;
70
+ clearFieldError: (path: keyof Values | string) => void;
71
+ clearErrors: () => void;
72
+ setTouched: (touched: FormStatus | ((touched: FormStatus) => FormStatus)) => void;
73
+ setDirty: (dirty: FormStatus | ((dirty: FormStatus) => FormStatus)) => void;
74
+ resetTouched: () => void;
75
+ resetDirty: (values?: Values) => void;
76
+ getTouched: () => FormStatus;
77
+ getDirty: () => FormStatus;
78
+ isTouched: (path?: keyof Values | string) => boolean;
79
+ isDirty: (path?: keyof Values | string) => boolean;
80
+ reorderListItem: (path: keyof Values | string, payload: ReorderPayload) => void;
81
+ insertListItem: (path: keyof Values | string, item: any, index?: number) => void;
82
+ removeListItem: (path: keyof Values | string, index: number) => void;
83
+ replaceListItem: (path: keyof Values | string, index: number, item: any) => void;
84
+ validate: () => {
85
+ hasErrors: boolean;
86
+ errors: FormErrors;
87
+ };
88
+ validateField: (path: keyof Values | string) => {
89
+ hasError: boolean;
90
+ error: any;
91
+ };
92
+ isValid: (path?: keyof Values | string) => boolean;
93
+ getInputProps: (path: keyof Values | string, options?: GetInputPropsOptions) => Record<string, any>;
94
+ onSubmit: (submit: (values: TransformedValues, event?: Event) => void | Promise<void>, validationFailure?: (errors: FormErrors, values: Values, event?: Event) => void) => (event?: Event) => void;
95
+ getTransformedValues: (values?: Values) => TransformedValues;
96
+ key: (path: keyof Values | string) => string;
97
+ getInputNode: <NodeType extends HTMLElement = HTMLElement>(path: keyof Values | string) => NodeType | null;
98
+ }
@@ -0,0 +1,12 @@
1
+ import type { UseFormReturnType } from './types';
2
+ export interface UseFieldInput<Values extends Record<string, any>> {
3
+ form: UseFormReturnType<Values>;
4
+ path: keyof Values | string;
5
+ }
6
+ export declare function useField<Values extends Record<string, any>>({ form, path, }: UseFieldInput<Values>): {
7
+ value: import("vue").WritableComputedRef<any, any>;
8
+ error: import("vue").ComputedRef<any>;
9
+ touched: import("vue").ComputedRef<boolean>;
10
+ dirty: import("vue").ComputedRef<boolean>;
11
+ getInputProps: () => Record<string, any>;
12
+ };
@@ -0,0 +1,2 @@
1
+ import type { UseFormInput, UseFormReturnType } from './types';
2
+ export declare function useForm<Values extends Record<string, any> = Record<string, any>, TransformedValues = Values>({ name, mode, initialValues, initialErrors, initialDirty, initialTouched, clearInputErrorOnChange, validateInputOnChange, validateInputOnBlur, validate: rules, transformValues, onValuesChange, enhanceGetInputProps, onSubmitPreventDefault, touchTrigger, cascadeUpdates, }?: UseFormInput<Values, TransformedValues>): UseFormReturnType<Values, TransformedValues>;
@@ -0,0 +1,31 @@
1
+ import type { FormErrors, FormRulesRecord } from './types';
2
+ export declare function hasLength(payload: {
3
+ min?: number;
4
+ max?: number;
5
+ }, error?: any): (value: string | unknown[]) => any;
6
+ export declare function isNotEmpty(error?: any): (value: unknown) => any;
7
+ export declare function matches(regexp: RegExp, error?: any): (value: string) => any;
8
+ export declare function isEmail(error?: any): (value: string) => any;
9
+ export declare function isInRange(payload: {
10
+ min?: number;
11
+ max?: number;
12
+ }, error?: any): (value: number) => any;
13
+ export declare function matchesField(path: string, error?: any): (value: unknown, values: Record<string, any>) => any;
14
+ export declare function isNotEmptyHtml(error?: any): (value: string) => any;
15
+ export declare function isJsonString(error?: any): (value: string) => any;
16
+ export declare const formRootRule: unique symbol;
17
+ export declare function validateValues<Values extends Record<string, any>>(rules: FormRulesRecord<Values> | ((values: Values) => FormErrors) | undefined, values: Values): {
18
+ hasErrors: boolean;
19
+ errors: FormErrors;
20
+ };
21
+ export declare function validateFieldValue<Values extends Record<string, any>>(path: PropertyKey, rules: FormRulesRecord<Values> | ((values: Values) => FormErrors) | undefined, values: Values): {
22
+ hasError: boolean;
23
+ error: any;
24
+ };
25
+ export declare function schemaResolver<T>(schema: {
26
+ safeParse: (value: T) => any;
27
+ }): (values: T) => any;
28
+ export declare const zodResolver: typeof schemaResolver;
29
+ export declare const yupResolver: typeof schemaResolver;
30
+ export declare const superstructResolver: typeof schemaResolver;
31
+ export declare const joiResolver: typeof schemaResolver;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@mantine-vue/form",
3
+ "version": "1.1.1",
4
+ "description": "Vue form management package equivalent to @mantine/form",
5
+ "license": "MIT",
6
+ "files": [
7
+ "cjs",
8
+ "esm",
9
+ "lib",
10
+ "styles.css",
11
+ "styles.layer.css",
12
+ "styles"
13
+ ],
14
+ "sideEffects": false,
15
+ "main": "./cjs/index.cjs",
16
+ "module": "./esm/index.mjs",
17
+ "types": "./lib/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./lib/index.d.mts",
22
+ "default": "./esm/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./lib/index.d.ts",
26
+ "default": "./cjs/index.cjs"
27
+ }
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "@mantine-vue/utils": "1.1.1"
32
+ },
33
+ "devDependencies": {
34
+ "@mantine-vue/utils": "workspace:*",
35
+ "vue": "^3.5.0"
36
+ },
37
+ "peerDependencies": {
38
+ "vue": "^3.5.0"
39
+ }
40
+ }