@microsoft/fast-element 2.0.0-beta.21 → 2.0.0-beta.23

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 (56) hide show
  1. package/CHANGELOG.json +54 -0
  2. package/CHANGELOG.md +21 -1
  3. package/dist/dts/binding/binding.d.ts +49 -0
  4. package/dist/dts/binding/normalize.d.ts +9 -0
  5. package/dist/dts/binding/one-time.d.ts +11 -0
  6. package/dist/dts/binding/one-way.d.ts +20 -0
  7. package/dist/dts/{templating/binding-signal.d.ts → binding/signal.d.ts} +16 -3
  8. package/dist/dts/{templating/binding-two-way.d.ts → binding/two-way.d.ts} +6 -4
  9. package/dist/dts/components/element-controller.d.ts +20 -5
  10. package/dist/dts/context.d.ts +21 -8
  11. package/dist/dts/index.d.ts +7 -2
  12. package/dist/dts/interfaces.d.ts +9 -4
  13. package/dist/dts/metadata.d.ts +1 -0
  14. package/dist/dts/platform.d.ts +9 -1
  15. package/dist/dts/styles/css-binding-directive.d.ts +60 -0
  16. package/dist/dts/styles/css.d.ts +9 -2
  17. package/dist/dts/styles/host.d.ts +2 -5
  18. package/dist/dts/templating/{binding.d.ts → html-binding-directive.d.ts} +3 -34
  19. package/dist/dts/templating/html-directive.d.ts +3 -35
  20. package/dist/dts/templating/render.d.ts +19 -5
  21. package/dist/dts/templating/repeat.d.ts +3 -2
  22. package/dist/dts/templating/template.d.ts +2 -6
  23. package/dist/dts/templating/view.d.ts +16 -6
  24. package/dist/dts/testing/fakes.d.ts +2 -1
  25. package/dist/esm/binding/binding.js +18 -0
  26. package/dist/esm/binding/normalize.js +17 -0
  27. package/dist/esm/binding/one-time.js +21 -0
  28. package/dist/esm/binding/one-way.js +30 -0
  29. package/dist/esm/{templating/binding-signal.js → binding/signal.js} +20 -10
  30. package/dist/esm/{templating/binding-two-way.js → binding/two-way.js} +14 -15
  31. package/dist/esm/components/element-controller.js +33 -8
  32. package/dist/esm/context.js +22 -1
  33. package/dist/esm/index.js +9 -2
  34. package/dist/esm/interfaces.js +3 -3
  35. package/dist/esm/metadata.js +3 -1
  36. package/dist/esm/observation/observable.js +3 -6
  37. package/dist/esm/platform.js +9 -0
  38. package/dist/esm/styles/css-binding-directive.js +76 -0
  39. package/dist/esm/styles/css.js +14 -2
  40. package/dist/esm/templating/compiler.js +2 -1
  41. package/dist/esm/templating/{binding.js → html-binding-directive.js} +3 -70
  42. package/dist/esm/templating/html-directive.js +2 -25
  43. package/dist/esm/templating/render.js +25 -12
  44. package/dist/esm/templating/repeat.js +3 -3
  45. package/dist/esm/templating/template.js +9 -10
  46. package/dist/esm/templating/view.js +2 -6
  47. package/dist/esm/testing/fakes.js +1 -1
  48. package/dist/fast-element.api.json +1129 -222
  49. package/dist/fast-element.d.ts +125 -33
  50. package/dist/fast-element.debug.js +217 -117
  51. package/dist/fast-element.debug.min.js +1 -1
  52. package/dist/fast-element.js +217 -117
  53. package/dist/fast-element.min.js +1 -1
  54. package/dist/fast-element.untrimmed.d.ts +132 -72
  55. package/docs/api-report.md +52 -48
  56. package/package.json +5 -5
