@yunuenm23/react-file-uploader 0.1.0 → 0.1.2
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/README.md +12 -0
- package/dist/fileuploader.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +332 -249
- package/dist/src/index.d.ts +2 -2
- package/dist/src/types.d.ts +14 -0
- package/dist/src/useFileUploader.d.ts +1 -1
- package/dist/src/utils.d.ts +8 -1
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Reusable React file uploader component without Ant Design or Next.js dependencies.
|
|
4
4
|
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
- Live docs and playground: https://moncadayunuen.github.io/react_fileuploader/
|
|
8
|
+
- GitHub repository: https://github.com/moncadayunuen/react_fileuploader
|
|
9
|
+
- npm package: https://www.npmjs.com/package/@yunuenm23/react-file-uploader
|
|
10
|
+
|
|
5
11
|
## Install locally
|
|
6
12
|
|
|
7
13
|
```bash
|
|
@@ -17,6 +23,8 @@ npm run dev
|
|
|
17
23
|
|
|
18
24
|
Open `http://127.0.0.1:5173/`.
|
|
19
25
|
|
|
26
|
+
Public docs: https://moncadayunuen.github.io/react_fileuploader/
|
|
27
|
+
|
|
20
28
|
## Publish package
|
|
21
29
|
|
|
22
30
|
```bash
|
|
@@ -51,6 +59,7 @@ export function Example() {
|
|
|
51
59
|
acceptFiles={["image/*", "video/*", "audio/*", "application/pdf"]}
|
|
52
60
|
maxFiles={3}
|
|
53
61
|
maxSizeFile={2}
|
|
62
|
+
imageCompression={{ enabled: true, mode: "lossless" }}
|
|
54
63
|
multipleFiles
|
|
55
64
|
theme={{
|
|
56
65
|
accent: "#7c3aed",
|
|
@@ -70,6 +79,7 @@ export function Example() {
|
|
|
70
79
|
|
|
71
80
|
- `acceptFiles`: MIME types or extensions, for example `["image/*", "video/*", "audio/*", ".pdf"]`.
|
|
72
81
|
- `maxSizeFile`: max size in MB.
|
|
82
|
+
- `imageCompression`: optimizes supported images before validation and selection.
|
|
73
83
|
- `multipleFiles`: enables multi-file selection.
|
|
74
84
|
- `maxFiles`: approved file limit.
|
|
75
85
|
- `validateDimensions`: validates image width and height.
|
|
@@ -82,3 +92,5 @@ export function Example() {
|
|
|
82
92
|
Images, videos, and audio files render compact clickable thumbnails that open a larger preview. Document-like files render as downloadable items. The package also exports `useFileUploader` if you want to build a fully custom UI with the same validation logic.
|
|
83
93
|
|
|
84
94
|
You can theme the component with the `theme` prop or by overriding CSS variables such as `--file-uploader-accent`, `--file-uploader-surface`, and `--file-uploader-border`.
|
|
95
|
+
|
|
96
|
+
`imageCompression={{ enabled: true, mode: "lossless" }}` optimizes SVG and PNG only when the optimized file is smaller. JPEG and WebP are kept unchanged in lossless mode. Use `mode: "balanced"` with a `quality` value only when you accept browser re-encoding.
|
package/dist/fileuploader.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ReactFileUploader as default, ReactFileUploader, FileUploader } from './src';
|
|
2
|
-
export type { FileUploaderHandle, FileUploaderItem, FileUploaderLabels, FileUploaderProps, } from './src';
|
|
2
|
+
export type { FileUploaderHandle, FileUploaderItem, FileUploaderLabels, FileUploaderProps, ImageCompressionMode, ImageCompressionOptions, } from './src';
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("react/jsx-runtime"),n=require("react"),z=["png","webp","jpeg","jpg","svg"],Z=["mp3","wav","ogg","mpeg","aac","flac"],G=["mp4","webm","ogg","mov","quicktime"],ee={audio:"MP3, WAV, OGG, AAC, FLAC",image:"PNG, JPG, JPEG, WEBP, SVG",video:"MP4, WEBM, OGG, MOV"},O=(e,s=" ")=>{const l=["Bytes","KB","MB","GB","TB"];if(e===0)return"n/a";const r=Math.floor(Math.log(e)/Math.log(1024));return`${r===0?e:(e/1024**r).toFixed(1)}${s}${l[r]}`},D=e=>{var r,o;const s=(r=e.name.split(".").pop())==null?void 0:r.toLowerCase();return((o=e.type.split("/")[1])==null?void 0:o.toLowerCase())||s||""},H=e=>e.map(s=>{const[l,r]=s.split("/");return r?r==="*"?ee[l]??`Cualquier ${l}`:r.toUpperCase():s.replace(".","").toUpperCase()}),N=e=>{const s=D(e);return e.type.startsWith("image/")||z.includes(s)},R=e=>{const s=D(e);return e.type.startsWith("audio/")||Z.includes(s)},T=e=>{const s=D(e);return e.type.startsWith("video/")||G.includes(s)},B=e=>N(e)||R(e)||T(e),W=e=>!B(e),q=(e,s)=>{if(s.length===0)return!0;const l=D(e);return s.some(r=>{const o=r.trim().toLowerCase();return o.startsWith(".")?o.slice(1)===l:o.endsWith("/*")?e.type.startsWith(o.replace("*","")):e.type.toLowerCase()===o||l===o})},ae=(e,s)=>new Promise(l=>{const r=URL.createObjectURL(e),o=new window.Image;o.onload=()=>{URL.revokeObjectURL(r),l(o.width<=s.width&&o.height<=s.height)},o.onerror=()=>{URL.revokeObjectURL(r),l(!1)},o.src=r}),P=async(e,s)=>{const l=[],r=s.maxSizeFile>0?s.maxSizeFile*1024*1024:0;r>0&&e.size>r&&l.push("file-size"),q(e,s.acceptFiles)||l.push("file-type"),s.validateDimensions&&N(e)&&(await ae(e,s.dimensions)||l.push("image-dimensions"));const o=l.length===0;return{id:`${e.name}-${e.size}-${e.lastModified}-${crypto.randomUUID()}`,file:e,status:o?"approved":"rejected",approve:o,reasons:l,previewUrl:B(e)?URL.createObjectURL(e):void 0}},S=e=>{e.forEach(s=>{s.previewUrl&&URL.revokeObjectURL(s.previewUrl)})},se=[],re={width:0,height:0},le=[],ie=e=>"dataTransfer"in e?Array.from(e.dataTransfer.files):Array.from(e.target.files??[]),J=({acceptFiles:e=se,dimensions:s=re,maxFiles:l=1,maxSizeFile:r=0,multipleFiles:o=!1,updateFiles:b=le,validateDimensions:g=!1,onFilesChange:m,onFilesSelected:v})=>{const x=n.useRef(null),U=n.useRef([]),[h,k]=n.useState([]),[y,L]=n.useState(!1),w=n.useMemo(()=>h.filter(d=>d.approve),[h]),C=n.useMemo(()=>H(e),[e]),u=o?w.length<l:h.length===0,j=n.useCallback(()=>{x.current&&(x.current.value="")},[]),c=n.useCallback(d=>{const f=d.filter(_=>_.approve).map(_=>_.file);if(m==null||m(d),o){v==null||v(f);return}f[0]&&(v==null||v(f[0]))},[o,m,v]),p=n.useCallback(d=>{k(f=>{const _=d(f),M=f.filter(E=>!_.some(Y=>Y.id===E.id));return S(M),U.current=_,_})},[]),t=n.useCallback(async d=>{d.preventDefault(),L(!1);const f=ie(d),_=await Promise.all(f.map(E=>P(E,{acceptFiles:e,dimensions:s,maxSizeFile:r,validateDimensions:g}))),M=o?[...h,..._.filter(E=>E.approve).slice(0,Math.max(l-w.length,0))]:_.slice(0,1);p(()=>M),c(M),j()},[e,w.length,j,s,c,h,l,r,o,p,g]),i=n.useCallback(d=>{const f=h.filter(_=>_.id!==d.id);p(()=>f),c(f),j()},[j,c,h,p]),A=n.useCallback(()=>{p(()=>[]),j(),m==null||m([])},[j,m,p]),I=n.useCallback(()=>{var d;(d=x.current)==null||d.click()},[]),K=n.useCallback(d=>{d.preventDefault(),L(!0)},[]),Q=n.useCallback(d=>{d.preventDefault(),L(!1)},[]),X=n.useCallback(d=>{if(u){t(d);return}d.preventDefault(),L(!1)},[u,t]);return n.useEffect(()=>{if(b.length===0)return;let d=!1;return Promise.all(b.map(f=>P(f,{acceptFiles:e,dimensions:s,maxSizeFile:r,validateDimensions:g}))).then(f=>{d||p(()=>f)}),()=>{d=!0}},[e,s,r,p,b,g]),n.useEffect(()=>{U.current=h},[h]),n.useEffect(()=>()=>{S(U.current)},[]),{acceptedFormats:C,approvedItems:w,canAddFiles:u,clear:A,handleFiles:t,inputRef:x,isDragging:y,items:h,onDragLeave:Q,onDragOver:K,onDrop:X,open:I,removeFile:i}},oe=[],te={width:0,height:0},ce=[],ne={idleTitle:a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"Arrastra y suelta"})," tus archivos aqui"]}),idleHint:"Selecciona archivos desde tu equipo.",browseFile:"Buscar archivo",browseFiles:"Buscar archivos",limitReached:"Limite de archivos alcanzado",maxSize:e=>`Limite de ${e}MB por archivo.`,allowedFormats:e=>a.jsxs(a.Fragment,{children:["Archivos permitidos: ",a.jsx("span",{className:"file-uploader__format",children:e.join(", ")})]}),imageDimensions:(e,s)=>`Dimensiones de imagen: ${e}x${s}`,selectedCount:(e,s)=>`${e} / ${s} ${e===1?"archivo seleccionado":"archivos seleccionados"}`,removeFile:"Eliminar archivo",downloadFile:"Descargar archivo",previewFile:"Vista previa del archivo",closePreview:"Cerrar vista previa"},de=e=>{if(!e)return;const s={"--file-uploader-accent":e.accent,"--file-uploader-accent-soft":e.accentSoft,"--file-uploader-border":e.border,"--file-uploader-danger":e.danger,"--file-uploader-ink":e.ink,"--file-uploader-muted":e.muted,"--file-uploader-success":e.success,"--file-uploader-surface":e.surface,"--file-uploader-item-surface":e.itemSurface,"--file-uploader-modal-backdrop":e.modalBackdrop,"--file-uploader-modal-surface":e.modalSurface};return Object.keys(s).forEach(l=>{const r=l;s[r]===void 0&&delete s[r]}),s},ue=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 640 512",children:a.jsx("path",{d:"M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9C96.1 197.4 96 194.7 96 192c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128H144Zm79-217c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l39-39V392c0 13.3 10.7 24 24 24s24-10.7 24-24V257.9l39 39c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0l-80 80Z"})}),pe=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M0 64C0 28.7 28.7 0 64 0h160v128c0 17.7 14.3 32 32 32h128v288c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64Zm384 64H256V0l128 128Z"})}),$=({approved:e})=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:e?a.jsx("path",{d:"M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512Zm113-303L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9Z"}):a.jsx("path",{d:"M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512ZM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9Z"})}),fe=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:a.jsx("path",{d:"M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32v242.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7V32ZM64 352c-35.3 0-64 28.7-64 64v32c0 35.3 28.7 64 64 64h384c35.3 0 64-28.7 64-64v-32c0-35.3-28.7-64-64-64H346.5l-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352H64Z"})}),me=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80v352c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9l288-176c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39Z"})}),V=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:a.jsx("path",{d:"M499.1 6.3c8.1 6 12.9 15.6 12.9 25.7v320c0 53-43 96-96 96s-96-43-96-96s43-96 96-96c11.2 0 22 1.9 32 5.5V111.9L192 160v224c0 53-43 96-96 96S0 437 0 384s43-96 96-96c11.2 0 22 1.9 32 5.5V128c0-15.4 10.9-28.6 26.1-31.5l320-60c9.9-1.9 20.1 .4 28.2 6.4Z"})}),ve=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6Z"})}),he=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 448 512",children:a.jsx("path",{d:"m135.2 17.7L128 32H32C14.3 32 0 46.3 0 64s14.3 32 32 32h384c17.7 0 32-14.3 32-32s-14.3-32-32-32h-96l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7ZM416 128H32l21.2 339c1.6 25.3 22.6 45 47.9 45h245.8c25.3 0 46.3-19.7 47.9-45L416 128Z"})}),_e=e=>{const s=URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download=e.name||"archivo_descarga",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(s)},F=n.forwardRef(({acceptFiles:e=oe,className:s="",dimensions:l=te,disabled:r=!1,fieldName:o="file-uploader",labels:b,maxFiles:g=1,maxSizeFile:m=0,multipleFiles:v=!1,onDeleteFiles:x,onFilesChange:U,onFilesSelected:h,showDownloadButton:k=!0,theme:y,updateFiles:L=ce,validateDimensions:w=!1},C)=>{const u={...ne,...b},j=de(y),[c,p]=n.useState(null),t=J({acceptFiles:e,dimensions:l,maxFiles:g,maxSizeFile:m,multipleFiles:v,onFilesChange:U,onFilesSelected:h,updateFiles:L,validateDimensions:w});return n.useImperativeHandle(C,()=>({clear:t.clear,open:t.open,files:()=>t.items}),[t.clear,t.items,t.open]),n.useEffect(()=>{if(!c)return;const i=A=>{A.key==="Escape"&&p(null)};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c]),n.useEffect(()=>{c&&!t.items.some(i=>i.id===c.id)&&p(null)},[c,t.items]),a.jsxs("section",{className:`file-uploader ${s}`.trim(),style:j,children:[a.jsxs("div",{className:["file-uploader__dropzone",t.items.length>0?"file-uploader__dropzone--active":"",t.isDragging?"file-uploader__dropzone--dragging":"",r?"file-uploader__dropzone--disabled":""].filter(Boolean).join(" "),onDrop:r?void 0:t.onDrop,onDragOver:r?void 0:t.onDragOver,onDragLeave:r?void 0:t.onDragLeave,children:[a.jsx("div",{className:"file-uploader__info",children:t.canAddFiles?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"file-uploader__main-icon",children:a.jsx(ue,{})}),a.jsxs("div",{children:[a.jsx("p",{className:"file-uploader__title",children:u.idleTitle}),a.jsx("p",{className:"file-uploader__hint",children:u.idleHint}),m>0&&a.jsx("p",{children:u.maxSize(m)}),e.length>0&&a.jsx("p",{children:u.allowedFormats(t.acceptedFormats)}),w&&a.jsx("p",{children:u.imageDimensions(l.width,l.height)})]})]}):a.jsxs("div",{children:[a.jsx("span",{className:"file-uploader__success-mark",children:a.jsx($,{approved:!0})}),a.jsx("p",{className:"file-uploader__title",children:u.limitReached})]})}),a.jsx("input",{ref:t.inputRef,type:"file",id:o,name:o,className:"file-uploader__input",onChange:t.handleFiles,accept:e.join(","),multiple:v,disabled:r}),t.canAddFiles&&a.jsx("button",{type:"button",className:"file-uploader__browse",onClick:t.open,disabled:r,children:v?u.browseFiles:u.browseFile}),t.items.length>0&&a.jsx("div",{className:"file-uploader__list",children:t.items.map(i=>{const A=k&&i.approve&&W(i.file);return a.jsx(n.Fragment,{children:a.jsxs("div",{className:["file-uploader__item",i.approve?"file-uploader__item--success":"file-uploader__item--failed"].join(" "),children:[a.jsx("span",{className:"file-uploader__status",children:a.jsx($,{approved:i.approve})}),i.previewUrl&&a.jsxs("button",{type:"button",className:"file-uploader__preview-trigger",onClick:()=>p(i),"aria-label":`${u.previewFile}: ${i.file.name}`,title:u.previewFile,children:[N(i.file)&&a.jsx("img",{className:"file-uploader__thumbnail file-uploader__thumbnail--image",src:i.previewUrl,alt:""}),T(i.file)&&a.jsxs(a.Fragment,{children:[a.jsx("video",{className:"file-uploader__thumbnail file-uploader__thumbnail--video",src:i.previewUrl,preload:"metadata",muted:!0}),a.jsx("span",{className:"file-uploader__preview-badge",children:a.jsx(me,{})})]}),R(i.file)&&a.jsx("span",{className:"file-uploader__media-placeholder",children:a.jsx(V,{})})]}),!i.previewUrl&&a.jsx("span",{className:"file-uploader__file-icon",children:a.jsx(pe,{})}),a.jsxs("div",{className:"file-uploader__file-info",children:[a.jsx("p",{className:"file-uploader__name",children:i.file.name}),a.jsx("p",{className:"file-uploader__size",children:O(i.file.size)})]}),a.jsxs("div",{className:"file-uploader__actions",children:[A&&a.jsx("button",{type:"button",className:"file-uploader__icon-button",onClick:()=>_e(i.file),"aria-label":u.downloadFile,title:u.downloadFile,children:a.jsx(fe,{})}),a.jsx("button",{type:"button",className:"file-uploader__icon-button file-uploader__icon-button--danger",onClick:()=>{(c==null?void 0:c.id)===i.id&&p(null),t.removeFile(i),x==null||x(t.items.filter(I=>I.id!==i.id&&I.approve),i)},"aria-label":u.removeFile,title:u.removeFile,children:a.jsx(he,{})})]})]})},i.id)})}),v&&a.jsx("p",{className:"file-uploader__counter",children:u.selectedCount(t.approvedItems.length,g)})]}),(c==null?void 0:c.previewUrl)&&a.jsx("div",{className:"file-uploader__modal",role:"dialog","aria-modal":"true","aria-label":`${u.previewFile}: ${c.file.name}`,onMouseDown:i=>{i.currentTarget===i.target&&p(null)},children:a.jsxs("div",{className:"file-uploader__modal-panel",children:[a.jsxs("div",{className:"file-uploader__modal-header",children:[a.jsxs("div",{children:[a.jsx("p",{className:"file-uploader__modal-title",children:c.file.name}),a.jsx("p",{className:"file-uploader__modal-meta",children:O(c.file.size)})]}),a.jsx("button",{type:"button",className:"file-uploader__icon-button",onClick:()=>p(null),"aria-label":u.closePreview,title:u.closePreview,children:a.jsx(ve,{})})]}),a.jsxs("div",{className:"file-uploader__modal-content",children:[N(c.file)&&a.jsx("img",{className:"file-uploader__modal-image",src:c.previewUrl,alt:c.file.name}),T(c.file)&&a.jsx("video",{className:"file-uploader__modal-video",src:c.previewUrl,controls:!0,preload:"metadata"}),R(c.file)&&a.jsxs("div",{className:"file-uploader__modal-audio",children:[a.jsx(V,{}),a.jsx("audio",{src:c.previewUrl,controls:!0,preload:"metadata"})]})]})]})})]})});F.displayName="ReactFileUploader";const xe=F;exports.DEFAULT_AUDIO_FORMATS=Z;exports.DEFAULT_IMAGE_FORMATS=z;exports.DEFAULT_VIDEO_FORMATS=G;exports.FileUploader=xe;exports.ReactFileUploader=F;exports.bytesToSize=O;exports.default=F;exports.getFileExtension=D;exports.getReadableAcceptedFormats=H;exports.isAudioFile=R;exports.isDocumentFile=W;exports.isImageFile=N;exports.isPreviewableFile=B;exports.isVideoFile=T;exports.matchesAcceptedType=q;exports.useFileUploader=J;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("react/jsx-runtime"),n=require("react"),Z=["png","webp","jpeg","jpg","svg"],H=["mp3","wav","ogg","mpeg","aac","flac"],q=["mp4","webm","ogg","mov","quicktime"],re={audio:"MP3, WAV, OGG, AAC, FLAC",image:"PNG, JPG, JPEG, WEBP, SVG",video:"MP4, WEBM, OGG, MOV"},B=(e,s=" ")=>{const l=["Bytes","KB","MB","GB","TB"];if(e===0)return"n/a";const r=Math.floor(Math.log(e)/Math.log(1024));return`${r===0?e:(e/1024**r).toFixed(1)}${s}${l[r]}`},F=e=>{var r,t;const s=(r=e.name.split(".").pop())==null?void 0:r.toLowerCase();return((t=e.type.split("/")[1])==null?void 0:t.toLowerCase())||s||""},G=e=>e.map(s=>{const[l,r]=s.split("/");return r?r==="*"?re[l]??`Cualquier ${l}`:r.toUpperCase():s.replace(".","").toUpperCase()}),A=e=>{const s=F(e);return e.type.startsWith("image/")||Z.includes(s)},R=e=>{const s=F(e);return e.type.startsWith("audio/")||H.includes(s)},T=e=>{const s=F(e);return e.type.startsWith("video/")||q.includes(s)},S=e=>A(e)||R(e)||T(e),W=e=>!S(e),le=e=>e===!0?{enabled:!0,mode:"lossless",quality:.92}:e?{enabled:(e==null?void 0:e.enabled)??!1,mode:(e==null?void 0:e.mode)??"lossless",quality:(e==null?void 0:e.quality)??.92}:{enabled:!1,mode:"lossless",quality:.92},J=(e,s)=>new File([e],s.name,{lastModified:s.lastModified,type:e.type||s.type}),te=async e=>{const l=(await e.text()).replace(/<!--[\s\S]*?-->/g,"").replace(/>\s+</g,"><").replace(/\s{2,}/g," ").trim(),r=new Blob([l],{type:e.type||"image/svg+xml"});return r.size<e.size?J(r,e):e},ie=(e,s,l)=>new Promise(r=>{const t=URL.createObjectURL(e),u=new window.Image;u.onload=()=>{const h=document.createElement("canvas");h.width=u.naturalWidth||u.width,h.height=u.naturalHeight||u.height;const m=h.getContext("2d");m==null||m.drawImage(u,0,0),URL.revokeObjectURL(t),h.toBlob(r,s,l)},u.onerror=()=>{URL.revokeObjectURL(t),r(null)},u.src=t}),K=async(e,s)=>{const l=le(s),r=F(e);if(!l.enabled||!A(e))return{file:e,originalFile:e,compressed:!1,mode:l.mode};if(r==="svg"||e.type==="image/svg+xml"){const m=await te(e);return{file:m,originalFile:e,compressed:m.size<e.size,mode:l.mode}}if(l.mode==="lossless"&&r!=="png")return{file:e,originalFile:e,compressed:!1,mode:l.mode};const t=l.mode==="lossless"?"image/png":e.type||"image/jpeg",u=await ie(e,t,l.mode==="balanced"?l.quality:void 0);return!u||u.size>=e.size?{file:e,originalFile:e,compressed:!1,mode:l.mode}:{file:J(u,e),originalFile:e,compressed:!0,mode:l.mode}},Q=(e,s)=>{if(s.length===0)return!0;const l=F(e);return s.some(r=>{const t=r.trim().toLowerCase();return t.startsWith(".")?t.slice(1)===l:t.endsWith("/*")?e.type.startsWith(t.replace("*","")):e.type.toLowerCase()===t||l===t})},oe=(e,s)=>new Promise(l=>{const r=URL.createObjectURL(e),t=new window.Image;t.onload=()=>{URL.revokeObjectURL(r),l(t.width<=s.width&&t.height<=s.height)},t.onerror=()=>{URL.revokeObjectURL(r),l(!1)},t.src=r}),P=async(e,s)=>{const l=await K(e,s.imageCompression),r=l.file,t=[],u=s.maxSizeFile>0?s.maxSizeFile*1024*1024:0;u>0&&r.size>u&&t.push("file-size"),Q(r,s.acceptFiles)||t.push("file-type"),s.validateDimensions&&A(r)&&(await oe(r,s.dimensions)||t.push("image-dimensions"));const h=t.length===0;return{id:`${r.name}-${r.size}-${r.lastModified}-${crypto.randomUUID()}`,file:r,originalFile:l.originalFile,status:h?"approved":"rejected",approve:h,reasons:t,previewUrl:S(r)?URL.createObjectURL(r):void 0,compression:{compressed:l.compressed,originalSize:l.originalFile.size,compressedSize:r.size,mode:l.mode}}},$=e=>{e.forEach(s=>{s.previewUrl&&URL.revokeObjectURL(s.previewUrl)})},ce=[],ne={width:0,height:0},de=[],ue=e=>"dataTransfer"in e?Array.from(e.dataTransfer.files):Array.from(e.target.files??[]),X=({acceptFiles:e=ce,dimensions:s=ne,imageCompression:l,maxFiles:r=1,maxSizeFile:t=0,multipleFiles:u=!1,updateFiles:h=de,validateDimensions:m=!1,onFilesChange:_,onFilesSelected:x})=>{const w=n.useRef(null),E=n.useRef([]),[g,z]=n.useState([]),[k,U]=n.useState(!1),L=n.useMemo(()=>g.filter(d=>d.approve),[g]),O=n.useMemo(()=>G(e),[e]),p=u?L.length<r:g.length===0,b=n.useCallback(()=>{w.current&&(w.current.value="")},[]),c=n.useCallback(d=>{const v=d.filter(j=>j.approve).map(j=>j.file);if(_==null||_(d),u){x==null||x(v);return}v[0]&&(x==null||x(v[0]))},[u,_,x]),f=n.useCallback(d=>{z(v=>{const j=d(v),D=v.filter(I=>!j.some(se=>se.id===I.id));return $(D),E.current=j,j})},[]),o=n.useCallback(async d=>{d.preventDefault(),U(!1);const v=ue(d),j=await Promise.all(v.map(I=>P(I,{acceptFiles:e,dimensions:s,imageCompression:l,maxSizeFile:t,validateDimensions:m}))),D=u?[...g,...j.filter(I=>I.approve).slice(0,Math.max(r-L.length,0))]:j.slice(0,1);f(()=>D),c(D),b()},[e,L.length,b,s,c,l,g,r,t,u,f,m]),i=n.useCallback(d=>{const v=g.filter(j=>j.id!==d.id);f(()=>v),c(v),b()},[b,c,g,f]),y=n.useCallback(()=>{f(()=>[]),b(),_==null||_([])},[b,_,f]),N=n.useCallback(()=>{var d;(d=w.current)==null||d.click()},[]),Y=n.useCallback(d=>{d.preventDefault(),U(!0)},[]),ee=n.useCallback(d=>{d.preventDefault(),U(!1)},[]),ae=n.useCallback(d=>{if(p){o(d);return}d.preventDefault(),U(!1)},[p,o]);return n.useEffect(()=>{if(h.length===0)return;let d=!1;return Promise.all(h.map(v=>P(v,{acceptFiles:e,dimensions:s,imageCompression:l,maxSizeFile:t,validateDimensions:m}))).then(v=>{d||f(()=>v)}),()=>{d=!0}},[e,s,l,t,f,h,m]),n.useEffect(()=>{E.current=g},[g]),n.useEffect(()=>()=>{$(E.current)},[]),{acceptedFormats:O,approvedItems:L,canAddFiles:p,clear:y,handleFiles:o,inputRef:w,isDragging:k,items:g,onDragLeave:ee,onDragOver:Y,onDrop:ae,open:N,removeFile:i}},pe=[],me={width:0,height:0},fe=[],ve={idleTitle:a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"Arrastra y suelta"})," tus archivos aqui"]}),idleHint:"Selecciona archivos desde tu equipo.",browseFile:"Buscar archivo",browseFiles:"Buscar archivos",limitReached:"Limite de archivos alcanzado",maxSize:e=>`Limite de ${e}MB por archivo.`,allowedFormats:e=>a.jsxs(a.Fragment,{children:["Archivos permitidos: ",a.jsx("span",{className:"file-uploader__format",children:e.join(", ")})]}),imageDimensions:(e,s)=>`Dimensiones de imagen: ${e}x${s}`,selectedCount:(e,s)=>`${e} / ${s} ${e===1?"archivo seleccionado":"archivos seleccionados"}`,removeFile:"Eliminar archivo",downloadFile:"Descargar archivo",previewFile:"Vista previa del archivo",closePreview:"Cerrar vista previa"},he=e=>{if(!e)return;const s={"--file-uploader-accent":e.accent,"--file-uploader-accent-soft":e.accentSoft,"--file-uploader-border":e.border,"--file-uploader-danger":e.danger,"--file-uploader-ink":e.ink,"--file-uploader-muted":e.muted,"--file-uploader-success":e.success,"--file-uploader-surface":e.surface,"--file-uploader-item-surface":e.itemSurface,"--file-uploader-modal-backdrop":e.modalBackdrop,"--file-uploader-modal-surface":e.modalSurface};return Object.keys(s).forEach(l=>{const r=l;s[r]===void 0&&delete s[r]}),s},_e=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 640 512",children:a.jsx("path",{d:"M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9C96.1 197.4 96 194.7 96 192c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128H144Zm79-217c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l39-39V392c0 13.3 10.7 24 24 24s24-10.7 24-24V257.9l39 39c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0l-80 80Z"})}),xe=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M0 64C0 28.7 28.7 0 64 0h160v128c0 17.7 14.3 32 32 32h128v288c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64Zm384 64H256V0l128 128Z"})}),V=({approved:e})=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:e?a.jsx("path",{d:"M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512Zm113-303L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9Z"}):a.jsx("path",{d:"M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512ZM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9Z"})}),ge=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:a.jsx("path",{d:"M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32v242.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7V32ZM64 352c-35.3 0-64 28.7-64 64v32c0 35.3 28.7 64 64 64h384c35.3 0 64-28.7 64-64v-32c0-35.3-28.7-64-64-64H346.5l-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352H64Z"})}),je=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80v352c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9l288-176c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39Z"})}),C=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 512 512",children:a.jsx("path",{d:"M499.1 6.3c8.1 6 12.9 15.6 12.9 25.7v320c0 53-43 96-96 96s-96-43-96-96s43-96 96-96c11.2 0 22 1.9 32 5.5V111.9L192 160v224c0 53-43 96-96 96S0 437 0 384s43-96 96-96c11.2 0 22 1.9 32 5.5V128c0-15.4 10.9-28.6 26.1-31.5l320-60c9.9-1.9 20.1 .4 28.2 6.4Z"})}),we=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 384 512",children:a.jsx("path",{d:"M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6Z"})}),be=()=>a.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 448 512",children:a.jsx("path",{d:"m135.2 17.7L128 32H32C14.3 32 0 46.3 0 64s14.3 32 32 32h384c17.7 0 32-14.3 32-32s-14.3-32-32-32h-96l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7ZM416 128H32l21.2 339c1.6 25.3 22.6 45 47.9 45h245.8c25.3 0 46.3-19.7 47.9-45L416 128Z"})}),Le=e=>{const s=URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download=e.name||"archivo_descarga",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(s)},M=n.forwardRef(({acceptFiles:e=pe,className:s="",dimensions:l=me,disabled:r=!1,fieldName:t="file-uploader",imageCompression:u,labels:h,maxFiles:m=1,maxSizeFile:_=0,multipleFiles:x=!1,onDeleteFiles:w,onFilesChange:E,onFilesSelected:g,showDownloadButton:z=!0,theme:k,updateFiles:U=fe,validateDimensions:L=!1},O)=>{const p={...ve,...h},b=he(k),[c,f]=n.useState(null),o=X({acceptFiles:e,dimensions:l,imageCompression:u,maxFiles:m,maxSizeFile:_,multipleFiles:x,onFilesChange:E,onFilesSelected:g,updateFiles:U,validateDimensions:L});return n.useImperativeHandle(O,()=>({clear:o.clear,open:o.open,files:()=>o.items}),[o.clear,o.items,o.open]),n.useEffect(()=>{if(!c)return;const i=y=>{y.key==="Escape"&&f(null)};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[c]),n.useEffect(()=>{c&&!o.items.some(i=>i.id===c.id)&&f(null)},[c,o.items]),a.jsxs("section",{className:`file-uploader ${s}`.trim(),style:b,children:[a.jsxs("div",{className:["file-uploader__dropzone",o.items.length>0?"file-uploader__dropzone--active":"",o.isDragging?"file-uploader__dropzone--dragging":"",r?"file-uploader__dropzone--disabled":""].filter(Boolean).join(" "),onDrop:r?void 0:o.onDrop,onDragOver:r?void 0:o.onDragOver,onDragLeave:r?void 0:o.onDragLeave,children:[a.jsx("div",{className:"file-uploader__info",children:o.canAddFiles?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"file-uploader__main-icon",children:a.jsx(_e,{})}),a.jsxs("div",{children:[a.jsx("p",{className:"file-uploader__title",children:p.idleTitle}),a.jsx("p",{className:"file-uploader__hint",children:p.idleHint}),_>0&&a.jsx("p",{children:p.maxSize(_)}),e.length>0&&a.jsx("p",{children:p.allowedFormats(o.acceptedFormats)}),L&&a.jsx("p",{children:p.imageDimensions(l.width,l.height)})]})]}):a.jsxs("div",{children:[a.jsx("span",{className:"file-uploader__success-mark",children:a.jsx(V,{approved:!0})}),a.jsx("p",{className:"file-uploader__title",children:p.limitReached})]})}),a.jsx("input",{ref:o.inputRef,type:"file",id:t,name:t,className:"file-uploader__input",onChange:o.handleFiles,accept:e.join(","),multiple:x,disabled:r}),o.canAddFiles&&a.jsx("button",{type:"button",className:"file-uploader__browse",onClick:o.open,disabled:r,children:x?p.browseFiles:p.browseFile}),o.items.length>0&&a.jsx("div",{className:"file-uploader__list",children:o.items.map(i=>{const y=z&&i.approve&&W(i.file);return a.jsx(n.Fragment,{children:a.jsxs("div",{className:["file-uploader__item",i.approve?"file-uploader__item--success":"file-uploader__item--failed"].join(" "),children:[a.jsx("span",{className:"file-uploader__status",children:a.jsx(V,{approved:i.approve})}),i.previewUrl&&a.jsxs("button",{type:"button",className:"file-uploader__preview-trigger",onClick:()=>f(i),"aria-label":`${p.previewFile}: ${i.file.name}`,title:p.previewFile,children:[A(i.file)&&a.jsx("img",{className:"file-uploader__thumbnail file-uploader__thumbnail--image",src:i.previewUrl,alt:""}),T(i.file)&&a.jsxs(a.Fragment,{children:[a.jsx("video",{className:"file-uploader__thumbnail file-uploader__thumbnail--video",src:i.previewUrl,preload:"metadata",muted:!0}),a.jsx("span",{className:"file-uploader__preview-badge",children:a.jsx(je,{})})]}),R(i.file)&&a.jsx("span",{className:"file-uploader__media-placeholder",children:a.jsx(C,{})})]}),!i.previewUrl&&a.jsx("span",{className:"file-uploader__file-icon",children:a.jsx(xe,{})}),a.jsxs("div",{className:"file-uploader__file-info",children:[a.jsx("p",{className:"file-uploader__name",children:i.file.name}),a.jsx("p",{className:"file-uploader__size",children:B(i.file.size)})]}),a.jsxs("div",{className:"file-uploader__actions",children:[y&&a.jsx("button",{type:"button",className:"file-uploader__icon-button",onClick:()=>Le(i.file),"aria-label":p.downloadFile,title:p.downloadFile,children:a.jsx(ge,{})}),a.jsx("button",{type:"button",className:"file-uploader__icon-button file-uploader__icon-button--danger",onClick:()=>{(c==null?void 0:c.id)===i.id&&f(null),o.removeFile(i),w==null||w(o.items.filter(N=>N.id!==i.id&&N.approve),i)},"aria-label":p.removeFile,title:p.removeFile,children:a.jsx(be,{})})]})]})},i.id)})}),x&&a.jsx("p",{className:"file-uploader__counter",children:p.selectedCount(o.approvedItems.length,m)})]}),(c==null?void 0:c.previewUrl)&&a.jsx("div",{className:"file-uploader__modal",role:"dialog","aria-modal":"true","aria-label":`${p.previewFile}: ${c.file.name}`,onMouseDown:i=>{i.currentTarget===i.target&&f(null)},children:a.jsxs("div",{className:"file-uploader__modal-panel",children:[a.jsxs("div",{className:"file-uploader__modal-header",children:[a.jsxs("div",{children:[a.jsx("p",{className:"file-uploader__modal-title",children:c.file.name}),a.jsx("p",{className:"file-uploader__modal-meta",children:B(c.file.size)})]}),a.jsx("button",{type:"button",className:"file-uploader__icon-button",onClick:()=>f(null),"aria-label":p.closePreview,title:p.closePreview,children:a.jsx(we,{})})]}),a.jsxs("div",{className:"file-uploader__modal-content",children:[A(c.file)&&a.jsx("img",{className:"file-uploader__modal-image",src:c.previewUrl,alt:c.file.name}),T(c.file)&&a.jsx("video",{className:"file-uploader__modal-video",src:c.previewUrl,controls:!0,preload:"metadata"}),R(c.file)&&a.jsxs("div",{className:"file-uploader__modal-audio",children:[a.jsx(C,{}),a.jsx("audio",{src:c.previewUrl,controls:!0,preload:"metadata"})]})]})]})})]})});M.displayName="ReactFileUploader";const Ue=M;exports.DEFAULT_AUDIO_FORMATS=H;exports.DEFAULT_IMAGE_FORMATS=Z;exports.DEFAULT_VIDEO_FORMATS=q;exports.FileUploader=Ue;exports.ReactFileUploader=M;exports.bytesToSize=B;exports.default=M;exports.getFileExtension=F;exports.getReadableAcceptedFormats=G;exports.isAudioFile=R;exports.isDocumentFile=W;exports.isImageFile=A;exports.isPreviewableFile=S;exports.isVideoFile=T;exports.matchesAcceptedType=Q;exports.optimizeImageFile=K;exports.useFileUploader=X;
|
package/dist/index.js
CHANGED
|
@@ -1,182 +1,262 @@
|
|
|
1
|
-
import { jsxs as p, jsx as r, Fragment as
|
|
2
|
-
import { useRef as
|
|
3
|
-
const
|
|
1
|
+
import { jsxs as p, jsx as r, Fragment as x } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as S, useState as $, useMemo as V, useCallback as b, useEffect as z, forwardRef as re, useImperativeHandle as ae, Fragment as te } from "react";
|
|
3
|
+
const le = ["png", "webp", "jpeg", "jpg", "svg"], oe = ["mp3", "wav", "ogg", "mpeg", "aac", "flac"], ie = ["mp4", "webm", "ogg", "mov", "quicktime"], se = {
|
|
4
4
|
audio: "MP3, WAV, OGG, AAC, FLAC",
|
|
5
5
|
image: "PNG, JPG, JPEG, WEBP, SVG",
|
|
6
6
|
video: "MP4, WEBM, OGG, MOV"
|
|
7
|
-
},
|
|
8
|
-
const
|
|
7
|
+
}, Z = (e, a = " ") => {
|
|
8
|
+
const l = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
9
9
|
if (e === 0)
|
|
10
10
|
return "n/a";
|
|
11
|
-
const
|
|
12
|
-
return `${
|
|
13
|
-
},
|
|
14
|
-
var
|
|
15
|
-
const a = (
|
|
16
|
-
return ((
|
|
17
|
-
},
|
|
18
|
-
const [
|
|
19
|
-
return
|
|
20
|
-
}),
|
|
21
|
-
const a =
|
|
22
|
-
return e.type.startsWith("image/") ||
|
|
11
|
+
const t = Math.floor(Math.log(e) / Math.log(1024));
|
|
12
|
+
return `${t === 0 ? e : (e / 1024 ** t).toFixed(1)}${a}${l[t]}`;
|
|
13
|
+
}, F = (e) => {
|
|
14
|
+
var t, o;
|
|
15
|
+
const a = (t = e.name.split(".").pop()) == null ? void 0 : t.toLowerCase();
|
|
16
|
+
return ((o = e.type.split("/")[1]) == null ? void 0 : o.toLowerCase()) || a || "";
|
|
17
|
+
}, ne = (e) => e.map((a) => {
|
|
18
|
+
const [l, t] = a.split("/");
|
|
19
|
+
return t ? t === "*" ? se[l] ?? `Cualquier ${l}` : t.toUpperCase() : a.replace(".", "").toUpperCase();
|
|
20
|
+
}), R = (e) => {
|
|
21
|
+
const a = F(e);
|
|
22
|
+
return e.type.startsWith("image/") || le.includes(a);
|
|
23
|
+
}, j = (e) => {
|
|
24
|
+
const a = F(e);
|
|
25
|
+
return e.type.startsWith("audio/") || oe.includes(a);
|
|
23
26
|
}, P = (e) => {
|
|
24
|
-
const a =
|
|
25
|
-
return e.type.startsWith("
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const a = F(e);
|
|
28
|
+
return e.type.startsWith("video/") || ie.includes(a);
|
|
29
|
+
}, C = (e) => R(e) || j(e) || P(e), ce = (e) => !C(e), de = (e) => e === !0 ? {
|
|
30
|
+
enabled: !0,
|
|
31
|
+
mode: "lossless",
|
|
32
|
+
quality: 0.92
|
|
33
|
+
} : e ? {
|
|
34
|
+
enabled: (e == null ? void 0 : e.enabled) ?? !1,
|
|
35
|
+
mode: (e == null ? void 0 : e.mode) ?? "lossless",
|
|
36
|
+
quality: (e == null ? void 0 : e.quality) ?? 0.92
|
|
37
|
+
} : {
|
|
38
|
+
enabled: !1,
|
|
39
|
+
mode: "lossless",
|
|
40
|
+
quality: 0.92
|
|
41
|
+
}, J = (e, a) => new File([e], a.name, {
|
|
42
|
+
lastModified: a.lastModified,
|
|
43
|
+
type: e.type || a.type
|
|
44
|
+
}), ue = async (e) => {
|
|
45
|
+
const l = (await e.text()).replace(/<!--[\s\S]*?-->/g, "").replace(/>\s+</g, "><").replace(/\s{2,}/g, " ").trim(), t = new Blob([l], { type: e.type || "image/svg+xml" });
|
|
46
|
+
return t.size < e.size ? J(t, e) : e;
|
|
47
|
+
}, pe = (e, a, l) => new Promise((t) => {
|
|
48
|
+
const o = URL.createObjectURL(e), d = new window.Image();
|
|
49
|
+
d.onload = () => {
|
|
50
|
+
const h = document.createElement("canvas");
|
|
51
|
+
h.width = d.naturalWidth || d.width, h.height = d.naturalHeight || d.height;
|
|
52
|
+
const m = h.getContext("2d");
|
|
53
|
+
m == null || m.drawImage(d, 0, 0), URL.revokeObjectURL(o), h.toBlob(t, a, l);
|
|
54
|
+
}, d.onerror = () => {
|
|
55
|
+
URL.revokeObjectURL(o), t(null);
|
|
56
|
+
}, d.src = o;
|
|
57
|
+
}), me = async (e, a) => {
|
|
58
|
+
const l = de(a), t = F(e);
|
|
59
|
+
if (!l.enabled || !R(e))
|
|
60
|
+
return {
|
|
61
|
+
file: e,
|
|
62
|
+
originalFile: e,
|
|
63
|
+
compressed: !1,
|
|
64
|
+
mode: l.mode
|
|
65
|
+
};
|
|
66
|
+
if (t === "svg" || e.type === "image/svg+xml") {
|
|
67
|
+
const m = await ue(e);
|
|
68
|
+
return {
|
|
69
|
+
file: m,
|
|
70
|
+
originalFile: e,
|
|
71
|
+
compressed: m.size < e.size,
|
|
72
|
+
mode: l.mode
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (l.mode === "lossless" && t !== "png")
|
|
76
|
+
return {
|
|
77
|
+
file: e,
|
|
78
|
+
originalFile: e,
|
|
79
|
+
compressed: !1,
|
|
80
|
+
mode: l.mode
|
|
81
|
+
};
|
|
82
|
+
const o = l.mode === "lossless" ? "image/png" : e.type || "image/jpeg", d = await pe(
|
|
83
|
+
e,
|
|
84
|
+
o,
|
|
85
|
+
l.mode === "balanced" ? l.quality : void 0
|
|
86
|
+
);
|
|
87
|
+
return !d || d.size >= e.size ? {
|
|
88
|
+
file: e,
|
|
89
|
+
originalFile: e,
|
|
90
|
+
compressed: !1,
|
|
91
|
+
mode: l.mode
|
|
92
|
+
} : {
|
|
93
|
+
file: J(d, e),
|
|
94
|
+
originalFile: e,
|
|
95
|
+
compressed: !0,
|
|
96
|
+
mode: l.mode
|
|
97
|
+
};
|
|
98
|
+
}, fe = (e, a) => {
|
|
30
99
|
if (a.length === 0)
|
|
31
100
|
return !0;
|
|
32
|
-
const
|
|
33
|
-
return a.some((
|
|
34
|
-
const
|
|
35
|
-
return
|
|
101
|
+
const l = F(e);
|
|
102
|
+
return a.some((t) => {
|
|
103
|
+
const o = t.trim().toLowerCase();
|
|
104
|
+
return o.startsWith(".") ? o.slice(1) === l : o.endsWith("/*") ? e.type.startsWith(o.replace("*", "")) : e.type.toLowerCase() === o || l === o;
|
|
36
105
|
});
|
|
37
|
-
},
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
URL.revokeObjectURL(
|
|
41
|
-
},
|
|
42
|
-
URL.revokeObjectURL(
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
const o = [],
|
|
46
|
-
|
|
47
|
-
const
|
|
106
|
+
}, ve = (e, a) => new Promise((l) => {
|
|
107
|
+
const t = URL.createObjectURL(e), o = new window.Image();
|
|
108
|
+
o.onload = () => {
|
|
109
|
+
URL.revokeObjectURL(t), l(o.width <= a.width && o.height <= a.height);
|
|
110
|
+
}, o.onerror = () => {
|
|
111
|
+
URL.revokeObjectURL(t), l(!1);
|
|
112
|
+
}, o.src = t;
|
|
113
|
+
}), H = async (e, a) => {
|
|
114
|
+
const l = await me(e, a.imageCompression), t = l.file, o = [], d = a.maxSizeFile > 0 ? a.maxSizeFile * 1024 * 1024 : 0;
|
|
115
|
+
d > 0 && t.size > d && o.push("file-size"), fe(t, a.acceptFiles) || o.push("file-type"), a.validateDimensions && R(t) && (await ve(t, a.dimensions) || o.push("image-dimensions"));
|
|
116
|
+
const h = o.length === 0;
|
|
48
117
|
return {
|
|
49
|
-
id: `${
|
|
50
|
-
file:
|
|
51
|
-
|
|
52
|
-
|
|
118
|
+
id: `${t.name}-${t.size}-${t.lastModified}-${crypto.randomUUID()}`,
|
|
119
|
+
file: t,
|
|
120
|
+
originalFile: l.originalFile,
|
|
121
|
+
status: h ? "approved" : "rejected",
|
|
122
|
+
approve: h,
|
|
53
123
|
reasons: o,
|
|
54
|
-
previewUrl:
|
|
124
|
+
previewUrl: C(t) ? URL.createObjectURL(t) : void 0,
|
|
125
|
+
compression: {
|
|
126
|
+
compressed: l.compressed,
|
|
127
|
+
originalSize: l.originalFile.size,
|
|
128
|
+
compressedSize: t.size,
|
|
129
|
+
mode: l.mode
|
|
130
|
+
}
|
|
55
131
|
};
|
|
56
|
-
},
|
|
132
|
+
}, W = (e) => {
|
|
57
133
|
e.forEach((a) => {
|
|
58
134
|
a.previewUrl && URL.revokeObjectURL(a.previewUrl);
|
|
59
135
|
});
|
|
60
|
-
},
|
|
61
|
-
acceptFiles: e =
|
|
62
|
-
dimensions: a =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
136
|
+
}, he = [], _e = { width: 0, height: 0 }, ge = [], we = (e) => "dataTransfer" in e ? Array.from(e.dataTransfer.files) : Array.from(e.target.files ?? []), Le = ({
|
|
137
|
+
acceptFiles: e = he,
|
|
138
|
+
dimensions: a = _e,
|
|
139
|
+
imageCompression: l,
|
|
140
|
+
maxFiles: t = 1,
|
|
141
|
+
maxSizeFile: o = 0,
|
|
142
|
+
multipleFiles: d = !1,
|
|
143
|
+
updateFiles: h = ge,
|
|
144
|
+
validateDimensions: m = !1,
|
|
145
|
+
onFilesChange: _,
|
|
146
|
+
onFilesSelected: g
|
|
70
147
|
}) => {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
}, []), n =
|
|
74
|
-
(
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
148
|
+
const U = S(null), E = S([]), [w, B] = $([]), [O, A] = $(!1), N = V(() => w.filter((c) => c.approve), [w]), k = V(() => ne(e), [e]), u = d ? N.length < t : w.length === 0, y = b(() => {
|
|
149
|
+
U.current && (U.current.value = "");
|
|
150
|
+
}, []), n = b(
|
|
151
|
+
(c) => {
|
|
152
|
+
const v = c.filter((L) => L.approve).map((L) => L.file);
|
|
153
|
+
if (_ == null || _(c), d) {
|
|
154
|
+
g == null || g(v);
|
|
78
155
|
return;
|
|
79
156
|
}
|
|
80
|
-
|
|
157
|
+
v[0] && (g == null || g(v[0]));
|
|
81
158
|
},
|
|
82
|
-
[
|
|
83
|
-
),
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
return
|
|
159
|
+
[d, _, g]
|
|
160
|
+
), f = b((c) => {
|
|
161
|
+
B((v) => {
|
|
162
|
+
const L = c(v), T = v.filter((D) => !L.some((ee) => ee.id === D.id));
|
|
163
|
+
return W(T), E.current = L, L;
|
|
87
164
|
});
|
|
88
|
-
}, []),
|
|
89
|
-
async (
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
(
|
|
165
|
+
}, []), s = b(
|
|
166
|
+
async (c) => {
|
|
167
|
+
c.preventDefault(), A(!1);
|
|
168
|
+
const v = we(c), L = await Promise.all(
|
|
169
|
+
v.map(
|
|
170
|
+
(D) => H(D, {
|
|
94
171
|
acceptFiles: e,
|
|
95
172
|
dimensions: a,
|
|
96
|
-
|
|
97
|
-
|
|
173
|
+
imageCompression: l,
|
|
174
|
+
maxSizeFile: o,
|
|
175
|
+
validateDimensions: m
|
|
98
176
|
})
|
|
99
177
|
)
|
|
100
|
-
),
|
|
101
|
-
|
|
178
|
+
), T = d ? [...w, ...L.filter((D) => D.approve).slice(0, Math.max(t - N.length, 0))] : L.slice(0, 1);
|
|
179
|
+
f(() => T), n(T), y();
|
|
102
180
|
},
|
|
103
181
|
[
|
|
104
182
|
e,
|
|
105
|
-
|
|
106
|
-
|
|
183
|
+
N.length,
|
|
184
|
+
y,
|
|
107
185
|
a,
|
|
108
186
|
n,
|
|
109
|
-
v,
|
|
110
|
-
o,
|
|
111
187
|
l,
|
|
188
|
+
w,
|
|
112
189
|
t,
|
|
113
|
-
|
|
114
|
-
|
|
190
|
+
o,
|
|
191
|
+
d,
|
|
192
|
+
f,
|
|
193
|
+
m
|
|
115
194
|
]
|
|
116
|
-
), i =
|
|
117
|
-
(
|
|
118
|
-
const
|
|
119
|
-
|
|
195
|
+
), i = b(
|
|
196
|
+
(c) => {
|
|
197
|
+
const v = w.filter((L) => L.id !== c.id);
|
|
198
|
+
f(() => v), n(v), y();
|
|
120
199
|
},
|
|
121
|
-
[
|
|
122
|
-
),
|
|
123
|
-
|
|
124
|
-
}, [
|
|
125
|
-
var
|
|
126
|
-
(
|
|
127
|
-
}, []),
|
|
128
|
-
|
|
129
|
-
}, []),
|
|
130
|
-
|
|
131
|
-
}, []),
|
|
132
|
-
(
|
|
133
|
-
if (
|
|
134
|
-
c
|
|
200
|
+
[y, n, w, f]
|
|
201
|
+
), I = b(() => {
|
|
202
|
+
f(() => []), y(), _ == null || _([]);
|
|
203
|
+
}, [y, _, f]), M = b(() => {
|
|
204
|
+
var c;
|
|
205
|
+
(c = U.current) == null || c.click();
|
|
206
|
+
}, []), Q = b((c) => {
|
|
207
|
+
c.preventDefault(), A(!0);
|
|
208
|
+
}, []), X = b((c) => {
|
|
209
|
+
c.preventDefault(), A(!1);
|
|
210
|
+
}, []), Y = b(
|
|
211
|
+
(c) => {
|
|
212
|
+
if (u) {
|
|
213
|
+
s(c);
|
|
135
214
|
return;
|
|
136
215
|
}
|
|
137
|
-
|
|
216
|
+
c.preventDefault(), A(!1);
|
|
138
217
|
},
|
|
139
|
-
[
|
|
218
|
+
[u, s]
|
|
140
219
|
);
|
|
141
|
-
return
|
|
142
|
-
if (
|
|
220
|
+
return z(() => {
|
|
221
|
+
if (h.length === 0)
|
|
143
222
|
return;
|
|
144
|
-
let
|
|
223
|
+
let c = !1;
|
|
145
224
|
return Promise.all(
|
|
146
|
-
|
|
147
|
-
(
|
|
225
|
+
h.map(
|
|
226
|
+
(v) => H(v, {
|
|
148
227
|
acceptFiles: e,
|
|
149
228
|
dimensions: a,
|
|
150
|
-
|
|
151
|
-
|
|
229
|
+
imageCompression: l,
|
|
230
|
+
maxSizeFile: o,
|
|
231
|
+
validateDimensions: m
|
|
152
232
|
})
|
|
153
233
|
)
|
|
154
|
-
).then((
|
|
155
|
-
|
|
234
|
+
).then((v) => {
|
|
235
|
+
c || f(() => v);
|
|
156
236
|
}), () => {
|
|
157
|
-
|
|
237
|
+
c = !0;
|
|
158
238
|
};
|
|
159
|
-
}, [e, a, l,
|
|
160
|
-
E.current =
|
|
161
|
-
}, [
|
|
162
|
-
|
|
239
|
+
}, [e, a, l, o, f, h, m]), z(() => {
|
|
240
|
+
E.current = w;
|
|
241
|
+
}, [w]), z(() => () => {
|
|
242
|
+
W(E.current);
|
|
163
243
|
}, []), {
|
|
164
|
-
acceptedFormats:
|
|
165
|
-
approvedItems:
|
|
166
|
-
canAddFiles:
|
|
167
|
-
clear:
|
|
168
|
-
handleFiles:
|
|
169
|
-
inputRef:
|
|
244
|
+
acceptedFormats: k,
|
|
245
|
+
approvedItems: N,
|
|
246
|
+
canAddFiles: u,
|
|
247
|
+
clear: I,
|
|
248
|
+
handleFiles: s,
|
|
249
|
+
inputRef: U,
|
|
170
250
|
isDragging: O,
|
|
171
|
-
items:
|
|
172
|
-
onDragLeave:
|
|
173
|
-
onDragOver:
|
|
174
|
-
onDrop:
|
|
175
|
-
open:
|
|
251
|
+
items: w,
|
|
252
|
+
onDragLeave: X,
|
|
253
|
+
onDragOver: Q,
|
|
254
|
+
onDrop: Y,
|
|
255
|
+
open: M,
|
|
176
256
|
removeFile: i
|
|
177
257
|
};
|
|
178
|
-
},
|
|
179
|
-
idleTitle: /* @__PURE__ */ p(
|
|
258
|
+
}, be = [], Ue = { width: 0, height: 0 }, ye = [], Ne = {
|
|
259
|
+
idleTitle: /* @__PURE__ */ p(x, { children: [
|
|
180
260
|
/* @__PURE__ */ r("span", { children: "Arrastra y suelta" }),
|
|
181
261
|
" tus archivos aqui"
|
|
182
262
|
] }),
|
|
@@ -185,7 +265,7 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
185
265
|
browseFiles: "Buscar archivos",
|
|
186
266
|
limitReached: "Limite de archivos alcanzado",
|
|
187
267
|
maxSize: (e) => `Limite de ${e}MB por archivo.`,
|
|
188
|
-
allowedFormats: (e) => /* @__PURE__ */ p(
|
|
268
|
+
allowedFormats: (e) => /* @__PURE__ */ p(x, { children: [
|
|
189
269
|
"Archivos permitidos: ",
|
|
190
270
|
/* @__PURE__ */ r("span", { className: "file-uploader__format", children: e.join(", ") })
|
|
191
271
|
] }),
|
|
@@ -195,7 +275,7 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
195
275
|
downloadFile: "Descargar archivo",
|
|
196
276
|
previewFile: "Vista previa del archivo",
|
|
197
277
|
closePreview: "Cerrar vista previa"
|
|
198
|
-
},
|
|
278
|
+
}, Ae = (e) => {
|
|
199
279
|
if (!e)
|
|
200
280
|
return;
|
|
201
281
|
const a = {
|
|
@@ -211,114 +291,116 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
211
291
|
"--file-uploader-modal-backdrop": e.modalBackdrop,
|
|
212
292
|
"--file-uploader-modal-surface": e.modalSurface
|
|
213
293
|
};
|
|
214
|
-
return Object.keys(a).forEach((
|
|
215
|
-
const
|
|
216
|
-
a[
|
|
294
|
+
return Object.keys(a).forEach((l) => {
|
|
295
|
+
const t = l;
|
|
296
|
+
a[t] === void 0 && delete a[t];
|
|
217
297
|
}), a;
|
|
218
|
-
},
|
|
219
|
-
const a = URL.createObjectURL(e),
|
|
220
|
-
|
|
221
|
-
},
|
|
298
|
+
}, Ee = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 640 512", children: /* @__PURE__ */ r("path", { d: "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9C96.1 197.4 96 194.7 96 192c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128H144Zm79-217c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l39-39V392c0 13.3 10.7 24 24 24s24-10.7 24-24V257.9l39 39c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0l-80 80Z" }) }), Ie = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 384 512", children: /* @__PURE__ */ r("path", { d: "M0 64C0 28.7 28.7 0 64 0h160v128c0 17.7 14.3 32 32 32h128v288c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64Zm384 64H256V0l128 128Z" }) }), G = ({ approved: e }) => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 512 512", children: e ? /* @__PURE__ */ r("path", { d: "M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512Zm113-303L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9Z" }) : /* @__PURE__ */ r("path", { d: "M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512ZM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9Z" }) }), De = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 512 512", children: /* @__PURE__ */ r("path", { d: "M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32v242.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7V32ZM64 352c-35.3 0-64 28.7-64 64v32c0 35.3 28.7 64 64 64h384c35.3 0 64-28.7 64-64v-32c0-35.3-28.7-64-64-64H346.5l-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352H64Z" }) }), ze = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 384 512", children: /* @__PURE__ */ r("path", { d: "M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80v352c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9l288-176c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39Z" }) }), q = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 512 512", children: /* @__PURE__ */ r("path", { d: "M499.1 6.3c8.1 6 12.9 15.6 12.9 25.7v320c0 53-43 96-96 96s-96-43-96-96s43-96 96-96c11.2 0 22 1.9 32 5.5V111.9L192 160v224c0 53-43 96-96 96S0 437 0 384s43-96 96-96c11.2 0 22 1.9 32 5.5V128c0-15.4 10.9-28.6 26.1-31.5l320-60c9.9-1.9 20.1 .4 28.2 6.4Z" }) }), Re = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 384 512", children: /* @__PURE__ */ r("path", { d: "M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6Z" }) }), Fe = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 448 512", children: /* @__PURE__ */ r("path", { d: "m135.2 17.7L128 32H32C14.3 32 0 46.3 0 64s14.3 32 32 32h384c17.7 0 32-14.3 32-32s-14.3-32-32-32h-96l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7ZM416 128H32l21.2 339c1.6 25.3 22.6 45 47.9 45h245.8c25.3 0 46.3-19.7 47.9-45L416 128Z" }) }), Me = (e) => {
|
|
299
|
+
const a = URL.createObjectURL(e), l = document.createElement("a");
|
|
300
|
+
l.href = a, l.download = e.name || "archivo_descarga", document.body.appendChild(l), l.click(), document.body.removeChild(l), URL.revokeObjectURL(a);
|
|
301
|
+
}, K = re(
|
|
222
302
|
({
|
|
223
|
-
acceptFiles: e =
|
|
303
|
+
acceptFiles: e = be,
|
|
224
304
|
className: a = "",
|
|
225
|
-
dimensions:
|
|
226
|
-
disabled:
|
|
227
|
-
fieldName:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
305
|
+
dimensions: l = Ue,
|
|
306
|
+
disabled: t = !1,
|
|
307
|
+
fieldName: o = "file-uploader",
|
|
308
|
+
imageCompression: d,
|
|
309
|
+
labels: h,
|
|
310
|
+
maxFiles: m = 1,
|
|
311
|
+
maxSizeFile: _ = 0,
|
|
312
|
+
multipleFiles: g = !1,
|
|
313
|
+
onDeleteFiles: U,
|
|
233
314
|
onFilesChange: E,
|
|
234
|
-
onFilesSelected:
|
|
235
|
-
showDownloadButton:
|
|
315
|
+
onFilesSelected: w,
|
|
316
|
+
showDownloadButton: B = !0,
|
|
236
317
|
theme: O,
|
|
237
|
-
updateFiles: A =
|
|
238
|
-
validateDimensions:
|
|
239
|
-
},
|
|
240
|
-
const
|
|
318
|
+
updateFiles: A = ye,
|
|
319
|
+
validateDimensions: N = !1
|
|
320
|
+
}, k) => {
|
|
321
|
+
const u = { ...Ne, ...h }, y = Ae(O), [n, f] = $(null), s = Le({
|
|
241
322
|
acceptFiles: e,
|
|
242
|
-
dimensions:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
323
|
+
dimensions: l,
|
|
324
|
+
imageCompression: d,
|
|
325
|
+
maxFiles: m,
|
|
326
|
+
maxSizeFile: _,
|
|
327
|
+
multipleFiles: g,
|
|
246
328
|
onFilesChange: E,
|
|
247
|
-
onFilesSelected:
|
|
329
|
+
onFilesSelected: w,
|
|
248
330
|
updateFiles: A,
|
|
249
|
-
validateDimensions:
|
|
331
|
+
validateDimensions: N
|
|
250
332
|
});
|
|
251
|
-
return
|
|
252
|
-
|
|
333
|
+
return ae(
|
|
334
|
+
k,
|
|
253
335
|
() => ({
|
|
254
|
-
clear:
|
|
255
|
-
open:
|
|
256
|
-
files: () =>
|
|
336
|
+
clear: s.clear,
|
|
337
|
+
open: s.open,
|
|
338
|
+
files: () => s.items
|
|
257
339
|
}),
|
|
258
|
-
[
|
|
259
|
-
),
|
|
340
|
+
[s.clear, s.items, s.open]
|
|
341
|
+
), z(() => {
|
|
260
342
|
if (!n)
|
|
261
343
|
return;
|
|
262
|
-
const i = (
|
|
263
|
-
|
|
344
|
+
const i = (I) => {
|
|
345
|
+
I.key === "Escape" && f(null);
|
|
264
346
|
};
|
|
265
347
|
return document.addEventListener("keydown", i), () => document.removeEventListener("keydown", i);
|
|
266
|
-
}, [n]),
|
|
267
|
-
n && !
|
|
268
|
-
}, [n,
|
|
348
|
+
}, [n]), z(() => {
|
|
349
|
+
n && !s.items.some((i) => i.id === n.id) && f(null);
|
|
350
|
+
}, [n, s.items]), /* @__PURE__ */ p("section", { className: `file-uploader ${a}`.trim(), style: y, children: [
|
|
269
351
|
/* @__PURE__ */ p(
|
|
270
352
|
"div",
|
|
271
353
|
{
|
|
272
354
|
className: [
|
|
273
355
|
"file-uploader__dropzone",
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
356
|
+
s.items.length > 0 ? "file-uploader__dropzone--active" : "",
|
|
357
|
+
s.isDragging ? "file-uploader__dropzone--dragging" : "",
|
|
358
|
+
t ? "file-uploader__dropzone--disabled" : ""
|
|
277
359
|
].filter(Boolean).join(" "),
|
|
278
|
-
onDrop:
|
|
279
|
-
onDragOver:
|
|
280
|
-
onDragLeave:
|
|
360
|
+
onDrop: t ? void 0 : s.onDrop,
|
|
361
|
+
onDragOver: t ? void 0 : s.onDragOver,
|
|
362
|
+
onDragLeave: t ? void 0 : s.onDragLeave,
|
|
281
363
|
children: [
|
|
282
|
-
/* @__PURE__ */ r("div", { className: "file-uploader__info", children:
|
|
283
|
-
/* @__PURE__ */ r("span", { className: "file-uploader__main-icon", children: /* @__PURE__ */ r(
|
|
364
|
+
/* @__PURE__ */ r("div", { className: "file-uploader__info", children: s.canAddFiles ? /* @__PURE__ */ p(x, { children: [
|
|
365
|
+
/* @__PURE__ */ r("span", { className: "file-uploader__main-icon", children: /* @__PURE__ */ r(Ee, {}) }),
|
|
284
366
|
/* @__PURE__ */ p("div", { children: [
|
|
285
|
-
/* @__PURE__ */ r("p", { className: "file-uploader__title", children:
|
|
286
|
-
/* @__PURE__ */ r("p", { className: "file-uploader__hint", children:
|
|
287
|
-
|
|
288
|
-
e.length > 0 && /* @__PURE__ */ r("p", { children:
|
|
289
|
-
|
|
367
|
+
/* @__PURE__ */ r("p", { className: "file-uploader__title", children: u.idleTitle }),
|
|
368
|
+
/* @__PURE__ */ r("p", { className: "file-uploader__hint", children: u.idleHint }),
|
|
369
|
+
_ > 0 && /* @__PURE__ */ r("p", { children: u.maxSize(_) }),
|
|
370
|
+
e.length > 0 && /* @__PURE__ */ r("p", { children: u.allowedFormats(s.acceptedFormats) }),
|
|
371
|
+
N && /* @__PURE__ */ r("p", { children: u.imageDimensions(l.width, l.height) })
|
|
290
372
|
] })
|
|
291
373
|
] }) : /* @__PURE__ */ p("div", { children: [
|
|
292
|
-
/* @__PURE__ */ r("span", { className: "file-uploader__success-mark", children: /* @__PURE__ */ r(
|
|
293
|
-
/* @__PURE__ */ r("p", { className: "file-uploader__title", children:
|
|
374
|
+
/* @__PURE__ */ r("span", { className: "file-uploader__success-mark", children: /* @__PURE__ */ r(G, { approved: !0 }) }),
|
|
375
|
+
/* @__PURE__ */ r("p", { className: "file-uploader__title", children: u.limitReached })
|
|
294
376
|
] }) }),
|
|
295
377
|
/* @__PURE__ */ r(
|
|
296
378
|
"input",
|
|
297
379
|
{
|
|
298
|
-
ref:
|
|
380
|
+
ref: s.inputRef,
|
|
299
381
|
type: "file",
|
|
300
|
-
id:
|
|
301
|
-
name:
|
|
382
|
+
id: o,
|
|
383
|
+
name: o,
|
|
302
384
|
className: "file-uploader__input",
|
|
303
|
-
onChange:
|
|
385
|
+
onChange: s.handleFiles,
|
|
304
386
|
accept: e.join(","),
|
|
305
|
-
multiple:
|
|
306
|
-
disabled:
|
|
387
|
+
multiple: g,
|
|
388
|
+
disabled: t
|
|
307
389
|
}
|
|
308
390
|
),
|
|
309
|
-
|
|
391
|
+
s.canAddFiles && /* @__PURE__ */ r(
|
|
310
392
|
"button",
|
|
311
393
|
{
|
|
312
394
|
type: "button",
|
|
313
395
|
className: "file-uploader__browse",
|
|
314
|
-
onClick:
|
|
315
|
-
disabled:
|
|
316
|
-
children:
|
|
396
|
+
onClick: s.open,
|
|
397
|
+
disabled: t,
|
|
398
|
+
children: g ? u.browseFiles : u.browseFile
|
|
317
399
|
}
|
|
318
400
|
),
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
return /* @__PURE__ */ r(
|
|
401
|
+
s.items.length > 0 && /* @__PURE__ */ r("div", { className: "file-uploader__list", children: s.items.map((i) => {
|
|
402
|
+
const I = B && i.approve && ce(i.file);
|
|
403
|
+
return /* @__PURE__ */ r(te, { children: /* @__PURE__ */ p(
|
|
322
404
|
"div",
|
|
323
405
|
{
|
|
324
406
|
className: [
|
|
@@ -326,17 +408,17 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
326
408
|
i.approve ? "file-uploader__item--success" : "file-uploader__item--failed"
|
|
327
409
|
].join(" "),
|
|
328
410
|
children: [
|
|
329
|
-
/* @__PURE__ */ r("span", { className: "file-uploader__status", children: /* @__PURE__ */ r(
|
|
411
|
+
/* @__PURE__ */ r("span", { className: "file-uploader__status", children: /* @__PURE__ */ r(G, { approved: i.approve }) }),
|
|
330
412
|
i.previewUrl && /* @__PURE__ */ p(
|
|
331
413
|
"button",
|
|
332
414
|
{
|
|
333
415
|
type: "button",
|
|
334
416
|
className: "file-uploader__preview-trigger",
|
|
335
|
-
onClick: () =>
|
|
336
|
-
"aria-label": `${
|
|
337
|
-
title:
|
|
417
|
+
onClick: () => f(i),
|
|
418
|
+
"aria-label": `${u.previewFile}: ${i.file.name}`,
|
|
419
|
+
title: u.previewFile,
|
|
338
420
|
children: [
|
|
339
|
-
|
|
421
|
+
R(i.file) && /* @__PURE__ */ r(
|
|
340
422
|
"img",
|
|
341
423
|
{
|
|
342
424
|
className: "file-uploader__thumbnail file-uploader__thumbnail--image",
|
|
@@ -344,7 +426,7 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
344
426
|
alt: ""
|
|
345
427
|
}
|
|
346
428
|
),
|
|
347
|
-
|
|
429
|
+
P(i.file) && /* @__PURE__ */ p(x, { children: [
|
|
348
430
|
/* @__PURE__ */ r(
|
|
349
431
|
"video",
|
|
350
432
|
{
|
|
@@ -354,27 +436,27 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
354
436
|
muted: !0
|
|
355
437
|
}
|
|
356
438
|
),
|
|
357
|
-
/* @__PURE__ */ r("span", { className: "file-uploader__preview-badge", children: /* @__PURE__ */ r(
|
|
439
|
+
/* @__PURE__ */ r("span", { className: "file-uploader__preview-badge", children: /* @__PURE__ */ r(ze, {}) })
|
|
358
440
|
] }),
|
|
359
|
-
|
|
441
|
+
j(i.file) && /* @__PURE__ */ r("span", { className: "file-uploader__media-placeholder", children: /* @__PURE__ */ r(q, {}) })
|
|
360
442
|
]
|
|
361
443
|
}
|
|
362
444
|
),
|
|
363
|
-
!i.previewUrl && /* @__PURE__ */ r("span", { className: "file-uploader__file-icon", children: /* @__PURE__ */ r(
|
|
445
|
+
!i.previewUrl && /* @__PURE__ */ r("span", { className: "file-uploader__file-icon", children: /* @__PURE__ */ r(Ie, {}) }),
|
|
364
446
|
/* @__PURE__ */ p("div", { className: "file-uploader__file-info", children: [
|
|
365
447
|
/* @__PURE__ */ r("p", { className: "file-uploader__name", children: i.file.name }),
|
|
366
|
-
/* @__PURE__ */ r("p", { className: "file-uploader__size", children:
|
|
448
|
+
/* @__PURE__ */ r("p", { className: "file-uploader__size", children: Z(i.file.size) })
|
|
367
449
|
] }),
|
|
368
450
|
/* @__PURE__ */ p("div", { className: "file-uploader__actions", children: [
|
|
369
|
-
|
|
451
|
+
I && /* @__PURE__ */ r(
|
|
370
452
|
"button",
|
|
371
453
|
{
|
|
372
454
|
type: "button",
|
|
373
455
|
className: "file-uploader__icon-button",
|
|
374
|
-
onClick: () =>
|
|
375
|
-
"aria-label":
|
|
376
|
-
title:
|
|
377
|
-
children: /* @__PURE__ */ r(
|
|
456
|
+
onClick: () => Me(i.file),
|
|
457
|
+
"aria-label": u.downloadFile,
|
|
458
|
+
title: u.downloadFile,
|
|
459
|
+
children: /* @__PURE__ */ r(De, {})
|
|
378
460
|
}
|
|
379
461
|
),
|
|
380
462
|
/* @__PURE__ */ r(
|
|
@@ -383,14 +465,14 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
383
465
|
type: "button",
|
|
384
466
|
className: "file-uploader__icon-button file-uploader__icon-button--danger",
|
|
385
467
|
onClick: () => {
|
|
386
|
-
(n == null ? void 0 : n.id) === i.id &&
|
|
387
|
-
|
|
468
|
+
(n == null ? void 0 : n.id) === i.id && f(null), s.removeFile(i), U == null || U(
|
|
469
|
+
s.items.filter((M) => M.id !== i.id && M.approve),
|
|
388
470
|
i
|
|
389
471
|
);
|
|
390
472
|
},
|
|
391
|
-
"aria-label":
|
|
392
|
-
title:
|
|
393
|
-
children: /* @__PURE__ */ r(
|
|
473
|
+
"aria-label": u.removeFile,
|
|
474
|
+
title: u.removeFile,
|
|
475
|
+
children: /* @__PURE__ */ r(Fe, {})
|
|
394
476
|
}
|
|
395
477
|
)
|
|
396
478
|
] })
|
|
@@ -398,7 +480,7 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
398
480
|
}
|
|
399
481
|
) }, i.id);
|
|
400
482
|
}) }),
|
|
401
|
-
|
|
483
|
+
g && /* @__PURE__ */ r("p", { className: "file-uploader__counter", children: u.selectedCount(s.approvedItems.length, m) })
|
|
402
484
|
]
|
|
403
485
|
}
|
|
404
486
|
),
|
|
@@ -408,30 +490,30 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
408
490
|
className: "file-uploader__modal",
|
|
409
491
|
role: "dialog",
|
|
410
492
|
"aria-modal": "true",
|
|
411
|
-
"aria-label": `${
|
|
493
|
+
"aria-label": `${u.previewFile}: ${n.file.name}`,
|
|
412
494
|
onMouseDown: (i) => {
|
|
413
|
-
i.currentTarget === i.target &&
|
|
495
|
+
i.currentTarget === i.target && f(null);
|
|
414
496
|
},
|
|
415
497
|
children: /* @__PURE__ */ p("div", { className: "file-uploader__modal-panel", children: [
|
|
416
498
|
/* @__PURE__ */ p("div", { className: "file-uploader__modal-header", children: [
|
|
417
499
|
/* @__PURE__ */ p("div", { children: [
|
|
418
500
|
/* @__PURE__ */ r("p", { className: "file-uploader__modal-title", children: n.file.name }),
|
|
419
|
-
/* @__PURE__ */ r("p", { className: "file-uploader__modal-meta", children:
|
|
501
|
+
/* @__PURE__ */ r("p", { className: "file-uploader__modal-meta", children: Z(n.file.size) })
|
|
420
502
|
] }),
|
|
421
503
|
/* @__PURE__ */ r(
|
|
422
504
|
"button",
|
|
423
505
|
{
|
|
424
506
|
type: "button",
|
|
425
507
|
className: "file-uploader__icon-button",
|
|
426
|
-
onClick: () =>
|
|
427
|
-
"aria-label":
|
|
428
|
-
title:
|
|
429
|
-
children: /* @__PURE__ */ r(
|
|
508
|
+
onClick: () => f(null),
|
|
509
|
+
"aria-label": u.closePreview,
|
|
510
|
+
title: u.closePreview,
|
|
511
|
+
children: /* @__PURE__ */ r(Re, {})
|
|
430
512
|
}
|
|
431
513
|
)
|
|
432
514
|
] }),
|
|
433
515
|
/* @__PURE__ */ p("div", { className: "file-uploader__modal-content", children: [
|
|
434
|
-
|
|
516
|
+
R(n.file) && /* @__PURE__ */ r(
|
|
435
517
|
"img",
|
|
436
518
|
{
|
|
437
519
|
className: "file-uploader__modal-image",
|
|
@@ -439,7 +521,7 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
439
521
|
alt: n.file.name
|
|
440
522
|
}
|
|
441
523
|
),
|
|
442
|
-
|
|
524
|
+
P(n.file) && /* @__PURE__ */ r(
|
|
443
525
|
"video",
|
|
444
526
|
{
|
|
445
527
|
className: "file-uploader__modal-video",
|
|
@@ -448,8 +530,8 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
448
530
|
preload: "metadata"
|
|
449
531
|
}
|
|
450
532
|
),
|
|
451
|
-
|
|
452
|
-
/* @__PURE__ */ r(
|
|
533
|
+
j(n.file) && /* @__PURE__ */ p("div", { className: "file-uploader__modal-audio", children: [
|
|
534
|
+
/* @__PURE__ */ r(q, {}),
|
|
453
535
|
/* @__PURE__ */ r("audio", { src: n.previewUrl, controls: !0, preload: "metadata" })
|
|
454
536
|
] })
|
|
455
537
|
] })
|
|
@@ -459,23 +541,24 @@ const ae = ["png", "webp", "jpeg", "jpg", "svg"], le = ["mp3", "wav", "ogg", "mp
|
|
|
459
541
|
] });
|
|
460
542
|
}
|
|
461
543
|
);
|
|
462
|
-
|
|
463
|
-
const
|
|
544
|
+
K.displayName = "ReactFileUploader";
|
|
545
|
+
const Be = K;
|
|
464
546
|
export {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
547
|
+
oe as DEFAULT_AUDIO_FORMATS,
|
|
548
|
+
le as DEFAULT_IMAGE_FORMATS,
|
|
549
|
+
ie as DEFAULT_VIDEO_FORMATS,
|
|
550
|
+
Be as FileUploader,
|
|
551
|
+
K as ReactFileUploader,
|
|
552
|
+
Z as bytesToSize,
|
|
553
|
+
K as default,
|
|
554
|
+
F as getFileExtension,
|
|
555
|
+
ne as getReadableAcceptedFormats,
|
|
556
|
+
j as isAudioFile,
|
|
475
557
|
ce as isDocumentFile,
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
558
|
+
R as isImageFile,
|
|
559
|
+
C as isPreviewableFile,
|
|
560
|
+
P as isVideoFile,
|
|
561
|
+
fe as matchesAcceptedType,
|
|
562
|
+
me as optimizeImageFile,
|
|
563
|
+
Le as useFileUploader
|
|
481
564
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { FileUploader, ReactFileUploader, ReactFileUploader as default } from './FileUploader';
|
|
2
2
|
export { useFileUploader } from './useFileUploader';
|
|
3
|
-
export { DEFAULT_IMAGE_FORMATS, DEFAULT_AUDIO_FORMATS, DEFAULT_VIDEO_FORMATS, bytesToSize, getFileExtension, getReadableAcceptedFormats, isAudioFile, isDocumentFile, isImageFile, isPreviewableFile, isVideoFile, matchesAcceptedType, } from './utils';
|
|
4
|
-
export type { FileUploaderHandle, FileUploaderItem, FileUploaderLabels, FileUploaderProps, FileUploaderRejectionReason, FileUploaderStatus, } from './types';
|
|
3
|
+
export { DEFAULT_IMAGE_FORMATS, DEFAULT_AUDIO_FORMATS, DEFAULT_VIDEO_FORMATS, bytesToSize, getFileExtension, getReadableAcceptedFormats, isAudioFile, isDocumentFile, isImageFile, isPreviewableFile, isVideoFile, matchesAcceptedType, optimizeImageFile, } from './utils';
|
|
4
|
+
export type { FileUploaderHandle, FileUploaderItem, FileUploaderLabels, FileUploaderProps, FileUploaderRejectionReason, FileUploaderStatus, ImageCompressionMode, ImageCompressionOptions, } from './types';
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ChangeEvent, CSSProperties, DragEvent, ReactNode } from 'react';
|
|
2
2
|
export type FileUploaderStatus = "approved" | "rejected";
|
|
3
3
|
export type FileUploaderRejectionReason = "file-size" | "file-type" | "image-dimensions";
|
|
4
|
+
export type ImageCompressionMode = "lossless" | "balanced";
|
|
5
|
+
export type ImageCompressionOptions = {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
mode?: ImageCompressionMode;
|
|
8
|
+
quality?: number;
|
|
9
|
+
};
|
|
4
10
|
export type FileUploaderLabels = {
|
|
5
11
|
idleTitle: ReactNode;
|
|
6
12
|
idleHint: ReactNode;
|
|
@@ -19,10 +25,17 @@ export type FileUploaderLabels = {
|
|
|
19
25
|
export type FileUploaderItem = {
|
|
20
26
|
id: string;
|
|
21
27
|
file: File;
|
|
28
|
+
originalFile?: File;
|
|
22
29
|
status: FileUploaderStatus;
|
|
23
30
|
approve: boolean;
|
|
24
31
|
reasons: FileUploaderRejectionReason[];
|
|
25
32
|
previewUrl?: string;
|
|
33
|
+
compression?: {
|
|
34
|
+
compressed: boolean;
|
|
35
|
+
originalSize: number;
|
|
36
|
+
compressedSize: number;
|
|
37
|
+
mode: ImageCompressionMode;
|
|
38
|
+
};
|
|
26
39
|
};
|
|
27
40
|
export type FileUploaderTheme = {
|
|
28
41
|
accent?: string;
|
|
@@ -64,6 +77,7 @@ export type FileUploaderProps = {
|
|
|
64
77
|
};
|
|
65
78
|
disabled?: boolean;
|
|
66
79
|
fieldName?: string;
|
|
80
|
+
imageCompression?: boolean | ImageCompressionOptions;
|
|
67
81
|
labels?: Partial<FileUploaderLabels>;
|
|
68
82
|
maxFiles?: number;
|
|
69
83
|
maxSizeFile?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChangeEvent, DragEvent } from 'react';
|
|
2
2
|
import { FileUploaderItem, FileUploaderProps } from './types';
|
|
3
|
-
export declare const useFileUploader: ({ acceptFiles, dimensions, maxFiles, maxSizeFile, multipleFiles, updateFiles, validateDimensions, onFilesChange, onFilesSelected, }: Pick<FileUploaderProps, "acceptFiles" | "dimensions" | "maxFiles" | "maxSizeFile" | "multipleFiles" | "onFilesChange" | "onFilesSelected" | "updateFiles" | "validateDimensions">) => {
|
|
3
|
+
export declare const useFileUploader: ({ acceptFiles, dimensions, imageCompression, maxFiles, maxSizeFile, multipleFiles, updateFiles, validateDimensions, onFilesChange, onFilesSelected, }: Pick<FileUploaderProps, "acceptFiles" | "dimensions" | "imageCompression" | "maxFiles" | "maxSizeFile" | "multipleFiles" | "onFilesChange" | "onFilesSelected" | "updateFiles" | "validateDimensions">) => {
|
|
4
4
|
acceptedFormats: string[];
|
|
5
5
|
approvedItems: FileUploaderItem[];
|
|
6
6
|
canAddFiles: boolean;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileUploaderItem } from './types';
|
|
1
|
+
import { FileUploaderItem, ImageCompressionMode, ImageCompressionOptions } from './types';
|
|
2
2
|
export declare const DEFAULT_IMAGE_FORMATS: string[];
|
|
3
3
|
export declare const DEFAULT_AUDIO_FORMATS: string[];
|
|
4
4
|
export declare const DEFAULT_VIDEO_FORMATS: string[];
|
|
@@ -10,6 +10,12 @@ export declare const isAudioFile: (file: File) => boolean;
|
|
|
10
10
|
export declare const isVideoFile: (file: File) => boolean;
|
|
11
11
|
export declare const isPreviewableFile: (file: File) => boolean;
|
|
12
12
|
export declare const isDocumentFile: (file: File) => boolean;
|
|
13
|
+
export declare const optimizeImageFile: (file: File, imageCompression?: boolean | ImageCompressionOptions) => Promise<{
|
|
14
|
+
file: File;
|
|
15
|
+
originalFile: File;
|
|
16
|
+
compressed: boolean;
|
|
17
|
+
mode: ImageCompressionMode;
|
|
18
|
+
}>;
|
|
13
19
|
export declare const matchesAcceptedType: (file: File, acceptFiles: string[]) => boolean;
|
|
14
20
|
export declare const validateImageDimensions: (file: File, dimensions: {
|
|
15
21
|
width: number;
|
|
@@ -21,6 +27,7 @@ export declare const createUploaderItem: (file: File, options: {
|
|
|
21
27
|
width: number;
|
|
22
28
|
height: number;
|
|
23
29
|
};
|
|
30
|
+
imageCompression?: boolean | ImageCompressionOptions;
|
|
24
31
|
maxSizeFile: number;
|
|
25
32
|
validateDimensions: boolean;
|
|
26
33
|
}) => Promise<FileUploaderItem>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunuenm23/react-file-uploader",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Advanced React file uploader component with media previews, document downloads, and no UI framework dependency.",
|
|
5
|
+
"homepage": "https://moncadayunuen.github.io/react_fileuploader/",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/moncadayunuen/react_fileuploader.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/moncadayunuen/react_fileuploader/issues"
|
|
12
|
+
},
|
|
5
13
|
"type": "module",
|
|
6
14
|
"main": "./dist/index.cjs",
|
|
7
15
|
"module": "./dist/index.js",
|