o
    d}                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZddlmZ ddl	m
Z
 dZdZdZdZd	Zd
ZdZdZdZdZdZdZdd Zdd Zdd Zdd Zdd Z		d4ddZdd Zdd  Zd!d" Zd#d$ Z d%d& Z!d'd( Z"d)d* Z#d5d,d-Z$d.d/ Z%	+d6d0d1Z&d2d3 Z'dS )7    N   )
r_keywords)reorder_propsa  #' @export
{funcname} <- function({default_argtext}{wildcards}) {{
    {wildcard_declaration}
    props <- list({default_paramtext}{wildcards})
    if (length(props) > 0) {{
        props <- props[!vapply(props, is.null, logical(1))]
    }}
    component <- list(
        props = props,
        type = '{name}',
        namespace = '{project_shortname}',
        propNames = c({prop_names}{wildcard_names}),
        package = '{package_name}'
        )

    structure(component, class = c('dash_component', 'list'))
}}
z?.{rpkgname}_js_metadata <- function() {{
deps_metadata <- list(a,  `{dep_name}` = structure(list(name = "{dep_name}",
version = "{project_ver}", src = list(href = NULL,
file = "deps"), meta = NULL,
script = {script_name},
stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}",
all_files = FALSE{async_or_dynamic}), class = "html_dependency")a>  `{project_shortname}` = structure(list(name = "{project_shortname}",
version = "{project_ver}", src = list(href = NULL,
file = "deps"), meta = NULL,
script = {script_name},
stylesheet = {css_name}, head = NULL, attachment = NULL, package = "{rpkgname}",
all_files = FALSE{async_or_dynamic}), class = "html_dependency")z)
return(deps_metadata)
}
z% Auto-generated: do not edit by hand
\name{{{funcname}}}

\alias{{{funcname}}}

\title{{{name} component}}

\description{{
{description}
}}

\usage{{
{funcname}({default_argtext})
}}

\arguments{{
{item_text}
}}

\value{{{value_text}}}

a~  Package: {package_name}
Title: {package_title}
Version: {package_version}
Description: {package_description}
Depends: R (>= 3.0.2){package_depends}
Imports: {package_imports}
Suggests: {package_suggests}{package_rauthors}
License: {package_license}{package_copyright}
URL: {package_url}
BugReports: {package_issues}
Encoding: UTF-8
LazyData: true{vignette_builder}
KeepSource: true
a  # ignore JS config files/folders
node_modules/
coverage/
src/
lib/
.babelrc
.builderrc
.eslintrc
.npmignore
.editorconfig
.eslintignore
.prettierrc
.circleci
.github

# demo folder has special meaning in R
# this should hopefully make it still
# allow for the possibility to make R demos
demo/.*\.js
demo/.*\.html
demo/.*\.css

# ignore Python files/folders
setup.py
usage.py
setup.py
requirements.txt
MANIFEST.in
CHANGELOG.md
test/
# CRAN has weird LICENSE requirements
LICENSE.txt
^.*\.Rproj$
^\.Rproj\.user$
z% Auto-generated: do not edit by hand
\docType{{package}}
\name{{{package_name}-package}}
\alias{{{package_name}}}
\title{{{pkg_help_title}}}
\description{{
{pkg_help_description}
}}
\author{{
\strong{{Maintainer}}: {maintainer}
}}
a+  
dash_assert_valid_wildcards <- function (attrib = list("data", "aria"), ...)
{
    args <- list(...)
    validation_results <- lapply(names(args), function(x) {
        grepl(paste0("^(", paste0(attrib, collapse="|"), ")-[a-zA-Z0-9_-]+$"),
            x)
    })
    if (FALSE %in% validation_results) {
        stop(sprintf("The following props are not valid in this component: '%s'",
            paste(names(args)[grepl(FALSE, unlist(validation_results))],
                collapse = ", ")), call. = FALSE)
    }
    else {
        return(args)
    }
}
zQ
    wildcard_names = names(dash_assert_valid_wildcards(attrib = list({}), ...))
z9


