1use serde::{Deserialize, Serialize};
2use slotmap::new_key_type;
3use indexmap::IndexMap;
4use crate::reactive::Binding;
5
6new_key_type! {
8 pub struct NodeId;
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub enum Value {
14 Static(serde_json::Value),
16 Binding(Binding),
18 TemplateString {
21 template: String,
22 bindings: Vec<Binding>,
23 },
24 Action(String),
26}
27
28pub type Props = IndexMap<String, Value>;
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct Element {
34 pub element_type: String,
36
37 pub props: Props,
39
40 pub children: Vec<Element>,
42
43 pub key: Option<String>,
45
46 }
48
49impl Element {
50 pub fn new(element_type: impl Into<String>) -> Self {
51 Self {
52 element_type: element_type.into(),
53 props: Props::new(),
54 children: Vec::new(),
55 key: None,
56 }
57 }
58
59 pub fn with_prop(mut self, key: impl Into<String>, value: Value) -> Self {
60 self.props.insert(key.into(), value);
61 self
62 }
63
64 pub fn with_child(mut self, child: Element) -> Self {
65 self.children.push(child);
66 self
67 }
68
69 pub fn with_key(mut self, key: impl Into<String>) -> Self {
70 self.key = Some(key.into());
71 self
72 }
73
74 }