diff --git a/packages/html/Cargo.toml b/packages/html/Cargo.toml
index b06ce3375..7e061855e 100644
--- a/packages/html/Cargo.toml
+++ b/packages/html/Cargo.toml
@@ -16,7 +16,7 @@ serde = { version = "1", features = ["derive"], optional = true }
serde_repr = { version = "0.1", optional = true }
wasm-bindgen = { workspace = true, optional = true }
euclid = "0.22.7"
-enumset = "1.0.11"
+enumset = "1.1.2"
keyboard-types = "0.7"
async-trait = "0.1.58"
serde-value = "0.7.0"
@@ -29,18 +29,18 @@ serde_json = { version = "1", optional = true }
optional = true
version = "0.3.56"
features = [
- "TouchEvent",
- "MouseEvent",
- "InputEvent",
- "ClipboardEvent",
- "KeyboardEvent",
- "TouchEvent",
- "WheelEvent",
- "AnimationEvent",
- "TransitionEvent",
- "PointerEvent",
- "FocusEvent",
- "CompositionEvent",
+ "TouchEvent",
+ "MouseEvent",
+ "InputEvent",
+ "ClipboardEvent",
+ "KeyboardEvent",
+ "TouchEvent",
+ "WheelEvent",
+ "AnimationEvent",
+ "TransitionEvent",
+ "PointerEvent",
+ "FocusEvent",
+ "CompositionEvent",
]
[dev-dependencies]
diff --git a/packages/html/src/events/animation.rs b/packages/html/src/events/animation.rs
index 6b4d398da..02612bc77 100644
--- a/packages/html/src/events/animation.rs
+++ b/packages/html/src/events/animation.rs
@@ -50,7 +50,7 @@ impl PartialEq for AnimationData {
#[cfg(feature = "serialize")]
/// A serialized version of AnimationData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedAnimationData {
animation_name: String,
pseudo_element: String,
diff --git a/packages/html/src/events/clipboard.rs b/packages/html/src/events/clipboard.rs
index 7f945378d..0469c4f1c 100644
--- a/packages/html/src/events/clipboard.rs
+++ b/packages/html/src/events/clipboard.rs
@@ -38,7 +38,7 @@ impl ClipboardData {
#[cfg(feature = "serialize")]
/// A serialized version of ClipboardData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedClipboardData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/composition.rs b/packages/html/src/events/composition.rs
index 41671a077..18ef4f5d1 100644
--- a/packages/html/src/events/composition.rs
+++ b/packages/html/src/events/composition.rs
@@ -38,7 +38,7 @@ impl CompositionData {
#[cfg(feature = "serialize")]
/// A serialized version of CompositionData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedCompositionData {
data: String,
}
diff --git a/packages/html/src/events/drag.rs b/packages/html/src/events/drag.rs
index c8599850f..004ea6612 100644
--- a/packages/html/src/events/drag.rs
+++ b/packages/html/src/events/drag.rs
@@ -99,7 +99,7 @@ impl DragData {
#[cfg(feature = "serialize")]
/// A serialized version of DragData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedDragData {
mouse: crate::point_interaction::SerializedPointInteraction,
}
diff --git a/packages/html/src/events/focus.rs b/packages/html/src/events/focus.rs
index af1da2c59..f96c1eaee 100644
--- a/packages/html/src/events/focus.rs
+++ b/packages/html/src/events/focus.rs
@@ -33,7 +33,7 @@ impl FocusData {
#[cfg(feature = "serialize")]
/// A serialized version of FocusData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Default)]
pub struct SerializedFocusData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/form.rs b/packages/html/src/events/form.rs
index 015559d64..de8bb0dbf 100644
--- a/packages/html/src/events/form.rs
+++ b/packages/html/src/events/form.rs
@@ -78,7 +78,7 @@ pub trait HasFormData: std::any::Any {
#[cfg(feature = "serialize")]
/// A serialized form data object
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedFormData {
value: String,
values: HashMap>,
@@ -172,7 +172,7 @@ impl<'de> serde::Deserialize<'de> for FormData {
#[cfg(feature = "serialize")]
/// A file engine that serializes files to bytes
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedFileEngine {
files: HashMap>,
}
diff --git a/packages/html/src/events/image.rs b/packages/html/src/events/image.rs
index 4e094c925..3c75edbdd 100644
--- a/packages/html/src/events/image.rs
+++ b/packages/html/src/events/image.rs
@@ -43,7 +43,7 @@ impl ImageData {
#[cfg(feature = "serialize")]
/// A serialized version of ImageData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedImageData {
load_error: bool,
}
diff --git a/packages/html/src/events/keyboard.rs b/packages/html/src/events/keyboard.rs
index 74109bea2..2af582089 100644
--- a/packages/html/src/events/keyboard.rs
+++ b/packages/html/src/events/keyboard.rs
@@ -1,6 +1,5 @@
use dioxus_core::Event;
use keyboard_types::{Code, Key, Location, Modifiers};
-use std::convert::TryInto;
use std::fmt::Debug;
#[cfg(feature = "serialize")]
@@ -80,7 +79,7 @@ impl KeyboardData {
#[cfg(feature = "serialize")]
/// A serialized version of KeyboardData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedKeyboardData {
auto_repeating: bool,
#[serde(deserialize_with = "resilient_deserialize_code")]
@@ -90,6 +89,26 @@ pub struct SerializedKeyboardData {
modifiers: Modifiers,
}
+#[cfg(feature = "serialize")]
+impl SerializedKeyboardData {
+ /// Create a new SerializedKeyboardData
+ pub fn new(
+ auto_repeating: bool,
+ code: Code,
+ key: Key,
+ location: Location,
+ modifiers: Modifiers,
+ ) -> Self {
+ Self {
+ auto_repeating,
+ code,
+ key,
+ location,
+ modifiers,
+ }
+ }
+}
+
#[cfg(feature = "serialize")]
impl From<&KeyboardData> for SerializedKeyboardData {
fn from(data: &KeyboardData) -> Self {
@@ -186,6 +205,8 @@ impl<'de> serde::Deserialize<'de> for KeyCode {
where
D: serde::Deserializer<'de>,
{
+ use std::convert::TryInto;
+
// We could be deserializing a unicode character, so we need to use u64 even if the output only takes u8
let value = u64::deserialize(deserializer)?;
diff --git a/packages/html/src/events/media.rs b/packages/html/src/events/media.rs
index 9382e6831..1abcab21d 100644
--- a/packages/html/src/events/media.rs
+++ b/packages/html/src/events/media.rs
@@ -32,7 +32,7 @@ impl MediaData {
#[cfg(feature = "serialize")]
/// A serialized version of MediaData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedMediaData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/mouse.rs b/packages/html/src/events/mouse.rs
index 6c346a434..0e73ef4f6 100644
--- a/packages/html/src/events/mouse.rs
+++ b/packages/html/src/events/mouse.rs
@@ -106,6 +106,13 @@ impl_event! {
}
impl MouseData {
+ /// Create a new instance of MouseData
+ pub fn new(inner: impl HasMouseData + 'static) -> Self {
+ Self {
+ inner: Box::new(inner),
+ }
+ }
+
/// Downcast this event to a concrete event type
pub fn downcast(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::()
@@ -172,23 +179,98 @@ impl PartialEq for MouseData {
}
#[cfg(feature = "serialize")]
-impl HasMouseData for crate::point_interaction::SerializedPointInteraction {
+/// A serialized version of [`MouseData`]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Default)]
+pub struct SerializedMouseData {
+ /// Common data for all pointer/mouse events
+ #[serde(flatten)]
+ point_data: crate::point_interaction::SerializedPointInteraction,
+}
+
+#[cfg(feature = "serialize")]
+impl SerializedMouseData {
+ /// Create a new instance of SerializedMouseData
+ pub fn new(
+ client_coordinates: ClientPoint,
+ element_coordinates: ElementPoint,
+ page_coordinates: PagePoint,
+ screen_coordinates: ScreenPoint,
+ modifiers: Modifiers,
+ held_buttons: MouseButtonSet,
+ trigger_button: Option,
+ ) -> Self {
+ Self {
+ point_data: crate::point_interaction::SerializedPointInteraction::new(
+ client_coordinates,
+ element_coordinates,
+ page_coordinates,
+ screen_coordinates,
+ modifiers,
+ held_buttons,
+ trigger_button,
+ ),
+ }
+ }
+}
+
+#[cfg(feature = "serialize")]
+impl From<&MouseData> for SerializedMouseData {
+ fn from(e: &MouseData) -> Self {
+ Self {
+ point_data: crate::point_interaction::SerializedPointInteraction::from(e),
+ }
+ }
+}
+
+#[cfg(feature = "serialize")]
+impl HasMouseData for SerializedMouseData {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
+#[cfg(feature = "serialize")]
+impl PointInteraction for SerializedMouseData {
+ fn client_coordinates(&self) -> ClientPoint {
+ self.point_data.client_coordinates()
+ }
+
+ fn element_coordinates(&self) -> ElementPoint {
+ self.point_data.element_coordinates()
+ }
+
+ fn page_coordinates(&self) -> PagePoint {
+ self.point_data.page_coordinates()
+ }
+
+ fn screen_coordinates(&self) -> ScreenPoint {
+ self.point_data.screen_coordinates()
+ }
+
+ fn modifiers(&self) -> Modifiers {
+ self.point_data.modifiers()
+ }
+
+ fn held_buttons(&self) -> MouseButtonSet {
+ self.point_data.held_buttons()
+ }
+
+ fn trigger_button(&self) -> Option {
+ self.point_data.trigger_button()
+ }
+}
+
#[cfg(feature = "serialize")]
impl serde::Serialize for MouseData {
fn serialize(&self, serializer: S) -> Result {
- crate::point_interaction::SerializedPointInteraction::from(self).serialize(serializer)
+ SerializedMouseData::from(self).serialize(serializer)
}
}
#[cfg(feature = "serialize")]
impl<'de> serde::Deserialize<'de> for MouseData {
fn deserialize>(deserializer: D) -> Result {
- let data = crate::point_interaction::SerializedPointInteraction::deserialize(deserializer)?;
+ let data = SerializedMouseData::deserialize(deserializer)?;
Ok(Self {
inner: Box::new(data),
})
diff --git a/packages/html/src/events/pointer.rs b/packages/html/src/events/pointer.rs
index cba360679..5540dbe62 100644
--- a/packages/html/src/events/pointer.rs
+++ b/packages/html/src/events/pointer.rs
@@ -209,7 +209,7 @@ impl PointInteraction for PointerData {
#[cfg(feature = "serialize")]
/// A serialized version of PointerData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedPointerData {
/// Common data for all pointer/mouse events
#[serde(flatten)]
diff --git a/packages/html/src/events/scroll.rs b/packages/html/src/events/scroll.rs
index 50be913d2..4655afbcc 100644
--- a/packages/html/src/events/scroll.rs
+++ b/packages/html/src/events/scroll.rs
@@ -33,7 +33,7 @@ impl PartialEq for ScrollData {
#[cfg(feature = "serialize")]
/// A serialized version of ScrollData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedScrollData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/selection.rs b/packages/html/src/events/selection.rs
index 272b3e898..de10b06c4 100644
--- a/packages/html/src/events/selection.rs
+++ b/packages/html/src/events/selection.rs
@@ -33,7 +33,7 @@ impl PartialEq for SelectionData {
#[cfg(feature = "serialize")]
/// A serialized version of SelectionData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedSelectionData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/toggle.rs b/packages/html/src/events/toggle.rs
index f2240bcbf..7de8be36d 100644
--- a/packages/html/src/events/toggle.rs
+++ b/packages/html/src/events/toggle.rs
@@ -33,7 +33,7 @@ impl ToggleData {
#[cfg(feature = "serialize")]
/// A serialized version of ToggleData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedToggleData {}
#[cfg(feature = "serialize")]
diff --git a/packages/html/src/events/touch.rs b/packages/html/src/events/touch.rs
index 4537bce92..7e9009ab6 100644
--- a/packages/html/src/events/touch.rs
+++ b/packages/html/src/events/touch.rs
@@ -60,7 +60,7 @@ impl TouchData {
#[cfg(feature = "serialize")]
/// A serialized version of TouchData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedTouchData {
alt_key: bool,
ctrl_key: bool,
diff --git a/packages/html/src/events/transition.rs b/packages/html/src/events/transition.rs
index 9cd66b761..c6dc65ae1 100644
--- a/packages/html/src/events/transition.rs
+++ b/packages/html/src/events/transition.rs
@@ -39,7 +39,7 @@ impl TransitionData {
#[cfg(feature = "serialize")]
/// A serialized version of TransitionData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedTransitionData {
property_name: String,
pseudo_element: String,
diff --git a/packages/html/src/events/wheel.rs b/packages/html/src/events/wheel.rs
index 87048f4ce..72550d835 100644
--- a/packages/html/src/events/wheel.rs
+++ b/packages/html/src/events/wheel.rs
@@ -44,11 +44,19 @@ impl WheelData {
#[cfg(feature = "serialize")]
/// A serialized version of WheelData
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub struct SerializedWheelData {
delta: WheelDelta,
}
+#[cfg(feature = "serialize")]
+impl SerializedWheelData {
+ /// Create a new SerializedWheelData
+ pub fn new(delta: WheelDelta) -> Self {
+ Self { delta }
+ }
+}
+
#[cfg(feature = "serialize")]
impl From<&WheelData> for SerializedWheelData {
fn from(data: &WheelData) -> Self {
diff --git a/packages/html/src/point_interaction.rs b/packages/html/src/point_interaction.rs
index 1d6301176..0b2230ab3 100644
--- a/packages/html/src/point_interaction.rs
+++ b/packages/html/src/point_interaction.rs
@@ -5,67 +5,6 @@ use crate::{
input_data::{MouseButton, MouseButtonSet},
};
-// #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
-// #[derive(Copy, Clone, Default, PartialEq, Eq)]
-// pub struct PointData {
-// pub alt_key: bool,
-
-// /// The button number that was pressed (if applicable) when the mouse event was fired.
-// pub button: i16,
-
-// /// Indicates which buttons are pressed on the mouse (or other input device) when a mouse event is triggered.
-// ///
-// /// Each button that can be pressed is represented by a given number (see below). If more than one button is pressed, the button values are added together to produce a new number. For example, if the secondary (2) and auxiliary (4) buttons are pressed simultaneously, the value is 6 (i.e., 2 + 4).
-// ///
-// /// - 1: Primary button (usually the left button)
-// /// - 2: Secondary button (usually the right button)
-// /// - 4: Auxiliary button (usually the mouse wheel button or middle button)
-// /// - 8: 4th button (typically the "Browser Back" button)
-// /// - 16 : 5th button (typically the "Browser Forward" button)
-// pub buttons: u16,
-
-// /// The horizontal coordinate within the application's viewport at which the event occurred (as opposed to the coordinate within the page).
-// ///
-// /// For example, clicking on the left edge of the viewport will always result in a mouse event with a clientX value of 0, regardless of whether the page is scrolled horizontally.
-// pub client_x: i32,
-
-// /// The vertical coordinate within the application's viewport at which the event occurred (as opposed to the coordinate within the page).
-// ///
-// /// For example, clicking on the top edge of the viewport will always result in a mouse event with a clientY value of 0, regardless of whether the page is scrolled vertically.
-// pub client_y: i32,
-
-// /// True if the control key was down when the mouse event was fired.
-// pub ctrl_key: bool,
-
-// /// True if the meta key was down when the mouse event was fired.
-// pub meta_key: bool,
-
-// /// The offset in the X coordinate of the mouse pointer between that event and the padding edge of the target node.
-// pub offset_x: i32,
-
-// /// The offset in the Y coordinate of the mouse pointer between that event and the padding edge of the target node.
-// pub offset_y: i32,
-
-// /// The X (horizontal) coordinate (in pixels) of the mouse, relative to the left edge of the entire document. This includes any portion of the document not currently visible.
-// ///
-// /// Being based on the edge of the document as it is, this property takes into account any horizontal scrolling of the page. For example, if the page is scrolled such that 200 pixels of the left side of the document are scrolled out of view, and the mouse is clicked 100 pixels inward from the left edge of the view, the value returned by pageX will be 300.
-// pub page_x: i32,
-
-// /// The Y (vertical) coordinate in pixels of the event relative to the whole document.
-// ///
-// /// See `page_x`.
-// pub page_y: i32,
-
-// /// The X coordinate of the mouse pointer in global (screen) coordinates.
-// pub screen_x: i32,
-
-// /// The Y coordinate of the mouse pointer in global (screen) coordinates.
-// pub screen_y: i32,
-
-// /// True if the shift key was down when the mouse event was fired.
-// pub shift_key: bool,
-// }
-
pub trait PointInteraction: std::any::Any {
/// Gets the coordinates of the pointer event.
fn coordinates(&self) -> Coordinates {
@@ -100,7 +39,7 @@ pub trait PointInteraction: std::any::Any {
}
#[cfg(feature = "serialize")]
-#[derive(serde::Serialize, serde::Deserialize)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Default)]
pub(crate) struct SerializedPointInteraction {
pub(crate) client_coordinates: ClientPoint,
pub(crate) element_coordinates: ElementPoint,
@@ -111,6 +50,30 @@ pub(crate) struct SerializedPointInteraction {
pub(crate) trigger_button: Option,
}
+#[cfg(feature = "serialize")]
+impl SerializedPointInteraction {
+ /// Create a new serialized point interaction.
+ pub fn new(
+ client_coordinates: ClientPoint,
+ element_coordinates: ElementPoint,
+ page_coordinates: PagePoint,
+ screen_coordinates: ScreenPoint,
+ modifiers: Modifiers,
+ held_buttons: MouseButtonSet,
+ trigger_button: Option,
+ ) -> Self {
+ Self {
+ client_coordinates,
+ element_coordinates,
+ page_coordinates,
+ screen_coordinates,
+ modifiers,
+ held_buttons,
+ trigger_button,
+ }
+ }
+}
+
#[cfg(feature = "serialize")]
impl From<&E> for SerializedPointInteraction {
fn from(data: &E) -> Self {
diff --git a/packages/html/src/transit.rs b/packages/html/src/transit.rs
index b27f8670a..b34a4b882 100644
--- a/packages/html/src/transit.rs
+++ b/packages/html/src/transit.rs
@@ -189,7 +189,7 @@ impl EventData {
fn test_back_and_forth() {
let data = HtmlEvent {
element: ElementId(0),
- data: EventData::Mouse(MouseData::default()),
+ data: EventData::Mouse(SerializedMouseData::default().into()),
name: "click".to_string(),
bubbles: true,
};