Skip to content

Commit a984c73

Browse files
committed
feat!: form control and ShareValueExt
1 parent 4aa022e commit a984c73

File tree

16 files changed

+1094
-784
lines changed

16 files changed

+1094
-784
lines changed

packages/frender-form-control/src/element.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub trait FormControlElement<V: ?Sized + FormControlValueKind, Renderer: ?Sized>
1616

1717
type OnValueChangeEventListener<F: HandleFormControlValue<V> + 'static>: Default;
1818

19+
// TODO: split into init and update
1920
fn on_value_change<F: HandleFormControlValue<V> + 'static>(
2021
&mut self,
2122
renderer: &mut Renderer,

packages/frender-form-control/src/input.rs

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub use value_kind::InputValueKind;
22

3-
use async_str_iter::IntoAsyncStrIterator;
43
use frender_common::{
54
strings::{CsrStr, SsrStr},
65
Empty, PrimarilyBorrow,
@@ -10,10 +9,12 @@ use super::{
109
element::FormControlElement,
1110
value::{
1211
FormControlValue, FormControlValueKind, MaybeProvideFormControlValue,
13-
ProvideFormControlValue, UncontrolledWithDefaultValue,
12+
UncontrolledWithDefaultValue,
1413
},
1514
};
1615

16+
mod ssr;
17+
1718
/// A trait alias
1819
pub trait InputElement<Renderer: ?Sized>:
1920
FormControlElement<str, Renderer>
@@ -435,97 +436,3 @@ impl<
435436
self
436437
}
437438
}
438-
439-
mod ssr {
440-
use async_str_iter::{any_str::IterAnyStr, chain::Chain, option::IterOption};
441-
use frender_common::IntoStaticStr;
442-
use frender_ssr::html::{
443-
attr::{AssertSpaceAndHtmlAttributeName, SpaceAndHtmlAttribute},
444-
attr_value::AttrEqValue,
445-
};
446-
447-
use frender_dom::component::IntoSpaceAndHtmlAttributesOrEmpty;
448-
449-
use super::*;
450-
451-
impl<
452-
//
453-
Type: InputType,
454-
Value: InputValue,
455-
Checked: InputChecked,
456-
> IntoSpaceAndHtmlAttributesOrEmpty for InputDataModel<Type, Value, Checked>
457-
{
458-
type SpaceAndHtmlAttributesOrEmpty = Chain<
459-
// type
460-
IterOption<
461-
SpaceAndHtmlAttribute<
462-
//
463-
AssertSpaceAndHtmlAttributeName<&'static str>,
464-
AttrEqValue<IterAnyStr<
465-
<<Type as InputType>::InputTypeStr as SsrStr>::StaticStr
466-
>>,
467-
>,
468-
>,
469-
Chain<
470-
// value
471-
IterOption<
472-
SpaceAndHtmlAttribute<
473-
//
474-
AssertSpaceAndHtmlAttributeName<&'static str>,
475-
<Value::ValueKind as InputValueKind>::IntoInputValueAttrValue<
476-
//
477-
<Value as MaybeProvideFormControlValue<Value::ValueKind>>::ProvideFormControlValue,
478-
>,
479-
>,
480-
>,
481-
// checked
482-
IterOption<AssertSpaceAndHtmlAttributeName<&'static str>>,
483-
>,
484-
>;
485-
486-
fn into_space_and_html_attributes_or_empty(self) -> Self::SpaceAndHtmlAttributesOrEmpty {
487-
const TYPE: AssertSpaceAndHtmlAttributeName<&'static str> =
488-
AssertSpaceAndHtmlAttributeName::new_from_str(" type");
489-
const VALUE: AssertSpaceAndHtmlAttributeName<&'static str> =
490-
AssertSpaceAndHtmlAttributeName::new_from_str(" value");
491-
const CHECKED: AssertSpaceAndHtmlAttributeName<&'static str> =
492-
AssertSpaceAndHtmlAttributeName::new_from_str(" checked");
493-
494-
let Self {
495-
r#type: input_type,
496-
value,
497-
checked,
498-
} = self;
499-
500-
let input_type = Type::maybe_into_input_type_str(input_type)
501-
.map(|v| v.into_into_static_str().into_static_str());
502-
503-
let value_attr = Value::maybe_into_provide_form_control_value(value)
504-
.map(|value| {
505-
let input_type = input_type.as_ref().map_or("", |v| v.as_ref());
506-
Value::ValueKind::into_input_value_attr_value(value, input_type)
507-
})
508-
.map(|eq_value| SpaceAndHtmlAttribute(VALUE, eq_value));
509-
510-
let checked_attr = {
511-
let checked = Checked::maybe_into_provide_form_control_value(checked)
512-
.map_or(false, |checked| checked.provide_form_control_value(|v| *v));
513-
checked.then_some(CHECKED)
514-
};
515-
516-
Chain::new(
517-
input_type
518-
.map(|input_type| {
519-
let value = IterAnyStr::new(input_type);
520-
let value = AttrEqValue(value);
521-
SpaceAndHtmlAttribute(TYPE, value)
522-
})
523-
.into_async_str_iterator(),
524-
Chain::new(
525-
value_attr.into_async_str_iterator(),
526-
checked_attr.into_async_str_iterator(),
527-
),
528-
)
529-
}
530-
}
531-
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use async_str_iter::{
2+
any_str::IterAnyStr, chain::Chain, option::IterOption, IntoAsyncStrIterator as _,
3+
};
4+
use frender_common::{strings::SsrStr, IntoStaticStr};
5+
use frender_dom::component::IntoSpaceAndHtmlAttributesOrEmpty;
6+
use frender_ssr::html::{
7+
attr::{AssertSpaceAndHtmlAttributeName, SpaceAndHtmlAttribute},
8+
attr_value::AttrEqValue,
9+
};
10+
11+
use crate::value::{MaybeProvideFormControlValue, ProvideFormControlValue as _};
12+
13+
use super::{InputChecked, InputDataModel, InputType, InputValue, InputValueKind};
14+
15+
impl<
16+
//
17+
Type: InputType,
18+
Value: InputValue,
19+
Checked: InputChecked,
20+
> IntoSpaceAndHtmlAttributesOrEmpty for InputDataModel<Type, Value, Checked>
21+
{
22+
type SpaceAndHtmlAttributesOrEmpty = Chain<
23+
// type
24+
IterOption<
25+
SpaceAndHtmlAttribute<
26+
//
27+
AssertSpaceAndHtmlAttributeName<&'static str>,
28+
AttrEqValue<IterAnyStr<
29+
<<Type as InputType>::InputTypeStr as SsrStr>::StaticStr
30+
>>,
31+
>,
32+
>,
33+
Chain<
34+
// value
35+
IterOption<
36+
SpaceAndHtmlAttribute<
37+
//
38+
AssertSpaceAndHtmlAttributeName<&'static str>,
39+
<Value::ValueKind as InputValueKind>::IntoInputValueAttrValue<
40+
//
41+
<Value as MaybeProvideFormControlValue<Value::ValueKind>>::ProvideFormControlValue,
42+
>,
43+
>,
44+
>,
45+
// checked
46+
IterOption<AssertSpaceAndHtmlAttributeName<&'static str>>,
47+
>,
48+
>;
49+
50+
fn into_space_and_html_attributes_or_empty(self) -> Self::SpaceAndHtmlAttributesOrEmpty {
51+
const TYPE: AssertSpaceAndHtmlAttributeName<&'static str> =
52+
AssertSpaceAndHtmlAttributeName::new_from_str(" type");
53+
const VALUE: AssertSpaceAndHtmlAttributeName<&'static str> =
54+
AssertSpaceAndHtmlAttributeName::new_from_str(" value");
55+
const CHECKED: AssertSpaceAndHtmlAttributeName<&'static str> =
56+
AssertSpaceAndHtmlAttributeName::new_from_str(" checked");
57+
58+
let Self {
59+
r#type: input_type,
60+
value,
61+
checked,
62+
} = self;
63+
64+
let input_type = Type::maybe_into_input_type_str(input_type)
65+
.map(|v| v.into_into_static_str().into_static_str());
66+
67+
let value_attr = Value::maybe_into_provide_form_control_value(value)
68+
.map(|value| {
69+
let input_type = input_type.as_ref().map_or("", |v| v.as_ref());
70+
Value::ValueKind::into_input_value_attr_value(value, input_type)
71+
})
72+
.map(|eq_value| SpaceAndHtmlAttribute(VALUE, eq_value));
73+
74+
let checked_attr = {
75+
let checked = Checked::maybe_into_provide_form_control_value(checked)
76+
.map_or(false, |checked| checked.provide_form_control_value(|v| *v));
77+
checked.then_some(CHECKED)
78+
};
79+
80+
Chain::new(
81+
input_type
82+
.map(|input_type| {
83+
let value = IterAnyStr::new(input_type);
84+
let value = AttrEqValue(value);
85+
SpaceAndHtmlAttribute(TYPE, value)
86+
})
87+
.into_async_str_iterator(),
88+
Chain::new(
89+
value_attr.into_async_str_iterator(),
90+
checked_attr.into_async_str_iterator(),
91+
),
92+
)
93+
}
94+
}

0 commit comments

Comments
 (0)