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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user