vlite3 0.4.3 → 0.4.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.
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { ref as v, computed as K, watch as L } from "vue";
|
|
2
|
-
import { initializeFormValues as B, deepClone as m, cleanSubmitValues as Q, getNestedValue as M, evaluateConditional as
|
|
2
|
+
import { initializeFormValues as B, deepClone as m, cleanSubmitValues as Q, getNestedValue as M, evaluateConditional as w, setNestedValue as x, collectFileFields as W, filterNullCustomFields as X } from "../utils/form.utils.js";
|
|
3
3
|
import { useFileUpload as Y } from "./useFileUpload.js";
|
|
4
|
-
function te(
|
|
5
|
-
const { schema: o, values: U, isUpdate: F = !1, folderId: g, onSubmit: j } =
|
|
4
|
+
function te(b) {
|
|
5
|
+
const { schema: o, values: U, isUpdate: F = !1, folderId: g, onSubmit: j } = b, { handleUploadFile: E } = Y(), t = v(B(o, U)), u = v({}), h = v(!1), d = v(!1), V = v(m(t.value)), y = K(() => o ? Array.isArray(o[0]) ? o.flat() : o : []);
|
|
6
6
|
L(
|
|
7
7
|
() => U,
|
|
8
8
|
(e) => {
|
|
9
|
-
e && (t.value = B(o, e),
|
|
9
|
+
e && (t.value = B(o, e), V.value = m(t.value), d.value = !1);
|
|
10
10
|
},
|
|
11
11
|
{ deep: !0 }
|
|
12
12
|
);
|
|
13
|
-
const
|
|
13
|
+
const S = () => ({
|
|
14
14
|
values: t.value,
|
|
15
15
|
isUpdate: F
|
|
16
16
|
}), C = (e) => M(t.value, e), T = (e) => u.value[e] || "", N = (e, l) => {
|
|
17
17
|
l ? u.value[e] = l : delete u.value[e];
|
|
18
|
-
},
|
|
18
|
+
}, A = () => {
|
|
19
19
|
u.value = {};
|
|
20
|
-
}, O = (e) => e.when ?
|
|
20
|
+
}, O = (e) => e.when ? w(e.when, S()) : !0, D = (e) => w(e.disabled, S()), I = (e) => w(e.readonly, S()), P = (e) => {
|
|
21
21
|
const l = C(e.name);
|
|
22
22
|
let a = "";
|
|
23
23
|
if (e.required && (l == null || l === "" || Array.isArray(l) && l.length === 0) && (a = `${e.label || e.name} is required`), !a && e.maxFileSize) {
|
|
@@ -43,7 +43,7 @@ function te(x) {
|
|
|
43
43
|
isUpdate: F
|
|
44
44
|
})), a ? u.value[e.name] = a : delete u.value[e.name], a;
|
|
45
45
|
}, $ = () => {
|
|
46
|
-
|
|
46
|
+
A();
|
|
47
47
|
let e = !0;
|
|
48
48
|
for (const l of y.value) {
|
|
49
49
|
if (!O(l) || D(l)) continue;
|
|
@@ -51,7 +51,7 @@ function te(x) {
|
|
|
51
51
|
}
|
|
52
52
|
return e;
|
|
53
53
|
}, R = (e, l, a) => {
|
|
54
|
-
t.value =
|
|
54
|
+
t.value = x(t.value, e, l), d.value = !0, delete u.value[e];
|
|
55
55
|
const i = y.value.find((n) => n.name === e);
|
|
56
56
|
if (i?.updateValues) {
|
|
57
57
|
const n = i.updateValues({
|
|
@@ -76,8 +76,8 @@ function te(x) {
|
|
|
76
76
|
if (Array.isArray(r)) {
|
|
77
77
|
const q = r.map(async (f) => {
|
|
78
78
|
if (f instanceof File || f && typeof f == "object" && f.file instanceof File) {
|
|
79
|
-
const
|
|
80
|
-
return
|
|
79
|
+
const z = await E(f, g);
|
|
80
|
+
return z ? k ? a(f, z) : z : null;
|
|
81
81
|
}
|
|
82
82
|
return f;
|
|
83
83
|
}), p = await Promise.all(q);
|
|
@@ -92,7 +92,7 @@ function te(x) {
|
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
return (await Promise.all(i)).forEach((s) => {
|
|
95
|
-
s && Object.assign(e,
|
|
95
|
+
s && Object.assign(e, x(e, s.name, s.value));
|
|
96
96
|
}), e;
|
|
97
97
|
}, H = (e) => {
|
|
98
98
|
const l = { ...e };
|
|
@@ -101,7 +101,7 @@ function te(x) {
|
|
|
101
101
|
const i = M(l, a.name);
|
|
102
102
|
if (Array.isArray(i)) {
|
|
103
103
|
const n = X(i, a.props.schema);
|
|
104
|
-
Object.assign(l,
|
|
104
|
+
Object.assign(l, x(l, a.name, n));
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
return l;
|
|
@@ -109,7 +109,7 @@ function te(x) {
|
|
|
109
109
|
return {
|
|
110
110
|
formValues: t,
|
|
111
111
|
errors: u,
|
|
112
|
-
isSubmitting:
|
|
112
|
+
isSubmitting: h,
|
|
113
113
|
isDirty: d,
|
|
114
114
|
handleFieldChange: R,
|
|
115
115
|
validateField: P,
|
|
@@ -120,23 +120,28 @@ function te(x) {
|
|
|
120
120
|
getFieldValue: C,
|
|
121
121
|
getFieldError: T,
|
|
122
122
|
setFieldError: N,
|
|
123
|
-
clearErrors:
|
|
123
|
+
clearErrors: A,
|
|
124
124
|
resetForm: () => {
|
|
125
|
-
t.value = m(
|
|
125
|
+
t.value = m(V.value), A(), d.value = !1;
|
|
126
126
|
},
|
|
127
127
|
handleSubmit: async () => {
|
|
128
128
|
if ($()) {
|
|
129
|
-
|
|
129
|
+
h.value = !0;
|
|
130
130
|
try {
|
|
131
131
|
let l = await G();
|
|
132
|
-
l = H(l), l = Q(
|
|
132
|
+
l = H(l), l = Q(
|
|
133
|
+
l,
|
|
134
|
+
o,
|
|
135
|
+
b.emitFields,
|
|
136
|
+
b.emitFields
|
|
137
|
+
), j && await j({
|
|
133
138
|
values: l,
|
|
134
139
|
isUpdate: F
|
|
135
|
-
}), d.value = !1,
|
|
140
|
+
}), d.value = !1, V.value = m(l);
|
|
136
141
|
} catch (l) {
|
|
137
142
|
throw console.error("[useForm] Submit error:", l), l;
|
|
138
143
|
} finally {
|
|
139
|
-
|
|
144
|
+
h.value = !1;
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
},
|
|
@@ -1,93 +1,93 @@
|
|
|
1
1
|
function k(e) {
|
|
2
2
|
return !!e && typeof e == "object";
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
if (!
|
|
6
|
-
const
|
|
7
|
-
let
|
|
8
|
-
for (const
|
|
9
|
-
if (
|
|
10
|
-
|
|
4
|
+
function d(e, r) {
|
|
5
|
+
if (!r || !e) return;
|
|
6
|
+
const f = r.split(".");
|
|
7
|
+
let y = e;
|
|
8
|
+
for (const n of f) {
|
|
9
|
+
if (y == null) return;
|
|
10
|
+
y = y[n];
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return y;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
let
|
|
18
|
-
for (let i = 0; i <
|
|
19
|
-
const c =
|
|
20
|
-
Array.isArray(
|
|
14
|
+
function v(e, r, f) {
|
|
15
|
+
if (!r) return e;
|
|
16
|
+
const y = r.split("."), n = { ...e };
|
|
17
|
+
let o = n;
|
|
18
|
+
for (let i = 0; i < y.length - 1; i++) {
|
|
19
|
+
const c = y[i];
|
|
20
|
+
Array.isArray(o[c]) ? o[c] = [...o[c]] : o[c] = o[c] ? { ...o[c] } : {}, o = o[c];
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return o[y[y.length - 1]] = f, n;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return !k(
|
|
24
|
+
function h(e, r) {
|
|
25
|
+
return !k(r) || !r.name ? e : d(e, r.name) === void 0 && r.value !== void 0 ? v(e, r.name, r.value) : e;
|
|
26
26
|
}
|
|
27
|
-
function E(e,
|
|
28
|
-
let
|
|
29
|
-
const
|
|
30
|
-
for (const
|
|
31
|
-
if (!
|
|
32
|
-
const
|
|
33
|
-
let i =
|
|
27
|
+
function E(e, r) {
|
|
28
|
+
let f = r ? m(r) : {};
|
|
29
|
+
const y = Array.isArray(e[0]) ? e.flat() : e;
|
|
30
|
+
for (const n of y) {
|
|
31
|
+
if (!n.name) continue;
|
|
32
|
+
const o = n.mapFrom || n.name;
|
|
33
|
+
let i = r ? d(r, o) : void 0;
|
|
34
34
|
if (i != null) {
|
|
35
|
-
const c =
|
|
35
|
+
const c = n.valueKey || n.key;
|
|
36
36
|
c && (Array.isArray(i) ? i = i.map(
|
|
37
|
-
(u) => u && typeof u == "object" ?
|
|
38
|
-
) : typeof i == "object" && (i =
|
|
37
|
+
(u) => u && typeof u == "object" ? d(u, c) : u
|
|
38
|
+
) : typeof i == "object" && (i = d(i, c))), n.format && (i = n.format(i, r || {}));
|
|
39
39
|
}
|
|
40
40
|
if (i === void 0) {
|
|
41
|
-
if (
|
|
42
|
-
const c =
|
|
41
|
+
if (n.mapFrom && r) {
|
|
42
|
+
const c = d(r, n.name);
|
|
43
43
|
c !== void 0 && (i = c);
|
|
44
44
|
}
|
|
45
45
|
if (i === void 0) {
|
|
46
|
-
const c = typeof
|
|
47
|
-
c !== void 0 && Object.assign(
|
|
46
|
+
const c = typeof n.value == "function" ? n.value() : n.value;
|
|
47
|
+
c !== void 0 && Object.assign(f, v(f, n.name, c));
|
|
48
48
|
} else
|
|
49
|
-
Object.assign(
|
|
49
|
+
Object.assign(f, v(f, n.name, i));
|
|
50
50
|
} else
|
|
51
|
-
Object.assign(
|
|
52
|
-
|
|
51
|
+
Object.assign(f, v(f, n.name, i));
|
|
52
|
+
f = h(f, n.addonLeft), f = h(f, n.addonRight);
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return f;
|
|
55
55
|
}
|
|
56
|
-
function O(e,
|
|
57
|
-
return e === void 0 ? !1 : typeof e == "boolean" ? e : typeof e == "function" ? e(
|
|
56
|
+
function O(e, r) {
|
|
57
|
+
return e === void 0 ? !1 : typeof e == "boolean" ? e : typeof e == "function" ? e(r) : !1;
|
|
58
58
|
}
|
|
59
|
-
function S(e,
|
|
60
|
-
return Array.isArray(e) ? e.filter((
|
|
61
|
-
const
|
|
62
|
-
return
|
|
59
|
+
function S(e, r) {
|
|
60
|
+
return Array.isArray(e) ? e.filter((f) => f ? !r.every((n) => {
|
|
61
|
+
const o = f[n.name];
|
|
62
|
+
return o == null || o === "";
|
|
63
63
|
}) : !1) : [];
|
|
64
64
|
}
|
|
65
|
-
function F(e,
|
|
66
|
-
const
|
|
67
|
-
for (const
|
|
68
|
-
if (!
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
const i =
|
|
72
|
-
i &&
|
|
73
|
-
name:
|
|
65
|
+
function F(e, r) {
|
|
66
|
+
const f = [], y = Array.isArray(e[0]) ? e.flat() : e;
|
|
67
|
+
for (const n of y) {
|
|
68
|
+
if (!n.name) continue;
|
|
69
|
+
const o = n.type;
|
|
70
|
+
if (o === "file" || o === "avatarUpload" || o === "fileUploader") {
|
|
71
|
+
const i = d(r, n.name);
|
|
72
|
+
i && f.push({
|
|
73
|
+
name: n.name,
|
|
74
74
|
value: i,
|
|
75
|
-
type:
|
|
76
|
-
field:
|
|
75
|
+
type: o,
|
|
76
|
+
field: n
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
if (
|
|
80
|
-
const i =
|
|
79
|
+
if (o === "customFields" && n.props?.schema) {
|
|
80
|
+
const i = d(r, n.name);
|
|
81
81
|
if (Array.isArray(i)) {
|
|
82
|
-
const u =
|
|
82
|
+
const u = n.props.schema.filter(
|
|
83
83
|
(s) => s.type === "file" || s.type === "avatarUpload" || s.type === "fileUploader"
|
|
84
84
|
);
|
|
85
|
-
u.length > 0 && i.forEach((s,
|
|
85
|
+
u.length > 0 && i.forEach((s, t) => {
|
|
86
86
|
u.forEach((a) => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
name: `${
|
|
90
|
-
value:
|
|
87
|
+
const l = s?.[a.name];
|
|
88
|
+
l && f.push({
|
|
89
|
+
name: `${n.name}.${t}.${a.name}`,
|
|
90
|
+
value: l,
|
|
91
91
|
type: a.type,
|
|
92
92
|
field: a
|
|
93
93
|
});
|
|
@@ -96,79 +96,85 @@ function F(e, n) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
return
|
|
99
|
+
return f;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function m(e) {
|
|
102
102
|
if (e === null || typeof e != "object") return e;
|
|
103
103
|
if (e instanceof Date) return new Date(e.getTime());
|
|
104
104
|
if (e instanceof File) return e;
|
|
105
|
-
if (Array.isArray(e)) return e.map((
|
|
106
|
-
const
|
|
107
|
-
for (const
|
|
108
|
-
Object.prototype.hasOwnProperty.call(e,
|
|
109
|
-
return
|
|
105
|
+
if (Array.isArray(e)) return e.map((f) => m(f));
|
|
106
|
+
const r = {};
|
|
107
|
+
for (const f in e)
|
|
108
|
+
Object.prototype.hasOwnProperty.call(e, f) && (r[f] = m(e[f]));
|
|
109
|
+
return r;
|
|
110
110
|
}
|
|
111
111
|
function x(e) {
|
|
112
112
|
return e ? typeof e == "object" && (typeof e.render == "function" || typeof e.setup == "function" || e.__name !== void 0 || e.name !== void 0) : !1;
|
|
113
113
|
}
|
|
114
|
-
function g(e,
|
|
115
|
-
const
|
|
114
|
+
function g(e, r, f, y) {
|
|
115
|
+
const n = f === void 0 && y === void 0, o = n ? m(e) : {}, i = Array.isArray(r[0]) ? r.flat() : r, c = f || [], u = y || [];
|
|
116
116
|
for (const s of i) {
|
|
117
117
|
if (!s.name) continue;
|
|
118
|
-
let
|
|
119
|
-
if (
|
|
120
|
-
if (s.type === "customFields" && s.props?.schema && Array.isArray(
|
|
118
|
+
let t = d(e, s.name);
|
|
119
|
+
if (t === void 0) continue;
|
|
120
|
+
if (t = m(t), s.type === "customFields" && s.props?.schema && Array.isArray(t)) {
|
|
121
121
|
const A = s.props.schema;
|
|
122
|
-
|
|
122
|
+
t = t.map((p) => g(p, A, f, y));
|
|
123
123
|
}
|
|
124
124
|
let a = !1;
|
|
125
|
-
s.transform && (
|
|
126
|
-
const
|
|
127
|
-
|
|
125
|
+
s.transform && (t = s.transform(t, e), a = !0);
|
|
126
|
+
const l = s.mapTo || s.name;
|
|
127
|
+
l !== s.name && (a = !0, n && !s.name.includes(".") && delete o[s.name]), !n || a ? Object.assign(o, v(o, l, t)) : Object.assign(o, v(o, s.name, t));
|
|
128
128
|
}
|
|
129
129
|
if (c.length > 0) {
|
|
130
|
-
const s = (
|
|
131
|
-
if (!(!
|
|
132
|
-
if (Array.isArray(
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
const s = (t, a) => {
|
|
131
|
+
if (!(!t || typeof t != "object") && !(!a || typeof a != "object"))
|
|
132
|
+
if (Array.isArray(t) && Array.isArray(a)) {
|
|
133
|
+
for (const l of c) {
|
|
134
|
+
const A = t.find((p) => p && typeof p == "object" && p[l] !== void 0)?.[l];
|
|
135
|
+
A !== void 0 && a.forEach((p) => {
|
|
136
|
+
p && typeof p == "object" && p[l] === void 0 && (p[l] = m(A));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
t.forEach((l, A) => {
|
|
140
|
+
a[A] && s(l, a[A]);
|
|
135
141
|
});
|
|
136
|
-
else {
|
|
137
|
-
for (const
|
|
138
|
-
|
|
139
|
-
for (const
|
|
140
|
-
typeof a[
|
|
142
|
+
} else {
|
|
143
|
+
for (const l of c)
|
|
144
|
+
t[l] !== void 0 && a[l] === void 0 && (a[l] = m(t[l]));
|
|
145
|
+
for (const l in a)
|
|
146
|
+
typeof a[l] == "object" && typeof t[l] == "object" && s(t[l], a[l]);
|
|
141
147
|
}
|
|
142
148
|
};
|
|
143
|
-
for (const
|
|
144
|
-
e[
|
|
145
|
-
s(e,
|
|
149
|
+
for (const t of c)
|
|
150
|
+
e[t] !== void 0 && o[t] === void 0 && (o[t] = m(e[t]));
|
|
151
|
+
s(e, o);
|
|
146
152
|
}
|
|
147
153
|
if (u.length > 0) {
|
|
148
|
-
const s = (
|
|
149
|
-
if (!(!
|
|
150
|
-
if (Array.isArray(
|
|
151
|
-
|
|
154
|
+
const s = (t) => {
|
|
155
|
+
if (!(!t || typeof t != "object"))
|
|
156
|
+
if (Array.isArray(t))
|
|
157
|
+
t.forEach(s);
|
|
152
158
|
else {
|
|
153
159
|
for (const a of u)
|
|
154
|
-
delete
|
|
155
|
-
for (const a in
|
|
156
|
-
s(
|
|
160
|
+
delete t[a];
|
|
161
|
+
for (const a in t)
|
|
162
|
+
s(t[a]);
|
|
157
163
|
}
|
|
158
164
|
};
|
|
159
|
-
s(
|
|
165
|
+
s(o);
|
|
160
166
|
}
|
|
161
|
-
return
|
|
167
|
+
return o;
|
|
162
168
|
}
|
|
163
169
|
export {
|
|
164
170
|
g as cleanSubmitValues,
|
|
165
171
|
F as collectFileFields,
|
|
166
|
-
|
|
172
|
+
m as deepClone,
|
|
167
173
|
O as evaluateConditional,
|
|
168
174
|
S as filterNullCustomFields,
|
|
169
|
-
|
|
175
|
+
d as getNestedValue,
|
|
170
176
|
E as initializeFormValues,
|
|
171
177
|
k as isAddonObject,
|
|
172
178
|
x as isComponent,
|
|
173
|
-
|
|
179
|
+
v as setNestedValue
|
|
174
180
|
};
|