
    /_i#                       d dl mZ d dlZd dl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 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 d dlmZ d dlmZ d dlmZ d dl m!Z!m"Z" erd dl#m$Z$ d dl%m&Z&  G d de      Z' G d de      Z(y)    )annotationsN)TYPE_CHECKINGAny)BaseCustomComponent)is_dataframe_like)get_dg_singleton_instance)current_form_id)check_cache_replay_rules)compute_and_register_element_id)StreamlitAPIException)
ArrowTable)
SpecialArg)Element)gather_metrics)get_script_run_ctx)register_widget)is_bytes_liketo_bytes)DeltaGenerator)WidgetCallbackc                      e Zd ZdZy)MarshallComponentExceptionzCClass for exceptions generated during custom component marshalling.N)__name__
__module____qualname____doc__     g/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/components/v1/custom_component.pyr   r   (   s    Mr   r   c                      e Zd ZdZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d
dZ ed      ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d
d       ZddZej                  Z	ddZ
dd	Zy)CustomComponentzA Custom Component declaration.Ndefaultkey	on_change	tab_indexc               0     | j                   |||||d|S )zAn alias for create_instance.r"   )create_instance)selfr#   r$   r%   r&   argskwargss          r   __call__zCustomComponent.__call__1   s2     $t##
 
 	
r   r(   c          	         t        |      dkD  rt        d|d    d      0t        t              rt        t              sdk\  st        d      	 ddl}ddlm t                t        |	      }i }	g |j                         D ]  \  }
}t        |      r3t               }|
|_        t!        |      |_        j%                  |       Dt'        |      rIt               }|
|_        j)                  |j*                  j,                  |       j%                  |       ||	|
<    	 t/        j0                  |	      d fd}t5               j6                  }t9               } |||      }|j;                  d|j<                         |S # t        $ r t        d      w xY w# t2        $ r}t        d
|      d}~ww xY w)a  Create a new instance of the component.

        Parameters
        ----------
        *args
            Must be empty; all args must be named. (This parameter exists to
            enforce correct use of the function.)
        default: any or None
            The default return value for the component. This is returned when
            the component's frontend hasn't yet specified a value with
            `setComponentValue`.
        key: str or None
            If not None, this is the user key we use to generate the
            component's "widget ID".
        on_change: WidgetCallback or None
            An optional callback invoked when the widget's value changes. No arguments are passed to it.
        tab_index : int, optional
            Specifies the tab order of the iframe containing the component.
            Possible values are:
            - ``None`` (default): Browser default behavior.
            - ``-1``: Removes the iframe from the natural tab order, but it can still be focused programmatically.
            - ``0`` or positive integer: Includes the iframe in the natural tab order.
        **kwargs
            Keyword args to pass to the component.

        Returns
        -------
        any or None
            The component's widget value.

        r   z
Argument 'z' needs a labelNz6tab_index must be None, -1, or a non-negative integer.)component_arrowzTo use Custom Components in Streamlit, you need to install
PyArrow. To do so locally:

`pip install pyarrow`

And if you're using Streamlit Cloud, add "pyarrow" to your requirements.txt.)r#   r$   z(Could not convert component args to JSONc           
        
j                   |j                  _        t        |       |j                  _        
j
                  
j
                  |j                  _        |j                  _        |j                  _        |j                  j                  j                         t        dddh| 
j                   
j
                        }||j                  _        d	d}t        |j                  j                  |d t               	d      }|j                  }|}|S t        |t               rj#                  |      }|S )
Ncomponent_instancenameurl)user_keykey_as_main_identitydgr2   r3   	json_argsspecial_argsc                    | S Nr   )ui_values    r   deserialize_componentzZCustomComponent.create_instance.<locals>.marshall_component.<locals>.deserialize_component   s    r   c                    | S r:   r   )xs    r   <lambda>zMCustomComponent.create_instance.<locals>.marshall_component.<locals>.<lambda>   s    Q r   
json_value)deserializer
serializerctxon_change_handler
value_type)r;   r   returnr   )r2   r1   component_namer	   form_idr3   r&   r7   r8   extendr   idr   r   value
isinstanceArrowTableProtoarrow_proto_to_dataframe)r6   elementcomputed_idr<   component_statewidget_valuer/   r#   r$   r%   r)   serialized_json_argsr8   r&   s         r   marshall_componentz;CustomComponent.create_instance.<locals>.marshall_component   s4   8<		G&&51@1DG&&.xx#15**.$7@**43GG&&0&&33::<H9$ '-e_YYHH.)K -8G&&)  .**--2&&("+'O +00L#&   L/:.GGUr   r1   )r6   r   rO   r   rF   r   )lenr   rL   intboolr   pyarrowstreamlit.components.v1r/   ImportErrorr
   dictitemsr   r   r$   r   bytesappendr   marshallarrow_dataframedatajsondumps	Exceptionr   main_dgr   _enqueuer1   )r)   r#   r$   r%   r&   r*   r+   rX   all_argsr7   arg_namearg_val	bytes_argdataframe_argexrT   r6   rO   return_valuer/   rS   r8   s   `````              @@@r   r(   zCustomComponent.create_instanceD   s   R t9q=,z$q'/-RSS  y#&y$/R'H 	? 	!" S9	!)!1 	.HgW%&L	 (	"*7"3	##I."7+ *$,!(()F)F)K)KWU##M2&-	(#	.	#'::i#8 ,	  ,	 ` '(00))"g6
('*D*DE{  	'P 	D  	,:B 	s$   
F 2F1 F.1	G:GGc                    t        |t              xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S )zEquality operator.)rL   r!   r2   pathr3   module_namer)   others     r   __eq__zCustomComponent.__eq__   so     uo. 6		UZZ'6		UZZ'6 EII%6   E$5$55	
r   c                    | |k(   S )zInequality operator.r   rq   s     r   __ne__zCustomComponent.__ne__   s    
 5=  r   c                n    d| j                    d| j                  | j                   S | j                   S )N'z': )r2   ro   r3   )r)   s    r   __str__zCustomComponent.__str__   s6    499+Sdii.C RSS RSSr   )r*   r   r#   r   r$   z
str | Noner%   zWidgetCallback | Noner&   z
int | Noner+   r   rF   r   )rr   objectrF   rW   )rF   str)r   r   r   r   r,   r   r(   rs   r   __hash__ru   rx   r   r   r   r!   r!   .   s    )
 +/ $

 
 	

 )
 
 
 

& %& +/ $VV V 	V
 )V V V 
V 'Vp
 #++H!Tr   r!   ))
__future__r   rb   typingr   r   0streamlit.components.types.base_custom_componentr   streamlit.dataframe_utilr   $streamlit.delta_generator_singletonsr   !streamlit.elements.lib.form_utilsr	   streamlit.elements.lib.policiesr
   streamlit.elements.lib.utilsr   streamlit.errorsr   streamlit.proto.Components_pb2r   rM   r   streamlit.proto.Element_pb2r   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   streamlit.runtime.stater   streamlit.type_utilr   r   streamlit.delta_generatorr   streamlit.runtime.state.commonr   r   r!   r   r   r   <module>r      sa    #  % P 6 J = D H 2 H 5 / 9 V 3 78=	!6 	CT) CTr   