
    &eS                    \   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
 d dlZd dlmZ d dl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# d dl$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*m+Z+ e G d d                      Z,e G d d                      Z- G d d          Z.dS )    )annotations)	dataclass)dedent)castoverload)LiteralN)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_value)StreamlitAPIException)TextArea)	TextInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)compute_widget_id)KeyLabelVisibilitySupportsStrmaybe_raise_label_warningsto_keyc                  ,    e Zd ZU ded<   dddZdd
ZdS )TextInputSerde
str | Nonevalue ui_value	widget_idstrreturnc                    ||n| j         S Nr    selfr"   r#   s      Glib/python3.11/site-packages/streamlit/elements/widgets/text_widgets.pydeserializezTextInputSerde.deserialize7       #/xxTZ?    vc                    |S r'    r*   r/   s     r+   	serializezTextInputSerde.serialize:       r.   Nr!   r"   r   r#   r$   r%   r   r/   r   r%   r   __name__
__module____qualname____annotations__r,   r3   r1   r.   r+   r   r   3   T         @ @ @ @ @     r.   r   c                  ,    e Zd ZU ded<   dddZdd
ZdS )TextAreaSerder   r    r!   r"   r#   r$   r%   c                    ||n| j         S r'   r(   r)   s      r+   r,   zTextAreaSerde.deserializeB   r-   r.   r/   c                    |S r'   r1   r2   s     r+   r3   zTextAreaSerde.serializeE   r4   r.   Nr5   r6   r7   r8   r1   r.   r+   r?   r?   >   r=   r.   r?   c                     e Zd Ze	 	 	 	 	 	 	 	 	 d1ddddd2d            Ze	 	 	 	 	 	 	 	 	 d3ddddd4d!            Z ed"          	 	 	 	 	 	 	 	 	 d1ddddd5d$            Z	 	 	 	 	 	 	 	 	 d1ddddd%d6d(Ze	 	 	 	 	 	 	 	 d7ddddd8d*            Ze	 	 	 	 	 	 	 	 d9ddddd:d+            Z ed,          	 	 	 	 	 	 	 	 d7ddddd;d-            Z	 	 	 	 	 	 	 	 d7ddddd%d<d.Ze	d=d0            Z
dS )>TextWidgetsMixinr!   NdefaultFvisible)placeholderdisabledlabel_visibilitylabelr$   r    	max_chars
int | Nonekey
Key | NonetypeLiteral['default', 'password']helpr   autocomplete	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerF   rG   boolrH   r   r%   c                   d S r'   r1   r*   rI   r    rJ   rL   rN   rP   rQ   rR   rT   rV   rF   rG   rH   s                 r+   
text_inputzTextWidgetsMixin.text_inputJ   	    $ 	r.   SupportsStr | Nonec                   d S r'   r1   rZ   s                 r+   r[   zTextWidgetsMixin.text_input^   r\   r.   r[   str | SupportsStr | Nonec               d    t                      }|                     |||||||||	|
||||          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 Markdown and supports the following
            elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

            This also supports:

            * Emoji shortcodes, such as ``:+1:``  and ``:sunglasses:``.
              For a list of all supported codes,
              see https://share.streamlit.io/streamlit/emoji-shortcodes.

            * LaTeX expressions, by wrapping them in "$" or "$$" (the "$$"
              must be on their own lines). Supported LaTeX functions are listed
              at https://katex.org/docs/supported.html.

            * Colored text, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet, gray/grey, rainbow.

            Unsupported 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``.

            For accessibility reasons, you should never set an empty label (label="")
            but hide it with label_visibility if needed. In the future, we may disallow
            empty labels by raising an exception.
        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. Multiple widgets of the same type may
            not share 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
            An optional tooltip that gets displayed next to the input.
        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, which disables the text input if set to True.
            The default is False.
        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. If "hidden", the label doesn't show but there
            is still empty space for it above the widget (equivalent to label="").
            If "collapsed", both the label and the space are removed. Default is
            "visible".

        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

        )rI   r    rJ   rL   rN   rP   rQ   rR   rT   rV   rF   rG   rH   ctx)r   _text_input)r*   rI   r    rJ   rL   rN   rP   rQ   rR   rT   rV   rF   rG   rH   ra   s                  r+   r[   zTextWidgetsMixin.text_inputr   sW    T !""%#-   
 
 	
r.   )rF   rG   rH   ra   ra   ScriptRunContext | Nonec                   t          |          }t          | j        |           t          |dk    rd n||           t	          ||           |t          |          nd }t          d||||||||t          |          t          | j                  |r|j        nd           }t                      }||_
        ||_        |||_        t          | j                  |_        ||_        t          |          |j        _        |t%          |          |_        |||_        |t          |          |_        |dk    rt          j        |_        n*|dk    rt          j        |_        nt3          d|z            |
