streamlit-nightly 1.31.1.dev20240211__py2.py3-none-any.whl → 1.31.2.dev20240212__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.
Files changed (26) hide show
  1. streamlit/cli_util.py +44 -0
  2. streamlit/config.py +36 -34
  3. streamlit/config_util.py +18 -16
  4. streamlit/delta_generator.py +20 -16
  5. streamlit/elements/image.py +30 -18
  6. streamlit/elements/write.py +5 -6
  7. streamlit/runtime/credentials.py +67 -55
  8. streamlit/runtime/secrets.py +6 -4
  9. streamlit/static/asset-manifest.json +3 -3
  10. streamlit/static/index.html +1 -1
  11. streamlit/static/static/js/4666.ad225eae.chunk.js +1 -0
  12. streamlit/static/static/js/{main.603949f7.js → main.043d802e.js} +2 -2
  13. streamlit/url_util.py +0 -8
  14. streamlit/watcher/path_watcher.py +3 -6
  15. streamlit/web/bootstrap.py +48 -46
  16. streamlit/web/cli.py +8 -5
  17. streamlit/web/server/routes.py +8 -0
  18. streamlit/web/server/server.py +2 -3
  19. {streamlit_nightly-1.31.1.dev20240211.dist-info → streamlit_nightly-1.31.2.dev20240212.dist-info}/METADATA +1 -1
  20. {streamlit_nightly-1.31.1.dev20240211.dist-info → streamlit_nightly-1.31.2.dev20240212.dist-info}/RECORD +25 -24
  21. streamlit/static/static/js/4666.3a6efd97.chunk.js +0 -1
  22. /streamlit/static/static/js/{main.603949f7.js.LICENSE.txt → main.043d802e.js.LICENSE.txt} +0 -0
  23. {streamlit_nightly-1.31.1.dev20240211.data → streamlit_nightly-1.31.2.dev20240212.data}/scripts/streamlit.cmd +0 -0
  24. {streamlit_nightly-1.31.1.dev20240211.dist-info → streamlit_nightly-1.31.2.dev20240212.dist-info}/WHEEL +0 -0
  25. {streamlit_nightly-1.31.1.dev20240211.dist-info → streamlit_nightly-1.31.2.dev20240212.dist-info}/entry_points.txt +0 -0
  26. {streamlit_nightly-1.31.1.dev20240211.dist-info → streamlit_nightly-1.31.2.dev20240212.dist-info}/top_level.txt +0 -0
@@ -14,22 +14,21 @@
14
14
 
15
15
  """Manage the user's Streamlit credentials."""
16
16
 
17
+ from __future__ import annotations
18
+
17
19
  import json
18
20
  import os
19
21
  import sys
20
22
  import textwrap
21
23
  from collections import namedtuple
22
24
  from datetime import datetime
23
- from typing import Optional
25
+ from typing import Final, NoReturn
24
26
  from uuid import uuid4
25
27
 
26
- import click
27
- import toml
28
-
29
- from streamlit import env_util, file_util, util
28
+ from streamlit import cli_util, env_util, file_util, util
30
29
  from streamlit.logger import get_logger
31
30
 
32
- LOGGER = get_logger(__name__)
31
+ _LOGGER: Final = get_logger(__name__)
33
32
 
34
33
 
35
34
  if env_util.IS_WINDOWS:
@@ -66,44 +65,15 @@ def email_prompt() -> str:
66
65
  %(email)s""".format(
67
66
  "👋 " if show_emoji else ""
68
67
  ) % {
69
- "welcome": click.style("Welcome to Streamlit!", bold=True),
70
- "email": click.style("Email: ", fg="blue"),
68
+ "welcome": cli_util.style_for_cli("Welcome to Streamlit!", bold=True),
69
+ "email": cli_util.style_for_cli("Email: ", fg="blue"),
71
70
  }
72
71
 
73
72
 
74
- # IMPORTANT: Break the text below at 80 chars.
75
- _TELEMETRY_TEXT = """
76
- You can find our privacy policy at %(link)s
77
-
78
- Summary:
79
- - This open source library collects usage statistics.
80
- - We cannot see and do not store information contained inside Streamlit apps,
81
- such as text, charts, images, etc.
82
- - Telemetry data is stored in servers in the United States.
83
- - If you'd like to opt out, add the following to %(config)s,
84
- creating that file if necessary:
85
-
86
- [browser]
87
- gatherUsageStats = false
88
- """ % {
89
- "link": click.style("https://streamlit.io/privacy-policy", underline=True),
90
- "config": click.style(_CONFIG_FILE_PATH),
91
- }
92
-
93
73
  _TELEMETRY_HEADLESS_TEXT = """
