@microsoft/fast-element 2.8.1 → 2.8.3

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.json CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "@microsoft/fast-element",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 21 Oct 2025 16:17:03 GMT",
5
+ "date": "Wed, 12 Nov 2025 20:41:22 GMT",
6
+ "version": "2.8.3",
7
+ "tag": "@microsoft/fast-element_v2.8.3",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "863023+radium-v@users.noreply.github.com",
12
+ "package": "@microsoft/fast-element",
13
+ "commit": "2601b22d4bfabc277ddb259dbe028d695712986b",
14
+ "comment": "fix: update hydration attribute logic in HydratableElementController tests and implementation"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 31 Oct 2025 20:45:55 GMT",
21
+ "version": "2.8.2",
22
+ "tag": "@microsoft/fast-element_v2.8.2",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "863023+radium-v@users.noreply.github.com",
27
+ "package": "@microsoft/fast-element",
28
+ "commit": "1c008047c3c0b651dbec6dd74ece2da71693cbf3",
29
+ "comment": "fix: use shadowOptions getter override to set hydration attributes"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Tue, 21 Oct 2025 16:17:27 GMT",
6
36
  "version": "2.8.1",
7
37
  "tag": "@microsoft/fast-element_v2.8.1",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
1
1
  # Change Log - @microsoft/fast-element
2
2
 
3
- <!-- This log was last generated on Tue, 21 Oct 2025 16:17:03 GMT and should not be manually modified. -->
3
+ <!-- This log was last generated on Wed, 12 Nov 2025 20:41:22 GMT and should not be manually modified. -->
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 2.8.3
8
+
9
+ Wed, 12 Nov 2025 20:41:22 GMT
10
+
11
+ ### Patches
12
+
13
+ - fix: update hydration attribute logic in HydratableElementController tests and implementation (863023+radium-v@users.noreply.github.com)
14
+
15
+ ## 2.8.2
16
+
17
+ Fri, 31 Oct 2025 20:45:55 GMT
18
+
19
+ ### Patches
20
+
21
+ - fix: use shadowOptions getter override to set hydration attributes (863023+radium-v@users.noreply.github.com)
22
+
7
23
  ## 2.8.1
8
24
 
9
- Tue, 21 Oct 2025 16:17:03 GMT
25
+ Tue, 21 Oct 2025 16:17:27 GMT
10
26
 
11
27
  ### Patches
12
28
 
@@ -13,10 +13,18 @@ import { FASTElementDefinition, ShadowRootOptions } from "./fast-definitions.js"
13
13
  export interface ElementControllerStrategy {
14
14
  new (element: HTMLElement, definition: FASTElementDefinition): ElementController;
15
15
  }
