vlite3 0.9.6 → 0.9.7
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/components/ColorPicker/ColorIro.vue3.js +2 -2
- package/components/ColorPicker/ColorPicker.vue.js +2 -2
- package/components/DatePicker.vue.js +38 -32
- package/components/DateRangePicker.vue.js +28 -26
- package/components/Dropdown/DropdownBooleanItem.vue.js +12 -9
- package/components/Dropdown/DropdownMenu.vue.js +2 -2
- package/components/Dropdown/DropdownMenu.vue2.js +51 -51
- package/components/Form/CustomFields.vue.d.ts +4 -0
- package/components/Form/CustomFields.vue.js +2 -2
- package/components/Form/CustomFields.vue2.js +147 -115
- package/components/Form/FormField.vue.d.ts +1 -0
- package/components/Form/FormField.vue.js +3 -0
- package/components/Form/FormFields.vue.js +2 -2
- package/components/Form/FormFields.vue2.js +38 -37
- package/components/Form/composables/useForm.d.ts +1 -1
- package/components/Form/composables/useForm.js +142 -125
- package/components/Form/types.d.ts +6 -0
- package/components/Form/utils/form.utils.js +115 -106
- package/components/Screen/ScreenFilter.vue.js +1 -1
- package/package.json +2 -2
- package/style.css +6 -1
- /package/components/ColorPicker/{ColorIro.vue2.js → ColorIro.vue.js} +0 -0
|
@@ -1,192 +1,209 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import { deepClone as
|
|
3
|
-
import { useFileUpload as
|
|
4
|
-
import { $t as
|
|
5
|
-
function ce(
|
|
6
|
-
const { schema:
|
|
7
|
-
|
|
8
|
-
),
|
|
1
|
+
import { ref as A, shallowRef as W, computed as X, watch as Y } from "vue";
|
|
2
|
+
import { deepClone as h, initializeFormValues as Z, cleanSubmitValues as _, getNestedValue as G, evaluateConditional as g, setNestedValue as z, collectFileFields as ee, filterNullCustomFields as le } from "../utils/form.utils.js";
|
|
3
|
+
import { useFileUpload as ae } from "./useFileUpload.js";
|
|
4
|
+
import { $t as te } from "../../../utils/i18n.js";
|
|
5
|
+
function ce($) {
|
|
6
|
+
const { schema: F, values: b, isUpdate: w = !1, folderId: D, onSubmit: O } = $, { handleUploadFile: P } = ae(), n = A(b ? h(b) : {}), p = A({}), j = A(!1), V = A(!1), m = A({}), x = W(
|
|
7
|
+
b ? h(b) : {}
|
|
8
|
+
), S = X(() => F ? Array.isArray(F[0]) ? F.flat() : F : []), k = async (e) => {
|
|
9
9
|
try {
|
|
10
|
-
const l = await
|
|
11
|
-
|
|
10
|
+
const l = await Z(F, e);
|
|
11
|
+
n.value = l, x.value = h(l), V.value = !1;
|
|
12
12
|
} catch (l) {
|
|
13
13
|
console.error("[useForm] Initialization error:", l);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
() =>
|
|
16
|
+
k(b), Y(
|
|
17
|
+
() => b,
|
|
18
18
|
(e) => {
|
|
19
|
-
e &&
|
|
19
|
+
e && k(e);
|
|
20
20
|
},
|
|
21
21
|
{ deep: !0 }
|
|
22
22
|
);
|
|
23
23
|
const U = () => ({
|
|
24
|
-
values:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
values: n.value,
|
|
25
|
+
globalValues: n.value,
|
|
26
|
+
isUpdate: w
|
|
27
|
+
}), B = (e) => G(n.value, e), H = (e) => p.value[e] || "", T = (e, l) => {
|
|
28
|
+
l ? p.value[e] = l : delete p.value[e];
|
|
29
|
+
}, E = () => {
|
|
30
|
+
p.value = {};
|
|
31
|
+
}, q = (e) => e.when ? g(e.when, U()) : !0, C = (e) => g(e.disabled, U()), L = (e) => g(e.readonly, U()), I = async (e, l = "") => {
|
|
32
|
+
const o = l ? `${l}.${e.name}` : e.name, t = B(o);
|
|
33
|
+
let s = "";
|
|
34
|
+
const i = e.labelI18n ? te(e.labelI18n) : typeof e.label == "string" ? e.label : e.name;
|
|
35
|
+
if (e.required && (t == null || t === "" || Array.isArray(t) && t.length === 0) && (s = `${i} is required`), !s && e.maxFileSize) {
|
|
36
|
+
const r = e.maxFileSize * 1024 * 1024;
|
|
37
|
+
if (t != null && t !== "") {
|
|
38
|
+
const a = Array.isArray(t) ? t : [t];
|
|
39
|
+
for (const c of a) {
|
|
40
|
+
const d = c instanceof File ? c.size : c?.fileSize || c?.file?.size || c?.size;
|
|
41
|
+
if (d !== void 0 && d > r) {
|
|
42
|
+
s = `${i} size must be less than ${e.maxFileSize}MB`;
|
|
42
43
|
break;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
|
|
48
|
+
if (!s && (e.type === "file" || e.type === "fileUploader") && (e.props?.multiple || e.maxFiles)) {
|
|
49
|
+
const r = e.maxFiles || e.props?.maxFiles;
|
|
50
|
+
r && Array.isArray(t) && t.length > r && (s = `Maximum ${r} files allowed`);
|
|
50
51
|
}
|
|
51
|
-
if (!
|
|
52
|
-
|
|
52
|
+
if (!s && e.validation) {
|
|
53
|
+
m.value[o] = !0;
|
|
53
54
|
try {
|
|
54
|
-
|
|
55
|
-
value:
|
|
56
|
-
values:
|
|
57
|
-
|
|
55
|
+
s = await e.validation({
|
|
56
|
+
value: t,
|
|
57
|
+
values: n.value,
|
|
58
|
+
globalValues: n.value,
|
|
59
|
+
isUpdate: w
|
|
58
60
|
});
|
|
59
|
-
} catch (
|
|
60
|
-
console.error(`[useForm] Validation error in field ${
|
|
61
|
+
} catch (r) {
|
|
62
|
+
console.error(`[useForm] Validation error in field ${o}:`, r), s = "Validation failed";
|
|
61
63
|
} finally {
|
|
62
|
-
|
|
64
|
+
m.value[o] = !1;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
if (s ? p.value[o] = s : delete p.value[o], e.type === "customFields" && e.props?.schema) {
|
|
68
|
+
const r = e.props.schema, a = Array.isArray(t) ? t : [];
|
|
69
|
+
let c = !1;
|
|
70
|
+
for (let d = 0; d < a.length; d++) {
|
|
71
|
+
const v = { values: a[d] || {}, globalValues: n.value, isUpdate: w };
|
|
72
|
+
for (const u of r) {
|
|
73
|
+
const f = !u.when || g(u.when, v), R = g(u.disabled, v);
|
|
74
|
+
f && !R ? await I(u, `${o}.${d}`) && (c = !0) : delete p.value[`${o}.${d}.${u.name}`];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
c && !s && (s = "Please fix errors in the list.", p.value[o] = s);
|
|
78
|
+
}
|
|
79
|
+
return s;
|
|
80
|
+
}, M = async () => {
|
|
81
|
+
E();
|
|
68
82
|
let e = !0;
|
|
69
|
-
for (const l of
|
|
70
|
-
if (!
|
|
71
|
-
await
|
|
83
|
+
for (const l of S.value) {
|
|
84
|
+
if (!q(l) || C(l)) continue;
|
|
85
|
+
await I(l) && (e = !1);
|
|
72
86
|
}
|
|
73
87
|
return e;
|
|
74
|
-
},
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
88
|
+
}, J = async (e, l, o) => {
|
|
89
|
+
const t = S.value.find((s) => s.name === e);
|
|
90
|
+
if (t && (C(t) || L(t))) {
|
|
77
91
|
console.warn(`[vlite3/useForm] Blocked attempted update to disabled/readonly field: ${e}`);
|
|
78
92
|
return;
|
|
79
93
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
94
|
+
if (n.value = z(n.value, e, l), V.value = !0, delete p.value[e], t?.updateValues) {
|
|
95
|
+
m.value[e] = !0;
|
|
82
96
|
try {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
const s = await t.updateValues({
|
|
98
|
+
value: l,
|
|
99
|
+
// Exposing the explicitly requested value
|
|
100
|
+
values: n.value,
|
|
101
|
+
globalValues: n.value,
|
|
102
|
+
data: o,
|
|
103
|
+
isUpdate: w,
|
|
104
|
+
updateError: T
|
|
88
105
|
});
|
|
89
|
-
|
|
90
|
-
} catch (
|
|
91
|
-
console.error(`[useForm] Error in updateValues for ${e}:`,
|
|
106
|
+
s && typeof s == "object" && (n.value = { ...n.value, ...s });
|
|
107
|
+
} catch (s) {
|
|
108
|
+
console.error(`[useForm] Error in updateValues for ${e}:`, s);
|
|
92
109
|
} finally {
|
|
93
|
-
|
|
110
|
+
m.value[e] = !1;
|
|
94
111
|
}
|
|
95
112
|
}
|
|
96
|
-
},
|
|
97
|
-
const e =
|
|
113
|
+
}, K = async () => {
|
|
114
|
+
const e = h(n.value), l = ee(F, e), o = (i, r) => {
|
|
98
115
|
let a = null;
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
...typeof
|
|
102
|
-
fileName:
|
|
103
|
-
fileUrl:
|
|
104
|
-
fileType:
|
|
105
|
-
fileSize:
|
|
116
|
+
i instanceof File ? a = i : i && typeof i == "object" && i.file instanceof File && (a = i.file);
|
|
117
|
+
const c = {
|
|
118
|
+
...typeof i == "object" ? i : {},
|
|
119
|
+
fileName: i?.fileName || a?.name || r.split("/").pop() || "unknown",
|
|
120
|
+
fileUrl: r,
|
|
121
|
+
fileType: i?.fileType || a?.type || "application/octet-stream",
|
|
122
|
+
fileSize: i?.fileSize || a?.size || 0
|
|
106
123
|
};
|
|
107
|
-
return delete
|
|
108
|
-
},
|
|
109
|
-
const { name:
|
|
124
|
+
return delete c.file, delete c.base64, c;
|
|
125
|
+
}, t = l.map(async (i) => {
|
|
126
|
+
const { name: r, value: a, field: c } = i, d = c.returnFileObject === !0, N = Array.isArray(a) ? a.some(
|
|
110
127
|
(v) => v instanceof File || v && typeof v == "object" && v.file instanceof File
|
|
111
128
|
) : a instanceof File || a && typeof a == "object" && a.file instanceof File;
|
|
112
|
-
|
|
129
|
+
N && (m.value[r] = !0);
|
|
113
130
|
try {
|
|
114
131
|
if (Array.isArray(a)) {
|
|
115
|
-
const v = a.map(async (
|
|
116
|
-
if (
|
|
117
|
-
const y = await
|
|
118
|
-
return y ?
|
|
132
|
+
const v = a.map(async (f) => {
|
|
133
|
+
if (f instanceof File || f && typeof f == "object" && f.file instanceof File) {
|
|
134
|
+
const y = await P(f, D);
|
|
135
|
+
return y ? d ? o(f, y) : y : null;
|
|
119
136
|
}
|
|
120
|
-
if (
|
|
121
|
-
const y = { ...
|
|
137
|
+
if (f && typeof f == "object") {
|
|
138
|
+
const y = { ...f };
|
|
122
139
|
return delete y.file, delete y.base64, y;
|
|
123
140
|
}
|
|
124
|
-
return
|
|
125
|
-
}),
|
|
126
|
-
return { name:
|
|
141
|
+
return f;
|
|
142
|
+
}), u = await Promise.all(v);
|
|
143
|
+
return { name: r, value: u };
|
|
127
144
|
} else {
|
|
128
145
|
if (a instanceof File || a && typeof a == "object" && a.file instanceof File) {
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
return { name:
|
|
146
|
+
const u = await P(a, D);
|
|
147
|
+
if (u)
|
|
148
|
+
return { name: r, value: d ? o(a, u) : u };
|
|
132
149
|
} else if (a && typeof a == "object") {
|
|
133
|
-
const
|
|
134
|
-
return delete
|
|
150
|
+
const u = { ...a };
|
|
151
|
+
return delete u.file, delete u.base64, { name: r, value: u };
|
|
135
152
|
}
|
|
136
153
|
return null;
|
|
137
154
|
}
|
|
138
155
|
} finally {
|
|
139
|
-
|
|
156
|
+
N && (m.value[r] = !1);
|
|
140
157
|
}
|
|
141
158
|
});
|
|
142
|
-
return (await Promise.all(
|
|
143
|
-
|
|
159
|
+
return (await Promise.all(t)).forEach((i) => {
|
|
160
|
+
i && (Object.assign(e, z(e, i.name, i.value)), n.value = z(n.value, i.name, i.value));
|
|
144
161
|
}), e;
|
|
145
|
-
},
|
|
162
|
+
}, Q = (e) => {
|
|
146
163
|
const l = { ...e };
|
|
147
|
-
for (const
|
|
148
|
-
if (
|
|
149
|
-
const
|
|
150
|
-
if (Array.isArray(
|
|
151
|
-
const
|
|
152
|
-
Object.assign(l, z(l,
|
|
164
|
+
for (const o of S.value)
|
|
165
|
+
if (o.type === "customFields" && o.props?.schema) {
|
|
166
|
+
const t = G(l, o.name);
|
|
167
|
+
if (Array.isArray(t)) {
|
|
168
|
+
const s = le(t, o.props.schema);
|
|
169
|
+
Object.assign(l, z(l, o.name, s));
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
172
|
return l;
|
|
156
173
|
};
|
|
157
174
|
return {
|
|
158
|
-
formValues:
|
|
159
|
-
errors:
|
|
175
|
+
formValues: n,
|
|
176
|
+
errors: p,
|
|
160
177
|
isSubmitting: j,
|
|
161
|
-
isDirty:
|
|
162
|
-
fieldLoading:
|
|
163
|
-
handleFieldChange:
|
|
164
|
-
validateField:
|
|
165
|
-
validateAll:
|
|
166
|
-
isFieldVisible:
|
|
167
|
-
isFieldDisabled:
|
|
168
|
-
isFieldReadonly:
|
|
169
|
-
getFieldValue:
|
|
170
|
-
getFieldError:
|
|
171
|
-
setFieldError:
|
|
172
|
-
clearErrors:
|
|
178
|
+
isDirty: V,
|
|
179
|
+
fieldLoading: m,
|
|
180
|
+
handleFieldChange: J,
|
|
181
|
+
validateField: I,
|
|
182
|
+
validateAll: M,
|
|
183
|
+
isFieldVisible: q,
|
|
184
|
+
isFieldDisabled: C,
|
|
185
|
+
isFieldReadonly: L,
|
|
186
|
+
getFieldValue: B,
|
|
187
|
+
getFieldError: H,
|
|
188
|
+
setFieldError: T,
|
|
189
|
+
clearErrors: E,
|
|
173
190
|
resetForm: () => {
|
|
174
|
-
|
|
191
|
+
n.value = h(x.value), E(), V.value = !1;
|
|
175
192
|
},
|
|
176
193
|
handleSubmit: async () => {
|
|
177
|
-
if (await
|
|
194
|
+
if (await M()) {
|
|
178
195
|
j.value = !0;
|
|
179
196
|
try {
|
|
180
|
-
let l = await
|
|
181
|
-
l =
|
|
197
|
+
let l = await K();
|
|
198
|
+
l = Q(l), l = await _(
|
|
182
199
|
l,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
),
|
|
200
|
+
F,
|
|
201
|
+
$.emitFields,
|
|
202
|
+
$.emitFields
|
|
203
|
+
), O && await O({
|
|
187
204
|
values: l,
|
|
188
|
-
isUpdate:
|
|
189
|
-
}),
|
|
205
|
+
isUpdate: w
|
|
206
|
+
}), V.value = !1, x.value = h(l);
|
|
190
207
|
} catch (l) {
|
|
191
208
|
throw console.error("[useForm] Submit error:", l), l;
|
|
192
209
|
} finally {
|
|
@@ -194,7 +211,7 @@ function ce(S) {
|
|
|
194
211
|
}
|
|
195
212
|
}
|
|
196
213
|
},
|
|
197
|
-
flatSchema:
|
|
214
|
+
flatSchema: S
|
|
198
215
|
};
|
|
199
216
|
}
|
|
200
217
|
export {
|
|
@@ -28,7 +28,10 @@ export type IFormFieldType = 'text' | 'email' | 'password' | 'number' | 'file' |
|
|
|
28
28
|
* Context passed to conditional functions
|
|
29
29
|
*/
|
|
30
30
|
export interface IFormContext {
|
|
31
|
+
/** The local scope values (row values in customFields, or global values at root level) */
|
|
31
32
|
values: Record<string, any>;
|
|
33
|
+
/** The root form state */
|
|
34
|
+
globalValues?: Record<string, any>;
|
|
32
35
|
isUpdate?: boolean;
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
@@ -41,6 +44,7 @@ export type IFormDisabled = boolean | ((context: IFormContext) => boolean);
|
|
|
41
44
|
export interface IFormValidationContext {
|
|
42
45
|
value: any;
|
|
43
46
|
values: Record<string, any>;
|
|
47
|
+
globalValues?: Record<string, any>;
|
|
44
48
|
isUpdate?: boolean;
|
|
45
49
|
}
|
|
46
50
|
export type IFormValidation = (context: IFormValidationContext) => string | Promise<string>;
|
|
@@ -48,7 +52,9 @@ export type IFormValidation = (context: IFormValidationContext) => string | Prom
|
|
|
48
52
|
* UpdateValues function signature - allows computed/derived fields
|
|
49
53
|
*/
|
|
50
54
|
export interface IFormUpdateContext {
|
|
55
|
+
value: any;
|
|
51
56
|
values: Record<string, any>;
|
|
57
|
+
globalValues?: Record<string, any>;
|
|
52
58
|
data?: any;
|
|
53
59
|
isUpdate?: boolean;
|
|
54
60
|
updateError?: (name: string, error: string) => void;
|