@volverjs/form-vue 1.0.0-beta.23 → 1.0.0-beta.25
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 +8 -6
- package/dist/VvForm.d.ts +3 -3
- package/dist/index.d.ts +13 -12
- package/dist/index.es.js +215 -215
- package/dist/index.umd.js +1 -1
- package/package.json +6 -6
- package/src/VvFormFieldsGroup.ts +1 -1
- package/src/index.ts +6 -1
package/README.md
CHANGED
|
@@ -239,14 +239,16 @@ The wrapper status is invalid if at least one of the fields inside it is invalid
|
|
|
239
239
|
```vue
|
|
240
240
|
<template>
|
|
241
241
|
<VvForm>
|
|
242
|
+
<!-- main VvFormWrapper -->
|
|
242
243
|
<VvFormWrapper v-slot="{ invalid }">
|
|
244
|
+
<!-- add VvFormFields to wrapper -->
|
|
243
245
|
<div class="form-section">
|
|
244
246
|
<span v-if="invalid">There is a validation error</span>
|
|
245
|
-
<!--
|
|
247
|
+
<!-- nested VvFormWrapper -->
|
|
246
248
|
<VvFormWrapper v-slot="{ invalid: groupInvalid }">
|
|
247
249
|
<div class="form-section__group">
|
|
248
250
|
<span v-if="groupInvalid">There is a validation error</span>
|
|
249
|
-
<!--
|
|
251
|
+
<!-- add VvFormFields to nested wrapper -->
|
|
250
252
|
</div>
|
|
251
253
|
</VvFormWrapper>
|
|
252
254
|
</div>
|
|
@@ -279,7 +281,7 @@ It automatically bind the form data through the `name` attribute. For nested obj
|
|
|
279
281
|
@input="onUpdate"
|
|
280
282
|
>
|
|
281
283
|
<small v-if="invalid" id="last-name-alert" role="alert">
|
|
282
|
-
{{ invalidLabel
|
|
284
|
+
{{ invalidLabel }}
|
|
283
285
|
</small>
|
|
284
286
|
</VvFormField>
|
|
285
287
|
</VvForm>
|
|
@@ -311,7 +313,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
|
|
|
311
313
|
<VvForm>
|
|
312
314
|
<VvFormFieldsGroup
|
|
313
315
|
v-slot="{ modelValue, invalids, invalidLabels, onUpdateField }"
|
|
314
|
-
:
|
|
316
|
+
:names="['firstName', 'lastName']"
|
|
315
317
|
>
|
|
316
318
|
<fieldset>
|
|
317
319
|
<p>
|
|
@@ -326,7 +328,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
|
|
|
326
328
|
@input="onUpdateField('firstName', $event)"
|
|
327
329
|
>
|
|
328
330
|
<small v-if="invalids.firstName" id="first-name-alert" role="alert">
|
|
329
|
-
{{ invalidLabels?.firstName
|
|
331
|
+
{{ invalidLabels?.firstName }}
|
|
330
332
|
</small>
|
|
331
333
|
</p>
|
|
332
334
|
<p>
|
|
@@ -341,7 +343,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
|
|
|
341
343
|
@input="onUpdateField('lastName', $event)"
|
|
342
344
|
>
|
|
343
345
|
<small v-if="invalids.lastName" id="last-name-alert" role="alert">
|
|
344
|
-
{{ invalidLabels?.lastName
|
|
346
|
+
{{ invalidLabels?.lastName }}
|
|
345
347
|
</small>
|
|
346
348
|
</p>
|
|
347
349
|
</fieldset>
|
package/dist/VvForm.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function defineForm<Schema extends FormSchema>(schema: Schema, pr
|
|
|
6
6
|
clear: () => void;
|
|
7
7
|
errors: import('vue').Ref<z.inferFormattedError<Schema, string> | undefined, z.inferFormattedError<Schema, string> | undefined>;
|
|
8
8
|
formData: import('vue').Ref<Partial<z.TypeOf<Schema> | undefined>, Partial<z.TypeOf<Schema> | undefined>>;
|
|
9
|
-
ignoreUpdates: import('@vueuse/
|
|
9
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
10
10
|
invalid: import('vue').ComputedRef<boolean>;
|
|
11
11
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
12
12
|
reset: () => void;
|
|
@@ -39,7 +39,7 @@ export declare function defineForm<Schema extends FormSchema>(schema: Schema, pr
|
|
|
39
39
|
clear: () => void;
|
|
40
40
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<z.inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
41
41
|
formData: import('vue').Ref<Partial<z.TypeOf<Schema> | undefined>, Partial<z.TypeOf<Schema> | undefined>>;
|
|
42
|
-
ignoreUpdates: import('@vueuse/
|
|
42
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
43
43
|
invalid: import('vue').ComputedRef<boolean>;
|
|
44
44
|
isReadonly: import('vue').Ref<boolean, boolean>;
|
|
45
45
|
reset: () => void;
|
|
@@ -85,7 +85,7 @@ export declare function defineForm<Schema extends FormSchema>(schema: Schema, pr
|
|
|
85
85
|
default: {
|
|
86
86
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<z.inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
87
87
|
formData: import('vue').Ref<Partial<z.TypeOf<Schema> | undefined>, Partial<z.TypeOf<Schema> | undefined>>;
|
|
88
|
-
ignoreUpdates: import('@vueuse/
|
|
88
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
89
89
|
invalid: import('vue').ComputedRef<boolean>;
|
|
90
90
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
91
91
|
status: Readonly<import('vue').Ref<FormStatus | undefined, FormStatus | undefined>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { InjectionKey, Plugin } from 'vue';
|
|
|
2
2
|
import { AnyZodObject } from 'zod';
|
|
3
3
|
import { defineForm } from './VvForm';
|
|
4
4
|
import { defineFormField } from './VvFormField';
|
|
5
|
+
import { defineFormFieldsGroup } from './VvFormFieldsGroup';
|
|
5
6
|
import { defineFormWrapper } from './VvFormWrapper';
|
|
6
|
-
import { defineFormTemplate } from './VvFormTemplate';
|
|
7
7
|
import { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormTemplateItem, Path, PathValue, FormSchema, FormTemplate } from './types';
|
|
8
8
|
export declare const pluginInjectionKey: InjectionKey<FormPluginOptions>;
|
|
9
9
|
export declare function createForm(options: FormPluginOptions): Plugin & Partial<ReturnType<typeof useForm>>;
|
|
@@ -14,7 +14,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
14
14
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>;
|
|
15
15
|
formInjectionKey: InjectionKey<InjectedFormData<Schema>>;
|
|
16
16
|
formWrapperInjectionKey: InjectionKey<InjectedFormWrapperData<Schema>>;
|
|
17
|
-
ignoreUpdates: import('@vueuse/
|
|
17
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
18
18
|
invalid: import('vue').ComputedRef<boolean>;
|
|
19
19
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
20
20
|
reset: () => void;
|
|
@@ -47,7 +47,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
47
47
|
clear: () => void;
|
|
48
48
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined>>;
|
|
49
49
|
formData: import('vue').Ref<Partial<import('zod').TypeOf<Schema> | undefined>, Partial<import('zod').TypeOf<Schema> | undefined>>;
|
|
50
|
-
ignoreUpdates: import('@vueuse/
|
|
50
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
51
51
|
invalid: import('vue').ComputedRef<boolean>;
|
|
52
52
|
isReadonly: import('vue').Ref<boolean, boolean>;
|
|
53
53
|
reset: () => void;
|
|
@@ -93,7 +93,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
93
93
|
default: {
|
|
94
94
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined>>;
|
|
95
95
|
formData: import('vue').Ref<Partial<import('zod').TypeOf<Schema> | undefined>, Partial<import('zod').TypeOf<Schema> | undefined>>;
|
|
96
|
-
ignoreUpdates: import('@vueuse/
|
|
96
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
97
97
|
invalid: import('vue').ComputedRef<boolean>;
|
|
98
98
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
99
99
|
status: Readonly<import('vue').Ref<import('./enums').FormStatus | undefined, import('./enums').FormStatus | undefined>>;
|
|
@@ -431,7 +431,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
431
431
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<AnyZodObject>>;
|
|
432
432
|
formInjectionKey: InjectionKey<InjectedFormData<AnyZodObject>>;
|
|
433
433
|
formWrapperInjectionKey: InjectionKey<InjectedFormWrapperData<AnyZodObject>>;
|
|
434
|
-
ignoreUpdates: import('@vueuse/
|
|
434
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
435
435
|
invalid: import('vue').ComputedRef<boolean>;
|
|
436
436
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
437
437
|
reset: () => void;
|
|
@@ -480,7 +480,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
480
480
|
} | undefined>, Partial<{
|
|
481
481
|
[x: string]: any;
|
|
482
482
|
} | undefined>>;
|
|
483
|
-
ignoreUpdates: import('@vueuse/
|
|
483
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
484
484
|
invalid: import('vue').ComputedRef<boolean>;
|
|
485
485
|
isReadonly: import('vue').Ref<boolean, boolean>;
|
|
486
486
|
reset: () => void;
|
|
@@ -542,7 +542,7 @@ export declare function useForm<Schema extends FormSchema>(schema: Schema, optio
|
|
|
542
542
|
} | undefined>, Partial<{
|
|
543
543
|
[x: string]: any;
|
|
544
544
|
} | undefined>>;
|
|
545
|
-
ignoreUpdates: import('@vueuse/
|
|
545
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
546
546
|
invalid: import('vue').ComputedRef<boolean>;
|
|
547
547
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
548
548
|
status: Readonly<import('vue').Ref<import('./enums').FormStatus | undefined, import('./enums').FormStatus | undefined>>;
|
|
@@ -934,8 +934,9 @@ export { defaultObjectBySchema } from './utils';
|
|
|
934
934
|
type FormComponent = ReturnType<typeof defineForm>;
|
|
935
935
|
type FormWrapperComponent = ReturnType<typeof defineFormWrapper>;
|
|
936
936
|
type FormFieldComponent = ReturnType<typeof defineFormField>;
|
|
937
|
-
type
|
|
938
|
-
|
|
937
|
+
type FormFieldsGroupComponent = ReturnType<typeof defineFormFieldsGroup>;
|
|
938
|
+
type FormTemplateComponent = ReturnType<typeof defineFormFieldsGroup>;
|
|
939
|
+
export type { FormComponent, FormComposableOptions, FormFieldComponent, FormFieldsGroupComponent, FormPluginOptions, FormSchema, FormTemplate, FormTemplateComponent, FormTemplateItem, FormWrapperComponent, InjectedFormData, InjectedFormFieldData, InjectedFormWrapperData, Path, PathValue, };
|
|
939
940
|
/**
|
|
940
941
|
* @deprecated Use `useForm()` instead
|
|
941
942
|
*/
|
|
@@ -946,7 +947,7 @@ export declare function formFactory<Schema extends FormSchema>(schema: Schema, o
|
|
|
946
947
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>;
|
|
947
948
|
formInjectionKey: InjectionKey<InjectedFormData<Schema>>;
|
|
948
949
|
formWrapperInjectionKey: InjectionKey<InjectedFormWrapperData<Schema>>;
|
|
949
|
-
ignoreUpdates: import('@vueuse/
|
|
950
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
950
951
|
invalid: import('vue').ComputedRef<boolean>;
|
|
951
952
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
952
953
|
reset: () => void;
|
|
@@ -979,7 +980,7 @@ export declare function formFactory<Schema extends FormSchema>(schema: Schema, o
|
|
|
979
980
|
clear: () => void;
|
|
980
981
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined>>;
|
|
981
982
|
formData: import('vue').Ref<Partial<import('zod').TypeOf<Schema> | undefined>, Partial<import('zod').TypeOf<Schema> | undefined>>;
|
|
982
|
-
ignoreUpdates: import('@vueuse/
|
|
983
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
983
984
|
invalid: import('vue').ComputedRef<boolean>;
|
|
984
985
|
isReadonly: import('vue').Ref<boolean, boolean>;
|
|
985
986
|
reset: () => void;
|
|
@@ -1025,7 +1026,7 @@ export declare function formFactory<Schema extends FormSchema>(schema: Schema, o
|
|
|
1025
1026
|
default: {
|
|
1026
1027
|
errors: Readonly<import('vue').Ref<import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined, import('vue').DeepReadonly<import('zod').inferFormattedError<Schema, string>> | undefined>>;
|
|
1027
1028
|
formData: import('vue').Ref<Partial<import('zod').TypeOf<Schema> | undefined>, Partial<import('zod').TypeOf<Schema> | undefined>>;
|
|
1028
|
-
ignoreUpdates: import('@vueuse/
|
|
1029
|
+
ignoreUpdates: import('@vueuse/core').IgnoredUpdater;
|
|
1029
1030
|
invalid: import('vue').ComputedRef<boolean>;
|
|
1030
1031
|
readonly: import('vue').Ref<boolean, boolean>;
|
|
1031
1032
|
status: Readonly<import('vue').Ref<import('./enums').FormStatus | undefined, import('./enums').FormStatus | undefined>>;
|
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ref as C, computed as O, readonly as K, defineComponent as M, toRaw as
|
|
1
|
+
import { ref as C, computed as O, readonly as K, defineComponent as M, toRaw as R, watch as L, isProxy as fe, onMounted as j, provide as Y, h as U, withModifiers as re, toRefs as F, inject as _, onBeforeUnmount as le, unref as Z, resolveComponent as N, defineAsyncComponent as ve, getCurrentInstance as de } from "vue";
|
|
2
2
|
import { watchIgnorable as ce, throttleFilter as ye } from "@vueuse/core";
|
|
3
|
-
import { ZodObject as H, ZodDefault as
|
|
4
|
-
var
|
|
5
|
-
function J(e,
|
|
3
|
+
import { ZodObject as H, ZodDefault as me, ZodNullable as he, ZodSchema as be, ZodArray as pe, ZodRecord as Ve, ZodEffects as te, ZodOptional as ae, ZodError as ge } from "zod";
|
|
4
|
+
var h = /* @__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 = "datetime-local", 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))(h || {}), B = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e))(B || {});
|
|
5
|
+
function J(e, s = {}) {
|
|
6
6
|
const r = (d) => {
|
|
7
7
|
let l = d;
|
|
8
8
|
for (; l instanceof te; )
|
|
@@ -15,13 +15,13 @@ function J(e, o = {}) {
|
|
|
15
15
|
return l instanceof ae;
|
|
16
16
|
}, t = r(e);
|
|
17
17
|
return {
|
|
18
|
-
...(t instanceof H ? t._def.unknownKeys === "passthrough" : !1) ?
|
|
18
|
+
...(t instanceof H ? t._def.unknownKeys === "passthrough" : !1) ? s : {},
|
|
19
19
|
...Object.fromEntries(
|
|
20
20
|
Object.entries(t.shape).map(
|
|
21
21
|
([d, l]) => {
|
|
22
|
-
const f =
|
|
22
|
+
const f = s[d], p = v(l);
|
|
23
23
|
let u = r(l), y;
|
|
24
|
-
if (u instanceof
|
|
24
|
+
if (u instanceof me && (y = u._def.defaultValue(), u = u._def.innerType), f === null && u instanceof he)
|
|
25
25
|
return [d, f];
|
|
26
26
|
if (f == null && p)
|
|
27
27
|
return [d, y];
|
|
@@ -36,9 +36,9 @@ function J(e, o = {}) {
|
|
|
36
36
|
return [
|
|
37
37
|
d,
|
|
38
38
|
f.map(
|
|
39
|
-
(
|
|
39
|
+
(m) => J(
|
|
40
40
|
b,
|
|
41
|
-
|
|
41
|
+
m && typeof m == "object" ? m : void 0
|
|
42
42
|
)
|
|
43
43
|
)
|
|
44
44
|
];
|
|
@@ -46,7 +46,7 @@ function J(e, o = {}) {
|
|
|
46
46
|
if (u instanceof Ve && f) {
|
|
47
47
|
const b = r(u._def.valueType);
|
|
48
48
|
if (b instanceof H)
|
|
49
|
-
return [d, Object.keys(f).reduce((
|
|
49
|
+
return [d, Object.keys(f).reduce((m, n) => (m[n] = J(b, f[n]), m), {})];
|
|
50
50
|
}
|
|
51
51
|
return u instanceof H ? [
|
|
52
52
|
d,
|
|
@@ -60,28 +60,28 @@ function J(e, o = {}) {
|
|
|
60
60
|
)
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
function Oe(e,
|
|
64
|
-
const t = C(), a = C(), d = O(() => a.value ===
|
|
63
|
+
function Oe(e, s, r, v) {
|
|
64
|
+
const t = C(), a = C(), d = O(() => a.value === B.invalid), l = C(), f = C(!1);
|
|
65
65
|
let p;
|
|
66
66
|
const u = async (k = l.value, g) => {
|
|
67
67
|
if (p = g, f.value)
|
|
68
68
|
return !0;
|
|
69
69
|
const V = await e.safeParseAsync(k);
|
|
70
70
|
if (!V.success) {
|
|
71
|
-
if (a.value =
|
|
71
|
+
if (a.value = B.invalid, !g)
|
|
72
72
|
return t.value = V.error.format(), !1;
|
|
73
|
-
const
|
|
74
|
-
return
|
|
73
|
+
const i = V.error.issues.filter((W) => g.has(W.path.join(".")));
|
|
74
|
+
return i.length ? (t.value = new ge(i).format(), !1) : (t.value = void 0, !0);
|
|
75
75
|
}
|
|
76
|
-
return t.value = void 0, a.value =
|
|
76
|
+
return t.value = void 0, a.value = B.valid, l.value = V.data, !0;
|
|
77
77
|
}, y = () => {
|
|
78
78
|
t.value = void 0, a.value = void 0, p = void 0;
|
|
79
79
|
}, b = () => {
|
|
80
|
-
l.value = J(e), y(), a.value =
|
|
81
|
-
},
|
|
80
|
+
l.value = J(e), y(), a.value = B.reset;
|
|
81
|
+
}, m = async () => f.value || !await u() ? !1 : (a.value = B.submitting, !0), { ignoreUpdates: n, stop: w } = ce(
|
|
82
82
|
l,
|
|
83
83
|
() => {
|
|
84
|
-
a.value =
|
|
84
|
+
a.value = B.updated;
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
deep: !0,
|
|
@@ -136,60 +136,60 @@ function Oe(e, o, r, v) {
|
|
|
136
136
|
setup(k, { emit: g }) {
|
|
137
137
|
return l.value = J(
|
|
138
138
|
e,
|
|
139
|
-
|
|
140
|
-
),
|
|
139
|
+
R(k.modelValue)
|
|
140
|
+
), L(
|
|
141
141
|
() => k.modelValue,
|
|
142
142
|
(V) => {
|
|
143
143
|
if (V) {
|
|
144
|
-
const
|
|
145
|
-
if (JSON.stringify(
|
|
144
|
+
const i = fe(V) ? R(V) : V;
|
|
145
|
+
if (JSON.stringify(i) === JSON.stringify(R(l.value)))
|
|
146
146
|
return;
|
|
147
|
-
l.value = typeof (
|
|
147
|
+
l.value = typeof (i == null ? void 0 : i.clone) == "function" ? i.clone() : JSON.parse(JSON.stringify(i));
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
150
|
{ deep: !0 }
|
|
151
|
-
),
|
|
152
|
-
var
|
|
153
|
-
if (V ===
|
|
154
|
-
const
|
|
155
|
-
g("invalid",
|
|
151
|
+
), L(a, async (V) => {
|
|
152
|
+
var i, W, A, $, q, T;
|
|
153
|
+
if (V === B.invalid) {
|
|
154
|
+
const G = R(t.value);
|
|
155
|
+
g("invalid", G), (i = r == null ? void 0 : r.onInvalid) == null || i.call(
|
|
156
156
|
r,
|
|
157
|
-
|
|
157
|
+
G
|
|
158
158
|
);
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
-
if (V ===
|
|
162
|
-
const
|
|
163
|
-
g("valid",
|
|
161
|
+
if (V === B.valid) {
|
|
162
|
+
const G = R(l.value);
|
|
163
|
+
g("valid", G), (W = r == null ? void 0 : r.onValid) == null || W.call(r, G), g("update:modelValue", G), (A = r == null ? void 0 : r.onUpdate) == null || A.call(r, G);
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
if (V ===
|
|
167
|
-
const
|
|
168
|
-
g("submit",
|
|
166
|
+
if (V === B.submitting) {
|
|
167
|
+
const G = R(l.value);
|
|
168
|
+
g("submit", G), ($ = r == null ? void 0 : r.onSubmit) == null || $.call(r, G);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
if (V ===
|
|
172
|
-
const
|
|
173
|
-
g("reset",
|
|
171
|
+
if (V === B.reset) {
|
|
172
|
+
const G = R(l.value);
|
|
173
|
+
g("reset", G), (q = r == null ? void 0 : r.onReset) == null || q.call(r, G);
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
|
-
if (V ===
|
|
176
|
+
if (V === B.updated) {
|
|
177
177
|
if ((t.value || r != null && r.continuousValidation || k.continuousValidation) && await u(void 0, p), !l.value || !k.modelValue || JSON.stringify(l.value) !== JSON.stringify(k.modelValue)) {
|
|
178
|
-
const
|
|
179
|
-
g("update:modelValue",
|
|
178
|
+
const G = R(l.value);
|
|
179
|
+
g("update:modelValue", G), (T = r == null ? void 0 : r.onUpdate) == null || T.call(r, G);
|
|
180
180
|
}
|
|
181
|
-
a.value ===
|
|
181
|
+
a.value === B.updated && (a.value = B.unknown);
|
|
182
182
|
}
|
|
183
183
|
}), j(() => {
|
|
184
184
|
f.value = k.readonly;
|
|
185
|
-
}),
|
|
185
|
+
}), L(
|
|
186
186
|
() => k.readonly,
|
|
187
187
|
(V) => {
|
|
188
188
|
f.value = V;
|
|
189
189
|
}
|
|
190
|
-
),
|
|
190
|
+
), L(f, (V) => {
|
|
191
191
|
V !== k.readonly && g("update:readonly", f.value);
|
|
192
|
-
}), Y(
|
|
192
|
+
}), Y(s, {
|
|
193
193
|
clear: y,
|
|
194
194
|
errors: x,
|
|
195
195
|
formData: l,
|
|
@@ -199,7 +199,7 @@ function Oe(e, o, r, v) {
|
|
|
199
199
|
reset: b,
|
|
200
200
|
status: E,
|
|
201
201
|
stopUpdatesWatch: w,
|
|
202
|
-
submit:
|
|
202
|
+
submit: m,
|
|
203
203
|
validate: u
|
|
204
204
|
}), {
|
|
205
205
|
clear: y,
|
|
@@ -211,7 +211,7 @@ function Oe(e, o, r, v) {
|
|
|
211
211
|
reset: b,
|
|
212
212
|
status: E,
|
|
213
213
|
stopUpdatesWatch: w,
|
|
214
|
-
submit:
|
|
214
|
+
submit: m,
|
|
215
215
|
validate: u
|
|
216
216
|
};
|
|
217
217
|
},
|
|
@@ -228,18 +228,18 @@ function Oe(e, o, r, v) {
|
|
|
228
228
|
reset: b,
|
|
229
229
|
status: E,
|
|
230
230
|
stopUpdatesWatch: w,
|
|
231
|
-
submit:
|
|
231
|
+
submit: m,
|
|
232
232
|
validate: u
|
|
233
233
|
})) ?? this.$slots.default;
|
|
234
234
|
};
|
|
235
|
-
return
|
|
235
|
+
return U(
|
|
236
236
|
this.tag,
|
|
237
237
|
{
|
|
238
238
|
onSubmit: re(this.submit, ["prevent"]),
|
|
239
239
|
onReset: re(this.reset, ["prevent"])
|
|
240
240
|
},
|
|
241
241
|
(this.template ?? (r == null ? void 0 : r.template)) && v ? [
|
|
242
|
-
|
|
242
|
+
U(
|
|
243
243
|
v,
|
|
244
244
|
{
|
|
245
245
|
schema: this.template ?? (r == null ? void 0 : r.template)
|
|
@@ -264,7 +264,7 @@ function Oe(e, o, r, v) {
|
|
|
264
264
|
reset: b,
|
|
265
265
|
status: a,
|
|
266
266
|
stopUpdatesWatch: w,
|
|
267
|
-
submit:
|
|
267
|
+
submit: m,
|
|
268
268
|
validate: u,
|
|
269
269
|
VvForm: S
|
|
270
270
|
};
|
|
@@ -288,11 +288,11 @@ function Q(e) {
|
|
|
288
288
|
return typeof e > "u";
|
|
289
289
|
}
|
|
290
290
|
const xe = /^[0-9]+$/, ke = ["__proto__", "prototype", "constructor"];
|
|
291
|
-
function z(e,
|
|
291
|
+
function z(e, s, r) {
|
|
292
292
|
const v = we(r) ? r : void 0;
|
|
293
|
-
if (!ne(e) || !se(
|
|
293
|
+
if (!ne(e) || !se(s))
|
|
294
294
|
return v;
|
|
295
|
-
const t = ie(
|
|
295
|
+
const t = ie(s);
|
|
296
296
|
if (t.length !== 0) {
|
|
297
297
|
for (const a of t) {
|
|
298
298
|
if (a === "*")
|
|
@@ -306,10 +306,10 @@ function z(e, o, r) {
|
|
|
306
306
|
return Q(e) ? v : e;
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
function ee(e,
|
|
310
|
-
if (!ne(e) || !se(
|
|
309
|
+
function ee(e, s, r) {
|
|
310
|
+
if (!ne(e) || !se(s))
|
|
311
311
|
return;
|
|
312
|
-
const v = ie(
|
|
312
|
+
const v = ie(s);
|
|
313
313
|
if (v.length === 0)
|
|
314
314
|
return;
|
|
315
315
|
const t = v.length;
|
|
@@ -329,17 +329,17 @@ function ee(e, o, r) {
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
function ie(e) {
|
|
332
|
-
const
|
|
333
|
-
return
|
|
332
|
+
const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((r) => !!r);
|
|
333
|
+
return s.some((r) => ke.indexOf(r) !== -1) ? [] : s;
|
|
334
334
|
}
|
|
335
|
-
function Se(e,
|
|
335
|
+
function Se(e, s, r, v) {
|
|
336
336
|
return M({
|
|
337
337
|
name: "VvFormField",
|
|
338
338
|
props: {
|
|
339
339
|
type: {
|
|
340
340
|
type: String,
|
|
341
|
-
validator: (t) => Object.values(
|
|
342
|
-
default:
|
|
341
|
+
validator: (t) => Object.values(h).includes(t),
|
|
342
|
+
default: h.custom
|
|
343
343
|
},
|
|
344
344
|
is: {
|
|
345
345
|
type: [Object, String],
|
|
@@ -387,7 +387,7 @@ function Se(e, o, r, v) {
|
|
|
387
387
|
],
|
|
388
388
|
slots: Object,
|
|
389
389
|
setup(t, { slots: a, emit: d }) {
|
|
390
|
-
const { props: l, name: f } = F(t), p = _(
|
|
390
|
+
const { props: l, name: f } = F(t), p = _(s, void 0);
|
|
391
391
|
p && p.fields.value.add(t.name);
|
|
392
392
|
const u = _(e), y = O({
|
|
393
393
|
get() {
|
|
@@ -397,11 +397,11 @@ function Se(e, o, r, v) {
|
|
|
397
397
|
String(t.name)
|
|
398
398
|
);
|
|
399
399
|
},
|
|
400
|
-
set(
|
|
400
|
+
set(i) {
|
|
401
401
|
u != null && u.formData && (ee(
|
|
402
402
|
new Object(u.formData.value),
|
|
403
403
|
String(t.name),
|
|
404
|
-
|
|
404
|
+
i
|
|
405
405
|
), d("update:modelValue", {
|
|
406
406
|
newValue: y.value,
|
|
407
407
|
formData: u == null ? void 0 : u.formData
|
|
@@ -414,10 +414,10 @@ function Se(e, o, r, v) {
|
|
|
414
414
|
const b = O(() => {
|
|
415
415
|
if (u != null && u.errors.value)
|
|
416
416
|
return z(u.errors.value, String(t.name));
|
|
417
|
-
}),
|
|
418
|
-
var
|
|
419
|
-
return (
|
|
420
|
-
}), n = O(() => b.value !== void 0), w =
|
|
417
|
+
}), m = O(() => {
|
|
418
|
+
var i;
|
|
419
|
+
return (i = b.value) == null ? void 0 : i._errors;
|
|
420
|
+
}), n = O(() => b.value !== void 0), w = L(n, () => {
|
|
421
421
|
if (n.value) {
|
|
422
422
|
d("invalid", b.value), p && p.errors.value.set(
|
|
423
423
|
String(t.name),
|
|
@@ -428,7 +428,7 @@ function Se(e, o, r, v) {
|
|
|
428
428
|
d("valid", y.value), p && p.errors.value.delete(
|
|
429
429
|
t.name
|
|
430
430
|
);
|
|
431
|
-
}), x =
|
|
431
|
+
}), x = L(
|
|
432
432
|
() => u == null ? void 0 : u.formData,
|
|
433
433
|
() => {
|
|
434
434
|
d("update:formData", u == null ? void 0 : u.formData);
|
|
@@ -438,12 +438,12 @@ function Se(e, o, r, v) {
|
|
|
438
438
|
le(() => {
|
|
439
439
|
w(), x();
|
|
440
440
|
});
|
|
441
|
-
const E = (
|
|
442
|
-
|
|
441
|
+
const E = (i) => {
|
|
442
|
+
i instanceof InputEvent && (i = i.target.value), y.value = i;
|
|
443
443
|
}, S = O(() => {
|
|
444
|
-
let
|
|
445
|
-
return typeof
|
|
446
|
-
(W, A) => (W[A] = Z(
|
|
444
|
+
let i = l.value;
|
|
445
|
+
return typeof i == "function" && (i = i(u == null ? void 0 : u.formData)), Object.keys(i).reduce(
|
|
446
|
+
(W, A) => (W[A] = Z(i[A]), W),
|
|
447
447
|
{}
|
|
448
448
|
);
|
|
449
449
|
}), k = O(() => u != null && u.readonly.value ? !0 : S.value.readonly ?? t.readonly), g = O(() => ({
|
|
@@ -451,25 +451,25 @@ function Se(e, o, r, v) {
|
|
|
451
451
|
name: S.value.name ?? t.name,
|
|
452
452
|
invalid: n.value,
|
|
453
453
|
valid: t.showValid ? !!(!n.value && y.value) : void 0,
|
|
454
|
-
type: ((
|
|
454
|
+
type: ((i) => {
|
|
455
455
|
if ([
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
].includes(
|
|
470
|
-
return
|
|
456
|
+
h.color,
|
|
457
|
+
h.date,
|
|
458
|
+
h.datetimeLocal,
|
|
459
|
+
h.email,
|
|
460
|
+
h.month,
|
|
461
|
+
h.number,
|
|
462
|
+
h.password,
|
|
463
|
+
h.search,
|
|
464
|
+
h.tel,
|
|
465
|
+
h.text,
|
|
466
|
+
h.time,
|
|
467
|
+
h.url,
|
|
468
|
+
h.week
|
|
469
|
+
].includes(i))
|
|
470
|
+
return i;
|
|
471
471
|
})(t.type),
|
|
472
|
-
invalidLabel:
|
|
472
|
+
invalidLabel: m.value,
|
|
473
473
|
modelValue: y.value,
|
|
474
474
|
readonly: k.value,
|
|
475
475
|
"onUpdate:modelValue": E
|
|
@@ -478,16 +478,16 @@ function Se(e, o, r, v) {
|
|
|
478
478
|
name: K(f),
|
|
479
479
|
errors: K(b)
|
|
480
480
|
}), { component: O(() => {
|
|
481
|
-
if (t.type ===
|
|
481
|
+
if (t.type === h.custom)
|
|
482
482
|
return {
|
|
483
483
|
render() {
|
|
484
|
-
var
|
|
485
|
-
return ((
|
|
484
|
+
var i;
|
|
485
|
+
return ((i = a.default) == null ? void 0 : i.call(a, {
|
|
486
486
|
errors: b.value,
|
|
487
487
|
formData: u == null ? void 0 : u.formData.value,
|
|
488
488
|
formErrors: u == null ? void 0 : u.errors.value,
|
|
489
489
|
invalid: n.value,
|
|
490
|
-
invalidLabel:
|
|
490
|
+
invalidLabel: m.value,
|
|
491
491
|
modelValue: y.value,
|
|
492
492
|
onUpdate: E,
|
|
493
493
|
readonly: k.value,
|
|
@@ -497,53 +497,53 @@ function Se(e, o, r, v) {
|
|
|
497
497
|
}
|
|
498
498
|
};
|
|
499
499
|
if (!((v == null ? void 0 : v.lazyLoad) ?? t.lazyLoad)) {
|
|
500
|
-
let
|
|
500
|
+
let i;
|
|
501
501
|
switch (t.type) {
|
|
502
|
-
case
|
|
503
|
-
|
|
502
|
+
case h.select:
|
|
503
|
+
i = N("VvSelect");
|
|
504
504
|
break;
|
|
505
|
-
case
|
|
506
|
-
|
|
505
|
+
case h.checkbox:
|
|
506
|
+
i = N("VvCheckbox");
|
|
507
507
|
break;
|
|
508
|
-
case
|
|
509
|
-
|
|
508
|
+
case h.radio:
|
|
509
|
+
i = N("VvRadio");
|
|
510
510
|
break;
|
|
511
|
-
case
|
|
512
|
-
|
|
511
|
+
case h.textarea:
|
|
512
|
+
i = N("VvTextarea");
|
|
513
513
|
break;
|
|
514
|
-
case
|
|
515
|
-
|
|
514
|
+
case h.radioGroup:
|
|
515
|
+
i = N("VvRadioGroup");
|
|
516
516
|
break;
|
|
517
|
-
case
|
|
518
|
-
|
|
517
|
+
case h.checkboxGroup:
|
|
518
|
+
i = N("VvCheckboxGroup");
|
|
519
519
|
break;
|
|
520
|
-
case
|
|
521
|
-
|
|
520
|
+
case h.combobox:
|
|
521
|
+
i = N("VvCombobox");
|
|
522
522
|
break;
|
|
523
523
|
default:
|
|
524
|
-
|
|
524
|
+
i = N("VvInputText");
|
|
525
525
|
}
|
|
526
|
-
if (typeof
|
|
527
|
-
return
|
|
526
|
+
if (typeof i != "string")
|
|
527
|
+
return i;
|
|
528
528
|
console.warn(
|
|
529
|
-
`[form-vue warn]: ${
|
|
529
|
+
`[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
|
|
530
530
|
);
|
|
531
531
|
}
|
|
532
532
|
return ve(async () => {
|
|
533
533
|
switch (v != null && v.sideEffects && await Promise.resolve(v.sideEffects(t.type)), t.type) {
|
|
534
|
-
case
|
|
534
|
+
case h.textarea:
|
|
535
535
|
return import("@volverjs/ui-vue/vv-textarea");
|
|
536
|
-
case
|
|
536
|
+
case h.radio:
|
|
537
537
|
return import("@volverjs/ui-vue/vv-radio");
|
|
538
|
-
case
|
|
538
|
+
case h.radioGroup:
|
|
539
539
|
return import("@volverjs/ui-vue/vv-radio-group");
|
|
540
|
-
case
|
|
540
|
+
case h.checkbox:
|
|
541
541
|
return import("@volverjs/ui-vue/vv-checkbox");
|
|
542
|
-
case
|
|
542
|
+
case h.checkboxGroup:
|
|
543
543
|
return import("@volverjs/ui-vue/vv-checkbox-group");
|
|
544
|
-
case
|
|
544
|
+
case h.select:
|
|
545
545
|
return import("@volverjs/ui-vue/vv-select");
|
|
546
|
-
case
|
|
546
|
+
case h.combobox:
|
|
547
547
|
return import("@volverjs/ui-vue/vv-combobox");
|
|
548
548
|
}
|
|
549
549
|
return import("@volverjs/ui-vue/vv-input-text");
|
|
@@ -551,11 +551,11 @@ function Se(e, o, r, v) {
|
|
|
551
551
|
}), hasProps: g, invalid: n };
|
|
552
552
|
},
|
|
553
553
|
render() {
|
|
554
|
-
return this.is ?
|
|
554
|
+
return this.is ? U(this.is, this.hasProps, this.$slots) : this.type === h.custom ? U(this.component, null, this.$slots) : U(this.component, this.hasProps, this.$slots);
|
|
555
555
|
}
|
|
556
556
|
});
|
|
557
557
|
}
|
|
558
|
-
function Ie(e,
|
|
558
|
+
function Ie(e, s, r) {
|
|
559
559
|
return M({
|
|
560
560
|
name: "VvFormFieldsGroup",
|
|
561
561
|
props: {
|
|
@@ -564,7 +564,7 @@ function Ie(e, o, r) {
|
|
|
564
564
|
default: void 0
|
|
565
565
|
},
|
|
566
566
|
names: {
|
|
567
|
-
type: [Array],
|
|
567
|
+
type: [Array, Object],
|
|
568
568
|
required: !0
|
|
569
569
|
},
|
|
570
570
|
props: {
|
|
@@ -600,23 +600,23 @@ function Ie(e, o, r) {
|
|
|
600
600
|
],
|
|
601
601
|
slots: Object,
|
|
602
602
|
setup(v, { slots: t, emit: a }) {
|
|
603
|
-
const { props: d, names: l, defaultValues: f } = F(v), p = O(() => Array.isArray(l.value) ? l.value : Object.values(l.value)), u = O(() => Array.isArray(l.value) ? l.value : Object.keys(l.value)), y = O(() => Array.isArray(l.value) ? l.value.reduce((
|
|
604
|
-
|
|
605
|
-
|
|
603
|
+
const { props: d, names: l, defaultValues: f } = F(v), p = O(() => Array.isArray(l.value) ? l.value : Object.values(l.value)), u = O(() => Array.isArray(l.value) ? l.value : Object.keys(l.value)), y = O(() => Array.isArray(l.value) ? l.value.reduce((o, c) => (o[String(c)] = c, o), {}) : l.value), b = O(() => Object.keys(y.value).reduce((o, c) => (o[String(y.value[c])] = c, o), {})), m = _(s, void 0);
|
|
604
|
+
m && p.value.forEach((o) => {
|
|
605
|
+
m.fields.value.add(o);
|
|
606
606
|
});
|
|
607
607
|
const n = _(e), w = O({
|
|
608
608
|
get() {
|
|
609
|
-
return n != null && n.formData ? u.value.reduce((
|
|
609
|
+
return n != null && n.formData ? u.value.reduce((o, c) => (o[c] = z(
|
|
610
610
|
new Object(n.formData.value),
|
|
611
611
|
y.value[c]
|
|
612
|
-
),
|
|
612
|
+
), o), {}) : {};
|
|
613
613
|
},
|
|
614
|
-
set(
|
|
614
|
+
set(o) {
|
|
615
615
|
n != null && n.formData && (u.value.forEach((c) => {
|
|
616
616
|
ee(
|
|
617
617
|
new Object(n.formData.value),
|
|
618
618
|
y.value[c],
|
|
619
|
-
|
|
619
|
+
o == null ? void 0 : o[c]
|
|
620
620
|
);
|
|
621
621
|
}), a("update:modelValue", {
|
|
622
622
|
newValue: w.value,
|
|
@@ -625,60 +625,60 @@ function Ie(e, o, r) {
|
|
|
625
625
|
}
|
|
626
626
|
});
|
|
627
627
|
j(() => {
|
|
628
|
-
f.value && p.value.forEach((
|
|
628
|
+
f.value && p.value.forEach((o) => {
|
|
629
629
|
var c, I;
|
|
630
|
-
((c = f.value) == null ? void 0 : c[
|
|
630
|
+
((c = f.value) == null ? void 0 : c[o]) !== void 0 && w.value[o] === void 0 && (w.value = {
|
|
631
631
|
...w.value,
|
|
632
|
-
[
|
|
632
|
+
[o]: (I = f.value) == null ? void 0 : I[o]
|
|
633
633
|
});
|
|
634
634
|
});
|
|
635
635
|
});
|
|
636
636
|
const x = O(() => {
|
|
637
637
|
if (!(n != null && n.errors.value))
|
|
638
638
|
return;
|
|
639
|
-
const
|
|
639
|
+
const o = p.value.reduce((c, I) => {
|
|
640
640
|
if (!n.errors.value)
|
|
641
641
|
return c;
|
|
642
642
|
const P = z(n.errors.value, String(I));
|
|
643
643
|
return P === void 0 || (c[String(I)] = P), c;
|
|
644
644
|
}, {});
|
|
645
|
-
if (Object.keys(
|
|
646
|
-
return
|
|
645
|
+
if (Object.keys(o).length !== 0)
|
|
646
|
+
return o;
|
|
647
647
|
}), E = O(() => {
|
|
648
648
|
if (!x.value)
|
|
649
649
|
return;
|
|
650
|
-
const
|
|
650
|
+
const o = Object.keys(x.value).reduce((c, I) => {
|
|
651
651
|
var P;
|
|
652
652
|
return (P = x.value) != null && P[I] && (c[b.value[I]] = x.value[I]._errors), c;
|
|
653
653
|
}, {});
|
|
654
|
-
if (Object.keys(
|
|
655
|
-
return
|
|
656
|
-
}), S = O(() => x.value !== void 0), k = O(() => u.value.reduce((
|
|
654
|
+
if (Object.keys(o).length !== 0)
|
|
655
|
+
return o;
|
|
656
|
+
}), S = O(() => x.value !== void 0), k = O(() => u.value.reduce((o, c) => {
|
|
657
657
|
var I;
|
|
658
|
-
return
|
|
659
|
-
}, {})), g =
|
|
658
|
+
return o[c] = !!((I = x.value) != null && I[b.value[c]]), o;
|
|
659
|
+
}, {})), g = L(S, () => {
|
|
660
660
|
if (S.value) {
|
|
661
|
-
a("invalid", x.value),
|
|
661
|
+
a("invalid", x.value), m && p.value.forEach((o) => {
|
|
662
662
|
var c, I;
|
|
663
|
-
if (!((c = x.value) != null && c[
|
|
664
|
-
|
|
665
|
-
|
|
663
|
+
if (!((c = x.value) != null && c[o])) {
|
|
664
|
+
m.errors.value.delete(
|
|
665
|
+
o
|
|
666
666
|
);
|
|
667
667
|
return;
|
|
668
668
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
(I = x.value) == null ? void 0 : I[
|
|
669
|
+
m.errors.value.set(
|
|
670
|
+
o,
|
|
671
|
+
(I = x.value) == null ? void 0 : I[o]
|
|
672
672
|
);
|
|
673
673
|
});
|
|
674
674
|
return;
|
|
675
675
|
}
|
|
676
|
-
a("valid", w.value),
|
|
677
|
-
|
|
678
|
-
|
|
676
|
+
a("valid", w.value), m && p.value.forEach((o) => {
|
|
677
|
+
m.errors.value.delete(
|
|
678
|
+
o
|
|
679
679
|
);
|
|
680
680
|
});
|
|
681
|
-
}), V =
|
|
681
|
+
}), V = L(
|
|
682
682
|
() => n == null ? void 0 : n.formData,
|
|
683
683
|
() => {
|
|
684
684
|
a("update:formData", n == null ? void 0 : n.formData);
|
|
@@ -688,23 +688,23 @@ function Ie(e, o, r) {
|
|
|
688
688
|
le(() => {
|
|
689
689
|
g(), V();
|
|
690
690
|
});
|
|
691
|
-
const
|
|
692
|
-
w.value =
|
|
693
|
-
}, W = (
|
|
694
|
-
c instanceof InputEvent && (c = c.target.value), u.value.includes(
|
|
691
|
+
const i = (o) => {
|
|
692
|
+
w.value = o;
|
|
693
|
+
}, W = (o, c) => {
|
|
694
|
+
c instanceof InputEvent && (c = c.target.value), u.value.includes(o) && (w.value = {
|
|
695
695
|
...w.value,
|
|
696
|
-
[
|
|
696
|
+
[o]: c
|
|
697
697
|
});
|
|
698
698
|
}, A = O(() => {
|
|
699
|
-
let
|
|
700
|
-
return typeof
|
|
701
|
-
(c, I) => (c[I] = Z(
|
|
699
|
+
let o = d.value;
|
|
700
|
+
return typeof o == "function" && (o = o(n == null ? void 0 : n.formData)), Object.keys(o).reduce(
|
|
701
|
+
(c, I) => (c[I] = Z(o[I]), c),
|
|
702
702
|
{}
|
|
703
703
|
);
|
|
704
|
-
}), $ = O(() => n != null && n.readonly.value ? !0 : A.value.readonly ?? v.readonly), q = O(() => u.value.reduce((
|
|
704
|
+
}), $ = O(() => n != null && n.readonly.value ? !0 : A.value.readonly ?? v.readonly), q = O(() => u.value.reduce((o, c) => (o[`onUpdate:${c}`] = (I) => {
|
|
705
705
|
W(c, I);
|
|
706
|
-
},
|
|
707
|
-
"onUpdate:modelValue":
|
|
706
|
+
}, o), {
|
|
707
|
+
"onUpdate:modelValue": i
|
|
708
708
|
})), T = O(() => ({
|
|
709
709
|
...q.value,
|
|
710
710
|
...A.value,
|
|
@@ -721,8 +721,8 @@ function Ie(e, o, r) {
|
|
|
721
721
|
errors: K(x)
|
|
722
722
|
}), { component: O(() => ({
|
|
723
723
|
render() {
|
|
724
|
-
var
|
|
725
|
-
return ((
|
|
724
|
+
var o;
|
|
725
|
+
return ((o = t.default) == null ? void 0 : o.call(t, {
|
|
726
726
|
errors: x.value,
|
|
727
727
|
formData: n == null ? void 0 : n.formData.value,
|
|
728
728
|
formErrors: n == null ? void 0 : n.errors.value,
|
|
@@ -730,7 +730,7 @@ function Ie(e, o, r) {
|
|
|
730
730
|
invalids: k.value,
|
|
731
731
|
invalidLabels: E.value,
|
|
732
732
|
modelValue: w.value,
|
|
733
|
-
onUpdate:
|
|
733
|
+
onUpdate: i,
|
|
734
734
|
onUpdateField: W,
|
|
735
735
|
readonly: $.value,
|
|
736
736
|
submit: n == null ? void 0 : n.submit,
|
|
@@ -740,11 +740,11 @@ function Ie(e, o, r) {
|
|
|
740
740
|
})), hasProps: T, invalid: S };
|
|
741
741
|
},
|
|
742
742
|
render() {
|
|
743
|
-
return this.is ?
|
|
743
|
+
return this.is ? U(this.is, this.hasProps, this.$slots) : U(this.component, null, this.$slots);
|
|
744
744
|
}
|
|
745
745
|
});
|
|
746
746
|
}
|
|
747
|
-
function Ee(e,
|
|
747
|
+
function Ee(e, s) {
|
|
748
748
|
return M({
|
|
749
749
|
name: "VvFormWrapper",
|
|
750
750
|
props: {
|
|
@@ -773,12 +773,12 @@ function Ee(e, o) {
|
|
|
773
773
|
],
|
|
774
774
|
slots: Object,
|
|
775
775
|
setup(r, { emit: v }) {
|
|
776
|
-
const t = _(e), a = _(
|
|
777
|
-
Y(
|
|
776
|
+
const t = _(e), a = _(s, void 0), d = C(/* @__PURE__ */ new Set()), l = C(/* @__PURE__ */ new Map()), { name: f } = F(r);
|
|
777
|
+
Y(s, {
|
|
778
778
|
name: K(f),
|
|
779
779
|
errors: l,
|
|
780
780
|
fields: d
|
|
781
|
-
}),
|
|
781
|
+
}), L(
|
|
782
782
|
d,
|
|
783
783
|
(y) => {
|
|
784
784
|
a != null && a.fields && y.forEach((b) => {
|
|
@@ -786,20 +786,20 @@ function Ee(e, o) {
|
|
|
786
786
|
});
|
|
787
787
|
},
|
|
788
788
|
{ deep: !0 }
|
|
789
|
-
),
|
|
789
|
+
), L(
|
|
790
790
|
() => new Map(l.value),
|
|
791
791
|
(y, b) => {
|
|
792
|
-
a != null && a.errors && (Array.from(b.keys()).forEach((
|
|
793
|
-
a.errors.value.delete(
|
|
794
|
-
}), Array.from(y.keys()).forEach((
|
|
795
|
-
const n = y.get(
|
|
796
|
-
n && a.errors.value.set(
|
|
792
|
+
a != null && a.errors && (Array.from(b.keys()).forEach((m) => {
|
|
793
|
+
a.errors.value.delete(m);
|
|
794
|
+
}), Array.from(y.keys()).forEach((m) => {
|
|
795
|
+
const n = y.get(m);
|
|
796
|
+
n && a.errors.value.set(m, n);
|
|
797
797
|
}));
|
|
798
798
|
},
|
|
799
799
|
{ deep: !0 }
|
|
800
800
|
);
|
|
801
801
|
const p = O(() => t != null && t.invalid.value ? l.value.size > 0 : !1);
|
|
802
|
-
|
|
802
|
+
L(p, () => {
|
|
803
803
|
p.value ? v("invalid") : v("valid");
|
|
804
804
|
});
|
|
805
805
|
const u = () => (t == null ? void 0 : t.validate(void 0, d.value)) ?? Promise.resolve(!0);
|
|
@@ -831,13 +831,13 @@ function Ee(e, o) {
|
|
|
831
831
|
validateWrapper: this.validateWrapper
|
|
832
832
|
});
|
|
833
833
|
};
|
|
834
|
-
return this.tag ?
|
|
834
|
+
return this.tag ? U(this.tag, null, {
|
|
835
835
|
default: r
|
|
836
836
|
}) : r();
|
|
837
837
|
}
|
|
838
838
|
});
|
|
839
839
|
}
|
|
840
|
-
function Ae(e,
|
|
840
|
+
function Ae(e, s) {
|
|
841
841
|
const r = M({
|
|
842
842
|
name: "VvFormTemplate",
|
|
843
843
|
props: {
|
|
@@ -863,7 +863,7 @@ function Ae(e, o) {
|
|
|
863
863
|
let l;
|
|
864
864
|
const f = d.reduce((u, y) => {
|
|
865
865
|
const b = typeof y == "function" ? y(a, v.scope) : y, {
|
|
866
|
-
vvIs:
|
|
866
|
+
vvIs: m,
|
|
867
867
|
vvName: n,
|
|
868
868
|
vvSlots: w,
|
|
869
869
|
vvChildren: x,
|
|
@@ -872,7 +872,7 @@ function Ae(e, o) {
|
|
|
872
872
|
vvType: k,
|
|
873
873
|
vvDefaultValue: g,
|
|
874
874
|
vvShowValid: V,
|
|
875
|
-
vvContent:
|
|
875
|
+
vvContent: i,
|
|
876
876
|
...W
|
|
877
877
|
} = b;
|
|
878
878
|
if (E !== void 0) {
|
|
@@ -890,31 +890,31 @@ function Ae(e, o) {
|
|
|
890
890
|
} else
|
|
891
891
|
l = void 0;
|
|
892
892
|
let A;
|
|
893
|
-
return x && (typeof
|
|
893
|
+
return x && (typeof m == "string" ? A = U(r, {
|
|
894
894
|
schema: x
|
|
895
895
|
}) : A = {
|
|
896
|
-
default: ($) =>
|
|
896
|
+
default: ($) => U(r, {
|
|
897
897
|
schema: x,
|
|
898
898
|
scope: $
|
|
899
899
|
})
|
|
900
900
|
}), n ? (u.push(
|
|
901
|
-
|
|
902
|
-
|
|
901
|
+
U(
|
|
902
|
+
s,
|
|
903
903
|
{
|
|
904
904
|
name: n,
|
|
905
|
-
is:
|
|
905
|
+
is: m,
|
|
906
906
|
type: k,
|
|
907
907
|
defaultValue: g,
|
|
908
908
|
showValid: V,
|
|
909
909
|
props: W
|
|
910
910
|
},
|
|
911
|
-
w ?? A ??
|
|
911
|
+
w ?? A ?? i
|
|
912
912
|
)
|
|
913
|
-
), u) :
|
|
914
|
-
|
|
915
|
-
|
|
913
|
+
), u) : m ? (u.push(
|
|
914
|
+
U(
|
|
915
|
+
m,
|
|
916
916
|
W,
|
|
917
|
-
w ?? A ??
|
|
917
|
+
w ?? A ?? i
|
|
918
918
|
)
|
|
919
919
|
), u) : (A && ("default" in A ? u.push(A.default(v.scope)) : u.push(A)), u);
|
|
920
920
|
}, []);
|
|
@@ -935,7 +935,7 @@ function Ae(e, o) {
|
|
|
935
935
|
});
|
|
936
936
|
return r;
|
|
937
937
|
}
|
|
938
|
-
function X(e,
|
|
938
|
+
function X(e, s = {}) {
|
|
939
939
|
const r = Symbol("formInjectionKey"), v = Symbol("formWrapperInjectionKey"), t = Symbol("formFieldInjectionKey"), a = Symbol("formFieldsGroupInjectionKey"), d = Ee(
|
|
940
940
|
r,
|
|
941
941
|
v
|
|
@@ -943,7 +943,7 @@ function X(e, o = {}) {
|
|
|
943
943
|
r,
|
|
944
944
|
v,
|
|
945
945
|
t,
|
|
946
|
-
|
|
946
|
+
s
|
|
947
947
|
), f = Ie(
|
|
948
948
|
r,
|
|
949
949
|
v,
|
|
@@ -952,7 +952,7 @@ function X(e, o = {}) {
|
|
|
952
952
|
clear: u,
|
|
953
953
|
errors: y,
|
|
954
954
|
formData: b,
|
|
955
|
-
ignoreUpdates:
|
|
955
|
+
ignoreUpdates: m,
|
|
956
956
|
invalid: n,
|
|
957
957
|
readonly: w,
|
|
958
958
|
reset: x,
|
|
@@ -961,7 +961,7 @@ function X(e, o = {}) {
|
|
|
961
961
|
submit: k,
|
|
962
962
|
validate: g,
|
|
963
963
|
VvForm: V
|
|
964
|
-
} = Oe(e, r,
|
|
964
|
+
} = Oe(e, r, s, p);
|
|
965
965
|
return {
|
|
966
966
|
clear: u,
|
|
967
967
|
errors: y,
|
|
@@ -969,7 +969,7 @@ function X(e, o = {}) {
|
|
|
969
969
|
formFieldInjectionKey: t,
|
|
970
970
|
formInjectionKey: r,
|
|
971
971
|
formWrapperInjectionKey: v,
|
|
972
|
-
ignoreUpdates:
|
|
972
|
+
ignoreUpdates: m,
|
|
973
973
|
invalid: n,
|
|
974
974
|
readonly: w,
|
|
975
975
|
reset: x,
|
|
@@ -985,32 +985,32 @@ function X(e, o = {}) {
|
|
|
985
985
|
};
|
|
986
986
|
}
|
|
987
987
|
const oe = Symbol("pluginInjectionKey");
|
|
988
|
-
function
|
|
989
|
-
let
|
|
990
|
-
return e.schema && (
|
|
991
|
-
...
|
|
988
|
+
function Ue(e) {
|
|
989
|
+
let s = {};
|
|
990
|
+
return e.schema && (s = X(e.schema, e)), {
|
|
991
|
+
...s,
|
|
992
992
|
install(r, { global: v = !1 } = {}) {
|
|
993
|
-
r.provide(oe, e), v && (r.config.globalProperties.$vvForm = e,
|
|
993
|
+
r.provide(oe, e), v && (r.config.globalProperties.$vvForm = e, s != null && s.VvForm && r.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && r.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && r.component("VvFormField", s.VvFormField), s != null && s.VvFormFieldsGroup && r.component("VvFormFieldsGroup", s.VvFormFieldsGroup), s != null && s.VvFormTemplate && r.component("VvFormTemplate", s.VvFormTemplate));
|
|
994
994
|
}
|
|
995
995
|
};
|
|
996
996
|
}
|
|
997
|
-
function
|
|
997
|
+
function Le(e, s = {}) {
|
|
998
998
|
return de() ? X(
|
|
999
999
|
e,
|
|
1000
1000
|
{
|
|
1001
1001
|
..._(oe, {}),
|
|
1002
|
-
...
|
|
1002
|
+
...s
|
|
1003
1003
|
}
|
|
1004
|
-
) : X(e,
|
|
1004
|
+
) : X(e, s);
|
|
1005
1005
|
}
|
|
1006
|
-
function
|
|
1007
|
-
return X(e,
|
|
1006
|
+
function Re(e, s = {}) {
|
|
1007
|
+
return X(e, s);
|
|
1008
1008
|
}
|
|
1009
1009
|
export {
|
|
1010
|
-
|
|
1011
|
-
|
|
1010
|
+
h as FormFieldType,
|
|
1011
|
+
Ue as createForm,
|
|
1012
1012
|
J as defaultObjectBySchema,
|
|
1013
|
-
|
|
1013
|
+
Re as formFactory,
|
|
1014
1014
|
oe as pluginInjectionKey,
|
|
1015
|
-
|
|
1015
|
+
Le as useForm
|
|
1016
1016
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(A=typeof globalThis<"u"?globalThis:A||self,e(A["@volverjs/form-vue"]={},A.Vue,A.VueUseCore,A.zod))})(this,function(A,e,T,B){"use strict";var p=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(p||{}),U=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.reset="reset",r.updated="updated",r.unknown="unknown",r))(U||{});function L(r,f={}){const t=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional&&(u=u._def.innerType),u},c=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional},a=t(r);return{...(a instanceof B.ZodObject?a._def.unknownKeys==="passthrough":!1)?f:{},...Object.fromEntries(Object.entries(a.shape).map(([v,u])=>{const d=f[v],V=c(u);let l=t(u),h;if(l instanceof B.ZodDefault&&(h=l._def.defaultValue(),l=l._def.innerType),d===null&&l instanceof B.ZodNullable)return[v,d];if(d==null&&V)return[v,h];if(l instanceof B.ZodSchema){const b=u.safeParse(d);if(b.success)return[v,b.data??h]}if(l instanceof B.ZodArray&&Array.isArray(d)&&d.length){const b=t(l._def.type);if(b instanceof B.ZodObject)return[v,d.map(y=>L(b,y&&typeof y=="object"?y:void 0))]}if(l instanceof B.ZodRecord&&d){const b=t(l._def.valueType);if(b instanceof B.ZodObject)return[v,Object.keys(d).reduce((y,o)=>(y[o]=L(b,d[o]),y),{})]}return l instanceof B.ZodObject?[v,L(l,d&&typeof d=="object"?d:h)]:[v,h]}))}}function z(r,f,t,c){const a=e.ref(),n=e.ref(),v=e.computed(()=>n.value===U.invalid),u=e.ref(),d=e.ref(!1);let V;const l=async(x=u.value,w)=>{if(V=w,d.value)return!0;const g=await r.safeParseAsync(x);if(!g.success){if(n.value=U.invalid,!w)return a.value=g.error.format(),!1;const s=g.error.issues.filter(W=>w.has(W.path.join(".")));return s.length?(a.value=new B.ZodError(s).format(),!1):(a.value=void 0,!0)}return a.value=void 0,n.value=U.valid,u.value=g.data,!0},h=()=>{a.value=void 0,n.value=void 0,V=void 0},b=()=>{u.value=L(r),h(),n.value=U.reset},y=async()=>d.value||!await l()?!1:(n.value=U.submitting,!0),{ignoreUpdates:o,stop:O}=T.watchIgnorable(u,()=>{n.value=U.updated},{deep:!0,eventFilter:T.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),S=e.readonly(a),E=e.readonly(n),k=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(x,{emit:w}){return u.value=L(r,e.toRaw(x.modelValue)),e.watch(()=>x.modelValue,g=>{if(g){const s=e.isProxy(g)?e.toRaw(g):g;if(JSON.stringify(s)===JSON.stringify(e.toRaw(u.value)))return;u.value=typeof(s==null?void 0:s.clone)=="function"?s.clone():JSON.parse(JSON.stringify(s))}},{deep:!0}),e.watch(n,async g=>{var s,W,R,G,$,M;if(g===U.invalid){const C=e.toRaw(a.value);w("invalid",C),(s=t==null?void 0:t.onInvalid)==null||s.call(t,C);return}if(g===U.valid){const C=e.toRaw(u.value);w("valid",C),(W=t==null?void 0:t.onValid)==null||W.call(t,C),w("update:modelValue",C),(R=t==null?void 0:t.onUpdate)==null||R.call(t,C);return}if(g===U.submitting){const C=e.toRaw(u.value);w("submit",C),(G=t==null?void 0:t.onSubmit)==null||G.call(t,C);return}if(g===U.reset){const C=e.toRaw(u.value);w("reset",C),($=t==null?void 0:t.onReset)==null||$.call(t,C);return}if(g===U.updated){if((a.value||t!=null&&t.continuousValidation||x.continuousValidation)&&await l(void 0,V),!u.value||!x.modelValue||JSON.stringify(u.value)!==JSON.stringify(x.modelValue)){const C=e.toRaw(u.value);w("update:modelValue",C),(M=t==null?void 0:t.onUpdate)==null||M.call(t,C)}n.value===U.updated&&(n.value=U.unknown)}}),e.onMounted(()=>{d.value=x.readonly}),e.watch(()=>x.readonly,g=>{d.value=g}),e.watch(d,g=>{g!==x.readonly&&w("update:readonly",d.value)}),e.provide(f,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}),{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,isReadonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}},render(){const x=()=>{var w,g;return((g=(w=this.$slots)==null?void 0:w.default)==null?void 0:g.call(w,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"]),onReset:e.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&c?[e.h(c,{schema:this.template??(t==null?void 0:t.template)},{default:x})]:{default:x})}});return{clear:h,errors:a,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:n,stopUpdatesWatch:O,submit:y,validate:l,VvForm:k}}function P(r){return Array.isArray(r)}function j(r){return typeof r<"u"}function H(r){return r===null}function Q(r){return typeof r=="object"}function X(r){return typeof r=="string"}function _(r){return typeof r>"u"}const D=/^[0-9]+$/,F=["__proto__","prototype","constructor"];function Z(r,f,t){const c=j(t)?t:void 0;if(!Q(r)||!X(f))return c;const a=Y(f);if(a.length!==0){for(const n of a){if(n==="*")continue;const v=function(u){return u.map(d=>_(d)||H(d)?d:P(d)?v(d):d[n])};if(P(r)&&!D.test(n)?r=v(r):r=r[n],_(r)||H(r))break}return _(r)?c:r}}function q(r,f,t){if(!Q(r)||!X(f))return;const c=Y(f);if(c.length===0)return;const a=c.length;for(let n=0;n<a;n++){const v=c[n];if(n===a-1){r[v]=t;return}if(v==="*"&&P(r)){const u=c.slice(n+1).join(".");for(const d of r)q(d,u,t);return}_(r[v])&&(r[v]={}),r=r[v]}}function Y(r){const f=r.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return f.some(t=>F.indexOf(t)!==-1)?[]:f}function ee(r,f,t,c){return e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:a=>Object.values(p).includes(a),default:p.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},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(a,{slots:n,emit:v}){const{props:u,name:d}=e.toRefs(a),V=e.inject(f,void 0);V&&V.fields.value.add(a.name);const l=e.inject(r),h=e.computed({get(){if(l!=null&&l.formData)return Z(new Object(l.formData.value),String(a.name))},set(s){l!=null&&l.formData&&(q(new Object(l.formData.value),String(a.name),s),v("update:modelValue",{newValue:h.value,formData:l==null?void 0:l.formData}))}});e.onMounted(()=>{h.value===void 0&&a.defaultValue!==void 0&&(h.value=a.defaultValue)});const b=e.computed(()=>{if(l!=null&&l.errors.value)return Z(l.errors.value,String(a.name))}),y=e.computed(()=>{var s;return(s=b.value)==null?void 0:s._errors}),o=e.computed(()=>b.value!==void 0),O=e.watch(o,()=>{if(o.value){v("invalid",b.value),V&&V.errors.value.set(String(a.name),b.value);return}v("valid",h.value),V&&V.errors.value.delete(a.name)}),S=e.watch(()=>l==null?void 0:l.formData,()=>{v("update:formData",l==null?void 0:l.formData)},{deep:!0});e.onBeforeUnmount(()=>{O(),S()});const E=s=>{s instanceof InputEvent&&(s=s.target.value),h.value=s},k=e.computed(()=>{let s=u.value;return typeof s=="function"&&(s=s(l==null?void 0:l.formData)),Object.keys(s).reduce((W,R)=>(W[R]=e.unref(s[R]),W),{})}),x=e.computed(()=>l!=null&&l.readonly.value?!0:k.value.readonly??a.readonly),w=e.computed(()=>({...k.value,name:k.value.name??a.name,invalid:o.value,valid:a.showValid?!!(!o.value&&h.value):void 0,type:(s=>{if([p.color,p.date,p.datetimeLocal,p.email,p.month,p.number,p.password,p.search,p.tel,p.text,p.time,p.url,p.week].includes(s))return s})(a.type),invalidLabel:y.value,modelValue:h.value,readonly:x.value,"onUpdate:modelValue":E}));return e.provide(t,{name:e.readonly(d),errors:e.readonly(b)}),{component:e.computed(()=>{if(a.type===p.custom)return{render(){var s;return((s=n.default)==null?void 0:s.call(n,{errors:b.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,invalid:o.value,invalidLabel:y.value,modelValue:h.value,onUpdate:E,readonly:x.value,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate}))??n.default}};if(!((c==null?void 0:c.lazyLoad)??a.lazyLoad)){let s;switch(a.type){case p.select:s=e.resolveComponent("VvSelect");break;case p.checkbox:s=e.resolveComponent("VvCheckbox");break;case p.radio:s=e.resolveComponent("VvRadio");break;case p.textarea:s=e.resolveComponent("VvTextarea");break;case p.radioGroup:s=e.resolveComponent("VvRadioGroup");break;case p.checkboxGroup:s=e.resolveComponent("VvCheckboxGroup");break;case p.combobox:s=e.resolveComponent("VvCombobox");break;default:s=e.resolveComponent("VvInputText")}if(typeof s!="string")return s;console.warn(`[form-vue warn]: ${s} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(c!=null&&c.sideEffects&&await Promise.resolve(c.sideEffects(a.type)),a.type){case p.textarea:return import("@volverjs/ui-vue/vv-textarea");case p.radio:return import("@volverjs/ui-vue/vv-radio");case p.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case p.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case p.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case p.select:return import("@volverjs/ui-vue/vv-select");case p.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:w,invalid:o}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===p.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}})}function re(r,f,t){return e.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(c,{slots:a,emit:n}){const{props:v,names:u,defaultValues:d}=e.toRefs(c),V=e.computed(()=>Array.isArray(u.value)?u.value:Object.values(u.value)),l=e.computed(()=>Array.isArray(u.value)?u.value:Object.keys(u.value)),h=e.computed(()=>Array.isArray(u.value)?u.value.reduce((i,m)=>(i[String(m)]=m,i),{}):u.value),b=e.computed(()=>Object.keys(h.value).reduce((i,m)=>(i[String(h.value[m])]=m,i),{})),y=e.inject(f,void 0);y&&V.value.forEach(i=>{y.fields.value.add(i)});const o=e.inject(r),O=e.computed({get(){return o!=null&&o.formData?l.value.reduce((i,m)=>(i[m]=Z(new Object(o.formData.value),h.value[m]),i),{}):{}},set(i){o!=null&&o.formData&&(l.value.forEach(m=>{q(new Object(o.formData.value),h.value[m],i==null?void 0:i[m])}),n("update:modelValue",{newValue:O.value,formData:o==null?void 0:o.formData}))}});e.onMounted(()=>{d.value&&V.value.forEach(i=>{var m,I;((m=d.value)==null?void 0:m[i])!==void 0&&O.value[i]===void 0&&(O.value={...O.value,[i]:(I=d.value)==null?void 0:I[i]})})});const S=e.computed(()=>{if(!(o!=null&&o.errors.value))return;const i=V.value.reduce((m,I)=>{if(!o.errors.value)return m;const N=Z(o.errors.value,String(I));return N===void 0||(m[String(I)]=N),m},{});if(Object.keys(i).length!==0)return i}),E=e.computed(()=>{if(!S.value)return;const i=Object.keys(S.value).reduce((m,I)=>{var N;return(N=S.value)!=null&&N[I]&&(m[b.value[I]]=S.value[I]._errors),m},{});if(Object.keys(i).length!==0)return i}),k=e.computed(()=>S.value!==void 0),x=e.computed(()=>l.value.reduce((i,m)=>{var I;return i[m]=!!((I=S.value)!=null&&I[b.value[m]]),i},{})),w=e.watch(k,()=>{if(k.value){n("invalid",S.value),y&&V.value.forEach(i=>{var m,I;if(!((m=S.value)!=null&&m[i])){y.errors.value.delete(i);return}y.errors.value.set(i,(I=S.value)==null?void 0:I[i])});return}n("valid",O.value),y&&V.value.forEach(i=>{y.errors.value.delete(i)})}),g=e.watch(()=>o==null?void 0:o.formData,()=>{n("update:formData",o==null?void 0:o.formData)},{deep:!0});e.onBeforeUnmount(()=>{w(),g()});const s=i=>{O.value=i},W=(i,m)=>{m instanceof InputEvent&&(m=m.target.value),l.value.includes(i)&&(O.value={...O.value,[i]:m})},R=e.computed(()=>{let i=v.value;return typeof i=="function"&&(i=i(o==null?void 0:o.formData)),Object.keys(i).reduce((m,I)=>(m[I]=e.unref(i[I]),m),{})}),G=e.computed(()=>o!=null&&o.readonly.value?!0:R.value.readonly??c.readonly),$=e.computed(()=>l.value.reduce((i,m)=>(i[`onUpdate:${m}`]=I=>{W(m,I)},i),{"onUpdate:modelValue":s})),M=e.computed(()=>({...$.value,...R.value,names:R.value.name??V.value,invalid:k.value,invalids:x.value,valid:c.showValid?!!(!k.value&&O.value):void 0,invalidLabels:E.value,modelValue:O.value,readonly:G.value}));return e.provide(t,{names:e.readonly(u),errors:e.readonly(S)}),{component:e.computed(()=>({render(){var i;return((i=a.default)==null?void 0:i.call(a,{errors:S.value,formData:o==null?void 0:o.formData.value,formErrors:o==null?void 0:o.errors.value,invalid:k.value,invalids:x.value,invalidLabels:E.value,modelValue:O.value,onUpdate:s,onUpdateField:W,readonly:G.value,submit:o==null?void 0:o.submit,validate:o==null?void 0:o.validate}))??a.default}})),hasProps:M,invalid:k}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):e.h(this.component,null,this.$slots)}})}function te(r,f){return e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:c}){const a=e.inject(r),n=e.inject(f,void 0),v=e.ref(new Set),u=e.ref(new Map),{name:d}=e.toRefs(t);e.provide(f,{name:e.readonly(d),errors:u,fields:v}),e.watch(v,h=>{n!=null&&n.fields&&h.forEach(b=>{n==null||n.fields.value.add(b)})},{deep:!0}),e.watch(()=>new Map(u.value),(h,b)=>{n!=null&&n.errors&&(Array.from(b.keys()).forEach(y=>{n.errors.value.delete(y)}),Array.from(h.keys()).forEach(y=>{const o=h.get(y);o&&n.errors.value.set(y,o)}))},{deep:!0});const V=e.computed(()=>a!=null&&a.invalid.value?u.value.size>0:!1);e.watch(V,()=>{V.value?c("invalid"):c("valid")});const l=()=>(a==null?void 0:a.validate(void 0,v.value))??Promise.resolve(!0);return{clear:a==null?void 0:a.clear,errors:a==null?void 0:a.errors,fields:v,fieldsErrors:u,formData:a==null?void 0:a.formData,invalid:V,reset:a==null?void 0:a.reset,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate,validateWrapper:l}},render(){const t=()=>{var c,a;return(a=(c=this.$slots).default)==null?void 0:a.call(c,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?e.h(this.tag,null,{default:t}):t()}})}function ae(r,f){const t=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(c,{slots:a}){const n=e.inject(r);if(n!=null&&n.formData)return()=>{var V;const v=typeof c.schema=="function"?c.schema(n,c.scope):c.schema;let u;const d=v.reduce((l,h)=>{const b=typeof h=="function"?h(n,c.scope):h,{vvIs:y,vvName:o,vvSlots:O,vvChildren:S,vvIf:E,vvElseIf:k,vvType:x,vvDefaultValue:w,vvShowValid:g,vvContent:s,...W}=b;if(E!==void 0){if(typeof E=="string"?u=!!Z(new Object(n.formData.value),E):typeof E=="function"?u=e.unref(E(n)):u=e.unref(E),!u)return l}else if(k!==void 0&&u!==void 0){if(u||(typeof k=="string"?u=!!Z(new Object(n.formData.value),k):typeof k=="function"?u=e.unref(k(n)):u=e.unref(k),!u))return l}else u=void 0;let R;return S&&(typeof y=="string"?R=e.h(t,{schema:S}):R={default:G=>e.h(t,{schema:S,scope:G})}),o?(l.push(e.h(f,{name:o,is:y,type:x,defaultValue:w,showValid:g,props:W},O??R??s)),l):y?(l.push(e.h(y,W,O??R??s)),l):(R&&("default"in R?l.push(R.default(c.scope)):l.push(R)),l)},[]);return d.push((V=a==null?void 0:a.default)==null?void 0:V.call(a,{errors:n==null?void 0:n.errors.value,formData:n==null?void 0:n.formData.value,invalid:n==null?void 0:n.invalid.value,status:n==null?void 0:n.status.value,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,clear:n==null?void 0:n.clear,reset:n==null?void 0:n.reset})),d}}});return t}function K(r,f={}){const t=Symbol("formInjectionKey"),c=Symbol("formWrapperInjectionKey"),a=Symbol("formFieldInjectionKey"),n=Symbol("formFieldsGroupInjectionKey"),v=te(t,c),u=ee(t,c,a,f),d=re(t,c,n),V=ae(t,u),{clear:l,errors:h,formData:b,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g}=z(r,t,f,V);return{clear:l,errors:h,formData:b,formFieldInjectionKey:a,formInjectionKey:t,formWrapperInjectionKey:c,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g,VvFormField:u,VvFormFieldsGroup:d,VvFormTemplate:V,VvFormWrapper:v}}const J=Symbol("pluginInjectionKey");function ne(r){let f={};return r.schema&&(f=K(r.schema,r)),{...f,install(t,{global:c=!1}={}){t.provide(J,r),c&&(t.config.globalProperties.$vvForm=r,f!=null&&f.VvForm&&t.component("VvForm",f.VvForm),f!=null&&f.VvFormWrapper&&t.component("VvFormWrapper",f.VvFormWrapper),f!=null&&f.VvFormField&&t.component("VvFormField",f.VvFormField),f!=null&&f.VvFormTemplate&&t.component("VvFormTemplate",f.VvFormTemplate))}}}function le(r,f={}){return e.getCurrentInstance()?K(r,{...e.inject(J,{}),...f}):K(r,f)}function ue(r,f={}){return K(r,f)}A.FormFieldType=p,A.createForm=ne,A.defaultObjectBySchema=L,A.formFactory=ue,A.pluginInjectionKey=J,A.useForm=le,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(A,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(A=typeof globalThis<"u"?globalThis:A||self,e(A["@volverjs/form-vue"]={},A.Vue,A.VueUseCore,A.zod))})(this,function(A,e,T,B){"use strict";var p=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(p||{}),G=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.reset="reset",r.updated="updated",r.unknown="unknown",r))(G||{});function L(r,s={}){const t=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional&&(u=u._def.innerType),u},c=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional},a=t(r);return{...(a instanceof B.ZodObject?a._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(a.shape).map(([v,u])=>{const d=s[v],V=c(u);let l=t(u),h;if(l instanceof B.ZodDefault&&(h=l._def.defaultValue(),l=l._def.innerType),d===null&&l instanceof B.ZodNullable)return[v,d];if(d==null&&V)return[v,h];if(l instanceof B.ZodSchema){const b=u.safeParse(d);if(b.success)return[v,b.data??h]}if(l instanceof B.ZodArray&&Array.isArray(d)&&d.length){const b=t(l._def.type);if(b instanceof B.ZodObject)return[v,d.map(y=>L(b,y&&typeof y=="object"?y:void 0))]}if(l instanceof B.ZodRecord&&d){const b=t(l._def.valueType);if(b instanceof B.ZodObject)return[v,Object.keys(d).reduce((y,o)=>(y[o]=L(b,d[o]),y),{})]}return l instanceof B.ZodObject?[v,L(l,d&&typeof d=="object"?d:h)]:[v,h]}))}}function z(r,s,t,c){const a=e.ref(),n=e.ref(),v=e.computed(()=>n.value===G.invalid),u=e.ref(),d=e.ref(!1);let V;const l=async(x=u.value,w)=>{if(V=w,d.value)return!0;const g=await r.safeParseAsync(x);if(!g.success){if(n.value=G.invalid,!w)return a.value=g.error.format(),!1;const i=g.error.issues.filter(U=>w.has(U.path.join(".")));return i.length?(a.value=new B.ZodError(i).format(),!1):(a.value=void 0,!0)}return a.value=void 0,n.value=G.valid,u.value=g.data,!0},h=()=>{a.value=void 0,n.value=void 0,V=void 0},b=()=>{u.value=L(r),h(),n.value=G.reset},y=async()=>d.value||!await l()?!1:(n.value=G.submitting,!0),{ignoreUpdates:o,stop:O}=T.watchIgnorable(u,()=>{n.value=G.updated},{deep:!0,eventFilter:T.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),S=e.readonly(a),E=e.readonly(n),k=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(x,{emit:w}){return u.value=L(r,e.toRaw(x.modelValue)),e.watch(()=>x.modelValue,g=>{if(g){const i=e.isProxy(g)?e.toRaw(g):g;if(JSON.stringify(i)===JSON.stringify(e.toRaw(u.value)))return;u.value=typeof(i==null?void 0:i.clone)=="function"?i.clone():JSON.parse(JSON.stringify(i))}},{deep:!0}),e.watch(n,async g=>{var i,U,R,W,$,M;if(g===G.invalid){const C=e.toRaw(a.value);w("invalid",C),(i=t==null?void 0:t.onInvalid)==null||i.call(t,C);return}if(g===G.valid){const C=e.toRaw(u.value);w("valid",C),(U=t==null?void 0:t.onValid)==null||U.call(t,C),w("update:modelValue",C),(R=t==null?void 0:t.onUpdate)==null||R.call(t,C);return}if(g===G.submitting){const C=e.toRaw(u.value);w("submit",C),(W=t==null?void 0:t.onSubmit)==null||W.call(t,C);return}if(g===G.reset){const C=e.toRaw(u.value);w("reset",C),($=t==null?void 0:t.onReset)==null||$.call(t,C);return}if(g===G.updated){if((a.value||t!=null&&t.continuousValidation||x.continuousValidation)&&await l(void 0,V),!u.value||!x.modelValue||JSON.stringify(u.value)!==JSON.stringify(x.modelValue)){const C=e.toRaw(u.value);w("update:modelValue",C),(M=t==null?void 0:t.onUpdate)==null||M.call(t,C)}n.value===G.updated&&(n.value=G.unknown)}}),e.onMounted(()=>{d.value=x.readonly}),e.watch(()=>x.readonly,g=>{d.value=g}),e.watch(d,g=>{g!==x.readonly&&w("update:readonly",d.value)}),e.provide(s,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}),{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,isReadonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}},render(){const x=()=>{var w,g;return((g=(w=this.$slots)==null?void 0:w.default)==null?void 0:g.call(w,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"]),onReset:e.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&c?[e.h(c,{schema:this.template??(t==null?void 0:t.template)},{default:x})]:{default:x})}});return{clear:h,errors:a,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:n,stopUpdatesWatch:O,submit:y,validate:l,VvForm:k}}function P(r){return Array.isArray(r)}function j(r){return typeof r<"u"}function H(r){return r===null}function Q(r){return typeof r=="object"}function X(r){return typeof r=="string"}function _(r){return typeof r>"u"}const D=/^[0-9]+$/,F=["__proto__","prototype","constructor"];function Z(r,s,t){const c=j(t)?t:void 0;if(!Q(r)||!X(s))return c;const a=Y(s);if(a.length!==0){for(const n of a){if(n==="*")continue;const v=function(u){return u.map(d=>_(d)||H(d)?d:P(d)?v(d):d[n])};if(P(r)&&!D.test(n)?r=v(r):r=r[n],_(r)||H(r))break}return _(r)?c:r}}function q(r,s,t){if(!Q(r)||!X(s))return;const c=Y(s);if(c.length===0)return;const a=c.length;for(let n=0;n<a;n++){const v=c[n];if(n===a-1){r[v]=t;return}if(v==="*"&&P(r)){const u=c.slice(n+1).join(".");for(const d of r)q(d,u,t);return}_(r[v])&&(r[v]={}),r=r[v]}}function Y(r){const s=r.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return s.some(t=>F.indexOf(t)!==-1)?[]:s}function ee(r,s,t,c){return e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:a=>Object.values(p).includes(a),default:p.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},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(a,{slots:n,emit:v}){const{props:u,name:d}=e.toRefs(a),V=e.inject(s,void 0);V&&V.fields.value.add(a.name);const l=e.inject(r),h=e.computed({get(){if(l!=null&&l.formData)return Z(new Object(l.formData.value),String(a.name))},set(i){l!=null&&l.formData&&(q(new Object(l.formData.value),String(a.name),i),v("update:modelValue",{newValue:h.value,formData:l==null?void 0:l.formData}))}});e.onMounted(()=>{h.value===void 0&&a.defaultValue!==void 0&&(h.value=a.defaultValue)});const b=e.computed(()=>{if(l!=null&&l.errors.value)return Z(l.errors.value,String(a.name))}),y=e.computed(()=>{var i;return(i=b.value)==null?void 0:i._errors}),o=e.computed(()=>b.value!==void 0),O=e.watch(o,()=>{if(o.value){v("invalid",b.value),V&&V.errors.value.set(String(a.name),b.value);return}v("valid",h.value),V&&V.errors.value.delete(a.name)}),S=e.watch(()=>l==null?void 0:l.formData,()=>{v("update:formData",l==null?void 0:l.formData)},{deep:!0});e.onBeforeUnmount(()=>{O(),S()});const E=i=>{i instanceof InputEvent&&(i=i.target.value),h.value=i},k=e.computed(()=>{let i=u.value;return typeof i=="function"&&(i=i(l==null?void 0:l.formData)),Object.keys(i).reduce((U,R)=>(U[R]=e.unref(i[R]),U),{})}),x=e.computed(()=>l!=null&&l.readonly.value?!0:k.value.readonly??a.readonly),w=e.computed(()=>({...k.value,name:k.value.name??a.name,invalid:o.value,valid:a.showValid?!!(!o.value&&h.value):void 0,type:(i=>{if([p.color,p.date,p.datetimeLocal,p.email,p.month,p.number,p.password,p.search,p.tel,p.text,p.time,p.url,p.week].includes(i))return i})(a.type),invalidLabel:y.value,modelValue:h.value,readonly:x.value,"onUpdate:modelValue":E}));return e.provide(t,{name:e.readonly(d),errors:e.readonly(b)}),{component:e.computed(()=>{if(a.type===p.custom)return{render(){var i;return((i=n.default)==null?void 0:i.call(n,{errors:b.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,invalid:o.value,invalidLabel:y.value,modelValue:h.value,onUpdate:E,readonly:x.value,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate}))??n.default}};if(!((c==null?void 0:c.lazyLoad)??a.lazyLoad)){let i;switch(a.type){case p.select:i=e.resolveComponent("VvSelect");break;case p.checkbox:i=e.resolveComponent("VvCheckbox");break;case p.radio:i=e.resolveComponent("VvRadio");break;case p.textarea:i=e.resolveComponent("VvTextarea");break;case p.radioGroup:i=e.resolveComponent("VvRadioGroup");break;case p.checkboxGroup:i=e.resolveComponent("VvCheckboxGroup");break;case p.combobox:i=e.resolveComponent("VvCombobox");break;default:i=e.resolveComponent("VvInputText")}if(typeof i!="string")return i;console.warn(`[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(c!=null&&c.sideEffects&&await Promise.resolve(c.sideEffects(a.type)),a.type){case p.textarea:return import("@volverjs/ui-vue/vv-textarea");case p.radio:return import("@volverjs/ui-vue/vv-radio");case p.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case p.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case p.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case p.select:return import("@volverjs/ui-vue/vv-select");case p.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:w,invalid:o}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===p.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}})}function re(r,s,t){return e.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array,Object],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(c,{slots:a,emit:n}){const{props:v,names:u,defaultValues:d}=e.toRefs(c),V=e.computed(()=>Array.isArray(u.value)?u.value:Object.values(u.value)),l=e.computed(()=>Array.isArray(u.value)?u.value:Object.keys(u.value)),h=e.computed(()=>Array.isArray(u.value)?u.value.reduce((f,m)=>(f[String(m)]=m,f),{}):u.value),b=e.computed(()=>Object.keys(h.value).reduce((f,m)=>(f[String(h.value[m])]=m,f),{})),y=e.inject(s,void 0);y&&V.value.forEach(f=>{y.fields.value.add(f)});const o=e.inject(r),O=e.computed({get(){return o!=null&&o.formData?l.value.reduce((f,m)=>(f[m]=Z(new Object(o.formData.value),h.value[m]),f),{}):{}},set(f){o!=null&&o.formData&&(l.value.forEach(m=>{q(new Object(o.formData.value),h.value[m],f==null?void 0:f[m])}),n("update:modelValue",{newValue:O.value,formData:o==null?void 0:o.formData}))}});e.onMounted(()=>{d.value&&V.value.forEach(f=>{var m,I;((m=d.value)==null?void 0:m[f])!==void 0&&O.value[f]===void 0&&(O.value={...O.value,[f]:(I=d.value)==null?void 0:I[f]})})});const S=e.computed(()=>{if(!(o!=null&&o.errors.value))return;const f=V.value.reduce((m,I)=>{if(!o.errors.value)return m;const N=Z(o.errors.value,String(I));return N===void 0||(m[String(I)]=N),m},{});if(Object.keys(f).length!==0)return f}),E=e.computed(()=>{if(!S.value)return;const f=Object.keys(S.value).reduce((m,I)=>{var N;return(N=S.value)!=null&&N[I]&&(m[b.value[I]]=S.value[I]._errors),m},{});if(Object.keys(f).length!==0)return f}),k=e.computed(()=>S.value!==void 0),x=e.computed(()=>l.value.reduce((f,m)=>{var I;return f[m]=!!((I=S.value)!=null&&I[b.value[m]]),f},{})),w=e.watch(k,()=>{if(k.value){n("invalid",S.value),y&&V.value.forEach(f=>{var m,I;if(!((m=S.value)!=null&&m[f])){y.errors.value.delete(f);return}y.errors.value.set(f,(I=S.value)==null?void 0:I[f])});return}n("valid",O.value),y&&V.value.forEach(f=>{y.errors.value.delete(f)})}),g=e.watch(()=>o==null?void 0:o.formData,()=>{n("update:formData",o==null?void 0:o.formData)},{deep:!0});e.onBeforeUnmount(()=>{w(),g()});const i=f=>{O.value=f},U=(f,m)=>{m instanceof InputEvent&&(m=m.target.value),l.value.includes(f)&&(O.value={...O.value,[f]:m})},R=e.computed(()=>{let f=v.value;return typeof f=="function"&&(f=f(o==null?void 0:o.formData)),Object.keys(f).reduce((m,I)=>(m[I]=e.unref(f[I]),m),{})}),W=e.computed(()=>o!=null&&o.readonly.value?!0:R.value.readonly??c.readonly),$=e.computed(()=>l.value.reduce((f,m)=>(f[`onUpdate:${m}`]=I=>{U(m,I)},f),{"onUpdate:modelValue":i})),M=e.computed(()=>({...$.value,...R.value,names:R.value.name??V.value,invalid:k.value,invalids:x.value,valid:c.showValid?!!(!k.value&&O.value):void 0,invalidLabels:E.value,modelValue:O.value,readonly:W.value}));return e.provide(t,{names:e.readonly(u),errors:e.readonly(S)}),{component:e.computed(()=>({render(){var f;return((f=a.default)==null?void 0:f.call(a,{errors:S.value,formData:o==null?void 0:o.formData.value,formErrors:o==null?void 0:o.errors.value,invalid:k.value,invalids:x.value,invalidLabels:E.value,modelValue:O.value,onUpdate:i,onUpdateField:U,readonly:W.value,submit:o==null?void 0:o.submit,validate:o==null?void 0:o.validate}))??a.default}})),hasProps:M,invalid:k}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):e.h(this.component,null,this.$slots)}})}function te(r,s){return e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:c}){const a=e.inject(r),n=e.inject(s,void 0),v=e.ref(new Set),u=e.ref(new Map),{name:d}=e.toRefs(t);e.provide(s,{name:e.readonly(d),errors:u,fields:v}),e.watch(v,h=>{n!=null&&n.fields&&h.forEach(b=>{n==null||n.fields.value.add(b)})},{deep:!0}),e.watch(()=>new Map(u.value),(h,b)=>{n!=null&&n.errors&&(Array.from(b.keys()).forEach(y=>{n.errors.value.delete(y)}),Array.from(h.keys()).forEach(y=>{const o=h.get(y);o&&n.errors.value.set(y,o)}))},{deep:!0});const V=e.computed(()=>a!=null&&a.invalid.value?u.value.size>0:!1);e.watch(V,()=>{V.value?c("invalid"):c("valid")});const l=()=>(a==null?void 0:a.validate(void 0,v.value))??Promise.resolve(!0);return{clear:a==null?void 0:a.clear,errors:a==null?void 0:a.errors,fields:v,fieldsErrors:u,formData:a==null?void 0:a.formData,invalid:V,reset:a==null?void 0:a.reset,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate,validateWrapper:l}},render(){const t=()=>{var c,a;return(a=(c=this.$slots).default)==null?void 0:a.call(c,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?e.h(this.tag,null,{default:t}):t()}})}function ae(r,s){const t=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(c,{slots:a}){const n=e.inject(r);if(n!=null&&n.formData)return()=>{var V;const v=typeof c.schema=="function"?c.schema(n,c.scope):c.schema;let u;const d=v.reduce((l,h)=>{const b=typeof h=="function"?h(n,c.scope):h,{vvIs:y,vvName:o,vvSlots:O,vvChildren:S,vvIf:E,vvElseIf:k,vvType:x,vvDefaultValue:w,vvShowValid:g,vvContent:i,...U}=b;if(E!==void 0){if(typeof E=="string"?u=!!Z(new Object(n.formData.value),E):typeof E=="function"?u=e.unref(E(n)):u=e.unref(E),!u)return l}else if(k!==void 0&&u!==void 0){if(u||(typeof k=="string"?u=!!Z(new Object(n.formData.value),k):typeof k=="function"?u=e.unref(k(n)):u=e.unref(k),!u))return l}else u=void 0;let R;return S&&(typeof y=="string"?R=e.h(t,{schema:S}):R={default:W=>e.h(t,{schema:S,scope:W})}),o?(l.push(e.h(s,{name:o,is:y,type:x,defaultValue:w,showValid:g,props:U},O??R??i)),l):y?(l.push(e.h(y,U,O??R??i)),l):(R&&("default"in R?l.push(R.default(c.scope)):l.push(R)),l)},[]);return d.push((V=a==null?void 0:a.default)==null?void 0:V.call(a,{errors:n==null?void 0:n.errors.value,formData:n==null?void 0:n.formData.value,invalid:n==null?void 0:n.invalid.value,status:n==null?void 0:n.status.value,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,clear:n==null?void 0:n.clear,reset:n==null?void 0:n.reset})),d}}});return t}function K(r,s={}){const t=Symbol("formInjectionKey"),c=Symbol("formWrapperInjectionKey"),a=Symbol("formFieldInjectionKey"),n=Symbol("formFieldsGroupInjectionKey"),v=te(t,c),u=ee(t,c,a,s),d=re(t,c,n),V=ae(t,u),{clear:l,errors:h,formData:b,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g}=z(r,t,s,V);return{clear:l,errors:h,formData:b,formFieldInjectionKey:a,formInjectionKey:t,formWrapperInjectionKey:c,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g,VvFormField:u,VvFormFieldsGroup:d,VvFormTemplate:V,VvFormWrapper:v}}const J=Symbol("pluginInjectionKey");function ne(r){let s={};return r.schema&&(s=K(r.schema,r)),{...s,install(t,{global:c=!1}={}){t.provide(J,r),c&&(t.config.globalProperties.$vvForm=r,s!=null&&s.VvForm&&t.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&t.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&t.component("VvFormField",s.VvFormField),s!=null&&s.VvFormFieldsGroup&&t.component("VvFormFieldsGroup",s.VvFormFieldsGroup),s!=null&&s.VvFormTemplate&&t.component("VvFormTemplate",s.VvFormTemplate))}}}function le(r,s={}){return e.getCurrentInstance()?K(r,{...e.inject(J,{}),...s}):K(r,s)}function ue(r,s={}){return K(r,s)}A.FormFieldType=p,A.createForm=ne,A.defaultObjectBySchema=L,A.formFactory=ue,A.pluginInjectionKey=J,A.useForm=le,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volverjs/form-vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.25",
|
|
5
5
|
"description": "Vue 3 Forms with @volverjs/ui-vue",
|
|
6
6
|
"author": "8 Wave S.r.l.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@volverjs/ui-vue": "^0.*",
|
|
54
|
-
"@vueuse/core": "^
|
|
54
|
+
"@vueuse/core": "^11.*",
|
|
55
55
|
"ts-dot-prop": "^2.*",
|
|
56
56
|
"vue": "^3.*",
|
|
57
57
|
"zod": "^3.*"
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
"@nabla/vite-plugin-eslint": "^2.0.4",
|
|
62
62
|
"@playwright/experimental-ct-vue": "1.48.2",
|
|
63
63
|
"@testing-library/vue": "^8.1.0",
|
|
64
|
-
"@vitejs/plugin-vue": "^5.1.
|
|
65
|
-
"@volverjs/style": "0.1.
|
|
64
|
+
"@vitejs/plugin-vue": "^5.1.5",
|
|
65
|
+
"@volverjs/style": "0.1.15",
|
|
66
66
|
"@vue/compiler-sfc": "^3.5.12",
|
|
67
67
|
"@vue/runtime-core": "^3.5.12",
|
|
68
68
|
"@vue/test-utils": "^2.4.6",
|
|
69
69
|
"copy": "^0.3.2",
|
|
70
70
|
"eslint": "^9.14.0",
|
|
71
|
-
"happy-dom": "^15.
|
|
71
|
+
"happy-dom": "^15.11.0",
|
|
72
72
|
"typescript": "^5.6.3",
|
|
73
|
-
"vite": "^5.4.
|
|
73
|
+
"vite": "^5.4.11",
|
|
74
74
|
"vite-plugin-dts": "^4.3.0",
|
|
75
75
|
"vite-plugin-externalize-deps": "^0.8.0",
|
|
76
76
|
"vitest": "^2.1.4"
|
package/src/VvFormFieldsGroup.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function defineFormFieldsGroup<Schema extends FormSchema>(formProvideKey:
|
|
|
36
36
|
default: undefined,
|
|
37
37
|
},
|
|
38
38
|
names: {
|
|
39
|
-
type: [Array] as PropType<
|
|
39
|
+
type: [Array, Object] as PropType<
|
|
40
40
|
Path<z.infer<Schema>>[] | Record<string, Path<z.infer<Schema>>>
|
|
41
41
|
>,
|
|
42
42
|
required: true,
|
package/src/index.ts
CHANGED
|
@@ -117,6 +117,9 @@ export function createForm(options: FormPluginOptions): Plugin & Partial<ReturnT
|
|
|
117
117
|
if (toReturn?.VvFormField) {
|
|
118
118
|
app.component('VvFormField', toReturn.VvFormField)
|
|
119
119
|
}
|
|
120
|
+
if (toReturn?.VvFormFieldsGroup) {
|
|
121
|
+
app.component('VvFormFieldsGroup', toReturn.VvFormFieldsGroup)
|
|
122
|
+
}
|
|
120
123
|
if (toReturn?.VvFormTemplate) {
|
|
121
124
|
app.component('VvFormTemplate', toReturn.VvFormTemplate)
|
|
122
125
|
}
|
|
@@ -144,12 +147,14 @@ export { defaultObjectBySchema } from './utils'
|
|
|
144
147
|
type FormComponent = ReturnType<typeof defineForm>
|
|
145
148
|
type FormWrapperComponent = ReturnType<typeof defineFormWrapper>
|
|
146
149
|
type FormFieldComponent = ReturnType<typeof defineFormField>
|
|
147
|
-
type
|
|
150
|
+
type FormFieldsGroupComponent = ReturnType<typeof defineFormFieldsGroup>
|
|
151
|
+
type FormTemplateComponent = ReturnType<typeof defineFormFieldsGroup>
|
|
148
152
|
|
|
149
153
|
export type {
|
|
150
154
|
FormComponent,
|
|
151
155
|
FormComposableOptions,
|
|
152
156
|
FormFieldComponent,
|
|
157
|
+
FormFieldsGroupComponent,
|
|
153
158
|
FormPluginOptions,
|
|
154
159
|
FormSchema,
|
|
155
160
|
FormTemplate,
|