@microsoft/fast-element 2.0.0-beta.1 → 2.0.0-beta.11

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 (98) hide show
  1. package/CHANGELOG.json +348 -0
  2. package/CHANGELOG.md +114 -1
  3. package/dist/dts/components/attributes.d.ts +10 -0
  4. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +49 -25
  5. package/dist/dts/components/fast-definitions.d.ts +43 -9
  6. package/dist/dts/components/fast-element.d.ts +15 -21
  7. package/dist/dts/context.d.ts +157 -0
  8. package/dist/dts/di/di.d.ts +899 -0
  9. package/dist/dts/index.d.ts +2 -2
  10. package/dist/dts/interfaces.d.ts +45 -14
  11. package/dist/dts/metadata.d.ts +25 -0
  12. package/dist/dts/observation/arrays.d.ts +1 -1
  13. package/dist/dts/observation/observable.d.ts +101 -75
  14. package/dist/dts/pending-task.d.ts +20 -0
  15. package/dist/dts/platform.d.ts +7 -0
  16. package/dist/dts/polyfills.d.ts +1 -8
  17. package/dist/dts/state/exports.d.ts +3 -0
  18. package/dist/dts/state/reactive.d.ts +8 -0
  19. package/dist/dts/state/state.d.ts +141 -0
  20. package/dist/dts/state/visitor.d.ts +6 -0
  21. package/dist/dts/state/watch.d.ts +10 -0
  22. package/dist/dts/styles/css-directive.d.ts +2 -2
  23. package/dist/dts/styles/element-styles.d.ts +10 -17
  24. package/dist/dts/styles/host.d.ts +68 -0
  25. package/dist/dts/templating/binding-signal.d.ts +21 -0
  26. package/dist/dts/templating/binding-two-way.d.ts +39 -0
  27. package/dist/dts/templating/binding.d.ts +69 -294
  28. package/dist/dts/templating/children.d.ts +1 -1
  29. package/dist/dts/templating/compiler.d.ts +1 -2
  30. package/dist/dts/templating/html-directive.d.ts +93 -35
  31. package/dist/dts/templating/node-observation.d.ts +4 -5
  32. package/dist/dts/templating/ref.d.ts +5 -13
  33. package/dist/dts/templating/render.d.ts +272 -0
  34. package/dist/dts/templating/repeat.d.ts +20 -75
  35. package/dist/dts/templating/slotted.d.ts +1 -1
  36. package/dist/dts/templating/template.d.ts +12 -61
  37. package/dist/dts/templating/view.d.ts +77 -12
  38. package/dist/dts/templating/when.d.ts +3 -3
  39. package/dist/dts/testing/exports.d.ts +3 -0
  40. package/dist/dts/testing/fakes.d.ts +4 -0
  41. package/dist/dts/testing/fixture.d.ts +84 -0
  42. package/dist/dts/testing/timeout.d.ts +7 -0
  43. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
  44. package/dist/dts/utilities.d.ts +0 -18
  45. package/dist/esm/components/attributes.js +13 -4
  46. package/dist/esm/components/{controller.js → element-controller.js} +188 -109
  47. package/dist/esm/components/fast-definitions.js +38 -28
  48. package/dist/esm/components/fast-element.js +31 -12
  49. package/dist/esm/context.js +163 -0
  50. package/dist/esm/debug.js +36 -4
  51. package/dist/esm/di/di.js +1435 -0
  52. package/dist/esm/index.js +2 -1
  53. package/dist/esm/interfaces.js +4 -0
  54. package/dist/esm/metadata.js +60 -0
  55. package/dist/esm/observation/arrays.js +304 -3
  56. package/dist/esm/observation/observable.js +81 -87
  57. package/dist/esm/pending-task.js +16 -0
  58. package/dist/esm/platform.js +26 -1
  59. package/dist/esm/polyfills.js +1 -55
  60. package/dist/esm/state/exports.js +3 -0
  61. package/dist/esm/state/reactive.js +34 -0
  62. package/dist/esm/state/state.js +148 -0
  63. package/dist/esm/state/visitor.js +28 -0
  64. package/dist/esm/state/watch.js +36 -0
  65. package/dist/esm/styles/css.js +4 -4
  66. package/dist/esm/styles/element-styles.js +14 -33
  67. package/dist/esm/{observation/behavior.js → styles/host.js} +0 -0
  68. package/dist/esm/templating/binding-signal.js +83 -0
  69. package/dist/esm/templating/binding-two-way.js +103 -0
  70. package/dist/esm/templating/binding.js +134 -414
  71. package/dist/esm/templating/compiler.js +30 -7
  72. package/dist/esm/templating/html-directive.js +100 -28
  73. package/dist/esm/templating/node-observation.js +9 -8
  74. package/dist/esm/templating/ref.js +4 -12
  75. package/dist/esm/templating/render.js +391 -0
  76. package/dist/esm/templating/repeat.js +96 -72
  77. package/dist/esm/templating/template.js +11 -29
  78. package/dist/esm/templating/view.js +107 -29
  79. package/dist/esm/templating/when.js +5 -4
  80. package/dist/esm/testing/exports.js +3 -0
  81. package/dist/esm/testing/fakes.js +76 -0
  82. package/dist/esm/testing/fixture.js +86 -0
  83. package/dist/esm/testing/timeout.js +24 -0
  84. package/dist/esm/utilities.js +0 -95
  85. package/dist/fast-element.api.json +9278 -10745
  86. package/dist/fast-element.d.ts +707 -813
  87. package/dist/fast-element.debug.js +1229 -944
  88. package/dist/fast-element.debug.min.js +1 -1
  89. package/dist/fast-element.js +1191 -938
  90. package/dist/fast-element.min.js +1 -1
  91. package/dist/fast-element.untrimmed.d.ts +716 -824
  92. package/docs/api-report.md +265 -319
  93. package/package.json +39 -14
  94. package/dist/dts/hooks.d.ts +0 -20
  95. package/dist/dts/observation/behavior.d.ts +0 -19
  96. package/dist/dts/observation/splice-strategies.d.ts +0 -13
  97. package/dist/esm/hooks.js +0 -32
  98. package/dist/esm/observation/splice-strategies.js +0 -400
