-
Notifications
You must be signed in to change notification settings - Fork 106
fix!(tags): decouple ns #446
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
Conversation
Reason: - JSX cannot use NS for svg, math, etc. - Increase portablility of Van Components by inheriting `curNS` of their parents - Simplify `tags` function
|
Interesting find, are you using van-jsx? |
|
@thednp, No, I'm not actually using While developing zdom, I ran into an issue where Van struggled to create elements like Plus, I noticed that the |
|
Please post some test JSX I can have a look. You can also test it right now here. UPDATE: I tested a sample SVG markup as JSX and didn't work. It might have to do with the |
|
I can confirm that's exactly the problem, I already have a working fix, mode details soon. |
|
In short this is the fix: In long: we also need to update the handling of the attributes as well. |
The problem is that children cannot inherit the |
|
I don't think @Tao-VanJS is going to approve this PR since we can have workarounds, but I might be wrong about that. Will investigate further layer today. |
|
I don't think you need to change VanJS to achieve what you want. Here is the sample code based on your idea: let curNs
const superTag = (name, ...args) => (curNs ? van.tags(curNs) : van.tags)[name](...args)
const superTags = new Proxy(superTag, {get: (target, name) => target.bind(null, name)})
const withNs = (ns, fn) => {
const oldNs = curNs
curNs = ns
try {
return fn()
} finally {
curNs = oldNs
}
}
const {div, circle, path, svg, math, mi, mn, mo, mrow, msup} = superTags
const Smiley = () => svg({width: "16px", viewBox: "0 0 50 50"},
circle({cx: "25", cy: "25", "r": "20", stroke: "black", "stroke-width": "2", fill: "yellow"}),
circle({cx: "16", cy: "20", "r": "2", stroke: "black", "stroke-width": "2", fill: "black"}),
circle({cx: "34", cy: "20", "r": "2", stroke: "black", "stroke-width": "2", fill: "black"}),
path({"d": "M 15 30 Q 25 40, 35 30", stroke: "black", "stroke-width": "2", fill: "transparent"}),
)
const Euler = () => math(
msup(mi("e"), mrow(mi("i"), mi("π"))), mo("+"), mn("1"), mo("="), mn("0"),
)
van.add(document.body,
div(withNs("http://www.w3.org/2000/svg", Smiley)),
div(withNs("http://www.w3.org/1998/Math/MathML", Euler)),
)Preview via: https://jsfiddle.net/tjz45e1n/1/ |
|
@Tao-VanJS thanks for dropping by! Based on your suggestion I've fixed the vite-plugin-vanjs (JSX) to work automatically with namespace elements. Will update it soon. |
|
Thank @Tao-VanJS , I just wanted to have an official workaround. Maybe @thednp will have good way to fix |
|
@binhtran432k in fact VanJS with our vite-plugin-vanjs is (possibly) the only framework to officially support MathML, in a couple of hours that is :) |
|
@binhtran432k you can now test vite-plugin-vanjs@0.1.10 with fixes for namespace elements, you can even not specify a namespace at all. |
Reason:
curNSof their parentstagsfunction