Skip to content

Commit 8943039

Browse files
committed
feat: propagate implementation of cancel event
1 parent 24080f3 commit 8943039

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

packages/core-types/src/bubbles.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/// in their definition, which gets passed as part of the mutations.
1111
pub fn event_bubbles(evt: &str) -> bool {
1212
match evt {
13+
"cancel" => false,
1314
"copy" => true,
1415
"cut" => true,
1516
"paste" => true,

packages/depinfo/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ mod tests {
342342
"/dioxus/packages/html/src/attribute_groups.rs",
343343
"/dioxus/packages/html/src/elements.rs",
344344
"/dioxus/packages/html/src/events/animation.rs",
345+
"/dioxus/packages/html/src/events/cancel.rs",
345346
"/dioxus/packages/html/src/events/clipboard.rs",
346347
"/dioxus/packages/html/src/events/composition.rs",
347348
"/dioxus/packages/html/src/events/drag.rs",

packages/desktop/src/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
1717
.into()
1818
}
1919

20+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
21+
event
22+
.downcast::<SerializedCancelData>()
23+
.cloned()
24+
.unwrap()
25+
.into()
26+
}
27+
2028
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
2129
event
2230
.downcast::<SerializedClipboardData>()

packages/html/src/events/cancel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ pub trait HasCancelData: std::any::Any {
8383
impl_event! {
8484
CancelData;
8585

86-
/// onCancel
86+
/// oncancel
8787
oncancel
8888
}

packages/html/src/transit.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ fn deserialize_raw(name: &str, data: &serde_json::Value) -> Result<EventData, se
6565
}
6666

6767
let data = match name {
68+
// Cancel
69+
"cancel" => Cancel(de(data)?),
70+
6871
// Mouse
6972
"click" | "contextmenu" | "dblclick" | "doubleclick" | "mousedown" | "mouseenter"
7073
| "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => Mouse(de(data)?),
@@ -154,6 +157,7 @@ impl HtmlEvent {
154157
#[serde(untagged)]
155158
#[non_exhaustive]
156159
pub enum EventData {
160+
Cancel(SerializedCancelData),
157161
Mouse(SerializedMouseData),
158162
Clipboard(SerializedClipboardData),
159163
Composition(SerializedCompositionData),
@@ -179,6 +183,9 @@ pub enum EventData {
179183
impl EventData {
180184
pub fn into_any(self) -> Rc<dyn Any> {
181185
match self {
186+
EventData::Cancel(data) => {
187+
Rc::new(PlatformEventData::new(Box::new(data))) as Rc<dyn Any>
188+
}
182189
EventData::Mouse(data) => {
183190
Rc::new(PlatformEventData::new(Box::new(data))) as Rc<dyn Any>
184191
}
@@ -291,6 +298,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
291298
.into()
292299
}
293300

301+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
302+
event
303+
.downcast::<SerializedCancelData>()
304+
.cloned()
305+
.unwrap()
306+
.into()
307+
}
308+
294309
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
295310
event
296311
.downcast::<SerializedClipboardData>()

packages/liveview/src/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
1515
.into()
1616
}
1717

18+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
19+
event
20+
.downcast::<SerializedCancelData>()
21+
.cloned()
22+
.unwrap()
23+
.into()
24+
}
25+
1826
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
1927
event
2028
.downcast::<SerializedClipboardData>()

packages/native-dom/src/events.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use dioxus_html::{
55
point_interaction::{
66
InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
77
},
8-
AnimationData, ClipboardData, CompositionData, DragData, FocusData, FormData, FormValue,
9-
HasFileData, HasFocusData, HasFormData, HasKeyboardData, HasMouseData, HtmlEventConverter,
10-
ImageData, KeyboardData, MediaData, MountedData, MouseData, PlatformEventData, PointerData,
11-
ResizeData, ScrollData, SelectionData, ToggleData, TouchData, TransitionData, VisibleData,
12-
WheelData,
8+
AnimationData, CancelData, ClipboardData, CompositionData, DragData, FocusData, FormData,
9+
FormValue, HasFileData, HasFocusData, HasFormData, HasKeyboardData, HasMouseData,
10+
HtmlEventConverter, ImageData, KeyboardData, MediaData, MountedData, MouseData,
11+
PlatformEventData, PointerData, ResizeData, ScrollData, SelectionData, ToggleData, TouchData,
12+
TransitionData, VisibleData, WheelData,
1313
};
1414
use keyboard_types::{Code, Key, Location, Modifiers};
1515
use std::any::Any;
@@ -18,6 +18,10 @@ use std::collections::HashMap;
1818
pub struct NativeConverter {}
1919

2020
impl HtmlEventConverter for NativeConverter {
21+
fn convert_cancel_data(&self, _event: &PlatformEventData) -> CancelData {
22+
todo!("todo: convert_cancel_data in dioxus-native. requires support in blitz")
23+
}
24+
2125
fn convert_form_data(&self, event: &PlatformEventData) -> FormData {
2226
event.downcast::<NativeFormData>().unwrap().clone().into()
2327
}

0 commit comments

Comments
 (0)