@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.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +512 -2
  3. package/dist/components/baht-form.d.ts +206 -0
  4. package/dist/components/baht-form.js +630 -0
  5. package/dist/components/baht-workflow.d.ts +187 -0
  6. package/dist/components/baht-workflow.js +455 -0
  7. package/dist/components/base.d.ts +92 -0
  8. package/dist/components/base.js +138 -0
  9. package/dist/components/combobox-controller.d.ts +65 -0
  10. package/dist/components/combobox-controller.js +82 -0
  11. package/dist/components/define.d.ts +7 -0
  12. package/dist/components/define.js +16 -0
  13. package/dist/components/field-base.d.ts +84 -0
  14. package/dist/components/field-base.js +152 -0
  15. package/dist/components/floating.d.ts +84 -0
  16. package/dist/components/floating.js +182 -0
  17. package/dist/components/form-layout.d.ts +39 -0
  18. package/dist/components/form-layout.js +67 -0
  19. package/dist/components/form-options.d.ts +39 -0
  20. package/dist/components/form-options.js +65 -0
  21. package/dist/components/form-readonly.d.ts +20 -0
  22. package/dist/components/form-readonly.js +70 -0
  23. package/dist/components/layers.d.ts +4 -0
  24. package/dist/components/layers.js +15 -0
  25. package/dist/components/menu-controller.d.ts +65 -0
  26. package/dist/components/menu-controller.js +134 -0
  27. package/dist/components/motion.d.ts +9 -0
  28. package/dist/components/motion.js +16 -0
  29. package/dist/components/primitives/baht-accordion.d.ts +29 -0
  30. package/dist/components/primitives/baht-accordion.js +66 -0
  31. package/dist/components/primitives/baht-alert.d.ts +20 -0
  32. package/dist/components/primitives/baht-alert.js +62 -0
  33. package/dist/components/primitives/baht-app-shell.d.ts +81 -0
  34. package/dist/components/primitives/baht-app-shell.js +161 -0
  35. package/dist/components/primitives/baht-approval-chain.d.ts +59 -0
  36. package/dist/components/primitives/baht-approval-chain.js +80 -0
  37. package/dist/components/primitives/baht-avatar.d.ts +19 -0
  38. package/dist/components/primitives/baht-avatar.js +43 -0
  39. package/dist/components/primitives/baht-badge.d.ts +24 -0
  40. package/dist/components/primitives/baht-badge.js +41 -0
  41. package/dist/components/primitives/baht-bar-chart.d.ts +78 -0
  42. package/dist/components/primitives/baht-bar-chart.js +361 -0
  43. package/dist/components/primitives/baht-breadcrumbs.d.ts +23 -0
  44. package/dist/components/primitives/baht-breadcrumbs.js +45 -0
  45. package/dist/components/primitives/baht-button.d.ts +89 -0
  46. package/dist/components/primitives/baht-button.js +146 -0
  47. package/dist/components/primitives/baht-calendar.d.ts +96 -0
  48. package/dist/components/primitives/baht-calendar.js +398 -0
  49. package/dist/components/primitives/baht-card.d.ts +34 -0
  50. package/dist/components/primitives/baht-card.js +70 -0
  51. package/dist/components/primitives/baht-catalog-card.d.ts +52 -0
  52. package/dist/components/primitives/baht-catalog-card.js +90 -0
  53. package/dist/components/primitives/baht-checkbox.d.ts +7 -0
  54. package/dist/components/primitives/baht-checkbox.js +40 -0
  55. package/dist/components/primitives/baht-choice-group.d.ts +52 -0
  56. package/dist/components/primitives/baht-choice-group.js +71 -0
  57. package/dist/components/primitives/baht-code.d.ts +18 -0
  58. package/dist/components/primitives/baht-code.js +33 -0
  59. package/dist/components/primitives/baht-column-picker.d.ts +69 -0
  60. package/dist/components/primitives/baht-column-picker.js +234 -0
  61. package/dist/components/primitives/baht-comments.d.ts +38 -0
  62. package/dist/components/primitives/baht-comments.js +102 -0
  63. package/dist/components/primitives/baht-currency.d.ts +13 -0
  64. package/dist/components/primitives/baht-currency.js +69 -0
  65. package/dist/components/primitives/baht-datepicker.d.ts +77 -0
  66. package/dist/components/primitives/baht-datepicker.js +235 -0
  67. package/dist/components/primitives/baht-donut-chart.d.ts +24 -0
  68. package/dist/components/primitives/baht-donut-chart.js +88 -0
  69. package/dist/components/primitives/baht-edit-table.d.ts +45 -0
  70. package/dist/components/primitives/baht-edit-table.js +176 -0
  71. package/dist/components/primitives/baht-empty-state.d.ts +26 -0
  72. package/dist/components/primitives/baht-empty-state.js +51 -0
  73. package/dist/components/primitives/baht-error-state.d.ts +21 -0
  74. package/dist/components/primitives/baht-error-state.js +44 -0
  75. package/dist/components/primitives/baht-facts.d.ts +42 -0
  76. package/dist/components/primitives/baht-facts.js +49 -0
  77. package/dist/components/primitives/baht-fieldset.d.ts +19 -0
  78. package/dist/components/primitives/baht-fieldset.js +42 -0
  79. package/dist/components/primitives/baht-file.d.ts +27 -0
  80. package/dist/components/primitives/baht-file.js +158 -0
  81. package/dist/components/primitives/baht-filter-builder.d.ts +39 -0
  82. package/dist/components/primitives/baht-filter-builder.js +201 -0
  83. package/dist/components/primitives/baht-filter.d.ts +36 -0
  84. package/dist/components/primitives/baht-filter.js +64 -0
  85. package/dist/components/primitives/baht-heatmap.d.ts +49 -0
  86. package/dist/components/primitives/baht-heatmap.js +168 -0
  87. package/dist/components/primitives/baht-input.d.ts +10 -0
  88. package/dist/components/primitives/baht-input.js +44 -0
  89. package/dist/components/primitives/baht-keyvalue-editor.d.ts +28 -0
  90. package/dist/components/primitives/baht-keyvalue-editor.js +106 -0
  91. package/dist/components/primitives/baht-line-chart.d.ts +45 -0
  92. package/dist/components/primitives/baht-line-chart.js +183 -0
  93. package/dist/components/primitives/baht-link.d.ts +26 -0
  94. package/dist/components/primitives/baht-link.js +48 -0
  95. package/dist/components/primitives/baht-list.d.ts +29 -0
  96. package/dist/components/primitives/baht-list.js +79 -0
  97. package/dist/components/primitives/baht-loading-overlay.d.ts +15 -0
  98. package/dist/components/primitives/baht-loading-overlay.js +33 -0
  99. package/dist/components/primitives/baht-markdown-view.d.ts +17 -0
  100. package/dist/components/primitives/baht-markdown-view.js +39 -0
  101. package/dist/components/primitives/baht-markdown.d.ts +34 -0
  102. package/dist/components/primitives/baht-markdown.js +177 -0
  103. package/dist/components/primitives/baht-menu.d.ts +53 -0
  104. package/dist/components/primitives/baht-menu.js +100 -0
  105. package/dist/components/primitives/baht-meter.d.ts +67 -0
  106. package/dist/components/primitives/baht-meter.js +107 -0
  107. package/dist/components/primitives/baht-modal.d.ts +71 -0
  108. package/dist/components/primitives/baht-modal.js +164 -0
  109. package/dist/components/primitives/baht-multiselect.d.ts +8 -0
  110. package/dist/components/primitives/baht-multiselect.js +47 -0
  111. package/dist/components/primitives/baht-notification-bell.d.ts +54 -0
  112. package/dist/components/primitives/baht-notification-bell.js +143 -0
  113. package/dist/components/primitives/baht-number.d.ts +5 -0
  114. package/dist/components/primitives/baht-number.js +39 -0
  115. package/dist/components/primitives/baht-order-box.d.ts +24 -0
  116. package/dist/components/primitives/baht-order-box.js +50 -0
  117. package/dist/components/primitives/baht-otp.d.ts +49 -0
  118. package/dist/components/primitives/baht-otp.js +109 -0
  119. package/dist/components/primitives/baht-page-header.d.ts +43 -0
  120. package/dist/components/primitives/baht-page-header.js +78 -0
  121. package/dist/components/primitives/baht-pagination.d.ts +33 -0
  122. package/dist/components/primitives/baht-pagination.js +86 -0
  123. package/dist/components/primitives/baht-popover.d.ts +45 -0
  124. package/dist/components/primitives/baht-popover.js +112 -0
  125. package/dist/components/primitives/baht-progress-ring.d.ts +22 -0
  126. package/dist/components/primitives/baht-progress-ring.js +62 -0
  127. package/dist/components/primitives/baht-progress.d.ts +17 -0
  128. package/dist/components/primitives/baht-progress.js +48 -0
  129. package/dist/components/primitives/baht-radio.d.ts +7 -0
  130. package/dist/components/primitives/baht-radio.js +74 -0
  131. package/dist/components/primitives/baht-range.d.ts +38 -0
  132. package/dist/components/primitives/baht-range.js +88 -0
  133. package/dist/components/primitives/baht-rating.d.ts +40 -0
  134. package/dist/components/primitives/baht-rating.js +107 -0
  135. package/dist/components/primitives/baht-record-bar.d.ts +30 -0
  136. package/dist/components/primitives/baht-record-bar.js +60 -0
  137. package/dist/components/primitives/baht-reference-dialog.d.ts +87 -0
  138. package/dist/components/primitives/baht-reference-dialog.js +418 -0
  139. package/dist/components/primitives/baht-reference-picker.d.ts +110 -0
  140. package/dist/components/primitives/baht-reference-picker.js +321 -0
  141. package/dist/components/primitives/baht-repeater.d.ts +59 -0
  142. package/dist/components/primitives/baht-repeater.js +315 -0
  143. package/dist/components/primitives/baht-rule-builder.d.ts +24 -0
  144. package/dist/components/primitives/baht-rule-builder.js +177 -0
  145. package/dist/components/primitives/baht-saved-filters.d.ts +41 -0
  146. package/dist/components/primitives/baht-saved-filters.js +126 -0
  147. package/dist/components/primitives/baht-search.d.ts +34 -0
  148. package/dist/components/primitives/baht-search.js +71 -0
  149. package/dist/components/primitives/baht-section-header.d.ts +28 -0
  150. package/dist/components/primitives/baht-section-header.js +48 -0
  151. package/dist/components/primitives/baht-section.d.ts +23 -0
  152. package/dist/components/primitives/baht-section.js +49 -0
  153. package/dist/components/primitives/baht-select.d.ts +49 -0
  154. package/dist/components/primitives/baht-select.js +197 -0
  155. package/dist/components/primitives/baht-skeleton.d.ts +16 -0
  156. package/dist/components/primitives/baht-skeleton.js +37 -0
  157. package/dist/components/primitives/baht-sparkline.d.ts +23 -0
  158. package/dist/components/primitives/baht-sparkline.js +56 -0
  159. package/dist/components/primitives/baht-spinner.d.ts +13 -0
  160. package/dist/components/primitives/baht-spinner.js +30 -0
  161. package/dist/components/primitives/baht-split-button.d.ts +43 -0
  162. package/dist/components/primitives/baht-split-button.js +87 -0
  163. package/dist/components/primitives/baht-stat-chart.d.ts +14 -0
  164. package/dist/components/primitives/baht-stat-chart.js +38 -0
  165. package/dist/components/primitives/baht-stat.d.ts +56 -0
  166. package/dist/components/primitives/baht-stat.js +117 -0
  167. package/dist/components/primitives/baht-steps.d.ts +33 -0
  168. package/dist/components/primitives/baht-steps.js +60 -0
  169. package/dist/components/primitives/baht-swipe-row.d.ts +64 -0
  170. package/dist/components/primitives/baht-swipe-row.js +178 -0
  171. package/dist/components/primitives/baht-table.d.ts +315 -0
  172. package/dist/components/primitives/baht-table.js +640 -0
  173. package/dist/components/primitives/baht-tabs.d.ts +54 -0
  174. package/dist/components/primitives/baht-tabs.js +128 -0
  175. package/dist/components/primitives/baht-tags.d.ts +96 -0
  176. package/dist/components/primitives/baht-tags.js +323 -0
  177. package/dist/components/primitives/baht-text.d.ts +10 -0
  178. package/dist/components/primitives/baht-text.js +29 -0
  179. package/dist/components/primitives/baht-textarea.d.ts +5 -0
  180. package/dist/components/primitives/baht-textarea.js +40 -0
  181. package/dist/components/primitives/baht-theme-toggle.d.ts +44 -0
  182. package/dist/components/primitives/baht-theme-toggle.js +101 -0
  183. package/dist/components/primitives/baht-timeline.d.ts +21 -0
  184. package/dist/components/primitives/baht-timeline.js +42 -0
  185. package/dist/components/primitives/baht-toast.d.ts +29 -0
  186. package/dist/components/primitives/baht-toast.js +83 -0
  187. package/dist/components/primitives/baht-toggle.d.ts +6 -0
  188. package/dist/components/primitives/baht-toggle.js +42 -0
  189. package/dist/components/primitives/baht-tooltip.d.ts +34 -0
  190. package/dist/components/primitives/baht-tooltip.js +85 -0
  191. package/dist/components/primitives/baht-tree.d.ts +58 -0
  192. package/dist/components/primitives/baht-tree.js +159 -0
  193. package/dist/components/primitives/baht-typeahead.d.ts +92 -0
  194. package/dist/components/primitives/baht-typeahead.js +258 -0
  195. package/dist/components/primitives/baht-upload.d.ts +108 -0
  196. package/dist/components/primitives/baht-upload.js +325 -0
  197. package/dist/components/primitives/baht-wizard.d.ts +57 -0
  198. package/dist/components/primitives/baht-wizard.js +147 -0
  199. package/dist/components/primitives/charts.d.ts +134 -0
  200. package/dist/components/primitives/charts.js +184 -0
  201. package/dist/components/primitives/column-map.d.ts +56 -0
  202. package/dist/components/primitives/column-map.js +70 -0
  203. package/dist/components/primitives/control-icons.d.ts +2 -0
  204. package/dist/components/primitives/control-icons.js +40 -0
  205. package/dist/components/primitives/icons.d.ts +24 -0
  206. package/dist/components/primitives/icons.js +86 -0
  207. package/dist/components/primitives/illustrations.d.ts +21 -0
  208. package/dist/components/primitives/illustrations.js +78 -0
  209. package/dist/components/primitives/index.d.ts +89 -0
  210. package/dist/components/primitives/kbd.d.ts +6 -0
  211. package/dist/components/primitives/kbd.js +9 -0
  212. package/dist/components/primitives/listbox.d.ts +2 -0
  213. package/dist/components/primitives/listbox.js +7 -0
  214. package/dist/components/primitives/markdown-render.d.ts +9 -0
  215. package/dist/components/primitives/markdown-render.js +77 -0
  216. package/dist/components/primitives/rule-rows.d.ts +55 -0
  217. package/dist/components/primitives/rule-rows.js +75 -0
  218. package/dist/components/primitives/tag-map.d.ts +6 -0
  219. package/dist/components/primitives/tag-map.js +39 -0
  220. package/dist/components/reference-labels.d.ts +22 -0
  221. package/dist/components/reference-labels.js +29 -0
  222. package/dist/components/shortcuts.d.ts +7 -0
  223. package/dist/components/shortcuts.js +43 -0
  224. package/dist/css/components.css +7517 -0
  225. package/dist/css/datepicker.css +346 -0
  226. package/dist/css/tokens.css +679 -0
  227. package/dist/custom-elements.json +45172 -0
  228. package/dist/engine.d.ts +1 -0
  229. package/dist/engine.js +1 -0
  230. package/dist/hydrate.d.ts +9 -0
  231. package/dist/hydrate.js +46 -0
  232. package/dist/index.d.ts +7 -0
  233. package/dist/index.js +210 -0
  234. package/dist/overlay.d.ts +50 -0
  235. package/dist/overlay.js +140 -0
  236. package/dist/react.d.ts +557 -0
  237. package/dist/react.js +1 -0
  238. package/dist/register.d.ts +106 -0
  239. package/dist/register.js +99 -0
  240. package/dist/ssr.d.ts +16 -0
  241. package/dist/ssr.js +125 -0
  242. package/dist/tokens.css +8197 -0
  243. package/dist/vscode.css-custom-data.json +6 -0
  244. package/dist/vscode.html-custom-data.json +2261 -0
  245. package/dist/web-types.json +6523 -0
  246. package/package.json +157 -4
