@microsoft/fast-element 2.0.0-beta.1 → 2.0.0-beta.4

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 (58) hide show
  1. package/CHANGELOG.json +147 -0
  2. package/CHANGELOG.md +42 -1
  3. package/dist/dts/components/fast-definitions.d.ts +11 -8
  4. package/dist/dts/components/fast-element.d.ts +13 -3
  5. package/dist/dts/context.d.ts +157 -0
  6. package/dist/dts/di/di.d.ts +854 -0
  7. package/dist/dts/hooks.d.ts +2 -2
  8. package/dist/dts/interfaces.d.ts +39 -7
  9. package/dist/dts/metadata.d.ts +25 -0
  10. package/dist/dts/observation/arrays.d.ts +1 -1
  11. package/dist/dts/observation/behavior.d.ts +4 -4
  12. package/dist/dts/observation/observable.d.ts +59 -72
  13. package/dist/dts/styles/element-styles.d.ts +6 -0
  14. package/dist/dts/templating/binding-signal.d.ts +21 -0
  15. package/dist/dts/templating/binding-two-way.d.ts +31 -0
  16. package/dist/dts/templating/binding.d.ts +74 -201
  17. package/dist/dts/templating/compiler.d.ts +1 -2
  18. package/dist/dts/templating/html-directive.d.ts +31 -3
  19. package/dist/dts/templating/render.d.ts +277 -0
  20. package/dist/dts/templating/repeat.d.ts +13 -63
  21. package/dist/dts/templating/template.d.ts +11 -60
  22. package/dist/dts/templating/view.d.ts +9 -9
  23. package/dist/dts/templating/when.d.ts +3 -3
  24. package/dist/dts/testing/exports.d.ts +2 -0
  25. package/dist/dts/testing/fixture.d.ts +90 -0
  26. package/dist/dts/testing/timeout.d.ts +7 -0
  27. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
  28. package/dist/esm/components/fast-definitions.js +27 -27
  29. package/dist/esm/components/fast-element.js +20 -4
  30. package/dist/esm/context.js +163 -0
  31. package/dist/esm/debug.js +35 -4
  32. package/dist/esm/di/di.js +1349 -0
  33. package/dist/esm/metadata.js +60 -0
  34. package/dist/esm/observation/arrays.js +1 -1
  35. package/dist/esm/observation/observable.js +73 -21
  36. package/dist/esm/platform.js +1 -1
  37. package/dist/esm/styles/element-styles.js +14 -0
  38. package/dist/esm/templating/binding-signal.js +79 -0
  39. package/dist/esm/templating/binding-two-way.js +98 -0
  40. package/dist/esm/templating/binding.js +137 -313
  41. package/dist/esm/templating/compiler.js +30 -7
  42. package/dist/esm/templating/html-directive.js +16 -2
  43. package/dist/esm/templating/render.js +392 -0
  44. package/dist/esm/templating/repeat.js +60 -38
  45. package/dist/esm/templating/template.js +9 -26
  46. package/dist/esm/templating/when.js +5 -4
  47. package/dist/esm/testing/exports.js +2 -0
  48. package/dist/esm/testing/fixture.js +88 -0
  49. package/dist/esm/testing/timeout.js +24 -0
  50. package/dist/fast-element.api.json +8509 -10358
  51. package/dist/fast-element.d.ts +315 -522
  52. package/dist/fast-element.debug.js +417 -438
  53. package/dist/fast-element.debug.min.js +1 -1
  54. package/dist/fast-element.js +382 -434
  55. package/dist/fast-element.min.js +1 -1
  56. package/dist/fast-element.untrimmed.d.ts +324 -529
  57. package/docs/api-report.md +124 -232
  58. package/package.json +32 -4
