@volverjs/form-vue 0.0.10-beta.4 → 0.0.10-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/VvForm.d.ts +132 -37
- package/dist/VvFormField.d.ts +7 -19
- package/dist/VvFormTemplate.d.ts +20 -0
- package/dist/VvFormWrapper.d.ts +120 -32
- package/dist/enums.d.ts +4 -0
- package/dist/index.d.ts +520 -97
- package/dist/index.es.js +398 -305
- package/dist/index.umd.js +1 -1
- package/dist/types.d.ts +98 -20
- package/dist/utils.d.ts +2 -13
- package/package.json +7 -6
- package/src/VvForm.ts +146 -120
- package/src/VvFormField.ts +16 -18
- package/src/VvFormTemplate.ts +161 -0
- package/src/VvFormWrapper.ts +50 -21
- package/src/enums.ts +5 -0
- package/src/index.ts +22 -19
- package/src/types.d.ts +98 -20
- package/src/utils.ts +2 -6
package/dist/index.es.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { watchThrottled as
|
|
3
|
-
import { ZodObject as
|
|
4
|
-
function
|
|
1
|
+
import { defineComponent as N, computed as V, onMounted as Y, onBeforeUnmount as D, inject as O, toRefs as J, watch as w, provide as _, readonly as g, resolveComponent as b, defineAsyncComponent as R, h as y, ref as E, isProxy as T, toRaw as j, withModifiers as F, unref as $ } from "vue";
|
|
2
|
+
import { watchThrottled as ee } from "@vueuse/core";
|
|
3
|
+
import { ZodObject as K, ZodDefault as re, ZodNullable as te, ZodSchema as ne, ZodEffects as oe } from "zod";
|
|
4
|
+
function L(e) {
|
|
5
5
|
return Array.isArray(e);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function ae(e) {
|
|
8
8
|
return typeof e < "u";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function M(e) {
|
|
11
11
|
return e === null;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function U(e) {
|
|
14
14
|
return typeof e == "object";
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function q(e) {
|
|
17
17
|
return typeof e == "string";
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function C(e) {
|
|
20
20
|
return typeof e > "u";
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
26
|
-
return
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
for (const
|
|
30
|
-
if (
|
|
22
|
+
const se = /^[0-9]+$/, ue = ["__proto__", "prototype", "constructor"];
|
|
23
|
+
function Z(e, o, i) {
|
|
24
|
+
const l = ae(i) ? i : void 0;
|
|
25
|
+
if (!U(e) || !q(o))
|
|
26
|
+
return l;
|
|
27
|
+
const n = P(o);
|
|
28
|
+
if (n.length !== 0) {
|
|
29
|
+
for (const r of n) {
|
|
30
|
+
if (r === "*")
|
|
31
31
|
continue;
|
|
32
|
-
const
|
|
33
|
-
return
|
|
32
|
+
const a = function(s) {
|
|
33
|
+
return s.map((u) => C(u) || M(u) ? u : L(u) ? a(u) : u[r]);
|
|
34
34
|
};
|
|
35
|
-
if (
|
|
35
|
+
if (L(e) && !se.test(r) ? e = a(e) : e = e[r], C(e) || M(e))
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return C(e) ? l : e;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
41
|
+
function z(e, o, i) {
|
|
42
|
+
if (!U(e) || !q(o))
|
|
43
43
|
return;
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
44
|
+
const l = P(o);
|
|
45
|
+
if (l.length === 0)
|
|
46
46
|
return;
|
|
47
|
-
const
|
|
48
|
-
for (let
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
e[
|
|
47
|
+
const n = l.length;
|
|
48
|
+
for (let r = 0; r < n; r++) {
|
|
49
|
+
const a = l[r];
|
|
50
|
+
if (r === n - 1) {
|
|
51
|
+
e[a] = i;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
for (const
|
|
57
|
-
|
|
54
|
+
if (a === "*" && L(e)) {
|
|
55
|
+
const s = l.slice(r + 1).join(".");
|
|
56
|
+
for (const u of e)
|
|
57
|
+
z(u, s, i);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
C(e[a]) && (e[a] = {}), e = e[a];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((
|
|
65
|
-
return o.some((
|
|
63
|
+
function P(e) {
|
|
64
|
+
const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((i) => !!i);
|
|
65
|
+
return o.some((i) => ue.indexOf(i) !== -1) ? [] : o;
|
|
66
66
|
}
|
|
67
|
-
var
|
|
68
|
-
const
|
|
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 || {}), G = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(G || {});
|
|
68
|
+
const ie = (e, o, i, l = {}) => N({
|
|
69
69
|
name: "FieldComponent",
|
|
70
70
|
props: {
|
|
71
71
|
type: {
|
|
72
72
|
type: String,
|
|
73
|
-
validator: (
|
|
74
|
-
default:
|
|
73
|
+
validator: (n) => Object.values(f).includes(n),
|
|
74
|
+
default: f.custom
|
|
75
75
|
},
|
|
76
76
|
is: {
|
|
77
77
|
type: [Object, String],
|
|
@@ -96,252 +96,271 @@ const oe = (e, o, a, s = {}) => E({
|
|
|
96
96
|
},
|
|
97
97
|
emits: ["invalid", "valid", "update:formData", "update:modelValue"],
|
|
98
98
|
expose: ["invalid", "invalidLabel", "errors"],
|
|
99
|
-
setup(
|
|
100
|
-
const
|
|
99
|
+
setup(n, { slots: r, emit: a }) {
|
|
100
|
+
const s = V({
|
|
101
101
|
get() {
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
104
|
-
Object(
|
|
105
|
-
String(
|
|
102
|
+
if (t != null && t.formData)
|
|
103
|
+
return Z(
|
|
104
|
+
Object(t.formData.value),
|
|
105
|
+
String(n.name)
|
|
106
106
|
);
|
|
107
107
|
},
|
|
108
|
-
set(
|
|
109
|
-
|
|
110
|
-
Object(
|
|
111
|
-
String(
|
|
112
|
-
|
|
113
|
-
),
|
|
114
|
-
newValue:
|
|
115
|
-
formData:
|
|
108
|
+
set(c) {
|
|
109
|
+
t != null && t.formData && (z(
|
|
110
|
+
Object(t.formData.value),
|
|
111
|
+
String(n.name),
|
|
112
|
+
c
|
|
113
|
+
), a("update:modelValue", {
|
|
114
|
+
newValue: s.value,
|
|
115
|
+
formData: t == null ? void 0 : t.formData
|
|
116
116
|
}));
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}),
|
|
122
|
-
|
|
119
|
+
Y(() => {
|
|
120
|
+
s.value === void 0 && n.defaultValue !== void 0 && (s.value = n.defaultValue);
|
|
121
|
+
}), D(() => {
|
|
122
|
+
S(), k();
|
|
123
123
|
});
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
129
|
-
}),
|
|
130
|
-
var
|
|
131
|
-
return (
|
|
132
|
-
}),
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
const u = O(o, void 0);
|
|
125
|
+
u && u.fields.value.add(n.name);
|
|
126
|
+
const t = O(e), { props: m, name: p } = J(n), h = V(() => {
|
|
127
|
+
if (t != null && t.errors.value)
|
|
128
|
+
return Z(t.errors.value, String(n.name));
|
|
129
|
+
}), v = V(() => {
|
|
130
|
+
var c;
|
|
131
|
+
return (c = h.value) == null ? void 0 : c._errors;
|
|
132
|
+
}), d = V(() => h.value !== void 0), S = w(d, () => {
|
|
133
|
+
d.value ? (a("invalid", v.value), u && u.errors.value.set(
|
|
134
|
+
n.name,
|
|
135
135
|
{
|
|
136
|
-
_errors:
|
|
136
|
+
_errors: v.value
|
|
137
137
|
}
|
|
138
|
-
)) : (
|
|
139
|
-
|
|
138
|
+
)) : (a("valid", s.value), u && u.errors.value.delete(
|
|
139
|
+
n.name
|
|
140
140
|
));
|
|
141
|
-
}),
|
|
142
|
-
() =>
|
|
141
|
+
}), k = w(
|
|
142
|
+
() => t == null ? void 0 : t.formData,
|
|
143
143
|
() => {
|
|
144
|
-
|
|
144
|
+
a("update:formData", t == null ? void 0 : t.formData);
|
|
145
145
|
},
|
|
146
146
|
{ deep: !0 }
|
|
147
|
-
),
|
|
148
|
-
|
|
149
|
-
},
|
|
150
|
-
...
|
|
151
|
-
name:
|
|
152
|
-
invalid:
|
|
153
|
-
valid:
|
|
154
|
-
type: ((
|
|
147
|
+
), x = (c) => {
|
|
148
|
+
s.value = c;
|
|
149
|
+
}, I = V(() => typeof m.value == "function" ? m.value(t == null ? void 0 : t.formData) : m.value), W = V(() => ({
|
|
150
|
+
...I.value,
|
|
151
|
+
name: I.value.name ?? n.name,
|
|
152
|
+
invalid: d.value,
|
|
153
|
+
valid: n.showValid ? !!(!d.value && s.value) : void 0,
|
|
154
|
+
type: ((c) => {
|
|
155
155
|
if ([
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
].includes(
|
|
170
|
-
return
|
|
171
|
-
})(
|
|
172
|
-
invalidLabel:
|
|
173
|
-
modelValue:
|
|
174
|
-
errors:
|
|
175
|
-
"onUpdate:modelValue":
|
|
156
|
+
f.text,
|
|
157
|
+
f.number,
|
|
158
|
+
f.email,
|
|
159
|
+
f.password,
|
|
160
|
+
f.tel,
|
|
161
|
+
f.url,
|
|
162
|
+
f.search,
|
|
163
|
+
f.date,
|
|
164
|
+
f.time,
|
|
165
|
+
f.datetimeLocal,
|
|
166
|
+
f.month,
|
|
167
|
+
f.week,
|
|
168
|
+
f.color
|
|
169
|
+
].includes(c))
|
|
170
|
+
return c;
|
|
171
|
+
})(n.type),
|
|
172
|
+
invalidLabel: v.value,
|
|
173
|
+
modelValue: s.value,
|
|
174
|
+
errors: n.is ? h.value : void 0,
|
|
175
|
+
"onUpdate:modelValue": x
|
|
176
176
|
}));
|
|
177
|
-
return
|
|
178
|
-
name:
|
|
179
|
-
errors:
|
|
177
|
+
return _(i, {
|
|
178
|
+
name: g(p),
|
|
179
|
+
errors: g(h)
|
|
180
180
|
}), { component: V(() => {
|
|
181
|
-
if (
|
|
181
|
+
if (n.type === f.custom)
|
|
182
182
|
return {
|
|
183
183
|
render() {
|
|
184
|
-
var
|
|
185
|
-
return ((
|
|
186
|
-
modelValue:
|
|
187
|
-
onUpdate:
|
|
188
|
-
invalid:
|
|
189
|
-
invalidLabel:
|
|
190
|
-
formData:
|
|
191
|
-
formErrors:
|
|
192
|
-
errors:
|
|
193
|
-
})) ??
|
|
184
|
+
var c;
|
|
185
|
+
return ((c = r.default) == null ? void 0 : c.call(r, {
|
|
186
|
+
modelValue: s.value,
|
|
187
|
+
onUpdate: x,
|
|
188
|
+
invalid: d.value,
|
|
189
|
+
invalidLabel: v.value,
|
|
190
|
+
formData: t == null ? void 0 : t.formData.value,
|
|
191
|
+
formErrors: t == null ? void 0 : t.errors.value,
|
|
192
|
+
errors: h.value
|
|
193
|
+
})) ?? r.defalut;
|
|
194
194
|
}
|
|
195
195
|
};
|
|
196
|
-
if (!
|
|
197
|
-
let
|
|
198
|
-
switch (
|
|
199
|
-
case
|
|
200
|
-
|
|
196
|
+
if (!l.lazyLoad) {
|
|
197
|
+
let c;
|
|
198
|
+
switch (n.type) {
|
|
199
|
+
case f.select:
|
|
200
|
+
c = b("VvSelect");
|
|
201
201
|
break;
|
|
202
|
-
case
|
|
203
|
-
|
|
202
|
+
case f.checkbox:
|
|
203
|
+
c = b("VvCheckbox");
|
|
204
204
|
break;
|
|
205
|
-
case
|
|
206
|
-
|
|
205
|
+
case f.radio:
|
|
206
|
+
c = b("VvRadio");
|
|
207
207
|
break;
|
|
208
|
-
case
|
|
209
|
-
|
|
208
|
+
case f.textarea:
|
|
209
|
+
c = b("VvTextarea");
|
|
210
210
|
break;
|
|
211
|
-
case
|
|
212
|
-
|
|
211
|
+
case f.radioGroup:
|
|
212
|
+
c = b("VvRadioGroup");
|
|
213
213
|
break;
|
|
214
|
-
case
|
|
215
|
-
|
|
214
|
+
case f.checkboxGroup:
|
|
215
|
+
c = b("VvCheckboxGroup");
|
|
216
216
|
break;
|
|
217
|
-
case
|
|
218
|
-
|
|
217
|
+
case f.combobox:
|
|
218
|
+
c = b("VvCombobox");
|
|
219
219
|
break;
|
|
220
220
|
default:
|
|
221
|
-
|
|
221
|
+
c = b("VvInputText");
|
|
222
222
|
}
|
|
223
|
-
if (typeof
|
|
224
|
-
return
|
|
223
|
+
if (typeof c != "string")
|
|
224
|
+
return c;
|
|
225
225
|
console.warn(
|
|
226
|
-
`[form-vue warn]: ${
|
|
226
|
+
`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
|
-
return
|
|
230
|
-
switch (
|
|
231
|
-
case
|
|
229
|
+
return R(async () => {
|
|
230
|
+
switch (l.sideEffects && await Promise.resolve(l.sideEffects(n.type)), n.type) {
|
|
231
|
+
case f.textarea:
|
|
232
232
|
return import("@volverjs/ui-vue/vv-textarea");
|
|
233
|
-
case
|
|
233
|
+
case f.radio:
|
|
234
234
|
return import("@volverjs/ui-vue/vv-radio");
|
|
235
|
-
case
|
|
235
|
+
case f.radioGroup:
|
|
236
236
|
return import("@volverjs/ui-vue/vv-radio-group");
|
|
237
|
-
case
|
|
237
|
+
case f.checkbox:
|
|
238
238
|
return import("@volverjs/ui-vue/vv-checkbox");
|
|
239
|
-
case
|
|
239
|
+
case f.checkboxGroup:
|
|
240
240
|
return import("@volverjs/ui-vue/vv-checkbox-group");
|
|
241
|
-
case
|
|
241
|
+
case f.combobox:
|
|
242
242
|
return import("@volverjs/ui-vue/vv-combobox");
|
|
243
243
|
}
|
|
244
244
|
return import("@volverjs/ui-vue/vv-input-text");
|
|
245
245
|
});
|
|
246
|
-
}), hasProps:
|
|
246
|
+
}), hasProps: W, invalid: d };
|
|
247
247
|
},
|
|
248
248
|
render() {
|
|
249
|
-
return this.is ?
|
|
249
|
+
return this.is ? y(this.is, this.hasProps, this.$slots) : this.type === f.custom ? y(this.component, null, this.$slots) : y(this.component, this.hasProps, this.$slots);
|
|
250
250
|
}
|
|
251
|
-
}),
|
|
252
|
-
const
|
|
253
|
-
let
|
|
254
|
-
for (;
|
|
255
|
-
|
|
256
|
-
return
|
|
257
|
-
},
|
|
251
|
+
}), H = (e, o = {}) => {
|
|
252
|
+
const i = (r) => {
|
|
253
|
+
let a = r;
|
|
254
|
+
for (; a instanceof oe; )
|
|
255
|
+
a = a.innerType();
|
|
256
|
+
return a;
|
|
257
|
+
}, l = i(e);
|
|
258
258
|
return {
|
|
259
|
-
...(
|
|
259
|
+
...(l instanceof K ? l._def.unknownKeys === "passthrough" : !1) ? o : {},
|
|
260
260
|
...Object.fromEntries(
|
|
261
|
-
Object.entries(
|
|
262
|
-
const
|
|
263
|
-
let
|
|
264
|
-
if (
|
|
265
|
-
return [
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
return [
|
|
261
|
+
Object.entries(l.shape).map(([r, a]) => {
|
|
262
|
+
const s = o[r], u = i(a);
|
|
263
|
+
let t;
|
|
264
|
+
if (u instanceof re && (t = u._def.defaultValue()), s === null && u instanceof te)
|
|
265
|
+
return [r, s];
|
|
266
|
+
if (u instanceof ne) {
|
|
267
|
+
const m = u.safeParse(o[r]);
|
|
268
|
+
if (m.success)
|
|
269
|
+
return [r, m.data ?? t];
|
|
270
270
|
}
|
|
271
|
-
return
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
return u instanceof K ? [
|
|
272
|
+
r,
|
|
273
|
+
H(
|
|
274
|
+
u,
|
|
275
|
+
s && typeof s == "object" ? s : {}
|
|
276
276
|
)
|
|
277
|
-
] : [
|
|
277
|
+
] : [r, t];
|
|
278
278
|
})
|
|
279
279
|
)
|
|
280
280
|
};
|
|
281
|
-
},
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
name: "FormComponent",
|
|
289
|
-
props: {
|
|
290
|
-
modelValue: {
|
|
291
|
-
type: Object,
|
|
292
|
-
default: () => ({})
|
|
293
|
-
},
|
|
294
|
-
continuosValidation: {
|
|
295
|
-
type: Boolean,
|
|
296
|
-
default: !1
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
emits: ["invalid", "valid", "submit", "update:modelValue"],
|
|
300
|
-
expose: ["submit", "errors", "status"],
|
|
301
|
-
setup(l, { emit: u }) {
|
|
302
|
-
t.value = M(
|
|
303
|
-
e,
|
|
304
|
-
l.modelValue
|
|
305
|
-
);
|
|
306
|
-
const c = (a == null ? void 0 : a.continuosValidation) || l.continuosValidation;
|
|
307
|
-
y(
|
|
308
|
-
() => l.modelValue,
|
|
309
|
-
(m) => {
|
|
310
|
-
if (m) {
|
|
311
|
-
const d = Q(m) ? X(m) : m;
|
|
312
|
-
t.value = typeof (d == null ? void 0 : d.clone) == "function" ? d.clone() : JSON.parse(JSON.stringify(d));
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
{ deep: !0 }
|
|
316
|
-
), D(
|
|
317
|
-
t,
|
|
318
|
-
(m) => {
|
|
319
|
-
(s.value || c) && n(), (!m || !l.modelValue || JSON.stringify(m) !== JSON.stringify(l.modelValue)) && u("update:modelValue", m);
|
|
320
|
-
},
|
|
321
|
-
{ deep: !0, throttle: (a == null ? void 0 : a.updateThrottle) ?? 500 }
|
|
322
|
-
);
|
|
323
|
-
const n = (m = t.value) => {
|
|
324
|
-
const d = e.safeParse(m);
|
|
325
|
-
return d.success ? (s.value = void 0, r.value = "valid", t.value = d.data, u("update:modelValue", t.value), u("valid", d.data), !0) : (s.value = d.error.format(), r.value = "invalid", u("invalid", s.value), !1);
|
|
326
|
-
}, v = () => n() ? (u("submit", t.value), !0) : !1;
|
|
327
|
-
return $(o, {
|
|
328
|
-
modelValue: t,
|
|
329
|
-
submit: v,
|
|
330
|
-
errors: w(s)
|
|
331
|
-
}), { submit: v };
|
|
281
|
+
}, le = (e, o, i) => {
|
|
282
|
+
const l = E(), n = E(), r = E(), a = N({
|
|
283
|
+
name: "FormComponent",
|
|
284
|
+
props: {
|
|
285
|
+
modelValue: {
|
|
286
|
+
type: Object,
|
|
287
|
+
default: () => ({})
|
|
332
288
|
},
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
{
|
|
337
|
-
onSubmit: Y(this.submit, ["prevent"])
|
|
338
|
-
},
|
|
339
|
-
this.$slots
|
|
340
|
-
);
|
|
289
|
+
continuosValidation: {
|
|
290
|
+
type: Boolean,
|
|
291
|
+
default: !1
|
|
341
292
|
}
|
|
342
|
-
}
|
|
293
|
+
},
|
|
294
|
+
emits: ["invalid", "valid", "submit", "update:modelValue"],
|
|
295
|
+
expose: ["submit", "errors", "status"],
|
|
296
|
+
setup(s, { emit: u }) {
|
|
297
|
+
r.value = H(e, s.modelValue);
|
|
298
|
+
const t = (i == null ? void 0 : i.continuosValidation) || s.continuosValidation;
|
|
299
|
+
w(
|
|
300
|
+
() => s.modelValue,
|
|
301
|
+
(v) => {
|
|
302
|
+
if (v) {
|
|
303
|
+
const d = T(v) ? j(v) : v;
|
|
304
|
+
r.value = typeof (d == null ? void 0 : d.clone) == "function" ? d.clone() : JSON.parse(JSON.stringify(d));
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{ deep: !0 }
|
|
308
|
+
), ee(
|
|
309
|
+
r,
|
|
310
|
+
(v) => {
|
|
311
|
+
(l.value || t) && m(), (!v || !s.modelValue || JSON.stringify(v) !== JSON.stringify(s.modelValue)) && u("update:modelValue", v);
|
|
312
|
+
},
|
|
313
|
+
{ deep: !0, throttle: (i == null ? void 0 : i.updateThrottle) ?? 500 }
|
|
314
|
+
);
|
|
315
|
+
const m = (v = r.value) => {
|
|
316
|
+
const d = e.safeParse(v);
|
|
317
|
+
return d.success ? (l.value = void 0, n.value = G.valid, r.value = d.data, u("update:modelValue", r.value), u("valid", d.data), !0) : (l.value = d.error.format(), n.value = G.invalid, u("invalid", l.value), !1);
|
|
318
|
+
}, p = () => m() ? (u("submit", r.value), !0) : !1, h = V(() => n.value === G.invalid);
|
|
319
|
+
return _(o, {
|
|
320
|
+
formData: r,
|
|
321
|
+
submit: p,
|
|
322
|
+
errors: g(l),
|
|
323
|
+
status: g(n),
|
|
324
|
+
invalid: h
|
|
325
|
+
}), {
|
|
326
|
+
formData: r,
|
|
327
|
+
submit: p,
|
|
328
|
+
errors: g(l),
|
|
329
|
+
status: g(n),
|
|
330
|
+
invalid: h
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
render() {
|
|
334
|
+
return y(
|
|
335
|
+
"form",
|
|
336
|
+
{
|
|
337
|
+
onSubmit: F(this.submit, ["prevent"])
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
default: () => {
|
|
341
|
+
var s, u;
|
|
342
|
+
return ((u = (s = this.$slots) == null ? void 0 : s.default) == null ? void 0 : u.call(s, {
|
|
343
|
+
formData: this.formData,
|
|
344
|
+
submit: this.submit,
|
|
345
|
+
errors: this.errors,
|
|
346
|
+
status: this.status,
|
|
347
|
+
invalid: this.invalid
|
|
348
|
+
})) ?? this.$slots.default;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
return {
|
|
355
|
+
errors: l,
|
|
356
|
+
status: n,
|
|
357
|
+
formData: r,
|
|
358
|
+
/**
|
|
359
|
+
* An hack to add types to the default slot
|
|
360
|
+
*/
|
|
361
|
+
VvForm: a
|
|
343
362
|
};
|
|
344
|
-
},
|
|
363
|
+
}, fe = (e, o) => N({
|
|
345
364
|
name: "WrapperComponent",
|
|
346
365
|
props: {
|
|
347
366
|
name: {
|
|
@@ -355,104 +374,178 @@ const oe = (e, o, a, s = {}) => E({
|
|
|
355
374
|
},
|
|
356
375
|
emits: ["invalid", "valid"],
|
|
357
376
|
expose: ["fields", "invalid"],
|
|
358
|
-
setup(
|
|
359
|
-
const r =
|
|
360
|
-
|
|
361
|
-
name:
|
|
377
|
+
setup(l, { emit: n }) {
|
|
378
|
+
const r = O(e), a = O(o, void 0), s = E(/* @__PURE__ */ new Set()), u = E(/* @__PURE__ */ new Map()), { name: t } = J(l);
|
|
379
|
+
_(o, {
|
|
380
|
+
name: g(t),
|
|
362
381
|
errors: u,
|
|
363
|
-
fields:
|
|
364
|
-
}),
|
|
365
|
-
|
|
366
|
-
(
|
|
367
|
-
|
|
368
|
-
|
|
382
|
+
fields: s
|
|
383
|
+
}), w(
|
|
384
|
+
s,
|
|
385
|
+
(p) => {
|
|
386
|
+
a != null && a.fields && p.forEach((h) => {
|
|
387
|
+
a == null || a.fields.value.add(h);
|
|
369
388
|
});
|
|
370
389
|
},
|
|
371
390
|
{ deep: !0 }
|
|
372
|
-
),
|
|
391
|
+
), w(
|
|
373
392
|
() => new Map(u.value),
|
|
374
|
-
(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}), Array.from(
|
|
378
|
-
const
|
|
379
|
-
|
|
393
|
+
(p, h) => {
|
|
394
|
+
a != null && a.errors && (Array.from(h.keys()).forEach((v) => {
|
|
395
|
+
a.errors.value.delete(v);
|
|
396
|
+
}), Array.from(p.keys()).forEach((v) => {
|
|
397
|
+
const d = p.get(v);
|
|
398
|
+
d && a.errors.value.set(v, d);
|
|
380
399
|
}));
|
|
381
400
|
},
|
|
382
401
|
{ deep: !0 }
|
|
383
402
|
);
|
|
384
|
-
const
|
|
385
|
-
return
|
|
386
|
-
|
|
403
|
+
const m = V(() => r != null && r.invalid.value ? u.value.size > 0 : !1);
|
|
404
|
+
return w(m, () => {
|
|
405
|
+
m.value ? n("invalid") : n("valid");
|
|
387
406
|
}), {
|
|
388
|
-
formData: r == null ? void 0 : r.
|
|
407
|
+
formData: r == null ? void 0 : r.formData,
|
|
389
408
|
errors: r == null ? void 0 : r.errors,
|
|
390
|
-
invalid:
|
|
391
|
-
fields:
|
|
409
|
+
invalid: m,
|
|
410
|
+
fields: s,
|
|
392
411
|
fieldsErrors: u
|
|
393
412
|
};
|
|
394
413
|
},
|
|
395
414
|
render() {
|
|
396
|
-
var
|
|
397
|
-
return this.tag ?
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
415
|
+
var l, n;
|
|
416
|
+
return this.tag ? y(this.tag, null, {
|
|
417
|
+
default: () => {
|
|
418
|
+
var r, a;
|
|
419
|
+
return ((a = (r = this.$slots).default) == null ? void 0 : a.call(r, {
|
|
420
|
+
invalid: this.invalid,
|
|
421
|
+
formData: this.formData,
|
|
422
|
+
errors: this.errors,
|
|
423
|
+
fieldsErrors: this.fieldsErrors
|
|
424
|
+
})) ?? this.$slots.defalut;
|
|
425
|
+
}
|
|
426
|
+
}) : ((n = (l = this.$slots).default) == null ? void 0 : n.call(l, {
|
|
407
427
|
invalid: this.invalid,
|
|
408
428
|
formData: this.formData,
|
|
409
429
|
errors: this.errors,
|
|
410
430
|
fieldsErrors: this.fieldsErrors
|
|
411
431
|
})) ?? this.$slots.defalut;
|
|
412
432
|
}
|
|
413
|
-
}),
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
433
|
+
}), ce = (e, o) => {
|
|
434
|
+
const i = N({
|
|
435
|
+
props: {
|
|
436
|
+
schema: {
|
|
437
|
+
type: [Array, Function],
|
|
438
|
+
required: !0
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
setup(l, { slots: n }) {
|
|
442
|
+
const r = O(e), a = typeof l.schema == "function" ? l.schema(r) : l.schema;
|
|
443
|
+
let s;
|
|
444
|
+
return () => {
|
|
445
|
+
var u;
|
|
446
|
+
return a == null ? void 0 : a.reduce(
|
|
447
|
+
(t, m) => {
|
|
448
|
+
const p = typeof m == "function" ? m(r) : m, {
|
|
449
|
+
vvIs: h,
|
|
450
|
+
vvName: v,
|
|
451
|
+
vvSlots: d,
|
|
452
|
+
vvChildren: S,
|
|
453
|
+
vvIf: k,
|
|
454
|
+
vvElseIf: x,
|
|
455
|
+
vvType: I,
|
|
456
|
+
vvDefaultValue: W,
|
|
457
|
+
vvShowValid: B,
|
|
458
|
+
...c
|
|
459
|
+
} = p;
|
|
460
|
+
if (k !== void 0) {
|
|
461
|
+
if (s = typeof k == "function" ? $(k(r)) : $(k), !s)
|
|
462
|
+
return t;
|
|
463
|
+
} else if (x !== void 0 && s !== void 0) {
|
|
464
|
+
if (s || (s = typeof x == "function" ? $(x(r)) : $(x), !s))
|
|
465
|
+
return t;
|
|
466
|
+
} else
|
|
467
|
+
s = void 0;
|
|
468
|
+
const A = S ? y(i, {
|
|
469
|
+
schema: S
|
|
470
|
+
}) : void 0;
|
|
471
|
+
return v ? (t.push(
|
|
472
|
+
y(
|
|
473
|
+
o,
|
|
474
|
+
{
|
|
475
|
+
name: v,
|
|
476
|
+
is: h,
|
|
477
|
+
type: I,
|
|
478
|
+
defaultValue: W,
|
|
479
|
+
showValid: B,
|
|
480
|
+
props: c
|
|
481
|
+
},
|
|
482
|
+
d ?? A
|
|
483
|
+
)
|
|
484
|
+
), t) : h ? (t.push(
|
|
485
|
+
y(
|
|
486
|
+
h,
|
|
487
|
+
c,
|
|
488
|
+
d ?? A
|
|
489
|
+
)
|
|
490
|
+
), t) : (S && t.push(A), t);
|
|
491
|
+
},
|
|
492
|
+
[
|
|
493
|
+
(u = n == null ? void 0 : n.default) == null ? void 0 : u.call(n, {
|
|
494
|
+
formData: r == null ? void 0 : r.formData.value,
|
|
495
|
+
submit: r == null ? void 0 : r.submit,
|
|
496
|
+
errors: r == null ? void 0 : r.errors.value,
|
|
497
|
+
status: r == null ? void 0 : r.status.value,
|
|
498
|
+
invalid: r == null ? void 0 : r.invalid.value
|
|
499
|
+
})
|
|
500
|
+
]
|
|
501
|
+
);
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
return i;
|
|
506
|
+
}, Q = (e, o = {}) => {
|
|
507
|
+
const i = Symbol(), l = Symbol(), n = Symbol(), { VvForm: r, errors: a, status: s, formData: u } = le(
|
|
508
|
+
e,
|
|
509
|
+
i,
|
|
426
510
|
o
|
|
427
|
-
)
|
|
511
|
+
), t = fe(
|
|
512
|
+
i,
|
|
513
|
+
l
|
|
514
|
+
), m = ie(
|
|
515
|
+
i,
|
|
516
|
+
l,
|
|
517
|
+
n,
|
|
518
|
+
o
|
|
519
|
+
), p = ce(i, m);
|
|
428
520
|
return {
|
|
429
|
-
VvForm:
|
|
430
|
-
VvFormWrapper:
|
|
431
|
-
VvFormField:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
521
|
+
VvForm: r,
|
|
522
|
+
VvFormWrapper: t,
|
|
523
|
+
VvFormField: m,
|
|
524
|
+
VvFormTemplate: p,
|
|
525
|
+
formInjectionKey: i,
|
|
526
|
+
formWrapperInjectionKey: l,
|
|
527
|
+
formFieldInjectionKey: n,
|
|
528
|
+
errors: a,
|
|
529
|
+
status: s,
|
|
530
|
+
formData: u
|
|
438
531
|
};
|
|
439
|
-
},
|
|
532
|
+
}, X = Symbol(), he = (e) => {
|
|
440
533
|
let o = {};
|
|
441
|
-
return e.schema && (o =
|
|
534
|
+
return e.schema && (o = Q(e.schema, e)), {
|
|
442
535
|
...o,
|
|
443
|
-
install(
|
|
444
|
-
|
|
536
|
+
install(i, { global: l = !1 } = {}) {
|
|
537
|
+
i.provide(X, e), l && (i.config.globalProperties.$vvForm = e, o != null && o.VvForm && i.component("VvForm", o.VvForm), o != null && o.VvFormWrapper && i.component("VvFormWrapper", o.VvFormWrapper), o != null && o.VvFormField && i.component("VvFormField", o.VvFormField), o != null && o.VvFormTemplate && i.component("VvFormTemplate", o.VvFormTemplate));
|
|
445
538
|
}
|
|
446
539
|
};
|
|
447
|
-
},
|
|
448
|
-
const
|
|
449
|
-
return
|
|
540
|
+
}, pe = (e, o = {}) => {
|
|
541
|
+
const i = { ...O(X, {}), ...o };
|
|
542
|
+
return Q(e, i);
|
|
450
543
|
};
|
|
451
544
|
export {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
545
|
+
f as FormFieldType,
|
|
546
|
+
he as createForm,
|
|
547
|
+
H as defaultObjectBySchema,
|
|
548
|
+
Q as formFactory,
|
|
549
|
+
X as pluginInjectionKey,
|
|
550
|
+
pe as useForm
|
|
458
551
|
};
|