Merge pull request #30 from lpotthast/main

This commit is contained in:
Marc-Stefan Cassola 2023-09-13 14:35:19 +01:00 committed by GitHub
commit 7f0ddc830f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 26 deletions

View file

@ -1,11 +1,10 @@
#![cfg_attr(feature = "ssr", allow(unused_variables, unused_imports))]
use crate::use_event_listener_with_options;
use crate::{use_event_listener_with_options, UseEventListenerOptions};
use cfg_if::cfg_if;
use leptos::ev::{blur, focus};
use leptos::html::{AnyElement, ToHtmlElement};
use leptos::*;
use web_sys::AddEventListenerOptions;
/// Reactive `document.activeElement`
///
@ -49,8 +48,8 @@ pub fn use_active_element() -> Signal<Option<HtmlElement<AnyElement>>> {
let (active_element, set_active_element) = create_signal(get_active_element());
cfg_if! { if #[cfg(not(feature = "ssr"))] {
let mut listener_options = AddEventListenerOptions::new();
listener_options.capture(true);
let listener_options = UseEventListenerOptions::default()
.capture(true);
let _ = use_event_listener_with_options(
window(),
@ -62,7 +61,7 @@ pub fn use_active_element() -> Signal<Option<HtmlElement<AnyElement>>> {
set_active_element.update(|el| *el = get_active_element());
},
listener_options.clone(),
listener_options,
);
let _ = use_event_listener_with_options(

View file

@ -80,7 +80,7 @@ where
}
};
let mut listener_options = UseEventListenerOptions::default().passive(true);
let listener_options = UseEventListenerOptions::default().passive(true);
let _ = use_event_listener_with_options(
el.clone(),

View file

@ -1,14 +1,13 @@
#![cfg_attr(feature = "ssr", allow(unused_variables, unused_imports))]
use crate::core::{ElementMaybeSignal, Position};
use crate::use_event_listener_with_options;
use crate::{use_event_listener_with_options, UseEventListenerOptions};
use cfg_if::cfg_if;
use default_struct_builder::DefaultBuilder;
use leptos::ev::{dragover, mousemove, touchend, touchmove, touchstart};
use leptos::*;
use std::marker::PhantomData;
use wasm_bindgen::{JsCast, JsValue};
use web_sys::AddEventListenerOptions;
/// Reactive mouse position
///
@ -158,40 +157,40 @@ where
cfg_if! { if #[cfg(not(feature = "ssr"))] {
let target = options.target;
let mut event_listener_options = AddEventListenerOptions::new();
event_listener_options.passive(true);
let event_listener_options = UseEventListenerOptions::default()
.passive(true);
let _ = use_event_listener_with_options(
target.clone(),
mousemove,
mouse_handler,
event_listener_options.clone(),
event_listener_options,
);
let _ = use_event_listener_with_options(
target.clone(),
dragover,
drag_handler,
event_listener_options.clone(),
event_listener_options,
);
if options.touch && !matches!(options.coord_type, UseMouseCoordType::Movement) {
let _ = use_event_listener_with_options(
target.clone(),
touchstart,
touch_handler.clone(),
event_listener_options.clone(),
event_listener_options,
);
let _ = use_event_listener_with_options(
target.clone(),
touchmove,
touch_handler,
event_listener_options.clone(),
event_listener_options,
);
if options.reset_on_touch_ends {
let _ = use_event_listener_with_options(
target,
touchend,
move |_| reset(),
event_listener_options.clone(),
event_listener_options,
);
}
}

View file

@ -1,6 +1,6 @@
use crate::core::ElementMaybeSignal;
use crate::use_event_listener::use_event_listener_with_options;
use crate::{use_debounce_fn_with_arg, use_throttle_fn_with_arg_and_options, ThrottleOptions};
use crate::{use_debounce_fn_with_arg, use_throttle_fn_with_arg_and_options, ThrottleOptions, UseEventListenerOptions};
use cfg_if::cfg_if;
use default_struct_builder::DefaultBuilder;
use leptos::ev::scrollend;
@ -377,7 +377,7 @@ where
target,
ev::scroll,
handler,
options.event_listener_options.clone().unwrap_or_default(),
options.event_listener_options.unwrap_or_default(),
);
} else {
let _ = use_event_listener_with_options::<
@ -389,7 +389,7 @@ where
target,
ev::scroll,
on_scroll_handler,
options.event_listener_options.clone().unwrap_or_default(),
options.event_listener_options.unwrap_or_default(),
);
}
@ -454,7 +454,7 @@ pub struct UseScrollOptions {
/// Options passed to the `addEventListener("scroll", ...)` call
#[builder(into)]
event_listener_options: Option<web_sys::AddEventListenerOptions>,
event_listener_options: Option<UseEventListenerOptions>,
/// When changing the `x` or `y` signals this specifies the scroll behaviour.
/// Can be `Auto` (= not smooth) or `Smooth`. Defaults to `Auto`.

View file

@ -1,10 +1,9 @@
#![cfg_attr(feature = "ssr", allow(unused_variables, unused_imports))]
use crate::use_event_listener_with_options;
use crate::{use_event_listener_with_options, UseEventListenerOptions};
use cfg_if::cfg_if;
use leptos::ev::scroll;
use leptos::*;
use web_sys::AddEventListenerOptions;
/// Reactive window scroll.
///
@ -41,10 +40,6 @@ pub fn use_window_scroll() -> (Signal<f64>, Signal<f64>) {
let (y, set_y) = create_signal(initial_y);
cfg_if! { if #[cfg(not(feature = "ssr"))] {
let mut options = AddEventListenerOptions::new();
options.capture(false);
options.passive(true);
let _ = use_event_listener_with_options(
window(),
scroll,
@ -52,7 +47,9 @@ pub fn use_window_scroll() -> (Signal<f64>, Signal<f64>) {
set_x.set(window().scroll_x().unwrap_or_default());
set_y.set(window().scroll_y().unwrap_or_default());
},
options,
UseEventListenerOptions::default()
.capture(false)
.passive(true),
);
}}