Fix elements and attributes mapping for dx translate

This commit is contained in:
Evan Almloff committed 2024-01-03 15:18:27 -06:00
1 parent 2e424436b3
commit afb258b658
10 files changed
+202 -17

No files matched your search

+45 -3
View File
@@ -79,6 +79,25 @@ macro_rules! impl_attribute_match {
};
}
#[cfg(feature = "html-to-rsx")]
macro_rules! impl_html_to_rsx_attribute_match {
(
$attr:ident $fil:ident $name:literal
) => {
if $attr == $name {
return Some(stringify!($fil));
}
};
(
$attr:ident $fil:ident $_:tt
) => {
if $attr == stringify!($fil) {
return Some(stringify!($fil));
}
};
}
macro_rules! impl_element {
(
$(#[$attr:meta])*
@@ -316,6 +335,30 @@ macro_rules! builder_constructors {
}
}
#[cfg(feature = "html-to-rsx")]
pub fn map_html_attribute_to_rsx(html: &str) -> Option<&'static str> {
$(
$(
impl_html_to_rsx_attribute_match!(
html $fil $extra
);
)*
)*
None
}
#[cfg(feature = "html-to-rsx")]
pub fn map_html_element_to_rsx(html: &str) -> Option<&'static str> {
$(
if html == stringify!($name) {
return Some(stringify!($name));
}
)*
None
}
$(
impl_element!(
$(#[$attr])*
@@ -998,9 +1041,8 @@ builder_constructors! {
src: Uri DEFAULT,
text: String DEFAULT,
// r#async: Bool,
// r#type: String, // TODO could be an enum
r#type: String "type",
r#async: Bool "async",
r#type: String "type", // TODO could be an enum
r#script: String "script",
};
+46
View File
@@ -33,12 +33,44 @@ macro_rules! trait_method_mapping {
};
}
#[cfg(feature = "html-to-rsx")]
macro_rules! html_to_rsx_attribute_mapping {
(
$matching:ident;
$(#[$attr:meta])*
$name:ident;
) => {
if $matching == stringify!($name) {
return Some(stringify!($name));
}
};
(
$matching:ident;
$(#[$attr:meta])*
$name:ident: $lit:literal;
) => {
if $matching == stringify!($lit) {
return Some(stringify!($name));
}
};
(
$matching:ident;
$(#[$attr:meta])*
$name:ident: $lit:literal, $ns:literal;
) => {
if $matching == stringify!($lit) {
return Some(stringify!($name));
}
};
}
macro_rules! trait_methods {
(
@base
$(#[$trait_attr:meta])*
$trait:ident;
$fn:ident;
$fn_html_to_rsx:ident;
$(
$(#[$attr:meta])*
$name:ident $(: $($arg:literal),*)*;
@@ -62,6 +94,18 @@ macro_rules! trait_methods {
)*
None
}
#[cfg(feature = "html-to-rsx")]
#[doc = "Converts an HTML attribute to an RSX attribute"]
pub(crate) fn $fn_html_to_rsx(html: &str) -> Option<&'static str> {
$(
html_to_rsx_attribute_mapping! {
html;
$name$(: $($arg),*)*;
}
)*
None
}
};
// Rename the incoming ident and apply a custom namespace
@@ -79,6 +123,7 @@ trait_methods! {
GlobalAttributes;
map_global_attributes;
map_html_global_attributes_to_rsx;
/// Prevent the default action for this element.
///
@@ -1593,6 +1638,7 @@ trait_methods! {
@base
SvgAttributes;
map_svg_attributes;
map_html_svg_attributes_to_rsx;
/// Prevent the default action for this element.
///
+2
View File
@@ -19,6 +19,8 @@
mod elements;
#[cfg(feature = "hot-reload-context")]
pub use elements::HtmlCtx;
#[cfg(feature = "html-to-rsx")]
pub use elements::{map_html_attribute_to_rsx, map_html_element_to_rsx};
pub mod events;
pub mod geometry;
mod global_attributes;