@microsoft/fast-element 2.0.0-beta.9 → 2.0.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.
Files changed (142) hide show
  1. package/.eslintrc.json +1 -1
  2. package/CHANGELOG.json +497 -0
  3. package/CHANGELOG.md +172 -1
  4. package/README.md +1 -9
  5. package/api-extractor.context.json +14 -0
  6. package/api-extractor.di.json +14 -0
  7. package/dist/context/context.api.json +1068 -0
  8. package/dist/di/di.api.json +4929 -0
  9. package/dist/dts/binding/binding.d.ts +49 -0
  10. package/dist/dts/binding/normalize.d.ts +9 -0
  11. package/dist/dts/binding/one-time.d.ts +11 -0
  12. package/dist/dts/binding/one-way.d.ts +20 -0
  13. package/dist/dts/{templating/binding-signal.d.ts → binding/signal.d.ts} +19 -4
  14. package/dist/dts/{templating/binding-two-way.d.ts → binding/two-way.d.ts} +9 -5
  15. package/dist/dts/components/attributes.d.ts +6 -0
  16. package/dist/dts/components/element-controller.d.ts +104 -8
  17. package/dist/dts/components/element-hydration.d.ts +2 -0
  18. package/dist/dts/components/fast-definitions.d.ts +6 -0
  19. package/dist/dts/components/hydration.d.ts +56 -0
  20. package/dist/dts/components/install-hydration.d.ts +1 -0
  21. package/dist/dts/context.d.ts +29 -15
  22. package/dist/dts/di/di.d.ts +0 -5
  23. package/dist/dts/dom-policy.d.ts +83 -0
  24. package/dist/dts/dom.d.ts +100 -0
  25. package/dist/dts/hydration/target-builder.d.ts +63 -0
  26. package/dist/dts/index.d.ts +33 -26
  27. package/dist/dts/index.rollup.d.ts +0 -1
  28. package/dist/dts/index.rollup.debug.d.ts +0 -1
  29. package/dist/dts/interfaces.d.ts +32 -82
  30. package/dist/dts/metadata.d.ts +6 -5
  31. package/dist/dts/observation/arrays.d.ts +1 -1
  32. package/dist/dts/observation/observable.bench.d.ts +18 -0
  33. package/dist/dts/observation/observable.d.ts +5 -5
  34. package/dist/dts/pending-task.d.ts +19 -7
  35. package/dist/dts/platform.d.ts +11 -2
  36. package/dist/dts/polyfills.d.ts +0 -8
  37. package/dist/dts/styles/css-binding-directive.d.ts +60 -0
  38. package/dist/dts/styles/css.d.ts +9 -7
  39. package/dist/dts/styles/element-styles.d.ts +1 -14
  40. package/dist/dts/styles/host.d.ts +2 -5
  41. package/dist/dts/styles/style-strategy.d.ts +42 -0
  42. package/dist/dts/templating/compiler.d.ts +11 -13
  43. package/dist/dts/templating/{binding.d.ts → html-binding-directive.d.ts} +21 -41
  44. package/dist/dts/templating/html-directive.d.ts +44 -140
  45. package/dist/dts/templating/install-hydratable-view-templates.d.ts +1 -0
  46. package/dist/dts/templating/node-observation.d.ts +11 -1
  47. package/dist/dts/templating/ref.d.ts +4 -0
  48. package/dist/dts/templating/render.bench.d.ts +3 -0
  49. package/dist/dts/templating/render.d.ts +49 -9
  50. package/dist/dts/templating/repeat-basic-reverse.bench.d.ts +3 -0
  51. package/dist/dts/templating/repeat-basic-shift.bench.d.ts +3 -0
  52. package/dist/dts/templating/repeat.d.ts +31 -9
  53. package/dist/dts/templating/template.d.ts +97 -12
  54. package/dist/dts/templating/view.d.ts +146 -29
  55. package/dist/dts/templating/when-basic.bench.d.ts +3 -0
  56. package/dist/dts/templating/when-conditional.bench.d.ts +3 -0
  57. package/dist/dts/templating/when-switch.bench.d.ts +3 -0
  58. package/dist/dts/templating/when.d.ts +3 -1
  59. package/dist/dts/testing/fakes.d.ts +12 -1
  60. package/dist/dts/tsdoc-metadata.json +1 -1
  61. package/dist/dts/utilities.d.ts +55 -1
  62. package/dist/esm/binding/binding.js +18 -0
  63. package/dist/esm/binding/normalize.js +17 -0
  64. package/dist/esm/binding/one-time.js +21 -0
  65. package/dist/esm/binding/one-way.js +30 -0
  66. package/dist/esm/{templating/binding-signal.js → binding/signal.js} +22 -6
  67. package/dist/esm/{templating/binding-two-way.js → binding/two-way.js} +18 -12
  68. package/dist/esm/components/attributes.js +16 -1
  69. package/dist/esm/components/element-controller.js +319 -49
  70. package/dist/esm/components/element-hydration.js +2 -0
  71. package/dist/esm/components/fast-definitions.js +12 -4
  72. package/dist/esm/components/fast-element.js +3 -1
  73. package/dist/esm/components/hydration.js +104 -0
  74. package/dist/esm/components/install-hydration.js +3 -0
  75. package/dist/esm/context.js +26 -4
  76. package/dist/esm/debug.js +8 -2
  77. package/dist/esm/di/di.js +9 -12
  78. package/dist/esm/dom-policy.js +345 -0
  79. package/dist/esm/dom.js +101 -0
  80. package/dist/esm/hydration/target-builder.js +175 -0
  81. package/dist/esm/index.js +34 -25
  82. package/dist/esm/index.rollup.debug.js +3 -1
  83. package/dist/esm/index.rollup.js +3 -1
  84. package/dist/esm/interfaces.js +51 -3
  85. package/dist/esm/metadata.js +11 -8
  86. package/dist/esm/observation/arrays.js +1 -1
  87. package/dist/esm/observation/observable.bench.js +79 -0
  88. package/dist/esm/observation/observable.js +20 -15
  89. package/dist/esm/observation/update-queue.js +2 -2
  90. package/dist/esm/pending-task.js +13 -1
  91. package/dist/esm/platform.js +12 -2
  92. package/dist/esm/polyfills.js +3 -61
  93. package/dist/esm/styles/css-binding-directive.js +76 -0
  94. package/dist/esm/styles/css.js +14 -7
  95. package/dist/esm/styles/element-styles.js +0 -33
  96. package/dist/esm/styles/style-strategy.js +1 -0
  97. package/dist/esm/templating/children.js +8 -4
  98. package/dist/esm/templating/compiler.js +37 -44
  99. package/dist/esm/templating/html-binding-directive.js +218 -0
  100. package/dist/esm/templating/html-directive.js +25 -152
  101. package/dist/esm/templating/install-hydratable-view-templates.js +17 -0
  102. package/dist/esm/templating/node-observation.js +14 -8
  103. package/dist/esm/templating/ref.js +1 -1
  104. package/dist/esm/templating/render.bench.js +56 -0
  105. package/dist/esm/templating/render.js +74 -30
  106. package/dist/esm/templating/repeat-basic-reverse.bench.js +43 -0
  107. package/dist/esm/templating/repeat-basic-shift.bench.js +43 -0
  108. package/dist/esm/templating/repeat.js +116 -17
  109. package/dist/esm/templating/template.js +135 -60
  110. package/dist/esm/templating/view.js +254 -34
  111. package/dist/esm/templating/when-basic.bench.js +36 -0
  112. package/dist/esm/templating/when-conditional.bench.js +39 -0
  113. package/dist/esm/templating/when-switch.bench.js +68 -0
  114. package/dist/esm/templating/when.js +12 -5
  115. package/dist/esm/testing/fakes.js +32 -1
  116. package/dist/esm/testing/fixture.js +1 -1
  117. package/dist/esm/utilities.js +97 -1
  118. package/dist/fast-element.api.json +9788 -5666
  119. package/dist/fast-element.d.ts +813 -2392
  120. package/dist/fast-element.debug.js +2785 -969
  121. package/dist/fast-element.debug.min.js +3 -1
  122. package/dist/fast-element.js +2638 -828
  123. package/dist/fast-element.min.js +3 -1
  124. package/dist/fast-element.untrimmed.d.ts +661 -313
  125. package/docs/{api-report.md → api-report.api.md} +238 -151
  126. package/docs/context/api-report.api.md +69 -0
  127. package/docs/di/api-report.api.md +315 -0
  128. package/karma.conf.cjs +2 -1
  129. package/package.json +59 -47
  130. package/scripts/run-api-extractor.js +51 -0
  131. package/scripts/run-benchmarks.js +46 -0
  132. package/tensile.config.js +12 -0
  133. package/dist/dts/templating/dom.d.ts +0 -41
  134. package/dist/esm/templating/binding.js +0 -282
  135. package/dist/esm/templating/dom.js +0 -49
  136. package/docs/guide/declaring-templates.md +0 -230
  137. package/docs/guide/defining-elements.md +0 -214
  138. package/docs/guide/leveraging-css.md +0 -253
  139. package/docs/guide/next-steps.md +0 -13
  140. package/docs/guide/observables-and-state.md +0 -213
  141. package/docs/guide/using-directives.md +0 -576
  142. package/docs/guide/working-with-shadow-dom.md +0 -296
