1import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{a as n,i as r,r as i,t as a}from"./emotion-styled.browser.esm.DsRKNFfx.js";import{t as o}from"./react-dom.DZwq-Xzd.js";import{Xt as s,c}from"./utils.94RcZhG4.js";import{_ as l,z as u}from"./protobuf.DC2L68b9.js";import{t as d}from"./types.cZoyy9Y-.js";import{t as f}from"./isEqual.CgNOpGTC.js";import{t as p}from"./zip.DLtjLZjW.js";import{n as m,t as h}from"./styled-components.B5oT30oI.js";import{t as g}from"./BaseButton.DzUQ5vsa.js";import{n as _}from"./FormClearHelper.D0Yt6KG5.js";import{t as v}from"./DynamicButtonLabel.UT8nPWDL.js";import{t as y}from"./useCalculatedDimensions.BnLCBgVi.js";import{a as b,c as x,d as S,f as C,i as w,l as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M}from"./utils.Ca1sxtey.js";import{t as N}from"./WidgetLabel.CVV1ys75.js";import{t as P}from"./WidgetLabelHelpIcon.BmvkC-YW.js";import{t as F}from"./UploadFileInfo.WAP1L8Dh.js";var I=e(t(),1),L=e(o(),1),R=a(`section`,{target:`e3v525e0`})(({isDisabled:e,isDragActive:t,theme:n})=>({position:`relative`,display:`flex`,gap:n.spacing.lg,alignItems:`flex-start`,padding:n.spacing.md,backgroundColor:n.colors.secondaryBg,borderRadius:n.radii.default,border:n.colors.widgetBorderColor?`${n.sizes.borderWidth} solid ${n.colors.widgetBorderColor}`:void 0,height:`auto`,minHeight:n.sizes.largestElementHeight,":focus":{outline:`none`},":focus-visible":{boxShadow:n.shadows.focusRingOutline},cursor:e?`not-allowed`:`pointer`,...t&&{boxShadow:`inset 0 0 0 2px ${n.colors.primary}`}})),z=a(`div`,{target:`e3v525e1`})(({theme:e})=>({position:`absolute`,top:e.spacing.threeXS,right:e.spacing.threeXS,bottom:e.spacing.threeXS,left:e.spacing.threeXS,display:`flex`,alignItems:`center`,justifyContent:`center`,backgroundColor:e.colors.secondaryBg,borderRadius:e.radii.default,zIndex:e.zIndices.priority})),B=a(`span`,{target:`e3v525e2`})(({theme:e})=>({color:e.colors.primary,fontSize:e.fontSizes.sm,fontWeight:e.fontWeights.extrabold})),V=a(`div`,{target:`e3v525e3`})({display:`flex`,alignItems:`center`,justifyContent:`flex-start`,textAlign:`left`,alignSelf:`center`,minWidth:0,flex:1}),H=a(`span`,{target:`e3v525e4`})(({theme:e,disabled:t})=>({fontSize:e.fontSizes.sm,color:t?e.colors.fadedText40:e.colors.fadedText60,display:`block`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`})),U=a(`div`,{target:`e3v525e5`})({display:`flex`,flexDirection:`column`,minWidth:0,maxWidth:`100%`}),W=a(`span`,{target:`e3v525e6`})({whiteSpace:`nowrap`}),G=a(`div`,{target:`e3v525e7`})(({theme:e})=>({lineHeight:e.lineHeights.tight})),K=2.5,q=.5;function J(e){let t=Math.floor(e),n=e-t;return`${t*K+Math.max(0,t-1)*q+(n>0?q+n*K:0)}rem`}var Y=()=>({[C]:{maxHeight:J(2.25),overflowY:`auto`}}),X=e=>({[R]:{flexDirection:`column`,alignItems:`stretch`,height:`fit-content`,gap:e.spacing.md},[V]:{alignSelf:`stretch`},[C]:{flexDirection:`column`,flexWrap:`nowrap`,alignItems:`flex-start`,maxHeight:`none`,overflowY:`visible`,gap:e.spacing.sm},[M]:{display:`flex`,flexDirection:`column`,flexWrap:`nowrap`,alignItems:`flex-start`,gap:e.spacing.sm,maxHeight:J(5.25),overflowY:`auto`,width:e.sizes.full},[S]:{width:e.sizes.full},[T]:{width:e.sizes.full}}),Z=a(`div`,{target:`e3v525e8`})(({theme:e,width:t})=>({...Y(),...t<c(`23rem`)?X(e):{}})),Q=(0,I.memo)(({acceptedTypes:e,maxSizeBytes:t,disabled:i})=>r(V,{"data-testid":`stFileUploaderDropzoneInstructions`,children:r(U,{children:n(H,{disabled:i,children:[`${D(t,k.Byte,0)} per file`,e.length?` ⢠${w(e)}`:null]})})})),ee=(0,I.memo)(({onDrop:e,multiple:t,acceptedTypes:a,maxSizeBytes:o,disabled:s,label:c,acceptDirectory:l=!1,uploadedFiles:u,hasFiles:d=!1})=>r(O,{onDrop:e,multiple:t,accept:j(a),maxSize:o,disabled:s,useFsAccessApi:!1,children:({getRootProps:e,getInputProps:f,isDragActive:p})=>{let _=f({multiple:t||!!l});return n(R,{...e({tabIndex:-1}),"data-testid":`stFileUploaderDropzone`,isDisabled:s,isDragActive:p,"aria-label":c,"aria-disabled":s,children:[r(`input`,{"data-testid":`stFileUploaderDropzoneInput`,..._,...l&&{webkitdirectory:``}}),p&&r(z,{children:r(B,{children:l?`Drag and drop directories here`:t?`Drag and drop files here`:`Drag and drop a file here`})}),d&&u?u:n(i,{children:[r(W,{children:r(g,{kind:h.SECONDARY,disabled:s,size:m.MEDIUM,children:r(v,{icon:`:material/upload:`,label:l?`Upload directories`:`Upload`})})}),r(Q,{acceptedTypes:a,maxSizeBytes:o,disabled:s})]})]})}})),te=(0,I.memo)(({items:e,onDelete:t,disabled:n,trailingContent:i})=>r(G,{children:r(E,{items:e,onDelete:t,disabled:n,trailingContent:i})}
1)),ne=(e,t)=>{let n=t.getFileUploaderStateValue(e);if(d(n))return{files:[],nextLocalId:1};let{uploadedFileInfo:r}=n;if(d(r)||r.length===0)return{files:[],nextLocalId:1};let i=1;return{files:r.map(e=>{let t=e.name,n=e.size,r=e.fileId,a=e.fileUrls,o=new F(t,n,i,{type:`uploaded`,fileId:r,fileUrls:a});return i+=1,o}),nextLocalId:i}},$=e=>new l({uploadedFileInfo:e.filter(e=>e.status.type===`uploaded`).map(e=>{let{name:t,size:n,status:r}=e,{fileId:i,fileUrls:a}=r;return new u({fileId:i,fileUrls:a,name:t,size:n})})}),re=(0,I.memo)(({disabled:e,element:t,widgetMgr:i,uploadClient:a,fragmentId:o})=>{let{width:c,elementRef:l}=y(),{files:u,nextLocalId:S}=(0,I.useMemo)(()=>ne(t,i),[t,i]),C=(0,I.useRef)(S),[w,T]=(0,I.useState)(()=>u),E=(0,I.useRef)(w);(0,I.useEffect)(()=>{E.current=w},[w]);let[D,O]=(0,I.useState)(!1),j=(0,I.useCallback)(()=>{let e=C.current;return C.current+=1,e},[]),M=(0,I.useMemo)(()=>{let e=t.maxUploadSizeMb;return x(e,k.Megabyte,k.Byte)},[t.maxUploadSizeMb]),R=(0,I.useCallback)(e=>{(0,L.flushSync)(()=>{T(t=>{let n=typeof e==`function`?e(t):e;return E.current=n,n})})},[]),z=(0,I.useCallback)(e=>{(0,L.flushSync)(()=>{O(e)})},[O]),B=(0,I.useCallback)(e=>{R(t=>[...t,e])},[R]),V=(0,I.useCallback)(e=>{e.length!==0&&R(t=>[...t,...e])},[R]),H=(0,I.useCallback)(e=>{R(t=>t.filter(t=>t.id!==e))},[R]),U=(0,I.useCallback)((e,t)=>{R(n=>n.map(n=>n.id===e?t:n))},[R]),W=(0,I.useCallback)(e=>E.current.find(t=>t.id===e),[]),G=w.some(e=>e.status.type===`uploading`)||D?`updating`:`ready`;(0,I.useEffect)(()=>{i.getFileUploaderStateValue(t)===void 0&&i.setFileUploaderStateValue(t,$(E.current),{fromUi:!1},o)},[i,t,o]),(0,I.useEffect)(()=>{if(G!==`ready`)return;let e=$(w);f(e,i.getFileUploaderStateValue(t))||i.setFileUploaderStateValue(t,e,{fromUi:!0},o)},[G,w,i,t,o]),_({element:t,widgetMgr:i,onFormCleared:(0,I.useCallback)(()=>{R(()=>[]);let e=$([]);i.setFileUploaderStateValue(t,e,{fromUi:!0},o)},[t,o,R,i])});let K=t.type,q=(0,I.useCallback)(e=>{let t=[],n=[];return e.forEach(e=>{A(e,K)?t.push(e):n.push({file:e,errors:[{code:`file-invalid-type`,message:`${e.type} files are not allowed.`}]})}),{accepted:t,rejected:n}},[K]),J=(0,I.useCallback)((e,t)=>{let n=W(e);d(n)||n.status.type!==`uploading`||U(n.id,n.setStatus({type:`uploaded`,fileId:t.fileId,fileUrls:t}))},[W,U]),Y=(0,I.useCallback)((e,n)=>{let r=new AbortController,i=new F(n.webkitRelativePath||n.name,n.size,j(),{type:`uploading`,abortController:r,progress:0});B(i),a.uploadFile(t,e.uploadUrl,n,void 0,r.signal).then(()=>J(i.id,e)).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||U(i.id,i.setStatus({type:`error`,errorMessage:e?e.toString():`Unknown error`}))})},[B,t,j,J,U,a]),X=(0,I.useCallback)(t=>{if(e)return;let n=W(t);d(n)||(n.status.type===`uploading`&&n.status.abortController.abort(),n.status.type===`uploaded`&&n.status.fileUrls.deleteUrl&&a.deleteFile(n.status.fileUrls.deleteUrl),H(t))},[e,W,H,a]),Q=(0,I.useCallback)((e,n)=>{let{multipleFiles:r}=t,i=!!t.acceptDirectory,o=[...e],s=[...n];if(i&&o.length>0){let{accepted:e,rejected:t}=q(o);o=e,s=[...s,...t]}if(!r&&o.length===0&&s.length>1){let e=s.findIndex(e=>e.errors.length===1&&e.errors[0].code===`too-many-files`);e>=0&&(o.push(s[e].file),s.splice(e,1))}if(a.fetchFileURLs(o).then(e=>{if(!r&&o.length>0){let e=E.current.find(e=>e.status.type!==`error`);if(e){z(!0);try{X(e.id)}finally{z(!1)}}}
1p(e,o).forEach(([e,t])=>{Y(e,t)})}).catch(e=>{V(o.map(t=>new F(t.name,t.size,j(),{type:`error`,errorMessage:e})))}),s.length>0){let e=s.map(e=>b(e,j(),M));V(e)}},[V,X,t,q,M,j,a,Y,z]);return n(Z,{className:`stFileUploader`,"data-testid":`stFileUploader`,width:c,ref:l,children:[r(N,{label:t.label,disabled:e,labelVisibility:s(t.labelVisibility?.value),children:t.help&&r(P,{content:t.help,label:t.label})}),r(ee,{onDrop:Q,multiple:t.multipleFiles,acceptedTypes:K,maxSizeBytes:M,label:t.label,disabled:e,acceptDirectory:!!t.acceptDirectory,hasFiles:w.length>0,uploadedFiles:w.length>0?r(te,{items:w,onDelete:X,disabled:e,trailingContent:r(g,{kind:h.BORDERLESS_ICON,disabled:e,size:m.XSMALL,"aria-label":`Add files`,children:r(v,{icon:`:material/add:`})})}):null})]})});export{re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.