laif-ds 0.2.18 → 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.
@@ -1,11 +1,12 @@
1
1
  "use client";
2
- import { jsxs as I, jsx as r, Fragment as L } from "react/jsx-runtime";
2
+ import { jsxs as v, jsx as r, Fragment as L } from "react/jsx-runtime";
3
3
  import c from "react";
4
- import { FilePreview as C } from "./file-preview.js";
5
- import { Card as A, CardHeader as S, CardTitle as B, CardContent as P } from "./card.js";
6
- import { Icon as _ } from "./icon.js";
7
- import { Input as W } from "./input.js";
8
- const H = {
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
- }, $ = (p) => Math.ceil(p / (1024 * 1024)), Q = ({
26
- accept: p,
27
- extensions: y = ["pdf", "image", "video", "audio"],
28
- multiple: d = !1,
29
- onUpload: v,
30
- description: b = "Trascina un file o clicca per selezionare",
31
- formatDescription: N = "Formato accettato: PDF, Immagini, Video, Audio",
32
- selectedLabel: m = "File selezionati",
33
- maxTotalSize: n,
34
- maxFiles: g
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 f = p ?? y.map((e) => H[e]).join(","), [o, x] = c.useState([]), [w, D] = c.useState(""), a = (e) => {
37
- const i = Array.from(e).filter(
38
- (s) => f.split(",").some((t) => (t = t.trim(), s.type.startsWith(t.replace("/*", "")) || s.name.toLowerCase().endsWith(t.replace("*", ""))))
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 l = [];
41
- const u = [];
42
- if (d) {
43
- let s = i;
44
- if (typeof g == "number") {
45
- const t = Math.max(g - o.length, 0);
46
- t < i.length && (s = i.slice(0, t), u.push(`Max ${g} file`));
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 n == "number") {
49
- const t = n;
50
- let M = o.reduce((h, E) => h + (E.size || 0), 0);
51
- const j = [];
52
- let z = !1;
53
- for (const h of s)
54
- M + (h.size || 0) <= t ? (j.push(h), M += h.size || 0) : z || (u.push(`Max ${$(t)} MB`), z = !0);
55
- s = j;
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
- l = [...o, ...s];
58
+ d = [...n, ...o];
58
59
  } else {
59
- const s = i[0] ? [i[0]] : [];
60
- if (typeof n == "number" && s[0]) {
61
- const t = n;
62
- (s[0].size || 0) > t ? (u.push(`Max ${$(t)} MB`), l = o) : l = s;
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
- l = s;
65
+ d = o;
65
66
  }
66
- x(l), D(u.join(" • ")), v?.(l);
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.preventDefault(), a(e.dataTransfer.files);
71
- }, F = (e) => {
72
- const i = o.filter((l, u) => u !== e);
73
- x(i), D(""), v?.(i);
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__ */ I("div", { className: "mx-auto w-full space-y-4", children: [
76
- (d || o.length === 0) && /* @__PURE__ */ r(
77
- K,
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: f,
80
- multiple: d,
81
- onDrop: k,
82
- onChange: R,
83
- description: b,
84
- formatDescription: N,
85
- errorCaption: w
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
- o.length > 0 && /* @__PURE__ */ r(L, { children: /* @__PURE__ */ I(A, { size: "sm", className: "shadow-none", children: [
89
- /* @__PURE__ */ r(S, { children: /* @__PURE__ */ r(B, { children: m }) }),
90
- /* @__PURE__ */ r(P, { children: d ? /* @__PURE__ */ r("div", { className: "flex flex-nowrap gap-2 overflow-x-auto py-2", children: o.map((e, i) => /* @__PURE__ */ r(
91
- C,
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: () => F(i)
107
+ onRemove: () => j(s)
95
108
  },
96
- e.name + i
97
- )) }) : /* @__PURE__ */ r(C, { file: o[0], onRemove: () => F(0) }) })
109
+ e.name + s
110
+ )) }) : /* @__PURE__ */ r(M, { file: n[0], onRemove: () => j(0) }) })
98
111
  ] }) })
99
112
  ] });
