* 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
70 lines
2.0 KiB
Rust
70 lines
2.0 KiB
Rust
use dioxus_cli_config::{RuntimeCLIArguments, CURRENT_CONFIG};
|
|
use dioxus_core::VirtualDom;
|
|
|
|
use crate::LiveviewRouter;
|
|
|
|
pub(crate) fn app_title() -> String {
|
|
CURRENT_CONFIG
|
|
.as_ref()
|
|
.map(|c| c.web.app.title.clone())
|
|
.unwrap_or_else(|_| "Dioxus Liveview App".to_string())
|
|
}
|
|
|
|
/// A configuration for the LiveView server.
|
|
pub struct Config<R: LiveviewRouter> {
|
|
router: R,
|
|
address: std::net::SocketAddr,
|
|
route: String,
|
|
}
|
|
|
|
impl<R: LiveviewRouter> Default for Config<R> {
|
|
fn default() -> Self {
|
|
let address = RuntimeCLIArguments::from_cli()
|
|
.map(|args| args.fullstack_address().address())
|
|
.unwrap_or(std::net::SocketAddr::V4(std::net::SocketAddrV4::new(
|
|
std::net::Ipv4Addr::new(127, 0, 0, 1),
|
|
8080,
|
|
)));
|
|
Self {
|
|
router: R::create_default_liveview_router(),
|
|
address,
|
|
route: "/".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<R: LiveviewRouter> Config<R> {
|
|
/// Set the route to use for the LiveView server.
|
|
pub fn route(mut self, route: impl Into<String>) -> Self {
|
|
self.route = route.into();
|
|
self
|
|
}
|
|
|
|
/// Create a new configuration for the LiveView server.
|
|
pub fn with_app(mut self, app: fn() -> dioxus_core::prelude::Element) -> Self {
|
|
self.router = self.router.with_app(&self.route, app);
|
|
self
|
|
}
|
|
|
|
/// Create a new configuration for the LiveView server.
|
|
pub fn with_virtual_dom(
|
|
mut self,
|
|
virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static,
|
|
) -> Self {
|
|
self.router = self.router.with_virtual_dom(&self.route, virtual_dom);
|
|
self
|
|
}
|
|
|
|
/// Set the address to listen on.
|
|
pub fn address(mut self, address: impl Into<std::net::SocketAddr>) -> Self {
|
|
self.address = address.into();
|
|
self
|
|
}
|
|
|
|
/// Launch the LiveView server.
|
|
pub async fn launch(self) {
|
|
println!("{} started on http://{}", app_title(), self.address);
|
|
self.router.start(self.address).await
|
|
}
|
|
}
|