@@ -207,16 +207,6 @@ export declare class AttributeDefinition implements Accessor {
207
207
  */
208
208
  export declare type AttributeMode = typeof reflectMode | typeof booleanMode | "fromView";
209
209
 
210
- /**
211
- * Creates an standard binding.
212
- * @param expression - The binding to refresh when changed.
213
- * @param policy - The security policy to associate with th binding.
214
- * @param isVolatile - Indicates whether the binding is volatile or not.
215
- * @returns A binding configuration.
216
- * @public
217
- */
218
- export declare function bind<T = any>(expression: Expression<T>, policy?: DOMPolicy, isVolatile?: boolean): Binding<T>;
219
-
220
210
  /**
221
211
  * Captures a binding expression along with related information and capabilities.
222
212
  *
@@ -239,10 +229,30 @@ export declare abstract class Binding<TSource = any, TReturn = any, TParent = an
239
229
  constructor(evaluate: Expression<TSource, TReturn, TParent>, policy?: DOMPolicy | undefined, isVolatile?: boolean);
240
230
  /**
241
231
  * Creates an observer capable of notifying a subscriber when the output of a binding changes.
242
- * @param directive - The HTML Directive to create the observer for.
243
232
  * @param subscriber - The subscriber to changes in the binding.
233
+ * @param directive - The Binding directive to create the observer for.
234
+ */
235
+ abstract createObserver(subscriber: Subscriber, directive: BindingDirective): ExpressionObserver<TSource, TReturn, TParent>;
236
+ }
237
+
238
+ /**
239
+ * The directive from which a binding originates.
240
+ *
241
+ * @public
242
+ */
243
+ export declare interface BindingDirective {
244
+ /**
245
+ * The binding.
244
246
  */
245
- abstract createObserver(directive: HTMLDirective, subscriber: Subscriber): ExpressionObserver<TSource, TReturn, TParent>;
247
+ readonly dataBinding: Binding;
248
+ /**
249
+ * The evaluated target aspect.
250
+ */
251
+ readonly targetAspect?: string;
252
+ /**
253
+ * The type of aspect to target.
254
+ */
255
+ readonly aspectType?: DOMAspect;
246
256
  }
247
257
 
248
258
  /**
@@ -461,10 +471,6 @@ export declare interface ContentView {
461
471
  remove(): void;
462
472
  }
463
473
 
464
- /* Excluded from this release type: createMetadataLocator */
465
-
466
- /* Excluded from this release type: createTypeRegistry */
467
-
468
474
  /**
469
475
  * Transforms a template literal string into styles.
470
476
  * @param strings - The string fragments that are interpolated with the values.
@@ -475,6 +481,54 @@ export declare interface ContentView {
475
481
  */
476
482
  export declare const css: CSSTemplateTag;
477
483
 
484
+ /**
485
+ * Enables bindings in CSS.
486
+ *
487
+ * @public
488
+ */
489
+ export declare class CSSBindingDirective implements HostBehavior, Subscriber, CSSDirective, BindingDirective {
490
+ readonly dataBinding: Binding;
491
+ readonly targetAspect: string;
492
+ /**
493
+ * Creates an instance of CSSBindingDirective.
494
+ * @param dataBinding - The binding to use in CSS.
495
+ * @param targetAspect - The CSS property to target.
496
+ */
497
+ constructor(dataBinding: Binding, targetAspect: string);
498
+ /**
499
+ * Creates a CSS fragment to interpolate into the CSS document.
500
+ * @returns - the string to interpolate into CSS
501
+ */
502
+ createCSS(add: AddBehavior): ComposableStyles;
503
+ /**
504
+ * Executed when this behavior is attached to a controller.
505
+ * @param controller - Controls the behavior lifecycle.
506
+ */
507
+ addedCallback(controller: HostController<HTMLElement & {
508
+ $cssBindings: Map<CSSBindingDirective, CSSBindingEntry>;
509
+ }>): void;
510
+ /**
511
+ * Executed when this behavior's host is connected.
512
+ * @param controller - Controls the behavior lifecycle.
513
+ */
514
+ connectedCallback(controller: HostController<HTMLElement & {
515
+ $cssBindings: Map<CSSBindingDirective, CSSBindingEntry>;
516
+ }>): void;
517
+ /**
518
+ * Executed when this behavior is detached from a controller.
519
+ * @param controller - Controls the behavior lifecycle.
520
+ */
521
+ removedCallback(controller: HostController<HTMLElement & {
522
+ $cssBindings: Map<CSSBindingDirective, CSSBindingEntry>;
523
+ }>): void;
524
+ /* Excluded from this release type: handleChange */
525
+ }
526
+
527
+ declare type CSSBindingEntry = {
528
+ observer: ExpressionObserver;
529
+ controller: HostController;
530
+ };
531
+
478
532
  /**
479
533
  * Directive for use in {@link css}.
480
534
  *
@@ -537,16 +591,22 @@ export declare interface CSSDirectiveDefinition<TType extends Constructable<CSSD
537
591
  * Use the .partial method to create partial CSS fragments.
538
592
  * @public
539
593
  */
