MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus / Document

Interface Document

packages/document/src/document.rs:64–115  ·  view source on GitHub ↗

A provider for document-related functionality. Provides things like a history API, a title, a way to run JS, and some other basics/essentials used by nearly every platform. An integration with some kind of navigation history. Depending on your use case, your implementation may deviate from the described procedure. This is fine, as long as both `current_route` and `current_query` match the descr

Source from the content-addressed store, hash-verified

62/// The described behaviors are designed to mimic a web browser, which most users should already
63/// know. Deviations might confuse them.
64pub trait Document: 'static {
65 /// Run `eval` against this document, returning an [`Eval`] that can be used to await the result.
66 fn eval(&self, js: String) -> Eval;
67
68 /// Set the title of the document
69 fn set_title(&self, title: String) {
70 self.eval(format!("document.title = {title:?};"));
71 }
72
73 /// Create a new element in the head
74 fn create_head_element(
75 &self,
76 name: &str,
77 attributes: &[(&str, String)],
78 contents: Option<String>,
79 ) {
80 // This default implementation remains to make the trait compatible with the 0.6 version, but it should not be used
81 // The element should only be created inside an effect so it is not called while the component is suspended
82 self.eval(create_element_in_head(name, attributes, contents));
83 }
84
85 /// Create a new meta tag in the head
86 fn create_meta(&self, props: MetaProps) {
87 let attributes = props.attributes();
88 self.create_head_element("meta", &attributes, None);
89 }
90
91 /// Create a new script tag in the head
92 fn create_script(&self, props: ScriptProps) {
93 let attributes = props.attributes();
94 self.create_head_element("script", &attributes, props.script_contents().ok());
95 }
96
97 /// Create a new style tag in the head
98 fn create_style(&self, props: StyleProps) {
99 let attributes = props.attributes();
100 self.create_head_element("style", &attributes, props.style_contents().ok());
101 }
102
103 /// Create a new link tag in the head
104 fn create_link(&self, props: LinkProps) {
105 let attributes = props.attributes();
106 self.create_head_element("link", &attributes, None);
107 }
108
109 /// Check if we should create a new head component at all. If it returns false, the head component will be skipped.
110 ///
111 /// This runs once per head component and is used to hydrate head components in fullstack.
112 fn create_head_component(&self) -> bool {
113 true
114 }
115}
116
117/// A document that does nothing
118#[derive(Default)]

Callers 8

create_metaMethod · 0.45
create_scriptMethod · 0.45
create_styleMethod · 0.45
create_linkMethod · 0.45
StyleFunction · 0.45
LinkFunction · 0.45
ScriptFunction · 0.45
MetaFunction · 0.45

Implementers 8

dioxus_document.rspackages/native-dom/src/dioxus_documen
document.rspackages/desktop/src/document.rs
document.rspackages/fullstack-core/src/document.r
document.rspackages/liveview/src/document.rs
document.rspackages/document/src/document.rs
document.rspackages/fullstack-server/src/document
document.rspackages/web/src/document.rs
contexts.rspackages/native/src/contexts.rs

Calls

no outgoing calls

Tested by

no test coverage detected