
    MfX                         d dl mZ d dl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mZ dd	lmZ 	 	 dd
Z	 	 ddZd Zd Z	 ddZd ZddZd Zd Zd Zd Zd Z	 ddZd Zd Z ddZ!dS )    )OrderedDictN)filldedent)_explicitize_argsNonExistentEventException   )python_keywords)collect_nodesfilter_base_nodes)	Componentc                 <   d}|| |v s|d|v rt                    nt          t                              }t          t                              }t          t	          t          t          |                                                              }	t          | |||          	                    dd          }
t          |          }d|v }d |D             }t                     t	                                                    }dv r d|	v r|                    d           d	}d
}d}nd}d}d}t          |          dk    rd}nd| d}|r|dz  }fd|D             }|r-|dv rdndz
  }t          |          |k    r|d|         }|
dz  }
|d                    |dgz             z  }t          d                                 D                       }t#          |                    | ||||	|
|||||t'          |          dgz                       S )a;  Dynamically generate class strings to have nicely formatted docstrings,
    keyword arguments, and repr.
    Inspired by http://jameso.be/2013/08/06/namedtuple.html
    Parameters
    ----------
    typename
    props
    description
    namespace
    prop_reorder_exceptions
    Returns
    -------
    string
    a  class {typename}(Component):
    """{docstring}"""
    _children_props = {children_props}
    _base_nodes = {base_nodes}
    _namespace = '{namespace}'
    _type = '{typename}'
    @_explicitize_args
    def __init__(self, {default_argtext}):
        self._prop_names = {list_of_valid_keys}
        self._valid_wildcard_attributes =            {list_of_valid_wildcard_attr_prefixes}
        self.available_properties = {list_of_valid_keys}
        self.available_wildcard_properties =            {list_of_valid_wildcard_attr_prefixes}
        _explicit_args = kwargs.pop('_explicit_args')
        _locals = locals()
        _locals.update(kwargs)  # For wildcard attrs and excess named props
        args = {args}
        {required_validation}
        super({typename}, self).__init__({argtext})
NALL)component_namepropsdescriptionprop_reorder_exceptionsz

childrenc                     g | ]
}|d k    |S r    ).0args     i/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/development/_py_components_generation.py
<listcomp>z)generate_class_string.<locals>.<listcomp>Y   s"    GGGSSJ5F5FS5F5F5F    zchildren=None, z:{k: _locals[k] for k in _explicit_args if k != 'children'}zchildren=children, **args z'{k: _locals[k] for k in _explicit_args}z**argsr   z
        for k in z:
            if k not in args:
                raise TypeError(
                    'Required argument `' + k + '` was not specified.')
        z
        if 'children' not in _explicit_args:
            raise TypeError('Required argument children was not specified.')
        c                     g | ]@}|                     d           s)|t          v |dk    &|         d         r|ddn|ddAS )z-*setPropsrequiredsz=Component.REQUIREDz=Component.UNDEFINED)endswithr
   )r   pr   s     r   r   z)generate_class_string.<locals>.<listcomp>y   s~        zz$ %&_$<$<j	 Qx
#.q'''''---- BQr   r	   z

