@glint/template 1.6.3-unstable.7c52122 → 1.6.3-unstable.cb1a168

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,28 @@
1
- import { HtmlElementAttributes, SvgElementAttributes } from './elements';
1
+ import './elements';
2
2
  import { AttrValue } from '../index';
3
- import { GlintSymbol } from './lib.dom.augmentation';
3
+ import { GlintElementRegistry } from './lib.dom.augmentation';
4
+
5
+ type Registry = GlintElementRegistry;
6
+
7
+ /**
8
+ * This doesn't generate _totally_ unique mappings, but they all have the same attributes.
9
+ *
10
+ * For example, given T = HTMLDivElement,
11
+ * we get back:
12
+ * - "HTMLTableCaptionElement"
13
+ * | "HTMLDivElement"
14
+ * | "HTMLHeadingElement"
15
+ * | "HTMLParagraphElement"
16
+ *
17
+ * And for the purposes of attribute lookup, that's good enough.
18
+ */
19
+ type Lookup<T> = {
20
+ [K in keyof Registry]: [Registry[K]] extends [T] // check assignability in one direction
21
+ ? [T] extends [Registry[K]] // and in the other
22
+ ? K // if both true, exact match
23
+ : never
24
+ : never;
25
+ }[keyof Registry];
4
26
 
5
27
  /**
6
28
  * A utility for constructing the type of an environment's `resolveOrReturn` from
@@ -25,13 +47,13 @@ export type MathMlElementForTagName<Name extends string> =
25
47
 
26
48
  type WithDataAttributes<T> = T & Record<`data-${string}`, AttrValue>;
27
49
 
28
- export type AttributesForElement<
29
- Elem extends Element,
30
- K = Elem extends { [GlintSymbol]: string } ? Elem[typeof GlintSymbol] : never,
31
- > = K extends keyof HtmlElementAttributes.HtmlElements
32
- ? WithDataAttributes<HtmlElementAttributes.HtmlElements[K]>
33
- : K extends keyof SvgElementAttributes.SvgElements
34
- ? WithDataAttributes<SvgElementAttributes.SvgElements[K]>
35
- : K extends keyof SvgElementAttributes.SvgElements
36
- ? WithDataAttributes<SvgElementAttributes.SvgElements[K]>
37
- : Record<string, AttrValue>;
50
+ export type AttributesForElement<Elem extends Element, K = Lookup<Elem>> =
51
+ // Is K in the HTML attributes map?
52
+ K extends keyof GlintHtmlElementAttributesMap
53
+ ? WithDataAttributes<GlintHtmlElementAttributesMap[K]>
54
+ : // Or is K in the SVG attributes map?
55
+ K extends keyof GlintSvgElementAttributesMap
56
+ ? WithDataAttributes<GlintSvgElementAttributesMap[K]>
57
+ : // If the element can't be found: fallback to just allow general AttrValue
58
+ // NOTE: MathML has no attributes
59
+ Record<string, AttrValue>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glint/template",
3
- "version": "1.6.3-unstable.7c52122",
3
+ "version": "1.6.3-unstable.cb1a168",
4
4
  "repository": "typed-ember/glint",
5
5
  "description": "Type definitions to back typechecking for Glimmer templates",
6
6
  "license": "MIT",