1
1
to_dash (t:: Any ) = t
2
2
3
- struct Component
3
+ struct Component
4
4
name :: String
5
5
type :: String
6
6
namespace :: String
@@ -9,9 +9,9 @@ struct Component
9
9
wildcard_regex :: Union{Nothing, Regex}
10
10
function Component (name:: String , type:: String , namespace:: String ,
11
11
props:: Vector{Symbol} , wildcard_props:: Vector{Symbol} ; kwargs... )
12
-
12
+
13
13
available_props = Set {Symbol} (props)
14
- wildcard_regex:: Union{Nothing, Regex} = nothing
14
+ wildcard_regex:: Union{Nothing, Regex} = nothing
15
15
if ! isempty (wildcard_props)
16
16
wildcard_regex = Regex (join (string .(wildcard_props), " |" ))
17
17
end
@@ -30,13 +30,36 @@ get_available_props(comp::Component) = getfield(comp, :available_props)
30
30
get_wildcard_regex (comp:: Component ) = getfield (comp, :wildcard_regex )
31
31
get_props (comp:: Component ) = getfield (comp, :props )
32
32
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 )
34
57
! Base. hasproperty (comp, prop) && error (" Component $(get_name (comp)) has no property $(prop) " )
35
58
props = get_props (comp)
36
59
return haskey (props, prop) ? props[prop] : nothing
37
60
end
38
61
39
- function Base. setproperty! (comp:: Component , prop:: Symbol , value)
62
+ function Base. setproperty! (comp:: Component , prop:: Symbol , value)
40
63
! Base. hasproperty (comp, prop) && error (" Component $(get_name (comp)) has no property $(prop) " )
41
64
props = get_props (comp)
42
65
push! (props, prop=> to_dash (value))
@@ -56,4 +79,4 @@ Base.propertynames(comp::Component) = collect(get_available_props(comp))
56
79
push_prop! (component:: Component , prop:: Symbol , value) = push! (component. props, prop=> to_dash (value))
57
80
58
81
JSON3. 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