
    -e!                       d Z ddlmZ ddlZ ej        e          ZddlZddlm	Z	m
Z ddlmZmZ ddlm
Z
mZmZmZ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m Z  ddl!m"Z" e	rddl#m$Z$ dZ%e 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S )z Client-side interactivity.

    )annotationsN)TYPE_CHECKINGAny   )HasPropsabstract)	r   AnyRefAutoBoolDictEitherInstanceRequiredString)Init)	Intrinsic)error)INVALID_PROPERTY_VALUENOT_A_PROPERTY_OF)Model)PathLike)CallbackOpenURLCustomJSSetValuec                  $     e Zd ZdZd fdZ xZS )r   z+ Base class for interactive callback.

    returnNonec                :     t                      j        |i | d S Nsuper__init__selfargskwargs	__class__s      6lib/python3.11/site-packages/bokeh/models/callbacks.pyr#   zCallback.__init__G   %    $)&)))))    r   r   __name__
__module____qualname____doc__r#   __classcell__r(   s   @r)   r   r   @   sG         
* * * * * * * * * *r+   r   c                  X     e Zd ZdZd
 fdZ edd          Z edd	          Z xZ	S )r   z4 Open a URL in a new or current tab or window.

    r   r   c                :     t                      j        |i | d S r    r!   r$   s      r)   r#   zOpenURL.__init__P   r*   r+   zhttp://z
    The URL to direct the web browser to. This can be a template string,
    which will be formatted with data from the data source.
    helpFz
    Open URL in a new (`False`, default) or current (`True`) tab or window.
    For `same_tab=False`, whether tab or window will be opened is browser
    dependent.
    r,   )
r.   r/   r0   r1   r#   r   urlr   same_tabr2   r3   s   @r)   r   r   J   sy         
* * * * * * & " 	 	 	C
 tE ! 	 	 	HHHHHr+   r   c                  $     e Zd ZdZd fdZ xZS )
CustomCode r   r   c                :     t                      j        |i | d S r    r!   r$   s      r)   r#   zCustomCode.__init__b   r*   r+   r,   r-   r3   s   @r)   r;   r;   ^   sB        G* * * * * * * * * *r+   r;   c                       e Zd ZdZd fdZ  eee          i d          Z  e	e          d          Z
 eeed	d
          Zedd            Z xZS )r   aU   Execute a JavaScript function.

    .. warning::
        The explicit purpose of this Bokeh Model is to embed *raw JavaScript
        code* for a browser to execute. If any part of the code is derived
        from untrusted user inputs, then you must take appropriate care to
        sanitize the user input prior to passing to Bokeh.

    r   r   c                :     t                      j        |i | d S r    r!   r$   s      r)   r#   zCustomJS.__init__q   r*   r+   z
    A mapping of names to Python objects. In particular those can be bokeh's models.
    These objects are made available to the callback's code snippet as the values of
    named parameters to the callback.
    )defaultr7   a  
    A snippet of JavaScript code to execute in the browser.

    This can be interpreted either as a JavaScript function or a module, depending
    on the ``module`` property:

    1. A JS function.

    The code is made into the body of a function, and all of of the named objects in
    ``args`` are available as parameters that the code can use. Additionally,
    a ``cb_obj`` parameter contains the object that triggered the callback
    an optional ``cb_data`` parameter that contains any tool-specific data
    (i.e. mouse coordinates and hovered glyph indices for the ``HoverTool``)
    and additional document context in ``cb_context`` argument.

    2. An ES module.

    A JavaScript module (ESM) exporting a default function with the following
    signature:

    .. code-block: javascript

        export default function(args, obj, data, context) {
            // program logic
        }

    where ``args`` is a key-value mapping of user-provided parameters, ``obj``
    refers to the object that triggered the callback, ``data`` is a key-value
    mapping of optional parameters provided by the caller, and ``context`` is
    an additional document context.

    The additional document context is composed of the following members:

    * ``index``: The view manager governing all views in the current
      instance of ``Bokeh``. If only one instance of ``Bokeh`` is
      loaded, then this is equivalent to using ``Bokeh.index``.

    This function can be an asynchronous function (``async function () {}`` or
    ``async () => {}``) if for example external resources are needed, which
    would require usage of one of the asynchronous Web APIs, for example:

    .. code-block: javascript

        const response = await fetch("/assets/data.csv")
        const data = await response.text()

    r6   autoz
    Whether to interpret the code as a JS function or ES module. If set to
    ``"auto"``, the this will be inferred from the code.
    pathr   r&   anyc                $   t          j        |          }|j        dk    rd}n |j        dk    rd}nt          d|           t	          |d          5 }|                                }ddd           n# 1 swxY w Y   t          |||	          S )
