@teamnovu/kit-vue-forms 0.1.16 → 0.1.18
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/FormPart.vue.d.ts +1 -1
- package/dist/composables/useFieldRegistry.d.ts +2 -2
- package/dist/composables/useForm.d.ts +25 -4
- package/dist/composables/useSubform.d.ts +2 -1
- package/dist/composables/useSubmitHandler.d.ts +8 -0
- package/dist/index.js +222 -214
- package/dist/types/form.d.ts +1 -1
- package/dist/utils/path.d.ts +1 -1
- package/package.json +2 -2
- package/src/composables/useFieldRegistry.ts +74 -74
- package/src/composables/useForm.ts +12 -28
- package/src/composables/useSubform.ts +112 -69
- package/src/composables/useSubmitHandler.ts +29 -0
- package/src/types/form.ts +1 -1
- package/src/utils/path.ts +41 -42
|
@@ -11,7 +11,7 @@ declare const _default: <TData extends object, TPath extends EntityPaths<TData>>
|
|
|
11
11
|
attrs: any;
|
|
12
12
|
slots: {
|
|
13
13
|
default?(_: {
|
|
14
|
-
subform: Form< PickEntity<TData, TPath
|
|
14
|
+
subform: Omit<Form< PickEntity<TData, TPath>>, "submitHandler">;
|
|
15
15
|
}): any;
|
|
16
16
|
};
|
|
17
17
|
emit: {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { Awaitable } from '@vueuse/core';
|
|
1
2
|
import { MaybeRef, ComputedRef } from 'vue';
|
|
2
3
|
import { FieldsTuple, FormDataDefault, FormField } from '../types/form';
|
|
3
4
|
import { Paths, PickProps } from '../types/util';
|
|
4
5
|
import { UseFieldOptions } from './useField';
|
|
5
6
|
import { ValidationState } from './useValidation';
|
|
6
|
-
import { Awaitable } from '@vueuse/core';
|
|
7
7
|
export type ResolvedFormField<T, K extends Paths<T>> = FormField<PickProps<T, K>, K>;
|
|
8
|
-
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>,
|
|
8
|
+
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>, "path"> & {
|
|
9
9
|
onBlur?: () => void;
|
|
10
10
|
onFocus?: () => void;
|
|
11
11
|
};
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Awaitable } from '@vueuse/core';
|
|
2
|
+
import { MaybeRef, MaybeRefOrGetter, Ref } from 'vue';
|
|
3
|
+
import { Form, FormDataDefault, FieldsTuple } from '../types/form';
|
|
4
|
+
import { EntityPaths, PickEntity } from '../types/util';
|
|
3
5
|
import { ValidationStrategy } from '../types/validation';
|
|
4
|
-
import {
|
|
6
|
+
import { SubformOptions } from './useSubform';
|
|
7
|
+
import { ValidationOptions, ValidatorOptions } from './useValidation';
|
|
8
|
+
import { ErrorBag, Paths, PickProps, FormField, Validator, ValidationResult } from '..';
|
|
9
|
+
import { DefineFieldOptions } from './useFieldRegistry';
|
|
5
10
|
export interface UseFormOptions<T extends FormDataDefault> extends ValidationOptions<T> {
|
|
6
11
|
initialData: MaybeRefOrGetter<T>;
|
|
7
12
|
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
8
13
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
9
14
|
}
|
|
10
|
-
export declare function useForm<T extends FormDataDefault>(options: UseFormOptions<T>):
|
|
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) => Omit<Form<PickEntity<T, P>>, "submitHandler">;
|
|
31
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Form, FormDataDefault } from '../types/form';
|
|
2
2
|
import { EntityPaths, PickEntity } from '../types/util';
|
|
3
|
+
import { UseFormOptions } from './useForm';
|
|
3
4
|
export interface SubformOptions<_T extends FormDataDefault> {
|
|
4
5
|
}
|
|
5
|
-
export declare function createSubformInterface<T extends FormDataDefault, K extends EntityPaths<T>>(mainForm: Form<T>, path: K, _options?: SubformOptions<PickEntity<T, K>>): Form<PickEntity<T, K>>;
|
|
6
|
+
export declare function createSubformInterface<T extends FormDataDefault, K extends EntityPaths<T>>(mainForm: Omit<Form<T>, "submitHandler">, path: K, formOptions?: UseFormOptions<T>, _options?: SubformOptions<PickEntity<T, K>>): Form<PickEntity<T, K>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Awaitable, MaybeRef } from '@vueuse/core';
|
|
2
|
+
import { Form, FormDataDefault } from '../types/form';
|
|
3
|
+
import { ValidationStrategy } from '../types/validation';
|
|
4
|
+
interface SubmitHandlerOptions {
|
|
5
|
+
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSubmitHandler<T extends FormDataDefault>(form: Omit<Form<T>, 'submitHandler'>, options: SubmitHandlerOptions): (onSubmit: (data: T) => Awaitable<void>) => (event: SubmitEvent) => Promise<void>;
|
|
8
|
+
export {};
|