@@ -1,56 +1,5 @@
1
- import { Binding, BindingObserver, ExecutionContext } from "../observation/observable.js";
2
- import { AddViewBehaviorFactory, Aspect, Aspected, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
3
- import type { CaptureType } from "./template.js";
4
- /**
5
- * Describes how aspects of an HTML element will be affected by bindings.
6
- * @public
7
- */
8
- export declare type BindingMode = Record<Aspect, (directive: HTMLBindingDirective) => Pick<ViewBehaviorFactory, "createBehavior">>;
9
- /**
10
- * Describes how aspects of an HTML element will be affected by bindings.
11
- * @public
12
- */
13
- export declare const BindingMode: Readonly<{
14
- /**
15
- * Creates a binding mode based on the supplied behavior types.
16
- * @param UpdateType - The base behavior type used to update aspects.
17
- * @param EventType - The base behavior type used to respond to events.
18
- * @returns A new binding mode.
19
- */
20
- define(UpdateType: typeof UpdateBinding, EventType?: typeof EventBinding): BindingMode;
21
- }>;
22
- /**
23
- * Describes the configuration for a binding expression.
24
- * @public
25
- */
26
- export interface BindingConfig<T = any> {
27
- /**
28
- * The binding mode to configure the binding with.
29
- */
30
- mode: BindingMode;
31
- /**
32
- * Options to be supplied to the binding behaviors.
33
- */
34
- options: T;
35
- }
36
- /**
37
- * Creates a new binding configuration based on the supplied options.
38
- * @public
39
- */
40
- export declare type BindingConfigResolver<T> = (options: T) => BindingConfig<T>;
41
- /**
42
- * Describes the configuration for a binding expression.
43
- * @public
44
- */
45
- export declare const BindingConfig: Readonly<{
46
- /**
47
- * Creates a binding configuration based on the provided mode and options.
48
- * @param mode - The mode to use for the configuration.
49
- * @param defaultOptions - The default options to use for the configuration.
50
- * @returns A new binding configuration.
51
- */
52
- define<T>(mode: BindingMode, defaultOptions: T): BindingConfig<T> & BindingConfigResolver<T>;
53
- }>;
1
+ import { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
2
+ import { AddViewBehaviorFactory, Aspect, Aspected, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
54
3
  /**
55
4
  * The "this" context for an update target function.
56
5
  * @public
@@ -73,57 +22,55 @@ export interface UpdateTargetThis {
73
22
  */
74
23
  export declare type UpdateTarget = (this: UpdateTargetThis, target: Node, aspect: string, value: any, source: any, context: ExecutionContext) => void;
75
24
  /**
76
- * A base binding behavior for DOM updates.
25
+ * A simple View that can be interpolated into HTML content.
77
26
  * @public
78
27
  */
79
- export declare class UpdateBinding implements ViewBehavior {
80
- readonly directive: HTMLBindingDirective;
81
- protected updateTarget: UpdateTarget;
28
+ export interface ContentView {
82
29
  /**
83
- * Creates an instance of UpdateBinding.
84
- * @param directive - The directive that has the configuration for this behavior.
85
- * @param updateTarget - The function used to update the target with the latest value.
30
+ * Binds a view's behaviors to its binding source.
31
+ * @param source - The binding source for the view's binding behaviors.
32
+ * @param context - The execution context to run the view within.
86
33
  */
87
- constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
34
+ bind(source: any, context: ExecutionContext): void;
88
35
  /**
89
- * Bind this behavior to the source.
90
- * @param source - The source to bind to.
91
- * @param context - The execution context that the binding is operating within.
92
- * @param targets - The targets that behaviors in a view can attach to.
36
+ * Unbinds a view's behaviors from its binding source and context.
93
37
  */
94
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
38
+ unbind(): void;
95
39
  /**
96
- * Unbinds this behavior from the source.
97
- * @param source - The source to unbind from.
98
- * @param context - The execution context that the binding is operating within.
99
- * @param targets - The targets that behaviors in a view can attach to.
40
+ * Inserts the view's DOM nodes before the referenced node.
41
+ * @param node - The node to insert the view's DOM before.
100
42
  */
101
- unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
43
+ insertBefore(node: Node): void;
102
44
  /**
103
- * Creates a behavior.
104
- * @param targets - The targets available for behaviors to be attached to.
45
+ * Removes the view's DOM nodes.
46
+ * The nodes are not disposed and the view can later be re-inserted.
105
47
  */
106
- createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
48
+ remove(): void;
107
49
  }
108
50
  /**
109
- * A binding behavior for one-time bindings.
51
+ * A simple template that can create ContentView instances.
110
52
  * @public
111
53
  */
112
- export declare class OneTimeBinding extends UpdateBinding {
54
+ export interface ContentTemplate {
113
55
  /**
114
- * Bind this behavior to the source.
115
- * @param source - The source to bind to.
116
- * @param context - The execution context that the binding is operating within.
117
- * @param targets - The targets that behaviors in a view can attach to.
56
+ * Creates a simple content view instance.
118
57
  */
119
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
58
+ create(): ContentView;
120
59
  }
121
60
  /**
122
- * A binding behavior for signal bindings.
61
+ * A binding behavior for bindings that change.
123
62
  * @public
124
63
  */
125
- export declare class SignalBinding extends UpdateBinding {
126
- private handlerProperty;
64
+ export declare class BindingBehavior implements ViewBehavior {
65
+ readonly directive: HTMLBindingDirective;
66
+ protected updateTarget: UpdateTarget;
67
+ private observerProperty;
68
+ /**
69
+ * Creates an instance of ChangeBinding.
70
+ * @param directive - The directive that has the configuration for this behavior.
71
+ * @param updateTarget - The function used to update the target with the latest value.
72
+ */
73
+ constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
127
74
  /**
128
75
  * Bind this behavior to the source.
129
76
  * @param source - The source to bind to.
@@ -138,40 +85,25 @@ export declare class SignalBinding extends UpdateBinding {
138
85
  * @param targets - The targets that behaviors in a view can attach to.
139
86
  */
140
87
  unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
141
- private getSignal;
142
- /**
143
- * Sends the specified signal to signaled bindings.
144
- * @param signal - The signal to send.
145
- * @public
146
- */
147
- static send(signal: string): void;
148
- }
149
- /**
150
- * A binding behavior for bindings that change.
151
- * @public
152
- */
153
- export declare class ChangeBinding extends UpdateBinding {
154
- private isBindingVolatile;
155
- private observerProperty;
156
- /**
157
- * Creates an instance of ChangeBinding.
158
- * @param directive - The directive that has the configuration for this behavior.
159
- * @param updateTarget - The function used to update the target with the latest value.
160
- */
161
- constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
88
+ /** @internal */
89
+ handleChange(binding: Expression, observer: ExpressionObserver): void;
162
90
  /**
163
91
  * Returns the binding observer used to update the node.
164
92
  * @param target - The target node.
165
93
  * @returns A BindingObserver.
166
94
  */
167
- protected getObserver(target: Node): BindingObserver;
95
+ protected getObserver(target: Node): ExpressionObserver;
168
96
  /**
169
- * Bind this behavior to the source.
170
- * @param source - The source to bind to.
171
- * @param context - The execution context that the binding is operating within.
172
- * @param targets - The targets that behaviors in a view can attach to.
97
+ * Creates a behavior.
98
+ * @param targets - The targets available for behaviors to be attached to.
173
99
  */
174
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
100
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
101
+ }
102
+ /**
103
+ * A special binding behavior that can bind node content.
104
+ * @public
105
+ */
106
+ export declare class ContentBehavior extends BindingBehavior {
175
107
  /**
176
108
  * Unbinds this behavior from the source.
177
109
  * @param source - The source to unbind from.
@@ -179,14 +111,12 @@ export declare class ChangeBinding extends UpdateBinding {
179
111
  * @param targets - The targets that behaviors in a view can attach to.
180
112
  */
181
113
  unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
182
- /** @internal */
183
- handleChange(binding: Binding, observer: BindingObserver): void;
184
114
  }
185
115
  /**
186
116
  * A binding behavior for handling events.
187
117
  * @public
188
118
  */
189
- export declare class EventBinding {
119
+ export declare class EventBehavior {
190
120
  readonly directive: HTMLBindingDirective;
191
121
  private contextProperty;
192
122
  private sourceProperty;
@@ -219,89 +149,12 @@ export declare class EventBinding {
219
149
  */
220
150
  handleEvent(event: Event): void;
221
151
  }
222
- /**
223
- * The settings required to enable two-way binding.
224
- * @public
225
- */
226
- export interface TwoWaySettings {
227
- /**
228
- * Determines which event to listen to, to detect changes in the view.
229
- * @param directive - The directive to determine the change event for.
230
- * @param target - The target element to determine the change event for.
231
- */
232
- determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
233
- }
234
- /**
235
- * A binding behavior for bindings that update in two directions.
236
- * @public
237
- */
238
- export declare class TwoWayBinding extends ChangeBinding {
239
- private changeEvent;
240
- /**
241
- * Bind this behavior to the source.
242
- * @param source - The source to bind to.
243
- * @param context - The execution context that the binding is operating within.
244
- * @param targets - The targets that behaviors in a view can attach to.
245
- */
246
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
247
- /**
248
- * Unbinds this behavior from the source.
249
- * @param source - The source to unbind from.
250
- * @param context - The execution context that the binding is operating within.
251
- * @param targets - The targets that behaviors in a view can attach to.
252
- */
253
- unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
254
- /** @internal */
255
- handleEvent(event: Event): void;
256
- /**
257
- * Configures two-way binding.
258
- * @param settings - The settings to use for the two-way binding system.
259
- */
260
- static configure(settings: TwoWaySettings): void;
261
- }
262
- /**
263
- * The default binding options.
264
- * @public
265
- */
266
- export declare type DefaultBindingOptions = AddEventListenerOptions;
267
- /**
268
- * The default onChange binding configuration.
269
- * @public
270
- */
271
- export declare const onChange: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
272
- /**
273
- * The default twoWay binding options.
274
- * @public
275
- */
276
- export declare type DefaultTwoWayBindingOptions = DefaultBindingOptions & {
277
- changeEvent?: string;
278
- fromView?: (value: any) => any;
279
- };
280
- /**
281
- * The default twoWay binding configuration.
282
- * @public
283
- */
284
- export declare const twoWay: BindingConfig<DefaultTwoWayBindingOptions> & BindingConfigResolver<DefaultTwoWayBindingOptions>;
285
- /**
286
- * The default onTime binding configuration.
287
- * @public
288
- */
289
- export declare const oneTime: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
290
- /**
291
- * Creates a signal binding configuration with the supplied options.
292
- * @param options - The signal name or a binding to use to retrieve the signal name.
293
- * @returns A binding configuration.
294
- * @public
295
- */
296
- export declare const signal: <T = any>(options: string | Binding<T, any, ExecutionContext<any>>) => BindingConfig<string | Binding<T, any, ExecutionContext<any>>>;
297
152
  /**
298
153
  * A directive that applies bindings.
299
154
  * @public
300
155
  */
301
156
  export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, Aspected {
302
- binding: Binding;
303
- mode: BindingMode;
304
- options: any;
157
+ dataBinding: Binding;
305
158
  private factory;
306
159
  /**
307
160
  * The unique id of the factory.
@@ -325,11 +178,9 @@ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehavior
325
178
  aspectType: Aspect;
326
179
  /**
327
180
  * Creates an instance of HTMLBindingDirective.
328
- * @param binding - The binding to apply.
329
- * @param mode - The binding mode to use when applying the binding.
330
- * @param options - The options to configure the binding with.
181
+ * @param dataBinding - The binding configuration to apply.
331
182
  */
332
- constructor(binding: Binding, mode: BindingMode, options: any);
183
+ constructor(dataBinding: Binding);
333
184
  /**
334
185
  * Creates HTML to be used within a template.
335
186
  * @param add - Can be used to add behavior factories to a template.
@@ -342,10 +193,32 @@ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehavior
342
193
  createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
343
194
  }
344
195
  /**
345
- * Creates a binding directive with the specified configuration.
346
- * @param binding - The binding expression.
347
- * @param config - The binding configuration.
348
- * @returns A binding directive.
196
+ * Creates an standard binding.
197
+ * @param binding - The binding to refresh when changed.
198
+ * @param isVolatile - Indicates whether the binding is volatile or not.
199
+ * @returns A binding configuration.
200
+ * @public
201
+ */
202
+ export declare function bind<T = any>(binding: Expression<T>, isVolatile?: boolean): Binding<T>;
203
+ /**
204
+ * Creates a one time binding
205
+ * @param binding - The binding to refresh when signaled.
206
+ * @returns A binding configuration.
207
+ * @public
208
+ */
209
+ export declare function oneTime<T = any>(binding: Expression<T>): Binding<T>;
210
+ /**
211
+ * Creates an event listener binding.
212
+ * @param binding - The binding to invoke when the event is raised.
213
+ * @param options - Event listener options.
214
+ * @returns A binding configuration.
215
+ * @public
216
+ */
217
+ export declare function listener<T = any>(binding: Expression<T>, options?: AddEventListenerOptions): Binding<T>;
218
+ /**
219
+ * Normalizes the input value into a binding.
220
+ * @param value - The value to create the default binding for.
221
+ * @returns A binding configuration for the provided value.
349
222
  * @public
350
223
  */
351
- export declare function bind<T = any>(binding: Binding<T>, config?: BindingConfig | DefaultBindingOptions): CaptureType<T>;
224
+ export declare function normalizeBinding<TSource = any, TReturn = any, TParent = any>(value: Expression<TSource, TReturn, TParent> | Binding<TSource, TReturn, TParent> | {}): Binding<TSource, TReturn, TParent>;
@@ -1,5 +1,4 @@
1
1
  import { TrustedTypesPolicy } from "../interfaces.js";
2
- import type { ExecutionContext } from "../observation/observable.js";
3
2
  import { ViewBehaviorFactory } from "./html-directive.js";
4
3
  import type { HTMLTemplateCompilationResult as TemplateCompilationResult } from "./template.js";
5
4
  /**
@@ -40,7 +39,7 @@ export declare const Compiler: {
40
39
  * it is recommended that you clone the original and pass the clone to this API.
41
40
  * @public
42
41
  */
43
- compile<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>>(html: string | HTMLTemplateElement, directives: Record<string, ViewBehaviorFactory>): TemplateCompilationResult<TSource, TParent, TContext>;
42
+ compile<TSource = any, TParent = any>(html: string | HTMLTemplateElement, directives: Record<string, ViewBehaviorFactory>): TemplateCompilationResult<TSource, TParent>;
44
43
  /**
45
44
  * Sets the default compilation strategy that will be used by the ViewTemplate whenever
46
45
  * it needs to compile a view preprocessed with the html template function.
@@ -1,6 +1,7 @@
1
1
  import type { Constructable } from "../interfaces.js";
2
2
  import type { Behavior } from "../observation/behavior.js";
3
- import type { Binding, ExecutionContext } from "../observation/observable.js";
3
+ import type { Subscriber } from "../observation/notifier.js";
4
+ import type { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
4
5
  /**
5
6
  * The target nodes available to a behavior.
6
7
  * @public
@@ -113,6 +114,31 @@ export declare const HTMLDirective: Readonly<{
113
114
  * @public
114
115
  */
115
116
  export declare function htmlDirective(options?: PartialHTMLDirectiveDefinition): (type: Constructable<HTMLDirective>) => void;
117
+ /**
118
+ * Captures a binding expression along with related information and capabilities.
119
+ *
120
+ * @public
121
+ */
122
+ export declare abstract class Binding<TSource = any, TReturn = any, TParent = any> {
123
+ /**
124
+ * Options associated with the binding.
125
+ */
126
+ options?: any;
127
+ /**
128
+ * Whether or not the binding is volatile.
129
+ */
130
+ isVolatile?: boolean;
131
+ /**
132
+ * Evaluates the binding expression.
133
+ */
134
+ evaluate: Expression<TSource, TReturn, TParent>;
135
+ /**
136
+ * Creates an observer capable of notifying a subscriber when the output of a binding changes.
137
+ * @param directive - The HTML Directive to create the observer for.
138
+ * @param subscriber - The subscriber to changes in the binding.
139
+ */
140
+ abstract createObserver(directive: HTMLDirective, subscriber: Subscriber): ExpressionObserver<TSource, TReturn, TParent>;
141
+ }
116
142
  /**
117
143
  * The type of HTML aspect to target.
118
144
  * @public
@@ -150,8 +176,10 @@ export declare const Aspect: Readonly<{
150
176
  *
151
177
  * @param directive - The directive to assign the aspect to.
152
178
  * @param value - The value to base the aspect determination on.
179
+ * @remarks
180
+ * If a falsy value is provided, then the content aspect will be assigned.
153
181
  */
154
- readonly assign: (directive: Aspected, value: string) => void;
182
+ readonly assign: (directive: Aspected, value?: string) => void;
155
183
  }>;
156
184
  /**
157
185
  * The type of HTML aspect to target.
@@ -178,7 +206,7 @@ export interface Aspected {
178
206
  /**
179
207
  * A binding if one is associated with the aspect.
180
208
  */
181
- binding?: Binding;
209
+ dataBinding?: Binding;
182
210
  }
183
211
  /**
184
212
  * A base class used for attribute directives that don't need internal state.