100
- }, K = ({
101
- accept: p,
102
- multiple: y,
103
- onDrop: d,
104
- onChange: v,
105
- description: b,
113
+ }, O = ({
114
+ accept: g,
115
+ multiple: f,
116
+ onDrop: b,
117
+ onChange: y,
118
+ description: w,
106
119
  formatDescription: N,
107
- errorCaption: m
120
+ errorCaption: l
108
121
  }) => {
109
- const n = c.useRef(null), [g, f] = c.useState(!1), o = c.useId(), x = c.useId(), w = c.useId(), D = c.useId();
110
- return /* @__PURE__ */ I(
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": b || "Seleziona file",
116
- "aria-describedby": `${o} ${x}${m ? ` ${w}` : ""}`,
117
- onKeyDown: (a) => {
118
- (a.key === "Enter" || a.key === " ") && (a.preventDefault(), n.current && (n.current.value = "", n.current.click()));
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
- n.current && (n.current.value = "", n.current.click());
134
+ a.current && (a.current.value = "", a.current.click());
122
135
  },
123
- onDragEnter: () => f(!0),
124
- onDragOver: (a) => a.preventDefault(),
125
- onDragLeave: () => f(!1),
126
- onDrop: (a) => {
127
- f(!1), d(a);
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 ${g ? "bg-muted/40" : ""}`,
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__ */ I("div", { className: "max-w-xs text-center", children: [
139
- /* @__PURE__ */ r("p", { id: o, className: "text-d-muted-foreground text-sm font-medium", children: b }),
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: x,
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
- m ? /* @__PURE__ */ r("p", { id: w, className: "mt-2 text-xs font-medium text-red-600", children: m }) : null
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
- W,
164
+ H,
152
165
  {
153
- ref: n,
154
- id: D,
166
+ ref: a,
167
+ id: I,
155
168
  type: "file",
156
169
  className: "hidden",
157
- accept: p,
158
- multiple: y,
159
- onChange: v
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
- Q as FileUploader
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
  }
package/dist/lib/utils.js CHANGED
@@ -1,47 +1,53 @@
1
1
  "use client";
2
- import { clsx as r } from "../node_modules/clsx/dist/clsx.js";
3
- import { twMerge as l } from "../node_modules/tailwind-merge/dist/bundle-mjs.js";
4
- function g(...t) {
5
- return l(r(t));
2
+ import { guessKind as l, getOfficeEmbedUrl as m } from "./file-preview.js";
3
+ import { clsx as d } from "../node_modules/clsx/dist/clsx.js";
4
+ import { twMerge as p } from "../node_modules/tailwind-merge/dist/bundle-mjs.js";
5
+ function u(...n) {
6
+ return p(d(n));
6
7
  }
7
- const h = (t) => {
8
- if (!t) return "#777777";
9
- let n = 0;
10
- for (let p = 0; p < t.length; p += 1)
11
- n = t.charCodeAt(p) + ((n << 5) - n), n &= n;
12
- let e = n >> 16 & 255, o = n >> 8 & 255, c = n & 255;
13
- const i = 60, a = 200;
14
- e = Math.min(a, Math.max(i, e)), o = Math.min(a, Math.max(i, o)), c = Math.min(a, Math.max(i, c));
15
- const s = (p) => p.toString(16).padStart(2, "0");
16
- return `#${s(e)}${s(o)}${s(c)}`;
17
- }, x = (t, n) => {
18
- let e = t.replace("#", "");
19
- e.length === 3 && (e = e.split("").map((s) => s + s).join(""));
20
- const o = parseInt(e, 16), c = o >> 16 & 255, i = o >> 8 & 255, a = o & 255;
21
- return `rgba(${c}, ${i}, ${a}, ${n})`;
22
- }, b = (t) => {
23
- const n = parseInt(t.replace("#", ""), 16), e = n >> 16 & 255, o = n >> 8 & 255, c = n & 255;
24
- return (0.299 * e + 0.587 * o + 0.114 * c) / 255 > 0.5 ? "#000000" : "#FFFFFF";
25
- }, f = (t, n) => {
26
- if (!t) return;
27
- const e = n?.split(".").pop()?.toLowerCase() || "";
28
- if (["pdf", "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg"].includes(e))
29
- window.open(t, "_blank");
30
- else if (["doc", "docx", "xls", "xlsx", "ppt", "pptx"].includes(e)) {
31
- const o = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(t)}`;
32
- window.open(o, "_blank");
33
- } else
34
- window.open(t, "_blank");
35
- }, w = (t, n) => {
36
- if (!t) return;
37
- const e = document.createElement("a");
38
- e.href = t, e.download = n || "document", e.style.display = "none", document.body.appendChild(e), e.click(), document.body.removeChild(e);
8
+ const b = (n) => {
9
+ if (!n) return "#777777";
10
+ let e = 0;
11
+ for (let s = 0; s < n.length; s += 1)
12
+ e = n.charCodeAt(s) + ((e << 5) - e), e &= e;
13
+ let t = e >> 16 & 255, o = e >> 8 & 255, r = e & 255;
14
+ const c = 60, a = 200;
15
+ t = Math.min(a, Math.max(c, t)), o = Math.min(a, Math.max(c, o)), r = Math.min(a, Math.max(c, r));
16
+ const i = (s) => s.toString(16).padStart(2, "0");
17
+ return `#${i(t)}${i(o)}${i(r)}`;
18
+ }, w = (n, e) => {
19
+ let t = n.replace("#", "");
20
+ t.length === 3 && (t = t.split("").map((i) => i + i).join(""));
21
+ const o = parseInt(t, 16), r = o >> 16 & 255, c = o >> 8 & 255, a = o & 255;
22
+ return `rgba(${r}, ${c}, ${a}, ${e})`;
23
+ }, x = (n) => {
24
+ const e = parseInt(n.replace("#", ""), 16), t = e >> 16 & 255, o = e >> 8 & 255, r = e & 255;
25
+ return (0.299 * t + 0.587 * o + 0.114 * r) / 255 > 0.5 ? "#000000" : "#FFFFFF";
26
+ }, y = (n, e) => {
27
+ if (!n) return;
28
+ const t = n.split("?")[1] || "";
29
+ let o = "";
30
+ try {
31
+ const c = new URLSearchParams(t);
32
+ o = c.get("response-content-type") || c.get("content-type") || "";
33
+ } catch {
34
+ }
35
+ if (l({ mimeType: o, filename: e, url: n }) === "office") {
36
+ const c = m(n);
37
+ window.open(c, "_blank");
38
+ return;
39
+ }
40
+ window.open(n, "_blank");
41
+ }, F = (n, e) => {
42
+ if (!n) return;
43
+ const t = document.createElement("a");
44
+ t.href = n, t.download = e || "document", t.style.display = "none", document.body.appendChild(t), t.click(), document.body.removeChild(t);
39
45
  };
40
46
  export {
41
- g as cn,
42
- w as downloadFile,
43
- b as hexContrast,
44
- x as hexToRgba,
45
- f as previewFile,
46
- h as stringToHexColor
47
+ u as cn,
48
+ F as downloadFile,
49
+ x as hexContrast,
50
+ w as hexToRgba,
51
+ y as previewFile,
52
+ b as stringToHexColor
47
53
  };
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { __module as x } from "../../_virtual/index6.js";
2
+ import { __module as x } from "../../_virtual/index7.js";
3
3
  var w;
4
4
  function O() {
5
5
  return w ? x.exports : (w = 1, function(d) {
@@ -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/index4.js";
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,5 +1,5 @@
1
1
  "use client";
2
- import { __exports as r } from "../../../_virtual/index7.js";
2
+ import { __exports as r } from "../../../_virtual/index6.js";
3
3
  import { __require as c } from "../../inline-style-parser/index.js";
4
4
  var f;
5
5
  function j() {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { bail as P } from "../../bail/index.js";
3
- import y from "../../../_virtual/index5.js";
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";