@@ -0,0 +1,418 @@
1
+ import { html as h, nothing as u } from "lit";
2
+ import { property as d, state as c } from "lit/decorators.js";
3
+ import { BahtElement as T } from "../base.js";
4
+ import { t as l } from "@20baht/engine";
5
+ import { customElement as P } from "../define.js";
6
+ import { completeFilter as O, textOf as $, matchesFilter as N } from "./baht-filter-builder.js";
7
+ import { labelAt as x, specAt as E, filterFieldsOf as C, valueAt as m } from "./column-map.js";
8
+ import "./baht-column-picker.js";
9
+ import "./baht-modal.js";
10
+ import "./baht-saved-filters.js";
11
+ var _ = Object.defineProperty, q = Object.getOwnPropertyDescriptor, o = (t, e, s, i) => {
12
+ for (var a = i > 1 ? void 0 : i ? q(e, s) : e, n = t.length - 1, p; n >= 0; n--)
13
+ (p = t[n]) && (a = (i ? p(e, s, a) : p(a)) || a);
14
+ return i && a && _(e, s, a), a;
15
+ };
16
+ const F = 20, w = 250, S = (t, e) => $(t).toLowerCase().includes(e.trim().toLowerCase()), z = (t, e) => {
17
+ const { search: s, columns: i, filter: a, sort: n, page: p, pageSize: g } = e, v = t.filter(
18
+ ({ values: f }) => (!(s != null && s.term.trim()) || S(m(f, s.field), s.term)) && Object.entries(i).every(
19
+ ([y, b]) => !b.trim() || S(m(f, y), b)
20
+ ) && N(f, a)
21
+ );
22
+ if (n) {
23
+ const f = n.dir === "asc" ? 1 : -1;
24
+ v.sort(
25
+ (y, b) => f * $(m(y.values, n.key)).localeCompare(
26
+ $(m(b.values, n.key)),
27
+ void 0,
28
+ {
29
+ numeric: !0
30
+ }
31
+ )
32
+ );
33
+ }
34
+ const k = (p - 1) * g;
35
+ return { rows: v.slice(k, k + g), total: v.length };
36
+ };
37
+ let r = class extends T {
38
+ constructor() {
39
+ super(...arguments), this.open = !1, this.heading = "", this.columns = [], this.lister = null, this.selected = "", this.walk = null, this.savedColumns = null, this.savedFilters = null, this.page = { rows: [], total: 0 }, this.pageNo = 1, this.loading = !1, this.failed = !1, this.searchField = "", this.searchTerm = "", this.columnTerms = {}, this.showColumnSearch = !0, this.showFilter = !1, this.draftFilter = { match: "all", conditions: [] }, this.filter = { match: "all", conditions: [] }, this.visible = [], this.pickerOpen = !1, this.offeredFrom = null, this.shownFrom = null, this.seq = 0, this.onSearchField = (t) => {
40
+ this.searchField = t.target.value, this.searchTerm.trim() && this.reload();
41
+ }, this.onSearchTerm = (t) => {
42
+ this.searchTerm = t.target.value, this.reload(w);
43
+ }, this.onToggleColumns = () => {
44
+ this.showColumnSearch = !this.showColumnSearch;
45
+ }, this.onToggleFilter = () => {
46
+ this.showFilter = !this.showFilter;
47
+ }, this.onOpenPicker = () => {
48
+ this.pickerOpen = !0;
49
+ }, this.onClosePicker = (t) => {
50
+ t.stopPropagation(), this.pickerOpen = !1;
51
+ }, this.onColumnsChosen = (t) => {
52
+ t.stopPropagation();
53
+ const { visibleColumns: e } = t.detail;
54
+ if (e.length === 0) return;
55
+ this.visible = e, this.emit("baht-columns-change", t.detail);
56
+ const s = !e.includes(this.searchField);
57
+ s && (this.searchField = e[0] ?? "");
58
+ const i = Object.entries(this.columnTerms), a = i.filter(([n]) => e.includes(n));
59
+ a.length !== i.length ? (this.columnTerms = Object.fromEntries(a), this.reload()) : s && this.searchTerm.trim() && this.reload();
60
+ }, this.onSavedFilterPick = (t) => {
61
+ t.stopPropagation(), this.filter = t.detail.value, this.draftFilter = this.filter, this.reload();
62
+ }, this.onSavedFiltersChange = (t) => {
63
+ t.stopPropagation(), this.savedFilters = t.detail.filters, this.emit("baht-saved-filters-change", { filters: t.detail.filters });
64
+ }, this.onRunFilter = () => {
65
+ this.filter = this.draftFilter, this.reload();
66
+ }, this.onClearFilter = () => {
67
+ this.draftFilter = { match: "all", conditions: [] }, this.filter = this.draftFilter, this.reload();
68
+ }, this.onPageInput = (t) => {
69
+ const e = Number(t.target.value);
70
+ Number.isInteger(e) && this.goTo(e);
71
+ };
72
+ }
73
+ /** Read per row and handed to the column picker: one object per `columns`, not one per read. */
74
+ get offered() {
75
+ var e;
76
+ if (this.walk) return this.walk;
77
+ if (((e = this.offeredFrom) == null ? void 0 : e.columns) === this.columns) return this.offeredFrom.map;
78
+ const t = Object.fromEntries(
79
+ this.columns.map((s) => [
80
+ s.key,
81
+ {
82
+ label: s.label,
83
+ ...s.type ? { type: s.type } : {},
84
+ ...s.options ? { options: s.options } : {}
85
+ }
86
+ ])
87
+ );
88
+ return this.offeredFrom = { columns: this.columns, map: t }, t;
89
+ }
90
+ /** What the table shows now. */
91
+ get shown() {
92
+ const t = this.offered, e = this.shownFrom;
93
+ if ((e == null ? void 0 : e.visible) === this.visible && e.offered === t) return e.fields;
94
+ const s = this.visible.map((i) => ({ key: i, label: x(t, i) }));
95
+ return this.shownFrom = { visible: this.visible, offered: t, fields: s }, s;
96
+ }
97
+ disconnectedCallback() {
98
+ super.disconnectedCallback(), clearTimeout(this.timer);
99
+ }
100
+ willUpdate(t) {
101
+ if (t.has("open") && this.open) {
102
+ const e = (this.savedColumns ?? []).filter((i) => E(this.offered, i) !== void 0);
103
+ this.visible = e.length > 0 ? e : this.columns.map((i) => i.key);
104
+ const s = this.visible[0];
105
+ this.searchField = s ?? "", this.sort = s ? { key: s, dir: "asc" } : void 0, this.pickerOpen = !1, this.pageNo = 1, this.searchTerm = "", this.columnTerms = {}, this.filter = { match: "all", conditions: [] }, this.draftFilter = this.filter, this.showFilter = !1;
106
+ }
107
+ }
108
+ async getUpdateComplete() {
109
+ var e, s;
110
+ const t = await super.getUpdateComplete();
111
+ return await ((e = this.querySelector("baht-column-picker")) == null ? void 0 : e.updateComplete), await ((s = this.querySelector("baht-saved-filters")) == null ? void 0 : s.updateComplete), t;
112
+ }
113
+ updated(t) {
114
+ t.has("open") && this.open && this.load();
115
+ }
116
+ get lastPage() {
117
+ return Math.max(1, Math.ceil(this.page.total / F));
118
+ }
119
+ async load() {
120
+ if (!this.lister) return;
121
+ const t = ++this.seq;
122
+ this.loading = !0, this.failed = !1;
123
+ try {
124
+ const e = await this.lister({
125
+ ...this.searchTerm.trim() ? { search: { field: this.searchField, term: this.searchTerm } } : {},
126
+ columns: this.columnTerms,
127
+ filter: this.filter,
128
+ ...this.sort ? { sort: this.sort } : {},
129
+ page: this.pageNo,
130
+ pageSize: F
131
+ });
132
+ t === this.seq && (this.page = e);
133
+ } catch {
134
+ t === this.seq && (this.failed = !0, this.page = { rows: [], total: 0 });
135
+ } finally {
136
+ t === this.seq && (this.loading = !1);
137
+ }
138
+ }
139
+ /** A change to what matches starts again from the first page; typing waits for a pause. */
140
+ reload(t = 0) {
141
+ clearTimeout(this.timer), this.pageNo = 1, this.timer = setTimeout(() => void this.load(), t);
142
+ }
143
+ goTo(t) {
144
+ const e = Math.min(Math.max(1, t), this.lastPage);
145
+ e !== this.pageNo && (this.pageNo = e, this.load());
146
+ }
147
+ toggleSort(t) {
148
+ var e;
149
+ this.sort = ((e = this.sort) == null ? void 0 : e.key) === t ? { key: t, dir: this.sort.dir === "asc" ? "desc" : "asc" } : { key: t, dir: "asc" }, this.reload();
150
+ }
151
+ renderPager() {
152
+ const { total: t, rows: e } = this.page, s = t === 0 ? 0 : (this.pageNo - 1) * F + 1, i = (a, n, p, g) => h`<button
153
+ type="button"
154
+ class="baht-refdialog-tool"
155
+ aria-label=${a}
156
+ title=${a}
157
+ ?disabled=${g}
158
+ @click=${() => {
159
+ this.goTo(p);
160
+ }}
161
+ >
162
+ ${n}
163
+ </button>`;
164
+ return h`<div class="baht-refdialog-pager">
165
+ ${i(l("refFirst"), "«", 1, this.pageNo <= 1)}
166
+ ${i(l("refPrevious"), "‹", this.pageNo - 1, this.pageNo <= 1)}
167
+ <input
168
+ class="baht-control"
169
+ type="number"
170
+ min="1"
171
+ aria-label=${l("refPage")}
172
+ .value=${String(this.pageNo)}
173
+ @change=${this.onPageInput}
174
+ />
175
+ <span>${l("refRange", { from: s, to: s === 0 ? 0 : s + e.length - 1, total: t })}</span>
176
+ ${i(l("refNext"), "›", this.pageNo + 1, this.pageNo >= this.lastPage)}
177
+ ${i(l("refLast"), "»", this.lastPage, this.pageNo >= this.lastPage)}
178
+ </div>`;
179
+ }
180
+ renderFilter() {
181
+ return h`<div class="baht-refdialog-filter">
182
+ <baht-filter-builder
183
+ .fields=${C(this.offered)}
184
+ .value=${this.draftFilter}
185
+ @baht-change=${(t) => {
186
+ t.stopPropagation(), this.draftFilter = t.detail.value;
187
+ }}
188
+ ></baht-filter-builder>
189
+ <div class="baht-refdialog-filter-actions">
190
+ <button type="button" class="baht-refdialog-tool" @click=${this.onRunFilter}>
191
+ ${l("refRun")}
192
+ </button>
193
+ <button type="button" class="baht-refdialog-tool" @click=${this.onClearFilter}>
194
+ ${l("refClearFilter")}
195
+ </button>
196
+ ${this.savedFilters ? h`<baht-saved-filters
197
+ .filters=${this.savedFilters}
198
+ .current=${O(this.draftFilter)}
199
+ .fields=${C(this.offered)}
200
+ @baht-filter-pick=${this.onSavedFilterPick}
201
+ @baht-saved-filters-change=${this.onSavedFiltersChange}
202
+ ></baht-saved-filters>` : u}
203
+ </div>
204
+ </div>`;
205
+ }
206
+ renderHead() {
207
+ return h`<thead>
208
+ <tr>
209
+ ${this.shown.map((t) => {
210
+ var i, a, n;
211
+ const e = ((i = this.sort) == null ? void 0 : i.key) === t.key, s = ((a = this.sort) == null ? void 0 : a.dir) === "asc" ? " ▲" : " ▼";
212
+ return h`<th scope="col" aria-sort=${e ? ((n = this.sort) == null ? void 0 : n.dir) === "asc" ? "ascending" : "descending" : "none"}>
213
+ <button
214
+ type="button"
215
+ class="baht-refdialog-sort"
216
+ aria-pressed=${e ? "true" : "false"}
217
+ @click=${() => {
218
+ this.toggleSort(t.key);
219
+ }}
220
+ >
221
+ ${t.label}${e ? s : ""}
222
+ </button>
223
+ </th>`;
224
+ })}
225
+ </tr>
226
+ ${this.showColumnSearch ? h`<tr>
227
+ ${this.shown.map(
228
+ (t) => h`<th>
229
+ <input
230
+ class="baht-control"
231
+ type="search"
232
+ placeholder=${l("refSearch")}
233
+ aria-label=${`${l("refSearch")} ${t.label}`}
234
+ .value=${this.columnTerms[t.key] ?? ""}
235
+ @input=${(e) => {
236
+ this.columnTerms = {
237
+ ...this.columnTerms,
238
+ [t.key]: e.target.value
239
+ }, this.reload(w);
240
+ }}
241
+ />
242
+ </th>`
243
+ )}
244
+ </tr>` : u}
245
+ </thead>`;
246
+ }
247
+ renderCell(t, e, s) {
248
+ const i = $(m(t.values, e.key));
249
+ return s > 0 ? h`<td>${i}</td>` : h`<td>
250
+ <button
251
+ type="button"
252
+ class="baht-refdialog-pick"
253
+ @click=${() => {
254
+ this.emit("baht-pick", { key: t.key, label: t.label });
255
+ }}
256
+ >
257
+ ${i || t.label}
258
+ </button>
259
+ </td>`;
260
+ }
261
+ renderBody() {
262
+ const t = Math.max(1, this.visible.length), e = (s) => h`<tr><td class="baht-refdialog-note" colspan=${t}>${s}</td></tr>`;
263
+ return h`<tbody aria-busy=${this.loading ? "true" : "false"}>
264
+ ${this.failed ? e(l("refFailed")) : this.page.rows.length === 0 ? e(this.loading ? l("refLoading") : l("refEmpty")) : this.page.rows.map(
265
+ (s) => h`<tr
266
+ data-key=${s.key}
267
+ aria-selected=${s.key === this.selected ? "true" : "false"}
268
+ >
269
+ ${this.shown.map((i, a) => this.renderCell(s, i, a))}
270
+ </tr>`
271
+ )}
272
+ </tbody>`;
273
+ }
274
+ render() {
275
+ return h`<baht-modal
276
+ .open=${this.open}
277
+ .heading=${this.heading}
278
+ @baht-close=${(t) => {
279
+ t.stopPropagation(), this.emit("baht-close");
280
+ }}
281
+ >
282
+ <div class="baht-refdialog">
283
+ ${this.open ? h`<div class="baht-refdialog-bar">
284
+ <select
285
+ class="baht-control"
286
+ aria-label=${l("refColumn")}
287
+ @change=${this.onSearchField}
288
+ >
289
+ ${this.shown.map(
290
+ (t) => h`<option value=${t.key} ?selected=${t.key === this.searchField}>
291
+ ${t.label}
292
+ </option>`
293
+ )}
294
+ </select>
295
+ <input
296
+ class="baht-control"
297
+ type="search"
298
+ placeholder=${l("refSearch")}
299
+ aria-label=${l("refSearch")}
300
+ .value=${this.searchTerm}
301
+ @input=${this.onSearchTerm}
302
+ />
303
+ <button
304
+ type="button"
305
+ class="baht-refdialog-tool"
306
+ aria-pressed=${this.showFilter ? "true" : "false"}
307
+ @click=${this.onToggleFilter}
308
+ >
309
+ ${l("refFilter")}${this.filter.conditions.length ? ` (${String(this.filter.conditions.length)})` : ""}
310
+ </button>
311
+ <button
312
+ type="button"
313
+ class="baht-refdialog-tool"
314
+ aria-pressed=${this.showColumnSearch ? "true" : "false"}
315
+ @click=${this.onToggleColumns}
316
+ >
317
+ ${l("refColumnSearch")}
318
+ </button>
319
+ <button
320
+ type="button"
321
+ class="baht-refdialog-tool baht-refdialog-columns"
322
+ aria-haspopup="dialog"
323
+ @click=${this.onOpenPicker}
324
+ >
325
+ ${l("columns")}
326
+ </button>
327
+ ${this.renderPager()}
328
+ </div>
329
+ ${this.showFilter ? this.renderFilter() : u}
330
+ <div class="baht-refdialog-scroll">
331
+ <table class="baht-refdialog-table">
332
+ ${this.renderHead()} ${this.renderBody()}
333
+ </table>
334
+ </div>
335
+ ${this.pickerOpen ? h`<baht-column-picker
336
+ .open=${!0}
337
+ .columns=${this.offered}
338
+ .selected=${this.visible}
339
+ @baht-close=${this.onClosePicker}
340
+ @baht-columns-change=${this.onColumnsChosen}
341
+ ></baht-column-picker>` : u}` : u}
342
+ </div>
343
+ </baht-modal>`;
344
+ }
345
+ };
346
+ o([
347
+ d({ type: Boolean, reflect: !0 })
348
+ ], r.prototype, "open", 2);
349
+ o([
350
+ d()
351
+ ], r.prototype, "heading", 2);
352
+ o([
353
+ d({ attribute: !1 })
354
+ ], r.prototype, "columns", 2);
355
+ o([
356
+ d({ attribute: !1 })
357
+ ], r.prototype, "lister", 2);
358
+ o([
359
+ d()
360
+ ], r.prototype, "selected", 2);
361
+ o([
362
+ d({ attribute: !1 })
363
+ ], r.prototype, "walk", 2);
364
+ o([
365
+ d({ attribute: !1 })
366
+ ], r.prototype, "savedColumns", 2);
367
+ o([
368
+ d({ attribute: !1 })
369
+ ], r.prototype, "savedFilters", 2);
370
+ o([
371
+ c()
372
+ ], r.prototype, "page", 2);
373
+ o([
374
+ c()
375
+ ], r.prototype, "pageNo", 2);
376
+ o([
377
+ c()
378
+ ], r.prototype, "loading", 2);
379
+ o([
380
+ c()
381
+ ], r.prototype, "failed", 2);
382
+ o([
383
+ c()
384
+ ], r.prototype, "searchField", 2);
385
+ o([
386
+ c()
387
+ ], r.prototype, "searchTerm", 2);
388
+ o([
389
+ c()
390
+ ], r.prototype, "columnTerms", 2);
391
+ o([
392
+ c()
393
+ ], r.prototype, "showColumnSearch", 2);
394
+ o([
395
+ c()
396
+ ], r.prototype, "showFilter", 2);
397
+ o([
398
+ c()
399
+ ], r.prototype, "draftFilter", 2);
400
+ o([
401
+ c()
402
+ ], r.prototype, "filter", 2);
403
+ o([
404
+ c()
405
+ ], r.prototype, "sort", 2);
406
+ o([
407
+ c()
408
+ ], r.prototype, "visible", 2);
409
+ o([
410
+ c()
411
+ ], r.prototype, "pickerOpen", 2);
412
+ r = o([
413
+ P("baht-reference-dialog")
414
+ ], r);
415
+ export {
416
+ r as BahtReferenceDialog,
417
+ z as pageOfRows
418
+ };
@@ -0,0 +1,110 @@
1
+ import { nothing, PropertyValues, TemplateResult } from 'lit';
2
+ import { BahtFieldBase } from '../field-base.js';
3
+ import { FilterField, ReferenceColumns, SavedFilter, ReferenceOption, ReferencePage, ReferenceQuery } from '@20baht/engine';
4
+ export type { ReferenceOption } from '@20baht/engine';
5
+ /**
6
+ * The lookup a field-mode picker talks to: `registry.references[field.reference]` with the
7
+ * form's data already bound by `<baht-form>`.
8
+ */
9
+ export interface FieldReferenceLookup {
10
+ search: (term: string) => ReferenceOption[] | Promise<ReferenceOption[]>;
11
+ resolve?: (id: string) => ReferenceOption | null | Promise<ReferenceOption | null>;
12
+ columns?: FilterField[];
13
+ list?: (query: ReferenceQuery) => ReferencePage | Promise<ReferencePage>;
14
+ walk?: ReferenceColumns;
15
+ savedColumns?: () => string[] | null;
16
+ saveColumns?: (keys: string[]) => void;
17
+ savedFilters?: () => SavedFilter[];
18
+ saveFilters?: (filters: SavedFilter[]) => void;
19
+ }
20
+ /**
21
+ * Reference lookup: read-only input + magnifier opening a typeahead dropdown.
22
+ * The host supplies the data via `fetcher(term)`; the component owns the
23
+ * debounce, the dropdown, and the keyboard interaction.
24
+ *
25
+ * const el = document.createElement('baht-reference-picker');
26
+ * el.fetcher = (term) => api.search('sys_user', term); // Promise<ReferenceOption[]>
27
+ * el.value = '6816f79cc0a8016401c5a33be04be441';
28
+ * el.display = 'Abel Tuter';
29
+ * el.addEventListener('baht-change', (e) => onPick(e.detail)); // { value, label }
30
+ *
31
+ * Clearing emits `baht-change` with `{ value: '', label: '' }`. Set `href` to
32
+ * render an open-record link next to the lookup button.
33
+ *
34
+ * **Form field** (`type: 'reference'`, set by `<baht-form>`): `lookup` replaces `fetcher` /
35
+ * `display` — `<baht-form>` binds `registry.references[field.reference]` with the form data.
36
+ * The value is the picked record's id (`null` when cleared), emitted as
37
+ * `baht-input { key, value }`; an existing id is shown by `lookup.resolve(id)`'s label (or
38
+ * raw, without a resolver). Field label / help / error as for every field.
39
+ *
40
+ * **With `lookup.list`** the field is a box to type in, which suggests matches, and the search
41
+ * button opens the records as a table in `<baht-reference-dialog>`.
42
+ *
43
+ * @fires {CustomEvent<{ value: string; label: string }>} baht-change - Standalone mode: a record was picked or cleared. `detail: { value, label }`.
44
+ * @fires {CustomEvent<{ key: string; value: string | null }>} baht-input - Field mode: a record was picked or cleared. `detail: { key, value }`.
45
+ */
46
+ export declare class BahtReferencePicker extends BahtFieldBase {
47
+ constructor();
48
+ /** Accessible name for the combobox + its option list (standalone; a field uses its label). */
49
+ label: string;
50
+ /** Selected id (the reference's key). Field mode: `string | null`. */
51
+ value: unknown;
52
+ /** Human-readable label for `value`; falls back to showing the raw id. */
53
+ display: string;
54
+ placeholder: string;
55
+ /** Marks the control invalid (styles + aria-invalid). */
56
+ invalid: boolean;
57
+ /** Optional link to the selected record, rendered as an external-link button. */
58
+ href: string;
59
+ /** Accessible name for the lookup button. */
60
+ lookupLabel: string;
61
+ /** Debounce for search calls, ms (default 200). */
62
+ debounce?: number;
63
+ /** Async search: term in, options out. Required for the dropdown to work (standalone). */
64
+ fetcher: ((term: string) => Promise<ReferenceOption[]>) | null;
65
+ /** Field mode: the record lookup (set by `<baht-form>` from `registry.references`). */
66
+ lookup: FieldReferenceLookup | null;
67
+ private readonly labels;
68
+ private open;
69
+ private term;
70
+ private options;
71
+ private loading;
72
+ private activeIndex;
73
+ private dialogOpen;
74
+ private inputEl;
75
+ private get listboxId();
76
+ private readonly combo;
77
+ private get isField();
78
+ /** Records can be browsed in a table: the box is for typing, the button for the table. */
79
+ private get hasTable();
80
+ private get locked();
81
+ private get recordId();
82
+ /**
83
+ * What the open dialog was handed from the lookup's storage-backed `savedColumns()` /
84
+ * `savedFilters()`: read when it opens and when the lookup changes, never once per render.
85
+ */
86
+ private saved;
87
+ protected willUpdate(changed: PropertyValues<this>): void;
88
+ protected updated(changed: PropertyValues<this>): void;
89
+ /** Field mode: look up the label of an id we have not seen picked (the raw id shows until then). */
90
+ private resolveLabel;
91
+ private openLookup;
92
+ private close;
93
+ private search;
94
+ private runFetch;
95
+ private pick;
96
+ private clear;
97
+ private emitChange;
98
+ private readonly onInput;
99
+ private readonly onKeydown;
100
+ protected render(): TemplateResult | typeof nothing;
101
+ /** ARIA wiring that differs by mode: a field points at its label / help / error. */
102
+ private comboboxAria;
103
+ /** What the closed input shows: the record's label when known, else its id. */
104
+ private get inputText();
105
+ protected renderControl(): TemplateResult;
106
+ private readonly onLookupClick;
107
+ private renderDialog;
108
+ private renderClear;
109
+ private renderList;
110
+ }