@microsoft/fast-element 1.10.5 → 2.0.0-beta.10

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 (122) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +629 -6
  3. package/CHANGELOG.md +152 -5
  4. package/dist/dts/components/attributes.d.ts +14 -1
  5. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +32 -32
  6. package/dist/dts/components/fast-definitions.d.ts +51 -11
  7. package/dist/dts/components/fast-element.d.ts +18 -23
  8. package/dist/dts/context.d.ts +157 -0
  9. package/dist/{esm/observation/behavior.js → dts/debug.d.ts} +0 -0
  10. package/dist/dts/di/di.d.ts +899 -0
  11. package/dist/dts/index.d.ts +17 -16
  12. package/dist/dts/index.debug.d.ts +2 -0
  13. package/dist/dts/index.rollup.d.ts +2 -0
  14. package/dist/dts/index.rollup.debug.d.ts +3 -0
  15. package/dist/dts/interfaces.d.ts +176 -0
  16. package/dist/dts/metadata.d.ts +25 -0
  17. package/dist/dts/observation/arrays.d.ts +207 -0
  18. package/dist/dts/observation/notifier.d.ts +18 -18
  19. package/dist/dts/observation/observable.d.ts +117 -34
  20. package/dist/dts/observation/update-queue.d.ts +40 -0
  21. package/dist/dts/pending-task.d.ts +20 -0
  22. package/dist/dts/platform.d.ts +23 -66
  23. package/dist/dts/polyfills.d.ts +8 -0
  24. package/dist/dts/state/exports.d.ts +3 -0
  25. package/dist/dts/state/reactive.d.ts +8 -0
  26. package/dist/dts/state/state.d.ts +141 -0
  27. package/dist/dts/state/visitor.d.ts +6 -0
  28. package/dist/dts/state/watch.d.ts +10 -0
  29. package/dist/dts/styles/css-directive.d.ts +44 -6
  30. package/dist/dts/styles/css.d.ts +19 -3
  31. package/dist/dts/styles/element-styles.d.ts +49 -63
  32. package/dist/dts/styles/host.d.ts +68 -0
  33. package/dist/dts/templating/binding-signal.d.ts +21 -0
  34. package/dist/dts/templating/binding-two-way.d.ts +39 -0
  35. package/dist/dts/templating/binding.d.ts +101 -70
  36. package/dist/dts/templating/children.d.ts +18 -15
  37. package/dist/dts/templating/compiler.d.ts +46 -28
  38. package/dist/dts/templating/dom.d.ts +41 -0
  39. package/dist/dts/templating/html-directive.d.ts +239 -45
  40. package/dist/dts/templating/markup.d.ts +48 -0
  41. package/dist/dts/templating/node-observation.d.ts +45 -30
  42. package/dist/dts/templating/ref.d.ts +6 -20
  43. package/dist/dts/templating/render.d.ts +272 -0
  44. package/dist/dts/templating/repeat.d.ts +36 -33
  45. package/dist/dts/templating/slotted.d.ts +13 -14
  46. package/dist/dts/templating/template.d.ts +28 -22
  47. package/dist/dts/templating/view.d.ts +82 -24
  48. package/dist/dts/templating/when.d.ts +3 -3
  49. package/dist/dts/testing/exports.d.ts +3 -0
  50. package/dist/dts/testing/fakes.d.ts +4 -0
  51. package/dist/dts/testing/fixture.d.ts +84 -0
  52. package/dist/dts/testing/timeout.d.ts +7 -0
  53. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  54. package/dist/dts/utilities.d.ts +22 -0
  55. package/dist/esm/components/attributes.js +38 -28
  56. package/dist/esm/components/{controller.js → element-controller.js} +150 -140
  57. package/dist/esm/components/fast-definitions.js +48 -46
  58. package/dist/esm/components/fast-element.js +31 -12
  59. package/dist/esm/context.js +163 -0
  60. package/dist/esm/debug.js +61 -0
  61. package/dist/esm/di/di.js +1435 -0
  62. package/dist/esm/index.debug.js +2 -0
  63. package/dist/esm/index.js +20 -14
  64. package/dist/esm/index.rollup.debug.js +3 -0
  65. package/dist/esm/index.rollup.js +2 -0
  66. package/dist/esm/interfaces.js +12 -1
  67. package/dist/esm/metadata.js +60 -0
  68. package/dist/esm/observation/arrays.js +570 -0
  69. package/dist/esm/observation/notifier.js +27 -35
  70. package/dist/esm/observation/observable.js +116 -149
  71. package/dist/esm/observation/update-queue.js +67 -0
  72. package/dist/esm/pending-task.js +16 -0
  73. package/dist/esm/platform.js +60 -42
  74. package/dist/esm/polyfills.js +85 -0
  75. package/dist/esm/state/exports.js +3 -0
  76. package/dist/esm/state/reactive.js +34 -0
  77. package/dist/esm/state/state.js +148 -0
  78. package/dist/esm/state/visitor.js +28 -0
  79. package/dist/esm/state/watch.js +36 -0
  80. package/dist/esm/styles/css-directive.js +29 -13
  81. package/dist/esm/styles/css.js +29 -42
  82. package/dist/esm/styles/element-styles.js +79 -104
  83. package/dist/esm/styles/host.js +1 -0
  84. package/dist/esm/templating/binding-signal.js +83 -0
  85. package/dist/esm/templating/binding-two-way.js +103 -0
  86. package/dist/esm/templating/binding.js +189 -159
  87. package/dist/esm/templating/children.js +33 -23
  88. package/dist/esm/templating/compiler.js +258 -152
  89. package/dist/esm/templating/dom.js +49 -0
  90. package/dist/esm/templating/html-directive.js +193 -36
  91. package/dist/esm/templating/markup.js +75 -0
  92. package/dist/esm/templating/node-observation.js +51 -45
  93. package/dist/esm/templating/ref.js +8 -25
  94. package/dist/esm/templating/render.js +391 -0
  95. package/dist/esm/templating/repeat.js +83 -79
  96. package/dist/esm/templating/slotted.js +23 -20
  97. package/dist/esm/templating/template.js +51 -93
  98. package/dist/esm/templating/view.js +125 -46
  99. package/dist/esm/templating/when.js +6 -4
  100. package/dist/esm/testing/exports.js +3 -0
  101. package/dist/esm/testing/fakes.js +76 -0
  102. package/dist/esm/testing/fixture.js +86 -0
  103. package/dist/esm/testing/timeout.js +24 -0
  104. package/dist/esm/utilities.js +44 -0
  105. package/dist/fast-element.api.json +12153 -5373
  106. package/dist/fast-element.d.ts +1448 -696
  107. package/dist/fast-element.debug.js +4107 -0
  108. package/dist/fast-element.debug.min.js +1 -0
  109. package/dist/fast-element.js +3817 -4029
  110. package/dist/fast-element.min.js +1 -1
  111. package/dist/fast-element.untrimmed.d.ts +2814 -0
  112. package/docs/api-report.md +567 -254
  113. package/docs/fast-element-2-changes.md +15 -0
  114. package/karma.conf.cjs +6 -17
  115. package/package.json +76 -15
  116. package/dist/dts/dom.d.ts +0 -112
  117. package/dist/dts/observation/array-change-records.d.ts +0 -48
  118. package/dist/dts/observation/array-observer.d.ts +0 -9
  119. package/dist/dts/observation/behavior.d.ts +0 -19
  120. package/dist/esm/dom.js +0 -207
  121. package/dist/esm/observation/array-change-records.js +0 -326
  122. package/dist/esm/observation/array-observer.js +0 -177
