@gridui/select 1.0.6 → 1.1.2

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.
package/dist/index.js CHANGED
@@ -1,158 +1,33 @@
1
1
  // src/shared/style.ts
2
- import { dropdownItemStyles } from "@gridui/dropdown-menu";
3
- import { overlaySurfaceStyles } from "@gridui/overlay";
2
+ import { overlayListItemStyles, overlayListStyles } from "@gridui/overlay";
4
3
  import { cn } from "@gridui/style-utils";
5
4
  import { cva } from "class-variance-authority";
6
- var selectItemStyles = cva(cn(dropdownItemStyles(), "gridui-u-min-w-0"));
7
- var selectIconStyles = cva("gridui-u-inline-flex gridui-u-shrink-0 gridui-u-items-center gridui-u-[&_svg]:size-gridui-16");
8
- var selectOptionContentStyles = cva("gridui-u-min-w-0 gridui-u-flex-1 gridui-u-whitespace-normal gridui-u-wrap-anywhere");
9
- var selectOptionDescriptionStyles = cva("gridui-u-block gridui-u-text-muted gridui-u-type-caption gridui-u-mt-gridui-4");
10
- var selectListStyles = cva("gridui-u-min-h-0 gridui-u-overflow-y-auto");
11
- var selectEmptyStyles = cva("gridui-u-p-gridui-8 gridui-u-text-muted gridui-u-type-caption");
12
- var selectActionsStyles = cva("gridui-u-shrink-0 gridui-u-border-t gridui-u-border-border gridui-u-pt-gridui-4");
5
+ var selectIconStyles = cva("gridui-u-select--inline-flex gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--[&_svg]:size-gridui-16");
6
+ var selectOptionContentStyles = cva("gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere");
7
+ var selectOptionDescriptionStyles = cva("gridui-u-select--block gridui-u-select--text-muted gridui-u-select--type-caption gridui-u-select--mt-gridui-4");
8
+ var selectListStyles = cva("gridui-u-select--min-h-0 gridui-u-select--overflow-y-auto");
9
+ var selectEmptyStyles = cva("gridui-u-select--p-gridui-8 gridui-u-select--text-muted gridui-u-select--type-caption");
10
+ var selectActionsStyles = cva("gridui-u-select--shrink-0 gridui-u-select--border-t gridui-u-select--border-border");
13
11
  var selectActionStyles = cva(cn(
14
- selectItemStyles(),
15
- "gridui-u-w-full gridui-u-text-start gridui-u-whitespace-normal gridui-u-wrap-anywhere"
12
+ overlayListItemStyles(),
13
+ "gridui-u-select--w-full gridui-u-select--text-start"
16
14
  ));
17
15
  var comboboxContentStyles = cva(cn(
18
- overlaySurfaceStyles(),
19
- "gridui-u-z-(--gridui-z-popover) gridui-u-p-gridui-4 gridui-u-type-data",
20
- "gridui-combobox-content gridui-u-box-border gridui-u-flex gridui-u-flex-col gridui-u-overflow-hidden gridui-u-min-w-0 gridui-u-w-(--anchor-width) gridui-u-max-h-(--available-height) gridui-u-max-w-(--available-width)"
16
+ overlayListStyles(),
17
+ "gridui-combobox-content gridui-u-select--box-border gridui-u-select--flex gridui-u-select--flex-col gridui-u-select--overflow-hidden gridui-u-select--min-w-0 gridui-u-select--w-(--anchor-width) gridui-u-select--max-h-(--available-height) gridui-u-select--max-w-(--available-width)"
21
18
  ));
22
19
 
