#![allow(rustdoc::invalid_html_tags)]
#[expect(unused)]
pub(crate) const DATASTAR_KEY: &str = "datastar";
#[allow(unused)]
pub(crate) const DATASTAR_REQ_HEADER_STR: &str = "datastar-request";
pub const DEFAULT_SSE_RETRY_DURATION: u64 = 1000;
pub(crate) const SELECTOR_DATALINE_LITERAL: &str = "selector";
pub(crate) const MODE_DATALINE_LITERAL: &str = "mode";
pub(crate) const ELEMENTS_DATALINE_LITERAL: &str = "elements";
pub(crate) const USE_VIEW_TRANSITION_DATALINE_LITERAL: &str = "useViewTransition";
pub(crate) const VIEW_TRANSITION_SELECTOR_DATALINE_LITERAL: &str = "viewTransitionSelector";
pub(crate) const NAMESPACE_DATALINE_LITERAL: &str = "namespace";
pub(crate) const SIGNALS_DATALINE_LITERAL: &str = "signals";
pub(crate) const ONLY_IF_MISSING_DATALINE_LITERAL: &str = "onlyIfMissing";
pub(crate) const DEFAULT_ELEMENTS_USE_VIEW_TRANSITIONS: bool = false;
pub(crate) const DEFAULT_PATCH_SIGNALS_ONLY_IF_MISSING: bool = false;
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ElementPatchMode {
#[default]
Outer,
Inner,
Remove,
Replace,
Prepend,
Append,
Before,
After,
}
impl ElementPatchMode {
pub(crate) const fn as_str(&self) -> &'static str {
match self {
Self::Outer => "outer",
Self::Inner => "inner",
Self::Remove => "remove",
Self::Replace => "replace",
Self::Prepend => "prepend",
Self::Append => "append",
Self::Before => "before",
Self::After => "after",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventType {
PatchElements,
PatchSignals,
}
impl EventType {
pub(crate) const fn as_str(&self) -> &str {
match self {
Self::PatchElements => "datastar-patch-elements",
Self::PatchSignals => "datastar-patch-signals",
}
}
}
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Namespace {
#[default]
Html,
Svg,
MathMl,
}
impl Namespace {
pub(crate) const fn as_str(&self) -> &'static str {
match self {
Self::Html => "html",
Self::Svg => "svg",
Self::MathMl => "mathml",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn maps_element_patch_modes() {
assert_eq!(ElementPatchMode::Outer.as_str(), "outer");
assert_eq!(ElementPatchMode::Inner.as_str(), "inner");
assert_eq!(ElementPatchMode::Remove.as_str(), "remove");
assert_eq!(ElementPatchMode::Replace.as_str(), "replace");
assert_eq!(ElementPatchMode::Prepend.as_str(), "prepend");
assert_eq!(ElementPatchMode::Append.as_str(), "append");
assert_eq!(ElementPatchMode::Before.as_str(), "before");
assert_eq!(ElementPatchMode::After.as_str(), "after");
}
#[test]
fn maps_event_types() {
assert_eq!(EventType::PatchElements.as_str(), "datastar-patch-elements");
assert_eq!(EventType::PatchSignals.as_str(), "datastar-patch-signals");
}
#[test]
fn maps_namespaces() {
assert_eq!(Namespace::Html.as_str(), "html");
assert_eq!(Namespace::Svg.as_str(), "svg");
assert_eq!(Namespace::MathMl.as_str(), "mathml");
}
}