@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.1
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 +6 -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 +15 -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 +110 -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 +312 -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 +752 -0
- package/dist/esm/command/schema-validation.js +194 -0
- package/dist/esm/command/types.js +86 -0
- package/dist/esm/command/validation.js +511 -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 +839 -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 +210 -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 +121 -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 +1440 -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 +63 -0
- package/dist/esm/observation/arrays.js +661 -0
- package/dist/esm/observation/notifier.js +164 -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 +7618 -0
- package/dist/fast-element.debug.min.js +3 -0
- package/dist/fast-element.js +7617 -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 +12 -12
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { TRUST_KEY } from "./types.js";
|
|
13
|
+
const warningSeverities = new Set([
|
|
14
|
+
"info",
|
|
15
|
+
"warning",
|
|
16
|
+
"caution",
|
|
17
|
+
]);
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
if (value === null || typeof value !== "object") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const prototype = Object.getPrototypeOf(value);
|
|
23
|
+
return prototype === Object.prototype || prototype === null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalize untrusted warnings: non-arrays yield `undefined`; entries without a string
|
|
27
|
+
* `code` and `message` are dropped; invalid `severity` / non-plain `details` are omitted.
|
|
28
|
+
*/
|
|
29
|
+
function sanitizeWarnings(value) {
|
|
30
|
+
if (!Array.isArray(value)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const warnings = [];
|
|
34
|
+
for (const entry of value) {
|
|
35
|
+
if (!isPlainObject(entry) ||
|
|
36
|
+
typeof entry.code !== "string" ||
|
|
37
|
+
typeof entry.message !== "string") {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const warning = { code: entry.code, message: entry.message };
|
|
41
|
+
if (warningSeverities.has(entry.severity)) {
|
|
42
|
+
warning.severity = entry.severity;
|
|
43
|
+
}
|
|
44
|
+
if (isPlainObject(entry.details)) {
|
|
45
|
+
warning.details = entry.details;
|
|
46
|
+
}
|
|
47
|
+
warnings.push(warning);
|
|
48
|
+
}
|
|
49
|
+
return warnings;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extract trust signals from a CustomEvent.
|
|
53
|
+
* Returns empty object if no trust signals present.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export function getTrustSignals(event) {
|
|
57
|
+
const detail = event.detail;
|
|
58
|
+
if (detail && typeof detail === "object" && TRUST_KEY in detail) {
|
|
59
|
+
const trust = detail[TRUST_KEY];
|
|
60
|
+
if (trust && typeof trust === "object") {
|
|
61
|
+
const signals = trust;
|
|
62
|
+
const confidence = signals.confidence;
|
|
63
|
+
const warnings = sanitizeWarnings(signals.warnings);
|
|
64
|
+
return Object.assign(Object.assign(Object.assign({}, (typeof confidence === "number" &&
|
|
65
|
+
Number.isFinite(confidence) &&
|
|
66
|
+
confidence >= 0 &&
|
|
67
|
+
confidence <= 1
|
|
68
|
+
? { confidence }
|
|
69
|
+
: {})), (typeof signals.reasoning === "string"
|
|
70
|
+
? { reasoning: signals.reasoning }
|
|
71
|
+
: {})), (warnings !== undefined ? { warnings } : {}));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if an event has trust signals.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export function hasTrustSignals(event) {
|
|
81
|
+
const signals = getTrustSignals(event);
|
|
82
|
+
return (signals.confidence !== undefined ||
|
|
83
|
+
signals.reasoning !== undefined ||
|
|
84
|
+
signals.warnings !== undefined);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Wrap detail with trust signals.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* - Plain objects are copied and the signals are added under {@link TRUST_KEY}.
|
|
91
|
+
* - Anything else (primitives, arrays, Dates, class instances, ...) is wrapped in a
|
|
92
|
+
* `{ value, __trust }` envelope so it is never spread into a different shape.
|
|
93
|
+
* - A `__trust` key already present on a plain-object detail is caller-supplied
|
|
94
|
+
* (often from parsed JSON) and is never kept: it is replaced by the real signals,
|
|
95
|
+
* or dropped when there are none, so detail data cannot forge trust signals.
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
export function wrapDetailWithTrust(detail, signals) {
|
|
100
|
+
const { confidence, reasoning } = signals !== null && signals !== void 0 ? signals : {};
|
|
101
|
+
const warnings = Array.isArray(signals === null || signals === void 0 ? void 0 : signals.warnings) ? signals.warnings : undefined;
|
|
102
|
+
if (confidence === undefined && reasoning === undefined && warnings === undefined) {
|
|
103
|
+
if (isPlainObject(detail) && TRUST_KEY in detail) {
|
|
104
|
+
const _a = detail, _b = TRUST_KEY, _forged = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
105
|
+
return rest;
|
|
106
|
+
}
|
|
107
|
+
return detail; // No-op when no trust signals
|
|
108
|
+
}
|
|
109
|
+
if (confidence !== undefined &&
|
|
110
|
+
(!Number.isFinite(confidence) || confidence < 0 || confidence > 1)) {
|
|
111
|
+
throw new RangeError("Trust confidence must be a finite number from 0 to 1.");
|
|
112
|
+
}
|
|
113
|
+
const trust = {};
|
|
114
|
+
if (confidence !== undefined)
|
|
115
|
+
trust.confidence = confidence;
|
|
116
|
+
if (reasoning !== undefined)
|
|
117
|
+
trust.reasoning = reasoning;
|
|
118
|
+
if (warnings !== undefined)
|
|
119
|
+
trust.warnings = warnings.map(warning => (Object.assign({}, warning)));
|
|
120
|
+
if (isPlainObject(detail)) {
|
|
121
|
+
const _c = detail, _d = TRUST_KEY, _forged = _c[_d], rest = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
|
|
122
|
+
return Object.assign(Object.assign({}, rest), { [TRUST_KEY]: trust });
|
|
123
|
+
}
|
|
124
|
+
// Wrap everything that is not a plain object in an envelope
|
|
125
|
+
return { value: detail, [TRUST_KEY]: trust };
|
|
126
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DOM } from "./dom.js";
|
|
2
|
+
import { ExecutionContext } from "./observation/observable.js";
|
|
3
|
+
import { nextId } from "./templating/markup.js";
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
|
|
6
|
+
* When the parent of a node is a shadow-root, it will return the host
|
|
7
|
+
* element of the shadow root. Otherwise it will return the parent node or null if
|
|
8
|
+
* no parent node exists.
|
|
9
|
+
* @param element - The element for which to retrieve the composed parent
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function composedParent(element) {
|
|
14
|
+
const parentNode = element.parentElement;
|
|
15
|
+
if (parentNode) {
|
|
16
|
+
return parentNode;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const rootNode = element.getRootNode();
|
|
20
|
+
if (rootNode.host instanceof HTMLElement) {
|
|
21
|
+
// this is shadow-root
|
|
22
|
+
return rootNode.host;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if the reference element contains the test element in a "composed" DOM tree that
|
|
29
|
+
* ignores shadow DOM boundaries.
|
|
30
|
+
*
|
|
31
|
+
* Returns true of the test element is a descendent of the reference, or exists in
|
|
32
|
+
* a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
|
|
33
|
+
* @param reference - The element to test for containment against.
|
|
34
|
+
* @param test - The element being tested for containment.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function composedContains(reference, test) {
|
|
39
|
+
let current = test;
|
|
40
|
+
while (current !== null) {
|
|
41
|
+
if (current === reference) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
current = composedParent(current);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An extension of MutationObserver that supports unobserving nodes.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export class UnobservableMutationObserver extends MutationObserver {
|
|
53
|
+
/**
|
|
54
|
+
* Creates an instance of UnobservableMutationObserver.
|
|
55
|
+
* @param callback - The callback to invoke when observed nodes are changed.
|
|
56
|
+
*/
|
|
57
|
+
constructor(callback) {
|
|
58
|
+
function handler(mutations) {
|
|
59
|
+
this.callback.call(null, mutations.filter(record => this.observedNodes.has(record.target)));
|
|
60
|
+
}
|
|
61
|
+
super(handler);
|
|
62
|
+
this.callback = callback;
|
|
63
|
+
this.observedNodes = new Set();
|
|
64
|
+
}
|
|
65
|
+
observe(target, options) {
|
|
66
|
+
this.observedNodes.add(target);
|
|
67
|
+
super.observe(target, options);
|
|
68
|
+
}
|
|
69
|
+
unobserve(target) {
|
|
70
|
+
this.observedNodes.delete(target);
|
|
71
|
+
if (this.observedNodes.size < 1) {
|
|
72
|
+
this.disconnect();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Bridges between ViewBehaviors and HostBehaviors, enabling a host to
|
|
78
|
+
* control ViewBehaviors.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export const ViewBehaviorOrchestrator = Object.freeze({
|
|
82
|
+
/**
|
|
83
|
+
* Creates a ViewBehaviorOrchestrator.
|
|
84
|
+
* @param source - The source to to associate behaviors with.
|
|
85
|
+
* @returns A ViewBehaviorOrchestrator.
|
|
86
|
+
*/
|
|
87
|
+
create(source) {
|
|
88
|
+
const behaviors = [];
|
|
89
|
+
const targets = {};
|
|
90
|
+
let unbindables = null;
|
|
91
|
+
let isConnected = false;
|
|
92
|
+
return {
|
|
93
|
+
source,
|
|
94
|
+
context: ExecutionContext.default,
|
|
95
|
+
targets,
|
|
96
|
+
get isBound() {
|
|
97
|
+
return isConnected;
|
|
98
|
+
},
|
|
99
|
+
addBehaviorFactory(factory, target) {
|
|
100
|
+
var _a, _b, _c, _d;
|
|
101
|
+
const compiled = factory;
|
|
102
|
+
compiled.id = (_a = compiled.id) !== null && _a !== void 0 ? _a : nextId();
|
|
103
|
+
compiled.targetNodeId = (_b = compiled.targetNodeId) !== null && _b !== void 0 ? _b : nextId();
|
|
104
|
+
compiled.targetTagName = (_c = target.tagName) !== null && _c !== void 0 ? _c : null;
|
|
105
|
+
compiled.policy = (_d = compiled.policy) !== null && _d !== void 0 ? _d : DOM.policy;
|
|
106
|
+
this.addTarget(compiled.targetNodeId, target);
|
|
107
|
+
this.addBehavior(compiled.createBehavior());
|
|
108
|
+
},
|
|
109
|
+
addTarget(nodeId, target) {
|
|
110
|
+
targets[nodeId] = target;
|
|
111
|
+
},
|
|
112
|
+
addBehavior(behavior) {
|
|
113
|
+
behaviors.push(behavior);
|
|
114
|
+
if (isConnected) {
|
|
115
|
+
behavior.bind(this);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
onUnbind(unbindable) {
|
|
119
|
+
if (unbindables === null) {
|
|
120
|
+
unbindables = [];
|
|
121
|
+
}
|
|
122
|
+
unbindables.push(unbindable);
|
|
123
|
+
},
|
|
124
|
+
connectedCallback(controller) {
|
|
125
|
+
if (!isConnected) {
|
|
126
|
+
isConnected = true;
|
|
127
|
+
behaviors.forEach(x => x.bind(this));
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
disconnectedCallback(controller) {
|
|
131
|
+
if (isConnected) {
|
|
132
|
+
isConnected = false;
|
|
133
|
+
if (unbindables !== null) {
|
|
134
|
+
unbindables.forEach(x => x.unbind(this));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
});
|