@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,4 +1,4 @@
1
- import { BindingObserver } from "./observation/observable.js";
1
+ import { ExpressionNotifier } from "./observation/observable.js";
2
2
  /**
3
3
  * Functions used for getting and setting a stateful value.
4
4
  * @beta
@@ -17,4 +17,4 @@ export declare function useState<T>(value: T, deep?: boolean): State<T>;
17
17
  * @param action An action that is affected by state changes.
18
18
  * @returns A BindingObserver which can be used to dispose of the effect.
19
19
  */
20
- export declare function useEffect(action: () => void): BindingObserver;
20
+ export declare function useEffect(action: () => void): ExpressionNotifier;
@@ -13,6 +13,20 @@ export declare type Callable = typeof Function.prototype.call | {
13
13
  export declare type Constructable<T = {}> = {
14
14
  new (...args: any[]): T;
15
15
  };
16
+ /**
17
+ * Represents a class.
18
+ * @public
19
+ */
20
+ export declare type Class<T, C = {}> = C & {
21
+ /**
22
+ * The class's prototype;
23
+ */
24
+ readonly prototype: T;
25
+ /**
26
+ * The class's constructor.
27
+ */
28
+ new (...args: any[]): T;
29
+ };
16
30
  /**
17
31
  * Provides a mechanism for releasing resources.
18
32
  * @public
@@ -77,18 +91,21 @@ export interface FASTGlobal {
77
91
  /**
78
92
  * Sends a warning to the developer.
79
93
  * @param code - The warning code to send.
80
- * @param args - Args relevant for the warning.
94
+ * @param values - Values relevant for the warning message.
81
95
  */
82
- warn(code: number, ...args: any[]): void;
96
+ warn(code: number, values?: Record<string, any>): void;
83
97
  /**
84
98
  * Creates an error.
85
99
  * @param code - The error code to send.
86
- * @param args - Args relevant for the error.
100
+ * @param values - Values relevant for the error message.
87
101
  */
88
- error(code: number, ...args: any[]): Error;
102
+ error(code: number, values?: Record<string, any>): Error;
89
103
  /**
90
104
  * Adds debug messages for errors and warnings.
91
105
  * @param messages - The message dictionary to add.
106
+ * @remarks
107
+ * Message can include placeholders like $\{name\} which can be
108
+ * replaced by values passed at runtime.
92
109
  */
93
110
  addMessages(messages: Record<number, string>): void;
94
111
  }
@@ -101,8 +118,7 @@ export declare const enum KernelServiceId {
101
118
  observable = 2,
102
119
  contextEvent = 3,
103
120
  elementRegistry = 4,
104
- styleSheetStrategy = 5,
105
- developerChannel = 6
121
+ styleSheetStrategy = 5
106
122
  }
