@reactzero/combo 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 (124) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +188 -0
  4. package/dist/Combo-Cx3kSkop.cjs +2 -0
  5. package/dist/Combo-Cx3kSkop.cjs.map +1 -0
  6. package/dist/Combo-qs6_L512.js +439 -0
  7. package/dist/Combo-qs6_L512.js.map +1 -0
  8. package/dist/components/Combo.d.ts +71 -0
  9. package/dist/components/Combo.d.ts.map +1 -0
  10. package/dist/components/LiveRegion.d.ts +7 -0
  11. package/dist/components/LiveRegion.d.ts.map +1 -0
  12. package/dist/components/Portal.d.ts +8 -0
  13. package/dist/components/Portal.d.ts.map +1 -0
  14. package/dist/components/slots/CheckboxItem.d.ts +38 -0
  15. package/dist/components/slots/CheckboxItem.d.ts.map +1 -0
  16. package/dist/components/slots/CustomItem.d.ts +35 -0
  17. package/dist/components/slots/CustomItem.d.ts.map +1 -0
  18. package/dist/components/slots/FooterActions.d.ts +42 -0
  19. package/dist/components/slots/FooterActions.d.ts.map +1 -0
  20. package/dist/components/slots/GroupSeparator.d.ts +30 -0
  21. package/dist/components/slots/GroupSeparator.d.ts.map +1 -0
  22. package/dist/components/slots/index.d.ts +9 -0
  23. package/dist/components/slots/index.d.ts.map +1 -0
  24. package/dist/components/tabs/TabbedCombo.d.ts +45 -0
  25. package/dist/components/tabs/TabbedCombo.d.ts.map +1 -0
  26. package/dist/components/tabs/index.d.ts +3 -0
  27. package/dist/components/tabs/index.d.ts.map +1 -0
  28. package/dist/core/announce.d.ts +10 -0
  29. package/dist/core/announce.d.ts.map +1 -0
  30. package/dist/core/ids.d.ts +13 -0
  31. package/dist/core/ids.d.ts.map +1 -0
  32. package/dist/core/keyboard.d.ts +13 -0
  33. package/dist/core/keyboard.d.ts.map +1 -0
  34. package/dist/core/scroll.d.ts +5 -0
  35. package/dist/core/scroll.d.ts.map +1 -0
  36. package/dist/core/stateMachine.d.ts +32 -0
  37. package/dist/core/stateMachine.d.ts.map +1 -0
  38. package/dist/core/utils.d.ts +26 -0
  39. package/dist/core/utils.d.ts.map +1 -0
  40. package/dist/defaults-iFGq2Q-7.cjs +2 -0
  41. package/dist/defaults-iFGq2Q-7.cjs.map +1 -0
  42. package/dist/defaults-rhC5DFTg.js +53 -0
  43. package/dist/defaults-rhC5DFTg.js.map +1 -0
  44. package/dist/entries/hook-bare.d.ts +4 -0
  45. package/dist/entries/hook-bare.d.ts.map +1 -0
  46. package/dist/entries/hook.d.ts +4 -0
  47. package/dist/entries/hook.d.ts.map +1 -0
  48. package/dist/entries/icons.d.ts +4 -0
  49. package/dist/entries/icons.d.ts.map +1 -0
  50. package/dist/entries/index.d.ts +9 -0
  51. package/dist/entries/index.d.ts.map +1 -0
  52. package/dist/entries/position.d.ts +3 -0
  53. package/dist/entries/position.d.ts.map +1 -0
  54. package/dist/entries/slots.d.ts +9 -0
  55. package/dist/entries/slots.d.ts.map +1 -0
  56. package/dist/entries/tabs.d.ts +4 -0
  57. package/dist/entries/tabs.d.ts.map +1 -0
  58. package/dist/hook-bare.cjs +2 -0
  59. package/dist/hook-bare.cjs.map +1 -0
  60. package/dist/hook-bare.js +9 -0
  61. package/dist/hook-bare.js.map +1 -0
  62. package/dist/hook.cjs +2 -0
  63. package/dist/hook.cjs.map +1 -0
  64. package/dist/hook.js +11 -0
  65. package/dist/hook.js.map +1 -0
  66. package/dist/hooks/useCombo.d.ts +3 -0
  67. package/dist/hooks/useCombo.d.ts.map +1 -0
  68. package/dist/hooks/usePosition.d.ts +16 -0
  69. package/dist/hooks/usePosition.d.ts.map +1 -0
  70. package/dist/icons/defaults.d.ts +16 -0
  71. package/dist/icons/defaults.d.ts.map +1 -0
  72. package/dist/icons/icons.d.ts +30 -0
  73. package/dist/icons/icons.d.ts.map +1 -0
  74. package/dist/icons-Ch1Q5AhF.js +40 -0
  75. package/dist/icons-Ch1Q5AhF.js.map +1 -0
  76. package/dist/icons-vzkEacAb.cjs +2 -0
  77. package/dist/icons-vzkEacAb.cjs.map +1 -0
  78. package/dist/icons.cjs +2 -0
  79. package/dist/icons.cjs.map +1 -0
  80. package/dist/icons.js +20 -0
  81. package/dist/icons.js.map +1 -0
  82. package/dist/index.cjs +2 -0
  83. package/dist/index.cjs.map +1 -0
  84. package/dist/index.d.ts +2 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +12 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/position.cjs +2 -0
  89. package/dist/position.cjs.map +1 -0
  90. package/dist/position.js +5 -0
  91. package/dist/position.js.map +1 -0
  92. package/dist/slots.cjs +2 -0
  93. package/dist/slots.cjs.map +1 -0
  94. package/dist/slots.js +92 -0
  95. package/dist/slots.js.map +1 -0
  96. package/dist/style.css +1 -0
  97. package/dist/styles/base.css +205 -0
  98. package/dist/styles/checkbox.css +36 -0
  99. package/dist/styles/chips.css +71 -0
  100. package/dist/styles/custom-item.css +64 -0
  101. package/dist/styles/footer.css +73 -0
  102. package/dist/styles/groups.css +23 -0
  103. package/dist/styles/meta.css +30 -0
  104. package/dist/styles/radio.css +36 -0
  105. package/dist/styles/select.css +35 -0
  106. package/dist/styles/states.css +22 -0
  107. package/dist/tabs.cjs +2 -0
  108. package/dist/tabs.cjs.map +1 -0
  109. package/dist/tabs.js +132 -0
  110. package/dist/tabs.js.map +1 -0
  111. package/dist/themes/dark.css +96 -0
  112. package/dist/themes/default.css +126 -0
  113. package/dist/themes/high-contrast.css +98 -0
  114. package/dist/types.d.ts +168 -0
  115. package/dist/types.d.ts.map +1 -0
  116. package/dist/useCombo-D_vriwVz.cjs +2 -0
  117. package/dist/useCombo-D_vriwVz.cjs.map +1 -0
  118. package/dist/useCombo-gPeBdkRf.js +887 -0
  119. package/dist/useCombo-gPeBdkRf.js.map +1 -0
  120. package/dist/usePosition-6GfutqGX.cjs +2 -0
  121. package/dist/usePosition-6GfutqGX.cjs.map +1 -0
  122. package/dist/usePosition-DVw8IlwA.js +36 -0
  123. package/dist/usePosition-DVw8IlwA.js.map +1 -0
  124. package/package.json +219 -0