@@ -1,9 +1,11 @@
1
1
  import type { FASTElement } from "../components/fast-element.js";
2
+ import type { DOMPolicy } from "../dom.js";
2
3
  import { Constructable } from "../interfaces.js";
4
+ import { Binding, BindingDirective } from "../binding/binding.js";
3
5
  import type { Subscriber } from "../observation/notifier.js";
4
6
  import type { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
5
- import { ContentTemplate, ContentView } from "./binding.js";
6
- import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
7
+ import type { ContentTemplate, ContentView } from "./html-binding-directive.js";
8
+ import { AddViewBehaviorFactory, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
7
9
  import { CaptureType, SyntheticViewTemplate, TemplateValue, ViewTemplate } from "./template.js";
8
10
  /**
9
11
  * A Behavior that enables advanced rendering.
@@ -35,24 +37,21 @@ export declare class RenderBehavior<TSource = any> implements ViewBehavior, Subs
35
37
  unbind(controller: ViewController): void;
36
38
  /** @internal */
37
39
  handleChange(source: any, observer: ExpressionObserver): void;
40
+ private bindView;
38
41
  private refreshView;
39
42
  }
40
43
  /**
41
44
  * A Directive that enables use of the RenderBehavior.
42
45
  * @public
43
46
  */
44
- export declare class RenderDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
47
+ export declare class RenderDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory, BindingDirective {
45
48
  readonly dataBinding: Binding<TSource>;
46
49
  readonly templateBinding: Binding<TSource, ContentTemplate>;
47
50
  readonly templateBindingDependsOnData: boolean;
48
- /**
49
- * The unique id of the factory.
50
- */
51
- id: string;
52
51
  /**
53
52
  * The structural id of the DOM node to which the created behavior will apply.
54
53
  */
55
- nodeId: string;
54
+ targetNodeId: string;
56
55
  /**
57
56
  * Creates an instance of RenderDirective.
58
57
  * @param dataBinding - A binding expression that returns the data to render.
@@ -123,12 +122,41 @@ export declare type TemplateRenderOptions = CommonRenderOptions & {
123
122
  export declare type BaseElementRenderOptions<TSource = any, TParent = any> = CommonRenderOptions & {
124
123
  /**
125
124
  * Attributes to use when creating the element template.
125
+ * @remarks
126
+ * This API should be used with caution. When providing attributes, if not done properly,
127
+ * you can open up the application to XSS attacks. When using this API, provide a strong
128
+ * DOMPolicy that can properly sanitize and also be sure to manually sanitize attribute
129
+ * values particularly if they can come from user input.
126
130
  */
127
131
  attributes?: Record<string, string | TemplateValue<TSource, TParent>>;
128
132
  /**
129
133
  * Content to use when creating the element template.
134
+ * @remarks
135
+ * This API should be used with caution. When providing content, if not done properly,
136
+ * you can open up the application to XSS attacks. When using this API, provide a strong
137
+ * DOMPolicy that can properly sanitize and also be sure to manually sanitize content
138
+ * particularly if it can come from user input. Prefer passing a template
139
+ * created by the the html tag helper rather than passing a raw string, as that will
140
+ * enable the JS runtime to help secure the static strings.
130
141
  */
131
142
  content?: string | SyntheticViewTemplate;
143
+ /**
144
+ * The DOMPolicy to create the render instruction with.
145
+ */
146
+ policy?: DOMPolicy;
147
+ };
148
+ /**
149
+ * Render options for directly creating an element with {@link RenderInstruction.createElementTemplate}
150
+ * @public
151
+ */
152
+ export declare type ElementCreateOptions<TSource = any, TParent = any> = Omit<BaseElementRenderOptions, "type" | "name"> & {
153
+ /**
154
+ * Directives to use when creating the element template. These directives are applied directly to the specified tag.
155
+ *
156
+ * @remarks
157
+ * Directives supported by this API are: `ref`, `children`, `slotted`, or any custom `HTMLDirective` that can be used on a HTML tag.
158
+ */
159
+ directives?: TemplateValue<TSource, TParent>[];
132
160
  };
133
161
  /**
134
162
  * Render options used to specify an element.
@@ -150,7 +178,7 @@ export declare type TagNameRenderOptions<TSource = any, TParent = any> = BaseEle
150
178
  */
151
179
  tagName: string;
152
180
  };
