Merge pull request #146 from carloskiki/mouse-coord-type

Rework of `UseMouseCoordType`
This commit is contained in:
Marc-Stefan Cassola 2024-08-14 03:31:46 +01:00 committed by GitHub
commit 30e6c9351b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 13 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated to web_sys 0.3.70 which unfortunately is breaking some things. - Updated to web_sys 0.3.70 which unfortunately is breaking some things.
- `use_clipboard` doesn't need the unstable flags anymore. - `use_clipboard` doesn't need the unstable flags anymore.
- `use_locale` now uses `unic_langid::LanguageIdentifier` and proper locale matching (thanks to @mondeja). - `use_locale` now uses `unic_langid::LanguageIdentifier` and proper locale matching (thanks to @mondeja).
- Removed `UseMouseEventExtractorDefault` and reworked `UseMouseCoordType` (thanks to @carloskiki)
- `use_preferred_dark` and `use_color_mode` now try to read the `Sec-CH-Prefers-Color-Scheme` header in SSR. - `use_preferred_dark` and `use_color_mode` now try to read the `Sec-CH-Prefers-Color-Scheme` header in SSR.
### Fixes 🍕 ### Fixes 🍕

View file

@ -58,7 +58,8 @@ where
.map(|l| l.as_ref().clone()) .map(|l| l.as_ref().clone())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
const EMPTY_ERR_MSG: & str = "Empty supported list. You have to provide at least one locale in the `supported` parameter"; const EMPTY_ERR_MSG: &str = "Empty supported list. You have to provide at least one locale in the `supported` parameter";
assert!(!supported.is_empty(), "{}", EMPTY_ERR_MSG); assert!(!supported.is_empty(), "{}", EMPTY_ERR_MSG);
Signal::derive(move || { Signal::derive(move || {

View file

@ -6,6 +6,7 @@ use cfg_if::cfg_if;
use default_struct_builder::DefaultBuilder; use default_struct_builder::DefaultBuilder;
use leptos::ev::{dragover, mousemove, touchend, touchmove, touchstart}; use leptos::ev::{dragover, mousemove, touchend, touchmove, touchstart};
use leptos::*; use leptos::*;
use std::convert::Infallible;
use std::marker::PhantomData; use std::marker::PhantomData;
use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen::{JsCast, JsValue};
@ -230,10 +231,10 @@ where
_marker: PhantomData<T>, _marker: PhantomData<T>,
} }
impl Default for UseMouseOptions<UseWindow, web_sys::Window, UseMouseEventExtractorDefault> { impl Default for UseMouseOptions<UseWindow, web_sys::Window, Infallible> {
fn default() -> Self { fn default() -> Self {
Self { Self {
coord_type: UseMouseCoordType::<UseMouseEventExtractorDefault>::default(), coord_type: UseMouseCoordType::default(),
target: use_window(), target: use_window(),
touch: true, touch: true,
reset_on_touch_ends: false, reset_on_touch_ends: false,
@ -253,7 +254,7 @@ pub enum UseMouseCoordType<E: UseMouseEventExtractor + Clone> {
Custom(E), Custom(E),
} }
impl Default for UseMouseCoordType<UseMouseEventExtractorDefault> { impl Default for UseMouseCoordType<Infallible> {
fn default() -> Self { fn default() -> Self {
Self::Page Self::Page
} }
@ -297,10 +298,15 @@ impl<E: UseMouseEventExtractor + Clone> UseMouseEventExtractor for UseMouseCoord
} }
} }
#[derive(Clone)] impl UseMouseEventExtractor for Infallible {
pub struct UseMouseEventExtractorDefault; fn extract_mouse_coords(&self, _: &web_sys::MouseEvent) -> Option<(f64, f64)> {
unreachable!()
}
impl UseMouseEventExtractor for UseMouseEventExtractorDefault {} fn extract_touch_coords(&self, _: &web_sys::Touch) -> Option<(f64, f64)> {
unreachable!()
}
}
/// Return type of [`use_mouse`]. /// Return type of [`use_mouse`].
pub struct UseMouseReturn { pub struct UseMouseReturn {

View file

@ -1,11 +1,12 @@
use crate::core::{ElementMaybeSignal, Position}; use crate::core::{ElementMaybeSignal, Position};
use crate::{ use crate::{
use_mouse_with_options, use_window, UseMouseCoordType, UseMouseEventExtractor, use_mouse_with_options, use_window, UseMouseCoordType, UseMouseEventExtractor, UseMouseOptions,
UseMouseEventExtractorDefault, UseMouseOptions, UseMouseReturn, UseMouseSourceType, UseWindow, UseMouseReturn, UseMouseSourceType, UseWindow,
}; };
use cfg_if::cfg_if; use cfg_if::cfg_if;
use default_struct_builder::DefaultBuilder; use default_struct_builder::DefaultBuilder;
use leptos::*; use leptos::*;
use std::convert::Infallible;
use std::marker::PhantomData; use std::marker::PhantomData;
/// Reactive mouse position related to an element. /// Reactive mouse position related to an element.
@ -195,12 +196,10 @@ where
_marker: PhantomData<T>, _marker: PhantomData<T>,
} }
impl Default impl Default for UseMouseInElementOptions<UseWindow, web_sys::Window, Infallible> {
for UseMouseInElementOptions<UseWindow, web_sys::Window, UseMouseEventExtractorDefault>
{
fn default() -> Self { fn default() -> Self {
Self { Self {
coord_type: UseMouseCoordType::<UseMouseEventExtractorDefault>::default(), coord_type: UseMouseCoordType::default(),
target: use_window(), target: use_window(),
touch: true, touch: true,
reset_on_touch_ends: false, reset_on_touch_ends: false,