vlite3 0.3.1 → 0.3.4

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
- import { defineComponent as K, ref as S, useSlots as O, computed as v, openBlock as a, createElementBlock as u, createElementVNode as s, renderSlot as q, normalizeClass as z, createBlock as y, withModifiers as D, createVNode as b, createTextVNode as H, toDisplayString as F, createCommentVNode as x, Fragment as J, renderList as Q } from "vue";
2
- import f from "../Icon.vue.js";
3
- import T from "../Button.vue.js";
4
- const X = { class: "w-full" }, Y = ["multiple", "accept"], Z = ["value", "placeholder", "disabled"], _ = { class: "absolute right-3 top-1/2 -translate-y-1/2 flex items-center justify-center gap-2 bg-background" }, ee = { class: "p-3 bg-muted rounded-full text-muted-foreground" }, le = { class: "space-y-1" }, te = {
1
+ import { defineComponent as q, ref as F, useSlots as H, computed as y, openBlock as r, createElementBlock as c, createElementVNode as n, renderSlot as J, normalizeClass as S, createBlock as x, withModifiers as D, createVNode as k, createTextVNode as Q, toDisplayString as A, createCommentVNode as w, Fragment as X, renderList as Y } from "vue";
2
+ import g from "../Icon.vue.js";
3
+ import $ from "../Button.vue.js";
4
+ const Z = { class: "w-full" }, _ = ["multiple", "accept"], ee = ["value", "placeholder", "disabled"], le = { class: "absolute right-3 top-1/2 -translate-y-1/2 flex items-center justify-center gap-2 bg-background" }, te = { class: "p-3 bg-muted rounded-full text-muted-foreground" }, ae = { class: "space-y-1" }, ie = {
5
5
  key: 0,
6
6
  class: "text-xs text-muted-foreground"
7
7
  }, oe = {
8
8
  key: 1,
9
9
  class: "space-y-2"
10
- }, ie = { class: "shrink-0 mr-3" }, re = { class: "p-2 bg-primary-light rounded text-primary-fg-light" }, ae = { class: "flex-1 min-w-0" }, ne = { class: "text-sm font-medium text-foreground truncate" }, se = { class: "text-xs text-muted-foreground" }, de = { class: "flex-shrink-0 ml-3 flex gap-2" }, ue = {
10
+ }, re = { class: "shrink-0 mr-3" }, se = { class: "p-2 bg-primary-light rounded text-primary-fg-light" }, ne = { class: "flex-1 min-w-0" }, de = { class: "text-sm font-medium text-foreground truncate" }, ue = { class: "text-xs text-muted-foreground" }, ce = { class: "flex-shrink-0 ml-3 flex gap-2" }, fe = {
11
11
  key: 0,
12
12
  class: "flex gap-2"
13
- }, ce = {
13
+ }, me = {
14
14
  key: 2,
15
15
  class: "absolute inset-0 bg-white/60 backdrop-blur-[1px] flex items-center justify-center rounded-lg z-10"
16
- }, fe = { class: "bg-white p-2 rounded-full shadow-lg" }, ve = /* @__PURE__ */ K({
16
+ }, ge = { class: "bg-white p-2 rounded-full shadow-lg" }, ye = /* @__PURE__ */ q({
17
17
  name: "FilePicker",
18
18
  __name: "FilePicker",
19
19
  props: {
@@ -24,106 +24,126 @@ const X = { class: "w-full" }, Y = ["multiple", "accept"], Z = ["value", "placeh
24
24
  loading: { type: Boolean, default: !1 },
25
25
  disabled: { type: Boolean, default: !1 },
26
26
  maxSize: {},
27
+ maxFiles: {},
27
28
  variant: { default: "dropzone" },
28
29
  placeholder: {},
29
30
  size: { default: "md" },
30
31
  rounded: { default: "md" }
31
32
  },
32
33
  emits: ["update:modelValue", "change", "error"],
33
- setup(o, { emit: B }) {
34
- const e = o, c = B, C = S(null), m = S(!1), d = S(!1);
35
- O();
36
- const N = v(() => e.fileTypes.join(",")), k = v(() => Array.isArray(e.modelValue) ? e.modelValue.length > 0 : e.modelValue !== null), w = v(() => {
37
- let t = [];
38
- return Array.isArray(e.modelValue) ? t = e.modelValue : e.modelValue && (t = [e.modelValue]), t.map((l) => {
39
- if (typeof l == "string") {
40
- const r = l.split("/").pop() || "Unknown File";
34
+ setup(a, { emit: M }) {
35
+ const e = a, d = M, C = F(null), h = F(!1), u = F(!1);
36
+ H();
37
+ const N = y(() => e.fileTypes.join(",")), V = y(() => Array.isArray(e.modelValue) ? e.modelValue.length > 0 : e.modelValue !== null), b = y(() => {
38
+ let l = [];
39
+ return Array.isArray(e.modelValue) ? l = e.modelValue : e.modelValue && (l = [e.modelValue]), l.map((t) => {
40
+ if (typeof t == "string") {
41
+ const o = t.split("/").pop() || "Unknown File";
41
42
  return {
42
- fileName: decodeURIComponent(r),
43
+ fileName: decodeURIComponent(o),
43
44
  fileType: "unknown",
44
45
  fileSize: 0,
45
46
  file: null,
46
- base64: l,
47
+ base64: t,
47
48
  isUrl: !0
48
49
  };
49
50
  }
50
- return l;
51
+ return t;
51
52
  });
52
- }), g = () => {
53
- e.disabled || e.loading || d.value || C.value?.click();
54
- }, j = (t) => {
55
- t.preventDefault(), !(e.disabled || e.loading) && (m.value = !0);
56
- }, $ = (t) => {
57
- t.preventDefault(), m.value = !1;
58
- }, M = (t) => {
59
- t.preventDefault(), m.value = !1, !(e.disabled || e.loading || d.value) && t.dataTransfer?.files && A(t.dataTransfer.files);
60
- }, I = (t) => {
61
- const l = t.target;
62
- l.files && A(l.files), l.value = "";
63
- }, L = (t) => {
64
- if (t === 0 || !t) return "";
65
- const l = 1024, r = ["Bytes", "KB", "MB", "GB", "TB"], n = Math.floor(Math.log(t) / Math.log(l));
66
- return parseFloat((t / Math.pow(l, n)).toFixed(2)) + " " + r[n];
67
- }, P = (t) => new Promise((l, r) => {
68
- const n = new FileReader();
69
- n.readAsDataURL(t), n.onload = () => {
70
- typeof n.result == "string" ? l(n.result) : r(new Error("Failed to read file as base64"));
71
- }, n.onerror = (p) => r(p);
72
- }), A = async (t) => {
73
- if (t.length === 0) return;
74
- d.value = !0;
75
- const l = [], r = [], n = Array.from(t), p = e.multiSelect ? n : [n[0]];
53
+ }), p = () => {
54
+ if (!(e.disabled || e.loading || u.value)) {
55
+ if (e.multiSelect && e.maxFiles && (Array.isArray(e.modelValue) ? e.modelValue.length : e.modelValue ? 1 : 0) >= e.maxFiles) {
56
+ d("error", `Maximum ${e.maxFiles} files allowed`);
57
+ return;
58
+ }
59
+ C.value?.click();
60
+ }
61
+ }, j = (l) => {
62
+ l.preventDefault(), !(e.disabled || e.loading) && (h.value = !0);
63
+ }, L = (l) => {
64
+ l.preventDefault(), h.value = !1;
65
+ }, I = (l) => {
66
+ l.preventDefault(), h.value = !1, !(e.disabled || e.loading || u.value) && l.dataTransfer?.files && z(l.dataTransfer.files);
67
+ }, P = (l) => {
68
+ const t = l.target;
69
+ t.files && z(t.files), t.value = "";
70
+ }, E = (l) => {
71
+ if (l === 0 || !l) return "";
72
+ const t = 1024, o = ["Bytes", "KB", "MB", "GB", "TB"], s = Math.floor(Math.log(l) / Math.log(t));
73
+ return parseFloat((l / Math.pow(t, s)).toFixed(2)) + " " + o[s];
74
+ }, U = (l) => new Promise((t, o) => {
75
+ const s = new FileReader();
76
+ s.readAsDataURL(l), s.onload = () => {
77
+ typeof s.result == "string" ? t(s.result) : o(new Error("Failed to read file as base64"));
78
+ }, s.onerror = (f) => o(f);
79
+ }), z = async (l) => {
80
+ if (l.length === 0) return;
81
+ u.value = !0;
82
+ const t = [], o = [], s = Array.from(l);
83
+ let f = e.multiSelect ? s : [s[0]];
84
+ if (e.multiSelect && e.maxFiles) {
85
+ const i = Array.isArray(e.modelValue) ? e.modelValue.length : e.modelValue ? 1 : 0, m = e.maxFiles - i;
86
+ if (m <= 0) {
87
+ d("error", `Maximum ${e.maxFiles} files allowed`), u.value = !1;
88
+ return;
89
+ }
90
+ f.length > m && (o.push(`Only ${m} more file(s) allowed. Maximum ${e.maxFiles} files.`), f = f.slice(0, m));
91
+ }
76
92
  try {
77
- for (const i of p) {
78
- if (e.fileTypes.length > 0 && !e.fileTypes.some((h) => {
79
- if (h.startsWith("."))
80
- return i.name.toLowerCase().endsWith(h.toLowerCase());
81
- if (h.endsWith("/*")) {
82
- const G = h.split("/")[0];
83
- return i.type.startsWith(G);
93
+ for (const i of f) {
94
+ if (e.fileTypes.length > 0 && !e.fileTypes.some((v) => {
95
+ if (v.startsWith("."))
96
+ return i.name.toLowerCase().endsWith(v.toLowerCase());
97
+ if (v.endsWith("/*")) {
98
+ const K = v.split("/")[0];
99
+ return i.type.startsWith(K);
84
100
  }
85
- return i.type === h;
101
+ return i.type === v;
86
102
  })) {
87
- r.push(`File type not allowed: ${i.name}`);
103
+ o.push(`File type not allowed: ${i.name}`);
88
104
  continue;
89
105
  }
90
- if (e.maxSize && i.size > e.maxSize) {
91
- r.push(`File too large: ${i.name}`);
92
- continue;
93
- }
94
- let V = "";
95
- e.returnFormat === "base64" && (V = await P(i)), l.push({
106
+ let m = !1;
107
+ e.maxSize && i.size > e.maxSize && (o.push(`File too large: ${i.name}`), m = !0);
108
+ let T = "";
109
+ if (e.returnFormat === "base64" && !m)
110
+ try {
111
+ T = await U(i);
112
+ } catch (B) {
113
+ console.error("Base64 read failed", B);
114
+ }
115
+ t.push({
96
116
  fileName: i.name,
97
117
  fileType: i.type,
98
118
  fileSize: i.size,
99
119
  file: i,
100
- base64: V
120
+ base64: T
101
121
  });
102
122
  }
103
- if (r.length > 0 && c("error", r.join("; ")), l.length > 0) {
123
+ if (o.length > 0 && d("error", o.join("; ")), t.length > 0) {
104
124
  let i;
105
- e.multiSelect ? i = [...Array.isArray(e.modelValue) ? e.modelValue : [], ...l] : i = l[0], c("update:modelValue", i), c("change", i);
125
+ e.multiSelect ? i = [...Array.isArray(e.modelValue) ? e.modelValue : e.modelValue ? [e.modelValue] : [], ...t] : i = t[0], d("update:modelValue", i), d("change", i);
106
126
  }
107
127
  } catch (i) {
108
- console.error("Error processing files:", i), c("error", "Failed to process files");
128
+ console.error("Error processing files:", i), d("error", "Failed to process files");
109
129
  } finally {
110
- d.value = !1;
130
+ u.value = !1;
111
131
  }
112
- }, E = (t) => {
132
+ }, W = (l) => {
113
133
  if (!(e.disabled || e.loading))
114
134
  if (e.multiSelect && Array.isArray(e.modelValue)) {
115
- const l = [...e.modelValue];
116
- l.splice(t, 1), c("update:modelValue", l), c("change", l);
135
+ const t = [...e.modelValue];
136
+ t.splice(l, 1), d("update:modelValue", t), d("change", t);
117
137
  } else
118
- c("update:modelValue", null), c("change", null);
119
- }, U = () => {
120
- e.disabled || e.loading || (c("update:modelValue", null), c("change", null));
121
- }, W = v(() => k.value ? w.value.map((l) => l.fileName).join(", ") : ""), R = v(() => {
122
- const t = "block w-full bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 transition-all focus-visible:outline-none cursor-pointer", l = {
138
+ d("update:modelValue", null), d("change", null);
139
+ }, R = () => {
140
+ e.disabled || e.loading || (d("update:modelValue", null), d("change", null));
141
+ }, O = y(() => V.value ? b.value.map((t) => t.fileName).join(", ") : ""), G = y(() => {
142
+ const l = "block w-full bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 transition-all focus-visible:outline-none cursor-pointer", t = {
123
143
  sm: "h-8 text-xs",
124
144
  md: "h-10 text-sm",
125
145
  lg: "h-12 text-base"
126
- }, r = {
146
+ }, o = {
127
147
  none: "rounded-none",
128
148
  sm: "rounded-sm",
129
149
  md: "rounded-md",
@@ -133,153 +153,153 @@ const X = { class: "w-full" }, Y = ["multiple", "accept"], Z = ["value", "placeh
133
153
  full: "rounded-full"
134
154
  };
135
155
  return [
136
- t,
156
+ l,
137
157
  "border border-input focus-visible:border-primary",
138
158
  // Default outline style
139
- l[e.size],
140
- r[e.rounded],
159
+ t[e.size],
160
+ o[e.rounded],
141
161
  "pr-10",
142
162
  // Space for icon
143
163
  e.disabled ? "cursor-not-allowed opacity-50" : ""
144
164
  ].join(" ");
145
165
  });
146
- return (t, l) => (a(), u("div", X, [
147
- s("input", {
166
+ return (l, t) => (r(), c("div", Z, [
167
+ n("input", {
148
168
  ref_key: "fileInput",
149
169
  ref: C,
150
170
  type: "file",
151
- multiple: o.multiSelect,
171
+ multiple: a.multiSelect,
152
172
  accept: N.value,
153
173
  class: "hidden",
154
- onChange: I
155
- }, null, 40, Y),
156
- q(t.$slots, "trigger", {
157
- trigger: g,
158
- isDragging: m.value,
159
- isLoading: o.loading || d.value,
160
- files: w.value
174
+ onChange: P
175
+ }, null, 40, _),
176
+ J(l.$slots, "trigger", {
177
+ trigger: p,
178
+ isDragging: h.value,
179
+ isLoading: a.loading || u.value,
180
+ files: b.value
161
181
  }, () => [
162
- o.variant === "input" ? (a(), u("div", {
182
+ a.variant === "input" ? (r(), c("div", {
163
183
  key: 0,
164
184
  class: "relative",
165
- onClick: g
185
+ onClick: p
166
186
  }, [
167
- s("input", {
187
+ n("input", {
168
188
  type: "text",
169
- value: W.value,
170
- placeholder: o.placeholder || "Select file...",
189
+ value: O.value,
190
+ placeholder: a.placeholder || "Select file...",
171
191
  readonly: "",
172
- class: z(R.value),
173
- disabled: o.disabled || o.loading || d.value
174
- }, null, 10, Z),
175
- s("div", _, [
176
- o.loading || d.value ? (a(), y(f, {
192
+ class: S(G.value),
193
+ disabled: a.disabled || a.loading || u.value
194
+ }, null, 10, ee),
195
+ n("div", le, [
196
+ a.loading || u.value ? (r(), x(g, {
177
197
  key: 0,
178
198
  icon: "lucide:loader-2",
179
199
  class: "h-4 w-4 animate-spin text-muted-foreground"
180
- })) : k.value && !o.disabled ? (a(), u("button", {
200
+ })) : V.value && !a.disabled ? (r(), c("button", {
181
201
  key: 1,
182
202
  type: "button",
183
203
  class: "text-muted-foreground hover:text-foreground focus:outline-none",
184
- onClick: D(U, ["stop"])
204
+ onClick: D(R, ["stop"])
185
205
  }, [
186
- b(f, {
206
+ k(g, {
187
207
  icon: "lucide:x-circle",
188
208
  class: "h-4 w-4"
189
209
  })
190
- ])) : (a(), y(f, {
210
+ ])) : (r(), x(g, {
191
211
  key: 2,
192
212
  icon: "lucide:upload",
193
213
  class: "h-4 w-4 text-muted-foreground"
194
214
  }))
195
215
  ])
196
- ])) : (a(), u("div", {
216
+ ])) : (r(), c("div", {
197
217
  key: 1,
198
218
  class: "relative",
199
219
  onDragover: j,
200
- onDragleave: $,
201
- onDrop: M
220
+ onDragleave: L,
221
+ onDrop: I
202
222
  }, [
203
- k.value ? (a(), u("div", oe, [
204
- (a(!0), u(J, null, Q(w.value, (r, n) => (a(), u("div", {
205
- key: n,
206
- class: z(["relative flex items-center p-3 border border-border rounded-lg bg-card shadow-sm transition-colors group", [!o.multiSelect && !o.disabled ? "cursor-pointer hover:border-primary/50" : ""]]),
207
- onClick: l[0] || (l[0] = (p) => !o.multiSelect && !o.disabled ? g() : null)
223
+ V.value ? (r(), c("div", oe, [
224
+ (r(!0), c(X, null, Y(b.value, (o, s) => (r(), c("div", {
225
+ key: s,
226
+ class: S(["relative flex items-center p-3 border border-border rounded-lg bg-card shadow-sm transition-colors group", [!a.multiSelect && !a.disabled ? "cursor-pointer hover:border-primary/50" : ""]]),
227
+ onClick: t[0] || (t[0] = (f) => !a.multiSelect && !a.disabled ? p() : null)
208
228
  }, [
209
- s("div", ie, [
210
- s("div", re, [
211
- b(f, {
229
+ n("div", re, [
230
+ n("div", se, [
231
+ k(g, {
212
232
  icon: "lucide:file-text",
213
233
  class: "w-5 h-5"
214
234
  })
215
235
  ])
216
236
  ]),
217
- s("div", ae, [
218
- s("p", ne, F(r.fileName), 1),
219
- s("p", se, F(L(r.fileSize)), 1)
237
+ n("div", ne, [
238
+ n("p", de, A(o.fileName), 1),
239
+ n("p", ue, A(E(o.fileSize)), 1)
220
240
  ]),
221
- s("div", de, [
222
- !o.disabled && !o.loading ? (a(), y(T, {
241
+ n("div", ce, [
242
+ !a.disabled && !a.loading ? (r(), x($, {
223
243
  key: 0,
224
244
  size: "xs",
225
245
  variant: "ghost",
226
246
  icon: "lucide:x",
227
247
  rounded: "full",
228
248
  class: "text-muted-foreground hover:text-destructive hover:bg-destructive/10",
229
- onClick: D((p) => E(n), ["stop"])
230
- }, null, 8, ["onClick"])) : x("", !0)
249
+ onClick: D((f) => W(s), ["stop"])
250
+ }, null, 8, ["onClick"])) : w("", !0)
231
251
  ])
232
252
  ], 2))), 128)),
233
- o.multiSelect ? (a(), u("div", ue, [
234
- b(T, {
253
+ a.multiSelect && (!a.maxFiles || b.value.length < a.maxFiles) ? (r(), c("div", fe, [
254
+ k($, {
235
255
  size: "sm",
236
256
  variant: "outline",
237
257
  icon: "lucide:plus",
238
258
  text: "Add more",
239
- disabled: o.disabled || o.loading || d.value,
240
- onClick: g
259
+ disabled: a.disabled || a.loading || u.value,
260
+ onClick: p
241
261
  }, null, 8, ["disabled"])
242
- ])) : x("", !0)
243
- ])) : (a(), u("div", {
262
+ ])) : w("", !0)
263
+ ])) : (r(), c("div", {
244
264
  key: 0,
245
- class: z(["border-2 border-dashed border-border rounded-lg p-6 transition-all duration-200 ease-in-out cursor-pointer flex flex-col items-center justify-center text-center gap-2", [
246
- m.value ? "border-primary bg-primary/5" : "hover:border-primary/50 hover:bg-muted/50",
247
- o.disabled || o.loading || d.value ? "opacity-50 cursor-not-allowed" : ""
265
+ class: S(["border-2 border-dashed border-border rounded-lg p-6 transition-all duration-200 ease-in-out cursor-pointer flex flex-col items-center justify-center text-center gap-2", [
266
+ h.value ? "border-primary bg-primary/5" : "hover:border-primary/50 hover:bg-muted/50",
267
+ a.disabled || a.loading || u.value ? "opacity-50 cursor-not-allowed" : ""
248
268
  ]]),
249
- onClick: g
269
+ onClick: p
250
270
  }, [
251
- s("div", ee, [
252
- o.loading || d.value ? (a(), y(f, {
271
+ n("div", te, [
272
+ a.loading || u.value ? (r(), x(g, {
253
273
  key: 0,
254
274
  icon: "lucide:loader-2",
255
275
  class: "w-6 h-6 animate-spin"
256
- })) : (a(), y(f, {
276
+ })) : (r(), x(g, {
257
277
  key: 1,
258
278
  icon: "lucide:upload-cloud",
259
279
  class: "w-6 h-6"
260
280
  }))
261
281
  ]),
262
- s("div", le, [
263
- l[1] || (l[1] = s("p", { class: "text-sm font-medium text-foreground" }, [
264
- s("span", { class: "text-primary hover:underline" }, "Click to upload"),
265
- H(" or drag and drop ")
282
+ n("div", ae, [
283
+ t[1] || (t[1] = n("p", { class: "text-sm font-medium text-foreground" }, [
284
+ n("span", { class: "text-primary hover:underline" }, "Click to upload"),
285
+ Q(" or drag and drop ")
266
286
  ], -1)),
267
- o.fileTypes.length ? (a(), u("p", te, F(o.fileTypes.join(", ")), 1)) : x("", !0)
287
+ a.fileTypes.length ? (r(), c("p", ie, A(a.fileTypes.join(", ")), 1)) : w("", !0)
268
288
  ])
269
289
  ], 2)),
270
- o.loading || d.value ? (a(), u("div", ce, [
271
- s("div", fe, [
272
- b(f, {
290
+ a.loading || u.value ? (r(), c("div", me, [
291
+ n("div", ge, [
292
+ k(g, {
273
293
  icon: "lucide:loader-2",
274
294
  class: "w-6 h-6 animate-spin text-primary"
275
295
  })
276
296
  ])
277
- ])) : x("", !0)
297
+ ])) : w("", !0)
278
298
  ], 32))
279
299
  ])
280
300
  ]));
281
301
  }
282
302
  });
283
303
  export {
284
- ve as default
304
+ ye as default
285
305
  };