
    g3W                    L   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z* erd dl+m,Z, d dl)m*Z* e G d d             Z-e G d d             Z. G d d      Z/y)    )annotations)	dataclass)dedent)TYPE_CHECKINGLiteralcastoverload)current_form_id)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)StreamlitAPIException)TextArea)	TextInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)SupportsStr)DeltaGeneratorc                  *    e Zd ZU ded<   dddZddZy)	TextInputSerde
str | Nonevaluec                "    ||S | j                   S Nr"   selfui_value	widget_ids      \/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/widgets/text_widgets.pydeserializezTextInputSerde.deserialize:       #/x?TZZ?    c                    |S r$    r'   vs     r*   	serializezTextInputSerde.serialize=       r-   N r(   r!   r)   strreturnr!   r1   r!   r8   r!   __name__
__module____qualname____annotations__r+   r2   r/   r-   r*   r    r    6       @r-   r    c                  *    e Zd ZU ded<   dddZddZy)	TextAreaSerder!   r"   c                "    ||S | j                   S r$   r%   r&   s      r*   r+   zTextAreaSerde.deserializeE   r,   r-   c                    |S r$   r/   r0   s     r*   r2   zTextAreaSerde.serializeH   r3   r-   Nr4   r6   r9   r:   r/   r-   r*   rA   rA   A   r?   r-   rA   c                  F   e Zd Ze	 	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed      	 	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 	 dddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Ze	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed      	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 dddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZe	dd       Z
y)TextWidgetsMixinNFvisible)placeholderdisabledlabel_visibilityc                    y r$   r/   r'   labelr"   	max_charskeytypehelpautocomplete	on_changeargskwargsrG   rH   rI   s                 r*   
text_inputzTextWidgetsMixin.text_inputM       $ 	r-   c                    y r$   r/   rK   s                 r*   rU   zTextWidgetsMixin.text_inputa   rV   r-   rU   c               T    t               }| j                  |||||||||	|
||||      S )a  Display a single-line text input widget.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this input is for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        value : object or None
            The text value of this widget when it first renders. This will be
            cast to str internally. If ``None``, will initialize empty and
            return ``None`` until the user provides input. Defaults to empty string.

        max_chars : int or None
            Max number of characters allowed in text input.

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        type : "default" or "password"
            The type of the text input. This can be either "default" (for
            a regular text input), or "password" (for a text input that
            masks the user's typed value). Defaults to "default".

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        autocomplete : str
            An optional value that will be passed to the <input> element's
            autocomplete property. If unspecified, this value will be set to
            "new-password" for "password" inputs, and the empty string for
            "default" inputs. For more details, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete

        on_change : callable
            An optional callback invoked when this text input's value changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        placeholder : str or None
            An optional string displayed when the text input is empty. If None,
            no text is displayed.

        disabled : bool
            An optional boolean that disables the text input if set to
            ``True``. The default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        Returns
        -------
        str or None
            The current value of the text input widget or ``None`` if no value has been
            provided by the user.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> title = st.text_input("Movie title", "Life of Brian")
        >>> st.write("The current movie title is", title)

        .. output::
           https://doc-text-input.streamlit.app/
           height: 260px

        )rL   r"   rM   rN   rO   rP   rQ   rR   rS   rT   rG   rH   rI   ctx)r   _text_input)r'   rL   r"   rM   rN   rO   rP   rQ   rR   rS   rT   rG   rH   rI   rY   s                  r*   rU   zTextWidgetsMixin.text_inputu   sO    l !"%#-   
 	
r-   )rG   rH   rI   rY   c                  t        |      }t        | j                  |||dk(  rd n|       t        ||       |t	        |      nd }t        d|t        | j                        ||||||t	        |      
      }t               j                  }|||v r||   d }t               }||_
        ||_        |||_        t        | j                        |_        ||_        t        |      |j                   _        |t%        |      |_        |||_        |t	        |      |_        |dk(  rt        j,                  |_        n)|dk(  rt        j0                  |_        nt3        d|z        |	|dk(  rdnd}||_        t7        |      }t9        |j                  ||	|
