@brightlocal/ui-components 2.7.0 → 2.9.0

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