bank20baht-ui 0.3.1 → 0.4.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/dist/chunks/baht-workflow-CkbvfwES.js +4783 -0
- package/dist/components/primitives/baht-bar-chart.d.ts +55 -7
- package/dist/components/primitives/baht-donut-chart.d.ts +8 -6
- package/dist/components/primitives/baht-heatmap.d.ts +27 -0
- package/dist/components/primitives/baht-line-chart.d.ts +33 -0
- package/dist/components/primitives/baht-meter.d.ts +41 -0
- package/dist/components/primitives/baht-sparkline.d.ts +23 -0
- package/dist/components/primitives/baht-stat.d.ts +46 -0
- package/dist/components/primitives/charts.d.ts +105 -1
- package/dist/components/primitives/index.d.ts +6 -1
- package/dist/custom-elements.json +9709 -6274
- package/dist/index.js +81 -69
- package/dist/react.d.ts +70 -5
- package/dist/ssr.js +1 -1
- package/dist/tokens.css +486 -14
- package/dist/vscode.html-custom-data.json +334 -4
- package/dist/web-types.json +718 -6
- package/package.json +1 -1
- package/dist/chunks/baht-workflow-Gd0J8mGC.js +0 -3952
|
@@ -0,0 +1,4783 @@
|
|
|
1
|
+
import { nothing as h, html as n, svg as A } from "lit";
|
|
2
|
+
import { property as l, customElement as b, state as $, query as Bt } from "lit/decorators.js";
|
|
3
|
+
import { B as y, b as ne, h as S, a as J } from "./base-CajA2aCO.js";
|
|
4
|
+
import { t as m } from "./i18n-BcPL9_Jh.js";
|
|
5
|
+
import { n as $e, k as Lt, o as ds, i as Rt, p as us, d as se, a as rs, m as Ae, v as Le, c as bs, g as fs, l as ms } from "./display-DQRcvsn7.js";
|
|
6
|
+
import { repeat as Ce } from "lit/directives/repeat.js";
|
|
7
|
+
import { html as ee, unsafeStatic as os } from "lit/static-html.js";
|
|
8
|
+
import { c as vs, r as H } from "./baht-toast-CD1WrOYr.js";
|
|
9
|
+
import { live as ot } from "lit/directives/live.js";
|
|
10
|
+
import { ifDefined as L } from "lit/directives/if-defined.js";
|
|
11
|
+
import $s from "flatpickr";
|
|
12
|
+
var ys = Object.defineProperty, gs = Object.getOwnPropertyDescriptor, he = (t, e, i, a) => {
|
|
13
|
+
for (var s = a > 1 ? void 0 : a ? gs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
14
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
15
|
+
return a && s && ys(e, i, s), s;
|
|
16
|
+
};
|
|
17
|
+
let zt = class extends y {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments), this.tone = "neutral", this.label = "", this.dot = null;
|
|
20
|
+
}
|
|
21
|
+
get showDot() {
|
|
22
|
+
return this.dot !== null ? this.dot : ["neutral", "success", "danger", "warning", "info"].includes(this.tone);
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
const t = this.tone === "neutral" ? "" : ` baht-badge--${this.tone}`;
|
|
26
|
+
return n`<span class="baht-badge${t}">
|
|
27
|
+
${this.showDot ? n`<span class="baht-badge-dot" aria-hidden="true"></span>` : h}${this.label}
|
|
28
|
+
</span>`;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
he([
|
|
32
|
+
l()
|
|
33
|
+
], zt.prototype, "tone", 2);
|
|
34
|
+
he([
|
|
35
|
+
l()
|
|
36
|
+
], zt.prototype, "label", 2);
|
|
37
|
+
he([
|
|
38
|
+
l({ attribute: !1 })
|
|
39
|
+
], zt.prototype, "dot", 2);
|
|
40
|
+
zt = he([
|
|
41
|
+
b("baht-badge")
|
|
42
|
+
], zt);
|
|
43
|
+
var ws = Object.defineProperty, xs = Object.getOwnPropertyDescriptor, je = (t, e, i, a) => {
|
|
44
|
+
for (var s = a > 1 ? void 0 : a ? xs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
45
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
46
|
+
return a && s && ws(e, i, s), s;
|
|
47
|
+
};
|
|
48
|
+
let ae = class extends y {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments), this.variant = "inline", this.code = "";
|
|
51
|
+
}
|
|
52
|
+
firstUpdated() {
|
|
53
|
+
const t = this.renderRoot.querySelector(this.variant === "block" ? "pre" : "code");
|
|
54
|
+
t && ne(this, t);
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
return this.variant === "block" ? n`<pre class="baht-code baht-code--block" tabindex="0">${this.code}</pre>` : n`<code class="baht-code">${this.code}</code>`;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
je([
|
|
61
|
+
l()
|
|
62
|
+
], ae.prototype, "variant", 2);
|
|
63
|
+
je([
|
|
64
|
+
l()
|
|
65
|
+
], ae.prototype, "code", 2);
|
|
66
|
+
ae = je([
|
|
67
|
+
b("baht-code")
|
|
68
|
+
], ae);
|
|
69
|
+
var _s = Object.defineProperty, ks = Object.getOwnPropertyDescriptor, yt = (t, e, i, a) => {
|
|
70
|
+
for (var s = a > 1 ? void 0 : a ? ks(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
71
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
72
|
+
return a && s && _s(e, i, s), s;
|
|
73
|
+
};
|
|
74
|
+
let ht = class extends y {
|
|
75
|
+
constructor() {
|
|
76
|
+
super(...arguments), this.page = 1, this.totalPages = 1, this.variant = "numbered", this.siblings = 1, this.hasNext = !1, this.hasPrev = !1;
|
|
77
|
+
}
|
|
78
|
+
go(t) {
|
|
79
|
+
const e = Math.min(Math.max(1, t), this.totalPages);
|
|
80
|
+
e !== this.page && this.dispatchEvent(
|
|
81
|
+
new CustomEvent("baht-page-change", {
|
|
82
|
+
detail: { page: e },
|
|
83
|
+
bubbles: !0,
|
|
84
|
+
composed: !0
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
goCursor(t) {
|
|
89
|
+
t === "next" && !this.hasNext || t === "prev" && !this.hasPrev || this.dispatchEvent(
|
|
90
|
+
new CustomEvent("baht-cursor-change", {
|
|
91
|
+
detail: { direction: t },
|
|
92
|
+
bubbles: !0,
|
|
93
|
+
composed: !0
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
/** Visible page numbers with `null` marking an ellipsis gap. */
|
|
98
|
+
get pageItems() {
|
|
99
|
+
const { page: t, totalPages: e, siblings: i } = this, a = /* @__PURE__ */ new Set([1, e]);
|
|
100
|
+
for (let c = t - i; c <= t + i; c++)
|
|
101
|
+
c >= 1 && c <= e && a.add(c);
|
|
102
|
+
const s = [...a].sort((c, f) => c - f), r = [];
|
|
103
|
+
let o = 0;
|
|
104
|
+
for (const c of s)
|
|
105
|
+
o && c - o === 2 ? r.push(o + 1) : o && c - o > 2 && r.push(null), r.push(c), o = c;
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
render() {
|
|
109
|
+
if (this.variant === "cursor")
|
|
110
|
+
return n`<nav class="baht-pagination baht-pagination--cursor" aria-label="Pagination">
|
|
111
|
+
<button type="button" ?disabled=${!this.hasPrev} @click=${() => this.goCursor("prev")}><span aria-hidden="true">« </span>Prev</button>
|
|
112
|
+
<button type="button" ?disabled=${!this.hasNext} @click=${() => this.goCursor("next")}>Next<span aria-hidden="true"> »</span></button>
|
|
113
|
+
</nav>`;
|
|
114
|
+
const t = this.page <= 1, e = this.page >= this.totalPages;
|
|
115
|
+
return n`<nav class="baht-pagination" aria-label="Pagination">
|
|
116
|
+
<button type="button" aria-label="Previous page" ?disabled=${t} @click=${() => this.go(this.page - 1)}><span aria-hidden="true">«</span></button>
|
|
117
|
+
${this.variant === "compact" ? n`<span class="baht-pagination-label">Page ${this.page} of ${this.totalPages}</span>` : this.pageItems.map(
|
|
118
|
+
(i) => i === null ? n`<span class="baht-pagination-ellipsis" aria-hidden="true">…</span>` : n`<button
|
|
119
|
+
type="button"
|
|
120
|
+
aria-current=${i === this.page ? "page" : h}
|
|
121
|
+
aria-label="Page ${i}"
|
|
122
|
+
@click=${() => this.go(i)}
|
|
123
|
+
>${i}</button>`
|
|
124
|
+
)}
|
|
125
|
+
<button type="button" aria-label="Next page" ?disabled=${e} @click=${() => this.go(this.page + 1)}><span aria-hidden="true">»</span></button>
|
|
126
|
+
</nav>`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
yt([
|
|
130
|
+
l({ type: Number })
|
|
131
|
+
], ht.prototype, "page", 2);
|
|
132
|
+
yt([
|
|
133
|
+
l({ type: Number, attribute: "total-pages" })
|
|
134
|
+
], ht.prototype, "totalPages", 2);
|
|
135
|
+
yt([
|
|
136
|
+
l()
|
|
137
|
+
], ht.prototype, "variant", 2);
|
|
138
|
+
yt([
|
|
139
|
+
l({ type: Number })
|
|
140
|
+
], ht.prototype, "siblings", 2);
|
|
141
|
+
yt([
|
|
142
|
+
l({ type: Boolean, attribute: "has-next" })
|
|
143
|
+
], ht.prototype, "hasNext", 2);
|
|
144
|
+
yt([
|
|
145
|
+
l({ type: Boolean, attribute: "has-prev" })
|
|
146
|
+
], ht.prototype, "hasPrev", 2);
|
|
147
|
+
ht = yt([
|
|
148
|
+
b("baht-pagination")
|
|
149
|
+
], ht);
|
|
150
|
+
var Ps = Object.defineProperty, Os = Object.getOwnPropertyDescriptor, O = (t, e, i, a) => {
|
|
151
|
+
for (var s = a > 1 ? void 0 : a ? Os(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
152
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
153
|
+
return a && s && Ps(e, i, s), s;
|
|
154
|
+
};
|
|
155
|
+
const Cs = " › ", ye = (t) => t !== null && typeof t == "object" && !Array.isArray(t) && !(t instanceof Date), te = (t) => t.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
|
|
156
|
+
let k = class extends y {
|
|
157
|
+
constructor() {
|
|
158
|
+
super(...arguments), this.items = [], this.columns = {}, this.loading = !1, this.error = !1, this.errorMessage = "Couldn't load data. Try again.", this.emptyMessage = "No records yet.", this.showIndex = !0, this.indexOffset = 0, this.skeletonRows = 10, this.rowKey = "", this.clickable = !0, this.renderers = {}, this.visibleColumns = [], this.columnPicker = !0, this.page = 1, this.totalPages = 1, this.cursorMode = !1, this.hasNext = !1, this.hasPrev = !1, this.pickerOpen = !1, this.pickedColumns = null, this.draftColumns = [], this.pickAvail = [], this.pickSel = [], this.expanded = [], this.pickerPreviousFocus = null, this.onPickerKeydown = (t) => {
|
|
159
|
+
t.key === "Escape" ? this.closePicker() : t.key === "Tab" && this.trapPickerFocus(t);
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
get pickerTitleId() {
|
|
163
|
+
return `baht-table-picker-title-${this.uid}`;
|
|
164
|
+
}
|
|
165
|
+
pickerFocusables() {
|
|
166
|
+
const t = this.querySelector(".baht-table-picker-modal");
|
|
167
|
+
return t ? Array.from(
|
|
168
|
+
t.querySelectorAll(
|
|
169
|
+
'button:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
170
|
+
)
|
|
171
|
+
) : [];
|
|
172
|
+
}
|
|
173
|
+
/** Keep Tab cycling inside the column-picker dialog (no escape to the page behind). */
|
|
174
|
+
trapPickerFocus(t) {
|
|
175
|
+
const e = this.pickerFocusables();
|
|
176
|
+
if (e.length === 0) return;
|
|
177
|
+
const i = e[0], a = e[e.length - 1], s = document.activeElement, r = this.querySelector(".baht-table-picker-modal");
|
|
178
|
+
r != null && r.contains(s) ? t.shiftKey && s === i ? (a.focus(), t.preventDefault()) : !t.shiftKey && s === a && (i.focus(), t.preventDefault()) : (i.focus(), t.preventDefault());
|
|
179
|
+
}
|
|
180
|
+
disconnectedCallback() {
|
|
181
|
+
super.disconnectedCallback(), S() && document.removeEventListener("keydown", this.onPickerKeydown);
|
|
182
|
+
}
|
|
183
|
+
willUpdate(t) {
|
|
184
|
+
t.has("visibleColumns") && !t.has("columns") && (this.pickedColumns = null);
|
|
185
|
+
}
|
|
186
|
+
// ---- column model ----------------------------------------------------
|
|
187
|
+
/** The declared map, or one derived from the first row (nested objects become reference columns). */
|
|
188
|
+
get spec() {
|
|
189
|
+
if (Object.keys(this.columns).length > 0) return this.columns;
|
|
190
|
+
const t = this.items[0];
|
|
191
|
+
if (!t) return {};
|
|
192
|
+
const e = {};
|
|
193
|
+
for (const [i, a] of Object.entries(t))
|
|
194
|
+
e[i] = ye(a) ? {
|
|
195
|
+
label: te(i),
|
|
196
|
+
fields: Object.fromEntries(Object.keys(a).map((s) => [s, te(s)]))
|
|
197
|
+
} : te(i);
|
|
198
|
+
return e;
|
|
199
|
+
}
|
|
200
|
+
/** Walk a dotted key through the spec; undefined when no such column exists. */
|
|
201
|
+
specAt(t) {
|
|
202
|
+
let e = this.spec, i;
|
|
203
|
+
for (const a of t.split(".")) {
|
|
204
|
+
const s = e == null ? void 0 : e[a];
|
|
205
|
+
if (s === void 0) return;
|
|
206
|
+
const r = typeof s == "string" ? { label: s } : s;
|
|
207
|
+
i = r, e = r.fields;
|
|
208
|
+
}
|
|
209
|
+
return i;
|
|
210
|
+
}
|
|
211
|
+
isReference(t) {
|
|
212
|
+
var e;
|
|
213
|
+
return (((e = this.specAt(t)) == null ? void 0 : e.fields) ?? void 0) !== void 0;
|
|
214
|
+
}
|
|
215
|
+
childrenOf(t) {
|
|
216
|
+
var e;
|
|
217
|
+
return Object.keys(((e = this.specAt(t)) == null ? void 0 : e.fields) ?? {}).map((i) => `${t}.${i}`);
|
|
218
|
+
}
|
|
219
|
+
/** Every pickable key, reference fields included (`requester`, `requester.name`, ...). */
|
|
220
|
+
allPaths(t = "") {
|
|
221
|
+
return (t ? this.childrenOf(t) : this.allColumnKeys).flatMap((i) => this.isReference(i) ? [i, ...this.allPaths(i)] : [i]);
|
|
222
|
+
}
|
|
223
|
+
get allColumnKeys() {
|
|
224
|
+
return Object.keys(this.spec);
|
|
225
|
+
}
|
|
226
|
+
get columnKeys() {
|
|
227
|
+
return (this.pickedColumns ?? (this.visibleColumns.length > 0 ? this.visibleColumns : this.allColumnKeys)).filter((e) => this.specAt(e) !== void 0);
|
|
228
|
+
}
|
|
229
|
+
/** "Requested by › Department" for a dotted key; the plain label otherwise. */
|
|
230
|
+
labelFor(t) {
|
|
231
|
+
const e = [];
|
|
232
|
+
let i = this.spec;
|
|
233
|
+
for (const a of t.split(".")) {
|
|
234
|
+
const s = i == null ? void 0 : i[a];
|
|
235
|
+
if (s === void 0) {
|
|
236
|
+
e.push(te(a)), i = void 0;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
e.push(typeof s == "string" ? s : s.label), i = typeof s == "string" ? void 0 : s.fields;
|
|
240
|
+
}
|
|
241
|
+
return e.join(Cs);
|
|
242
|
+
}
|
|
243
|
+
/** The row's value at a dotted key (`requester.department`). */
|
|
244
|
+
static valueAt(t, e) {
|
|
245
|
+
let i = t;
|
|
246
|
+
for (const a of e.split(".")) {
|
|
247
|
+
if (!ye(i)) return;
|
|
248
|
+
i = i[a];
|
|
249
|
+
}
|
|
250
|
+
return i;
|
|
251
|
+
}
|
|
252
|
+
// ---- picker -----------------------------------------------------------
|
|
253
|
+
openPicker() {
|
|
254
|
+
this.draftColumns = this.columnKeys.slice(), this.pickAvail = [], this.pickSel = [], this.pickerOpen = !0, this.pickerPreviousFocus = document.activeElement, S() && document.addEventListener("keydown", this.onPickerKeydown), this.updateComplete.then(() => {
|
|
255
|
+
var t;
|
|
256
|
+
this.pickerOpen && ((t = this.pickerFocusables()[0]) == null || t.focus());
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
closePicker() {
|
|
260
|
+
var e;
|
|
261
|
+
if (!this.pickerOpen) return;
|
|
262
|
+
this.pickerOpen = !1, S() && document.removeEventListener("keydown", this.onPickerKeydown);
|
|
263
|
+
const t = this.pickerPreviousFocus;
|
|
264
|
+
this.pickerPreviousFocus = null, t != null && t.isConnected && ((e = t.focus) == null || e.call(t));
|
|
265
|
+
}
|
|
266
|
+
static selectedValues(t) {
|
|
267
|
+
return Array.from(t.target.selectedOptions).map((e) => e.value);
|
|
268
|
+
}
|
|
269
|
+
toggleAvail(t) {
|
|
270
|
+
this.pickAvail = this.pickAvail.includes(t) ? this.pickAvail.filter((e) => e !== t) : [...this.pickAvail, t];
|
|
271
|
+
}
|
|
272
|
+
toggleExpanded(t) {
|
|
273
|
+
this.expanded = this.expanded.includes(t) ? this.expanded.filter((e) => e !== t) : [...this.expanded, t];
|
|
274
|
+
}
|
|
275
|
+
addToSelected() {
|
|
276
|
+
this.draftColumns = [
|
|
277
|
+
...this.draftColumns,
|
|
278
|
+
...this.pickAvail.filter((t) => !this.draftColumns.includes(t))
|
|
279
|
+
], this.pickAvail = [];
|
|
280
|
+
}
|
|
281
|
+
removeFromSelected() {
|
|
282
|
+
this.draftColumns = this.draftColumns.filter((t) => !this.pickSel.includes(t)), this.pickSel = [];
|
|
283
|
+
}
|
|
284
|
+
moveSelected(t) {
|
|
285
|
+
const e = [...this.draftColumns], i = this.pickSel.map((a) => e.indexOf(a)).filter((a) => a >= 0).sort((a, s) => t === -1 ? a - s : s - a);
|
|
286
|
+
for (const a of i) {
|
|
287
|
+
const s = a + t;
|
|
288
|
+
s < 0 || s >= e.length || ([e[a], e[s]] = [e[s], e[a]]);
|
|
289
|
+
}
|
|
290
|
+
this.draftColumns = e;
|
|
291
|
+
}
|
|
292
|
+
confirmPicker() {
|
|
293
|
+
this.pickedColumns = this.draftColumns, this.closePicker();
|
|
294
|
+
const t = {
|
|
295
|
+
visibleColumns: this.pickedColumns,
|
|
296
|
+
columns: this.pickedColumns.map((e) => ({ key: e, label: this.labelFor(e) }))
|
|
297
|
+
};
|
|
298
|
+
this.dispatchEvent(
|
|
299
|
+
new CustomEvent("baht-columns-change", { detail: t, bubbles: !0, composed: !0 })
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
emitRow(t, e) {
|
|
303
|
+
this.clickable && this.dispatchEvent(
|
|
304
|
+
new CustomEvent("baht-row-click", {
|
|
305
|
+
detail: { row: t, index: e, id: this.rowKey ? t[this.rowKey] : void 0 },
|
|
306
|
+
bubbles: !0,
|
|
307
|
+
composed: !0
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
cell(t, e) {
|
|
312
|
+
const i = this.renderers[e], a = k.valueAt(t, e);
|
|
313
|
+
if (i) return i(a, t);
|
|
314
|
+
if (ye(a)) {
|
|
315
|
+
const s = a.name ?? a.label ?? a.title ?? a.id;
|
|
316
|
+
return s == null ? "" : String(s);
|
|
317
|
+
}
|
|
318
|
+
return a == null ? "" : String(a);
|
|
319
|
+
}
|
|
320
|
+
renderBody(t) {
|
|
321
|
+
const e = t.length + (this.showIndex ? 1 : 0);
|
|
322
|
+
return this.loading ? n`${Array.from(
|
|
323
|
+
{ length: this.skeletonRows },
|
|
324
|
+
(i, a) => n`<tr>
|
|
325
|
+
${this.showIndex ? n`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
|
|
326
|
+
${t.map(() => n`<td><span class="baht-skeleton" style="height:16px;"></span></td>`)}
|
|
327
|
+
</tr>`
|
|
328
|
+
)}` : this.error ? n`<tr><td colspan=${e}><div class="baht-table-state baht-table-state--error" role="alert">${this.errorMessage}</div></td></tr>` : this.items.length === 0 ? n`<tr><td colspan=${e}><div class="baht-table-state">${this.emptyMessage}</div></td></tr>` : n`${this.items.map(
|
|
329
|
+
(i, a) => n`<tr
|
|
330
|
+
tabindex=${this.clickable ? "0" : h}
|
|
331
|
+
@click=${() => this.emitRow(i, a)}
|
|
332
|
+
@keydown=${(s) => {
|
|
333
|
+
s.key !== "Enter" && s.key !== " " || (s.preventDefault(), this.emitRow(i, a));
|
|
334
|
+
}}
|
|
335
|
+
>
|
|
336
|
+
${this.showIndex ? n`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
|
|
337
|
+
${t.map((s) => n`<td data-col=${s}>${this.cell(i, s)}</td>`)}
|
|
338
|
+
</tr>`
|
|
339
|
+
)}`;
|
|
340
|
+
}
|
|
341
|
+
renderColumnToggle() {
|
|
342
|
+
return n`<div class="baht-table-picker">
|
|
343
|
+
<button
|
|
344
|
+
type="button"
|
|
345
|
+
class="baht-table-picker-toggle"
|
|
346
|
+
aria-haspopup="dialog"
|
|
347
|
+
aria-expanded=${this.pickerOpen ? "true" : "false"}
|
|
348
|
+
@click=${() => this.openPicker()}
|
|
349
|
+
>Columns</button>
|
|
350
|
+
</div>`;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* One row of the Available tree. A reference column gets an expander that
|
|
354
|
+
* unfolds its fields (the dot-walk); every row is a toggle button so the
|
|
355
|
+
* list works from the keyboard without the native multi-select.
|
|
356
|
+
*/
|
|
357
|
+
renderAvailRow(t, e) {
|
|
358
|
+
const i = this.specAt(t), a = (i == null ? void 0 : i.fields) !== void 0, s = this.expanded.includes(t), r = this.draftColumns.includes(t);
|
|
359
|
+
return n`<li class="baht-table-picker-node" style="--baht-picker-depth:${e}">
|
|
360
|
+
<div class="baht-table-picker-row">
|
|
361
|
+
${a ? n`<button
|
|
362
|
+
type="button"
|
|
363
|
+
class="baht-table-picker-expand"
|
|
364
|
+
aria-label=${s ? `Collapse ${i == null ? void 0 : i.label}` : `Expand ${i == null ? void 0 : i.label}`}
|
|
365
|
+
aria-expanded=${s ? "true" : "false"}
|
|
366
|
+
@click=${() => this.toggleExpanded(t)}
|
|
367
|
+
>${s ? "▾" : "▸"}</button>` : n`<span class="baht-table-picker-expand baht-table-picker-expand--leaf"></span>`}
|
|
368
|
+
<button
|
|
369
|
+
type="button"
|
|
370
|
+
class="baht-table-picker-option"
|
|
371
|
+
data-key=${t}
|
|
372
|
+
?disabled=${r}
|
|
373
|
+
aria-pressed=${this.pickAvail.includes(t) ? "true" : "false"}
|
|
374
|
+
@click=${() => this.toggleAvail(t)}
|
|
375
|
+
>${e === 0 ? this.labelFor(t) : (i == null ? void 0 : i.label) ?? t}</button>
|
|
376
|
+
</div>
|
|
377
|
+
${a && s ? n`<ul class="baht-table-picker-tree">
|
|
378
|
+
${this.childrenOf(t).map((o) => this.renderAvailRow(o, e + 1))}
|
|
379
|
+
</ul>` : h}
|
|
380
|
+
</li>`;
|
|
381
|
+
}
|
|
382
|
+
renderColumnModal() {
|
|
383
|
+
const t = this.allColumnKeys, e = this.allPaths().filter((a) => !this.draftColumns.includes(a)).length, i = (a) => (s) => a(k.selectedValues(s));
|
|
384
|
+
return n`<div
|
|
385
|
+
class="baht-table-picker-scrim"
|
|
386
|
+
@click=${(a) => a.target === a.currentTarget && this.closePicker()}
|
|
387
|
+
>
|
|
388
|
+
<div class="baht-table-picker-modal" role="dialog" aria-modal="true" aria-labelledby=${this.pickerTitleId}>
|
|
389
|
+
<div class="baht-table-picker-modal-head">
|
|
390
|
+
<b id=${this.pickerTitleId}>Choose columns</b>
|
|
391
|
+
<button type="button" class="baht-table-picker-modal-close" aria-label="Close" @click=${() => this.closePicker()}>×</button>
|
|
392
|
+
</div>
|
|
393
|
+
<div class="baht-table-picker-grid">
|
|
394
|
+
<div>
|
|
395
|
+
<div class="baht-table-picker-collabel">Available (${e})</div>
|
|
396
|
+
<ul class="baht-table-picker-tree baht-table-picker-avail" aria-label="Available columns">
|
|
397
|
+
${t.map((a) => this.renderAvailRow(a, 0))}
|
|
398
|
+
</ul>
|
|
399
|
+
</div>
|
|
400
|
+
<div class="baht-table-picker-btns">
|
|
401
|
+
<button type="button" ?disabled=${!this.pickAvail.length} @click=${() => this.addToSelected()}>› Add</button>
|
|
402
|
+
<button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.removeFromSelected()}>‹ Remove</button>
|
|
403
|
+
<button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.moveSelected(-1)}>↑ Up</button>
|
|
404
|
+
<button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.moveSelected(1)}>↓ Down</button>
|
|
405
|
+
</div>
|
|
406
|
+
<div>
|
|
407
|
+
<div class="baht-table-picker-collabel">Selected (${this.draftColumns.length})</div>
|
|
408
|
+
<select multiple size="10" class="baht-table-picker-select" aria-label="Selected columns" @change=${i((a) => this.pickSel = a)}>
|
|
409
|
+
${this.draftColumns.map(
|
|
410
|
+
(a) => n`<option value=${a} ?selected=${this.pickSel.includes(a)}>${this.labelFor(a)}</option>`
|
|
411
|
+
)}
|
|
412
|
+
</select>
|
|
413
|
+
</div>
|
|
414
|
+
</div>
|
|
415
|
+
<div class="baht-table-picker-modal-foot">
|
|
416
|
+
<button type="button" @click=${() => this.draftColumns = []}>Clear all</button>
|
|
417
|
+
<button type="button" @click=${() => this.draftColumns = t.slice()}>Select all</button>
|
|
418
|
+
<span class="baht-table-picker-spacer"></span>
|
|
419
|
+
<button type="button" @click=${() => this.closePicker()}>Cancel</button>
|
|
420
|
+
<button type="button" class="baht-table-picker-ok" @click=${() => this.confirmPicker()}>OK</button>
|
|
421
|
+
</div>
|
|
422
|
+
</div>
|
|
423
|
+
</div>`;
|
|
424
|
+
}
|
|
425
|
+
render() {
|
|
426
|
+
const t = this.columnKeys;
|
|
427
|
+
return n`<div
|
|
428
|
+
class="baht-table-wrap"
|
|
429
|
+
tabindex=${this.clickable ? h : "0"}
|
|
430
|
+
aria-busy=${this.loading ? "true" : h}
|
|
431
|
+
>
|
|
432
|
+
${this.columnPicker ? this.renderColumnToggle() : h}
|
|
433
|
+
${this.columnPicker && this.pickerOpen ? this.renderColumnModal() : h}
|
|
434
|
+
<table class="baht-table">
|
|
435
|
+
<thead>
|
|
436
|
+
<tr>
|
|
437
|
+
${this.showIndex ? n`<th scope="col" class="baht-table-index">No.</th>` : h}
|
|
438
|
+
${t.map((e) => n`<th scope="col" data-col=${e}>${this.labelFor(e)}</th>`)}
|
|
439
|
+
</tr>
|
|
440
|
+
</thead>
|
|
441
|
+
<tbody>${this.renderBody(t)}</tbody>
|
|
442
|
+
</table>
|
|
443
|
+
${this.cursorMode ? n`<div class="baht-table-footer">
|
|
444
|
+
<baht-pagination
|
|
445
|
+
variant="cursor"
|
|
446
|
+
?has-next=${this.hasNext}
|
|
447
|
+
?has-prev=${this.hasPrev}
|
|
448
|
+
></baht-pagination>
|
|
449
|
+
</div>` : this.totalPages > 1 ? n`<div class="baht-table-footer">
|
|
450
|
+
<baht-pagination
|
|
451
|
+
variant="compact"
|
|
452
|
+
page=${this.page}
|
|
453
|
+
total-pages=${this.totalPages}
|
|
454
|
+
></baht-pagination>
|
|
455
|
+
</div>` : h}
|
|
456
|
+
</div>`;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
O([
|
|
460
|
+
l({ attribute: !1 })
|
|
461
|
+
], k.prototype, "items", 2);
|
|
462
|
+
O([
|
|
463
|
+
l({ attribute: !1 })
|
|
464
|
+
], k.prototype, "columns", 2);
|
|
465
|
+
O([
|
|
466
|
+
l({ type: Boolean })
|
|
467
|
+
], k.prototype, "loading", 2);
|
|
468
|
+
O([
|
|
469
|
+
l({ type: Boolean })
|
|
470
|
+
], k.prototype, "error", 2);
|
|
471
|
+
O([
|
|
472
|
+
l({ attribute: "error-message" })
|
|
473
|
+
], k.prototype, "errorMessage", 2);
|
|
474
|
+
O([
|
|
475
|
+
l({ attribute: "empty-message" })
|
|
476
|
+
], k.prototype, "emptyMessage", 2);
|
|
477
|
+
O([
|
|
478
|
+
l({ type: Boolean, attribute: "show-index" })
|
|
479
|
+
], k.prototype, "showIndex", 2);
|
|
480
|
+
O([
|
|
481
|
+
l({ type: Number, attribute: "index-offset" })
|
|
482
|
+
], k.prototype, "indexOffset", 2);
|
|
483
|
+
O([
|
|
484
|
+
l({ type: Number, attribute: "skeleton-rows" })
|
|
485
|
+
], k.prototype, "skeletonRows", 2);
|
|
486
|
+
O([
|
|
487
|
+
l({ attribute: "row-key" })
|
|
488
|
+
], k.prototype, "rowKey", 2);
|
|
489
|
+
O([
|
|
490
|
+
l({ type: Boolean })
|
|
491
|
+
], k.prototype, "clickable", 2);
|
|
492
|
+
O([
|
|
493
|
+
l({ attribute: !1 })
|
|
494
|
+
], k.prototype, "renderers", 2);
|
|
495
|
+
O([
|
|
496
|
+
l({ attribute: !1 })
|
|
497
|
+
], k.prototype, "visibleColumns", 2);
|
|
498
|
+
O([
|
|
499
|
+
l({ type: Boolean, attribute: "column-picker" })
|
|
500
|
+
], k.prototype, "columnPicker", 2);
|
|
501
|
+
O([
|
|
502
|
+
l({ type: Number })
|
|
503
|
+
], k.prototype, "page", 2);
|
|
504
|
+
O([
|
|
505
|
+
l({ type: Number, attribute: "total-pages" })
|
|
506
|
+
], k.prototype, "totalPages", 2);
|
|
507
|
+
O([
|
|
508
|
+
l({ type: Boolean, attribute: "cursor-mode" })
|
|
509
|
+
], k.prototype, "cursorMode", 2);
|
|
510
|
+
O([
|
|
511
|
+
l({ type: Boolean, attribute: "has-next" })
|
|
512
|
+
], k.prototype, "hasNext", 2);
|
|
513
|
+
O([
|
|
514
|
+
l({ type: Boolean, attribute: "has-prev" })
|
|
515
|
+
], k.prototype, "hasPrev", 2);
|
|
516
|
+
O([
|
|
517
|
+
$()
|
|
518
|
+
], k.prototype, "pickerOpen", 2);
|
|
519
|
+
O([
|
|
520
|
+
$()
|
|
521
|
+
], k.prototype, "pickedColumns", 2);
|
|
522
|
+
O([
|
|
523
|
+
$()
|
|
524
|
+
], k.prototype, "draftColumns", 2);
|
|
525
|
+
O([
|
|
526
|
+
$()
|
|
527
|
+
], k.prototype, "pickAvail", 2);
|
|
528
|
+
O([
|
|
529
|
+
$()
|
|
530
|
+
], k.prototype, "pickSel", 2);
|
|
531
|
+
O([
|
|
532
|
+
$()
|
|
533
|
+
], k.prototype, "expanded", 2);
|
|
534
|
+
k = O([
|
|
535
|
+
b("baht-table")
|
|
536
|
+
], k);
|
|
537
|
+
var Ds = Object.defineProperty, Fs = Object.getOwnPropertyDescriptor, ut = (t, e, i, a) => {
|
|
538
|
+
for (var s = a > 1 ? void 0 : a ? Fs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
539
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
540
|
+
return a && s && Ds(e, i, s), s;
|
|
541
|
+
};
|
|
542
|
+
let it = class extends y {
|
|
543
|
+
constructor() {
|
|
544
|
+
super(...arguments), this.items = [], this.loading = !1, this.error = !1, this.errorMessage = "Couldn't load data. Try again.", this.emptyMessage = "Nothing here yet.", this.skeletonRows = 5, this.clickable = !0;
|
|
545
|
+
}
|
|
546
|
+
emitItem(t, e) {
|
|
547
|
+
this.clickable && this.dispatchEvent(
|
|
548
|
+
new CustomEvent("baht-item-click", {
|
|
549
|
+
detail: { item: t, index: e, id: t.id },
|
|
550
|
+
bubbles: !0,
|
|
551
|
+
composed: !0
|
|
552
|
+
})
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
renderRows() {
|
|
556
|
+
return this.loading ? n`${Array.from(
|
|
557
|
+
{ length: this.skeletonRows },
|
|
558
|
+
() => n`<div class="baht-list-item">
|
|
559
|
+
<div class="baht-list-main">
|
|
560
|
+
<span class="baht-skeleton baht-skeleton--text" style="width:40%; margin-bottom:6px;"></span>
|
|
561
|
+
<span class="baht-skeleton baht-skeleton--text" style="width:65%;"></span>
|
|
562
|
+
</div>
|
|
563
|
+
</div>`
|
|
564
|
+
)}` : this.error ? n`<div class="baht-list-state baht-list-state--error" role="alert">${this.errorMessage}</div>` : this.items.length === 0 ? n`<div class="baht-list-state">${this.emptyMessage}</div>` : n`${this.items.map(
|
|
565
|
+
(t, e) => n`<div
|
|
566
|
+
class="baht-list-item"
|
|
567
|
+
role="listitem"
|
|
568
|
+
tabindex=${this.clickable ? "0" : h}
|
|
569
|
+
@click=${() => this.emitItem(t, e)}
|
|
570
|
+
@keydown=${(i) => {
|
|
571
|
+
i.key !== "Enter" && i.key !== " " || (i.preventDefault(), this.emitItem(t, e));
|
|
572
|
+
}}
|
|
573
|
+
>
|
|
574
|
+
<div class="baht-list-main">
|
|
575
|
+
<div class="baht-list-title">${t.title}</div>
|
|
576
|
+
${t.subtitle ? n`<div class="baht-list-subtitle">${t.subtitle}</div>` : h}
|
|
577
|
+
</div>
|
|
578
|
+
${t.badge ? n`<baht-badge tone=${t.badgeTone ?? "neutral"} label=${t.badge}></baht-badge>` : h}
|
|
579
|
+
${t.meta ? n`<span class="baht-list-meta">${t.meta}</span>` : h}
|
|
580
|
+
</div>`
|
|
581
|
+
)}`;
|
|
582
|
+
}
|
|
583
|
+
render() {
|
|
584
|
+
const t = !this.loading && !this.error && this.items.length > 0;
|
|
585
|
+
return n`<div class="baht-list" role=${t ? "list" : h}>${this.renderRows()}</div>`;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
ut([
|
|
589
|
+
l({ attribute: !1 })
|
|
590
|
+
], it.prototype, "items", 2);
|
|
591
|
+
ut([
|
|
592
|
+
l({ type: Boolean })
|
|
593
|
+
], it.prototype, "loading", 2);
|
|
594
|
+
ut([
|
|
595
|
+
l({ type: Boolean })
|
|
596
|
+
], it.prototype, "error", 2);
|
|
597
|
+
ut([
|
|
598
|
+
l({ attribute: "error-message" })
|
|
599
|
+
], it.prototype, "errorMessage", 2);
|
|
600
|
+
ut([
|
|
601
|
+
l({ attribute: "empty-message" })
|
|
602
|
+
], it.prototype, "emptyMessage", 2);
|
|
603
|
+
ut([
|
|
604
|
+
l({ type: Number, attribute: "skeleton-rows" })
|
|
605
|
+
], it.prototype, "skeletonRows", 2);
|
|
606
|
+
ut([
|
|
607
|
+
l({ type: Boolean })
|
|
608
|
+
], it.prototype, "clickable", 2);
|
|
609
|
+
it = ut([
|
|
610
|
+
b("baht-list")
|
|
611
|
+
], it);
|
|
612
|
+
var Es = Object.defineProperty, Bs = Object.getOwnPropertyDescriptor, Wt = (t, e, i, a) => {
|
|
613
|
+
for (var s = a > 1 ? void 0 : a ? Bs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
614
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
615
|
+
return a && s && Es(e, i, s), s;
|
|
616
|
+
};
|
|
617
|
+
let kt = class extends y {
|
|
618
|
+
constructor() {
|
|
619
|
+
super(...arguments), this.text = "", this.position = "top", this.dismissed = !1;
|
|
620
|
+
}
|
|
621
|
+
get tooltipId() {
|
|
622
|
+
return `baht-tooltip-${this.uid}`;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Point aria-describedby at the tooltip from the focusable child (light DOM,
|
|
626
|
+
* so the id reference works). No focusable child -> the anchor itself becomes
|
|
627
|
+
* one, so keyboard users can still surface the tooltip.
|
|
628
|
+
*/
|
|
629
|
+
wireDescribedBy() {
|
|
630
|
+
const t = this.anchorEl.querySelector(
|
|
631
|
+
"button, a[href], input, select, textarea, [tabindex]"
|
|
632
|
+
);
|
|
633
|
+
t ? (t.setAttribute("aria-describedby", this.tooltipId), this.anchorEl.removeAttribute("tabindex"), this.anchorEl.removeAttribute("aria-describedby")) : (this.anchorEl.setAttribute("tabindex", "0"), this.anchorEl.setAttribute("aria-describedby", this.tooltipId));
|
|
634
|
+
}
|
|
635
|
+
firstUpdated() {
|
|
636
|
+
ne(this, this.anchorEl), this.wireDescribedBy(), setTimeout(() => this.isConnected && this.wireDescribedBy(), 0);
|
|
637
|
+
}
|
|
638
|
+
onKeydown(t) {
|
|
639
|
+
t.key === "Escape" && (this.dismissed = !0);
|
|
640
|
+
}
|
|
641
|
+
rearm() {
|
|
642
|
+
this.dismissed = !1;
|
|
643
|
+
}
|
|
644
|
+
render() {
|
|
645
|
+
return n`<span
|
|
646
|
+
class="baht-tooltip-host${this.dismissed ? " baht-tooltip-host--dismissed" : ""}"
|
|
647
|
+
@keydown=${this.onKeydown}
|
|
648
|
+
@mouseleave=${this.rearm}
|
|
649
|
+
@focusout=${this.rearm}
|
|
650
|
+
>
|
|
651
|
+
<span class="baht-tooltip-anchor"></span>
|
|
652
|
+
<span class="baht-tooltip baht-tooltip--${this.position}" id=${this.tooltipId} role="tooltip">${this.text}</span>
|
|
653
|
+
</span>`;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
Wt([
|
|
657
|
+
l()
|
|
658
|
+
], kt.prototype, "text", 2);
|
|
659
|
+
Wt([
|
|
660
|
+
l()
|
|
661
|
+
], kt.prototype, "position", 2);
|
|
662
|
+
Wt([
|
|
663
|
+
Bt(".baht-tooltip-anchor")
|
|
664
|
+
], kt.prototype, "anchorEl", 2);
|
|
665
|
+
Wt([
|
|
666
|
+
$()
|
|
667
|
+
], kt.prototype, "dismissed", 2);
|
|
668
|
+
kt = Wt([
|
|
669
|
+
b("baht-tooltip")
|
|
670
|
+
], kt);
|
|
671
|
+
var Is = Object.defineProperty, js = Object.getOwnPropertyDescriptor, It = (t, e, i, a) => {
|
|
672
|
+
for (var s = a > 1 ? void 0 : a ? js(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
673
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
674
|
+
return a && s && Is(e, i, s), s;
|
|
675
|
+
};
|
|
676
|
+
let ft = class extends y {
|
|
677
|
+
constructor() {
|
|
678
|
+
super(...arguments), this.tone = "info", this.heading = "", this.message = "", this.dismissible = !1, this.dismissed = !1, this.generation = 0;
|
|
679
|
+
}
|
|
680
|
+
willUpdate(t) {
|
|
681
|
+
(t.has("message") || t.has("heading")) && (this.dismissed = !1, this.generation++);
|
|
682
|
+
}
|
|
683
|
+
dismiss() {
|
|
684
|
+
this.dispatchEvent(new CustomEvent("baht-dismiss", { bubbles: !0, composed: !0 }));
|
|
685
|
+
const t = this.generation, e = () => {
|
|
686
|
+
t === this.generation && (this.dismissed = !0);
|
|
687
|
+
}, i = this.querySelector(".baht-alert");
|
|
688
|
+
if (!i) {
|
|
689
|
+
e();
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
i.classList.add("baht-alert--leaving"), vs(i, e);
|
|
693
|
+
}
|
|
694
|
+
render() {
|
|
695
|
+
return this.dismissed ? h : n`<div class="baht-alert baht-alert--${this.tone}" role="alert">
|
|
696
|
+
<div class="baht-alert-main">
|
|
697
|
+
${this.heading ? n`<div class="baht-alert-title">${this.heading}</div>` : h}
|
|
698
|
+
${this.message ? n`<div class="baht-alert-message">${this.message}</div>` : h}
|
|
699
|
+
</div>
|
|
700
|
+
${this.dismissible ? n`<button type="button" class="baht-alert-dismiss" aria-label=${m("dismiss")} @click=${() => this.dismiss()}>×</button>` : h}
|
|
701
|
+
</div>`;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
It([
|
|
705
|
+
l()
|
|
706
|
+
], ft.prototype, "tone", 2);
|
|
707
|
+
It([
|
|
708
|
+
l()
|
|
709
|
+
], ft.prototype, "heading", 2);
|
|
710
|
+
It([
|
|
711
|
+
l()
|
|
712
|
+
], ft.prototype, "message", 2);
|
|
713
|
+
It([
|
|
714
|
+
l({ type: Boolean })
|
|
715
|
+
], ft.prototype, "dismissible", 2);
|
|
716
|
+
It([
|
|
717
|
+
$()
|
|
718
|
+
], ft.prototype, "dismissed", 2);
|
|
719
|
+
ft = It([
|
|
720
|
+
b("baht-alert")
|
|
721
|
+
], ft);
|
|
722
|
+
var Ss = Object.defineProperty, Ms = Object.getOwnPropertyDescriptor, jt = (t, e, i, a) => {
|
|
723
|
+
for (var s = a > 1 ? void 0 : a ? Ms(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
724
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
725
|
+
return a && s && Ss(e, i, s), s;
|
|
726
|
+
};
|
|
727
|
+
let mt = class extends y {
|
|
728
|
+
constructor() {
|
|
729
|
+
super(...arguments), this.value = 0, this.max = 5, this.readonly = !1, this.label = "Rating", this.hover = 0;
|
|
730
|
+
}
|
|
731
|
+
emitValue(t) {
|
|
732
|
+
this.dispatchEvent(
|
|
733
|
+
new CustomEvent("baht-change", { detail: { value: t }, bubbles: !0, composed: !0 })
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
pick(t) {
|
|
737
|
+
this.readonly || this.emitValue(t === this.value ? 0 : t);
|
|
738
|
+
}
|
|
739
|
+
/** APG radio-group keys: arrows move the value, Home/End jump the ends. */
|
|
740
|
+
onKeydown(t, e) {
|
|
741
|
+
var a;
|
|
742
|
+
if (this.readonly) return;
|
|
743
|
+
let i;
|
|
744
|
+
if (t.key === "ArrowRight" || t.key === "ArrowUp") i = Math.min(e + 1, this.max);
|
|
745
|
+
else if (t.key === "ArrowLeft" || t.key === "ArrowDown") i = Math.max(e - 1, 1);
|
|
746
|
+
else if (t.key === "Home") i = 1;
|
|
747
|
+
else if (t.key === "End") i = this.max;
|
|
748
|
+
else return;
|
|
749
|
+
t.preventDefault(), this.emitValue(i), (a = this.querySelectorAll("button")[i - 1]) == null || a.focus();
|
|
750
|
+
}
|
|
751
|
+
setHover(t) {
|
|
752
|
+
this.readonly || (this.hover = t);
|
|
753
|
+
}
|
|
754
|
+
render() {
|
|
755
|
+
const t = this.hover || this.value;
|
|
756
|
+
return n`<div
|
|
757
|
+
class="baht-rating"
|
|
758
|
+
role="radiogroup"
|
|
759
|
+
aria-label=${this.label}
|
|
760
|
+
@mouseleave=${() => this.setHover(0)}
|
|
761
|
+
>
|
|
762
|
+
${Array.from({ length: this.max }, (e, i) => {
|
|
763
|
+
const a = i + 1, s = this.value || 1;
|
|
764
|
+
return n`<button
|
|
765
|
+
type="button"
|
|
766
|
+
class=${a <= t ? "baht-rating--on" : ""}
|
|
767
|
+
role="radio"
|
|
768
|
+
aria-checked=${a === this.value}
|
|
769
|
+
aria-label="${a} of ${this.max}"
|
|
770
|
+
tabindex=${a === s ? "0" : "-1"}
|
|
771
|
+
?disabled=${this.readonly}
|
|
772
|
+
@mouseenter=${() => this.setHover(a)}
|
|
773
|
+
@click=${() => this.pick(a)}
|
|
774
|
+
@keydown=${(r) => this.onKeydown(r, a)}
|
|
775
|
+
>★</button>`;
|
|
776
|
+
})}
|
|
777
|
+
</div>`;
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
jt([
|
|
781
|
+
l({ type: Number })
|
|
782
|
+
], mt.prototype, "value", 2);
|
|
783
|
+
jt([
|
|
784
|
+
l({ type: Number })
|
|
785
|
+
], mt.prototype, "max", 2);
|
|
786
|
+
jt([
|
|
787
|
+
l({ type: Boolean })
|
|
788
|
+
], mt.prototype, "readonly", 2);
|
|
789
|
+
jt([
|
|
790
|
+
l()
|
|
791
|
+
], mt.prototype, "label", 2);
|
|
792
|
+
jt([
|
|
793
|
+
$()
|
|
794
|
+
], mt.prototype, "hover", 2);
|
|
795
|
+
mt = jt([
|
|
796
|
+
b("baht-rating")
|
|
797
|
+
], mt);
|
|
798
|
+
var Ts = Object.defineProperty, As = Object.getOwnPropertyDescriptor, bt = (t, e, i, a) => {
|
|
799
|
+
for (var s = a > 1 ? void 0 : a ? As(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
800
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
801
|
+
return a && s && Ts(e, i, s), s;
|
|
802
|
+
};
|
|
803
|
+
let rt = class extends y {
|
|
804
|
+
constructor() {
|
|
805
|
+
super(...arguments), this.value = 0, this.min = 0, this.max = 100, this.step = 1, this.label = "", this.disabled = !1, this.showValue = !0;
|
|
806
|
+
}
|
|
807
|
+
get inputId() {
|
|
808
|
+
return `baht-range-${this.uid}`;
|
|
809
|
+
}
|
|
810
|
+
onInput(t) {
|
|
811
|
+
const e = Number(t.target.value);
|
|
812
|
+
this.dispatchEvent(
|
|
813
|
+
new CustomEvent("baht-change", { detail: { value: e }, bubbles: !0, composed: !0 })
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
render() {
|
|
817
|
+
return n`<div class="baht-range">
|
|
818
|
+
${this.label ? n`<label class="baht-label" for=${this.inputId}>${this.label}</label>` : h}
|
|
819
|
+
<div class="baht-range-row">
|
|
820
|
+
<input
|
|
821
|
+
type="range"
|
|
822
|
+
id=${this.inputId}
|
|
823
|
+
aria-label=${this.label ? h : "Value"}
|
|
824
|
+
.value=${ot(String(this.value))}
|
|
825
|
+
min=${this.min}
|
|
826
|
+
max=${this.max}
|
|
827
|
+
step=${this.step}
|
|
828
|
+
?disabled=${this.disabled}
|
|
829
|
+
@input=${(t) => this.onInput(t)}
|
|
830
|
+
/>
|
|
831
|
+
${this.showValue ? n`<span class="baht-range-value">${this.value}</span>` : h}
|
|
832
|
+
</div>
|
|
833
|
+
</div>`;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
bt([
|
|
837
|
+
l({ type: Number })
|
|
838
|
+
], rt.prototype, "value", 2);
|
|
839
|
+
bt([
|
|
840
|
+
l({ type: Number })
|
|
841
|
+
], rt.prototype, "min", 2);
|
|
842
|
+
bt([
|
|
843
|
+
l({ type: Number })
|
|
844
|
+
], rt.prototype, "max", 2);
|
|
845
|
+
bt([
|
|
846
|
+
l({ type: Number })
|
|
847
|
+
], rt.prototype, "step", 2);
|
|
848
|
+
bt([
|
|
849
|
+
l()
|
|
850
|
+
], rt.prototype, "label", 2);
|
|
851
|
+
bt([
|
|
852
|
+
l({ type: Boolean })
|
|
853
|
+
], rt.prototype, "disabled", 2);
|
|
854
|
+
bt([
|
|
855
|
+
l({ type: Boolean, attribute: "show-value" })
|
|
856
|
+
], rt.prototype, "showValue", 2);
|
|
857
|
+
rt = bt([
|
|
858
|
+
b("baht-range")
|
|
859
|
+
], rt);
|
|
860
|
+
var Ls = Object.defineProperty, Ns = Object.getOwnPropertyDescriptor, St = (t, e, i, a) => {
|
|
861
|
+
for (var s = a > 1 ? void 0 : a ? Ns(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
862
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
863
|
+
return a && s && Ls(e, i, s), s;
|
|
864
|
+
};
|
|
865
|
+
let vt = class extends y {
|
|
866
|
+
constructor() {
|
|
867
|
+
super(...arguments), this.length = 6, this.value = "", this.disabled = !1, this.mode = "numeric", this.label = "One-time code", this._chars = [], this._lastValue = "", this._wasFull = !1;
|
|
868
|
+
}
|
|
869
|
+
inputs() {
|
|
870
|
+
return Array.from(this.querySelectorAll("input"));
|
|
871
|
+
}
|
|
872
|
+
clean(t) {
|
|
873
|
+
return this.mode === "numeric" ? t.replace(/\D/g, "") : t;
|
|
874
|
+
}
|
|
875
|
+
willUpdate(t) {
|
|
876
|
+
super.willUpdate(t);
|
|
877
|
+
const e = t.has("value") && this.value !== this._lastValue;
|
|
878
|
+
!this.hasUpdated || e ? (this._chars = Array.from({ length: this.length }, (i, a) => this.value[a] ?? ""), this._lastValue = this.value, this._wasFull = this._chars.length > 0 && this._chars.every((i) => i !== "")) : this._chars.length !== this.length && (this._chars = Array.from({ length: this.length }, (i, a) => this._chars[a] ?? ""));
|
|
879
|
+
}
|
|
880
|
+
/** Writes `text` into `_chars` starting at `start`. Returns the index just
|
|
881
|
+
* past the last box written (may equal `this.length`). */
|
|
882
|
+
fill(t, e) {
|
|
883
|
+
let i = t;
|
|
884
|
+
for (const a of e) {
|
|
885
|
+
if (i >= this.length) break;
|
|
886
|
+
this._chars[i] = a, i += 1;
|
|
887
|
+
}
|
|
888
|
+
return i;
|
|
889
|
+
}
|
|
890
|
+
commit() {
|
|
891
|
+
const t = this._chars.join("").slice(0, this.length);
|
|
892
|
+
this.value = t, this._lastValue = t, this.requestUpdate(), this.dispatchEvent(
|
|
893
|
+
new CustomEvent("baht-change", {
|
|
894
|
+
detail: { value: this.value },
|
|
895
|
+
bubbles: !0,
|
|
896
|
+
composed: !0
|
|
897
|
+
})
|
|
898
|
+
);
|
|
899
|
+
const e = this._chars.length > 0 && this._chars.every((i) => i !== "");
|
|
900
|
+
e && !this._wasFull && this.dispatchEvent(
|
|
901
|
+
new CustomEvent("baht-otp-complete", {
|
|
902
|
+
detail: { value: this.value },
|
|
903
|
+
bubbles: !0,
|
|
904
|
+
composed: !0
|
|
905
|
+
})
|
|
906
|
+
), this._wasFull = e;
|
|
907
|
+
}
|
|
908
|
+
onInput(t, e) {
|
|
909
|
+
var r, o;
|
|
910
|
+
const i = e.target, a = this.clean(i.value);
|
|
911
|
+
if (a.length > 1) {
|
|
912
|
+
const c = this.fill(t, a);
|
|
913
|
+
i.value = this._chars[t] ?? "", this.commit(), (r = this.inputs()[Math.min(c, this.length - 1)]) == null || r.focus();
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const s = a.slice(-1);
|
|
917
|
+
i.value = s, this._chars[t] = s, this.commit(), s && t < this.length - 1 && ((o = this.inputs()[t + 1]) == null || o.focus());
|
|
918
|
+
}
|
|
919
|
+
onKeydown(t, e) {
|
|
920
|
+
var i;
|
|
921
|
+
e.key === "Backspace" && !this._chars[t] && t > 0 && (this._chars[t - 1] = "", this.commit(), (i = this.inputs()[t - 1]) == null || i.focus(), e.preventDefault());
|
|
922
|
+
}
|
|
923
|
+
onPaste(t) {
|
|
924
|
+
var a, s;
|
|
925
|
+
t.preventDefault();
|
|
926
|
+
const e = this.clean(((a = t.clipboardData) == null ? void 0 : a.getData("text")) ?? "").slice(0, this.length);
|
|
927
|
+
if (!e) return;
|
|
928
|
+
const i = this.fill(0, e);
|
|
929
|
+
this.commit(), (s = this.inputs()[Math.min(i, this.length - 1)]) == null || s.focus();
|
|
930
|
+
}
|
|
931
|
+
render() {
|
|
932
|
+
return n`<div class="baht-otp" role="group" aria-label=${this.label} @paste=${(t) => this.onPaste(t)}>
|
|
933
|
+
${this._chars.map(
|
|
934
|
+
(t, e) => n`<input
|
|
935
|
+
type="text"
|
|
936
|
+
inputmode=${this.mode === "numeric" ? "numeric" : "text"}
|
|
937
|
+
maxlength="1"
|
|
938
|
+
autocomplete=${e === 0 ? "one-time-code" : "off"}
|
|
939
|
+
aria-label=${m("otpCharacter", { i: e + 1, n: this.length })}
|
|
940
|
+
.value=${t}
|
|
941
|
+
?disabled=${this.disabled}
|
|
942
|
+
@input=${(i) => this.onInput(e, i)}
|
|
943
|
+
@keydown=${(i) => this.onKeydown(e, i)}
|
|
944
|
+
/>`
|
|
945
|
+
)}
|
|
946
|
+
</div>`;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
St([
|
|
950
|
+
l({ type: Number })
|
|
951
|
+
], vt.prototype, "length", 2);
|
|
952
|
+
St([
|
|
953
|
+
l()
|
|
954
|
+
], vt.prototype, "value", 2);
|
|
955
|
+
St([
|
|
956
|
+
l({ type: Boolean })
|
|
957
|
+
], vt.prototype, "disabled", 2);
|
|
958
|
+
St([
|
|
959
|
+
l()
|
|
960
|
+
], vt.prototype, "mode", 2);
|
|
961
|
+
St([
|
|
962
|
+
l()
|
|
963
|
+
], vt.prototype, "label", 2);
|
|
964
|
+
vt = St([
|
|
965
|
+
b("baht-otp")
|
|
966
|
+
], vt);
|
|
967
|
+
var qs = Object.defineProperty, Rs = Object.getOwnPropertyDescriptor, Mt = (t, e, i, a) => {
|
|
968
|
+
for (var s = a > 1 ? void 0 : a ? Rs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
969
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
970
|
+
return a && s && qs(e, i, s), s;
|
|
971
|
+
};
|
|
972
|
+
let $t = class extends y {
|
|
973
|
+
constructor() {
|
|
974
|
+
super(...arguments), this.options = [], this.selected = [], this.multiple = !0, this.disabled = !1, this.label = "Filters";
|
|
975
|
+
}
|
|
976
|
+
toggle(t) {
|
|
977
|
+
const e = this.selected.includes(t);
|
|
978
|
+
let i;
|
|
979
|
+
this.multiple ? (i = e ? this.selected.filter((s) => s !== t) : [...this.selected, t], i = this.options.map((s) => s.key).filter((s) => i.includes(s))) : i = e ? [] : [t], this.dispatchEvent(
|
|
980
|
+
new CustomEvent("baht-change", { detail: { selected: i }, bubbles: !0, composed: !0 })
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
render() {
|
|
984
|
+
return n`<div class="baht-filter" role="group" aria-label=${this.label}>
|
|
985
|
+
${this.options.map(
|
|
986
|
+
(t) => n`<button
|
|
987
|
+
type="button"
|
|
988
|
+
aria-pressed=${this.selected.includes(t.key)}
|
|
989
|
+
?disabled=${this.disabled}
|
|
990
|
+
@click=${() => this.toggle(t.key)}
|
|
991
|
+
>${t.label}</button>`
|
|
992
|
+
)}
|
|
993
|
+
</div>`;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
Mt([
|
|
997
|
+
l({ attribute: !1 })
|
|
998
|
+
], $t.prototype, "options", 2);
|
|
999
|
+
Mt([
|
|
1000
|
+
l({ attribute: !1 })
|
|
1001
|
+
], $t.prototype, "selected", 2);
|
|
1002
|
+
Mt([
|
|
1003
|
+
l({ type: Boolean })
|
|
1004
|
+
], $t.prototype, "multiple", 2);
|
|
1005
|
+
Mt([
|
|
1006
|
+
l({ type: Boolean })
|
|
1007
|
+
], $t.prototype, "disabled", 2);
|
|
1008
|
+
Mt([
|
|
1009
|
+
l()
|
|
1010
|
+
], $t.prototype, "label", 2);
|
|
1011
|
+
$t = Mt([
|
|
1012
|
+
b("baht-filter")
|
|
1013
|
+
], $t);
|
|
1014
|
+
var zs = Object.defineProperty, Vs = Object.getOwnPropertyDescriptor, ce = (t, e, i, a) => {
|
|
1015
|
+
for (var s = a > 1 ? void 0 : a ? Vs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1016
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1017
|
+
return a && s && zs(e, i, s), s;
|
|
1018
|
+
};
|
|
1019
|
+
let Vt = class extends y {
|
|
1020
|
+
constructor() {
|
|
1021
|
+
super(...arguments), this.variant = "rect", this.width = "100%", this.height = "";
|
|
1022
|
+
}
|
|
1023
|
+
render() {
|
|
1024
|
+
const t = this.height || (this.variant === "text" ? "1em" : "20px"), e = this.variant === "rect" ? "" : ` baht-skeleton--${this.variant}`;
|
|
1025
|
+
return n`<span
|
|
1026
|
+
class="baht-skeleton${e}"
|
|
1027
|
+
style="width:${this.width}; height:${t};"
|
|
1028
|
+
aria-hidden="true"
|
|
1029
|
+
></span>`;
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
ce([
|
|
1033
|
+
l()
|
|
1034
|
+
], Vt.prototype, "variant", 2);
|
|
1035
|
+
ce([
|
|
1036
|
+
l()
|
|
1037
|
+
], Vt.prototype, "width", 2);
|
|
1038
|
+
ce([
|
|
1039
|
+
l()
|
|
1040
|
+
], Vt.prototype, "height", 2);
|
|
1041
|
+
Vt = ce([
|
|
1042
|
+
b("baht-skeleton")
|
|
1043
|
+
], Vt);
|
|
1044
|
+
var Ks = Object.defineProperty, Us = Object.getOwnPropertyDescriptor, Jt = (t, e, i, a) => {
|
|
1045
|
+
for (var s = a > 1 ? void 0 : a ? Us(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1046
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1047
|
+
return a && s && Ks(e, i, s), s;
|
|
1048
|
+
};
|
|
1049
|
+
let Pt = class extends y {
|
|
1050
|
+
constructor() {
|
|
1051
|
+
super(...arguments), this.value = null, this.tone = "primary", this.showLabel = !1, this.label = "Progress";
|
|
1052
|
+
}
|
|
1053
|
+
render() {
|
|
1054
|
+
const t = this.value == null || Number.isNaN(this.value), e = t ? 0 : Math.min(100, Math.max(0, this.value)), i = this.tone === "primary" ? "" : ` baht-progress--${this.tone}`;
|
|
1055
|
+
return n`<div>
|
|
1056
|
+
<div
|
|
1057
|
+
class="baht-progress${i}${t ? " baht-progress--indeterminate" : ""}"
|
|
1058
|
+
role="progressbar"
|
|
1059
|
+
aria-label=${this.label}
|
|
1060
|
+
aria-valuemin="0"
|
|
1061
|
+
aria-valuemax="100"
|
|
1062
|
+
aria-valuenow=${t ? h : e}
|
|
1063
|
+
>
|
|
1064
|
+
<div class="baht-progress-bar" style=${t ? h : `width:${e}%`}></div>
|
|
1065
|
+
</div>
|
|
1066
|
+
${this.showLabel && !t ? n`<div class="baht-progress-label">${e}%</div>` : h}
|
|
1067
|
+
</div>`;
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
Jt([
|
|
1071
|
+
l({ type: Number })
|
|
1072
|
+
], Pt.prototype, "value", 2);
|
|
1073
|
+
Jt([
|
|
1074
|
+
l()
|
|
1075
|
+
], Pt.prototype, "tone", 2);
|
|
1076
|
+
Jt([
|
|
1077
|
+
l({ type: Boolean, attribute: "show-label" })
|
|
1078
|
+
], Pt.prototype, "showLabel", 2);
|
|
1079
|
+
Jt([
|
|
1080
|
+
l()
|
|
1081
|
+
], Pt.prototype, "label", 2);
|
|
1082
|
+
Pt = Jt([
|
|
1083
|
+
b("baht-progress")
|
|
1084
|
+
], Pt);
|
|
1085
|
+
var Hs = Object.defineProperty, Gs = Object.getOwnPropertyDescriptor, Se = (t, e, i, a) => {
|
|
1086
|
+
for (var s = a > 1 ? void 0 : a ? Gs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1087
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1088
|
+
return a && s && Hs(e, i, s), s;
|
|
1089
|
+
};
|
|
1090
|
+
let ie = class extends y {
|
|
1091
|
+
constructor() {
|
|
1092
|
+
super(...arguments), this.size = "md", this.label = "Loading";
|
|
1093
|
+
}
|
|
1094
|
+
render() {
|
|
1095
|
+
const t = this.size === "md" ? "" : ` baht-spinner--${this.size}`;
|
|
1096
|
+
return n`<span class="baht-spinner${t}" role="status" aria-label=${this.label}></span>`;
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
Se([
|
|
1100
|
+
l()
|
|
1101
|
+
], ie.prototype, "size", 2);
|
|
1102
|
+
Se([
|
|
1103
|
+
l()
|
|
1104
|
+
], ie.prototype, "label", 2);
|
|
1105
|
+
ie = Se([
|
|
1106
|
+
b("baht-spinner")
|
|
1107
|
+
], ie);
|
|
1108
|
+
var Ws = Object.defineProperty, Js = Object.getOwnPropertyDescriptor, Yt = (t, e, i, a) => {
|
|
1109
|
+
for (var s = a > 1 ? void 0 : a ? Js(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1110
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1111
|
+
return a && s && Ws(e, i, s), s;
|
|
1112
|
+
};
|
|
1113
|
+
let Ot = class extends y {
|
|
1114
|
+
constructor() {
|
|
1115
|
+
super(...arguments), this.heading = "", this.subtitle = "", this.hero = !1;
|
|
1116
|
+
}
|
|
1117
|
+
firstUpdated() {
|
|
1118
|
+
ne(this, this.bodyEl);
|
|
1119
|
+
}
|
|
1120
|
+
render() {
|
|
1121
|
+
return n`<div class="baht-card${this.hero ? " baht-card--hero" : ""}">
|
|
1122
|
+
${this.heading ? n`<div class="baht-card-title">${this.heading}</div>` : h}
|
|
1123
|
+
${this.subtitle ? n`<div class="baht-card-subtitle">${this.subtitle}</div>` : h}
|
|
1124
|
+
<div class="baht-card-body"></div>
|
|
1125
|
+
</div>`;
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
Yt([
|
|
1129
|
+
l()
|
|
1130
|
+
], Ot.prototype, "heading", 2);
|
|
1131
|
+
Yt([
|
|
1132
|
+
l()
|
|
1133
|
+
], Ot.prototype, "subtitle", 2);
|
|
1134
|
+
Yt([
|
|
1135
|
+
l({ type: Boolean })
|
|
1136
|
+
], Ot.prototype, "hero", 2);
|
|
1137
|
+
Yt([
|
|
1138
|
+
Bt(".baht-card-body")
|
|
1139
|
+
], Ot.prototype, "bodyEl", 2);
|
|
1140
|
+
Ot = Yt([
|
|
1141
|
+
b("baht-card")
|
|
1142
|
+
], Ot);
|
|
1143
|
+
var Ys = Object.defineProperty, Xs = Object.getOwnPropertyDescriptor, pe = (t, e, i, a) => {
|
|
1144
|
+
for (var s = a > 1 ? void 0 : a ? Xs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1145
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1146
|
+
return a && s && Ys(e, i, s), s;
|
|
1147
|
+
};
|
|
1148
|
+
let Kt = class extends y {
|
|
1149
|
+
constructor() {
|
|
1150
|
+
super(...arguments), this.legend = "", this.disabled = !1;
|
|
1151
|
+
}
|
|
1152
|
+
firstUpdated() {
|
|
1153
|
+
ne(this, this.bodyEl);
|
|
1154
|
+
}
|
|
1155
|
+
render() {
|
|
1156
|
+
return n`<fieldset class="baht-fieldset" ?disabled=${this.disabled}>
|
|
1157
|
+
${this.legend ? n`<legend>${this.legend}</legend>` : h}
|
|
1158
|
+
<div class="baht-fieldset-body"></div>
|
|
1159
|
+
</fieldset>`;
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
pe([
|
|
1163
|
+
l()
|
|
1164
|
+
], Kt.prototype, "legend", 2);
|
|
1165
|
+
pe([
|
|
1166
|
+
l({ type: Boolean })
|
|
1167
|
+
], Kt.prototype, "disabled", 2);
|
|
1168
|
+
pe([
|
|
1169
|
+
Bt(".baht-fieldset-body")
|
|
1170
|
+
], Kt.prototype, "bodyEl", 2);
|
|
1171
|
+
Kt = pe([
|
|
1172
|
+
b("baht-fieldset")
|
|
1173
|
+
], Kt);
|
|
1174
|
+
var Zs = Object.defineProperty, Qs = Object.getOwnPropertyDescriptor, ls = (t, e, i, a) => {
|
|
1175
|
+
for (var s = a > 1 ? void 0 : a ? Qs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1176
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1177
|
+
return a && s && Zs(e, i, s), s;
|
|
1178
|
+
};
|
|
1179
|
+
let De = class extends y {
|
|
1180
|
+
constructor() {
|
|
1181
|
+
super(...arguments), this.items = [];
|
|
1182
|
+
}
|
|
1183
|
+
render() {
|
|
1184
|
+
return n`<div class="baht-timeline" role="list">
|
|
1185
|
+
${this.items.map(
|
|
1186
|
+
(t, e) => n`<div class="baht-timeline-item" role="listitem">
|
|
1187
|
+
<div class="baht-timeline-rail">
|
|
1188
|
+
<span class="baht-timeline-dot${t.tone && t.tone !== "primary" ? ` baht-timeline-dot--${t.tone}` : ""}"></span>
|
|
1189
|
+
${e < this.items.length - 1 ? n`<span class="baht-timeline-line"></span>` : h}
|
|
1190
|
+
</div>
|
|
1191
|
+
<div class="baht-timeline-main">
|
|
1192
|
+
<div class="baht-timeline-title">
|
|
1193
|
+
${t.title}
|
|
1194
|
+
${t.time ? n`<span class="baht-timeline-time"> · ${t.time}</span>` : h}
|
|
1195
|
+
</div>
|
|
1196
|
+
${t.description ? n`<div class="baht-timeline-desc">${t.description}</div>` : h}
|
|
1197
|
+
</div>
|
|
1198
|
+
</div>`
|
|
1199
|
+
)}
|
|
1200
|
+
</div>`;
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
ls([
|
|
1204
|
+
l({ attribute: !1 })
|
|
1205
|
+
], De.prototype, "items", 2);
|
|
1206
|
+
De = ls([
|
|
1207
|
+
b("baht-timeline")
|
|
1208
|
+
], De);
|
|
1209
|
+
var ta = Object.defineProperty, ea = Object.getOwnPropertyDescriptor, de = (t, e, i, a) => {
|
|
1210
|
+
for (var s = a > 1 ? void 0 : a ? ea(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1211
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1212
|
+
return a && s && ta(e, i, s), s;
|
|
1213
|
+
};
|
|
1214
|
+
let Ct = class extends y {
|
|
1215
|
+
constructor() {
|
|
1216
|
+
super(...arguments), this.items = [], this.multiple = !1, this.openSet = /* @__PURE__ */ new Set(), this.itemsFingerprint = "";
|
|
1217
|
+
}
|
|
1218
|
+
static fingerprint(t) {
|
|
1219
|
+
return JSON.stringify(t.map((e) => [e.title, e.content]));
|
|
1220
|
+
}
|
|
1221
|
+
willUpdate(t) {
|
|
1222
|
+
if (t.has("items")) {
|
|
1223
|
+
const e = Ct.fingerprint(this.items);
|
|
1224
|
+
e !== this.itemsFingerprint && (this.itemsFingerprint = e, this.openSet = new Set(this.items.flatMap((i, a) => i.open ? [a] : [])));
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
toggle(t) {
|
|
1228
|
+
const e = !this.openSet.has(t), i = this.multiple ? new Set(this.openSet) : /* @__PURE__ */ new Set();
|
|
1229
|
+
e ? i.add(t) : i.delete(t), this.openSet = i, this.dispatchEvent(
|
|
1230
|
+
new CustomEvent("baht-toggle", { detail: { index: t, open: e }, bubbles: !0, composed: !0 })
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
render() {
|
|
1234
|
+
return n`<div class="baht-accordion">
|
|
1235
|
+
${this.items.map((t, e) => {
|
|
1236
|
+
const i = this.openSet.has(e), a = `baht-acc-${this.uid}-t-${e}`, s = `baht-acc-${this.uid}-p-${e}`;
|
|
1237
|
+
return n`<div class="baht-accordion-item${i ? " baht-accordion-item--open" : ""}">
|
|
1238
|
+
<button
|
|
1239
|
+
type="button"
|
|
1240
|
+
class="baht-accordion-trigger"
|
|
1241
|
+
id=${a}
|
|
1242
|
+
aria-expanded=${i}
|
|
1243
|
+
aria-controls=${i ? s : h}
|
|
1244
|
+
@click=${() => this.toggle(e)}
|
|
1245
|
+
>
|
|
1246
|
+
<span>${t.title}</span>
|
|
1247
|
+
<span class="baht-accordion-chevron" aria-hidden="true">▾</span>
|
|
1248
|
+
</button>
|
|
1249
|
+
${i ? n`<div class="baht-accordion-content" id=${s} role="region" aria-labelledby=${a}>${t.content}</div>` : h}
|
|
1250
|
+
</div>`;
|
|
1251
|
+
})}
|
|
1252
|
+
</div>`;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
de([
|
|
1256
|
+
l({ attribute: !1 })
|
|
1257
|
+
], Ct.prototype, "items", 2);
|
|
1258
|
+
de([
|
|
1259
|
+
l({ type: Boolean })
|
|
1260
|
+
], Ct.prototype, "multiple", 2);
|
|
1261
|
+
de([
|
|
1262
|
+
$()
|
|
1263
|
+
], Ct.prototype, "openSet", 2);
|
|
1264
|
+
Ct = de([
|
|
1265
|
+
b("baht-accordion")
|
|
1266
|
+
], Ct);
|
|
1267
|
+
var sa = Object.defineProperty, aa = Object.getOwnPropertyDescriptor, Xt = (t, e, i, a) => {
|
|
1268
|
+
for (var s = a > 1 ? void 0 : a ? aa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1269
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1270
|
+
return a && s && sa(e, i, s), s;
|
|
1271
|
+
};
|
|
1272
|
+
let Dt = class extends y {
|
|
1273
|
+
constructor() {
|
|
1274
|
+
super(...arguments), this.href = "", this.label = "", this.external = !1, this.externalHint = "opens in new tab";
|
|
1275
|
+
}
|
|
1276
|
+
render() {
|
|
1277
|
+
return n`<a
|
|
1278
|
+
class="baht-link"
|
|
1279
|
+
href=${this.href || h}
|
|
1280
|
+
target=${this.external ? "_blank" : h}
|
|
1281
|
+
rel=${this.external ? "noopener noreferrer" : h}
|
|
1282
|
+
>${this.label}${this.external ? n` <span class="baht-link-external" aria-hidden="true">↗</span><span class="baht-visually-hidden"> (${this.externalHint})</span>` : h}</a>`;
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
Xt([
|
|
1286
|
+
l()
|
|
1287
|
+
], Dt.prototype, "href", 2);
|
|
1288
|
+
Xt([
|
|
1289
|
+
l()
|
|
1290
|
+
], Dt.prototype, "label", 2);
|
|
1291
|
+
Xt([
|
|
1292
|
+
l({ type: Boolean })
|
|
1293
|
+
], Dt.prototype, "external", 2);
|
|
1294
|
+
Xt([
|
|
1295
|
+
l({ attribute: "external-hint" })
|
|
1296
|
+
], Dt.prototype, "externalHint", 2);
|
|
1297
|
+
Dt = Xt([
|
|
1298
|
+
b("baht-link")
|
|
1299
|
+
], Dt);
|
|
1300
|
+
var ia = Object.defineProperty, ra = Object.getOwnPropertyDescriptor, Me = (t, e, i, a) => {
|
|
1301
|
+
for (var s = a > 1 ? void 0 : a ? ra(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1302
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1303
|
+
return a && s && ia(e, i, s), s;
|
|
1304
|
+
};
|
|
1305
|
+
let re = class extends y {
|
|
1306
|
+
constructor() {
|
|
1307
|
+
super(...arguments), this.items = [], this.separator = "›";
|
|
1308
|
+
}
|
|
1309
|
+
navigate(t, e) {
|
|
1310
|
+
this.dispatchEvent(
|
|
1311
|
+
new CustomEvent("baht-navigate", { detail: { item: t, index: e }, bubbles: !0, composed: !0 })
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
render() {
|
|
1315
|
+
const t = this.items.length - 1;
|
|
1316
|
+
return n`<nav class="baht-breadcrumbs" aria-label="Breadcrumb">
|
|
1317
|
+
${this.items.map((e, i) => {
|
|
1318
|
+
const a = i < t ? n`<span class="baht-breadcrumbs-sep" aria-hidden="true">${this.separator}</span>` : h;
|
|
1319
|
+
return i === t ? n`<span class="baht-breadcrumbs-current" aria-current="page">${e.label}</span>${a}` : e.href ? n`<a class="baht-link" href=${e.href}>${e.label}</a>${a}` : n`<a
|
|
1320
|
+
class="baht-link"
|
|
1321
|
+
href="#"
|
|
1322
|
+
@click=${(s) => {
|
|
1323
|
+
s.preventDefault(), this.navigate(e, i);
|
|
1324
|
+
}}
|
|
1325
|
+
>${e.label}</a>${a}`;
|
|
1326
|
+
})}
|
|
1327
|
+
</nav>`;
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
Me([
|
|
1331
|
+
l({ attribute: !1 })
|
|
1332
|
+
], re.prototype, "items", 2);
|
|
1333
|
+
Me([
|
|
1334
|
+
l()
|
|
1335
|
+
], re.prototype, "separator", 2);
|
|
1336
|
+
re = Me([
|
|
1337
|
+
b("baht-breadcrumbs")
|
|
1338
|
+
], re);
|
|
1339
|
+
var oa = Object.getOwnPropertyDescriptor, la = (t, e, i, a) => {
|
|
1340
|
+
for (var s = a > 1 ? void 0 : a ? oa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1341
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1342
|
+
return s;
|
|
1343
|
+
};
|
|
1344
|
+
let Ne = class extends J {
|
|
1345
|
+
renderControl() {
|
|
1346
|
+
return n`<input
|
|
1347
|
+
class="baht-control baht-control--text"
|
|
1348
|
+
id=${this.controlId}
|
|
1349
|
+
type=${this.field.type === "email" ? "email" : this.field.type === "password" ? "password" : "text"}
|
|
1350
|
+
.value=${ot(this.shownValue == null ? "" : String(this.shownValue))}
|
|
1351
|
+
placeholder=${L(this.field.placeholder)}
|
|
1352
|
+
maxlength=${L(this.field.max_length)}
|
|
1353
|
+
autocomplete=${L(this.field.autocomplete)}
|
|
1354
|
+
?disabled=${this.disabled}
|
|
1355
|
+
?readonly=${this.readonly}
|
|
1356
|
+
?required=${this.required}
|
|
1357
|
+
aria-invalid=${this.invalid}
|
|
1358
|
+
aria-describedby=${this.describedBy}
|
|
1359
|
+
@input=${(t) => this.emitTyped(t.target.value)}
|
|
1360
|
+
/>`;
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
Ne = la([
|
|
1364
|
+
b("baht-input")
|
|
1365
|
+
], Ne);
|
|
1366
|
+
var na = Object.getOwnPropertyDescriptor, ha = (t, e, i, a) => {
|
|
1367
|
+
for (var s = a > 1 ? void 0 : a ? na(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1368
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1369
|
+
return s;
|
|
1370
|
+
};
|
|
1371
|
+
let qe = class extends J {
|
|
1372
|
+
renderControl() {
|
|
1373
|
+
return n`<textarea
|
|
1374
|
+
class="baht-control baht-control--textarea"
|
|
1375
|
+
id=${this.controlId}
|
|
1376
|
+
.value=${ot(this.shownValue == null ? "" : String(this.shownValue))}
|
|
1377
|
+
placeholder=${L(this.field.placeholder)}
|
|
1378
|
+
maxlength=${L(this.field.max_length)}
|
|
1379
|
+
rows=${this.field.rows ?? 3}
|
|
1380
|
+
autocomplete=${L(this.field.autocomplete)}
|
|
1381
|
+
?disabled=${this.disabled}
|
|
1382
|
+
?readonly=${this.readonly}
|
|
1383
|
+
?required=${this.required}
|
|
1384
|
+
aria-invalid=${this.invalid}
|
|
1385
|
+
aria-describedby=${this.describedBy}
|
|
1386
|
+
@input=${(t) => this.emitTyped(t.target.value)}
|
|
1387
|
+
></textarea>`;
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
qe = ha([
|
|
1391
|
+
b("baht-textarea")
|
|
1392
|
+
], qe);
|
|
1393
|
+
var ca = Object.getOwnPropertyDescriptor, pa = (t, e, i, a) => {
|
|
1394
|
+
for (var s = a > 1 ? void 0 : a ? ca(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1395
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1396
|
+
return s;
|
|
1397
|
+
};
|
|
1398
|
+
let Re = class extends J {
|
|
1399
|
+
renderControl() {
|
|
1400
|
+
return n`<input
|
|
1401
|
+
class="baht-control baht-control--number"
|
|
1402
|
+
id=${this.controlId}
|
|
1403
|
+
type="number"
|
|
1404
|
+
.value=${ot(this.shownValue == null ? "" : String(this.shownValue))}
|
|
1405
|
+
placeholder=${L(this.field.placeholder)}
|
|
1406
|
+
min=${L(this.field.min)}
|
|
1407
|
+
max=${L(this.field.max)}
|
|
1408
|
+
step=${L(this.field.step)}
|
|
1409
|
+
?disabled=${this.disabled}
|
|
1410
|
+
?readonly=${this.readonly}
|
|
1411
|
+
?required=${this.required}
|
|
1412
|
+
aria-invalid=${this.invalid}
|
|
1413
|
+
aria-describedby=${this.describedBy}
|
|
1414
|
+
@input=${(t) => {
|
|
1415
|
+
const e = t.target.value;
|
|
1416
|
+
this.emitTyped(e === "" ? null : Number(e));
|
|
1417
|
+
}}
|
|
1418
|
+
/>`;
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
Re = pa([
|
|
1422
|
+
b("baht-number")
|
|
1423
|
+
], Re);
|
|
1424
|
+
var da = Object.defineProperty, ua = Object.getOwnPropertyDescriptor, Te = (t, e, i, a) => {
|
|
1425
|
+
for (var s = a > 1 ? void 0 : a ? ua(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1426
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1427
|
+
return a && s && da(e, i, s), s;
|
|
1428
|
+
};
|
|
1429
|
+
const ba = 500;
|
|
1430
|
+
let oe = class extends J {
|
|
1431
|
+
constructor() {
|
|
1432
|
+
super(...arguments), this.open = !1, this.active = 0, this.typeBuffer = "", this.onDocMousedown = (t) => {
|
|
1433
|
+
this.contains(t.target) || this.close();
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
disconnectedCallback() {
|
|
1437
|
+
super.disconnectedCallback(), clearTimeout(this.typeTimer), S() && document.removeEventListener("mousedown", this.onDocMousedown);
|
|
1438
|
+
}
|
|
1439
|
+
get listId() {
|
|
1440
|
+
return `${this.controlId}-list`;
|
|
1441
|
+
}
|
|
1442
|
+
optionId(t) {
|
|
1443
|
+
return `${this.listId}-${t}`;
|
|
1444
|
+
}
|
|
1445
|
+
/** Placeholder row first (picks `null`), then the field's options. */
|
|
1446
|
+
get rows() {
|
|
1447
|
+
return [
|
|
1448
|
+
{ key: "", label: this.field.placeholder ?? m("choose") },
|
|
1449
|
+
...this.field.options ?? []
|
|
1450
|
+
];
|
|
1451
|
+
}
|
|
1452
|
+
get currentKey() {
|
|
1453
|
+
return this.value == null ? "" : String(this.value);
|
|
1454
|
+
}
|
|
1455
|
+
get selectedIndex() {
|
|
1456
|
+
const t = this.rows.findIndex((e) => e.key === this.currentKey);
|
|
1457
|
+
return t < 0 ? 0 : t;
|
|
1458
|
+
}
|
|
1459
|
+
get interactive() {
|
|
1460
|
+
return !this.disabled && !this.readonly;
|
|
1461
|
+
}
|
|
1462
|
+
willUpdate(t) {
|
|
1463
|
+
super.willUpdate(t), this.field && t.has("value") && !this.open && (this.active = this.selectedIndex);
|
|
1464
|
+
}
|
|
1465
|
+
updated() {
|
|
1466
|
+
var e;
|
|
1467
|
+
if (!this.open) return;
|
|
1468
|
+
const t = this.querySelector(`#${this.optionId(this.active)}`);
|
|
1469
|
+
(e = t == null ? void 0 : t.scrollIntoView) == null || e.call(t, { block: "nearest" });
|
|
1470
|
+
}
|
|
1471
|
+
openList() {
|
|
1472
|
+
!this.interactive || this.open || (this.active = this.selectedIndex, this.open = !0, S() && document.addEventListener("mousedown", this.onDocMousedown));
|
|
1473
|
+
}
|
|
1474
|
+
close() {
|
|
1475
|
+
this.open && (this.open = !1, S() && document.removeEventListener("mousedown", this.onDocMousedown));
|
|
1476
|
+
}
|
|
1477
|
+
toggle() {
|
|
1478
|
+
this.open ? this.close() : this.openList();
|
|
1479
|
+
}
|
|
1480
|
+
commit(t) {
|
|
1481
|
+
const e = this.rows[t];
|
|
1482
|
+
this.close(), e && this.emitInput(e.key === "" ? null : e.key);
|
|
1483
|
+
}
|
|
1484
|
+
highlight(t) {
|
|
1485
|
+
this.active !== t && (this.active = t);
|
|
1486
|
+
}
|
|
1487
|
+
move(t) {
|
|
1488
|
+
const e = this.rows.length - 1;
|
|
1489
|
+
this.active = Math.min(e, Math.max(0, this.active + t));
|
|
1490
|
+
}
|
|
1491
|
+
/** Type-to-select: first option (after the highlighted one) starting with the buffer. */
|
|
1492
|
+
typeahead(t) {
|
|
1493
|
+
clearTimeout(this.typeTimer), this.typeBuffer += t.toLowerCase(), this.typeTimer = setTimeout(() => this.typeBuffer = "", ba);
|
|
1494
|
+
const e = this.rows, i = this.typeBuffer.length === 1 ? this.active + 1 : this.active;
|
|
1495
|
+
for (let a = 0; a < e.length; a++) {
|
|
1496
|
+
const s = (i + a) % e.length;
|
|
1497
|
+
if (s !== 0 && e[s].label.toLowerCase().startsWith(this.typeBuffer)) {
|
|
1498
|
+
this.open ? this.active = s : this.commit(s);
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
onKeydown(t) {
|
|
1504
|
+
if (!this.interactive) return;
|
|
1505
|
+
const { key: e } = t;
|
|
1506
|
+
if (!this.open) {
|
|
1507
|
+
e === "ArrowDown" || e === "ArrowUp" || e === "Enter" || e === " " ? (t.preventDefault(), this.openList()) : e === "Home" || e === "End" ? (t.preventDefault(), this.commit(e === "Home" ? Math.min(1, this.rows.length - 1) : this.rows.length - 1)) : e.length === 1 && !t.altKey && !t.ctrlKey && !t.metaKey && this.typeahead(e);
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
switch (e) {
|
|
1511
|
+
case "ArrowDown":
|
|
1512
|
+
t.preventDefault(), this.move(1);
|
|
1513
|
+
break;
|
|
1514
|
+
case "ArrowUp":
|
|
1515
|
+
t.preventDefault(), this.move(-1);
|
|
1516
|
+
break;
|
|
1517
|
+
case "Home":
|
|
1518
|
+
t.preventDefault(), this.active = 0;
|
|
1519
|
+
break;
|
|
1520
|
+
case "End":
|
|
1521
|
+
t.preventDefault(), this.active = this.rows.length - 1;
|
|
1522
|
+
break;
|
|
1523
|
+
case "Enter":
|
|
1524
|
+
case " ":
|
|
1525
|
+
t.preventDefault(), this.commit(this.active);
|
|
1526
|
+
break;
|
|
1527
|
+
case "Escape":
|
|
1528
|
+
t.preventDefault(), this.close();
|
|
1529
|
+
break;
|
|
1530
|
+
case "Tab":
|
|
1531
|
+
this.commit(this.active);
|
|
1532
|
+
break;
|
|
1533
|
+
default:
|
|
1534
|
+
e.length === 1 && !t.altKey && !t.ctrlKey && !t.metaKey && this.typeahead(e);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
renderControl() {
|
|
1538
|
+
const t = this.rows, e = this.selectedIndex, i = e === 0;
|
|
1539
|
+
return n`<div class="baht-select${this.open ? " baht-select--open" : ""}">
|
|
1540
|
+
<button
|
|
1541
|
+
type="button"
|
|
1542
|
+
class="baht-control baht-control--select baht-select-trigger${i ? " baht-select-trigger--placeholder" : ""}"
|
|
1543
|
+
id=${this.controlId}
|
|
1544
|
+
role="combobox"
|
|
1545
|
+
aria-haspopup="listbox"
|
|
1546
|
+
aria-expanded=${this.open ? "true" : "false"}
|
|
1547
|
+
aria-controls=${this.listId}
|
|
1548
|
+
aria-labelledby=${this.field.label ? this.labelId : h}
|
|
1549
|
+
aria-activedescendant=${this.open ? this.optionId(this.active) : h}
|
|
1550
|
+
aria-required=${this.required ? "true" : h}
|
|
1551
|
+
aria-invalid=${this.invalid}
|
|
1552
|
+
aria-describedby=${this.describedBy}
|
|
1553
|
+
?disabled=${this.disabled}
|
|
1554
|
+
aria-readonly=${this.readonly && !this.disabled ? "true" : h}
|
|
1555
|
+
@click=${() => this.toggle()}
|
|
1556
|
+
@keydown=${(a) => this.onKeydown(a)}
|
|
1557
|
+
>
|
|
1558
|
+
<span class="baht-select-value">${t[e].label}</span>
|
|
1559
|
+
<span class="baht-select-chevron" aria-hidden="true">▾</span>
|
|
1560
|
+
</button>
|
|
1561
|
+
<div
|
|
1562
|
+
class="baht-listbox baht-select-list"
|
|
1563
|
+
id=${this.listId}
|
|
1564
|
+
role="listbox"
|
|
1565
|
+
aria-labelledby=${this.field.label ? this.labelId : h}
|
|
1566
|
+
?hidden=${!this.open}
|
|
1567
|
+
>
|
|
1568
|
+
${t.map(
|
|
1569
|
+
// eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox (aria-activedescendant pattern); options are never focused
|
|
1570
|
+
(a, s) => n`<div
|
|
1571
|
+
class="baht-listbox-option${s === this.active ? " baht-listbox-option--active" : ""}${s === 0 ? " baht-listbox-option--placeholder" : ""}"
|
|
1572
|
+
id=${this.optionId(s)}
|
|
1573
|
+
role="option"
|
|
1574
|
+
aria-selected=${s === e ? "true" : "false"}
|
|
1575
|
+
data-key=${a.key}
|
|
1576
|
+
@mousedown=${(r) => r.preventDefault()}
|
|
1577
|
+
@mousemove=${() => this.highlight(s)}
|
|
1578
|
+
@click=${() => this.commit(s)}
|
|
1579
|
+
>
|
|
1580
|
+
${a.label}
|
|
1581
|
+
</div>`
|
|
1582
|
+
)}
|
|
1583
|
+
</div>
|
|
1584
|
+
</div>`;
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
Te([
|
|
1588
|
+
$()
|
|
1589
|
+
], oe.prototype, "open", 2);
|
|
1590
|
+
Te([
|
|
1591
|
+
$()
|
|
1592
|
+
], oe.prototype, "active", 2);
|
|
1593
|
+
oe = Te([
|
|
1594
|
+
b("baht-select")
|
|
1595
|
+
], oe);
|
|
1596
|
+
var fa = Object.getOwnPropertyDescriptor, ma = (t, e, i, a) => {
|
|
1597
|
+
for (var s = a > 1 ? void 0 : a ? fa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1598
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1599
|
+
return s;
|
|
1600
|
+
};
|
|
1601
|
+
let ze = class extends J {
|
|
1602
|
+
get selected() {
|
|
1603
|
+
return Array.isArray(this.value) ? this.value : [];
|
|
1604
|
+
}
|
|
1605
|
+
toggle(t, e) {
|
|
1606
|
+
const i = e ? [...this.selected, t] : this.selected.filter((s) => s !== t), a = (this.field.options ?? []).map((s) => s.key);
|
|
1607
|
+
this.emitInput(a.filter((s) => i.includes(s)));
|
|
1608
|
+
}
|
|
1609
|
+
renderControl() {
|
|
1610
|
+
return n`<div
|
|
1611
|
+
class="baht-control baht-control--multiselect"
|
|
1612
|
+
role="group"
|
|
1613
|
+
aria-labelledby=${this.field.label ? this.labelId : h}
|
|
1614
|
+
aria-describedby=${this.describedBy}
|
|
1615
|
+
>
|
|
1616
|
+
${(this.field.options ?? []).map(
|
|
1617
|
+
(t) => n`<label class="baht-option">
|
|
1618
|
+
<input
|
|
1619
|
+
type="checkbox"
|
|
1620
|
+
value=${t.key}
|
|
1621
|
+
.checked=${ot(this.selected.includes(t.key))}
|
|
1622
|
+
?disabled=${this.disabled || this.readonly}
|
|
1623
|
+
@change=${(e) => this.toggle(t.key, e.target.checked)}
|
|
1624
|
+
/>
|
|
1625
|
+
<span>${t.label}</span>
|
|
1626
|
+
</label>`
|
|
1627
|
+
)}
|
|
1628
|
+
</div>`;
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
ze = ma([
|
|
1632
|
+
b("baht-multiselect")
|
|
1633
|
+
], ze);
|
|
1634
|
+
var va = Object.getOwnPropertyDescriptor, $a = (t, e, i, a) => {
|
|
1635
|
+
for (var s = a > 1 ? void 0 : a ? va(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1636
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1637
|
+
return s;
|
|
1638
|
+
};
|
|
1639
|
+
let Ve = class extends J {
|
|
1640
|
+
/** Label sits beside the box, so suppress the block label. */
|
|
1641
|
+
renderLabel() {
|
|
1642
|
+
return h;
|
|
1643
|
+
}
|
|
1644
|
+
renderControl() {
|
|
1645
|
+
return n`<label class="baht-control baht-control--checkbox baht-option">
|
|
1646
|
+
<input
|
|
1647
|
+
type="checkbox"
|
|
1648
|
+
id=${this.controlId}
|
|
1649
|
+
.checked=${ot(this.value === !0)}
|
|
1650
|
+
?disabled=${this.disabled || this.readonly}
|
|
1651
|
+
?required=${this.required}
|
|
1652
|
+
aria-invalid=${this.invalid}
|
|
1653
|
+
aria-describedby=${this.describedBy}
|
|
1654
|
+
@change=${(t) => this.emitInput(t.target.checked)}
|
|
1655
|
+
/>
|
|
1656
|
+
<span class="baht-label"
|
|
1657
|
+
>${this.field.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</span
|
|
1658
|
+
>
|
|
1659
|
+
</label>`;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
Ve = $a([
|
|
1663
|
+
b("baht-checkbox")
|
|
1664
|
+
], Ve);
|
|
1665
|
+
var ya = Object.getOwnPropertyDescriptor, ga = (t, e, i, a) => {
|
|
1666
|
+
for (var s = a > 1 ? void 0 : a ? ya(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1667
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1668
|
+
return s;
|
|
1669
|
+
};
|
|
1670
|
+
let Ke = class extends J {
|
|
1671
|
+
renderControl() {
|
|
1672
|
+
return n`<div
|
|
1673
|
+
class="baht-control baht-control--radio"
|
|
1674
|
+
role="radiogroup"
|
|
1675
|
+
aria-labelledby=${this.field.label ? this.labelId : h}
|
|
1676
|
+
aria-required=${this.required ? "true" : h}
|
|
1677
|
+
aria-invalid=${this.invalid}
|
|
1678
|
+
aria-describedby=${this.describedBy}
|
|
1679
|
+
>
|
|
1680
|
+
${(this.field.options ?? []).map(
|
|
1681
|
+
(t) => n`<label class="baht-option">
|
|
1682
|
+
<input
|
|
1683
|
+
type="radio"
|
|
1684
|
+
name=${this.controlId}
|
|
1685
|
+
value=${t.key}
|
|
1686
|
+
.checked=${ot(this.value === t.key)}
|
|
1687
|
+
?disabled=${this.disabled || this.readonly}
|
|
1688
|
+
@change=${() => this.emitInput(t.key)}
|
|
1689
|
+
/>
|
|
1690
|
+
<span>${t.label}</span>
|
|
1691
|
+
</label>`
|
|
1692
|
+
)}
|
|
1693
|
+
</div>`;
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
Ke = ga([
|
|
1697
|
+
b("baht-radio")
|
|
1698
|
+
], Ke);
|
|
1699
|
+
var wa = Object.getOwnPropertyDescriptor, xa = (t, e, i, a) => {
|
|
1700
|
+
for (var s = a > 1 ? void 0 : a ? wa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1701
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1702
|
+
return s;
|
|
1703
|
+
};
|
|
1704
|
+
let Ue = class extends J {
|
|
1705
|
+
renderLabel() {
|
|
1706
|
+
return h;
|
|
1707
|
+
}
|
|
1708
|
+
renderControl() {
|
|
1709
|
+
return n`<label class="baht-control baht-control--toggle baht-option">
|
|
1710
|
+
<input
|
|
1711
|
+
type="checkbox"
|
|
1712
|
+
role="switch"
|
|
1713
|
+
id=${this.controlId}
|
|
1714
|
+
aria-checked=${this.value === !0 ? "true" : "false"}
|
|
1715
|
+
.checked=${ot(this.value === !0)}
|
|
1716
|
+
?disabled=${this.disabled || this.readonly}
|
|
1717
|
+
?required=${this.required}
|
|
1718
|
+
aria-invalid=${this.invalid}
|
|
1719
|
+
aria-describedby=${this.describedBy}
|
|
1720
|
+
@change=${(t) => this.emitInput(t.target.checked)}
|
|
1721
|
+
/>
|
|
1722
|
+
<span class="baht-toggle-track"><span class="baht-toggle-thumb"></span></span>
|
|
1723
|
+
<span class="baht-label"
|
|
1724
|
+
>${this.field.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</span
|
|
1725
|
+
>
|
|
1726
|
+
</label>`;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
Ue = xa([
|
|
1730
|
+
b("baht-toggle")
|
|
1731
|
+
], Ue);
|
|
1732
|
+
var _a = Object.getOwnPropertyDescriptor, ka = (t, e, i, a) => {
|
|
1733
|
+
for (var s = a > 1 ? void 0 : a ? _a(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1734
|
+
(o = t[r]) && (s = o(s) || s);
|
|
1735
|
+
return s;
|
|
1736
|
+
};
|
|
1737
|
+
let He = class extends J {
|
|
1738
|
+
constructor() {
|
|
1739
|
+
super(...arguments), this.lastEmitted = null;
|
|
1740
|
+
}
|
|
1741
|
+
renderControl() {
|
|
1742
|
+
return n`<input
|
|
1743
|
+
class="baht-control baht-control--date"
|
|
1744
|
+
id=${this.controlId}
|
|
1745
|
+
type="text"
|
|
1746
|
+
autocomplete="off"
|
|
1747
|
+
placeholder=${L(this.field.placeholder)}
|
|
1748
|
+
?disabled=${this.disabled}
|
|
1749
|
+
?readonly=${this.readonly}
|
|
1750
|
+
?required=${this.required}
|
|
1751
|
+
aria-invalid=${this.invalid}
|
|
1752
|
+
aria-describedby=${this.describedBy}
|
|
1753
|
+
/>`;
|
|
1754
|
+
}
|
|
1755
|
+
connectedCallback() {
|
|
1756
|
+
super.connectedCallback(), this.hasUpdated && this.requestUpdate();
|
|
1757
|
+
}
|
|
1758
|
+
disconnectedCallback() {
|
|
1759
|
+
super.disconnectedCallback(), this.teardown();
|
|
1760
|
+
}
|
|
1761
|
+
updated(t) {
|
|
1762
|
+
const e = this.querySelector("input.baht-control--date");
|
|
1763
|
+
if (!e) {
|
|
1764
|
+
this.teardown();
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
if (!this.fp || this.fp.input !== e || t.has("field") || t.has("disabled") || t.has("readonly")) {
|
|
1768
|
+
this.teardown(), this.fp = $s(e, this.options());
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
t.has("value") && (this.lastEmitted = null, this.syncValue());
|
|
1772
|
+
}
|
|
1773
|
+
teardown() {
|
|
1774
|
+
var t;
|
|
1775
|
+
(t = this.fp) == null || t.destroy(), this.fp = void 0, this.todayBtn = void 0, this.clearBtn = void 0;
|
|
1776
|
+
}
|
|
1777
|
+
/** Push the host-fed `value` into the calendar without echoing an event. */
|
|
1778
|
+
syncValue() {
|
|
1779
|
+
if (!this.fp) return;
|
|
1780
|
+
const t = this.datesOf(this.value);
|
|
1781
|
+
We(this.fp.selectedDates, t) || (t.length === 0 ? this.fp.clear(!1) : this.fp.setDate(t, !1));
|
|
1782
|
+
}
|
|
1783
|
+
options() {
|
|
1784
|
+
const t = this.field, e = $e(t), i = Lt(t.min), a = Lt(t.max);
|
|
1785
|
+
return {
|
|
1786
|
+
static: !0,
|
|
1787
|
+
disableMobile: !0,
|
|
1788
|
+
// our calendar everywhere — never the OS date wheel
|
|
1789
|
+
mode: e,
|
|
1790
|
+
dateFormat: t.date_format ?? "Y-m-d",
|
|
1791
|
+
allowInput: !0,
|
|
1792
|
+
clickOpens: !this.disabled && !this.readonly,
|
|
1793
|
+
defaultDate: this.datesOf(this.value),
|
|
1794
|
+
...i ? { minDate: i } : {},
|
|
1795
|
+
...a ? { maxDate: a } : {},
|
|
1796
|
+
disable: Je(t),
|
|
1797
|
+
onReady: (s, r, o) => this.mountFooter(o),
|
|
1798
|
+
onOpen: () => this.refreshFooter(),
|
|
1799
|
+
onChange: (s) => {
|
|
1800
|
+
this.refreshFooter(), !(e === "range" && s.length === 1) && this.emitIfChanged(s);
|
|
1801
|
+
},
|
|
1802
|
+
onClose: (s) => {
|
|
1803
|
+
var r, o;
|
|
1804
|
+
e === "range" && s.length === 1 && ((r = this.fp) == null || r.clear(!1)), this.emitIfChanged(((o = this.fp) == null ? void 0 : o.selectedDates) ?? []);
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
// ---- footer: Today / Clear ------------------------------------------
|
|
1809
|
+
mountFooter(t) {
|
|
1810
|
+
const e = document.createElement("div");
|
|
1811
|
+
e.className = "baht-datepicker-footer";
|
|
1812
|
+
const i = document.createElement("button");
|
|
1813
|
+
i.type = "button", i.className = "baht-button baht-button--sm baht-datepicker-today", i.textContent = m("today"), i.addEventListener("click", () => this.pickToday());
|
|
1814
|
+
const a = document.createElement("button");
|
|
1815
|
+
a.type = "button", a.className = "baht-button baht-button--danger baht-button--sm baht-datepicker-clear", a.textContent = m("clear"), a.addEventListener("click", () => {
|
|
1816
|
+
var s, r;
|
|
1817
|
+
(s = this.fp) == null || s.clear(), (r = this.fp) == null || r.close();
|
|
1818
|
+
}), e.append(i, a), t.calendarContainer.appendChild(e), this.todayBtn = i, this.clearBtn = a, this.refreshFooter(t);
|
|
1819
|
+
}
|
|
1820
|
+
/** Today greys out when the rules exclude it; Clear when there is nothing to clear.
|
|
1821
|
+
* `fp` is passed explicitly from onReady — it fires inside the flatpickr()
|
|
1822
|
+
* call, before `this.fp` is assigned. */
|
|
1823
|
+
refreshFooter(t = this.fp) {
|
|
1824
|
+
t && (this.todayBtn && (this.todayBtn.disabled = !this.todayAllowed()), this.clearBtn && (this.clearBtn.disabled = t.selectedDates.length === 0));
|
|
1825
|
+
}
|
|
1826
|
+
todayAllowed() {
|
|
1827
|
+
const t = _t(/* @__PURE__ */ new Date()), e = Lt(this.field.min), i = Lt(this.field.max);
|
|
1828
|
+
if (e && t < _t(e) || i && t > _t(i)) return !1;
|
|
1829
|
+
for (const a of Je(this.field) ?? [])
|
|
1830
|
+
if (a instanceof Date) {
|
|
1831
|
+
if (Ge(a, t)) return !1;
|
|
1832
|
+
} else if (typeof a == "function") {
|
|
1833
|
+
if (a(t)) return !1;
|
|
1834
|
+
} else if (typeof a == "object" && "from" in a) {
|
|
1835
|
+
const s = _t(new Date(a.from)), r = _t(new Date(a.to));
|
|
1836
|
+
if (t >= s && t <= r) return !1;
|
|
1837
|
+
}
|
|
1838
|
+
return !0;
|
|
1839
|
+
}
|
|
1840
|
+
pickToday() {
|
|
1841
|
+
const t = this.fp;
|
|
1842
|
+
if (!t || !this.todayAllowed()) return;
|
|
1843
|
+
const e = _t(/* @__PURE__ */ new Date());
|
|
1844
|
+
switch ($e(this.field)) {
|
|
1845
|
+
case "range":
|
|
1846
|
+
t.setDate([e, e], !0);
|
|
1847
|
+
break;
|
|
1848
|
+
case "multiple": {
|
|
1849
|
+
t.selectedDates.some((a) => Ge(a, e)) || t.setDate([...t.selectedDates, e], !0);
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
default:
|
|
1853
|
+
t.setDate(e, !0);
|
|
1854
|
+
}
|
|
1855
|
+
t.close();
|
|
1856
|
+
}
|
|
1857
|
+
emitIfChanged(t) {
|
|
1858
|
+
const e = this.lastEmitted ?? this.datesOf(this.value);
|
|
1859
|
+
We(t, e) || (this.lastEmitted = [...t], this.emitInput(this.toValue(t)));
|
|
1860
|
+
}
|
|
1861
|
+
/** Host value (any mode) -> the Date list flatpickr works with. */
|
|
1862
|
+
datesOf(t) {
|
|
1863
|
+
return ds(t).map(Lt).filter((e) => e !== null);
|
|
1864
|
+
}
|
|
1865
|
+
/** flatpickr's selection -> the value shape of the field's mode. */
|
|
1866
|
+
toValue(t) {
|
|
1867
|
+
const e = t.map(Rt);
|
|
1868
|
+
switch ($e(this.field)) {
|
|
1869
|
+
case "range":
|
|
1870
|
+
return e.length === 2 ? [e[0], e[1]] : null;
|
|
1871
|
+
case "multiple":
|
|
1872
|
+
return e;
|
|
1873
|
+
default:
|
|
1874
|
+
return e[0] ?? null;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
He = ka([
|
|
1879
|
+
b("baht-datepicker")
|
|
1880
|
+
], He);
|
|
1881
|
+
function _t(t) {
|
|
1882
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate());
|
|
1883
|
+
}
|
|
1884
|
+
function Ge(t, e) {
|
|
1885
|
+
return Rt(t) === Rt(e);
|
|
1886
|
+
}
|
|
1887
|
+
function We(t, e) {
|
|
1888
|
+
return t.length !== e.length ? !1 : t.every((i, a) => Rt(i) === Rt(e[a]));
|
|
1889
|
+
}
|
|
1890
|
+
function Je(t) {
|
|
1891
|
+
const e = [];
|
|
1892
|
+
for (const a of t.disabled_dates ?? []) {
|
|
1893
|
+
const s = us(a);
|
|
1894
|
+
s && e.push(s[0].getTime() === s[1].getTime() ? s[0] : { from: s[0], to: s[1] });
|
|
1895
|
+
}
|
|
1896
|
+
const i = t.disabled_weekdays;
|
|
1897
|
+
return i != null && i.length && e.push((a) => i.includes(a.getDay())), e;
|
|
1898
|
+
}
|
|
1899
|
+
var Pa = Object.defineProperty, Oa = Object.getOwnPropertyDescriptor, Zt = (t, e, i, a) => {
|
|
1900
|
+
for (var s = a > 1 ? void 0 : a ? Oa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
1901
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
1902
|
+
return a && s && Pa(e, i, s), s;
|
|
1903
|
+
};
|
|
1904
|
+
function Ye(t) {
|
|
1905
|
+
return t !== null && typeof t == "object" && typeof t.url == "string";
|
|
1906
|
+
}
|
|
1907
|
+
function ge(t) {
|
|
1908
|
+
return t >= 1024 * 1024 ? `${(t / 1024 / 1024).toFixed(1)} MB` : t >= 1024 ? `${Math.round(t / 1024)} KB` : `${t} B`;
|
|
1909
|
+
}
|
|
1910
|
+
let Ft = class extends J {
|
|
1911
|
+
constructor() {
|
|
1912
|
+
super(...arguments), this.uploadingCount = 0, this.uploadError = null, this.rejectedNames = [];
|
|
1913
|
+
}
|
|
1914
|
+
get refs() {
|
|
1915
|
+
return Array.isArray(this.value) ? this.value.filter(Ye) : Ye(this.value) ? [this.value] : [];
|
|
1916
|
+
}
|
|
1917
|
+
emitRefs(t) {
|
|
1918
|
+
this.emitInput(this.field.multiple ? t : t[0] ?? null);
|
|
1919
|
+
}
|
|
1920
|
+
async uploadAll(t) {
|
|
1921
|
+
if (!this.uploader) return;
|
|
1922
|
+
this.uploadError = null, this.uploadingCount += t.length;
|
|
1923
|
+
const e = this.field.multiple ? [...this.refs] : [];
|
|
1924
|
+
for (const i of t)
|
|
1925
|
+
try {
|
|
1926
|
+
e.push(await this.uploader(i));
|
|
1927
|
+
} catch {
|
|
1928
|
+
this.uploadError = m("uploadFailed");
|
|
1929
|
+
} finally {
|
|
1930
|
+
this.uploadingCount -= 1;
|
|
1931
|
+
}
|
|
1932
|
+
this.emitRefs(e);
|
|
1933
|
+
}
|
|
1934
|
+
onPick(t) {
|
|
1935
|
+
const e = t.target;
|
|
1936
|
+
this.take(Array.from(e.files ?? []), e);
|
|
1937
|
+
}
|
|
1938
|
+
take(t, e) {
|
|
1939
|
+
const i = this.field.max_size, a = i ? t.filter((r) => r.size <= i) : t, s = i ? t.filter((r) => r.size > i) : [];
|
|
1940
|
+
if (this.rejectedNames = s.map((r) => r.name), this.uploader) {
|
|
1941
|
+
e && (e.value = ""), this.uploadAll(a);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
this.emitInput(this.field.multiple ? a : a[0] ?? null);
|
|
1945
|
+
}
|
|
1946
|
+
get captured() {
|
|
1947
|
+
return this.uploader ? [] : Array.isArray(this.value) ? this.value.filter((t) => t instanceof File) : this.value instanceof File ? [this.value] : [];
|
|
1948
|
+
}
|
|
1949
|
+
hintText() {
|
|
1950
|
+
const t = [];
|
|
1951
|
+
return this.field.accept && t.push(
|
|
1952
|
+
this.field.accept.split(",").map((e) => e.trim()).join(", ")
|
|
1953
|
+
), this.field.max_size && t.push(m("uploadMaxSize", { size: ge(this.field.max_size) })), t.join(" · ");
|
|
1954
|
+
}
|
|
1955
|
+
renderControl() {
|
|
1956
|
+
const t = this.disabled || this.readonly || this.uploadingCount > 0, e = this.hintText(), i = [
|
|
1957
|
+
"baht-dropzone",
|
|
1958
|
+
t ? "baht-dropzone--disabled" : "",
|
|
1959
|
+
this.invalid === "true" ? "baht-dropzone--invalid" : ""
|
|
1960
|
+
].filter(Boolean).join(" ");
|
|
1961
|
+
return n`<div
|
|
1962
|
+
class=${i}
|
|
1963
|
+
@dragover=${(a) => {
|
|
1964
|
+
t || (a.preventDefault(), a.currentTarget.classList.add("baht-dropzone--over"));
|
|
1965
|
+
}}
|
|
1966
|
+
@dragleave=${(a) => a.currentTarget.classList.remove("baht-dropzone--over")}
|
|
1967
|
+
@drop=${(a) => {
|
|
1968
|
+
var s;
|
|
1969
|
+
a.preventDefault(), a.currentTarget.classList.remove("baht-dropzone--over"), t || this.take(Array.from(((s = a.dataTransfer) == null ? void 0 : s.files) ?? []));
|
|
1970
|
+
}}
|
|
1971
|
+
>
|
|
1972
|
+
<input
|
|
1973
|
+
class="baht-control baht-control--file baht-dropzone-input"
|
|
1974
|
+
id=${this.controlId}
|
|
1975
|
+
type="file"
|
|
1976
|
+
accept=${L(this.field.accept)}
|
|
1977
|
+
?multiple=${this.field.multiple}
|
|
1978
|
+
?disabled=${t}
|
|
1979
|
+
?required=${this.required}
|
|
1980
|
+
aria-invalid=${this.invalid}
|
|
1981
|
+
aria-describedby=${this.describedBy}
|
|
1982
|
+
@change=${(a) => this.onPick(a)}
|
|
1983
|
+
/>
|
|
1984
|
+
<span class="baht-dropzone-icon" aria-hidden="true">${H("upload")}</span>
|
|
1985
|
+
<span class="baht-dropzone-text">
|
|
1986
|
+
<label class="baht-dropzone-action" for=${this.controlId}
|
|
1987
|
+
>${this.field.multiple ? m("chooseFiles") : m("chooseFile")}</label
|
|
1988
|
+
>
|
|
1989
|
+
<span class="baht-dropzone-or">${m("orDropHere")}</span>
|
|
1990
|
+
</span>
|
|
1991
|
+
${e ? n`<span class="baht-dropzone-hint">${e}</span>` : h}
|
|
1992
|
+
</div>
|
|
1993
|
+
${this.uploadingCount > 0 ? n`<p class="baht-file-status" role="status">${m("uploading")}</p>` : h}
|
|
1994
|
+
${this.uploadError ? n`<p class="baht-error" role="alert">${this.uploadError}</p>` : h}
|
|
1995
|
+
${this.rejectedNames.length > 0 ? n`<p class="baht-error baht-file-rejected" role="alert">
|
|
1996
|
+
${m("fileRejectedTooLarge", { names: this.rejectedNames.join(", ") })}
|
|
1997
|
+
</p>` : h}
|
|
1998
|
+
${this.captured.map(
|
|
1999
|
+
(a) => n`<span class="baht-file-chip">
|
|
2000
|
+
<span class="baht-file-name">${a.name}</span>
|
|
2001
|
+
<span class="baht-file-size">${ge(a.size)}</span>
|
|
2002
|
+
</span>`
|
|
2003
|
+
)}
|
|
2004
|
+
${this.refs.map(
|
|
2005
|
+
(a) => n`<span class="baht-file-chip">
|
|
2006
|
+
<a href=${a.url} target="_blank" rel="noreferrer"
|
|
2007
|
+
>${a.name}<span class="baht-visually-hidden"> (${m("opensInNewTab")})</span></a
|
|
2008
|
+
>
|
|
2009
|
+
<span class="baht-file-size">${ge(a.size)}</span>
|
|
2010
|
+
${this.disabled || this.readonly ? h : n`<button
|
|
2011
|
+
type="button"
|
|
2012
|
+
class="baht-file-remove"
|
|
2013
|
+
aria-label=${m("removeFile")}
|
|
2014
|
+
title=${m("removeFile")}
|
|
2015
|
+
@click=${() => this.emitRefs(this.refs.filter((s) => s !== a))}
|
|
2016
|
+
>
|
|
2017
|
+
${H("close")}
|
|
2018
|
+
</button>`}
|
|
2019
|
+
</span>`
|
|
2020
|
+
)}`;
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
Zt([
|
|
2024
|
+
l({ attribute: !1 })
|
|
2025
|
+
], Ft.prototype, "uploader", 2);
|
|
2026
|
+
Zt([
|
|
2027
|
+
$()
|
|
2028
|
+
], Ft.prototype, "uploadingCount", 2);
|
|
2029
|
+
Zt([
|
|
2030
|
+
$()
|
|
2031
|
+
], Ft.prototype, "uploadError", 2);
|
|
2032
|
+
Zt([
|
|
2033
|
+
$()
|
|
2034
|
+
], Ft.prototype, "rejectedNames", 2);
|
|
2035
|
+
Ft = Zt([
|
|
2036
|
+
b("baht-file")
|
|
2037
|
+
], Ft);
|
|
2038
|
+
var Ca = Object.defineProperty, Da = Object.getOwnPropertyDescriptor, B = (t, e, i, a) => {
|
|
2039
|
+
for (var s = a > 1 ? void 0 : a ? Da(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2040
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2041
|
+
return a && s && Ca(e, i, s), s;
|
|
2042
|
+
};
|
|
2043
|
+
function Fa(t, e) {
|
|
2044
|
+
return e.split(".").reduce((i, a) => {
|
|
2045
|
+
if (i !== null && typeof i == "object") return i[a];
|
|
2046
|
+
}, t);
|
|
2047
|
+
}
|
|
2048
|
+
function Ea(t, e) {
|
|
2049
|
+
const i = t.trim();
|
|
2050
|
+
if (!i) return null;
|
|
2051
|
+
try {
|
|
2052
|
+
const a = JSON.parse(i);
|
|
2053
|
+
if (typeof a == "string") return a;
|
|
2054
|
+
const s = e ? Fa(a, e) : a;
|
|
2055
|
+
return typeof s == "string" && s ? s : null;
|
|
2056
|
+
} catch {
|
|
2057
|
+
return /^(https?:\/\/|\/|data:|blob:)/.test(i) ? i : null;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
function Ba(t) {
|
|
2061
|
+
const i = (t.split(/[?#]/)[0] ?? t).split("/").filter(Boolean).pop() ?? t;
|
|
2062
|
+
try {
|
|
2063
|
+
return decodeURIComponent(i);
|
|
2064
|
+
} catch {
|
|
2065
|
+
return i;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
function we(t) {
|
|
2069
|
+
return t >= 1024 * 1024 ? `${(t / 1024 / 1024).toFixed(1)} MB` : t >= 1024 ? `${Math.round(t / 1024)} KB` : `${t} B`;
|
|
2070
|
+
}
|
|
2071
|
+
let D = class extends y {
|
|
2072
|
+
constructor() {
|
|
2073
|
+
super(...arguments), this.url = "", this.method = "POST", this.fieldName = "file", this.responseKey = "url", this.headers = {}, this.withCredentials = !1, this.value = null, this.label = "", this.hint = "", this.multiple = !1, this.disabled = !1, this.required = !1, this.error = null, this.pending = [], this.rejectedNames = [], this.dragging = !1, this.known = /* @__PURE__ */ new Map(), this.seq = 0;
|
|
2074
|
+
}
|
|
2075
|
+
get urls() {
|
|
2076
|
+
return Array.isArray(this.value) ? this.value.filter((t) => typeof t == "string" && t) : typeof this.value == "string" && this.value ? [this.value] : [];
|
|
2077
|
+
}
|
|
2078
|
+
get inputId() {
|
|
2079
|
+
return `baht-upload-${this.uid}`;
|
|
2080
|
+
}
|
|
2081
|
+
fileFor(t) {
|
|
2082
|
+
return this.known.get(t) ?? { name: Ba(t), size: 0, url: t };
|
|
2083
|
+
}
|
|
2084
|
+
/** Empty the value (does not delete anything on the server). */
|
|
2085
|
+
clear() {
|
|
2086
|
+
this.emitValue([]);
|
|
2087
|
+
}
|
|
2088
|
+
emitValue(t) {
|
|
2089
|
+
const e = this.multiple ? t : t[0] ?? null;
|
|
2090
|
+
this.value = e, this.dispatchEvent(
|
|
2091
|
+
new CustomEvent("baht-change", {
|
|
2092
|
+
detail: { value: e, files: t.map((i) => this.fileFor(i)) },
|
|
2093
|
+
bubbles: !0,
|
|
2094
|
+
composed: !0
|
|
2095
|
+
})
|
|
2096
|
+
);
|
|
2097
|
+
}
|
|
2098
|
+
accept_(t) {
|
|
2099
|
+
if (this.disabled || t.length === 0) return;
|
|
2100
|
+
const e = this.maxSize, i = e ? t.filter((s) => s.size <= e) : t;
|
|
2101
|
+
this.rejectedNames = e ? t.filter((s) => s.size > e).map((s) => s.name) : [];
|
|
2102
|
+
const a = this.multiple ? i : i.slice(0, 1);
|
|
2103
|
+
for (const s of a) this.start(s);
|
|
2104
|
+
}
|
|
2105
|
+
onPick(t) {
|
|
2106
|
+
const e = t.target;
|
|
2107
|
+
this.accept_(Array.from(e.files ?? [])), e.value = "";
|
|
2108
|
+
}
|
|
2109
|
+
onDragOver(t) {
|
|
2110
|
+
this.disabled || (t.preventDefault(), this.dragging = !0);
|
|
2111
|
+
}
|
|
2112
|
+
onDragLeave() {
|
|
2113
|
+
this.dragging = !1;
|
|
2114
|
+
}
|
|
2115
|
+
onDrop(t) {
|
|
2116
|
+
var e;
|
|
2117
|
+
t.preventDefault(), this.dragging = !1, this.accept_(Array.from(((e = t.dataTransfer) == null ? void 0 : e.files) ?? []));
|
|
2118
|
+
}
|
|
2119
|
+
start(t) {
|
|
2120
|
+
const e = { id: ++this.seq, file: t, percent: 0, error: null };
|
|
2121
|
+
this.pending = this.multiple ? [...this.pending, e] : [e], this.dispatchEvent(
|
|
2122
|
+
new CustomEvent("baht-upload-start", { detail: { file: t }, bubbles: !0, composed: !0 })
|
|
2123
|
+
), this.send(e);
|
|
2124
|
+
}
|
|
2125
|
+
patch(t, e) {
|
|
2126
|
+
this.pending = this.pending.map((i) => i.id === t ? { ...i, ...e } : i);
|
|
2127
|
+
}
|
|
2128
|
+
send(t) {
|
|
2129
|
+
const e = new XMLHttpRequest();
|
|
2130
|
+
e.open(this.method || "POST", this.url);
|
|
2131
|
+
for (const [a, s] of Object.entries(this.headers ?? {})) e.setRequestHeader(a, s);
|
|
2132
|
+
e.withCredentials = this.withCredentials, e.upload.onprogress = (a) => {
|
|
2133
|
+
const s = a.total > 0 ? Math.round(a.loaded / a.total * 100) : 0;
|
|
2134
|
+
this.patch(t.id, { percent: s }), this.dispatchEvent(
|
|
2135
|
+
new CustomEvent("baht-upload-progress", {
|
|
2136
|
+
detail: { file: t.file, loaded: a.loaded, total: a.total, percent: s },
|
|
2137
|
+
bubbles: !0,
|
|
2138
|
+
composed: !0
|
|
2139
|
+
})
|
|
2140
|
+
);
|
|
2141
|
+
}, e.onload = () => {
|
|
2142
|
+
const a = e.status >= 200 && e.status < 300, s = a ? Ea(e.responseText, this.responseKey) : null;
|
|
2143
|
+
if (!a || !s) return this.failed(t, a ? 0 : e.status);
|
|
2144
|
+
this.known.set(s, {
|
|
2145
|
+
name: t.file.name,
|
|
2146
|
+
size: t.file.size,
|
|
2147
|
+
type: t.file.type || void 0,
|
|
2148
|
+
url: s
|
|
2149
|
+
}), this.pending = this.pending.filter((r) => r.id !== t.id), this.emitValue(this.multiple ? [...this.urls, s] : [s]);
|
|
2150
|
+
}, e.onerror = () => this.failed(t, 0);
|
|
2151
|
+
const i = new FormData();
|
|
2152
|
+
i.append(this.fieldName || "file", t.file, t.file.name), e.send(i);
|
|
2153
|
+
}
|
|
2154
|
+
failed(t, e) {
|
|
2155
|
+
const i = m("uploadFailed");
|
|
2156
|
+
this.patch(t.id, { error: i, percent: 0 }), this.dispatchEvent(
|
|
2157
|
+
new CustomEvent("baht-upload-error", {
|
|
2158
|
+
detail: { file: t.file, status: e, message: i },
|
|
2159
|
+
bubbles: !0,
|
|
2160
|
+
composed: !0
|
|
2161
|
+
})
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
2164
|
+
retry(t) {
|
|
2165
|
+
this.patch(t.id, { error: null, percent: 0 }), this.send({ ...t, error: null, percent: 0 });
|
|
2166
|
+
}
|
|
2167
|
+
dismiss(t) {
|
|
2168
|
+
this.pending = this.pending.filter((e) => e.id !== t.id);
|
|
2169
|
+
}
|
|
2170
|
+
defaultHint() {
|
|
2171
|
+
const t = [];
|
|
2172
|
+
return this.accept && t.push(
|
|
2173
|
+
this.accept.split(",").map((e) => e.trim()).join(", ")
|
|
2174
|
+
), this.maxSize && t.push(m("uploadMaxSize", { size: we(this.maxSize) })), t.join(" · ");
|
|
2175
|
+
}
|
|
2176
|
+
render() {
|
|
2177
|
+
const t = this.pending.some((c) => !c.error), e = !!this.error, i = this.hint || this.defaultHint(), a = i ? `${this.inputId}-hint` : void 0, s = this.error ? `${this.inputId}-error` : void 0, r = [a, s].filter(Boolean).join(" ") || void 0, o = [
|
|
2178
|
+
"baht-dropzone",
|
|
2179
|
+
this.dragging ? "baht-dropzone--over" : "",
|
|
2180
|
+
this.disabled ? "baht-dropzone--disabled" : "",
|
|
2181
|
+
e ? "baht-dropzone--invalid" : ""
|
|
2182
|
+
].filter(Boolean).join(" ");
|
|
2183
|
+
return n`<div class="baht-field baht-field--upload">
|
|
2184
|
+
${this.label ? n`<label class="baht-label" for=${this.inputId}
|
|
2185
|
+
>${this.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</label
|
|
2186
|
+
>` : h}
|
|
2187
|
+
<div
|
|
2188
|
+
class=${o}
|
|
2189
|
+
@dragover=${this.onDragOver}
|
|
2190
|
+
@dragleave=${this.onDragLeave}
|
|
2191
|
+
@drop=${this.onDrop}
|
|
2192
|
+
>
|
|
2193
|
+
<input
|
|
2194
|
+
class="baht-dropzone-input"
|
|
2195
|
+
id=${this.inputId}
|
|
2196
|
+
type="file"
|
|
2197
|
+
accept=${L(this.accept)}
|
|
2198
|
+
?multiple=${this.multiple}
|
|
2199
|
+
?disabled=${this.disabled}
|
|
2200
|
+
?required=${this.required}
|
|
2201
|
+
aria-invalid=${e ? "true" : "false"}
|
|
2202
|
+
aria-describedby=${L(r)}
|
|
2203
|
+
@change=${(c) => this.onPick(c)}
|
|
2204
|
+
/>
|
|
2205
|
+
<span class="baht-dropzone-icon" aria-hidden="true">${H("upload")}</span>
|
|
2206
|
+
<span class="baht-dropzone-text">
|
|
2207
|
+
<label class="baht-dropzone-action" for=${this.inputId}
|
|
2208
|
+
>${this.multiple ? m("chooseFiles") : m("chooseFile")}</label
|
|
2209
|
+
>
|
|
2210
|
+
<span class="baht-dropzone-or">${m("orDropHere")}</span>
|
|
2211
|
+
</span>
|
|
2212
|
+
${i ? n`<span class="baht-dropzone-hint" id=${L(a)}>${i}</span>` : h}
|
|
2213
|
+
</div>
|
|
2214
|
+
|
|
2215
|
+
${this.pending.length > 0 || this.urls.length > 0 ? n`<ul class="baht-upload-list" aria-live="polite" aria-busy=${t ? "true" : "false"}>
|
|
2216
|
+
${this.urls.map((c) => this.renderStored(c))}
|
|
2217
|
+
${this.pending.map((c) => this.renderPending(c))}
|
|
2218
|
+
</ul>` : h}
|
|
2219
|
+
${this.rejectedNames.length > 0 ? n`<p class="baht-error" role="alert">
|
|
2220
|
+
${m("fileRejectedTooLarge", { names: this.rejectedNames.join(", ") })}
|
|
2221
|
+
</p>` : h}
|
|
2222
|
+
${this.error ? n`<p class="baht-error" id=${L(s)} role="alert">${this.error}</p>` : h}
|
|
2223
|
+
</div>`;
|
|
2224
|
+
}
|
|
2225
|
+
renderStored(t) {
|
|
2226
|
+
const e = this.fileFor(t);
|
|
2227
|
+
return n`<li class="baht-file-chip baht-file-chip--done">
|
|
2228
|
+
<span class="baht-file-chip-icon" aria-hidden="true">${H("check")}</span>
|
|
2229
|
+
<a class="baht-file-name" href=${t} target="_blank" rel="noreferrer"
|
|
2230
|
+
>${e.name}<span class="baht-visually-hidden"> (${m("opensInNewTab")})</span></a
|
|
2231
|
+
>
|
|
2232
|
+
${e.size > 0 ? n`<span class="baht-file-size">${we(e.size)}</span>` : h}
|
|
2233
|
+
${this.disabled ? h : n`<button
|
|
2234
|
+
type="button"
|
|
2235
|
+
class="baht-file-remove"
|
|
2236
|
+
aria-label=${m("removeFile")}
|
|
2237
|
+
title=${m("removeFile")}
|
|
2238
|
+
@click=${() => this.emitValue(this.urls.filter((i) => i !== t))}
|
|
2239
|
+
>
|
|
2240
|
+
${H("close")}
|
|
2241
|
+
</button>`}
|
|
2242
|
+
</li>`;
|
|
2243
|
+
}
|
|
2244
|
+
renderPending(t) {
|
|
2245
|
+
return n`<li class="baht-file-chip ${t.error ? "baht-file-chip--error" : "baht-file-chip--busy"}">
|
|
2246
|
+
<span class="baht-file-name">${t.file.name}</span>
|
|
2247
|
+
<span class="baht-file-size">${we(t.file.size)}</span>
|
|
2248
|
+
${t.error ? n`<span class="baht-file-status baht-file-status--error" role="alert">${t.error}</span>
|
|
2249
|
+
<button type="button" class="baht-upload-retry" @click=${() => this.retry(t)}>
|
|
2250
|
+
${m("retry")}
|
|
2251
|
+
</button>
|
|
2252
|
+
<button
|
|
2253
|
+
type="button"
|
|
2254
|
+
class="baht-file-remove"
|
|
2255
|
+
aria-label=${m("removeFile")}
|
|
2256
|
+
title=${m("removeFile")}
|
|
2257
|
+
@click=${() => this.dismiss(t)}
|
|
2258
|
+
>
|
|
2259
|
+
${H("close")}
|
|
2260
|
+
</button>` : n`<span
|
|
2261
|
+
class="baht-upload-bar"
|
|
2262
|
+
role="progressbar"
|
|
2263
|
+
aria-label=${m("uploading")}
|
|
2264
|
+
aria-valuemin="0"
|
|
2265
|
+
aria-valuemax="100"
|
|
2266
|
+
aria-valuenow=${String(t.percent)}
|
|
2267
|
+
><span class="baht-upload-bar-fill" style="width:${t.percent}%"></span
|
|
2268
|
+
></span>`}
|
|
2269
|
+
</li>`;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
B([
|
|
2273
|
+
l()
|
|
2274
|
+
], D.prototype, "url", 2);
|
|
2275
|
+
B([
|
|
2276
|
+
l()
|
|
2277
|
+
], D.prototype, "method", 2);
|
|
2278
|
+
B([
|
|
2279
|
+
l({ attribute: "field-name" })
|
|
2280
|
+
], D.prototype, "fieldName", 2);
|
|
2281
|
+
B([
|
|
2282
|
+
l({ attribute: "response-key" })
|
|
2283
|
+
], D.prototype, "responseKey", 2);
|
|
2284
|
+
B([
|
|
2285
|
+
l({ attribute: !1 })
|
|
2286
|
+
], D.prototype, "headers", 2);
|
|
2287
|
+
B([
|
|
2288
|
+
l({ type: Boolean, attribute: "with-credentials" })
|
|
2289
|
+
], D.prototype, "withCredentials", 2);
|
|
2290
|
+
B([
|
|
2291
|
+
l({ attribute: !1 })
|
|
2292
|
+
], D.prototype, "value", 2);
|
|
2293
|
+
B([
|
|
2294
|
+
l()
|
|
2295
|
+
], D.prototype, "label", 2);
|
|
2296
|
+
B([
|
|
2297
|
+
l()
|
|
2298
|
+
], D.prototype, "hint", 2);
|
|
2299
|
+
B([
|
|
2300
|
+
l()
|
|
2301
|
+
], D.prototype, "accept", 2);
|
|
2302
|
+
B([
|
|
2303
|
+
l({ type: Boolean })
|
|
2304
|
+
], D.prototype, "multiple", 2);
|
|
2305
|
+
B([
|
|
2306
|
+
l({ type: Number, attribute: "max-size" })
|
|
2307
|
+
], D.prototype, "maxSize", 2);
|
|
2308
|
+
B([
|
|
2309
|
+
l({ type: Boolean })
|
|
2310
|
+
], D.prototype, "disabled", 2);
|
|
2311
|
+
B([
|
|
2312
|
+
l({ type: Boolean })
|
|
2313
|
+
], D.prototype, "required", 2);
|
|
2314
|
+
B([
|
|
2315
|
+
l()
|
|
2316
|
+
], D.prototype, "error", 2);
|
|
2317
|
+
B([
|
|
2318
|
+
$()
|
|
2319
|
+
], D.prototype, "pending", 2);
|
|
2320
|
+
B([
|
|
2321
|
+
$()
|
|
2322
|
+
], D.prototype, "rejectedNames", 2);
|
|
2323
|
+
B([
|
|
2324
|
+
$()
|
|
2325
|
+
], D.prototype, "dragging", 2);
|
|
2326
|
+
D = B([
|
|
2327
|
+
b("baht-upload")
|
|
2328
|
+
], D);
|
|
2329
|
+
var Ia = Object.defineProperty, ja = Object.getOwnPropertyDescriptor, ns = (t, e, i, a) => {
|
|
2330
|
+
for (var s = a > 1 ? void 0 : a ? ja(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2331
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2332
|
+
return a && s && Ia(e, i, s), s;
|
|
2333
|
+
};
|
|
2334
|
+
let Fe = class extends y {
|
|
2335
|
+
render() {
|
|
2336
|
+
if (!this.field) return h;
|
|
2337
|
+
const t = this.field.variant ?? "body";
|
|
2338
|
+
return n`<div class="baht-text baht-text--${t}">${this.field.text ?? this.field.label ?? ""}</div>`;
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
ns([
|
|
2342
|
+
l({ attribute: !1 })
|
|
2343
|
+
], Fe.prototype, "field", 2);
|
|
2344
|
+
Fe = ns([
|
|
2345
|
+
b("baht-text")
|
|
2346
|
+
], Fe);
|
|
2347
|
+
var Sa = Object.defineProperty, Ma = Object.getOwnPropertyDescriptor, hs = (t, e, i, a) => {
|
|
2348
|
+
for (var s = a > 1 ? void 0 : a ? Ma(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2349
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2350
|
+
return a && s && Sa(e, i, s), s;
|
|
2351
|
+
};
|
|
2352
|
+
let Ee = class extends y {
|
|
2353
|
+
render() {
|
|
2354
|
+
return this.field ? n`<div class="baht-section">
|
|
2355
|
+
<span class="baht-section-label">${this.field.text ?? this.field.label ?? ""}</span>
|
|
2356
|
+
</div>` : h;
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
hs([
|
|
2360
|
+
l({ attribute: !1 })
|
|
2361
|
+
], Ee.prototype, "field", 2);
|
|
2362
|
+
Ee = hs([
|
|
2363
|
+
b("baht-section")
|
|
2364
|
+
], Ee);
|
|
2365
|
+
var Ta = Object.defineProperty, Aa = Object.getOwnPropertyDescriptor, ue = (t, e, i, a) => {
|
|
2366
|
+
for (var s = a > 1 ? void 0 : a ? Aa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2367
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2368
|
+
return a && s && Ta(e, i, s), s;
|
|
2369
|
+
};
|
|
2370
|
+
let Ut = class extends y {
|
|
2371
|
+
constructor() {
|
|
2372
|
+
super(...arguments), this.total = 0, this.label = "", this.color = "";
|
|
2373
|
+
}
|
|
2374
|
+
render() {
|
|
2375
|
+
return n`<div class="baht-stat-chart">
|
|
2376
|
+
<div
|
|
2377
|
+
class="baht-stat-chart-total"
|
|
2378
|
+
style=${this.color ? `color:${this.color}` : h}
|
|
2379
|
+
>${this.total.toLocaleString("en-US")}</div>
|
|
2380
|
+
${this.label ? n`<div class="baht-stat-chart-label">${this.label}</div>` : h}
|
|
2381
|
+
</div>`;
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
ue([
|
|
2385
|
+
l({ type: Number })
|
|
2386
|
+
], Ut.prototype, "total", 2);
|
|
2387
|
+
ue([
|
|
2388
|
+
l()
|
|
2389
|
+
], Ut.prototype, "label", 2);
|
|
2390
|
+
ue([
|
|
2391
|
+
l()
|
|
2392
|
+
], Ut.prototype, "color", 2);
|
|
2393
|
+
Ut = ue([
|
|
2394
|
+
b("baht-stat-chart")
|
|
2395
|
+
], Ut);
|
|
2396
|
+
var La = Object.defineProperty, Tt = (t, e, i, a) => {
|
|
2397
|
+
for (var s = void 0, r = t.length - 1, o; r >= 0; r--)
|
|
2398
|
+
(o = t[r]) && (s = o(e, i, s) || s);
|
|
2399
|
+
return s && La(e, i, s), s;
|
|
2400
|
+
};
|
|
2401
|
+
const Na = 10;
|
|
2402
|
+
function nt(t, e) {
|
|
2403
|
+
return e && t === 0 ? e : `var(--baht-chart-${t % Na + 1})`;
|
|
2404
|
+
}
|
|
2405
|
+
function Xe(t, e = 5) {
|
|
2406
|
+
return `var(--baht-chart-seq-${Math.min(e - 1, Math.max(0, t)) + 1})`;
|
|
2407
|
+
}
|
|
2408
|
+
function qt(t, e = "number", i = "THB") {
|
|
2409
|
+
if (!Number.isFinite(t)) return "—";
|
|
2410
|
+
switch (e) {
|
|
2411
|
+
case "currency":
|
|
2412
|
+
return new Intl.NumberFormat("en-US", {
|
|
2413
|
+
style: "currency",
|
|
2414
|
+
currency: i || "THB",
|
|
2415
|
+
currencyDisplay: "narrowSymbol",
|
|
2416
|
+
maximumFractionDigits: 0
|
|
2417
|
+
}).format(t).replace(/THB\s?/, "฿");
|
|
2418
|
+
case "percent":
|
|
2419
|
+
return new Intl.NumberFormat("en-US", {
|
|
2420
|
+
style: "percent",
|
|
2421
|
+
maximumFractionDigits: 1
|
|
2422
|
+
}).format(t);
|
|
2423
|
+
case "compact":
|
|
2424
|
+
return new Intl.NumberFormat("en-US", {
|
|
2425
|
+
notation: "compact",
|
|
2426
|
+
maximumFractionDigits: 1
|
|
2427
|
+
}).format(t);
|
|
2428
|
+
default:
|
|
2429
|
+
return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(t);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
function Be(t, e = 4) {
|
|
2433
|
+
if (!Number.isFinite(t) || t <= 0) return [0, 1];
|
|
2434
|
+
const i = t / (Math.max(1, e) + 1), a = 10 ** Math.floor(Math.log10(i)), s = [1, 2, 2.5, 5, 10].map((c) => c * a).find((c) => c >= i - 1e-9) ?? 10 * a, r = Math.ceil(t / s) * s, o = [];
|
|
2435
|
+
for (let c = 0; c <= r + s / 1e3; c += s) o.push(Number(c.toFixed(10)));
|
|
2436
|
+
return o;
|
|
2437
|
+
}
|
|
2438
|
+
function le(t, e) {
|
|
2439
|
+
const [i, a] = t, [s, r] = e, o = a - i;
|
|
2440
|
+
return !Number.isFinite(o) || o === 0 ? () => s : (c) => s + (c - i) / o * (r - s);
|
|
2441
|
+
}
|
|
2442
|
+
function qa(t, e, i = "Other") {
|
|
2443
|
+
if (t.length <= e) return t;
|
|
2444
|
+
const a = t.slice(0, e - 1), s = t.slice(e - 1).reduce((r, o) => r + o.count, 0);
|
|
2445
|
+
return [...a, { label: i, count: s }];
|
|
2446
|
+
}
|
|
2447
|
+
function be(t, e, i, a = "View as table") {
|
|
2448
|
+
return n`<details class="baht-chart-table">
|
|
2449
|
+
<summary>${a}</summary>
|
|
2450
|
+
<table>
|
|
2451
|
+
<caption>${t}</caption>
|
|
2452
|
+
<thead>
|
|
2453
|
+
<tr>
|
|
2454
|
+
${e.map((s) => n`<th scope="col">${s}</th>`)}
|
|
2455
|
+
</tr>
|
|
2456
|
+
</thead>
|
|
2457
|
+
<tbody>
|
|
2458
|
+
${i.map(
|
|
2459
|
+
(s) => n`<tr>
|
|
2460
|
+
${s.map(
|
|
2461
|
+
(r, o) => o === 0 ? n`<th scope="row">${r}</th>` : n`<td class="baht-chart-num">${r}</td>`
|
|
2462
|
+
)}
|
|
2463
|
+
</tr>`
|
|
2464
|
+
)}
|
|
2465
|
+
</tbody>
|
|
2466
|
+
</table>
|
|
2467
|
+
</details>`;
|
|
2468
|
+
}
|
|
2469
|
+
class tt extends y {
|
|
2470
|
+
constructor() {
|
|
2471
|
+
super(...arguments), this.emptyMessage = "No data to chart", this.loading = !1, this.showTable = !0, this.format = "number", this.currency = "THB", this.held = null;
|
|
2472
|
+
}
|
|
2473
|
+
/** Value → display text using this chart's `format` / `currency`. */
|
|
2474
|
+
fmt(e) {
|
|
2475
|
+
return qt(e, this.format, this.currency);
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* The snapshot to draw. While `loading` is set the previous one is returned,
|
|
2479
|
+
* so a refetch dims the chart instead of emptying it.
|
|
2480
|
+
*/
|
|
2481
|
+
hold(e) {
|
|
2482
|
+
return this.loading ? this.held ?? e : (this.held = e, e);
|
|
2483
|
+
}
|
|
2484
|
+
/** Root class list: `baht-chart` plus the loading modifier. */
|
|
2485
|
+
rootClass(e) {
|
|
2486
|
+
return `baht-chart ${e}${this.loading ? " baht-chart--loading" : ""}`;
|
|
2487
|
+
}
|
|
2488
|
+
/** The single floating tooltip node; rendered by the template, never appended. */
|
|
2489
|
+
renderTooltip() {
|
|
2490
|
+
return n`<div class="baht-chart-tooltip" role="status" aria-live="polite" hidden></div>`;
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Show `text` near the pointer (or, on keyboard focus, near the mark).
|
|
2494
|
+
* Content is assigned with `textContent`: category and series names are
|
|
2495
|
+
* untrusted data (interaction.md).
|
|
2496
|
+
*/
|
|
2497
|
+
showTip(e, i) {
|
|
2498
|
+
var g;
|
|
2499
|
+
const a = this.tipEl;
|
|
2500
|
+
if (!a) return;
|
|
2501
|
+
a.textContent = i, a.hidden = !1;
|
|
2502
|
+
const s = this.querySelector(".baht-chart");
|
|
2503
|
+
if (!s || typeof s.getBoundingClientRect != "function") return;
|
|
2504
|
+
const r = s.getBoundingClientRect(), o = e;
|
|
2505
|
+
let c, f;
|
|
2506
|
+
if (typeof o.clientX == "number" && (o.clientX !== 0 || o.clientY !== 0))
|
|
2507
|
+
c = o.clientX - r.left, f = o.clientY - r.top;
|
|
2508
|
+
else {
|
|
2509
|
+
const _ = e.currentTarget, p = (g = _ == null ? void 0 : _.getBoundingClientRect) == null ? void 0 : g.call(_);
|
|
2510
|
+
c = p ? p.left + p.width / 2 - r.left : 0, f = p ? p.top - r.top : 0;
|
|
2511
|
+
}
|
|
2512
|
+
a.style.left = `${Math.round(c)}px`, a.style.top = `${Math.round(f)}px`;
|
|
2513
|
+
}
|
|
2514
|
+
/** Hide the tooltip (pointerleave / blur). */
|
|
2515
|
+
hideTip() {
|
|
2516
|
+
const e = this.tipEl;
|
|
2517
|
+
e && (e.hidden = !0, e.textContent = "");
|
|
2518
|
+
}
|
|
2519
|
+
/** The empty placeholder, or `nothing` when there is data. */
|
|
2520
|
+
renderEmpty() {
|
|
2521
|
+
return n`<div class="baht-chart-empty">${this.emptyMessage}</div>`;
|
|
2522
|
+
}
|
|
2523
|
+
/** Legend rows — only ever rendered for 2+ series (marks-and-anatomy.md). */
|
|
2524
|
+
renderLegend(e, i = "rect") {
|
|
2525
|
+
return e.length < 2 ? h : n`<div class="baht-chart-legend">
|
|
2526
|
+
${e.map(
|
|
2527
|
+
(a) => n`<div class="baht-chart-legend-row">
|
|
2528
|
+
<span
|
|
2529
|
+
class="baht-chart-swatch${i === "line" ? " baht-chart-swatch--line" : ""}"
|
|
2530
|
+
style="background:${a.color}"
|
|
2531
|
+
aria-hidden="true"
|
|
2532
|
+
></span>
|
|
2533
|
+
<span class="baht-chart-legend-label">${a.label}</span>
|
|
2534
|
+
${a.value ? n`<span class="baht-chart-legend-count">${a.value}</span>` : h}
|
|
2535
|
+
${a.share ? n`<span class="baht-chart-legend-pct">${a.share}</span>` : h}
|
|
2536
|
+
</div>`
|
|
2537
|
+
)}
|
|
2538
|
+
</div>`;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
Tt([
|
|
2542
|
+
l({ attribute: "empty-message" })
|
|
2543
|
+
], tt.prototype, "emptyMessage");
|
|
2544
|
+
Tt([
|
|
2545
|
+
l({ type: Boolean, reflect: !0 })
|
|
2546
|
+
], tt.prototype, "loading");
|
|
2547
|
+
Tt([
|
|
2548
|
+
l({ type: Boolean, attribute: "show-table" })
|
|
2549
|
+
], tt.prototype, "showTable");
|
|
2550
|
+
Tt([
|
|
2551
|
+
l()
|
|
2552
|
+
], tt.prototype, "format");
|
|
2553
|
+
Tt([
|
|
2554
|
+
l()
|
|
2555
|
+
], tt.prototype, "currency");
|
|
2556
|
+
Tt([
|
|
2557
|
+
Bt(".baht-chart-tooltip")
|
|
2558
|
+
], tt.prototype, "tipEl");
|
|
2559
|
+
var Ra = Object.defineProperty, za = Object.getOwnPropertyDescriptor, gt = (t, e, i, a) => {
|
|
2560
|
+
for (var s = a > 1 ? void 0 : a ? za(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2561
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2562
|
+
return a && s && Ra(e, i, s), s;
|
|
2563
|
+
};
|
|
2564
|
+
let ct = class extends y {
|
|
2565
|
+
constructor() {
|
|
2566
|
+
super(...arguments), this.values = [], this.width = 96, this.height = 24, this.accentLast = !0, this.color = "", this.label = "";
|
|
2567
|
+
}
|
|
2568
|
+
render() {
|
|
2569
|
+
const t = (this.values ?? []).filter((C) => Number.isFinite(C));
|
|
2570
|
+
if (t.length < 2) return h;
|
|
2571
|
+
const e = Math.max(16, this.width), i = Math.max(8, this.height), a = 3, s = Math.min(...t), r = Math.max(...t), o = le([0, t.length - 1], [a, e - a]), c = le([s, r === s ? s + 1 : r], [i - a, a]), f = t.map((C, d) => `${o(d).toFixed(2)},${c(C).toFixed(2)}`).join(" "), g = o(t.length - 1), _ = c(t[t.length - 1]), p = this.color || "var(--baht-chart-muted)", w = this.label || `Trend of ${t.length} points`;
|
|
2572
|
+
return n`<svg
|
|
2573
|
+
class="baht-sparkline"
|
|
2574
|
+
width=${e}
|
|
2575
|
+
height=${i}
|
|
2576
|
+
viewBox="0 0 ${e} ${i}"
|
|
2577
|
+
role="img"
|
|
2578
|
+
aria-label=${w}
|
|
2579
|
+
>
|
|
2580
|
+
${A`<polyline class="baht-sparkline-line" points=${f} fill="none" stroke=${p}/>`}
|
|
2581
|
+
${this.accentLast ? A`<circle class="baht-sparkline-dot" cx=${g.toFixed(2)} cy=${_.toFixed(2)} r="3"
|
|
2582
|
+
fill="var(--baht-chart-1)"/>` : h}
|
|
2583
|
+
</svg>`;
|
|
2584
|
+
}
|
|
2585
|
+
};
|
|
2586
|
+
gt([
|
|
2587
|
+
l({ type: Array })
|
|
2588
|
+
], ct.prototype, "values", 2);
|
|
2589
|
+
gt([
|
|
2590
|
+
l({ type: Number })
|
|
2591
|
+
], ct.prototype, "width", 2);
|
|
2592
|
+
gt([
|
|
2593
|
+
l({ type: Number })
|
|
2594
|
+
], ct.prototype, "height", 2);
|
|
2595
|
+
gt([
|
|
2596
|
+
l({ type: Boolean, attribute: "accent-last" })
|
|
2597
|
+
], ct.prototype, "accentLast", 2);
|
|
2598
|
+
gt([
|
|
2599
|
+
l()
|
|
2600
|
+
], ct.prototype, "color", 2);
|
|
2601
|
+
gt([
|
|
2602
|
+
l()
|
|
2603
|
+
], ct.prototype, "label", 2);
|
|
2604
|
+
ct = gt([
|
|
2605
|
+
b("baht-sparkline")
|
|
2606
|
+
], ct);
|
|
2607
|
+
var Va = Object.defineProperty, Ka = Object.getOwnPropertyDescriptor, Y = (t, e, i, a) => {
|
|
2608
|
+
for (var s = a > 1 ? void 0 : a ? Ka(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2609
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2610
|
+
return a && s && Va(e, i, s), s;
|
|
2611
|
+
};
|
|
2612
|
+
let K = class extends y {
|
|
2613
|
+
constructor() {
|
|
2614
|
+
super(...arguments), this.label = "", this.value = 0, this.format = "number", this.currency = "THB", this.delta = null, this.deltaKind = "pct", this.deltaLabel = "", this.upIsGood = !0, this.trend = [], this.size = "md";
|
|
2615
|
+
}
|
|
2616
|
+
/** Direction of the delta paired with whether up is good. */
|
|
2617
|
+
get tone() {
|
|
2618
|
+
const t = this.delta;
|
|
2619
|
+
return t == null || !Number.isFinite(t) || t === 0 ? "flat" : t > 0 === this.upIsGood ? "good" : "bad";
|
|
2620
|
+
}
|
|
2621
|
+
get arrow() {
|
|
2622
|
+
const t = this.delta ?? 0;
|
|
2623
|
+
return t > 0 ? "↑" : t < 0 ? "↓" : "→";
|
|
2624
|
+
}
|
|
2625
|
+
get deltaText() {
|
|
2626
|
+
const t = this.delta ?? 0, e = Math.abs(t);
|
|
2627
|
+
return this.deltaKind === "pct" ? `${qt(e / 100, "percent")}` : qt(e, this.format, this.currency);
|
|
2628
|
+
}
|
|
2629
|
+
render() {
|
|
2630
|
+
const t = this.delta != null && Number.isFinite(this.delta), e = this.tone, i = (this.delta ?? 0) > 0 ? "up" : (this.delta ?? 0) < 0 ? "down" : "flat";
|
|
2631
|
+
return n`<div class="baht-stat${this.size === "hero" ? " baht-stat--hero" : ""}">
|
|
2632
|
+
${this.label ? n`<div class="baht-stat-label">${this.label}</div>` : h}
|
|
2633
|
+
<div class="baht-stat-value">${qt(this.value, this.format, this.currency)}</div>
|
|
2634
|
+
${t ? n`<div class="baht-stat-delta baht-stat-delta--${e}">
|
|
2635
|
+
<span class="baht-stat-arrow" aria-hidden="true">${this.arrow}</span>
|
|
2636
|
+
<span class="baht-stat-delta-value">${this.deltaText}</span>
|
|
2637
|
+
<span class="baht-visually-hidden">${i}</span>
|
|
2638
|
+
${this.deltaLabel ? n`<span class="baht-stat-delta-label">${this.deltaLabel}</span>` : h}
|
|
2639
|
+
</div>` : h}
|
|
2640
|
+
${this.trend.length > 1 ? n`<baht-sparkline
|
|
2641
|
+
class="baht-stat-trend"
|
|
2642
|
+
.values=${this.trend}
|
|
2643
|
+
label=${`${this.label || "Value"} trend, ${this.trend.length} points`}
|
|
2644
|
+
></baht-sparkline>` : h}
|
|
2645
|
+
</div>`;
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
Y([
|
|
2649
|
+
l()
|
|
2650
|
+
], K.prototype, "label", 2);
|
|
2651
|
+
Y([
|
|
2652
|
+
l({ type: Number })
|
|
2653
|
+
], K.prototype, "value", 2);
|
|
2654
|
+
Y([
|
|
2655
|
+
l()
|
|
2656
|
+
], K.prototype, "format", 2);
|
|
2657
|
+
Y([
|
|
2658
|
+
l()
|
|
2659
|
+
], K.prototype, "currency", 2);
|
|
2660
|
+
Y([
|
|
2661
|
+
l({ type: Number })
|
|
2662
|
+
], K.prototype, "delta", 2);
|
|
2663
|
+
Y([
|
|
2664
|
+
l({ attribute: "delta-kind" })
|
|
2665
|
+
], K.prototype, "deltaKind", 2);
|
|
2666
|
+
Y([
|
|
2667
|
+
l({ attribute: "delta-label" })
|
|
2668
|
+
], K.prototype, "deltaLabel", 2);
|
|
2669
|
+
Y([
|
|
2670
|
+
l({ type: Boolean, attribute: "up-is-good" })
|
|
2671
|
+
], K.prototype, "upIsGood", 2);
|
|
2672
|
+
Y([
|
|
2673
|
+
l({ type: Array })
|
|
2674
|
+
], K.prototype, "trend", 2);
|
|
2675
|
+
Y([
|
|
2676
|
+
l()
|
|
2677
|
+
], K.prototype, "size", 2);
|
|
2678
|
+
K = Y([
|
|
2679
|
+
b("baht-stat")
|
|
2680
|
+
], K);
|
|
2681
|
+
var Ua = Object.defineProperty, Ha = Object.getOwnPropertyDescriptor, At = (t, e, i, a) => {
|
|
2682
|
+
for (var s = a > 1 ? void 0 : a ? Ha(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2683
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2684
|
+
return a && s && Ua(e, i, s), s;
|
|
2685
|
+
};
|
|
2686
|
+
const Ze = 6;
|
|
2687
|
+
let G = class extends tt {
|
|
2688
|
+
constructor() {
|
|
2689
|
+
super(...arguments), this.groups = [], this.total = null, this.color = "", this.centerLabel = "records", this.otherLabel = "Other";
|
|
2690
|
+
}
|
|
2691
|
+
render() {
|
|
2692
|
+
const t = this.hold(this.groups ?? []);
|
|
2693
|
+
if (t.length === 0)
|
|
2694
|
+
return n`<div class=${this.rootClass("baht-donut-chart")}>${this.renderEmpty()}</div>`;
|
|
2695
|
+
const e = qa(t, Ze, this.otherLabel), i = e.reduce((p, w) => p + w.count, 0) || 1, a = this.total ?? t.reduce((p, w) => p + w.count, 0), s = G.R, r = 2 * Math.PI * s, o = e.length > 1 ? G.GAP : 0, c = t.length > Ze;
|
|
2696
|
+
let f = 0;
|
|
2697
|
+
const g = e.map((p, w) => {
|
|
2698
|
+
const C = p.count / i, d = Math.max(0, C * r - o), v = {
|
|
2699
|
+
...p,
|
|
2700
|
+
frac: C,
|
|
2701
|
+
dash: `${d} ${r - d}`,
|
|
2702
|
+
offset: -f * r,
|
|
2703
|
+
// the folded tail is grey — never a generated ninth hue
|
|
2704
|
+
color: c && w === e.length - 1 ? "var(--baht-chart-muted)" : nt(w, this.color || void 0)
|
|
2705
|
+
};
|
|
2706
|
+
return f += C, v;
|
|
2707
|
+
}), _ = `${a} ${this.centerLabel}: ${g.map((p) => `${p.label || "(empty)"} ${p.count} (${Math.round(p.frac * 100)}%)`).join(", ")}`;
|
|
2708
|
+
return n`<div class=${this.rootClass("baht-donut-chart")}>
|
|
2709
|
+
<svg width="160" height="160" viewBox="0 0 160 160" role="img" aria-label=${_}>
|
|
2710
|
+
<g transform="translate(80,80) rotate(-90)">
|
|
2711
|
+
${g.map(
|
|
2712
|
+
(p) => A`<circle r=${s} cx="0" cy="0" fill="none" stroke=${p.color}
|
|
2713
|
+
stroke-width="22" stroke-dasharray=${p.dash} stroke-dashoffset=${p.offset}/>`
|
|
2714
|
+
)}
|
|
2715
|
+
</g>
|
|
2716
|
+
<text x="80" y="76" text-anchor="middle" class="baht-donut-chart-total">${this.fmt(a)}</text>
|
|
2717
|
+
<text x="80" y="94" text-anchor="middle" class="baht-donut-chart-sub">${this.centerLabel}</text>
|
|
2718
|
+
</svg>
|
|
2719
|
+
<div class="baht-chart-legend">
|
|
2720
|
+
${g.map(
|
|
2721
|
+
(p) => n`<div class="baht-chart-legend-row">
|
|
2722
|
+
<span class="baht-chart-swatch" style="background:${p.color}" aria-hidden="true"></span>
|
|
2723
|
+
<span class="baht-chart-legend-label">${p.label || "(empty)"}</span>
|
|
2724
|
+
<span class="baht-chart-legend-count">${this.fmt(p.count)}</span>
|
|
2725
|
+
<span class="baht-chart-legend-pct">(${Math.round(p.frac * 100)}%)</span>
|
|
2726
|
+
</div>`
|
|
2727
|
+
)}
|
|
2728
|
+
</div>
|
|
2729
|
+
${this.showTable ? be(
|
|
2730
|
+
`${a} ${this.centerLabel}`,
|
|
2731
|
+
["Slice", "Value", "Share"],
|
|
2732
|
+
g.map((p) => [
|
|
2733
|
+
p.label || "(empty)",
|
|
2734
|
+
this.fmt(p.count),
|
|
2735
|
+
`${Math.round(p.frac * 100)}%`
|
|
2736
|
+
])
|
|
2737
|
+
) : h}
|
|
2738
|
+
</div>`;
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
G.R = 54;
|
|
2742
|
+
G.GAP = 2;
|
|
2743
|
+
At([
|
|
2744
|
+
l({ attribute: !1 })
|
|
2745
|
+
], G.prototype, "groups", 2);
|
|
2746
|
+
At([
|
|
2747
|
+
l({ type: Number })
|
|
2748
|
+
], G.prototype, "total", 2);
|
|
2749
|
+
At([
|
|
2750
|
+
l()
|
|
2751
|
+
], G.prototype, "color", 2);
|
|
2752
|
+
At([
|
|
2753
|
+
l({ attribute: "center-label" })
|
|
2754
|
+
], G.prototype, "centerLabel", 2);
|
|
2755
|
+
At([
|
|
2756
|
+
l({ attribute: "other-label" })
|
|
2757
|
+
], G.prototype, "otherLabel", 2);
|
|
2758
|
+
G = At([
|
|
2759
|
+
b("baht-donut-chart")
|
|
2760
|
+
], G);
|
|
2761
|
+
var Ga = Object.defineProperty, Wa = Object.getOwnPropertyDescriptor, V = (t, e, i, a) => {
|
|
2762
|
+
for (var s = a > 1 ? void 0 : a ? Wa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
2763
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
2764
|
+
return a && s && Ga(e, i, s), s;
|
|
2765
|
+
};
|
|
2766
|
+
const Qe = 24, ts = 2, Ja = 56, Ya = 26;
|
|
2767
|
+
let R = class extends tt {
|
|
2768
|
+
constructor() {
|
|
2769
|
+
super(...arguments), this.groups = [], this.series = [], this.categories = [], this.orientation = "horizontal", this.stacked = !1, this.compare = [], this.markers = [], this.labelValues = "ends", this.emphasis = null, this.color = "", this.label = "", this.band = 0;
|
|
2770
|
+
}
|
|
2771
|
+
connectedCallback() {
|
|
2772
|
+
super.connectedCallback(), !(!S() || typeof ResizeObserver > "u") && (this.resizeObserver = new ResizeObserver(() => this.measure()), this.resizeObserver.observe(this));
|
|
2773
|
+
}
|
|
2774
|
+
disconnectedCallback() {
|
|
2775
|
+
var t;
|
|
2776
|
+
(t = this.resizeObserver) == null || t.disconnect(), this.resizeObserver = void 0, super.disconnectedCallback();
|
|
2777
|
+
}
|
|
2778
|
+
firstUpdated() {
|
|
2779
|
+
S() && queueMicrotask(() => this.measure());
|
|
2780
|
+
}
|
|
2781
|
+
/** Host width → px per category. Never runs on the server (`hasDom` guard). */
|
|
2782
|
+
measure() {
|
|
2783
|
+
var r;
|
|
2784
|
+
if (!S() || !this.isConnected || this.orientation !== "vertical") return;
|
|
2785
|
+
const t = this.columnCount;
|
|
2786
|
+
if (t === 0) return;
|
|
2787
|
+
const e = ((r = this.getBoundingClientRect) == null ? void 0 : r.call(this).width) ?? 0;
|
|
2788
|
+
if (!e) return;
|
|
2789
|
+
const a = (Math.max(0, e - Ja) - ts * (t - 1)) / t, s = a > 0 ? Math.floor(a * 100) / 100 : 0;
|
|
2790
|
+
Math.abs(s - this.band) > 0.01 && (this.band = s);
|
|
2791
|
+
}
|
|
2792
|
+
get columnCount() {
|
|
2793
|
+
const t = this.model.series;
|
|
2794
|
+
return t.length === 0 ? 0 : Math.max(...t.map((e) => e.values.length));
|
|
2795
|
+
}
|
|
2796
|
+
/** The series actually drawn — `groups` is normalised into one series. */
|
|
2797
|
+
get model() {
|
|
2798
|
+
var e;
|
|
2799
|
+
if ((e = this.series) != null && e.length)
|
|
2800
|
+
return { series: this.series, categories: this.categories ?? [], legacy: !1 };
|
|
2801
|
+
const t = this.groups ?? [];
|
|
2802
|
+
return {
|
|
2803
|
+
series: t.length ? [{ name: this.label || "Value", values: t.map((i) => i.count) }] : [],
|
|
2804
|
+
categories: t.map((i) => i.label),
|
|
2805
|
+
legacy: !0
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
colorFor(t, e, i) {
|
|
2809
|
+
const a = this.model.series[t];
|
|
2810
|
+
return this.emphasis != null && !(i ? t === this.emphasis : e === this.emphasis) ? "var(--baht-chart-muted)" : nt(i ? t : 0, this.color || (a == null ? void 0 : a.color) || void 0);
|
|
2811
|
+
}
|
|
2812
|
+
render() {
|
|
2813
|
+
const t = this.hold(this.model);
|
|
2814
|
+
return t.series.length === 0 ? n`<div class=${this.rootClass("baht-bar-chart")}>${this.renderEmpty()}</div>` : this.orientation === "vertical" ? this.renderVertical(t) : this.renderHorizontal(t);
|
|
2815
|
+
}
|
|
2816
|
+
/** Largest value a bar can reach: the raw max for `groups`, a clean tick otherwise. */
|
|
2817
|
+
domainMax(t, e, i) {
|
|
2818
|
+
const a = Math.max(...t.map((c) => c.values.length)), s = Array.from(
|
|
2819
|
+
{ length: a },
|
|
2820
|
+
(c, f) => e ? t.reduce((g, _) => g + (_.values[f] ?? 0), 0) : Math.max(...t.map((g) => g.values[f] ?? 0))
|
|
2821
|
+
), r = Math.max(
|
|
2822
|
+
1,
|
|
2823
|
+
...s,
|
|
2824
|
+
...this.compare ?? [],
|
|
2825
|
+
...(this.markers ?? []).map((c) => c.value)
|
|
2826
|
+
);
|
|
2827
|
+
if (i) return r;
|
|
2828
|
+
const o = Be(r, 4);
|
|
2829
|
+
return o[o.length - 1] ?? r;
|
|
2830
|
+
}
|
|
2831
|
+
tableTwin(t, e, i) {
|
|
2832
|
+
var s;
|
|
2833
|
+
if (!this.showTable) return h;
|
|
2834
|
+
const a = ["Category", ...t.map((r) => r.name || "Value")];
|
|
2835
|
+
return (s = this.compare) != null && s.length && a.push("Previous"), be(
|
|
2836
|
+
this.label || "Bar chart data",
|
|
2837
|
+
a,
|
|
2838
|
+
Array.from({ length: i }, (r, o) => {
|
|
2839
|
+
var f;
|
|
2840
|
+
const c = [
|
|
2841
|
+
e[o] || "(empty)",
|
|
2842
|
+
...t.map((g) => this.fmt(g.values[o] ?? 0))
|
|
2843
|
+
];
|
|
2844
|
+
return (f = this.compare) != null && f.length && c.push(this.fmt(this.compare[o] ?? 0)), c;
|
|
2845
|
+
})
|
|
2846
|
+
);
|
|
2847
|
+
}
|
|
2848
|
+
/** Markers with no `category` span the chart; the rest ride their own row. */
|
|
2849
|
+
markersFor(t) {
|
|
2850
|
+
return (this.markers ?? []).filter((e) => !e.category || e.category === t);
|
|
2851
|
+
}
|
|
2852
|
+
markerOverlay(t, e) {
|
|
2853
|
+
return this.markersFor(e).map(
|
|
2854
|
+
(i) => n`<span
|
|
2855
|
+
class="baht-bar-chart-marker"
|
|
2856
|
+
style=${`left:${Math.min(100, i.value / t * 100).toFixed(2)}%`}
|
|
2857
|
+
title=${i.label ?? this.fmt(i.value)}
|
|
2858
|
+
aria-hidden="true"
|
|
2859
|
+
></span>`
|
|
2860
|
+
);
|
|
2861
|
+
}
|
|
2862
|
+
renderHorizontal(t) {
|
|
2863
|
+
const { series: e, categories: i, legacy: a } = t, s = e.length > 1, r = Math.max(...e.map((p) => p.values.length)), o = this.domainMax(e, this.stacked, a), c = (this.compare ?? []).length > 0, f = (this.stacked ? 1 : e.length) + (c ? 1 : 0), g = Math.min(Qe, Math.max(6, Math.floor(48 / f))), _ = Array.from({ length: r }, (p, w) => {
|
|
2864
|
+
const C = i[w] || "(empty)", d = e.reduce((P, q) => P + (q.values[w] ?? 0), 0), v = `${C}: ${e.map((P) => `${P.name ? `${P.name} ` : ""}${this.fmt(P.values[w] ?? 0)}`).join(", ")}${c ? `, previous ${this.fmt(this.compare[w] ?? 0)}` : ""}`, z = e.map((P, q) => ({
|
|
2865
|
+
value: P.values[w] ?? 0,
|
|
2866
|
+
color: this.colorFor(q, w, s),
|
|
2867
|
+
name: P.name
|
|
2868
|
+
}));
|
|
2869
|
+
return n`<div class="baht-bar-chart-row">
|
|
2870
|
+
<span class="baht-bar-chart-label" title=${C}>${C}</span>
|
|
2871
|
+
<div
|
|
2872
|
+
class="baht-bar-chart-track${this.stacked ? " baht-bar-chart-track--stacked" : ""}"
|
|
2873
|
+
tabindex="0"
|
|
2874
|
+
role="button"
|
|
2875
|
+
aria-label=${v}
|
|
2876
|
+
@pointermove=${(P) => this.showTip(P, v)}
|
|
2877
|
+
@pointerleave=${() => this.hideTip()}
|
|
2878
|
+
@focus=${(P) => this.showTip(P, v)}
|
|
2879
|
+
@blur=${() => this.hideTip()}
|
|
2880
|
+
>
|
|
2881
|
+
${this.markerOverlay(o, C)}
|
|
2882
|
+
<div class="baht-bar-chart-bars">
|
|
2883
|
+
${this.stacked ? n`<div class="baht-bar-chart-stack" style=${`height:${g}px`}>
|
|
2884
|
+
${z.map(
|
|
2885
|
+
(P) => n`<div
|
|
2886
|
+
class="baht-bar-chart-bar baht-bar-chart-bar--segment"
|
|
2887
|
+
style=${`width:${Math.max(0, P.value / o * 100)}%;background:${P.color}`}
|
|
2888
|
+
></div>`
|
|
2889
|
+
)}
|
|
2890
|
+
</div>` : z.map(
|
|
2891
|
+
(P) => n`<div
|
|
2892
|
+
class="baht-bar-chart-bar"
|
|
2893
|
+
style=${`width:${Math.max(2, P.value / o * 100)}%;height:${g}px;background:${P.color}`}
|
|
2894
|
+
></div>`
|
|
2895
|
+
)}
|
|
2896
|
+
${c ? n`<div
|
|
2897
|
+
class="baht-bar-chart-bar baht-bar-chart-bar--compare"
|
|
2898
|
+
style=${`width:${Math.max(2, (this.compare[w] ?? 0) / o * 100)}%;height:${Math.min(8, g)}px`}
|
|
2899
|
+
></div>` : h}
|
|
2900
|
+
</div>
|
|
2901
|
+
</div>
|
|
2902
|
+
${this.labelValues === "ends" ? n`<span class="baht-bar-chart-count"
|
|
2903
|
+
>${a ? e[0].values[w] ?? 0 : this.fmt(this.stacked ? d : e[0].values[w] ?? 0)}</span
|
|
2904
|
+
>` : h}
|
|
2905
|
+
</div>`;
|
|
2906
|
+
});
|
|
2907
|
+
return n`<div class=${this.rootClass("baht-bar-chart")}>
|
|
2908
|
+
${_}
|
|
2909
|
+
${this.renderTooltip()}
|
|
2910
|
+
${this.renderLegend(e.map((p, w) => ({ label: p.name, color: nt(w, p.color) })))}
|
|
2911
|
+
${this.tableTwin(e, i, r)}
|
|
2912
|
+
</div>`;
|
|
2913
|
+
}
|
|
2914
|
+
renderVertical(t) {
|
|
2915
|
+
const { series: e, categories: i, legacy: a } = t, s = e.length > 1, r = Math.max(...e.map((d) => d.values.length)), o = this.domainMax(e, this.stacked, a), c = Be(o, 4), f = (this.compare ?? []).length > 0, g = (this.stacked ? 1 : e.length) + (f ? 1 : 0), _ = this.band > 0 ? (this.band - ts) / g : 48 / g, p = Math.min(Qe, Math.max(2, Math.floor(_))), w = this.band > 0 ? Math.max(1, Math.ceil(Ya / Math.max(1, this.band))) : Math.max(1, Math.ceil(r / 12)), C = this.label || `Column chart, ${r} categories. ${i.map((d, v) => `${d} ${this.fmt(e[0].values[v] ?? 0)}`).join(", ")}`;
|
|
2916
|
+
return n`<div class=${this.rootClass("baht-bar-chart baht-bar-chart--vertical")}>
|
|
2917
|
+
<div class="baht-bar-chart-plot" role="img" aria-label=${C}>
|
|
2918
|
+
<div class="baht-bar-chart-yaxis" aria-hidden="true">
|
|
2919
|
+
${[...c].reverse().map((d) => n`<span class="baht-chart-tick-text">${this.fmt(d)}</span>`)}
|
|
2920
|
+
</div>
|
|
2921
|
+
<div class="baht-bar-chart-grid">
|
|
2922
|
+
${(this.markers ?? []).filter((d) => !d.category).map(
|
|
2923
|
+
(d) => n`<span
|
|
2924
|
+
class="baht-bar-chart-marker baht-bar-chart-marker--horizontal"
|
|
2925
|
+
style=${`bottom:${Math.min(100, d.value / o * 100).toFixed(2)}%`}
|
|
2926
|
+
title=${d.label ?? this.fmt(d.value)}
|
|
2927
|
+
aria-hidden="true"
|
|
2928
|
+
></span>`
|
|
2929
|
+
)}
|
|
2930
|
+
${[...c].reverse().map(() => n`<span class="baht-chart-grid-rule" aria-hidden="true"></span>`)}
|
|
2931
|
+
<div class="baht-bar-chart-columns">
|
|
2932
|
+
${Array.from({ length: r }, (d, v) => {
|
|
2933
|
+
const z = i[v] || "(empty)", P = `${z}: ${e.map((q) => `${q.name ? `${q.name} ` : ""}${this.fmt(q.values[v] ?? 0)}`).join(", ")}`;
|
|
2934
|
+
return n`<div
|
|
2935
|
+
class="baht-bar-chart-column"
|
|
2936
|
+
style=${this.band > 0 ? `flex:0 0 auto;width:${this.band}px` : h}
|
|
2937
|
+
tabindex="0"
|
|
2938
|
+
role="button"
|
|
2939
|
+
aria-label=${P}
|
|
2940
|
+
@pointermove=${(q) => this.showTip(q, P)}
|
|
2941
|
+
@pointerleave=${() => this.hideTip()}
|
|
2942
|
+
@focus=${(q) => this.showTip(q, P)}
|
|
2943
|
+
@blur=${() => this.hideTip()}
|
|
2944
|
+
>
|
|
2945
|
+
<div class="baht-bar-chart-column-bars">
|
|
2946
|
+
${e.map(
|
|
2947
|
+
(q, ve) => n`<div
|
|
2948
|
+
class="baht-bar-chart-col"
|
|
2949
|
+
style=${`height:${Math.max(1, (q.values[v] ?? 0) / o * 100)}%;width:${p}px;background:${this.colorFor(ve, v, s)}`}
|
|
2950
|
+
></div>`
|
|
2951
|
+
)}
|
|
2952
|
+
${f ? n`<div
|
|
2953
|
+
class="baht-bar-chart-col baht-bar-chart-col--compare"
|
|
2954
|
+
style=${`height:${Math.max(1, (this.compare[v] ?? 0) / o * 100)}%;width:${Math.min(8, p)}px`}
|
|
2955
|
+
></div>` : h}
|
|
2956
|
+
</div>
|
|
2957
|
+
${v % w === 0 ? n`<span class="baht-bar-chart-xlabel">${z}</span>` : h}
|
|
2958
|
+
</div>`;
|
|
2959
|
+
})}
|
|
2960
|
+
</div>
|
|
2961
|
+
</div>
|
|
2962
|
+
</div>
|
|
2963
|
+
${this.renderTooltip()}
|
|
2964
|
+
${this.renderLegend(e.map((d, v) => ({ label: d.name, color: nt(v, d.color) })))}
|
|
2965
|
+
${this.tableTwin(e, i, r)}
|
|
2966
|
+
</div>`;
|
|
2967
|
+
}
|
|
2968
|
+
};
|
|
2969
|
+
V([
|
|
2970
|
+
l({ attribute: !1 })
|
|
2971
|
+
], R.prototype, "groups", 2);
|
|
2972
|
+
V([
|
|
2973
|
+
l({ attribute: !1 })
|
|
2974
|
+
], R.prototype, "series", 2);
|
|
2975
|
+
V([
|
|
2976
|
+
l({ attribute: !1 })
|
|
2977
|
+
], R.prototype, "categories", 2);
|
|
2978
|
+
V([
|
|
2979
|
+
l()
|
|
2980
|
+
], R.prototype, "orientation", 2);
|
|
2981
|
+
V([
|
|
2982
|
+
l({ type: Boolean })
|
|
2983
|
+
], R.prototype, "stacked", 2);
|
|
2984
|
+
V([
|
|
2985
|
+
l({ attribute: !1 })
|
|
2986
|
+
], R.prototype, "compare", 2);
|
|
2987
|
+
V([
|
|
2988
|
+
l({ attribute: !1 })
|
|
2989
|
+
], R.prototype, "markers", 2);
|
|
2990
|
+
V([
|
|
2991
|
+
l({ attribute: "label-values" })
|
|
2992
|
+
], R.prototype, "labelValues", 2);
|
|
2993
|
+
V([
|
|
2994
|
+
l({ type: Number })
|
|
2995
|
+
], R.prototype, "emphasis", 2);
|
|
2996
|
+
V([
|
|
2997
|
+
l()
|
|
2998
|
+
], R.prototype, "color", 2);
|
|
2999
|
+
V([
|
|
3000
|
+
l()
|
|
3001
|
+
], R.prototype, "label", 2);
|
|
3002
|
+
V([
|
|
3003
|
+
$()
|
|
3004
|
+
], R.prototype, "band", 2);
|
|
3005
|
+
R = V([
|
|
3006
|
+
b("baht-bar-chart")
|
|
3007
|
+
], R);
|
|
3008
|
+
var Xa = Object.defineProperty, Za = Object.getOwnPropertyDescriptor, lt = (t, e, i, a) => {
|
|
3009
|
+
for (var s = a > 1 ? void 0 : a ? Za(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3010
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3011
|
+
return a && s && Xa(e, i, s), s;
|
|
3012
|
+
};
|
|
3013
|
+
const es = 640, xe = 260, E = { top: 14, right: 72, bottom: 30, left: 60 };
|
|
3014
|
+
let Q = class extends tt {
|
|
3015
|
+
constructor() {
|
|
3016
|
+
super(...arguments), this.series = [], this.categories = [], this.area = !1, this.markers = [], this.forecast = 0, this.baseline = null, this.labelValues = "ends", this.label = "", this.crosshairAt = null;
|
|
3017
|
+
}
|
|
3018
|
+
get plot() {
|
|
3019
|
+
return { w: es - E.left - E.right, h: xe - E.top - E.bottom };
|
|
3020
|
+
}
|
|
3021
|
+
render() {
|
|
3022
|
+
const t = this.hold({
|
|
3023
|
+
series: (this.series ?? []).filter((u) => {
|
|
3024
|
+
var x;
|
|
3025
|
+
return u && ((x = u.values) == null ? void 0 : x.length);
|
|
3026
|
+
}),
|
|
3027
|
+
categories: this.categories ?? []
|
|
3028
|
+
}), { series: e, categories: i } = t;
|
|
3029
|
+
if (e.length === 0)
|
|
3030
|
+
return n`<div class=${this.rootClass("baht-line-chart")}>${this.renderEmpty()}</div>`;
|
|
3031
|
+
const a = Math.max(...e.map((u) => u.values.length)), s = e.flatMap((u) => u.values).filter((u) => Number.isFinite(u)), r = Math.max(0, ...s, ...(this.markers ?? []).map((u) => u.value)), o = Be(r, 4), c = o[o.length - 1] ?? 1, { w: f, h: g } = this.plot, _ = le([0, Math.max(1, a - 1)], [E.left, E.left + f]), p = le([0, c], [E.top + g, E.top]), w = Math.max(0, a - 1 - Math.max(0, this.forecast)), C = (u, x, Z) => u.slice(x, Z + 1).map((st, at) => `${at === 0 ? "M" : "L"}${_(x + at).toFixed(2)},${p(st).toFixed(2)}`).join(" "), d = e.map((u, x) => ({
|
|
3032
|
+
i: x,
|
|
3033
|
+
name: u.name,
|
|
3034
|
+
value: u.values[u.values.length - 1] ?? 0,
|
|
3035
|
+
yPos: p(u.values[u.values.length - 1] ?? 0),
|
|
3036
|
+
color: nt(x, u.color)
|
|
3037
|
+
})), v = [...d].sort((u, x) => u.yPos - x.yPos), z = v.some((u, x) => x > 0 && u.yPos - v[x - 1].yPos < 15), P = this.labelValues === "ends" && !z, q = Math.max(1, Math.ceil(a / 8)), ve = this.label || `Line chart, ${e.length} series over ${a} points. ${e.map((u, x) => `${u.name}: ${this.fmt(d[x].value)} at the end`).join(". ")}`;
|
|
3038
|
+
return n`<div class=${this.rootClass("baht-line-chart")}>
|
|
3039
|
+
<svg
|
|
3040
|
+
class="baht-chart-svg"
|
|
3041
|
+
viewBox="0 0 ${es} ${xe}"
|
|
3042
|
+
preserveAspectRatio="xMidYMid meet"
|
|
3043
|
+
role="img"
|
|
3044
|
+
aria-label=${ve}
|
|
3045
|
+
>
|
|
3046
|
+
${o.map(
|
|
3047
|
+
(u) => A`
|
|
3048
|
+
<line class="baht-chart-grid-line" x1=${E.left} x2=${E.left + f}
|
|
3049
|
+
y1=${p(u).toFixed(2)} y2=${p(u).toFixed(2)}/>
|
|
3050
|
+
<text class="baht-chart-tick" x=${E.left - 8} y=${(p(u) + 4).toFixed(2)}
|
|
3051
|
+
text-anchor="end">${this.fmt(u)}</text>`
|
|
3052
|
+
)}
|
|
3053
|
+
${this.baseline != null ? [
|
|
3054
|
+
A`<line class="baht-chart-baseline" x1=${E.left} x2=${E.left + f}
|
|
3055
|
+
y1=${p(this.baseline).toFixed(2)} y2=${p(this.baseline).toFixed(2)}/>`
|
|
3056
|
+
] : []}
|
|
3057
|
+
${(this.markers ?? []).map(
|
|
3058
|
+
(u) => A`
|
|
3059
|
+
<line class="baht-chart-marker-line" x1=${E.left} x2=${E.left + f}
|
|
3060
|
+
y1=${p(u.value).toFixed(2)} y2=${p(u.value).toFixed(2)}/>
|
|
3061
|
+
<text class="baht-chart-marker-label" x=${E.left + f} y=${(p(u.value) - 5).toFixed(2)}
|
|
3062
|
+
text-anchor="end">${u.label ?? this.fmt(u.value)}</text>`
|
|
3063
|
+
)}
|
|
3064
|
+
${this.area && e.length === 1 ? A`<path class="baht-chart-area" fill=${nt(0, e[0].color)}
|
|
3065
|
+
d=${`${C(e[0].values, 0, a - 1)} L${_(a - 1).toFixed(2)},${p(0).toFixed(2)} L${_(0).toFixed(2)},${p(0).toFixed(2)} Z`}/>` : h}
|
|
3066
|
+
${e.map((u, x) => {
|
|
3067
|
+
const Z = nt(x, u.color), st = [
|
|
3068
|
+
A`<path class="baht-chart-line" d=${C(u.values, 0, w)} stroke=${Z} fill="none"/>`
|
|
3069
|
+
];
|
|
3070
|
+
return w < a - 1 && st.push(
|
|
3071
|
+
A`<path class="baht-chart-line baht-chart-line--forecast" d=${C(u.values, w, a - 1)}
|
|
3072
|
+
stroke=${Z} fill="none"/>`
|
|
3073
|
+
), st.push(
|
|
3074
|
+
A`<circle class="baht-chart-end-dot" cx=${_(a - 1).toFixed(2)}
|
|
3075
|
+
cy=${p(u.values[u.values.length - 1] ?? 0).toFixed(2)} r="4" fill=${Z}/>`
|
|
3076
|
+
), st;
|
|
3077
|
+
})}
|
|
3078
|
+
${P ? d.map(
|
|
3079
|
+
(u) => A`
|
|
3080
|
+
<text class="baht-chart-end-label" x=${_(a - 1) + 10} y=${(u.yPos + 4).toFixed(2)}
|
|
3081
|
+
text-anchor="start">${this.fmt(u.value)}</text>`
|
|
3082
|
+
) : h}
|
|
3083
|
+
${i.map(
|
|
3084
|
+
(u, x) => x % q === 0 ? A`<text class="baht-chart-tick" x=${_(x).toFixed(2)} y=${xe - 10} text-anchor="middle">${u}</text>` : h
|
|
3085
|
+
)}
|
|
3086
|
+
${Array.from({ length: a }, (u, x) => {
|
|
3087
|
+
const Z = f / Math.max(1, a - 1), st = `${i[x] ?? `Point ${x + 1}`}: ${e.map((at) => `${at.name} ${this.fmt(at.values[x] ?? 0)}`).join(", ")}`;
|
|
3088
|
+
return A`<rect class="baht-chart-hit" x=${(_(x) - Z / 2).toFixed(2)} y=${E.top}
|
|
3089
|
+
width=${Math.max(24, Z).toFixed(2)} height=${g} tabindex="0" role="button"
|
|
3090
|
+
aria-label=${st}
|
|
3091
|
+
@pointermove=${(at) => this.onHover(at, x, st)}
|
|
3092
|
+
@pointerleave=${() => this.onLeave()}
|
|
3093
|
+
@focus=${(at) => this.onHover(at, x, st)}
|
|
3094
|
+
@blur=${() => this.onLeave()}/>`;
|
|
3095
|
+
})}
|
|
3096
|
+
${this.crosshairAt != null ? A`<line class="baht-chart-crosshair" x1=${_(this.crosshairAt).toFixed(2)}
|
|
3097
|
+
x2=${_(this.crosshairAt).toFixed(2)} y1=${E.top} y2=${E.top + g}/>` : h}
|
|
3098
|
+
</svg>
|
|
3099
|
+
${this.renderTooltip()}
|
|
3100
|
+
${this.renderLegend(
|
|
3101
|
+
e.map((u, x) => ({ label: u.name, color: nt(x, u.color) })),
|
|
3102
|
+
"line"
|
|
3103
|
+
)}
|
|
3104
|
+
${this.showTable ? be(
|
|
3105
|
+
this.label || "Line chart data",
|
|
3106
|
+
["Point", ...e.map((u) => u.name)],
|
|
3107
|
+
Array.from({ length: a }, (u, x) => [
|
|
3108
|
+
i[x] ?? `Point ${x + 1}`,
|
|
3109
|
+
...e.map((Z) => this.fmt(Z.values[x] ?? 0))
|
|
3110
|
+
])
|
|
3111
|
+
) : h}
|
|
3112
|
+
</div>`;
|
|
3113
|
+
}
|
|
3114
|
+
onHover(t, e, i) {
|
|
3115
|
+
this.crosshairAt = e, this.requestUpdate(), this.showTip(t, i);
|
|
3116
|
+
}
|
|
3117
|
+
onLeave() {
|
|
3118
|
+
this.crosshairAt = null, this.requestUpdate(), this.hideTip();
|
|
3119
|
+
}
|
|
3120
|
+
};
|
|
3121
|
+
lt([
|
|
3122
|
+
l({ attribute: !1 })
|
|
3123
|
+
], Q.prototype, "series", 2);
|
|
3124
|
+
lt([
|
|
3125
|
+
l({ attribute: !1 })
|
|
3126
|
+
], Q.prototype, "categories", 2);
|
|
3127
|
+
lt([
|
|
3128
|
+
l({ type: Boolean })
|
|
3129
|
+
], Q.prototype, "area", 2);
|
|
3130
|
+
lt([
|
|
3131
|
+
l({ attribute: !1 })
|
|
3132
|
+
], Q.prototype, "markers", 2);
|
|
3133
|
+
lt([
|
|
3134
|
+
l({ type: Number })
|
|
3135
|
+
], Q.prototype, "forecast", 2);
|
|
3136
|
+
lt([
|
|
3137
|
+
l({ type: Number })
|
|
3138
|
+
], Q.prototype, "baseline", 2);
|
|
3139
|
+
lt([
|
|
3140
|
+
l({ attribute: "label-values" })
|
|
3141
|
+
], Q.prototype, "labelValues", 2);
|
|
3142
|
+
lt([
|
|
3143
|
+
l()
|
|
3144
|
+
], Q.prototype, "label", 2);
|
|
3145
|
+
Q = lt([
|
|
3146
|
+
b("baht-line-chart")
|
|
3147
|
+
], Q);
|
|
3148
|
+
var Qa = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, wt = (t, e, i, a) => {
|
|
3149
|
+
for (var s = a > 1 ? void 0 : a ? ti(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3150
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3151
|
+
return a && s && Qa(e, i, s), s;
|
|
3152
|
+
};
|
|
3153
|
+
const _e = 22, Nt = 24, ss = 34, ke = 18, ei = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
3154
|
+
function Pe(t) {
|
|
3155
|
+
const e = /^(\d{4})-(\d{2})-(\d{2})/.exec(t ?? "");
|
|
3156
|
+
return e ? new Date(Date.UTC(+e[1], +e[2] - 1, +e[3])) : null;
|
|
3157
|
+
}
|
|
3158
|
+
function Oe(t) {
|
|
3159
|
+
return t.toISOString().slice(0, 10);
|
|
3160
|
+
}
|
|
3161
|
+
let pt = class extends tt {
|
|
3162
|
+
constructor() {
|
|
3163
|
+
super(...arguments), this.values = [], this.from = "", this.to = "", this.lessLabel = "Less", this.moreLabel = "More", this.label = "";
|
|
3164
|
+
}
|
|
3165
|
+
get range() {
|
|
3166
|
+
const t = (this.values ?? []).map((a) => Pe(a.date)).filter((a) => !!a), e = Pe(this.from) ?? (t.length ? new Date(Math.min(...t.map((a) => +a))) : null), i = Pe(this.to) ?? (t.length ? new Date(Math.max(...t.map((a) => +a))) : null);
|
|
3167
|
+
return !e || !i || +i < +e ? null : { start: e, end: i };
|
|
3168
|
+
}
|
|
3169
|
+
render() {
|
|
3170
|
+
const t = this.hold({ values: this.values ?? [], range: this.range }), e = t.range;
|
|
3171
|
+
if (!e || t.values.length === 0)
|
|
3172
|
+
return n`<div class=${this.rootClass("baht-heatmap")}>${this.renderEmpty()}</div>`;
|
|
3173
|
+
const i = new Map(t.values.map((d) => [d.date.slice(0, 10), d.value])), a = [], s = new Date(e.start), r = (e.start.getUTCDay() + 6) % 7;
|
|
3174
|
+
let o = 0;
|
|
3175
|
+
for (; +s <= +e.end; ) {
|
|
3176
|
+
const d = Oe(s), v = (s.getUTCDay() + 6) % 7, z = Math.floor((r + o) / 7);
|
|
3177
|
+
a.push({ iso: d, value: i.has(d) ? i.get(d) : null, col: z, row: v }), s.setUTCDate(s.getUTCDate() + 1), o += 1;
|
|
3178
|
+
}
|
|
3179
|
+
const c = Math.max(1, ...a.map((d) => d.col + 1)), f = ss + c * Nt, g = ke + 7 * Nt + 4, _ = Math.max(1, ...a.map((d) => d.value ?? 0)), p = (d) => Math.min(4, Math.max(0, Math.ceil(d / _ * 5) - 1)), w = a.reduce((d, v) => d + (v.value ?? 0), 0), C = this.label || `Calendar heatmap, ${a.length} days from ${Oe(e.start)} to ${Oe(e.end)}, total ${this.fmt(w)}`;
|
|
3180
|
+
return n`<div class=${this.rootClass("baht-heatmap")}>
|
|
3181
|
+
<svg
|
|
3182
|
+
class="baht-chart-svg baht-heatmap-svg"
|
|
3183
|
+
width=${f}
|
|
3184
|
+
height=${g}
|
|
3185
|
+
viewBox="0 0 ${f} ${g}"
|
|
3186
|
+
preserveAspectRatio="xMinYMin meet"
|
|
3187
|
+
role="img"
|
|
3188
|
+
aria-label=${C}
|
|
3189
|
+
>
|
|
3190
|
+
${ei.map(
|
|
3191
|
+
(d, v) => v % 2 === 0 ? A`<text class="baht-chart-tick" x="0" y=${ke + v * Nt + _e / 2 + 4}>${d}</text>` : h
|
|
3192
|
+
)}
|
|
3193
|
+
${a.map((d) => {
|
|
3194
|
+
const v = d.value == null ? `${d.iso}: no activity` : `${d.iso}: ${this.fmt(d.value)}`, z = d.value == null || d.value <= 0 ? "var(--baht-chart-grid)" : Xe(p(d.value));
|
|
3195
|
+
return A`<rect class="baht-heatmap-cell" x=${ss + d.col * Nt} y=${ke + d.row * Nt}
|
|
3196
|
+
width=${_e} height=${_e} rx="3" fill=${z} tabindex="0" role="button" aria-label=${v}
|
|
3197
|
+
@pointermove=${(P) => this.showTip(P, v)}
|
|
3198
|
+
@pointerleave=${() => this.hideTip()}
|
|
3199
|
+
@focus=${(P) => this.showTip(P, v)}
|
|
3200
|
+
@blur=${() => this.hideTip()}/>`;
|
|
3201
|
+
})}
|
|
3202
|
+
</svg>
|
|
3203
|
+
${this.renderTooltip()}
|
|
3204
|
+
<div class="baht-heatmap-scale">
|
|
3205
|
+
<span class="baht-heatmap-scale-label">${this.lessLabel}</span>
|
|
3206
|
+
${[0, 1, 2, 3, 4].map(
|
|
3207
|
+
(d) => n`<span
|
|
3208
|
+
class="baht-chart-swatch"
|
|
3209
|
+
style=${`background:${Xe(d)}`}
|
|
3210
|
+
aria-hidden="true"
|
|
3211
|
+
></span>`
|
|
3212
|
+
)}
|
|
3213
|
+
<span class="baht-heatmap-scale-label">${this.moreLabel}</span>
|
|
3214
|
+
</div>
|
|
3215
|
+
${this.showTable ? be(
|
|
3216
|
+
this.label || "Calendar heatmap data",
|
|
3217
|
+
["Date", "Value"],
|
|
3218
|
+
a.map((d) => [d.iso, d.value == null ? "—" : this.fmt(d.value)])
|
|
3219
|
+
) : h}
|
|
3220
|
+
</div>`;
|
|
3221
|
+
}
|
|
3222
|
+
};
|
|
3223
|
+
wt([
|
|
3224
|
+
l({ attribute: !1 })
|
|
3225
|
+
], pt.prototype, "values", 2);
|
|
3226
|
+
wt([
|
|
3227
|
+
l()
|
|
3228
|
+
], pt.prototype, "from", 2);
|
|
3229
|
+
wt([
|
|
3230
|
+
l()
|
|
3231
|
+
], pt.prototype, "to", 2);
|
|
3232
|
+
wt([
|
|
3233
|
+
l({ attribute: "less-label" })
|
|
3234
|
+
], pt.prototype, "lessLabel", 2);
|
|
3235
|
+
wt([
|
|
3236
|
+
l({ attribute: "more-label" })
|
|
3237
|
+
], pt.prototype, "moreLabel", 2);
|
|
3238
|
+
wt([
|
|
3239
|
+
l()
|
|
3240
|
+
], pt.prototype, "label", 2);
|
|
3241
|
+
pt = wt([
|
|
3242
|
+
b("baht-heatmap")
|
|
3243
|
+
], pt);
|
|
3244
|
+
var si = Object.defineProperty, ai = Object.getOwnPropertyDescriptor, et = (t, e, i, a) => {
|
|
3245
|
+
for (var s = a > 1 ? void 0 : a ? ai(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3246
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3247
|
+
return a && s && si(e, i, s), s;
|
|
3248
|
+
};
|
|
3249
|
+
let W = class extends y {
|
|
3250
|
+
constructor() {
|
|
3251
|
+
super(...arguments), this.value = 0, this.max = 100, this.label = "", this.format = "number", this.currency = "THB", this.thresholds = { warning: 0.8, danger: 1 }, this.expected = null, this.overLabel = "Over budget", this.nearLabel = "Near limit";
|
|
3252
|
+
}
|
|
3253
|
+
get fraction() {
|
|
3254
|
+
const t = this.max || 1, e = this.value / t;
|
|
3255
|
+
return Number.isFinite(e) ? Math.max(0, e) : 0;
|
|
3256
|
+
}
|
|
3257
|
+
/** `ok` | `warning` | `danger`, from the fraction and the thresholds. */
|
|
3258
|
+
get severity() {
|
|
3259
|
+
const { warning: t, danger: e } = this.thresholds ?? { warning: 0.8, danger: 1 }, i = this.fraction;
|
|
3260
|
+
return i >= e ? "danger" : i >= t ? "warning" : "ok";
|
|
3261
|
+
}
|
|
3262
|
+
get statusText() {
|
|
3263
|
+
const t = this.severity;
|
|
3264
|
+
return t === "danger" ? this.overLabel : t === "warning" ? this.nearLabel : "";
|
|
3265
|
+
}
|
|
3266
|
+
render() {
|
|
3267
|
+
const t = this.severity, e = Math.min(100, this.fraction * 100), i = (o) => qt(o, this.format, this.currency), a = this.expected != null && Number.isFinite(this.expected) && this.max ? Math.min(100, Math.max(0, this.expected / this.max * 100)) : null, s = `${i(this.value)} of ${i(this.max)}`, r = t === "danger" ? "!" : t === "warning" ? "△" : "";
|
|
3268
|
+
return n`<div class="baht-meter baht-meter--${t}">
|
|
3269
|
+
<div class="baht-meter-head">
|
|
3270
|
+
${this.label ? n`<span class="baht-meter-label">${this.label}</span>` : h}
|
|
3271
|
+
<span class="baht-meter-value">${s}</span>
|
|
3272
|
+
${this.statusText ? n`<span class="baht-meter-status"
|
|
3273
|
+
><span class="baht-meter-icon" aria-hidden="true">${r}</span
|
|
3274
|
+
>${this.statusText}</span
|
|
3275
|
+
>` : h}
|
|
3276
|
+
</div>
|
|
3277
|
+
<div
|
|
3278
|
+
class="baht-meter-track"
|
|
3279
|
+
role="meter"
|
|
3280
|
+
aria-label=${this.label || "Meter"}
|
|
3281
|
+
aria-valuemin="0"
|
|
3282
|
+
aria-valuemax=${this.max}
|
|
3283
|
+
aria-valuenow=${this.value}
|
|
3284
|
+
aria-valuetext=${`${s}${this.statusText ? `, ${this.statusText}` : ""}`}
|
|
3285
|
+
>
|
|
3286
|
+
<div class="baht-meter-fill" style=${`width:${e.toFixed(2)}%`}></div>
|
|
3287
|
+
${a != null ? n`<span
|
|
3288
|
+
class="baht-meter-expected"
|
|
3289
|
+
style=${`left:${a.toFixed(2)}%`}
|
|
3290
|
+
aria-hidden="true"
|
|
3291
|
+
></span>` : h}
|
|
3292
|
+
</div>
|
|
3293
|
+
${a != null ? n`<div class="baht-meter-pace">Expected by now ${i(this.expected)}</div>` : h}
|
|
3294
|
+
</div>`;
|
|
3295
|
+
}
|
|
3296
|
+
};
|
|
3297
|
+
et([
|
|
3298
|
+
l({ type: Number })
|
|
3299
|
+
], W.prototype, "value", 2);
|
|
3300
|
+
et([
|
|
3301
|
+
l({ type: Number })
|
|
3302
|
+
], W.prototype, "max", 2);
|
|
3303
|
+
et([
|
|
3304
|
+
l()
|
|
3305
|
+
], W.prototype, "label", 2);
|
|
3306
|
+
et([
|
|
3307
|
+
l()
|
|
3308
|
+
], W.prototype, "format", 2);
|
|
3309
|
+
et([
|
|
3310
|
+
l()
|
|
3311
|
+
], W.prototype, "currency", 2);
|
|
3312
|
+
et([
|
|
3313
|
+
l({ attribute: !1 })
|
|
3314
|
+
], W.prototype, "thresholds", 2);
|
|
3315
|
+
et([
|
|
3316
|
+
l({ type: Number })
|
|
3317
|
+
], W.prototype, "expected", 2);
|
|
3318
|
+
et([
|
|
3319
|
+
l({ attribute: "over-label" })
|
|
3320
|
+
], W.prototype, "overLabel", 2);
|
|
3321
|
+
et([
|
|
3322
|
+
l({ attribute: "near-label" })
|
|
3323
|
+
], W.prototype, "nearLabel", 2);
|
|
3324
|
+
W = et([
|
|
3325
|
+
b("baht-meter")
|
|
3326
|
+
], W);
|
|
3327
|
+
var ii = Object.defineProperty, ri = Object.getOwnPropertyDescriptor, fe = (t, e, i, a) => {
|
|
3328
|
+
for (var s = a > 1 ? void 0 : a ? ri(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3329
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3330
|
+
return a && s && ii(e, i, s), s;
|
|
3331
|
+
};
|
|
3332
|
+
let Ht = class extends y {
|
|
3333
|
+
constructor() {
|
|
3334
|
+
super(...arguments), this.icon = "🗂️", this.message = "Nothing to display", this.hint = "";
|
|
3335
|
+
}
|
|
3336
|
+
render() {
|
|
3337
|
+
return n`<div class="baht-empty-state">
|
|
3338
|
+
${this.icon ? n`<div class="baht-empty-state-icon" aria-hidden="true">${this.icon}</div>` : h}
|
|
3339
|
+
<div class="baht-empty-state-message">${this.message}</div>
|
|
3340
|
+
${this.hint ? n`<div class="baht-empty-state-hint">${this.hint}</div>` : h}
|
|
3341
|
+
</div>`;
|
|
3342
|
+
}
|
|
3343
|
+
};
|
|
3344
|
+
fe([
|
|
3345
|
+
l()
|
|
3346
|
+
], Ht.prototype, "icon", 2);
|
|
3347
|
+
fe([
|
|
3348
|
+
l()
|
|
3349
|
+
], Ht.prototype, "message", 2);
|
|
3350
|
+
fe([
|
|
3351
|
+
l()
|
|
3352
|
+
], Ht.prototype, "hint", 2);
|
|
3353
|
+
Ht = fe([
|
|
3354
|
+
b("baht-empty-state")
|
|
3355
|
+
], Ht);
|
|
3356
|
+
var oi = Object.defineProperty, li = Object.getOwnPropertyDescriptor, Qt = (t, e, i, a) => {
|
|
3357
|
+
for (var s = a > 1 ? void 0 : a ? li(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3358
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3359
|
+
return a && s && oi(e, i, s), s;
|
|
3360
|
+
};
|
|
3361
|
+
let Et = class extends y {
|
|
3362
|
+
constructor() {
|
|
3363
|
+
super(...arguments), this.icon = "⚠️", this.heading = "Something went wrong", this.message = "", this.retryLabel = "";
|
|
3364
|
+
}
|
|
3365
|
+
onRetry() {
|
|
3366
|
+
this.dispatchEvent(new CustomEvent("baht-retry", { bubbles: !0, composed: !0 }));
|
|
3367
|
+
}
|
|
3368
|
+
render() {
|
|
3369
|
+
return n`<div class="baht-error-state" role="alert">
|
|
3370
|
+
${this.icon ? n`<div class="baht-error-state-icon" aria-hidden="true">${this.icon}</div>` : h}
|
|
3371
|
+
<div class="baht-error-state-heading">${this.heading}</div>
|
|
3372
|
+
${this.message ? n`<div class="baht-error-state-message">${this.message}</div>` : h}
|
|
3373
|
+
${this.retryLabel ? n`<baht-button size="sm" label=${this.retryLabel} @click=${this.onRetry}></baht-button>` : h}
|
|
3374
|
+
</div>`;
|
|
3375
|
+
}
|
|
3376
|
+
};
|
|
3377
|
+
Qt([
|
|
3378
|
+
l()
|
|
3379
|
+
], Et.prototype, "icon", 2);
|
|
3380
|
+
Qt([
|
|
3381
|
+
l()
|
|
3382
|
+
], Et.prototype, "heading", 2);
|
|
3383
|
+
Qt([
|
|
3384
|
+
l()
|
|
3385
|
+
], Et.prototype, "message", 2);
|
|
3386
|
+
Qt([
|
|
3387
|
+
l({ attribute: "retry-label" })
|
|
3388
|
+
], Et.prototype, "retryLabel", 2);
|
|
3389
|
+
Et = Qt([
|
|
3390
|
+
b("baht-error-state")
|
|
3391
|
+
], Et);
|
|
3392
|
+
var ni = Object.defineProperty, hi = Object.getOwnPropertyDescriptor, xt = (t, e, i, a) => {
|
|
3393
|
+
for (var s = a > 1 ? void 0 : a ? hi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3394
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3395
|
+
return a && s && ni(e, i, s), s;
|
|
3396
|
+
};
|
|
3397
|
+
let dt = class extends y {
|
|
3398
|
+
constructor() {
|
|
3399
|
+
super(...arguments), this.value = {}, this.keyPlaceholder = "key", this.valuePlaceholder = "value", this.add_label = "Add row", this.disabled = !1, this.rows = [{ k: "", v: "" }], this.syncedJson = "";
|
|
3400
|
+
}
|
|
3401
|
+
willUpdate(t) {
|
|
3402
|
+
if (!t.has("value")) return;
|
|
3403
|
+
const e = JSON.stringify(this.value ?? {});
|
|
3404
|
+
e !== this.syncedJson && (this.syncedJson = e, this.rows = this.toRows(this.value));
|
|
3405
|
+
}
|
|
3406
|
+
toRows(t) {
|
|
3407
|
+
const e = Object.entries(t ?? {}).map(([i, a]) => ({
|
|
3408
|
+
k: i,
|
|
3409
|
+
v: typeof a == "string" ? a : JSON.stringify(a)
|
|
3410
|
+
}));
|
|
3411
|
+
return e.length > 0 ? e : [{ k: "", v: "" }];
|
|
3412
|
+
}
|
|
3413
|
+
commit(t) {
|
|
3414
|
+
this.rows = t.length > 0 ? t : [{ k: "", v: "" }];
|
|
3415
|
+
const e = {};
|
|
3416
|
+
for (const i of t) i.k.trim() && (e[i.k.trim()] = i.v);
|
|
3417
|
+
this.syncedJson = JSON.stringify(e), this.dispatchEvent(
|
|
3418
|
+
new CustomEvent("baht-change", { detail: { value: e }, bubbles: !0, composed: !0 })
|
|
3419
|
+
);
|
|
3420
|
+
}
|
|
3421
|
+
edit(t, e) {
|
|
3422
|
+
this.commit(this.rows.map((i, a) => a === t ? { ...i, ...e } : i));
|
|
3423
|
+
}
|
|
3424
|
+
addRow() {
|
|
3425
|
+
this.rows = [...this.rows, { k: "", v: "" }];
|
|
3426
|
+
}
|
|
3427
|
+
render() {
|
|
3428
|
+
return n`<div class="baht-keyvalue">
|
|
3429
|
+
${this.rows.map(
|
|
3430
|
+
(t, e) => n`<div class="baht-keyvalue-row">
|
|
3431
|
+
<input
|
|
3432
|
+
class="baht-control baht-keyvalue-key"
|
|
3433
|
+
placeholder=${this.keyPlaceholder}
|
|
3434
|
+
aria-label="${this.keyPlaceholder} ${e + 1}"
|
|
3435
|
+
.value=${t.k}
|
|
3436
|
+
?disabled=${this.disabled}
|
|
3437
|
+
@input=${(i) => this.edit(e, { k: i.target.value })}
|
|
3438
|
+
/>
|
|
3439
|
+
<span class="baht-keyvalue-eq" aria-hidden="true">=</span>
|
|
3440
|
+
<input
|
|
3441
|
+
class="baht-control baht-keyvalue-value"
|
|
3442
|
+
placeholder=${this.valuePlaceholder}
|
|
3443
|
+
aria-label="${this.valuePlaceholder} ${e + 1}"
|
|
3444
|
+
.value=${t.v}
|
|
3445
|
+
?disabled=${this.disabled}
|
|
3446
|
+
@input=${(i) => this.edit(e, { v: i.target.value })}
|
|
3447
|
+
/>
|
|
3448
|
+
<button
|
|
3449
|
+
type="button"
|
|
3450
|
+
class="baht-keyvalue-remove"
|
|
3451
|
+
aria-label="Remove row ${e + 1}"
|
|
3452
|
+
?disabled=${this.disabled}
|
|
3453
|
+
@click=${() => this.commit(this.rows.filter((i, a) => a !== e))}
|
|
3454
|
+
>${H("close")}</button>
|
|
3455
|
+
</div>`
|
|
3456
|
+
)}
|
|
3457
|
+
<button
|
|
3458
|
+
type="button"
|
|
3459
|
+
class="baht-keyvalue-add"
|
|
3460
|
+
?disabled=${this.disabled}
|
|
3461
|
+
@click=${this.addRow}
|
|
3462
|
+
>${H("plus")}${this.add_label}</button>
|
|
3463
|
+
</div>`;
|
|
3464
|
+
}
|
|
3465
|
+
};
|
|
3466
|
+
xt([
|
|
3467
|
+
l({ attribute: !1 })
|
|
3468
|
+
], dt.prototype, "value", 2);
|
|
3469
|
+
xt([
|
|
3470
|
+
l({ attribute: "key-placeholder" })
|
|
3471
|
+
], dt.prototype, "keyPlaceholder", 2);
|
|
3472
|
+
xt([
|
|
3473
|
+
l({ attribute: "value-placeholder" })
|
|
3474
|
+
], dt.prototype, "valuePlaceholder", 2);
|
|
3475
|
+
xt([
|
|
3476
|
+
l({ attribute: "add-label" })
|
|
3477
|
+
], dt.prototype, "add_label", 2);
|
|
3478
|
+
xt([
|
|
3479
|
+
l({ type: Boolean })
|
|
3480
|
+
], dt.prototype, "disabled", 2);
|
|
3481
|
+
xt([
|
|
3482
|
+
$()
|
|
3483
|
+
], dt.prototype, "rows", 2);
|
|
3484
|
+
dt = xt([
|
|
3485
|
+
b("baht-keyvalue-editor")
|
|
3486
|
+
], dt);
|
|
3487
|
+
var ci = Object.defineProperty, pi = Object.getOwnPropertyDescriptor, T = (t, e, i, a) => {
|
|
3488
|
+
for (var s = a > 1 ? void 0 : a ? pi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3489
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3490
|
+
return a && s && ci(e, i, s), s;
|
|
3491
|
+
};
|
|
3492
|
+
let j = class extends y {
|
|
3493
|
+
constructor() {
|
|
3494
|
+
super(...arguments), this.label = "Reference", this.value = "", this.display = "", this.placeholder = "", this.disabled = !1, this.invalid = !1, this.href = "", this.lookupLabel = "Look up records", this.debounce = 200, this.fetcher = null, this.open = !1, this.term = "", this.options = [], this.loading = !1, this.activeIndex = -1, this.fetchSeq = 0, this.onDocMousedown = (t) => {
|
|
3495
|
+
this.contains(t.target) || this.close();
|
|
3496
|
+
};
|
|
3497
|
+
}
|
|
3498
|
+
get listboxId() {
|
|
3499
|
+
return `baht-refpicker-list-${this.uid}`;
|
|
3500
|
+
}
|
|
3501
|
+
disconnectedCallback() {
|
|
3502
|
+
super.disconnectedCallback(), clearTimeout(this.timer), S() && document.removeEventListener("mousedown", this.onDocMousedown);
|
|
3503
|
+
}
|
|
3504
|
+
openLookup() {
|
|
3505
|
+
this.disabled || this.open || (this.open = !0, this.term = "", this.activeIndex = -1, S() && document.addEventListener("mousedown", this.onDocMousedown), this.search(""), this.updateComplete.then(() => {
|
|
3506
|
+
var t;
|
|
3507
|
+
return (t = this.inputEl) == null ? void 0 : t.focus();
|
|
3508
|
+
}));
|
|
3509
|
+
}
|
|
3510
|
+
close() {
|
|
3511
|
+
this.open && (this.open = !1, this.loading = !1, clearTimeout(this.timer), S() && document.removeEventListener("mousedown", this.onDocMousedown));
|
|
3512
|
+
}
|
|
3513
|
+
search(t) {
|
|
3514
|
+
clearTimeout(this.timer), this.timer = setTimeout(async () => {
|
|
3515
|
+
if (!this.fetcher) return;
|
|
3516
|
+
const e = ++this.fetchSeq;
|
|
3517
|
+
this.loading = !0;
|
|
3518
|
+
try {
|
|
3519
|
+
const i = await this.fetcher(t);
|
|
3520
|
+
e === this.fetchSeq && (this.options = i);
|
|
3521
|
+
} catch {
|
|
3522
|
+
e === this.fetchSeq && (this.options = []);
|
|
3523
|
+
} finally {
|
|
3524
|
+
e === this.fetchSeq && (this.loading = !1);
|
|
3525
|
+
}
|
|
3526
|
+
}, this.debounce);
|
|
3527
|
+
}
|
|
3528
|
+
pick(t) {
|
|
3529
|
+
this.close(), this.emitChange(t.key, t.label);
|
|
3530
|
+
}
|
|
3531
|
+
clear() {
|
|
3532
|
+
this.close(), this.emitChange("", "");
|
|
3533
|
+
}
|
|
3534
|
+
emitChange(t, e) {
|
|
3535
|
+
this.dispatchEvent(
|
|
3536
|
+
new CustomEvent("baht-change", {
|
|
3537
|
+
detail: { value: t, label: e },
|
|
3538
|
+
bubbles: !0,
|
|
3539
|
+
composed: !0
|
|
3540
|
+
})
|
|
3541
|
+
);
|
|
3542
|
+
}
|
|
3543
|
+
onInput(t) {
|
|
3544
|
+
this.term = t.target.value, this.activeIndex = -1, this.search(this.term);
|
|
3545
|
+
}
|
|
3546
|
+
onKeydown(t) {
|
|
3547
|
+
if (this.open)
|
|
3548
|
+
if (t.key === "ArrowDown" || t.key === "ArrowUp") {
|
|
3549
|
+
t.preventDefault();
|
|
3550
|
+
const e = t.key === "ArrowDown" ? 1 : -1, i = this.options.length;
|
|
3551
|
+
i > 0 && (this.activeIndex = (this.activeIndex + e + i) % i);
|
|
3552
|
+
} else if (t.key === "Enter") {
|
|
3553
|
+
t.preventDefault();
|
|
3554
|
+
const e = this.options[this.activeIndex];
|
|
3555
|
+
e && this.pick(e);
|
|
3556
|
+
} else t.key === "Escape" && (t.preventDefault(), this.close());
|
|
3557
|
+
}
|
|
3558
|
+
render() {
|
|
3559
|
+
const t = this.open ? this.term : this.display || this.value;
|
|
3560
|
+
return n`<div class="baht-refpicker${this.open ? " baht-refpicker--open" : ""}">
|
|
3561
|
+
<div class="baht-refpicker-field">
|
|
3562
|
+
<input
|
|
3563
|
+
class="baht-control baht-refpicker-input"
|
|
3564
|
+
type="text"
|
|
3565
|
+
role="combobox"
|
|
3566
|
+
aria-label=${this.label}
|
|
3567
|
+
aria-expanded=${this.open ? "true" : "false"}
|
|
3568
|
+
aria-controls=${this.listboxId}
|
|
3569
|
+
aria-autocomplete="list"
|
|
3570
|
+
aria-invalid=${this.invalid ? "true" : h}
|
|
3571
|
+
aria-activedescendant=${this.activeIndex >= 0 ? `${this.listboxId}-${this.activeIndex}` : h}
|
|
3572
|
+
placeholder=${this.open ? this.placeholder || "Search…" : this.placeholder}
|
|
3573
|
+
.value=${t}
|
|
3574
|
+
?disabled=${this.disabled}
|
|
3575
|
+
?readonly=${!this.open}
|
|
3576
|
+
@focus=${() => this.openLookup()}
|
|
3577
|
+
@input=${this.onInput}
|
|
3578
|
+
@keydown=${this.onKeydown}
|
|
3579
|
+
/>
|
|
3580
|
+
${this.value && !this.disabled ? n`<button
|
|
3581
|
+
type="button"
|
|
3582
|
+
class="baht-refpicker-clear"
|
|
3583
|
+
aria-label="Clear"
|
|
3584
|
+
@mousedown=${(e) => e.preventDefault()}
|
|
3585
|
+
@click=${() => this.clear()}
|
|
3586
|
+
>${H("close")}</button>` : h}
|
|
3587
|
+
</div>
|
|
3588
|
+
<button
|
|
3589
|
+
type="button"
|
|
3590
|
+
class="baht-refpicker-lookup"
|
|
3591
|
+
aria-label=${this.lookupLabel}
|
|
3592
|
+
title=${this.lookupLabel}
|
|
3593
|
+
?disabled=${this.disabled}
|
|
3594
|
+
@click=${() => this.open ? this.close() : this.openLookup()}
|
|
3595
|
+
>${H("search")}</button>
|
|
3596
|
+
${this.value && this.href ? n`<a
|
|
3597
|
+
class="baht-refpicker-open"
|
|
3598
|
+
href=${this.href}
|
|
3599
|
+
aria-label="Open record"
|
|
3600
|
+
title="Open record"
|
|
3601
|
+
>${H("external")}</a>` : h}
|
|
3602
|
+
<div
|
|
3603
|
+
class="baht-refpicker-list"
|
|
3604
|
+
id=${this.listboxId}
|
|
3605
|
+
role="listbox"
|
|
3606
|
+
aria-label=${this.label}
|
|
3607
|
+
aria-busy=${this.loading ? "true" : h}
|
|
3608
|
+
?hidden=${!this.open}
|
|
3609
|
+
>
|
|
3610
|
+
${this.loading ? n`<div class="baht-refpicker-note" role="option" aria-disabled="true" aria-selected="false">Searching…</div>` : this.options.length === 0 ? n`<div class="baht-refpicker-note" role="option" aria-disabled="true" aria-selected="false">No matches</div>` : this.options.map(
|
|
3611
|
+
(e, i) => n`<button
|
|
3612
|
+
type="button"
|
|
3613
|
+
class="baht-refpicker-option${i === this.activeIndex ? " baht-refpicker-option--active" : ""}"
|
|
3614
|
+
id="${this.listboxId}-${i}"
|
|
3615
|
+
role="option"
|
|
3616
|
+
aria-selected=${e.key === this.value ? "true" : "false"}
|
|
3617
|
+
@mousedown=${(a) => a.preventDefault()}
|
|
3618
|
+
@click=${() => this.pick(e)}
|
|
3619
|
+
>
|
|
3620
|
+
<span class="baht-refpicker-option-label">${e.label}</span>
|
|
3621
|
+
${e.sub ? n`<span class="baht-refpicker-option-sub">${e.sub}</span>` : h}
|
|
3622
|
+
</button>`
|
|
3623
|
+
)}
|
|
3624
|
+
</div>
|
|
3625
|
+
</div>`;
|
|
3626
|
+
}
|
|
3627
|
+
};
|
|
3628
|
+
T([
|
|
3629
|
+
l()
|
|
3630
|
+
], j.prototype, "label", 2);
|
|
3631
|
+
T([
|
|
3632
|
+
l()
|
|
3633
|
+
], j.prototype, "value", 2);
|
|
3634
|
+
T([
|
|
3635
|
+
l()
|
|
3636
|
+
], j.prototype, "display", 2);
|
|
3637
|
+
T([
|
|
3638
|
+
l()
|
|
3639
|
+
], j.prototype, "placeholder", 2);
|
|
3640
|
+
T([
|
|
3641
|
+
l({ type: Boolean })
|
|
3642
|
+
], j.prototype, "disabled", 2);
|
|
3643
|
+
T([
|
|
3644
|
+
l({ type: Boolean })
|
|
3645
|
+
], j.prototype, "invalid", 2);
|
|
3646
|
+
T([
|
|
3647
|
+
l()
|
|
3648
|
+
], j.prototype, "href", 2);
|
|
3649
|
+
T([
|
|
3650
|
+
l({ attribute: "lookup-label" })
|
|
3651
|
+
], j.prototype, "lookupLabel", 2);
|
|
3652
|
+
T([
|
|
3653
|
+
l({ type: Number })
|
|
3654
|
+
], j.prototype, "debounce", 2);
|
|
3655
|
+
T([
|
|
3656
|
+
l({ attribute: !1 })
|
|
3657
|
+
], j.prototype, "fetcher", 2);
|
|
3658
|
+
T([
|
|
3659
|
+
$()
|
|
3660
|
+
], j.prototype, "open", 2);
|
|
3661
|
+
T([
|
|
3662
|
+
$()
|
|
3663
|
+
], j.prototype, "term", 2);
|
|
3664
|
+
T([
|
|
3665
|
+
$()
|
|
3666
|
+
], j.prototype, "options", 2);
|
|
3667
|
+
T([
|
|
3668
|
+
$()
|
|
3669
|
+
], j.prototype, "loading", 2);
|
|
3670
|
+
T([
|
|
3671
|
+
$()
|
|
3672
|
+
], j.prototype, "activeIndex", 2);
|
|
3673
|
+
T([
|
|
3674
|
+
Bt("input")
|
|
3675
|
+
], j.prototype, "inputEl", 2);
|
|
3676
|
+
j = T([
|
|
3677
|
+
b("baht-reference-picker")
|
|
3678
|
+
], j);
|
|
3679
|
+
var di = Object.defineProperty, ui = Object.getOwnPropertyDescriptor, I = (t, e, i, a) => {
|
|
3680
|
+
for (var s = a > 1 ? void 0 : a ? ui(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3681
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3682
|
+
return a && s && di(e, i, s), s;
|
|
3683
|
+
};
|
|
3684
|
+
let F = class extends y {
|
|
3685
|
+
constructor() {
|
|
3686
|
+
super(...arguments), this.label = "Search", this.value = "", this.placeholder = "", this.disabled = !1, this.invalid = !1, this.options = [], this.fetcher = null, this.debounce = 150, this.minChars = 1, this.maxItems = 8, this.freeText = !0, this.autocomplete = "off", this.term = "", this.open = !1, this.results = [], this.loading = !1, this.activeIndex = -1, this.fetchSeq = 0, this.picked = null, this.lastPicked = null, this.onDocMousedown = (t) => {
|
|
3687
|
+
this.contains(t.target) || this.close();
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
get inputId() {
|
|
3691
|
+
return `baht-typeahead-${this.uid}`;
|
|
3692
|
+
}
|
|
3693
|
+
get listboxId() {
|
|
3694
|
+
return `${this.inputId}-list`;
|
|
3695
|
+
}
|
|
3696
|
+
optionId(t) {
|
|
3697
|
+
return `${this.listboxId}-${t}`;
|
|
3698
|
+
}
|
|
3699
|
+
disconnectedCallback() {
|
|
3700
|
+
super.disconnectedCallback(), clearTimeout(this.timer), S() && document.removeEventListener("mousedown", this.onDocMousedown);
|
|
3701
|
+
}
|
|
3702
|
+
willUpdate(t) {
|
|
3703
|
+
super.willUpdate(t), t.has("value") && this.timer === void 0 && (this.term = this.value);
|
|
3704
|
+
}
|
|
3705
|
+
updated() {
|
|
3706
|
+
var t, e;
|
|
3707
|
+
!this.open || this.activeIndex < 0 || (e = (t = this.querySelector(`#${this.optionId(this.activeIndex)}`)) == null ? void 0 : t.scrollIntoView) == null || e.call(t, {
|
|
3708
|
+
block: "nearest"
|
|
3709
|
+
});
|
|
3710
|
+
}
|
|
3711
|
+
// ---- suggestions -----------------------------------------------------
|
|
3712
|
+
filterStatic(t) {
|
|
3713
|
+
var s;
|
|
3714
|
+
const e = t.trim().toLowerCase();
|
|
3715
|
+
if (!e) return this.options.slice(0, this.maxItems);
|
|
3716
|
+
const i = [], a = [];
|
|
3717
|
+
for (const r of this.options) {
|
|
3718
|
+
const o = r.label.toLowerCase();
|
|
3719
|
+
o.startsWith(e) ? i.push(r) : (o.includes(e) || (s = r.sub) != null && s.toLowerCase().includes(e)) && a.push(r);
|
|
3720
|
+
}
|
|
3721
|
+
return [...i, ...a].slice(0, this.maxItems);
|
|
3722
|
+
}
|
|
3723
|
+
async suggest(t) {
|
|
3724
|
+
if (t.length < this.minChars) {
|
|
3725
|
+
this.results = [], this.loading = !1, this.close();
|
|
3726
|
+
return;
|
|
3727
|
+
}
|
|
3728
|
+
if (!this.fetcher) {
|
|
3729
|
+
this.results = this.filterStatic(t), this.activeIndex = -1, this.open = !0, this.listen();
|
|
3730
|
+
return;
|
|
3731
|
+
}
|
|
3732
|
+
const e = ++this.fetchSeq;
|
|
3733
|
+
this.loading = !0, this.open = !0, this.listen();
|
|
3734
|
+
try {
|
|
3735
|
+
const i = await this.fetcher(t);
|
|
3736
|
+
e === this.fetchSeq && (this.results = i.slice(0, this.maxItems));
|
|
3737
|
+
} catch {
|
|
3738
|
+
e === this.fetchSeq && (this.results = []);
|
|
3739
|
+
} finally {
|
|
3740
|
+
e === this.fetchSeq && (this.loading = !1, this.activeIndex = -1);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
highlight(t) {
|
|
3744
|
+
this.activeIndex !== t && (this.activeIndex = t);
|
|
3745
|
+
}
|
|
3746
|
+
listen() {
|
|
3747
|
+
S() && document.addEventListener("mousedown", this.onDocMousedown);
|
|
3748
|
+
}
|
|
3749
|
+
close() {
|
|
3750
|
+
S() && document.removeEventListener("mousedown", this.onDocMousedown), this.open && (this.open = !1, this.activeIndex = -1);
|
|
3751
|
+
}
|
|
3752
|
+
// ---- events ------------------------------------------------------------
|
|
3753
|
+
emitChange(t, e) {
|
|
3754
|
+
this.dispatchEvent(
|
|
3755
|
+
new CustomEvent("baht-change", {
|
|
3756
|
+
detail: { value: t, option: e },
|
|
3757
|
+
bubbles: !0,
|
|
3758
|
+
composed: !0
|
|
3759
|
+
})
|
|
3760
|
+
);
|
|
3761
|
+
}
|
|
3762
|
+
onInput(t) {
|
|
3763
|
+
this.term = t.target.value, this.picked = null, clearTimeout(this.timer), this.timer = setTimeout(
|
|
3764
|
+
() => {
|
|
3765
|
+
this.timer = void 0, this.emitChange(this.term, null), this.suggest(this.term);
|
|
3766
|
+
},
|
|
3767
|
+
Math.max(0, this.debounce)
|
|
3768
|
+
);
|
|
3769
|
+
}
|
|
3770
|
+
/** Hand pending text to the host now (blur, Enter). */
|
|
3771
|
+
flush() {
|
|
3772
|
+
this.timer !== void 0 && (clearTimeout(this.timer), this.timer = void 0, this.emitChange(this.term, null));
|
|
3773
|
+
}
|
|
3774
|
+
pick(t) {
|
|
3775
|
+
clearTimeout(this.timer), this.timer = void 0, this.picked = t, this.lastPicked = t, this.term = t.label, this.close(), this.emitChange(t.label, t), this.dispatchEvent(
|
|
3776
|
+
new CustomEvent("baht-select", { detail: { option: t }, bubbles: !0, composed: !0 })
|
|
3777
|
+
);
|
|
3778
|
+
}
|
|
3779
|
+
onBlur() {
|
|
3780
|
+
if (!this.freeText && !this.picked) {
|
|
3781
|
+
clearTimeout(this.timer), this.timer = void 0;
|
|
3782
|
+
const t = this.lastPicked;
|
|
3783
|
+
this.term = (t == null ? void 0 : t.label) ?? "", this.picked = t, this.value !== this.term && this.emitChange(this.term, t);
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
this.flush();
|
|
3787
|
+
}
|
|
3788
|
+
onKeydown(t) {
|
|
3789
|
+
const e = this.results.length;
|
|
3790
|
+
switch (t.key) {
|
|
3791
|
+
case "ArrowDown":
|
|
3792
|
+
if (t.preventDefault(), !this.open) {
|
|
3793
|
+
this.suggest(this.term);
|
|
3794
|
+
return;
|
|
3795
|
+
}
|
|
3796
|
+
e > 0 && (this.activeIndex = (this.activeIndex + 1) % e);
|
|
3797
|
+
break;
|
|
3798
|
+
case "ArrowUp":
|
|
3799
|
+
t.preventDefault(), this.open && e > 0 && (this.activeIndex = (this.activeIndex - 1 + e) % e);
|
|
3800
|
+
break;
|
|
3801
|
+
case "Enter": {
|
|
3802
|
+
const i = this.open ? this.results[this.activeIndex] : void 0;
|
|
3803
|
+
i ? (t.preventDefault(), this.pick(i)) : (this.flush(), this.close());
|
|
3804
|
+
break;
|
|
3805
|
+
}
|
|
3806
|
+
case "Escape":
|
|
3807
|
+
this.open && (t.preventDefault(), this.close());
|
|
3808
|
+
break;
|
|
3809
|
+
case "Tab":
|
|
3810
|
+
this.flush(), this.close();
|
|
3811
|
+
break;
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
render() {
|
|
3815
|
+
const t = this.open, e = !this.loading && this.results.length === 0;
|
|
3816
|
+
return n`<div class="baht-typeahead${this.open ? " baht-typeahead--open" : ""}">
|
|
3817
|
+
<input
|
|
3818
|
+
class="baht-control baht-typeahead-input"
|
|
3819
|
+
id=${this.inputId}
|
|
3820
|
+
type="text"
|
|
3821
|
+
role="combobox"
|
|
3822
|
+
aria-label=${this.label}
|
|
3823
|
+
aria-autocomplete="list"
|
|
3824
|
+
aria-expanded=${t ? "true" : "false"}
|
|
3825
|
+
aria-controls=${this.listboxId}
|
|
3826
|
+
aria-activedescendant=${t && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : h}
|
|
3827
|
+
aria-invalid=${this.invalid ? "true" : h}
|
|
3828
|
+
autocomplete=${this.autocomplete}
|
|
3829
|
+
placeholder=${this.placeholder || h}
|
|
3830
|
+
.value=${ot(this.term)}
|
|
3831
|
+
?disabled=${this.disabled}
|
|
3832
|
+
@input=${(i) => this.onInput(i)}
|
|
3833
|
+
@keydown=${(i) => this.onKeydown(i)}
|
|
3834
|
+
@blur=${() => this.onBlur()}
|
|
3835
|
+
/>
|
|
3836
|
+
<div
|
|
3837
|
+
class="baht-listbox baht-typeahead-list"
|
|
3838
|
+
id=${this.listboxId}
|
|
3839
|
+
role="listbox"
|
|
3840
|
+
aria-label=${this.label}
|
|
3841
|
+
aria-busy=${this.loading ? "true" : h}
|
|
3842
|
+
?hidden=${!t}
|
|
3843
|
+
>
|
|
3844
|
+
${this.loading ? n`<div class="baht-listbox-note" role="option" aria-disabled="true" aria-selected="false">Searching…</div>` : e ? n`<div class="baht-listbox-note" role="option" aria-disabled="true" aria-selected="false">No matches</div>` : this.results.map(
|
|
3845
|
+
// eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox input (aria-activedescendant pattern)
|
|
3846
|
+
(i, a) => n`<div
|
|
3847
|
+
class="baht-listbox-option${a === this.activeIndex ? " baht-listbox-option--active" : ""}"
|
|
3848
|
+
id=${this.optionId(a)}
|
|
3849
|
+
role="option"
|
|
3850
|
+
aria-selected=${a === this.activeIndex ? "true" : "false"}
|
|
3851
|
+
data-key=${i.key}
|
|
3852
|
+
@mousedown=${(s) => s.preventDefault()}
|
|
3853
|
+
@mousemove=${() => this.highlight(a)}
|
|
3854
|
+
@click=${() => {
|
|
3855
|
+
var s;
|
|
3856
|
+
this.pick(i), (s = this.inputEl) == null || s.focus();
|
|
3857
|
+
}}
|
|
3858
|
+
>
|
|
3859
|
+
<span class="baht-listbox-option-label">${i.label}</span>
|
|
3860
|
+
${i.sub ? n`<span class="baht-listbox-option-sub">${i.sub}</span>` : h}
|
|
3861
|
+
</div>`
|
|
3862
|
+
)}
|
|
3863
|
+
</div>
|
|
3864
|
+
</div>`;
|
|
3865
|
+
}
|
|
3866
|
+
};
|
|
3867
|
+
I([
|
|
3868
|
+
l()
|
|
3869
|
+
], F.prototype, "label", 2);
|
|
3870
|
+
I([
|
|
3871
|
+
l()
|
|
3872
|
+
], F.prototype, "value", 2);
|
|
3873
|
+
I([
|
|
3874
|
+
l()
|
|
3875
|
+
], F.prototype, "placeholder", 2);
|
|
3876
|
+
I([
|
|
3877
|
+
l({ type: Boolean })
|
|
3878
|
+
], F.prototype, "disabled", 2);
|
|
3879
|
+
I([
|
|
3880
|
+
l({ type: Boolean })
|
|
3881
|
+
], F.prototype, "invalid", 2);
|
|
3882
|
+
I([
|
|
3883
|
+
l({ attribute: !1 })
|
|
3884
|
+
], F.prototype, "options", 2);
|
|
3885
|
+
I([
|
|
3886
|
+
l({ attribute: !1 })
|
|
3887
|
+
], F.prototype, "fetcher", 2);
|
|
3888
|
+
I([
|
|
3889
|
+
l({ type: Number })
|
|
3890
|
+
], F.prototype, "debounce", 2);
|
|
3891
|
+
I([
|
|
3892
|
+
l({ type: Number, attribute: "min-chars" })
|
|
3893
|
+
], F.prototype, "minChars", 2);
|
|
3894
|
+
I([
|
|
3895
|
+
l({ type: Number, attribute: "max-items" })
|
|
3896
|
+
], F.prototype, "maxItems", 2);
|
|
3897
|
+
I([
|
|
3898
|
+
l({ attribute: "free-text", converter: (t) => t !== "false" })
|
|
3899
|
+
], F.prototype, "freeText", 2);
|
|
3900
|
+
I([
|
|
3901
|
+
l()
|
|
3902
|
+
], F.prototype, "autocomplete", 2);
|
|
3903
|
+
I([
|
|
3904
|
+
$()
|
|
3905
|
+
], F.prototype, "term", 2);
|
|
3906
|
+
I([
|
|
3907
|
+
$()
|
|
3908
|
+
], F.prototype, "open", 2);
|
|
3909
|
+
I([
|
|
3910
|
+
$()
|
|
3911
|
+
], F.prototype, "results", 2);
|
|
3912
|
+
I([
|
|
3913
|
+
$()
|
|
3914
|
+
], F.prototype, "loading", 2);
|
|
3915
|
+
I([
|
|
3916
|
+
$()
|
|
3917
|
+
], F.prototype, "activeIndex", 2);
|
|
3918
|
+
I([
|
|
3919
|
+
Bt("input")
|
|
3920
|
+
], F.prototype, "inputEl", 2);
|
|
3921
|
+
F = I([
|
|
3922
|
+
b("baht-typeahead")
|
|
3923
|
+
], F);
|
|
3924
|
+
const cs = {
|
|
3925
|
+
text: "baht-input",
|
|
3926
|
+
email: "baht-input",
|
|
3927
|
+
password: "baht-input",
|
|
3928
|
+
textarea: "baht-textarea",
|
|
3929
|
+
number: "baht-number",
|
|
3930
|
+
dropdown: "baht-select",
|
|
3931
|
+
multiselect: "baht-multiselect",
|
|
3932
|
+
checkbox: "baht-checkbox",
|
|
3933
|
+
radio: "baht-radio",
|
|
3934
|
+
toggle: "baht-toggle",
|
|
3935
|
+
date: "baht-datepicker",
|
|
3936
|
+
file: "baht-file",
|
|
3937
|
+
label: "baht-text",
|
|
3938
|
+
section: "baht-section",
|
|
3939
|
+
repeater: "baht-repeater"
|
|
3940
|
+
};
|
|
3941
|
+
var bi = Object.defineProperty, fi = Object.getOwnPropertyDescriptor, ps = (t, e, i, a) => {
|
|
3942
|
+
for (var s = a > 1 ? void 0 : a ? fi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
3943
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
3944
|
+
return a && s && bi(e, i, s), s;
|
|
3945
|
+
};
|
|
3946
|
+
const mi = {
|
|
3947
|
+
"1/4": "baht-field--w-1-4",
|
|
3948
|
+
"1/2": "baht-field--w-1-2",
|
|
3949
|
+
"3/4": "baht-field--w-3-4",
|
|
3950
|
+
full: "baht-field--w-full"
|
|
3951
|
+
}, as = /* @__PURE__ */ new Map();
|
|
3952
|
+
function vi(t) {
|
|
3953
|
+
let e = as.get(t);
|
|
3954
|
+
return e || (e = os(t), as.set(t, e)), e;
|
|
3955
|
+
}
|
|
3956
|
+
let Ie = class extends J {
|
|
3957
|
+
constructor() {
|
|
3958
|
+
super(...arguments), this.rowErrors = [];
|
|
3959
|
+
}
|
|
3960
|
+
willUpdate(t) {
|
|
3961
|
+
super.willUpdate(t);
|
|
3962
|
+
}
|
|
3963
|
+
get rows() {
|
|
3964
|
+
return Array.isArray(this.value) ? this.value : [];
|
|
3965
|
+
}
|
|
3966
|
+
get subFields() {
|
|
3967
|
+
return [...this.field.fields ?? []].sort((t, e) => t.order - e.order).filter((t) => t.type !== "repeater");
|
|
3968
|
+
}
|
|
3969
|
+
patchRow(t, e, i) {
|
|
3970
|
+
const a = [...this.rows];
|
|
3971
|
+
a[t] = { ...a[t], [e]: i }, this.emitInput(a);
|
|
3972
|
+
}
|
|
3973
|
+
addRow() {
|
|
3974
|
+
const t = {};
|
|
3975
|
+
for (const e of this.subFields)
|
|
3976
|
+
e.type === "label" || e.type === "section" || (t[e.key] = se(e));
|
|
3977
|
+
this.emitInput([...this.rows, t]);
|
|
3978
|
+
}
|
|
3979
|
+
removeRow(t) {
|
|
3980
|
+
this.emitInput(this.rows.filter((e, i) => i !== t));
|
|
3981
|
+
}
|
|
3982
|
+
/** Pending keystrokes in any row land in the array before the host reads it. */
|
|
3983
|
+
flushTyped() {
|
|
3984
|
+
var t;
|
|
3985
|
+
if (!S()) return super.flushTyped();
|
|
3986
|
+
for (const e of this.querySelectorAll(".baht-repeater-row > .baht-field > *"))
|
|
3987
|
+
(t = e.flushTyped) == null || t.call(e);
|
|
3988
|
+
super.flushTyped();
|
|
3989
|
+
}
|
|
3990
|
+
errorFor(t, e) {
|
|
3991
|
+
var a;
|
|
3992
|
+
const i = `${this.field.key}[${t}].${e}`;
|
|
3993
|
+
return ((a = this.rowErrors.find((s) => s.key === i)) == null ? void 0 : a.message) ?? null;
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Sub-controls render declaratively (one static-tag template per primitive, rows
|
|
3997
|
+
* keyed by index) so Lit reuses the same node across re-renders — typing keeps
|
|
3998
|
+
* focus, same as <baht-form> — and the whole thing renders on the server.
|
|
3999
|
+
*/
|
|
4000
|
+
renderSub(t, e, i) {
|
|
4001
|
+
const a = cs[i.type];
|
|
4002
|
+
if (!a) return h;
|
|
4003
|
+
const s = vi(a), r = mi[i.width ?? "full"] ?? "baht-field--w-full", o = (c) => {
|
|
4004
|
+
c.stopPropagation();
|
|
4005
|
+
const { value: f } = c.detail;
|
|
4006
|
+
this.patchRow(e, i.key, f);
|
|
4007
|
+
};
|
|
4008
|
+
return n`<div class="baht-field ${r}" data-key=${i.key} data-type=${i.type}>
|
|
4009
|
+
${ee`<${s}
|
|
4010
|
+
.field=${i}
|
|
4011
|
+
.value=${Object.hasOwn(t, i.key) ? t[i.key] : se(i)}
|
|
4012
|
+
.disabled=${this.disabled}
|
|
4013
|
+
.readonly=${this.readonly}
|
|
4014
|
+
.required=${!!i.required}
|
|
4015
|
+
.error=${this.errorFor(e, i.key)}
|
|
4016
|
+
.debounce=${this.debounce}
|
|
4017
|
+
@baht-input=${o}
|
|
4018
|
+
></${s}>`}
|
|
4019
|
+
</div>`;
|
|
4020
|
+
}
|
|
4021
|
+
renderControl() {
|
|
4022
|
+
const t = this.rows, e = !this.disabled && !this.readonly, i = this.field.max_rows !== void 0 && t.length >= this.field.max_rows;
|
|
4023
|
+
return n`<div
|
|
4024
|
+
class="baht-repeater"
|
|
4025
|
+
id=${this.controlId}
|
|
4026
|
+
role="group"
|
|
4027
|
+
aria-labelledby=${this.field.label ? this.labelId : h}
|
|
4028
|
+
aria-describedby=${this.describedBy}
|
|
4029
|
+
>
|
|
4030
|
+
${Ce(
|
|
4031
|
+
t,
|
|
4032
|
+
(a, s) => s,
|
|
4033
|
+
(a, s) => n`<div
|
|
4034
|
+
class="baht-repeater-row"
|
|
4035
|
+
data-row=${s}
|
|
4036
|
+
role="group"
|
|
4037
|
+
aria-label=${m("row", { n: s + 1 })}
|
|
4038
|
+
>
|
|
4039
|
+
${Ce(
|
|
4040
|
+
this.subFields,
|
|
4041
|
+
(r) => r.key,
|
|
4042
|
+
(r) => this.renderSub(a, s, r)
|
|
4043
|
+
)}
|
|
4044
|
+
${e ? n`<button
|
|
4045
|
+
type="button"
|
|
4046
|
+
class="baht-repeater-remove"
|
|
4047
|
+
aria-label=${m("removeRowN", { n: s + 1 })}
|
|
4048
|
+
title=${m("removeRowN", { n: s + 1 })}
|
|
4049
|
+
@click=${() => this.removeRow(s)}
|
|
4050
|
+
>
|
|
4051
|
+
✕
|
|
4052
|
+
</button>` : h}
|
|
4053
|
+
</div>`
|
|
4054
|
+
)}
|
|
4055
|
+
${this.readonly ? h : n`<button
|
|
4056
|
+
type="button"
|
|
4057
|
+
class="baht-repeater-add"
|
|
4058
|
+
?disabled=${this.disabled || i}
|
|
4059
|
+
@click=${() => this.addRow()}
|
|
4060
|
+
>
|
|
4061
|
+
+ ${this.field.add_label ?? m("addRow")}
|
|
4062
|
+
</button>`}
|
|
4063
|
+
</div>`;
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
ps([
|
|
4067
|
+
l({ attribute: !1 })
|
|
4068
|
+
], Ie.prototype, "rowErrors", 2);
|
|
4069
|
+
Ie = ps([
|
|
4070
|
+
b("baht-repeater")
|
|
4071
|
+
], Ie);
|
|
4072
|
+
var $i = Object.defineProperty, yi = Object.getOwnPropertyDescriptor, me = (t, e, i, a) => {
|
|
4073
|
+
for (var s = a > 1 ? void 0 : a ? yi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
4074
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
4075
|
+
return a && s && $i(e, i, s), s;
|
|
4076
|
+
};
|
|
4077
|
+
let Gt = class extends y {
|
|
4078
|
+
constructor() {
|
|
4079
|
+
super(...arguments), this.steps = [], this.current = 0, this.variant = "default";
|
|
4080
|
+
}
|
|
4081
|
+
render() {
|
|
4082
|
+
const t = this.variant === "sidebar";
|
|
4083
|
+
return n`<ol
|
|
4084
|
+
class="baht-steps ${t ? "baht-steps--sidebar" : ""}"
|
|
4085
|
+
aria-label=${m("step", { current: this.current + 1, total: this.steps.length })}
|
|
4086
|
+
>
|
|
4087
|
+
${this.steps.map((e, i) => {
|
|
4088
|
+
const a = i < this.current ? "done" : i === this.current ? "current" : "todo";
|
|
4089
|
+
return n`<li
|
|
4090
|
+
class="baht-step baht-step--${a} ${t ? "baht-step--sidebar" : ""}"
|
|
4091
|
+
aria-current=${a === "current" ? "step" : "false"}
|
|
4092
|
+
>
|
|
4093
|
+
${t ? h : n`<span class="baht-step-marker" aria-hidden="true">${a === "done" ? "✓" : i + 1}</span>`}
|
|
4094
|
+
<span class="baht-step-label">${e}</span>
|
|
4095
|
+
${a === "done" ? n`<span class="baht-visually-hidden"> (${m("stepDone")})</span>` : a === "current" ? n`<span class="baht-visually-hidden"> (${m("stepCurrent")})</span>` : h}
|
|
4096
|
+
</li>`;
|
|
4097
|
+
})}
|
|
4098
|
+
</ol>`;
|
|
4099
|
+
}
|
|
4100
|
+
};
|
|
4101
|
+
me([
|
|
4102
|
+
l({ attribute: !1 })
|
|
4103
|
+
], Gt.prototype, "steps", 2);
|
|
4104
|
+
me([
|
|
4105
|
+
l({ type: Number })
|
|
4106
|
+
], Gt.prototype, "current", 2);
|
|
4107
|
+
me([
|
|
4108
|
+
l()
|
|
4109
|
+
], Gt.prototype, "variant", 2);
|
|
4110
|
+
Gt = me([
|
|
4111
|
+
b("baht-steps")
|
|
4112
|
+
], Gt);
|
|
4113
|
+
var gi = Object.defineProperty, wi = Object.getOwnPropertyDescriptor, X = (t, e, i, a) => {
|
|
4114
|
+
for (var s = a > 1 ? void 0 : a ? wi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
4115
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
4116
|
+
return a && s && gi(e, i, s), s;
|
|
4117
|
+
};
|
|
4118
|
+
const xi = {
|
|
4119
|
+
"1/4": "baht-field--w-1-4",
|
|
4120
|
+
"1/2": "baht-field--w-1-2",
|
|
4121
|
+
"3/4": "baht-field--w-3-4",
|
|
4122
|
+
full: "baht-field--w-full"
|
|
4123
|
+
}, is = /* @__PURE__ */ new Map();
|
|
4124
|
+
function _i(t) {
|
|
4125
|
+
let e = is.get(t);
|
|
4126
|
+
return e || (e = os(t), is.set(t, e)), e;
|
|
4127
|
+
}
|
|
4128
|
+
let U = class extends y {
|
|
4129
|
+
constructor() {
|
|
4130
|
+
super(...arguments), this.value = {}, this.registry = {}, this.options = {}, this.fieldStates = {}, this.flags = {}, this.readonly = !1, this.edits = {}, this.errors = [], this.dynamicOptions = /* @__PURE__ */ new Map(), this.optionsSnapshots = /* @__PURE__ */ new Map(), this.optionsEpoch = /* @__PURE__ */ new Map(), this.warnedViews = /* @__PURE__ */ new Set(), this.flagCache = {};
|
|
4131
|
+
}
|
|
4132
|
+
get effectiveForm() {
|
|
4133
|
+
return this.form ? ((this.flagCache.form !== this.form || this.flagCache.flags !== this.flags) && (this.flagCache = {
|
|
4134
|
+
form: this.form,
|
|
4135
|
+
flags: this.flags,
|
|
4136
|
+
out: rs(this.form, this.flags)
|
|
4137
|
+
}), this.flagCache.out) : this.form;
|
|
4138
|
+
}
|
|
4139
|
+
willUpdate(t) {
|
|
4140
|
+
t.has("value") && (this.edits = {}), (t.has("form") || t.has("flags")) && (this.dynamicOptions.clear(), this.optionsSnapshots.clear(), this.optionsEpoch.clear()), (t.has("form") || t.has("flags") || t.has("value") || t.has("registry")) && this.syncDynamicOptions();
|
|
4141
|
+
}
|
|
4142
|
+
/**
|
|
4143
|
+
* Refetch `options_from` options whose dep snapshot changed. Sync fetchers
|
|
4144
|
+
* land immediately; async ones re-render on resolve (stale responses are
|
|
4145
|
+
* dropped by epoch).
|
|
4146
|
+
*/
|
|
4147
|
+
syncDynamicOptions() {
|
|
4148
|
+
var e, i;
|
|
4149
|
+
const t = this.getData();
|
|
4150
|
+
for (const a of ((e = this.effectiveForm) == null ? void 0 : e.fields) ?? []) {
|
|
4151
|
+
if (!a.options_from) continue;
|
|
4152
|
+
const s = JSON.stringify((a.options_deps ?? []).map((f) => t[f] ?? null));
|
|
4153
|
+
if (this.optionsSnapshots.get(a.key) === s) continue;
|
|
4154
|
+
this.optionsSnapshots.set(a.key, s);
|
|
4155
|
+
const r = (this.optionsEpoch.get(a.key) ?? 0) + 1;
|
|
4156
|
+
this.optionsEpoch.set(a.key, r);
|
|
4157
|
+
const o = (i = this.registry.options) == null ? void 0 : i[a.options_from];
|
|
4158
|
+
if (!o) {
|
|
4159
|
+
console.warn(`[bahtui] unknown options fetcher "${a.options_from}" — skipped`), this.dynamicOptions.set(a.key, []);
|
|
4160
|
+
continue;
|
|
4161
|
+
}
|
|
4162
|
+
const c = o(t);
|
|
4163
|
+
c instanceof Promise ? c.then((f) => {
|
|
4164
|
+
this.optionsEpoch.get(a.key) === r && (this.dynamicOptions.set(a.key, f), this.requestUpdate());
|
|
4165
|
+
}).catch((f) => {
|
|
4166
|
+
console.warn(`[bahtui] options fetcher "${a.options_from}" failed`, f), this.optionsEpoch.get(a.key) === r && this.optionsSnapshots.delete(a.key);
|
|
4167
|
+
}) : this.dynamicOptions.set(a.key, c);
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
/**
|
|
4171
|
+
* A user edit invalidates every field whose options_deps include the edited
|
|
4172
|
+
* key — their values reset to defaults, cascading down chains
|
|
4173
|
+
* (province -> district -> subdistrict).
|
|
4174
|
+
*/
|
|
4175
|
+
clearDependents(t) {
|
|
4176
|
+
var a, s;
|
|
4177
|
+
const e = [t], i = /* @__PURE__ */ new Set();
|
|
4178
|
+
for (; e.length > 0; ) {
|
|
4179
|
+
const r = e.shift();
|
|
4180
|
+
for (const o of ((a = this.effectiveForm) == null ? void 0 : a.fields) ?? [])
|
|
4181
|
+
!((s = o.options_deps) != null && s.includes(r)) || i.has(o.key) || (i.add(o.key), this.edits = { ...this.edits, [o.key]: se(o) }, e.push(o.key));
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
get sortedFields() {
|
|
4185
|
+
if (!this.form) return [];
|
|
4186
|
+
const t = Ae(this.effectiveForm, this.view);
|
|
4187
|
+
return t || (this.view !== void 0 && !this.warnedViews.has(this.view) && (this.warnedViews.add(this.view), console.warn(`[bahtui] unknown view "${this.view}" — showing the full form`)), Ae(this.effectiveForm) ?? []);
|
|
4188
|
+
}
|
|
4189
|
+
stateFor(t) {
|
|
4190
|
+
return this.fieldStates[t.key] ?? {
|
|
4191
|
+
visible: !0,
|
|
4192
|
+
enabled: !t.disabled,
|
|
4193
|
+
readonly: !!t.readonly,
|
|
4194
|
+
required: !!t.required,
|
|
4195
|
+
computed: !1
|
|
4196
|
+
};
|
|
4197
|
+
}
|
|
4198
|
+
valueFor(t) {
|
|
4199
|
+
return Object.hasOwn(this.edits, t.key) ? this.edits[t.key] : Object.hasOwn(this.value, t.key) ? this.value[t.key] : se(t);
|
|
4200
|
+
}
|
|
4201
|
+
// ---- public API (spec 01 §6) ----
|
|
4202
|
+
/** Debounced keystrokes still in a control land in `edits` before anyone reads them. */
|
|
4203
|
+
flushTyped() {
|
|
4204
|
+
var t;
|
|
4205
|
+
if (S())
|
|
4206
|
+
for (const e of this.querySelectorAll(":scope > .baht-form > .baht-field > *"))
|
|
4207
|
+
(t = e.flushTyped) == null || t.call(e);
|
|
4208
|
+
}
|
|
4209
|
+
getData() {
|
|
4210
|
+
var e;
|
|
4211
|
+
this.flushTyped();
|
|
4212
|
+
const t = {};
|
|
4213
|
+
for (const i of ((e = this.effectiveForm) == null ? void 0 : e.fields) ?? [])
|
|
4214
|
+
i.type === "label" || i.type === "section" || (t[i.key] = this.valueFor(i));
|
|
4215
|
+
return t;
|
|
4216
|
+
}
|
|
4217
|
+
setValue(t) {
|
|
4218
|
+
this.edits = { ...this.edits, ...t }, this.requestUpdate();
|
|
4219
|
+
}
|
|
4220
|
+
validate() {
|
|
4221
|
+
const t = [], e = this.getData();
|
|
4222
|
+
for (const a of this.sortedFields) {
|
|
4223
|
+
if (a.type === "label" || a.type === "section") continue;
|
|
4224
|
+
const s = this.stateFor(a);
|
|
4225
|
+
if (!s.visible) continue;
|
|
4226
|
+
const r = s.required === !!a.required ? a : { ...a, required: s.required };
|
|
4227
|
+
t.push(...Le(r, this.valueFor(a), this.registry, e));
|
|
4228
|
+
}
|
|
4229
|
+
this.errors = t;
|
|
4230
|
+
const i = { valid: t.length === 0, errors: t };
|
|
4231
|
+
return this.dispatchEvent(
|
|
4232
|
+
new CustomEvent("baht-validity", { detail: i, bubbles: !0, composed: !0 })
|
|
4233
|
+
), i;
|
|
4234
|
+
}
|
|
4235
|
+
reset() {
|
|
4236
|
+
this.edits = {}, this.value = {}, this.errors = [], this.requestUpdate();
|
|
4237
|
+
}
|
|
4238
|
+
// ---- internal ----
|
|
4239
|
+
onFieldInput(t, e) {
|
|
4240
|
+
var s;
|
|
4241
|
+
e.stopPropagation();
|
|
4242
|
+
let { value: i } = e.detail;
|
|
4243
|
+
const a = t.formatter ? (s = this.registry.formatters) == null ? void 0 : s[t.formatter] : void 0;
|
|
4244
|
+
t.formatter && !a && console.warn(`[bahtui] unknown formatter "${t.formatter}" — skipped`), a && (i = a(i)), this.edits = { ...this.edits, [t.key]: i }, this.clearDependents(t.key), this.syncDynamicOptions(), (this.options.validateOn ?? "change") === "change" && this.errors.length > 0 && this.validate(), this.dispatchEvent(
|
|
4245
|
+
new CustomEvent("baht-change", {
|
|
4246
|
+
detail: { form_name: this.form.form_name, key: t.key, value: i, data: this.getData() },
|
|
4247
|
+
bubbles: !0,
|
|
4248
|
+
composed: !0
|
|
4249
|
+
})
|
|
4250
|
+
);
|
|
4251
|
+
}
|
|
4252
|
+
/** Validate a single field against current form data (siblings included). */
|
|
4253
|
+
validateOneField(t) {
|
|
4254
|
+
const e = this.stateFor(t);
|
|
4255
|
+
if (!e.visible) return [];
|
|
4256
|
+
const i = this.getData(), a = e.required === !!t.required ? t : { ...t, required: e.required };
|
|
4257
|
+
return Le(a, this.valueFor(t), this.registry, i);
|
|
4258
|
+
}
|
|
4259
|
+
/** `validateOn: 'blur'` — validate just the field the user left, same as
|
|
4260
|
+
* how errors are shown elsewhere (merged into `this.errors`, painted by
|
|
4261
|
+
* `renderField`/`.baht-error`). No-op for 'change'/'submit' modes. */
|
|
4262
|
+
onFieldBlur(t) {
|
|
4263
|
+
if ((this.options.validateOn ?? "change") !== "blur") return;
|
|
4264
|
+
const e = this.validateOneField(t), i = this.errors.filter((a) => a.key !== t.key);
|
|
4265
|
+
this.errors = [...i, ...e];
|
|
4266
|
+
}
|
|
4267
|
+
renderField(t) {
|
|
4268
|
+
var C, d;
|
|
4269
|
+
const e = cs[t.type];
|
|
4270
|
+
if (!e)
|
|
4271
|
+
return console.warn(`[bahtui] unknown field type "${t.type}" — skipped`), h;
|
|
4272
|
+
const i = this.stateFor(t), a = xi[t.width ?? "full"] ?? "baht-field--w-full", s = ((C = this.errors.find((v) => v.key === t.key)) == null ? void 0 : C.message) ?? null;
|
|
4273
|
+
if (this.readonly && t.type !== "label" && t.type !== "section")
|
|
4274
|
+
return this.renderReadonlyField(t, a, i.visible);
|
|
4275
|
+
const r = t.options_from ? { ...t, options: this.dynamicOptions.get(t.key) ?? t.options ?? [] } : t, o = this.valueFor(t), c = !i.enabled, f = this.readonly || i.readonly, g = this.options.inputDebounce, _ = (v) => this.onControlInput(t.key, v), p = _i(e);
|
|
4276
|
+
let w;
|
|
4277
|
+
if (t.type === "repeater") {
|
|
4278
|
+
const v = this.errors.filter((z) => z.key.startsWith(`${t.key}[`));
|
|
4279
|
+
w = ee`<${p}
|
|
4280
|
+
.field=${r}
|
|
4281
|
+
.value=${o}
|
|
4282
|
+
.disabled=${c}
|
|
4283
|
+
.readonly=${f}
|
|
4284
|
+
.required=${i.required}
|
|
4285
|
+
.error=${s}
|
|
4286
|
+
.debounce=${g}
|
|
4287
|
+
.rowErrors=${v}
|
|
4288
|
+
@baht-input=${_}
|
|
4289
|
+
></${p}>`;
|
|
4290
|
+
} else if (t.type === "file") {
|
|
4291
|
+
let v;
|
|
4292
|
+
t.uploader && (v = (d = this.registry.uploaders) == null ? void 0 : d[t.uploader], v || console.warn(`[bahtui] unknown uploader "${t.uploader}" — capture only`)), w = ee`<${p}
|
|
4293
|
+
.field=${r}
|
|
4294
|
+
.value=${o}
|
|
4295
|
+
.disabled=${c}
|
|
4296
|
+
.readonly=${f}
|
|
4297
|
+
.required=${i.required}
|
|
4298
|
+
.error=${s}
|
|
4299
|
+
.debounce=${g}
|
|
4300
|
+
.uploader=${v}
|
|
4301
|
+
@baht-input=${_}
|
|
4302
|
+
></${p}>`;
|
|
4303
|
+
} else
|
|
4304
|
+
w = ee`<${p}
|
|
4305
|
+
.field=${r}
|
|
4306
|
+
.value=${o}
|
|
4307
|
+
.disabled=${c}
|
|
4308
|
+
.readonly=${f}
|
|
4309
|
+
.required=${i.required}
|
|
4310
|
+
.error=${s}
|
|
4311
|
+
.debounce=${g}
|
|
4312
|
+
@baht-input=${_}
|
|
4313
|
+
></${p}>`;
|
|
4314
|
+
return n`<div
|
|
4315
|
+
class="baht-field ${a} ${i.visible ? "" : "baht-field--hidden"}"
|
|
4316
|
+
data-key=${t.key}
|
|
4317
|
+
data-type=${t.type}
|
|
4318
|
+
data-testid="${this.form.form_id}.${t.key}"
|
|
4319
|
+
@focusout=${() => this.onFieldBlur(t)}
|
|
4320
|
+
>
|
|
4321
|
+
${w}
|
|
4322
|
+
</div>`;
|
|
4323
|
+
}
|
|
4324
|
+
/**
|
|
4325
|
+
* Resolve the descriptor at event time — it may have changed since the control
|
|
4326
|
+
* was first rendered (the same node is reused across renders, see render()).
|
|
4327
|
+
*/
|
|
4328
|
+
onControlInput(t, e) {
|
|
4329
|
+
var a;
|
|
4330
|
+
const i = (a = this.effectiveForm) == null ? void 0 : a.fields.find((s) => s.key === t);
|
|
4331
|
+
i && this.onFieldInput(i, e);
|
|
4332
|
+
}
|
|
4333
|
+
renderReadonlyField(t, e, i) {
|
|
4334
|
+
const a = t.options_from ? this.dynamicOptions.get(t.key) ?? t.options ?? [] : t.options, s = bs(t, this.valueFor(t), a), r = s.kind === "empty" ? n`<span class="baht-readonly-value baht-readonly-value--empty">${m("emptyValue")}</span>` : s.kind === "text" ? n`<span class="baht-readonly-value">${s.text}</span>` : s.kind === "chips" ? n`<span class="baht-readonly-value baht-readonly-chips"
|
|
4335
|
+
>${s.items.map((o) => n`<span class="baht-readonly-chip">${o}</span>`)}</span
|
|
4336
|
+
>` : n`<div class="baht-readonly-rows">
|
|
4337
|
+
${s.rows.map(
|
|
4338
|
+
(o) => n`<div class="baht-readonly-row">
|
|
4339
|
+
${o.map(
|
|
4340
|
+
(c) => n`<span class="baht-readonly-cell"
|
|
4341
|
+
><span class="baht-readonly-cell-label">${c.label}</span
|
|
4342
|
+
><span class="baht-readonly-cell-value">${c.text}</span></span
|
|
4343
|
+
>`
|
|
4344
|
+
)}
|
|
4345
|
+
</div>`
|
|
4346
|
+
)}
|
|
4347
|
+
</div>`;
|
|
4348
|
+
return n`<div
|
|
4349
|
+
class="baht-field ${e} baht-field--readonly ${i ? "" : "baht-field--hidden"}"
|
|
4350
|
+
data-key=${t.key}
|
|
4351
|
+
data-type=${t.type}
|
|
4352
|
+
data-testid="${this.form.form_id}.${t.key}"
|
|
4353
|
+
>
|
|
4354
|
+
${t.label ? n`<span class="baht-label">${t.label}</span>` : h}
|
|
4355
|
+
${r}
|
|
4356
|
+
</div>`;
|
|
4357
|
+
}
|
|
4358
|
+
render() {
|
|
4359
|
+
return n`<div class="baht-form ${this.readonly ? "baht-form--readonly" : ""}">
|
|
4360
|
+
${Ce(
|
|
4361
|
+
this.sortedFields,
|
|
4362
|
+
(t) => t.key,
|
|
4363
|
+
(t) => this.renderField(t)
|
|
4364
|
+
)}
|
|
4365
|
+
</div>`;
|
|
4366
|
+
}
|
|
4367
|
+
};
|
|
4368
|
+
X([
|
|
4369
|
+
l({ attribute: !1 })
|
|
4370
|
+
], U.prototype, "form", 2);
|
|
4371
|
+
X([
|
|
4372
|
+
l({ attribute: !1 })
|
|
4373
|
+
], U.prototype, "value", 2);
|
|
4374
|
+
X([
|
|
4375
|
+
l({ attribute: !1 })
|
|
4376
|
+
], U.prototype, "registry", 2);
|
|
4377
|
+
X([
|
|
4378
|
+
l({ attribute: !1 })
|
|
4379
|
+
], U.prototype, "options", 2);
|
|
4380
|
+
X([
|
|
4381
|
+
l({ attribute: !1 })
|
|
4382
|
+
], U.prototype, "fieldStates", 2);
|
|
4383
|
+
X([
|
|
4384
|
+
l({ type: String })
|
|
4385
|
+
], U.prototype, "view", 2);
|
|
4386
|
+
X([
|
|
4387
|
+
l({ attribute: !1 })
|
|
4388
|
+
], U.prototype, "flags", 2);
|
|
4389
|
+
X([
|
|
4390
|
+
l({ type: Boolean })
|
|
4391
|
+
], U.prototype, "readonly", 2);
|
|
4392
|
+
X([
|
|
4393
|
+
$()
|
|
4394
|
+
], U.prototype, "edits", 2);
|
|
4395
|
+
X([
|
|
4396
|
+
$()
|
|
4397
|
+
], U.prototype, "errors", 2);
|
|
4398
|
+
U = X([
|
|
4399
|
+
b("baht-form")
|
|
4400
|
+
], U);
|
|
4401
|
+
var ki = Object.defineProperty, Pi = Object.getOwnPropertyDescriptor, N = (t, e, i, a) => {
|
|
4402
|
+
for (var s = a > 1 ? void 0 : a ? Pi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
|
|
4403
|
+
(o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
|
|
4404
|
+
return a && s && ki(e, i, s), s;
|
|
4405
|
+
};
|
|
4406
|
+
let M = class extends y {
|
|
4407
|
+
constructor() {
|
|
4408
|
+
super(...arguments), this.value = {}, this.registry = {}, this.validateGate = !0, this.showBack = !0, this.flags = {}, this.showSteps = !1, this.stepsVariant = "default", this.data = {}, this.derived = null, this.current = null, this.approvalError = null, this.history = [], this.flagCache = {};
|
|
4409
|
+
}
|
|
4410
|
+
get currentFormName() {
|
|
4411
|
+
return this.current;
|
|
4412
|
+
}
|
|
4413
|
+
get effectiveWorkflow() {
|
|
4414
|
+
return this.workflow ? ((this.flagCache.workflow !== this.workflow || this.flagCache.flags !== this.flags) && (this.flagCache = {
|
|
4415
|
+
workflow: this.workflow,
|
|
4416
|
+
flags: this.flags,
|
|
4417
|
+
out: rs(this.workflow, this.flags)
|
|
4418
|
+
}), this.flagCache.out) : this.workflow;
|
|
4419
|
+
}
|
|
4420
|
+
willUpdate(t) {
|
|
4421
|
+
var e, i;
|
|
4422
|
+
t.has("workflow") || t.has("value") ? (this.data = structuredClone(this.value ?? {}), this.reevaluate(), this.history = [], this.current = ((e = this.visibleForms[0]) == null ? void 0 : e.form_name) ?? null, this.approvalError = null) : t.has("flags") && (this.reevaluate(), this.current && !this.visibleForms.some((a) => a.form_name === this.current) && (this.current = ((i = this.visibleForms[0]) == null ? void 0 : i.form_name) ?? null));
|
|
4423
|
+
}
|
|
4424
|
+
reevaluate() {
|
|
4425
|
+
this.derived = fs(this.effectiveWorkflow, this.data), this.data = this.derived.data;
|
|
4426
|
+
}
|
|
4427
|
+
/** Forms in ascending order whose derived visibility is true. */
|
|
4428
|
+
get visibleForms() {
|
|
4429
|
+
var e;
|
|
4430
|
+
const t = [...((e = this.effectiveWorkflow) == null ? void 0 : e.forms) ?? []].sort((i, a) => i.order - a.order);
|
|
4431
|
+
return this.derived ? t.filter((i) => {
|
|
4432
|
+
var a;
|
|
4433
|
+
return ((a = this.derived.forms[i.form_name]) == null ? void 0 : a.visible) !== !1;
|
|
4434
|
+
}) : t;
|
|
4435
|
+
}
|
|
4436
|
+
get currentForm() {
|
|
4437
|
+
return this.visibleForms.find((t) => t.form_name === this.current) ?? null;
|
|
4438
|
+
}
|
|
4439
|
+
/** Where next() would go from here: a form_name or 'end' (spec 03 §6). */
|
|
4440
|
+
get navTarget() {
|
|
4441
|
+
var a;
|
|
4442
|
+
if (!this.current) return "end";
|
|
4443
|
+
const t = this.effectiveWorkflow;
|
|
4444
|
+
if (t.transitions && t.transitions.length > 0)
|
|
4445
|
+
return ms(t, this.current, this.data);
|
|
4446
|
+
const e = this.visibleForms, i = e.findIndex((s) => s.form_name === this.current);
|
|
4447
|
+
return ((a = e[i + 1]) == null ? void 0 : a.form_name) ?? "end";
|
|
4448
|
+
}
|
|
4449
|
+
get isLast() {
|
|
4450
|
+
return this.current !== null && this.navTarget === "end";
|
|
4451
|
+
}
|
|
4452
|
+
fieldStatesFor(t) {
|
|
4453
|
+
const e = {};
|
|
4454
|
+
if (!this.derived) return e;
|
|
4455
|
+
const i = `${t}.`;
|
|
4456
|
+
for (const [a, s] of Object.entries(this.derived.fields))
|
|
4457
|
+
a.startsWith(i) && (e[a.slice(i.length)] = s);
|
|
4458
|
+
return e;
|
|
4459
|
+
}
|
|
4460
|
+
get formEl() {
|
|
4461
|
+
return this.querySelector("baht-form");
|
|
4462
|
+
}
|
|
4463
|
+
// ---- public API (spec 03 §2) ----
|
|
4464
|
+
getData() {
|
|
4465
|
+
var t;
|
|
4466
|
+
return ((t = this.derived) == null ? void 0 : t.data) ?? this.data;
|
|
4467
|
+
}
|
|
4468
|
+
/**
|
|
4469
|
+
* Host/store write into one form's data — same path a user edit takes
|
|
4470
|
+
* (rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset
|
|
4471
|
+
* that re-feeding the `value` prop causes.
|
|
4472
|
+
*/
|
|
4473
|
+
setValue(t, e) {
|
|
4474
|
+
var i;
|
|
4475
|
+
this.data = { ...this.data, [t]: { ...this.data[t], ...e } }, this.reevaluate(), this.current && !this.visibleForms.some((a) => a.form_name === this.current) && (this.current = ((i = this.visibleForms[0]) == null ? void 0 : i.form_name) ?? null), this.emit("baht-data-change", { data: this.getData() });
|
|
4476
|
+
}
|
|
4477
|
+
next() {
|
|
4478
|
+
const t = this.currentForm;
|
|
4479
|
+
if (!t) return;
|
|
4480
|
+
if (t.kind === "approval") {
|
|
4481
|
+
this.decide("approved");
|
|
4482
|
+
return;
|
|
4483
|
+
}
|
|
4484
|
+
let e = { valid: !0, errors: [] };
|
|
4485
|
+
this.formEl && (e = this.formEl.validate()), !(this.validateGate && !e.valid) && (this.reevaluate(), this.advance(e));
|
|
4486
|
+
}
|
|
4487
|
+
/** Advance past the current form: submit+complete at 'end', else step to navTarget. */
|
|
4488
|
+
advance(t = {}) {
|
|
4489
|
+
const e = { ...t, data: this.getData() }, i = this.navTarget;
|
|
4490
|
+
if (i === "end") {
|
|
4491
|
+
this.emit("baht-submit", e), this.emit("baht-complete", { data: this.getData(), status: "completed" });
|
|
4492
|
+
return;
|
|
4493
|
+
}
|
|
4494
|
+
const a = this.visibleForms.find((s) => s.form_name === i);
|
|
4495
|
+
if (!a || a.form_name === this.current) {
|
|
4496
|
+
const s = a ? "self-transition" : "target-hidden";
|
|
4497
|
+
console.warn(
|
|
4498
|
+
`[bahtui] cannot advance from "${this.current}": target "${i}" is ` + (a ? "the current form (self-transition)" : "not visible")
|
|
4499
|
+
), this.emit("baht-nav-blocked", {
|
|
4500
|
+
form_name: this.current,
|
|
4501
|
+
target: i,
|
|
4502
|
+
reason: s,
|
|
4503
|
+
data: this.getData()
|
|
4504
|
+
});
|
|
4505
|
+
return;
|
|
4506
|
+
}
|
|
4507
|
+
this.history.push(this.current), this.current = a.form_name, this.emit("baht-next", { form_name: a.form_name, order: a.order, ...e }), this.emit("baht-step-change", {
|
|
4508
|
+
form_name: a.form_name,
|
|
4509
|
+
order: a.order,
|
|
4510
|
+
direction: "forward"
|
|
4511
|
+
});
|
|
4512
|
+
}
|
|
4513
|
+
/** Approve the current approval step (same as pressing its Approve button). */
|
|
4514
|
+
approve() {
|
|
4515
|
+
this.decide("approved");
|
|
4516
|
+
}
|
|
4517
|
+
/** Reject the current approval step (same as pressing its Reject button). */
|
|
4518
|
+
reject() {
|
|
4519
|
+
this.decide("rejected");
|
|
4520
|
+
}
|
|
4521
|
+
decide(t) {
|
|
4522
|
+
var f;
|
|
4523
|
+
const e = this.currentForm;
|
|
4524
|
+
if (!e || e.kind !== "approval") return;
|
|
4525
|
+
const i = e.approval ?? {}, a = String(((f = this.data[e.form_name]) == null ? void 0 : f.comment) ?? ""), s = i.comment ?? "optional";
|
|
4526
|
+
if ((s === "required" || s === "requireOnReject" && t === "rejected") && a.trim() === "") {
|
|
4527
|
+
this.approvalError = m("commentRequired");
|
|
4528
|
+
return;
|
|
4529
|
+
}
|
|
4530
|
+
this.approvalError = null, this.data = {
|
|
4531
|
+
...this.data,
|
|
4532
|
+
[e.form_name]: { ...this.data[e.form_name], decision: t, comment: a }
|
|
4533
|
+
}, this.reevaluate();
|
|
4534
|
+
const o = { form_name: e.form_name, decision: t, comment: a, data: this.getData() };
|
|
4535
|
+
if (t === "approved") {
|
|
4536
|
+
this.emit("baht-approve", o), this.advance({ decision: t, comment: a });
|
|
4537
|
+
return;
|
|
4538
|
+
}
|
|
4539
|
+
this.emit("baht-reject", o);
|
|
4540
|
+
const c = i.on_reject ?? { action: "end" };
|
|
4541
|
+
c.action === "goto" && this.visibleForms.some((g) => g.form_name === c.form) ? this.gotoForm(c.form) : this.emit("baht-complete", { data: this.getData(), status: "rejected" });
|
|
4542
|
+
}
|
|
4543
|
+
/** Jump back to a visible form, truncating the history to that point. */
|
|
4544
|
+
gotoForm(t) {
|
|
4545
|
+
const e = this.history.indexOf(t);
|
|
4546
|
+
this.history = e >= 0 ? this.history.slice(0, e) : [], this.current = t;
|
|
4547
|
+
const i = this.effectiveWorkflow.forms.find((a) => a.form_name === t);
|
|
4548
|
+
this.emit("baht-step-change", { form_name: t, order: (i == null ? void 0 : i.order) ?? 0, direction: "back" });
|
|
4549
|
+
}
|
|
4550
|
+
back() {
|
|
4551
|
+
let t = this.history.pop();
|
|
4552
|
+
for (; t !== void 0 && !this.visibleForms.some((i) => i.form_name === t); )
|
|
4553
|
+
t = this.history.pop();
|
|
4554
|
+
if (!t) return;
|
|
4555
|
+
this.current = t, this.approvalError = null;
|
|
4556
|
+
const e = this.effectiveWorkflow.forms.find((i) => i.form_name === t);
|
|
4557
|
+
this.emit("baht-step-change", { form_name: t, order: (e == null ? void 0 : e.order) ?? 0, direction: "back" });
|
|
4558
|
+
}
|
|
4559
|
+
gotoStart() {
|
|
4560
|
+
var t;
|
|
4561
|
+
this.history = [], this.current = ((t = this.visibleForms[0]) == null ? void 0 : t.form_name) ?? null, this.approvalError = null;
|
|
4562
|
+
}
|
|
4563
|
+
// ---- internal ----
|
|
4564
|
+
onFormChange(t) {
|
|
4565
|
+
var s;
|
|
4566
|
+
t.stopPropagation();
|
|
4567
|
+
const { form_name: e, key: i, value: a } = t.detail;
|
|
4568
|
+
this.data = { ...this.data, [e]: { ...this.data[e], [i]: a } }, this.reevaluate(), this.current && !this.visibleForms.some((r) => r.form_name === this.current) && (this.current = ((s = this.visibleForms[0]) == null ? void 0 : s.form_name) ?? null), this.emit("baht-data-change", { data: this.getData() });
|
|
4569
|
+
}
|
|
4570
|
+
onCommentInput(t, e) {
|
|
4571
|
+
this.data = { ...this.data, [t]: { ...this.data[t], comment: e } }, this.reevaluate(), e.trim() !== "" && (this.approvalError = null), this.emit("baht-data-change", { data: this.getData() });
|
|
4572
|
+
}
|
|
4573
|
+
emit(t, e) {
|
|
4574
|
+
this.dispatchEvent(new CustomEvent(t, { detail: e, bubbles: !0, composed: !0 }));
|
|
4575
|
+
}
|
|
4576
|
+
// ---- approval summary (spec 03 §4) ----
|
|
4577
|
+
/** Forms the approval step summarizes: configured list, else every earlier plain form. */
|
|
4578
|
+
summary_forms(t) {
|
|
4579
|
+
var a;
|
|
4580
|
+
const e = (a = t.approval) == null ? void 0 : a.summary_forms, i = this.visibleForms.filter(
|
|
4581
|
+
(s) => s.form_name !== t.form_name && s.kind !== "approval"
|
|
4582
|
+
);
|
|
4583
|
+
return e ? i.filter((s) => e.includes(s.form_name)) : i.filter((s) => s.order < t.order);
|
|
4584
|
+
}
|
|
4585
|
+
renderApproval(t) {
|
|
4586
|
+
var a, s;
|
|
4587
|
+
const e = ((a = t.approval) == null ? void 0 : a.comment) ?? "optional", i = this.summary_forms(t);
|
|
4588
|
+
return n`<div class="baht-approval">
|
|
4589
|
+
<div class="baht-approval-summary">
|
|
4590
|
+
${i.length === 0 ? n`<p class="baht-approval-empty">${m("nothingToReview")}</p>` : i.map(
|
|
4591
|
+
(r) => n`<section class="baht-approval-group">
|
|
4592
|
+
<h4 class="baht-approval-group-title">${r.form_name}</h4>
|
|
4593
|
+
<baht-form
|
|
4594
|
+
readonly
|
|
4595
|
+
.form=${r}
|
|
4596
|
+
.value=${this.data[r.form_name] ?? {}}
|
|
4597
|
+
.fieldStates=${this.fieldStatesFor(r.form_name)}
|
|
4598
|
+
></baht-form>
|
|
4599
|
+
</section>`
|
|
4600
|
+
)}
|
|
4601
|
+
</div>
|
|
4602
|
+
${e !== "hidden" ? n`<label class="baht-approval-comment">
|
|
4603
|
+
<span class="baht-approval-comment-label">
|
|
4604
|
+
${m("comment")}${e === "required" ? m("commentRequiredSuffix") : ""}
|
|
4605
|
+
</span>
|
|
4606
|
+
<textarea
|
|
4607
|
+
rows="3"
|
|
4608
|
+
aria-required=${e === "required" ? "true" : h}
|
|
4609
|
+
aria-invalid=${this.approvalError ? "true" : h}
|
|
4610
|
+
.value=${String(((s = this.data[t.form_name]) == null ? void 0 : s.comment) ?? "")}
|
|
4611
|
+
@input=${(r) => this.onCommentInput(t.form_name, r.target.value)}
|
|
4612
|
+
></textarea>
|
|
4613
|
+
</label>` : h}
|
|
4614
|
+
${this.approvalError ? n`<p class="baht-error" role="alert">${this.approvalError}</p>` : h}
|
|
4615
|
+
</div>`;
|
|
4616
|
+
}
|
|
4617
|
+
render() {
|
|
4618
|
+
var s, r;
|
|
4619
|
+
const t = this.currentForm;
|
|
4620
|
+
if (!t) return n`<div class="baht-workflow"></div>`;
|
|
4621
|
+
const e = t.kind === "approval", i = this.visibleForms, a = i.findIndex((o) => o.form_name === t.form_name);
|
|
4622
|
+
return n`<div
|
|
4623
|
+
class="baht-workflow"
|
|
4624
|
+
data-step=${t.form_name}
|
|
4625
|
+
data-testid="${this.workflow.workflow_id}.${t.form_name}"
|
|
4626
|
+
>
|
|
4627
|
+
<div class="baht-visually-hidden" role="status">
|
|
4628
|
+
${m("step", { current: a + 1, total: i.length })}
|
|
4629
|
+
</div>
|
|
4630
|
+
${this.showSteps ? n`<baht-steps
|
|
4631
|
+
.steps=${i.map((o) => o.form_name)}
|
|
4632
|
+
.current=${a}
|
|
4633
|
+
.variant=${this.stepsVariant}
|
|
4634
|
+
></baht-steps>` : h}
|
|
4635
|
+
${e ? this.renderApproval(t) : n`<baht-form
|
|
4636
|
+
.form=${t}
|
|
4637
|
+
.value=${this.data[t.form_name] ?? {}}
|
|
4638
|
+
.registry=${this.registry}
|
|
4639
|
+
.fieldStates=${this.fieldStatesFor(t.form_name)}
|
|
4640
|
+
.view=${t.view}
|
|
4641
|
+
@baht-change=${(o) => this.onFormChange(o)}
|
|
4642
|
+
></baht-form>`}
|
|
4643
|
+
<div class="baht-workflow-nav">
|
|
4644
|
+
${this.showBack && this.history.length > 0 ? n`<button type="button" class="baht-button baht-button--back"
|
|
4645
|
+
data-testid="${this.workflow.workflow_id}.back"
|
|
4646
|
+
@click=${() => this.back()}
|
|
4647
|
+
>
|
|
4648
|
+
${this.backLabel ?? m("back")}
|
|
4649
|
+
</button>` : h}
|
|
4650
|
+
${e ? n`<button
|
|
4651
|
+
type="button"
|
|
4652
|
+
class="baht-button baht-button--reject"
|
|
4653
|
+
data-testid="${this.workflow.workflow_id}.reject"
|
|
4654
|
+
@click=${() => this.decide("rejected")}
|
|
4655
|
+
>
|
|
4656
|
+
${((s = t.approval) == null ? void 0 : s.reject_label) ?? m("reject")}
|
|
4657
|
+
</button>
|
|
4658
|
+
<button
|
|
4659
|
+
type="button"
|
|
4660
|
+
class="baht-button baht-button--next baht-button--approve"
|
|
4661
|
+
data-testid="${this.workflow.workflow_id}.approve"
|
|
4662
|
+
@click=${() => this.decide("approved")}
|
|
4663
|
+
>
|
|
4664
|
+
${((r = t.approval) == null ? void 0 : r.approve_label) ?? m("approve")}
|
|
4665
|
+
</button>` : n`<button type="button" class="baht-button baht-button--next"
|
|
4666
|
+
data-testid="${this.workflow.workflow_id}.next"
|
|
4667
|
+
@click=${() => this.next()}
|
|
4668
|
+
>
|
|
4669
|
+
${this.isLast ? this.submitLabel ?? m("submit") : this.nextLabel ?? m("next")}
|
|
4670
|
+
</button>`}
|
|
4671
|
+
</div>
|
|
4672
|
+
</div>`;
|
|
4673
|
+
}
|
|
4674
|
+
};
|
|
4675
|
+
N([
|
|
4676
|
+
l({ attribute: !1 })
|
|
4677
|
+
], M.prototype, "workflow", 2);
|
|
4678
|
+
N([
|
|
4679
|
+
l({ attribute: !1 })
|
|
4680
|
+
], M.prototype, "value", 2);
|
|
4681
|
+
N([
|
|
4682
|
+
l({ attribute: !1 })
|
|
4683
|
+
], M.prototype, "registry", 2);
|
|
4684
|
+
N([
|
|
4685
|
+
l({ type: Boolean, attribute: "validate-gate" })
|
|
4686
|
+
], M.prototype, "validateGate", 2);
|
|
4687
|
+
N([
|
|
4688
|
+
l({ attribute: "next-label" })
|
|
4689
|
+
], M.prototype, "nextLabel", 2);
|
|
4690
|
+
N([
|
|
4691
|
+
l({ attribute: "submit-label" })
|
|
4692
|
+
], M.prototype, "submitLabel", 2);
|
|
4693
|
+
N([
|
|
4694
|
+
l({ attribute: "back-label" })
|
|
4695
|
+
], M.prototype, "backLabel", 2);
|
|
4696
|
+
N([
|
|
4697
|
+
l({ type: Boolean, attribute: "show-back" })
|
|
4698
|
+
], M.prototype, "showBack", 2);
|
|
4699
|
+
N([
|
|
4700
|
+
l({ attribute: !1 })
|
|
4701
|
+
], M.prototype, "flags", 2);
|
|
4702
|
+
N([
|
|
4703
|
+
l({ type: Boolean, attribute: "show-steps" })
|
|
4704
|
+
], M.prototype, "showSteps", 2);
|
|
4705
|
+
N([
|
|
4706
|
+
l({ attribute: "steps-variant" })
|
|
4707
|
+
], M.prototype, "stepsVariant", 2);
|
|
4708
|
+
N([
|
|
4709
|
+
$()
|
|
4710
|
+
], M.prototype, "data", 2);
|
|
4711
|
+
N([
|
|
4712
|
+
$()
|
|
4713
|
+
], M.prototype, "derived", 2);
|
|
4714
|
+
N([
|
|
4715
|
+
$()
|
|
4716
|
+
], M.prototype, "current", 2);
|
|
4717
|
+
N([
|
|
4718
|
+
$()
|
|
4719
|
+
], M.prototype, "approvalError", 2);
|
|
4720
|
+
M = N([
|
|
4721
|
+
b("baht-workflow")
|
|
4722
|
+
], M);
|
|
4723
|
+
export {
|
|
4724
|
+
Xe as $,
|
|
4725
|
+
ht as A,
|
|
4726
|
+
Ct as B,
|
|
4727
|
+
Pt as C,
|
|
4728
|
+
Ke as D,
|
|
4729
|
+
rt as E,
|
|
4730
|
+
mt as F,
|
|
4731
|
+
j as G,
|
|
4732
|
+
Ie as H,
|
|
4733
|
+
Ee as I,
|
|
4734
|
+
oe as J,
|
|
4735
|
+
Vt as K,
|
|
4736
|
+
ct as L,
|
|
4737
|
+
ie as M,
|
|
4738
|
+
K as N,
|
|
4739
|
+
Ut as O,
|
|
4740
|
+
Gt as P,
|
|
4741
|
+
k as Q,
|
|
4742
|
+
Fe as R,
|
|
4743
|
+
qe as S,
|
|
4744
|
+
De as T,
|
|
4745
|
+
Ue as U,
|
|
4746
|
+
kt as V,
|
|
4747
|
+
F as W,
|
|
4748
|
+
D as X,
|
|
4749
|
+
M as Y,
|
|
4750
|
+
cs as Z,
|
|
4751
|
+
nt as _,
|
|
4752
|
+
ft as a,
|
|
4753
|
+
qa as a0,
|
|
4754
|
+
qt as a1,
|
|
4755
|
+
le as a2,
|
|
4756
|
+
Be as a3,
|
|
4757
|
+
be as a4,
|
|
4758
|
+
zt as b,
|
|
4759
|
+
R as c,
|
|
4760
|
+
re as d,
|
|
4761
|
+
Ot as e,
|
|
4762
|
+
tt as f,
|
|
4763
|
+
Ve as g,
|
|
4764
|
+
ae as h,
|
|
4765
|
+
He as i,
|
|
4766
|
+
G as j,
|
|
4767
|
+
Ht as k,
|
|
4768
|
+
Et as l,
|
|
4769
|
+
Kt as m,
|
|
4770
|
+
Ft as n,
|
|
4771
|
+
$t as o,
|
|
4772
|
+
U as p,
|
|
4773
|
+
pt as q,
|
|
4774
|
+
Ne as r,
|
|
4775
|
+
dt as s,
|
|
4776
|
+
Q as t,
|
|
4777
|
+
Dt as u,
|
|
4778
|
+
it as v,
|
|
4779
|
+
W as w,
|
|
4780
|
+
ze as x,
|
|
4781
|
+
Re as y,
|
|
4782
|
+
vt as z
|
|
4783
|
+
};
|