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