@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,177 @@
1
+ import { html as n, nothing as f } from "lit";
2
+ import { property as b, state as m } from "lit/decorators.js";
3
+ import { ifDefined as c } from "lit/directives/if-defined.js";
4
+ import { live as v } from "lit/directives/live.js";
5
+ import { t as l } from "@20baht/engine";
6
+ import { BahtFieldBase as g } from "../field-base.js";
7
+ import { customElement as w } from "../define.js";
8
+ import "./baht-markdown-view.js";
9
+ var y = Object.defineProperty, x = Object.getOwnPropertyDescriptor, h = (e, t, r, a) => {
10
+ for (var i = a > 1 ? void 0 : a ? x(t, r) : t, s = e.length - 1, o; s >= 0; s--)
11
+ (o = e[s]) && (i = (a ? o(t, r, i) : o(i)) || i);
12
+ return a && i && y(t, r, i), i;
13
+ };
14
+ const T = /^image\/(png|jpe?g|gif|webp)$/, E = (e) => {
15
+ const t = e.name.replace(/[[\]\\]/g, "\\$&"), r = (e.type ?? "").split(";")[0] ?? "";
16
+ return `${T.test(r) ? "!" : ""}[${t}](${e.url})`;
17
+ };
18
+ let d = class extends g {
19
+ constructor() {
20
+ super(...arguments), this.tab = "write", this.dropping = !1, this.uploadError = null, this.uploads = 0, this.onTabKey = (e) => {
21
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
22
+ const t = this.tab === "write" ? "preview" : "write";
23
+ this.tab = t, this.updateComplete.then(() => {
24
+ var r;
25
+ (r = this.querySelector(`[data-tab="${t}"]`)) == null || r.focus();
26
+ });
27
+ }, this.onPaste = (e) => {
28
+ const t = e.clipboardData;
29
+ !this.uploader || !(t != null && t.files.length) || t.getData("text/plain") || (e.preventDefault(), this.uploadAll(Array.from(t.files)));
30
+ }, this.onDragOver = (e) => {
31
+ var t;
32
+ !this.uploader || !((t = e.dataTransfer) != null && t.types.includes("Files")) || (e.preventDefault(), this.dropping = !0);
33
+ }, this.onDrop = (e) => {
34
+ var t;
35
+ this.dropping = !1, !(!this.uploader || !((t = e.dataTransfer) != null && t.files.length)) && (e.preventDefault(), this.uploadAll(Array.from(e.dataTransfer.files)));
36
+ }, this.onPick = (e) => {
37
+ const t = e.target;
38
+ this.uploadAll(Array.from(t.files ?? [])), t.value = "";
39
+ };
40
+ }
41
+ get textarea() {
42
+ return this.querySelector("textarea");
43
+ }
44
+ select(e) {
45
+ this.tab = e, e === "write" && this.updateComplete.then(() => {
46
+ var t;
47
+ return (t = this.textarea) == null ? void 0 : t.focus();
48
+ });
49
+ }
50
+ uploadAll(e) {
51
+ const { textarea: t, uploader: r } = this;
52
+ if (!t || !r) return;
53
+ this.uploadError = null;
54
+ const a = this.field.max_size;
55
+ for (const i of e) {
56
+ if (a && i.size > a) {
57
+ this.uploadError = l("uploadFailed");
58
+ continue;
59
+ }
60
+ const s = `![${l("uploading")} ${i.name.replace(/[[\]]/g, "")} (${String(++this.uploads)})]()`, o = t.selectionStart, u = t.value[o - 1], p = `${u && u !== `
61
+ ` ? `
62
+ ` : ""}${s}
63
+ `;
64
+ t.setRangeText(p, o, t.selectionEnd, "end"), this.emitTyped(t.value), r(i).then(
65
+ ($) => {
66
+ this.fill(s, E($));
67
+ },
68
+ () => {
69
+ this.fill(s, ""), this.uploadError = l("uploadFailed");
70
+ }
71
+ );
72
+ }
73
+ }
74
+ /** The upload's placeholder becomes its result, wherever typing has moved it to. */
75
+ fill(e, t) {
76
+ const { textarea: r } = this, a = (r == null ? void 0 : r.value.indexOf(e)) ?? -1;
77
+ if (!r || a < 0) return;
78
+ const i = a + e.length, s = (p) => p >= i ? p + t.length - e.length : Math.min(p, a), [o, u] = [s(r.selectionStart), s(r.selectionEnd)];
79
+ r.setRangeText(t, a, i), r.setSelectionRange(o, u), this.emitTyped(r.value);
80
+ }
81
+ renderTab(e, t) {
82
+ const r = this.tab === e;
83
+ return n`<button
84
+ type="button"
85
+ role="tab"
86
+ class="baht-tabs-tab${r ? " baht-tabs-tab--on" : ""}"
87
+ data-tab=${e}
88
+ aria-selected=${r ? "true" : "false"}
89
+ tabindex=${r ? 0 : -1}
90
+ @click=${() => {
91
+ this.select(e);
92
+ }}
93
+ >
94
+ ${t}
95
+ </button>`;
96
+ }
97
+ renderView() {
98
+ const e = this.shownText;
99
+ return e.trim() ? n`<baht-markdown-view
100
+ class="baht-md-preview"
101
+ .source=${e}
102
+ .allowImage=${this.allowImage}
103
+ ></baht-markdown-view>` : n`<div class="baht-md-preview baht-readonly-value--empty">${l("markdownEmpty")}</div>`;
104
+ }
105
+ renderHint() {
106
+ return n`<div class="baht-help baht-md-hint">
107
+ ${l("markdownHint")}
108
+ ${this.uploader ? n`<label class="baht-md-attach">
109
+ ${l("markdownAttach")}
110
+ <input
111
+ type="file"
112
+ multiple
113
+ hidden
114
+ accept=${c(this.field.accept)}
115
+ @change=${this.onPick}
116
+ />
117
+ </label>` : f}
118
+ </div>`;
119
+ }
120
+ renderControl() {
121
+ if (this.disabled || this.readonly) return this.renderView();
122
+ const e = this.tab === "preview";
123
+ return n`<div
124
+ class="baht-tabs-list baht-md-tabs"
125
+ role="tablist"
126
+ aria-labelledby=${c(this.field.label ? this.labelId : void 0)}
127
+ @keydown=${this.onTabKey}
128
+ >
129
+ ${this.renderTab("write", l("markdownWrite"))}
130
+ ${this.renderTab("preview", l("markdownPreview"))}
131
+ </div>
132
+ <textarea
133
+ class="baht-control baht-control--textarea baht-md-input${this.dropping ? " baht-md-input--dropping" : ""}"
134
+ id=${this.controlId}
135
+ ?hidden=${e}
136
+ .value=${v(this.shownText)}
137
+ placeholder=${c(this.field.placeholder)}
138
+ maxlength=${c(this.field.max_length)}
139
+ rows=${this.field.rows ?? 8}
140
+ ?required=${this.required}
141
+ aria-invalid=${this.invalidAttr}
142
+ aria-describedby=${this.describedBy}
143
+ @input=${(t) => {
144
+ this.emitTyped(t.target.value);
145
+ }}
146
+ @paste=${this.onPaste}
147
+ @dragover=${this.onDragOver}
148
+ @dragleave=${() => {
149
+ this.dropping = !1;
150
+ }}
151
+ @drop=${this.onDrop}
152
+ ></textarea>
153
+ ${e ? this.renderView() : this.renderHint()}
154
+ ${this.uploadError ? n`<div class="baht-error" role="alert">${this.uploadError}</div>` : f}`;
155
+ }
156
+ };
157
+ h([
158
+ b({ attribute: !1 })
159
+ ], d.prototype, "uploader", 2);
160
+ h([
161
+ b({ attribute: !1 })
162
+ ], d.prototype, "allowImage", 2);
163
+ h([
164
+ m()
165
+ ], d.prototype, "tab", 2);
166
+ h([
167
+ m()
168
+ ], d.prototype, "dropping", 2);
169
+ h([
170
+ m()
171
+ ], d.prototype, "uploadError", 2);
172
+ d = h([
173
+ w("baht-markdown")
174
+ ], d);
175
+ export {
176
+ d as BahtMarkdown
177
+ };
@@ -0,0 +1,53 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ import { MenuItem } from '../menu-controller.js';
4
+ import { IconName } from './icons.js';
5
+ /**
6
+ * Action menu behind a button: the ⋯ "more" menu on a table row or card, or a labelled
7
+ * "Export ▾" menu. Same menu as `<baht-split-button>` — items with optional `shortcut`
8
+ * hints (bound page-wide), disabled and danger entries, the APG menu-button keyboard.
9
+ *
10
+ * <baht-menu></baht-menu> <!-- ⋯ icon trigger -->
11
+ * <baht-menu trigger-label="Export" align="start"></baht-menu>
12
+ * el.items = [{ value: 'rename', label: 'Rename', shortcut: 'f2' },
13
+ * { value: 'delete', label: 'Delete', danger: true }];
14
+ * el.addEventListener('baht-select', (e) => run(e.detail.value));
15
+ *
16
+ * A child marked `data-trigger` becomes the trigger's content (an avatar menu); `heading`
17
+ * adds a non-item first line ("Signed in as …"); items with `checked` are settings
18
+ * (`menuitemcheckbox`) and can carry a `description` line.
19
+ *
20
+ * <baht-menu label="Account" heading="somchai@20baht.com">
21
+ * <baht-avatar data-trigger label="Somchai"></baht-avatar>
22
+ * </baht-menu>
23
+ *
24
+ * @fires {CustomEvent<{ value: string; item: MenuItem }>} baht-select - An item was picked (click, keyboard or its shortcut). `detail: { value, item }`.
25
+ */
26
+ export declare class BahtMenu extends BahtElement {
27
+ /** Menu entries. Set as a property: `el.items = [...]`. */
28
+ items: MenuItem[];
29
+ /** Visible trigger text; empty = an icon-only trigger. */
30
+ triggerLabel: string;
31
+ /** Trigger icon from the curated set (default `more`, the ⋯). Ignored when `trigger-label` is set. */
32
+ icon: IconName | '';
33
+ /** Accessible name of the trigger (and the menu). Defaults to the trigger text, else "More actions". */
34
+ label: string;
35
+ /** Trigger look: `ghost` (default) or `secondary`. */
36
+ variant: 'ghost' | 'secondary';
37
+ size: 'sm' | 'md';
38
+ /** Menu edge aligned with the trigger: `'end'` (default) or `'start'`. */
39
+ align: 'start' | 'end';
40
+ disabled: boolean;
41
+ /** Non-item first line of the menu ("Signed in as …"). */
42
+ heading: string;
43
+ private triggerEl;
44
+ /** True once a `data-trigger` child was moved into the trigger. */
45
+ private customTrigger;
46
+ private readonly menu;
47
+ private get menuId();
48
+ protected firstUpdated(): void;
49
+ protected updated(changed: Map<PropertyKey, unknown>): void;
50
+ /** Button chrome for the built-in triggers; a custom (avatar) trigger stays bare. */
51
+ private triggerClass;
52
+ protected render(): TemplateResult;
53
+ }
@@ -0,0 +1,100 @@
1
+ import { nothing as m, html as l } from "lit";
2
+ import { property as a, query as g, state as c } from "lit/decorators.js";
3
+ import { BahtElement as b, arr as d } from "../base.js";
4
+ import { customElement as f } from "../define.js";
5
+ import { t as y } from "@20baht/engine";
6
+ import { MenuController as $ } from "../menu-controller.js";
7
+ import { isIconName as v, renderIcon as p } from "./icons.js";
8
+ var w = Object.defineProperty, T = Object.getOwnPropertyDescriptor, i = (t, e, s, n) => {
9
+ for (var o = n > 1 ? void 0 : n ? T(e, s) : e, h = t.length - 1, u; h >= 0; h--)
10
+ (u = t[h]) && (o = (n ? u(e, s, o) : u(o)) || o);
11
+ return n && o && w(e, s, o), o;
12
+ };
13
+ let r = class extends b {
14
+ constructor() {
15
+ super(...arguments), this.items = [], this.triggerLabel = "", this.icon = "more", this.label = "", this.variant = "ghost", this.size = "md", this.align = "end", this.disabled = !1, this.heading = "", this.customTrigger = !1, this.menu = new $(this, {
16
+ items: () => d(this.items),
17
+ trigger: () => this.querySelector(".baht-menu-trigger"),
18
+ onPick: (t) => {
19
+ this.emit("baht-select", { value: t.value, item: t });
20
+ }
21
+ });
22
+ }
23
+ get menuId() {
24
+ return `baht-menu-${this.uid}`;
25
+ }
26
+ firstUpdated() {
27
+ const t = Array.from(this.children).find(
28
+ (e) => e.hasAttribute("data-trigger") && !e.classList.contains("baht-menu-host")
29
+ );
30
+ t && (this.triggerEl.append(t), this.customTrigger = !0);
31
+ }
32
+ updated(t) {
33
+ t.has("items") && this.menu.rebind();
34
+ }
35
+ /** Button chrome for the built-in triggers; a custom (avatar) trigger stays bare. */
36
+ triggerClass(t, e) {
37
+ if (t) return "baht-menu-trigger baht-menu-trigger--custom";
38
+ const s = [
39
+ "baht-button",
40
+ `baht-button--${this.variant === "secondary" ? "secondary" : "ghost"}`
41
+ ];
42
+ return this.size === "sm" && s.push("baht-button--sm"), e && s.push("baht-button--icon"), s.push("baht-menu-trigger"), s.join(" ");
43
+ }
44
+ render() {
45
+ const t = this.menu.open, e = this.triggerLabel, s = this.label || e || y("moreActions"), n = this.customTrigger, o = !e && !n, h = o && this.icon && v(this.icon) ? p(this.icon) : m, u = this.triggerClass(n, o);
46
+ return l`<div class="baht-menu-host${t ? " baht-menu-host--open" : ""}">
47
+ <button
48
+ type="button"
49
+ class=${u}
50
+ aria-haspopup="menu"
51
+ aria-expanded=${t ? "true" : "false"}
52
+ aria-controls=${this.menuId}
53
+ aria-label=${o || n || this.label ? s : m}
54
+ ?disabled=${this.disabled}
55
+ @click=${this.menu.onTriggerClick}
56
+ @keydown=${this.menu.onTriggerKeydown}
57
+ >${h}${e && !n ? l`${e}${p("chevron-down")}` : m}</button>
58
+ ${this.menu.render(this.menuId, this.align, s, this.heading)}
59
+ </div>`;
60
+ }
61
+ };
62
+ i([
63
+ a({ attribute: !1 })
64
+ ], r.prototype, "items", 2);
65
+ i([
66
+ a({ attribute: "trigger-label" })
67
+ ], r.prototype, "triggerLabel", 2);
68
+ i([
69
+ a()
70
+ ], r.prototype, "icon", 2);
71
+ i([
72
+ a()
73
+ ], r.prototype, "label", 2);
74
+ i([
75
+ a()
76
+ ], r.prototype, "variant", 2);
77
+ i([
78
+ a()
79
+ ], r.prototype, "size", 2);
80
+ i([
81
+ a()
82
+ ], r.prototype, "align", 2);
83
+ i([
84
+ a({ type: Boolean, reflect: !0 })
85
+ ], r.prototype, "disabled", 2);
86
+ i([
87
+ a()
88
+ ], r.prototype, "heading", 2);
89
+ i([
90
+ g(".baht-menu-trigger")
91
+ ], r.prototype, "triggerEl", 2);
92
+ i([
93
+ c()
94
+ ], r.prototype, "customTrigger", 2);
95
+ r = i([
96
+ f("baht-menu")
97
+ ], r);
98
+ export {
99
+ r as BahtMenu
100
+ };
@@ -0,0 +1,67 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ import { ChartFormat } from './charts.js';
4
+ /** Fractions of `max` at which the fill changes severity. */
5
+ export interface MeterThresholds {
6
+ warning: number;
7
+ danger: number;
8
+ }
9
+ /** What a meter measures, which picks its default status words. */
10
+ export type MeterKind = 'budget' | 'capacity';
11
+ /**
12
+ * Spent-against-budget meter. The fill carries severity (accent → warning →
13
+ * danger) and the unfilled track is a lighter step of the same ramp, so state
14
+ * reads across the whole bar. Severity is always paired with an icon and a
15
+ * worded status, never color alone.
16
+ *
17
+ * <baht-meter label="Food" value="4200" max="4000" format="currency"></baht-meter>
18
+ * <baht-meter kind="capacity" label="vCPUs" value="18" max="20"></baht-meter>
19
+ *
20
+ * `kind="capacity"` measures room used rather than money spent: the status words become
21
+ * "Almost full", "Full" and "Over quota". An explicit `near-label` / `at-label` / `over-label`
22
+ * still wins.
23
+ */
24
+ export declare class BahtMeter extends BahtElement {
25
+ /** Amount used so far. */
26
+ value: number;
27
+ /** The budget / capacity the value is measured against. */
28
+ max: number;
29
+ /** Sentence-case caption. */
30
+ label: string;
31
+ /**
32
+ * How value, max and the pace read: number | currency | percent | percent-100 |
33
+ * compact. The fill is always `value / max`. `percent` expects fractions (value
34
+ * `0.14`, max `1` → "14% of 100%"); for 0 to 100 values (value `14`, the default max
35
+ * `100`) use `percent-100`.
36
+ */
37
+ format: ChartFormat;
38
+ /** ISO currency code for `format="currency"` (THB renders `฿`). */
39
+ currency: string;
40
+ /** Fractions of `max` where the fill turns warning / danger. */
41
+ thresholds: MeterThresholds;
42
+ /** Pace marker: where the value *should* be by now. `null` hides the tick. */
43
+ expected: number | null;
44
+ /**
45
+ * What the meter measures: `budget` (money spent) or `capacity` (room used: "Almost full",
46
+ * "Full", "Over quota"). Picks the status words a label left at its default shows.
47
+ */
48
+ kind: MeterKind;
49
+ /** Word shown after the numbers when the meter is over budget. */
50
+ overLabel: string;
51
+ /** Word shown when the value has reached the budget exactly, but not passed it. */
52
+ atLabel: string;
53
+ /** Word shown after the numbers when the meter is near its limit. */
54
+ nearLabel: string;
55
+ /** A label the host set wins; one still at its budget default takes the kind's word. */
56
+ private word;
57
+ private get fraction();
58
+ /**
59
+ * `ok` | `warning` | `danger`, from the fraction and the thresholds. `danger` is
60
+ * strictly **above** its threshold: spending exactly the budget is not
61
+ * overspending, so it reads as the warning tone with an "At budget" status.
62
+ * `warning` stays inclusive (`>=`).
63
+ */
64
+ private get severity();
65
+ private get statusText();
66
+ protected render(): TemplateResult;
67
+ }
@@ -0,0 +1,107 @@
1
+ import { nothing as u, html as p } from "lit";
2
+ import { property as s } from "lit/decorators.js";
3
+ import { BahtElement as d } from "../base.js";
4
+ import { formatValue as b } from "./charts.js";
5
+ import { customElement as v } from "../define.js";
6
+ var f = Object.defineProperty, x = Object.getOwnPropertyDescriptor, a = (e, t, i, o) => {
7
+ for (var n = o > 1 ? void 0 : o ? x(t, i) : t, l = e.length - 1, h; l >= 0; l--)
8
+ (h = e[l]) && (n = (o ? h(t, i, n) : h(n)) || n);
9
+ return o && n && f(t, i, n), n;
10
+ };
11
+ const c = { near: "Near limit", at: "At budget", over: "Over budget" }, y = { near: "Almost full", at: "Full", over: "Over quota" };
12
+ let r = class extends d {
13
+ constructor() {
14
+ super(...arguments), this.value = 0, this.max = 100, this.label = "", this.format = "number", this.currency = "THB", this.thresholds = { warning: 0.8, danger: 1 }, this.expected = null, this.kind = "budget", this.overLabel = c.over, this.atLabel = c.at, this.nearLabel = c.near;
15
+ }
16
+ /** A label the host set wins; one still at its budget default takes the kind's word. */
17
+ word(e, t) {
18
+ return t !== c[e] ? t : this.kind === "capacity" ? y[e] : t;
19
+ }
20
+ get fraction() {
21
+ const e = this.max || 1, t = this.value / e;
22
+ return Number.isFinite(t) ? Math.max(0, t) : 0;
23
+ }
24
+ /**
25
+ * `ok` | `warning` | `danger`, from the fraction and the thresholds. `danger` is
26
+ * strictly **above** its threshold: spending exactly the budget is not
27
+ * overspending, so it reads as the warning tone with an "At budget" status.
28
+ * `warning` stays inclusive (`>=`).
29
+ */
30
+ get severity() {
31
+ const { warning: e, danger: t } = this.thresholds, i = this.fraction;
32
+ return i > t ? "danger" : i >= e ? "warning" : "ok";
33
+ }
34
+ get statusText() {
35
+ const { danger: e } = this.thresholds, t = this.severity;
36
+ return t === "danger" ? this.word("over", this.overLabel) : t === "warning" ? this.fraction >= e ? this.word("at", this.atLabel) : this.word("near", this.nearLabel) : "";
37
+ }
38
+ render() {
39
+ const e = this.severity, t = Math.min(100, this.fraction * 100), i = (m) => b(m, this.format, this.currency), o = this.expected != null && Number.isFinite(this.expected) && this.max ? Math.min(100, Math.max(0, this.expected / this.max * 100)) : null, n = `${i(this.value)} of ${i(this.max)}`, l = e === "warning" && this.fraction >= this.thresholds.danger, h = e === "danger" ? "!" : l ? "=" : e === "warning" ? "△" : "";
40
+ return p`<div class="baht-meter baht-meter--${e}">
41
+ <div class="baht-meter-head">
42
+ ${this.label ? p`<span class="baht-meter-label">${this.label}</span>` : u}
43
+ <span class="baht-meter-value">${n}</span>
44
+ ${this.statusText ? p`<span class="baht-meter-status"
45
+ ><span class="baht-meter-icon" aria-hidden="true">${h}</span
46
+ >${this.statusText}</span
47
+ >` : u}
48
+ </div>
49
+ <div
50
+ class="baht-meter-track"
51
+ role="meter"
52
+ aria-label=${this.label || "Meter"}
53
+ aria-valuemin="0"
54
+ aria-valuemax=${this.max}
55
+ aria-valuenow=${this.value}
56
+ aria-valuetext=${`${n}${this.statusText ? `, ${this.statusText}` : ""}`}
57
+ >
58
+ <div class="baht-meter-fill" style=${`width:${t.toFixed(2)}%`}></div>
59
+ ${o != null ? p`<span
60
+ class="baht-meter-expected"
61
+ style=${`left:${o.toFixed(2)}%`}
62
+ aria-hidden="true"
63
+ ></span>` : u}
64
+ </div>
65
+ ${o != null ? p`<div class="baht-meter-pace">Expected by now ${i(this.expected)}</div>` : u}
66
+ </div>`;
67
+ }
68
+ };
69
+ a([
70
+ s({ type: Number })
71
+ ], r.prototype, "value", 2);
72
+ a([
73
+ s({ type: Number })
74
+ ], r.prototype, "max", 2);
75
+ a([
76
+ s()
77
+ ], r.prototype, "label", 2);
78
+ a([
79
+ s()
80
+ ], r.prototype, "format", 2);
81
+ a([
82
+ s()
83
+ ], r.prototype, "currency", 2);
84
+ a([
85
+ s({ attribute: !1 })
86
+ ], r.prototype, "thresholds", 2);
87
+ a([
88
+ s({ type: Number })
89
+ ], r.prototype, "expected", 2);
90
+ a([
91
+ s()
92
+ ], r.prototype, "kind", 2);
93
+ a([
94
+ s({ attribute: "over-label" })
95
+ ], r.prototype, "overLabel", 2);
96
+ a([
97
+ s({ attribute: "at-label" })
98
+ ], r.prototype, "atLabel", 2);
99
+ a([
100
+ s({ attribute: "near-label" })
101
+ ], r.prototype, "nearLabel", 2);
102
+ r = a([
103
+ v("baht-meter")
104
+ ], r);
105
+ export {
106
+ r as BahtMeter
107
+ };
@@ -0,0 +1,71 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ /** Where the dialog panel sits. */
4
+ export type ModalPlacement = 'center' | 'sheet' | 'side';
5
+ /** How wide a centered dialog may grow: 400, 560 (default) or 760px. */
6
+ export type ModalSize = 'sm' | 'md' | 'lg';
7
+ /**
8
+ * Modal dialog (20baht: 0.4 ink scrim, no blur; float shadow; 20px radius).
9
+ * Controlled: the host flips `open`. Children become the body; children with
10
+ * `data-slot="footer"` go in a footer row under it, right-aligned, that stays
11
+ * in view while the body scrolls (in every `placement`) and is part of the
12
+ * focus trap.
13
+ *
14
+ * <baht-modal heading="Delete this workflow?">
15
+ * <p>Steps and run history will be removed.</p>
16
+ * <baht-button data-slot="footer" variant="secondary">Cancel</baht-button>
17
+ * <baht-button data-slot="footer" variant="danger">Delete</baht-button>
18
+ * </baht-modal>
19
+ * modal.open = true;
20
+ * modal.addEventListener('baht-close', (e) => (modal.open = false));
21
+ *
22
+ * `placement` moves the panel: `'center'` (default) is the dialog above;
23
+ * `'sheet'` docks it to the bottom as a bottom sheet below 600px viewport
24
+ * width (full width, rounded top corners, a grab handle, max 90dvh with the
25
+ * body scrolling, slides up) and is a centered dialog from 600px up; `'side'`
26
+ * is a full-height drawer at the inline end, `min(420px, 100vw)` wide, sliding
27
+ * in from that edge. Scrim, focus trap/restore and `baht-close` are the same in
28
+ * every placement. Modifier classes: `.baht-modal--sheet` / `.baht-modal--side`
29
+ * on the panel, `.baht-modal-scrim--sheet` / `.baht-modal-scrim--side` on the scrim.
30
+ * @fires {CustomEvent<{ reason: 'escape' | 'scrim' | 'button' }>} baht-close - Asked to close; the host sets `open` to false.
31
+ */
32
+ export declare class BahtModal extends BahtElement {
33
+ constructor();
34
+ open: boolean;
35
+ heading: string;
36
+ /** One muted line under the heading; also becomes the dialog's aria-describedby. */
37
+ description: string;
38
+ showClose: boolean;
39
+ /** `'center'` (default) dialog, `'sheet'` bottom sheet below 600px (centered
40
+ * from 600px up), or `'side'` full-height drawer at the inline end. */
41
+ placement: ModalPlacement;
42
+ /**
43
+ * Widest a centered dialog (and a sheet from 600px up) grows: `'sm'` 400px, `'md'` 560px
44
+ * (default), `'lg'` 760px, all capped by the window. A `'side'` drawer keeps its own width.
45
+ */
46
+ size: ModalSize;
47
+ /**
48
+ * Scrim click requests close. Off by default: a stray click outside the panel
49
+ * must not throw away what the user typed — close via ×, Escape or your buttons.
50
+ */
51
+ closeOnScrim: boolean;
52
+ private bodyEl;
53
+ private footEl;
54
+ private get titleId();
55
+ private get descriptionId();
56
+ private closing;
57
+ private closeToken;
58
+ private previousFocus;
59
+ private onKeydown;
60
+ private focusables;
61
+ /** Keep Tab cycling inside the dialog (no keyboard escape to the page behind). */
62
+ private trapFocus;
63
+ connectedCallback(): void;
64
+ disconnectedCallback(): void;
65
+ protected willUpdate(changed: Map<PropertyKey, unknown>): void;
66
+ protected adoptChildren(): void;
67
+ protected updated(changed: Map<PropertyKey, unknown>): void;
68
+ /** Ask the host to close (the host owns `open`). */
69
+ requestClose(reason?: 'escape' | 'scrim' | 'button'): void;
70
+ protected render(): TemplateResult;
71
+ }