@microsoft/fast-element 2.0.0-beta.6 → 2.0.0-beta.7

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 (64) hide show
  1. package/CHANGELOG.json +57 -0
  2. package/CHANGELOG.md +16 -1
  3. package/dist/dts/components/attributes.d.ts +10 -0
  4. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +24 -25
  5. package/dist/dts/components/fast-definitions.d.ts +28 -3
  6. package/dist/dts/components/fast-element.d.ts +2 -2
  7. package/dist/dts/di/di.d.ts +41 -0
  8. package/dist/dts/index.d.ts +2 -2
  9. package/dist/dts/observation/observable.d.ts +86 -47
  10. package/dist/dts/pending-task.d.ts +20 -0
  11. package/dist/dts/platform.d.ts +6 -0
  12. package/dist/dts/styles/css-directive.d.ts +2 -2
  13. package/dist/dts/styles/element-styles.d.ts +3 -3
  14. package/dist/dts/styles/host.d.ts +68 -0
  15. package/dist/dts/templating/binding-signal.d.ts +2 -2
  16. package/dist/dts/templating/binding-two-way.d.ts +11 -3
  17. package/dist/dts/templating/binding.d.ts +21 -119
  18. package/dist/dts/templating/children.d.ts +1 -1
  19. package/dist/dts/templating/html-directive.d.ts +69 -39
  20. package/dist/dts/templating/node-observation.d.ts +4 -5
  21. package/dist/dts/templating/ref.d.ts +5 -13
  22. package/dist/dts/templating/render.d.ts +15 -20
  23. package/dist/dts/templating/repeat.d.ts +11 -16
  24. package/dist/dts/templating/slotted.d.ts +1 -1
  25. package/dist/dts/templating/template.d.ts +4 -4
  26. package/dist/dts/templating/view.d.ts +68 -9
  27. package/dist/dts/templating/when.d.ts +1 -1
  28. package/dist/dts/testing/exports.d.ts +1 -0
  29. package/dist/dts/testing/fakes.d.ts +4 -0
  30. package/dist/dts/testing/fixture.d.ts +0 -6
  31. package/dist/esm/components/attributes.js +13 -4
  32. package/dist/esm/components/{controller.js → element-controller.js} +95 -105
  33. package/dist/esm/components/fast-definitions.js +3 -1
  34. package/dist/esm/components/fast-element.js +4 -4
  35. package/dist/esm/di/di.js +87 -3
  36. package/dist/esm/index.js +2 -1
  37. package/dist/esm/observation/observable.js +59 -126
  38. package/dist/esm/pending-task.js +16 -0
  39. package/dist/esm/platform.js +21 -0
  40. package/dist/esm/styles/css.js +4 -4
  41. package/dist/esm/{observation/behavior.js → styles/host.js} +0 -0
  42. package/dist/esm/templating/binding-signal.js +21 -17
  43. package/dist/esm/templating/binding-two-way.js +32 -27
  44. package/dist/esm/templating/binding.js +73 -177
  45. package/dist/esm/templating/html-directive.js +78 -7
  46. package/dist/esm/templating/node-observation.js +9 -8
  47. package/dist/esm/templating/ref.js +4 -12
  48. package/dist/esm/templating/render.js +30 -31
  49. package/dist/esm/templating/repeat.js +37 -38
  50. package/dist/esm/templating/template.js +3 -4
  51. package/dist/esm/templating/view.js +96 -24
  52. package/dist/esm/testing/exports.js +1 -0
  53. package/dist/esm/testing/fakes.js +76 -0
  54. package/dist/esm/testing/fixture.js +1 -3
  55. package/dist/fast-element.api.json +5720 -5385
  56. package/dist/fast-element.d.ts +510 -399
  57. package/dist/fast-element.debug.js +492 -509
  58. package/dist/fast-element.debug.min.js +1 -1
  59. package/dist/fast-element.js +492 -509
  60. package/dist/fast-element.min.js +1 -1
  61. package/dist/fast-element.untrimmed.d.ts +519 -405
  62. package/docs/api-report.md +197 -129
  63. package/package.json +5 -1
  64. package/dist/dts/observation/behavior.d.ts +0 -19
@@ -1,8 +1,7 @@
1
- import type { Behavior } from "../observation/behavior.js";
2
1
  import type { Subscriber } from "../observation/notifier.js";
3
- import { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
2
+ import { Expression, ExpressionObserver } from "../observation/observable.js";
4
3
  import { Splice } from "../observation/arrays.js";
5
- import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
4
+ import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
6
5
  import type { CaptureType, SyntheticViewTemplate, ViewTemplate } from "./template.js";
7
6
  /**
8
7
  * Options for configuring repeat behavior.
@@ -22,18 +21,16 @@ export interface RepeatOptions {
22
21
  * A behavior that renders a template for each item in an array.
23
22
  * @public
24
23
  */
25
- export declare class RepeatBehavior<TSource = any> implements Behavior, Subscriber {
24
+ export declare class RepeatBehavior<TSource = any> implements ViewBehavior, Subscriber {
26
25
  private directive;
27
26
  private location;
28
- private source;
27
+ private controller;
29
28
  private views;
30
29
  private template;
31
30
  private templateBindingObserver;
32
31
  private items;
33
32
  private itemsObserver;
34
33
  private itemsBindingObserver;
35
- private context;
36
- private childContext;
37
34
  private bindView;
38
35
  /**
39
36
  * Creates an instance of RepeatBehavior.
@@ -44,16 +41,14 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
44
41
  * @param isTemplateBindingVolatile - Indicates whether the template binding has volatile dependencies.
45
42
  * @param options - Options used to turn on special repeat features.
46
43
  */
47
- constructor(directive: RepeatDirective, location: Node);
44
+ constructor(directive: RepeatDirective);
48
45
  /**
49
- * Bind this behavior to the source.
50
- * @param source - The source to bind to.
51
- * @param context - The execution context that the binding is operating within.
46
+ * Bind this behavior.
47
+ * @param controller - The view controller that manages the lifecycle of this behavior.
52
48
  */
53
- bind(source: TSource, context: ExecutionContext): void;
49
+ bind(controller: ViewController): void;
54
50
  /**
55
- * Unbinds this behavior from the source.
56
- * @param source - The source to unbind from.
51
+ * Unbinds this behavior.
57
52
  */
58
53
  unbind(): void;
59
54
  /**
@@ -99,7 +94,7 @@ export declare class RepeatDirective<TSource = any> implements HTMLDirective, Vi
99
94
  * Creates a behavior for the provided target node.
100
95
  * @param target - The node instance to create the behavior for.
101
96
  */
102
- createBehavior(targets: ViewBehaviorTargets): RepeatBehavior<TSource>;
97
+ createBehavior(): RepeatBehavior<TSource>;
103
98
  }
104
99
  /**
105
100
  * A directive that enables list rendering.
@@ -109,4 +104,4 @@ export declare class RepeatDirective<TSource = any> implements HTMLDirective, Vi
109
104
  * @param options - Options used to turn on special repeat features.
110
105
  * @public
111
106
  */
112
- export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(items: Expression<TSource, TArray, ExecutionContext<TSource>> | Binding<TSource, TArray> | ReadonlyArray<any>, template: Expression<TSource, ViewTemplate> | Binding<TSource, ViewTemplate> | ViewTemplate, options?: RepeatOptions): CaptureType<TSource>;
107
+ export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>, TParent = any>(items: Expression<TSource, TArray, TParent> | Binding<TSource, TArray, TParent> | ReadonlyArray<any>, template: Expression<TSource, ViewTemplate<any, TSource>> | Binding<TSource, ViewTemplate<any, TSource>> | ViewTemplate<any, TSource>, options?: RepeatOptions): CaptureType<TSource, TParent>;
@@ -35,4 +35,4 @@ export declare class SlottedDirective extends NodeObservationDirective<SlottedDi
35
35
  * @param propertyOrOptions - The options used to configure slotted node observation.
36
36
  * @public
37
37
  */
38
- export declare function slotted<T = any>(propertyOrOptions: (keyof T & string) | SlottedDirectiveOptions<keyof T & string>): CaptureType<T>;
38
+ export declare function slotted<TSource = any, TParent = any>(propertyOrOptions: (keyof TSource & string) | SlottedDirectiveOptions<keyof TSource & string>): CaptureType<TSource, TParent>;
@@ -1,4 +1,4 @@
1
- import { ExecutionContext, Expression } from "../observation/observable.js";
1
+ import type { Expression } from "../observation/observable.js";
2
2
  import { Binding, HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
3
3
  import type { ElementView, HTMLView, SyntheticView } from "./view.js";
4
4
  /**
@@ -74,20 +74,20 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
74
74
  * @param hostBindingTarget - An HTML element to target the host bindings at if different from the
75
75
  * host that the template is being attached to.
76
76
  */
77
- render(source: TSource, host: Node, hostBindingTarget?: Element, context?: ExecutionContext): HTMLView<TSource, TParent>;
77
+ render(source: TSource, host: Node, hostBindingTarget?: Element): HTMLView<TSource, TParent>;
78
78
  }
79
79
  /**
80
80
  * A marker interface used to capture types when interpolating Directive helpers
81
81
  * into templates.
82
82
  * @public
83
83
  */
84
- export interface CaptureType<TSource> {
84
+ export interface CaptureType<TSource, TParent> {
85
85
  }
86
86
  /**
87
87
  * Represents the types of values that can be interpolated into a template.
88
88
  * @public
89
89
  */
90
- export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource>;
90
+ export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
91
91
  /**
92
92
  * Transforms a template literal string into a ViewTemplate.
93
93
  * @param strings - The string fragments that are interpolated with the values.
@@ -1,6 +1,6 @@
1
1
  import type { Disposable } from "../interfaces.js";
2
- import type { ExecutionContext } from "../observation/observable.js";
3
- import type { ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
2
+ import { ExecutionContext } from "../observation/observable.js";
3
+ import type { ViewBehaviorFactory, ViewBehaviorTargets, ViewController } from "./html-directive.js";
4
4
  /**
5
5
  * Represents a collection of DOM nodes which can be bound to a data source.
6
6
  * @public
@@ -9,7 +9,7 @@ export interface View<TSource = any, TParent = any> extends Disposable {
9
9
  /**
10
10
  * The execution context the view is running within.
11
11
  */
12
- readonly context: ExecutionContext<TParent> | null;
12
+ readonly context: ExecutionContext<TParent>;
13
13
  /**
14
14
  * The data that the view is bound to.
15
15
  */
@@ -17,9 +17,8 @@ export interface View<TSource = any, TParent = any> extends Disposable {
17
17
  /**
18
18
  * Binds a view's behaviors to its binding source.
19
19
  * @param source - The binding source for the view's binding behaviors.
20
- * @param context - The execution context to run the view within.
21
20
  */
22
- bind(source: TSource, context: ExecutionContext<TParent>): void;
21
+ bind(source: TSource): void;
23
22
  /**
24
23
  * Unbinds a view's behaviors from its binding source and context.
25
24
  */
@@ -64,19 +63,75 @@ export interface SyntheticView<TSource = any, TParent = any> extends View<TSourc
64
63
  * The standard View implementation, which also implements ElementView and SyntheticView.
65
64
  * @public
66
65
  */
67
- export declare class HTMLView<TSource = any, TParent = any> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent> {
66
+ export declare class HTMLView<TSource = any, TParent = any> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent>, ExecutionContext<TParent> {
68
67
  private fragment;
69
68
  private factories;
70
- private targets;
69
+ readonly targets: ViewBehaviorTargets;
71
70
  private behaviors;
71
+ private unbindables;
72
72
  /**
73
73
  * The data that the view is bound to.
74
74
  */
75
75
  source: TSource | null;
76
+ isBound: boolean;
77
+ selfContained: boolean;
76
78
  /**
77
79
  * The execution context the view is running within.
78
80
  */
79
- context: ExecutionContext<TParent> | null;
81
+ get context(): ExecutionContext<TParent>;
82
+ /**
83
+ * The index of the current item within a repeat context.
84
+ */
85
+ index: number;
86
+ /**
87
+ * The length of the current collection within a repeat context.
88
+ */
89
+ length: number;
90
+ /**
91
+ * The parent data source within a nested context.
92
+ */
93
+ readonly parent: TParent;
94
+ /**
95
+ * The parent execution context when in nested context scenarios.
96
+ */
97
+ readonly parentContext: ExecutionContext<TParent>;
98
+ /**
99
+ * The current event within an event handler.
100
+ */
101
+ get event(): Event;
102
+ /**
103
+ * Indicates whether the current item within a repeat context
104
+ * has an even index.
105
+ */
106
+ get isEven(): boolean;
107
+ /**
108
+ * Indicates whether the current item within a repeat context
109
+ * has an odd index.
110
+ */
111
+ get isOdd(): boolean;
112
+ /**
113
+ * Indicates whether the current item within a repeat context
114
+ * is the first item in the collection.
115
+ */
116
+ get isFirst(): boolean;
117
+ /**
118
+ * Indicates whether the current item within a repeat context
119
+ * is somewhere in the middle of the collection.
120
+ */
121
+ get isInMiddle(): boolean;
122
+ /**
123
+ * Indicates whether the current item within a repeat context
124
+ * is the last item in the collection.
125
+ */
126
+ get isLast(): boolean;
127
+ /**
128
+ * Returns the typed event detail of a custom event.
129
+ */
130
+ eventDetail<TDetail>(): TDetail;
131
+ /**
132
+ * Returns the typed event target of the event.
133
+ */
134
+ eventTarget<TTarget extends EventTarget>(): TTarget;
80
135
  /**
81
136
  * The first DOM node in the range of nodes that make up the view.
82
137
  */
@@ -111,16 +166,20 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
111
166
  * Once a view has been disposed, it cannot be inserted or bound again.
112
167
  */
113
168
  dispose(): void;
169
+ onUnbind(behavior: {
170
+ unbind(controller: ViewController<TSource, TParent>): any;
171
+ }): void;
114
172
  /**
115
173
  * Binds a view's behaviors to its binding source.
116
174
  * @param source - The binding source for the view's binding behaviors.
117
175
  * @param context - The execution context to run the behaviors within.
118
176
  */
119
- bind(source: TSource, context: ExecutionContext<TParent>): void;
177
+ bind(source: TSource): void;
120
178
  /**
121
179
  * Unbinds a view's behaviors from its binding source.
122
180
  */
123
181
  unbind(): void;
182
+ private evaluateUnbindables;
124
183
  /**
125
184
  * Efficiently disposes of a contiguous range of synthetic view instances.
126
185
  * @param views - A contiguous range of views to be disposed.
@@ -7,4 +7,4 @@ import type { CaptureType, SyntheticViewTemplate } from "./template.js";
7
7
  * the template to render when the condition is true.
8
8
  * @public
9
9
  */
10
- export declare function when<TSource = any, TReturn = any>(condition: Expression<TSource, TReturn> | boolean, templateOrTemplateBinding: SyntheticViewTemplate | Expression<TSource, SyntheticViewTemplate>): CaptureType<TSource>;
10
+ export declare function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType<TSource, TParent>;
@@ -1,2 +1,3 @@
1
1
  export { timeout } from "./timeout.js";
2
2
  export * from "./fixture.js";
3
+ export * from "./fakes.js";
@@ -0,0 +1,4 @@
1
+ import { ExecutionContext } from "../index.js";
2
+ export declare const Fake: Readonly<{
3
+ executionContext<TParent = any>(parent?: TParent | undefined, parentContext?: ExecutionContext<TParent> | undefined): ExecutionContext<TParent>;
4
+ }>;
@@ -1,5 +1,4 @@
1
1
  import type { Constructable } from "../interfaces.js";
2
- import { ExecutionContext } from "../observation/observable.js";
3
2
  import { ViewTemplate } from "../templating/template.js";
4
3
  import type { HTMLView } from "../templating/view.js";
5
4
  /**
@@ -22,11 +21,6 @@ export interface FixtureOptions {
22
21
  * @defaultValue An empty object.
23
22
  */
24
23
  source?: any;
25
- /**
26
- * The execution context to use during binding.
27
- * @defaultValue {@link @microsoft/fast-element#ExecutionContext}
28
- */
29
- context?: ExecutionContext;
30
24
  }
31
25
  /**
32
26
  * A test fixture.
@@ -2,8 +2,19 @@ import { Observable } from "../observation/observable.js";
2
2
  import { isString } from "../interfaces.js";
3
3
  import { Updates } from "../observation/update-queue.js";
4
4
  import { DOM } from "../templating/dom.js";
5
+ import { createMetadataLocator } from "../platform.js";
5
6
  const booleanMode = "boolean";
6
7
  const reflectMode = "reflect";
8
+ /**
9
+ * Metadata used to configure a custom attribute's behavior.
10
+ * @public
11
+ */
12
+ export const AttributeConfiguration = Object.freeze({
13
+ /**
14
+ * Locates all attribute configurations associated with a type.
15
+ */
16
+ locate: createMetadataLocator(),
17
+ });
7
18
  /**
8
19
  * A {@link ValueConverter} that converts to and from `boolean` values.
9
20
  * @remarks
@@ -141,7 +152,7 @@ export class AttributeDefinition {
141
152
  */
142
153
  static collect(Owner, ...attributeLists) {
143
154
  const attributes = [];
144
- attributeLists.push(Owner.attributes);
155
+ attributeLists.push(AttributeConfiguration.locate(Owner));
145
156
  for (let i = 0, ii = attributeLists.length; i < ii; ++i) {
146
157
  const list = attributeLists[i];
147
158
  if (list === void 0) {
@@ -171,9 +182,7 @@ export function attr(configOrTarget, prop) {
171
182
  // - @attr({...opts})
172
183
  config.property = $prop;
173
184
  }
174
- const attributes = $target.constructor.attributes ||
175
- ($target.constructor.attributes = []);
176
- attributes.push(config);
185
+ AttributeConfiguration.locate($target.constructor).push(config);
177
186
  }
178
187
  if (arguments.length > 1) {
179
188
  // Non invocation: