
    )j<C                        d dl Z d dlZd dlmZ ddlmZ ddlmZmZm	Z	m
Z
  e j        e          Zg dZ G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Zddddd eez  d!ee         d"edz  d#ed$edz  d%efd&Z G d' d(e          ZdS ))    N)Path   )AbstractElement   )UserDefinedFunctionExternalScriptget_external_script_from_nameregister_user_provided_script)LoadingServerTemplateScriptStyleJSEvalGetterClientStateChangeClientTriggersDeepReactiveLifeCycleMonitorSizeObserverHandlerregister_external_scriptc                   $     e Zd ZdZd fd	Z xZS )r   zn
    Three circle spinning with a message

    :param message: Content of the message
    :type name: str
    Nc                 `     t                      j        d|fi | | xj        dgz  c_        d S )Nztrame-loadingmessagesuper__init___attr_namesselfchildrenkwargs	__class__s      T/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trame_client/widgets/trame.pyr   zLoading.__init__+   sF    (==f===
 	
    N__name__
__module____qualname____doc__r   __classcell__r#   s   @r$   r   r   #   sG         
 
 
 
 
 
 
 
 
 
r%   r   c                   $     e Zd ZdZd fd	Z xZS )r   a  
    Template content presentation

    :param name: Name of the template to display. (default: 'main')
    :type name: str

    :param use_url: If true, will use the `{url_key}=` from the url to override
                    the `name=` attribute.
    :type use_url: bool

    :param url_key: Name of the key to extract from url for use_url. (default: 'ui')
    :type url_key: str
    Nc                 b     t                      j        d|fi | | xj        g dz  c_        d S )Nztrame-template))nametemplateName)use_urluseUrl)url_keyurlKeyr   r   s      r$   r   zServerTemplate.__init__D   sN    )8>>v>>> 
 
 
 	
r%   r&   r'   r-   s   @r$   r   r   5   sG         
 
 
 
 
 
 
 
 
 
r%   r   c                   0     e Zd ZdZdZd fd	ZddZ xZS )r   z Provide means to execute JS coder   Nc                 "    t                      j        d|fi | t          xj        dz  c_        |                    ddt          j                   | _        d| j         d| j        d<   | xj        dgz  c_        | xj        dgz  c_        d S )	Nz
trame-execr   reftrame_exec_ref_zref=""eventexec)	r   r   r   _next_idget_JSEval__ref_attributesr   _event_namesr   s      r$   r   zJSEval.__init__U   s    x::6:::1ZZ'J'J'JKK
"7$*"7"7"7
 	
 	
 	
r%   c                     |"| j                             | j        d           d S | j                             | j        d|           d S )Nr<   )serverjs_callr?   )r    r;   s     r$   r<   zJSEval.execa   sI    =K
F33333K
FE:::::r%   r&   )r(   r)   r*   r+   r=   r   r<   r,   r-   s   @r$   r   r   P   s\        **H

 

 

 

 

 

; ; ; ; ; ; ; ;r%   r   c                   D     e Zd ZdZdZd fd	Zd Zed             Z xZ	S )r   z(Provide means to inject global CSS rulesr   Nc                    t           xj        dz  c_         t                      j        di | dt           j         | _        d| j         d| j        d<   | j        j        j        	                    | j        |           d S )Nr   trame-styletrame__inline_style_z:css="r:   _css)rG   )
r   r=   r   r   _keyr@   rC   root_serverstate
setdefault)r    css_contentr"   r#   s      r$   r   zStyle.__init__p   s    !11&111;5>;;	#8DI#8#8#8 %00KHHHHHr%   c                 8    || j         j        j        | j        <   dS zUpdate style contentNrC   rK   rL   rJ   )r    rN   s     r$   updatezStyle.updatew   s    3>%di000r%   c                     | j         S z/Name the the state variable used by this widgetrJ   r    s    r$   var_namezStyle.var_name{        yr%   r&   
r(   r)   r*   r+   r=   r   rR   propertyrW   r,   r-   s   @r$   r   r   k   sx        22HI I I I I I? ? ?   X    r%   r   c                   D     e Zd ZdZdZd fd	Zd Zed             Z xZ	S )r   z+Provide means to inject a global script tagr   Nc                 *   t           xj        dz  c_         t                      j        di | dt           j         | _        d| j         d| j        d<   | j        j        j        	                    | j        |           | xj
        g dz  c_
        d S )	Nr   trame-scripttrame__inline_script_z	:script="r:   _script)moduleasynccrossorigindefer	integritynomodulereferrerpolicysrc)r]   )r   r=   r   r   rJ   r@   rC   rK   rL   rM   r   )r    script_contentr"   r#   s      r$   r   zScript.__init__   s    1226222=FO==	&>$)&>&>&>#%00NKKK 	
 	
 	
 		
r%   c                 8    || j         j        j        | j        <   dS rP   rQ   )r    rh   s     r$   rR   zScript.update   s    3A%di000r%   c                     | j         S rT   rU   rV   s    r$   rW   zScript.var_name   rX   r%   r&   rY   r-   s   @r$   r   r      su        55H
 
 
 
 
 
"B B B   X    r%   r   c                   .     e Zd ZdZ	 	 	 	 	 d fd	Z xZS )r   a  Provide means to extract a reactive state variable from its name

    :param name: Name of the state variable to extract. This can be an expression too.

    :param value_name: Name of the JavaScript variable name (default: "value")
    :type value_name: str

    :param key_name: Name for the JavaScript variable that will hold the evaluate expression of the "name" property.

    :param update_nested_name: Method name if you aim to update the nested structure.

    :param update_name: Method name if you aim to update the full value.
    Nc                     t                      j        di | | xj        dgz  c_        g }|r|                    d|            |r|                    d|            |r|                    d|            |r|                    d|            n|                    d           dd	                    |           d
| j        d<   d S )Ntrame-getterr0   z	keyName: zupdateNested: zupdate: zvalue: valuez
v-slot="{ z,  }"slot)rm   )r   r   r   appendjoinr@   )	r    r!   
value_namekey_nameupdate_nested_nameupdate_namer"   extractsr#   s	           r$   r   zGetter.__init__   s    	226222
 	
  	4OO222333 	COOA-?AABBB 	6OO4{44555 	%OO2j223333OOG$$$#J81D1D#J#J#J   r%   )NNNNNr'   r-   s   @r$   r   r      sb           K K K K K K K K K Kr%   r   c                   $     e Zd ZdZd fd	Z xZS )r   a  
    Allow the client side to trigger an event when a state element changes.

    :param value: Name of the state variable to monitor
    :type value: str
    :param immediate: Trigger change right away rather than at nextTick (default: False)
    :type immediate: bool
    :param trigger_on_create: If set to true, the change event will be triggered when the client start. (default: False)
    :type trigger_on_create: bool
    :param change: Event triggered when state[value] change
    :type change: Function or JS expression (event)
    Nc                      t                      j        d|fi | | xj        g dz  c_        | xj        dgz  c_        d S )Nztrame-client-state-change))rn   z:value	immediate)trigger_on_createtriggerChangeOnCreatechanger   r   r   rA   r   s      r$   r   zClientStateChange.__init__   sf    4hII&III 
 
 
 	

 	hZ'r%   r&   r'   r-   s   @r$   r   r      sG         ( ( ( ( ( ( ( ( ( (r%   r   c                   *     e Zd ZdZd fd	Zd Z xZS )r   a/  
    Allow to trigger an event on the client side

    :param ref: Identifier for the client side DOM elem
    :param **kwargs: List of events to registers with their callbacks

    Built-in events are:
       - mounted
       - created
       - before_destroy
       - before_unmount
       - exit
    trame_triggersNc                     || _          t                      j        dd |d| | xj        dgz  c_        | xj        ddgz  c_        | xj        t          |                                          z  c_        d S )Ntrame-client-triggers)r!   r8   r8   before_destroybeforeDestroy)before_unmountbeforeUnmount)r   )_ClientTriggers__namer   r   r   rA   listkeys)r    r8   r!   r"   r#   s       r$   r   zClientTriggers.__init__  s    S4SSSFSSSUG#//
 	
 	T&++--000r%   c                 :     | j         j        | j        d|g|R   dS )zt
        Perform the call on the client

        :param method: Key used in the kwargs at construction time
        emitN)rC   rD   r   )r    methodargss      r$   callzClientTriggers.call  s-     	DK?$??????r%   )r   N)r(   r)   r*   r+   r   r   r,   r-   s   @r$   r   r      s]         1 1 1 1 1 1@ @ @ @ @ @ @r%   r   c                   (     e Zd ZdZ	 	 d fd	Z xZS )r   ax  Create a deeply reactive state from state variable name.
    The provided name can not be reactive.
    It needs to be statically defined in Python like in the example blow.

    This component only works with client_type="vue3".

       with DeepReactive(my_nested_var):
          html.Input(v_model=my_nested_var.txt_1)
          html.Input(v_model=my_nested_var.txt_2)
    Nc                      t                      j        d|fd|i| | xj        dgz  c_        d| d| j        d<   d S )Nztrame-deep-reactiver0   zv-slot="{ value: ro   rp   )r   r   r   r@   )r    r0   r!   r"   r#   s       r$   r   zDeepReactive.__init__$  si     	.NNtNvNNN
 	
 $C#B#B#B   r%   )NNr'   r-   s   @r$   r   r     sY        	 	 C C C C C C C C C Cr%   r   c                   $     e Zd ZdZd fd	Z xZS )r   ax  
    LifeCycleMonitor is a debug purpose tool to validate a sub-tree get the proper
    expected life cycle event.

    This component allow to print into the client side console when any of the
    monitored event happen.

    :param name: User specific text to easily identify which component the event
                was coming from.
    :param type: console[type](...) so you can use 'log', 'error', 'info', 'warn'
    :param value: Another value that is printed when an event occur
    :param events: List of events to monitor such as created, beforeMount,
        mounted, beforeUpdate, updated, beforeDestroy, destroyed
    Nc                      t                      j        d|fi | | xj        g dz  c_        | xj        g dz  c_        d S )Nztrame-life-cycle-monitor)r0   typern   events)created)before_mountbeforeMountmounted)before_updatebeforeUpdateupdatedr   	destroyedr~   r   s      r$   r   zLifeCycleMonitor.__init__E  ss    3XHHHHH 
 
 
 	
 	 
 
 
 	
r%   r&   r'   r-   s   @r$   r   r   5  sG         
 
 
 
 
 
 
 
 
 
r%   r   c                   "     e Zd ZdZ fdZ xZS )r   z
    SizeObserver allow to monitor the space available in the UI and bind that
    information onto a state variable.

    :param _name: Name of the state variable to bound the component size to
    c                      t                      j        di | | xj        dgz  c_        d | j        j        |<   | j        j                            |          | _        d S )Ntrame-size-observerr0   )r   )r   r   r   rC   rL   
translatortranslate_keyr0   )r    _namer"   r#   s      r$   r   zSizeObserver.__init__c  sk    99&999
 	
 $(% K*88??			r%   r'   r-   s   @r$   r   r   [  sK         @ @ @ @ @ @ @ @ @r%   r   F)r0   umdumd_global_var_namescript_file_pathfunction_namesr0   r   r   returnc                    t          |          dk    sJ |s t          t          j                              }t	          | ||||          S )ae  
    Register an external script that can be used together with the Handler widget.

    Args:
        script_file_path (Path | str):
            The local of the script you want to register. Can be either a local or a remote script. Accepts:
            - `Path`: local path to your script on the filesystem
            - `str`: an valid URL to the script
        function_names (list[str]): public API of your script that you want to expose to the Handler widget.
            Accepts a list of function names that must be defined in your script.
        name (str): a registration identifier for your script.
            You may use it later to reference your script when instantiating the Handler widget.
        umd (bool, optional): If true, your script is considered as a UMD module and treated as such.
            For ES module, just keep the default value. Defaults to False.
        umd_global_var_name (str | None):
            Specify the global variable name the UMD module will use to register itself on the browser window object.
            Required if and only if `umd` is set to True. Defaults to None.
    r   )r   r0   r   r   )lenstruuiduuid4r
   )r   r   r0   r   r   s        r$   r   r   l  s^    8 ~"""" !4:<<  (%/   r%   c                        e Zd ZdZdddeeeef         z  ez  ez  def fdZe	defd            Z
d	edefd
Z xZS )r   a  
    Facilitates the execution of registered JS functions and external scripts.

    The Handler simplifies calling client-side logic registered via `register_external_script`.
    It manages the execution flow between the Python state and JavaScript functions,
    providing events to monitor execution status.

    Args:
        function (UserDefinedFunction | tuple[str, str] | ExternalScript | str):
            The JavaScript function to execute. Accepts:
            - `UserDefinedFunction`: Obtained from `ExternalScript.function`.
            - `tuple[str, str]`: A `(module_name, function_name)` pair.
            - `ExternalScript`: An object from `register_external_script` (must
              contain exactly one function).
            - `str`: The registration identifier of an external script.
        variable (str): The name of the state variable to be passed as the
            primary input to the function.
        trigger_on_change (bool, optional): If True, the function is automatically
            invoked whenever `variable` changes. Defaults to True.
        inputs (dict, optional): A dictionary of additional key-value pairs
            to be passed as arguments to the function. Defaults to None.

    Events:
        completed: A generic event emitted regardless of the execution outcome.
        success: Emitted when the function executes and returns successfully.
        failure: Emitted when the function reports a handled error.
        error: Emitted when an unhandled exception occurs during execution.
    
input_datavariablefunctionr   c                   dt          |            } t                      j        di |d|i || _        | j        d         s
g | j        d<   t          |t                    r	|j        }|}t          |t                    r0t          |d                   }|
                    |d                   }t          |t                    r|}|
                                }t          |t                    r#t          |          }|
                                }| j        d                             |j        |j        |j        |d           | xj        g dz  c_        | xj        g d	z  c_        d
| j         d| j        d<   d S )Ntrame_external_scripttrame-handlerfunction_keytrame__client_external_scriptsr   r   )module_typepathr   id)trigger_on_changeinputs)r   functionKey)successfailureerror	completedzv-slot:default="{ input_data: z, run }"rp   )r   )r   r   r   r   rL   
isinstancer   scripttupler	   r   r   r   rq   r   module_pathr0   r   rA   r@   )r    r   r   r"   external_script_idexternal_scriptfunction_handler#   s          r$   r   zHandler.__init__  s    @RXX??TTFTTASTTTT z:; 	>;=DJ78h 344 	'&oO&Oh&& 	D;HQKHHO-66x{CCOh// 	9&O-6688Oh$$ 	9;HEEO-6688O
34;;.:'3+0(	 	
 	
 	
 	 
 
 
 	

 	IIII GdmFFF 	   r%   r   c                     | j          dS )zQ
        Get the JS expression that references the handler's input data.
        z.valuer   rV   s    r$   r   zHandler.input_data  s    
 -''''r%   	input_varc                     d| dS )zn
        Return a JS expression that will invoke the handler with the provided input_var as argument.
        zrun() )r    r   s     r$   runzHandler.run  s     #i""""r%   )r(   r)   r*   r+   r   r   r   r   r   rZ   r   r   r,   r-   s   @r$   r   r     s         B %	2
 2
 2
 &c3h7.H3N2
 	2
 2
 2
 2
 2
 2
h (C ( ( ( X(#S #S # # # # # # # #r%   r   )loggingr   pathlibr   corer   external_script_handlerr   r   r	   r
   	getLoggerr(   logger__all__r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   r   r   r%   r$   <module>r      s@           ! ! ! ! ! !            
	8	$	$  (
 
 
 
 
o 
 
 
$
 
 
 
 
_ 
 
 
6; ; ; ; ;_ ; ; ;6    O   2    _   F+K +K +K +K +K_ +K +K +Kb( ( ( ( ( ( ( (6@ @ @ @ @_ @ @ @JC C C C C? C C C: 
  
  
  
  
  
  
  
L@ @ @ @ @? @ @ @* &*' ' 'Sj' I' *	'
 
' t' ' ' ' 'Z]# ]# ]# ]# ]#o ]# ]# ]# ]# ]#r%   