153
- declare function createElementTemplate<TSource = any, TParent = any>(tagName: string, attributes?: Record<string, string | TemplateValue<TSource, TParent>>, content?: string | ContentTemplate): ViewTemplate<TSource, TParent>;
181
+ declare function createElementTemplate<TSource = any, TParent = any>(tagName: string, options?: ElementCreateOptions): ViewTemplate<TSource, TParent>;
154
182
  declare function create(options: TagNameRenderOptions): RenderInstruction;
155
183
  declare function create(options: ElementConstructorRenderOptions): RenderInstruction;
156
184
  declare function create(options: TemplateRenderOptions): RenderInstruction;
@@ -175,6 +203,11 @@ export declare const RenderInstruction: Readonly<{
175
203
  /**
176
204
  * Creates a RenderInstruction for a set of options.
177
205
  * @param options - The options to use when creating the RenderInstruction.
206
+ * @remarks
207
+ * This API should be used with caution. When providing attributes or content,
208
+ * if not done properly, you can open up the application to XSS attacks. When using this API,
209
+ * provide a strong DOMPolicy that can properly sanitize and also be sure to manually sanitize
210
+ * content and attribute values particularly if they can come from user input.
178
211
  */
179
212
  create: typeof create;
180
213
  /**
@@ -182,7 +215,13 @@ export declare const RenderInstruction: Readonly<{
182
215
  * @param tagName - The tag name to use when creating the template.
183
216
  * @param attributes - The attributes to apply to the element.
184
217
  * @param content - The content to insert into the element.
218
+ * @param policy - The DOMPolicy to create the template with.
185
219
  * @returns A template based on the provided specifications.
220
+ * @remarks
221
+ * This API should be used with caution. When providing attributes or content,
222
+ * if not done properly, you can open up the application to XSS attacks. When using this API,
223
+ * provide a strong DOMPolicy that can properly sanitize and also be sure to manually sanitize
224
+ * content and attribute values particularly if they can come from user input.
186
225
  */
187
226
  createElementTemplate: typeof createElementTemplate;
188
227
  /**
@@ -251,6 +290,7 @@ export declare class NodeTemplate implements ContentTemplate, ContentView {
251
290
  insertBefore(refNode: Node): void;
252
291
  remove(): void;
253
292
  create(): ContentView;
293
+ hydrate(first: Node, last: Node): ContentView;
254
294
  }
255
295
  /**
256
296
  * Creates a RenderDirective for use in advanced rendering scenarios.
@@ -0,0 +1,3 @@
1
+ declare const itemRenderer: () => HTMLElement;
2
+ export default itemRenderer;
3
+ export { tests } from "@tensile-perf/web-components";
@@ -0,0 +1,3 @@
1
+ declare const itemRenderer: () => HTMLElement;
2
+ export default itemRenderer;
3
+ export { tests } from "@tensile-perf/web-components";
@@ -1,8 +1,10 @@
1
+ import { Splice } from "../observation/arrays.js";
1
2
  import type { Subscriber } from "../observation/notifier.js";
2
3
  import { Expression, ExpressionObserver } from "../observation/observable.js";
3
- import { Splice } from "../observation/arrays.js";
4
- import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
4
+ import type { Binding, BindingDirective } from "../binding/binding.js";
5
+ import { AddViewBehaviorFactory, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
5
6
  import type { CaptureType, SyntheticViewTemplate, ViewTemplate } from "./template.js";
7
+ import { SyntheticView } from "./view.js";
6
8
  /**
7
9
  * Options for configuring repeat behavior.
8
10
  * @public
@@ -17,6 +19,28 @@ export interface RepeatOptions {
17
19
  */
18
20
  recycle?: boolean;
19
21
  }