23
- // src/shared/combobox-options.tsx
24
- import { dropdownIndicatorStyles, dropdownLabelStyles } from "@gridui/dropdown-menu";
25
- import { useInteractionOutline, useScrollbars } from "@gridui/overlay";
26
- import { Check } from "lucide-react";
27
- import { jsx, jsxs } from "react/jsx-runtime";
28
- var ComboboxOptions = (props) => {
29
- const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
30
- const scrollbarRef = useScrollbars();
31
- const ref = useInteractionOutline({
32
- ref: scrollbarRef,
33
- selector: '[role="option"]'
34
- });
35
- const renderOption = (option) => {
36
- const itemId = optionId(option.value);
37
- const checked = typeof selected === "string" ? selected === option.value : selected.includes(option.value);
38
- return /* @__PURE__ */ jsxs(
39
- "div",
40
- {
41
- id: itemId,
42
- role: "option",
43
- "aria-selected": checked,
44
- "aria-disabled": option.disabled,
45
- "aria-labelledby": `${itemId}-label`,
46
- "aria-describedby": option.description ? `${itemId}-description` : void 0,
47
- "data-disabled": option.disabled ? "" : void 0,
48
- "data-highlighted": active === option.value ? "" : void 0,
49
- className: selectItemStyles(),
50
- onPointerMove: () => {
51
- onHighlight(option.value);
52
- },
53
- onPointerDown: (event) => {
54
- event.preventDefault();
55
- },
56
- onClick: () => {
57
- if (!option.disabled) {
58
- onSelect(option);
59
- }
60
- },
61
- children: [
62
- /* @__PURE__ */ jsx(
63
- "span",
64
- {
65
- className: dropdownIndicatorStyles(),
66
- "aria-hidden": "true",
67
- children: checked && /* @__PURE__ */ jsx(
68
- Check,
69
- {
70
- size: 16
71
- }
72
- )
73
- }
74
- ),
75
- option.icon && /* @__PURE__ */ jsx(
76
- "span",
77
- {
78
- className: selectIconStyles(),
79
- "aria-hidden": "true",
80
- children: option.icon
81
- }
82
- ),
83
- /* @__PURE__ */ jsxs(
84
- "span",
85
- {
86
- className: selectOptionContentStyles(),
87
- children: [
88
- /* @__PURE__ */ jsx(
89
- "span",
90
- {
91
- id: `${itemId}-label`,
92
- children: option.label
93
- }
94
- ),
95
- option.description && /* @__PURE__ */ jsx(
96
- "span",
97
- {
98
- id: `${itemId}-description`,
99
- className: selectOptionDescriptionStyles(),
100
- children: option.description
101
- }
102
- )
103
- ]
104
- }
105
- )
106
- ]
107
- },
108
- option.value
109
- );
110
- };
111
- return /* @__PURE__ */ jsx(
112
- "div",
113
- {
114
- ref,
115
- id,
116
- role: "listbox",
117
- "aria-multiselectable": multiple || void 0,
118
- "aria-label": label,
119
- className: selectListStyles(),
120
- children: options.map((entry, index) => {
121
- return "options" in entry ? /* @__PURE__ */ jsxs(
122
- "div",
123
- {
124
- role: "group",
125
- "aria-labelledby": `${id}-group-${index}`,
126
- children: [
127
- /* @__PURE__ */ jsx(
128
- "div",
129
- {
130
- id: `${id}-group-${index}`,
131
- className: dropdownLabelStyles(),
132
- children: entry.label
133
- }
134
- ),
135
- entry.options.map(renderOption)
136
- ]
137
- },
138
- entry.label
139
- ) : renderOption(entry);
140
- })
141
- }
142
- );
143
- };
144
-
145
- // src/shared/selection-actions.tsx
146
- import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
20
+ // src/shared/popup/selection-actions.tsx
21
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
147
22
  var SelectionActions = (props) => {
148
23
  const { actions, onAction } = props;
149
- return /* @__PURE__ */ jsx2(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx2(
24
+ return /* @__PURE__ */ jsx(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx(
150
25
  "div",
151
26
  {
152
27
  className: selectActionsStyles(),
153
28
  children: actions.map((action) => {
154
- const content = /* @__PURE__ */ jsxs2(Fragment, { children: [
155
- action.icon && /* @__PURE__ */ jsx2(
29
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
30
+ action.icon && /* @__PURE__ */ jsx(
156
31
  "span",
157
32
  {
158
33
  className: selectIconStyles(),
@@ -164,7 +39,7 @@ var SelectionActions = (props) => {
164
39
  ] });
165
40
  const actionClass = selectActionStyles();
166
41
  if (action.href !== void 0) {
167
- return /* @__PURE__ */ jsx2(
42
+ return /* @__PURE__ */ jsx(
168
43
  "a",
169
44
  {
170
45
  href: action.disabled ? void 0 : action.href,
@@ -188,7 +63,7 @@ var SelectionActions = (props) => {
188
63
  action.id
189
64
  );
190
65
  }
191
- return /* @__PURE__ */ jsx2(
66
+ return /* @__PURE__ */ jsx(
192
67
  "button",
193
68
  {
194
69
  type: "button",
@@ -207,104 +82,18 @@ var SelectionActions = (props) => {
207
82
  ) });
208
83
  };
209
84
 
210
- // src/shared/selection-form.tsx
211
- import { focusInvalidControl, useFormReset } from "@gridui/form";
212
- import { useLayoutEffect, useRef } from "react";
213
- import { flushSync } from "react-dom";
214
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
215
- var SelectionForm = (props) => {
216
- const {
217
- name,
218
- form,
219
- required,
220
- disabled,
221
- selectedValue,
222
- allOptions,
223
- onValueChange,
224
- onReset,
225
- onInvalid
226
- } = props;
227
- const nativeRef = useRef(null);
228
- const resetSelection = useRef(onReset);
229
- const currentValue = useRef(selectedValue);
230
- useLayoutEffect(() => {
231
- resetSelection.current = onReset;
232
- currentValue.current = selectedValue;
233
- }, [
234
- onReset,
235
- selectedValue
236
- ]);
237
- useFormReset(nativeRef, () => {
238
- flushSync(() => {
239
- resetSelection.current();
240
- });
241
- if (nativeRef.current) {
242
- nativeRef.current.value = currentValue.current;
243
- }
244
- }, form);
245
- return /* @__PURE__ */ jsxs3(
246
- "select",
247
- {
248
- ref: nativeRef,
249
- "aria-hidden": "true",
250
- tabIndex: -1,
251
- className: "gridui-u-sr-only",
252
- name,
253
- form,
254
- required,
255
- disabled,
256
- value: selectedValue,
257
- onChange: (event) => {
258
- onValueChange(event.currentTarget.value);
259
- },
260
- onInvalid: (event) => {
261
- focusInvalidControl(event, onInvalid);
262
- },
263
- children: [
264
- !allOptions.some((option) => {
265
- return option.value === "";
266
- }) && /* @__PURE__ */ jsx3(
267
- "option",
268
- {
269
- value: ""
270
- }
271
- ),
272
- selectedValue !== "" && !allOptions.some((option) => {
273
- return option.value === selectedValue;
274
- }) && /* @__PURE__ */ jsx3(
275
- "option",
276
- {
277
- value: selectedValue,
278
- children: selectedValue
279
- }
280
- ),
281
- allOptions.map((option) => {
282
- return /* @__PURE__ */ jsx3(
283
- "option",
284
- {
285
- value: option.value,
286
- disabled: option.disabled,
287
- children: option.label
288
- },
289
- option.value
290
- );
291
- })
292
- ]
293
- }
294
- );
295
- };
296
-
297
- // src/shared/selection-popup.tsx
85
+ // src/shared/popup/selection-popup.tsx
86
+ import { isComposingKeyEvent } from "@gridui/interaction";
298
87
  import { interactionLayerProps } from "@gridui/overlay";
299
88
  import * as Primitive from "@radix-ui/react-popover";
300
- import { jsx as jsx4 } from "react/jsx-runtime";
89
+ import { jsx as jsx2 } from "react/jsx-runtime";
301
90
  var SelectionPopup = (props) => {
302
91
  const { container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
303
- return /* @__PURE__ */ jsx4(
92
+ return /* @__PURE__ */ jsx2(
304
93
  Primitive.Portal,
305
94
  {
306
95
  container,
307
- children: /* @__PURE__ */ jsx4(
96
+ children: /* @__PURE__ */ jsx2(
308
97
  Primitive.Content,
309
98
  {
310
99
  ...interactionLayerProps,
@@ -330,21 +119,211 @@ var SelectionPopup = (props) => {
330
119
  } else {
331
120
  onDismiss?.();
332
121
  }
333
- },
334
- onEscapeKeyDown: (event) => {
335
- event.preventDefault();
336
- event.stopPropagation();
337
- if (!event.isComposing) {
338
- onEscape();
122
+ },
123
+ onEscapeKeyDown: (event) => {
124
+ event.preventDefault();
125
+ event.stopPropagation();
126
+ if (!isComposingKeyEvent(event)) {
127
+ onEscape();
128
+ }
129
+ },
130
+ onKeyDown: (event) => {
131
+ if (event.key === "Escape") {
132
+ event.stopPropagation();
133
+ }
134
+ }
135
+ }
136
+ )
137
+ }
138
+ );
139
+ };
140
+
141
+ // src/shared/popup/use-selection-popup.ts
142
+ import { useEffect, useRef, useState } from "react";
143
+ import { flushSync } from "react-dom";
144
+ var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
145
+ const [
146
+ localOpen,
147
+ setLocalOpen
148
+ ] = useState(false);
149
+ const popupRef = useRef(null);
150
+ const restoreFocus = useRef(true);
151
+ const unavailable = Boolean(disabled || readOnly);
152
+ useEffect(() => {
153
+ if (unavailable) {
154
+ setLocalOpen(false);
155
+ }
156
+ }, [unavailable]);
157
+ const available = () => {
158
+ return !unavailable && !controlRef.current?.matches(":disabled");
159
+ };
160
+ const changeOpen = (next) => {
161
+ if (next && !available()) {
162
+ return;
163
+ }
164
+ if (next) {
165
+ restoreFocus.current = true;
166
+ }
167
+ setLocalOpen(next);
168
+ };
169
+ const close = () => {
170
+ restoreFocus.current = false;
171
+ setLocalOpen(false);
172
+ };
173
+ const focus = () => {
174
+ controlRef.current?.focus();
175
+ };
176
+ const finalFocus = () => {
177
+ const control = controlRef.current;
178
+ if (!restoreFocus.current || !control) {
179
+ return false;
180
+ }
181
+ const active = control.ownerDocument.activeElement;
182
+ if (active && active !== control.ownerDocument.body && active !== control && !popupRef.current?.contains(active)) {
183
+ return false;
184
+ }
185
+ return control;
186
+ };
187
+ const runAction = (action) => {
188
+ if (action.disabled || !available()) {
189
+ return false;
190
+ }
191
+ if (action.closeOnAction !== false) {
192
+ flushSync(close);
193
+ focus();
194
+ }
195
+ action.onAction?.();
196
+ return true;
197
+ };
198
+ return {
199
+ open: localOpen && !unavailable,
200
+ popupRef,
201
+ available,
202
+ changeOpen,
203
+ close,
204
+ focus,
205
+ finalFocus,
206
+ runAction
207
+ };
208
+ };
209
+
210
+ // src/shared/search/combobox-options.tsx
211
+ import { overlayListIndicatorStyles, overlayListItemStyles as overlayListItemStyles2, overlayListLabelStyles, useInteractionOutline, useScrollbars } from "@gridui/overlay";
212
+ import { Check } from "lucide-react";
213
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
214
+ var ComboboxOptions = (props) => {
215
+ const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
216
+ const scrollbarRef = useScrollbars();
217
+ const ref = useInteractionOutline({
218
+ ref: scrollbarRef,
219
+ selector: '[role="option"]'
220
+ });
221
+ const renderOption = (option) => {
222
+ const itemId = optionId(option.value);
223
+ const checked = typeof selected === "string" ? selected === option.value : selected.includes(option.value);
224
+ return /* @__PURE__ */ jsxs2(
225
+ "div",
226
+ {
227
+ id: itemId,
228
+ role: "option",
229
+ "aria-selected": checked,
230
+ "aria-disabled": option.disabled,
231
+ "aria-labelledby": `${itemId}-label`,
232
+ "aria-describedby": option.description ? `${itemId}-description` : void 0,
233
+ "data-disabled": option.disabled ? "" : void 0,
234
+ "data-highlighted": active === option.value ? "" : void 0,
235
+ className: overlayListItemStyles2(),
236
+ onPointerMove: () => {
237
+ onHighlight(option.value);
238
+ },
239
+ onPointerDown: (event) => {
240
+ event.preventDefault();
241
+ },
242
+ onClick: () => {
243
+ if (!option.disabled) {
244
+ onSelect(option);
245
+ }
246
+ },
247
+ children: [
248
+ option.icon && /* @__PURE__ */ jsx3(
249
+ "span",
250
+ {
251
+ className: selectIconStyles(),
252
+ "aria-hidden": "true",
253
+ children: option.icon
254
+ }
255
+ ),
256
+ /* @__PURE__ */ jsxs2(
257
+ "span",
258
+ {
259
+ className: selectOptionContentStyles(),
260
+ children: [
261
+ /* @__PURE__ */ jsx3(
262
+ "span",
263
+ {
264
+ id: `${itemId}-label`,
265
+ children: option.label
266
+ }
267
+ ),
268
+ option.description && /* @__PURE__ */ jsx3(
269
+ "span",
270
+ {
271
+ id: `${itemId}-description`,
272
+ className: selectOptionDescriptionStyles(),
273
+ children: option.description
274
+ }
275
+ )
276
+ ]
277
+ }
278
+ ),
279
+ /* @__PURE__ */ jsx3(
280
+ "span",
281
+ {
282
+ className: overlayListIndicatorStyles(),
283
+ "aria-hidden": "true",
284
+ children: checked && /* @__PURE__ */ jsx3(
285
+ Check,
286
+ {
287
+ size: 16
288
+ }
289
+ )
339
290
  }
291
+ )
292
+ ]
293
+ },
294
+ option.value
295
+ );
296
+ };
297
+ return /* @__PURE__ */ jsx3(
298
+ "div",
299
+ {
300
+ ref,
301
+ id,
302
+ role: "listbox",
303
+ "aria-multiselectable": multiple || void 0,
304
+ "aria-label": label,
305
+ className: selectListStyles(),
306
+ children: options.map((entry, index) => {
307
+ return "options" in entry ? /* @__PURE__ */ jsxs2(
308
+ "div",
309
+ {
310
+ role: "group",
311
+ "aria-labelledby": `${id}-group-${index}`,
312
+ children: [
313
+ /* @__PURE__ */ jsx3(
314
+ "div",
315
+ {
316
+ id: `${id}-group-${index}`,
317
+ className: overlayListLabelStyles(),
318
+ children: entry.label
319
+ }
320
+ ),
321
+ entry.options.map(renderOption)
322
+ ]
340
323
  },
341
- onKeyDown: (event) => {
342
- if (event.key === "Escape") {
343
- event.stopPropagation();
344
- }
345
- }
346
- }
347
- )
324
+ entry.label
325
+ ) : renderOption(entry);
326
+ })
348
327
  }
349
328
  );
350
329
  };
@@ -377,7 +356,7 @@ var filterOptions = (options, query) => {
377
356
  });
378
357
  };
379
358
 
380
- // src/shared/scroll-option.ts
359
+ // src/shared/search/scroll-option.ts
381
360
  var scrollOption = (id) => {
382
361
  const option = document.getElementById(id);
383
362
  const list = option?.closest('[role="listbox"]');
@@ -393,20 +372,23 @@ var scrollOption = (id) => {
393
372
  }
394
373
  };
395
374
 
396
- // src/shared/use-search-options.ts
397
- import { useEffect, useState } from "react";
375
+ // src/shared/search/use-search-options.ts
376
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
398
377
  var INITIAL_SEARCH = {
399
378
  query: null,
400
379
  highlighted: null
401
380
  };
402
- var useSearchOptions = (options, selected, listId, open) => {
381
+ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
403
382
  const [
404
383
  search,
405
384
  setSearch
406
- ] = useState(INITIAL_SEARCH);
407
- const query = open ? search.query : null;
385
+ ] = useState2(INITIAL_SEARCH);
386
+ const { query: controlledQuery, onQueryChange, filterOptions: shouldFilter = true, loading, errorLabel } = searchProps;
387
+ const wasOpen = useRef2(open);
388
+ const query = open ? controlledQuery ?? search.query : null;
408
389
  const all = flattenOptions(options);
409
- const filtered = filterOptions(options, query ?? "");
390
+ const availableOptions = shouldFilter ? filterOptions(options, query ?? "") : options;
391
+ const filtered = loading || errorLabel ? [] : availableOptions;
410
392
  const visible = flattenOptions(filtered);
411
393
  const highlighted = visible.find((option) => {
412
394
  return option.value === search.highlighted;
@@ -416,18 +398,27 @@ var useSearchOptions = (options, selected, listId, open) => {
416
398
  }) : void 0;
417
399
  const active = highlighted ?? selectedOption ?? visible[0];
418
400
  const activeValue = active?.value ?? null;
401
+ const optionIndices = new Map(all.map((option, index) => {
402
+ return [
403
+ option.value,
404
+ index
405
+ ];
406
+ }));
419
407
  const optionId = (value) => {
420
- return `${listId}-${all.findIndex((option) => {
421
- return option.value === value;
422
- })}`;
408
+ return `${listId}-${optionIndices.get(value) ?? -1}`;
423
409
  };
424
410
  const activeOptionId = active ? optionId(active.value) : void 0;
425
- useEffect(() => {
426
- if (!open) {
411
+ useEffect2(() => {
412
+ if (!open && wasOpen.current) {
427
413
  setSearch(INITIAL_SEARCH);
414
+ onQueryChange?.("");
428
415
  }
429
- }, [open]);
430
- useEffect(() => {
416
+ wasOpen.current = open;
417
+ }, [
418
+ open,
419
+ onQueryChange
420
+ ]);
421
+ useEffect2(() => {
431
422
  if (open && activeOptionId !== void 0) {
432
423
  scrollOption(activeOptionId);
433
424
  }
@@ -454,6 +445,7 @@ var useSearchOptions = (options, selected, listId, open) => {
454
445
  optionId,
455
446
  highlight,
456
447
  changeQuery: (text) => {
448
+ onQueryChange?.(text);
457
449
  setSearch({
458
450
  query: text,
459
451
  highlighted: null
@@ -471,77 +463,95 @@ var useSearchOptions = (options, selected, listId, open) => {
471
463
  };
472
464
  };
473
465
 
474
- // src/shared/use-selection-popup.ts
475
- import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
466
+ // src/shared/selection-form.tsx
467
+ import { focusInvalidControl, useFormReset } from "@gridui/form";
468
+ import { useLayoutEffect, useRef as useRef3 } from "react";
476
469
  import { flushSync as flushSync2 } from "react-dom";
477
- var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
478
- const [
479
- localOpen,
480
- setLocalOpen
481
- ] = useState2(false);
482
- const popupRef = useRef2(null);
483
- const restoreFocus = useRef2(true);
484
- const unavailable = Boolean(disabled || readOnly);
485
- useEffect2(() => {
486
- if (unavailable) {
487
- setLocalOpen(false);
488
- }
489
- }, [unavailable]);
490
- const available = () => {
491
- return !unavailable && !controlRef.current?.matches(":disabled");
492
- };
493
- const changeOpen = (next) => {
494
- if (next && !available()) {
495
- return;
496
- }
497
- if (next) {
498
- restoreFocus.current = true;
499
- }
500
- setLocalOpen(next);
501
- };
502
- const close = () => {
503
- restoreFocus.current = false;
504
- setLocalOpen(false);
505
- };
506
- const focus = () => {
507
- controlRef.current?.focus();
508
- };
509
- const finalFocus = () => {
510
- const control = controlRef.current;
511
- if (!restoreFocus.current || !control) {
512
- return false;
513
- }
514
- const active = control.ownerDocument.activeElement;
515
- if (active && active !== control.ownerDocument.body && active !== control && !popupRef.current?.contains(active)) {
516
- return false;
517
- }
518
- return control;
519
- };
520
- const runAction = (action) => {
521
- if (action.disabled || !available()) {
522
- return false;
470
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
471
+ var SelectionForm = (props) => {
472
+ const {
473
+ name,
474
+ form,
475
+ required,
476
+ disabled,
477
+ selectedValue,
478
+ allOptions,
479
+ onValueChange,
480
+ onReset,
481
+ onInvalid
482
+ } = props;
483
+ const nativeRef = useRef3(null);
484
+ const resetSelection = useRef3(onReset);
485
+ const currentValue = useRef3(selectedValue);
486
+ useLayoutEffect(() => {
487
+ resetSelection.current = onReset;
488
+ currentValue.current = selectedValue;
489
+ }, [
490
+ onReset,
491
+ selectedValue
492
+ ]);
493
+ useFormReset(nativeRef, () => {
494
+ flushSync2(() => {
495
+ resetSelection.current();
496
+ });
497
+ if (nativeRef.current) {
498
+ nativeRef.current.value = currentValue.current;
523
499
  }
524
- if (action.closeOnAction !== false) {
525
- flushSync2(close);
526
- focus();
500
+ }, form);
501
+ return /* @__PURE__ */ jsxs3(
502
+ "select",
503
+ {
504
+ ref: nativeRef,
505
+ "aria-hidden": "true",
506
+ tabIndex: -1,
507
+ className: "gridui-u-select--sr-only",
508
+ name,
509
+ form,
510
+ required,
511
+ disabled,
512
+ value: selectedValue,
513
+ onChange: (event) => {
514
+ onValueChange(event.currentTarget.value);
515
+ },
516
+ onInvalid: (event) => {
517
+ focusInvalidControl(event, onInvalid);
518
+ },
519
+ children: [
520
+ !allOptions.some((option) => {
521
+ return option.value === "";
522
+ }) && /* @__PURE__ */ jsx4(
523
+ "option",
524
+ {
525
+ value: ""
526
+ }
527
+ ),
528
+ selectedValue !== "" && !allOptions.some((option) => {
529
+ return option.value === selectedValue;
530
+ }) && /* @__PURE__ */ jsx4(
531
+ "option",
532
+ {
533
+ value: selectedValue,
534
+ children: selectedValue
535
+ }
536
+ ),
537
+ allOptions.map((option) => {
538
+ return /* @__PURE__ */ jsx4(
539
+ "option",
540
+ {
541
+ value: option.value,
542
+ disabled: option.disabled,
543
+ children: option.label
544
+ },
545
+ option.value
546
+ );
547
+ })
548
+ ]
527
549
  }
528
- action.onAction?.();
529
- return true;
530
- };
531
- return {
532
- open: localOpen && !unavailable,
533
- popupRef,
534
- available,
535
- changeOpen,
536
- close,
537
- focus,
538
- finalFocus,
539
- runAction
540
- };
550
+ );
541
551
  };
542
552
 
543
553
  // src/shared/use-selection-value.ts
544
- import { useRef as useRef3, useState as useState3 } from "react";
554
+ import { useRef as useRef4, useState as useState3 } from "react";
545
555
  var useSelectionValue = (props, available) => {
546
556
  const { value, defaultValue = "", onValueChange } = props;
547
557
  const [
@@ -549,7 +559,7 @@ var useSelectionValue = (props, available) => {
549
559
  setLocalValue
550
560
  ] = useState3(defaultValue);
551
561
  const selectedValue = value ?? localValue;
552
- const initialValue = useRef3(selectedValue);
562
+ const initialValue = useRef4(selectedValue);
553
563
  const update = (next) => {
554
564
  if (next === selectedValue) {
555
565
  return;
@@ -574,15 +584,16 @@ var useSelectionValue = (props, available) => {
574
584
 
575
585
  // src/combobox/style.ts
576
586
  import { cva as cva2 } from "class-variance-authority";
577
- var comboboxInputStyles = cva2("gridui-u-pr-11 gridui-u-text-ellipsis");
578
- var comboboxTriggerStyles = cva2("gridui-u-absolute gridui-u-inset-y-0 gridui-u-right-0 gridui-u-flex gridui-u-w-9 gridui-u-items-center gridui-u-justify-center gridui-u-rounded-control gridui-u-text-foreground gridui-u-cursor-pointer gridui-u-disabled:cursor-not-allowed gridui-u-disabled:opacity-50");
587
+ var comboboxInputStyles = cva2("gridui-u-select--pr-11 gridui-u-select--text-ellipsis");
588
+ var comboboxTriggerStyles = cva2("gridui-u-select--absolute gridui-u-select--inset-y-0 gridui-u-select--right-0 gridui-u-select--flex gridui-u-select--w-9 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--rounded-control gridui-u-select--text-foreground gridui-u-select--cursor-pointer gridui-u-select--disabled:cursor-not-allowed gridui-u-select--disabled:opacity-50");
579
589
 
580
590
  // src/combobox/combobox.tsx
581
591
  import { controlVariants } from "@gridui/input";
592
+ import { isComposingKeyEvent as isComposingKeyEvent2 } from "@gridui/interaction";
582
593
  import { cn as cn2 } from "@gridui/style-utils";
583
594
  import * as Primitive2 from "@radix-ui/react-popover";
584
595
  import { ChevronDown, X } from "lucide-react";
585
- import { useId, useRef as useRef4 } from "react";
596
+ import { useId, useRef as useRef5 } from "react";
586
597
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
587
598
  var Combobox = (props) => {
588
599
  const {
@@ -607,10 +618,17 @@ var Combobox = (props) => {
607
618
  placeholder,
608
619
  onKeyDown,
609
620
  onClick,
621
+ query: controlledQuery,
622
+ onQueryChange,
623
+ filterOptions: filterOptions2,
624
+ loading,
625
+ loadingLabel,
626
+ errorLabel,
627
+ resultCountLabel,
610
628
  ...restProps
611
629
  } = props;
612
- const controlRef = useRef4(null);
613
- const anchorRef = useRef4(null);
630
+ const controlRef = useRef5(null);
631
+ const anchorRef = useRef5(null);
614
632
  const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
615
633
  disabled,
616
634
  readOnly,
@@ -623,7 +641,13 @@ var Combobox = (props) => {
623
641
  }, available);
624
642
  const inputId = useId();
625
643
  const listId = `${inputId}-list`;
626
- const search = useSearchOptions(options, [selectedValue], listId, open);
644
+ const search = useSearchOptions(options, [selectedValue], listId, open, {
645
+ query: controlledQuery,
646
+ onQueryChange,
647
+ filterOptions: filterOptions2,
648
+ loading,
649
+ errorLabel
650
+ });
627
651
  const { all: allOptions, filtered, visible, query, active, optionId, activeOptionId } = search;
628
652
  const selected = allOptions.find((option) => {
629
653
  return option.value === selectedValue;
@@ -633,7 +657,7 @@ var Combobox = (props) => {
633
657
  changeOpen(true);
634
658
  };
635
659
  const choose = (option) => {
636
- if (option.disabled || !available()) {
660
+ if (option.disabled || loading || errorLabel || !available()) {
637
661
  return;
638
662
  }
639
663
  change(option.value);
@@ -649,7 +673,7 @@ var Combobox = (props) => {
649
673
  /* @__PURE__ */ jsxs4(
650
674
  "div",
651
675
  {
652
- className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-w-full gridui-u-items-stretch gridui-u-gap-gridui-4",
676
+ className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--w-full gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
653
677
  dir,
654
678
  children: [
655
679
  /* @__PURE__ */ jsx5(
@@ -660,7 +684,7 @@ var Combobox = (props) => {
660
684
  "div",
661
685
  {
662
686
  ref: anchorRef,
663
- className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-flex-1 gridui-u-items-stretch",
687
+ className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--items-stretch",
664
688
  children: [
665
689
  /* @__PURE__ */ jsx5(
666
690
  "input",
@@ -681,6 +705,7 @@ var Combobox = (props) => {
681
705
  "aria-label": restProps["aria-label"] ?? (restProps.id ? void 0 : searchLabel),
682
706
  "aria-required": required,
683
707
  "aria-autocomplete": "list",
708
+ "aria-busy": loading || void 0,
684
709
  "aria-expanded": open,
685
710
  "aria-controls": open ? listId : void 0,
686
711
  "aria-activedescendant": open ? activeOptionId : void 0,
@@ -709,7 +734,7 @@ var Combobox = (props) => {
709
734
  if (event.defaultPrevented || readOnly) {
710
735
  return;
711
736
  }
712
- if (event.nativeEvent.isComposing) {
737
+ if (isComposingKeyEvent2(event.nativeEvent)) {
713
738
  if (event.key === "Enter" || event.key === "Escape") {
714
739
  event.stopPropagation();
715
740
  }
@@ -787,7 +812,7 @@ var Combobox = (props) => {
787
812
  close();
788
813
  focus();
789
814
  },
790
- className: cn2(controlVariants({ size: controlSize }), "gridui-u-flex gridui-u-w-auto gridui-u-shrink-0 gridui-u-items-center gridui-u-justify-center gridui-u-min-w-11 gridui-u-cursor-pointer"),
815
+ className: cn2(controlVariants({ size: controlSize }), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
791
816
  children: /* @__PURE__ */ jsx5(
792
817
  X,
793
818
  {
@@ -832,12 +857,13 @@ var Combobox = (props) => {
832
857
  focus();
833
858
  },
834
859
  children: [
835
- visible.length === 0 && /* @__PURE__ */ jsx5(
860
+ /* @__PURE__ */ jsx5(
836
861
  "div",
837
862
  {
838
863
  role: "status",
839
- className: selectEmptyStyles(),
840
- children: emptyLabel
864
+ "aria-atomic": "true",
865
+ className: cn2(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
866
+ children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
841
867
  }
842
868
  ),
843
869
  /* @__PURE__ */ jsx5(
@@ -871,10 +897,11 @@ var Combobox = (props) => {
871
897
  // src/multi-select/multi-select.tsx
872
898
  import { ListFieldControl, useListField } from "@gridui/form";
873
899
  import { controlVariants as controlVariants2 } from "@gridui/input";
900
+ import { isComposingKeyEvent as isComposingKeyEvent3 } from "@gridui/interaction";
874
901
  import { cn as cn3 } from "@gridui/style-utils";
875
902
  import * as Primitive3 from "@radix-ui/react-popover";
876
903
  import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
877
- import { useId as useId2, useRef as useRef5 } from "react";
904
+ import { useId as useId2, useRef as useRef6 } from "react";
878
905
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
879
906
  var MultiSelect = (props) => {
880
907
  const {
@@ -895,9 +922,16 @@ var MultiSelect = (props) => {
895
922
  className,
896
923
  ref,
897
924
  onKeyDown,
925
+ query: controlledQuery,
926
+ onQueryChange,
927
+ filterOptions: filterOptions2,
928
+ loading,
929
+ loadingLabel,
930
+ errorLabel,
931
+ resultCountLabel,
898
932
  ...restProps
899
933
  } = props;
900
- const search = useRef5(null);
934
+ const search = useRef6(null);
901
935
  const id = useId2();
902
936
  const { selected, native, control, change } = useListField({
903
937
  value,
@@ -914,10 +948,16 @@ var MultiSelect = (props) => {
914
948
  readOnly,
915
949
  controlRef: control
916
950
  });
917
- const searchOptions = useSearchOptions(options, selected, `${id}-list`, open);
951
+ const searchOptions = useSearchOptions(options, selected, `${id}-list`, open, {
952
+ query: controlledQuery,
953
+ onQueryChange,
954
+ filterOptions: filterOptions2,
955
+ loading,
956
+ errorLabel
957
+ });
918
958
  const { all, filtered, visible, query, active, optionId, activeOptionId } = searchOptions;
919
959
  const choose = (option) => {
920
- if (option.disabled || !available()) {
960
+ if (option.disabled || loading || errorLabel || !available()) {
921
961
  return;
922
962
  }
923
963
  change(selected.includes(option.value) ? selected.filter((entry) => {
@@ -937,7 +977,7 @@ var MultiSelect = (props) => {
937
977
  /* @__PURE__ */ jsxs5(
938
978
  "div",
939
979
  {
940
- className: "gridui-u-flex gridui-u-min-w-0 gridui-u-items-stretch gridui-u-gap-gridui-4",
980
+ className: "gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
941
981
  dir: restProps.dir,
942
982
  children: [
943
983
  /* @__PURE__ */ jsx6(
@@ -962,7 +1002,7 @@ var MultiSelect = (props) => {
962
1002
  ref.current = element;
963
1003
  }
964
1004
  },
965
- className: cn3(controlVariants2(), "gridui-u-flex gridui-u-flex-1 gridui-u-items-center gridui-u-gap-gridui-8 gridui-u-text-start", className),
1005
+ className: cn3(controlVariants2(), "gridui-u-select--flex gridui-u-select--flex-1 gridui-u-select--items-center gridui-u-select--gap-gridui-8 gridui-u-select--text-start", className),
966
1006
  onKeyDown: (event) => {
967
1007
  onKeyDown?.(event);
968
1008
  if (!event.defaultPrevented && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
@@ -974,7 +1014,7 @@ var MultiSelect = (props) => {
974
1014
  /* @__PURE__ */ jsx6(
975
1015
  "span",
976
1016
  {
977
- className: "gridui-u-min-w-0 gridui-u-flex-1 gridui-u-wrap-anywhere",
1017
+ className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--wrap-anywhere",
978
1018
  children: selected.length ? selected.map((entry) => {
979
1019
  return all.find((option) => {
980
1020
  return option.value === entry;
@@ -1000,7 +1040,7 @@ var MultiSelect = (props) => {
1000
1040
  type: "button",
1001
1041
  "aria-label": clearLabel,
1002
1042
  disabled: disabled || readOnly || required || !selected.length,
1003
- className: cn3(controlVariants2(), "gridui-u-flex gridui-u-w-auto gridui-u-shrink-0 gridui-u-items-center gridui-u-justify-center gridui-u-min-w-11 gridui-u-cursor-pointer"),
1043
+ className: cn3(controlVariants2(), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
1004
1044
  onClick: () => {
1005
1045
  change([]);
1006
1046
  control.current?.focus();
@@ -1084,15 +1124,16 @@ var MultiSelect = (props) => {
1084
1124
  "aria-label": searchLabel,
1085
1125
  "aria-expanded": "true",
1086
1126
  "aria-autocomplete": "list",
1127
+ "aria-busy": loading || void 0,
1087
1128
  "aria-controls": `${id}-list`,
1088
1129
  "aria-activedescendant": activeOptionId,
1089
1130
  value: query ?? "",
1090
- className: cn3(controlVariants2({ size: "small" }), "gridui-u-mb-gridui-4 gridui-u-shrink-0"),
1131
+ className: cn3(controlVariants2({ size: "small" }), "gridui-u-select--m-gridui-8 gridui-u-select--w-auto gridui-u-select--shrink-0"),
1091
1132
  onChange: (event) => {
1092
1133
  searchOptions.changeQuery(event.target.value);
1093
1134
  },
1094
1135
  onKeyDown: (event) => {
1095
- if (event.nativeEvent.isComposing) {
1136
+ if (isComposingKeyEvent3(event.nativeEvent)) {
1096
1137
  event.stopPropagation();
1097
1138
  return;
1098
1139
  }
@@ -1124,12 +1165,13 @@ var MultiSelect = (props) => {
1124
1165
  onHighlight: searchOptions.highlight
1125
1166
  }
1126
1167
  ),
1127
- !visible.length && /* @__PURE__ */ jsx6(
1168
+ /* @__PURE__ */ jsx6(
1128
1169
  "div",
1129
1170
  {
1130
1171
  role: "status",
1131
- className: selectEmptyStyles(),
1132
- children: emptyLabel
1172
+ "aria-atomic": "true",
1173
+ className: cn3(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
1174
+ children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
1133
1175
  }
1134
1176
  )
1135
1177
  ]
@@ -1140,29 +1182,8 @@ var MultiSelect = (props) => {
1140
1182
  );
1141
1183
  };
1142
1184
 
1143
- // src/select/style.ts
1144
- import { overlaySurfaceStyles as overlaySurfaceStyles2 } from "@gridui/overlay";
1145
- import { cn as cn4 } from "@gridui/style-utils";
1146
- import { cva as cva3 } from "class-variance-authority";
1147
- var selectContentStyles = cva3(cn4(
1148
- overlaySurfaceStyles2(),
1149
- "gridui-u-z-(--gridui-z-popover) gridui-u-p-gridui-4 gridui-u-type-data",
1150
- "gridui-select-content gridui-u-box-border gridui-u-relative gridui-u-flex gridui-u-flex-col gridui-u-overflow-hidden gridui-u-min-w-0 gridui-u-w-(--anchor-width) gridui-u-max-w-(--available-width) gridui-u-max-h-(--available-height)"
1151
- ));
1152
- var selectMenuItemStyles = cva3(cn4(selectItemStyles(), "gridui-u-relative gridui-u-px-gridui-4 gridui-u-pr-9"));
1153
- var selectIndicatorStyles = cva3("gridui-u-absolute gridui-u-inset-y-0 gridui-u-right-gridui-4 gridui-u-flex gridui-u-w-gridui-16 gridui-u-items-center gridui-u-justify-center gridui-u-text-foreground");
1154
- var selectScrollArrowStyles = cva3("gridui-u-absolute gridui-u-inset-x-0 gridui-u-z-(--gridui-z-content) gridui-u-flex gridui-u-h-gridui-24 gridui-u-items-center gridui-u-justify-center gridui-u-bg-background gridui-u-text-foreground", {
1155
- variants: {
1156
- direction: {
1157
- up: "gridui-u-top-0",
1158
- down: "gridui-u-bottom-0"
1159
- }
1160
- }
1161
- });
1162
-
1163
1185
  // src/select/select-options.tsx
1164
- import { dropdownLabelStyles as dropdownLabelStyles2 } from "@gridui/dropdown-menu";
1165
- import { useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
1186
+ import { overlayListIndicatorStyles as overlayListIndicatorStyles2, overlayListItemStyles as overlayListItemStyles3, overlayListLabelStyles as overlayListLabelStyles2, useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
1166
1187
  import * as Primitive4 from "@radix-ui/react-select";
1167
1188
  import { Check as Check2 } from "lucide-react";
1168
1189
  import { useId as useId3 } from "react";
@@ -1199,7 +1220,7 @@ var SelectOptions = (props) => {
1199
1220
  /* @__PURE__ */ jsx7(
1200
1221
  Primitive4.Label,
1201
1222
  {
1202
- className: dropdownLabelStyles2(),
1223
+ className: overlayListLabelStyles2(),
1203
1224
  children: entry.label
1204
1225
  }
1205
1226
  ),
@@ -1232,7 +1253,7 @@ var SelectOptionItem = (props) => {
1232
1253
  "aria-describedby": option.description ? descriptionId : void 0,
1233
1254
  textValue: option.label,
1234
1255
  disabled: option.disabled,
1235
- className: selectMenuItemStyles(),
1256
+ className: overlayListItemStyles3(),
1236
1257
  children: [
1237
1258
  option.icon && /* @__PURE__ */ jsx7(
1238
1259
  "span",
@@ -1266,16 +1287,16 @@ var SelectOptionItem = (props) => {
1266
1287
  }
1267
1288
  ),
1268
1289
  /* @__PURE__ */ jsx7(
1269
- Primitive4.ItemIndicator,
1290
+ "span",
1270
1291
  {
1271
- className: selectIndicatorStyles(),
1292
+ className: overlayListIndicatorStyles2(),
1272
1293
  "aria-hidden": "true",
1273
- children: /* @__PURE__ */ jsx7(
1294
+ children: /* @__PURE__ */ jsx7(Primitive4.ItemIndicator, { children: /* @__PURE__ */ jsx7(
1274
1295
  Check2,
1275
1296
  {
1276
1297
  size: 16
1277
1298
  }
1278
- )
1299
+ ) })
1279
1300
  }
1280
1301
  )
1281
1302
  ]
@@ -1283,13 +1304,30 @@ var SelectOptionItem = (props) => {
1283
1304
  );
1284
1305
  };
1285
1306
 
1307
+ // src/select/style.ts
1308
+ import { overlayListStyles as overlayListStyles2 } from "@gridui/overlay";
1309
+ import { cn as cn4 } from "@gridui/style-utils";
1310
+ import { cva as cva3 } from "class-variance-authority";
1311
+ var selectContentStyles = cva3(cn4(
1312
+ overlayListStyles2(),
1313
+ "gridui-select-content gridui-u-select--box-border gridui-u-select--relative gridui-u-select--flex gridui-u-select--flex-col gridui-u-select--overflow-hidden gridui-u-select--min-w-0 gridui-u-select--w-(--anchor-width) gridui-u-select--max-w-(--available-width) gridui-u-select--max-h-(--available-height)"
1314
+ ));
1315
+ var selectScrollArrowStyles = cva3("gridui-u-select--absolute gridui-u-select--inset-x-0 gridui-u-select--z-(--gridui-z-content) gridui-u-select--flex gridui-u-select--h-gridui-24 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--bg-background gridui-u-select--text-foreground", {
1316
+ variants: {
1317
+ direction: {
1318
+ up: "gridui-u-select--top-0",
1319
+ down: "gridui-u-select--bottom-0"
1320
+ }
1321
+ }
1322
+ });
1323
+
1286
1324
  // src/select/select.tsx
1287
1325
  import { controlVariants as controlVariants3 } from "@gridui/input";
1288
1326
  import { interactionLayerProps as interactionLayerProps2 } from "@gridui/overlay";
1289
1327
  import { cn as cn5 } from "@gridui/style-utils";
1290
1328
  import * as Primitive5 from "@radix-ui/react-select";
1291
1329
  import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
1292
- import { useId as useId4, useRef as useRef6, useState as useState4 } from "react";
1330
+ import { useId as useId4, useRef as useRef7, useState as useState4 } from "react";
1293
1331
  import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1294
1332
  var Select = (props) => {
1295
1333
  const {
@@ -1312,7 +1350,7 @@ var Select = (props) => {
1312
1350
  ref,
1313
1351
  ...restProps
1314
1352
  } = props;
1315
- const controlRef = useRef6(null);
1353
+ const controlRef = useRef7(null);
1316
1354
  const {
1317
1355
  open,
1318
1356
  popupRef,
@@ -1363,7 +1401,7 @@ var Select = (props) => {
1363
1401
  /* @__PURE__ */ jsxs7(
1364
1402
  "div",
1365
1403
  {
1366
- className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-w-full gridui-u-items-stretch gridui-u-gap-gridui-4",
1404
+ className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--w-full gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
1367
1405
  dir,
1368
1406
  children: [
1369
1407
  /* @__PURE__ */ jsxs7(
@@ -1382,7 +1420,7 @@ var Select = (props) => {
1382
1420
  ref.current = element;
1383
1421
  }
1384
1422
  },
1385
- className: cn5(controlVariants3({ size: controlSize }), "gridui-u-flex gridui-u-flex-1 gridui-u-items-center gridui-u-gap-gridui-8 gridui-u-text-start", className),
1423
+ className: cn5(controlVariants3({ size: controlSize }), "gridui-u-select--flex gridui-u-select--flex-1 gridui-u-select--items-center gridui-u-select--gap-gridui-8 gridui-u-select--text-start", className),
1386
1424
  children: [
1387
1425
  selected?.icon && /* @__PURE__ */ jsx8(
1388
1426
  "span",
@@ -1395,7 +1433,7 @@ var Select = (props) => {
1395
1433
  /* @__PURE__ */ jsx8(
1396
1434
  "span",
1397
1435
  {
1398
- className: "gridui-u-min-w-0 gridui-u-flex-1 gridui-u-whitespace-normal gridui-u-wrap-anywhere",
1436
+ className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere",
1399
1437
  children: /* @__PURE__ */ jsx8(
1400
1438
  Primitive5.Value,
1401
1439
  {
@@ -1409,7 +1447,7 @@ var Select = (props) => {
1409
1447
  ChevronDown3,
1410
1448
  {
1411
1449
  size: 16,
1412
- className: "gridui-u-shrink-0",
1450
+ className: "gridui-u-select--shrink-0",
1413
1451
  "aria-hidden": "true"
1414
1452
  }
1415
1453
  ) })
@@ -1426,7 +1464,7 @@ var Select = (props) => {
1426
1464
  change("");
1427
1465
  controlRef.current?.focus();
1428
1466
  },
1429
- className: cn5(controlVariants3({ size: controlSize }), "gridui-u-flex gridui-u-w-auto gridui-u-shrink-0 gridui-u-items-center gridui-u-justify-center gridui-u-min-w-11 gridui-u-cursor-pointer"),
1467
+ className: cn5(controlVariants3({ size: controlSize }), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
1430
1468
  children: /* @__PURE__ */ jsx8(
1431
1469
  X3,
1432
1470
  {
@@ -1514,7 +1552,7 @@ var Select = (props) => {
1514
1552
  /* @__PURE__ */ jsxs7(
1515
1553
  "div",
1516
1554
  {
1517
- className: "gridui-u-relative gridui-u-flex gridui-u-min-h-0 gridui-u-flex-col",
1555
+ className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-h-0 gridui-u-select--flex-col",
1518
1556
  children: [
1519
1557
  /* @__PURE__ */ jsx8(
1520
1558
  Primitive5.ScrollUpButton,
@@ -1569,9 +1607,110 @@ var Select = (props) => {
1569
1607
  }
1570
1608
  );
1571
1609
  };
1610
+
1611
+ // src/use-async-options/request.ts
1612
+ var createOptionsRequest = (loadOptions, onState) => {
1613
+ let controller;
1614
+ const cancel = () => {
1615
+ controller?.abort();
1616
+ controller = void 0;
1617
+ };
1618
+ const run = async (query) => {
1619
+ cancel();
1620
+ const current = new AbortController();
1621
+ controller = current;
1622
+ onState({
1623
+ query,
1624
+ options: [],
1625
+ loading: true,
1626
+ error: null
1627
+ });
1628
+ try {
1629
+ const options = await loadOptions(query, current.signal);
1630
+ if (controller === current && !current.signal.aborted) {
1631
+ onState({
1632
+ query,
1633
+ options,
1634
+ loading: false,
1635
+ error: null
1636
+ });
1637
+ }
1638
+ } catch (error) {
1639
+ if (controller === current && !current.signal.aborted) {
1640
+ onState({
1641
+ query,
1642
+ options: [],
1643
+ loading: false,
1644
+ error
1645
+ });
1646
+ }
1647
+ }
1648
+ };
1649
+ return {
1650
+ run,
1651
+ cancel
1652
+ };
1653
+ };
1654
+
1655
+ // src/use-async-options/use-async-options.ts
1656
+ import { useEffect as useEffect3, useState as useState5 } from "react";
1657
+ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true }) => {
1658
+ if (!Number.isFinite(debounceMs) || debounceMs < 0) {
1659
+ throw new RangeError("Option search debounce must be finite and nonnegative.");
1660
+ }
1661
+ const [
1662
+ state,
1663
+ setState
1664
+ ] = useState5({
1665
+ loader: loadOptions,
1666
+ result: {
1667
+ query,
1668
+ options: [],
1669
+ loading: enabled,
1670
+ error: null
1671
+ }
1672
+ });
1673
+ useEffect3(() => {
1674
+ const publish = (result) => {
1675
+ setState({
1676
+ loader: loadOptions,
1677
+ result
1678
+ });
1679
+ };
1680
+ const request = createOptionsRequest(loadOptions, publish);
1681
+ publish({
1682
+ query,
1683
+ options: [],
1684
+ loading: enabled,
1685
+ error: null
1686
+ });
1687
+ if (!enabled) {
1688
+ return request.cancel;
1689
+ }
1690
+ const timer = setTimeout(() => {
1691
+ void request.run(query);
1692
+ }, debounceMs);
1693
+ return () => {
1694
+ clearTimeout(timer);
1695
+ request.cancel();
1696
+ };
1697
+ }, [
1698
+ query,
1699
+ loadOptions,
1700
+ debounceMs,
1701
+ enabled
1702
+ ]);
1703
+ return state.loader === loadOptions && state.result.query === query && enabled ? state.result : {
1704
+ query,
1705
+ options: [],
1706
+ loading: enabled,
1707
+ error: null
1708
+ };
1709
+ };
1572
1710
  export {
1573
1711
  Combobox,
1574
1712
  MultiSelect,
1575
- Select
1713
+ Select,
1714
+ useAsyncOptions
1576
1715
  };
1577
1716
  //# sourceMappingURL=index.js.map