@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,84 @@
1
+ import { ReactiveControllerHost } from 'lit';
2
+ export interface Box {
3
+ top: number;
4
+ bottom: number;
5
+ left: number;
6
+ right: number;
7
+ }
8
+ export interface Placement {
9
+ top: number;
10
+ left: number;
11
+ /** The room on the chosen side: a taller panel is cut to this and scrolls. */
12
+ maxHeight: number;
13
+ }
14
+ /**
15
+ * Where a panel of `size` goes for an opener at `anchor` in a window of `view`: under the opener
16
+ * when it fits or when there is more room there, above it otherwise (`above` swaps the two). `end`
17
+ * lines the right edges up, otherwise the left ones. The panel never leaves the window.
18
+ */
19
+ export declare function place(anchor: Box, size: {
20
+ width: number;
21
+ height: number;
22
+ }, view: {
23
+ width: number;
24
+ height: number;
25
+ }, options?: {
26
+ end?: boolean;
27
+ above?: boolean | undefined;
28
+ gap?: number | undefined;
29
+ }): Placement;
30
+ interface Options {
31
+ /** Selector of the panel inside the host. It hangs from its parent element and is open while not `hidden`. */
32
+ panel: string;
33
+ /** A list is as wide as the control it hangs from; a menu keeps its own width. */
34
+ fit?: boolean;
35
+ /** Space between the opener and the panel. */
36
+ gap?: number;
37
+ /**
38
+ * Which corner the panel asks for: `end` lines up the end edges (left in RTL), `above` puts it
39
+ * over the opener when it fits. A menu reads `end` from `baht-menu--end` when this is not given.
40
+ */
41
+ where?: () => {
42
+ end?: boolean;
43
+ above?: boolean;
44
+ };
45
+ /** When the panel counts as open, if not "while it is not `hidden`" (flatpickr's calendar: `.open`). */
46
+ open?: (panel: HTMLElement) => boolean;
47
+ }
48
+ type Host = ReactiveControllerHost & HTMLElement;
49
+ /** Float the host's panel while it is open: see `FloatingController`. Call once, when the element is built. */
50
+ export declare function floatPanel(host: Host, options: Options): void;
51
+ export type Side = 'top' | 'bottom' | 'left' | 'right';
52
+ /**
53
+ * Where a tip of `size` goes on `side` of an opener at `anchor`: centred on the opener, moved to
54
+ * the other side when its own has no room and the other does, never past the window edge.
55
+ */
56
+ export declare function placeSide(anchor: Box, size: {
57
+ width: number;
58
+ height: number;
59
+ }, view: {
60
+ width: number;
61
+ height: number;
62
+ }, side: Side, gap?: number): {
63
+ top: number;
64
+ left: number;
65
+ side: Side;
66
+ };
67
+ /** Float the host's tooltip (`selector`) while its opener is pointed at or focused: see `TipController`. */
68
+ export declare function floatTip(host: Host, selector: string): void;
69
+ /** Keep the host's window-sized `layer` in the top layer while it shows: see `LayerController`. */
70
+ export declare function floatLayer(host: Host, opts: {
71
+ layer: string;
72
+ shown?: (el: HTMLElement) => boolean;
73
+ keepOnTop?: boolean;
74
+ }): void;
75
+ /**
76
+ * Pin a pointer tip (a chart's tooltip) at window point `x`, `y`, in the top layer so a card, a
77
+ * table or any `overflow` box around the chart cannot clip it. Its stylesheet's transform centres
78
+ * it above the point; it is kept inside the window across, and turned under the point when there
79
+ * is no room above.
80
+ */
81
+ export declare function pinTip(tip: HTMLElement, x: number, y: number): void;
82
+ /** Let a pinned tip go: see `pinTip`. */
83
+ export declare function unpinTip(tip: HTMLElement): void;
84
+ export {};
@@ -0,0 +1,182 @@
1
+ import { hasDom as w } from "./base.js";
2
+ const l = 8;
3
+ function x(e, t, o, i = {}) {
4
+ const n = i.gap ?? 4, s = o.height - e.bottom - n - l, r = e.top - n - l, p = i.above ? !(t.height <= r || r >= s) : t.height <= s || s >= r, h = Math.max(0, p ? s : r), f = Math.min(t.height, h), a = i.end ? e.right - t.width : e.left;
5
+ return {
6
+ top: p ? e.bottom + n : e.top - n - f,
7
+ left: Math.max(l, Math.min(a, o.width - t.width - l)),
8
+ maxHeight: h
9
+ };
10
+ }
11
+ let u = 0;
12
+ function d(e) {
13
+ if (typeof e.showPopover == "function") {
14
+ u++, e.setAttribute("popover", "manual");
15
+ try {
16
+ e.showPopover();
17
+ } catch {
18
+ e.removeAttribute("popover");
19
+ }
20
+ }
21
+ }
22
+ function m(e) {
23
+ if (e.hasAttribute("popover")) {
24
+ try {
25
+ e.hidePopover();
26
+ } catch {
27
+ }
28
+ e.removeAttribute("popover");
29
+ }
30
+ }
31
+ function v(e) {
32
+ m(e), e.removeAttribute("style");
33
+ }
34
+ function g(e, t) {
35
+ const o = t ? "addEventListener" : "removeEventListener";
36
+ window[o]("scroll", e, !0), window[o]("resize", e);
37
+ }
38
+ class y {
39
+ constructor(t, o) {
40
+ this.host = t, this.opts = o, this.panel = null, this.onMove = (i) => {
41
+ var n;
42
+ i.target instanceof Node && ((n = this.panel) != null && n.contains(i.target)) || (this.frame ?? (this.frame = requestAnimationFrame(() => {
43
+ this.frame = void 0, this.position();
44
+ })));
45
+ };
46
+ }
47
+ hostUpdated() {
48
+ var i, n;
49
+ if (!w()) return;
50
+ const t = this.host.querySelector(this.opts.panel), o = t && (((n = (i = this.opts).open) == null ? void 0 : n.call(i, t)) ?? !t.hidden) ? t : null;
51
+ o !== this.panel && (this.release(), o && this.attach(o)), this.position();
52
+ }
53
+ hostDisconnected() {
54
+ this.release();
55
+ }
56
+ attach(t) {
57
+ this.panel = t, d(t), g(this.onMove, !0);
58
+ }
59
+ release() {
60
+ const t = this.panel;
61
+ t && (this.panel = null, g(this.onMove, !1), this.frame !== void 0 && cancelAnimationFrame(this.frame), this.frame = void 0, v(t));
62
+ }
63
+ position() {
64
+ var a, c;
65
+ const t = this.panel, o = t == null ? void 0 : t.parentElement;
66
+ if (!t || !o) return;
67
+ const i = o.getBoundingClientRect();
68
+ t.style.cssText = `position:fixed;margin:0;${this.opts.fit ? `box-sizing:border-box;width:${String(i.width)}px;` : ""}`;
69
+ const n = getComputedStyle(t), s = n.minWidth.endsWith("%") ? `min-width:${String(i.width * parseFloat(n.minWidth) / 100)}px;` : "";
70
+ t.style.cssText += s;
71
+ const r = t.offsetHeight, { end: p = t.classList.contains("baht-menu--end"), above: h } = ((c = (a = this.opts).where) == null ? void 0 : c.call(a)) ?? {}, f = x(
72
+ i,
73
+ { width: t.offsetWidth, height: r },
74
+ { width: window.innerWidth, height: window.innerHeight },
75
+ { end: p !== (n.direction === "rtl"), above: h, gap: this.opts.gap }
76
+ );
77
+ t.style.cssText += `top:${String(f.top)}px;left:${String(f.left)}px;right:auto;bottom:auto;${r > f.maxHeight ? `max-height:${String(f.maxHeight)}px;overflow-y:auto;` : ""}`;
78
+ }
79
+ }
80
+ function C(e, t) {
81
+ e.addController(new y(e, t));
82
+ }
83
+ const M = { top: "bottom", bottom: "top", left: "right", right: "left" };
84
+ function S(e, t, o, i, n = 6) {
85
+ const s = {
86
+ top: e.top,
87
+ bottom: o.height - e.bottom,
88
+ left: e.left,
89
+ right: o.width - e.right
90
+ }, r = n + l + (i === "top" || i === "bottom" ? t.height : t.width), p = M[i], h = s[i] < r && s[p] >= r ? p : i, f = (a, c, b) => Math.max(l, Math.min(a, b - c - l));
91
+ return h === "top" || h === "bottom" ? {
92
+ top: h === "top" ? e.top - n - t.height : e.bottom + n,
93
+ left: f((e.left + e.right - t.width) / 2, t.width, o.width),
94
+ side: h
95
+ } : {
96
+ top: f((e.top + e.bottom - t.height) / 2, t.height, o.height),
97
+ left: h === "left" ? e.left - n - t.width : e.right + n,
98
+ side: h
99
+ };
100
+ }
101
+ class T {
102
+ constructor(t, o) {
103
+ this.host = t, this.selector = o, this.tip = null, this.opener = null, this.hovered = !1, this.focused = !1, this.floating = !1, this.onPoint = (i) => {
104
+ var n;
105
+ i.type === "mouseenter" || i.type === "mouseleave" ? this.hovered = i.type === "mouseenter" : i instanceof FocusEvent && i.relatedTarget instanceof Node && ((n = this.opener) != null && n.contains(i.relatedTarget)) || (this.focused = i.type === "focusin"), this.sync();
106
+ }, this.onMove = () => {
107
+ this.position();
108
+ };
109
+ }
110
+ hostUpdated() {
111
+ if (!w()) return;
112
+ const t = this.host.querySelector(this.selector);
113
+ (t !== this.tip || (t == null ? void 0 : t.parentElement) !== this.opener) && (this.bind(!1), this.tip = t, this.opener = (t == null ? void 0 : t.parentElement) ?? null, this.bind(!0)), this.floating && this.position();
114
+ }
115
+ hostDisconnected() {
116
+ this.bind(!1), this.tip = this.opener = null;
117
+ }
118
+ bind(t) {
119
+ t || (this.hovered = this.focused = !1, this.sync());
120
+ const o = this.opener;
121
+ if (!o) return;
122
+ const i = t ? "addEventListener" : "removeEventListener";
123
+ for (const n of ["mouseenter", "mouseleave", "focusin", "focusout"])
124
+ o[i](n, this.onPoint);
125
+ }
126
+ sync() {
127
+ const t = this.tip, o = (this.hovered || this.focused) && !!t;
128
+ o !== this.floating && t && (this.floating = o, o ? d(t) : v(t), g(this.onMove, o)), o && this.position();
129
+ }
130
+ position() {
131
+ var s;
132
+ const { tip: t, opener: o } = this;
133
+ if (!t || !o) return;
134
+ t.style.cssText = "position:fixed;margin:0;inset:auto;transform:none;border:0;overflow:visible;";
135
+ const i = (s = /baht-tooltip--(top|bottom|left|right)/.exec(t.className)) == null ? void 0 : s[1], n = S(
136
+ o.getBoundingClientRect(),
137
+ { width: t.offsetWidth, height: t.offsetHeight },
138
+ { width: window.innerWidth, height: window.innerHeight },
139
+ i ?? "top"
140
+ );
141
+ t.style.cssText += `top:${String(n.top)}px;left:${String(n.left)}px;`;
142
+ }
143
+ }
144
+ function W(e, t) {
145
+ e.addController(new T(e, t));
146
+ }
147
+ class $ {
148
+ constructor(t, o) {
149
+ this.host = t, this.opts = o, this.el = null, this.at = -1;
150
+ }
151
+ hostUpdated() {
152
+ var i, n;
153
+ if (!w()) return;
154
+ const t = this.host.querySelector(this.opts.layer), o = t && (((n = (i = this.opts).shown) == null ? void 0 : n.call(i, t)) ?? !0) ? t : null;
155
+ o !== this.el && this.hostDisconnected(), o && (this.el && !(this.opts.keepOnTop && this.at !== u) || (m(o), d(o), this.el = o, this.at = u));
156
+ }
157
+ hostDisconnected() {
158
+ this.el && m(this.el), this.el = null;
159
+ }
160
+ }
161
+ function A(e, t) {
162
+ e.addController(new $(e, t));
163
+ }
164
+ function H(e, t, o) {
165
+ e.hasAttribute("popover") || d(e);
166
+ const i = e.offsetWidth / 2, n = Math.max(l + i, Math.min(t, window.innerWidth - l - i)), s = o - e.offsetHeight * 1.25 < l ? "transform:translate(-50%,25%);" : "";
167
+ e.style.cssText = `position:fixed;margin:0;inset:auto;border:0;overflow:visible;left:${String(
168
+ Math.round(n)
169
+ )}px;top:${String(Math.round(o))}px;${s}`;
170
+ }
171
+ function P(e) {
172
+ v(e);
173
+ }
174
+ export {
175
+ A as floatLayer,
176
+ C as floatPanel,
177
+ W as floatTip,
178
+ H as pinTip,
179
+ x as place,
180
+ S as placeSide,
181
+ P as unpinTip
182
+ };
@@ -0,0 +1,39 @@
1
+ import { nothing } from 'lit';
2
+ import { FieldDescriptor } from '@20baht/engine';
3
+ /** Where each field of a `<baht-form>` sits: its tab, its fold and, in two columns, its grid row. */
4
+ export interface TabLayout {
5
+ /** The first tab section: the strip renders in its place. */
6
+ first: string | undefined;
7
+ /** Field key → the tab section it sits in. */
8
+ owner: Map<string, string>;
9
+ /** The tabs with a visible field. */
10
+ showing: {
11
+ key: string;
12
+ label: string;
13
+ }[];
14
+ open: string | undefined;
15
+ /** Field key -> the collapsible section it sits under. */
16
+ section: Map<string, string>;
17
+ /** Field key -> its grid row, in a two-column form (the strip under its section's key). */
18
+ rows: Map<string, number>;
19
+ }
20
+ export declare const isTabSection: (field: FieldDescriptor) => boolean;
21
+ export declare function foldClass(layout: TabLayout, key: string, folded: ReadonlySet<string>): string;
22
+ export declare function tabClass(layout: TabLayout, key: string): string;
23
+ export declare function rowStyle(layout: TabLayout, key: string): string | typeof nothing;
24
+ interface LayoutInput {
25
+ /** The fields in display order. */
26
+ fields: FieldDescriptor[];
27
+ visible: (field: FieldDescriptor) => boolean;
28
+ /** The tab the host asked for; the first showing one when unset or gone. */
29
+ tab: string;
30
+ folded: ReadonlySet<string>;
31
+ twoColumn: boolean;
32
+ }
33
+ /**
34
+ * Tabs come from sections marked `tab`. Nothing moves in the DOM: every field stays rendered so
35
+ * rules, values and validate() still cover the whole form, and the ones in another tab are hidden.
36
+ * A tab shows while any of its fields is visible.
37
+ */
38
+ export declare function buildLayout(input: LayoutInput): TabLayout;
39
+ export {};
@@ -0,0 +1,67 @@
1
+ import { nothing as k } from "lit";
2
+ const d = (e) => e.type === "section" && !!e.tab, r = 2;
3
+ function y(e, s, t) {
4
+ const o = e.section.get(s);
5
+ return o !== void 0 && t.has(o) ? " baht-field--folded" : "";
6
+ }
7
+ function h(e, s) {
8
+ const t = e.owner.get(s);
9
+ return t !== void 0 && t !== e.open ? " baht-field--tab-hidden" : "";
10
+ }
11
+ function u(e, s) {
12
+ const t = e.rows.get(s);
13
+ return t === void 0 ? k : `--baht-field-row:${String(t)}`;
14
+ }
15
+ function m(e) {
16
+ var w, b;
17
+ const s = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), o = [];
18
+ let c;
19
+ for (const n of e.fields) {
20
+ if (n.type === "section" && (c = n.collapsible ? n.key : void 0), d(n)) {
21
+ o.push({
22
+ key: n.key,
23
+ label: n.text ?? n.label ?? n.key,
24
+ visible: !1
25
+ });
26
+ continue;
27
+ }
28
+ c && n.key !== c && t.set(n.key, c);
29
+ const f = o.at(-1);
30
+ f && (s.set(n.key, f.key), f.visible || (f.visible = e.visible(n)));
31
+ }
32
+ const i = o.filter((n) => n.visible), l = (w = i.find((n) => n.key === e.tab) ?? i[0]) == null ? void 0 : w.key, a = {
33
+ first: (b = o[0]) == null ? void 0 : b.key,
34
+ owner: s,
35
+ showing: i,
36
+ open: l,
37
+ section: t,
38
+ rows: /* @__PURE__ */ new Map()
39
+ };
40
+ return e.twoColumn && v(a, e), a;
41
+ }
42
+ function v(e, s) {
43
+ const t = [r, r];
44
+ for (const o of s.fields) {
45
+ if (d(o)) {
46
+ if (o.key !== e.first || e.showing.length === 0) continue;
47
+ } else {
48
+ if (!s.visible(o) || h(e, o.key)) continue;
49
+ if (y(e, o.key, s.folded)) continue;
50
+ }
51
+ const c = d(o) ? void 0 : o.column;
52
+ if (c === 1 || c === 2) {
53
+ const i = c - 1, l = t[i] ?? r;
54
+ e.rows.set(o.key, l), t[i] = l + 1;
55
+ } else {
56
+ const i = Math.max(...t);
57
+ e.rows.set(o.key, i), t.fill(i + 1);
58
+ }
59
+ }
60
+ }
61
+ export {
62
+ m as buildLayout,
63
+ y as foldClass,
64
+ d as isTabSection,
65
+ u as rowStyle,
66
+ h as tabClass
67
+ };
@@ -0,0 +1,39 @@
1
+ import { FieldDescriptor, FieldOption, FormDefinition, Registry } from '@20baht/engine';
2
+ interface Host {
3
+ /** The flag-resolved form, or undefined before one is bound. */
4
+ form: () => FormDefinition | undefined;
5
+ /** The data the fetchers read and the dep snapshots are taken from. */
6
+ data: () => Record<string, unknown>;
7
+ registry: () => Registry;
8
+ /** An async fetch landed: render again. */
9
+ refresh: () => void;
10
+ }
11
+ /**
12
+ * The dynamic options of a `<baht-form>` (`options_from` / `options_deps`): which fields load
13
+ * options, the dep snapshot each last fetched for, a fetch epoch that drops stale responses, and
14
+ * the options themselves. Sync fetchers land immediately; async ones render again when they
15
+ * resolve.
16
+ */
17
+ export declare class DynamicOptions {
18
+ private readonly host;
19
+ /** Resolved options + the dep snapshot / fetch epoch they belong to. */
20
+ private readonly loaded;
21
+ private readonly snapshots;
22
+ private readonly epochs;
23
+ private fetches;
24
+ constructor(host: Host);
25
+ /** Forget everything loaded: another form, or other flags. */
26
+ clear(): void;
27
+ get(id: string): FieldOption[] | undefined;
28
+ /** Every field that may load options: top-level as its key, a repeater column as `rows.col`. */
29
+ private sources;
30
+ /** A field with its loaded options, its repeater columns' included. */
31
+ withOptions(field: FieldDescriptor): FieldDescriptor;
32
+ /** The options a read-only field shows: loaded ones for `options_from`, else its own. */
33
+ optionsFor(field: FieldDescriptor): FieldOption[] | undefined;
34
+ /**
35
+ * Refetch the options whose dep snapshot changed. Stale responses are dropped by epoch.
36
+ */
37
+ sync(): void;
38
+ }
39
+ export {};
@@ -0,0 +1,65 @@
1
+ class c {
2
+ constructor(t) {
3
+ this.host = t, this.loaded = /* @__PURE__ */ new Map(), this.snapshots = /* @__PURE__ */ new Map(), this.epochs = /* @__PURE__ */ new Map(), this.fetches = 0;
4
+ }
5
+ /** Forget everything loaded: another form, or other flags. */
6
+ clear() {
7
+ this.loaded.clear(), this.snapshots.clear(), this.epochs.clear();
8
+ }
9
+ get(t) {
10
+ return this.loaded.get(t);
11
+ }
12
+ /** Every field that may load options: top-level as its key, a repeater column as `rows.col`. */
13
+ *sources() {
14
+ var t;
15
+ for (const o of ((t = this.host.form()) == null ? void 0 : t.fields) ?? [])
16
+ if (yield [o.key, o], o.type === "repeater")
17
+ for (const s of o.fields ?? []) yield [`${o.key}.${s.key}`, s];
18
+ }
19
+ /** A field with its loaded options, its repeater columns' included. */
20
+ withOptions(t) {
21
+ var o;
22
+ return t.options_from ? { ...t, options: this.loaded.get(t.key) ?? t.options ?? [] } : t.type !== "repeater" || !((o = t.fields) != null && o.some((s) => s.options_from)) ? t : {
23
+ ...t,
24
+ fields: t.fields.map(
25
+ (s) => s.options_from ? {
26
+ ...s,
27
+ options: this.loaded.get(`${t.key}.${s.key}`) ?? s.options ?? []
28
+ } : s
29
+ )
30
+ };
31
+ }
32
+ /** The options a read-only field shows: loaded ones for `options_from`, else its own. */
33
+ optionsFor(t) {
34
+ return t.options_from ? this.loaded.get(t.key) ?? t.options ?? [] : t.options;
35
+ }
36
+ /**
37
+ * Refetch the options whose dep snapshot changed. Stale responses are dropped by epoch.
38
+ */
39
+ sync() {
40
+ var o;
41
+ const t = this.host.data();
42
+ for (const [s, e] of this.sources()) {
43
+ if (!e.options_from) continue;
44
+ const r = JSON.stringify((e.options_deps ?? []).map((i) => t[i] ?? null));
45
+ if (this.snapshots.get(s) === r) continue;
46
+ this.snapshots.set(s, r);
47
+ const n = ++this.fetches;
48
+ this.epochs.set(s, n);
49
+ const p = (o = this.host.registry().options) == null ? void 0 : o[e.options_from];
50
+ if (!p) {
51
+ console.warn(`[bahtui] unknown options fetcher "${e.options_from}" — skipped`), this.loaded.set(s, []);
52
+ continue;
53
+ }
54
+ const h = p(t);
55
+ h instanceof Promise ? h.then((i) => {
56
+ this.epochs.get(s) === n && (this.loaded.set(s, i), this.host.refresh());
57
+ }).catch((i) => {
58
+ console.warn(`[bahtui] options fetcher "${e.options_from}" failed`, i), this.epochs.get(s) === n && this.snapshots.delete(s);
59
+ }) : this.loaded.set(s, h);
60
+ }
61
+ }
62
+ }
63
+ export {
64
+ c as DynamicOptions
65
+ };
@@ -0,0 +1,20 @@
1
+ import { nothing, TemplateResult } from 'lit';
2
+ import { FieldDescriptor, DisplayValue } from '@20baht/engine';
3
+ /** What the read-only renderer needs from the form around it. */
4
+ export interface ReadonlyContext {
5
+ /** A reference's label once known, the raw id until then. */
6
+ referenceText: (field: FieldDescriptor, id: string) => string;
7
+ /** `registry.markdownImage`: which image URLs a markdown value may show. */
8
+ markdownImage: ((href: string) => boolean) | undefined;
9
+ }
10
+ interface ReadonlyField {
11
+ field: FieldDescriptor;
12
+ shown: DisplayValue;
13
+ /** Width class, then `hidden` / revealed / tab / fold classes: everything after `baht-field--readonly`. */
14
+ classes: string;
15
+ style: string | typeof nothing;
16
+ testId: string;
17
+ }
18
+ /** One field of a read-only form: its label over its value. */
19
+ export declare function renderReadonlyField(arg: ReadonlyField, ctx: ReadonlyContext): TemplateResult;
20
+ export {};
@@ -0,0 +1,70 @@
1
+ import { nothing as l, html as e } from "lit";
2
+ import { t as o } from "@20baht/engine";
3
+ import "./primitives/baht-markdown.js";
4
+ function p(n) {
5
+ return e`<span class="baht-readonly-value baht-readonly-chips"
6
+ >${n.map(
7
+ (a) => a.url ? e`<a
8
+ class="baht-readonly-chip baht-readonly-file"
9
+ href=${a.url}
10
+ target="_blank"
11
+ rel="noopener noreferrer"
12
+ >${a.name}</a
13
+ >` : e`<span class="baht-readonly-chip">${a.name}</span>`
14
+ )}</span
15
+ >`;
16
+ }
17
+ function d(n, a, t) {
18
+ switch (a.kind) {
19
+ case "empty":
20
+ return e`<span class="baht-readonly-value baht-readonly-value--empty"
21
+ >${o("emptyValue")}</span
22
+ >`;
23
+ case "text":
24
+ return n.type === "markdown" ? e`<baht-markdown-view
25
+ class="baht-readonly-value"
26
+ .source=${a.text}
27
+ .allowImage=${t.markdownImage}
28
+ ></baht-markdown-view>` : e`<span class="baht-readonly-value"
29
+ >${n.type === "reference" ? t.referenceText(n, a.text) : a.text}</span
30
+ >`;
31
+ case "chips":
32
+ return e`<span class="baht-readonly-value baht-readonly-chips"
33
+ >${a.items.map((s) => e`<span class="baht-readonly-chip">${s}</span>`)}</span
34
+ >`;
35
+ case "files":
36
+ return p(a.items);
37
+ case "rows":
38
+ return e`<div class="baht-readonly-rows">
39
+ ${a.rows.map(
40
+ (s) => e`<div class="baht-readonly-row">
41
+ ${s.map(
42
+ (r) => e`<span class="baht-readonly-cell"
43
+ ><span class="baht-readonly-cell-label">${r.label}</span
44
+ ><span class="baht-readonly-cell-value"
45
+ >${r.reference ? t.referenceText(r.reference, r.text) : r.text}</span
46
+ ></span
47
+ >`
48
+ )}
49
+ </div>`
50
+ )}
51
+ </div>`;
52
+ }
53
+ }
54
+ function b(n, a) {
55
+ const { field: t } = n;
56
+ return e`<div
57
+ class=${n.classes}
58
+ data-column=${t.column ?? l}
59
+ style=${n.style}
60
+ data-key=${t.key}
61
+ data-type=${t.type}
62
+ data-testid=${n.testId}
63
+ >
64
+ ${t.label ? e`<span class="baht-label">${t.label}</span>` : l}
65
+ ${d(t, n.shown, a)}
66
+ </div>`;
67
+ }
68
+ export {
69
+ b as renderReadonlyField
70
+ };
@@ -0,0 +1,4 @@
1
+ export declare function pushLayer(el: HTMLElement): void;
2
+ export declare function dropLayer(el: HTMLElement): void;
3
+ /** The topmost open layer, or `null` when none is open. */
4
+ export declare function topLayer(): HTMLElement | null;
@@ -0,0 +1,15 @@
1
+ let t = [];
2
+ function e(r) {
3
+ t = t.filter((n) => n !== r), t.push(r);
4
+ }
5
+ function u(r) {
6
+ t = t.filter((n) => n !== r);
7
+ }
8
+ function o() {
9
+ return t.at(-1) ?? null;
10
+ }
11
+ export {
12
+ u as dropLayer,
13
+ e as pushLayer,
14
+ o as topLayer
15
+ };
@@ -0,0 +1,65 @@
1
+ import { ReactiveController, ReactiveControllerHost, TemplateResult } from 'lit';
2
+ import { IconName } from './primitives/icons.js';
3
+ /** One entry of an action menu (`<baht-menu>`, `<baht-split-button>`). */
4
+ export interface MenuItem {
5
+ /** Sent as `baht-select` `detail.value`. */
6
+ value: string;
7
+ label: string;
8
+ /** Key combo that picks this item from anywhere (menu open or not), shown as a hint. */
9
+ shortcut?: string;
10
+ disabled?: boolean;
11
+ /** Destructive action: rendered in the danger color. */
12
+ danger?: boolean;
13
+ /** A setting toggled from the menu: rendered as `menuitemcheckbox` with this state. */
14
+ checked?: boolean;
15
+ /** Muted second line under the label. */
16
+ description?: string;
17
+ /** Leading icon from the curated set (`trash`, `terminal`, …); unknown names draw nothing. */
18
+ icon?: IconName;
19
+ /** Extra class on the item (e.g. to show it only at some widths). */
20
+ class?: string;
21
+ /** Language of the label, when it differs from the page (a "ภาษาไทย" switch). */
22
+ lang?: string;
23
+ }
24
+ type Host = ReactiveControllerHost & HTMLElement & {
25
+ disabled: boolean;
26
+ };
27
+ interface Options {
28
+ items: () => MenuItem[];
29
+ /** The element that opens the menu, so focus can return to it. */
30
+ trigger: () => HTMLElement | null;
31
+ onPick: (item: MenuItem) => void;
32
+ }
33
+ /**
34
+ * The ARIA menu behind `<baht-menu>` and `<baht-split-button>`: open state, outside click,
35
+ * APG menu-button keyboard (↓/↑/Enter/Space open on the first/last item; ↑ ↓ wrap and skip
36
+ * disabled; Home/End; Escape closes back to the trigger and is marked handled so a surrounding
37
+ * `<baht-modal>` stays open; Tab closes), item rendering with shortcut hints, and page-wide
38
+ * item shortcuts (same scoping as `<baht-button shortcut>`).
39
+ */
40
+ export declare class MenuController implements ReactiveController {
41
+ private readonly host;
42
+ private readonly opts;
43
+ open: boolean;
44
+ private mac;
45
+ private unbinders;
46
+ constructor(host: Host, opts: Options);
47
+ hostConnected(): void;
48
+ hostDisconnected(): void;
49
+ /** Re-register item shortcuts — call when `items` changes. */
50
+ rebind(): void;
51
+ private unbindAll;
52
+ private readonly onDocMousedown;
53
+ setOpen(open: boolean): void;
54
+ pick(item: MenuItem): void;
55
+ private enabledButtons;
56
+ private openAndFocus;
57
+ /** Trigger click: keyboard activation (detail 0) lands on the first item, per the APG. */
58
+ readonly onTriggerClick: (e: MouseEvent) => void;
59
+ readonly onTriggerKeydown: (e: KeyboardEvent) => void;
60
+ private readonly onMenuKeydown;
61
+ private renderItem;
62
+ /** The menu panel. `align` picks the edge it lines up with; `heading` is a non-item first line. */
63
+ render(id: string, align: 'start' | 'end', label: string, heading?: string): TemplateResult;
64
+ }
65
+ export {};