From 1436c3ed5a917d681c62e4aa92fd8386a1654521 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 18 Jul 2022 13:15:07 +0900 Subject: [PATCH 1/5] document features automatically. --- packages/yew/src/app_handle.rs | 1 - packages/yew/src/functional/hooks/mod.rs | 8 -------- .../yew/src/functional/hooks/use_prepared_state/mod.rs | 1 - .../yew/src/functional/hooks/use_transitive_state/mod.rs | 1 - packages/yew/src/html/component/scope.rs | 1 - packages/yew/src/lib.rs | 1 + packages/yew/src/renderer.rs | 1 - 7 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/yew/src/app_handle.rs b/packages/yew/src/app_handle.rs index 5f6a9a04735..6594275f713 100644 --- a/packages/yew/src/app_handle.rs +++ b/packages/yew/src/app_handle.rs @@ -65,7 +65,6 @@ fn clear_element(host: &Element) { } } -#[cfg_attr(documenting, doc(cfg(feature = "hydration")))] #[cfg(feature = "hydration")] mod feat_hydration { use super::*; diff --git a/packages/yew/src/functional/hooks/mod.rs b/packages/yew/src/functional/hooks/mod.rs index be1cf62e4ba..5787cb56c98 100644 --- a/packages/yew/src/functional/hooks/mod.rs +++ b/packages/yew/src/functional/hooks/mod.rs @@ -3,14 +3,10 @@ mod use_context; mod use_effect; mod use_force_update; mod use_memo; -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] mod use_prepared_state; mod use_reducer; mod use_ref; mod use_state; -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] mod use_transitive_state; pub use use_callback::*; @@ -18,14 +14,10 @@ pub use use_context::*; pub use use_effect::*; pub use use_force_update::*; pub use use_memo::*; -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] pub use use_prepared_state::*; pub use use_reducer::*; pub use use_ref::*; pub use use_state::*; -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] pub use use_transitive_state::*; use crate::functional::HookContext; diff --git a/packages/yew/src/functional/hooks/use_prepared_state/mod.rs b/packages/yew/src/functional/hooks/use_prepared_state/mod.rs index c54f9de9f66..625ea0407ff 100644 --- a/packages/yew/src/functional/hooks/use_prepared_state/mod.rs +++ b/packages/yew/src/functional/hooks/use_prepared_state/mod.rs @@ -89,7 +89,6 @@ pub use feat_ssr::*; /// Whilst async closure is an unstable feature, the procedural macro will rewrite this to a /// closure that returns an async block automatically. You can use this hook with async closure /// in stable Rust. -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] pub use use_prepared_state_macro as use_prepared_state; // With SSR. #[doc(hidden)] diff --git a/packages/yew/src/functional/hooks/use_transitive_state/mod.rs b/packages/yew/src/functional/hooks/use_transitive_state/mod.rs index f8ef487b5cb..8dd0a09643c 100644 --- a/packages/yew/src/functional/hooks/use_transitive_state/mod.rs +++ b/packages/yew/src/functional/hooks/use_transitive_state/mod.rs @@ -55,7 +55,6 @@ pub use feat_ssr::*; /// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This /// type is used during client side rendering to deserialize the state prepared on the server /// side. -#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))] pub use use_transitive_state_macro as use_transitive_state; // With SSR. #[doc(hidden)] diff --git a/packages/yew/src/html/component/scope.rs b/packages/yew/src/html/component/scope.rs index 519d7e5a397..bf821025cfc 100644 --- a/packages/yew/src/html/component/scope.rs +++ b/packages/yew/src/html/component/scope.rs @@ -609,7 +609,6 @@ mod feat_csr { #[cfg(feature = "csr")] pub(crate) use feat_csr::*; -#[cfg_attr(documenting, doc(cfg(feature = "hydration")))] #[cfg(feature = "hydration")] mod feat_hydration { use wasm_bindgen::JsCast; diff --git a/packages/yew/src/lib.rs b/packages/yew/src/lib.rs index 5371cda33ee..a185e2e0e5f 100644 --- a/packages/yew/src/lib.rs +++ b/packages/yew/src/lib.rs @@ -1,6 +1,7 @@ #![allow(clippy::needless_doctest_main)] #![doc(html_logo_url = "https://yew.rs/img/logo.png")] #![cfg_attr(documenting, feature(doc_cfg))] +#![cfg_attr(documenting, feature(doc_auto_cfg))] #![cfg_attr( feature = "nightly", feature(fn_traits, async_closure, unboxed_closures) diff --git a/packages/yew/src/renderer.rs b/packages/yew/src/renderer.rs index fbf57fd1894..2d62a8d43a8 100644 --- a/packages/yew/src/renderer.rs +++ b/packages/yew/src/renderer.rs @@ -93,7 +93,6 @@ where } } -#[cfg_attr(documenting, doc(cfg(feature = "hydration")))] #[cfg(feature = "hydration")] mod feat_hydration { use super::*; From 02441078d94d7717b85be8c782d7e2d7753b7c05 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 18 Jul 2022 13:19:58 +0900 Subject: [PATCH 2/5] Document with `#[cfg(...)]`. --- packages/yew/src/app_handle.rs | 2 +- packages/yew/src/dom_bundle/subtree_root.rs | 2 +- packages/yew/src/renderer.rs | 4 ++-- packages/yew/src/server_renderer.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/yew/src/app_handle.rs b/packages/yew/src/app_handle.rs index 6594275f713..8aa085aef12 100644 --- a/packages/yew/src/app_handle.rs +++ b/packages/yew/src/app_handle.rs @@ -9,7 +9,7 @@ use crate::dom_bundle::BSubtree; use crate::html::{BaseComponent, NodeRef, Scope, Scoped}; /// An instance of an application. -#[cfg_attr(documenting, doc(cfg(feature = "csr")))] +#[cfg(feature = "csr")] #[derive(Debug)] pub struct AppHandle { /// `Scope` holder diff --git a/packages/yew/src/dom_bundle/subtree_root.rs b/packages/yew/src/dom_bundle/subtree_root.rs index 42c0a0ef542..1d86e8e01be 100644 --- a/packages/yew/src/dom_bundle/subtree_root.rs +++ b/packages/yew/src/dom_bundle/subtree_root.rs @@ -232,7 +232,7 @@ static BUBBLE_EVENTS: AtomicBool = AtomicBool::new(true); /// handler has no effect. /// /// This function should be called before any component is mounted. -#[cfg_attr(documenting, doc(cfg(feature = "csr")))] +#[cfg(feature = "csr")] pub fn set_event_bubbling(bubble: bool) { BUBBLE_EVENTS.store(bubble, Ordering::Relaxed); } diff --git a/packages/yew/src/renderer.rs b/packages/yew/src/renderer.rs index 2d62a8d43a8..fd8c5edb49d 100644 --- a/packages/yew/src/renderer.rs +++ b/packages/yew/src/renderer.rs @@ -14,7 +14,7 @@ thread_local! { /// Set a custom panic hook. /// Unless a panic hook is set through this function, Yew will /// overwrite any existing panic hook when an application is rendered with [Renderer]. -#[cfg_attr(documenting, doc(cfg(feature = "csr")))] +#[cfg(feature = "csr")] pub fn set_custom_panic_hook(hook: Box) + Sync + Send + 'static>) { std::panic::set_hook(hook); PANIC_HOOK_IS_SET.with(|hook_is_set| hook_is_set.set(true)); @@ -29,7 +29,7 @@ fn set_default_panic_hook() { /// The Yew Renderer. /// /// This is the main entry point of a Yew application. -#[cfg_attr(documenting, doc(cfg(feature = "csr")))] +#[cfg(feature = "csr")] #[derive(Debug)] #[must_use = "Renderer does nothing unless render() is called."] pub struct Renderer diff --git a/packages/yew/src/server_renderer.rs b/packages/yew/src/server_renderer.rs index 45c6c79c2e9..d31dd80aa7e 100644 --- a/packages/yew/src/server_renderer.rs +++ b/packages/yew/src/server_renderer.rs @@ -7,7 +7,7 @@ use crate::platform::io::{self, DEFAULT_BUF_SIZE}; use crate::platform::{run_pinned, spawn_local}; /// A Yew Server-side Renderer that renders on the current thread. -#[cfg_attr(documenting, doc(cfg(feature = "ssr")))] +#[cfg(feature = "ssr")] #[derive(Debug)] pub struct LocalServerRenderer where @@ -112,7 +112,7 @@ where /// the rendering process has finished. /// /// See [`yew::platform`] for more information. -#[cfg_attr(documenting, doc(cfg(feature = "ssr")))] +#[cfg(feature = "ssr")] pub struct ServerRenderer where COMP: BaseComponent, From 00fc74f15a128d6a81f5ef2827e2e61bd4199a7d Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 18 Jul 2022 13:29:01 +0900 Subject: [PATCH 3/5] Fix Clippy. --- packages/yew/src/functional/mod.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/packages/yew/src/functional/mod.rs b/packages/yew/src/functional/mod.rs index 82b6ba1ac09..01133b5cbd5 100644 --- a/packages/yew/src/functional/mod.rs +++ b/packages/yew/src/functional/mod.rs @@ -27,7 +27,6 @@ use std::rc::Rc; use wasm_bindgen::prelude::*; -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(all(feature = "hydration", feature = "ssr"))] use crate::html::RenderMode; use crate::html::{AnyScope, BaseComponent, Context, HtmlResult}; @@ -68,7 +67,6 @@ pub use yew_macro::hook; type ReRender = Rc; /// Primitives of a prepared state hook. -#[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(any(feature = "hydration", feature = "ssr"))] pub(crate) trait PreparedState { #[cfg(feature = "ssr")] @@ -83,7 +81,6 @@ pub(crate) trait Effect { /// A hook context to be passed to hooks. pub struct HookContext { pub(crate) scope: AnyScope, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(all(feature = "hydration", feature = "ssr"))] creation_mode: RenderMode, re_render: ReRender, @@ -91,14 +88,11 @@ pub struct HookContext { states: Vec>, effects: Vec>, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(any(feature = "hydration", feature = "ssr"))] prepared_states: Vec>, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] prepared_states_data: Vec>, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] prepared_state_counter: usize, @@ -111,29 +105,22 @@ impl HookContext { fn new( scope: AnyScope, re_render: ReRender, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] - #[cfg(all(feature = "hydration", feature = "ssr"))] - creation_mode: RenderMode, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] - #[cfg(feature = "hydration")] - prepared_state: Option<&str>, + #[cfg(all(feature = "hydration", feature = "ssr"))] creation_mode: RenderMode, + #[cfg(feature = "hydration")] prepared_state: Option<&str>, ) -> RefCell { RefCell::new(HookContext { scope, re_render, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(all(feature = "hydration", feature = "ssr"))] creation_mode, states: Vec::new(), - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(any(feature = "hydration", feature = "ssr"))] prepared_states: Vec::new(), effects: Vec::new(), - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] prepared_states_data: { match prepared_state { @@ -141,7 +128,6 @@ impl HookContext { None => Vec::new(), } }, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] prepared_state_counter: 0, @@ -187,7 +173,6 @@ impl HookContext { t } - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(any(feature = "hydration", feature = "ssr"))] pub(crate) fn next_prepared_state( &mut self, @@ -220,7 +205,6 @@ impl HookContext { #[inline(always)] fn prepare_run(&mut self) { - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] { self.prepared_state_counter = 0; @@ -277,15 +261,11 @@ impl HookContext { } } - #[cfg(any( - not(feature = "ssr"), - not(any(target_arch = "wasm32", feature = "tokio")) - ))] + #[cfg(not(feature = "ssr"))] fn prepare_state(&self) -> Option { None } - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "ssr")] fn prepare_state(&self) -> Option { if self.prepared_states.is_empty() { @@ -361,10 +341,8 @@ where hook_ctx: HookContext::new( scope, re_render, - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(all(feature = "hydration", feature = "ssr"))] ctx.creation_mode(), - #[cfg(any(target_arch = "wasm32", feature = "tokio"))] #[cfg(feature = "hydration")] ctx.prepared_state(), ), From 56b44120f13c4886a85aceaa7e68e00e689b6737 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 18 Jul 2022 13:38:17 +0900 Subject: [PATCH 4/5] Adjust unreleased docs header. --- api-docs/before-content.html | 4 ++-- api-docs/styles.css | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api-docs/before-content.html b/api-docs/before-content.html index acd9b0294ac..620e1d46150 100644 --- a/api-docs/before-content.html +++ b/api-docs/before-content.html @@ -1,4 +1,4 @@
-

