@loccal/ui 0.0.0-stage → 0.3.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 (254) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +21 -0
  3. package/README.md +38 -3
  4. package/dist/components/ui/accordion.d.ts +6 -0
  5. package/dist/components/ui/accordion.js +17 -0
  6. package/dist/components/ui/ai-panel.d.ts +47 -0
  7. package/dist/components/ui/ai-panel.js +74 -0
  8. package/dist/components/ui/alert-dialog.d.ts +18 -0
  9. package/dist/components/ui/alert-dialog.js +42 -0
  10. package/dist/components/ui/alert.d.ts +10 -0
  11. package/dist/components/ui/alert.js +27 -0
  12. package/dist/components/ui/avatar.d.ts +11 -0
  13. package/dist/components/ui/avatar.js +23 -0
  14. package/dist/components/ui/badge.d.ts +7 -0
  15. package/dist/components/ui/badge.js +36 -0
  16. package/dist/components/ui/breadcrumb.d.ts +10 -0
  17. package/dist/components/ui/breadcrumb.js +36 -0
  18. package/dist/components/ui/button-group.d.ts +10 -0
  19. package/dist/components/ui/button-group.js +36 -0
  20. package/dist/components/ui/button.d.ts +8 -0
  21. package/dist/components/ui/button.js +34 -0
  22. package/dist/components/ui/calendar.d.ts +10 -0
  23. package/dist/components/ui/calendar.js +76 -0
  24. package/dist/components/ui/card.d.ts +11 -0
  25. package/dist/components/ui/card.js +24 -0
  26. package/dist/components/ui/chart.d.ts +44 -0
  27. package/dist/components/ui/chart.js +132 -0
  28. package/dist/components/ui/checkbox.d.ts +3 -0
  29. package/dist/components/ui/checkbox.js +9 -0
  30. package/dist/components/ui/code-view.d.ts +31 -0
  31. package/dist/components/ui/code-view.js +62 -0
  32. package/dist/components/ui/collapsible.d.ts +5 -0
  33. package/dist/components/ui/collapsible.js +13 -0
  34. package/dist/components/ui/command-block.d.ts +28 -0
  35. package/dist/components/ui/command-block.js +58 -0
  36. package/dist/components/ui/command.d.ts +19 -0
  37. package/dist/components/ui/command.js +35 -0
  38. package/dist/components/ui/connection-status.d.ts +29 -0
  39. package/dist/components/ui/connection-status.js +26 -0
  40. package/dist/components/ui/context-menu.d.ts +29 -0
  41. package/dist/components/ui/context-menu.js +51 -0
  42. package/dist/components/ui/data-table.d.ts +49 -0
  43. package/dist/components/ui/data-table.js +100 -0
  44. package/dist/components/ui/dialog.d.ts +18 -0
  45. package/dist/components/ui/dialog.js +37 -0
  46. package/dist/components/ui/drawer.d.ts +16 -0
  47. package/dist/components/ui/drawer.js +75 -0
  48. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  49. package/dist/components/ui/dropdown-menu.js +51 -0
  50. package/dist/components/ui/dropzone.d.ts +11 -0
  51. package/dist/components/ui/dropzone.js +39 -0
  52. package/dist/components/ui/empty.d.ts +11 -0
  53. package/dist/components/ui/empty.js +33 -0
  54. package/dist/components/ui/field.d.ts +24 -0
  55. package/dist/components/ui/field.js +68 -0
  56. package/dist/components/ui/file-tree.d.ts +42 -0
  57. package/dist/components/ui/file-tree.js +88 -0
  58. package/dist/components/ui/file-type-icon.d.ts +16 -0
  59. package/dist/components/ui/file-type-icon.js +19 -0
  60. package/dist/components/ui/hash-chain.d.ts +43 -0
  61. package/dist/components/ui/hash-chain.js +34 -0
  62. package/dist/components/ui/history-palette.d.ts +37 -0
  63. package/dist/components/ui/history-palette.js +44 -0
  64. package/dist/components/ui/hover-card.d.ts +5 -0
  65. package/dist/components/ui/hover-card.js +14 -0
  66. package/dist/components/ui/icon-base.d.ts +15 -0
  67. package/dist/components/ui/icon-base.js +18 -0
  68. package/dist/components/ui/icon.d.ts +15 -0
  69. package/dist/components/ui/icon.js +32 -0
  70. package/dist/components/ui/icons-compat.d.ts +32 -0
  71. package/dist/components/ui/icons-compat.js +34 -0
  72. package/dist/components/ui/icons.d.ts +1048 -0
  73. package/dist/components/ui/icons.js +264 -0
  74. package/dist/components/ui/input-group.d.ts +18 -0
  75. package/dist/components/ui/input-group.js +57 -0
  76. package/dist/components/ui/input-otp.d.ts +11 -0
  77. package/dist/components/ui/input-otp.js +21 -0
  78. package/dist/components/ui/input.d.ts +3 -0
  79. package/dist/components/ui/input.js +7 -0
  80. package/dist/components/ui/kbd.d.ts +3 -0
  81. package/dist/components/ui/kbd.js +9 -0
  82. package/dist/components/ui/label.d.ts +3 -0
  83. package/dist/components/ui/label.js +7 -0
  84. package/dist/components/ui/locale-switch.d.ts +9 -0
  85. package/dist/components/ui/locale-switch.js +31 -0
  86. package/dist/components/ui/log-panel.d.ts +28 -0
  87. package/dist/components/ui/log-panel.js +59 -0
  88. package/dist/components/ui/menubar.d.ts +29 -0
  89. package/dist/components/ui/menubar.js +56 -0
  90. package/dist/components/ui/metric-grid.d.ts +20 -0
  91. package/dist/components/ui/metric-grid.js +14 -0
  92. package/dist/components/ui/model-list.d.ts +33 -0
  93. package/dist/components/ui/model-list.js +69 -0
  94. package/dist/components/ui/navigation-menu.d.ts +11 -0
  95. package/dist/components/ui/navigation-menu.js +31 -0
  96. package/dist/components/ui/number-field.d.ts +29 -0
  97. package/dist/components/ui/number-field.js +65 -0
  98. package/dist/components/ui/pagination.d.ts +17 -0
  99. package/dist/components/ui/pagination.js +26 -0
  100. package/dist/components/ui/pane-tree.d.ts +18 -0
  101. package/dist/components/ui/pane-tree.js +65 -0
  102. package/dist/components/ui/popover.d.ts +9 -0
  103. package/dist/components/ui/popover.js +23 -0
  104. package/dist/components/ui/progress.d.ts +7 -0
  105. package/dist/components/ui/progress.js +20 -0
  106. package/dist/components/ui/radio-group.d.ts +5 -0
  107. package/dist/components/ui/radio-group.js +12 -0
  108. package/dist/components/ui/resizable.d.ts +7 -0
  109. package/dist/components/ui/resizable.js +14 -0
  110. package/dist/components/ui/scroll-area.d.ts +5 -0
  111. package/dist/components/ui/scroll-area.js +11 -0
  112. package/dist/components/ui/select.d.ts +15 -0
  113. package/dist/components/ui/select.js +34 -0
  114. package/dist/components/ui/separator.d.ts +3 -0
  115. package/dist/components/ui/separator.js +8 -0
  116. package/dist/components/ui/settings-layout.d.ts +31 -0
  117. package/dist/components/ui/settings-layout.js +45 -0
  118. package/dist/components/ui/sheet.d.ts +14 -0
  119. package/dist/components/ui/sheet.js +37 -0
  120. package/dist/components/ui/shell-picker.d.ts +18 -0
  121. package/dist/components/ui/shell-picker.js +17 -0
  122. package/dist/components/ui/skeleton.d.ts +2 -0
  123. package/dist/components/ui/skeleton.js +6 -0
  124. package/dist/components/ui/slider.d.ts +3 -0
  125. package/dist/components/ui/slider.js +12 -0
  126. package/dist/components/ui/sonner.d.ts +3 -0
  127. package/dist/components/ui/sonner.js +25 -0
  128. package/dist/components/ui/spinner.d.ts +2 -0
  129. package/dist/components/ui/spinner.js +7 -0
  130. package/dist/components/ui/split-button.d.ts +21 -0
  131. package/dist/components/ui/split-button.js +14 -0
  132. package/dist/components/ui/stat.d.ts +10 -0
  133. package/dist/components/ui/stat.js +8 -0
  134. package/dist/components/ui/status-bar.d.ts +13 -0
  135. package/dist/components/ui/status-bar.js +15 -0
  136. package/dist/components/ui/stepper.d.ts +13 -0
  137. package/dist/components/ui/stepper.js +11 -0
  138. package/dist/components/ui/switch.d.ts +5 -0
  139. package/dist/components/ui/switch.js +8 -0
  140. package/dist/components/ui/table.d.ts +10 -0
  141. package/dist/components/ui/table.js +28 -0
  142. package/dist/components/ui/tabs.d.ts +10 -0
  143. package/dist/components/ui/tabs.js +29 -0
  144. package/dist/components/ui/terminal-tabs.d.ts +31 -0
  145. package/dist/components/ui/terminal-tabs.js +109 -0
  146. package/dist/components/ui/terminal-view.d.ts +51 -0
  147. package/dist/components/ui/terminal-view.js +189 -0
  148. package/dist/components/ui/textarea.d.ts +3 -0
  149. package/dist/components/ui/textarea.js +6 -0
  150. package/dist/components/ui/timeline.d.ts +9 -0
  151. package/dist/components/ui/timeline.js +18 -0
  152. package/dist/components/ui/toggle-group.d.ts +11 -0
  153. package/dist/components/ui/toggle-group.js +24 -0
  154. package/dist/components/ui/toggle.d.ts +8 -0
  155. package/dist/components/ui/toggle.js +26 -0
  156. package/dist/components/ui/tooltip.d.ts +6 -0
  157. package/dist/components/ui/tooltip.js +17 -0
  158. package/dist/components/ui/tree-view.d.ts +20 -0
  159. package/dist/components/ui/tree-view.js +41 -0
  160. package/dist/components/ui/window-frame.d.ts +35 -0
  161. package/dist/components/ui/window-frame.js +49 -0
  162. package/dist/lib/ai-markdown.d.ts +13 -0
  163. package/dist/lib/ai-markdown.js +46 -0
  164. package/dist/lib/command-risk.d.ts +6 -0
  165. package/dist/lib/command-risk.js +42 -0
  166. package/dist/lib/file-icons.d.ts +18 -0
  167. package/dist/lib/file-icons.js +136 -0
  168. package/dist/lib/file-kind.d.ts +10 -0
  169. package/dist/lib/file-kind.js +63 -0
  170. package/dist/lib/format.d.ts +9 -0
  171. package/dist/lib/format.js +30 -0
  172. package/dist/lib/i18n-core.d.ts +20 -0
  173. package/dist/lib/i18n-core.js +36 -0
  174. package/dist/lib/i18n.d.ts +15 -0
  175. package/dist/lib/i18n.js +68 -0
  176. package/dist/lib/icon-data.d.ts +276 -0
  177. package/dist/lib/icon-data.js +307 -0
  178. package/dist/lib/icon-shapes.d.ts +14 -0
  179. package/dist/lib/icon-shapes.js +47 -0
  180. package/dist/lib/log-filter.d.ts +23 -0
  181. package/dist/lib/log-filter.js +44 -0
  182. package/dist/lib/number-field.d.ts +11 -0
  183. package/dist/lib/number-field.js +30 -0
  184. package/dist/lib/pane-tree.d.ts +39 -0
  185. package/dist/lib/pane-tree.js +92 -0
  186. package/dist/lib/platform.d.ts +10 -0
  187. package/dist/lib/platform.js +24 -0
  188. package/dist/lib/shell-meta.d.ts +7 -0
  189. package/dist/lib/shell-meta.js +70 -0
  190. package/dist/lib/syntax.d.ts +16 -0
  191. package/dist/lib/syntax.js +540 -0
  192. package/dist/lib/tab-order.d.ts +6 -0
  193. package/dist/lib/tab-order.js +24 -0
  194. package/dist/lib/table-sort.d.ts +16 -0
  195. package/dist/lib/table-sort.js +66 -0
  196. package/dist/lib/terminal-themes.d.ts +30 -0
  197. package/dist/lib/terminal-themes.js +90 -0
  198. package/dist/lib/utils.d.ts +2 -0
  199. package/dist/lib/utils.js +5 -0
  200. package/dist-cdn/loccal-ui.css +971 -0
  201. package/dist-cdn/loccal-ui.min.js +1 -0
  202. package/dist-wc/base.d.ts +31 -0
  203. package/dist-wc/base.js +104 -0
  204. package/dist-wc/button.d.ts +12 -0
  205. package/dist-wc/button.js +47 -0
  206. package/dist-wc/calendar.d.ts +16 -0
  207. package/dist-wc/calendar.js +106 -0
  208. package/dist-wc/choice.d.ts +17 -0
  209. package/dist-wc/choice.js +76 -0
  210. package/dist-wc/command.d.ts +32 -0
  211. package/dist-wc/command.js +181 -0
  212. package/dist-wc/data-table.d.ts +22 -0
  213. package/dist-wc/data-table.js +128 -0
  214. package/dist-wc/dialog.d.ts +29 -0
  215. package/dist-wc/dialog.js +94 -0
  216. package/dist-wc/disclosure.d.ts +17 -0
  217. package/dist-wc/disclosure.js +91 -0
  218. package/dist-wc/fields2.d.ts +38 -0
  219. package/dist-wc/fields2.js +133 -0
  220. package/dist-wc/file-tree.d.ts +19 -0
  221. package/dist-wc/file-tree.js +97 -0
  222. package/dist-wc/floating.d.ts +32 -0
  223. package/dist-wc/floating.js +91 -0
  224. package/dist-wc/index.d.ts +23 -0
  225. package/dist-wc/index.js +24 -0
  226. package/dist-wc/input-otp.d.ts +14 -0
  227. package/dist-wc/input-otp.js +82 -0
  228. package/dist-wc/navigation-menu.d.ts +14 -0
  229. package/dist-wc/navigation-menu.js +75 -0
  230. package/dist-wc/number-field.d.ts +13 -0
  231. package/dist-wc/number-field.js +67 -0
  232. package/dist-wc/resizable.d.ts +14 -0
  233. package/dist-wc/resizable.js +57 -0
  234. package/dist-wc/select.d.ts +17 -0
  235. package/dist-wc/select.js +80 -0
  236. package/dist-wc/static.d.ts +1 -0
  237. package/dist-wc/static.js +175 -0
  238. package/dist-wc/status-bar.d.ts +11 -0
  239. package/dist-wc/status-bar.js +54 -0
  240. package/dist-wc/styles.css +971 -0
  241. package/dist-wc/tabs.d.ts +16 -0
  242. package/dist-wc/tabs.js +62 -0
  243. package/dist-wc/terminal-tabs.d.ts +16 -0
  244. package/dist-wc/terminal-tabs.js +79 -0
  245. package/dist-wc/toaster.d.ts +16 -0
  246. package/dist-wc/toaster.js +68 -0
  247. package/dist-wc/toggle.d.ts +30 -0
  248. package/dist-wc/toggle.js +101 -0
  249. package/dist-wc/tree.d.ts +17 -0
  250. package/dist-wc/tree.js +72 -0
  251. package/docs/ARQUITETURA-VANILLA.md +54 -0
  252. package/docs/VERSIONING.md +88 -0
  253. package/package.json +1078 -6
  254. package/styles.css +476 -0
