11to_dash (t:: Any ) = t
22
3- struct Component
3+ struct Component
44 name :: String
55 type :: String
66 namespace :: String
@@ -9,9 +9,9 @@ struct Component
99 wildcard_regex :: Union{Nothing, Regex}
1010 function Component (name:: String , type:: String , namespace:: String ,
1111 props:: Vector{Symbol} , wildcard_props:: Vector{Symbol} ; kwargs... )
12-
12+
1313 available_props = Set {Symbol} (props)
14- wildcard_regex:: Union{Nothing, Regex} = nothing
14+ wildcard_regex:: Union{Nothing, Regex} = nothing
1515 if ! isempty (wildcard_props)
1616 wildcard_regex = Regex (join (string .(wildcard_props), " |" ))
1717 end
@@ -30,13 +30,36 @@ get_available_props(comp::Component) = getfield(comp, :available_props)
3030get_wildcard_regex (comp:: Component ) = getfield (comp, :wildcard_regex )
3131get_props (comp:: Component ) = getfield (comp, :props )
3232
33- function Base. getproperty (comp:: Component , prop:: Symbol )
33+ const VecChildTypes = Union{NTuple{N, Component} where {N}, Vector{<: Component }}
34+
35+ function Base. getindex (component:: Component , id:: AbstractString )
36+ component. id == id && return component
37+ hasproperty (component, :children ) || return nothing
38+ cc = component. children
39+ return if cc isa Union{VecChildTypes, DashBase. Component}
40+ cc[id]
41+ elseif cc isa AbstractVector
42+ fcc = identity .(filter (x-> hasproperty (x, :id ), cc))
43+ isempty (fcc) ? nothing : fcc[id]
44+ else
45+ nothing
46+ end
47+ end
48+ function Base. getindex (children:: VecChildTypes , id:: AbstractString )
49+ for element in children
50+ element. id == id && return element
51+ el = element[id]
52+ el != = nothing && return el
53+ end
54+ end
55+
56+ function Base. getproperty (comp:: Component , prop:: Symbol )
3457 ! Base. hasproperty (comp, prop) && error (" Component $(get_name (comp)) has no property $(prop) " )
3558 props = get_props (comp)
3659 return haskey (props, prop) ? props[prop] : nothing
3760end
3861
39- function Base. setproperty! (comp:: Component , prop:: Symbol , value)
62+ function Base. setproperty! (comp:: Component , prop:: Symbol , value)
4063 ! Base. hasproperty (comp, prop) && error (" Component $(get_name (comp)) has no property $(prop) " )
4164 props = get_props (comp)
4265 push! (props, prop=> to_dash (value))
@@ -56,4 +79,4 @@ Base.propertynames(comp::Component) = collect(get_available_props(comp))
5679push_prop! (component:: Component , prop:: Symbol , value) = push! (component. props, prop=> to_dash (value))
5780
5881JSON3. StructTypes. StructType (:: Type{DashBase.Component} ) = JSON3. StructTypes. Struct ()
59- JSON3. StructTypes. excludes (:: Type{DashBase.Component} ) = (:name , :available_props , :wildcard_regex )
82+ JSON3. StructTypes. excludes (:: Type{DashBase.Component} ) = (:name , :available_props , :wildcard_regex )
0 commit comments