@mortenbrudvik/waveui 0.8.0 → 0.10.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 (206) hide show
  1. package/README.md +634 -167
  2. package/dist/components/data-display/InfoButton.cjs +2 -0
  3. package/dist/components/data-display/InfoButton.cjs.map +1 -0
  4. package/dist/components/data-display/InfoButton.mjs +173 -0
  5. package/dist/components/data-display/InfoButton.mjs.map +1 -0
  6. package/dist/components/data-display/InfoLabel.cjs +1 -1
  7. package/dist/components/data-display/InfoLabel.cjs.map +1 -1
  8. package/dist/components/data-display/InfoLabel.mjs +39 -96
  9. package/dist/components/data-display/InfoLabel.mjs.map +1 -1
  10. package/dist/components/input/Calendar.cjs +2 -0
  11. package/dist/components/input/Calendar.cjs.map +1 -0
  12. package/dist/components/input/Calendar.mjs +352 -0
  13. package/dist/components/input/Calendar.mjs.map +1 -0
  14. package/dist/components/input/Calendar.views.cjs +2 -0
  15. package/dist/components/input/Calendar.views.cjs.map +1 -0
  16. package/dist/components/input/Calendar.views.mjs +194 -0
  17. package/dist/components/input/Calendar.views.mjs.map +1 -0
  18. package/dist/components/input/Checkbox.cjs +1 -1
  19. package/dist/components/input/Checkbox.cjs.map +1 -1
  20. package/dist/components/input/Checkbox.mjs +91 -75
  21. package/dist/components/input/Checkbox.mjs.map +1 -1
  22. package/dist/components/input/ColorArea.cjs +1 -1
  23. package/dist/components/input/ColorArea.cjs.map +1 -1
  24. package/dist/components/input/ColorArea.mjs +18 -18
  25. package/dist/components/input/ColorArea.mjs.map +1 -1
  26. package/dist/components/input/ColorPicker.parts.cjs +1 -1
  27. package/dist/components/input/ColorPicker.parts.cjs.map +1 -1
  28. package/dist/components/input/ColorPicker.parts.mjs +1 -1
  29. package/dist/components/input/ColorPicker.parts.mjs.map +1 -1
  30. package/dist/components/input/Combobox.cjs +1 -1
  31. package/dist/components/input/Combobox.cjs.map +1 -1
  32. package/dist/components/input/Combobox.expand.cjs +1 -1
  33. package/dist/components/input/Combobox.expand.cjs.map +1 -1
  34. package/dist/components/input/Combobox.expand.mjs +20 -20
  35. package/dist/components/input/Combobox.expand.mjs.map +1 -1
  36. package/dist/components/input/Combobox.mjs +219 -138
  37. package/dist/components/input/Combobox.mjs.map +1 -1
  38. package/dist/components/input/Combobox.text.cjs +2 -0
  39. package/dist/components/input/Combobox.text.cjs.map +1 -0
  40. package/dist/components/input/Combobox.text.mjs +24 -0
  41. package/dist/components/input/Combobox.text.mjs.map +1 -0
  42. package/dist/components/input/DatePicker.cjs +1 -1
  43. package/dist/components/input/DatePicker.cjs.map +1 -1
  44. package/dist/components/input/DatePicker.mjs +205 -286
  45. package/dist/components/input/DatePicker.mjs.map +1 -1
  46. package/dist/components/input/Dropdown.cjs +1 -1
  47. package/dist/components/input/Dropdown.cjs.map +1 -1
  48. package/dist/components/input/Dropdown.mjs +137 -105
  49. package/dist/components/input/Dropdown.mjs.map +1 -1
  50. package/dist/components/input/Field.cjs +1 -1
  51. package/dist/components/input/Field.cjs.map +1 -1
  52. package/dist/components/input/Field.mjs +99 -66
  53. package/dist/components/input/Field.mjs.map +1 -1
  54. package/dist/components/input/Input.cjs +1 -1
  55. package/dist/components/input/Input.cjs.map +1 -1
  56. package/dist/components/input/Input.mjs +79 -55
  57. package/dist/components/input/Input.mjs.map +1 -1
  58. package/dist/components/input/Label.cjs +1 -1
  59. package/dist/components/input/Label.cjs.map +1 -1
  60. package/dist/components/input/Label.mjs +19 -13
  61. package/dist/components/input/Label.mjs.map +1 -1
  62. package/dist/components/input/Listbox.cjs +2 -0
  63. package/dist/components/input/Listbox.cjs.map +1 -0
  64. package/dist/components/input/Listbox.mjs +134 -0
  65. package/dist/components/input/Listbox.mjs.map +1 -0
  66. package/dist/components/input/Option.cjs +1 -1
  67. package/dist/components/input/Option.cjs.map +1 -1
  68. package/dist/components/input/Option.mjs +158 -97
  69. package/dist/components/input/Option.mjs.map +1 -1
  70. package/dist/components/input/Rating.cjs +1 -1
  71. package/dist/components/input/Rating.cjs.map +1 -1
  72. package/dist/components/input/Rating.item.cjs +2 -0
  73. package/dist/components/input/Rating.item.cjs.map +1 -0
  74. package/dist/components/input/Rating.item.mjs +255 -0
  75. package/dist/components/input/Rating.item.mjs.map +1 -0
  76. package/dist/components/input/Rating.mjs +150 -151
  77. package/dist/components/input/Rating.mjs.map +1 -1
  78. package/dist/components/input/SearchBox.cjs +1 -1
  79. package/dist/components/input/SearchBox.cjs.map +1 -1
  80. package/dist/components/input/SearchBox.mjs +146 -115
  81. package/dist/components/input/SearchBox.mjs.map +1 -1
  82. package/dist/components/input/Select.cjs +1 -1
  83. package/dist/components/input/Select.cjs.map +1 -1
  84. package/dist/components/input/Select.mjs +34 -25
  85. package/dist/components/input/Select.mjs.map +1 -1
  86. package/dist/components/input/Slider.cjs +1 -1
  87. package/dist/components/input/Slider.cjs.map +1 -1
  88. package/dist/components/input/Slider.mjs +77 -54
  89. package/dist/components/input/Slider.mjs.map +1 -1
  90. package/dist/components/input/SpinButton.cjs +1 -1
  91. package/dist/components/input/SpinButton.cjs.map +1 -1
  92. package/dist/components/input/SpinButton.mjs +198 -96
  93. package/dist/components/input/SpinButton.mjs.map +1 -1
  94. package/dist/components/input/SwatchPicker.cjs +1 -1
  95. package/dist/components/input/SwatchPicker.cjs.map +1 -1
  96. package/dist/components/input/SwatchPicker.context.cjs +2 -0
  97. package/dist/components/input/SwatchPicker.context.cjs.map +1 -0
  98. package/dist/components/input/SwatchPicker.context.mjs +35 -0
  99. package/dist/components/input/SwatchPicker.context.mjs.map +1 -0
  100. package/dist/components/input/SwatchPicker.mjs +131 -103
  101. package/dist/components/input/SwatchPicker.mjs.map +1 -1
  102. package/dist/components/input/SwatchPicker.swatches.cjs +2 -0
  103. package/dist/components/input/SwatchPicker.swatches.cjs.map +1 -0
  104. package/dist/components/input/SwatchPicker.swatches.mjs +207 -0
  105. package/dist/components/input/SwatchPicker.swatches.mjs.map +1 -0
  106. package/dist/components/input/Switch.cjs +1 -1
  107. package/dist/components/input/Switch.cjs.map +1 -1
  108. package/dist/components/input/Switch.mjs +71 -55
  109. package/dist/components/input/Switch.mjs.map +1 -1
  110. package/dist/components/input/TagPicker.cjs +1 -1
  111. package/dist/components/input/TagPicker.cjs.map +1 -1
  112. package/dist/components/input/TagPicker.mjs +154 -123
  113. package/dist/components/input/TagPicker.mjs.map +1 -1
  114. package/dist/components/input/Textarea.cjs +1 -1
  115. package/dist/components/input/Textarea.cjs.map +1 -1
  116. package/dist/components/input/Textarea.mjs +28 -21
  117. package/dist/components/input/Textarea.mjs.map +1 -1
  118. package/dist/components/input/TimePicker.cjs +1 -1
  119. package/dist/components/input/TimePicker.cjs.map +1 -1
  120. package/dist/components/input/TimePicker.mjs +204 -199
  121. package/dist/components/input/TimePicker.mjs.map +1 -1
  122. package/dist/components/input/dateUtils.cjs +1 -1
  123. package/dist/components/input/dateUtils.cjs.map +1 -1
  124. package/dist/components/input/dateUtils.mjs +114 -96
  125. package/dist/components/input/dateUtils.mjs.map +1 -1
  126. package/dist/components/input/fieldLabel.cjs +2 -0
  127. package/dist/components/input/fieldLabel.cjs.map +1 -0
  128. package/dist/components/input/fieldLabel.mjs +17 -0
  129. package/dist/components/input/fieldLabel.mjs.map +1 -0
  130. package/dist/components/input/inputLook.cjs +2 -0
  131. package/dist/components/input/inputLook.cjs.map +1 -0
  132. package/dist/components/input/inputLook.mjs +28 -0
  133. package/dist/components/input/inputLook.mjs.map +1 -0
  134. package/dist/components/input/pickerLabels.cjs +2 -0
  135. package/dist/components/input/pickerLabels.cjs.map +1 -0
  136. package/dist/components/input/pickerLabels.mjs +16 -0
  137. package/dist/components/input/pickerLabels.mjs.map +1 -0
  138. package/dist/components/input/pickerStyles.cjs +1 -1
  139. package/dist/components/input/pickerStyles.cjs.map +1 -1
  140. package/dist/components/input/pickerStyles.mjs +42 -4
  141. package/dist/components/input/pickerStyles.mjs.map +1 -1
  142. package/dist/components/input/pickerValues.cjs +2 -0
  143. package/dist/components/input/pickerValues.cjs.map +1 -0
  144. package/dist/components/input/pickerValues.mjs +24 -0
  145. package/dist/components/input/pickerValues.mjs.map +1 -0
  146. package/dist/components/navigation/Menu.popover.cjs +1 -1
  147. package/dist/components/navigation/Menu.popover.cjs.map +1 -1
  148. package/dist/components/navigation/Menu.popover.mjs +10 -10
  149. package/dist/components/navigation/Menu.root.cjs +1 -1
  150. package/dist/components/navigation/Menu.root.cjs.map +1 -1
  151. package/dist/components/navigation/Menu.root.mjs +10 -10
  152. package/dist/components/overlays/Popover.cjs +1 -1
  153. package/dist/components/overlays/Popover.cjs.map +1 -1
  154. package/dist/components/overlays/Popover.mjs +203 -208
  155. package/dist/components/overlays/Popover.mjs.map +1 -1
  156. package/dist/components/overlays/Popover.shared.cjs +1 -1
  157. package/dist/components/overlays/Popover.shared.cjs.map +1 -1
  158. package/dist/components/overlays/Popover.shared.mjs +82 -77
  159. package/dist/components/overlays/Popover.shared.mjs.map +1 -1
  160. package/dist/components/provider/WaveProvider.cjs +1 -1
  161. package/dist/components/provider/WaveProvider.cjs.map +1 -1
  162. package/dist/components/provider/WaveProvider.mjs +25 -19
  163. package/dist/components/provider/WaveProvider.mjs.map +1 -1
  164. package/dist/components/table/useGridNavigation.cjs +1 -1
  165. package/dist/components/table/useGridNavigation.cjs.map +1 -1
  166. package/dist/components/table/useGridNavigation.mjs +67 -70
  167. package/dist/components/table/useGridNavigation.mjs.map +1 -1
  168. package/dist/hooks/useActiveDescendant.cjs +2 -0
  169. package/dist/hooks/useActiveDescendant.cjs.map +1 -0
  170. package/dist/hooks/useActiveDescendant.mjs +56 -0
  171. package/dist/hooks/useActiveDescendant.mjs.map +1 -0
  172. package/dist/hooks/useFieldControl.cjs.map +1 -1
  173. package/dist/hooks/useFieldControl.mjs.map +1 -1
  174. package/dist/hooks/useListbox.cjs +1 -1
  175. package/dist/hooks/useListbox.cjs.map +1 -1
  176. package/dist/hooks/useListbox.mjs +250 -210
  177. package/dist/hooks/useListbox.mjs.map +1 -1
  178. package/dist/hooks/useRovingGrid.cjs +2 -0
  179. package/dist/hooks/useRovingGrid.cjs.map +1 -0
  180. package/dist/hooks/useRovingGrid.mjs +69 -0
  181. package/dist/hooks/useRovingGrid.mjs.map +1 -0
  182. package/dist/index.cjs +1 -1
  183. package/dist/index.d.cts +2901 -203
  184. package/dist/index.d.ts +2901 -203
  185. package/dist/index.mjs +107 -99
  186. package/dist/lib/classNames.cjs +1 -1
  187. package/dist/lib/classNames.cjs.map +1 -1
  188. package/dist/lib/classNames.mjs +111 -67
  189. package/dist/lib/classNames.mjs.map +1 -1
  190. package/dist/lib/date.cjs +2 -0
  191. package/dist/lib/date.cjs.map +1 -0
  192. package/dist/lib/date.mjs +44 -0
  193. package/dist/lib/date.mjs.map +1 -0
  194. package/dist/lib/focus.cjs +1 -1
  195. package/dist/lib/focus.cjs.map +1 -1
  196. package/dist/lib/focus.mjs +5 -2
  197. package/dist/lib/focus.mjs.map +1 -1
  198. package/dist/lib/layers.cjs.map +1 -1
  199. package/dist/lib/layers.mjs.map +1 -1
  200. package/dist/lib/styles.cjs +1 -1
  201. package/dist/lib/styles.cjs.map +1 -1
  202. package/dist/lib/styles.mjs +21 -4
  203. package/dist/lib/styles.mjs.map +1 -1
  204. package/dist/styles.css +1 -1
  205. package/package.json +1 -1
  206. package/src/styles/tokens.css +13 -0