16
- declare const enum Stages {
16
+ /**
17
+ * The various lifecycle stages of an ElementController.
18
+ * @public
19
+ */
20
+ export declare const enum Stages {
21
+ /** The element is in the process of connecting. */
17
22
  connecting = 0,
23
+ /** The element is connected. */
18
24
  connected = 1,
25
+ /** The element is in the process of disconnecting. */
19
26
  disconnecting = 2,
27
+ /** The element is disconnected. */
20
28
  disconnected = 3
21
29
  }
22
30
  /**
@@ -24,11 +32,29 @@ declare const enum Stages {
24
32
  * @public
25
33
  */
26
34
  export declare class ElementController<TElement extends HTMLElement = HTMLElement> extends PropertyChangeNotifier implements HostController<TElement> {
35
+ /**
36
+ * A map of observable properties that were set on the element before upgrade.
37
+ */
27
38
  private boundObservables;
39
+ /**
40
+ * Indicates whether the controller needs to perform initial rendering.
41
+ */
28
42
  protected needsInitialization: boolean;
29
- private hasExistingShadowRoot;
43
+ /**
44
+ * Indicates whether the element has an existing shadow root (e.g. from declarative shadow DOM).
45
+ */
46
+ protected hasExistingShadowRoot: boolean;
47
+ /**
48
+ * The template used to render the component.
49
+ */
30
50
  private _template;
51
+ /**
52
+ * The shadow root options for the component.
53
+ */
31
54
  private _shadowRootOptions;
55
+ /**
56
+ * The current lifecycle stage of the controller.
57
+ */
32
58
  protected stage: Stages;
33
59
  /**
34
60
  * A guard against connecting behaviors multiple times
@@ -36,12 +62,19 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
36
62
  * another behavior during it's connectedCallback
37
63
  */
38
64
  private guardBehaviorConnection;
65
+ /**
66
+ * The behaviors associated with the component.
67
+ */
39
68
  protected behaviors: Map<HostBehavior<TElement>, number> | null;
40
69
  /**
41
70
  * Tracks whether behaviors are connected so that
42
71
  * behaviors cant be connected multiple times
43
72
  */
44
73
  private behaviorsConnected;
74
+ /**
75
+ * The main set of styles used for the component, independent of any
76
+ * dynamically added styles.
77
+ */
45
78
  private _mainStyles;
46
79
  /**
47
80
  * This allows Observable.getNotifier(...) to return the Controller
@@ -91,6 +124,9 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
91
124
  */
92
125
  get template(): ElementViewTemplate<TElement> | null;
93
126
  set template(value: ElementViewTemplate<TElement> | null);
127
+ /**
128
+ * The shadow root options for the component.
129
+ */
94
130
  get shadowOptions(): ShadowRootOptions | undefined;
95
131
  set shadowOptions(value: ShadowRootOptions | undefined);
96
132
  /**
@@ -139,8 +175,17 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
139
175
  * Runs connected lifecycle behavior on the associated element.
140
176
  */
141
177
  connect(): void;
178
+ /**
179
+ * Binds any observables that were set before upgrade.
180
+ */
142
181
  protected bindObservables(): void;
182
+ /**
183
+ * Connects any existing behaviors on the associated element.
184
+ */
143
185
  protected connectBehaviors(): void;
186
+ /**
187
+ * Disconnects any behaviors on the associated element.
188
+ */
144
189
  protected disconnectBehaviors(): void;
145
190
  /**
146
191
  * Runs disconnected lifecycle behavior on the associated element.
@@ -162,6 +207,13 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
162
207
  * Only emits events if connected.
163
208
  */
164
209
  emit(type: string, detail?: any, options?: Omit<CustomEventInit, "detail">): void | boolean;
210
+ /**
211
+ * Renders the provided template to the element.
212
+ *
213
+ * @param template - The template to render.
214
+ * @remarks
215
+ * If `null` is provided, any existing view will be removed.
216
+ */
165
217
  protected renderTemplate(template: ElementViewTemplate | null | undefined): void;
166
218
  /**
167
219
  * Locates or creates a controller for the specified element.
@@ -204,7 +256,15 @@ export declare class StyleElementStrategy implements StyleStrategy {
204
256
  addStylesTo(target: StyleTarget): void;
205
257
  removeStylesFrom(target: StyleTarget): void;
206
258
  }
259
+ /**
260
+ * The attribute used to defer hydration of an element.
261
+ * @public
262
+ */
207
263
  export declare const deferHydrationAttribute = "defer-hydration";
264
+ /**
265
+ * The attribute used to indicate that an element needs hydration.
266
+ * @public
267
+ */
208
268
  export declare const needsHydrationAttribute = "needs-hydration";
209
269
  /**
210
270
  * Lifecycle callbacks for element hydration events
@@ -238,6 +298,11 @@ export declare class HydratableElementController<TElement extends HTMLElement =
238
298
  */
239
299
  protected needsHydration?: boolean;
240
300
  private static hydrationObserver;
301
+ /**
302
+ * {@inheritdoc ElementController.shadowOptions}
303
+ */
304
+ get shadowOptions(): ShadowRootOptions | undefined;
305
+ set shadowOptions(value: ShadowRootOptions | undefined);
241
306
  /**
242
307
  * Lifecycle callbacks for hydration events
243
308
  */
@@ -263,7 +328,9 @@ export declare class HydratableElementController<TElement extends HTMLElement =
263
328
  * @param deadline - the idle deadline object
264
329
  */
265
330
  private static checkHydrationComplete;
266
- static forCustomElement(element: HTMLElement, override?: boolean): ElementController<HTMLElement>;
331
+ /**
332
+ * Runs connected lifecycle behavior on the associated element.
333
+ */
267
334
  connect(): void;
268
335
  /**
269
336
  * A map of element instances by the name of the custom element they are
@@ -279,7 +346,15 @@ export declare class HydratableElementController<TElement extends HTMLElement =
279
346
  * Removes the current element instance from the hydrating instances map
280
347
  */
281
348
  private removeHydratingInstance;
349
+ /**
350
+ * Unregisters the hydration observer when the element is disconnected.
351
+ */
282
352
  disconnect(): void;
353
+ /**
354
+ * Sets the ElementController strategy to HydratableElementController.
355
+ * @remarks
356
+ * This method is typically called during application startup to enable
357
+ * hydration support for FAST elements.
358
+ */
283
359
  static install(): void;
284
360
  }
285
- export {};
@@ -31,4 +31,4 @@ export { render, RenderBehavior, RenderDirective } from "./templating/render.js"
31
31
  export { customElement, FASTElement } from "./components/fast-element.js";
32
32
  export { FASTElementDefinition, PartialFASTElementDefinition, ShadowRootOptions, fastElementRegistry, TemplateOptions, TypeRegistry, type TemplateLifecycleCallbacks, } from "./components/fast-definitions.js";
33
33
  export { attr, AttributeConfiguration, AttributeDefinition, AttributeMode, booleanConverter, DecoratorAttributeConfiguration, nullableBooleanConverter, nullableNumberConverter, ValueConverter, } from "./components/attributes.js";
34
- export { ElementController, ElementControllerStrategy, HydratableElementController, type HydrationControllerCallbacks, } from "./components/element-controller.js";
34
+ export { deferHydrationAttribute, ElementController, ElementControllerStrategy, HydratableElementController, type HydrationControllerCallbacks, needsHydrationAttribute, Stages, } from "./components/element-controller.js";
@@ -32,10 +32,25 @@ export class ElementController extends PropertyChangeNotifier {
32
32
  */
33
33
  constructor(element, definition) {
34
34
  super(element);
35
+ /**
36
+ * A map of observable properties that were set on the element before upgrade.
37
+ */
35
38
  this.boundObservables = null;
39
+ /**
40
+ * Indicates whether the controller needs to perform initial rendering.
41
+ */
36
42
  this.needsInitialization = true;
43
+ /**
44
+ * Indicates whether the element has an existing shadow root (e.g. from declarative shadow DOM).
45
+ */
37
46
  this.hasExistingShadowRoot = false;
47
+ /**
48
+ * The template used to render the component.
49
+ */
38
50
  this._template = null;
51
+ /**
52
+ * The current lifecycle stage of the controller.
53
+ */
39
54
  this.stage = 3 /* Stages.disconnected */;
40
55
  /**
41
56
  * A guard against connecting behaviors multiple times
@@ -43,12 +58,19 @@ export class ElementController extends PropertyChangeNotifier {
43
58
  * another behavior during it's connectedCallback
44
59
  */
45
60
  this.guardBehaviorConnection = false;
61
+ /**
62
+ * The behaviors associated with the component.
63
+ */
46
64
  this.behaviors = null;
47
65
  /**
48
66
  * Tracks whether behaviors are connected so that
49
67
  * behaviors cant be connected multiple times
50
68
  */
51
69
  this.behaviorsConnected = false;
70
+ /**
71
+ * The main set of styles used for the component, independent of any
72
+ * dynamically added styles.
73
+ */
52
74
  this._mainStyles = null;
53
75
  /**
54
76
  * This allows Observable.getNotifier(...) to return the Controller
@@ -144,6 +166,9 @@ export class ElementController extends PropertyChangeNotifier {
144
166
  this.renderTemplate(value);
145
167
  }
146
168
  }
169
+ /**
170
+ * The shadow root options for the component.
171
+ */
147
172
  get shadowOptions() {
148
173
  return this._shadowRootOptions;
149
174
  }
@@ -318,6 +343,9 @@ export class ElementController extends PropertyChangeNotifier {
318
343
  this.stage = 1 /* Stages.connected */;
319
344
  Observable.notify(this, isConnectedPropertyName);
320
345
  }
346
+ /**
347
+ * Binds any observables that were set before upgrade.
348
+ */
321
349
  bindObservables() {
322
350
  if (this.boundObservables !== null) {
323
351
  const element = this.source;
@@ -330,6 +358,9 @@ export class ElementController extends PropertyChangeNotifier {
330
358
  this.boundObservables = null;
331
359
  }
332
360
  }
361
+ /**
362
+ * Connects any existing behaviors on the associated element.
363
+ */
333
364
  connectBehaviors() {
334
365
  if (this.behaviorsConnected === false) {
335
366
  const behaviors = this.behaviors;
@@ -343,6 +374,9 @@ export class ElementController extends PropertyChangeNotifier {
343
374
  this.behaviorsConnected = true;
344
375
  }
345
376
  }
377
+ /**
378
+ * Disconnects any behaviors on the associated element.
379
+ */
346
380
  disconnectBehaviors() {
347
381
  if (this.behaviorsConnected === true) {
348
382
  const behaviors = this.behaviors;
@@ -395,6 +429,13 @@ export class ElementController extends PropertyChangeNotifier {
395
429
  }
396
430
  return false;
397
431
  }
432
+ /**
433
+ * Renders the provided template to the element.
434
+ *
435
+ * @param template - The template to render.
436
+ * @remarks
437
+ * If `null` is provided, any existing view will be removed.
438
+ */
398
439
  renderTemplate(template) {
399
440
  var _a;
400
441
  // When getting the host to render to, we start by looking
@@ -582,7 +623,15 @@ if (ElementStyles.supportsAdoptedStyleSheets) {
582
623
  else {
583
624
  ElementStyles.setDefaultStrategy(StyleElementStrategy);
584
625
  }
626
+ /**
627
+ * The attribute used to defer hydration of an element.
628
+ * @public
629
+ */
585
630
  export const deferHydrationAttribute = "defer-hydration";
631
+ /**
632
+ * The attribute used to indicate that an element needs hydration.
633
+ * @public
634
+ */
586
635
  export const needsHydrationAttribute = "needs-hydration";
587
636
  /**
588
637
  * An ElementController capable of hydrating FAST elements from
@@ -591,6 +640,20 @@ export const needsHydrationAttribute = "needs-hydration";
591
640
  * @beta
592
641
  */
593
642
  export class HydratableElementController extends ElementController {
643
+ /**
644
+ * {@inheritdoc ElementController.shadowOptions}
645
+ */
646
+ get shadowOptions() {
647
+ return super.shadowOptions;
648
+ }
649
+ set shadowOptions(value) {
650
+ super.shadowOptions = value;
651
+ if ((this.hasExistingShadowRoot || (value !== void 0 && !this.template)) &&
652
+ this.definition.templateOptions === TemplateOptions.deferAndHydrate) {
653
+ this.source.toggleAttribute(deferHydrationAttribute, true);
654
+ this.source.toggleAttribute(needsHydrationAttribute, true);
655
+ }
656
+ }
594
657
  /**
595
658
  * Adds the current element instance to the hydrating instances map
596
659
  */
@@ -641,20 +704,14 @@ export class HydratableElementController extends ElementController {
641
704
  ElementController.setStrategy(ElementController);
642
705
  }
643
706
  }
644
- static forCustomElement(element, override) {
645
- const definition = FASTElementDefinition.getForInstance(element);
646
- if ((definition === null || definition === void 0 ? void 0 : definition.templateOptions) === TemplateOptions.deferAndHydrate &&
647
- !definition.template) {
648
- element.toggleAttribute(deferHydrationAttribute, true);
649
- element.toggleAttribute(needsHydrationAttribute, true);
650
- }
651
- return super.forCustomElement(element, override);
652
- }
707
+ /**
708
+ * Runs connected lifecycle behavior on the associated element.
709
+ */
653
710
  connect() {
654
711
  var _a, _b, _c, _d, _e;
655
712
  // Initialize needsHydration on first connect
656
713
  this.needsHydration =
657
- (_a = this.needsHydration) !== null && _a !== void 0 ? _a : this.source.getAttribute(needsHydrationAttribute) !== null;
714
+ (_a = this.needsHydration) !== null && _a !== void 0 ? _a : this.source.hasAttribute(needsHydrationAttribute);
658
715
  if (this.needsHydration) {
659
716
  (_c = (_b = HydratableElementController.lifecycleCallbacks) === null || _b === void 0 ? void 0 : _b.elementWillHydrate) === null || _c === void 0 ? void 0 : _c.call(_b, this.definition.name);
660
717
  }
@@ -736,10 +793,19 @@ export class HydratableElementController extends ElementController {
736
793
  HydratableElementController.idleCallbackId = requestIdleCallback(HydratableElementController.checkHydrationComplete, { timeout: 50 });
737
794
  }
738
795
  }
796
+ /**
797
+ * Unregisters the hydration observer when the element is disconnected.
798
+ */
739
799
  disconnect() {
740
800
  super.disconnect();
741
801
  HydratableElementController.hydrationObserver.unobserve(this.source);
742
802
  }
803
+ /**
804
+ * Sets the ElementController strategy to HydratableElementController.
805
+ * @remarks
806
+ * This method is typically called during application startup to enable
807
+ * hydration support for FAST elements.
808
+ */
743
809
  static install() {
744
810
  ElementController.setStrategy(HydratableElementController);
745
811
  }
package/dist/esm/index.js CHANGED
@@ -36,4 +36,4 @@ export { render, RenderBehavior, RenderDirective } from "./templating/render.js"
36
36
  export { customElement, FASTElement } from "./components/fast-element.js";
37
37
  export { FASTElementDefinition, fastElementRegistry, TemplateOptions, } from "./components/fast-definitions.js";
38
38
  export { attr, AttributeConfiguration, AttributeDefinition, booleanConverter, nullableBooleanConverter, nullableNumberConverter, } from "./components/attributes.js";
39
- export { ElementController, HydratableElementController, } from "./components/element-controller.js";
39
+ export { deferHydrationAttribute, ElementController, HydratableElementController, needsHydrationAttribute, } from "./components/element-controller.js";