This is unreleased documentation for Yew Next version.

-

For up-to-date documentation, see the latest version on docs.rs.

+
This is unreleased documentation for Yew Next version.
+
For up-to-date documentation, see the latest version on docs.rs.
diff --git a/api-docs/styles.css b/api-docs/styles.css index 9a6d18c087c..e4a6e60ad21 100644 --- a/api-docs/styles.css +++ b/api-docs/styles.css @@ -1,13 +1,16 @@ #unreleased-version-header { - background-color: rgb(77, 56, 0); + background-color: rgb(200, 237, 248); z-index: 400; - position: fixed; + position: absolute; left: 0; top: 0; right: 0; height: 70px; padding-top: 10px; + padding-bottom: 10px; text-align: center; + font-family: sans-serif; + box-shadow: 0 0 5px 0 rgb(100, 100, 100); } body { From 3593765f85ed6f1858c1cce315fb30b6efc7b38e Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 18 Jul 2022 13:43:26 +0900 Subject: [PATCH 5/5] Adapt dark mode as well. --- api-docs/styles.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api-docs/styles.css b/api-docs/styles.css index e4a6e60ad21..6df5e9397ea 100644 --- a/api-docs/styles.css +++ b/api-docs/styles.css @@ -13,6 +13,13 @@ box-shadow: 0 0 5px 0 rgb(100, 100, 100); } +@media (prefers-color-scheme: dark) { + #unreleased-version-header { + background-color: rgb(32, 43, 57); + box-shadow: 0 0 5px 0 black; + } +} + body { padding-top: 70px !important; }