From 294cbaf222257f49104f60463a5ba858d2e0153a Mon Sep 17 00:00:00 2001 From: Maccesch Date: Tue, 13 Aug 2024 02:10:35 +0100 Subject: [PATCH] updated to latest version of web_sys --- Cargo.toml | 4 ++-- src/use_clipboard.rs | 18 ++++++++---------- src/use_event_listener.rs | 8 ++++---- src/use_event_source.rs | 4 ++-- src/use_mutation_observer.rs | 16 ++++++++-------- src/use_resize_observer.rs | 4 ++-- src/use_web_notification.rs | 21 ++++++++++----------- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 870af1a..6a18c69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-use" -version = "0.11.4" +version = "0.11.5" edition = "2021" authors = ["Marc-Stefan Cassola"] categories = ["gui", "web-programming"] @@ -37,7 +37,7 @@ wasm-bindgen = "0.2.92" wasm-bindgen-futures = "0.4" [dependencies.web-sys] -version = "0.3" +version = ">=0.3.70" features = [ "AddEventListenerOptions", "BinaryType", diff --git a/src/use_clipboard.rs b/src/use_clipboard.rs index c6f1efe..f33cfd6 100644 --- a/src/use_clipboard.rs +++ b/src/use_clipboard.rs @@ -79,10 +79,9 @@ pub fn use_clipboard_with_options( let update_text = move |_| { if is_supported.get() { spawn_local(async move { - if let Some(clipboard) = window().navigator().clipboard() { - if let Ok(text) = js_fut!(clipboard.read_text()).await { - set_text.set(text.as_string()); - } + let clipboard = window().navigator().clipboard(); + if let Ok(text) = js_fut!(clipboard.read_text()).await { + set_text.set(text.as_string()); } }) } @@ -102,12 +101,11 @@ pub fn use_clipboard_with_options( let value = value.to_owned(); spawn_local(async move { - if let Some(clipboard) = window().navigator().clipboard() { - if js_fut!(clipboard.write_text(&value)).await.is_ok() { - set_text.set(Some(value)); - set_copied.set(true); - start(()); - } + let clipboard = window().navigator().clipboard(); + if js_fut!(clipboard.write_text(&value)).await.is_ok() { + set_text.set(Some(value)); + set_copied.set(true); + start(()); } }); } diff --git a/src/use_event_listener.rs b/src/use_event_listener.rs index 68ff33d..8f35a51 100644 --- a/src/use_event_listener.rs +++ b/src/use_event_listener.rs @@ -235,11 +235,11 @@ impl UseEventListenerOptions { passive, } = self; - let mut options = web_sys::AddEventListenerOptions::new(); - options.capture(*capture); - options.once(*once); + let options = web_sys::AddEventListenerOptions::new(); + options.set_capture(*capture); + options.set_once(*once); if let Some(passive) = passive { - options.passive(*passive); + options.set_passive(*passive); } options diff --git a/src/use_event_source.rs b/src/use_event_source.rs index 7cf049b..09539e7 100644 --- a/src/use_event_source.rs +++ b/src/use_event_source.rs @@ -183,8 +183,8 @@ where return; } - let mut event_src_opts = web_sys::EventSourceInit::new(); - event_src_opts.with_credentials(with_credentials); + let event_src_opts = web_sys::EventSourceInit::new(); + event_src_opts.set_with_credentials(with_credentials); let es = web_sys::EventSource::new_with_event_source_init_dict(&url, &event_src_opts) .unwrap_throw(); diff --git a/src/use_mutation_observer.rs b/src/use_mutation_observer.rs index c165c09..813ce4f 100644 --- a/src/use_mutation_observer.rs +++ b/src/use_mutation_observer.rs @@ -214,20 +214,20 @@ impl From for web_sys::MutationObserverInit { character_data_old_value, } = val; - let mut init = Self::new(); + let init = Self::new(); - init.subtree(subtree) - .child_list(child_list) - .attributes(attributes) - .attribute_old_value(attribute_old_value) - .character_data_old_value(character_data_old_value); + init.set_subtree(subtree); + init.set_child_list(child_list); + init.set_attributes(attributes); + init.set_attribute_old_value(attribute_old_value); + init.set_character_data_old_value(character_data_old_value); if let Some(attribute_filter) = attribute_filter { let array = js_sys::Array::from_iter(attribute_filter.into_iter().map(JsValue::from)); - init.attribute_filter(array.unchecked_ref()); + init.set_attribute_filter(array.unchecked_ref()); } if let Some(character_data) = character_data { - init.character_data(character_data); + init.set_character_data(character_data); } init diff --git a/src/use_resize_observer.rs b/src/use_resize_observer.rs index 3a631ca..154f3c2 100644 --- a/src/use_resize_observer.rs +++ b/src/use_resize_observer.rs @@ -171,8 +171,8 @@ pub struct UseResizeObserverOptions { impl From for web_sys::ResizeObserverOptions { fn from(val: UseResizeObserverOptions) -> Self { - let mut options = web_sys::ResizeObserverOptions::new(); - options.box_( + let options = web_sys::ResizeObserverOptions::new(); + options.set_box( val.box_ .unwrap_or(web_sys::ResizeObserverBoxOptions::ContentBox), ); diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 9d396c9..b73ff14 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -318,32 +318,31 @@ impl Default for UseWebNotificationOptions { impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { fn from(options: &UseWebNotificationOptions) -> Self { - let mut web_sys_options = Self::new(); + let web_sys_options = Self::new(); - web_sys_options - .dir(options.direction.into()) - .require_interaction(options.require_interaction) - .renotify(options.renotify) - .silent(options.silent); + web_sys_options.set_dir(options.direction.into()); + web_sys_options.set_require_interaction(options.require_interaction); + web_sys_options.set_renotify(options.renotify); + web_sys_options.set_silent(options.silent); if let Some(body) = &options.body { - web_sys_options.body(body); + web_sys_options.set_body(body); } if let Some(icon) = &options.icon { - web_sys_options.icon(icon); + web_sys_options.set_icon(icon); } if let Some(image) = &options.image { - web_sys_options.image(image); + web_sys_options.set_image(image); } if let Some(language) = &options.language { - web_sys_options.lang(language); + web_sys_options.set_lang(language); } if let Some(tag) = &options.tag { - web_sys_options.tag(tag); + web_sys_options.set_tag(tag); } web_sys_options