@@ -12,6 +12,23 @@ use crate::vdom::Mailbox; // todo temp
12
12
13
13
//use regex::Regex;
14
14
15
+ /// Common Namespaces
16
+ #[ derive( Debug , Clone , PartialEq ) ]
17
+ pub enum Namespace {
18
+ /// SVG Namespace
19
+ Svg ,
20
+ Custom ( String )
21
+ }
22
+
23
+ impl Namespace {
24
+ pub fn as_str ( & self ) -> & str {
25
+ use self :: Namespace :: * ;
26
+ match self {
27
+ Svg => "http://www.w3.org/2000/svg" ,
28
+ Custom ( s) => s
29
+ }
30
+ }
31
+ }
15
32
16
33
// todo cleanup enums vs &strs for restricting events/styles/attrs to
17
34
// todo valid ones.
@@ -520,12 +537,14 @@ make_tags! {
520
537
521
538
Details => "details" , Dialog => "dialog" , Menu => "menu" , MenuItem => "menuitem" , Summary => "summary" ,
522
539
523
- Content => "content" , Element => "element" , Shadow => "shadow" , Slot => "slot" , Template => "template"
540
+ Content => "content" , Element => "element" , Shadow => "shadow" , Slot => "slot" , Template => "template" ,
541
+
542
+ Svg => "svg" , Line => "line" , Rect => "rect" , Circle => "circle"
524
543
}
525
544
526
545
/// An component in our virtual DOM.
527
546
pub struct El < Ms : Clone + ' static > {
528
- // M sis a message type, as in part of TEA.
547
+ // Ms is a message type, as in part of TEA.
529
548
// We call this 'El' instead of 'Element' for brevity, and to prevent
530
549
// confusion with web_sys::Element.
531
550
@@ -536,6 +555,7 @@ pub struct El<Ms: Clone + 'static> {
536
555
pub listeners : Vec < Listener < Ms > > ,
537
556
pub text : Option < String > ,
538
557
pub children : Vec < El < Ms > > ,
558
+ pub namespace : Option < Namespace > ,
539
559
540
560
// Things that get filled in later, to assist with rendering.
541
561
pub id : Option < u32 > ,
@@ -550,16 +570,17 @@ pub struct El<Ms: Clone + 'static> {
550
570
551
571
impl < Ms : Clone + ' static > El < Ms > {
552
572
pub fn new ( tag : Tag , attrs : Attrs , style : Style ,
553
- listeners : Vec < Listener < Ms > > , text : & str , children : Vec < El < Ms > > ) -> Self {
573
+ listeners : Vec < Listener < Ms > > , text : & str , children : Vec < El < Ms > > , namespace : Option < Namespace > ) -> Self {
554
574
Self { tag, attrs, style, text : Some ( text. into ( ) ) , children,
555
- el_ws : None , listeners, id : None , nest_level : None , raw_html : false }
575
+ el_ws : None , listeners, id : None , nest_level : None , raw_html : false , namespace
576
+ }
556
577
}
557
578
558
579
/// Create an empty element, specifying only the tag
559
580
pub fn empty ( tag : Tag ) -> Self {
560
581
Self { tag, attrs : Attrs :: empty ( ) , style : Style :: empty ( ) ,
561
582
text : None , children : Vec :: new ( ) , el_ws : None ,
562
- listeners : Vec :: new ( ) , id : None , nest_level : None , raw_html : false }
583
+ listeners : Vec :: new ( ) , id : None , nest_level : None , raw_html : false , namespace : None }
563
584
}
564
585
565
586
/// Create an element that will display markdown from the text you pass to it, as HTML
@@ -651,6 +672,7 @@ impl<Ms: Clone + 'static> El<Ms> {
651
672
nest_level : None ,
652
673
el_ws : self . el_ws . clone ( ) ,
653
674
raw_html : self . raw_html ,
675
+ namespace : self . namespace . clone ( ) ,
654
676
}
655
677
}
656
678
@@ -682,6 +704,7 @@ impl<Ms: Clone + 'static> Clone for El<Ms> {
682
704
el_ws : self . el_ws . clone ( ) ,
683
705
listeners : Vec :: new ( ) ,
684
706
raw_html : self . raw_html ,
707
+ namespace : self . namespace . clone ( ) ,
685
708
}
686
709
}
687
710
}
0 commit comments