107
123
  /**
108
124
  * A node that can be targeted by styles.
@@ -154,7 +170,23 @@ export declare const enum Message {
154
170
  needsArrayObservation = 1101,
155
171
  onlySetHTMLPolicyOnce = 1201,
156
172
  bindingInnerHTMLRequiresTrustedTypes = 1202,
157
- missingElementDefinition = 1401
173
+ twoWayBindingRequiresObservables = 1203,
174
+ hostBindingWithoutHost = 1204,
175
+ unsupportedBindingBehavior = 1205,
176
+ missingElementDefinition = 1401,
177
+ noRegistrationForContext = 1501,
178
+ noFactoryForResolver = 1502,
179
+ invalidResolverStrategy = 1503,
180
+ cannotAutoregisterDependency = 1504,
181
+ cannotResolveKey = 1505,
182
+ cannotConstructNativeFunction = 1506,
183
+ cannotJITRegisterNonConstructor = 1507,
184
+ cannotJITRegisterIntrinsic = 1508,
185
+ cannotJITRegisterInterface = 1509,
186
+ invalidResolver = 1510,
187
+ invalidKey = 1511,
188
+ noDefaultResolver = 1512,
189
+ cyclicDependency = 1513
158
190
  }
159
191
  /**
160
192
  * @internal
@@ -0,0 +1,25 @@
1
+ import type { Constructable } from "./interfaces.js";
2
+ /**
3
+ * Provides basic metadata capabilities used by Context and Dependency Injection.
4
+ */
5
+ export declare const Metadata: Readonly<{
6
+ /**
7
+ * Gets the "design:paramtypes" metadata for the specified type.
8
+ * @param Type - The type to get the metadata for.
9
+ * @returns The metadata array or a frozen empty array if no metadata is found.
10
+ */
11
+ getDesignParamTypes: (Type: any) => any;
12
+ /**
13
+ * Gets the "annotation:paramtypes" metadata for the specified type.
14
+ * @param Type - The type to get the metadata for.
15
+ * @returns The metadata array or a frozen empty array if no metadata is found.
16
+ */
17
+ getAnnotationParamTypes: (Type: any) => any;
18
+ /**
19
+ *
20
+ * @param Type - Gets the "annotation:paramtypes" metadata for the specified type. If none is found,
21
+ * an empty, mutable metadata array is created and added.
22
+ * @returns The metadata array.
23
+ */
24
+ getOrCreateAnnotationParamTypes(Type: Constructable): any[];
25
+ }>;
@@ -204,4 +204,4 @@ export declare const ArrayObserver: Readonly<{
204
204
  * @returns The length of the array.
205
205
  * @public
206
206
  */
207
- export declare function length<T>(array: readonly T[]): number;
207
+ export declare function lengthOf<T>(array: readonly T[]): number;
@@ -1,19 +1,19 @@
1
- import type { ExecutionContext, RootContext } from "./observable.js";
1
+ import type { ExecutionContext } from "./observable.js";
2
2
  /**
3
3
  * Represents an object that can contribute behavior to a view or
4
4
  * element's bind/unbind operations.
5
5
  * @public
6
6
  */
7
- export interface Behavior<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = RootContext> {
7
+ export interface Behavior<TSource = any, TParent = any> {
8
8
  /**
9
9
  * Bind this behavior to the source.
10
10
  * @param source - The source to bind to.
11
11
  * @param context - The execution context that the binding is operating within.
12
12
  */
13
- bind(source: TSource, context: TContext): void;
13
+ bind(source: TSource, context: ExecutionContext<TParent>): void;
14
14
  /**
15
15
  * Unbinds this behavior from the source.
16
16
  * @param source - The source to unbind from.
17
17
  */
18
- unbind(source: TSource, context: TContext): void;
18
+ unbind(source: TSource, context: ExecutionContext<TParent>): void;
19
19
  }
@@ -23,10 +23,10 @@ export interface Accessor {
23
23
  }
24
24
  /**
25
25
  * The signature of an arrow function capable of being evaluated
26
- * as part of a template binding update.
26
+ * against source data and within an execution context.
27
27
  * @public
28
28
  */
29
- export declare type Binding<TSource = any, TReturn = any, TContext extends ExecutionContext = ExecutionContext> = (source: TSource, context: TContext) => TReturn;
29
+ export declare type Expression<TSource = any, TReturn = any, TParent = any> = (source: TSource, context: ExecutionContext<TParent>) => TReturn;
30
30
  /**
31
31
  * A record of observable property access.
32
32
  * @public
@@ -42,19 +42,25 @@ export interface ObservationRecord {
42
42
  propertyName: string;
43
43
  }
44
44
  /**
45
- * Enables evaluation of and subscription to a binding.
45
+ * Observes a binding for changes.
46
+ *
46
47
  * @public
47
48
  */
48
- export interface BindingObserver<TSource = any, TReturn = any, TParent = any> extends Notifier, Disposable {
49
+ export interface ExpressionObserver<TSource = any, TReturn = any, TParent = any> extends Disposable {
49
50
  /**
50
- * Begins observing the binding for the source and returns the current value.
51
- * @param source - The source that the binding is based on.
52
- * @param context - The execution context to execute the binding within.
53
- * @returns The value of the binding.
51
+ * Begins observing the binding.
52
+ * @param source - The source to pass to the binding.
53
+ * @param context - The context to pass to the binding.
54
54
  */
55
55
  observe(source: TSource, context?: ExecutionContext<TParent>): TReturn;
56
+ }
57
+ /**
58
+ * Enables evaluation of and subscription to a binding.
59
+ * @public
60
+ */
61
+ export interface ExpressionNotifier<TSource = any, TReturn = any, TParent = any> extends Notifier, ExpressionObserver<TSource, TReturn, TParent> {
56
62
  /**
57
- * Gets {@link ObservationRecord|ObservationRecords} that the {@link BindingObserver}
63
+ * Gets {@link ObservationRecord|ObservationRecords} that the {@link ExpressionNotifier}
58
64
  * is observing.
59
65
  */
60
66
  records(): IterableIterator<ObservationRecord>;
@@ -114,19 +120,19 @@ export declare const Observable: Readonly<{
114
120
  */
115
121
  getAccessors: (target: {}) => Accessor[];
116
122
  /**
117
- * Creates a {@link BindingObserver} that can watch the
118
- * provided {@link Binding} for changes.
123
+ * Creates a {@link ExpressionNotifier} that can watch the
124
+ * provided {@link Expression} for changes.
119
125
  * @param binding - The binding to observe.
120
126
  * @param initialSubscriber - An initial subscriber to changes in the binding value.
121
127
  * @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
122
128
  */
123
- binding<TSource = any, TReturn = any>(binding: Binding<TSource, TReturn, ExecutionContext<any>>, initialSubscriber?: Subscriber, isVolatileBinding?: boolean): BindingObserver<TSource, TReturn, any>;
129
+ binding<TSource = any, TReturn = any>(binding: Expression<TSource, TReturn, any>, initialSubscriber?: Subscriber, isVolatileBinding?: boolean): ExpressionNotifier<TSource, TReturn, any>;
124
130
  /**
125
131
  * Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
126
132
  * on every evaluation of the value.
127
133
  * @param binding - The binding to inspect.
128
134
  */
129
- isVolatileBinding<TSource_1 = any, TReturn_1 = any>(binding: Binding<TSource_1, TReturn_1, ExecutionContext<any>>): boolean;
135
+ isVolatileBinding<TSource_1 = any, TReturn_1 = any>(binding: Expression<TSource_1, TReturn_1, any>): boolean;
130
136
  }>;
131
137
  /**
132
138
  * Decorator: Defines an observable property on the target.
@@ -147,31 +153,19 @@ export declare function volatile(target: {}, name: string | Accessor, descriptor
147
153
  * Provides additional contextual information available to behaviors and expressions.
148
154
  * @public
149
155
  */
150
- export interface RootContext {
156
+ export declare class ExecutionContext<TParentSource = any> {
151
157
  /**
152
- * The current event within an event handler.
158
+ * The default execution context.
153
159
  */
154
- readonly event: Event;
160
+ static readonly default: ExecutionContext<any>;
155
161
  /**
156
- * Returns the typed event detail of a custom event.
162
+ * The index of the current item within a repeat context.
157
163
  */
158
- eventDetail<TDetail = any>(): TDetail;
164
+ index: number;
159
165
  /**
160
- * Returns the typed event target of the event.
166
+ * The length of the current collection within a repeat context.
161
167
  */
162
- eventTarget<TTarget extends EventTarget = EventTarget>(): TTarget;
163
- /**
164
- * Creates a new execution context descendent from the current context.
165
- * @param source - The source for the context if different than the parent.
166
- * @returns A child execution context.
167
- */
168
- createChildContext<TParentSource>(source: TParentSource): ChildContext<TParentSource>;
169
- }
170
- /**
171
- * Provides additional contextual information when inside a child template.
172
- * @public
173
- */
174
- export interface ChildContext<TParentSource = any> extends RootContext {
168
+ length: number;
175
169
  /**
176
170
  * The parent data source within a nested context.
177
171
  */
@@ -179,80 +173,73 @@ export interface ChildContext<TParentSource = any> extends RootContext {
179
173
  /**
180
174
  * The parent execution context when in nested context scenarios.
181
175
  */
182
- readonly parentContext: ChildContext<TParentSource>;
176
+ readonly parentContext: ExecutionContext<TParentSource>;
177
+ private constructor();
183
178
  /**
184
- * Creates a new execution context descent suitable for use in list rendering.
185
- * @param item - The list item to serve as the source.
186
- * @param index - The index of the item in the list.
187
- * @param length - The length of the list.
188
- */
189
- createItemContext(index: number, length: number): ItemContext<TParentSource>;
190
- }
191
- /**
192
- * Provides additional contextual information when inside a repeat item template.s
193
- * @public
194
- */
195
- export interface ItemContext<TParentSource = any> extends ChildContext<TParentSource> {
196
- /**
197
- * The index of the current item within a repeat context.
198
- */
199
- readonly index: number;
200
- /**
201
- * The length of the current collection within a repeat context.
179
+ * The current event within an event handler.
202
180
  */
203
- readonly length: number;
181
+ get event(): Event;
204
182
  /**
205
183
  * Indicates whether the current item within a repeat context
206
184
  * has an even index.
207
185
  */
208
- readonly isEven: boolean;
186
+ get isEven(): boolean;
209
187
  /**
210
188
  * Indicates whether the current item within a repeat context
211
189
  * has an odd index.
212
190
  */
213
- readonly isOdd: boolean;
191
+ get isOdd(): boolean;
214
192
  /**
215
193
  * Indicates whether the current item within a repeat context
216
194
  * is the first item in the collection.
217
195
  */
218
- readonly isFirst: boolean;
196
+ get isFirst(): boolean;
219
197
  /**
220
198
  * Indicates whether the current item within a repeat context
221
199
  * is somewhere in the middle of the collection.
222
200
  */
223
- readonly isInMiddle: boolean;
201
+ get isInMiddle(): boolean;
224
202
  /**
225
203
  * Indicates whether the current item within a repeat context
226
204
  * is the last item in the collection.
227
205
  */
228
- readonly isLast: boolean;
206
+ get isLast(): boolean;
207
+ /**
208
+ * Returns the typed event detail of a custom event.
209
+ */
210
+ eventDetail<TDetail>(): TDetail;
211
+ /**
212
+ * Returns the typed event target of the event.
213
+ */
214
+ eventTarget<TTarget extends EventTarget>(): TTarget;
229
215
  /**
230
216
  * Updates the position/size on a context associated with a list item.
231
217
  * @param index - The new index of the item.
232
218
  * @param length - The new length of the list.
233
219
  */
234
220
  updatePosition(index: number, length: number): void;
235
- }
236
- /**
237
- * The common execution context APIs.
238
- * @public
239
- */
240
- export declare const ExecutionContext: Readonly<{
241
- default: RootContext;
221
+ /**
222
+ * Creates a new execution context descendent from the current context.
223
+ * @param source - The source for the context if different than the parent.
224
+ * @returns A child execution context.
225
+ */
226
+ createChildContext<TParentSource>(parentSource: TParentSource): ExecutionContext<TParentSource>;
227
+ /**
228
+ * Creates a new execution context descent suitable for use in list rendering.
229
+ * @param item - The list item to serve as the source.
230
+ * @param index - The index of the item in the list.
231
+ * @param length - The length of the list.
232
+ */
233
+ createItemContext(index: number, length: number): ExecutionContext<TParentSource>;
242
234
  /**
243
235
  * Sets the event for the current execution context.
244
236
  * @param event - The event to set.
245
237
  * @internal
246
238
  */
247
- setEvent(event: Event | null): void;
239
+ static setEvent(event: Event | null): void;
248
240
  /**
249
241
  * Creates a new root execution context.
250
242
  * @returns A new execution context.
251
243
  */
252
- create(): RootContext;
253
- }>;
254
- /**
255
- * Represents some sort of execution context.
256
- * @public
257
- */
258
- export declare type ExecutionContext<TParentSource = any> = RootContext | ChildContext<TParentSource> | ItemContext<TParentSource>;
244
+ static create(): ExecutionContext;
245
+ }
@@ -58,6 +58,12 @@ export declare class ElementStyles {
58
58
  * @param Strategy - The strategy type to construct.
59
59
  */
60
60
  static setDefaultStrategy(Strategy: ConstructibleStyleStrategy): void;
61
+ /**
62
+ * Normalizes a set of composable style options.
63
+ * @param styles - The style options to normalize.
64
+ * @returns A singular ElementStyles instance or undefined.
65
+ */
66
+ static normalize(styles: ComposableStyles | ComposableStyles[] | undefined): ElementStyles | undefined;
61
67
  /**
62
68
  * Indicates whether the DOM supports the adoptedStyleSheets feature.
63
69
  */
@@ -0,0 +1,21 @@
1
+ import type { Expression } from "../observation/observable.js";
2
+ import type { Subscriber } from "../observation/notifier.js";
3
+ import { Binding } from "./html-directive.js";
4
+ export declare const Signal: Readonly<{
5
+ subscribe(signal: string, subscriber: Subscriber): void;
6
+ unsubscribe(signal: string, subscriber: Subscriber): void;
7
+ /**
8
+ * Sends the specified signal to signaled bindings.
9
+ * @param signal - The signal to send.
10
+ * @public
11
+ */
12
+ send(signal: string): void;
13
+ }>;
14
+ /**
15
+ * Creates a signal binding configuration with the supplied options.
16
+ * @param binding - The binding to refresh when signaled.
17
+ * @param options - The signal name or a binding to use to retrieve the signal name.
18
+ * @returns A binding configuration.
19
+ * @public
20
+ */
21
+ export declare function signal<T = any>(binding: Expression<T>, options: string | Expression<T>): Binding<T>;
@@ -0,0 +1,31 @@
1
+ import { Expression } from "../observation/observable.js";
2
+ import type { HTMLBindingDirective } from "./binding.js";
3
+ import { Binding } from "./html-directive.js";
4
+ /**
5
+ * The twoWay binding options.
6
+ * @public
7
+ */
8
+ export declare type TwoWayBindingOptions = {
9
+ changeEvent?: string;
10
+ fromView?: (value: any) => any;
11
+ };
12
+ /**
13
+ * The settings required to enable two-way binding.
14
+ * @public
15
+ */
16
+ export interface TwoWaySettings {
17
+ /**
18
+ * Determines which event to listen to, to detect changes in the view.
19
+ * @param directive - The directive to determine the change event for.
20
+ * @param target - The target element to determine the change event for.
21
+ */
22
+ determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
23
+ }
24
+ /**
25
+ * Creates a default binding.
26
+ * @param binding - The binding to refresh when changed.
27
+ * @param isBindingVolatile - Indicates whether the binding is volatile or not.
28
+ * @returns A binding configuration.
29
+ * @public
30
+ */
31
+ export declare function twoWay<T = any>(binding: Expression<T>, optionsOrChangeEvent?: TwoWayBindingOptions | string, isBindingVolatile?: boolean): Binding<T>;