@microsoft/fast-element 2.0.0-beta.2 → 2.0.0-beta.20

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 (113) hide show
  1. package/CHANGELOG.json +488 -0
  2. package/CHANGELOG.md +180 -1
  3. package/dist/dts/components/attributes.d.ts +15 -0
  4. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +74 -28
  5. package/dist/dts/components/fast-definitions.d.ts +41 -9
  6. package/dist/dts/components/fast-element.d.ts +14 -26
  7. package/dist/dts/components/hydration.d.ts +14 -0
  8. package/dist/{esm/observation/behavior.js → dts/components/install-hydration.d.ts} +0 -0
  9. package/dist/dts/context.d.ts +1 -1
  10. package/dist/dts/di/di.d.ts +894 -0
  11. package/dist/dts/dom-policy.d.ts +68 -0
  12. package/dist/dts/dom.d.ts +100 -0
  13. package/dist/dts/index.d.ts +5 -4
  14. package/dist/dts/index.rollup.d.ts +0 -1
  15. package/dist/dts/index.rollup.debug.d.ts +0 -1
  16. package/dist/dts/interfaces.d.ts +60 -79
  17. package/dist/dts/observation/observable.d.ts +99 -54
  18. package/dist/dts/pending-task.d.ts +20 -0
  19. package/dist/dts/platform.d.ts +7 -0
  20. package/dist/dts/polyfills.d.ts +0 -8
  21. package/dist/dts/state/exports.d.ts +3 -0
  22. package/dist/dts/state/reactive.d.ts +8 -0
  23. package/dist/dts/state/state.d.ts +141 -0
  24. package/dist/dts/state/visitor.d.ts +6 -0
  25. package/dist/dts/state/watch.d.ts +10 -0
  26. package/dist/dts/styles/css-directive.d.ts +2 -2
  27. package/dist/dts/styles/css.d.ts +0 -5
  28. package/dist/dts/styles/element-styles.d.ts +10 -17
  29. package/dist/dts/styles/host.d.ts +68 -0
  30. package/dist/dts/styles/style-strategy.d.ts +42 -0
  31. package/dist/dts/templating/binding-signal.d.ts +12 -27
  32. package/dist/dts/templating/binding-two-way.d.ts +22 -37
  33. package/dist/dts/templating/binding.d.ts +76 -208
  34. package/dist/dts/templating/children.d.ts +1 -1
  35. package/dist/dts/templating/compiler.d.ts +11 -13
  36. package/dist/dts/templating/html-directive.d.ts +91 -97
  37. package/dist/dts/templating/node-observation.d.ts +15 -6
  38. package/dist/dts/templating/ref.d.ts +7 -11
  39. package/dist/dts/templating/render.d.ts +296 -0
  40. package/dist/dts/templating/repeat.d.ts +23 -34
  41. package/dist/dts/templating/slotted.d.ts +1 -1
  42. package/dist/dts/templating/template.d.ts +92 -14
  43. package/dist/dts/templating/view.d.ts +81 -11
  44. package/dist/dts/templating/when.d.ts +3 -3
  45. package/dist/dts/testing/exports.d.ts +3 -0
  46. package/dist/dts/testing/fakes.d.ts +14 -0
  47. package/dist/dts/testing/fixture.d.ts +84 -0
  48. package/dist/dts/testing/timeout.d.ts +7 -0
  49. package/dist/dts/utilities.d.ts +53 -18
  50. package/dist/esm/components/attributes.js +28 -5
  51. package/dist/esm/components/{controller.js → element-controller.js} +239 -137
  52. package/dist/esm/components/fast-definitions.js +38 -30
  53. package/dist/esm/components/fast-element.js +27 -16
  54. package/dist/esm/components/hydration.js +35 -0
  55. package/dist/esm/components/install-hydration.js +2 -0
  56. package/dist/esm/context.js +5 -1
  57. package/dist/esm/debug.js +40 -5
  58. package/dist/esm/di/di.js +1430 -0
  59. package/dist/esm/dom-policy.js +337 -0
  60. package/dist/esm/dom.js +101 -0
  61. package/dist/esm/index.js +4 -2
  62. package/dist/esm/index.rollup.debug.js +3 -1
  63. package/dist/esm/index.rollup.js +3 -1
  64. package/dist/esm/interfaces.js +52 -0
  65. package/dist/esm/observation/arrays.js +303 -2
  66. package/dist/esm/observation/observable.js +88 -142
  67. package/dist/esm/observation/update-queue.js +2 -2
  68. package/dist/esm/pending-task.js +16 -0
  69. package/dist/esm/platform.js +27 -2
  70. package/dist/esm/polyfills.js +3 -61
  71. package/dist/esm/state/exports.js +3 -0
  72. package/dist/esm/state/reactive.js +34 -0
  73. package/dist/esm/state/state.js +148 -0
  74. package/dist/esm/state/visitor.js +28 -0
  75. package/dist/esm/state/watch.js +36 -0
  76. package/dist/esm/styles/css.js +4 -9
  77. package/dist/esm/styles/element-styles.js +14 -33
  78. package/dist/esm/styles/host.js +1 -0
  79. package/dist/esm/styles/style-strategy.js +1 -0
  80. package/dist/esm/templating/binding-signal.js +67 -62
  81. package/dist/esm/templating/binding-two-way.js +72 -39
  82. package/dist/esm/templating/binding.js +142 -286
  83. package/dist/esm/templating/children.js +8 -4
  84. package/dist/esm/templating/compiler.js +59 -43
  85. package/dist/esm/templating/html-directive.js +56 -75
  86. package/dist/esm/templating/node-observation.js +20 -13
  87. package/dist/esm/templating/ref.js +4 -12
  88. package/dist/esm/templating/render.js +402 -0
  89. package/dist/esm/templating/repeat.js +88 -75
  90. package/dist/esm/templating/template.js +132 -60
  91. package/dist/esm/templating/view.js +113 -29
  92. package/dist/esm/templating/when.js +5 -4
  93. package/dist/esm/testing/exports.js +3 -0
  94. package/dist/esm/testing/fakes.js +107 -0
  95. package/dist/esm/testing/fixture.js +86 -0
  96. package/dist/esm/testing/timeout.js +24 -0
  97. package/dist/esm/utilities.js +95 -95
  98. package/dist/fast-element.api.json +9487 -8326
  99. package/dist/fast-element.d.ts +847 -644
  100. package/dist/fast-element.debug.js +1993 -1166
  101. package/dist/fast-element.debug.min.js +1 -1
  102. package/dist/fast-element.js +1903 -1111
  103. package/dist/fast-element.min.js +1 -1
  104. package/dist/fast-element.untrimmed.d.ts +911 -701
  105. package/docs/api-report.md +329 -252
  106. package/package.json +38 -16
  107. package/dist/dts/hooks.d.ts +0 -20
  108. package/dist/dts/observation/behavior.d.ts +0 -19
  109. package/dist/dts/observation/splice-strategies.d.ts +0 -13
  110. package/dist/dts/templating/dom.d.ts +0 -41
  111. package/dist/esm/hooks.js +0 -32
  112. package/dist/esm/observation/splice-strategies.js +0 -400
  113. package/dist/esm/templating/dom.js +0 -49
