From 7516db5ca740ccbff5138a5aca7cc998051dbf01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABlle=20Huisman?= Date: Sat, 7 Dec 2024 10:16:27 +0100 Subject: [PATCH] Add support for math and svg elements to leptos-node-ref --- packages/leptos-node-ref/src/any_node_ref.rs | 130 ++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) diff --git a/packages/leptos-node-ref/src/any_node_ref.rs b/packages/leptos-node-ref/src/any_node_ref.rs index ab15e58..4472afe 100644 --- a/packages/leptos-node-ref/src/any_node_ref.rs +++ b/packages/leptos-node-ref/src/any_node_ref.rs @@ -55,7 +55,7 @@ impl Track for AnyNodeRef { } } -macro_rules! impl_any_node_ref { +macro_rules! impl_html_any_node_ref { ($($element:ident),*,) => { $(impl NodeRefContainer for AnyNodeRef { fn load(self, el: &Element) { @@ -67,7 +67,31 @@ macro_rules! impl_any_node_ref { }; } -impl_any_node_ref!( +macro_rules! impl_math_any_node_ref { + ($($element:ident),*,) => { + $(impl NodeRefContainer for AnyNodeRef { + fn load(self, el: &Element) { + // safe to construct SendWrapper here, because it will only run in the browser + // so it will always be accessed or dropped from the main thread + self.0.set(Some(SendWrapper::new(el.clone()))); + } + })* + }; +} + +macro_rules! impl_svg_any_node_ref { + ($($element:ident),*,) => { + $(impl NodeRefContainer for AnyNodeRef { + fn load(self, el: &Element) { + // safe to construct SendWrapper here, because it will only run in the browser + // so it will always be accessed or dropped from the main thread + self.0.set(Some(SendWrapper::new(el.clone()))); + } + })* + }; +} + +impl_html_any_node_ref!( A, Abbr, Address, Area, Article, Aside, Audio, B, Base, Bdi, Bdo, Blockquote, Body, Br, Button, Canvas, Caption, Cite, Code, Col, Colgroup, Data, Datalist, Dd, Del, Details, Dfn, Dialog, Div, Dl, Dt, Em, Embed, Fieldset, Figcaption, Figure, Footer, Form, H1, H2, H3, H4, H5, H6, Head, @@ -77,3 +101,105 @@ impl_any_node_ref!( Source, Span, Strong, Style, Sub, Summary, Sup, Table, Tbody, Td, Template, Textarea, Tfoot, Th, Thead, Time, Title, Tr, Track, U, Ul, Var, Video, Wbr, ); + +impl_math_any_node_ref!( + Math, + Mi, + Mn, + Mo, + Ms, + Mspace, + Mtext, + Menclose, + Merror, + Mfenced, + Mfrac, + Mpadded, + Mphantom, + Mroot, + Mrow, + Msqrt, + Mstyle, + Mmultiscripts, + Mover, + Mprescripts, + Msub, + Msubsup, + Msup, + Munder, + Munderover, + Mtable, + Mtd, + Mtr, + Maction, + Annotation, + Semantics, +); + +impl_svg_any_node_ref!( + A, + Animate, + AnimateMotion, + AnimateTransform, + Circle, + ClipPath, + Defs, + Desc, + Discard, + Ellipse, + FeBlend, + FeColorMatrix, + FeComponentTransfer, + FeComposite, + FeConvolveMatrix, + FeDiffuseLighting, + FeDisplacementMap, + FeDistantLight, + FeDropShadow, + FeFlood, + FeFuncA, + FeFuncB, + FeFuncG, + FeFuncR, + FeGaussianBlur, + FeImage, + FeMerge, + FeMergeNode, + FeMorphology, + FeOffset, + FePointLight, + FeSpecularLighting, + FeSpotLight, + FeTile, + FeTurbulence, + Filter, + ForeignObject, + G, + Hatch, + Hatchpath, + Image, + Line, + LinearGradient, + Marker, + Mask, + Metadata, + Mpath, + Path, + Pattern, + Polygon, + Polyline, + RadialGradient, + Rect, + Script, + Set, + Stop, + Style, + Svg, + Switch, + Symbol, + Text, + TextPath, + Title, + Tspan, + View, +);