@microsoft/fast-html 1.0.0-alpha.4 → 1.0.0-alpha.41

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 (68) hide show
  1. package/README.md +266 -19
  2. package/dist/dts/components/element.d.ts +10 -0
  3. package/dist/dts/components/index.d.ts +3 -1
  4. package/dist/dts/components/observer-map.d.ts +27 -0
  5. package/dist/dts/components/schema.d.ts +144 -0
  6. package/dist/dts/components/template.d.ts +83 -7
  7. package/dist/dts/components/utilities.d.ts +128 -37
  8. package/dist/dts/index.d.ts +1 -1
  9. package/dist/dts/tsdoc-metadata.json +1 -1
  10. package/dist/esm/components/element.js +73 -0
  11. package/dist/esm/components/index.js +3 -1
  12. package/dist/esm/components/observer-map.js +68 -0
  13. package/dist/esm/components/observer-map.spec.js +39 -0
  14. package/dist/esm/components/schema.js +250 -0
  15. package/dist/esm/components/schema.spec.js +484 -0
  16. package/dist/esm/components/template.js +242 -213
  17. package/dist/esm/components/utilities.js +1008 -64
  18. package/dist/esm/components/utilities.spec.js +522 -93
  19. package/dist/esm/index.js +1 -1
  20. package/dist/fast-html.api.json +350 -1
  21. package/dist/fast-html.d.ts +283 -6
  22. package/dist/fast-html.untrimmed.d.ts +283 -6
  23. package/package.json +27 -38
  24. package/rules/attribute-directives.yml +38 -0
  25. package/rules/call-expression-with-event-argument.yml +41 -0
  26. package/rules/member-expression.yml +33 -0
  27. package/rules/tag-function-to-template-literal.yml +16 -0
  28. package/dist/dts/fixtures/binding/binding.spec.d.ts +0 -1
  29. package/dist/dts/fixtures/binding/main.d.ts +0 -1
  30. package/dist/dts/fixtures/children/children.spec.d.ts +0 -1
  31. package/dist/dts/fixtures/children/main.d.ts +0 -1
  32. package/dist/dts/fixtures/dot-syntax/dot-syntax.spec.d.ts +0 -1
  33. package/dist/dts/fixtures/dot-syntax/main.d.ts +0 -1
  34. package/dist/dts/fixtures/event/event.spec.d.ts +0 -1
  35. package/dist/dts/fixtures/event/main.d.ts +0 -1
  36. package/dist/dts/fixtures/partial/main.d.ts +0 -1
  37. package/dist/dts/fixtures/partial/partial.spec.d.ts +0 -1
  38. package/dist/dts/fixtures/ref/main.d.ts +0 -1
  39. package/dist/dts/fixtures/ref/ref.spec.d.ts +0 -1
  40. package/dist/dts/fixtures/repeat/main.d.ts +0 -1
  41. package/dist/dts/fixtures/repeat/repeat.spec.d.ts +0 -1
  42. package/dist/dts/fixtures/slotted/main.d.ts +0 -1
  43. package/dist/dts/fixtures/slotted/slotted.spec.d.ts +0 -1
  44. package/dist/dts/fixtures/when/main.d.ts +0 -1
  45. package/dist/dts/fixtures/when/when.spec.d.ts +0 -1
  46. package/dist/esm/fixtures/attribute/attribute.spec.js +0 -23
  47. package/dist/esm/fixtures/attribute/main.js +0 -19
  48. package/dist/esm/fixtures/binding/binding.spec.js +0 -17
  49. package/dist/esm/fixtures/binding/main.js +0 -19
  50. package/dist/esm/fixtures/children/children.spec.js +0 -33
  51. package/dist/esm/fixtures/children/main.js +0 -24
  52. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +0 -9
  53. package/dist/esm/fixtures/dot-syntax/main.js +0 -16
  54. package/dist/esm/fixtures/event/event.spec.js +0 -12
  55. package/dist/esm/fixtures/event/main.js +0 -16
  56. package/dist/esm/fixtures/partial/main.js +0 -31
  57. package/dist/esm/fixtures/partial/partial.spec.js +0 -14
  58. package/dist/esm/fixtures/ref/main.js +0 -14
  59. package/dist/esm/fixtures/ref/ref.spec.js +0 -13
  60. package/dist/esm/fixtures/repeat/main.js +0 -19
  61. package/dist/esm/fixtures/repeat/repeat.spec.js +0 -26
  62. package/dist/esm/fixtures/slotted/main.js +0 -22
  63. package/dist/esm/fixtures/slotted/slotted.spec.js +0 -25
  64. package/dist/esm/fixtures/when/main.js +0 -146
  65. package/dist/esm/fixtures/when/when.spec.js +0 -82
  66. package/dist/esm/tsconfig.tsbuildinfo +0 -1
  67. /package/dist/dts/{fixtures/attribute/attribute.spec.d.ts → components/observer-map.spec.d.ts} +0 -0
  68. /package/dist/dts/{fixtures/attribute/main.d.ts → components/schema.spec.d.ts} +0 -0
