laif-ds 0.2.12 → 0.2.14
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.
- package/dist/_virtual/index4.js +2 -5
- package/dist/_virtual/index5.js +5 -5
- package/dist/_virtual/index6.js +5 -2
- package/dist/components/ui/app-select.js +114 -100
- package/dist/components/ui/carousel.js +4 -4
- package/dist/components/ui/chart.js +4 -4
- package/dist/components/ui/command.js +3 -3
- package/dist/components/ui/file-previewer.js +170 -0
- package/dist/components/ui/navigation-menu.js +7 -7
- package/dist/components/ui/popover.js +17 -16
- package/dist/components/ui/textarea.js +24 -15
- package/dist/index.d.ts +33 -3
- package/dist/index.js +128 -124
- package/dist/lib/file-preview.js +33 -0
- package/dist/node_modules/eventemitter3/index2.js +1 -1
- package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.js +1 -1
- package/dist/node_modules/unified/lib/index.js +1 -1
- package/dist/styles.v3.css +1 -1
- package/package.json +2 -2
package/dist/_virtual/index4.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { __require as r } from "../node_modules/extend/index.js";
|
|
4
|
-
var t = r();
|
|
5
|
-
const x = /* @__PURE__ */ e(t);
|
|
2
|
+
var e = { exports: {} };
|
|
6
3
|
export {
|
|
7
|
-
|
|
4
|
+
e as __module
|
|
8
5
|
};
|
package/dist/_virtual/index5.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { getDefaultExportFromCjs as
|
|
3
|
-
import { __require as
|
|
4
|
-
var t =
|
|
5
|
-
const
|
|
2
|
+
import { getDefaultExportFromCjs as e } from "./_commonjsHelpers.js";
|
|
3
|
+
import { __require as r } from "../node_modules/extend/index.js";
|
|
4
|
+
var t = r();
|
|
5
|
+
const x = /* @__PURE__ */ e(t);
|
|
6
6
|
export {
|
|
7
|
-
|
|
7
|
+
x as default
|
|
8
8
|
};
|
package/dist/_virtual/index6.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
|
|
3
|
+
import { __require as e } from "../node_modules/style-to-js/cjs/index.js";
|
|
4
|
+
var t = e();
|
|
5
|
+
const a = /* @__PURE__ */ r(t);
|
|
3
6
|
export {
|
|
4
|
-
|
|
7
|
+
a as default
|
|
5
8
|
};
|
|
@@ -1,127 +1,140 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as o, jsx as
|
|
3
|
-
import { Badge as
|
|
4
|
-
import { Command as le, CommandInput as
|
|
5
|
-
import { Label as
|
|
6
|
-
import { cn as
|
|
2
|
+
import { jsxs as o, jsx as t, Fragment as te } from "react/jsx-runtime";
|
|
3
|
+
import { Badge as re } from "./badge.js";
|
|
4
|
+
import { Command as le, CommandInput as ne, CommandList as ae, CommandEmpty as se, CommandGroup as k, CommandItem as D } from "./command.js";
|
|
5
|
+
import { Label as oe } from "./label.js";
|
|
6
|
+
import { cn as g } from "../../lib/utils.js";
|
|
7
7
|
import * as s from "react";
|
|
8
|
-
import { Checkbox as
|
|
9
|
-
import { Icon as
|
|
10
|
-
import { Popover as
|
|
11
|
-
import
|
|
12
|
-
const
|
|
8
|
+
import { Checkbox as ie } from "./checkbox.js";
|
|
9
|
+
import { Icon as j } from "./icon.js";
|
|
10
|
+
import { Popover as de, PopoverTrigger as ce, PopoverContent as ue } from "./popover.js";
|
|
11
|
+
import me from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
|
|
12
|
+
const fe = {
|
|
13
13
|
sm: "min-h-8 h-8 text-xs py-1.5",
|
|
14
14
|
default: "min-h-9 h-9 text-sm py-2",
|
|
15
15
|
lg: "min-h-10 h-10 text-base py-2"
|
|
16
|
-
},
|
|
16
|
+
}, he = {
|
|
17
17
|
sm: "h-5 w-5",
|
|
18
18
|
default: "h-5 w-5",
|
|
19
19
|
lg: "h-5.5 w-5.5"
|
|
20
20
|
};
|
|
21
|
-
function
|
|
21
|
+
function Se(B) {
|
|
22
22
|
const {
|
|
23
23
|
multiple: a = !1,
|
|
24
|
-
options:
|
|
24
|
+
options: f,
|
|
25
25
|
value: N,
|
|
26
|
-
defaultValue:
|
|
27
|
-
onValueChange:
|
|
28
|
-
onClear:
|
|
29
|
-
placeholder:
|
|
30
|
-
emptyPlaceholder:
|
|
31
|
-
searchPlaceholder:
|
|
32
|
-
addItemPlaceholder:
|
|
33
|
-
itemCountMessage:
|
|
34
|
-
maxSelectedMessage:
|
|
26
|
+
defaultValue: A,
|
|
27
|
+
onValueChange: R,
|
|
28
|
+
onClear: b,
|
|
29
|
+
placeholder: E = "Seleziona...",
|
|
30
|
+
emptyPlaceholder: F = "Nessun risultato",
|
|
31
|
+
searchPlaceholder: L = "Cerca...",
|
|
32
|
+
addItemPlaceholder: T = "Aggiungi",
|
|
33
|
+
itemCountMessage: W = (e) => `${e} elementi selezionati`,
|
|
34
|
+
maxSelectedMessage: X = (e) => `Puoi selezionare fino a ${e} elementi`,
|
|
35
35
|
label: S,
|
|
36
|
-
className:
|
|
37
|
-
wrpClassName:
|
|
36
|
+
className: $ = "",
|
|
37
|
+
wrpClassName: q = "",
|
|
38
38
|
searchable: P = !1,
|
|
39
|
-
creatable:
|
|
40
|
-
groupBy:
|
|
39
|
+
creatable: G = !1,
|
|
40
|
+
groupBy: v = "group",
|
|
41
41
|
maxSelected: i,
|
|
42
|
-
showChipsInsteadOfCount:
|
|
43
|
-
disabled:
|
|
42
|
+
showChipsInsteadOfCount: H = !1,
|
|
43
|
+
disabled: x,
|
|
44
44
|
size: V = "default"
|
|
45
|
-
} =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
} = B, [C, w] = s.useState(!1), [d, y] = s.useState(""), c = s.useRef(null), [J, K] = s.useState(0), [Q, z] = s.useState(null);
|
|
46
|
+
s.useEffect(() => {
|
|
47
|
+
if (c.current) {
|
|
48
|
+
const e = c.current.closest(
|
|
49
|
+
'[data-slot="drawer-content"]'
|
|
50
|
+
);
|
|
51
|
+
e && z(e);
|
|
52
|
+
const l = c.current.closest(
|
|
53
|
+
'[data-slot="sheet-content"]'
|
|
54
|
+
);
|
|
55
|
+
l && z(l);
|
|
56
|
+
}
|
|
57
|
+
}, []);
|
|
58
|
+
const O = N !== void 0, [U, Y] = s.useState(A), u = O ? N : U, m = (e) => {
|
|
59
|
+
O || Y(e), R?.(e);
|
|
60
|
+
}, n = s.useMemo(() => a ? Array.isArray(u) ? u : [] : u != null ? [u] : [], [u, a]), p = s.useMemo(() => {
|
|
61
|
+
const e = f.filter((l) => n.includes(l.value));
|
|
49
62
|
if (a) {
|
|
50
|
-
const
|
|
51
|
-
return [...e, ...
|
|
52
|
-
} else if (
|
|
53
|
-
return [{ value:
|
|
63
|
+
const l = n.filter((r) => !e.find((h) => h.value === r)).map((r) => ({ value: r, label: r }));
|
|
64
|
+
return [...e, ...l];
|
|
65
|
+
} else if (n.length && !e.length)
|
|
66
|
+
return [{ value: n[0], label: n[0] }];
|
|
54
67
|
return e;
|
|
55
|
-
}, [
|
|
68
|
+
}, [f, n, a]), I = (e) => {
|
|
56
69
|
if (!e.disabled)
|
|
57
70
|
if (a) {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
71
|
+
const l = n.includes(e.value);
|
|
72
|
+
if (!l && i !== void 0 && n.length >= i)
|
|
60
73
|
return;
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
m(
|
|
75
|
+
l ? n.filter((r) => r !== e.value) : [...n, e.value]
|
|
63
76
|
);
|
|
64
77
|
} else
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
(e,
|
|
70
|
-
const r =
|
|
71
|
-
return e[r] = e[r] || [], e[r].push(
|
|
78
|
+
m(e.value), w(!1);
|
|
79
|
+
}, Z = s.useCallback(() => {
|
|
80
|
+
m([]), y(""), b && b();
|
|
81
|
+
}, [m, b]), _ = s.useMemo(() => v ? f.reduce(
|
|
82
|
+
(e, l) => {
|
|
83
|
+
const r = l[v] || "";
|
|
84
|
+
return e[r] = e[r] || [], e[r].push(l), e;
|
|
72
85
|
},
|
|
73
86
|
{}
|
|
74
|
-
) : { "":
|
|
87
|
+
) : { "": f }, [f, v]);
|
|
75
88
|
return s.useEffect(() => {
|
|
76
|
-
|
|
77
|
-
}, [
|
|
78
|
-
S && /* @__PURE__ */
|
|
89
|
+
C && c.current && K(c.current.getBoundingClientRect().width);
|
|
90
|
+
}, [C]), /* @__PURE__ */ o("div", { className: g("flex flex-col gap-2", q), children: [
|
|
91
|
+
S && /* @__PURE__ */ t(oe, { children: S }),
|
|
79
92
|
/* @__PURE__ */ o(
|
|
80
|
-
|
|
93
|
+
de,
|
|
81
94
|
{
|
|
82
|
-
open:
|
|
83
|
-
onOpenChange: (e) => !
|
|
95
|
+
open: x ? !1 : C,
|
|
96
|
+
onOpenChange: (e) => !x && w(e),
|
|
84
97
|
children: [
|
|
85
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ t(ce, { asChild: !0, children: /* @__PURE__ */ o(
|
|
86
99
|
"div",
|
|
87
100
|
{
|
|
88
|
-
ref:
|
|
89
|
-
className:
|
|
101
|
+
ref: c,
|
|
102
|
+
className: g(
|
|
90
103
|
"bg-d-input border-d-border/50 focus-within:ring-d-ring flex min-h-10 w-full min-w-[100px] items-center justify-between gap-2 rounded-md border px-3 py-2 text-sm focus-within:ring-1",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
fe[V],
|
|
105
|
+
x && "cursor-not-allowed opacity-50",
|
|
106
|
+
$
|
|
94
107
|
),
|
|
95
108
|
children: [
|
|
96
|
-
|
|
97
|
-
/* @__PURE__ */
|
|
98
|
-
|
|
109
|
+
p.length === 0 ? /* @__PURE__ */ t("span", { className: "text-d-muted-foreground", children: E }) : a ? /* @__PURE__ */ o("div", { className: "flex h-full w-full min-w-0 items-center justify-between gap-2", children: [
|
|
110
|
+
/* @__PURE__ */ t("div", { className: "flex min-w-0 flex-nowrap gap-1 overflow-auto", children: H ? /* @__PURE__ */ t(te, { children: p.map((e) => /* @__PURE__ */ o(
|
|
111
|
+
re,
|
|
99
112
|
{
|
|
100
113
|
variant: "secondary",
|
|
101
114
|
className: "hover:bg-d-secondary/100 bg-d-secondary/50 border-d-border flex cursor-pointer items-center gap-1 border",
|
|
102
|
-
onClick: (
|
|
103
|
-
|
|
115
|
+
onClick: (l) => {
|
|
116
|
+
l.stopPropagation(), I(e);
|
|
104
117
|
},
|
|
105
118
|
children: [
|
|
106
119
|
e.label,
|
|
107
|
-
!e.fixed && /* @__PURE__ */
|
|
120
|
+
!e.fixed && /* @__PURE__ */ t(j, { name: "X", size: "xs" })
|
|
108
121
|
]
|
|
109
122
|
},
|
|
110
123
|
e.value
|
|
111
|
-
)) }) : /* @__PURE__ */
|
|
112
|
-
/* @__PURE__ */
|
|
124
|
+
)) }) : /* @__PURE__ */ t("div", { children: W(p.length) }) }),
|
|
125
|
+
/* @__PURE__ */ t(
|
|
113
126
|
"div",
|
|
114
127
|
{
|
|
115
|
-
className:
|
|
128
|
+
className: g(
|
|
116
129
|
"border-d-input bg-d-accent flex aspect-square cursor-pointer items-center rounded-full p-1",
|
|
117
|
-
|
|
130
|
+
he[V]
|
|
118
131
|
),
|
|
119
132
|
onClick: (e) => {
|
|
120
|
-
e.stopPropagation(), e.preventDefault(),
|
|
133
|
+
e.stopPropagation(), e.preventDefault(), Z();
|
|
121
134
|
},
|
|
122
135
|
onMouseDown: (e) => e.preventDefault(),
|
|
123
|
-
children: /* @__PURE__ */
|
|
124
|
-
|
|
136
|
+
children: /* @__PURE__ */ t(
|
|
137
|
+
j,
|
|
125
138
|
{
|
|
126
139
|
name: "X",
|
|
127
140
|
size: "xs",
|
|
@@ -130,67 +143,68 @@ function ye(j) {
|
|
|
130
143
|
)
|
|
131
144
|
}
|
|
132
145
|
)
|
|
133
|
-
] }) : /* @__PURE__ */
|
|
134
|
-
/* @__PURE__ */
|
|
146
|
+
] }) : /* @__PURE__ */ t("span", { children: p[0]?.label }),
|
|
147
|
+
/* @__PURE__ */ t(me, { className: "h-4 w-4 opacity-50" })
|
|
135
148
|
]
|
|
136
149
|
}
|
|
137
150
|
) }),
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
|
|
151
|
+
/* @__PURE__ */ t(
|
|
152
|
+
ue,
|
|
140
153
|
{
|
|
141
154
|
className: "p-0",
|
|
142
|
-
style: { width:
|
|
155
|
+
style: { width: J },
|
|
143
156
|
align: "start",
|
|
144
157
|
sideOffset: 4,
|
|
158
|
+
container: Q,
|
|
145
159
|
children: /* @__PURE__ */ o(le, { shouldFilter: !!P, className: "w-full", children: [
|
|
146
|
-
P && /* @__PURE__ */
|
|
147
|
-
|
|
160
|
+
P && /* @__PURE__ */ t("div", { className: "border-d-border border-b p-0.5", children: /* @__PURE__ */ t(
|
|
161
|
+
ne,
|
|
148
162
|
{
|
|
149
|
-
placeholder:
|
|
163
|
+
placeholder: L,
|
|
150
164
|
value: d,
|
|
151
|
-
onValueChange:
|
|
165
|
+
onValueChange: y
|
|
152
166
|
}
|
|
153
167
|
) }),
|
|
154
|
-
/* @__PURE__ */ o(
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
|
|
157
|
-
|
|
168
|
+
/* @__PURE__ */ o(ae, { className: "max-h-60 overflow-auto overscroll-contain", children: [
|
|
169
|
+
/* @__PURE__ */ t(se, { children: F }),
|
|
170
|
+
G && d && /* @__PURE__ */ t(k, { children: /* @__PURE__ */ t(
|
|
171
|
+
D,
|
|
158
172
|
{
|
|
159
173
|
className: "cursor-pointer",
|
|
160
174
|
onSelect: () => {
|
|
161
|
-
d && (
|
|
175
|
+
d && (m(a ? [...n, d] : d), y(""), !a && w(!1));
|
|
162
176
|
},
|
|
163
177
|
children: /* @__PURE__ */ o("div", { className: "text-d-foreground text-xs", children: [
|
|
164
|
-
|
|
178
|
+
T,
|
|
165
179
|
" “",
|
|
166
180
|
d,
|
|
167
181
|
"”"
|
|
168
182
|
] })
|
|
169
183
|
}
|
|
170
184
|
) }),
|
|
171
|
-
Object.entries(
|
|
172
|
-
const
|
|
185
|
+
Object.entries(_).map(([e, l]) => /* @__PURE__ */ t(k, { heading: e || void 0, children: l.map((r) => {
|
|
186
|
+
const h = n.includes(r.value), ee = a && i !== void 0 && !h && n.length >= i, M = r.disabled || ee;
|
|
173
187
|
return /* @__PURE__ */ o(
|
|
174
|
-
|
|
188
|
+
D,
|
|
175
189
|
{
|
|
176
190
|
value: typeof r.label == "string" ? r.label : String(r.value),
|
|
177
|
-
onSelect: () => !
|
|
178
|
-
className:
|
|
191
|
+
onSelect: () => !M && I(r),
|
|
192
|
+
className: g(
|
|
179
193
|
"cursor-pointer",
|
|
180
|
-
|
|
181
|
-
!a &&
|
|
194
|
+
M && "cursor-not-allowed opacity-50",
|
|
195
|
+
!a && h && "bg-d-accent/75 text-d-accent-foreground"
|
|
182
196
|
// highlight single select
|
|
183
197
|
),
|
|
184
198
|
children: [
|
|
185
|
-
a && /* @__PURE__ */
|
|
186
|
-
/* @__PURE__ */
|
|
199
|
+
a && /* @__PURE__ */ t(ie, { checked: h, className: "mr-1" }),
|
|
200
|
+
/* @__PURE__ */ t("span", { children: r.label })
|
|
187
201
|
]
|
|
188
202
|
},
|
|
189
203
|
r.value
|
|
190
204
|
);
|
|
191
205
|
}) }, e))
|
|
192
206
|
] }),
|
|
193
|
-
a && i !== void 0 &&
|
|
207
|
+
a && i !== void 0 && n.length >= i && /* @__PURE__ */ t("div", { className: "border-d-border text-d-muted-foreground border-t px-2 py-1 text-xs", children: X(i) })
|
|
194
208
|
] })
|
|
195
209
|
}
|
|
196
210
|
)
|
|
@@ -200,5 +214,5 @@ function ye(j) {
|
|
|
200
214
|
] });
|
|
201
215
|
}
|
|
202
216
|
export {
|
|
203
|
-
|
|
217
|
+
Se as AppSelect
|
|
204
218
|
};
|
|
@@ -4,8 +4,8 @@ import * as l from "react";
|
|
|
4
4
|
import k from "../../node_modules/embla-carousel-react/esm/embla-carousel-react.esm.js";
|
|
5
5
|
import { cn as d } from "../../lib/utils.js";
|
|
6
6
|
import { Button as v } from "./button.js";
|
|
7
|
-
import z from "../../node_modules/lucide-react/dist/esm/icons/arrow-
|
|
8
|
-
import g from "../../node_modules/lucide-react/dist/esm/icons/arrow-
|
|
7
|
+
import z from "../../node_modules/lucide-react/dist/esm/icons/arrow-right.js";
|
|
8
|
+
import g from "../../node_modules/lucide-react/dist/esm/icons/arrow-left.js";
|
|
9
9
|
const p = l.createContext(null);
|
|
10
10
|
function m() {
|
|
11
11
|
const o = l.useContext(p);
|
|
@@ -136,7 +136,7 @@ function q({
|
|
|
136
136
|
onClick: i,
|
|
137
137
|
...s,
|
|
138
138
|
children: [
|
|
139
|
-
/* @__PURE__ */ a(
|
|
139
|
+
/* @__PURE__ */ a(g, {}),
|
|
140
140
|
/* @__PURE__ */ a("span", { className: "sr-only", children: "Previous slide" })
|
|
141
141
|
]
|
|
142
142
|
}
|
|
@@ -164,7 +164,7 @@ function F({
|
|
|
164
164
|
onClick: i,
|
|
165
165
|
...s,
|
|
166
166
|
children: [
|
|
167
|
-
/* @__PURE__ */ a(
|
|
167
|
+
/* @__PURE__ */ a(z, {}),
|
|
168
168
|
/* @__PURE__ */ a("span", { className: "sr-only", children: "Next slide" })
|
|
169
169
|
]
|
|
170
170
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { jsx as s, jsxs as f, Fragment as L } from "react/jsx-runtime";
|
|
3
3
|
import * as p from "react";
|
|
4
4
|
import { cn as l } from "../../lib/utils.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Legend as T } from "../../node_modules/recharts/es6/component/Legend.js";
|
|
6
|
+
import { Tooltip as I } from "../../node_modules/recharts/es6/component/Tooltip.js";
|
|
7
7
|
import { ResponsiveContainer as K } from "../../node_modules/recharts/es6/component/ResponsiveContainer.js";
|
|
8
8
|
const P = { light: "", dark: ".dark" }, N = p.createContext(null);
|
|
9
9
|
function j() {
|
|
@@ -60,7 +60,7 @@ ${t.map(([d, o]) => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
) : null;
|
|
63
|
-
}, z =
|
|
63
|
+
}, z = I;
|
|
64
64
|
function A({
|
|
65
65
|
active: c,
|
|
66
66
|
payload: e,
|
|
@@ -155,7 +155,7 @@ function A({
|
|
|
155
155
|
}
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
-
const B =
|
|
158
|
+
const B = T;
|
|
159
159
|
function D({
|
|
160
160
|
className: c,
|
|
161
161
|
hideIcon: e = !1,
|
|
@@ -18,7 +18,7 @@ const m = c.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ o(
|
|
|
18
18
|
}
|
|
19
19
|
));
|
|
20
20
|
m.displayName = "Command";
|
|
21
|
-
function
|
|
21
|
+
function y({
|
|
22
22
|
title: e = "Command Palette",
|
|
23
23
|
description: t = "Search for a command to run...",
|
|
24
24
|
children: r,
|
|
@@ -67,7 +67,7 @@ function N({
|
|
|
67
67
|
{
|
|
68
68
|
"data-slot": "command-list",
|
|
69
69
|
className: a(
|
|
70
|
-
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
70
|
+
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto overscroll-contain",
|
|
71
71
|
e
|
|
72
72
|
),
|
|
73
73
|
...t
|
|
@@ -149,7 +149,7 @@ function I({
|
|
|
149
149
|
}
|
|
150
150
|
export {
|
|
151
151
|
m as Command,
|
|
152
|
-
|
|
152
|
+
y as CommandDialog,
|
|
153
153
|
b as CommandEmpty,
|
|
154
154
|
C as CommandGroup,
|
|
155
155
|
w as CommandInput,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as t, jsxs as T } from "react/jsx-runtime";
|
|
3
|
+
import { createAsk as j } from "../../node_modules/use-ask/dist/index.js";
|
|
4
|
+
import { Dialog as U, DialogContent as O, DialogHeader as E, DialogTitle as L, DialogDescription as k } from "./dialog.js";
|
|
5
|
+
import { Icon as C } from "./icon.js";
|
|
6
|
+
import { getExt as M, guessKind as S, isHttpUrl as A, getOfficeEmbedUrl as z } from "../../lib/file-preview.js";
|
|
7
|
+
import { cn as H } from "../../lib/utils.js";
|
|
8
|
+
import { useRef as q, useState as x, useEffect as N, useMemo as g } from "react";
|
|
9
|
+
const [R, B] = j({});
|
|
10
|
+
function D(r) {
|
|
11
|
+
return typeof r == "string" ? { url: r } : r instanceof File ? { file: r, filename: r.name, mimeType: r.type } : typeof r == "function" ? { loader: r } : r && typeof r.then == "function" ? { loader: r } : r || {};
|
|
12
|
+
}
|
|
13
|
+
async function _(r) {
|
|
14
|
+
return R.ask(D(r));
|
|
15
|
+
}
|
|
16
|
+
function $(r) {
|
|
17
|
+
return R.safeAsk(D(r));
|
|
18
|
+
}
|
|
19
|
+
function I(r, s, a) {
|
|
20
|
+
const n = q(null), [d, u] = x(!1), [v, m] = x(null), [y, c] = x(null), [e, p] = x({});
|
|
21
|
+
N(() => {
|
|
22
|
+
if (!s) {
|
|
23
|
+
p({}), u(!1), m(null);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const i = r || {};
|
|
27
|
+
p({
|
|
28
|
+
url: i.url,
|
|
29
|
+
file: i.file,
|
|
30
|
+
filename: i.filename,
|
|
31
|
+
mimeType: i.mimeType,
|
|
32
|
+
title: i.title
|
|
33
|
+
});
|
|
34
|
+
const o = i.loader;
|
|
35
|
+
if (!o) return;
|
|
36
|
+
let f = !1;
|
|
37
|
+
return u(!0), m(null), (async () => {
|
|
38
|
+
try {
|
|
39
|
+
const l = typeof o == "function" ? await o() : await o;
|
|
40
|
+
if (f) return;
|
|
41
|
+
typeof l == "string" ? p((h) => ({ ...h, url: l })) : l instanceof File ? p((h) => ({
|
|
42
|
+
...h,
|
|
43
|
+
file: l,
|
|
44
|
+
filename: l.name,
|
|
45
|
+
mimeType: l.type
|
|
46
|
+
})) : l && typeof l == "object" && p((h) => ({ ...h, ...l }));
|
|
47
|
+
} catch (l) {
|
|
48
|
+
f || m(l?.message || "Errore durante il caricamento della preview");
|
|
49
|
+
} finally {
|
|
50
|
+
f || u(!1);
|
|
51
|
+
}
|
|
52
|
+
})(), () => {
|
|
53
|
+
f = !0;
|
|
54
|
+
};
|
|
55
|
+
}, [s, a, r]), N(() => {
|
|
56
|
+
if (e.file) {
|
|
57
|
+
const i = URL.createObjectURL(e.file);
|
|
58
|
+
return n.current = i, () => {
|
|
59
|
+
n.current && (URL.revokeObjectURL(n.current), n.current = null);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}, [e.file]);
|
|
63
|
+
const F = g(
|
|
64
|
+
() => e.file ? n.current || void 0 : e.url,
|
|
65
|
+
[e.file, e.url]
|
|
66
|
+
), w = g(
|
|
67
|
+
() => e.filename || e.file?.name || M(e.url || "") || "document",
|
|
68
|
+
[e.filename, e.file, e.url]
|
|
69
|
+
), b = g(
|
|
70
|
+
() => S({
|
|
71
|
+
mimeType: e.mimeType,
|
|
72
|
+
filename: w,
|
|
73
|
+
url: e.url
|
|
74
|
+
}),
|
|
75
|
+
[e.mimeType, w, e.url]
|
|
76
|
+
);
|
|
77
|
+
N(() => {
|
|
78
|
+
if (c(null), b === "text")
|
|
79
|
+
if (e.file) {
|
|
80
|
+
const i = new FileReader();
|
|
81
|
+
i.onload = (o) => {
|
|
82
|
+
if (typeof o.target?.result == "string") {
|
|
83
|
+
const f = o.target.result.length > 2e5 ? o.target.result.slice(0, 2e5) + `
|
|
84
|
+
…` : o.target.result;
|
|
85
|
+
c(f);
|
|
86
|
+
}
|
|
87
|
+
}, i.readAsText(e.file);
|
|
88
|
+
} else e.url && A(e.url) ? fetch(e.url).then((i) => i.text()).then(
|
|
89
|
+
(i) => c(i.length > 2e5 ? i.slice(0, 2e5) + `
|
|
90
|
+
…` : i)
|
|
91
|
+
).catch(() => c("Anteprima non disponibile")) : c("Anteprima non disponibile");
|
|
92
|
+
}, [b, e.file, e.url, a]);
|
|
93
|
+
const P = g(
|
|
94
|
+
() => /* @__PURE__ */ T("span", { className: "flex items-center gap-2", children: [
|
|
95
|
+
/* @__PURE__ */ t(C, { name: "File", className: "h-4 w-4" }),
|
|
96
|
+
r?.title || e.title || w
|
|
97
|
+
] }),
|
|
98
|
+
[r, e.title, w]
|
|
99
|
+
);
|
|
100
|
+
return { loading: d, error: v, src: F, text: y, kind: b, title: P };
|
|
101
|
+
}
|
|
102
|
+
const ee = () => {
|
|
103
|
+
const [{ key: r, payload: s }, { asking: a, cancel: n }] = B(), { loading: d, error: u, src: v, text: m, kind: y, title: c } = I(
|
|
104
|
+
s,
|
|
105
|
+
a,
|
|
106
|
+
r
|
|
107
|
+
);
|
|
108
|
+
return /* @__PURE__ */ t(U, { open: a, onOpenChange: (e) => !e && n(), children: /* @__PURE__ */ T(O, { size: "xl", className: "sm:max-w-4xl", children: [
|
|
109
|
+
/* @__PURE__ */ T(E, { children: [
|
|
110
|
+
/* @__PURE__ */ t(L, { children: c }),
|
|
111
|
+
u ? /* @__PURE__ */ t(k, { className: "text-red-600", children: u }) : null
|
|
112
|
+
] }),
|
|
113
|
+
/* @__PURE__ */ t("div", { className: H("relative", "max-h-[80vh] overflow-auto p-1"), children: d ? /* @__PURE__ */ t("div", { className: "grid h-[60vh] place-items-center", children: /* @__PURE__ */ t("div", { className: "border-d-border border-t-d-foreground h-10 w-10 animate-spin rounded-full border-2" }) }) : /* @__PURE__ */ t(K, { kind: y, src: v, text: m, officeUrl: v }) })
|
|
114
|
+
] }) });
|
|
115
|
+
}, K = ({
|
|
116
|
+
kind: r,
|
|
117
|
+
src: s,
|
|
118
|
+
text: a,
|
|
119
|
+
officeUrl: n
|
|
120
|
+
}) => {
|
|
121
|
+
if (!s && r !== "text" && r !== "office")
|
|
122
|
+
return /* @__PURE__ */ t("div", { className: "text-d-secondary-foreground", children: "Nessuna sorgente disponibile" });
|
|
123
|
+
switch (r) {
|
|
124
|
+
case "image":
|
|
125
|
+
return /* @__PURE__ */ t("div", { className: "grid place-items-center", children: /* @__PURE__ */ t(
|
|
126
|
+
"img",
|
|
127
|
+
{
|
|
128
|
+
src: s,
|
|
129
|
+
alt: "preview",
|
|
130
|
+
className: "max-h-[78vh] w-auto max-w-full object-contain"
|
|
131
|
+
}
|
|
132
|
+
) });
|
|
133
|
+
case "pdf":
|
|
134
|
+
return /* @__PURE__ */ t(
|
|
135
|
+
"iframe",
|
|
136
|
+
{
|
|
137
|
+
src: s,
|
|
138
|
+
title: "PDF Preview",
|
|
139
|
+
className: "h-[78vh] w-full rounded"
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
case "audio":
|
|
143
|
+
return /* @__PURE__ */ t("div", { className: "grid place-items-center", children: /* @__PURE__ */ t("audio", { controls: !0, className: "w-full max-w-2xl", children: /* @__PURE__ */ t("source", { src: s }) }) });
|
|
144
|
+
case "video":
|
|
145
|
+
return /* @__PURE__ */ t("div", { className: "grid place-items-center", children: /* @__PURE__ */ t("video", { controls: !0, className: "max-h-[78vh] w-full max-w-3xl rounded", children: /* @__PURE__ */ t("source", { src: s }) }) });
|
|
146
|
+
case "text":
|
|
147
|
+
return /* @__PURE__ */ t("pre", { className: "max-h-[78vh] overflow-auto rounded border p-3 text-sm whitespace-pre-wrap", children: a || "Caricamento…" });
|
|
148
|
+
case "office": {
|
|
149
|
+
if (n && A(n)) {
|
|
150
|
+
const d = z(n);
|
|
151
|
+
return /* @__PURE__ */ t(
|
|
152
|
+
"iframe",
|
|
153
|
+
{
|
|
154
|
+
src: d,
|
|
155
|
+
title: "Office Preview",
|
|
156
|
+
className: "h-[78vh] w-full rounded"
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return /* @__PURE__ */ t("div", { className: "rounded border p-3 text-sm", children: 'Anteprima Office non disponibile per file locali. Usa "Apri in nuova scheda" o "Download".' });
|
|
161
|
+
}
|
|
162
|
+
default:
|
|
163
|
+
return /* @__PURE__ */ t("div", { className: "rounded border p-3 text-sm", children: "Anteprima non disponibile per questo tipo di file." });
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
export {
|
|
167
|
+
ee as FilePreviewer,
|
|
168
|
+
_ as previewFileModal,
|
|
169
|
+
$ as safePreviewFileModal
|
|
170
|
+
};
|