-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
[wip] Implement special builder method for html-svg transition tags #70
Conversation
Looks like a PR on scalajs-dom is needed before this can work. Somehow I did not catch that earlier. |
Turns out there is no I have moved the definition back to |
svgTag(tagName) | ||
} | ||
|
||
@inline protected def htmlToSvgTag[Ref <: DomSvgElement](tagName: String): T[Ref] = { | ||
@inline protected def svgSvgTag[Ref <: DomSvgElement](tagName: String): T[Ref] = { | ||
svgTag(tagName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only use the methods for two tags anyways we can also name them for what they are.
Which makes the implementation look like this
private [lookout] trait SvgTagBuilder extends builders.SvgTagBuilder[CommonSvgTag, dom.svg.Element] {
import VDomModifierTypes._
override protected def svgTag[Ref <: svg.Element](tagName: String, void: Boolean): TypedVNode[Svg, Svg, Ref] = ???
override protected def svgSvgTag[Ref <: svg.Element](tagName: String): TypedVNode[Both, Svg, Ref] = ???
override protected def svgForeignObjectTag[Ref <: svg.Element](tagName: String): TypedVNode[Svg, Html, Ref] = ???
}
@@ -59,52 +59,55 @@ trait SvgTags[T[_ <: SvgElement], SvgElement, | |||
] { | |||
this: SvgTagBuilder[T, SvgElement] => | |||
|
|||
type TPure <: T | |||
type TSvg <: T[Svg] | |||
type TForeignObject <: T[SvgElement] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could probably be named differently, I especially dislike TPure
but I couldn't think of anything better.
I had to add some type aliases to support narrowing the types of tags. |
Sorry for the delay! I just looked at this, and for Laminar it would require changes there too. I'm not yet sure what the exact scope of those changes would be, but I have quite a few complex and high impact features in Airstream that I want to implement first. I'm working on the assumption that this change is simply to improve type safety, as I was able to construct SVGs with foreign objects with them just fine. In this regard it relates (somewhat) to #13. |
No worries. I must admit that, after implementing this into outwatch as a proof of concept we have decided on not pursuing the concept any further since it would add too much complexity to for the safety it adds. |
Ah, thanks for confirming this. I had a suspicion that the required complexity would be prohibitive. Shall we close this then? (Keeping #13 alive as the entry point to this general issue). |
Yeah, I am fine with closing this. |
This change implements a special builder method in the
HtmlTagBuilder
andSvgTagBuilder
traits.There are (as far as I am aware) two tags in browsers whose children use another xml namespace as the tags themselves. They are the
<svg>
tag and the<foreignObject>
tag.<svg>
is a html tag, but it's children are svg tags.foreignObject
is a svg tag, but it's children are html tags.In theory this would allow us to have a tag builder that whose html tags only allow for html attrs and so on. I.e.
That way
div( stroke := "green" )
orsvg( section )
would not compile.This change also deprecates the
svg
tag definition inside theSvgTags
trait.Initially I thought that the svg tag would only be a relevant part of the svg namespace when being used as the top level tag of the document, but I have looked further into it while writing this and I have found some examples of people using multiple svg tags inside the same element.
I am not sure anymore if it should really be deprecated.