package/README.md CHANGED
@@ -22,7 +22,13 @@ npm install --save @microsoft/fast-html
22
22
  In your JS bundle you will need to include the `@microsoft/fast-html` package:
23
23
 
24
24
  ```typescript
25
- import { TemplateElement } from "@microsoft/fast-html";
25
+ import { RenderableFASTElement, TemplateElement } from "@microsoft/fast-html";
26
+ import { MyCustomElement } from "./my-custom-element";
27
+
28
+ RenderableFASTElement(MyCustomElement).defineAsync({
29
+ name: "my-custom-element",
30
+ templateOptions: "defer-and-hydrate",
31
+ });
26
32
 
27
33
  TemplateElement.define({
28
34
  name: "f-template",
@@ -45,9 +51,183 @@ Example:
45
51
  </f-template>
46
52
  ```
47
53
 
54
+ #### Non-browser HTML rendering
55
+
56
+ One of the benefits of FAST declarative HTML templates is that the server can be stack agnostic as JavaScript does not need to be interpreted. By default `@microsoft/fast-html` will expect hydratable content and uses comments and datasets for tracking the binding logic. For more information on what that markup should look like, as well as an example of how initial state may be applied, read our [documentation](./RENDERING.md) to understand what markup should be generated for a hydratable experience. For the sake of brevity hydratable markup will be excluded from the README.
57
+
58
+ #### Using the RenderableFASTElement
59
+
60
+ The use of `RenderableFASTElement` as a mixin for your custom element will automatically remove the `defer-hydration` attribute signalling for hydration to begin, and if you need to add state before hydration should occur you can make use of the `prepare` method.
61
+
62
+ Example:
63
+ ```typescript
64
+ class MyCustomElement extends FASTElement {
65
+ private prepare(): Promise<void> {
66
+ // Get initial state
67
+ }
68
+ }
69
+
70
+ RenderableFASTElement(MyCustomElement).defineAsync({
71
+ name: "my-custom-element",
72
+ templateOptions: "defer-and-hydrate",
73
+ });
74
+ ```
75
+
76
+ #### Lifecycle Callbacks
77
+
78
+ FAST HTML provides lifecycle callbacks that allow you to hook into various stages of template processing and element hydration. These callbacks are useful for tracking the rendering lifecycle, gathering analytics, or coordinating complex initialization sequences.
79
+
80
+ ##### Available Callbacks
81
+
82
+ **Template Lifecycle Callbacks:**
83
+ - `elementDidRegister(name: string)` - Called after the JavaScript class definition has been registered
84
+ - `templateWillUpdate(name: string)` - Called before the template has been evaluated and assigned
85
+ - `templateDidUpdate(name: string)` - Called after the template has been assigned to the definition
86
+ - `elementDidDefine(name: string)` - Called after the custom element has been defined
87
+
88
+ **Hydration Lifecycle Callbacks:**
89
+ - `elementWillHydrate(name: string)` - Called before an element begins hydration
90
+ - `elementDidHydrate(name: string)` - Called after an element completes hydration
91
+ - `hydrationComplete()` - Called after all elements have completed hydration
92
+
93
+ ##### Configuring Callbacks
94
+
95
+ Configure lifecycle callbacks using `TemplateElement.config()`:
96
+
97
+ ```typescript
98
+ import { TemplateElement, type HydrationLifecycleCallbacks } from "@microsoft/fast-html";
99
+
100
+ // You can configure all callbacks at once
101
+ const callbacks: HydrationLifecycleCallbacks = {
102
+ elementDidRegister(name: string) {
103
+ console.log(`Element registered: ${name}`);
104
+ },
105
+ templateWillUpdate(name: string) {
106
+ console.log(`Template updating: ${name}`);
107
+ },
108
+ templateDidUpdate(name: string) {
109
+ console.log(`Template updated: ${name}`);
110
+ },
111
+ elementDidDefine(name: string) {
112
+ console.log(`Element defined: ${name}`);
113
+ },
114
+ elementWillHydrate(name: string) {
115
+ console.log(`Element will hydrate: ${name}`);
116
+ },
117
+ elementDidHydrate(name: string) {
118
+ console.log(`Element hydrated: ${name}`);
119
+ },
120
+ hydrationComplete() {
121
+ console.log('All elements hydrated');
122
+ }
123
+ };
124
+
125
+ TemplateElement.config(callbacks);
126
+
127
+ // Or configure only the callbacks you need
128
+ TemplateElement.config({
129
+ elementDidHydrate(name: string) {
130
+ console.log(`${name} is ready`);
131
+ },
132
+ hydrationComplete() {
133
+ console.log('Page is interactive');
134
+ }
135
+ });
136
+ ```
137
+
138
+ ##### Lifecycle Order
139
+
140
+ The lifecycle callbacks occur in the following general sequence:
141
+
142
+ 1. **Registration Phase**: `elementDidRegister` is called when the element class is registered
143
+ 2. **Template Phase**: `templateWillUpdate` → (template processing) → `templateDidUpdate` → `elementDidDefine`
144
+ 3. **Hydration Phase**: `elementWillHydrate` → (hydration) → `elementDidHydrate`
145
+ 4. **Completion**: `hydrationComplete` is called after all elements finish hydrating
146
+
147
+ **Note:** Template processing is asynchronous and happens independently for each element. The template and hydration phases can be interleaved when multiple elements are being processed simultaneously.
148
+
149
+ ##### Use Cases
150
+
151
+ **Performance Monitoring:**
152
+ ```typescript
153
+ TemplateElement.config({
154
+ elementWillHydrate(name: string) {
155
+ performance.mark(`${name}-hydration-start`);
156
+ },
157
+ elementDidHydrate(name: string) {
158
+ performance.mark(`${name}-hydration-end`);
159
+ performance.measure(
160
+ `${name}-hydration`,
161
+ `${name}-hydration-start`,
162
+ `${name}-hydration-end`
163
+ );
164
+ },
165
+ hydrationComplete() {
166
+ // Report to analytics
167
+ const entries = performance.getEntriesByType('measure');
168
+ console.log('Hydration metrics:', entries);
169
+ }
170
+ });
171
+ ```
172
+
173
+ **Loading State Management:**
174
+ ```typescript
175
+ TemplateElement.config({
176
+ elementWillHydrate(name: string) {
177
+ // Show loading indicator
178
+ document.body.classList.add('hydrating');
179
+ },
180
+ hydrationComplete() {
181
+ // Hide loading indicator once all elements are ready
182
+ document.body.classList.remove('hydrating');
183
+ document.body.classList.add('hydrated');
184
+ }
185
+ });
186
+ ```
187
+
188
+ **Debugging and Development:**
189
+ ```typescript
190
+ if (process.env.NODE_ENV === 'development') {
191
+ const events: Array<{callback: string; name?: string; timestamp: number}> = [];
192
+
193
+ TemplateElement.config({
194
+ elementDidRegister(name) {
195
+ events.push({ callback: 'elementDidRegister', name, timestamp: Date.now() });
196
+ },
197
+ templateWillUpdate(name) {
198
+ events.push({ callback: 'templateWillUpdate', name, timestamp: Date.now() });
199
+ },
200
+ templateDidUpdate(name) {
201
+ events.push({ callback: 'templateDidUpdate', name, timestamp: Date.now() });
202
+ },
203
+ elementDidDefine(name) {
204
+ events.push({ callback: 'elementDidDefine', name, timestamp: Date.now() });
205
+ },
206
+ elementWillHydrate(name) {
207
+ events.push({ callback: 'elementWillHydrate', name, timestamp: Date.now() });
208
+ },
209
+ elementDidHydrate(name) {
210
+ events.push({ callback: 'elementDidHydrate', name, timestamp: Date.now() });
211
+ },
212
+ hydrationComplete() {
213
+ events.push({ callback: 'hydrationComplete', timestamp: Date.now() });
214
+ console.table(events);
215
+ }
216
+ });
217
+ }
218
+ ```
219
+
48
220
  ### Syntax
