@spearwolf/shadow-objects 0.30.1 → 0.31.0
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 +24 -0
- package/README.md +34 -10
- package/bundle.js +13 -13
- package/package.json +3 -3
- package/src/bundle.js +4 -4
- package/src/bundle.js.map +7 -1
- package/src/constants.js +53 -40
- package/src/constants.js.map +7 -1
- package/src/create-worker.bundle.js +6 -8
- package/src/create-worker.bundle.js.map +7 -1
- package/src/create-worker.js +5 -2
- package/src/create-worker.js.map +7 -1
- package/src/elements/ShaeElement.js +57 -54
- package/src/elements/ShaeElement.js.map +7 -1
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +320 -341
- package/src/elements/ShaeEntElement.js.map +7 -1
- package/src/elements/ShaePropElement.js +312 -320
- package/src/elements/ShaePropElement.js.map +7 -1
- package/src/elements/ShaeWorkerElement.js +234 -229
- package/src/elements/ShaeWorkerElement.js.map +7 -1
- package/src/elements/constants.js +37 -22
- package/src/elements/constants.js.map +7 -1
- package/src/elements/events.d.ts +1 -1
- package/src/elements/events.d.ts.map +1 -1
- package/src/elements/events.js +1 -2
- package/src/elements/events.js.map +7 -1
- package/src/elements.js +4 -4
- package/src/elements.js.map +7 -1
- package/src/in-the-dark/Entity.d.ts +3 -1
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +299 -275
- package/src/in-the-dark/Entity.js.map +7 -1
- package/src/in-the-dark/Kernel.d.ts +1 -1
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +556 -532
- package/src/in-the-dark/Kernel.js.map +7 -1
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +101 -104
- package/src/in-the-dark/Registry.js.map +7 -1
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +21 -23
- package/src/in-the-dark/ShadowObject.js.map +7 -1
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js +139 -123
- package/src/in-the-dark/SignalsPath.js.map +7 -1
- package/src/in-the-dark/events.js +11 -9
- package/src/in-the-dark/events.js.map +7 -1
- package/src/in-the-dark/importModule.js +31 -29
- package/src/in-the-dark/importModule.js.map +7 -1
- package/src/index.d.ts +2 -2
- package/src/index.d.ts.map +1 -1
- package/src/index.js +14 -14
- package/src/index.js.map +7 -1
- package/src/shadow-objects.js +6 -6
- package/src/shadow-objects.js.map +7 -1
- package/src/shadow-objects.worker.js +3 -3
- package/src/shadow-objects.worker.js.map +7 -1
- package/src/shae-ent.js +3 -3
- package/src/shae-ent.js.map +7 -1
- package/src/shae-prop.js +3 -3
- package/src/shae-prop.js.map +7 -1
- package/src/shae-worker.js +3 -3
- package/src/shae-worker.js.map +7 -1
- package/src/types.d.ts +5 -4
- package/src/types.d.ts.map +1 -1
- package/src/types.js +1 -2
- package/src/types.js.map +7 -1
- package/src/utils/ConsoleLogger.js +179 -185
- package/src/utils/ConsoleLogger.js.map +7 -1
- package/src/utils/FrameLoop.js +41 -40
- package/src/utils/FrameLoop.js.map +7 -1
- package/src/utils/array-utils.js +22 -24
- package/src/utils/array-utils.js.map +7 -1
- package/src/utils/attr-utils.js +15 -11
- package/src/utils/attr-utils.js.map +7 -1
- package/src/utils/constants.js +5 -2
- package/src/utils/constants.js.map +7 -1
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/generateUUID.js +269 -32
- package/src/utils/generateUUID.js.map +7 -1
- package/src/utils/props-utils.js +34 -43
- package/src/utils/props-utils.js.map +7 -1
- package/src/utils/toMaybe.js +5 -2
- package/src/utils/toMaybe.js.map +7 -1
- package/src/utils/toNamespace.js +6 -3
- package/src/utils/toNamespace.js.map +7 -1
- package/src/utils/toUrlString.js +9 -6
- package/src/utils/toUrlString.js.map +7 -1
- package/src/utils/waitForMessageOfType.js +30 -32
- package/src/utils/waitForMessageOfType.js.map +7 -1
- package/src/view/ComponentChanges.d.ts +1 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +249 -251
- package/src/view/ComponentChanges.js.map +7 -1
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +303 -331
- package/src/view/ComponentContext.js.map +7 -1
- package/src/view/ComponentMemory.d.ts +1 -0
- package/src/view/ComponentMemory.d.ts.map +1 -1
- package/src/view/ComponentMemory.js +73 -76
- package/src/view/ComponentMemory.js.map +7 -1
- package/src/view/IShadowObjectEnvProxy.js +1 -2
- package/src/view/IShadowObjectEnvProxy.js.map +7 -1
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +57 -52
- package/src/view/LocalShadowObjectEnv.js.map +7 -1
- package/src/view/RemoteWorkerEnv.js +134 -123
- package/src/view/RemoteWorkerEnv.js.map +7 -1
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +232 -228
- package/src/view/ShadowEnv.js.map +7 -1
- package/src/view/ViewComponent.d.ts +9 -0
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +142 -130
- package/src/view/ViewComponent.js.map +7 -1
- package/src/view/cloneChangeTrail.js +13 -11
- package/src/view/cloneChangeTrail.js.map +7 -1
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +78 -67
- package/src/worker/MessageRouter.js.map +7 -1
- package/src/worker/WorkerRuntime.js +22 -21
- package/src/worker/WorkerRuntime.js.map +7 -1
- package/tsconfig.lib.tsbuildinfo +0 -1
|
@@ -1,359 +1,338 @@
|
|
|
1
|
-
import { on } from
|
|
2
|
-
import { beQuiet, createEffect, createSignal } from
|
|
3
|
-
import { ComponentContext } from
|
|
4
|
-
import { ShadowEnv } from
|
|
5
|
-
import { ViewComponent } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.removeAttribute(ATTR_FORWARD_CUSTOM_EVENTS);
|
|
87
|
-
}
|
|
88
|
-
else if (val === true) {
|
|
89
|
-
if (!this.hasAttribute(ATTR_FORWARD_CUSTOM_EVENTS)) {
|
|
90
|
-
this.setAttribute(ATTR_FORWARD_CUSTOM_EVENTS, '');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const str = Array.from(val).join(',');
|
|
95
|
-
if (this.getAttribute(ATTR_FORWARD_CUSTOM_EVENTS) !== str) {
|
|
96
|
-
this.setAttribute(ATTR_FORWARD_CUSTOM_EVENTS, str);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
createEffect(() => {
|
|
101
|
-
const vc = this.viewComponent$.get();
|
|
102
|
-
if (vc) {
|
|
103
|
-
const unsubcribe = on(vc, ComponentContext.ReRequestParentRoots, () => this.#reReuestParentRoot());
|
|
104
|
-
const oldNs = vc.context?.ns;
|
|
105
|
-
return () => {
|
|
106
|
-
unsubcribe();
|
|
107
|
-
vc.destroy();
|
|
108
|
-
if (oldNs && oldNs !== this.ns) {
|
|
109
|
-
ShadowEnv.get(oldNs)?.sync();
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.syncShadowObjects();
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
createEffect(() => {
|
|
118
|
-
const vc = this.viewComponent$.get();
|
|
119
|
-
if (!vc)
|
|
120
|
-
return;
|
|
121
|
-
// Make sure we are patching the instance method, not the prototype
|
|
122
|
-
const originalDispatchEvent = Object.hasOwn(vc, 'dispatchEvent')
|
|
123
|
-
? Object.getPrototypeOf(vc).dispatchEvent
|
|
124
|
-
: vc.dispatchEvent;
|
|
125
|
-
const filter = this.forwardCustomEvents$.get();
|
|
126
|
-
if (!filter)
|
|
127
|
-
return;
|
|
128
|
-
const allowedTypes = filter instanceof Set ? filter : undefined;
|
|
129
|
-
const newDispatch = (type, data, traverseChildren) => {
|
|
130
|
-
originalDispatchEvent.call(vc, type, data, traverseChildren);
|
|
131
|
-
if (type === ComponentContext.ReRequestParentRoots)
|
|
132
|
-
return;
|
|
133
|
-
if (allowedTypes && !allowedTypes.has(type))
|
|
134
|
-
return;
|
|
135
|
-
this.dispatchEvent(new CustomEvent(type, {
|
|
136
|
-
bubbles: true,
|
|
137
|
-
composed: true,
|
|
138
|
-
detail: data,
|
|
139
|
-
}));
|
|
140
|
-
};
|
|
141
|
-
// We use defineProperty to ensure it is writable and configurable
|
|
142
|
-
Object.defineProperty(vc, 'dispatchEvent', {
|
|
143
|
-
value: newDispatch,
|
|
144
|
-
writable: true,
|
|
145
|
-
configurable: true,
|
|
146
|
-
});
|
|
147
|
-
return () => {
|
|
148
|
-
if (Object.hasOwn(vc, 'dispatchEvent') && vc.dispatchEvent === newDispatch) {
|
|
149
|
-
delete vc.dispatchEvent;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
this.token$.onChange((token) => {
|
|
154
|
-
const vc = this.viewComponent$.value;
|
|
155
|
-
if (vc) {
|
|
156
|
-
vc.token = token;
|
|
157
|
-
this.syncShadowObjects();
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
this.style.display = 'contents';
|
|
161
|
-
}
|
|
162
|
-
#unsubscribeViewComponentEffect;
|
|
163
|
-
#setupViewComponentEffect() {
|
|
164
|
-
this.#unsubscribeViewComponentEffect?.();
|
|
165
|
-
const unsubscribeComponentContext = this.componentContext$.onChange((context) => {
|
|
166
|
-
const token = this.token$.value;
|
|
167
|
-
let vc = this.viewComponent$.value;
|
|
168
|
-
if (vc) {
|
|
169
|
-
vc.context = context;
|
|
170
|
-
}
|
|
171
|
-
else if (context) {
|
|
172
|
-
vc = new ViewComponent(token, { context });
|
|
173
|
-
this.viewComponent$.set(vc);
|
|
174
|
-
}
|
|
1
|
+
import { on } from "@spearwolf/eventize";
|
|
2
|
+
import { beQuiet, createEffect, createSignal } from "@spearwolf/signalize";
|
|
3
|
+
import { ComponentContext } from "../view/ComponentContext.js";
|
|
4
|
+
import { ShadowEnv } from "../view/ShadowEnv.js";
|
|
5
|
+
import { ViewComponent } from "../view/ViewComponent.js";
|
|
6
|
+
import { ATTR_FORWARD_CUSTOM_EVENTS, ATTR_TOKEN, RequestEntParentEventName, ReRequestEntParentEventName } from "./constants.js";
|
|
7
|
+
import { ShaeElement } from "./ShaeElement.js";
|
|
8
|
+
class ShaeEntElement extends ShaeElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.isShaeEntElement = true;
|
|
12
|
+
this.componentContext$ = createSignal();
|
|
13
|
+
this.viewComponent$ = createSignal();
|
|
14
|
+
this.token$ = createSignal();
|
|
15
|
+
this.forwardCustomEvents$ = createSignal(false);
|
|
16
|
+
this.#shadowRootHostNeedsUpdate = true;
|
|
17
|
+
this.#onSlotChange = () => {
|
|
18
|
+
const shadowRootHost = this.findShadowRootHost();
|
|
19
|
+
if (shadowRootHost == null) return;
|
|
20
|
+
this.dispatchEvent(
|
|
21
|
+
new CustomEvent(ReRequestEntParentEventName, {
|
|
22
|
+
bubbles: true,
|
|
23
|
+
composed: true,
|
|
24
|
+
detail: { requester: this, shadowRootHost }
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
this.#onReRequestParent = (event) => {
|
|
29
|
+
const requester = event.detail?.requester;
|
|
30
|
+
if (requester === this) return;
|
|
31
|
+
if (!requester?.isShaeEntElement) return;
|
|
32
|
+
if (requester.ns !== this.ns) return;
|
|
33
|
+
const shadowRootHost = event.detail?.shadowRootHost;
|
|
34
|
+
if (shadowRootHost) {
|
|
35
|
+
this.#dispatchRequestParent();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.#onRequestParent = (event) => {
|
|
39
|
+
const requester = event.detail?.requester;
|
|
40
|
+
if (requester === this) return;
|
|
41
|
+
if (!requester?.isShaeEntElement) return;
|
|
42
|
+
if (requester.ns !== this.ns) return;
|
|
43
|
+
event.stopPropagation();
|
|
44
|
+
requester.#setParent(this);
|
|
45
|
+
};
|
|
46
|
+
this.ns$.onChange((ns) => {
|
|
47
|
+
this.componentContext$.set(ComponentContext.get(ns));
|
|
48
|
+
if (this.isConnected) {
|
|
49
|
+
this.#dispatchRequestParent();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
this.#updateTokenValue();
|
|
53
|
+
this.token$.onChange((token) => {
|
|
54
|
+
if (token == null) {
|
|
55
|
+
this.removeAttribute(ATTR_TOKEN);
|
|
56
|
+
} else if (this.getAttribute(ATTR_TOKEN) !== token) {
|
|
57
|
+
this.setAttribute(ATTR_TOKEN, token);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.#updateForwardCustomEventsValue();
|
|
61
|
+
this.forwardCustomEvents$.onChange((val) => {
|
|
62
|
+
if (!val) {
|
|
63
|
+
this.removeAttribute(ATTR_FORWARD_CUSTOM_EVENTS);
|
|
64
|
+
} else if (val === true) {
|
|
65
|
+
if (!this.hasAttribute(ATTR_FORWARD_CUSTOM_EVENTS)) {
|
|
66
|
+
this.setAttribute(ATTR_FORWARD_CUSTOM_EVENTS, "");
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const str = Array.from(val).join(",");
|
|
70
|
+
if (this.getAttribute(ATTR_FORWARD_CUSTOM_EVENTS) !== str) {
|
|
71
|
+
this.setAttribute(ATTR_FORWARD_CUSTOM_EVENTS, str);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
createEffect(() => {
|
|
76
|
+
const vc = this.viewComponent$.get();
|
|
77
|
+
if (vc) {
|
|
78
|
+
const unsubcribe = on(vc, ComponentContext.ReRequestParentRoots, () => this.#reReuestParentRoot());
|
|
79
|
+
const oldNs = vc.context?.ns;
|
|
80
|
+
return () => {
|
|
81
|
+
unsubcribe();
|
|
82
|
+
vc.destroy();
|
|
83
|
+
if (oldNs && oldNs !== this.ns) {
|
|
84
|
+
ShadowEnv.get(oldNs)?.sync();
|
|
85
|
+
} else {
|
|
175
86
|
this.syncShadowObjects();
|
|
176
|
-
|
|
177
|
-
this.#unsubscribeViewComponentEffect = () => {
|
|
178
|
-
unsubscribeComponentContext();
|
|
87
|
+
}
|
|
179
88
|
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
connectedCallback() {
|
|
211
|
-
this.#shadowRootHostNeedsUpdate = true;
|
|
212
|
-
this.addEventListener('slotchange', this.#onSlotChange, { capture: false, passive: false });
|
|
213
|
-
this.addEventListener(RequestEntParentEventName, this.#onRequestParent, { capture: false, passive: false });
|
|
214
|
-
this.#setupViewComponentEffect();
|
|
215
|
-
// --- token ---
|
|
216
|
-
beQuiet(() => this.#updateTokenValue());
|
|
217
|
-
// --- forward-custom-events ---
|
|
218
|
-
beQuiet(() => this.#updateForwardCustomEventsValue());
|
|
219
|
-
// --- componentContext | viewComponent ---
|
|
220
|
-
if (this.componentContext == null) {
|
|
221
|
-
this.componentContext$.set(ComponentContext.get(this.ns));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
createEffect(() => {
|
|
92
|
+
const vc = this.viewComponent$.get();
|
|
93
|
+
if (!vc) return;
|
|
94
|
+
const originalDispatchEvent = Object.hasOwn(vc, "dispatchEvent") ? Object.getPrototypeOf(vc).dispatchEvent : vc.dispatchEvent;
|
|
95
|
+
const filter = this.forwardCustomEvents$.get();
|
|
96
|
+
if (!filter) return;
|
|
97
|
+
const allowedTypes = filter instanceof Set ? filter : void 0;
|
|
98
|
+
const newDispatch = (type, data, traverseChildren) => {
|
|
99
|
+
originalDispatchEvent.call(vc, type, data, traverseChildren);
|
|
100
|
+
if (type === ComponentContext.ReRequestParentRoots) return;
|
|
101
|
+
if (allowedTypes && !allowedTypes.has(type)) return;
|
|
102
|
+
this.dispatchEvent(
|
|
103
|
+
new CustomEvent(type, {
|
|
104
|
+
bubbles: true,
|
|
105
|
+
composed: true,
|
|
106
|
+
detail: data
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
Object.defineProperty(vc, "dispatchEvent", {
|
|
111
|
+
value: newDispatch,
|
|
112
|
+
writable: true,
|
|
113
|
+
configurable: true
|
|
114
|
+
});
|
|
115
|
+
return () => {
|
|
116
|
+
if (Object.hasOwn(vc, "dispatchEvent") && vc.dispatchEvent === newDispatch) {
|
|
117
|
+
delete vc.dispatchEvent;
|
|
222
118
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
this.token$.onChange((token) => {
|
|
122
|
+
const vc = this.viewComponent$.value;
|
|
123
|
+
if (vc) {
|
|
124
|
+
vc.token = token;
|
|
229
125
|
this.syncShadowObjects();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
this.style.display = "contents";
|
|
129
|
+
}
|
|
130
|
+
static {
|
|
131
|
+
this.observedAttributes = [...ShaeElement.observedAttributes, ATTR_TOKEN, ATTR_FORWARD_CUSTOM_EVENTS];
|
|
132
|
+
}
|
|
133
|
+
get componentContext() {
|
|
134
|
+
return this.componentContext$.value;
|
|
135
|
+
}
|
|
136
|
+
get viewComponent() {
|
|
137
|
+
return this.viewComponent$.value;
|
|
138
|
+
}
|
|
139
|
+
get uuid() {
|
|
140
|
+
return this.viewComponent?.uuid;
|
|
141
|
+
}
|
|
142
|
+
get token() {
|
|
143
|
+
return this.token$.value;
|
|
144
|
+
}
|
|
145
|
+
set token(token) {
|
|
146
|
+
this.token$.set(token);
|
|
147
|
+
}
|
|
148
|
+
#parentObserver;
|
|
149
|
+
#unsubscribeViewComponentEffect;
|
|
150
|
+
#setupViewComponentEffect() {
|
|
151
|
+
this.#unsubscribeViewComponentEffect?.();
|
|
152
|
+
const unsubscribeComponentContext = this.componentContext$.onChange((context) => {
|
|
153
|
+
const token = this.token$.value;
|
|
154
|
+
let vc = this.viewComponent$.value;
|
|
155
|
+
if (vc) {
|
|
156
|
+
vc.context = context;
|
|
157
|
+
} else if (context) {
|
|
158
|
+
vc = new ViewComponent(token, { context });
|
|
159
|
+
this.viewComponent$.set(vc);
|
|
160
|
+
}
|
|
161
|
+
this.syncShadowObjects();
|
|
162
|
+
});
|
|
163
|
+
this.#unsubscribeViewComponentEffect = () => {
|
|
164
|
+
unsubscribeComponentContext();
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
#destroyViewComponentEffect() {
|
|
168
|
+
this.#unsubscribeViewComponentEffect?.();
|
|
169
|
+
this.#unsubscribeViewComponentEffect = void 0;
|
|
170
|
+
}
|
|
171
|
+
#shadowRootHost;
|
|
172
|
+
#shadowRootHostNeedsUpdate;
|
|
173
|
+
findShadowRootHost() {
|
|
174
|
+
if (this.#shadowRootHostNeedsUpdate) {
|
|
175
|
+
this.#shadowRootHostNeedsUpdate = false;
|
|
176
|
+
let current = this;
|
|
177
|
+
while (current) {
|
|
178
|
+
if (current.parentElement == null) {
|
|
179
|
+
const root = current.parentNode;
|
|
180
|
+
if (root) {
|
|
181
|
+
this.#shadowRootHost = root.host;
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
249
184
|
}
|
|
185
|
+
current = current.parentElement;
|
|
186
|
+
}
|
|
250
187
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
188
|
+
return this.#shadowRootHost;
|
|
189
|
+
}
|
|
190
|
+
getParentNodeForObserver() {
|
|
191
|
+
const parent = this.parentNode;
|
|
192
|
+
if (parent) return parent;
|
|
193
|
+
return parent.host ?? parent;
|
|
194
|
+
}
|
|
195
|
+
connectedCallback() {
|
|
196
|
+
this.#shadowRootHostNeedsUpdate = true;
|
|
197
|
+
this.addEventListener("slotchange", this.#onSlotChange, { capture: false, passive: false });
|
|
198
|
+
this.addEventListener(RequestEntParentEventName, this.#onRequestParent, { capture: false, passive: false });
|
|
199
|
+
this.#setupViewComponentEffect();
|
|
200
|
+
beQuiet(() => this.#updateTokenValue());
|
|
201
|
+
beQuiet(() => this.#updateForwardCustomEventsValue());
|
|
202
|
+
if (this.componentContext == null) {
|
|
203
|
+
this.componentContext$.set(ComponentContext.get(this.ns));
|
|
258
204
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
205
|
+
this.#dispatchRequestParent();
|
|
206
|
+
this.componentContext?.dispatchReRequestParentRoots();
|
|
207
|
+
this.#createParentObserver();
|
|
208
|
+
this.syncShadowObjects();
|
|
209
|
+
}
|
|
210
|
+
#createParentObserver() {
|
|
211
|
+
this.#destroyParentObserver();
|
|
212
|
+
const parent = this.getParentNodeForObserver();
|
|
213
|
+
if (parent) {
|
|
214
|
+
this.#parentObserver = new MutationObserver((mutations, _observer) => {
|
|
215
|
+
for (const { target, removedNodes } of mutations) {
|
|
216
|
+
if (target === parent) {
|
|
217
|
+
for (const node of removedNodes) {
|
|
218
|
+
if (node === this) {
|
|
219
|
+
this.#destroyParentObserver();
|
|
220
|
+
this.onParentChanged(this.getParentNodeForObserver(), parent);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
266
225
|
}
|
|
226
|
+
});
|
|
227
|
+
this.#parentObserver.observe(parent, { childList: true, subtree: false, attributes: false });
|
|
267
228
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
229
|
+
}
|
|
230
|
+
onParentChanged(_newParent, _oldParent) {
|
|
231
|
+
this.#setParent(void 0);
|
|
232
|
+
this.#dispatchRequestParent();
|
|
233
|
+
}
|
|
234
|
+
#destroyParentObserver() {
|
|
235
|
+
this.#parentObserver?.disconnect();
|
|
236
|
+
this.#parentObserver = void 0;
|
|
237
|
+
}
|
|
238
|
+
attributeChangedCallback(name) {
|
|
239
|
+
super.attributeChangedCallback(name);
|
|
240
|
+
if (name === ATTR_TOKEN) {
|
|
241
|
+
this.#updateTokenValue();
|
|
242
|
+
} else if (name === ATTR_FORWARD_CUSTOM_EVENTS) {
|
|
243
|
+
this.#updateForwardCustomEventsValue();
|
|
277
244
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
245
|
+
}
|
|
246
|
+
disconnectedCallback() {
|
|
247
|
+
this.#shadowRootHostNeedsUpdate = true;
|
|
248
|
+
this.#destroyParentObserver();
|
|
249
|
+
this.removeEventListener("slotchange", this.#onSlotChange, { capture: false });
|
|
250
|
+
this.removeEventListener(RequestEntParentEventName, this.#onRequestParent, { capture: false });
|
|
251
|
+
this.#setParent(void 0);
|
|
252
|
+
this.componentContext$.set(void 0);
|
|
253
|
+
this.syncShadowObjects();
|
|
254
|
+
this.#destroyViewComponentEffect();
|
|
255
|
+
}
|
|
256
|
+
#reReuestParentRoot() {
|
|
257
|
+
if (this.isConnected) {
|
|
258
|
+
this.#setParent(void 0);
|
|
259
|
+
this.#dispatchRequestParent();
|
|
283
260
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
261
|
+
}
|
|
262
|
+
#dispatchRequestParent() {
|
|
263
|
+
this.dispatchEvent(
|
|
264
|
+
new CustomEvent(RequestEntParentEventName, {
|
|
265
|
+
bubbles: true,
|
|
266
|
+
composed: true,
|
|
267
|
+
detail: { requester: this }
|
|
268
|
+
})
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
#unsubscribeFromParent;
|
|
272
|
+
#setParent(parent) {
|
|
273
|
+
if (this.entParentNode === parent) return;
|
|
274
|
+
if (this.entParentNode) {
|
|
275
|
+
this.entParentNode.removeEventListener(ReRequestEntParentEventName, this.#onReRequestParent, { capture: false });
|
|
291
276
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const vc = this.viewComponent$.get();
|
|
311
|
-
if (vc) {
|
|
312
|
-
const parentVC = parent.viewComponent$.get();
|
|
313
|
-
vc.parent = parentVC && parentVC.context === vc.context ? parentVC : undefined;
|
|
314
|
-
if (vc.parent == null) {
|
|
315
|
-
queueMicrotask(() => {
|
|
316
|
-
this.#dispatchRequestParent();
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
this.syncShadowObjects();
|
|
320
|
-
}
|
|
277
|
+
this.entParentNode = parent;
|
|
278
|
+
if (this.entParentNode) {
|
|
279
|
+
this.entParentNode.addEventListener(ReRequestEntParentEventName, this.#onReRequestParent, {
|
|
280
|
+
capture: false,
|
|
281
|
+
passive: false
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
this.#unsubscribeFromParent?.();
|
|
285
|
+
this.#unsubscribeFromParent = void 0;
|
|
286
|
+
if (parent) {
|
|
287
|
+
const e = createEffect(() => {
|
|
288
|
+
const vc = this.viewComponent$.get();
|
|
289
|
+
if (vc) {
|
|
290
|
+
const parentVC = parent.viewComponent$.get();
|
|
291
|
+
vc.parent = parentVC && parentVC.context === vc.context ? parentVC : void 0;
|
|
292
|
+
if (vc.parent == null) {
|
|
293
|
+
queueMicrotask(() => {
|
|
294
|
+
this.#dispatchRequestParent();
|
|
321
295
|
});
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
else {
|
|
325
|
-
const vc = this.viewComponent;
|
|
326
|
-
if (vc.parent) {
|
|
327
|
-
vc.parent = undefined;
|
|
328
|
-
this.syncShadowObjects();
|
|
329
|
-
}
|
|
296
|
+
}
|
|
297
|
+
this.syncShadowObjects();
|
|
330
298
|
}
|
|
299
|
+
});
|
|
300
|
+
this.#unsubscribeFromParent = () => e.destroy();
|
|
301
|
+
} else {
|
|
302
|
+
const vc = this.viewComponent;
|
|
303
|
+
if (vc.parent) {
|
|
304
|
+
vc.parent = void 0;
|
|
305
|
+
this.syncShadowObjects();
|
|
306
|
+
}
|
|
331
307
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
308
|
+
}
|
|
309
|
+
#onSlotChange;
|
|
310
|
+
#onReRequestParent;
|
|
311
|
+
#onRequestParent;
|
|
312
|
+
#updateTokenValue() {
|
|
313
|
+
if (this.hasAttribute(ATTR_TOKEN)) {
|
|
314
|
+
const token = this.getAttribute(ATTR_TOKEN)?.trim() || void 0;
|
|
315
|
+
this.token$.set(token);
|
|
340
316
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
317
|
+
}
|
|
318
|
+
#updateForwardCustomEventsValue() {
|
|
319
|
+
if (this.hasAttribute(ATTR_FORWARD_CUSTOM_EVENTS)) {
|
|
320
|
+
const val = this.getAttribute(ATTR_FORWARD_CUSTOM_EVENTS);
|
|
321
|
+
if (!val || val.trim().length === 0) {
|
|
322
|
+
this.forwardCustomEvents$.set(true);
|
|
323
|
+
} else {
|
|
324
|
+
this.forwardCustomEvents$.set(
|
|
325
|
+
new Set(
|
|
326
|
+
val.split(",").map((s) => s.trim()).filter((s) => s.length > 0)
|
|
327
|
+
)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
this.forwardCustomEvents$.set(false);
|
|
357
332
|
}
|
|
333
|
+
}
|
|
358
334
|
}
|
|
359
|
-
|
|
335
|
+
export {
|
|
336
|
+
ShaeEntElement
|
|
337
|
+
};
|
|
338
|
+
//# sourceMappingURL=ShaeEntElement.js.map
|