chore: iron out all events

This commit is contained in:
Jonathan Kelley 2022-11-21 17:15:17 -08:00
parent 491bf4332d
commit 08ca068d1c
15 changed files with 360 additions and 1645 deletions

File diff suppressed because it is too large Load diff

View file

@ -24,53 +24,126 @@ macro_rules! impl_event {
}; };
} }
mod mouse;
pub use mouse::*;
mod animation; mod animation;
pub use animation::*; mod clipboard;
mod composition; mod composition;
pub use composition::*;
mod drag; mod drag;
pub use drag::*;
mod focus; mod focus;
pub use focus::*;
mod form; mod form;
pub use form::*;
mod image; mod image;
pub use image::*;
mod keyboard; mod keyboard;
pub use keyboard::*;
mod media; mod media;
pub use media::*; mod mouse;
mod pointer; mod pointer;
pub use pointer::*; mod scroll;
mod selection; mod selection;
pub use selection::*;
mod toggle; mod toggle;
pub use toggle::*;
mod touch; mod touch;
pub use touch::*;
mod transition; mod transition;
pub use transition::*;
mod wheel; mod wheel;
pub use animation::*;
pub use clipboard::*;
pub use composition::*;
pub use drag::*;
pub use focus::*;
pub use form::*;
pub use image::*;
pub use keyboard::*;
pub use media::*;
pub use mouse::*;
pub use pointer::*;
pub use scroll::*;
pub use selection::*;
pub use toggle::*;
pub use touch::*;
pub use transition::*;
pub use wheel::*; pub use wheel::*;
mod clipboard; // pub fn event_bubbles(evt: &str) -> bool {
pub use clipboard::*; // match evt {
// "copy" => true,
mod scroll; // "cut" => true,
pub use scroll::*; // "paste" => true,
// "compositionend" => true,
// "compositionstart" => true,
// "compositionupdate" => true,
// "keydown" => true,
// "keypress" => true,
// "keyup" => true,
// "focus" => false,
// "focusout" => true,
// "focusin" => true,
// "blur" => false,
// "change" => true,
// "input" => true,
// "invalid" => true,
// "reset" => true,
// "submit" => true,
// "click" => true,
// "contextmenu" => true,
// "doubleclick" => true,
// "dblclick" => true,
// "drag" => true,
// "dragend" => true,
// "dragenter" => false,
// "dragexit" => false,
// "dragleave" => true,
// "dragover" => true,
// "dragstart" => true,
// "drop" => true,
// "mousedown" => true,
// "mouseenter" => false,
// "mouseleave" => false,
// "mousemove" => true,
// "mouseout" => true,
// "scroll" => false,
// "mouseover" => true,
// "mouseup" => true,
// "pointerdown" => true,
// "pointermove" => true,
// "pointerup" => true,
// "pointercancel" => true,
// "gotpointercapture" => true,
// "lostpointercapture" => true,
// "pointerenter" => false,
// "pointerleave" => false,
// "pointerover" => true,
// "pointerout" => true,
// "select" => true,
// "touchcancel" => true,
// "touchend" => true,
// "touchmove" => true,
// "touchstart" => true,
// "wheel" => true,
// "abort" => false,
// "canplay" => false,
// "canplaythrough" => false,
// "durationchange" => false,
// "emptied" => false,
// "encrypted" => true,
// "ended" => false,
// "error" => false,
// "loadeddata" => false,
// "loadedmetadata" => false,
// "loadstart" => false,
// "pause" => false,
// "play" => false,
// "playing" => false,
// "progress" => false,
// "ratechange" => false,
// "seeked" => false,
// "seeking" => false,
// "stalled" => false,
// "suspend" => false,
// "timeupdate" => false,
// "volumechange" => false,
// "waiting" => false,
// "animationstart" => true,
// "animationend" => true,
// "animationiteration" => true,
// "transitionend" => true,
// "toggle" => true,
// _ => panic!("unsupported event type {:?}", evt),
// }
// }

View file

@ -9,3 +9,16 @@ pub struct AnimationData {
pub pseudo_element: String, pub pseudo_element: String,
pub elapsed_time: f32, pub elapsed_time: f32,
} }
impl_event! [
AnimationData;
/// onanimationstart
onanimationstart
/// onanimationend
onanimationend
/// onanimationiteration
onanimationiteration
];

View file

@ -6,3 +6,16 @@ pub type ClipboardEvent = UiEvent<ClipboardData>;
pub struct ClipboardData { pub struct ClipboardData {
// DOMDataTransfer clipboardData // DOMDataTransfer clipboardData
} }
impl_event![
ClipboardData;
/// oncopy
oncopy
/// oncut
oncut
/// onpaste
onpaste
];

