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