Skip to main content

euv_core/vdom/
enum.rs

1use crate::*;
2
3/// Represents the type of an HTML tag or a component.
4///
5/// Distinguishes between standard HTML elements and user-defined components.
6#[derive(Clone)]
7pub enum Tag {
8    /// A standard HTML element identified by its tag name.
9    Element(String),
10    /// A custom component type.
11    Component(String),
12}
13
14/// Represents the name of an HTML attribute or DOM property.
15///
16/// Covers common HTML attributes, accessibility attributes, and custom data attributes.
17#[derive(Clone)]
18pub enum Attribute {
19    /// The accesskey attribute.
20    AccessKey,
21    /// The action attribute for forms.
22    Action,
23    /// The alt attribute for images.
24    Alt,
25    /// The aria-label accessibility attribute.
26    AriaLabel,
27    /// The autocomplete attribute.
28    AutoComplete,
29    /// The autofocus attribute.
30    AutoFocus,
31    /// The checked attribute for checkboxes/radios.
32    Checked,
33    /// The class attribute.
34    Class,
35    /// The cols attribute for textareas.
36    Cols,
37    /// The contenteditable attribute.
38    ContentEditable,
39    /// The data-* custom attribute.
40    Data(String),
41    /// The dir attribute.
42    Dir,
43    /// The disabled attribute.
44    Disabled,
45    /// The draggable attribute.
46    Draggable,
47    /// The enctype attribute for forms.
48    EncType,
49    /// The for attribute for labels.
50    For,
51    /// The form attribute.
52    Form,
53    /// The height attribute.
54    Height,
55    /// The hidden attribute.
56    Hidden,
57    /// The href attribute for links.
58    Href,
59    /// The id attribute.
60    Id,
61    /// The lang attribute.
62    Lang,
63    /// The max attribute.
64    Max,
65    /// The maxlength attribute.
66    MaxLength,
67    /// The method attribute for forms.
68    Method,
69    /// The min attribute.
70    Min,
71    /// The minlength attribute.
72    MinLength,
73    /// The multiple attribute for selects.
74    Multiple,
75    /// The name attribute.
76    Name,
77    /// The pattern attribute for inputs.
78    Pattern,
79    /// The placeholder attribute.
80    Placeholder,
81    /// The readonly attribute.
82    ReadOnly,
83    /// The required attribute.
84    Required,
85    /// The rows attribute for textareas.
86    Rows,
87    /// The selected attribute for options.
88    Selected,
89    /// The size attribute.
90    Size,
91    /// The spellcheck attribute.
92    SpellCheck,
93    /// The src attribute for media/images.
94    Src,
95    /// The step attribute.
96    Step,
97    /// The style attribute.
98    Style,
99    /// The tabindex attribute.
100    TabIndex,
101    /// The target attribute for links/forms.
102    Target,
103    /// The title attribute.
104    Title,
105    /// The type attribute for inputs.
106    Type,
107    /// The value attribute.
108    Value,
109    /// The width attribute.
110    Width,
111    /// A custom attribute with an arbitrary name.
112    Other(String),
113}
114
115/// Represents the value of an HTML attribute.
116///
117/// Attributes can be static text, reactive signals, event handlers, dynamic expressions,
118/// or CSS class references.
119#[derive(Clone)]
120pub enum AttributeValue {
121    /// A static string value.
122    Text(String),
123    /// A dynamic signal-backed value.
124    Signal(Signal<String>),
125    /// An event handler callback.
126    Event(crate::event::NativeEventHandler),
127    /// A dynamic expression value of any type (for component props).
128    Dynamic(String),
129    /// A CSS class reference created by the `class!` macro.
130    Css(CssClass),
131}
132
133/// Represents a node in the virtual DOM tree.
134///
135/// The core enum representing elements, text, fragments, and empty nodes.
136#[derive(Clone, Default)]
137pub enum VirtualNode {
138    /// An element node with a tag, attributes, and children.
139    Element {
140        /// The tag type of this element.
141        tag: Tag,
142        /// The attributes attached to this element.
143        attributes: Vec<AttributeEntry>,
144        /// The child nodes.
145        children: Vec<VirtualNode>,
146        /// An optional key for diffing.
147        key: Option<String>,
148    },
149    /// A text node.
150    Text(TextNode),
151    /// A fragment of multiple nodes without a wrapper element.
152    Fragment(Vec<VirtualNode>),
153    /// A dynamic node that re-renders based on signal changes.
154    Dynamic(DynamicNode),
155    /// An empty placeholder node.
156    #[default]
157    Empty,
158}