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

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 (68) hide show
  1. package/CHANGELOG.json +147 -0
  2. package/CHANGELOG.md +42 -1
  3. package/dist/dts/components/fast-definitions.d.ts +9 -8
  4. package/dist/dts/components/fast-element.d.ts +12 -24
  5. package/dist/dts/context.d.ts +1 -1
  6. package/dist/dts/di/di.d.ts +858 -0
  7. package/dist/dts/interfaces.d.ts +43 -7
  8. package/dist/dts/observation/observable.d.ts +19 -13
  9. package/dist/dts/state/exports.d.ts +3 -0
  10. package/dist/dts/state/reactive.d.ts +8 -0
  11. package/dist/dts/state/state.d.ts +141 -0
  12. package/dist/dts/state/visitor.d.ts +6 -0
  13. package/dist/dts/state/watch.d.ts +10 -0
  14. package/dist/dts/styles/element-styles.d.ts +6 -0
  15. package/dist/dts/templating/binding-signal.d.ts +10 -27
  16. package/dist/dts/templating/binding-two-way.d.ts +16 -41
  17. package/dist/dts/templating/binding.d.ts +79 -118
  18. package/dist/dts/templating/html-directive.d.ts +28 -2
  19. package/dist/dts/templating/render.d.ts +277 -0
  20. package/dist/dts/templating/repeat.d.ts +12 -16
  21. package/dist/dts/templating/template.d.ts +3 -3
  22. package/dist/dts/templating/when.d.ts +3 -3
  23. package/dist/dts/testing/exports.d.ts +2 -0
  24. package/dist/dts/testing/fixture.d.ts +90 -0
  25. package/dist/dts/testing/timeout.d.ts +7 -0
  26. package/dist/dts/utilities.d.ts +0 -18
  27. package/dist/esm/components/fast-definitions.js +25 -27
  28. package/dist/esm/components/fast-element.js +20 -11
  29. package/dist/esm/context.js +5 -1
  30. package/dist/esm/debug.js +35 -4
  31. package/dist/esm/di/di.js +1351 -0
  32. package/dist/esm/interfaces.js +4 -0
  33. package/dist/esm/observation/arrays.js +303 -2
  34. package/dist/esm/observation/observable.js +11 -6
  35. package/dist/esm/platform.js +1 -1
  36. package/dist/esm/state/exports.js +3 -0
  37. package/dist/esm/state/reactive.js +34 -0
  38. package/dist/esm/state/state.js +148 -0
  39. package/dist/esm/state/visitor.js +28 -0
  40. package/dist/esm/state/watch.js +36 -0
  41. package/dist/esm/styles/element-styles.js +14 -0
  42. package/dist/esm/templating/binding-signal.js +56 -61
  43. package/dist/esm/templating/binding-two-way.js +51 -35
  44. package/dist/esm/templating/binding.js +137 -156
  45. package/dist/esm/templating/compiler.js +29 -7
  46. package/dist/esm/templating/html-directive.js +12 -1
  47. package/dist/esm/templating/render.js +392 -0
  48. package/dist/esm/templating/repeat.js +57 -40
  49. package/dist/esm/templating/template.js +8 -5
  50. package/dist/esm/templating/view.js +3 -1
  51. package/dist/esm/templating/when.js +5 -4
  52. package/dist/esm/testing/exports.js +2 -0
  53. package/dist/esm/testing/fixture.js +88 -0
  54. package/dist/esm/testing/timeout.js +24 -0
  55. package/dist/esm/utilities.js +0 -95
  56. package/dist/fast-element.api.json +2827 -2757
  57. package/dist/fast-element.d.ts +215 -229
  58. package/dist/fast-element.debug.js +650 -256
  59. package/dist/fast-element.debug.min.js +1 -1
  60. package/dist/fast-element.js +615 -252
  61. package/dist/fast-element.min.js +1 -1
  62. package/dist/fast-element.untrimmed.d.ts +223 -234
  63. package/docs/api-report.md +87 -90
  64. package/package.json +18 -9
  65. package/dist/dts/hooks.d.ts +0 -20
  66. package/dist/dts/observation/splice-strategies.d.ts +0 -13
  67. package/dist/esm/hooks.js +0 -32
  68. package/dist/esm/observation/splice-strategies.js +0 -400
