laif-ds 0.1.85 → 0.1.88

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,19 +1,17 @@
1
1
  "use client";
2
- import { jsxs as n, jsx as e } from "react/jsx-runtime";
3
- import * as Y from "react";
4
- import { useState as i, useEffect as k, useCallback as D } from "react";
5
- import { useDebounce as Z } from "../../hooks/use-debounce.js";
6
- import { cva as _ } from "../../node_modules/class-variance-authority/dist/index.js";
7
- import { cn as z } from "../../lib/utils.js";
8
- import { Button as V } from "./button.js";
9
- import { Label as ee } from "./label.js";
10
- import { Command as te, CommandInput as oe, CommandList as ne, CommandEmpty as se, CommandGroup as O, CommandItem as R } from "./command.js";
11
- import { Popover as re, PopoverTrigger as ae, PopoverContent as ie } from "./popover.js";
12
- import ce from "../../node_modules/lucide-react/dist/esm/icons/x.js";
13
- import le from "../../node_modules/lucide-react/dist/esm/icons/chevrons-up-down.js";
14
- import de from "../../node_modules/lucide-react/dist/esm/icons/loader-circle.js";
15
- import me from "../../node_modules/lucide-react/dist/esm/icons/check.js";
16
- const fe = _(
2
+ import { jsxs as r, jsx as e } from "react/jsx-runtime";
3
+ import * as p from "react";
4
+ import { useState as l, useEffect as h, useCallback as F } from "react";
5
+ import { useDebounce as oe } from "../../hooks/use-debounce.js";
6
+ import { cva as re } from "../../node_modules/class-variance-authority/dist/index.js";
7
+ import { cn as S } from "../../lib/utils.js";
8
+ import { Label as le } from "./label.js";
9
+ import { Popover as ae, PopoverTrigger as ce, PopoverContent as ie } from "./popover.js";
10
+ import { Command as de, CommandInput as fe, CommandList as me, CommandEmpty as ue, CommandGroup as G, CommandItem as M } from "./command.js";
11
+ import { Icon as B } from "./icon.js";
12
+ import pe from "../../node_modules/lucide-react/dist/esm/icons/loader-circle.js";
13
+ import he from "../../node_modules/lucide-react/dist/esm/icons/check.js";
14
+ const ge = re(
17
15
  "flex items-center justify-between whitespace-nowrap rounded-md border border-input bg-d-input px-3 py-2 shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
18
16
  {
19
17
  variants: {
@@ -28,132 +26,153 @@ const fe = _(
28
26
  }
29
27
  }
30
28
  );
31
- function ke({
32
- fetcher: c,
33
- preload: m,
34
- filterFn: y,
35
- renderOption: A,
29
+ function Pe({
30
+ fetcher: i,
31
+ preload: f,
32
+ filterFn: R,
33
+ renderOption: E,
36
34
  getOptionValue: a,
37
- getDisplayValue: b,
38
- notFound: F,
39
- loadingSkeleton: $,
40
- label: l,
41
- labelClassName: B,
42
- placeholder: G = "Select...",
43
- value: s = "",
44
- onChange: u,
45
- disabled: v = !1,
46
- width: E = "200px",
47
- className: M,
48
- triggerClassName: U,
49
- noResultsMessage: X,
50
- clearable: w = !0,
51
- size: q
35
+ getDisplayValue: g,
36
+ notFound: U,
37
+ loadingSkeleton: X,
38
+ label: z,
39
+ labelClassName: $,
40
+ placeholder: O = "Select...",
41
+ value: o = "",
42
+ onChange: x,
43
+ disabled: W = !1,
44
+ width: m = "200px",
45
+ triggerClassName: q,
46
+ noResultsMessage: H,
47
+ clearable: L = !0,
48
+ size: J
52
49
  }) {
53
- const [p, N] = i(!1), [r, d] = i([]), [C, h] = i(!1), [S, g] = i(null), [L, x] = i(null), [I, H] = i(""), f = Z(I, m ? 0 : 300), [j, P] = i([]);
54
- k(() => ((async () => {
50
+ const [c, j] = l(!1), y = m === "auto", I = p.useRef(null), P = p.useRef(null), K = p.useRef(null), Q = p.useRef(null), [w, N] = l(!1), [v, b] = l(null), [T, C] = l(null), [D, Y] = l(""), u = oe(D, f ? 0 : 300), [k, A] = l([]), [n, d] = l([]), [Z, _] = l(
51
+ void 0
52
+ );
53
+ h(() => ((async () => {
55
54
  try {
56
- if (h(!0), g(null), m) {
55
+ if (N(!0), b(null), f) {
57
56
  console.log(
58
57
  "[AsyncSelect] Preload attivo: caricamento completo dei dati"
59
58
  );
60
- const o = await c("");
61
- P(o), d(o);
59
+ const s = await i("");
60
+ A(s), d(s);
62
61
  } else {
63
- const o = await c(s);
64
- d(o);
62
+ const s = await i(o);
63
+ d(s);
65
64
  }
66
- } catch (o) {
67
- g(
68
- o instanceof Error ? o.message : "Failed to fetch options"
65
+ } catch (s) {
66
+ b(
67
+ s instanceof Error ? s.message : "Failed to fetch options"
69
68
  );
70
69
  } finally {
71
- h(!1);
70
+ N(!1);
72
71
  }
73
72
  })(), () => {
74
- d([]), P([]);
75
- }), [c, s, m]), k(() => {
76
- if (p)
77
- if (m)
78
- if (f) {
79
- const t = j.filter(
80
- (o) => y ? y(o, f) : String(b(o)).toLowerCase().includes(f.toLowerCase())
73
+ d([]), A([]);
74
+ }), [i, o, f]), h(() => {
75
+ if (c)
76
+ if (f)
77
+ if (u) {
78
+ const t = k.filter(
79
+ (s) => R ? R(s, u) : String(g(s)).toLowerCase().includes(u.toLowerCase())
81
80
  );
82
81
  d(t);
83
82
  } else
84
- d(j);
83
+ d(k);
85
84
  else
86
85
  (async () => {
87
86
  try {
88
- h(!0), g(null);
89
- const o = await c(f);
90
- d(o);
91
- } catch (o) {
92
- g(
93
- o instanceof Error ? o.message : "Failed to fetch options"
87
+ N(!0), b(null);
88
+ const s = await i(u);
89
+ d(s);
90
+ } catch (s) {
91
+ b(
92
+ s instanceof Error ? s.message : "Failed to fetch options"
94
93
  );
95
94
  } finally {
96
- h(!1);
95
+ N(!1);
97
96
  }
98
97
  })();
99
98
  }, [
100
- p,
99
+ c,
100
+ u,
101
101
  f,
102
- m,
103
- y,
104
- j,
105
- b
106
- ]), k(() => {
107
- if (s && r.length > 0) {
108
- const t = r.find((o) => a(o) === s);
109
- x(t || null);
110
- } else s || x(null);
111
- }, [s, r, a]);
112
- const J = D(
102
+ R,
103
+ k,
104
+ g
105
+ ]), h(() => {
106
+ if (o && n.length > 0) {
107
+ const t = n.find((s) => a(s) === o);
108
+ C(t || null);
109
+ } else o || C(null);
110
+ }, [o, n, a]), h(() => {
111
+ c && I.current && I.current.focus();
112
+ }, [c]), h(() => {
113
+ if (c && P.current) {
114
+ const t = P.current.getBoundingClientRect();
115
+ _(t.width);
116
+ }
117
+ }, [c]);
118
+ const V = F(
113
119
  (t) => {
114
- const o = w && t === s ? "" : t, Q = r.find((W) => a(W) === o) || null;
115
- x(Q), u(o), N(!1);
120
+ const s = L && t === o ? "" : t, se = n.find((ne) => a(ne) === s) || null;
121
+ C(se), x(s), j(!1);
116
122
  },
117
- [s, u, w, r, a]
118
- ), K = D(
123
+ [o, x, L, n, a]
124
+ ), ee = F(
119
125
  (t) => {
120
- t.stopPropagation(), t.preventDefault(), x(null), u(""), N(!1);
126
+ t.stopPropagation(), t.preventDefault(), C(null), x(""), j(!1);
121
127
  },
122
- [u]
123
- ), T = Y.useId();
124
- return /* @__PURE__ */ n("div", { className: "space-y-1.5", children: [
125
- l && /* @__PURE__ */ e(ee, { htmlFor: T, className: B, children: l }),
126
- /* @__PURE__ */ n(re, { open: p, onOpenChange: N, children: [
127
- /* @__PURE__ */ e(ae, { disabled: v, children: /* @__PURE__ */ e(
128
- V,
128
+ [x]
129
+ ), te = p.useId();
130
+ return /* @__PURE__ */ r("div", { className: S("space-y-1.5", y && "w-full"), children: [
131
+ z && /* @__PURE__ */ e(le, { className: $, children: z }),
132
+ /* @__PURE__ */ e("div", { ref: K, className: "relative", "data-slot": "async-select", children: /* @__PURE__ */ r(ae, { open: c, onOpenChange: j, children: [
133
+ /* @__PURE__ */ e(ce, { asChild: !0, children: /* @__PURE__ */ e(
134
+ "button",
129
135
  {
130
- id: T,
136
+ id: te,
131
137
  type: "button",
132
- variant: "ghost",
133
- role: "combobox",
134
- "aria-expanded": p,
135
- className: z(
136
- fe({ size: q }),
137
- v && "cursor-not-allowed opacity-50",
138
- U,
139
- "font-normal"
138
+ disabled: W,
139
+ className: S(
140
+ ge({ size: J }),
141
+ W && "cursor-not-allowed opacity-50",
142
+ q,
143
+ "font-normal",
144
+ y && "w-full"
140
145
  ),
141
- style: { width: E },
142
- disabled: v,
143
- children: /* @__PURE__ */ n("div", { className: "flex flex-1 items-center justify-between overflow-hidden", children: [
144
- L ? /* @__PURE__ */ e("div", { className: "truncate", children: b(L) }) : /* @__PURE__ */ e("span", { className: "text-d-muted-foreground hover:text-d-foreground", children: G }),
145
- /* @__PURE__ */ n("div", { className: "flex items-center gap-1", children: [
146
- w && L && /* @__PURE__ */ e(
146
+ style: y ? void 0 : { width: m },
147
+ ref: P,
148
+ children: /* @__PURE__ */ r("div", { className: "flex w-full flex-1 items-center justify-between overflow-hidden", children: [
149
+ T ? /* @__PURE__ */ e("div", { className: "truncate", children: g(T) }) : /* @__PURE__ */ e("span", { className: "text-d-muted-foreground hover:text-d-foreground", children: O }),
150
+ /* @__PURE__ */ r("div", { className: "flex w-full items-center justify-end gap-1", children: [
151
+ L && T && /* @__PURE__ */ e(
147
152
  "div",
148
153
  {
149
- className: "bg-d-input hover:bg-d-input/30 border-d-border z-20 flex cursor-pointer items-center justify-center rounded-full border p-1",
150
- onClick: K,
154
+ className: "border-d-input bg-d-accent cursor-pointer rounded-full p-1",
155
+ onClick: ee,
151
156
  onMouseDown: (t) => t.preventDefault(),
152
157
  "aria-label": "Clear selection",
153
- children: /* @__PURE__ */ e(ce, { size: 8, className: "text-d-foreground" })
158
+ children: /* @__PURE__ */ e(
159
+ B,
160
+ {
161
+ name: "X",
162
+ size: "xs",
163
+ className: "!text-d-foreground opacity-50"
164
+ }
165
+ )
154
166
  }
155
167
  ),
156
- /* @__PURE__ */ e(le, { className: "opacity-50", size: 10 })
168
+ /* @__PURE__ */ e(
169
+ B,
170
+ {
171
+ name: "ChevronsUpDown",
172
+ size: "xs",
173
+ className: "!text-d-foreground opacity-50"
174
+ }
175
+ )
157
176
  ] })
158
177
  ] })
159
178
  }
@@ -161,63 +180,75 @@ function ke({
161
180
  /* @__PURE__ */ e(
162
181
  ie,
163
182
  {
164
- style: { width: E },
165
- className: z("p-0", M),
166
- children: /* @__PURE__ */ n(te, { shouldFilter: !1, children: [
167
- /* @__PURE__ */ n("div", { className: "border-d-border relative w-full border-b", children: [
168
- /* @__PURE__ */ e(
169
- oe,
170
- {
171
- className: "!focus:outline-none !focus-visible:outline-none !focus:ring-0 !focus:ring-offset-0 !focus-visible:ring-0 !focus-visible:ring-offset-0 !border-none !outline-none",
172
- placeholder: `Search ${typeof l == "string" ? l.toLowerCase() : "options"}...`,
173
- value: I,
174
- onValueChange: (t) => {
175
- H(t);
183
+ className: S("p-0"),
184
+ style: {
185
+ width: y ? Z : typeof m == "number" ? `${m}px` : m
186
+ },
187
+ align: "start",
188
+ side: "bottom",
189
+ sideOffset: 4,
190
+ onWheel: (t) => t.stopPropagation(),
191
+ avoidCollisions: !1,
192
+ children: /* @__PURE__ */ r(
193
+ de,
194
+ {
195
+ shouldFilter: !1,
196
+ className: "w-full border-none shadow-lg",
197
+ children: [
198
+ /* @__PURE__ */ e(
199
+ fe,
200
+ {
201
+ ref: I,
202
+ placeholder: O,
203
+ value: D,
204
+ onValueChange: Y
176
205
  }
177
- }
178
- ),
179
- C && r.length > 0 && /* @__PURE__ */ e("div", { className: "absolute top-1/2 right-2 flex -translate-y-1/2 transform items-center", children: /* @__PURE__ */ e(de, { className: "h-4 w-4 animate-spin" }) })
180
- ] }),
181
- /* @__PURE__ */ n(ne, { children: [
182
- S && /* @__PURE__ */ e("div", { className: "text-d-destructive p-3 text-center", children: S }),
183
- C && r.length === 0 && ($ || /* @__PURE__ */ e(ue, {})),
184
- !C && !S && r.length === 0 && (F || /* @__PURE__ */ e(se, { children: X ?? `No ${typeof l == "string" ? l.toLowerCase() : "options"} found.` })),
185
- /* @__PURE__ */ e(O, { children: r.map((t) => /* @__PURE__ */ n(
186
- R,
187
- {
188
- value: a(t),
189
- onSelect: J,
190
- children: [
191
- A(t),
192
- /* @__PURE__ */ e(
193
- me,
194
- {
195
- className: z(
196
- "ml-auto h-3 w-3",
197
- s === a(t) ? "opacity-100" : "opacity-0"
206
+ ),
207
+ w && n.length > 0 && /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-2", children: /* @__PURE__ */ e(pe, { className: "h-4 w-4 animate-spin" }) }),
208
+ /* @__PURE__ */ r(me, { ref: Q, children: [
209
+ v && /* @__PURE__ */ e("div", { className: "text-d-destructive p-3 text-center", children: v }),
210
+ w && n.length === 0 && (X || /* @__PURE__ */ e(xe, {})),
211
+ !w && !v && n.length === 0 && (U || /* @__PURE__ */ e(ue, { children: H || "No results found." })),
212
+ !w && !v && n.length > 0 && /* @__PURE__ */ e(G, { children: n.map((t) => /* @__PURE__ */ r(
213
+ M,
214
+ {
215
+ value: a(t),
216
+ onSelect: V,
217
+ className: "cursor-pointer",
218
+ children: [
219
+ E ? E(t) : /* @__PURE__ */ e("span", { children: g(t) }),
220
+ /* @__PURE__ */ e(
221
+ he,
222
+ {
223
+ className: S(
224
+ "ml-auto h-4 w-4",
225
+ o === a(t) ? "opacity-100" : "opacity-0"
226
+ )
227
+ }
198
228
  )
199
- }
200
- )
201
- ]
202
- },
203
- a(t)
204
- )) })
205
- ] })
206
- ] })
229
+ ]
230
+ },
231
+ a(t)
232
+ )) })
233
+ ] })
234
+ ]
235
+ }
236
+ )
207
237
  }
208
238
  )
209
- ] })
239
+ ] }) })
210
240
  ] });
211
241
  }
212
- function ue() {
213
- return /* @__PURE__ */ e(O, { children: [1, 2, 3].map((c) => /* @__PURE__ */ e(R, { disabled: !0, children: /* @__PURE__ */ n("div", { className: "flex w-full items-center gap-2", children: [
242
+ function xe() {
243
+ return /* @__PURE__ */ e(G, { children: [1, 2, 3].map((i) => /* @__PURE__ */ e(M, { disabled: !0, children: /* @__PURE__ */ r("div", { className: "flex w-full items-center gap-2", children: [
214
244
  /* @__PURE__ */ e("div", { className: "bg-d-secondary h-6 w-6 animate-pulse rounded-full" }),
215
- /* @__PURE__ */ n("div", { className: "flex flex-1 flex-col gap-1", children: [
245
+ /* @__PURE__ */ r("div", { className: "flex flex-1 flex-col gap-1", children: [
216
246
  /* @__PURE__ */ e("div", { className: "bg-d-secondary h-4 w-24 animate-pulse rounded" }),
217
247
  /* @__PURE__ */ e("div", { className: "bg-d-secondary h-3 w-16 animate-pulse rounded" })
218
248
  ] })
219
- ] }) }, c)) });
249
+ ] }) }, i)) });
220
250
  }
221
251
  export {
222
- ke as AsyncSelect
252
+ Pe as AsyncSelect,
253
+ ge as asyncSelectTriggerVariants
223
254
  };
@@ -14,7 +14,7 @@ const m = h(
14
14
  outline: "border bg-d-background shadow-xs hover:bg-d-accent hover:text-d-accent-foreground dark:bg-d-input/30 dark:border-d-input dark:hover:bg-d-input/50",
15
15
  "outline-primary": "border !border-d-primary bg-d-background shadow-xs text-d-primary/80 hover:!text-d-primary",
16
16
  secondary: "bg-d-secondary text-d-secondary-foreground shadow-xs hover:bg-d-secondary/80 hover:text-d-secondary-foreground",
17
- ghost: "hover:bg-d-accent hover:text-d-accent-foreground dark:hover:bg-d-accent/50",
17
+ ghost: "hover:bg-d-accent hover:text-d-accent-foreground dark:hover:bg-d-accent",
18
18
  link: "text-d-primary underline-offset-4 hover:underline"
19
19
  },
20
20
  size: {
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as e } from "react/jsx-runtime";
3
- import { Checkbox as t, CheckboxIndicator as a } from "../../node_modules/@radix-ui/react-checkbox/dist/index.js";
4
- import { cn as d } from "../../lib/utils.js";
3
+ import { Checkbox as t, CheckboxIndicator as d } from "../../node_modules/@radix-ui/react-checkbox/dist/index.js";
4
+ import { cn as a } from "../../lib/utils.js";
5
5
  import o from "../../node_modules/lucide-react/dist/esm/icons/check.js";
6
6
  function b({
7
7
  className: r,
@@ -11,13 +11,13 @@ function b({
11
11
  t,
12
12
  {
13
13
  "data-slot": "checkbox",
14
- className: d(
15
- "peer border-d-input dark:bg-d-input/30 data-[state=checked]:bg-d-primary data-[state=checked]:text-d-primary-foreground dark:data-[state=checked]:bg-d-primary data-[state=checked]:border-d-primary focus-visible:border-d-ring focus-visible:ring-d-ring/50 aria-invalid:ring-d-destructive/20 dark:aria-invalid:ring-d-destructive/40 aria-invalid:border-d-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
14
+ className: a(
15
+ "peer bg-d-input border-d-border data-[state=checked]:bg-d-primary data-[state=checked]:border-d-primary data-[state=checked]:text-d-primary-foreground focus-visible:border-d-ring focus-visible:ring-d-ring/50 aria-invalid:border-d-destructive aria-invalid:ring-d-destructive/20 dark:aria-invalid:ring-d-destructive/40 size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
16
16
  r
17
17
  ),
18
18
  ...i,
19
19
  children: /* @__PURE__ */ e(
20
- a,
20
+ d,
21
21
  {
22
22
  "data-slot": "checkbox-indicator",
23
23
  className: "flex items-center justify-center text-current transition-none",