Synchronous prevent default (#2792)
* add prevent default methods to the event * sync prevent default almost working * sync prevent default working * Move event handling into the runtime * update core tests * restore desktop file dialog * implement prevent default on web * add a hint about the new prevent default method * fix web prevent default * Fix CTRL+click on links * fix values memorize in place test * Fix a few more tests * Add a playwright test for sync prevent default * Fix core doc tests * create a deprecated VirtualDom::handle_event * fix macos imports in desktop * Fix onmounted event * Fix liveview support * switch to RefCell for metadata * Remove println * remove prevent default attribute * remove web specific link behavior * Fix liveview links * more liveview fixes for link * Fix merge conflicts * Fix clippy * use the new prevent default in the file upload example
This commit is contained in:
1 parent
8b62b71e2d
commit
cab573eefd
54 files changed
+940
-729
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
use std::{rc::Rc, sync::Mutex};
|
||||
use std::{any::Any, rc::Rc, sync::Mutex};
|
||||
|
||||
static CLICKS: Mutex<usize> = Mutex::new(0);
|
||||
|
||||
@@ -12,12 +12,11 @@ fn events_propagate() {
|
||||
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
||||
|
||||
// Top-level click is registered
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(1),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(1));
|
||||
assert_eq!(*CLICKS.lock().unwrap(), 1);
|
||||
|
||||
// break reference....
|
||||
@@ -27,12 +26,11 @@ fn events_propagate() {
|
||||
}
|
||||
|
||||
// Lower click is registered
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(2),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(2));
|
||||
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
||||
|
||||
// break reference....
|
||||
@@ -42,12 +40,11 @@ fn events_propagate() {
|
||||
}
|
||||
|
||||
// Stop propagation occurs
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(2),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(2));
|
||||
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#![cfg(not(miri))]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{AttributeValue, DynamicNode, NoOpMutations, Template, VComponent, VNode, *};
|
||||
use std::{cfg, collections::HashSet, default::Default};
|
||||
use dioxus_core::{AttributeValue, DynamicNode, NoOpMutations, VComponent, VNode, *};
|
||||
use std::{any::Any, cfg, collections::HashSet, default::Default, rc::Rc};
|
||||
|
||||
fn random_ns() -> Option<&'static str> {
|
||||
let namespace = rand::random::<u8>() % 2;
|
||||
@@ -279,12 +279,11 @@ fn diff() {
|
||||
for _ in 0..100 {
|
||||
for &id in &event_listeners {
|
||||
println!("firing event on {:?}", id);
|
||||
vdom.handle_event(
|
||||
"data",
|
||||
std::rc::Rc::new(String::from("hello world")),
|
||||
id,
|
||||
let event = Event::new(
|
||||
std::rc::Rc::new(String::from("hello world")) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
vdom.runtime().handle_event("data", event, id);
|
||||
}
|
||||
{
|
||||
vdom.render_immediate(&mut InsertEventListenerMutationHandler(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::html::SerializedHtmlEventConverter;
|
||||
use dioxus::prelude::*;
|
||||
use std::any::Any;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -60,12 +61,11 @@ fn events_generate() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
||||
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(1),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(1));
|
||||
|
||||
dom.mark_dirty(ScopeId::APP);
|
||||
let edits = dom.render_immediate_to_vec();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
use dioxus_elements::SerializedHtmlEventConverter;
|
||||
use std::rc::Rc;
|
||||
use std::{any::Any, rc::Rc};
|
||||
|
||||
#[test]
|
||||
fn miri_rollover() {
|
||||
@@ -11,12 +11,11 @@ fn miri_rollover() {
|
||||
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
||||
|
||||
for _ in 0..3 {
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(2),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(2));
|
||||
dom.process_events();
|
||||
_ = dom.render_immediate_to_vec();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dioxus::html::SerializedHtmlEventConverter;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
use std::rc::Rc;
|
||||
use std::{any::Any, rc::Rc};
|
||||
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
|
||||
use tracing_subscriber::{layer::SubscriberExt, Registry};
|
||||
|
||||
@@ -42,12 +42,11 @@ fn basic_tracing() {
|
||||
edited_virtual_dom.assert();
|
||||
|
||||
for _ in 0..3 {
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
|
||||
ElementId(2),
|
||||
let event = Event::new(
|
||||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
||||
true,
|
||||
);
|
||||
dom.runtime().handle_event("click", event, ElementId(2));
|
||||
dom.process_events();
|
||||
_ = dom.render_immediate_to_vec();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user