22
+ export declare class HydrationRepeatError extends Error {
23
+ readonly propertyBag: {
24
+ index: number;
25
+ hydrationStage: string;
26
+ itemsLength?: number;
27
+ viewsState: string[];
28
+ viewTemplateString?: string;
29
+ rootNodeContent: string;
30
+ };
31
+ constructor(
32
+ /**
33
+ * The error message
34
+ */
35
+ message: string | undefined, propertyBag: {
36
+ index: number;
37
+ hydrationStage: string;
38
+ itemsLength?: number;
39
+ viewsState: string[];
40
+ viewTemplateString?: string;
41
+ rootNodeContent: string;
42
+ });
43
+ }
20
44
  /**
21
45
  * A behavior that renders a template for each item in an array.
22
46
  * @public
@@ -25,13 +49,14 @@ export declare class RepeatBehavior<TSource = any> implements ViewBehavior, Subs
25
49
  private directive;
26
50
  private location;
27
51
  private controller;
28
- private views;
29
52
  private template;
30
53
  private templateBindingObserver;
31
54
  private items;
32
55
  private itemsObserver;
33
56
  private itemsBindingObserver;
34
57
  private bindView;
58
+ /** @internal */
59
+ views: SyntheticView[];
35
60
  /**
36
61
  * Creates an instance of RepeatBehavior.
37
62
  * @param location - The location in the DOM to render the repeat.
@@ -61,23 +86,20 @@ export declare class RepeatBehavior<TSource = any> implements ViewBehavior, Subs
61
86
  private updateViews;
62
87
  private refreshAllViews;
63
88
  private unbindAllViews;
89
+ private hydrateViews;
64
90
  }
65
91
  /**
66
92
  * A directive that configures list rendering.
67
93
  * @public
68
94
  */