@@ -5,29 +5,27 @@ import { useEventCallback as i } from "./useEventCallback.mjs";
5
5
  import { useId as a } from "./useId.mjs";
6
6
  import { isAltGraphCharacter as o, useTypeahead as s } from "./useTypeahead.mjs";
7
7
  import { useMergedRefs as c } from "./useMergedRefs.mjs";
8
- import * as l from "react";
9
- import { useCallback as u, useContext as d, useEffect as f, useLayoutEffect as p, useMemo as m, useRef as h, useState as g, useSyncExternalStore as ee } from "react";
8
+ import { useActiveDescendant as l } from "./useActiveDescendant.mjs";
9
+ import * as u from "react";
10
+ import { useCallback as d, useContext as f, useEffect as p, useLayoutEffect as m, useMemo as h, useRef as g, useState as _, useSyncExternalStore as v } from "react";
10
11
  //#region src/hooks/useListbox.ts
11
- var _ = [], v = /* @__PURE__ */ new Set();
12
- function y() {
13
- return _;
12
+ var y = [], b = /* @__PURE__ */ new Set();
13
+ function x() {
14
+ return y;
14
15
  }
15
- function b(e, t) {
16
+ function S(e, t) {
16
17
  if (e === t) return !0;
17
18
  if (e.size !== t.size) return !1;
18
19
  for (let n of e) if (!t.has(n)) return !1;
19
20
  return !0;
20
21
  }
21
- function x(e, t) {
22
- return e.value === t.value && e.label === t.label && e.textValue === t.textValue && !!e.disabled == !!t.disabled && !!e.hidden == !!t.hidden;
23
- }
24
- function S(e, t) {
25
- return e === t || e.length === t.length && e.every((e, n) => x(e, t[n]));
26
- }
27
22
  function C(e, t) {
28
- return e === t || e.length === t.length && e.every((e, n) => e.value === t[n].value);
23
+ return e.value === t.value && e.label === t.label && e.textValue === t.textValue && !!e.disabled == !!t.disabled && !!e.hidden == !!t.hidden;
29
24
  }
30
25
  function w(e, t) {
26
+ return e === t || e.length === t.length && e.every((e, n) => C(e, t[n]));
27
+ }
28
+ function T(e, t) {
31
29
  let n = e.element.current, r = t.element.current;
32
30
  if (n && r && n !== r && n.isConnected && r.isConnected) {
33
31
  let e = n.compareDocumentPosition(r);
@@ -36,7 +34,7 @@ function w(e, t) {
36
34
  }
37
35
  return e.seq - t.seq;
38
36
  }
39
- var T = class {
37
+ var E = class {
40
38
  indexByValue = /* @__PURE__ */ new Map();
41
39
  registrations = /* @__PURE__ */ new Set();
42
40
  stateListeners = /* @__PURE__ */ new Set();
@@ -46,7 +44,7 @@ var T = class {
46
44
  dirty = !1;
47
45
  flushScheduled = !1;
48
46
  itemsStale = !1;
49
- itemsSnapshot = _;
47
+ itemsSnapshot = y;
50
48
  sorted = [];
51
49
  observer = null;
52
50
  observed = null;
@@ -55,7 +53,7 @@ var T = class {
55
53
  registrationMode = !0;
56
54
  active = null;
57
55
  selected;
58
- hidden = v;
56
+ hidden = b;
59
57
  constructor(e) {
60
58
  this.selected = new Set(e);
61
59
  }
@@ -85,21 +83,21 @@ var T = class {
85
83
  getItems = () => {
86
84
  if (this.itemsStale) {
87
85
  this.itemsStale = !1;
88
- let e = Array.from(this.registrations).sort(w);
86
+ let e = Array.from(this.registrations).sort(T);
89
87
  this.sorted = e;
90
88
  let t = /* @__PURE__ */ new Set(), n = [];
91
89
  for (let { item: r } of e) t.has(r.value) || (t.add(r.value), n.push(r));
92
- S(n, this.itemsSnapshot) || (this.itemsSnapshot = n);
90
+ w(n, this.itemsSnapshot) || (this.itemsSnapshot = n);
93
91
  }
94
92
  return this.itemsSnapshot;
95
93
  };
96
- getElement(e) {
94
+ getElement = (e) => {
97
95
  for (let { item: t, element: n } of this.registrations) {
98
96
  let r = n.current;
99
97
  if (t.value === e && r && r.isConnected) return r;
100
98
  }
101
99
  return null;
102
- }
100
+ };
103
101
  setRegistrationMode(e) {
104
102
  e !== this.registrationMode && (this.registrationMode = e, this.syncObserver());
105
103
  }
@@ -129,7 +127,7 @@ var T = class {
129
127
  }
130
128
  setRenderState(e, t, n) {
131
129
  let r = !1;
132
- if (e !== this.active && (this.active = e, r = !0), b(t, this.selected) || (this.selected = t, r = !0), b(n, this.hidden) || (this.hidden = n, r = !0), r) for (let e of Array.from(this.stateListeners)) e();
130
+ if (e !== this.active && (this.active = e, r = !0), S(t, this.selected) || (this.selected = t, r = !0), S(n, this.hidden) || (this.hidden = n, r = !0), r) for (let e of Array.from(this.stateListeners)) e();
133
131
  }
134
132
  notifyItems() {
135
133
  for (let e of Array.from(this.itemListeners)) e();
@@ -139,7 +137,7 @@ var T = class {
139
137
  };
140
138
  syncObserver() {
141
139
  let e = this.connected && this.registrationMode && typeof MutationObserver < "u" ? this.commonAncestor() : null;
142
- e !== this.observed && (this.observer?.disconnect(), this.observed = e, this.watching = !1, e && (t && D(e), this.observer ??= new MutationObserver(this.onMutation), this.observer.observe(e, {
140
+ e !== this.observed && (this.observer?.disconnect(), this.observed = e, this.watching = !1, e && (t && O(e), this.observer ??= new MutationObserver(this.onMutation), this.observer.observe(e, {
143
141
  childList: !0,
144
142
  subtree: !0
145
143
  })));
@@ -166,66 +164,69 @@ var T = class {
166
164
  }
167
165
  warnDuplicates() {
168
166
  let e = /* @__PURE__ */ new Set();
169
- for (let { item: t } of this.registrations) e.has(t.value) && E(t.value), e.add(t.value);
167
+ for (let { item: t } of this.registrations) e.has(t.value) && D(t.value), e.add(t.value);
170
168
  }
171
169
  };
172
- function E(e) {
170
+ function D(e) {
173
171
  r(`useListbox:duplicate:${e}`, `Listbox: several options share the value "${e}". Option values must be unique within a listbox; only the first one can be highlighted and selected.`);
174
172
  }
175
- function D(e) {
173
+ function O(e) {
176
174
  let t = e.ownerDocument;
177
175
  !t || e !== t.body && e !== t.documentElement || r("useListbox:single-container", "Listbox: the options of one listbox are rendered in more than one container (for example an inline list kept mounted next to a portaled one). All options must live in a single container at a time: render the list inline only while closed and in the portal only while open.");
178
176
  }
179
- var O = l.createContext(null);
180
- O.displayName = "ListboxContext";
181
- var k = null;
182
- function A() {
183
- return k ??= {
177
+ var k = u.createContext(null);
178
+ k.displayName = "ListboxContext";
179
+ var A = null;
180
+ function j() {
181
+ return A ??= {
184
182
  listboxId: "wave-listbox-inert",
185
- store: new T([]),
183
+ store: new E([]),
184
+ multiselect: !1,
185
+ mode: "select-only",
186
186
  select: () => {},
187
- highlight: () => {}
188
- }, k;
187
+ highlight: () => {},
188
+ press: () => {}
189
+ }, A;
189
190
  }
190
- function j(e) {
191
- return d(O) || (n(e, "a listbox (Combobox or Dropdown)"), A());
191
+ function M(e) {
192
+ return f(k) || (n(e, "a listbox (Listbox, Combobox, Dropdown or a ListboxProvider)"), j());
192
193
  }
193
- var M = Symbol.for("@mortenbrudvik/waveui/listbox-element-kind");
194
- function N(e, t) {
195
- return Object.defineProperty(e, M, {
194
+ var N = Symbol.for("@mortenbrudvik/waveui/listbox-element-kind");
195
+ function P(e, t) {
196
+ return Object.defineProperty(e, N, {
196
197
  value: t,
197
198
  configurable: !0
198
199
  }), e;
199
200
  }
200
- function P(e) {
201
+ function F(e) {
201
202
  if (typeof e != "function" && typeof e != "object" || e === null) return;
202
- let t = e[M];
203
+ let t = e[N];
203
204
  return t === "option" || t === "group" ? t : void 0;
204
205
  }
205
- function F(e) {
206
+ function I(e) {
206
207
  if (typeof e == "string") return e;
207
208
  if (typeof e == "number" || typeof e == "bigint") return String(e);
208
209
  if (e == null || typeof e == "boolean") return "";
209
- if (l.isValidElement(e)) return typeof e.type == "string" || e.type === l.Fragment ? F(e.props.children) : "";
210
+ if (u.isValidElement(e)) return typeof e.type == "string" || e.type === u.Fragment ? I(e.props.children) : "";
210
211
  if (typeof e == "object" && Symbol.iterator in e) {
211
212
  let t = "";
212
- for (let n of e) t += F(n);
213
+ for (let n of e) t += I(n);
213
214
  return t;
214
215
  }
215
216
  return "";
216
217
  }
217
- function I(e, t) {
218
- return typeof e.label == "string" ? e.label : typeof e.textValue == "string" ? e.textValue : e.children === null || e.children === void 0 ? t : F(e.children).trim() || void 0;
218
+ function ee(e, t) {
219
+ return typeof e.label == "string" ? e.label : typeof e.textValue == "string" ? e.textValue : e.children === null || e.children === void 0 ? t : I(e.children).trim() || void 0;
219
220
  }
220
221
  function L(t, n) {
221
- l.Children.forEach(t, (t) => {
222
- if (!l.isValidElement(t)) return;
222
+ u.Children.forEach(t, (t) => {
223
+ if (!u.isValidElement(t)) return;
223
224
  let r = e(t);
224
- if (r === l.Fragment) {
225
+ if (r === u.Fragment) {
225
226
  L(t.props.children, n);
226
227
  return;
227
228
  }
228
- let i = P(r);
229
+ let i = F(r);
229
230
  if (i === "group") {
230
231
  L(t.props.children, n);
231
232
  return;
@@ -233,7 +234,7 @@ function L(t, n) {
233
234
  if (i !== "option") return;
234
235
  let { value: a } = t.props;
235
236
  if (typeof a != "string" || n.has(a)) return;
236
- let o = I(t.props, a);
237
+ let o = ee(t.props, a);
237
238
  o !== void 0 && n.set(a, o);
238
239
  });
239
240
  }
@@ -241,15 +242,7 @@ function R(e) {
241
242
  let t = /* @__PURE__ */ new Map();
242
243
  return L(e, t), t;
243
244
  }
244
- function te(e, t, n, r) {
245
- let i = e.length;
246
- if (i === 0) return null;
247
- let a = t === null ? -1 : e.indexOf(t);
248
- if (a === -1) return n > 0 ? e[0] : e[i - 1];
249
- let o = a + n;
250
- return (o < 0 || o >= i) && (o = r && Math.abs(n) === 1 ? (o + i) % i : Math.max(0, Math.min(i - 1, o))), e[o];
251
- }
252
- function ne(e) {
245
+ function te(e) {
253
246
  return (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.value !== "";
254
247
  }
255
248
  var z = /* @__PURE__ */ new Set([
@@ -258,172 +251,216 @@ var z = /* @__PURE__ */ new Set([
258
251
  "z",
259
252
  "y"
260
253
  ]);
261
- function re(e) {
254
+ function ne(e) {
262
255
  let t = e.currentTarget;
263
256
  if ((t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement) && (t.readOnly || t.disabled)) return !1;
264
257
  let { key: n } = e;
265
258
  return n === "Backspace" || n === "Delete" || n === "Process" || n === "Unidentified" ? !0 : n.length === 1 ? !(e.metaKey || e.ctrlKey && !o(e)) || z.has(n.toLowerCase()) : !1;
266
259
  }
267
- function ie(e) {
260
+ function re(e) {
268
261
  e.preventDefault();
269
262
  }
270
263
  function B(e) {
271
- let { open: t, onOpenChange: n, mode: r, multiple: c = !1, selectedValues: l, onSelect: d, items: _, filter: b, loop: x = !1, typeahead: S = r === "select-only", autoHighlight: w = "selected", highlightOnFilter: D = !1, idPrefix: O, onClearDraft: k } = e, A = a(O ?? "listbox"), [j] = g(() => new T(l)), M = _ !== void 0, N = ee(j.subscribeItems, M ? y : j.getItems, y), P = _ ?? N, F = m(() => P.filter((e) => !e.hidden && (!b || b(e))), [P, b]), I = m(() => F.filter((e) => !e.disabled).map((e) => e.value), [F]), L = m(() => new Set(I), [I]), R = m(() => {
264
+ let { open: t, onOpenChange: n, mode: c, multiselect: u = !1, selectedValues: f, onSelect: y, items: S, filter: C, loop: w = !1, typeahead: T = c !== "editable", disabledOptionsFocusable: O = !1, autoHighlight: k = "selected", highlightOnFilter: A = !1, onActiveValueChange: j, idPrefix: M, onClearDraft: N } = e, P = c === "standalone", F = P ? void 0 : n, [I, ee] = _(null), L = a(M ?? "listbox"), [R] = _(() => new E(f)), z = S !== void 0, B = v(R.subscribeItems, z ? x : R.getItems, x), V = S ?? B, H = h(() => V.filter((e) => !e.hidden && (!C || C(e))), [V, C]), U = h(() => O ? H.map((e) => e.value) : H.filter((e) => !e.disabled).map((e) => e.value), [H, O]), W = h(() => {
272
265
  let e = /* @__PURE__ */ new Map();
273
- for (let t of P) e.has(t.value) || e.set(t.value, t);
266
+ for (let t of V) e.has(t.value) || e.set(t.value, t);
274
267
  return e;
275
- }, [P]), z = m(() => {
276
- if (F.length === P.length) return v;
277
- let e = new Set(F.map((e) => e.value)), t = /* @__PURE__ */ new Set();
278
- for (let n of P) e.has(n.value) || t.add(n.value);
268
+ }, [V]), G = h(() => {
269
+ if (H.length === V.length) return b;
270
+ let e = new Set(H.map((e) => e.value)), t = /* @__PURE__ */ new Set();
271
+ for (let n of V) e.has(n.value) || t.add(n.value);
279
272
  return t;
280
- }, [P, F]), B = new Set(l), [V, H] = g(null), U = t ? V : null, [W, G] = g(() => ({
281
- open: t,
282
- items: F
283
- }));
284
- if (D) {
285
- let e = !C(W.items, F);
286
- (e || W.open !== t) && (G({
287
- open: t,
288
- items: F
289
- }), t && e && (U = I[0] ?? null));
290
- }
291
- U !== null && !L.has(U) && (U = null), U !== V && H(U);
292
- let K = I.find((e) => B.has(e)) ?? null, q = null;
293
- w === "selected" ? q = K ?? I[0] ?? null : w === "first" && (q = I[0] ?? null);
294
- let J = t ? U ?? q : null, Y = u((e) => `${A}-opt-${j.getIndex(e)}`, [A, j]), X = J === null ? void 0 : Y(J), ae = u((e) => R.get(e), [R]), Z = h(null), Q = u((e) => {
295
- Z.current = null, H(e);
296
- }, []), oe = Q, $ = i((e, t, r) => {
297
- let i = R.get(e) ?? r;
298
- i && !i.disabled && (d(e, i), c && t === "select" ? Q(e) : (Q(null), n(!1, t)));
299
- }), se = i((e, t) => {
300
- $(e, "select", t);
301
- }), ce = i((e) => {
302
- t && L.has(e) && e !== J && (Z.current = e, H(e));
303
- }), { onTypeahead: le } = s({
304
- getItems: () => F.map((e) => ({
273
+ }, [V, H]), K = new Set(f), q = U.find((e) => K.has(e)) ?? null, J = null;
274
+ k === "selected" ? J = q ?? U[0] ?? null : k === "first" && (J = U[0] ?? null);
275
+ let Y = d((e) => `${L}-opt-${R.getIndex(e)}`, [L, R]), ie = d((e) => W.get(e), [W]), X = l({
276
+ items: U,
277
+ getId: Y,
278
+ enabled: t,
279
+ fallback: J,
280
+ loop: w,
281
+ activateFirstOnChange: A,
282
+ getElement: R.getElement,
283
+ onActiveValueChange: j
284
+ }), { activeValue: Z, activeDescendantId: Q } = X, $ = i((e, t, n, r) => {
285
+ let i = W.get(e) ?? r;
286
+ i && !i.disabled && (y(e, {
287
+ item: i,
288
+ event: n
289
+ }), P || u && t === "select" ? X.setActiveValue(e) : (X.setActiveValue(null), F?.(!1, {
290
+ reason: t,
291
+ event: n
292
+ })));
293
+ }), ae = i((e, t, n) => {
294
+ $(e, "select", n, t);
295
+ }), oe = i((e) => {
296
+ I ? I.focus({ preventScroll: !0 }) : P && r("useListbox:list-ref", "useListbox: the list element is unknown, so a pointer press cannot focus the list. Pass the `ref` of `getListboxProps()` to the list element, merged with your own ref."), U.includes(e) ? X.setActiveValue(e, { scroll: !1 }) : !t && J !== null && X.setActiveValue(J, { scroll: !1 });
297
+ }), se = g(null), { onTypeahead: ce } = s({
298
+ getItems: () => H.map((e) => ({
305
299
  value: e.value,
306
300
  text: e.textValue ?? e.label,
307
- disabled: e.disabled
301
+ disabled: !O && e.disabled
308
302
  })),
309
303
  onMatch: (e) => {
310
- Q(e), t || n(!0, "keyboard");
304
+ X.setActiveValue(e);
305
+ let n = se.current;
306
+ !t && n && F?.(!0, {
307
+ reason: "keyboard",
308
+ event: n
309
+ });
311
310
  }
312
- }), ue = i((e) => {
311
+ }), le = i((e) => {
313
312
  if (e.defaultPrevented || e.nativeEvent.isComposing) return;
314
- r === "editable" && t && re(e) && Q(D ? I[0] ?? null : null);
315
- let i = o(e);
316
- if (e.ctrlKey && !i || e.metaKey) return;
317
- let { key: a, altKey: s } = e, l = r === "select-only", u = I[0] ?? null, d = I[I.length - 1] ?? null, f = (e) => {
318
- Q(e), t || n(!0, "keyboard");
319
- }, p = (e) => Q(te(I, J, e, x)), m = () => {
320
- J === null ? c || n(!1, "keyboard") : $(J, "select");
313
+ se.current = e.nativeEvent, c === "editable" && t && ne(e) && X.setActiveValue(A ? U[0] ?? null : null);
314
+ let n = o(e);
315
+ if (e.ctrlKey && !n || e.metaKey) return;
316
+ let { key: r, altKey: i } = e;
317
+ if (P && (r === "Tab" || r === "Escape" || i && r.startsWith("Arrow"))) return;
318
+ let a = c === "select-only", s = c === "editable", l = U[0] ?? null, d = U[U.length - 1] ?? null, f = (n) => {
319
+ X.setActiveValue(n), t || F?.(!0, {
320
+ reason: "keyboard",
321
+ event: e.nativeEvent
322
+ });
323
+ }, p = () => {
324
+ Z === null ? u || F?.(!1, {
325
+ reason: "keyboard",
326
+ event: e.nativeEvent
327
+ }) : $(Z, "select", e.nativeEvent);
321
328
  };
322
- switch (a) {
329
+ switch (r) {
323
330
  case "ArrowDown":
324
- e.preventDefault(), s ? t || n(!0, "keyboard") : t ? p(1) : f(K ?? u);
331
+ e.preventDefault(), i ? t || F?.(!0, {
332
+ reason: "keyboard",
333
+ event: e.nativeEvent
334
+ }) : t ? X.next() : f(q ?? l);
325
335
  return;
326
336
  case "ArrowUp":
327
- if (e.preventDefault(), s) {
337
+ if (e.preventDefault(), i) {
328
338
  if (!t) return;
329
- l && !c && J !== null ? $(J, "select") : n(!1, "keyboard");
330
- } else t ? p(-1) : f(K ?? d);
339
+ a && !u && Z !== null && !W.get(Z)?.disabled ? $(Z, "select", e.nativeEvent) : F?.(!1, {
340
+ reason: "keyboard",
341
+ event: e.nativeEvent
342
+ });
343
+ } else t ? X.prev() : f(q ?? d);
331
344
  return;
332
345
  case "Home":
333
346
  case "End":
334
- if (!l) return;
335
- e.preventDefault(), f(a === "Home" ? u : d);
347
+ if (s) return;
348
+ e.preventDefault(), f(r === "Home" ? l : d);
336
349
  return;
337
350
  case "PageUp":
338
351
  case "PageDown":
339
- if (!l || !t) return;
340
- e.preventDefault(), p(a === "PageDown" ? 10 : -10);
352
+ if (s || !t) return;
353
+ e.preventDefault(), X.move(r === "PageDown" ? 10 : -10);
341
354
  return;
342
355
  case "Enter":
343
- if (!l) {
344
- t && J !== null && (e.preventDefault(), $(J, "select"));
356
+ if (s) {
357
+ t && Z !== null && (e.preventDefault(), $(Z, "select", e.nativeEvent));
345
358
  return;
346
359
  }
347
- e.preventDefault(), t ? m() : n(!0, "keyboard");
360
+ e.preventDefault(), t ? p() : F?.(!0, {
361
+ reason: "keyboard",
362
+ event: e.nativeEvent
363
+ });
348
364
  return;
349
365
  case "Escape":
350
- t ? (e.preventDefault(), n(!1, "escape")) : !l && k && ne(e.currentTarget) && (e.preventDefault(), k());
366
+ t ? (e.preventDefault(), F?.(!1, {
367
+ reason: "escape",
368
+ event: e.nativeEvent
369
+ })) : s && N && te(e.currentTarget) && (e.preventDefault(), N());
351
370
  return;
352
371
  case "Tab":
353
372
  if (!t) return;
354
- l && !c && J !== null ? $(J, "tab") : n(!1, "tab");
373
+ a && !u && Z !== null && !W.get(Z)?.disabled ? $(Z, "tab", e.nativeEvent) : F?.(!1, {
374
+ reason: "tab",
375
+ event: e.nativeEvent
376
+ });
355
377
  return;
356
378
  }
357
- if (a !== " " || l) {
358
- if (!S || s && !i || a.length !== 1) {
359
- a === " " && l && (e.preventDefault(), t ? m() : n(!0, "keyboard"));
379
+ if (!(r === " " && s)) {
380
+ if (!T || i && !n || r.length !== 1) {
381
+ r === " " && !s && (e.preventDefault(), t ? p() : F?.(!0, {
382
+ reason: "keyboard",
383
+ event: e.nativeEvent
384
+ }));
360
385
  return;
361
386
  }
362
- if (le(e, t ? J : K)) {
387
+ if (ce(e, t ? Z : q)) {
363
388
  e.preventDefault();
364
389
  return;
365
390
  }
366
- if (a === " ") {
367
- e.preventDefault(), t ? m() : n(!0, "keyboard");
391
+ if (r === " ") {
392
+ e.preventDefault(), t ? p() : F?.(!0, {
393
+ reason: "keyboard",
394
+ event: e.nativeEvent
395
+ });
368
396
  return;
369
397
  }
370
- l && !t && (e.preventDefault(), n(!0, "keyboard"));
398
+ a && !t && (e.preventDefault(), F?.(!0, {
399
+ reason: "keyboard",
400
+ event: e.nativeEvent
401
+ }));
371
402
  }
372
- }), de = i((e) => {
373
- r === "select-only" && e.key === " " && e.preventDefault();
403
+ }), ue = i((e) => {
404
+ c === "select-only" && e.key === " " && e.preventDefault();
374
405
  });
375
- return p(() => {
376
- j.setRegistrationMode(!M), j.flush(), j.checkOrderAfterCommit(), j.setRenderState(J, B, z);
377
- }), p(() => (j.connect(), () => j.disconnect()), [j]), p(() => {
378
- let e = J !== null && J === Z.current;
379
- Z.current = null, !(J === null || e) && (j.getElement(J) ?? (typeof document < "u" ? document.getElementById(Y(J)) : null))?.scrollIntoView?.({ block: "nearest" });
380
- }, [
381
- J,
382
- Y,
383
- j
384
- ]), f(() => {
385
- if (!_) return;
406
+ m(() => {
407
+ R.setRegistrationMode(!z), R.flush(), R.checkOrderAfterCommit(), R.setRenderState(Z, K, G);
408
+ }), m(() => (R.connect(), () => R.disconnect()), [R]), p(() => {
409
+ if (!S) return;
386
410
  let e = /* @__PURE__ */ new Set();
387
- for (let t of _) e.has(t.value) && E(t.value), e.add(t.value);
388
- }, [_]), {
389
- listboxId: A,
390
- activeValue: J,
391
- activeDescendantId: X,
392
- items: F,
393
- getItem: ae,
411
+ for (let t of S) e.has(t.value) && D(t.value), e.add(t.value);
412
+ }, [S]);
413
+ let de = h(() => ({
414
+ listboxId: L,
415
+ store: R,
416
+ multiselect: u,
417
+ mode: c,
418
+ select: ae,
419
+ highlight: X.highlight,
420
+ press: oe
421
+ }), [
422
+ L,
423
+ R,
424
+ u,
425
+ c,
426
+ ae,
427
+ X.highlight,
428
+ oe
429
+ ]);
430
+ return {
431
+ listboxId: L,
432
+ activeValue: Z,
433
+ activeDescendantId: Q,
434
+ items: H,
435
+ getItem: ie,
394
436
  getOptionId: Y,
395
- setActiveValue: oe,
396
- onKeyDown: ue,
397
- onKeyUp: de,
437
+ setActiveValue: X.setActiveValue,
438
+ onKeyDown: le,
439
+ onKeyUp: ue,
398
440
  getComboboxProps: () => {
399
441
  let e = {
400
442
  role: "combobox",
401
443
  "aria-expanded": t,
402
- "aria-controls": A,
444
+ "aria-controls": L,
403
445
  "aria-haspopup": "listbox"
404
446
  };
405
- return X !== void 0 && (e["aria-activedescendant"] = X), r === "editable" && (e["aria-autocomplete"] = "list"), e;
447
+ return Q !== void 0 && (e["aria-activedescendant"] = Q), c === "editable" && (e["aria-autocomplete"] = "list"), e;
406
448
  },
407
449
  getListboxProps: () => {
408
- let e = {
409
- id: A,
450
+ let e = P ? {
451
+ id: L,
452
+ role: "listbox",
453
+ tabIndex: 0,
454
+ ref: ee
455
+ } : {
456
+ id: L,
410
457
  role: "listbox",
411
458
  tabIndex: -1,
412
- onMouseDown: ie
459
+ onMouseDown: re
413
460
  };
414
- return c && (e["aria-multiselectable"] = !0), e;
461
+ return P && Q !== void 0 && (e["aria-activedescendant"] = Q), u && (e["aria-multiselectable"] = !0), e;
415
462
  },
416
- context: m(() => ({
417
- listboxId: A,
418
- store: j,
419
- select: se,
420
- highlight: ce
421
- }), [
422
- A,
423
- j,
424
- se,
425
- ce
426
- ])
463
+ context: de
427
464
  };
428
465
  }
429
466
  var V = 1, H = 2, U = 4;
@@ -431,62 +468,65 @@ function W(e, t) {
431
468
  return (e.isActive(t) ? V : 0) | (e.isSelected(t) ? H : 0) | (e.isHidden(t) ? U : 0);
432
469
  }
433
470
  function G(e, t) {
434
- let { store: n, listboxId: r, select: i, highlight: a } = j("Option"), { value: o, label: s, textValue: l, disabled: d = !1, hidden: f = !1 } = e, m = `${r}-opt-${n.getIndex(o)}`, g = ee(n.subscribe, () => W(n, o), () => W(n, o)), _ = (g & V) !== 0, v = (g & H) !== 0, y = f || (g & U) !== 0, b = h(null), S = u((e) => {
435
- b.current = e;
436
- }, []), C = c(t, S), w = h(null);
437
- p(() => {
438
- let e = s === void 0 && l === void 0 ? b.current?.textContent?.trim() : void 0, t = {
439
- value: o,
440
- label: s ?? l ?? (e || o)
471
+ let { store: n, listboxId: r, multiselect: i, mode: a, select: o, highlight: s, press: l } = M("Option"), { value: u, label: f, textValue: p, disabled: h = !1, hidden: _ = !1 } = e, y = `${r}-opt-${n.getIndex(u)}`, b = v(n.subscribe, () => W(n, u), () => W(n, u)), x = (b & V) !== 0, S = (b & H) !== 0, w = _ || (b & U) !== 0, T = g(null), E = d((e) => {
472
+ T.current = e;
473
+ }, []), D = c(t, E), O = g(null);
474
+ m(() => {
475
+ let e = f === void 0 && p === void 0 ? T.current?.textContent?.trim() : void 0, t = {
476
+ value: u,
477
+ label: f ?? p ?? (e || u)
441
478
  };
442
- l !== void 0 && (t.textValue = l), d && (t.disabled = !0), f && (t.hidden = !0);
443
- let r = w.current;
444
- r && r.store === n && x(r.item, t) || (r?.unregister(), w.current = {
479
+ p !== void 0 && (t.textValue = p), h && (t.disabled = !0), _ && (t.hidden = !0);
480
+ let r = O.current;
481
+ r && r.store === n && C(r.item, t) || (r?.unregister(), O.current = {
445
482
  store: n,
446
483
  item: t,
447
- unregister: n.register(t, b)
484
+ unregister: n.register(t, T)
448
485
  });
449
- }), p(() => () => {
450
- w.current?.unregister(), w.current = null;
486
+ }), m(() => () => {
487
+ O.current?.unregister(), O.current = null;
451
488
  }, []);
452
- let T = {
453
- id: m,
489
+ let k = d((e) => {
490
+ if (h) return;
491
+ let t = {
492
+ value: u,
493
+ label: f ?? p ?? u
494
+ };
495
+ p !== void 0 && (t.textValue = p), o(u, t, e.nativeEvent);
496
+ }, [
497
+ o,
498
+ u,
499
+ f,
500
+ p,
501
+ h
502
+ ]), A = d(() => {
503
+ !h && !n.isActive(u) && s(u);
504
+ }, [
505
+ s,
506
+ n,
507
+ u,
508
+ h
509
+ ]), j = d((e) => {
510
+ e.button === 0 && (e.preventDefault(), l(u));
511
+ }, [l, u]), N = {
512
+ id: y,
454
513
  role: "option",
455
- "aria-selected": v,
456
- onClick: u(() => {
457
- if (d) return;
458
- let e = {
459
- value: o,
460
- label: s ?? l ?? o
461
- };
462
- l !== void 0 && (e.textValue = l), i(o, e);
463
- }, [
464
- i,
465
- o,
466
- s,
467
- l,
468
- d
469
- ]),
470
- onPointerMove: u(() => {
471
- !d && !n.isActive(o) && a(o);
472
- }, [
473
- a,
474
- n,
475
- o,
476
- d
477
- ]),
478
- ref: C
514
+ "aria-selected": S,
515
+ onClick: k,
516
+ onPointerMove: A,
517
+ ref: D
479
518
  };
480
- return d && (T["aria-disabled"] = !0, T["data-disabled"] = ""), y && (T.hidden = !0), _ && (T["data-active"] = ""), v && (T["data-selected"] = ""), {
481
- id: m,
482
- selected: v,
483
- active: _,
484
- disabled: d,
485
- hidden: y,
486
- optionProps: T
519
+ return a === "standalone" && (N.onMouseDown = j), h && (N["aria-disabled"] = !0, N["data-disabled"] = ""), w && (N.hidden = !0), x && (N["data-active"] = ""), S && (N["data-selected"] = ""), {
520
+ id: y,
521
+ selected: S,
522
+ active: x,
523
+ disabled: h,
524
+ hidden: w,
525
+ multiselect: i,
526
+ optionProps: N
487
527
  };
488
528
  }
489
529
  //#endregion
490
- export { O as ListboxContext, R as collectOptionLabels, N as markListboxElement, B as useListbox, G as useListboxOption };
530
+ export { k as ListboxContext, R as collectOptionLabels, P as markListboxElement, B as useListbox, G as useListboxOption };
491
531
 
492
532
  //# sourceMappingURL=useListbox.mjs.map