94
74
  Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
95
75
  """
96
76
 
97
- # IMPORTANT: Break the text below at 80 chars.
98
- _INSTRUCTIONS_TEXT = """
99
- %(start)s
100
- %(prompt)s %(hello)s
101
- """ % {
102
- "start": click.style("Get started by typing:", fg="blue", bold=True),
103
- "prompt": click.style("$", fg="blue"),
104
- "hello": click.style("streamlit hello", bold=True),
105
- }
106
-
107
77
 
108
78
  def _send_email(email: str) -> None:
109
79
  """Send the user's email to segment.io, if submitted"""
@@ -152,7 +122,7 @@ def _send_email(email: str) -> None:
152
122
  class Credentials(object):
153
123
  """Credentials class."""
154
124
 
155
- _singleton: Optional["Credentials"] = None
125
+ _singleton: "Credentials" | None = None
156
126
 
157
127
  @classmethod
158
128
  def get_current(cls):
@@ -177,12 +147,14 @@ class Credentials(object):
177
147
  def __repr__(self) -> str:
178
148
  return util.repr_(self)
179
149
 
180
- def load(self, auto_resolve=False) -> None:
150
+ def load(self, auto_resolve: bool = False) -> None:
181
151
  """Load from toml file."""
182
152
  if self.activation is not None:
183
- LOGGER.error("Credentials already loaded. Not rereading file.")
153
+ _LOGGER.error("Credentials already loaded. Not rereading file.")
184
154
  return
185
155
 
156
+ import toml
157
+
186
158
  try:
187
159
  with open(self._conf_file, "r") as f:
188
160
  data = toml.load(f).get("general")
@@ -211,7 +183,7 @@ class Credentials(object):
211
183
  % (self._conf_file)
212
184
  )
213
185
 
214
- def _check_activated(self, auto_resolve=True):
186
+ def _check_activated(self, auto_resolve: bool = True) -> None:
215
187
  """Check if streamlit is activated.
216
188
 
217
189
  Used by `streamlit run script.py`
@@ -225,7 +197,7 @@ class Credentials(object):
225
197
  _exit("Activation email not valid.")
226
198
 
227
199
  @classmethod
228
- def reset(cls):
200
+ def reset(cls) -> None:
229
201
  """Reset credentials by removing file.
230
202
 
231
203
  This is used by `streamlit activate reset` in case a user wants
@@ -237,9 +209,9 @@ class Credentials(object):
237
209
  try:
238
210
  os.remove(c._conf_file)
239
211
  except OSError as e:
240
- LOGGER.error("Error removing credentials file: %s" % e)
212
+ _LOGGER.error("Error removing credentials file: %s" % e)
241
213
 
242
- def save(self):
214
+ def save(self) -> None:
243
215
  """Save to toml file and send email."""
244
216
  from requests.exceptions import RequestException
245
217
 
@@ -251,13 +223,16 @@ class Credentials(object):
251
223
 
252
224
  # Write the file
253
225
  data = {"email": self.activation.email}
226
+
227
+ import toml
228
+
254
229
  with open(self._conf_file, "w") as f:
255
230
  toml.dump({"general": data}, f)
256
231
 
257
232
  try:
258
233
  _send_email(self.activation.email)
259
234
  except RequestException as e:
260
- LOGGER.error(f"Error saving email: {e}")
235
+ _LOGGER.error(f"Error saving email: {e}")
261
236
 
262
237
  def activate(self, show_instructions: bool = True) -> None:
263
238
  """Activate Streamlit.
@@ -283,6 +258,8 @@ class Credentials(object):
283
258
  activated = False
284
259
 
285
260
  while not activated:
261
+ import click
262
+
286
263
  email = click.prompt(
287
264
  text=email_prompt(),
288
265
  prompt_suffix="",
@@ -293,12 +270,47 @@ class Credentials(object):
293
270
  self.activation = _verify_email(email)
294
271
  if self.activation.is_valid:
295
272
  self.save()
296
- click.secho(_TELEMETRY_TEXT)
273
+ # IMPORTANT: Break the text below at 80 chars.
274
+ TELEMETRY_TEXT = """
275
+ You can find our privacy policy at %(link)s
276
+
277
+ Summary:
278
+ - This open source library collects usage statistics.
279
+ - We cannot see and do not store information contained inside Streamlit apps,
280
+ such as text, charts, images, etc.
281
+ - Telemetry data is stored in servers in the United States.
282
+ - If you'd like to opt out, add the following to %(config)s,
283
+ creating that file if necessary:
284
+
285
+ [browser]
286
+ gatherUsageStats = false
287
+ """ % {
288
+ "link": cli_util.style_for_cli(
289
+ "https://streamlit.io/privacy-policy", underline=True
290
+ ),
291
+ "config": cli_util.style_for_cli(_CONFIG_FILE_PATH),
292
+ }
293
+
294
+ cli_util.print_to_cli(TELEMETRY_TEXT)
297
295
  if show_instructions:
298
- click.secho(_INSTRUCTIONS_TEXT)
296
+ # IMPORTANT: Break the text below at 80 chars.
297
+ INSTRUCTIONS_TEXT = """
298
+ %(start)s
299
+ %(prompt)s %(hello)s
300
+ """ % {
301
+ "start": cli_util.style_for_cli(
302
+ "Get started by typing:", fg="blue", bold=True
303
+ ),
304
+ "prompt": cli_util.style_for_cli("$", fg="blue"),
305
+ "hello": cli_util.style_for_cli(
306
+ "streamlit hello", bold=True
307
+ ),
308
+ }
309
+
310
+ cli_util.print_to_cli(INSTRUCTIONS_TEXT)
299
311
  activated = True
300
312
  else: # pragma: nocover
301
- LOGGER.error("Please try again.")
313
+ _LOGGER.error("Please try again.")
302
314
 
303
315
 
304
316
  def _verify_email(email: str) -> _Activation:
@@ -323,27 +335,27 @@ def _verify_email(email: str) -> _Activation:
323
335
  # We deliberately use simple email validation here
324
336
  # since we do not use email address anywhere to send emails.
325
337
  if len(email) > 0 and email.count("@") != 1:
326
- LOGGER.error("That doesn't look like an email :(")
338
+ _LOGGER.error("That doesn't look like an email :(")
327
339
  return _Activation(None, False)
328
340
 
329
341
  return _Activation(email, True)
330
342
 
331
343
 
332
- def _exit(message): # pragma: nocover
344
+ def _exit(message: str) -> NoReturn:
333
345
  """Exit program with error."""
334
- LOGGER.error(message)
346
+ _LOGGER.error(message)
335
347
  sys.exit(-1)
336
348
 
337
349
 
338
- def _get_credential_file_path():
350
+ def _get_credential_file_path() -> str:
339
351
  return file_util.get_streamlit_file_path("credentials.toml")
340
352
 
341
353
 
342
- def _check_credential_file_exists():
354
+ def _check_credential_file_exists() -> bool:
343
355
  return os.path.exists(_get_credential_file_path())
344
356
 
345
357
 
346
- def check_credentials():
358
+ def check_credentials() -> None:
347
359
  """Check credentials and potentially activate.
348
360
 
349
361
  Note
@@ -357,6 +369,6 @@ def check_credentials():
357
369
  if not _check_credential_file_exists() and config.get_option("server.headless"):
358
370
  if not config.is_manually_set("browser.gatherUsageStats"):
359
371
  # If not manually defined, show short message about usage stats gathering.
360
- click.secho(_TELEMETRY_HEADLESS_TEXT)
372
+ cli_util.print_to_cli(_TELEMETRY_HEADLESS_TEXT)
361
373
  return
362
374
  Credentials.get_current()._check_activated()
@@ -12,25 +12,25 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  import os
16
18
  import threading
17
19
  from copy import deepcopy
18
20
  from typing import (
19
21
  Any,
20
22
  Dict,
23
+ Final,
21
24
  ItemsView,
22
25
  Iterator,
23
26
  KeysView,
24
27
  List,
25
28
  Mapping,
26
29
  NoReturn,
27
- Optional,
28
30
  ValuesView,
29
31
  )
30
32
 
31
- import toml
32
33
  from blinker import Signal
33
- from typing_extensions import Final
34
34
 
35
35
  import streamlit as st
36
36
  import streamlit.watcher.path_watcher
@@ -120,7 +120,7 @@ class Secrets(Mapping[str, Any]):
120
120
 
121
121
  def __init__(self, file_paths: List[str]):
122
122
  # Our secrets dict.
123
- self._secrets: Optional[Mapping[str, Any]] = None
123
+ self._secrets: Mapping[str, Any] | None = None
124
124
  self._lock = threading.RLock()
125
125
  self._file_watchers_installed = False
126
126
  self._file_paths = file_paths
@@ -201,6 +201,8 @@ class Secrets(Mapping[str, Any]):
201
201
  continue
202
202
 
203
203
  try:
204
+ import toml
205
+
204
206
  secrets.update(toml.loads(secrets_file_str))
205
207
  except:
206
208
  if print_exceptions:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.77d1c464.css",
4
- "main.js": "./static/js/main.603949f7.js",
4
+ "main.js": "./static/js/main.043d802e.js",
5
5
  "static/js/9336.2d95d840.chunk.js": "./static/js/9336.2d95d840.chunk.js",
6
6
  "static/js/9330.c0dd1723.chunk.js": "./static/js/9330.c0dd1723.chunk.js",
7
7
  "static/js/7217.d970c074.chunk.js": "./static/js/7217.d970c074.chunk.js",
@@ -33,7 +33,7 @@
33
33
  "static/js/4477.2555c11a.chunk.js": "./static/js/4477.2555c11a.chunk.js",
34
34
  "static/js/4319.213fc321.chunk.js": "./static/js/4319.213fc321.chunk.js",
35
35
  "static/js/5106.22187bfc.chunk.js": "./static/js/5106.22187bfc.chunk.js",
36
- "static/js/4666.3a6efd97.chunk.js": "./static/js/4666.3a6efd97.chunk.js",
36
+ "static/js/4666.ad225eae.chunk.js": "./static/js/4666.ad225eae.chunk.js",
37
37
  "static/js/5379.af4bbff3.chunk.js": "./static/js/5379.af4bbff3.chunk.js",
38
38
  "static/js/8691.ee84f70b.chunk.js": "./static/js/8691.ee84f70b.chunk.js",
39
39
  "static/js/6718.97945fc6.chunk.js": "./static/js/6718.97945fc6.chunk.js",
@@ -150,6 +150,6 @@
150
150
  },
151
151
  "entrypoints": [
152
152
  "static/css/main.77d1c464.css",
153
- "static/js/main.603949f7.js"
153
+ "static/js/main.043d802e.js"
154
154
  ]
155
155
  }
@@ -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.603949f7.js"></script><link href="./static/css/main.77d1c464.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
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.043d802e.js"></script><link href="./static/css/main.77d1c464.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([[4666],{90186:(e,t,i)=>{i.d(t,{$:()=>p,Z:()=>c});var s=i(66845),l=i(25621),n=i(66694),a=i(27466),r=i(38570),o=i(80318),d=i(40864);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(n.E),f=!(0,a.MJ)(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)(r.Z,{value:t,overrides:(0,o.aO)(x,g)})}},77367:(e,t,i)=>{i.d(t,{R:()=>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}}},14666:(e,t,i)=>{i.r(t),i.d(t,{default:()=>he});var s=i(23183),l=i(62813),n=i.n(l),a=i(84693),r=i.n(a),o=i(66845),d=i(16295),p=i(87814),c=i(50641);let g;!function(e){e.Gigabyte="gb",e.Megabyte="mb",e.Kilobyte="kb",e.Byte="b"}(g||(g={}));const h=(0,c.rA)()?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):"".concat(e.toFixed(i)).concat(t.toUpperCase())};var f=i(98478),x=i(86659),w=i(8879),y=i(68411),b=i(51622),F=i(9003),S=i(81354),v=i(1515);const j=(0,v.Z)("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.lg,":focus":{outline:"none"},":focus-visible":{boxShadow:"0 0 0 1px ".concat(i.colors.primary)},color:t?i.colors.gray:i.colors.bodyText}}),""),I=(0,v.Z)("div",{target:"e1b2p2ww14"})((()=>({marginRight:"auto",alignItems:"center",display:"flex"})),""),U=(0,v.Z)("span",{target:"e1b2p2ww13"})((e=>{let{theme:t}=e;return{color:t.colors.darkenedBgMix100,marginRight:t.spacing.lg}}),""),M=(0,v.Z)("span",{target:"e1b2p2ww12"})((e=>{let{theme:t}=e;return{marginBottom:t.spacing.twoXS}}),""),z=(0,v.Z)("div",{target:"e1b2p2ww11"})({name:"1fttcpj",styles:"display:flex;flex-direction:column"}),L=(0,v.Z)("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}}),""),C=(0,v.Z)("ul",{target:"e1b2p2ww9"})((()=>({listStyleType:"none",marginBottom:0})),""),B=(0,v.Z)("li",{target:"e1b2p2ww8"})((e=>{let{theme:t}=e;return{margin:t.spacing.none,padding:t.spacing.none}}),""),Z=(0,v.Z)("div",{target:"e1b2p2ww7"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"baseline",flex:1,paddingLeft:t.spacing.lg,overflow:"hidden"}}),""),R=(0,v.Z)("div",{target:"e1b2p2ww6"})((e=>{let{theme:t}=e;return{marginRight:t.spacing.sm,marginBottom:t.spacing.twoXS,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}),""),k=(0,v.Z)("div",{target:"e1b2p2ww5"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",marginBottom:t.spacing.twoXS}}),""),T=(0,v.Z)("span",{target:"e1b2p2ww4"})((e=>{let{theme:t}=e;return{marginRight:t.spacing.twoXS}}),""),D=(0,v.Z)("div",{target:"e1b2p2ww3"})((e=>{let{theme:t}=e;return{display:"flex",padding:t.spacing.twoXS,color:t.colors.darkenedBgMix100}}),""),X=(0,v.Z)("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"}}),""),P=(0,v.Z)("span",{target:"e1b2p2ww1"})({name:"0",styles:""}),E=e=>({[j]:{display:"flex",flexDirection:"column",alignItems:"flex-start"},[I]:{marginBottom:e.spacing.lg},[U]:{display:"none"},[L]:{paddingRight:e.spacing.lg},[k]:{maxWidth:"inherit",flex:1,alignItems:"flex-start",marginBottom:e.spacing.sm},[R]:{width:e.sizes.full},[Z]:{flexDirection:"column"},[X]:{height:"auto",whiteSpace:"initial"},[P]:{display:"none"},[B]:{margin:e.spacing.none,padding:e.spacing.none}}),A=(0,v.Z)("div",{target:"e1b2p2ww0"})((e=>{let{theme:t}=e;return t.inSidebar?E(t):{["@media (max-width: ".concat(t.breakpoints.sm,")")]:E(t)}}),"");var V=i(74529),N=i(46927),W=i(33746),O=i(40864);const H=e=>{let{multiple:t,acceptedExtensions:i,maxSizeBytes:s}=e;return(0,O.jsxs)(I,{"data-testid":"stFileUploaderDropzoneInstructions",children:[(0,O.jsx)(U,{children:(0,O.jsx)(N.Z,{content:V.n,size:"threeXL"})}),(0,O.jsxs)(z,{children:[(0,O.jsxs)(M,{children:["Drag and drop file",t?"s":""," here"]}),(0,O.jsxs)(W.x,{children:["Limit ".concat(m(s,g.Byte,0)," per file"),i.length?" \u2022 ".concat(i.map((e=>e.replace(/^\./,"").toUpperCase())).join(", ")):null]})]})]})},_=e=>{let{onDrop:t,multiple:i,acceptedExtensions:s,maxSizeBytes:l,disabled:n,label:a}=e;return(0,O.jsx)(b.ZP,{onDrop:t,multiple:i,accept:s.length?s:void 0,maxSize:l,disabled:n,useFsAccessApi:!1,children:e=>{let{getRootProps:t,getInputProps:r}=e;return(0,O.jsxs)(j,{...t(),"data-testid":"stFileUploaderDropzone",isDisabled:n,"aria-label":a,children:[(0,O.jsx)("input",{"data-testid":"stFileUploaderDropzoneInput",...r()}),(0,O.jsx)(H,{multiple:i,acceptedExtensions:s,maxSizeBytes:l}),(0,O.jsx)(F.ZP,{kind:S.nW.SECONDARY,disabled:n,size:S.V5.SMALL,children:"Browse files"})]})}})};var G=i(13005),K=i.n(G),$=i(30351),q=i(14609);const J=(0,v.Z)("div",{target:"e16k0npc1"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:t.spacing.twoXS,marginBottom:t.spacing.twoXS}}),""),Y=(0,v.Z)("div",{target:"e16k0npc0"})((e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",justifyContent:"center",color:t.colors.fadedText40}}),""),Q=e=>{let{className:t,currentPage:i,totalPages:s,onNext:l,onPrevious:n}=e;return(0,O.jsxs)(J,{className:t,"data-testid":"stPagination",children:[(0,O.jsx)(W.x,{children:"Showing page ".concat(i," of ").concat(s)}),(0,O.jsxs)(Y,{children:[(0,O.jsx)(F.ZP,{onClick:n,kind:S.nW.MINIMAL,children:(0,O.jsx)(N.Z,{content:$.s,size:"xl"})}),(0,O.jsx)(F.ZP,{onClick:l,kind:S.nW.MINIMAL,children:(0,O.jsx)(N.Z,{content:q._,size:"xl"})})]})]})};var ee=i(88235);const te=(e,t)=>Math.ceil(e.length/t),ie=e=>K()((t=>{let{pageSize:i,items:s,resetOnAdd:l,...n}=t;const[a,r]=(0,o.useState)(0),[d,p]=(0,o.useState)(te(s,i)),c=(0,ee.D)(s);(0,o.useEffect)((()=>{c&&c.length!==s.length&&p(te(s,i)),c&&c.length<s.length?l&&r(0):a+1>=d&&r(d-1)}),[s,a,i,c,l,d]);const g=s.slice(a*i,a*i+i);return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(e,{items:g,...n}),s.length>i?(0,O.jsx)(Q,{className:"streamlit-paginator",pageSize:i,totalPages:d,currentPage:a+1,onNext:()=>{r(Math.min(a+1,d-1))},onPrevious:()=>{r(Math.max(0,a-1))}}):null]})}),e);var se=i(62288),le=i(87847),ne=i(31197),ae=i(90186);const re=e=>{let{fileInfo:t}=e;return"uploading"===t.status.type?(0,O.jsx)(ae.Z,{value:t.status.progress,size:ae.$.SMALL,overrides:{Bar:{style:{marginLeft:0,marginTop:"4px"}}}}):"error"===t.status.type?(0,O.jsxs)(X,{children:[(0,O.jsx)(T,{"data-testid":"stFileUploaderFileErrorMessage",children:t.status.errorMessage}),(0,O.jsx)(P,{children:(0,O.jsx)(N.Z,{content:se.j,size:"lg"})})]}):"uploaded"===t.status.type?(0,O.jsx)(W.x,{children:m(t.size,g.Byte)}):null},oe=e=>{let{fileInfo:t,onDelete:i}=e;return(0,O.jsxs)(k,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[(0,O.jsx)(D,{children:(0,O.jsx)(N.Z,{content:le.h,size:"twoXL"})}),(0,O.jsxs)(Z,{className:"stFileUploaderFileData",children:[(0,O.jsx)(R,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:t.name,children:t.name}),(0,O.jsx)(re,{fileInfo:t})]}),(0,O.jsx)("div",{"data-testid":"stFileUploaderDeleteBtn",children:(0,O.jsx)(F.ZP,{onClick:()=>i(t.id),kind:S.nW.MINIMAL,children:(0,O.jsx)(N.Z,{content:ne.U,size:"lg"})})})]})},de=ie((e=>{let{items:t,onDelete:i}=e;return(0,O.jsx)(C,{children:t.map((e=>(0,O.jsx)(B,{children:(0,O.jsx)(oe,{fileInfo:e,onDelete:i})},e.id)))})})),pe=e=>(0,O.jsx)(L,{children:(0,O.jsx)(de,{...e})});var ce=i(77367);class ge extends o.PureComponent{constructor(e){super(e),this.formClearHelper=new p.K,this.localFileIdCounter=1,this.componentDidUpdate=()=>{if("ready"!==this.status)return;const e=this.createWidgetValue(),{element:t,widgetMgr:i}=this.props,s=i.getFileUploaderStateValue(t);n()(e,s)||i.setFileUploaderStateValue(t,e,{fromUi:!0})},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.deleteFile(e.id)}r()(t,e).forEach((e=>{let[t,i]=e;this.uploadFile(t,i)}))})).catch((t=>{this.addFiles(e.map((e=>new ce.R(e.name,e.size,this.nextLocalFileId(),{type:"error",errorMessage:t}))))})),t.length>0){const e=t.map((e=>{const{file:t}=e;return new ce.R(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=s.Z.CancelToken.source(),l=new ce.R(t.name,t.size,this.nextLocalFileId(),{type:"uploading",cancelToken:i,progress:1});this.addFile(l),this.props.uploadClient.uploadFile(this.props.element,e.uploadUrl,t,(e=>this.onUploadProgress(e,l.id)),i.token).then((()=>this.onUploadComplete(l.id,e))).catch((e=>{s.Z.isCancel(e)||this.updateFile(l.id,l.setStatus({type:"error",errorMessage:e?e.toString():"Unknown error"}))}))},this.onUploadComplete=(e,t)=>{const i=this.getFile(e);null!=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 ".concat(m(this.maxUploadSizeInBytes,g.Byte)," or smaller.");case"file-invalid-type":return"".concat(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);null!=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(null==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();null!=e&&this.props.widgetMgr.setFileUploaderStateValue(this.props.element,e,{fromUi:!0})}))},this.state=this.initialValue}get initialValue(){const e={files:[],newestServerFileId:0},{widgetMgr:t,element:i}=this.props,s=t.getFileUploaderStateValue(i);if(null==s)return e;const{uploadedFileInfo:l}=s;return null==l||0===l.length?e:{files:l.map((e=>{const t=e.name,i=e.size,s=e.fileId,l=e.fileUrls;return new ce.R(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),a=h**n;return s>l?e/a:e*a})(this.props.element.maxUploadSizeMb,g.Megabyte,g.Byte)}get status(){return this.state.files.some((e=>"uploading"===e.status.type))?"updating":"ready"}componentDidMount(){const e=this.createWidgetValue(),{element:t,widgetMgr:i}=this.props;void 0===i.getFileUploaderStateValue(t)&&i.setFileUploaderStateValue(t,e,{fromUi:!1})}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 d.jM({fileId:l,fileUrls:n,name:t,size:i})}));return new d.xO({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 a=t.slice().reverse();return(0,O.jsxs)(A,{"data-testid":"stFileUploader",children:[(0,O.jsx)(f.O,{label:i.label,disabled:s,labelVisibility:(0,c.iF)(null===(e=i.labelVisibility)||void 0===e?void 0:e.value),children:i.help&&(0,O.jsx)(x.dT,{children:(0,O.jsx)(w.Z,{content:i.help,placement:y.u.TOP_RIGHT})})}),(0,O.jsx)(_,{onDrop:this.dropHandler,multiple:i.multipleFiles,acceptedExtensions:n,maxSizeBytes:this.maxUploadSizeInBytes,label:i.label,disabled:s}),a.length>0&&(0,O.jsx)(pe,{items:a,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0})]})}nextLocalFileId(){return this.localFileIdCounter++}}const he=ge},87814:(e,t,i)=>{i.d(t,{K:()=>l});var s=i(50641);class l{constructor(){this.formClearListener=void 0,this.lastWidgetMgr=void 0,this.lastFormId=void 0}manageFormClearListener(e,t,i){null!=this.formClearListener&&this.lastWidgetMgr===e&&this.lastFormId===t||(this.disconnect(),(0,s.bM)(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}}}}]);