@volverjs/form-vue 0.0.10-beta.4 → 0.0.10-beta.5

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,5 +1,5 @@
1
- import { type InjectionKey, type Ref } from 'vue';
2
- import type { AnyZodObject, ZodEffects } from 'zod';
1
+ import { type InjectionKey, type Ref, type DeepReadonly } from 'vue';
2
+ import type { AnyZodObject, TypeOf, ZodEffects, z } from 'zod';
3
3
  import type { InjectedFormData, InjectedFormWrapperData } from './types';
4
4
  export declare const defineFormWrapper: <Schema extends AnyZodObject | ZodEffects<AnyZodObject, {
5
5
  [x: string]: any;
@@ -13,7 +13,105 @@ export declare const defineFormWrapper: <Schema extends AnyZodObject | ZodEffect
13
13
  [x: string]: any;
14
14
  }, {
15
15
  [x: string]: any;
16
- }>>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>) => import("vue").DefineComponent<{
16
+ }>>(formProvideKey: InjectionKey<InjectedFormData<Schema>>, wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>) => {
17
+ new (...args: any[]): {
18
+ $: import("vue").ComponentInternalInstance;
19
+ $data: {};
20
+ $props: Partial<{
21
+ tag: string;
22
+ }> & Omit<Readonly<import("vue").ExtractPropTypes<{
23
+ name: {
24
+ type: StringConstructor;
25
+ required: true;
26
+ };
27
+ tag: {
28
+ type: StringConstructor;
29
+ default: undefined;
30
+ };
31
+ }>> & {
32
+ onValid?: ((...args: any[]) => any) | undefined;
33
+ onInvalid?: ((...args: any[]) => any) | undefined;
34
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "tag">;
35
+ $attrs: {
36
+ [x: string]: unknown;
37
+ };
38
+ $refs: {
39
+ [x: string]: unknown;
40
+ };
41
+ $slots: Readonly<{
42
+ [name: string]: import("vue").Slot | undefined;
43
+ }>;
44
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
45
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
46
+ $emit: (event: "valid" | "invalid", ...args: any[]) => void;
47
+ $el: any;
48
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
49
+ name: {
50
+ type: StringConstructor;
51
+ required: true;
52
+ };
53
+ tag: {
54
+ type: StringConstructor;
55
+ default: undefined;
56
+ };
57
+ }>> & {
58
+ onValid?: ((...args: any[]) => any) | undefined;
59
+ onInvalid?: ((...args: any[]) => any) | undefined;
60
+ }, {
61
+ formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
62
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
63
+ invalid: import("vue").ComputedRef<boolean>;
64
+ fields: Ref<Set<string>>;
65
+ fieldsErrors: Ref<Map<string, Record<string, {
66
+ _errors: string[];
67
+ }>>>;
68
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], string, {
69
+ tag: string;
70
+ }, {}, string> & {
71
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
72
+ created?: ((() => void) | (() => void)[]) | undefined;
73
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
74
+ mounted?: ((() => void) | (() => void)[]) | undefined;
75
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
76
+ updated?: ((() => void) | (() => void)[]) | undefined;
77
+ activated?: ((() => void) | (() => void)[]) | undefined;
78
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
79
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
80
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
81
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
82
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
83
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
84
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
85
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void)[]) | undefined;
86
+ };
87
+ $forceUpdate: () => void;
88
+ $nextTick: typeof import("vue").nextTick;
89
+ $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
90
+ } & Readonly<import("vue").ExtractPropTypes<{
91
+ name: {
92
+ type: StringConstructor;
93
+ required: true;
94
+ };
95
+ tag: {
96
+ type: StringConstructor;
97
+ default: undefined;
98
+ };
99
+ }>> & {
100
+ onValid?: ((...args: any[]) => any) | undefined;
101
+ onInvalid?: ((...args: any[]) => any) | undefined;
102
+ } & import("vue").ShallowUnwrapRef<{
103
+ formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
104
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
105
+ invalid: import("vue").ComputedRef<boolean>;
106
+ fields: Ref<Set<string>>;
107
+ fieldsErrors: Ref<Map<string, Record<string, {
108
+ _errors: string[];
109
+ }>>>;
110
+ }> & {} & import("vue").ComponentCustomProperties & {};
111
+ __isFragment?: undefined;
112
+ __isTeleport?: undefined;
113
+ __isSuspense?: undefined;
114
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
17
115
  name: {
18
116
  type: StringConstructor;
19
117
  required: true;
@@ -22,26 +120,28 @@ export declare const defineFormWrapper: <Schema extends AnyZodObject | ZodEffect
22
120
  type: StringConstructor;
23
121
  default: undefined;
24
122
  };
123
+ }>> & {
124
+ onValid?: ((...args: any[]) => any) | undefined;
125
+ onInvalid?: ((...args: any[]) => any) | undefined;
25
126
  }, {
26
- formData: Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
27
- errors: Readonly<Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
127
+ formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
128
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
28
129
  invalid: import("vue").ComputedRef<boolean>;
29
130
  fields: Ref<Set<string>>;
30
131
  fieldsErrors: Ref<Map<string, Record<string, {
31
132
  _errors: string[];
32
133
  }>>>;
33
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
34
- name: {
35
- type: StringConstructor;
36
- required: true;
37
- };
38
- tag: {
39
- type: StringConstructor;
40
- default: undefined;
41
- };
42
- }>> & {
43
- onValid?: ((...args: any[]) => any) | undefined;
44
- onInvalid?: ((...args: any[]) => any) | undefined;
45
- }, {
134
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", {
46
135
  tag: string;
47
- }>;
136
+ }, {}, string> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
137
+ $slots: {
138
+ default: (_: {
139
+ invalid: boolean;
140
+ formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
141
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
142
+ fieldsErrors: Map<string, Record<string, {
143
+ _errors: string[];
144
+ }>>;
145
+ }) => any;
146
+ };
147
+ });
package/dist/index.d.ts CHANGED
@@ -46,7 +46,105 @@ export declare const formFactory: <Schema extends AnyZodObject | ZodEffects<AnyZ
46
46
  modelValue: Record<string, any>;
47
47
  continuosValidation: boolean;
48
48
  }>;
