vlite3 0.4.3 → 0.4.4
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,83 +1,85 @@
|
|
|
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
|
-
let
|
|
23
|
-
if (e.required && (l == null || l === "" || Array.isArray(l) && l.length === 0) && (
|
|
22
|
+
let s = "";
|
|
23
|
+
if (e.required && (l == null || l === "" || Array.isArray(l) && l.length === 0) && (s = `${e.label || e.name} is required`), !s && e.maxFileSize) {
|
|
24
24
|
const i = e.maxFileSize * 1024 * 1024;
|
|
25
25
|
if (l != null && l !== "") {
|
|
26
26
|
const n = Array.isArray(l) ? l : [l];
|
|
27
|
-
for (const
|
|
28
|
-
const c =
|
|
27
|
+
for (const a of n) {
|
|
28
|
+
const c = a instanceof File ? a.size : a?.fileSize || a?.file?.size || a?.size;
|
|
29
29
|
if (c !== void 0 && c > i) {
|
|
30
|
-
|
|
30
|
+
s = `${e.label || e.name} size must be less than ${e.maxFileSize}MB`;
|
|
31
31
|
break;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
if (!
|
|
36
|
+
if (!s && (e.type === "file" || e.type === "fileUploader") && (e.props?.multiple || e.maxFiles)) {
|
|
37
37
|
const i = e.maxFiles || e.props?.maxFiles;
|
|
38
|
-
i && Array.isArray(l) && l.length > i && (
|
|
38
|
+
i && Array.isArray(l) && l.length > i && (s = `Maximum ${i} files allowed`);
|
|
39
39
|
}
|
|
40
|
-
return !
|
|
40
|
+
return !s && e.validation && (s = e.validation({
|
|
41
41
|
value: l,
|
|
42
42
|
values: t.value,
|
|
43
43
|
isUpdate: F
|
|
44
|
-
})),
|
|
44
|
+
})), s ? u.value[e.name] = s : delete u.value[e.name], s;
|
|
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;
|
|
50
50
|
P(l) && (e = !1);
|
|
51
51
|
}
|
|
52
52
|
return e;
|
|
53
|
-
}, R = (e, l,
|
|
54
|
-
t.value =
|
|
53
|
+
}, R = (e, l, s) => {
|
|
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({
|
|
58
58
|
values: t.value,
|
|
59
|
-
data:
|
|
59
|
+
data: s,
|
|
60
60
|
isUpdate: F,
|
|
61
61
|
updateError: N
|
|
62
62
|
});
|
|
63
63
|
n && typeof n == "object" && (t.value = { ...t.value, ...n });
|
|
64
64
|
}
|
|
65
65
|
}, G = async () => {
|
|
66
|
-
const e = m(t.value), l = W(o, e),
|
|
66
|
+
const e = m(t.value), l = W(o, e), s = (a, c) => {
|
|
67
67
|
let r = null;
|
|
68
|
-
return
|
|
69
|
-
|
|
68
|
+
return a instanceof File ? r = a : a && typeof a == "object" && a.file instanceof File && (r = a.file), {
|
|
69
|
+
// Spread original item to keep any metadata like __typename
|
|
70
|
+
...typeof a == "object" && a !== null && !(a instanceof File) ? a : {},
|
|
71
|
+
fileName: a?.fileName || r?.name || c.split("/").pop() || "unknown",
|
|
70
72
|
fileUrl: c,
|
|
71
|
-
fileType:
|
|
72
|
-
fileSize:
|
|
73
|
+
fileType: a?.fileType || r?.type || "application/octet-stream",
|
|
74
|
+
fileSize: a?.fileSize || r?.size || 0
|
|
73
75
|
};
|
|
74
|
-
}, i = l.map(async (
|
|
75
|
-
const { name: c, value: r, field: J } =
|
|
76
|
+
}, i = l.map(async (a) => {
|
|
77
|
+
const { name: c, value: r, field: J } = a, k = J.returnFileObject === !0;
|
|
76
78
|
if (Array.isArray(r)) {
|
|
77
79
|
const q = r.map(async (f) => {
|
|
78
80
|
if (f instanceof File || f && typeof f == "object" && f.file instanceof File) {
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
+
const z = await E(f, g);
|
|
82
|
+
return z ? k ? s(f, z) : z : null;
|
|
81
83
|
}
|
|
82
84
|
return f;
|
|
83
85
|
}), p = await Promise.all(q);
|
|
@@ -86,22 +88,22 @@ function te(x) {
|
|
|
86
88
|
if (r instanceof File || r && typeof r == "object" && r.file instanceof File) {
|
|
87
89
|
const p = await E(r, g);
|
|
88
90
|
if (p)
|
|
89
|
-
return { name: c, value: k ?
|
|
91
|
+
return { name: c, value: k ? s(r, p) : p };
|
|
90
92
|
}
|
|
91
93
|
return null;
|
|
92
94
|
}
|
|
93
95
|
});
|
|
94
|
-
return (await Promise.all(i)).forEach((
|
|
95
|
-
|
|
96
|
+
return (await Promise.all(i)).forEach((a) => {
|
|
97
|
+
a && Object.assign(e, x(e, a.name, a.value));
|
|
96
98
|
}), e;
|
|
97
99
|
}, H = (e) => {
|
|
98
100
|
const l = { ...e };
|
|
99
|
-
for (const
|
|
100
|
-
if (
|
|
101
|
-
const i = M(l,
|
|
101
|
+
for (const s of y.value)
|
|
102
|
+
if (s.type === "customFields" && s.props?.schema) {
|
|
103
|
+
const i = M(l, s.name);
|
|
102
104
|
if (Array.isArray(i)) {
|
|
103
|
-
const n = X(i,
|
|
104
|
-
Object.assign(l,
|
|
105
|
+
const n = X(i, s.props.schema);
|
|
106
|
+
Object.assign(l, x(l, s.name, n));
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
return l;
|
|
@@ -109,7 +111,7 @@ function te(x) {
|
|
|
109
111
|
return {
|
|
110
112
|
formValues: t,
|
|
111
113
|
errors: u,
|
|
112
|
-
isSubmitting:
|
|
114
|
+
isSubmitting: h,
|
|
113
115
|
isDirty: d,
|
|
114
116
|
handleFieldChange: R,
|
|
115
117
|
validateField: P,
|
|
@@ -120,23 +122,28 @@ function te(x) {
|
|
|
120
122
|
getFieldValue: C,
|
|
121
123
|
getFieldError: T,
|
|
122
124
|
setFieldError: N,
|
|
123
|
-
clearErrors:
|
|
125
|
+
clearErrors: A,
|
|
124
126
|
resetForm: () => {
|
|
125
|
-
t.value = m(
|
|
127
|
+
t.value = m(V.value), A(), d.value = !1;
|
|
126
128
|
},
|
|
127
129
|
handleSubmit: async () => {
|
|
128
130
|
if ($()) {
|
|
129
|
-
|
|
131
|
+
h.value = !0;
|
|
130
132
|
try {
|
|
131
133
|
let l = await G();
|
|
132
|
-
l = H(l), l = Q(
|
|
134
|
+
l = H(l), l = Q(
|
|
135
|
+
l,
|
|
136
|
+
o,
|
|
137
|
+
b.emitFields,
|
|
138
|
+
b.emitFields
|
|
139
|
+
), j && await j({
|
|
133
140
|
values: l,
|
|
134
141
|
isUpdate: F
|
|
135
|
-
}), d.value = !1,
|
|
142
|
+
}), d.value = !1, V.value = m(l);
|
|
136
143
|
} catch (l) {
|
|
137
144
|
throw console.error("[useForm] Submit error:", l), l;
|
|
138
145
|
} finally {
|
|
139
|
-
|
|
146
|
+
h.value = !1;
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
},
|
|
@@ -14,12 +14,12 @@ function p(e, n) {
|
|
|
14
14
|
function m(e, n, r) {
|
|
15
15
|
if (!n) return e;
|
|
16
16
|
const l = n.split("."), t = { ...e };
|
|
17
|
-
let
|
|
17
|
+
let o = t;
|
|
18
18
|
for (let i = 0; i < l.length - 1; i++) {
|
|
19
19
|
const c = l[i];
|
|
20
|
-
Array.isArray(
|
|
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[l[l.length - 1]] = r, t;
|
|
23
23
|
}
|
|
24
24
|
function v(e, n) {
|
|
25
25
|
return !k(n) || !n.name ? e : p(e, n.name) === void 0 && n.value !== void 0 ? m(e, n.name, n.value) : e;
|
|
@@ -29,12 +29,12 @@ function E(e, n) {
|
|
|
29
29
|
const l = Array.isArray(e[0]) ? e.flat() : e;
|
|
30
30
|
for (const t of l) {
|
|
31
31
|
if (!t.name) continue;
|
|
32
|
-
const
|
|
33
|
-
let i = n ? p(n,
|
|
32
|
+
const o = t.mapFrom || t.name;
|
|
33
|
+
let i = n ? p(n, o) : void 0;
|
|
34
34
|
if (i != null) {
|
|
35
35
|
const c = t.valueKey || t.key;
|
|
36
36
|
c && (Array.isArray(i) ? i = i.map(
|
|
37
|
-
(
|
|
37
|
+
(y) => y && typeof y == "object" ? p(y, c) : y
|
|
38
38
|
) : typeof i == "object" && (i = p(i, c))), t.format && (i = t.format(i, n || {}));
|
|
39
39
|
}
|
|
40
40
|
if (i === void 0) {
|
|
@@ -58,36 +58,36 @@ function O(e, n) {
|
|
|
58
58
|
}
|
|
59
59
|
function S(e, n) {
|
|
60
60
|
return Array.isArray(e) ? e.filter((r) => r ? !n.every((t) => {
|
|
61
|
-
const
|
|
62
|
-
return
|
|
61
|
+
const o = r[t.name];
|
|
62
|
+
return o == null || o === "";
|
|
63
63
|
}) : !1) : [];
|
|
64
64
|
}
|
|
65
65
|
function F(e, n) {
|
|
66
66
|
const r = [], l = Array.isArray(e[0]) ? e.flat() : e;
|
|
67
67
|
for (const t of l) {
|
|
68
68
|
if (!t.name) continue;
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
69
|
+
const o = t.type;
|
|
70
|
+
if (o === "file" || o === "avatarUpload" || o === "fileUploader") {
|
|
71
71
|
const i = p(n, t.name);
|
|
72
72
|
i && r.push({
|
|
73
73
|
name: t.name,
|
|
74
74
|
value: i,
|
|
75
|
-
type:
|
|
75
|
+
type: o,
|
|
76
76
|
field: t
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
if (
|
|
79
|
+
if (o === "customFields" && t.props?.schema) {
|
|
80
80
|
const i = p(n, t.name);
|
|
81
81
|
if (Array.isArray(i)) {
|
|
82
|
-
const
|
|
82
|
+
const y = t.props.schema.filter(
|
|
83
83
|
(s) => s.type === "file" || s.type === "avatarUpload" || s.type === "fileUploader"
|
|
84
84
|
);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
name: `${t.name}.${
|
|
90
|
-
value:
|
|
85
|
+
y.length > 0 && i.forEach((s, f) => {
|
|
86
|
+
y.forEach((a) => {
|
|
87
|
+
const u = s?.[a.name];
|
|
88
|
+
u && r.push({
|
|
89
|
+
name: `${t.name}.${f}.${a.name}`,
|
|
90
|
+
value: u,
|
|
91
91
|
type: a.type,
|
|
92
92
|
field: a
|
|
93
93
|
});
|
|
@@ -112,53 +112,53 @@ 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
114
|
function g(e, n, r, l) {
|
|
115
|
-
const t = r === void 0 && l === void 0,
|
|
115
|
+
const t = r === void 0 && l === void 0, o = t ? d(e) : {}, i = Array.isArray(n[0]) ? n.flat() : n, c = r || [], y = l || [];
|
|
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 f = p(e, s.name);
|
|
119
|
+
if (f === void 0) continue;
|
|
120
|
+
if (s.type === "customFields" && s.props?.schema && Array.isArray(f)) {
|
|
121
121
|
const A = s.props.schema;
|
|
122
|
-
|
|
122
|
+
f = f.map((h) => g(h, A, r, l));
|
|
123
123
|
}
|
|
124
124
|
let a = !1;
|
|
125
|
-
s.transform && (
|
|
126
|
-
const
|
|
127
|
-
|
|
125
|
+
s.transform && (f = s.transform(f, e), a = !0);
|
|
126
|
+
const u = s.mapTo || s.name;
|
|
127
|
+
u !== s.name && (a = !0, t && !s.name.includes(".") && delete o[s.name]), !t || a ? Object.assign(o, m(o, u, f)) : Object.assign(o, m(o, s.name, f));
|
|
128
128
|
}
|
|
129
129
|
if (c.length > 0) {
|
|
130
|
-
const s = (
|
|
131
|
-
if (!(!
|
|
132
|
-
if (Array.isArray(
|
|
133
|
-
|
|
134
|
-
a[A] && s(
|
|
130
|
+
const s = (f, a) => {
|
|
131
|
+
if (!(!f || typeof f != "object") && !(!a || typeof a != "object"))
|
|
132
|
+
if (Array.isArray(f) && Array.isArray(a))
|
|
133
|
+
f.forEach((u, A) => {
|
|
134
|
+
a[A] && s(u, a[A]);
|
|
135
135
|
});
|
|
136
136
|
else {
|
|
137
|
-
for (const
|
|
138
|
-
|
|
139
|
-
for (const
|
|
140
|
-
typeof a[
|
|
137
|
+
for (const u of c)
|
|
138
|
+
f[u] !== void 0 && a[u] === void 0 && (a[u] = d(f[u]));
|
|
139
|
+
for (const u in a)
|
|
140
|
+
typeof a[u] == "object" && a[u] !== null && typeof f[u] == "object" && f[u] !== null && s(f[u], a[u]);
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
for (const
|
|
144
|
-
e[
|
|
145
|
-
s(e,
|
|
143
|
+
for (const f of c)
|
|
144
|
+
e[f] !== void 0 && o[f] === void 0 && (o[f] = d(e[f]));
|
|
145
|
+
s(e, o);
|
|
146
146
|
}
|
|
147
|
-
if (
|
|
148
|
-
const s = (
|
|
149
|
-
if (!(!
|
|
150
|
-
if (Array.isArray(
|
|
151
|
-
|
|
147
|
+
if (y.length > 0) {
|
|
148
|
+
const s = (f) => {
|
|
149
|
+
if (!(!f || typeof f != "object"))
|
|
150
|
+
if (Array.isArray(f))
|
|
151
|
+
f.forEach(s);
|
|
152
152
|
else {
|
|
153
|
-
for (const a of
|
|
154
|
-
delete
|
|
155
|
-
for (const a in
|
|
156
|
-
s(
|
|
153
|
+
for (const a of y)
|
|
154
|
+
delete f[a];
|
|
155
|
+
for (const a in f)
|
|
156
|
+
s(f[a]);
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
|
-
s(
|
|
159
|
+
s(o);
|
|
160
160
|
}
|
|
161
|
-
return
|
|
161
|
+
return o;
|
|
162
162
|
}
|
|
163
163
|
export {
|
|
164
164
|
g as cleanSubmitValues,
|