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.
@@ -1,192 +1,209 @@
1
- import { ref as w, shallowRef as Q, computed as W, watch as X } from "vue";
2
- import { deepClone as m, initializeFormValues as Y, cleanSubmitValues as Z, getNestedValue as R, evaluateConditional as $, setNestedValue as z, collectFileFields as _, filterNullCustomFields as ee } from "../utils/form.utils.js";
3
- import { useFileUpload as le } from "./useFileUpload.js";
4
- import { $t as ae } from "../../../utils/i18n.js";
5
- function ce(S) {
6
- const { schema: d, values: F, isUpdate: V = !1, folderId: C, onSubmit: I } = S, { handleUploadFile: N } = le(), r = w(F ? m(F) : {}), f = w({}), j = w(!1), b = w(!1), p = w({}), g = Q(
7
- F ? m(F) : {}
8
- ), A = W(() => d ? Array.isArray(d[0]) ? d.flat() : d : []), O = async (e) => {
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 Y(d, e);
11
- r.value = l, g.value = m(l), b.value = !1;
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
- O(F), X(
17
- () => F,
16
+ k(b), Y(
17
+ () => b,
18
18
  (e) => {
19
- e && O(e);
19
+ e && k(e);
20
20
  },
21
21
  { deep: !0 }
22
22
  );
23
23
  const U = () => ({
24
- values: r.value,
25
- isUpdate: V
26
- }), D = (e) => R(r.value, e), G = (e) => f.value[e] || "", P = (e, l) => {
27
- l ? f.value[e] = l : delete f.value[e];
28
- }, x = () => {
29
- f.value = {};
30
- }, k = (e) => e.when ? $(e.when, U()) : !0, E = (e) => $(e.disabled, U()), B = (e) => $(e.readonly, U()), T = async (e) => {
31
- const l = D(e.name);
32
- let t = "";
33
- const n = e.labelI18n ? ae(e.labelI18n) : typeof e.label == "string" ? e.label : e.name;
34
- if (e.required && (l == null || l === "" || Array.isArray(l) && l.length === 0) && (t = `${n} is required`), !t && e.maxFileSize) {
35
- const i = e.maxFileSize * 1024 * 1024;
36
- if (l != null && l !== "") {
37
- const s = Array.isArray(l) ? l : [l];
38
- for (const o of s) {
39
- const a = o instanceof File ? o.size : o?.fileSize || o?.file?.size || o?.size;
40
- if (a !== void 0 && a > i) {
41
- t = `${n} size must be less than ${e.maxFileSize}MB`;
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 (!t && (e.type === "file" || e.type === "fileUploader") && (e.props?.multiple || e.maxFiles)) {
48
- const i = e.maxFiles || e.props?.maxFiles;
49
- i && Array.isArray(l) && l.length > i && (t = `Maximum ${i} files allowed`);
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 (!t && e.validation) {
52
- p.value[e.name] = !0;
52
+ if (!s && e.validation) {
53
+ m.value[o] = !0;
53
54
  try {
54
- t = await e.validation({
55
- value: l,
56
- values: r.value,
57
- isUpdate: V
55
+ s = await e.validation({
56
+ value: t,
57
+ values: n.value,
58
+ globalValues: n.value,
59
+ isUpdate: w
58
60
  });
59
- } catch (i) {
60
- console.error(`[useForm] Validation error in field ${e.name}:`, i), t = "Validation failed";
61
+ } catch (r) {
62
+ console.error(`[useForm] Validation error in field ${o}:`, r), s = "Validation failed";
61
63
  } finally {
62
- p.value[e.name] = !1;
64
+ m.value[o] = !1;
63
65
  }
64
66
  }
65
- return t ? f.value[e.name] = t : delete f.value[e.name], t;
66
- }, q = async () => {
67
- x();
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 A.value) {
70
- if (!k(l) || E(l)) continue;
71
- await T(l) && (e = !1);
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
- }, H = async (e, l, t) => {
75
- const n = A.value.find((i) => i.name === e);
76
- if (n && (E(n) || B(n))) {
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 (r.value = z(r.value, e, l), b.value = !0, delete f.value[e], n?.updateValues) {
81
- p.value[e] = !0;
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 i = await n.updateValues({
84
- values: r.value,
85
- data: t,
86
- isUpdate: V,
87
- updateError: P
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
- i && typeof i == "object" && (r.value = { ...r.value, ...i });
90
- } catch (i) {
91
- console.error(`[useForm] Error in updateValues for ${e}:`, i);
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
- p.value[e] = !1;
110
+ m.value[e] = !1;
94
111
  }
95
112
  }
96
- }, J = async () => {
97
- const e = m(r.value), l = _(d, e), t = (s, o) => {
113
+ }, K = async () => {
114
+ const e = h(n.value), l = ee(F, e), o = (i, r) => {
98
115
  let a = null;
99
- s instanceof File ? a = s : s && typeof s == "object" && s.file instanceof File && (a = s.file);
100
- const h = {
101
- ...typeof s == "object" ? s : {},
102
- fileName: s?.fileName || a?.name || o.split("/").pop() || "unknown",
103
- fileUrl: o,
104
- fileType: s?.fileType || a?.type || "application/octet-stream",
105
- fileSize: s?.fileSize || a?.size || 0
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 h.file, delete h.base64, h;
108
- }, n = l.map(async (s) => {
109
- const { name: o, value: a, field: h } = s, L = h.returnFileObject === !0, M = Array.isArray(a) ? a.some(
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
- M && (p.value[o] = !0);
129
+ N && (m.value[r] = !0);
113
130
  try {
114
131
  if (Array.isArray(a)) {
115
- const v = a.map(async (u) => {
116
- if (u instanceof File || u && typeof u == "object" && u.file instanceof File) {
117
- const y = await N(u, C);
118
- return y ? L ? t(u, y) : y : null;
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 (u && typeof u == "object") {
121
- const y = { ...u };
137
+ if (f && typeof f == "object") {
138
+ const y = { ...f };
122
139
  return delete y.file, delete y.base64, y;
123
140
  }
124
- return u;
125
- }), c = await Promise.all(v);
126
- return { name: o, value: c };
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 c = await N(a, C);
130
- if (c)
131
- return { name: o, value: L ? t(a, c) : c };
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 c = { ...a };
134
- return delete c.file, delete c.base64, { name: o, value: c };
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
- M && (p.value[o] = !1);
156
+ N && (m.value[r] = !1);
140
157
  }
141
158
  });
142
- return (await Promise.all(n)).forEach((s) => {
143
- s && (Object.assign(e, z(e, s.name, s.value)), r.value = z(r.value, s.name, s.value));
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
- }, K = (e) => {
162
+ }, Q = (e) => {
146
163
  const l = { ...e };
147
- for (const t of A.value)
148
- if (t.type === "customFields" && t.props?.schema) {
149
- const n = R(l, t.name);
150
- if (Array.isArray(n)) {
151
- const i = ee(n, t.props.schema);
152
- Object.assign(l, z(l, t.name, i));
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: r,
159
- errors: f,
175
+ formValues: n,
176
+ errors: p,
160
177
  isSubmitting: j,
161
- isDirty: b,
162
- fieldLoading: p,
163
- handleFieldChange: H,
164
- validateField: T,
165
- validateAll: q,
166
- isFieldVisible: k,
167
- isFieldDisabled: E,
168
- isFieldReadonly: B,
169
- getFieldValue: D,
170
- getFieldError: G,
171
- setFieldError: P,
172
- clearErrors: x,
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
- r.value = m(g.value), x(), b.value = !1;
191
+ n.value = h(x.value), E(), V.value = !1;
175
192
  },
176
193
  handleSubmit: async () => {
177
- if (await q()) {
194
+ if (await M()) {
178
195
  j.value = !0;
179
196
  try {
180
- let l = await J();
181
- l = K(l), l = await Z(
197
+ let l = await K();
198
+ l = Q(l), l = await _(
182
199
  l,
183
- d,
184
- S.emitFields,
185
- S.emitFields
186
- ), I && await I({
200
+ F,
201
+ $.emitFields,
202
+ $.emitFields
203
+ ), O && await O({
187
204
  values: l,
188
- isUpdate: V
189
- }), b.value = !1, g.value = m(l);
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: A
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;