use crate::{dioxus_document::qual_name, NodeId}; use blitz_dom::{ local_name, namespace_url, node::{Attribute, NodeSpecificData}, ns, BaseDocument, ElementNodeData, NodeData, QualName, RestyleHint, }; use dioxus_core::{ AttributeValue, ElementId, Template, TemplateAttribute, TemplateNode, WriteMutations, }; use rustc_hash::FxHashMap; use std::collections::HashSet; /// The state of the Dioxus integration with the RealDom #[derive(Debug)] pub struct DioxusState { /// Store of templates keyed by unique name templates: FxHashMap>, /// Stack machine state for applying dioxus mutations stack: Vec, /// Mapping from vdom ElementId -> rdom NodeId node_id_mapping: Vec>, } /// A writer for mutations that can be used with the RealDom. pub struct MutationWriter<'a> { /// The realdom associated with this writer pub doc: &'a mut BaseDocument, /// The state associated with this writer pub state: &'a mut DioxusState, pub style_nodes: HashSet, /// The (latest) node which has been mounted in and had autofocus=true, if any #[cfg(feature = "autofocus")] pub node_to_autofocus: Option, } impl<'a> MutationWriter<'a> { pub fn new(doc: &'a mut BaseDocument, state: &'a mut DioxusState) -> Self { MutationWriter { doc, state, style_nodes: HashSet::new(), #[cfg(feature = "autofocus")] node_to_autofocus: None, } } fn is_style_node(&self, node_id: NodeId) -> bool { self.doc .get_node(node_id) .unwrap() .data .is_element_with_tag_name(&local_name!("style")) } fn maybe_push_style_node(&mut self, node_id: impl Into>) { if let Some(node_id) = node_id.into() { if self.is_style_node(node_id) { self.style_nodes.insert(node_id); } } } #[track_caller] fn maybe_push_parent_style_node(&mut self, node_id: NodeId) { let parent_id = self.doc.get_node(node_id).unwrap().parent; self.maybe_push_style_node(parent_id); } } impl Drop for MutationWriter<'_> { fn drop(&mut self) { // Add/Update inline stylesheets (