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