49
221
 
50
- All bindings use a handlebars syntax.
222
+ All bindings use a handlebars-like syntax.
223
+
224
+ Some bindings are only relevant to the browser, such as for click handlers or other pieces of dynamic interaction. As such, their bindings use single curly braces `{}`, this is to prevent an intial SSR (Server Side Rendering) or other build time rendering technologies from needing to interpret them.
225
+
226
+ If a binding is relevant to both client and the back end rendering engine, it will use `{{}}` or `{{{}}}` depending on what type of data injection is being done.
227
+
228
+ Browser-only bindings:
229
+ - Event bindings
230
+ - Attribute directives
51
231
 
52
232
  #### Content binding
53
233
 
@@ -60,33 +240,49 @@ All bindings use a handlebars syntax.
60
240
  Event bindings must include the `()` as well as being preceeded by `@` in keeping with `@microsoft/fast-element` tagged template `html` syntax.
61
241
 
62
242
  ```html
63
- <button @click="{{handleClick()}}"></button>
243
+ <button @click="{handleClick()}"></button>
244
+ ```
245
+
246
+ In addition you may include an event or attribute or observable, events are denoted with `e` as a reserved letter.
247
+
248
+ Event:
249
+ ```html
250
+ <button @click="{handleClick(e)}"></button>
251
+ ```
252
+
253
+ Attribute/Observable:
254
+ ```html
255
+ <button @click="{handleClick(foo)}"></button>
64
256
  ```
