euv_core/dynamic/hub/struct.rs
1use super::*;
2
3/// Serializable style overrides attached to a `DynamicNodeSpec`.
4#[derive(Clone, Copy, Data, Debug, Default, Deserialize, PartialEq, Serialize)]
5#[serde(default)]
6pub struct DynamicStyleSpec {
7 /// Optional explicit pixel width (when `Some`, overrides default auto width).
8 #[get(skip)]
9 pub(crate) width: Option<f32>,
10 /// Optional explicit pixel height (when `Some`, overrides default auto height).
11 #[get(skip)]
12 pub(crate) height: Option<f32>,
13 /// Whether this node should stretch to `100%` of its parent width.
14 #[get(type(copy))]
15 pub(crate) full_width: bool,
16 /// Optional uniform inner padding in logical pixels.
17 #[get(skip)]
18 pub(crate) padding: Option<f32>,
19 /// Optional inter-child gap in logical pixels.
20 #[get(skip)]
21 pub(crate) gap: Option<f32>,
22 /// Optional uniform corner radius in logical pixels.
23 #[get(skip)]
24 pub(crate) radius: Option<f32>,
25 /// Optional text font size in logical pixels.
26 #[get(skip)]
27 pub(crate) font_size: Option<f32>,
28 /// Whether typography renders in bold weight.
29 #[get(type(copy))]
30 pub(crate) bold: bool,
31 /// Optional 24-bit RGB hex background fill color (e.g. `0x2563EB`).
32 #[get(skip)]
33 pub(crate) background_hex: Option<u32>,
34 /// Optional 24-bit RGB hex foreground text color (e.g. `0xFFFFFF`).
35 #[get(skip)]
36 pub(crate) color_hex: Option<u32>,
37 /// Optional border stroke width in logical pixels.
38 #[get(skip)]
39 pub(crate) border_width: Option<f32>,
40 /// Optional 24-bit RGB hex border stroke color.
41 #[get(skip)]
42 pub(crate) border_hex: Option<u32>,
43 /// Grid column count when `kind == DynamicNodeKind::Grid`.
44 #[get(type(copy))]
45 pub(crate) columns: u16,
46 /// Flex grow factor inside parent flex containers.
47 #[get(type(copy))]
48 pub(crate) flex_grow: f32,
49}
50
51/// Serializable declarative UI node tree compiled directly into native `SceneTree` nodes at runtime.
52#[derive(Clone, Data, Debug, Default, Deserialize, New, PartialEq, Serialize)]
53#[serde(default)]
54pub struct DynamicNodeSpec {
55 /// Semantic native primitive kind.
56 #[get(type(copy))]
57 pub(crate) kind: DynamicNodeKind,
58 /// Optional UTF-8 text content for `Text`, `Button`, `Badge`, or `Card` title.
59 #[new(skip)]
60 pub(crate) text: String,
61 /// Optional action identifier emitted as `DynamicActionEvent` when clicked.
62 #[new(skip)]
63 #[get(skip)]
64 pub(crate) action: Option<String>,
65 /// Optional opaque string payload carried by `DynamicActionEvent`.
66 #[new(skip)]
67 pub(crate) payload: String,
68 /// Optional declarative visual and layout style overrides.
69 #[new(skip)]
70 #[get(type(copy))]
71 pub(crate) style: DynamicStyleSpec,
72 /// Ordered nested child specifications.
73 #[new(skip)]
74 pub(crate) children: Vec<DynamicNodeSpec>,
75}
76
77/// Versioned, checksum-verified component-level dynamic update payload.
78#[derive(Clone, Data, Debug, Deserialize, New, PartialEq, Serialize)]
79pub struct DynamicComponentUpdate {
80 /// Unique slot identifier targeted by this component update (e.g. `"promo_banner"`).
81 pub(crate) id: String,
82 /// Monotonic component revision number (`>= 1`).
83 #[get(type(copy))]
84 pub(crate) version: u64,
85 /// Declarative UI subtree replacing the slot contents.
86 pub(crate) spec: DynamicNodeSpec,
87 /// Optional expected deterministic FNV-1a checksum (`0` skips checksum verification).
88 #[new(skip)]
89 #[serde(default)]
90 #[get(type(copy))]
91 pub(crate) checksum: u64,
92 /// Whether this update may apply a version lower than or equal to the currently active version.
93 #[new(skip)]
94 #[serde(default)]
95 #[get(type(copy))]
96 pub(crate) allow_downgrade: bool,
97}
98
99/// Versioned, checksum-verified page-level dynamic update payload (overrides or injects a route).
100#[derive(Clone, Data, Debug, Deserialize, New, PartialEq, Serialize)]
101pub struct DynamicPageUpdate {
102 /// Normalized route path targeted by this page update (e.g. `"/promo-live"`).
103 pub(crate) route: String,
104 /// Human-readable page title exposed for navigation menus and headers.
105 pub(crate) title: String,
106 /// Monotonic page revision number (`>= 1`).
107 #[get(type(copy))]
108 pub(crate) version: u64,
109 /// Declarative UI page tree rendered when this route is active.
110 pub(crate) spec: DynamicNodeSpec,
111 /// Optional expected deterministic FNV-1a checksum (`0` skips checksum verification).
112 #[new(skip)]
113 #[serde(default)]
114 #[get(type(copy))]
115 pub(crate) checksum: u64,
116 /// Hint indicating whether external page state should be preserved across hot-swaps.
117 #[new(skip)]
118 #[serde(default)]
119 #[get(type(copy))]
120 pub(crate) preserve_state: bool,
121 /// Whether this update may apply a version lower than or equal to the currently active version.
122 #[new(skip)]
123 #[serde(default)]
124 #[get(type(copy))]
125 pub(crate) allow_downgrade: bool,
126}
127
128/// Atomic multi-target update manifest delivering component-level and page-level updates together.
129#[derive(Clone, Data, Debug, Default, Deserialize, New, PartialEq, Serialize)]
130pub struct DynamicUpdateBundle {
131 /// Unique release bundle identifier (e.g. `"ota-2026.11.25-01"`).
132 pub(crate) bundle_id: String,
133 /// Monotonic bundle release version.
134 #[get(type(copy))]
135 pub(crate) version: u64,
136 /// Ordered component-level updates applied atomically.
137 #[new(skip)]
138 #[serde(default)]
139 pub(crate) components: Vec<DynamicComponentUpdate>,
140 /// Ordered page-level updates applied atomically.
141 #[new(skip)]
142 #[serde(default)]
143 pub(crate) pages: Vec<DynamicPageUpdate>,
144}
145
146/// Interactive event emitted when a user activates a button inside a dynamically updated component or page.
147#[derive(Clone, Data, Debug, Eq, Hash, New, PartialEq)]
148pub struct DynamicActionEvent {
149 /// Originating component slot ID or page route path.
150 pub(crate) source_id: String,
151 /// Action identifier declared on the dynamic control.
152 pub(crate) action: String,
153 /// Optional string payload carried with the action.
154 pub(crate) payload: String,
155}
156
157/// Cumulative runtime telemetry counters exposed reactively by `DynamicUpdateHub`.
158#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
159pub struct DynamicTelemetry {
160 /// Total successful component-level dynamic updates applied.
161 #[get(type(copy))]
162 pub(crate) components_applied: u64,
163 /// Total successful page-level dynamic updates applied.
164 #[get(type(copy))]
165 pub(crate) pages_applied: u64,
166 /// Total component or page rollbacks executed.
167 #[get(type(copy))]
168 pub(crate) rollbacks: u64,
169 /// Total rejected updates (checksum mismatch, version regression, invalid JSON).
170 #[get(type(copy))]
171 pub(crate) rejected: u64,
172 /// Total interactive actions dispatched from dynamically rendered controls.
173 #[get(type(copy))]
174 pub(crate) actions_dispatched: u64,
175}
176
177/// Single revision entry stored on a component or page history stack for instant rollback.
178#[derive(Clone, CustomDebug)]
179pub(crate) struct DynamicSlotRecord {
180 /// Revision version number.
181 pub(crate) version: u64,
182 /// Optional page title (empty for component slots).
183 pub(crate) title: String,
184 /// Verified payload checksum (`0` for native Rust closure swaps).
185 pub(crate) checksum: u64,
186 /// Renderable payload (declarative spec or native Rust builder).
187 pub(crate) payload: DynamicPayload,
188}
189
190/// Internal interior-mutable registry storing component/page revision stacks and surgical signals.
191#[derive(CustomDebug)]
192pub(crate) struct DynamicHubState {
193 /// Revision stacks keyed by component slot ID.
194 pub(crate) components: HashMap<String, Vec<DynamicSlotRecord>>,
195 /// Dedicated per-component reactive revision signals for O(1) surgical re-renders.
196 pub(crate) component_signals: HashMap<String, Signal<u64>>,
197 /// Revision stacks keyed by normalized page route path.
198 pub(crate) pages: HashMap<String, Vec<DynamicSlotRecord>>,
199 /// Dedicated per-page reactive revision signals for O(1) surgical page re-renders.
200 pub(crate) page_signals: HashMap<String, Signal<u64>>,
201 /// Reactive counter bumped whenever the set of registered dynamic routes changes.
202 pub(crate) routes_signal: Signal<u64>,
203 /// Reactive telemetry snapshot signal.
204 pub(crate) telemetry_signal: Signal<DynamicTelemetry>,
205 /// Reactive signal carrying the most recent `DynamicActionEvent`.
206 pub(crate) last_action: Signal<Option<DynamicActionEvent>>,
207 /// Registered imperative action callbacks.
208 #[debug(skip)]
209 pub(crate) action_handlers: Vec<DynamicActionCallback>,
210 /// Reactive runtime epoch active when hub signals were allocated.
211 pub(crate) runtime_epoch: u64,
212}
213
214/// Internal staged commit payload returned after applying a page-level dynamic update.
215pub(crate) struct PageApplyCommit {
216 /// Revision signal for the updated route.
217 pub(crate) page_sig: Signal<u64>,
218 /// Revision signal tracking the dynamic route table.
219 pub(crate) routes_sig: Signal<u64>,
220 /// Telemetry snapshot signal.
221 pub(crate) tel_sig: Signal<DynamicTelemetry>,
222 /// Updated telemetry snapshot to publish.
223 pub(crate) tel: DynamicTelemetry,
224 /// Whether this commit introduced a new dynamic route.
225 pub(crate) is_new_route: bool,
226}
227
228/// Internal staged commit payload returned after rolling back a page-level dynamic update.
229pub(crate) struct PageRollbackCommit {
230 /// Restored version number (`0` when reverted to compiled fallback).
231 pub(crate) next_ver: u64,
232 /// Revision signal for the rolled-back route.
233 pub(crate) page_sig: Signal<u64>,
234 /// Revision signal tracking the dynamic route table.
235 pub(crate) routes_sig: Signal<u64>,
236 /// Telemetry snapshot signal.
237 pub(crate) tel_sig: Signal<DynamicTelemetry>,
238 /// Updated telemetry snapshot to publish.
239 pub(crate) tel: DynamicTelemetry,
240 /// Whether rolling back removed the dynamic route entry.
241 pub(crate) route_removed: bool,
242}
243
244/// Internal staged commit payload returned after validating and applying an atomic bundle.
245pub(crate) struct BundleApplyCommit {
246 /// Component and page revision signals dirtied by the bundle.
247 pub(crate) dirty_signals: Vec<Signal<u64>>,
248 /// Whether at least one new dynamic route was registered.
249 pub(crate) added_route: bool,
250 /// Revision signal tracking the dynamic route table.
251 pub(crate) routes_sig: Signal<u64>,
252 /// Telemetry snapshot signal.
253 pub(crate) tel_sig: Signal<DynamicTelemetry>,
254 /// Updated telemetry snapshot to publish.
255 pub(crate) tel: DynamicTelemetry,
256}
257
258/// Shared cross-platform hub orchestrating surgical component-level and page-level dynamic updates.
259#[derive(Clone, CustomDebug)]
260pub struct DynamicUpdateHub {
261 /// Interior-mutable registry state shared across `App`, `Context`, and live UI slots.
262 pub(crate) inner: Rc<RefCell<DynamicHubState>>,
263}
264
265/// Declarative `Component` slot supporting surgical component-level dynamic updates and rollbacks.
266#[derive(CustomDebug, Data, New)]
267pub struct DynamicComponentSlot {
268 /// Unique component slot identifier targeted by `DynamicUpdateHub::apply_component`.
269 pub(crate) id: String,
270 /// Compiled fallback UI builder rendered when no dynamic update is active for `id`.
271 #[debug(skip)]
272 #[get(skip)]
273 pub(crate) fallback: Rc<dyn Fn() -> NodeId>,
274 /// Optional explicit `DynamicUpdateHub` override (defaults to the ambient `Context` hub).
275 #[new(skip)]
276 #[get(skip)]
277 pub(crate) hub: Option<DynamicUpdateHub>,
278 /// Optional container `Style` applied to the slot host wrapper node.
279 #[new(skip)]
280 #[get(type(copy))]
281 pub(crate) style: Style,
282}
283
284/// Declarative `Component` slot supporting surgical page-level dynamic updates for a single route.
285#[derive(CustomDebug, Data, New)]
286pub struct DynamicPageSlot {
287 /// Route path targeted by `DynamicUpdateHub::apply_page` (e.g. `"/dynamic/live"`).
288 pub(crate) route: String,
289 /// Compiled fallback page builder rendered when no dynamic page update is active.
290 #[debug(skip)]
291 #[get(skip)]
292 pub(crate) fallback: Rc<dyn Fn() -> NodeId>,
293 /// Optional explicit `DynamicUpdateHub` override (defaults to the ambient `Context` hub).
294 #[new(skip)]
295 #[get(skip)]
296 pub(crate) hub: Option<DynamicUpdateHub>,
297 /// Optional container `Style` applied to the page slot host node.
298 #[new(skip)]
299 #[get(type(copy))]
300 pub(crate) style: Style,
301}
302
303/// Reactive route-driven page outlet seamlessly rendering compiled routes, hot-updated pages, and runtime-injected routes.
304#[derive(CustomDebug, Data, New)]
305pub struct DynamicPageOutlet {
306 /// Reactive route path signal controlling which page is currently active.
307 #[get(type(copy))]
308 pub(crate) route: Signal<String>,
309 /// Fallback router closure invoked when the active route has no dynamic page override.
310 #[debug(skip)]
311 #[get(skip)]
312 pub(crate) fallback: Rc<dyn Fn(&str) -> NodeId>,
313 /// Optional explicit `DynamicUpdateHub` override (defaults to the ambient `Context` hub).
314 #[new(skip)]
315 #[get(skip)]
316 pub(crate) hub: Option<DynamicUpdateHub>,
317 /// Optional container `Style` applied to the outlet host wrapper node.
318 #[new(skip)]
319 #[get(type(copy))]
320 pub(crate) style: Style,
321}