|dk    rdnd}||_        t7          |          }t9          d||||	|
|j        |j        |		  	        }|j        r|j        |j        |_        d
|_         | j        !                    d|           |j        S )Nr!   default_valuerL   r[   )user_keyrI   r    rJ   rL   rN   rP   rQ   rF   form_idpagerD   passwordzN'%s' is not a valid text_input type. Valid types are 'default' and 'password'.znew-passwordrg   on_change_handlerrT   rV   deserializer
serializerra   T)"r   r
   dgr   r   r$   r   r	   page_script_hashTextInputProtoidrI   rD   rh   rG   r   rH   r    r   rP   rJ   rF   DEFAULTrN   PASSWORDr   rQ   r   r   r,   r3   value_changed	set_value_enqueue)r*   rI   r    rJ   rL   rN   rP   rQ   rR   rT   rV   rF   rG   rH   ra   rr   text_input_protoserdewidget_states                      r+   rb   zTextWidgetsMixin._text_input   sc   $ SkkTWi000!TWXXXX"5*:;;; $/E


T%K((#DG,,),6%%$
 
 
 *++ !&',$#247#;#; $,!2R3
 3
)/ $*4LL! )2&"+.{+;+;(9$2$:!!Z$2$;!!'`   -1Z-?-?>>RL(4%u%%&'*

 

 

 % 	.!-)5); &)-&'7888!!r.   heightc
                   d S r'   r1   r*   rI   r    r{   rJ   rL   rP   rR   rT   rV   rF   rG   rH   s                r+   	text_areazTextWidgetsMixin.text_areaR  	    " 	r.   c
                   d S r'   r1   r}   s                r+   r~   zTextWidgetsMixin.text_areae  r   r.   r~   c
               b    t                      }|                     |||||||||	|
|||          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 Markdown and supports the following
            elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

            This also supports:

            * Emoji shortcodes, such as ``:+1:``  and ``:sunglasses:``.
              For a list of all supported codes,
              see https://share.streamlit.io/streamlit/emoji-shortcodes.

            * LaTeX expressions, by wrapping them in "$" or "$$" (the "$$"
              must be on their own lines). Supported LaTeX functions are listed
              at https://katex.org/docs/supported.html.

            * Colored text, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet, gray/grey, rainbow.

            Unsupported 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``.

            For accessibility reasons, you should never set an empty label (label="")
            but hide it with label_visibility if needed. In the future, we may disallow
            empty labels by raising an exception.
        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 None, a
            default height is used.
        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. Multiple widgets of the same type may
            not share the same key.
        help : str
            An optional tooltip that gets displayed next to the textarea.
        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, which disables the text area if set to True.
            The default is False.
        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. If "hidden", the label doesn't show but there
            is still empty space for it above the widget (equivalent to label="").
            If "collapsed", both the label and the space are removed. Default is
            "visible".

        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

        )rI   r    r{   rJ   rL   rP   rR   rT   rV   rF   rG   rH   ra   )r   
_text_area)r*   rI   r    r{   rJ   rL   rP   rR   rT   rV   rF   rG   rH   ra   s                 r+   r~   zTextWidgetsMixin.text_areax  sR    V !""#-  
 
 	
r.   c
               f   t          |          }t          | j        |           t          |dk    rd n||           t	          ||           |t          |          nd }t          d|||||||t          |
          t          | j                  |r|j        nd           }t                      }||_
        ||_        |||_        t          | j                  |_        ||_        t          |          |j        _        |t%          |          |_        |||_        |||_        |
