diff --git a/Cargo.toml b/Cargo.toml index fe5bda5..1072d77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,6 @@ thaw_components = { version = "0.2.0-alpha", path = "./thaw_components" } thaw_macro = { version = "0.1.0-alpha", path = "./thaw_macro" } thaw_utils = { version = "0.1.0-alpha", path = "./thaw_utils" } -leptos = "0.7.0-beta" -leptos_meta = "0.7.0-beta" \ No newline at end of file +leptos = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } +leptos_meta = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } +leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "3dbedfc8710add4bc9a94fe27fa000fb180f393b" } diff --git a/demo/Cargo.toml b/demo/Cargo.toml index c44baa8..791dfda 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [dependencies] leptos = { workspace = true } leptos_meta = { workspace = true } -leptos_router = "0.7.0-beta" +leptos_router = { workspace = true } thaw = { path = "../thaw" } demo_markdown = { path = "../demo_markdown" } icondata = "0.3.0" diff --git a/thaw/src/auto_complete/mod.rs b/thaw/src/auto_complete/mod.rs index f0fb748..a44906b 100644 --- a/thaw/src/auto_complete/mod.rs +++ b/thaw/src/auto_complete/mod.rs @@ -10,7 +10,7 @@ use crate::{ use leptos::{context::Provider, either::Either, html, prelude::*}; use std::collections::HashMap; use thaw_components::{Binder, Follower, FollowerPlacement, FollowerWidth}; -use thaw_utils::{class_list, mount_style, ArcOneCallback, BoxOneCallback, Model, OptionalProp}; +use thaw_utils::{class_list, mount_style, ArcOneCallback, BoxOneCallback, Model}; #[slot] pub struct AutoCompletePrefix { @@ -25,7 +25,7 @@ pub struct AutoCompleteSuffix { #[component] pub fn AutoComplete( #[prop(optional, into)] value: Model, - #[prop(optional, into)] placeholder: OptionalProp>, + #[prop(optional, into)] placeholder: MaybeProp, #[prop(optional, into)] clear_after_select: MaybeSignal, #[prop(optional, into)] blur_after_select: MaybeSignal, #[prop(optional, into)] on_select: Option>, diff --git a/thaw/src/input/mod.rs b/thaw/src/input/mod.rs index e431d72..34c0133 100644 --- a/thaw/src/input/mod.rs +++ b/thaw/src/input/mod.rs @@ -24,7 +24,7 @@ pub fn Input( #[prop(optional, into)] input_type: MaybeSignal, /// Placeholder text for the input. #[prop(optional, into)] - placeholder: OptionalProp>, + placeholder: MaybeProp, #[prop(optional, into)] on_focus: Option>, #[prop(optional, into)] on_blur: Option>, /// Whether the input is disabled @@ -165,7 +165,7 @@ pub fn Input( on:blur=on_internal_blur class="thaw-input__input" disabled=move || disabled.get() - placeholder=placeholder.map(|p| move || p.get()) + placeholder=move || placeholder.get() node_ref=input_ref /> diff --git a/thaw/src/menu/menu_item.rs b/thaw/src/menu/menu_item.rs index 12ad46e..ebb2f7f 100644 --- a/thaw/src/menu/menu_item.rs +++ b/thaw/src/menu/menu_item.rs @@ -4,11 +4,11 @@ use crate::{ }; use leptos::prelude::*; use thaw_components::{Fallback, If, OptionComp, Then}; -use thaw_utils::{class_list, mount_style, OptionalMaybeSignal}; +use thaw_utils::{class_list, mount_style}; #[component] pub fn MenuItem( - #[prop(optional, into)] icon: OptionalMaybeSignal, + #[prop(optional, into)] icon: MaybeProp, #[prop(into)] value: MaybeSignal, #[prop(optional, into)] disabled: MaybeSignal, #[prop(optional, into)] class: MaybeProp, diff --git a/thaw/src/menu/mod.rs b/thaw/src/menu/mod.rs index 8d7fe02..4c637ed 100644 --- a/thaw/src/menu/mod.rs +++ b/thaw/src/menu/mod.rs @@ -7,14 +7,13 @@ use leptos::{ev, html::Div, leptos_dom::helpers::TimeoutHandle, prelude::*}; use std::time::Duration; use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement}; use thaw_utils::{ - add_event_listener, call_on_click_outside, class_list, mount_style, ArcOneCallback, - BoxCallback, OptionalProp, + add_event_listener, call_on_click_outside, class_list, mount_style, ArcOneCallback, BoxCallback, }; #[slot] pub struct MenuTrigger { #[prop(optional, into)] - class: OptionalProp>, + class: MaybeProp, children: Children, } @@ -103,7 +102,7 @@ pub fn Menu( view! {
, - #[prop(optional, into)] justify: OptionalMaybeSignal, + #[prop(optional, into)] align: MaybeProp, + #[prop(optional, into)] justify: MaybeProp, #[prop(optional, into)] class: MaybeProp, children: ChildrenFragment, ) -> impl IntoView { diff --git a/thaw_utils/src/optional_prop.rs b/thaw_utils/src/optional_prop.rs index bcda1c3..ba163a1 100644 --- a/thaw_utils/src/optional_prop.rs +++ b/thaw_utils/src/optional_prop.rs @@ -1,4 +1,7 @@ -use leptos::prelude::{MaybeSignal, Memo, ReadSignal, RwSignal, Signal}; +use leptos::{ + prelude::{MaybeSignal, Memo, ReadSignal, RwSignal, Signal}, + reactive_graph::owner::Storage, +}; use std::ops::{Deref, DerefMut}; use crate::BoxOneCallback; @@ -58,6 +61,7 @@ impl From<&str> for OptionalProp { } } +/// TODO remove signal impl From<&str> for OptionalProp> { fn from(value: &str) -> Self { Self(Some(MaybeSignal::from(value.to_string()))) @@ -88,8 +92,11 @@ impl From> for OptionalProp> { } } -impl From> for OptionalProp> { - fn from(value: Signal) -> Self { +impl From> for OptionalProp> +where + S: Storage, +{ + fn from(value: Signal) -> Self { Self(Some(MaybeSignal::from(value))) } } diff --git a/thaw_utils/src/signals/mod.rs b/thaw_utils/src/signals/mod.rs index a8b3364..d91f8c0 100644 --- a/thaw_utils/src/signals/mod.rs +++ b/thaw_utils/src/signals/mod.rs @@ -1,11 +1,9 @@ mod component_ref; mod model; -mod optional_maybe_signal; mod signal_watch; mod stored_maybe_signal; pub use component_ref::ComponentRef; pub use model::{Model, OptionModel, VecModel}; -pub use optional_maybe_signal::OptionalMaybeSignal; pub use signal_watch::SignalWatch; pub use stored_maybe_signal::StoredMaybeSignal; diff --git a/thaw_utils/src/signals/model.rs b/thaw_utils/src/signals/model.rs index 5c8f86c..6f0b01a 100644 --- a/thaw_utils/src/signals/model.rs +++ b/thaw_utils/src/signals/model.rs @@ -6,18 +6,20 @@ pub use vec_model::VecModel; use leptos::reactive_graph::{ computed::Memo, + owner::{Storage, SyncStorage}, signal::{ReadSignal, RwSignal, WriteSignal}, traits::{DefinedAt, IsDisposed, Set, Update, With, WithUntracked}, wrappers::read::Signal, }; -pub struct Model +pub struct Model where T: 'static, + S: Storage, { - read: Signal, - write: WriteSignal, - on_write: Option>, + read: Signal, + write: WriteSignal, + on_write: Option>, } impl Default for Model { @@ -26,13 +28,16 @@ impl Default for Model { } } -impl Clone for Model { +impl Clone for Model +where + S: Storage, +{ fn clone(&self) -> Self { *self } } -impl Copy for Model {} +impl Copy for Model where S: Storage {} impl Model { fn new(value: T) -> Self { @@ -45,9 +50,12 @@ impl Model { } } -impl DefinedAt for Model { +impl DefinedAt for Model +where + S: Storage, +{ fn defined_at(&self) -> Option<&'static std::panic::Location<'static>> { - todo!() + self.read.defined_at() } } @@ -82,7 +90,10 @@ impl Update for Model { } } -impl IsDisposed for Model { +impl IsDisposed for Model +where + S: Storage, +{ fn is_disposed(&self) -> bool { self.write.is_disposed() } @@ -105,8 +116,11 @@ impl From> for Model { } } -impl From<(Signal, WriteSignal)> for Model { - fn from((read, write): (Signal, WriteSignal)) -> Self { +impl From<(Signal, WriteSignal)> for Model +where + S: Storage, +{ + fn from((read, write): (Signal, WriteSignal)) -> Self { Self { read, write, diff --git a/thaw_utils/src/signals/model/option_model.rs b/thaw_utils/src/signals/model/option_model.rs index 618d41a..37bb30b 100644 --- a/thaw_utils/src/signals/model/option_model.rs +++ b/thaw_utils/src/signals/model/option_model.rs @@ -1,19 +1,21 @@ use leptos::reactive_graph::{ computed::Memo, + owner::{Storage, SyncStorage}, signal::{ReadSignal, RwSignal, WriteSignal}, traits::{Get, GetUntracked, Set, With, WithUntracked}, wrappers::read::Signal, }; -pub enum OptionModel +pub enum OptionModel where T: 'static, + S: Storage + Storage>, { - T(Signal, WriteSignal, Option>), + T(Signal, WriteSignal, Option>), Option( - Signal>, - WriteSignal>, - Option>>, + Signal, S>, + WriteSignal, S>, + Option, S>>, ), } @@ -23,13 +25,16 @@ impl Default for OptionModel { } } -impl Clone for OptionModel { +impl Clone for OptionModel +where + S: Storage + Storage>, +{ fn clone(&self) -> Self { *self } } -impl Copy for OptionModel {} +impl Copy for OptionModel where S: Storage + Storage> {} impl OptionModel { fn new(value: T) -> Self { @@ -112,14 +117,20 @@ impl From>> for OptionModel { } } -impl From<(Signal, WriteSignal)> for OptionModel { - fn from((read, write): (Signal, WriteSignal)) -> Self { +impl From<(Signal, WriteSignal)> for OptionModel +where + S: Storage + Storage>, +{ + fn from((read, write): (Signal, WriteSignal)) -> Self { Self::T(read, write, None) } } -impl From<(Signal>, WriteSignal>)> for OptionModel { - fn from((read, write): (Signal>, WriteSignal>)) -> Self { +impl From<(Signal, S>, WriteSignal, S>)> for OptionModel +where + S: Storage + Storage>, +{ + fn from((read, write): (Signal, S>, WriteSignal, S>)) -> Self { Self::Option(read, write, None) } } diff --git a/thaw_utils/src/signals/model/vec_model.rs b/thaw_utils/src/signals/model/vec_model.rs index d6ab1b8..37f3ffc 100644 --- a/thaw_utils/src/signals/model/vec_model.rs +++ b/thaw_utils/src/signals/model/vec_model.rs @@ -2,26 +2,28 @@ use leptos::{ prelude::Update, reactive_graph::{ computed::Memo, + owner::{Storage, SyncStorage}, signal::{ReadSignal, RwSignal, WriteSignal}, traits::{GetUntracked, Set, With, WithUntracked}, wrappers::read::Signal, }, }; -pub enum VecModel +pub enum VecModel where T: 'static, + S: Storage + Storage> + Storage>, { - T(Signal, WriteSignal, Option>), + T(Signal, WriteSignal, Option>), Option( - Signal>, - WriteSignal>, - Option>>, + Signal, S>, + WriteSignal, S>, + Option, S>>, ), Vec( - Signal>, - WriteSignal>, - Option>>, + Signal, S>, + WriteSignal, S>, + Option, S>>, ), } @@ -31,13 +33,16 @@ impl Default for VecModel { } } -impl Clone for VecModel { +impl Clone for VecModel +where + S: Storage + Storage> + Storage>, +{ fn clone(&self) -> Self { *self } } -impl Copy for VecModel {} +impl Copy for VecModel where S: Storage + Storage> + Storage> {} impl VecModel { fn new(value: T) -> Self { @@ -192,20 +197,29 @@ impl From>> for VecModel { } } -impl From<(Signal, WriteSignal)> for VecModel { - fn from((read, write): (Signal, WriteSignal)) -> Self { +impl From<(Signal, WriteSignal)> for VecModel +where + S: Storage + Storage> + Storage>, +{ + fn from((read, write): (Signal, WriteSignal)) -> Self { Self::T(read, write, None) } } -impl From<(Signal>, WriteSignal>)> for VecModel { - fn from((read, write): (Signal>, WriteSignal>)) -> Self { +impl From<(Signal, S>, WriteSignal, S>)> for VecModel +where + S: Storage + Storage> + Storage>, +{ + fn from((read, write): (Signal, S>, WriteSignal, S>)) -> Self { Self::Option(read, write, None) } } -impl From<(Signal>, WriteSignal>)> for VecModel { - fn from((read, write): (Signal>, WriteSignal>)) -> Self { +impl From<(Signal, S>, WriteSignal, S>)> for VecModel +where + S: Storage + Storage> + Storage>, +{ + fn from((read, write): (Signal, S>, WriteSignal, S>)) -> Self { Self::Vec(read, write, None) } } diff --git a/thaw_utils/src/signals/optional_maybe_signal.rs b/thaw_utils/src/signals/optional_maybe_signal.rs deleted file mode 100644 index d43b3be..0000000 --- a/thaw_utils/src/signals/optional_maybe_signal.rs +++ /dev/null @@ -1,86 +0,0 @@ -use leptos::prelude::*; -use std::ops::Deref; - -pub struct OptionalMaybeSignal(MaybeSignal>); - -impl Default for OptionalMaybeSignal { - fn default() -> Self { - Self(MaybeSignal::Static(None)) - } -} - -impl Copy for OptionalMaybeSignal {} - -impl Clone for OptionalMaybeSignal { - fn clone(&self) -> Self { - Self(self.0.clone()) - } -} - -impl Deref for OptionalMaybeSignal { - type Target = MaybeSignal>; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl From for OptionalMaybeSignal { - fn from(value: T) -> Self { - Self(MaybeSignal::Static(Some(value))) - } -} - -impl From> for OptionalMaybeSignal { - fn from(value: Option) -> Self { - Self(MaybeSignal::Static(value)) - } -} - -impl From>> for OptionalMaybeSignal { - fn from(value: ReadSignal>) -> Self { - Self(MaybeSignal::Dynamic(value.into())) - } -} - -impl From>> for OptionalMaybeSignal { - fn from(value: RwSignal>) -> Self { - Self(MaybeSignal::Dynamic(value.into())) - } -} - -impl From>> for OptionalMaybeSignal { - fn from(value: Memo>) -> Self { - Self(MaybeSignal::Dynamic(value.into())) - } -} - -impl From>> for OptionalMaybeSignal { - fn from(value: Signal>) -> Self { - Self(MaybeSignal::Dynamic(value)) - } -} - -impl From>> for OptionalMaybeSignal { - fn from(value: MaybeSignal>) -> Self { - Self(value) - } -} - -// TODO -// #[cfg(test)] -// mod test { -// use super::OptionalMaybeSignal; -// use leptos::{create_runtime, MaybeSignal}; - -// #[test] -// fn into() { -// let runtime = create_runtime(); - -// let _: MaybeSignal = 12.into(); -// let _: OptionalMaybeSignal = Some(12).into(); -// let _: OptionalMaybeSignal = MaybeSignal::Static(Some(12)).into(); - -// runtime.dispose(); -// } -// } diff --git a/thaw_utils/src/signals/stored_maybe_signal.rs b/thaw_utils/src/signals/stored_maybe_signal.rs index b191509..bf5f810 100644 --- a/thaw_utils/src/signals/stored_maybe_signal.rs +++ b/thaw_utils/src/signals/stored_maybe_signal.rs @@ -1,21 +1,36 @@ use leptos::reactive_graph::{ - owner::StoredValue, + owner::{Storage, StoredValue, SyncStorage}, traits::{DefinedAt, With, WithUntracked}, wrappers::read::{MaybeSignal, Signal}, }; -#[derive(Clone)] -pub enum StoredMaybeSignal +pub enum StoredMaybeSignal where T: 'static, + S: Storage, { - StoredValue(StoredValue), - Signal(Signal), + StoredValue(StoredValue), + Signal(Signal), } -impl Copy for StoredMaybeSignal {} +impl Clone for StoredMaybeSignal +where + S: Storage, +{ + fn clone(&self) -> Self { + match self { + Self::StoredValue(v) => Self::StoredValue(v.clone()), + Self::Signal(s) => Self::Signal(s.clone()), + } + } +} -impl DefinedAt for StoredMaybeSignal { +impl Copy for StoredMaybeSignal where S: Storage {} + +impl DefinedAt for StoredMaybeSignal +where + S: Storage, +{ fn defined_at(&self) -> Option<&'static std::panic::Location<'static>> { match self { StoredMaybeSignal::StoredValue(value) => value.defined_at(),