@teamnovu/kit-vue-forms 0.0.3 → 0.0.4
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/useFieldRegistry.d.ts +5 -1
- package/dist/composables/useValidation.d.ts +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/types/form.d.ts +0 -4
- package/package.json +1 -1
- package/src/components/Field.vue +23 -0
- package/src/composables/useFieldRegistry.ts +6 -1
- package/src/composables/useForm.ts +2 -0
- package/src/index.ts +4 -1
- package/src/types/form.ts +0 -5
- package/src/types/validation.ts +1 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { FormDataDefault, FormField
|
|
1
|
+
import { FormDataDefault, FormField } from '../types/form';
|
|
2
2
|
import { Paths, PickProps } from '../types/util';
|
|
3
3
|
import { UseFieldOptions } from './useField';
|
|
4
4
|
type FieldRegistryCache<T> = Record<Paths<T>, FormField<any, string>>;
|
|
5
5
|
export type ResolvedFormField<T, K extends Paths<T>> = FormField<PickProps<T, K>, K>;
|
|
6
6
|
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>, 'path' | 'type' | 'required'>;
|
|
7
|
+
interface FormState<T extends FormDataDefault, TIn extends FormDataDefault = T> {
|
|
8
|
+
data: T;
|
|
9
|
+
initialData: TIn;
|
|
10
|
+
}
|
|
7
11
|
export declare function useFieldRegistry<T extends FormDataDefault>(formState: FormState<T>): {
|
|
8
12
|
fields: FieldRegistryCache<T>;
|
|
9
13
|
getField: <K extends Paths<T>>(path: K) => ResolvedFormField<T, K> | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MaybeRef, Ref, ComputedRef } from 'vue';
|
|
2
2
|
import { default as z } from 'zod';
|
|
3
3
|
import { FormDataDefault } from '../types/form';
|
|
4
|
-
import { ErrorBag, ValidationFunction, ValidationResult, Validator
|
|
4
|
+
import { ErrorBag, ValidationFunction, ValidationResult, Validator } from '../types/validation';
|
|
5
|
+
import { ValidationErrors } from '..';
|
|
5
6
|
export interface ValidatorOptions<T> {
|
|
6
7
|
schema?: MaybeRef<z.ZodType>;
|
|
7
8
|
validateFn?: MaybeRef<ValidationFunction<T>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ export { useForm } from './composables/useForm';
|
|
|
2
2
|
export type { UseFormOptions } from './composables/useForm';
|
|
3
3
|
export { useField } from './composables/useField';
|
|
4
4
|
export type { UseFieldOptions } from './composables/useField';
|
|
5
|
-
export type { ValidationStrategy, ValidationErrorMessage as ErrorMessage, ValidationResult, ErrorBag } from './types/validation';
|
|
5
|
+
export type { ValidationStrategy, ValidationErrorMessage as ErrorMessage, ValidationResult, ErrorBag, Validator, ValidationFunction, ValidationErrors } from './types/validation';
|
|
6
6
|
export type { DeepPartial } from './utils/type-helpers';
|
|
7
|
+
export type { Form, FormField } from './types/form';
|
|
8
|
+
export type { SplitPath, Paths, PickProps } from './types/util';
|
package/dist/types/form.d.ts
CHANGED
|
@@ -5,10 +5,6 @@ import { EntityPaths, Paths, PickEntity, PickProps } from './util';
|
|
|
5
5
|
import { ErrorBag, ValidationErrorMessage, ValidationErrors, ValidationResult, Validator } from './validation';
|
|
6
6
|
import { ValidatorOptions } from '../composables/useValidation';
|
|
7
7
|
export type FormDataDefault = object;
|
|
8
|
-
export interface FormState<T extends FormDataDefault, TIn extends FormDataDefault = T> {
|
|
9
|
-
data: T;
|
|
10
|
-
initialData: TIn;
|
|
11
|
-
}
|
|
12
8
|
export interface FormField<T, P extends string> {
|
|
13
9
|
data: Ref<T>;
|
|
14
10
|
path: Ref<P>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<slot v-bind="field" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script
|
|
6
|
+
setup lang="ts"
|
|
7
|
+
generic="TPath extends Paths<TData>, TData extends object"
|
|
8
|
+
>
|
|
9
|
+
import type { Form } from '../types/form.ts'
|
|
10
|
+
import type { Paths, PickProps } from '../types/util.ts'
|
|
11
|
+
import type { UseFieldOptions } from '../composables/useField.ts'
|
|
12
|
+
|
|
13
|
+
export interface FieldProps<TPath extends string, TData extends object> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
|
|
14
|
+
form: Form<TData>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const props = defineProps<FieldProps<TPath, TData>>()
|
|
18
|
+
|
|
19
|
+
const field = props.form.defineField({
|
|
20
|
+
path: props.path,
|
|
21
|
+
required: props.required,
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, toRef, unref } from 'vue'
|
|
2
|
-
import type { FormDataDefault, FormField
|
|
2
|
+
import type { FormDataDefault, FormField } from '../types/form'
|
|
3
3
|
import type { Paths, PickProps } from '../types/util'
|
|
4
4
|
import { getLens, getNestedValue } from '../utils/path'
|
|
5
5
|
import { useField, type UseFieldOptions } from './useField'
|
|
@@ -11,6 +11,11 @@ export type ResolvedFormField<T, K extends Paths<T>> = FormField<PickProps<T, K>
|
|
|
11
11
|
|
|
12
12
|
export type DefineFieldOptions<F, K extends string> = Pick<UseFieldOptions<F, K>, 'path' | 'type' | 'required'>
|
|
13
13
|
|
|
14
|
+
interface FormState<T extends FormDataDefault, TIn extends FormDataDefault = T> {
|
|
15
|
+
data: T
|
|
16
|
+
initialData: TIn
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
export function useFieldRegistry<T extends FormDataDefault>(
|
|
15
20
|
formState: FormState<T>,
|
|
16
21
|
) {
|
|
@@ -8,6 +8,8 @@ import { useFormState } from './useFormState'
|
|
|
8
8
|
import { createSubformInterface, type SubformOptions } from './useSubform'
|
|
9
9
|
import { useValidation, type ValidationOptions } from './useValidation'
|
|
10
10
|
|
|
11
|
+
// TODO @Elias implement validation strategy handling
|
|
12
|
+
|
|
11
13
|
export interface UseFormOptions<T extends FormDataDefault> extends ValidationOptions<T> {
|
|
12
14
|
initialData: MaybeRefOrGetter<T>
|
|
13
15
|
validationStrategy?: MaybeRef<ValidationStrategy>
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,8 @@ export { useField } from './composables/useField'
|
|
|
7
7
|
export type { UseFieldOptions } from './composables/useField'
|
|
8
8
|
|
|
9
9
|
// Types
|
|
10
|
-
export type { ValidationStrategy, ValidationErrorMessage as ErrorMessage, ValidationResult, ErrorBag } from './types/validation'
|
|
10
|
+
export type { ValidationStrategy, ValidationErrorMessage as ErrorMessage, ValidationResult, ErrorBag, Validator, ValidationFunction, ValidationErrors } from './types/validation'
|
|
11
11
|
export type { DeepPartial } from './utils/type-helpers'
|
|
12
|
+
|
|
13
|
+
export type { Form, FormField } from './types/form'
|
|
14
|
+
export type { SplitPath, Paths, PickProps } from './types/util'
|
package/src/types/form.ts
CHANGED
|
@@ -7,11 +7,6 @@ import type { ValidatorOptions } from '../composables/useValidation'
|
|
|
7
7
|
|
|
8
8
|
export type FormDataDefault = object
|
|
9
9
|
|
|
10
|
-
export interface FormState<T extends FormDataDefault, TIn extends FormDataDefault = T> {
|
|
11
|
-
data: T
|
|
12
|
-
initialData: TIn
|
|
13
|
-
}
|
|
14
|
-
|
|
15
10
|
export interface FormField<T, P extends string> {
|
|
16
11
|
data: Ref<T>
|
|
17
12
|
path: Ref<P>
|