@brightlocal/ui-components 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/combobox.js CHANGED
@@ -1,73 +1,105 @@
1
- import { jsx as a, jsxs as E, Fragment as A } from "react/jsx-runtime";
2
- import * as t from "react";
3
- import { Check as M, ChevronsUpDown as j } from "@brightlocal/icons";
4
- import { cva as O } from "class-variance-authority";
5
- import { defaultFilter as P } from "cmdk";
6
- import { cn as y } from "@brightlocal/ui-components/lib/utils";
7
- import { Popover as _, PopoverContent as G, PopoverTrigger as U } from "@brightlocal/ui-components/popover";
8
- import { Command as $, CommandEmpty as q, CommandGroup as z, CommandInput as D, CommandItem as H, CommandList as B, CommandSeparator as J } from "@brightlocal/ui-components/command";
9
- const F = t.createContext(null);
10
- function I() {
11
- const e = t.useContext(F);
12
- if (!e)
1
+ import { jsx as i, jsxs as G, Fragment as K } from "react/jsx-runtime";
2
+ import * as e from "react";
3
+ import { Check as Y, ChevronsUpDown as Q } from "@brightlocal/icons";
4
+ import { useVirtualizer as X } from "@tanstack/react-virtual";
5
+ import { cva as Z } from "class-variance-authority";
6
+ import { defaultFilter as H } from "cmdk";
7
+ import { cn as M } from "@brightlocal/ui-components/lib/utils";
8
+ import { useDevWarning as W } from "@brightlocal/ui-components/lib/use-dev-warning";
9
+ import { Popover as V, PopoverContent as ee, PopoverTrigger as te } from "@brightlocal/ui-components/popover";
10
+ import { Command as oe, CommandEmpty as re, CommandGroup as ne, CommandInput as ae, CommandItem as se, CommandList as ie, CommandSeparator as ce } from "@brightlocal/ui-components/command";
11
+ const B = e.createContext(null), J = e.createContext(null);
12
+ function z() {
13
+ const t = e.useContext(B);
14
+ if (!t)
13
15
  throw new Error("Combobox components must be used within a <Combobox>");
14
- return e;
16
+ return t;
15
17
  }
16
- function ue({
17
- value: e,
18
+ function Pe({
19
+ value: t,
18
20
  onValueChange: o,
19
21
  open: n,
20
22
  onOpenChange: r,
21
- shouldFilter: u = !0,
22
- disabled: c = !1,
23
- itemToStringValue: s,
24
- children: v
23
+ shouldFilter: l = !0,
24
+ disabled: m = !1,
25
+ itemToStringValue: u,
26
+ children: g
25
27
  }) {
26
- const [b, C] = t.useState(""), [f, h] = t.useState(!1), [g, i] = t.useState(
28
+ const [v, C] = e.useState(""), [L, S] = e.useState(!1), [R, E] = e.useState(
27
29
  () => /* @__PURE__ */ new Map()
28
- ), w = e !== void 0, p = n !== void 0, d = w ? e : b, m = p ? n : f, x = t.useCallback(
29
- (l) => {
30
- p || h(l), r?.(l);
30
+ ), [w, k] = e.useState(""), [h, b] = e.useState(void 0), N = t !== void 0, D = n !== void 0, y = N ? t : v, d = D ? n : L, p = e.useCallback(
31
+ (x) => {
32
+ x || k(""), D || S(x), r?.(x);
31
33
  },
32
- [p, r]
33
- ), k = t.useCallback(
34
- (l) => {
35
- w || C(l), o?.(l);
34
+ [D, r]
35
+ ), P = e.useCallback(
36
+ (x) => {
37
+ N || C(x), o?.(x);
36
38
  },
37
- [w, o]
38
- ), N = t.useCallback((l, L) => {
39
- i((S) => {
40
- if (S.get(l) === L) return S;
41
- const T = new Map(S);
42
- return T.set(l, L), T;
43
- });
44
- }, []), R = t.useMemo(
39
+ [N, o]
40
+ ), a = e.useRef(/* @__PURE__ */ new Map()), I = e.useRef(!1), A = e.useRef(!0);
41
+ e.useEffect(() => () => {
42
+ A.current = !1;
43
+ }, []);
44
+ const $ = e.useCallback(() => {
45
+ I.current || (I.current = !0, queueMicrotask(() => {
46
+ I.current = !1, A.current && E(new Map(a.current));
47
+ }));
48
+ }, []), T = e.useCallback(
49
+ (x, j) => {
50
+ a.current.get(x) !== j && (a.current.set(x, j), $());
51
+ },
52
+ [$]
53
+ ), O = e.useRef(y);
54
+ e.useLayoutEffect(() => {
55
+ O.current = y;
56
+ }, [y]);
57
+ const _ = e.useCallback(
58
+ (x) => {
59
+ x !== O.current && a.current.has(x) && (a.current.delete(x), $());
60
+ },
61
+ [$]
62
+ ), U = e.useMemo(
63
+ () => u ? (x, j, s) => H(u(x), j, s) : H,
64
+ [u]
65
+ ), q = e.useMemo(
45
66
  () => ({
46
- open: m,
47
- setOpen: x,
48
- value: d,
49
- onValueChange: k,
50
- shouldFilter: u,
51
- disabled: c,
52
- itemLabels: g,
53
- registerItem: N,
54
- itemToStringValue: s
67
+ open: d,
68
+ setOpen: p,
69
+ value: y,
70
+ onValueChange: P,
71
+ shouldFilter: l,
72
+ disabled: m,
73
+ itemLabels: R,
74
+ registerItem: T,
75
+ unregisterItem: _,
76
+ itemToStringValue: u,
77
+ filterFn: U,
78
+ searchValue: w,
79
+ setSearchValue: k,
80
+ activeDescendantId: h,
81
+ setActiveDescendantId: b
55
82
  }),
56
83
  [
57
- m,
58
- x,
59
84
  d,
60
- k,
85
+ p,
86
+ y,
87
+ P,
88
+ l,
89
+ m,
90
+ R,
91
+ T,
92
+ _,
61
93
  u,
62
- c,
63
- g,
64
- N,
65
- s
94
+ U,
95
+ w,
96
+ h,
97
+ b
66
98
  ]
67
99
  );
68
- return /* @__PURE__ */ a(F.Provider, { value: R, children: /* @__PURE__ */ a(_, { open: m, onOpenChange: x, children: v }) });
100
+ return /* @__PURE__ */ i(B.Provider, { value: q, children: /* @__PURE__ */ i(V, { open: d, onOpenChange: p, children: g }) });
69
101
  }
70
- const K = O([
102
+ const le = Z([
71
103
  // Base layout
72
104
  "relative flex w-full items-center justify-between gap-2",
73
105
  "px-4 py-2 h-9",
@@ -90,44 +122,44 @@ const K = O([
90
122
  "transition-[background-color,border-color,box-shadow] duration-200 ease-out",
91
123
  // Icon styles
92
124
  "[&_svg]:pointer-events-none [&_svg]:shrink-0"
93
- ]), Q = t.forwardRef(
125
+ ]), ue = e.forwardRef(
94
126
  ({
95
- className: e,
127
+ className: t,
96
128
  dataHook: o,
97
129
  error: n,
98
130
  trackingEl: r,
99
- trackingLabel: u,
100
- children: c,
101
- ...s
102
- }, v) => {
103
- const { open: b, disabled: C, value: f } = I(), h = t.useId(), g = !f, i = n || s["aria-invalid"] === !0 || s["aria-invalid"] === "true";
104
- return /* @__PURE__ */ a(U, { asChild: !0, children: /* @__PURE__ */ E(
131
+ trackingLabel: l,
132
+ children: m,
133
+ ...u
134
+ }, g) => {
135
+ const { open: v, disabled: C, value: L } = z(), S = e.useId(), R = !L, E = n || u["aria-invalid"] === !0 || u["aria-invalid"] === "true";
136
+ return /* @__PURE__ */ i(te, { asChild: !0, children: /* @__PURE__ */ G(
105
137
  "button",
106
138
  {
107
- ref: v,
108
- "aria-controls": b ? h : void 0,
109
- "aria-expanded": b,
139
+ ref: g,
140
+ "aria-controls": v ? S : void 0,
141
+ "aria-expanded": v,
110
142
  "aria-haspopup": "listbox",
111
- "aria-invalid": i ? "true" : void 0,
112
- className: y(
113
- K(),
114
- i && "border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",
115
- e
143
+ "aria-invalid": E ? "true" : void 0,
144
+ className: M(
145
+ le(),
146
+ E && "border-destructive-40 dark:border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",
147
+ t
116
148
  ),
117
149
  "data-hook": o,
118
- "data-placeholder": g,
150
+ "data-placeholder": R,
119
151
  "data-slot": "combobox-trigger",
120
- "data-state": b ? "open" : "closed",
152
+ "data-state": v ? "open" : "closed",
121
153
  "data-tracking-el": r || "combobox-trigger",
122
- "data-tracking-label": u,
123
- disabled: C || s.disabled,
154
+ "data-tracking-label": l,
155
+ disabled: C || u.disabled,
124
156
  role: "combobox",
125
157
  type: "button",
126
- ...s,
158
+ ...u,
127
159
  children: [
128
- c,
129
- /* @__PURE__ */ a(
130
- j,
160
+ m,
161
+ /* @__PURE__ */ i(
162
+ Q,
131
163
  {
132
164
  "aria-hidden": "true",
133
165
  className: "text-muted-foreground ml-auto shrink-0"
@@ -138,90 +170,92 @@ const K = O([
138
170
  ) });
139
171
  }
140
172
  );
141
- Q.displayName = "ComboboxTrigger";
142
- function ce({ placeholder: e, className: o }) {
143
- const { value: n, itemLabels: r } = I(), u = n ? r.get(n) || n : e;
144
- return /* @__PURE__ */ a(
173
+ ue.displayName = "ComboboxTrigger";
174
+ function De({
175
+ placeholder: t,
176
+ className: o,
177
+ displayValue: n
178
+ }) {
179
+ const { value: r, itemLabels: l } = z(), m = r ? l.get(r) || n?.(r) || r : t;
180
+ return /* @__PURE__ */ i(
145
181
  "span",
146
182
  {
147
- className: y(
183
+ className: M(
148
184
  "text-foreground overflow-hidden text-sm leading-normal font-medium text-ellipsis whitespace-nowrap",
149
185
  o
150
186
  ),
151
187
  "data-slot": "combobox-value",
152
- children: u
188
+ children: m
153
189
  }
154
190
  );
155
191
  }
156
- function le({
157
- dataHook: e,
192
+ function Fe({
193
+ dataHook: t,
158
194
  className: o,
159
195
  children: n,
160
196
  align: r = "start",
161
- side: u = "bottom",
162
- sideOffset: c,
163
- avoidCollisions: s,
164
- hideList: v = !1
197
+ side: l = "bottom",
198
+ sideOffset: m,
199
+ avoidCollisions: u,
200
+ hideList: g = !1
165
201
  }) {
166
- const { open: b, shouldFilter: C, itemToStringValue: f } = I(), [h, g] = t.useState(
202
+ const { open: v, shouldFilter: C, filterFn: L, itemToStringValue: S } = z(), [R, E] = e.useState(
167
203
  null
168
- ), i = t.useRef(null), w = t.useCallback((d) => {
169
- if (i.current?.(), i.current = null, !d) return;
170
- let m = !1;
171
- const x = (l) => {
172
- m || (l === "top" || l === "bottom") && (m = !0, k.disconnect(), g(l));
173
- }, k = new MutationObserver(() => {
174
- x(d.getAttribute("data-side"));
204
+ ), w = e.useRef(null), k = e.useCallback((b) => {
205
+ if (w.current?.(), w.current = null, !b) return;
206
+ let N = !1;
207
+ const D = (P) => {
208
+ N || (P === "top" || P === "bottom") && (N = !0, y.disconnect(), E(P));
209
+ }, y = new MutationObserver(() => {
210
+ D(b.getAttribute("data-side"));
175
211
  });
176
- k.observe(d, {
212
+ y.observe(b, {
177
213
  attributes: !0,
178
214
  attributeFilter: ["data-side"]
179
215
  });
180
- let N = 0, R = 0;
181
- N = requestAnimationFrame(() => {
182
- R = requestAnimationFrame(() => {
183
- x(d.getAttribute("data-side"));
216
+ let d = 0, p = 0;
217
+ d = requestAnimationFrame(() => {
218
+ p = requestAnimationFrame(() => {
219
+ D(b.getAttribute("data-side"));
184
220
  });
185
- }), i.current = () => {
186
- m = !0, k.disconnect(), cancelAnimationFrame(N), cancelAnimationFrame(R);
221
+ }), w.current = () => {
222
+ N = !0, y.disconnect(), cancelAnimationFrame(d), cancelAnimationFrame(p);
187
223
  };
188
224
  }, []);
189
- t.useEffect(() => {
190
- if (!b) {
191
- i.current?.(), i.current = null;
192
- const d = setTimeout(() => g(null), 150);
193
- return () => clearTimeout(d);
225
+ e.useEffect(() => {
226
+ if (!v) {
227
+ w.current?.(), w.current = null;
228
+ const b = setTimeout(() => E(null), 150);
229
+ return () => clearTimeout(b);
194
230
  }
195
- }, [b]);
196
- const p = t.useMemo(() => {
197
- if (f)
198
- return (d, m, x) => P(f(d), m, x);
199
- }, [f]);
200
- return /* @__PURE__ */ a(
201
- G,
231
+ }, [v]);
232
+ const h = S ? L : void 0;
233
+ return /* @__PURE__ */ i(
234
+ ee,
202
235
  {
203
- ref: w,
236
+ ref: k,
204
237
  align: r,
205
238
  "aria-label": "Options",
206
- avoidCollisions: s,
207
- className: y(
239
+ avoidCollisions: u,
240
+ className: M(
208
241
  "flex max-h-[var(--radix-popover-content-available-height)] w-[var(--radix-popover-trigger-width)] flex-col overflow-hidden p-0",
209
242
  o
210
243
  ),
244
+ collisionPadding: 4,
211
245
  "data-slot": "combobox-popover",
212
- side: h ?? u,
213
- sideOffset: c,
214
- children: /* @__PURE__ */ a(
215
- $,
246
+ side: R ?? l,
247
+ sideOffset: m,
248
+ children: /* @__PURE__ */ i(
249
+ oe,
216
250
  {
217
- className: y(
251
+ className: M(
218
252
  "min-h-0 flex-1 border-0 shadow-none",
219
253
  "[&_[data-slot='command-input-wrapper']]:shrink-0",
220
- v && "[&_[data-slot='command-input-wrapper']]:border-b-0"
254
+ g && "[&_[data-slot='command-input-wrapper']]:border-b-0"
221
255
  ),
222
256
  "data-slot": "combobox-command",
223
- dataHook: e || "combobox-command",
224
- filter: p,
257
+ dataHook: t || "combobox-command",
258
+ filter: h,
225
259
  shouldFilter: C,
226
260
  children: n
227
261
  }
@@ -229,73 +263,344 @@ function le({
229
263
  }
230
264
  );
231
265
  }
232
- const V = t.forwardRef((e, o) => /* @__PURE__ */ a(D, { ref: o, "data-slot": "combobox-input", ...e }));
233
- V.displayName = "ComboboxInput";
234
- const W = t.forwardRef(({ className: e, ...o }, n) => /* @__PURE__ */ a(
235
- B,
266
+ const de = e.forwardRef(({ debounceMs: t, onValueChange: o, ...n }, r) => {
267
+ const { setSearchValue: l, shouldFilter: m, activeDescendantId: u } = z(), g = e.useRef(
268
+ void 0
269
+ );
270
+ W(
271
+ () => !!(t && t > 0 && m),
272
+ `debounceMs is set on <ComboboxInput> but shouldFilter is true (default).
273
+ Debounce is designed for async/server-driven search where the consumer controls the items list.
274
+ Set shouldFilter={false} on <Combobox> for async search, or remove debounceMs for client-side filtering.`,
275
+ [t, m]
276
+ ), W(
277
+ () => !!(t && t > 0 && n.value !== void 0),
278
+ "debounceMs is set on <ComboboxInput> together with a controlled `value` prop.\nThe debounced onValueChange callback cannot update the controlled value synchronously, so the input will appear to lag behind typing.\nRemove `value` to let the input manage its own display, or remove debounceMs if you need a controlled input.",
279
+ [t, n.value]
280
+ ), e.useEffect(() => () => {
281
+ g.current && clearTimeout(g.current);
282
+ }, []);
283
+ const v = e.useCallback(
284
+ (C) => {
285
+ l(C), t && t > 0 ? (clearTimeout(g.current), g.current = setTimeout(() => {
286
+ o?.(C);
287
+ }, t)) : o?.(C);
288
+ },
289
+ [t, o, l]
290
+ );
291
+ return /* @__PURE__ */ i(
292
+ ae,
293
+ {
294
+ ref: r,
295
+ "aria-activedescendant": u,
296
+ "data-slot": "combobox-input",
297
+ onValueChange: v,
298
+ ...n
299
+ }
300
+ );
301
+ });
302
+ de.displayName = "ComboboxInput";
303
+ const fe = e.forwardRef(({ className: t, ...o }, n) => /* @__PURE__ */ i(
304
+ ie,
236
305
  {
237
306
  ref: n,
238
- className: y("min-h-0 flex-1", e),
307
+ className: M("min-h-0 flex-1", t),
239
308
  "data-slot": "combobox-list",
240
309
  ...o
241
310
  }
242
311
  ));
243
- W.displayName = "ComboboxList";
244
- const X = t.forwardRef((e, o) => /* @__PURE__ */ a(q, { ref: o, "data-slot": "combobox-empty", ...e }));
245
- X.displayName = "ComboboxEmpty";
246
- const Y = t.forwardRef((e, o) => /* @__PURE__ */ a(z, { ref: o, "data-slot": "combobox-group", ...e }));
247
- Y.displayName = "ComboboxGroup";
248
- function Z(e, o, n) {
312
+ fe.displayName = "ComboboxList";
313
+ function me({
314
+ items: t,
315
+ getItemValue: o,
316
+ getItemLabel: n,
317
+ getItemKeywords: r,
318
+ estimateSize: l = 36,
319
+ overscan: m = 5,
320
+ children: u,
321
+ renderEmpty: g,
322
+ className: v,
323
+ dataHook: C
324
+ }, L) {
325
+ const S = e.useRef(null), {
326
+ value: R,
327
+ onValueChange: E,
328
+ setOpen: w,
329
+ shouldFilter: k,
330
+ searchValue: h,
331
+ filterFn: b,
332
+ setActiveDescendantId: N,
333
+ registerItem: D,
334
+ unregisterItem: y
335
+ } = z(), [d, p] = e.useState(0), P = e.useId();
336
+ e.useImperativeHandle(L, () => S.current, []), e.useEffect(() => {
337
+ const s = n ?? o;
338
+ for (const c of t)
339
+ D(o(c), s(c));
340
+ return () => {
341
+ for (const c of t)
342
+ y(o(c));
343
+ };
344
+ }, [t, o, n, D, y]);
345
+ const a = e.useMemo(() => {
346
+ if (!k || !h.trim()) return t;
347
+ const s = [];
348
+ for (const c of t) {
349
+ let f = n ? H(n(c), h) : b(o(c), h);
350
+ if (r)
351
+ for (const F of r(c))
352
+ f = Math.max(f, H(F, h));
353
+ f > 0 && s.push({ item: c, score: f });
354
+ }
355
+ return s.sort((c, f) => f.score - c.score), s.map((c) => c.item);
356
+ }, [
357
+ t,
358
+ k,
359
+ h,
360
+ o,
361
+ n,
362
+ r,
363
+ b
364
+ ]), I = X({
365
+ count: a.length,
366
+ getScrollElement: () => S.current,
367
+ estimateSize: () => l,
368
+ overscan: m
369
+ }), A = d >= 0 && d < a.length ? o(a[d]) : null;
370
+ e.useEffect(() => {
371
+ p(0);
372
+ }, [h, a.length]);
373
+ const $ = e.useRef(!1);
374
+ e.useEffect(() => {
375
+ if ($.current || !R) return;
376
+ const s = a.findIndex((c) => o(c) === R);
377
+ s >= 0 && (p(s), I.scrollToIndex(s, { align: "center" }), $.current = !0);
378
+ }, [R, a, o, I]);
379
+ const T = e.useRef(!1);
380
+ e.useEffect(() => {
381
+ T.current && d >= 0 && d < a.length && I.scrollToIndex(d, { align: "auto" }), T.current = !1;
382
+ }, [d, a.length, I]), e.useEffect(() => {
383
+ const s = S.current?.closest(
384
+ '[data-slot="combobox-command"]'
385
+ );
386
+ if (!s) return;
387
+ const c = (f) => {
388
+ switch (f.key) {
389
+ case "ArrowDown":
390
+ f.preventDefault(), f.stopPropagation(), T.current = !0, p(
391
+ (F) => F < a.length - 1 ? F + 1 : F
392
+ );
393
+ break;
394
+ case "ArrowUp":
395
+ f.preventDefault(), f.stopPropagation(), T.current = !0, p((F) => F > 0 ? F - 1 : F);
396
+ break;
397
+ case "Enter":
398
+ if (f.preventDefault(), f.stopPropagation(), d >= 0 && d < a.length) {
399
+ const F = o(a[d]);
400
+ E(F === R ? "" : F), w(!1);
401
+ }
402
+ break;
403
+ case "Home":
404
+ f.preventDefault(), f.stopPropagation(), T.current = !0, p(0);
405
+ break;
406
+ case "End":
407
+ f.preventDefault(), f.stopPropagation(), T.current = !0, p(a.length - 1);
408
+ break;
409
+ }
410
+ };
411
+ return s.addEventListener("keydown", c, { capture: !0 }), () => s.removeEventListener("keydown", c, { capture: !0 });
412
+ }, [a, d, R, E, w, o]);
413
+ const O = e.useMemo(() => {
414
+ const s = /* @__PURE__ */ new Map();
415
+ return a.forEach((c, f) => {
416
+ s.set(o(c), f);
417
+ }), s;
418
+ }, [a, o]), _ = e.useCallback(
419
+ (s) => {
420
+ const c = O.get(s);
421
+ c !== void 0 && p(c);
422
+ },
423
+ [O]
424
+ ), U = e.useCallback(
425
+ (s) => (O.get(s) ?? 0) + 1,
426
+ [O]
427
+ ), q = a.length, x = e.useMemo(
428
+ () => ({
429
+ activeValue: A,
430
+ onItemPointerMove: _,
431
+ idPrefix: P,
432
+ filteredCount: q,
433
+ getItemPosition: U
434
+ }),
435
+ [A, _, P, q, U]
436
+ ), j = A != null ? `${P}item-${A}` : void 0;
437
+ return e.useEffect(() => (N(j), () => N(void 0)), [j, N]), a.length === 0 ? /* @__PURE__ */ i(
438
+ "div",
439
+ {
440
+ ref: S,
441
+ className: M(
442
+ "max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
443
+ v
444
+ ),
445
+ "data-hook": C,
446
+ "data-slot": "combobox-virtual-list",
447
+ role: "listbox",
448
+ children: g
449
+ }
450
+ ) : /* @__PURE__ */ i(J.Provider, { value: x, children: /* @__PURE__ */ i(
451
+ "div",
452
+ {
453
+ ref: S,
454
+ className: M(
455
+ "max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
456
+ v
457
+ ),
458
+ "data-hook": C,
459
+ "data-slot": "combobox-virtual-list",
460
+ role: "listbox",
461
+ children: /* @__PURE__ */ i(
462
+ "div",
463
+ {
464
+ className: "relative w-full",
465
+ style: { height: `${I.getTotalSize()}px` },
466
+ children: I.getVirtualItems().map((s) => /* @__PURE__ */ i(
467
+ "div",
468
+ {
469
+ ref: I.measureElement,
470
+ className: "absolute top-0 left-0 w-full px-2",
471
+ "data-index": s.index,
472
+ style: {
473
+ transform: `translateY(${s.start}px)`
474
+ },
475
+ children: u(
476
+ a[s.index],
477
+ s.index,
478
+ h
479
+ )
480
+ },
481
+ s.key
482
+ ))
483
+ }
484
+ )
485
+ }
486
+ ) });
487
+ }
488
+ const Le = e.forwardRef(me), be = e.forwardRef((t, o) => /* @__PURE__ */ i(re, { ref: o, "data-slot": "combobox-empty", ...t }));
489
+ be.displayName = "ComboboxEmpty";
490
+ const pe = e.forwardRef(({ children: t, ...o }, n) => {
491
+ const r = e.useRef(null);
492
+ return W(
493
+ () => r.current ? r.current.querySelectorAll('[data-slot="combobox-item"]').length >= 100 : !1,
494
+ `ComboboxGroup contains 100+ items. Use <ComboboxVirtualList> for large datasets to avoid DOM bloat and slow renders.
495
+ Import: import { ComboboxVirtualList } from "@brightlocal/ui-components/combobox"`,
496
+ [t]
497
+ ), /* @__PURE__ */ i(
498
+ ne,
499
+ {
500
+ ref: (l) => {
501
+ r.current = l, typeof n == "function" ? n(l) : n && (n.current = l);
502
+ },
503
+ "data-slot": "combobox-group",
504
+ ...o,
505
+ children: t
506
+ }
507
+ );
508
+ });
509
+ pe.displayName = "ComboboxGroup";
510
+ function xe(t, o, n) {
249
511
  if (!o || !o.trim())
250
- return e;
512
+ return t;
251
513
  const r = new RegExp(
252
514
  `(${o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
253
515
  "gi"
254
- ), u = e.split(r);
255
- return /* @__PURE__ */ a("span", { children: u.map(
256
- (c, s) => s % 2 === 1 ? /* @__PURE__ */ a("span", { className: n, children: c }, s) : /* @__PURE__ */ a(t.Fragment, { children: c }, s)
516
+ ), l = t.split(r);
517
+ return /* @__PURE__ */ i("span", { children: l.map(
518
+ (m, u) => u % 2 === 1 ? /* @__PURE__ */ i("span", { className: n, children: m }, u) : /* @__PURE__ */ i(e.Fragment, { children: m }, u)
257
519
  ) });
258
520
  }
259
- const ee = t.forwardRef(
521
+ const ve = e.forwardRef(
260
522
  ({
261
- value: e,
523
+ value: t,
262
524
  label: o,
263
525
  dataHook: n,
264
526
  children: r,
265
- className: u,
266
- highlight: c,
267
- highlightClassName: s,
268
- keywords: v,
269
- ...b
527
+ className: l,
528
+ highlight: m,
529
+ highlightClassName: u,
530
+ keywords: g,
531
+ ...v
270
532
  }, C) => {
271
- const { value: f, onValueChange: h, setOpen: g, registerItem: i } = I(), w = f === e, p = t.useMemo(() => o || (typeof r == "string" ? r : typeof r == "number" ? String(r) : e), [o, r, e]), d = t.useRef(i);
272
- t.useEffect(() => {
273
- d.current = i;
274
- }, [i]), t.useEffect(() => {
275
- d.current(e, p);
276
- }, [e, p]);
277
- const m = () => {
278
- h(e === f ? "" : e), g(!1);
279
- }, x = () => c && typeof r == "string" ? Z(
533
+ const { value: L, onValueChange: S, setOpen: R, registerItem: E, unregisterItem: w } = z(), k = e.useContext(J), h = L === t, b = e.useMemo(() => o || (typeof r == "string" ? r : typeof r == "number" ? String(r) : t), [o, r, t]), N = e.useRef(E), D = e.useRef(w);
534
+ e.useEffect(() => {
535
+ N.current = E, D.current = w;
536
+ }, [E, w]);
537
+ const y = !!k;
538
+ e.useEffect(() => {
539
+ if (!y)
540
+ return N.current(t, b), () => D.current(t);
541
+ }, [t, b, y]);
542
+ const d = () => {
543
+ S(t === L ? "" : t), R(!1);
544
+ }, p = () => m && typeof r == "string" ? xe(
280
545
  r,
281
- c,
282
- s || "text-sm leading-normal font-semibold"
546
+ m,
547
+ u || "text-sm leading-normal font-semibold"
283
548
  ) : r;
284
- return /* @__PURE__ */ E(
285
- H,
549
+ if (k) {
550
+ const P = k.activeValue === t, a = !!v.disabled;
551
+ return /* @__PURE__ */ G(
552
+ "div",
553
+ {
554
+ ref: C,
555
+ "aria-disabled": a || void 0,
556
+ "aria-posinset": k.getItemPosition(t),
557
+ "aria-selected": h,
558
+ "aria-setsize": k.filteredCount,
559
+ className: M(
560
+ "data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground relative flex cursor-default items-center justify-between gap-2 rounded-sm px-2 py-3 text-sm outline-hidden select-none",
561
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
562
+ a && "pointer-events-none opacity-50",
563
+ l
564
+ ),
565
+ "data-highlighted": P || void 0,
566
+ "data-hook": n,
567
+ "data-slot": "combobox-item",
568
+ id: `${k.idPrefix}item-${t}`,
569
+ role: "option",
570
+ tabIndex: -1,
571
+ onClick: a ? void 0 : d,
572
+ onKeyDown: a ? void 0 : (I) => {
573
+ (I.key === "Enter" || I.key === " ") && d();
574
+ },
575
+ onPointerMove: a ? void 0 : () => k.onItemPointerMove(t),
576
+ children: [
577
+ p(),
578
+ h && /* @__PURE__ */ i(
579
+ Y,
580
+ {
581
+ "aria-hidden": "true",
582
+ className: "text-muted-foreground shrink-0"
583
+ }
584
+ )
585
+ ]
586
+ }
587
+ );
588
+ }
589
+ return /* @__PURE__ */ G(
590
+ se,
286
591
  {
287
592
  ref: C,
288
- className: y("justify-between", u),
593
+ className: M("justify-between", l),
289
594
  "data-slot": "combobox-item",
290
595
  dataHook: n,
291
- keywords: v ? [p, ...v] : [p],
292
- value: e,
293
- onSelect: m,
294
- ...b,
596
+ keywords: g ? [b, ...g] : [b],
597
+ value: t,
598
+ onSelect: d,
599
+ ...v,
295
600
  children: [
296
- x(),
297
- w && /* @__PURE__ */ a(
298
- M,
601
+ p(),
602
+ h && /* @__PURE__ */ i(
603
+ Y,
299
604
  {
300
605
  "aria-hidden": "true",
301
606
  className: "text-muted-foreground shrink-0"
@@ -306,23 +611,22 @@ const ee = t.forwardRef(
306
611
  );
307
612
  }
308
613
  );
309
- ee.displayName = "ComboboxItem";
310
- const oe = t.forwardRef((e, o) => /* @__PURE__ */ a(J, { ref: o, "data-slot": "combobox-separator", ...e }));
311
- oe.displayName = "ComboboxSeparator";
312
- function me({ className: e, children: o }) {
313
- return /* @__PURE__ */ a(
614
+ ve.displayName = "ComboboxItem";
615
+ const he = e.forwardRef((t, o) => /* @__PURE__ */ i(ce, { ref: o, "data-slot": "combobox-separator", ...t }));
616
+ he.displayName = "ComboboxSeparator";
617
+ function Me({ className: t, children: o }) {
618
+ return /* @__PURE__ */ i(
314
619
  "div",
315
620
  {
316
- "aria-disabled": "true",
317
- "aria-selected": "false",
318
- className: y(
621
+ "aria-live": "polite",
622
+ className: M(
319
623
  "text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",
320
- e
624
+ t
321
625
  ),
322
626
  "data-slot": "combobox-loading",
323
- role: "option",
324
- children: o || /* @__PURE__ */ E(A, { children: [
325
- /* @__PURE__ */ a(
627
+ role: "status",
628
+ children: o || /* @__PURE__ */ G(K, { children: [
629
+ /* @__PURE__ */ i(
326
630
  "div",
327
631
  {
328
632
  "aria-hidden": "true",
@@ -335,15 +639,16 @@ function me({ className: e, children: o }) {
335
639
  );
336
640
  }
337
641
  export {
338
- ue as Combobox,
339
- le as ComboboxContent,
340
- X as ComboboxEmpty,
341
- Y as ComboboxGroup,
342
- V as ComboboxInput,
343
- ee as ComboboxItem,
344
- W as ComboboxList,
345
- me as ComboboxLoading,
346
- oe as ComboboxSeparator,
347
- Q as ComboboxTrigger,
348
- ce as ComboboxValue
642
+ Pe as Combobox,
643
+ Fe as ComboboxContent,
644
+ be as ComboboxEmpty,
645
+ pe as ComboboxGroup,
646
+ de as ComboboxInput,
647
+ ve as ComboboxItem,
648
+ fe as ComboboxList,
649
+ Me as ComboboxLoading,
650
+ he as ComboboxSeparator,
651
+ ue as ComboboxTrigger,
652
+ De as ComboboxValue,
653
+ Le as ComboboxVirtualList
349
654
  };