euv_core/vdom/struct.rs
1use crate::*;
2
3/// Represents a CSS style property.
4///
5/// A single key-value pair representing a CSS declaration.
6#[derive(Data, Default, New)]
7pub struct StyleProperty {
8 /// The CSS property name (e.g., "margin", "padding").
9 #[get(pub)]
10 #[set(pub)]
11 name: String,
12 /// The CSS property value.
13 #[get(pub)]
14 #[set(pub)]
15 value: String,
16}
17
18/// A collection of CSS style properties that can be converted to a style string.
19#[derive(Data, New)]
20pub struct Style {
21 /// The list of style properties.
22 #[get(pub)]
23 #[set(pub)]
24 properties: Vec<StyleProperty>,
25}
26
27/// Represents a single attribute on a virtual DOM node.
28///
29/// Combines an attribute name with its corresponding value.
30#[derive(Clone, Data, New)]
31pub struct AttributeEntry {
32 /// The name of the attribute.
33 #[get(pub(crate))]
34 #[set(pub(crate))]
35 pub(crate) name: String,
36 /// The value of the attribute.
37 #[get(pub(crate))]
38 #[set(pub(crate))]
39 pub(crate) value: AttributeValue,
40}
41
42/// Represents a text node in the virtual DOM.
43///
44/// Text nodes may optionally be bound to a reactive signal for automatic updates.
45#[derive(Clone, Data, New)]
46pub struct TextNode {
47 /// The text content.
48 #[get(pub(crate))]
49 #[set(pub(crate))]
50 pub(crate) content: String,
51 /// An optional signal that drives reactive text updates.
52 #[get(pub(crate))]
53 #[set(pub(crate))]
54 pub(crate) signal: Option<Signal<String>>,
55}
56
57/// A closure-based dynamic node that re-renders when its dependency signals change.
58///
59/// Holds a boxed closure that produces a fresh `VirtualNode` on each evaluation.
60/// The renderer subscribes to the closure's signals and patches the DOM automatically.
61/// Contains a `HookContext` that persists hook state (like `use_signal`) across
62/// re-renders, ensuring that signal values are not reset when the render function
63/// is called again.
64#[derive(Data)]
65pub struct DynamicNode {
66 /// The closure that generates the dynamic virtual node tree.
67 #[get(pub)]
68 #[set(pub)]
69 pub(crate) render_fn: Rc<RefCell<dyn FnMut() -> VirtualNode>>,
70 /// Persistent hook context for this dynamic node, storing signal
71 /// state and other hook values across render cycles.
72 ///
73 /// Implements `Copy`; all copies share the same underlying state.
74 #[get(pub, type(copy))]
75 #[set(pub)]
76 pub(crate) hook_context: HookContext,
77}
78
79/// Represents a CSS class with a name and its style declarations.
80///
81/// Created by the `class!` macro and used in `html!` via the `class:` attribute.
82/// When the renderer encounters a `CssClass`, it injects the styles into the
83/// DOM's `<style>` element on first use and applies the class name to the element.
84#[derive(Clone, Data, Default)]
85pub struct CssClass {
86 /// The CSS class name used in the DOM.
87 #[get(pub)]
88 #[set(pub)]
89 name: String,
90 /// The CSS style declarations (e.g., "max-width: 800px; margin: 0 auto;").
91 #[get(pub)]
92 #[set(pub)]
93 style: String,
94}