Skip to content

Commit

Permalink
support for custom elements in jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Feb 6, 2024
1 parent 15d2d23 commit b462412
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export type validHTMLElementAttrs<El extends HTMLElement> = {

export type validHTMLElementSpecificAttrs<TAG extends string> = TAG extends keyof typeof htmlElementAttributes ? {
[key in (typeof htmlElementAttributes)[TAG][number]]: TAG extends keyof htmlElementAttributeValues ? (key extends keyof htmlElementAttributeValues[TAG] ? htmlElementAttributeValues[TAG][key] : string) : string
} : Record<string, unknown>;
} : Record<string, never>;

export type validSVGElementSpecificAttrs<TAG extends string> = TAG extends keyof typeof svgElementAttributes ? {
[key in (typeof svgElementAttributes)[TAG][number]]: TAG extends keyof svgElementAttributeValues ? (key extends keyof svgElementAttributeValues[TAG] ? svgElementAttributeValues[TAG][key] : string) : string
} : Record<string, unknown>;
} : Record<string, never>;



Expand Down
2 changes: 2 additions & 0 deletions datex-bindings/dom-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ export class DOMUtils {
// valid attribute name?
// not an HTML attribute
if (!(
// if one of the following is true, the attribute is added
attr.startsWith("data-") ||
attr.startsWith("aria-") ||
element.tagName.includes("-") || // is custom element
defaultElementAttributes.includes(<typeof defaultElementAttributes[number]>attr) ||
elementEventHandlerAttributes.includes(<typeof elementEventHandlerAttributes[number]>attr) ||
(<readonly string[]>htmlElementAttributes[<keyof typeof htmlElementAttributes>element.tagName.toLowerCase()])?.includes(<typeof htmlElementAttributes[keyof typeof htmlElementAttributes][number]>attr) ||
Expand Down
3 changes: 2 additions & 1 deletion jsx/jsx-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ declare global {
// svg elements
& {
readonly [key in keyof SVGElementTagNameMap]: _IntrinsicAttributes<HTMLElementTagNameMap[key]> & {children?: childrenOrChildrenPromise|childrenOrChildrenPromise[]} & htmlAttrs<validSVGElementSpecificAttrs<key>, true>
}
}
& Record<`${string}-${string}`, {children?: childrenOrChildrenPromise|childrenOrChildrenPromise[], [key: string]: unknown}> // allow custom elements
// other custom elements
& {
'shadow-root': {children?: childrenOrChildrenPromise|childrenOrChildrenPromise[]} & {mode?:'open'|'closed'}
Expand Down

0 comments on commit b462412

Please sign in to comment.