From 9cb0e386aabfb28f65d4b5254179d8ca337d3703 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 21 Aug 2024 21:25:24 -0400 Subject: [PATCH 01/10] Feat: Add `vibrate` field to `use_web_notification` - Implemented `vibrate` option in `UseWebNotificationOptions` and `ShowOptions` structures allowing specifying vibration patterns for notifications. --- src/use_web_notification.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 2a51626..d8dbd38 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -228,7 +228,6 @@ impl From for web_sys::NotificationDirection { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `vibrate` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct UseWebNotificationOptions { @@ -281,6 +280,10 @@ pub struct UseWebNotificationOptions { #[builder(into)] silent: Option, + /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + #[builder(into)] + vibrate: Option, + /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -308,6 +311,7 @@ impl Default for UseWebNotificationOptions { require_interaction: false, renotify: false, silent: None, + vibrate: None, on_click: Rc::new(|_| {}), on_close: Rc::new(|_| {}), on_error: Rc::new(|_| {}), @@ -345,6 +349,9 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options.set_tag(tag); } + if let Some(vibrate) = &options.vibrate { + web_sys_options.set_vibrate(vibrate); + } web_sys_options } } @@ -354,7 +361,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `vibrate` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct ShowOptions { @@ -408,6 +414,10 @@ pub struct ShowOptions { /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. #[builder(into)] silent: Option, + + /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + #[builder(into)] + vibrate: Option, } #[cfg(not(feature = "ssr"))] @@ -448,6 +458,10 @@ impl ShowOptions { if let Some(silent) = self.silent { options.set_silent(Some(silent)); } + + if let Some(vibrate) = &self.vibrate { + options.set_vibrate(vibrate); + } } } From 4ff32e7dcef84b1f800b78b561475bf9a01206da Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 21 Aug 2024 21:28:52 -0400 Subject: [PATCH 02/10] Docs: Correct default value for `silent` field - Updated comments to reflect that the default value for `silent` is `null`, not `false`. --- src/use_web_notification.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index d8dbd38..f34c9cd 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -276,7 +276,7 @@ pub struct UseWebNotificationOptions { renotify: bool, /// A boolean value specifying whether the notification should be silent, regardless of the device settings. - /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + /// The default is `null`, which means the notification is not silent. If `true`, then the notification will be silent. #[builder(into)] silent: Option, @@ -411,7 +411,7 @@ pub struct ShowOptions { renotify: Option, /// A boolean value specifying whether the notification should be silent, regardless of the device settings. - /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + /// The default is `null`, which means the notification is not silent. If `true`, then the notification will be silent. #[builder(into)] silent: Option, From 3fbe9c66d2b6dbd2786e352748e5426e0fb34589 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Thu, 22 Aug 2024 13:37:32 +0100 Subject: [PATCH 03/10] added features for every function. fixes #152 --- Cargo.toml | 399 +++++++++++++----- examples/on_click_outside/Cargo.toml | 2 +- examples/signal_debounced/Cargo.toml | 2 +- examples/signal_throttled/Cargo.toml | 2 +- examples/ssr/Cargo.toml | 15 +- examples/sync_signal/Cargo.toml | 2 +- examples/use_active_element/Cargo.toml | 2 +- examples/use_breakpoints/Cargo.toml | 2 +- examples/use_broadcast_channel/Cargo.toml | 2 +- examples/use_clipboard/Cargo.toml | 2 +- examples/use_color_mode/Cargo.toml | 2 +- examples/use_cookie/Cargo.toml | 2 +- examples/use_css_var/Cargo.toml | 2 +- examples/use_cycle_list/Cargo.toml | 2 +- examples/use_debounce_fn/Cargo.toml | 2 +- examples/use_device_orientation/Cargo.toml | 2 +- examples/use_device_pixel_ratio/Cargo.toml | 2 +- examples/use_display_media/Cargo.toml | 2 +- examples/use_document_visibility/Cargo.toml | 2 +- examples/use_draggable/Cargo.toml | 2 +- examples/use_drop_zone/Cargo.toml | 2 +- examples/use_element_bounding/Cargo.toml | 2 +- examples/use_element_hover/Cargo.toml | 2 +- examples/use_element_size/Cargo.toml | 2 +- examples/use_element_visibility/Cargo.toml | 2 +- examples/use_event_listener/Cargo.toml | 2 +- examples/use_favicon/Cargo.toml | 2 +- examples/use_geolocation/Cargo.toml | 2 +- examples/use_idle/Cargo.toml | 2 +- examples/use_infinite_scroll/Cargo.toml | 2 +- examples/use_intersection_observer/Cargo.toml | 2 +- examples/use_interval/Cargo.toml | 2 +- examples/use_interval_fn/Cargo.toml | 2 +- examples/use_intl_number_format/Cargo.toml | 2 +- examples/use_locale/Cargo.toml | 2 +- examples/use_locales/Cargo.toml | 2 +- examples/use_media_query/Cargo.toml | 2 +- examples/use_mouse/Cargo.toml | 2 +- examples/use_mouse_in_element/Cargo.toml | 2 +- examples/use_mutation_observer/Cargo.toml | 2 +- examples/use_permission/Cargo.toml | 2 +- .../use_prefers_reduced_motion/Cargo.toml | 2 +- examples/use_raf_fn/Cargo.toml | 2 +- examples/use_resize_observer/Cargo.toml | 2 +- examples/use_scroll/Cargo.toml | 2 +- examples/use_service_worker/Cargo.toml | 2 +- examples/use_sorted/Cargo.toml | 2 +- examples/use_storage/Cargo.toml | 2 +- examples/use_throttle_fn/Cargo.toml | 2 +- examples/use_timeout_fn/Cargo.toml | 2 +- examples/use_timestamp/Cargo.toml | 2 +- examples/use_user_media/Cargo.toml | 2 +- examples/use_web_notification/Cargo.toml | 2 +- examples/use_websocket/Cargo.toml | 2 +- examples/use_webtransport/Cargo.toml | 2 +- examples/use_window_focus/Cargo.toml | 2 +- examples/use_window_scroll/Cargo.toml | 2 +- examples/watch_debounced/Cargo.toml | 2 +- examples/watch_pausable/Cargo.toml | 2 +- examples/watch_throttled/Cargo.toml | 2 +- src/core/mod.rs | 10 +- src/core/reconnect_limit.rs | 20 + src/core/ssr_safe_method.rs | 2 + src/core/storage.rs | 21 - src/lib.rs | 141 +++++++ src/storage/mod.rs | 23 +- src/storage/use_storage.rs | 5 +- src/use_color_mode.rs | 3 +- src/use_websocket.rs | 22 +- src/utils/header_macro.rs | 2 + src/utils/js_value_from_to_string.rs | 2 + src/utils/mod.rs | 5 + src/utils/signal_filtered.rs | 2 + src/watch_debounced.rs | 2 +- src/watch_throttled.rs | 2 +- 75 files changed, 580 insertions(+), 212 deletions(-) create mode 100644 src/core/reconnect_limit.rs delete mode 100644 src/core/storage.rs diff --git a/Cargo.toml b/Cargo.toml index 9ec4f61..de5940a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,14 +14,14 @@ homepage = "https://leptos-use.rs" [dependencies] actix-web = { version = "4", optional = true, default-features = false } -async-trait = "0.1" +async-trait = { version = "0.1", optional = true } cfg-if = "1" -codee = "0.1" -cookie = { version = "0.18", features = ["percent-encode"] } +codee = { version = "0.1", optional = true } +cookie = { version = "0.18", features = ["percent-encode"], optional = true } default-struct-builder = "0.5" -futures-util = "0.3" -gloo-timers = { version = "0.3.0", features = ["futures"] } -gloo-utils = { version = "0.2.0" } +futures-util = { version = "0.3", optional = true } +gloo-timers = { version = "0.3.0", optional = true, features = ["futures"] } +gloo-utils = { version = "0.2.0", optional = true } http1 = { version = "1", optional = true, package = "http" } http0_2 = { version = "0.2", optional = true, package = "http" } js-sys = "0.3" @@ -33,101 +33,10 @@ leptos-spin = { version = "0.1", optional = true } num = { version = "0.4", optional = true } paste = "1" thiserror = "1" -unic-langid = "0.9" +unic-langid = { version = "0.9", optional = true } wasm-bindgen = "=0.2.93" wasm-bindgen-futures = "0.4" - -[dependencies.web-sys] -version = "=0.3.70" -features = [ - "AddEventListenerOptions", - "BinaryType", - "BroadcastChannel", - "Coordinates", - "Clipboard", - "CloseEvent", - "CssStyleDeclaration", - "CustomEvent", - "CustomEventInit", - "DisplayMediaStreamConstraints", - "DomRect", - "DomRectReadOnly", - "DataTransfer", - "DragEvent", - "Element", - "EventListener", - "EventListenerOptions", - "EventSource", - "EventSourceInit", - "EventTarget", - "File", - "FileList", - "Geolocation", - "HtmlDocument", - "HtmlElement", - "HtmlLinkElement", - "HtmlStyleElement", - "IntersectionObserver", - "IntersectionObserverInit", - "IntersectionObserverEntry", - "Location", - "MediaDevices", - "MediaQueryList", - "MediaStream", - "MediaStreamConstraints", - "MediaStreamTrack", - "MessageEvent", - "MouseEvent", - "MutationObserver", - "MutationObserverInit", - "MutationRecord", - "Navigator", - "NodeList", - "Notification", - "NotificationDirection", - "NotificationOptions", - "NotificationPermission", - "Permissions", - "PermissionState", - "PermissionStatus", - "PointerEvent", - "Position", - "PositionError", - "PositionOptions", - "ReadableStream", - "ReadableStreamDefaultReader", - "ReadableStreamGetReaderOptions", - "ReadableStreamReaderMode", - "ResizeObserver", - "ResizeObserverBoxOptions", - "ResizeObserverEntry", - "ResizeObserverOptions", - "ResizeObserverSize", - "ScrollBehavior", - "ScrollToOptions", - "ServiceWorker", - "ServiceWorkerContainer", - "ServiceWorkerRegistration", - "ServiceWorkerState", - "Storage", - "StorageEvent", - "Touch", - "TouchEvent", - "TouchList", - "Url", - "UrlSearchParams", - "VisibilityState", - "WebSocket", - "WebTransport", - "WebTransportOptions", - "WebTransportDatagramDuplexStream", - "WebTransportBidirectionalStream", - "Window", - "WebTransportReceiveStream", - "WebTransportSendStream", - "WritableStream", - "WritableStreamDefaultWriter", -] +web-sys = { version = "=0.3.70", optional = true } [dev-dependencies] codee = { version = "0.1", features = ["json_serde", "msgpack_serde", "base64", "prost"] } @@ -138,13 +47,303 @@ serde = { version = "1", features = ["derive"] } unic-langid = { version = "0.9", features = ["macros"] } [features] +default = [ + "is_err", + "is_none", + "is_ok", + "is_some", + "on_click_outside", + "signal_debounced", + "signal_throttled", + "storage", + "sync_signal", + "use_active_element", + "use_breakpoints", + "use_broadcast_channel", + "use_clipboard", + "use_color_mode", + "use_cookie", + "use_css_var", + "use_cycle_list", + "use_debounce_fn", + "use_device_orientation", + "use_device_pixel_ratio", + "use_display_media", + "use_document", + "use_document_visibility", + "use_draggable", + "use_drop_zone", + "use_element_bounding", + "use_element_hover", + "use_element_size", + "use_element_visibility", + "use_event_listener", + "use_event_source", + "use_favicon", + "use_geolocation", + "use_idle", + "use_infinite_scroll", + "use_intersection_observer", + "use_interval", + "use_interval_fn", + "use_intl_number_format", + "use_locale", + "use_locales", + "use_media_query", + "use_mouse", + "use_mouse_in_element", + "use_mutation_observer", + "use_permission", + "use_preferred_contrast", + "use_preferred_dark", + "use_prefers_reduced_motion", + "use_raf_fn", + "use_resize_observer", + "use_scroll", + "use_service_worker", + "use_sorted", + "use_supported", + "use_throttle_fn", + "use_timeout_fn", + "use_timestamp", + "use_to_string", + "use_user_media", + "use_web_notification", + "use_websocket", + "use_window", + "use_window_focus", + "use_window_scroll", + "watch_debounced", + "watch_pausable", + "watch_throttled", + "watch_with_options", + "whenever" +] actix = ["dep:actix-web", "dep:leptos_actix", "dep:http0_2"] axum = ["dep:leptos_axum", "dep:http1"] -docs = [] +docs = ["dep:web-sys"] +element = ["use_document", "use_window", "dep:web-sys", "web-sys/EventTarget"] +is = ["use_window"] +is_err = [] +is_none = [] +is_ok = [] +is_some = [] math = ["num"] +on_click_outside = ["use_event_listener", "is"] +signal_debounced = ["use_debounce_fn"] +signal_throttled = ["use_throttle_fn"] spin = ["dep:leptos-spin", "dep:http1"] ssr = [] +storage = [ + "use_event_listener", + "use_window", + "watch_with_options", + "dep:web-sys", + "dep:codee", + "web-sys/CustomEventInit", + "web-sys/Storage" +] +sync_signal = [] +use_active_element = ["use_event_listener"] +use_breakpoints = ["use_media_query"] +use_broadcast_channel = [ + "use_event_listener", + "use_supported", + "dep:codee", + "web-sys/BroadcastChannel", +] +use_clipboard = [ + "use_event_listener", + "use_permission", + "use_supported", + "use_timeout_fn", + "web-sys/Clipboard", +] +use_color_mode = [ + "use_cookie", + "use_cycle_list", + "use_preferred_dark", + "storage", + "sync_signal" +] +use_cookie = [ + "use_broadcast_channel", + "watch_pausable", + "dep:cookie", + "web-sys/HtmlDocument", +] +use_css_var = [ + "use_mutation_observer", + "watch_with_options", +] +use_cycle_list = [] +use_debounce_fn = [] +use_device_orientation = ["use_event_listener", "use_supported"] +use_device_pixel_ratio = ["use_event_listener", "web-sys/MediaQueryList"] +use_display_media = [ + "use_window", + "web-sys/DisplayMediaStreamConstraints", + "web-sys/MediaDevices", + "web-sys/MediaStream", + "web-sys/MediaStreamTrack", +] +use_document = [ + "dep:web-sys", + "web-sys/VisibilityState", +] +use_document_visibility = ["use_event_listener", "web-sys/VisibilityState"] +use_draggable = ["use_event_listener", "web-sys/DomRect"] +use_drop_zone = [ + "use_event_listener", + "web-sys/DataTransfer", + "web-sys/File", + "web-sys/FileList" +] +use_element_bounding = [ + "use_event_listener", + "use_resize_observer", + "web-sys/DomRect", +] +use_element_hover = ["use_event_listener"] +use_element_size = [ + "use_resize_observer", + "watch_with_options", + "web-sys/ResizeObserverSize", +] +use_element_visibility = [ + "use_intersection_observer", + "web-sys/DomRect", +] +use_event_listener = [ + "element", + "watch_with_options", + "dep:web-sys", + "web-sys/EventTarget", + "web-sys/EventListenerOptions" +] +use_event_source = [ + "use_event_listener", + "web-sys/EventSource", + "web-sys/EventSourceInit", + "dep:codee", +] +use_favicon = [] +use_geolocation = [ + "use_window", + "web-sys/Coordinates", + "web-sys/Geolocation", + "web-sys/Position", + "web-sys/PositionError", + "web-sys/PositionOptions", +] +use_idle = [ + "use_event_listener", + "use_document", + "use_timestamp", +] +use_infinite_scroll = [ + "use_element_visibility", + "use_scroll", + "dep:gloo-timers", + "dep:futures-util", +] +use_intersection_observer = [ + "element", + "watch_with_options", + "web-sys/IntersectionObserver", + "web-sys/IntersectionObserverEntry", + "web-sys/IntersectionObserverInit", +] +use_interval = ["use_interval_fn"] +use_interval_fn = [] +use_intl_number_format = [] +use_locale = ["use_locales", "dep:unic-langid"] +use_locales = ["use_event_listener", "use_window"] +use_media_query = ["use_event_listener"] +use_mouse = [ + "element", + "use_event_listener", + "use_window", + "web-sys/Touch", + "web-sys/TouchList", +] +use_mouse_in_element = [ + "use_mouse", + "web-sys/DomRect", +] +use_mutation_observer = [ + "element", + "use_supported", + "web-sys/MutationObserver", + "web-sys/MutationObserverInit", + "web-sys/MutationRecord", +] +use_permission = [ + "use_event_listener", + "web-sys/Permissions", + "web-sys/PermissionState", + "web-sys/PermissionStatus", +] +use_preferred_contrast = ["use_media_query"] +use_preferred_dark = ["use_media_query"] +use_prefers_reduced_motion = ["use_media_query"] +use_raf_fn = [] +use_resize_observer = [ + "element", + "use_supported", + "web-sys/DomRectReadOnly", + "web-sys/ResizeObserver", + "web-sys/ResizeObserverBoxOptions", + "web-sys/ResizeObserverEntry", + "web-sys/ResizeObserverOptions", +] +use_scroll = [ + "element", + "use_event_listener", + "use_debounce_fn", + "use_throttle_fn", + "web-sys/ScrollBehavior", + "web-sys/ScrollToOptions", +] +use_service_worker = [ + "use_window", + "web-sys/ServiceWorker", + "web-sys/ServiceWorkerContainer", + "web-sys/ServiceWorkerRegistration" +] +use_sorted = [] +use_supported = [] +use_throttle_fn = [] +use_timeout_fn = [] +use_timestamp = ["use_interval_fn", "use_raf_fn"] +use_to_string = [] +use_user_media = [ + "use_window", + "web-sys/MediaDevices", + "web-sys/MediaStream", + "web-sys/MediaStreamConstraints", + "web-sys/MediaStreamTrack", +] +use_web_notification = [ + "use_supported", + "use_window", + "use_event_listener", + "web-sys/Notification", + "web-sys/NotificationOptions", + "web-sys/NotificationPermission", + "web-sys/NotificationDirection", + "web-sys/VisibilityState" +] +use_websocket = ["dep:codee"] +use_window = ["use_document", "dep:web-sys", "web-sys/Navigator", "web-sys/MediaQueryList"] +use_window_focus = ["use_event_listener"] +use_window_scroll = ["use_event_listener", "use_window"] wasm_ssr = [] +watch_debounced = ["watch_with_options"] +watch_pausable = ["watch_with_options"] +watch_throttled = ["watch_with_options"] +watch_with_options = [] +whenever = [] [package.metadata.docs.rs] features = ["math", "docs", "ssr"] diff --git a/examples/on_click_outside/Cargo.toml b/examples/on_click_outside/Cargo.toml index 3313bf8..c6d6279 100644 --- a/examples/on_click_outside/Cargo.toml +++ b/examples/on_click_outside/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["on_click_outside", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/signal_debounced/Cargo.toml b/examples/signal_debounced/Cargo.toml index 6f85a28..9411da3 100644 --- a/examples/signal_debounced/Cargo.toml +++ b/examples/signal_debounced/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["signal_debounced", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/signal_throttled/Cargo.toml b/examples/signal_throttled/Cargo.toml index 73b2b91..2a14d8a 100644 --- a/examples/signal_throttled/Cargo.toml +++ b/examples/signal_throttled/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["signal_throttled", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml index 533ce90..33e9575 100644 --- a/examples/ssr/Cargo.toml +++ b/examples/ssr/Cargo.toml @@ -16,7 +16,6 @@ leptos = { version = "0.6", features = ["nightly"] } leptos_axum = { version = "0.6", optional = true } leptos_meta = { version = "0.6", features = ["nightly"] } leptos_router = { version = "0.6", features = ["nightly"] } -leptos-use = { path = "../.." } log = "0.4" simple_logger = "4" tokio = { version = "1", features = ["full"], optional = true } @@ -28,6 +27,20 @@ thiserror = "1.0.38" tracing = { version = "0.1.37", optional = true } http = "1" +[dependencies.leptos-use] +path = "../.." +features = [ + "use_cookie", + "use_color_mode", + "use_debounce_fn", + "use_event_listener", + "use_interval", + "use_intl_number_format", + "use_locales", + "use_timestamp", + "storage" +] + [features] hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"] ssr = [ diff --git a/examples/sync_signal/Cargo.toml b/examples/sync_signal/Cargo.toml index 0eae2b1..c072a2b 100644 --- a/examples/sync_signal/Cargo.toml +++ b/examples/sync_signal/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["sync_signal", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_active_element/Cargo.toml b/examples/use_active_element/Cargo.toml index c19c400..e5c31a5 100644 --- a/examples/use_active_element/Cargo.toml +++ b/examples/use_active_element/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_active_element", "docs"] } web-sys = { version = "0.3", features = ["HtmlElement", "DomStringMap"] } [dev-dependencies] diff --git a/examples/use_breakpoints/Cargo.toml b/examples/use_breakpoints/Cargo.toml index 22b894b..b022945 100644 --- a/examples/use_breakpoints/Cargo.toml +++ b/examples/use_breakpoints/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_breakpoints", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_broadcast_channel/Cargo.toml b/examples/use_broadcast_channel/Cargo.toml index a7bf756..3cfcd3f 100644 --- a/examples/use_broadcast_channel/Cargo.toml +++ b/examples/use_broadcast_channel/Cargo.toml @@ -9,7 +9,7 @@ codee = "0.1" console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_broadcast_channel", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_clipboard/Cargo.toml b/examples/use_clipboard/Cargo.toml index d85ad83..43cba10 100644 --- a/examples/use_clipboard/Cargo.toml +++ b/examples/use_clipboard/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_clipboard", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_color_mode/Cargo.toml b/examples/use_color_mode/Cargo.toml index ead2ef6..26874f0 100644 --- a/examples/use_color_mode/Cargo.toml +++ b/examples/use_color_mode/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_color_mode", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_cookie/Cargo.toml b/examples/use_cookie/Cargo.toml index c645550..2974155 100644 --- a/examples/use_cookie/Cargo.toml +++ b/examples/use_cookie/Cargo.toml @@ -9,7 +9,7 @@ codee = "0.1" console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_cookie", "docs"] } rand = "0.8" getrandom = { version = "0.2", features = ["js"] } web-sys = "0.3" diff --git a/examples/use_css_var/Cargo.toml b/examples/use_css_var/Cargo.toml index 267c40e..97d6fa6 100644 --- a/examples/use_css_var/Cargo.toml +++ b/examples/use_css_var/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_css_var", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_cycle_list/Cargo.toml b/examples/use_cycle_list/Cargo.toml index c59b61c..77f6c25 100644 --- a/examples/use_cycle_list/Cargo.toml +++ b/examples/use_cycle_list/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_cycle_list", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_debounce_fn/Cargo.toml b/examples/use_debounce_fn/Cargo.toml index d5f4621..c3f7b9e 100644 --- a/examples/use_debounce_fn/Cargo.toml +++ b/examples/use_debounce_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_debounce_fn", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_device_orientation/Cargo.toml b/examples/use_device_orientation/Cargo.toml index 9a4c64a..5fec238 100644 --- a/examples/use_device_orientation/Cargo.toml +++ b/examples/use_device_orientation/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_device_orientation", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_device_pixel_ratio/Cargo.toml b/examples/use_device_pixel_ratio/Cargo.toml index 5874c65..98efdde 100644 --- a/examples/use_device_pixel_ratio/Cargo.toml +++ b/examples/use_device_pixel_ratio/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_device_pixel_ratio", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_display_media/Cargo.toml b/examples/use_display_media/Cargo.toml index c7ffe6a..f5f4b79 100644 --- a/examples/use_display_media/Cargo.toml +++ b/examples/use_display_media/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_display_media", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_document_visibility/Cargo.toml b/examples/use_document_visibility/Cargo.toml index cb9b8f1..8d5b019 100644 --- a/examples/use_document_visibility/Cargo.toml +++ b/examples/use_document_visibility/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_document_visibility", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_draggable/Cargo.toml b/examples/use_draggable/Cargo.toml index e2e9a61..8427afb 100644 --- a/examples/use_draggable/Cargo.toml +++ b/examples/use_draggable/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_draggable", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_drop_zone/Cargo.toml b/examples/use_drop_zone/Cargo.toml index 115dc9d..aa05fca 100644 --- a/examples/use_drop_zone/Cargo.toml +++ b/examples/use_drop_zone/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_drop_zone", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_element_bounding/Cargo.toml b/examples/use_element_bounding/Cargo.toml index 7620bcd..8ef72c3 100644 --- a/examples/use_element_bounding/Cargo.toml +++ b/examples/use_element_bounding/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_element_bounding", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_element_hover/Cargo.toml b/examples/use_element_hover/Cargo.toml index 9d90e62..9be576c 100644 --- a/examples/use_element_hover/Cargo.toml +++ b/examples/use_element_hover/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_element_hover", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_element_size/Cargo.toml b/examples/use_element_size/Cargo.toml index daf02f0..4e71f62 100644 --- a/examples/use_element_size/Cargo.toml +++ b/examples/use_element_size/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_element_size", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_element_visibility/Cargo.toml b/examples/use_element_visibility/Cargo.toml index 50ba543..3506775 100644 --- a/examples/use_element_visibility/Cargo.toml +++ b/examples/use_element_visibility/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_element_visibility", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_event_listener/Cargo.toml b/examples/use_event_listener/Cargo.toml index 653bb76..d0e75c1 100644 --- a/examples/use_event_listener/Cargo.toml +++ b/examples/use_event_listener/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../.." } +leptos-use = { path = "../..", features = ["use_event_listener"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_favicon/Cargo.toml b/examples/use_favicon/Cargo.toml index 260413a..38d4f05 100644 --- a/examples/use_favicon/Cargo.toml +++ b/examples/use_favicon/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_favicon", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_geolocation/Cargo.toml b/examples/use_geolocation/Cargo.toml index bb7c93e..4ded1d2 100644 --- a/examples/use_geolocation/Cargo.toml +++ b/examples/use_geolocation/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_geolocation", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_idle/Cargo.toml b/examples/use_idle/Cargo.toml index 1b412b4..0e8d92a 100644 --- a/examples/use_idle/Cargo.toml +++ b/examples/use_idle/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_idle", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_infinite_scroll/Cargo.toml b/examples/use_infinite_scroll/Cargo.toml index e55811a..52cafcb 100644 --- a/examples/use_infinite_scroll/Cargo.toml +++ b/examples/use_infinite_scroll/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_infinite_scroll", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_intersection_observer/Cargo.toml b/examples/use_intersection_observer/Cargo.toml index b401615..b8c5d1a 100644 --- a/examples/use_intersection_observer/Cargo.toml +++ b/examples/use_intersection_observer/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_intersection_observer", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_interval/Cargo.toml b/examples/use_interval/Cargo.toml index a49f0cd..cd02ec5 100644 --- a/examples/use_interval/Cargo.toml +++ b/examples/use_interval/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_interval", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_interval_fn/Cargo.toml b/examples/use_interval_fn/Cargo.toml index 86bc8b2..96de322 100644 --- a/examples/use_interval_fn/Cargo.toml +++ b/examples/use_interval_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs", "math"] } +leptos-use = { path = "../..", features = ["use_interval_fn", "docs", "math"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_intl_number_format/Cargo.toml b/examples/use_intl_number_format/Cargo.toml index 7eadd70..5ed97da 100644 --- a/examples/use_intl_number_format/Cargo.toml +++ b/examples/use_intl_number_format/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_intl_number_format", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_locale/Cargo.toml b/examples/use_locale/Cargo.toml index 1a2555a..1c592fe 100644 --- a/examples/use_locale/Cargo.toml +++ b/examples/use_locale/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_locale", "docs"] } unic-langid = { version = "0.9", features = ["macros"] } web-sys = "0.3" diff --git a/examples/use_locales/Cargo.toml b/examples/use_locales/Cargo.toml index 05b5bc9..c98524c 100644 --- a/examples/use_locales/Cargo.toml +++ b/examples/use_locales/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_locales", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_media_query/Cargo.toml b/examples/use_media_query/Cargo.toml index 345aa87..a57d7fe 100644 --- a/examples/use_media_query/Cargo.toml +++ b/examples/use_media_query/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_media_query", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_mouse/Cargo.toml b/examples/use_mouse/Cargo.toml index 1c91a04..cb2dea3 100644 --- a/examples/use_mouse/Cargo.toml +++ b/examples/use_mouse/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_mouse", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_mouse_in_element/Cargo.toml b/examples/use_mouse_in_element/Cargo.toml index ac23964..2823591 100644 --- a/examples/use_mouse_in_element/Cargo.toml +++ b/examples/use_mouse_in_element/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_mouse_in_element", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_mutation_observer/Cargo.toml b/examples/use_mutation_observer/Cargo.toml index fcf12fd..c85533a 100644 --- a/examples/use_mutation_observer/Cargo.toml +++ b/examples/use_mutation_observer/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_mutation_observer", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_permission/Cargo.toml b/examples/use_permission/Cargo.toml index 17f2388..f03e633 100644 --- a/examples/use_permission/Cargo.toml +++ b/examples/use_permission/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_permission", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_prefers_reduced_motion/Cargo.toml b/examples/use_prefers_reduced_motion/Cargo.toml index 4b0d55a..3cdeb8d 100644 --- a/examples/use_prefers_reduced_motion/Cargo.toml +++ b/examples/use_prefers_reduced_motion/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_prefers_reduced_motion", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_raf_fn/Cargo.toml b/examples/use_raf_fn/Cargo.toml index 48b8cd9..e9c4c57 100644 --- a/examples/use_raf_fn/Cargo.toml +++ b/examples/use_raf_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_raf_fn", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_resize_observer/Cargo.toml b/examples/use_resize_observer/Cargo.toml index 0ce7f4c..8ba4ed2 100644 --- a/examples/use_resize_observer/Cargo.toml +++ b/examples/use_resize_observer/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_resize_observer", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_scroll/Cargo.toml b/examples/use_scroll/Cargo.toml index ccb133a..25874cd 100644 --- a/examples/use_scroll/Cargo.toml +++ b/examples/use_scroll/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_scroll", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_service_worker/Cargo.toml b/examples/use_service_worker/Cargo.toml index 8e3b8c7..f074dd0 100644 --- a/examples/use_service_worker/Cargo.toml +++ b/examples/use_service_worker/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_service_worker", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_sorted/Cargo.toml b/examples/use_sorted/Cargo.toml index 05462ac..8ff335f 100644 --- a/examples/use_sorted/Cargo.toml +++ b/examples/use_sorted/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_sorted", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_storage/Cargo.toml b/examples/use_storage/Cargo.toml index 5174789..b8b2285 100644 --- a/examples/use_storage/Cargo.toml +++ b/examples/use_storage/Cargo.toml @@ -8,7 +8,7 @@ codee = { version = "0.1", features = ["json_serde"] } console_error_panic_hook = "0.1" console_log = "1" leptos = { version = "0.6", features = ["nightly", "csr"] } -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["storage", "docs"] } log = "0.4" serde = "1.0.163" web-sys = "0.3" diff --git a/examples/use_throttle_fn/Cargo.toml b/examples/use_throttle_fn/Cargo.toml index 04d6006..d39fc8d 100644 --- a/examples/use_throttle_fn/Cargo.toml +++ b/examples/use_throttle_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_throttle_fn", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_timeout_fn/Cargo.toml b/examples/use_timeout_fn/Cargo.toml index 9b0cfa4..608afac 100644 --- a/examples/use_timeout_fn/Cargo.toml +++ b/examples/use_timeout_fn/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_timeout_fn", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_timestamp/Cargo.toml b/examples/use_timestamp/Cargo.toml index a065eb4..5e0a16f 100644 --- a/examples/use_timestamp/Cargo.toml +++ b/examples/use_timestamp/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_timestamp", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_user_media/Cargo.toml b/examples/use_user_media/Cargo.toml index ffd38b8..170c4af 100644 --- a/examples/use_user_media/Cargo.toml +++ b/examples/use_user_media/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_user_media", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_web_notification/Cargo.toml b/examples/use_web_notification/Cargo.toml index 216f31e..f499927 100644 --- a/examples/use_web_notification/Cargo.toml +++ b/examples/use_web_notification/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_web_notification", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_websocket/Cargo.toml b/examples/use_websocket/Cargo.toml index 2eb5095..26ed9a6 100644 --- a/examples/use_websocket/Cargo.toml +++ b/examples/use_websocket/Cargo.toml @@ -9,7 +9,7 @@ codee = { version = "0.1", features = ["msgpack_serde"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_websocket", "docs"] } serde = { version = "1", features = ["derive"] } web-sys = "0.3" diff --git a/examples/use_webtransport/Cargo.toml b/examples/use_webtransport/Cargo.toml index 5291647..680dc93 100644 --- a/examples/use_webtransport/Cargo.toml +++ b/examples/use_webtransport/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_web_notification", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_window_focus/Cargo.toml b/examples/use_window_focus/Cargo.toml index d157e75..ff9224a 100644 --- a/examples/use_window_focus/Cargo.toml +++ b/examples/use_window_focus/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_window_focus", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/use_window_scroll/Cargo.toml b/examples/use_window_scroll/Cargo.toml index d8a1c48..43092e2 100644 --- a/examples/use_window_scroll/Cargo.toml +++ b/examples/use_window_scroll/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["use_window_scroll", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/watch_debounced/Cargo.toml b/examples/watch_debounced/Cargo.toml index 8af3c77..b7d1872 100644 --- a/examples/watch_debounced/Cargo.toml +++ b/examples/watch_debounced/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["watch_debounced", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/watch_pausable/Cargo.toml b/examples/watch_pausable/Cargo.toml index a14897d..548f01a 100644 --- a/examples/watch_pausable/Cargo.toml +++ b/examples/watch_pausable/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["watch_pausable", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/examples/watch_throttled/Cargo.toml b/examples/watch_throttled/Cargo.toml index e711c4f..d69a67a 100644 --- a/examples/watch_throttled/Cargo.toml +++ b/examples/watch_throttled/Cargo.toml @@ -8,7 +8,7 @@ leptos = { version = "0.6", features = ["nightly", "csr"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" -leptos-use = { path = "../..", features = ["docs"] } +leptos-use = { path = "../..", features = ["watch_throttled", "docs"] } web-sys = "0.3" [dev-dependencies] diff --git a/src/core/mod.rs b/src/core/mod.rs index 3fe5ca3..0b51baa 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -1,26 +1,32 @@ mod connection_ready_state; mod datetime; mod direction; +#[cfg(feature = "element")] mod element_maybe_signal; +#[cfg(feature = "element")] mod elements_maybe_signal; mod maybe_rw_signal; mod pointer_type; mod position; +mod reconnect_limit; mod size; mod ssr_safe_method; -mod storage; +#[cfg(feature = "use_color_mode")] pub(crate) mod url; mod use_rw_signal; pub use connection_ready_state::*; pub(crate) use datetime::*; pub use direction::*; +#[cfg(feature = "element")] pub use element_maybe_signal::*; +#[cfg(feature = "element")] pub use elements_maybe_signal::*; pub use maybe_rw_signal::*; pub use pointer_type::*; pub use position::*; +pub use reconnect_limit::*; pub use size::*; +#[allow(unused_imports)] pub(crate) use ssr_safe_method::*; -pub use storage::*; pub use use_rw_signal::*; diff --git a/src/core/reconnect_limit.rs b/src/core/reconnect_limit.rs new file mode 100644 index 0000000..5d28b2c --- /dev/null +++ b/src/core/reconnect_limit.rs @@ -0,0 +1,20 @@ +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum ReconnectLimit { + Infinite, + Limited(u64), +} + +impl Default for ReconnectLimit { + fn default() -> Self { + ReconnectLimit::Limited(3) + } +} + +impl ReconnectLimit { + pub fn is_exceeded_by(self, times: u64) -> bool { + match self { + ReconnectLimit::Infinite => false, + ReconnectLimit::Limited(limit) => times >= limit, + } + } +} diff --git a/src/core/ssr_safe_method.rs b/src/core/ssr_safe_method.rs index 9ffa513..da46452 100644 --- a/src/core/ssr_safe_method.rs +++ b/src/core/ssr_safe_method.rs @@ -1,3 +1,5 @@ +#![allow(unused_macros, unused_imports)] + macro_rules! impl_ssr_safe_method { ( $(#[$attr:meta])* diff --git a/src/core/storage.rs b/src/core/storage.rs deleted file mode 100644 index 8390217..0000000 --- a/src/core/storage.rs +++ /dev/null @@ -1,21 +0,0 @@ -use leptos::window; -use wasm_bindgen::JsValue; - -/// Local or session storage or a custom store that is a `web_sys::Storage`. -#[derive(Default)] -pub enum StorageType { - #[default] - Local, - Session, - Custom(web_sys::Storage), -} - -impl StorageType { - pub fn into_storage(self) -> Result, JsValue> { - match self { - StorageType::Local => window().local_storage(), - StorageType::Session => window().session_storage(), - StorageType::Custom(storage) => Ok(Some(storage)), - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 0e43a6b..1b18ab1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,150 +7,291 @@ pub mod core; pub mod docs; #[cfg(feature = "math")] pub mod math; +#[cfg(feature = "storage")] pub mod storage; pub mod utils; +pub use core::ReconnectLimit; + // #[cfg(web_sys_unstable_apis)] // mod use_webtransport; // #[cfg(web_sys_unstable_apis)] // pub use use_webtransport::*; +#[cfg(feature = "is_err")] mod is_err; +#[cfg(feature = "is_none")] mod is_none; +#[cfg(feature = "is_ok")] mod is_ok; +#[cfg(feature = "is_some")] mod is_some; +#[cfg(feature = "on_click_outside")] mod on_click_outside; +#[cfg(feature = "signal_debounced")] mod signal_debounced; +#[cfg(feature = "signal_throttled")] mod signal_throttled; +#[cfg(feature = "sync_signal")] mod sync_signal; +#[cfg(feature = "use_active_element")] mod use_active_element; +#[cfg(feature = "use_breakpoints")] mod use_breakpoints; +#[cfg(feature = "use_broadcast_channel")] mod use_broadcast_channel; +#[cfg(feature = "use_clipboard")] mod use_clipboard; +#[cfg(feature = "use_color_mode")] mod use_color_mode; +#[cfg(feature = "use_cookie")] mod use_cookie; +#[cfg(feature = "use_css_var")] mod use_css_var; +#[cfg(feature = "use_cycle_list")] mod use_cycle_list; +#[cfg(feature = "use_debounce_fn")] mod use_debounce_fn; +#[cfg(feature = "use_device_orientation")] mod use_device_orientation; +#[cfg(feature = "use_device_pixel_ratio")] mod use_device_pixel_ratio; +#[cfg(feature = "use_display_media")] mod use_display_media; +#[cfg(feature = "use_document")] mod use_document; +#[cfg(feature = "use_document_visibility")] mod use_document_visibility; +#[cfg(feature = "use_draggable")] mod use_draggable; +#[cfg(feature = "use_drop_zone")] mod use_drop_zone; +#[cfg(feature = "use_element_bounding")] mod use_element_bounding; +#[cfg(feature = "use_element_hover")] mod use_element_hover; +#[cfg(feature = "use_element_size")] mod use_element_size; +#[cfg(feature = "use_element_visibility")] mod use_element_visibility; +#[cfg(feature = "use_event_listener")] mod use_event_listener; +#[cfg(feature = "use_event_source")] mod use_event_source; +#[cfg(feature = "use_favicon")] mod use_favicon; +#[cfg(feature = "use_geolocation")] mod use_geolocation; +#[cfg(feature = "use_idle")] mod use_idle; +#[cfg(feature = "use_infinite_scroll")] mod use_infinite_scroll; +#[cfg(feature = "use_intersection_observer")] mod use_intersection_observer; +#[cfg(feature = "use_interval")] mod use_interval; +#[cfg(feature = "use_interval_fn")] mod use_interval_fn; +#[cfg(feature = "use_intl_number_format")] mod use_intl_number_format; +#[cfg(feature = "use_locale")] mod use_locale; +#[cfg(feature = "use_locales")] mod use_locales; +#[cfg(feature = "use_media_query")] mod use_media_query; +#[cfg(feature = "use_mouse")] mod use_mouse; +#[cfg(feature = "use_mouse_in_element")] mod use_mouse_in_element; +#[cfg(feature = "use_mutation_observer")] mod use_mutation_observer; +#[cfg(feature = "use_permission")] mod use_permission; +#[cfg(feature = "use_preferred_contrast")] mod use_preferred_contrast; +#[cfg(feature = "use_preferred_dark")] mod use_preferred_dark; +#[cfg(feature = "use_prefers_reduced_motion")] mod use_prefers_reduced_motion; +#[cfg(feature = "use_raf_fn")] mod use_raf_fn; +#[cfg(feature = "use_resize_observer")] mod use_resize_observer; +#[cfg(feature = "use_scroll")] mod use_scroll; +#[cfg(feature = "use_service_worker")] mod use_service_worker; +#[cfg(feature = "use_sorted")] mod use_sorted; +#[cfg(feature = "use_supported")] mod use_supported; +#[cfg(feature = "use_throttle_fn")] mod use_throttle_fn; +#[cfg(feature = "use_timeout_fn")] mod use_timeout_fn; +#[cfg(feature = "use_timestamp")] mod use_timestamp; +#[cfg(feature = "use_to_string")] mod use_to_string; +#[cfg(feature = "use_user_media")] mod use_user_media; +#[cfg(feature = "use_web_notification")] mod use_web_notification; +#[cfg(feature = "use_websocket")] mod use_websocket; +#[cfg(feature = "use_window")] mod use_window; +#[cfg(feature = "use_window_focus")] mod use_window_focus; +#[cfg(feature = "use_window_scroll")] mod use_window_scroll; +#[cfg(feature = "watch_debounced")] mod watch_debounced; +#[cfg(feature = "watch_pausable")] mod watch_pausable; +#[cfg(feature = "watch_throttled")] mod watch_throttled; +#[cfg(feature = "watch_with_options")] mod watch_with_options; +#[cfg(feature = "whenever")] mod whenever; +#[cfg(feature = "is_err")] pub use is_err::*; +#[cfg(feature = "is_none")] pub use is_none::*; +#[cfg(feature = "is_ok")] pub use is_ok::*; +#[cfg(feature = "is_some")] pub use is_some::*; +#[cfg(feature = "on_click_outside")] pub use on_click_outside::*; +#[cfg(feature = "signal_debounced")] pub use signal_debounced::*; +#[cfg(feature = "signal_throttled")] pub use signal_throttled::*; +#[cfg(feature = "sync_signal")] pub use sync_signal::*; +#[cfg(feature = "use_active_element")] pub use use_active_element::*; +#[cfg(feature = "use_breakpoints")] pub use use_breakpoints::*; +#[cfg(feature = "use_broadcast_channel")] pub use use_broadcast_channel::*; +#[cfg(feature = "use_clipboard")] pub use use_clipboard::*; +#[cfg(feature = "use_color_mode")] pub use use_color_mode::*; +#[cfg(feature = "use_cookie")] pub use use_cookie::*; +#[cfg(feature = "use_css_var")] pub use use_css_var::*; +#[cfg(feature = "use_cycle_list")] pub use use_cycle_list::*; +#[cfg(feature = "use_debounce_fn")] pub use use_debounce_fn::*; +#[cfg(feature = "use_device_orientation")] pub use use_device_orientation::*; +#[cfg(feature = "use_device_pixel_ratio")] pub use use_device_pixel_ratio::*; +#[cfg(feature = "use_display_media")] pub use use_display_media::*; +#[cfg(feature = "use_document")] pub use use_document::*; +#[cfg(feature = "use_document_visibility")] pub use use_document_visibility::*; +#[cfg(feature = "use_draggable")] pub use use_draggable::*; +#[cfg(feature = "use_drop_zone")] pub use use_drop_zone::*; +#[cfg(feature = "use_element_bounding")] pub use use_element_bounding::*; +#[cfg(feature = "use_element_hover")] pub use use_element_hover::*; +#[cfg(feature = "use_element_size")] pub use use_element_size::*; +#[cfg(feature = "use_element_visibility")] pub use use_element_visibility::*; +#[cfg(feature = "use_event_listener")] pub use use_event_listener::*; +#[cfg(feature = "use_event_source")] pub use use_event_source::*; +#[cfg(feature = "use_favicon")] pub use use_favicon::*; +#[cfg(feature = "use_geolocation")] pub use use_geolocation::*; +#[cfg(feature = "use_idle")] pub use use_idle::*; +#[cfg(feature = "use_infinite_scroll")] pub use use_infinite_scroll::*; +#[cfg(feature = "use_intersection_observer")] pub use use_intersection_observer::*; +#[cfg(feature = "use_interval")] pub use use_interval::*; +#[cfg(feature = "use_interval_fn")] pub use use_interval_fn::*; +#[cfg(feature = "use_intl_number_format")] pub use use_intl_number_format::*; +#[cfg(feature = "use_locale")] pub use use_locale::*; +#[cfg(feature = "use_locales")] pub use use_locales::*; +#[cfg(feature = "use_media_query")] pub use use_media_query::*; +#[cfg(feature = "use_mouse")] pub use use_mouse::*; +#[cfg(feature = "use_mouse_in_element")] pub use use_mouse_in_element::*; +#[cfg(feature = "use_mutation_observer")] pub use use_mutation_observer::*; +#[cfg(feature = "use_permission")] pub use use_permission::*; +#[cfg(feature = "use_preferred_contrast")] pub use use_preferred_contrast::*; +#[cfg(feature = "use_preferred_dark")] pub use use_preferred_dark::*; +#[cfg(feature = "use_prefers_reduced_motion")] pub use use_prefers_reduced_motion::*; +#[cfg(feature = "use_raf_fn")] pub use use_raf_fn::*; +#[cfg(feature = "use_resize_observer")] pub use use_resize_observer::*; +#[cfg(feature = "use_scroll")] pub use use_scroll::*; +#[cfg(feature = "use_service_worker")] pub use use_service_worker::*; +#[cfg(feature = "use_sorted")] pub use use_sorted::*; +#[cfg(feature = "use_supported")] pub use use_supported::*; +#[cfg(feature = "use_throttle_fn")] pub use use_throttle_fn::*; +#[cfg(feature = "use_timeout_fn")] pub use use_timeout_fn::*; +#[cfg(feature = "use_timestamp")] pub use use_timestamp::*; +#[cfg(feature = "use_to_string")] pub use use_to_string::*; +#[cfg(feature = "use_user_media")] pub use use_user_media::*; +#[cfg(feature = "use_web_notification")] pub use use_web_notification::*; +#[cfg(feature = "use_websocket")] pub use use_websocket::*; +#[cfg(feature = "use_window")] pub use use_window::*; +#[cfg(feature = "use_window_focus")] pub use use_window_focus::*; +#[cfg(feature = "use_window_scroll")] pub use use_window_scroll::*; +#[cfg(feature = "watch_debounced")] pub use watch_debounced::*; +#[cfg(feature = "watch_pausable")] pub use watch_pausable::*; +#[cfg(feature = "watch_throttled")] pub use watch_throttled::*; +#[cfg(feature = "watch_with_options")] pub use watch_with_options::*; +#[cfg(feature = "whenever")] pub use whenever::*; diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 54f79db..5930028 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -2,7 +2,28 @@ mod use_local_storage; mod use_session_storage; mod use_storage; -pub use crate::core::StorageType; pub use use_local_storage::*; pub use use_session_storage::*; pub use use_storage::*; + +use leptos::window; +use wasm_bindgen::JsValue; + +/// Local or session storage or a custom store that is a `web_sys::Storage`. +#[derive(Default)] +pub enum StorageType { + #[default] + Local, + Session, + Custom(web_sys::Storage), +} + +impl StorageType { + pub fn into_storage(self) -> Result, JsValue> { + match self { + StorageType::Local => window().local_storage(), + StorageType::Session => window().session_storage(), + StorageType::Custom(storage) => Ok(Some(storage)), + } + } +} diff --git a/src/storage/use_storage.rs b/src/storage/use_storage.rs index 91b56c0..86705e9 100644 --- a/src/storage/use_storage.rs +++ b/src/storage/use_storage.rs @@ -1,7 +1,4 @@ -use crate::{ - core::{MaybeRwSignal, StorageType}, - utils::FilterOptions, -}; +use crate::{core::MaybeRwSignal, storage::StorageType, utils::FilterOptions}; use codee::{CodecError, Decoder, Encoder}; use default_struct_builder::DefaultBuilder; use leptos::*; diff --git a/src/use_color_mode.rs b/src/use_color_mode.rs index 9f3719e..28ded80 100644 --- a/src/use_color_mode.rs +++ b/src/use_color_mode.rs @@ -1,7 +1,6 @@ use crate::core::url; -use crate::core::StorageType; use crate::core::{ElementMaybeSignal, MaybeRwSignal}; -use crate::storage::{use_storage_with_options, UseStorageOptions}; +use crate::storage::{use_storage_with_options, StorageType, UseStorageOptions}; use crate::utils::get_header; use crate::{ sync_signal_with_options, use_cookie, use_preferred_dark_with_options, SyncSignalOptions, diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 48a9596..51910e7 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use std::time::Duration; use thiserror::Error; -use crate::core::ConnectionReadyState; +use crate::{core::ConnectionReadyState, ReconnectLimit}; use codee::{ CodecError, Decoder, Encoder, HybridCoderError, HybridDecoder, HybridEncoder, IsBinary, }; @@ -608,26 +608,6 @@ where send, } } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum ReconnectLimit { - Infinite, - Limited(u64), -} - -impl Default for ReconnectLimit { - fn default() -> Self { - ReconnectLimit::Limited(3) - } -} - -impl ReconnectLimit { - pub fn is_exceeded_by(self, times: u64) -> bool { - match self { - ReconnectLimit::Infinite => false, - ReconnectLimit::Limited(limit) => times >= limit, - } - } -} type RcFnBytes = Rc; diff --git a/src/utils/header_macro.rs b/src/utils/header_macro.rs index 4f6f087..2664f78 100644 --- a/src/utils/header_macro.rs +++ b/src/utils/header_macro.rs @@ -1,3 +1,5 @@ +#![allow(unused_macros, unused_imports)] + macro_rules! get_header { ( $header_name:expr, diff --git a/src/utils/js_value_from_to_string.rs b/src/utils/js_value_from_to_string.rs index f371c96..4149c4c 100644 --- a/src/utils/js_value_from_to_string.rs +++ b/src/utils/js_value_from_to_string.rs @@ -1,3 +1,5 @@ +#![allow(unused_macros, unused_imports)] + macro_rules! js_value_from_to_string { ($name:ident) => { impl From<$name> for JsValue { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 32d43b0..76b179a 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,6 +5,7 @@ mod filters; ))] mod header; mod header_macro; +#[cfg(feature = "is")] mod is; mod js; mod js_value_from_to_string; @@ -18,8 +19,12 @@ pub use filters::*; any(feature = "axum", feature = "actix", feature = "spin") ))] pub use header::*; +#[allow(unused_imports)] pub(crate) use header_macro::*; +#[cfg(feature = "is")] pub use is::*; +#[allow(unused_imports)] pub(crate) use js_value_from_to_string::*; pub use pausable::*; +#[allow(unused_imports)] pub(crate) use signal_filtered::*; diff --git a/src/utils/signal_filtered.rs b/src/utils/signal_filtered.rs index 1e7ad03..365c871 100644 --- a/src/utils/signal_filtered.rs +++ b/src/utils/signal_filtered.rs @@ -1,3 +1,5 @@ +#![allow(unused_macros, unused_imports)] + macro_rules! signal_filtered { ( $(#[$outer:meta])* diff --git a/src/watch_debounced.rs b/src/watch_debounced.rs index 2dbe3ef..c0b12a1 100644 --- a/src/watch_debounced.rs +++ b/src/watch_debounced.rs @@ -1,4 +1,4 @@ -use crate::{watch_with_options, DebounceOptions, WatchOptions}; +use crate::{watch_with_options, utils::DebounceOptions, WatchOptions}; use default_struct_builder::DefaultBuilder; use leptos::*; diff --git a/src/watch_throttled.rs b/src/watch_throttled.rs index 5fd585f..e70f5e0 100644 --- a/src/watch_throttled.rs +++ b/src/watch_throttled.rs @@ -1,4 +1,4 @@ -use crate::{watch_with_options, ThrottleOptions, WatchOptions}; +use crate::{watch_with_options, utils::ThrottleOptions, WatchOptions}; use default_struct_builder::DefaultBuilder; /// A throttled version of `leptos::watch`. From 3eadd9cf1a5765853c9ff99572983cc68a15dacc Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Thu, 22 Aug 2024 23:22:02 -0400 Subject: [PATCH 04/10] Feat: Update `vibrate` type to Rust type - Updated `vibrate` type to `Vec` to improve SSR and type safety. - Added new helper function `vibration_patter_to_jsvalue` to convert `Vec` to `JsValue`. --- src/use_web_notification.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index f34c9cd..0a3cefb 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -3,6 +3,7 @@ use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::*; use std::rc::Rc; +use wasm_bindgen::JsValue; /// Reactive [Notification API](https://developer.mozilla.org/en-US/docs/Web/API/Notification). /// @@ -282,7 +283,7 @@ pub struct UseWebNotificationOptions { /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. #[builder(into)] - vibrate: Option, + vibrate: Option>, /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -350,7 +351,7 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { } if let Some(vibrate) = &options.vibrate { - web_sys_options.set_vibrate(vibrate); + web_sys_options.set_vibrate(&vibration_pattern_to_jsvalue(vibrate)); } web_sys_options } @@ -417,7 +418,7 @@ pub struct ShowOptions { /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. #[builder(into)] - vibrate: Option, + vibrate: Option>, } #[cfg(not(feature = "ssr"))] @@ -460,7 +461,7 @@ impl ShowOptions { } if let Some(vibrate) = &self.vibrate { - options.set_vibrate(vibrate); + options.set_vibrate(&vibration_pattern_to_jsvalue(vibrate)); } } } @@ -476,6 +477,15 @@ fn browser_supports_notifications() -> bool { false } +/// Helper function to convert `Vec` into a `JsValue` array that represents a vibration pattern +fn vibration_pattern_to_jsvalue(pattern: &Vec) -> JsValue { + let array = js_sys::Array::new(); + for &value in pattern.iter() { + array.push(&JsValue::from(value)); + } + array.into() +} + #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] /// The permission to send notifications pub enum NotificationPermission { From 2443c695e9913a7cf5905920d1d2b95dfd022a31 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Thu, 22 Aug 2024 23:24:26 -0400 Subject: [PATCH 05/10] Chore: Apply cargo `fmt` to ensure code formatting - Reformatted the code for `watch_debounced` & `watch_throttled` to pass `cargo fmt --check` --- src/watch_debounced.rs | 2 +- src/watch_throttled.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/watch_debounced.rs b/src/watch_debounced.rs index c0b12a1..a8cb00a 100644 --- a/src/watch_debounced.rs +++ b/src/watch_debounced.rs @@ -1,4 +1,4 @@ -use crate::{watch_with_options, utils::DebounceOptions, WatchOptions}; +use crate::{utils::DebounceOptions, watch_with_options, WatchOptions}; use default_struct_builder::DefaultBuilder; use leptos::*; diff --git a/src/watch_throttled.rs b/src/watch_throttled.rs index e70f5e0..38db9ce 100644 --- a/src/watch_throttled.rs +++ b/src/watch_throttled.rs @@ -1,4 +1,4 @@ -use crate::{watch_with_options, utils::ThrottleOptions, WatchOptions}; +use crate::{utils::ThrottleOptions, watch_with_options, WatchOptions}; use default_struct_builder::DefaultBuilder; /// A throttled version of `leptos::watch`. From 5133c0308c847e3283d8bc6208826c5d91b2c879 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Fri, 23 Aug 2024 00:01:25 -0400 Subject: [PATCH 06/10] Doc: update `vibrate` doc type to reflect new type - Updated the `vibrate` type in the docs to Vec. --- src/use_web_notification.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 0a3cefb..fd730d6 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -281,7 +281,7 @@ pub struct UseWebNotificationOptions { #[builder(into)] silent: Option, - /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. #[builder(into)] vibrate: Option>, @@ -416,7 +416,7 @@ pub struct ShowOptions { #[builder(into)] silent: Option, - /// A JsValue array specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. #[builder(into)] vibrate: Option>, } From 2d3f5132161e037dd4580ea49ae3b55b7427f27c Mon Sep 17 00:00:00 2001 From: Maccesch Date: Fri, 23 Aug 2024 19:59:59 +0100 Subject: [PATCH 07/10] implemented different types support for sending and receiving using use_websocket --- CHANGELOG.md | 8 +++ Cargo.toml | 4 +- examples/Cargo.toml | 3 ++ examples/use_websocket/Cargo.toml | 2 +- examples/use_websocket/src/main.rs | 4 +- src/use_websocket.rs | 81 ++++++++++++++++-------------- 6 files changed, 59 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d5315c..1d62aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `use_prefers_reduced_motion` +### Breaking Change 🛠 + +- `use_websocket` now supports different types for sending and receiving messages + +### Change 🔥 + +- There is now a feature for almost every function to get better compile and rust-analyzer times. + ## [0.12.0] - 2024-08-14 > Make sure you also update `cargo-leptos` to the latest version if you use that. diff --git a/Cargo.toml b/Cargo.toml index de5940a..08472be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ homepage = "https://leptos-use.rs" actix-web = { version = "4", optional = true, default-features = false } async-trait = { version = "0.1", optional = true } cfg-if = "1" -codee = { version = "0.1", optional = true } +codee = { version = "0.2", optional = true } cookie = { version = "0.18", features = ["percent-encode"], optional = true } default-struct-builder = "0.5" futures-util = { version = "0.3", optional = true } @@ -39,7 +39,7 @@ wasm-bindgen-futures = "0.4" web-sys = { version = "=0.3.70", optional = true } [dev-dependencies] -codee = { version = "0.1", features = ["json_serde", "msgpack_serde", "base64", "prost"] } +codee = { version = "0.2", features = ["json_serde", "msgpack_serde", "base64", "prost"] } getrandom = { version = "0.2", features = ["js"] } leptos_meta = "0.6" rand = "0.8" diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 187bcf3..4d029f4 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -87,5 +87,8 @@ panic = "abort" [lib] +[workspace.dependencies] +codee = { version = "0.2" } + [package.metadata.leptos] lib-profile-release = "wasm-release" diff --git a/examples/use_websocket/Cargo.toml b/examples/use_websocket/Cargo.toml index 26ed9a6..7f8eb1c 100644 --- a/examples/use_websocket/Cargo.toml +++ b/examples/use_websocket/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] leptos = { version = "0.6", features = ["nightly", "csr"] } -codee = { version = "0.1", features = ["msgpack_serde"] } +codee = { workspace = true, features = ["msgpack_serde"] } console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_websocket/src/main.rs b/examples/use_websocket/src/main.rs index 477f3e2..5a3249c 100644 --- a/examples/use_websocket/src/main.rs +++ b/examples/use_websocket/src/main.rs @@ -33,7 +33,7 @@ fn Demo() -> impl IntoView { open, close, .. - } = use_websocket::("wss://echo.websocket.events/"); + } = use_websocket::("wss://echo.websocket.events/"); let send_message = move |_| { let m = Apple { @@ -101,7 +101,7 @@ fn Demo() -> impl IntoView { close: close2, message: message2, .. - } = use_websocket_with_options::( + } = use_websocket_with_options::( "wss://echo.websocket.events/", UseWebSocketOptions::default() .immediate(false) diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 51910e7..30bd122 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -3,14 +3,13 @@ use cfg_if::cfg_if; use leptos::{leptos_dom::helpers::TimeoutHandle, *}; use std::cell::Cell; +use std::marker::PhantomData; use std::rc::Rc; use std::time::Duration; use thiserror::Error; use crate::{core::ConnectionReadyState, ReconnectLimit}; -use codee::{ - CodecError, Decoder, Encoder, HybridCoderError, HybridDecoder, HybridEncoder, IsBinary, -}; +use codee::{CodecError, Decoder, Encoder, HybridCoderError, HybridDecoder, HybridEncoder}; use default_struct_builder::DefaultBuilder; use js_sys::Array; use wasm_bindgen::prelude::*; @@ -45,7 +44,7 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// open, /// close, /// .. -/// } = use_websocket::("wss://echo.websocket.events/"); +/// } = use_websocket::("wss://echo.websocket.events/"); /// /// let send_message = move |_| { /// send(&"Hello, world!".to_string()); @@ -98,7 +97,7 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// message, /// send, /// .. -/// } = use_websocket::("wss://some.websocket.server/"); +/// } = use_websocket::("wss://some.websocket.server/"); /// /// let send_data = move || { /// send(&SomeData { @@ -189,7 +188,7 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// message, /// send, /// .. -/// } = use_websocket::("ws:://some.websocket.io"); +/// } = use_websocket::("ws:://some.websocket.io"); /// /// provide_context(WebsocketContext::new(message, Rc::new(send.clone()))); /// # @@ -229,45 +228,47 @@ use web_sys::{BinaryType, CloseEvent, Event, MessageEvent, WebSocket}; /// ## Server-Side Rendering /// /// On the server the returned functions amount to no-ops. -pub fn use_websocket( +pub fn use_websocket( url: &str, ) -> UseWebSocketReturn< - T, + Tx, + Rx, impl Fn() + Clone + 'static, impl Fn() + Clone + 'static, - impl Fn(&T) + Clone + 'static, + impl Fn(&Tx) + Clone + 'static, > where - T: 'static, - C: Encoder + Decoder, - C: IsBinary>::Encoded>, - C: HybridDecoder>::Encoded, Error = >::Error>, - C: HybridEncoder>::Encoded, Error = >::Error>, + Tx: 'static, + Rx: 'static, + C: Encoder + Decoder, + C: HybridEncoder>::Encoded, Error = >::Error>, + C: HybridDecoder>::Encoded, Error = >::Error>, { - use_websocket_with_options::(url, UseWebSocketOptions::default()) + use_websocket_with_options::(url, UseWebSocketOptions::default()) } /// Version of [`use_websocket`] that takes `UseWebSocketOptions`. See [`use_websocket`] for how to use. #[allow(clippy::type_complexity)] -pub fn use_websocket_with_options( +pub fn use_websocket_with_options( url: &str, options: UseWebSocketOptions< - T, - HybridCoderError<>::Error>, - HybridCoderError<>::Error>, + Rx, + HybridCoderError<>::Error>, + HybridCoderError<>::Error>, >, ) -> UseWebSocketReturn< - T, + Tx, + Rx, impl Fn() + Clone + 'static, impl Fn() + Clone + 'static, - impl Fn(&T) + Clone + 'static, + impl Fn(&Tx) + Clone + 'static, > where - T: 'static, - C: Encoder + Decoder, - C: IsBinary>::Encoded>, - C: HybridDecoder>::Encoded, Error = >::Error>, - C: HybridEncoder>::Encoded, Error = >::Error>, + Tx: 'static, + Rx: 'static, + C: Encoder + Decoder, + C: HybridEncoder>::Encoded, Error = >::Error>, + C: HybridDecoder>::Encoded, Error = >::Error>, { let url = normalize_url(url); @@ -551,8 +552,8 @@ where let send = { let on_error = Rc::clone(&on_error); - move |value: &T| { - if C::is_binary() { + move |value: &Tx| { + if C::is_binary_encoder() { match C::encode_bin(value) { Ok(val) => send_bytes(&val), Err(err) => on_error(CodecError::Encode(err).into()), @@ -606,6 +607,7 @@ where open, close, send, + _marker: PhantomData, } } @@ -613,15 +615,15 @@ type RcFnBytes = Rc; /// Options for [`use_websocket_with_options`]. #[derive(DefaultBuilder)] -pub struct UseWebSocketOptions +pub struct UseWebSocketOptions where - T: ?Sized, + Rx: ?Sized, { /// `WebSocket` connect callback. on_open: Rc, /// `WebSocket` message callback for typed message decoded by codec. #[builder(skip)] - on_message: Rc, + on_message: Rc, /// `WebSocket` message callback for text. on_message_raw: Rc, /// `WebSocket` message callback for binary. @@ -644,7 +646,7 @@ where protocols: Option>, } -impl UseWebSocketOptions { +impl UseWebSocketOptions { /// `WebSocket` error callback. pub fn on_error(self, handler: F) -> Self where @@ -659,7 +661,7 @@ impl UseWebSocketOptions { /// `WebSocket` message callback for typed message decoded by codec. pub fn on_message(self, handler: F) -> Self where - F: Fn(&T) + 'static, + F: Fn(&Rx) + 'static, { Self { on_message: Rc::new(handler), @@ -668,7 +670,7 @@ impl UseWebSocketOptions { } } -impl Default for UseWebSocketOptions { +impl Default for UseWebSocketOptions { fn default() -> Self { Self { on_open: Rc::new(|_| {}), @@ -687,17 +689,18 @@ impl Default for UseWebSocketOptions { /// Return type of [`use_websocket`]. #[derive(Clone)] -pub struct UseWebSocketReturn +pub struct UseWebSocketReturn where - T: 'static, + Tx: 'static, + Rx: 'static, OpenFn: Fn() + Clone + 'static, CloseFn: Fn() + Clone + 'static, - SendFn: Fn(&T) + Clone + 'static, + SendFn: Fn(&Tx) + Clone + 'static, { /// The current state of the `WebSocket` connection. pub ready_state: Signal, /// Latest message received from `WebSocket`. - pub message: Signal>, + pub message: Signal>, /// The `WebSocket` instance. pub ws: Option, /// Opens the `WebSocket` connection @@ -706,6 +709,8 @@ where pub close: CloseFn, /// Sends data through the socket pub send: SendFn, + + _marker: PhantomData, } #[derive(Error, Debug)] From 856a64dd18c0dbca75509785673b4eda85db5542 Mon Sep 17 00:00:00 2001 From: BakerNet Date: Fri, 23 Aug 2024 18:02:02 -0700 Subject: [PATCH 08/10] fix error when cleanup happens after reconnect attempt is on timeout --- src/use_websocket.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 30bd122..e7e420c 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -302,7 +302,11 @@ where { let reconnect_ref: StoredValue>> = store_value(None); reconnect_ref.set_value({ + let unmounted = Rc::clone(&unmounted); + Some(Rc::new(move || { + let unmounted = Rc::clone(&unmounted); + if !manually_closed_ref.get_value() && !reconnect_limit.is_exceeded_by(reconnect_times_ref.get_value()) && ws_ref @@ -312,6 +316,9 @@ where reconnect_timer_ref.set_value( set_timeout_with_handle( move || { + if unmounted.get() { + return; + } if let Some(connect) = connect_ref.get_value() { connect(); reconnect_times_ref.update_value(|current| *current += 1); From 54a04ac382d361cb9bf2f1426882f2ec419ba6df Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Fri, 23 Aug 2024 23:39:42 -0400 Subject: [PATCH 09/10] Docs: Update vibration pattern documentation and convert helper function - Updated comment for `vibrate` to describe the `Vec` format for vibration patterns. - Modified `vibration_pattern_to_jsvalue` to accept a slice (`&[u16]`) and convert it to a `JsValue` array. --- src/use_web_notification.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index fd730d6..23f5f83 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -281,7 +281,8 @@ pub struct UseWebNotificationOptions { #[builder(into)] silent: Option, - /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` specifying the vibration pattern in milliseconds for vibrating and not vibrating. + /// The last entry can be a vibration since it stops automatically after each period. #[builder(into)] vibrate: Option>, @@ -416,7 +417,8 @@ pub struct ShowOptions { #[builder(into)] silent: Option, - /// A `Vec` value specifying the vibration pattern in which the device is vibrating and not vibrating. + /// A `Vec` specifying the vibration pattern in milliseconds for vibrating and not vibrating. + /// The last entry can be a vibration since it stops automatically after each period. #[builder(into)] vibrate: Option>, } @@ -477,8 +479,8 @@ fn browser_supports_notifications() -> bool { false } -/// Helper function to convert `Vec` into a `JsValue` array that represents a vibration pattern -fn vibration_pattern_to_jsvalue(pattern: &Vec) -> JsValue { +/// Helper function to convert a slice of `u16` into a `JsValue` array that represents a vibration pattern +fn vibration_pattern_to_jsvalue(pattern: &[u16]) -> JsValue { let array = js_sys::Array::new(); for &value in pattern.iter() { array.push(&JsValue::from(value)); From 97c678c4a1d1af2566646647d2755f70e1921262 Mon Sep 17 00:00:00 2001 From: Maccesch Date: Sat, 24 Aug 2024 12:38:11 +0100 Subject: [PATCH 10/10] fixed examples --- examples/ssr/Cargo.toml | 2 +- examples/use_broadcast_channel/Cargo.toml | 2 +- examples/use_cookie/Cargo.toml | 2 +- examples/use_storage/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml index 33e9575..8840456 100644 --- a/examples/ssr/Cargo.toml +++ b/examples/ssr/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -codee = "0.1" +codee.workspace = true console_error_panic_hook = "0.1" console_log = "1" cfg-if = "1" diff --git a/examples/use_broadcast_channel/Cargo.toml b/examples/use_broadcast_channel/Cargo.toml index 3cfcd3f..4331bf6 100644 --- a/examples/use_broadcast_channel/Cargo.toml +++ b/examples/use_broadcast_channel/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] leptos = { version = "0.6", features = ["nightly", "csr"] } -codee = "0.1" +codee.workspace = true console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_cookie/Cargo.toml b/examples/use_cookie/Cargo.toml index 2974155..eb64a66 100644 --- a/examples/use_cookie/Cargo.toml +++ b/examples/use_cookie/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] leptos = { version = "0.6", features = ["nightly", "csr"] } -codee = "0.1" +codee.workspace = true console_error_panic_hook = "0.1" console_log = "1" log = "0.4" diff --git a/examples/use_storage/Cargo.toml b/examples/use_storage/Cargo.toml index b8b2285..5dcff2f 100644 --- a/examples/use_storage/Cargo.toml +++ b/examples/use_storage/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -codee = { version = "0.1", features = ["json_serde"] } +codee = { workspace = true, features = ["json_serde"] } console_error_panic_hook = "0.1" console_log = "1" leptos = { version = "0.6", features = ["nightly", "csr"] }