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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
pub mod attribute;
pub mod child;
pub mod class;
pub mod event_delegation;
pub mod logging;
pub mod operations;
pub mod property;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub mod reconcile;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub mod render;
pub use attribute::*;
pub use child::*;
pub use class::*;
pub use logging::*;
pub use operations::*;
pub use property::*;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub use render::*;
pub use js_sys;
pub use wasm_bindgen;
pub use web_sys;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub type Element = web_sys::Element;
#[cfg(feature = "ssr")]
pub type Element = String;
#[cfg(not(any(feature = "csr", feature = "hydrate", feature = "ssr")))]
pub type Element = web_sys::Element;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub type Node = web_sys::Node;
#[cfg(feature = "ssr")]
pub type Node = String;
#[cfg(not(any(feature = "csr", feature = "hydrate", feature = "ssr")))]
pub type Node = web_sys::Node;
use leptos_reactive::Scope;
pub use wasm_bindgen::UnwrapThrowExt;
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub trait Mountable {
fn mount(&self, parent: &web_sys::Element);
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
impl Mountable for Element {
fn mount(&self, parent: &web_sys::Element) {
parent.append_child(self).unwrap_throw();
}
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
impl Mountable for Vec<Element> {
fn mount(&self, parent: &web_sys::Element) {
for element in self {
parent.append_child(element).unwrap_throw();
}
}
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub fn mount_to_body<T, F>(f: F)
where
F: Fn(Scope) -> T + 'static,
T: Mountable,
{
mount(document().body().unwrap_throw(), f)
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub fn mount<T, F>(parent: web_sys::HtmlElement, f: F)
where
F: Fn(Scope) -> T + 'static,
T: Mountable,
{
use leptos_reactive::create_scope;
let _ = create_scope(move |cx| {
(f(cx)).mount(&parent);
});
}
#[cfg(feature = "hydrate")]
pub fn hydrate<T, F>(parent: web_sys::HtmlElement, f: F)
where
F: Fn(Scope) -> T + 'static,
T: Mountable,
{
let _ = leptos_reactive::create_scope(move |cx| {
cx.start_hydration(&parent);
(f(cx));
cx.end_hydration();
});
}
#[cfg(feature = "csr")]
pub fn create_component<F, T>(cx: Scope, f: F) -> T
where
F: FnOnce() -> T,
{
cx.untrack(f)
}
#[cfg(not(feature = "csr"))]
pub fn create_component<F, T>(cx: Scope, f: F) -> T
where
F: FnOnce() -> T,
{
cx.with_next_context(f)
}
#[macro_export]
macro_rules! is_server {
() => {
cfg!(feature = "ssr")
};
}
#[macro_export]
macro_rules! is_dev {
() => {
cfg!(debug_assertions)
};
}