@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,321 @@
|
|
|
1
|
+
import { nothing as h, html as c } from "lit";
|
|
2
|
+
import { t as u, isSafeUrl as v } from "@20baht/engine";
|
|
3
|
+
import { property as p, state as b, query as k } from "lit/decorators.js";
|
|
4
|
+
import { ComboboxController as $ } from "../combobox-controller.js";
|
|
5
|
+
import { BahtFieldBase as y } from "../field-base.js";
|
|
6
|
+
import { renderIcon as m } from "./icons.js";
|
|
7
|
+
import { customElement as g } from "../define.js";
|
|
8
|
+
import { ReferenceLabels as x } from "../reference-labels.js";
|
|
9
|
+
import { floatPanel as I } from "../floating.js";
|
|
10
|
+
import "./baht-reference-dialog.js";
|
|
11
|
+
var w = Object.defineProperty, C = Object.getOwnPropertyDescriptor, r = (e, t, i, s) => {
|
|
12
|
+
for (var o = s > 1 ? void 0 : s ? C(t, i) : t, n = e.length - 1, a; n >= 0; n--)
|
|
13
|
+
(a = e[n]) && (o = (s ? a(t, i, o) : a(o)) || o);
|
|
14
|
+
return s && o && w(t, i, o), o;
|
|
15
|
+
};
|
|
16
|
+
let l = class extends y {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(), this.label = "Reference", this.value = "", this.display = "", this.placeholder = "", this.invalid = !1, this.href = "", this.lookupLabel = "Look up records", this.fetcher = null, this.lookup = null, this.labels = new x(() => {
|
|
19
|
+
this.requestUpdate();
|
|
20
|
+
}), this.open = !1, this.term = "", this.options = [], this.loading = !1, this.activeIndex = -1, this.dialogOpen = !1, this.combo = new $(this, {
|
|
21
|
+
onOutside: () => {
|
|
22
|
+
this.close();
|
|
23
|
+
}
|
|
24
|
+
}), this.saved = null, this.onInput = (e) => {
|
|
25
|
+
!this.open && this.hasTable && (this.open = !0, this.combo.watchOutside()), this.term = e.target.value, this.activeIndex = -1, this.search(this.term);
|
|
26
|
+
}, this.onKeydown = (e) => {
|
|
27
|
+
if (this.open)
|
|
28
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
const t = this.combo.nextActive(e.key, this.activeIndex, this.options.length, {
|
|
31
|
+
wrap: !0
|
|
32
|
+
});
|
|
33
|
+
t !== void 0 && (this.activeIndex = t);
|
|
34
|
+
} else if (e.key === "Enter") {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
const t = this.options[this.activeIndex];
|
|
37
|
+
t && this.pick(t);
|
|
38
|
+
} else e.key === "Escape" && (e.preventDefault(), this.close());
|
|
39
|
+
}, this.onLookupClick = () => {
|
|
40
|
+
this.hasTable ? (this.close(), this.dialogOpen = !0) : this.open ? this.close() : this.openLookup();
|
|
41
|
+
}, I(this, { panel: ".baht-refpicker-list", fit: !0, gap: 2 });
|
|
42
|
+
}
|
|
43
|
+
get listboxId() {
|
|
44
|
+
return `baht-refpicker-list-${this.uid}`;
|
|
45
|
+
}
|
|
46
|
+
get isField() {
|
|
47
|
+
return this.assignedField !== void 0;
|
|
48
|
+
}
|
|
49
|
+
/** Records can be browsed in a table: the box is for typing, the button for the table. */
|
|
50
|
+
get hasTable() {
|
|
51
|
+
var e;
|
|
52
|
+
return this.isField && !!((e = this.lookup) != null && e.list);
|
|
53
|
+
}
|
|
54
|
+
get locked() {
|
|
55
|
+
return this.disabled || this.isField && this.readonly;
|
|
56
|
+
}
|
|
57
|
+
get recordId() {
|
|
58
|
+
return typeof this.value == "string" ? this.value : "";
|
|
59
|
+
}
|
|
60
|
+
willUpdate(e) {
|
|
61
|
+
var t, i, s, o, n;
|
|
62
|
+
super.willUpdate(e), this.dialogOpen ? ((t = this.saved) == null ? void 0 : t.lookup) !== this.lookup && (this.saved = {
|
|
63
|
+
lookup: this.lookup,
|
|
64
|
+
columns: ((s = (i = this.lookup) == null ? void 0 : i.savedColumns) == null ? void 0 : s.call(i)) ?? null,
|
|
65
|
+
filters: ((n = (o = this.lookup) == null ? void 0 : o.savedFilters) == null ? void 0 : n.call(o)) ?? null
|
|
66
|
+
}) : this.saved = null;
|
|
67
|
+
}
|
|
68
|
+
updated(e) {
|
|
69
|
+
super.updated(e), this.isField && (e.has("value") || e.has("lookup")) && this.resolveLabel();
|
|
70
|
+
}
|
|
71
|
+
/** Field mode: look up the label of an id we have not seen picked (the raw id shows until then). */
|
|
72
|
+
resolveLabel() {
|
|
73
|
+
var i;
|
|
74
|
+
const e = this.recordId, t = (i = this.lookup) == null ? void 0 : i.resolve;
|
|
75
|
+
e && t && this.labels.request(e, e, t);
|
|
76
|
+
}
|
|
77
|
+
openLookup() {
|
|
78
|
+
this.locked || this.open || (this.open = !0, this.term = "", this.activeIndex = -1, this.combo.watchOutside(), this.combo.cancel(), this.options = [], this.runFetch(""), this.updateComplete.then(() => {
|
|
79
|
+
var e;
|
|
80
|
+
(e = this.inputEl) == null || e.focus();
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
close() {
|
|
84
|
+
this.open && (this.open = !1, this.loading = !1, this.combo.invalidate(), this.combo.cancel(), this.combo.unwatchOutside());
|
|
85
|
+
}
|
|
86
|
+
search(e) {
|
|
87
|
+
this.combo.schedule(() => {
|
|
88
|
+
this.runFetch(e);
|
|
89
|
+
}, this.debounce ?? 200);
|
|
90
|
+
}
|
|
91
|
+
async runFetch(e) {
|
|
92
|
+
var s;
|
|
93
|
+
const t = this.isField ? this.lookup : null;
|
|
94
|
+
if (this.isField ? !t : !this.fetcher) return;
|
|
95
|
+
const i = this.combo.begin();
|
|
96
|
+
this.loading = !0;
|
|
97
|
+
try {
|
|
98
|
+
const o = t ? await t.search(e) : await ((s = this.fetcher) == null ? void 0 : s.call(this, e));
|
|
99
|
+
this.combo.isCurrent(i) && (this.options = o ?? []);
|
|
100
|
+
} catch {
|
|
101
|
+
this.combo.isCurrent(i) && (this.options = []);
|
|
102
|
+
} finally {
|
|
103
|
+
this.combo.isCurrent(i) && (this.loading = !1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
pick(e) {
|
|
107
|
+
this.close(), this.emitChange(e.key, e.label);
|
|
108
|
+
}
|
|
109
|
+
clear() {
|
|
110
|
+
this.close(), this.emitChange("", "");
|
|
111
|
+
}
|
|
112
|
+
emitChange(e, t) {
|
|
113
|
+
if (!this.isField) {
|
|
114
|
+
this.emit("baht-change", { value: e, label: t });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
e && this.labels.set(e, t), this.emitInput(e || null);
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
return this.isField ? super.render() : this.renderControl();
|
|
121
|
+
}
|
|
122
|
+
/** ARIA wiring that differs by mode: a field points at its label / help / error. */
|
|
123
|
+
comboboxAria() {
|
|
124
|
+
return this.isField ? {
|
|
125
|
+
label: h,
|
|
126
|
+
labelledby: this.field.label ? this.labelId : h,
|
|
127
|
+
required: this.required ? "true" : h,
|
|
128
|
+
describedby: this.describedBy,
|
|
129
|
+
invalid: this.invalidAttr,
|
|
130
|
+
listName: this.field.label ?? this.label
|
|
131
|
+
} : {
|
|
132
|
+
label: this.label,
|
|
133
|
+
labelledby: h,
|
|
134
|
+
required: h,
|
|
135
|
+
describedby: h,
|
|
136
|
+
invalid: this.invalid ? "true" : h,
|
|
137
|
+
listName: this.label
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** What the closed input shows: the record's label when known, else its id. */
|
|
141
|
+
get inputText() {
|
|
142
|
+
if (this.open) return this.term;
|
|
143
|
+
const e = this.recordId, t = this.isField ? this.labels.get(e) : this.display;
|
|
144
|
+
return t !== void 0 && t !== "" ? t : e;
|
|
145
|
+
}
|
|
146
|
+
renderControl() {
|
|
147
|
+
const e = this.recordId, t = this.comboboxAria();
|
|
148
|
+
return c`<div class="baht-refpicker${this.open ? " baht-refpicker--open" : ""}">
|
|
149
|
+
<div class="baht-refpicker-field">
|
|
150
|
+
<input
|
|
151
|
+
class="baht-control baht-refpicker-input"
|
|
152
|
+
type="text"
|
|
153
|
+
role="combobox"
|
|
154
|
+
id=${this.isField ? this.controlId : h}
|
|
155
|
+
aria-label=${t.label}
|
|
156
|
+
aria-labelledby=${t.labelledby}
|
|
157
|
+
aria-required=${t.required}
|
|
158
|
+
aria-describedby=${t.describedby}
|
|
159
|
+
aria-expanded=${this.open ? "true" : "false"}
|
|
160
|
+
aria-controls=${this.listboxId}
|
|
161
|
+
aria-autocomplete="list"
|
|
162
|
+
aria-invalid=${t.invalid}
|
|
163
|
+
aria-activedescendant=${this.activeIndex >= 0 ? `${this.listboxId}-${this.activeIndex}` : h}
|
|
164
|
+
placeholder=${this.open ? this.placeholder || u("searchPlaceholder") : this.placeholder}
|
|
165
|
+
.value=${this.inputText}
|
|
166
|
+
?disabled=${this.locked}
|
|
167
|
+
?readonly=${!this.open && !this.hasTable}
|
|
168
|
+
@focus=${() => {
|
|
169
|
+
this.hasTable || this.openLookup();
|
|
170
|
+
}}
|
|
171
|
+
@input=${this.onInput}
|
|
172
|
+
@keydown=${this.onKeydown}
|
|
173
|
+
/>
|
|
174
|
+
${e && !this.locked ? this.renderClear() : h}
|
|
175
|
+
</div>
|
|
176
|
+
<button
|
|
177
|
+
type="button"
|
|
178
|
+
class="baht-refpicker-lookup"
|
|
179
|
+
aria-label=${this.lookupLabel}
|
|
180
|
+
title=${this.lookupLabel}
|
|
181
|
+
?disabled=${this.locked}
|
|
182
|
+
@click=${this.onLookupClick}
|
|
183
|
+
>${m("search")}</button>
|
|
184
|
+
${e && this.href && v(this.href) ? c`<a
|
|
185
|
+
class="baht-refpicker-open"
|
|
186
|
+
href=${this.href}
|
|
187
|
+
aria-label=${u("openRecord")}
|
|
188
|
+
title=${u("openRecord")}
|
|
189
|
+
>${m("external")}</a>` : h}
|
|
190
|
+
${this.renderList(e, t.listName)}
|
|
191
|
+
${this.hasTable ? this.renderDialog(t.listName) : h}
|
|
192
|
+
</div>`;
|
|
193
|
+
}
|
|
194
|
+
renderDialog(e) {
|
|
195
|
+
var t, i, s, o, n;
|
|
196
|
+
return c`<baht-reference-dialog
|
|
197
|
+
.open=${this.dialogOpen}
|
|
198
|
+
.heading=${e}
|
|
199
|
+
.columns=${((t = this.lookup) == null ? void 0 : t.columns) ?? []}
|
|
200
|
+
.lister=${((i = this.lookup) == null ? void 0 : i.list) ?? null}
|
|
201
|
+
.selected=${this.recordId}
|
|
202
|
+
.walk=${((s = this.lookup) == null ? void 0 : s.walk) ?? null}
|
|
203
|
+
.savedColumns=${((o = this.saved) == null ? void 0 : o.columns) ?? null}
|
|
204
|
+
.savedFilters=${((n = this.saved) == null ? void 0 : n.filters) ?? null}
|
|
205
|
+
@baht-saved-filters-change=${(a) => {
|
|
206
|
+
var d, f;
|
|
207
|
+
a.stopPropagation(), (f = (d = this.lookup) == null ? void 0 : d.saveFilters) == null || f.call(d, a.detail.filters);
|
|
208
|
+
}}
|
|
209
|
+
@baht-columns-change=${(a) => {
|
|
210
|
+
var d, f;
|
|
211
|
+
a.stopPropagation(), (f = (d = this.lookup) == null ? void 0 : d.saveColumns) == null || f.call(d, a.detail.visibleColumns);
|
|
212
|
+
}}
|
|
213
|
+
@baht-close=${(a) => {
|
|
214
|
+
a.stopPropagation(), this.dialogOpen = !1;
|
|
215
|
+
}}
|
|
216
|
+
@baht-pick=${(a) => {
|
|
217
|
+
a.stopPropagation(), this.dialogOpen = !1, this.emitChange(a.detail.key, a.detail.label);
|
|
218
|
+
}}
|
|
219
|
+
></baht-reference-dialog>`;
|
|
220
|
+
}
|
|
221
|
+
renderClear() {
|
|
222
|
+
return c`<button
|
|
223
|
+
type="button"
|
|
224
|
+
class="baht-refpicker-clear"
|
|
225
|
+
aria-label=${u("clear")}
|
|
226
|
+
@mousedown=${(e) => {
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
}}
|
|
229
|
+
@click=${() => {
|
|
230
|
+
this.clear();
|
|
231
|
+
}}
|
|
232
|
+
>${m("close")}</button>`;
|
|
233
|
+
}
|
|
234
|
+
renderList(e, t) {
|
|
235
|
+
const i = (s) => this.combo.note("baht-refpicker-note", s);
|
|
236
|
+
return c`<div
|
|
237
|
+
class="baht-refpicker-list"
|
|
238
|
+
id=${this.listboxId}
|
|
239
|
+
role="listbox"
|
|
240
|
+
aria-label=${t}
|
|
241
|
+
aria-busy=${this.loading ? "true" : h}
|
|
242
|
+
?hidden=${!this.open}
|
|
243
|
+
>
|
|
244
|
+
${this.loading ? i(u("searching")) : this.options.length === 0 ? i(u("noMatches")) : this.options.map(
|
|
245
|
+
(s, o) => c`<button
|
|
246
|
+
type="button"
|
|
247
|
+
class="baht-refpicker-option${o === this.activeIndex ? " baht-refpicker-option--active" : ""}"
|
|
248
|
+
id="${this.listboxId}-${o}"
|
|
249
|
+
role="option"
|
|
250
|
+
aria-selected=${s.key === e ? "true" : "false"}
|
|
251
|
+
@mousedown=${(n) => {
|
|
252
|
+
n.preventDefault();
|
|
253
|
+
}}
|
|
254
|
+
@click=${() => {
|
|
255
|
+
this.pick(s);
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
<span class="baht-refpicker-option-label">${s.label}</span>
|
|
259
|
+
${s.sub ? c`<span class="baht-refpicker-option-sub">${s.sub}</span>` : h}
|
|
260
|
+
</button>`
|
|
261
|
+
)}
|
|
262
|
+
</div>`;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
r([
|
|
266
|
+
p()
|
|
267
|
+
], l.prototype, "label", 2);
|
|
268
|
+
r([
|
|
269
|
+
p()
|
|
270
|
+
], l.prototype, "value", 2);
|
|
271
|
+
r([
|
|
272
|
+
p()
|
|
273
|
+
], l.prototype, "display", 2);
|
|
274
|
+
r([
|
|
275
|
+
p()
|
|
276
|
+
], l.prototype, "placeholder", 2);
|
|
277
|
+
r([
|
|
278
|
+
p({ type: Boolean })
|
|
279
|
+
], l.prototype, "invalid", 2);
|
|
280
|
+
r([
|
|
281
|
+
p()
|
|
282
|
+
], l.prototype, "href", 2);
|
|
283
|
+
r([
|
|
284
|
+
p({ attribute: "lookup-label" })
|
|
285
|
+
], l.prototype, "lookupLabel", 2);
|
|
286
|
+
r([
|
|
287
|
+
p({ type: Number })
|
|
288
|
+
], l.prototype, "debounce", 2);
|
|
289
|
+
r([
|
|
290
|
+
p({ attribute: !1 })
|
|
291
|
+
], l.prototype, "fetcher", 2);
|
|
292
|
+
r([
|
|
293
|
+
p({ attribute: !1 })
|
|
294
|
+
], l.prototype, "lookup", 2);
|
|
295
|
+
r([
|
|
296
|
+
b()
|
|
297
|
+
], l.prototype, "open", 2);
|
|
298
|
+
r([
|
|
299
|
+
b()
|
|
300
|
+
], l.prototype, "term", 2);
|
|
301
|
+
r([
|
|
302
|
+
b()
|
|
303
|
+
], l.prototype, "options", 2);
|
|
304
|
+
r([
|
|
305
|
+
b()
|
|
306
|
+
], l.prototype, "loading", 2);
|
|
307
|
+
r([
|
|
308
|
+
b()
|
|
309
|
+
], l.prototype, "activeIndex", 2);
|
|
310
|
+
r([
|
|
311
|
+
b()
|
|
312
|
+
], l.prototype, "dialogOpen", 2);
|
|
313
|
+
r([
|
|
314
|
+
k("input")
|
|
315
|
+
], l.prototype, "inputEl", 2);
|
|
316
|
+
l = r([
|
|
317
|
+
g("baht-reference-picker")
|
|
318
|
+
], l);
|
|
319
|
+
export {
|
|
320
|
+
l as BahtReferencePicker
|
|
321
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import { BahtFieldBase } from '../field-base.js';
|
|
3
|
+
import { DerivedFieldState, FieldDescriptor, ValidationError } from '@20baht/engine';
|
|
4
|
+
import { FieldReferenceLookup } from './baht-reference-picker.js';
|
|
5
|
+
/** The lookup of a `reference` column; `row` reads the row it is in when asked. */
|
|
6
|
+
export type RowLookup = (sub: FieldDescriptor, row: () => Record<string, unknown>) => FieldReferenceLookup | null;
|
|
7
|
+
/**
|
|
8
|
+
* <baht-repeater> — array-of-rows control (spec 01 §10). `value` is an array
|
|
9
|
+
* of row objects; every row renders the same `field.fields` sub-descriptors
|
|
10
|
+
* (one level deep — nested repeaters are skipped). Controlled like every
|
|
11
|
+
* primitive: edits emit the WHOLE array via `baht-input`; the host re-feeds.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BahtRepeater extends BahtFieldBase {
|
|
14
|
+
/** Row-scoped errors from the host form, keyed `key[i].subKey`. */
|
|
15
|
+
rowErrors: ValidationError[];
|
|
16
|
+
/**
|
|
17
|
+
* Rule-derived states of the row sub-fields, keyed `key[i].sub` (spec 02
|
|
18
|
+
* §2a). Absent = every sub-field visible with its descriptor defaults.
|
|
19
|
+
*/
|
|
20
|
+
rowStates: Record<string, DerivedFieldState>;
|
|
21
|
+
/** Set by the host form: what makes a `reference` column searchable. */
|
|
22
|
+
rowLookup: RowLookup | null;
|
|
23
|
+
private draft;
|
|
24
|
+
private readonly labels;
|
|
25
|
+
private get rows();
|
|
26
|
+
private subFieldsSource;
|
|
27
|
+
private subFieldsCache;
|
|
28
|
+
/** Ordered sub-descriptors, cached per identity (read per row per render). */
|
|
29
|
+
private get subFields();
|
|
30
|
+
private patchRow;
|
|
31
|
+
private blankRow;
|
|
32
|
+
private addRow;
|
|
33
|
+
private removeRow;
|
|
34
|
+
/** Pending keystrokes in any row land in the array before the host reads it. */
|
|
35
|
+
flushTyped(): void;
|
|
36
|
+
/** Only a reference picker reads `lookup`; every other control ignores it. */
|
|
37
|
+
private lookupOf;
|
|
38
|
+
/** A stored id in the row table: its label once known, the id until then. */
|
|
39
|
+
private referenceLabel;
|
|
40
|
+
private errorFor;
|
|
41
|
+
/**
|
|
42
|
+
* Sub-controls render declaratively (one static-tag template per primitive, rows
|
|
43
|
+
* keyed by index) so Lit reuses the same node across re-renders — typing keeps
|
|
44
|
+
* focus, same as <baht-form> — and the whole thing renders on the server.
|
|
45
|
+
*/
|
|
46
|
+
private renderSub;
|
|
47
|
+
/** The dialog's copy of a row: edits stay in it until Save. */
|
|
48
|
+
private renderDraftSub;
|
|
49
|
+
private saveDraft;
|
|
50
|
+
private cellText;
|
|
51
|
+
/** `row_editor: 'dialog'`: the rows as a table, one opened at a time in a modal. */
|
|
52
|
+
private renderTable;
|
|
53
|
+
protected renderControl(): TemplateResult;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface HTMLElementTagNameMap {
|
|
57
|
+
'baht-repeater': BahtRepeater;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { nothing as d, html as l } from "lit";
|
|
2
|
+
import { property as $, state as R } from "lit/decorators.js";
|
|
3
|
+
import { repeat as u } from "lit/directives/repeat.js";
|
|
4
|
+
import { html as w } from "lit/static-html.js";
|
|
5
|
+
import { hasDom as _ } from "../base.js";
|
|
6
|
+
import { BahtFieldBase as F } from "../field-base.js";
|
|
7
|
+
import { TAG_FOR_TYPE as m, staticTag as v, WIDTH_CLASS as k } from "./tag-map.js";
|
|
8
|
+
import { defaultValue as b, validateField as S, displayValue as O, t as n } from "@20baht/engine";
|
|
9
|
+
import { customElement as T } from "../define.js";
|
|
10
|
+
import { ReferenceLabels as x } from "../reference-labels.js";
|
|
11
|
+
import "./baht-button.js";
|
|
12
|
+
import "./baht-modal.js";
|
|
13
|
+
var I = Object.defineProperty, q = Object.getOwnPropertyDescriptor, c = (e, t, r, i) => {
|
|
14
|
+
for (var o = i > 1 ? void 0 : i ? q(t, r) : t, a = e.length - 1, s; a >= 0; a--)
|
|
15
|
+
(s = e[a]) && (o = (i ? s(t, r, o) : s(o)) || o);
|
|
16
|
+
return i && o && I(t, r, o), o;
|
|
17
|
+
};
|
|
18
|
+
const D = 4;
|
|
19
|
+
let p = class extends F {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments), this.rowErrors = [], this.rowStates = {}, this.rowLookup = null, this.draft = null, this.labels = new x(() => {
|
|
22
|
+
this.requestUpdate();
|
|
23
|
+
}), this.subFieldsCache = [];
|
|
24
|
+
}
|
|
25
|
+
get rows() {
|
|
26
|
+
return Array.isArray(this.value) ? this.value : [];
|
|
27
|
+
}
|
|
28
|
+
/** Ordered sub-descriptors, cached per identity (read per row per render). */
|
|
29
|
+
get subFields() {
|
|
30
|
+
const e = this.field.fields;
|
|
31
|
+
return e !== this.subFieldsSource && (this.subFieldsSource = e, this.subFieldsCache = [...e ?? []].sort((t, r) => t.order - r.order).filter((t) => t.type !== "repeater")), this.subFieldsCache;
|
|
32
|
+
}
|
|
33
|
+
patchRow(e, t, r) {
|
|
34
|
+
const i = [...this.rows];
|
|
35
|
+
i[e] = { ...i[e], [t]: r }, this.emitInput(i);
|
|
36
|
+
}
|
|
37
|
+
blankRow() {
|
|
38
|
+
const e = {};
|
|
39
|
+
for (const t of this.subFields)
|
|
40
|
+
t.type === "label" || t.type === "section" || (e[t.key] = b(t));
|
|
41
|
+
return e;
|
|
42
|
+
}
|
|
43
|
+
addRow() {
|
|
44
|
+
this.emitInput([...this.rows, this.blankRow()]);
|
|
45
|
+
}
|
|
46
|
+
removeRow(e) {
|
|
47
|
+
this.emitInput(this.rows.filter((t, r) => r !== e));
|
|
48
|
+
}
|
|
49
|
+
/** Pending keystrokes in any row land in the array before the host reads it. */
|
|
50
|
+
flushTyped() {
|
|
51
|
+
var e;
|
|
52
|
+
if (!_()) {
|
|
53
|
+
super.flushTyped();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const t of this.querySelectorAll(
|
|
57
|
+
".baht-repeater-row > .baht-field > *, .baht-repeater-dialog > .baht-field > *"
|
|
58
|
+
))
|
|
59
|
+
(e = t.flushTyped) == null || e.call(t);
|
|
60
|
+
super.flushTyped();
|
|
61
|
+
}
|
|
62
|
+
/** Only a reference picker reads `lookup`; every other control ignores it. */
|
|
63
|
+
lookupOf(e, t) {
|
|
64
|
+
var r;
|
|
65
|
+
return e.type === "reference" ? ((r = this.rowLookup) == null ? void 0 : r.call(this, e, t)) ?? null : null;
|
|
66
|
+
}
|
|
67
|
+
/** A stored id in the row table: its label once known, the id until then. */
|
|
68
|
+
referenceLabel(e, t) {
|
|
69
|
+
var a;
|
|
70
|
+
const r = `${e.reference ?? ""}\0${t}`, i = this.labels.get(r);
|
|
71
|
+
if (i !== void 0) return i;
|
|
72
|
+
const o = (a = this.lookupOf(e, () => ({}))) == null ? void 0 : a.resolve;
|
|
73
|
+
return o && this.labels.request(r, t, o), t;
|
|
74
|
+
}
|
|
75
|
+
errorFor(e, t) {
|
|
76
|
+
var i;
|
|
77
|
+
const r = `${this.field.key}[${e}].${t}`;
|
|
78
|
+
return ((i = this.rowErrors.find((o) => o.key === r)) == null ? void 0 : i.message) ?? null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sub-controls render declaratively (one static-tag template per primitive, rows
|
|
82
|
+
* keyed by index) so Lit reuses the same node across re-renders — typing keeps
|
|
83
|
+
* focus, same as <baht-form> — and the whole thing renders on the server.
|
|
84
|
+
*/
|
|
85
|
+
renderSub(e, t, r) {
|
|
86
|
+
const i = m[r.type];
|
|
87
|
+
if (!i) return d;
|
|
88
|
+
const o = v(i), a = k[r.width ?? "full"] ?? "baht-field--w-full", s = this.rowStates[`${this.field.key}[${t}].${r.key}`], h = (y) => {
|
|
89
|
+
y.stopPropagation();
|
|
90
|
+
const { value: g } = y.detail;
|
|
91
|
+
this.patchRow(t, r.key, g);
|
|
92
|
+
}, f = r.hidden === !0 || s !== void 0 && !s.visible;
|
|
93
|
+
return l`<div
|
|
94
|
+
class="baht-field ${a}${f ? " baht-field--hidden" : ""}"
|
|
95
|
+
data-key=${r.key}
|
|
96
|
+
data-type=${r.type}
|
|
97
|
+
>
|
|
98
|
+
${w`<${o}
|
|
99
|
+
.field=${r}
|
|
100
|
+
.value=${Object.hasOwn(e, r.key) ? e[r.key] : b(r)}
|
|
101
|
+
.disabled=${this.disabled || s !== void 0 && !s.enabled}
|
|
102
|
+
.readonly=${this.readonly || ((s == null ? void 0 : s.readonly) ?? !1)}
|
|
103
|
+
.required=${s ? s.required : !!r.required}
|
|
104
|
+
.error=${this.errorFor(t, r.key)}
|
|
105
|
+
.debounce=${this.debounce}
|
|
106
|
+
.lookup=${this.lookupOf(r, () => this.rows[t] ?? {})}
|
|
107
|
+
@baht-input=${h}
|
|
108
|
+
></${o}>`}
|
|
109
|
+
</div>`;
|
|
110
|
+
}
|
|
111
|
+
/** The dialog's copy of a row: edits stay in it until Save. */
|
|
112
|
+
renderDraftSub(e, t) {
|
|
113
|
+
var s;
|
|
114
|
+
const r = m[t.type];
|
|
115
|
+
if (!r || t.hidden) return d;
|
|
116
|
+
const i = v(r), o = k[t.width ?? "full"] ?? "baht-field--w-full", a = ((s = e.errors.find((h) => h.key === t.key)) == null ? void 0 : s.message) ?? null;
|
|
117
|
+
return l`<div class="baht-field ${o}" data-key=${t.key} data-type=${t.type}>
|
|
118
|
+
${w`<${i}
|
|
119
|
+
.field=${t}
|
|
120
|
+
.value=${Object.hasOwn(e.row, t.key) ? e.row[t.key] : b(t)}
|
|
121
|
+
.required=${!!t.required}
|
|
122
|
+
.error=${a}
|
|
123
|
+
.debounce=${this.debounce}
|
|
124
|
+
.lookup=${this.lookupOf(t, () => {
|
|
125
|
+
var h;
|
|
126
|
+
return ((h = this.draft) == null ? void 0 : h.row) ?? {};
|
|
127
|
+
})}
|
|
128
|
+
@baht-input=${(h) => {
|
|
129
|
+
h.stopPropagation();
|
|
130
|
+
const { value: f } = h.detail;
|
|
131
|
+
this.draft && (this.draft = { ...this.draft, row: { ...this.draft.row, [t.key]: f } });
|
|
132
|
+
}}
|
|
133
|
+
></${i}>`}
|
|
134
|
+
</div>`;
|
|
135
|
+
}
|
|
136
|
+
saveDraft() {
|
|
137
|
+
this.flushTyped();
|
|
138
|
+
const e = this.draft;
|
|
139
|
+
if (!e) return;
|
|
140
|
+
const t = this.subFields.flatMap(
|
|
141
|
+
(i) => i.type === "label" || i.type === "section" || i.hidden ? [] : S(i, e.row[i.key], {}, e.row, {})
|
|
142
|
+
);
|
|
143
|
+
if (t.length > 0) {
|
|
144
|
+
this.draft = { ...e, errors: t };
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const r = [...this.rows];
|
|
148
|
+
e.index === null ? r.push(e.row) : r[e.index] = e.row, this.draft = null, this.emitInput(r);
|
|
149
|
+
}
|
|
150
|
+
cellText(e, t) {
|
|
151
|
+
const r = O(e, t[e.key]);
|
|
152
|
+
return r.kind === "text" ? e.type === "reference" ? this.referenceLabel(e, r.text) : r.text : r.kind === "chips" ? r.items.join(", ") : r.kind === "files" ? r.items.map((i) => i.name).join(", ") : "";
|
|
153
|
+
}
|
|
154
|
+
/** `row_editor: 'dialog'`: the rows as a table, one opened at a time in a modal. */
|
|
155
|
+
renderTable(e, t) {
|
|
156
|
+
const r = this.subFields.filter((o) => o.type !== "label" && o.type !== "section" && !o.hidden).slice(0, D), i = this.draft;
|
|
157
|
+
return l`<div
|
|
158
|
+
class="baht-repeater baht-repeater--table"
|
|
159
|
+
id=${this.controlId}
|
|
160
|
+
role="group"
|
|
161
|
+
aria-labelledby=${this.field.label ? this.labelId : d}
|
|
162
|
+
aria-describedby=${this.describedBy}
|
|
163
|
+
>
|
|
164
|
+
${this.rows.length > 0 ? l`<table class="baht-repeater-table">
|
|
165
|
+
<thead>
|
|
166
|
+
<tr>
|
|
167
|
+
${r.map((o) => l`<th scope="col">${o.label ?? o.key}</th>`)}
|
|
168
|
+
${e ? l`<th scope="col"></th>` : d}
|
|
169
|
+
</tr>
|
|
170
|
+
</thead>
|
|
171
|
+
<tbody>
|
|
172
|
+
${this.rows.map(
|
|
173
|
+
(o, a) => l`<tr
|
|
174
|
+
data-row=${a}
|
|
175
|
+
class=${this.rowErrors.some((s) => s.key.startsWith(`${this.field.key}[${String(a)}]`)) ? "baht-repeater-table-row--invalid" : ""}
|
|
176
|
+
>
|
|
177
|
+
${r.map((s) => l`<td>${this.cellText(s, o)}</td>`)}
|
|
178
|
+
${e ? l`<td class="baht-repeater-table-actions">
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
class="baht-repeater-edit"
|
|
182
|
+
aria-label=${n("editRowN", { n: a + 1 })}
|
|
183
|
+
title=${n("editRowN", { n: a + 1 })}
|
|
184
|
+
@click=${() => {
|
|
185
|
+
this.draft = { index: a, row: { ...o }, errors: [] };
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
✎
|
|
189
|
+
</button>
|
|
190
|
+
<button
|
|
191
|
+
type="button"
|
|
192
|
+
class="baht-repeater-remove"
|
|
193
|
+
aria-label=${n("removeRowN", { n: a + 1 })}
|
|
194
|
+
title=${n("removeRowN", { n: a + 1 })}
|
|
195
|
+
@click=${() => {
|
|
196
|
+
this.removeRow(a);
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
✕
|
|
200
|
+
</button>
|
|
201
|
+
</td>` : d}
|
|
202
|
+
</tr>`
|
|
203
|
+
)}
|
|
204
|
+
</tbody>
|
|
205
|
+
</table>` : d}
|
|
206
|
+
${e ? l`<button
|
|
207
|
+
type="button"
|
|
208
|
+
class="baht-repeater-add"
|
|
209
|
+
?disabled=${t}
|
|
210
|
+
@click=${() => {
|
|
211
|
+
this.draft = { index: null, row: this.blankRow(), errors: [] };
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
+ ${this.field.add_label ?? n("addRow")}
|
|
215
|
+
</button>` : d}
|
|
216
|
+
<baht-modal
|
|
217
|
+
.open=${i !== null}
|
|
218
|
+
.heading=${this.field.label ?? ""}
|
|
219
|
+
@baht-close=${(o) => {
|
|
220
|
+
o.stopPropagation(), this.draft = null;
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div class="baht-repeater-dialog">
|
|
224
|
+
${i ? u(
|
|
225
|
+
this.subFields,
|
|
226
|
+
(o) => o.key,
|
|
227
|
+
(o) => this.renderDraftSub(i, o)
|
|
228
|
+
) : d}
|
|
229
|
+
<div class="baht-repeater-dialog-actions">
|
|
230
|
+
<baht-button
|
|
231
|
+
variant="secondary"
|
|
232
|
+
@click=${() => {
|
|
233
|
+
this.draft = null;
|
|
234
|
+
}}
|
|
235
|
+
>${n("cancelRow")}</baht-button
|
|
236
|
+
>
|
|
237
|
+
<baht-button
|
|
238
|
+
variant="primary"
|
|
239
|
+
@click=${() => {
|
|
240
|
+
this.saveDraft();
|
|
241
|
+
}}
|
|
242
|
+
>${n("saveRow")}</baht-button
|
|
243
|
+
>
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
</baht-modal>
|
|
247
|
+
</div>`;
|
|
248
|
+
}
|
|
249
|
+
renderControl() {
|
|
250
|
+
const e = this.rows, t = !this.disabled && !this.readonly, r = this.field.max_rows !== void 0 && e.length >= this.field.max_rows;
|
|
251
|
+
return this.field.row_editor === "dialog" ? this.renderTable(t, r) : l`<div
|
|
252
|
+
class="baht-repeater"
|
|
253
|
+
id=${this.controlId}
|
|
254
|
+
role="group"
|
|
255
|
+
aria-labelledby=${this.field.label ? this.labelId : d}
|
|
256
|
+
aria-describedby=${this.describedBy}
|
|
257
|
+
>
|
|
258
|
+
${u(
|
|
259
|
+
e,
|
|
260
|
+
(i, o) => o,
|
|
261
|
+
(i, o) => l`<div
|
|
262
|
+
class="baht-repeater-row"
|
|
263
|
+
data-row=${o}
|
|
264
|
+
role="group"
|
|
265
|
+
aria-label=${n("row", { n: o + 1 })}
|
|
266
|
+
>
|
|
267
|
+
${u(
|
|
268
|
+
this.subFields,
|
|
269
|
+
(a) => a.key,
|
|
270
|
+
(a) => this.renderSub(i, o, a)
|
|
271
|
+
)}
|
|
272
|
+
${t ? l`<button
|
|
273
|
+
type="button"
|
|
274
|
+
class="baht-repeater-remove"
|
|
275
|
+
aria-label=${n("removeRowN", { n: o + 1 })}
|
|
276
|
+
title=${n("removeRowN", { n: o + 1 })}
|
|
277
|
+
@click=${() => {
|
|
278
|
+
this.removeRow(o);
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
✕
|
|
282
|
+
</button>` : d}
|
|
283
|
+
</div>`
|
|
284
|
+
)}
|
|
285
|
+
${this.readonly ? d : l`<button
|
|
286
|
+
type="button"
|
|
287
|
+
class="baht-repeater-add"
|
|
288
|
+
?disabled=${this.disabled || r}
|
|
289
|
+
@click=${() => {
|
|
290
|
+
this.addRow();
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
+ ${this.field.add_label ?? n("addRow")}
|
|
294
|
+
</button>`}
|
|
295
|
+
</div>`;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
c([
|
|
299
|
+
$({ attribute: !1 })
|
|
300
|
+
], p.prototype, "rowErrors", 2);
|
|
301
|
+
c([
|
|
302
|
+
$({ attribute: !1 })
|
|
303
|
+
], p.prototype, "rowStates", 2);
|
|
304
|
+
c([
|
|
305
|
+
$({ attribute: !1 })
|
|
306
|
+
], p.prototype, "rowLookup", 2);
|
|
307
|
+
c([
|
|
308
|
+
R()
|
|
309
|
+
], p.prototype, "draft", 2);
|
|
310
|
+
p = c([
|
|
311
|
+
T("baht-repeater")
|
|
312
|
+
], p);
|
|
313
|
+
export {
|
|
314
|
+
p as BahtRepeater
|
|
315
|
+
};
|