\item{{...}}{{wildcards allowed have the form: `{}`}}
c                 C   s&  t |}t|d}t| }d}d}d}d}	d}
d}tdd |D r5t|}d}t|dd}d}d	d	d |D }|d d  D ]#}|
dsP|d
krV|| qE|tv rh|| td||  qE|
d	dd |D 7 }
|	d	dd |D 7 }	tjt|| | |
|||	||||d
S )Nprops c                 s       | ]}| d V  qdS -*Nendswith.0key r   n/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/dash/development/_r_components_generation.py	<genexpr>       z(generate_class_string.<locals>.<genexpr>, ...r
   z, wildcard_names, c                 s   s*    | ]}d |vr|dvrd |V  qdS )*)setProps'{}'Nformatr   pr   r   r   r      s    
r   zSWARNING: prop "{}" in component "{}" is an R keyword - REMOVED FROM THE R COMPONENTc                 s       | ]}d  |V  qdS z{}=NULLNr   r   r   r   r   r      r   c                 s   s,    | ]}|d krd |nd |V  qdS )childrenz{0}={0}z{}=childrenNr   r   r   r   r   r      s
    
)
funcnamenamedefault_argtext	wildcardswildcard_declarationdefault_paramtextproject_shortname
prop_nameswildcard_namespackage_name)snake_case_to_camel_caser   listkeysanyget_wildcards_rwildcard_templater   replacejoinr   remover   warningswarnr_component_stringformat_fn_name)r!   r   r&   prefixr)   	prop_keysr#   r$   r(   r%   r"   accepted_wildcardsr'   itemr   r   r   generate_class_string   sZ   




r;   c                 C   sv  t jdt  t|}t|dg t|dg  }| d}t	|}t
j|d}g }g }t|dkrtt|D ]F}	||	 }
|
d }t|
}d|v rS|d	d }nd
|}d|v rdd|}d}nd|}d}|tj|||||||dg7 }d|}q9n0t|dkr|d }	|	d }t|	}d|v rd|}d}nd|}d}tj||||||d}d||tg}|S )aC  Dynamically generate R function to supply JavaScript and CSS dependency
    information required by the dash package for R.

    Parameters
    ----------
    project_shortname = component library name, in snake case

    Returns
    -------
    function_string = complete R function code to provide component features
    r   _js_dist	_css_distversion)rpkgnamer   relative_package_pathdash_.{}cssr   NULL)dep_nameproject_verr?   r&   script_namecss_nameasync_or_dynamicz,
)r&   rG   r?   rH   rI   rJ   r   )syspathinsertosgetcwd	importlibimport_modulegetattrgetr*   frame_open_templater   lenrangeget_async_typesplitframe_element_templater1   frame_body_templateframe_close_template)pkg_datar&   modalldistrG   r?   function_frame_openfunction_framefunction_frame_bodydepcurr_deprpprJ   rF   rI   rH   function_stringr   r   r   generate_js_metadata   sn   






	rf   c                 C   sX   d}|   D ]#}|dv r)| | }t|tsd| }nt| }d||}q|S )Nr   )asyncdynamicr   z	, {} = {})r,   
isinstanceboolr   lowerstrupper)rb   rJ   r   keyvalr   r   r   rW   V  s   
rW   c                 C   s   | dkr|S d | |S )Nr   z
\{}{{
{}}}r   )tagcoder   r   r   wrape  s   rq   c                    sF  t ||   d }d}d}d}d}	d}
t }tdd |D r(t|}	d}|dd D ]}|ds=|tv s=|d	krB|| q.|d
dd |D 7 }|dfdd|D 7 }t	
dd|}t	
dd|}d|v rx|dd  }|dkr||7 }|t|	7 }tjd|}t|ddd }|tj | tj|ddd||
|ddd W d   n1 sw   Y  |durd|v r|d} fdd|D pdgd }d}|rd| v r!|td t|d!rd!nd|d 7 }t|d"dd}||d  W d   dS 1 sw   Y  dS dS dS dS dS )#a  Write R documentation file (.Rd) given component name and properties.

    Parameters
    ----------
    name = the name of the Dash component for which a help file is generated
    props = the properties of the component
    description = the component's description, inserted into help file header
    prefix = the DashR library prefix (optional, can be a blank string)
    rpkg_data = package metadata (optional)

    Returns
    -------
    writes an R help file to the man directory for the generated R package
    z.Rdr   zQnamed list of JSON elements corresponding to React.js properties and their valuesc                 s   r   r	   r   r   r   r   r   r     r   z"write_help_file.<locals>.<genexpr>r   Nr
   r   r   c                 s   r   r   r   r   r   r   r   r     r   z

