bank20baht-ui 0.2.5 → 0.2.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/dist/chunks/index-BI-29Q8f.js +694 -0
- package/dist/components/primitives/baht-datepicker.d.ts +34 -2
- package/dist/core/dates.d.ts +29 -0
- package/dist/core/i18n.d.ts +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/types.d.ts +21 -0
- package/dist/custom-elements.json +106 -1
- package/dist/engine.js +22 -628
- package/dist/index.js +724 -640
- package/dist/react.d.ts +1 -0
- package/dist/tokens.css +170 -1
- package/dist/vscode.html-custom-data.json +1 -1
- package/dist/web-types.json +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
function D(e) {
|
|
2
|
+
if (e.value !== void 0) return e.value;
|
|
3
|
+
switch (e.type) {
|
|
4
|
+
case "checkbox":
|
|
5
|
+
case "toggle":
|
|
6
|
+
return !1;
|
|
7
|
+
case "multiselect":
|
|
8
|
+
case "repeater":
|
|
9
|
+
return [];
|
|
10
|
+
case "file":
|
|
11
|
+
return e.multiple ? [] : null;
|
|
12
|
+
case "label":
|
|
13
|
+
case "section":
|
|
14
|
+
return;
|
|
15
|
+
// static block, no value
|
|
16
|
+
default:
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const Y = {
|
|
21
|
+
required: "This field is required",
|
|
22
|
+
minLength: "Must be at least {n} characters",
|
|
23
|
+
maxLength: "Must be at most {n} characters",
|
|
24
|
+
min: "Must be at least {n}",
|
|
25
|
+
max: "Must be at most {n}",
|
|
26
|
+
pattern: "Invalid format",
|
|
27
|
+
email: "Invalid email address",
|
|
28
|
+
dateDisabled: "This date cannot be selected",
|
|
29
|
+
compareEq: "Must match {other}",
|
|
30
|
+
compareNe: "Must differ from {other}",
|
|
31
|
+
compareGt: "Must be greater than {other}",
|
|
32
|
+
compareGte: "Must be at least {other}",
|
|
33
|
+
compareLt: "Must be less than {other}",
|
|
34
|
+
compareLte: "Must be at most {other}",
|
|
35
|
+
fileTooLarge: "File is too large",
|
|
36
|
+
fileTypeNotAllowed: "File type not allowed",
|
|
37
|
+
fileRejectedTooLarge: "Too large, not added: {names}",
|
|
38
|
+
uploading: "Uploading…",
|
|
39
|
+
uploadFailed: "Upload failed, try again",
|
|
40
|
+
removeFile: "Remove file",
|
|
41
|
+
addRow: "Add row",
|
|
42
|
+
removeRow: "Remove row",
|
|
43
|
+
minRows: "Add at least {n} rows",
|
|
44
|
+
maxRows: "Add at most {n} rows",
|
|
45
|
+
next: "Next",
|
|
46
|
+
submit: "Submit",
|
|
47
|
+
back: "Back",
|
|
48
|
+
step: "Step {current} of {total}",
|
|
49
|
+
approve: "Approve",
|
|
50
|
+
reject: "Reject",
|
|
51
|
+
decision: "Decision",
|
|
52
|
+
comment: "Comment",
|
|
53
|
+
commentRequiredSuffix: " (required)",
|
|
54
|
+
decisionRequired: "A decision is required.",
|
|
55
|
+
commentRequired: "A comment is required.",
|
|
56
|
+
nothingToReview: "Nothing to review.",
|
|
57
|
+
yes: "Yes",
|
|
58
|
+
no: "No",
|
|
59
|
+
emptyValue: "Not provided",
|
|
60
|
+
choose: "Select",
|
|
61
|
+
rowCount: "{n} rows"
|
|
62
|
+
}, J = {
|
|
63
|
+
required: "กรุณากรอกข้อมูลนี้",
|
|
64
|
+
minLength: "ต้องมีอย่างน้อย {n} ตัวอักษร",
|
|
65
|
+
maxLength: "ต้องไม่เกิน {n} ตัวอักษร",
|
|
66
|
+
min: "ต้องไม่น้อยกว่า {n}",
|
|
67
|
+
max: "ต้องไม่เกิน {n}",
|
|
68
|
+
pattern: "รูปแบบไม่ถูกต้อง",
|
|
69
|
+
email: "อีเมลไม่ถูกต้อง",
|
|
70
|
+
dateDisabled: "ไม่สามารถเลือกวันที่นี้ได้",
|
|
71
|
+
compareEq: "ต้องตรงกับ {other}",
|
|
72
|
+
compareNe: "ต้องไม่ตรงกับ {other}",
|
|
73
|
+
compareGt: "ต้องมากกว่า {other}",
|
|
74
|
+
compareGte: "ต้องไม่น้อยกว่า {other}",
|
|
75
|
+
compareLt: "ต้องน้อยกว่า {other}",
|
|
76
|
+
compareLte: "ต้องไม่เกิน {other}",
|
|
77
|
+
fileTooLarge: "ไฟล์มีขนาดใหญ่เกินไป",
|
|
78
|
+
fileTypeNotAllowed: "ชนิดไฟล์ไม่ได้รับอนุญาต",
|
|
79
|
+
fileRejectedTooLarge: "ขนาดใหญ่เกินไป ไม่ถูกเพิ่ม: {names}",
|
|
80
|
+
uploading: "กำลังอัปโหลด…",
|
|
81
|
+
uploadFailed: "อัปโหลดไม่สำเร็จ ลองอีกครั้ง",
|
|
82
|
+
removeFile: "ลบไฟล์",
|
|
83
|
+
addRow: "เพิ่มแถว",
|
|
84
|
+
removeRow: "ลบแถว",
|
|
85
|
+
minRows: "ต้องมีอย่างน้อย {n} แถว",
|
|
86
|
+
maxRows: "ต้องไม่เกิน {n} แถว",
|
|
87
|
+
next: "ถัดไป",
|
|
88
|
+
submit: "ส่งข้อมูล",
|
|
89
|
+
back: "ย้อนกลับ",
|
|
90
|
+
step: "ขั้นตอนที่ {current} จาก {total}",
|
|
91
|
+
approve: "อนุมัติ",
|
|
92
|
+
reject: "ไม่อนุมัติ",
|
|
93
|
+
decision: "ผลการพิจารณา",
|
|
94
|
+
comment: "ความคิดเห็น",
|
|
95
|
+
commentRequiredSuffix: " (จำเป็น)",
|
|
96
|
+
decisionRequired: "ต้องเลือกผลการพิจารณา",
|
|
97
|
+
commentRequired: "ต้องกรอกความคิดเห็น",
|
|
98
|
+
nothingToReview: "ไม่มีข้อมูลให้ตรวจสอบ",
|
|
99
|
+
yes: "ใช่",
|
|
100
|
+
no: "ไม่ใช่",
|
|
101
|
+
emptyValue: "ไม่ได้ระบุ",
|
|
102
|
+
choose: "เลือก",
|
|
103
|
+
rowCount: "{n} แถว"
|
|
104
|
+
}, K = { en: Y, th: J };
|
|
105
|
+
let R = Y;
|
|
106
|
+
function xe(e, t) {
|
|
107
|
+
R = { ...K[e], ...t };
|
|
108
|
+
}
|
|
109
|
+
function Ae() {
|
|
110
|
+
return R;
|
|
111
|
+
}
|
|
112
|
+
function ve(e) {
|
|
113
|
+
R = e;
|
|
114
|
+
}
|
|
115
|
+
function f(e, t) {
|
|
116
|
+
let n = R[e];
|
|
117
|
+
if (t)
|
|
118
|
+
for (const [s, r] of Object.entries(t))
|
|
119
|
+
n = n.replaceAll(`{${s}}`, () => String(r));
|
|
120
|
+
return n;
|
|
121
|
+
}
|
|
122
|
+
function B(e) {
|
|
123
|
+
if (e.kind !== "approval") return [];
|
|
124
|
+
const t = (s) => e.field_data.some((r) => r.key === s), n = [];
|
|
125
|
+
return t("decision") || n.push({ order: 9001, type: "text", key: "decision", label: f("decision") }), t("comment") || n.push({ order: 9002, type: "textarea", key: "comment", label: f("comment") }), n;
|
|
126
|
+
}
|
|
127
|
+
function q(e, t) {
|
|
128
|
+
var s;
|
|
129
|
+
const n = t.indexOf(".");
|
|
130
|
+
if (n !== -1)
|
|
131
|
+
return (s = e[t.slice(0, n)]) == null ? void 0 : s[t.slice(n + 1)];
|
|
132
|
+
}
|
|
133
|
+
function j(e) {
|
|
134
|
+
return e == null ? !0 : typeof e == "string" ? e === "" : Array.isArray(e) ? e.length === 0 : !1;
|
|
135
|
+
}
|
|
136
|
+
function w(e, t) {
|
|
137
|
+
if (typeof e == "number" && typeof t == "number") return e - t;
|
|
138
|
+
if (e instanceof Date || t instanceof Date) {
|
|
139
|
+
const r = new Date(e).getTime(), o = new Date(t).getTime();
|
|
140
|
+
return Number.isNaN(r) || Number.isNaN(o) ? null : r - o;
|
|
141
|
+
}
|
|
142
|
+
if (typeof e == "string" && typeof t == "string") {
|
|
143
|
+
const r = Number(e), o = Number(t);
|
|
144
|
+
return e !== "" && t !== "" && !Number.isNaN(r) && !Number.isNaN(o) ? r - o : e < t ? -1 : e > t ? 1 : 0;
|
|
145
|
+
}
|
|
146
|
+
const n = Number(e), s = Number(t);
|
|
147
|
+
return Number.isNaN(n) || Number.isNaN(s) ? null : n - s;
|
|
148
|
+
}
|
|
149
|
+
function X(e, t) {
|
|
150
|
+
const n = q(t, e.field), s = e.valueField !== void 0 ? q(t, e.valueField) : e.value;
|
|
151
|
+
switch (e.op) {
|
|
152
|
+
case "eq":
|
|
153
|
+
return n === s;
|
|
154
|
+
case "ne":
|
|
155
|
+
return n !== s;
|
|
156
|
+
case "gt": {
|
|
157
|
+
const r = w(n, s);
|
|
158
|
+
return r !== null && r > 0;
|
|
159
|
+
}
|
|
160
|
+
case "gte": {
|
|
161
|
+
const r = w(n, s);
|
|
162
|
+
return r !== null && r >= 0;
|
|
163
|
+
}
|
|
164
|
+
case "lt": {
|
|
165
|
+
const r = w(n, s);
|
|
166
|
+
return r !== null && r < 0;
|
|
167
|
+
}
|
|
168
|
+
case "lte": {
|
|
169
|
+
const r = w(n, s);
|
|
170
|
+
return r !== null && r <= 0;
|
|
171
|
+
}
|
|
172
|
+
case "in":
|
|
173
|
+
return Array.isArray(s) && s.includes(n);
|
|
174
|
+
case "notIn":
|
|
175
|
+
return Array.isArray(s) && !s.includes(n);
|
|
176
|
+
case "contains":
|
|
177
|
+
return Array.isArray(n) ? n.includes(s) : typeof n == "string" && n.includes(String(s));
|
|
178
|
+
case "notContains":
|
|
179
|
+
return Array.isArray(n) ? !n.includes(s) : typeof n == "string" && !n.includes(String(s));
|
|
180
|
+
case "startsWith":
|
|
181
|
+
return typeof n == "string" && n.startsWith(String(s));
|
|
182
|
+
case "endsWith":
|
|
183
|
+
return typeof n == "string" && n.endsWith(String(s));
|
|
184
|
+
case "isEmpty":
|
|
185
|
+
return j(n);
|
|
186
|
+
case "isNotEmpty":
|
|
187
|
+
return !j(n);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function x(e, t) {
|
|
191
|
+
return e === void 0 ? !0 : "and" in e ? e.and.every((n) => x(n, t)) : "or" in e ? e.or.some((n) => x(n, t)) : "not" in e ? !x(e.not, t) : X(e, t);
|
|
192
|
+
}
|
|
193
|
+
const H = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
194
|
+
function A(e) {
|
|
195
|
+
if (typeof e != "string") return null;
|
|
196
|
+
const t = H.exec(e);
|
|
197
|
+
if (!t) return null;
|
|
198
|
+
const [n, s, r] = [Number(t[1]), Number(t[2]), Number(t[3])], o = new Date(n, s - 1, r);
|
|
199
|
+
return o.getFullYear() !== n || o.getMonth() !== s - 1 || o.getDate() !== r ? null : o;
|
|
200
|
+
}
|
|
201
|
+
function Q(e) {
|
|
202
|
+
const t = (n) => String(n).padStart(2, "0");
|
|
203
|
+
return `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())}`;
|
|
204
|
+
}
|
|
205
|
+
const Z = (e) => e.dateMode ?? "single";
|
|
206
|
+
function ee(e) {
|
|
207
|
+
return typeof e == "string" ? e === "" ? [] : [e] : Array.isArray(e) ? e.filter((t) => typeof t == "string") : [];
|
|
208
|
+
}
|
|
209
|
+
function te(e) {
|
|
210
|
+
const t = e.indexOf("/");
|
|
211
|
+
if (t === -1) {
|
|
212
|
+
const r = A(e);
|
|
213
|
+
return r ? [r, r] : null;
|
|
214
|
+
}
|
|
215
|
+
const n = A(e.slice(0, t)), s = A(e.slice(t + 1));
|
|
216
|
+
return !n || !s ? null : n <= s ? [n, s] : [s, n];
|
|
217
|
+
}
|
|
218
|
+
function ne(e, t) {
|
|
219
|
+
var s;
|
|
220
|
+
const n = A(t);
|
|
221
|
+
if (!n) return !1;
|
|
222
|
+
if ((s = e.disabledWeekdays) != null && s.includes(n.getDay())) return !0;
|
|
223
|
+
for (const r of e.disabledDates ?? []) {
|
|
224
|
+
const o = te(r);
|
|
225
|
+
if (o && n >= o[0] && n <= o[1]) return !0;
|
|
226
|
+
}
|
|
227
|
+
return !1;
|
|
228
|
+
}
|
|
229
|
+
function re(e, t, n = 3660) {
|
|
230
|
+
const s = A(e), r = A(t);
|
|
231
|
+
if (!s || !r || s >= r) return [];
|
|
232
|
+
const o = [], i = new Date(s);
|
|
233
|
+
for (i.setDate(i.getDate() + 1); i < r && o.length < n; )
|
|
234
|
+
o.push(Q(i)), i.setDate(i.getDate() + 1);
|
|
235
|
+
return o;
|
|
236
|
+
}
|
|
237
|
+
const se = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
238
|
+
function F(e) {
|
|
239
|
+
return e == null ? !0 : typeof e == "string" ? e === "" : Array.isArray(e) ? e.length === 0 : typeof e == "boolean" ? e === !1 : !1;
|
|
240
|
+
}
|
|
241
|
+
function oe(e) {
|
|
242
|
+
const t = [...e.validators ?? []], n = (s) => t.some((r) => r.type === s);
|
|
243
|
+
return e.required && !n("required") && t.push({ type: "required" }), e.maxLength !== void 0 && !n("maxLength") && t.push({ type: "maxLength", value: e.maxLength }), e.minLength !== void 0 && !n("minLength") && t.push({ type: "minLength", value: e.minLength }), e.min !== void 0 && !n("min") && t.push({ type: "min", value: e.min }), e.max !== void 0 && !n("max") && t.push({ type: "max", value: e.max }), e.type === "email" && !n("email") && t.push({ type: "email" }), t;
|
|
244
|
+
}
|
|
245
|
+
const M = (e) => Array.isArray(e) ? e : [e];
|
|
246
|
+
function ie(e, t, n, s) {
|
|
247
|
+
var r;
|
|
248
|
+
switch (e.type) {
|
|
249
|
+
case "required":
|
|
250
|
+
return F(t) ? e.message ?? f("required") : null;
|
|
251
|
+
case "minLength": {
|
|
252
|
+
const o = Number(e.value);
|
|
253
|
+
return Number.isNaN(o) ? (console.warn(
|
|
254
|
+
`[bahtui] minLength validator has non-numeric value ${JSON.stringify(e.value)} — skipped`
|
|
255
|
+
), null) : typeof t == "string" && t.length < o ? e.message ?? f("minLength", { n: e.value }) : null;
|
|
256
|
+
}
|
|
257
|
+
case "maxLength": {
|
|
258
|
+
const o = Number(e.value);
|
|
259
|
+
return Number.isNaN(o) ? (console.warn(
|
|
260
|
+
`[bahtui] maxLength validator has non-numeric value ${JSON.stringify(e.value)} — skipped`
|
|
261
|
+
), null) : typeof t == "string" && t.length > o ? e.message ?? f("maxLength", { n: e.value }) : null;
|
|
262
|
+
}
|
|
263
|
+
case "min":
|
|
264
|
+
return M(t).some((i) => {
|
|
265
|
+
const a = w(i, e.value);
|
|
266
|
+
return a !== null && a < 0;
|
|
267
|
+
}) ? e.message ?? f("min", { n: e.value }) : null;
|
|
268
|
+
case "max":
|
|
269
|
+
return M(t).some((i) => {
|
|
270
|
+
const a = w(i, e.value);
|
|
271
|
+
return a !== null && a > 0;
|
|
272
|
+
}) ? e.message ?? f("max", { n: e.value }) : null;
|
|
273
|
+
case "pattern": {
|
|
274
|
+
if (typeof t != "string") return null;
|
|
275
|
+
let o;
|
|
276
|
+
try {
|
|
277
|
+
o = new RegExp(String(e.value));
|
|
278
|
+
} catch {
|
|
279
|
+
return console.warn(`[bahtui] invalid pattern ${JSON.stringify(e.value)} — skipped`), null;
|
|
280
|
+
}
|
|
281
|
+
return o.test(t) ? null : e.message ?? f("pattern");
|
|
282
|
+
}
|
|
283
|
+
case "email":
|
|
284
|
+
return typeof t == "string" && !se.test(t) ? e.message ?? f("email") : null;
|
|
285
|
+
case "compare": {
|
|
286
|
+
const o = s == null ? void 0 : s[e.field ?? ""];
|
|
287
|
+
if (o === void 0 || F(o)) return null;
|
|
288
|
+
const i = w(t, o);
|
|
289
|
+
if (i === null) return null;
|
|
290
|
+
const a = e.op ?? "eq";
|
|
291
|
+
if (a === "eq" ? i === 0 : a === "ne" ? i !== 0 : a === "gt" ? i > 0 : a === "gte" ? i >= 0 : a === "lt" ? i < 0 : i <= 0) return null;
|
|
292
|
+
const p = `compare${a[0].toUpperCase()}${a.slice(1)}`;
|
|
293
|
+
return e.message ?? f(p, { other: e.field });
|
|
294
|
+
}
|
|
295
|
+
case "custom": {
|
|
296
|
+
const o = (r = n == null ? void 0 : n.validators) == null ? void 0 : r[e.fn ?? ""];
|
|
297
|
+
if (!o)
|
|
298
|
+
return console.warn(`[bahtui] unknown custom validator "${e.fn}" — skipped`), null;
|
|
299
|
+
const i = o(t);
|
|
300
|
+
return i === null ? null : e.message ?? i;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function ae(e, t, n, s) {
|
|
305
|
+
const r = [], o = oe(e), i = F(t);
|
|
306
|
+
for (const a of o) {
|
|
307
|
+
if (a.type !== "required" && i) continue;
|
|
308
|
+
const d = ie(a, t, n, s);
|
|
309
|
+
d !== null && r.push({ key: e.key, message: d });
|
|
310
|
+
}
|
|
311
|
+
return e.type === "repeater" && r.push(...me(e, t, n)), e.type === "file" && r.push(...fe(e, t)), e.type === "date" && !i && r.push(...ue(e, t)), r;
|
|
312
|
+
}
|
|
313
|
+
function ue(e, t) {
|
|
314
|
+
var s, r;
|
|
315
|
+
if (!((s = e.disabledDates) != null && s.length) && !((r = e.disabledWeekdays) != null && r.length)) return [];
|
|
316
|
+
const n = ee(t);
|
|
317
|
+
return Z(e) === "range" && n.length === 2 && n.push(...re(n[0], n[1])), n.some((o) => ne(e, o)) ? [{ key: e.key, message: f("dateDisabled") }] : [];
|
|
318
|
+
}
|
|
319
|
+
function ce(e) {
|
|
320
|
+
return e !== null && typeof e == "object" && typeof e.url == "string" && typeof e.size == "number" && typeof e.name == "string";
|
|
321
|
+
}
|
|
322
|
+
function le(e, t, n) {
|
|
323
|
+
return e.split(",").some((s) => {
|
|
324
|
+
const r = s.trim().toLowerCase();
|
|
325
|
+
return r ? r.startsWith(".") ? t.toLowerCase().endsWith(r) : r.endsWith("/*") ? n.toLowerCase().startsWith(r.slice(0, -1)) : n.toLowerCase() === r : !1;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function fe(e, t) {
|
|
329
|
+
const n = (Array.isArray(t) ? t : [t]).filter(ce), s = [];
|
|
330
|
+
for (const r of n)
|
|
331
|
+
e.maxSize !== void 0 && r.size > e.maxSize && s.push({ key: e.key, message: f("fileTooLarge") }), e.accept && !le(e.accept, r.name ?? "", r.type ?? "") && s.push({ key: e.key, message: f("fileTypeNotAllowed") });
|
|
332
|
+
return s;
|
|
333
|
+
}
|
|
334
|
+
function me(e, t, n) {
|
|
335
|
+
if (t != null && !Array.isArray(t))
|
|
336
|
+
return [{ key: e.key, message: f("pattern") }];
|
|
337
|
+
const s = Array.isArray(t) ? t : [], r = [];
|
|
338
|
+
e.minRows !== void 0 && s.length < e.minRows && r.push({ key: e.key, message: f("minRows", { n: e.minRows }) }), e.maxRows !== void 0 && s.length > e.maxRows && r.push({ key: e.key, message: f("maxRows", { n: e.maxRows }) });
|
|
339
|
+
const o = [...e.fields ?? []].sort((i, a) => i.order - a.order);
|
|
340
|
+
return s.forEach((i, a) => {
|
|
341
|
+
const d = i !== null && typeof i == "object" && !Array.isArray(i) ? i : {}, p = {};
|
|
342
|
+
for (const u of o)
|
|
343
|
+
u.type === "label" || u.type === "section" || u.type === "repeater" || (p[u.key] = Object.hasOwn(d, u.key) ? d[u.key] : D(u));
|
|
344
|
+
for (const u of o)
|
|
345
|
+
if (!(u.type === "label" || u.type === "section" || u.type === "repeater"))
|
|
346
|
+
for (const y of ae(u, p[u.key], n, p))
|
|
347
|
+
r.push({ key: `${e.key}[${a}].${y.key}`, message: y.message });
|
|
348
|
+
}), r;
|
|
349
|
+
}
|
|
350
|
+
function Se(e, t) {
|
|
351
|
+
var r;
|
|
352
|
+
if (!t) return [...e.field_data].sort((o, i) => o.order - i.order);
|
|
353
|
+
const n = (r = e.views) == null ? void 0 : r.find((o) => o.name === t);
|
|
354
|
+
if (!n) return null;
|
|
355
|
+
const s = new Map(e.field_data.map((o) => [o.key, o]));
|
|
356
|
+
return n.fields.map((o) => s.get(o)).filter((o) => o !== void 0);
|
|
357
|
+
}
|
|
358
|
+
function S(e, t) {
|
|
359
|
+
return e ? e.startsWith("!") ? t[e.slice(1)] !== !0 : t[e] === !0 : !0;
|
|
360
|
+
}
|
|
361
|
+
function G(e, t) {
|
|
362
|
+
return e.filter((n) => S(n.flag, t)).map((n) => n.fields ? { ...n, fields: G(n.fields, t) } : n);
|
|
363
|
+
}
|
|
364
|
+
function E(e) {
|
|
365
|
+
return e.some((t) => t.flag !== void 0 || (t.fields ? E(t.fields) : !1));
|
|
366
|
+
}
|
|
367
|
+
function T(e, t) {
|
|
368
|
+
if (!E(e.field_data)) return e;
|
|
369
|
+
const n = G(e.field_data, t), s = new Set(n.map((r) => r.key));
|
|
370
|
+
return {
|
|
371
|
+
...e,
|
|
372
|
+
field_data: n,
|
|
373
|
+
...e.views ? { views: e.views.map((r) => ({ ...r, fields: r.fields.filter((o) => s.has(o)) })) } : {}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function Le(e, t = {}) {
|
|
377
|
+
if ("workflowId" in e) {
|
|
378
|
+
const n = e;
|
|
379
|
+
return n.forms.some((r) => r.flag !== void 0 || E(r.field_data)) || n.rules.some((r) => r.flag !== void 0) || (n.transitions ?? []).some((r) => r.flag !== void 0) ? {
|
|
380
|
+
...n,
|
|
381
|
+
forms: n.forms.filter((r) => S(r.flag, t)).map((r) => T(r, t)),
|
|
382
|
+
rules: n.rules.filter((r) => S(r.flag, t)),
|
|
383
|
+
...n.transitions ? { transitions: n.transitions.filter((r) => S(r.flag, t)) } : {}
|
|
384
|
+
} : e;
|
|
385
|
+
}
|
|
386
|
+
return T(e, t);
|
|
387
|
+
}
|
|
388
|
+
function de(e) {
|
|
389
|
+
if (e == null || e === "") return null;
|
|
390
|
+
const t = Number(e);
|
|
391
|
+
return Number.isNaN(t) ? null : t;
|
|
392
|
+
}
|
|
393
|
+
function L(e) {
|
|
394
|
+
return typeof e == "number" && Number.isNaN(e) ? null : e;
|
|
395
|
+
}
|
|
396
|
+
function $(e, t) {
|
|
397
|
+
if ("ref" in e) return q(t, e.ref);
|
|
398
|
+
if ("const" in e) return e.const;
|
|
399
|
+
if ("if" in e) {
|
|
400
|
+
const [s, r, o] = e.if;
|
|
401
|
+
return x(s, t) ? L($(r, t)) : L($(o, t));
|
|
402
|
+
}
|
|
403
|
+
const n = e.args.map((s) => L($(s, t)));
|
|
404
|
+
switch (e.op) {
|
|
405
|
+
case "concat":
|
|
406
|
+
return n.map((s) => s == null ? "" : String(s)).join("");
|
|
407
|
+
case "coalesce":
|
|
408
|
+
return n.find((s) => s != null) ?? null;
|
|
409
|
+
case "add":
|
|
410
|
+
case "sub":
|
|
411
|
+
case "mul":
|
|
412
|
+
case "div": {
|
|
413
|
+
const s = n.map(de);
|
|
414
|
+
return s.length === 0 || s.some((r) => r === null) ? null : s.reduce((r, o, i) => {
|
|
415
|
+
if (i === 0) return o;
|
|
416
|
+
switch (e.op) {
|
|
417
|
+
case "add":
|
|
418
|
+
return r + o;
|
|
419
|
+
case "sub":
|
|
420
|
+
return r - o;
|
|
421
|
+
case "mul":
|
|
422
|
+
return r * o;
|
|
423
|
+
default:
|
|
424
|
+
return o === 0 ? NaN : r / o;
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function pe(e, t) {
|
|
431
|
+
return L($(e, t));
|
|
432
|
+
}
|
|
433
|
+
const V = 20, _ = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
434
|
+
function I(e, t) {
|
|
435
|
+
return e !== null && typeof e == "object" && Object.hasOwn(e, t) ? e[t] : void 0;
|
|
436
|
+
}
|
|
437
|
+
function O(e, t) {
|
|
438
|
+
if (e === t) return !0;
|
|
439
|
+
if (Array.isArray(e) && Array.isArray(t))
|
|
440
|
+
return e.length === t.length && e.every((n, s) => O(n, t[s]));
|
|
441
|
+
if (e !== null && t !== null && typeof e == "object" && typeof t == "object" && Object.getPrototypeOf(e) === Object.prototype && Object.getPrototypeOf(t) === Object.prototype) {
|
|
442
|
+
const n = Object.keys(e), s = Object.keys(t);
|
|
443
|
+
return n.length === s.length && n.every((r) => O(e[r], t[r]));
|
|
444
|
+
}
|
|
445
|
+
return !1;
|
|
446
|
+
}
|
|
447
|
+
function ye(e) {
|
|
448
|
+
let t;
|
|
449
|
+
for (const n of e)
|
|
450
|
+
(!t || n.priority > t.priority || n.priority === t.priority && n.index >= t.index) && (t = n);
|
|
451
|
+
return t == null ? void 0 : t.action;
|
|
452
|
+
}
|
|
453
|
+
function he(e, t) {
|
|
454
|
+
const n = [], s = /* @__PURE__ */ new Map(), r = [];
|
|
455
|
+
let o = {};
|
|
456
|
+
for (const u of e.forms) {
|
|
457
|
+
if (_.has(u.formName)) {
|
|
458
|
+
n.push({ ref: u.formName, message: "unsafe form name", kind: "schema" });
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
r.push(u.formName);
|
|
462
|
+
const y = {}, N = I(t, u.formName);
|
|
463
|
+
for (const m of [...u.field_data, ...B(u)]) {
|
|
464
|
+
if (m.type === "label" || m.type === "section") continue;
|
|
465
|
+
if (_.has(m.key)) {
|
|
466
|
+
n.push({
|
|
467
|
+
ref: `${u.formName}.${m.key}`,
|
|
468
|
+
message: "unsafe field key",
|
|
469
|
+
kind: "schema"
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
s.set(`${u.formName}.${m.key}`, m);
|
|
474
|
+
const c = I(N, m.key);
|
|
475
|
+
y[m.key] = c !== void 0 ? c : D(m);
|
|
476
|
+
}
|
|
477
|
+
o[u.formName] = y;
|
|
478
|
+
}
|
|
479
|
+
let i = {}, a = {}, d = !1;
|
|
480
|
+
for (let u = 0; u < V; u++) {
|
|
481
|
+
i = {}, a = {};
|
|
482
|
+
for (const c of r) a[c] = { visible: !0 };
|
|
483
|
+
for (const [c, h] of s)
|
|
484
|
+
i[c] = {
|
|
485
|
+
visible: !0,
|
|
486
|
+
enabled: !h.disabled,
|
|
487
|
+
readonly: !!h.readonly,
|
|
488
|
+
required: !!h.required,
|
|
489
|
+
computed: !1
|
|
490
|
+
};
|
|
491
|
+
const y = /* @__PURE__ */ new Map();
|
|
492
|
+
e.rules.forEach((c, h) => {
|
|
493
|
+
const l = x(c.when, o) ? c.then : c.else;
|
|
494
|
+
if (!l) return;
|
|
495
|
+
const k = c.priority ?? 0;
|
|
496
|
+
for (const g of l) {
|
|
497
|
+
const b = ge(g), v = y.get(b) ?? [];
|
|
498
|
+
v.push({ action: g, priority: k, index: h }), y.set(b, v);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
const N = [];
|
|
502
|
+
for (const [c, h] of y) {
|
|
503
|
+
const l = ye(h);
|
|
504
|
+
if (!l) continue;
|
|
505
|
+
if (l.action === "setValue") {
|
|
506
|
+
N.push({ ref: `${l.target.form}.${l.target.field}`, action: l });
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (l.action === "showForm" || l.action === "hideForm" || l.action === "skipForm") {
|
|
510
|
+
const v = a[l.target.form];
|
|
511
|
+
if (!v) {
|
|
512
|
+
n.push({
|
|
513
|
+
ref: l.target.form,
|
|
514
|
+
message: `rule targets unknown form (${c})`,
|
|
515
|
+
kind: "schema"
|
|
516
|
+
});
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
v.visible = l.action === "showForm";
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const k = l.target, g = `${k.form}.${k.field}`, b = i[g];
|
|
523
|
+
if (!b) {
|
|
524
|
+
n.push({ ref: g, message: "rule targets unknown field", kind: "schema" });
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
switch (l.action) {
|
|
528
|
+
case "show":
|
|
529
|
+
b.visible = !0;
|
|
530
|
+
break;
|
|
531
|
+
case "hide":
|
|
532
|
+
b.visible = !1;
|
|
533
|
+
break;
|
|
534
|
+
case "enable":
|
|
535
|
+
b.enabled = !0;
|
|
536
|
+
break;
|
|
537
|
+
case "disable":
|
|
538
|
+
b.enabled = !1;
|
|
539
|
+
break;
|
|
540
|
+
case "readonly":
|
|
541
|
+
b.readonly = !0;
|
|
542
|
+
break;
|
|
543
|
+
case "required":
|
|
544
|
+
b.required = !0;
|
|
545
|
+
break;
|
|
546
|
+
case "optional":
|
|
547
|
+
b.required = !1;
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
const m = {};
|
|
552
|
+
for (const c of r) m[c] = { ...o[c] };
|
|
553
|
+
for (const [c, h] of s) {
|
|
554
|
+
const [l, k] = C(c);
|
|
555
|
+
(!a[l].visible || !i[c].visible) && (m[l][k] = D(h));
|
|
556
|
+
}
|
|
557
|
+
for (const { ref: c, action: h } of N) {
|
|
558
|
+
const [l, k] = C(c), g = i[c];
|
|
559
|
+
if (!g) {
|
|
560
|
+
n.push({ ref: c, message: "setValue targets unknown field", kind: "schema" });
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
!a[l].visible || !g.visible || (m[l][k] = pe(h.value, m), h.lock !== !1 && (g.readonly = !0, g.computed = !0));
|
|
564
|
+
}
|
|
565
|
+
if (O(m, o)) {
|
|
566
|
+
d = !0, o = m;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
o = m;
|
|
570
|
+
}
|
|
571
|
+
d || n.push({
|
|
572
|
+
ref: e.workflowId,
|
|
573
|
+
message: `rules did not converge within ${V} passes (cycle?)`,
|
|
574
|
+
kind: "data"
|
|
575
|
+
});
|
|
576
|
+
const p = {};
|
|
577
|
+
for (const u of r) {
|
|
578
|
+
if (!a[u].visible) continue;
|
|
579
|
+
const y = {};
|
|
580
|
+
for (const [N, m] of Object.entries(o[u]))
|
|
581
|
+
i[`${u}.${N}`].visible && (y[N] = m);
|
|
582
|
+
p[u] = y;
|
|
583
|
+
}
|
|
584
|
+
return { data: p, fields: i, forms: a, errors: n };
|
|
585
|
+
}
|
|
586
|
+
function ge(e) {
|
|
587
|
+
const t = e.action === "show" || e.action === "hide" ? "visible" : e.action === "enable" || e.action === "disable" ? "enabled" : e.action === "required" || e.action === "optional" ? "required" : e.action === "showForm" || e.action === "hideForm" || e.action === "skipForm" ? "formVisible" : e.action, n = "field" in e.target ? `${e.target.form}.${e.target.field}` : e.target.form;
|
|
588
|
+
return `${t}:${n}`;
|
|
589
|
+
}
|
|
590
|
+
function C(e) {
|
|
591
|
+
const t = e.indexOf(".");
|
|
592
|
+
return [e.slice(0, t), e.slice(t + 1)];
|
|
593
|
+
}
|
|
594
|
+
function P(e, t) {
|
|
595
|
+
const n = he(e, t);
|
|
596
|
+
return new Set(
|
|
597
|
+
e.forms.filter((s) => {
|
|
598
|
+
var r;
|
|
599
|
+
return ((r = n.forms[s.formName]) == null ? void 0 : r.visible) !== !1;
|
|
600
|
+
}).map((s) => s.formName)
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
function W(e, t, n) {
|
|
604
|
+
for (const o of e.transitions ?? [])
|
|
605
|
+
if (o.from === t && x(o.when, n))
|
|
606
|
+
return o.to;
|
|
607
|
+
const s = [...e.forms].sort((o, i) => o.order - i.order), r = s.findIndex((o) => o.formName === t);
|
|
608
|
+
return r >= 0 && r + 1 < s.length ? s[r + 1].formName : "end";
|
|
609
|
+
}
|
|
610
|
+
function be(e, t, n, s) {
|
|
611
|
+
const r = s ?? P(e, n), o = /* @__PURE__ */ new Set([t]);
|
|
612
|
+
let i = W(e, t, n);
|
|
613
|
+
for (; i !== "end" && !r.has(i); ) {
|
|
614
|
+
if (o.has(i)) return "end";
|
|
615
|
+
o.add(i), i = W(e, i, n);
|
|
616
|
+
}
|
|
617
|
+
return i;
|
|
618
|
+
}
|
|
619
|
+
function $e(e, t) {
|
|
620
|
+
var d;
|
|
621
|
+
const n = P(e, t), r = (d = [...e.forms].sort((p, u) => p.order - u.order).find((p) => n.has(p.formName))) == null ? void 0 : d.formName;
|
|
622
|
+
if (!r) return [];
|
|
623
|
+
const o = [], i = /* @__PURE__ */ new Set();
|
|
624
|
+
let a = r;
|
|
625
|
+
for (; a !== "end" && !i.has(a); )
|
|
626
|
+
i.add(a), o.push(a), a = be(e, a, t, n);
|
|
627
|
+
return o;
|
|
628
|
+
}
|
|
629
|
+
const ke = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, U = (e, t) => {
|
|
630
|
+
const n = e == null ? void 0 : e.find((s) => s.key === String(t));
|
|
631
|
+
return n ? n.label : String(t);
|
|
632
|
+
}, Ne = (e) => e && typeof e == "object" && "name" in e ? String(e.name) : String(e), z = (e) => {
|
|
633
|
+
const t = new Date(e);
|
|
634
|
+
return Number.isNaN(t.getTime()) ? e : /^\d{4}-\d{2}-\d{2}$/.test(e) ? (/* @__PURE__ */ new Date(e + "T00:00:00")).toLocaleDateString() : t.toLocaleString();
|
|
635
|
+
};
|
|
636
|
+
function we(e, t, n = e.options) {
|
|
637
|
+
if (ke(t)) return { kind: "empty" };
|
|
638
|
+
switch (e.type) {
|
|
639
|
+
case "checkbox":
|
|
640
|
+
case "toggle":
|
|
641
|
+
return { kind: "text", text: f(t ? "yes" : "no") };
|
|
642
|
+
case "dropdown":
|
|
643
|
+
case "radio":
|
|
644
|
+
return { kind: "text", text: U(n, t) };
|
|
645
|
+
case "multiselect":
|
|
646
|
+
return { kind: "chips", items: (Array.isArray(t) ? t : [t]).map((r) => U(n, r)) };
|
|
647
|
+
case "date": {
|
|
648
|
+
if (!Array.isArray(t)) return { kind: "text", text: z(String(t)) };
|
|
649
|
+
const s = t.map((r) => z(String(r)));
|
|
650
|
+
return e.dateMode === "range" && s.length === 2 ? { kind: "text", text: `${s[0]} – ${s[1]}` } : { kind: "chips", items: s };
|
|
651
|
+
}
|
|
652
|
+
case "file":
|
|
653
|
+
return { kind: "chips", items: (Array.isArray(t) ? t : [t]).map(Ne) };
|
|
654
|
+
case "repeater": {
|
|
655
|
+
const s = Array.isArray(t) ? t : [], r = e.fields ?? [];
|
|
656
|
+
return {
|
|
657
|
+
kind: "rows",
|
|
658
|
+
rows: s.map(
|
|
659
|
+
(o) => r.filter((i) => i.type !== "label" && i.type !== "section").map((i) => {
|
|
660
|
+
const a = we(i, o == null ? void 0 : o[i.key]), d = a.kind === "text" ? a.text : a.kind === "chips" ? a.items.join(", ") : a.kind === "rows" ? f("rowCount", { n: a.rows.length }) : f("emptyValue");
|
|
661
|
+
return { label: i.label ?? i.key, text: d };
|
|
662
|
+
})
|
|
663
|
+
)
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
default:
|
|
667
|
+
return { kind: "text", text: String(t) };
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
export {
|
|
671
|
+
te as a,
|
|
672
|
+
D as b,
|
|
673
|
+
Le as c,
|
|
674
|
+
Z as d,
|
|
675
|
+
we as e,
|
|
676
|
+
Q as f,
|
|
677
|
+
he as g,
|
|
678
|
+
be as h,
|
|
679
|
+
ee as i,
|
|
680
|
+
B as j,
|
|
681
|
+
x as k,
|
|
682
|
+
pe as l,
|
|
683
|
+
S as m,
|
|
684
|
+
Ae as n,
|
|
685
|
+
ne as o,
|
|
686
|
+
A as p,
|
|
687
|
+
q,
|
|
688
|
+
Se as r,
|
|
689
|
+
ve as s,
|
|
690
|
+
f as t,
|
|
691
|
+
xe as u,
|
|
692
|
+
ae as v,
|
|
693
|
+
$e as w
|
|
694
|
+
};
|