1#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
2pub struct ComponentInvocation {
3 #[serde(skip_serializing_if = "Option::is_none")]
4 pub id: Option<String>,
5 pub name: String,
6 pub properties: Vec<Property>,
7 pub iteration: Box<Option<Loop>>,
8 pub condition: Box<Option<fastn_resolved::Expression>>,
9 pub events: Vec<Event>,
10 pub children: Vec<ComponentInvocation>,
11 pub source: ComponentSource,
12 pub line_number: usize,
13}
14
15impl fastn_resolved::ComponentInvocation {
16 pub fn from_name(name: &str) -> fastn_resolved::ComponentInvocation {
17 fastn_resolved::ComponentInvocation {
18 id: None,
19 name: name.to_string(),
20 properties: vec![],
21 iteration: Box::new(None),
22 condition: Box::new(None),
23 events: vec![],
24 children: vec![],
25 source: Default::default(),
26 line_number: 0,
27 }
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
32pub struct Loop {
33 pub on: fastn_resolved::PropertyValue,
34 pub alias: String,
35 pub loop_counter_alias: Option<String>,
36 pub line_number: usize,
37}
38
39impl Loop {
40 pub fn new(
41 on: fastn_resolved::PropertyValue,
42 alias: &str,
43 loop_counter_alias: Option<String>,
44 line_number: usize,
45 ) -> fastn_resolved::Loop {
46 fastn_resolved::Loop {
47 on,
48 alias: alias.to_string(),
49 line_number,
50 loop_counter_alias,
51 }
52 }
53}
54
55#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize, serde::Serialize)]
56pub enum ComponentSource {
57 #[default]
58 Declaration,
59 Variable,
60}
61
62#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
63pub struct Event {
64 pub name: fastn_resolved::EventName,
65 pub action: fastn_resolved::FunctionCall,
66 pub line_number: usize,
67}
68
69#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
70pub struct Property {
71 pub value: fastn_resolved::PropertyValue,
72 pub source: fastn_resolved::PropertySource,
73 pub condition: Option<fastn_resolved::Expression>,
74 pub line_number: usize,
75}
76
77#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize, serde::Serialize)]
78pub enum PropertySource {
79 #[default]
80 Caption,
81 Body,
82 Header {
83 name: String,
84 mutable: bool,
85 },
86 Subsection,
87 Default,
88}
89
90impl fastn_resolved::PropertySource {
91 pub fn is_equal(&self, other: &fastn_resolved::PropertySource) -> bool {
92 match self {
93 fastn_resolved::PropertySource::Caption
94 | fastn_resolved::PropertySource::Body
95 | fastn_resolved::PropertySource::Subsection
96 | fastn_resolved::PropertySource::Default => self.eq(other),
97 fastn_resolved::PropertySource::Header { name, .. } => {
98 matches!(other, fastn_resolved::PropertySource::Header {
99 name: other_name, ..
100 } if other_name.eq(name))
101 }
102 }
103 }
104
105 pub fn is_default(&self) -> bool {
106 matches!(self, fastn_resolved::PropertySource::Default)
107 }
108}
109
110#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
111pub enum EventName {
112 Click,
113 MouseEnter,
114 MouseLeave,
115 ClickOutside,
116 GlobalKey(Vec<String>),
117 GlobalKeySeq(Vec<String>),
118 Input,
119 Change,
120 Blur,
121 Focus,
122 RivePlay(String),
123 RiveStateChange(String),
124 RivePause(String),
125}
126
127#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
128pub struct ComponentDefinition {
129 pub name: String,
130 pub arguments: Vec<Argument>,
131 pub definition: fastn_resolved::ComponentInvocation,
132 pub css: Option<fastn_resolved::PropertyValue>,
133 pub line_number: usize,
134}
135
136impl fastn_resolved::ComponentDefinition {
137 pub fn new(
138 name: &str,
139 arguments: Vec<fastn_resolved::Argument>,
140 definition: fastn_resolved::ComponentInvocation,
141 css: Option<fastn_resolved::PropertyValue>,
142 line_number: usize,
143 ) -> fastn_resolved::ComponentDefinition {
144 fastn_resolved::ComponentDefinition {
145 name: name.to_string(),
146 arguments,
147 definition,
148 css,
149 line_number,
150 }
151 }
152}
153
154pub type Argument = fastn_resolved::Field;