fix native core, plasmo and dioxus-tui
This commit is contained in:
1 parent
87572d694f
commit
439e39bab4
37 files changed
+588
-266
No files matched your search
@@ -3,45 +3,104 @@ use std::{
|
||||
fmt::{Display, Formatter},
|
||||
};
|
||||
|
||||
use dioxus_core::{ElementId, Mutations, VirtualDom};
|
||||
use dioxus_core::{ElementId, WriteMutations};
|
||||
use dioxus_html::{
|
||||
geometry::euclid::{Point2D, Rect, Size2D},
|
||||
MountedData, MountedError, RenderedElementBacking,
|
||||
};
|
||||
|
||||
use dioxus_native_core::NodeId;
|
||||
use dioxus_native_core::{dioxus::DioxusNativeCoreMutationWriter, NodeId};
|
||||
use plasmo::query::{ElementRef, Query};
|
||||
|
||||
pub(crate) fn find_mount_events(mutations: &Mutations) -> Vec<ElementId> {
|
||||
let mut mount_events = Vec::new();
|
||||
for mutation in &mutations.edits {
|
||||
if let dioxus_core::Mutation::NewEventListener {
|
||||
name: "mounted",
|
||||
id,
|
||||
} = mutation
|
||||
{
|
||||
mount_events.push(*id);
|
||||
}
|
||||
}
|
||||
mount_events
|
||||
pub(crate) struct DioxusTUIMutationWriter<'a> {
|
||||
pub(crate) query: Query,
|
||||
pub(crate) events: &'a mut Vec<(ElementId, &'static str, Box<dyn Any>, bool)>,
|
||||
pub(crate) native_core_writer: DioxusNativeCoreMutationWriter<'a>,
|
||||
}
|
||||
|
||||
// We need to queue the mounted events to give rink time to rendere and resolve the layout of elements after they are created
|
||||
pub(crate) fn create_mounted_events(
|
||||
vdom: &VirtualDom,
|
||||
events: &mut Vec<(ElementId, &'static str, Box<dyn Any>, bool)>,
|
||||
mount_events: impl Iterator<Item = (ElementId, NodeId)>,
|
||||
) {
|
||||
let query: Query = vdom
|
||||
.base_scope()
|
||||
.consume_context()
|
||||
.expect("Query should be in context");
|
||||
for (id, node_id) in mount_events {
|
||||
let element = TuiElement {
|
||||
query: query.clone(),
|
||||
id: node_id,
|
||||
};
|
||||
events.push((id, "mounted", Box::new(MountedData::new(element)), false));
|
||||
impl WriteMutations for DioxusTUIMutationWriter<'_> {
|
||||
fn register_template(&mut self, template: dioxus_core::prelude::Template) {
|
||||
self.native_core_writer.register_template(template)
|
||||
}
|
||||
|
||||
fn append_children(&mut self, id: ElementId, m: usize) {
|
||||
self.native_core_writer.append_children(id, m)
|
||||
}
|
||||
|
||||
fn assign_node_id(&mut self, path: &'static [u8], id: ElementId) {
|
||||
self.native_core_writer.assign_node_id(path, id)
|
||||
}
|
||||
|
||||
fn create_placeholder(&mut self, id: ElementId) {
|
||||
self.native_core_writer.create_placeholder(id)
|
||||
}
|
||||
|
||||
fn create_text_node(&mut self, value: &str, id: ElementId) {
|
||||
self.native_core_writer.create_text_node(value, id)
|
||||
}
|
||||
|
||||
fn hydrate_text_node(&mut self, path: &'static [u8], value: &str, id: ElementId) {
|
||||
self.native_core_writer.hydrate_text_node(path, value, id)
|
||||
}
|
||||
|
||||
fn load_template(&mut self, name: &'static str, index: usize, id: ElementId) {
|
||||
self.native_core_writer.load_template(name, index, id)
|
||||
}
|
||||
|
||||
fn replace_node_with(&mut self, id: ElementId, m: usize) {
|
||||
self.native_core_writer.replace_node_with(id, m)
|
||||
}
|
||||
|
||||
fn replace_placeholder_with_nodes(&mut self, path: &'static [u8], m: usize) {
|
||||
self.native_core_writer
|
||||
.replace_placeholder_with_nodes(path, m)
|
||||
}
|
||||
|
||||
fn insert_nodes_after(&mut self, id: ElementId, m: usize) {
|
||||
self.native_core_writer.insert_nodes_after(id, m)
|
||||
}
|
||||
|
||||
fn insert_nodes_before(&mut self, id: ElementId, m: usize) {
|
||||
self.native_core_writer.insert_nodes_before(id, m)
|
||||
}
|
||||
|
||||
fn set_attribute(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
ns: Option<&'static str>,
|
||||
value: &dioxus_core::AttributeValue,
|
||||
id: ElementId,
|
||||
) {
|
||||
self.native_core_writer.set_attribute(name, ns, value, id)
|
||||
}
|
||||
|
||||
fn set_node_text(&mut self, value: &str, id: ElementId) {
|
||||
self.native_core_writer.set_node_text(value, id)
|
||||
}
|
||||
|
||||
fn create_event_listener(&mut self, name: &'static str, id: ElementId) {
|
||||
if name == "mounted" {
|
||||
let element = TuiElement {
|
||||
query: self.query.clone(),
|
||||
id: self.native_core_writer.state.element_to_node_id(id),
|
||||
};
|
||||
self.events
|
||||
.push((id, "mounted", Box::new(MountedData::new(element)), false));
|
||||
} else {
|
||||
self.native_core_writer.create_event_listener(name, id)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_event_listener(&mut self, name: &'static str, id: ElementId) {
|
||||
self.native_core_writer.remove_event_listener(name, id)
|
||||
}
|
||||
|
||||
fn remove_node(&mut self, id: ElementId) {
|
||||
self.native_core_writer.remove_node(id)
|
||||
}
|
||||
|
||||
fn push_root(&mut self, id: ElementId) {
|
||||
self.native_core_writer.push_root(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user