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