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
|
|
3
|
-
import * as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { useDebounce as
|
|
6
|
-
import { cva as
|
|
7
|
-
import { cn as
|
|
8
|
-
import { Button as
|
|
9
|
-
import { Label as
|
|
10
|
-
import { Command as
|
|
11
|
-
import { Popover as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
const
|
|
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
|
|
32
|
-
fetcher:
|
|
33
|
-
preload:
|
|
31
|
+
function ke({
|
|
32
|
+
fetcher: i,
|
|
33
|
+
preload: m,
|
|
34
34
|
filterFn: x,
|
|
35
|
-
renderOption:
|
|
36
|
-
getOptionValue:
|
|
37
|
-
getDisplayValue:
|
|
38
|
-
notFound:
|
|
39
|
-
loadingSkeleton:
|
|
40
|
-
label:
|
|
41
|
-
labelClassName:
|
|
42
|
-
placeholder:
|
|
43
|
-
value:
|
|
44
|
-
onChange:
|
|
45
|
-
disabled:
|
|
46
|
-
width:
|
|
47
|
-
className:
|
|
48
|
-
triggerClassName:
|
|
49
|
-
noResultsMessage:
|
|
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:
|
|
51
|
+
size: q
|
|
52
52
|
}) {
|
|
53
|
-
const [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
98
|
-
|
|
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
|
-
[
|
|
103
|
-
),
|
|
119
|
+
[n, p, v, r, a]
|
|
120
|
+
), K = D(
|
|
104
121
|
(t) => {
|
|
105
|
-
t.stopPropagation(), t.preventDefault(),
|
|
122
|
+
t.stopPropagation(), t.preventDefault(), y(null), p(""), N(!1);
|
|
106
123
|
},
|
|
107
|
-
[
|
|
108
|
-
),
|
|
109
|
-
return /* @__PURE__ */
|
|
110
|
-
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
/* @__PURE__ */ e(
|
|
113
|
-
|
|
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:
|
|
132
|
+
id: T,
|
|
116
133
|
variant: "ghost",
|
|
117
134
|
role: "combobox",
|
|
118
|
-
"aria-expanded":
|
|
119
|
-
className:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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:
|
|
126
|
-
disabled:
|
|
127
|
-
children: /* @__PURE__ */
|
|
128
|
-
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
v &&
|
|
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:
|
|
151
|
+
onClick: K,
|
|
135
152
|
onMouseDown: (t) => t.preventDefault(),
|
|
136
153
|
"aria-label": "Clear selection",
|
|
137
|
-
children: /* @__PURE__ */ e(
|
|
154
|
+
children: /* @__PURE__ */ e(ie, { size: 8, className: "text-d-foreground" })
|
|
138
155
|
}
|
|
139
156
|
),
|
|
140
|
-
/* @__PURE__ */ e(
|
|
157
|
+
/* @__PURE__ */ e(le, { className: "opacity-50", size: 10 })
|
|
141
158
|
] })
|
|
142
159
|
] })
|
|
143
160
|
}
|
|
144
161
|
) }),
|
|
145
162
|
/* @__PURE__ */ e(
|
|
146
|
-
|
|
163
|
+
ce,
|
|
147
164
|
{
|
|
148
|
-
style: { width:
|
|
149
|
-
className:
|
|
150
|
-
children: /* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
170
|
+
oe,
|
|
154
171
|
{
|
|
155
|
-
placeholder: `Search ${typeof
|
|
156
|
-
value:
|
|
172
|
+
placeholder: `Search ${typeof l == "string" ? l.toLowerCase() : "options"}...`,
|
|
173
|
+
value: I,
|
|
157
174
|
onValueChange: (t) => {
|
|
158
|
-
|
|
175
|
+
H(t);
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
),
|
|
162
|
-
|
|
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__ */
|
|
181
|
+
/* @__PURE__ */ s(se, { children: [
|
|
165
182
|
b && /* @__PURE__ */ e("div", { className: "text-d-destructive p-3 text-center", children: b }),
|
|
166
|
-
|
|
167
|
-
!
|
|
168
|
-
/* @__PURE__ */ e(
|
|
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:
|
|
172
|
-
onSelect:
|
|
188
|
+
value: a(t),
|
|
189
|
+
onSelect: J,
|
|
173
190
|
children: [
|
|
174
|
-
|
|
191
|
+
F(t),
|
|
175
192
|
/* @__PURE__ */ e(
|
|
176
|
-
|
|
193
|
+
me,
|
|
177
194
|
{
|
|
178
|
-
className:
|
|
195
|
+
className: k(
|
|
179
196
|
"ml-auto h-3 w-3",
|
|
180
|
-
|
|
197
|
+
n === a(t) ? "opacity-100" : "opacity-0"
|
|
181
198
|
)
|
|
182
199
|
}
|
|
183
200
|
)
|
|
184
201
|
]
|
|
185
202
|
},
|
|
186
|
-
|
|
203
|
+
a(t)
|
|
187
204
|
)) })
|
|
188
205
|
] })
|
|
189
206
|
] })
|
|
@@ -192,15 +209,15 @@ function Ee({
|
|
|
192
209
|
] })
|
|
193
210
|
] });
|
|
194
211
|
}
|
|
195
|
-
function
|
|
196
|
-
return /* @__PURE__ */ e(
|
|
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__ */
|
|
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
|
-
] }) },
|
|
219
|
+
] }) }, i)) });
|
|
203
220
|
}
|
|
204
221
|
export {
|
|
205
|
-
|
|
222
|
+
ke as AsyncSelect
|
|
206
223
|
};
|