@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 { LitElement, PropertyValues, RenderOptions } from 'lit';
2
+ /**
3
+ * `String(value)` for a value of unknown shape (field values, row cells, JSON data).
4
+ * Primitives read as usual; anything else keeps `String()`'s own behaviour so display
5
+ * never changes with the type — one funnel instead of a `no-base-to-string` at each use.
6
+ */
7
+ /**
8
+ * Runtime guards for rich props. The TS type says `T[]` / `Record`, but hosts assign
9
+ * from JSON (`el.markers = json.markers`) and JS hosts pass `undefined` freely, so
10
+ * every read goes through here instead of a `?? []` that the type-aware lint would
11
+ * (rightly, for TS callers) flag as unnecessary.
12
+ */
13
+ export declare function arr<T>(value: T[] | null | undefined): T[];
14
+ export declare function obj<T extends object>(value: T | null | undefined): T | Record<string, never>;
15
+ export { sameData } from '@20baht/engine';
16
+ export declare function stringOf(value: unknown): string;
17
+ /**
18
+ * True when a real DOM is present. Lit's own `isServer` is hard-coded to `true` in its
19
+ * node build, which jsdom/happy-dom test runners also load, so guards that need "is there
20
+ * a document to touch" feature-detect instead: the @lit-labs/ssr dom shim has no
21
+ * `querySelector`.
22
+ */
23
+ export declare function hasDom(): boolean;
24
+ /**
25
+ * Attribute converter for booleans that DEFAULT TO TRUE. Lit's own `type: Boolean` reads
26
+ * `show-close="false"` as true (presence is all it checks), so a default-true switch could
27
+ * never be turned off from HTML. With this: absent = default, bare = true, `="false"` = false.
28
+ *
29
+ * @property({ attribute: 'show-close', converter: boolOff }) showClose = true;
30
+ */
31
+ export declare const boolOff: {
32
+ fromAttribute: (value: string | null) => boolean;
33
+ toAttribute: (value: boolean) => string | null;
34
+ };
35
+ /** Signature of the light-DOM hydrate function installed by `@20baht/ui/hydrate`. */
36
+ export type BahtHydrate = (value: unknown, host: HTMLElement, options?: RenderOptions) => void;
37
+ /**
38
+ * While a parent hydrates, the hydrate module parks each nested `baht-*` child's server
39
+ * markup under this key so the parent's hydration walk does not see the child's part
40
+ * markers. `hasSsrMarkup` treats a parked stash as "still server-rendered".
41
+ */
42
+ export declare const SSR_STASH: unique symbol;
43
+ /** True while the element's light DOM still holds un-hydrated server-rendered Lit markup. */
44
+ export declare function hasSsrMarkup(host: Element): boolean;
45
+ /** Light-DOM Lit base: consumer CSS reaches every internal node (spec 01 §6). */
46
+ export declare class BahtElement extends LitElement {
47
+ /**
48
+ * Per-instance sequence for unique DOM ids (`for`/`id`/`aria-*` pairs). Stays `0` for the
49
+ * server render and for the client's hydrating render so both produce identical markup.
50
+ * The number is allocated at the first update — not in `connectedCallback`, which the
51
+ * HTML parser can fire before the server-rendered children exist: plain client-side
52
+ * mounts get it just before their first render (single render, as before), hydrated
53
+ * ones right after hydration (one extra render that rewrites the ids).
54
+ */
55
+ protected uid: number;
56
+ protected createRenderRoot(): HTMLElement;
57
+ static get observedAttributes(): string[];
58
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
59
+ connectedCallback(): void;
60
+ disconnectedCallback(): void;
61
+ private childWatch;
62
+ /**
63
+ * Move the host's author children into their places in the rendered markup. Runs after
64
+ * every render and when children are added to the host later; must be safe to repeat.
65
+ * Elements without children of their own leave it unset.
66
+ */
67
+ protected adoptChildren?(): void;
68
+ private watchChildren;
69
+ protected update(changed: PropertyValues): void;
70
+ /** Dispatch a bubbling, composed CustomEvent — crosses any light/shadow DOM boundary. */
71
+ protected emit(name: string, detail?: unknown): void;
72
+ }
73
+ /**
74
+ * Light DOM has no <slot>. Call from an element's `adoptChildren()` to move author-supplied
75
+ * children into `slot`: everything that isn't the rendered `root` or a Lit comment marker.
76
+ * Safe to repeat. (During HTML parsing children can land after connectedCallback fires, so
77
+ * sweeping at render, and again when children arrive, is the reliable point.)
78
+ */
79
+ export declare function adoptLightChildren(host: HTMLElement, slot: HTMLElement): void;
80
+ /**
81
+ * Sends the host's children to their places: one with `data-slot="<name>"` to that slot, the rest to
82
+ * `fallback`. Call it from an element's `adoptChildren()`, which runs after every render and when a
83
+ * framework host adds children later.
84
+ */
85
+ export declare function adoptSlotted(host: HTMLElement, fallback: HTMLElement, slots: Record<string, HTMLElement>): void;
86
+ /** True when a slot holds an element or non-blank text, so it is worth showing. */
87
+ export declare function hasSlotted(slot: Element): boolean;
88
+ /**
89
+ * A press on a link that a router may want: fires a cancelable event, and if the host cancels it the
90
+ * browser stays put. A press with a modifier key is left to the browser (new tab and so on).
91
+ */
92
+ export declare function routeClick(host: HTMLElement, name: string, e: MouseEvent, detail: unknown): void;
@@ -0,0 +1,138 @@
1
+ import { LitElement as c, ReactiveElement as h } from "lit";
2
+ import { sameData as k } from "@20baht/engine";
3
+ function b(e) {
4
+ return e ?? [];
5
+ }
6
+ function m(e) {
7
+ return e ?? {};
8
+ }
9
+ function y(e) {
10
+ return e == null ? "" : typeof e == "string" ? e : String(e);
11
+ }
12
+ function d() {
13
+ return typeof document < "u" && "querySelector" in document;
14
+ }
15
+ const C = {
16
+ fromAttribute: (e) => e !== "false",
17
+ // null (absent) = default
18
+ toAttribute: (e) => e ? "" : "false"
19
+ }, u = Symbol.for("bahtui.ssrStash");
20
+ function l(e) {
21
+ if (e[u]) return !0;
22
+ const t = e.firstChild;
23
+ return (t == null ? void 0 : t.nodeType) === 8 && t.data.startsWith("lit-part");
24
+ }
25
+ function p(e) {
26
+ let t = e.firstChild;
27
+ if ((t == null ? void 0 : t.nodeType) !== 8 || !t.data.startsWith("lit-part")) return;
28
+ let i = 0;
29
+ for (; t; ) {
30
+ const r = t.nextSibling;
31
+ if (t.nodeType === 8) {
32
+ const n = t.data;
33
+ n.startsWith("lit-part") ? i += 1 : n.startsWith("/lit-part") && (i -= 1);
34
+ }
35
+ if (t.remove(), i === 0) break;
36
+ t = r;
37
+ }
38
+ }
39
+ let a = 0;
40
+ class N extends c {
41
+ constructor() {
42
+ super(...arguments), this.uid = 0, this.childWatch = null;
43
+ }
44
+ createRenderRoot() {
45
+ return this;
46
+ }
47
+ /*
48
+ * `defer-hydration` protocol (same contract as @lit-labs/ssr-client's
49
+ * lit-element-hydrate-support): a server-rendered element nested inside another
50
+ * carries the attribute and must not render until its host has hydrated and set its
51
+ * properties; the host's hydration removes the attribute. Implemented here so the
52
+ * library's own elements honour it regardless of the order `lit` was first imported —
53
+ * hydrate-support can only patch LitElement if it loads before lit-element does.
54
+ */
55
+ static get observedAttributes() {
56
+ return [...super.observedAttributes, "defer-hydration"];
57
+ }
58
+ attributeChangedCallback(t, i, r) {
59
+ if (t === "defer-hydration") {
60
+ r === null && this.isConnected && (super.connectedCallback(), this.watchChildren());
61
+ return;
62
+ }
63
+ super.attributeChangedCallback(t, i, r);
64
+ }
65
+ connectedCallback() {
66
+ this.hasAttribute("defer-hydration") || (super.connectedCallback(), this.watchChildren());
67
+ }
68
+ disconnectedCallback() {
69
+ var t;
70
+ (t = this.childWatch) == null || t.disconnect(), this.childWatch = null, super.disconnectedCallback();
71
+ }
72
+ watchChildren() {
73
+ !this.adoptChildren || this.childWatch || !d() || typeof MutationObserver > "u" || (this.childWatch = new MutationObserver((t) => {
74
+ var r;
75
+ t.some(
76
+ (n) => Array.from(n.addedNodes).some((o) => o.nodeType !== Node.COMMENT_NODE)
77
+ ) && this.hasUpdated && ((r = this.adoptChildren) == null || r.call(this));
78
+ }), this.childWatch.observe(this, { childList: !0 }));
79
+ }
80
+ update(t) {
81
+ var o;
82
+ const i = !this.hasUpdated, r = globalThis.bahtHydrate, n = i && d() && l(this);
83
+ if (n)
84
+ if (r) {
85
+ const s = this.render();
86
+ this.renderOptions.isConnected = this.isConnected, h.prototype.update.call(this, t), r(s, this, this.renderOptions);
87
+ } else
88
+ p(this), super.update(t);
89
+ else
90
+ i && d() && this.uid === 0 && (this.uid = ++a), super.update(t);
91
+ d() && ((o = this.adoptChildren) == null || o.call(this)), n && this.uid === 0 && (this.uid = ++a, this.requestUpdate());
92
+ }
93
+ /** Dispatch a bubbling, composed CustomEvent — crosses any light/shadow DOM boundary. */
94
+ emit(t, i) {
95
+ this.dispatchEvent(new CustomEvent(t, { detail: i, bubbles: !0, composed: !0 }));
96
+ }
97
+ }
98
+ function E(e, t) {
99
+ let i = t;
100
+ for (; i.parentNode && i.parentNode !== e; ) i = i.parentNode;
101
+ const r = Array.from(e.childNodes).filter(
102
+ (n) => n !== i && n.nodeType !== Node.COMMENT_NODE
103
+ );
104
+ r.length > 0 && t.append(...r);
105
+ }
106
+ function S(e, t, i) {
107
+ let r = t;
108
+ for (; r.parentNode && r.parentNode !== e; ) r = r.parentNode;
109
+ for (const n of Array.from(e.childNodes)) {
110
+ if (n === r || n.nodeType === Node.COMMENT_NODE) continue;
111
+ const o = n instanceof HTMLElement ? n.dataset.slot : void 0, s = o !== void 0 && Object.hasOwn(i, o) ? i[o] : t;
112
+ s == null || s.append(n);
113
+ }
114
+ }
115
+ function O(e) {
116
+ return e.childElementCount > 0 || e.textContent.trim() !== "";
117
+ }
118
+ function g(e, t, i, r) {
119
+ if (i.button !== 0 || i.metaKey || i.ctrlKey || i.shiftKey || i.altKey) return;
120
+ e.dispatchEvent(
121
+ new CustomEvent(t, { detail: r, bubbles: !0, composed: !0, cancelable: !0 })
122
+ ) || i.preventDefault();
123
+ }
124
+ export {
125
+ N as BahtElement,
126
+ u as SSR_STASH,
127
+ E as adoptLightChildren,
128
+ S as adoptSlotted,
129
+ b as arr,
130
+ C as boolOff,
131
+ d as hasDom,
132
+ O as hasSlotted,
133
+ l as hasSsrMarkup,
134
+ m as obj,
135
+ g as routeClick,
136
+ k as sameData,
137
+ y as stringOf
138
+ };
@@ -0,0 +1,65 @@
1
+ import { ReactiveController, ReactiveControllerHost, TemplateResult } from 'lit';
2
+ type Host = ReactiveControllerHost & HTMLElement;
3
+ interface Options {
4
+ /** A mousedown landed outside the host while the controller was watching. */
5
+ onOutside: () => void;
6
+ }
7
+ /**
8
+ * Keys the combobox keyboard moves the highlight with. Home/End are left to the text caret in
9
+ * the typing comboboxes, so they only count where `homeEnd` is set (the select-only one).
10
+ */
11
+ export interface MoveOptions {
12
+ /** Past either end: wrap around (typing comboboxes) or stop at the end (select-only). */
13
+ wrap: boolean;
14
+ homeEnd?: boolean;
15
+ }
16
+ /**
17
+ * The part every list-popup element (`<baht-select>`, `<baht-typeahead>`, `<baht-tags>`,
18
+ * `<baht-reference-picker>`) wrote for itself, as a Lit controller in the style of
19
+ * `MenuController`:
20
+ *
21
+ * - the outside-mousedown listener: `watchOutside()` while the list is open, `unwatchOutside()`
22
+ * when it closes; it leaves with the element and comes back if an open element is moved;
23
+ * - a trailing debounce timer (`schedule` / `cancel` / `pending`);
24
+ * - a stale-response guard for async option fetches (`begin` / `isCurrent` / `invalidate`);
25
+ * - `nextActive`, the arrow-key movement of the highlighted option;
26
+ * - `note`, the non-selectable row ("Searching…", "No matches").
27
+ */
28
+ export declare class ComboboxController implements ReactiveController {
29
+ private readonly host;
30
+ private readonly opts;
31
+ private watching;
32
+ private attached;
33
+ private timer;
34
+ private seq;
35
+ constructor(host: Host, opts: Options);
36
+ hostConnected(): void;
37
+ hostDisconnected(): void;
38
+ private readonly onDocMousedown;
39
+ private attach;
40
+ private detach;
41
+ /** Start closing the list on a mousedown outside the host (idempotent). */
42
+ watchOutside(): void;
43
+ /** Stop watching (idempotent): the list closed. */
44
+ unwatchOutside(): void;
45
+ /** Run `fn` after `ms` of quiet; a newer call replaces it. */
46
+ schedule(fn: () => void, ms: number): void;
47
+ /** Drop the scheduled call, if any. */
48
+ cancel(): void;
49
+ /** A scheduled call is still waiting. */
50
+ get pending(): boolean;
51
+ /** Start a fetch: the number identifies it, and any earlier one is stale from now on. */
52
+ begin(): number;
53
+ /** The fetch numbered `seq` is still the latest (and nothing invalidated it). */
54
+ isCurrent(seq: number): boolean;
55
+ /** Whatever is in flight no longer matters (the list closed, the lookup changed). */
56
+ invalidate(): void;
57
+ /**
58
+ * Where the highlight goes for `key` from `active` over `count` options, or `undefined` when
59
+ * the key is not a movement key (or there is nothing to move over).
60
+ */
61
+ nextActive(key: string, active: number, count: number, opts: MoveOptions): number | undefined;
62
+ /** A row that is not an option: shown while searching or when nothing matched. */
63
+ note(className: string, text: string): TemplateResult;
64
+ }
65
+ export {};
@@ -0,0 +1,82 @@
1
+ import { html as h } from "lit";
2
+ import { hasDom as o } from "./base.js";
3
+ class c {
4
+ constructor(t, e) {
5
+ this.host = t, this.opts = e, this.watching = !1, this.attached = !1, this.seq = 0, this.onDocMousedown = (i) => {
6
+ (!(i.target instanceof Node) || !this.host.contains(i.target)) && this.opts.onOutside();
7
+ }, t.addController(this);
8
+ }
9
+ hostConnected() {
10
+ this.watching && this.attach();
11
+ }
12
+ hostDisconnected() {
13
+ this.detach(), this.cancel();
14
+ }
15
+ attach() {
16
+ this.attached || !o() || (this.attached = !0, document.addEventListener("mousedown", this.onDocMousedown));
17
+ }
18
+ detach() {
19
+ this.attached && (this.attached = !1, document.removeEventListener("mousedown", this.onDocMousedown));
20
+ }
21
+ /** Start closing the list on a mousedown outside the host (idempotent). */
22
+ watchOutside() {
23
+ this.watching = !0, this.attach();
24
+ }
25
+ /** Stop watching (idempotent): the list closed. */
26
+ unwatchOutside() {
27
+ this.watching = !1, this.detach();
28
+ }
29
+ /** Run `fn` after `ms` of quiet; a newer call replaces it. */
30
+ schedule(t, e) {
31
+ clearTimeout(this.timer), this.timer = setTimeout(() => {
32
+ this.timer = void 0, t();
33
+ }, e);
34
+ }
35
+ /** Drop the scheduled call, if any. */
36
+ cancel() {
37
+ clearTimeout(this.timer), this.timer = void 0;
38
+ }
39
+ /** A scheduled call is still waiting. */
40
+ get pending() {
41
+ return this.timer !== void 0;
42
+ }
43
+ /** Start a fetch: the number identifies it, and any earlier one is stale from now on. */
44
+ begin() {
45
+ return ++this.seq;
46
+ }
47
+ /** The fetch numbered `seq` is still the latest (and nothing invalidated it). */
48
+ isCurrent(t) {
49
+ return t === this.seq;
50
+ }
51
+ /** Whatever is in flight no longer matters (the list closed, the lookup changed). */
52
+ invalidate() {
53
+ this.seq++;
54
+ }
55
+ /**
56
+ * Where the highlight goes for `key` from `active` over `count` options, or `undefined` when
57
+ * the key is not a movement key (or there is nothing to move over).
58
+ */
59
+ nextActive(t, e, i, s) {
60
+ if (i <= 0) return;
61
+ const r = i - 1;
62
+ switch (t) {
63
+ case "ArrowDown":
64
+ return s.wrap ? (e + 1) % i : Math.min(r, e + 1);
65
+ case "ArrowUp":
66
+ return s.wrap ? (e - 1 + i) % i : Math.max(0, e - 1);
67
+ case "Home":
68
+ return s.homeEnd ? 0 : void 0;
69
+ case "End":
70
+ return s.homeEnd ? r : void 0;
71
+ default:
72
+ return;
73
+ }
74
+ }
75
+ /** A row that is not an option: shown while searching or when nothing matched. */
76
+ note(t, e) {
77
+ return h`<div class=${t} role="option" aria-disabled="true" aria-selected="false">${e}</div>`;
78
+ }
79
+ }
80
+ export {
81
+ c as ComboboxController
82
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Lit's `@customElement`, tolerating a tag being defined already. Module
3
+ * federation or a duplicated dependency can load two copies of @20baht/ui
4
+ * into one page; the second copy keeps the first definition and warns
5
+ * instead of throwing from `customElements.define`.
6
+ */
7
+ export declare function customElement(tag: string): (cls: CustomElementConstructor) => void;
@@ -0,0 +1,16 @@
1
+ const i = "0.1.0";
2
+ function o(e) {
3
+ return (n) => {
4
+ const t = customElements.get(e);
5
+ if (t) {
6
+ t !== n && console.warn(
7
+ `[bahtui] <${e}> is already defined (@20baht/ui ${t.bahtVersion ?? "unknown"}); skipping the copy from @20baht/ui ${i}`
8
+ );
9
+ return;
10
+ }
11
+ Object.defineProperty(n, "bahtVersion", { value: i }), customElements.define(e, n);
12
+ };
13
+ }
14
+ export {
15
+ o as customElement
16
+ };
@@ -0,0 +1,84 @@
1
+ import { nothing, PropertyValues, TemplateResult } from 'lit';
2
+ import { FieldDescriptor } from '@20baht/engine';
3
+ import { BahtElement } from './base.js';
4
+ /**
5
+ * Shared shape of every field primitive: descriptor + value in, `baht-input` out.
6
+ * Dumb and controlled — never mutates its own `value` prop; the host re-feeds it.
7
+ *
8
+ * `controlId` carries the base class `uid`: the same field key renders once per repeater
9
+ * row (and can repeat across forms on one page), so key-only ids collide — worst for
10
+ * radios, whose shared native `name` merges groups.
11
+ * @fires {CustomEvent<{ key: string; value: unknown }>} baht-input - Field mode: the user edited the value.
12
+ */
13
+ export declare abstract class BahtFieldBase extends BahtElement {
14
+ /**
15
+ * Default trailing debounce (ms) for TYPED edits — text, email, password,
16
+ * textarea, number. Every keystroke otherwise re-runs the host's rules,
17
+ * validation and dependent-option fetches. Per element: the `debounce`
18
+ * property/attribute; `<baht-form options.inputDebounce>` sets it for a whole
19
+ * form. 0 = emit on every keystroke. Selects, checkboxes, radios, toggles,
20
+ * dates and files are never debounced — a pick is one event.
21
+ */
22
+ static defaultDebounce: number;
23
+ field: FieldDescriptor;
24
+ value: unknown;
25
+ disabled: boolean;
26
+ readonly: boolean;
27
+ required: boolean;
28
+ /** Append the localized "(optional)" marker to the label when not required (set by <baht-form show-optional>). */
29
+ showOptional: boolean;
30
+ error: string | null;
31
+ /** Debounce for typed edits (ms); unset = BahtFieldBase.defaultDebounce. */
32
+ debounce?: number;
33
+ /**
34
+ * The keystrokes not yet (or just) handed to the host. The control keeps
35
+ * rendering `typed.value` until the host's `value` moves, so a re-render
36
+ * mid-typing (a sibling field changing) can't snap the text back.
37
+ */
38
+ private typed;
39
+ private typedTimer;
40
+ private readonly onFocusOut;
41
+ connectedCallback(): void;
42
+ disconnectedCallback(): void;
43
+ protected willUpdate(changed: PropertyValues<this>): void;
44
+ protected get effectiveDebounce(): number;
45
+ /** A typed edit: emitted after `debounce` ms of quiet (or at once when 0). */
46
+ protected emitTyped(value: unknown): void;
47
+ /** Hand a pending typed edit to the host now (blur, disconnect, host reads). Idempotent. */
48
+ flushTyped(): void;
49
+ /**
50
+ * The host did not take the edit: forget the keystrokes and show `value` again. Without this
51
+ * a refused edit stays on screen, since `value` never moves to say the text has landed.
52
+ */
53
+ discardTyped(): void;
54
+ /** What a typed control shows: pending keystrokes win over a stale host value. */
55
+ protected get shownValue(): unknown;
56
+ /** `shownValue` as control text: `''` for null/undefined, `String()` otherwise. */
57
+ protected get shownText(): string;
58
+ /**
59
+ * `field` as the host may actually have left it: a framework can connect the element
60
+ * before it binds the descriptor, so internally it is optional until then.
61
+ */
62
+ protected get assignedField(): FieldDescriptor | undefined;
63
+ /** Emit the user's edit upward (composed so it crosses any boundary). */
64
+ protected emitInput(value: unknown): void;
65
+ protected abstract renderControl(): TemplateResult;
66
+ /** True when `field.icon` names a real icon — gates both the icon markup
67
+ * and the control's icon-padding class, so a typo/removed name never
68
+ * leaves the control indented for a glyph that isn't there. */
69
+ protected get hasFieldIcon(): boolean;
70
+ /** Leading icon for text/currency/textarea/dropdown controls (spec: field.icon). */
71
+ protected renderFieldIcon(): TemplateResult | typeof nothing;
72
+ protected renderLabel(): TemplateResult | typeof nothing;
73
+ /** Required asterisk, or the "(optional)" marker when the form asks for it. */
74
+ protected renderLabelMark(): TemplateResult | typeof nothing;
75
+ protected get controlId(): string;
76
+ protected get labelId(): string;
77
+ protected get errorId(): string;
78
+ protected get helpId(): string;
79
+ /** id list for the control's aria-describedby: error first, then help. */
80
+ protected get describedBy(): string | typeof nothing;
81
+ /** 'true' while the field is in error, else absent (styles hook on [aria-invalid]). */
82
+ protected get invalidAttr(): string | typeof nothing;
83
+ protected render(): TemplateResult | typeof nothing;
84
+ }
@@ -0,0 +1,152 @@
1
+ import { nothing as r, html as o } from "lit";
2
+ import { property as s } from "lit/decorators.js";
3
+ import { t as c } from "@20baht/engine";
4
+ import { isIconName as p, renderIcon as f } from "./primitives/icons.js";
5
+ import { BahtElement as y, stringOf as b } from "./base.js";
6
+ var m = Object.defineProperty, l = (h, e, i, v) => {
7
+ for (var d = void 0, a = h.length - 1, u; a >= 0; a--)
8
+ (u = h[a]) && (d = u(e, i, d) || d);
9
+ return d && m(e, i, d), d;
10
+ }, n;
11
+ const t = (n = class extends y {
12
+ constructor() {
13
+ super(...arguments), this.value = null, this.disabled = !1, this.readonly = !1, this.required = !1, this.showOptional = !1, this.error = null, this.typed = null, this.onFocusOut = () => {
14
+ this.flushTyped();
15
+ };
16
+ }
17
+ connectedCallback() {
18
+ super.connectedCallback(), this.addEventListener("focusout", this.onFocusOut);
19
+ }
20
+ disconnectedCallback() {
21
+ this.removeEventListener("focusout", this.onFocusOut), this.flushTyped(), super.disconnectedCallback();
22
+ }
23
+ willUpdate(e) {
24
+ var i;
25
+ super.willUpdate(e), e.has("value") && ((i = this.typed) != null && i.emitted) && (this.typed = null);
26
+ }
27
+ get effectiveDebounce() {
28
+ return this.debounce ?? n.defaultDebounce;
29
+ }
30
+ /** A typed edit: emitted after `debounce` ms of quiet (or at once when 0). */
31
+ emitTyped(e) {
32
+ const i = this.effectiveDebounce;
33
+ if (clearTimeout(this.typedTimer), i <= 0) {
34
+ this.typed = null, this.emitInput(e);
35
+ return;
36
+ }
37
+ this.typed = { value: e, emitted: !1 }, this.typedTimer = setTimeout(() => {
38
+ this.flushTyped();
39
+ }, i);
40
+ }
41
+ /** Hand a pending typed edit to the host now (blur, disconnect, host reads). Idempotent. */
42
+ flushTyped() {
43
+ clearTimeout(this.typedTimer), this.typedTimer = void 0, !(!this.typed || this.typed.emitted) && (this.typed.emitted = !0, this.emitInput(this.typed.value));
44
+ }
45
+ /**
46
+ * The host did not take the edit: forget the keystrokes and show `value` again. Without this
47
+ * a refused edit stays on screen, since `value` never moves to say the text has landed.
48
+ */
49
+ discardTyped() {
50
+ clearTimeout(this.typedTimer), this.typedTimer = void 0, this.typed = null, this.requestUpdate();
51
+ }
52
+ /** What a typed control shows: pending keystrokes win over a stale host value. */
53
+ get shownValue() {
54
+ return this.typed ? this.typed.value : this.value;
55
+ }
56
+ /** `shownValue` as control text: `''` for null/undefined, `String()` otherwise. */
57
+ get shownText() {
58
+ return b(this.shownValue);
59
+ }
60
+ /**
61
+ * `field` as the host may actually have left it: a framework can connect the element
62
+ * before it binds the descriptor, so internally it is optional until then.
63
+ */
64
+ get assignedField() {
65
+ return this.field;
66
+ }
67
+ /** Emit the user's edit upward (composed so it crosses any boundary). */
68
+ emitInput(e) {
69
+ this.emit("baht-input", { key: this.field.key, value: e });
70
+ }
71
+ /** True when `field.icon` names a real icon — gates both the icon markup
72
+ * and the control's icon-padding class, so a typo/removed name never
73
+ * leaves the control indented for a glyph that isn't there. */
74
+ get hasFieldIcon() {
75
+ const e = this.field.icon;
76
+ return e != null && p(e);
77
+ }
78
+ /** Leading icon for text/currency/textarea/dropdown controls (spec: field.icon). */
79
+ renderFieldIcon() {
80
+ const e = this.field.icon;
81
+ return e == null || !p(e) ? r : o`<span class="baht-field-icon" aria-hidden="true">${f(e)}</span>`;
82
+ }
83
+ renderLabel() {
84
+ return this.field.label ? o`<label class="baht-label" id=${this.labelId} for=${this.controlId}>
85
+ ${this.field.label}${this.renderLabelMark()}
86
+ </label>` : r;
87
+ }
88
+ /** Required asterisk, or the "(optional)" marker when the form asks for it. */
89
+ renderLabelMark() {
90
+ return this.required ? o`<span class="baht-required-mark" aria-hidden="true">*</span>` : this.showOptional ? o`<span class="baht-optional">${c("optional")}</span>` : r;
91
+ }
92
+ get controlId() {
93
+ var e;
94
+ return `baht-${((e = this.assignedField) == null ? void 0 : e.key) ?? ""}-${this.uid}`;
95
+ }
96
+ get labelId() {
97
+ return `${this.controlId}-label`;
98
+ }
99
+ get errorId() {
100
+ return `${this.controlId}-error`;
101
+ }
102
+ get helpId() {
103
+ return `${this.controlId}-help`;
104
+ }
105
+ /** id list for the control's aria-describedby: error first, then help. */
106
+ get describedBy() {
107
+ const e = [this.error ? this.errorId : "", this.field.help ? this.helpId : ""].filter(
108
+ Boolean
109
+ );
110
+ return e.length > 0 ? e.join(" ") : r;
111
+ }
112
+ /** 'true' while the field is in error, else absent (styles hook on [aria-invalid]). */
113
+ get invalidAttr() {
114
+ return this.error ? "true" : r;
115
+ }
116
+ render() {
117
+ return this.assignedField ? o`
118
+ ${this.renderLabel()}
119
+ ${this.renderControl()}
120
+ ${this.field.help ? o`<div class="baht-help" id=${this.helpId}>${this.field.help}</div>` : r}
121
+ ${this.error ? o`<div class="baht-error" id=${this.errorId} role="alert">${this.error}</div>` : r}
122
+ ` : r;
123
+ }
124
+ }, n.defaultDebounce = 150, n);
125
+ l([
126
+ s({ attribute: !1 })
127
+ ], t.prototype, "field");
128
+ l([
129
+ s({ attribute: !1 })
130
+ ], t.prototype, "value");
131
+ l([
132
+ s({ type: Boolean })
133
+ ], t.prototype, "disabled");
134
+ l([
135
+ s({ type: Boolean })
136
+ ], t.prototype, "readonly");
137
+ l([
138
+ s({ type: Boolean })
139
+ ], t.prototype, "required");
140
+ l([
141
+ s({ type: Boolean, attribute: "show-optional" })
142
+ ], t.prototype, "showOptional");
143
+ l([
144
+ s({ attribute: !1 })
145
+ ], t.prototype, "error");
146
+ l([
147
+ s({ type: Number })
148
+ ], t.prototype, "debounce");
149
+ let k = t;
150
+ export {
151
+ k as BahtFieldBase
152
+ };