Refactor Mutations and simplify Templates (#578)
* update mutations to be path based rather than renderer integrated
This commit is contained in:
1 parent
020c4bf0f8
commit
3b7b503333
44 files changed
+2643
-3134
No files matched your search
@@ -1,7 +1,9 @@
|
||||
use crate::{node::PreventDefault, Dom};
|
||||
|
||||
use dioxus_core::GlobalNodeId;
|
||||
use dioxus_native_core::utils::{ElementProduced, PersistantElementIter};
|
||||
use dioxus_native_core::{
|
||||
utils::{ElementProduced, PersistantElementIter},
|
||||
RealNodeId,
|
||||
};
|
||||
use dioxus_native_core_macro::sorted_str_slice;
|
||||
|
||||
use std::{cmp::Ordering, num::NonZeroU16};
|
||||
@@ -90,7 +92,7 @@ impl NodeDepState<()> for Focus {
|
||||
}
|
||||
} else if node
|
||||
.listeners()
|
||||
.map(|mut listeners| {
|
||||
.and_then(|mut listeners| {
|
||||
listeners
|
||||
.any(|l| FOCUS_EVENTS.binary_search(&l).is_ok())
|
||||
.then_some(())
|
||||
@@ -117,7 +119,7 @@ const FOCUS_ATTRIBUTES: &[&str] = &sorted_str_slice!(["tabindex"]);
|
||||
#[derive(Default)]
|
||||
pub(crate) struct FocusState {
|
||||
pub(crate) focus_iter: PersistantElementIter,
|
||||
pub(crate) last_focused_id: Option<GlobalNodeId>,
|
||||
pub(crate) last_focused_id: Option<RealNodeId>,
|
||||
pub(crate) focus_level: FocusLevel,
|
||||
pub(crate) dirty: bool,
|
||||
}
|
||||
@@ -216,6 +218,9 @@ impl FocusState {
|
||||
}
|
||||
|
||||
if let Some(id) = next_focus {
|
||||
if !rdom[id].state.focus.level.focusable() {
|
||||
panic!()
|
||||
}
|
||||
rdom[id].state.focused = true;
|
||||
if let Some(old) = self.last_focused_id.replace(id) {
|
||||
rdom[old].state.focused = false;
|
||||
@@ -231,9 +236,9 @@ impl FocusState {
|
||||
|
||||
pub(crate) fn prune(&mut self, mutations: &dioxus_core::Mutations, rdom: &Dom) {
|
||||
fn remove_children(
|
||||
to_prune: &mut [&mut Option<GlobalNodeId>],
|
||||
to_prune: &mut [&mut Option<RealNodeId>],
|
||||
rdom: &Dom,
|
||||
removed: GlobalNodeId,
|
||||
removed: RealNodeId,
|
||||
) {
|
||||
for opt in to_prune.iter_mut() {
|
||||
if let Some(id) = opt {
|
||||
@@ -256,19 +261,19 @@ impl FocusState {
|
||||
dioxus_core::DomEdit::ReplaceWith { root, .. } => remove_children(
|
||||
&mut [&mut self.last_focused_id],
|
||||
rdom,
|
||||
rdom.decode_id(*root),
|
||||
rdom.resolve_maybe_id(*root),
|
||||
),
|
||||
dioxus_core::DomEdit::Remove { root } => remove_children(
|
||||
&mut [&mut self.last_focused_id],
|
||||
rdom,
|
||||
rdom.decode_id(*root),
|
||||
rdom.resolve_maybe_id(*root),
|
||||
),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_focus(&mut self, rdom: &mut Dom, id: GlobalNodeId) {
|
||||
pub(crate) fn set_focus(&mut self, rdom: &mut Dom, id: RealNodeId) {
|
||||
if let Some(old) = self.last_focused_id.replace(id) {
|
||||
rdom[old].state.focused = false;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use crossterm::event::{
|
||||
Event as TermEvent, KeyCode as TermKeyCode, KeyModifiers, MouseButton, MouseEventKind,
|
||||
};
|
||||
use dioxus_core::*;
|
||||
use dioxus_native_core::RealNodeId;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use dioxus_html::geometry::euclid::{Point2D, Rect, Size2D};
|
||||
@@ -190,7 +191,8 @@ impl InnerInputState {
|
||||
self.resolve_mouse_events(previous_mouse, resolved_events, layout, dom);
|
||||
|
||||
if old_focus != self.focus_state.last_focused_id {
|
||||
if let Some(id) = self.focus_state.last_focused_id {
|
||||
// elements with listeners will always have a element id
|
||||
if let Some(RealNodeId::ElementId(id)) = self.focus_state.last_focused_id {
|
||||
resolved_events.push(UserEvent {
|
||||
scope_id: None,
|
||||
priority: EventPriority::Medium,
|
||||
@@ -208,7 +210,7 @@ impl InnerInputState {
|
||||
bubbles: event_bubbles("focusin"),
|
||||
});
|
||||
}
|
||||
if let Some(id) = old_focus {
|
||||
if let Some(RealNodeId::ElementId(id)) = old_focus {
|
||||
resolved_events.push(UserEvent {
|
||||
scope_id: None,
|
||||
priority: EventPriority::Medium,
|
||||
@@ -243,13 +245,13 @@ impl InnerInputState {
|
||||
fn try_create_event(
|
||||
name: &'static str,
|
||||
data: Arc<dyn Any + Send + Sync>,
|
||||
will_bubble: &mut FxHashSet<GlobalNodeId>,
|
||||
will_bubble: &mut FxHashSet<RealNodeId>,
|
||||
resolved_events: &mut Vec<UserEvent>,
|
||||
node: &Node,
|
||||
dom: &Dom,
|
||||
) {
|
||||
// only trigger event if the event was not triggered already by a child
|
||||
let id = node.node_data.id;
|
||||
let id = node.mounted_id();
|
||||
if will_bubble.insert(id) {
|
||||
let mut parent = node.node_data.parent;
|
||||
while let Some(parent_id) = parent {
|
||||
@@ -260,7 +262,7 @@ impl InnerInputState {
|
||||
scope_id: None,
|
||||
priority: EventPriority::Medium,
|
||||
name,
|
||||
element: Some(id),
|
||||
element: Some(id.as_element_id()),
|
||||
data,
|
||||
bubbles: event_bubbles(name),
|
||||
})
|
||||
@@ -547,7 +549,7 @@ impl InnerInputState {
|
||||
let currently_contains = layout_contains_point(node_layout, new_pos);
|
||||
|
||||
if currently_contains && node.state.focus.level.focusable() {
|
||||
focus_id = Some(node.node_data.id);
|
||||
focus_id = Some(node.mounted_id());
|
||||
}
|
||||
});
|
||||
if let Some(id) = focus_id {
|
||||
@@ -665,7 +667,7 @@ impl RinkInputHandler {
|
||||
scope_id: None,
|
||||
priority: EventPriority::Medium,
|
||||
name: event,
|
||||
element: Some(node.node_data.id),
|
||||
element: Some(node.mounted_id().as_element_id()),
|
||||
data: data.clone(),
|
||||
bubbles: event_bubbles(event),
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ use dioxus_native_core::layout_attributes::apply_layout_attributes;
|
||||
use dioxus_native_core::node_ref::{AttributeMask, NodeMask, NodeView};
|
||||
use dioxus_native_core::real_dom::OwnedAttributeView;
|
||||
use dioxus_native_core::state::ChildDepState;
|
||||
use dioxus_native_core::RealNodeId;
|
||||
use dioxus_native_core_macro::sorted_str_slice;
|
||||
use taffy::prelude::*;
|
||||
|
||||
@@ -100,7 +101,7 @@ impl ChildDepState for TaffyLayout {
|
||||
}
|
||||
|
||||
// the root node fills the entire area
|
||||
if node.id() == ElementId(0) {
|
||||
if node.id() == RealNodeId::ElementId(ElementId(0)) {
|
||||
apply_layout_attributes("width", "100%", &mut style);
|
||||
apply_layout_attributes("height", "100%", &mut style);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crossterm::{
|
||||
};
|
||||
use dioxus_core::exports::futures_channel::mpsc::unbounded;
|
||||
use dioxus_core::*;
|
||||
use dioxus_native_core::real_dom::RealDom;
|
||||
use dioxus_native_core::{real_dom::RealDom, RealNodeId};
|
||||
use focus::FocusState;
|
||||
use futures::{
|
||||
channel::mpsc::{UnboundedReceiver, UnboundedSender},
|
||||
@@ -133,8 +133,8 @@ fn render_vdom(
|
||||
terminal.clear().unwrap();
|
||||
}
|
||||
|
||||
let mut to_rerender: rustc_hash::FxHashSet<GlobalNodeId> =
|
||||
vec![GlobalNodeId::VNodeId(ElementId(0))]
|
||||
let mut to_rerender: rustc_hash::FxHashSet<RealNodeId> =
|
||||
vec![RealNodeId::ElementId(ElementId(0))]
|
||||
.into_iter()
|
||||
.collect();
|
||||
let mut updated = true;
|
||||
|
||||
Reference in new issue
Block a user