@@ -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.
@@ -155,7 +171,23 @@ export declare const enum Message {
155
171
  onlySetHTMLPolicyOnce = 1201,
156
172
  bindingInnerHTMLRequiresTrustedTypes = 1202,
157
173
  twoWayBindingRequiresObservables = 1203,
158
- missingElementDefinition = 1401
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,
190
+ connectUpdateRequiresController = 1514
159
191
  }
160
192
  /**
161
193
  * @internal
@@ -165,3 +197,7 @@ export declare const isFunction: (object: any) => object is Function;
165
197
  * @internal
166
198
  */
167
199
  export declare const isString: (object: any) => object is string;
200
+ /**
201
+ * @internal
202
+ */
203
+ export declare const noop: () => undefined;
@@ -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, TParent = any> = (source: TSource, context: ExecutionContext<TParent>) => 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, 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, 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.
@@ -0,0 +1,3 @@
1
+ export { reactive } from "./reactive.js";
2
+ export { watch } from "./watch.js";
3
+ export * from "./state.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a plain object to a reactive, observable object.
3
+ * @param object - The object to make reactive.
4
+ * @param deep - Indicates whether or not to deeply convert the oject.
5
+ * @returns The converted object.
6
+ * @beta
7
+ */
8
+ export declare function reactive<T>(object: T, deep?: boolean): T;
@@ -0,0 +1,141 @@
1
+ import { Disposable } from "../interfaces.js";
2
+ import type { Subscriber } from "../observation/notifier.js";
3
+ /**
4
+ * Options for creating state.
5
+ * @beta
6
+ */
7
+ export declare type StateOptions = {
8
+ /**
9
+ * Indicates whether to deeply make the state value observable.
10
+ */
11
+ deep?: boolean;
12
+ /**
13
+ * A friendly name for the state.
14
+ */
15
+ name?: string;
16
+ };
17
+ /**
18
+ * A readonly stateful value.
19
+ * @beta
20
+ */
21
+ export declare type ReadonlyState<T> = {
22
+ /**
23
+ * Gets the current state value.
24
+ */
25
+ (): T;
26
+ /**
27
+ * Gets the current state value.
28
+ */
29
+ readonly current: T;
30
+ };
31
+ /**
32
+ * A read/write stateful value.
33
+ * @beta
34
+ */
35
+ export declare type State<T> = ReadonlyState<T> & {
36
+ /**
37
+ * Gets or sets the current state value.
38
+ */
39
+ current: T;
40
+ /**
41
+ * Sets the current state value.
42
+ * @param value The new state value.
43
+ */
44
+ set(value: T): void;
45
+ /**
46
+ * Creates a readonly version of the state.
47
+ */
48
+ asReadonly(): ReadonlyState<T>;
49
+ };
50
+ /**
51
+ * Creates a reactive state value.
52
+ * @param value - The initial state value.
53
+ * @param options - Options to customize the state or a friendly name.
54
+ * @returns A State instance.
55
+ * @beta
56
+ */
57
+ export declare function state<T>(value: T, options?: string | StateOptions): State<T>;
58
+ /**
59
+ * A readonly stateful value associated with an object owner.
60
+ * @beta
61
+ */
62
+ export declare type ReadonlyOwnedState<T> = {
63
+ /**
64
+ * Gets the current stateful value for the owner.
65
+ */
66
+ (owner: any): T;
67
+ };
68
+ /**
69
+ * A read/write stateful value associated with an owner.
70
+ * @beta
71
+ */
72
+ export declare type OwnedState<T> = ReadonlyOwnedState<T> & {
73
+ /**
74
+ * Sets
75
+ * @param owner - The object to set the state for the owner.
76
+ * @param value - The new state value.
77
+ */
78
+ set(owner: any, value: T): void;
79
+ /**
80
+ * Creates a readonly version of the state.
81
+ */
82
+ asReadonly(): ReadonlyOwnedState<T>;
83
+ };
84
+ /**
85
+ * Creates a reactive state that has its value associated with a specific owner.
86
+ * @param value - The initial value or a factory that provides an initial value for each owner.
87
+ * @param options - Options to customize the state or a friendly name.
88
+ * @returns An OwnedState instance.
89
+ * @beta
90
+ */
91
+ export declare function ownedState<T>(value: T | (() => T), options?: string | StateOptions): OwnedState<T>;
92
+ /**
93
+ * State whose value is computed from other dependencies.
94
+ * @beta
95
+ */
96
+ export declare type ComputedState<T> = ReadonlyState<T> & Disposable & {
97
+ /**
98
+ * Subscribes to notification of changes in the state.
99
+ * @param subscriber - The object that is subscribing for change notification.
100
+ */
101
+ subscribe(subscriber: Subscriber): void;
102
+ /**
103
+ * Unsubscribes from notification of changes in the state.
104
+ * @param subscriber - The object that is unsubscribing from change notification.
105
+ */
106
+ unsubscribe(subscriber: Subscriber): void;
107
+ };
108
+ /**
109
+ * A callback that enables computation setup.
110
+ * @beta
111
+ */
112
+ export declare type ComputedSetupCallback = () => (() => void) | void;
113
+ /**
114
+ * Provides computed state capabilities.
115
+ * @beta
116
+ */
117
+ export declare type ComputedBuilder = {
118
+ /**
119
+ * Callbacks related to computed state.
120
+ */
121
+ on: {
122
+ /**
123
+ * Provides a setup callback for the computation.
124
+ * @param callback The callback to run to setup the computation.
125
+ */
126
+ setup(callback: ComputedSetupCallback): void;
127
+ };
128
+ };
129
+ /**
130
+ * A callback that initializes the computation.
131
+ * @beta
132
+ */
133
+ export declare type ComputedInitializer<T> = (builder: ComputedBuilder) => () => T;
134
+ /**
135
+ * Creates a ComputedState.
136
+ * @param initialize - The initialization callback.
137
+ * @param name - A friendly name for this computation.
138
+ * @returns A ComputedState
139
+ * @beta
140
+ */
141
+ export declare function computedState<T>(initialize: ComputedInitializer<T>, name?: string): ComputedState<T>;
@@ -0,0 +1,6 @@
1
+ export interface ObjectVisitor<TVisitorData> {
2
+ visitObject(object: any, data: TVisitorData): void;
3
+ visitArray(array: any[], data: TVisitorData): void;
4
+ visitProperty(object: any, key: PropertyKey, value: any, data: TVisitorData): void;
5
+ }
6
+ export declare function visitObject<TVisitorData>(object: any, deep: boolean, visitor: ObjectVisitor<TVisitorData>, data: TVisitorData, traversed: WeakSet<any> | Set<any>): void;
@@ -0,0 +1,10 @@
1
+ import { Disposable } from "../interfaces.js";
2
+ import type { Subscriber } from "../observation/notifier.js";
3
+ /**
4
+ * Deeply subscribes to changes in existing observable objects.
5
+ * @param object - The observable object to watch.
6
+ * @param subscriber - The handler to call when changes are made to the object.
7
+ * @returns A disposable that can be used to unsubscribe from change updates.
8
+ * @beta
9
+ */
10
+ export declare function watch(object: any, subscriber: Subscriber | ((subject: any, args: any) => void)): Disposable;
@@ -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
  */
