Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for math and svg elements to leptos-node-ref #5

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 128 additions & 2 deletions packages/leptos-node-ref/src/any_node_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<leptos::html::$element> for AnyNodeRef {
fn load(self, el: &Element) {
Expand All @@ -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<leptos::math::$element> 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<leptos::svg::$element> 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,
Expand All @@ -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,
);
Loading