Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"packages/extension",
"packages/router",
"packages/html",
"packages/html-events",
"packages/html-internal-macro",
"packages/hooks",
"packages/web",
Expand Down Expand Up @@ -128,6 +129,7 @@ dioxus-router-macro = { path = "packages/router-macro", version = "0.7.4" }
dioxus-document = { path = "packages/document", version = "0.7.4", default-features = false }
dioxus-history = { path = "packages/history", version = "0.7.4", default-features = false }
dioxus-html = { path = "packages/html", version = "0.7.4", default-features = false }
html-events = { path = "packages/html-events", version = "0.7.4", default-features = false }
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.7.4" }
dioxus-hooks = { path = "packages/hooks", version = "0.7.4" }
dioxus-web = { path = "packages/web", version = "0.7.4", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dioxus-asset-resolver = { workspace = true, features = ["native"] }
generational-box = { workspace = true }
dioxus-devtools = { workspace = true, optional = true }

anyhow = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
Expand Down
16 changes: 4 additions & 12 deletions packages/desktop/src/file_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,16 @@ impl NativeFileData for DesktopFileData {
fn read_bytes(
&self,
) -> std::pin::Pin<
Box<
dyn std::future::Future<Output = Result<bytes::Bytes, dioxus_core::CapturedError>>
+ 'static,
>,
Box<dyn std::future::Future<Output = Result<bytes::Bytes, anyhow::Error>> + 'static>,
> {
let path = self.0.clone();
Box::pin(async move { Ok(bytes::Bytes::from(std::fs::read(&path)?)) })
}

fn read_string(
&self,
) -> std::pin::Pin<
Box<dyn std::future::Future<Output = Result<String, dioxus_core::CapturedError>> + 'static>,
> {
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, anyhow::Error>> + 'static>>
{
let path = self.0.clone();
Box::pin(async move { Ok(std::fs::read_to_string(&path)?) })
}
Expand All @@ -454,11 +450,7 @@ impl NativeFileData for DesktopFileData {
fn byte_stream(
&self,
) -> std::pin::Pin<
Box<
dyn futures_util::Stream<Item = Result<bytes::Bytes, dioxus_core::CapturedError>>
+ 'static
+ Send,
>,
Box<dyn futures_util::Stream<Item = Result<bytes::Bytes, anyhow::Error>> + 'static + Send>,
> {
let path = self.0.clone();
Box::pin(futures_util::stream::once(async move {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use crate::{document::DesktopDocument, WeakDesktopContext};
use crate::{element::DesktopElement, file_upload::DesktopFormData};
use base64::prelude::BASE64_STANDARD;
use dioxus_core::{consume_context, provide_context, Runtime, ScopeId, VirtualDom};
use dioxus_core::{consume_context, provide_context, ElementId, Runtime, ScopeId, VirtualDom};
use dioxus_document::Document;
use dioxus_history::{History, MemoryHistory};
use dioxus_hooks::to_owned;
Expand Down Expand Up @@ -105,6 +105,8 @@ impl WebviewEdits {
bubbles,
data,
} = event;
let element = ElementId(element);

let Some(desktop_context) = self.desktop_context.get() else {
tracing::error!(
"Tried to handle event before setting the desktop context on the event handler"
Expand Down
2 changes: 1 addition & 1 deletion packages/dioxus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub mod prelude {
#[cfg_attr(docsrs, doc(cfg(feature = "html")))]
#[doc(no_inline)]
pub use dioxus_elements::{
events::*, extensions::*, global_attributes, keyboard_types, svg_attributes, traits::*,
events::*, extensions::*, global_attributes, keyboard_types, svg_attributes,
GlobalAttributesExtension, SvgAttributesExtension,
};

Expand Down
42 changes: 42 additions & 0 deletions packages/html-events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "html-events"
version = { workspace = true }
authors = ["Jonathan Kelley"]
edition = "2021"
description = "Types/Traits to represent HTML events"
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react"]

[dependencies]
keyboard-types = { workspace = true, default-features = false }
futures-util = { workspace = true }
euclid = "0.22.11"
enumset = "1.1.6"
bytes = { workspace = true }
anyhow = { workspace = true }

# Serialize
serde = { workspace = true, features = ["derive"], optional = true }
serde_repr = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }

[dev-dependencies]
serde_json = { workspace = true }
tracing = { workspace = true }

[features]
default = ["serialize"]
serialize = [
"dep:serde",
"dep:serde_json",
"dep:serde_repr",
"euclid/serde",
"keyboard-types/serde",
"bytes/serde"
]

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
feature = ["html-to-rsx", "hot-reload-context", "html-to-rsx"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use dioxus_core::Event;

pub type AnimationEvent = Event<AnimationData>;

pub struct AnimationData {
inner: Box<dyn HasAnimationData>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use dioxus_core::Event;

pub type CancelEvent = Event<CancelData>;

pub struct CancelData {
inner: Box<dyn HasCancelData>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use dioxus_core::Event;

pub type ClipboardEvent = Event<ClipboardData>;

pub struct ClipboardData {
inner: Box<dyn HasClipboardData>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use dioxus_core::Event;

pub type CompositionEvent = Event<CompositionData>;

pub struct CompositionData {
inner: Box<dyn HasCompositionData>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use crate::{
geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint},
};

use dioxus_core::Event;
use keyboard_types::Modifiers;

use crate::HasMouseData;

pub type DragEvent = Event<DragData>;

/// The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by
/// placing a pointer device (such as a mouse) on the touch surface and then dragging the pointer to a new location
/// (such as another DOM element). Applications are free to interpret a drag and drop interaction in an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use dioxus_core::Event;

pub type FocusEvent = Event<FocusData>;

pub struct FocusData {
inner: Box<dyn HasFocusData>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use crate::file_data::HasFileData;
use crate::FileData;
use std::fmt::Debug;

use dioxus_core::Event;

pub type FormEvent = Event<FormData>;

/* DOMEvent: Send + SyncTarget relatedTarget */
pub struct FormData {
inner: Box<dyn HasFormData>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,25 @@ macro_rules! expand_html_event_converter {
fn $converter(&self, event: &PlatformEventData) -> $data;
)*
}
};
}

macro_rules! expand_from_impls {
(
enum Event {
$(
#[convert = $converter:ident]
#[events = [
$(
$( #[$attr:meta] )*
$name:ident => $raw:ident,
)*
]]
$(#[raw = [$($raw_only:ident),* $(,)?]])?
$group:ident($data:ident),
)*
}
) => {
$(
impl From<&PlatformEventData> for $data {
fn from(val: &PlatformEventData) -> Self {
Expand Down Expand Up @@ -413,36 +431,7 @@ macro_rules! expand_html_event_deserialize {
};
}

macro_rules! expand_html_event_listeners {
(
enum Event {
$(
#[convert = $converter:ident]
#[events = [
$(
$( #[$attr:meta] )*
$name:ident => $raw:ident,
)*
]]
$(#[raw = [$($raw_only:ident),* $(,)?]])?
$group:ident($data:ident),
)*
}
) => {
$(
impl_event! {
$data;
$(
#[doc = concat!(stringify!($name))]
$( #[$attr] )*
$name: concat!("on", stringify!($raw));
)*
}
)*
};
}

with_html_event_groups!(expand_html_event_converter);
#[cfg(feature = "serialize")]
with_html_event_groups!(expand_html_event_deserialize);
with_html_event_groups!(expand_html_event_listeners);
with_html_event_groups!(expand_from_impls);
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use dioxus_core::Event;

pub type ImageEvent = Event<ImageData>;
pub struct ImageData {
inner: Box<dyn HasImageData>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dioxus_core::Event;
use keyboard_types::{Code, Key, Location, Modifiers};
use std::fmt::Debug;

Expand All @@ -14,7 +13,6 @@ where
Ok(Code::deserialize(deserializer).unwrap_or(Code::Unidentified))
}

pub type KeyboardEvent = Event<KeyboardData>;
pub struct KeyboardData {
inner: Box<dyn HasKeyboardData>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use dioxus_core::Event;

pub type MediaEvent = Event<MediaData>;
pub struct MediaData {
inner: Box<dyn HasMediaData>,
}
Expand Down
Loading
Loading