540
- export declare type CSSTemplateTag = ((strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => ElementStyles) & {
594
+ export declare type CSSTemplateTag = (<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: CSSValue<TSource, TParent>[]) => ElementStyles) & {
541
595
  /**
542
596
  * Transforms a template literal string into partial CSS.
543
597
  * @param strings - The string fragments that are interpolated with the values.
544
598
  * @param values - The values that are interpolated with the string fragments.
545
599
  * @public
546
600
  */
547
- partial(strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]): CSSDirective;
601
+ partial<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: CSSValue<TSource, TParent>[]): CSSDirective;
548
602
  };
549
603
 
604
+ /**
605
+ * Represents the types of values that can be interpolated into a template.
606
+ * @public
607
+ */
608
+ export declare type CSSValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | ComposableStyles | CSSDirective;
609
+
550
610
  /**
551
611
  * Decorator: Defines a platform custom element based on `FASTElement`.
552
612
  * @param nameOrDef - The name of the element to define or a definition object
@@ -728,6 +788,18 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
728
788
  * connected to the document.
729
789
  */
730
790
  get isConnected(): boolean;
791
+ /**
792
+ * The context the expression is evaluated against.
793
+ */
794
+ get context(): ExecutionContext;
795
+ /**
796
+ * Indicates whether the controller is bound.
797
+ */
798
+ get isBound(): boolean;
799
+ /**
800
+ * Indicates how the source's lifetime relates to the controller's lifetime.
801
+ */
802
+ get sourceLifetime(): SourceLifetime | undefined;
731
803
  /**
732
804
  * Gets/sets the template used to render the component.
733
805
  * @remarks
@@ -742,6 +814,13 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
742
814
  get mainStyles(): ElementStyles | null;
743
815
  set mainStyles(value: ElementStyles | null);
744
816
  /* Excluded from this release type: __constructor */
817
+ /**
818
+ * Registers an unbind handler with the controller.
819
+ * @param behavior - An object to call when the controller unbinds.
820
+ */
821
+ onUnbind(behavior: {
822
+ unbind(controller: ExpressionController<TElement>): any;
823
+ }): void;
745
824
  /**
746
825
  * Adds the behavior to the component.
747
826
  * @param behavior - The behavior to add.
@@ -787,7 +866,6 @@ export declare class ElementController<TElement extends HTMLElement = HTMLElemen
787
866
  * Only emits events if connected.
788
867
  */
789
868
  emit(type: string, detail?: any, options?: Omit<CustomEventInit, "detail">): void | boolean;
790
- /* Excluded from this release type: toJSON */
791
869
  private renderTemplate;
792
870
  /**
793
871
  * Locates or creates a controller for the specified element.
@@ -884,6 +962,17 @@ export declare class ElementStyles {
884
962
  * @public
885
963
  */
