@ark-ui/solid 5.6.0 → 5.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 (176) hide show
  1. package/dist/chunk/{YGOJI6HV.js → 6VPRFZA4.js} +2 -2
  2. package/dist/chunk/{Y3WE2S3D.jsx → 7LQ4EWHB.jsx} +4 -4
  3. package/dist/chunk/{SSZEXBY3.js → BBUDIIYT.js} +79 -45
  4. package/dist/chunk/{VDDVCRFC.jsx → BXAUWHBZ.jsx} +6 -4
  5. package/dist/chunk/{N4O7ZKCJ.jsx → BZLIWOGC.jsx} +4 -4
  6. package/dist/chunk/{EEG3DZXG.jsx → CRWRK56B.jsx} +4 -3
  7. package/dist/chunk/ETB2BIQZ.jsx +30 -0
  8. package/dist/chunk/{U67NSVQP.js → FPYZVUFW.js} +2 -2
  9. package/dist/chunk/{ABSJMCRQ.js → HUQXLQRU.js} +2 -2
  10. package/dist/chunk/{G2DDCQSJ.jsx → MJEKBIW2.jsx} +83 -50
  11. package/dist/chunk/N3VQSC2A.js +1057 -0
  12. package/dist/chunk/{4UD3WT4B.js → PHBHYNUH.js} +2 -2
  13. package/dist/chunk/PKUUD527.js +25 -0
  14. package/dist/chunk/{OF3ALDDY.js → QCEB2LAT.js} +4 -2
  15. package/dist/chunk/RU4LLCFH.jsx +1128 -0
  16. package/dist/chunk/{MM2I4S7S.jsx → SPPHU23S.jsx} +4 -4
  17. package/dist/components/accordion/index.js +1 -1
  18. package/dist/components/accordion/index.jsx +3 -3
  19. package/dist/components/angle-slider/index.js +1 -1
  20. package/dist/components/angle-slider/index.jsx +2 -2
  21. package/dist/components/avatar/index.js +1 -1
  22. package/dist/components/avatar/index.jsx +2 -2
  23. package/dist/components/carousel/index.js +1 -1
  24. package/dist/components/carousel/index.jsx +2 -2
  25. package/dist/components/checkbox/index.js +1 -1
  26. package/dist/components/checkbox/index.jsx +2 -2
  27. package/dist/components/clipboard/index.jsx +1 -1
  28. package/dist/components/collapsible/index.js +1 -1
  29. package/dist/components/collapsible/index.jsx +2 -2
  30. package/dist/components/collection.d.ts +1 -1
  31. package/dist/components/color-picker/index.js +1 -1
  32. package/dist/components/color-picker/index.jsx +3 -3
  33. package/dist/components/combobox/index.js +1 -1
  34. package/dist/components/combobox/index.jsx +3 -3
  35. package/dist/components/date-picker/index.js +1 -1
  36. package/dist/components/date-picker/index.jsx +2 -2
  37. package/dist/components/dialog/index.js +1 -1
  38. package/dist/components/dialog/index.jsx +2 -2
  39. package/dist/components/download-trigger/index.jsx +1 -1
  40. package/dist/components/editable/index.js +1 -1
  41. package/dist/components/editable/index.jsx +2 -2
  42. package/dist/components/file-upload/index.js +1 -1
  43. package/dist/components/file-upload/index.jsx +2 -2
  44. package/dist/components/floating-panel/index.js +1 -1
  45. package/dist/components/floating-panel/index.jsx +3 -2
  46. package/dist/components/format/index.jsx +1 -1
  47. package/dist/components/frame/index.jsx +1 -1
  48. package/dist/components/hover-card/index.js +1 -1
  49. package/dist/components/hover-card/index.jsx +2 -2
  50. package/dist/components/index.d.ts +3 -1
  51. package/dist/components/index.js +42 -41
  52. package/dist/components/index.jsx +405 -370
  53. package/dist/components/listbox/index.d.ts +113 -0
  54. package/dist/components/listbox/index.js +2 -0
  55. package/dist/components/listbox/index.jsx +49 -0
  56. package/dist/components/menu/index.js +1 -1
  57. package/dist/components/menu/index.jsx +2 -2
  58. package/dist/components/number-input/index.js +1 -1
  59. package/dist/components/number-input/index.jsx +2 -2
  60. package/dist/components/pagination/index.js +1 -1
  61. package/dist/components/pagination/index.jsx +2 -2
  62. package/dist/components/pin-input/index.js +1 -1
  63. package/dist/components/pin-input/index.jsx +2 -2
  64. package/dist/components/popover/index.js +1 -1
  65. package/dist/components/popover/index.jsx +2 -2
  66. package/dist/components/progress/index.js +1 -1
  67. package/dist/components/progress/index.jsx +2 -2
  68. package/dist/components/qr-code/index.js +1 -1
  69. package/dist/components/qr-code/index.jsx +2 -2
  70. package/dist/components/radio-group/index.js +1 -1
  71. package/dist/components/radio-group/index.jsx +2 -2
  72. package/dist/components/rating-group/index.js +1 -1
  73. package/dist/components/rating-group/index.jsx +2 -2
  74. package/dist/components/segment-group/index.js +1 -1
  75. package/dist/components/segment-group/index.jsx +2 -2
  76. package/dist/components/select/index.js +1 -1
  77. package/dist/components/select/index.jsx +3 -3
  78. package/dist/components/signature-pad/index.js +1 -1
  79. package/dist/components/signature-pad/index.jsx +2 -2
  80. package/dist/components/slider/index.js +1 -1
  81. package/dist/components/slider/index.jsx +2 -2
  82. package/dist/components/splitter/index.js +1 -1
  83. package/dist/components/splitter/index.jsx +2 -2
  84. package/dist/components/steps/index.js +1 -1
  85. package/dist/components/steps/index.jsx +2 -2
  86. package/dist/components/switch/index.js +1 -1
  87. package/dist/components/switch/index.jsx +2 -2
  88. package/dist/components/tabs/index.js +1 -1
  89. package/dist/components/tabs/index.jsx +2 -2
  90. package/dist/components/tags-input/index.js +1 -1
  91. package/dist/components/tags-input/index.jsx +2 -2
  92. package/dist/components/time-picker/index.js +1 -1
  93. package/dist/components/time-picker/index.jsx +2 -2
  94. package/dist/components/timer/index.jsx +1 -1
  95. package/dist/components/toast/index.js +1 -1
  96. package/dist/components/toast/index.jsx +2 -2
  97. package/dist/components/toggle-group/index.js +1 -1
  98. package/dist/components/toggle-group/index.jsx +2 -2
  99. package/dist/components/tooltip/index.js +1 -1
  100. package/dist/components/tooltip/index.jsx +2 -2
  101. package/dist/components/tour/index.js +1 -1
  102. package/dist/components/tour/index.jsx +2 -2
  103. package/dist/components/tree-view/index.js +1 -1
  104. package/dist/components/tree-view/index.jsx +3 -3
  105. package/dist/index.d.ts +3 -1
  106. package/dist/index.js +43 -42
  107. package/dist/index.jsx +402 -367
  108. package/dist/providers/index.js +1 -1
  109. package/dist/providers/index.jsx +4 -4
  110. package/package.json +63 -62
  111. package/dist/chunk/{Z254KIAA.jsx → 2ZIPSG6O.jsx} +3 -3
  112. package/dist/chunk/{MA35L6TV.jsx → 3GZBI3C7.jsx} +3 -3
  113. package/dist/chunk/{AD2EIGNX.jsx → 3RSBQIQ3.jsx} +3 -3
  114. package/dist/chunk/{ROXCI3ZP.js → 4ALLEGBR.js} +1 -1
  115. package/dist/chunk/{KOWWX76D.js → 4FHVXCRW.js} +2 -2
  116. package/dist/chunk/{CGUVAYKV.js → 5FWNSCWP.js} +1 -1
  117. package/dist/chunk/{E7EIHMW2.js → 5I3KMKOJ.js} +0 -0
  118. package/dist/chunk/{DPTBH7NV.js → 5JGPNGFH.js} +1 -1
  119. package/dist/chunk/{C5HFE3OV.js → 5X7KNFCM.js} +1 -1
  120. package/dist/chunk/{O6XGGFFV.jsx → 64OEA2DF.jsx} +3 -3
  121. package/dist/chunk/{2HLGNCOQ.js → 6NYYJAMS.js} +1 -1
  122. package/dist/chunk/{JWXGONCE.js → ACHQ3WMT.js} +1 -1
  123. package/dist/chunk/{7LCINU3A.jsx → ASFHFF7Y.jsx} +3 -3
  124. package/dist/chunk/{QBFJVUX3.js → ATMLAY2Z.js} +1 -1
  125. package/dist/chunk/{74VQO5NB.js → BOAJIMOM.js} +2 -2
  126. package/dist/chunk/{MSINFF7E.jsx → BWOFNO5N.jsx} +3 -3
  127. package/dist/chunk/{TM5I6GID.jsx → CLX4TELO.jsx} +3 -3
  128. package/dist/chunk/{QN2KHWAW.jsx → CMXNP72H.jsx} +3 -3
  129. package/dist/chunk/{YPH7FBUN.jsx → D4UVDNW5.jsx} +3 -3
  130. package/dist/chunk/{46YZVE6D.js → DBIUMOLI.js} +1 -1
  131. package/dist/chunk/{IKA3JJFV.jsx → ENH3JQLY.jsx} +3 -3
  132. package/dist/chunk/{AMEMCPNB.jsx → EX2VGSCG.jsx} +3 -3
  133. package/dist/chunk/{CHLRHJV2.jsx → FHEJON2W.jsx} +3 -3
  134. package/dist/chunk/{AYESR2LP.jsx → FUGFSIYK.jsx} +3 -3
  135. package/dist/chunk/{DUMB6XV5.js → FVIF7LDE.js} +1 -1
  136. package/dist/chunk/{ROFVSOHA.jsx → HNF2QPQ2.jsx} +3 -3
  137. package/dist/chunk/{24OEHSBA.js → HQJBHHB6.js} +1 -1
  138. package/dist/chunk/{4VSNWWYK.js → HS2AKVM3.js} +2 -2
  139. package/dist/chunk/{XH6HBC54.jsx → IEGQ2BAU.jsx} +0 -0
  140. package/dist/chunk/{CRYRP5LM.jsx → IK5AQC3K.jsx} +6 -6
  141. package/dist/chunk/{SUOC3NNA.js → IMKHRMUF.js} +1 -1
  142. package/dist/chunk/{RY6GW37O.jsx → ISCBIWKW.jsx} +3 -3
  143. package/dist/chunk/{TKGOCHK5.js → JCVIA4KI.js} +1 -1
  144. package/dist/chunk/{Z2TDX72A.js → K2GRJC27.js} +1 -1
  145. package/dist/chunk/{F4L2MTJA.jsx → KRJNIKO2.jsx} +3 -3
  146. package/dist/chunk/{ZDKSAOA5.jsx → KWT5RGLQ.jsx} +3 -3
  147. package/dist/chunk/{JTNTC6FF.jsx → L3SIBBML.jsx} +3 -3
  148. package/dist/chunk/{ZOGAU3AQ.js → L7KH34DE.js} +1 -1
  149. package/dist/chunk/{DJIEVIL4.jsx → LI7J6F7D.jsx} +3 -3
  150. package/dist/chunk/{K5AG7O7B.jsx → LKX2UAMN.jsx} +3 -3
  151. package/dist/chunk/{2WVEDTEK.js → LPWKZJG2.js} +1 -1
  152. package/dist/chunk/{XZZ6TULR.jsx → MD7PHDJK.jsx} +3 -3
  153. package/dist/chunk/{E2CL7JEV.js → MPNDTPUK.js} +1 -1
  154. package/dist/chunk/{JN5MJP56.jsx → MTVAX7XO.jsx} +3 -3
  155. package/dist/chunk/{BVKIR2P4.js → MXJSLVKN.js} +1 -1
  156. package/dist/chunk/{WR7AKRSO.jsx → N26ZXGSY.jsx} +3 -3
  157. package/dist/chunk/{BT2NIRPC.js → OBLSSYMA.js} +1 -1
  158. package/dist/chunk/{DW4NU34Z.js → OE7Y5R5I.js} +1 -1
  159. package/dist/chunk/{GNQB7IOU.js → OMTG2F6B.js} +1 -1
  160. package/dist/chunk/{WXJYBPWI.js → PDYWOA6Y.js} +1 -1
  161. package/dist/chunk/{N3FF6O2Y.js → POK6DGO4.js} +1 -1
  162. package/dist/chunk/{WW35AWP2.js → QRODT7WM.js} +1 -1
  163. package/dist/chunk/{YIVTZ7BP.jsx → QXPKPCGG.jsx} +3 -3
  164. package/dist/chunk/{4QD4ZSJK.jsx → ROA4DJEO.jsx} +3 -3
  165. package/dist/chunk/{IXXDQXSI.js → RXOSUP6U.js} +1 -1
  166. package/dist/chunk/{T3IKIVSG.jsx → TKQSSFZN.jsx} +3 -3
  167. package/dist/chunk/{7TPJ7KWF.jsx → UH2ERZB4.jsx} +6 -6
  168. package/dist/chunk/{Z3MPOJ5X.js → UIEL6LO3.js} +1 -1
  169. package/dist/chunk/{DXWAFMGQ.jsx → VWUOL2OR.jsx} +3 -3
  170. package/dist/chunk/{KLURGV6W.jsx → WKJMOIA7.jsx} +3 -3
  171. package/dist/chunk/{C4PG7WMU.js → XME7TKM2.js} +1 -1
  172. package/dist/chunk/{UGS5HMDP.jsx → XOHR2G2L.jsx} +6 -6
  173. package/dist/chunk/{S42D66WQ.js → YECHEPH3.js} +1 -1
  174. package/dist/chunk/{2H2BP2D4.jsx → YIOS67AB.jsx} +3 -3
  175. package/dist/chunk/{MSLAT5GQ.js → YIY75WWN.js} +1 -1
  176. package/dist/chunk/{WOSTAOH5.js → ZKM4DTGM.js} +1 -1
