laif-ds 0.2.71 → 0.2.73

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,263 +0,0 @@
1
- "use client";
2
- import { jsx as i, jsxs as a, Fragment as g } from "react/jsx-runtime";
3
- import { getExt as h, imageExts as P } from "../../lib/file-preview.js";
4
- import { motion as k } from "framer-motion";
5
- import c, { useEffect as j } from "react";
6
- import { AppTextTooltip as z } from "./app-tooltip.js";
7
- import { Button as L } from "./button.js";
8
- import { Command as A, CommandGroup as T, CommandItem as B } from "./command.js";
9
- import { Icon as p } from "./icon.js";
10
- import { Popover as I, PopoverTrigger as U, PopoverContent as E } from "./popover.js";
11
- import { cn as b } from "../../lib/utils.js";
12
- import l from "../../node_modules/lucide-react/dist/esm/icons/file-text.js";
13
- import F from "../../node_modules/lucide-react/dist/esm/icons/file-audio.js";
14
- import N from "../../node_modules/lucide-react/dist/esm/icons/file-video.js";
15
- import S from "../../node_modules/lucide-react/dist/esm/icons/file.js";
16
- import O from "../../node_modules/lucide-react/dist/esm/icons/file-spreadsheet.js";
17
- import R from "../../node_modules/lucide-react/dist/esm/icons/file-archive.js";
18
- import $ from "../../node_modules/lucide-react/dist/esm/icons/file-code.js";
19
- const u = (e) => "type" in e && typeof e.type == "string" && e instanceof File, d = (e) => e.name || "url" in e && e.url || "", v = (e) => {
20
- if (u(e)) return e.type || "";
21
- const t = e.type;
22
- return typeof t == "string" ? t : "";
23
- }, W = (e, t) => {
24
- const o = {
25
- pdf: { icon: l, colorClass: "text-red-600" },
26
- doc: { icon: l, colorClass: "text-blue-600" },
27
- docx: { icon: l, colorClass: "text-blue-600" },
28
- ppt: { icon: l, colorClass: "text-orange-600" },
29
- pptx: { icon: l, colorClass: "text-orange-600" },
30
- txt: { icon: l, colorClass: "text-gray-600" },
31
- md: { icon: l, colorClass: "text-gray-600" }
32
- }, r = (s, n) => s.forEach((m) => o[m] = n);
33
- return r(["xls", "xlsx", "csv"], {
34
- icon: O,
35
- colorClass: "text-green-600"
36
- }), r(["zip", "rar", "7z", "tar", "gz", "tgz"], {
37
- icon: R,
38
- colorClass: "text-amber-600"
39
- }), r(["mp3", "wav", "ogg", "flac", "m4a"], {
40
- icon: F,
41
- colorClass: "text-violet-600"
42
- }), r(["mp4", "mov", "avi", "mkv", "webm"], {
43
- icon: N,
44
- colorClass: "text-rose-600"
45
- }), r(
46
- [
47
- "js",
48
- "ts",
49
- "jsx",
50
- "tsx",
51
- "json",
52
- "xml",
53
- "yml",
54
- "yaml",
55
- "html",
56
- "css",
57
- "scss"
58
- ],
59
- {
60
- icon: $,
61
- colorClass: "text-indigo-600"
62
- }
63
- ), e && o[e] ? o[e] : t?.startsWith("audio/") ? { icon: F, colorClass: "text-violet-600" } : t?.startsWith("video/") ? { icon: N, colorClass: "text-rose-600" } : t?.startsWith("text/") ? { icon: l, colorClass: "text-gray-600" } : { icon: S, colorClass: "text-d-secondary-foreground" };
64
- }, _ = (e) => {
65
- if (!Number.isFinite(e) || e < 0) return "";
66
- if (e === 0) return "0B";
67
- const t = ["B", "KB", "MB", "GB", "TB"], o = Math.min(
68
- Math.floor(Math.log(e) / Math.log(1024)),
69
- t.length - 1
70
- ), r = e / 1024 ** o, s = o > 0 && r < 100 ? 2 : 0;
71
- return `${r.toFixed(s)}${t[o]}`;
72
- }, G = (e) => {
73
- const t = u(e) ? _(e.size) : "", o = V(e);
74
- return { sizeLabel: t, formatLabel: o };
75
- }, D = (e, t) => e && t ? `${e} · ${t}` : e || t || null, K = {
76
- layout: !0,
77
- initial: { opacity: 0, y: "100%" },
78
- animate: { opacity: 1, y: 0 },
79
- exit: { opacity: 0, y: "100%" }
80
- }, y = ({
81
- sizeLabel: e,
82
- formatLabel: t
83
- }) => {
84
- const o = D(e, t);
85
- return o ? /* @__PURE__ */ i("div", { className: "text-d-secondary-foreground/70 text-xs", children: o }) : null;
86
- }, V = (e) => {
87
- const t = h(d(e));
88
- if (t) return t.toUpperCase();
89
- const o = v(e);
90
- if (!o) return "";
91
- if (o === "application/pdf") return "PDF";
92
- const [r, s] = o.split("/");
93
- return r === "image" ? s?.toUpperCase() || "IMAGE" : r === "audio" || r === "video" || r === "text" ? r.toUpperCase() : /(officedocument|msword|ms-excel|ms-powerpoint)/.test(o) ? "OFFICE" : "";
94
- }, X = ({
95
- url: e,
96
- onPreview: t,
97
- onDownload: o,
98
- onRemove: r
99
- }) => /* @__PURE__ */ a(I, { children: [
100
- /* @__PURE__ */ i(U, { asChild: !0, children: /* @__PURE__ */ i(L, { variant: "ghost", size: "icon", children: /* @__PURE__ */ i(p, { name: "Menu", size: "sm" }) }) }),
101
- /* @__PURE__ */ i(E, { className: "w-42 p-0", align: "end", children: /* @__PURE__ */ i(A, { children: /* @__PURE__ */ i(T, { children: [
102
- {
103
- key: "preview",
104
- cond: !!t,
105
- icon: "Presentation",
106
- label: "Anteprima",
107
- onSelect: t
108
- },
109
- {
110
- key: "download",
111
- cond: !!o,
112
- icon: "Download",
113
- label: "Download",
114
- onSelect: o
115
- },
116
- {
117
- key: "remove",
118
- cond: !!r,
119
- icon: "Trash",
120
- label: "Elimina",
121
- onSelect: r,
122
- danger: !0
123
- }
124
- ].map(
125
- (n) => n.cond && /* @__PURE__ */ a(
126
- B,
127
- {
128
- onSelect: () => n.onSelect?.(e),
129
- className: n.danger ? "text-d-destructive" : void 0,
130
- children: [
131
- /* @__PURE__ */ i(
132
- p,
133
- {
134
- name: n.icon,
135
- size: "sm",
136
- className: n.danger ? "text-d-destructive" : void 0
137
- }
138
- ),
139
- /* @__PURE__ */ i("span", { children: n.label })
140
- ]
141
- },
142
- n.key
143
- )
144
- ) }) }) })
145
- ] }), xe = c.forwardRef(
146
- (e, t) => {
147
- const o = d(e.file), r = h(o), s = v(e.file), n = r === "csv" || s === "text/csv";
148
- return s && s.startsWith("image/") || r && P.has(r) ? /* @__PURE__ */ i(q, { ...e, ref: t }) : !n && (r === "txt" || r === "md" || s && s.startsWith("text/")) ? /* @__PURE__ */ i(H, { ...e, ref: t }) : /* @__PURE__ */ i(J, { ...e, ref: t });
149
- }
150
- ), C = c.forwardRef(
151
- ({
152
- file: e,
153
- onRemove: t,
154
- onPreview: o,
155
- onDownload: r,
156
- showActionMenu: s = !1,
157
- className: n,
158
- defaultClassName: m,
159
- children: w
160
- }, f) => {
161
- const x = u(e) ? URL.createObjectURL(e) : e.url, M = G(e);
162
- return /* @__PURE__ */ a(
163
- k.div,
164
- {
165
- ref: f,
166
- className: b(
167
- "border-d-border relative flex items-center rounded-md border text-xs",
168
- m,
169
- n
170
- ),
171
- ...K,
172
- children: [
173
- /* @__PURE__ */ a("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
174
- w(x, M),
175
- s && /* @__PURE__ */ i(
176
- X,
177
- {
178
- url: x,
179
- onPreview: o,
180
- onDownload: r,
181
- onRemove: t
182
- }
183
- )
184
- ] }),
185
- !s && t ? /* @__PURE__ */ i(
186
- L,
187
- {
188
- className: "bg-d-background hover:bg-d-background absolute -top-2 -right-2 flex !size-3.5 rounded-full text-xs",
189
- variant: "outline",
190
- size: "icon",
191
- onClick: () => t(x),
192
- children: /* @__PURE__ */ i(p, { name: "X", className: "h-2.5 max-w-2.5" })
193
- }
194
- ) : null
195
- ]
196
- }
197
- );
198
- }
199
- ), q = c.forwardRef((e, t) => /* @__PURE__ */ i(C, { ...e, ref: t, defaultClassName: "gap-2 p-1.5 pr-2", children: (o, r) => /* @__PURE__ */ a(g, { children: [
200
- /* @__PURE__ */ i(
201
- "img",
202
- {
203
- alt: `Attachment ${d(e.file)}`,
204
- className: b(
205
- "bg-d-secondary border-d-border h-10 w-10 shrink-0 rounded-sm border object-cover"
206
- ),
207
- src: o
208
- }
209
- ),
210
- /* @__PURE__ */ a("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
211
- /* @__PURE__ */ i(z, { text: d(e.file) }),
212
- /* @__PURE__ */ i(
213
- y,
214
- {
215
- sizeLabel: r.sizeLabel,
216
- formatLabel: r.formatLabel
217
- }
218
- )
219
- ] })
220
- ] }) })), H = c.forwardRef((e, t) => {
221
- const [o, r] = c.useState("");
222
- return j(() => {
223
- if (u(e.file)) {
224
- const s = new FileReader();
225
- s.onload = (n) => {
226
- n.target?.result && r(
227
- typeof n.target.result == "string" ? n.target.result.slice(0, 100) : ""
228
- );
229
- }, s.readAsText(e.file);
230
- } else
231
- r("Anteprima non disponibile");
232
- }, [e.file]), /* @__PURE__ */ i(C, { ...e, ref: t, defaultClassName: "gap-2 p-1.5 pr-2", children: (s, n) => /* @__PURE__ */ a(g, { children: [
233
- /* @__PURE__ */ i("div", { className: "bg-d-secondary border-d-border flex h-10 w-10 shrink-0 items-center justify-center rounded-sm border p-1 text-[8px]", children: o }),
234
- /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ i(
235
- y,
236
- {
237
- sizeLabel: n.sizeLabel,
238
- formatLabel: n.formatLabel
239
- }
240
- ) })
241
- ] }) });
242
- }), J = c.forwardRef((e, t) => {
243
- const o = d(e.file), r = h(o), s = v(e.file), { icon: n, colorClass: m } = W(r, s);
244
- return /* @__PURE__ */ i(C, { ...e, ref: t, defaultClassName: "gap-2 p-1.5 pr-2", children: (w, f) => /* @__PURE__ */ a(g, { children: [
245
- /* @__PURE__ */ i("div", { className: "bg-d-secondary flex h-10 w-10 shrink-0 items-center justify-center rounded-sm", children: /* @__PURE__ */ i(n, { className: b("h-5 w-5", m) }) }),
246
- /* @__PURE__ */ a("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
247
- /* @__PURE__ */ i(z, { text: o }),
248
- /* @__PURE__ */ i(
249
- y,
250
- {
251
- sizeLabel: f.sizeLabel,
252
- formatLabel: f.formatLabel
253
- }
254
- )
255
- ] })
256
- ] }) });
257
- });
258
- export {
259
- xe as FilePreview,
260
- J as GenericFilePreview,
261
- q as ImageFilePreview,
262
- H as TextFilePreview
263
- };