Note: due to the large number of props for this component,
not all of them appear in the constructor signature, but
they may still be used as keyword arguments., z**kwargsc                 &    i | ]\  }}|d k    ||S r   r   )r   kvs      r   
<dictcomp>z)generate_class_string.<locals>.<dictcomp>   s#    MMMDAqQ*__1a___r   )typename	namespacefiltered_props$list_of_valid_wildcard_attr_prefixeslist_of_valid_keys	docstringdefault_argtextargsargtextrequired_validationchildren_props
base_nodes)filter_propsreorder_propsreprparse_wildcardslistmapstrkeyscreate_docstringreplacerequired_propsprohibit_eventsremovelenjoinr   itemsr   formatr   )r*   r   r   r+   r   	max_propscr,   wildcard_prefixesr.   r/   required_argsis_children_required	prop_keysr0   r1   r2   r3   default_arglistfinal_max_propsnodess    `                   r   generate_class_stringrP      s   J	A0 $/H@W4W4W#/E=T4T4T 	U <..//	  _U3344d3sN,?,?,A,A#B#BCCDD  7	  
 gfd  #>22M%6GGMGGGME UZZ\\""IUz-???$$$+K-8
=Q        	
      O  	#J%,?,?qqQG/11-.>.>?O?I tyyJ<!?@@@OMMEKKMMMMMNNE	)1B1+ 3 (//:,> 	 	
 	
  r   c                 J   d}t          | |||||          }| dd}t          j                            ||          }	t	          |	dd          5 }
|
                    |           |
                    |           ddd           n# 1 swxY w Y   t          d|            dS )	zGenerate a Python class file (.py) given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    prop_reorder_exceptions
    Returns
    -------
    zp# AUTO GENERATED FILE - DO NOT EDIT

from dash.development.base_component import Component, _explicitize_args


r"   z.pywutf-8encodingNz
Generated )rP   ospathrD   openwriteprint)r*   r   r   r+   r   rG   import_stringclass_string	file_name	file_pathfs              r   generate_class_filer`      s    (	/  )%i1H) L """"IY	22I	iw	/	/	/ 1		               

"y
"
"#####s   +BB
B
c                 N   t          t          j                            | d          dd          5 }d                    d |D                       }d                    d |D                       }| d	| d
}|                    |           d d d            d S # 1 swxY w Y   d S )Nz_imports_.pyrR   rS   rT   r   c              3   &   K   | ]}d | d| V  dS )zfrom .z import Nr   r   xs     r   	<genexpr>z#generate_imports.<locals>.<genexpr>   s3      %R%R!&=q&=&=!&=&=%R%R%R%R%R%Rr   z,
c              3   "   K   | ]
}d | dV  dS )z    ""Nr   rc   s     r   re   z#generate_imports.<locals>.<genexpr>   s*      ??qlalll??????r   z

__all__ = [
z
])rX   rV   rW   rD   rY   )project_shortname
componentsr_   component_importsall_listimports_strings         r   generate_importsrm      s    	
&77w
 
 
  	
 II%R%Rz%R%R%RRR::??J?????-MMMMM	                                   s   ABB!Bc                    g }|                                 D ]m\  }}|                    d          d                             d          d         }|                    |           |D ]} |||d         |d         |            n|S )N/.r   r   r   )rE   splitappend)rh   metadatacomponent_generatorsri   component_pathcomponent_datar   	generators           r   generate_classes_filesry      s    J*2..*:*: 
 
&'--c2226<<SAA!D.)))- 	 	IIw'}-!	   	 r   c                 z    t          | ||||          }t          t          d}t          ||           ||          }|S )zGenerate a Python class object given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    )r   r   )rP   r   r   exec)r*   r   r   r+   r   stringscoperesults           r   generate_classr      sM     #%i1H F $:KLLE8_FMr   c                 X    d t          |                                           D             S )zPull names of required props from the props object.
    Parameters
    ----------
    props: dict
    Returns
    -------
    list
        List of prop names (str) that are required for the Component
    c                 (    g | ]\  }}|d          |S )r!   r   )r   	prop_nameprops      r   r   z"required_props.<locals>.<listcomp>  s&    UUU/)TDDTUIUUUr   )r:   rE   r   s    r   r@   r@      s)     VUT%++---@-@UUUUr   c                    || |v s|d|v r|nt          |          }| d                                         dv rdnd}d                    d t          |                                          D                       }d	| d
|  d| d| S )a5  Create the Dash component docstring.
    Parameters
    ----------
    component_name: str
        Component name
    props: dict
        Dictionary with {propName: propMetadata} structure
    description: str
        Component description
    Returns
    -------
    str
        Dash component docstring
    Nr   r   aeiounr   r   c              3      K   | ]T\  }}t          |d |v r|d          n|d         |d         |d         |                    d          dd|v od |v          V  UdS )typeflowTyper!   r   defaultValuer   r   type_objectr!   r   default
indent_numis_flow_typeNcreate_prop_docstringget)r   r$   r   s      r   re   z#create_docstring.<locals>.<genexpr>$  s         At 	(.$VD<L*%]+HH^,,#t+Bd0B	
 	
 	
     r   A z component.
z

Keyword arguments:
)r7   lowerrD   r6   rE   )r   r   r   r   r   r1   s         r   r>   r>   	  s    & $/"999#/E=T4T4T 	 5!! 
 a &&((G33A99   $E**0022    D 	YAXXXX[XXRVXXr   c                 4    d| v sd| v rt          d          dS )zEvents have been removed. Raise an error if we see dashEvents or
    fireEvents.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Raises
    -------
    ?
    
dashEvents
fireEventsziEvents are no longer supported by dash. Use properties instead, eg `n_clicks` instead of a `click` event.Nr   r   s    r   rA   rA   6  s8     u 5 5'8
 
 	
 !6 5r   c                 V    g }dD ]#}|| v r|                     |dd                    $|S )zPull out the wildcard attributes from the Component props.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    list
        List of Dash valid wildcard prefixes
    )zdata-*zaria-*Nrp   )rs   )r   r-   wildcard_attrs      r   r9   r9   H  sJ     ,.(- L LE!!077crc8JKKK//r   c           	          d| v rdgng }d| v rdgng }t          ||z   t          t          |                                                     z             S )aV  If "children" is in props, then move it to the front to respect dash
    convention, then 'id', then the remaining props sorted by prop name
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Dictionary with {propName: propMetadata} structure
    r   )r   r   id)r   r   )r   sortedr:   rE   )r   props1props2s      r   r7   r7   Z  s^      $.#6#6BF!U]]j\\FvU[[]]0C0C)D)DDEEEr   c                    t          j        |           }t          |                                          D ]\  }}d|vrd|vr|                    |           #d|v r(|d         d         }|dv r|                    |           Od|v rF|d         d         }|dk    r1d|d         vs|d         d         dk    r|                    |           t
          |S )a  Filter props from the Component arguments to exclude:
        - Those without a "type" or a "flowType" field
        - Those with arg.type.name in {'func', 'symbol', 'instanceOf'}
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Filtered dictionary with {propName: propMetadata} structure
    Examples
    --------
    ```python
    prop_args = {
        'prop1': {
            'type': {'name': 'bool'},
            'required': False,
            'description': 'A description',
            'flowType': {},
            'defaultValue': {'value': 'false', 'computed': False},
        },
        'prop2': {'description': 'A prop without a type'},
        'prop3': {
            'type': {'name': 'func'},
            'description': 'A function prop',
        },
    }
    # filtered_prop_args is now
    # {
    #    'prop1': {
    #        'type': {'name': 'bool'},
    #        'required': False,
    #        'description': 'A description',
    #        'flowType': {},
    #        'defaultValue': {'value': 'false', 'computed': False},
    #    },
    # }
    filtered_prop_args = filter_props(prop_args)
    ```
    r   r   name>   funcsymbol
instanceOf	signatureobject)copydeepcopyr:   rE   pop
ValueError)r   r,   arg_namer   arg_typearg_type_names         r   r6   r6   o  s
   T ]5))Nn224455  #3!6!6x((( S==6{6*H;;;""8,,,3
OF3M++ Z00C
OF4Kx4W4W"&&x000r   c                 r    dddd}|                                 D ]\  }}|                     ||          } | S )zM
    replaces javascript keywords true, false, null with Python keywords
    TrueFalseNone)truefalsenull)rE   r?   )txtfix_word
js_keywordpython_keywords       r   fix_keywordsr     sK     &AAH&.nn&6&6 6 6"
Nkk*n55Jr   Fc                    t          |||          }d|z  }|r|d         nd}t          |          }d}	|rd}	n|r|dvrd|                    d	d          z   }	|rd
nd}
|                                                    d
                              dd          |
z   }|dz   }t	          |||dd          }|rd	| nd}|rdnd}t          |          }d	|v r|                    d          rdnd}|                    d          \  }}}d|  d| | }t	          |||dd          }d|v r8|                    dd          \  }}d                    |d|g          }| d| }|	                    d	          
                    d          }|t          |          k    r1d                    d |                                D                       }d	| d|  d| d |	 d!| | d"| | S |r| d nd}d	| d|  d| |	 d!| | 
S )#a  Create the Dash component prop docstring.
    Parameters
    ----------
    prop_name: str
        Name of the Dash component prop
    type_object: dict
        react-docgen-generated prop type dictionary
    required: bool
        Component is required?
    description: str
        Dash component description
    default: dict
        Either None if a default value is not defined, or
        dict containing the key 'value' that defines a
        default value for the prop
    indent_num: int
        Number of indents to use for the context block
        (creates 2 spaces for every indent)
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    Returns
    -------
    str
        Dash component prop docstring
    )r   r   r   z  valuer   optionalr!   )r   z{}z[]zdefault r   rq   rg   z\"z    F)initial_indentsubsequent_indentbreak_long_wordsbreak_on_hyphens:r:   zlist of dictsdictz
with keys:`z` is a z| dict with keys:z |r	   Orz

  -c              3   ,   K   | ]}|d k    d|z   V  dS )r   z

    Nr   )r   lines     r   re   z(create_prop_docstring.<locals>.<genexpr>  s5       ! !&*QS
T!! !r   z- z (z; )z

)js_to_py_typer   r?   stripr   
startswith	partitionrr   rD   lstripfindrC   
splitlines)r   r   r!   r   r   r   r   py_type_nameindent_spacingis_requiredperioddesc_indentcolondict_or_listintro1intro2
dict_descrintro
dict_part1
dict_part2current_indenttns                         r   r   r     s"   D !lz  L J&N")1ggrG7##GK = 	 =W$888 7??4#<#<<  'SSRF##%%++C0088eDDvMK 6)K"%  K )4;${$$$K&CCBE{++K|*6*A*A&*I*IUv &2%;%;L%I%I"
6I66f6f66&)""
 
 
 *,,%/%5%5dA%>%>"J
+tZ!@AAJ&::j::J $**40055c::S0000 ! !.8.C.C.E.E! ! !  J
' ' '9 ' ' ' ' ' 'e '' ''$' '	

 !-	4L				"BUUU)UUrU;UUUUUUr   c                       fd} fd} fd}t          d d d d d d	 d
 d  fd fd| fd|||          S )z=Mapping from the PropTypes js type object to the Python type.c            
          dd                      fdt          t          d                                                             D                       z   S )Ndict with keys:
r   c           
   3      K   | ]L\  }}t          |||d          |                    dd          |                    d          dz             V  MdS )r!   r   r   r      )r   r   r!   r   r   r   Nr   )r   r   r   r   s      r   re   zHmap_js_to_py_types_prop_types.<locals>.shape_or_exact.<locals>.<genexpr>'  s       
/
 
/
  	4 "# j) HH]B7700%>  
/
 
/
 
/
 
/
 
/
 
/
r   r   )rD   r   r:   rE   r   r   s   r   shape_or_exactz5map_js_to_py_types_prop_types.<locals>.shape_or_exact&  si    "TYY 
/
 
/
 
/
 
/
 $*${7/C/I/I/K/K*L*L#M#M
/
 
/
 
/
 
&
 
&
 

 
	
r   c                      t          d                   } | r>d|                     d          d         dk    r| dz   n|                     ddd          z   S d	S )
Nr   list of r   r   r   r"   dictsr	   r:   )r   rr   r?   )innerr   s    r   array_ofz/map_js_to_py_types_prop_types.<locals>.array_of3  sk    k'233 	;;s##A&&00 ]]67A66 
 vr   c                  z    d d         D             } dt          |            dd                    |            dS )Nc                 ,    g | ]}t          |          S r   r   )r   elements     r   r   zCmap_js_to_py_types_prop_types.<locals>.tuple_of.<locals>.<listcomp>>  s     RRRwM'**RRRr   elementsr   z elements: [r%   ])rC   rD   )r   r   s    r   tuple_ofz/map_js_to_py_types_prop_types.<locals>.tuple_of=  sF    RR+j:QRRRK#h--KKTYYx5H5HKKKKr   c                      dS Nr:   r   r   r   r   <lambda>z/map_js_to_py_types_prop_types.<locals>.<lambda>B      f r   c                      dS Nbooleanr   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>C  s    Y r   c                      dS Nnumberr   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>D      x r   c                      dS Nr|   r   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>E  r   r   c                      dS Nr   r   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>F      v r   c                      dS )Nz'boolean | number | string | dict | listr   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>G  s    = r   c                      dS Nzdash componentr   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>H      ( r   c                      dS Nz8a list of or a singular dash component, string or numberr   r   r   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>I      O r   c                  T    dd                     d  d         D                       z   S )Nza value equal to: r%   c              3   @   K   | ]}t          |d                    V  dS )r   N)r<   )r   ts     r   re   zBmap_js_to_py_types_prop_types.<locals>.<lambda>.<locals>.<genexpr>M  s,      FFAAgJFFFFFFr   r   rD   r   s   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>K  s4     iiFFW1EFFFFFG r   c                  N    d                     d  d         D                       S )N | c              3   Z   K   | ]&}t          |          d k    t          |          V  'dS r   Nr   r   subTypes     r   re   zBmap_js_to_py_types_prop_types.<locals>.<lambda>.<locals>.<genexpr>P  I       !
 !
W%%++ '""++++!
 !
r   r   r  r  s   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>P  s6    ejj !
 !
&w/!
 !
 !
 
 
 r   c                  4    dt           d                   z   S )Nz-dict with strings as keys and values of type r   r   r  s   r   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>X  s     ;K0112 r   )arrayboolr   r|   r   anyr   nodeenumunionarrayOfobjectOfshapeexacttupler   )r   r   r   r   r   s   ``   r   map_js_to_py_types_prop_typesr#  #  s    
 
 
 
 
 
    L L L L L n~==((OO
 
 
 


 
 
 
 
 
 
 

 ?       r   c                 Z     t          d d d d d d d d  fd	 fd
 fd          S )z2Mapping from the Flow js types to the Python type.c                      dS r   r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>g  r   r   c                      dS r   r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>h  s    	 r   c                      dS r   r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>i  r   r   c                      dS r   r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>j  r   r   c                      dS r  r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>k  r  r   c                      dS )Nz!bool | number | str | dict | listr   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>l  s    7 r   c                      dS r  r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>m  r  r   c                      dS r  r   r   r   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>n  r	  r   c                  N    d                     d  d         D                       S )Nr  c              3   Z   K   | ]&}t          |          d k    t          |          V  'dS r  r   r  s     r   re   zBmap_js_to_py_types_flow_types.<locals>.<lambda>.<locals>.<genexpr>p  r  r   r   r  r  s   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>p  s6    ejj !
 !
&z2!
 !
 !
 
 
 r   c                      dt           d         d                   dk    rdt           d         d                    dndz   S )Nr:   r   r   r   z of r"   r   r  s   r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>v  sT    f [4Q788B>> @=Z!8!;<<????	
 r   c                 f     dd                      fdd         d         D                       z   S )Nr   r   c           
   3      K   | ]b}t          |d          |d         |d         d         |d                             dd          |                    d          dz   d          V  cd	S )
keyr   r!   r   r   r   r   Tr   Nr   )r   r   r   s     r   re   zBmap_js_to_py_types_flow_types.<locals>.<lambda>.<locals>.<genexpr>  s          &"5k $W!']:6 $W 1 1- D D HH^44)A~!%       r   r   
propertiesr  r   s   `r   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>}  sT    ii     (4\B     r   )r  r   r   r|   Objectr  ElementNoder  Arrayr   r"  r  s   `r   map_js_to_py_types_flow_typesr8  d  s    n!!~77((OO
 
 
 

 
 
 

 
 
 
/& & & &r   c                    | d         }|rt          |           nt          | |          }d| v r| d         s|                     dd          dk    rdS ||v r'|dk    r ||         |          S  ||                     S dS )	a  Convert JS types to Python types for the component definition.
    Parameters
    ----------
    type_object: dict
        react-docgen-generated prop type dictionary
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    indent_num: int
        Number of indents to use for the docstring for the prop
    Returns
    -------
    str
        Python type string
    r   r  )r   r   computedr   r   functionr   )r8  r#  r   )r   r   r   js_type_namejs_to_py_typess        r   r   r     s      v&L 	
%+>>>>*#

 
 
  	k!!
# 	"??62&&*44r~%%;&&/>,/
;;;+~l+---2r   )NN)N)F)Fr   )"collectionsr   r   rV   textwrapr   r   dash.development.base_componentr   dash.exceptionsr   _all_keywordsr
   _collect_nodesr   r   base_componentr   rP   r`   rm   ry   r   r@   r>   rA   r9   r7   r6   r   r   r#  r8  r   r   r   r   <module>rE     s   # # # # # #  				 ! ! ! ! ! ! ! ! = = = = = = 5 5 5 5 5 5 * * * * * * < < < < < < < < % % % % % % !R R R Rt !#$ #$ #$ #$L       $ FJ   .
V 
V 
V* * * *Z
 
 
$0 0 0$F F F*A A AH  & aV aV aV aVH> > >B( ( (V$ $ $ $ $ $r   