|j:                  |j<                  |d	
      }|j>                  r$|j"                  |j"                  |_        d|_         | j                  jC                  d|       |j"                  S )Nr5   default_valuerU   )	user_keyform_idrL   r"   rM   rO   rP   rQ   rG   defaultpasswordzN'%s' is not a valid text_input type. Valid types are 'default' and 'password'.znew-passwordstring_valueon_change_handlerrS   rT   deserializer
serializerrY   
value_typeT)"r   r   dgr   r7   r   r
   r   filtered_stateTextInputProtoidrL   r`   r_   rH   r   rI   r"   r   rP   rM   rG   DEFAULTrO   PASSWORDr   rQ   r    r   r+   r2   value_changed	set_value_enqueue)r'   rL   r"   rM   rN   rO   rP   rQ   rR   rS   rT   rG   rH   rI   rY   
element_idsession_statetext_input_protoserdewidget_states                       r*   rZ   zTextWidgetsMixin._text_input   s2   $ SkGG"'2+$5		
 	#5*:; $/E
T4#DGG,%K(

 *+::?sm3c8J8RE)+(!&',$#2477#; $,!2R3
))/ $*4L! )2&"+.{+;(9$2$:$:!Z$2$;$;!'`  -1Z-?>RL(4%u%&'**%	
 %%!!-)5);); &)-&'78!!!r-   c
                    y r$   r/   r'   rL   r"   heightrM   rN   rP   rR   rS   rT   rG   rH   rI   s                r*   	text_areazTextWidgetsMixin.text_areaf      " 	r-   c
                    y r$   r/   rw   s                r*   ry   zTextWidgetsMixin.text_areay  rz   r-   ry   c
               ~    ||dk  rt        d| d      t               }| j                  |||||||||	|
|||      S )a  Display a multi-line text input widget.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this input is for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        value : object or None
            The text value of this widget when it first renders. This will be
            cast to str internally. If ``None``, will initialize empty and
            return ``None`` until the user provides input. Defaults to empty string.

        height : int or None
            Desired height of the UI element expressed in pixels. If this is
            ``None`` (default), the widget's initial height fits three lines.
            The height must be at least 68 pixels, which fits two lines.

        max_chars : int or None
            Maximum number of characters allowed in text area.

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this text_area's value changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        placeholder : str or None
            An optional string displayed when the text area is empty. If None,
            no text is displayed.

        disabled : bool
            An optional boolean that disables the text area if set to ``True``.
            The default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.
        Returns
        -------
        str or None
            The current value of the text area widget or ``None`` if no value has been
            provided by the user.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> txt = st.text_area(
        ...     "Text to analyze",
        ...     "It was the best of times, it was the worst of times, it was the age of "
        ...     "wisdom, it was the age of foolishness, it was the epoch of belief, it "
        ...     "was the epoch of incredulity, it was the season of Light, it was the "
        ...     "season of Darkness, it was the spring of hope, it was the winter of "
        ...     "despair, (...)",
        ... )
        >>>
        >>> st.write(f"You wrote {len(txt)} characters.")

        .. output::
           https://doc-text-area.streamlit.app/
           height: 300px

        D   zInvalid height z3px for `st.text_area` - must be at least 68 pixels.)rL   r"   rx   rM   rN   rP   rR   rS   rT   rG   rH   rI   rY   )r   r   
_text_area)r'   rL   r"   rx   rM   rN   rP   rR   rS   rT   rG   rH   rI   rY   s                 r*   ry   zTextWidgetsMixin.text_area  sr    n &2+'!&)\]  !"#-  
 	
r-   c
               |   t        |      }t        | j                  |||dk(  rd n|       t        ||       |t	        |      nd }t        d|t        | j                        |||||t	        |
      	      }t               j                  }|||v r||   d }t               }||_
        ||_        |||_        t        | j                        |_        ||_        t        |      |j                   _        |t%        |      |_        |||_        |||_        |
