@teamnovu/kit-vue-forms 0.2.4 → 0.2.6

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.
@@ -3,11 +3,11 @@ import { Paths, PickProps } from '../types/util.ts';
3
3
  import { UseFieldOptions } from '../composables/useField.ts';
4
4
  import { VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, VNode } from 'vue';
5
5
  import { ValidationErrors, ErrorMessage } from '../index.js';
6
- export interface FieldProps<TData extends object, TPath extends string> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
7
- form: Form<TData>;
6
+ export interface FieldProps<TData extends object, TPath extends string, TDataOut = TData> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
7
+ form: Form<TData, TDataOut>;
8
8
  }
9
- declare const _default: <TData extends object, TPath extends Paths<TData>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
10
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FieldProps<TData, TPath> & Partial<{}>> & PublicProps;
9
+ declare const _default: <TData extends object, TPath extends Paths<TData>, TDataOut = TData>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
10
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FieldProps<TData, TPath, TDataOut> & Partial<{}>> & PublicProps;
11
11
  expose(exposed: ShallowUnwrapRef<{}>): void;
12
12
  attrs: any;
13
13
  slots: {
@@ -1,15 +1,15 @@
1
1
  import { Component, VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, VNode } from 'vue';
2
2
  import { ComponentProps } from 'vue-component-type-helpers';
3
3
  import { Paths } from '../types/util.ts';
4
- import { Form } from '../types/form.ts';
5
- export interface FormFieldWrapperProps<TData extends object, TPath extends string, TComponent> {
4
+ import { Form, FormDataDefault } from '../types/form.ts';
5
+ export interface FormFieldWrapperProps<TForm extends Form<FormDataDefault, unknown>, TPath extends string, TComponent> {
6
6
  component: TComponent;
7
7
  componentProps: Omit<ComponentProps<TComponent>, 'modelValue' | 'update:modelValue' | 'errors'>;
8
- form: Form<TData>;
8
+ form: TForm;
9
9
  path: TPath;
10
10
  }
11
- declare const _default: <TData extends object, TPath extends Paths<TData>, TComponent extends Component>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
12
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FormFieldWrapperProps<TData, TPath, TComponent> & Partial<{}>> & PublicProps;
11
+ declare const _default: <TForm extends Form<FormDataDefault, unknown>, TPath extends Paths<TForm extends Form<infer Data> ? Data : never>, TComponent extends Component>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
12
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FormFieldWrapperProps<TForm, TPath, TComponent> & Partial<{}>> & PublicProps;
13
13
  expose(exposed: ShallowUnwrapRef<{}>): void;
14
14
  attrs: any;
15
15
  slots: Partial<Record<number, (_: any) => any>> & {
@@ -1,12 +1,12 @@
1
1
  import { Form } from '../types/form.ts';
2
2
  import { EntityPaths, PickEntity } from '../types/util.ts';
3
3
  import { VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, VNode } from 'vue';
4
- export interface FormPartProps<TData extends object, TPath> {
5
- form: Form<TData>;
4
+ export interface FormPartProps<TData extends object, TPath, TDataOut = TData> {
5
+ form: Form<TData, TDataOut>;
6
6
  path: TPath;
7
7
  }
8
- declare const _default: <TData extends object, TPath extends EntityPaths<TData>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
9
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FormPartProps<TData, TPath> & Partial<{}>> & PublicProps;
8
+ declare const _default: <TData extends object, TPath extends EntityPaths<TData>, TDataOut = TData>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
9
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FormPartProps<TData, TPath, TDataOut> & Partial<{}>> & PublicProps;
10
10
  expose(exposed: ShallowUnwrapRef<{}>): void;
11
11
  attrs: any;
12
12
  slots: {
@@ -9,7 +9,7 @@ export interface UseFormOptions<T extends FormDataDefault, TOut = T> extends Val
9
9
  keepValuesOnUnmount?: MaybeRef<boolean>;
10
10
  }
11
11
  export declare function useForm<T extends FormDataDefault, TOut = T>(options: UseFormOptions<T, TOut> & {
12
- schema: MaybeRef<z.ZodType<TOut, T>>;
12
+ schema: MaybeRef<z.ZodType<TOut, unknown>>;
13
13
  }): Form<T, TOut>;
14
14
  export declare function useForm<T extends FormDataDefault>(options: Omit<UseFormOptions<T, T>, 'schema'> & {
15
15
  schema?: undefined;
@@ -4,7 +4,7 @@ import { FormDataDefault } from '../types/form';
4
4
  import { ErrorBag, ValidationFunction, ValidationResult, Validator } from '../types/validation';
5
5
  import { ValidationErrors } from '..';
6
6
  export interface ValidatorOptions<T, TOut = T> {
7
- schema?: MaybeRef<z.ZodType<TOut, T> | undefined>;
7
+ schema?: MaybeRef<z.ZodType<TOut, unknown> | undefined>;
8
8
  validateFn?: MaybeRef<ValidationFunction<T, TOut> | undefined>;
9
9
  }
10
10
  export interface ValidationOptions<T, TOut = T> extends ValidatorOptions<T, TOut> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-vue-forms",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -4,18 +4,22 @@
4
4
 
5
5
  <script
6
6
  setup lang="ts"
7
- generic="TData extends object, TPath extends Paths<TData>"
7
+ generic="TData extends object, TPath extends Paths<TData>, TDataOut = TData"
8
8
  >
9
9
  import { reactive } from 'vue'
10
10
  import type { Form } from '../types/form.ts'
11
11
  import type { Paths, PickProps } from '../types/util.ts'
12
12
  import type { UseFieldOptions } from '../composables/useField.ts'
13
13
 
14
- export interface FieldProps<TData extends object, TPath extends string> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
15
- form: Form<TData>
14
+ export interface FieldProps<
15
+ TData extends object,
16
+ TPath extends string,
17
+ TDataOut = TData,
18
+ > extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
19
+ form: Form<TData, TDataOut>
16
20
  }
17
21
 
18
- const props = defineProps<FieldProps<TData, TPath>>()
22
+ const props = defineProps<FieldProps<TData, TPath, TDataOut>>()
19
23
 
20
24
  const field = props.form.defineField({
21
25
  path: props.path,
@@ -28,17 +28,25 @@
28
28
  <script
29
29
  setup
30
30
  lang="ts"
31
- generic="TData extends object, TPath extends Paths<TData>, TComponent extends Component"
31
+ generic="
32
+ TForm extends Form<FormDataDefault, unknown>,
33
+ TPath extends Paths<TForm extends Form<infer Data> ? Data : never>,
34
+ TComponent extends Component
35
+ "
32
36
  >
33
37
  import { type Component } from 'vue'
34
38
  import type { ComponentProps } from 'vue-component-type-helpers'
35
39
  import type { Paths } from '../types/util.ts'
36
- import type { Form } from '../types/form.ts'
40
+ import type { Form, FormDataDefault } from '../types/form.ts'
37
41
 
38
- export interface FormFieldWrapperProps<TData extends object, TPath extends string, TComponent> {
42
+ export interface FormFieldWrapperProps<
43
+ TForm extends Form<FormDataDefault, unknown>,
44
+ TPath extends string,
45
+ TComponent,
46
+ > {
39
47
  component: TComponent
40
48
  componentProps: Omit<ComponentProps<TComponent>, 'modelValue' | 'update:modelValue' | 'errors'>
41
- form: Form<TData>
49
+ form: TForm
42
50
  path: TPath
43
51
  }
44
52
 
@@ -46,5 +54,5 @@ defineOptions({
46
54
  inheritAttrs: false,
47
55
  })
48
56
 
49
- defineProps<FormFieldWrapperProps<TData, TPath, TComponent>>()
57
+ defineProps<FormFieldWrapperProps<TForm, TPath, TComponent>>()
50
58
  </script>
@@ -5,18 +5,18 @@
5
5
  <script
6
6
  setup
7
7
  lang="ts"
8
- generic="TData extends object, TPath extends EntityPaths<TData>"
8
+ generic="TData extends object, TPath extends EntityPaths<TData>, TDataOut = TData"
9
9
  >
10
10
  import { computed } from 'vue'
11
11
  import type { Form } from '../types/form.ts'
12
12
  import type { EntityPaths } from '../types/util.ts'
13
13
 
14
- export interface FormPartProps<TData extends object, TPath> {
15
- form: Form<TData>
14
+ export interface FormPartProps<TData extends object, TPath, TDataOut = TData> {
15
+ form: Form<TData, TDataOut>
16
16
  path: TPath
17
17
  }
18
18
 
19
- const props = defineProps<FormPartProps<TData, TPath>>()
19
+ const props = defineProps<FormPartProps<TData, TPath, TDataOut>>()
20
20
 
21
21
  const subform = computed(() => props.form.getSubForm(props.path))
22
22
  </script>
@@ -33,7 +33,7 @@ export interface UseFormOptions<T extends FormDataDefault, TOut = T>
33
33
  export function useForm<
34
34
  T extends FormDataDefault,
35
35
  TOut = T,
36
- >(options: UseFormOptions<T, TOut> & { schema: MaybeRef<z.ZodType<TOut, T>> }): Form<T, TOut>
36
+ >(options: UseFormOptions<T, TOut> & { schema: MaybeRef<z.ZodType<TOut, unknown>> }): Form<T, TOut>
37
37
 
38
38
  // Overload: without schema - infer types from initialData
39
39
  export function useForm<T extends FormDataDefault>(
@@ -6,7 +6,7 @@ import { hasErrors, isValidResult, mergeErrors } from '../utils/validation'
6
6
  import { flattenError } from '../utils/zod'
7
7
 
8
8
  export interface ValidatorOptions<T, TOut = T> {
9
- schema?: MaybeRef<z.ZodType<TOut, T> | undefined>
9
+ schema?: MaybeRef<z.ZodType<TOut, unknown> | undefined>
10
10
  validateFn?: MaybeRef<ValidationFunction<T, TOut> | undefined>
11
11
  }
12
12