886
964
  export declare interface ElementView<TSource = any, TParent = any> extends View<TSource, TParent> {
965
+ /**
966
+ * Indicates how the source's lifetime relates to the controller's lifetime.
967
+ */
968
+ readonly sourceLifetime?: SourceLifetime;
969
+ /**
970
+ * Registers an unbind handler with the controller.
971
+ * @param behavior - An object to call when the controller unbinds.
972
+ */
973
+ onUnbind(behavior: {
974
+ unbind(controller: ViewController<TSource, TParent>): any;
975
+ }): void;
887
976
  /**
888
977
  * Appends the view's DOM nodes to the referenced node.
889
978
  * @param node - The parent node to append the view's DOM nodes to.
@@ -1291,11 +1380,7 @@ export declare interface HostBehavior<TSource = any> {
1291
1380
  * associated with a component host.
1292
1381
  * @public
1293
1382
  */
1294
- export declare interface HostController<TSource = any> {
1295
- /**
1296
- * The component source.
1297
- */
1298
- readonly source: TSource;
1383
+ export declare interface HostController<TSource = any> extends ExpressionController<TSource> {
1299
1384
  /**
1300
1385
  * Indicates whether the host is connected or not.
1301
1386
  */
@@ -1343,7 +1428,7 @@ export declare const html: HTMLTemplateTag;
1343
1428
  * A directive that applies bindings.
1344
1429
  * @public
1345
1430
  */
1346
- export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, ViewBehavior, Aspected {
1431
+ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, ViewBehavior, Aspected, BindingDirective {
1347
1432
  dataBinding: Binding;
1348
1433
  private data;
1349
1434
  private updateTarget;
@@ -1612,7 +1697,6 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
1612
1697
  * Unbinds a view's behaviors from its binding source.
1613
1698
  */
1614
1699
  unbind(): void;
1615
- /* Excluded from this release type: toJSON */
1616
1700
  private evaluateUnbindables;
1617
1701
  /**
1618
1702
  * Efficiently disposes of a contiguous range of synthetic view instances.
@@ -1938,6 +2022,16 @@ export declare interface ObservationRecord {
1938
2022
  */
1939
2023
  export declare function oneTime<T = any>(expression: Expression<T>, policy?: DOMPolicy): Binding<T>;
1940
2024
 
2025
+ /**
2026
+ * Creates an standard binding.
2027
+ * @param expression - The binding to refresh when changed.
2028
+ * @param policy - The security policy to associate with th binding.
2029
+ * @param isVolatile - Indicates whether the binding is volatile or not.
2030
+ * @returns A binding configuration.
2031
+ * @public
2032
+ */
2033
+ export declare function oneWay<T = any>(expression: Expression<T>, policy?: DOMPolicy, isVolatile?: boolean): Binding<T>;
2034
+
1941
2035
  /**
1942
2036
  * Common APIs related to content parsing.
1943
2037
  * @public
@@ -2127,7 +2221,7 @@ export declare class RepeatBehavior<TSource = any> implements ViewBehavior, Subs
2127
2221
  * A directive that configures list rendering.
2128
2222
  * @public
2129
2223
  */
2130
- export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
2224
+ export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory, BindingDirective {
2131
2225
  readonly dataBinding: Binding<TSource>;
2132
2226
  readonly templateBinding: Binding<TSource, SyntheticViewTemplate>;
2133
2227
  readonly options: RepeatOptions;
@@ -2400,7 +2494,6 @@ export declare type SpliceStrategySupport = typeof SpliceStrategySupport[keyof t
2400
2494
  */
2401
2495
  export declare abstract class StatelessAttachedAttributeDirective<TOptions> implements HTMLDirective, ViewBehaviorFactory, ViewBehavior {
2402
2496
  protected options: TOptions;
2403
- /* Excluded from this release type: toJSON */
2404
2497
  /**
2405
2498
  * Creates an instance of RefDirective.
2406
2499
  * @param options - The options to use in configuring the directive.
@@ -2603,10 +2696,6 @@ export declare type TrustedTypesPolicy = {
2603
2696
  createHTML(html: string): string;
2604
2697
  };
2605
2698
 
2606
- /* Excluded from this release type: TypeDefinition */
2607
-
2608
- /* Excluded from this release type: TypeRegistry */
2609
-
2610
2699
  /**
2611
2700
  * A work queue used to synchronize writes to the DOM.
2612
2701
  * @public
@@ -2679,6 +2768,10 @@ export declare interface View<TSource = any, TParent = any> extends Disposable {
2679
2768
  * The data that the view is bound to.
2680
2769
  */
2681
2770
  readonly source: TSource | null;
2771
+ /**
2772
+ * Indicates whether the controller is bound.
2773
+ */
2774
+ readonly isBound: boolean;
2682
2775
  /**
2683
2776
  * Binds a view's behaviors to its binding source.
2684
2777
  * @param source - The binding source for the view's binding behaviors.
@@ -2798,7 +2891,6 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
2798
2891
  * host that the template is being attached to.
2799
2892
  */
2800
2893
  render(source: TSource, host: Node, hostBindingTarget?: Element): HTMLView<TSource, TParent>;
2801
- /* Excluded from this release type: toJSON */
2802
2894
  /**
2803
2895
  * Creates a template based on a set of static strings and dynamic values.
2804
2896
  * @param strings - The static strings to create the template with.