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

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 (54) 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/hooks.d.ts +2 -2
  8. package/dist/dts/interfaces.d.ts +40 -7
  9. package/dist/dts/observation/observable.d.ts +19 -13
  10. package/dist/dts/styles/element-styles.d.ts +6 -0
  11. package/dist/dts/templating/binding-signal.d.ts +10 -27
  12. package/dist/dts/templating/binding-two-way.d.ts +16 -41
  13. package/dist/dts/templating/binding.d.ts +79 -118
  14. package/dist/dts/templating/html-directive.d.ts +31 -3
  15. package/dist/dts/templating/render.d.ts +277 -0
  16. package/dist/dts/templating/repeat.d.ts +12 -16
  17. package/dist/dts/templating/template.d.ts +3 -3
  18. package/dist/dts/templating/when.d.ts +3 -3
  19. package/dist/dts/testing/exports.d.ts +2 -0
  20. package/dist/dts/testing/fixture.d.ts +90 -0
  21. package/dist/dts/testing/timeout.d.ts +7 -0
  22. package/dist/esm/components/fast-definitions.js +25 -27
  23. package/dist/esm/components/fast-element.js +20 -11
  24. package/dist/esm/context.js +5 -1
  25. package/dist/esm/debug.js +36 -4
  26. package/dist/esm/di/di.js +1351 -0
  27. package/dist/esm/observation/arrays.js +303 -2
  28. package/dist/esm/observation/observable.js +11 -6
  29. package/dist/esm/platform.js +1 -1
  30. package/dist/esm/styles/element-styles.js +14 -0
  31. package/dist/esm/templating/binding-signal.js +56 -61
  32. package/dist/esm/templating/binding-two-way.js +56 -34
  33. package/dist/esm/templating/binding.js +137 -156
  34. package/dist/esm/templating/compiler.js +30 -7
  35. package/dist/esm/templating/html-directive.js +16 -2
  36. package/dist/esm/templating/render.js +392 -0
  37. package/dist/esm/templating/repeat.js +57 -40
  38. package/dist/esm/templating/template.js +8 -5
  39. package/dist/esm/templating/view.js +3 -1
  40. package/dist/esm/templating/when.js +5 -4
  41. package/dist/esm/testing/exports.js +2 -0
  42. package/dist/esm/testing/fixture.js +88 -0
  43. package/dist/esm/testing/timeout.js +24 -0
  44. package/dist/fast-element.api.json +2828 -2758
  45. package/dist/fast-element.d.ts +218 -230
  46. package/dist/fast-element.debug.js +656 -257
  47. package/dist/fast-element.debug.min.js +1 -1
  48. package/dist/fast-element.js +620 -253
  49. package/dist/fast-element.min.js +1 -1
  50. package/dist/fast-element.untrimmed.d.ts +226 -235
  51. package/docs/api-report.md +88 -91
  52. package/package.json +15 -6
  53. package/dist/dts/observation/splice-strategies.d.ts +0 -13
  54. package/dist/esm/observation/splice-strategies.js +0 -400
@@ -0,0 +1,88 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { FASTElementDefinition } from "../components/fast-definitions.js";
11
+ import { ExecutionContext } from "../observation/observable.js";
12
+ import { ViewTemplate } from "../templating/template.js";
13
+ function findElement(view) {
14
+ let current = view.firstChild;
15
+ while (current !== null && current.nodeType !== 1) {
16
+ current = current.nextSibling;
17
+ }
18
+ return current;
19
+ }
20
+ /**
21
+ * Creates a random, unique name suitable for use as a Custom Element name.
22
+ * @public
23
+ */
24
+ export function uniqueElementName(prefix = "fast-unique") {
25
+ return `${prefix}-${Math.random().toString(36).substring(7)}`;
26
+ }
27
+ /**
28
+ * Creates a test fixture suitable for testing custom elements, templates, and bindings.
29
+ * @param templateNameOrType An HTML template or single element name to create the fixture for.
30
+ * @param options Enables customizing fixture creation behavior.
31
+ * @remarks
32
+ * Yields control to the caller one Microtask later, in order to
33
+ * ensure that the DOM has settled.
34
+ * @public
35
+ */
36
+ export function fixture(templateNameOrType, options = {}) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const document = options.document || globalThis.document;
39
+ const parent = options.parent || document.createElement("div");
40
+ const source = options.source || {};
41
+ const context = options.context || ExecutionContext.default;
42
+ if (typeof templateNameOrType === "function") {
43
+ const def = FASTElementDefinition.getByType(templateNameOrType);
44
+ if (!def) {
45
+ throw new Error("Missing FASTElement definition.");
46
+ }
47
+ templateNameOrType = def.name;
48
+ }
49
+ if (typeof templateNameOrType === "string") {
50
+ const html = `<${templateNameOrType}></${templateNameOrType}>`;
51
+ templateNameOrType = new ViewTemplate(html, {});
52
+ }
53
+ const view = templateNameOrType.create();
54
+ const element = findElement(view);
55
+ let isConnected = false;
56
+ view.bind(source, context);
57
+ view.appendTo(parent);
58
+ customElements.upgrade(parent);
59
+ // Hook into the Microtask Queue to ensure the DOM is settled
60
+ // before yielding control to the caller.
61
+ yield Promise.resolve();
62
+ const connect = () => __awaiter(this, void 0, void 0, function* () {
63
+ if (isConnected) {
64
+ return;
65
+ }
66
+ isConnected = true;
67
+ document.body.appendChild(parent);
68
+ yield Promise.resolve();
69
+ });
70
+ const disconnect = () => __awaiter(this, void 0, void 0, function* () {
71
+ if (!isConnected) {
72
+ return;
73
+ }
74
+ isConnected = false;
75
+ document.body.removeChild(parent);
76
+ yield Promise.resolve();
77
+ });
78
+ return {
79
+ document,
80
+ template: templateNameOrType,
81
+ view,
82
+ parent,
83
+ element,
84
+ connect,
85
+ disconnect,
86
+ };
87
+ });
88
+ }
@@ -0,0 +1,24 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * A timeout helper for use in tests.
12
+ * @param timeout The length of the timeout.
13
+ * @returns A promise that resolves once the configured time has elapsed.
14
+ * @public
15
+ */
16
+ export function timeout(timeout = 0) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ return new Promise((resolve, reject) => {
19
+ window.setTimeout(() => {
20
+ resolve(void 0);
21
+ }, timeout);
22
+ });
23
+ });
24
+ }