@@ -1,26 +1,44 @@
1
- import { Controller } from "./controller.js";
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
- return class extends BaseType {
6
+ const type = class extends BaseType {
6
7
  constructor() {
7
8
  /* eslint-disable-next-line */
8
9
  super();
9
- Controller.forCustomElement(this);
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.onConnectedCallback();
16
+ this.$fastController.connect();
16
17
  }
17
18
  disconnectedCallback() {
18
- this.$fastController.onDisconnectedCallback();
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(BaseType) {
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(type, nameOrDef) {
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
- metadata(type, nameOrDef) {
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
- FASTElement.define(type, nameOrDef);
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);
@@ -0,0 +1,2 @@
1
+ import { HydratableElementController } from "./hydration.js";
2
+ HydratableElementController.install();
@@ -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 new Error(`No registration for context: '${Interface.name}'`);
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
@@ -9,21 +9,56 @@ 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 /* onlySetHTMLPolicyOnce */]: "The HTML policy can only be set once.",
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.",
14
20
  [1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
21
+ [1501 /* noRegistrationForContext */]: "No registration for Context/Interface '${name}'.",
22
+ [1502 /* noFactoryForResolver */]: "Dependency injection resolver for '${key}' returned a null factory.",
23
+ [1503 /* invalidResolverStrategy */]: "Invalid dependency injection resolver strategy specified '${strategy}'.",
24
+ [1504 /* cannotAutoregisterDependency */]: "Unable to autoregister dependency.",
25
+ [1505 /* cannotResolveKey */]: "Unable to resolve dependency injection key '${key}'.",
26
+ [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.",
27
+ [1507 /* cannotJITRegisterNonConstructor */]: "Attempted to jitRegister something that is not a constructor '${value}'. Did you forget to register this dependency?",
28
+ [1508 /* cannotJITRegisterIntrinsic */]: "Attempted to jitRegister an intrinsic type '${value}'. Did you forget to add @inject(Key)?",
29
+ [1509 /* cannotJITRegisterInterface */]: "Attempted to jitRegister an interface '${value}'.",
30
+ [1510 /* invalidResolver */]: "A valid resolver was not returned from the register method.",
31
+ [1511 /* invalidKey */]: "Key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?",
32
+ [1512 /* noDefaultResolver */]: "'${key}' not registered. Did you forget to add @singleton()?",
33
+ [1513 /* cyclicDependency */]: "Cyclic dependency found '${name}'.",
34
+ [1514 /* connectUpdateRequiresController */]: "Injected properties that are updated on changes to DOM connectivity require the target object to be an instance of FASTElement.",
15
35
  };
36
+ const allPlaceholders = /(\$\{\w+?})/g;
37
+ const placeholder = /\$\{(\w+?)}/g;
38
+ const noValues = Object.freeze({});
39
+ function formatMessage(message, values) {
40
+ return message
41
+ .split(allPlaceholders)
42
+ .map(v => {
43
+ var _a;
44
+ const replaced = v.replace(placeholder, "$1");
45
+ return String((_a = values[replaced]) !== null && _a !== void 0 ? _a : v);
46
+ })
47
+ .join("");
48
+ }
16
49
  Object.assign(FAST, {
17
50
  addMessages(messages) {
18
51
  Object.assign(debugMessages, messages);
19
52
  },
20
- warn(code, ...args) {
53
+ warn(code, values = noValues) {
21
54
  var _a;
22
- console.warn((_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning");
55
+ const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning";
56
+ console.warn(formatMessage(message, values));
23
57
  },
24
- error(code, ...args) {
58
+ error(code, values = noValues) {
25
59
  var _a;
26
- return new Error((_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error");
60
+ const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error";
61
+ return new Error(formatMessage(message, values));
27
62
  },
28
63
  });
29
64
  export {};