@glint/template 0.8.2 → 0.9.1

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,3 +1,4 @@
1
+ import { AttrValue, ContentValue } from '..';
1
2
  import {
2
3
  AcceptsBlocks,
3
4
  AnyContext,
@@ -8,18 +9,18 @@ import {
8
9
  Invokable,
9
10
  TemplateContext,
10
11
  } from '../integration';
11
- import { ElementForTagName, EmittableValue } from './types';
12
+ import { ElementForTagName } from './types';
12
13
 
13
14
  /*
14
- * Emits the given value to the DOM. This corresponds to a mustache
15
- * statement either at the top level:
15
+ * Emits the given value as top-level content to the DOM. This:
16
16
  *
17
- * {{value}}
18
- * {{value foo=bar}}
19
- * <div data-x={{value foo=bar}}>
20
- * <div data-x="hello {{value foo=bar}}">
17
+ * Hello, {{world}}
18
+ *
19
+ * Would produce code like:
20
+ *
21
+ * emitContent(resolveOrReturn(value)({}))
21
22
  */
22
- export declare function emitValue(value: AcceptsBlocks<{}, any> | EmittableValue): void;
23
+ export declare function emitContent(value: ContentValue): void;
23
24
 
24
25
  /*
25
26
  * Emits an element of the given name, providing a value to the
@@ -106,7 +107,7 @@ export declare function applySplattributes<
106
107
  * <div foo={{bar}}></div>
107
108
  * <AnotherComponent foo={{bar}} />
108
109
  */
109
- export declare function applyAttributes(element: Element, attrs: Record<string, unknown>): void;
110
+ export declare function applyAttributes(element: Element, attrs: Record<string, AttrValue>): void;
110
111
 
111
112
  /*
112
113
  * Applies a modifier to an element or component.
@@ -29,12 +29,3 @@ export type ResolveContext<T> = T extends HasContext<infer Context>
29
29
  : T extends Constructor<HasContext<infer Context>>
30
30
  ? Context
31
31
  : unknown;
32
-
33
- // This encompasses both @glimmer/runtime and @ember/template's notion of `SafeString`s,
34
- // and this coverage is tested in `emit-value.test.ts`.
35
- type SafeString = { toHTML(): string };
36
-
37
- /**
38
- * Represents values that can safely be emitted into the DOM i.e. as `<span>{{value}}</span>`.
39
- */
40
- export type EmittableValue = SafeString | Element | string | number | boolean | null | void;
@@ -8,6 +8,36 @@ import {
8
8
  } from './integration';
9
9
  import { ExpandSignature } from '@glimmer/component/-private/component';
10
10
 
11
+ /**
12
+ * Any value that can be safely emitted into the DOM as top-level content,
13
+ * i.e. as `<div>{{value}}</div>`.
14
+ *
15
+ * This includes primitives like strings, numbers and booleans; "nothing"
16
+ * values like `null` and `undefined`; DOM nodes; and blockless curly
17
+ * component invocations.
18
+ */
19
+ export type ContentValue =
20
+ | string
21
+ | number
22
+ | boolean
23
+ | null
24
+ | undefined
25
+ | void
26
+ | SafeString
27
+ | Node
28
+ | ArglessCurlyComponent;
29
+
30
+ /**
31
+ * Any value that can be safely set as an HTML attribute on a DOM node.
32
+ * This includes strings, numbers, booleans and `null`/`undefined`.
33
+ *
34
+ * Note that this does not include functions, as writing something like
35
+ * `onclick={{this.handleClick}}` in a template ultimately relies on
36
+ * fallback behavior in the VM to set the `onclick` property, and is
37
+ * better performed using the `{{on}}` modifier.
38
+ */
39
+ export type AttrValue = string | number | boolean | null | undefined | SafeString;
40
+
11
41
  /**
12
42
  * A value that is invokable like a component in a template. In an
13
43
  * appropriate Glint environment, subclasses of `EmberComponent` and
@@ -112,3 +142,13 @@ type InvokableArgs<S> = [
112
142
  named: GuardEmpty<Get<Get<S, 'Args'>, 'Named'>>,
113
143
  ...positional: Constrain<Get<Get<S, 'Args'>, 'Positional'>, Array<unknown>, []>
114
144
  ];
145
+
146
+ // This encompasses both @glimmer/runtime and @ember/template's notion of `SafeString`s,
147
+ // and this coverage is tested in `emit-content.test.ts`.
148
+ type SafeString = { toHTML(): string };
149
+
150
+ // `{{foo}}` becomes `emitContent(resolveOrReturn(foo)({})`, which means if `foo`
151
+ // is a component that accepts no args, then this is a valid invocation.
152
+ type ArglessCurlyComponent = AcceptsBlocks<{}, any>;
153
+
154
+ export {};
@@ -1,5 +1,10 @@
1
1
  import { AcceptsBlocks, DirectInvokable } from '../integration';
2
2
 
3
3
  export type InElementKeyword = DirectInvokable<{
4
- (args: { insertBefore?: null | undefined }, element: Element): AcceptsBlocks<{ default: [] }>;
4
+ (
5
+ args: {
6
+ insertBefore?: null | undefined;
7
+ },
8
+ element: ShadowRoot | Element
9
+ ): AcceptsBlocks<{ default: [] }>;
5
10
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glint/template",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "repository": "typed-ember/glint",
5
5
  "description": "Type definitions to back typechecking for Glimmer templates",
6
6
  "license": "MIT",