@duxweb/dvha-core 0.1.14 → 0.1.15

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 y=require("lodash-es"),o=require("vue"),h=require("./data.cjs");function N(t){const r=o.ref(),s=o.ref({page:1,pageSize:typeof t.pagination=="number"?t.pagination:t.pagination?20:0}),d=o.ref(!1),b=y.debounce(e=>{r.value=e},t.debounce||300),V=e=>{b(e)},{data:i,isLoading:S}=h.useList({get path(){return t.path||""},get filters(){const e={...t.params};return r.value&&(e[t.keywordField||"keyword"]=r.value),e},get pagination(){return t.pagination?s.value:void 0},get providerName(){return t.providerName}}),f=o.ref([]),v=e=>{const{optionField:n}=t;return typeof n=="string"?e[n]||e.value||e.id:e.value||e.id},w=e=>{const{optionLabel:n="label",optionValue:u="value"}=t;let l;typeof n=="function"?l=n(e):typeof n=="string"?l=e[n]||e.label||e.name||e.title||String(e.value||e.id||""):l=e.label||e.name||e.title||String(e.value||e.id||"");let a;return typeof u=="function"?a=u(e):typeof u=="string"?a=e[u]||e.value||e.id:a=e.value||e.id,{label:l,value:a,raw:e}},g=o.computed(()=>{var u;const e=((u=i.value)==null?void 0:u.data)||[],n=[...f.value];return e.forEach(l=>{n.some(c=>v(c)===v(l))||n.push(l)}),n.map(l=>w(l))}),x=o.computed(()=>{var e;return((e=i.value)==null?void 0:e.meta)||{}}),{refetch:E}=h.useMany({get path(){return t.path||""},get ids(){return t.defaultValue?y.isArray(t.defaultValue)?t.defaultValue:[t.defaultValue]:[]},options:{enabled:!1},providerName:t.providerName});o.watch(()=>t.defaultValue,async e=>{var l;if(!(d.value||!e||(d.value=!0,(Array.isArray(e)?e:[e]).every(a=>g.value.some(c=>c.value===a)))))try{const a=await E();f.value=((l=a==null?void 0:a.data)==null?void 0:l.data)||[]}catch(a){console.warn("Failed to fetch selected items:",a)}},{immediate:!0});const F=o.computed(()=>S.value&&!i.value);return{onSearch:V,options:g,meta:x,loading:F,pagination:s}}exports.useSelect=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("lodash-es"),o=require("vue"),h=require("./data.cjs");function N(t){const r=o.ref(),c=o.ref({page:1,pageSize:typeof t.pagination=="number"?t.pagination:t.pagination?20:0}),s=o.ref(!1),b=y.debounce(e=>{r.value=e},t.debounce||300),V=e=>{b(e)},{data:d,isLoading:S}=h.useList({get path(){return t.path||""},get filters(){const e={...t.params};return r.value&&(e[t.keywordField||"keyword"]=r.value),e},get pagination(){return t.pagination?c.value:void 0},get providerName(){return t.providerName}}),f=o.ref([]),v=e=>{const{optionField:n}=t;return typeof n=="string"?e[n]||e.value||e.id:e.value||e.id},w=e=>{const{optionLabel:n="label",optionValue:u="value"}=t;let l;typeof n=="function"?l=n(e):typeof n=="string"?l=e[n]||e.label||e.name||e.title||String(e.value||e.id||""):l=e.label||e.name||e.title||String(e.value||e.id||"");let a;return typeof u=="function"?a=u(e):typeof u=="string"?a=e[u]||e.value||e.id:a=e.value||e.id,{label:l,value:a,raw:e}},g=o.computed(()=>{var u;const e=((u=d.value)==null?void 0:u.data)||[],n=[...f.value];return e.forEach(l=>{n.some(i=>v(i)===v(l))||n.push(l)}),n.map(l=>w(l))}),x=o.computed(()=>{var e;return((e=d.value)==null?void 0:e.meta)||{}}),{refetch:E}=h.useMany({get path(){return t.path||""},get ids(){return t.defaultValue?y.isArray(t.defaultValue)?t.defaultValue:[t.defaultValue]:[]},options:{enabled:!1},providerName:t.providerName});o.watch(()=>t.defaultValue,async e=>{var l;if(!(s.value||!e||(s.value=!0,(Array.isArray(e)?e:[e]).every(a=>g.value.some(i=>i.value===a)))))try{const a=await E();f.value=((l=a==null?void 0:a.data)==null?void 0:l.data)||[]}catch(a){console.warn("Failed to fetch selected items:",a)}},{immediate:!0});const F=o.computed(()=>S.value);return{onSearch:V,options:g,meta:x,loading:F,pagination:c}}exports.useSelect=N;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("@vueuse/core"),R=require("lodash-es"),u=require("vue"),V=require("./upload/local.cjs");function W(l){const v=u.ref(!1),i=u.ref([]),d=u.ref(-1),f=u.ref(new Map),A=l.driver||V.createLocalUploadDriver(),$=u.computed(()=>{const{onProgress:e,onDataCallback:n,onCancel:a,onComplete:t,maxFileSize:c,maxFileCount:o,accept:s,multiple:r,autoUpload:m,options:U,onSuccess:P,onError:F,method:X,driver:Y,...J}=l;return J}),I=u.computed(()=>l.method||"POST"),b=u.computed(()=>{const e=i.value.length,n=i.value.reduce((o,s)=>o+(s.filesize||0),0);let a=0,t=0;return i.value.forEach((o,s)=>{var r;s<d.value?a+=o.filesize||0:s===d.value&&(a+=((r=o.progress)==null?void 0:r.loaded)||0)}),n>0&&(t=Math.round(a/n*100)),{index:d.value>=0?d.value+1:0,totalFiles:e,currentFile:i.value[d.value],totalPercent:t,totalLoaded:a,totalSize:n}}),w=e=>{if(e===0)return"0 Bytes";const n=1024,a=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},h=e=>{if(e===0)return"0 B/s";const n=1024,a=["B/s","KB/s","MB/s","GB/s"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},x=()=>R.uniqueId("upload-"),k=async(e,n,a)=>{switch(n){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 t=e.includes(",")?e.split(",")[1]:e,c=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",o=atob(t),s=new Uint8Array(o.length);for(let m=0;m<o.length;m++)s[m]=o.charCodeAt(m);const r=new Blob([s],{type:c});return new File([r],"base64-file",{type:c})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const t=new Blob([e]);return new File([t],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${n}`)}},T=e=>{if(l.maxFileSize&&e.size>l.maxFileSize)throw new Error(`File size cannot exceed ${w(l.maxFileSize)}`);if(l.maxFileCount&&i.value.length>=l.maxFileCount)throw new Error(`File count cannot exceed ${l.maxFileCount}`)},q=async(e,n,a)=>{const t=await k(e,n);T(t);const c={id:x(),file:t,filename:t.name,filesize:t.size,filetype:t.type,filesizeText:w(t.size),status:"pending",progress:{loaded:0,total:t.size,percent:0,speed:0,speedText:h(0),remainingTime:0,uploadTime:0}};return i.value.push(c),c},g=(e,n)=>{const a=i.value.findIndex(t=>t.id===e);a!==-1&&(i.value[a]={...i.value[a],...n})},z=()=>{var n;i.value.every(a=>a.status!=="uploading")&&((n=l.onComplete)==null||n.call(l,i.value))},y=e=>{var a;const n=i.value.find(t=>t.id===e);if(!n||n.status!=="pending"&&n.status!=="uploading")return!1;if(n.status==="uploading"){const t=f.value.get(e);t&&(t.abort(),f.value.delete(e))}return g(e,{status:"cancelled"}),(a=l.onCancel)==null||a.call(l,e),z(),!0},D=e=>{e?e.forEach(n=>y(n)):i.value.forEach(n=>y(n.id))},G=async e=>{if(!e.file)throw new Error("File not found");T(e.file);const n=new AbortController;f.value.set(e.id,n);const a=Date.now();g(e.id,{status:"uploading"}),await A.upload(e.file,{...$.value,method:I.value,signal:n.signal,onUploadProgress:t=>{var F;const s=(Date.now()-a)/1e3,r=s>0?t.loaded/s:0,m=(t.total||0)-t.loaded,U=r>0?m/r:0,P={loaded:t.loaded,total:t.total,percent:t.percent||0,speed:Math.round(r),speedText:h(r),uploadTime:Math.round(s),remainingTime:Math.round(U)};g(e.id,{status:"uploading",progress:P}),(F=l.onProgress)==null||F.call(l,b.value)}}).then(t=>{var s,r;if(e.status==="cancelled")return;const c=((s=l.onDataCallback)==null?void 0:s.call(l,t,e))||{},o=Math.round((Date.now()-a)/1e3);g(e.id,{status:"success",data:t,...c,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:h(0),uploadTime:o,remainingTime:0}}),f.value.delete(e.id),(r=l.onSuccess)==null||r.call(l,t)}).catch(t=>{if(!(t.message==="canceled"||e.status==="cancelled"))throw g(e.id,{status:"error",error:t.message}),f.value.delete(e.id),t}).finally(()=>{z()})},C=async()=>{var n;const e=i.value.filter(a=>a.status==="pending");if(e.length!==0){v.value=!0;try{for(let a=0;a<e.length;a++){const t=e[a],c=i.value.findIndex(o=>o.id===t.id);d.value=c,await G(t)}}catch(a){throw(n=l.onError)==null||n.call(l,{status:(a==null?void 0:a.status)||500,message:(a==null?void 0:a.message)||"upload failed"}),a}finally{v.value=!1,d.value=-1}}},B=async(e,n="file")=>{var a;try{if(l.multiple||E(),!l.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(l.maxFileCount&&i.value.length+e.length>l.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);for(const t of e)await q(t,n)}catch(t){throw(a=l.onError)==null||a.call(l,{status:(t==null?void 0:t.status)||400,message:(t==null?void 0:t.message)||"Failed to add files"}),t}l.autoUpload&&C()},K=e=>{const n=e.map(a=>j(a));i.value.push(...n)},E=()=>{i.value.forEach(e=>{y(e.id)}),f.value.clear(),i.value=[],d.value=-1},M=e=>{const n=i.value.find(t=>t.id===e);if(n&&n.status==="uploading"){g(e,{status:"cancelled"});const t=f.value.get(e);if(!t)return;t.abort(),f.value.delete(e)}const a=i.value.findIndex(t=>t.id===e);a!==-1&&i.value.splice(a,1)},L=e=>{e?e.forEach(n=>M(n)):i.value.forEach(n=>M(n.id))},{files:N,open:O,reset:S}=Q.useFileDialog({accept:l.accept,multiple:l.multiple||!1}),j=e=>({id:x(),...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:h(0),remainingTime:0,uploadTime:0}});u.watch(N,async e=>{if(e&&e.length>0){const n=Array.from(e);S(),await B(n,"file").catch(a=>{console.warn("Failed to add selected files:",a)})}});const H=u.computed(()=>i.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:i,dataFiles:H,progress:b,open:O,trigger:C,resetFiles:S,clearFiles:E,removeFiles:L,addFiles:B,addDataFiles:K,cancelFiles:D}}exports.useUpload=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@vueuse/core"),Q=require("lodash-es"),u=require("vue"),R=require("./upload/local.cjs");function V(l){const v=u.ref(!1),i=u.ref([]),d=u.ref(-1),f=u.ref(new Map),P=l.driver||R.createLocalUploadDriver(),A=u.computed(()=>{const{onProgress:e,onDataCallback:n,onCancel:a,onComplete:t,maxFileSize:c,maxFileCount:o,accept:s,multiple:r,autoUpload:m,options:S,onSuccess:U,onError:F,method:X,driver:Y,...H}=l;return H}),$=u.computed(()=>l.method||"POST"),b=u.computed(()=>{const e=i.value.length,n=i.value.reduce((o,s)=>o+(s.filesize||0),0);let a=0,t=0;return i.value.forEach((o,s)=>{var r;s<d.value?a+=o.filesize||0:s===d.value&&(a+=((r=o.progress)==null?void 0:r.loaded)||0)}),n>0&&(t=Math.round(a/n*100)),{index:d.value>=0?d.value+1:0,totalFiles:e,currentFile:i.value[d.value],totalPercent:t,totalLoaded:a,totalSize:n}}),w=e=>{if(e===0)return"0 Bytes";const n=1024,a=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},h=e=>{if(e===0)return"0 B/s";const n=1024,a=["B/s","KB/s","MB/s","GB/s"],t=Math.floor(Math.log(e)/Math.log(n));return`${Number.parseFloat((e/n**t).toFixed(2))} ${a[t]}`},x=()=>Q.uniqueId("upload-"),I=async(e,n,a)=>{switch(n){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 t=e.includes(",")?e.split(",")[1]:e,c=e.includes(",")?e.split(",")[0].split(":")[1].split(";")[0]:"application/octet-stream",o=atob(t),s=new Uint8Array(o.length);for(let m=0;m<o.length;m++)s[m]=o.charCodeAt(m);const r=new Blob([s],{type:c});return new File([r],"base64-file",{type:c})}case"arrayBuffer":{if(!(e instanceof ArrayBuffer))throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');const t=new Blob([e]);return new File([t],"array-buffer-file",{type:"application/octet-stream"})}default:throw new Error(`Unsupported upload type: ${n}`)}},T=e=>{if(l.maxFileSize&&e.size>l.maxFileSize)throw new Error(`File size cannot exceed ${w(l.maxFileSize)}`);if(l.maxFileCount&&i.value.length>=l.maxFileCount)throw new Error(`File count cannot exceed ${l.maxFileCount}`)},k=async(e,n,a)=>{const t=await I(e,n);T(t);const c={id:x(),file:t,filename:t.name,filesize:t.size,filetype:t.type,filesizeText:w(t.size),status:"pending",progress:{loaded:0,total:t.size,percent:0,speed:0,speedText:h(0),remainingTime:0,uploadTime:0}};return i.value.push(c),c},g=(e,n)=>{const a=i.value.findIndex(t=>t.id===e);a!==-1&&(i.value[a]={...i.value[a],...n})},z=()=>{var n;i.value.every(a=>a.status!=="uploading")&&((n=l.onComplete)==null||n.call(l,i.value))},y=e=>{var a;const n=i.value.find(t=>t.id===e);if(!n||n.status!=="pending"&&n.status!=="uploading")return!1;if(n.status==="uploading"){const t=f.value.get(e);t&&(t.abort(),f.value.delete(e))}return g(e,{status:"cancelled"}),(a=l.onCancel)==null||a.call(l,e),z(),!0},q=e=>{e?e.forEach(n=>y(n)):i.value.forEach(n=>y(n.id))},D=async e=>{if(!e.file)throw new Error("File not found");T(e.file);const n=new AbortController;f.value.set(e.id,n);const a=Date.now();g(e.id,{status:"uploading"}),await P.upload(e.file,{...A.value,method:$.value,signal:n.signal,onUploadProgress:t=>{var F;const s=(Date.now()-a)/1e3,r=s>0?t.loaded/s:0,m=(t.total||0)-t.loaded,S=r>0?m/r:0,U={loaded:t.loaded,total:t.total,percent:t.percent||0,speed:Math.round(r),speedText:h(r),uploadTime:Math.round(s),remainingTime:Math.round(S)};g(e.id,{status:"uploading",progress:U}),(F=l.onProgress)==null||F.call(l,b.value)}}).then(t=>{var s,r;if(e.status==="cancelled")return;const c=((s=l.onDataCallback)==null?void 0:s.call(l,t,e))||{},o=Math.round((Date.now()-a)/1e3);g(e.id,{status:"success",data:t,...c,progress:{...e.progress,loaded:e.filesize||0,percent:100,speed:0,speedText:h(0),uploadTime:o,remainingTime:0}}),f.value.delete(e.id),(r=l.onSuccess)==null||r.call(l,t)}).catch(t=>{if(!(t.message==="canceled"||e.status==="cancelled"))throw g(e.id,{status:"error",error:t.message}),f.value.delete(e.id),t}).finally(()=>{z()})},C=async()=>{var n;const e=i.value.filter(a=>a.status==="pending");if(e.length!==0){v.value=!0;try{for(let a=0;a<e.length;a++){const t=e[a],c=i.value.findIndex(o=>o.id===t.id);d.value=c,await D(t)}}catch(a){throw(n=l.onError)==null||n.call(l,{status:(a==null?void 0:a.status)||500,message:(a==null?void 0:a.message)||"upload failed"}),a}finally{v.value=!1,d.value=-1}}},B=async(e,n="file")=>{var a;try{if(!l.multiple&&e.length>1)throw new Error("Single file mode: only one file can be selected");if(l.maxFileCount&&i.value.length+e.length>l.maxFileCount)throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);for(const t of e)await k(t,n)}catch(t){throw(a=l.onError)==null||a.call(l,{status:(t==null?void 0:t.status)||400,message:(t==null?void 0:t.message)||"Failed to add files"}),t}l.autoUpload&&C()},G=()=>{i.value.forEach(e=>{y(e.id)}),f.value.clear(),i.value=[],d.value=-1},E=e=>{const n=i.value.find(t=>t.id===e);if(n&&n.status==="uploading"){g(e,{status:"cancelled"});const t=f.value.get(e);if(!t)return;t.abort(),f.value.delete(e)}const a=i.value.findIndex(t=>t.id===e);a!==-1&&i.value.splice(a,1)},K=e=>{e?e.forEach(n=>E(n)):i.value.forEach(n=>E(n.id))},{files:L,open:N,reset:M}=J.useFileDialog({accept:l.accept,multiple:l.multiple||!1}),O=e=>({id:x(),...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:h(0),remainingTime:0,uploadTime:0}});u.watch(L,async e=>{if(e&&e.length>0){const n=Array.from(e);M(),await B(n,"file").catch(a=>{console.warn("Failed to add selected files:",a)})}});const j=u.computed(()=>i.value.filter(e=>e.status==="success").map(e=>({url:e.url,filename:e.filename,filesize:e.filesize,filetype:e.filetype})));return{isUploading:v,uploadFiles:i,dataFiles:j,progress:b,open:N,trigger:C,resetFiles:M,clearFiles:G,removeFiles:K,addFiles:B,addDataFiles:e=>{const n=e.map(a=>O(a));i.value.push(...n)},cancelFiles:q}}exports.useUpload=V;
@@ -1,15 +1,15 @@
1
1
  import { debounce as N, isArray as k } from "lodash-es";
2
- import { ref as o, computed as s, watch as m } from "vue";
2
+ import { ref as o, computed as c, watch as m } from "vue";
3
3
  import { useList as p, useMany as A } from "./data.js";
4
4
  function z(a) {
5
- const r = o(), d = o({
5
+ const r = o(), s = o({
6
6
  page: 1,
7
7
  pageSize: typeof a.pagination == "number" ? a.pagination : a.pagination ? 20 : 0
8
- }), f = o(!1), h = N((e) => {
8
+ }), d = o(!1), h = N((e) => {
9
9
  r.value = e;
10
10
  }, a.debounce || 300), b = (e) => {
11
11
  h(e);
12
- }, { data: i, isLoading: V } = p({
12
+ }, { data: f, isLoading: V } = p({
13
13
  get path() {
14
14
  return a.path || "";
15
15
  },
@@ -18,7 +18,7 @@ function z(a) {
18
18
  return r.value && (e[a.keywordField || "keyword"] = r.value), e;
19
19
  },
20
20
  get pagination() {
21
- return a.pagination ? d.value : void 0;
21
+ return a.pagination ? s.value : void 0;
22
22
  },
23
23
  get providerName() {
24
24
  return a.providerName;
@@ -36,17 +36,17 @@ function z(a) {
36
36
  value: t,
37
37
  raw: e
38
38
  };
39
- }, y = s(() => {
39
+ }, y = c(() => {
40
40
  var u;
41
- const e = ((u = i.value) == null ? void 0 : u.data) || [], n = [...v.value];
41
+ const e = ((u = f.value) == null ? void 0 : u.data) || [], n = [...v.value];
42
42
  return e.forEach((l) => {
43
43
  n.some(
44
- (c) => g(c) === g(l)
44
+ (i) => g(i) === g(l)
45
45
  ) || n.push(l);
46
46
  }), n.map((l) => w(l));
47
- }), S = s(() => {
47
+ }), S = c(() => {
48
48
  var e;
49
- return ((e = i.value) == null ? void 0 : e.meta) || {};
49
+ return ((e = f.value) == null ? void 0 : e.meta) || {};
50
50
  }), { refetch: x } = A({
51
51
  get path() {
52
52
  return a.path || "";
@@ -61,8 +61,8 @@ function z(a) {
61
61
  });
62
62
  m(() => a.defaultValue, async (e) => {
63
63
  var l;
64
- if (!(f.value || !e || (f.value = !0, (Array.isArray(e) ? e : [e]).every(
65
- (t) => y.value.some((c) => c.value === t)
64
+ if (!(d.value || !e || (d.value = !0, (Array.isArray(e) ? e : [e]).every(
65
+ (t) => y.value.some((i) => i.value === t)
66
66
  ))))
67
67
  try {
68
68
  const t = await x();
@@ -71,13 +71,13 @@ function z(a) {
71
71
  console.warn("Failed to fetch selected items:", t);
72
72
  }
73
73
  }, { immediate: !0 });
74
- const F = s(() => V.value && !i.value);
74
+ const F = c(() => V.value);
75
75
  return {
76
76
  onSearch: b,
77
77
  options: y,
78
78
  meta: S,
79
79
  loading: F,
80
- pagination: d
80
+ pagination: s
81
81
  };
82
82
  }
83
83
  export {
@@ -1,17 +1,17 @@
1
- import { useFileDialog as R } from "@vueuse/core";
2
- import { uniqueId as V } from "lodash-es";
3
- import { ref as g, computed as v, watch as W } from "vue";
4
- import { createLocalUploadDriver as X } from "./upload/local.js";
1
+ import { useFileDialog as Q } from "@vueuse/core";
2
+ import { uniqueId as R } from "lodash-es";
3
+ import { ref as g, computed as v, watch as V } from "vue";
4
+ import { createLocalUploadDriver as W } from "./upload/local.js";
5
5
  function ne(l) {
6
- const w = g(!1), i = g([]), u = g(-1), d = g(/* @__PURE__ */ new Map()), $ = l.driver || X(), I = v(() => {
7
- const { onProgress: e, onDataCallback: n, onCancel: a, onComplete: t, maxFileSize: c, maxFileCount: s, accept: o, multiple: r, autoUpload: f, options: P, onSuccess: A, onError: x, method: Y, driver: Z, ...Q } = l;
8
- return Q;
9
- }), k = v(() => l.method || "POST"), b = v(() => {
10
- const e = i.value.length, n = i.value.reduce((s, o) => s + (o.filesize || 0), 0);
6
+ const w = g(!1), i = g([]), u = g(-1), d = g(/* @__PURE__ */ new Map()), A = l.driver || W(), $ = v(() => {
7
+ const { onProgress: e, onDataCallback: n, onCancel: a, onComplete: t, maxFileSize: c, maxFileCount: o, accept: s, multiple: r, autoUpload: f, options: U, onSuccess: P, onError: x, method: Y, driver: Z, ...J } = l;
8
+ return J;
9
+ }), I = v(() => l.method || "POST"), b = v(() => {
10
+ const e = i.value.length, n = i.value.reduce((o, s) => o + (s.filesize || 0), 0);
11
11
  let a = 0, t = 0;
12
- return i.value.forEach((s, o) => {
12
+ return i.value.forEach((o, s) => {
13
13
  var r;
14
- o < u.value ? a += s.filesize || 0 : o === u.value && (a += ((r = s.progress) == null ? void 0 : r.loaded) || 0);
14
+ s < u.value ? a += o.filesize || 0 : s === u.value && (a += ((r = o.progress) == null ? void 0 : r.loaded) || 0);
15
15
  }), n > 0 && (t = Math.round(a / n * 100)), {
16
16
  index: u.value >= 0 ? u.value + 1 : 0,
17
17
  totalFiles: e,
@@ -30,7 +30,7 @@ function ne(l) {
30
30
  return "0 B/s";
31
31
  const n = 1024, a = ["B/s", "KB/s", "MB/s", "GB/s"], t = Math.floor(Math.log(e) / Math.log(n));
32
32
  return `${Number.parseFloat((e / n ** t).toFixed(2))} ${a[t]}`;
33
- }, T = () => V("upload-"), D = async (e, n, a) => {
33
+ }, T = () => R("upload-"), k = async (e, n, a) => {
34
34
  switch (n) {
35
35
  case "file": {
36
36
  if (!(e instanceof File))
@@ -45,10 +45,10 @@ function ne(l) {
45
45
  case "base64": {
46
46
  if (typeof e != "string")
47
47
  throw new TypeError('Payload must be a string when type is "base64"');
48
- const t = e.includes(",") ? e.split(",")[1] : e, c = e.includes(",") ? e.split(",")[0].split(":")[1].split(";")[0] : "application/octet-stream", s = atob(t), o = new Uint8Array(s.length);
49
- for (let f = 0; f < s.length; f++)
50
- o[f] = s.charCodeAt(f);
51
- const r = new Blob([o], { type: c });
48
+ const t = e.includes(",") ? e.split(",")[1] : e, c = e.includes(",") ? e.split(",")[0].split(":")[1].split(";")[0] : "application/octet-stream", o = atob(t), s = new Uint8Array(o.length);
49
+ for (let f = 0; f < o.length; f++)
50
+ s[f] = o.charCodeAt(f);
51
+ const r = new Blob([s], { type: c });
52
52
  return new File([r], "base64-file", { type: c });
53
53
  }
54
54
  case "arrayBuffer": {
@@ -65,8 +65,8 @@ function ne(l) {
65
65
  throw new Error(`File size cannot exceed ${y(l.maxFileSize)}`);
66
66
  if (l.maxFileCount && i.value.length >= l.maxFileCount)
67
67
  throw new Error(`File count cannot exceed ${l.maxFileCount}`);
68
- }, G = async (e, n, a) => {
69
- const t = await D(e, n);
68
+ }, D = async (e, n, a) => {
69
+ const t = await k(e, n);
70
70
  z(t);
71
71
  const c = {
72
72
  id: T(),
@@ -105,40 +105,40 @@ function ne(l) {
105
105
  return m(e, {
106
106
  status: "cancelled"
107
107
  }), (a = l.onCancel) == null || a.call(l, e), C(), !0;
108
- }, K = (e) => {
108
+ }, G = (e) => {
109
109
  e ? e.forEach((n) => F(n)) : i.value.forEach((n) => F(n.id));
110
- }, L = async (e) => {
110
+ }, K = async (e) => {
111
111
  if (!e.file)
112
112
  throw new Error("File not found");
113
113
  z(e.file);
114
114
  const n = new AbortController();
115
115
  d.value.set(e.id, n);
116
116
  const a = Date.now();
117
- m(e.id, { status: "uploading" }), await $.upload(e.file, {
118
- ...I.value,
119
- method: k.value,
117
+ m(e.id, { status: "uploading" }), await A.upload(e.file, {
118
+ ...$.value,
119
+ method: I.value,
120
120
  signal: n.signal,
121
121
  onUploadProgress: (t) => {
122
122
  var x;
123
- const o = (Date.now() - a) / 1e3, r = o > 0 ? t.loaded / o : 0, f = (t.total || 0) - t.loaded, P = r > 0 ? f / r : 0, A = {
123
+ const s = (Date.now() - a) / 1e3, r = s > 0 ? t.loaded / s : 0, f = (t.total || 0) - t.loaded, U = r > 0 ? f / r : 0, P = {
124
124
  loaded: t.loaded,
125
125
  total: t.total,
126
126
  percent: t.percent || 0,
127
127
  speed: Math.round(r),
128
128
  speedText: h(r),
129
- uploadTime: Math.round(o),
130
- remainingTime: Math.round(P)
129
+ uploadTime: Math.round(s),
130
+ remainingTime: Math.round(U)
131
131
  };
132
132
  m(e.id, {
133
133
  status: "uploading",
134
- progress: A
134
+ progress: P
135
135
  }), (x = l.onProgress) == null || x.call(l, b.value);
136
136
  }
137
137
  }).then((t) => {
138
- var o, r;
138
+ var s, r;
139
139
  if (e.status === "cancelled")
140
140
  return;
141
- const c = ((o = l.onDataCallback) == null ? void 0 : o.call(l, t, e)) || {}, s = Math.round((Date.now() - a) / 1e3);
141
+ const c = ((s = l.onDataCallback) == null ? void 0 : s.call(l, t, e)) || {}, o = Math.round((Date.now() - a) / 1e3);
142
142
  m(e.id, {
143
143
  status: "success",
144
144
  data: t,
@@ -149,7 +149,7 @@ function ne(l) {
149
149
  percent: 100,
150
150
  speed: 0,
151
151
  speedText: h(0),
152
- uploadTime: s,
152
+ uploadTime: o,
153
153
  remainingTime: 0
154
154
  }
155
155
  }), d.value.delete(e.id), (r = l.onSuccess) == null || r.call(l, t);
@@ -169,8 +169,8 @@ function ne(l) {
169
169
  w.value = !0;
170
170
  try {
171
171
  for (let a = 0; a < e.length; a++) {
172
- const t = e[a], c = i.value.findIndex((s) => s.id === t.id);
173
- u.value = c, await L(t);
172
+ const t = e[a], c = i.value.findIndex((o) => o.id === t.id);
173
+ u.value = c, await K(t);
174
174
  }
175
175
  } catch (a) {
176
176
  throw (n = l.onError) == null || n.call(l, {
@@ -184,12 +184,12 @@ function ne(l) {
184
184
  }, E = async (e, n = "file") => {
185
185
  var a;
186
186
  try {
187
- if (l.multiple || M(), !l.multiple && e.length > 1)
187
+ if (!l.multiple && e.length > 1)
188
188
  throw new Error("Single file mode: only one file can be selected");
189
189
  if (l.maxFileCount && i.value.length + e.length > l.maxFileCount)
190
190
  throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);
191
191
  for (const t of e)
192
- await G(t, n);
192
+ await D(t, n);
193
193
  } catch (t) {
194
194
  throw (a = l.onError) == null || a.call(l, {
195
195
  status: (t == null ? void 0 : t.status) || 400,
@@ -197,14 +197,11 @@ function ne(l) {
197
197
  }), t;
198
198
  }
199
199
  l.autoUpload && B();
200
- }, N = (e) => {
201
- const n = e.map((a) => H(a));
202
- i.value.push(...n);
203
- }, M = () => {
200
+ }, L = () => {
204
201
  i.value.forEach((e) => {
205
202
  F(e.id);
206
203
  }), d.value.clear(), i.value = [], u.value = -1;
207
- }, S = (e) => {
204
+ }, M = (e) => {
208
205
  const n = i.value.find((t) => t.id === e);
209
206
  if (n && n.status === "uploading") {
210
207
  m(e, {
@@ -217,12 +214,12 @@ function ne(l) {
217
214
  }
218
215
  const a = i.value.findIndex((t) => t.id === e);
219
216
  a !== -1 && i.value.splice(a, 1);
220
- }, q = (e) => {
221
- e ? e.forEach((n) => S(n)) : i.value.forEach((n) => S(n.id));
222
- }, { files: O, open: j, reset: U } = R({
217
+ }, N = (e) => {
218
+ e ? e.forEach((n) => M(n)) : i.value.forEach((n) => M(n.id));
219
+ }, { files: q, open: O, reset: S } = Q({
223
220
  accept: l.accept,
224
221
  multiple: l.multiple || !1
225
- }), H = (e) => ({
222
+ }), j = (e) => ({
226
223
  id: T(),
227
224
  ...e,
228
225
  filesizeText: e.filesize ? y(e.filesize) : void 0,
@@ -237,15 +234,15 @@ function ne(l) {
237
234
  uploadTime: 0
238
235
  }
239
236
  });
240
- W(O, async (e) => {
237
+ V(q, async (e) => {
241
238
  if (e && e.length > 0) {
242
239
  const n = Array.from(e);
243
- U(), await E(n, "file").catch((a) => {
240
+ S(), await E(n, "file").catch((a) => {
244
241
  console.warn("Failed to add selected files:", a);
245
242
  });
246
243
  }
247
244
  });
248
- const J = v(() => i.value.filter((e) => e.status === "success").map((e) => ({
245
+ const H = v(() => i.value.filter((e) => e.status === "success").map((e) => ({
249
246
  url: e.url,
250
247
  filename: e.filename,
251
248
  filesize: e.filesize,
@@ -254,16 +251,19 @@ function ne(l) {
254
251
  return {
255
252
  isUploading: w,
256
253
  uploadFiles: i,
257
- dataFiles: J,
254
+ dataFiles: H,
258
255
  progress: b,
259
- open: j,
256
+ open: O,
260
257
  trigger: B,
261
- resetFiles: U,
262
- clearFiles: M,
263
- removeFiles: q,
258
+ resetFiles: S,
259
+ clearFiles: L,
260
+ removeFiles: N,
264
261
  addFiles: E,
265
- addDataFiles: N,
266
- cancelFiles: K
262
+ addDataFiles: (e) => {
263
+ const n = e.map((a) => j(a));
264
+ i.value.push(...n);
265
+ },
266
+ cancelFiles: G
267
267
  };
268
268
  }
269
269
  export {
@@ -0,0 +1,18 @@
1
+ interface IUseTreeProps {
2
+ path?: string;
3
+ params?: Record<string, any>;
4
+ treeOptions?: {
5
+ valueKey?: string;
6
+ parentKey?: string;
7
+ sortKey?: string;
8
+ childrenKey?: string;
9
+ };
10
+ converTree?: boolean;
11
+ providerName?: string;
12
+ }
13
+ export declare function useTree(props: IUseTreeProps): {
14
+ options: import("vue").ComputedRef<any>;
15
+ loading: import("vue").ComputedRef<boolean>;
16
+ expanded: import("vue").ComputedRef<unknown[]>;
17
+ };
18
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "0.1.14",
4
+ "version": "0.1.15",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {