@volverjs/form-vue 1.0.0-beta.21 → 1.0.0-beta.22

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.
@@ -121,7 +121,7 @@ export declare function defineFormField<Schema extends FormSchema>(formProvideKe
121
121
  formErrors?: DeepReadonly<inferFormattedError<Schema, string>>;
122
122
  invalid: boolean;
123
123
  invalidLabel: string;
124
- modelValue: any;
124
+ modelValue: unknown;
125
125
  onUpdate: (value: unknown) => void;
126
126
  readonly: boolean;
127
127
  submit?: InjectedFormData<Schema>["submit"];
package/dist/index.d.ts CHANGED
@@ -223,7 +223,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
223
223
  formErrors?: import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined;
224
224
  invalid: boolean;
225
225
  invalidLabel: string;
226
- modelValue: any;
226
+ modelValue: unknown;
227
227
  onUpdate: (value: unknown) => void;
228
228
  readonly: boolean;
229
229
  submit?: InjectedFormData<Schema_1>["submit"];
@@ -575,7 +575,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
575
575
  } | undefined;
576
576
  invalid: boolean;
577
577
  invalidLabel: string;
578
- modelValue: any;
578
+ modelValue: unknown;
579
579
  onUpdate: (value: unknown) => void;
580
580
  readonly: boolean;
581
581
  submit?: InjectedFormData<Schema_1>["submit"];