49
- VvFormWrapper: import("vue").DefineComponent<{
49
+ VvFormWrapper: {
50
+ new (...args: any[]): {
51
+ $: import("vue").ComponentInternalInstance;
52
+ $data: {};
53
+ $props: Partial<{
54
+ tag: string;
55
+ }> & Omit<Readonly<import("vue").ExtractPropTypes<{
56
+ name: {
57
+ type: StringConstructor;
58
+ required: true;
59
+ };
60
+ tag: {
61
+ type: StringConstructor;
62
+ default: undefined;
63
+ };
64
+ }>> & {
65
+ onValid?: ((...args: any[]) => any) | undefined;
66
+ onInvalid?: ((...args: any[]) => any) | undefined;
67
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "tag">;
68
+ $attrs: {
69
+ [x: string]: unknown;
70
+ };
71
+ $refs: {
72
+ [x: string]: unknown;
73
+ };
74
+ $slots: Readonly<{
75
+ [name: string]: import("vue").Slot | undefined;
76
+ }>;
77
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
78
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
79
+ $emit: (event: "valid" | "invalid", ...args: any[]) => void;
80
+ $el: any;
81
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
82
+ name: {
83
+ type: StringConstructor;
84
+ required: true;
85
+ };
86
+ tag: {
87
+ type: StringConstructor;
88
+ default: undefined;
89
+ };
90
+ }>> & {
91
+ onValid?: ((...args: any[]) => any) | undefined;
92
+ onInvalid?: ((...args: any[]) => any) | undefined;
93
+ }, {
94
+ formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
95
+ errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
96
+ invalid: import("vue").ComputedRef<boolean>;
97
+ fields: import("vue").Ref<Set<string>>;
98
+ fieldsErrors: import("vue").Ref<Map<string, Record<string, {
99
+ _errors: string[];
100
+ }>>>;
101
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], string, {
102
+ tag: string;
103
+ }, {}, string> & {
104
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
105
+ created?: ((() => void) | (() => void)[]) | undefined;
106
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
107
+ mounted?: ((() => void) | (() => void)[]) | undefined;
108
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
109
+ updated?: ((() => void) | (() => void)[]) | undefined;
110
+ activated?: ((() => void) | (() => void)[]) | undefined;
111
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
112
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
113
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
114
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
115
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
116
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
117
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
118
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void)[]) | undefined;
119
+ };
120
+ $forceUpdate: () => void;
121
+ $nextTick: typeof import("vue").nextTick;
122
+ $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
123
+ } & Readonly<import("vue").ExtractPropTypes<{
124
+ name: {
125
+ type: StringConstructor;
126
+ required: true;
127
+ };
128
+ tag: {
129
+ type: StringConstructor;
130
+ default: undefined;
131
+ };
132
+ }>> & {
133
+ onValid?: ((...args: any[]) => any) | undefined;
134
+ onInvalid?: ((...args: any[]) => any) | undefined;
135
+ } & import("vue").ShallowUnwrapRef<{
136
+ formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
137
+ errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
138
+ invalid: import("vue").ComputedRef<boolean>;
139
+ fields: import("vue").Ref<Set<string>>;
140
+ fieldsErrors: import("vue").Ref<Map<string, Record<string, {
141
+ _errors: string[];
142
+ }>>>;
143
+ }> & {} & import("vue").ComponentCustomProperties & {};
144
+ __isFragment?: undefined;
145
+ __isTeleport?: undefined;
146
+ __isSuspense?: undefined;
147
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
50
148
  name: {
51
149
  type: StringConstructor;
52
150
  required: true;
@@ -55,6 +153,9 @@ export declare const formFactory: <Schema extends AnyZodObject | ZodEffects<AnyZ
55
153
  type: StringConstructor;
56
154
  default: undefined;
57
155
  };
156
+ }>> & {
157
+ onValid?: ((...args: any[]) => any) | undefined;
158
+ onInvalid?: ((...args: any[]) => any) | undefined;
58
159
  }, {
59
160
  formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
60
161
  errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
@@ -63,21 +164,20 @@ export declare const formFactory: <Schema extends AnyZodObject | ZodEffects<AnyZ
63
164
  fieldsErrors: import("vue").Ref<Map<string, Record<string, {
64
165
  _errors: string[];
65
166
  }>>>;
66
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
67
- name: {
68
- type: StringConstructor;
69
- required: true;
70
- };
71
- tag: {
72
- type: StringConstructor;
73
- default: undefined;
74
- };
75
- }>> & {
76
- onValid?: ((...args: any[]) => any) | undefined;
77
- onInvalid?: ((...args: any[]) => any) | undefined;
78
- }, {
167
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", {
79
168
  tag: string;
80
- }>;
169
+ }, {}, string> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
170
+ $slots: {
171
+ default: (_: {
172
+ invalid: boolean;
173
+ formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
174
+ errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
175
+ fieldsErrors: Map<string, Record<string, {
176
+ _errors: string[];
177
+ }>>;
178
+ }) => any;
179
+ };
180
+ });
81
181
  VvFormField: import("vue").DefineComponent<{
82
182
  type: {
83
183
  type: import("vue").PropType<"number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetimeLocal" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom">;
@@ -208,7 +308,105 @@ export declare const useForm: <Schema extends AnyZodObject | ZodEffects<AnyZodOb
208
308
  modelValue: Record<string, any>;
209
309
  continuosValidation: boolean;
210
310
  }>;
211
- VvFormWrapper: import("vue").DefineComponent<{
311
+ VvFormWrapper: {
312
+ new (...args: any[]): {
313
+ $: import("vue").ComponentInternalInstance;
314
+ $data: {};
315
+ $props: Partial<{
316
+ tag: string;
317
+ }> & Omit<Readonly<import("vue").ExtractPropTypes<{
318
+ name: {
319
+ type: StringConstructor;
320
+ required: true;
321
+ };
322
+ tag: {
323
+ type: StringConstructor;
324
+ default: undefined;
325
+ };
326
+ }>> & {
327
+ onValid?: ((...args: any[]) => any) | undefined;
328
+ onInvalid?: ((...args: any[]) => any) | undefined;
329
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "tag">;
330
+ $attrs: {
331
+ [x: string]: unknown;
332
+ };
333
+ $refs: {
334
+ [x: string]: unknown;
335
+ };
336
+ $slots: Readonly<{
337
+ [name: string]: import("vue").Slot | undefined;
338
+ }>;
339
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
340
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null;
341
+ $emit: (event: "valid" | "invalid", ...args: any[]) => void;
342
+ $el: any;
343
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
344
+ name: {
345
+ type: StringConstructor;
346
+ required: true;
347
+ };
348
+ tag: {
349
+ type: StringConstructor;
350
+ default: undefined;
351
+ };
352
+ }>> & {
353
+ onValid?: ((...args: any[]) => any) | undefined;
354
+ onInvalid?: ((...args: any[]) => any) | undefined;
355
+ }, {
356
+ formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
357
+ errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
358
+ invalid: import("vue").ComputedRef<boolean>;
359
+ fields: import("vue").Ref<Set<string>>;
360
+ fieldsErrors: import("vue").Ref<Map<string, Record<string, {
361
+ _errors: string[];
362
+ }>>>;
363
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], string, {
364
+ tag: string;
365
+ }, {}, string> & {
366
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
367
+ created?: ((() => void) | (() => void)[]) | undefined;
368
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
369
+ mounted?: ((() => void) | (() => void)[]) | undefined;
370
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
371
+ updated?: ((() => void) | (() => void)[]) | undefined;
372
+ activated?: ((() => void) | (() => void)[]) | undefined;
373
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
374
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
375
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
376
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
377
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
378
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
379
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
380
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}> | null, info: string) => boolean | void)[]) | undefined;
381
+ };
382
+ $forceUpdate: () => void;
383
+ $nextTick: typeof import("vue").nextTick;
384
+ $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
385
+ } & Readonly<import("vue").ExtractPropTypes<{
386
+ name: {
387
+ type: StringConstructor;
388
+ required: true;
389
+ };
390
+ tag: {
391
+ type: StringConstructor;
392
+ default: undefined;
393
+ };
394
+ }>> & {
395
+ onValid?: ((...args: any[]) => any) | undefined;
396
+ onInvalid?: ((...args: any[]) => any) | undefined;
397
+ } & import("vue").ShallowUnwrapRef<{
398
+ formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
399
+ errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
400
+ invalid: import("vue").ComputedRef<boolean>;
401
+ fields: import("vue").Ref<Set<string>>;
402
+ fieldsErrors: import("vue").Ref<Map<string, Record<string, {
403
+ _errors: string[];
404
+ }>>>;
405
+ }> & {} & import("vue").ComponentCustomProperties & {};
406
+ __isFragment?: undefined;
407
+ __isTeleport?: undefined;
408
+ __isSuspense?: undefined;
409
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
212
410
  name: {
213
411
  type: StringConstructor;
214
412
  required: true;
@@ -217,6 +415,9 @@ export declare const useForm: <Schema extends AnyZodObject | ZodEffects<AnyZodOb
217
415
  type: StringConstructor;
218
416
  default: undefined;
219
417
  };
