1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::{
attr,
Attribute,
Value,
};
use crate::{
Element,
Node,
};
pub trait Special {
fn get_key(&self) -> Option<&Value> {
self.get_value("key")
}
fn is_focused(&self) -> bool {
self.get_value("focus")
.map(|v| v.as_bool())
.flatten()
.unwrap_or(false)
}
fn get_value<'a>(&'a self, att_name: &'static str) -> Option<&'a Value>;
}
impl<MSG> Special for Node<MSG> {
fn get_value<'a>(&'a self, att_name: &'static str) -> Option<&'a Value> {
self.get_attribute_value(&&att_name)
.map(|att_values| {
att_values.first().map(|v| v.get_simple()).flatten()
})
.flatten()
}
}
impl<MSG> Special for Element<MSG> {
fn get_value<'a>(&'a self, att_name: &'static str) -> Option<&'a Value> {
self.get_attribute_value(&&att_name)
.map(|att_values| {
att_values.first().map(|v| v.get_simple()).flatten()
})
.flatten()
}
}
pub fn key<V, MSG>(v: V) -> Attribute<MSG>
where
V: Into<Value>,
{
attr("key", v)
}
pub fn skip<MSG>(v: bool) -> Attribute<MSG> {
attr("skip", v)
}
pub fn replace<MSG>(v: bool) -> Attribute<MSG> {
attr("replace", v)
}