123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //! webview dom
- use dioxus_core as dioxus;
- use dioxus_core::prelude::*;
- use dioxus_core::{
- diff::RealDom,
- serialize::DomEdits,
- virtual_dom::{RealDomNode, VirtualDom},
- };
- use DomEdits::*;
- pub struct WebviewDom<'bump> {
- pub edits: Vec<DomEdits<'bump>>,
- pub node_counter: u64,
- }
- impl WebviewDom<'_> {
- pub fn new() -> Self {
- Self {
- edits: Vec::new(),
- node_counter: 0,
- }
- }
- }
- impl<'bump> RealDom<'bump> for WebviewDom<'bump> {
- fn push_root(&mut self, root: dioxus_core::virtual_dom::RealDomNode) {
- self.edits.push(PushRoot { root: root.0 });
- }
- fn append_child(&mut self) {
- self.edits.push(AppendChild);
- }
- fn replace_with(&mut self) {
- self.edits.push(ReplaceWith);
- }
- fn remove(&mut self) {
- self.edits.push(Remove);
- }
- fn remove_all_children(&mut self) {
- self.edits.push(RemoveAllChildren);
- }
- fn create_text_node(&mut self, text: &'bump str) -> dioxus_core::virtual_dom::RealDomNode {
- self.node_counter += 1;
- let id = RealDomNode::new(self.node_counter);
- self.edits.push(CreateTextNode { text, id: id.0 });
- id
- }
- fn create_element(
- &mut self,
- tag: &'bump str,
- ns: Option<&'bump str>,
- ) -> dioxus_core::virtual_dom::RealDomNode {
- self.node_counter += 1;
- let id = RealDomNode::new(self.node_counter);
- match ns {
- Some(ns) => self.edits.push(CreateElementNs { id: id.0, ns, tag }),
- None => self.edits.push(CreateElement { id: id.0, tag }),
- }
- id
- }
- fn create_placeholder(&mut self) -> dioxus_core::virtual_dom::RealDomNode {
- self.node_counter += 1;
- let id = RealDomNode::new(self.node_counter);
- self.edits.push(CreatePlaceholder { id: id.0 });
- id
- }
- fn new_event_listener(
- &mut self,
- event: &'static str,
- scope: dioxus_core::prelude::ScopeIdx,
- element_id: usize,
- realnode: dioxus_core::virtual_dom::RealDomNode,
- ) {
- self.edits.push(NewEventListener {
- scope,
- event,
- idx: element_id,
- node: realnode.0,
- });
- }
- fn remove_event_listener(&mut self, event: &'static str) {
- self.edits.push(RemoveEventListener { event });
- }
- fn set_text(&mut self, text: &'bump str) {
- self.edits.push(SetText { text });
- }
- fn set_attribute(&mut self, field: &'static str, value: &'bump str, ns: Option<&'bump str>) {
- self.edits.push(SetAttribute { field, value, ns });
- }
- fn remove_attribute(&mut self, name: &'static str) {
- self.edits.push(RemoveAttribute { name });
- }
- fn raw_node_as_any_mut(&self) -> &mut dyn std::any::Any {
- todo!()
- // self.edits.push(PushRoot { root });
- }
- }
|