@@ -1,38 +1,21 @@
1
- import type { Binding, ExecutionContext } from "../observation/observable.js";
2
- import { BindingConfig, UpdateBinding } from "./binding.js";
3
- import type { ViewBehaviorTargets } from "./html-directive.js";
4
- /**
5
- * A binding behavior for signal bindings.
6
- * @public
7
- */
8
- export declare class SignalBinding extends UpdateBinding {
9
- private handlerProperty;
10
- /**
11
- * Bind this behavior to the source.
12
- * @param source - The source to bind to.
13
- * @param context - The execution context that the binding is operating within.
14
- * @param targets - The targets that behaviors in a view can attach to.
15
- */
16
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
17
- /**
18
- * Unbinds this behavior from the source.
19
- * @param source - The source to unbind from.
20
- * @param context - The execution context that the binding is operating within.
21
- * @param targets - The targets that behaviors in a view can attach to.
22
- */
23
- unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
24
- private getSignal;
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;
25
7
  /**
26
8
  * Sends the specified signal to signaled bindings.
27
9
  * @param signal - The signal to send.
28
10
  * @public
29
11
  */
30
- static send(signal: string): void;
31
- }
12
+ send(signal: string): void;
13
+ }>;
32
14
  /**
33
15
  * Creates a signal binding configuration with the supplied options.
16
+ * @param binding - The binding to refresh when signaled.
34
17
  * @param options - The signal name or a binding to use to retrieve the signal name.
35
18
  * @returns A binding configuration.
36
19
  * @public
37
20
  */
