bank20baht-ui 0.0.1
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/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/chunks/baht-toast-BlZBbneT.js +324 -0
- package/dist/components/baht-form.d.ts +41 -0
- package/dist/components/baht-workflow.d.ts +64 -0
- package/dist/components/base.d.ts +38 -0
- package/dist/components/primitives/baht-accordion.d.ts +26 -0
- package/dist/components/primitives/baht-alert.d.ts +17 -0
- package/dist/components/primitives/baht-badge.d.ts +19 -0
- package/dist/components/primitives/baht-breadcrumbs.d.ts +22 -0
- package/dist/components/primitives/baht-button.d.ts +31 -0
- package/dist/components/primitives/baht-card.d.ts +18 -0
- package/dist/components/primitives/baht-checkbox.d.ts +7 -0
- package/dist/components/primitives/baht-code.d.ts +18 -0
- package/dist/components/primitives/baht-datepicker.d.ts +6 -0
- package/dist/components/primitives/baht-fieldset.d.ts +17 -0
- package/dist/components/primitives/baht-file.d.ts +9 -0
- package/dist/components/primitives/baht-filter.d.ts +24 -0
- package/dist/components/primitives/baht-input.d.ts +6 -0
- package/dist/components/primitives/baht-link.d.ts +17 -0
- package/dist/components/primitives/baht-list.d.ts +28 -0
- package/dist/components/primitives/baht-modal.d.ts +32 -0
- package/dist/components/primitives/baht-multiselect.d.ts +8 -0
- package/dist/components/primitives/baht-number.d.ts +5 -0
- package/dist/components/primitives/baht-otp.d.ts +26 -0
- package/dist/components/primitives/baht-pagination.d.ts +21 -0
- package/dist/components/primitives/baht-progress.d.ts +16 -0
- package/dist/components/primitives/baht-radio.d.ts +5 -0
- package/dist/components/primitives/baht-range.d.ts +21 -0
- package/dist/components/primitives/baht-rating.d.ts +22 -0
- package/dist/components/primitives/baht-select.d.ts +5 -0
- package/dist/components/primitives/baht-skeleton.d.ts +16 -0
- package/dist/components/primitives/baht-spinner.d.ts +13 -0
- package/dist/components/primitives/baht-table.d.ts +44 -0
- package/dist/components/primitives/baht-text.d.ts +8 -0
- package/dist/components/primitives/baht-textarea.d.ts +5 -0
- package/dist/components/primitives/baht-timeline.d.ts +21 -0
- package/dist/components/primitives/baht-toast.d.ts +27 -0
- package/dist/components/primitives/baht-toggle.d.ts +6 -0
- package/dist/components/primitives/baht-tooltip.d.ts +29 -0
- package/dist/components/primitives/icons.d.ts +13 -0
- package/dist/components/primitives/index.d.ts +38 -0
- package/dist/core/approval.d.ts +9 -0
- package/dist/core/defaults.d.ts +6 -0
- package/dist/core/engine/conditions.d.ts +4 -0
- package/dist/core/engine/evaluate.d.ts +8 -0
- package/dist/core/engine/expressions.d.ts +3 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/types.d.ts +166 -0
- package/dist/core/validators.d.ts +6 -0
- package/dist/custom-elements.json +7761 -0
- package/dist/engine.js +329 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1796 -0
- package/dist/overlay.d.ts +45 -0
- package/dist/overlay.js +121 -0
- package/dist/react.d.ts +191 -0
- package/dist/react.js +1 -0
- package/dist/tokens.css +936 -0
- package/dist/vscode.css-custom-data.json +6 -0
- package/dist/vscode.html-custom-data.json +479 -0
- package/dist/web-types.json +1226 -0
- package/package.json +94 -0
package/dist/engine.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
function F(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
|
+
return [];
|
|
9
|
+
case "file":
|
|
10
|
+
return e.multiple ? [] : null;
|
|
11
|
+
case "label":
|
|
12
|
+
return;
|
|
13
|
+
// static block, no value
|
|
14
|
+
default:
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function S(e) {
|
|
19
|
+
if (e.kind !== "approval") return [];
|
|
20
|
+
const t = (n) => e.field_data.some((s) => s.key === n), r = [];
|
|
21
|
+
return t("decision") || r.push({ order: 9001, type: "text", key: "decision", label: "Decision" }), t("comment") || r.push({ order: 9002, type: "textarea", key: "comment", label: "Comment" }), r;
|
|
22
|
+
}
|
|
23
|
+
const M = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
24
|
+
function j(e) {
|
|
25
|
+
return e == null ? !0 : typeof e == "string" ? e === "" : Array.isArray(e) ? e.length === 0 : typeof e == "boolean" ? e === !1 : !1;
|
|
26
|
+
}
|
|
27
|
+
function V(e) {
|
|
28
|
+
const t = [...e.validators ?? []], r = (n) => t.some((s) => s.type === n);
|
|
29
|
+
return e.required && !r("required") && t.push({ type: "required" }), e.maxLength !== void 0 && !r("maxLength") && t.push({ type: "maxLength", value: e.maxLength }), e.minLength !== void 0 && !r("minLength") && t.push({ type: "minLength", value: e.minLength }), e.min !== void 0 && !r("min") && t.push({ type: "min", value: e.min }), e.max !== void 0 && !r("max") && t.push({ type: "max", value: e.max }), e.type === "email" && !r("email") && t.push({ type: "email" }), t;
|
|
30
|
+
}
|
|
31
|
+
function D(e, t, r) {
|
|
32
|
+
var n;
|
|
33
|
+
switch (e.type) {
|
|
34
|
+
case "required":
|
|
35
|
+
return j(t) ? e.message ?? "This field is required" : null;
|
|
36
|
+
case "minLength":
|
|
37
|
+
return typeof t == "string" && t.length < Number(e.value) ? e.message ?? `Must be at least ${e.value} characters` : null;
|
|
38
|
+
case "maxLength":
|
|
39
|
+
return typeof t == "string" && t.length > Number(e.value) ? e.message ?? `Must be at most ${e.value} characters` : null;
|
|
40
|
+
case "min": {
|
|
41
|
+
const s = Number(t);
|
|
42
|
+
return !Number.isNaN(s) && s < Number(e.value) ? e.message ?? `Must be at least ${e.value}` : null;
|
|
43
|
+
}
|
|
44
|
+
case "max": {
|
|
45
|
+
const s = Number(t);
|
|
46
|
+
return !Number.isNaN(s) && s > Number(e.value) ? e.message ?? `Must be at most ${e.value}` : null;
|
|
47
|
+
}
|
|
48
|
+
case "pattern":
|
|
49
|
+
return typeof t == "string" && !new RegExp(String(e.value)).test(t) ? e.message ?? "Invalid format" : null;
|
|
50
|
+
case "email":
|
|
51
|
+
return typeof t == "string" && !M.test(t) ? e.message ?? "Invalid email address" : null;
|
|
52
|
+
case "custom": {
|
|
53
|
+
const s = (n = r == null ? void 0 : r.validators) == null ? void 0 : n[e.fn ?? ""];
|
|
54
|
+
if (!s)
|
|
55
|
+
return console.warn(`[bahtui] unknown custom validator "${e.fn}" — skipped`), null;
|
|
56
|
+
const i = s(t);
|
|
57
|
+
return i === null ? null : e.message ?? i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function C(e, t, r) {
|
|
62
|
+
const n = [], s = V(e), i = j(t);
|
|
63
|
+
for (const l of s) {
|
|
64
|
+
if (l.type !== "required" && i) continue;
|
|
65
|
+
const g = D(l, t, r);
|
|
66
|
+
g !== null && n.push({ key: e.key, message: g });
|
|
67
|
+
}
|
|
68
|
+
return n;
|
|
69
|
+
}
|
|
70
|
+
function w(e, t) {
|
|
71
|
+
var n;
|
|
72
|
+
const r = t.indexOf(".");
|
|
73
|
+
if (r !== -1)
|
|
74
|
+
return (n = e[t.slice(0, r)]) == null ? void 0 : n[t.slice(r + 1)];
|
|
75
|
+
}
|
|
76
|
+
function L(e) {
|
|
77
|
+
return e == null ? !0 : typeof e == "string" ? e === "" : Array.isArray(e) ? e.length === 0 : !1;
|
|
78
|
+
}
|
|
79
|
+
function v(e, t) {
|
|
80
|
+
if (typeof e == "number" && typeof t == "number") return e - t;
|
|
81
|
+
if (e instanceof Date || t instanceof Date) {
|
|
82
|
+
const s = new Date(e).getTime(), i = new Date(t).getTime();
|
|
83
|
+
return Number.isNaN(s) || Number.isNaN(i) ? null : s - i;
|
|
84
|
+
}
|
|
85
|
+
if (typeof e == "string" && typeof t == "string") {
|
|
86
|
+
const s = Number(e), i = Number(t);
|
|
87
|
+
return e !== "" && t !== "" && !Number.isNaN(s) && !Number.isNaN(i) ? s - i : e < t ? -1 : e > t ? 1 : 0;
|
|
88
|
+
}
|
|
89
|
+
const r = Number(e), n = Number(t);
|
|
90
|
+
return Number.isNaN(r) || Number.isNaN(n) ? null : r - n;
|
|
91
|
+
}
|
|
92
|
+
function I(e, t) {
|
|
93
|
+
const r = w(t, e.field), n = e.valueField !== void 0 ? w(t, e.valueField) : e.value;
|
|
94
|
+
switch (e.op) {
|
|
95
|
+
case "eq":
|
|
96
|
+
return r === n;
|
|
97
|
+
case "ne":
|
|
98
|
+
return r !== n;
|
|
99
|
+
case "gt": {
|
|
100
|
+
const s = v(r, n);
|
|
101
|
+
return s !== null && s > 0;
|
|
102
|
+
}
|
|
103
|
+
case "gte": {
|
|
104
|
+
const s = v(r, n);
|
|
105
|
+
return s !== null && s >= 0;
|
|
106
|
+
}
|
|
107
|
+
case "lt": {
|
|
108
|
+
const s = v(r, n);
|
|
109
|
+
return s !== null && s < 0;
|
|
110
|
+
}
|
|
111
|
+
case "lte": {
|
|
112
|
+
const s = v(r, n);
|
|
113
|
+
return s !== null && s <= 0;
|
|
114
|
+
}
|
|
115
|
+
case "in":
|
|
116
|
+
return Array.isArray(n) && n.includes(r);
|
|
117
|
+
case "notIn":
|
|
118
|
+
return Array.isArray(n) && !n.includes(r);
|
|
119
|
+
case "contains":
|
|
120
|
+
return Array.isArray(r) ? r.includes(n) : typeof r == "string" && r.includes(String(n));
|
|
121
|
+
case "notContains":
|
|
122
|
+
return Array.isArray(r) ? !r.includes(n) : typeof r == "string" && !r.includes(String(n));
|
|
123
|
+
case "startsWith":
|
|
124
|
+
return typeof r == "string" && r.startsWith(String(n));
|
|
125
|
+
case "endsWith":
|
|
126
|
+
return typeof r == "string" && r.endsWith(String(n));
|
|
127
|
+
case "isEmpty":
|
|
128
|
+
return L(r);
|
|
129
|
+
case "isNotEmpty":
|
|
130
|
+
return !L(r);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function N(e, t) {
|
|
134
|
+
return e === void 0 ? !0 : "and" in e ? e.and.every((r) => N(r, t)) : "or" in e ? e.or.some((r) => N(r, t)) : "not" in e ? !N(e.not, t) : I(e, t);
|
|
135
|
+
}
|
|
136
|
+
function R(e) {
|
|
137
|
+
if (e == null || e === "") return null;
|
|
138
|
+
const t = Number(e);
|
|
139
|
+
return Number.isNaN(t) ? null : t;
|
|
140
|
+
}
|
|
141
|
+
function k(e, t) {
|
|
142
|
+
if ("ref" in e) return w(t, e.ref);
|
|
143
|
+
if ("const" in e) return e.const;
|
|
144
|
+
if ("if" in e) {
|
|
145
|
+
const [n, s, i] = e.if;
|
|
146
|
+
return N(n, t) ? k(s, t) : k(i, t);
|
|
147
|
+
}
|
|
148
|
+
const r = e.args.map((n) => k(n, t));
|
|
149
|
+
switch (e.op) {
|
|
150
|
+
case "concat":
|
|
151
|
+
return r.map((n) => n == null ? "" : String(n)).join("");
|
|
152
|
+
case "coalesce":
|
|
153
|
+
return r.find((n) => n != null) ?? null;
|
|
154
|
+
case "add":
|
|
155
|
+
case "sub":
|
|
156
|
+
case "mul":
|
|
157
|
+
case "div": {
|
|
158
|
+
const n = r.map(R);
|
|
159
|
+
return n.some((s) => s === null) ? null : n.reduce((s, i, l) => {
|
|
160
|
+
if (l === 0) return i;
|
|
161
|
+
switch (e.op) {
|
|
162
|
+
case "add":
|
|
163
|
+
return s + i;
|
|
164
|
+
case "sub":
|
|
165
|
+
return s - i;
|
|
166
|
+
case "mul":
|
|
167
|
+
return s * i;
|
|
168
|
+
default:
|
|
169
|
+
return i === 0 ? NaN : s / i;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function T(e, t) {
|
|
176
|
+
const r = k(e, t);
|
|
177
|
+
return typeof r == "number" && Number.isNaN(r) ? null : r;
|
|
178
|
+
}
|
|
179
|
+
const E = 20;
|
|
180
|
+
function $(e, t) {
|
|
181
|
+
if (e === t) return !0;
|
|
182
|
+
if (Array.isArray(e) && Array.isArray(t))
|
|
183
|
+
return e.length === t.length && e.every((r, n) => $(r, t[n]));
|
|
184
|
+
if (e !== null && t !== null && typeof e == "object" && typeof t == "object" && Object.getPrototypeOf(e) === Object.prototype && Object.getPrototypeOf(t) === Object.prototype) {
|
|
185
|
+
const r = Object.keys(e), n = Object.keys(t);
|
|
186
|
+
return r.length === n.length && r.every((s) => $(e[s], t[s]));
|
|
187
|
+
}
|
|
188
|
+
return !1;
|
|
189
|
+
}
|
|
190
|
+
function W(e) {
|
|
191
|
+
let t;
|
|
192
|
+
for (const r of e)
|
|
193
|
+
(!t || r.priority > t.priority || r.priority === t.priority && r.index >= t.index) && (t = r);
|
|
194
|
+
return t == null ? void 0 : t.action;
|
|
195
|
+
}
|
|
196
|
+
function P(e, t) {
|
|
197
|
+
var x;
|
|
198
|
+
const r = [], n = /* @__PURE__ */ new Map(), s = [];
|
|
199
|
+
let i = {};
|
|
200
|
+
for (const a of e.forms) {
|
|
201
|
+
s.push(a.formName);
|
|
202
|
+
const p = {};
|
|
203
|
+
for (const c of [...a.field_data, ...S(a)]) {
|
|
204
|
+
if (c.type === "label") continue;
|
|
205
|
+
n.set(`${a.formName}.${c.key}`, c);
|
|
206
|
+
const f = (x = t[a.formName]) == null ? void 0 : x[c.key];
|
|
207
|
+
p[c.key] = f !== void 0 ? f : F(c);
|
|
208
|
+
}
|
|
209
|
+
i[a.formName] = p;
|
|
210
|
+
}
|
|
211
|
+
let l = {}, g = {}, A = !1;
|
|
212
|
+
for (let a = 0; a < E; a++) {
|
|
213
|
+
l = {}, g = {};
|
|
214
|
+
for (const u of s) g[u] = { visible: !0 };
|
|
215
|
+
for (const [u, m] of n)
|
|
216
|
+
l[u] = {
|
|
217
|
+
visible: !0,
|
|
218
|
+
enabled: !m.disabled,
|
|
219
|
+
readonly: !1,
|
|
220
|
+
required: !!m.required,
|
|
221
|
+
computed: !1
|
|
222
|
+
};
|
|
223
|
+
const p = /* @__PURE__ */ new Map();
|
|
224
|
+
e.rules.forEach((u, m) => {
|
|
225
|
+
const o = N(u.when, i) ? u.then : u.else;
|
|
226
|
+
if (!o) return;
|
|
227
|
+
const h = u.priority ?? 0;
|
|
228
|
+
for (const d of o) {
|
|
229
|
+
const y = _(d), b = p.get(y) ?? [];
|
|
230
|
+
b.push({ action: d, priority: h, index: m }), p.set(y, b);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const c = [];
|
|
234
|
+
for (const [u, m] of p) {
|
|
235
|
+
const o = W(m);
|
|
236
|
+
if (!o) continue;
|
|
237
|
+
if (o.action === "setValue") {
|
|
238
|
+
c.push({ ref: `${o.target.form}.${o.target.field}`, action: o });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (o.action === "showForm" || o.action === "hideForm" || o.action === "skipForm") {
|
|
242
|
+
const b = g[o.target.form];
|
|
243
|
+
if (!b) {
|
|
244
|
+
r.push({ ref: o.target.form, message: `rule targets unknown form (${u})` });
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
b.visible = o.action === "showForm";
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const h = o.target, d = `${h.form}.${h.field}`, y = l[d];
|
|
251
|
+
if (!y) {
|
|
252
|
+
r.push({ ref: d, message: "rule targets unknown field" });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
switch (o.action) {
|
|
256
|
+
case "show":
|
|
257
|
+
y.visible = !0;
|
|
258
|
+
break;
|
|
259
|
+
case "hide":
|
|
260
|
+
y.visible = !1;
|
|
261
|
+
break;
|
|
262
|
+
case "enable":
|
|
263
|
+
y.enabled = !0;
|
|
264
|
+
break;
|
|
265
|
+
case "disable":
|
|
266
|
+
y.enabled = !1;
|
|
267
|
+
break;
|
|
268
|
+
case "readonly":
|
|
269
|
+
y.readonly = !0;
|
|
270
|
+
break;
|
|
271
|
+
case "required":
|
|
272
|
+
y.required = !0;
|
|
273
|
+
break;
|
|
274
|
+
case "optional":
|
|
275
|
+
y.required = !1;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const f = {};
|
|
280
|
+
for (const u of s) f[u] = { ...i[u] };
|
|
281
|
+
for (const [u, m] of n) {
|
|
282
|
+
const [o, h] = O(u);
|
|
283
|
+
(!g[o].visible || !l[u].visible) && (f[o][h] = F(m));
|
|
284
|
+
}
|
|
285
|
+
for (const { ref: u, action: m } of c) {
|
|
286
|
+
const [o, h] = O(u), d = l[u];
|
|
287
|
+
if (!d) {
|
|
288
|
+
r.push({ ref: u, message: "setValue targets unknown field" });
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
!g[o].visible || !d.visible || (f[o][h] = T(m.value, f), m.lock !== !1 && (d.readonly = !0, d.computed = !0));
|
|
292
|
+
}
|
|
293
|
+
if ($(f, i)) {
|
|
294
|
+
A = !0, i = f;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
i = f;
|
|
298
|
+
}
|
|
299
|
+
A || r.push({
|
|
300
|
+
ref: e.workflowId,
|
|
301
|
+
message: `rules did not converge within ${E} passes (cycle?)`
|
|
302
|
+
});
|
|
303
|
+
const q = {};
|
|
304
|
+
for (const a of s) {
|
|
305
|
+
if (!g[a].visible) continue;
|
|
306
|
+
const p = {};
|
|
307
|
+
for (const [c, f] of Object.entries(i[a]))
|
|
308
|
+
l[`${a}.${c}`].visible && (p[c] = f);
|
|
309
|
+
q[a] = p;
|
|
310
|
+
}
|
|
311
|
+
return { data: q, fields: l, forms: g, errors: r };
|
|
312
|
+
}
|
|
313
|
+
function _(e) {
|
|
314
|
+
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, r = "field" in e.target ? `${e.target.form}.${e.target.field}` : e.target.form;
|
|
315
|
+
return `${t}:${r}`;
|
|
316
|
+
}
|
|
317
|
+
function O(e) {
|
|
318
|
+
const t = e.indexOf(".");
|
|
319
|
+
return [e.slice(0, t), e.slice(t + 1)];
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
S as approvalFields,
|
|
323
|
+
F as defaultValue,
|
|
324
|
+
N as evalCondition,
|
|
325
|
+
T as evalValueExpr,
|
|
326
|
+
P as evaluate,
|
|
327
|
+
w as readRef,
|
|
328
|
+
C as validateField
|
|
329
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './core/index.js';
|
|
2
|
+
export * from './components/primitives/index.js';
|
|
3
|
+
export { BahtElement, BahtFieldBase, adoptLightChildren } from './components/base.js';
|
|
4
|
+
export { BahtForm } from './components/baht-form.js';
|
|
5
|
+
export { BahtWorkflow } from './components/baht-workflow.js';
|