c                 3   s2    | ]}d  |t | d  | d V  qdS )z\item{{{}}}{{{}{}}}typedescriptionN)r   print_r_typer   r   r   r   r     s    
z(?<!\\)%z\%z**Example Usage**r   manwutf-8encoding<   F)widthbreak_long_words
 )r    r!   r"   	item_text
value_textrs   
r_examplesc                    s   g | ]}| d  kr|qS )r!   )rS   )r   e)r    r   r   
<listcomp>  s    z#write_help_file.<locals>.<listcomp>rp   examplesdontrunza+)r6   r+   r,   r-   r.   r   r   r2   r1   resubrX   rstripwildcard_help_templater   rN   rL   openwritehelp_stringtextwrapfillr0   rS   rq   )r!   r   rs   r7   	rpkg_data	file_namer#   r"   r   r9   r   r8   r:   	file_pathfexthe_exresultfar   )r    r   r   write_help_filek  sn   




$r   c                 C   s   t |d}t| |||| d}t| |||}t|| d }tjd|}	t|	ddd}
|
| |
| W d    n1 s@w   Y  t	d
| d S )	Nr   %# AUTO GENERATED FILE - DO NOT EDIT

.RRrv   rw   rx   zGenerated {})r   r   r;   r6   rN   rL   r1   r   r   printr   )r!   r   rs   r&   r7   r   import_stringclass_stringr   r   r   r   r   r   write_class_file  s   

r   c                 C   s$  t | |d}d}tjdstd tjd|}t|ddd}|| |r.|t W d   n1 s8w   Y  tjdrHt	
d td t|D ]=\}}}	|	D ]5}
tj|
d	 }|d
v rhqYtjtjdtj||}tj|st| t	tj||
| qYqRdS )zWrite an internal (not exported) R function to return all JS
    dependencies as required by dash.

    Parameters
    ----------
    project_shortname = hyphenated string, e.g. dash-html-components

    Returns
    -------
    )r\   r&   
internal.Rr   rv   rw   rx   Nz	inst/depsr   )z.pyz.pycz.jsonz
inst/deps/)rf   rN   rL   existsmakedirsr1   r   r   wildcard_helpershutilrmtreewalksplitextrelpathcopy)r\   r&   has_wildcardsre   r   r   r   rel_dirname_	filenamesfilename	extensiontarget_dirnamer   r   r   write_js_metadata  s>   





r   c           $      C   sf  t |}d}	d}
| d}|dur>|dr |d| dd}|dr/|d| dd}|dr=d|dd}	n| dd}| dd}| d	d
}|rbd|d  }tdd|}|rr|d }tdd|}|r|d }tdd|}d| v r| d dd}n	d}tdtj	d d| v r| dd}n	d}tdtj	d | d}|
dd }|
dd dd }|
dd }|ddd }| d| d}d|vrtdtj	d td |dur|drd|dd}
nd |||}
tjd!stjd"s| d#d}n| d#dd$ }tjd!s0td"d! d%}d}|
d|
d }tt|}|rS|D ]
}|d&|7 }qHtjd'rpd(}d)|vrod*|vro|d+7 }|d}nd}tjd,|d- }t| || td.d/d0d1}|| || || W d   n	1 sw   Y  td2d/d0d1}|t W d   n	1 sw   Y  tj|||||
|||||	|||d3} td4d/d0d1}!|!|  W d   n	1 sw   Y  |dur/|dr1tj||d|d||d5}"t|d6d0d1}#|#|" W d   dS 1 s(w   Y  dS dS dS )7zGenerate documents for R package creation.

    Parameters
    ----------
    pkg_data
    rpkg_data
    project_shortname
    export_string
    package_depends
    package_imports
    package_suggests
    has_wildcards

    Returns
    -------
    r   r!   Npkg_help_titlers   pkg_help_descriptionpkg_copyrightz