@@ -0,0 +1,887 @@
1
+ import { useId as Ue, useRef as S, useReducer as Re, useEffect as w, useMemo as J, useCallback as m } from "react";
2
+ import { c as ke, d as xe } from "./icons-Ch1Q5AhF.js";
3
+ const f = (...e) => (...r) => {
4
+ e.forEach((t) => t?.(...r));
5
+ }, ee = (e) => e == null ? "" : typeof e == "string" ? e : typeof e == "object" && "label" in e ? String(e.label) : String(e), Fe = (e) => typeof e == "string" || typeof e == "number" ? e : typeof e == "object" && e != null && "value" in e ? e.value : String(e), Ae = (e, r, t) => {
6
+ if (!r) return e;
7
+ const l = r.toLowerCase();
8
+ return e.filter(
9
+ (o) => t(o).toLowerCase().includes(l)
10
+ );
11
+ }, Q = (e, r, t) => Math.min(Math.max(e, r), t);
12
+ function A(...e) {
13
+ return (r) => {
14
+ e.forEach((t) => {
15
+ typeof t == "function" ? t(r) : t != null && (t.current = r);
16
+ });
17
+ };
18
+ }
19
+ function _(e) {
20
+ return e === "OPEN_IDLE" || e === "OPEN_HIGHLIGHTED";
21
+ }
22
+ function U(e, r, t) {
23
+ const l = t.filterFunction ? t.filterFunction(e, r) : Ae(e, r, (o) => t.itemToString(o));
24
+ return t.hideDisabled ? l.filter((o) => !t.isItemDisabled(o)) : l;
25
+ }
26
+ function Z(e, r, t, l, o) {
27
+ const d = e.length;
28
+ if (d === 0) return -1;
29
+ if (o === "focus") {
30
+ let h = r + t;
31
+ return h >= d && (h = 0), h < 0 && (h = d - 1), h;
32
+ }
33
+ let I = r + t, T = 0;
34
+ for (; T < d; ) {
35
+ if (I >= d && (I = 0), I < 0 && (I = d - 1), !l(e[I])) return I;
36
+ I += t, T++;
37
+ }
38
+ return -1;
39
+ }
40
+ function $e(e, r, t) {
41
+ if (e.length === 0) return -1;
42
+ if (t === "focus") return 0;
43
+ for (let l = 0; l < e.length; l++)
44
+ if (!r(e[l])) return l;
45
+ return -1;
46
+ }
47
+ function Pe(e, r, t) {
48
+ if (e.length === 0) return -1;
49
+ if (t === "focus") return e.length - 1;
50
+ for (let l = e.length - 1; l >= 0; l--)
51
+ if (!r(e[l])) return l;
52
+ return -1;
53
+ }
54
+ function te(e) {
55
+ const r = e.itemToString ?? ee, t = e.selectedItem ?? e.defaultSelectedItem ?? null;
56
+ return {
57
+ status: "IDLE",
58
+ selectedItem: t,
59
+ selectedItems: e.selectedItems ?? e.defaultSelectedItems ?? [],
60
+ inputValue: e.inputValue ?? e.defaultInputValue ?? (t ? r(t) : ""),
61
+ lastConfirmedValue: t ? r(t) : "",
62
+ highlightedIndex: -1,
63
+ filteredItems: e.items,
64
+ expandedItems: /* @__PURE__ */ new Set(),
65
+ activeTabId: null,
66
+ isLoading: e.isLoading ?? !1,
67
+ isLoadingMore: !1,
68
+ error: null,
69
+ visibleChipCount: 0
70
+ };
71
+ }
72
+ function Be(e, r, t) {
73
+ switch (r.type) {
74
+ case "FOCUS":
75
+ return e.status !== "IDLE" ? e : {
76
+ ...e,
77
+ status: "FOCUSED_CLOSED",
78
+ lastConfirmedValue: e.inputValue
79
+ };
80
+ case "BLUR": {
81
+ if (e.status === "IDLE") return e;
82
+ if (t.mode === "multi")
83
+ return {
84
+ ...e,
85
+ status: "IDLE",
86
+ inputValue: "",
87
+ lastConfirmedValue: "",
88
+ highlightedIndex: -1,
89
+ filteredItems: t.items
90
+ };
91
+ if (t.commitOnBlur && _(e.status) && e.highlightedIndex >= 0 && e.highlightedIndex < e.filteredItems.length) {
92
+ const l = e.filteredItems[e.highlightedIndex];
93
+ if (!t.isItemDisabled(l)) {
94
+ const o = t.itemToString(l);
95
+ return {
96
+ ...e,
97
+ status: "IDLE",
98
+ selectedItem: l,
99
+ inputValue: o,
100
+ lastConfirmedValue: o,
101
+ highlightedIndex: -1
102
+ };
103
+ }
104
+ }
105
+ return {
106
+ ...e,
107
+ status: "IDLE",
108
+ inputValue: e.lastConfirmedValue,
109
+ highlightedIndex: -1
110
+ };
111
+ }
112
+ case "INPUT_CHANGE": {
113
+ if (t.variant === "select") return e;
114
+ const l = U(t.items, r.value, t);
115
+ return {
116
+ ...e,
117
+ status: "OPEN_IDLE",
118
+ inputValue: r.value,
119
+ filteredItems: l,
120
+ highlightedIndex: -1
121
+ };
122
+ }
123
+ case "TOGGLE_MENU": {
124
+ if (_(e.status))
125
+ return {
126
+ ...e,
127
+ status: "FOCUSED_CLOSED",
128
+ inputValue: t.mode === "multi" ? "" : e.lastConfirmedValue,
129
+ highlightedIndex: -1,
130
+ ...t.mode === "multi" ? { filteredItems: t.items } : {}
131
+ };
132
+ const l = t.mode === "multi" ? e.inputValue : "", o = U(t.items, l, t);
133
+ return {
134
+ ...e,
135
+ status: "OPEN_IDLE",
136
+ inputValue: l,
137
+ filteredItems: o,
138
+ highlightedIndex: -1
139
+ };
140
+ }
141
+ case "OPEN_MENU": {
142
+ if (_(e.status)) return e;
143
+ const l = t.mode === "multi" ? e.inputValue : "", o = U(t.items, l, t);
144
+ return {
145
+ ...e,
146
+ status: "OPEN_IDLE",
147
+ inputValue: l,
148
+ filteredItems: o,
149
+ highlightedIndex: -1
150
+ };
151
+ }
152
+ case "CLOSE_MENU":
153
+ return _(e.status) ? {
154
+ ...e,
155
+ status: "FOCUSED_CLOSED",
156
+ inputValue: t.mode === "multi" ? "" : e.lastConfirmedValue,
157
+ highlightedIndex: -1,
158
+ ...t.mode === "multi" ? { filteredItems: t.items } : {}
159
+ } : e;
160
+ case "HIGHLIGHT_ITEM": {
161
+ if (!_(e.status) && e.status !== "FOCUSED_CLOSED")
162
+ return e;
163
+ const l = r.index;
164
+ return l < 0 ? { ...e, status: "OPEN_IDLE", highlightedIndex: -1 } : l >= e.filteredItems.length || t.disabledItemBehavior === "skip" && t.isItemDisabled(e.filteredItems[l]) ? e : {
165
+ ...e,
166
+ status: "OPEN_HIGHLIGHTED",
167
+ highlightedIndex: l
168
+ };
169
+ }
170
+ case "HIGHLIGHT_FIRST": {
171
+ const l = $e(
172
+ e.filteredItems,
173
+ t.isItemDisabled,
174
+ t.disabledItemBehavior
175
+ );
176
+ return l < 0 ? { ...e, status: "OPEN_IDLE", highlightedIndex: -1 } : {
177
+ ...e,
178
+ status: "OPEN_HIGHLIGHTED",
179
+ highlightedIndex: l
180
+ };
181
+ }
182
+ case "HIGHLIGHT_LAST": {
183
+ const l = Pe(
184
+ e.filteredItems,
185
+ t.isItemDisabled,
186
+ t.disabledItemBehavior
187
+ );
188
+ return l < 0 ? { ...e, status: "OPEN_IDLE", highlightedIndex: -1 } : {
189
+ ...e,
190
+ status: "OPEN_HIGHLIGHTED",
191
+ highlightedIndex: l
192
+ };
193
+ }
194
+ case "HIGHLIGHT_NEXT": {
195
+ const l = e.highlightedIndex, o = Z(
196
+ e.filteredItems,
197
+ l,
198
+ 1,
199
+ t.isItemDisabled,
200
+ t.disabledItemBehavior
201
+ );
202
+ return o < 0 ? e : {
203
+ ...e,
204
+ status: "OPEN_HIGHLIGHTED",
205
+ highlightedIndex: o
206
+ };
207
+ }
208
+ case "HIGHLIGHT_PREV": {
209
+ const l = e.highlightedIndex, o = Z(
210
+ e.filteredItems,
211
+ l,
212
+ -1,
213
+ t.isItemDisabled,
214
+ t.disabledItemBehavior
215
+ );
216
+ return o < 0 ? e : {
217
+ ...e,
218
+ status: "OPEN_HIGHLIGHTED",
219
+ highlightedIndex: o
220
+ };
221
+ }
222
+ case "SELECT_HIGHLIGHTED": {
223
+ if (e.highlightedIndex < 0 || e.highlightedIndex >= e.filteredItems.length) return e;
224
+ const l = e.filteredItems[e.highlightedIndex];
225
+ if (t.isItemDisabled(l)) return e;
226
+ if (t.mode === "multi") {
227
+ const d = t.itemToValue(l), I = e.selectedItems.some(
228
+ (h) => t.itemToValue(h) === d
229
+ );
230
+ if (!I && t.maxSelected != null && e.selectedItems.length >= t.maxSelected)
231
+ return e;
232
+ const T = I ? e.selectedItems.filter((h) => t.itemToValue(h) !== d) : [...e.selectedItems, l];
233
+ return {
234
+ ...e,
235
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
236
+ selectedItems: T,
237
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
238
+ };
239
+ }
240
+ if (t.deselectionAllowed && e.selectedItem != null) {
241
+ const d = t.itemToValue(e.selectedItem), I = t.itemToValue(l);
242
+ if (d === I)
243
+ return {
244
+ ...e,
245
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
246
+ selectedItem: null,
247
+ inputValue: "",
248
+ lastConfirmedValue: "",
249
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
250
+ };
251
+ }
252
+ const o = t.itemToString(l);
253
+ return {
254
+ ...e,
255
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
256
+ selectedItem: l,
257
+ inputValue: o,
258
+ lastConfirmedValue: o,
259
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
260
+ };
261
+ }
262
+ case "SELECT_ITEM": {
263
+ const l = r.item;
264
+ if (t.isItemDisabled(l)) return e;
265
+ if (t.mode === "multi") {
266
+ const d = t.itemToValue(l), I = e.selectedItems.some(
267
+ (h) => t.itemToValue(h) === d
268
+ );
269
+ if (!I && t.maxSelected != null && e.selectedItems.length >= t.maxSelected)
270
+ return e;
271
+ const T = I ? e.selectedItems.filter((h) => t.itemToValue(h) !== d) : [...e.selectedItems, l];
272
+ return {
273
+ ...e,
274
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
275
+ selectedItems: T,
276
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
277
+ };
278
+ }
279
+ if (t.deselectionAllowed && e.selectedItem != null) {
280
+ const d = t.itemToValue(e.selectedItem), I = t.itemToValue(l);
281
+ if (d === I)
282
+ return {
283
+ ...e,
284
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
285
+ selectedItem: null,
286
+ inputValue: "",
287
+ lastConfirmedValue: "",
288
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
289
+ };
290
+ }
291
+ const o = t.itemToString(l);
292
+ return {
293
+ ...e,
294
+ status: t.closeOnSelect ? "FOCUSED_CLOSED" : e.status,
295
+ selectedItem: l,
296
+ inputValue: o,
297
+ lastConfirmedValue: o,
298
+ highlightedIndex: t.closeOnSelect ? -1 : e.highlightedIndex
299
+ };
300
+ }
301
+ case "DESELECT_ITEM": {
302
+ if (t.mode === "multi") {
303
+ const l = t.itemToValue(r.item);
304
+ return {
305
+ ...e,
306
+ selectedItems: e.selectedItems.filter(
307
+ (o) => t.itemToValue(o) !== l
308
+ )
309
+ };
310
+ }
311
+ return e.selectedItem == null ? e : {
312
+ ...e,
313
+ selectedItem: null,
314
+ inputValue: "",
315
+ lastConfirmedValue: ""
316
+ };
317
+ }
318
+ case "CLEAR_SELECTION":
319
+ return {
320
+ ...e,
321
+ selectedItem: null,
322
+ selectedItems: [],
323
+ inputValue: "",
324
+ lastConfirmedValue: "",
325
+ filteredItems: t.items
326
+ };
327
+ case "REMOVE_LAST_CHIP":
328
+ return t.mode !== "multi" || e.selectedItems.length === 0 || e.inputValue !== "" ? e : {
329
+ ...e,
330
+ selectedItems: e.selectedItems.slice(0, -1)
331
+ };
332
+ case "SELECT_ALL": {
333
+ if (t.mode !== "multi") return e;
334
+ let l = e.filteredItems.filter(
335
+ (o) => !t.isItemDisabled(o)
336
+ );
337
+ return t.maxSelected != null && (l = l.slice(0, t.maxSelected)), {
338
+ ...e,
339
+ selectedItems: l
340
+ };
341
+ }
342
+ case "SYNC_ITEMS": {
343
+ const l = U(t.items, e.inputValue, t);
344
+ return {
345
+ ...e,
346
+ filteredItems: l,
347
+ highlightedIndex: -1
348
+ };
349
+ }
350
+ case "RESET":
351
+ return te({
352
+ items: t.items,
353
+ itemToString: t.itemToString,
354
+ itemToValue: t.itemToValue
355
+ });
356
+ default:
357
+ return e;
358
+ }
359
+ }
360
+ function Ke(e, r, t) {
361
+ return (l) => {
362
+ const o = r.status === "OPEN_IDLE" || r.status === "OPEN_HIGHLIGHTED";
363
+ switch (l.key) {
364
+ case "ArrowDown": {
365
+ l.preventDefault(), o ? e({ type: "HIGHLIGHT_NEXT" }) : (e({ type: "OPEN_MENU" }), e({ type: "HIGHLIGHT_FIRST" }));
366
+ break;
367
+ }
368
+ case "ArrowUp": {
369
+ l.preventDefault(), o ? e({ type: "HIGHLIGHT_PREV" }) : (e({ type: "OPEN_MENU" }), e({ type: "HIGHLIGHT_LAST" }));
370
+ break;
371
+ }
372
+ case "Enter": {
373
+ o && r.highlightedIndex >= 0 && (l.preventDefault(), e({ type: "SELECT_HIGHLIGHTED" }));
374
+ break;
375
+ }
376
+ case "Escape": {
377
+ o && (l.preventDefault(), e({ type: "CLOSE_MENU" }));
378
+ break;
379
+ }
380
+ case "Home": {
381
+ o && (l.preventDefault(), e({ type: "HIGHLIGHT_FIRST" }));
382
+ break;
383
+ }
384
+ case "End": {
385
+ o && (l.preventDefault(), e({ type: "HIGHLIGHT_LAST" }));
386
+ break;
387
+ }
388
+ case "PageDown": {
389
+ if (o) {
390
+ l.preventDefault();
391
+ const d = r.filteredItems.length - 1;
392
+ e({
393
+ type: "HIGHLIGHT_ITEM",
394
+ index: Q(r.highlightedIndex + 10, 0, d)
395
+ });
396
+ }
397
+ break;
398
+ }
399
+ case "PageUp": {
400
+ o && (l.preventDefault(), e({
401
+ type: "HIGHLIGHT_ITEM",
402
+ index: Q(r.highlightedIndex - 10, 0, r.filteredItems.length - 1)
403
+ }));
404
+ break;
405
+ }
406
+ case "Tab": {
407
+ o && (t.commitOnBlur && r.highlightedIndex >= 0 && e({ type: "SELECT_HIGHLIGHTED" }), e({ type: "CLOSE_MENU" }));
408
+ break;
409
+ }
410
+ case "Backspace": {
411
+ r.inputValue === "" && e({ type: "REMOVE_LAST_CHIP" });
412
+ break;
413
+ }
414
+ case " ": {
415
+ t.variant === "select" && !o ? (l.preventDefault(), e({ type: "OPEN_MENU" }), e({ type: "HIGHLIGHT_FIRST" })) : t.variant === "select" && o && r.highlightedIndex >= 0 && (l.preventDefault(), e({ type: "SELECT_HIGHLIGHTED" }));
416
+ break;
417
+ }
418
+ case "a":
419
+ case "A": {
420
+ (l.ctrlKey || l.metaKey) && t.mode === "multi" && (l.preventDefault(), e({ type: "SELECT_ALL" }));
421
+ break;
422
+ }
423
+ }
424
+ };
425
+ }
426
+ const L = "rzero";
427
+ function ze(e) {
428
+ return {
429
+ base: e,
430
+ input: `${L}-input-${e}`,
431
+ label: `${L}-label-${e}`,
432
+ listbox: `${L}-listbox-${e}`,
433
+ toggleButton: `${L}-toggle-${e}`,
434
+ clearButton: `${L}-clear-${e}`,
435
+ liveRegion: `${L}-live-${e}`,
436
+ item: (r) => `${L}-item-${e}-${r}`,
437
+ group: (r) => `${L}-group-${e}-${r}`
438
+ };
439
+ }
440
+ function je(e) {
441
+ const r = Ue(), t = e ?? r, l = S(null);
442
+ return (!l.current || l.current.base !== t) && (l.current = ze(t)), l.current;
443
+ }
444
+ let b = null, $ = null;
445
+ function Xe() {
446
+ return typeof document > "u" ? null : (b && document.body.contains(b) || (b = document.createElement("div"), b.setAttribute("role", "status"), b.setAttribute("aria-live", "polite"), b.setAttribute("aria-atomic", "true"), b.setAttribute("data-rzero-live", ""), Object.assign(b.style, {
447
+ position: "absolute",
448
+ width: "1px",
449
+ height: "1px",
450
+ padding: "0",
451
+ margin: "-1px",
452
+ overflow: "hidden",
453
+ clip: "rect(0,0,0,0)",
454
+ whiteSpace: "nowrap",
455
+ borderWidth: "0"
456
+ }), document.body.appendChild(b)), b);
457
+ }
458
+ function y(e, r = 3e3) {
459
+ const t = Xe();
460
+ t && ($ && clearTimeout($), t.textContent = "", requestAnimationFrame(() => {
461
+ t.textContent = e;
462
+ }), $ = setTimeout(() => {
463
+ t.textContent = "";
464
+ }, r));
465
+ }
466
+ function qe(e, r) {
467
+ if (!e || r < 0) return;
468
+ const t = e.querySelector(
469
+ `[data-rzero-index="${r}"]`
470
+ );
471
+ t && typeof t.scrollIntoView == "function" && t.scrollIntoView({ block: "nearest" });
472
+ }
473
+ function Je(e) {
474
+ const {
475
+ items: r,
476
+ itemToString: t,
477
+ itemToValue: l,
478
+ mode: o = "single",
479
+ variant: d = "input",
480
+ filterFunction: I,
481
+ closeOnSelect: T = o === "single",
482
+ commitOnBlur: h = !1,
483
+ deselectionAllowed: le = !0,
484
+ disabled: c = !1,
485
+ readOnly: E = !1,
486
+ isItemDisabled: ne,
487
+ hideDisabled: ie = !1,
488
+ disabledItemBehavior: R = "skip",
489
+ ariaLabel: C,
490
+ ariaLabelledBy: D,
491
+ icons: V,
492
+ chevronStyle: P = "caret",
493
+ onSelectedItemChange: re,
494
+ onSelectedItemsChange: oe,
495
+ onIsOpenChange: de,
496
+ onHighlightedIndexChange: ue,
497
+ onStateChange: se,
498
+ onInputChange: ae
499
+ } = e, H = t ?? ee, O = l ?? Fe, k = ne ?? (() => !1), u = je(e.id), v = S(null), x = S(null), B = S(null), K = S(null);
500
+ K.current = {
501
+ items: r,
502
+ itemToString: H,
503
+ itemToValue: O,
504
+ filterFunction: I,
505
+ closeOnSelect: T,
506
+ commitOnBlur: h,
507
+ deselectionAllowed: le,
508
+ isItemDisabled: k,
509
+ disabledItemBehavior: R,
510
+ hideDisabled: ie,
511
+ variant: d,
512
+ mode: o,
513
+ maxSelected: e.maxSelected
514
+ };
515
+ const [i, s] = Re(
516
+ (n, a) => Be(n, a, K.current),
517
+ e,
518
+ te
519
+ ), z = S(r);
520
+ w(() => {
521
+ z.current !== r && (z.current = r, s({ type: "SYNC_ITEMS" }));
522
+ }, [r]);
523
+ const g = i.status === "OPEN_IDLE" || i.status === "OPEN_HIGHLIGHTED", Ie = o === "multi" ? i.selectedItems.length > 0 : i.selectedItem != null, ce = o === "multi" ? i.selectedItems.map(H).join(", ") : i.selectedItem != null ? H(i.selectedItem) : "", me = J(
524
+ () => ke(V),
525
+ // eslint-disable-next-line react-hooks/exhaustive-deps
526
+ [V]
527
+ ), he = J(
528
+ () => xe(P, V?.chevronDown),
529
+ [P, V?.chevronDown]
530
+ ), j = S(i);
531
+ j.current = i;
532
+ const G = m(
533
+ (n) => {
534
+ if (c || E) return;
535
+ Ke(s, j.current, {
536
+ variant: d,
537
+ commitOnBlur: h,
538
+ mode: o
539
+ })(n);
540
+ },
541
+ [c, E, d, h, o]
542
+ );
543
+ w(() => {
544
+ i.highlightedIndex >= 0 && qe(x.current, i.highlightedIndex);
545
+ }, [i.highlightedIndex]);
546
+ const X = S(!1), q = S(0);
547
+ w(() => {
548
+ const n = X.current, a = q.current;
549
+ if (X.current = g, q.current = i.filteredItems.length, g && (!n || a !== i.filteredItems.length)) {
550
+ const p = i.filteredItems.length;
551
+ y(
552
+ p === 0 ? "No options available" : `${p} option${p !== 1 ? "s" : ""} available`
553
+ );
554
+ }
555
+ }, [g, i.filteredItems.length]);
556
+ const Y = S(i);
557
+ w(() => {
558
+ const n = Y.current;
559
+ if (Y.current = i, n.selectedItem !== i.selectedItem && (re?.(i.selectedItem), i.selectedItem ? y(`${H(i.selectedItem)} selected`) : n.selectedItem && y(`${H(n.selectedItem)} deselected`)), n.selectedItems !== i.selectedItems)
560
+ if (oe?.(i.selectedItems), i.selectedItems.length > n.selectedItems.length) {
561
+ const p = i.selectedItems[i.selectedItems.length - 1];
562
+ p && y(`${H(p)} selected, ${i.selectedItems.length} total`);
563
+ } else i.selectedItems.length < n.selectedItems.length && y(`Item removed, ${i.selectedItems.length} selected`);
564
+ (n.status === "OPEN_IDLE" || n.status === "OPEN_HIGHLIGHTED") !== g && de?.(g), n.highlightedIndex !== i.highlightedIndex && ue?.(i.highlightedIndex), n.inputValue !== i.inputValue && ae?.(i.inputValue), se?.(i);
565
+ }, [i]);
566
+ const fe = m(
567
+ (n = {}) => ({
568
+ id: u.label,
569
+ htmlFor: u.input,
570
+ ...n
571
+ }),
572
+ [u]
573
+ ), ge = m(
574
+ (n = {}) => ({
575
+ id: u.input,
576
+ role: "combobox",
577
+ "aria-expanded": g,
578
+ "aria-haspopup": "listbox",
579
+ "aria-controls": u.listbox,
580
+ "aria-autocomplete": d === "select" ? "none" : "list",
581
+ "aria-activedescendant": i.highlightedIndex >= 0 ? u.item(i.highlightedIndex) : void 0,
582
+ "aria-labelledby": D ?? u.label,
583
+ "aria-label": C,
584
+ "aria-disabled": c ? !0 : void 0,
585
+ readOnly: E || d === "select",
586
+ disabled: c === !0,
587
+ autoComplete: "off",
588
+ value: i.inputValue,
589
+ ...n,
590
+ onChange: f(
591
+ n.onChange,
592
+ (a) => {
593
+ c || E || s({ type: "INPUT_CHANGE", value: a.target.value });
594
+ }
595
+ ),
596
+ onKeyDown: f(
597
+ n.onKeyDown,
598
+ G
599
+ ),
600
+ onFocus: f(
601
+ n.onFocus,
602
+ () => {
603
+ c || s({ type: "FOCUS" });
604
+ }
605
+ ),
606
+ onBlur: f(
607
+ n.onBlur,
608
+ () => {
609
+ s({ type: "BLUR" });
610
+ }
611
+ ),
612
+ onClick: f(
613
+ n.onClick,
614
+ () => {
615
+ c || E || g || s({ type: "OPEN_MENU" });
616
+ }
617
+ ),
618
+ ref: A(
619
+ v,
620
+ n.ref
621
+ )
622
+ }),
623
+ [
624
+ u,
625
+ g,
626
+ i.highlightedIndex,
627
+ i.inputValue,
628
+ C,
629
+ D,
630
+ c,
631
+ E,
632
+ d,
633
+ G
634
+ ]
635
+ ), Ee = m(
636
+ (n = {}) => ({
637
+ id: u.toggleButton,
638
+ type: "button",
639
+ "aria-label": g ? "Close options" : "Open options",
640
+ "aria-expanded": g,
641
+ "aria-haspopup": "listbox",
642
+ "aria-controls": u.listbox,
643
+ tabIndex: -1,
644
+ "aria-disabled": c ? !0 : void 0,
645
+ ...n,
646
+ onMouseDown: f(
647
+ n.onMouseDown,
648
+ (a) => a.preventDefault()
649
+ // prevent input blur
650
+ ),
651
+ onClick: f(
652
+ n.onClick,
653
+ () => {
654
+ c || E || (s({ type: "TOGGLE_MENU" }), v.current?.focus());
655
+ }
656
+ )
657
+ }),
658
+ [u, g, c, E]
659
+ ), pe = m(
660
+ (n = {}) => ({
661
+ id: u.clearButton,
662
+ type: "button",
663
+ "aria-label": "Clear selection",
664
+ tabIndex: -1,
665
+ ...n,
666
+ onMouseDown: f(
667
+ n.onMouseDown,
668
+ (a) => a.preventDefault()
669
+ // prevent input blur
670
+ ),
671
+ onClick: f(
672
+ n.onClick,
673
+ () => {
674
+ c || E || (s({ type: "CLEAR_SELECTION" }), v.current?.focus());
675
+ }
676
+ )
677
+ }),
678
+ [u, c, E]
679
+ ), be = m(
680
+ (n = {}) => ({
681
+ id: u.listbox,
682
+ role: "listbox",
683
+ "aria-labelledby": D ?? u.label,
684
+ "aria-label": C,
685
+ "aria-multiselectable": o === "multi" ? !0 : void 0,
686
+ ...n,
687
+ onMouseDown: f(
688
+ n.onMouseDown,
689
+ (a) => a.preventDefault()
690
+ // prevent input blur
691
+ ),
692
+ ref: A(
693
+ x,
694
+ n.ref
695
+ )
696
+ }),
697
+ [u, C, D, o]
698
+ ), Se = m(
699
+ ({
700
+ item: n,
701
+ index: a,
702
+ variant: p,
703
+ ...N
704
+ }) => {
705
+ const F = o === "multi" ? i.selectedItems.some((we) => O(we) === O(n)) : i.selectedItem != null && O(i.selectedItem) === O(n), Ne = i.highlightedIndex === a, M = k(n), Me = p === "checkbox" || p === "radio";
706
+ return {
707
+ id: u.item(a),
708
+ role: "option",
709
+ "aria-selected": F,
710
+ "aria-checked": Me ? F : void 0,
711
+ "aria-disabled": M || void 0,
712
+ "data-rzero-index": a,
713
+ "data-highlighted": Ne || void 0,
714
+ "data-selected": F || void 0,
715
+ "data-disabled": M || void 0,
716
+ "data-variant": p || void 0,
717
+ ...N,
718
+ onClick: f(
719
+ N?.onClick,
720
+ () => {
721
+ M || s({ type: "SELECT_ITEM", item: n });
722
+ }
723
+ ),
724
+ onMouseEnter: f(
725
+ N?.onMouseEnter,
726
+ () => {
727
+ M && R === "skip" || s({ type: "HIGHLIGHT_ITEM", index: a });
728
+ }
729
+ ),
730
+ onMouseLeave: f(
731
+ N?.onMouseLeave,
732
+ () => {
733
+ s({ type: "HIGHLIGHT_ITEM", index: -1 });
734
+ }
735
+ )
736
+ };
737
+ },
738
+ [
739
+ i.selectedItem,
740
+ i.selectedItems,
741
+ i.highlightedIndex,
742
+ u,
743
+ O,
744
+ k,
745
+ R,
746
+ o
747
+ ]
748
+ ), Te = m(
749
+ ({
750
+ group: n,
751
+ index: a,
752
+ ...p
753
+ }) => ({
754
+ role: "group",
755
+ "aria-label": n.label,
756
+ id: u.group(a),
757
+ "data-disabled": n.disabled || void 0,
758
+ ...p
759
+ }),
760
+ [u]
761
+ ), Le = m(
762
+ (n = {}) => ({
763
+ "data-rzero-chevron": "",
764
+ "aria-hidden": !0,
765
+ ...n
766
+ }),
767
+ []
768
+ ), W = m(
769
+ (n = {}) => ({
770
+ role: "combobox",
771
+ "aria-expanded": g,
772
+ "aria-haspopup": "listbox",
773
+ "aria-controls": u.listbox,
774
+ "aria-activedescendant": i.highlightedIndex >= 0 ? u.item(i.highlightedIndex) : void 0,
775
+ "aria-label": C,
776
+ "aria-labelledby": D,
777
+ "aria-disabled": c ? !0 : void 0,
778
+ "data-rzero-trigger": "",
779
+ "data-disabled": c || void 0,
780
+ "data-readonly": E || void 0,
781
+ "data-loading": c === "loading" || void 0,
782
+ tabIndex: 0,
783
+ ...n,
784
+ onKeyDown: f(
785
+ n.onKeyDown,
786
+ G
787
+ ),
788
+ onClick: f(
789
+ n.onClick,
790
+ () => {
791
+ c || E || s({ type: "TOGGLE_MENU" });
792
+ }
793
+ ),
794
+ onFocus: f(
795
+ n.onFocus,
796
+ () => {
797
+ c || s({ type: "FOCUS" });
798
+ }
799
+ ),
800
+ onBlur: f(
801
+ n.onBlur,
802
+ () => {
803
+ s({ type: "BLUR" });
804
+ }
805
+ ),
806
+ ref: A(
807
+ B,
808
+ n.ref
809
+ )
810
+ }),
811
+ [
812
+ u,
813
+ g,
814
+ i.highlightedIndex,
815
+ C,
816
+ D,
817
+ c,
818
+ E,
819
+ G
820
+ ]
821
+ ), Ce = m(() => s({ type: "OPEN_MENU" }), []), De = m(() => s({ type: "CLOSE_MENU" }), []), He = m(
822
+ () => s({ type: "TOGGLE_MENU" }),
823
+ []
824
+ ), Oe = m(
825
+ (n) => s({ type: "SELECT_ITEM", item: n }),
826
+ []
827
+ ), _e = m(
828
+ (n) => s({ type: "DESELECT_ITEM", item: n }),
829
+ []
830
+ ), ye = m(
831
+ () => s({ type: "SELECT_ALL" }),
832
+ []
833
+ ), Ve = m(
834
+ () => s({ type: "CLEAR_SELECTION" }),
835
+ []
836
+ ), ve = m(
837
+ (n) => s({ type: "INPUT_CHANGE", value: n }),
838
+ []
839
+ ), Ge = m(() => s({ type: "RESET" }), []);
840
+ return {
841
+ // Prop getters
842
+ getInputProps: ge,
843
+ getToggleButtonProps: Ee,
844
+ getLabelProps: fe,
845
+ getClearButtonProps: pe,
846
+ getMenuProps: be,
847
+ getItemProps: Se,
848
+ getGroupProps: Te,
849
+ getChevronProps: Le,
850
+ getTriggerProps: W,
851
+ getControlProps: W,
852
+ // State
853
+ isOpen: g,
854
+ inputValue: i.inputValue,
855
+ selectedItem: i.selectedItem,
856
+ selectedItems: i.selectedItems,
857
+ highlightedIndex: i.highlightedIndex,
858
+ filteredItems: i.filteredItems,
859
+ hasSelection: Ie,
860
+ triggerLabel: ce,
861
+ isLoading: i.isLoading,
862
+ isEmpty: g && i.filteredItems.length === 0,
863
+ isError: i.error != null,
864
+ error: i.error,
865
+ // Icons
866
+ icons: me,
867
+ chevronIcon: he,
868
+ // Actions
869
+ openMenu: Ce,
870
+ closeMenu: De,
871
+ toggleMenu: He,
872
+ selectItem: Oe,
873
+ removeItem: _e,
874
+ selectAll: ye,
875
+ clearSelection: Ve,
876
+ setInputValue: ve,
877
+ reset: Ge,
878
+ // Refs
879
+ inputRef: v,
880
+ listboxRef: x,
881
+ triggerRef: B
882
+ };
883
+ }
884
+ export {
885
+ Je as u
886
+ };
887
+ //# sourceMappingURL=useCombo-gPeBdkRf.js.map