kotoba_state_graph/
schema.rs

1//! Defines the standard schema for representing UI state as a graph.
2//!
3//! This includes standard vertex types for UI components, edge labels for
4//! relationships (e.g., parent-child), and conventional property keys for state.
5
6/// Standard Vertex Types for UI Components.
7pub enum UiVertexType {
8    /// The root of the UI component tree.
9    UIRoot,
10    /// A generic UI component.
11    Component,
12    /// A modal dialog.
13    Modal,
14    /// A list of items.
15    List,
16    /// An input field.
17    Input,
18    /// A button.
19    Button,
20    /// A text element.
21    Text,
22}
23
24impl UiVertexType {
25    pub fn as_str(&self) -> &'static str {
26        match self {
27            UiVertexType::UIRoot => "UIRoot",
28            UiVertexType::Component => "Component",
29            UiVertexType::Modal => "Modal",
30            UiVertexType::List => "List",
31            UiVertexType::Input => "Input",
32            UiVertexType::Button => "Button",
33            UiVertexType::Text => "Text",
34        }
35    }
36}
37
38/// Standard Edge Labels for UI relationships.
39pub enum UiEdgeLabel {
40    /// Represents a parent-child relationship in the component tree.
41    HasChild,
42    /// Links a component to its state object.
43    HasState,
44    /// Links a form to its input fields.
45    HasInput,
46}
47
48impl UiEdgeLabel {
49    pub fn as_str(&self) -> &'static str {
50        match self {
51            UiEdgeLabel::HasChild => "HAS_CHILD",
52            UiEdgeLabel::HasState => "HAS_STATE",
53            UiEdgeLabel::HasInput => "HAS_INPUT",
54        }
55    }
56}
57
58/// Standard Property Keys for component state.
59pub struct UiPropKey;
60
61impl UiPropKey {
62    /// The unique identifier for a component within the UI graph.
63    pub const ID: &'static str = "id";
64    /// The visibility state of a component (boolean).
65    pub const IS_VISIBLE: &'static str = "isVisible";
66    /// The disabled state of a component (boolean).
67    pub const IS_DISABLED: &'static str = "isDisabled";
68    /// The title or label of a component (string).
69    pub const TITLE: &'static str = "title";
70    /// The value of an input component (string, number, etc.).
71    pub const VALUE: &'static str = "value";
72    /// The items in a list component (array).
73    pub const ITEMS: &'static str = "items";
74    /// The error message associated with a component (string).
75    pub const ERROR: &'static str = "error";
76    /// The loading state of a component (boolean).
77    pub const IS_LOADING: &'static str = "isLoading";
78    /// A map of all other component properties.
79    pub const PROPS: &'static str = "props";
80}