From 40b369d36a5061f79a790cee7d30f7e5d942b1d0 Mon Sep 17 00:00:00 2001 From: Joshua McQuistan Date: Tue, 7 Nov 2023 10:13:55 +0000 Subject: [PATCH 1/4] Remove use of --cfg=web_sys_unstable_apis --- .cargo/config.toml | 3 --- Cargo.toml | 3 --- examples/.cargo/config.toml | 2 -- examples/use_element_size/.cargo/config.toml | 2 -- src/lib.rs | 14 ++++---------- src/use_element_size.rs | 7 ++----- src/use_resize_observer.rs | 7 ++----- template/.ffizer.yaml | 4 ---- .../{{ module }}/{{ function_name }}.ffizer.hbs.rs | 3 --- 9 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 .cargo/config.toml delete mode 100644 examples/.cargo/config.toml delete mode 100644 examples/use_element_size/.cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index b891103..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,3 +0,0 @@ -[unstable] -rustflags = ["--cfg=web_sys_unstable_apis"] -rustdocflags = ["--cfg=web_sys_unstable_apis"] \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5c557e6..1c7a7c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,3 @@ ssr = [] [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg=web_sys_unstable_apis"] -rustc-args = ["--cfg=web_sys_unstable_apis"] - diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml deleted file mode 100644 index c87f326..0000000 --- a/examples/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustflags = ["--cfg=web_sys_unstable_apis", "--cfg=has_std"] diff --git a/examples/use_element_size/.cargo/config.toml b/examples/use_element_size/.cargo/config.toml deleted file mode 100644 index 8467175..0000000 --- a/examples/use_element_size/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustflags = ["--cfg=web_sys_unstable_apis"] diff --git a/src/lib.rs b/src/lib.rs index a9700c1..811846c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ // #![feature(doc_cfg)] //! Collection of essential Leptos utilities inspired by SolidJS USE / VueUse -use cfg_if::cfg_if; - pub mod core; #[cfg(feature = "docs")] pub mod docs; @@ -12,14 +10,6 @@ pub mod math; pub mod storage; pub mod utils; -cfg_if! { if #[cfg(web_sys_unstable_apis)] { - mod use_element_size; - mod use_resize_observer; - - pub use use_element_size::*; - pub use use_resize_observer::*; -}} - mod is_err; mod is_none; mod is_ok; @@ -38,6 +28,7 @@ mod use_document_visibility; mod use_draggable; mod use_drop_zone; mod use_element_hover; +mod use_element_size; mod use_element_visibility; mod use_event_listener; mod use_favicon; @@ -54,6 +45,7 @@ mod use_mutation_observer; mod use_preferred_contrast; mod use_preferred_dark; mod use_raf_fn; +mod use_resize_observer; mod use_scroll; mod use_service_worker; mod use_sorted; @@ -90,6 +82,7 @@ pub use use_document_visibility::*; pub use use_draggable::*; pub use use_drop_zone::*; pub use use_element_hover::*; +pub use use_element_size::*; pub use use_element_visibility::*; pub use use_event_listener::*; pub use use_favicon::*; @@ -106,6 +99,7 @@ pub use use_mutation_observer::*; pub use use_preferred_contrast::*; pub use use_preferred_dark::*; pub use use_raf_fn::*; +pub use use_resize_observer::*; pub use use_scroll::*; pub use use_service_worker::*; pub use use_sorted::*; diff --git a/src/use_element_size.rs b/src/use_element_size.rs index 8831505..273af57 100644 --- a/src/use_element_size.rs +++ b/src/use_element_size.rs @@ -12,9 +12,6 @@ cfg_if! { if #[cfg(not(feature = "ssr"))] { /// Reactive size of an HTML element. /// -/// > This function requires `--cfg=web_sys_unstable_apis` to be activated as -/// [described in the wasm-bindgen guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html). -/// /// Please refer to [ResizeObserver on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) /// for more details. /// @@ -25,12 +22,12 @@ cfg_if! { if #[cfg(not(feature = "ssr"))] { /// ## Usage /// /// ``` -/// # use leptos::*; +/// # use leptos::{html::Div, *}; /// # use leptos_use::{use_element_size, UseElementSizeReturn}; /// # /// # #[component] /// # fn Demo() -> impl IntoView { -/// let el = create_node_ref(); +/// let el = create_node_ref::
(); /// /// let UseElementSizeReturn { width, height } = use_element_size(el); /// diff --git a/src/use_resize_observer.rs b/src/use_resize_observer.rs index 2e35e85..07e5dd4 100644 --- a/src/use_resize_observer.rs +++ b/src/use_resize_observer.rs @@ -12,9 +12,6 @@ cfg_if! { if #[cfg(not(feature = "ssr"))] { /// Reports changes to the dimensions of an Element's content or the border-box. /// -/// > This function requires `--cfg=web_sys_unstable_apis` to be activated as -/// [described in the wasm-bindgen guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html). -/// /// Please refer to [ResizeObserver on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) /// for more details. /// @@ -25,12 +22,12 @@ cfg_if! { if #[cfg(not(feature = "ssr"))] { /// ## Usage /// /// ``` -/// # use leptos::*; +/// # use leptos::{html::Div, *}; /// # use leptos_use::use_resize_observer; /// # /// # #[component] /// # fn Demo() -> impl IntoView { -/// let el = create_node_ref(); +/// let el = create_node_ref::
(); /// let (text, set_text) = create_signal("".to_string()); /// /// use_resize_observer( diff --git a/template/.ffizer.yaml b/template/.ffizer.yaml index cafee3e..58c6216 100644 --- a/template/.ffizer.yaml +++ b/template/.ffizer.yaml @@ -3,10 +3,6 @@ variables: ask: Name of the function - name: category ask: Documentation category (lower case) - - name: unstable_apis - default_value: "false" - ask: Does the function require `--cfg=web_sys_unstable_apis` to be activated? - select_in_values: ["true", "false"] - name: module default_value: "" ask: Module [optional] diff --git a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs index 0edb6ba..3217414 100644 --- a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs +++ b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs @@ -3,9 +3,6 @@ use leptos::*; ///{{#if (eq unstable_apis "true")}} /// -/// > This function requires `--cfg=web_sys_unstable_apis` to be activated as -/// [described in the wasm-bindgen guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html).{{/if}} -/// /// ## Demo /// /// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/{{ function_name }}) From e242834b665f69c47a2fe6d76c010a668e8b74af Mon Sep 17 00:00:00 2001 From: Joshua McQuistan Date: Wed, 8 Nov 2023 11:38:07 +0000 Subject: [PATCH 2/4] Specify minimum wasm-bindgen version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1c7a7c1..c558d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ num = { version = "0.4", optional = true } paste = "1" serde = { version = "1", optional = true } serde_json = { version = "1", optional = true } -wasm-bindgen = "0.2" +wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4" [dependencies.web-sys] From f918da96884618cdedf2ed2602e49ddde4c06ba6 Mon Sep 17 00:00:00 2001 From: Joshua McQuistan Date: Fri, 10 Nov 2023 17:14:14 +0000 Subject: [PATCH 3/4] Revert remove use of --cfg=web_sys_unstable_apis for templates --- template/.ffizer.yaml | 4 ++++ template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/template/.ffizer.yaml b/template/.ffizer.yaml index 58c6216..cafee3e 100644 --- a/template/.ffizer.yaml +++ b/template/.ffizer.yaml @@ -3,6 +3,10 @@ variables: ask: Name of the function - name: category ask: Documentation category (lower case) + - name: unstable_apis + default_value: "false" + ask: Does the function require `--cfg=web_sys_unstable_apis` to be activated? + select_in_values: ["true", "false"] - name: module default_value: "" ask: Module [optional] diff --git a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs index 3217414..0edb6ba 100644 --- a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs +++ b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs @@ -3,6 +3,9 @@ use leptos::*; ///{{#if (eq unstable_apis "true")}} /// +/// > This function requires `--cfg=web_sys_unstable_apis` to be activated as +/// [described in the wasm-bindgen guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html).{{/if}} +/// /// ## Demo /// /// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/{{ function_name }}) From 1d08beaa3e454840fa4a71942dedb4708ed6fb50 Mon Sep 17 00:00:00 2001 From: Joshua McQuistan Date: Fri, 10 Nov 2023 18:13:56 +0000 Subject: [PATCH 4/4] Problem: clippy says Default impl can be derived --- src/use_element_size.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/use_element_size.rs b/src/use_element_size.rs index 273af57..bc6a226 100644 --- a/src/use_element_size.rs +++ b/src/use_element_size.rs @@ -172,7 +172,7 @@ where } } -#[derive(DefaultBuilder)] +#[derive(DefaultBuilder, Default)] /// Options for [`use_element_size_with_options`]. pub struct UseElementSizeOptions { /// Initial size returned before any measurements on the `target` are done. Also the value reported @@ -184,15 +184,6 @@ pub struct UseElementSizeOptions { pub box_: Option, } -impl Default for UseElementSizeOptions { - fn default() -> Self { - Self { - initial_size: Size::default(), - box_: None, - } - } -} - /// The return value of [`use_element_size`]. pub struct UseElementSizeReturn { /// The width of the element.