t	        |
      |_        t/        |      }t1        |j                  |||	|j2                  |j4                  |d      }|j6                  r$|j"                  |j"                  |_        d|_        | j                  j;                  d|       |j"                  S )Nr5   r\   ry   )r^   r_   rL   r"   rx   rM   rP   rG   rb   rc   T)r   r   rh   r   r7   r   r
   r   ri   TextAreaProtork   rL   r`   r_   rH   r   rI   r"   r   rP   rx   rM   rG   rA   r   r+   r2   rn   ro   rp   )r'   rL   r"   rx   rM   rN   rP   rR   rS   rT   rG   rH   rI   rY   rq   rr   text_area_protort   ru   s                      r*   r~   zTextWidgetsMixin._text_area  s   " SkGG"'2+$5		
 	#5*:;#/E
T4#DGG,K(


 *+::?sm3c8J8RE'/' %&+O#"1$''":#+ 1Q2
((. #)$<O %+O" (1O%"*-k*:O'e$&'**%	
 %%!!-(4(:(:%(,O%o6!!!r-   c                    t        d|       S )zGet our DeltaGenerator.r   )r   )r'   s    r*   rh   zTextWidgetsMixin.dgq  s     $d++r-   )	r5   NNr`   NNNNN)rL   r7   r"   r7   rM   
int | NonerN   
Key | NonerO   Literal['default', 'password']rP   r!   rQ   r!   rR   WidgetCallback | NonerS   WidgetArgs | NonerT   WidgetKwargs | NonerG   r!   rH   boolrI   r   r8   r7   )	NNNr`   NNNNN)rL   r7   r"   SupportsStr | NonerM   r   rN   r   rO   r   rP   r!   rQ   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   r8   r!   )rL   r7   r"   str | SupportsStr | NonerM   r   rN   r   rO   r   rP   r!   rQ   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   r8   r!   )rL   r7   r"   r   rM   r   rN   r   rO   r7   rP   r!   rQ   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   rY   ScriptRunContext | Noner8   r!   )r5   NNNNNNN)rL   r7   r"   r7   rx   r   rM   r   rN   r   rP   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   r8   r7   )NNNNNNNN)rL   r7   r"   r   rx   r   rM   r   rN   r   rP   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   r8   r!   )rL   r7   r"   r   rx   r   rM   r   rN   r   rP   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   r8   r!   )rL   r7   r"   r   rx   r   rM   r   rN   r   rP   r!   rR   r   rS   r   rT   r   rG   r!   rH   r   rI   r   rY   r   r8   r!   )r8   r   )r;   r<   r=   r	   rU   r   rZ   ry   r~   propertyrh   r/   r-   r*   rE   rE   L   s     $/8#'+/"&&* #',5  	
  -  ! )   $    *  
! &  %) $/8#'+/"&&* #',5 " 	
  -  ! )   $    *  
! & L! +- $/8#'+/"&&*E
 #',5E
E
 (E
 	E

 E
 -E
 E
 !E
 )E
  E
 $E
  E
 E
 *E
  
!E
 "E
T %' $#'+/"&&*g" #',5'+!g"g" "g" 	g"
 g" g" g" !g" )g"  g" $g"  g" g" *g"  %!g"" 
#g"R  ! $+/"&&* #',5  	
    )   $    * 
 $  %)! $+/"&&* #',5 " 	
    )   $    * 
 $ K  +-! $+/"&&*J
 #',5J
J
 (J
 	J

 J
 J
 J
 )J
  J
 $J
  J
 J
 *J
 
J
 !J
^ %'! $+/"&&*V" #',5'+V"V" "V" 	V"
 V" V" V" )V"  V" $V"  V" V" *V" %V"  
!V"p , ,r-   rE   N)0
__future__r   dataclassesr   textwrapr   typingr   r   r   r	   !streamlit.elements.lib.form_utilsr
   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   streamlit.errorsr   streamlit.proto.TextArea_pb2r   r   streamlit.proto.TextInput_pb2r   rj   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   r   streamlit.type_utilr   streamlit.delta_generatorr   r    rA   rE   r/   r-   r*   <module>r      s    # !  9 9 =  3 B E 9 O  8/      h, h,r-   