diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0ca13..0dee1f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. - `use_clipboard` doesn't need the unstable flags anymore. - `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. ### Fixes 🍕 diff --git a/src/use_locale.rs b/src/use_locale.rs index ff69e7f..76b1274 100644 --- a/src/use_locale.rs +++ b/src/use_locale.rs @@ -58,7 +58,8 @@ where .map(|l| l.as_ref().clone()) .collect::>(); - 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); Signal::derive(move || { diff --git a/src/use_mouse.rs b/src/use_mouse.rs index 74f943f..337523c 100644 --- a/src/use_mouse.rs +++ b/src/use_mouse.rs @@ -6,6 +6,7 @@ use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::ev::{dragover, mousemove, touchend, touchmove, touchstart}; use leptos::*; +use std::convert::Infallible; use std::marker::PhantomData; use wasm_bindgen::{JsCast, JsValue}; @@ -230,10 +231,10 @@ where _marker: PhantomData, } -impl Default for UseMouseOptions { +impl Default for UseMouseOptions { fn default() -> Self { Self { - coord_type: UseMouseCoordType::::default(), + coord_type: UseMouseCoordType::default(), target: use_window(), touch: true, reset_on_touch_ends: false, @@ -253,7 +254,7 @@ pub enum UseMouseCoordType { Custom(E), } -impl Default for UseMouseCoordType { +impl Default for UseMouseCoordType { fn default() -> Self { Self::Page } @@ -297,10 +298,15 @@ impl UseMouseEventExtractor for UseMouseCoord } } -#[derive(Clone)] -pub struct UseMouseEventExtractorDefault; +impl UseMouseEventExtractor for Infallible { + 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`]. pub struct UseMouseReturn { diff --git a/src/use_mouse_in_element.rs b/src/use_mouse_in_element.rs index 29ad0f9..c3d23ae 100644 --- a/src/use_mouse_in_element.rs +++ b/src/use_mouse_in_element.rs @@ -1,11 +1,12 @@ use crate::core::{ElementMaybeSignal, Position}; use crate::{ - use_mouse_with_options, use_window, UseMouseCoordType, UseMouseEventExtractor, - UseMouseEventExtractorDefault, UseMouseOptions, UseMouseReturn, UseMouseSourceType, UseWindow, + use_mouse_with_options, use_window, UseMouseCoordType, UseMouseEventExtractor, UseMouseOptions, + UseMouseReturn, UseMouseSourceType, UseWindow, }; use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::*; +use std::convert::Infallible; use std::marker::PhantomData; /// Reactive mouse position related to an element. @@ -195,12 +196,10 @@ where _marker: PhantomData, } -impl Default - for UseMouseInElementOptions -{ +impl Default for UseMouseInElementOptions { fn default() -> Self { Self { - coord_type: UseMouseCoordType::::default(), + coord_type: UseMouseCoordType::default(), target: use_window(), touch: true, reset_on_touch_ends: false,