From ed9f592c01c104498c11691a8d633dcbd72b0930 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Fri, 9 Aug 2024 14:05:24 +0800 Subject: [PATCH] fix: nightly mode --- demo/Cargo.toml | 7 ++--- thaw/Cargo.toml | 1 + thaw/src/anchor/mod.rs | 25 ++++++++--------- thaw/src/message_bar/message_bar.rs | 21 +++++++------- thaw_utils/Cargo.toml | 1 + thaw_utils/src/class_list.rs | 43 ++++++++++++++++++++++------- 6 files changed, 60 insertions(+), 38 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 791dfda..6b40b73 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -27,11 +27,8 @@ default = ["csr"] tracing = ["leptos/tracing"] csr = ["leptos/csr", "thaw/csr"] ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "thaw/ssr"] -hydrate = [ - "leptos/hydrate", - "thaw/hydrate", -] -nightly = ["leptos/nightly", "leptos_router/nightly"] +hydrate = ["leptos/hydrate", "thaw/hydrate"] +nightly = ["leptos/nightly", "leptos_router/nightly", "thaw/nightly"] # https://benw.is/posts/how-i-improved-my-rust-compile-times-by-seventy-five-percent#optimization-level diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index a0aabd2..69f33af 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -42,3 +42,4 @@ send_wrapper = "0.6" csr = ["leptos/csr", "thaw_components/csr", "thaw_utils/csr"] ssr = ["leptos/ssr", "thaw_components/ssr", "thaw_utils/ssr"] hydrate = ["leptos/hydrate", "thaw_components/hydrate", "thaw_utils/hydrate"] +nightly = ["leptos/nightly", "thaw_utils/nightly"] diff --git a/thaw/src/anchor/mod.rs b/thaw/src/anchor/mod.rs index 4bffb93..cd3a321 100644 --- a/thaw/src/anchor/mod.rs +++ b/thaw/src/anchor/mod.rs @@ -32,18 +32,6 @@ pub fn Anchor( id: String, } - impl OffsetTarget { - fn get_bounding_client_rect(&self) -> Option { - match self { - OffsetTarget::Selector(selector) => { - let el = document().query_selector(selector).ok().flatten()?; - Some(el.get_bounding_client_rect()) - } - OffsetTarget::Element(el) => Some(el.get_bounding_client_rect()), - } - } - } - let offset_target = send_wrapper::SendWrapper::new(offset_target); let on_scroll = move || { @@ -212,7 +200,18 @@ pub enum OffsetTarget { Element(Element), } - +#[cfg(any(feature = "csr", feature = "hydrate"))] +impl OffsetTarget { + fn get_bounding_client_rect(&self) -> Option { + match self { + OffsetTarget::Selector(selector) => { + let el = document().query_selector(selector).ok().flatten()?; + Some(el.get_bounding_client_rect()) + } + OffsetTarget::Element(el) => Some(el.get_bounding_client_rect()), + } + } +} impl From<&'static str> for OffsetTarget { fn from(value: &'static str) -> Self { diff --git a/thaw/src/message_bar/message_bar.rs b/thaw/src/message_bar/message_bar.rs index a983616..7a1da57 100644 --- a/thaw/src/message_bar/message_bar.rs +++ b/thaw/src/message_bar/message_bar.rs @@ -1,4 +1,4 @@ -use leptos::prelude::*; +use leptos::{either::EitherOf4, prelude::*}; use thaw_utils::{class_list, mount_style, StoredMaybeSignal}; #[component] @@ -6,7 +6,8 @@ pub fn MessageBar( #[prop(optional, into)] class: MaybeProp, #[prop(optional, into)] layout: MaybeSignal, /// Default designs announcement presets. - #[prop(optional, into)] intent: MaybeSignal, + #[prop(optional, into)] + intent: MaybeSignal, children: Children, ) -> impl IntoView { mount_style("message-bar", include_str!("./message-bar.css")); @@ -25,29 +26,29 @@ pub fn MessageBar(
{ move || match intent.get() { - MessageBarIntent::Info => view! { + MessageBarIntent::Info => EitherOf4::A(view! { - }, - MessageBarIntent::Success => view! { + }), + MessageBarIntent::Success => EitherOf4::B(view! { - }, - MessageBarIntent::Warning => view! { + }), + MessageBarIntent::Warning => EitherOf4::C(view! { - }, - MessageBarIntent::Error => view! { + }), + MessageBarIntent::Error => EitherOf4::D(view! { - }, + }), } } diff --git a/thaw_utils/Cargo.toml b/thaw_utils/Cargo.toml index 2769ef5..4c15381 100644 --- a/thaw_utils/Cargo.toml +++ b/thaw_utils/Cargo.toml @@ -24,3 +24,4 @@ send_wrapper = "0.6" csr = ["leptos/csr"] ssr = ["leptos/ssr", "leptos_meta/ssr"] hydrate = ["leptos/hydrate"] +nightly = ["leptos/nightly"] \ No newline at end of file diff --git a/thaw_utils/src/class_list.rs b/thaw_utils/src/class_list.rs index c42b80b..e511a23 100644 --- a/thaw_utils/src/class_list.rs +++ b/thaw_utils/src/class_list.rs @@ -1,6 +1,11 @@ +#[cfg(not(feature = "nightly"))] use leptos::{ - prelude::{MaybeProp, Memo, Oco, RenderEffect, RwSignal}, - reactive_graph::traits::{Get, Update, With, WithUntracked}, + prelude::{MaybeProp, Memo}, + reactive_graph::traits::Get, +}; +use leptos::{ + prelude::{Oco, RenderEffect, RwSignal}, + reactive_graph::traits::{Update, With, WithUntracked}, tachys::renderer::DomRenderer, }; use std::collections::HashSet; @@ -280,6 +285,22 @@ pub enum Class { Fn(Oco<'static, str>, Box bool>), } +pub trait IntoClassValue { + fn into_class_value(self) -> Option>; +} + +impl IntoClassValue for String { + fn into_class_value(self) -> Option> { + Some(self.into()) + } +} + +impl IntoClassValue for Option { + fn into_class_value(self) -> Option> { + self.map(|v| v.into()) + } +} + pub trait IntoClass { fn into_class(self) -> Class; } @@ -299,10 +320,10 @@ impl IntoClass for &'static str { impl IntoClass for T where T: Fn() -> U + 'static, - U: ToString, + U: IntoClassValue, { fn into_class(self) -> Class { - Class::FnString(Box::new(move || (self)().to_string().into())) + Class::FnOptionString(Box::new(move || (self)().into_class_value())) } } @@ -320,6 +341,13 @@ where } } +#[cfg(not(feature = "nightly"))] +impl IntoClass for MaybeProp { + fn into_class(self) -> Class { + Class::FnOptionString(Box::new(move || self.get().map(|c| Oco::from(c)))) + } +} + impl IntoClass for (&'static str, T) where T: Fn() -> bool + 'static, @@ -339,18 +367,13 @@ impl IntoClass for (&'static str, bool) { } } +#[cfg(not(feature = "nightly"))] impl IntoClass for (&'static str, Memo) { fn into_class(self) -> Class { Class::Fn(self.0.into(), Box::new(move || self.1.get())) } } -impl IntoClass for MaybeProp { - fn into_class(self) -> Class { - Class::FnOptionString(Box::new(move || self.get().map(|c| Oco::from(c)))) - } -} - impl IntoClass for (String, T) where T: Fn() -> bool + 'static,