Copyright: {}r>   z0.0.1r   ,z
(,(?![ ]))bugsurlzGWarning: a URL for bug reports was not provided. Empty string inserted.)filehomepagez@Warning: a homepage URL was not provided. Empty string inserted.authorz <r   r   r~      
maintainer<zError, aborting R package generation: R packages require a properly formatted author field or installation will fail. Please include an email address enclosed within < > brackets in package.json. pkg_authorsz
Authors@R: {}zD
Authors@R: person("{}", "{}", role = c("aut", "cre"), email = "{}")LICENSEzLICENSE.txtlicensez + file LICENSEr   z
import({})
	vignettesz
VignetteBuilder: knitrknitr	rmarkdownz, knitr, rmarkdownru   z-package.Rd	NAMESPACEzw+rw   rx   z.Rbuildignore)r)   package_titlepackage_descriptionpackage_versionpackage_rauthorspackage_dependspackage_importspackage_suggestspackage_licensepackage_copyrightpackage_urlpackage_issuesvignette_builderDESCRIPTION)r)   r   r   lib_namer   rv   )r*   rS   r   striplstripr   r   r   rK   stderrrX   rsplitexitrN   rL   isfilesymlinkfilterrj   r   r1   r   r   r   rbuild_ignore_stringdescription_templatepkghelp_stub)$r\   r   r&   export_stringr   r   r   r   r)   r   r   r   r   r   r   r   r   package_authorpackage_author_namepackage_author_emailpackage_author_fnpackage_author_lnr   r   r   packages_stringrpackage_listrpackager   pkghelp_stub_pathr   f2description_stringf3pkghelpf4r   r   r   generate_rpkg  s   














$r   c                 C   s.   |  d}|d ddd |dd  D  S )Nr   r   r   c                 s   s    | ]}|  V  qd S )N)
capitalize)r   rv   r   r   r   r     s    z+snake_case_to_camel_case.<locals>.<genexpr>r   )rX   r1   )
namestringsr   r   r   r*     s   
$r*   c                 C   s,   | r| t | S t |d  |dd   S )Nr   r   )r*   rk   )r7   r!   r   r   r   r6     s   r6   c	              	   K   sT   t ||}
d}| D ]}tdd |d D rd} nqt||| |
|||| d S )NFc                 s   r   r	   r   r   r   r   r   r     r   z#generate_exports.<locals>.<genexpr>r   T)make_namespace_exportsvaluesr-   r   )r&   
componentsmetadatar\   r   r7   r   r   r   kwargsr   r   component_datar   r   r   generate_exports  s"   
r   c              	      s  d}| D ]}| dst|tvrt|dvr|d |7 }qg }ddg fdd| D  }g }td	D ]}| d
rK||vrK|tjd	|g7 }q6|D ]}t|dddp}|	 }	t
jdd|	t
jd}	|	dddd}	t
dd|	}	t
dd|	}	t|	d }
t|	|
k rt|	}
t
dd|	}	t
dd|	}	t|	|
k st
d|	}|D ]}|d }|d dkr||vr|| qW d    n1 sw   Y  qN|ddd  |D 7 }|S )!Nr   r
   )r   r   zexport({}{})
zutils.Rr   c                    s   g | ]}d   |qS )z{}{}.Rr   )r   	componentr7   r   r   r      s    z*make_namespace_exports.<locals>.<listcomp>r   r   rrw   rx   z#.*$)flagsr}   r~   z'([^'\\]|\\'|\\[^'])*'z''z"([^"\\]|\\"|\\[^"])*"z""r   z\(([^()]|\(\))*\)z()z\{([^{}]|\{\})*\}rC   z6([^A-Za-z0-9._]|^)([A-Za-z0-9._]+)\s*(=|<-)\s*functionr   rB   c                 s   r   )z
export({})Nr   )r   functionr   r   r   r   L  r   z)make_namespace_exports.<locals>.<genexpr>)r   rl   r   r   rN   listdirrL   r1   r   readr   r   Mr0   rU   findallappend)r   r7   r   r   	rfilelistomitlistfnlistscriptrfiler   prev_lenmatchesmatchfnr   r   r   r     s\   