418
+ }>> & {
419
+ onValid?: ((...args: any[]) => any) | undefined;
420
+ onInvalid?: ((...args: any[]) => any) | undefined;
220
421
  }, {
221
422
  formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
222
423
  errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
@@ -225,21 +426,20 @@ export declare const useForm: <Schema extends AnyZodObject | ZodEffects<AnyZodOb
225
426
  fieldsErrors: import("vue").Ref<Map<string, Record<string, {
226
427
  _errors: string[];
227
428
  }>>>;
228
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
229
- name: {
230
- type: StringConstructor;
231
- required: true;
232
- };
233
- tag: {
234
- type: StringConstructor;
235
- default: undefined;
236
- };
237
- }>> & {
238
- onValid?: ((...args: any[]) => any) | undefined;
239
- onInvalid?: ((...args: any[]) => any) | undefined;
240
- }, {
429
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid")[], "valid" | "invalid", {
241
430
  tag: string;
242
- }>;
431
+ }, {}, string> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
432
+ $slots: {
433
+ default: (_: {
434
+ invalid: boolean;
435
+ formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
436
+ errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
437
+ fieldsErrors: Map<string, Record<string, {
438
+ _errors: string[];
439
+ }>>;
440
+ }) => any;
441
+ };
442
+ });
243
443
  VvFormField: import("vue").DefineComponent<{
244
444
  type: {
245
445
  type: import("vue").PropType<"number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetimeLocal" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom">;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent as E, computed as V, onMounted as q, onBeforeUnmount as R, inject as S, toRefs as I, watch as y, provide as $, readonly as w, resolveComponent as h, defineAsyncComponent as H, h as x, ref as g, isProxy as Q, toRaw as X, withModifiers as Y } from "vue";
1
+ import { defineComponent as E, computed as b, onMounted as R, onBeforeUnmount as q, inject as S, toRefs as I, watch as y, provide as $, readonly as w, resolveComponent as p, defineAsyncComponent as H, h as x, ref as g, isProxy as Q, toRaw as X, withModifiers as Y } from "vue";
2
2
  import { watchThrottled as D } from "@vueuse/core";
3
3
  import { ZodObject as L, ZodDefault as T, ZodNullable as j, ZodSchema as F, ZodEffects as ee } from "zod";
4
4
  function O(e) {
@@ -20,57 +20,57 @@ function k(e) {
20
20
  return typeof e > "u";
21
21
  }
22
22
  const re = /^[0-9]+$/, ne = ["__proto__", "prototype", "constructor"];
23
- function A(e, o, a) {
24
- const s = te(a) ? a : void 0;
23
+ function A(e, o, s) {
24
+ const u = te(s) ? s : void 0;
25
25
  if (!W(e) || !_(o))
26
- return s;
27
- const r = K(o);
28
- if (r.length !== 0) {
29
- for (const t of r) {
26
+ return u;
27
+ const a = K(o);
28
+ if (a.length !== 0) {
29
+ for (const t of a) {
30
30
  if (t === "*")
31
31
  continue;
32
- const l = function(u) {
33
- return u.map((c) => k(c) || N(c) ? c : O(c) ? l(c) : c[t]);
32
+ const r = function(c) {
33
+ return c.map((l) => k(l) || N(l) ? l : O(l) ? r(l) : l[t]);
34
34
  };
35
- if (O(e) && !re.test(t) ? e = l(e) : e = e[t], k(e) || N(e))
35
+ if (O(e) && !re.test(t) ? e = r(e) : e = e[t], k(e) || N(e))
36
36
  break;
37
37
  }
38
- return k(e) ? s : e;
38
+ return k(e) ? u : e;
39
39
  }
40
40
  }
41
- function B(e, o, a) {
41
+ function B(e, o, s) {
42
42
  if (!W(e) || !_(o))
43
43
  return;
44
- const s = K(o);
45
- if (s.length === 0)
44
+ const u = K(o);
45
+ if (u.length === 0)
46
46
  return;
47
- const r = s.length;
48
- for (let t = 0; t < r; t++) {
49
- const l = s[t];
50
- if (t === r - 1) {
51
- e[l] = a;
47
+ const a = u.length;
48
+ for (let t = 0; t < a; t++) {
49
+ const r = u[t];
50
+ if (t === a - 1) {
51
+ e[r] = s;
52
52
  return;
53
53
  }
54
- if (l === "*" && O(e)) {
55
- const u = s.slice(t + 1).join(".");
56
- for (const c of e)
57
- B(c, u, a);
54
+ if (r === "*" && O(e)) {
55
+ const c = u.slice(t + 1).join(".");
56
+ for (const l of e)
57
+ B(l, c, s);
58
58
  return;
59
59
  }
60
- k(e[l]) && (e[l] = {}), e = e[l];
60
+ k(e[r]) && (e[r] = {}), e = e[r];
61
61
  }
62
62
  }
63
63
  function K(e) {
64
- const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((a) => !!a);
65
- return o.some((a) => ne.indexOf(a) !== -1) ? [] : o;
64
+ const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((s) => !!s);
65
+ return o.some((s) => ne.indexOf(s) !== -1) ? [] : o;
66
66
  }
67
67
  var i = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetimeLocal", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e))(i || {});
68
- const oe = (e, o, a, s = {}) => E({
68
+ const oe = (e, o, s, u = {}) => E({
69
69
  name: "FieldComponent",
70
70
  props: {
71
71
  type: {
72
72
  type: String,
73
- validator: (r) => Object.values(i).includes(r),
73
+ validator: (a) => Object.values(i).includes(a),
74
74
  default: i.custom
75
75
  },
76
76
  is: {
@@ -96,61 +96,61 @@ const oe = (e, o, a, s = {}) => E({
96
96
  },
97
97
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
98
98
  expose: ["invalid", "invalidLabel", "errors"],
99
- setup(r, { slots: t, emit: l }) {
100
- const u = V({
99
+ setup(a, { slots: t, emit: r }) {
100
+ const c = b({
101
101
  get() {
102
102
  if (n != null && n.modelValue)
103
103
  return A(
104
104
  Object(n.modelValue.value),
105
- String(r.name)
105
+ String(a.name)
106
106
  );
107
107
  },
108
108
  set(f) {
109
109
  n != null && n.modelValue && (B(
110
110
  Object(n.modelValue.value),
111
- String(r.name),
111
+ String(a.name),
112
112
  f
113
- ), l("update:modelValue", {
114
- newValue: u.value,
113
+ ), r("update:modelValue", {
114
+ newValue: c.value,
115
115
  formData: n == null ? void 0 : n.modelValue
116
116
  }));
117
117
  }
118
118
  });
119
- q(() => {
120
- u.value === void 0 && r.defaultValue !== void 0 && (u.value = r.defaultValue);
121
- }), R(() => {
119
+ R(() => {
120
+ c.value === void 0 && a.defaultValue !== void 0 && (c.value = a.defaultValue);
121
+ }), q(() => {
122
122
  J(), U();
123
123
  });
124
- const c = S(o, void 0);
125
- c && c.fields.value.add(r.name);
126
- const n = S(e), { props: v, name: m } = I(r), d = V(() => {
124
+ const l = S(o, void 0);
125
+ l && l.fields.value.add(a.name);
126
+ const n = S(e), { props: m, name: v } = I(a), d = b(() => {
127
127
  if (n != null && n.errors.value)
128
- return A(n.errors.value, String(r.name));
129
- }), p = V(() => {
128
+ return A(n.errors.value, String(a.name));
129
+ }), h = b(() => {
130
130
  var f;
131
131
  return (f = d.value) == null ? void 0 : f._errors;
132
- }), b = V(() => d.value !== void 0), J = y(b, () => {
133
- b.value ? (l("invalid", p.value), c && c.errors.value.set(
134
- r.name,
132
+ }), V = b(() => d.value !== void 0), J = y(V, () => {
133
+ V.value ? (r("invalid", h.value), l && l.errors.value.set(
134
+ a.name,
135
135
  {
136
- _errors: p.value
136
+ _errors: h.value
137
137
  }
138
- )) : (l("valid", u.value), c && c.errors.value.delete(
139
- r.name
138
+ )) : (r("valid", c.value), l && l.errors.value.delete(
139
+ a.name
140
140
  ));
141
141
  }), U = y(
142
142
  () => n == null ? void 0 : n.modelValue,
143
143
  () => {
144
- l("update:formData", n == null ? void 0 : n.modelValue);
144
+ r("update:formData", n == null ? void 0 : n.modelValue);
145
145
  },
146
146
  { deep: !0 }
147
147
  ), G = (f) => {
148
- u.value = f;
149
- }, C = V(() => typeof v.value == "function" ? v.value(n == null ? void 0 : n.modelValue) : v.value), z = V(() => ({
148
+ c.value = f;
149
+ }, C = b(() => typeof m.value == "function" ? m.value(n == null ? void 0 : n.modelValue) : m.value), z = b(() => ({
150
150
  ...C.value,
151
- name: C.value.name ?? r.name,
152
- invalid: b.value,
153
- valid: r.showValid ? !!(!b.value && u.value) : void 0,
151
+ name: C.value.name ?? a.name,
152
+ invalid: V.value,
153
+ valid: a.showValid ? !!(!V.value && c.value) : void 0,
154
154
  type: ((f) => {
155
155
  if ([
156
156
  i.text,
@@ -168,57 +168,57 @@ const oe = (e, o, a, s = {}) => E({
168
168
  i.color
169
169
  ].includes(f))
170
170
  return f;
171
- })(r.type),
172
- invalidLabel: p.value,
173
- modelValue: u.value,
174
- errors: r.is ? d.value : void 0,
171
+ })(a.type),
172
+ invalidLabel: h.value,
173
+ modelValue: c.value,
174
+ errors: a.is ? d.value : void 0,
175
175
  "onUpdate:modelValue": G
176
176
  }));
177
- return $(a, {
178
- name: w(m),
177
+ return $(s, {
178
+ name: w(v),
179
179
  errors: w(d)
180
- }), { component: V(() => {
181
- if (r.type === i.custom)
180
+ }), { component: b(() => {
181
+ if (a.type === i.custom)
182
182
  return {
183
183
  render() {
184
184
  var f;
185
185
  return ((f = t.default) == null ? void 0 : f.call(t, {
186
- modelValue: u.value,
186
+ modelValue: c.value,
187
187
  onUpdate: G,
188
- invalid: b.value,
189
- invalidLabel: p.value,
188
+ invalid: V.value,
189
+ invalidLabel: h.value,
190
190
  formData: n == null ? void 0 : n.modelValue.value,
191
191
  formErrors: n == null ? void 0 : n.errors.value,
192
192
  errors: d.value
193
193
  })) ?? t.defalut;
194
194
  }
195
195
  };
196
- if (!s.lazyLoad) {
196
+ if (!u.lazyLoad) {
197
197
  let f;
198
- switch (r.type) {
198
+ switch (a.type) {
199
199
  case i.select:
200
- f = h("VvSelect");
200
+ f = p("VvSelect");
201
201
  break;
202
202
  case i.checkbox:
203
- f = h("VvCheckbox");
203
+ f = p("VvCheckbox");
204
204
  break;
205
205
  case i.radio:
206
- f = h("VvRadio");
206
+ f = p("VvRadio");
207
207
  break;
208
208
  case i.textarea:
209
- f = h("VvTextarea");
209
+ f = p("VvTextarea");
210
210
  break;
211
211
  case i.radioGroup:
212
- f = h("VvRadioGroup");
212
+ f = p("VvRadioGroup");
213
213
  break;
214
214
  case i.checkboxGroup:
215
- f = h("VvCheckboxGroup");
215
+ f = p("VvCheckboxGroup");
216
216
  break;
217
217
  case i.combobox:
218
- f = h("VvCombobox");
218
+ f = p("VvCombobox");
219
219
  break;
220
220
  default:
221
- f = h("VvInputText");
221
+ f = p("VvInputText");
222
222
  }
223
223
  if (typeof f != "string")
224
224
  return f;
@@ -227,7 +227,7 @@ const oe = (e, o, a, s = {}) => E({
227
227
  );
228
228
  }
229
229
  return H(async () => {
230
- switch (s.sideEffects && await Promise.resolve(s.sideEffects(r.type)), r.type) {
230
+ switch (u.sideEffects && await Promise.resolve(u.sideEffects(a.type)), a.type) {
231
231
  case i.textarea:
232
232
  return import("@volverjs/ui-vue/vv-textarea");
233
233
  case i.radio:
@@ -243,46 +243,46 @@ const oe = (e, o, a, s = {}) => E({
243
243
  }
244
244
  return import("@volverjs/ui-vue/vv-input-text");
245
245
  });
246
- }), hasProps: z, invalid: b };
246
+ }), hasProps: z, invalid: V };
247
247
  },
248
248
  render() {
249
249
  return this.is ? x(this.is, this.hasProps, this.$slots) : this.type === i.custom ? x(this.component, null, this.$slots) : x(this.component, this.hasProps, this.$slots);
250
250
  }
251
251
  }), M = (e, o = {}) => {
252
- const a = (t) => {
253
- let l = t;
254
- for (; l instanceof ee; )
255
- l = l.innerType();
256
- return l;
257
- }, s = a(e);
252
+ const s = (t) => {
253
+ let r = t;
254
+ for (; r instanceof ee; )
255
+ r = r.innerType();
256
+ return r;
257
+ }, u = s(e);
258
258
  return {
259
- ...(s instanceof L ? s._def.unknownKeys === "passthrough" : !1) ? o : {},
259
+ ...(u instanceof L ? u._def.unknownKeys === "passthrough" : !1) ? o : {},
260
260
  ...Object.fromEntries(
261
- Object.entries(s.shape).map(([t, l]) => {
262
- const u = o[t], c = a(l);
261
+ Object.entries(u.shape).map(([t, r]) => {
262
+ const c = o[t], l = s(r);
263
263
  let n;
264
- if (c instanceof T && (n = c._def.defaultValue()), u === null && c instanceof j)
265
- return [t, u];
266
- if (c instanceof F) {
267
- const v = c.safeParse(o[t]);
268
- if (v.success)
269
- return [t, v.data ?? n];
264
+ if (l instanceof T && (n = l._def.defaultValue()), c === null && l instanceof j)
265
+ return [t, c];
266
+ if (l instanceof F) {
267
+ const m = l.safeParse(o[t]);
268
+ if (m.success)
269
+ return [t, m.data ?? n];
270
270
  }
271
- return c instanceof L ? [
271
+ return l instanceof L ? [
272
272
  t,
273
273
  M(
274
- c,
275
- u && typeof u == "object" ? u : {}
274
+ l,
275
+ c && typeof c == "object" ? c : {}
276
276
  )
277
277
  ] : [t, n];
278
278
  })
279
279
  )
280
280
  };
281
- }, ae = (e, o, a) => {
282
- const s = g(), r = g(), t = g();
281
+ }, ae = (e, o, s) => {
282
+ const u = g(), a = g(), t = g();
283
283
  return {
284
- errors: s,
285
- status: r,
284
+ errors: u,
285
+ status: a,
286
286
  formData: t,
287
287
  component: E({
288
288
  name: "FormComponent",
@@ -298,37 +298,37 @@ const oe = (e, o, a, s = {}) => E({
298
298
  },
299
299
  emits: ["invalid", "valid", "submit", "update:modelValue"],
300
300
  expose: ["submit", "errors", "status"],
301
- setup(l, { emit: u }) {
301
+ setup(r, { emit: c }) {
302
302
  t.value = M(
303
303
  e,
304
- l.modelValue
304
+ r.modelValue
305
305
  );
306
- const c = (a == null ? void 0 : a.continuosValidation) || l.continuosValidation;
306
+ const l = (s == null ? void 0 : s.continuosValidation) || r.continuosValidation;
307
307
  y(
308
- () => l.modelValue,
309
- (m) => {
310
- if (m) {
311
- const d = Q(m) ? X(m) : m;
308
+ () => r.modelValue,
309
+ (v) => {
310
+ if (v) {
311
+ const d = Q(v) ? X(v) : v;
312
312
  t.value = typeof (d == null ? void 0 : d.clone) == "function" ? d.clone() : JSON.parse(JSON.stringify(d));
313
313
  }
314
314
  },
315
315
  { deep: !0 }
316
316
  ), D(
317
317
  t,
318
- (m) => {
319
- (s.value || c) && n(), (!m || !l.modelValue || JSON.stringify(m) !== JSON.stringify(l.modelValue)) && u("update:modelValue", m);
318
+ (v) => {
319
+ (u.value || l) && n(), (!v || !r.modelValue || JSON.stringify(v) !== JSON.stringify(r.modelValue)) && c("update:modelValue", v);
320
320
  },
321
- { deep: !0, throttle: (a == null ? void 0 : a.updateThrottle) ?? 500 }
321
+ { deep: !0, throttle: (s == null ? void 0 : s.updateThrottle) ?? 500 }
322
322
  );
323
- const n = (m = t.value) => {
324
- const d = e.safeParse(m);
325
- return d.success ? (s.value = void 0, r.value = "valid", t.value = d.data, u("update:modelValue", t.value), u("valid", d.data), !0) : (s.value = d.error.format(), r.value = "invalid", u("invalid", s.value), !1);
326
- }, v = () => n() ? (u("submit", t.value), !0) : !1;
323
+ const n = (v = t.value) => {
324
+ const d = e.safeParse(v);
325
+ return d.success ? (u.value = void 0, a.value = "valid", t.value = d.data, c("update:modelValue", t.value), c("valid", d.data), !0) : (u.value = d.error.format(), a.value = "invalid", c("invalid", u.value), !1);
326
+ }, m = () => n() ? (c("submit", t.value), !0) : !1;
327
327
  return $(o, {
328
328
  modelValue: t,
329
- submit: v,
330
- errors: w(s)
331
- }), { submit: v };
329
+ submit: m,
330
+ errors: w(u)
331
+ }), { submit: m };
332
332
  },
333
333
  render() {
334
334
  return x(
@@ -355,55 +355,55 @@ const oe = (e, o, a, s = {}) => E({
355
355
  },
356
356
  emits: ["invalid", "valid"],
357
357
  expose: ["fields", "invalid"],
358
- setup(a, { emit: s }) {
359
- const r = S(e), t = S(o, void 0), l = g(/* @__PURE__ */ new Set()), u = g(/* @__PURE__ */ new Map()), { name: c } = I(a);
358
+ setup(u, { emit: a }) {
359
+ const t = S(e), r = S(o, void 0), c = g(/* @__PURE__ */ new Set()), l = g(/* @__PURE__ */ new Map()), { name: n } = I(u);
360
360
  $(o, {
361
- name: w(c),
362
- errors: u,
363
- fields: l
361
+ name: w(n),
362
+ errors: l,
363
+ fields: c
364
364
  }), y(
365
- l,
365
+ c,
366
366
  (v) => {
367
- t != null && t.fields && v.forEach((m) => {
368
- t == null || t.fields.value.add(m);
367
+ r != null && r.fields && v.forEach((d) => {
368
+ r == null || r.fields.value.add(d);
369
369
  });
370
370
  },
371
371
  { deep: !0 }
372
372
  ), y(
373
- () => new Map(u.value),
374
- (v, m) => {
375
- t != null && t.errors && (Array.from(m.keys()).forEach((d) => {
376
- t.errors.value.delete(d);
377
- }), Array.from(v.keys()).forEach((d) => {
378
- const p = v.get(d);
379
- p && t.errors.value.set(d, p);
373
+ () => new Map(l.value),
374
+ (v, d) => {
375
+ r != null && r.errors && (Array.from(d.keys()).forEach((h) => {
376
+ r.errors.value.delete(h);
377
+ }), Array.from(v.keys()).forEach((h) => {
378
+ const V = v.get(h);
379
+ V && r.errors.value.set(h, V);
380
380
  }));
381
381
  },
382
382
  { deep: !0 }
383
383
  );
384
- const n = V(() => r != null && r.errors.value ? u.value.size > 0 : !1);
385
- return y(n, () => {
386
- n.value ? s("invalid") : s("valid");
384
+ const m = b(() => t != null && t.errors.value ? l.value.size > 0 : !1);
385
+ return y(m, () => {
386
+ m.value ? a("invalid") : a("valid");
387
387
  }), {
388
- formData: r == null ? void 0 : r.modelValue,
389
- errors: r == null ? void 0 : r.errors,
390
- invalid: n,
391
- fields: l,
392
- fieldsErrors: u
388
+ formData: t == null ? void 0 : t.modelValue,
389
+ errors: t == null ? void 0 : t.errors,
390
+ invalid: m,
391
+ fields: c,
392
+ fieldsErrors: l
393
393
  };
394
394
  },
395
395
  render() {
396
- var a, s, r, t;
396
+ var u, a, t, r;
397
397
  return this.tag ? x(
398
398
  this.tag,
399
399
  null,
400
- ((s = (a = this.$slots).default) == null ? void 0 : s.call(a, {
400
+ ((a = (u = this.$slots).default) == null ? void 0 : a.call(u, {
401
401
  invalid: this.invalid,
402
402
  formData: this.formData,
403
403
  errors: this.errors,
404
404
  fieldsErrors: this.fieldsErrors
405
405
  })) ?? this.$slots.defalut
406
- ) : ((t = (r = this.$slots).default) == null ? void 0 : t.call(r, {
406
+ ) : ((r = (t = this.$slots).default) == null ? void 0 : r.call(t, {
407
407
  invalid: this.invalid,
408
408
  formData: this.formData,
409
409
  errors: this.errors,
@@ -411,42 +411,42 @@ const oe = (e, o, a, s = {}) => E({
411
411
  })) ?? this.$slots.defalut;
412
412
  }
413
413
  }), P = (e, o = {}) => {
414
- const a = Symbol(), s = Symbol(), r = Symbol(), {
414
+ const s = Symbol(), u = Symbol(), a = Symbol(), {
415
415
  component: t,
416
- errors: l,
417
- status: u,
418
- formData: c
419
- } = ae(e, a, o), n = se(
420
- a,
421
- s
422
- ), v = oe(
423
- a,
416
+ errors: r,
417
+ status: c,
418
+ formData: l
419
+ } = ae(e, s, o), n = se(
424
420
  s,
425
- r,
421
+ u
422
+ ), m = oe(
423
+ s,
424
+ u,
425
+ a,
426
426
  o
427
427
  );
428
428
  return {
429
429
  VvForm: t,
430
430
  VvFormWrapper: n,
431
- VvFormField: v,
432
- formInjectionKey: a,
433
- formWrapperInjectionKey: s,
434
- formFieldInjectionKey: r,
435
- errors: l,
436
- status: u,
437
- formData: c
431
+ VvFormField: m,
432
+ formInjectionKey: s,
433
+ formWrapperInjectionKey: u,
434
+ formFieldInjectionKey: a,
435
+ errors: r,
436
+ status: c,
437
+ formData: l
438
438
  };
439
439
  }, Z = Symbol(), fe = (e) => {
440
440
  let o = {};
441
441
  return e.schema && (o = P(e.schema, e)), {
442
442
  ...o,
443
- install(a, { global: s = !1 } = {}) {
444
- a.provide(Z, e), s && (a.config.globalProperties.$vvForm = e, o != null && o.VvForm && a.component("VvForm", o.VvForm), o != null && o.VvFormWrapper && a.component("VvFormWrapper", o.VvFormWrapper), o != null && o.VvFormField && a.component("VvFormField", o.VvFormField));
443
+ install(s, { global: u = !1 } = {}) {
444
+ s.provide(Z, e), u && (s.config.globalProperties.$vvForm = e, o != null && o.VvForm && s.component("VvForm", o.VvForm), o != null && o.VvFormWrapper && s.component("VvFormWrapper", o.VvFormWrapper), o != null && o.VvFormField && s.component("VvFormField", o.VvFormField));
445
445
  }
446
446
  };
447
447
  }, de = (e, o = {}) => {
448
- const a = { ...S(Z, {}), ...o };
449
- return P(e, a);
448
+ const s = { ...S(Z, {}), ...o };
449
+ return P(e, s);
450
450
  };
451
451
  export {
452
452
  i as FormFieldType,
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(p,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],t):(p=typeof globalThis<"u"?globalThis:p||self,t(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,t,A,b){"use strict";function x(e){return Array.isArray(e)}function B(e){return typeof e<"u"}function O(e){return e===null}function C(e){return typeof e=="object"}function E(e){return typeof e=="string"}function g(e){return typeof e>"u"}const W=/^[0-9]+$/,_=["__proto__","prototype","constructor"];function $(e,a,s){const l=B(s)?s:void 0;if(!C(e)||!E(a))return l;const n=I(a);if(n.length!==0){for(const r of n){if(r==="*")continue;const u=function(c){return c.map(f=>g(f)||O(f)?f:x(f)?u(f):f[r])};if(x(e)&&!W.test(r)?e=u(e):e=e[r],g(e)||O(e))break}return g(e)?l:e}}function G(e,a,s){if(!C(e)||!E(a))return;const l=I(a);if(l.length===0)return;const n=l.length;for(let r=0;r<n;r++){const u=l[r];if(r===n-1){e[u]=s;return}if(u==="*"&&x(e)){const c=l.slice(r+1).join(".");for(const f of e)G(f,c,s);return}g(e[u])&&(e[u]={}),e=e[u]}}function I(e){const a=e.split(/[.]|(?:\[(\d|\*)\])/).filter(s=>!!s);return a.some(s=>_.indexOf(s)!==-1)?[]:a}var i=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(i||{});const K=(e,a,s,l={})=>t.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:n=>Object.values(i).includes(n),default:i.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(n,{slots:r,emit:u}){const c=t.computed({get(){if(o!=null&&o.modelValue)return $(Object(o.modelValue.value),String(n.name))},set(d){o!=null&&o.modelValue&&(G(Object(o.modelValue.value),String(n.name),d),u("update:modelValue",{newValue:c.value,formData:o==null?void 0:o.modelValue}))}});t.onMounted(()=>{c.value===void 0&&n.defaultValue!==void 0&&(c.value=n.defaultValue)}),t.onBeforeUnmount(()=>{U(),J()});const f=t.inject(a,void 0);f&&f.fields.value.add(n.name);const o=t.inject(e),{props:h,name:v}=t.toRefs(n),m=t.computed(()=>{if(o!=null&&o.errors.value)return $(o.errors.value,String(n.name))}),V=t.computed(()=>{var d;return(d=m.value)==null?void 0:d._errors}),y=t.computed(()=>m.value!==void 0),U=t.watch(y,()=>{y.value?(u("invalid",V.value),f&&f.errors.value.set(n.name,{_errors:V.value})):(u("valid",c.value),f&&f.errors.value.delete(n.name))}),J=t.watch(()=>o==null?void 0:o.modelValue,()=>{u("update:formData",o==null?void 0:o.modelValue)},{deep:!0}),L=d=>{c.value=d},N=t.computed(()=>typeof h.value=="function"?h.value(o==null?void 0:o.modelValue):h.value),R=t.computed(()=>({...N.value,name:N.value.name??n.name,invalid:y.value,valid:n.showValid?!!(!y.value&&c.value):void 0,type:(d=>{if([i.text,i.number,i.email,i.password,i.tel,i.url,i.search,i.date,i.time,i.datetimeLocal,i.month,i.week,i.color].includes(d))return d})(n.type),invalidLabel:V.value,modelValue:c.value,errors:n.is?m.value:void 0,"onUpdate:modelValue":L}));return t.provide(s,{name:t.readonly(v),errors:t.readonly(m)}),{component:t.computed(()=>{if(n.type===i.custom)return{render(){var d;return((d=r.default)==null?void 0:d.call(r,{modelValue:c.value,onUpdate:L,invalid:y.value,invalidLabel:V.value,formData:o==null?void 0:o.modelValue.value,formErrors:o==null?void 0:o.errors.value,errors:m.value}))??r.defalut}};if(!l.lazyLoad){let d;switch(n.type){case i.select:d=t.resolveComponent("VvSelect");break;case i.checkbox:d=t.resolveComponent("VvCheckbox");break;case i.radio:d=t.resolveComponent("VvRadio");break;case i.textarea:d=t.resolveComponent("VvTextarea");break;case i.radioGroup:d=t.resolveComponent("VvRadioGroup");break;case i.checkboxGroup:d=t.resolveComponent("VvCheckboxGroup");break;case i.combobox:d=t.resolveComponent("VvCombobox");break;default:d=t.resolveComponent("VvInputText")}if(typeof d!="string")return d;console.warn(`[form-vue warn]: ${d} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return t.defineAsyncComponent(async()=>{switch(l.sideEffects&&await Promise.resolve(l.sideEffects(n.type)),n.type){case i.textarea:return import("@volverjs/ui-vue/vv-textarea");case i.radio:return import("@volverjs/ui-vue/vv-radio");case i.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case i.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case i.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case i.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:R,invalid:y}},render(){return this.is?t.h(this.is,this.hasProps,this.$slots):this.type===i.custom?t.h(this.component,null,this.$slots):t.h(this.component,this.hasProps,this.$slots)}}),S=(e,a={})=>{const s=r=>{let u=r;for(;u instanceof b.ZodEffects;)u=u.innerType();return u},l=s(e);return{...(l instanceof b.ZodObject?l._def.unknownKeys==="passthrough":!1)?a:{},...Object.fromEntries(Object.entries(l.shape).map(([r,u])=>{const c=a[r],f=s(u);let o;if(f instanceof b.ZodDefault&&(o=f._def.defaultValue()),c===null&&f instanceof b.ZodNullable)return[r,c];if(f instanceof b.ZodSchema){const h=f.safeParse(a[r]);if(h.success)return[r,h.data??o]}return f instanceof b.ZodObject?[r,S(f,c&&typeof c=="object"?c:{})]:[r,o]}))}},M=(e,a,s)=>{const l=t.ref(),n=t.ref(),r=t.ref();return{errors:l,status:n,formData:r,component:t.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(u,{emit:c}){r.value=S(e,u.modelValue);const f=(s==null?void 0:s.continuosValidation)||u.continuosValidation;t.watch(()=>u.modelValue,v=>{if(v){const m=t.isProxy(v)?t.toRaw(v):v;r.value=typeof(m==null?void 0:m.clone)=="function"?m.clone():JSON.parse(JSON.stringify(m))}},{deep:!0}),A.watchThrottled(r,v=>{(l.value||f)&&o(),(!v||!u.modelValue||JSON.stringify(v)!==JSON.stringify(u.modelValue))&&c("update:modelValue",v)},{deep:!0,throttle:(s==null?void 0:s.updateThrottle)??500});const o=(v=r.value)=>{const m=e.safeParse(v);return m.success?(l.value=void 0,n.value="valid",r.value=m.data,c("update:modelValue",r.value),c("valid",m.data),!0):(l.value=m.error.format(),n.value="invalid",c("invalid",l.value),!1)},h=()=>o()?(c("submit",r.value),!0):!1;return t.provide(a,{modelValue:r,submit:h,errors:t.readonly(l)}),{submit:h}},render(){return t.h("form",{onSubmit:t.withModifiers(this.submit,["prevent"])},this.$slots)}})}},P=(e,a)=>t.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(s,{emit:l}){const n=t.inject(e),r=t.inject(a,void 0),u=t.ref(new Set),c=t.ref(new Map),{name:f}=t.toRefs(s);t.provide(a,{name:t.readonly(f),errors:c,fields:u}),t.watch(u,h=>{r!=null&&r.fields&&h.forEach(v=>{r==null||r.fields.value.add(v)})},{deep:!0}),t.watch(()=>new Map(c.value),(h,v)=>{r!=null&&r.errors&&(Array.from(v.keys()).forEach(m=>{r.errors.value.delete(m)}),Array.from(h.keys()).forEach(m=>{const V=h.get(m);V&&r.errors.value.set(m,V)}))},{deep:!0});const o=t.computed(()=>n!=null&&n.errors.value?c.value.size>0:!1);return t.watch(o,()=>{o.value?l("invalid"):l("valid")}),{formData:n==null?void 0:n.modelValue,errors:n==null?void 0:n.errors,invalid:o,fields:u,fieldsErrors:c}},render(){var s,l,n,r;return this.tag?t.h(this.tag,null,((l=(s=this.$slots).default)==null?void 0:l.call(s,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut):((r=(n=this.$slots).default)==null?void 0:r.call(n,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),k=(e,a={})=>{const s=Symbol(),l=Symbol(),n=Symbol(),{component:r,errors:u,status:c,formData:f}=M(e,s,a),o=P(s,l),h=K(s,l,n,a);return{VvForm:r,VvFormWrapper:o,VvFormField:h,formInjectionKey:s,formWrapperInjectionKey:l,formFieldInjectionKey:n,errors:u,status:c,formData:f}},w=Symbol(),Z=e=>{let a={};return e.schema&&(a=k(e.schema,e)),{...a,install(s,{global:l=!1}={}){s.provide(w,e),l&&(s.config.globalProperties.$vvForm=e,a!=null&&a.VvForm&&s.component("VvForm",a.VvForm),a!=null&&a.VvFormWrapper&&s.component("VvFormWrapper",a.VvFormWrapper),a!=null&&a.VvFormField&&s.component("VvFormField",a.VvFormField))}}},q=(e,a={})=>{const s={...t.inject(w,{}),...a};return k(e,s)};p.FormFieldType=i,p.createForm=Z,p.defaultObjectBySchema=S,p.formFactory=k,p.pluginInjectionKey=w,p.useForm=q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],t):(p=typeof globalThis<"u"?globalThis:p||self,t(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,t,A,y){"use strict";function x(e){return Array.isArray(e)}function B(e){return typeof e<"u"}function O(e){return e===null}function C(e){return typeof e=="object"}function E(e){return typeof e=="string"}function g(e){return typeof e>"u"}const W=/^[0-9]+$/,_=["__proto__","prototype","constructor"];function $(e,a,l){const i=B(l)?l:void 0;if(!C(e)||!E(a))return i;const s=I(a);if(s.length!==0){for(const r of s){if(r==="*")continue;const n=function(f){return f.map(c=>g(c)||O(c)?c:x(c)?n(c):c[r])};if(x(e)&&!W.test(r)?e=n(e):e=e[r],g(e)||O(e))break}return g(e)?i:e}}function G(e,a,l){if(!C(e)||!E(a))return;const i=I(a);if(i.length===0)return;const s=i.length;for(let r=0;r<s;r++){const n=i[r];if(r===s-1){e[n]=l;return}if(n==="*"&&x(e)){const f=i.slice(r+1).join(".");for(const c of e)G(c,f,l);return}g(e[n])&&(e[n]={}),e=e[n]}}function I(e){const a=e.split(/[.]|(?:\[(\d|\*)\])/).filter(l=>!!l);return a.some(l=>_.indexOf(l)!==-1)?[]:a}var u=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(u||{});const K=(e,a,l,i={})=>t.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:s=>Object.values(u).includes(s),default:u.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(s,{slots:r,emit:n}){const f=t.computed({get(){if(o!=null&&o.modelValue)return $(Object(o.modelValue.value),String(s.name))},set(d){o!=null&&o.modelValue&&(G(Object(o.modelValue.value),String(s.name),d),n("update:modelValue",{newValue:f.value,formData:o==null?void 0:o.modelValue}))}});t.onMounted(()=>{f.value===void 0&&s.defaultValue!==void 0&&(f.value=s.defaultValue)}),t.onBeforeUnmount(()=>{U(),J()});const c=t.inject(a,void 0);c&&c.fields.value.add(s.name);const o=t.inject(e),{props:v,name:h}=t.toRefs(s),m=t.computed(()=>{if(o!=null&&o.errors.value)return $(o.errors.value,String(s.name))}),V=t.computed(()=>{var d;return(d=m.value)==null?void 0:d._errors}),b=t.computed(()=>m.value!==void 0),U=t.watch(b,()=>{b.value?(n("invalid",V.value),c&&c.errors.value.set(s.name,{_errors:V.value})):(n("valid",f.value),c&&c.errors.value.delete(s.name))}),J=t.watch(()=>o==null?void 0:o.modelValue,()=>{n("update:formData",o==null?void 0:o.modelValue)},{deep:!0}),L=d=>{f.value=d},N=t.computed(()=>typeof v.value=="function"?v.value(o==null?void 0:o.modelValue):v.value),R=t.computed(()=>({...N.value,name:N.value.name??s.name,invalid:b.value,valid:s.showValid?!!(!b.value&&f.value):void 0,type:(d=>{if([u.text,u.number,u.email,u.password,u.tel,u.url,u.search,u.date,u.time,u.datetimeLocal,u.month,u.week,u.color].includes(d))return d})(s.type),invalidLabel:V.value,modelValue:f.value,errors:s.is?m.value:void 0,"onUpdate:modelValue":L}));return t.provide(l,{name:t.readonly(h),errors:t.readonly(m)}),{component:t.computed(()=>{if(s.type===u.custom)return{render(){var d;return((d=r.default)==null?void 0:d.call(r,{modelValue:f.value,onUpdate:L,invalid:b.value,invalidLabel:V.value,formData:o==null?void 0:o.modelValue.value,formErrors:o==null?void 0:o.errors.value,errors:m.value}))??r.defalut}};if(!i.lazyLoad){let d;switch(s.type){case u.select:d=t.resolveComponent("VvSelect");break;case u.checkbox:d=t.resolveComponent("VvCheckbox");break;case u.radio:d=t.resolveComponent("VvRadio");break;case u.textarea:d=t.resolveComponent("VvTextarea");break;case u.radioGroup:d=t.resolveComponent("VvRadioGroup");break;case u.checkboxGroup:d=t.resolveComponent("VvCheckboxGroup");break;case u.combobox:d=t.resolveComponent("VvCombobox");break;default:d=t.resolveComponent("VvInputText")}if(typeof d!="string")return d;console.warn(`[form-vue warn]: ${d} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return t.defineAsyncComponent(async()=>{switch(i.sideEffects&&await Promise.resolve(i.sideEffects(s.type)),s.type){case u.textarea:return import("@volverjs/ui-vue/vv-textarea");case u.radio:return import("@volverjs/ui-vue/vv-radio");case u.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case u.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case u.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case u.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:R,invalid:b}},render(){return this.is?t.h(this.is,this.hasProps,this.$slots):this.type===u.custom?t.h(this.component,null,this.$slots):t.h(this.component,this.hasProps,this.$slots)}}),S=(e,a={})=>{const l=r=>{let n=r;for(;n instanceof y.ZodEffects;)n=n.innerType();return n},i=l(e);return{...(i instanceof y.ZodObject?i._def.unknownKeys==="passthrough":!1)?a:{},...Object.fromEntries(Object.entries(i.shape).map(([r,n])=>{const f=a[r],c=l(n);let o;if(c instanceof y.ZodDefault&&(o=c._def.defaultValue()),f===null&&c instanceof y.ZodNullable)return[r,f];if(c instanceof y.ZodSchema){const v=c.safeParse(a[r]);if(v.success)return[r,v.data??o]}return c instanceof y.ZodObject?[r,S(c,f&&typeof f=="object"?f:{})]:[r,o]}))}},M=(e,a,l)=>{const i=t.ref(),s=t.ref(),r=t.ref();return{errors:i,status:s,formData:r,component:t.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(n,{emit:f}){r.value=S(e,n.modelValue);const c=(l==null?void 0:l.continuosValidation)||n.continuosValidation;t.watch(()=>n.modelValue,h=>{if(h){const m=t.isProxy(h)?t.toRaw(h):h;r.value=typeof(m==null?void 0:m.clone)=="function"?m.clone():JSON.parse(JSON.stringify(m))}},{deep:!0}),A.watchThrottled(r,h=>{(i.value||c)&&o(),(!h||!n.modelValue||JSON.stringify(h)!==JSON.stringify(n.modelValue))&&f("update:modelValue",h)},{deep:!0,throttle:(l==null?void 0:l.updateThrottle)??500});const o=(h=r.value)=>{const m=e.safeParse(h);return m.success?(i.value=void 0,s.value="valid",r.value=m.data,f("update:modelValue",r.value),f("valid",m.data),!0):(i.value=m.error.format(),s.value="invalid",f("invalid",i.value),!1)},v=()=>o()?(f("submit",r.value),!0):!1;return t.provide(a,{modelValue:r,submit:v,errors:t.readonly(i)}),{submit:v}},render(){return t.h("form",{onSubmit:t.withModifiers(this.submit,["prevent"])},this.$slots)}})}},P=(e,a)=>t.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(i,{emit:s}){const r=t.inject(e),n=t.inject(a,void 0),f=t.ref(new Set),c=t.ref(new Map),{name:o}=t.toRefs(i);t.provide(a,{name:t.readonly(o),errors:c,fields:f}),t.watch(f,h=>{n!=null&&n.fields&&h.forEach(m=>{n==null||n.fields.value.add(m)})},{deep:!0}),t.watch(()=>new Map(c.value),(h,m)=>{n!=null&&n.errors&&(Array.from(m.keys()).forEach(V=>{n.errors.value.delete(V)}),Array.from(h.keys()).forEach(V=>{const b=h.get(V);b&&n.errors.value.set(V,b)}))},{deep:!0});const v=t.computed(()=>r!=null&&r.errors.value?c.value.size>0:!1);return t.watch(v,()=>{v.value?s("invalid"):s("valid")}),{formData:r==null?void 0:r.modelValue,errors:r==null?void 0:r.errors,invalid:v,fields:f,fieldsErrors:c}},render(){var i,s,r,n;return this.tag?t.h(this.tag,null,((s=(i=this.$slots).default)==null?void 0:s.call(i,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut):((n=(r=this.$slots).default)==null?void 0:n.call(r,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),k=(e,a={})=>{const l=Symbol(),i=Symbol(),s=Symbol(),{component:r,errors:n,status:f,formData:c}=M(e,l,a),o=P(l,i),v=K(l,i,s,a);return{VvForm:r,VvFormWrapper:o,VvFormField:v,formInjectionKey:l,formWrapperInjectionKey:i,formFieldInjectionKey:s,errors:n,status:f,formData:c}},w=Symbol(),Z=e=>{let a={};return e.schema&&(a=k(e.schema,e)),{...a,install(l,{global:i=!1}={}){l.provide(w,e),i&&(l.config.globalProperties.$vvForm=e,a!=null&&a.VvForm&&l.component("VvForm",a.VvForm),a!=null&&a.VvFormWrapper&&l.component("VvFormWrapper",a.VvFormWrapper),a!=null&&a.VvFormField&&l.component("VvFormField",a.VvFormField))}}},q=(e,a={})=>{const l={...t.inject(w,{}),...a};return k(e,l)};p.FormFieldType=u,p.createForm=Z,p.defaultObjectBySchema=S,p.formFactory=k,p.pluginInjectionKey=w,p.useForm=q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "0.0.10-beta.4",
22
+ "version": "0.0.10-beta.5",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -44,8 +44,8 @@
44
44
  "devDependencies": {
45
45
  "@playwright/experimental-ct-vue": "^1.32.3",
46
46
  "@testing-library/vue": "^7.0.0",
47
- "@typescript-eslint/eslint-plugin": "^5.58.0",
48
- "@typescript-eslint/parser": "^5.58.0",
47
+ "@typescript-eslint/eslint-plugin": "^5.59.0",
48
+ "@typescript-eslint/parser": "^5.59.0",
49
49
  "@vitejs/plugin-vue": "^4.1.0",
50
50
  "@volverjs/style": "^0.1.8",
51
51
  "@vue/compiler-sfc": "^3.2.47",
@@ -55,14 +55,14 @@
55
55
  "eslint": "^8.38.0",
56
56
  "eslint-config-prettier": "^8.8.0",
57
57
  "eslint-plugin-prettier": "^4.2.1",
58
- "happy-dom": "^9.6.1",
58
+ "happy-dom": "^9.9.2",
59
59
  "prettier": "^2.8.7",
60
60
  "typescript": "^5.0.4",
61
- "vite": "^4.2.1",
61
+ "vite": "^4.3.1",
62
62
  "vite-plugin-eslint": "^1.8.1",
63
63
  "vite-plugin-externalize-deps": "^0.5.0",
64
64
  "vitest": "^0.30.1",
65
- "vue-tsc": "^1.2.0"
65
+ "vue-tsc": "^1.4.2"
66
66
  },
67
67
  "typesVersions": {
68
68
  "*": {
@@ -10,8 +10,9 @@ import {
10
10
  toRefs,
11
11
  watch,
12
12
  h,
13
+ type DeepReadonly,
13
14
  } from 'vue'
14
- import type { AnyZodObject, ZodEffects } from 'zod'
15
+ import type { AnyZodObject, TypeOf, ZodEffects, z } from 'zod'
15
16
  import type { InjectedFormData, InjectedFormWrapperData } from './types'
16
17
 
17
18
  export const defineFormWrapper = <
@@ -23,7 +24,7 @@ export const defineFormWrapper = <
23
24
  formProvideKey: InjectionKey<InjectedFormData<Schema>>,
24
25
  wrapperProvideKey: InjectionKey<InjectedFormWrapperData<Schema>>,
25
26
  ) => {
26
- return defineComponent({
27
+ const toReturn = defineComponent({
27
28
  name: 'WrapperComponent',
28
29
  props: {
29
30
  name: {
@@ -131,4 +132,34 @@ export const defineFormWrapper = <
131
132
  )
132
133
  },
133
134
  })
135
+ /**
136
+ * An hack to add types to the slots
137
+ */
138
+ return toReturn as typeof toReturn & {
139
+ new (): {
140
+ $slots: {
141
+ default: (_: {
142
+ invalid: boolean
143
+ formData: unknown extends
144
+ | Partial<TypeOf<Schema>>
145
+ | undefined
146
+ ? undefined
147
+ : Partial<TypeOf<Schema>> | undefined
148
+ errors: Readonly<
149
+ Ref<DeepReadonly<z.inferFormattedError<Schema>>>
150
+ >
151
+ fieldsErrors: Map<
152
+ string,
153
+ Record<
154
+ string,
155
+ {
156
+ _errors: string[]
157
+ }
158
+ >
159
+ >
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ }) => any
162
+ }
163
+ }
164
+ }
134
165
  }