t          |
          |_        t/          |          }t1          d|||||	|j        |j        |	  	        }|j        r|j        |j        |_        d|_        | j                            d|           |j        S )Nr!   re   r~   )
rg   rI   r    r{   rJ   rL   rP   rF   rh   ri   rk   T)r   r
   ro   r   r   r$   r   r	   rp   TextAreaProtorr   rI   rD   rh   rG   r   rH   r    r   rP   r{   rJ   rF   r?   r   r,   r3   ru   rv   rw   )r*   rI   r    r{   rJ   rL   rP   rR   rT   rV   rF   rG   rH   ra   rr   text_area_protory   rz   s                     r+   r   zTextWidgetsMixin._text_area  s   " SkkTWi000!TWXXXX"5*:;;;#/E


TK((#DG,,),6%%$
 
 
 (// %&+O#"1$'":":#+ 1Q2
 2
(. #)$<<O %+O" (1O%"*-k*:*:O'e$$&'*

 

 

 % 	-!-(4(:%(,O%o666!!r.   *'streamlit.delta_generator.DeltaGenerator'c                "    t          d|           S )zGet our DeltaGenerator.z(streamlit.delta_generator.DeltaGenerator)r   )r*   s    r+   ro   zTextWidgetsMixin.dgG  s     >EEEr.   )	r!   NNrD   NNNNN)rI   r$   r    r$   rJ   rK   rL   rM   rN   rO   rP   r   rQ   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r$   )	NNNrD   NNNNN)rI   r$   r    r]   rJ   rK   rL   rM   rN   rO   rP   r   rQ   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r   )rI   r$   r    r_   rJ   rK   rL   rM   rN   rO   rP   r   rQ   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r   )rI   r$   r    r]   rJ   rK   rL   rM   rN   r$   rP   r   rQ   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   ra   rc   r%   r   )r!   NNNNNNN)rI   r$   r    r$   r{   rK   rJ   rK   rL   rM   rP   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r$   )NNNNNNNN)rI   r$   r    r]   r{   rK   rJ   rK   rL   rM   rP   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r   )rI   r$   r    r_   r{   rK   rJ   rK   rL   rM   rP   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   r%   r   )rI   r$   r    r]   r{   rK   rJ   rK   rL   rM   rP   r   rR   rS   rT   rU   rV   rW   rF   r   rG   rX   rH   r   ra   rc   r%   r   )r%   r   )r9   r:   r;   r   r[   r   rb   r~   r   propertyro   r1   r.   r+   rC   rC   I   s         $/8#'+/"&&* #',5     X&  %) $/8#'+/"&&* #',5     X& ^L!! +- $/8#'+/"&&*y
 #',5y
 y
 y
 y
 y
 "!y
| %' $#'+/"&&*b" #',5'+!b" b" b" b" b" b"H  ! $+/"&&* #',5     X$  %)! $+/"&&* #',5     X$ ^K   +-! $+/"&&*y
 #',5y
 y
 y
 y
 y
 ! y
| %'! $+/"&&*Q" #',5'+Q" Q" Q" Q" Q" Q"f F F F XF F Fr.   rC   )/
__future__r   dataclassesr   textwrapr   typingr   r   typing_extensionsr   	streamlitstreamlit.elements.formr	   streamlit.elements.utilsr
   r   r   streamlit.errorsr   streamlit.proto.TextArea_pb2r   r   streamlit.proto.TextInput_pb2r   rq   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   streamlit.runtime.state.commonr   streamlit.type_utilr   r   r   r   r   r   r?   rC   r1   r.   r+   <module>r      s]   # " " " " " ! ! ! ! ! !       ! ! ! ! ! ! ! ! % % % % % %     3 3 3 3 3 3         
 3 2 2 2 2 2 B B B B B B E E E E E E 9 9 9 9 9 9 O O O O O O O O            = < < < < <                             AF AF AF AF AF AF AF AF AF AFr.   