@armco/uploader 0.0.4 → 0.0.6

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.
package/cjs/Uploader.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-Uploader .ar-Uploader__file-uploader-progress-bar{transition:max-height .3s,opacity .3s,padding .3s,margin-bottom .3s,background-color .3s;opacity:0;max-height:0}.ar-Uploader .ar-Uploader__file-uploader-progress-bar.show{opacity:1;max-height:4rem}.ar-Uploader .ar-Uploader__file-uploader-progress-bar:hover{background-color:var(--ar-bg-hover-6)}.ar-Uploader .ar-Button.loading .pre{animation:rotating .5s linear infinite}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{transition:border .3s ease-in-out;border:1px dashed lightgrey;border-radius:.5rem;padding:.5rem;background-color:var(--ar-bg-base)}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input:has(.ar-Avatar.FAILED){border-color:var(--ar-color-danger-soft)}.ar-Uploader .ar-Uploader__upload-prompt-text{color:var(--ar-color-obscure-4)}.ar-Uploader .ar-Uploader__upload-message{color:var(--ar-color-obscure-2)}")),document.head.appendChild(r)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
- "use strict";const s=require("react/jsx-runtime"),c=require("react"),C=require("uuid"),ie=require("react-dnd-html5-backend"),n=require("@armco/types"),oe=require("./useUpload.js"),ce=require("@armco/utils/hooks"),ue=require("@armco/utils/helper"),de=require("@armco/utils/network"),me=require("@armco/shared-components/Droppable"),W=require("@armco/shared-components/Button"),fe=require("@armco/shared-components/Text"),pe=require("@armco/shared-components/ProgressIndicator"),ge=require("@armco/shared-components/Tooltip"),xe=require("@armco/configs/endpoints"),P=require("@armco/avatar"),_=require("@armco/icon"),he=({clear:i,demo:a,disabled:p,result:u})=>{const[F,A]=c.useState(),[T,d]=c.useState();c.useEffect(()=>{d(!0)},[]);const b=u.type==="image",I=s.jsx(pe,{label:u.file.name,preIcon:b?"":"im.ImAttachment",progress:u.progress,slot:n.ArPopoverSlots.ANCHOR,rightEndContent:(F||u.status===n.ArProgress.FAILED)&&s.jsx(_,{icon:"ri.RiDeleteBin6Fill",attributes:{colors:{fillColor:u.status===n.ArProgress.FAILED?"#ff4d4f":"grey"},classes:p?"":"cursor-pointer"},events:{onClick:()=>{p||(d(!1),setTimeout(i,300))}}}),status:u.status,thumbnailRenderer:()=>b?s.jsx(P,{classes:"me-3",item:u,size:n.ArSizes.XSMALL,variant:"circle",viewOnly:!0}):null}),R=x=>typeof x=="string"?x:x.error||x.message||"Server Error";return s.jsx("div",{className:`ar-Uploader__file-uploader-progress-bar position-relative ${T?" show p-1 border-radius l1 mb-1 cursor-pointer":" px-1"} ${u.status}`,onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1),children:u.status===n.ArProgress.FAILED?s.jsxs(ge,{demo:a,children:[I,s.jsx("span",{slot:n.ArPopoverSlots.POPOVER,children:R(u.error)})]}):I})},ye=c.memo(i=>{const{acceptedFileTypes:a,acceptedFileCount:p,afterUpload:u,allowMultiple:F,beforeUpload:A,demo:T,disabled:d,uploadEntryRenderer:b,errorMessage:I="Failed to upload",endpoint:R,fileSizeLimit:x="5mb",files:g,handler:V,message:U,onFileSelected:q,avatarSize:J=n.ArSizes.REGULAR,variant:r="compact",theme:K,updateEndpoint:M,uploadSequential:X,uploadButtonText:w="Upload",uploadingButtonText:z="Uploading..."}=i,m=c.useRef(null),{notify:j}=ce.useNotification(),[t,$]=c.useState(),[v,D]=c.useState(),[L,B]=c.useState(),[N,k]=c.useState(),Y=c.useMemo(()=>v?p!==void 0?g==null?void 0:g.slice(0,p):g:g==null?void 0:g.slice(0,1),[g]),{clear:E,upload:Q,results:O}=oe(R||V||"",X,Y),h=r==="image-circle"||r==="image-rect";c.useEffect(()=>{$(O),(!O||Object.keys(O).length===0)&&m.current&&(m.current.value="");let e;t&&Object.keys(t).length>0&&Object.keys(t).every(l=>{const o=t[l];return e||(e=o.status===n.ArProgress.FAILED),o.status===n.ArProgress.FAILED}),e&&k(I)},[O]),c.useEffect(()=>{D(F)},[F]),c.useEffect(()=>{B(a)},[a]),c.useEffect(()=>{h&&(D(!1),B(["image/jpeg","image/png","image/gif","image/svg+xml"]))},[h]);const G=e=>{const l=ue.convertToBytes(x);let o;try{o=p!==void 0&&(typeof p=="number"?p:parseInt(p))}catch{console.warn("Incorrect prop acceptedFileCount supplied, should be a numeric value")}if(typeof o=="number"&&e&&e.length+Object.keys(t||{}).length>o)k("Exceeded allowed number of files."),j({message:"You've selected more then allowed number of files",type:n.ArAlertType.WARNING,uid:C.v4()});else if(e.findIndex(f=>f.size>l)>-1){const f=`${v?"One or more files exceed ":"Selected file exceeds "}specified size limit of ${x}`;k(f),j({message:f,type:n.ArAlertType.WARNING,uid:C.v4()})}else e&&e.length>0&&(Q(e,u,v),q&&q(e))},Z=e=>{var o;k("");const l=Array.from((o=e.target||e.dataTransfer)==null?void 0:o.files);(!A||A(l,()=>G(l)))&&G(l)},y=t&&Object.keys(t).findIndex(e=>t[e].status===n.ArProgress.IN_PROGRESS)>-1,ee=!!(t&&Object.keys(t).length>0&&Object.keys(t).every(e=>{const l=t[e];return l.status===n.ArProgress.COMPLETED||l.status===n.ArProgress.FAILED})),S=t&&t[Object.keys(t)[0]],te=e=>{if(t&&S){const l=Object.keys(t).find(o=>o.startsWith(S.file.name));if(l){const o={...t[l]};o.imageProps=e,t[l]=o,$({...t})}}},se=e=>{if(t&&S){const l=Object.keys(t).find(o=>o.startsWith(S.file.name));if(l){const o=t[l];let f=M||R;if(f){const ae=process.env.NODE_ENV||"development";f=(f.startsWith("http")?"":xe.API_CONFIG.STATIC_HOST[ae])+f,de.put(f,o).then(ne=>{ne.status===200?j({message:"Image updaetd successfully!",type:n.ArAlertType.SUCCESS,uid:C.v4()}):j({message:"Failed to update image!",type:n.ArAlertType.ERROR,uid:C.v4()})})}else j({message:"Missing image update URL",type:n.ArAlertType.WARNING,uid:C.v4()})}}},H=s.jsxs("div",{className:`ar-Uploader__file-input flex-v-center${y?" disabled":""}${r!=="compact"&&!y&&!d?" cursor-pointer":""}${r==="large"?" flex-h-center flex-column p-3":" justify-content-between"}${r==="image-circle"?" border-radius-50":""}`,onClick:()=>{var e;return r!=="compact"&&!y&&!d&&((e=m.current)==null?void 0:e.click())},children:[h?s.jsx(P,{clearImage:E,demo:T,variant:r==="image-circle"?"circle":"rect",item:S,onChange:te,onCommit:se,size:J,uploadButtonText:w,uploadingButtonText:z}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ar-Uploader__file-input__prompt d-flex flex-column",children:[s.jsx("div",{className:`d-inline-flex ${r==="large"?" flex-center flex-column":"flex-v-center"}`,children:r==="compact"?s.jsxs(s.Fragment,{children:[s.jsx(W,{classes:y?"loading":"",content:y?z:w,preIcon:y?"ri.RiLoader5Fill":ee?N?"fa.FaExclamation":"fa.FaCheck":"md.MdOutlineFileUpload",onClick:()=>{var e;return(e=m.current)==null?void 0:e.click()},theme:K,disabled:d||y}),t&&Object.keys(t).length>0&&r==="compact"&&s.jsxs(s.Fragment,{children:[v?s.jsx("span",{className:"fw-bold flex-v-center ms-3",children:`(${Object.keys(t).length} file${Object.keys(t).length>1?"s":""})`}):s.jsx(fe,{classes:"fw-bold flex-v-center ms-3 text-decoration-underline",descriptor:{id:"temp-text-id",order:0,name:"Text",text:t[Object.keys(t)[0]].file.name,chunks:{}},overflowEllipsis:!0,overflowTooltip:!0}),s.jsx(_,{icon:"io5.IoClose",attributes:{colors:{fillColor:"red"},classes:`ms-2 ${d?"":"cursor-pointer"}`},events:{onClick:()=>{d&&(E(),m.current&&(m.current.value=""))}}})]})]}):s.jsxs(s.Fragment,{children:[s.jsx(_,{icon:"io5.IoFileTrayOutline",attributes:{colors:{fillColor:"#1677ff"},classes:r==="large"?"mb-2":"me-3",size:r==="large"?"3rem":"1rem"}}),s.jsx("span",{className:`ar-Uploader__upload-prompt-text${r==="large"?" h5 mb-0":""}`,children:"Click or drag files here to upload"})]})}),U&&s.jsx("small",{className:`ar-Uploader__upload-message text-decoration-underline ${r==="large"?"fw-bold f3 mt-2 mb-2":"mt-1"}`,children:U})]}),s.jsx("div",{className:"ar-Uploader__file-input__actions",children:r!=="compact"&&t&&Object.keys(t).length>0&&s.jsx(W,{containerClasses:`text-end${r==="large"?" mt-3":""}`,content:"Clear",variant:n.ArButtonVariants.DANGER,size:r==="regular"?n.ArSizes.XSMALL:n.ArSizes.SMALL,onClick:e=>{e.stopPropagation(),E(),m.current&&(m.current.value="")}})})]}),s.jsx("input",{className:"ar-Uploader__input d-none",type:"file",onChange:Z,ref:m,title:"file-uploader",accept:Array.isArray(L)?L.join(","):L,disabled:d,multiple:v})]}),re=N&&s.jsx("span",{className:"error my-1 small",children:N}),le=t&&r!=="compact"&&s.jsx("div",{className:"ar-Uploader__file-upload-progress mt-2",children:Object.entries(t).map(([e,l])=>b?b(l,()=>E(e)):s.jsx(he,{clear:()=>E(e),demo:!!T,disabled:!!d,result:l},e))});return s.jsxs("div",{className:`ar-Uploader d-flex flex-column${r?" "+r:""}${h?" flex-center":" w-100"}`,onDragOver:e=>e.preventDefault(),onDragLeave:e=>e.preventDefault(),children:[r!=="compact"?s.jsx(me,{dropHandler:e=>{m.current&&!d&&(m.current.files=e.dataTransfer.files,m.current.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0})))},acceptTypes:[ie.NativeTypes.FILE],hideHoverEffect:h||d,children:H}):H,!h&&re,!h&&le]})},(i,a)=>i.acceptedFileTypes===a.acceptedFileTypes&&i.acceptedFileCount===a.acceptedFileCount&&i.allowMultiple===a.allowMultiple&&i.disabled===a.disabled&&i.errorMessage===a.errorMessage&&i.endpoint===a.endpoint&&i.fileSizeLimit===a.fileSizeLimit&&JSON.stringify(i.files)===JSON.stringify(a.files)&&i.message===a.message&&i.avatarSize===a.avatarSize&&i.variant===a.variant&&i.theme===a.theme&&i.uploadSequential===a.uploadSequential&&i.uploadButtonText===a.uploadButtonText&&i.uploadingButtonText===a.uploadingButtonText);module.exports=ye;
1
+ (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-Uploader .ar-Uploader__file-uploader-progress-bar{transition:max-height .3s,opacity .3s,padding .3s,margin-bottom .3s,background-color .3s;opacity:0;max-height:0}.ar-Uploader .ar-Uploader__file-uploader-progress-bar.show{opacity:1;max-height:4rem}.ar-Uploader .ar-Uploader__file-uploader-progress-bar:hover{background-color:var(--ar-bg-hover-6)}.ar-Uploader .ar-Button.loading .pre{animation:rotating .5s linear infinite}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{transition:border .3s ease-in-out}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input:has(.ar-Avatar.FAILED){border-color:var(--ar-color-danger-soft)}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{border:1px dashed lightgrey;border-radius:.5rem;padding:.5rem;background-color:var(--ar-bg-base)}.ar-Uploader .ar-Uploader__upload-prompt-text{color:var(--ar-color-obscure-4)}.ar-Uploader .ar-Uploader__upload-message{color:var(--ar-color-obscure-2)}")),document.head.appendChild(r)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
+ "use strict";const t=require("react/jsx-runtime"),c=require("react"),S=require("uuid"),oe=require("react-dnd-html5-backend"),ce=require("@armco/configs/endpoints"),C=require("@armco/utils"),ue=require("@armco/utils/hooks"),de=require("@armco/utils/network"),o=require("@armco/shared-components/enums"),me=require("@armco/shared-components/Droppable"),P=require("@armco/shared-components/Button"),fe=require("@armco/shared-components/Text"),pe=require("@armco/shared-components/ProgressIndicator"),ge=require("@armco/shared-components/Tooltip"),V=require("@armco/shared-components/Avatar"),q=require("@armco/icon"),xe=require("./utils.js"),he=require("./useUpload.js"),ye=({clear:a,demo:n,disabled:p,result:u})=>{const[F,y]=c.useState(),[T,d]=c.useState();c.useEffect(()=>{d(!0)},[]);const A=u.type==="image",I=t.jsx(pe,{label:u.file.name,preIcon:A?"":"im.ImAttachment",progress:u.progress,slot:o.ArPopoverSlots.ANCHOR,rightEndContent:(F||u.status===o.ArProgress.FAILED)&&t.jsx(q,{icon:"ri.RiDeleteBin6Fill",attributes:{colors:{fillColor:u.status===o.ArProgress.FAILED?"#ff4d4f":"grey"},classes:p?"":"cursor-pointer"},events:{onClick:()=>{p||(d(!1),setTimeout(a,300))}}}),status:u.status,thumbnailRenderer:()=>A?t.jsx(V,{classes:"me-3",item:u,size:o.ArSizes.XSMALL,variant:"circle",viewOnly:!0}):null}),R=g=>typeof g=="string"?g:g.error||g.message||"Server Error";return t.jsx("div",{className:`ar-Uploader__file-uploader-progress-bar position-relative ${T?" show p-1 border-radius l1 mb-1 cursor-pointer":" px-1"} ${u.status}`,onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),children:u.status===o.ArProgress.FAILED?t.jsxs(ge,{demo:n,children:[I,t.jsx("span",{slot:o.ArPopoverSlots.POPOVER,children:R(u.error)})]}):I})},Ae=c.memo(a=>{const{acceptedFileTypes:n,acceptedFileCount:p,afterUpload:u,allowMultiple:F,beforeUpload:y,demo:T,disabled:d,uploadEntryRenderer:A,errorMessage:I="Failed to upload",endpoint:R,fileSizeLimit:g="5mb",files:k,handler:J,message:U,onFileSelected:M,avatarSize:K=o.ArSizes.REGULAR,variant:r="compact",theme:X,updateEndpoint:w,uploadSequential:Y,uploadButtonText:$="Upload",uploadingButtonText:z="Uploading..."}=a,m=c.useRef(null),{notify:b}=ue.useNotification(),[e,D]=c.useState(),[j,B]=c.useState(),[N,G]=c.useState(),[_,O]=c.useState(),Q=c.useMemo(()=>j?p!==void 0?k?.slice(0,p):k:k?.slice(0,1),[k]),{clear:v,upload:Z,results:L}=he(R||J||"",Y,Q),x=r==="image-circle"||r==="image-rect";c.useEffect(()=>{D(L),(!L||Object.keys(L).length===0)&&m.current&&(m.current.value="");let s;e&&Object.keys(e).length>0&&Object.keys(e).every(l=>{const i=e[l];return s||=i.status===o.ArProgress.FAILED,i.status===o.ArProgress.FAILED}),s&&O(I)},[L]),c.useEffect(()=>{B(F)},[F]),c.useEffect(()=>{G(n)},[n]),c.useEffect(()=>{x&&(B(!1),G(["image/jpeg","image/png","image/gif","image/svg+xml"]))},[x]);const H=s=>{const l=xe.convertToBytes(g);let i;try{i=p!==void 0&&(typeof p=="number"?p:parseInt(p))}catch{console.warn("Incorrect prop acceptedFileCount supplied, should be a numeric value")}if(typeof i=="number"&&s&&s.length+Object.keys(e||{}).length>i)O("Exceeded allowed number of files."),b({message:"You've selected more then allowed number of files",type:C.ArAlertType.WARNING,uid:S.v4()});else if(s.findIndex(f=>f.size>l)>-1){const f=`${j?"One or more files exceed ":"Selected file exceeds "}specified size limit of ${g}`;O(f),b({message:f,type:C.ArAlertType.WARNING,uid:S.v4()})}else s&&s.length>0&&(Z(s,u,j),M&&M(s))},ee=s=>{O("");const l=Array.from((s.target||s.dataTransfer)?.files);(!y||y(l,()=>H(l)))&&H(l)},h=e&&Object.keys(e).findIndex(s=>e[s].status===o.ArProgress.IN_PROGRESS)>-1,te=!!(e&&Object.keys(e).length>0&&Object.keys(e).every(s=>{const l=e[s];return l.status===o.ArProgress.COMPLETED||l.status===o.ArProgress.FAILED})),E=e&&e[Object.keys(e)[0]],se=s=>{if(e&&E){const l=Object.keys(e).find(i=>i.startsWith(E.file.name));if(l){const i={...e[l]};i.imageProps=s,e[l]=i,D({...e})}}},re=s=>{if(e&&E){const l=Object.keys(e).find(i=>i.startsWith(E.file.name));if(l){const i=e[l];let f=w||R;if(f){const ae=process.env.NODE_ENV||"development";f=(f.startsWith("http")?"":ce.API_CONFIG.STATIC_HOST[ae])+f,de.put(f,i).then(ie=>{ie.status===200?b({message:"Image updaetd successfully!",type:C.ArAlertType.SUCCESS,uid:S.v4()}):b({message:"Failed to update image!",type:C.ArAlertType.ERROR,uid:S.v4()})})}else b({message:"Missing image update URL",type:C.ArAlertType.WARNING,uid:S.v4()})}}},W=t.jsxs("div",{className:`ar-Uploader__file-input flex-v-center${h?" disabled":""}${r!=="compact"&&!h&&!d?" cursor-pointer":""}${r==="large"?" flex-h-center flex-column p-3":" justify-content-between"}${r==="image-circle"?" border-radius-50":""}`,onClick:()=>r!=="compact"&&!h&&!d&&m.current?.click(),children:[x?t.jsx(V,{clearImage:v,demo:T,variant:r==="image-circle"?"circle":"rect",item:E,onChange:se,onCommit:re,size:K,uploadButtonText:$,uploadingButtonText:z}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ar-Uploader__file-input__prompt d-flex flex-column",children:[t.jsx("div",{className:`d-inline-flex ${r==="large"?" flex-center flex-column":"flex-v-center"}`,children:r==="compact"?t.jsxs(t.Fragment,{children:[t.jsx(P,{classes:h?"loading":"",content:h?z:$,preIcon:h?"ri.RiLoader5Fill":te?_?"fa.FaExclamation":"fa.FaCheck":"md.MdOutlineFileUpload",onClick:()=>m.current?.click(),theme:X,disabled:d||h}),e&&Object.keys(e).length>0&&r==="compact"&&t.jsxs(t.Fragment,{children:[j?t.jsx("span",{className:"fw-bold flex-v-center ms-3",children:`(${Object.keys(e).length} file${Object.keys(e).length>1?"s":""})`}):t.jsx(fe,{classes:"fw-bold flex-v-center ms-3 text-decoration-underline",descriptor:{id:"temp-text-id",order:0,name:"Text",text:e[Object.keys(e)[0]].file.name,chunks:{}},overflowEllipsis:!0,overflowTooltip:!0}),t.jsx(q,{icon:"io5.IoClose",attributes:{colors:{fillColor:"red"},classes:`ms-2 ${d?"":"cursor-pointer"}`},events:{onClick:()=>{d&&(v(),m.current&&(m.current.value=""))}}})]})]}):t.jsxs(t.Fragment,{children:[t.jsx(q,{icon:"io5.IoFileTrayOutline",attributes:{colors:{fillColor:"#1677ff"},classes:r==="large"?"mb-2":"me-3",size:r==="large"?"3rem":"1rem"}}),t.jsx("span",{className:`ar-Uploader__upload-prompt-text${r==="large"?" h5 mb-0":""}`,children:"Click or drag files here to upload"})]})}),U&&t.jsx("small",{className:`ar-Uploader__upload-message text-decoration-underline ${r==="large"?"fw-bold f3 mt-2 mb-2":"mt-1"}`,children:U})]}),t.jsx("div",{className:"ar-Uploader__file-input__actions",children:r!=="compact"&&e&&Object.keys(e).length>0&&t.jsx(P,{containerClasses:`text-end${r==="large"?" mt-3":""}`,content:"Clear",variant:o.ArButtonVariants.DANGER,size:r==="regular"?o.ArSizes.XSMALL:o.ArSizes.SMALL,onClick:s=>{s.stopPropagation(),v(),m.current&&(m.current.value="")}})})]}),t.jsx("input",{className:"ar-Uploader__input d-none",type:"file",onChange:ee,ref:m,title:"file-uploader",accept:Array.isArray(N)?N.join(","):N,disabled:d,multiple:j})]}),le=_&&t.jsx("span",{className:"error my-1 small",children:_}),ne=e&&r!=="compact"&&t.jsx("div",{className:"ar-Uploader__file-upload-progress mt-2",children:Object.entries(e).map(([s,l])=>A?A(l,()=>v(s)):t.jsx(ye,{clear:()=>v(s),demo:!!T,disabled:!!d,result:l},s))});return t.jsxs("div",{className:`ar-Uploader d-flex flex-column${r?" "+r:""}${x?" flex-center":" w-100"}`,onDragOver:s=>s.preventDefault(),onDragLeave:s=>s.preventDefault(),children:[r!=="compact"?t.jsx(me,{dropHandler:s=>{m.current&&!d&&(m.current.files=s.dataTransfer.files,m.current.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0})))},acceptTypes:[oe.NativeTypes.FILE],hideHoverEffect:x||d,children:W}):W,!x&&le,!x&&ne]})},(a,n)=>a.acceptedFileTypes===n.acceptedFileTypes&&a.acceptedFileCount===n.acceptedFileCount&&a.allowMultiple===n.allowMultiple&&a.disabled===n.disabled&&a.errorMessage===n.errorMessage&&a.endpoint===n.endpoint&&a.fileSizeLimit===n.fileSizeLimit&&JSON.stringify(a.files)===JSON.stringify(n.files)&&a.message===n.message&&a.avatarSize===n.avatarSize&&a.variant===n.variant&&a.theme===n.theme&&a.uploadSequential===n.uploadSequential&&a.uploadButtonText===n.uploadButtonText&&a.uploadingButtonText===n.uploadingButtonText);module.exports=Ae;
package/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./useUpload.js"),u=require("./Uploader.js");exports.useUpload=e;exports.default=u;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("./useUpload.js"),r=require("./Uploader.js"),e=require("./utils.js");exports.useUpload=t;exports.default=r;exports.convertToBytes=e.convertToBytes;exports.generateFileKey=e.generateFileKey;exports.isImage=e.isImage;
package/cjs/useUpload.js CHANGED
@@ -1 +1 @@
1
- "use strict";const f=require("react"),E=require("@armco/types"),g=require("@armco/utils/helper"),P=require("@armco/utils/network"),S={status:E.ArProgress.COMPLETED,progress:100},d={status:E.ArProgress.FAILED,progress:0},A=(i,p,h)=>{const[l,o]=f.useState(),u=f.useRef({}),c=f.useRef({});f.useEffect(()=>{if(h){const e={};h==null||h.forEach(s=>{e[g.generateFileKey(s)]={...s,progress:100,status:E.ArProgress.COMPLETED,file:typeof s=="object"?s:{name:s.name}}}),o(e)}},[h]),f.useEffect(()=>{const e=c.current;return()=>{Object.keys(e).forEach(s=>clearInterval(e[s]))}},[c]);const v=e=>{if(e){const s={...l};delete s[e],o(s),u.current[e]=!0,clearInterval(c.current[e])}else o(void 0),l&&Object.keys(l).forEach(s=>l[s].status===E.ArProgress.IN_PROGRESS&&(u.current[s]=!0)),Object.keys(c.current).forEach(s=>clearInterval(c.current[s]))},R=async e=>{const y=typeof i=="function"?i:null,r=g.generateFileKey(e);return c.current[r]=setInterval(()=>{o(n=>{const t=n&&n[r];if(!t||t.progress>=95)return c.current&&clearInterval(c.current[r]),n;const a=Math.floor(Math.random()*8)+5;return{...n,[r]:{...t,progress:t.progress+a}}})},500),y?await y(e).then(n=>{u.current[r]||(n.ok||o(t=>({...t,[r]:{file:e,...d}})),o(t=>({...t,[r]:{file:e,...S}})))}).catch(()=>{u.current[r]||o(n=>({...n,[r]:{file:e,...d}}))}).finally(()=>{c.current&&clearInterval(c.current[r])}):await P.upload(i,e).then(n=>{if(u.current[r])delete u.current[r],delete c.current[r];else{if(!n.body){o(a=>({...a,[r]:{file:e,...d,error:n.body,httpStatus:n.status}}));return}const t=n.body.saved[0];o(a=>({...a,[r]:{...t||{},file:e,...S}}))}}).catch(n=>{u.current[r]?(delete u.current[r],delete c.current[r]):o(t=>({...t,[r]:{file:e,...d,error:n}}))}).finally(()=>{c.current&&clearInterval(c.current[r])})};return{clear:v,upload:async(e,s,y)=>{const r={};e.forEach(t=>{const a=g.generateFileKey(t);r[a]={file:t,status:E.ArProgress.IN_PROGRESS,progress:p?1:Math.floor(Math.random()*10)}}),o(y?{...l,...r}:r);let n=[];for(const t of e)p?n.push(await R(t)):n.push(R(t));await Promise.allSettled(n).then(t=>s&&s(t))},results:l}};module.exports=A;
1
+ "use strict";const f=require("react"),i=require("@armco/shared-components/enums"),P=require("@armco/utils/network"),g=require("./utils.js"),S={status:i.ArProgress.COMPLETED,progress:100},E={status:i.ArProgress.FAILED,progress:0},m=(d,p,y)=>{const[l,o]=f.useState(),u=f.useRef({}),c=f.useRef({});f.useEffect(()=>{if(y){const e={};y?.forEach(s=>{e[g.generateFileKey(s)]={...s,progress:100,status:i.ArProgress.COMPLETED,file:typeof s=="object"?s:{name:s.name}}}),o(e)}},[y]),f.useEffect(()=>{const e=c.current;return()=>{Object.keys(e).forEach(s=>clearInterval(e[s]))}},[c]);const v=e=>{if(e){const s={...l};delete s[e],o(s),u.current[e]=!0,clearInterval(c.current[e])}else o(void 0),l&&Object.keys(l).forEach(s=>l[s].status===i.ArProgress.IN_PROGRESS&&(u.current[s]=!0)),Object.keys(c.current).forEach(s=>clearInterval(c.current[s]))},R=async e=>{const h=typeof d=="function"?d:null,r=g.generateFileKey(e);return c.current[r]=setInterval(()=>{o(n=>{const t=n&&n[r];if(!t||t.progress>=95)return c.current&&clearInterval(c.current[r]),n;const a=Math.floor(Math.random()*8)+5;return{...n,[r]:{...t,progress:t.progress+a}}})},500),h?await h(e).then(n=>{u.current[r]||(n.ok||o(t=>({...t,[r]:{file:e,...E}})),o(t=>({...t,[r]:{file:e,...S}})))}).catch(()=>{u.current[r]||o(n=>({...n,[r]:{file:e,...E}}))}).finally(()=>{c.current&&clearInterval(c.current[r])}):await P.upload(d,e).then(n=>{if(u.current[r])delete u.current[r],delete c.current[r];else{if(!n.body){o(a=>({...a,[r]:{file:e,...E,error:n.body,httpStatus:n.status}}));return}const t=n.body.saved[0];o(a=>({...a,[r]:{...t||{},file:e,...S}}))}}).catch(n=>{u.current[r]?(delete u.current[r],delete c.current[r]):o(t=>({...t,[r]:{file:e,...E,error:n}}))}).finally(()=>{c.current&&clearInterval(c.current[r])})};return{clear:v,upload:async(e,s,h)=>{const r={};e.forEach(t=>{const a=g.generateFileKey(t);r[a]={file:t,status:i.ArProgress.IN_PROGRESS,progress:p?1:Math.floor(Math.random()*10)}}),o(h?{...l,...r}:r);let n=[];for(const t of e)p?n.push(await R(t)):n.push(R(t));await Promise.allSettled(n).then(t=>s&&s(t))},results:l}};module.exports=m;
package/cjs/utils.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/tiff","image/bmp","image/x-icon"];function i(e){return"size"in e?`${e.name}_${e.size}_${e.type}_${e.lastModified}`:e.name+"-preexisting-"+Date.now()}function s(e){const t=e.trim().toLowerCase();try{return t.endsWith("kb")?parseFloat(t.slice(0,-2))*1024:t.endsWith("mb")?parseFloat(t.slice(0,-2))*1024*1024:t.endsWith("bytes")?parseFloat(t.slice(0,-5)):isNaN(parseFloat(t))?-1:parseFloat(t)}catch{return-1}}function a(e){return!!e&&r.indexOf(e)>-1}exports.convertToBytes=s;exports.generateFileKey=i;exports.isImage=a;
package/es/Uploader.js CHANGED
@@ -1,57 +1,58 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-Uploader .ar-Uploader__file-uploader-progress-bar{transition:max-height .3s,opacity .3s,padding .3s,margin-bottom .3s,background-color .3s;opacity:0;max-height:0}.ar-Uploader .ar-Uploader__file-uploader-progress-bar.show{opacity:1;max-height:4rem}.ar-Uploader .ar-Uploader__file-uploader-progress-bar:hover{background-color:var(--ar-bg-hover-6)}.ar-Uploader .ar-Button.loading .pre{animation:rotating .5s linear infinite}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{transition:border .3s ease-in-out;border:1px dashed lightgrey;border-radius:.5rem;padding:.5rem;background-color:var(--ar-bg-base)}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input:has(.ar-Avatar.FAILED){border-color:var(--ar-color-danger-soft)}.ar-Uploader .ar-Uploader__upload-prompt-text{color:var(--ar-color-obscure-4)}.ar-Uploader .ar-Uploader__upload-message{color:var(--ar-color-obscure-2)}")),document.head.appendChild(r)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
- import { jsxs as p, jsx as r, Fragment as M } from "react/jsx-runtime";
3
- import { memo as me, useRef as ue, useState as x, useMemo as fe, useEffect as L } from "react";
4
- import { v4 as O } from "uuid";
1
+ (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(".ar-Uploader .ar-Uploader__file-uploader-progress-bar{transition:max-height .3s,opacity .3s,padding .3s,margin-bottom .3s,background-color .3s;opacity:0;max-height:0}.ar-Uploader .ar-Uploader__file-uploader-progress-bar.show{opacity:1;max-height:4rem}.ar-Uploader .ar-Uploader__file-uploader-progress-bar:hover{background-color:var(--ar-bg-hover-6)}.ar-Uploader .ar-Button.loading .pre{animation:rotating .5s linear infinite}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{transition:border .3s ease-in-out}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input:has(.ar-Avatar.FAILED){border-color:var(--ar-color-danger-soft)}.ar-Uploader:not(.compact):not(.image-rect):not(.image-circle) .ar-Uploader__file-input{border:1px dashed lightgrey;border-radius:.5rem;padding:.5rem;background-color:var(--ar-bg-base)}.ar-Uploader .ar-Uploader__upload-prompt-text{color:var(--ar-color-obscure-4)}.ar-Uploader .ar-Uploader__upload-message{color:var(--ar-color-obscure-2)}")),document.head.appendChild(r)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
2
+ import { jsxs as f, jsx as a, Fragment as M } from "react/jsx-runtime";
3
+ import { memo as me, useRef as ue, useState as b, useMemo as fe, useEffect as R } from "react";
4
+ import { v4 as F } from "uuid";
5
5
  import { NativeTypes as pe } from "react-dnd-html5-backend";
6
- import { ArSizes as j, ArProgress as g, ArButtonVariants as ge, ArAlertType as R, ArPopoverSlots as Y } from "@armco/types";
7
- import he from "./useUpload.js";
8
- import { useNotification as ye } from "@armco/utils/hooks";
9
- import { convertToBytes as be } from "@armco/utils/helper";
10
- import { put as xe } from "@armco/utils/network";
11
- import ve from "@armco/shared-components/Droppable";
6
+ import { API_CONFIG as ge } from "@armco/configs/endpoints";
7
+ import { ArAlertType as O } from "@armco/utils";
8
+ import { useNotification as he } from "@armco/utils/hooks";
9
+ import { put as ye } from "@armco/utils/network";
10
+ import { ArSizes as j, ArProgress as p, ArButtonVariants as be, ArPopoverSlots as Y } from "@armco/shared-components/enums";
11
+ import xe from "@armco/shared-components/Droppable";
12
12
  import Q from "@armco/shared-components/Button";
13
- import Ce from "@armco/shared-components/Text";
14
- import Ae from "@armco/shared-components/ProgressIndicator";
15
- import Ee from "@armco/shared-components/Tooltip";
16
- import { API_CONFIG as Ie } from "@armco/configs/endpoints";
17
- import Z from "@armco/avatar";
13
+ import ve from "@armco/shared-components/Text";
14
+ import Ce from "@armco/shared-components/ProgressIndicator";
15
+ import Ae from "@armco/shared-components/Tooltip";
16
+ import Z from "@armco/shared-components/Avatar";
18
17
  import D from "@armco/icon";
18
+ import { convertToBytes as Ee } from "./utils.js";
19
+ import Ie from "./useUpload.js";
19
20
  const Fe = ({
20
- clear: n,
21
+ clear: i,
21
22
  demo: o,
22
23
  disabled: u,
23
24
  result: s
24
25
  }) => {
25
- const [S, v] = x(), [T, c] = x();
26
- L(() => {
26
+ const [L, x] = b(), [S, c] = b();
27
+ R(() => {
27
28
  c(!0);
28
29
  }, []);
29
- const C = s.type === "image", k = /* @__PURE__ */ r(
30
- Ae,
30
+ const v = s.type === "image", T = /* @__PURE__ */ a(
31
+ Ce,
31
32
  {
32
33
  label: s.file.name,
33
- preIcon: C ? "" : "im.ImAttachment",
34
+ preIcon: v ? "" : "im.ImAttachment",
34
35
  progress: s.progress,
35
36
  slot: Y.ANCHOR,
36
- rightEndContent: (S || s.status === g.FAILED) && /* @__PURE__ */ r(
37
+ rightEndContent: (L || s.status === p.FAILED) && /* @__PURE__ */ a(
37
38
  D,
38
39
  {
39
40
  icon: "ri.RiDeleteBin6Fill",
40
41
  attributes: {
41
42
  colors: {
42
- fillColor: s.status === g.FAILED ? "#ff4d4f" : "grey"
43
+ fillColor: s.status === p.FAILED ? "#ff4d4f" : "grey"
43
44
  },
44
45
  classes: u ? "" : "cursor-pointer"
45
46
  },
46
47
  events: {
47
48
  onClick: () => {
48
- u || (c(!1), setTimeout(n, 300));
49
+ u || (c(!1), setTimeout(i, 300));
49
50
  }
50
51
  }
51
52
  }
52
53
  ),
53
54
  status: s.status,
54
- thumbnailRenderer: () => C ? /* @__PURE__ */ r(
55
+ thumbnailRenderer: () => v ? /* @__PURE__ */ a(
55
56
  Z,
56
57
  {
57
58
  classes: "me-3",
@@ -62,34 +63,34 @@ const Fe = ({
62
63
  }
63
64
  ) : null
64
65
  }
65
- ), N = (h) => typeof h == "string" ? h : h.error || h.message || "Server Error";
66
- return /* @__PURE__ */ r(
66
+ ), k = (g) => typeof g == "string" ? g : g.error || g.message || "Server Error";
67
+ return /* @__PURE__ */ a(
67
68
  "div",
68
69
  {
69
- className: `ar-Uploader__file-uploader-progress-bar position-relative ${T ? " show p-1 border-radius l1 mb-1 cursor-pointer" : " px-1"} ${s.status}`,
70
- onMouseEnter: () => v(!0),
71
- onMouseLeave: () => v(!1),
72
- children: s.status === g.FAILED ? /* @__PURE__ */ p(Ee, { demo: o, children: [
73
- k,
74
- /* @__PURE__ */ r("span", { slot: Y.POPOVER, children: N(s.error) })
75
- ] }) : k
70
+ className: `ar-Uploader__file-uploader-progress-bar position-relative ${S ? " show p-1 border-radius l1 mb-1 cursor-pointer" : " px-1"} ${s.status}`,
71
+ onMouseEnter: () => x(!0),
72
+ onMouseLeave: () => x(!1),
73
+ children: s.status === p.FAILED ? /* @__PURE__ */ f(Ae, { demo: o, children: [
74
+ T,
75
+ /* @__PURE__ */ a("span", { slot: Y.POPOVER, children: k(s.error) })
76
+ ] }) : T
76
77
  }
77
78
  );
78
- }, Je = me(
79
- (n) => {
79
+ }, Ke = me(
80
+ (i) => {
80
81
  const {
81
82
  acceptedFileTypes: o,
82
83
  acceptedFileCount: u,
83
84
  afterUpload: s,
84
- allowMultiple: S,
85
- beforeUpload: v,
86
- demo: T,
85
+ allowMultiple: L,
86
+ beforeUpload: x,
87
+ demo: S,
87
88
  disabled: c,
88
- uploadEntryRenderer: C,
89
- errorMessage: k = "Failed to upload",
90
- endpoint: N,
91
- fileSizeLimit: h = "5mb",
92
- files: f,
89
+ uploadEntryRenderer: v,
90
+ errorMessage: T = "Failed to upload",
91
+ endpoint: k,
92
+ fileSizeLimit: g = "5mb",
93
+ files: N,
93
94
  handler: P,
94
95
  message: z,
95
96
  onFileSelected: B,
@@ -100,120 +101,116 @@ const Fe = ({
100
101
  uploadSequential: le,
101
102
  uploadButtonText: W = "Upload",
102
103
  uploadingButtonText: H = "Uploading..."
103
- } = n, d = ue(null), { notify: A } = ye(), [t, q] = x(), [E, V] = x(), [w, J] = x(), [$, _] = x(), ae = fe(
104
- () => E ? u !== void 0 ? f == null ? void 0 : f.slice(0, u) : f : f == null ? void 0 : f.slice(0, 1),
105
- [f]
106
- ), { clear: I, upload: re, results: U } = he(
107
- N || P || "",
104
+ } = i, d = ue(null), { notify: C } = he(), [e, q] = b(), [A, V] = b(), [w, J] = b(), [$, _] = b(), re = fe(
105
+ () => A ? u !== void 0 ? N?.slice(0, u) : N : N?.slice(0, 1),
106
+ [N]
107
+ ), { clear: E, upload: ae, results: U } = Ie(
108
+ k || P || "",
108
109
  le,
109
- ae
110
- ), y = l === "image-circle" || l === "image-rect";
111
- L(() => {
110
+ re
111
+ ), h = l === "image-circle" || l === "image-rect";
112
+ R(() => {
112
113
  q(U), (!U || Object.keys(U).length === 0) && d.current && (d.current.value = "");
113
- let e;
114
- t && Object.keys(t).length > 0 && Object.keys(t).every((a) => {
115
- const i = t[a];
116
- return e || (e = i.status === g.FAILED), i.status === g.FAILED;
117
- }), e && _(k);
118
- }, [U]), L(() => {
119
- V(S);
120
- }, [S]), L(() => {
114
+ let t;
115
+ e && Object.keys(e).length > 0 && Object.keys(e).every((r) => {
116
+ const n = e[r];
117
+ return t ||= n.status === p.FAILED, n.status === p.FAILED;
118
+ }), t && _(T);
119
+ }, [U]), R(() => {
120
+ V(L);
121
+ }, [L]), R(() => {
121
122
  J(o);
122
- }, [o]), L(() => {
123
- y && (V(!1), J([
123
+ }, [o]), R(() => {
124
+ h && (V(!1), J([
124
125
  "image/jpeg",
125
126
  "image/png",
126
127
  "image/gif",
127
128
  "image/svg+xml"
128
129
  ]));
129
- }, [y]);
130
- const K = (e) => {
131
- const a = be(h);
132
- let i;
130
+ }, [h]);
131
+ const K = (t) => {
132
+ const r = Ee(g);
133
+ let n;
133
134
  try {
134
- i = u !== void 0 && (typeof u == "number" ? u : parseInt(u));
135
+ n = u !== void 0 && (typeof u == "number" ? u : parseInt(u));
135
136
  } catch {
136
137
  console.warn(
137
138
  "Incorrect prop acceptedFileCount supplied, should be a numeric value"
138
139
  );
139
140
  }
140
- if (typeof i == "number" && e && e.length + Object.keys(t || {}).length > i)
141
- _("Exceeded allowed number of files."), A({
141
+ if (typeof n == "number" && t && t.length + Object.keys(e || {}).length > n)
142
+ _("Exceeded allowed number of files."), C({
142
143
  message: "You've selected more then allowed number of files",
143
- type: R.WARNING,
144
- uid: O()
144
+ type: O.WARNING,
145
+ uid: F()
145
146
  });
146
- else if (e.findIndex((m) => m.size > a) > -1) {
147
- const m = `${E ? "One or more files exceed " : "Selected file exceeds "}specified size limit of ${h}`;
148
- _(m), A({
147
+ else if (t.findIndex((m) => m.size > r) > -1) {
148
+ const m = `${A ? "One or more files exceed " : "Selected file exceeds "}specified size limit of ${g}`;
149
+ _(m), C({
149
150
  message: m,
150
- type: R.WARNING,
151
- uid: O()
151
+ type: O.WARNING,
152
+ uid: F()
152
153
  });
153
- } else e && e.length > 0 && (re(e, s, E), B && B(e));
154
- }, oe = (e) => {
155
- var i;
154
+ } else t && t.length > 0 && (ae(t, s, A), B && B(t));
155
+ }, oe = (t) => {
156
156
  _("");
157
- const a = Array.from(
158
- (i = e.target || e.dataTransfer) == null ? void 0 : i.files
157
+ const r = Array.from(
158
+ (t.target || t.dataTransfer)?.files
159
159
  );
160
- (!v || v(a, () => K(a))) && K(a);
161
- }, b = t && Object.keys(t).findIndex((e) => t[e].status === g.IN_PROGRESS) > -1, ne = !!(t && Object.keys(t).length > 0 && Object.keys(t).every((e) => {
162
- const a = t[e];
163
- return a.status === g.COMPLETED || a.status === g.FAILED;
164
- })), F = t && t[Object.keys(t)[0]], X = /* @__PURE__ */ p(
160
+ (!x || x(r, () => K(r))) && K(r);
161
+ }, y = e && Object.keys(e).findIndex((t) => e[t].status === p.IN_PROGRESS) > -1, ie = !!(e && Object.keys(e).length > 0 && Object.keys(e).every((t) => {
162
+ const r = e[t];
163
+ return r.status === p.COMPLETED || r.status === p.FAILED;
164
+ })), I = e && e[Object.keys(e)[0]], X = /* @__PURE__ */ f(
165
165
  "div",
166
166
  {
167
- className: `ar-Uploader__file-input flex-v-center${b ? " disabled" : ""}${l !== "compact" && !b && !c ? " cursor-pointer" : ""}${l === "large" ? " flex-h-center flex-column p-3" : " justify-content-between"}${l === "image-circle" ? " border-radius-50" : ""}`,
168
- onClick: () => {
169
- var e;
170
- return l !== "compact" && !b && !c && ((e = d.current) == null ? void 0 : e.click());
171
- },
167
+ className: `ar-Uploader__file-input flex-v-center${y ? " disabled" : ""}${l !== "compact" && !y && !c ? " cursor-pointer" : ""}${l === "large" ? " flex-h-center flex-column p-3" : " justify-content-between"}${l === "image-circle" ? " border-radius-50" : ""}`,
168
+ onClick: () => l !== "compact" && !y && !c && d.current?.click(),
172
169
  children: [
173
- y ? /* @__PURE__ */ r(
170
+ h ? /* @__PURE__ */ a(
174
171
  Z,
175
172
  {
176
- clearImage: I,
177
- demo: T,
173
+ clearImage: E,
174
+ demo: S,
178
175
  variant: l === "image-circle" ? "circle" : "rect",
179
- item: F,
180
- onChange: (e) => {
181
- if (t && F) {
182
- const a = Object.keys(t).find(
183
- (i) => i.startsWith(F.file.name)
176
+ item: I,
177
+ onChange: (t) => {
178
+ if (e && I) {
179
+ const r = Object.keys(e).find(
180
+ (n) => n.startsWith(I.file.name)
184
181
  );
185
- if (a) {
186
- const i = { ...t[a] };
187
- i.imageProps = e, t[a] = i, q({ ...t });
182
+ if (r) {
183
+ const n = { ...e[r] };
184
+ n.imageProps = t, e[r] = n, q({ ...e });
188
185
  }
189
186
  }
190
187
  },
191
- onCommit: (e) => {
192
- if (t && F) {
193
- const a = Object.keys(t).find(
194
- (i) => i.startsWith(F.file.name)
188
+ onCommit: (t) => {
189
+ if (e && I) {
190
+ const r = Object.keys(e).find(
191
+ (n) => n.startsWith(I.file.name)
195
192
  );
196
- if (a) {
197
- const i = t[a];
198
- let m = G || N;
193
+ if (r) {
194
+ const n = e[r];
195
+ let m = G || k;
199
196
  if (m) {
200
197
  const ce = process.env.NODE_ENV || "development";
201
- m = (m.startsWith("http") ? "" : Ie.STATIC_HOST[ce]) + m, xe(m, i).then((de) => {
202
- de.status === 200 ? A({
198
+ m = (m.startsWith("http") ? "" : ge.STATIC_HOST[ce]) + m, ye(m, n).then((de) => {
199
+ de.status === 200 ? C({
203
200
  message: "Image updaetd successfully!",
204
- type: R.SUCCESS,
205
- uid: O()
206
- }) : A({
201
+ type: O.SUCCESS,
202
+ uid: F()
203
+ }) : C({
207
204
  message: "Failed to update image!",
208
- type: R.ERROR,
209
- uid: O()
205
+ type: O.ERROR,
206
+ uid: F()
210
207
  });
211
208
  });
212
209
  } else
213
- A({
210
+ C({
214
211
  message: "Missing image update URL",
215
- type: R.WARNING,
216
- uid: O()
212
+ type: O.WARNING,
213
+ uid: F()
217
214
  });
218
215
  }
219
216
  }
@@ -222,44 +219,41 @@ const Fe = ({
222
219
  uploadButtonText: W,
223
220
  uploadingButtonText: H
224
221
  }
225
- ) : /* @__PURE__ */ p(M, { children: [
226
- /* @__PURE__ */ p("div", { className: "ar-Uploader__file-input__prompt d-flex flex-column", children: [
227
- /* @__PURE__ */ r(
222
+ ) : /* @__PURE__ */ f(M, { children: [
223
+ /* @__PURE__ */ f("div", { className: "ar-Uploader__file-input__prompt d-flex flex-column", children: [
224
+ /* @__PURE__ */ a(
228
225
  "div",
229
226
  {
230
227
  className: `d-inline-flex ${l === "large" ? " flex-center flex-column" : "flex-v-center"}`,
231
- children: l === "compact" ? /* @__PURE__ */ p(M, { children: [
232
- /* @__PURE__ */ r(
228
+ children: l === "compact" ? /* @__PURE__ */ f(M, { children: [
229
+ /* @__PURE__ */ a(
233
230
  Q,
234
231
  {
235
- classes: b ? "loading" : "",
236
- content: b ? H : W,
237
- preIcon: b ? "ri.RiLoader5Fill" : ne ? $ ? "fa.FaExclamation" : "fa.FaCheck" : "md.MdOutlineFileUpload",
238
- onClick: () => {
239
- var e;
240
- return (e = d.current) == null ? void 0 : e.click();
241
- },
232
+ classes: y ? "loading" : "",
233
+ content: y ? H : W,
234
+ preIcon: y ? "ri.RiLoader5Fill" : ie ? $ ? "fa.FaExclamation" : "fa.FaCheck" : "md.MdOutlineFileUpload",
235
+ onClick: () => d.current?.click(),
242
236
  theme: te,
243
- disabled: c || b
237
+ disabled: c || y
244
238
  }
245
239
  ),
246
- t && Object.keys(t).length > 0 && l === "compact" && /* @__PURE__ */ p(M, { children: [
247
- E ? /* @__PURE__ */ r("span", { className: "fw-bold flex-v-center ms-3", children: `(${Object.keys(t).length} file${Object.keys(t).length > 1 ? "s" : ""})` }) : /* @__PURE__ */ r(
248
- Ce,
240
+ e && Object.keys(e).length > 0 && l === "compact" && /* @__PURE__ */ f(M, { children: [
241
+ A ? /* @__PURE__ */ a("span", { className: "fw-bold flex-v-center ms-3", children: `(${Object.keys(e).length} file${Object.keys(e).length > 1 ? "s" : ""})` }) : /* @__PURE__ */ a(
242
+ ve,
249
243
  {
250
244
  classes: "fw-bold flex-v-center ms-3 text-decoration-underline",
251
245
  descriptor: {
252
246
  id: "temp-text-id",
253
247
  order: 0,
254
248
  name: "Text",
255
- text: t[Object.keys(t)[0]].file.name,
249
+ text: e[Object.keys(e)[0]].file.name,
256
250
  chunks: {}
257
251
  },
258
252
  overflowEllipsis: !0,
259
253
  overflowTooltip: !0
260
254
  }
261
255
  ),
262
- /* @__PURE__ */ r(
256
+ /* @__PURE__ */ a(
263
257
  D,
264
258
  {
265
259
  icon: "io5.IoClose",
@@ -271,14 +265,14 @@ const Fe = ({
271
265
  },
272
266
  events: {
273
267
  onClick: () => {
274
- c && (I(), d.current && (d.current.value = ""));
268
+ c && (E(), d.current && (d.current.value = ""));
275
269
  }
276
270
  }
277
271
  }
278
272
  )
279
273
  ] })
280
- ] }) : /* @__PURE__ */ p(M, { children: [
281
- /* @__PURE__ */ r(
274
+ ] }) : /* @__PURE__ */ f(M, { children: [
275
+ /* @__PURE__ */ a(
282
276
  D,
283
277
  {
284
278
  icon: "io5.IoFileTrayOutline",
@@ -291,7 +285,7 @@ const Fe = ({
291
285
  }
292
286
  }
293
287
  ),
294
- /* @__PURE__ */ r(
288
+ /* @__PURE__ */ a(
295
289
  "span",
296
290
  {
297
291
  className: `ar-Uploader__upload-prompt-text${l === "large" ? " h5 mb-0" : ""}`,
@@ -301,7 +295,7 @@ const Fe = ({
301
295
  ] })
302
296
  }
303
297
  ),
304
- z && /* @__PURE__ */ r(
298
+ z && /* @__PURE__ */ a(
305
299
  "small",
306
300
  {
307
301
  className: `ar-Uploader__upload-message text-decoration-underline ${l === "large" ? "fw-bold f3 mt-2 mb-2" : "mt-1"}`,
@@ -309,20 +303,20 @@ const Fe = ({
309
303
  }
310
304
  )
311
305
  ] }),
312
- /* @__PURE__ */ r("div", { className: "ar-Uploader__file-input__actions", children: l !== "compact" && t && Object.keys(t).length > 0 && /* @__PURE__ */ r(
306
+ /* @__PURE__ */ a("div", { className: "ar-Uploader__file-input__actions", children: l !== "compact" && e && Object.keys(e).length > 0 && /* @__PURE__ */ a(
313
307
  Q,
314
308
  {
315
309
  containerClasses: `text-end${l === "large" ? " mt-3" : ""}`,
316
310
  content: "Clear",
317
- variant: ge.DANGER,
311
+ variant: be.DANGER,
318
312
  size: l === "regular" ? j.XSMALL : j.SMALL,
319
- onClick: (e) => {
320
- e.stopPropagation(), I(), d.current && (d.current.value = "");
313
+ onClick: (t) => {
314
+ t.stopPropagation(), E(), d.current && (d.current.value = "");
321
315
  }
322
316
  }
323
317
  ) })
324
318
  ] }),
325
- /* @__PURE__ */ r(
319
+ /* @__PURE__ */ a(
326
320
  "input",
327
321
  {
328
322
  className: "ar-Uploader__input d-none",
@@ -332,51 +326,51 @@ const Fe = ({
332
326
  title: "file-uploader",
333
327
  accept: Array.isArray(w) ? w.join(",") : w,
334
328
  disabled: c,
335
- multiple: E
329
+ multiple: A
336
330
  }
337
331
  )
338
332
  ]
339
333
  }
340
- ), ie = $ && /* @__PURE__ */ r("span", { className: "error my-1 small", children: $ }), se = t && l !== "compact" && /* @__PURE__ */ r("div", { className: "ar-Uploader__file-upload-progress mt-2", children: Object.entries(t).map(
341
- ([e, a]) => C ? C(a, () => I(e)) : /* @__PURE__ */ r(
334
+ ), ne = $ && /* @__PURE__ */ a("span", { className: "error my-1 small", children: $ }), se = e && l !== "compact" && /* @__PURE__ */ a("div", { className: "ar-Uploader__file-upload-progress mt-2", children: Object.entries(e).map(
335
+ ([t, r]) => v ? v(r, () => E(t)) : /* @__PURE__ */ a(
342
336
  Fe,
343
337
  {
344
- clear: () => I(e),
345
- demo: !!T,
338
+ clear: () => E(t),
339
+ demo: !!S,
346
340
  disabled: !!c,
347
- result: a
341
+ result: r
348
342
  },
349
- e
343
+ t
350
344
  )
351
345
  ) });
352
- return /* @__PURE__ */ p(
346
+ return /* @__PURE__ */ f(
353
347
  "div",
354
348
  {
355
- className: `ar-Uploader d-flex flex-column${l ? " " + l : ""}${y ? " flex-center" : " w-100"}`,
356
- onDragOver: (e) => e.preventDefault(),
357
- onDragLeave: (e) => e.preventDefault(),
349
+ className: `ar-Uploader d-flex flex-column${l ? " " + l : ""}${h ? " flex-center" : " w-100"}`,
350
+ onDragOver: (t) => t.preventDefault(),
351
+ onDragLeave: (t) => t.preventDefault(),
358
352
  children: [
359
- l !== "compact" ? /* @__PURE__ */ r(
360
- ve,
353
+ l !== "compact" ? /* @__PURE__ */ a(
354
+ xe,
361
355
  {
362
- dropHandler: (e) => {
363
- d.current && !c && (d.current.files = e.dataTransfer.files, d.current.dispatchEvent(
356
+ dropHandler: (t) => {
357
+ d.current && !c && (d.current.files = t.dataTransfer.files, d.current.dispatchEvent(
364
358
  new Event("change", { bubbles: !0, cancelable: !0 })
365
359
  ));
366
360
  },
367
361
  acceptTypes: [pe.FILE],
368
- hideHoverEffect: y || c,
362
+ hideHoverEffect: h || c,
369
363
  children: X
370
364
  }
371
365
  ) : X,
372
- !y && ie,
373
- !y && se
366
+ !h && ne,
367
+ !h && se
374
368
  ]
375
369
  }
376
370
  );
377
371
  },
378
- (n, o) => n.acceptedFileTypes === o.acceptedFileTypes && n.acceptedFileCount === o.acceptedFileCount && n.allowMultiple === o.allowMultiple && n.disabled === o.disabled && n.errorMessage === o.errorMessage && n.endpoint === o.endpoint && n.fileSizeLimit === o.fileSizeLimit && JSON.stringify(n.files) === JSON.stringify(o.files) && n.message === o.message && n.avatarSize === o.avatarSize && n.variant === o.variant && n.theme === o.theme && n.uploadSequential === o.uploadSequential && n.uploadButtonText === o.uploadButtonText && n.uploadingButtonText === o.uploadingButtonText
372
+ (i, o) => i.acceptedFileTypes === o.acceptedFileTypes && i.acceptedFileCount === o.acceptedFileCount && i.allowMultiple === o.allowMultiple && i.disabled === o.disabled && i.errorMessage === o.errorMessage && i.endpoint === o.endpoint && i.fileSizeLimit === o.fileSizeLimit && JSON.stringify(i.files) === JSON.stringify(o.files) && i.message === o.message && i.avatarSize === o.avatarSize && i.variant === o.variant && i.theme === o.theme && i.uploadSequential === o.uploadSequential && i.uploadButtonText === o.uploadButtonText && i.uploadingButtonText === o.uploadingButtonText
379
373
  );
380
374
  export {
381
- Je as default
375
+ Ke as default
382
376
  };
package/es/index.js CHANGED
@@ -1,6 +1,10 @@
1
- import { default as a } from "./useUpload.js";
2
- import { default as r } from "./Uploader.js";
1
+ import { default as r } from "./useUpload.js";
2
+ import { default as a } from "./Uploader.js";
3
+ import { convertToBytes as l, generateFileKey as m, isImage as p } from "./utils.js";
3
4
  export {
4
- r as default,
5
- a as useUpload
5
+ l as convertToBytes,
6
+ a as default,
7
+ m as generateFileKey,
8
+ p as isImage,
9
+ r as useUpload
6
10
  };
package/es/useUpload.js CHANGED
@@ -1,28 +1,28 @@
1
1
  import { useState as I, useRef as S, useEffect as v } from "react";
2
- import { ArProgress as d } from "@armco/types";
3
- import { generateFileKey as m } from "@armco/utils/helper";
2
+ import { ArProgress as f } from "@armco/shared-components/enums";
4
3
  import { upload as b } from "@armco/utils/network";
4
+ import { generateFileKey as E } from "./utils.js";
5
5
  const R = {
6
- status: d.COMPLETED,
6
+ status: f.COMPLETED,
7
7
  progress: 100
8
- }, p = {
9
- status: d.FAILED,
8
+ }, h = {
9
+ status: f.FAILED,
10
10
  progress: 0
11
- }, C = (E, y, f) => {
11
+ }, C = (i, m, p) => {
12
12
  const [l, o] = I(), a = S({}), c = S({});
13
13
  v(() => {
14
- if (f) {
14
+ if (p) {
15
15
  const t = {};
16
- f == null || f.forEach((n) => {
17
- t[m(n)] = {
16
+ p?.forEach((n) => {
17
+ t[E(n)] = {
18
18
  ...n,
19
19
  progress: 100,
20
- status: d.COMPLETED,
20
+ status: f.COMPLETED,
21
21
  file: typeof n == "object" ? n : { name: n.name }
22
22
  };
23
23
  }), o(t);
24
24
  }
25
- }, [f]), v(() => {
25
+ }, [p]), v(() => {
26
26
  const t = c.current;
27
27
  return () => {
28
28
  Object.keys(t).forEach((n) => clearInterval(t[n]));
@@ -34,12 +34,12 @@ const R = {
34
34
  delete n[t], o(n), a.current[t] = !0, clearInterval(c.current[t]);
35
35
  } else
36
36
  o(void 0), l && Object.keys(l).forEach(
37
- (n) => l[n].status === d.IN_PROGRESS && (a.current[n] = !0)
37
+ (n) => l[n].status === f.IN_PROGRESS && (a.current[n] = !0)
38
38
  ), Object.keys(c.current).forEach(
39
39
  (n) => clearInterval(c.current[n])
40
40
  );
41
- }, i = async (t) => {
42
- const h = typeof E == "function" ? E : null, r = m(t);
41
+ }, y = async (t) => {
42
+ const d = typeof i == "function" ? i : null, r = E(t);
43
43
  return c.current[r] = setInterval(() => {
44
44
  o((s) => {
45
45
  const e = s && s[r];
@@ -54,10 +54,10 @@ const R = {
54
54
  }
55
55
  };
56
56
  });
57
- }, 500), h ? await h(t).then((s) => {
57
+ }, 500), d ? await d(t).then((s) => {
58
58
  a.current[r] || (s.ok || o((e) => ({
59
59
  ...e,
60
- [r]: { file: t, ...p }
60
+ [r]: { file: t, ...h }
61
61
  })), o((e) => ({
62
62
  ...e,
63
63
  [r]: { file: t, ...R }
@@ -65,11 +65,11 @@ const R = {
65
65
  }).catch(() => {
66
66
  a.current[r] || o((s) => ({
67
67
  ...s,
68
- [r]: { file: t, ...p }
68
+ [r]: { file: t, ...h }
69
69
  }));
70
70
  }).finally(() => {
71
71
  c.current && clearInterval(c.current[r]);
72
- }) : await b(E, t).then((s) => {
72
+ }) : await b(i, t).then((s) => {
73
73
  if (a.current[r])
74
74
  delete a.current[r], delete c.current[r];
75
75
  else {
@@ -78,7 +78,7 @@ const R = {
78
78
  ...u,
79
79
  [r]: {
80
80
  file: t,
81
- ...p,
81
+ ...h,
82
82
  error: s.body,
83
83
  httpStatus: s.status
84
84
  }
@@ -94,25 +94,25 @@ const R = {
94
94
  }).catch((s) => {
95
95
  a.current[r] ? (delete a.current[r], delete c.current[r]) : o((e) => ({
96
96
  ...e,
97
- [r]: { file: t, ...p, error: s }
97
+ [r]: { file: t, ...h, error: s }
98
98
  }));
99
99
  }).finally(() => {
100
100
  c.current && clearInterval(c.current[r]);
101
101
  });
102
102
  };
103
- return { clear: g, upload: async (t, n, h) => {
103
+ return { clear: g, upload: async (t, n, d) => {
104
104
  const r = {};
105
105
  t.forEach((e) => {
106
- const u = m(e);
106
+ const u = E(e);
107
107
  r[u] = {
108
108
  file: e,
109
- status: d.IN_PROGRESS,
110
- progress: y ? 1 : Math.floor(Math.random() * 10)
109
+ status: f.IN_PROGRESS,
110
+ progress: m ? 1 : Math.floor(Math.random() * 10)
111
111
  };
112
- }), o(h ? { ...l, ...r } : r);
112
+ }), o(d ? { ...l, ...r } : r);
113
113
  let s = [];
114
114
  for (const e of t)
115
- y ? s.push(await i(e)) : s.push(i(e));
115
+ m ? s.push(await y(e)) : s.push(y(e));
116
116
  await Promise.allSettled(s).then(
117
117
  (e) => n && n(e)
118
118
  );
package/es/utils.js ADDED
@@ -0,0 +1,29 @@
1
+ const r = [
2
+ "image/jpeg",
3
+ "image/png",
4
+ "image/gif",
5
+ "image/webp",
6
+ "image/svg+xml",
7
+ "image/tiff",
8
+ "image/bmp",
9
+ "image/x-icon"
10
+ ];
11
+ function i(e) {
12
+ return "size" in e ? `${e.name}_${e.size}_${e.type}_${e.lastModified}` : e.name + "-preexisting-" + Date.now();
13
+ }
14
+ function s(e) {
15
+ const n = e.trim().toLowerCase();
16
+ try {
17
+ return n.endsWith("kb") ? parseFloat(n.slice(0, -2)) * 1024 : n.endsWith("mb") ? parseFloat(n.slice(0, -2)) * 1024 * 1024 : n.endsWith("bytes") ? parseFloat(n.slice(0, -5)) : isNaN(parseFloat(n)) ? -1 : parseFloat(n);
18
+ } catch {
19
+ return -1;
20
+ }
21
+ }
22
+ function a(e) {
23
+ return !!e && r.indexOf(e) > -1;
24
+ }
25
+ export {
26
+ s as convertToBytes,
27
+ i as generateFileKey,
28
+ a as isImage
29
+ };
package/package.json CHANGED
@@ -1,24 +1,11 @@
1
1
  {
2
2
  "name": "@armco/uploader",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "main": "cjs/index.js",
6
6
  "module": "es/index.js",
7
7
  "types": "types/index.d.ts",
8
- "scripts": {
9
- "*": "rm -rf build && tsc && vite build",
10
- "format": "prettier --write .",
11
- "lint": "eslint .",
12
- "publish:sh": "./publish.sh",
13
- "publish:local": "./publish-local.sh"
14
- },
15
8
  "peerDependencies": {
16
- "@armco/types": "^0.0.17",
17
- "@armco/configs": "^0.0.10",
18
- "@armco/utils": "^0.0.28",
19
- "@armco/shared-components": "^0.0.56",
20
- "@armco/icon": "^0.0.9",
21
- "@armco/avatar": "^0.0.5",
22
9
  "react": "^18.2.0",
23
10
  "react-dnd-html5-backend": "^16.0.1",
24
11
  "react-dom": "^18.2.0",
@@ -40,7 +27,7 @@
40
27
  "prettier": "prettier-config-nick",
41
28
  "repository": {
42
29
  "type": "git",
43
- "url": "git+https://github.com/ReStruct-Corporate-Advantage/uploader.git"
30
+ "url": "git+https://gitea.armco.dev/ReStruct-Corporate-Advantage/uploader.git"
44
31
  },
45
32
  "keywords": [
46
33
  "components",
@@ -50,7 +37,18 @@
50
37
  ],
51
38
  "license": "ISC",
52
39
  "bugs": {
53
- "url": "https://github.com/ReStruct-Corporate-Advantage/uploader/issues"
40
+ "url": "https://gitea.armco.dev/ReStruct-Corporate-Advantage/uploader/issues"
41
+ },
42
+ "homepage": "https://gitea.armco.dev/ReStruct-Corporate-Advantage/uploader#readme",
43
+ "dependencies": {
44
+ "@armco/configs": "^0.0.15",
45
+ "@armco/icon": "^0.0.13",
46
+ "@armco/shared-components": "^0.0.59",
47
+ "@armco/utils": "^0.0.31",
48
+ "@types/uuid": "^10.0.0"
54
49
  },
55
- "homepage": "https://github.com/ReStruct-Corporate-Advantage/uploader#readme"
50
+ "private": false,
51
+ "files": [
52
+ "*"
53
+ ]
56
54
  }
@@ -1,3 +1,4 @@
1
- import { UploaderProps } from '@armco/types';
2
- declare const Uploader: import('react').MemoExoticComponent<(props: UploaderProps) => JSX.Element>;
1
+ import { ReactNode } from 'react';
2
+ import { UploaderProps } from './types';
3
+ declare const Uploader: import('react').MemoExoticComponent<(props: UploaderProps) => ReactNode>;
3
4
  export default Uploader;
package/types/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { default as useUpload } from './useUpload';
2
2
  export { default } from './Uploader';
3
+ export * from './utils';
4
+ export * from './types';
@@ -0,0 +1,44 @@
1
+ import { BaseProps, FunctionType } from '@armco/types';
2
+ import { ImageProps } from '@armco/shared-components/Image';
3
+ import { ArProgress, ArSizes } from '@armco/shared-components/enums';
4
+ export type UploadHandler = (file: File) => Promise<UploadResults>;
5
+ export type UploadResults = {
6
+ [key: string]: UploadResult;
7
+ };
8
+ export interface UploadResult {
9
+ file: File | {
10
+ name: string;
11
+ };
12
+ imageProps?: Partial<ImageProps>;
13
+ status: ArProgress;
14
+ progress: number;
15
+ type?: string;
16
+ url?: string;
17
+ error?: string;
18
+ httpStatus?: number;
19
+ }
20
+ export interface UploaderProps extends BaseProps {
21
+ acceptedFileTypes?: string | Array<string>;
22
+ acceptedFileCount?: number;
23
+ afterUpload?: FunctionType;
24
+ allowMultiple?: boolean;
25
+ avatarSize?: ArSizes;
26
+ beforeUpload?: FunctionType;
27
+ disabled?: boolean;
28
+ endpoint?: string;
29
+ errorMessage?: string;
30
+ files?: Array<File | {
31
+ name: string;
32
+ url?: string;
33
+ }>;
34
+ fileSizeLimit?: string;
35
+ handler?: UploadHandler;
36
+ message?: string;
37
+ updateEndpoint?: string;
38
+ uploadEntryRenderer?: FunctionType;
39
+ uploadSequential?: boolean;
40
+ onFileSelected: FunctionType;
41
+ variant: "compact" | "regular" | "large" | "image-circle" | "image-rect";
42
+ uploadButtonText?: string;
43
+ uploadingButtonText?: string;
44
+ }
@@ -1,4 +1,5 @@
1
- import { FunctionType, UploadHandler, UploadResults } from '@armco/types';
1
+ import { FunctionType } from '@armco/types';
2
+ import { UploadHandler, UploadResults } from './types';
2
3
  declare const useUpload: (endpointOrHandler: string | UploadHandler, isSequential?: boolean, files?: Array<File | {
3
4
  name: string;
4
5
  url?: string;
@@ -0,0 +1,5 @@
1
+ export declare function generateFileKey(file: File | {
2
+ name: string;
3
+ }): string;
4
+ export declare function convertToBytes(input: string): number;
5
+ export declare function isImage(type: string): boolean;