@20baht/ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +512 -2
- package/dist/components/baht-form.d.ts +206 -0
- package/dist/components/baht-form.js +630 -0
- package/dist/components/baht-workflow.d.ts +187 -0
- package/dist/components/baht-workflow.js +455 -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 +45172 -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,69 @@
|
|
|
1
|
+
import { html as d } from "lit";
|
|
2
|
+
import { state as f } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as p } from "lit/directives/if-defined.js";
|
|
4
|
+
import { live as h } from "lit/directives/live.js";
|
|
5
|
+
import { BahtFieldBase as m } from "../field-base.js";
|
|
6
|
+
import { stringOf as a } from "../base.js";
|
|
7
|
+
import { customElement as b } from "../define.js";
|
|
8
|
+
var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, u = (r, t, i, o) => {
|
|
9
|
+
for (var e = o > 1 ? void 0 : o ? $(t, i) : t, n = r.length - 1, s; n >= 0; n--)
|
|
10
|
+
(s = r[n]) && (e = (o ? s(t, i, e) : s(e)) || e);
|
|
11
|
+
return o && e && y(t, i, e), e;
|
|
12
|
+
};
|
|
13
|
+
function c(r) {
|
|
14
|
+
const t = r.replace(/,/g, "").trim();
|
|
15
|
+
if (t === "" || t === "-") return null;
|
|
16
|
+
const i = Number(t);
|
|
17
|
+
return Number.isNaN(i) ? null : i;
|
|
18
|
+
}
|
|
19
|
+
function g(r) {
|
|
20
|
+
return r.toLocaleString("en-US", { maximumFractionDigits: 2 });
|
|
21
|
+
}
|
|
22
|
+
let l = class extends m {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments), this.focused = !1;
|
|
25
|
+
}
|
|
26
|
+
displayFor(r) {
|
|
27
|
+
if (r == null || r === "") return "";
|
|
28
|
+
const t = typeof r == "number" ? r : c(a(r));
|
|
29
|
+
return t == null ? a(r) : this.focused ? String(t) : g(t);
|
|
30
|
+
}
|
|
31
|
+
renderControl() {
|
|
32
|
+
return d`<span class="baht-field-icon-wrap">
|
|
33
|
+
${this.renderFieldIcon()}
|
|
34
|
+
<input
|
|
35
|
+
class="baht-control baht-control--currency${this.hasFieldIcon ? " baht-control--has-icon" : ""}"
|
|
36
|
+
id=${this.controlId}
|
|
37
|
+
type="text"
|
|
38
|
+
inputmode="decimal"
|
|
39
|
+
autocomplete="off"
|
|
40
|
+
.value=${h(this.displayFor(this.shownValue))}
|
|
41
|
+
placeholder=${p(this.field.placeholder)}
|
|
42
|
+
?disabled=${this.disabled}
|
|
43
|
+
?readonly=${this.readonly}
|
|
44
|
+
?required=${this.required}
|
|
45
|
+
aria-invalid=${this.invalidAttr}
|
|
46
|
+
aria-describedby=${this.describedBy}
|
|
47
|
+
@focus=${() => {
|
|
48
|
+
this.focused = !0;
|
|
49
|
+
}}
|
|
50
|
+
@blur=${() => {
|
|
51
|
+
this.focused = !1;
|
|
52
|
+
}}
|
|
53
|
+
@input=${(r) => {
|
|
54
|
+
const t = r.target.value;
|
|
55
|
+
this.emitTyped(t === "" ? null : c(t));
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</span>`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
u([
|
|
62
|
+
f()
|
|
63
|
+
], l.prototype, "focused", 2);
|
|
64
|
+
l = u([
|
|
65
|
+
b("baht-currency")
|
|
66
|
+
], l);
|
|
67
|
+
export {
|
|
68
|
+
l as BahtCurrency
|
|
69
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtFieldBase } from '../field-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Calendar field on top of flatpickr. The VALUE is always ISO `yyyy-mm-dd`
|
|
5
|
+
* regardless of `field.date_format` (display only):
|
|
6
|
+
* - `date_mode: 'single'` (default) -> `string | null`
|
|
7
|
+
* - `date_mode: 'range'` -> `[start, end] | null` (inclusive)
|
|
8
|
+
* - `date_mode: 'multiple'` -> `string[]`
|
|
9
|
+
* `min` / `max` bound the calendar; `disabled_dates` (ISO days or `a/b`
|
|
10
|
+
* intervals) and `disabled_weekdays` (0 = Sun … 6 = Sat) grey days out — and
|
|
11
|
+
* the engine re-checks them on validate, so the calendar is UX, not the gate.
|
|
12
|
+
*
|
|
13
|
+
* The calendar renders INSIDE the element (flatpickr `static`), so it lives in
|
|
14
|
+
* light DOM like every other node and picks up a theme set on any ancestor.
|
|
15
|
+
* While open it is drawn in the top layer (`floatPanel`), as wide as the field
|
|
16
|
+
* (at most 26rem), under it or above it, so a modal body or any `overflow`
|
|
17
|
+
* container cannot cut it off.
|
|
18
|
+
*
|
|
19
|
+
* A footer under the grid carries **Today** (picks today — greyed out when
|
|
20
|
+
* min/max/disabled rules exclude it) and **Clear** (empties the value). With
|
|
21
|
+
* `field.enable_time` the first button reads **Now** (i18n key `now`) and picks
|
|
22
|
+
* today at the current time, to the minute (seconds dropped), under the same
|
|
23
|
+
* min/max/disabled rules; like Today it closes the calendar. Both
|
|
24
|
+
* `await el.updateComplete` resolves only once the calendar is attached (the
|
|
25
|
+
* lazy flatpickr load is folded into it), so hosts and tests need no extra wait.
|
|
26
|
+
* Today / Clear go through flatpickr, so they emit exactly like a click on a day. `disableMobile`
|
|
27
|
+
* keeps this calendar on phones too — never the OS date wheel.
|
|
28
|
+
*/
|
|
29
|
+
export declare class BahtDatepicker extends BahtFieldBase {
|
|
30
|
+
private fp;
|
|
31
|
+
/**
|
|
32
|
+
* What we last told the host. A controlled host re-feeds `value` after the
|
|
33
|
+
* event, but a slow (or absent) re-feed must not make onClose re-emit the
|
|
34
|
+
* pick onChange already sent — compare against this until `value` catches up.
|
|
35
|
+
*/
|
|
36
|
+
private lastEmitted;
|
|
37
|
+
private todayBtn;
|
|
38
|
+
private clearBtn;
|
|
39
|
+
/** In-flight flatpickr load that this element is waiting on (first mount per page). */
|
|
40
|
+
private pendingLoad;
|
|
41
|
+
/**
|
|
42
|
+
* flatpickr closes the calendar on mousedown outside it. The open calendar
|
|
43
|
+
* makes the page taller, so closing it can clamp the scroll position and
|
|
44
|
+
* slide whatever was pressed (a Submit button below the field) out from
|
|
45
|
+
* under the pointer before mouseup, and the click is lost. While the
|
|
46
|
+
* calendar is open, a press outside it holds the page height until that
|
|
47
|
+
* press is over.
|
|
48
|
+
*/
|
|
49
|
+
private readonly holdPageHeight;
|
|
50
|
+
constructor();
|
|
51
|
+
protected getUpdateComplete(): Promise<boolean>;
|
|
52
|
+
protected renderControl(): TemplateResult;
|
|
53
|
+
connectedCallback(): void;
|
|
54
|
+
disconnectedCallback(): void;
|
|
55
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
56
|
+
private teardown;
|
|
57
|
+
/** Push the host-fed `value` into the calendar without echoing an event. */
|
|
58
|
+
private syncValue;
|
|
59
|
+
/** Value-equality for the picker's own selection (minute-precise with `enable_time`). */
|
|
60
|
+
private sameInstants;
|
|
61
|
+
private options;
|
|
62
|
+
private mountFooter;
|
|
63
|
+
/** Today greys out when the rules exclude it; Clear when there is nothing to clear.
|
|
64
|
+
* `fp` is passed explicitly from onReady — it fires inside the flatpickr()
|
|
65
|
+
* call, before `this.fp` is assigned. */
|
|
66
|
+
private refreshFooter;
|
|
67
|
+
private todayAllowed;
|
|
68
|
+
private pickToday;
|
|
69
|
+
private emitIfChanged;
|
|
70
|
+
/** Host value (any mode) -> the Date list flatpickr works with. A bare
|
|
71
|
+
* day is accepted even with `enable_time` on (defaults to midnight) -
|
|
72
|
+
* a host may not always have a time to feed back (an edited record that
|
|
73
|
+
* predates this field, for one). */
|
|
74
|
+
private datesOf;
|
|
75
|
+
/** flatpickr's selection -> the value shape of the field's mode. */
|
|
76
|
+
private toValue;
|
|
77
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { html as g } from "lit";
|
|
2
|
+
import { ifDefined as y } from "lit/directives/if-defined.js";
|
|
3
|
+
import { BahtFieldBase as w } from "../field-base.js";
|
|
4
|
+
import { formatIsoDateTime as f, formatIsoDate as c, dateModeOf as h, parseIsoDate as l, t as p, isoDaysOf as D, parseIsoDateTime as v, parseDisabledEntry as k } from "@20baht/engine";
|
|
5
|
+
import { renderIcon as C } from "./icons.js";
|
|
6
|
+
import { floatPanel as E } from "../floating.js";
|
|
7
|
+
import { customElement as _ } from "../define.js";
|
|
8
|
+
var L = Object.getOwnPropertyDescriptor, I = (t, e, n, i) => {
|
|
9
|
+
for (var s = i > 1 ? void 0 : i ? L(e, n) : e, a = t.length - 1, r; a >= 0; a--)
|
|
10
|
+
(r = t[a]) && (s = r(s) || s);
|
|
11
|
+
return s;
|
|
12
|
+
};
|
|
13
|
+
let u, B;
|
|
14
|
+
function O() {
|
|
15
|
+
return B ?? (B = import("flatpickr").then(
|
|
16
|
+
(t) => u = t.default,
|
|
17
|
+
(t) => {
|
|
18
|
+
console.warn("[bahtui] <baht-datepicker> needs the `flatpickr` peer dependency", t);
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
}
|
|
22
|
+
let m = class extends w {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(), this.lastEmitted = null, this.holdPageHeight = (t) => {
|
|
25
|
+
const e = t.target;
|
|
26
|
+
if (e instanceof Node && this.contains(e)) return;
|
|
27
|
+
const n = document.documentElement, i = n.style.minHeight;
|
|
28
|
+
n.style.minHeight = `${String(n.scrollHeight)}px`;
|
|
29
|
+
let s = !1;
|
|
30
|
+
const a = () => {
|
|
31
|
+
s || (s = !0, window.removeEventListener("pointerup", r, !0), window.removeEventListener("pointercancel", r, !0), n.style.minHeight = i);
|
|
32
|
+
}, r = () => {
|
|
33
|
+
setTimeout(a, 0);
|
|
34
|
+
};
|
|
35
|
+
window.addEventListener("pointerup", r, !0), window.addEventListener("pointercancel", r, !0), setTimeout(a, 2e3);
|
|
36
|
+
}, E(this, {
|
|
37
|
+
panel: ".flatpickr-calendar",
|
|
38
|
+
fit: !0,
|
|
39
|
+
gap: 2,
|
|
40
|
+
open: (t) => t.classList.contains("open")
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async getUpdateComplete() {
|
|
44
|
+
let t = await super.getUpdateComplete();
|
|
45
|
+
for (; this.pendingLoad; )
|
|
46
|
+
await this.pendingLoad, t = await super.getUpdateComplete();
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
49
|
+
renderControl() {
|
|
50
|
+
return g`<span class="baht-datepicker-field">
|
|
51
|
+
<input
|
|
52
|
+
class="baht-control baht-control--date"
|
|
53
|
+
id=${this.controlId}
|
|
54
|
+
type="text"
|
|
55
|
+
autocomplete="off"
|
|
56
|
+
placeholder=${y(this.field.placeholder)}
|
|
57
|
+
?disabled=${this.disabled}
|
|
58
|
+
?readonly=${this.readonly}
|
|
59
|
+
?required=${this.required}
|
|
60
|
+
aria-invalid=${this.invalidAttr}
|
|
61
|
+
aria-describedby=${this.describedBy}
|
|
62
|
+
/>
|
|
63
|
+
<span class="baht-datepicker-field-icon" aria-hidden="true">${C("calendar")}</span>
|
|
64
|
+
</span>`;
|
|
65
|
+
}
|
|
66
|
+
connectedCallback() {
|
|
67
|
+
super.connectedCallback(), this.hasUpdated && this.requestUpdate();
|
|
68
|
+
}
|
|
69
|
+
disconnectedCallback() {
|
|
70
|
+
super.disconnectedCallback(), this.teardown();
|
|
71
|
+
}
|
|
72
|
+
updated(t) {
|
|
73
|
+
var i;
|
|
74
|
+
const e = this.querySelector("input.baht-control--date");
|
|
75
|
+
if (!e) {
|
|
76
|
+
this.teardown();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (((i = this.fp) == null ? void 0 : i.input) !== e || t.has("field") || t.has("disabled") || t.has("readonly")) {
|
|
80
|
+
if (this.teardown(), !u) {
|
|
81
|
+
this.pendingLoad ?? (this.pendingLoad = O().then((s) => {
|
|
82
|
+
this.pendingLoad = void 0, s && this.isConnected && this.requestUpdate();
|
|
83
|
+
}));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.fp = u(e, this.options());
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
t.has("value") && (this.lastEmitted = null, this.syncValue());
|
|
90
|
+
}
|
|
91
|
+
teardown() {
|
|
92
|
+
var t;
|
|
93
|
+
document.removeEventListener("pointerdown", this.holdPageHeight, !0), (t = this.fp) == null || t.destroy(), this.fp = void 0, this.todayBtn = void 0, this.clearBtn = void 0;
|
|
94
|
+
}
|
|
95
|
+
/** Push the host-fed `value` into the calendar without echoing an event. */
|
|
96
|
+
syncValue() {
|
|
97
|
+
if (!this.fp) return;
|
|
98
|
+
const t = this.datesOf(this.value);
|
|
99
|
+
this.sameInstants(this.fp.selectedDates, t) || (t.length === 0 ? this.fp.clear(!1) : this.fp.setDate(t, !1));
|
|
100
|
+
}
|
|
101
|
+
/** Value-equality for the picker's own selection (minute-precise with `enable_time`). */
|
|
102
|
+
sameInstants(t, e) {
|
|
103
|
+
if (t.length !== e.length) return !1;
|
|
104
|
+
const n = this.field.enable_time ? f : c;
|
|
105
|
+
return t.every((i, s) => n(i) === n(e[s]));
|
|
106
|
+
}
|
|
107
|
+
options() {
|
|
108
|
+
const t = this.field, e = h(t), n = l(t.min), i = l(t.max), s = b(t);
|
|
109
|
+
return {
|
|
110
|
+
static: !0,
|
|
111
|
+
disableMobile: !0,
|
|
112
|
+
// our calendar everywhere — never the OS date wheel
|
|
113
|
+
mode: e,
|
|
114
|
+
dateFormat: t.date_format ?? (t.enable_time ? "Y-m-d H:i" : "Y-m-d"),
|
|
115
|
+
...t.enable_time ? { enableTime: !0, time_24hr: t.time_24hr ?? !1 } : {},
|
|
116
|
+
allowInput: !0,
|
|
117
|
+
clickOpens: !this.disabled && !this.readonly,
|
|
118
|
+
defaultDate: this.datesOf(this.value),
|
|
119
|
+
...n ? { minDate: n } : {},
|
|
120
|
+
...i ? { maxDate: i } : {},
|
|
121
|
+
...s ? { disable: s } : {},
|
|
122
|
+
onReady: (a, r, d) => {
|
|
123
|
+
this.mountFooter(d);
|
|
124
|
+
},
|
|
125
|
+
onOpen: () => {
|
|
126
|
+
this.refreshFooter(), this.requestUpdate(), document.addEventListener("pointerdown", this.holdPageHeight, !0);
|
|
127
|
+
},
|
|
128
|
+
onChange: (a) => {
|
|
129
|
+
this.refreshFooter(), !(e === "range" && a.length === 1) && this.emitIfChanged(a);
|
|
130
|
+
},
|
|
131
|
+
onClose: (a) => {
|
|
132
|
+
var r, d;
|
|
133
|
+
this.requestUpdate(), document.removeEventListener("pointerdown", this.holdPageHeight, !0), e === "range" && a.length === 1 && ((r = this.fp) == null || r.clear(!1)), this.emitIfChanged(((d = this.fp) == null ? void 0 : d.selectedDates) ?? []);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// ---- footer: Today / Clear ------------------------------------------
|
|
138
|
+
mountFooter(t) {
|
|
139
|
+
const e = document.createElement("div");
|
|
140
|
+
e.className = "baht-datepicker-footer";
|
|
141
|
+
const n = document.createElement("button");
|
|
142
|
+
n.type = "button", n.className = "baht-button baht-button--sm baht-datepicker-today", n.textContent = p(this.field.enable_time ? "now" : "today"), n.addEventListener("click", () => {
|
|
143
|
+
this.pickToday();
|
|
144
|
+
});
|
|
145
|
+
const i = document.createElement("button");
|
|
146
|
+
i.type = "button", i.className = "baht-button baht-button--danger baht-button--sm baht-datepicker-clear", i.textContent = p("clear"), i.addEventListener("click", () => {
|
|
147
|
+
var s, a;
|
|
148
|
+
(s = this.fp) == null || s.clear(), (a = this.fp) == null || a.close();
|
|
149
|
+
}), e.append(n, i), t.calendarContainer.appendChild(e), this.todayBtn = n, this.clearBtn = i, this.refreshFooter(t);
|
|
150
|
+
}
|
|
151
|
+
/** Today greys out when the rules exclude it; Clear when there is nothing to clear.
|
|
152
|
+
* `fp` is passed explicitly from onReady — it fires inside the flatpickr()
|
|
153
|
+
* call, before `this.fp` is assigned. */
|
|
154
|
+
refreshFooter(t = this.fp) {
|
|
155
|
+
t && (this.todayBtn && (this.todayBtn.disabled = !this.todayAllowed()), this.clearBtn && (this.clearBtn.disabled = t.selectedDates.length === 0));
|
|
156
|
+
}
|
|
157
|
+
todayAllowed() {
|
|
158
|
+
const t = o(/* @__PURE__ */ new Date()), e = l(this.field.min), n = l(this.field.max);
|
|
159
|
+
return e && t < o(e) || n && t > o(n) ? !1 : !(b(this.field) ?? []).some((i) => H(i, t));
|
|
160
|
+
}
|
|
161
|
+
pickToday() {
|
|
162
|
+
const t = this.fp;
|
|
163
|
+
if (!t || !this.todayAllowed()) return;
|
|
164
|
+
const e = this.field.enable_time ? x(/* @__PURE__ */ new Date()) : o(/* @__PURE__ */ new Date());
|
|
165
|
+
switch (h(this.field)) {
|
|
166
|
+
case "range":
|
|
167
|
+
t.setDate([e, e], !0);
|
|
168
|
+
break;
|
|
169
|
+
case "multiple": {
|
|
170
|
+
t.selectedDates.some((i) => this.sameInstants([i], [e])) || t.setDate([...t.selectedDates, e], !0);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case "single":
|
|
174
|
+
t.setDate(e, !0);
|
|
175
|
+
}
|
|
176
|
+
t.close();
|
|
177
|
+
}
|
|
178
|
+
emitIfChanged(t) {
|
|
179
|
+
const e = this.lastEmitted ?? this.datesOf(this.value);
|
|
180
|
+
this.sameInstants(t, e) || (this.lastEmitted = [...t], this.emitInput(this.toValue(t)));
|
|
181
|
+
}
|
|
182
|
+
/** Host value (any mode) -> the Date list flatpickr works with. A bare
|
|
183
|
+
* day is accepted even with `enable_time` on (defaults to midnight) -
|
|
184
|
+
* a host may not always have a time to feed back (an edited record that
|
|
185
|
+
* predates this field, for one). */
|
|
186
|
+
datesOf(t) {
|
|
187
|
+
const e = (n) => (this.field.enable_time ? v(n) : null) ?? l(n);
|
|
188
|
+
return D(t).map(e).filter((n) => n !== null);
|
|
189
|
+
}
|
|
190
|
+
/** flatpickr's selection -> the value shape of the field's mode. */
|
|
191
|
+
toValue(t) {
|
|
192
|
+
const e = this.field.enable_time ? f : c, n = t.map(e);
|
|
193
|
+
switch (h(this.field)) {
|
|
194
|
+
case "range":
|
|
195
|
+
return n.length === 2 ? [n[0], n[1]] : null;
|
|
196
|
+
case "multiple":
|
|
197
|
+
return n;
|
|
198
|
+
case "single":
|
|
199
|
+
return n[0] ?? null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
m = I([
|
|
204
|
+
_("baht-datepicker")
|
|
205
|
+
], m);
|
|
206
|
+
function o(t) {
|
|
207
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate());
|
|
208
|
+
}
|
|
209
|
+
function x(t) {
|
|
210
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours(), t.getMinutes());
|
|
211
|
+
}
|
|
212
|
+
function F(t, e) {
|
|
213
|
+
return c(t) === c(e);
|
|
214
|
+
}
|
|
215
|
+
function H(t, e) {
|
|
216
|
+
if (t instanceof Date) return F(t, e);
|
|
217
|
+
if (typeof t == "function") return t(e);
|
|
218
|
+
if (typeof t == "object" && "from" in t) {
|
|
219
|
+
const n = o(new Date(t.from)), i = o(new Date(t.to));
|
|
220
|
+
return e >= n && e <= i;
|
|
221
|
+
}
|
|
222
|
+
return !1;
|
|
223
|
+
}
|
|
224
|
+
function b(t) {
|
|
225
|
+
const e = [];
|
|
226
|
+
for (const i of t.disabled_dates ?? []) {
|
|
227
|
+
const s = k(i);
|
|
228
|
+
s && e.push(s[0].getTime() === s[1].getTime() ? s[0] : { from: s[0], to: s[1] });
|
|
229
|
+
}
|
|
230
|
+
const n = t.disabled_weekdays;
|
|
231
|
+
return n != null && n.length && e.push((i) => n.includes(i.getDay())), e;
|
|
232
|
+
}
|
|
233
|
+
export {
|
|
234
|
+
m as BahtDatepicker
|
|
235
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import { BahtChartBase, ChartGroup } from './charts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Pure-SVG donut with a legend that carries value and share.
|
|
5
|
+
*
|
|
6
|
+
* const el = document.createElement('baht-donut-chart');
|
|
7
|
+
* el.groups = [{ label: 'Open', count: 4 }, { label: 'Closed', count: 9 }];
|
|
8
|
+
*
|
|
9
|
+
* `total` defaults to the group sum; set it when the center number differs
|
|
10
|
+
* (e.g. records vs. groups). Segments are separated by a 2px gap that shows the
|
|
11
|
+
* surface through, never by a stroke drawn around them.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BahtDonutChart extends BahtChartBase {
|
|
14
|
+
groups: ChartGroup[];
|
|
15
|
+
total: number | null;
|
|
16
|
+
/** Single-series color override (first segment). */
|
|
17
|
+
color: string;
|
|
18
|
+
centerLabel: string;
|
|
19
|
+
/** Label of the folded tail bucket. */
|
|
20
|
+
otherLabel: string;
|
|
21
|
+
private static readonly R;
|
|
22
|
+
private static readonly GAP;
|
|
23
|
+
protected render(): TemplateResult;
|
|
24
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { html as b, nothing as x, svg as w } from "lit";
|
|
2
|
+
import { property as p } from "lit/decorators.js";
|
|
3
|
+
import { arr as L } from "../base.js";
|
|
4
|
+
import { BahtChartBase as C, foldOther as M, chartColor as P, renderTableTwin as _ } from "./charts.js";
|
|
5
|
+
import { customElement as O } from "../define.js";
|
|
6
|
+
var B = Object.defineProperty, E = Object.getOwnPropertyDescriptor, c = (s, a, n, o) => {
|
|
7
|
+
for (var r = o > 1 ? void 0 : o ? E(a, n) : a, l = s.length - 1, i; l >= 0; l--)
|
|
8
|
+
(i = s[l]) && (r = (o ? i(a, n, r) : i(r)) || r);
|
|
9
|
+
return o && r && B(a, n, r), r;
|
|
10
|
+
};
|
|
11
|
+
const $ = 6;
|
|
12
|
+
let e = class extends C {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments), this.groups = [], this.total = null, this.color = "", this.centerLabel = "records", this.otherLabel = "Other";
|
|
15
|
+
}
|
|
16
|
+
render() {
|
|
17
|
+
const s = this.hold(L(this.groups));
|
|
18
|
+
if (s.length === 0)
|
|
19
|
+
return b`<div class=${this.rootClass("baht-donut-chart")}>${this.renderEmpty()}</div>`;
|
|
20
|
+
const a = M(s, $, this.otherLabel), n = a.reduce((t, h) => t + h.count, 0) || 1, o = this.total ?? s.reduce((t, h) => t + h.count, 0), r = e.R, l = 2 * Math.PI * r, i = a.length > 1 ? e.GAP : 0, g = s.length > $;
|
|
21
|
+
let m = 0;
|
|
22
|
+
const d = a.map((t, h) => {
|
|
23
|
+
const u = t.count / n, f = Math.max(0, u * l - i), y = {
|
|
24
|
+
...t,
|
|
25
|
+
frac: u,
|
|
26
|
+
dash: `${f} ${l - f}`,
|
|
27
|
+
offset: -m * l,
|
|
28
|
+
// the folded tail is grey — never a generated ninth hue
|
|
29
|
+
color: g && h === a.length - 1 ? "var(--baht-chart-muted)" : P(h, this.color || void 0)
|
|
30
|
+
};
|
|
31
|
+
return m += u, y;
|
|
32
|
+
}), v = `${o} ${this.centerLabel}: ${d.map((t) => `${t.label || "(empty)"} ${t.count} (${Math.round(t.frac * 100)}%)`).join(", ")}`;
|
|
33
|
+
return b`<div class=${this.rootClass("baht-donut-chart")}>
|
|
34
|
+
<svg width="160" height="160" viewBox="0 0 160 160" role="img" aria-label=${v}>
|
|
35
|
+
<g transform="translate(80,80) rotate(-90)">
|
|
36
|
+
${d.map(
|
|
37
|
+
(t) => w`<circle r=${r} cx="0" cy="0" fill="none" stroke=${t.color}
|
|
38
|
+
stroke-width="22" stroke-dasharray=${t.dash} stroke-dashoffset=${t.offset}/>`
|
|
39
|
+
)}
|
|
40
|
+
</g>
|
|
41
|
+
<text x="80" y="76" text-anchor="middle" class="baht-donut-chart-total">${this.fmt(o)}</text>
|
|
42
|
+
<text x="80" y="94" text-anchor="middle" class="baht-donut-chart-sub">${this.centerLabel}</text>
|
|
43
|
+
</svg>
|
|
44
|
+
<div class="baht-chart-legend">
|
|
45
|
+
${d.map(
|
|
46
|
+
(t) => b`<div class="baht-chart-legend-row">
|
|
47
|
+
<span class="baht-chart-swatch" style="background:${t.color}" aria-hidden="true"></span>
|
|
48
|
+
<span class="baht-chart-legend-label">${t.label || "(empty)"}</span>
|
|
49
|
+
<span class="baht-chart-legend-count">${this.fmt(t.count)}</span>
|
|
50
|
+
<span class="baht-chart-legend-pct">(${Math.round(t.frac * 100)}%)</span>
|
|
51
|
+
</div>`
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
${this.showTable ? _(
|
|
55
|
+
`${o} ${this.centerLabel}`,
|
|
56
|
+
["Slice", "Value", "Share"],
|
|
57
|
+
d.map((t) => [
|
|
58
|
+
t.label || "(empty)",
|
|
59
|
+
this.fmt(t.count),
|
|
60
|
+
`${Math.round(t.frac * 100)}%`
|
|
61
|
+
])
|
|
62
|
+
) : x}
|
|
63
|
+
</div>`;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
e.R = 54;
|
|
67
|
+
e.GAP = 2;
|
|
68
|
+
c([
|
|
69
|
+
p({ attribute: !1 })
|
|
70
|
+
], e.prototype, "groups", 2);
|
|
71
|
+
c([
|
|
72
|
+
p({ type: Number })
|
|
73
|
+
], e.prototype, "total", 2);
|
|
74
|
+
c([
|
|
75
|
+
p()
|
|
76
|
+
], e.prototype, "color", 2);
|
|
77
|
+
c([
|
|
78
|
+
p({ attribute: "center-label" })
|
|
79
|
+
], e.prototype, "centerLabel", 2);
|
|
80
|
+
c([
|
|
81
|
+
p({ attribute: "other-label" })
|
|
82
|
+
], e.prototype, "otherLabel", 2);
|
|
83
|
+
e = c([
|
|
84
|
+
O("baht-donut-chart")
|
|
85
|
+
], e);
|
|
86
|
+
export {
|
|
87
|
+
e as BahtDonutChart
|
|
88
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from '../base.js';
|
|
3
|
+
export interface EditColumn {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/**
|
|
7
|
+
* `readonly` shows the value (a key set once: it is still a text input in
|
|
8
|
+
* the `addable` row); the rest are inputs. Default `text`.
|
|
9
|
+
*/
|
|
10
|
+
type?: 'text' | 'number' | 'checkbox' | 'select' | 'readonly';
|
|
11
|
+
options?: {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
export type EditRow = Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* A table whose cells are edited in place (reference lists, catalog items,
|
|
19
|
+
* groups). Each changed row shows Save; Save emits `baht-row-save`
|
|
20
|
+
* `{ key, row }`, Remove emits `baht-row-delete` `{ key, row }`. With
|
|
21
|
+
* `addable`, a blank first row emits `baht-row-add` `{ row }`. The host
|
|
22
|
+
* persists and feeds the new `rows` back, which clears the edits.
|
|
23
|
+
* @fires {CustomEvent<{ row: EditRow }>} baht-row-add - The blank first row was added (`addable`).
|
|
24
|
+
* @fires {CustomEvent<{ key: string; row: EditRow }>} baht-row-save - A changed row's Save was pressed.
|
|
25
|
+
* @fires {CustomEvent<{ key: string; row: EditRow }>} baht-row-delete - Remove was pressed (`removable`).
|
|
26
|
+
*/
|
|
27
|
+
export declare class BahtEditTable extends BahtElement {
|
|
28
|
+
columns: EditColumn[];
|
|
29
|
+
rows: EditRow[];
|
|
30
|
+
rowKey: string;
|
|
31
|
+
addable: boolean;
|
|
32
|
+
removable: boolean;
|
|
33
|
+
label: string;
|
|
34
|
+
/** Edited rows by key, until the host feeds new `rows`. */
|
|
35
|
+
private edits;
|
|
36
|
+
private draft;
|
|
37
|
+
willUpdate(changed: PropertyValues<this>): void;
|
|
38
|
+
private setDraft;
|
|
39
|
+
private addDraft;
|
|
40
|
+
private keyOf;
|
|
41
|
+
private editCell;
|
|
42
|
+
private inputValue;
|
|
43
|
+
private cell;
|
|
44
|
+
protected render(): TemplateResult;
|
|
45
|
+
}
|