@duxweb/dvha-core 0.1.13 → 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),P=l.driver||V.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,...J}=l;return J}),$=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-"),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.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=e=>{const n=e.map(a=>j(a));i.value.push(...n)},K=()=>{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)},L=e=>{e?e.forEach(n=>E(n)):i.value.forEach(n=>E(n.id))},{files:N,open:O,reset:M}=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);M(),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:M,clearFiles:K,removeFiles:L,addFiles:B,addDataFiles:G,cancelFiles:q}}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,11 +1,11 @@
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()), A = l.driver || X(), $ = 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, ...Q } = l;
8
- return Q;
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
9
  }), I = v(() => l.method || "POST"), b = v(() => {
10
10
  const e = i.value.length, n = i.value.reduce((o, s) => o + (s.filesize || 0), 0);
11
11
  let a = 0, t = 0;
@@ -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-"), k = 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))
@@ -184,6 +184,8 @@ function ne(l) {
184
184
  }, E = async (e, n = "file") => {
185
185
  var a;
186
186
  try {
187
+ if (!l.multiple && e.length > 1)
188
+ throw new Error("Single file mode: only one file can be selected");
187
189
  if (l.maxFileCount && i.value.length + e.length > l.maxFileCount)
188
190
  throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);
189
191
  for (const t of e)
@@ -195,10 +197,7 @@ function ne(l) {
195
197
  }), t;
196
198
  }
197
199
  l.autoUpload && B();
198
- }, L = (e) => {
199
- const n = e.map((a) => H(a));
200
- i.value.push(...n);
201
- }, N = () => {
200
+ }, L = () => {
202
201
  i.value.forEach((e) => {
203
202
  F(e.id);
204
203
  }), d.value.clear(), i.value = [], u.value = -1;
@@ -215,12 +214,12 @@ function ne(l) {
215
214
  }
216
215
  const a = i.value.findIndex((t) => t.id === e);
217
216
  a !== -1 && i.value.splice(a, 1);
218
- }, q = (e) => {
217
+ }, N = (e) => {
219
218
  e ? e.forEach((n) => M(n)) : i.value.forEach((n) => M(n.id));
220
- }, { files: O, open: j, reset: S } = R({
219
+ }, { files: q, open: O, reset: S } = Q({
221
220
  accept: l.accept,
222
221
  multiple: l.multiple || !1
223
- }), H = (e) => ({
222
+ }), j = (e) => ({
224
223
  id: T(),
225
224
  ...e,
226
225
  filesizeText: e.filesize ? y(e.filesize) : void 0,
@@ -235,7 +234,7 @@ function ne(l) {
235
234
  uploadTime: 0
236
235
  }
237
236
  });
238
- W(O, async (e) => {
237
+ V(q, async (e) => {
239
238
  if (e && e.length > 0) {
240
239
  const n = Array.from(e);
241
240
  S(), await E(n, "file").catch((a) => {
@@ -243,7 +242,7 @@ function ne(l) {
243
242
  });
244
243
  }
245
244
  });
246
- 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) => ({
247
246
  url: e.url,
248
247
  filename: e.filename,
249
248
  filesize: e.filesize,
@@ -252,15 +251,18 @@ function ne(l) {
252
251
  return {
253
252
  isUploading: w,
254
253
  uploadFiles: i,
255
- dataFiles: J,
254
+ dataFiles: H,
256
255
  progress: b,
257
- open: j,
256
+ open: O,
258
257
  trigger: B,
259
258
  resetFiles: S,
260
- clearFiles: N,
261
- removeFiles: q,
259
+ clearFiles: L,
260
+ removeFiles: N,
262
261
  addFiles: E,
263
- addDataFiles: L,
262
+ addDataFiles: (e) => {
263
+ const n = e.map((a) => j(a));
264
+ i.value.push(...n);
265
+ },
264
266
  cancelFiles: G
265
267
  };
266
268
  }
@@ -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.13",
4
+ "version": "0.1.15",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {