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

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 The Ember TypeScript team and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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.7.0",
4
4
  "repository": "typed-ember/glint",
5
5
  "description": "Type definitions to back typechecking for Glimmer templates",
6
6
  "license": "MIT",
@@ -14,11 +14,6 @@
14
14
  "types": "./*.d.ts"
15
15
  }
16
16
  },
17
- "scripts": {
18
- "test": "echo 'no standalone tests within this project'",
19
- "test:typecheck": "tsc --project __tests__",
20
- "test:tsc": "echo 'no standalone typecheck within this project'"
21
- },
22
17
  "files": [
23
18
  "README.md",
24
19
  "-private",
@@ -38,5 +33,10 @@
38
33
  },
39
34
  "publishConfig": {
40
35
  "access": "public"
36
+ },
37
+ "scripts": {
38
+ "test": "echo 'no standalone tests within this project'",
39
+ "test:typecheck": "tsc --project __tests__",
40
+ "test:tsc": "echo 'no standalone typecheck within this project'"
41
41
  }
42
- }
42
+ }