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
mod basic_element;
mod container;
pub mod create;
mod element;
mod enclose;
pub mod events;
pub mod prelude;
mod replaceable;
mod slot;
pub mod state_slice;
mod style_storage;
mod svg_element;
pub mod web_str;

pub use basic_element::{BasicElement, RawElement};
pub use container::*;
pub use create::components as cmp;
pub use hobo_css as css;
pub use element::Element;
#[doc(inline)]
pub use events::*;
pub use hobo_derive::*;
#[doc(hidden)]
pub use paste;
pub use replaceable::*;
pub use slot::*;
pub use web_sys;

fn dom() -> web_sys::Document { web_sys::window().expect("no window").document().expect("no document") }

#[derive(Default)]
pub struct Context {
	style_storage: style_storage::StyleStorage,
}

thread_local! {
	static CONTEXT: Context = Default::default();
}

/// Trait for hobo components with textual contents
pub trait SetText<T>: RawElement<RawElementType = T>
where
	T: AsRef<web_sys::Element> + AsRef<web_sys::HtmlElement>,
{
	fn set_text<'a>(&self, x: impl Into<std::borrow::Cow<'a, str>>) {
		let html_element: &web_sys::HtmlElement = self.raw_element().as_ref();
		html_element.set_inner_text(&x.into());
	}

	fn text<'a>(self, x: impl Into<std::borrow::Cow<'a, str>>) -> Self
	where
		Self: Sized,
	{
		self.set_text(x);
		self
	}
}

impl<T, E> SetText<E> for T
where
	T: RawElement<RawElementType = E>,
	E: AsRef<web_sys::Element> + AsRef<web_sys::HtmlElement>,
{}