@@ -0,0 +1,1057 @@
1
+ import { createMachine } from './PKUUD527.js';
2
+ import { createSplitProps as createSplitProps$1 } from './ZMHI4GDJ.js';
3
+ import { ark } from './EPLBB4QN.js';
4
+ import { useLocaleContext } from './QEMQBM6W.js';
5
+ import { useEnvironmentContext } from './YMMMHJJS.js';
6
+ import { createContext } from './TROPIN4C.js';
7
+ import { runIfFn } from './DT73WLR4.js';
8
+ import { __export } from './ESLJRKWD.js';
9
+ import { createComponent, mergeProps as mergeProps$1 } from 'solid-js/web';
10
+ import { mergeProps, useMachine, normalizeProps } from '@zag-js/solid';
11
+ import { children, createUniqueId, createMemo } from 'solid-js';
12
+ import { createAnatomy } from '@zag-js/anatomy';
13
+ import { Selection, ListCollection, isGridCollection } from '@zag-js/collection';
14
+ import { raf, observeAttributes, getByTypeahead, getWindow, getDocument, isVirtualClick, getEventTarget, scrollIntoView, dataAttr, isSelfTarget, getEventKey, isEditableElement, ariaAttr, isCtrlOrMetaKey, isComposingEvent, getNativeEvent, isMac } from '@zag-js/dom-query';
15
+ import { isEqual, createSplitProps, ensure } from '@zag-js/utils';
16
+ import { createProps } from '@zag-js/types';
17
+
18
+ // src/components/listbox/use-listbox-context.ts
19
+ var [ListboxProvider, useListboxContext] = createContext({
20
+ hookName: "useListboxContext",
21
+ providerName: "<ListboxProvider />"
22
+ });
23
+
24
+ // src/components/listbox/listbox-content.tsx
25
+ var ListboxContent = (props2) => {
26
+ const listbox = useListboxContext();
27
+ const mergedProps = mergeProps(() => listbox().getContentProps(), props2);
28
+ return createComponent(ark.div, mergedProps);
29
+ };
30
+ var ListboxInput = (props2) => {
31
+ const [inputProps, localProps] = createSplitProps$1()(props2, ["autoHighlight"]);
32
+ const listbox = useListboxContext();
33
+ const mergedProps = mergeProps(() => listbox().getInputProps(inputProps), localProps);
34
+ return createComponent(ark.input, mergedProps);
35
+ };
36
+
37
+ // src/components/listbox/use-listbox-item-context.ts
38
+ var [ListboxItemProvider, useListboxItemContext] = createContext({
39
+ hookName: "useListboxItemContext",
40
+ providerName: "<ListboxItemProvider />"
41
+ });
42
+
43
+ // src/components/listbox/use-listbox-item-props-context.ts
44
+ var [ListboxItemPropsProvider, useListboxItemPropsContext] = createContext({
45
+ hookName: "useListboxItemPropsContext",
46
+ providerName: "<ListboxItemPropsProvider />"
47
+ });
48
+
49
+ // src/components/listbox/listbox-item.tsx
50
+ var ListboxItem = (props2) => {
51
+ const [itemProps2, localProps] = createSplitProps$1()(props2, ["item", "highlightOnHover"]);
52
+ const listbox = useListboxContext();
53
+ const mergedProps = mergeProps(() => listbox().getItemProps(itemProps2), localProps);
54
+ const itemState = () => listbox().getItemState(itemProps2);
55
+ return createComponent(ListboxItemPropsProvider, {
56
+ value: itemProps2,
57
+ get children() {
58
+ return createComponent(ListboxItemProvider, {
59
+ get value() {
60
+ return itemState();
61
+ },
62
+ get children() {
63
+ return createComponent(ark.div, mergedProps);
64
+ }
65
+ });
66
+ }
67
+ });
68
+ };
69
+
70
+ // src/components/listbox/use-listbox-item-group-props-context.ts
71
+ var [ListboxItemGroupPropsProvider, useListboxItemGroupPropsContext] = createContext({
72
+ hookName: "useListboxItemGroupPropsContext",
73
+ providerName: "<ListboxItemGroupPropsProvider />"
74
+ });
75
+
76
+ // src/components/listbox/listbox-item-group.tsx
77
+ var ListboxItemGroup = (props2) => {
78
+ const id = createUniqueId();
79
+ const [_itemGroupProps, localProps] = createSplitProps$1()(props2, ["id"]);
80
+ const itemGroupProps2 = {
81
+ id,
82
+ ..._itemGroupProps
83
+ };
84
+ const listbox = useListboxContext();
85
+ const mergedProps = mergeProps(() => listbox().getItemGroupProps(itemGroupProps2), localProps);
86
+ return createComponent(ListboxItemGroupPropsProvider, {
87
+ value: itemGroupProps2,
88
+ get children() {
89
+ return createComponent(ark.div, mergedProps);
90
+ }
91
+ });
92
+ };
93
+ var ListboxItemGroupLabel = (props2) => {
94
+ const listbox = useListboxContext();
95
+ const itemGroupProps2 = useListboxItemGroupPropsContext();
96
+ const mergedProps = mergeProps(() => listbox().getItemGroupLabelProps({
97
+ htmlFor: itemGroupProps2.id
98
+ }), props2);
99
+ return createComponent(ark.div, mergedProps);
100
+ };
101
+ var ListboxItemIndicator = (props2) => {
102
+ const listbox = useListboxContext();
103
+ const itemProps2 = useListboxItemPropsContext();
104
+ const mergedProps = mergeProps(() => listbox().getItemIndicatorProps(itemProps2), props2);
105
+ return createComponent(ark.div, mergedProps);
106
+ };
107
+ var ListboxItemText = (props2) => {
108
+ const listbox = useListboxContext();
109
+ const itemProps2 = useListboxItemPropsContext();
110
+ const mergedProps = mergeProps(() => listbox().getItemTextProps(itemProps2), props2);
111
+ return createComponent(ark.div, mergedProps);
112
+ };
113
+ var ListboxLabel = (props2) => {
114
+ const listbox = useListboxContext();
115
+ const mergedProps = mergeProps(() => listbox().getLabelProps(), props2);
116
+ return createComponent(ark.label, mergedProps);
117
+ };
118
+ function isValidKey(e) {
119
+ return !(e.metaKey || !isMac() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
120
+ }
121
+ var nonTextInputTypes = /* @__PURE__ */ new Set(["checkbox", "radio", "range", "color", "file", "image", "button", "submit", "reset"]);
122
+ function isKeyboardFocusEvent(isTextInput, modality, e) {
123
+ const target = e ? getEventTarget(e) : null;
124
+ const win = getWindow(target);
125
+ isTextInput = isTextInput || target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target?.type) || target instanceof win.HTMLTextAreaElement || target instanceof win.HTMLElement && target.isContentEditable;
126
+ return !(isTextInput && modality === "keyboard" && e instanceof win.KeyboardEvent && !Reflect.has(FOCUS_VISIBLE_INPUT_KEYS, e.key));
127
+ }
128
+ var currentModality = null;
129
+ var changeHandlers = /* @__PURE__ */ new Set();
130
+ var listenerMap = /* @__PURE__ */ new Map();
131
+ var hasEventBeforeFocus = false;
132
+ var hasBlurredWindowRecently = false;
133
+ var FOCUS_VISIBLE_INPUT_KEYS = {
134
+ Tab: true,
135
+ Escape: true
136
+ };
137
+ function triggerChangeHandlers(modality, e) {
138
+ for (let handler of changeHandlers) {
139
+ handler(modality, e);
140
+ }
141
+ }
142
+ function handleKeyboardEvent(e) {
143
+ hasEventBeforeFocus = true;
144
+ if (isValidKey(e)) {
145
+ currentModality = "keyboard";
146
+ triggerChangeHandlers("keyboard", e);
147
+ }
148
+ }
149
+ function handlePointerEvent(e) {
150
+ currentModality = "pointer";
151
+ if (e.type === "mousedown" || e.type === "pointerdown") {
152
+ hasEventBeforeFocus = true;
153
+ triggerChangeHandlers("pointer", e);
154
+ }
155
+ }
156
+ function handleClickEvent(e) {
157
+ if (isVirtualClick(e)) {
158
+ hasEventBeforeFocus = true;
159
+ currentModality = "virtual";
160
+ }
161
+ }
162
+ function handleFocusEvent(e) {
163
+ const target = getEventTarget(e);
164
+ if (target === getWindow(target) || target === getDocument(target)) {
165
+ return;
166
+ }
167
+ if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
168
+ currentModality = "virtual";
169
+ triggerChangeHandlers("virtual", e);
170
+ }
171
+ hasEventBeforeFocus = false;
172
+ hasBlurredWindowRecently = false;
173
+ }
174
+ function handleWindowBlur() {
175
+ hasEventBeforeFocus = false;
176
+ hasBlurredWindowRecently = true;
177
+ }
178
+ function setupGlobalFocusEvents(root) {
179
+ if (typeof window === "undefined" || listenerMap.get(getWindow(root))) {
180
+ return;
181
+ }
182
+ const win = getWindow(root);
183
+ const doc = getDocument(root);
184
+ let focus = win.HTMLElement.prototype.focus;
185
+ win.HTMLElement.prototype.focus = function() {
186
+ currentModality = "virtual";
187
+ triggerChangeHandlers("virtual", null);
188
+ hasEventBeforeFocus = true;
189
+ focus.apply(this, arguments);
190
+ };
191
+ doc.addEventListener("keydown", handleKeyboardEvent, true);
192
+ doc.addEventListener("keyup", handleKeyboardEvent, true);
193
+ doc.addEventListener("click", handleClickEvent, true);
194
+ win.addEventListener("focus", handleFocusEvent, true);
195
+ win.addEventListener("blur", handleWindowBlur, false);
196
+ if (typeof win.PointerEvent !== "undefined") {
197
+ doc.addEventListener("pointerdown", handlePointerEvent, true);
198
+ doc.addEventListener("pointermove", handlePointerEvent, true);
199
+ doc.addEventListener("pointerup", handlePointerEvent, true);
200
+ } else {
201
+ doc.addEventListener("mousedown", handlePointerEvent, true);
202
+ doc.addEventListener("mousemove", handlePointerEvent, true);
203
+ doc.addEventListener("mouseup", handlePointerEvent, true);
204
+ }
205
+ win.addEventListener(
206
+ "beforeunload",
207
+ () => {
208
+ tearDownWindowFocusTracking(root);
209
+ },
210
+ { once: true }
211
+ );
212
+ listenerMap.set(win, { focus });
213
+ }
214
+ var tearDownWindowFocusTracking = (root, loadListener) => {
215
+ const win = getWindow(root);
216
+ const doc = getDocument(root);
217
+ if (!listenerMap.has(win)) {
218
+ return;
219
+ }
220
+ win.HTMLElement.prototype.focus = listenerMap.get(win).focus;
221
+ doc.removeEventListener("keydown", handleKeyboardEvent, true);
222
+ doc.removeEventListener("keyup", handleKeyboardEvent, true);
223
+ doc.removeEventListener("click", handleClickEvent, true);
224
+ win.removeEventListener("focus", handleFocusEvent, true);
225
+ win.removeEventListener("blur", handleWindowBlur, false);
226
+ if (typeof win.PointerEvent !== "undefined") {
227
+ doc.removeEventListener("pointerdown", handlePointerEvent, true);
228
+ doc.removeEventListener("pointermove", handlePointerEvent, true);
229
+ doc.removeEventListener("pointerup", handlePointerEvent, true);
230
+ } else {
231
+ doc.removeEventListener("mousedown", handlePointerEvent, true);
232
+ doc.removeEventListener("mousemove", handlePointerEvent, true);
233
+ doc.removeEventListener("mouseup", handlePointerEvent, true);
234
+ }
235
+ listenerMap.delete(win);
236
+ };
237
+ function getInteractionModality() {
238
+ return currentModality;
239
+ }
240
+ function isFocusVisible() {
241
+ return currentModality === "keyboard";
242
+ }
243
+ function trackFocusVisible(props2 = {}) {
244
+ const { isTextInput, autoFocus, onChange, root } = props2;
245
+ setupGlobalFocusEvents(root);
246
+ onChange?.({ isFocusVisible: autoFocus || isFocusVisible(), modality: currentModality });
247
+ const handler = (modality, e) => {
248
+ if (!isKeyboardFocusEvent(!!isTextInput, modality, e)) return;
249
+ onChange?.({ isFocusVisible: isFocusVisible(), modality });
250
+ };
251
+ changeHandlers.add(handler);
252
+ return () => {
253
+ changeHandlers.delete(handler);
254
+ };
255
+ }
256
+ var anatomy = createAnatomy("listbox").parts(
257
+ "label",
258
+ "input",
259
+ "item",
260
+ "itemText",
261
+ "itemIndicator",
262
+ "itemGroup",
263
+ "itemGroupLabel",
264
+ "content",
265
+ "root",
266
+ "valueText"
267
+ );
268
+ var parts = anatomy.build();
269
+ var collection = (options) => {
270
+ return new ListCollection(options);
271
+ };
272
+ collection.empty = () => {
273
+ return new ListCollection({ items: [] });
274
+ };
275
+ var getRootId = (ctx) => ctx.ids?.root ?? `select:${ctx.id}`;
276
+ var getContentId = (ctx) => ctx.ids?.content ?? `select:${ctx.id}:content`;
277
+ var getLabelId = (ctx) => ctx.ids?.label ?? `select:${ctx.id}:label`;
278
+ var getItemId = (ctx, id) => ctx.ids?.item?.(id) ?? `select:${ctx.id}:option:${id}`;
279
+ var getItemGroupId = (ctx, id) => ctx.ids?.itemGroup?.(id) ?? `select:${ctx.id}:optgroup:${id}`;
280
+ var getItemGroupLabelId = (ctx, id) => ctx.ids?.itemGroupLabel?.(id) ?? `select:${ctx.id}:optgroup-label:${id}`;
281
+ var getContentEl = (ctx) => ctx.getById(getContentId(ctx));
282
+ var getItemEl = (ctx, id) => ctx.getById(getItemId(ctx, id));
283
+ function connect(service, normalize) {
284
+ const { context, prop, scope, computed, send } = service;
285
+ const disabled = prop("disabled");
286
+ const collection2 = prop("collection");
287
+ const layout = isGridCollection(collection2) ? "grid" : "list";
288
+ const value = context.get("value");
289
+ const highlightedValue = context.get("highlightedValue");
290
+ const highlightedItem = context.get("highlightedItem");
291
+ const selectedItems = context.get("selectedItems");
292
+ const isTypingAhead = computed("isTypingAhead");
293
+ const interactive = computed("isInteractive");
294
+ const ariaActiveDescendant = highlightedValue ? getItemId(scope, highlightedValue) : void 0;
295
+ function getItemState(props2) {
296
+ const itemDisabled = collection2.getItemDisabled(props2.item);
297
+ const value2 = collection2.getItemValue(props2.item);
298
+ ensure(value2, () => `[zag-js] No value found for item ${JSON.stringify(props2.item)}`);
299
+ return {
300
+ value: value2,
301
+ disabled: Boolean(disabled || itemDisabled),
302
+ highlighted: highlightedValue === value2 && context.get("focused"),
303
+ selected: context.get("value").includes(value2)
304
+ };
305
+ }
306
+ return {
307
+ empty: value.length === 0,
308
+ highlightedItem,
309
+ highlightedValue,
310
+ clearHighlightedValue() {
311
+ send({ type: "HIGHLIGHTED_VALUE.SET", value: null });
312
+ },
313
+ selectedItems,
314
+ hasSelectedItems: computed("hasSelectedItems"),
315
+ value,
316
+ valueAsString: context.get("valueAsString"),
317
+ collection: collection2,
318
+ disabled: !!disabled,
319
+ selectValue(value2) {
320
+ send({ type: "ITEM.SELECT", value: value2 });
321
+ },
322
+ setValue(value2) {
323
+ send({ type: "VALUE.SET", value: value2 });
324
+ },
325
+ selectAll() {
326
+ if (!computed("multiple")) {
327
+ throw new Error("[zag-js] Cannot select all items in a single-select listbox");
328
+ }
329
+ send({ type: "VALUE.SET", value: collection2.getValues() });
330
+ },
331
+ highlightValue(value2) {
332
+ send({ type: "HIGHLIGHTED_VALUE.SET", value: value2 });
333
+ },
334
+ clearValue(value2) {
335
+ if (value2) {
336
+ send({ type: "ITEM.CLEAR", value: value2 });
337
+ } else {
338
+ send({ type: "VALUE.CLEAR" });
339
+ }
340
+ },
341
+ getItemState,
342
+ getRootProps() {
343
+ return normalize.element({
344
+ ...parts.root.attrs,
345
+ dir: prop("dir"),
346
+ id: getRootId(scope),
347
+ "data-orientation": prop("orientation"),
348
+ "data-disabled": dataAttr(disabled)
349
+ });
350
+ },
351
+ getInputProps(props2 = {}) {
352
+ return normalize.input({
353
+ ...parts.input.attrs,
354
+ dir: prop("dir"),
355
+ disabled,
356
+ "data-disabled": dataAttr(disabled),
357
+ autoComplete: "off",
358
+ autoCorrect: "off",
359
+ "aria-haspopup": "listbox",
360
+ "aria-controls": getContentId(scope),
361
+ "aria-autocomplete": "list",
362
+ "aria-activedescendant": ariaActiveDescendant,
363
+ spellCheck: false,
364
+ enterKeyHint: "go",
365
+ onFocus() {
366
+ queueMicrotask(() => {
367
+ const contentEl = getContentEl(scope);
368
+ const win = getWindow(contentEl);
369
+ const focusInEvt = new win.FocusEvent("focusin", { bubbles: true, cancelable: true });
370
+ contentEl?.dispatchEvent(focusInEvt);
371
+ });
372
+ },
373
+ onBlur(event) {
374
+ if (event.defaultPrevented) return;
375
+ const contentEl = getContentEl(scope);
376
+ const win = getWindow(contentEl);
377
+ const focusOutEvt = new win.FocusEvent("focusout", { bubbles: true, cancelable: true });
378
+ contentEl?.dispatchEvent(focusOutEvt);
379
+ },
380
+ onInput(event) {
381
+ if (!props2.autoHighlight) return;
382
+ const node = event.currentTarget;
383
+ queueMicrotask(() => {
384
+ if (!node.isConnected) return;
385
+ send({
386
+ type: "HIGHLIGHTED_VALUE.SET",
387
+ value: node.value ? prop("collection").firstValue : null
388
+ });
389
+ });
390
+ },
391
+ onKeyDown(event) {
392
+ if (event.defaultPrevented) return;
393
+ if (isComposingEvent(event)) return;
394
+ const nativeEvent = getNativeEvent(event);
395
+ switch (nativeEvent.key) {
396
+ case "ArrowDown":
397
+ case "ArrowUp":
398
+ case "Home":
399
+ case "End": {
400
+ if ((event.key === "Home" || event.key === "End") && !highlightedValue && event.shiftKey) {
401
+ return;
402
+ }
403
+ event.preventDefault();
404
+ const win = scope.getWin();
405
+ const keyboardEvent = new win.KeyboardEvent(nativeEvent.type, nativeEvent);
406
+ getContentEl(scope)?.dispatchEvent(keyboardEvent);
407
+ break;
408
+ }
409
+ case "Enter":
410
+ event.preventDefault();
411
+ send({ type: "ITEM.CLICK", value: highlightedValue });
412
+ break;
413
+ }
414
+ }
415
+ });
416
+ },
417
+ getLabelProps() {
418
+ return normalize.element({
419
+ dir: prop("dir"),
420
+ id: getLabelId(scope),
421
+ ...parts.label.attrs,
422
+ "data-disabled": dataAttr(disabled)
423
+ });
424
+ },
425
+ getValueTextProps() {
426
+ return normalize.element({
427
+ ...parts.valueText.attrs,
428
+ dir: prop("dir"),
429
+ "data-disabled": dataAttr(disabled)
430
+ });
431
+ },
432
+ getItemProps(props2) {
433
+ const itemState = getItemState(props2);
434
+ return normalize.element({
435
+ id: getItemId(scope, itemState.value),
436
+ role: "option",
437
+ ...parts.item.attrs,
438
+ dir: prop("dir"),
439
+ "data-value": itemState.value,
440
+ "aria-selected": itemState.selected,
441
+ "data-selected": dataAttr(itemState.selected),
442
+ "data-layout": layout,
443
+ "data-state": itemState.selected ? "checked" : "unchecked",
444
+ "data-orientation": prop("orientation"),
445
+ "data-highlighted": dataAttr(itemState.highlighted),
446
+ "data-disabled": dataAttr(itemState.disabled),
447
+ "aria-disabled": ariaAttr(itemState.disabled),
448
+ onPointerMove(event) {
449
+ if (!props2.highlightOnHover) return;
450
+ if (itemState.disabled || event.pointerType !== "mouse") return;
451
+ if (itemState.highlighted) return;
452
+ send({ type: "ITEM.POINTER_MOVE", value: itemState.value });
453
+ },
454
+ onMouseDown(event) {
455
+ event.preventDefault();
456
+ getContentEl(scope)?.focus();
457
+ },
458
+ onClick(event) {
459
+ if (event.defaultPrevented) return;
460
+ if (itemState.disabled) return;
461
+ send({
462
+ type: "ITEM.CLICK",
463
+ value: itemState.value,
464
+ shiftKey: event.shiftKey,
465
+ anchorValue: highlightedValue,
466
+ metaKey: isCtrlOrMetaKey(event)
467
+ });
468
+ }
469
+ });
470
+ },
471
+ getItemTextProps(props2) {
472
+ const itemState = getItemState(props2);
473
+ return normalize.element({
474
+ ...parts.itemText.attrs,
475
+ "data-state": itemState.selected ? "checked" : "unchecked",
476
+ "data-disabled": dataAttr(itemState.disabled),
477
+ "data-highlighted": dataAttr(itemState.highlighted)
478
+ });
479
+ },
480
+ getItemIndicatorProps(props2) {
481
+ const itemState = getItemState(props2);
482
+ return normalize.element({
483
+ ...parts.itemIndicator.attrs,
484
+ "aria-hidden": true,
485
+ "data-state": itemState.selected ? "checked" : "unchecked",
486
+ hidden: !itemState.selected
487
+ });
488
+ },
489
+ getItemGroupLabelProps(props2) {
490
+ const { htmlFor } = props2;
491
+ return normalize.element({
492
+ ...parts.itemGroupLabel.attrs,
493
+ id: getItemGroupLabelId(scope, htmlFor),
494
+ dir: prop("dir"),
495
+ role: "presentation"
496
+ });
497
+ },
498
+ getItemGroupProps(props2) {
499
+ const { id } = props2;
500
+ return normalize.element({
501
+ ...parts.itemGroup.attrs,
502
+ "data-disabled": dataAttr(disabled),
503
+ "data-orientation": prop("orientation"),
504
+ "data-empty": dataAttr(collection2.size === 0),
505
+ id: getItemGroupId(scope, id),
506
+ "aria-labelledby": getItemGroupLabelId(scope, id),
507
+ role: "group",
508
+ dir: prop("dir")
509
+ });
510
+ },
511
+ getContentProps() {
512
+ return normalize.element({
513
+ dir: prop("dir"),
514
+ id: getContentId(scope),
515
+ role: "listbox",
516
+ ...parts.content.attrs,
517
+ "data-activedescendant": ariaActiveDescendant,
518
+ "aria-activedescendant": ariaActiveDescendant,
519
+ "data-orientation": prop("orientation"),
520
+ "aria-multiselectable": computed("multiple") ? true : void 0,
521
+ "aria-labelledby": getLabelId(scope),
522
+ tabIndex: 0,
523
+ "data-layout": layout,
524
+ "data-empty": dataAttr(collection2.size === 0),
525
+ style: {
526
+ "--column-count": isGridCollection(collection2) ? collection2.columnCount : 1
527
+ },
528
+ onFocus() {
529
+ send({ type: "CONTENT.FOCUS" });
530
+ },
531
+ onBlur() {
532
+ send({ type: "CONTENT.BLUR" });
533
+ },
534
+ onKeyDown(event) {
535
+ if (!interactive) return;
536
+ if (!isSelfTarget(event)) return;
537
+ const shiftKey = event.shiftKey;
538
+ const keyMap = {
539
+ ArrowUp(event2) {
540
+ let nextValue = null;
541
+ if (isGridCollection(collection2) && highlightedValue) {
542
+ nextValue = collection2.getPreviousRowValue(highlightedValue);
543
+ } else if (highlightedValue) {
544
+ nextValue = collection2.getPreviousValue(highlightedValue);
545
+ }
546
+ if (!nextValue && (prop("loopFocus") || !highlightedValue)) {
547
+ nextValue = collection2.lastValue;
548
+ }
549
+ if (!nextValue) return;
550
+ event2.preventDefault();
551
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
552
+ },
553
+ ArrowDown(event2) {
554
+ let nextValue = null;
555
+ if (isGridCollection(collection2) && highlightedValue) {
556
+ nextValue = collection2.getNextRowValue(highlightedValue);
557
+ } else if (highlightedValue) {
558
+ nextValue = collection2.getNextValue(highlightedValue);
559
+ }
560
+ if (!nextValue && (prop("loopFocus") || !highlightedValue)) {
561
+ nextValue = collection2.firstValue;
562
+ }
563
+ if (!nextValue) return;
564
+ event2.preventDefault();
565
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
566
+ },
567
+ ArrowLeft() {
568
+ if (!isGridCollection(collection2) && prop("orientation") === "vertical") return;
569
+ let nextValue = highlightedValue ? collection2.getPreviousValue(highlightedValue) : null;
570
+ if (!nextValue && prop("loopFocus")) {
571
+ nextValue = collection2.lastValue;
572
+ }
573
+ if (!nextValue) return;
574
+ event.preventDefault();
575
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
576
+ },
577
+ ArrowRight() {
578
+ if (!isGridCollection(collection2) && prop("orientation") === "vertical") return;
579
+ let nextValue = highlightedValue ? collection2.getNextValue(highlightedValue) : null;
580
+ if (!nextValue && prop("loopFocus")) {
581
+ nextValue = collection2.firstValue;
582
+ }
583
+ if (!nextValue) return;
584
+ event.preventDefault();
585
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
586
+ },
587
+ Home(event2) {
588
+ event2.preventDefault();
589
+ let nextValue = collection2.firstValue;
590
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
591
+ },
592
+ End(event2) {
593
+ event2.preventDefault();
594
+ let nextValue = collection2.lastValue;
595
+ send({ type: "NAVIGATE", value: nextValue, shiftKey, anchorValue: highlightedValue });
596
+ },
597
+ Enter() {
598
+ send({ type: "ITEM.CLICK", value: highlightedValue });
599
+ },
600
+ a(event2) {
601
+ if (isCtrlOrMetaKey(event2) && computed("multiple") && !prop("disallowSelectAll")) {
602
+ event2.preventDefault();
603
+ send({ type: "VALUE.SET", value: collection2.getValues() });
604
+ }
605
+ },
606
+ Space(event2) {
607
+ if (isTypingAhead && prop("typeahead")) {
608
+ send({ type: "CONTENT.TYPEAHEAD", key: event2.key });
609
+ } else {
610
+ keyMap.Enter?.(event2);
611
+ }
612
+ },
613
+ Escape(event2) {
614
+ if (prop("deselectable") && value.length > 0) {
615
+ event2.preventDefault();
616
+ event2.stopPropagation();
617
+ send({ type: "VALUE.CLEAR" });
618
+ }
619
+ }
620
+ };
621
+ const exec = keyMap[getEventKey(event)];
622
+ if (exec) {
623
+ exec(event);
624
+ return;
625
+ }
626
+ const target = getEventTarget(event);
627
+ if (isEditableElement(target)) {
628
+ return;
629
+ }
630
+ if (getByTypeahead.isValidEvent(event) && prop("typeahead")) {
631
+ send({ type: "CONTENT.TYPEAHEAD", key: event.key });
632
+ event.preventDefault();
633
+ }
634
+ }
635
+ });
636
+ }
637
+ };
638
+ }
639
+ var machine = createMachine({
640
+ props({ props: props2 }) {
641
+ return {
642
+ loopFocus: false,
643
+ composite: true,
644
+ defaultValue: [],
645
+ multiple: false,
646
+ typeahead: true,
647
+ collection: collection.empty(),
648
+ orientation: "vertical",
649
+ selectionMode: "single",
650
+ ...props2
651
+ };
652
+ },
653
+ context({ prop, bindable }) {
654
+ return {
655
+ value: bindable(() => ({
656
+ defaultValue: prop("defaultValue"),
657
+ value: prop("value"),
658
+ isEqual,
659
+ onChange(value) {
660
+ const items = prop("collection").findMany(value);
661
+ return prop("onValueChange")?.({ value, items });
662
+ }
663
+ })),
664
+ highlightedValue: bindable(() => ({
665
+ defaultValue: prop("defaultHighlightedValue") || null,
666
+ value: prop("highlightedValue"),
667
+ sync: true,
668
+ onChange(value) {
669
+ prop("onHighlightChange")?.({
670
+ highlightedValue: value,
671
+ highlightedItem: prop("collection").find(value),
672
+ highlightedIndex: prop("collection").indexOf(value)
673
+ });
674
+ }
675
+ })),
676
+ highlightedItem: bindable(() => ({
677
+ defaultValue: null
678
+ })),
679
+ selectedItems: bindable(() => {
680
+ const value = prop("value") ?? prop("defaultValue") ?? [];
681
+ const items = prop("collection").findMany(value);
682
+ return { defaultValue: items };
683
+ }),
684
+ valueAsString: bindable(() => {
685
+ const value = prop("value") ?? prop("defaultValue") ?? [];
686
+ return { defaultValue: prop("collection").stringifyMany(value) };
687
+ }),
688
+ focused: bindable(() => ({
689
+ defaultValue: false
690
+ }))
691
+ };
692
+ },
693
+ refs({ prop }) {
694
+ return {
695
+ typeahead: { ...getByTypeahead.defaultOptions },
696
+ prevCollection: prop("collection")
697
+ };
698
+ },
699
+ computed: {
700
+ hasSelectedItems: ({ context }) => context.get("value").length > 0,
701
+ isTypingAhead: ({ refs }) => refs.get("typeahead").keysSoFar !== "",
702
+ isInteractive: ({ prop }) => !prop("disabled"),
703
+ selection: ({ context, prop }) => {
704
+ const selection = new Selection(context.get("value"));
705
+ selection.selectionMode = prop("selectionMode");
706
+ selection.deselectable = !!prop("deselectable");
707
+ return selection;
708
+ },
709
+ multiple: ({ prop }) => prop("selectionMode") === "multiple" || prop("selectionMode") === "extended"
710
+ },
711
+ initialState() {
712
+ return "idle";
713
+ },
714
+ watch({ context, prop, track, action }) {
715
+ track([() => context.get("value").toString()], () => {
716
+ action(["syncSelectedItems"]);
717
+ });
718
+ track([() => context.get("highlightedValue")], () => {
719
+ action(["syncHighlightedItem"]);
720
+ });
721
+ track([() => prop("collection").toString()], () => {
722
+ action(["syncCollection"]);
723
+ });
724
+ },
725
+ effects: ["trackFocusVisible"],
726
+ on: {
727
+ "HIGHLIGHTED_VALUE.SET": {
728
+ actions: ["setHighlightedItem"]
729
+ },
730
+ "ITEM.SELECT": {
731
+ actions: ["selectItem"]
732
+ },
733
+ "ITEM.CLEAR": {
734
+ actions: ["clearItem"]
735
+ },
736
+ "VALUE.SET": {
737
+ actions: ["setSelectedItems"]
738
+ },
739
+ "VALUE.CLEAR": {
740
+ actions: ["clearSelectedItems"]
741
+ },
742
+ "CLEAR.CLICK": {
743
+ actions: ["clearSelectedItems"]
744
+ }
745
+ },
746
+ states: {
747
+ idle: {
748
+ effects: ["scrollToHighlightedItem"],
749
+ on: {
750
+ "CONTENT.FOCUS": {
751
+ actions: ["setFocused"]
752
+ },
753
+ "CONTENT.BLUR": {
754
+ actions: ["clearFocused"]
755
+ },
756
+ "ITEM.CLICK": {
757
+ actions: ["setHighlightedItem", "selectHighlightedItem"]
758
+ },
759
+ "CONTENT.TYPEAHEAD": {
760
+ actions: ["highlightMatchingItem"]
761
+ },
762
+ "ITEM.POINTER_MOVE": {
763
+ actions: ["highlightItem"]
764
+ },
765
+ "ITEM.POINTER_LEAVE": {
766
+ actions: ["clearHighlightedItem"]
767
+ },
768
+ NAVIGATE: {
769
+ actions: ["setHighlightedItem", "selectWithKeyboard"]
770
+ }
771
+ }
772
+ }
773
+ },
774
+ implementations: {
775
+ effects: {
776
+ trackFocusVisible: ({ scope }) => {
777
+ return trackFocusVisible({ root: scope.getRootNode?.() });
778
+ },
779
+ scrollToHighlightedItem({ context, prop, scope }) {
780
+ const exec = (immediate) => {
781
+ const highlightedValue = context.get("highlightedValue");
782
+ if (highlightedValue == null) return;
783
+ const modality = getInteractionModality();
784
+ if (modality !== "keyboard") return;
785
+ const itemEl = getItemEl(scope, highlightedValue);
786
+ const contentEl2 = getContentEl(scope);
787
+ const scrollToIndexFn = prop("scrollToIndexFn");
788
+ if (scrollToIndexFn) {
789
+ const highlightedIndex = prop("collection").indexOf(highlightedValue);
790
+ scrollToIndexFn?.({ index: highlightedIndex, immediate });
791
+ return;
792
+ }
793
+ scrollIntoView(itemEl, { rootEl: contentEl2, block: "nearest" });
794
+ };
795
+ raf(() => exec(true));
796
+ const contentEl = () => getContentEl(scope);
797
+ return observeAttributes(contentEl, {
798
+ defer: true,
799
+ attributes: ["data-activedescendant"],
800
+ callback() {
801
+ exec(false);
802
+ }
803
+ });
804
+ }
805
+ },
806
+ actions: {
807
+ selectHighlightedItem({ context, prop, event, computed }) {
808
+ const value = event.value ?? context.get("highlightedValue");
809
+ if (value == null) return;
810
+ const selection = computed("selection");
811
+ const collection2 = prop("collection");
812
+ if (event.shiftKey && computed("multiple") && event.anchorValue) {
813
+ const next = selection.extendSelection(collection2, event.anchorValue, value);
814
+ invokeOnSelect(selection, next, prop("onSelect"));
815
+ context.set("value", Array.from(next));
816
+ } else {
817
+ const next = selection.select(collection2, value, event.metaKey);
818
+ invokeOnSelect(selection, next, prop("onSelect"));
819
+ context.set("value", Array.from(next));
820
+ }
821
+ },
822
+ selectWithKeyboard({ context, prop, event, computed }) {
823
+ const selection = computed("selection");
824
+ const collection2 = prop("collection");
825
+ if (event.shiftKey && computed("multiple") && event.anchorValue) {
826
+ const next = selection.extendSelection(collection2, event.anchorValue, event.value);
827
+ invokeOnSelect(selection, next, prop("onSelect"));
828
+ context.set("value", Array.from(next));
829
+ return;
830
+ }
831
+ if (prop("selectOnHighlight")) {
832
+ const next = selection.replaceSelection(collection2, event.value);
833
+ invokeOnSelect(selection, next, prop("onSelect"));
834
+ context.set("value", Array.from(next));
835
+ }
836
+ },
837
+ highlightItem({ context, event }) {
838
+ context.set("highlightedValue", event.value);
839
+ },
840
+ highlightMatchingItem({ context, prop, event, refs }) {
841
+ const value = prop("collection").search(event.key, {
842
+ state: refs.get("typeahead"),
843
+ currentValue: context.get("highlightedValue")
844
+ });
845
+ if (value == null) return;
846
+ context.set("highlightedValue", value);
847
+ },
848
+ setHighlightedItem({ context, event }) {
849
+ context.set("highlightedValue", event.value);
850
+ },
851
+ clearHighlightedItem({ context }) {
852
+ context.set("highlightedValue", null);
853
+ },
854
+ selectItem({ context, prop, event, computed }) {
855
+ const collection2 = prop("collection");
856
+ const selection = computed("selection");
857
+ const next = selection.select(collection2, event.value);
858
+ invokeOnSelect(selection, next, prop("onSelect"));
859
+ context.set("value", Array.from(next));
860
+ },
861
+ clearItem({ context, event, computed }) {
862
+ const selection = computed("selection");
863
+ const value = selection.deselect(event.value);
864
+ context.set("value", Array.from(value));
865
+ },
866
+ setSelectedItems({ context, event }) {
867
+ context.set("value", event.value);
868
+ },
869
+ clearSelectedItems({ context }) {
870
+ context.set("value", []);
871
+ },
872
+ syncCollection({ context, prop, refs }) {
873
+ const collection2 = prop("collection");
874
+ const highlightedItem = collection2.find(context.get("highlightedValue"));
875
+ if (highlightedItem) context.set("highlightedItem", highlightedItem);
876
+ const selectedItems = collection2.findMany(context.get("value"));
877
+ context.set("selectedItems", selectedItems);
878
+ const valueAsString = collection2.stringifyItems(selectedItems);
879
+ context.set("valueAsString", valueAsString);
880
+ const highlightedValue = syncHighlightedValue(
881
+ collection2,
882
+ refs.get("prevCollection"),
883
+ context.get("highlightedValue")
884
+ );
885
+ queueMicrotask(() => {
886
+ context.set("highlightedValue", highlightedValue);
887
+ refs.set("prevCollection", collection2);
888
+ });
889
+ },
890
+ syncSelectedItems({ context, prop }) {
891
+ const collection2 = prop("collection");
892
+ const prevSelectedItems = context.get("selectedItems");
893
+ const value = context.get("value");
894
+ const selectedItems = value.map((value2) => {
895
+ const item = prevSelectedItems.find((item2) => collection2.getItemValue(item2) === value2);
896
+ return item || collection2.find(value2);
897
+ });
898
+ context.set("selectedItems", selectedItems);
899
+ context.set("valueAsString", collection2.stringifyItems(selectedItems));
900
+ },
901
+ syncHighlightedItem({ context, prop }) {
902
+ const collection2 = prop("collection");
903
+ const highlightedValue = context.get("highlightedValue");
904
+ const highlightedItem = highlightedValue ? collection2.find(highlightedValue) : null;
905
+ context.set("highlightedItem", highlightedItem);
906
+ },
907
+ setFocused({ context }) {
908
+ context.set("focused", true);
909
+ },
910
+ clearFocused({ context }) {
911
+ context.set("focused", false);
912
+ }
913
+ }
914
+ }
915
+ });
916
+ var diff = (a, b) => {
917
+ const result = new Set(a);
918
+ for (const item of b) result.delete(item);
919
+ return result;
920
+ };
921
+ function invokeOnSelect(current, next, onSelect) {
922
+ const added = diff(next, current);
923
+ for (const item of added) {
924
+ onSelect?.({ value: item });
925
+ }
926
+ }
927
+ function syncHighlightedValue(collection2, prevCollection, highlightedValue) {
928
+ if (highlightedValue != null && !collection2.find(highlightedValue) && prevCollection) {
929
+ const startIndex = prevCollection.indexOf(highlightedValue);
930
+ const prevItems = [...prevCollection.items];
931
+ const items = [...collection2.items];
932
+ const diff2 = (prevItems?.length ?? 0) - (items?.length ?? 0);
933
+ let index = Math.min(
934
+ diff2 > 1 ? Math.max((startIndex ?? 0) - diff2 + 1, 0) : startIndex ?? 0,
935
+ (items?.length ?? 0) - 1
936
+ );
937
+ let newValue = null;
938
+ let isReverseSearching = false;
939
+ while (index >= 0) {
940
+ if (!collection2.getItemDisabled(items[index])) {
941
+ newValue = collection2.getItemValue(items[index]);
942
+ break;
943
+ }
944
+ if (index < items.length - 1 && !isReverseSearching) {
945
+ index++;
946
+ } else {
947
+ isReverseSearching = true;
948
+ if (index > (startIndex ?? 0)) {
949
+ index = startIndex ?? 0;
950
+ }
951
+ index--;
952
+ }
953
+ }
954
+ return newValue;
955
+ }
956
+ return null;
957
+ }
958
+ var props = createProps()([
959
+ "collection",
960
+ "defaultHighlightedValue",
961
+ "defaultValue",
962
+ "dir",
963
+ "disabled",
964
+ "deselectable",
965
+ "disallowSelectAll",
966
+ "getRootNode",
967
+ "highlightedValue",
968
+ "id",
969
+ "ids",
970
+ "loopFocus",
971
+ "onHighlightChange",
972
+ "onSelect",
973
+ "onValueChange",
974
+ "orientation",
975
+ "scrollToIndexFn",
976
+ "selectionMode",
977
+ "selectOnHighlight",
978
+ "typeahead",
979
+ "value"
980
+ ]);
981
+ createSplitProps(props);
982
+ var itemProps = createProps()(["item", "highlightOnHover"]);
983
+ createSplitProps(itemProps);
984
+ var itemGroupProps = createProps()(["id"]);
985
+ createSplitProps(itemGroupProps);
986
+ var itemGroupLabelProps = createProps()(["htmlFor"]);
987
+ createSplitProps(itemGroupLabelProps);
988
+ var useListbox = (props2) => {
989
+ const id = createUniqueId();
990
+ const locale = useLocaleContext();
991
+ const environment = useEnvironmentContext();
992
+ const machineProps = createMemo(() => ({
993
+ id,
994
+ dir: locale().dir,
995
+ getRootNode: environment().getRootNode,
996
+ ...runIfFn(props2)
997
+ }));
998
+ const service = useMachine(machine, machineProps);
999
+ return createMemo(() => connect(service, normalizeProps));
1000
+ };
1001
+
1002
+ // src/components/listbox/listbox-root.tsx
1003
+ var ListboxRoot = (props2) => {
1004
+ const [useListboxProps, localProps] = createSplitProps$1()(props2, ["collection", "defaultHighlightedValue", "defaultValue", "deselectable", "disabled", "disallowSelectAll", "highlightedValue", "id", "ids", "loopFocus", "onHighlightChange", "onSelect", "onValueChange", "orientation", "scrollToIndexFn", "selectionMode", "selectOnHighlight", "typeahead", "value"]);
1005
+ const listbox = useListbox(useListboxProps);
1006
+ const mergedProps = mergeProps(() => listbox().getRootProps(), localProps);
1007
+ return createComponent(ListboxProvider, {
1008
+ value: listbox,
1009
+ get children() {
1010
+ return createComponent(ark.div, mergedProps);
1011
+ }
1012
+ });
1013
+ };
1014
+ var ListboxRootProvider = (props2) => {
1015
+ const [{
1016
+ value: listbox
1017
+ }, localProps] = createSplitProps$1()(props2, ["value"]);
1018
+ const mergedProps = mergeProps(() => listbox().getRootProps(), localProps);
1019
+ return createComponent(ListboxProvider, {
1020
+ value: listbox,
1021
+ get children() {
1022
+ return createComponent(ark.div, mergedProps);
1023
+ }
1024
+ });
1025
+ };
1026
+ var ListboxValueText = (props2) => {
1027
+ const {
1028
+ placeholder,
1029
+ ...localprops
1030
+ } = props2;
1031
+ const listbox = useListboxContext();
1032
+ const mergedProps = mergeProps(() => listbox().getValueTextProps(), localprops);
1033
+ const resolved = children(() => props2.children);
1034
+ return createComponent(ark.span, mergeProps$1(mergedProps, {
1035
+ get children() {
1036
+ return resolved() || listbox().valueAsString || placeholder;
1037
+ }
1038
+ }));
1039
+ };
1040
+
1041
+ // src/components/listbox/listbox.ts
1042
+ var listbox_exports = {};
1043
+ __export(listbox_exports, {
1044
+ Content: () => ListboxContent,
1045
+ Input: () => ListboxInput,
1046
+ Item: () => ListboxItem,
1047
+ ItemGroup: () => ListboxItemGroup,
1048
+ ItemGroupLabel: () => ListboxItemGroupLabel,
1049
+ ItemIndicator: () => ListboxItemIndicator,
1050
+ ItemText: () => ListboxItemText,
1051
+ Label: () => ListboxLabel,
1052
+ Root: () => ListboxRoot,
1053
+ RootProvider: () => ListboxRootProvider,
1054
+ ValueText: () => ListboxValueText
1055
+ });
1056
+
1057
+ export { ListboxContent, ListboxInput, ListboxItem, ListboxItemGroup, ListboxItemGroupLabel, ListboxItemIndicator, ListboxItemText, ListboxLabel, ListboxRoot, ListboxRootProvider, ListboxValueText, anatomy, listbox_exports, useListbox, useListboxContext, useListboxItemContext };