@armco/uploader 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/Uploader.js +2 -2
- package/cjs/index.js +1 -1
- package/cjs/useUpload.js +1 -1
- package/cjs/utils.js +1 -0
- package/es/Uploader.js +161 -167
- package/es/index.js +8 -4
- package/es/useUpload.js +26 -26
- package/es/utils.js +29 -0
- package/package.json +15 -17
- package/types/Uploader.d.ts +3 -2
- package/types/index.d.ts +2 -0
- package/types/types.d.ts +44 -0
- package/types/useUpload.d.ts +2 -1
- package/types/utils.d.ts +5 -0
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
|
|
2
|
-
"use strict";const
|
|
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
|
|
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"),
|
|
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
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { memo as me, useRef as ue, useState as
|
|
4
|
-
import { v4 as
|
|
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 {
|
|
7
|
-
import
|
|
8
|
-
import { useNotification as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
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
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
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:
|
|
21
|
+
clear: i,
|
|
21
22
|
demo: o,
|
|
22
23
|
disabled: u,
|
|
23
24
|
result: s
|
|
24
25
|
}) => {
|
|
25
|
-
const [
|
|
26
|
-
|
|
26
|
+
const [L, x] = b(), [S, c] = b();
|
|
27
|
+
R(() => {
|
|
27
28
|
c(!0);
|
|
28
29
|
}, []);
|
|
29
|
-
const
|
|
30
|
-
|
|
30
|
+
const v = s.type === "image", T = /* @__PURE__ */ a(
|
|
31
|
+
Ce,
|
|
31
32
|
{
|
|
32
33
|
label: s.file.name,
|
|
33
|
-
preIcon:
|
|
34
|
+
preIcon: v ? "" : "im.ImAttachment",
|
|
34
35
|
progress: s.progress,
|
|
35
36
|
slot: Y.ANCHOR,
|
|
36
|
-
rightEndContent: (
|
|
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 ===
|
|
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(
|
|
49
|
+
u || (c(!1), setTimeout(i, 300));
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
),
|
|
53
54
|
status: s.status,
|
|
54
|
-
thumbnailRenderer: () =>
|
|
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
|
-
),
|
|
66
|
-
return /* @__PURE__ */
|
|
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 ${
|
|
70
|
-
onMouseEnter: () =>
|
|
71
|
-
onMouseLeave: () =>
|
|
72
|
-
children: s.status ===
|
|
73
|
-
|
|
74
|
-
/* @__PURE__ */
|
|
75
|
-
] }) :
|
|
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
|
-
},
|
|
79
|
-
(
|
|
79
|
+
}, Ke = me(
|
|
80
|
+
(i) => {
|
|
80
81
|
const {
|
|
81
82
|
acceptedFileTypes: o,
|
|
82
83
|
acceptedFileCount: u,
|
|
83
84
|
afterUpload: s,
|
|
84
|
-
allowMultiple:
|
|
85
|
-
beforeUpload:
|
|
86
|
-
demo:
|
|
85
|
+
allowMultiple: L,
|
|
86
|
+
beforeUpload: x,
|
|
87
|
+
demo: S,
|
|
87
88
|
disabled: c,
|
|
88
|
-
uploadEntryRenderer:
|
|
89
|
-
errorMessage:
|
|
90
|
-
endpoint:
|
|
91
|
-
fileSizeLimit:
|
|
92
|
-
files:
|
|
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
|
-
} =
|
|
104
|
-
() =>
|
|
105
|
-
[
|
|
106
|
-
), { clear:
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
),
|
|
111
|
-
|
|
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
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
return
|
|
117
|
-
}),
|
|
118
|
-
}, [U]),
|
|
119
|
-
V(
|
|
120
|
-
}, [
|
|
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]),
|
|
123
|
-
|
|
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
|
-
}, [
|
|
130
|
-
const K = (
|
|
131
|
-
const
|
|
132
|
-
let
|
|
130
|
+
}, [h]);
|
|
131
|
+
const K = (t) => {
|
|
132
|
+
const r = Ee(g);
|
|
133
|
+
let n;
|
|
133
134
|
try {
|
|
134
|
-
|
|
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
|
|
141
|
-
_("Exceeded allowed number of files."),
|
|
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:
|
|
144
|
-
uid:
|
|
144
|
+
type: O.WARNING,
|
|
145
|
+
uid: F()
|
|
145
146
|
});
|
|
146
|
-
else if (
|
|
147
|
-
const m = `${
|
|
148
|
-
_(m),
|
|
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:
|
|
151
|
-
uid:
|
|
151
|
+
type: O.WARNING,
|
|
152
|
+
uid: F()
|
|
152
153
|
});
|
|
153
|
-
} else
|
|
154
|
-
}, oe = (
|
|
155
|
-
var i;
|
|
154
|
+
} else t && t.length > 0 && (ae(t, s, A), B && B(t));
|
|
155
|
+
}, oe = (t) => {
|
|
156
156
|
_("");
|
|
157
|
-
const
|
|
158
|
-
(
|
|
157
|
+
const r = Array.from(
|
|
158
|
+
(t.target || t.dataTransfer)?.files
|
|
159
159
|
);
|
|
160
|
-
(!
|
|
161
|
-
},
|
|
162
|
-
const
|
|
163
|
-
return
|
|
164
|
-
})),
|
|
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${
|
|
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
|
-
|
|
170
|
+
h ? /* @__PURE__ */ a(
|
|
174
171
|
Z,
|
|
175
172
|
{
|
|
176
|
-
clearImage:
|
|
177
|
-
demo:
|
|
173
|
+
clearImage: E,
|
|
174
|
+
demo: S,
|
|
178
175
|
variant: l === "image-circle" ? "circle" : "rect",
|
|
179
|
-
item:
|
|
180
|
-
onChange: (
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
(
|
|
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 (
|
|
186
|
-
const
|
|
187
|
-
|
|
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: (
|
|
192
|
-
if (
|
|
193
|
-
const
|
|
194
|
-
(
|
|
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 (
|
|
197
|
-
const
|
|
198
|
-
let m = G ||
|
|
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") ? "" :
|
|
202
|
-
de.status === 200 ?
|
|
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:
|
|
205
|
-
uid:
|
|
206
|
-
}) :
|
|
201
|
+
type: O.SUCCESS,
|
|
202
|
+
uid: F()
|
|
203
|
+
}) : C({
|
|
207
204
|
message: "Failed to update image!",
|
|
208
|
-
type:
|
|
209
|
-
uid:
|
|
205
|
+
type: O.ERROR,
|
|
206
|
+
uid: F()
|
|
210
207
|
});
|
|
211
208
|
});
|
|
212
209
|
} else
|
|
213
|
-
|
|
210
|
+
C({
|
|
214
211
|
message: "Missing image update URL",
|
|
215
|
-
type:
|
|
216
|
-
uid:
|
|
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__ */
|
|
226
|
-
/* @__PURE__ */
|
|
227
|
-
/* @__PURE__ */
|
|
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__ */
|
|
232
|
-
/* @__PURE__ */
|
|
228
|
+
children: l === "compact" ? /* @__PURE__ */ f(M, { children: [
|
|
229
|
+
/* @__PURE__ */ a(
|
|
233
230
|
Q,
|
|
234
231
|
{
|
|
235
|
-
classes:
|
|
236
|
-
content:
|
|
237
|
-
preIcon:
|
|
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 ||
|
|
237
|
+
disabled: c || y
|
|
244
238
|
}
|
|
245
239
|
),
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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:
|
|
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__ */
|
|
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 && (
|
|
268
|
+
c && (E(), d.current && (d.current.value = ""));
|
|
275
269
|
}
|
|
276
270
|
}
|
|
277
271
|
}
|
|
278
272
|
)
|
|
279
273
|
] })
|
|
280
|
-
] }) : /* @__PURE__ */
|
|
281
|
-
/* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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:
|
|
311
|
+
variant: be.DANGER,
|
|
318
312
|
size: l === "regular" ? j.XSMALL : j.SMALL,
|
|
319
|
-
onClick: (
|
|
320
|
-
|
|
313
|
+
onClick: (t) => {
|
|
314
|
+
t.stopPropagation(), E(), d.current && (d.current.value = "");
|
|
321
315
|
}
|
|
322
316
|
}
|
|
323
317
|
) })
|
|
324
318
|
] }),
|
|
325
|
-
/* @__PURE__ */
|
|
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:
|
|
329
|
+
multiple: A
|
|
336
330
|
}
|
|
337
331
|
)
|
|
338
332
|
]
|
|
339
333
|
}
|
|
340
|
-
),
|
|
341
|
-
([
|
|
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: () =>
|
|
345
|
-
demo: !!
|
|
338
|
+
clear: () => E(t),
|
|
339
|
+
demo: !!S,
|
|
346
340
|
disabled: !!c,
|
|
347
|
-
result:
|
|
341
|
+
result: r
|
|
348
342
|
},
|
|
349
|
-
|
|
343
|
+
t
|
|
350
344
|
)
|
|
351
345
|
) });
|
|
352
|
-
return /* @__PURE__ */
|
|
346
|
+
return /* @__PURE__ */ f(
|
|
353
347
|
"div",
|
|
354
348
|
{
|
|
355
|
-
className: `ar-Uploader d-flex flex-column${l ? " " + l : ""}${
|
|
356
|
-
onDragOver: (
|
|
357
|
-
onDragLeave: (
|
|
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__ */
|
|
360
|
-
|
|
353
|
+
l !== "compact" ? /* @__PURE__ */ a(
|
|
354
|
+
xe,
|
|
361
355
|
{
|
|
362
|
-
dropHandler: (
|
|
363
|
-
d.current && !c && (d.current.files =
|
|
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:
|
|
362
|
+
hideHoverEffect: h || c,
|
|
369
363
|
children: X
|
|
370
364
|
}
|
|
371
365
|
) : X,
|
|
372
|
-
!
|
|
373
|
-
!
|
|
366
|
+
!h && ne,
|
|
367
|
+
!h && se
|
|
374
368
|
]
|
|
375
369
|
}
|
|
376
370
|
);
|
|
377
371
|
},
|
|
378
|
-
(
|
|
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
|
-
|
|
375
|
+
Ke as default
|
|
382
376
|
};
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { default as
|
|
2
|
-
import { default as
|
|
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
|
-
|
|
5
|
-
a as
|
|
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
|
|
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:
|
|
6
|
+
status: f.COMPLETED,
|
|
7
7
|
progress: 100
|
|
8
|
-
},
|
|
9
|
-
status:
|
|
8
|
+
}, h = {
|
|
9
|
+
status: f.FAILED,
|
|
10
10
|
progress: 0
|
|
11
|
-
}, C = (
|
|
11
|
+
}, C = (i, m, p) => {
|
|
12
12
|
const [l, o] = I(), a = S({}), c = S({});
|
|
13
13
|
v(() => {
|
|
14
|
-
if (
|
|
14
|
+
if (p) {
|
|
15
15
|
const t = {};
|
|
16
|
-
|
|
17
|
-
t[
|
|
16
|
+
p?.forEach((n) => {
|
|
17
|
+
t[E(n)] = {
|
|
18
18
|
...n,
|
|
19
19
|
progress: 100,
|
|
20
|
-
status:
|
|
20
|
+
status: f.COMPLETED,
|
|
21
21
|
file: typeof n == "object" ? n : { name: n.name }
|
|
22
22
|
};
|
|
23
23
|
}), o(t);
|
|
24
24
|
}
|
|
25
|
-
}, [
|
|
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 ===
|
|
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
|
-
},
|
|
42
|
-
const
|
|
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),
|
|
57
|
+
}, 500), d ? await d(t).then((s) => {
|
|
58
58
|
a.current[r] || (s.ok || o((e) => ({
|
|
59
59
|
...e,
|
|
60
|
-
[r]: { file: t, ...
|
|
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, ...
|
|
68
|
+
[r]: { file: t, ...h }
|
|
69
69
|
}));
|
|
70
70
|
}).finally(() => {
|
|
71
71
|
c.current && clearInterval(c.current[r]);
|
|
72
|
-
}) : await b(
|
|
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
|
-
...
|
|
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, ...
|
|
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,
|
|
103
|
+
return { clear: g, upload: async (t, n, d) => {
|
|
104
104
|
const r = {};
|
|
105
105
|
t.forEach((e) => {
|
|
106
|
-
const u =
|
|
106
|
+
const u = E(e);
|
|
107
107
|
r[u] = {
|
|
108
108
|
file: e,
|
|
109
|
-
status:
|
|
110
|
-
progress:
|
|
109
|
+
status: f.IN_PROGRESS,
|
|
110
|
+
progress: m ? 1 : Math.floor(Math.random() * 10)
|
|
111
111
|
};
|
|
112
|
-
}), o(
|
|
112
|
+
}), o(d ? { ...l, ...r } : r);
|
|
113
113
|
let s = [];
|
|
114
114
|
for (const e of t)
|
|
115
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.7",
|
|
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.18",
|
|
17
|
-
"@armco/configs": "^0.0.11",
|
|
18
|
-
"@armco/utils": "^0.0.29",
|
|
19
|
-
"@armco/shared-components": "^0.0.57",
|
|
20
|
-
"@armco/icon": "^0.0.10",
|
|
21
|
-
"@armco/avatar": "^0.0.6",
|
|
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://
|
|
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://
|
|
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.61",
|
|
47
|
+
"@armco/utils": "^0.0.31",
|
|
48
|
+
"@types/uuid": "^10.0.0"
|
|
54
49
|
},
|
|
55
|
-
"
|
|
50
|
+
"private": false,
|
|
51
|
+
"files": [
|
|
52
|
+
"*"
|
|
53
|
+
]
|
|
56
54
|
}
|
package/types/Uploader.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
package/types/types.d.ts
ADDED
|
@@ -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
|
+
}
|
package/types/useUpload.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FunctionType
|
|
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;
|