validation.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /// TODO @Jon
  2. /// Figure out if validation should be its own crate, or embedded directly into dioxus
  3. ///
  4. /// Should we even be bothered with validation?
  5. ///
  6. ///
  7. ///
  8. mod validation {
  9. use once_cell::sync::Lazy;
  10. use std::collections::HashSet;
  11. // Used to uniquely identify elements that contain closures so that the DomUpdater can
  12. // look them up by their unique id.
  13. // When the DomUpdater sees that the element no longer exists it will drop all of it's
  14. // Rc'd Closures for those events.
  15. // It doesn't quite make sense to keep this here, perhaps just in the html crate?
  16. // Dioxus itself shouldn't be concerned with the attribute names
  17. // a ftk!
  18. static SELF_CLOSING_TAGS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
  19. [
  20. "area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "command",
  21. "keygen", "source",
  22. ]
  23. .iter()
  24. .cloned()
  25. .collect()
  26. });
  27. /// Whether or not this tag is self closing
  28. ///
  29. /// ```ignore
  30. /// use dioxus_core::validation::is_self_closing;
  31. /// assert_eq!(is_self_closing("br"), true);
  32. /// assert_eq!(is_self_closing("div"), false);
  33. /// ```
  34. pub fn is_self_closing(tag: &str) -> bool {
  35. SELF_CLOSING_TAGS.contains(tag)
  36. // SELF_CLOSING_TAGS.contains(tag) || is_self_closing_svg_tag(tag)
  37. }
  38. }