65
257
 
66
258
  #### Directives
67
259
 
68
260
  Directives are assumed to be either an attribute directive or a directive that also serves a template. Both are prepended by `f-`. The logic of these directives and what their use cases are is explained in the [FAST html documentation](https://fast.design/docs/getting-started/html-directives).
69
261
 
262
+ Attribute directives are part of [client side binding](#syntax) and therefore use the `{}` syntax.
263
+
70
264
  Attribute directives include:
71
265
  - **slotted**
72
266
 
73
267
  Example:
74
268
  ```html
75
- <slot f-slotted="{{slottedNodes}}"></slot>
269
+ <slot f-slotted="{slottedNodes}"></slot>
270
+ <slot f-slotted="{slottedNodes filter elements()}"></slot>
271
+ <slot f-slotted="{slottedNodes filter elements(div, p)}"></slot>
76
272
  ```
77
273
 
78
274
  - **children**
79
275
 
80
276
  Example:
81
277
  ```html
82
- <ul f-children="{{listItems}}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
278
+ <ul f-children="{listItems}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
83
279
  ```
84
280
 
85
281
  - **ref**
86
282
 
87
283
  Example:
88
284
  ```html
89
- <video f-ref="{{video}}"></video>
285
+ <video f-ref="{video}"></video>
90
286
  ```
91
287
 
92
288
  Template directives include:
@@ -117,26 +313,77 @@ Where the right operand can be either a reference to a value (string e.g. `{{foo
117
313
  <ul><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
118
314
  ```
119
315
 
120
- - **partial & apply**
316
+ Bindings inside `<f-repeat>` without a context prefix resolve to the custom element. For example, `{{title}}` below resolves to the host element's `title` property:
121
317
 
122
- These directives are new to the declarative HTML model and allow for the ability to declare a `partial` directive containing a template partial which can then be referenced by an `apply` directive.
123
-
124
- Example:
125
318
  ```html
126
- <f-partial id="test">
127
- <ul>
128
- <f-repeat value="{{item in items}}">
129
- <li>{{item.text}}<f-apply partial="test" value="{{item.items}}"></f-apply></li>
130
- </f-repeat>
131
- </ul>
132
- </f-partial>
133
- <f-apply partial="test" value="{{items}}"></f-apply>
319
+ <ul><f-repeat value="{{item in list}}"><li>{{item}} - {{title}}</li></f-repeat></ul>
134
320
  ```
135
321
 
322
+ #### Execution Context Access
323
+
324
+ In imperative fast-element templates, every binding expression receives both the data source and the execution context: `${(x, c) => c.parent.handleClick(c.event)}`. Declarative `<f-template>` expressions can access the same execution context using the `$c` prefix.
325
+
326
+ This is particularly useful inside `<f-repeat>`, where `$c.parent` refers to the parent view-model (typically the host element) and `$c.event` provides the DOM event.
327
+
328
+ Event handler with context access:
329
+
330
+ ```html
331
+ <f-repeat value="{{item in items}}">
332
+ <button @click="{$c.parent.handleItemClick($c.event)}">{{item.name}}</button>
333
+ </f-repeat>
334
+ ```
335
+
336
+ Conditional rendering using a host property inside a repeat:
337
+
338
+ ```html
339
+ <f-repeat value="{{item in items}}">
340
+ <f-when value="{{$c.parent.showNames}}">
341
+ <span>{{item.name}}</span>
342
+ </f-when>
343
+ </f-repeat>
344
+ ```
345
+
346
+ #### Unescaped HTML
347
+
348
+ You can add unescaped HTML using triple braces, this will create an additional `div` element as the HTML needs an element to bind to. Where possible it is advisable to not use unescaped HTML and instead use other binding techniques.
349
+
350
+ Example:
351
+ ```html
352
+ {{{html}}}
353
+ ```
354
+
136
355
  ### Writing Components
137
356
 
138
357
  When writing components with the intention of using the declarative HTML syntax, it is imperative that components are written with styling and rendering of the component to be less reliant on any JavaScript state management. An example of this is relying on `elementInterals` state to style a component.
139
358
 
359
+ ### Converting Components
360
+
361
+ FAST Components written using the `html` tag template literal can be partially converted via the supplied `.yml` rules made for use with [ast-grep](https://ast-grep.github.io/).
362
+
363
+ Example:
364
+
365
+ ```ts
366
+ // before
367
+ export const template = html`
368
+ <slot ${slotted("slottedNodes")}></slot>
369
+ `;
370
+ // after
371
+ export const template = `
372
+ <slot f-slotted="{slottedNodes}"></slot>
373
+ `;
374
+ ```
375
+
376
+ Which creates a starting point for converting the tag template literals to the declarative HTML syntax.
377
+
378
+ If your template includes JavaScript specific logic that does not conform to those rules, the fix may not be applied or may apply incorrectly. It is therefore suggested that complex logic instead leverages the custom elements JavaScript class.
379
+
380
+ #### Available Rules
381
+
382
+ - `@microsoft/fast-html/rules/attribute-directive.yml`
383
+ - `@microsoft/fast-html/rules/call-expression-with-event-argument.yml`
384
+ - `@microsoft/fast-html/rules/member-expression.yml`
385
+ - `@microsoft/fast-html/rules/tag-function-to-template-literal.yml`
386
+
140
387
  ## Acknowledgements
141
388
 
142
- This project has been heavily inspired by [Handlebars](https://handlebarsjs.com/) and [Vue.js](https://vuejs.org/).
389
+ This project has been heavily inspired by [Handlebars](https://handlebarsjs.com/) and [Vue.js](https://vuejs.org/).
@@ -0,0 +1,10 @@
1
+ import { type Constructable, type FASTElement } from "@microsoft/fast-element";
2
+ /**
3
+ * A mixin function that extends a base class with additional functionality for
4
+ * rendering and hydration.
5
+ *
6
+ * @param BaseCtor - The base class to extend.
7
+ * @returns A new class that extends the provided base class with additional functionality for rendering and hydration.
8
+ * @public
9
+ */
10
+ export declare function RenderableFASTElement<T extends Constructable<FASTElement>>(BaseCtor: T): T;
@@ -1 +1,3 @@
1
- export { TemplateElement } from "./template.js";
1
+ export { RenderableFASTElement } from "./element.js";
2
+ export { ObserverMap } from "./observer-map.js";
3
+ export { ObserverMapOption, TemplateElement, type ElementOptions, type ElementOptionsDictionary, type HydrationLifecycleCallbacks, } from "./template.js";
@@ -0,0 +1,27 @@
1
+ import type { Schema } from "./schema.js";
2
+ /**
3
+ * ObserverMap provides functionality for caching binding paths, extracting root properties,
4
+ * and defining observable properties on class prototypes
5
+ */
6
+ export declare class ObserverMap {
7
+ private schema;
8
+ private classPrototype;
9
+ constructor(classPrototype: any, schema: Schema);
10
+ defineProperties(): void;
11
+ /**
12
+ * Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
13
+ * @param target - The target instance that owns the root property
14
+ * @param rootProperty - The name of the root property for notification purposes
15
+ * @param object - The object to wrap with a proxy
16
+ * @returns A proxy that triggers notifications on property mutations
17
+ */
18
+ private getAndAssignObservables;
19
+ /**
20
+ * Creates a property change handler function for observable properties
21
+ * This handler is called when an observable property transitions from undefined to a defined value
22
+ * @param propertyName - The name of the property for which to create the change handler
23
+ * @param existingChangedMethod - Optional existing changed method to call after the instance resolver logic
24
+ * @returns A function that handles property changes and sets up proxies for object values
25
+ */
26
+ private defineChanged;
27
+ }
@@ -0,0 +1,144 @@
1
+ import type { ChildrenMap } from "./utilities.js";
2
+ type FastContextMetaData = "$fast_context";
3
+ type FastContextsMetaData = "$fast_parent_contexts";
4
+ export interface JSONSchemaDefinition extends JSONSchemaCommon {
5
+ $fast_context: string;
6
+ $fast_parent_contexts: Array<string>;
7
+ }
8
+ interface JSONSchemaCommon {
9
+ type?: string;
10
+ properties?: any;
11
+ items?: any;
12
+ anyOf?: Array<any>;
13
+ $ref?: string;
14
+ }
15
+ export interface JSONSchema extends JSONSchemaCommon {
16
+ $schema: string;
17
+ $id: string;
18
+ $defs?: Record<string, JSONSchemaDefinition>;
19
+ }
20
+ interface CachedPathCommon {
21
+ parentContext: string | null;
22
+ currentContext: string | null;
23
+ path: string;
24
+ }
25
+ type AccessCachedPathType = "access";
26
+ export interface AccessCachedPath extends CachedPathCommon {
27
+ type: AccessCachedPathType;
28
+ }
29
+ type DefaultCachedPathType = "default";
30
+ export interface DefaultCachedPath extends CachedPathCommon {
31
+ type: DefaultCachedPathType;
32
+ }
33
+ type EventCachedPathType = "event";
34
+ export interface EventCachedPath extends CachedPathCommon {
35
+ type: EventCachedPathType;
36
+ }
37
+ type RepeatCachedPathType = "repeat";
38
+ export interface RepeatCachedPath extends CachedPathCommon {
39
+ type: RepeatCachedPathType;
40
+ }
41
+ export type CachedPath = DefaultCachedPath | RepeatCachedPath | AccessCachedPath | EventCachedPath;
42
+ export type CachedPathMap = Map<string, Map<string, JSONSchema>>;
43
+ interface RegisterPathConfig {
44
+ rootPropertyName: string;
45
+ pathConfig: CachedPath;
46
+ childrenMap: ChildrenMap | null;
47
+ }
48
+ export declare const fastContextMetaData: FastContextMetaData;
49
+ export declare const fastContextsMetaData: FastContextsMetaData;
50
+ export declare const defsPropertyName = "$defs";
51
+ export declare const refPropertyName = "$ref";
52
+ /**
53
+ * A constructed JSON schema from a template
54
+ */
55
+ export declare class Schema {
56
+ /**
57
+ * The name of the custom element
58
+ */
59
+ private customElementName;
60
+ /**
61
+ * A JSON schema describing each root schema
62
+ */
63
+ static jsonSchemaMap: CachedPathMap;
64
+ constructor(name: string);
65
+ /**
66
+ * Add a path to a schema
67
+ * @param config RegisterPathConfig
68
+ */
69
+ addPath(config: RegisterPathConfig): void;
70
+ /**
71
+ * Gets the JSON schema for a property name
72
+ * @param rootPropertyName - the root property the JSON schema is mapped to
73
+ * @returns The JSON schema for the root property
74
+ */
75
+ getSchema(rootPropertyName: string): JSONSchema | null;
76
+ /**
77
+ * Gets root properties
78
+ * @returns IterableIterator<string>
79
+ */
80
+ getRootProperties(): IterableIterator<string>;
81
+ /**
82
+ * Get a path split into property names
83
+ * @param path The dot syntax path e.g. a.b.c
84
+ * @returns An array of items in the path
85
+ */
86
+ private getSplitPath;
87
+ /**
88
+ * Gets the path to the $def
89
+ * @param context The context name e.g. {{item in items}} in a repeat creates the "item" context
90
+ * @returns A string to use as a $ref
91
+ */
92
+ private getDefsPath;
93
+ /**
94
+ * Get the schema $id
95
+ * @param customElementName - The custom element name
96
+ * @param propertyName - The property name
97
+ * @returns The ID that can be used in the JSON schema as $id
98
+ */
99
+ private getSchemaId;
100
+ /**
101
+ * Add a new JSON schema to the JSON schema map
102
+ * @param propertyName The name of the property to assign this JSON schema to
103
+ */
104
+ private addNewSchema;
105
+ /**
106
+ * Add properties to a context
107
+ * @param schema The schema to add the properties to
108
+ * @param splitPath The path split into property/context names
109
+ * @param context The paths context
110
+ */
111
+ private addPropertiesToAContext;
112
+ /**
113
+ * Add properties to an object
114
+ * @param schema The schema to add the properties to
115
+ * @param splitPath The path split into property/context names
116
+ * @param context The paths context
117
+ * @param type The data type (see JSON schema for details)
118
+ */
119
+ private addPropertiesToAnObject;
120
+ /**
121
+ * Add an array to an object property
122
+ * @param schema The schema to add the properties to
123
+ * @param context The name of the context
124
+ */
125
+ private addArrayToAnObject;
126
+ /**
127
+ * Add a context to the $defs property
128
+ * @param schema The schema to use
129
+ * @param propertyName The name of the property the context belongs to
130
+ * @param currentContext The current context
131
+ * @param parentContext The parent context
132
+ * @returns
133
+ */
134
+ private addContext;
135
+ /**
136
+ * Get parent contexts
137
+ * @param schema The schema to use
138
+ * @param parentContext The parent context
139
+ * @param contexts A list of parent contexts
140
+ * @returns
141
+ */
142
+ private getParentContexts;
143
+ }
144
+ export {};
@@ -1,4 +1,41 @@
1
- import { FASTElement } from "@microsoft/fast-element";
1
+ import { FASTElement, HydrationControllerCallbacks, TemplateLifecycleCallbacks } from "@microsoft/fast-element";
2
+ import "@microsoft/fast-element/install-hydratable-view-templates.js";
3
+ /**
4
+ * Values for the observerMap element option.
5
+ */
6
+ export declare const ObserverMapOption: {
7
+ readonly all: "all";
8
+ };
9
+ /**
10
+ * Type for the observerMap element option.
11
+ */
12
+ export type ObserverMapOption = (typeof ObserverMapOption)[keyof typeof ObserverMapOption];
13
+ /**
14
+ * Element options the TemplateElement will use to update the registered element
15
+ */
16
+ export interface ElementOptions {
17
+ observerMap?: ObserverMapOption;
18
+ }
19
+ /**
20
+ * A dictionary of element options the TemplateElement will use to update the registered element
21
+ */
22
+ export interface ElementOptionsDictionary<ElementOptionsType = ElementOptions> {
23
+ [key: string]: ElementOptionsType;
24
+ }
25
+ /**
26
+ * Lifecycle callbacks for template and hydration events.
27
+ * Combines template lifecycle callbacks with hydration callbacks and adds template-processing events.
28
+ */
29
+ export interface HydrationLifecycleCallbacks extends HydrationControllerCallbacks, TemplateLifecycleCallbacks {
30
+ /**
31
+ * Called after the JS class definition has been registered
32
+ */
33
+ elementDidRegister?(name: string): void;
34
+ /**
35
+ * Called before the template has been evaluated and assigned
36
+ */
37
+ templateWillUpdate?(name: string): void;
38
+ }
2
39
  /**
3
40
  * The <f-template> custom element that will provide view logic to the element
4
41
  */
@@ -7,12 +44,52 @@ declare class TemplateElement extends FASTElement {
7
44
  * The name of the custom element this template will be applied to
8
45
  */
9
46
  name?: string;
10
- private partials;
47
+ /**
48
+ * A dictionary of custom element options
49
+ */
50
+ static elementOptions: ElementOptionsDictionary;
51
+ /**
52
+ * ObserverMap instance for caching binding paths
53
+ */
54
+ private observerMap?;
55
+ /**
56
+ * Default element options
57
+ */
58
+ private static defaultElementOptions;
59
+ /**
60
+ * Metadata containing JSON schema for properties on a custom eleemnt
61
+ */
62
+ private schema?;
63
+ /**
64
+ * Lifecycle callbacks for hydration events
65
+ */
66
+ private static lifecycleCallbacks;
67
+ /**
68
+ * Configure lifecycle callbacks for hydration events.
69
+ *
70
+ * @param callbacks - Lifecycle callbacks to configure.
71
+ * @returns The {@link TemplateElement} class.
72
+ */
73
+ static config(callbacks: HydrationLifecycleCallbacks): typeof TemplateElement;
74
+ /**
75
+ * Set options for custom elements.
76
+ *
77
+ * @param elementOptions - A dictionary of custom element options
78
+ * @returns The TemplateElement class.
79
+ */
80
+ static options(elementOptions?: ElementOptionsDictionary): typeof TemplateElement;
81
+ constructor();
82
+ /**
83
+ * Set options for a custom element
84
+ * @param name - The name of the custom element to set options for.
85
+ */
86
+ private static setOptions;
11
87
  connectedCallback(): void;
12
88
  /**
13
89
  * Resolve strings and values from an innerHTML string
14
90
  * @param innerHTML - The innerHTML.
15
91
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
92
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
16
93
  */
17
94
  private resolveStringsAndValues;
18
95
  /**
@@ -26,6 +103,8 @@ declare class TemplateElement extends FASTElement {
26
103
  * @param behaviorConfig - The directive behavior configuration object.
27
104
  * @param externalValues - The interpreted values from the parent.
28
105
  * @param innerHTML - The innerHTML.
106
+ * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
107
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
29
108
  */
30
109
  private resolveTemplateDirective;
31
110
  /**
@@ -42,6 +121,7 @@ declare class TemplateElement extends FASTElement {
42
121
  * @param values - The interpreted values.
43
122
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
44
123
  * @param behaviorConfig - The binding behavior configuration object.
124
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
45
125
  */
46
126
  private resolveDataBinding;
47
127
  /**
@@ -50,12 +130,8 @@ declare class TemplateElement extends FASTElement {
50
130
  * @param strings - The strings array.
51
131
  * @param values - The interpreted values.
52
132
  * @param self - Indicates that this should refer to itself instead of a property when creating bindings.
133
+ * @param observerMap - ObserverMap instance for caching binding paths (optional).
53
134
  */
54
135
  private resolveInnerHTML;
55
- /**
56
- * Resolve all partial templates
57
- * @param unresolvedInnerHTML - The innerHTML.
58
- */
59
- private resolveAllPartials;
60
136
  }
61
137
  export { TemplateElement };