@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.
- package/CHANGELOG.json +147 -0
- package/CHANGELOG.md +42 -1
- package/dist/dts/components/fast-definitions.d.ts +9 -8
- package/dist/dts/components/fast-element.d.ts +12 -24
- package/dist/dts/context.d.ts +1 -1
- package/dist/dts/di/di.d.ts +858 -0
- package/dist/dts/interfaces.d.ts +43 -7
- package/dist/dts/observation/observable.d.ts +19 -13
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/element-styles.d.ts +6 -0
- package/dist/dts/templating/binding-signal.d.ts +10 -27
- package/dist/dts/templating/binding-two-way.d.ts +16 -41
- package/dist/dts/templating/binding.d.ts +79 -118
- package/dist/dts/templating/html-directive.d.ts +28 -2
- package/dist/dts/templating/render.d.ts +277 -0
- package/dist/dts/templating/repeat.d.ts +12 -16
- package/dist/dts/templating/template.d.ts +3 -3
- package/dist/dts/templating/when.d.ts +3 -3
- package/dist/dts/testing/exports.d.ts +2 -0
- package/dist/dts/testing/fixture.d.ts +90 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/utilities.d.ts +0 -18
- package/dist/esm/components/fast-definitions.js +25 -27
- package/dist/esm/components/fast-element.js +20 -11
- package/dist/esm/context.js +5 -1
- package/dist/esm/debug.js +35 -4
- package/dist/esm/di/di.js +1351 -0
- package/dist/esm/interfaces.js +4 -0
- package/dist/esm/observation/arrays.js +303 -2
- package/dist/esm/observation/observable.js +11 -6
- package/dist/esm/platform.js +1 -1
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/element-styles.js +14 -0
- package/dist/esm/templating/binding-signal.js +56 -61
- package/dist/esm/templating/binding-two-way.js +51 -35
- package/dist/esm/templating/binding.js +137 -156
- package/dist/esm/templating/compiler.js +29 -7
- package/dist/esm/templating/html-directive.js +12 -1
- package/dist/esm/templating/render.js +392 -0
- package/dist/esm/templating/repeat.js +57 -40
- package/dist/esm/templating/template.js +8 -5
- package/dist/esm/templating/view.js +3 -1
- package/dist/esm/templating/when.js +5 -4
- package/dist/esm/testing/exports.js +2 -0
- package/dist/esm/testing/fixture.js +88 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/utilities.js +0 -95
- package/dist/fast-element.api.json +2827 -2757
- package/dist/fast-element.d.ts +215 -229
- package/dist/fast-element.debug.js +650 -256
- package/dist/fast-element.debug.min.js +1 -1
- package/dist/fast-element.js +615 -252
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +223 -234
- package/docs/api-report.md +87 -90
- package/package.json +18 -9
- package/dist/dts/hooks.d.ts +0 -20
- package/dist/dts/observation/splice-strategies.d.ts +0 -13
- package/dist/esm/hooks.js +0 -32
- package/dist/esm/observation/splice-strategies.js +0 -400
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Behavior } from "../observation/behavior.js";
|
|
2
2
|
import type { Subscriber } from "../observation/notifier.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
|
|
4
4
|
import { Splice } from "../observation/arrays.js";
|
|
5
|
-
import { AddViewBehaviorFactory, HTMLDirective, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
|
|
5
|
+
import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
|
|
6
6
|
import type { CaptureType, SyntheticViewTemplate, ViewTemplate } from "./template.js";
|
|
7
7
|
/**
|
|
8
8
|
* Options for configuring repeat behavior.
|
|
@@ -23,10 +23,8 @@ export interface RepeatOptions {
|
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
export declare class RepeatBehavior<TSource = any> implements Behavior, Subscriber {
|
|
26
|
+
private directive;
|
|
26
27
|
private location;
|
|
27
|
-
private itemsBinding;
|
|
28
|
-
private templateBinding;
|
|
29
|
-
private options;
|
|
30
28
|
private source;
|
|
31
29
|
private views;
|
|
32
30
|
private template;
|
|
@@ -40,13 +38,13 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
|
|
|
40
38
|
/**
|
|
41
39
|
* Creates an instance of RepeatBehavior.
|
|
42
40
|
* @param location - The location in the DOM to render the repeat.
|
|
43
|
-
* @param
|
|
41
|
+
* @param dataBinding - The array to render.
|
|
44
42
|
* @param isItemsBindingVolatile - Indicates whether the items binding has volatile dependencies.
|
|
45
43
|
* @param templateBinding - The template to render for each item.
|
|
46
44
|
* @param isTemplateBindingVolatile - Indicates whether the template binding has volatile dependencies.
|
|
47
45
|
* @param options - Options used to turn on special repeat features.
|
|
48
46
|
*/
|
|
49
|
-
constructor(
|
|
47
|
+
constructor(directive: RepeatDirective, location: Node);
|
|
50
48
|
/**
|
|
51
49
|
* Bind this behavior to the source.
|
|
52
50
|
* @param source - The source to bind to.
|
|
@@ -63,7 +61,7 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
|
|
|
63
61
|
* @param source - The source of the change.
|
|
64
62
|
* @param args - The details about what was changed.
|
|
65
63
|
*/
|
|
66
|
-
handleChange(source: any, args: Splice[]): void;
|
|
64
|
+
handleChange(source: any, args: Splice[] | ExpressionObserver): void;
|
|
67
65
|
private observeItems;
|
|
68
66
|
private updateViews;
|
|
69
67
|
private refreshAllViews;
|
|
@@ -74,11 +72,9 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
|
|
|
74
72
|
* @public
|
|
75
73
|
*/
|
|
76
74
|
export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
|
|
77
|
-
readonly
|
|
75
|
+
readonly dataBinding: Binding<TSource>;
|
|
78
76
|
readonly templateBinding: Binding<TSource, SyntheticViewTemplate>;
|
|
79
77
|
readonly options: RepeatOptions;
|
|
80
|
-
private isItemsBindingVolatile;
|
|
81
|
-
private isTemplateBindingVolatile;
|
|
82
78
|
/**
|
|
83
79
|
* The unique id of the factory.
|
|
84
80
|
*/
|
|
@@ -94,11 +90,11 @@ export declare class RepeatDirective<TSource = any> implements HTMLDirective, Vi
|
|
|
94
90
|
createHTML(add: AddViewBehaviorFactory): string;
|
|
95
91
|
/**
|
|
96
92
|
* Creates an instance of RepeatDirective.
|
|
97
|
-
* @param
|
|
93
|
+
* @param dataBinding - The binding that provides the array to render.
|
|
98
94
|
* @param templateBinding - The template binding used to obtain a template to render for each item in the array.
|
|
99
95
|
* @param options - Options used to turn on special repeat features.
|
|
100
96
|
*/
|
|
101
|
-
constructor(
|
|
97
|
+
constructor(dataBinding: Binding<TSource>, templateBinding: Binding<TSource, SyntheticViewTemplate>, options: RepeatOptions);
|
|
102
98
|
/**
|
|
103
99
|
* Creates a behavior for the provided target node.
|
|
104
100
|
* @param target - The node instance to create the behavior for.
|
|
@@ -107,10 +103,10 @@ export declare class RepeatDirective<TSource = any> implements HTMLDirective, Vi
|
|
|
107
103
|
}
|
|
108
104
|
/**
|
|
109
105
|
* A directive that enables list rendering.
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
106
|
+
* @param items - The array to render.
|
|
107
|
+
* @param template - The template or a template binding used obtain a template
|
|
112
108
|
* to render for each item in the array.
|
|
113
109
|
* @param options - Options used to turn on special repeat features.
|
|
114
110
|
* @public
|
|
115
111
|
*/
|
|
116
|
-
export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(
|
|
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>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
|
|
1
|
+
import { ExecutionContext, Expression } from "../observation/observable.js";
|
|
2
|
+
import { Binding, HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
|
|
3
3
|
import type { ElementView, HTMLView, SyntheticView } from "./view.js";
|
|
4
4
|
/**
|
|
5
5
|
* A template capable of creating views specifically for rendering custom elements.
|
|
@@ -87,7 +87,7 @@ export interface CaptureType<TSource> {
|
|
|
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> = 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>;
|
|
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,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Expression } from "../observation/observable.js";
|
|
2
2
|
import type { CaptureType, SyntheticViewTemplate } from "./template.js";
|
|
3
3
|
/**
|
|
4
4
|
* A directive that enables basic conditional rendering in a template.
|
|
5
|
-
* @param
|
|
5
|
+
* @param condition - The condition to test for rendering.
|
|
6
6
|
* @param templateOrTemplateBinding - The template or a binding that gets
|
|
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>(
|
|
10
|
+
export declare function when<TSource = any, TReturn = any>(condition: Expression<TSource, TReturn> | boolean, templateOrTemplateBinding: SyntheticViewTemplate | Expression<TSource, SyntheticViewTemplate>): CaptureType<TSource>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Constructable } from "../interfaces.js";
|
|
2
|
+
import { ExecutionContext } from "../observation/observable.js";
|
|
3
|
+
import { ViewTemplate } from "../templating/template.js";
|
|
4
|
+
import type { HTMLView } from "../templating/view.js";
|
|
5
|
+
/**
|
|
6
|
+
* Options used to customize the creation of the test fixture.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface FixtureOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The document to run the fixture in.
|
|
12
|
+
* @defaultValue `globalThis.document`
|
|
13
|
+
*/
|
|
14
|
+
document?: Document;
|
|
15
|
+
/**
|
|
16
|
+
* The parent element to append the fixture to.
|
|
17
|
+
* @defaultValue An instance of `HTMLDivElement`.
|
|
18
|
+
*/
|
|
19
|
+
parent?: HTMLElement;
|
|
20
|
+
/**
|
|
21
|
+
* The data source to bind the HTML to.
|
|
22
|
+
* @defaultValue An empty object.
|
|
23
|
+
*/
|
|
24
|
+
source?: any;
|
|
25
|
+
/**
|
|
26
|
+
* The execution context to use during binding.
|
|
27
|
+
* @defaultValue {@link @microsoft/fast-element#ExecutionContext}
|
|
28
|
+
*/
|
|
29
|
+
context?: ExecutionContext;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A test fixture.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface Fixture<TElement = HTMLElement> {
|
|
36
|
+
/**
|
|
37
|
+
* The document the fixture is running in.
|
|
38
|
+
*/
|
|
39
|
+
document: Document;
|
|
40
|
+
/**
|
|
41
|
+
* The template the fixture was created from.
|
|
42
|
+
*/
|
|
43
|
+
template: ViewTemplate;
|
|
44
|
+
/**
|
|
45
|
+
* The view that was created from the fixture's template.
|
|
46
|
+
*/
|
|
47
|
+
view: HTMLView;
|
|
48
|
+
/**
|
|
49
|
+
* The parent element that the view was appended to.
|
|
50
|
+
* @remarks
|
|
51
|
+
* This element will be appended to the DOM only
|
|
52
|
+
* after {@link Fixture.connect} has been called.
|
|
53
|
+
*/
|
|
54
|
+
parent: HTMLElement;
|
|
55
|
+
/**
|
|
56
|
+
* The first element in the {@link Fixture.view}.
|
|
57
|
+
*/
|
|
58
|
+
element: TElement;
|
|
59
|
+
/**
|
|
60
|
+
* Adds the {@link Fixture.parent} to the DOM, causing the
|
|
61
|
+
* connect lifecycle to begin.
|
|
62
|
+
* @remarks
|
|
63
|
+
* Yields control to the caller one Microtask later, in order to
|
|
64
|
+
* ensure that the DOM has settled.
|
|
65
|
+
*/
|
|
66
|
+
connect: () => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the {@link Fixture.parent} from the DOM, causing the
|
|
69
|
+
* disconnect lifecycle to begin.
|
|
70
|
+
* @remarks
|
|
71
|
+
* Yields control to the caller one Microtask later, in order to
|
|
72
|
+
* ensure that the DOM has settled.
|
|
73
|
+
*/
|
|
74
|
+
disconnect: () => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a random, unique name suitable for use as a Custom Element name.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare function uniqueElementName(prefix?: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a test fixture suitable for testing custom elements, templates, and bindings.
|
|
83
|
+
* @param templateNameOrType An HTML template or single element name to create the fixture for.
|
|
84
|
+
* @param options Enables customizing fixture creation behavior.
|
|
85
|
+
* @remarks
|
|
86
|
+
* Yields control to the caller one Microtask later, in order to
|
|
87
|
+
* ensure that the DOM has settled.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export declare function fixture<TElement = HTMLElement>(templateNameOrType: ViewTemplate | string | Constructable<TElement>, options?: FixtureOptions): Promise<Fixture<TElement>>;
|
package/dist/dts/utilities.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
import { Disposable } from "./interfaces.js";
|
|
2
|
-
import type { Subscriber } from "./observation/notifier.js";
|
|
3
|
-
/**
|
|
4
|
-
* Converts a plain object to an observable object.
|
|
5
|
-
* @param object - The object to make observable.
|
|
6
|
-
* @param deep - Indicates whether or not to deeply convert the oject.
|
|
7
|
-
* @returns The converted object.
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export declare function makeObservable<T>(object: T, deep?: boolean): T;
|
|
11
|
-
/**
|
|
12
|
-
* Deeply subscribes to changes in existing observable objects.
|
|
13
|
-
* @param object - The observable object to watch.
|
|
14
|
-
* @param subscriber - The handler to call when changes are made to the object.
|
|
15
|
-
* @returns A disposable that can be used to unsubscribe from change updates.
|
|
16
|
-
* @beta
|
|
17
|
-
*/
|
|
18
|
-
export declare function watch(object: any, subscriber: Subscriber | ((subject: any, args: any) => void)): Disposable;
|
|
19
1
|
/**
|
|
20
2
|
* Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
|
|
21
3
|
* When the parent of a node is a shadow-root, it will return the host
|
|
@@ -11,19 +11,15 @@ const fastElementRegistry = FAST.getById(4 /* KernelServiceId.elementRegistry */
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export class FASTElementDefinition {
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of FASTElementDefinition.
|
|
16
|
-
* @param type - The type this definition is being created for.
|
|
17
|
-
* @param nameOrConfig - The name of the element to define or a config object
|
|
18
|
-
* that describes the element to define.
|
|
19
|
-
*/
|
|
20
14
|
constructor(type, nameOrConfig = type.definition) {
|
|
15
|
+
this.platformDefined = false;
|
|
21
16
|
if (isString(nameOrConfig)) {
|
|
22
17
|
nameOrConfig = { name: nameOrConfig };
|
|
23
18
|
}
|
|
24
19
|
this.type = type;
|
|
25
20
|
this.name = nameOrConfig.name;
|
|
26
21
|
this.template = nameOrConfig.template;
|
|
22
|
+
const proto = type.prototype;
|
|
27
23
|
const attributes = AttributeDefinition.collect(type, nameOrConfig.attributes);
|
|
28
24
|
const observedAttributes = new Array(attributes.length);
|
|
29
25
|
const propertyLookup = {};
|
|
@@ -33,9 +29,13 @@ export class FASTElementDefinition {
|
|
|
33
29
|
observedAttributes[i] = current.attribute;
|
|
34
30
|
propertyLookup[current.name] = current;
|
|
35
31
|
attributeLookup[current.attribute] = current;
|
|
32
|
+
Observable.defineProperty(proto, current);
|
|
36
33
|
}
|
|
34
|
+
Reflect.defineProperty(type, "observedAttributes", {
|
|
35
|
+
value: observedAttributes,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
});
|
|
37
38
|
this.attributes = attributes;
|
|
38
|
-
this.observedAttributes = observedAttributes;
|
|
39
39
|
this.propertyLookup = propertyLookup;
|
|
40
40
|
this.attributeLookup = attributeLookup;
|
|
41
41
|
this.shadowOptions =
|
|
@@ -48,20 +48,14 @@ export class FASTElementDefinition {
|
|
|
48
48
|
nameOrConfig.elementOptions === void 0
|
|
49
49
|
? defaultElementOptions
|
|
50
50
|
: Object.assign(Object.assign({}, defaultElementOptions), nameOrConfig.elementOptions);
|
|
51
|
-
this.styles =
|
|
52
|
-
|
|
53
|
-
? void 0
|
|
54
|
-
: Array.isArray(nameOrConfig.styles)
|
|
55
|
-
? new ElementStyles(nameOrConfig.styles)
|
|
56
|
-
: nameOrConfig.styles instanceof ElementStyles
|
|
57
|
-
? nameOrConfig.styles
|
|
58
|
-
: new ElementStyles([nameOrConfig.styles]);
|
|
51
|
+
this.styles = ElementStyles.normalize(nameOrConfig.styles);
|
|
52
|
+
fastElementRegistry.register(this);
|
|
59
53
|
}
|
|
60
54
|
/**
|
|
61
55
|
* Indicates if this element has been defined in at least one registry.
|
|
62
56
|
*/
|
|
63
57
|
get isDefined() {
|
|
64
|
-
return
|
|
58
|
+
return this.platformDefined;
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
61
|
* Defines a custom element based on this definition.
|
|
@@ -71,22 +65,26 @@ export class FASTElementDefinition {
|
|
|
71
65
|
*/
|
|
72
66
|
define(registry = customElements) {
|
|
73
67
|
const type = this.type;
|
|
74
|
-
if (fastElementRegistry.register(this)) {
|
|
75
|
-
const attributes = this.attributes;
|
|
76
|
-
const proto = type.prototype;
|
|
77
|
-
for (let i = 0, ii = attributes.length; i < ii; ++i) {
|
|
78
|
-
Observable.defineProperty(proto, attributes[i]);
|
|
79
|
-
}
|
|
80
|
-
Reflect.defineProperty(type, "observedAttributes", {
|
|
81
|
-
value: this.observedAttributes,
|
|
82
|
-
enumerable: true,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
68
|
if (!registry.get(this.name)) {
|
|
69
|
+
this.platformDefined = true;
|
|
86
70
|
registry.define(this.name, type, this.elementOptions);
|
|
87
71
|
}
|
|
88
72
|
return this;
|
|
89
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates an instance of FASTElementDefinition.
|
|
76
|
+
* @param type - The type this definition is being created for.
|
|
77
|
+
* @param nameOrDef - The name of the element to define or a config object
|
|
78
|
+
* that describes the element to define.
|
|
79
|
+
*/
|
|
80
|
+
static compose(type, nameOrDef) {
|
|
81
|
+
const found = fastElementRegistry.getByType(type);
|
|
82
|
+
if (found) {
|
|
83
|
+
return new FASTElementDefinition(class extends type {
|
|
84
|
+
}, nameOrDef);
|
|
85
|
+
}
|
|
86
|
+
return new FASTElementDefinition(type, nameOrDef);
|
|
87
|
+
}
|
|
90
88
|
}
|
|
91
89
|
/**
|
|
92
90
|
* Gets the element definition associated with the specified type.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFunction } from "../interfaces.js";
|
|
1
2
|
import { Controller } from "./controller.js";
|
|
2
3
|
import { FASTElementDefinition, } from "./fast-definitions.js";
|
|
3
4
|
/* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
|
|
@@ -22,6 +23,21 @@ function createFASTElement(BaseType) {
|
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
}
|
|
26
|
+
function compose(type, nameOrDef) {
|
|
27
|
+
if (isFunction(type)) {
|
|
28
|
+
return FASTElementDefinition.compose(type, nameOrDef);
|
|
29
|
+
}
|
|
30
|
+
return FASTElementDefinition.compose(this, type);
|
|
31
|
+
}
|
|
32
|
+
function define(type, nameOrDef) {
|
|
33
|
+
if (isFunction(type)) {
|
|
34
|
+
return FASTElementDefinition.compose(type, nameOrDef).define().type;
|
|
35
|
+
}
|
|
36
|
+
return FASTElementDefinition.compose(this, type).define().type;
|
|
37
|
+
}
|
|
38
|
+
function from(BaseType) {
|
|
39
|
+
return createFASTElement(BaseType);
|
|
40
|
+
}
|
|
25
41
|
/**
|
|
26
42
|
* A minimal base class for FASTElements that also provides
|
|
27
43
|
* static helpers for working with FASTElements.
|
|
@@ -33,26 +49,19 @@ export const FASTElement = Object.assign(createFASTElement(HTMLElement), {
|
|
|
33
49
|
* provided base type.
|
|
34
50
|
* @param BaseType - The base element type to inherit from.
|
|
35
51
|
*/
|
|
36
|
-
from
|
|
37
|
-
return createFASTElement(BaseType);
|
|
38
|
-
},
|
|
52
|
+
from,
|
|
39
53
|
/**
|
|
40
54
|
* Defines a platform custom element based on the provided type and definition.
|
|
41
55
|
* @param type - The custom element type to define.
|
|
42
56
|
* @param nameOrDef - The name of the element to define or a definition object
|
|
43
57
|
* that describes the element to define.
|
|
44
58
|
*/
|
|
45
|
-
define
|
|
46
|
-
return this.metadata(type, nameOrDef).define().type;
|
|
47
|
-
},
|
|
59
|
+
define,
|
|
48
60
|
/**
|
|
49
61
|
* Defines metadata for a FASTElement which can be used to later define the element.
|
|
50
|
-
* IMPORTANT: This API will be renamed to "compose" in a future beta.
|
|
51
62
|
* @public
|
|
52
63
|
*/
|
|
53
|
-
|
|
54
|
-
return new FASTElementDefinition(type, nameOrDef);
|
|
55
|
-
},
|
|
64
|
+
compose,
|
|
56
65
|
});
|
|
57
66
|
/**
|
|
58
67
|
* Decorator: Defines a platform custom element based on `FASTElement`.
|
|
@@ -63,6 +72,6 @@ export const FASTElement = Object.assign(createFASTElement(HTMLElement), {
|
|
|
63
72
|
export function customElement(nameOrDef) {
|
|
64
73
|
/* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
|
|
65
74
|
return function (type) {
|
|
66
|
-
|
|
75
|
+
define(type, nameOrDef);
|
|
67
76
|
};
|
|
68
77
|
}
|
package/dist/esm/context.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import "./interfaces.js";
|
|
1
2
|
import { Metadata } from "./metadata.js";
|
|
3
|
+
import { FAST } from "./platform.js";
|
|
2
4
|
const contextEventType = "context-request";
|
|
3
5
|
let requestStrategy;
|
|
4
6
|
/**
|
|
@@ -19,7 +21,9 @@ export const Context = Object.freeze({
|
|
|
19
21
|
create(name, initialValue) {
|
|
20
22
|
const Interface = function (target, property, index) {
|
|
21
23
|
if (target == null || new.target !== undefined) {
|
|
22
|
-
throw
|
|
24
|
+
throw FAST.error(1501 /* Message.noRegistrationForContext */, {
|
|
25
|
+
name: Interface.name,
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
if (property) {
|
|
25
29
|
Context.defineProperty(target, property, Interface);
|
package/dist/esm/debug.js
CHANGED
|
@@ -12,19 +12,50 @@ const debugMessages = {
|
|
|
12
12
|
[1201 /* onlySetHTMLPolicyOnce */]: "The HTML policy can only be set once.",
|
|
13
13
|
[1202 /* bindingInnerHTMLRequiresTrustedTypes */]: "To bind innerHTML, you must use a TrustedTypesPolicy.",
|
|
14
14
|
[1203 /* twoWayBindingRequiresObservables */]: "View=>Model update skipped. To use twoWay binding, the target property must be observable.",
|
|
15
|
+
[1204 /* hostBindingWithoutHost */]: "No host element is present. Cannot bind host with ${name}.",
|
|
16
|
+
[1205 /* unsupportedBindingBehavior */]: "The requested binding behavior is not supported by the binding engine.",
|
|
15
17
|
[1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
|
|
18
|
+
[1501 /* noRegistrationForContext */]: "No registration for Context/Interface '${name}'.",
|
|
19
|
+
[1502 /* noFactoryForResolver */]: "Dependency injection resolver for '${key}' returned a null factory.",
|
|
20
|
+
[1503 /* invalidResolverStrategy */]: "Invalid dependency injection resolver strategy specified '${strategy}'.",
|
|
21
|
+
[1504 /* cannotAutoregisterDependency */]: "Unable to autoregister dependency.",
|
|
22
|
+
[1505 /* cannotResolveKey */]: "Unable to resolve dependency injection key '${key}'.",
|
|
23
|
+
[1506 /* cannotConstructNativeFunction */]: "'${name}' is a native function and therefore cannot be safely constructed by DI. If this is intentional, please use a callback or cachedCallback resolver.",
|
|
24
|
+
[1507 /* cannotJITRegisterNonConstructor */]: "Attempted to jitRegister something that is not a constructor '${value}'. Did you forget to register this dependency?",
|
|
25
|
+
[1508 /* cannotJITRegisterIntrinsic */]: "Attempted to jitRegister an intrinsic type '${value}'. Did you forget to add @inject(Key)?",
|
|
26
|
+
[1509 /* cannotJITRegisterInterface */]: "Attempted to jitRegister an interface '${value}'.",
|
|
27
|
+
[1510 /* invalidResolver */]: "A valid resolver was not returned from the register method.",
|
|
28
|
+
[1511 /* invalidKey */]: "Key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?",
|
|
29
|
+
[1512 /* noDefaultResolver */]: "'${key}' not registered. Did you forget to add @singleton()?",
|
|
30
|
+
[1513 /* cyclicDependency */]: "Cyclic dependency found '${name}'.",
|
|
31
|
+
[1514 /* connectUpdateRequiresController */]: "Injected properties that are updated on changes to DOM connectivity require the target object to be an instance of FASTElement.",
|
|
16
32
|
};
|
|
33
|
+
const allPlaceholders = /(\$\{\w+?})/g;
|
|
34
|
+
const placeholder = /\$\{(\w+?)}/g;
|
|
35
|
+
const noValues = Object.freeze({});
|
|
36
|
+
function formatMessage(message, values) {
|
|
37
|
+
return message
|
|
38
|
+
.split(allPlaceholders)
|
|
39
|
+
.map(v => {
|
|
40
|
+
var _a;
|
|
41
|
+
const replaced = v.replace(placeholder, "$1");
|
|
42
|
+
return String((_a = values[replaced]) !== null && _a !== void 0 ? _a : v);
|
|
43
|
+
})
|
|
44
|
+
.join("");
|
|
45
|
+
}
|
|
17
46
|
Object.assign(FAST, {
|
|
18
47
|
addMessages(messages) {
|
|
19
48
|
Object.assign(debugMessages, messages);
|
|
20
49
|
},
|
|
21
|
-
warn(code,
|
|
50
|
+
warn(code, values = noValues) {
|
|
22
51
|
var _a;
|
|
23
|
-
|
|
52
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning";
|
|
53
|
+
console.warn(formatMessage(message, values));
|
|
24
54
|
},
|
|
25
|
-
error(code,
|
|
55
|
+
error(code, values = noValues) {
|
|
26
56
|
var _a;
|
|
27
|
-
|
|
57
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error";
|
|
58
|
+
return new Error(formatMessage(message, values));
|
|
28
59
|
},
|
|
29
60
|
});
|
|
30
61
|
export {};
|