@@ -0,0 +1,16 @@
1
+ import { type CalendarValue } from "@loccal/core";
2
+ import { LoccalElement } from "./base.ts";
3
+ /**
4
+ * `<loccal-calendar mode="single|multiple|range" value min max week-start hide-outside-days>`; `value`: "AAAA-MM-DD", lista separada por virgula
5
+ * (multiple) ou "de/ate" (range). Propriedades: `value` (string | string[] | { from, to }) e `disabledDates` (string[]).
6
+ * Eventos: `loccal-change` { value }, `loccal-month-change` { year, month }. Datas e nomes via Intl no idioma do componente.
7
+ */
8
+ export declare class LoccalCalendar extends LoccalElement {
9
+ #private;
10
+ static observedAttributes: string[];
11
+ get value(): CalendarValue;
12
+ set value(v: CalendarValue);
13
+ set disabledDates(v: string[]);
14
+ protected setup(): void;
15
+ protected update(): void;
16
+ }
@@ -0,0 +1,106 @@
1
+ import { applyAttrs, bindCalendar, CALENDAR_LABELS, createCalendar, DEFAULT_WEEK_START, getCalendarModel, getCalendarProps, resolveLabels, valueOf } from "@loccal/core";
2
+ import { define, el, LoccalElement } from "./base.js";
3
+ const parseAttr = (mode, v) => {
4
+ if (!v)
5
+ return null;
6
+ if (mode === "single")
7
+ return v;
8
+ if (mode === "multiple")
9
+ return v.split(",").map((x) => x.trim()).filter(Boolean);
10
+ const [from, to] = v.split("/");
11
+ return from ? { from, ...(to ? { to } : {}) } : null;
12
+ };
13
+ /**
14
+ * `<loccal-calendar mode="single|multiple|range" value min max week-start hide-outside-days>`; `value`: "AAAA-MM-DD", lista separada por virgula
15
+ * (multiple) ou "de/ate" (range). Propriedades: `value` (string | string[] | { from, to }) e `disabledDates` (string[]).
16
+ * Eventos: `loccal-change` { value }, `loccal-month-change` { year, month }. Datas e nomes via Intl no idioma do componente.
17
+ */
18
+ export class LoccalCalendar extends LoccalElement {
19
+ static observedAttributes = ["mode", "value", "min", "max", "week-start", "hide-outside-days", "today", "locale", "labels"];
20
+ #machine = createCalendar({}, {
21
+ onChange: (value) => this.emit("loccal-change", { value }),
22
+ onMonthChange: (year, month) => this.emit("loccal-month-change", { year, month }),
23
+ });
24
+ #pendingValue;
25
+ #pendingDisabled;
26
+ get value() {
27
+ return valueOf(this.#machine.state);
28
+ }
29
+ set value(v) {
30
+ if (this.ready)
31
+ this.#machine.send({ type: "SET_VALUE", value: v });
32
+ else
33
+ this.#pendingValue = v;
34
+ }
35
+ set disabledDates(v) {
36
+ if (this.ready)
37
+ this.#machine.patch({ disabledDates: v });
38
+ else
39
+ this.#pendingDisabled = v;
40
+ }
41
+ setup() {
42
+ this.own(bindCalendar(this, this.#machine));
43
+ this.own(this.#machine.subscribe(() => this.#render()));
44
+ }
45
+ update() {
46
+ const mode = this.getAttribute("mode") || "single";
47
+ const ws = this.getAttribute("week-start");
48
+ const today = this.getAttribute("today") ?? undefined;
49
+ this.#machine.patch({
50
+ mode,
51
+ min: this.getAttribute("min") ?? undefined,
52
+ max: this.getAttribute("max") ?? undefined,
53
+ weekStart: ws !== null ? Number(ws) : DEFAULT_WEEK_START[this.locale],
54
+ showOutside: !this.bool("hide-outside-days"),
55
+ ...(today ? { today } : {}),
56
+ ...(this.#pendingDisabled ? { disabledDates: this.#pendingDisabled } : {}),
57
+ });
58
+ this.#pendingDisabled = undefined;
59
+ const attr = this.getAttribute("value");
60
+ const next = this.#pendingValue !== undefined ? this.#pendingValue : attr !== null ? parseAttr(mode, attr) : undefined;
61
+ this.#pendingValue = undefined;
62
+ if (next !== undefined) {
63
+ this.#machine.send({ type: "SET_VALUE", value: next });
64
+ const first = typeof next === "string" ? next : Array.isArray(next) ? next[0] : next?.from;
65
+ if (first)
66
+ this.#machine.patch({ focus: first, year: Number(first.slice(0, 4)), month: Number(first.slice(5, 7)) - 1 });
67
+ }
68
+ this.#render();
69
+ }
70
+ #render() {
71
+ const s = this.#machine.state;
72
+ const l = resolveLabels(CALENDAR_LABELS, this.locale, this.labels);
73
+ const model = getCalendarModel(s, this.locale);
74
+ applyAttrs(this, getCalendarProps(s, "root", { label: this.getAttribute("aria-label") ?? l.label }));
75
+ const hadFocus = this.contains(document.activeElement) && document.activeElement.getAttribute("data-part") === "day";
76
+ const prev = el("button", {}, el("span", { "aria-hidden": "true" }, "‹"));
77
+ applyAttrs(prev, getCalendarProps(s, "prev", { label: l.prev }));
78
+ const next = el("button", {}, el("span", { "aria-hidden": "true" }, "›"));
79
+ applyAttrs(next, getCalendarProps(s, "next", { label: l.next }));
80
+ const title = el("div", {}, model.title);
81
+ applyAttrs(title, getCalendarProps(s, "title"));
82
+ const nav = el("div", {}, prev, title, next);
83
+ applyAttrs(nav, getCalendarProps(s, "nav"));
84
+ const head = el("tr", {}, ...model.weekdays.map((w) => {
85
+ const th = el("th", {}, w.short);
86
+ applyAttrs(th, getCalendarProps(s, "weekday", { label: w.long }));
87
+ return th;
88
+ }));
89
+ const body = el("tbody", {}, ...model.weeks.map((week) => el("tr", {}, ...week.map((d) => {
90
+ const td = el("td", {});
91
+ applyAttrs(td, getCalendarProps(s, "cell", { day: d }));
92
+ if (d.outside && !s.showOutside)
93
+ return td;
94
+ const b = el("button", {}, String(d.day));
95
+ applyAttrs(b, getCalendarProps(s, "day", { day: d }));
96
+ td.append(b);
97
+ return td;
98
+ }))));
99
+ const grid = el("table", {}, el("thead", {}, head), body);
100
+ applyAttrs(grid, getCalendarProps(s, "grid", { title: model.title }));
101
+ this.replaceChildren(nav, grid);
102
+ if (hadFocus)
103
+ this.querySelector(`[data-part=day][data-date="${s.focus}"]`)?.focus();
104
+ }
105
+ }
106
+ define("loccal-calendar", LoccalCalendar);
@@ -0,0 +1,17 @@
1
+ import { type ChoiceKind } from "@loccal/core";
2
+ import { LoccalElement } from "./base.ts";
3
+ declare abstract class ChoiceRoot extends LoccalElement {
4
+ #private;
5
+ static deferWhenEmpty: boolean;
6
+ static observedAttributes: string[];
7
+ protected abstract readonly kind: ChoiceKind;
8
+ protected setup(): void;
9
+ protected update(): void;
10
+ }
11
+ export declare class LoccalRadioGroup extends ChoiceRoot {
12
+ protected readonly kind: "radio-group";
13
+ }
14
+ export declare class LoccalToggleGroup extends ChoiceRoot {
15
+ protected readonly kind: "toggle-group";
16
+ }
17
+ export {};
@@ -0,0 +1,76 @@
1
+ import { applyAttrs, bindChoice, createChoice, getChoiceItemProps, getChoiceRootProps, syncChoiceRoving } from "@loccal/core";
2
+ import { define, LoccalElement } from "./base.js";
3
+ /** Item: envolve um `<button>` nativo; o elemento raiz aplica papel e estado. */
4
+ class LoccalChoiceItem extends LoccalElement {
5
+ static observedAttributes = ["disabled"];
6
+ setup() {
7
+ if (!this.querySelector(":scope > button")) {
8
+ const b = document.createElement("button");
9
+ b.append(...Array.from(this.childNodes));
10
+ this.append(b);
11
+ }
12
+ }
13
+ update() {
14
+ this.closest("loccal-radio-group, loccal-toggle-group")?.dispatchEvent(new CustomEvent("loccal-item-change"));
15
+ }
16
+ }
17
+ class ChoiceRoot extends LoccalElement {
18
+ static deferWhenEmpty = true;
19
+ static observedAttributes = ["value", "type", "disabled", "orientation"];
20
+ #m;
21
+ /** Criada sob demanda: `kind` so existe depois do construtor da subclasse. */
22
+ get #machine() {
23
+ return (this.#m ??= createChoice(this.kind, {}, (value) => {
24
+ this.setAttribute("value", value.join(" "));
25
+ this.emit("loccal-value-change", { value: this.kind === "radio-group" ? (value[0] ?? "") : value });
26
+ }));
27
+ }
28
+ setup() {
29
+ const click = (e) => {
30
+ const btn = e.target.closest(`button[data-slot="${this.kind}-item"]`);
31
+ if (btn && this.contains(btn) && !btn.disabled)
32
+ this.#machine.send({ type: "SELECT", value: btn.getAttribute("data-value") ?? "" });
33
+ };
34
+ this.addEventListener("click", click);
35
+ this.addEventListener("loccal-item-change", this.#render);
36
+ this.own(() => {
37
+ this.removeEventListener("click", click);
38
+ this.removeEventListener("loccal-item-change", this.#render);
39
+ });
40
+ this.own(bindChoice(this, this.kind));
41
+ this.own(this.#machine.subscribe(() => this.#render()));
42
+ }
43
+ #render = () => {
44
+ const s = this.#machine.state;
45
+ applyAttrs(this, getChoiceRootProps(s));
46
+ const tag = `loccal-${this.kind}-item`;
47
+ for (const host of this.querySelectorAll(tag)) {
48
+ const btn = host.querySelector("button");
49
+ if (btn)
50
+ applyAttrs(btn, getChoiceItemProps(s, host.getAttribute("value") ?? "", { disabled: host.hasAttribute("disabled") && host.getAttribute("disabled") !== "false" }));
51
+ }
52
+ syncChoiceRoving(this, this.kind);
53
+ };
54
+ update() {
55
+ const v = this.getAttribute("value");
56
+ this.#machine.patch({
57
+ type: this.kind === "toggle-group" && this.getAttribute("type") === "single" ? "single" : this.kind === "radio-group" ? "single" : "multiple",
58
+ disabled: this.bool("disabled"),
59
+ orientation: this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal",
60
+ value: v ? v.split(/\s+/).filter(Boolean) : [],
61
+ });
62
+ this.#render();
63
+ }
64
+ }
65
+ export class LoccalRadioGroup extends ChoiceRoot {
66
+ kind = "radio-group";
67
+ }
68
+ export class LoccalToggleGroup extends ChoiceRoot {
69
+ kind = "toggle-group";
70
+ }
71
+ define("loccal-radio-group", LoccalRadioGroup);
72
+ define("loccal-toggle-group", LoccalToggleGroup);
73
+ define("loccal-radio-group-item", class extends LoccalChoiceItem {
74
+ });
75
+ define("loccal-toggle-group-item", class extends LoccalChoiceItem {
76
+ });
@@ -0,0 +1,32 @@
1
+ import { type CommandItem, type HistoryItem } from "@loccal/core";
2
+ import { LoccalElement } from "./base.ts";
3
+ /**
4
+ * `<loccal-command placeholder no-filter query>` com a propriedade `items` ({ id, label, group?, meta?, mono?, keywords?, disabled? }).
5
+ * Busca sem acento, setas, Enter (ou clique) seleciona e Ctrl/Cmd+Enter executa. Eventos: `loccal-select` { item, run }, `loccal-query-change` { query }.
6
+ */
7
+ export declare class LoccalCommand extends LoccalElement {
8
+ #private;
9
+ static observedAttributes: string[];
10
+ get items(): CommandItem[];
11
+ set items(v: CommandItem[]);
12
+ get query(): string;
13
+ set query(q: string);
14
+ focus(): void;
15
+ protected setup(): void;
16
+ protected update(): void;
17
+ }
18
+ /**
19
+ * `<loccal-history-palette open now>` com a propriedade `items` ({ id, command, execCount?, executedMs? }). A busca e do chamador:
20
+ * escute `loccal-query-change` e atualize `items`. Enter insere, Ctrl+Enter executa, Esc fecha.
21
+ * Eventos: `loccal-insert` { item }, `loccal-run` { item }, `loccal-query-change` { query }, `loccal-open-change` { open }.
22
+ */
23
+ export declare class LoccalHistoryPalette extends LoccalElement {
24
+ #private;
25
+ static observedAttributes: string[];
26
+ get items(): HistoryItem[];
27
+ set items(v: HistoryItem[]);
28
+ get open(): boolean;
29
+ set open(v: boolean);
30
+ protected setup(): void;
31
+ protected update(): void;
32
+ }
@@ -0,0 +1,181 @@
1
+ import { applyAttrs, bindCommand, COMMAND_LABELS, createCommand, getCommandProps, HISTORY_PALETTE_LABELS, historyToCommandItem, resolveLabels, visibleCommandItems } from "@loccal/core";
2
+ import { define, el, LoccalElement } from "./base.js";
3
+ import { LoccalDialog } from "./dialog.js";
4
+ // Referencia o dialogo para garantir o registro de <loccal-dialog> mesmo com tree-shaking.
5
+ const REQUIRES = [LoccalDialog];
6
+ void REQUIRES;
7
+ /**
8
+ * `<loccal-command placeholder no-filter query>` com a propriedade `items` ({ id, label, group?, meta?, mono?, keywords?, disabled? }).
9
+ * Busca sem acento, setas, Enter (ou clique) seleciona e Ctrl/Cmd+Enter executa. Eventos: `loccal-select` { item, run }, `loccal-query-change` { query }.
10
+ */
11
+ export class LoccalCommand extends LoccalElement {
12
+ static observedAttributes = ["placeholder", "no-filter", "query", "locale", "labels", "aria-label"];
13
+ #machine = createCommand({}, {
14
+ onSelect: (item, o) => this.emit("loccal-select", { item, run: o.run }),
15
+ onQueryChange: (query) => this.emit("loccal-query-change", { query }),
16
+ });
17
+ #input;
18
+ #list;
19
+ #pending;
20
+ get items() {
21
+ return this.#machine.state.items;
22
+ }
23
+ set items(v) {
24
+ if (!this.ready)
25
+ this.#pending = v;
26
+ else
27
+ this.#machine.send({ type: "SET_ITEMS", items: v });
28
+ }
29
+ get query() {
30
+ return this.#machine.state.query;
31
+ }
32
+ set query(q) {
33
+ this.setAttribute("query", q);
34
+ }
35
+ focus() {
36
+ this.#input?.focus();
37
+ }
38
+ setup() {
39
+ this.#input = el("input", { "data-part": "input" });
40
+ this.#list = el("div", { "data-part": "list" });
41
+ this.replaceChildren(this.#input, this.#list);
42
+ if (this.#pending)
43
+ this.#machine.send({ type: "SET_ITEMS", items: this.#pending });
44
+ this.own(bindCommand(this, this.#machine));
45
+ this.own(this.#machine.subscribe(() => this.#render()));
46
+ }
47
+ update() {
48
+ const q = this.getAttribute("query");
49
+ this.#machine.patch({ filter: !this.bool("no-filter") });
50
+ if (q !== null && q !== this.#machine.state.query)
51
+ this.#machine.send({ type: "SET_QUERY", query: q });
52
+ this.#render();
53
+ }
54
+ #render() {
55
+ const s = this.#machine.state;
56
+ const l = resolveLabels(COMMAND_LABELS, this.locale, this.labels);
57
+ const base = this.uid;
58
+ applyAttrs(this, getCommandProps(s, "root", base));
59
+ const label = this.getAttribute("aria-label") ?? l.label;
60
+ applyAttrs(this.#input, getCommandProps(s, "input", base, { label, placeholder: this.getAttribute("placeholder") ?? l.placeholder }));
61
+ if (this.#input.value !== s.query)
62
+ this.#input.value = s.query;
63
+ applyAttrs(this.#list, getCommandProps(s, "list", base, { label }));
64
+ const visible = visibleCommandItems(s);
65
+ const nodes = [];
66
+ if (!visible.length)
67
+ nodes.push(el("div", getCommandProps(s, "empty", base), l.empty));
68
+ let group;
69
+ let box = null;
70
+ for (const item of visible) {
71
+ if (item.group !== group || (item.group && !box)) {
72
+ group = item.group;
73
+ box = group ? el("div", {}) : null;
74
+ if (box) {
75
+ applyAttrs(box, getCommandProps(s, "group", base, { group }));
76
+ box.append(el("div", { "data-part": "group-label", "aria-hidden": "true" }, group));
77
+ nodes.push(box);
78
+ }
79
+ }
80
+ const opt = el("div");
81
+ applyAttrs(opt, getCommandProps(s, "option", base, { item }));
82
+ opt.append(el("span", { "data-part": "label", ...(item.mono ? { "data-mono": "" } : {}) }, item.label));
83
+ if (item.meta)
84
+ opt.append(el("span", { "data-part": "meta" }, item.meta));
85
+ (box ?? { append: (n) => nodes.push(n) }).append(opt);
86
+ }
87
+ this.#list.replaceChildren(...nodes);
88
+ this.#list.querySelector("[data-active=true]")?.scrollIntoView?.({ block: "nearest" });
89
+ }
90
+ }
91
+ define("loccal-command", LoccalCommand);
92
+ /**
93
+ * `<loccal-history-palette open now>` com a propriedade `items` ({ id, command, execCount?, executedMs? }). A busca e do chamador:
94
+ * escute `loccal-query-change` e atualize `items`. Enter insere, Ctrl+Enter executa, Esc fecha.
95
+ * Eventos: `loccal-insert` { item }, `loccal-run` { item }, `loccal-query-change` { query }, `loccal-open-change` { open }.
96
+ */
97
+ export class LoccalHistoryPalette extends LoccalElement {
98
+ static observedAttributes = ["open", "now", "locale", "labels"];
99
+ #items = [];
100
+ #dialog;
101
+ #command;
102
+ #title;
103
+ #desc;
104
+ #footer;
105
+ get items() {
106
+ return this.#items;
107
+ }
108
+ set items(v) {
109
+ this.#items = v;
110
+ if (this.ready)
111
+ this.#sync();
112
+ }
113
+ get open() {
114
+ return this.hasAttribute("open");
115
+ }
116
+ set open(v) {
117
+ v ? this.setAttribute("open", "") : this.removeAttribute("open");
118
+ }
119
+ setup() {
120
+ this.#title = el("h2", { "data-part": "title" });
121
+ this.#desc = el("p", { "data-part": "description" });
122
+ this.#command = document.createElement("loccal-command");
123
+ this.#command.setAttribute("no-filter", "");
124
+ this.#footer = el("div", { "data-part": "footer" });
125
+ const content = el("div", { "data-part": "content" }, this.#title, this.#desc, this.#command, this.#footer);
126
+ this.#dialog = document.createElement("loccal-dialog");
127
+ this.#dialog.append(content);
128
+ this.replaceChildren(this.#dialog);
129
+ const onSelect = (e) => {
130
+ const { item, run } = e.detail;
131
+ const h = this.#items.find((x) => x.id === item.id);
132
+ if (!h)
133
+ return;
134
+ e.stopPropagation();
135
+ this.emit(run ? "loccal-run" : "loccal-insert", { item: h });
136
+ this.open = false;
137
+ };
138
+ const onQuery = (e) => {
139
+ e.stopPropagation();
140
+ this.emit("loccal-query-change", { query: e.detail.query });
141
+ };
142
+ const onOpen = (e) => {
143
+ if (e.target !== this.#dialog)
144
+ return;
145
+ e.stopPropagation();
146
+ const open = e.detail.open;
147
+ if (open !== this.open)
148
+ this.open = open;
149
+ if (!open)
150
+ this.#command.query = "";
151
+ else
152
+ queueMicrotask(() => this.#command.focus());
153
+ this.emit("loccal-open-change", { open });
154
+ };
155
+ this.#command.addEventListener("loccal-select", onSelect);
156
+ this.#command.addEventListener("loccal-query-change", onQuery);
157
+ this.#dialog.addEventListener("loccal-open-change", onOpen);
158
+ this.own(() => {
159
+ this.#command.removeEventListener("loccal-select", onSelect);
160
+ this.#command.removeEventListener("loccal-query-change", onQuery);
161
+ this.#dialog.removeEventListener("loccal-open-change", onOpen);
162
+ });
163
+ }
164
+ update() {
165
+ const l = resolveLabels(HISTORY_PALETTE_LABELS, this.locale, this.labels);
166
+ this.#title.textContent = l.title;
167
+ this.#desc.textContent = l.description;
168
+ this.#command.setAttribute("placeholder", l.placeholder);
169
+ this.#command.setAttribute("locale", this.locale);
170
+ this.#command.labels = { empty: l.empty, label: l.title };
171
+ this.#footer.textContent = `Enter ${l.insert} Ctrl+Enter ${l.run} Esc`;
172
+ if (this.#dialog.open !== this.open)
173
+ this.#dialog.open = this.open;
174
+ this.#sync();
175
+ }
176
+ #sync() {
177
+ const now = Number(this.getAttribute("now")) || Date.now();
178
+ this.#command.items = this.#items.map((h) => historyToCommandItem(h, now, this.locale));
179
+ }
180
+ }
181
+ define("loccal-history-palette", LoccalHistoryPalette);
@@ -0,0 +1,22 @@
1
+ import { type DataTableColumn } from "@loccal/core";
2
+ import { LoccalElement } from "./base.ts";
3
+ /**
4
+ * `<loccal-data-table selectable max-height caption row-key>` com as propriedades `rows`, `columns` ({ key, header, value?, cell?, sortable?, align?, width?, mono? }),
5
+ * `sort` ({ key, dir } | null) e `selected` (Set de ids); `rowId` opcional (funcao). Linhas de `row-key` (padrao "id") identificam cada item.
6
+ * Eventos: `loccal-sort-change` { sort }, `loccal-selected-change` { selected }, `loccal-activate` { row } (Enter ou duplo clique).
7
+ */
8
+ export declare class LoccalDataTable extends LoccalElement {
9
+ #private;
10
+ static observedAttributes: string[];
11
+ get rows(): readonly unknown[];
12
+ set rows(v: readonly unknown[]);
13
+ get columns(): readonly DataTableColumn[];
14
+ set columns(v: readonly DataTableColumn[]);
15
+ get sort(): import("@loccal/core").SortState;
16
+ set sort(v: import("@loccal/core").SortState);
17
+ get selected(): ReadonlySet<string>;
18
+ set selected(v: ReadonlySet<string> | string[]);
19
+ set rowId(fn: ((row: any) => string) | undefined);
20
+ protected setup(): void;
21
+ protected update(): void;
22
+ }
@@ -0,0 +1,128 @@
1
+ import { applyAttrs, bindDataTable, createDataTable, DATA_TABLE_LABELS, dataTableOrder, dataTableSelectedText, allState, cellText, getDataTableProps, resolveLabels, rowIdOf, sortedDataRows } from "@loccal/core";
2
+ import { define, el, LoccalElement } from "./base.js";
3
+ /**
4
+ * `<loccal-data-table selectable max-height caption row-key>` com as propriedades `rows`, `columns` ({ key, header, value?, cell?, sortable?, align?, width?, mono? }),
5
+ * `sort` ({ key, dir } | null) e `selected` (Set de ids); `rowId` opcional (funcao). Linhas de `row-key` (padrao "id") identificam cada item.
6
+ * Eventos: `loccal-sort-change` { sort }, `loccal-selected-change` { selected }, `loccal-activate` { row } (Enter ou duplo clique).
7
+ */
8
+ export class LoccalDataTable extends LoccalElement {
9
+ static observedAttributes = ["selectable", "max-height", "caption", "row-key", "locale", "labels"];
10
+ #machine = createDataTable({}, {
11
+ onSortChange: (sort) => this.emit("loccal-sort-change", { sort }),
12
+ onSelectedChange: (selected) => this.emit("loccal-selected-change", { selected }),
13
+ onActivate: (row) => this.emit("loccal-activate", { row }),
14
+ });
15
+ #pending = {};
16
+ #set(patch) {
17
+ if (this.ready)
18
+ this.#machine.patch(patch);
19
+ else
20
+ Object.assign(this.#pending, patch);
21
+ }
22
+ get rows() {
23
+ return this.#machine.state.rows;
24
+ }
25
+ set rows(v) {
26
+ this.#set({ rows: v });
27
+ }
28
+ get columns() {
29
+ return this.#machine.state.columns;
30
+ }
31
+ set columns(v) {
32
+ this.#set({ columns: v });
33
+ }
34
+ get sort() {
35
+ return this.#machine.state.sort;
36
+ }
37
+ set sort(v) {
38
+ this.#set({ sort: v ?? null });
39
+ }
40
+ get selected() {
41
+ return this.#machine.state.selected;
42
+ }
43
+ set selected(v) {
44
+ this.#set({ selected: new Set(v) });
45
+ }
46
+ set rowId(fn) {
47
+ this.#set({ rowId: fn });
48
+ }
49
+ setup() {
50
+ this.#machine.patch(this.#pending);
51
+ this.own(bindDataTable(this, this.#machine));
52
+ this.own(this.#machine.subscribe(() => this.#render()));
53
+ }
54
+ update() {
55
+ this.#machine.patch({ selectable: this.bool("selectable"), rowKey: this.getAttribute("row-key") ?? "id" });
56
+ this.#render();
57
+ }
58
+ #render() {
59
+ const s = this.#machine.state;
60
+ const l = resolveLabels(DATA_TABLE_LABELS, this.locale, this.labels);
61
+ applyAttrs(this, getDataTableProps(s, "root"));
62
+ const order = dataTableOrder(s);
63
+ const rows = sortedDataRows(s);
64
+ const all = allState(order, s.selected);
65
+ const headRow = el("tr", { "data-part": "head-row" });
66
+ const check = (state, label, id) => {
67
+ const b = el("button", {});
68
+ applyAttrs(b, getDataTableProps(s, "check", { state, label, id }));
69
+ b.append(el("span", { "data-part": "check-box", "data-state": state }));
70
+ return b;
71
+ };
72
+ if (s.selectable)
73
+ headRow.append(Object.assign(el("th", { "data-part": "th", "data-kind": "check", scope: "col" }), {}));
74
+ if (s.selectable)
75
+ headRow.lastElementChild.append(check(all, l.selectAll));
76
+ for (const c of s.columns) {
77
+ const th = el("th", {});
78
+ applyAttrs(th, getDataTableProps(s, "th", { column: c }));
79
+ if (c.width)
80
+ th.style.width = c.width;
81
+ if (c.sortable) {
82
+ const b = el("button", {});
83
+ applyAttrs(b, getDataTableProps(s, "sort", { column: c }));
84
+ b.append(el("span", { "data-part": "th-label" }, c.header));
85
+ if (s.sort?.key === c.key)
86
+ b.append(el("span", { "data-part": "sort-icon", "data-dir": s.sort.dir, role: "img", "aria-label": s.sort.dir === "asc" ? l.sortedAsc : l.sortedDesc }, s.sort.dir === "asc" ? "↑" : "↓"));
87
+ th.append(b);
88
+ }
89
+ else
90
+ th.append(el("span", { "data-part": "th-label" }, c.header));
91
+ headRow.append(th);
92
+ }
93
+ const tbody = el("tbody", {});
94
+ if (!rows.length) {
95
+ const td = el("td", { "data-part": "empty", colspan: String(s.columns.length + (s.selectable ? 1 : 0)) }, l.empty);
96
+ tbody.append(el("tr", {}, td));
97
+ }
98
+ rows.forEach((row, i) => {
99
+ const id = rowIdOf(s, row);
100
+ const tr = el("tr", {});
101
+ applyAttrs(tr, getDataTableProps(s, "row", { index: i, id }));
102
+ if (s.selectable) {
103
+ const td = el("td", { "data-part": "cell", "data-kind": "check" });
104
+ td.append(check(s.selected.has(id) ? "all" : "none", l.selectRow, id));
105
+ tr.append(td);
106
+ }
107
+ for (const c of s.columns)
108
+ tr.append(el("td", { "data-part": "cell", "data-align": c.align ?? "left", ...(c.mono ? { "data-mono": "" } : {}) }, cellText(c, row)));
109
+ tbody.append(tr);
110
+ });
111
+ const table = el("table", {}, ...(this.getAttribute("caption") ? [el("caption", { "data-part": "caption" }, this.getAttribute("caption"))] : []), el("thead", {}, headRow), tbody);
112
+ applyAttrs(table, getDataTableProps(s, "table"));
113
+ const scroller = el("div", {}, table);
114
+ applyAttrs(scroller, getDataTableProps(s, "scroller", { maxHeight: this.getAttribute("max-height") ?? undefined }));
115
+ const nodes = [scroller];
116
+ if (s.selectable && s.selected.size > 0) {
117
+ const f = el("div", {}, dataTableSelectedText(l, s.selected.size));
118
+ applyAttrs(f, getDataTableProps(s, "footer"));
119
+ nodes.push(f);
120
+ }
121
+ const hadFocus = this.contains(document.activeElement) && document.activeElement.getAttribute("data-part") === "row";
122
+ const idx = hadFocus ? Number(document.activeElement.getAttribute("data-index")) : -1;
123
+ this.replaceChildren(...nodes);
124
+ if (hadFocus)
125
+ this.querySelectorAll("tbody [data-part=row]")[idx]?.focus();
126
+ }
127
+ }
128
+ define("loccal-data-table", LoccalDataTable);
@@ -0,0 +1,29 @@
1
+ import { type DialogVariant } from "@loccal/core";
2
+ import { LoccalElement } from "./base.ts";
3
+ /**
4
+ * `<loccal-dialog open modal close-on-escape close-on-outside>` com partes `[data-part]`:
5
+ * trigger, content (obrigatorio), title, description, close. O backdrop e criado se nao existir.
6
+ * Evento: `loccal-open-change` { open }.
7
+ */
8
+ export declare class LoccalDialog extends LoccalElement {
9
+ #private;
10
+ static deferWhenEmpty: boolean;
11
+ static observedAttributes: string[];
12
+ /** Variante padrao do elemento (sheet, drawer e alert-dialog reaproveitam esta classe). */
13
+ static defaultVariant: DialogVariant;
14
+ get open(): boolean;
15
+ set open(v: boolean);
16
+ show(): void;
17
+ close(): void;
18
+ protected setup(): void;
19
+ protected update(): void;
20
+ }
21
+ export declare class LoccalSheet extends LoccalDialog {
22
+ static defaultVariant: DialogVariant;
23
+ }
24
+ export declare class LoccalDrawer extends LoccalDialog {
25
+ static defaultVariant: DialogVariant;
26
+ }
27
+ export declare class LoccalAlertDialog extends LoccalDialog {
28
+ static defaultVariant: DialogVariant;
29
+ }