a  
        Construct a ``CustomJS`` instance from a ``*.js`` or ``*.mjs`` file.

        For example, if we want to construct a ``CustomJS`` instance from
        a JavaScript module ``my_module.mjs``, that takes a single argument
        ``source``, then we would use:

        .. code-block: python

            from bokeh.models import ColumnDataSource, CustomJS
            source = ColumnDataSource(data=dict(x=[1, 2, 3]))
            CustomJS.from_file("./my_module.mjs", source=source)

        z.jsFz.mjsTz#expected a *.js or *.mjs file, got zutf-8)encodingN)coder&   module)pathlibPathsuffixRuntimeErroropenreadr   )clsrB   r&   rG   filerF   s         r)   	from_filezCustomJS.from_file   s      |D!!;%FF[F""FFKTKKLLL$))) 	T99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 TV<<<<s   A55A9<A9r,   )rB   r   r&   rC   r   r   )r.   r/   r0   r1   r#   r   r   r	   r&   r   rF   r   r
   r   rG   classmethodrP   r2   r3   s   @r)   r   r   e   s         * * * * * *  44 2 	 	 	D 88F ." .	 .	 .	D` VD$ 6 	 	 	F
 = = = [= = = = =r+   r   c                       e Zd ZU dZeeefd fd
Z e ee          d          Z	de
d<    eed          Zde
d<    eed          Z ee          d             Z ee          d             Z xZS )r   z+ Allows to update a property of an object. objInit[HasProps]attr	Init[str]value	Init[any]r   r   c                B     t                      j        d|||d| d S )N)rS   rU   rW    r!   )r%   rS   rU   rW   r'   r(   s        r)   r#   zSetValue.__init__   s/    CSt5CCFCCCCCr+   z%
    Object to set the value on.
    r6   r   z!
    The property to modify.
    strz
    The value to set.
    c                j    | j                             | j        d          rd S | j         d| j          S )NF)raisesz is not a property of )rS   lookuprU   )r%   s    r)   /_check_if_an_attribute_is_a_property_of_a_modelz8SetValue._check_if_an_attribute_is_a_property_of_a_model   s<    8??49U?33 	B4iAAtxAAAr+   c                    | j                             | j                  }|j                            | j                  rd S | j        d| j          d| j         S )Nz is not a valid value for .)rS   r^   rU   propertyis_validrW   )r%   
descriptors     r)    _check_if_provided_a_valid_valuez)SetValue._check_if_provided_a_valid_value   sZ    X__TY//
''
33 	U4jTTdhTTTTTr+   )rS   rT   rU   rV   rW   rX   r   r   )r.   r/   r0   r1   r   r#   r   r   r   rS   __annotations__r   rU   r   rW   r   r   r_   r   re   r2   r3   s   @r)   r   r      sB        55 .7)hq D D D D D D D HXXh// 7 	 	 	C 	 	 	 	  ' 	 	 	D 	 	 	 	 HS   	 	 	E UB B B U!""U U #"U U U U Ur+   r   )+r1   
__future__r   logging	getLoggerr.   logrH   typingr   r   rC   core.has_propsr   r   core.propertiesr	   r
   r   r   r   r   r   r   core.property.basesr   core.property.singletonsr   core.validationr   core.validation.errorsr   r   modelr   
core.typesr   __all__r   r   r;   r   r   rZ   r+   r)   <module>ru      sg    # " " " " " g!!  , , , , , , , , 0 / / / / / / /
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ' & & & & & 0 0 0 0 0 0 # # # # # # N N N N N N N N       &%%%%%% 
* * * * *u * * 
*	 	 	 	 	h 	 	 	(* * * * * * * *f= f= f= f= f=z f= f= f=P!U !U !U !U !Ux !U !U !U !U !Ur+   