@@ -934,7 +934,7 @@ export declare function formFactory<Schema extends FormSchema>(schema: Schema, o
934
934
  formErrors?: import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined;
935
935
  invalid: boolean;
936
936
  invalidLabel: string;
937
- modelValue: any;
937
+ modelValue: unknown;
938
938
  onUpdate: (value: unknown) => void;
939
939
  readonly: boolean;
940
940
  submit?: InjectedFormData<Schema_1>["submit"];
package/dist/types.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { Component, DeepReadonly, Ref, RendererElement, RendererNode, VNode, WatchStopHandle } from 'vue';
2
- import { z } from 'zod';
2
+ import { z, AnyZodObject, ZodEffects, ZodOptional, ZodTypeAny } from 'zod';
3
3
  import { IgnoredUpdater } from '@vueuse/core';
4
4
  import { FormFieldType, FormStatus } from './enums';
5
- export type FormSchema = z.AnyZodObject | z.ZodEffects<z.AnyZodObject> | z.ZodEffects<z.ZodEffects<z.AnyZodObject>>;
5
+ type Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
6
+ type DecrementDepth<D extends Depth[number]> = Depth[D];
7
+ export type EffectType<T extends ZodTypeAny, D extends Depth[number] = 10> = D extends 0 ? T : T | ZodOptional<T> | ZodEffects<EffectType<T, DecrementDepth<D>>>;
8
+ export type FormSchema = EffectType<AnyZodObject>;
6
9
  export type FormFieldComponentOptions = {
7
10
  lazyLoad?: boolean;
8
11
  sideEffects?: (type: `${FormFieldType}`) => Promise<void> | void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@volverjs/form-vue",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.21",
4
+ "version": "1.0.0-beta.22",
5
5
  "description": "Vue 3 Forms with @volverjs/ui-vue",
6
6
  "author": "8 Wave S.r.l.",
7
7
  "license": "MIT",
@@ -57,23 +57,23 @@
57
57
  "zod": "^3.23.*"
58
58
  },
59
59
  "devDependencies": {
60
- "@antfu/eslint-config": "^3.7.3",
60
+ "@antfu/eslint-config": "^3.8.0",
61
61
  "@nabla/vite-plugin-eslint": "^2.0.4",
62
- "@playwright/experimental-ct-vue": "1.48.1",
62
+ "@playwright/experimental-ct-vue": "1.48.2",
63
63
  "@testing-library/vue": "^8.1.0",
64
64
  "@vitejs/plugin-vue": "^5.1.4",
65
- "@volverjs/style": "0.1.13",
65
+ "@volverjs/style": "0.1.14",
66
66
  "@vue/compiler-sfc": "^3.5.12",
67
67
  "@vue/runtime-core": "^3.5.12",
68
68
  "@vue/test-utils": "^2.4.6",
69
69
  "copy": "^0.3.2",
70
- "eslint": "^9.12.0",
70
+ "eslint": "^9.13.0",
71
71
  "happy-dom": "^15.7.4",
72
72
  "typescript": "^5.6.3",
73
- "vite": "^5.4.9",
74
- "vite-plugin-dts": "^4.2.4",
73
+ "vite": "^5.4.10",
74
+ "vite-plugin-dts": "^4.3.0",
75
75
  "vite-plugin-externalize-deps": "^0.8.0",
76
- "vitest": "^2.1.3"
76
+ "vitest": "^2.1.4"
77
77
  },
78
78
  "scripts": {
79
79
  "lint": "eslint .",
@@ -105,7 +105,7 @@ export function defineFormField<Schema extends FormSchema>(formProvideKey: Injec
105
105
  formErrors?: DeepReadonly<inferFormattedError<Schema, string>>
106
106
  invalid: boolean
107
107
  invalidLabel: string
108
- modelValue: any
108
+ modelValue: unknown
109
109
  onUpdate: (value: unknown) => void
110
110
  readonly: boolean
111
111
  submit?: InjectedFormData<Schema>['submit']
@@ -12,7 +12,7 @@ import {
12
12
  unref,
13
13
  } from 'vue'
14
14
  import type { FormSchema, InjectedFormData, FormTemplate, RenderFunctionOutput } from './types'
15
- import type { inferFormattedError, TypeOf, z } from 'zod'
15
+ import type { inferFormattedError, TypeOf } from 'zod'
16
16
  import type { FormStatus } from './enums'
17
17
 
18
18
  export function defineFormTemplate<Schema extends FormSchema>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, VvFormField: Component) {
package/src/types.ts CHANGED
@@ -1,12 +1,18 @@
1
1
  import type { Component, DeepReadonly, Ref, RendererElement, RendererNode, VNode, WatchStopHandle } from 'vue'
2
- import type { TypeOf, z } from 'zod'
2
+ import { z, type AnyZodObject, type ZodEffects, type ZodOptional, type ZodTypeAny } from 'zod'
3
3
  import type { IgnoredUpdater } from '@vueuse/core'
4
4
  import type { FormFieldType, FormStatus } from './enums'
5
5
 
6
- export type FormSchema =
7
- | z.AnyZodObject
8
- | z.ZodEffects<z.AnyZodObject>
9
- | z.ZodEffects<z.ZodEffects<z.AnyZodObject>>
6
+ type Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // Adjust the depth limit as needed
7
+
8
+ type DecrementDepth<D extends Depth[number]> = Depth[D]
9
+
10
+ export type EffectType<T extends ZodTypeAny, D extends Depth[number] = 10> =
11
+ D extends 0
12
+ ? T
13
+ : T | ZodOptional<T> | ZodEffects<EffectType<T, DecrementDepth<D>>>
14
+
15
+ export type FormSchema = EffectType<AnyZodObject>
10
16
 
11
17
  export type FormFieldComponentOptions = {
12
18
  lazyLoad?: boolean
package/src/utils.ts CHANGED
@@ -11,15 +11,11 @@ import {
11
11
  ZodRecord,
12
12
  ZodArray,
13
13
  } from 'zod'
14
- import type { FormSchema } from './types'
14
+ import type { EffectType, FormSchema } from './types'
15
15
 
16
16
  export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema, original: Partial<z.infer<Schema>> & Record<string, unknown> = {}): Partial<z.infer<Schema>> {
17
17
  const getSchemaInnerType = <Type extends ZodTypeAny>(
18
- schema:
19
- | Type
20
- | ZodEffects<Type>
21
- | ZodEffects<ZodEffects<Type>>
22
- | ZodOptional<Type>,
18
+ schema: EffectType<Type>,
23
19
  ) => {
24
20
  let toReturn = schema
25
21
  while (toReturn instanceof ZodEffects) {
@@ -48,9 +44,9 @@ export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema,
48
44
  }
49
45
  const innerType = getSchemaInnerType<AnyZodObject>(schema)
50
46
  const unknownKeys
51
- = innerType instanceof ZodObject
52
- ? innerType._def.unknownKeys === 'passthrough'
53
- : false
47
+ = innerType instanceof ZodObject
48
+ ? innerType._def.unknownKeys === 'passthrough'
49
+ : false
54
50
  return {
55
51
  ...(unknownKeys ? original : {}),
56
52
  ...Object.fromEntries(
@@ -94,7 +90,7 @@ export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema,
94
90
  (element && typeof element === 'object'
95
91
  ? element
96
92
  : undefined) as Partial<
97
- typeof arrayType
93
+ typeof arrayType
98
94
  >,
99
95
  ),
100
96
  ),
@@ -105,7 +101,7 @@ export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema,
105
101
  const valueType = getSchemaInnerType(innerType._def.valueType)
106
102
  if (valueType instanceof ZodObject) {
107
103
  return [key, Object.keys(originalValue).reduce((acc: Record<string, unknown>, recordKey: string) => {
108
- acc[recordKey] = defaultObjectBySchema(valueType, originalValue[recordKey])
104
+ acc[recordKey] = defaultObjectBySchema(valueType, (originalValue as Record<string, unknown>)[recordKey] as Partial<any> & Record<string, unknown>)
109
105
  return acc
110
106
  }, {})]
111
107
  }
@@ -117,7 +113,7 @@ export function defaultObjectBySchema<Schema extends FormSchema>(schema: Schema,
117
113
  innerType,
118
114
  originalValue
119
115
  && typeof originalValue === 'object'
120
- ? originalValue
116
+ ? (originalValue as Partial<z.infer<Schema>> & Record<string, unknown>)
121
117
  : defaultValue,
122
118
  ),
123
119
  ]