@voidable/ui 0.6.1 → 0.8.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 (250) hide show
  1. package/README.md +168 -9
  2. package/dist/angular/index.d.ts +20 -0
  3. package/dist/angular/index.js +78 -0
  4. package/dist/autoloader-core.d.ts +45 -0
  5. package/dist/autoloader-table.generated.d.ts +5 -0
  6. package/dist/autoloader.d.ts +13 -0
  7. package/dist/autoloader.js +229 -0
  8. package/dist/base.d.ts +173 -2
  9. package/dist/base.js +2 -9
  10. package/dist/chunks/base-CMruMbxC.js +824 -0
  11. package/dist/chunks/disclosure-Bj_49GcC.js +23 -0
  12. package/dist/chunks/dismiss-Drsy_dE5.js +37 -0
  13. package/dist/chunks/form-control-C0vH6gii.js +300 -0
  14. package/dist/chunks/keyboard-MQpfTX5I.js +46 -0
  15. package/dist/chunks/keyboard-activation-CV0m4hkn.js +29 -0
  16. package/dist/chunks/modal-D_YVy2vg.js +71 -0
  17. package/dist/chunks/overlay-BywGMcDW.js +467 -0
  18. package/dist/chunks/parts-D30c8OoG.js +229 -0
  19. package/dist/chunks/{shape-FJvZa8FW.js → shape-C_LW7EjG.js} +12 -4
  20. package/dist/components/accordion.d.ts +38 -10
  21. package/dist/components/accordion.js +51 -53
  22. package/dist/components/action-input.d.ts +64 -6
  23. package/dist/components/action-input.js +84 -41
  24. package/dist/components/alert.d.ts +24 -10
  25. package/dist/components/alert.js +26 -27
  26. package/dist/components/avatar.d.ts +8 -2
  27. package/dist/components/avatar.js +3 -3
  28. package/dist/components/badge.d.ts +8 -3
  29. package/dist/components/badge.js +2 -2
  30. package/dist/components/banner.d.ts +21 -10
  31. package/dist/components/banner.js +27 -27
  32. package/dist/components/bar-chart.d.ts +30 -6
  33. package/dist/components/bar-chart.js +29 -39
  34. package/dist/components/breadcrumbs.d.ts +19 -6
  35. package/dist/components/breadcrumbs.js +16 -22
  36. package/dist/components/button.d.ts +64 -10
  37. package/dist/components/button.js +70 -26
  38. package/dist/components/calendar.d.ts +65 -10
  39. package/dist/components/calendar.js +157 -106
  40. package/dist/components/card.d.ts +14 -9
  41. package/dist/components/card.js +8 -22
  42. package/dist/components/carousel.d.ts +65 -14
  43. package/dist/components/carousel.js +84 -93
  44. package/dist/components/charts/scale.d.ts +0 -1
  45. package/dist/components/charts/shape.d.ts +0 -1
  46. package/dist/components/checkbox-group.d.ts +38 -5
  47. package/dist/components/checkbox-group.js +61 -20
  48. package/dist/components/checkbox.d.ts +53 -7
  49. package/dist/components/checkbox.js +66 -29
  50. package/dist/components/collapsible.d.ts +29 -9
  51. package/dist/components/collapsible.js +42 -44
  52. package/dist/components/color-picker.d.ts +20 -4
  53. package/dist/components/color-picker.js +35 -29
  54. package/dist/components/combobox.d.ts +84 -10
  55. package/dist/components/combobox.js +142 -45
  56. package/dist/components/compose-input.d.ts +8 -1
  57. package/dist/components/compose-input.js +9 -3
  58. package/dist/components/dialog.d.ts +24 -20
  59. package/dist/components/dialog.js +8 -57
  60. package/dist/components/divider.d.ts +8 -1
  61. package/dist/components/divider.js +3 -3
  62. package/dist/components/donut-chart.d.ts +28 -5
  63. package/dist/components/donut-chart.js +55 -54
  64. package/dist/components/drawer.d.ts +19 -18
  65. package/dist/components/drawer.js +9 -53
  66. package/dist/components/dropdown-menu.d.ts +62 -7
  67. package/dist/components/dropdown-menu.js +124 -33
  68. package/dist/components/editable.d.ts +37 -3
  69. package/dist/components/editable.js +45 -24
  70. package/dist/components/error-fallback.d.ts +36 -5
  71. package/dist/components/error-fallback.js +73 -23
  72. package/dist/components/field.d.ts +38 -4
  73. package/dist/components/field.js +63 -21
  74. package/dist/components/file-upload.d.ts +23 -2
  75. package/dist/components/file-upload.js +47 -24
  76. package/dist/components/gauge.d.ts +48 -9
  77. package/dist/components/gauge.js +57 -55
  78. package/dist/components/hamburger.d.ts +19 -4
  79. package/dist/components/hamburger.js +28 -19
  80. package/dist/components/hover-card.d.ts +40 -14
  81. package/dist/components/hover-card.js +76 -59
  82. package/dist/components/indicator.d.ts +18 -7
  83. package/dist/components/indicator.js +16 -18
  84. package/dist/components/input.d.ts +70 -5
  85. package/dist/components/input.js +83 -20
  86. package/dist/components/line-chart.d.ts +27 -5
  87. package/dist/components/line-chart.js +19 -21
  88. package/dist/components/list.d.ts +10 -1
  89. package/dist/components/list.js +3 -3
  90. package/dist/components/menu.d.ts +67 -21
  91. package/dist/components/menu.js +116 -115
  92. package/dist/components/multiselect.d.ts +108 -13
  93. package/dist/components/multiselect.js +207 -70
  94. package/dist/components/nav-bar.d.ts +12 -7
  95. package/dist/components/nav-bar.js +11 -21
  96. package/dist/components/nav-menu.d.ts +52 -12
  97. package/dist/components/nav-menu.js +68 -70
  98. package/dist/components/number-input.d.ts +76 -8
  99. package/dist/components/number-input.js +117 -51
  100. package/dist/components/pagination.d.ts +19 -1
  101. package/dist/components/pagination.js +68 -7
  102. package/dist/components/panel.d.ts +16 -8
  103. package/dist/components/panel.js +20 -20
  104. package/dist/components/pin-input.d.ts +41 -4
  105. package/dist/components/pin-input.js +45 -27
  106. package/dist/components/popover.d.ts +29 -11
  107. package/dist/components/popover.js +47 -35
  108. package/dist/components/progress.d.ts +7 -3
  109. package/dist/components/progress.js +3 -3
  110. package/dist/components/radio-group.d.ts +30 -5
  111. package/dist/components/radio-group.js +56 -19
  112. package/dist/components/radio.d.ts +47 -7
  113. package/dist/components/radio.js +68 -29
  114. package/dist/components/scroll-area.d.ts +8 -5
  115. package/dist/components/scroll-area.js +19 -20
  116. package/dist/components/segmented-control.d.ts +52 -8
  117. package/dist/components/segmented-control.js +66 -36
  118. package/dist/components/select.d.ts +59 -12
  119. package/dist/components/select.js +96 -46
  120. package/dist/components/sidebar.d.ts +22 -3
  121. package/dist/components/sidebar.js +20 -10
  122. package/dist/components/skeleton.d.ts +5 -2
  123. package/dist/components/skeleton.js +4 -4
  124. package/dist/components/slider.d.ts +27 -5
  125. package/dist/components/slider.js +29 -17
  126. package/dist/components/spinner.d.ts +6 -2
  127. package/dist/components/spinner.js +3 -3
  128. package/dist/components/stat.d.ts +21 -4
  129. package/dist/components/stat.js +7 -3
  130. package/dist/components/status-dot.d.ts +4 -1
  131. package/dist/components/status-dot.js +3 -3
  132. package/dist/components/stepper.d.ts +5 -1
  133. package/dist/components/stepper.js +2 -2
  134. package/dist/components/switch.d.ts +24 -5
  135. package/dist/components/switch.js +37 -19
  136. package/dist/components/table.d.ts +51 -2
  137. package/dist/components/table.js +157 -8
  138. package/dist/components/tabs.d.ts +49 -17
  139. package/dist/components/tabs.js +85 -54
  140. package/dist/components/tag.d.ts +17 -7
  141. package/dist/components/tag.js +19 -21
  142. package/dist/components/tags-input.d.ts +33 -4
  143. package/dist/components/tags-input.js +40 -30
  144. package/dist/components/textarea.d.ts +61 -5
  145. package/dist/components/textarea.js +58 -21
  146. package/dist/components/toast.d.ts +89 -15
  147. package/dist/components/toast.js +105 -30
  148. package/dist/components/toggle-group.d.ts +30 -3
  149. package/dist/components/toggle-group.js +43 -16
  150. package/dist/components/toggle.d.ts +25 -4
  151. package/dist/components/toggle.js +28 -18
  152. package/dist/components/tooltip.d.ts +31 -12
  153. package/dist/components/tooltip.js +62 -28
  154. package/dist/components.json +1518 -0
  155. package/dist/custom-elements.json +31817 -0
  156. package/dist/dev/index.d.ts +40 -0
  157. package/dist/dev/rules.d.ts +46 -0
  158. package/dist/dev/table.generated.d.ts +8 -0
  159. package/dist/dev/types.d.ts +113 -0
  160. package/dist/dev.js +3364 -0
  161. package/dist/disclosure.d.ts +30 -0
  162. package/dist/dismiss.d.ts +20 -0
  163. package/dist/form-control.d.ts +92 -0
  164. package/dist/index.d.ts +5 -4
  165. package/dist/index.js +24 -24
  166. package/dist/keyboard-activation.d.ts +31 -0
  167. package/dist/keyboard.d.ts +32 -0
  168. package/dist/modal.d.ts +44 -0
  169. package/dist/overlay.d.ts +249 -0
  170. package/dist/parts.d.ts +171 -0
  171. package/dist/projection.d.ts +370 -0
  172. package/dist/types/elements.d.ts +648 -0
  173. package/dist/types/react.d.ts +163 -0
  174. package/dist/types/solid.d.ts +164 -0
  175. package/dist/types/solid2.d.ts +161 -0
  176. package/dist/types/svelte.d.ts +154 -0
  177. package/dist/types/vue.d.ts +156 -0
  178. package/dist/vscode.html-custom-data.json +6004 -0
  179. package/dist/web-types.json +8365 -0
  180. package/package.json +113 -21
  181. package/dist/base.d.ts.map +0 -1
  182. package/dist/components/accordion.d.ts.map +0 -1
  183. package/dist/components/action-input.d.ts.map +0 -1
  184. package/dist/components/alert.d.ts.map +0 -1
  185. package/dist/components/avatar.d.ts.map +0 -1
  186. package/dist/components/badge.d.ts.map +0 -1
  187. package/dist/components/banner.d.ts.map +0 -1
  188. package/dist/components/bar-chart.d.ts.map +0 -1
  189. package/dist/components/breadcrumbs.d.ts.map +0 -1
  190. package/dist/components/button.d.ts.map +0 -1
  191. package/dist/components/calendar.d.ts.map +0 -1
  192. package/dist/components/card.d.ts.map +0 -1
  193. package/dist/components/carousel.d.ts.map +0 -1
  194. package/dist/components/charts/scale.d.ts.map +0 -1
  195. package/dist/components/charts/shape.d.ts.map +0 -1
  196. package/dist/components/checkbox-group.d.ts.map +0 -1
  197. package/dist/components/checkbox.d.ts.map +0 -1
  198. package/dist/components/collapsible.d.ts.map +0 -1
  199. package/dist/components/color-picker.d.ts.map +0 -1
  200. package/dist/components/combobox.d.ts.map +0 -1
  201. package/dist/components/compose-input.d.ts.map +0 -1
  202. package/dist/components/dialog.d.ts.map +0 -1
  203. package/dist/components/divider.d.ts.map +0 -1
  204. package/dist/components/donut-chart.d.ts.map +0 -1
  205. package/dist/components/drawer.d.ts.map +0 -1
  206. package/dist/components/dropdown-menu.d.ts.map +0 -1
  207. package/dist/components/editable.d.ts.map +0 -1
  208. package/dist/components/error-fallback.d.ts.map +0 -1
  209. package/dist/components/field.d.ts.map +0 -1
  210. package/dist/components/file-upload.d.ts.map +0 -1
  211. package/dist/components/gauge.d.ts.map +0 -1
  212. package/dist/components/hamburger.d.ts.map +0 -1
  213. package/dist/components/hover-card.d.ts.map +0 -1
  214. package/dist/components/indicator.d.ts.map +0 -1
  215. package/dist/components/input.d.ts.map +0 -1
  216. package/dist/components/line-chart.d.ts.map +0 -1
  217. package/dist/components/list.d.ts.map +0 -1
  218. package/dist/components/menu.d.ts.map +0 -1
  219. package/dist/components/multiselect.d.ts.map +0 -1
  220. package/dist/components/nav-bar.d.ts.map +0 -1
  221. package/dist/components/nav-menu.d.ts.map +0 -1
  222. package/dist/components/number-input.d.ts.map +0 -1
  223. package/dist/components/pagination.d.ts.map +0 -1
  224. package/dist/components/panel.d.ts.map +0 -1
  225. package/dist/components/pin-input.d.ts.map +0 -1
  226. package/dist/components/popover.d.ts.map +0 -1
  227. package/dist/components/progress.d.ts.map +0 -1
  228. package/dist/components/radio-group.d.ts.map +0 -1
  229. package/dist/components/radio.d.ts.map +0 -1
  230. package/dist/components/scroll-area.d.ts.map +0 -1
  231. package/dist/components/segmented-control.d.ts.map +0 -1
  232. package/dist/components/select.d.ts.map +0 -1
  233. package/dist/components/sidebar.d.ts.map +0 -1
  234. package/dist/components/skeleton.d.ts.map +0 -1
  235. package/dist/components/slider.d.ts.map +0 -1
  236. package/dist/components/spinner.d.ts.map +0 -1
  237. package/dist/components/stat.d.ts.map +0 -1
  238. package/dist/components/status-dot.d.ts.map +0 -1
  239. package/dist/components/stepper.d.ts.map +0 -1
  240. package/dist/components/switch.d.ts.map +0 -1
  241. package/dist/components/table.d.ts.map +0 -1
  242. package/dist/components/tabs.d.ts.map +0 -1
  243. package/dist/components/tag.d.ts.map +0 -1
  244. package/dist/components/tags-input.d.ts.map +0 -1
  245. package/dist/components/textarea.d.ts.map +0 -1
  246. package/dist/components/toast.d.ts.map +0 -1
  247. package/dist/components/toggle-group.d.ts.map +0 -1
  248. package/dist/components/toggle.d.ts.map +0 -1
  249. package/dist/components/tooltip.d.ts.map +0 -1
  250. package/dist/index.d.ts.map +0 -1
