laif-ds 0.1.48 → 0.1.50

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