mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-22 16:49:22 -05:00
Merge pull request #146 from carloskiki/mouse-coord-type
Rework of `UseMouseCoordType`
This commit is contained in:
commit
30e6c9351b
4 changed files with 20 additions and 13 deletions
|
@ -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 🍕
|
||||
|
|
|
@ -59,6 +59,7 @@ where
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
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 || {
|
||||
|
|
|
@ -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<T>,
|
||||
}
|
||||
|
||||
impl Default for UseMouseOptions<UseWindow, web_sys::Window, UseMouseEventExtractorDefault> {
|
||||
impl Default for UseMouseOptions<UseWindow, web_sys::Window, Infallible> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
coord_type: UseMouseCoordType::<UseMouseEventExtractorDefault>::default(),
|
||||
coord_type: UseMouseCoordType::default(),
|
||||
target: use_window(),
|
||||
touch: true,
|
||||
reset_on_touch_ends: false,
|
||||
|
@ -253,7 +254,7 @@ pub enum UseMouseCoordType<E: UseMouseEventExtractor + Clone> {
|
|||
Custom(E),
|
||||
}
|
||||
|
||||
impl Default for UseMouseCoordType<UseMouseEventExtractorDefault> {
|
||||
impl Default for UseMouseCoordType<Infallible> {
|
||||
fn default() -> Self {
|
||||
Self::Page
|
||||
}
|
||||
|
@ -297,10 +298,15 @@ impl<E: UseMouseEventExtractor + Clone> 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 {
|
||||
|
|
|
@ -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<T>,
|
||||
}
|
||||
|
||||
impl Default
|
||||
for UseMouseInElementOptions<UseWindow, web_sys::Window, UseMouseEventExtractorDefault>
|
||||
{
|
||||
impl Default for UseMouseInElementOptions<UseWindow, web_sys::Window, Infallible> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
coord_type: UseMouseCoordType::<UseMouseEventExtractorDefault>::default(),
|
||||
coord_type: UseMouseCoordType::default(),
|
||||
target: use_window(),
|
||||
touch: true,
|
||||
reset_on_touch_ends: false,
|
||||
|
|
Loading…
Add table
Reference in a new issue