View file

@ -6,3 +6,16 @@ pub type CompositionEvent = UiEvent<CompositionData>;
pub struct CompositionData { pub struct CompositionData {
pub data: String, pub data: String,
} }
impl_event! [
CompositionData;
/// oncompositionstart
oncompositionstart
/// oncompositionend
oncompositionend
/// oncompositionupdate
oncompositionupdate
];

View file

@ -0,0 +1,47 @@
use std::any::Any;
use dioxus_core::UiEvent;
use crate::MouseData;
pub type DragEvent = UiEvent<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
/// application-specific way.
pub struct DragData {
/// Inherit mouse data
pub mouse: MouseData,
/// And then add the rest of the drag data
pub data: Box<dyn Any>,
}
impl_event! {
DragData;
/// ondrag
ondrag
/// ondragend
ondragend
/// ondragenter
ondragenter
/// ondragexit
ondragexit
/// ondragleave
ondragleave
/// ondragover
ondragover
/// ondragstart
ondragstart
/// ondrop
ondrop
}

View file

@ -6,3 +6,13 @@ pub type ImageEvent = UiEvent<ImageData>;
pub struct ImageData { pub struct ImageData {
pub load_error: bool, pub load_error: bool,
} }
impl_event! [
ImageData;
/// onerror
onerror
/// onload
onload
];

View file

@ -4,3 +4,78 @@ pub type MediaEvent = UiEvent<MediaData>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MediaData {} pub struct MediaData {}
impl_event! [
MediaData;
///abort
onabort
///canplay
oncanplay
///canplaythrough
oncanplaythrough
///durationchange
ondurationchange
///emptied
onemptied
///encrypted
onencrypted
///ended
onended
// todo: this conflicts with image events
// neither have data, so it's okay
// ///error
// onerror
///loadeddata
onloadeddata
///loadedmetadata
onloadedmetadata
///loadstart
onloadstart
///pause
onpause
///play
onplay
///playing
onplaying
///progress
onprogress
///ratechange
onratechange
///seeked
onseeked
///seeking
onseeking
///stalled
onstalled
///suspend
onsuspend
///timeupdate
ontimeupdate
///volumechange
onvolumechange
///waiting
onwaiting
];

View file

@ -125,30 +125,6 @@ impl_event! {
/// ondoubleclick /// ondoubleclick
ondblclick ondblclick
/// ondrag
ondrag
/// ondragend
ondragend
/// ondragenter
ondragenter
/// ondragexit
ondragexit
/// ondragleave
ondragleave
/// ondragover
ondragover
/// ondragstart
ondragstart
/// ondrop
ondrop
/// onmousedown /// onmousedown
onmousedown onmousedown

View file

@ -29,3 +29,36 @@ pub struct PointerData {
pub is_primary: bool, pub is_primary: bool,
// pub get_modifier_state: bool, // pub get_modifier_state: bool,
} }
impl_event![
PointerData;
/// pointerdown
onpointerdown
/// pointermove
onpointermove
/// pointerup
onpointerup
/// pointercancel
onpointercancel
/// gotpointercapture
ongotpointercapture
/// lostpointercapture
onlostpointercapture
/// pointerenter
onpointerenter
/// pointerleave
onpointerleave
/// pointerover
onpointerover
/// pointerout
onpointerout
];

View file

@ -4,3 +4,10 @@ pub type ScrollEvent = UiEvent<ScrollData>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ScrollData {} pub struct ScrollData {}
impl_event! {
ScrollData;
/// onscroll
onscroll
}

View file

@ -4,3 +4,16 @@ pub type SelectionEvent = UiEvent<SelectionData>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SelectionData {} pub struct SelectionData {}
impl_event! [
SelectionData;
/// select
onselect
/// selectstart
onselectstart
/// selectionchange
onselectionchange
];

View file

@ -4,3 +4,10 @@ pub type ToggleEvent = UiEvent<ToggleData>;
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ToggleData {} pub struct ToggleData {}
impl_event! {
ToggleData;
/// ontoggle
ontoggle
}

View file

@ -13,3 +13,18 @@ pub struct TouchData {
// targetTouches: DOMTouchList, // targetTouches: DOMTouchList,
// touches: DOMTouchList, // touches: DOMTouchList,
} }
impl_event! {
TouchData;
/// touchstart
ontouchstart
/// touchmove
ontouchmove
/// touchend
ontouchend
/// touchcancel
ontouchcancel
}

View file

@ -8,3 +8,10 @@ pub struct TransitionData {
pub pseudo_element: String, pub pseudo_element: String,
pub elapsed_time: f32, pub elapsed_time: f32,
} }
impl_event! {
TransitionData;
/// transitionend
ontransitionend
}