22 lines
27 KiB
JavaScript
22 lines
27 KiB
JavaScript
import{bR as mt,r as l,L as O,R as xe,M as gt,a3 as U,a_ as Be,bH as We,bi as Ue,dh as ht,di as Ae,z as ft,G as bt,c5 as $t,H as yt,ba as fe,ak as wt,Z as vt,dj as St,bg as Ge,a9 as Ke,ar as Ct,bQ as Et,bx as Ft,cc as xt,dk as It,P as Me,B as qe,b9 as je,dl as Rt,dm as Dt,dn as Nt,J as Te,bK as Pt,aA as Lt,K as Ot,bp as Ut,bq as At,bS as ze}from"./index-B-sDl1ER.js";import{P as Mt}from"./progress-C__thZ4V.js";const qt=((e,t)=>{if(e&&t){const n=Array.isArray(t)?t:t.split(","),a=e.name||"",s=e.type||"",o=s.replace(/\/.*$/,"");return n.some(i=>{const r=i.trim();if(/^\*(\/\*)?$/.test(i))return!0;if(r.charAt(0)==="."){const c=a.toLowerCase(),u=r.toLowerCase();let p=[u];return(u===".jpg"||u===".jpeg")&&(p=[".jpg",".jpeg"]),p.some(f=>c.endsWith(f))}return/\/\*$/.test(r)?o===r.replace(/\/.*$/,""):s===r?!0:/^\w+$/.test(r)?(mt(!1,`Upload takes an invalidate 'accept' type '${r}'.Skip for check.`),!0):!1})}return!0});function jt(e,t){const n=`cannot ${e.method} ${e.action} ${t.status}'`,a=new Error(n);return a.status=t.status,a.method=e.method,a.url=e.action,a}function _e(e){const t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch{return t}}function Xe(e){const t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=function(o){o.total>0&&(o.percent=o.loaded/o.total*100),e.onProgress(o)});const n=new FormData;e.data&&Object.keys(e.data).forEach(s=>{const o=e.data[s];if(Array.isArray(o)){o.forEach(i=>{n.append(`${s}[]`,i)});return}n.append(s,o)}),e.file instanceof Blob?n.append(e.filename,e.file,e.file.name):n.append(e.filename,e.file),t.onerror=function(o){e.onError(o)},t.onload=function(){return t.status<200||t.status>=300?e.onError(jt(e,t),_e(t)):e.onSuccess(_e(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const a=e.headers||{};return a["X-Requested-With"]!==null&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(a).forEach(s=>{a[s]!==null&&t.setRequestHeader(s,a[s])}),t.send(n),{abort(){t.abort()}}}const Tt=async(e,t)=>{const n=[],a=[];e.forEach(c=>a.push(c.webkitGetAsEntry()));async function s(c){const u=c.createReader(),p=[];for(;;){const f=await new Promise(v=>{u.readEntries(v,()=>v([]))}),F=f.length;if(!F)break;for(let v=0;v<F;v++)p.push(f[v])}return p}async function o(c){return new Promise(u=>{c.file(p=>{t(p)?(c.fullPath&&!p.webkitRelativePath&&(Object.defineProperties(p,{webkitRelativePath:{writable:!0}}),p.webkitRelativePath=c.fullPath.replace(/^\//,""),Object.defineProperties(p,{webkitRelativePath:{writable:!1}})),u(p)):u(null)})})}const i=async(c,u)=>{if(c){if(c.path="",c.isFile){const p=await o(c);p&&n.push(p)}else if(c.isDirectory){const p=await s(c);a.push(...p)}}};let r=0;for(;r<a.length;)await i(a[r]),r++;return n},zt=+new Date;let _t=0;function Ce(){return`rc-upload-${zt}-${++_t}`}function be(){return be=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},be.apply(this,arguments)}class Xt extends l.Component{state={uid:Ce()};reqs={};fileInput;_isMounted;filterFile=(t,n=!1)=>{const{accept:a,directory:s}=this.props;let o,i;if(typeof a=="string")i=a;else{const{filter:c,format:u}=a||{};i=u,c==="native"?o=()=>!0:o=c}return(o||(s||n?c=>qt(c,i):()=>!0))(t)};onChange=t=>{const{files:n}=t.target,a=[...n].filter(s=>this.filterFile(s));this.uploadFiles(a),this.reset()};onClick=t=>{const n=this.fileInput;if(!n)return;const a=t.target,{onClick:s}=this.props;a&&a.tagName==="BUTTON"&&(n.parentNode.focus(),a.blur()),n.click(),s&&s(t)};onKeyDown=t=>{t.key==="Enter"&&this.onClick(t)};onDataTransferFiles=async(t,n)=>{const{multiple:a,directory:s}=this.props,o=[...t.items||[]];let i=[...t.files||[]];if((i.length>0||o.some(r=>r.kind==="file"))&&n?.(),s)i=await Tt(Array.prototype.slice.call(o),this.filterFile),this.uploadFiles(i);else{let r=[...i].filter(c=>this.filterFile(c,!0));a===!1&&(r=i.slice(0,1)),this.uploadFiles(r)}};onFilePaste=async t=>{const{pastable:n}=this.props;if(n&&t.type==="paste"){const a=t.clipboardData;return this.onDataTransferFiles(a,()=>{t.preventDefault()})}};onFileDragOver=t=>{t.preventDefault()};onFileDrop=async t=>{if(t.preventDefault(),t.type==="drop"){const n=t.dataTransfer;return this.onDataTransferFiles(n)}};componentDidMount(){this._isMounted=!0;const{pastable:t}=this.props;t&&document.addEventListener("paste",this.onFilePaste)}componentWillUnmount(){this._isMounted=!1,this.abort(),document.removeEventListener("paste",this.onFilePaste)}componentDidUpdate(t){const{pastable:n}=this.props;n&&!t.pastable?document.addEventListener("paste",this.onFilePaste):!n&&t.pastable&&document.removeEventListener("paste",this.onFilePaste)}uploadFiles=t=>{const n=[...t],a=n.map(s=>(s.uid=Ce(),this.processFile(s,n)));Promise.all(a).then(s=>{const{onBatchStart:o}=this.props;o?.(s.map(({origin:i,parsedFile:r})=>({file:i,parsedFile:r}))),s.filter(i=>i.parsedFile!==null).forEach(i=>{this.post(i)})})};processFile=async(t,n)=>{const{beforeUpload:a}=this.props;let s=t;if(a){try{s=await a(t,n)}catch{s=!1}if(s===!1)return{origin:t,parsedFile:null,action:null,data:null}}const{action:o}=this.props;let i;typeof o=="function"?i=await o(t):i=o;const{data:r}=this.props;let c;typeof r=="function"?c=await r(t):c=r;const u=(typeof s=="object"||typeof s=="string")&&s?s:t;let p;u instanceof File?p=u:p=new File([u],t.name,{type:t.type});const f=p;return f.uid=t.uid,{origin:t,data:c,parsedFile:f,action:i}};post({data:t,origin:n,action:a,parsedFile:s}){if(!this._isMounted)return;const{onStart:o,customRequest:i,name:r,headers:c,withCredentials:u,method:p}=this.props,{uid:f}=n,F=i||Xe,v={action:a,filename:r,data:t,file:s,headers:c,withCredentials:u,method:p||"post",onProgress:x=>{const{onProgress:E}=this.props;E?.(x,s)},onSuccess:(x,E)=>{const{onSuccess:D}=this.props;D?.(x,s,E),delete this.reqs[f]},onError:(x,E)=>{const{onError:D}=this.props;D?.(x,E,s),delete this.reqs[f]}};o(n),this.reqs[f]=F(v,{defaultRequest:Xe})}reset(){this.setState({uid:Ce()})}abort(t){const{reqs:n}=this;if(t){const a=t.uid?t.uid:t;n[a]&&n[a].abort&&n[a].abort(),delete n[a]}else Object.keys(n).forEach(a=>{n[a]&&n[a].abort&&n[a].abort(),delete n[a]})}saveFileInput=t=>{this.fileInput=t};render(){const{component:t,prefixCls:n,className:a,classNames:s={},disabled:o,id:i,name:r,style:c,styles:u={},multiple:p,accept:f,capture:F,children:v,directory:x,openFileDialogOnClick:E,onMouseEnter:D,onMouseLeave:j,hasControlInside:q,...T}=this.props,A=typeof f=="string"?f:f?.format,R=O(n,{[`${n}-disabled`]:o,[a]:a}),X=x?{directory:"directory",webkitdirectory:"webkitdirectory"}:{},H=o?{}:{onClick:E?this.onClick:()=>{},onKeyDown:E?this.onKeyDown:()=>{},onMouseEnter:D,onMouseLeave:j,onDrop:this.onFileDrop,onDragOver:this.onFileDragOver,tabIndex:q?void 0:"0"};return xe.createElement(t,be({},H,{className:R,role:q?void 0:"button",style:c}),xe.createElement("input",be({},gt(T,{aria:!0,data:!0}),{id:i,name:r,disabled:o,type:"file",ref:this.saveFileInput,onClick:M=>M.stopPropagation(),key:this.state.uid,style:{display:"none",...u.input},className:s.input,accept:A},X,{multiple:p,onChange:this.onChange},F!=null?{capture:F}:{})),v)}}function Ie(){return Ie=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},Ie.apply(this,arguments)}function Ee(){}let He=class extends l.Component{static defaultProps={component:"span",prefixCls:"rc-upload",data:{},headers:{},name:"file",multipart:!1,onStart:Ee,onError:Ee,onSuccess:Ee,multiple:!1,beforeUpload:null,customRequest:null,withCredentials:!1,openFileDialogOnClick:!0,hasControlInside:!1};uploader;abort(t){this.uploader.abort(t)}saveUploader=t=>{this.uploader=t};render(){return xe.createElement(Xt,Ie({},this.props,{ref:this.saveUploader}))}};const Ht=e=>{const{componentCls:t,iconCls:n}=e;return{[`${t}-wrapper`]:{[`${t}-drag`]:{position:"relative",width:"100%",height:"100%",textAlign:"center",background:e.colorFillAlter,border:`${U(e.lineWidth)} dashed ${e.colorBorder}`,borderRadius:e.borderRadiusLG,cursor:"pointer",transition:`border-color ${e.motionDurationSlow}`,[t]:{padding:e.padding},[`${t}-btn`]:{display:"table",width:"100%",height:"100%",outline:"none",borderRadius:e.borderRadiusLG,"&:focus-visible":{outline:`${U(e.lineWidthFocus)} solid ${e.colorPrimaryBorder}`}},[`${t}-drag-container`]:{display:"table-cell",verticalAlign:"middle"},[`
|
|
&:not(${t}-disabled):hover,
|
|
&-hover:not(${t}-disabled)
|
|
`]:{borderColor:e.colorPrimaryHover},[`p${t}-drag-icon`]:{marginBottom:e.margin,[n]:{color:e.colorPrimary,fontSize:e.uploadThumbnailSize}},[`p${t}-text`]:{margin:`0 0 ${U(e.marginXXS)}`,color:e.colorTextHeading,fontSize:e.fontSizeLG},[`p${t}-hint`]:{color:e.colorTextDescription,fontSize:e.fontSize},[`&${t}-disabled`]:{[`p${t}-drag-icon ${n},
|
|
p${t}-text,
|
|
p${t}-hint
|
|
`]:{color:e.colorTextDisabled}}}}}},Bt=e=>{const{componentCls:t,iconCls:n,fontSize:a,lineHeight:s,motionDurationSlow:o,calc:i}=e,r=`${t}-list-item`,c=`${r}-actions`,u=`${r}-action`;return{[`${t}-wrapper`]:{[`${t}-list`]:{...We(),lineHeight:e.lineHeight,[r]:{position:"relative",height:i(e.lineHeight).mul(a).equal(),marginTop:e.marginXS,fontSize:a,display:"flex",alignItems:"center",transition:`background-color ${o}`,borderRadius:e.borderRadiusSM,"&:hover":{backgroundColor:e.controlItemBgHover},[`${r}-name`]:{...Be,padding:`0 ${U(e.paddingXS)}`,lineHeight:s,flex:"auto",transition:`all ${o}`},[c]:{whiteSpace:"nowrap",[u]:{opacity:0},"@media (hover: none), (pointer: coarse)":{[u]:{opacity:1}},[n]:{color:e.actionsColor,transition:`all ${o}`},[`
|
|
${u}:focus-visible,
|
|
&.picture ${u}
|
|
`]:{opacity:1}},[`${t}-icon ${n}`]:{color:e.colorIcon,fontSize:a},[`${r}-progress`]:{position:"absolute",bottom:e.calc(e.uploadProgressOffset).mul(-1).equal(),width:"100%",paddingInlineStart:i(a).add(e.paddingXS).equal(),fontSize:a,lineHeight:0,pointerEvents:"none","> div":{margin:0}}},[`${r}:hover ${u}`]:{opacity:1},[`${r}-error`]:{color:e.colorError,[`${r}-name, ${t}-icon ${n}`]:{color:e.colorError},[c]:{[`${n}, ${n}:hover`]:{color:e.colorError},[u]:{opacity:1}}},[`${t}-list-item-container`]:{transition:["opacity","height"].map(p=>`${p} ${o}`).join(", "),"&::before":{display:"table",width:0,height:0,content:'""'}}}}}},Wt=e=>{const{componentCls:t}=e,n=new Ue("uploadAnimateInlineIn",{from:{width:0,height:0,padding:0,opacity:0,margin:e.calc(e.marginXS).div(-2).equal()}}),a=new Ue("uploadAnimateInlineOut",{to:{width:0,height:0,padding:0,opacity:0,margin:e.calc(e.marginXS).div(-2).equal()}}),s=`${t}-animate-inline`;return[{[`${t}-wrapper`]:{[`${s}-appear, ${s}-enter, ${s}-leave`]:{animationDuration:e.motionDurationSlow,animationTimingFunction:e.motionEaseInOutCirc,animationFillMode:"forwards"},[`${s}-appear, ${s}-enter`]:{animationName:n},[`${s}-leave`]:{animationName:a}}},{[`${t}-wrapper`]:ht(e)},n,a]},Gt=e=>{const{componentCls:t,iconCls:n,uploadThumbnailSize:a,uploadProgressOffset:s,calc:o}=e,i=`${t}-list`,r=`${i}-item`;return{[`${t}-wrapper`]:{[`
|
|
${i}${i}-picture,
|
|
${i}${i}-picture-card,
|
|
${i}${i}-picture-circle
|
|
`]:{[r]:{position:"relative",height:o(a).add(o(e.lineWidth).mul(2)).add(o(e.paddingXS).mul(2)).equal(),padding:e.paddingXS,border:`${U(e.lineWidth)} ${e.lineType} ${e.colorBorder}`,borderRadius:e.borderRadiusLG,"&:hover":{background:"transparent"},[`${r}-thumbnail`]:{...Be,width:a,height:a,lineHeight:U(o(a).add(e.paddingSM).equal()),textAlign:"center",flex:"none",[n]:{fontSize:e.fontSizeHeading2,color:e.colorPrimary},img:{display:"block",width:"100%",height:"100%",overflow:"hidden"}},[`${r}-progress`]:{bottom:o(e.fontSize).mul(e.lineHeight).div(2).add(s).equal(),width:`calc(100% - ${U(o(e.paddingSM).mul(2).equal())})`,marginTop:0,paddingInlineStart:o(a).add(e.paddingXS).equal()}},[`${r}-error`]:{borderColor:e.colorError,[`${r}-thumbnail ${n}`]:{[`svg path[fill='${Ae[0]}']`]:{fill:e.colorErrorBg},[`svg path[fill='${Ae.primary}']`]:{fill:e.colorError}}},[`${r}-uploading`]:{borderStyle:"dashed",[`${r}-name`]:{marginBottom:s}}},[`${i}${i}-picture-circle ${r}`]:{[`&, &::before, ${r}-thumbnail`]:{borderRadius:"50%"}}}}},Kt=e=>{const{componentCls:t,iconCls:n,fontSizeLG:a,colorTextLightSolid:s,calc:o}=e,i=`${t}-list`,r=`${i}-item`,c=e.uploadPicCardSize;return{[`
|
|
${t}-wrapper${t}-picture-card-wrapper,
|
|
${t}-wrapper${t}-picture-circle-wrapper
|
|
`]:{...We(),display:"block",[`${t}${t}-select`]:{width:c,height:c,textAlign:"center",verticalAlign:"top",backgroundColor:e.colorFillAlter,border:`${U(e.lineWidth)} dashed ${e.colorBorder}`,borderRadius:e.borderRadiusLG,cursor:"pointer",transition:`border-color ${e.motionDurationSlow}`,[`> ${t}`]:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",textAlign:"center"},[`&:not(${t}-disabled):hover`]:{borderColor:e.colorPrimary}},[`${i}${i}-picture-card, ${i}${i}-picture-circle`]:{display:"flex",flexWrap:"wrap","&:not(:empty)":{minHeight:c},"@supports not (gap: 1px)":{"& > *":{marginBlockEnd:e.marginXS,marginInlineEnd:e.marginXS}},"@supports (gap: 1px)":{gap:e.marginXS},[`${i}-item-container`]:{display:"inline-block",width:c,height:c,verticalAlign:"top"},"&::after":{display:"none"},"&::before":{display:"none"},[r]:{height:"100%",margin:0,"&::before":{position:"absolute",zIndex:1,width:`calc(100% - ${U(o(e.paddingXS).mul(2).equal())})`,height:`calc(100% - ${U(o(e.paddingXS).mul(2).equal())})`,backgroundColor:e.colorBgMask,opacity:0,transition:`all ${e.motionDurationSlow}`,content:'" "'}},[`${r}:hover`]:{[`&::before, ${r}-actions`]:{opacity:1}},[`${r}-actions`]:{position:"absolute",insetInlineStart:0,zIndex:10,width:"100%",whiteSpace:"nowrap",textAlign:"center",opacity:0,transition:`all ${e.motionDurationSlow}`,[`
|
|
${n}-eye,
|
|
${n}-download,
|
|
${n}-delete
|
|
`]:{zIndex:10,width:a,margin:`0 ${U(e.marginXXS)}`,fontSize:a,cursor:"pointer",transition:`all ${e.motionDurationSlow}`,color:s,"&:hover":{color:s},svg:{verticalAlign:"baseline"}}},[`${r}-thumbnail, ${r}-thumbnail img`]:{position:"static",display:"block",width:"100%",height:"100%",objectFit:"contain"},[`${r}-name`]:{display:"none",textAlign:"center"},[`${r}-file + ${r}-name`]:{position:"absolute",bottom:e.margin,display:"block",width:`calc(100% - ${U(o(e.paddingXS).mul(2).equal())})`},[`${r}-uploading`]:{[`&${r}`]:{backgroundColor:e.colorFillAlter},[`&::before, ${n}-eye, ${n}-download, ${n}-delete`]:{display:"none"}},[`${r}-progress`]:{bottom:e.marginXL,width:`calc(100% - ${U(o(e.paddingXS).mul(2).equal())})`,paddingInlineStart:0}}},[`${t}-wrapper${t}-picture-circle-wrapper`]:{[`${t}${t}-select`]:{borderRadius:"50%"}}}},Vt=e=>{const{componentCls:t}=e;return{[`${t}-rtl`]:{direction:"rtl"}}},Jt=e=>{const{componentCls:t,colorTextDisabled:n}=e;return{[`${t}-wrapper`]:{...yt(e),[t]:{outline:0,"input[type='file']":{cursor:"pointer"}},[`${t}-select`]:{display:"inline-block"},[`${t}-hidden`]:{display:"none"},[`${t}-disabled`]:{color:n,cursor:"not-allowed"}}}},Zt=e=>({actionsColor:e.colorIcon,pictureCardSize:e.controlHeightLG*2.55}),Qt=ft("Upload",e=>{const{fontSizeHeading3:t,marginXS:n,lineWidth:a,pictureCardSize:s,calc:o}=e,i=bt(e,{uploadThumbnailSize:o(t).mul(2).equal(),uploadProgressOffset:o(o(n).div(2)).add(a).equal(),uploadPicCardSize:s});return[Jt(i),Ht(i),Gt(i),Kt(i),Bt(i),Wt(i),Vt(i),$t(i)]},Zt);function ge(e){return{...e,lastModified:e.lastModified,lastModifiedDate:e.lastModifiedDate,name:e.name,size:e.size,type:e.type,uid:e.uid,percent:0,originFileObj:e}}function he(e,t){const n=fe(t),a=n.findIndex(({uid:s})=>s===e.uid);return a===-1?n.push(e):n[a]=e,n}function Fe(e,t){const n=e.uid!==void 0?"uid":"name";return t.filter(a=>a[n]===e[n])[0]}function Yt(e,t){const n=e.uid!==void 0?"uid":"name",a=t.filter(s=>s[n]!==e[n]);return a.length===t.length?null:a}const kt=(e="")=>{const t=e.split("/"),a=t[t.length-1].split(/#|\?/)[0];return(/\.[^./\\]*$/.exec(a)||[""])[0]},Ve=e=>e.indexOf("image/")===0,er=e=>{if(e.type&&!e.thumbUrl)return Ve(e.type);const t=e.thumbUrl||e.url||"",n=kt(t);return/^data:image\//.test(t)||/(webp|svg|png|gif|jpg|jpeg|jfif|bmp|dpg|ico|heic|heif)$/i.test(n)?!0:!(/^data:/.test(t)||n)},G=200;function tr(e){return new Promise(t=>{if(!e.type||!Ve(e.type)){t("");return}const n=document.createElement("canvas");n.width=G,n.height=G,n.style.cssText=`position: fixed; left: 0; top: 0; width: ${G}px; height: ${G}px; z-index: 9999; display: none;`,document.body.appendChild(n);const a=n.getContext("2d"),s=new Image;if(s.onload=()=>{const{width:o,height:i}=s;let r=G,c=G,u=0,p=0;o>i?(c=i*(G/o),p=-(c-r)/2):(r=o*(G/i),u=-(r-c)/2),a.drawImage(s,u,p,r,c);const f=n.toDataURL();document.body.removeChild(n),window.URL.revokeObjectURL(s.src),t(f)},s.crossOrigin="anonymous",e.type.startsWith("image/svg+xml")){const o=new FileReader;o.onload=()=>{o.result&&typeof o.result=="string"&&(s.src=o.result)},o.readAsDataURL(e)}else if(e.type.startsWith("image/gif")){const o=new FileReader;o.onload=()=>{o.result&&t(o.result)},o.readAsDataURL(e)}else s.src=window.URL.createObjectURL(e)})}const rr=l.forwardRef(({prefixCls:e,className:t,style:n,classNames:a,styles:s,locale:o,listType:i,file:r,items:c,progress:u,iconRender:p,actionIconRender:f,itemRender:F,isImgUrl:v,showPreviewIcon:x,showRemoveIcon:E,showDownloadIcon:D,previewIcon:j,removeIcon:q,downloadIcon:T,extra:A,onPreview:R,onDownload:X,onClose:H},M)=>{const{status:z}=r,[N,Y]=l.useState(z);l.useEffect(()=>{z!=="removed"&&Y(z)},[z]);const[se,k]=l.useState(!1);l.useEffect(()=>{const S=setTimeout(()=>{k(!0)},300);return()=>{clearTimeout(S)}},[]);const _=p(r);let B=l.createElement("div",{className:`${e}-icon`},_);if(i==="picture"||i==="picture-card"||i==="picture-circle")if(N==="uploading"||!r.thumbUrl&&!r.url){const S=O(`${e}-list-item-thumbnail`,{[`${e}-list-item-file`]:N!=="uploading"});B=l.createElement("div",{className:S},_)}else{const S=v?.(r)?l.createElement("img",{src:r.thumbUrl||r.url,alt:r.name,className:`${e}-list-item-image`,crossOrigin:r.crossOrigin}):_,ae=O(`${e}-list-item-thumbnail`,{[`${e}-list-item-file`]:v&&!v(r)});B=l.createElement("a",{className:ae,onClick:$e=>R(r,$e),href:r.url||r.thumbUrl,target:"_blank",rel:"noopener noreferrer"},S)}const ie=O(`${e}-list-item`,`${e}-list-item-${N}`,a?.item),le=typeof r.linkProps=="string"?JSON.parse(r.linkProps):r.linkProps,ee=(typeof E=="function"?E(r):E)?f((typeof q=="function"?q(r):q)||l.createElement(wt,null),()=>H(r),e,o.removeFile,!0):null,P=(typeof D=="function"?D(r):D)&&N==="done"?f((typeof T=="function"?T(r):T)||l.createElement(vt,null),()=>X(r),e,o.downloadFile):null,W=i!=="picture-card"&&i!=="picture-circle"&&l.createElement("span",{key:"download-delete",className:O(`${e}-list-item-actions`,{picture:i==="picture"})},P,ee),K=typeof A=="function"?A(r):A,te=K&&l.createElement("span",{className:`${e}-list-item-extra`},K),C=O(`${e}-list-item-name`),re=r.url?l.createElement("a",{key:"view",target:"_blank",rel:"noopener noreferrer",className:C,title:r.name,...le,href:r.url,onClick:S=>R(r,S)},r.name,te):l.createElement("span",{key:"view",className:C,onClick:S=>R(r,S),title:r.name},r.name,te),d=(typeof x=="function"?x(r):x)&&(r.url||r.thumbUrl)?l.createElement("a",{href:r.url||r.thumbUrl,target:"_blank",rel:"noopener noreferrer",onClick:S=>R(r,S),title:o.previewFile},typeof j=="function"?j(r):j||l.createElement(St,null)):null,y=(i==="picture-card"||i==="picture-circle")&&N!=="uploading"&&l.createElement("span",{className:`${e}-list-item-actions`},d,N==="done"&&P,ee),{getPrefixCls:I}=l.useContext(Ge),L=I(),ne=l.createElement("div",{className:ie,style:s?.item},B,re,W,y,se&&l.createElement(Ke,{motionName:`${L}-fade`,visible:N==="uploading",motionDeadline:2e3},({className:S})=>{const ae="percent"in r?l.createElement(Mt,{type:"line",percent:r.percent,"aria-label":r["aria-label"],"aria-labelledby":r["aria-labelledby"],...u}):null;return l.createElement("div",{className:O(`${e}-list-item-progress`,S)},ae)})),V=r.response&&typeof r.response=="string"?r.response:r.error?.statusText||r.error?.message||o.uploadError,J=N==="error"?l.createElement(Ct,{title:V,getPopupContainer:S=>S.parentNode},ne):ne;return l.createElement("div",{className:O(`${e}-list-item-container`,t),style:n,ref:M},F?F(J,r,c,{download:X.bind(null,r),preview:R.bind(null,r),remove:H.bind(null,r)}):J)}),nr=(e,t)=>{const{listType:n="text",previewFile:a=tr,onPreview:s,onDownload:o,onRemove:i,locale:r,iconRender:c,isImageUrl:u=er,prefixCls:p,items:f=[],showPreviewIcon:F=!0,showRemoveIcon:v=!0,showDownloadIcon:x=!1,removeIcon:E,previewIcon:D,downloadIcon:j,extra:q,progress:T={size:[-1,2],showInfo:!1},appendAction:A,appendActionVisible:R=!0,itemRender:X,disabled:H,classNames:M,styles:z}=e,[,N]=Et(),[Y,se]=l.useState(!1),k=["picture-card","picture-circle"].includes(n);l.useEffect(()=>{n.startsWith("picture")&&(f||[]).forEach(d=>{!(d.originFileObj instanceof File||d.originFileObj instanceof Blob)||d.thumbUrl!==void 0||(d.thumbUrl="",a?.(d.originFileObj).then(y=>{d.thumbUrl=y||"",N()}))})},[n,f,a]),l.useEffect(()=>{se(!0)},[]);const _=(d,y)=>{if(s)return y?.preventDefault(),s(d)},B=d=>{typeof o=="function"?o(d):d.url&&window.open(d.url)},ie=d=>{i?.(d)},le=d=>{if(c)return c(d,n);const y=d.status==="uploading";if(n.startsWith("picture")){const I=n==="picture"?l.createElement(je,null):r.uploading,L=u?.(d)?l.createElement(Rt,null):l.createElement(Dt,null);return y?I:L}return y?l.createElement(je,null):l.createElement(Nt,null)},ee=(d,y,I,L,ne)=>{const V={type:"text",size:"small",title:L,onClick:J=>{y(),l.isValidElement(d)&&d.props.onClick?.(J)},className:`${I}-list-item-action`,disabled:ne?H:!1};return l.isValidElement(d)?l.createElement(qe,{...V,icon:Me(d,{...d.props,onClick:()=>{}})}):l.createElement(qe,{...V},l.createElement("span",null,d))};l.useImperativeHandle(t,()=>({handlePreview:_,handleDownload:B}));const{getPrefixCls:P}=l.useContext(Ge),W=P("upload",p),K=P(),te=O(`${W}-list`,`${W}-list-${n}`,M?.list),C=l.useMemo(()=>Ft(xt(K),["onAppearEnd","onEnterEnd","onLeaveEnd"]),[K]),re={...k?{}:C,motionDeadline:2e3,motionName:`${W}-${k?"animate-inline":"animate"}`,keys:fe(f.map(d=>({key:d.uid,file:d}))),motionAppear:Y};return l.createElement("div",{className:te,style:z?.list},l.createElement(It,{...re,component:!1},({key:d,file:y,className:I,style:L})=>l.createElement(rr,{key:d,locale:r,prefixCls:W,className:I,style:L,classNames:M,styles:z,file:y,items:f,progress:T,listType:n,isImgUrl:u,showPreviewIcon:F,showRemoveIcon:v,showDownloadIcon:x,removeIcon:E,previewIcon:D,downloadIcon:j,extra:q,iconRender:le,actionIconRender:ee,itemRender:X,onPreview:_,onDownload:B,onClose:ie})),A&&l.createElement(Ke,{...re,visible:R,forceRender:!0},({className:d,style:y})=>Me(A,I=>({className:O(I.className,d),style:{...y,pointerEvents:d?"none":void 0,...I.style}}))))},ar=l.forwardRef(nr),de=`__LIST_IGNORE_${Date.now()}__`,or=(e,t)=>{const n=Te("upload"),{fileList:a,defaultFileList:s,onRemove:o,showUploadList:i=!0,listType:r="text",onPreview:c,onDownload:u,onChange:p,onDrop:f,previewFile:F,disabled:v,locale:x,iconRender:E,isImageUrl:D,progress:j,prefixCls:q,className:T,type:A="select",children:R,style:X,itemRender:H,maxCount:M,data:z={},multiple:N=!1,hasControlInside:Y=!0,action:se="",accept:k="",supportServerRender:_=!0,rootClassName:B,styles:ie,classNames:le}=e,ee=l.useContext(Pt),P=v??ee,W=e.customRequest||n.customRequest,[K,te]=Lt(s,a),C=K||[],[re,d]=l.useState("drop"),y=l.useRef(null),I=l.useRef(null);l.useMemo(()=>{const m=Date.now();(a||[]).forEach((h,$)=>{!h.uid&&!Object.isFrozen(h)&&(h.uid=`__AUTO__${m}_${$}__`)})},[a]);const L=(m,h,$)=>{let g=fe(h),b=!1;M===1?g=g.slice(-1):M&&(b=g.length>M,g=g.slice(0,M)),ze.flushSync(()=>{te(g)});const Z={file:m,fileList:g};$&&(Z.event=$),(!b||m.status==="removed"||g.some(me=>me.uid===m.uid))&&ze.flushSync(()=>{p?.(Z)})},ne=async(m,h)=>{const{beforeUpload:$}=e;let g=m;if($){const b=await $(m,h);if(b===!1)return!1;if(delete m[de],b===de)return Object.defineProperty(m,de,{value:!0,configurable:!0}),!1;typeof b=="object"&&b&&(g=b)}return g},V=m=>{const h=m.filter(b=>!b.file[de]);if(!h.length)return;const $=h.map(b=>ge(b.file));let g=fe(C);$.forEach(b=>{g=he(b,g)}),$.forEach((b,Z)=>{let me=b;if(h[Z].parsedFile)b.status="uploading";else{const{originFileObj:oe}=b;let Q;try{Q=new File([oe],oe.name,{type:oe.type})}catch{Q=new Blob([oe],{type:oe.type}),Q.name=oe.name,Q.lastModifiedDate=new Date,Q.lastModified=new Date().getTime()}Q.uid=b.uid,me=Q}L(me,g)})},J=(m,h,$)=>{try{typeof m=="string"&&(m=JSON.parse(m))}catch{}if(!Fe(h,C))return;const g=ge(h);g.status="done",g.percent=100,g.response=m,g.xhr=$;const b=he(g,C);L(g,b)},S=(m,h)=>{if(!Fe(h,C))return;const $=ge(h);$.status="uploading",$.percent=m.percent;const g=he($,C);L($,g,m)},ae=(m,h,$)=>{if(!Fe($,C))return;const g=ge($);g.error=m,g.response=h,g.status="error";const b=he(g,C);L(g,b)},$e=m=>{let h;Promise.resolve(typeof o=="function"?o(m):o).then($=>{if($===!1)return;const g=Yt(m,C);g&&(h={...m,status:"removed"},C?.forEach(b=>{const Z=h.uid!==void 0?"uid":"name";b[Z]===h[Z]&&!Object.isFrozen(b)&&(b.status="removed")}),y.current?.abort(h),L(h,g))})},ye=m=>{d(m.type),m.type==="drop"&&f?.(m)};l.useImperativeHandle(t,()=>({onBatchStart:V,onSuccess:J,onProgress:S,onError:ae,fileList:C,upload:y.current,nativeElement:I.current}));const{getPrefixCls:Qe,direction:Re,className:Ye,style:ke,classNames:et,styles:tt}=Te("upload"),w=Qe("upload",q),rt={...e,listType:r,showUploadList:i,type:A,multiple:N,hasControlInside:Y,supportServerRender:_,disabled:P},[ue,pe]=Ot([et,le],[tt,ie],{props:rt}),ce={onBatchStart:V,onError:ae,onProgress:S,onSuccess:J,...e,customRequest:W,data:z,multiple:N,action:se,accept:k,supportServerRender:_,prefixCls:w,disabled:P,beforeUpload:ne,onChange:void 0,hasControlInside:Y};delete ce.className,delete ce.style,(!R||P)&&delete ce.id;const De=`${w}-wrapper`,[Ne,nt]=Qt(w,De),[at]=Ut("Upload",At.Upload),{showRemoveIcon:Pe,showPreviewIcon:ot,showDownloadIcon:st,removeIcon:it,previewIcon:lt,downloadIcon:ct,extra:dt}=typeof i=="boolean"?{}:i,ut=typeof Pe>"u"?!P:Pe,we=(m,h)=>i?l.createElement(ar,{classNames:ue,styles:pe,prefixCls:w,listType:r,items:C,previewFile:F,onPreview:c,onDownload:u,onRemove:$e,showRemoveIcon:ut,showPreviewIcon:ot,showDownloadIcon:st,removeIcon:it,previewIcon:lt,downloadIcon:ct,iconRender:E,extra:dt,locale:{...at,...x},isImageUrl:D,progress:j,appendAction:m,appendActionVisible:h,itemRender:H,disabled:P}):m,ve=O(De,T,B,Ne,nt,Ye,ue.root,{[`${w}-rtl`]:Re==="rtl",[`${w}-picture-card-wrapper`]:r==="picture-card",[`${w}-picture-circle-wrapper`]:r==="picture-circle"}),Se={...pe.root},Le={...ke,...X};if(A==="drag"){const m=O(Ne,w,`${w}-drag`,{[`${w}-drag-uploading`]:C.some(h=>h.status==="uploading"),[`${w}-drag-hover`]:re==="dragover",[`${w}-disabled`]:P,[`${w}-rtl`]:Re==="rtl"},ue.trigger);return l.createElement("span",{className:ve,ref:I,style:Se},l.createElement("div",{className:m,style:{...Le,...pe.trigger},onDrop:ye,onDragOver:ye,onDragLeave:ye},l.createElement(He,{...ce,ref:y,className:`${w}-btn`},l.createElement("div",{className:`${w}-drag-container`},R))),we())}const pt=O(w,`${w}-select`,{[`${w}-disabled`]:P,[`${w}-hidden`]:!R},ue.trigger),Oe=l.createElement("div",{className:pt,style:{...Le,...pe.trigger}},l.createElement(He,{...ce,ref:y}));return r==="picture-card"||r==="picture-circle"?l.createElement("span",{className:ve,ref:I,style:Se},we(Oe,!!R)):l.createElement("span",{className:ve,ref:I,style:Se},Oe,we())},Je=l.forwardRef(or),sr=l.forwardRef((e,t)=>{const{style:n,height:a,hasControlInside:s=!1,children:o,...i}=e,r={...n,height:a};return l.createElement(Je,{ref:t,hasControlInside:s,...i,style:r,type:"drag"},o)}),Ze=Je;Ze.Dragger=sr;Ze.LIST_IGNORE=de;export{Ze as U};
|