69
- export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
95
+ export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory, BindingDirective {
70
96
  readonly dataBinding: Binding<TSource>;
71
97
  readonly templateBinding: Binding<TSource, SyntheticViewTemplate>;
72
98
  readonly options: RepeatOptions;
73
- /**
74
- * The unique id of the factory.
75
- */
76
- id: string;
77
99
  /**
78
100
  * The structural id of the DOM node to which the created behavior will apply.
79
101
  */
80
- nodeId: string;
102
+ targetNodeId: string;
81
103
  /**
82
104
  * Creates a placeholder string based on the directive's index within the template.
83
105
  * @param index - The index of the directive within the template.
@@ -1,5 +1,7 @@
1
+ import type { DOMPolicy } from "../dom.js";
2
+ import { Binding } from "../binding/binding.js";
1
3
  import type { Expression } from "../observation/observable.js";
2
- import { Binding, HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
4
+ import { AddViewBehaviorFactory, CompiledViewBehaviorFactory, HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
3
5
  import type { ElementView, HTMLView, SyntheticView } from "./view.js";
4
6
  /**
5
7
  * A template capable of creating views specifically for rendering custom elements.
@@ -20,6 +22,16 @@ export interface ElementViewTemplate<TSource = any, TParent = any> {
20
22
  */
21
23
  render(source: TSource, host: Node, hostBindingTarget?: Element): ElementView<TSource, TParent>;
22
24
  }
25
+ export interface HydratableElementViewTemplate<TSource = any, TParent = any> extends ElementViewTemplate<TSource, TParent> {
26
+ hydrate(firstChild: Node, lastChild: Node, hostBindingTarget?: Element): ElementView<TSource, TParent>;
27
+ }
28
+ /**
29
+ * A marker interface used to capture types when interpolating Directive helpers
30
+ * into templates.
31
+ * @public
32
+ */
33
+ export interface CaptureType<TSource, TParent> {
34
+ }
23
35
  /**
24
36
  * A template capable of rendering views not specifically connected to custom elements.
25
37
  * @public
@@ -29,6 +41,13 @@ export interface SyntheticViewTemplate<TSource = any, TParent = any> {
29
41
  * Creates a SyntheticView instance based on this template definition.
30
42
  */
31
43
  create(): SyntheticView<TSource, TParent>;
44
+ /**
45
+ * Returns a directive that can inline the template.
46
+ */
47
+ inline(): CaptureType<TSource, TParent>;
48
+ }
49
+ export interface HydratableSyntheticViewTemplate<TSource = any, TParent = any> extends SyntheticViewTemplate {
50
+ hydrate(firstChild: Node, lastChild: Node): SyntheticView<TSource, TParent>;
32
51
  }
33
52
  /**
34
53
  * The result of a template compilation operation.
@@ -40,12 +59,41 @@ export interface HTMLTemplateCompilationResult<TSource = any, TParent = any> {
40
59
  * @param hostBindingTarget - The host binding target for the view.
41
60
  */
42
61
  createView(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
62
+ readonly factories: CompiledViewBehaviorFactory[];
63
+ }
64
+ /**
65
+ * Represents the types of values that can be interpolated into a template.
66
+ * @public
67
+ */
68
+ export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
69
+ /**
70
+ * Inlines a template into another template.
71
+ * @public
72
+ */
73
+ export declare class InlineTemplateDirective implements HTMLDirective {
74
+ private html;
75
+ private factories;
76
+ /**
77
+ * An empty template partial.
78
+ */
79
+ static readonly empty: InlineTemplateDirective;
80
+ /**
81
+ * Creates an instance of InlineTemplateDirective.
82
+ * @param template - The template to inline.
83
+ */
84
+ constructor(html: string, factories?: Record<string, ViewBehaviorFactory>);
85
+ /**
86
+ * Creates HTML to be used within a template.
87
+ * @param add - Can be used to add behavior factories to a template.
88
+ */
89
+ createHTML(add: AddViewBehaviorFactory): string;
43
90
  }
44
91
  /**
45
92
  * A template capable of creating HTMLView instances or rendering directly to DOM.
46
93
  * @public
47
94
  */
48
95
  export declare class ViewTemplate<TSource = any, TParent = any> implements ElementViewTemplate<TSource, TParent>, SyntheticViewTemplate<TSource, TParent> {
96
+ private policy?;
49
97
  private result;
50
98
  /**
51
99
  * The html representing what this template will
@@ -60,13 +108,31 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
60
108
  * Creates an instance of ViewTemplate.
61
109
  * @param html - The html representing what this template will instantiate, including placeholders for directives.
62
110
  * @param factories - The directives that will be connected to placeholders in the html.
111
+ * @param policy - The security policy to use when compiling this template.
63
112
  */
64
- constructor(html: string | HTMLTemplateElement, factories: Record<string, ViewBehaviorFactory>);
113
+ constructor(html: string | HTMLTemplateElement, factories?: Record<string, ViewBehaviorFactory>, policy?: DOMPolicy | undefined);
114
+ /**
115
+ * @internal
116
+ */
117
+ compile(): HTMLTemplateCompilationResult<TSource, TParent>;
65
118
  /**
66
119
  * Creates an HTMLView instance based on this template definition.
67
120
  * @param hostBindingTarget - The element that host behaviors will be bound to.
68
121
  */
69
122
  create(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
123
+ /**
124
+ * Returns a directive that can inline the template.
125
+ */
126
+ inline(): CaptureType<TSource, TParent>;
127
+ /**
128
+ * Sets the DOMPolicy for this template.
129
+ * @param policy - The policy to associated with this template.
130
+ * @returns The modified template instance.
131
+ * @remarks
132
+ * The DOMPolicy can only be set once for a template and cannot be
133
+ * set after the template is compiled.
134
+ */
135
+ withPolicy(policy: DOMPolicy): this;
70
136
  /**
71
137
  * Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
72
138
  * @param source - The data source to bind the template to.
@@ -75,19 +141,38 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
75
141
  * host that the template is being attached to.
76
142
  */
77
143
  render(source: TSource, host: Node, hostBindingTarget?: Element): HTMLView<TSource, TParent>;
144
+ /**
145
+ * Creates a template based on a set of static strings and dynamic values.
146
+ * @param strings - The static strings to create the template with.
147
+ * @param values - The dynamic values to create the template with.
148
+ * @param policy - The DOMPolicy to associated with the template.
149
+ * @returns A ViewTemplate.
150
+ * @remarks
151
+ * This API should not be used directly under normal circumstances because constructing
152
+ * a template in this way, if not done properly, can open up the application to XSS
153
+ * attacks. When using this API, provide a strong DOMPolicy that can properly sanitize
154
+ * and also be sure to manually sanitize all static strings particularly if they can
155
+ * come from user input.
156
+ */
157
+ static create<TSource = any, TParent = any>(strings: string[], values: TemplateValue<TSource, TParent>[], policy?: DOMPolicy): ViewTemplate<TSource, TParent>;
78
158
  }
79
159
  /**
80
- * A marker interface used to capture types when interpolating Directive helpers
81
- * into templates.
82
- * @public
83
- */
84
- export interface CaptureType<TSource, TParent> {
85
- }
86
- /**
87
- * Represents the types of values that can be interpolated into a template.
160
+ * Transforms a template literal string into a ViewTemplate.
161
+ * @param strings - The string fragments that are interpolated with the values.
162
+ * @param values - The values that are interpolated with the string fragments.
163
+ * @remarks
164
+ * The html helper supports interpolation of strings, numbers, binding expressions,
165
+ * other template instances, and Directive instances.
88
166
  * @public
89
167
  */
90
- export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
168
+ export declare type HTMLTemplateTag = (<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent>[]) => ViewTemplate<TSource, TParent>) & {
169
+ /**
170
+ * Transforms a template literal string into partial HTML.
171
+ * @param html - The HTML string fragment to interpolate.
172
+ * @public
173
+ */
174
+ partial(html: string): InlineTemplateDirective;
175
+ };
91
176
  /**
92
177
  * Transforms a template literal string into a ViewTemplate.
93
178
  * @param strings - The string fragments that are interpolated with the values.
@@ -97,4 +182,4 @@ export declare type TemplateValue<TSource, TParent = any> = Expression<TSource,
97
182
  * other template instances, and Directive instances.
98
183
  * @public
99
184
  */
100
- export declare function html<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent>[]): ViewTemplate<TSource, TParent>;
185
+ export declare const html: HTMLTemplateTag;
@@ -1,6 +1,9 @@
1
+ import { Hydratable } from "../components/hydration.js";
2
+ import { ViewBehaviorBoundaries } from "../hydration/target-builder.js";
3
+ import type { ViewTemplate } from "../templating/template.js";
1
4
  import type { Disposable } from "../interfaces.js";
2
5
  import { ExecutionContext, SourceLifetime } from "../observation/observable.js";
3
- import type { ViewBehaviorFactory, ViewBehaviorTargets, ViewController } from "./html-directive.js";
6
+ import type { CompiledViewBehaviorFactory, ViewBehaviorFactory, ViewBehaviorTargets, ViewController } from "./html-directive.js";
4
7
  /**
5
8
  * Represents a collection of DOM nodes which can be bound to a data source.
6
9
  * @public
@@ -14,6 +17,10 @@ export interface View<TSource = any, TParent = any> extends Disposable {
14
17
  * The data that the view is bound to.
15
18
  */
16
19
  readonly source: TSource | null;
20
+ /**
21
+ * Indicates whether the controller is bound.
22
+ */
23
+ readonly isBound: boolean;
17
24
  /**
18
25
  * Binds a view's behaviors to its binding source.
19
26
  * @param source - The binding source for the view's binding behaviors.
@@ -29,6 +36,17 @@ export interface View<TSource = any, TParent = any> extends Disposable {
29
36
  * @public
30
37
  */
31
38
  export interface ElementView<TSource = any, TParent = any> extends View<TSource, TParent> {
39
+ /**
40
+ * Indicates how the source's lifetime relates to the controller's lifetime.
41
+ */
42
+ readonly sourceLifetime?: SourceLifetime;
43
+ /**
44
+ * Registers an unbind handler with the controller.
45
+ * @param behavior - An object to call when the controller unbinds.
46
+ */
47
+ onUnbind(behavior: {
48
+ unbind(controller: ViewController<TSource, TParent>): any;
49
+ }): void;
32
50
  /**
33
51
  * Appends the view's DOM nodes to the referenced node.
34
52
  * @param node - The parent node to append the view's DOM nodes to.
@@ -59,32 +77,7 @@ export interface SyntheticView<TSource = any, TParent = any> extends View<TSourc
59
77
  */
60
78
  remove(): void;
61
79
  }
