laif-ds 0.2.19 → 0.2.20
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 +5 -5
- package/dist/_virtual/index5.js +5 -5
- package/dist/components/ui/file-preview.js +215 -138
- package/dist/components/ui/file-previewer.js +1 -1
- package/dist/components/ui/file-uploader.js +109 -96
- package/dist/index.d.ts +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 +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
2
|
+
import { jsxs as v, jsx as r, Fragment as L } from "react/jsx-runtime";
|
|
3
3
|
import c from "react";
|
|
4
|
-
import {
|
|
5
|
-
import { Card as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
4
|
+
import { Button as A } from "./button.js";
|
|
5
|
+
import { Card as B, CardHeader as S, CardTitle as P, CardContent as _ } from "./card.js";
|
|
6
|
+
import { FilePreview as M } from "./file-preview.js";
|
|
7
|
+
import { Icon as W } from "./icon.js";
|
|
8
|
+
import { Input as H } from "./input.js";
|
|
9
|
+
const K = {
|
|
9
10
|
pdf: "application/pdf",
|
|
10
11
|
doc: ".doc",
|
|
11
12
|
docx: ".docx",
|
|
@@ -22,141 +23,153 @@ const H = {
|
|
|
22
23
|
image: "image/*",
|
|
23
24
|
video: "video/*",
|
|
24
25
|
audio: "audio/*"
|
|
25
|
-
}, $ = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
maxFiles:
|
|
26
|
+
}, $ = (g) => Math.ceil(g / (1024 * 1024)), X = ({
|
|
27
|
+
extensions: g = ["pdf", "image", "video", "audio"],
|
|
28
|
+
multiple: f = !1,
|
|
29
|
+
onUpload: b,
|
|
30
|
+
description: y = "Trascina un file o clicca per selezionare",
|
|
31
|
+
formatDescription: w = "Formato accettato: PDF, Immagini, Video, Audio",
|
|
32
|
+
selectedLabel: N = "File selezionati",
|
|
33
|
+
maxTotalSize: l,
|
|
34
|
+
removeAllLabel: a = "rimuovi tutto",
|
|
35
|
+
maxFiles: x
|
|
35
36
|
}) => {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
(
|
|
37
|
+
const u = g.map((e) => K[e]).join(","), [n, p] = c.useState([]), [D, I] = c.useState(""), i = (e) => {
|
|
38
|
+
const s = Array.from(e).filter(
|
|
39
|
+
(o) => u.split(",").some((t) => (t = t.trim(), o.type.startsWith(t.replace("/*", "")) || o.name.toLowerCase().endsWith(t.replace("*", ""))))
|
|
39
40
|
);
|
|
40
|
-
let
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
let
|
|
44
|
-
if (typeof
|
|
45
|
-
const t = Math.max(
|
|
46
|
-
t <
|
|
41
|
+
let d = [];
|
|
42
|
+
const m = [];
|
|
43
|
+
if (f) {
|
|
44
|
+
let o = s;
|
|
45
|
+
if (typeof x == "number") {
|
|
46
|
+
const t = Math.max(x - n.length, 0);
|
|
47
|
+
t < s.length && (o = s.slice(0, t), m.push(`Max ${x} file`));
|
|
47
48
|
}
|
|
48
|
-
if (typeof
|
|
49
|
-
const t =
|
|
50
|
-
let
|
|
51
|
-
const
|
|
52
|
-
let
|
|
53
|
-
for (const h of
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (typeof l == "number") {
|
|
50
|
+
const t = l;
|
|
51
|
+
let z = n.reduce((h, E) => h + (E.size || 0), 0);
|
|
52
|
+
const C = [];
|
|
53
|
+
let F = !1;
|
|
54
|
+
for (const h of o)
|
|
55
|
+
z + (h.size || 0) <= t ? (C.push(h), z += h.size || 0) : F || (m.push(`Max ${$(t)} MB`), F = !0);
|
|
56
|
+
o = C;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
d = [...n, ...o];
|
|
58
59
|
} else {
|
|
59
|
-
const
|
|
60
|
-
if (typeof
|
|
61
|
-
const t =
|
|
62
|
-
(
|
|
60
|
+
const o = s[0] ? [s[0]] : [];
|
|
61
|
+
if (typeof l == "number" && o[0]) {
|
|
62
|
+
const t = l;
|
|
63
|
+
(o[0].size || 0) > t ? (m.push(`Max ${$(t)} MB`), d = n) : d = o;
|
|
63
64
|
} else
|
|
64
|
-
|
|
65
|
+
d = o;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
}, R = (e) => {
|
|
68
|
-
e.target.files && a(e.target.files), e.target.value = "";
|
|
67
|
+
p(d), I(m.join(" • ")), b?.(d);
|
|
69
68
|
}, k = (e) => {
|
|
70
|
-
e.
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
e.target.files && i(e.target.files), e.target.value = "";
|
|
70
|
+
}, R = (e) => {
|
|
71
|
+
e.preventDefault(), i(e.dataTransfer.files);
|
|
72
|
+
}, j = (e) => {
|
|
73
|
+
const s = n.filter((d, m) => m !== e);
|
|
74
|
+
p(s), I(""), b?.(s);
|
|
74
75
|
};
|
|
75
|
-
return /* @__PURE__ */
|
|
76
|
-
(
|
|
77
|
-
|
|
76
|
+
return /* @__PURE__ */ v("div", { className: "mx-auto w-full space-y-4", children: [
|
|
77
|
+
(f || n.length === 0) && /* @__PURE__ */ r(
|
|
78
|
+
O,
|
|
78
79
|
{
|
|
79
|
-
accept:
|
|
80
|
-
multiple:
|
|
81
|
-
onDrop:
|
|
82
|
-
onChange:
|
|
83
|
-
description:
|
|
84
|
-
formatDescription:
|
|
85
|
-
errorCaption:
|
|
80
|
+
accept: u,
|
|
81
|
+
multiple: f,
|
|
82
|
+
onDrop: R,
|
|
83
|
+
onChange: k,
|
|
84
|
+
description: y,
|
|
85
|
+
formatDescription: w,
|
|
86
|
+
errorCaption: D
|
|
86
87
|
}
|
|
87
88
|
),
|
|
88
|
-
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
n.length > 0 && /* @__PURE__ */ r(L, { children: /* @__PURE__ */ v(B, { size: "sm", className: "shadow-none", children: [
|
|
90
|
+
/* @__PURE__ */ v(S, { className: "flex justify-between", children: [
|
|
91
|
+
/* @__PURE__ */ r(P, { children: N }),
|
|
92
|
+
/* @__PURE__ */ r(
|
|
93
|
+
A,
|
|
94
|
+
{
|
|
95
|
+
size: "sm",
|
|
96
|
+
variant: "ghost",
|
|
97
|
+
className: "text-xs",
|
|
98
|
+
onClick: () => p([]),
|
|
99
|
+
children: a
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] }),
|
|
103
|
+
/* @__PURE__ */ r(_, { children: f ? /* @__PURE__ */ r("div", { className: "flex flex-nowrap gap-2 overflow-x-auto py-2", children: n.map((e, s) => /* @__PURE__ */ r(
|
|
104
|
+
M,
|
|
92
105
|
{
|
|
93
106
|
file: e,
|
|
94
|
-
onRemove: () =>
|
|
107
|
+
onRemove: () => j(s)
|
|
95
108
|
},
|
|
96
|
-
e.name +
|
|
97
|
-
)) }) : /* @__PURE__ */ r(
|
|
109
|
+
e.name + s
|
|
110
|
+
)) }) : /* @__PURE__ */ r(M, { file: n[0], onRemove: () => j(0) }) })
|
|
98
111
|
] }) })
|
|
99
112
|
] });
|
|
100
|
-
},
|
|
101
|
-
accept:
|
|
102
|
-
multiple:
|
|
103
|
-
onDrop:
|
|
104
|
-
onChange:
|
|
105
|
-
description:
|
|
113
|
+
}, O = ({
|
|
114
|
+
accept: g,
|
|
115
|
+
multiple: f,
|
|
116
|
+
onDrop: b,
|
|
117
|
+
onChange: y,
|
|
118
|
+
description: w,
|
|
106
119
|
formatDescription: N,
|
|
107
|
-
errorCaption:
|
|
120
|
+
errorCaption: l
|
|
108
121
|
}) => {
|
|
109
|
-
const
|
|
110
|
-
return /* @__PURE__ */
|
|
122
|
+
const a = c.useRef(null), [x, u] = c.useState(!1), n = c.useId(), p = c.useId(), D = c.useId(), I = c.useId();
|
|
123
|
+
return /* @__PURE__ */ v(
|
|
111
124
|
"div",
|
|
112
125
|
{
|
|
113
126
|
role: "button",
|
|
114
127
|
tabIndex: 0,
|
|
115
|
-
"aria-label":
|
|
116
|
-
"aria-describedby": `${
|
|
117
|
-
onKeyDown: (
|
|
118
|
-
(
|
|
128
|
+
"aria-label": w || "Seleziona file",
|
|
129
|
+
"aria-describedby": `${n} ${p}${l ? ` ${D}` : ""}`,
|
|
130
|
+
onKeyDown: (i) => {
|
|
131
|
+
(i.key === "Enter" || i.key === " ") && (i.preventDefault(), a.current && (a.current.value = "", a.current.click()));
|
|
119
132
|
},
|
|
120
133
|
onClick: () => {
|
|
121
|
-
|
|
134
|
+
a.current && (a.current.value = "", a.current.click());
|
|
122
135
|
},
|
|
123
|
-
onDragEnter: () =>
|
|
124
|
-
onDragOver: (
|
|
125
|
-
onDragLeave: () =>
|
|
126
|
-
onDrop: (
|
|
127
|
-
|
|
136
|
+
onDragEnter: () => u(!0),
|
|
137
|
+
onDragOver: (i) => i.preventDefault(),
|
|
138
|
+
onDragLeave: () => u(!1),
|
|
139
|
+
onDrop: (i) => {
|
|
140
|
+
u(!1), b(i);
|
|
128
141
|
},
|
|
129
|
-
className: `border-d-border flex w-full cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed px-4 py-8 ${
|
|
142
|
+
className: `border-d-border flex w-full cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed px-4 py-8 ${x ? "bg-muted/40" : ""}`,
|
|
130
143
|
children: [
|
|
131
144
|
/* @__PURE__ */ r(
|
|
132
|
-
|
|
145
|
+
W,
|
|
133
146
|
{
|
|
134
147
|
name: "ArrowUpFromLine",
|
|
135
148
|
className: "text-d-muted-foreground h-10 w-10"
|
|
136
149
|
}
|
|
137
150
|
),
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
/* @__PURE__ */ r("p", { id:
|
|
151
|
+
/* @__PURE__ */ v("div", { className: "max-w-xs text-center", children: [
|
|
152
|
+
/* @__PURE__ */ r("p", { id: n, className: "text-d-muted-foreground text-sm font-medium", children: w }),
|
|
140
153
|
/* @__PURE__ */ r(
|
|
141
154
|
"p",
|
|
142
155
|
{
|
|
143
|
-
id:
|
|
156
|
+
id: p,
|
|
144
157
|
className: "text-d-muted-foreground text-muted-foreground mt-1 text-xs",
|
|
145
158
|
children: N
|
|
146
159
|
}
|
|
147
160
|
),
|
|
148
|
-
|
|
161
|
+
l ? /* @__PURE__ */ r("p", { id: D, className: "mt-2 text-xs font-medium text-red-600", children: l }) : null
|
|
149
162
|
] }),
|
|
150
163
|
/* @__PURE__ */ r(
|
|
151
|
-
|
|
164
|
+
H,
|
|
152
165
|
{
|
|
153
|
-
ref:
|
|
154
|
-
id:
|
|
166
|
+
ref: a,
|
|
167
|
+
id: I,
|
|
155
168
|
type: "file",
|
|
156
169
|
className: "hidden",
|
|
157
|
-
accept:
|
|
158
|
-
multiple:
|
|
159
|
-
onChange:
|
|
170
|
+
accept: g,
|
|
171
|
+
multiple: f,
|
|
172
|
+
onChange: y
|
|
160
173
|
}
|
|
161
174
|
)
|
|
162
175
|
]
|
|
@@ -164,5 +177,5 @@ const H = {
|
|
|
164
177
|
);
|
|
165
178
|
};
|
|
166
179
|
export {
|
|
167
|
-
|
|
180
|
+
X as FileUploader
|
|
168
181
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -893,13 +893,13 @@ declare interface FilePreviewProps {
|
|
|
893
893
|
export declare const FileUploader: default_2.FC<FileUploaderProps>;
|
|
894
894
|
|
|
895
895
|
declare interface FileUploaderProps {
|
|
896
|
-
accept?: string;
|
|
897
896
|
extensions?: AcceptItem[];
|
|
898
897
|
multiple?: boolean;
|
|
899
898
|
onUpload?: (files: File[]) => void;
|
|
900
899
|
description?: string;
|
|
901
900
|
formatDescription?: string;
|
|
902
901
|
selectedLabel?: string;
|
|
902
|
+
removeAllLabel?: string;
|
|
903
903
|
maxTotalSize?: number;
|
|
904
904
|
maxFiles?: number;
|
|
905
905
|
}
|
|
@@ -3,7 +3,7 @@ import { stringify as w } from "../../comma-separated-tokens/index.js";
|
|
|
3
3
|
import { ok as u } from "../../devlop/lib/default.js";
|
|
4
4
|
import { svg as m, html as C } from "../../property-information/index.js";
|
|
5
5
|
import { stringify as N } from "../../space-separated-tokens/index.js";
|
|
6
|
-
import S from "../../../_virtual/
|
|
6
|
+
import S from "../../../_virtual/index5.js";
|
|
7
7
|
import { whitespace as j } from "../../hast-util-whitespace/lib/index.js";
|
|
8
8
|
import { name as x } from "../../estree-util-is-identifier-name/lib/index.js";
|
|
9
9
|
import { VFileMessage as h } from "../../vfile-message/lib/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { bail as P } from "../../bail/index.js";
|
|
3
|
-
import y from "../../../_virtual/
|
|
3
|
+
import y from "../../../_virtual/index4.js";
|
|
4
4
|
import z from "../../is-plain-obj/index.js";
|
|
5
5
|
import { CallableInstance as C } from "./callable-instance.js";
|
|
6
6
|
import { trough as A } from "../../trough/lib/index.js";
|