o
    沪g3W                     @  s.  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 dZ-eG dd dZ.G dd dZ/dS )    )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d	ZdddZdS )TextInputSerde
str | Nonevalue ui_value	widget_idstrreturnc                 C     |d ur|S | j S Nr!   selfr#   r$    r,   c/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/text_widgets.pydeserialize:      zTextInputSerde.deserializevc                 C     |S r(   r,   r+   r0   r,   r,   r-   	serialize=      zTextInputSerde.serializeNr"   r#   r    r$   r%   r&   r    r0   r    r&   r    __name__
__module____qualname____annotations__r.   r3   r,   r,   r,   r-   r   6      
 r   c                   @  r   )TextAreaSerder    r!   r"   r#   r$   r%   r&   c                 C  r'   r(   r)   r*   r,   r,   r-   r.   E   r/   zTextAreaSerde.deserializer0   c                 C  r1   r(   r,   r2   r,   r,   r-   r3   H   r4   zTextAreaSerde.serializeNr5   r6   r7   r8   r,   r,   r,   r-   r>   A   r=   r>   c                   @  sv  e Zd Ze									d6ddddd7dd Ze									d8ddddd9d"d Zed#									d6ddddd:d%d Z									d6ddddd&d;d)d*Ze								d<ddddd=d,d-Ze								d>ddddd?d.d-Zed/								d<ddddd@d0d-Z								d<ddddd&dAd1d2Ze	dBd4d5Z
dS )C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 | NonerB   rC   boolrD   r   r&   c                C     d S r(   r,   r+   rE   r!   rF   rH   rJ   rL   rM   rN   rP   rR   rB   rC   rD   r,   r,   r-   
text_inputM      zTextWidgetsMixin.text_inputSupportsStr | Nonec                C  rU   r(   r,   rV   r,   r,   r-   rW   a   rX   rW   str | SupportsStr | Nonec                C  s,   t  }| j|||||||||	|
||||d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

        )rE   r!   rF   rH   rJ   rL   rM   rN   rP   rR   rB   rC   rD   ctx)r   _text_input)r+   rE   r!   rF   rH   rJ   rL   rM   rN   rP   rR   rB   rC   rD   r[   r,   r,   r-   rW   u   s"   v)rB   rC   rD   r[   r[   ScriptRunContext | Nonec                C  s  t |}t| j|||dkrd n|d t|| |d ur t|nd }td|t| j||||||t|d
}t j}|d urI||v rI|| d u rId }t	 }||_
||_|d urY||_t| j|_||_t||j_|d urqt||_|d urx||_|d urt||_|dkrt	j|_n|dkrt	j|_ntd| |d u r|dkrdnd}||_t|}t|j
||	|
|j|j|d	d
}|jr|jd ur|j|_d|_ | j!d| |jS )Nr"   default_valuerW   )	user_keyform_idrE   r!   rF   rJ   rL   rM   rB   r@   passwordzN'%s' is not a valid text_input type. Valid types are 'default' and 'password'.znew-passwordstring_valueon_change_handlerrP   rR   deserializer
serializerr[   
value_typeT)"r   r
   dgr   r%   r   r	   r   filtered_stateTextInputProtoidrE   r@   ra   rC   r   rD   r!   r   rL   rF   rB   DEFAULTrJ   PASSWORDr   rM   r   r   r.   r3   value_changed	set_value_enqueue)r+   rE   r!   rF   rH   rJ   rL   rM   rN   rP   rR   rB   rC   rD   r[   
element_idsession_statetext_input_protoserdewidget_stater,   r,   r-   r\      s   





zTextWidgetsMixin._text_inputheightc
                C  rU   r(   r,   r+   rE   r!   rw   rF   rH   rL   rN   rP   rR   rB   rC   rD   r,   r,   r-   	text_areaf     zTextWidgetsMixin.text_areac
                C  rU   r(   r,   rx   r,   r,   r-   ry   y  rz   ry   c
                C  sJ   |dur|dk rt d| dt }| j|||||||||	|
|||d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

        ND   zInvalid height z3px for `st.text_area` - must be at least 68 pixels.)rE   r!   rw   rF   rH   rL   rN   rP   rR   rB   rC   rD   r[   )r   r   
_text_area)r+   rE   r!   rw   rF   rH   rL   rN   rP   rR   rB   rC   rD   r[   r,   r,   r-   ry     s(   w
c
                C  sf  t |}t| j|||dkrd n|d t|| |d ur t|nd }td|t| j|||||t|
d	}t j}|d urH||v rH|| d u rHd }t	 }||_
||_|d urX||_t| j|_||_t||j_|d urpt||_|d urw||_|d ur~||_|
d urt|
|_t|}t|j
|||	|j|j|dd}|jr|jd ur|j|_d|_| jd| |jS )Nr"   r^   ry   )r`   ra   rE   r!   rw   rF   rL   rB   rc   rd   T)r   r
   ri   r   r%   r   r	   r   rj   TextAreaProtorl   rE   r@   ra   rC   r   rD   r!   r   rL   rw   rF   rB   r>   r   r.   r3   ro   rp   rq   )r+   rE   r!   rw   rF   rH   rL   rN   rP   rR   rB   rC   rD   r[   rr   rs   text_area_protoru   rv   r,   r,   r-   r|     st   



zTextWidgetsMixin._text_arear   c                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r+   r,   r,   r-   ri   q  s   
zTextWidgetsMixin.dg)	r"   NNr@   NNNNN)rE   r%   r!   r%   rF   rG   rH   rI   rJ   rK   rL   r    rM   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r%   )	NNNr@   NNNNN)rE   r%   r!   rY   rF   rG   rH   rI   rJ   rK   rL   r    rM   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r    )rE   r%   r!   rZ   rF   rG   rH   rI   rJ   rK   rL   r    rM   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r    )rE   r%   r!   rY   rF   rG   rH   rI   rJ   r%   rL   r    rM   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r[   r]   r&   r    )r"   NNNNNNN)rE   r%   r!   r%   rw   rG   rF   rG   rH   rI   rL   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r%   )NNNNNNNN)rE   r%   r!   rY   rw   rG   rF   rG   rH   rI   rL   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r    )rE   r%   r!   rZ   rw   rG   rF   rG   rH   rI   rL   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r&   r    )rE   r%   r!   rY   rw   rG   rF   rG   rH   rI   rL   r    rN   rO   rP   rQ   rR   rS   rB   r    rC   rT   rD   r   r[   r]   r&   r    )r&   r   )r9   r:   r;   r   rW   r   r\   ry   r|   propertyri   r,   r,   r,   r-   r?   L   s     i Xr?   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   rk   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   r   streamlit.type_utilr   streamlit.delta_generatorr   r   r>   r?   r,   r,   r,   r-   <module>   s,   