@@ -1,7 +1,8 @@
1
- import { t as e } from "../chunks/decorate-CaYbmmmm.js";
2
- import { n as t } from "../chunks/scale-_ccSuoYg.js";
3
- import { a as n, i as r, n as i, r as a } from "../chunks/shape-FJvZa8FW.js";
4
- import { LitElement as o, html as s, nothing as c, svg as l } from "lit";
1
+ import { t as e } from "../chunks/base-CMruMbxC.js";
2
+ import { t } from "../chunks/decorate-CaYbmmmm.js";
3
+ import { n } from "../chunks/scale-_ccSuoYg.js";
4
+ import { a as r, i, n as a, r as o } from "../chunks/shape-C_LW7EjG.js";
5
+ import { html as s, nothing as c, svg as l } from "lit";
5
6
  import { property as u, state as d } from "lit/decorators.js";
6
7
  //#region src/components/line-chart.ts
7
8
  function f(e) {
@@ -18,9 +19,9 @@ function h(e) {
18
19
  let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
19
20
  return (n <= 1 ? 1 : n <= 2 ? 2 : n <= 5 ? 5 : 10) * t;
20
21
  }
21
- var g = class extends o {
22
+ var g = class extends e {
22
23
  constructor(...e) {
23
- super(...e), this.height = 220, this.showValues = !1, this.variant = "outline", this.interpolation = "linear", this.ariaLabel = "", this._data = { series: [] }, this._phase = "pre", this._display = /* @__PURE__ */ new Map(), this._targets = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._animStart = 0, this._animDuration = 0, this._rafHandle = 0, this._reveal = 0, this._revealFrom = 0, this._hoverIndex = null, this._tick = (e) => {
24
+ super(...e), this.height = 220, this.showValue = !1, this.variant = "outline", this.interpolation = "linear", this.ariaLabel = "", this._data = { series: [] }, this._phase = "pre", this._display = /* @__PURE__ */ new Map(), this._targets = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._animStart = 0, this._animDuration = 0, this._rafHandle = 0, this._reveal = 0, this._revealFrom = 0, this._hoverIndex = null, this._tick = (e) => {
24
25
  let t = e - this._animStart, n = Math.min(t / this._animDuration, 1), r = f(n);
25
26
  this._reveal = this._revealFrom + (1 - this._revealFrom) * r;
26
27
  for (let [e, t] of this._targets) {
@@ -46,9 +47,6 @@ var g = class extends o {
46
47
  this._hoverIndex = null;
47
48
  };
48
49
  }
49
- createRenderRoot() {
50
- return this;
51
- }
52
50
  get data() {
53
51
  return this._data;
54
52
  }
@@ -61,11 +59,11 @@ var g = class extends o {
61
59
  }
62
60
  _refreshTargets() {
63
61
  this._targets.clear(), this._data.series.forEach((e, t) => {
64
- e.values.forEach((e, n) => this._targets.set(this._key(t, n), e));
62
+ e.values.forEach((e, n) => this._targets.set(this._key(t, n), Number.isFinite(e) ? e : 0));
65
63
  });
66
64
  }
67
65
  connectedCallback() {
68
- super.connectedCallback(), this.setAttribute("role", "img"), this._refreshTargets(), requestAnimationFrame(() => {
66
+ super.connectedCallback(), this.setHostAttribute("role", "img"), this._refreshTargets(), requestAnimationFrame(() => {
69
67
  this._startAnimation(/* @__PURE__ */ new Map(), !0);
70
68
  }), this.addEventListener("mousemove", this._onMouseMove), this.addEventListener("mouseleave", this._onMouseLeave);
71
69
  }
@@ -82,9 +80,9 @@ var g = class extends o {
82
80
  this._phase = "animating", this._rafHandle = requestAnimationFrame(this._tick);
83
81
  }
84
82
  render() {
85
- let { series: e, labels: o = [] } = this._data;
86
- if (e.length === 0) return s`<svg viewBox="0 0 600 ${this.height}" aria-label=${this.ariaLabel}></svg>`;
87
- let u = this.height - 16 - 32, d = Math.max(...e.map((e) => e.values.length)), f = e.flatMap((e) => e.values), g = h(Math.max(...f, 0) * 1.1) || 1, _ = new t([0, Math.max(0, d - 1)], [40, 584]), v = new t([0, g], [16 + u, 16]), y = v.ticks(5), b = 16 + u, x = getComputedStyle(this), S = (parseFloat(x.getPropertyValue("--void-radius-sm")) || 0) > 0 && this.interpolation === "linear", C = S ? n : a, w = S ? r : i, T = e.map((e, t) => {
83
+ let { series: e, labels: t = [] } = this._data;
84
+ if (e.length === 0) return s`<svg viewBox="0 0 600 ${this.height}" role="img" aria-label=${this.ariaLabel || "Line chart"}></svg>`;
85
+ let u = this.height - 16 - 32, d = Math.max(...e.map((e) => e.values.length)), f = e.flatMap((e) => e.values).filter(Number.isFinite), g = h(Math.max(...f, 0) * 1.1) || 1, _ = new n([0, Math.max(0, d - 1)], [40, 584]), v = new n([0, g], [16 + u, 16]), y = v.ticks(5), b = 16 + u, x = getComputedStyle(this), S = (parseFloat(x.getPropertyValue("--void-radius-sm")) || 0) > 0 && this.interpolation === "linear", C = S ? r : o, w = S ? i : a, T = e.map((e, t) => {
88
86
  let n = [];
89
87
  for (let r = 0; r < e.values.length; r++) {
90
88
  let e = this._display.get(this._key(t, r)) ?? 0;
@@ -127,7 +125,7 @@ var g = class extends o {
127
125
  `;
128
126
  })}
129
127
 
130
- ${this.showValues ? e.map((e, t) => l`
128
+ ${this.showValue ? e.map((e, t) => l`
131
129
  <g class="void-line-chart-values">
132
130
  ${e.values.map((e, n) => {
133
131
  let r = this._display.get(this._key(t, n)) ?? 0;
@@ -137,10 +135,10 @@ var g = class extends o {
137
135
  `) : c}
138
136
 
139
137
  <g class="void-line-chart-x-axis">
140
- ${o.slice(0, d).map((e, t) => l`<text x=${_.scale(t)} y=${16 + u + 18} text-anchor="middle">${e}</text>`)}
138
+ ${t.slice(0, d).map((e, t) => l`<text x=${_.scale(t)} y=${16 + u + 18} text-anchor="middle">${e}</text>`)}
141
139
  </g>
142
140
 
143
- ${this._hoverIndex !== null && this._hoverIndex < d ? this._renderHover(e, o, _, v, this._hoverIndex, 16, u, 40, 544) : c}
141
+ ${this._hoverIndex !== null && this._hoverIndex < d ? this._renderHover(e, t, _, v, this._hoverIndex, 16, u, 40, 544) : c}
144
142
  </svg>
145
143
  `;
146
144
  }
@@ -204,13 +202,13 @@ var g = class extends o {
204
202
  `;
205
203
  }
206
204
  };
207
- e([u({
205
+ t([u({
208
206
  type: Number,
209
207
  reflect: !0
210
- })], g.prototype, "height", void 0), e([u({
208
+ })], g.prototype, "height", void 0), t([u({
211
209
  type: Boolean,
212
- attribute: "show-values",
210
+ attribute: "show-value",
213
211
  reflect: !0
214
- })], g.prototype, "showValues", void 0), e([u({ reflect: !0 })], g.prototype, "variant", void 0), e([u({ reflect: !0 })], g.prototype, "interpolation", void 0), e([u({ attribute: "aria-label" })], g.prototype, "ariaLabel", void 0), e([d()], g.prototype, "_phase", void 0), e([d()], g.prototype, "_hoverIndex", void 0), customElements.get("void-line-chart") || customElements.define("void-line-chart", g);
212
+ })], g.prototype, "showValue", void 0), t([u({ reflect: !0 })], g.prototype, "variant", void 0), t([u({ reflect: !0 })], g.prototype, "interpolation", void 0), t([u({ attribute: "aria-label" })], g.prototype, "ariaLabel", void 0), t([d()], g.prototype, "_phase", void 0), t([d()], g.prototype, "_hoverIndex", void 0), customElements.get("void-line-chart") || customElements.define("void-line-chart", g);
215
213
  //#endregion
216
214
  export { g as VoidLineChart };
@@ -1,13 +1,23 @@
1
1
  import { VoidElement } from '../base.js';
2
2
  /** Structured item list for menus, option sets, and content feeds with consistent spacing and optional dividers. */
3
3
  export declare class VoidList extends VoidElement {
4
+ /** Draw a hairline between items. */
4
5
  dividers: boolean;
5
6
  connectedCallback(): void;
6
7
  }
7
8
  /** Individual selectable item within a VoidList. */
8
9
  export declare class VoidListItem extends VoidElement {
10
+ /**
11
+ * Mark the item as the current choice: it is drawn highlighted. It is a visual state only; it is not
12
+ * exposed to assistive technology.
13
+ */
9
14
  selected: boolean;
15
+ /** Dim the item and stop it firing `void-click`. */
10
16
  disabled: boolean;
17
+ /**
18
+ * Make the item behave like a button: a hover and focus style, and a click fires `void-click`. Without
19
+ * it the item is static and fires nothing.
20
+ */
11
21
  interactive: boolean;
12
22
  connectedCallback(): void;
13
23
  protected updated(_changed: Map<string, unknown>): void;
@@ -19,4 +29,3 @@ declare global {
19
29
  'void-list-item': VoidListItem;
20
30
  }
21
31
  }
22
- //# sourceMappingURL=list.d.ts.map
@@ -1,4 +1,4 @@
1
- import { VoidElement as e } from "../base.js";
1
+ import { t as e } from "../chunks/base-CMruMbxC.js";
2
2
  import { t } from "../chunks/decorate-CaYbmmmm.js";
3
3
  import { property as n } from "lit/decorators.js";
4
4
  //#region src/components/list.ts
@@ -7,7 +7,7 @@ var r = class extends e {
7
7
  super(...e), this.dividers = !1;
8
8
  }
9
9
  connectedCallback() {
10
- super.connectedCallback(), this.setAttribute("role", "list");
10
+ super.connectedCallback(), this.setHostAttribute("role", "list");
11
11
  }
12
12
  };
13
13
  t([n({
@@ -25,7 +25,7 @@ var i = class extends e {
25
25
  };
26
26
  }
27
27
  connectedCallback() {
28
- super.connectedCallback(), this.setAttribute("role", "listitem");
28
+ super.connectedCallback(), this.setHostAttribute("role", "listitem");
29
29
  }
30
30
  updated(e) {
31
31
  super.updated(e), e.has("interactive") && (this.interactive ? this.addEventListener("click", this._handleClick) : this.removeEventListener("click", this._handleClick));
@@ -1,44 +1,91 @@
1
- import { nothing } from 'lit';
2
1
  import { VoidElement } from '../base.js';
3
- /** Always-visible menu panel for command palettes, side panels, and searchable action lists. */
2
+ import { KeyboardActivation } from '../keyboard-activation.js';
3
+ import { PartsController } from '../parts.js';
4
+ /**
5
+ * Always-visible menu panel for command palettes, side panels, and searchable action lists.
6
+ *
7
+ * Its regions are parts, in this order: an optional `<void-menu-search>` around one text field (present means
8
+ * the menu is searchable), the `<void-menu-content>` holding the `<void-menu-item>`s and
9
+ * `<void-menu-group>`s, and an optional `<void-menu-empty>` shown instead of the default "No results found" when
10
+ * a search matches nothing. The parts are the final DOM: the menu moves and renders nothing.
11
+ *
12
+ * Follows the WAI-ARIA menu pattern: the content is the `role="menu"` (the host has no role, so the search
13
+ * field is not a menu child) and the items are `menuitem`s, one tab stop at a time (roving tabindex).
14
+ * Keys are handled on the menu itself, never on the document. Keyboard: ArrowDown and ArrowUp move between
15
+ * items (wrapping, skipping disabled and filtered-out ones; with a search field, ArrowDown from the field
16
+ * goes to the first item and ArrowUp from the first item returns to the field), Home and End jump to
17
+ * the first and last item, typing jumps to the next item starting with the characters (not in the search
18
+ * field), Enter or Space activate the item (`void-select`), Escape closes the menu.
19
+ */
4
20
  export declare class VoidMenu extends VoidElement {
21
+ /**
22
+ * Whether the menu is shown. It starts hidden: add `open` to show it (the menu has no trigger of its own).
23
+ * Escape sets it back to false.
24
+ */
5
25
  open: boolean;
6
- searchable: boolean;
26
+ /** Size step: `sm`, `md` (default) or `lg`. */
7
27
  size: 'sm' | 'md' | 'lg';
8
- placeholder: string;
9
28
  private _query;
10
- private _userContent;
11
- private _didSetup;
29
+ protected readonly _parts: PartsController;
30
+ private readonly _typeahead;
31
+ private _observer;
32
+ /** The text field inside the search part (a native input, or the one a `<void-input>` holds). */
33
+ private _searchInput;
34
+ private _items;
35
+ /** Items that can take focus: enabled and not filtered out, in document order. */
36
+ private get _focusableItems();
37
+ /** Names the content, links the search field to it and applies the current search. Idempotent. */
38
+ private _wire;
12
39
  connectedCallback(): void;
13
40
  disconnectedCallback(): void;
14
41
  protected updated(changed: Map<string, unknown>): void;
42
+ /** Roving tabindex: one item (the one last focused, else the first) is the menu's tab stop. */
43
+ private _syncTabStop;
44
+ private _handleFocusIn;
45
+ private _inSearch;
15
46
  private _handleKeydown;
16
- private _onSearchInput;
17
- private _filterItems;
18
- private _updateEmptyState;
47
+ private _onInput;
48
+ /**
49
+ * Hides the items (and groups, and the menu's empty state) the search does not match. Written through the parts
50
+ * controller each pass, so what the search hid is shown again as soon as the search is cleared, and a morph
51
+ * keeps it.
52
+ */
53
+ private _applyFilter;
19
54
  private _clearSearch;
20
- render(): typeof nothing | import('lit').TemplateResult<1>;
21
55
  }
56
+ /**
57
+ * One action in a `void-menu`: activating it (click, Enter or Space) fires `void-select` with its `value`. Its
58
+ * text is its label; an optional `<void-menu-item-icon>` before it and `<void-menu-item-shortcut>` after it are
59
+ * CSS-only parts.
60
+ *
61
+ * @fires {CustomEvent<{ item: VoidMenuItem; value: string }>} void-select - The item was chosen.
62
+ */
22
63
  export declare class VoidMenuItem extends VoidElement {
64
+ /** Enter and Space fire a real `click`, as on a native button. */
65
+ protected readonly _activation: KeyboardActivation;
66
+ /**
67
+ * What the item stands for, passed as `detail.value` of `void-select` (empty when not set). Use it instead of
68
+ * matching on the item's text.
69
+ */
23
70
  value: string;
71
+ /** Dim the item, skip it in keyboard navigation and stop it firing `void-select`. */
24
72
  disabled: boolean;
25
- shortcut: string;
26
- icon: string;
27
- private _originalContent;
28
73
  connectedCallback(): void;
29
74
  disconnectedCallback(): void;
30
75
  updated(changed: Map<string, unknown>): void;
31
- private _buildContent;
76
+ /** @internal Set by the owning menu: whether this item is the menu's tab stop. */
77
+ _setTabStop(stop: boolean): void;
32
78
  private _handleClick;
33
- private _handleKeydown;
34
79
  }
80
+ /**
81
+ * Labelled group of `void-menu-item`s inside a `void-menu`. Its heading is a `<void-menu-group-label>` first in
82
+ * the group, which names the group.
83
+ */
35
84
  export declare class VoidMenuGroup extends VoidElement {
36
- label: string;
37
- private _userContent;
38
- private _didSetup;
85
+ protected readonly _parts: PartsController;
86
+ /** The group is named by its label part. */
87
+ private _wire;
39
88
  connectedCallback(): void;
40
- protected updated(changed: Map<string, unknown>): void;
41
- render(): import('lit').TemplateResult<1>;
42
89
  }
43
90
  declare global {
44
91
  interface HTMLElementTagNameMap {
@@ -47,4 +94,3 @@ declare global {
47
94
  'void-menu-group': VoidMenuGroup;
48
95
  }
49
96
  }
50
- //# sourceMappingURL=menu.d.ts.map
@@ -1,96 +1,114 @@
1
- import { VoidElement as e } from "../base.js";
1
+ import { t as e } from "../chunks/base-CMruMbxC.js";
2
2
  import { t } from "../chunks/decorate-CaYbmmmm.js";
3
- import { html as n, nothing as r } from "lit";
4
- import { property as i } from "lit/decorators.js";
3
+ import { t as n } from "../chunks/keyboard-activation-CV0m4hkn.js";
4
+ import { n as r } from "../chunks/parts-D30c8OoG.js";
5
+ import { i, r as a, t as o } from "../chunks/keyboard-MQpfTX5I.js";
6
+ import { property as s } from "lit/decorators.js";
5
7
  //#region src/components/menu.ts
6
- var a = class extends e {
8
+ var c = class extends e {
7
9
  constructor(...e) {
8
- super(...e), this.open = !1, this.searchable = !1, this.size = "md", this.placeholder = "Search...", this._query = "", this._userContent = [], this._didSetup = !1, this._handleKeydown = (e) => {
9
- if (this.open) {
10
- if (e.key === "Escape") {
11
- e.preventDefault(), this.open = !1, this._clearSearch();
12
- return;
13
- }
14
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
15
- e.preventDefault();
16
- let t = Array.from(this.querySelectorAll("void-menu-item:not([disabled]):not([hidden])"));
17
- if (!t.length) return;
18
- let n = t.indexOf(document.activeElement);
19
- e.key === "ArrowDown" ? (t[n + 1] ?? t[0]).focus() : (t[n - 1] ?? t[t.length - 1]).focus();
20
- }
10
+ super(...e), this.open = !1, this.size = "md", this._query = "", this._parts = new r(this, {
11
+ tags: [
12
+ "void-menu-search",
13
+ "void-menu-content",
14
+ "void-menu-empty",
15
+ "void-menu-group",
16
+ "void-menu-item"
17
+ ],
18
+ onChange: () => this._wire()
19
+ }), this._typeahead = new o(), this._observer = null, this._handleFocusIn = (e) => {
20
+ let t = e.target.closest("void-menu-item");
21
+ t && this._parts.owns(t) && this._syncTabStop(t);
22
+ }, this._handleKeydown = (e) => {
23
+ if (!this.open) return;
24
+ let t = e.target;
25
+ if (e.key === "Escape") {
26
+ e.preventDefault(), e.stopPropagation(), this.open = !1, this._clearSearch();
27
+ return;
21
28
  }
22
- }, this._onSearchInput = (e) => {
23
- this._query = e.target.value, this._filterItems();
29
+ if (e.altKey || e.ctrlKey || e.metaKey) return;
30
+ let n = this._focusableItems, r = this._inSearch(t), o = n.indexOf(t.closest("void-menu-item")), s = n.map(() => !1), c = this._searchInput(), l;
31
+ if (e.key === "ArrowDown") l = r || o < 0 ? n[0] : n[i(s, o, 1)];
32
+ else if (e.key === "ArrowUp") l = c && o === 0 ? c : r || o < 0 ? n[n.length - 1] : n[i(s, o, -1)];
33
+ else if (e.key === "Home" && !r) l = n[0];
34
+ else if (e.key === "End" && !r) l = n[n.length - 1];
35
+ else if (a(e) && !r && o >= 0 && e.key !== " ") {
36
+ let t = this._typeahead.match(e.key, n.map((e) => e.textContent ?? ""), s, o);
37
+ t >= 0 && (e.preventDefault(), n[t].focus());
38
+ return;
39
+ } else return;
40
+ e.preventDefault(), l?.focus();
41
+ }, this._onInput = (e) => {
42
+ let t = e.target;
43
+ this._inSearch(t) && (this._query = t.value, this._parts.sync());
24
44
  };
25
45
  }
46
+ _searchInput() {
47
+ return this._parts.one("void-menu-search")?.querySelector("input") ?? null;
48
+ }
49
+ _items() {
50
+ return this._parts.all("void-menu-item");
51
+ }
52
+ get _focusableItems() {
53
+ return this._items().filter((e) => !e.disabled && !e.closest("[hidden]"));
54
+ }
55
+ _wire() {
56
+ let e = this._parts.one("void-menu-content");
57
+ if (e) {
58
+ this._parts.provide(e, "role", "menu"), this._parts.provide(e, "aria-label", this.getAttribute("aria-label") || "Menu");
59
+ let t = this._searchInput();
60
+ t && this._parts.set(t, "aria-controls", this._parts.id(e, "void-menu-content"));
61
+ }
62
+ let t = this._searchInput();
63
+ t && this._parts.provide(t, "autocomplete", "off"), this._applyFilter(), this._syncTabStop();
64
+ }
26
65
  connectedCallback() {
27
- super.connectedCallback(), this.setAttribute("role", "menu"), this._didSetup || (this._userContent = Array.from(this.childNodes)), document.addEventListener("keydown", this._handleKeydown);
66
+ super.connectedCallback(), this.addEventListener("keydown", this._handleKeydown), this.addEventListener("focusin", this._handleFocusIn), this.addEventListener("input", this._onInput), this._observer ??= new MutationObserver(() => this._syncTabStop()), this._observer.observe(this, {
67
+ subtree: !0,
68
+ attributes: !0,
69
+ attributeFilter: ["hidden", "disabled"]
70
+ });
28
71
  }
29
72
  disconnectedCallback() {
30
- super.disconnectedCallback(), document.removeEventListener("keydown", this._handleKeydown);
73
+ super.disconnectedCallback(), this.removeEventListener("keydown", this._handleKeydown), this.removeEventListener("focusin", this._handleFocusIn), this.removeEventListener("input", this._onInput), this._observer?.disconnect(), this._typeahead.reset();
31
74
  }
32
75
  updated(e) {
33
- if (super.updated(e), !this._didSetup) {
34
- this._didSetup = !0;
35
- let e = this.querySelector(".void-menu-list");
36
- if (e) for (let t of this._userContent) e.appendChild(t);
37
- }
38
- e.has("open") && this.open && this.searchable && requestAnimationFrame(() => {
39
- this.querySelector(".void-menu-search")?.focus();
40
- });
76
+ super.updated(e), this._syncTabStop(), e.has("open") && this.open && requestAnimationFrame(() => this._searchInput()?.focus());
41
77
  }
42
- _filterItems() {
43
- let e = this._query.toLowerCase();
44
- this.querySelectorAll("void-menu-item").forEach((t) => {
45
- let n = (t.textContent?.trim() ?? "").toLowerCase(), r = (t.getAttribute("value") ?? "").toLowerCase();
46
- !e || n.includes(e) || r.includes(e) ? t.removeAttribute("hidden") : t.setAttribute("hidden", "");
47
- }), this.querySelectorAll("void-menu-group").forEach((e) => {
48
- e.querySelectorAll("void-menu-item:not([hidden])").length === 0 ? e.setAttribute("hidden", "") : e.removeAttribute("hidden");
49
- }), this._updateEmptyState();
50
- }
51
- _updateEmptyState() {
52
- let e = this.querySelector(".void-menu-list");
53
- if (!e) return;
54
- let t = this.querySelector(".void-menu-empty");
55
- this.querySelectorAll("void-menu-item:not([hidden])").length === 0 && this._query ? t || (t = document.createElement("div"), t.className = "void-menu-empty", t.textContent = "No results found", e.appendChild(t)) : t && t.remove();
78
+ _syncTabStop(e) {
79
+ let t = this._focusableItems, n = e && t.includes(e) ? e : t.find((e) => e.getAttribute("tabindex") === "0") ?? t[0];
80
+ for (let e of this._items()) typeof e._setTabStop == "function" && e._setTabStop(e === n);
81
+ }
82
+ _inSearch(e) {
83
+ return !!this._parts.one("void-menu-search")?.contains(e);
84
+ }
85
+ _applyFilter() {
86
+ let e = this._query.toLowerCase(), t = 0;
87
+ if (e) {
88
+ for (let n of this._items()) {
89
+ let r = (n.textContent?.trim() ?? "").toLowerCase(), i = (n.getAttribute("value") ?? "").toLowerCase();
90
+ r.includes(e) || i.includes(e) ? t++ : this._parts.set(n, "hidden", !0);
91
+ }
92
+ for (let e of this._parts.all("void-menu-group")) e.querySelector("void-menu-item:not([hidden])") || this._parts.set(e, "hidden", !0);
93
+ } else t = 1;
94
+ this.setHostAttribute("empty", !!e && t === 0);
56
95
  }
57
96
  _clearSearch() {
58
97
  this._query = "";
59
- let e = this.querySelector(".void-menu-search");
60
- e && (e.value = ""), this.querySelectorAll("void-menu-item[hidden], void-menu-group[hidden]").forEach((e) => {
61
- e.removeAttribute("hidden");
62
- });
63
- let t = this.querySelector(".void-menu-empty");
64
- t && t.remove();
65
- }
66
- render() {
67
- return this.open ? n`
68
- ${this.searchable ? n`
69
- <input
70
- class="void-menu-search"
71
- type="text"
72
- placeholder=${this.placeholder}
73
- autocomplete="off"
74
- @input=${this._onSearchInput}
75
- />
76
- ` : r}
77
- <div class="void-menu-list" role="listbox" aria-label="Menu options"></div>
78
- ` : r;
98
+ let e = this._searchInput();
99
+ e && (e.value = ""), this._parts.sync();
79
100
  }
80
101
  };
81
- t([i({
102
+ t([s({
82
103
  type: Boolean,
83
104
  reflect: !0
84
- })], a.prototype, "open", void 0), t([i({
85
- type: Boolean,
86
- reflect: !0
87
- })], a.prototype, "searchable", void 0), t([i({
105
+ })], c.prototype, "open", void 0), t([s({
88
106
  type: String,
89
107
  reflect: !0
90
- })], a.prototype, "size", void 0), t([i({ type: String })], a.prototype, "placeholder", void 0), customElements.get("void-menu") || customElements.define("void-menu", a);
91
- var o = class extends e {
108
+ })], c.prototype, "size", void 0), customElements.get("void-menu") || customElements.define("void-menu", c);
109
+ var l = class extends e {
92
110
  constructor(...e) {
93
- super(...e), this.value = "", this.disabled = !1, this.shortcut = "", this.icon = "", this._originalContent = null, this._handleClick = (e) => {
111
+ super(...e), this._activation = new n(this, { disabled: () => this.disabled }), this.value = "", this.disabled = !1, this._handleClick = (e) => {
94
112
  if (this.disabled) {
95
113
  e.stopImmediatePropagation();
96
114
  return;
@@ -98,65 +116,48 @@ var o = class extends e {
98
116
  this.dispatchEvent(new CustomEvent("void-select", {
99
117
  bubbles: !0,
100
118
  composed: !0,
101
- detail: { value: this.value }
119
+ detail: {
120
+ item: this,
121
+ value: this.value
122
+ }
102
123
  }));
103
- }, this._handleKeydown = (e) => {
104
- (e.key === "Enter" || e.key === " ") && !this.disabled && (e.preventDefault(), this._handleClick(e));
105
124
  };
106
125
  }
107
126
  connectedCallback() {
108
- super.connectedCallback(), this.setAttribute("role", "menuitem"), this.setAttribute("tabindex", this.disabled ? "-1" : "0"), this.addEventListener("click", this._handleClick), this.addEventListener("keydown", this._handleKeydown), this._originalContent === null && (this._originalContent = Array.from(this.childNodes).map((e) => e.cloneNode(!0))), this._buildContent();
127
+ super.connectedCallback(), this.setHostAttribute("role", "menuitem"), this.setHostAttribute("tabindex", "-1"), this.addEventListener("click", this._handleClick);
109
128
  }
110
129
  disconnectedCallback() {
111
- super.disconnectedCallback(), this.removeEventListener("click", this._handleClick), this.removeEventListener("keydown", this._handleKeydown);
130
+ super.disconnectedCallback(), this.removeEventListener("click", this._handleClick);
112
131
  }
113
132
  updated(e) {
114
- e.has("disabled") && (this.setAttribute("tabindex", this.disabled ? "-1" : "0"), this.setAttribute("aria-disabled", String(this.disabled)));
115
- }
116
- _buildContent() {
117
- if (!this.icon && !this.shortcut) return;
118
- let e = document.createDocumentFragment();
119
- if (this.icon) {
120
- let t = document.createElement("span");
121
- t.className = "void-menu-item-icon", t.textContent = this.icon, e.appendChild(t);
122
- }
123
- let t = document.createElement("span");
124
- if (t.className = "void-menu-item-label", this._originalContent) for (let e of this._originalContent) t.appendChild(e.cloneNode(!0));
125
- if (e.appendChild(t), this.shortcut) {
126
- let t = document.createElement("span");
127
- t.className = "void-menu-item-shortcut", t.textContent = this.shortcut, e.appendChild(t);
128
- }
129
- this.textContent = "", this.appendChild(e);
133
+ super.updated(e), e.has("disabled") && (this.setHostAttribute("tabindex", "-1"), this.setHostAttribute("aria-disabled", this.disabled ? "true" : null));
134
+ }
135
+ _setTabStop(e) {
136
+ this.setHostAttribute("tabindex", e && !this.disabled ? "0" : "-1");
130
137
  }
131
138
  };
132
- t([i({ type: String })], o.prototype, "value", void 0), t([i({
139
+ t([s({
140
+ type: String,
141
+ reflect: !0
142
+ })], l.prototype, "value", void 0), t([s({
133
143
  type: Boolean,
134
144
  reflect: !0
135
- })], o.prototype, "disabled", void 0), t([i({ type: String })], o.prototype, "shortcut", void 0), t([i({ type: String })], o.prototype, "icon", void 0), customElements.get("void-menu-item") || customElements.define("void-menu-item", o);
136
- var s = class extends e {
145
+ })], l.prototype, "disabled", void 0), customElements.get("void-menu-item") || customElements.define("void-menu-item", l);
146
+ var u = class extends e {
137
147
  constructor(...e) {
138
- super(...e), this.label = "", this._userContent = [], this._didSetup = !1;
139
- }
140
- connectedCallback() {
141
- super.connectedCallback(), this.setAttribute("role", "group"), this.label && this.setAttribute("aria-label", this.label), this._didSetup || (this._userContent = Array.from(this.childNodes));
148
+ super(...e), this._parts = new r(this, {
149
+ tags: ["void-menu-group-label"],
150
+ onChange: () => this._wire()
151
+ });
142
152
  }
143
- updated(e) {
144
- if (super.updated(e), e.has("label") && this.label && this.setAttribute("aria-label", this.label), !this._didSetup) {
145
- this._didSetup = !0;
146
- let e = this.querySelector(".void-menu-group-items");
147
- if (e) for (let t of this._userContent) e.appendChild(t);
148
- }
153
+ _wire() {
154
+ let e = this._parts.one("void-menu-group-label");
155
+ this.setHostAttribute("aria-labelledby", e ? this._parts.id(e, "void-menu-group-label") : null);
149
156
  }
150
- render() {
151
- return n`
152
- ${this.label ? n`<div class="void-menu-group-label">${this.label}</div>` : r}
153
- <div class="void-menu-group-items"></div>
154
- `;
157
+ connectedCallback() {
158
+ super.connectedCallback(), this.setHostAttribute("role", "group");
155
159
  }
156
160
  };
157
- t([i({
158
- type: String,
159
- reflect: !0
160
- })], s.prototype, "label", void 0), customElements.get("void-menu-group") || customElements.define("void-menu-group", s);
161
+ customElements.get("void-menu-group") || customElements.define("void-menu-group", u);
161
162
  //#endregion
162
- export { a as VoidMenu, s as VoidMenuGroup, o as VoidMenuItem };
163
+ export { c as VoidMenu, u as VoidMenuGroup, l as VoidMenuItem };