@zazz-ui/core 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 (260) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -0
  4. package/dist/sri.json +75 -0
  5. package/dist/zazz.css +1 -0
  6. package/dist/zazz.js +1 -0
  7. package/examples/about.html +590 -0
  8. package/examples/components.html +1040 -0
  9. package/examples/forms.html +511 -0
  10. package/examples/index.html +268 -0
  11. package/examples/layout.html +320 -0
  12. package/examples/products.html +846 -0
  13. package/examples/responsive.html +339 -0
  14. package/package.json +85 -0
  15. package/src/base/_layers.css +12 -0
  16. package/src/base/_layout.css +568 -0
  17. package/src/base/_reset.css +515 -0
  18. package/src/base/_typography.css +495 -0
  19. package/src/base/_utilities.css +6628 -0
  20. package/src/base/_variables.css +682 -0
  21. package/src/base/_view-transitions.css +103 -0
  22. package/src/base/command-score.d.ts +12 -0
  23. package/src/base/command-score.d.ts.map +1 -0
  24. package/src/base/command-score.js +151 -0
  25. package/src/base/command-score.ts +192 -0
  26. package/src/base/dialog-lifecycle.d.ts +11 -0
  27. package/src/base/dialog-lifecycle.d.ts.map +1 -0
  28. package/src/base/dialog-lifecycle.js +65 -0
  29. package/src/base/dialog-lifecycle.ts +80 -0
  30. package/src/base/embla.d.ts +90 -0
  31. package/src/base/embla.d.ts.map +1 -0
  32. package/src/base/embla.js +643 -0
  33. package/src/base/embla.ts +791 -0
  34. package/src/base/hotkeys.d.ts +82 -0
  35. package/src/base/hotkeys.d.ts.map +1 -0
  36. package/src/base/hotkeys.js +141 -0
  37. package/src/base/hotkeys.ts +195 -0
  38. package/src/base/navigation.d.ts +2 -0
  39. package/src/base/navigation.d.ts.map +1 -0
  40. package/src/base/navigation.js +136 -0
  41. package/src/base/navigation.ts +151 -0
  42. package/src/base/reveal.d.ts +80 -0
  43. package/src/base/reveal.d.ts.map +1 -0
  44. package/src/base/reveal.js +305 -0
  45. package/src/base/reveal.ts +379 -0
  46. package/src/base/signals.d.ts +89 -0
  47. package/src/base/signals.d.ts.map +1 -0
  48. package/src/base/signals.js +134 -0
  49. package/src/base/signals.ts +164 -0
  50. package/src/base/typeahead.d.ts +105 -0
  51. package/src/base/typeahead.d.ts.map +1 -0
  52. package/src/base/typeahead.js +411 -0
  53. package/src/base/typeahead.ts +500 -0
  54. package/src/base/utils.d.ts +56 -0
  55. package/src/base/utils.d.ts.map +1 -0
  56. package/src/base/utils.js +88 -0
  57. package/src/base/utils.ts +98 -0
  58. package/src/base/zazz-element.d.ts +44 -0
  59. package/src/base/zazz-element.d.ts.map +1 -0
  60. package/src/base/zazz-element.js +59 -0
  61. package/src/base/zazz-element.ts +73 -0
  62. package/src/globals.d.ts +148 -0
  63. package/src/head.d.ts +95 -0
  64. package/src/head.d.ts.map +1 -0
  65. package/src/head.js +311 -0
  66. package/src/head.ts +433 -0
  67. package/src/index.css +71 -0
  68. package/src/index.d.ts +36 -0
  69. package/src/index.d.ts.map +1 -0
  70. package/src/index.js +35 -0
  71. package/src/index.ts +36 -0
  72. package/src/manifest.d.ts +90 -0
  73. package/src/manifest.d.ts.map +1 -0
  74. package/src/manifest.js +614 -0
  75. package/src/manifest.ts +667 -0
  76. package/src/primitives/accordion/accordion.css +104 -0
  77. package/src/primitives/accordion/accordion.html +69 -0
  78. package/src/primitives/alert-dialog/alert-dialog.css +38 -0
  79. package/src/primitives/alert-dialog/alert-dialog.html +53 -0
  80. package/src/primitives/autocomplete/autocomplete-groups.html +77 -0
  81. package/src/primitives/autocomplete/autocomplete.css +114 -0
  82. package/src/primitives/autocomplete/autocomplete.d.ts +30 -0
  83. package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -0
  84. package/src/primitives/autocomplete/autocomplete.html +66 -0
  85. package/src/primitives/autocomplete/autocomplete.js +41 -0
  86. package/src/primitives/autocomplete/autocomplete.ts +46 -0
  87. package/src/primitives/avatar/avatar.html +44 -0
  88. package/src/primitives/badge/badge-icon.html +36 -0
  89. package/src/primitives/badge/badge.css +251 -0
  90. package/src/primitives/badge/badge.html +7 -0
  91. package/src/primitives/breadcrumbs/breadcrumbs.html +9 -0
  92. package/src/primitives/button/button-icon-only.html +84 -0
  93. package/src/primitives/button/button-icon.html +82 -0
  94. package/src/primitives/button/button.css +319 -0
  95. package/src/primitives/button/button.html +8 -0
  96. package/src/primitives/button-group/button-group-vertical.html +6 -0
  97. package/src/primitives/button-group/button-group.css +94 -0
  98. package/src/primitives/button-group/button-group.html +64 -0
  99. package/src/primitives/card/card-subgrid.html +118 -0
  100. package/src/primitives/card/card.html +53 -0
  101. package/src/primitives/carousel/carousel.css +61 -0
  102. package/src/primitives/carousel/carousel.d.ts +16 -0
  103. package/src/primitives/carousel/carousel.d.ts.map +1 -0
  104. package/src/primitives/carousel/carousel.html +315 -0
  105. package/src/primitives/carousel/carousel.js +73 -0
  106. package/src/primitives/carousel/carousel.ts +84 -0
  107. package/src/primitives/checkbox/checkbox-tasklist.html +71 -0
  108. package/src/primitives/checkbox/checkbox.css +82 -0
  109. package/src/primitives/checkbox/checkbox.d.ts +21 -0
  110. package/src/primitives/checkbox/checkbox.d.ts.map +1 -0
  111. package/src/primitives/checkbox/checkbox.html +17 -0
  112. package/src/primitives/checkbox/checkbox.js +190 -0
  113. package/src/primitives/checkbox/checkbox.ts +219 -0
  114. package/src/primitives/combobox/combobox-multiselect.html +91 -0
  115. package/src/primitives/combobox/combobox.css +307 -0
  116. package/src/primitives/combobox/combobox.d.ts +100 -0
  117. package/src/primitives/combobox/combobox.d.ts.map +1 -0
  118. package/src/primitives/combobox/combobox.html +73 -0
  119. package/src/primitives/combobox/combobox.js +503 -0
  120. package/src/primitives/combobox/combobox.ts +559 -0
  121. package/src/primitives/command/command-actions.d.ts +31 -0
  122. package/src/primitives/command/command-actions.d.ts.map +1 -0
  123. package/src/primitives/command/command-actions.html +89 -0
  124. package/src/primitives/command/command-actions.js +70 -0
  125. package/src/primitives/command/command-actions.ts +77 -0
  126. package/src/primitives/command/command-dialog.html +77 -0
  127. package/src/primitives/command/command.css +151 -0
  128. package/src/primitives/command/command.d.ts +52 -0
  129. package/src/primitives/command/command.d.ts.map +1 -0
  130. package/src/primitives/command/command.html +119 -0
  131. package/src/primitives/command/command.js +146 -0
  132. package/src/primitives/command/command.ts +157 -0
  133. package/src/primitives/dialog/dialog-with-form.html +200 -0
  134. package/src/primitives/dialog/dialog.css +229 -0
  135. package/src/primitives/dialog/dialog.html +90 -0
  136. package/src/primitives/fields/fields.css +278 -0
  137. package/src/primitives/input/input-icon-leading.html +19 -0
  138. package/src/primitives/input/input-icon-trailing.html +18 -0
  139. package/src/primitives/input/input.css +114 -0
  140. package/src/primitives/input/input.html +61 -0
  141. package/src/primitives/input-group/input-group-password-group.html +108 -0
  142. package/src/primitives/input-group/input-group.css +215 -0
  143. package/src/primitives/input-group/input-group.html +132 -0
  144. package/src/primitives/kbd/kbd-group.html +18 -0
  145. package/src/primitives/kbd/kbd.css +87 -0
  146. package/src/primitives/kbd/kbd.html +7 -0
  147. package/src/primitives/lightbox/lightbox.css +459 -0
  148. package/src/primitives/lightbox/lightbox.d.ts +7 -0
  149. package/src/primitives/lightbox/lightbox.d.ts.map +1 -0
  150. package/src/primitives/lightbox/lightbox.html +665 -0
  151. package/src/primitives/lightbox/lightbox.js +96 -0
  152. package/src/primitives/lightbox/lightbox.ts +113 -0
  153. package/src/primitives/menu/menu-interest.html +52 -0
  154. package/src/primitives/menu/menu.css +55 -0
  155. package/src/primitives/menu/menu.d.ts +38 -0
  156. package/src/primitives/menu/menu.d.ts.map +1 -0
  157. package/src/primitives/menu/menu.html +70 -0
  158. package/src/primitives/menu/menu.js +117 -0
  159. package/src/primitives/menu/menu.ts +131 -0
  160. package/src/primitives/menubar/menubar-help-search.html +103 -0
  161. package/src/primitives/menubar/menubar.html +166 -0
  162. package/src/primitives/meter/meter.css +178 -0
  163. package/src/primitives/meter/meter.html +38 -0
  164. package/src/primitives/mobile-menu/mobile-menu.css +145 -0
  165. package/src/primitives/mobile-menu/mobile-menu.html +614 -0
  166. package/src/primitives/navigation-menu/navigation-menu-featured.html +76 -0
  167. package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +158 -0
  168. package/src/primitives/navigation-menu/navigation-menu-interest.html +103 -0
  169. package/src/primitives/navigation-menu/navigation-menu-megamenu.html +141 -0
  170. package/src/primitives/navigation-menu/navigation-menu-simple.html +96 -0
  171. package/src/primitives/navigation-menu/navigation-menu.css +295 -0
  172. package/src/primitives/navigation-menu/navigation-menu.html +576 -0
  173. package/src/primitives/otp/otp.css +126 -0
  174. package/src/primitives/otp/otp.d.ts +89 -0
  175. package/src/primitives/otp/otp.d.ts.map +1 -0
  176. package/src/primitives/otp/otp.html +22 -0
  177. package/src/primitives/otp/otp.js +226 -0
  178. package/src/primitives/otp/otp.ts +279 -0
  179. package/src/primitives/password-group/password-group.css +238 -0
  180. package/src/primitives/password-group/password-group.d.ts +25 -0
  181. package/src/primitives/password-group/password-group.d.ts.map +1 -0
  182. package/src/primitives/password-group/password-group.html +109 -0
  183. package/src/primitives/password-group/password-group.js +76 -0
  184. package/src/primitives/password-group/password-group.ts +95 -0
  185. package/src/primitives/popover/popover.css +233 -0
  186. package/src/primitives/progress/progress-indeterminate.html +1 -0
  187. package/src/primitives/progress/progress.css +105 -0
  188. package/src/primitives/progress/progress.html +7 -0
  189. package/src/primitives/prose/prose.html +65 -0
  190. package/src/primitives/radio/radio.css +84 -0
  191. package/src/primitives/radio/radio.html +17 -0
  192. package/src/primitives/reveal/reveal.css +167 -0
  193. package/src/primitives/select/multiselect.d.ts +43 -0
  194. package/src/primitives/select/multiselect.d.ts.map +1 -0
  195. package/src/primitives/select/multiselect.js +147 -0
  196. package/src/primitives/select/multiselect.ts +188 -0
  197. package/src/primitives/select/select-align.html +49 -0
  198. package/src/primitives/select/select-multiple.html +12 -0
  199. package/src/primitives/select/select-sides.html +65 -0
  200. package/src/primitives/select/select.css +481 -0
  201. package/src/primitives/select/select.html +16 -0
  202. package/src/primitives/separator/separator.css +49 -0
  203. package/src/primitives/separator/separator.html +16 -0
  204. package/src/primitives/slider/slider.css +122 -0
  205. package/src/primitives/slider/slider.html +1 -0
  206. package/src/primitives/switch/switch.css +126 -0
  207. package/src/primitives/switch/switch.html +13 -0
  208. package/src/primitives/table/table-alternating.html +36 -0
  209. package/src/primitives/table/table-grid.html +30 -0
  210. package/src/primitives/table/table-size-sm.html +26 -0
  211. package/src/primitives/table/table.css +158 -0
  212. package/src/primitives/table/table.html +45 -0
  213. package/src/primitives/tabs/tabs.css +328 -0
  214. package/src/primitives/tabs/tabs.d.ts +35 -0
  215. package/src/primitives/tabs/tabs.d.ts.map +1 -0
  216. package/src/primitives/tabs/tabs.html +75 -0
  217. package/src/primitives/tabs/tabs.js +84 -0
  218. package/src/primitives/tabs/tabs.ts +93 -0
  219. package/src/primitives/textarea/textarea.css +78 -0
  220. package/src/primitives/textarea/textarea.html +10 -0
  221. package/src/primitives/toaster/toaster.css +309 -0
  222. package/src/primitives/toaster/toaster.d.ts +138 -0
  223. package/src/primitives/toaster/toaster.d.ts.map +1 -0
  224. package/src/primitives/toaster/toaster.html +77 -0
  225. package/src/primitives/toaster/toaster.js +736 -0
  226. package/src/primitives/toaster/toaster.ts +823 -0
  227. package/src/primitives/toggle/toggle.css +295 -0
  228. package/src/primitives/toggle/toggle.html +68 -0
  229. package/src/primitives/toggle-group/toggle-group-multiple.html +14 -0
  230. package/src/primitives/toggle-group/toggle-group-vertical.html +14 -0
  231. package/src/primitives/toggle-group/toggle-group.css +73 -0
  232. package/src/primitives/toggle-group/toggle-group.html +53 -0
  233. package/src/primitives/toolbar/toolbar.html +45 -0
  234. package/src/primitives/tooltip/tooltip-disabled.html +19 -0
  235. package/src/primitives/tooltip/tooltip-sides.html +57 -0
  236. package/src/primitives/tooltip/tooltip-with-kbd.html +31 -0
  237. package/src/primitives/tooltip/tooltip.css +235 -0
  238. package/src/primitives/tooltip/tooltip.html +12 -0
  239. package/src/primitives/utilities/aspect-ratio.html +17 -0
  240. package/src/primitives/utilities/basis.html +27 -0
  241. package/src/primitives/utilities/col-span.html +23 -0
  242. package/src/primitives/utilities/compose.html +19 -0
  243. package/src/primitives/utilities/flex-align.html +26 -0
  244. package/src/primitives/utilities/flex-direction.html +36 -0
  245. package/src/primitives/utilities/flex-grow.html +17 -0
  246. package/src/primitives/utilities/gap.html +62 -0
  247. package/src/primitives/utilities/grid-cols.html +20 -0
  248. package/src/primitives/utilities/grid-pile.html +5 -0
  249. package/src/primitives/utilities/grid-responsive.html +31 -0
  250. package/src/primitives/utilities/margin-auto.html +13 -0
  251. package/src/primitives/utilities/object-fit.html +41 -0
  252. package/src/primitives/utilities/order.html +17 -0
  253. package/src/primitives/utilities/overflow.html +26 -0
  254. package/src/primitives/utilities/padding-compose.html +23 -0
  255. package/src/primitives/utilities/padding.html +30 -0
  256. package/src/primitives/utilities/position.html +13 -0
  257. package/src/primitives/utilities/responsive-flex.html +22 -0
  258. package/src/primitives/utilities/responsive-grid.html +31 -0
  259. package/src/primitives/utilities/size.html +22 -0
  260. package/src/primitives/utilities/width.html +22 -0
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview `<ui-command>`: a command menu for search and quick actions.
4
+ * @description Light-DOM custom element on the shared typeahead engine
5
+ * (`base/typeahead.ts`), architected after cmdk. The panel (a `popover="auto"`
6
+ * dropdown or a `<dialog class="ui-dialog">`) contains the search input;
7
+ * items rank by match score and the best match auto-highlights.
8
+ *
9
+ * Actions are the platform's own vocabulary: navigation items are real
10
+ * `<a href>` links, and action items are `<button command commandfor>` invoker
11
+ * buttons (including custom `--commands`). Enter activates the highlighted
12
+ * item exactly as a click would; every activation also dispatches a bubbling
13
+ * `zazz:command-select` CustomEvent (`detail: { item, value }`) from the root.
14
+ * Without JavaScript the trigger still opens the panel natively and every
15
+ * item still works: only filtering, highlight, and hotkeys are lost.
16
+ *
17
+ * Attributes:
18
+ * - `data-command-hotkey` (root): global toggle shortcut, e.g. `"mod+k"`.
19
+ * - `data-hotkey` (item): global accelerator that activates the item, active
20
+ * while the element is connected (even with the panel closed).
21
+ * - `data-stay-open` (item): keep the panel open after activation.
22
+ * - `data-sort="document"` (root): opt out of score ranking (default: score).
23
+ *
24
+ * Parts: `command-open` (trigger), `command-panel`, `command-header`,
25
+ * `command-input`, `command-list`, `command-group` / `command-group-label`,
26
+ * `command-item` (`data-value`, `data-keywords`), `command-kbd`,
27
+ * `command-footer`, `command-empty`.
28
+ *
29
+ * For complex custom actions, see the example `command-actions.ts`: listen
30
+ * for your `--command` on its target, or for `zazz:command-select` on the root.
31
+ */
32
+ import { TypeaheadElement } from "../../base/typeahead.js";
33
+ import { bindHotkey } from "../../base/hotkeys.js";
34
+ import { defineZazzElement } from "../../base/zazz-element.js";
35
+ class UiCommand extends TypeaheadElement {
36
+ slotPrefix = "command";
37
+ managesPanel = false;
38
+ autoHighlight = true;
39
+ /** Command ranks by score unless the author opts back into DOM order. */
40
+ get sortByScore() {
41
+ return this.getAttribute("data-sort") !== "document";
42
+ }
43
+ setup(signal) {
44
+ super.setup(signal);
45
+ const input = this.searchInput;
46
+ const panel = this.panel;
47
+ if (!input || !panel)
48
+ return;
49
+ // Global toggle shortcut on the root
50
+ const toggleSpec = this.getAttribute("data-command-hotkey");
51
+ if (toggleSpec) {
52
+ bindHotkey(toggleSpec, () => this.#togglePanel(), { signal });
53
+ }
54
+ // Per-item accelerators: global while connected, panel open or not
55
+ for (const item of this.items()) {
56
+ const spec = item.getAttribute("data-hotkey");
57
+ if (spec) {
58
+ bindHotkey(spec, () => this.#activate(item, true), { signal });
59
+ }
60
+ }
61
+ // Reset the search whenever the panel closes, so it reopens fresh
62
+ const reset = () => {
63
+ input.value = "";
64
+ this.query.set("");
65
+ this.activeIndex.set(0);
66
+ };
67
+ if (panel instanceof HTMLDialogElement) {
68
+ this.addEventListener("zazz:dialog-close", (event) => {
69
+ if (event.target === panel)
70
+ reset();
71
+ }, { signal });
72
+ }
73
+ else {
74
+ panel.addEventListener("toggle", (event) => {
75
+ if (event.newState === "closed")
76
+ reset();
77
+ }, { signal });
78
+ }
79
+ }
80
+ /**
81
+ * @description A pointer commit has already run the item's native activation
82
+ * (link navigation, invoker command); a keyboard commit runs it via
83
+ * `click()`. Both announce `zazz:command-select` and close the panel unless
84
+ * the item asks to stay open.
85
+ *
86
+ * @param item - The activated item.
87
+ * @param source - How the commit happened.
88
+ */
89
+ commit(item, source) {
90
+ this.#activate(item, source === "keyboard");
91
+ }
92
+ /**
93
+ * @description Runs one item's activation: optional synthetic click,
94
+ * `zazz:command-select`, then close (unless `data-stay-open`).
95
+ *
96
+ * @param item - The item to activate.
97
+ * @param click - Whether to run the native activation via `click()`.
98
+ * @private
99
+ */
100
+ #activate(item, click) {
101
+ this.dispatchEvent(new CustomEvent("zazz:command-select", {
102
+ bubbles: true,
103
+ detail: { item, value: this.itemValue(item) },
104
+ }));
105
+ if (click)
106
+ item.click();
107
+ if (!item.hasAttribute("data-stay-open"))
108
+ this.#closePanel();
109
+ }
110
+ /**
111
+ * @description Opens or closes the panel, branching on its surface.
112
+ * @private
113
+ */
114
+ #togglePanel() {
115
+ const panel = this.panel;
116
+ if (!panel)
117
+ return;
118
+ if (panel instanceof HTMLDialogElement) {
119
+ if (panel.open)
120
+ panel.close();
121
+ else
122
+ panel.showModal();
123
+ }
124
+ else {
125
+ panel.togglePopover();
126
+ }
127
+ }
128
+ /**
129
+ * @description Closes the panel, branching on its surface.
130
+ * @private
131
+ */
132
+ #closePanel() {
133
+ const panel = this.panel;
134
+ if (!panel)
135
+ return;
136
+ if (panel instanceof HTMLDialogElement) {
137
+ if (panel.open)
138
+ panel.close();
139
+ }
140
+ else if (panel.matches(":popover-open, .\\:popover-open")) {
141
+ panel.hidePopover();
142
+ }
143
+ }
144
+ }
145
+ defineZazzElement("ui-command", UiCommand);
146
+ export { UiCommand };
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview `<ui-command>`: a command menu for search and quick actions.
5
+ * @description Light-DOM custom element on the shared typeahead engine
6
+ * (`base/typeahead.ts`), architected after cmdk. The panel (a `popover="auto"`
7
+ * dropdown or a `<dialog class="ui-dialog">`) contains the search input;
8
+ * items rank by match score and the best match auto-highlights.
9
+ *
10
+ * Actions are the platform's own vocabulary: navigation items are real
11
+ * `<a href>` links, and action items are `<button command commandfor>` invoker
12
+ * buttons (including custom `--commands`). Enter activates the highlighted
13
+ * item exactly as a click would; every activation also dispatches a bubbling
14
+ * `zazz:command-select` CustomEvent (`detail: { item, value }`) from the root.
15
+ * Without JavaScript the trigger still opens the panel natively and every
16
+ * item still works: only filtering, highlight, and hotkeys are lost.
17
+ *
18
+ * Attributes:
19
+ * - `data-command-hotkey` (root): global toggle shortcut, e.g. `"mod+k"`.
20
+ * - `data-hotkey` (item): global accelerator that activates the item, active
21
+ * while the element is connected (even with the panel closed).
22
+ * - `data-stay-open` (item): keep the panel open after activation.
23
+ * - `data-sort="document"` (root): opt out of score ranking (default: score).
24
+ *
25
+ * Parts: `command-open` (trigger), `command-panel`, `command-header`,
26
+ * `command-input`, `command-list`, `command-group` / `command-group-label`,
27
+ * `command-item` (`data-value`, `data-keywords`), `command-kbd`,
28
+ * `command-footer`, `command-empty`.
29
+ *
30
+ * For complex custom actions, see the example `command-actions.ts`: listen
31
+ * for your `--command` on its target, or for `zazz:command-select` on the root.
32
+ */
33
+
34
+ import { TypeaheadElement } from "../../base/typeahead.ts";
35
+ import { bindHotkey } from "../../base/hotkeys.ts";
36
+ import { defineZazzElement } from "../../base/zazz-element.ts";
37
+
38
+ class UiCommand extends TypeaheadElement {
39
+ protected readonly slotPrefix = "command";
40
+ protected readonly managesPanel: boolean = false;
41
+ protected readonly autoHighlight: boolean = true;
42
+
43
+ /** Command ranks by score unless the author opts back into DOM order. */
44
+ protected get sortByScore(): boolean {
45
+ return this.getAttribute("data-sort") !== "document";
46
+ }
47
+
48
+ protected setup(signal: AbortSignal): void {
49
+ super.setup(signal);
50
+ const input = this.searchInput;
51
+ const panel = this.panel;
52
+ if (!input || !panel) return;
53
+
54
+ // Global toggle shortcut on the root
55
+ const toggleSpec = this.getAttribute("data-command-hotkey");
56
+ if (toggleSpec) {
57
+ bindHotkey(toggleSpec, () => this.#togglePanel(), { signal });
58
+ }
59
+
60
+ // Per-item accelerators: global while connected, panel open or not
61
+ for (const item of this.items()) {
62
+ const spec = item.getAttribute("data-hotkey");
63
+ if (spec) {
64
+ bindHotkey(spec, () => this.#activate(item, true), { signal });
65
+ }
66
+ }
67
+
68
+ // Reset the search whenever the panel closes, so it reopens fresh
69
+ const reset = (): void => {
70
+ input.value = "";
71
+ this.query.set("");
72
+ this.activeIndex.set(0);
73
+ };
74
+ if (panel instanceof HTMLDialogElement) {
75
+ this.addEventListener(
76
+ "zazz:dialog-close",
77
+ (event) => {
78
+ if (event.target === panel) reset();
79
+ },
80
+ { signal },
81
+ );
82
+ } else {
83
+ panel.addEventListener(
84
+ "toggle",
85
+ (event) => {
86
+ if ((event as ToggleEvent).newState === "closed") reset();
87
+ },
88
+ { signal },
89
+ );
90
+ }
91
+ }
92
+
93
+ /**
94
+ * @description A pointer commit has already run the item's native activation
95
+ * (link navigation, invoker command); a keyboard commit runs it via
96
+ * `click()`. Both announce `zazz:command-select` and close the panel unless
97
+ * the item asks to stay open.
98
+ *
99
+ * @param item - The activated item.
100
+ * @param source - How the commit happened.
101
+ */
102
+ protected commit(item: HTMLElement, source: "keyboard" | "pointer"): void {
103
+ this.#activate(item, source === "keyboard");
104
+ }
105
+
106
+ /**
107
+ * @description Runs one item's activation: optional synthetic click,
108
+ * `zazz:command-select`, then close (unless `data-stay-open`).
109
+ *
110
+ * @param item - The item to activate.
111
+ * @param click - Whether to run the native activation via `click()`.
112
+ * @private
113
+ */
114
+ #activate(item: HTMLElement, click: boolean): void {
115
+ this.dispatchEvent(
116
+ new CustomEvent("zazz:command-select", {
117
+ bubbles: true,
118
+ detail: { item, value: this.itemValue(item) },
119
+ }),
120
+ );
121
+ if (click) item.click();
122
+ if (!item.hasAttribute("data-stay-open")) this.#closePanel();
123
+ }
124
+
125
+ /**
126
+ * @description Opens or closes the panel, branching on its surface.
127
+ * @private
128
+ */
129
+ #togglePanel(): void {
130
+ const panel = this.panel;
131
+ if (!panel) return;
132
+ if (panel instanceof HTMLDialogElement) {
133
+ if (panel.open) panel.close();
134
+ else panel.showModal();
135
+ } else {
136
+ panel.togglePopover();
137
+ }
138
+ }
139
+
140
+ /**
141
+ * @description Closes the panel, branching on its surface.
142
+ * @private
143
+ */
144
+ #closePanel(): void {
145
+ const panel = this.panel;
146
+ if (!panel) return;
147
+ if (panel instanceof HTMLDialogElement) {
148
+ if (panel.open) panel.close();
149
+ } else if (panel.matches(":popover-open, .\\:popover-open")) {
150
+ panel.hidePopover();
151
+ }
152
+ }
153
+ }
154
+
155
+ defineZazzElement("ui-command", UiCommand);
156
+
157
+ export { UiCommand };
@@ -0,0 +1,200 @@
1
+ <button class="ui-button" type="button" command="show-modal" commandfor="form-dialog-1">
2
+ New project
3
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
4
+ <rect width="256" height="256" fill="none" />
5
+ <line
6
+ x1="40"
7
+ y1="128"
8
+ x2="216"
9
+ y2="128"
10
+ fill="none"
11
+ stroke="currentColor"
12
+ stroke-linecap="round"
13
+ stroke-linejoin="round"
14
+ stroke-width="16"
15
+ />
16
+ <line
17
+ x1="128"
18
+ y1="40"
19
+ x2="128"
20
+ y2="216"
21
+ fill="none"
22
+ stroke="currentColor"
23
+ stroke-linecap="round"
24
+ stroke-linejoin="round"
25
+ stroke-width="16"
26
+ />
27
+ </svg>
28
+ </button>
29
+ <dialog id="form-dialog-1" class="ui-dialog" closedby="any" data-size="article">
30
+ <div data-slot="dialog-content">
31
+ <header data-slot="dialog-header">
32
+ <h2 class="text-lg font-heading font-strong">New project</h2>
33
+ <p class="text-muted-foreground">
34
+ Add a project to your workspace. You can change these settings later.
35
+ </p>
36
+ </header>
37
+ <form id="f-new-project-1" class="flex flex-col gap-md" data-slot="dialog-body" method="dialog">
38
+ <fieldset class="ui-field-group">
39
+ <legend class="sr-only">Contact</legend>
40
+ <div class="grid grid-cols-2 gap-sm">
41
+ <div class="ui-field">
42
+ <label data-slot="field-label" for="fd-name">Name</label>
43
+ <input
44
+ class="ui-input"
45
+ id="fd-name"
46
+ name="name"
47
+ type="text"
48
+ inputmode="text"
49
+ placeholder="Ada Lovelace"
50
+ required
51
+ />
52
+ </div>
53
+ <div class="ui-field">
54
+ <label data-slot="field-label" for="fd-email">Email</label>
55
+ <input
56
+ class="ui-input"
57
+ id="fd-email"
58
+ name="email"
59
+ type="email"
60
+ inputmode="email"
61
+ required
62
+ placeholder="you@example.com"
63
+ autocomplete="email"
64
+ aria-describedby="fd-email-hint"
65
+ />
66
+ <div data-slot="field-description">
67
+ <span data-slot="field-hint" id="fd-email-hint"
68
+ >We'll only use this to send receipts.</span
69
+ >
70
+ <span data-slot="field-error" role="alert">Please enter a valid email address.</span>
71
+ </div>
72
+ </div>
73
+ <label class="ui-field-group col-span-2">
74
+ <span data-slot="field-label">Repository</span>
75
+ <div class="ui-input-group">
76
+ <input
77
+ class="ui-input"
78
+ type="search"
79
+ name="repo"
80
+ id="fd-repo"
81
+ inputmode="search"
82
+ placeholder="Search repositories…"
83
+ />
84
+ <span data-slot="input-group-addon">
85
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
86
+ <rect width="256" height="256" fill="none" />
87
+ <circle
88
+ cx="112"
89
+ cy="112"
90
+ r="80"
91
+ fill="none"
92
+ stroke="currentColor"
93
+ stroke-linecap="round"
94
+ stroke-linejoin="round"
95
+ stroke-width="16"
96
+ />
97
+ <line
98
+ x1="168.57"
99
+ y1="168.57"
100
+ x2="224"
101
+ y2="224"
102
+ fill="none"
103
+ stroke="currentColor"
104
+ stroke-linecap="round"
105
+ stroke-linejoin="round"
106
+ stroke-width="16"
107
+ />
108
+ </svg>
109
+ </span>
110
+ </div>
111
+ </label>
112
+ </div>
113
+ </fieldset>
114
+
115
+ <fieldset class="ui-field-group">
116
+ <div class="ui-field">
117
+ <label data-slot="field-label" for="fd-message">Description</label>
118
+ <textarea
119
+ class="ui-textarea"
120
+ id="fd-message"
121
+ name="description"
122
+ inputmode="text"
123
+ placeholder="What is this project for?"
124
+ ></textarea>
125
+ </div>
126
+ </fieldset>
127
+
128
+ <fieldset class="ui-radio-group">
129
+ <legend>Billing</legend>
130
+ <label class="ui-field" data-orientation="horizontal">
131
+ <input class="ui-radio" type="radio" name="billing" value="monthly" />
132
+ <span data-slot="field-label">Monthly billing</span>
133
+ </label>
134
+ <label class="ui-field" data-orientation="horizontal">
135
+ <input class="ui-radio" type="radio" name="billing" value="annual" checked />
136
+ <span data-slot="field-label">Annual billing</span>
137
+ </label>
138
+ </fieldset>
139
+
140
+ <label class="ui-field" data-orientation="horizontal">
141
+ <input type="checkbox" name="terms" required />
142
+ <span data-slot="field-label">Accept terms &amp; conditions</span>
143
+ </label>
144
+ </form>
145
+ <footer data-slot="dialog-footer">
146
+ <button
147
+ class="ui-button"
148
+ type="button"
149
+ value="cancel"
150
+ commandfor="form-dialog-1"
151
+ command="close"
152
+ >
153
+ Cancel
154
+ </button>
155
+ <button
156
+ class="ui-button"
157
+ data-variant="primary"
158
+ type="submit"
159
+ form="f-new-project-1"
160
+ value="save"
161
+ >
162
+ Create project
163
+ </button>
164
+ </footer>
165
+ <button
166
+ class="ui-button"
167
+ data-slot="dialog-close"
168
+ data-size="icon"
169
+ data-variant="ghost"
170
+ type="button"
171
+ commandfor="form-dialog-1"
172
+ command="close"
173
+ aria-label="Close dialog"
174
+ >
175
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
176
+ <rect width="256" height="256" fill="none" />
177
+ <line
178
+ x1="200"
179
+ y1="56"
180
+ x2="56"
181
+ y2="200"
182
+ stroke="currentColor"
183
+ stroke-linecap="round"
184
+ stroke-linejoin="round"
185
+ stroke-width="16"
186
+ />
187
+ <line
188
+ x1="200"
189
+ y1="200"
190
+ x2="56"
191
+ y2="56"
192
+ stroke="currentColor"
193
+ stroke-linecap="round"
194
+ stroke-linejoin="round"
195
+ stroke-width="16"
196
+ />
197
+ </svg>
198
+ </button>
199
+ </div>
200
+ </dialog>