@s_mart/dropzone 10.0.2 → 11.0.1
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/dist/index.d.mts +10 -5
- package/dist/index.mjs +7 -82
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { HTMLAttributes, HtmlHTMLAttributes } from 'react';
|
|
3
|
+
import { Theme, ButtonProps, TypographyProps } from '@mui/material';
|
|
3
4
|
import { StyledComponent } from '@emotion/styled';
|
|
4
5
|
import { MUIStyledCommonProps } from '@mui/system';
|
|
5
|
-
import { HtmlHTMLAttributes, LabelHTMLAttributes, HTMLAttributes } from 'react';
|
|
6
6
|
import { FileValidated } from '@dropzone-ui/react';
|
|
7
7
|
import { DropzoneProps } from '@dropzone-ui/react/build/components/dropzone/components/Dropzone/DropzoneProps';
|
|
8
8
|
import { FileItemProps } from '@dropzone-ui/react/build/components/file-item/components/FileItem/FileItemProps';
|
|
@@ -10,9 +10,11 @@ import { FileItemProps } from '@dropzone-ui/react/build/components/file-item/com
|
|
|
10
10
|
type DropzoneComponent<Element extends HTMLAttributes<unknown>, Props extends Record<string, unknown> = Record<string, unknown>> = StyledComponent<MUIStyledCommonProps<Theme>, Element, Props>;
|
|
11
11
|
declare const DropzoneRoot: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>>;
|
|
12
12
|
declare const DropzoneOverlay: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>, DropzoneOverlayAttrs>;
|
|
13
|
-
declare const DropzoneLabelContainer: DropzoneComponent<
|
|
14
|
-
declare const
|
|
13
|
+
declare const DropzoneLabelContainer: DropzoneComponent<ButtonProps, DropzoneLabelContainerAttrs>;
|
|
14
|
+
declare const DropzoneFilesContainer: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>>;
|
|
15
15
|
declare const DropzoneListItem: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>>;
|
|
16
|
+
declare const DropzoneFilesListRoot: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>>;
|
|
17
|
+
declare const DropzoneFilesListContainer: DropzoneComponent<HtmlHTMLAttributes<HTMLDivElement>>;
|
|
16
18
|
|
|
17
19
|
type DropzoneHeaderTitleSlotProps = {
|
|
18
20
|
headerTitle?: DropzoneHeaderTitleBaseProps & TypographyProps;
|
|
@@ -30,12 +32,15 @@ type DropzoneV2SlotProps = Partial<{
|
|
|
30
32
|
root: Parameters<typeof DropzoneRoot>[0];
|
|
31
33
|
overlay: Parameters<typeof DropzoneOverlay>[0];
|
|
32
34
|
labelContainer: Parameters<typeof DropzoneLabelContainer>[0];
|
|
33
|
-
|
|
35
|
+
filesContainer: Parameters<typeof DropzoneFilesContainer>[0];
|
|
36
|
+
filesListRoot: Parameters<typeof DropzoneFilesListRoot>[0];
|
|
37
|
+
filesListContainer: Parameters<typeof DropzoneFilesListContainer>[0];
|
|
34
38
|
listItem: Parameters<typeof DropzoneListItem>[0];
|
|
35
39
|
header: DropzoneHeaderTitleSlotProps;
|
|
36
40
|
}>;
|
|
37
41
|
type DropzoneV2Slots = DropzoneHeaderTitleSlots;
|
|
38
42
|
type DropzoneV2Props = Pick<DropzoneHeaderTitleBaseProps, 'showFilesSize'> & {
|
|
43
|
+
files: File[];
|
|
39
44
|
onChange(files: File[]): void;
|
|
40
45
|
/**
|
|
41
46
|
* Permite filtrar os arquivos que são adicionados
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{styled as
|
|
1
|
+
import{Button as be,styled as F,Typography as He}from"@mui/material";import{colorPalette as I}from"@s_mart/tokens";var j=F("div")`
|
|
2
2
|
min-width: 300px;
|
|
3
3
|
align-items: center;
|
|
4
4
|
display: flex;
|
|
@@ -6,7 +6,7 @@ import{styled as P}from"@mui/material";import{colorPalette as B}from"@s_mart/tok
|
|
|
6
6
|
justify-content: center;
|
|
7
7
|
gap: 8px;
|
|
8
8
|
padding: 16px;
|
|
9
|
-
`,
|
|
9
|
+
`,G=F("div")`
|
|
10
10
|
display: none;
|
|
11
11
|
position: absolute;
|
|
12
12
|
z-index: 20;
|
|
@@ -14,7 +14,7 @@ import{styled as P}from"@mui/material";import{colorPalette as B}from"@s_mart/tok
|
|
|
14
14
|
left: 0;
|
|
15
15
|
height: 0;
|
|
16
16
|
width: 0;
|
|
17
|
-
border: 0px dashed ${
|
|
17
|
+
border: 0px dashed ${I.neutral[500]};
|
|
18
18
|
border-radius: 8px;
|
|
19
19
|
display: flex;
|
|
20
20
|
justify-content: center;
|
|
@@ -27,82 +27,7 @@ import{styled as P}from"@mui/material";import{colorPalette as B}from"@s_mart/tok
|
|
|
27
27
|
width: 99.3%;
|
|
28
28
|
border-width: 2px;
|
|
29
29
|
}
|
|
30
|
-
`,Q=P("label")`
|
|
31
|
-
width: 100%;
|
|
32
|
-
pointer-events: all;
|
|
33
|
-
min-height: 40px;
|
|
34
|
-
height: 60px;
|
|
35
|
-
background-color: ${({theme:e})=>e.palette.primary.main};
|
|
36
|
-
border-radius: 16px;
|
|
37
|
-
display: flex;
|
|
38
|
-
flex-direction: column;
|
|
39
|
-
justify-content: center;
|
|
40
|
-
align-items: center;
|
|
41
|
-
gap: 8px;
|
|
42
|
-
padding: .5rem 1rem ;
|
|
43
|
-
|
|
44
|
-
cursor: pointer;
|
|
45
|
-
transition: all 0.5s ease;
|
|
46
|
-
|
|
47
|
-
&[data-max-files='1'] {
|
|
48
|
-
min-height: 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
&[data-has-files='true']{
|
|
52
|
-
height: 40px;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Se tiver arquivos e o máximo de arquivos for 1
|
|
56
|
-
&[data-has-files='true'][data-max-files='1'] {
|
|
57
|
-
height: 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
&[data-has-files='true'] #dropzone-upload-info {
|
|
61
|
-
display: none;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Se não tiver arquivos || tiver maximo de arquivos == 1 aplica no #dropzone-upload-more-label
|
|
66
|
-
&:not([data-has-files='true']) #dropzone-upload-more-label,
|
|
67
|
-
&[data-max-files='1'] #dropzone-upload-more-label{
|
|
68
|
-
display: none;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
& #dropzone-upload-more-label {
|
|
73
|
-
pointer-events: all;
|
|
74
|
-
color: white;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Se estiver processando zip, aplica no root e no #dropzone-upload-more-label
|
|
79
|
-
&[data-is-processing-zip='true'],
|
|
80
|
-
&[data-is-processing-zip='true'] #dropzone-upload-more-label {
|
|
81
|
-
pointer-events: none;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
&:hover {
|
|
85
|
-
background-color: ${({theme:e})=>e.palette.primary.dark};
|
|
86
|
-
}
|
|
87
|
-
`,J=P("div")`
|
|
88
|
-
width: 100%;
|
|
89
|
-
max-height: 300px;
|
|
90
|
-
background-color: ${B.neutral[20]};
|
|
91
|
-
border-radius: 16px;
|
|
92
|
-
overflow-y: auto;
|
|
93
|
-
display: flex;
|
|
94
|
-
flex-direction: column;
|
|
95
|
-
border: 8px solid ${B.neutral[20]};
|
|
96
|
-
gap: 8px;
|
|
97
|
-
`,W=P("div")`
|
|
98
|
-
background-color: white;
|
|
99
|
-
border-radius: 16px;
|
|
100
|
-
padding: 8px;
|
|
101
|
-
gap: 8px;
|
|
102
|
-
display: flex;
|
|
103
|
-
align-items: center;
|
|
104
|
-
justify-content: space-between;
|
|
105
|
-
`;import{Tooltip as Ve,Typography as ie}from"@mui/material";import{IconButton as Oe,LIcon as ae}from"@s_mart/core";import{lineTimes as Xe}from"@s_mart/regular-icons";import{colorPalette as le}from"@s_mart/tokens";import{useMemo as ee}from"react";import{lineFile as Ce,linePicture as Le,lineXMLFile as we}from"@s_mart/light-icons";import{lineFileCertificate as Pe}from"@s_mart/regular-icons";var Y=e=>{switch(e){case"application/xml":case"text/xml":return we;case"image/gif":case"image/jpeg":case"image/png":case"image/svg":case"image/webp":return Le;case"application/pkcs12":return Pe;default:return Ce}},H=e=>{let t="";return e<1024?t=`${e} Bytes`:e<1024*1024?t=`${(e/1024).toFixed(2)} KB`:e<1024*1024*1024&&(t=`${(e/1024/1024).toFixed(2)} MB`),t};var oe=({filesInfo:e})=>{let t=ee(()=>e.map(o=>({name:o.name,fileSize:H(o.size),icon:Y(o.type)})),[e]),r=ee(()=>({totalSize:H(e.reduce((o,n)=>o+n.size,0)),totalFilesLabel:e.length===1?"1 arquivo":`${e.length} arquivos`}),[e]);return{files:t,headerInfo:r}};import{Tooltip as He}from"@mui/material";import q from"@mui/utils/deepmerge";import{IconButton as Se,LIcon as Ee}from"@s_mart/core";import{lineTimes as Me}from"@s_mart/regular-icons";import{jsx as O}from"react/jsx-runtime";var U={headerCleartooltip:{title:"Remover todos"},headerClearIconButton:{variant:"text",color:"neutral",sx:{borderRadius:50}},headerClearLicon:{icon:Me,removeMargin:!0}},V={clone:!1},te=({onClick:e,slotProps:t})=>{let r=q(U.headerCleartooltip,t?.headerCleartooltip,V),o=q(U.headerClearIconButton,t?.headerClearIconButton,V),n=q(U.headerClearLicon,t?.headerClearLicon,V);return O(He,{...r,children:O(Se,{...o,onClick:e,children:O(Ee,{...n})})})};import{styled as Ie}from"@mui/material";var re=Ie("div")({display:"flex",justifyContent:"space-between",alignItems:"center",paddingBlock:"0.5rem"});import{Typography as Re}from"@mui/material";import Ae from"@mui/utils/deepmerge";import{useMemo as ke}from"react";import{Fragment as Ue,jsx as R}from"react/jsx-runtime";var $e={headerTitle:{variant:"titleXXS"}},Be={headerTitleContent:e=>R(qe,{...e})},qe=e=>{let t=`${e.filesLengthLabel}`;return e.showFilesSize&&(t+=` - ${e.filesTotalSize}`),R(Ue,{children:t})},ne=e=>{let t=e.slots?.headerTitleContent??Be.headerTitleContent,r=ke(()=>Ae($e.headerTitle,{...e,...e.slotProps?.headerTitle}),[e.filesLengthLabel,e.filesTotalSize,e]);return R(Re,{...r,children:R(t,{...r})})};var A={Container:re,Title:ne,ClearButton:te};import{jsx as y,jsxs as X}from"react/jsx-runtime";var se=({filesInfo:e,onRemoveFile:t,onRemoveAllFiles:r,slotProps:o,slots:n,showFilesSize:p})=>{let{files:d,headerInfo:a}=oe({filesInfo:e});return d.length===0?null:X(J,{...o?.listContainer,children:[X(A.Container,{children:[y(A.Title,{slots:n,slotProps:o?.header,filesLengthLabel:a.totalFilesLabel,filesTotalSize:a.totalSize,showFilesSize:p}),y(A.ClearButton,{onClick:r})]}),d.map((l,u)=>y(Ve,{title:l.name,children:X(W,{...o?.listItem,children:[y(ae,{icon:l.icon,removeMargin:!0,size:"24px"}),p&&y(ie,{variant:"titleXXS",color:le.neutral[600],whiteSpace:"nowrap",children:l.fileSize}),y(ie,{variant:"titleXXS",sx:{color:le.neutral[600],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"center"},children:l.name}),y(Oe,{variant:"text",color:"neutral",sx:{borderRadius:50},onClick:()=>t(u),children:y(ae,{icon:Xe,removeMargin:!0})})]})},`${l.name}-${u}`))]})};import{CircularProgress as pe,Stack as Z,Typography as k}from"@mui/material";import{LIcon as Ze}from"@s_mart/core";import{lineFileUpload as _e}from"@s_mart/regular-icons";import{jsx as b,jsxs as S}from"react/jsx-runtime";var de=({placeholder:e,isProcessingZip:t})=>t?S("div",{children:[S(Z,{id:"dropzone-upload-info",sx:{gap:1,alignItems:"center",direction:"row"},children:[b(pe,{sx:{color:"white"},size:24}),b(k,{variant:"titleSM",color:"white",children:"Descompactando zip..."})]}),S(Z,{id:"dropzone-upload-more-label",sx:{gap:1,alignItems:"center",direction:"row"},children:[b(pe,{sx:{color:"white"},size:12}),b(k,{variant:"bodySM",sx:{fontWeight:700},children:"Descompactando zip..."})]})]}):S("div",{children:[S(Z,{id:"dropzone-upload-info",sx:{gap:1,alignItems:"center",direction:"row"},children:[b(Ze,{icon:_e,size:"48px",color:"white",removeMargin:!0}),b(k,{variant:"titleSM",color:"white",children:e})]}),b(k,{id:"dropzone-upload-more-label",variant:"bodySM",sx:{fontWeight:700},children:"Carregar mais arquivos"})]});import{useCallback as E,useEffect as Qe,useMemo as Je,useRef as me,useState as G}from"react";var ce=async(e,t)=>{let r=[];for(let o of e.items){if(o.kind!=="file")continue;if(typeof o.webkitGetAsEntry=="function"){let p=o.webkitGetAsEntry();if(p===null)continue;let d=await je(p);r.push(...d);continue}let n=o.getAsFile();n&&r.push(n)}return t!==void 0&&(r=Ne(r,t)),r},je=e=>new Promise((t,r)=>{let o=0,n=[];p(e);function p(a){Ke(a)?(o++,a.file(l=>{o--,n.push(l),o===0&&t(n)})):Ge(a)&&d(a.createReader())}function d(a){o++,a.readEntries(function(l){o--;for(let u of l)p(u);o===0&&t(n)})}}),Ge=e=>e.isDirectory,Ke=e=>e.isFile,Ne=(e,t)=>{let r=[],o=t.split(",");for(let n of e){let p=`.${n.name.split(".").pop()?.toLowerCase()}`;o.includes(p)&&r.push(n)}return r};var _=e=>{e.stopPropagation(),e.preventDefault()},j=e=>{e.dataTransfer.dropEffect="link",_(e)};var ue=({onChange:e,filterOnDrop:t,maxSize:r,maxFiles:o,accept:n,onError:p,onWarning:d})=>{let[a,l]=G([]),[u,z]=G(!1),[C,L]=G(!1),x=me(null),s=me(!1),h=E(async i=>{L(!0);let m=[],{BlobReader:g,BlobWriter:f,ZipReader:M}=await import("@zip.js/zip.js").catch(()=>{throw new Error("Fa\xE7a a instala\xE7\xE3o da biblioteca @zip.js/zip.js para utilizar o Dropzone.")}),w=new g(i),D=new M(w);try{let T=await D.getEntries();for(let I of T){if(I.directory||I.getData===void 0)continue;let Te=await I.getData(new f),be=new File([Te],I.filename);m.push(be)}}catch(T){p?.("Ocorreu um erro ao processar o arquivo compactado.",T)}finally{L(!1),await D.close()}return m},[p]),c=E(async i=>{if(!n)return i;let m=[];for(let g of i){let f=`.${g.name.split(".").pop()?.toLocaleLowerCase()}`;if(!n.split(",").includes(f)){d?.(`O arquivo "${g.name}" n\xE3o \xE9 valido, extens\xF5es aceitas ${n}`);continue}if(f===".zip"){let w=await h(g);if(!w.length)continue;let D=await c(w);D.length&&m.push(...D);continue}m.push(g)}return m},[n,d,h]),F=E(async i=>{let m=await t?.(i)??i,g=await c(m);l(f=>{if(o!==void 0&&f.length+g.length>o)return d?.(`Quantidade m\xE1xima de arquivos ${o} alcan\xE7ada`),f;if(r!==void 0){let M=f.reduce((D,T)=>D+T.size,0),w=g.reduce((D,T)=>D+T.size,0);if(M+w>r)return d?.(`O arquivo \xE9 muito grande, O tamanho m\xE1ximo permitido \xE9 ${H(r)}`),f}return f!==void 0?[...f,...g]:g}),s.current=!0},[t,o,r,d,c]),De=async i=>{if(i.target.files){let m=[...i.target.files];F(m)}},ye=E(i=>{x.current?.value&&(x.current.value=""),l(m=>m?.filter((g,f)=>f!==i))},[]),ve=E(()=>{x.current?.value&&(x.current.value=""),l([])},[]),xe=Je(()=>a?.map(i=>({size:i.size,type:i.type,name:i.name}))??[],[a]),Fe=n?`${n.toUpperCase()},${n.toLowerCase()}`:void 0;return Qe(()=>{s.current&&e(a)},[a,e]),{inputRef:x,isDragging:u,filesInfo:xe,treatedAccept:Fe,isProcessingZip:C,handleRemoveFile:ye,handleRemoveAllFiles:ve,handleChangeFiles:De,handleDragEnter:i=>{j(i),z(!0)},handleDragLeave:i=>{j(i),z(!1)},handleDrop:async i=>{_(i),z(!1);let m=await ce(i.dataTransfer,n);F(m)}}};import{jsx as $,jsxs as fe}from"react/jsx-runtime";var We=e=>{let{inputRef:t,filesInfo:r,treatedAccept:o,handleChangeFiles:n,handleRemoveFile:p,handleRemoveAllFiles:d,handleDragEnter:a,handleDragLeave:l,handleDrop:u,isDragging:z,isProcessingZip:C}=ue(e),L=e.placeholder??"Pressione para carregar os arquivos";return fe(K,{onDragOver:a,...e.slotProps?.root,children:[$(N,{"data-is-dragging":z,onDrop:u,onDragLeave:l,...e.slotProps?.overlay}),$(se,{filesInfo:r,onRemoveFile:p,onRemoveAllFiles:d,showFilesSize:e.showFilesSize,slotProps:e.slotProps,slots:e.slots}),fe(Q,{htmlFor:"dropzone","data-max-files":e.maxFiles,"data-has-files":!!r.length,"data-is-processing-zip":C,...e.slotProps?.labelContainer,children:[$(de,{placeholder:L,isProcessingZip:C}),$("input",{ref:t,id:"dropzone",type:"file",accept:o,hidden:!0,onChange:n,multiple:e.maxFiles===void 0||e.maxFiles>1})]})]})};import{useEffect as eo,useState as oo}from"react";import{Dropzone as to,FileItem as ro}from"@dropzone-ui/react";import{LIcon as no}from"@s_mart/core";import{Tooltip as io,Typography as ao}from"@mui/material";import{lineTimes as lo}from"@s_mart/regular-icons";import{styled as Ye}from"@mui/material";import{colorPalette as ge}from"@s_mart/tokens";var he=Ye("button")`
|
|
30
|
+
`,K=F(be)(({theme:e})=>({width:"100%",pointerEvents:"all",minHeight:"40px",backgroundColor:e.palette.primary.main,borderRadius:Number.parseFloat(e.shape.borderRadius.toString())*2,display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"8px",padding:".5rem 1rem",cursor:"pointer",transition:"all 0.5s ease",'&[data-max-files="1"]':{minHeight:0},'&[data-has-files="true"]':{height:"40px"},'&[data-has-files="true"][data-max-files="1"]':{height:0},'&[data-has-files="true"] #dropzone-upload-info':{display:"none"},'&:not([data-has-files="true"]) #dropzone-upload-more-label, &[data-max-files="1"] #dropzone-upload-more-label':{display:"none"},"& #dropzone-upload-more-label":{pointerEvents:"all",color:"white"},'&[data-is-processing-zip="true"], &[data-is-processing-zip="true"] #dropzone-upload-more-label':{pointerEvents:"none"},"&:hover":{backgroundColor:({theme:t})=>t.palette.primary.dark}})),Q=F("div")(({theme:e})=>({width:"100%",maxHeight:"300px",backgroundColor:I.neutral[20],borderRadius:Number.parseFloat(e.shape.borderRadius.toString())*2,display:"flex",flexDirection:"column",border:`1px solid ${I.neutral[20]}`,padding:"8px",gap:"8px"})),Y=F("div")({backgroundColor:"white",borderRadius:"16px",padding:"8px",gap:"24px",display:"grid",gridTemplateColumns:"min-content min-content 1fr min-content",alignItems:"center",justifyContent:"space-between"}),J=F("div")({height:300,overflow:"auto"}),W=F("div")({position:"relative",width:"100%"}),ee=F("div")({top:0,left:0,width:"100%",position:"absolute",paddingBottom:"8px",boxSizing:"border-box"}),oe=F(He)({color:I.neutral[600],overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"start"});import{Tooltip as Ze,Typography as Ne}from"@mui/material";import{IconButton as _e,LIcon as se}from"@s_mart/core";import{lineTimes as je}from"@s_mart/regular-icons";import{colorPalette as Ge}from"@s_mart/tokens";import{useMemo as re}from"react";import{lineFile as we,linePicture as Pe,lineXMLFile as Ee}from"@s_mart/light-icons";import{lineFileCertificate as Se}from"@s_mart/regular-icons";var te=e=>{switch(e){case"application/xml":case"text/xml":return Ee;case"image/gif":case"image/jpeg":case"image/png":case"image/svg":case"image/webp":return Pe;case"application/pkcs12":return Se;default:return we}},H=e=>{let t="";return e<1024?t=`${e} Bytes`:e<1024*1024?t=`${(e/1024).toFixed(2)} KB`:e<1024*1024*1024&&(t=`${(e/1024/1024).toFixed(2)} MB`),t};var ne=({filesInfo:e})=>{let t=re(()=>e.map(o=>({name:o.name,fileSize:H(o.size),icon:te(o.type)})),[e]),r=re(()=>({totalSize:H(e.reduce((o,n)=>o+n.size,0)),totalFilesLabel:e.length===1?"1 arquivo":`${e.length} arquivos`}),[e]);return{files:t,headerInfo:r}};import{Tooltip as Ie}from"@mui/material";import V from"@mui/utils/deepmerge";import{IconButton as Me,LIcon as Re}from"@s_mart/core";import{lineTimes as Ae}from"@s_mart/regular-icons";import{jsx as O}from"react/jsx-runtime";var U={headerCleartooltip:{title:"Remover todos"},headerClearIconButton:{variant:"text",color:"neutral",sx:{borderRadius:50}},headerClearLicon:{icon:Ae,removeMargin:!0}},q={clone:!1},ie=({onClick:e,slotProps:t})=>{let r=V(U.headerCleartooltip,t?.headerCleartooltip,q),o=V(U.headerClearIconButton,t?.headerClearIconButton,q),n=V(U.headerClearLicon,t?.headerClearLicon,q);return O(Ie,{...r,children:O(Me,{...o,onClick:e,children:O(Re,{...n})})})};import{styled as ke}from"@mui/material";var ae=ke("div")({display:"flex",justifyContent:"space-between",alignItems:"center",paddingBlock:"0.5rem"});import{Typography as Be}from"@mui/material";import $e from"@mui/utils/deepmerge";import{useMemo as Ve}from"react";import{Fragment as Xe,jsx as M}from"react/jsx-runtime";var Ue={headerTitle:{variant:"titleXXS"}},qe={headerTitleContent:e=>M(Oe,{...e})},Oe=e=>{let t=`${e.filesLengthLabel}`;return e.showFilesSize&&(t+=` - ${e.filesTotalSize}`),M(Xe,{children:t})},le=e=>{let t=e.slots?.headerTitleContent??qe.headerTitleContent,r=Ve(()=>$e(Ue.headerTitle,{...e,...e.slotProps?.headerTitle}),[e.filesLengthLabel,e.filesTotalSize,e]);return M(Be,{...r,children:M(t,{...r})})};var R={Container:ae,Title:le,ClearButton:ie};import{useRef as Ke}from"react";import{useVirtualizer as Qe}from"@tanstack/react-virtual";import{jsx as h,jsxs as X}from"react/jsx-runtime";var pe=({filesInfo:e,onRemoveFile:t,onRemoveAllFiles:r,slotProps:o,slots:n,showFilesSize:p})=>{let{files:l,headerInfo:i}=ne({filesInfo:e}),u=Ke(null),d=Qe({count:l.length,getScrollElement:()=>u.current,estimateSize:()=>60,overscan:5});return l.length===0?null:X(Q,{...o?.filesContainer,children:[X(R.Container,{children:[h(R.Title,{slots:n,slotProps:o?.header,filesLengthLabel:i.totalFilesLabel,filesTotalSize:i.totalSize,showFilesSize:p}),h(R.ClearButton,{onClick:r})]}),h(J,{ref:u,...o?.filesListRoot,children:h(W,{...o?.filesListContainer,sx:{height:`${d.getTotalSize()}px`,...o?.filesListContainer},children:d.getVirtualItems().map(m=>{let g=l[m.index];return h(ee,{sx:{height:`${m.size}px`,transform:`translateY(${m.start}px)`},children:h(Ze,{title:g.name,arrow:!0,placement:"top",children:X(Y,{...o?.listItem,children:[h(se,{icon:g.icon,removeMargin:!0,size:"24px"}),h(Ne,{variant:"titleXXS",color:Ge.neutral[600],whiteSpace:"nowrap",children:p&&g.fileSize}),h(oe,{variant:"titleXXS",children:g.name}),h(_e,{variant:"text",color:"neutral",sx:{borderRadius:50},onClick:()=>t(m.index),children:h(se,{icon:je,removeMargin:!0})})]})})},m.key)})})})]})};import{CircularProgress as de,Stack as Z,Typography as A}from"@mui/material";import{LIcon as Ye}from"@s_mart/core";import{lineFileUpload as Je}from"@s_mart/regular-icons";import{jsx as T,jsxs as w}from"react/jsx-runtime";var ce=({placeholder:e,isProcessingZip:t})=>t?w("div",{children:[w(Z,{id:"dropzone-upload-info",sx:{gap:1,alignItems:"center",direction:"row"},children:[T(de,{sx:{color:"white"},size:24}),T(A,{variant:"titleSM",color:"white",children:"Descompactando zip..."})]}),w(Z,{id:"dropzone-upload-more-label",sx:{gap:1,alignItems:"center",direction:"row"},children:[T(de,{sx:{color:"white"},size:12}),T(A,{variant:"bodySM",sx:{fontWeight:700},children:"Descompactando zip..."})]})]}):w("div",{children:[w(Z,{id:"dropzone-upload-info",sx:{gap:1,alignItems:"center",direction:"row"},children:[T(Ye,{icon:Je,size:"48px",color:"white",removeMargin:!0}),T(A,{variant:"titleSM",color:"white",children:e})]}),T(A,{id:"dropzone-upload-more-label",variant:"bodySM",sx:{fontWeight:700},children:"Carregar mais arquivos"})]});import{useCallback as P,useMemo as ro,useRef as ue,useState as fe}from"react";var me=async(e,t)=>{let r=[];for(let o of e.items){if(o.kind!=="file")continue;if(typeof o.webkitGetAsEntry=="function"){let p=o.webkitGetAsEntry();if(p===null)continue;let l=await We(p);r.push(...l);continue}let n=o.getAsFile();n&&r.push(n)}return t!==void 0&&(r=to(r,t)),r},We=e=>new Promise((t,r)=>{let o=0,n=[];p(e);function p(i){oo(i)?(o++,i.file(u=>{o--,n.push(u),o===0&&t(n)})):eo(i)&&l(i.createReader())}function l(i){o++,i.readEntries(function(u){o--;for(let d of u)p(d);o===0&&t(n)})}}),eo=e=>e.isDirectory,oo=e=>e.isFile,to=(e,t)=>{let r=[],o=t.split(",");for(let n of e){let p=`.${n.name.split(".").pop()?.toLowerCase()}`;o.includes(p)&&r.push(n)}return r};var N=e=>{e.stopPropagation(),e.preventDefault()},_=e=>{e.dataTransfer.dropEffect="link",N(e)};var ge=({onChange:e,filterOnDrop:t,maxSize:r,maxFiles:o,accept:n,onError:p,onWarning:l,files:i})=>{let[u,d]=fe(!1),[m,g]=fe(!1),y=ue(null),B=ue(!1),s=P(async a=>{g(!0);let f=[],{BlobReader:D,BlobWriter:b,ZipReader:E}=await import("@zip.js/zip.js").catch(()=>{throw new Error("Fa\xE7a a instala\xE7\xE3o da biblioteca @zip.js/zip.js para utilizar o Dropzone com exporta\xE7\xE3o de .zip")}),x=new D(a),v=new E(x);try{let $=await v.getEntries();for(let S of $){if(S.directory||S.getData===void 0)continue;let Te=await S.getData(new b),Le=new File([Te],S.filename);f.push(Le)}}catch($){p?.("Ocorreu um erro ao processar o arquivo compactado.",$)}finally{g(!1),await v.close()}return f},[p]),z=P(async a=>{if(!n)return a;let f=[];for(let D of a){let b=`.${D.name.split(".").pop()?.toLocaleLowerCase()}`;if(!n.split(",").includes(b)){l?.(`O arquivo "${D.name}" n\xE3o \xE9 valido, extens\xF5es aceitas ${n}`);continue}if(b===".zip"){let x=await s(D);if(!x.length)continue;let v=await z(x);v.length&&f.push(...v);continue}f.push(D)}return f},[n,l,s]),c=P(async a=>{let f=await t?.(a)??a,D=await z(f);if(o!==void 0&&i.length+D.length>o)return l?.(`Quantidade m\xE1xima de arquivos ${o} alcan\xE7ada`),i;if(r!==void 0){let b=i.reduce((x,v)=>x+v.size,0),E=D.reduce((x,v)=>x+v.size,0);if(b+E>r)return l?.(`O arquivo \xE9 muito grande, O tamanho m\xE1ximo permitido \xE9 ${H(r)}`),i}return B.current=!0,[...i,...D]},[i,t,o,r,l,z]),L=async a=>{if(a.target.files){let f=[...a.target.files];e(await c(f))}},ve=P(a=>{y.current?.value&&(y.current.value=""),e(i.filter((f,D)=>D!==a))},[e,i]),Fe=P(()=>{y.current?.value&&(y.current.value=""),e([])},[e]),xe=ro(()=>i?.map(a=>({size:a.size,type:a.type,name:a.name}))??[],[i]),Ce=n?`${n.toUpperCase()},${n.toLowerCase()}`:void 0;return{inputRef:y,isDragging:u,filesInfo:xe,treatedAccept:Ce,isProcessingZip:m,handleRemoveFile:ve,handleRemoveAllFiles:Fe,handleChangeFiles:L,handleDragEnter:a=>{_(a),d(!0)},handleDragLeave:a=>{_(a),d(!1)},handleDrop:async a=>{N(a),d(!1);let f=await me(a.dataTransfer,n);c(f)}}};import{jsx as k,jsxs as ze}from"react/jsx-runtime";var no=e=>{let{inputRef:t,filesInfo:r,treatedAccept:o,handleChangeFiles:n,handleRemoveFile:p,handleRemoveAllFiles:l,handleDragEnter:i,handleDragLeave:u,handleDrop:d,isDragging:m,isProcessingZip:g}=ge(e),y=e.placeholder??"Pressione para carregar os arquivos";return ze(j,{onDragOver:i,...e.slotProps?.root,children:[k(G,{"data-is-dragging":m,onDrop:d,onDragLeave:u,...e.slotProps?.overlay}),k(pe,{filesInfo:r,onRemoveFile:p,onRemoveAllFiles:l,showFilesSize:e.showFilesSize,slotProps:e.slotProps,slots:e.slots}),ze(K,{onClick:()=>t.current?.click(),"data-max-files":e.maxFiles,"data-has-files":!!r.length,"data-is-processing-zip":g,...e.slotProps?.labelContainer,children:[k(ce,{placeholder:y,isProcessingZip:g}),k("input",{ref:t,type:"file",accept:o,hidden:!0,onChange:n,multiple:e.maxFiles===void 0||e.maxFiles>1})]})]})};import{useEffect as ao,useState as lo}from"react";import{Dropzone as so,FileItem as po}from"@dropzone-ui/react";import{LIcon as co}from"@s_mart/core";import{Tooltip as mo,Typography as uo}from"@mui/material";import{lineTimes as fo}from"@s_mart/regular-icons";import{styled as io}from"@mui/material";import{colorPalette as De}from"@s_mart/tokens";var he=io("button")`
|
|
106
31
|
display: flex;
|
|
107
32
|
align-items: center;
|
|
108
33
|
justify-content: center;
|
|
@@ -122,10 +47,10 @@ import{styled as P}from"@mui/material";import{colorPalette as B}from"@s_mart/tok
|
|
|
122
47
|
cursor: pointer;
|
|
123
48
|
transition: all 0.3s ease;
|
|
124
49
|
|
|
125
|
-
color: ${
|
|
50
|
+
color: ${De.neutral[500]};
|
|
126
51
|
|
|
127
52
|
&:hover {
|
|
128
|
-
background-color: ${
|
|
53
|
+
background-color: ${De.neutral[40]};
|
|
129
54
|
transition: all 0.3s ease;
|
|
130
55
|
}
|
|
131
|
-
`;import{Fragment as
|
|
56
|
+
`;import{Fragment as go,jsx as C,jsxs as zo}from"react/jsx-runtime";var ye=({showDeleteAllFilesButton:e=!0,placeholder:t,fileItemProps:r,initialValue:o=[],onClean:n,onReset:p,tratamentoFilesOnChange:l,onNotification:i,...u})=>{let[d,m]=lo(o),g=s=>{let z=s.filter(c=>c.valid===!0);if(m(z),s.length>0){let c=s.filter(L=>L.valid===!1);c.length===1?i({variant:"warning",duration:5e3,title:`Arquivo ${c[0].file.name} inv\xE1lido`,message:c[0].errors?.[0]}):c.length>1&&c.forEach(L=>{i({variant:"warning",duration:5e3,title:`Arquivo ${L.file.name} inv\xE1lido`,message:L.errors?.[0]})})}},y=()=>{m([]),p?.()},B=s=>{let z=d.filter(c=>c.id!==s.id);m(z),n?.(z)};return ao(()=>{o.length&&m(o)},[o]),C(so,{localization:"PT-pt",header:!1,footer:!1,headerClassName:"header",view:"grid",value:d,...u,onChange:async s=>{let z=s;if(l){let c=await l(s);c&&(z=c)}g(z),u.onChange?.(z)},children:d.length===0?C("div",{children:t||"Arraste os arquivos aqui ou clique para selecionar"}):zo(go,{children:[e&&C(mo,{title:C(uo,{variant:"bodyMD",children:"Remover"}),children:C(he,{onClick:s=>{s.preventDefault(),s.stopPropagation(),y()},children:C(co,{icon:fo,size:"24px"})})}),C("div",{style:{display:"flex"},children:d?.map(s=>C(po,{info:!0,localization:"PT-pt",preview:!0,...s,...r,onDelete:()=>B(s)},s.id))})]})})};export{ye as Dropzone,ye as DropzoneV1,no as DropzoneV2};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/dropzone",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@dropzone-ui/react": "^6.7.20",
|
|
14
14
|
"@mui/utils": "^7.2.0",
|
|
15
|
+
"@tanstack/react-virtual": "^3.13.12",
|
|
15
16
|
"react-is": "^18.3.1",
|
|
16
|
-
"tsup": "8.0
|
|
17
|
+
"tsup": "8.5.0"
|
|
17
18
|
},
|
|
18
19
|
"peerDependencies": {
|
|
19
20
|
"@emotion/react": "^11.11.4",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"react-dom": "^18.3.1",
|
|
30
31
|
"typescript": ">=5.4.2",
|
|
31
32
|
"@s_mart/core": "10.0.2",
|
|
32
|
-
"@s_mart/light-icons": "6.0.
|
|
33
|
+
"@s_mart/light-icons": "6.0.12",
|
|
33
34
|
"@s_mart/regular-icons": "6.0.11",
|
|
34
35
|
"@s_mart/tokens": "6.0.0"
|
|
35
36
|
},
|
|
@@ -45,10 +46,10 @@
|
|
|
45
46
|
"react": "^18.3.1",
|
|
46
47
|
"react-dom": "^18.3.1",
|
|
47
48
|
"typescript": ">=5.4.2",
|
|
48
|
-
"@s_mart/
|
|
49
|
-
"@s_mart/
|
|
49
|
+
"@s_mart/core": "10.0.2",
|
|
50
|
+
"@s_mart/light-icons": "6.0.12",
|
|
50
51
|
"@s_mart/tokens": "6.0.0",
|
|
51
|
-
"@s_mart/
|
|
52
|
+
"@s_mart/regular-icons": "6.0.11"
|
|
52
53
|
},
|
|
53
54
|
"overrides": {
|
|
54
55
|
"react-is": "^18.3.1"
|