@microsoft/fast-element 2.0.0-beta.2 → 2.0.0-beta.21
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 +509 -0
- package/CHANGELOG.md +189 -1
- package/dist/dts/components/attributes.d.ts +15 -0
- package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +74 -28
- package/dist/dts/components/fast-definitions.d.ts +41 -9
- package/dist/dts/components/fast-element.d.ts +14 -26
- package/dist/dts/components/hydration.d.ts +14 -0
- package/dist/{esm/observation/behavior.js → dts/components/install-hydration.d.ts} +0 -0
- package/dist/dts/context.d.ts +7 -7
- package/dist/dts/di/di.d.ts +894 -0
- package/dist/dts/dom-policy.d.ts +83 -0
- package/dist/dts/dom.d.ts +100 -0
- package/dist/dts/index.d.ts +5 -4
- package/dist/dts/index.rollup.d.ts +0 -1
- package/dist/dts/index.rollup.debug.d.ts +0 -1
- package/dist/dts/interfaces.d.ts +62 -80
- package/dist/dts/metadata.d.ts +5 -5
- package/dist/dts/observation/observable.d.ts +99 -54
- package/dist/dts/pending-task.d.ts +32 -0
- package/dist/dts/platform.d.ts +8 -1
- package/dist/dts/polyfills.d.ts +0 -8
- 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/css-directive.d.ts +2 -2
- package/dist/dts/styles/css.d.ts +0 -5
- package/dist/dts/styles/element-styles.d.ts +10 -17
- package/dist/dts/styles/host.d.ts +68 -0
- package/dist/dts/styles/style-strategy.d.ts +42 -0
- package/dist/dts/templating/binding-signal.d.ts +12 -27
- package/dist/dts/templating/binding-two-way.d.ts +22 -37
- package/dist/dts/templating/binding.d.ts +76 -208
- package/dist/dts/templating/children.d.ts +1 -1
- package/dist/dts/templating/compiler.d.ts +11 -13
- package/dist/dts/templating/html-directive.d.ts +91 -97
- package/dist/dts/templating/node-observation.d.ts +15 -6
- package/dist/dts/templating/ref.d.ts +7 -11
- package/dist/dts/templating/render.d.ts +296 -0
- package/dist/dts/templating/repeat.d.ts +23 -34
- package/dist/dts/templating/slotted.d.ts +1 -1
- package/dist/dts/templating/template.d.ts +92 -14
- package/dist/dts/templating/view.d.ts +81 -11
- package/dist/dts/templating/when.d.ts +3 -3
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +14 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/utilities.d.ts +55 -19
- package/dist/esm/components/attributes.js +28 -5
- package/dist/esm/components/{controller.js → element-controller.js} +238 -137
- package/dist/esm/components/fast-definitions.js +38 -30
- package/dist/esm/components/fast-element.js +27 -16
- package/dist/esm/components/hydration.js +35 -0
- package/dist/esm/components/install-hydration.js +2 -0
- package/dist/esm/context.js +7 -3
- package/dist/esm/debug.js +41 -5
- package/dist/esm/di/di.js +1430 -0
- package/dist/esm/dom-policy.js +345 -0
- package/dist/esm/dom.js +101 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.rollup.debug.js +3 -1
- package/dist/esm/index.rollup.js +3 -1
- package/dist/esm/interfaces.js +52 -0
- package/dist/esm/metadata.js +9 -8
- package/dist/esm/observation/arrays.js +303 -2
- package/dist/esm/observation/observable.js +88 -142
- package/dist/esm/observation/update-queue.js +2 -2
- package/dist/esm/pending-task.js +28 -0
- package/dist/esm/platform.js +28 -3
- package/dist/esm/polyfills.js +3 -61
- 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/css.js +4 -9
- package/dist/esm/styles/element-styles.js +14 -33
- package/dist/esm/styles/host.js +1 -0
- package/dist/esm/styles/style-strategy.js +1 -0
- package/dist/esm/templating/binding-signal.js +67 -62
- package/dist/esm/templating/binding-two-way.js +72 -39
- package/dist/esm/templating/binding.js +142 -286
- package/dist/esm/templating/children.js +8 -4
- package/dist/esm/templating/compiler.js +59 -43
- package/dist/esm/templating/html-directive.js +56 -75
- package/dist/esm/templating/node-observation.js +20 -13
- package/dist/esm/templating/ref.js +4 -12
- package/dist/esm/templating/render.js +402 -0
- package/dist/esm/templating/repeat.js +88 -75
- package/dist/esm/templating/template.js +132 -60
- package/dist/esm/templating/view.js +113 -29
- package/dist/esm/templating/when.js +5 -4
- package/dist/esm/testing/exports.js +3 -0
- package/dist/esm/testing/fakes.js +107 -0
- package/dist/esm/testing/fixture.js +86 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/utilities.js +97 -96
- package/dist/fast-element.api.json +9741 -8201
- package/dist/fast-element.d.ts +889 -646
- package/dist/fast-element.debug.js +2001 -1167
- package/dist/fast-element.debug.min.js +1 -1
- package/dist/fast-element.js +1907 -1109
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +913 -703
- package/docs/api-report.md +331 -258
- package/package.json +38 -16
- package/dist/dts/hooks.d.ts +0 -20
- package/dist/dts/observation/behavior.d.ts +0 -19
- package/dist/dts/observation/splice-strategies.d.ts +0 -13
- package/dist/dts/templating/dom.d.ts +0 -41
- package/dist/esm/hooks.js +0 -32
- package/dist/esm/observation/splice-strategies.js +0 -400
- package/dist/esm/templating/dom.js +0 -49
|
@@ -1,26 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isFunction } from "../interfaces.js";
|
|
2
|
+
import { ElementController } from "./element-controller.js";
|
|
2
3
|
import { FASTElementDefinition, } from "./fast-definitions.js";
|
|
3
4
|
/* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
|
|
4
5
|
function createFASTElement(BaseType) {
|
|
5
|
-
|
|
6
|
+
const type = class extends BaseType {
|
|
6
7
|
constructor() {
|
|
7
8
|
/* eslint-disable-next-line */
|
|
8
9
|
super();
|
|
9
|
-
|
|
10
|
+
ElementController.forCustomElement(this);
|
|
10
11
|
}
|
|
11
12
|
$emit(type, detail, options) {
|
|
12
13
|
return this.$fastController.emit(type, detail, options);
|
|
13
14
|
}
|
|
14
15
|
connectedCallback() {
|
|
15
|
-
this.$fastController.
|
|
16
|
+
this.$fastController.connect();
|
|
16
17
|
}
|
|
17
18
|
disconnectedCallback() {
|
|
18
|
-
this.$fastController.
|
|
19
|
+
this.$fastController.disconnect();
|
|
19
20
|
}
|
|
20
21
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
21
22
|
this.$fastController.onAttributeChangedCallback(name, oldValue, newValue);
|
|
22
23
|
}
|
|
23
24
|
};
|
|
25
|
+
FASTElementDefinition.registerBaseType(type);
|
|
26
|
+
return type;
|
|
27
|
+
}
|
|
28
|
+
function compose(type, nameOrDef) {
|
|
29
|
+
if (isFunction(type)) {
|
|
30
|
+
return FASTElementDefinition.compose(type, nameOrDef);
|
|
31
|
+
}
|
|
32
|
+
return FASTElementDefinition.compose(this, type);
|
|
33
|
+
}
|
|
34
|
+
function define(type, nameOrDef) {
|
|
35
|
+
if (isFunction(type)) {
|
|
36
|
+
return FASTElementDefinition.compose(type, nameOrDef).define().type;
|
|
37
|
+
}
|
|
38
|
+
return FASTElementDefinition.compose(this, type).define().type;
|
|
39
|
+
}
|
|
40
|
+
function from(BaseType) {
|
|
41
|
+
return createFASTElement(BaseType);
|
|
24
42
|
}
|
|
25
43
|
/**
|
|
26
44
|
* A minimal base class for FASTElements that also provides
|
|
@@ -33,26 +51,19 @@ export const FASTElement = Object.assign(createFASTElement(HTMLElement), {
|
|
|
33
51
|
* provided base type.
|
|
34
52
|
* @param BaseType - The base element type to inherit from.
|
|
35
53
|
*/
|
|
36
|
-
from
|
|
37
|
-
return createFASTElement(BaseType);
|
|
38
|
-
},
|
|
54
|
+
from,
|
|
39
55
|
/**
|
|
40
56
|
* Defines a platform custom element based on the provided type and definition.
|
|
41
57
|
* @param type - The custom element type to define.
|
|
42
58
|
* @param nameOrDef - The name of the element to define or a definition object
|
|
43
59
|
* that describes the element to define.
|
|
44
60
|
*/
|
|
45
|
-
define
|
|
46
|
-
return this.metadata(type, nameOrDef).define().type;
|
|
47
|
-
},
|
|
61
|
+
define,
|
|
48
62
|
/**
|
|
49
63
|
* 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
64
|
* @public
|
|
52
65
|
*/
|
|
53
|
-
|
|
54
|
-
return new FASTElementDefinition(type, nameOrDef);
|
|
55
|
-
},
|
|
66
|
+
compose,
|
|
56
67
|
});
|
|
57
68
|
/**
|
|
58
69
|
* Decorator: Defines a platform custom element based on `FASTElement`.
|
|
@@ -63,6 +74,6 @@ export const FASTElement = Object.assign(createFASTElement(HTMLElement), {
|
|
|
63
74
|
export function customElement(nameOrDef) {
|
|
64
75
|
/* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
|
|
65
76
|
return function (type) {
|
|
66
|
-
|
|
77
|
+
define(type, nameOrDef);
|
|
67
78
|
};
|
|
68
79
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UnobservableMutationObserver } from "../utilities.js";
|
|
2
|
+
import { ElementController } from "./element-controller.js";
|
|
3
|
+
const deferHydrationAttribute = "defer-hydration";
|
|
4
|
+
/**
|
|
5
|
+
* An ElementController capable of hydrating FAST elements from
|
|
6
|
+
* Declarative Shadow DOM.
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export class HydratableElementController extends ElementController {
|
|
11
|
+
static hydrationObserverHandler(records) {
|
|
12
|
+
for (const record of records) {
|
|
13
|
+
HydratableElementController.hydrationObserver.unobserve(record.target);
|
|
14
|
+
record.target.$fastController.connect();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
connect() {
|
|
18
|
+
if (this.source.hasAttribute(deferHydrationAttribute)) {
|
|
19
|
+
HydratableElementController.hydrationObserver.observe(this.source, {
|
|
20
|
+
attributeFilter: [deferHydrationAttribute],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
super.connect();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
disconnect() {
|
|
28
|
+
super.disconnect();
|
|
29
|
+
HydratableElementController.hydrationObserver.unobserve(this.source);
|
|
30
|
+
}
|
|
31
|
+
static install() {
|
|
32
|
+
ElementController.setStrategy(HydratableElementController);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
HydratableElementController.hydrationObserver = new UnobservableMutationObserver(HydratableElementController.hydrationObserverHandler);
|
package/dist/esm/context.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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
|
/**
|
|
5
7
|
* Enables using the {@link https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md | W3C Community Context protocol.}
|
|
6
|
-
* @
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
10
|
export const Context = Object.freeze({
|
|
9
11
|
/**
|
|
@@ -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);
|
|
@@ -128,7 +132,7 @@ export const Context = Object.freeze({
|
|
|
128
132
|
* initialValue if the context isn't handled.
|
|
129
133
|
*/
|
|
130
134
|
defineProperty(target, propertyName, context) {
|
|
131
|
-
const field =
|
|
135
|
+
const field = Symbol.for(`fast:di:${propertyName}`);
|
|
132
136
|
Reflect.defineProperty(target, propertyName, {
|
|
133
137
|
get: function () {
|
|
134
138
|
var _a;
|
package/dist/esm/debug.js
CHANGED
|
@@ -9,21 +9,57 @@ if (globalThis.FAST === void 0) {
|
|
|
9
9
|
const FAST = globalThis.FAST;
|
|
10
10
|
const debugMessages = {
|
|
11
11
|
[1101 /* needsArrayObservation */]: "Must call enableArrayObservation before observing arrays.",
|
|
12
|
-
[1201 /*
|
|
12
|
+
[1201 /* onlySetDOMPolicyOnce */]: "The DOM Policy can only be set once.",
|
|
13
13
|
[1202 /* bindingInnerHTMLRequiresTrustedTypes */]: "To bind innerHTML, you must use a TrustedTypesPolicy.",
|
|
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.",
|
|
17
|
+
[1206 /* directCallToHTMLTagNotAllowed */]: "Calling html`` as a normal function invalidates the security guarantees provided by FAST.",
|
|
18
|
+
[1207 /* onlySetTemplatePolicyOnce */]: "The DOM Policy for an HTML template can only be set once.",
|
|
19
|
+
[1208 /* cannotSetTemplatePolicyAfterCompilation */]: "The DOM Policy cannot be set after a template is compiled.",
|
|
20
|
+
[1209 /* blockedByDOMPolicy */]: "'${aspectName}' on '${tagName}' is blocked by the current DOMPolicy.",
|
|
14
21
|
[1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
|
|
22
|
+
[1501 /* noRegistrationForContext */]: "No registration for Context/Interface '${name}'.",
|
|
23
|
+
[1502 /* noFactoryForResolver */]: "Dependency injection resolver for '${key}' returned a null factory.",
|
|
24
|
+
[1503 /* invalidResolverStrategy */]: "Invalid dependency injection resolver strategy specified '${strategy}'.",
|
|
25
|
+
[1504 /* cannotAutoregisterDependency */]: "Unable to autoregister dependency.",
|
|
26
|
+
[1505 /* cannotResolveKey */]: "Unable to resolve dependency injection key '${key}'.",
|
|
27
|
+
[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.",
|
|
28
|
+
[1507 /* cannotJITRegisterNonConstructor */]: "Attempted to jitRegister something that is not a constructor '${value}'. Did you forget to register this dependency?",
|
|
29
|
+
[1508 /* cannotJITRegisterIntrinsic */]: "Attempted to jitRegister an intrinsic type '${value}'. Did you forget to add @inject(Key)?",
|
|
30
|
+
[1509 /* cannotJITRegisterInterface */]: "Attempted to jitRegister an interface '${value}'.",
|
|
31
|
+
[1510 /* invalidResolver */]: "A valid resolver was not returned from the register method.",
|
|
32
|
+
[1511 /* invalidKey */]: "Key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?",
|
|
33
|
+
[1512 /* noDefaultResolver */]: "'${key}' not registered. Did you forget to add @singleton()?",
|
|
34
|
+
[1513 /* cyclicDependency */]: "Cyclic dependency found '${name}'.",
|
|
35
|
+
[1514 /* connectUpdateRequiresController */]: "Injected properties that are updated on changes to DOM connectivity require the target object to be an instance of FASTElement.",
|
|
15
36
|
};
|
|
37
|
+
const allPlaceholders = /(\$\{\w+?})/g;
|
|
38
|
+
const placeholder = /\$\{(\w+?)}/g;
|
|
39
|
+
const noValues = Object.freeze({});
|
|
40
|
+
function formatMessage(message, values) {
|
|
41
|
+
return message
|
|
42
|
+
.split(allPlaceholders)
|
|
43
|
+
.map(v => {
|
|
44
|
+
var _a;
|
|
45
|
+
const replaced = v.replace(placeholder, "$1");
|
|
46
|
+
return String((_a = values[replaced]) !== null && _a !== void 0 ? _a : v);
|
|
47
|
+
})
|
|
48
|
+
.join("");
|
|
49
|
+
}
|
|
16
50
|
Object.assign(FAST, {
|
|
17
51
|
addMessages(messages) {
|
|
18
52
|
Object.assign(debugMessages, messages);
|
|
19
53
|
},
|
|
20
|
-
warn(code,
|
|
54
|
+
warn(code, values = noValues) {
|
|
21
55
|
var _a;
|
|
22
|
-
|
|
56
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning";
|
|
57
|
+
console.warn(formatMessage(message, values));
|
|
23
58
|
},
|
|
24
|
-
error(code,
|
|
59
|
+
error(code, values = noValues) {
|
|
25
60
|
var _a;
|
|
26
|
-
|
|
61
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error";
|
|
62
|
+
return new Error(formatMessage(message, values));
|
|
27
63
|
},
|
|
28
64
|
});
|
|
29
65
|
export {};
|