From 4e49d71efe404883ce5cace430fd59a63f64e610 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 23 Dec 2022 17:11:00 -0500 Subject: [PATCH 1/8] chore: tweak global attributes --- packages/html/src/global_attributes.rs | 3088 +++++++++++++++++------- 1 file changed, 2264 insertions(+), 824 deletions(-) diff --git a/packages/html/src/global_attributes.rs b/packages/html/src/global_attributes.rs index 5c4ac42e8..a03b2f5e6 100644 --- a/packages/html/src/global_attributes.rs +++ b/packages/html/src/global_attributes.rs @@ -2,131 +2,165 @@ use crate::AttributeDiscription; -macro_rules! no_namespace_trait_methods { +macro_rules! trait_methods { ( + $trait:ident; $( $(#[$attr:meta])* - $name:ident; - )* + $name:ident $(: $($arg:literal),*)*; + )+ ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - stringify!($name), - None, - false - ); - )* - }; -} -macro_rules! style_trait_methods { - ( - $( - $(#[$attr:meta])* - $name:ident: $lit:literal, - )* - ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - $lit, - Some("style"), - false - ); - )* - }; -} -macro_rules! aria_trait_methods { - ( - $( - $(#[$attr:meta])* - $name:ident: $lit:literal, - )* - ) => { - $( - $(#[$attr])* - const $name: AttributeDiscription = ( - $lit, - None, - false - ); - )* + pub trait $trait { + $( + $(#[$attr])* + const $name: AttributeDiscription = trait_methods! { $name $(: $($arg),*)*; }; + )* + } }; + + // Rename the incoming ident and apply a custom namespace + ( $name:ident: $lit:literal, $ns:literal; ) => { ($lit, Some($ns), false) }; + + // Rename the incoming ident + ( $name:ident: $lit:literal; ) => { ($lit, None, false ) }; + + // Don't rename the incoming ident + ( $name:ident; ) => { (stringify!($name), None, false) }; } -pub trait GlobalAttributes { +trait_methods! { + GlobalAttributes; + /// Prevent the default action for this element. /// /// For more information, see the MDN docs: /// + prevent_default: "dioxus-prevent-default"; - const prevent_default: AttributeDiscription = ("dioxus-prevent-default", None, false); - no_namespace_trait_methods! { - accesskey; - autocapitalize; - autofocus; - /// The HTML class attribute is used to specify a class for an HTML element. - /// - /// ## Details - /// Multiple HTML elements can share the same class. - /// - /// The class global attribute is a space-separated list of the case-sensitive classes of the element. - /// Classes allow CSS and Javascript to select and access specific elements via the class selectors or - /// functions like the DOM method document.getElementsByClassName. - /// - /// ## Example - /// - /// ### HTML: - /// ```html - ///

Above point sounds a bit obvious. Remove/rewrite?

- /// ``` - /// - /// ### CSS: - /// ```css - /// .note { - /// font-style: italic; - /// font-weight: bold; - /// } - /// - /// .editorial { - /// background: rgb(255, 0, 0, .25); - /// padding: 10px; - /// } - /// ``` - class; - contenteditable; - data; - dir; - draggable; - enterkeyhint; - exportparts; - hidden; - id; - inputmode; - is; - itemid; - itemprop; - itemref; - itemscope; - itemtype; - lang; - nonce; - part; - role; - slot; - spellcheck; - style; - tabindex; - title; - translate; + /// + accesskey: "accesskey"; - /// dangerous_inner_html is Dioxus's replacement for using innerHTML in the browser DOM. In general, setting - /// HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) - /// attack. So, you can set HTML directly from Dioxus, but you have to type out dangerous_inner_html to remind - /// yourself that it’s dangerous - dangerous_inner_html; - } + + /// + autocapitalize: "autocapitalize"; + + + /// + autofocus; + + /// The HTML class attribute is used to specify a class for an HTML element. + /// + /// ## Details + /// Multiple HTML elements can share the same class. + /// + /// The class global attribute is a space-separated list of the case-sensitive classes of the element. + /// Classes allow CSS and Javascript to select and access specific elements via the class selectors or + /// functions like the DOM method document.getElementsByClassName. + /// + /// ## Example + /// + /// ### HTML: + /// ```html + ///

Above point sounds a bit obvious. Remove/rewrite?

+ /// ``` + /// + /// ### CSS: + /// ```css + /// .note { + /// font-style: italic; + /// font-weight: bold; + /// } + /// + /// .editorial { + /// background: rgb(255, 0, 0, .25); + /// padding: 10px; + /// } + /// ``` + /// + class; + + /// + contenteditable; + + /// + data; + + /// + dir; + + /// + draggable; + + /// + enterkeyhint; + + /// + exportparts; + + ///