"r   c                    sp    fdd}t dd dd dd dd dd d	d d
d dd  fdd fdd fdd fdd||dS )z8Mapping from the PropTypes js type object to the R type.c                
      s>   d ddd  d D d ddd  d  D S )	Nz lists containing elements {}.
{}r   c                 s   r   )r   Nr   r   tr   r   r   r   U  r   z;get_r_prop_types.<locals>.shape_or_exact.<locals>.<genexpr>valuez+Those elements have the following types:
{}r}   c              	   s   s2    | ]\}}t |||d  |ddddV  qdS )requiredrs   r   r   )	prop_nametype_objectr  rs   
indent_numN)create_prop_docstring_rrS   )r   r  propr   r   r   r   W  s    

)r   r1   itemsr   r  r   r   shape_or_exactS  s   

z(get_r_prop_types.<locals>.shape_or_exactc                   S      dS )Nzunnamed listr   r   r   r   r   <lambda>e      z"get_r_prop_types.<locals>.<lambda>c                   S   r  )Nlogicalr   r   r   r   r   r  f  r  c                   S   r  )Nnumericr   r   r   r   r   r  g  r  c                   S   r  )N	characterr   r   r   r   r   r  h  r  c                   S   r  )Nz
named listr   r   r   r   r   r  i  r  c                   S   r  )Nz9logical | numeric | character | named list | unnamed listr   r   r   r   r   r  j  r  c                   S   r  )Nzdash componentr   r   r   r   r   r  k  r  c                   S   r  )Nz8a list of or a singular dash component, string or numberr   r   r   r   r   r  l  r  c                         d ddd  d D S )Nza value equal to: {}r   c                 s   s"    | ]}d  t|d V  qdS )rC   r  N)r   rl   r  r   r   r   r   o  s     5get_r_prop_types.<locals>.<lambda>.<locals>.<genexpr>r  r   r1   r   r  r   r   r  n  s    c                      r  )NrC   z | c                 s   s*    | ]}t |d krdt |V  qdS )r   rC   N
get_r_typer   )r   subTyper   r   r   r   s  s    

r  r  r   r   r  r   r   r  r  s
    
c                      s,   dt  d dkrdt  d  S d S )Nr+   r  r   z of {}sr!  r   r  r   r   r  z  s   c                      s   d t d S )Nz.list with named elements and values of type {}r  )r   r"  r   r  r   r   r    s    
)arrayrj   numberstringobjectr-   elementnodeenumunionarrayOfobjectOfshapeexact)dict)r  r  r   r  r   get_r_prop_typesP  s"   



	r1  Fc                 C   sP   | d }t | d}d| v r| d s| dddkrdS ||v r&||  }|S dS )aP  
    Convert JS types to R types for the component definition
    Parameters
    ----------
    type_object: dict
        react-docgen-generated prop type dictionary
    is_flow_type: bool
    indent_num: int
        Number of indents to use for the docstring for the prop
    Returns
    -------
    str
        Python type string
    r!   r  computedrr   r   r   )r1  rS   )r  is_flow_typer  js_type_namejs_to_r_types	prop_typer   r   r   r"    s   

r"  c                 C   s   t |  }|r|d7 }|S )Nz. )r"  r   )typedata
typestringr   r   r   rt     s   rt   c                 C   s   t |||d d}d| }d|v r!dj|| |||rddS ddS d	j|| |r,d
|nd|dkr6d|nd|r=ddS ddS )aS  
    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
    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  r3  r  z  r}   z^{indent_spacing}- {name} ({is_required}): {description}. {name} has the following type: {type}r  optional)indent_spacingr!   rr   rs   is_requiredz;{indent_spacing}- {name} ({type}{is_required}){description}z{}; r   z: {}r!  )r  r  r  rs   r  r3  r_type_namer:  r   r   r   r    s4   

r  c                 C   s,   d}|d dd | D 7 }|dkrd}|S )Nr   r   c                 s   s$    | ]}| d rd|V  qdS )r
   r   N)r   r   r   r   r   r   r     s   " z"get_wildcards_r.<locals>.<genexpr>rE   )r1   )r8   r#   r   r   r   r.     s
   r.   )NN)Fr   )F)(rN   rK   r   rP   r   r   r3   _all_keywordsr   _py_components_generationr   r5   rT   rY   rZ   r[   r   r   r   r   r   r/   r   r;   rf   rW   rq   r   r   r   r   r*   r6   r   r   r1  r"  rt   r  r.   r   r   r   r   <module>   sT   $Aba
7 B	$?
=	
2