@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.2
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.md +12 -0
- package/dist/command/command.api.json +7857 -0
- package/dist/context/context.api.json +1084 -0
- package/dist/declarative/declarative.api.json +8130 -0
- package/dist/definition-schema/definition-schema.api.json +2689 -0
- package/dist/di/di.api.json +4945 -0
- package/dist/dts/arrays.d.ts +2 -0
- package/dist/dts/binding/binding.d.ts +59 -0
- package/dist/dts/binding/exports.d.ts +9 -0
- package/dist/dts/binding/normalize.d.ts +9 -0
- package/dist/dts/binding/one-time.d.ts +11 -0
- package/dist/dts/binding/one-way.d.ts +20 -0
- package/dist/dts/binding/signal.d.ts +36 -0
- package/dist/dts/binding/two-way.d.ts +44 -0
- package/dist/dts/command/behavior.d.ts +94 -0
- package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
- package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
- package/dist/dts/command/command.d.ts +79 -0
- package/dist/dts/command/component-registry.d.ts +50 -0
- package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
- package/dist/dts/command/index.d.ts +21 -0
- package/dist/dts/command/registry.d.ts +201 -0
- package/dist/dts/command/schema-validation.d.ts +45 -0
- package/dist/dts/command/types.d.ts +332 -0
- package/dist/dts/command/validation.d.ts +116 -0
- package/dist/dts/command/weak-ref.d.ts +11 -0
- package/dist/dts/components/attributes.d.ts +153 -0
- package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
- package/dist/dts/components/element-controller.d.ts +349 -0
- package/dist/dts/components/element-hydration.d.ts +2 -0
- package/dist/dts/components/enable-hydration.d.ts +66 -0
- package/dist/dts/components/fast-definitions.d.ts +211 -0
- package/dist/dts/components/fast-element-registry.d.ts +23 -0
- package/dist/dts/components/fast-element.d.ts +91 -0
- package/dist/dts/components/hydration-tracker.d.ts +110 -0
- package/dist/dts/components/hydration.d.ts +52 -0
- package/dist/dts/components/schema.d.ts +205 -0
- package/dist/dts/context.d.ts +171 -0
- package/dist/dts/debug.d.ts +5 -0
- package/dist/dts/declarative/attribute-map.d.ts +58 -0
- package/dist/dts/declarative/debug.d.ts +4 -0
- package/dist/dts/declarative/index.d.ts +14 -0
- package/dist/dts/declarative/interfaces.d.ts +8 -0
- package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
- package/dist/dts/declarative/observer-map.d.ts +89 -0
- package/dist/dts/declarative/runtime.d.ts +5 -0
- package/dist/dts/declarative/syntax.d.ts +21 -0
- package/dist/dts/declarative/template-bridge.d.ts +33 -0
- package/dist/dts/declarative/template-parser.d.ts +98 -0
- package/dist/dts/declarative/template.d.ts +9 -0
- package/dist/dts/declarative/utilities.d.ts +358 -0
- package/dist/dts/definition-schema/api.d.ts +42 -0
- package/dist/dts/definition-schema/cem.d.ts +78 -0
- package/dist/dts/definition-schema/extension.d.ts +18 -0
- package/dist/dts/definition-schema/extract.d.ts +38 -0
- package/dist/dts/definition-schema/index.d.ts +9 -0
- package/dist/dts/definition-schema/storage.d.ts +35 -0
- package/dist/dts/definition-schema/types.d.ts +176 -0
- package/dist/dts/dev-mode.d.ts +13 -0
- package/dist/dts/di/di.d.ts +894 -0
- package/dist/dts/dom-policy.d.ts +101 -0
- package/dist/dts/dom.d.ts +88 -0
- package/dist/dts/hydration/diagnostics.d.ts +93 -0
- package/dist/dts/hydration/exports.d.ts +18 -0
- package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
- package/dist/dts/hydration/messages.d.ts +62 -0
- package/dist/dts/hydration/runtime.d.ts +7 -0
- package/dist/dts/hydration/target-builder.d.ts +107 -0
- package/dist/dts/index.d.ts +51 -0
- package/dist/dts/index.debug.d.ts +1 -0
- package/dist/dts/index.rollup.d.ts +1 -0
- package/dist/dts/index.rollup.debug.d.ts +1 -0
- package/dist/dts/interfaces.d.ts +106 -0
- package/dist/dts/metadata.d.ts +26 -0
- package/dist/dts/observation/arrays.d.ts +248 -0
- package/dist/dts/observation/notifier.d.ts +127 -0
- package/dist/dts/observation/observable.d.ts +276 -0
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/observation/volatile.d.ts +9 -0
- package/dist/dts/platform.d.ts +87 -0
- package/dist/dts/registry.d.ts +2 -0
- package/dist/dts/render.d.ts +7 -0
- package/dist/dts/schema.d.ts +1 -0
- package/dist/dts/scoped/detection.d.ts +55 -0
- package/dist/dts/scoped/index.d.ts +68 -0
- package/dist/dts/scoped/mixin.d.ts +118 -0
- package/dist/dts/scoped/registry.d.ts +76 -0
- package/dist/dts/scoped/types.d.ts +48 -0
- 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 +50 -0
- package/dist/dts/styles/css.d.ts +34 -0
- package/dist/dts/styles/element-styles.d.ts +61 -0
- package/dist/dts/styles/host.d.ts +65 -0
- package/dist/dts/styles/style-strategy.d.ts +42 -0
- package/dist/dts/templating/children.d.ts +62 -0
- package/dist/dts/templating/compiler.d.ts +54 -0
- package/dist/dts/templating/html-binding-directive.d.ts +155 -0
- package/dist/dts/templating/html-directive.d.ts +218 -0
- package/dist/dts/templating/html.d.ts +1 -0
- package/dist/dts/templating/hydration-view.d.ts +130 -0
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +99 -0
- package/dist/dts/templating/ref.d.ts +23 -0
- package/dist/dts/templating/render.d.ts +318 -0
- package/dist/dts/templating/repeat.d.ts +131 -0
- package/dist/dts/templating/slotted.d.ts +38 -0
- package/dist/dts/templating/template.d.ts +221 -0
- package/dist/dts/templating/view.d.ts +268 -0
- package/dist/dts/templating/when.d.ts +12 -0
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +16 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/models.d.ts +20 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/trust/index.d.ts +8 -0
- package/dist/dts/trust/types.d.ts +48 -0
- package/dist/dts/trust/utils.d.ts +26 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/utilities.d.ts +76 -0
- package/dist/esm/arrays.js +1 -0
- package/dist/esm/binding/binding.js +18 -0
- package/dist/esm/binding/exports.js +6 -0
- package/dist/esm/binding/normalize.js +17 -0
- package/dist/esm/binding/one-time.js +21 -0
- package/dist/esm/binding/one-way.js +30 -0
- package/dist/esm/binding/signal.js +99 -0
- package/dist/esm/binding/two-way.js +109 -0
- package/dist/esm/command/behavior.js +155 -0
- package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
- package/dist/esm/command/behaviors/undo-behavior.js +313 -0
- package/dist/esm/command/command.js +104 -0
- package/dist/esm/command/component-registry.js +107 -0
- package/dist/esm/command/components/confirm-dialog.js +370 -0
- package/dist/esm/command/index.js +22 -0
- package/dist/esm/command/registry.js +755 -0
- package/dist/esm/command/schema-validation.js +194 -0
- package/dist/esm/command/types.js +86 -0
- package/dist/esm/command/validation.js +508 -0
- package/dist/esm/command/weak-ref.js +5 -0
- package/dist/esm/components/attributes.js +219 -0
- package/dist/esm/components/definition-schema-transforms.js +23 -0
- package/dist/esm/components/element-controller.js +840 -0
- package/dist/esm/components/element-hydration.js +2 -0
- package/dist/esm/components/enable-hydration.js +123 -0
- package/dist/esm/components/fast-definitions.js +294 -0
- package/dist/esm/components/fast-element-registry.js +67 -0
- package/dist/esm/components/fast-element.js +82 -0
- package/dist/esm/components/hydration-tracker.js +211 -0
- package/dist/esm/components/hydration.js +187 -0
- package/dist/esm/components/schema.js +253 -0
- package/dist/esm/context.js +185 -0
- package/dist/esm/debug.js +71 -0
- package/dist/esm/declarative/attribute-map.js +122 -0
- package/dist/esm/declarative/debug.js +4 -0
- package/dist/esm/declarative/index.js +10 -0
- package/dist/esm/declarative/interfaces.js +9 -0
- package/dist/esm/declarative/observer-map-utilities.js +565 -0
- package/dist/esm/declarative/observer-map.js +216 -0
- package/dist/esm/declarative/runtime.js +14 -0
- package/dist/esm/declarative/syntax.js +36 -0
- package/dist/esm/declarative/template-bridge.js +160 -0
- package/dist/esm/declarative/template-parser.js +306 -0
- package/dist/esm/declarative/template.js +116 -0
- package/dist/esm/declarative/utilities.js +1069 -0
- package/dist/esm/definition-schema/api.js +129 -0
- package/dist/esm/definition-schema/cem.js +89 -0
- package/dist/esm/definition-schema/extension.js +53 -0
- package/dist/esm/definition-schema/extract.js +167 -0
- package/dist/esm/definition-schema/index.js +8 -0
- package/dist/esm/definition-schema/storage.js +58 -0
- package/dist/esm/definition-schema/types.js +8 -0
- package/dist/esm/dev-mode.js +22 -0
- package/dist/esm/di/di.js +1441 -0
- package/dist/esm/dom-policy.js +374 -0
- package/dist/esm/dom.js +101 -0
- package/dist/esm/hydration/diagnostics.js +50 -0
- package/dist/esm/hydration/exports.js +6 -0
- package/dist/esm/hydration/hydration-debugger.js +112 -0
- package/dist/esm/hydration/messages.js +84 -0
- package/dist/esm/hydration/runtime.js +33 -0
- package/dist/esm/hydration/target-builder.js +264 -0
- package/dist/esm/index.debug.js +3 -0
- package/dist/esm/index.js +49 -0
- package/dist/esm/index.rollup.debug.js +6 -0
- package/dist/esm/index.rollup.js +4 -0
- package/dist/esm/interfaces.js +55 -0
- package/dist/esm/metadata.js +57 -0
- package/dist/esm/observation/arrays.js +661 -0
- package/dist/esm/observation/notifier.js +162 -0
- package/dist/esm/observation/observable.js +324 -0
- package/dist/esm/observation/update-queue.js +56 -0
- package/dist/esm/observation/volatile.js +16 -0
- package/dist/esm/platform.js +98 -0
- package/dist/esm/registry.js +2 -0
- package/dist/esm/render.js +1 -0
- package/dist/esm/schema.js +1 -0
- package/dist/esm/scoped/detection.js +102 -0
- package/dist/esm/scoped/index.js +69 -0
- package/dist/esm/scoped/mixin.js +127 -0
- package/dist/esm/scoped/registry.js +125 -0
- package/dist/esm/scoped/types.js +4 -0
- 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-directive.js +36 -0
- package/dist/esm/styles/css.js +56 -0
- package/dist/esm/styles/element-styles.js +144 -0
- package/dist/esm/styles/host.js +1 -0
- package/dist/esm/styles/style-strategy.js +1 -0
- package/dist/esm/templating/children.js +67 -0
- package/dist/esm/templating/compiler.js +359 -0
- package/dist/esm/templating/html-binding-directive.js +288 -0
- package/dist/esm/templating/html-directive.js +113 -0
- package/dist/esm/templating/html.js +1 -0
- package/dist/esm/templating/hydration-view.js +228 -0
- package/dist/esm/templating/markup.js +83 -0
- package/dist/esm/templating/node-observation.js +84 -0
- package/dist/esm/templating/ref.js +21 -0
- package/dist/esm/templating/render.js +468 -0
- package/dist/esm/templating/repeat.js +434 -0
- package/dist/esm/templating/slotted.js +49 -0
- package/dist/esm/templating/template.js +206 -0
- package/dist/esm/templating/view.js +298 -0
- package/dist/esm/templating/when.js +22 -0
- 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/models.js +58 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/trust/index.js +7 -0
- package/dist/esm/trust/types.js +6 -0
- package/dist/esm/trust/utils.js +126 -0
- package/dist/esm/utilities.js +140 -0
- package/dist/fast-element.api.json +26798 -0
- package/dist/fast-element.d.ts +3985 -0
- package/dist/fast-element.debug.js +7604 -0
- package/dist/fast-element.debug.min.js +3 -0
- package/dist/fast-element.js +7603 -0
- package/dist/fast-element.min.js +3 -0
- package/dist/fast-element.untrimmed.d.ts +4103 -0
- package/dist/observation/arrays/arrays.api.json +2621 -0
- package/dist/scoped/scoped.api.json +891 -0
- package/dist/trust/trust.api.json +629 -0
- package/package.json +21 -23
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An implementation of {@link Notifier} that efficiently keeps track of
|
|
3
|
+
* subscribers interested in a specific change notification on an
|
|
4
|
+
* observable subject.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This set is optimized for the most common scenario of 1 or 2 subscribers.
|
|
8
|
+
* With this in mind, it can store a subscriber in an internal field, allowing it to avoid Array#push operations.
|
|
9
|
+
* If the set ever exceeds two subscribers, it upgrades to an array automatically.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export class SubscriberSet {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of SubscriberSet for the specified subject.
|
|
15
|
+
* @param subject - The subject that subscribers will receive notifications from.
|
|
16
|
+
* @param initialSubscriber - An initial subscriber to changes.
|
|
17
|
+
*/
|
|
18
|
+
constructor(subject, initialSubscriber) {
|
|
19
|
+
this.sub1 = void 0;
|
|
20
|
+
this.sub2 = void 0;
|
|
21
|
+
this.spillover = void 0;
|
|
22
|
+
this.subject = subject;
|
|
23
|
+
this.sub1 = initialSubscriber;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether the provided subscriber has been added to this set.
|
|
27
|
+
* @param subscriber - The subscriber to test for inclusion in this set.
|
|
28
|
+
*/
|
|
29
|
+
has(subscriber) {
|
|
30
|
+
return this.spillover === void 0
|
|
31
|
+
? this.sub1 === subscriber || this.sub2 === subscriber
|
|
32
|
+
: this.spillover.indexOf(subscriber) !== -1;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Subscribes to notification of changes in an object's state.
|
|
36
|
+
* @param subscriber - The object that is subscribing for change notification.
|
|
37
|
+
*/
|
|
38
|
+
subscribe(subscriber) {
|
|
39
|
+
const spillover = this.spillover;
|
|
40
|
+
if (spillover === void 0) {
|
|
41
|
+
if (this.has(subscriber)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (this.sub1 === void 0) {
|
|
45
|
+
this.sub1 = subscriber;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.sub2 === void 0) {
|
|
49
|
+
this.sub2 = subscriber;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.spillover = [this.sub1, this.sub2, subscriber];
|
|
53
|
+
this.sub1 = void 0;
|
|
54
|
+
this.sub2 = void 0;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const index = spillover.indexOf(subscriber);
|
|
58
|
+
if (index === -1) {
|
|
59
|
+
spillover.push(subscriber);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Unsubscribes from notification of changes in an object's state.
|
|
65
|
+
* @param subscriber - The object that is unsubscribing from change notification.
|
|
66
|
+
*/
|
|
67
|
+
unsubscribe(subscriber) {
|
|
68
|
+
const spillover = this.spillover;
|
|
69
|
+
if (spillover === void 0) {
|
|
70
|
+
if (this.sub1 === subscriber) {
|
|
71
|
+
this.sub1 = void 0;
|
|
72
|
+
}
|
|
73
|
+
else if (this.sub2 === subscriber) {
|
|
74
|
+
this.sub2 = void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const index = spillover.indexOf(subscriber);
|
|
79
|
+
if (index !== -1) {
|
|
80
|
+
spillover.splice(index, 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Notifies all subscribers.
|
|
86
|
+
* @param args - Data passed along to subscribers during notification.
|
|
87
|
+
*/
|
|
88
|
+
notify(args) {
|
|
89
|
+
const spillover = this.spillover;
|
|
90
|
+
const subject = this.subject;
|
|
91
|
+
if (spillover === void 0) {
|
|
92
|
+
const sub1 = this.sub1;
|
|
93
|
+
const sub2 = this.sub2;
|
|
94
|
+
if (sub1 !== void 0) {
|
|
95
|
+
sub1.handleChange(subject, args);
|
|
96
|
+
}
|
|
97
|
+
if (sub2 !== void 0) {
|
|
98
|
+
sub2.handleChange(subject, args);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
for (let i = 0, ii = spillover.length; i < ii; ++i) {
|
|
103
|
+
spillover[i].handleChange(subject, args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An implementation of Notifier that allows subscribers to be notified
|
|
110
|
+
* of individual property changes on an object.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export class PropertyChangeNotifier {
|
|
114
|
+
/**
|
|
115
|
+
* Creates an instance of PropertyChangeNotifier for the specified subject.
|
|
116
|
+
* @param subject - The object that subscribers will receive notifications for.
|
|
117
|
+
*/
|
|
118
|
+
constructor(subject) {
|
|
119
|
+
this.subscribers = {};
|
|
120
|
+
this.subjectSubscribers = null;
|
|
121
|
+
this.subject = subject;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Notifies all subscribers, based on the specified property.
|
|
125
|
+
* @param propertyName - The property name, passed along to subscribers during notification.
|
|
126
|
+
*/
|
|
127
|
+
notify(propertyName) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
(_a = this.subscribers[propertyName]) === null || _a === void 0 ? void 0 : _a.notify(propertyName);
|
|
130
|
+
(_b = this.subjectSubscribers) === null || _b === void 0 ? void 0 : _b.notify(propertyName);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Subscribes to notification of changes in an object's state.
|
|
134
|
+
* @param subscriber - The object that is subscribing for change notification.
|
|
135
|
+
* @param propertyToWatch - The name of the property that the subscriber is interested in watching for changes.
|
|
136
|
+
*/
|
|
137
|
+
subscribe(subscriber, propertyToWatch) {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
let subscribers;
|
|
140
|
+
if (propertyToWatch) {
|
|
141
|
+
subscribers = (_a = this.subscribers[propertyToWatch]) !== null && _a !== void 0 ? _a : (this.subscribers[propertyToWatch] = new SubscriberSet(this.subject));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
subscribers = (_b = this.subjectSubscribers) !== null && _b !== void 0 ? _b : (this.subjectSubscribers = new SubscriberSet(this.subject));
|
|
145
|
+
}
|
|
146
|
+
subscribers.subscribe(subscriber);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Unsubscribes from notification of changes in an object's state.
|
|
150
|
+
* @param subscriber - The object that is unsubscribing from change notification.
|
|
151
|
+
* @param propertyToUnwatch - The name of the property that the subscriber is no longer interested in watching.
|
|
152
|
+
*/
|
|
153
|
+
unsubscribe(subscriber, propertyToUnwatch) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
if (propertyToUnwatch) {
|
|
156
|
+
(_a = this.subscribers[propertyToUnwatch]) === null || _a === void 0 ? void 0 : _a.unsubscribe(subscriber);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
(_b = this.subjectSubscribers) === null || _b === void 0 ? void 0 : _b.unsubscribe(subscriber);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { isFunction, isString, Message } from "../interfaces.js";
|
|
2
|
+
import { createMetadataLocator, FAST, makeSerializationNoop } from "../platform.js";
|
|
3
|
+
import { PropertyChangeNotifier, SubscriberSet } from "./notifier.js";
|
|
4
|
+
import { Updates } from "./update-queue.js";
|
|
5
|
+
/**
|
|
6
|
+
* Describes how the source's lifetime relates to its controller's lifetime.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const SourceLifetime = Object.freeze({
|
|
10
|
+
/**
|
|
11
|
+
* The source to controller lifetime relationship is unknown.
|
|
12
|
+
*/
|
|
13
|
+
unknown: void 0,
|
|
14
|
+
/**
|
|
15
|
+
* The source and controller lifetimes are coupled to one another.
|
|
16
|
+
* They can/will be GC'd together.
|
|
17
|
+
*/
|
|
18
|
+
coupled: 1,
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Common Observable APIs.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const Observable = (() => {
|
|
25
|
+
const queueUpdate = Updates.enqueue;
|
|
26
|
+
const volatileRegex = /(:|&&|\|\||if|\?\.)/;
|
|
27
|
+
const notifierLookup = new WeakMap();
|
|
28
|
+
let watcher = void 0;
|
|
29
|
+
let createArrayObserver = (array) => {
|
|
30
|
+
throw FAST.error(Message.needsArrayObservation);
|
|
31
|
+
};
|
|
32
|
+
function getNotifier(source) {
|
|
33
|
+
var _a;
|
|
34
|
+
let found = (_a = source.$fastController) !== null && _a !== void 0 ? _a : notifierLookup.get(source);
|
|
35
|
+
if (found === void 0) {
|
|
36
|
+
Array.isArray(source)
|
|
37
|
+
? (found = createArrayObserver(source))
|
|
38
|
+
: notifierLookup.set(source, (found = new PropertyChangeNotifier(source)));
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
const getAccessors = createMetadataLocator();
|
|
43
|
+
class DefaultObservableAccessor {
|
|
44
|
+
constructor(name) {
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.field = `_${name}`;
|
|
47
|
+
this.callback = `${name}Changed`;
|
|
48
|
+
}
|
|
49
|
+
getValue(source) {
|
|
50
|
+
if (watcher !== void 0) {
|
|
51
|
+
watcher.watch(source, this.name);
|
|
52
|
+
}
|
|
53
|
+
return source[this.field];
|
|
54
|
+
}
|
|
55
|
+
setValue(source, newValue) {
|
|
56
|
+
const field = this.field;
|
|
57
|
+
const oldValue = source[field];
|
|
58
|
+
if (oldValue !== newValue) {
|
|
59
|
+
source[field] = newValue;
|
|
60
|
+
const callback = source[this.callback];
|
|
61
|
+
if (isFunction(callback)) {
|
|
62
|
+
callback.call(source, oldValue, newValue);
|
|
63
|
+
}
|
|
64
|
+
getNotifier(source).notify(this.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class ExpressionNotifierImplementation extends SubscriberSet {
|
|
69
|
+
constructor(expression, initialSubscriber, isVolatileBinding = false) {
|
|
70
|
+
super(expression, initialSubscriber);
|
|
71
|
+
this.expression = expression;
|
|
72
|
+
this.isVolatileBinding = isVolatileBinding;
|
|
73
|
+
this.needsRefresh = true;
|
|
74
|
+
this.needsQueue = true;
|
|
75
|
+
this.isAsync = true;
|
|
76
|
+
this.first = this;
|
|
77
|
+
this.last = null;
|
|
78
|
+
this.propertySource = void 0;
|
|
79
|
+
this.propertyName = void 0;
|
|
80
|
+
this.notifier = void 0;
|
|
81
|
+
this.next = void 0;
|
|
82
|
+
}
|
|
83
|
+
setMode(isAsync) {
|
|
84
|
+
this.isAsync = this.needsQueue = isAsync;
|
|
85
|
+
}
|
|
86
|
+
bind(controller) {
|
|
87
|
+
const value = this.observe(controller.source, controller.context);
|
|
88
|
+
if (!controller.isBound && this.requiresUnbind(controller)) {
|
|
89
|
+
controller.onUnbind(this);
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
requiresUnbind(controller) {
|
|
94
|
+
return (controller.sourceLifetime !== SourceLifetime.coupled ||
|
|
95
|
+
this.first !== this.last ||
|
|
96
|
+
this.first.propertySource !== controller.source);
|
|
97
|
+
}
|
|
98
|
+
unbind(controller) {
|
|
99
|
+
this.dispose();
|
|
100
|
+
}
|
|
101
|
+
observe(source, context) {
|
|
102
|
+
if (this.needsRefresh && this.last !== null) {
|
|
103
|
+
this.dispose();
|
|
104
|
+
}
|
|
105
|
+
const previousWatcher = watcher;
|
|
106
|
+
watcher = this.needsRefresh ? this : void 0;
|
|
107
|
+
this.needsRefresh = this.isVolatileBinding;
|
|
108
|
+
let result;
|
|
109
|
+
try {
|
|
110
|
+
result = this.expression(source, context);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
watcher = previousWatcher;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
// backwards compat with v1 kernel
|
|
118
|
+
disconnect() {
|
|
119
|
+
this.dispose();
|
|
120
|
+
}
|
|
121
|
+
dispose() {
|
|
122
|
+
if (this.last !== null) {
|
|
123
|
+
let current = this.first;
|
|
124
|
+
while (current !== void 0) {
|
|
125
|
+
current.notifier.unsubscribe(this, current.propertyName);
|
|
126
|
+
current = current.next;
|
|
127
|
+
}
|
|
128
|
+
this.last = null;
|
|
129
|
+
// A disposed graph has no subscriptions, so the next observe()
|
|
130
|
+
// must always re-track, regardless of sync/async mode.
|
|
131
|
+
this.needsRefresh = true;
|
|
132
|
+
this.needsQueue = this.isAsync;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
watch(propertySource, propertyName) {
|
|
136
|
+
const prev = this.last;
|
|
137
|
+
const notifier = getNotifier(propertySource);
|
|
138
|
+
const current = prev === null ? this.first : {};
|
|
139
|
+
current.propertySource = propertySource;
|
|
140
|
+
current.propertyName = propertyName;
|
|
141
|
+
current.notifier = notifier;
|
|
142
|
+
notifier.subscribe(this, propertyName);
|
|
143
|
+
if (prev !== null) {
|
|
144
|
+
if (!this.needsRefresh) {
|
|
145
|
+
// Declaring the variable prior to assignment below circumvents
|
|
146
|
+
// a bug in Angular's optimization process causing infinite recursion
|
|
147
|
+
// of this watch() method. Details https://github.com/microsoft/fast/issues/4969
|
|
148
|
+
// biome-ignore lint/style/useConst: see above
|
|
149
|
+
let prevValue;
|
|
150
|
+
watcher = void 0;
|
|
151
|
+
prevValue = prev.propertySource[prev.propertyName];
|
|
152
|
+
watcher = this;
|
|
153
|
+
if (propertySource === prevValue) {
|
|
154
|
+
this.needsRefresh = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
prev.next = current;
|
|
158
|
+
}
|
|
159
|
+
this.last = current;
|
|
160
|
+
}
|
|
161
|
+
handleChange() {
|
|
162
|
+
if (this.needsQueue) {
|
|
163
|
+
this.needsQueue = false;
|
|
164
|
+
queueUpdate(this);
|
|
165
|
+
}
|
|
166
|
+
else if (!this.isAsync) {
|
|
167
|
+
this.call();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
call() {
|
|
171
|
+
if (this.last !== null) {
|
|
172
|
+
this.needsQueue = this.isAsync;
|
|
173
|
+
this.notify(this);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
*records() {
|
|
177
|
+
let next = this.first;
|
|
178
|
+
while (next !== void 0) {
|
|
179
|
+
yield next;
|
|
180
|
+
next = next.next;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
makeSerializationNoop(ExpressionNotifierImplementation);
|
|
185
|
+
return Object.freeze({
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
* @param factory - The factory used to create array observers.
|
|
189
|
+
*/
|
|
190
|
+
setArrayObserverFactory(factory) {
|
|
191
|
+
createArrayObserver = factory;
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Gets a notifier for an object or Array.
|
|
195
|
+
* @param source - The object or Array to get the notifier for.
|
|
196
|
+
*/
|
|
197
|
+
getNotifier,
|
|
198
|
+
/**
|
|
199
|
+
* Records a property change for a source object.
|
|
200
|
+
* @param source - The object to record the change against.
|
|
201
|
+
* @param propertyName - The property to track as changed.
|
|
202
|
+
*/
|
|
203
|
+
track(source, propertyName) {
|
|
204
|
+
watcher && watcher.watch(source, propertyName);
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Notifies watchers that the currently executing property getter or function is volatile
|
|
208
|
+
* with respect to its observable dependencies.
|
|
209
|
+
*/
|
|
210
|
+
trackVolatile() {
|
|
211
|
+
watcher && (watcher.needsRefresh = true);
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* Notifies subscribers of a source object of changes.
|
|
215
|
+
* @param source - the object to notify of changes.
|
|
216
|
+
* @param args - The change args to pass to subscribers.
|
|
217
|
+
*/
|
|
218
|
+
notify(source, args) {
|
|
219
|
+
/* eslint-disable-next-line @typescript-eslint/no-use-before-define */
|
|
220
|
+
getNotifier(source).notify(args);
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* Defines an observable property on an object or prototype.
|
|
224
|
+
* @param target - The target object to define the observable on.
|
|
225
|
+
* @param nameOrAccessor - The name of the property to define as observable;
|
|
226
|
+
* or a custom accessor that specifies the property name and accessor implementation.
|
|
227
|
+
*/
|
|
228
|
+
defineProperty(target, nameOrAccessor) {
|
|
229
|
+
if (isString(nameOrAccessor)) {
|
|
230
|
+
nameOrAccessor = new DefaultObservableAccessor(nameOrAccessor);
|
|
231
|
+
}
|
|
232
|
+
getAccessors(target).push(nameOrAccessor);
|
|
233
|
+
Reflect.defineProperty(target, nameOrAccessor.name, {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
get() {
|
|
236
|
+
return nameOrAccessor.getValue(this);
|
|
237
|
+
},
|
|
238
|
+
set(newValue) {
|
|
239
|
+
nameOrAccessor.setValue(this, newValue);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Finds all the observable accessors defined on the target,
|
|
245
|
+
* including its prototype chain.
|
|
246
|
+
* @param target - The target object to search for accessor on.
|
|
247
|
+
*/
|
|
248
|
+
getAccessors,
|
|
249
|
+
/**
|
|
250
|
+
* Creates a {@link ExpressionNotifier} that can watch the
|
|
251
|
+
* provided {@link Expression} for changes.
|
|
252
|
+
* @param expression - The binding to observe.
|
|
253
|
+
* @param initialSubscriber - An initial subscriber to changes in the binding value.
|
|
254
|
+
* @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
|
|
255
|
+
*/
|
|
256
|
+
binding(expression, initialSubscriber, isVolatileBinding = this.isVolatileBinding(expression)) {
|
|
257
|
+
return new ExpressionNotifierImplementation(expression, initialSubscriber, isVolatileBinding);
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
|
|
261
|
+
* on every evaluation of the value.
|
|
262
|
+
* @param expression - The binding to inspect.
|
|
263
|
+
*/
|
|
264
|
+
isVolatileBinding(expression) {
|
|
265
|
+
return volatileRegex.test(expression.toString());
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
})();
|
|
269
|
+
/**
|
|
270
|
+
* Decorator: Defines an observable property on the target.
|
|
271
|
+
* @param target - The target to define the observable on.
|
|
272
|
+
* @param nameOrAccessor - The property name or accessor to define the observable as.
|
|
273
|
+
* @public
|
|
274
|
+
*/
|
|
275
|
+
export function observable(target, nameOrAccessor) {
|
|
276
|
+
Observable.defineProperty(target, nameOrAccessor);
|
|
277
|
+
}
|
|
278
|
+
const contextEvent = (() => {
|
|
279
|
+
let current = null;
|
|
280
|
+
return {
|
|
281
|
+
get() {
|
|
282
|
+
return current;
|
|
283
|
+
},
|
|
284
|
+
set(event) {
|
|
285
|
+
current = event;
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
})();
|
|
289
|
+
/**
|
|
290
|
+
* Provides additional contextual information available to behaviors and expressions.
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
export const ExecutionContext = Object.freeze({
|
|
294
|
+
/**
|
|
295
|
+
* A default execution context.
|
|
296
|
+
*/
|
|
297
|
+
default: {
|
|
298
|
+
index: 0,
|
|
299
|
+
length: 0,
|
|
300
|
+
get event() {
|
|
301
|
+
return ExecutionContext.getEvent();
|
|
302
|
+
},
|
|
303
|
+
eventDetail() {
|
|
304
|
+
return this.event.detail;
|
|
305
|
+
},
|
|
306
|
+
eventTarget() {
|
|
307
|
+
return this.event.target;
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
/**
|
|
311
|
+
* Gets the current event.
|
|
312
|
+
* @returns An event object.
|
|
313
|
+
*/
|
|
314
|
+
getEvent() {
|
|
315
|
+
return contextEvent.get();
|
|
316
|
+
},
|
|
317
|
+
/**
|
|
318
|
+
* Sets the current event.
|
|
319
|
+
* @param event - An event object.
|
|
320
|
+
*/
|
|
321
|
+
setEvent(event) {
|
|
322
|
+
contextEvent.set(event);
|
|
323
|
+
},
|
|
324
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const tasks = [];
|
|
2
|
+
const pendingErrors = [];
|
|
3
|
+
const rAF = globalThis.requestAnimationFrame;
|
|
4
|
+
let updateAsync = true;
|
|
5
|
+
function throwFirstError() {
|
|
6
|
+
if (pendingErrors.length) {
|
|
7
|
+
throw pendingErrors.shift();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function tryRunTask(task) {
|
|
11
|
+
try {
|
|
12
|
+
task.call();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (updateAsync) {
|
|
16
|
+
pendingErrors.push(error);
|
|
17
|
+
setTimeout(throwFirstError, 0);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
tasks.length = 0;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function process() {
|
|
26
|
+
const capacity = 1024;
|
|
27
|
+
let index = 0;
|
|
28
|
+
while (index < tasks.length) {
|
|
29
|
+
tryRunTask(tasks[index]);
|
|
30
|
+
index++;
|
|
31
|
+
if (index > capacity) {
|
|
32
|
+
for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
|
|
33
|
+
tasks[scan] = tasks[scan + index];
|
|
34
|
+
}
|
|
35
|
+
tasks.length -= index;
|
|
36
|
+
index = 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
tasks.length = 0;
|
|
40
|
+
}
|
|
41
|
+
function enqueue(callable) {
|
|
42
|
+
tasks.push(callable);
|
|
43
|
+
if (tasks.length < 2) {
|
|
44
|
+
updateAsync ? rAF(process) : process();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The default UpdateQueue.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export const Updates = Object.freeze({
|
|
52
|
+
enqueue,
|
|
53
|
+
next: () => new Promise(enqueue),
|
|
54
|
+
process,
|
|
55
|
+
setMode: (isAsync) => (updateAsync = isAsync),
|
|
56
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Observable } from "./observable.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator: Marks a property getter as having volatile observable dependencies.
|
|
4
|
+
* @param target - The target that the property is defined on.
|
|
5
|
+
* @param name - The property name.
|
|
6
|
+
* @param descriptor - The existing descriptor.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export function volatile(target, name, descriptor) {
|
|
10
|
+
return Object.assign({}, descriptor, {
|
|
11
|
+
get() {
|
|
12
|
+
Observable.trackVolatile();
|
|
13
|
+
return descriptor.get.apply(this);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { noop } from "./interfaces.js";
|
|
2
|
+
const debugMessages = Object.create(null);
|
|
3
|
+
/**
|
|
4
|
+
* The FAST messaging API for warnings and errors.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const FAST = {
|
|
8
|
+
/**
|
|
9
|
+
* Sends a warning to the developer.
|
|
10
|
+
* @param code - The warning code to send.
|
|
11
|
+
* @param values - Values relevant for the warning message.
|
|
12
|
+
*/
|
|
13
|
+
warn(_code, _values) { },
|
|
14
|
+
/**
|
|
15
|
+
* Creates an error from a code.
|
|
16
|
+
* @param code - The error code.
|
|
17
|
+
* @param values - Values relevant for the error message.
|
|
18
|
+
*/
|
|
19
|
+
error(code, _values) {
|
|
20
|
+
return new Error(`Error ${code}`);
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Adds debug messages for errors and warnings.
|
|
24
|
+
* @param messages - The message dictionary to add.
|
|
25
|
+
*/
|
|
26
|
+
addMessages(messages) {
|
|
27
|
+
Object.assign(debugMessages, messages);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Gets the shared debug message lookup.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function getDebugMessageLookup() {
|
|
35
|
+
return debugMessages;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A readonly, empty array.
|
|
39
|
+
* @remarks
|
|
40
|
+
* Typically returned by APIs that return arrays when there are
|
|
41
|
+
* no actual items to return.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export const emptyArray = Object.freeze([]);
|
|
45
|
+
/**
|
|
46
|
+
* Do not change. Part of shared kernel contract.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export function createTypeRegistry() {
|
|
50
|
+
const typeToDefinition = new Map();
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
register(definition) {
|
|
53
|
+
if (typeToDefinition.has(definition.type)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
typeToDefinition.set(definition.type, definition);
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
getByType(key) {
|
|
60
|
+
return typeToDefinition.get(key);
|
|
61
|
+
},
|
|
62
|
+
getForInstance(object) {
|
|
63
|
+
if (object === null || object === void 0) {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
return typeToDefinition.get(object.constructor);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a function capable of locating metadata associated with a type.
|
|
72
|
+
* @returns A metadata locator function.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export function createMetadataLocator() {
|
|
76
|
+
const metadataLookup = new WeakMap();
|
|
77
|
+
return function (target) {
|
|
78
|
+
let metadata = metadataLookup.get(target);
|
|
79
|
+
if (metadata === void 0) {
|
|
80
|
+
let currentTarget = Reflect.getPrototypeOf(target);
|
|
81
|
+
while (metadata === void 0 && currentTarget !== null) {
|
|
82
|
+
metadata = metadataLookup.get(currentTarget);
|
|
83
|
+
currentTarget = Reflect.getPrototypeOf(currentTarget);
|
|
84
|
+
}
|
|
85
|
+
metadata = metadata === void 0 ? [] : metadata.slice(0);
|
|
86
|
+
metadataLookup.set(target, metadata);
|
|
87
|
+
}
|
|
88
|
+
return metadata;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Makes a type noop for JSON serialization.
|
|
93
|
+
* @param type - The type to make noop for JSON serialization.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
export function makeSerializationNoop(type) {
|
|
97
|
+
type.prototype.toJSON = noop;
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RenderBehavior, RenderDirective, render } from "./templating/render.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Schema, schemaRegistry, } from "./components/schema.js";
|