62
- /**
63
- * The standard View implementation, which also implements ElementView and SyntheticView.
64
- * @public
65
- */
66
- export declare class HTMLView<TSource = any, TParent = any> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent>, ExecutionContext<TParent> {
67
- private fragment;
68
- private factories;
69
- readonly targets: ViewBehaviorTargets;
70
- private behaviors;
71
- private unbindables;
72
- /**
73
- * The data that the view is bound to.
74
- */
75
- source: TSource | null;
76
- /**
77
- * Indicates whether the controller is bound.
78
- */
79
- isBound: boolean;
80
- /**
81
- * Indicates how the source's lifetime relates to the controller's lifetime.
82
- */
83
- readonly sourceLifetime: SourceLifetime;
84
- /**
85
- * The execution context the view is running within.
86
- */
87
- context: ExecutionContext<TParent>;
80
+ declare class DefaultExecutionContext<TParent> implements ExecutionContext<TParent> {
88
81
  /**
89
82
  * The index of the current item within a repeat context.
90
83
  */
@@ -138,6 +131,33 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
138
131
  * Returns the typed event target of the event.
139
132
  */
140
133
  eventTarget<TTarget extends EventTarget>(): TTarget;
134
+ }
135
+ /**
136
+ * The standard View implementation, which also implements ElementView and SyntheticView.
137
+ * @public
138
+ */
139
+ export declare class HTMLView<TSource = any, TParent = any> extends DefaultExecutionContext<TParent> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent>, ExecutionContext<TParent> {
140
+ private fragment;
141
+ private factories;
142
+ readonly targets: ViewBehaviorTargets;
143
+ private behaviors;
144
+ private unbindables;
145
+ /**
146
+ * The data that the view is bound to.
147
+ */
148
+ source: TSource | null;
149
+ /**
150
+ * Indicates whether the controller is bound.
151
+ */
152
+ isBound: boolean;
153
+ /**
154
+ * Indicates how the source's lifetime relates to the controller's lifetime.
155
+ */
156
+ readonly sourceLifetime: SourceLifetime;
157
+ /**
158
+ * The execution context the view is running within.
159
+ */
160
+ context: ExecutionContext<TParent>;
141
161
  /**
142
162
  * The first DOM node in the range of nodes that make up the view.
143
163
  */
@@ -151,7 +171,7 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
151
171
  * @param fragment - The html fragment that contains the nodes for this view.
152
172
  * @param behaviors - The behaviors to be applied to this view.
153
173
  */
154
- constructor(fragment: DocumentFragment, factories: ReadonlyArray<ViewBehaviorFactory>, targets: ViewBehaviorTargets);
174
+ constructor(fragment: DocumentFragment, factories: ReadonlyArray<CompiledViewBehaviorFactory>, targets: ViewBehaviorTargets);
155
175
  /**
156
176
  * Appends the view's DOM nodes to the referenced node.
157
177
  * @param node - The parent node to append the view's DOM nodes to.
@@ -173,7 +193,7 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
173
193
  */
174
194
  dispose(): void;
175
195
  onUnbind(behavior: {
176
- unbind(controller: ViewController<TSource, TParent>): any;
196
+ unbind(controller: ViewController<TSource, TParent>): void;
177
197
  }): void;
178
198
  /**
179
199
  * Binds a view's behaviors to its binding source.
@@ -192,3 +212,100 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
192
212
  */
193
213
  static disposeContiguousBatch(views: SyntheticView[]): void;
194
214
  }
215
+ /** @public */
216
+ export interface HydratableView<TSource = any, TParent = any> extends ElementView, SyntheticView, DefaultExecutionContext<TParent> {
217
+ [Hydratable]: symbol;
218
+ readonly bindingViewBoundaries: Record<string, ViewNodes>;
219
+ readonly hydrationStage: keyof typeof HydrationStage;
220
+ }
221
+ export interface ViewNodes {
222
+ first: Node;
223
+ last: Node;
224
+ }
225
+ export declare const HydrationStage: {
226
+ readonly unhydrated: "unhydrated";
227
+ readonly hydrating: "hydrating";
228
+ readonly hydrated: "hydrated";
229
+ };
230
+ /** @public */
231
+ export declare class HydrationBindingError extends Error {
232
+ /**
233
+ * The factory that was unable to be bound
234
+ */
235
+ readonly factory: ViewBehaviorFactory;
236
+ /**
237
+ * A DocumentFragment containing a clone of the
238
+ * view's Nodes.
239
+ */
240
+ readonly fragment: DocumentFragment;
241
+ /**
242
+ * String representation of the HTML in the template that
243
+ * threw the binding error.
244
+ */
245
+ readonly templateString: string;
246
+ constructor(
247
+ /**
248
+ * The error message
249
+ */
250
+ message: string | undefined,
251
+ /**
252
+ * The factory that was unable to be bound
253
+ */
254
+ factory: ViewBehaviorFactory,
255
+ /**
256
+ * A DocumentFragment containing a clone of the
257
+ * view's Nodes.
258
+ */
259
+ fragment: DocumentFragment,
260
+ /**
261
+ * String representation of the HTML in the template that
262
+ * threw the binding error.
263
+ */
264
+ templateString: string);
265
+ }
266
+ export declare class HydrationView<TSource = any, TParent = any> extends DefaultExecutionContext<TParent> implements HydratableView {
267
+ readonly firstChild: Node;
268
+ readonly lastChild: Node;
269
+ private sourceTemplate;
270
+ private hostBindingTarget?;
271
+ [Hydratable]: symbol;
272
+ context: ExecutionContext<any>;
273
+ source: TSource | null;
274
+ isBound: boolean;
275
+ get hydrationStage(): "unhydrated" | "hydrating" | "hydrated";
276
+ get targets(): ViewBehaviorTargets;
277
+ get bindingViewBoundaries(): ViewBehaviorBoundaries;
278
+ readonly sourceLifetime: SourceLifetime;
279
+ private unbindables;
280
+ private fragment;
281
+ private behaviors;
282
+ private factories;
283
+ private _hydrationStage;
284
+ private _bindingViewBoundaries;
285
+ private _targets;
286
+ constructor(firstChild: Node, lastChild: Node, sourceTemplate: ViewTemplate, hostBindingTarget?: Element | undefined);
287
+ /**
288
+ * no-op. Hydrated views are don't need to be moved from a documentFragment
289
+ * to the target node.
290
+ */
291
+ insertBefore(node: Node): void;
292
+ /**
293
+ * Appends the view to a node. In cases where this is called before the
294
+ * view has been removed, the method will no-op.
295
+ * @param node - the node to append the view to.
296
+ */
297
+ appendTo(node: Node): void;
298
+ remove(): void;
299
+ bind(source: TSource, context?: ExecutionContext<any>): void;
300
+ unbind(): void;
301
+ /**
302
+ * Removes the view and unbinds its behaviors, disposing of DOM nodes afterward.
303
+ * Once a view has been disposed, it cannot be inserted or bound again.
304
+ */
305
+ dispose(): void;
306
+ onUnbind(behavior: {
307
+ unbind(controller: ViewController<TSource, TParent>): void;
308
+ }): void;
309
+ private evaluateUnbindables;
310
+ }
311
+ export {};
@@ -0,0 +1,3 @@
1
+ declare const itemRenderer: () => HTMLElement;
2
+ export default itemRenderer;
3
+ export { tests } from "@tensile-perf/web-components";
@@ -0,0 +1,3 @@
1
+ declare const itemRenderer: () => HTMLElement;
2
+ export default itemRenderer;
3
+ export { tests } from "@tensile-perf/web-components";
@@ -0,0 +1,3 @@
1
+ declare const itemRenderer: () => HTMLElement;
2
+ export default itemRenderer;
3
+ export { tests } from "@tensile-perf/web-components";
@@ -5,6 +5,8 @@ import type { CaptureType, SyntheticViewTemplate } from "./template.js";
5
5
  * @param condition - The condition to test for rendering.
6
6
  * @param templateOrTemplateBinding - The template or a binding that gets
7
7
  * the template to render when the condition is true.
8
+ * @param elseTemplateOrTemplateBinding - Optional template or binding that that
9
+ * gets the template to render when the conditional is false.
8
10
  * @public
9
11
  */
10
- export declare function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType<TSource, TParent>;
12
+ export declare function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>, elseTemplateOrTemplateBinding?: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType<TSource, TParent>;
@@ -1,4 +1,15 @@
1
- import { ExecutionContext } from "../index.js";
1
+ import { ExecutionContext } from "../observation/observable.js";
2
+ import type { ViewBehavior, ViewBehaviorTargets } from "../templating/html-directive.js";
2
3
  export declare const Fake: Readonly<{
3
4
  executionContext<TParent = any>(parent?: TParent | undefined, parentContext?: ExecutionContext<TParent> | undefined): ExecutionContext<TParent>;
5
+ viewController<TSource = any, TParent_1 = any>(targets?: ViewBehaviorTargets, ...behaviors: ViewBehavior<TSource, TParent_1>[]): {
6
+ isBound: boolean;
7
+ context: ExecutionContext<TParent_1>;
8
+ onUnbind(object: any): void;
9
+ source: TSource;
10
+ targets: ViewBehaviorTargets;
11
+ toJSON: () => undefined;
12
+ bind(source: TSource, context?: ExecutionContext<TParent_1>): void;
13
+ unbind(): void;
14
+ };
4
15
  }>;
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.24.2"
8
+ "packageVersion": "7.47.0"
9
9
  }
10
10
  ]
11
11
  }