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