@microsoft/fast-element 3.0.0-rc.1 → 3.0.0-rc.2
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.
- package/CHANGELOG.md +51 -1
- package/README.md +50 -14
- package/dist/context/context.api.json +13 -13
- package/dist/declarative/declarative.api.json +654 -15
- package/dist/di/di.api.json +15 -15
- package/dist/dts/__test__/helpers.d.ts +6 -0
- package/dist/dts/__test__/setup-node.d.ts +0 -0
- package/dist/dts/binding/binding.d.ts +15 -5
- package/dist/dts/binding/one-time.d.ts +1 -1
- package/dist/dts/binding/one-way.d.ts +1 -1
- package/dist/dts/binding/signal.d.ts +1 -1
- package/dist/dts/binding/two-way.d.ts +1 -1
- package/dist/dts/components/attributes.d.ts +1 -1
- package/dist/dts/components/enable-hydration.d.ts +22 -2
- package/dist/dts/components/fast-definitions.d.ts +7 -4
- package/dist/dts/components/fast-element.d.ts +42 -12
- package/dist/dts/components/hydration-tracker.d.ts +47 -4
- package/dist/dts/components/hydration.d.ts +5 -0
- package/dist/dts/context.d.ts +7 -7
- package/dist/dts/declarative/debug.d.ts +2 -3
- package/dist/dts/declarative/index.d.ts +3 -2
- package/dist/dts/declarative/interfaces.d.ts +1 -2
- package/dist/dts/declarative/template.d.ts +2 -1
- package/dist/dts/declarative/utilities.d.ts +50 -4
- package/dist/dts/di/di.d.ts +6 -6
- package/dist/dts/dom-policy.d.ts +22 -4
- package/dist/dts/dom.d.ts +4 -16
- package/dist/dts/hydration/diagnostics.d.ts +93 -0
- package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
- package/dist/dts/hydration/messages.d.ts +62 -0
- package/dist/dts/hydration/target-builder.d.ts +26 -1
- package/dist/dts/hydration.d.ts +7 -3
- package/dist/dts/index.d.ts +7 -3
- package/dist/dts/interfaces.d.ts +1 -0
- package/dist/dts/observation/observable.d.ts +3 -3
- package/dist/dts/platform.d.ts +20 -4
- package/dist/dts/registry.d.ts +1 -0
- package/dist/dts/templating/children.d.ts +1 -1
- package/dist/dts/templating/compiler.d.ts +1 -1
- package/dist/dts/templating/html-binding-directive.d.ts +6 -2
- package/dist/dts/templating/html-directive.d.ts +2 -1
- package/dist/dts/templating/hydration-view.d.ts +24 -3
- package/dist/dts/templating/ref.d.ts +1 -1
- package/dist/dts/templating/render.d.ts +2 -2
- package/dist/dts/templating/repeat.d.ts +1 -1
- package/dist/dts/templating/slotted.d.ts +1 -1
- package/dist/dts/templating/template.d.ts +5 -5
- package/dist/dts/templating/when.d.ts +1 -1
- package/dist/dts/testing/fakes.d.ts +4 -4
- package/dist/esm/__test__/helpers.js +22 -0
- package/dist/esm/__test__/setup-node.js +18 -0
- package/dist/esm/binding/two-way.js +1 -2
- package/dist/esm/components/attributes.js +12 -8
- package/dist/esm/components/element-controller.js +11 -6
- package/dist/esm/components/enable-hydration.js +27 -3
- package/dist/esm/components/fast-definitions.js +19 -18
- package/dist/esm/components/hydration-tracker.js +34 -5
- package/dist/esm/components/hydration.js +85 -6
- package/dist/esm/debug.js +1 -0
- package/dist/esm/declarative/attribute-map.js +2 -1
- package/dist/esm/declarative/debug.js +0 -1
- package/dist/esm/declarative/index.js +1 -0
- package/dist/esm/declarative/interfaces.js +0 -1
- package/dist/esm/declarative/observer-map-utilities.js +58 -55
- package/dist/esm/declarative/template-bridge.js +4 -14
- package/dist/esm/declarative/template.js +4 -3
- package/dist/esm/declarative/utilities.js +236 -1
- package/dist/esm/di/di.js +2 -1
- package/dist/esm/dom-policy.js +33 -4
- package/dist/esm/hydration/diagnostics.js +50 -0
- package/dist/esm/hydration/hydration-debugger.js +112 -0
- package/dist/esm/hydration/messages.js +84 -0
- package/dist/esm/hydration/target-builder.js +65 -19
- package/dist/esm/hydration.js +3 -1
- package/dist/esm/index.js +6 -2
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/metadata.js +2 -8
- package/dist/esm/observation/notifier.js +2 -4
- package/dist/esm/registry.js +1 -0
- package/dist/esm/templating/html-binding-directive.js +1 -1
- package/dist/esm/templating/hydration-view.js +20 -27
- package/dist/esm/templating/render.js +39 -18
- package/dist/esm/templating/repeat.js +51 -17
- package/dist/esm/templating/view.js +1 -1
- package/dist/esm/testing/fixture.js +2 -2
- package/dist/esm/testing/timeout.js +2 -2
- package/dist/fast-element.api.json +1329 -99
- package/dist/fast-element.d.ts +147 -66
- package/dist/fast-element.debug.js +392 -99
- package/dist/fast-element.debug.min.js +2 -2
- package/dist/fast-element.js +392 -99
- package/dist/fast-element.min.js +2 -2
- package/dist/fast-element.untrimmed.d.ts +133 -70
- package/dist/hydration/hydration.api.json +1280 -57
- package/dist/styles/styles.api.json +1 -1
- package/package.json +21 -9
- package/ARCHITECTURE_FASTELEMENT.md +0 -63
- package/ARCHITECTURE_HTML_TAGGED_TEMPLATE_LITERAL.md +0 -36
- package/ARCHITECTURE_INTRO.md +0 -10
- package/ARCHITECTURE_OVERVIEW.md +0 -52
- package/ARCHITECTURE_UPDATES.md +0 -11
- package/CHANGELOG.json +0 -2275
- package/DECLARATIVE_DESIGN.md +0 -806
- package/DECLARATIVE_HTML.md +0 -470
- package/DECLARATIVE_MIGRATION.md +0 -215
- package/DECLARATIVE_RENDERING.md +0 -530
- package/DECLARATIVE_RENDERING_LIFECYCLE.md +0 -288
- package/DECLARATIVE_SCHEMA_OBSERVER_MAP.md +0 -489
- package/DESIGN.md +0 -615
- package/MIGRATION.md +0 -387
- package/SIZES.md +0 -25
- package/api-extractor.arrays.json +0 -15
- package/api-extractor.context.json +0 -15
- package/api-extractor.declarative.json +0 -15
- package/api-extractor.di.json +0 -15
- package/api-extractor.hydration.json +0 -15
- package/api-extractor.styles.json +0 -15
- package/biome.json +0 -4
- package/docs/ACKNOWLEDGEMENTS.md +0 -12
- package/docs/api-report.api.md +0 -1299
- package/docs/arrays/api-report.api.md +0 -114
- package/docs/context/api-report.api.md +0 -69
- package/docs/declarative/api-report.api.md +0 -397
- package/docs/di/api-report.api.md +0 -315
- package/docs/fast-element-2-changes.md +0 -15
- package/docs/hydration/api-report.api.md +0 -285
- package/docs/styles/api-report.api.md +0 -135
- package/playwright.config.ts +0 -26
- package/playwright.declarative.config.ts +0 -26
- package/playwright.declarative.webui.config.ts +0 -20
- package/scripts/declarative/build-fixtures-with-webui.js +0 -135
- package/scripts/declarative/build-fixtures.js +0 -49
- package/scripts/declarative/build-fixtures.utilities.js +0 -101
- package/scripts/measure-sizes.js +0 -219
- package/scripts/run-api-extractor.js +0 -70
- package/test/declarative/fixtures/README.md +0 -72
- package/test/declarative/fixtures/WRITING_FIXTURES.md +0 -330
- package/test/declarative/fixtures/bindings/README.md +0 -12
- package/test/declarative/fixtures/bindings/attribute/entry.html +0 -13
- package/test/declarative/fixtures/bindings/attribute/fast-build.config.json +0 -6
- package/test/declarative/fixtures/bindings/attribute/index.html +0 -25
- package/test/declarative/fixtures/bindings/attribute/main.ts +0 -41
- package/test/declarative/fixtures/bindings/attribute/state.json +0 -8
- package/test/declarative/fixtures/bindings/attribute/templates.html +0 -11
- package/test/declarative/fixtures/bindings/content/entry.html +0 -12
- package/test/declarative/fixtures/bindings/content/fast-build.config.json +0 -6
- package/test/declarative/fixtures/bindings/content/index.html +0 -19
- package/test/declarative/fixtures/bindings/content/main.ts +0 -27
- package/test/declarative/fixtures/bindings/content/state.json +0 -4
- package/test/declarative/fixtures/bindings/content/templates.html +0 -6
- package/test/declarative/fixtures/bindings/dot-syntax/entry.html +0 -11
- package/test/declarative/fixtures/bindings/dot-syntax/fast-build.config.json +0 -6
- package/test/declarative/fixtures/bindings/dot-syntax/index.html +0 -47
- package/test/declarative/fixtures/bindings/dot-syntax/main.ts +0 -59
- package/test/declarative/fixtures/bindings/dot-syntax/state.json +0 -16
- package/test/declarative/fixtures/bindings/dot-syntax/templates.html +0 -17
- package/test/declarative/fixtures/bindings/event/entry.html +0 -11
- package/test/declarative/fixtures/bindings/event/fast-build.config.json +0 -6
- package/test/declarative/fixtures/bindings/event/index.html +0 -43
- package/test/declarative/fixtures/bindings/event/main.ts +0 -43
- package/test/declarative/fixtures/bindings/event/state.json +0 -3
- package/test/declarative/fixtures/bindings/event/templates.html +0 -18
- package/test/declarative/fixtures/bindings/host/entry.html +0 -40
- package/test/declarative/fixtures/bindings/host/fast-build.config.json +0 -6
- package/test/declarative/fixtures/bindings/host/index.html +0 -96
- package/test/declarative/fixtures/bindings/host/main.ts +0 -222
- package/test/declarative/fixtures/bindings/host/state.json +0 -9
- package/test/declarative/fixtures/bindings/host/templates.html +0 -55
- package/test/declarative/fixtures/directives/README.md +0 -12
- package/test/declarative/fixtures/directives/children/entry.html +0 -11
- package/test/declarative/fixtures/directives/children/fast-build.config.json +0 -6
- package/test/declarative/fixtures/directives/children/index.html +0 -15
- package/test/declarative/fixtures/directives/children/main.ts +0 -22
- package/test/declarative/fixtures/directives/children/state.json +0 -3
- package/test/declarative/fixtures/directives/children/templates.html +0 -3
- package/test/declarative/fixtures/directives/ref/entry.html +0 -11
- package/test/declarative/fixtures/directives/ref/fast-build.config.json +0 -6
- package/test/declarative/fixtures/directives/ref/index.html +0 -15
- package/test/declarative/fixtures/directives/ref/main.ts +0 -17
- package/test/declarative/fixtures/directives/ref/state.json +0 -1
- package/test/declarative/fixtures/directives/ref/templates.html +0 -3
- package/test/declarative/fixtures/directives/repeat/entry.html +0 -21
- package/test/declarative/fixtures/directives/repeat/fast-build.config.json +0 -6
- package/test/declarative/fixtures/directives/repeat/index.html +0 -133
- package/test/declarative/fixtures/directives/repeat/main.ts +0 -110
- package/test/declarative/fixtures/directives/repeat/sprites.svg +0 -8
- package/test/declarative/fixtures/directives/repeat/state.json +0 -10
- package/test/declarative/fixtures/directives/repeat/templates.html +0 -75
- package/test/declarative/fixtures/directives/slotted/entry.html +0 -17
- package/test/declarative/fixtures/directives/slotted/fast-build.config.json +0 -6
- package/test/declarative/fixtures/directives/slotted/index.html +0 -27
- package/test/declarative/fixtures/directives/slotted/main.ts +0 -29
- package/test/declarative/fixtures/directives/slotted/state.json +0 -1
- package/test/declarative/fixtures/directives/slotted/templates.html +0 -7
- package/test/declarative/fixtures/directives/when/entry.html +0 -51
- package/test/declarative/fixtures/directives/when/fast-build.config.json +0 -6
- package/test/declarative/fixtures/directives/when/index.html +0 -136
- package/test/declarative/fixtures/directives/when/main.ts +0 -172
- package/test/declarative/fixtures/directives/when/state.json +0 -12
- package/test/declarative/fixtures/directives/when/templates.html +0 -75
- package/test/declarative/fixtures/ecosystem/README.md +0 -11
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/entry.html +0 -12
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/fast-build.config.json +0 -6
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/index.html +0 -20
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/main.ts +0 -68
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/state.json +0 -4
- package/test/declarative/fixtures/ecosystem/declarative-no-hydration/templates.html +0 -7
- package/test/declarative/fixtures/ecosystem/errors/entry.html +0 -12
- package/test/declarative/fixtures/ecosystem/errors/fast-build.config.json +0 -6
- package/test/declarative/fixtures/ecosystem/errors/index.html +0 -20
- package/test/declarative/fixtures/ecosystem/errors/main.ts +0 -17
- package/test/declarative/fixtures/ecosystem/errors/state.json +0 -1
- package/test/declarative/fixtures/ecosystem/errors/templates.html +0 -7
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/entry.html +0 -17
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/fast-build.config.json +0 -6
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/index.html +0 -56
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/main.ts +0 -134
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/state.json +0 -12
- package/test/declarative/fixtures/ecosystem/lifecycle-callbacks/templates.html +0 -34
- package/test/declarative/fixtures/ecosystem/performance-metrics/entry.html +0 -25
- package/test/declarative/fixtures/ecosystem/performance-metrics/fast-build.config.json +0 -6
- package/test/declarative/fixtures/ecosystem/performance-metrics/fast-card.css +0 -10
- package/test/declarative/fixtures/ecosystem/performance-metrics/index.html +0 -181
- package/test/declarative/fixtures/ecosystem/performance-metrics/main.ts +0 -58
- package/test/declarative/fixtures/ecosystem/performance-metrics/state.json +0 -6
- package/test/declarative/fixtures/ecosystem/performance-metrics/templates.html +0 -15
- package/test/declarative/fixtures/extensions/README.md +0 -15
- package/test/declarative/fixtures/extensions/attribute-map/entry.html +0 -14
- package/test/declarative/fixtures/extensions/attribute-map/fast-build.config.json +0 -6
- package/test/declarative/fixtures/extensions/attribute-map/index.html +0 -31
- package/test/declarative/fixtures/extensions/attribute-map/main.ts +0 -40
- package/test/declarative/fixtures/extensions/attribute-map/state.json +0 -4
- package/test/declarative/fixtures/extensions/attribute-map/templates.html +0 -14
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/entry.html +0 -12
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/fast-build.config.json +0 -7
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/index.html +0 -25
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/main.ts +0 -31
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/state.json +0 -5
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy/templates.html +0 -11
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/entry.html +0 -13
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/fast-build.config.json +0 -7
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/index.html +0 -23
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/main.ts +0 -37
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/state.json +0 -1
- package/test/declarative/fixtures/extensions/attribute-map-naming-strategy-camel-case/templates.html +0 -9
- package/test/declarative/fixtures/extensions/observer-map/entry.html +0 -15
- package/test/declarative/fixtures/extensions/observer-map/fast-build.config.json +0 -6
- package/test/declarative/fixtures/extensions/observer-map/index.html +0 -442
- package/test/declarative/fixtures/extensions/observer-map/main.ts +0 -482
- package/test/declarative/fixtures/extensions/observer-map/state.json +0 -158
- package/test/declarative/fixtures/extensions/observer-map/templates.html +0 -172
- package/test/declarative/fixtures/extensions/observer-map-config-object/entry.html +0 -16
- package/test/declarative/fixtures/extensions/observer-map-config-object/fast-build.config.json +0 -6
- package/test/declarative/fixtures/extensions/observer-map-config-object/index.html +0 -27
- package/test/declarative/fixtures/extensions/observer-map-config-object/main.ts +0 -53
- package/test/declarative/fixtures/extensions/observer-map-config-object/state.json +0 -9
- package/test/declarative/fixtures/extensions/observer-map-config-object/templates.html +0 -12
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/README.md +0 -98
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/entry.html +0 -156
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/fast-build.config.json +0 -6
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/index.html +0 -376
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/main.ts +0 -366
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/state.json +0 -69
- package/test/declarative/fixtures/extensions/observer-map-deep-merge/templates.html +0 -91
- package/test/declarative/fixtures/extensions/observer-map-properties/entry.html +0 -14
- package/test/declarative/fixtures/extensions/observer-map-properties/fast-build.config.json +0 -6
- package/test/declarative/fixtures/extensions/observer-map-properties/index.html +0 -110
- package/test/declarative/fixtures/extensions/observer-map-properties/main.ts +0 -175
- package/test/declarative/fixtures/extensions/observer-map-properties/state.json +0 -29
- package/test/declarative/fixtures/extensions/observer-map-properties/templates.html +0 -55
- package/test/declarative/fixtures/scenarios/README.md +0 -7
- package/test/declarative/fixtures/scenarios/nested-elements/entry.html +0 -16
- package/test/declarative/fixtures/scenarios/nested-elements/fast-build.config.json +0 -6
- package/test/declarative/fixtures/scenarios/nested-elements/index.html +0 -126
- package/test/declarative/fixtures/scenarios/nested-elements/main.ts +0 -214
- package/test/declarative/fixtures/scenarios/nested-elements/state.json +0 -10
- package/test/declarative/fixtures/scenarios/nested-elements/templates.html +0 -54
- package/test/declarative/index.html +0 -12
- package/test/declarative/vite.config.ts +0 -55
- package/test/declarative-main.ts +0 -6
- package/test/extension-subpaths-main.ts +0 -9
- package/test/index.html +0 -11
- package/test/main.ts +0 -109
- package/test/pure-declarative-main.ts +0 -1
- package/test/vite.config.ts +0 -19
- package/tsconfig.api-extractor.json +0 -6
package/DECLARATIVE_HTML.md
DELETED
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
# FAST Element Declarative HTML
|
|
2
|
-
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://badge.fury.io/js/%40microsoft%2Ffast-element)
|
|
5
|
-
|
|
6
|
-
The declarative entrypoint in `@microsoft/fast-element` interprets FAST
|
|
7
|
-
declarative HTML syntax as a template for a FAST web component.
|
|
8
|
-
|
|
9
|
-
This document focuses on declarative-runtime implementation details:
|
|
10
|
-
template structure, prerendered markup requirements, lifecycle callbacks,
|
|
11
|
-
binding configuration, syntax, and integration testing.
|
|
12
|
-
|
|
13
|
-
For package installation, using `declarativeTemplate()`, extension setup, and
|
|
14
|
-
the package-level hydration overview, see the
|
|
15
|
-
[FAST Element README](./README.md#declarative-html) and
|
|
16
|
-
[Prerendered Content Optimization](./README.md#prerendered-content-optimization).
|
|
17
|
-
For user-facing guides covering f-template syntax, element definition, and
|
|
18
|
-
server-side rendering, see the
|
|
19
|
-
[Declarative HTML docs](https://fast.design/docs/3.x/declarative-templates/overview/).
|
|
20
|
-
|
|
21
|
-
## Template Structure
|
|
22
|
-
|
|
23
|
-
After importing the declarative APIs as shown in the README, templates are
|
|
24
|
-
associated with an element through
|
|
25
|
-
`<f-template name="[custom-element-name]"><template>...</template></f-template>`.
|
|
26
|
-
The host custom element should be defined with
|
|
27
|
-
`template: declarativeTemplate()`. This automatically defines `<f-template>` in
|
|
28
|
-
the relevant registry and waits for the matching declarative template when it is
|
|
29
|
-
already present or inserted later.
|
|
30
|
-
|
|
31
|
-
The `@microsoft/fast-element` entrypoint itself remains
|
|
32
|
-
side-effect free at import time. Declarative APIs lazily install declarative
|
|
33
|
-
debug messages when they create templates. Hydratable `ViewTemplate` support is
|
|
34
|
-
installed only when `enableHydration()` is called from
|
|
35
|
-
`@microsoft/fast-element`.
|
|
36
|
-
|
|
37
|
-
`observerMap()` and `attributeMap()` are available from
|
|
38
|
-
`@microsoft/fast-element`, including when using the maps without declarative
|
|
39
|
-
templates.
|
|
40
|
-
|
|
41
|
-
Example:
|
|
42
|
-
```html
|
|
43
|
-
<my-custom-element greeting="Hello world">
|
|
44
|
-
<template shadowrootmode="open">
|
|
45
|
-
Hello world
|
|
46
|
-
</template>
|
|
47
|
-
</my-custom-element>
|
|
48
|
-
<f-template name="my-custom-element">
|
|
49
|
-
<template>{{greeting}}</template>
|
|
50
|
-
</f-template>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
The legacy `defer-hydration` and `needs-hydration` attributes are no longer
|
|
54
|
-
required.
|
|
55
|
-
|
|
56
|
-
## Non-browser HTML Rendering
|
|
57
|
-
|
|
58
|
-
One of the benefits of FAST declarative HTML templates is that the server can
|
|
59
|
-
be stack agnostic because JavaScript does not need to be interpreted to emit
|
|
60
|
-
the initial HTML. The declarative runtime expects hydratable comment markers
|
|
61
|
-
and datasets when prerendered content is generated. For the required marker
|
|
62
|
-
format and initial-state application details, see
|
|
63
|
-
[DECLARATIVE_RENDERING.md](./DECLARATIVE_RENDERING.md).
|
|
64
|
-
|
|
65
|
-
## Lifecycle Callbacks
|
|
66
|
-
|
|
67
|
-
FAST Element's declarative APIs provide lifecycle callbacks that allow you to
|
|
68
|
-
hook into template processing and hydration. The callbacks are split by scope:
|
|
69
|
-
|
|
70
|
-
| Scope | API | Callbacks |
|
|
71
|
-
|---|---|---|
|
|
72
|
-
| Per element | `declarativeTemplate(callbacks)` | `elementDidRegister`, `templateWillUpdate`, `templateDidUpdate`, `elementDidDefine`, `elementWillHydrate`, `elementDidHydrate` |
|
|
73
|
-
| Global hydration | `enableHydration(options)` | `hydrationStarted`, `hydrationComplete` |
|
|
74
|
-
|
|
75
|
-
Hydration is opt-in. Call `enableHydration()` before FAST elements connect when
|
|
76
|
-
you want prerendered Declarative Shadow DOM to be reused:
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import { enableHydration } from "@microsoft/fast-element/hydration.js";
|
|
80
|
-
|
|
81
|
-
enableHydration({
|
|
82
|
-
hydrationStarted() {
|
|
83
|
-
console.log("Hydration started");
|
|
84
|
-
},
|
|
85
|
-
hydrationComplete() {
|
|
86
|
-
console.log("All elements hydrated");
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Pass per-element lifecycle callbacks directly to `declarativeTemplate()`:
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import { declarativeTemplate } from "@microsoft/fast-element/declarative.js";
|
|
95
|
-
|
|
96
|
-
MyComponent.define({
|
|
97
|
-
name: "my-component",
|
|
98
|
-
template: declarativeTemplate({
|
|
99
|
-
elementDidRegister(name) {
|
|
100
|
-
console.log(`Element registered: ${name}`);
|
|
101
|
-
},
|
|
102
|
-
templateWillUpdate(name) {
|
|
103
|
-
console.log(`Template updating: ${name}`);
|
|
104
|
-
},
|
|
105
|
-
templateDidUpdate(name) {
|
|
106
|
-
console.log(`Template updated: ${name}`);
|
|
107
|
-
},
|
|
108
|
-
elementDidDefine(name) {
|
|
109
|
-
console.log(`Element defined: ${name}`);
|
|
110
|
-
},
|
|
111
|
-
elementWillHydrate(source) {
|
|
112
|
-
console.log(`Element will hydrate: ${source.localName}`);
|
|
113
|
-
},
|
|
114
|
-
elementDidHydrate(source) {
|
|
115
|
-
console.log(`Element hydrated: ${source.localName}`);
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
The lifecycle callbacks occur in this general sequence:
|
|
122
|
-
|
|
123
|
-
1. `elementDidRegister(name)`
|
|
124
|
-
2. `templateWillUpdate(name)` → template processing → `templateDidUpdate(name)`
|
|
125
|
-
3. `elementDidDefine(name)`
|
|
126
|
-
4. If `enableHydration()` was called and the element has prerendered content:
|
|
127
|
-
`hydrationStarted()` → `elementWillHydrate(source)` → hydration →
|
|
128
|
-
`elementDidHydrate(source)` → `hydrationComplete()`
|
|
129
|
-
|
|
130
|
-
Template processing is asynchronous and happens independently for each element,
|
|
131
|
-
so callbacks for different elements may interleave.
|
|
132
|
-
|
|
133
|
-
## `observerMap`
|
|
134
|
-
|
|
135
|
-
When the `observerMap()` extension is applied to an element definition,
|
|
136
|
-
it automatically sets up deep reactive observation for root properties
|
|
137
|
-
discovered in the template. Declarative templates assign `definition.schema`
|
|
138
|
-
during template resolution, so `observerMap()` has schema data automatically.
|
|
139
|
-
For non-declarative/manual schemas, import from `@microsoft/fast-element` and
|
|
140
|
-
pass `observerMap({ schema })`.
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
import { observerMap } from "@microsoft/fast-element/observer-map.js";
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
For finer control, pass a configuration object with a `properties` key that maps root property names to a recursive path tree:
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
UserProfile.define(
|
|
150
|
-
{
|
|
151
|
-
name: "user-profile",
|
|
152
|
-
template: declarativeTemplate(),
|
|
153
|
-
},
|
|
154
|
-
[
|
|
155
|
-
observerMap({
|
|
156
|
-
properties: {
|
|
157
|
-
user: {
|
|
158
|
-
name: true, // user.name — observed
|
|
159
|
-
details: {
|
|
160
|
-
age: true, // user.details.age — observed
|
|
161
|
-
history: false, // user.details.history — NOT observed
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
// root properties not listed here are skipped
|
|
165
|
-
},
|
|
166
|
-
}),
|
|
167
|
-
],
|
|
168
|
-
);
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Each path entry can be:
|
|
172
|
-
- **`true`** — observe this path and all descendants.
|
|
173
|
-
- **`false`** — skip this path and all descendants.
|
|
174
|
-
- **An object** with an optional `$observe` boolean and child property overrides.
|
|
175
|
-
|
|
176
|
-
Use `$observe: false` on a node to skip it by default, then re-include specific children:
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
observerMap({
|
|
180
|
-
properties: {
|
|
181
|
-
analytics: {
|
|
182
|
-
charts: {
|
|
183
|
-
$observe: false, // charts NOT observed by default
|
|
184
|
-
activeChart: true, // ...except activeChart IS observed
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
When `properties` is omitted, all root properties are observed. When
|
|
192
|
-
`properties` is present but empty (`{ properties: {} }`), no root properties
|
|
193
|
-
are observed.
|
|
194
|
-
|
|
195
|
-
Manual schema example:
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { FASTElement, Schema } from "@microsoft/fast-element";
|
|
199
|
-
import { observerMap } from "@microsoft/fast-element/observer-map.js";
|
|
200
|
-
|
|
201
|
-
class MyElement extends FASTElement {}
|
|
202
|
-
|
|
203
|
-
const schema = new Schema("my-element");
|
|
204
|
-
schema.addPath({
|
|
205
|
-
rootPropertyName: "user",
|
|
206
|
-
pathConfig: {
|
|
207
|
-
type: "default",
|
|
208
|
-
parentContext: null,
|
|
209
|
-
currentContext: null,
|
|
210
|
-
path: "user.name",
|
|
211
|
-
},
|
|
212
|
-
childrenMap: null,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
MyElement.define({ name: "my-element" }, [observerMap({ schema })]);
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## `attributeMap`
|
|
219
|
-
|
|
220
|
-
When the `attributeMap()` extension is applied to an element definition,
|
|
221
|
-
it automatically creates reactive `@attr` properties for every **leaf binding**
|
|
222
|
-
in the template — simple expressions like `{{foo}}` or `id="{{fooBar}}"` that
|
|
223
|
-
have no nested properties. Declarative templates provide the schema
|
|
224
|
-
automatically. For non-declarative/manual schemas, place the optional `schema`
|
|
225
|
-
on the FAST element definition and import `attributeMap()` from
|
|
226
|
-
`@microsoft/fast-element`.
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
import { attributeMap } from "@microsoft/fast-element/attribute-map.js";
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
By default, the binding key is treated as a camelCase property name and the HTML
|
|
233
|
-
attribute name is derived by converting it to kebab-case. Properties already
|
|
234
|
-
decorated with `@attr` or `@observable` on the class are left untouched.
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
MyElement.define(
|
|
238
|
-
{
|
|
239
|
-
name: "my-element",
|
|
240
|
-
template: declarativeTemplate(),
|
|
241
|
-
},
|
|
242
|
-
[attributeMap()],
|
|
243
|
-
);
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
With the template:
|
|
247
|
-
|
|
248
|
-
```html
|
|
249
|
-
<f-template name="my-element">
|
|
250
|
-
<template>
|
|
251
|
-
<p>{{greeting}}</p>
|
|
252
|
-
<p>{{firstName}}</p>
|
|
253
|
-
</template>
|
|
254
|
-
</f-template>
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
This registers `greeting` (attribute `greeting`, property `greeting`) and
|
|
258
|
-
`firstName` (attribute `first-name`, property `firstName`) as `@attr`
|
|
259
|
-
properties on the element prototype, enabling `setAttribute("first-name",
|
|
260
|
-
"Jane")` to trigger a template re-render automatically.
|
|
261
|
-
|
|
262
|
-
### `attribute-name-strategy`
|
|
263
|
-
|
|
264
|
-
The `attribute-name-strategy` configuration option controls how template binding
|
|
265
|
-
keys map to HTML attribute names. This matches the build-time
|
|
266
|
-
`--attribute-name-strategy` option in `@microsoft/fast-build`.
|
|
267
|
-
|
|
268
|
-
| Strategy | Behaviour | Example |
|
|
269
|
-
|---|---|---|
|
|
270
|
-
| `"camelCase"` (default) | Binding key is the camelCase property; attribute name is derived as kebab-case | `{{fooBar}}` → property `fooBar`, attribute `foo-bar` |
|
|
271
|
-
| `"none"` | Binding key used as-is for both property and attribute | `{{foo-bar}}` → property `foo-bar`, attribute `foo-bar` |
|
|
272
|
-
|
|
273
|
-
```typescript
|
|
274
|
-
MyElement.define(
|
|
275
|
-
{
|
|
276
|
-
name: "my-element",
|
|
277
|
-
template: declarativeTemplate(),
|
|
278
|
-
},
|
|
279
|
-
[
|
|
280
|
-
attributeMap({
|
|
281
|
-
"attribute-name-strategy": "none",
|
|
282
|
-
}),
|
|
283
|
-
],
|
|
284
|
-
);
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
When using the `"none"` strategy, property names may contain dashes and must be
|
|
288
|
-
accessed via bracket notation (e.g. `element["foo-bar"]`).
|
|
289
|
-
|
|
290
|
-
## Syntax
|
|
291
|
-
|
|
292
|
-
All bindings use a handlebars-like syntax.
|
|
293
|
-
|
|
294
|
-
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.
|
|
295
|
-
|
|
296
|
-
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.
|
|
297
|
-
|
|
298
|
-
Browser-only bindings:
|
|
299
|
-
- Event bindings
|
|
300
|
-
- Attribute directives
|
|
301
|
-
|
|
302
|
-
### Content binding
|
|
303
|
-
|
|
304
|
-
```html
|
|
305
|
-
{{text}}
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
### Event binding
|
|
309
|
-
|
|
310
|
-
Event bindings must include the `()` as well as being preceeded by `@` in keeping with the `@microsoft/fast-element` tagged template syntax.
|
|
311
|
-
|
|
312
|
-
```html
|
|
313
|
-
<button @click="{handleClick()}"></button>
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
You can pass the DOM event object, the execution context, or both as arguments. Any other argument is treated as a binding expression and resolved against the current data source.
|
|
317
|
-
|
|
318
|
-
**`$e` — DOM event object (preferred):**
|
|
319
|
-
```html
|
|
320
|
-
<button @click="{handleClick($e)}"></button>
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
**`$c` — execution context:**
|
|
324
|
-
```html
|
|
325
|
-
<button @click="{handleClick($c)}"></button>
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
**`$c.somePath` — a property of the execution context (e.g. `$c.parent`, `$c.event`):**
|
|
329
|
-
```html
|
|
330
|
-
<button @click="{handleClick($c.parent)}"></button>
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
**Multiple arguments:**
|
|
334
|
-
```html
|
|
335
|
-
<button @click="{handleClick($e, $c)}"></button>
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
**Arbitrary binding expressions** — any token that is not `$e` or `$c` is resolved as a binding path on the data source:
|
|
339
|
-
```html
|
|
340
|
-
<button @click="{handleClick(user.id)}"></button>
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
Use `$e` for the DOM event object.
|
|
344
|
-
|
|
345
|
-
### Directives
|
|
346
|
-
|
|
347
|
-
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).
|
|
348
|
-
|
|
349
|
-
Attribute directives are part of [client side binding](#syntax) and therefore use the `{}` syntax.
|
|
350
|
-
|
|
351
|
-
Attribute directives include:
|
|
352
|
-
- **slotted**
|
|
353
|
-
|
|
354
|
-
Example:
|
|
355
|
-
```html
|
|
356
|
-
<slot f-slotted="{slottedNodes}"></slot>
|
|
357
|
-
<slot f-slotted="{slottedNodes filter elements()}"></slot>
|
|
358
|
-
<slot f-slotted="{slottedNodes filter elements(div, p)}"></slot>
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
- **children**
|
|
362
|
-
|
|
363
|
-
Example:
|
|
364
|
-
```html
|
|
365
|
-
<ul f-children="{listItems}"><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
- **ref**
|
|
369
|
-
|
|
370
|
-
Example:
|
|
371
|
-
```html
|
|
372
|
-
<video f-ref="{video}"></video>
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
Template directives include:
|
|
376
|
-
- **when**
|
|
377
|
-
|
|
378
|
-
Example:
|
|
379
|
-
```html
|
|
380
|
-
<f-when value="{{show}}">Hello world</f-when>
|
|
381
|
-
<f-when value="{{!show}}">Goodbye world</f-when>
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
The following operators can also be used:
|
|
385
|
-
- `==`
|
|
386
|
-
- `!=`
|
|
387
|
-
- `>=`
|
|
388
|
-
- `>`
|
|
389
|
-
- `<=`
|
|
390
|
-
- `<`
|
|
391
|
-
- `||`
|
|
392
|
-
- `&&`
|
|
393
|
-
|
|
394
|
-
Where the right operand can be either a reference to a value (string e.g. `{{foo == 'bar'}}`, boolean e.g. `{{foo == true}}`, number e.g. `{{foo == 3}}`) or another binding value.
|
|
395
|
-
|
|
396
|
-
- **repeat**
|
|
397
|
-
|
|
398
|
-
Example:
|
|
399
|
-
```html
|
|
400
|
-
<ul><f-repeat value="{{item in list}}"><li>{{item}}</li></f-repeat></ul>
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
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:
|
|
404
|
-
|
|
405
|
-
```html
|
|
406
|
-
<ul><f-repeat value="{{item in list}}"><li>{{item}} - {{title}}</li></f-repeat></ul>
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
### Execution Context Access
|
|
410
|
-
|
|
411
|
-
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.
|
|
412
|
-
|
|
413
|
-
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.
|
|
414
|
-
|
|
415
|
-
Event handler with context access:
|
|
416
|
-
|
|
417
|
-
```html
|
|
418
|
-
<f-repeat value="{{item in items}}">
|
|
419
|
-
<button @click="{$c.parent.handleItemClick($c.event)}">{{item.name}}</button>
|
|
420
|
-
</f-repeat>
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
Conditional rendering using a host property inside a repeat:
|
|
424
|
-
|
|
425
|
-
```html
|
|
426
|
-
<f-repeat value="{{item in items}}">
|
|
427
|
-
<f-when value="{{$c.parent.showNames}}">
|
|
428
|
-
<span>{{item.name}}</span>
|
|
429
|
-
</f-when>
|
|
430
|
-
</f-repeat>
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
### Unescaped HTML
|
|
434
|
-
|
|
435
|
-
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.
|
|
436
|
-
|
|
437
|
-
Example:
|
|
438
|
-
```html
|
|
439
|
-
{{{html}}}
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
## Writing Components
|
|
443
|
-
|
|
444
|
-
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.
|
|
445
|
-
|
|
446
|
-
## WebUI Integration Testing
|
|
447
|
-
|
|
448
|
-
The fixture tests in `test/declarative/fixtures/` are also validated against
|
|
449
|
-
[`@microsoft/webui`](https://github.com/microsoft/webui) to ensure
|
|
450
|
-
cross-renderer compatibility. The build step renders each fixture's templates
|
|
451
|
-
with `webui build --plugin=fast`, then the existing Playwright specs run
|
|
452
|
-
against the webui-rendered output.
|
|
453
|
-
|
|
454
|
-
```shell
|
|
455
|
-
# Build fixtures with webui and run Playwright tests
|
|
456
|
-
npm run test:webui-integration -w @microsoft/fast-element
|
|
457
|
-
|
|
458
|
-
# Or run the steps separately
|
|
459
|
-
npm run build:fixtures:webui -w @microsoft/fast-element
|
|
460
|
-
npm exec -w @microsoft/fast-element -- playwright test --config=playwright.declarative.webui.config.ts
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
This is also run automatically in CI via the `ci-webui-integration.yml` GitHub Action on pull requests and pushes to `main`.
|
|
464
|
-
|
|
465
|
-
Some tests are conditionally skipped during webui integration runs due to known
|
|
466
|
-
rendering differences between `fast-build` and `webui`. The
|
|
467
|
-
`playwright.declarative.webui.config.ts` file sets
|
|
468
|
-
`FAST_WEBUI_INTEGRATION=true`, and affected tests use `test.skip()` with a
|
|
469
|
-
descriptive reason. See the WebUI Integration Tests section in
|
|
470
|
-
[DECLARATIVE_DESIGN.md](./DECLARATIVE_DESIGN.md) for the full list.
|
package/DECLARATIVE_MIGRATION.md
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
# Migrating from previous versions
|
|
2
|
-
|
|
3
|
-
## Hydration Marker Format (v1-alpha → v1)
|
|
4
|
-
|
|
5
|
-
The SSR output format for hydration markers has been simplified. If you have any tooling that inspects or generates hydration markers, update it to use the new format.
|
|
6
|
-
|
|
7
|
-
| Old marker | New marker |
|
|
8
|
-
|---|---|
|
|
9
|
-
| `<!-- fe-b$$start$$...$$fe-b -->` | `<!--fe:b-->` |
|
|
10
|
-
| `<!-- fe-b$$end$$...$$fe-b -->` | `<!--fe:/b-->` |
|
|
11
|
-
| `<!-- fe-repeat$$start$$...$$fe-repeat -->` | `<!--fe:r-->` |
|
|
12
|
-
| `<!-- fe-repeat$$end$$...$$fe-repeat -->` | `<!--fe:/r-->` |
|
|
13
|
-
| `data-fe-b="0 1 2"` / `data-fe-b-0` / `data-fe-c-0-3` | `data-fe="N"` |
|
|
14
|
-
|
|
15
|
-
The `@microsoft/fast-build` WASM binary emits the new markers automatically. Rebuild all fixtures and SSR output after upgrading.
|
|
16
|
-
|
|
17
|
-
See the [`@microsoft/fast-element` MIGRATION.md](../fast-element/MIGRATION.md#hydration-marker-format-v3) for full details on API changes.
|
|
18
|
-
|
|
19
|
-
## Prerendered Content Optimization (v1-alpha → v1)
|
|
20
|
-
|
|
21
|
-
### Removed exports
|
|
22
|
-
|
|
23
|
-
| Export | Replacement |
|
|
24
|
-
|---|---|
|
|
25
|
-
| `RenderableFASTElement` | Extend `FASTElement` |
|
|
26
|
-
|
|
27
|
-
### Removed concepts
|
|
28
|
-
|
|
29
|
-
| Concept | Replacement |
|
|
30
|
-
|---|---|
|
|
31
|
-
| `prepare()` lifecycle hook | Set state in `connectedCallback`; the reactive system updates the DOM |
|
|
32
|
-
| `defer-hydration` attribute in rendered markup | Template-pending guard in `ElementController.connect()` |
|
|
33
|
-
| `needs-hydration` attribute in rendered markup | `hasExistingShadowRoot` detection in `ElementController` |
|
|
34
|
-
| `waitForAncestorHydration()` | Not needed — prerendered content is correct regardless of connection order |
|
|
35
|
-
|
|
36
|
-
### Migration steps
|
|
37
|
-
|
|
38
|
-
1. Replace `RenderableFASTElement(MyComponent).defineAsync({...})` with
|
|
39
|
-
`await MyComponent.define({...})` and use `declarativeTemplate()` for
|
|
40
|
-
declarative templates. `declarativeTemplate()` is the waiting behavior: it
|
|
41
|
-
resolves the matching `<f-template>` before `define()` completes.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// Before
|
|
45
|
-
import { RenderableFASTElement } from "@microsoft/fast-html";
|
|
46
|
-
RenderableFASTElement(MyComponent).defineAsync({
|
|
47
|
-
name: "my-component",
|
|
48
|
-
templateOptions: "defer-and-hydrate",
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// After
|
|
52
|
-
await MyComponent.define({
|
|
53
|
-
name: "my-component",
|
|
54
|
-
template: declarativeTemplate(),
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
2. Remove `prepare()` methods. Move any initialization logic to `connectedCallback`:
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
// Before
|
|
62
|
-
class MyComponent extends FASTElement {
|
|
63
|
-
async prepare() {
|
|
64
|
-
this.data = await fetchData();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// After
|
|
69
|
-
class MyComponent extends FASTElement {
|
|
70
|
-
connectedCallback() {
|
|
71
|
-
super.connectedCallback();
|
|
72
|
-
this.loadData();
|
|
73
|
-
}
|
|
74
|
-
async loadData() {
|
|
75
|
-
this.data = await fetchData();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
3. Remove `defer-hydration` and `needs-hydration` attributes from server-rendered markup:
|
|
81
|
-
|
|
82
|
-
```html
|
|
83
|
-
<!-- Before -->
|
|
84
|
-
<my-component defer-hydration needs-hydration text="Hello">
|
|
85
|
-
<template shadowrootmode="open">...</template>
|
|
86
|
-
</my-component>
|
|
87
|
-
|
|
88
|
-
<!-- After -->
|
|
89
|
-
<my-component text="Hello">
|
|
90
|
-
<template shadowrootmode="open">...</template>
|
|
91
|
-
</my-component>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
4. Await `$fastController.isPrerendered` to detect prerendered components:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
connectedCallback() {
|
|
98
|
-
super.connectedCallback();
|
|
99
|
-
this.$fastController.isPrerendered.then(prerendered => {
|
|
100
|
-
if (!prerendered) {
|
|
101
|
-
this.fetchData();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Modularize Schema, ObserverMap, and AttributeMap
|
|
108
|
-
|
|
109
|
-
### Import changes
|
|
110
|
-
|
|
111
|
-
Configuration types have moved from `template.ts` to their owning modules. If you import types directly from internal paths, update your imports:
|
|
112
|
-
|
|
113
|
-
| Before | After |
|
|
114
|
-
|---|---|
|
|
115
|
-
| `import type { ObserverMapConfig } from "./template.js"` | `import type { ObserverMapConfig } from "./observer-map.js"` |
|
|
116
|
-
| `import type { AttributeMapConfig } from "./template.js"` | `import type { AttributeMapConfig } from "./attribute-map.js"` |
|
|
117
|
-
|
|
118
|
-
Public declarative imports now come from
|
|
119
|
-
`@microsoft/fast-element` rather than
|
|
120
|
-
`@microsoft/fast-html`. Existing declarative imports for `attributeMap()` and
|
|
121
|
-
`observerMap()` remain valid. New code that only needs the map extensions should
|
|
122
|
-
prefer `@microsoft/fast-element` and
|
|
123
|
-
`@microsoft/fast-element`.
|
|
124
|
-
|
|
125
|
-
### Schema changes
|
|
126
|
-
|
|
127
|
-
`Schema.jsonSchemaMap` (static property) has been replaced by:
|
|
128
|
-
- An instance-level `schemaMap` on each `Schema` instance (private)
|
|
129
|
-
- A module-level `schemaRegistry` export for cross-element lookups
|
|
130
|
-
|
|
131
|
-
| Before | After |
|
|
132
|
-
|---|---|
|
|
133
|
-
| `Schema.jsonSchemaMap.get('my-element')` | `import { schemaRegistry } from "@microsoft/fast-element"; schemaRegistry.get('my-element')` |
|
|
134
|
-
|
|
135
|
-
### Public exports
|
|
136
|
-
|
|
137
|
-
The public entrypoint exports the functional declarative API:
|
|
138
|
-
|
|
139
|
-
| Export | Purpose |
|
|
140
|
-
|---|---|
|
|
141
|
-
| `declarativeTemplate()` | Resolves `<f-template>` markup for a FAST element definition |
|
|
142
|
-
| `attributeMap()` | Definition extension for automatic `@attr` property registration |
|
|
143
|
-
| `observerMap()` | Definition extension for automatic deep observation |
|
|
144
|
-
| `Schema` | JSON schema builder class |
|
|
145
|
-
| `schemaRegistry` | Module-level registry for cross-element schema lookups |
|
|
146
|
-
| `JSONSchema` | JSON Schema type interface |
|
|
147
|
-
| `CachedPathMap` | Schema registry map type |
|
|
148
|
-
|
|
149
|
-
## Simplified ObserverMap and AttributeMap defaults
|
|
150
|
-
|
|
151
|
-
The explicit `ObserverMapOption.all` and `AttributeMapOption.all` constants have
|
|
152
|
-
been removed. Calling `observerMap()` with no arguments observes every
|
|
153
|
-
discovered root property, and calling `attributeMap()` with no arguments maps
|
|
154
|
-
every discovered leaf binding.
|
|
155
|
-
|
|
156
|
-
| Before | After |
|
|
157
|
-
|---|---|
|
|
158
|
-
| `observerMap(ObserverMapOption.all)` | `observerMap()` |
|
|
159
|
-
| `attributeMap(AttributeMapOption.all)` | `attributeMap()` |
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
## Declarative TemplateElement API removal
|
|
163
|
-
|
|
164
|
-
The public declarative API is now the functional API. The `<f-template>`
|
|
165
|
-
implementation is internal and is defined automatically by `declarativeTemplate()`.
|
|
166
|
-
|
|
167
|
-
| Removed | Replacement |
|
|
168
|
-
|---|---|
|
|
169
|
-
| `TemplateElement` public export | `declarativeTemplate()` on each FAST element definition |
|
|
170
|
-
| `TemplateElement.define({ name: "f-template" })` | No manual definition; `declarativeTemplate()` defines the internal publisher in the target registry |
|
|
171
|
-
| `TemplateElement.config(callbacks)` / `HydrationLifecycleCallbacks` | Per-element callbacks via `declarativeTemplate(callbacks)` and global hydration callbacks via `enableHydration(options)` |
|
|
172
|
-
| `TemplateElement.options({ "my-el": { attributeMap, observerMap } })` | Define extensions: `MyElement.define(definition, [attributeMap(...), observerMap(...)])` |
|
|
173
|
-
| `ElementOptions` / `ElementOptionsDictionary` | No replacement |
|
|
174
|
-
| `AttributeMap` / `ObserverMap` class exports from the old declarative public surface | `attributeMap()` / `observerMap()` extension helpers and their config types |
|
|
175
|
-
|
|
176
|
-
Hydration is also no longer installed by `@microsoft/fast-element`.
|
|
177
|
-
Call `enableHydration()` from `@microsoft/fast-element/hydration.js` before FAST
|
|
178
|
-
elements connect when prerendered Declarative Shadow DOM should be reused.
|
|
179
|
-
|
|
180
|
-
## Schema-driven maps and optional definition schema
|
|
181
|
-
|
|
182
|
-
`attributeMap()` and `observerMap()` are now schema-driven extensions that are
|
|
183
|
-
factored away from declarative templating. Import them from
|
|
184
|
-
`@microsoft/fast-element` for declarative or non-declarative use:
|
|
185
|
-
|
|
186
|
-
```ts
|
|
187
|
-
import { attributeMap } from "@microsoft/fast-element/attribute-map.js";
|
|
188
|
-
import { observerMap } from "@microsoft/fast-element/observer-map.js";
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
`FASTElementDefinition.schema` is optional. `declarativeTemplate()` assigns it
|
|
192
|
-
automatically when it parses `<f-template>` markup. Manual schema users can pass
|
|
193
|
-
a schema in the element definition, and `observerMap()` can also take a schema
|
|
194
|
-
directly in configuration:
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { FASTElement, Schema } from "@microsoft/fast-element";
|
|
198
|
-
import { observerMap } from "@microsoft/fast-element/observer-map.js";
|
|
199
|
-
|
|
200
|
-
class MyElement extends FASTElement {}
|
|
201
|
-
|
|
202
|
-
const schema = new Schema("my-element");
|
|
203
|
-
schema.addPath({
|
|
204
|
-
rootPropertyName: "user",
|
|
205
|
-
pathConfig: {
|
|
206
|
-
type: "default",
|
|
207
|
-
parentContext: null,
|
|
208
|
-
currentContext: null,
|
|
209
|
-
path: "user.name",
|
|
210
|
-
},
|
|
211
|
-
childrenMap: null,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
MyElement.define({ name: "my-element" }, [observerMap({ schema })]);
|
|
215
|
-
```
|