saha-ui 1.22.9 → 1.22.10

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.
@@ -1,63 +1,96 @@
1
- import { jsx as e, jsxs as h, Fragment as Oe } from "react/jsx-runtime";
2
- import { createContext as Ae, forwardRef as L, useState as O, useRef as $, useEffect as B, useCallback as Ve, useContext as T } from "react";
3
- import { createPortal as oe } from "react-dom";
4
- import { cn as d } from "../../lib/utils.js";
5
- import { useClickOutside as Le } from "../../hooks/useClickOutside.js";
6
- import { X as ie, ChevronDown as ce, Search as Pe, Check as de } from "lucide-react";
7
- import { selectTriggerVariants as ue, selectOptionVariants as M, selectMenuVariants as fe } from "./Select.styles.js";
8
- const P = Ae({}), pe = L(
1
+ import { jsx as e, jsxs as b, Fragment as Le } from "react/jsx-runtime";
2
+ import { createContext as Ve, forwardRef as D, useState as L, useRef as I, useCallback as O, useEffect as M, useContext as J } from "react";
3
+ import { createPortal as me } from "react-dom";
4
+ import { cn as p } from "../../lib/utils.js";
5
+ import { useClickOutside as Re } from "../../hooks/useClickOutside.js";
6
+ import { X as pe, ChevronDown as he, Search as Ie, Check as ge } from "lucide-react";
7
+ import { selectTriggerVariants as ye, selectOptionVariants as ae, selectMenuVariants as we } from "./Select.styles.js";
8
+ const U = Ve({
9
+ items: /* @__PURE__ */ new Map(),
10
+ registerItem: () => {
11
+ },
12
+ unregisterItem: () => {
13
+ },
14
+ triggerRef: null
15
+ }), ve = D(
9
16
  ({
10
- value: r,
11
- defaultValue: u,
12
- onValueChange: o,
13
- open: l,
14
- defaultOpen: s,
15
- onOpenChange: n,
16
- disabled: p = !1,
17
- variant: v = "default",
18
- size: m = "md",
19
- children: b,
20
- className: N,
21
- multiple: f = !1,
22
- closeOnSelect: S = !0,
23
- clearable: q = !1,
24
- name: y
25
- }, D) => {
26
- const [U, A] = O(u || (f ? [] : "")), [X, F] = O(
27
- s || !1
28
- ), w = r !== void 0 ? r : U, V = l !== void 0 ? l : X, G = f ? !1 : S, E = (g) => {
29
- r === void 0 && A(g), o?.(g);
30
- }, z = (g) => {
31
- l === void 0 && F(g), n?.(g);
32
- };
17
+ value: t,
18
+ defaultValue: o,
19
+ onValueChange: g,
20
+ open: n,
21
+ defaultOpen: h,
22
+ onOpenChange: v,
23
+ disabled: d = !1,
24
+ variant: u = "default",
25
+ size: f = "md",
26
+ children: i,
27
+ className: c,
28
+ multiple: s = !1,
29
+ closeOnSelect: y = !0,
30
+ clearable: k = !1,
31
+ name: x
32
+ }, X) => {
33
+ const [V, N] = L(o || (s ? [] : "")), [B, K] = L(
34
+ h || !1
35
+ ), [Z, E] = L(/* @__PURE__ */ new Map()), _ = I(null), C = t !== void 0 ? t : V, F = n !== void 0 ? n : B, G = s ? !1 : y, P = O(
36
+ (w) => {
37
+ t === void 0 && N(w), g?.(w);
38
+ },
39
+ [t, g]
40
+ ), Q = O(
41
+ (w) => {
42
+ n === void 0 && K(w), v?.(w);
43
+ },
44
+ [n, v]
45
+ ), W = O(
46
+ (w, z) => {
47
+ E((j) => {
48
+ const $ = new Map(j);
49
+ return $.set(w, z), $;
50
+ });
51
+ },
52
+ []
53
+ ), ee = O((w) => {
54
+ E((z) => {
55
+ const j = new Map(z);
56
+ return j.delete(w), j;
57
+ });
58
+ }, []), te = O(
59
+ (w) => {
60
+ w.stopPropagation(), P(s ? [] : "");
61
+ },
62
+ [s, P]
63
+ ), Y = s ? Array.isArray(C) && C.length > 0 : !!C;
33
64
  return /* @__PURE__ */ e(
34
- P.Provider,
65
+ U.Provider,
35
66
  {
36
67
  value: {
37
- value: w,
38
- onValueChange: E,
39
- open: V,
40
- onOpenChange: z,
41
- disabled: p,
42
- variant: v,
43
- size: m,
44
- multiple: f,
45
- closeOnSelect: G
68
+ value: C,
69
+ onValueChange: P,
70
+ open: F,
71
+ onOpenChange: Q,
72
+ disabled: d,
73
+ variant: u,
74
+ size: f,
75
+ multiple: s,
76
+ closeOnSelect: G,
77
+ items: Z,
78
+ registerItem: W,
79
+ unregisterItem: ee,
80
+ triggerRef: _
46
81
  },
47
- children: /* @__PURE__ */ h("div", { ref: D, className: d("relative", N), children: [
48
- b,
49
- y && f && Array.isArray(w) && w.map((g) => /* @__PURE__ */ e("input", { type: "hidden", name: y, value: g }, g)),
50
- y && !f && w && /* @__PURE__ */ e("input", { type: "hidden", name: y, value: String(w) }),
51
- q && !p && (f ? Array.isArray(w) && w.length > 0 : !!w) && /* @__PURE__ */ e(
82
+ children: /* @__PURE__ */ b("div", { ref: X, className: p("relative", c), children: [
83
+ i,
84
+ x && s && Array.isArray(C) && C.map((w) => /* @__PURE__ */ e("input", { type: "hidden", name: x, value: w }, w)),
85
+ x && !s && C && /* @__PURE__ */ e("input", { type: "hidden", name: x, value: String(C) }),
86
+ k && !d && Y && /* @__PURE__ */ e(
52
87
  "button",
53
88
  {
54
89
  type: "button",
55
- onClick: (g) => {
56
- g.stopPropagation(), E(f ? [] : "");
57
- },
58
- className: "absolute right-10 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-foreground/10 transition-colors",
90
+ onClick: te,
91
+ className: "absolute right-10 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-foreground/10 transition-colors z-10",
59
92
  "aria-label": "Clear selection",
60
- children: /* @__PURE__ */ e(ie, { className: "w-4 h-4" })
93
+ children: /* @__PURE__ */ e(pe, { className: "w-4 h-4" })
61
94
  }
62
95
  )
63
96
  ] })
@@ -65,282 +98,289 @@ const P = Ae({}), pe = L(
65
98
  );
66
99
  }
67
100
  );
68
- pe.displayName = "SelectComposable";
69
- const me = L(
70
- (r, u) => {
101
+ ve.displayName = "SelectComposable";
102
+ const xe = D(
103
+ (t, o) => {
71
104
  const {
72
- label: o,
73
- description: l,
74
- placeholder: s = "Select an option...",
75
- error: n,
76
- helperText: p,
77
- value: v,
78
- defaultValue: m,
79
- onChange: b,
80
- options: N,
81
- multiple: f = !1,
82
- searchable: S = !1,
83
- clearable: q = !1,
84
- disabled: y = !1,
85
- required: D = !1,
86
- loading: U = !1,
87
- variant: A = "default",
88
- size: X = "md",
89
- fullWidth: F = !0,
90
- maxHeight: w = "300px",
91
- maxSelections: V,
92
- closeOnSelect: G = !0,
93
- showCheckmarks: E = !0,
94
- creatable: z = !1,
95
- onCreateOption: g,
96
- renderOption: Q,
97
- renderValue: J,
98
- icon: K,
99
- clearIcon: he,
100
- dropdownIcon: ve,
101
- name: Z,
102
- id: _,
103
- className: ge,
104
- menuClassName: ye,
105
- optionClassName: ee
106
- } = r, [x, j] = O(!1), [C, W] = O(""), [be, te] = O(m || (f ? [] : "")), [I, we] = O({
105
+ label: g,
106
+ description: n,
107
+ placeholder: h = "Select an option...",
108
+ error: v,
109
+ helperText: d,
110
+ value: u,
111
+ defaultValue: f,
112
+ onChange: i,
113
+ options: c = [],
114
+ multiple: s = !1,
115
+ searchable: y = !1,
116
+ clearable: k = !1,
117
+ disabled: x = !1,
118
+ required: X = !1,
119
+ loading: V = !1,
120
+ variant: N = "default",
121
+ size: B = "md",
122
+ fullWidth: K = !0,
123
+ maxHeight: Z = "300px",
124
+ maxSelections: E,
125
+ closeOnSelect: _ = !0,
126
+ showCheckmarks: C = !0,
127
+ creatable: F = !1,
128
+ onCreateOption: G,
129
+ renderOption: P,
130
+ renderValue: Q,
131
+ icon: W,
132
+ clearIcon: ee,
133
+ dropdownIcon: te,
134
+ name: Y,
135
+ id: w,
136
+ className: z,
137
+ menuClassName: j,
138
+ optionClassName: $
139
+ } = t, [S, q] = L(!1), [A, re] = L(""), [be, le] = L(f || (s ? [] : "")), [H, Ne] = L({
107
140
  top: 0,
108
141
  left: 0,
109
142
  width: 0
110
- }), re = f ? !1 : G, R = v !== void 0, c = R ? v : be, ne = $(null), Y = $(null), H = $(null);
111
- Le(ne, () => {
112
- x && j(!1);
113
- }), B(() => {
114
- x && S && H.current && H.current.focus();
115
- }, [x, S]), B(() => {
116
- if (x && Y.current) {
117
- const t = () => {
118
- const i = Y.current?.getBoundingClientRect();
119
- i && we({
120
- top: i.bottom + window.scrollY,
121
- left: i.left + window.scrollX,
122
- width: i.width
143
+ }), oe = s ? !1 : _, T = u !== void 0, m = T ? u : be, ie = I(null), ne = I(null), se = I(null), ce = I(null);
144
+ Re(
145
+ ie,
146
+ () => {
147
+ S && q(!1);
148
+ },
149
+ [ce]
150
+ ), M(() => {
151
+ S && y && se.current && se.current.focus();
152
+ }, [S, y]), M(() => {
153
+ if (S && ne.current) {
154
+ const r = () => {
155
+ const l = ne.current?.getBoundingClientRect();
156
+ l && Ne({
157
+ top: l.bottom + window.scrollY,
158
+ left: l.left + window.scrollX,
159
+ width: l.width
123
160
  });
124
161
  };
125
- return t(), window.addEventListener("scroll", t, !0), window.addEventListener("resize", t), () => {
126
- window.removeEventListener("scroll", t, !0), window.removeEventListener("resize", t);
162
+ return r(), window.addEventListener("scroll", r, !0), window.addEventListener("resize", r), () => {
163
+ window.removeEventListener("scroll", r, !0), window.removeEventListener("resize", r);
127
164
  };
128
165
  }
129
- }, [x]);
130
- const ae = C ? N.filter(
131
- (t) => t.label.toLowerCase().includes(C.toLowerCase()) || t.description?.toLowerCase().includes(C.toLowerCase())
132
- ) : N, xe = ae.reduce(
133
- (t, i) => {
134
- const a = i.group || "default";
135
- return t[a] || (t[a] = []), t[a].push(i), t;
166
+ }, [S]);
167
+ const de = A ? c.filter(
168
+ (r) => r.label.toLowerCase().includes(A.toLowerCase()) || r.description?.toLowerCase().includes(A.toLowerCase())
169
+ ) : c, Ce = de.reduce(
170
+ (r, l) => {
171
+ const a = l.group || "default";
172
+ return r[a] || (r[a] = []), r[a].push(l), r;
136
173
  },
137
174
  {}
138
- ), le = Ve(
139
- (t) => {
140
- if (y) return;
141
- let i;
142
- if (f) {
143
- const a = Array.isArray(c) ? c : [];
144
- if (a.includes(t))
145
- i = a.filter((k) => k !== t);
175
+ ), ue = O(
176
+ (r) => {
177
+ if (x) return;
178
+ let l;
179
+ if (s) {
180
+ const a = Array.isArray(m) ? m : [];
181
+ if (a.includes(r))
182
+ l = a.filter((R) => R !== r);
146
183
  else {
147
- if (V && a.length >= V)
184
+ if (E && a.length >= E)
148
185
  return;
149
- i = [...a, t];
186
+ l = [...a, r];
150
187
  }
151
188
  } else
152
- i = t, re && j(!1);
153
- R || te(i), b?.(i), S && W("");
189
+ l = r, oe && q(!1);
190
+ T || le(l), i && i(l), y && re("");
154
191
  },
155
192
  [
156
- y,
157
- f,
158
- c,
159
- V,
160
- re,
161
- R,
162
- b,
163
- S
193
+ x,
194
+ s,
195
+ m,
196
+ E,
197
+ oe,
198
+ T,
199
+ i,
200
+ y
164
201
  ]
165
- ), Ne = (t) => {
166
- t.stopPropagation();
167
- const i = f ? [] : "";
168
- R || te(i), b?.(i);
169
- }, Ce = () => {
170
- z && C && g && (g(C), W(""), j(!1));
171
- }, Se = (t) => f && Array.isArray(c) ? c.includes(t) : c === t, ke = () => {
172
- if (J)
173
- return J(c);
174
- if (f && Array.isArray(c) && c.length > 0) {
175
- const t = N.filter(
176
- (i) => c.includes(i.value)
202
+ ), Se = O(
203
+ (r) => {
204
+ r.stopPropagation();
205
+ const l = s ? [] : "";
206
+ T || le(l), i && i(l);
207
+ },
208
+ [s, T, i]
209
+ ), ke = () => {
210
+ F && A && G && (G(A), re(""), q(!1));
211
+ }, Ae = (r) => s && Array.isArray(m) ? m.includes(r) : m === r, Oe = () => {
212
+ if (Q)
213
+ return Q(m);
214
+ if (s && Array.isArray(m) && m.length > 0) {
215
+ const r = c.filter(
216
+ (l) => m.includes(l.value)
177
217
  );
178
- return t.length === 1 ? t[0].label : `${t.length} selected`;
218
+ return r.length === 1 ? r[0].label : `${r.length} selected`;
179
219
  }
180
- return !f && c ? N.find(
181
- (i) => i.value === c
182
- )?.label || c : s;
183
- }, se = f ? Array.isArray(c) && c.length > 0 : !!c;
184
- return /* @__PURE__ */ h("div", { ref: u, className: d("flex flex-col gap-2", ge), children: [
185
- (o || l) && /* @__PURE__ */ h("div", { className: "flex flex-col gap-1", children: [
186
- o && /* @__PURE__ */ e(
220
+ return !s && m ? c.find(
221
+ (l) => l.value === m
222
+ )?.label || m : h;
223
+ }, fe = s ? Array.isArray(m) && m.length > 0 : !!m;
224
+ return /* @__PURE__ */ b("div", { ref: o, className: p("flex flex-col gap-2", z), children: [
225
+ (g || n) && /* @__PURE__ */ b("div", { className: "flex flex-col gap-1", children: [
226
+ g && /* @__PURE__ */ e(
187
227
  "label",
188
228
  {
189
- htmlFor: _,
190
- className: d(
229
+ htmlFor: w,
230
+ className: p(
191
231
  "text-sm font-semibold text-foreground",
192
- D && "after:content-['*'] after:ml-1 after:text-destructive"
232
+ X && "after:content-['*'] after:ml-1 after:text-destructive"
193
233
  ),
194
- children: o
234
+ children: g
195
235
  }
196
236
  ),
197
- l && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: l })
237
+ n && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: n })
198
238
  ] }),
199
- /* @__PURE__ */ h("div", { ref: ne, className: "relative", children: [
200
- /* @__PURE__ */ h(
239
+ /* @__PURE__ */ b("div", { ref: ie, className: "relative", children: [
240
+ /* @__PURE__ */ b(
201
241
  "button",
202
242
  {
203
- ref: Y,
243
+ ref: ne,
204
244
  type: "button",
205
- id: _,
206
- onClick: () => !y && j(!x),
207
- className: d(
208
- ue({
209
- variant: A,
210
- size: X,
211
- error: !!n,
212
- fullWidth: F
245
+ id: w,
246
+ onClick: () => !x && q(!S),
247
+ className: p(
248
+ ye({
249
+ variant: N,
250
+ size: B,
251
+ error: !!v,
252
+ fullWidth: K
213
253
  })
214
254
  ),
215
- disabled: y,
255
+ disabled: x,
216
256
  "aria-haspopup": "listbox",
217
- "aria-expanded": x,
257
+ "aria-expanded": S,
218
258
  children: [
219
- K && /* @__PURE__ */ e("span", { className: "shrink-0", children: K }),
259
+ W && /* @__PURE__ */ e("span", { className: "shrink-0", children: W }),
220
260
  /* @__PURE__ */ e(
221
261
  "span",
222
262
  {
223
- className: d(
263
+ className: p(
224
264
  "flex-1 text-left truncate",
225
- !se && "text-muted-foreground"
265
+ !fe && "text-muted-foreground"
226
266
  ),
227
- children: U ? "Loading..." : ke()
267
+ children: V ? "Loading..." : Oe()
228
268
  }
229
269
  ),
230
270
  /* @__PURE__ */ e(
231
271
  "span",
232
272
  {
233
- className: d(
273
+ className: p(
234
274
  "transition-transform duration-200",
235
- x && "rotate-180"
275
+ S && "rotate-180"
236
276
  ),
237
- children: ve || /* @__PURE__ */ e(ce, { className: "w-5 h-5" })
277
+ children: te || /* @__PURE__ */ e(he, { className: "w-5 h-5" })
238
278
  }
239
279
  )
240
280
  ]
241
281
  }
242
282
  ),
243
- q && se && !y && /* @__PURE__ */ e(
283
+ k && fe && !x && /* @__PURE__ */ e(
244
284
  "button",
245
285
  {
246
286
  type: "button",
247
- onClick: (t) => {
248
- t.stopPropagation(), Ne(t);
249
- },
250
- className: "absolute right-10 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-foreground/10 transition-colors",
287
+ onClick: Se,
288
+ className: "absolute right-10 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-foreground/10 transition-colors z-10",
251
289
  "aria-label": "Clear selection",
252
- children: he || /* @__PURE__ */ e(ie, { className: "w-4 h-4" })
290
+ children: ee || /* @__PURE__ */ e(pe, { className: "w-4 h-4" })
253
291
  }
254
292
  ),
255
- x && !y && typeof window < "u" && oe(
256
- /* @__PURE__ */ h(
293
+ S && !x && typeof window < "u" && me(
294
+ /* @__PURE__ */ b(
257
295
  "div",
258
296
  {
259
- className: d(fe({ variant: A }), ye),
297
+ ref: ce,
298
+ className: p(we({ variant: N }), j),
260
299
  style: {
261
300
  position: "absolute",
262
- top: `${I.top}px`,
263
- left: `${I.left}px`,
264
- width: `${I.width}px`,
301
+ top: `${H.top}px`,
302
+ left: `${H.left}px`,
303
+ width: `${H.width}px`,
265
304
  zIndex: 9999,
266
- opacity: I.width > 0 ? 1 : 0,
305
+ opacity: H.width > 0 ? 1 : 0,
267
306
  transition: "opacity 0.15s ease-out"
268
307
  },
269
308
  role: "listbox",
270
- "aria-multiselectable": f,
309
+ "aria-multiselectable": s,
271
310
  children: [
272
- S && /* @__PURE__ */ e("div", { className: "p-2 border-b-2 border-border/50", children: /* @__PURE__ */ h("div", { className: "relative", children: [
273
- /* @__PURE__ */ e(Pe, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" }),
311
+ y && /* @__PURE__ */ e("div", { className: "p-2 border-b-2 border-border/50", children: /* @__PURE__ */ b("div", { className: "relative", children: [
312
+ /* @__PURE__ */ e(Ie, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" }),
274
313
  /* @__PURE__ */ e(
275
314
  "input",
276
315
  {
277
- ref: H,
316
+ ref: se,
278
317
  type: "text",
279
- value: C,
280
- onChange: (t) => W(t.target.value),
318
+ value: A,
319
+ onChange: (r) => re(r.target.value),
281
320
  placeholder: "Search...",
282
321
  className: "w-full pl-10 pr-4 py-2 bg-background/50 rounded-md border-2 border-border/50 focus:border-primary focus:outline-none transition-colors"
283
322
  }
284
323
  )
285
324
  ] }) }),
286
- /* @__PURE__ */ e("div", { className: "overflow-y-auto", style: { maxHeight: w }, children: ae.length === 0 ? /* @__PURE__ */ e("div", { className: "px-4 py-8 text-center text-muted-foreground", children: C ? /* @__PURE__ */ h(Oe, { children: [
325
+ /* @__PURE__ */ e("div", { className: "overflow-y-auto", style: { maxHeight: Z }, children: de.length === 0 ? /* @__PURE__ */ e("div", { className: "px-4 py-8 text-center text-muted-foreground", children: A ? /* @__PURE__ */ b(Le, { children: [
287
326
  /* @__PURE__ */ e("p", { children: "No results found" }),
288
- z && /* @__PURE__ */ h(
327
+ F && /* @__PURE__ */ b(
289
328
  "button",
290
329
  {
291
- onClick: Ce,
330
+ type: "button",
331
+ onClick: ke,
292
332
  className: "mt-2 text-primary hover:underline",
293
333
  children: [
294
334
  'Create "',
295
- C,
335
+ A,
296
336
  '"'
297
337
  ]
298
338
  }
299
339
  )
300
- ] }) : "No options available" }) : Object.entries(xe).map(([t, i]) => /* @__PURE__ */ h("div", { children: [
301
- t !== "default" && /* @__PURE__ */ e("div", { className: "px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider bg-foreground/5", children: t }),
302
- i.map((a) => {
303
- const k = Se(a.value);
304
- return Q ? /* @__PURE__ */ e(
340
+ ] }) : "No options available" }) : Object.entries(Ce).map(([r, l]) => /* @__PURE__ */ b("div", { children: [
341
+ r !== "default" && /* @__PURE__ */ e("div", { className: "px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider bg-foreground/5", children: r }),
342
+ l.map((a) => {
343
+ const R = Ae(a.value);
344
+ return P ? /* @__PURE__ */ e(
305
345
  "div",
306
346
  {
307
- onClick: () => !a.disabled && le(a.value),
308
- className: d(
309
- M({
310
- variant: A,
347
+ onClick: () => !a.disabled && ue(a.value),
348
+ className: p(
349
+ ae({
350
+ variant: N,
311
351
  disabled: a.disabled
312
352
  }),
313
- ee
353
+ $
314
354
  ),
315
- "data-selected": k,
355
+ "data-selected": R,
316
356
  role: "option",
317
- "aria-selected": k,
318
- children: Q(a)
357
+ "aria-selected": R,
358
+ children: P(a)
319
359
  },
320
360
  a.value
321
- ) : /* @__PURE__ */ h(
361
+ ) : /* @__PURE__ */ b(
322
362
  "div",
323
363
  {
324
- onClick: () => !a.disabled && le(a.value),
325
- className: d(
326
- M({
327
- variant: A,
364
+ onClick: () => !a.disabled && ue(a.value),
365
+ className: p(
366
+ ae({
367
+ variant: N,
328
368
  disabled: a.disabled
329
369
  }),
330
- ee
370
+ $
331
371
  ),
332
- "data-selected": k,
372
+ "data-selected": R,
333
373
  role: "option",
334
- "aria-selected": k,
374
+ "aria-selected": R,
335
375
  children: [
336
- E && /* @__PURE__ */ e(
376
+ C && /* @__PURE__ */ e(
337
377
  "span",
338
378
  {
339
- className: d(
379
+ className: p(
340
380
  "shrink-0 w-5 h-5 flex items-center justify-center",
341
- k ? "opacity-100" : "opacity-0"
381
+ R ? "opacity-100" : "opacity-0"
342
382
  ),
343
- children: /* @__PURE__ */ e(de, { className: "w-4 h-4" })
383
+ children: /* @__PURE__ */ e(ge, { className: "w-4 h-4" })
344
384
  }
345
385
  ),
346
386
  a.avatar && /* @__PURE__ */ e(
@@ -352,7 +392,7 @@ const me = L(
352
392
  }
353
393
  ),
354
394
  a.icon && /* @__PURE__ */ e("span", { className: "shrink-0", children: a.icon }),
355
- /* @__PURE__ */ h("div", { className: "flex-1 min-w-0", children: [
395
+ /* @__PURE__ */ b("div", { className: "flex-1 min-w-0", children: [
356
396
  /* @__PURE__ */ e("div", { className: "font-medium truncate", children: a.label }),
357
397
  a.description && /* @__PURE__ */ e("div", { className: "text-sm text-muted-foreground truncate", children: a.description })
358
398
  ] })
@@ -361,60 +401,65 @@ const me = L(
361
401
  a.value
362
402
  );
363
403
  })
364
- ] }, t)) })
404
+ ] }, r)) })
365
405
  ]
366
406
  }
367
407
  ),
368
408
  document.body
369
409
  )
370
410
  ] }),
371
- Z && /* @__PURE__ */ e(
411
+ Y && /* @__PURE__ */ e(
372
412
  "input",
373
413
  {
374
414
  type: "hidden",
375
- name: Z,
376
- value: Array.isArray(c) ? c.join(",") : c
415
+ name: Y,
416
+ value: Array.isArray(m) ? m.join(",") : m
377
417
  }
378
418
  ),
379
- n && /* @__PURE__ */ e("p", { className: "text-sm text-destructive font-medium", children: n }),
380
- !n && p && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: p })
419
+ v && /* @__PURE__ */ e("p", { className: "text-sm text-destructive font-medium", children: v }),
420
+ !v && d && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: d })
381
421
  ] });
382
422
  }
383
423
  );
384
- me.displayName = "SelectPropsBase";
385
- const Ee = L((r, u) => !r.options && r.children ? /* @__PURE__ */ e(pe, { ...r, ref: u }) : /* @__PURE__ */ e(me, { ...r, ref: u }));
424
+ xe.displayName = "SelectPropsBase";
425
+ const Ee = D((t, o) => !t.options && t.children ? /* @__PURE__ */ e(ve, { ...t, ref: o }) : /* @__PURE__ */ e(xe, { ...t, ref: o }));
386
426
  Ee.displayName = "Select";
387
- const ze = L(
388
- ({ children: r, className: u, ...o }, l) => {
389
- const s = T(P);
390
- return /* @__PURE__ */ h(
427
+ const Pe = D(
428
+ ({ children: t, className: o, ...g }, n) => {
429
+ const h = J(U), v = I(null), d = O(
430
+ (y) => {
431
+ v.current = y, typeof n == "function" ? n(y) : n && (n.current = y), h.triggerRef && (h.triggerRef.current = y);
432
+ },
433
+ [n, h.triggerRef]
434
+ ), { disabled: u, onOpenChange: f, open: i, variant: c, size: s } = h;
435
+ return /* @__PURE__ */ b(
391
436
  "button",
392
437
  {
393
- ref: l,
438
+ ref: d,
394
439
  type: "button",
395
- onClick: () => !s.disabled && s.onOpenChange?.(!s.open),
396
- disabled: s.disabled,
397
- className: d(
398
- ue({
399
- variant: s.variant,
400
- size: s.size,
440
+ onClick: () => !u && f?.(!i),
441
+ disabled: u,
442
+ className: p(
443
+ ye({
444
+ variant: c,
445
+ size: s,
401
446
  fullWidth: !0
402
447
  }),
403
448
  "justify-between",
404
- u
449
+ o
405
450
  ),
406
451
  "aria-haspopup": "listbox",
407
- "aria-expanded": s.open,
452
+ "aria-expanded": i,
408
453
  "data-select-trigger": "true",
409
- ...o,
454
+ ...g,
410
455
  children: [
411
- r,
456
+ t,
412
457
  /* @__PURE__ */ e(
413
- ce,
458
+ he,
414
459
  {
415
- className: d(
460
+ className: p(
416
461
  "h-4 w-4 opacity-50 transition-transform duration-200",
417
- s.open && "rotate-180"
462
+ i && "rotate-180"
418
463
  )
419
464
  }
420
465
  )
@@ -423,147 +468,161 @@ const ze = L(
423
468
  );
424
469
  }
425
470
  );
426
- ze.displayName = "SelectTrigger";
427
- const je = ({ placeholder: r, className: u }) => {
428
- const o = T(P), l = o.value;
429
- let s = r;
430
- o.multiple && Array.isArray(l) ? l.length === 0 ? s = r : l.length === 1 ? s = l[0] : s = `${l.length} selected` : !o.multiple && l && (s = l);
431
- const n = !(Array.isArray(l) ? l.length === 0 : !l);
471
+ Pe.displayName = "SelectTrigger";
472
+ const ze = ({ placeholder: t, className: o }) => {
473
+ const g = J(U), { value: n, multiple: h, items: v } = g, d = (i) => v.get(i)?.label || i;
474
+ let u = t;
475
+ h && Array.isArray(n) ? n.length === 0 ? u = t : n.length === 1 ? u = d(n[0]) : u = `${n.length} selected` : !h && n && typeof n == "string" && (u = d(n));
476
+ const f = Array.isArray(n) ? n.length > 0 : !!n;
432
477
  return /* @__PURE__ */ e(
433
478
  "span",
434
479
  {
435
- className: d(
480
+ className: p(
436
481
  "block truncate text-left",
437
- !n && "text-muted-foreground",
438
- u
482
+ !f && "text-muted-foreground",
483
+ o
439
484
  ),
440
- children: s
485
+ children: u
441
486
  }
442
487
  );
443
488
  };
444
- je.displayName = "SelectValue";
445
- const Ie = ({ children: r, className: u }) => {
446
- const o = T(P), l = $(null), [s, n] = O({ top: 0, left: 0, width: 0 });
447
- return B(() => {
448
- if (!o.open) return;
449
- const p = (v) => {
450
- const m = v.target;
451
- l.current?.contains(m) || document.querySelector('[data-select-trigger="true"]')?.contains(m) || o.onOpenChange?.(!1);
489
+ ze.displayName = "SelectValue";
490
+ const je = ({ children: t, className: o }) => {
491
+ const g = J(U), n = I(null), [h, v] = L({ top: 0, left: 0, width: 0 }), { open: d, onOpenChange: u, triggerRef: f, variant: i } = g;
492
+ return M(() => {
493
+ if (!d) return;
494
+ const c = (y) => {
495
+ const k = y.target;
496
+ n.current?.contains(k) || f?.current?.contains(k) || u?.(!1);
497
+ }, s = setTimeout(() => {
498
+ document.addEventListener("mousedown", c);
499
+ }, 0);
500
+ return () => {
501
+ clearTimeout(s), document.removeEventListener("mousedown", c);
452
502
  };
453
- return document.addEventListener("mousedown", p), () => document.removeEventListener("mousedown", p);
454
- }, [o]), B(() => {
455
- if (o.open) {
456
- const p = document.querySelector(
457
- '[aria-haspopup="listbox"][aria-expanded="true"]'
458
- );
459
- if (p) {
460
- const v = () => {
461
- const m = p.getBoundingClientRect();
462
- n({
463
- top: m.bottom + window.scrollY,
464
- left: m.left + window.scrollX,
465
- width: m.width
466
- });
467
- };
468
- return v(), window.addEventListener("scroll", v, !0), window.addEventListener("resize", v), () => {
469
- window.removeEventListener("scroll", v, !0), window.removeEventListener("resize", v);
470
- };
471
- }
472
- }
473
- }, [o.open]), !o.open || typeof window > "u" ? null : oe(
503
+ }, [d, u, f]), M(() => {
504
+ if (!d || !f?.current) return;
505
+ const c = () => {
506
+ const s = f?.current?.getBoundingClientRect();
507
+ s && v({
508
+ top: s.bottom + window.scrollY,
509
+ left: s.left + window.scrollX,
510
+ width: s.width
511
+ });
512
+ };
513
+ return c(), window.addEventListener("scroll", c, !0), window.addEventListener("resize", c), () => {
514
+ window.removeEventListener("scroll", c, !0), window.removeEventListener("resize", c);
515
+ };
516
+ }, [d, f]), !d || typeof window > "u" ? null : me(
474
517
  /* @__PURE__ */ e(
475
518
  "div",
476
519
  {
477
- ref: l,
478
- className: d(
479
- fe({ variant: o.variant }),
480
- u
481
- ),
520
+ ref: n,
521
+ className: p(we({ variant: i }), o),
482
522
  style: {
483
523
  position: "absolute",
484
- top: `${s.top}px`,
485
- left: `${s.left}px`,
486
- width: `${s.width}px`,
524
+ top: `${h.top}px`,
525
+ left: `${h.left}px`,
526
+ width: `${h.width}px`,
487
527
  zIndex: 9999,
488
- opacity: s.width > 0 ? 1 : 0,
528
+ opacity: h.width > 0 ? 1 : 0,
489
529
  transition: "opacity 0.15s ease-out"
490
530
  },
491
531
  role: "listbox",
492
- children: /* @__PURE__ */ e("div", { className: "overflow-y-auto max-h-[300px]", children: r })
532
+ children: /* @__PURE__ */ e("div", { className: "overflow-y-auto max-h-[300px]", children: t })
493
533
  }
494
534
  ),
495
535
  document.body
496
536
  );
497
537
  };
498
- Ie.displayName = "SelectContent";
499
- const Re = L(
500
- ({ value: r, children: u, disabled: o, className: l }, s) => {
501
- const n = T(P), p = n.multiple ? Array.isArray(n.value) && n.value.includes(r) : n.value === r;
502
- return /* @__PURE__ */ h(
538
+ je.displayName = "SelectContent";
539
+ const Be = D(
540
+ ({ value: t, children: o, disabled: g, className: n }, h) => {
541
+ const v = J(U), {
542
+ registerItem: d,
543
+ multiple: u,
544
+ value: f,
545
+ onValueChange: i,
546
+ closeOnSelect: c,
547
+ onOpenChange: s,
548
+ disabled: y,
549
+ variant: k
550
+ } = v;
551
+ M(() => {
552
+ d(t, {
553
+ value: t,
554
+ label: o,
555
+ disabled: g
556
+ });
557
+ }, [t, o, g, d]);
558
+ const x = u ? Array.isArray(f) && f.includes(t) : f === t;
559
+ return /* @__PURE__ */ b(
503
560
  "div",
504
561
  {
505
- ref: s,
562
+ ref: h,
506
563
  onClick: () => {
507
- if (!(o || n.disabled))
508
- if (n.multiple) {
509
- const m = Array.isArray(n.value) ? n.value : [];
510
- let b;
511
- m.includes(r) ? b = m.filter((N) => N !== r) : b = [...m, r], n.onValueChange?.(b), n.closeOnSelect && n.onOpenChange?.(!1);
564
+ if (!(g || y)) {
565
+ if (u) {
566
+ const V = Array.isArray(f) ? f : [];
567
+ let N;
568
+ V.includes(t) ? N = V.filter((B) => B !== t) : N = [...V, t], i?.(N);
512
569
  } else
513
- n.onValueChange?.(r), n.closeOnSelect && n.onOpenChange?.(!1);
570
+ i?.(t);
571
+ c && s?.(!1);
572
+ }
514
573
  },
515
- className: d(
516
- M({
517
- variant: n.variant,
518
- disabled: o || n.disabled
574
+ className: p(
575
+ ae({
576
+ variant: k,
577
+ disabled: g || y
519
578
  }),
520
579
  "flex items-center gap-2 cursor-pointer",
521
- l
580
+ n
522
581
  ),
523
- "data-selected": p,
582
+ "data-selected": x,
524
583
  role: "option",
525
- "aria-selected": p,
584
+ "aria-selected": x,
526
585
  children: [
527
586
  /* @__PURE__ */ e(
528
587
  "span",
529
588
  {
530
- className: d(
589
+ className: p(
531
590
  "shrink-0 w-5 h-5 flex items-center justify-center",
532
- p ? "opacity-100" : "opacity-0"
591
+ x ? "opacity-100" : "opacity-0"
533
592
  ),
534
- children: /* @__PURE__ */ e(de, { className: "w-4 h-4" })
593
+ children: /* @__PURE__ */ e(ge, { className: "w-4 h-4" })
535
594
  }
536
595
  ),
537
- /* @__PURE__ */ e("span", { className: "flex-1", children: u })
596
+ /* @__PURE__ */ e("span", { className: "flex-1", children: o })
538
597
  ]
539
598
  }
540
599
  );
541
600
  }
542
601
  );
543
- Re.displayName = "SelectItem";
544
- const $e = ({ children: r, className: u }) => /* @__PURE__ */ e("div", { className: d("py-1", u), children: r });
602
+ Be.displayName = "SelectItem";
603
+ const $e = ({ children: t, className: o }) => /* @__PURE__ */ e("div", { className: p("py-1", o), children: t });
545
604
  $e.displayName = "SelectGroup";
546
- const Be = ({ children: r, className: u }) => /* @__PURE__ */ e(
605
+ const Te = ({ children: t, className: o }) => /* @__PURE__ */ e(
547
606
  "div",
548
607
  {
549
- className: d(
608
+ className: p(
550
609
  "px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider",
551
- u
610
+ o
552
611
  ),
553
- children: r
612
+ children: t
554
613
  }
555
614
  );
556
- Be.displayName = "SelectLabel";
557
- const Te = ({ className: r }) => /* @__PURE__ */ e("div", { className: d("h-px bg-border my-1", r) });
558
- Te.displayName = "SelectSeparator";
615
+ Te.displayName = "SelectLabel";
616
+ const Me = ({ className: t }) => /* @__PURE__ */ e("div", { className: p("h-px bg-border my-1", t) });
617
+ Me.displayName = "SelectSeparator";
559
618
  export {
560
619
  Ee as Select,
561
- Ie as SelectContent,
620
+ je as SelectContent,
562
621
  $e as SelectGroup,
563
- Re as SelectItem,
564
- Be as SelectLabel,
565
- Te as SelectSeparator,
566
- ze as SelectTrigger,
567
- je as SelectValue,
622
+ Be as SelectItem,
623
+ Te as SelectLabel,
624
+ Me as SelectSeparator,
625
+ Pe as SelectTrigger,
626
+ ze as SelectValue,
568
627
  Ee as default
569
628
  };