@@ -1,8 +1,7 @@
1
1
  import { isFunction, isString } from "../interfaces.js";
2
- import { ExecutionContext, } from "../observation/observable.js";
3
- import { bind, oneTime } from "./binding.js";
2
+ import { bind, HTMLBindingDirective, oneTime } from "./binding.js";
4
3
  import { Compiler } from "./compiler.js";
5
- import { Aspect, HTMLDirective, } from "./html-directive.js";
4
+ import { Aspect, Binding, HTMLDirective, } from "./html-directive.js";
6
5
  import { nextId } from "./markup.js";
7
6
  /**
8
7
  * A template capable of creating HTMLView instances or rendering directly to DOM.
@@ -36,9 +35,9 @@ export class ViewTemplate {
36
35
  * @param hostBindingTarget - An HTML element to target the host bindings at if different from the
37
36
  * host that the template is being attached to.
38
37
  */
39
- render(source, host, hostBindingTarget, context) {
40
- const view = this.create(hostBindingTarget !== null && hostBindingTarget !== void 0 ? hostBindingTarget : host);
41
- view.bind(source, context !== null && context !== void 0 ? context : ExecutionContext.default);
38
+ render(source, host, hostBindingTarget) {
39
+ const view = this.create(hostBindingTarget);
40
+ view.bind(source);
42
41
  view.appendTo(host);
43
42
  return view;
44
43
  }
@@ -78,12 +77,12 @@ export function html(strings, ...values) {
78
77
  let definition;
79
78
  html += currentString;
80
79
  if (isFunction(currentValue)) {
81
- html += createAspectedHTML(bind(currentValue), currentString, add);
80
+ html += createAspectedHTML(new HTMLBindingDirective(bind(currentValue)), currentString, add);
82
81
  }
83
82
  else if (isString(currentValue)) {
84
83
  const match = lastAttributeNameRegex.exec(currentString);
85
84
  if (match !== null) {
86
- const directive = bind(() => currentValue, oneTime);
85
+ const directive = new HTMLBindingDirective(oneTime(() => currentValue));
87
86
  Aspect.assign(directive, match[2]);
88
87
  html += directive.createHTML(add);
89
88
  }
@@ -91,8 +90,11 @@ export function html(strings, ...values) {
91
90
  html += currentValue;
92
91
  }
93
92
  }
93
+ else if (currentValue instanceof Binding) {
94
+ html += createAspectedHTML(new HTMLBindingDirective(currentValue), currentString, add);
95
+ }
94
96
  else if ((definition = HTMLDirective.getForInstance(currentValue)) === void 0) {
95
- html += createAspectedHTML(bind(() => currentValue, oneTime), currentString, add);
97
+ html += createAspectedHTML(new HTMLBindingDirective(oneTime(() => currentValue)), currentString, add);
96
98
  }
97
99
  else {
98
100
  if (definition.aspected) {
@@ -105,23 +107,3 @@ export function html(strings, ...values) {
105
107
  }
106
108
  return new ViewTemplate(html + strings[strings.length - 1], factories);
107
109
  }
108
- /**
109
- * Transforms a template literal string into a ChildViewTemplate.
110
- * @param strings - The string fragments that are interpolated with the values.
111
- * @param values - The values that are interpolated with the string fragments.
112
- * @remarks
113
- * The html helper supports interpolation of strings, numbers, binding expressions,
114
- * other template instances, and Directive instances.
115
- * @public
116
- */
117
- export const child = html;
118
- /**
119
- * Transforms a template literal string into an ItemViewTemplate.
120
- * @param strings - The string fragments that are interpolated with the values.
121
- * @param values - The values that are interpolated with the string fragments.
122
- * @remarks
123
- * The html helper supports interpolation of strings, numbers, binding expressions,
124
- * other template instances, and Directive instances.
125
- * @public
126
- */
127
- export const item = html;
@@ -1,3 +1,4 @@
1
+ import { ExecutionContext, Observable, SourceLifetime, } from "../observation/observable.js";
1
2
  function removeNodeSequence(firstNode, lastNode) {
2
3
  const parent = firstNode.parentNode;
3
4
  let current = firstNode;
@@ -24,17 +25,87 @@ export class HTMLView {
24
25
  this.factories = factories;
25
26
  this.targets = targets;
26
27
  this.behaviors = null;
28
+ this.unbindables = [];
27
29
  /**
28
30
  * The data that the view is bound to.
29
31
  */
30
32
  this.source = null;
33
+ /**
34
+ * Indicates whether the controller is bound.
35
+ */
36
+ this.isBound = false;
37
+ /**
38
+ * Indicates how the source's lifetime relates to the controller's lifetime.
39
+ */
40
+ this.sourceLifetime = SourceLifetime.unknown;
31
41
  /**
32
42
  * The execution context the view is running within.
33
43
  */
34
- this.context = null;
44
+ this.context = this;
45
+ /**
46
+ * The index of the current item within a repeat context.
47
+ */
48
+ this.index = 0;
49
+ /**
50
+ * The length of the current collection within a repeat context.
51
+ */
52
+ this.length = 0;
35
53
  this.firstChild = fragment.firstChild;
36
54
  this.lastChild = fragment.lastChild;
37
55
  }
56
+ /**
57
+ * The current event within an event handler.
58
+ */
59
+ get event() {
60
+ return ExecutionContext.getEvent();
61
+ }
62
+ /**
63
+ * Indicates whether the current item within a repeat context
64
+ * has an even index.
65
+ */
66
+ get isEven() {
67
+ return this.index % 2 === 0;
68
+ }
69
+ /**
70
+ * Indicates whether the current item within a repeat context
71
+ * has an odd index.
72
+ */
73
+ get isOdd() {
74
+ return this.index % 2 !== 0;
75
+ }
76
+ /**
77
+ * Indicates whether the current item within a repeat context
78
+ * is the first item in the collection.
79
+ */
80
+ get isFirst() {
81
+ return this.index === 0;
82
+ }
83
+ /**
84
+ * Indicates whether the current item within a repeat context
85
+ * is somewhere in the middle of the collection.
86
+ */
87
+ get isInMiddle() {
88
+ return !this.isFirst && !this.isLast;
89
+ }
90
+ /**
91
+ * Indicates whether the current item within a repeat context
92
+ * is the last item in the collection.
93
+ */
94
+ get isLast() {
95
+ return this.index === this.length - 1;
96
+ }
97
+ /**
98
+ * Returns the typed event detail of a custom event.
99
+ */
100
+ eventDetail() {
101
+ return this.event.detail;
102
+ }
103
+ /**
104
+ * Returns the typed event target of the event.
105
+ */
106
+ eventTarget() {
107
+ return this.event.target;
108
+ }
38
109
  /**
39
110
  * Appends the view's DOM nodes to the referenced node.
40
111
  * @param node - The parent node to append the view's DOM nodes to.
@@ -51,8 +122,10 @@ export class HTMLView {
51
122
  node.parentNode.insertBefore(this.fragment, node);
52
123
  }
53
124
  else {
54
- const parentNode = node.parentNode;
55
125
  const end = this.lastChild;
126
+ if (node.previousSibling === end)
127
+ return;
128
+ const parentNode = node.parentNode;
56
129
  let current = this.firstChild;
57
130
  let next;
58
131
  while (current !== end) {
@@ -87,58 +160,61 @@ export class HTMLView {
87
160
  removeNodeSequence(this.firstChild, this.lastChild);
88
161
  this.unbind();
89
162
  }
163
+ onUnbind(behavior) {
164
+ this.unbindables.push(behavior);
165
+ }
90
166
  /**
91
167
  * Binds a view's behaviors to its binding source.
92
168
  * @param source - The binding source for the view's binding behaviors.
93
169
  * @param context - The execution context to run the behaviors within.
94
170
  */
95
- bind(source, context) {
96
- let behaviors = this.behaviors;
97
- const oldSource = this.source;
98
- if (oldSource === source) {
171
+ bind(source, context = this) {
172
+ if (this.source === source) {
99
173
  return;
100
174
  }
101
- this.source = source;
102
- this.context = context;
103
- const targets = this.targets;
104
- if (oldSource !== null) {
105
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
106
- const current = behaviors[i];
107
- current.unbind(oldSource, context, targets);
108
- current.bind(source, context, targets);
109
- }
110
- }
111
- else if (behaviors === null) {
175
+ let behaviors = this.behaviors;
176
+ if (behaviors === null) {
177
+ this.source = source;
178
+ this.context = context;
112
179
  this.behaviors = behaviors = new Array(this.factories.length);
113
180
  const factories = this.factories;
114
181
  for (let i = 0, ii = factories.length; i < ii; ++i) {
115
- const behavior = factories[i].createBehavior(targets);
116
- behavior.bind(source, context, targets);
182
+ const behavior = factories[i].createBehavior();
183
+ behavior.bind(this);
117
184
  behaviors[i] = behavior;
118
185
  }
119
186
  }
120
187
  else {
188
+ if (this.source !== null) {
189
+ this.evaluateUnbindables();
190
+ }
191
+ this.isBound = false;
192
+ this.source = source;
193
+ this.context = context;
121
194
  for (let i = 0, ii = behaviors.length; i < ii; ++i) {
122
- behaviors[i].bind(source, context, targets);
195
+ behaviors[i].bind(this);
123
196
  }
124
197
  }
198
+ this.isBound = true;
125
199
  }
126
200
  /**
127
201
  * Unbinds a view's behaviors from its binding source.
128
202
  */
129
203
  unbind() {
130
- const oldSource = this.source;
131
- if (oldSource === null) {
204
+ if (!this.isBound || this.source === null) {
132
205
  return;
133
206
  }
134
- const targets = this.targets;
135
- const context = this.context;
136
- const behaviors = this.behaviors;
137
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
138
- behaviors[i].unbind(oldSource, context, targets);
139
- }
207
+ this.evaluateUnbindables();
140
208
  this.source = null;
141
- this.context = null;
209
+ this.context = this;
210
+ this.isBound = false;
211
+ }
212
+ evaluateUnbindables() {
213
+ const unbindables = this.unbindables;
214
+ for (let i = 0, ii = unbindables.length; i < ii; ++i) {
215
+ unbindables[i].unbind(this);
216
+ }
217
+ unbindables.length = 0;
142
218
  }
143
219
  /**
144
220
  * Efficiently disposes of a contiguous range of synthetic view instances.
@@ -154,3 +230,5 @@ export class HTMLView {
154
230
  }
155
231
  }
156
232
  }
233
+ Observable.defineProperty(HTMLView.prototype, "index");
234
+ Observable.defineProperty(HTMLView.prototype, "length");
@@ -1,14 +1,15 @@
1
1
  import { isFunction } from "../interfaces.js";
2
2
  /**
3
3
  * A directive that enables basic conditional rendering in a template.
4
- * @param binding - The condition to test for rendering.
4
+ * @param condition - The condition to test for rendering.
5
5
  * @param templateOrTemplateBinding - The template or a binding that gets
6
6
  * the template to render when the condition is true.
7
7
  * @public
8
8
  */
9
- export function when(binding, templateOrTemplateBinding) {
10
- const getTemplate = isFunction(templateOrTemplateBinding)
9
+ export function when(condition, templateOrTemplateBinding) {
10
+ const dataBinding = isFunction(condition) ? condition : () => condition;
11
+ const templateBinding = isFunction(templateOrTemplateBinding)
11
12
  ? templateOrTemplateBinding
12
13
  : () => templateOrTemplateBinding;
13
- return (source, context) => binding(source, context) ? getTemplate(source, context) : null;
14
+ return (source, context) => dataBinding(source, context) ? templateBinding(source, context) : null;
14
15
  }
@@ -0,0 +1,3 @@
1
+ export { timeout } from "./timeout.js";
2
+ export * from "./fixture.js";
3
+ export * from "./fakes.js";
@@ -0,0 +1,76 @@
1
+ import { ExecutionContext } from "../index.js";
2
+ export const Fake = Object.freeze({
3
+ executionContext(parent, parentContext) {
4
+ return {
5
+ /**
6
+ * The index of the current item within a repeat context.
7
+ */
8
+ index: 0,
9
+ /**
10
+ * The length of the current collection within a repeat context.
11
+ */
12
+ length: 0,
13
+ /**
14
+ * The parent data source within a nested context.
15
+ */
16
+ parent: parent,
17
+ /**
18
+ * The parent execution context when in nested context scenarios.
19
+ */
20
+ parentContext: parentContext,
21
+ /**
22
+ * The current event within an event handler.
23
+ */
24
+ get event() {
25
+ return ExecutionContext.getEvent();
26
+ },
27
+ /**
28
+ * Indicates whether the current item within a repeat context
29
+ * has an even index.
30
+ */
31
+ get isEven() {
32
+ return this.index % 2 === 0;
33
+ },
34
+ /**
35
+ * Indicates whether the current item within a repeat context
36
+ * has an odd index.
37
+ */
38
+ get isOdd() {
39
+ return this.index % 2 !== 0;
40
+ },
41
+ /**
42
+ * Indicates whether the current item within a repeat context
43
+ * is the first item in the collection.
44
+ */
45
+ get isFirst() {
46
+ return this.index === 0;
47
+ },
48
+ /**
49
+ * Indicates whether the current item within a repeat context
50
+ * is somewhere in the middle of the collection.
51
+ */
52
+ get isInMiddle() {
53
+ return !this.isFirst && !this.isLast;
54
+ },
55
+ /**
56
+ * Indicates whether the current item within a repeat context
57
+ * is the last item in the collection.
58
+ */
59
+ get isLast() {
60
+ return this.index === this.length - 1;
61
+ },
62
+ /**
63
+ * Returns the typed event detail of a custom event.
64
+ */
65
+ eventDetail() {
66
+ return this.event.detail;
67
+ },
68
+ /**
69
+ * Returns the typed event target of the event.
70
+ */
71
+ eventTarget() {
72
+ return this.event.target;
73
+ },
74
+ };
75
+ },
76
+ });
@@ -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
+ }
@@ -1,98 +1,3 @@
1
- import { ArrayObserver } from "./index.debug.js";
2
- import { isFunction } from "./interfaces.js";
3
- import { Observable } from "./observation/observable.js";
4
- function shouldTraverse(value, traversed) {
5
- return (value !== null &&
6
- value !== void 0 &&
7
- typeof value === "object" &&
8
- !traversed.has(value));
9
- }
10
- function traverseObject(object, deep, visitor, data, traversed) {
11
- if (!shouldTraverse(object, traversed)) {
12
- return;
13
- }
14
- traversed.add(object);
15
- if (Array.isArray(object)) {
16
- visitor.visitArray(object, data);
17
- for (const item of object) {
18
- traverseObject(item, deep, visitor, data, traversed);
19
- }
20
- }
21
- else {
22
- visitor.visitObject(object, data);
23
- for (const key in object) {
24
- const value = object[key];
25
- visitor.visitProperty(object, key, value, data);
26
- if (deep) {
27
- traverseObject(value, deep, visitor, data, traversed);
28
- }
29
- }
30
- }
31
- }
32
- const noop = () => void 0;
33
- const observed = new WeakSet();
34
- const makeObserverVisitor = {
35
- visitObject: noop,
36
- visitArray: noop,
37
- visitProperty(object, propertyName, value) {
38
- Reflect.defineProperty(object, propertyName, {
39
- enumerable: true,
40
- get() {
41
- Observable.track(object, propertyName);
42
- return value;
43
- },
44
- set(newValue) {
45
- if (value !== newValue) {
46
- value = newValue;
47
- Observable.notify(object, propertyName);
48
- }
49
- },
50
- });
51
- },
52
- };
53
- function watchObject(object, data) {
54
- const notifier = Observable.getNotifier(object);
55
- notifier.subscribe(data.subscriber);
56
- data.notifiers.push(notifier);
57
- }
58
- const watchVisitor = {
59
- visitProperty: noop,
60
- visitObject: watchObject,
61
- visitArray: watchObject,
62
- };
63
- /**
64
- * Converts a plain object to an observable object.
65
- * @param object - The object to make observable.
66
- * @param deep - Indicates whether or not to deeply convert the oject.
67
- * @returns The converted object.
68
- * @beta
69
- */
70
- export function makeObservable(object, deep = false) {
71
- traverseObject(object, deep, makeObserverVisitor, void 0, observed);
72
- return object;
73
- }
74
- /**
75
- * Deeply subscribes to changes in existing observable objects.
76
- * @param object - The observable object to watch.
77
- * @param subscriber - The handler to call when changes are made to the object.
78
- * @returns A disposable that can be used to unsubscribe from change updates.
79
- * @beta
80
- */
81
- export function watch(object, subscriber) {
82
- const data = {
83
- notifiers: [],
84
- subscriber: isFunction(subscriber) ? { handleChange: subscriber } : subscriber,
85
- };
86
- ArrayObserver.enable();
87
- traverseObject(object, true, watchVisitor, data, new Set());
88
- return {
89
- dispose() {
90
- for (const n of data.notifiers) {
91
- n.unsubscribe(data.subscriber);
92
- }
93
- },
94
- };
95
- }
96
1
  /**
97
2
  * Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
98
3
  * When the parent of a node is a shadow-root, it will return the host