-
Notifications
You must be signed in to change notification settings - Fork 52
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
provide suggestions and type checking for elements attributes #663
base: main
Are you sure you want to change the base?
Conversation
@@ -10,7 +10,7 @@ export type ResolveOrReturn<T> = T & (<U>(item: U) => () => U); | |||
*/ | |||
export type ElementForTagName<Name extends string> = Name extends keyof HTMLElementTagNameMap | |||
? Name extends keyof SVGElementTagNameMap | |||
? HTMLElementTagNameMap[Name] & SVGElementTagNameMap[Name] | |||
? HTMLElementTagNameMap[Name] | SVGElementTagNameMap[Name] |
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.
comment also says that it should be an union This will return a union for elements that exist both in HTML and SVG.
But it was an intersection
hmmm, this needs a way to distinguish exactly between svg elements and html elements... |
Thanks for this, but I think this is conflating HTML attributes and DOM properties in a way that doesn't quite work. The properties on an |
😞 |
does TS provide no map/list of attributes? |
If we can't get a list of attributes, |
what about this? |
We spent time looking into this earlier on in Glint's development—I think everyone involved agrees this would be nice to have! TS doesn't include anything like this in its standard library, though, and at least as of when we last checked we didn't find any third-party version either.
At a types level, that just exposes
Is that a valid heuristic? I feel pretty strongly that wrong completions are worse than no completions. |
yes, but a subset of incomplete, yet correct completions are better than no completions.
we could PR them to |
Yes, which is exactly why I asked if your suggested heuristic of only doing single-word ones actually works 😜 |
In other words, my point is that this isn't just a casing issue. Driving off of |
I think making a pr to https://www.npmjs.com/package/html-element-attributes to generate a d.ts would then make ut usable |
Let's see what the maintainer says: wooorm/html-element-attributes#9 I've worked with them before with remark/unified/codemirror stuff before, and iirc, they're pretty responsive. |
Would also need https://github.com/wooorm/svg-element-attributes |
well, I couldn't give up just yet :) now i only get valid completions for element attributes. unfortunately it only works inside an AttrNode if we had a node for the tag name, we could probably default the location to attributes for the rest |
return completions?.entries.map((completionEntry) => ({ | ||
label: completionEntry.name, | ||
label: isInElementAttributes | ||
? completionEntry.name.replace(/["']/g, '') |
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.
to remove "
or '
from element attributes containing a -
@@ -42,7 +42,7 @@ export function templateToTypescript( | |||
return mapTemplateContents(originalTemplate, { embeddingSyntax }, (ast, mapper) => { | |||
let { emit, record, rangeForLine, rangeForNode } = mapper; | |||
let scope = new ScopeStack([]); | |||
|
|||
let inSVG = false; |
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.
it could be possible to have components inside svg, with this it would be possible to a glint-directive @glint-in-svg
a the top of the template to specify that we are inside svg.
[P in keyof T]?: T[P] extends SVGAnimatedString ? string : T[P]; | ||
}; | ||
|
||
// TODO: improve this to allow other keys |
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.
anyone knowns how to achieve this?
basically would like to allow other keys that default to AttrValue.
Currently I do it with & Record<string, AttrValue>
(line 157), but that sets all properties to AttrValue
# Conflicts: # packages/core/src/transform/template/template-to-typescript.ts
this would also make it possible to wrap WebComponents and have auto completions and type checking for those.
also allows any key. ideally we should only allow any key, if its prefixed with
data-
.unfortunately
<WebComponent myoptions="<cursor here>" />
does not provide completions.But
<WebComponent myoptions={{"<cursor here>"}} />
does