diff --git a/src/use_document.rs b/src/use_document.rs index dfbf8b7..126fcd0 100644 --- a/src/use_document.rs +++ b/src/use_document.rs @@ -1,11 +1,15 @@ use cfg_if::cfg_if; +use js_sys::Function; use std::ops::Deref; use crate::core::impl_ssr_safe_method; #[cfg(not(feature = "ssr"))] use leptos::*; use wasm_bindgen::JsValue; -use web_sys::NodeList; +use web_sys::{ + Document, Element, HtmlCollection, HtmlElement, HtmlHeadElement, Location, NodeList, + VisibilityState, Window, +}; /// SSR safe `document()`. /// This returns just a new-type wrapper around `Option`. @@ -39,10 +43,10 @@ pub fn use_document() -> UseDocument { /// Return type of [`use_document`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct UseDocument(Option); +pub struct UseDocument(Option); impl Deref for UseDocument { - type Target = Option; + type Target = Option; fn deref(&self) -> &Self::Target { &self.0 } @@ -51,22 +55,205 @@ impl Deref for UseDocument { impl UseDocument { impl_ssr_safe_method!( /// Returns `Some(Document)` in the Browser. `None` otherwise. - body(&self) -> Option; + body(&self) -> Option; .unwrap_or_default() ); impl_ssr_safe_method!( /// Returns the active (focused) `Some(web_sys::Element)` in the Browser. `None` otherwise. - active_element(&self) -> Option; + active_element(&self) -> Option; .unwrap_or_default() ); impl_ssr_safe_method!( - query_selector(&self, selector: &str) -> Result, JsValue>; + query_selector(&self, selector: &str) -> Result, JsValue>; .unwrap_or(Ok(None)) ); impl_ssr_safe_method!( query_selector_all(&self, selectors: &str) -> Option> ); + + impl_ssr_safe_method!( + url(&self) -> Option> + ); + + impl_ssr_safe_method!( + document_uri(&self) -> Option> + ); + + impl_ssr_safe_method!( + compat_mode(&self) -> Option + ); + + impl_ssr_safe_method!( + character_set(&self) -> Option + ); + + impl_ssr_safe_method!( + charset(&self) -> Option + ); + + impl_ssr_safe_method!( + input_encoding(&self) -> Option + ); + + impl_ssr_safe_method!( + content_type(&self) -> Option + ); + + impl_ssr_safe_method!( + document_element(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + location(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + referrer(&self) -> Option + ); + + impl_ssr_safe_method!( + last_modified(&self) -> Option + ); + + impl_ssr_safe_method!( + ready_state(&self) -> Option + ); + + impl_ssr_safe_method!( + title(&self) -> Option + ); + + impl_ssr_safe_method!( + dir(&self) -> Option + ); + + impl_ssr_safe_method!( + head(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + images(&self) -> Option + ); + + impl_ssr_safe_method!( + embeds(&self) -> Option + ); + + impl_ssr_safe_method!( + plugins(&self) -> Option + ); + + impl_ssr_safe_method!( + links(&self) -> Option + ); + + impl_ssr_safe_method!( + forms(&self) -> Option + ); + + impl_ssr_safe_method!( + scripts(&self) -> Option + ); + + impl_ssr_safe_method!( + default_view(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onreadystatechange(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onbeforescriptexecute(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onafterscriptexecute(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onselectionchange(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + current_script(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + anchors(&self) -> Option + ); + + impl_ssr_safe_method!( + applets(&self) -> Option + ); + + impl_ssr_safe_method!( + fullscreen(&self) -> Option + ); + + impl_ssr_safe_method!( + fullscreen_enabled(&self) -> Option + ); + + impl_ssr_safe_method!( + onfullscreenchange(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onfullscreenerror(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onpointerlockchange(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + onpointerlockerror(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + /// Hides on server by default + hidden(&self) -> bool; + .unwrap_or(true) + ); + + impl_ssr_safe_method!( + visibility_state(&self) -> Option + ); + + impl_ssr_safe_method!( + onvisibilitychange(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + selected_style_sheet_set(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + last_style_sheet_set(&self) -> Option; + .unwrap_or_default() + ); + + impl_ssr_safe_method!( + preferred_style_sheet_set(&self) -> Option; + .unwrap_or_default() + ); }