@duxweb/dvha-core 1.1.5 → 1.1.7

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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@vueuse/core"),V=require("lodash-es"),c=require("vue"),_=require("./upload/local.cjs");function H(l){l=l||{};const v=c.ref(!1),o=c.ref([]),u=c.ref(-1),d=c.ref(new Map),S=l.driver||_.createLocalUploadDriver(),P=c.computed(()=>{const{onProgress:e,onDataCallback:t,onCancel:a,onComplete:n,maxFileSize:i,maxFileCount:s,accept:r,multiple:f,autoUpload:m,options:M,onSuccess:U,onError:Q,method:R,driver:W,params:X,...O}=l;return O}),A=c.computed(()=>l.method||"POST"),F=c.computed(()=>{const e=o.value.length,t=o.value.reduce((s,r)=>s+(r.filesize||0),0);let a=0,n=0;return o.value.forEach((s,r)=>{r<u.value?a+=s.filesize||0:r===u.value&&(a+=s.progress?.loaded||0)}),t>0&&(n=Math.round(a/t*100)),{index:u.value>=0?u.value+1:0,totalFiles:e,currentFile:o.value[u.value],totalPercent:n,totalLoaded:a,totalSize:t}}),w=e=>{if(e===0)return"0 Bytes";const t=1024,a=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**n).toFixed(2))} ${a[n]}`},g=e=>{if(e===0)return"0 B/s";const t=1024,a=["B/s","KB/s","MB/s","GB/s"],n=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**n).toFixed(2))} ${a[n]}`},b=()=>V.uniqueId("upload-"),$=async(e,t,a)=>{switch(t){case"file":{if(!(e instanceof File))throw new TypeError('Payload must be a File when type is "file"');return e}case"blob":{if(!(e instanceof Blob))throw new TypeError('Payload must be a Blob when type is "blob"');return new File([e],"blob-file",{type:e.type})}case"base64":{if(typeof e!="string")throw new TypeError('Payload must be a string when type is "base64"');const n=e.includes(",")?e.split(",")[1]:e,i=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",s=atob(n),r=new Uint8Array(s.length);for(let m=0;m<s.length;m++)r[m]=s.charCodeAt(m);const f=new Blob([r],{type:i});return new File([f],"base64-file",{type:i})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const n=new Blob([e]);return new File([n],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${t}`)}},x=e=>{if(l.maxFileSize&&e.size>l.maxFileSize)throw new Error(`File size cannot exceed ${w(l.maxFileSize)}`);if(l.maxFileCount&&o.value.length>=l.maxFileCount)throw new Error(`File count cannot exceed ${l.maxFileCount}`)},I=async(e,t,a)=>{const n=await $(e,t);x(n);const i={id:b(),file:n,filename:n.name,filesize:n.size,filetype:n.type,filesizeText:w(n.size),status:"pending",progress:{loaded:0,total:n.size,percent:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}};return o.value.push(i),i},h=(e,t)=>{const a=o.value.findIndex(n=>n.id===e);a!==-1&&(o.value[a]={...o.value[a],...t})},T=()=>{o.value.every(t=>t.status!=="uploading")&&l.onComplete?.(o.value)},p=e=>{const t=o.value.find(a=>a.id===e);if(!t||t.status!=="pending"&&t.status!=="uploading")return!1;if(t.status==="uploading"){const a=d.value.get(e);a&&(a.abort(),d.value.delete(e))}return h(e,{status:"cancelled"}),l.onCancel?.(e),T(),!0},k=e=>{e?e.forEach(t=>p(t)):o.value.forEach(t=>p(t.id))},q=async e=>{if(!e.file)throw new Error("File not found");x(e.file);const t=new AbortController;d.value.set(e.id,t);const a=Date.now();return h(e.id,{status:"uploading"}),S.upload(e.file,{...P.value,method:A.value,signal:t.signal,params:l.params,onUploadProgress:n=>{const r=(Date.now()-a)/1e3,f=r>0?n.loaded/r:0,m=(n.total||0)-n.loaded,M=f>0?m/f:0,U={loaded:n.loaded,total:n.total,percent:n.percent||0,speed:Math.round(f),speedText:g(f),uploadTime:Math.round(r),remainingTime:Math.round(M)};h(e.id,{status:"uploading",progress:U}),l.onProgress?.(F.value)}}).then(n=>{if(e.status==="cancelled")throw new Error("Upload cancelled");const i=l.onDataCallback?.(n,e)||n.data,s=Math.round((Date.now()-a)/1e3),r={...e,status:"success",data:n,...i,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:g(0),uploadTime:s,remainingTime:0}};return h(e.id,r),d.value.delete(e.id),l.onSuccess?.(n),r}).catch(n=>{throw n.message==="canceled"||e.status==="cancelled"?new Error("Upload cancelled"):(h(e.id,{status:"error",error:n.message}),d.value.delete(e.id),n)}).finally(()=>{T()})},z=async()=>{const e=o.value.filter(t=>t.status==="pending");if(e.length===0)return[];v.value=!0;try{const t=[];for(let a=0;a<e.length;a++){const n=e[a],i=o.value.findIndex(r=>r.id===n.id);u.value=i;const s=await q(n);t.push(s)}return t}catch(t){throw l.onError?.({status:t?.status||500,message:t?.message||"upload failed"}),t}finally{v.value=!1,u.value=-1}},y=()=>{o.value.forEach(e=>{p(e.id)}),d.value.clear(),o.value=[],u.value=-1},C=async(e,t="file")=>{try{if(!l.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(!l.multiple&&o.value.length>0&&y(),l.maxFileCount&&o.value.length+e.length>l.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);for(const a of e)await I(a,t)}catch(a){throw l.onError?.({status:a?.status||400,message:a?.message||"Failed to add files"}),a}l.autoUpload&&z().catch(a=>{console.warn("Auto upload failed:",a)})},E=e=>{const t=o.value.find(n=>n.id===e);if(t&&t.status==="uploading"){h(e,{status:"cancelled"});const n=d.value.get(e);if(!n)return;n.abort(),d.value.delete(e)}const a=o.value.findIndex(n=>n.id===e);a!==-1&&o.value.splice(a,1)},D=e=>{e?e.forEach(t=>E(t)):o.value.forEach(t=>E(t.id))},{files:G,open:K,reset:B}=j.useFileDialog({accept:l.accept,multiple:l.multiple||!1}),L=e=>({id:b(),...e,filesizeText:e.filesize?w(e.filesize):void 0,status:e.url?"success":"pending",progress:{loaded:0,total:e.filesize||0,percent:e.url?100:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}});c.watch(G,async e=>{if(e&&e.length>0){const t=Array.from(e);B(),await C(t,"file").catch(a=>{console.warn("Failed to add selected files:",a)})}});const N=c.computed(()=>o.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:o,dataFiles:N,progress:F,open:K,trigger:z,resetFiles:B,clearFiles:y,removeFiles:D,addFiles:C,addDataFiles:e=>{!l.multiple&&o.value.length>0&&y();const t=e.map(a=>L(a));o.value.push(...t)},cancelFiles:k}}exports.useUpload=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@vueuse/core"),V=require("lodash-es"),c=require("vue"),_=require("./upload/local.cjs");function H(l){l=l||{};const v=c.ref(!1),o=c.ref([]),u=c.ref(-1),d=c.ref(new Map),S=l.driver||_.createLocalUploadDriver(),P=c.computed(()=>{const{onProgress:e,onDataCallback:t,onCancel:a,onComplete:n,maxFileSize:i,maxFileCount:s,accept:r,multiple:f,autoUpload:m,options:M,onSuccess:U,onError:Q,method:R,driver:W,params:X,...O}=l;return O}),A=c.computed(()=>l.method||"POST"),F=c.computed(()=>{const e=o.value.length,t=o.value.reduce((s,r)=>s+(r.filesize||0),0);let a=0,n=0;return o.value.forEach((s,r)=>{r<u.value?a+=s.filesize||0:r===u.value&&(a+=s.progress?.loaded||0)}),t>0&&(n=Math.round(a/t*100)),{index:u.value>=0?u.value+1:0,totalFiles:e,currentFile:o.value[u.value],totalPercent:n,totalLoaded:a,totalSize:t}}),w=e=>{if(e===0)return"0 Bytes";const t=1024,a=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**n).toFixed(2))} ${a[n]}`},g=e=>{if(e===0)return"0 B/s";const t=1024,a=["B/s","KB/s","MB/s","GB/s"],n=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**n).toFixed(2))} ${a[n]}`},b=()=>V.uniqueId("upload-"),$=async(e,t,a)=>{switch(t){case"file":{if(!(e instanceof File))throw new TypeError('Payload must be a File when type is "file"');return e}case"blob":{if(!(e instanceof Blob))throw new TypeError('Payload must be a Blob when type is "blob"');return new File([e],"blob-file",{type:e.type})}case"base64":{if(typeof e!="string")throw new TypeError('Payload must be a string when type is "base64"');const n=e.includes(",")?e.split(",")[1]:e,i=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",s=atob(n),r=new Uint8Array(s.length);for(let m=0;m<s.length;m++)r[m]=s.charCodeAt(m);const f=new Blob([r],{type:i});return new File([f],"base64-file",{type:i})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const n=new Blob([e]);return new File([n],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${t}`)}},x=e=>{if(l.maxFileSize&&e.size>l.maxFileSize)throw new Error(`File size cannot exceed ${w(l.maxFileSize)}`);if(l.maxFileCount&&o.value.length>l.maxFileCount)throw new Error(`File count cannot exceed ${l.maxFileCount}`)},I=async(e,t,a)=>{const n=await $(e,t);x(n);const i={id:b(),file:n,filename:n.name,filesize:n.size,filetype:n.type,filesizeText:w(n.size),status:"pending",progress:{loaded:0,total:n.size,percent:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}};return o.value.push(i),i},h=(e,t)=>{const a=o.value.findIndex(n=>n.id===e);a!==-1&&(o.value[a]={...o.value[a],...t})},T=()=>{o.value.every(t=>t.status!=="uploading")&&l.onComplete?.(o.value)},p=e=>{const t=o.value.find(a=>a.id===e);if(!t||t.status!=="pending"&&t.status!=="uploading")return!1;if(t.status==="uploading"){const a=d.value.get(e);a&&(a.abort(),d.value.delete(e))}return h(e,{status:"cancelled"}),l.onCancel?.(e),T(),!0},k=e=>{e?e.forEach(t=>p(t)):o.value.forEach(t=>p(t.id))},q=async e=>{if(!e.file)throw new Error("File not found");x(e.file);const t=new AbortController;d.value.set(e.id,t);const a=Date.now();return h(e.id,{status:"uploading"}),S.upload(e.file,{...P.value,method:A.value,signal:t.signal,params:l.params,onUploadProgress:n=>{const r=(Date.now()-a)/1e3,f=r>0?n.loaded/r:0,m=(n.total||0)-n.loaded,M=f>0?m/f:0,U={loaded:n.loaded,total:n.total,percent:n.percent||0,speed:Math.round(f),speedText:g(f),uploadTime:Math.round(r),remainingTime:Math.round(M)};h(e.id,{status:"uploading",progress:U}),l.onProgress?.(F.value)}}).then(n=>{if(e.status==="cancelled")throw new Error("Upload cancelled");const i=l.onDataCallback?.(n,e)||n.data,s=Math.round((Date.now()-a)/1e3),r={...e,status:"success",data:n,...i,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:g(0),uploadTime:s,remainingTime:0}};return h(e.id,r),d.value.delete(e.id),l.onSuccess?.(n),r}).catch(n=>{throw n.message==="canceled"||e.status==="cancelled"?new Error("Upload cancelled"):(h(e.id,{status:"error",error:n.message}),d.value.delete(e.id),n)}).finally(()=>{T()})},z=async()=>{const e=o.value.filter(t=>t.status==="pending");if(e.length===0)return[];v.value=!0;try{const t=[];for(let a=0;a<e.length;a++){const n=e[a],i=o.value.findIndex(r=>r.id===n.id);u.value=i;const s=await q(n);t.push(s)}return t}catch(t){throw l.onError?.({status:t?.status||500,message:t?.message||"upload failed"}),t}finally{v.value=!1,u.value=-1}},y=()=>{o.value.forEach(e=>{p(e.id)}),d.value.clear(),o.value=[],u.value=-1},C=async(e,t="file")=>{try{if(!l.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(!l.multiple&&o.value.length>0&&y(),l.maxFileCount&&o.value.length+e.length>l.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);for(const a of e)await I(a,t)}catch(a){throw l.onError?.({status:a?.status||400,message:a?.message||"Failed to add files"}),a}l.autoUpload&&z().catch(a=>{console.warn("Auto upload failed:",a)})},E=e=>{const t=o.value.find(n=>n.id===e);if(t&&t.status==="uploading"){h(e,{status:"cancelled"});const n=d.value.get(e);if(!n)return;n.abort(),d.value.delete(e)}const a=o.value.findIndex(n=>n.id===e);a!==-1&&o.value.splice(a,1)},D=e=>{e?e.forEach(t=>E(t)):o.value.forEach(t=>E(t.id))},{files:G,open:K,reset:B}=j.useFileDialog({accept:l.accept,multiple:l.multiple||!1}),L=e=>({id:b(),...e,filesizeText:e.filesize?w(e.filesize):void 0,status:e.url?"success":"pending",progress:{loaded:0,total:e.filesize||0,percent:e.url?100:0,speed:0,speedText:g(0),remainingTime:0,uploadTime:0}});c.watch(G,async e=>{if(e&&e.length>0){const t=Array.from(e);B(),await C(t,"file").catch(a=>{console.warn("Failed to add selected files:",a)})}});const N=c.computed(()=>o.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:o,dataFiles:N,progress:F,open:K,trigger:z,resetFiles:B,clearFiles:y,removeFiles:D,addFiles:C,addDataFiles:e=>{!l.multiple&&o.value.length>0&&y();const t=e.map(a=>L(a));o.value.push(...t)},cancelFiles:k}}exports.useUpload=H;
@@ -63,7 +63,7 @@ function ne(l) {
63
63
  }, T = (e) => {
64
64
  if (l.maxFileSize && e.size > l.maxFileSize)
65
65
  throw new Error(`File size cannot exceed ${p(l.maxFileSize)}`);
66
- if (l.maxFileCount && o.value.length >= l.maxFileCount)
66
+ if (l.maxFileCount && o.value.length > l.maxFileCount)
67
67
  throw new Error(`File count cannot exceed ${l.maxFileCount}`);
68
68
  }, k = async (e, t, n) => {
69
69
  const a = await I(e, t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "1.1.5",
4
+ "version": "1.1.7",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {