streamlit-nightly 1.34.1.dev20240507__py2.py3-none-any.whl → 1.34.1.dev20240509__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.
@@ -16,7 +16,9 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
+ import hashlib
19
20
  import json
21
+ import re
20
22
  from contextlib import nullcontext
21
23
  from typing import TYPE_CHECKING, Any, Final, Literal, Sequence, cast
22
24
 
@@ -32,6 +34,7 @@ from streamlit.proto.ArrowVegaLiteChart_pb2 import (
32
34
  ArrowVegaLiteChart as ArrowVegaLiteChartProto,
33
35
  )
34
36
  from streamlit.runtime.metrics_util import gather_metrics
37
+ from streamlit.util import HASHLIB_KWARGS
35
38
 
36
39
  if TYPE_CHECKING:
37
40
  import altair as alt
@@ -128,13 +131,25 @@ def _marshall_chart_data(
128
131
  These operations will happen in-place."""
129
132
 
130
133
  # Pull data out of spec dict when it's in a 'datasets' key:
131
- # datasets: {foo: df1, bar: df2}, ...}
134
+ # datasets: {foo: df1_bytes, bar: df2_bytes}, ...}
132
135
  if "datasets" in spec:
133
136
  for dataset_name, dataset_data in spec["datasets"].items():
134
137
  dataset = proto.datasets.add()
135
138
  dataset.name = str(dataset_name)
136
139
  dataset.has_name = True
137
- dataset.data.data = _serialize_data(dataset_data)
140
+ # The ID transformer (id_transform function registered before conversion to dict)
141
+ # already serializes the data into Arrow IPC format (bytes) when the Altair object
142
+ # gets converted into the vega-lite spec dict.
143
+ # If its already in bytes, we don't need to serialize it here again.
144
+ # We just need to pass the data information into the correct proto fields.
145
+
146
+ # TODO(lukasmasuch): Are there any other cases where we need to serialize the data
147
+ # or can we remove the _serialize_data here?
148
+ dataset.data.data = (
149
+ dataset_data
150
+ if isinstance(dataset_data, bytes)
151
+ else _serialize_data(dataset_data)
152
+ )
138
153
  del spec["datasets"]
139
154
 
140
155
  # Pull data out of spec dict when it's in a top-level 'data' key:
@@ -169,11 +184,21 @@ def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> dict[str, Any]
169
184
  datasets = {}
170
185
 
171
186
  def id_transform(data) -> dict[str, str]:
172
- """Altair data transformer that returns a fake named dataset with the
173
- object id.
187
+ """Altair data transformer that serializes the data,
188
+ creates a stable name based on the hash of the data,
189
+ stores the bytes into the datasets mapping and
190
+ returns this name to have it be used in Altair.
174
191
  """
175
- name = str(id(data))
176
- datasets[name] = data
192
+
193
+ # Already serialize the data to be able to create a stable
194
+ # dataset name:
195
+ data_bytes = _serialize_data(data)
196
+ # Use the md5 hash of the data as the name:
197
+ h = hashlib.new("md5", **HASHLIB_KWARGS)
198
+ h.update(str(data_bytes).encode("utf-8"))
199
+ name = h.hexdigest()
200
+
201
+ datasets[name] = data_bytes
177
202
  return {"name": name}
178
203
 
179
204
  alt.data_transformers.register("id", id_transform) # type: ignore[attr-defined,unused-ignore]
@@ -185,12 +210,94 @@ def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> dict[str, Any]
185
210
  with alt.data_transformers.enable("id"): # type: ignore[attr-defined,unused-ignore]
186
211
  chart_dict = altair_chart.to_dict()
187
212
 
188
- # Put datasets back into the chart dict but note how they weren't
189
- # transformed.
213
+ # Put datasets back into the chart dict:
190
214
  chart_dict["datasets"] = datasets
191
215
  return chart_dict
192
216
 
193
217
 
218
+ def _reset_counter_pattern(prefix: str, vega_spec: str) -> str:
219
+ """Altair uses a global counter for unnamed parameters and views.
220
+ We need to reset these counters on a spec-level to make the
221
+ spec stable across reruns and avoid changes to the element ID.
222
+ """
223
+ pattern = re.compile(rf'"{prefix}\d+"')
224
+ # Get all matches without duplicates in order of appearance.
225
+ # Using a set here would not guarantee the order of appearance,
226
+ # which might lead to different replacements on each run.
227
+ # The order of the spec from Altair is expected to stay stable
228
+ # within the same session / Altair version.
229
+ # The order might change with Altair updates, but that's not really
230
+ # a case that is relevant for us since we mainly care about having
231
+ # this stable within a session.
232
+ if matches := list(dict.fromkeys(pattern.findall(vega_spec))):
233
+ # Add a prefix to the replacement to avoid
234
+ # replacing instances that already have been replaced before.
235
+ # The prefix here is arbitrarily chosen with the main goal
236
+ # that its extremely unlikely to already be part of the spec:
237
+ replacement_prefix = "__replace_prefix_o9hd101n22e1__"
238
+
239
+ # Replace all matches with a counter starting from 1
240
+ # We start from 1 to imitate the altair behavior.
241
+ for counter, match in enumerate(matches, start=1):
242
+ vega_spec = vega_spec.replace(
243
+ match, f'"{replacement_prefix}{prefix}{counter}"'
244
+ )
245
+
246
+ # Remove the prefix again from all replacements:
247
+ vega_spec = vega_spec.replace(replacement_prefix, "")
248
+ return vega_spec
249
+
250
+
251
+ def _stabilize_vega_json_spec(vega_spec: str) -> str:
252
+ """Makes the chart spec stay stable across reruns and sessions.
253
+
254
+ Altair auto creates names for unnamed parameters & views. It uses a global counter
255
+ for the naming which will result in a different spec on every rerun.
256
+ In Streamlit, we need the spec to be stable across reruns and sessions to prevent the chart
257
+ from getting a new identity. So we need to replace the names with counter with a stable name.
258
+ Having a stable chart spec is also important for features like forward message cache,
259
+ where we don't want to have changing messages on every rerun.
260
+
261
+ Parameter counter:
262
+ https://github.com/vega/altair/blob/f345cd9368ae2bbc98628e9245c93fa9fb582621/altair/vegalite/v5/api.py#L196
263
+
264
+ View counter:
265
+ https://github.com/vega/altair/blob/f345cd9368ae2bbc98628e9245c93fa9fb582621/altair/vegalite/v5/api.py#L2885
266
+
267
+ This is temporary solution waiting for a fix for this issue:
268
+ https://github.com/vega/altair/issues/3416
269
+
270
+ Other solutions we considered:
271
+ - working on the dict object: this would require to iterate through the object and do the
272
+ same kind of replacement; though we would need to know the structure and since we need
273
+ the spec in String-format anyways, we deemed that executing the replacement on the
274
+ String is the better alternative
275
+ - resetting the counter: the counter is incremented already when the chart object is created
276
+ (see this GitHub issue comment https://github.com/vega/altair/issues/3416#issuecomment-2098530464),
277
+ so it would be too late here to reset the counter with a thread-lock to prevent interference
278
+ between sessions
279
+ """
280
+
281
+ # We only want to apply these replacements if it is really necessary
282
+ # since there is a risk that we replace names that where chosen by the user
283
+ # and thereby introduce unwanted side effects.
284
+
285
+ # We only need to apply the param_ fix if there are actually parameters defined
286
+ # somewhere in the spec. We can check for this by looking for the '"params"' key.
287
+ # This isn't a perfect check, but good enough to prevent unnecessary executions
288
+ # for the majority of charts.
289
+ if '"params"' in vega_spec:
290
+ vega_spec = _reset_counter_pattern("param_", vega_spec)
291
+
292
+ # Simple check if the spec contains a composite chart:
293
+ # https://vega.github.io/vega-lite/docs/composition.html
294
+ # Other charts will not contain the `view_` name,
295
+ # so its better to not replace this pattern.
296
+ if re.search(r'"(vconcat|hconcat|facet|layer|concat|repeat)"', vega_spec):
297
+ vega_spec = _reset_counter_pattern("view_", vega_spec)
298
+ return vega_spec
299
+
300
+
194
301
  class VegaChartsMixin:
195
302
  """Mix-in class for all vega-related chart commands.
196
303
 
@@ -1020,7 +1127,8 @@ class VegaChartsMixin:
1020
1127
  spec = _prepare_vega_lite_spec(spec, use_container_width, **kwargs)
1021
1128
  _marshall_chart_data(proto, spec, data)
1022
1129
 
1023
- proto.spec = json.dumps(spec)
1130
+ # Prevent the spec from changing across reruns:
1131
+ proto.spec = _stabilize_vega_json_spec(json.dumps(spec))
1024
1132
  proto.use_container_width = use_container_width
1025
1133
  proto.theme = theme or ""
1026
1134
 
@@ -39,7 +39,7 @@ from streamlit.runtime.state import (
39
39
  register_widget,
40
40
  )
41
41
  from streamlit.runtime.state.common import compute_widget_id, save_for_app_testing
42
- from streamlit.string_util import validate_emoji
42
+ from streamlit.string_util import validate_icon_or_emoji
43
43
  from streamlit.type_util import Key, to_key
44
44
 
45
45
  if TYPE_CHECKING:
@@ -487,11 +487,22 @@ class ButtonMixin:
487
487
  Unsupported elements are unwrapped so only their children (text contents)
488
488
  render. Display unsupported elements as literal characters by
489
489
  backslash-escaping them. E.g. ``1\. Not an ordered list``.
490
- icon : str
491
- An optional argument that specifies an emoji to use as
492
- the icon for the link. Shortcodes are not allowed. Please use a
493
- single character instead. E.g. "🚨", "🔥", "🤖", etc.
494
- Defaults to ``None``, which means no icon is displayed.
490
+ icon : str, None
491
+ An optional emoji or icon to display next to the button label. If ``icon``
492
+ is ``None`` (default), no icon is displayed. If ``icon`` is a
493
+ string, the following options are valid:
494
+
495
+ * A single-character emoji. For example, you can set ``icon="🚨"``
496
+ or ``icon="🔥"``. Emoji short codes are not supported.
497
+
498
+ * An icon from the Material Symbols library (outlined style) in the
499
+ format ``":material/icon_name:"`` where "icon_name" is the name
500
+ of the icon in snake case.
501
+
502
+ For example, ``icon=":material/thumb_up:"`` will display the
503
+ Thumb Up icon. Find additional icons in the `Material Symbols \
504
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
505
+ font library.
495
506
  help : str
496
507
  An optional tooltip that gets displayed when the link is
497
508
  hovered over.
@@ -662,7 +673,7 @@ class ButtonMixin:
662
673
  page_link_proto.label = label
663
674
 
664
675
  if icon is not None:
665
- page_link_proto.icon = validate_emoji(icon)
676
+ page_link_proto.icon = validate_icon_or_emoji(icon)
666
677
 
667
678
  if help is not None:
668
679
  page_link_proto.help = dedent(help)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.3aaaea00.css",
4
- "main.js": "./static/js/main.b84b6de2.js",
4
+ "main.js": "./static/js/main.5a6e0ded.js",
5
5
  "static/js/9336.2d95d840.chunk.js": "./static/js/9336.2d95d840.chunk.js",
6
6
  "static/js/9330.2b4c99e0.chunk.js": "./static/js/9330.2b4c99e0.chunk.js",
7
7
  "static/js/2736.4336e2b9.chunk.js": "./static/js/2736.4336e2b9.chunk.js",
@@ -17,13 +17,13 @@
17
17
  "static/js/4500.b6f348d1.chunk.js": "./static/js/4500.b6f348d1.chunk.js",
18
18
  "static/js/1307.0f0cca93.chunk.js": "./static/js/1307.0f0cca93.chunk.js",
19
19
  "static/js/2469.09ea79bb.chunk.js": "./static/js/2469.09ea79bb.chunk.js",
20
- "static/js/4113.9b2db2e3.chunk.js": "./static/js/4113.9b2db2e3.chunk.js",
20
+ "static/js/4113.99983645.chunk.js": "./static/js/4113.99983645.chunk.js",
21
21
  "static/js/1168.7452e363.chunk.js": "./static/js/1168.7452e363.chunk.js",
22
22
  "static/js/178.7bea8c5d.chunk.js": "./static/js/178.7bea8c5d.chunk.js",
23
23
  "static/js/1792.8bd6ce2a.chunk.js": "./static/js/1792.8bd6ce2a.chunk.js",
24
24
  "static/js/3513.ebc278c4.chunk.js": "./static/js/3513.ebc278c4.chunk.js",
25
25
  "static/js/7602.e8abc06b.chunk.js": "./static/js/7602.e8abc06b.chunk.js",
26
- "static/js/6013.64cd6d28.chunk.js": "./static/js/6013.64cd6d28.chunk.js",
26
+ "static/js/6013.4ba2d616.chunk.js": "./static/js/6013.4ba2d616.chunk.js",
27
27
  "static/js/8492.0d93bd08.chunk.js": "./static/js/8492.0d93bd08.chunk.js",
28
28
  "static/js/4177.69f9f18d.chunk.js": "./static/js/4177.69f9f18d.chunk.js",
29
29
  "static/js/1451.3b0a3e31.chunk.js": "./static/js/1451.3b0a3e31.chunk.js",
@@ -153,6 +153,6 @@
153
153
  },
154
154
  "entrypoints": [
155
155
  "static/css/main.3aaaea00.css",
156
- "static/js/main.b84b6de2.js"
156
+ "static/js/main.5a6e0ded.js"
157
157
  ]
158
158
  }
@@ -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.b84b6de2.js"></script><link href="./static/css/main.3aaaea00.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.5a6e0ded.js"></script><link href="./static/css/main.3aaaea00.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([[4113],{34113:(e,r,t)=>{t.r(r),t.d(r,{default:()=>f});var o=t(66845),a=t(25621),n=t(22704),l=t(68411),i=t(27446),s=t(63730),d=t(66694),c=t(84457),g=t(1515);const p=(0,g.Z)("div",{target:"e11k5jya2"})((e=>{let{}=e;return{display:"flex",flexDirection:"column"}}),""),u=(0,g.Z)("a",{target:"e11k5jya1"})((e=>{let{disabled:r,isCurrentPage:t,fluidWidth:o,theme:a}=e;return{textDecoration:"none",width:"number"==typeof o?"".concat(o,"px"):"fit-content",display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",gap:a.spacing.sm,borderRadius:a.spacing.twoXS,paddingLeft:a.spacing.sm,paddingRight:a.spacing.sm,marginTop:a.spacing.threeXS,marginBottom:a.spacing.threeXS,lineHeight:a.lineHeights.menuItem,backgroundColor:t?a.colors.darkenedBgMix15:"transparent","&:hover":{backgroundColor:t?a.colors.darkenedBgMix25:a.colors.darkenedBgMix15},"&:active,&:visited,&:hover":{textDecoration:"none"},"&:focus":{outline:"none"},"&:focus-visible":{backgroundColor:a.colors.darkenedBgMix15},"@media print":{paddingLeft:a.spacing.none},...r?{borderColor:a.colors.fadedText10,backgroundColor:a.colors.transparent,color:a.colors.fadedText40,cursor:"not-allowed","&:hover":{color:a.colors.fadedText40,backgroundColor:a.colors.transparent}}:{}}}),""),h=(0,g.Z)("span",{target:"e11k5jya0"})((e=>{let{disabled:r,theme:t}=e;return{color:t.colors.bodyText,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",display:"table-cell",...r?{borderColor:t.colors.fadedText10,backgroundColor:t.colors.transparent,color:t.colors.fadedText40,cursor:"not-allowed"}:{}}}),"");var x=t(40864);const f=function(e){const{onPageChange:r,currentPageScriptHash:t}=o.useContext(d.E),g=o.useContext(c.Z),{colors:f}=(0,a.u)(),{disabled:b,element:k,width:m}=e,C={width:m},w=function(e,r){return!(null!==e||!r)||!(null===e&&!r)&&!0===e}(k.useContainerWidth,g),v=t===k.pageScriptHash;return(0,x.jsx)("div",{className:"row-widget stPageLink","data-testid":"stPageLink",style:C,children:(0,x.jsx)(i.t,{help:k.help,placement:l.u.TOP_RIGHT,children:(0,x.jsx)(p,{children:(0,x.jsxs)(u,{"data-testid":"stPageLink-NavLink",disabled:b,isCurrentPage:v,fluidWidth:!!w&&m,href:k.page,target:k.external?"_blank":"",rel:"noreferrer",onClick:e=>{k.external?b&&e.preventDefault():(e.preventDefault(),b||r(k.pageScriptHash))},children:[k.icon&&(0,x.jsx)(n.p,{size:"lg",color:f.bodyText,iconValue:k.icon}),(0,x.jsx)(h,{disabled:b,children:(0,x.jsx)(s.ZP,{source:k.label,allowHTML:!1,isLabel:!0,boldLabel:v,largerLabel:!0,disableLinks:!0})})]})})})})}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[6013],{79986:(e,t,r)=>{r.d(t,{Z:()=>d});r(66845);var n,o=r(50641),i=r(86659),a=r(50669),s=r(1515);const c=(0,r(7865).F4)(n||(n=(0,a.Z)(["\n 50% {\n color: rgba(0, 0, 0, 0);\n }\n"]))),l=(0,s.Z)("span",{target:"edlqvik0"})((e=>{let{includeDot:t,shouldBlink:r,theme:n}=e;return{...t?{"&::before":{opacity:1,content:'"\u2022"',animation:"none",color:n.colors.gray,margin:"0 5px"}}:{},...r?{color:n.colors.red,animationName:"".concat(c),animationDuration:"0.5s",animationIterationCount:5}:{}}}),"");var u=r(40864);const d=e=>{let{dirty:t,value:r,maxLength:n,className:a,type:s="single",inForm:c}=e;const d=[],p=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];d.push((0,u.jsx)(l,{includeDot:d.length>0,shouldBlink:t,children:e},d.length))};if(t){const e=c?"submit form":"apply";if("multiline"===s){const t=(0,o.Ge)()?"\u2318":"Ctrl";p("Press ".concat(t,"+Enter to ").concat(e))}else"single"===s&&p("Press Enter to ".concat(e))}return n&&("chat"!==s||t)&&p("".concat(r.length,"/").concat(n),t&&r.length>=n),(0,u.jsx)(i.X7,{"data-testid":"InputInstructions",className:a,children:d})}},46013:(e,t,r)=>{r.r(t),r.d(t,{default:()=>x});var n=r(66845),o=r(25621),i=r(25773),a=r(69),s=n.forwardRef((function(e,t){return n.createElement(a.D,(0,i.Z)({iconAttrs:{fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},e,{ref:t}),n.createElement("rect",{width:24,height:24,fill:"none"}),n.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"}))}));s.displayName="Send";var c=r(118),l=r(46927),u=r(79986),d=r(27466),p=r(48266),f=r(1515);const h=(0,f.Z)("div",{target:"e1d2x3se4"})((e=>{var t;let{theme:r,width:n}=e;return{borderRadius:r.radii.lg,display:"flex",backgroundColor:null!==(t=r.colors.widgetBackgroundColor)&&void 0!==t?t:r.colors.secondaryBg,width:"".concat(n,"px")}}),""),y=(0,f.Z)("div",{target:"e1d2x3se3"})((e=>{let{theme:t}=e;return{backgroundColor:t.colors.transparent,position:"relative",flexGrow:1,borderRadius:t.radii.lg,display:"flex",alignItems:"center"}}),""),g=(0,f.Z)("button",{target:"e1d2x3se2"})((e=>{let{theme:t,disabled:r,extended:n}=e;const o=(0,d.Iy)(t),[i,a]=o?[t.colors.gray60,t.colors.gray80]:[t.colors.gray80,t.colors.gray40];return{border:"none",backgroundColor:t.colors.transparent,borderTopRightRadius:n?t.radii.none:t.radii.lg,borderTopLeftRadius:n?t.radii.lg:t.radii.none,borderBottomRightRadius:t.radii.lg,display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:1,margin:0,padding:t.spacing.sm,color:r?i:a,pointerEvents:"auto","&:focus":{outline:"none"},":focus":{outline:"none"},"&:focus-visible":{backgroundColor:o?t.colors.gray10:t.colors.gray90},"&:hover":{backgroundColor:t.colors.primary,color:t.colors.white},"&:disabled, &:disabled:hover, &:disabled:active":{backgroundColor:t.colors.transparent,borderColor:t.colors.transparent,color:t.colors.gray}}}),""),b=(0,f.Z)("div",{target:"e1d2x3se1"})((()=>({display:"flex",alignItems:"flex-end",height:"100%",position:"absolute",right:"0px",pointerEvents:"none"})),""),m=(0,f.Z)("div",{target:"e1d2x3se0"})({name:"1lm6gnd",styles:"position:absolute;bottom:0px;right:3rem"});var v=r(40864);const x=function(e){let{width:t,element:r,widgetMgr:i,fragmentId:a}=e;const f=(0,o.u)(),[x,w]=(0,n.useState)(!1),[O,j]=(0,n.useState)(r.default),[C,S]=(0,n.useState)(0),P=(0,n.useRef)(null),R=(0,n.useRef)({minHeight:0,maxHeight:0}),k=()=>{P.current&&P.current.focus(),O&&(i.setStringTriggerValue(r,O,{fromUi:!0},a),w(!1),j(""),S(0))};(0,n.useEffect)((()=>{if(r.setValue){r.setValue=!1;const e=r.value||"";j(e),w(""!==e)}}),[r]),(0,n.useEffect)((()=>{if(P.current){const{offsetHeight:e}=P.current;R.current.minHeight=e,R.current.maxHeight=6.5*e}}),[P]);const{disabled:I,placeholder:E,maxChars:B}=r,T=(0,d.Iy)(f),{minHeight:F,maxHeight:Z}=R.current,z=T?f.colors.gray70:f.colors.gray80,A=!!(C>0&&P.current)&&Math.abs(C-F)>1;return(0,v.jsx)(h,{className:"stChatInput","data-testid":"stChatInput",width:t,children:(0,v.jsxs)(y,{children:[(0,v.jsx)(c.Z,{inputRef:P,value:O,placeholder:E,onChange:e=>{const{value:t}=e.target,{maxChars:n}=r;0!==n&&t.length>n||(w(""!==t),j(t),S((()=>{let e=0;const{current:t}=P;if(t){const r=t.placeholder;t.placeholder="",t.style.height="auto",e=t.scrollHeight,t.placeholder=r,t.style.height=""}return e})()))},onKeyDown:e=>{const{metaKey:t,ctrlKey:r,shiftKey:n}=e;(e=>{var t;const{keyCode:r,key:n}=e;return("Enter"===n||13===r||10===r)&&!(!0===(null===(t=e.nativeEvent)||void 0===t?void 0:t.isComposing))})(e)&&!n&&!r&&!t&&(e.preventDefault(),k())},"aria-label":E,disabled:I,rows:1,overrides:{Root:{style:{outline:"none",backgroundColor:f.colors.transparent,borderLeftWidth:"1px",borderRightWidth:"1px",borderTopWidth:"1px",borderBottomWidth:"1px",width:"".concat(t,"px")}},InputContainer:{style:{backgroundColor:f.colors.transparent}},Input:{props:{"data-testid":"stChatInputTextArea"},style:{lineHeight:"1.4",backgroundColor:f.colors.transparent,"::placeholder":{color:z},height:A?"".concat(C+1,"px"):"auto",maxHeight:Z?"".concat(Z,"px"):"none",paddingRight:"3rem",paddingLeft:f.spacing.sm,paddingBottom:f.spacing.sm,paddingTop:f.spacing.sm}}}}),t>p.A.hideWidgetDetails&&(0,v.jsx)(m,{children:(0,v.jsx)(u.Z,{dirty:x,value:O,maxLength:B,type:"chat",inForm:!1})}),(0,v.jsx)(b,{children:(0,v.jsx)(g,{onClick:k,disabled:!x||I,extended:A,"data-testid":"stChatInputSubmitButton",children:(0,v.jsx)(l.Z,{content:s,size:"xl",color:"inherit"})})})]})})}},118:(e,t,r)=>{r.d(t,{Z:()=>P});var n=r(66845),o=r(80318),i=r(9656),a=r(38254),s=r(80745),c=r(98479);function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var p=(0,s.zo)("div",(function(e){return u(u({},(0,c.d5)(u(u({$positive:!1},e),{},{$hasIconTrailing:!1}))),{},{width:e.$resize?"fit-content":"100%"})}));p.displayName="StyledTextAreaRoot",p.displayName="StyledTextAreaRoot";var f=(0,s.zo)("div",(function(e){return(0,c.hB)(u({$positive:!1},e))}));f.displayName="StyledTextareaContainer",f.displayName="StyledTextareaContainer";var h=(0,s.zo)("textarea",(function(e){return u(u({},(0,c.Hx)(e)),{},{resize:e.$resize||"none"})}));function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function g(){return g=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!==typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==r)return;var n,o,i=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(c){s=!0,o=c}finally{try{a||null==r.return||r.return()}finally{if(s)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"===typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return m(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function x(e,t){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},x(e,t)}function w(e){var t=function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=j(e);if(t){var o=j(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===y(t)||"function"===typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return O(e)}(this,r)}}function O(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function j(e){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},j(e)}function C(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}h.displayName="StyledTextarea",h.displayName="StyledTextarea";var S=function(e){!function(e,t){if("function"!==typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&x(e,t)}(l,e);var t,r,s,c=w(l);function l(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return C(O(e=c.call.apply(c,[this].concat(r))),"state",{isFocused:e.props.autoFocus||!1}),C(O(e),"onFocus",(function(t){e.setState({isFocused:!0}),e.props.onFocus(t)})),C(O(e),"onBlur",(function(t){e.setState({isFocused:!1}),e.props.onBlur(t)})),e}return t=l,(r=[{key:"render",value:function(){var e=this.props.overrides,t=void 0===e?{}:e,r=b((0,o.jb)(t.Root,p),2),s=r[0],c=r[1],l=(0,o.aO)({Input:{component:h},InputContainer:{component:f}},t);return n.createElement(s,g({"data-baseweb":"textarea",$isFocused:this.state.isFocused,$isReadOnly:this.props.readOnly,$disabled:this.props.disabled,$error:this.props.error,$positive:this.props.positive,$required:this.props.required,$resize:this.props.resize},c),n.createElement(i.Z,g({},this.props,{type:a.iB.textarea,overrides:l,onFocus:this.onFocus,onBlur:this.onBlur,resize:this.props.resize})))}}])&&v(t.prototype,r),s&&v(t,s),Object.defineProperty(t,"prototype",{writable:!1}),l}(n.Component);C(S,"defaultProps",{autoFocus:!1,disabled:!1,readOnly:!1,error:!1,name:"",onBlur:function(){},onChange:function(){},onKeyDown:function(){},onKeyPress:function(){},onKeyUp:function(){},onFocus:function(){},overrides:{},placeholder:"",required:!1,rows:3,size:a.NO.default});const P=S}}]);