@teamnovu/kit-vue-forms 0.1.19 → 0.1.20
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.
|
@@ -1,31 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Form, FormDataDefault, FieldsTuple } from '../types/form';
|
|
4
|
-
import { EntityPaths, PickEntity } from '../types/util';
|
|
1
|
+
import { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { Form, FormDataDefault } from '../types/form';
|
|
5
3
|
import { ValidationStrategy } from '../types/validation';
|
|
6
|
-
import {
|
|
7
|
-
import { ValidationOptions, ValidatorOptions } from './useValidation';
|
|
8
|
-
import { ErrorBag, Paths, PickProps, FormField, Validator, ValidationResult } from '..';
|
|
9
|
-
import { DefineFieldOptions } from './useFieldRegistry';
|
|
4
|
+
import { ValidationOptions } from './useValidation';
|
|
10
5
|
export interface UseFormOptions<T extends FormDataDefault> extends ValidationOptions<T> {
|
|
11
6
|
initialData: MaybeRefOrGetter<T>;
|
|
12
7
|
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
13
8
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
14
9
|
}
|
|
15
|
-
export declare function useForm<T extends FormDataDefault>(options: UseFormOptions<T>):
|
|
16
|
-
submitHandler: (onSubmit: (data: T) => Awaitable<void>) => (event: SubmitEvent) => Promise<void>;
|
|
17
|
-
errors: Ref< ErrorBag>;
|
|
18
|
-
data: Ref<T, T>;
|
|
19
|
-
isValid: Ref<boolean>;
|
|
20
|
-
isValidated: Ref<boolean>;
|
|
21
|
-
initialData: Readonly<Ref<T, T>>;
|
|
22
|
-
fields: Ref< FieldsTuple<T, Paths<T>>, FieldsTuple<T, Paths<T>>>;
|
|
23
|
-
defineField: <P extends Paths<T>>(options: DefineFieldOptions<PickProps<T, P>, P>) => FormField<PickProps<T, P>, P>;
|
|
24
|
-
getField: <P extends Paths<T>>(path: P) => FormField<PickProps<T, P>, P>;
|
|
25
|
-
isDirty: Ref<boolean>;
|
|
26
|
-
isTouched: Ref<boolean>;
|
|
27
|
-
defineValidator: <TData extends T>(options: ValidatorOptions<TData> | Ref< Validator<TData>, Validator<TData>>) => Ref< Validator<TData> | undefined, Validator<TData> | undefined>;
|
|
28
|
-
reset: () => void;
|
|
29
|
-
validateForm: () => Promise< ValidationResult>;
|
|
30
|
-
getSubForm: <P extends EntityPaths<T>>(path: P, options?: SubformOptions<PickEntity<T, P>> | undefined) => Form<PickEntity<T, P>>;
|
|
31
|
-
};
|
|
10
|
+
export declare function useForm<T extends FormDataDefault>(options: UseFormOptions<T>): Form<T>;
|
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Awaitable } from "@vueuse/core";
|
|
2
1
|
import {
|
|
3
2
|
computed,
|
|
4
3
|
reactive,
|
|
@@ -17,8 +16,8 @@ import { cloneRefValue } from "../utils/general";
|
|
|
17
16
|
import { useFieldRegistry } from "./useFieldRegistry";
|
|
18
17
|
import { useFormState } from "./useFormState";
|
|
19
18
|
import { createSubformInterface, type SubformOptions } from "./useSubform";
|
|
20
|
-
import { useValidation, type ValidationOptions } from "./useValidation";
|
|
21
19
|
import { useSubmitHandler } from "./useSubmitHandler";
|
|
20
|
+
import { useValidation, type ValidationOptions } from "./useValidation";
|
|
22
21
|
|
|
23
22
|
export interface UseFormOptions<T extends FormDataDefault>
|
|
24
23
|
extends ValidationOptions<T> {
|
|
@@ -27,7 +26,9 @@ export interface UseFormOptions<T extends FormDataDefault>
|
|
|
27
26
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
export function useForm<T extends FormDataDefault>(
|
|
29
|
+
export function useForm<T extends FormDataDefault>(
|
|
30
|
+
options: UseFormOptions<T>,
|
|
31
|
+
): Form<T> {
|
|
31
32
|
const initialData = computed(() => cloneRefValue(options.initialData));
|
|
32
33
|
|
|
33
34
|
const data = ref<T>(cloneRefValue(initialData)) as Ref<T>;
|