@@ -0,0 +1,86 @@
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 { ViewTemplate } from "../templating/template.js";
12
+ function findElement(view) {
13
+ let current = view.firstChild;
14
+ while (current !== null && current.nodeType !== 1) {
15
+ current = current.nextSibling;
16
+ }
17
+ return current;
18
+ }
19
+ /**
20
+ * Creates a random, unique name suitable for use as a Custom Element name.
21
+ * @public
22
+ */
23
+ export function uniqueElementName(prefix = "fast-unique") {
24
+ return `${prefix}-${Math.random().toString(36).substring(7)}`;
25
+ }
26
+ /**
27
+ * Creates a test fixture suitable for testing custom elements, templates, and bindings.
28
+ * @param templateNameOrType An HTML template or single element name to create the fixture for.
29
+ * @param options Enables customizing fixture creation behavior.
30
+ * @remarks
31
+ * Yields control to the caller one Microtask later, in order to
32
+ * ensure that the DOM has settled.
33
+ * @public
34
+ */
35
+ export function fixture(templateNameOrType, options = {}) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const document = options.document || globalThis.document;
38
+ const parent = options.parent || document.createElement("div");
39
+ const source = options.source || {};
40
+ if (typeof templateNameOrType === "function") {
41
+ const def = FASTElementDefinition.getByType(templateNameOrType);
42
+ if (!def) {
43
+ throw new Error("Missing FASTElement definition.");
44
+ }
45
+ templateNameOrType = def.name;
46
+ }
47
+ if (typeof templateNameOrType === "string") {
48
+ const html = `<${templateNameOrType}></${templateNameOrType}>`;
49
+ templateNameOrType = new ViewTemplate(html, {});
50
+ }
51
+ const view = templateNameOrType.create();
52
+ const element = findElement(view);
53
+ let isConnected = false;
54
+ view.bind(source);
55
+ view.appendTo(parent);
56
+ customElements.upgrade(parent);
57
+ // Hook into the Microtask Queue to ensure the DOM is settled
58
+ // before yielding control to the caller.
59
+ yield Promise.resolve();
60
+ const connect = () => __awaiter(this, void 0, void 0, function* () {
61
+ if (isConnected) {
62
+ return;
63
+ }
64
+ isConnected = true;
65
+ document.body.appendChild(parent);
66
+ yield Promise.resolve();
67
+ });
68
+ const disconnect = () => __awaiter(this, void 0, void 0, function* () {
69
+ if (!isConnected) {
70
+ return;
71
+ }
72
+ isConnected = false;
73
+ document.body.removeChild(parent);
74
+ yield Promise.resolve();
75
+ });
76
+ return {
77
+ document,
78
+ template: templateNameOrType,
79
+ view,
80
+ parent,
81
+ element,
82
+ connect,
83
+ disconnect,
84
+ };
85
+ });
86
+ }
@@ -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
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
3
+ * When the parent of a node is a shadow-root, it will return the host
4
+ * element of the shadow root. Otherwise it will return the parent node or null if
5
+ * no parent node exists.
6
+ * @param element - The element for which to retrieve the composed parent
7
+ *
8
+ * @public
9
+ */
10
+ export function composedParent(element) {
11
+ const parentNode = element.parentElement;
12
+ if (parentNode) {
13
+ return parentNode;
14
+ }
15
+ else {
16
+ const rootNode = element.getRootNode();
17
+ if (rootNode.host instanceof HTMLElement) {
18
+ // this is shadow-root
19
+ return rootNode.host;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ /**
25
+ * Determines if the reference element contains the test element in a "composed" DOM tree that
26
+ * ignores shadow DOM boundaries.
27
+ *
28
+ * Returns true of the test element is a descendent of the reference, or exist in
29
+ * a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
30
+ * @param reference - The element to test for containment against.
31
+ * @param test - The element being tested for containment.
32
+ *
33
+ * @public
34
+ */
35
+ export function composedContains(reference, test) {
36
+ let current = test;
37
+ while (current !== null) {
38
+ if (current === reference) {
39
+ return true;
40
+ }
41
+ current = composedParent(current);
42
+ }
43
+ return false;
44
+ }