From e35a09148f23cd0effee4f0ccd5c657c73646f98 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Wed, 9 Oct 2024 21:35:25 +0200 Subject: [PATCH] made use_drop_zone usable again --- examples/Cargo.toml | 2 +- src/use_active_element.rs | 2 +- src/use_drop_zone.rs | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5d3a9b5..41f7055 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -23,6 +23,7 @@ members = [ "use_display_media", "use_document_visibility", "use_draggable", + "use_drop_zone", "use_element_bounding", "use_element_hover", "use_element_size", @@ -69,7 +70,6 @@ members = [ "watch_debounced", "watch_pausable", "watch_throttled", - # "use_drop_zone", # "use_webtransport", ] diff --git a/src/use_active_element.rs b/src/use_active_element.rs index 1d284b8..4a1342b 100644 --- a/src/use_active_element.rs +++ b/src/use_active_element.rs @@ -21,7 +21,7 @@ use leptos::prelude::*; /// # fn Demo() -> impl IntoView { /// let active_element = use_active_element(); /// -/// create_effect(move |_| { +/// Effect::new(move || { /// log!("focus changed to {:?}", active_element.get()); /// }); /// # diff --git a/src/use_drop_zone.rs b/src/use_drop_zone.rs index e873b1f..b733430 100644 --- a/src/use_drop_zone.rs +++ b/src/use_drop_zone.rs @@ -3,6 +3,7 @@ use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::prelude::*; use leptos::reactive::wrappers::read::Signal; +use send_wrapper::SendWrapper; use std::fmt::{Debug, Formatter}; use std::sync::Arc; @@ -69,10 +70,12 @@ where El: IntoElementMaybeSignal, { let (is_over_drop_zone, set_over_drop_zone) = signal(false); - let (files, set_files) = signal_local(Vec::::new()); + let (files, set_files) = signal(Vec::>::new()); #[cfg(not(feature = "ssr"))] { + use std::ops::Deref; + let UseDropZoneOptions { on_drop, on_enter, @@ -90,6 +93,7 @@ where .unwrap_or_default() .into_iter() .map(web_sys::File::from) + .map(SendWrapper::new) .collect(); set_files.update(move |f| *f = files); @@ -109,7 +113,8 @@ where let _z = leptos::reactive::diagnostics::SpecialNonReactiveZone::enter(); on_enter(UseDropZoneEvent { - files: files.get_untracked().into_iter().collect(), + files: files + .with_untracked(|files| files.into_iter().map(|f| f.deref().clone()).collect()), event, }); }); @@ -122,7 +127,8 @@ where let _z = leptos::reactive::diagnostics::SpecialNonReactiveZone::enter(); on_over(UseDropZoneEvent { - files: files.get_untracked().into_iter().collect(), + files: files + .with_untracked(|files| files.into_iter().map(|f| f.deref().clone()).collect()), event, }); }); @@ -140,7 +146,8 @@ where let _z = leptos::reactive::diagnostics::SpecialNonReactiveZone::enter(); on_leave(UseDropZoneEvent { - files: files.get_untracked().into_iter().collect(), + files: files + .with_untracked(|files| files.into_iter().map(|f| f.deref().clone()).collect()), event, }); }); @@ -156,7 +163,8 @@ where let _z = leptos::reactive::diagnostics::SpecialNonReactiveZone::enter(); on_drop(UseDropZoneEvent { - files: files.get_untracked().into_iter().collect(), + files: files + .with_untracked(|files| files.into_iter().map(|f| f.deref().clone()).collect()), event, }); }); @@ -211,7 +219,7 @@ pub struct UseDropZoneEvent { /// Return type of [`use_drop_zone`]. pub struct UseDropZoneReturn { /// Files being handled - pub files: Signal, LocalStorage>, + pub files: Signal>>, /// Whether the files (dragged by the pointer) are over the drop zone pub is_over_drop_zone: Signal, }