streamlit-nightly 1.43.3.dev20250312__py3-none-any.whl → 1.43.3.dev20250313__py3-none-any.whl
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.
- streamlit/auth_util.py +2 -1
- streamlit/commands/experimental_query_params.py +1 -1
- streamlit/commands/logo.py +3 -3
- streamlit/components/v1/__init__.py +1 -3
- streamlit/config.py +3 -2
- streamlit/config_option.py +1 -3
- streamlit/connections/snowflake_connection.py +0 -1
- streamlit/connections/sql_connection.py +0 -1
- streamlit/dataframe_util.py +7 -6
- streamlit/delta_generator_singletons.py +2 -2
- streamlit/elements/arrow.py +0 -1
- streamlit/elements/exception.py +3 -1
- streamlit/elements/form.py +3 -3
- streamlit/elements/json.py +2 -2
- streamlit/elements/layouts.py +0 -5
- streamlit/elements/lib/built_in_chart_utils.py +1 -2
- streamlit/elements/lib/column_config_utils.py +0 -3
- streamlit/elements/lib/column_types.py +6 -39
- streamlit/elements/lib/image_utils.py +2 -1
- streamlit/elements/lib/options_selector_utils.py +6 -3
- streamlit/elements/lib/subtitle_utils.py +2 -0
- streamlit/elements/lib/utils.py +0 -2
- streamlit/elements/media.py +2 -1
- streamlit/elements/metric.py +0 -1
- streamlit/elements/progress.py +1 -1
- streamlit/elements/text.py +2 -2
- streamlit/elements/vega_charts.py +2 -1
- streamlit/elements/widgets/audio_input.py +2 -1
- streamlit/elements/widgets/button.py +0 -1
- streamlit/elements/widgets/button_group.py +2 -3
- streamlit/elements/widgets/data_editor.py +2 -3
- streamlit/elements/widgets/slider.py +1 -1
- streamlit/elements/widgets/text_widgets.py +1 -0
- streamlit/elements/write.py +0 -1
- streamlit/errors.py +4 -2
- streamlit/external/langchain/streamlit_callback_handler.py +1 -2
- streamlit/file_util.py +4 -2
- streamlit/navigation/page.py +0 -1
- streamlit/platform.py +1 -3
- streamlit/runtime/caching/cache_data_api.py +5 -5
- streamlit/runtime/caching/cache_errors.py +1 -1
- streamlit/runtime/caching/cache_resource_api.py +4 -4
- streamlit/runtime/caching/cache_utils.py +6 -4
- streamlit/runtime/caching/storage/cache_storage_protocol.py +6 -6
- streamlit/runtime/caching/storage/dummy_cache_storage.py +2 -2
- streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py +6 -6
- streamlit/runtime/caching/storage/local_disk_cache_storage.py +6 -6
- streamlit/runtime/connection_factory.py +0 -1
- streamlit/runtime/context.py +1 -1
- streamlit/runtime/credentials.py +1 -1
- streamlit/runtime/forward_msg_cache.py +1 -1
- streamlit/runtime/forward_msg_queue.py +2 -1
- streamlit/runtime/fragment.py +2 -1
- streamlit/runtime/memory_media_file_storage.py +2 -2
- streamlit/runtime/metrics_util.py +2 -2
- streamlit/runtime/runtime_util.py +1 -1
- streamlit/runtime/scriptrunner/script_runner.py +1 -1
- streamlit/runtime/scriptrunner_utils/exceptions.py +1 -1
- streamlit/runtime/scriptrunner_utils/script_run_context.py +1 -0
- streamlit/runtime/secrets.py +5 -3
- streamlit/runtime/state/common.py +1 -1
- streamlit/runtime/state/safe_session_state.py +1 -1
- streamlit/runtime/state/session_state.py +4 -3
- streamlit/runtime/stats.py +1 -1
- streamlit/runtime/uploaded_file_manager.py +4 -3
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{FileDownload.esm.C9csNfwR.js → FileDownload.esm.imTamlxP.js} +1 -1
- streamlit/static/static/js/{FileHelper.CTWNHaVI.js → FileHelper.BwPSCUvG.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.1VkFJY3v.js → FormClearHelper.DB5q2Avl.js} +1 -1
- streamlit/static/static/js/{Hooks.vPqq3xQ5.js → Hooks.Cxijo2P7.js} +1 -1
- streamlit/static/static/js/{InputInstructions.7jABRwB0.js → InputInstructions.B3OvMrKL.js} +1 -1
- streamlit/static/static/js/{ProgressBar.BWY8ITDS.js → ProgressBar.DmTol130.js} +1 -1
- streamlit/static/static/js/{RenderInPortalIfExists.CP_sn1OG.js → RenderInPortalIfExists.B8t62565.js} +1 -1
- streamlit/static/static/js/{Toolbar.DzqMcgvB.js → Toolbar.CbG49UPG.js} +1 -1
- streamlit/static/static/js/{base-input.DjuthXF0.js → base-input.D7sJ1S2g.js} +1 -1
- streamlit/static/static/js/{checkbox.BddRUN3_.js → checkbox.0Qx7AQxA.js} +1 -1
- streamlit/static/static/js/{createSuper.BAGgahBq.js → createSuper.DYiyAta_.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.Bscjz8_-.js → data-grid-overlay-editor.DH61CZYo.js} +1 -1
- streamlit/static/static/js/{downloader.BgDSv-Ig.js → downloader.ClUad3SK.js} +1 -1
- streamlit/static/static/js/{es6.3kVHyEdR.js → es6.oePMPTIo.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.n2oqEwdf.js → iframeResizer.contentWindow.DWkIX4K7.js} +1 -1
- streamlit/static/static/js/{index.C8ZHYetm.js → index.1VrMb7Gq.js} +1 -1
- streamlit/static/static/js/{index.zrNj-omI.js → index.62zz5frt.js} +1 -1
- streamlit/static/static/js/{index.k2DDVmzp.js → index.BJRyQckV.js} +1 -1
- streamlit/static/static/js/{index.CrZncPLs.js → index.BQVZQA1G.js} +1 -1
- streamlit/static/static/js/{index.UJT9uVs_.js → index.BSZRb65z.js} +1 -1
- streamlit/static/static/js/{index.N6CP_9Qh.js → index.BUJE3tb_.js} +1 -1
- streamlit/static/static/js/{index.mMuChmJi.js → index.BWsaTYC-.js} +1 -1
- streamlit/static/static/js/{index.ChDimwy6.js → index.BccrUqFL.js} +1 -1
- streamlit/static/static/js/{index.CFbiFnmq.js → index.BhzKPoO6.js} +1 -1
- streamlit/static/static/js/{index.FJszpQ-y.js → index.BpNXx3zc.js} +5 -5
- streamlit/static/static/js/{index.B1ZLFKil.js → index.BzEstIKX.js} +1 -1
- streamlit/static/static/js/{index.j6cgFK9c.js → index.C-ilKj2l.js} +1 -1
- streamlit/static/static/js/{index.D3EE2F77.js → index.CCAIkxXD.js} +2367 -1541
- streamlit/static/static/js/{index.S_LaABz9.js → index.CEXlj4h2.js} +1 -1
- streamlit/static/static/js/{index.CYrF9jN2.js → index.CEtBn4Yo.js} +1 -1
- streamlit/static/static/js/{index.D3uVQMaA.js → index.CM7PC5PD.js} +1 -1
- streamlit/static/static/js/{index.Dv6XiWKs.js → index.CSLXWDcG.js} +1 -1
- streamlit/static/static/js/{index.Cj7yHfOR.js → index.CqywW5KK.js} +1 -1
- streamlit/static/static/js/{index.D7k3QVrz.js → index.CyRCgpSs.js} +1 -1
- streamlit/static/static/js/{index.pEU90S1o.js → index.CzFs8nXc.js} +3 -3
- streamlit/static/static/js/{index.DAghU1FB.js → index.Czxn5B2N.js} +1 -1
- streamlit/static/static/js/{index.B8IuPu4x.js → index.D0OLo5Dp.js} +1 -1
- streamlit/static/static/js/{index.BaYVwylD.js → index.D2JlVfHE.js} +1 -1
- streamlit/static/static/js/{index.OtBp-Blq.js → index.DJRmF7dm.js} +1 -1
- streamlit/static/static/js/{index.C28BRw13.js → index.Dd9D963h.js} +1 -1
- streamlit/static/static/js/{index.DAAc9Gb3.js → index.DhcpqbOJ.js} +1 -1
- streamlit/static/static/js/{index.DbI6X421.js → index.DlEF0vUx.js} +1 -1
- streamlit/static/static/js/{index.BNTyamf9.js → index.DnJimAdR.js} +1 -1
- streamlit/static/static/js/{index.BfTunuGf.js → index.DoqMrowT.js} +1 -1
- streamlit/static/static/js/{index.BPcgpI5G.js → index.DqsHy8ck.js} +1 -1
- streamlit/static/static/js/{index.3k9e_sFT.js → index.DtS10fdK.js} +1 -1
- streamlit/static/static/js/{index.BQXOwXQG.js → index.XZw2NTV4.js} +1 -1
- streamlit/static/static/js/{index.svH5ea22.js → index.YB9Oe71d.js} +1 -1
- streamlit/static/static/js/{index.DlXteNnv.js → index.axjxDsFs.js} +1 -1
- streamlit/static/static/js/{index.Bd5GUMH8.js → index.kB2IGVOe.js} +1 -1
- streamlit/static/static/js/{index.0JqsAt5p.js → index.tVO_vJdT.js} +1 -1
- streamlit/static/static/js/{index.CrjCtGqg.js → index.uPQFE7KD.js} +1 -1
- streamlit/static/static/js/{input.A7Xel5Mz.js → input.od7ufwko.js} +1 -1
- streamlit/static/static/js/{memory.DKAi1aOw.js → memory.B4tdC6o-.js} +1 -1
- streamlit/static/static/js/{mergeWith.BOXngkwE.js → mergeWith.BIQlVIWW.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.Dr9nZLr4.js → number-overlay-editor.yJDCpy9b.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.Dmq70n5Q.js → possibleConstructorReturn.CarGSmuW.js} +1 -1
- streamlit/static/static/js/{sandbox.OiNVhKVk.js → sandbox.DMCKOK6i.js} +1 -1
- streamlit/static/static/js/{textarea.BvcErhuX.js → textarea.CKKbJt6B.js} +1 -1
- streamlit/static/static/js/{timepicker.BndxQ_56.js → timepicker.BgsARtBm.js} +1 -1
- streamlit/static/static/js/{toConsumableArray.Bvyh5k2t.js → toConsumableArray.DXHhbr1a.js} +1 -1
- streamlit/static/static/js/{uniqueId.BJXawxf6.js → uniqueId.Cb5oTCCd.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.-z6NaxAe.js → useBasicWidgetState.8rZ80dWq.js} +1 -1
- streamlit/static/static/js/{useOnInputChange.DvBUKld6.js → useOnInputChange.Bc5KC47X.js} +1 -1
- streamlit/static/static/js/{withFullScreenWrapper.CubK7zml.js → withFullScreenWrapper.CSP3iCNz.js} +1 -1
- streamlit/string_util.py +3 -2
- streamlit/testing/v1/element_tree.py +30 -30
- streamlit/testing/v1/util.py +2 -1
- streamlit/time_util.py +1 -3
- streamlit/type_util.py +2 -1
- streamlit/user_info.py +0 -1
- streamlit/watcher/event_based_path_watcher.py +1 -1
- streamlit/web/bootstrap.py +3 -1
- streamlit/web/cache_storage_manager_config.py +1 -1
- streamlit/web/cli.py +2 -2
- streamlit/web/server/authlib_tornado_integration.py +1 -1
- streamlit/web/server/browser_websocket_handler.py +2 -1
- streamlit/web/server/routes.py +2 -2
- streamlit/web/server/server_util.py +2 -4
- {streamlit_nightly-1.43.3.dev20250312.dist-info → streamlit_nightly-1.43.3.dev20250313.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.43.3.dev20250312.dist-info → streamlit_nightly-1.43.3.dev20250313.dist-info}/RECORD +151 -151
- {streamlit_nightly-1.43.3.dev20250312.data → streamlit_nightly-1.43.3.dev20250313.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.43.3.dev20250312.dist-info → streamlit_nightly-1.43.3.dev20250313.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.43.3.dev20250312.dist-info → streamlit_nightly-1.43.3.dev20250313.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.43.3.dev20250312.dist-info → streamlit_nightly-1.43.3.dev20250313.dist-info}/top_level.txt +0 -0
@@ -1 +1 @@
|
|
1
|
-
import{r as l,E as V,_ as $,n as u,A as ft,y as N,j as n,ba as J,bu as mt,B as z,bp as Q,b5 as Z,bo as U,a$ as vt,bG as yt,bj as wt,bH as I,bs as Ct,F as tt,bh as It,bI as xt,L as D,bl as bt,bk as St}from"./index.pEU90S1o.js";import{g as zt,F as k,C as Ft,I as Et,E as Ut,a as Ht,s as Tt,u as Bt,b as Dt}from"./FileHelper.CTWNHaVI.js";import{I as Lt}from"./InputInstructions.7jABRwB0.js";import{i as Rt}from"./inputUtils.CQWz5UKz.js";import{a as Y}from"./index.D8rVyQy1.js";import{U as et}from"./UploadFileInfo.C-jY39rj.js";import{T as Mt}from"./textarea.BvcErhuX.js";import"./base-input.DjuthXF0.js";var ot=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),l.createElement("path",{d:"M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5a2.5 2.5 0 015 0v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5a2.5 2.5 0 005 0V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z"}))});ot.displayName="AttachFile";var nt=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("path",{d:"M11 15h2v2h-2v-2zm0-8h2v6h-2V7zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"}))});nt.displayName="ErrorOutline";var at=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("rect",{width:24,height:24,fill:"none"}),l.createElement("path",{d:"M3 5.51v3.71c0 .46.31.86.76.97L11 12l-7.24 1.81c-.45.11-.76.51-.76.97v3.71c0 .72.73 1.2 1.39.92l15.42-6.49c.82-.34.82-1.5 0-1.84L4.39 4.58C3.73 4.31 3 4.79 3 5.51z"}))});at.displayName="Send";const kt=u("div",{target:"e1togvvn0"})("border:none;position:relative;display:flex;"),Vt=u("div",{target:"e1togvvn1"})(({theme:t,extended:e})=>({border:`${t.sizes.borderWidth} solid`,borderColor:t.colors.widgetBorderColor??t.colors.transparent,borderRadius:t.radii.chatInput,backgroundColor:t.colors.secondaryBg,position:"relative",flexGrow:1,display:"flex",alignItems:"center",paddingLeft:t.spacing.lg,maxHeight:e?"none":t.sizes.minElementHeight,gap:t.spacing.sm,overflow:"hidden",":focus-within":{borderColor:t.colors.primary}})),$t=u("button",{target:"e1togvvn2"})(({theme:t,disabled:e,extended:r})=>{const c=ft(t),[f,p]=c?[t.colors.gray60,t.colors.gray80]:[t.colors.gray80,t.colors.gray40];return{border:"none",backgroundColor:t.colors.transparent,borderTopRightRadius:r?"0":t.radii.chatInput,borderTopLeftRadius:r?t.radii.default:"0",borderBottomRightRadius:t.radii.chatInput,display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:t.lineHeights.none,margin:t.spacing.none,padding:t.spacing.sm,color:e?f:p,pointerEvents:"auto","&:focus":{outline:"none"},":focus":{outline:"none"},"&:focus-visible":{backgroundColor:c?t.colors.gray10:t.colors.gray90},"&:hover":{color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{backgroundColor:t.colors.transparent,borderColor:t.colors.transparent,color:t.colors.gray,cursor:"not-allowed"}}}),Nt=u("div",{target:"e1togvvn3"})(({theme:t})=>({display:"flex",alignItems:"flex-end",height:"100%",position:"absolute",right:0,marginBottom:`-${t.sizes.borderWidth}`,pointerEvents:"none"})),At=u("div",{target:"e1togvvn4"})(({theme:t})=>({position:"absolute",bottom:"0px",right:`calc(${t.iconSizes.xl} + 2 * ${t.spacing.sm} + ${t.spacing.sm})`})),Wt=u("div",{target:"ewqvugz0"})(({theme:t,height:e})=>({backgroundColor:t.colors.transparent,position:"absolute",left:0,bottom:0,minHeight:`max(${t.sizes.emptyDropdownHeight}, ${e})`,width:"100%",zIndex:t.zIndices.priority})),qt=u("div",{target:"ewqvugz1"})(({theme:t,height:e})=>({border:`${t.sizes.borderWidth} solid`,borderColor:t.colors.primary,borderRadius:t.radii.chatInput,backgroundColor:t.colors.secondaryBg,color:t.colors.primary,display:"flex",alignItems:"center",justifyContent:"center",height:e,width:"100%",fontWeight:t.fontWeights.bold})),Pt=u("div",{target:"ewqvugz2"})(({theme:t,disabled:e})=>({display:"flex",alignItems:"top",height:"100%",marginTop:`-${t.sizes.borderWidth}`,cursor:e?"not-allowed":"auto"})),Kt=u("div",{target:"ewqvugz3"})(({disabled:t})=>({pointerEvents:t?"none":"auto"})),Ot=u("div",{target:"ewqvugz4"})(({theme:t})=>({marginTop:"0.625em",marginLeft:t.spacing.sm,height:t.spacing.xl,width:t.sizes.borderWidth,backgroundColor:t.colors.fadedText20})),_t=u("div",{target:"ewqvugz5"})(({theme:t})=>({left:0,right:0,lineHeight:t.lineHeights.tight,paddingLeft:t.spacing.sm,paddingRight:t.spacing.sm,overflowX:"auto"})),Xt=u("div",{target:"ewqvugz6"})(({})=>({display:"flex"})),Gt=u("div",{target:"ewqvugz7"})(({})=>({flex:"0 0 auto"})),jt=u("div",{target:"ewqvugz8"})(({theme:t})=>({display:"flex",alignItems:"center",padding:t.spacing.sm,gap:t.spacing.twoXS})),Yt=u("div",{target:"ewqvugz9"})(({theme:t})=>({color:t.colors.fadedText60})),Jt=u("div",{target:"ewqvugz10"})(({theme:t,fileStatus:e})=>({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:e.type==="uploaded"?t.colors.bodyText:t.colors.fadedText60})),Qt=u("div",{target:"ewqvugz11"})(({theme:t})=>({marginRight:t.spacing.md,color:t.colors.fadedText60})),Zt=u("small",{target:"ewqvugz12"})(({theme:t})=>({display:"flex",alignItems:"center",maxHeight:t.sizes.smallElementHeight,color:t.colors.fadedText60,"& :hover":{color:t.colors.bodyText}}));function te({children:t,content:e}){const r=N();return n(mt,{content:e,placement:J.TOP,overrides:{Body:{style:{top:`-${r.sizes.minElementHeight}`}}},children:t})}const ee=({fileInfo:t})=>{const e=N(),{type:r}=t.status;switch(r){case"uploading":return n(yt,{usingCustomTheme:!1,"data-testid":"stChatInputFileIconSpinner",size:"lg",margin:"0",padding:"0"});case"error":return n(te,{content:t.status.errorMessage,children:n(U,{color:e.colors.red,content:nt,size:"lg"})});case"uploaded":return n(U,{content:Et,size:"lg"});default:return vt(r),null}},oe=({fileInfo:t,onDelete:e})=>z(jt,{className:"stChatInputFile","data-testid":"stChatInputFile",children:[n(Yt,{children:n(ee,{fileInfo:t})}),n(Jt,{className:"stChatInputFileName","data-testid":"stChatInputFileName",title:t.name,fileStatus:t.status,children:t.name}),n(Qt,{children:zt(t.size,k.Byte)}),n(Zt,{"data-testid":"stChatInputDeleteBtn",children:n(Q,{onClick:()=>e(t.id),kind:Z.MINIMAL,children:n(U,{content:Ft,size:"lg"})})})]}),ne=({items:t,onDelete:e})=>n(_t,{"data-testid":"stChatUploadedFiles",children:n(Xt,{children:t.map(r=>n(Gt,{children:n(oe,{fileInfo:r,onDelete:e})},r.id))})}),ae=({getNextLocalFileId:t,addFiles:e,updateFile:r,uploadClient:c,element:f,onUploadProgress:p,onUploadComplete:m})=>(x,h)=>{const v=Y.CancelToken.source(),g=new et(h.name,h.size,t(),{type:"uploading",cancelToken:v,progress:1});e([g]),c.uploadFile({formId:"",...f},x.uploadUrl,h,d=>p(d,g.id),v.token).then(()=>m(g.id,x)).catch(d=>{Y.isCancel(d)||r(g.id,g.setStatus({type:"error",errorMessage:d?d.toString():"Unknown error"}))})},re=({acceptMultipleFiles:t,maxFileSize:e,uploadClient:r,uploadFile:c,addFiles:f,getNextLocalFileId:p,deleteExistingFiles:m,onUploadComplete:x})=>(h,v)=>{if(!t&&h.length===0&&v.length>1){const g=v.findIndex(d=>{var y;return((y=d.errors)==null?void 0:y[0].code)===Ut.TooManyFiles});g>=0&&(h.push(v[g].file),v.splice(g,1))}if(!t&&h.length>0&&m(),r.fetchFileURLs(h).then(g=>{wt(g,h).forEach(([d,y])=>{c(d,y)})}).catch(g=>{f(h.map(d=>new et(d.name,d.size,p(),{type:"error",errorMessage:g})))}),v.length>0){const g=v.map(d=>Ht(d,p(),e));f(g)}x()},ie=({getRootProps:t,getInputProps:e,acceptFile:r,disabled:c,theme:f})=>z(Pt,{disabled:c,children:[z(Kt,{"data-testid":"stChatInputFileUploadButton",disabled:c,...t(),children:[n("input",{...e()}),n(Ct,{content:`Upload or drag and drop ${r===I.Multiple?"files":"a file"}`,placement:J.TOP,onMouseEnterDelay:500,children:n(Q,{kind:Z.MINIMAL,disabled:c,children:n(U,{content:ot,size:"lg",color:c?f.colors.fadedText40:f.colors.fadedText60})})})]}),n(Ot,{})]}),se=({getRootProps:t,getInputProps:e,acceptFile:r,inputHeight:c})=>z(tt,{children:[n(Wt,{height:c,...t(),children:n("input",{...e()})}),n(qt,{height:c,children:`Drag and drop ${r===I.Multiple?"files":"a file"} here`})]}),le=6.5,L=1,R=(t,e,r)=>r.map(c=>c.id===t?e:c),M=(t,e)=>e.find(r=>r.id===t);function de({disabled:t,element:e,widgetMgr:r,fragmentId:c,uploadClient:f}){const p=N(),m=l.useRef(null),x=l.useRef(0),h=l.useRef({minHeight:0,maxHeight:0}),[v,g]=It(),[d,y]=l.useState(e.default),[F,A]=l.useState(0),[H,rt]=l.useState(!1),[b,S]=l.useState([]),[E,T]=l.useState(!1),B=l.useMemo(()=>b.some(o=>o.status.type==="uploading")?!1:d!==""||b.length>0,[b,d]),C=xt(e.acceptFile),W=Tt(e.maxUploadSizeMb,k.Megabyte,k.Byte),q=l.useCallback(o=>S(a=>[...a,...o]),[]),P=l.useCallback(o=>{S(a=>{const s=M(o,a);return D(s)?a:(s.status.type==="uploading"&&s.status.cancelToken.cancel(),s.status.type==="uploaded"&&s.status.fileUrls.deleteUrl&&f.deleteFile(s.status.fileUrls.deleteUrl),a.filter(i=>i.id!==o))})},[f]),it=()=>{const o=b.filter(a=>a.status.type==="uploaded").map(a=>{const{name:s,size:i,status:w}=a,{fileId:gt,fileUrls:ht}=w;return new bt({fileId:gt,fileUrls:ht,name:s,size:i})});return new St({uploadedFileInfo:o})},K=()=>x.current++,st=re({acceptMultipleFiles:C===I.Multiple,maxFileSize:W,uploadClient:f,uploadFile:ae({getNextLocalFileId:K,addFiles:q,updateFile:(o,a)=>{S(s=>R(o,a,s))},uploadClient:f,element:e,onUploadProgress:(o,a)=>{S(s=>{const i=M(a,s);if(D(i)||i.status.type!=="uploading")return s;const w=Math.round(o.loaded*100/o.total);return i.status.progress===w?s:R(a,i.setStatus({type:"uploading",cancelToken:i.status.cancelToken,progress:w}),s)})},onUploadComplete:(o,a)=>{S(s=>{const i=M(o,s);return D(i)||i.status.type!=="uploading"?s:R(i.id,i.setStatus({type:"uploaded",fileId:a.fileId,fileUrls:a}),s)})}}),addFiles:q,getNextLocalFileId:K,deleteExistingFiles:()=>b.forEach(o=>P(o.id)),onUploadComplete:()=>{m.current&&m.current.focus()}}),{getRootProps:O,getInputProps:_}=Bt({onDrop:st,multiple:C===I.Multiple,accept:Dt(e.fileType),maxSize:W}),lt=()=>{let o=0;const{current:a}=m;if(a){const s=a.placeholder;a.placeholder="",a.style.height="auto",o=a.scrollHeight,a.placeholder=s,a.style.height=""}return o},X=()=>{if(m.current&&m.current.focus(),!B||t)return;const o={data:d,fileUploaderState:it()};r.setChatInputValue(e,o,{fromUi:!0},c),S([]),y(""),A(0)},dt=o=>{const{metaKey:a,ctrlKey:s,shiftKey:i}=o;Rt(o)&&!i&&!s&&!a&&(o.preventDefault(),X())},ct=o=>{const{value:a}=o.target,{maxChars:s}=e;s!==0&&a.length>s||(y(a),A(lt()))};l.useEffect(()=>{if(e.setValue){e.setValue=!1;const o=e.value||"";y(o)}},[e]),l.useLayoutEffect(()=>{if(m.current){const{offsetHeight:o}=m.current;h.current.minHeight=o,h.current.maxHeight=o*le}},[m]),l.useEffect(()=>{const o=i=>{var w;i.preventDefault(),i.stopPropagation(),!E&&((w=i.dataTransfer)!=null&&w.types.includes("Files"))&&T(!0)},a=i=>{i.preventDefault(),i.stopPropagation(),E&&(i.clientX<=0&&i.clientY<=0||i.clientX>=window.innerWidth&&i.clientY>=window.innerHeight)&&T(!1)},s=i=>{i.preventDefault(),i.stopPropagation(),E&&T(!1)};return window.addEventListener("dragover",o),window.addEventListener("drop",s),window.addEventListener("dragleave",a),()=>{window.removeEventListener("dragover",o),window.removeEventListener("drop",s),window.removeEventListener("dragleave",a)}},[E]),l.useLayoutEffect(()=>{const{minHeight:o}=h.current;rt(F>0&&m.current?Math.abs(F-o)>L:!1)},[F]);const{placeholder:G,maxChars:pt}=e,{maxHeight:j}=h.current,ut=C!==I.None&&E;return z(tt,{children:[C===I.None?null:n(ne,{items:[...b],onDelete:P}),n(kt,{className:"stChatInput","data-testid":"stChatInput",ref:g,children:ut?n(se,{getRootProps:O,getInputProps:_,acceptFile:C,inputHeight:H?`${F+L}px`:p.sizes.minElementHeight}):z(Vt,{extended:H,children:[C===I.None?null:n(ie,{getRootProps:O,getInputProps:_,acceptFile:C,disabled:t,theme:p}),n(Mt,{inputRef:m,value:d,placeholder:G,onChange:ct,onKeyDown:dt,"aria-label":G,disabled:t,rows:1,overrides:{Root:{style:{minHeight:p.sizes.minElementHeight,outline:"none",borderLeftWidth:"0",borderRightWidth:"0",borderTopWidth:"0",borderBottomWidth:"0"}},Input:{props:{"data-testid":"stChatInputTextArea"},style:{lineHeight:p.lineHeights.inputWidget,"::placeholder":{opacity:"0.7"},height:H?`${F+L}px`:"auto",maxHeight:j?`${j}px`:"none",paddingLeft:p.spacing.none,paddingBottom:p.spacing.sm,paddingTop:p.spacing.sm,paddingRight:`calc(${p.iconSizes.xl} + 2 * ${p.spacing.sm} + ${p.spacing.sm})`}}}}),v>p.breakpoints.hideWidgetDetails&&n(At,{children:n(Lt,{dirty:B,value:d,maxLength:pt,type:"chat",inForm:!1})}),n(Nt,{children:n($t,{onClick:X,disabled:!B||t,extended:H,"data-testid":"stChatInputSubmitButton",children:n(U,{content:at,size:"xl",color:"inherit"})})})]})})]})}const ye=l.memo(de);export{ye as default};
|
1
|
+
import{r as l,E as V,_ as $,n as u,A as ft,y as N,j as n,ba as J,bu as mt,B as z,bp as Q,b5 as Z,bo as U,a$ as vt,bG as yt,bj as wt,bH as I,bs as Ct,F as tt,bh as It,bI as xt,L as D,bl as bt,bk as St}from"./index.CzFs8nXc.js";import{g as zt,F as k,C as Ft,I as Et,E as Ut,a as Ht,s as Tt,u as Bt,b as Dt}from"./FileHelper.BwPSCUvG.js";import{I as Lt}from"./InputInstructions.B3OvMrKL.js";import{i as Rt}from"./inputUtils.CQWz5UKz.js";import{a as Y}from"./index.D8rVyQy1.js";import{U as et}from"./UploadFileInfo.C-jY39rj.js";import{T as Mt}from"./textarea.CKKbJt6B.js";import"./base-input.D7sJ1S2g.js";var ot=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),l.createElement("path",{d:"M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5a2.5 2.5 0 015 0v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5a2.5 2.5 0 005 0V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z"}))});ot.displayName="AttachFile";var nt=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("path",{d:"M11 15h2v2h-2v-2zm0-8h2v6h-2V7zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"}))});nt.displayName="ErrorOutline";var at=l.forwardRef(function(t,e){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return l.createElement(V,$({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:e}),l.createElement("rect",{width:24,height:24,fill:"none"}),l.createElement("path",{d:"M3 5.51v3.71c0 .46.31.86.76.97L11 12l-7.24 1.81c-.45.11-.76.51-.76.97v3.71c0 .72.73 1.2 1.39.92l15.42-6.49c.82-.34.82-1.5 0-1.84L4.39 4.58C3.73 4.31 3 4.79 3 5.51z"}))});at.displayName="Send";const kt=u("div",{target:"e1togvvn0"})("border:none;position:relative;display:flex;"),Vt=u("div",{target:"e1togvvn1"})(({theme:t,extended:e})=>({border:`${t.sizes.borderWidth} solid`,borderColor:t.colors.widgetBorderColor??t.colors.transparent,borderRadius:t.radii.chatInput,backgroundColor:t.colors.secondaryBg,position:"relative",flexGrow:1,display:"flex",alignItems:"center",paddingLeft:t.spacing.lg,maxHeight:e?"none":t.sizes.minElementHeight,gap:t.spacing.sm,overflow:"hidden",":focus-within":{borderColor:t.colors.primary}})),$t=u("button",{target:"e1togvvn2"})(({theme:t,disabled:e,extended:r})=>{const c=ft(t),[f,p]=c?[t.colors.gray60,t.colors.gray80]:[t.colors.gray80,t.colors.gray40];return{border:"none",backgroundColor:t.colors.transparent,borderTopRightRadius:r?"0":t.radii.chatInput,borderTopLeftRadius:r?t.radii.default:"0",borderBottomRightRadius:t.radii.chatInput,display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:t.lineHeights.none,margin:t.spacing.none,padding:t.spacing.sm,color:e?f:p,pointerEvents:"auto","&:focus":{outline:"none"},":focus":{outline:"none"},"&:focus-visible":{backgroundColor:c?t.colors.gray10:t.colors.gray90},"&:hover":{color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{backgroundColor:t.colors.transparent,borderColor:t.colors.transparent,color:t.colors.gray,cursor:"not-allowed"}}}),Nt=u("div",{target:"e1togvvn3"})(({theme:t})=>({display:"flex",alignItems:"flex-end",height:"100%",position:"absolute",right:0,marginBottom:`-${t.sizes.borderWidth}`,pointerEvents:"none"})),At=u("div",{target:"e1togvvn4"})(({theme:t})=>({position:"absolute",bottom:"0px",right:`calc(${t.iconSizes.xl} + 2 * ${t.spacing.sm} + ${t.spacing.sm})`})),Wt=u("div",{target:"ewqvugz0"})(({theme:t,height:e})=>({backgroundColor:t.colors.transparent,position:"absolute",left:0,bottom:0,minHeight:`max(${t.sizes.emptyDropdownHeight}, ${e})`,width:"100%",zIndex:t.zIndices.priority})),qt=u("div",{target:"ewqvugz1"})(({theme:t,height:e})=>({border:`${t.sizes.borderWidth} solid`,borderColor:t.colors.primary,borderRadius:t.radii.chatInput,backgroundColor:t.colors.secondaryBg,color:t.colors.primary,display:"flex",alignItems:"center",justifyContent:"center",height:e,width:"100%",fontWeight:t.fontWeights.bold})),Pt=u("div",{target:"ewqvugz2"})(({theme:t,disabled:e})=>({display:"flex",alignItems:"top",height:"100%",marginTop:`-${t.sizes.borderWidth}`,cursor:e?"not-allowed":"auto"})),Kt=u("div",{target:"ewqvugz3"})(({disabled:t})=>({pointerEvents:t?"none":"auto"})),Ot=u("div",{target:"ewqvugz4"})(({theme:t})=>({marginTop:"0.625em",marginLeft:t.spacing.sm,height:t.spacing.xl,width:t.sizes.borderWidth,backgroundColor:t.colors.fadedText20})),_t=u("div",{target:"ewqvugz5"})(({theme:t})=>({left:0,right:0,lineHeight:t.lineHeights.tight,paddingLeft:t.spacing.sm,paddingRight:t.spacing.sm,overflowX:"auto"})),Xt=u("div",{target:"ewqvugz6"})(({})=>({display:"flex"})),Gt=u("div",{target:"ewqvugz7"})(({})=>({flex:"0 0 auto"})),jt=u("div",{target:"ewqvugz8"})(({theme:t})=>({display:"flex",alignItems:"center",padding:t.spacing.sm,gap:t.spacing.twoXS})),Yt=u("div",{target:"ewqvugz9"})(({theme:t})=>({color:t.colors.fadedText60})),Jt=u("div",{target:"ewqvugz10"})(({theme:t,fileStatus:e})=>({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:e.type==="uploaded"?t.colors.bodyText:t.colors.fadedText60})),Qt=u("div",{target:"ewqvugz11"})(({theme:t})=>({marginRight:t.spacing.md,color:t.colors.fadedText60})),Zt=u("small",{target:"ewqvugz12"})(({theme:t})=>({display:"flex",alignItems:"center",maxHeight:t.sizes.smallElementHeight,color:t.colors.fadedText60,"& :hover":{color:t.colors.bodyText}}));function te({children:t,content:e}){const r=N();return n(mt,{content:e,placement:J.TOP,overrides:{Body:{style:{top:`-${r.sizes.minElementHeight}`}}},children:t})}const ee=({fileInfo:t})=>{const e=N(),{type:r}=t.status;switch(r){case"uploading":return n(yt,{usingCustomTheme:!1,"data-testid":"stChatInputFileIconSpinner",size:"lg",margin:"0",padding:"0"});case"error":return n(te,{content:t.status.errorMessage,children:n(U,{color:e.colors.red,content:nt,size:"lg"})});case"uploaded":return n(U,{content:Et,size:"lg"});default:return vt(r),null}},oe=({fileInfo:t,onDelete:e})=>z(jt,{className:"stChatInputFile","data-testid":"stChatInputFile",children:[n(Yt,{children:n(ee,{fileInfo:t})}),n(Jt,{className:"stChatInputFileName","data-testid":"stChatInputFileName",title:t.name,fileStatus:t.status,children:t.name}),n(Qt,{children:zt(t.size,k.Byte)}),n(Zt,{"data-testid":"stChatInputDeleteBtn",children:n(Q,{onClick:()=>e(t.id),kind:Z.MINIMAL,children:n(U,{content:Ft,size:"lg"})})})]}),ne=({items:t,onDelete:e})=>n(_t,{"data-testid":"stChatUploadedFiles",children:n(Xt,{children:t.map(r=>n(Gt,{children:n(oe,{fileInfo:r,onDelete:e})},r.id))})}),ae=({getNextLocalFileId:t,addFiles:e,updateFile:r,uploadClient:c,element:f,onUploadProgress:p,onUploadComplete:m})=>(x,h)=>{const v=Y.CancelToken.source(),g=new et(h.name,h.size,t(),{type:"uploading",cancelToken:v,progress:1});e([g]),c.uploadFile({formId:"",...f},x.uploadUrl,h,d=>p(d,g.id),v.token).then(()=>m(g.id,x)).catch(d=>{Y.isCancel(d)||r(g.id,g.setStatus({type:"error",errorMessage:d?d.toString():"Unknown error"}))})},re=({acceptMultipleFiles:t,maxFileSize:e,uploadClient:r,uploadFile:c,addFiles:f,getNextLocalFileId:p,deleteExistingFiles:m,onUploadComplete:x})=>(h,v)=>{if(!t&&h.length===0&&v.length>1){const g=v.findIndex(d=>{var y;return((y=d.errors)==null?void 0:y[0].code)===Ut.TooManyFiles});g>=0&&(h.push(v[g].file),v.splice(g,1))}if(!t&&h.length>0&&m(),r.fetchFileURLs(h).then(g=>{wt(g,h).forEach(([d,y])=>{c(d,y)})}).catch(g=>{f(h.map(d=>new et(d.name,d.size,p(),{type:"error",errorMessage:g})))}),v.length>0){const g=v.map(d=>Ht(d,p(),e));f(g)}x()},ie=({getRootProps:t,getInputProps:e,acceptFile:r,disabled:c,theme:f})=>z(Pt,{disabled:c,children:[z(Kt,{"data-testid":"stChatInputFileUploadButton",disabled:c,...t(),children:[n("input",{...e()}),n(Ct,{content:`Upload or drag and drop ${r===I.Multiple?"files":"a file"}`,placement:J.TOP,onMouseEnterDelay:500,children:n(Q,{kind:Z.MINIMAL,disabled:c,children:n(U,{content:ot,size:"lg",color:c?f.colors.fadedText40:f.colors.fadedText60})})})]}),n(Ot,{})]}),se=({getRootProps:t,getInputProps:e,acceptFile:r,inputHeight:c})=>z(tt,{children:[n(Wt,{height:c,...t(),children:n("input",{...e()})}),n(qt,{height:c,children:`Drag and drop ${r===I.Multiple?"files":"a file"} here`})]}),le=6.5,L=1,R=(t,e,r)=>r.map(c=>c.id===t?e:c),M=(t,e)=>e.find(r=>r.id===t);function de({disabled:t,element:e,widgetMgr:r,fragmentId:c,uploadClient:f}){const p=N(),m=l.useRef(null),x=l.useRef(0),h=l.useRef({minHeight:0,maxHeight:0}),[v,g]=It(),[d,y]=l.useState(e.default),[F,A]=l.useState(0),[H,rt]=l.useState(!1),[b,S]=l.useState([]),[E,T]=l.useState(!1),B=l.useMemo(()=>b.some(o=>o.status.type==="uploading")?!1:d!==""||b.length>0,[b,d]),C=xt(e.acceptFile),W=Tt(e.maxUploadSizeMb,k.Megabyte,k.Byte),q=l.useCallback(o=>S(a=>[...a,...o]),[]),P=l.useCallback(o=>{S(a=>{const s=M(o,a);return D(s)?a:(s.status.type==="uploading"&&s.status.cancelToken.cancel(),s.status.type==="uploaded"&&s.status.fileUrls.deleteUrl&&f.deleteFile(s.status.fileUrls.deleteUrl),a.filter(i=>i.id!==o))})},[f]),it=()=>{const o=b.filter(a=>a.status.type==="uploaded").map(a=>{const{name:s,size:i,status:w}=a,{fileId:gt,fileUrls:ht}=w;return new bt({fileId:gt,fileUrls:ht,name:s,size:i})});return new St({uploadedFileInfo:o})},K=()=>x.current++,st=re({acceptMultipleFiles:C===I.Multiple,maxFileSize:W,uploadClient:f,uploadFile:ae({getNextLocalFileId:K,addFiles:q,updateFile:(o,a)=>{S(s=>R(o,a,s))},uploadClient:f,element:e,onUploadProgress:(o,a)=>{S(s=>{const i=M(a,s);if(D(i)||i.status.type!=="uploading")return s;const w=Math.round(o.loaded*100/o.total);return i.status.progress===w?s:R(a,i.setStatus({type:"uploading",cancelToken:i.status.cancelToken,progress:w}),s)})},onUploadComplete:(o,a)=>{S(s=>{const i=M(o,s);return D(i)||i.status.type!=="uploading"?s:R(i.id,i.setStatus({type:"uploaded",fileId:a.fileId,fileUrls:a}),s)})}}),addFiles:q,getNextLocalFileId:K,deleteExistingFiles:()=>b.forEach(o=>P(o.id)),onUploadComplete:()=>{m.current&&m.current.focus()}}),{getRootProps:O,getInputProps:_}=Bt({onDrop:st,multiple:C===I.Multiple,accept:Dt(e.fileType),maxSize:W}),lt=()=>{let o=0;const{current:a}=m;if(a){const s=a.placeholder;a.placeholder="",a.style.height="auto",o=a.scrollHeight,a.placeholder=s,a.style.height=""}return o},X=()=>{if(m.current&&m.current.focus(),!B||t)return;const o={data:d,fileUploaderState:it()};r.setChatInputValue(e,o,{fromUi:!0},c),S([]),y(""),A(0)},dt=o=>{const{metaKey:a,ctrlKey:s,shiftKey:i}=o;Rt(o)&&!i&&!s&&!a&&(o.preventDefault(),X())},ct=o=>{const{value:a}=o.target,{maxChars:s}=e;s!==0&&a.length>s||(y(a),A(lt()))};l.useEffect(()=>{if(e.setValue){e.setValue=!1;const o=e.value||"";y(o)}},[e]),l.useLayoutEffect(()=>{if(m.current){const{offsetHeight:o}=m.current;h.current.minHeight=o,h.current.maxHeight=o*le}},[m]),l.useEffect(()=>{const o=i=>{var w;i.preventDefault(),i.stopPropagation(),!E&&((w=i.dataTransfer)!=null&&w.types.includes("Files"))&&T(!0)},a=i=>{i.preventDefault(),i.stopPropagation(),E&&(i.clientX<=0&&i.clientY<=0||i.clientX>=window.innerWidth&&i.clientY>=window.innerHeight)&&T(!1)},s=i=>{i.preventDefault(),i.stopPropagation(),E&&T(!1)};return window.addEventListener("dragover",o),window.addEventListener("drop",s),window.addEventListener("dragleave",a),()=>{window.removeEventListener("dragover",o),window.removeEventListener("drop",s),window.removeEventListener("dragleave",a)}},[E]),l.useLayoutEffect(()=>{const{minHeight:o}=h.current;rt(F>0&&m.current?Math.abs(F-o)>L:!1)},[F]);const{placeholder:G,maxChars:pt}=e,{maxHeight:j}=h.current,ut=C!==I.None&&E;return z(tt,{children:[C===I.None?null:n(ne,{items:[...b],onDelete:P}),n(kt,{className:"stChatInput","data-testid":"stChatInput",ref:g,children:ut?n(se,{getRootProps:O,getInputProps:_,acceptFile:C,inputHeight:H?`${F+L}px`:p.sizes.minElementHeight}):z(Vt,{extended:H,children:[C===I.None?null:n(ie,{getRootProps:O,getInputProps:_,acceptFile:C,disabled:t,theme:p}),n(Mt,{inputRef:m,value:d,placeholder:G,onChange:ct,onKeyDown:dt,"aria-label":G,disabled:t,rows:1,overrides:{Root:{style:{minHeight:p.sizes.minElementHeight,outline:"none",borderLeftWidth:"0",borderRightWidth:"0",borderTopWidth:"0",borderBottomWidth:"0"}},Input:{props:{"data-testid":"stChatInputTextArea"},style:{lineHeight:p.lineHeights.inputWidget,"::placeholder":{opacity:"0.7"},height:H?`${F+L}px`:"auto",maxHeight:j?`${j}px`:"none",paddingLeft:p.spacing.none,paddingBottom:p.spacing.sm,paddingTop:p.spacing.sm,paddingRight:`calc(${p.iconSizes.xl} + 2 * ${p.spacing.sm} + ${p.spacing.sm})`}}}}),v>p.breakpoints.hideWidgetDetails&&n(At,{children:n(Lt,{dirty:B,value:d,maxLength:pt,type:"chat",inForm:!1})}),n(Nt,{children:n($t,{onClick:X,disabled:!B||t,extended:H,"data-testid":"stChatInputSubmitButton",children:n(U,{content:at,size:"xl",color:"inherit"})})})]})})]})}const ye=l.memo(de);export{ye as default};
|
@@ -1 +1 @@
|
|
1
|
-
import{r as g,E as C,_ as b,n as d,G as j,B as p,j as n,bo as m,bp as y,b4 as O,b5 as F,cp as G,cq as _,aZ as q,F as K,bE as Y,R as Z,aA as J,bj as Q,L as h,b as f,bl as ee,bk as te,br as ie,bF as se,bs as le,ba as ae,bt as ne}from"./index.pEU90S1o.js";import{a as I}from"./index.D8rVyQy1.js";import{F as oe}from"./FormClearHelper.1VkFJY3v.js";import{g as M,F as S,b as re,D as de,I as ce,C as pe,a as ge,s as ue}from"./FileHelper.CTWNHaVI.js";import{S as he,P as me}from"./ProgressBar.BWY8ITDS.js";import{u as fe}from"./Hooks.vPqq3xQ5.js";import{U as x}from"./UploadFileInfo.C-jY39rj.js";var B=g.forwardRef(function(e,s){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return g.createElement(C,b({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:s}),g.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),g.createElement("path",{d:"M19.35 10.04A7.49 7.49 0 0012 4C9.11 4 6.6 5.64 5.35 8.04A5.994 5.994 0 000 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95A5.469 5.469 0 0112 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11A2.98 2.98 0 0122 15c0 1.65-1.35 3-3 3zM8 13h2.55v3h2.9v-3H16l-4-4z"}))});B.displayName="CloudUpload";var D=g.forwardRef(function(e,s){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return g.createElement(C,b({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:s}),g.createElement("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}))});D.displayName="Error";const V=d("section",{target:"e17y52ym0"})(({isDisabled:e,theme:s})=>({display:"flex",alignItems:"center",padding:s.spacing.lg,backgroundColor:s.colors.secondaryBg,borderRadius:s.radii.default,border:s.colors.widgetBorderColor?`${s.sizes.borderWidth} solid ${s.colors.widgetBorderColor}`:void 0,":focus":{outline:"none"},":focus-visible":{boxShadow:`0 0 0 1px ${s.colors.primary}`},color:e?s.colors.gray:s.colors.bodyText})),P=d("div",{target:"e17y52ym1"})({marginRight:"auto",alignItems:"center",display:"flex"}),L=d("span",{target:"e17y52ym2"})(({theme:e})=>({color:e.colors.darkenedBgMix100,marginRight:e.spacing.lg})),ye=d("span",{target:"e17y52ym3"})(({theme:e})=>({marginBottom:e.spacing.twoXS})),Fe=d("div",{target:"e17y52ym4"})({display:"flex",flexDirection:"column"}),E=d("div",{target:"e17y52ym5"})(({theme:e})=>({left:0,right:0,lineHeight:e.lineHeights.tight,paddingTop:e.spacing.md,paddingLeft:e.spacing.lg,paddingRight:e.spacing.lg})),Se=d("ul",{target:"e17y52ym6"})(({theme:e})=>({listStyleType:"none",margin:e.spacing.none,padding:e.spacing.none})),A=d("li",{target:"e17y52ym7"})(({theme:e})=>({margin:e.spacing.none,padding:e.spacing.none})),W=d("div",{target:"e17y52ym8"})(({theme:e})=>({display:"flex",alignItems:"baseline",flex:1,paddingLeft:e.spacing.lg,overflow:"hidden"})),k=d("div",{target:"e17y52ym9"})(({theme:e})=>({marginRight:e.spacing.sm,marginBottom:e.spacing.twoXS,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"})),R=d("div",{target:"e17y52ym10"})(({theme:e})=>({display:"flex",alignItems:"center",marginBottom:e.spacing.twoXS})),Ue=d("span",{target:"e17y52ym11"})(({theme:e})=>({marginRight:e.spacing.twoXS})),xe=d("div",{target:"e17y52ym12"})(({theme:e})=>({display:"flex",padding:e.spacing.twoXS,color:e.colors.darkenedBgMix100})),N=d("small",{target:"e17y52ym13"})(({theme:e})=>({color:e.colors.danger,fontSize:e.fontSizes.sm,height:e.fontSizes.sm,lineHeight:e.fontSizes.sm,display:"flex",alignItems:"center",whiteSpace:"nowrap"})),T=d("span",{target:"e17y52ym14"})({}),we=e=>({[V]:{display:"flex",flexDirection:"column",alignItems:"flex-start"},[P]:{marginBottom:e.spacing.lg},[L]:{display:"none"},[E]:{paddingRight:e.spacing.lg},[R]:{maxWidth:"inherit",flex:1,alignItems:"flex-start",marginBottom:e.spacing.sm},[k]:{width:e.sizes.full},[W]:{flexDirection:"column"},[N]:{height:"auto",whiteSpace:"initial"},[T]:{display:"none"},[A]:{margin:e.spacing.none,padding:e.spacing.none}}),Ie=d("div",{target:"e17y52ym15"})(({theme:e,width:s})=>{if(s<j("23rem"))return we(e)});var v;(function(e){e.DANGER="danger"})(v||(v={}));const w=d("small",{target:"ejh2rmr0"})(({kind:e,theme:s})=>{const{danger:t,fadedText60:i}=s.colors;return{color:e==="danger"?t:i,fontSize:s.fontSizes.sm,lineHeight:s.lineHeights.tight}}),ve=({multiple:e,acceptedExtensions:s,maxSizeBytes:t})=>p(P,{"data-testid":"stFileUploaderDropzoneInstructions",children:[n(L,{children:n(m,{content:B,size:"threeXL"})}),p(Fe,{children:[p(ye,{children:["Drag and drop file",e?"s":""," here"]}),p(w,{children:[`Limit ${M(t,S.Byte,0)} per file`,s.length?` • ${s.map(i=>i.replace(/^\./,"").toUpperCase()).join(", ")}`:null]})]})]}),ze=({onDrop:e,multiple:s,acceptedExtensions:t,maxSizeBytes:i,disabled:l,label:o})=>n(de,{onDrop:e,multiple:s,accept:re(t),maxSize:i,disabled:l,useFsAccessApi:!1,children:({getRootProps:a,getInputProps:r})=>p(V,{...a(),"data-testid":"stFileUploaderDropzone",isDisabled:l,"aria-label":o,children:[n("input",{"data-testid":"stFileUploaderDropzoneInput",...r()}),n(ve,{multiple:s,acceptedExtensions:t,maxSizeBytes:i}),n(y,{kind:F.SECONDARY,disabled:l,size:O.SMALL,children:"Browse files"})]})}),Ce=d("div",{target:"egc9vxm0"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:e.spacing.twoXS,marginBottom:e.spacing.twoXS})),be=d("div",{target:"egc9vxm1"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.colors.fadedText40})),Me=({currentPage:e,totalPages:s,onNext:t,onPrevious:i})=>p(Ce,{"data-testid":"stFileUploaderPagination",children:[n(w,{children:`Showing page ${e} of ${s}`}),p(be,{children:[n(y,{onClick:i,kind:F.MINIMAL,children:n(m,{content:G,size:"xl"})}),n(y,{onClick:t,kind:F.MINIMAL,children:n(m,{content:_,size:"xl"})})]})]}),z=(e,s)=>Math.ceil(e.length/s),Be=e=>q(({pageSize:t,items:i,resetOnAdd:l,...o})=>{const[a,r]=g.useState(0),[c,U]=g.useState(()=>z(i,t)),u=fe(i);g.useEffect(()=>{u&&u.length!==i.length&&U(z(i,t)),u&&u.length<i.length?l&&r(0):a+1>=c&&r(c-1)},[i,a,t,u,l,c]);const H=()=>{r(Math.min(a+1,c-1))},X=()=>{r(Math.max(0,a-1))},$=i.slice(a*t,a*t+t);return p(K,{children:[n(e,{items:$,...o}),i.length>t?n(Me,{pageSize:t,totalPages:c,currentPage:a+1,onNext:H,onPrevious:X}):null]})},e),De=({fileInfo:e})=>e.status.type==="uploading"?n(me,{value:e.status.progress,size:he.SMALL}):e.status.type==="error"?p(N,{children:[n(Ue,{"data-testid":"stFileUploaderFileErrorMessage",children:e.status.errorMessage}),n(T,{children:n(m,{content:D,size:"lg"})})]}):e.status.type==="uploaded"?n(w,{children:M(e.size,S.Byte)}):null,Ve=({fileInfo:e,onDelete:s})=>p(R,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[n(xe,{children:n(m,{content:ce,size:"twoXL"})}),p(W,{className:"stFileUploaderFileData",children:[n(k,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:e.name,children:e.name}),n(De,{fileInfo:e})]}),n("div",{"data-testid":"stFileUploaderDeleteBtn",children:n(y,{onClick:()=>s(e.id),kind:F.MINIMAL,children:n(m,{content:pe,size:"lg"})})})]}),Pe=({items:e,onDelete:s})=>n(Se,{children:e.map(t=>n(A,{children:n(Ve,{fileInfo:t,onDelete:s})},t.id))}),Le=Be(Pe),Ee=e=>n(E,{children:n(Le,{...e})});class Ae extends Z.PureComponent{constructor(s){super(s),this.formClearHelper=new oe,this.localFileIdCounter=1,this.forceUpdatingStatus=!1,this.componentDidUpdate=()=>{if(this.status!=="ready")return;const t=this.createWidgetValue(),{element:i,widgetMgr:l,fragmentId:o}=this.props,a=l.getFileUploaderStateValue(i);J(t,a)||l.setFileUploaderStateValue(i,t,{fromUi:!0},o)},this.dropHandler=(t,i)=>{const{element:l}=this.props,{multipleFiles:o}=l;if(!o&&t.length===0&&i.length>1){const a=i.findIndex(r=>r.errors.length===1&&r.errors[0].code==="too-many-files");a>=0&&(t.push(i[a].file),i.splice(a,1))}if(this.props.uploadClient.fetchFileURLs(t).then(a=>{if(!o&&t.length>0){const r=this.state.files.find(c=>c.status.type!=="error");r&&(this.forceUpdatingStatus=!0,this.deleteFile(r.id),this.forceUpdatingStatus=!1)}Q(a,t).forEach(([r,c])=>{this.uploadFile(r,c)})}).catch(a=>{this.addFiles(t.map(r=>new x(r.name,r.size,this.nextLocalFileId(),{type:"error",errorMessage:a})))}),i.length>0){const a=i.map(r=>ge(r,this.nextLocalFileId(),this.maxUploadSizeInBytes));this.addFiles(a)}},this.uploadFile=(t,i)=>{const l=I.CancelToken.source(),o=new x(i.name,i.size,this.nextLocalFileId(),{type:"uploading",cancelToken:l,progress:1});this.addFile(o),this.props.uploadClient.uploadFile(this.props.element,t.uploadUrl,i,a=>this.onUploadProgress(a,o.id),l.token).then(()=>this.onUploadComplete(o.id,t)).catch(a=>{I.isCancel(a)||this.updateFile(o.id,o.setStatus({type:"error",errorMessage:a?a.toString():"Unknown error"}))})},this.onUploadComplete=(t,i)=>{const l=this.getFile(t);h(l)||l.status.type!=="uploading"||this.updateFile(l.id,l.setStatus({type:"uploaded",fileId:i.fileId,fileUrls:i}))},this.deleteFile=t=>{const i=this.getFile(t);h(i)||(i.status.type==="uploading"&&i.status.cancelToken.cancel(),i.status.type==="uploaded"&&i.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(i.status.fileUrls.deleteUrl),this.removeFile(t))},this.addFile=t=>{f.flushSync(()=>{this.setState(i=>({files:[...i.files,t]}))})},this.addFiles=t=>{f.flushSync(()=>{this.setState(i=>({files:[...i.files,...t]}))})},this.removeFile=t=>{f.flushSync(()=>{this.setState(i=>({files:i.files.filter(l=>l.id!==t)}))})},this.getFile=t=>this.state.files.find(i=>i.id===t),this.updateFile=(t,i)=>{f.flushSync(()=>{this.setState(l=>({files:l.files.map(o=>o.id===t?i:o)}))})},this.onUploadProgress=(t,i)=>{const l=this.getFile(i);if(h(l)||l.status.type!=="uploading")return;const o=Math.round(t.loaded*100/t.total);l.status.progress!==o&&this.updateFile(i,l.setStatus({type:"uploading",cancelToken:l.status.cancelToken,progress:o}))},this.onFormCleared=()=>{f.flushSync(()=>{this.setState({files:[]},()=>{const t=this.createWidgetValue();if(h(t))return;const{widgetMgr:i,element:l,fragmentId:o}=this.props;i.setFileUploaderStateValue(l,t,{fromUi:!0},o)})})},this.state=this.initialValue}get initialValue(){const s={files:[]},{widgetMgr:t,element:i}=this.props,l=t.getFileUploaderStateValue(i);if(h(l))return s;const{uploadedFileInfo:o}=l;return h(o)||o.length===0?s:{files:o.map(a=>{const r=a.name,c=a.size,U=a.fileId,u=a.fileUrls;return new x(r,c,this.nextLocalFileId(),{type:"uploaded",fileId:U,fileUrls:u})})}}componentWillUnmount(){this.formClearHelper.disconnect()}get maxUploadSizeInBytes(){const s=this.props.element.maxUploadSizeMb;return ue(s,S.Megabyte,S.Byte)}get status(){const s=t=>t.status.type==="uploading";return this.state.files.some(s)||this.forceUpdatingStatus?"updating":"ready"}componentDidMount(){const s=this.createWidgetValue(),{element:t,widgetMgr:i,fragmentId:l}=this.props;i.getFileUploaderStateValue(t)===void 0&&i.setFileUploaderStateValue(t,s,{fromUi:!1},l)}createWidgetValue(){const s=this.state.files.filter(t=>t.status.type==="uploaded").map(t=>{const{name:i,size:l,status:o}=t,{fileId:a,fileUrls:r}=o;return new ee({fileId:a,fileUrls:r,name:i,size:l})});return new te({uploadedFileInfo:s})}render(){var c;const{files:s}=this.state,{element:t,disabled:i,widgetMgr:l,width:o}=this.props,a=t.type;this.formClearHelper.manageFormClearListener(l,t.formId,this.onFormCleared);const r=s.slice().reverse();return p(Ie,{className:"stFileUploader","data-testid":"stFileUploader",width:o,children:[n(ne,{label:t.label,disabled:i,labelVisibility:ie((c=t.labelVisibility)==null?void 0:c.value),children:t.help&&n(se,{children:n(le,{content:t.help,placement:ae.TOP_RIGHT})})}),n(ze,{onDrop:this.dropHandler,multiple:t.multipleFiles,acceptedExtensions:a,maxSizeBytes:this.maxUploadSizeInBytes,label:t.label,disabled:i}),r.length>0&&n(Ee,{items:r,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0})]})}nextLocalFileId(){return this.localFileIdCounter++}}const $e=Y(g.memo(Ae));export{$e as default};
|
1
|
+
import{r as g,E as C,_ as b,n as d,G as j,B as p,j as n,bo as m,bp as y,b4 as O,b5 as F,cp as G,cq as _,aZ as q,F as K,bE as Y,R as Z,aA as J,bj as Q,L as h,b as f,bl as ee,bk as te,br as ie,bF as se,bs as le,ba as ae,bt as ne}from"./index.CzFs8nXc.js";import{a as I}from"./index.D8rVyQy1.js";import{F as oe}from"./FormClearHelper.DB5q2Avl.js";import{g as M,F as S,b as re,D as de,I as ce,C as pe,a as ge,s as ue}from"./FileHelper.BwPSCUvG.js";import{S as he,P as me}from"./ProgressBar.DmTol130.js";import{u as fe}from"./Hooks.Cxijo2P7.js";import{U as x}from"./UploadFileInfo.C-jY39rj.js";var B=g.forwardRef(function(e,s){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return g.createElement(C,b({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:s}),g.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),g.createElement("path",{d:"M19.35 10.04A7.49 7.49 0 0012 4C9.11 4 6.6 5.64 5.35 8.04A5.994 5.994 0 000 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95A5.469 5.469 0 0112 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11A2.98 2.98 0 0122 15c0 1.65-1.35 3-3 3zM8 13h2.55v3h2.9v-3H16l-4-4z"}))});B.displayName="CloudUpload";var D=g.forwardRef(function(e,s){var t={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return g.createElement(C,b({iconAttrs:t,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:s}),g.createElement("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}))});D.displayName="Error";const V=d("section",{target:"e17y52ym0"})(({isDisabled:e,theme:s})=>({display:"flex",alignItems:"center",padding:s.spacing.lg,backgroundColor:s.colors.secondaryBg,borderRadius:s.radii.default,border:s.colors.widgetBorderColor?`${s.sizes.borderWidth} solid ${s.colors.widgetBorderColor}`:void 0,":focus":{outline:"none"},":focus-visible":{boxShadow:`0 0 0 1px ${s.colors.primary}`},color:e?s.colors.gray:s.colors.bodyText})),P=d("div",{target:"e17y52ym1"})({marginRight:"auto",alignItems:"center",display:"flex"}),L=d("span",{target:"e17y52ym2"})(({theme:e})=>({color:e.colors.darkenedBgMix100,marginRight:e.spacing.lg})),ye=d("span",{target:"e17y52ym3"})(({theme:e})=>({marginBottom:e.spacing.twoXS})),Fe=d("div",{target:"e17y52ym4"})({display:"flex",flexDirection:"column"}),E=d("div",{target:"e17y52ym5"})(({theme:e})=>({left:0,right:0,lineHeight:e.lineHeights.tight,paddingTop:e.spacing.md,paddingLeft:e.spacing.lg,paddingRight:e.spacing.lg})),Se=d("ul",{target:"e17y52ym6"})(({theme:e})=>({listStyleType:"none",margin:e.spacing.none,padding:e.spacing.none})),A=d("li",{target:"e17y52ym7"})(({theme:e})=>({margin:e.spacing.none,padding:e.spacing.none})),W=d("div",{target:"e17y52ym8"})(({theme:e})=>({display:"flex",alignItems:"baseline",flex:1,paddingLeft:e.spacing.lg,overflow:"hidden"})),k=d("div",{target:"e17y52ym9"})(({theme:e})=>({marginRight:e.spacing.sm,marginBottom:e.spacing.twoXS,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"})),R=d("div",{target:"e17y52ym10"})(({theme:e})=>({display:"flex",alignItems:"center",marginBottom:e.spacing.twoXS})),Ue=d("span",{target:"e17y52ym11"})(({theme:e})=>({marginRight:e.spacing.twoXS})),xe=d("div",{target:"e17y52ym12"})(({theme:e})=>({display:"flex",padding:e.spacing.twoXS,color:e.colors.darkenedBgMix100})),N=d("small",{target:"e17y52ym13"})(({theme:e})=>({color:e.colors.danger,fontSize:e.fontSizes.sm,height:e.fontSizes.sm,lineHeight:e.fontSizes.sm,display:"flex",alignItems:"center",whiteSpace:"nowrap"})),T=d("span",{target:"e17y52ym14"})({}),we=e=>({[V]:{display:"flex",flexDirection:"column",alignItems:"flex-start"},[P]:{marginBottom:e.spacing.lg},[L]:{display:"none"},[E]:{paddingRight:e.spacing.lg},[R]:{maxWidth:"inherit",flex:1,alignItems:"flex-start",marginBottom:e.spacing.sm},[k]:{width:e.sizes.full},[W]:{flexDirection:"column"},[N]:{height:"auto",whiteSpace:"initial"},[T]:{display:"none"},[A]:{margin:e.spacing.none,padding:e.spacing.none}}),Ie=d("div",{target:"e17y52ym15"})(({theme:e,width:s})=>{if(s<j("23rem"))return we(e)});var v;(function(e){e.DANGER="danger"})(v||(v={}));const w=d("small",{target:"ejh2rmr0"})(({kind:e,theme:s})=>{const{danger:t,fadedText60:i}=s.colors;return{color:e==="danger"?t:i,fontSize:s.fontSizes.sm,lineHeight:s.lineHeights.tight}}),ve=({multiple:e,acceptedExtensions:s,maxSizeBytes:t})=>p(P,{"data-testid":"stFileUploaderDropzoneInstructions",children:[n(L,{children:n(m,{content:B,size:"threeXL"})}),p(Fe,{children:[p(ye,{children:["Drag and drop file",e?"s":""," here"]}),p(w,{children:[`Limit ${M(t,S.Byte,0)} per file`,s.length?` • ${s.map(i=>i.replace(/^\./,"").toUpperCase()).join(", ")}`:null]})]})]}),ze=({onDrop:e,multiple:s,acceptedExtensions:t,maxSizeBytes:i,disabled:l,label:o})=>n(de,{onDrop:e,multiple:s,accept:re(t),maxSize:i,disabled:l,useFsAccessApi:!1,children:({getRootProps:a,getInputProps:r})=>p(V,{...a(),"data-testid":"stFileUploaderDropzone",isDisabled:l,"aria-label":o,children:[n("input",{"data-testid":"stFileUploaderDropzoneInput",...r()}),n(ve,{multiple:s,acceptedExtensions:t,maxSizeBytes:i}),n(y,{kind:F.SECONDARY,disabled:l,size:O.SMALL,children:"Browse files"})]})}),Ce=d("div",{target:"egc9vxm0"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:e.spacing.twoXS,marginBottom:e.spacing.twoXS})),be=d("div",{target:"egc9vxm1"})(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.colors.fadedText40})),Me=({currentPage:e,totalPages:s,onNext:t,onPrevious:i})=>p(Ce,{"data-testid":"stFileUploaderPagination",children:[n(w,{children:`Showing page ${e} of ${s}`}),p(be,{children:[n(y,{onClick:i,kind:F.MINIMAL,children:n(m,{content:G,size:"xl"})}),n(y,{onClick:t,kind:F.MINIMAL,children:n(m,{content:_,size:"xl"})})]})]}),z=(e,s)=>Math.ceil(e.length/s),Be=e=>q(({pageSize:t,items:i,resetOnAdd:l,...o})=>{const[a,r]=g.useState(0),[c,U]=g.useState(()=>z(i,t)),u=fe(i);g.useEffect(()=>{u&&u.length!==i.length&&U(z(i,t)),u&&u.length<i.length?l&&r(0):a+1>=c&&r(c-1)},[i,a,t,u,l,c]);const H=()=>{r(Math.min(a+1,c-1))},X=()=>{r(Math.max(0,a-1))},$=i.slice(a*t,a*t+t);return p(K,{children:[n(e,{items:$,...o}),i.length>t?n(Me,{pageSize:t,totalPages:c,currentPage:a+1,onNext:H,onPrevious:X}):null]})},e),De=({fileInfo:e})=>e.status.type==="uploading"?n(me,{value:e.status.progress,size:he.SMALL}):e.status.type==="error"?p(N,{children:[n(Ue,{"data-testid":"stFileUploaderFileErrorMessage",children:e.status.errorMessage}),n(T,{children:n(m,{content:D,size:"lg"})})]}):e.status.type==="uploaded"?n(w,{children:M(e.size,S.Byte)}):null,Ve=({fileInfo:e,onDelete:s})=>p(R,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[n(xe,{children:n(m,{content:ce,size:"twoXL"})}),p(W,{className:"stFileUploaderFileData",children:[n(k,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:e.name,children:e.name}),n(De,{fileInfo:e})]}),n("div",{"data-testid":"stFileUploaderDeleteBtn",children:n(y,{onClick:()=>s(e.id),kind:F.MINIMAL,children:n(m,{content:pe,size:"lg"})})})]}),Pe=({items:e,onDelete:s})=>n(Se,{children:e.map(t=>n(A,{children:n(Ve,{fileInfo:t,onDelete:s})},t.id))}),Le=Be(Pe),Ee=e=>n(E,{children:n(Le,{...e})});class Ae extends Z.PureComponent{constructor(s){super(s),this.formClearHelper=new oe,this.localFileIdCounter=1,this.forceUpdatingStatus=!1,this.componentDidUpdate=()=>{if(this.status!=="ready")return;const t=this.createWidgetValue(),{element:i,widgetMgr:l,fragmentId:o}=this.props,a=l.getFileUploaderStateValue(i);J(t,a)||l.setFileUploaderStateValue(i,t,{fromUi:!0},o)},this.dropHandler=(t,i)=>{const{element:l}=this.props,{multipleFiles:o}=l;if(!o&&t.length===0&&i.length>1){const a=i.findIndex(r=>r.errors.length===1&&r.errors[0].code==="too-many-files");a>=0&&(t.push(i[a].file),i.splice(a,1))}if(this.props.uploadClient.fetchFileURLs(t).then(a=>{if(!o&&t.length>0){const r=this.state.files.find(c=>c.status.type!=="error");r&&(this.forceUpdatingStatus=!0,this.deleteFile(r.id),this.forceUpdatingStatus=!1)}Q(a,t).forEach(([r,c])=>{this.uploadFile(r,c)})}).catch(a=>{this.addFiles(t.map(r=>new x(r.name,r.size,this.nextLocalFileId(),{type:"error",errorMessage:a})))}),i.length>0){const a=i.map(r=>ge(r,this.nextLocalFileId(),this.maxUploadSizeInBytes));this.addFiles(a)}},this.uploadFile=(t,i)=>{const l=I.CancelToken.source(),o=new x(i.name,i.size,this.nextLocalFileId(),{type:"uploading",cancelToken:l,progress:1});this.addFile(o),this.props.uploadClient.uploadFile(this.props.element,t.uploadUrl,i,a=>this.onUploadProgress(a,o.id),l.token).then(()=>this.onUploadComplete(o.id,t)).catch(a=>{I.isCancel(a)||this.updateFile(o.id,o.setStatus({type:"error",errorMessage:a?a.toString():"Unknown error"}))})},this.onUploadComplete=(t,i)=>{const l=this.getFile(t);h(l)||l.status.type!=="uploading"||this.updateFile(l.id,l.setStatus({type:"uploaded",fileId:i.fileId,fileUrls:i}))},this.deleteFile=t=>{const i=this.getFile(t);h(i)||(i.status.type==="uploading"&&i.status.cancelToken.cancel(),i.status.type==="uploaded"&&i.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(i.status.fileUrls.deleteUrl),this.removeFile(t))},this.addFile=t=>{f.flushSync(()=>{this.setState(i=>({files:[...i.files,t]}))})},this.addFiles=t=>{f.flushSync(()=>{this.setState(i=>({files:[...i.files,...t]}))})},this.removeFile=t=>{f.flushSync(()=>{this.setState(i=>({files:i.files.filter(l=>l.id!==t)}))})},this.getFile=t=>this.state.files.find(i=>i.id===t),this.updateFile=(t,i)=>{f.flushSync(()=>{this.setState(l=>({files:l.files.map(o=>o.id===t?i:o)}))})},this.onUploadProgress=(t,i)=>{const l=this.getFile(i);if(h(l)||l.status.type!=="uploading")return;const o=Math.round(t.loaded*100/t.total);l.status.progress!==o&&this.updateFile(i,l.setStatus({type:"uploading",cancelToken:l.status.cancelToken,progress:o}))},this.onFormCleared=()=>{f.flushSync(()=>{this.setState({files:[]},()=>{const t=this.createWidgetValue();if(h(t))return;const{widgetMgr:i,element:l,fragmentId:o}=this.props;i.setFileUploaderStateValue(l,t,{fromUi:!0},o)})})},this.state=this.initialValue}get initialValue(){const s={files:[]},{widgetMgr:t,element:i}=this.props,l=t.getFileUploaderStateValue(i);if(h(l))return s;const{uploadedFileInfo:o}=l;return h(o)||o.length===0?s:{files:o.map(a=>{const r=a.name,c=a.size,U=a.fileId,u=a.fileUrls;return new x(r,c,this.nextLocalFileId(),{type:"uploaded",fileId:U,fileUrls:u})})}}componentWillUnmount(){this.formClearHelper.disconnect()}get maxUploadSizeInBytes(){const s=this.props.element.maxUploadSizeMb;return ue(s,S.Megabyte,S.Byte)}get status(){const s=t=>t.status.type==="uploading";return this.state.files.some(s)||this.forceUpdatingStatus?"updating":"ready"}componentDidMount(){const s=this.createWidgetValue(),{element:t,widgetMgr:i,fragmentId:l}=this.props;i.getFileUploaderStateValue(t)===void 0&&i.setFileUploaderStateValue(t,s,{fromUi:!1},l)}createWidgetValue(){const s=this.state.files.filter(t=>t.status.type==="uploaded").map(t=>{const{name:i,size:l,status:o}=t,{fileId:a,fileUrls:r}=o;return new ee({fileId:a,fileUrls:r,name:i,size:l})});return new te({uploadedFileInfo:s})}render(){var c;const{files:s}=this.state,{element:t,disabled:i,widgetMgr:l,width:o}=this.props,a=t.type;this.formClearHelper.manageFormClearListener(l,t.formId,this.onFormCleared);const r=s.slice().reverse();return p(Ie,{className:"stFileUploader","data-testid":"stFileUploader",width:o,children:[n(ne,{label:t.label,disabled:i,labelVisibility:ie((c=t.labelVisibility)==null?void 0:c.value),children:t.help&&n(se,{children:n(le,{content:t.help,placement:ae.TOP_RIGHT})})}),n(ze,{onDrop:this.dropHandler,multiple:t.multipleFiles,acceptedExtensions:a,maxSizeBytes:this.maxUploadSizeInBytes,label:t.label,disabled:i}),r.length>0&&n(Ee,{items:r,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0})]})}nextLocalFileId(){return this.localFileIdCounter++}}const $e=Y(g.memo(Ae));export{$e as default};
|