streamlit-nightly 1.38.1.dev20240904__py2.py3-none-any.whl → 1.38.1.dev20240906__py2.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/commands/page_config.py +12 -14
- streamlit/config.py +11 -0
- streamlit/elements/layouts.py +10 -14
- streamlit/elements/lib/policies.py +11 -12
- streamlit/elements/widgets/button.py +16 -9
- streamlit/elements/widgets/multiselect.py +5 -15
- streamlit/elements/widgets/number_input.py +22 -26
- streamlit/errors.py +274 -2
- streamlit/runtime/app_session.py +7 -0
- streamlit/runtime/pages_manager.py +4 -0
- streamlit/runtime/scriptrunner_utils/script_run_context.py +6 -7
- streamlit/static/asset-manifest.json +3 -3
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/5180.5e064ef1.chunk.js +1 -0
- streamlit/static/static/js/{main.31d1a42d.js → main.abc0ee04.js} +2 -2
- streamlit/testing/v1/local_script_runner.py +1 -1
- streamlit/web/server/component_request_handler.py +6 -0
- streamlit/web/server/server.py +4 -0
- {streamlit_nightly-1.38.1.dev20240904.dist-info → streamlit_nightly-1.38.1.dev20240906.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.38.1.dev20240904.dist-info → streamlit_nightly-1.38.1.dev20240906.dist-info}/RECORD +25 -25
- streamlit/static/static/js/5281.1a0ea2eb.chunk.js +0 -1
- /streamlit/static/static/js/{main.31d1a42d.js.LICENSE.txt → main.abc0ee04.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.38.1.dev20240904.data → streamlit_nightly-1.38.1.dev20240906.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.38.1.dev20240904.dist-info → streamlit_nightly-1.38.1.dev20240906.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.38.1.dev20240904.dist-info → streamlit_nightly-1.38.1.dev20240906.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.38.1.dev20240904.dist-info → streamlit_nightly-1.38.1.dev20240906.dist-info}/top_level.txt +0 -0
@@ -269,6 +269,10 @@ class PagesManager:
|
|
269
269
|
def intended_page_script_hash(self) -> PageHash | None:
|
270
270
|
return self._intended_page_script_hash
|
271
271
|
|
272
|
+
@property
|
273
|
+
def mpa_version(self) -> int:
|
274
|
+
return 2 if isinstance(self.pages_strategy, PagesStrategyV2) else 1
|
275
|
+
|
272
276
|
def get_main_page(self) -> PageInfo:
|
273
277
|
return {
|
274
278
|
"script_path": self._main_script_path,
|
@@ -23,7 +23,11 @@ from urllib import parse
|
|
23
23
|
|
24
24
|
from typing_extensions import TypeAlias
|
25
25
|
|
26
|
-
from streamlit.errors import
|
26
|
+
from streamlit.errors import (
|
27
|
+
NoSessionContext,
|
28
|
+
StreamlitAPIException,
|
29
|
+
StreamlitSetPageConfigMustBeFirstCommandError,
|
30
|
+
)
|
27
31
|
from streamlit.logger import get_logger
|
28
32
|
|
29
33
|
if TYPE_CHECKING:
|
@@ -143,12 +147,7 @@ class ScriptRunContext:
|
|
143
147
|
def enqueue(self, msg: ForwardMsg) -> None:
|
144
148
|
"""Enqueue a ForwardMsg for this context's session."""
|
145
149
|
if msg.HasField("page_config_changed") and not self._set_page_config_allowed:
|
146
|
-
raise
|
147
|
-
"`set_page_config()` can only be called once per app page, "
|
148
|
-
"and must be called as the first Streamlit command in your script.\n\n"
|
149
|
-
"For more information refer to the [docs]"
|
150
|
-
"(https://docs.streamlit.io/develop/api-reference/configuration/st.set_page_config)."
|
151
|
-
)
|
150
|
+
raise StreamlitSetPageConfigMustBeFirstCommandError()
|
152
151
|
|
153
152
|
# We want to disallow set_page config if one of the following occurs:
|
154
153
|
# - set_page_config was called on this message
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"files": {
|
3
3
|
"main.css": "./static/css/main.5513bd04.css",
|
4
|
-
"main.js": "./static/js/main.
|
4
|
+
"main.js": "./static/js/main.abc0ee04.js",
|
5
5
|
"static/js/6679.265ca09c.chunk.js": "./static/js/6679.265ca09c.chunk.js",
|
6
6
|
"static/js/9464.7e9a3c0a.chunk.js": "./static/js/9464.7e9a3c0a.chunk.js",
|
7
7
|
"static/js/9077.e0a8db2a.chunk.js": "./static/js/9077.e0a8db2a.chunk.js",
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"static/js/6088.00849717.chunk.js": "./static/js/6088.00849717.chunk.js",
|
36
36
|
"static/js/8166.0d1971ea.chunk.js": "./static/js/8166.0d1971ea.chunk.js",
|
37
37
|
"static/js/9114.c676bef4.chunk.js": "./static/js/9114.c676bef4.chunk.js",
|
38
|
-
"static/js/
|
38
|
+
"static/js/5180.5e064ef1.chunk.js": "./static/js/5180.5e064ef1.chunk.js",
|
39
39
|
"static/js/5618.6d42e995.chunk.js": "./static/js/5618.6d42e995.chunk.js",
|
40
40
|
"static/js/1260.5ebd5704.chunk.js": "./static/js/1260.5ebd5704.chunk.js",
|
41
41
|
"static/js/3560.17463b1c.chunk.js": "./static/js/3560.17463b1c.chunk.js",
|
@@ -153,6 +153,6 @@
|
|
153
153
|
},
|
154
154
|
"entrypoints": [
|
155
155
|
"static/css/main.5513bd04.css",
|
156
|
-
"static/js/main.
|
156
|
+
"static/js/main.abc0ee04.js"
|
157
157
|
]
|
158
158
|
}
|
streamlit/static/index.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.abc0ee04.js"></script><link href="./static/css/main.5513bd04.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[5180],{3727:(e,t,i)=>{i.d(t,{A:()=>c,o:()=>p});var s=i(58878),l=i(8151),n=i(70766),r=i(35331),a=i(58144),o=i(84152),d=i(90782);let p;!function(e){e.EXTRASMALL="xs",e.SMALL="sm",e.MEDIUM="md",e.LARGE="lg",e.EXTRALARGE="xl"}(p||(p={}));const c=function(e){let{value:t,width:i,size:c=p.SMALL,overrides:g}=e;const h=(0,l.u)(),u={xs:h.spacing.twoXS,sm:h.spacing.sm,md:h.spacing.lg,lg:h.spacing.xl,xl:h.spacing.twoXL},{activeTheme:m}=s.useContext(o.n),f=!(0,a.tl)(m),x={BarContainer:{style:{marginTop:h.spacing.none,marginBottom:h.spacing.none,marginRight:h.spacing.none,marginLeft:h.spacing.none}},Bar:{style:e=>{let{$theme:t}=e;return{width:i?i.toString():void 0,marginTop:h.spacing.none,marginBottom:h.spacing.none,marginRight:h.spacing.none,marginLeft:h.spacing.none,height:u[c],backgroundColor:t.colors.progressbarTrackFill,borderTopLeftRadius:h.spacing.twoXS,borderTopRightRadius:h.spacing.twoXS,borderBottomLeftRadius:h.spacing.twoXS,borderBottomRightRadius:h.spacing.twoXS}}},BarProgress:{style:()=>({backgroundColor:f?h.colors.primary:h.colors.blue70,borderTopLeftRadius:h.spacing.twoXS,borderTopRightRadius:h.spacing.twoXS,borderBottomLeftRadius:h.spacing.twoXS,borderBottomRightRadius:h.spacing.twoXS})}};return(0,d.jsx)(n.A,{value:t,overrides:(0,r.Qp)(x,g)})}},9830:(e,t,i)=>{i.d(t,{m:()=>s});class s{setStatus(e){return new s(this.name,this.size,this.id,e)}constructor(e,t,i,s){this.name=void 0,this.size=void 0,this.status=void 0,this.id=void 0,this.name=e,this.size=t,this.id=i,this.status=s}}},75180:(e,t,i)=>{i.r(t),i.d(t,{default:()=>ge});var s=i(58878),l=i(32782),n=i(71034),r=i.n(n),a=i(50609),o=i.n(a),d=i(25571),p=i(29669),c=i(34752);let g;!function(e){e.Gigabyte="gb",e.Megabyte="mb",e.Kilobyte="kb",e.Byte="b"}(g||(g={}));const h=(0,d.Q2)()?1024:1e3,u=[g.Gigabyte,g.Megabyte,g.Kilobyte,g.Byte],m=function(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(t||(t=g.Byte),i<0&&(i=0),e<0)throw new Error("Size must be greater than or equal to 0");const s=u.indexOf(t);return s&&e>h/2?m(e/h,u[s-1],i):`${e.toFixed(i)}${t.toUpperCase()}`};var f=i(70474),x=i(78286),w=i(93480),y=i(997),b=i(97779),F=i(36459),S=i(84720),v=i(89653);const j=(0,v.A)("section",{target:"e1b2p2ww15"})((e=>{let{isDisabled:t,theme:i}=e;return{display:"flex",alignItems:"center",padding:i.spacing.lg,backgroundColor:i.colors.secondaryBg,borderRadius:i.radii.default,":focus":{outline:"none"},":focus-visible":{boxShadow:`0 0 0 1px ${i.colors.primary}`},color:t?i.colors.gray:i.colors.bodyText}}),""),I=(0,v.A)("div",{target:"e1b2p2ww14"})((()=>({marginRight:"auto",alignItems:"center",display:"flex"})),""),U=(0,v.A)("span",{target:"e1b2p2ww13"})((e=>{let{theme:t}=e;return{color:t.colors.darkenedBgMix100,marginRight:t.spacing.lg}}),""),A=(0,v.A)("span",{target:"e1b2p2ww12"})((e=>{let{theme:t}=e;return{marginBottom:t.spacing.twoXS}}),""),z=(0,v.A)("div",{target:"e1b2p2ww11"})({name:"1fttcpj",styles:"display:flex;flex-direction:column"}),L=(0,v.A)("div",{target:"e1b2p2ww10"})((e=>{let{theme:t}=e;return{left:0,right:0,lineHeight:t.lineHeights.tight,paddingTop:t.spacing.md,paddingLeft:t.spacing.lg,paddingRight:t.spacing.lg}}),""),M=(0,v.A)("ul",{target:"e1b2p2ww9"})((e=>{let{theme:t}=e;return{listStyleType:"none",marginBottom:t.spacing.none}}),""),C=(0,v.A)("li",{target:"e1b2p2ww8"})((e=>{let{theme:t}=e;return{margin:t.spacing.none,padding:t.spacing.none}}),""),B=(0,v.A)("div",{target:"e1b2p2ww7"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"baseline",flex:1,paddingLeft:t.spacing.lg,overflow:"hidden"}}),""),X=(0,v.A)("div",{target:"e1b2p2ww6"})((e=>{let{theme:t}=e;return{marginRight:t.spacing.sm,marginBottom:t.spacing.twoXS,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}),""),R=(0,v.A)("div",{target:"e1b2p2ww5"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",marginBottom:t.spacing.twoXS}}),""),k=(0,v.A)("span",{target:"e1b2p2ww4"})((e=>{let{theme:t}=e;return{marginRight:t.spacing.twoXS}}),""),T=(0,v.A)("div",{target:"e1b2p2ww3"})((e=>{let{theme:t}=e;return{display:"flex",padding:t.spacing.twoXS,color:t.colors.darkenedBgMix100}}),""),D=(0,v.A)("small",{target:"e1b2p2ww2"})((e=>{let{theme:t}=e;return{color:t.colors.danger,fontSize:t.fontSizes.sm,height:t.fontSizes.sm,lineHeight:t.fontSizes.sm,display:"flex",alignItems:"center",whiteSpace:"nowrap"}}),""),E=(0,v.A)("span",{target:"e1b2p2ww1"})({name:"0",styles:""}),P=e=>({[j]:{display:"flex",flexDirection:"column",alignItems:"flex-start"},[I]:{marginBottom:e.spacing.lg},[U]:{display:"none"},[L]:{paddingRight:e.spacing.lg},[R]:{maxWidth:"inherit",flex:1,alignItems:"flex-start",marginBottom:e.spacing.sm},[X]:{width:e.sizes.full},[B]:{flexDirection:"column"},[D]:{height:"auto",whiteSpace:"initial"},[E]:{display:"none"},[C]:{margin:e.spacing.none,padding:e.spacing.none}}),V=(0,v.A)("div",{target:"e1b2p2ww0"})((e=>{let{theme:t}=e;return t.inSidebar?P(t):{[`@media (max-width: ${t.breakpoints.sm})`]:P(t)}}),"");var N=i(72718),$=i(64611),W=i(12978),H=i(90782);const O=e=>{let{multiple:t,acceptedExtensions:i,maxSizeBytes:s}=e;return(0,H.jsxs)(I,{"data-testid":"stFileUploaderDropzoneInstructions",children:[(0,H.jsx)(U,{children:(0,H.jsx)($.A,{content:N.b,size:"threeXL"})}),(0,H.jsxs)(z,{children:[(0,H.jsxs)(A,{children:["Drag and drop file",t?"s":""," here"]}),(0,H.jsxs)(W.O,{children:[`Limit ${m(s,g.Byte,0)} per file`,i.length?` \u2022 ${i.map((e=>e.replace(/^\./,"").toUpperCase())).join(", ")}`:null]})]})]})},K=e=>{let{onDrop:t,multiple:i,acceptedExtensions:s,maxSizeBytes:l,disabled:n,label:r}=e;return(0,H.jsx)(b.Ay,{onDrop:t,multiple:i,accept:s.length?s:void 0,maxSize:l,disabled:n,useFsAccessApi:!1,children:e=>{let{getRootProps:t,getInputProps:a}=e;return(0,H.jsxs)(j,{...t(),"data-testid":"stFileUploaderDropzone",isDisabled:n,"aria-label":r,children:[(0,H.jsx)("input",{"data-testid":"stFileUploaderDropzoneInput",...a()}),(0,H.jsx)(O,{multiple:i,acceptedExtensions:s,maxSizeBytes:l}),(0,H.jsx)(F.Ay,{kind:S.KX.SECONDARY,disabled:n,size:S.Pj.SMALL,children:"Browse files"})]})}})};var _=i(53124),G=i.n(_);var q=i(77434),Q=i(76370);const Y=(0,v.A)("div",{target:"e1nlpozb1"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:t.spacing.twoXS,marginBottom:t.spacing.twoXS}}),""),J=(0,v.A)("div",{target:"e1nlpozb0"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",justifyContent:"center",color:t.colors.fadedText40}}),""),Z=e=>{let{currentPage:t,totalPages:i,onNext:s,onPrevious:l}=e;return(0,H.jsxs)(Y,{"data-testid":"stFileUploaderPagination",children:[(0,H.jsx)(W.O,{children:`Showing page ${t} of ${i}`}),(0,H.jsxs)(J,{children:[(0,H.jsx)(F.Ay,{onClick:l,kind:S.KX.MINIMAL,children:(0,H.jsx)($.A,{content:q.J,size:"xl"})}),(0,H.jsx)(F.Ay,{onClick:s,kind:S.KX.MINIMAL,children:(0,H.jsx)($.A,{content:Q.c,size:"xl"})})]})]})},ee=(e,t)=>Math.ceil(e.length/t),te=e=>G()((t=>{let{pageSize:i,items:l,resetOnAdd:n,...r}=t;const[a,o]=(0,s.useState)(0),[d,p]=(0,s.useState)(ee(l,i)),c=(e=>{const t=(0,s.useRef)();return(0,s.useEffect)((()=>{t.current=e}),[e]),t.current})(l);(0,s.useEffect)((()=>{c&&c.length!==l.length&&p(ee(l,i)),c&&c.length<l.length?n&&o(0):a+1>=d&&o(d-1)}),[l,a,i,c,n,d]);const g=l.slice(a*i,a*i+i);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(e,{items:g,...r}),l.length>i?(0,H.jsx)(Z,{pageSize:i,totalPages:d,currentPage:a+1,onNext:()=>{o(Math.min(a+1,d-1))},onPrevious:()=>{o(Math.max(0,a-1))}}):null]})}),e);var ie=i(2742),se=i(97522),le=i(64754),ne=i(3727);const re=e=>{let{fileInfo:t}=e;return"uploading"===t.status.type?(0,H.jsx)(ne.A,{value:t.status.progress,size:ne.o.SMALL,overrides:{Bar:{style:{marginLeft:0,marginTop:"4px"}}}}):"error"===t.status.type?(0,H.jsxs)(D,{children:[(0,H.jsx)(k,{"data-testid":"stFileUploaderFileErrorMessage",children:t.status.errorMessage}),(0,H.jsx)(E,{children:(0,H.jsx)($.A,{content:ie.$,size:"lg"})})]}):"uploaded"===t.status.type?(0,H.jsx)(W.O,{children:m(t.size,g.Byte)}):null},ae=e=>{let{fileInfo:t,onDelete:i}=e;return(0,H.jsxs)(R,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[(0,H.jsx)(T,{children:(0,H.jsx)($.A,{content:se.i,size:"twoXL"})}),(0,H.jsxs)(B,{className:"stFileUploaderFileData",children:[(0,H.jsx)(X,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:t.name,children:t.name}),(0,H.jsx)(re,{fileInfo:t})]}),(0,H.jsx)("div",{"data-testid":"stFileUploaderDeleteBtn",children:(0,H.jsx)(F.Ay,{onClick:()=>i(t.id),kind:S.KX.MINIMAL,children:(0,H.jsx)($.A,{content:le.k,size:"lg"})})})]})},oe=te((e=>{let{items:t,onDelete:i}=e;return(0,H.jsx)(M,{children:t.map((e=>(0,H.jsx)(C,{children:(0,H.jsx)(ae,{fileInfo:e,onDelete:i})},e.id)))})})),de=e=>(0,H.jsx)(L,{children:(0,H.jsx)(oe,{...e})});var pe=i(9830);class ce extends s.PureComponent{constructor(e){super(e),this.formClearHelper=new c.o,this.localFileIdCounter=1,this.forceUpdatingStatus=!1,this.componentDidUpdate=()=>{if("ready"!==this.status)return;const e=this.createWidgetValue(),{element:t,widgetMgr:i,fragmentId:s}=this.props,l=i.getFileUploaderStateValue(t);r()(e,l)||i.setFileUploaderStateValue(t,e,{fromUi:!0},s)},this.reset=()=>{this.setState({files:[]})},this.dropHandler=(e,t)=>{const{element:i}=this.props,{multipleFiles:s}=i;if(!s&&0===e.length&&t.length>1){const i=t.findIndex((e=>1===e.errors.length&&"too-many-files"===e.errors[0].code));i>=0&&(e.push(t[i].file),t.splice(i,1))}if(this.props.uploadClient.fetchFileURLs(e).then((t=>{if(!s&&e.length>0){const e=this.state.files.find((e=>"error"!==e.status.type));e&&(this.forceUpdatingStatus=!0,this.deleteFile(e.id),this.forceUpdatingStatus=!1)}o()(t,e).forEach((e=>{let[t,i]=e;this.uploadFile(t,i)}))})).catch((t=>{this.addFiles(e.map((e=>new pe.m(e.name,e.size,this.nextLocalFileId(),{type:"error",errorMessage:t}))))})),t.length>0){const e=t.map((e=>{const{file:t}=e;return new pe.m(t.name,t.size,this.nextLocalFileId(),{type:"error",errorMessage:this.getErrorMessage(e.errors[0].code,e.file)})}));this.addFiles(e)}},this.uploadFile=(e,t)=>{const i=l.A.CancelToken.source(),s=new pe.m(t.name,t.size,this.nextLocalFileId(),{type:"uploading",cancelToken:i,progress:1});this.addFile(s),this.props.uploadClient.uploadFile(this.props.element,e.uploadUrl,t,(e=>this.onUploadProgress(e,s.id)),i.token).then((()=>this.onUploadComplete(s.id,e))).catch((e=>{l.A.isCancel(e)||this.updateFile(s.id,s.setStatus({type:"error",errorMessage:e?e.toString():"Unknown error"}))}))},this.onUploadComplete=(e,t)=>{const i=this.getFile(e);(0,d.hX)(i)||"uploading"!==i.status.type||this.updateFile(i.id,i.setStatus({type:"uploaded",fileId:t.fileId,fileUrls:t}))},this.getErrorMessage=(e,t)=>{switch(e){case"file-too-large":return`File must be ${m(this.maxUploadSizeInBytes,g.Byte)} or smaller.`;case"file-invalid-type":return`${t.type} files are not allowed.`;case"file-too-small":return"File size is too small.";case"too-many-files":return"Only one file is allowed.";default:return"Unexpected error. Please try again."}},this.deleteFile=e=>{const t=this.getFile(e);(0,d.hX)(t)||("uploading"===t.status.type&&t.status.cancelToken.cancel(),"uploaded"===t.status.type&&t.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(t.status.fileUrls.deleteUrl),this.removeFile(e))},this.addFile=e=>{this.setState((t=>({files:[...t.files,e]})))},this.addFiles=e=>{this.setState((t=>({files:[...t.files,...e]})))},this.removeFile=e=>{this.setState((t=>({files:t.files.filter((t=>t.id!==e))})))},this.getFile=e=>this.state.files.find((t=>t.id===e)),this.updateFile=(e,t)=>{this.setState((i=>({files:i.files.map((i=>i.id===e?t:i))})))},this.onUploadProgress=(e,t)=>{const i=this.getFile(t);if((0,d.hX)(i)||"uploading"!==i.status.type)return;const s=Math.round(100*e.loaded/e.total);i.status.progress!==s&&this.updateFile(t,i.setStatus({type:"uploading",cancelToken:i.status.cancelToken,progress:s}))},this.onFormCleared=()=>{this.setState({files:[]},(()=>{const e=this.createWidgetValue();if((0,d.hX)(e))return;const{widgetMgr:t,element:i,fragmentId:s}=this.props;t.setFileUploaderStateValue(i,e,{fromUi:!0},s)}))},this.state=this.initialValue}get initialValue(){const e={files:[],newestServerFileId:0},{widgetMgr:t,element:i}=this.props,s=t.getFileUploaderStateValue(i);if((0,d.hX)(s))return e;const{uploadedFileInfo:l}=s;return(0,d.hX)(l)||0===l.length?e:{files:l.map((e=>{const t=e.name,i=e.size,s=e.fileId,l=e.fileUrls;return new pe.m(t,i,this.nextLocalFileId(),{type:"uploaded",fileId:s,fileUrls:l})}))}}componentWillUnmount(){this.formClearHelper.disconnect()}get maxUploadSizeInBytes(){return((e,t,i)=>{if(e<0)throw Error("Size must be 0 or greater");const s=u.findIndex((e=>e===t)),l=u.findIndex((e=>e===i));if(-1===s||-1===l)throw Error("Unexpected byte unit provided");if(s===l)return e;const n=Math.abs(s-l),r=h**n;return s>l?e/r:e*r})(this.props.element.maxUploadSizeMb,g.Megabyte,g.Byte)}get status(){return this.state.files.some((e=>"uploading"===e.status.type))||this.forceUpdatingStatus?"updating":"ready"}componentDidMount(){const e=this.createWidgetValue(),{element:t,widgetMgr:i,fragmentId:s}=this.props;void 0===i.getFileUploaderStateValue(t)&&i.setFileUploaderStateValue(t,e,{fromUi:!1},s)}createWidgetValue(){const e=this.state.files.filter((e=>"uploaded"===e.status.type)).map((e=>{const{name:t,size:i,status:s}=e,{fileId:l,fileUrls:n}=s;return new p.HY({fileId:l,fileUrls:n,name:t,size:i})}));return new p.qX({uploadedFileInfo:e})}render(){var e;const{files:t}=this.state,{element:i,disabled:s,widgetMgr:l}=this.props,n=i.type;this.formClearHelper.manageFormClearListener(l,i.formId,this.onFormCleared);const r=t.slice().reverse();return(0,H.jsxs)(V,{className:"stFileUploader","data-testid":"stFileUploader",children:[(0,H.jsx)(f.L,{label:i.label,disabled:s,labelVisibility:(0,d.yv)(null===(e=i.labelVisibility)||void 0===e?void 0:e.value),children:i.help&&(0,H.jsx)(x.j,{children:(0,H.jsx)(w.A,{content:i.help,placement:y.W.TOP_RIGHT})})}),(0,H.jsx)(K,{onDrop:this.dropHandler,multiple:i.multipleFiles,acceptedExtensions:n,maxSizeBytes:this.maxUploadSizeInBytes,label:i.label,disabled:s}),r.length>0&&(0,H.jsx)(de,{items:r,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0})]})}nextLocalFileId(){return this.localFileIdCounter++}}const ge=ce},34752:(e,t,i)=>{i.d(t,{o:()=>l});var s=i(25571);class l{constructor(){this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}manageFormClearListener(e,t,i){(0,s.se)(this.formClearListener)&&this.lastWidgetMgr===e&&this.lastFormId===t||(this.disconnect(),(0,s._L)(t)&&(this.formClearListener=e.addFormClearedListener(t,i),this.lastWidgetMgr=e,this.lastFormId=t))}disconnect(){var e;null===(e=this.formClearListener)||void 0===e||e.disconnect(),this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}}}}]);
|