38
- export declare const signal: <T = any>(options: string | Binding<T, any, any>) => BindingConfig<string | Binding<T, any, any>>;
21
+ export declare function signal<T = any>(binding: Expression<T>, options: string | Expression<T>): Binding<T>;
@@ -1,6 +1,14 @@
1
- import type { ExecutionContext } from "../observation/observable.js";
2
- import { BindingConfig, ChangeBinding, DefaultBindingOptions, HTMLBindingDirective } from "./binding.js";
3
- import type { ViewBehaviorTargets } from "./html-directive.js";
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
+ };
4
12
  /**
5
13
  * The settings required to enable two-way binding.
6
14
  * @public
@@ -14,43 +22,10 @@ export interface TwoWaySettings {
14
22
  determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
15
23
  }
16
24
  /**
17
- * A binding behavior for bindings that update in two directions.
18
- * @public
19
- */
20
- export declare class TwoWayBinding extends ChangeBinding {
21
- private changeEvent;
22
- /**
23
- * Bind this behavior to the source.
24
- * @param source - The source to bind to.
25
- * @param context - The execution context that the binding is operating within.
26
- * @param targets - The targets that behaviors in a view can attach to.
27
- */
28
- bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
29
- /**
30
- * Unbinds this behavior from the source.
31
- * @param source - The source to unbind from.
32
- * @param context - The execution context that the binding is operating within.
33
- * @param targets - The targets that behaviors in a view can attach to.
34
- */
35
- unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
36
- /** @internal */
37
- handleEvent(event: Event): void;
38
- /**
39
- * Configures two-way binding.
40
- * @param settings - The settings to use for the two-way binding system.
41
- */
42
- static configure(settings: TwoWaySettings): void;
43
- }
44
- /**
45
- * The default twoWay binding options.
46
- * @public
47
- */
48
- export declare type DefaultTwoWayBindingOptions = DefaultBindingOptions & {
49
- changeEvent?: string;
50
- fromView?: (value: any) => any;
51
- };
52
- /**
53
- * The default twoWay binding configuration.
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.
54
29
  * @public
55
30
  */
56
- export declare const twoWay: BindingConfig<DefaultTwoWayBindingOptions> & import("./binding.js").BindingConfigResolver<DefaultTwoWayBindingOptions>;
31
+ export declare function twoWay<T = any>(binding: Expression<T>, optionsOrChangeEvent?: TwoWayBindingOptions | string, isBindingVolatile?: boolean): Binding<T>;