@teamnovu/kit-vue-forms 0.1.14 → 0.1.16
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/components/FormFieldWrapper.vue.d.ts +1 -1
- package/dist/composables/useField.d.ts +7 -3
- package/dist/composables/useFieldRegistry.d.ts +13 -4
- package/dist/composables/useValidation.d.ts +1 -0
- package/dist/index.js +353 -278
- package/dist/types/form.d.ts +3 -1
- package/dist/utils/path.d.ts +4 -1
- package/docs/reference.md +0 -2
- package/package.json +1 -1
- package/src/components/FormFieldWrapper.vue +8 -0
- package/src/composables/useField.ts +23 -5
- package/src/composables/useFieldRegistry.ts +82 -15
- package/src/composables/useForm.ts +79 -32
- package/src/composables/useValidation.ts +17 -0
- package/src/types/form.ts +23 -8
- package/src/utils/path.ts +81 -46
- package/tests/subform.test.ts +17 -0
- package/tests/useField.test.ts +17 -0
- package/tests/useForm.test.ts +352 -200
- package/tests/useValidation.test.ts +97 -1
|
@@ -12,7 +12,7 @@ declare const _default: <TData extends object, TPath extends Paths<TData>, TComp
|
|
|
12
12
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FormFieldWrapperProps<TData, TPath, TComponent> & Partial<{}>> & PublicProps;
|
|
13
13
|
expose(exposed: ShallowUnwrapRef<{}>): void;
|
|
14
14
|
attrs: any;
|
|
15
|
-
slots: {
|
|
15
|
+
slots: Partial<Record<number, (_: any) => any>> & {
|
|
16
16
|
default?(_: {}): any;
|
|
17
17
|
};
|
|
18
18
|
emit: {};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Awaitable } from '@vueuse/core';
|
|
2
|
+
import { MaybeRef, MaybeRefOrGetter, Ref } from 'vue';
|
|
2
3
|
import { FormField } from '../types/form';
|
|
3
4
|
import { ValidationErrors } from '../types/validation';
|
|
4
5
|
export interface UseFieldOptions<T, K extends string> {
|
|
5
6
|
value?: MaybeRef<T>;
|
|
6
7
|
initialValue?: MaybeRefOrGetter<Readonly<T>>;
|
|
7
8
|
path: K;
|
|
8
|
-
errors?:
|
|
9
|
+
errors?: Ref<ValidationErrors>;
|
|
10
|
+
existsInForm?: MaybeRef<boolean>;
|
|
11
|
+
onBlur?: () => Awaitable<void>;
|
|
12
|
+
onFocus?: () => Awaitable<void>;
|
|
9
13
|
}
|
|
10
|
-
export declare function useField<T, K extends string>(
|
|
14
|
+
export declare function useField<T, K extends string>(fieldOptions: UseFieldOptions<T, K>): FormField<T, K>;
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
+
import { MaybeRef, ComputedRef } from 'vue';
|
|
1
2
|
import { FieldsTuple, FormDataDefault, FormField } from '../types/form';
|
|
2
3
|
import { Paths, PickProps } from '../types/util';
|
|
3
4
|
import { UseFieldOptions } from './useField';
|
|
4
5
|
import { ValidationState } from './useValidation';
|
|
5
|
-
import {
|
|
6
|
+
import { Awaitable } from '@vueuse/core';
|
|
6
7
|
export type ResolvedFormField<T, K extends Paths<T>> = FormField<PickProps<T, K>, K>;
|
|
7
|
-
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>, 'path'
|
|
8
|
+
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>, 'path'> & {
|
|
9
|
+
onBlur?: () => void;
|
|
10
|
+
onFocus?: () => void;
|
|
11
|
+
};
|
|
8
12
|
interface FormState<T extends FormDataDefault, TIn extends FormDataDefault = T> {
|
|
9
13
|
data: T;
|
|
10
14
|
initialData: TIn;
|
|
11
15
|
}
|
|
12
|
-
|
|
16
|
+
interface FieldRegistryOptions {
|
|
17
|
+
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
18
|
+
onBlur?: (path: string) => Awaitable<void>;
|
|
19
|
+
onFocus?: (path: string) => Awaitable<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function useFieldRegistry<T extends FormDataDefault>(formState: FormState<T>, validationState: ValidationState<T>, fieldRegistryOptions?: FieldRegistryOptions): {
|
|
13
22
|
fields: ComputedRef<FieldsTuple<T>>;
|
|
14
|
-
getField: <
|
|
23
|
+
getField: <P extends Paths<T>>(path: P) => ResolvedFormField<T, P>;
|
|
15
24
|
registerField: <K extends Paths<T>>(field: ResolvedFormField<T, K>) => void;
|
|
16
25
|
deregisterField: (path: Paths<T>) => void;
|
|
17
26
|
defineField: <K extends Paths<T>>(options: DefineFieldOptions<PickProps<T, K>, K>) => ResolvedFormField<T, K>;
|
|
@@ -16,6 +16,7 @@ export declare function useValidation<T extends FormDataDefault>(formState: {
|
|
|
16
16
|
data: T;
|
|
17
17
|
}, options: ValidationOptions<T>): {
|
|
18
18
|
validateForm: () => Promise<ValidationResult>;
|
|
19
|
+
validateField: (path: string) => Promise<ValidationResult>;
|
|
19
20
|
defineValidator: <TData extends T>(options: ValidatorOptions<TData> | Ref<Validator<TData>>) => Ref<Validator<TData> | undefined, Validator<TData> | undefined>;
|
|
20
21
|
isValid: ComputedRef<boolean>;
|
|
21
22
|
reset: () => void;
|