@ark-ui/solid 5.15.1 → 5.15.3

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