@20baht/ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +501 -2
  3. package/dist/components/baht-form.d.ts +191 -0
  4. package/dist/components/baht-form.js +614 -0
  5. package/dist/components/baht-workflow.d.ts +173 -0
  6. package/dist/components/baht-workflow.js +430 -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 +45110 -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,92 @@
1
+ import { PropertyValues, TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ export interface TypeaheadOption {
4
+ key: string;
5
+ label: string;
6
+ /** Secondary text shown right-aligned (e.g. an email under a name). */
7
+ sub?: string;
8
+ }
9
+ /**
10
+ * Text input with suggestions (autocomplete). The value IS the text — pick a
11
+ * suggestion and the input shows its label; keep typing and the text stands
12
+ * on its own (`free-text`, default) or is only a filter (`free-text="false"`,
13
+ * blur then reverts to the last picked option).
14
+ *
15
+ * Suggestions come from a static `options` list (filtered here — labels that
16
+ * start with the term rank first, then labels that contain it) or from an
17
+ * async `fetcher(term)`. Typing is debounced (`debounce`, 150 ms) before the
18
+ * host hears `baht-change` and before a fetcher runs.
19
+ *
20
+ * const el = document.createElement('baht-typeahead');
21
+ * el.options = [{ key: 'th', label: 'Thailand' }, { key: 'tw', label: 'Taiwan' }];
22
+ * el.addEventListener('baht-change', (e) => (draft.country = e.detail.value));
23
+ * el.addEventListener('baht-select', (e) => (draft.countryCode = e.detail.option.key));
24
+ *
25
+ * ARIA: APG editable combobox with list autocomplete — the input is the
26
+ * combobox, `aria-activedescendant` walks the listbox, Escape closes, Enter
27
+ * picks. Unlike <baht-reference-picker> the input is always editable and the
28
+ * text itself is a valid value; unlike <baht-select> the list is a filter of
29
+ * what was typed, not a fixed menu.
30
+ * @fires {CustomEvent<{ value: string; option: TypeaheadOption | null }>} baht-change - The text or the picked option changed.
31
+ * @fires {CustomEvent<{ option: TypeaheadOption }>} baht-select - An option was picked.
32
+ */
33
+ export declare class BahtTypeahead extends BahtElement {
34
+ constructor();
35
+ /** Accessible name (also the listbox name). */
36
+ label: string;
37
+ /** The text. Controlled: re-feed after `baht-change` (or don't — the input keeps what was typed). */
38
+ value: string;
39
+ placeholder: string;
40
+ disabled: boolean;
41
+ /** Marks the control invalid (styles + aria-invalid). */
42
+ invalid: boolean;
43
+ /** Static suggestion list, filtered client-side. Ignored when `fetcher` is set. */
44
+ options: TypeaheadOption[];
45
+ /** Async suggestions: term in, options out. Errors show as "no matches". */
46
+ fetcher: ((term: string) => Promise<TypeaheadOption[]>) | null;
47
+ /** Quiet time (ms) before the host hears the text and suggestions are (re)computed. */
48
+ debounce: number;
49
+ /** Characters typed before suggestions appear (0 = suggest on focus/arrow too). */
50
+ minChars: number;
51
+ /** Cap on suggestions shown. */
52
+ maxItems: number;
53
+ /** false = the text must be a picked option; blur reverts otherwise. */
54
+ freeText: boolean;
55
+ /** HTML autocomplete token forwarded to the input ('off' keeps the browser's own list away). */
56
+ autocomplete: string;
57
+ private term;
58
+ private open;
59
+ private results;
60
+ private loading;
61
+ private activeIndex;
62
+ private inputEl;
63
+ private readonly combo;
64
+ /** The text currently IS this picked option (null once the user types again). */
65
+ private picked;
66
+ /** Most recent pick ever — what `free-text="false"` reverts to on blur. */
67
+ private lastPicked;
68
+ private get inputId();
69
+ private get listboxId();
70
+ private optionId;
71
+ protected willUpdate(changed: PropertyValues<this>): void;
72
+ protected updated(): void;
73
+ private filterStatic;
74
+ private suggest;
75
+ private highlight;
76
+ private listen;
77
+ private close;
78
+ private emitChange;
79
+ private onInput;
80
+ /** Hand pending text to the host now (blur, Enter). */
81
+ private flush;
82
+ private pick;
83
+ private onBlur;
84
+ private moveActive;
85
+ private onKeydown;
86
+ protected render(): TemplateResult;
87
+ }
88
+ declare global {
89
+ interface HTMLElementTagNameMap {
90
+ 'baht-typeahead': BahtTypeahead;
91
+ }
92
+ }
@@ -0,0 +1,258 @@
1
+ import { nothing as p, html as u } from "lit";
2
+ import { t as d } from "@20baht/engine";
3
+ import { live as m } from "lit/directives/live.js";
4
+ import { property as l, state as c, query as b } from "lit/decorators.js";
5
+ import { boolOff as f, BahtElement as v } from "../base.js";
6
+ import { scrollOptionIntoView as y } from "./listbox.js";
7
+ import { ComboboxController as x } from "../combobox-controller.js";
8
+ import { customElement as g } from "../define.js";
9
+ import { floatPanel as I } from "../floating.js";
10
+ var $ = Object.defineProperty, w = Object.getOwnPropertyDescriptor, s = (t, e, o, a) => {
11
+ for (var h = a > 1 ? void 0 : a ? w(e, o) : e, r = t.length - 1, n; r >= 0; r--)
12
+ (n = t[r]) && (h = (a ? n(e, o, h) : n(h)) || h);
13
+ return a && h && $(e, o, h), h;
14
+ };
15
+ let i = class extends v {
16
+ constructor() {
17
+ super(), this.label = "Search", this.value = "", this.placeholder = "", this.disabled = !1, this.invalid = !1, this.options = [], this.fetcher = null, this.debounce = 150, this.minChars = 1, this.maxItems = 8, this.freeText = !0, this.autocomplete = "off", this.term = "", this.open = !1, this.results = [], this.loading = !1, this.activeIndex = -1, this.combo = new x(this, {
18
+ onOutside: () => {
19
+ this.close();
20
+ }
21
+ }), this.picked = null, this.lastPicked = null, I(this, { panel: ".baht-typeahead-list", fit: !0, gap: 2 });
22
+ }
23
+ get inputId() {
24
+ return `baht-typeahead-${this.uid}`;
25
+ }
26
+ get listboxId() {
27
+ return `${this.inputId}-list`;
28
+ }
29
+ optionId(t) {
30
+ return `${this.listboxId}-${t}`;
31
+ }
32
+ willUpdate(t) {
33
+ super.willUpdate(t), t.has("value") && !this.combo.pending && (this.term = this.value);
34
+ }
35
+ updated() {
36
+ y(this, this.open, this.activeIndex, this.optionId(this.activeIndex));
37
+ }
38
+ // ---- suggestions -----------------------------------------------------
39
+ filterStatic(t) {
40
+ var h;
41
+ const e = t.trim().toLowerCase();
42
+ if (!e) return this.options.slice(0, this.maxItems);
43
+ const o = [], a = [];
44
+ for (const r of this.options) {
45
+ const n = r.label.toLowerCase();
46
+ n.startsWith(e) ? o.push(r) : (n.includes(e) || (h = r.sub) != null && h.toLowerCase().includes(e)) && a.push(r);
47
+ }
48
+ return [...o, ...a].slice(0, this.maxItems);
49
+ }
50
+ async suggest(t) {
51
+ if (t.length < this.minChars) {
52
+ this.results = [], this.loading = !1, this.close();
53
+ return;
54
+ }
55
+ if (!this.fetcher) {
56
+ this.results = this.filterStatic(t), this.activeIndex = -1, this.open = !0, this.listen();
57
+ return;
58
+ }
59
+ const e = this.combo.begin();
60
+ this.loading = !0, this.open = !0, this.listen();
61
+ try {
62
+ const o = await this.fetcher(t);
63
+ this.combo.isCurrent(e) && (this.results = o.slice(0, this.maxItems));
64
+ } catch {
65
+ this.combo.isCurrent(e) && (this.results = []);
66
+ } finally {
67
+ this.combo.isCurrent(e) && (this.loading = !1, this.activeIndex = -1);
68
+ }
69
+ }
70
+ highlight(t) {
71
+ this.activeIndex !== t && (this.activeIndex = t);
72
+ }
73
+ listen() {
74
+ this.combo.watchOutside();
75
+ }
76
+ close() {
77
+ this.combo.unwatchOutside(), this.open && (this.open = !1, this.activeIndex = -1);
78
+ }
79
+ // ---- events ------------------------------------------------------------
80
+ emitChange(t, e) {
81
+ this.emit("baht-change", { value: t, option: e });
82
+ }
83
+ onInput(t) {
84
+ this.term = t.target.value, this.picked = null, this.combo.schedule(
85
+ () => {
86
+ this.emitChange(this.term, null), this.suggest(this.term);
87
+ },
88
+ Math.max(0, this.debounce)
89
+ );
90
+ }
91
+ /** Hand pending text to the host now (blur, Enter). */
92
+ flush() {
93
+ this.combo.pending && (this.combo.cancel(), this.emitChange(this.term, null));
94
+ }
95
+ pick(t) {
96
+ this.combo.cancel(), this.picked = t, this.lastPicked = t, this.term = t.label, this.close(), this.emitChange(t.label, t), this.emit("baht-select", { option: t });
97
+ }
98
+ onBlur() {
99
+ if (!this.freeText && !this.picked) {
100
+ this.combo.cancel();
101
+ const t = this.lastPicked;
102
+ this.term = (t == null ? void 0 : t.label) ?? "", this.picked = t, this.value !== this.term && this.emitChange(this.term, t);
103
+ return;
104
+ }
105
+ this.flush();
106
+ }
107
+ moveActive(t) {
108
+ const e = this.combo.nextActive(t, this.activeIndex, this.results.length, { wrap: !0 });
109
+ e !== void 0 && (this.activeIndex = e);
110
+ }
111
+ onKeydown(t) {
112
+ switch (t.key) {
113
+ case "ArrowDown":
114
+ if (t.preventDefault(), !this.open) {
115
+ this.suggest(this.term);
116
+ return;
117
+ }
118
+ this.moveActive(t.key);
119
+ break;
120
+ case "ArrowUp":
121
+ t.preventDefault(), this.open && this.moveActive(t.key);
122
+ break;
123
+ case "Enter": {
124
+ const e = this.open ? this.results[this.activeIndex] : void 0;
125
+ e ? (t.preventDefault(), this.pick(e)) : (this.flush(), this.close());
126
+ break;
127
+ }
128
+ case "Escape":
129
+ this.open && (t.preventDefault(), this.close());
130
+ break;
131
+ case "Tab":
132
+ this.flush(), this.close();
133
+ break;
134
+ }
135
+ }
136
+ render() {
137
+ const t = this.open, e = !this.loading && this.results.length === 0;
138
+ return u`<div class="baht-typeahead${this.open ? " baht-typeahead--open" : ""}">
139
+ <input
140
+ class="baht-control baht-typeahead-input"
141
+ id=${this.inputId}
142
+ type="text"
143
+ role="combobox"
144
+ aria-label=${this.label}
145
+ aria-autocomplete="list"
146
+ aria-expanded=${t ? "true" : "false"}
147
+ aria-controls=${this.listboxId}
148
+ aria-activedescendant=${t && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : p}
149
+ aria-invalid=${this.invalid ? "true" : p}
150
+ autocomplete=${this.autocomplete}
151
+ placeholder=${this.placeholder || p}
152
+ .value=${m(this.term)}
153
+ ?disabled=${this.disabled}
154
+ @input=${(o) => {
155
+ this.onInput(o);
156
+ }}
157
+ @keydown=${(o) => {
158
+ this.onKeydown(o);
159
+ }}
160
+ @blur=${() => {
161
+ this.onBlur();
162
+ }}
163
+ />
164
+ <div
165
+ class="baht-listbox baht-typeahead-list"
166
+ id=${this.listboxId}
167
+ role="listbox"
168
+ aria-label=${this.label}
169
+ aria-busy=${this.loading ? "true" : p}
170
+ ?hidden=${!t}
171
+ >
172
+ ${this.loading ? this.combo.note("baht-listbox-note", d("searching")) : e ? this.combo.note("baht-listbox-note", d("noMatches")) : this.results.map(
173
+ // eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox input (aria-activedescendant pattern)
174
+ (o, a) => u`<div
175
+ class="baht-listbox-option${a === this.activeIndex ? " baht-listbox-option--active" : ""}"
176
+ id=${this.optionId(a)}
177
+ role="option"
178
+ aria-selected=${a === this.activeIndex ? "true" : "false"}
179
+ data-key=${o.key}
180
+ @mousedown=${(h) => {
181
+ h.preventDefault();
182
+ }}
183
+ @mousemove=${() => {
184
+ this.highlight(a);
185
+ }}
186
+ @click=${() => {
187
+ var h;
188
+ this.pick(o), (h = this.inputEl) == null || h.focus();
189
+ }}
190
+ >
191
+ <span class="baht-listbox-option-label">${o.label}</span>
192
+ ${o.sub ? u`<span class="baht-listbox-option-sub">${o.sub}</span>` : p}
193
+ </div>`
194
+ )}
195
+ </div>
196
+ </div>`;
197
+ }
198
+ };
199
+ s([
200
+ l()
201
+ ], i.prototype, "label", 2);
202
+ s([
203
+ l()
204
+ ], i.prototype, "value", 2);
205
+ s([
206
+ l()
207
+ ], i.prototype, "placeholder", 2);
208
+ s([
209
+ l({ type: Boolean })
210
+ ], i.prototype, "disabled", 2);
211
+ s([
212
+ l({ type: Boolean })
213
+ ], i.prototype, "invalid", 2);
214
+ s([
215
+ l({ attribute: !1 })
216
+ ], i.prototype, "options", 2);
217
+ s([
218
+ l({ attribute: !1 })
219
+ ], i.prototype, "fetcher", 2);
220
+ s([
221
+ l({ type: Number })
222
+ ], i.prototype, "debounce", 2);
223
+ s([
224
+ l({ type: Number, attribute: "min-chars" })
225
+ ], i.prototype, "minChars", 2);
226
+ s([
227
+ l({ type: Number, attribute: "max-items" })
228
+ ], i.prototype, "maxItems", 2);
229
+ s([
230
+ l({ attribute: "free-text", converter: f })
231
+ ], i.prototype, "freeText", 2);
232
+ s([
233
+ l()
234
+ ], i.prototype, "autocomplete", 2);
235
+ s([
236
+ c()
237
+ ], i.prototype, "term", 2);
238
+ s([
239
+ c()
240
+ ], i.prototype, "open", 2);
241
+ s([
242
+ c()
243
+ ], i.prototype, "results", 2);
244
+ s([
245
+ c()
246
+ ], i.prototype, "loading", 2);
247
+ s([
248
+ c()
249
+ ], i.prototype, "activeIndex", 2);
250
+ s([
251
+ b("input")
252
+ ], i.prototype, "inputEl", 2);
253
+ i = s([
254
+ g("baht-typeahead")
255
+ ], i);
256
+ export {
257
+ i as BahtTypeahead
258
+ };
@@ -0,0 +1,108 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ import { UploadedFile } from '@20baht/engine';
4
+ export interface UploadChangeDetail {
5
+ /** The stored URL(s): a string, `string[]` when `multiple`, `null` when empty. */
6
+ value: string | string[] | null;
7
+ /** One entry per URL in `value`, with what is known about the file behind it. */
8
+ files: UploadedFile[];
9
+ }
10
+ export interface UploadProgressDetail {
11
+ file: File;
12
+ loaded: number;
13
+ total: number;
14
+ percent: number;
15
+ }
16
+ export interface UploadErrorDetail {
17
+ file: File;
18
+ /** HTTP status, or 0 for a network failure / unusable body. */
19
+ status: number;
20
+ message: string;
21
+ }
22
+ /**
23
+ * File upload against an HTTP endpoint. Picking (or dropping) a file sends it **immediately**
24
+ * as `multipart/form-data` to `url`; the endpoint answers with where it stored the file and
25
+ * that URL becomes the value. Nothing waits for a form submit, and no host code is needed:
26
+ * the whole contract is attributes.
27
+ *
28
+ * <baht-upload url="/api/uploads" accept=".pdf,image/*" max-size="10485760"></baht-upload>
29
+ *
30
+ * Expected response: `2xx` with JSON `{ "url": "…" }` (change the key with `response-key`,
31
+ * dotted paths allowed) or a plain-text URL body. Anything else is an upload error the
32
+ * user can retry.
33
+ *
34
+ * el.addEventListener('baht-change', (e) => e.detail.value); // string | string[] | null
35
+ *
36
+ * Auth: set `headers` (property) and/or `with-credentials`. Progress: `baht-upload-progress`.
37
+ * Value is controlled the usual way — feed it back on `baht-change`, or pre-fill with the
38
+ * URLs already on record and the chips render from them.
39
+ * @fires {CustomEvent<UploadChangeDetail>} baht-change - The uploaded files changed.
40
+ * @fires {CustomEvent<{ file: File }>} baht-upload-start - A file started uploading.
41
+ * @fires {CustomEvent<UploadProgressDetail>} baht-upload-progress - Upload progress.
42
+ * @fires {CustomEvent<UploadErrorDetail>} baht-upload-error - An upload failed.
43
+ */
44
+ export declare class BahtUpload extends BahtElement {
45
+ /** Endpoint that receives the file and returns its stored URL. Required. */
46
+ url: string;
47
+ /** HTTP method for the upload request. */
48
+ method: string;
49
+ /** Form-data key the file is sent under. */
50
+ fieldName: string;
51
+ /** Where the stored URL lives in a JSON response (dotted path). Empty = the body itself. */
52
+ responseKey: string;
53
+ /** Extra request headers (e.g. Authorization). Property only. */
54
+ headers: Record<string, string>;
55
+ /** Send cookies on cross-origin requests. */
56
+ withCredentials: boolean;
57
+ /** Stored URL(s). `string`, `string[]` when `multiple`, or `null`. Property only. */
58
+ value: string | string[] | null;
59
+ /** Visible label. */
60
+ label: string;
61
+ /** Helper text under the control. Defaults to the accept / size limits when set. */
62
+ hint: string;
63
+ /** Native `accept` filter (`.pdf,image/*`). */
64
+ accept?: string;
65
+ /** Allow several files; the value becomes an array. */
66
+ multiple: boolean;
67
+ /** Reject files over this many bytes before sending. */
68
+ maxSize?: number;
69
+ disabled: boolean;
70
+ required: boolean;
71
+ /** Validation message to display (marks the control invalid). */
72
+ error: string | null;
73
+ private pending;
74
+ private rejectedNames;
75
+ private dragging;
76
+ /** What is known about each stored URL (from the upload that produced it). */
77
+ private known;
78
+ private seq;
79
+ /** The request behind each pending entry, so a replaced or removed one can be aborted. */
80
+ private readonly requests;
81
+ private get urls();
82
+ private get inputId();
83
+ private fileFor;
84
+ /** Empty the value (does not delete anything on the server). */
85
+ clear(): void;
86
+ private emitValue;
87
+ private accept_;
88
+ private onPick;
89
+ private readonly onDragOver;
90
+ private readonly onDragLeave;
91
+ private readonly onDrop;
92
+ private start;
93
+ private patch;
94
+ private abort;
95
+ private abortAll;
96
+ disconnectedCallback(): void;
97
+ private send;
98
+ private failed;
99
+ private retry;
100
+ private dismiss;
101
+ private defaultHint;
102
+ protected render(): TemplateResult;
103
+ private renderLabel;
104
+ private renderList;
105
+ private renderRejected;
106
+ private renderStored;
107
+ private renderPending;
108
+ }