@volverjs/form-vue 0.0.10-beta.10 → 0.0.10-beta.12
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/README.md +2 -2
- package/dist/VvForm.d.ts +4 -0
- package/dist/VvFormTemplate.d.ts +1 -0
- package/dist/VvFormWrapper.d.ts +8 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.es.js +238 -228
- package/dist/index.umd.js +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/VvForm.ts +18 -11
- package/src/VvFormField.ts +2 -0
- package/src/VvFormTemplate.ts +2 -0
- package/src/VvFormWrapper.ts +8 -0
- package/src/types.d.ts +1 -0
package/README.md
CHANGED
|
@@ -171,7 +171,7 @@ The **default settings** are **inherited** from the plugin (if it's installed).
|
|
|
171
171
|
`useForm()` can create a form also outside a Vue 3 Component, plugin settings are **not inherited**.
|
|
172
172
|
|
|
173
173
|
```ts
|
|
174
|
-
import {
|
|
174
|
+
import { useForm } from '@volverjs/form-vue'
|
|
175
175
|
import { z } from 'zod'
|
|
176
176
|
|
|
177
177
|
const schema = z.object({
|
|
@@ -187,7 +187,7 @@ const {
|
|
|
187
187
|
formData,
|
|
188
188
|
status,
|
|
189
189
|
errors
|
|
190
|
-
} =
|
|
190
|
+
} = useForm(schema, {
|
|
191
191
|
lazyLoad: true
|
|
192
192
|
})
|
|
193
193
|
|
package/dist/VvForm.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
70
70
|
}, {
|
|
71
71
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
72
72
|
submit: () => boolean;
|
|
73
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean;
|
|
73
74
|
errors: Readonly<Ref<DeepReadonly<z.ZodFormattedError<z.TypeOf<Schema>>> | undefined>>;
|
|
74
75
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
75
76
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -118,6 +119,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
118
119
|
} & import("vue").ShallowUnwrapRef<{
|
|
119
120
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
120
121
|
submit: () => boolean;
|
|
122
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean;
|
|
121
123
|
errors: Readonly<Ref<DeepReadonly<z.ZodFormattedError<z.TypeOf<Schema>>> | undefined>>;
|
|
122
124
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
123
125
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -146,6 +148,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
146
148
|
}, {
|
|
147
149
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
148
150
|
submit: () => boolean;
|
|
151
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean;
|
|
149
152
|
errors: Readonly<Ref<DeepReadonly<z.ZodFormattedError<z.TypeOf<Schema>>> | undefined>>;
|
|
150
153
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
151
154
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -158,6 +161,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
158
161
|
default: (_: {
|
|
159
162
|
formData: unknown extends Partial<z.TypeOf<Schema>> | undefined ? undefined : Partial<z.TypeOf<Schema>> | undefined;
|
|
160
163
|
submit: () => boolean;
|
|
164
|
+
validate: () => boolean;
|
|
161
165
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
162
166
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
163
167
|
invalid: Ref<DeepReadonly<boolean>>;
|
package/dist/VvFormTemplate.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const defineFormTemplate: <Schema extends FormSchema>(formProvide
|
|
|
12
12
|
default: (_: {
|
|
13
13
|
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
14
14
|
submit: () => boolean;
|
|
15
|
+
validate: () => boolean;
|
|
15
16
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
16
17
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
17
18
|
invalid: Ref<DeepReadonly<boolean>>;
|
package/dist/VvFormWrapper.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
48
48
|
}, {
|
|
49
49
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
50
50
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
|
|
51
|
+
submit: (() => boolean) | undefined;
|
|
52
|
+
validate: (() => boolean) | undefined;
|
|
51
53
|
invalid: import("vue").ComputedRef<boolean>;
|
|
52
54
|
fields: Ref<Set<string>>;
|
|
53
55
|
fieldsErrors: Ref<Map<string, Record<string, {
|
|
@@ -90,6 +92,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
90
92
|
} & import("vue").ShallowUnwrapRef<{
|
|
91
93
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
92
94
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
|
|
95
|
+
submit: (() => boolean) | undefined;
|
|
96
|
+
validate: (() => boolean) | undefined;
|
|
93
97
|
invalid: import("vue").ComputedRef<boolean>;
|
|
94
98
|
fields: Ref<Set<string>>;
|
|
95
99
|
fieldsErrors: Ref<Map<string, Record<string, {
|
|
@@ -114,6 +118,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
114
118
|
}, {
|
|
115
119
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
116
120
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema_1, string>>>> | undefined;
|
|
121
|
+
submit: (() => boolean) | undefined;
|
|
122
|
+
validate: (() => boolean) | undefined;
|
|
117
123
|
invalid: import("vue").ComputedRef<boolean>;
|
|
118
124
|
fields: Ref<Set<string>>;
|
|
119
125
|
fieldsErrors: Ref<Map<string, Record<string, {
|
|
@@ -126,6 +132,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
126
132
|
default: (_: {
|
|
127
133
|
invalid: boolean;
|
|
128
134
|
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
135
|
+
submit: () => boolean;
|
|
136
|
+
validate: () => boolean;
|
|
129
137
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
130
138
|
fieldsErrors: Map<string, Record<string, {
|
|
131
139
|
_errors: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
68
68
|
}, {
|
|
69
69
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
70
70
|
submit: () => boolean;
|
|
71
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
71
72
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
72
73
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
73
74
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -116,6 +117,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
116
117
|
} & import("vue").ShallowUnwrapRef<{
|
|
117
118
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
118
119
|
submit: () => boolean;
|
|
120
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
119
121
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
120
122
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
121
123
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -144,6 +146,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
144
146
|
}, {
|
|
145
147
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
146
148
|
submit: () => boolean;
|
|
149
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
147
150
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
148
151
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
149
152
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -156,6 +159,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
156
159
|
default: (_: {
|
|
157
160
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
158
161
|
submit: () => boolean;
|
|
162
|
+
validate: () => boolean;
|
|
159
163
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
160
164
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
161
165
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -209,6 +213,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
209
213
|
}, {
|
|
210
214
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
211
215
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
216
|
+
submit: (() => boolean) | undefined;
|
|
217
|
+
validate: (() => boolean) | undefined;
|
|
212
218
|
invalid: import("vue").ComputedRef<boolean>;
|
|
213
219
|
fields: import("vue").Ref<Set<string>>;
|
|
214
220
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -251,6 +257,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
251
257
|
} & import("vue").ShallowUnwrapRef<{
|
|
252
258
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
253
259
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
260
|
+
submit: (() => boolean) | undefined;
|
|
261
|
+
validate: (() => boolean) | undefined;
|
|
254
262
|
invalid: import("vue").ComputedRef<boolean>;
|
|
255
263
|
fields: import("vue").Ref<Set<string>>;
|
|
256
264
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -275,6 +283,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
275
283
|
}, {
|
|
276
284
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
277
285
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
286
|
+
submit: (() => boolean) | undefined;
|
|
287
|
+
validate: (() => boolean) | undefined;
|
|
278
288
|
invalid: import("vue").ComputedRef<boolean>;
|
|
279
289
|
fields: import("vue").Ref<Set<string>>;
|
|
280
290
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -287,6 +297,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
287
297
|
default: (_: {
|
|
288
298
|
invalid: boolean;
|
|
289
299
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
300
|
+
submit: () => boolean;
|
|
301
|
+
validate: () => boolean;
|
|
290
302
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
291
303
|
fieldsErrors: Map<string, Record<string, {
|
|
292
304
|
_errors: string[];
|
|
@@ -392,6 +404,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
392
404
|
default: (_: {
|
|
393
405
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
394
406
|
submit: () => boolean;
|
|
407
|
+
validate: () => boolean;
|
|
395
408
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
396
409
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
397
410
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -477,6 +490,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
477
490
|
}, {
|
|
478
491
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
479
492
|
submit: () => boolean;
|
|
493
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
480
494
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
481
495
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
482
496
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -525,6 +539,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
525
539
|
} & import("vue").ShallowUnwrapRef<{
|
|
526
540
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
527
541
|
submit: () => boolean;
|
|
542
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
528
543
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
529
544
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
530
545
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -553,6 +568,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
553
568
|
}, {
|
|
554
569
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
555
570
|
submit: () => boolean;
|
|
571
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean;
|
|
556
572
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").ZodFormattedError<import("zod").TypeOf<Schema>>> | undefined>>;
|
|
557
573
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
558
574
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -565,6 +581,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
565
581
|
default: (_: {
|
|
566
582
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
567
583
|
submit: () => boolean;
|
|
584
|
+
validate: () => boolean;
|
|
568
585
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
569
586
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
570
587
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -618,6 +635,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
618
635
|
}, {
|
|
619
636
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
620
637
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
638
|
+
submit: (() => boolean) | undefined;
|
|
639
|
+
validate: (() => boolean) | undefined;
|
|
621
640
|
invalid: import("vue").ComputedRef<boolean>;
|
|
622
641
|
fields: import("vue").Ref<Set<string>>;
|
|
623
642
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -660,6 +679,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
660
679
|
} & import("vue").ShallowUnwrapRef<{
|
|
661
680
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
662
681
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
682
|
+
submit: (() => boolean) | undefined;
|
|
683
|
+
validate: (() => boolean) | undefined;
|
|
663
684
|
invalid: import("vue").ComputedRef<boolean>;
|
|
664
685
|
fields: import("vue").Ref<Set<string>>;
|
|
665
686
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -684,6 +705,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
684
705
|
}, {
|
|
685
706
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
686
707
|
errors: Readonly<import("vue").Ref<DeepReadonly<import("zod").inferFormattedError<Schema_1, string>>>> | undefined;
|
|
708
|
+
submit: (() => boolean) | undefined;
|
|
709
|
+
validate: (() => boolean) | undefined;
|
|
687
710
|
invalid: import("vue").ComputedRef<boolean>;
|
|
688
711
|
fields: import("vue").Ref<Set<string>>;
|
|
689
712
|
fieldsErrors: import("vue").Ref<Map<string, Record<string, {
|
|
@@ -696,6 +719,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
696
719
|
default: (_: {
|
|
697
720
|
invalid: boolean;
|
|
698
721
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
722
|
+
submit: () => boolean;
|
|
723
|
+
validate: () => boolean;
|
|
699
724
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
700
725
|
fieldsErrors: Map<string, Record<string, {
|
|
701
726
|
_errors: string[];
|
|
@@ -801,6 +826,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
801
826
|
default: (_: {
|
|
802
827
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
803
828
|
submit: () => boolean;
|
|
829
|
+
validate: () => boolean;
|
|
804
830
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
805
831
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
806
832
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
package/dist/index.es.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { defineComponent as G, computed as y, onMounted as
|
|
1
|
+
import { defineComponent as G, computed as y, onMounted as R, onBeforeUnmount as T, inject as O, toRefs as U, watch as w, provide as z, readonly as k, resolveComponent as g, defineAsyncComponent as D, h as x, ref as E, toRaw as Z, isProxy as j, withModifiers as F, unref as C, getCurrentInstance as ee } from "vue";
|
|
2
2
|
import { watchThrottled as re } from "@vueuse/core";
|
|
3
|
-
import { ZodObject as
|
|
3
|
+
import { ZodObject as J, ZodDefault as te, ZodNullable as ae, ZodSchema as ne, ZodEffects as se } from "zod";
|
|
4
4
|
function _(e) {
|
|
5
5
|
return Array.isArray(e);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function oe(e) {
|
|
8
8
|
return typeof e < "u";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function M(e) {
|
|
11
11
|
return e === null;
|
|
12
12
|
}
|
|
13
13
|
function q(e) {
|
|
@@ -19,58 +19,58 @@ function P(e) {
|
|
|
19
19
|
function $(e) {
|
|
20
20
|
return typeof e > "u";
|
|
21
21
|
}
|
|
22
|
-
const ue = /^[0-9]+$/,
|
|
23
|
-
function N(e,
|
|
24
|
-
const
|
|
25
|
-
if (!q(e) || !P(
|
|
26
|
-
return
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
for (const r of
|
|
22
|
+
const ue = /^[0-9]+$/, ie = ["__proto__", "prototype", "constructor"];
|
|
23
|
+
function N(e, s, l) {
|
|
24
|
+
const o = oe(l) ? l : void 0;
|
|
25
|
+
if (!q(e) || !P(s))
|
|
26
|
+
return o;
|
|
27
|
+
const n = Q(s);
|
|
28
|
+
if (n.length !== 0) {
|
|
29
|
+
for (const r of n) {
|
|
30
30
|
if (r === "*")
|
|
31
31
|
continue;
|
|
32
|
-
const u = function(
|
|
33
|
-
return
|
|
32
|
+
const u = function(a) {
|
|
33
|
+
return a.map((i) => $(i) || M(i) ? i : _(i) ? u(i) : i[r]);
|
|
34
34
|
};
|
|
35
|
-
if (_(e) && !ue.test(r) ? e = u(e) : e = e[r], $(e) ||
|
|
35
|
+
if (_(e) && !ue.test(r) ? e = u(e) : e = e[r], $(e) || M(e))
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
|
-
return $(e) ?
|
|
38
|
+
return $(e) ? o : e;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!q(e) || !P(
|
|
41
|
+
function H(e, s, l) {
|
|
42
|
+
if (!q(e) || !P(s))
|
|
43
43
|
return;
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
44
|
+
const o = Q(s);
|
|
45
|
+
if (o.length === 0)
|
|
46
46
|
return;
|
|
47
|
-
const
|
|
48
|
-
for (let r = 0; r <
|
|
49
|
-
const u =
|
|
50
|
-
if (r ===
|
|
51
|
-
e[u] =
|
|
47
|
+
const n = o.length;
|
|
48
|
+
for (let r = 0; r < n; r++) {
|
|
49
|
+
const u = o[r];
|
|
50
|
+
if (r === n - 1) {
|
|
51
|
+
e[u] = l;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
if (u === "*" && _(e)) {
|
|
55
|
-
const
|
|
56
|
-
for (const
|
|
57
|
-
|
|
55
|
+
const a = o.slice(r + 1).join(".");
|
|
56
|
+
for (const i of e)
|
|
57
|
+
H(i, a, l);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
$(e[u]) && (e[u] = {}), e = e[u];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
return
|
|
63
|
+
function Q(e) {
|
|
64
|
+
const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((l) => !!l);
|
|
65
|
+
return s.some((l) => ie.indexOf(l) !== -1) ? [] : s;
|
|
66
66
|
}
|
|
67
67
|
var f = /* @__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))(f || {}), L = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(L || {});
|
|
68
|
-
const
|
|
68
|
+
const le = (e, s, l, o) => G({
|
|
69
69
|
name: "FieldComponent",
|
|
70
70
|
props: {
|
|
71
71
|
type: {
|
|
72
72
|
type: String,
|
|
73
|
-
validator: (
|
|
73
|
+
validator: (n) => Object.values(f).includes(n),
|
|
74
74
|
default: f.custom
|
|
75
75
|
},
|
|
76
76
|
is: {
|
|
@@ -100,47 +100,47 @@ const ie = (e, o, i, s) => G({
|
|
|
100
100
|
},
|
|
101
101
|
emits: ["invalid", "valid", "update:formData", "update:modelValue"],
|
|
102
102
|
expose: ["invalid", "invalidLabel", "errors"],
|
|
103
|
-
setup(
|
|
104
|
-
const
|
|
103
|
+
setup(n, { slots: r, emit: u }) {
|
|
104
|
+
const a = y({
|
|
105
105
|
get() {
|
|
106
106
|
if (t != null && t.formData)
|
|
107
107
|
return N(
|
|
108
108
|
Object(t.formData.value),
|
|
109
|
-
String(
|
|
109
|
+
String(n.name)
|
|
110
110
|
);
|
|
111
111
|
},
|
|
112
|
-
set(
|
|
113
|
-
t != null && t.formData && (
|
|
112
|
+
set(v) {
|
|
113
|
+
t != null && t.formData && (H(
|
|
114
114
|
Object(t.formData.value),
|
|
115
|
-
String(
|
|
116
|
-
|
|
115
|
+
String(n.name),
|
|
116
|
+
v
|
|
117
117
|
), u("update:modelValue", {
|
|
118
|
-
newValue:
|
|
118
|
+
newValue: a.value,
|
|
119
119
|
formData: t == null ? void 0 : t.formData
|
|
120
120
|
}));
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}),
|
|
123
|
+
R(() => {
|
|
124
|
+
a.value === void 0 && n.defaultValue !== void 0 && (a.value = n.defaultValue);
|
|
125
|
+
}), T(() => {
|
|
126
126
|
S(), V();
|
|
127
127
|
});
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const t = O(e), { props: m, name:
|
|
128
|
+
const i = O(s, void 0);
|
|
129
|
+
i && i.fields.value.add(n.name);
|
|
130
|
+
const t = O(e), { props: m, name: h } = U(n), d = y(() => {
|
|
131
131
|
if (t != null && t.errors.value)
|
|
132
|
-
return N(t.errors.value, String(
|
|
133
|
-
}),
|
|
134
|
-
var
|
|
135
|
-
return (
|
|
136
|
-
}),
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
return N(t.errors.value, String(n.name));
|
|
133
|
+
}), c = y(() => {
|
|
134
|
+
var v;
|
|
135
|
+
return (v = d.value) == null ? void 0 : v._errors;
|
|
136
|
+
}), b = y(() => d.value !== void 0), S = w(b, () => {
|
|
137
|
+
b.value ? (u("invalid", c.value), i && i.errors.value.set(
|
|
138
|
+
n.name,
|
|
139
139
|
{
|
|
140
|
-
_errors:
|
|
140
|
+
_errors: c.value
|
|
141
141
|
}
|
|
142
|
-
)) : (u("valid",
|
|
143
|
-
|
|
142
|
+
)) : (u("valid", a.value), i && i.errors.value.delete(
|
|
143
|
+
n.name
|
|
144
144
|
));
|
|
145
145
|
}), V = w(
|
|
146
146
|
() => t == null ? void 0 : t.formData,
|
|
@@ -148,14 +148,14 @@ const ie = (e, o, i, s) => G({
|
|
|
148
148
|
u("update:formData", t == null ? void 0 : t.formData);
|
|
149
149
|
},
|
|
150
150
|
{ deep: !0 }
|
|
151
|
-
),
|
|
152
|
-
|
|
151
|
+
), p = (v) => {
|
|
152
|
+
a.value = v;
|
|
153
153
|
}, I = y(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), W = y(() => ({
|
|
154
154
|
...I.value,
|
|
155
|
-
name: I.value.name ??
|
|
156
|
-
invalid:
|
|
157
|
-
valid:
|
|
158
|
-
type: ((
|
|
155
|
+
name: I.value.name ?? n.name,
|
|
156
|
+
invalid: b.value,
|
|
157
|
+
valid: n.showValid ? !!(!b.value && a.value) : void 0,
|
|
158
|
+
type: ((v) => {
|
|
159
159
|
if ([
|
|
160
160
|
f.text,
|
|
161
161
|
f.number,
|
|
@@ -170,67 +170,69 @@ const ie = (e, o, i, s) => G({
|
|
|
170
170
|
f.month,
|
|
171
171
|
f.week,
|
|
172
172
|
f.color
|
|
173
|
-
].includes(
|
|
174
|
-
return
|
|
175
|
-
})(
|
|
176
|
-
invalidLabel:
|
|
177
|
-
modelValue:
|
|
178
|
-
"onUpdate:modelValue":
|
|
173
|
+
].includes(v))
|
|
174
|
+
return v;
|
|
175
|
+
})(n.type),
|
|
176
|
+
invalidLabel: c.value,
|
|
177
|
+
modelValue: a.value,
|
|
178
|
+
"onUpdate:modelValue": p
|
|
179
179
|
}));
|
|
180
|
-
return z(
|
|
181
|
-
name: k(
|
|
182
|
-
errors: k(
|
|
180
|
+
return z(l, {
|
|
181
|
+
name: k(h),
|
|
182
|
+
errors: k(d)
|
|
183
183
|
}), { component: y(() => {
|
|
184
|
-
if (
|
|
184
|
+
if (n.type === f.custom)
|
|
185
185
|
return {
|
|
186
186
|
render() {
|
|
187
|
-
var
|
|
188
|
-
return ((
|
|
189
|
-
modelValue:
|
|
190
|
-
onUpdate:
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
var v;
|
|
188
|
+
return ((v = r.default) == null ? void 0 : v.call(r, {
|
|
189
|
+
modelValue: a.value,
|
|
190
|
+
onUpdate: p,
|
|
191
|
+
submit: t == null ? void 0 : t.submit,
|
|
192
|
+
validate: t == null ? void 0 : t.validate,
|
|
193
|
+
invalid: b.value,
|
|
194
|
+
invalidLabel: c.value,
|
|
193
195
|
formData: t == null ? void 0 : t.formData.value,
|
|
194
196
|
formErrors: t == null ? void 0 : t.errors.value,
|
|
195
|
-
errors:
|
|
197
|
+
errors: d.value
|
|
196
198
|
})) ?? r.defalut;
|
|
197
199
|
}
|
|
198
200
|
};
|
|
199
|
-
if (!((
|
|
200
|
-
let
|
|
201
|
-
switch (
|
|
201
|
+
if (!((o == null ? void 0 : o.lazyLoad) ?? n.lazyLoad)) {
|
|
202
|
+
let v;
|
|
203
|
+
switch (n.type) {
|
|
202
204
|
case f.select:
|
|
203
|
-
|
|
205
|
+
v = g("VvSelect");
|
|
204
206
|
break;
|
|
205
207
|
case f.checkbox:
|
|
206
|
-
|
|
208
|
+
v = g("VvCheckbox");
|
|
207
209
|
break;
|
|
208
210
|
case f.radio:
|
|
209
|
-
|
|
211
|
+
v = g("VvRadio");
|
|
210
212
|
break;
|
|
211
213
|
case f.textarea:
|
|
212
|
-
|
|
214
|
+
v = g("VvTextarea");
|
|
213
215
|
break;
|
|
214
216
|
case f.radioGroup:
|
|
215
|
-
|
|
217
|
+
v = g("VvRadioGroup");
|
|
216
218
|
break;
|
|
217
219
|
case f.checkboxGroup:
|
|
218
|
-
|
|
220
|
+
v = g("VvCheckboxGroup");
|
|
219
221
|
break;
|
|
220
222
|
case f.combobox:
|
|
221
|
-
|
|
223
|
+
v = g("VvCombobox");
|
|
222
224
|
break;
|
|
223
225
|
default:
|
|
224
|
-
|
|
226
|
+
v = g("VvInputText");
|
|
225
227
|
}
|
|
226
|
-
if (typeof
|
|
227
|
-
return
|
|
228
|
+
if (typeof v != "string")
|
|
229
|
+
return v;
|
|
228
230
|
console.warn(
|
|
229
|
-
`[form-vue warn]: ${
|
|
231
|
+
`[form-vue warn]: ${v} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
|
|
230
232
|
);
|
|
231
233
|
}
|
|
232
|
-
return
|
|
233
|
-
switch (
|
|
234
|
+
return D(async () => {
|
|
235
|
+
switch (o != null && o.sideEffects && await Promise.resolve(o.sideEffects(n.type)), n.type) {
|
|
234
236
|
case f.textarea:
|
|
235
237
|
return import("@volverjs/ui-vue/vv-textarea");
|
|
236
238
|
case f.radio:
|
|
@@ -246,45 +248,45 @@ const ie = (e, o, i, s) => G({
|
|
|
246
248
|
}
|
|
247
249
|
return import("@volverjs/ui-vue/vv-input-text");
|
|
248
250
|
});
|
|
249
|
-
}), hasProps: W, invalid:
|
|
251
|
+
}), hasProps: W, invalid: b };
|
|
250
252
|
},
|
|
251
253
|
render() {
|
|
252
254
|
return this.is ? x(this.is, this.hasProps, this.$slots) : this.type === f.custom ? x(this.component, null, this.$slots) : x(this.component, this.hasProps, this.$slots);
|
|
253
255
|
}
|
|
254
|
-
}),
|
|
255
|
-
const
|
|
256
|
+
}), X = (e, s = {}) => {
|
|
257
|
+
const l = (r) => {
|
|
256
258
|
let u = r;
|
|
257
|
-
for (; u instanceof
|
|
259
|
+
for (; u instanceof se; )
|
|
258
260
|
u = u.innerType();
|
|
259
261
|
return u;
|
|
260
|
-
},
|
|
262
|
+
}, o = l(e);
|
|
261
263
|
return {
|
|
262
|
-
...(
|
|
264
|
+
...(o instanceof J ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
|
|
263
265
|
...Object.fromEntries(
|
|
264
|
-
Object.entries(
|
|
266
|
+
Object.entries(o.shape).map(
|
|
265
267
|
([r, u]) => {
|
|
266
|
-
const
|
|
268
|
+
const a = s[r], i = l(u);
|
|
267
269
|
let t;
|
|
268
|
-
if (
|
|
269
|
-
return [r,
|
|
270
|
-
if (
|
|
271
|
-
const m = u.safeParse(
|
|
270
|
+
if (i instanceof te && (t = i._def.defaultValue()), a === null && i instanceof ae)
|
|
271
|
+
return [r, a];
|
|
272
|
+
if (i instanceof ne) {
|
|
273
|
+
const m = u.safeParse(a);
|
|
272
274
|
if (m.success)
|
|
273
275
|
return [r, m.data ?? t];
|
|
274
276
|
}
|
|
275
|
-
return
|
|
277
|
+
return i instanceof J ? [
|
|
276
278
|
r,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
X(
|
|
280
|
+
i,
|
|
281
|
+
a && typeof a == "object" ? a : {}
|
|
280
282
|
)
|
|
281
283
|
] : [r, t];
|
|
282
284
|
}
|
|
283
285
|
)
|
|
284
286
|
)
|
|
285
287
|
};
|
|
286
|
-
}, fe = (e,
|
|
287
|
-
const
|
|
288
|
+
}, fe = (e, s, l) => {
|
|
289
|
+
const o = E(), n = E(), r = E(), u = G({
|
|
288
290
|
name: "FormComponent",
|
|
289
291
|
props: {
|
|
290
292
|
modelValue: {
|
|
@@ -301,47 +303,47 @@ const ie = (e, o, i, s) => G({
|
|
|
301
303
|
}
|
|
302
304
|
},
|
|
303
305
|
emits: ["invalid", "valid", "submit", "update:modelValue"],
|
|
304
|
-
expose: ["submit", "errors", "status"],
|
|
305
|
-
setup(
|
|
306
|
-
r.value =
|
|
306
|
+
expose: ["submit", "validate", "errors", "status", "valid", "invalid"],
|
|
307
|
+
setup(a, { emit: i }) {
|
|
308
|
+
r.value = X(
|
|
307
309
|
e,
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
w(
|
|
312
|
-
() => n.modelValue,
|
|
310
|
+
Z(a.modelValue)
|
|
311
|
+
), w(
|
|
312
|
+
() => a.modelValue,
|
|
313
313
|
(d) => {
|
|
314
314
|
if (d) {
|
|
315
|
-
const
|
|
316
|
-
r.value = typeof (
|
|
315
|
+
const c = j(d) ? Z(d) : d;
|
|
316
|
+
r.value = typeof (c == null ? void 0 : c.clone) == "function" ? c.clone() : JSON.parse(JSON.stringify(c));
|
|
317
317
|
}
|
|
318
318
|
},
|
|
319
319
|
{ deep: !0 }
|
|
320
320
|
), re(
|
|
321
321
|
r,
|
|
322
322
|
(d) => {
|
|
323
|
-
(
|
|
323
|
+
((o.value || (l == null ? void 0 : l.continuosValidation)) ?? a.continuosValidation) && t(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && i("update:modelValue", d);
|
|
324
324
|
},
|
|
325
325
|
{
|
|
326
326
|
deep: !0,
|
|
327
|
-
throttle: (
|
|
327
|
+
throttle: (l == null ? void 0 : l.updateThrottle) ?? a.updateThrottle
|
|
328
328
|
}
|
|
329
329
|
);
|
|
330
|
-
const
|
|
331
|
-
const
|
|
332
|
-
return
|
|
333
|
-
},
|
|
334
|
-
return z(
|
|
330
|
+
const t = (d = r.value) => {
|
|
331
|
+
const c = e.safeParse(d);
|
|
332
|
+
return c.success ? (o.value = void 0, n.value = L.valid, r.value = c.data, i("update:modelValue", r.value), i("valid", c.data), !0) : (o.value = c.error.format(), n.value = L.invalid, i("invalid", o.value), !1);
|
|
333
|
+
}, m = () => t() ? (i("submit", r.value), !0) : !1, h = y(() => n.value === L.invalid);
|
|
334
|
+
return z(s, {
|
|
335
335
|
formData: r,
|
|
336
|
-
submit:
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
submit: m,
|
|
337
|
+
validate: t,
|
|
338
|
+
errors: k(o),
|
|
339
|
+
status: k(n),
|
|
339
340
|
invalid: h
|
|
340
341
|
}), {
|
|
341
342
|
formData: r,
|
|
342
|
-
submit:
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
submit: m,
|
|
344
|
+
validate: t,
|
|
345
|
+
errors: k(o),
|
|
346
|
+
status: k(n),
|
|
345
347
|
invalid: h
|
|
346
348
|
};
|
|
347
349
|
},
|
|
@@ -353,10 +355,11 @@ const ie = (e, o, i, s) => G({
|
|
|
353
355
|
},
|
|
354
356
|
{
|
|
355
357
|
default: () => {
|
|
356
|
-
var
|
|
357
|
-
return ((
|
|
358
|
+
var a, i;
|
|
359
|
+
return ((i = (a = this.$slots) == null ? void 0 : a.default) == null ? void 0 : i.call(a, {
|
|
358
360
|
formData: this.formData,
|
|
359
361
|
submit: this.submit,
|
|
362
|
+
validate: this.validate,
|
|
360
363
|
errors: this.errors,
|
|
361
364
|
status: this.status,
|
|
362
365
|
invalid: this.invalid
|
|
@@ -367,15 +370,15 @@ const ie = (e, o, i, s) => G({
|
|
|
367
370
|
}
|
|
368
371
|
});
|
|
369
372
|
return {
|
|
370
|
-
errors:
|
|
371
|
-
status:
|
|
373
|
+
errors: o,
|
|
374
|
+
status: n,
|
|
372
375
|
formData: r,
|
|
373
376
|
/**
|
|
374
377
|
* An hack to add types to the default slot
|
|
375
378
|
*/
|
|
376
379
|
VvForm: u
|
|
377
380
|
};
|
|
378
|
-
},
|
|
381
|
+
}, ve = (e, s) => G({
|
|
379
382
|
name: "WrapperComponent",
|
|
380
383
|
props: {
|
|
381
384
|
name: {
|
|
@@ -389,134 +392,141 @@ const ie = (e, o, i, s) => G({
|
|
|
389
392
|
},
|
|
390
393
|
emits: ["invalid", "valid"],
|
|
391
394
|
expose: ["fields", "invalid"],
|
|
392
|
-
setup(
|
|
393
|
-
const r = O(e), u = O(
|
|
394
|
-
z(
|
|
395
|
+
setup(o, { emit: n }) {
|
|
396
|
+
const r = O(e), u = O(s, void 0), a = E(/* @__PURE__ */ new Set()), i = E(/* @__PURE__ */ new Map()), { name: t } = U(o);
|
|
397
|
+
z(s, {
|
|
395
398
|
name: k(t),
|
|
396
|
-
errors:
|
|
397
|
-
fields:
|
|
399
|
+
errors: i,
|
|
400
|
+
fields: a
|
|
398
401
|
}), w(
|
|
399
|
-
|
|
400
|
-
(
|
|
401
|
-
u != null && u.fields &&
|
|
402
|
-
u == null || u.fields.value.add(
|
|
402
|
+
a,
|
|
403
|
+
(h) => {
|
|
404
|
+
u != null && u.fields && h.forEach((d) => {
|
|
405
|
+
u == null || u.fields.value.add(d);
|
|
403
406
|
});
|
|
404
407
|
},
|
|
405
408
|
{ deep: !0 }
|
|
406
409
|
), w(
|
|
407
|
-
() => new Map(
|
|
408
|
-
(
|
|
409
|
-
u != null && u.errors && (Array.from(
|
|
410
|
-
u.errors.value.delete(
|
|
411
|
-
}), Array.from(
|
|
412
|
-
const
|
|
413
|
-
|
|
410
|
+
() => new Map(i.value),
|
|
411
|
+
(h, d) => {
|
|
412
|
+
u != null && u.errors && (Array.from(d.keys()).forEach((c) => {
|
|
413
|
+
u.errors.value.delete(c);
|
|
414
|
+
}), Array.from(h.keys()).forEach((c) => {
|
|
415
|
+
const b = h.get(c);
|
|
416
|
+
b && u.errors.value.set(c, b);
|
|
414
417
|
}));
|
|
415
418
|
},
|
|
416
419
|
{ deep: !0 }
|
|
417
420
|
);
|
|
418
|
-
const m = y(() => r != null && r.invalid.value ?
|
|
421
|
+
const m = y(() => r != null && r.invalid.value ? i.value.size > 0 : !1);
|
|
419
422
|
return w(m, () => {
|
|
420
|
-
m.value ?
|
|
423
|
+
m.value ? n("invalid") : n("valid");
|
|
421
424
|
}), {
|
|
422
425
|
formData: r == null ? void 0 : r.formData,
|
|
423
426
|
errors: r == null ? void 0 : r.errors,
|
|
427
|
+
submit: r == null ? void 0 : r.submit,
|
|
428
|
+
validate: r == null ? void 0 : r.validate,
|
|
424
429
|
invalid: m,
|
|
425
|
-
fields:
|
|
426
|
-
fieldsErrors:
|
|
430
|
+
fields: a,
|
|
431
|
+
fieldsErrors: i
|
|
427
432
|
};
|
|
428
433
|
},
|
|
429
434
|
render() {
|
|
430
|
-
var
|
|
435
|
+
var o, n;
|
|
431
436
|
return this.tag ? x(this.tag, null, {
|
|
432
437
|
default: () => {
|
|
433
438
|
var r, u;
|
|
434
439
|
return ((u = (r = this.$slots).default) == null ? void 0 : u.call(r, {
|
|
435
440
|
invalid: this.invalid,
|
|
436
441
|
formData: this.formData,
|
|
442
|
+
submit: this.submit,
|
|
443
|
+
validate: this.validate,
|
|
437
444
|
errors: this.errors,
|
|
438
445
|
fieldsErrors: this.fieldsErrors
|
|
439
446
|
})) ?? this.$slots.defalut;
|
|
440
447
|
}
|
|
441
|
-
}) : ((
|
|
448
|
+
}) : ((n = (o = this.$slots).default) == null ? void 0 : n.call(o, {
|
|
442
449
|
invalid: this.invalid,
|
|
443
450
|
formData: this.formData,
|
|
451
|
+
submit: this.submit,
|
|
452
|
+
validate: this.validate,
|
|
444
453
|
errors: this.errors,
|
|
445
454
|
fieldsErrors: this.fieldsErrors
|
|
446
455
|
})) ?? this.$slots.defalut;
|
|
447
456
|
}
|
|
448
|
-
}), de = (e,
|
|
449
|
-
const
|
|
457
|
+
}), de = (e, s) => {
|
|
458
|
+
const l = G({
|
|
450
459
|
props: {
|
|
451
460
|
schema: {
|
|
452
461
|
type: [Array, Function],
|
|
453
462
|
required: !0
|
|
454
463
|
}
|
|
455
464
|
},
|
|
456
|
-
setup(
|
|
465
|
+
setup(o, { slots: n }) {
|
|
457
466
|
const r = O(e);
|
|
458
467
|
if (!(r != null && r.formData))
|
|
459
468
|
return;
|
|
460
|
-
const u = typeof
|
|
461
|
-
let
|
|
469
|
+
const u = typeof o.schema == "function" ? o.schema(r) : o.schema;
|
|
470
|
+
let a;
|
|
462
471
|
return () => {
|
|
463
|
-
var
|
|
472
|
+
var i;
|
|
464
473
|
return u.reduce(
|
|
465
474
|
(t, m) => {
|
|
466
|
-
const
|
|
467
|
-
vvIs:
|
|
468
|
-
vvName:
|
|
469
|
-
vvSlots:
|
|
475
|
+
const h = typeof m == "function" ? m(r) : m, {
|
|
476
|
+
vvIs: d,
|
|
477
|
+
vvName: c,
|
|
478
|
+
vvSlots: b,
|
|
470
479
|
vvChildren: S,
|
|
471
480
|
vvIf: V,
|
|
472
|
-
vvElseIf:
|
|
481
|
+
vvElseIf: p,
|
|
473
482
|
vvType: I,
|
|
474
483
|
vvDefaultValue: W,
|
|
475
484
|
vvShowValid: K,
|
|
476
|
-
...
|
|
477
|
-
} =
|
|
485
|
+
...v
|
|
486
|
+
} = h;
|
|
478
487
|
if (V !== void 0) {
|
|
479
|
-
if (typeof V == "string" ?
|
|
488
|
+
if (typeof V == "string" ? a = !!N(
|
|
480
489
|
Object(r.formData.value),
|
|
481
490
|
V
|
|
482
|
-
) : typeof V == "function" ?
|
|
491
|
+
) : typeof V == "function" ? a = C(V(r)) : a = C(V), !a)
|
|
483
492
|
return t;
|
|
484
|
-
} else if (
|
|
485
|
-
if (
|
|
493
|
+
} else if (p !== void 0 && a !== void 0) {
|
|
494
|
+
if (a || (typeof p == "string" ? a = !!N(
|
|
486
495
|
Object(r.formData.value),
|
|
487
|
-
|
|
488
|
-
) : typeof
|
|
496
|
+
p
|
|
497
|
+
) : typeof p == "function" ? a = C(p(r)) : a = C(p), !a))
|
|
489
498
|
return t;
|
|
490
499
|
} else
|
|
491
|
-
|
|
492
|
-
const A = S ? x(
|
|
500
|
+
a = void 0;
|
|
501
|
+
const A = S ? x(l, {
|
|
493
502
|
schema: S
|
|
494
503
|
}) : void 0;
|
|
495
|
-
return
|
|
504
|
+
return c ? (t.push(
|
|
496
505
|
x(
|
|
497
|
-
|
|
506
|
+
s,
|
|
498
507
|
{
|
|
499
|
-
name:
|
|
500
|
-
is:
|
|
508
|
+
name: c,
|
|
509
|
+
is: d,
|
|
501
510
|
type: I,
|
|
502
511
|
defaultValue: W,
|
|
503
512
|
showValid: K,
|
|
504
|
-
props:
|
|
513
|
+
props: v
|
|
505
514
|
},
|
|
506
|
-
|
|
515
|
+
b ?? A
|
|
507
516
|
)
|
|
508
|
-
), t) :
|
|
517
|
+
), t) : d ? (t.push(
|
|
509
518
|
x(
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
519
|
+
d,
|
|
520
|
+
v,
|
|
521
|
+
b ?? A
|
|
513
522
|
)
|
|
514
523
|
), t) : (S && t.push(A), t);
|
|
515
524
|
},
|
|
516
525
|
[
|
|
517
|
-
(
|
|
526
|
+
(i = n == null ? void 0 : n.default) == null ? void 0 : i.call(n, {
|
|
518
527
|
formData: r == null ? void 0 : r.formData.value,
|
|
519
528
|
submit: r == null ? void 0 : r.submit,
|
|
529
|
+
validate: r == null ? void 0 : r.validate,
|
|
520
530
|
errors: r == null ? void 0 : r.errors.value,
|
|
521
531
|
status: r == null ? void 0 : r.status.value,
|
|
522
532
|
invalid: r == null ? void 0 : r.invalid.value
|
|
@@ -526,50 +536,50 @@ const ie = (e, o, i, s) => G({
|
|
|
526
536
|
};
|
|
527
537
|
}
|
|
528
538
|
});
|
|
529
|
-
return
|
|
530
|
-
}, B = (e,
|
|
531
|
-
const
|
|
539
|
+
return l;
|
|
540
|
+
}, B = (e, s = {}) => {
|
|
541
|
+
const l = Symbol(), o = Symbol(), n = Symbol(), { VvForm: r, errors: u, status: a, formData: i } = fe(
|
|
532
542
|
e,
|
|
533
|
-
|
|
534
|
-
o
|
|
535
|
-
), t = ce(
|
|
536
|
-
i,
|
|
543
|
+
l,
|
|
537
544
|
s
|
|
538
|
-
),
|
|
539
|
-
|
|
540
|
-
s,
|
|
541
|
-
a,
|
|
545
|
+
), t = ve(
|
|
546
|
+
l,
|
|
542
547
|
o
|
|
543
|
-
),
|
|
548
|
+
), m = le(
|
|
549
|
+
l,
|
|
550
|
+
o,
|
|
551
|
+
n,
|
|
552
|
+
s
|
|
553
|
+
), h = de(l, m);
|
|
544
554
|
return {
|
|
545
555
|
VvForm: r,
|
|
546
556
|
VvFormWrapper: t,
|
|
547
557
|
VvFormField: m,
|
|
548
|
-
VvFormTemplate:
|
|
549
|
-
formInjectionKey:
|
|
550
|
-
formWrapperInjectionKey:
|
|
551
|
-
formFieldInjectionKey:
|
|
558
|
+
VvFormTemplate: h,
|
|
559
|
+
formInjectionKey: l,
|
|
560
|
+
formWrapperInjectionKey: o,
|
|
561
|
+
formFieldInjectionKey: n,
|
|
552
562
|
errors: u,
|
|
553
|
-
status:
|
|
554
|
-
formData:
|
|
563
|
+
status: a,
|
|
564
|
+
formData: i
|
|
555
565
|
};
|
|
556
|
-
},
|
|
557
|
-
let
|
|
558
|
-
return e.schema && (
|
|
559
|
-
...
|
|
560
|
-
install(
|
|
561
|
-
|
|
566
|
+
}, Y = Symbol(), be = (e) => {
|
|
567
|
+
let s = {};
|
|
568
|
+
return e.schema && (s = B(e.schema, e)), {
|
|
569
|
+
...s,
|
|
570
|
+
install(l, { global: o = !1 } = {}) {
|
|
571
|
+
l.provide(Y, e), o && (l.config.globalProperties.$vvForm = e, s != null && s.VvForm && l.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && l.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && l.component("VvFormField", s.VvFormField), s != null && s.VvFormTemplate && l.component("VvFormTemplate", s.VvFormTemplate));
|
|
562
572
|
}
|
|
563
573
|
};
|
|
564
|
-
},
|
|
565
|
-
...O(
|
|
566
|
-
...
|
|
567
|
-
}) : B(e,
|
|
574
|
+
}, pe = (e, s = {}) => ee() ? B(e, {
|
|
575
|
+
...O(Y, {}),
|
|
576
|
+
...s
|
|
577
|
+
}) : B(e, s), ye = (e, s = {}) => B(e, s);
|
|
568
578
|
export {
|
|
569
579
|
f as FormFieldType,
|
|
570
|
-
|
|
571
|
-
|
|
580
|
+
be as createForm,
|
|
581
|
+
X as defaultObjectBySchema,
|
|
572
582
|
ye as formFactory,
|
|
573
|
-
|
|
574
|
-
|
|
583
|
+
Y as pluginInjectionKey,
|
|
584
|
+
pe as useForm
|
|
575
585
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(y,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(y=typeof globalThis<"u"?globalThis:y||self,r(y["@volverjs/form-vue"]={},y.Vue,y.VueUseCore,y.zod))})(this,function(y,r,M,x){"use strict";function I(e){return Array.isArray(e)}function Z(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function A(e){return typeof e=="string"}function k(e){return typeof e>"u"}const z=/^[0-9]+$/,U=["__proto__","prototype","constructor"];function C(e,s,f){const i=Z(f)?f:void 0;if(!W(e)||!A(s))return i;const a=K(s);if(a.length!==0){for(const t of a){if(t==="*")continue;const l=function(o){return o.map(u=>k(u)||G(u)?u:I(u)?l(u):u[t])};if(I(e)&&!z.test(t)?e=l(e):e=e[t],k(e)||G(e))break}return k(e)?i:e}}function _(e,s,f){if(!W(e)||!A(s))return;const i=K(s);if(i.length===0)return;const a=i.length;for(let t=0;t<a;t++){const l=i[t];if(t===a-1){e[l]=f;return}if(l==="*"&&I(e)){const o=i.slice(t+1).join(".");for(const u of e)_(u,o,f);return}k(e[l])&&(e[l]={}),e=e[l]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>U.indexOf(f)!==-1)?[]:s}var c=(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))(c||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,s,f,i)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(c).includes(a),default:c.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},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(a,{slots:t,emit:l}){const o=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(a.name))},set(d){n!=null&&n.formData&&(_(Object(n.formData.value),String(a.name),d),l("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{o.value===void 0&&a.defaultValue!==void 0&&(o.value=a.defaultValue)}),r.onBeforeUnmount(()=>{w(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(a.name);const n=r.inject(e),{props:h,name:b}=r.toRefs(a),p=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(a.name))}),m=r.computed(()=>{var d;return(d=p.value)==null?void 0:d._errors}),v=r.computed(()=>p.value!==void 0),w=r.watch(v,()=>{v.value?(l("invalid",m.value),u&&u.errors.value.set(a.name,{_errors:m.value})):(l("valid",o.value),u&&u.errors.value.delete(a.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=d=>{o.value=d},E=r.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=r.computed(()=>({...E.value,name:E.value.name??a.name,invalid:v.value,valid:a.showValid?!!(!v.value&&o.value):void 0,type:(d=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(d))return d})(a.type),invalidLabel:m.value,modelValue:o.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(b),errors:r.readonly(p)}),{component:r.computed(()=>{if(a.type===c.custom)return{render(){var d;return((d=t.default)==null?void 0:d.call(t,{modelValue:o.value,onUpdate:V,invalid:v.value,invalidLabel:m.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value}))??t.defalut}};if(!((i==null?void 0:i.lazyLoad)??a.lazyLoad)){let d;switch(a.type){case c.select:d=r.resolveComponent("VvSelect");break;case c.checkbox:d=r.resolveComponent("VvCheckbox");break;case c.radio:d=r.resolveComponent("VvRadio");break;case c.textarea:d=r.resolveComponent("VvTextarea");break;case c.radioGroup:d=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:d=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:d=r.resolveComponent("VvCombobox");break;default:d=r.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 r.defineAsyncComponent(async()=>{switch(i!=null&&i.sideEffects&&await Promise.resolve(i.sideEffects(a.type)),a.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:v}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===c.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),$=(e,s={})=>{const f=t=>{let l=t;for(;l instanceof x.ZodEffects;)l=l.innerType();return l},i=f(e);return{...(i instanceof x.ZodObject?i._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(i.shape).map(([t,l])=>{const o=s[t],u=f(l);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),o===null&&u instanceof x.ZodNullable)return[t,o];if(u instanceof x.ZodSchema){const h=l.safeParse(o);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,$(u,o&&typeof o=="object"?o:{})]:[t,n]}))}},P=(e,s,f)=>{const i=r.ref(),a=r.ref(),t=r.ref(),l=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(o,{emit:u}){t.value=$(e,r.toRaw(o.modelValue));const n=(f==null?void 0:f.continuosValidation)??o.continuosValidation;r.watch(()=>o.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),M.watchThrottled(t,m=>{(i.value||n)&&h(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??o.updateThrottle});const h=(m=t.value)=>{const v=e.safeParse(m);return v.success?(i.value=void 0,a.value=O.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(i.value=v.error.format(),a.value=O.invalid,u("invalid",i.value),!1)},b=()=>h()?(u("submit",t.value),!0):!1,p=r.computed(()=>a.value===O.invalid);return r.provide(s,{formData:t,submit:b,errors:r.readonly(i),status:r.readonly(a),invalid:p}),{formData:t,submit:b,errors:r.readonly(i),status:r.readonly(a),invalid:p}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var o,u;return((u=(o=this.$slots)==null?void 0:o.default)==null?void 0:u.call(o,{formData:this.formData,submit:this.submit,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:i,status:a,formData:t,VvForm:l}},T=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(i,{emit:a}){const t=r.inject(e),l=r.inject(s,void 0),o=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(i);r.provide(s,{name:r.readonly(n),errors:u,fields:o}),r.watch(o,b=>{l!=null&&l.fields&&b.forEach(p=>{l==null||l.fields.value.add(p)})},{deep:!0}),r.watch(()=>new Map(u.value),(b,p)=>{l!=null&&l.errors&&(Array.from(p.keys()).forEach(m=>{l.errors.value.delete(m)}),Array.from(b.keys()).forEach(m=>{const v=b.get(m);v&&l.errors.value.set(m,v)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?a("invalid"):a("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,invalid:h,fields:o,fieldsErrors:u}},render(){var i,a;return this.tag?r.h(this.tag,null,{default:()=>{var t,l;return((l=(t=this.$slots).default)==null?void 0:l.call(t,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((a=(i=this.$slots).default)==null?void 0:a.call(i,{invalid:this.invalid,formData:this.formData,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),R=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(i,{slots:a}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const l=typeof i.schema=="function"?i.schema(t):i.schema;let o;return()=>{var u;return l.reduce((n,h)=>{const b=typeof h=="function"?h(t):h,{vvIs:p,vvName:m,vvSlots:v,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:q,...d}=b;if(g!==void 0){if(typeof g=="string"?o=!!C(Object(t.formData.value),g):typeof g=="function"?o=r.unref(g(t)):o=r.unref(g),!o)return n}else if(V!==void 0&&o!==void 0){if(o||(typeof V=="string"?o=!!C(Object(t.formData.value),V):typeof V=="function"?o=r.unref(V(t)):o=r.unref(V),!o))return n}else o=void 0;const N=w?r.h(f,{schema:w}):void 0;return m?(n.push(r.h(s,{name:m,is:p,type:E,defaultValue:L,showValid:q,props:d},v??N)),n):p?(n.push(r.h(p,d,v??N)),n):(w&&n.push(N),n)},[(u=a==null?void 0:a.default)==null?void 0:u.call(a,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},S=(e,s={})=>{const f=Symbol(),i=Symbol(),a=Symbol(),{VvForm:t,errors:l,status:o,formData:u}=P(e,f,s),n=T(f,i),h=J(f,i,a,s),b=R(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:b,formInjectionKey:f,formWrapperInjectionKey:i,formFieldInjectionKey:a,errors:l,status:o,formData:u}},B=Symbol(),D=e=>{let s={};return e.schema&&(s=S(e.schema,e)),{...s,install(f,{global:i=!1}={}){f.provide(B,e),i&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},H=(e,s={})=>r.getCurrentInstance()?S(e,{...r.inject(B,{}),...s}):S(e,s),Q=(e,s={})=>S(e,s);y.FormFieldType=c,y.createForm=D,y.defaultObjectBySchema=$,y.formFactory=Q,y.pluginInjectionKey=B,y.useForm=H,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,Z,x){"use strict";function I(e){return Array.isArray(e)}function z(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function A(e){return typeof e=="string"}function k(e){return typeof e>"u"}const M=/^[0-9]+$/,U=["__proto__","prototype","constructor"];function C(e,s,f){const i=z(f)?f:void 0;if(!W(e)||!A(s))return i;const o=K(s);if(o.length!==0){for(const t of o){if(t==="*")continue;const l=function(a){return a.map(u=>k(u)||G(u)?u:I(u)?l(u):u[t])};if(I(e)&&!M.test(t)?e=l(e):e=e[t],k(e)||G(e))break}return k(e)?i:e}}function _(e,s,f){if(!W(e)||!A(s))return;const i=K(s);if(i.length===0)return;const o=i.length;for(let t=0;t<o;t++){const l=i[t];if(t===o-1){e[l]=f;return}if(l==="*"&&I(e)){const a=i.slice(t+1).join(".");for(const u of e)_(u,a,f);return}k(e[l])&&(e[l]={}),e=e[l]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>U.indexOf(f)!==-1)?[]:s}var d=(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))(d||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,s,f,i)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:o=>Object.values(d).includes(o),default:d.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},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(o,{slots:t,emit:l}){const a=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(o.name))},set(c){n!=null&&n.formData&&(_(Object(n.formData.value),String(o.name),c),l("update:modelValue",{newValue:a.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{a.value===void 0&&o.defaultValue!==void 0&&(a.value=o.defaultValue)}),r.onBeforeUnmount(()=>{w(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(o.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(o),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(o.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),w=r.watch(b,()=>{b.value?(l("invalid",v.value),u&&u.errors.value.set(o.name,{_errors:v.value})):(l("valid",a.value),u&&u.errors.value.delete(o.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{a.value=c},E=r.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=r.computed(()=>({...E.value,name:E.value.name??o.name,invalid:b.value,valid:o.showValid?!!(!b.value&&a.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(o.type),invalidLabel:v.value,modelValue:a.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(o.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:a.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((i==null?void 0:i.lazyLoad)??o.lazyLoad)){let c;switch(o.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(i!=null&&i.sideEffects&&await Promise.resolve(i.sideEffects(o.type)),o.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),$=(e,s={})=>{const f=t=>{let l=t;for(;l instanceof x.ZodEffects;)l=l.innerType();return l},i=f(e);return{...(i instanceof x.ZodObject?i._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(i.shape).map(([t,l])=>{const a=s[t],u=f(l);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),a===null&&u instanceof x.ZodNullable)return[t,a];if(u instanceof x.ZodSchema){const h=l.safeParse(a);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,$(u,a&&typeof a=="object"?a:{})]:[t,n]}))}},P=(e,s,f)=>{const i=r.ref(),o=r.ref(),t=r.ref(),l=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(a,{emit:u}){t.value=$(e,r.toRaw(a.modelValue)),r.watch(()=>a.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),Z.watchThrottled(t,m=>{((i.value||(f==null?void 0:f.continuosValidation))??a.continuosValidation)&&n(),(!m||!a.modelValue||JSON.stringify(m)!==JSON.stringify(a.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??a.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(i.value=void 0,o.value=O.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(i.value=v.error.format(),o.value=O.invalid,u("invalid",i.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>o.value===O.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(i),status:r.readonly(o),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(i),status:r.readonly(o),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var a,u;return((u=(a=this.$slots)==null?void 0:a.default)==null?void 0:u.call(a,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:i,status:o,formData:t,VvForm:l}},T=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(i,{emit:o}){const t=r.inject(e),l=r.inject(s,void 0),a=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(i);r.provide(s,{name:r.readonly(n),errors:u,fields:a}),r.watch(a,y=>{l!=null&&l.fields&&y.forEach(m=>{l==null||l.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{l!=null&&l.errors&&(Array.from(m.keys()).forEach(v=>{l.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&l.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?o("invalid"):o("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:h,fields:a,fieldsErrors:u}},render(){var i,o;return this.tag?r.h(this.tag,null,{default:()=>{var t,l;return((l=(t=this.$slots).default)==null?void 0:l.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((o=(i=this.$slots).default)==null?void 0:o.call(i,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),R=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(i,{slots:o}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const l=typeof i.schema=="function"?i.schema(t):i.schema;let a;return()=>{var u;return l.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:q,...c}=y;if(g!==void 0){if(typeof g=="string"?a=!!C(Object(t.formData.value),g):typeof g=="function"?a=r.unref(g(t)):a=r.unref(g),!a)return n}else if(V!==void 0&&a!==void 0){if(a||(typeof V=="string"?a=!!C(Object(t.formData.value),V):typeof V=="function"?a=r.unref(V(t)):a=r.unref(V),!a))return n}else a=void 0;const N=w?r.h(f,{schema:w}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:E,defaultValue:L,showValid:q,props:c},b??N)),n):m?(n.push(r.h(m,c,b??N)),n):(w&&n.push(N),n)},[(u=o==null?void 0:o.default)==null?void 0:u.call(o,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})])}}});return f},S=(e,s={})=>{const f=Symbol(),i=Symbol(),o=Symbol(),{VvForm:t,errors:l,status:a,formData:u}=P(e,f,s),n=T(f,i),h=J(f,i,o,s),y=R(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:i,formFieldInjectionKey:o,errors:l,status:a,formData:u}},B=Symbol(),H=e=>{let s={};return e.schema&&(s=S(e.schema,e)),{...s,install(f,{global:i=!1}={}){f.provide(B,e),i&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},Q=(e,s={})=>r.getCurrentInstance()?S(e,{...r.inject(B,{}),...s}):S(e,s),X=(e,s={})=>S(e,s);p.FormFieldType=d,p.createForm=H,p.defaultObjectBySchema=$,p.formFactory=X,p.pluginInjectionKey=B,p.useForm=Q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type InjectedFormData<Schema extends FormSchema> = {
|
|
|
28
28
|
formData: Ref<Partial<z.infer<Schema>> | undefined>
|
|
29
29
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
|
|
30
30
|
submit: () => boolean
|
|
31
|
+
validate: () => boolean
|
|
31
32
|
status: Readonly<Ref<FormStatus | undefined>>
|
|
32
33
|
invalid: Readonly<Ref<boolean>>
|
|
33
34
|
}
|
package/package.json
CHANGED
package/src/VvForm.ts
CHANGED
|
@@ -48,16 +48,14 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
emits: ['invalid', 'valid', 'submit', 'update:modelValue'],
|
|
51
|
-
expose: ['submit', 'errors', 'status'],
|
|
51
|
+
expose: ['submit', 'validate', 'errors', 'status', 'valid', 'invalid'],
|
|
52
52
|
setup(props, { emit }) {
|
|
53
53
|
formData.value = defaultObjectBySchema(
|
|
54
54
|
schema,
|
|
55
55
|
toRaw(props.modelValue),
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
options?.continuosValidation ?? props.continuosValidation
|
|
60
|
-
|
|
58
|
+
// clone modelValue and update formData
|
|
61
59
|
watch(
|
|
62
60
|
() => props.modelValue,
|
|
63
61
|
(newValue) => {
|
|
@@ -73,12 +71,16 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
73
71
|
},
|
|
74
72
|
{ deep: true },
|
|
75
73
|
)
|
|
76
|
-
|
|
74
|
+
|
|
75
|
+
// emit update:modelValue on formData change
|
|
77
76
|
watchThrottled(
|
|
78
77
|
formData,
|
|
79
78
|
(newValue) => {
|
|
80
|
-
if (
|
|
81
|
-
|
|
79
|
+
if (
|
|
80
|
+
(errors.value || options?.continuosValidation) ??
|
|
81
|
+
props.continuosValidation
|
|
82
|
+
) {
|
|
83
|
+
validate()
|
|
82
84
|
}
|
|
83
85
|
if (
|
|
84
86
|
!newValue ||
|
|
@@ -95,7 +97,8 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
95
97
|
},
|
|
96
98
|
)
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
// validate formData with safeParse
|
|
101
|
+
const validate = (value = formData.value) => {
|
|
99
102
|
const parseResult = schema.safeParse(value)
|
|
100
103
|
if (!parseResult.success) {
|
|
101
104
|
errors.value =
|
|
@@ -114,9 +117,9 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
114
117
|
return true
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
// submit
|
|
120
|
+
// emit submit event if form is valid
|
|
118
121
|
const submit = () => {
|
|
119
|
-
if (!
|
|
122
|
+
if (!validate()) {
|
|
120
123
|
return false
|
|
121
124
|
}
|
|
122
125
|
emit('submit', formData.value)
|
|
@@ -125,10 +128,11 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
125
128
|
|
|
126
129
|
const invalid = computed(() => status.value === FormStatus.invalid)
|
|
127
130
|
|
|
128
|
-
// provide
|
|
131
|
+
// provide data to children
|
|
129
132
|
provide(provideKey, {
|
|
130
133
|
formData,
|
|
131
134
|
submit,
|
|
135
|
+
validate,
|
|
132
136
|
errors: readonly(errors),
|
|
133
137
|
status: readonly(status),
|
|
134
138
|
invalid,
|
|
@@ -137,6 +141,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
137
141
|
return {
|
|
138
142
|
formData,
|
|
139
143
|
submit,
|
|
144
|
+
validate,
|
|
140
145
|
errors: readonly(errors),
|
|
141
146
|
status: readonly(status),
|
|
142
147
|
invalid,
|
|
@@ -153,6 +158,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
153
158
|
this.$slots?.default?.({
|
|
154
159
|
formData: this.formData,
|
|
155
160
|
submit: this.submit,
|
|
161
|
+
validate: this.validate,
|
|
156
162
|
errors: this.errors,
|
|
157
163
|
status: this.status,
|
|
158
164
|
invalid: this.invalid,
|
|
@@ -178,6 +184,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
178
184
|
? undefined
|
|
179
185
|
: Partial<TypeOf<Schema>> | undefined
|
|
180
186
|
submit: () => boolean
|
|
187
|
+
validate: () => boolean
|
|
181
188
|
errors: Readonly<
|
|
182
189
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
183
190
|
>
|
package/src/VvFormField.ts
CHANGED
|
@@ -225,6 +225,8 @@ export const defineFormField = <Schema extends FormSchema>(
|
|
|
225
225
|
slots.default?.({
|
|
226
226
|
modelValue: modelValue.value,
|
|
227
227
|
onUpdate,
|
|
228
|
+
submit: injectedFormData?.submit,
|
|
229
|
+
validate: injectedFormData?.validate,
|
|
228
230
|
invalid: invalid.value,
|
|
229
231
|
invalidLabel: invalidLabel.value,
|
|
230
232
|
formData: injectedFormData?.formData.value,
|
package/src/VvFormTemplate.ts
CHANGED
|
@@ -144,6 +144,7 @@ export const defineFormTemplate = <Schema extends FormSchema>(
|
|
|
144
144
|
templateSlots?.default?.({
|
|
145
145
|
formData: injectedFormData?.formData.value,
|
|
146
146
|
submit: injectedFormData?.submit,
|
|
147
|
+
validate: injectedFormData?.validate,
|
|
147
148
|
errors: injectedFormData?.errors.value,
|
|
148
149
|
status: injectedFormData?.status.value,
|
|
149
150
|
invalid: injectedFormData?.invalid.value,
|
|
@@ -166,6 +167,7 @@ export const defineFormTemplate = <Schema extends FormSchema>(
|
|
|
166
167
|
? undefined
|
|
167
168
|
: Partial<TypeOf<Schema>> | undefined
|
|
168
169
|
submit: () => boolean
|
|
170
|
+
validate: () => boolean
|
|
169
171
|
errors: Readonly<
|
|
170
172
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
171
173
|
>
|
package/src/VvFormWrapper.ts
CHANGED
|
@@ -103,6 +103,8 @@ export const defineFormWrapper = <Schema extends FormSchema>(
|
|
|
103
103
|
return {
|
|
104
104
|
formData: injectedFormData?.formData,
|
|
105
105
|
errors: injectedFormData?.errors,
|
|
106
|
+
submit: injectedFormData?.submit,
|
|
107
|
+
validate: injectedFormData?.validate,
|
|
106
108
|
invalid,
|
|
107
109
|
fields,
|
|
108
110
|
fieldsErrors,
|
|
@@ -115,6 +117,8 @@ export const defineFormWrapper = <Schema extends FormSchema>(
|
|
|
115
117
|
this.$slots.default?.({
|
|
116
118
|
invalid: this.invalid,
|
|
117
119
|
formData: this.formData,
|
|
120
|
+
submit: this.submit,
|
|
121
|
+
validate: this.validate,
|
|
118
122
|
errors: this.errors,
|
|
119
123
|
fieldsErrors: this.fieldsErrors,
|
|
120
124
|
}) ?? this.$slots.defalut,
|
|
@@ -124,6 +128,8 @@ export const defineFormWrapper = <Schema extends FormSchema>(
|
|
|
124
128
|
this.$slots.default?.({
|
|
125
129
|
invalid: this.invalid,
|
|
126
130
|
formData: this.formData,
|
|
131
|
+
submit: this.submit,
|
|
132
|
+
validate: this.validate,
|
|
127
133
|
errors: this.errors,
|
|
128
134
|
fieldsErrors: this.fieldsErrors,
|
|
129
135
|
}) ?? this.$slots.defalut
|
|
@@ -143,6 +149,8 @@ export const defineFormWrapper = <Schema extends FormSchema>(
|
|
|
143
149
|
| undefined
|
|
144
150
|
? undefined
|
|
145
151
|
: Partial<TypeOf<Schema>> | undefined
|
|
152
|
+
submit: () => boolean
|
|
153
|
+
validate: () => boolean
|
|
146
154
|
errors: Readonly<
|
|
147
155
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
148
156
|
>
|
package/src/types.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type InjectedFormData<Schema extends FormSchema> = {
|
|
|
28
28
|
formData: Ref<Partial<z.infer<Schema>> | undefined>
|
|
29
29
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>
|
|
30
30
|
submit: () => boolean
|
|
31
|
+
validate: () => boolean
|
|
31
32
|
status: Readonly<Ref<FormStatus | undefined>>
|
|
32
33
|
invalid: Readonly<Ref<boolean>>
|
|
33
34
|
}
|