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:
Evan Almloff authored and GitHub committed 2024-08-13 11:57:54 -07:00
1 parent 8b62b71e2d
commit cab573eefd
54 files changed
+940 -729

No files matched your search

+2 -19
View File
@@ -1,7 +1,6 @@
use crate::{
app::SharedContext,
assets::AssetHandlerRegistry,
edits::EditQueue,
file_upload::NativeFileHover,
ipc::UserWindowEvent,
query::QueryEngine,
@@ -13,11 +12,7 @@ use dioxus_core::{
prelude::{current_scope_id, ScopeId},
VirtualDom,
};
use dioxus_interpreter_js::MutationState;
use std::{
cell::RefCell,
rc::{Rc, Weak},
};
use std::rc::{Rc, Weak};
use tao::{
event::Event,
event_loop::EventLoopWindowTarget,
@@ -63,13 +58,11 @@ pub struct DesktopService {
/// The receiver for queries about the current window
pub(super) query: QueryEngine,
pub(crate) edit_queue: EditQueue,
pub(crate) mutation_state: RefCell<MutationState>,
pub(crate) asset_handlers: AssetHandlerRegistry,
pub(crate) file_hover: NativeFileHover,
#[cfg(target_os = "ios")]
pub(crate) views: Rc<RefCell<Vec<*mut objc::runtime::Object>>>,
pub(crate) views: Rc<std::cell::RefCell<Vec<*mut objc::runtime::Object>>>,
}
/// A smart pointer to the current window.
@@ -86,7 +79,6 @@ impl DesktopService {
webview: WebView,
window: Window,
shared: Rc<SharedContext>,
edit_queue: EditQueue,
asset_handlers: AssetHandlerRegistry,
file_hover: NativeFileHover,
) -> Self {
@@ -94,23 +86,14 @@ impl DesktopService {
window,
webview,
shared,
edit_queue,
asset_handlers,
file_hover,
mutation_state: Default::default(),
query: Default::default(),
#[cfg(target_os = "ios")]
views: Default::default(),
}
}
/// Send a list of mutations to the webview
pub(crate) fn send_edits(&self) {
let mut mutations = self.mutation_state.borrow_mut();
let serialized_edits = mutations.export_memory();
self.edit_queue.add_edits(serialized_edits);
}
/// Create a new window using the props and window builder
///
/// Returns the webview handle for the new window.