@20baht/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +501 -2
- package/dist/components/baht-form.d.ts +191 -0
- package/dist/components/baht-form.js +614 -0
- package/dist/components/baht-workflow.d.ts +173 -0
- package/dist/components/baht-workflow.js +430 -0
- package/dist/components/base.d.ts +92 -0
- package/dist/components/base.js +138 -0
- package/dist/components/combobox-controller.d.ts +65 -0
- package/dist/components/combobox-controller.js +82 -0
- package/dist/components/define.d.ts +7 -0
- package/dist/components/define.js +16 -0
- package/dist/components/field-base.d.ts +84 -0
- package/dist/components/field-base.js +152 -0
- package/dist/components/floating.d.ts +84 -0
- package/dist/components/floating.js +182 -0
- package/dist/components/form-layout.d.ts +39 -0
- package/dist/components/form-layout.js +67 -0
- package/dist/components/form-options.d.ts +39 -0
- package/dist/components/form-options.js +65 -0
- package/dist/components/form-readonly.d.ts +20 -0
- package/dist/components/form-readonly.js +70 -0
- package/dist/components/layers.d.ts +4 -0
- package/dist/components/layers.js +15 -0
- package/dist/components/menu-controller.d.ts +65 -0
- package/dist/components/menu-controller.js +134 -0
- package/dist/components/motion.d.ts +9 -0
- package/dist/components/motion.js +16 -0
- package/dist/components/primitives/baht-accordion.d.ts +29 -0
- package/dist/components/primitives/baht-accordion.js +66 -0
- package/dist/components/primitives/baht-alert.d.ts +20 -0
- package/dist/components/primitives/baht-alert.js +62 -0
- package/dist/components/primitives/baht-app-shell.d.ts +81 -0
- package/dist/components/primitives/baht-app-shell.js +161 -0
- package/dist/components/primitives/baht-approval-chain.d.ts +59 -0
- package/dist/components/primitives/baht-approval-chain.js +80 -0
- package/dist/components/primitives/baht-avatar.d.ts +19 -0
- package/dist/components/primitives/baht-avatar.js +43 -0
- package/dist/components/primitives/baht-badge.d.ts +24 -0
- package/dist/components/primitives/baht-badge.js +41 -0
- package/dist/components/primitives/baht-bar-chart.d.ts +78 -0
- package/dist/components/primitives/baht-bar-chart.js +361 -0
- package/dist/components/primitives/baht-breadcrumbs.d.ts +23 -0
- package/dist/components/primitives/baht-breadcrumbs.js +45 -0
- package/dist/components/primitives/baht-button.d.ts +89 -0
- package/dist/components/primitives/baht-button.js +146 -0
- package/dist/components/primitives/baht-calendar.d.ts +96 -0
- package/dist/components/primitives/baht-calendar.js +398 -0
- package/dist/components/primitives/baht-card.d.ts +34 -0
- package/dist/components/primitives/baht-card.js +70 -0
- package/dist/components/primitives/baht-catalog-card.d.ts +52 -0
- package/dist/components/primitives/baht-catalog-card.js +90 -0
- package/dist/components/primitives/baht-checkbox.d.ts +7 -0
- package/dist/components/primitives/baht-checkbox.js +40 -0
- package/dist/components/primitives/baht-choice-group.d.ts +52 -0
- package/dist/components/primitives/baht-choice-group.js +71 -0
- package/dist/components/primitives/baht-code.d.ts +18 -0
- package/dist/components/primitives/baht-code.js +33 -0
- package/dist/components/primitives/baht-column-picker.d.ts +69 -0
- package/dist/components/primitives/baht-column-picker.js +234 -0
- package/dist/components/primitives/baht-comments.d.ts +38 -0
- package/dist/components/primitives/baht-comments.js +102 -0
- package/dist/components/primitives/baht-currency.d.ts +13 -0
- package/dist/components/primitives/baht-currency.js +69 -0
- package/dist/components/primitives/baht-datepicker.d.ts +77 -0
- package/dist/components/primitives/baht-datepicker.js +235 -0
- package/dist/components/primitives/baht-donut-chart.d.ts +24 -0
- package/dist/components/primitives/baht-donut-chart.js +88 -0
- package/dist/components/primitives/baht-edit-table.d.ts +45 -0
- package/dist/components/primitives/baht-edit-table.js +176 -0
- package/dist/components/primitives/baht-empty-state.d.ts +26 -0
- package/dist/components/primitives/baht-empty-state.js +51 -0
- package/dist/components/primitives/baht-error-state.d.ts +21 -0
- package/dist/components/primitives/baht-error-state.js +44 -0
- package/dist/components/primitives/baht-facts.d.ts +42 -0
- package/dist/components/primitives/baht-facts.js +49 -0
- package/dist/components/primitives/baht-fieldset.d.ts +19 -0
- package/dist/components/primitives/baht-fieldset.js +42 -0
- package/dist/components/primitives/baht-file.d.ts +27 -0
- package/dist/components/primitives/baht-file.js +158 -0
- package/dist/components/primitives/baht-filter-builder.d.ts +39 -0
- package/dist/components/primitives/baht-filter-builder.js +201 -0
- package/dist/components/primitives/baht-filter.d.ts +36 -0
- package/dist/components/primitives/baht-filter.js +64 -0
- package/dist/components/primitives/baht-heatmap.d.ts +49 -0
- package/dist/components/primitives/baht-heatmap.js +168 -0
- package/dist/components/primitives/baht-input.d.ts +10 -0
- package/dist/components/primitives/baht-input.js +44 -0
- package/dist/components/primitives/baht-keyvalue-editor.d.ts +28 -0
- package/dist/components/primitives/baht-keyvalue-editor.js +106 -0
- package/dist/components/primitives/baht-line-chart.d.ts +45 -0
- package/dist/components/primitives/baht-line-chart.js +183 -0
- package/dist/components/primitives/baht-link.d.ts +26 -0
- package/dist/components/primitives/baht-link.js +48 -0
- package/dist/components/primitives/baht-list.d.ts +29 -0
- package/dist/components/primitives/baht-list.js +79 -0
- package/dist/components/primitives/baht-loading-overlay.d.ts +15 -0
- package/dist/components/primitives/baht-loading-overlay.js +33 -0
- package/dist/components/primitives/baht-markdown-view.d.ts +17 -0
- package/dist/components/primitives/baht-markdown-view.js +39 -0
- package/dist/components/primitives/baht-markdown.d.ts +34 -0
- package/dist/components/primitives/baht-markdown.js +177 -0
- package/dist/components/primitives/baht-menu.d.ts +53 -0
- package/dist/components/primitives/baht-menu.js +100 -0
- package/dist/components/primitives/baht-meter.d.ts +67 -0
- package/dist/components/primitives/baht-meter.js +107 -0
- package/dist/components/primitives/baht-modal.d.ts +71 -0
- package/dist/components/primitives/baht-modal.js +164 -0
- package/dist/components/primitives/baht-multiselect.d.ts +8 -0
- package/dist/components/primitives/baht-multiselect.js +47 -0
- package/dist/components/primitives/baht-notification-bell.d.ts +54 -0
- package/dist/components/primitives/baht-notification-bell.js +143 -0
- package/dist/components/primitives/baht-number.d.ts +5 -0
- package/dist/components/primitives/baht-number.js +39 -0
- package/dist/components/primitives/baht-order-box.d.ts +24 -0
- package/dist/components/primitives/baht-order-box.js +50 -0
- package/dist/components/primitives/baht-otp.d.ts +49 -0
- package/dist/components/primitives/baht-otp.js +109 -0
- package/dist/components/primitives/baht-page-header.d.ts +43 -0
- package/dist/components/primitives/baht-page-header.js +78 -0
- package/dist/components/primitives/baht-pagination.d.ts +33 -0
- package/dist/components/primitives/baht-pagination.js +86 -0
- package/dist/components/primitives/baht-popover.d.ts +45 -0
- package/dist/components/primitives/baht-popover.js +112 -0
- package/dist/components/primitives/baht-progress-ring.d.ts +22 -0
- package/dist/components/primitives/baht-progress-ring.js +62 -0
- package/dist/components/primitives/baht-progress.d.ts +17 -0
- package/dist/components/primitives/baht-progress.js +48 -0
- package/dist/components/primitives/baht-radio.d.ts +7 -0
- package/dist/components/primitives/baht-radio.js +74 -0
- package/dist/components/primitives/baht-range.d.ts +38 -0
- package/dist/components/primitives/baht-range.js +88 -0
- package/dist/components/primitives/baht-rating.d.ts +40 -0
- package/dist/components/primitives/baht-rating.js +107 -0
- package/dist/components/primitives/baht-record-bar.d.ts +30 -0
- package/dist/components/primitives/baht-record-bar.js +60 -0
- package/dist/components/primitives/baht-reference-dialog.d.ts +87 -0
- package/dist/components/primitives/baht-reference-dialog.js +418 -0
- package/dist/components/primitives/baht-reference-picker.d.ts +110 -0
- package/dist/components/primitives/baht-reference-picker.js +321 -0
- package/dist/components/primitives/baht-repeater.d.ts +59 -0
- package/dist/components/primitives/baht-repeater.js +315 -0
- package/dist/components/primitives/baht-rule-builder.d.ts +24 -0
- package/dist/components/primitives/baht-rule-builder.js +177 -0
- package/dist/components/primitives/baht-saved-filters.d.ts +41 -0
- package/dist/components/primitives/baht-saved-filters.js +126 -0
- package/dist/components/primitives/baht-search.d.ts +34 -0
- package/dist/components/primitives/baht-search.js +71 -0
- package/dist/components/primitives/baht-section-header.d.ts +28 -0
- package/dist/components/primitives/baht-section-header.js +48 -0
- package/dist/components/primitives/baht-section.d.ts +23 -0
- package/dist/components/primitives/baht-section.js +49 -0
- package/dist/components/primitives/baht-select.d.ts +49 -0
- package/dist/components/primitives/baht-select.js +197 -0
- package/dist/components/primitives/baht-skeleton.d.ts +16 -0
- package/dist/components/primitives/baht-skeleton.js +37 -0
- package/dist/components/primitives/baht-sparkline.d.ts +23 -0
- package/dist/components/primitives/baht-sparkline.js +56 -0
- package/dist/components/primitives/baht-spinner.d.ts +13 -0
- package/dist/components/primitives/baht-spinner.js +30 -0
- package/dist/components/primitives/baht-split-button.d.ts +43 -0
- package/dist/components/primitives/baht-split-button.js +87 -0
- package/dist/components/primitives/baht-stat-chart.d.ts +14 -0
- package/dist/components/primitives/baht-stat-chart.js +38 -0
- package/dist/components/primitives/baht-stat.d.ts +56 -0
- package/dist/components/primitives/baht-stat.js +117 -0
- package/dist/components/primitives/baht-steps.d.ts +33 -0
- package/dist/components/primitives/baht-steps.js +60 -0
- package/dist/components/primitives/baht-swipe-row.d.ts +64 -0
- package/dist/components/primitives/baht-swipe-row.js +178 -0
- package/dist/components/primitives/baht-table.d.ts +315 -0
- package/dist/components/primitives/baht-table.js +640 -0
- package/dist/components/primitives/baht-tabs.d.ts +54 -0
- package/dist/components/primitives/baht-tabs.js +128 -0
- package/dist/components/primitives/baht-tags.d.ts +96 -0
- package/dist/components/primitives/baht-tags.js +323 -0
- package/dist/components/primitives/baht-text.d.ts +10 -0
- package/dist/components/primitives/baht-text.js +29 -0
- package/dist/components/primitives/baht-textarea.d.ts +5 -0
- package/dist/components/primitives/baht-textarea.js +40 -0
- package/dist/components/primitives/baht-theme-toggle.d.ts +44 -0
- package/dist/components/primitives/baht-theme-toggle.js +101 -0
- package/dist/components/primitives/baht-timeline.d.ts +21 -0
- package/dist/components/primitives/baht-timeline.js +42 -0
- package/dist/components/primitives/baht-toast.d.ts +29 -0
- package/dist/components/primitives/baht-toast.js +83 -0
- package/dist/components/primitives/baht-toggle.d.ts +6 -0
- package/dist/components/primitives/baht-toggle.js +42 -0
- package/dist/components/primitives/baht-tooltip.d.ts +34 -0
- package/dist/components/primitives/baht-tooltip.js +85 -0
- package/dist/components/primitives/baht-tree.d.ts +58 -0
- package/dist/components/primitives/baht-tree.js +159 -0
- package/dist/components/primitives/baht-typeahead.d.ts +92 -0
- package/dist/components/primitives/baht-typeahead.js +258 -0
- package/dist/components/primitives/baht-upload.d.ts +108 -0
- package/dist/components/primitives/baht-upload.js +325 -0
- package/dist/components/primitives/baht-wizard.d.ts +57 -0
- package/dist/components/primitives/baht-wizard.js +147 -0
- package/dist/components/primitives/charts.d.ts +134 -0
- package/dist/components/primitives/charts.js +184 -0
- package/dist/components/primitives/column-map.d.ts +56 -0
- package/dist/components/primitives/column-map.js +70 -0
- package/dist/components/primitives/control-icons.d.ts +2 -0
- package/dist/components/primitives/control-icons.js +40 -0
- package/dist/components/primitives/icons.d.ts +24 -0
- package/dist/components/primitives/icons.js +86 -0
- package/dist/components/primitives/illustrations.d.ts +21 -0
- package/dist/components/primitives/illustrations.js +78 -0
- package/dist/components/primitives/index.d.ts +89 -0
- package/dist/components/primitives/kbd.d.ts +6 -0
- package/dist/components/primitives/kbd.js +9 -0
- package/dist/components/primitives/listbox.d.ts +2 -0
- package/dist/components/primitives/listbox.js +7 -0
- package/dist/components/primitives/markdown-render.d.ts +9 -0
- package/dist/components/primitives/markdown-render.js +77 -0
- package/dist/components/primitives/rule-rows.d.ts +55 -0
- package/dist/components/primitives/rule-rows.js +75 -0
- package/dist/components/primitives/tag-map.d.ts +6 -0
- package/dist/components/primitives/tag-map.js +39 -0
- package/dist/components/reference-labels.d.ts +22 -0
- package/dist/components/reference-labels.js +29 -0
- package/dist/components/shortcuts.d.ts +7 -0
- package/dist/components/shortcuts.js +43 -0
- package/dist/css/components.css +7517 -0
- package/dist/css/datepicker.css +346 -0
- package/dist/css/tokens.css +679 -0
- package/dist/custom-elements.json +45110 -0
- package/dist/engine.d.ts +1 -0
- package/dist/engine.js +1 -0
- package/dist/hydrate.d.ts +9 -0
- package/dist/hydrate.js +46 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +210 -0
- package/dist/overlay.d.ts +50 -0
- package/dist/overlay.js +140 -0
- package/dist/react.d.ts +557 -0
- package/dist/react.js +1 -0
- package/dist/register.d.ts +106 -0
- package/dist/register.js +99 -0
- package/dist/ssr.d.ts +16 -0
- package/dist/ssr.js +125 -0
- package/dist/tokens.css +8197 -0
- package/dist/vscode.css-custom-data.json +6 -0
- package/dist/vscode.html-custom-data.json +2261 -0
- package/dist/web-types.json +6523 -0
- package/package.json +157 -4
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { nothing as p, html as n } from "lit";
|
|
2
|
+
import { property as o, state as g } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as c } from "lit/directives/if-defined.js";
|
|
4
|
+
import { BahtElement as $, obj as v } from "../base.js";
|
|
5
|
+
import { t as h, isSafeUrl as y } from "@20baht/engine";
|
|
6
|
+
import { renderIcon as b } from "./icons.js";
|
|
7
|
+
import { renderIllustration as z } from "./illustrations.js";
|
|
8
|
+
import { customElement as q } from "../define.js";
|
|
9
|
+
var j = Object.defineProperty, w = Object.getOwnPropertyDescriptor, l = (e, t, i, r) => {
|
|
10
|
+
for (var s = r > 1 ? void 0 : r ? w(t, i) : t, d = e.length - 1, u; d >= 0; d--)
|
|
11
|
+
(u = e[d]) && (s = (r ? u(t, i, s) : u(s)) || s);
|
|
12
|
+
return r && s && j(t, i, s), s;
|
|
13
|
+
};
|
|
14
|
+
function k(e, t) {
|
|
15
|
+
return t.split(".").reduce((i, r) => {
|
|
16
|
+
if (i !== null && typeof i == "object") return i[r];
|
|
17
|
+
}, e);
|
|
18
|
+
}
|
|
19
|
+
function x(e, t) {
|
|
20
|
+
const i = e.trim();
|
|
21
|
+
if (!i) return null;
|
|
22
|
+
try {
|
|
23
|
+
const r = JSON.parse(i);
|
|
24
|
+
if (typeof r == "string") return r;
|
|
25
|
+
const s = t ? k(r, t) : r;
|
|
26
|
+
return typeof s == "string" && s ? s : null;
|
|
27
|
+
} catch {
|
|
28
|
+
return /^(https?:\/\/|\/|data:|blob:)/.test(i) ? i : null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function B(e) {
|
|
32
|
+
const i = (e.split(/[?#]/)[0] ?? e).split("/").filter(Boolean).pop() ?? e;
|
|
33
|
+
try {
|
|
34
|
+
return decodeURIComponent(i);
|
|
35
|
+
} catch {
|
|
36
|
+
return i;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function m(e) {
|
|
40
|
+
return e >= 1024 * 1024 ? `${(e / 1024 / 1024).toFixed(1)} MB` : e >= 1024 ? `${Math.round(e / 1024)} KB` : `${e} B`;
|
|
41
|
+
}
|
|
42
|
+
let a = class extends $ {
|
|
43
|
+
constructor() {
|
|
44
|
+
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, this.requests = /* @__PURE__ */ new Map(), this.onDragOver = (e) => {
|
|
45
|
+
this.disabled || (e.preventDefault(), this.dragging = !0);
|
|
46
|
+
}, this.onDragLeave = () => {
|
|
47
|
+
this.dragging = !1;
|
|
48
|
+
}, this.onDrop = (e) => {
|
|
49
|
+
var t;
|
|
50
|
+
e.preventDefault(), this.dragging = !1, this.accept_(Array.from(((t = e.dataTransfer) == null ? void 0 : t.files) ?? []));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
get urls() {
|
|
54
|
+
return Array.isArray(this.value) ? this.value.filter((e) => typeof e == "string" && e) : typeof this.value == "string" && this.value ? [this.value] : [];
|
|
55
|
+
}
|
|
56
|
+
get inputId() {
|
|
57
|
+
return `baht-upload-${this.uid}`;
|
|
58
|
+
}
|
|
59
|
+
fileFor(e) {
|
|
60
|
+
return this.known.get(e) ?? { name: B(e), size: 0, url: e };
|
|
61
|
+
}
|
|
62
|
+
/** Empty the value (does not delete anything on the server). */
|
|
63
|
+
clear() {
|
|
64
|
+
this.emitValue([]);
|
|
65
|
+
}
|
|
66
|
+
emitValue(e) {
|
|
67
|
+
const t = this.multiple ? e : e[0] ?? null;
|
|
68
|
+
this.value = t, this.emit("baht-change", {
|
|
69
|
+
value: t,
|
|
70
|
+
files: e.map((i) => this.fileFor(i))
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
accept_(e) {
|
|
74
|
+
if (this.disabled || e.length === 0) return;
|
|
75
|
+
const t = this.maxSize, i = t ? e.filter((s) => s.size <= t) : e;
|
|
76
|
+
this.rejectedNames = t ? e.filter((s) => s.size > t).map((s) => s.name) : [];
|
|
77
|
+
const r = this.multiple ? i : i.slice(0, 1);
|
|
78
|
+
for (const s of r) this.start(s);
|
|
79
|
+
}
|
|
80
|
+
onPick(e) {
|
|
81
|
+
const t = e.target;
|
|
82
|
+
this.accept_(Array.from(t.files ?? [])), t.value = "";
|
|
83
|
+
}
|
|
84
|
+
start(e) {
|
|
85
|
+
const t = { id: ++this.seq, file: e, percent: 0, error: null };
|
|
86
|
+
this.multiple || this.abortAll(), this.pending = this.multiple ? [...this.pending, t] : [t], this.emit("baht-upload-start", { file: e }), this.send(t);
|
|
87
|
+
}
|
|
88
|
+
patch(e, t) {
|
|
89
|
+
this.pending = this.pending.map((i) => i.id === e ? { ...i, ...t } : i);
|
|
90
|
+
}
|
|
91
|
+
abort(e) {
|
|
92
|
+
var t;
|
|
93
|
+
(t = this.requests.get(e)) == null || t.abort(), this.requests.delete(e);
|
|
94
|
+
}
|
|
95
|
+
abortAll() {
|
|
96
|
+
for (const e of [...this.requests.keys()]) this.abort(e);
|
|
97
|
+
}
|
|
98
|
+
disconnectedCallback() {
|
|
99
|
+
super.disconnectedCallback(), this.abortAll();
|
|
100
|
+
}
|
|
101
|
+
send(e) {
|
|
102
|
+
const t = new XMLHttpRequest();
|
|
103
|
+
this.requests.set(e.id, t), t.open(this.method || "POST", this.url);
|
|
104
|
+
for (const [r, s] of Object.entries(v(this.headers))) t.setRequestHeader(r, s);
|
|
105
|
+
t.withCredentials = this.withCredentials, t.upload.onprogress = (r) => {
|
|
106
|
+
const s = r.total > 0 ? Math.round(r.loaded / r.total * 100) : 0;
|
|
107
|
+
this.patch(e.id, { percent: s }), this.emit("baht-upload-progress", {
|
|
108
|
+
file: e.file,
|
|
109
|
+
loaded: r.loaded,
|
|
110
|
+
total: r.total,
|
|
111
|
+
percent: s
|
|
112
|
+
});
|
|
113
|
+
}, t.onload = () => {
|
|
114
|
+
if (this.requests.get(e.id) !== t) return;
|
|
115
|
+
this.requests.delete(e.id);
|
|
116
|
+
const r = t.status >= 200 && t.status < 300, s = r ? x(t.responseText, this.responseKey) : null;
|
|
117
|
+
if (!r || !s) {
|
|
118
|
+
this.failed(e, r ? 0 : t.status);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.known.set(s, {
|
|
122
|
+
name: e.file.name,
|
|
123
|
+
size: e.file.size,
|
|
124
|
+
...e.file.type ? { type: e.file.type } : {},
|
|
125
|
+
url: s
|
|
126
|
+
}), this.pending = this.pending.filter((d) => d.id !== e.id), this.emitValue(this.multiple ? [...this.urls, s] : [s]);
|
|
127
|
+
}, t.onerror = () => {
|
|
128
|
+
this.requests.get(e.id) === t && (this.requests.delete(e.id), this.failed(e, 0));
|
|
129
|
+
};
|
|
130
|
+
const i = new FormData();
|
|
131
|
+
i.append(this.fieldName || "file", e.file, e.file.name), t.send(i);
|
|
132
|
+
}
|
|
133
|
+
failed(e, t) {
|
|
134
|
+
const i = h("uploadFailed");
|
|
135
|
+
this.patch(e.id, { error: i, percent: 0 }), this.emit("baht-upload-error", {
|
|
136
|
+
file: e.file,
|
|
137
|
+
status: t,
|
|
138
|
+
message: i
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
retry(e) {
|
|
142
|
+
this.patch(e.id, { error: null, percent: 0 }), this.send({ ...e, error: null, percent: 0 });
|
|
143
|
+
}
|
|
144
|
+
dismiss(e) {
|
|
145
|
+
this.abort(e.id), this.pending = this.pending.filter((t) => t.id !== e.id);
|
|
146
|
+
}
|
|
147
|
+
defaultHint() {
|
|
148
|
+
const e = [];
|
|
149
|
+
return this.accept && e.push(
|
|
150
|
+
this.accept.split(",").map((t) => t.trim()).join(", ")
|
|
151
|
+
), this.maxSize && e.push(h("uploadMaxSize", { size: m(this.maxSize) })), e.join(" · ");
|
|
152
|
+
}
|
|
153
|
+
render() {
|
|
154
|
+
const e = this.pending.some((f) => !f.error), t = !!this.error, i = this.hint || this.defaultHint(), r = i ? `${this.inputId}-hint` : void 0, s = this.error ? `${this.inputId}-error` : void 0, d = [r, s].filter(Boolean).join(" ") || void 0, u = [
|
|
155
|
+
"baht-dropzone",
|
|
156
|
+
this.dragging ? "baht-dropzone--over" : "",
|
|
157
|
+
this.disabled ? "baht-dropzone--disabled" : "",
|
|
158
|
+
t ? "baht-dropzone--invalid" : ""
|
|
159
|
+
].filter(Boolean).join(" ");
|
|
160
|
+
return n`<div class="baht-field baht-field--upload">
|
|
161
|
+
${this.renderLabel()}
|
|
162
|
+
<div
|
|
163
|
+
class=${u}
|
|
164
|
+
@dragover=${this.onDragOver}
|
|
165
|
+
@dragleave=${this.onDragLeave}
|
|
166
|
+
@drop=${this.onDrop}
|
|
167
|
+
>
|
|
168
|
+
<input
|
|
169
|
+
class="baht-dropzone-input"
|
|
170
|
+
id=${this.inputId}
|
|
171
|
+
type="file"
|
|
172
|
+
accept=${c(this.accept)}
|
|
173
|
+
?multiple=${this.multiple}
|
|
174
|
+
?disabled=${this.disabled}
|
|
175
|
+
?required=${this.required}
|
|
176
|
+
aria-invalid=${t ? "true" : "false"}
|
|
177
|
+
aria-describedby=${c(d)}
|
|
178
|
+
@change=${(f) => {
|
|
179
|
+
this.onPick(f);
|
|
180
|
+
}}
|
|
181
|
+
/>
|
|
182
|
+
<span class="baht-dropzone-icon" aria-hidden="true">${z("cloud-upload-arrow")}</span>
|
|
183
|
+
<span class="baht-dropzone-text">
|
|
184
|
+
<label class="baht-dropzone-action" for=${this.inputId}
|
|
185
|
+
>${this.multiple ? h("chooseFiles") : h("chooseFile")}</label
|
|
186
|
+
>
|
|
187
|
+
<span class="baht-dropzone-or">${h("orDropHere")}</span>
|
|
188
|
+
</span>
|
|
189
|
+
${i ? n`<span class="baht-dropzone-hint" id=${c(r)}>${i}</span>` : p}
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
${this.renderList(e)}
|
|
193
|
+
${this.renderRejected()}
|
|
194
|
+
${this.error ? n`<p class="baht-error" id=${c(s)} role="alert">${this.error}</p>` : p}
|
|
195
|
+
</div>`;
|
|
196
|
+
}
|
|
197
|
+
renderLabel() {
|
|
198
|
+
return this.label ? n`<label class="baht-label" for=${this.inputId}
|
|
199
|
+
>${this.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : p}</label
|
|
200
|
+
>` : p;
|
|
201
|
+
}
|
|
202
|
+
renderList(e) {
|
|
203
|
+
return this.pending.length === 0 && this.urls.length === 0 ? p : n`<ul class="baht-upload-list" aria-live="polite" aria-busy=${e ? "true" : "false"}>
|
|
204
|
+
${this.urls.map((t) => this.renderStored(t))}
|
|
205
|
+
${this.pending.map((t) => this.renderPending(t))}
|
|
206
|
+
</ul>`;
|
|
207
|
+
}
|
|
208
|
+
renderRejected() {
|
|
209
|
+
return this.rejectedNames.length === 0 ? p : n`<p class="baht-error" role="alert">
|
|
210
|
+
${h("fileRejectedTooLarge", { names: this.rejectedNames.join(", ") })}
|
|
211
|
+
</p>`;
|
|
212
|
+
}
|
|
213
|
+
renderStored(e) {
|
|
214
|
+
const t = this.fileFor(e);
|
|
215
|
+
return n`<li class="baht-file-chip baht-file-chip--done">
|
|
216
|
+
<span class="baht-file-chip-icon" aria-hidden="true">${b("check")}</span>
|
|
217
|
+
${y(e) ? n`<a class="baht-file-name" href=${e} target="_blank" rel="noreferrer"
|
|
218
|
+
>${t.name}<span class="baht-visually-hidden"> (${h("opensInNewTab")})</span></a
|
|
219
|
+
>` : n`<span class="baht-file-name">${t.name}</span>`}
|
|
220
|
+
${t.size > 0 ? n`<span class="baht-file-size">${m(t.size)}</span>` : p}
|
|
221
|
+
${this.disabled ? p : n`<button
|
|
222
|
+
type="button"
|
|
223
|
+
class="baht-file-remove"
|
|
224
|
+
aria-label=${h("removeFile")}
|
|
225
|
+
title=${h("removeFile")}
|
|
226
|
+
@click=${() => {
|
|
227
|
+
this.emitValue(this.urls.filter((i) => i !== e));
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
${b("close")}
|
|
231
|
+
</button>`}
|
|
232
|
+
</li>`;
|
|
233
|
+
}
|
|
234
|
+
renderPending(e) {
|
|
235
|
+
return n`<li class="baht-file-chip ${e.error ? "baht-file-chip--error" : "baht-file-chip--busy"}">
|
|
236
|
+
<span class="baht-file-name">${e.file.name}</span>
|
|
237
|
+
<span class="baht-file-size">${m(e.file.size)}</span>
|
|
238
|
+
${e.error ? n`<span class="baht-file-status baht-file-status--error" role="alert">${e.error}</span>
|
|
239
|
+
<button type="button" class="baht-upload-retry" @click=${() => {
|
|
240
|
+
this.retry(e);
|
|
241
|
+
}}>
|
|
242
|
+
${h("retry")}
|
|
243
|
+
</button>
|
|
244
|
+
<button
|
|
245
|
+
type="button"
|
|
246
|
+
class="baht-file-remove"
|
|
247
|
+
aria-label=${h("removeFile")}
|
|
248
|
+
title=${h("removeFile")}
|
|
249
|
+
@click=${() => {
|
|
250
|
+
this.dismiss(e);
|
|
251
|
+
}}
|
|
252
|
+
>
|
|
253
|
+
${b("close")}
|
|
254
|
+
</button>` : n`<span
|
|
255
|
+
class="baht-upload-bar"
|
|
256
|
+
role="progressbar"
|
|
257
|
+
aria-label=${h("uploading")}
|
|
258
|
+
aria-valuemin="0"
|
|
259
|
+
aria-valuemax="100"
|
|
260
|
+
aria-valuenow=${String(e.percent)}
|
|
261
|
+
><span class="baht-upload-bar-fill" style="width:${e.percent}%"></span
|
|
262
|
+
></span>`}
|
|
263
|
+
</li>`;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
l([
|
|
267
|
+
o()
|
|
268
|
+
], a.prototype, "url", 2);
|
|
269
|
+
l([
|
|
270
|
+
o()
|
|
271
|
+
], a.prototype, "method", 2);
|
|
272
|
+
l([
|
|
273
|
+
o({ attribute: "field-name" })
|
|
274
|
+
], a.prototype, "fieldName", 2);
|
|
275
|
+
l([
|
|
276
|
+
o({ attribute: "response-key" })
|
|
277
|
+
], a.prototype, "responseKey", 2);
|
|
278
|
+
l([
|
|
279
|
+
o({ attribute: !1 })
|
|
280
|
+
], a.prototype, "headers", 2);
|
|
281
|
+
l([
|
|
282
|
+
o({ type: Boolean, attribute: "with-credentials" })
|
|
283
|
+
], a.prototype, "withCredentials", 2);
|
|
284
|
+
l([
|
|
285
|
+
o({ attribute: !1 })
|
|
286
|
+
], a.prototype, "value", 2);
|
|
287
|
+
l([
|
|
288
|
+
o()
|
|
289
|
+
], a.prototype, "label", 2);
|
|
290
|
+
l([
|
|
291
|
+
o()
|
|
292
|
+
], a.prototype, "hint", 2);
|
|
293
|
+
l([
|
|
294
|
+
o()
|
|
295
|
+
], a.prototype, "accept", 2);
|
|
296
|
+
l([
|
|
297
|
+
o({ type: Boolean })
|
|
298
|
+
], a.prototype, "multiple", 2);
|
|
299
|
+
l([
|
|
300
|
+
o({ type: Number, attribute: "max-size" })
|
|
301
|
+
], a.prototype, "maxSize", 2);
|
|
302
|
+
l([
|
|
303
|
+
o({ type: Boolean })
|
|
304
|
+
], a.prototype, "disabled", 2);
|
|
305
|
+
l([
|
|
306
|
+
o({ type: Boolean })
|
|
307
|
+
], a.prototype, "required", 2);
|
|
308
|
+
l([
|
|
309
|
+
o()
|
|
310
|
+
], a.prototype, "error", 2);
|
|
311
|
+
l([
|
|
312
|
+
g()
|
|
313
|
+
], a.prototype, "pending", 2);
|
|
314
|
+
l([
|
|
315
|
+
g()
|
|
316
|
+
], a.prototype, "rejectedNames", 2);
|
|
317
|
+
l([
|
|
318
|
+
g()
|
|
319
|
+
], a.prototype, "dragging", 2);
|
|
320
|
+
a = l([
|
|
321
|
+
q("baht-upload")
|
|
322
|
+
], a);
|
|
323
|
+
export {
|
|
324
|
+
a as BahtUpload
|
|
325
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from '../base.js';
|
|
3
|
+
/** One page of `<baht-wizard>`; its panel is the child with `data-step="<key>"`. */
|
|
4
|
+
export interface WizardStep {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** Short tag on the step, with `variant="tabs"`. */
|
|
8
|
+
badge?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Pages filled in order, checked as you go. The panels are your children, matched by
|
|
12
|
+
* `data-step="<key>"`. `steps` may change while it runs: a tab per item ordered, for instance.
|
|
13
|
+
*
|
|
14
|
+
* <baht-wizard finish-label="Checkout">
|
|
15
|
+
* <section data-step="needs">…</section>
|
|
16
|
+
* <section data-step="options">…</section>
|
|
17
|
+
* </baht-wizard>
|
|
18
|
+
* wizard.steps = [{ key: 'needs', label: 'Describe needs' }, { key: 'options', label: 'Choose options' }];
|
|
19
|
+
* wizard.validateStep = (key) => forms[key].validate().valid;
|
|
20
|
+
*
|
|
21
|
+
* Next checks the page you are leaving; Back does not. Finish checks every page in order and stops
|
|
22
|
+
* on the first that fails.
|
|
23
|
+
*
|
|
24
|
+
* @fires {CustomEvent<{ value: string }>} baht-change - The page changed. `detail: { value }`.
|
|
25
|
+
* @fires {CustomEvent<void>} baht-finish - Every page passed.
|
|
26
|
+
*/
|
|
27
|
+
export declare class BahtWizard extends BahtElement {
|
|
28
|
+
steps: WizardStep[];
|
|
29
|
+
/** Key of the open page; the first when unset or unknown. */
|
|
30
|
+
value: string;
|
|
31
|
+
/** `chevron` shows a progress strip you read; `tabs` a strip you can click to go anywhere. */
|
|
32
|
+
variant: 'chevron' | 'tabs';
|
|
33
|
+
/** May this page be left? Unset: every page passes. */
|
|
34
|
+
validateStep?: (key: string) => boolean | Promise<boolean>;
|
|
35
|
+
backLabel: string;
|
|
36
|
+
nextLabel: string;
|
|
37
|
+
finishLabel: string;
|
|
38
|
+
/** Keeps the buttons from running twice while the host is working. */
|
|
39
|
+
busy: boolean;
|
|
40
|
+
private checking;
|
|
41
|
+
private panelsEl;
|
|
42
|
+
/** The open page's key. */
|
|
43
|
+
get selected(): string;
|
|
44
|
+
protected adoptChildren(): void;
|
|
45
|
+
private go;
|
|
46
|
+
private passes;
|
|
47
|
+
private guarded;
|
|
48
|
+
private next;
|
|
49
|
+
private finish;
|
|
50
|
+
private renderStrip;
|
|
51
|
+
protected render(): TemplateResult;
|
|
52
|
+
}
|
|
53
|
+
declare global {
|
|
54
|
+
interface HTMLElementTagNameMap {
|
|
55
|
+
'baht-wizard': BahtWizard;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { html as o, nothing as c } from "lit";
|
|
2
|
+
import { property as h, state as d, query as u } from "lit/decorators.js";
|
|
3
|
+
import { BahtElement as f, adoptLightChildren as v } from "../base.js";
|
|
4
|
+
import { t as b } from "@20baht/engine";
|
|
5
|
+
import { customElement as y } from "../define.js";
|
|
6
|
+
import "./baht-button.js";
|
|
7
|
+
import "./baht-steps.js";
|
|
8
|
+
import "./baht-tabs.js";
|
|
9
|
+
var m = Object.defineProperty, g = Object.getOwnPropertyDescriptor, r = (t, e, s, i) => {
|
|
10
|
+
for (var n = i > 1 ? void 0 : i ? g(e, s) : e, p = t.length - 1, l; p >= 0; p--)
|
|
11
|
+
(l = t[p]) && (n = (i ? l(e, s, n) : l(n)) || n);
|
|
12
|
+
return i && n && m(e, s, n), n;
|
|
13
|
+
};
|
|
14
|
+
let a = class extends f {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments), this.steps = [], this.value = "", this.variant = "chevron", this.backLabel = "", this.nextLabel = "", this.finishLabel = "", this.busy = !1, this.checking = !1;
|
|
17
|
+
}
|
|
18
|
+
/** The open page's key. */
|
|
19
|
+
get selected() {
|
|
20
|
+
var t;
|
|
21
|
+
return ((t = this.steps.find((e) => e.key === this.value) ?? this.steps[0]) == null ? void 0 : t.key) ?? "";
|
|
22
|
+
}
|
|
23
|
+
adoptChildren() {
|
|
24
|
+
v(this, this.panelsEl);
|
|
25
|
+
for (const t of Array.from(this.panelsEl.children))
|
|
26
|
+
t instanceof HTMLElement && (t.hidden = t.dataset.step !== this.selected);
|
|
27
|
+
}
|
|
28
|
+
go(t) {
|
|
29
|
+
t !== this.selected && (this.value = t, this.emit("baht-change", { value: t }));
|
|
30
|
+
}
|
|
31
|
+
async passes(t) {
|
|
32
|
+
return this.validateStep ? await this.validateStep(t) : !0;
|
|
33
|
+
}
|
|
34
|
+
async guarded(t) {
|
|
35
|
+
if (!(this.checking || this.busy)) {
|
|
36
|
+
this.checking = !0;
|
|
37
|
+
try {
|
|
38
|
+
await t();
|
|
39
|
+
} finally {
|
|
40
|
+
this.checking = !1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
next() {
|
|
45
|
+
return this.guarded(async () => {
|
|
46
|
+
const t = this.steps.findIndex((s) => s.key === this.selected), e = this.steps[t + 1];
|
|
47
|
+
e && await this.passes(this.selected) && this.go(e.key);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
finish() {
|
|
51
|
+
return this.guarded(async () => {
|
|
52
|
+
for (const t of this.steps)
|
|
53
|
+
if (!await this.passes(t.key)) {
|
|
54
|
+
this.go(t.key);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.emit("baht-finish");
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
renderStrip(t) {
|
|
61
|
+
if (this.variant === "tabs") {
|
|
62
|
+
const e = this.steps.map(
|
|
63
|
+
({ key: s, label: i, badge: n }) => n ? { key: s, label: i, badge: n } : { key: s, label: i }
|
|
64
|
+
);
|
|
65
|
+
return o`<baht-tabs
|
|
66
|
+
.tabs=${e}
|
|
67
|
+
.value=${this.selected}
|
|
68
|
+
@baht-change=${(s) => {
|
|
69
|
+
s.stopPropagation(), this.go(s.detail.value);
|
|
70
|
+
}}
|
|
71
|
+
></baht-tabs>`;
|
|
72
|
+
}
|
|
73
|
+
return o`<baht-steps
|
|
74
|
+
variant="chevron"
|
|
75
|
+
show-done
|
|
76
|
+
.steps=${this.steps.map((e) => e.label)}
|
|
77
|
+
.current=${t}
|
|
78
|
+
></baht-steps>`;
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
const t = this.steps.findIndex((i) => i.key === this.selected), e = t === this.steps.length - 1, s = this.busy || this.checking;
|
|
82
|
+
return o`<div class="baht-wizard">
|
|
83
|
+
${this.renderStrip(t)}
|
|
84
|
+
<div class="baht-wizard-panels"></div>
|
|
85
|
+
<div class="baht-wizard-actions">
|
|
86
|
+
${t > 0 ? o`<baht-button
|
|
87
|
+
variant="secondary"
|
|
88
|
+
.disabled=${s}
|
|
89
|
+
@click=${() => {
|
|
90
|
+
var i;
|
|
91
|
+
this.go(((i = this.steps[t - 1]) == null ? void 0 : i.key) ?? "");
|
|
92
|
+
}}
|
|
93
|
+
>${this.backLabel || b("back")}</baht-button
|
|
94
|
+
>` : c}
|
|
95
|
+
<span class="baht-wizard-gap"></span>
|
|
96
|
+
${e ? c : o`<baht-button
|
|
97
|
+
variant="primary"
|
|
98
|
+
.disabled=${s}
|
|
99
|
+
@click=${() => void this.next()}
|
|
100
|
+
>${this.nextLabel || b("next")}</baht-button
|
|
101
|
+
>`}
|
|
102
|
+
${e || this.finishLabel ? o`<baht-button
|
|
103
|
+
variant=${e ? "primary" : "secondary"}
|
|
104
|
+
.disabled=${s}
|
|
105
|
+
@click=${() => void this.finish()}
|
|
106
|
+
>${this.finishLabel || b("submit")}</baht-button
|
|
107
|
+
>` : c}
|
|
108
|
+
</div>
|
|
109
|
+
</div>`;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
r([
|
|
113
|
+
h({ attribute: !1 })
|
|
114
|
+
], a.prototype, "steps", 2);
|
|
115
|
+
r([
|
|
116
|
+
h()
|
|
117
|
+
], a.prototype, "value", 2);
|
|
118
|
+
r([
|
|
119
|
+
h()
|
|
120
|
+
], a.prototype, "variant", 2);
|
|
121
|
+
r([
|
|
122
|
+
h({ attribute: !1 })
|
|
123
|
+
], a.prototype, "validateStep", 2);
|
|
124
|
+
r([
|
|
125
|
+
h({ attribute: "back-label" })
|
|
126
|
+
], a.prototype, "backLabel", 2);
|
|
127
|
+
r([
|
|
128
|
+
h({ attribute: "next-label" })
|
|
129
|
+
], a.prototype, "nextLabel", 2);
|
|
130
|
+
r([
|
|
131
|
+
h({ attribute: "finish-label" })
|
|
132
|
+
], a.prototype, "finishLabel", 2);
|
|
133
|
+
r([
|
|
134
|
+
h({ type: Boolean })
|
|
135
|
+
], a.prototype, "busy", 2);
|
|
136
|
+
r([
|
|
137
|
+
d()
|
|
138
|
+
], a.prototype, "checking", 2);
|
|
139
|
+
r([
|
|
140
|
+
u(".baht-wizard-panels")
|
|
141
|
+
], a.prototype, "panelsEl", 2);
|
|
142
|
+
a = r([
|
|
143
|
+
y("baht-wizard")
|
|
144
|
+
], a);
|
|
145
|
+
export {
|
|
146
|
+
a as BahtWizard
|
|
147
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { nothing, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Shared chart vocabulary for the baht-*-chart primitives: series colors,
|
|
5
|
+
* value formatters, scales, the floating tooltip and the table twin every
|
|
6
|
+
* chart ships behind "View as table".
|
|
7
|
+
*
|
|
8
|
+
* Series colors come from the `--baht-chart-1 … --baht-chart-10` tokens so a
|
|
9
|
+
* consumer can retheme every chart from CSS; `color` on a chart overrides the
|
|
10
|
+
* first (or only) series.
|
|
11
|
+
*/
|
|
12
|
+
export interface ChartGroup {
|
|
13
|
+
label: string;
|
|
14
|
+
count: number;
|
|
15
|
+
}
|
|
16
|
+
/** One plotted series: a name, one value per category, optional fixed color. */
|
|
17
|
+
export interface ChartSeries {
|
|
18
|
+
name: string;
|
|
19
|
+
values: number[];
|
|
20
|
+
color?: string;
|
|
21
|
+
}
|
|
22
|
+
/** A reference line (budget, target, daily average) drawn over the marks. */
|
|
23
|
+
export interface ChartMarker {
|
|
24
|
+
/** Category the marker belongs to; omit for a chart-wide line. */
|
|
25
|
+
category?: string;
|
|
26
|
+
value: number;
|
|
27
|
+
label?: string;
|
|
28
|
+
}
|
|
29
|
+
/** One dated observation for `<baht-heatmap>`. */
|
|
30
|
+
export interface ChartDatePoint {
|
|
31
|
+
/** ISO `YYYY-MM-DD`. */
|
|
32
|
+
date: string;
|
|
33
|
+
value: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* How a raw number is rendered as text. `percent` takes a fraction (`0.18` → `18%`);
|
|
37
|
+
* `percent-100` takes a value already on a 0 to 100 scale (`18` → `18%`), the scale
|
|
38
|
+
* `<baht-progress>`, `<baht-progress-ring>` and `<baht-meter>`'s fill use.
|
|
39
|
+
*/
|
|
40
|
+
export type ChartFormat = 'number' | 'currency' | 'percent' | 'percent-100' | 'compact';
|
|
41
|
+
/** CSS color for series `i` — `override` wins for the first series only. */
|
|
42
|
+
export declare function chartColor(i: number, override?: string): string;
|
|
43
|
+
/** Sequential ramp step `i` (0-based, light → dark in light mode). */
|
|
44
|
+
export declare function chartSeqColor(i: number, steps?: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Render a number as display text.
|
|
47
|
+
*
|
|
48
|
+
* - `number` — grouped integer (`4,200`)
|
|
49
|
+
* - `currency` — narrow symbol, no decimals; THB renders `฿4,200`
|
|
50
|
+
* - `percent` — the value is a fraction (`0.185` → `18.5%`)
|
|
51
|
+
* - `percent-100` — the value is already a percentage (`18.5` → `18.5%`)
|
|
52
|
+
* - `compact` — `12.9K`, `4.2M`
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatValue(value: number, format?: ChartFormat, currency?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Axis ticks rounded to clean numbers: `0 … max` in 1 / 2 / 2.5 / 5 × 10ⁿ steps,
|
|
57
|
+
* always including 0 and a top step at or above `max` (marks-and-anatomy.md).
|
|
58
|
+
*/
|
|
59
|
+
export declare function niceTicks(max: number, count?: number): number[];
|
|
60
|
+
/**
|
|
61
|
+
* Clean ticks over `min … max`, always including 0: below zero when the data goes negative, so a
|
|
62
|
+
* negative point stays inside the plot. `minStep` is the finest step the format can print
|
|
63
|
+
* (`minTickStep`), so a ฿0–฿1 axis is 0, 1 and never "฿0 ฿0 ฿0 ฿1 ฿1 ฿1".
|
|
64
|
+
*/
|
|
65
|
+
export declare function niceRange(min: number, max: number, count?: number, minStep?: number): number[];
|
|
66
|
+
/** The finest tick step a format prints without two ticks reading the same. */
|
|
67
|
+
export declare function minTickStep(format: ChartFormat): number;
|
|
68
|
+
/** `v → px` over a linear domain. Degenerate domains map to the range start. */
|
|
69
|
+
export declare function linearScale(domain: readonly [number, number], range: readonly [number, number]): (value: number) => number;
|
|
70
|
+
/**
|
|
71
|
+
* Fold the tail of a group list into a single grey "Other" bucket — never cycle
|
|
72
|
+
* or generate a ninth hue (anti-patterns.md).
|
|
73
|
+
*/
|
|
74
|
+
export declare function foldOther(groups: ChartGroup[], max: number, label?: string): ChartGroup[];
|
|
75
|
+
/**
|
|
76
|
+
* The table twin every chart ships: the same numbers as real text, behind a
|
|
77
|
+
* `<details>` so it never competes with the marks. Cells are bound as text, so
|
|
78
|
+
* untrusted series/category names can never inject markup.
|
|
79
|
+
*/
|
|
80
|
+
export declare function renderTableTwin(caption: string, columns: string[], rows: (string | number)[][], summary?: string): TemplateResult;
|
|
81
|
+
/**
|
|
82
|
+
* Base for every chart element: the empty/loading contract, the value
|
|
83
|
+
* formatter, the table twin toggle and one floating tooltip per chart.
|
|
84
|
+
*
|
|
85
|
+
* `loading` holds the previous render at reduced opacity instead of flashing a
|
|
86
|
+
* skeleton (interaction.md): the data snapshot the chart draws is frozen while
|
|
87
|
+
* the attribute is set, and picks up the new props when it clears.
|
|
88
|
+
*/
|
|
89
|
+
export declare abstract class BahtChartBase extends BahtElement {
|
|
90
|
+
/** Shown instead of the marks when there is nothing to plot. */
|
|
91
|
+
emptyMessage: string;
|
|
92
|
+
/** Hold the previous render at reduced opacity while new data loads. */
|
|
93
|
+
loading: boolean;
|
|
94
|
+
/** Render the "View as table" twin under the chart. */
|
|
95
|
+
showTable: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* How values are rendered in labels, ticks, tooltips and the table twin:
|
|
98
|
+
* `number` | `currency` | `percent` | `percent-100` | `compact`. `percent` expects a
|
|
99
|
+
* fraction (`0.14` → "14%"); `percent-100` expects 0 to 100 (`14` → "14%").
|
|
100
|
+
*/
|
|
101
|
+
format: ChartFormat;
|
|
102
|
+
/** ISO currency code for `format="currency"` (THB renders `฿`). */
|
|
103
|
+
currency: string;
|
|
104
|
+
private tipEl?;
|
|
105
|
+
private held;
|
|
106
|
+
/** Value → display text using this chart's `format` / `currency`. */
|
|
107
|
+
protected fmt(value: number): string;
|
|
108
|
+
/**
|
|
109
|
+
* The snapshot to draw. While `loading` is set the previous one is returned,
|
|
110
|
+
* so a refetch dims the chart instead of emptying it.
|
|
111
|
+
*/
|
|
112
|
+
protected hold<T>(next: T): T;
|
|
113
|
+
/** Root class list: `baht-chart` plus the loading modifier. */
|
|
114
|
+
protected rootClass(extra: string): string;
|
|
115
|
+
/** The single floating tooltip node; rendered by the template, never appended. */
|
|
116
|
+
protected renderTooltip(): TemplateResult;
|
|
117
|
+
/**
|
|
118
|
+
* Show `text` near the pointer (or, on keyboard focus, near the mark).
|
|
119
|
+
* Content is assigned with `textContent`: category and series names are
|
|
120
|
+
* untrusted data (interaction.md).
|
|
121
|
+
*/
|
|
122
|
+
protected showTip(event: Event, text: string): void;
|
|
123
|
+
/** Hide the tooltip (pointerleave / blur). */
|
|
124
|
+
protected hideTip(): void;
|
|
125
|
+
/** The empty placeholder, or `nothing` when there is data. */
|
|
126
|
+
protected renderEmpty(): TemplateResult;
|
|
127
|
+
/** Legend rows — only ever rendered for 2+ series (marks-and-anatomy.md). */
|
|
128
|
+
protected renderLegend(entries: {
|
|
129
|
+
label: string;
|
|
130
|
+
color: string;
|
|
131
|
+
value?: string;
|
|
132
|
+
share?: string;
|
|
133
|
+
}[], kind?: 'rect' | 'line'): TemplateResult | typeof nothing;
|
|
134
|
+
}
|