maz-ui 4.0.0-beta.12 → 4.0.0-beta.13
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/dist/composables/useFormField.js +1 -1
- package/dist/composables/useFormValidator.js +18 -2
- package/dist/types/composables/useFormField.d.ts +16 -18
- package/dist/types/composables/useFormValidator/config.d.ts +2 -2
- package/dist/types/composables/useFormValidator/dom-events.d.ts +4 -4
- package/dist/types/composables/useFormValidator/state-management.d.ts +40 -22
- package/dist/types/composables/useFormValidator/types.d.ts +13 -13
- package/dist/types/composables/useFormValidator/validation.d.ts +10 -16
- package/dist/types/composables/useFormValidator.d.ts +1 -1
- package/package.json +2 -2
|
@@ -63,7 +63,7 @@ function useFormField(name, options) {
|
|
|
63
63
|
};
|
|
64
64
|
onMounted(() => {
|
|
65
65
|
const element = finalOpts.ref?.value, elementToBind = element instanceof HTMLElement ? element : element?.$el;
|
|
66
|
-
elementToBind instanceof HTMLElement ? handleInteractiveElements(elementToBind) : console.warn(`[maz-ui](useFormField) No element found for ref in field '${String(name)}'. Make sure the ref is properly bound to an HTMLElement or Vue component (form identifier: ${formOptions.identifier})`);
|
|
66
|
+
elementToBind instanceof HTMLElement ? handleInteractiveElements(elementToBind) : console.warn(`[maz-ui](useFormField) No element found for ref in field '${String(name)}'. Make sure the ref is properly bound to an HTMLElement or Vue component (form identifier: ${String(formOptions.identifier)})`);
|
|
67
67
|
}), onUnmounted(() => {
|
|
68
68
|
removeEventFromInteractiveElements({
|
|
69
69
|
interactiveElements,
|
|
@@ -29,7 +29,17 @@ function useFormValidator({ schema, defaultValues, model, options }) {
|
|
|
29
29
|
payload: payload.value,
|
|
30
30
|
options: opts
|
|
31
31
|
})
|
|
32
|
-
), isSubmitting = ref(!1), isSubmitted = ref(!1), isValid = computed(() =>
|
|
32
|
+
), isSubmitting = ref(!1), isSubmitted = ref(!1), isValid = computed(() => {
|
|
33
|
+
for (const key in fieldsStates.value)
|
|
34
|
+
if (!fieldsStates.value[key].valid)
|
|
35
|
+
return !1;
|
|
36
|
+
return !0;
|
|
37
|
+
}), isDirty = computed(() => {
|
|
38
|
+
for (const key in fieldsStates.value)
|
|
39
|
+
if (fieldsStates.value[key].dirty)
|
|
40
|
+
return !0;
|
|
41
|
+
return !1;
|
|
42
|
+
}), errors = computed(() => getFieldsErrors(fieldsStates.value)), errorMessages = computed(() => getErrorMessages(errors.value, fieldsStates.value));
|
|
33
43
|
model && watch(
|
|
34
44
|
payload,
|
|
35
45
|
(newModel) => {
|
|
@@ -79,7 +89,13 @@ function useFormValidator({ schema, defaultValues, model, options }) {
|
|
|
79
89
|
return fieldState && newSnapshot[name] !== oldSnapshot?.[name] && hasModeIncludes(["aggressive", "lazy", "progressive"], fieldState.mode);
|
|
80
90
|
});
|
|
81
91
|
if (fieldsToValidate.length > 0) {
|
|
82
|
-
const processValidations = createValidationProcessor(
|
|
92
|
+
const processValidations = createValidationProcessor(
|
|
93
|
+
fieldsToValidate,
|
|
94
|
+
fieldsStates,
|
|
95
|
+
payload,
|
|
96
|
+
internalSchema,
|
|
97
|
+
isSubmitted
|
|
98
|
+
);
|
|
83
99
|
typeof requestIdleCallback < "u" ? requestIdleCallback(processValidations, { timeout: 100 }) : nextTick(processValidations);
|
|
84
100
|
}
|
|
85
101
|
},
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { BaseFormPayload, ExtractModelKey, FormFieldOptions, FormSchema
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
export declare function useFormField<FieldType, Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(name: ModelKey, options?: FormFieldOptions<FieldType>): UseFormFieldReturn<FieldType>;
|
|
18
|
-
export {};
|
|
1
|
+
import { BaseFormPayload, ExtractModelKey, FormFieldOptions, FormSchema } from './useFormValidator/types';
|
|
2
|
+
export declare function useFormField<FieldType, Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(name: ModelKey, options?: FormFieldOptions<Model, ModelKey, FieldType>): {
|
|
3
|
+
hasError: import('vue').ComputedRef<boolean>;
|
|
4
|
+
errors: import('vue').ComputedRef<import('./useFormValidator/types').ValidationIssues>;
|
|
5
|
+
errorMessage: import('vue').ComputedRef<Record<ModelKey, string | undefined>[ModelKey]>;
|
|
6
|
+
isValid: import('vue').ComputedRef<boolean>;
|
|
7
|
+
isDirty: import('vue').ComputedRef<boolean>;
|
|
8
|
+
isBlurred: import('vue').ComputedRef<boolean>;
|
|
9
|
+
isValidated: import('vue').ComputedRef<boolean>;
|
|
10
|
+
isValidating: import('vue').ComputedRef<boolean>;
|
|
11
|
+
mode: import('vue').ComputedRef<"blur" | "eager" | "lazy" | "aggressive" | "progressive" | undefined>;
|
|
12
|
+
value: import('vue').WritableComputedRef<FieldType, FieldType>;
|
|
13
|
+
validationEvents: import('vue').ComputedRef<{
|
|
14
|
+
onBlur: () => void;
|
|
15
|
+
} | undefined>;
|
|
16
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { StrictOptions } from './types';
|
|
1
|
+
import { BaseFormPayload, ExtractModelKey, FormSchema, StrictOptions } from './types';
|
|
2
2
|
export declare const CONFIG: {
|
|
3
|
-
mode: StrictOptions['mode'];
|
|
3
|
+
mode: StrictOptions<BaseFormPayload, ExtractModelKey<FormSchema<BaseFormPayload>>>['mode'];
|
|
4
4
|
scrollToErrorSelector: string;
|
|
5
5
|
debounceTime: number;
|
|
6
6
|
throttleTime: number;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BaseFormPayload, FieldState, StrictOptions } from './types';
|
|
1
|
+
import { BaseFormPayload, ExtractModelKey, FieldState, FormSchema, StrictOptions } from './types';
|
|
2
2
|
export declare function scrollToError(selector?: string): void;
|
|
3
3
|
export declare function findInteractiveElements(el: HTMLElement): HTMLElement[];
|
|
4
4
|
export declare function addEventToInteractiveElements({ interactiveElements, onBlur, mode, }: {
|
|
5
5
|
interactiveElements: HTMLElement[];
|
|
6
6
|
onBlur: () => void;
|
|
7
|
-
mode: StrictOptions['mode'];
|
|
7
|
+
mode: StrictOptions<BaseFormPayload, ExtractModelKey<FormSchema<BaseFormPayload>>>['mode'];
|
|
8
8
|
}): void;
|
|
9
9
|
export declare function removeEventFromInteractiveElements({ interactiveElements, onBlur, }: {
|
|
10
10
|
interactiveElements: HTMLElement[];
|
|
11
11
|
onBlur: () => void;
|
|
12
12
|
}): void;
|
|
13
|
-
export declare function getValidationEvents<Model extends BaseFormPayload
|
|
13
|
+
export declare function getValidationEvents<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>, F extends FieldState<Model, ModelKey, Model[ModelKey]>>({ hasRef, fieldState, onBlur, }: {
|
|
14
14
|
hasRef?: boolean;
|
|
15
|
-
fieldState:
|
|
15
|
+
fieldState: F;
|
|
16
16
|
onBlur: () => void;
|
|
17
17
|
}): {
|
|
18
18
|
onBlur: () => void;
|
|
@@ -1,54 +1,72 @@
|
|
|
1
1
|
import { InjectionKey } from 'vue';
|
|
2
2
|
import { BaseFormPayload, CustomInstance, ExtractModelKey, FieldsStates, FieldState, FormContext, FormFieldOptions, FormSchema, StrictOptions } from './types';
|
|
3
|
-
export declare function getFieldState<Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model
|
|
3
|
+
export declare function getFieldState<Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]>({ name, schema, initialValue, fieldState, options, }: {
|
|
4
4
|
name: ModelKey;
|
|
5
5
|
schema?: FormSchema<Model>;
|
|
6
|
-
initialValue?:
|
|
7
|
-
fieldState: FieldState<Model>;
|
|
8
|
-
options?: Pick<StrictOptions<Model>, 'debouncedFields' | 'throttledFields' | 'mode'>;
|
|
9
|
-
}): FieldState<Model>;
|
|
6
|
+
initialValue?: FieldType;
|
|
7
|
+
fieldState: FieldState<Model, ModelKey, FieldType>;
|
|
8
|
+
options?: Pick<StrictOptions<Model, ModelKey>, 'debouncedFields' | 'throttledFields' | 'mode'>;
|
|
9
|
+
}): FieldState<Model, ModelKey, FieldType>;
|
|
10
10
|
export declare function fieldHasValidation<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>>(field: ModelKey, schema: FormSchema<Model>): boolean;
|
|
11
11
|
export declare function getFieldsStates<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>({ schema, payload, options, }: {
|
|
12
12
|
schema: FormSchema<Model>;
|
|
13
13
|
payload: Partial<Model>;
|
|
14
|
-
options: StrictOptions<Model>;
|
|
15
|
-
}): FieldsStates<Model>;
|
|
14
|
+
options: StrictOptions<Model, ModelKey>;
|
|
15
|
+
}): FieldsStates<Model, ModelKey>;
|
|
16
16
|
export declare function updateFieldsStates<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>({ fieldsStates, payload, schema, options, updateMode, }: {
|
|
17
|
-
fieldsStates: FieldsStates<Model>;
|
|
17
|
+
fieldsStates: FieldsStates<Model, ModelKey>;
|
|
18
18
|
payload: Model;
|
|
19
19
|
schema: FormSchema<Model>;
|
|
20
|
-
options: StrictOptions<Model>;
|
|
20
|
+
options: StrictOptions<Model, ModelKey>;
|
|
21
21
|
updateMode?: boolean;
|
|
22
22
|
}): void;
|
|
23
|
-
export declare function updateFieldState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model
|
|
23
|
+
export declare function updateFieldState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]>({ name, fieldState, payload, schema, options, updateMode, }: {
|
|
24
24
|
name: ModelKey;
|
|
25
|
-
fieldState: FieldState<Model>;
|
|
25
|
+
fieldState: FieldState<Model, ModelKey, FieldType>;
|
|
26
26
|
payload: Model;
|
|
27
27
|
schema: FormSchema<Model>;
|
|
28
|
-
options: FormFieldOptions<Model
|
|
28
|
+
options: FormFieldOptions<Model, ModelKey, FieldType> & StrictOptions<Model, ModelKey>;
|
|
29
29
|
updateMode?: boolean;
|
|
30
|
-
}):
|
|
31
|
-
|
|
30
|
+
}): {
|
|
31
|
+
blurred: boolean;
|
|
32
|
+
dirty: boolean;
|
|
33
|
+
error: boolean;
|
|
34
|
+
errors: import('./types').ValidationIssues;
|
|
35
|
+
valid: boolean;
|
|
36
|
+
validating: boolean;
|
|
37
|
+
validated: boolean;
|
|
38
|
+
validateFunction: ((args_0: {
|
|
39
|
+
name: ModelKey;
|
|
40
|
+
fieldState: FieldState<Model, ModelKey, Model[ModelKey]>;
|
|
41
|
+
schema: FormSchema<Model>;
|
|
42
|
+
payload: Model;
|
|
43
|
+
setError?: boolean;
|
|
44
|
+
setErrorIfInvalidAndNotEmpty?: boolean;
|
|
45
|
+
}) => Promise<void>) | undefined;
|
|
46
|
+
initialValue: Readonly<FieldType> | undefined;
|
|
47
|
+
mode: "blur" | "eager" | "lazy" | "aggressive" | "progressive" | undefined;
|
|
48
|
+
};
|
|
49
|
+
export declare function canExecuteValidation<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]>({ eventName, fieldState, isSubmitted, }: {
|
|
32
50
|
eventName: 'blur' | 'input';
|
|
33
|
-
fieldState: FieldState<Model>;
|
|
51
|
+
fieldState: FieldState<Model, ModelKey, FieldType>;
|
|
34
52
|
isSubmitted: boolean;
|
|
35
53
|
}): boolean;
|
|
36
|
-
export declare function handleFieldBlur<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model
|
|
54
|
+
export declare function handleFieldBlur<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]>({ name, force, payload, fieldState, schema, isSubmitted, }: {
|
|
37
55
|
name: ModelKey;
|
|
38
56
|
payload: Model;
|
|
39
|
-
fieldState: FieldState<Model>;
|
|
57
|
+
fieldState: FieldState<Model, ModelKey, FieldType>;
|
|
40
58
|
schema: FormSchema<Model>;
|
|
41
59
|
isSubmitted: boolean;
|
|
42
60
|
force?: boolean;
|
|
43
61
|
}): Promise<void> | undefined;
|
|
44
|
-
export declare function handleFieldInput<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model
|
|
62
|
+
export declare function handleFieldInput<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]>({ name, payload, fieldState, schema, isSubmitted, forceValidation, }: {
|
|
45
63
|
name: ModelKey;
|
|
46
64
|
payload: Model;
|
|
47
|
-
fieldState: FieldState<Model>;
|
|
65
|
+
fieldState: FieldState<Model, ModelKey, FieldType>;
|
|
48
66
|
schema: FormSchema<Model>;
|
|
49
67
|
isSubmitted: boolean;
|
|
50
68
|
forceValidation?: boolean;
|
|
51
69
|
}): Promise<void> | undefined;
|
|
52
|
-
export declare function hasModeIncludes(modes: StrictOptions['mode'][], value?: StrictOptions['mode']): value is StrictOptions['mode'];
|
|
53
|
-
export declare function getInstance<Model extends BaseFormPayload
|
|
54
|
-
export declare function getContext<Model extends BaseFormPayload
|
|
70
|
+
export declare function hasModeIncludes<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(modes: StrictOptions<Model, ModelKey>['mode'][], value?: StrictOptions<Model, ModelKey>['mode']): value is StrictOptions<Model, ModelKey>['mode'];
|
|
71
|
+
export declare function getInstance<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(composableName: string): CustomInstance<Model, ModelKey>;
|
|
72
|
+
export declare function getContext<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(identifier: string | symbol | InjectionKey<FormContext<Model, ModelKey>>, composableName: string): FormContext<Model, ModelKey>;
|
|
@@ -4,13 +4,13 @@ import { getValidateFunction } from './validation';
|
|
|
4
4
|
export type Validation = BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
|
|
5
5
|
export type ValidationIssues = InferIssue<Validation>[];
|
|
6
6
|
export type ExtractModelKey<T> = Extract<keyof T, string>;
|
|
7
|
-
export type FormSchema<Model
|
|
7
|
+
export type FormSchema<Model extends BaseFormPayload> = {
|
|
8
8
|
[K in Extract<keyof Model, string> as Model[K] extends Required<Model>[K] ? K : never]: Validation;
|
|
9
9
|
} & {
|
|
10
10
|
[K in Extract<keyof Model, string> as Model[K] extends Required<Model>[K] ? never : K]?: Validation;
|
|
11
11
|
};
|
|
12
|
-
export type CustomInstance<Model extends BaseFormPayload
|
|
13
|
-
formContexts?: Map<string | symbol | InjectionKey<FormContext<Model>>, FormContext<Model>>;
|
|
12
|
+
export type CustomInstance<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> = ComponentInternalInstance & {
|
|
13
|
+
formContexts?: Map<string | symbol | InjectionKey<FormContext<Model, ModelKey>>, FormContext<Model, ModelKey>>;
|
|
14
14
|
};
|
|
15
15
|
export interface FormValidatorOptions<Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>> {
|
|
16
16
|
/**
|
|
@@ -48,16 +48,16 @@ export interface FormValidatorOptions<Model extends BaseFormPayload = BaseFormPa
|
|
|
48
48
|
*/
|
|
49
49
|
identifier?: string | symbol;
|
|
50
50
|
}
|
|
51
|
-
export type StrictOptions<Model extends BaseFormPayload
|
|
52
|
-
export interface FormContext<Model extends BaseFormPayload
|
|
53
|
-
fieldsStates: Ref<FieldsStates<Model>>;
|
|
54
|
-
options: StrictOptions
|
|
51
|
+
export type StrictOptions<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> = Required<FormValidatorOptions<Model, ModelKey>>;
|
|
52
|
+
export interface FormContext<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> {
|
|
53
|
+
fieldsStates: Ref<FieldsStates<Model, ModelKey>>;
|
|
54
|
+
options: StrictOptions<Model, ModelKey>;
|
|
55
55
|
internalSchema: Ref<FormSchema<Model>>;
|
|
56
56
|
payload: Ref<Model>;
|
|
57
57
|
errorMessages: Ref<Record<ModelKey, string | undefined>>;
|
|
58
58
|
isSubmitted: Ref<boolean>;
|
|
59
59
|
}
|
|
60
|
-
export interface FieldState<Model extends BaseFormPayload,
|
|
60
|
+
export interface FieldState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>, FieldType = Model[ModelKey]> {
|
|
61
61
|
blurred: boolean;
|
|
62
62
|
dirty: boolean;
|
|
63
63
|
error: boolean;
|
|
@@ -66,12 +66,12 @@ export interface FieldState<Model extends BaseFormPayload, FieldType = Model[Ext
|
|
|
66
66
|
initialValue?: Readonly<FieldType>;
|
|
67
67
|
validating: boolean;
|
|
68
68
|
validated: boolean;
|
|
69
|
-
validateFunction: ReturnType<typeof getValidateFunction<Model>>;
|
|
70
|
-
mode?: StrictOptions['mode'];
|
|
69
|
+
validateFunction: ReturnType<typeof getValidateFunction<Model, ModelKey>>;
|
|
70
|
+
mode?: StrictOptions<Model, ModelKey>['mode'];
|
|
71
71
|
}
|
|
72
|
-
export type FieldsStates<Model extends BaseFormPayload
|
|
72
|
+
export type FieldsStates<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> = Record<ModelKey, FieldState<Model, ModelKey, Model[ModelKey]>>;
|
|
73
73
|
export type BaseFormPayload = Record<string, any>;
|
|
74
|
-
export interface FormFieldOptions<FieldType> {
|
|
74
|
+
export interface FormFieldOptions<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>, FieldType> {
|
|
75
75
|
/**
|
|
76
76
|
* Default value of the field
|
|
77
77
|
* @default undefined
|
|
@@ -81,7 +81,7 @@ export interface FormFieldOptions<FieldType> {
|
|
|
81
81
|
* Validation mode
|
|
82
82
|
* To override the form validation mode
|
|
83
83
|
*/
|
|
84
|
-
mode?: StrictOptions['mode'];
|
|
84
|
+
mode?: StrictOptions<Model, ModelKey>['mode'];
|
|
85
85
|
/**
|
|
86
86
|
* Reference to the component or HTML element to associate and trigger validation events
|
|
87
87
|
* Necessary for 'eager', 'progressive' and 'blur' validation modes
|
|
@@ -2,40 +2,34 @@ import { BaseFormPayload, ExtractModelKey, FieldsStates, FieldState, FormSchema,
|
|
|
2
2
|
export declare function isEmptyValue(value: unknown): value is null | undefined | '';
|
|
3
3
|
export declare function getValibotValidationMethod<MethodName extends keyof typeof import('valibot')>(methodName: MethodName): Promise<(typeof import('valibot'))[MethodName]>;
|
|
4
4
|
export declare function getValidationSchema<Model extends BaseFormPayload>(formSchema: FormSchema<Model>): Promise<import('valibot').ObjectSchemaAsync<FormSchema<Model>, undefined>>;
|
|
5
|
-
export declare function getFieldValidationResult<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model
|
|
5
|
+
export declare function getFieldValidationResult<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>>(name: ModelKey, schema: FormSchema<Model>, value: Model[ModelKey]): Promise<{
|
|
6
6
|
result: import('valibot').SafeParseResult<FormSchema<Model>[ModelKey]>;
|
|
7
7
|
isValid: boolean;
|
|
8
8
|
}>;
|
|
9
|
-
export declare function setFieldValidationState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model
|
|
9
|
+
export declare function setFieldValidationState<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>>({ name, fieldState, schema, payload, setError, setErrorIfInvalidAndNotEmpty, }: {
|
|
10
10
|
name: ModelKey;
|
|
11
|
-
fieldState: FieldState<Model>;
|
|
11
|
+
fieldState: FieldState<Model, ModelKey, Model[ModelKey]>;
|
|
12
12
|
schema: FormSchema<Model>;
|
|
13
13
|
payload: Model;
|
|
14
14
|
setError?: boolean;
|
|
15
15
|
setErrorIfInvalidAndNotEmpty?: boolean;
|
|
16
16
|
}): Promise<void>;
|
|
17
|
-
export declare function validateField<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>({ name, fieldState, payload, schema, }: {
|
|
18
|
-
name: ModelKey;
|
|
19
|
-
fieldState: FieldState<Model>;
|
|
20
|
-
payload: Model;
|
|
21
|
-
schema: FormSchema<Model>;
|
|
22
|
-
}): Promise<void> | undefined;
|
|
23
17
|
export declare function validateForm<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>({ fieldsStates, payload, setErrors, schema, }: {
|
|
24
|
-
fieldsStates: FieldsStates<Model
|
|
18
|
+
fieldsStates: FieldsStates<Model, ExtractModelKey<FormSchema<Model>>>;
|
|
25
19
|
setErrors?: boolean;
|
|
26
20
|
payload: Model;
|
|
27
21
|
schema: FormSchema<Model>;
|
|
28
22
|
}): Promise<void[]>;
|
|
29
|
-
export declare function getErrorMessages<Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(errors: Record<ModelKey, ValidationIssues>, fieldsStates: FieldsStates<Model
|
|
30
|
-
export declare function getFieldsErrors<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(fieldsStates: FieldsStates<Model
|
|
23
|
+
export declare function getErrorMessages<Model extends BaseFormPayload = BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(errors: Record<ModelKey, ValidationIssues>, fieldsStates: FieldsStates<Model, ExtractModelKey<FormSchema<Model>>>): Record<ModelKey, string | undefined>;
|
|
24
|
+
export declare function getFieldsErrors<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>(fieldsStates: FieldsStates<Model, ExtractModelKey<FormSchema<Model>>>): Record<ModelKey, ValidationIssues>;
|
|
31
25
|
export declare function getValidateFunction<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>> = ExtractModelKey<FormSchema<Model>>>({ name, hasValidation, debouncedFields, throttledFields, }: {
|
|
32
26
|
name: ModelKey;
|
|
33
27
|
hasValidation: boolean;
|
|
34
|
-
debouncedFields?: StrictOptions<Model>['debouncedFields'];
|
|
35
|
-
throttledFields?: StrictOptions<Model>['throttledFields'];
|
|
28
|
+
debouncedFields?: StrictOptions<Model, ModelKey>['debouncedFields'];
|
|
29
|
+
throttledFields?: StrictOptions<Model, ModelKey>['throttledFields'];
|
|
36
30
|
}): ((args_0: {
|
|
37
|
-
name:
|
|
38
|
-
fieldState: FieldState<Model,
|
|
31
|
+
name: ModelKey;
|
|
32
|
+
fieldState: FieldState<Model, ModelKey, Model[ModelKey]>;
|
|
39
33
|
schema: FormSchema<Model>;
|
|
40
34
|
payload: Model;
|
|
41
35
|
setError?: boolean;
|
|
@@ -15,7 +15,7 @@ export declare function useFormValidator<TSchema extends MaybeRefOrGetter<FormSc
|
|
|
15
15
|
isValid: import('vue').ComputedRef<boolean>;
|
|
16
16
|
errors: import('vue').ComputedRef<Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, import('./useFormValidator/types').ValidationIssues>>;
|
|
17
17
|
model: Ref<InferSchemaFormValidator<TSchema>, InferSchemaFormValidator<TSchema>>;
|
|
18
|
-
fieldsStates: Ref<FieldsStates<InferSchemaFormValidator<TSchema
|
|
18
|
+
fieldsStates: Ref<FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>, FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>>;
|
|
19
19
|
validateForm: (setErrors?: boolean) => Promise<void[]>;
|
|
20
20
|
scrollToError: typeof scrollToError;
|
|
21
21
|
handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"]) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maz-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.13",
|
|
5
5
|
"description": "A standalone components library for Vue.Js 3 & Nuxt.Js 3",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -240,5 +240,5 @@
|
|
|
240
240
|
"*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix",
|
|
241
241
|
"*.{vue,css,scss,postcss,pcss}": "stylelint --fix --allow-empty-input"
|
|
242
242
|
},
|
|
243
|
-
"gitHead": "
|
|
243
|
+
"gitHead": "9f0dc4d0f42b64d34290fc328458e94fc977a2ff"
|
|
244
244
|
}
|