@spearwolf/shadow-objects 0.30.2 → 0.32.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/bundle.js +13 -13
  3. package/package.json +3 -3
  4. package/src/bundle.js +4 -4
  5. package/src/bundle.js.map +7 -1
  6. package/src/constants.js +53 -40
  7. package/src/constants.js.map +7 -1
  8. package/src/create-worker.bundle.js +6 -8
  9. package/src/create-worker.bundle.js.map +7 -1
  10. package/src/create-worker.js +5 -2
  11. package/src/create-worker.js.map +7 -1
  12. package/src/elements/ShaeElement.js +57 -54
  13. package/src/elements/ShaeElement.js.map +7 -1
  14. package/src/elements/ShaeEntElement.d.ts.map +1 -1
  15. package/src/elements/ShaeEntElement.js +320 -341
  16. package/src/elements/ShaeEntElement.js.map +7 -1
  17. package/src/elements/ShaePropElement.js +312 -320
  18. package/src/elements/ShaePropElement.js.map +7 -1
  19. package/src/elements/ShaeWorkerElement.js +234 -229
  20. package/src/elements/ShaeWorkerElement.js.map +7 -1
  21. package/src/elements/constants.js +37 -22
  22. package/src/elements/constants.js.map +7 -1
  23. package/src/elements/events.d.ts +1 -1
  24. package/src/elements/events.d.ts.map +1 -1
  25. package/src/elements/events.js +1 -2
  26. package/src/elements/events.js.map +7 -1
  27. package/src/elements.js +4 -4
  28. package/src/elements.js.map +7 -1
  29. package/src/in-the-dark/Entity.d.ts +1 -1
  30. package/src/in-the-dark/Entity.d.ts.map +1 -1
  31. package/src/in-the-dark/Entity.js +299 -293
  32. package/src/in-the-dark/Entity.js.map +7 -1
  33. package/src/in-the-dark/Kernel.d.ts.map +1 -1
  34. package/src/in-the-dark/Kernel.js +556 -533
  35. package/src/in-the-dark/Kernel.js.map +7 -1
  36. package/src/in-the-dark/Registry.d.ts.map +1 -1
  37. package/src/in-the-dark/Registry.js +101 -104
  38. package/src/in-the-dark/Registry.js.map +7 -1
  39. package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
  40. package/src/in-the-dark/ShadowObject.js +21 -23
  41. package/src/in-the-dark/ShadowObject.js.map +7 -1
  42. package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
  43. package/src/in-the-dark/SignalsPath.js +139 -123
  44. package/src/in-the-dark/SignalsPath.js.map +7 -1
  45. package/src/in-the-dark/events.js +11 -9
  46. package/src/in-the-dark/events.js.map +7 -1
  47. package/src/in-the-dark/importModule.js +31 -29
  48. package/src/in-the-dark/importModule.js.map +7 -1
  49. package/src/index.d.ts +2 -2
  50. package/src/index.d.ts.map +1 -1
  51. package/src/index.js +14 -14
  52. package/src/index.js.map +7 -1
  53. package/src/shadow-objects.js +6 -6
  54. package/src/shadow-objects.js.map +7 -1
  55. package/src/shadow-objects.worker.js +3 -3
  56. package/src/shadow-objects.worker.js.map +7 -1
  57. package/src/shae-ent.js +3 -3
  58. package/src/shae-ent.js.map +7 -1
  59. package/src/shae-prop.js +3 -3
  60. package/src/shae-prop.js.map +7 -1
  61. package/src/shae-worker.js +3 -3
  62. package/src/shae-worker.js.map +7 -1
  63. package/src/types.d.ts +3 -2
  64. package/src/types.d.ts.map +1 -1
  65. package/src/types.js +1 -2
  66. package/src/types.js.map +7 -1
  67. package/src/utils/ConsoleLogger.js +179 -185
  68. package/src/utils/ConsoleLogger.js.map +7 -1
  69. package/src/utils/FrameLoop.js +41 -40
  70. package/src/utils/FrameLoop.js.map +7 -1
  71. package/src/utils/array-utils.js +22 -24
  72. package/src/utils/array-utils.js.map +7 -1
  73. package/src/utils/attr-utils.js +15 -11
  74. package/src/utils/attr-utils.js.map +7 -1
  75. package/src/utils/constants.js +5 -2
  76. package/src/utils/constants.js.map +7 -1
  77. package/src/utils/generateUUID.d.ts.map +1 -1
  78. package/src/utils/generateUUID.js +269 -32
  79. package/src/utils/generateUUID.js.map +7 -1
  80. package/src/utils/props-utils.js +34 -43
  81. package/src/utils/props-utils.js.map +7 -1
  82. package/src/utils/toMaybe.js +5 -2
  83. package/src/utils/toMaybe.js.map +7 -1
  84. package/src/utils/toNamespace.js +6 -3
  85. package/src/utils/toNamespace.js.map +7 -1
  86. package/src/utils/toUrlString.js +9 -6
  87. package/src/utils/toUrlString.js.map +7 -1
  88. package/src/utils/waitForMessageOfType.js +30 -32
  89. package/src/utils/waitForMessageOfType.js.map +7 -1
  90. package/src/view/ComponentChanges.d.ts +1 -1
  91. package/src/view/ComponentChanges.d.ts.map +1 -1
  92. package/src/view/ComponentChanges.js +249 -251
  93. package/src/view/ComponentChanges.js.map +7 -1
  94. package/src/view/ComponentContext.d.ts.map +1 -1
  95. package/src/view/ComponentContext.js +303 -331
  96. package/src/view/ComponentContext.js.map +7 -1
  97. package/src/view/ComponentMemory.d.ts +1 -0
  98. package/src/view/ComponentMemory.d.ts.map +1 -1
  99. package/src/view/ComponentMemory.js +73 -76
  100. package/src/view/ComponentMemory.js.map +7 -1
  101. package/src/view/IShadowObjectEnvProxy.js +1 -2
  102. package/src/view/IShadowObjectEnvProxy.js.map +7 -1
  103. package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
  104. package/src/view/LocalShadowObjectEnv.js +57 -52
  105. package/src/view/LocalShadowObjectEnv.js.map +7 -1
  106. package/src/view/RemoteWorkerEnv.js +134 -123
  107. package/src/view/RemoteWorkerEnv.js.map +7 -1
  108. package/src/view/ShadowEnv.d.ts.map +1 -1
  109. package/src/view/ShadowEnv.js +232 -228
  110. package/src/view/ShadowEnv.js.map +7 -1
  111. package/src/view/ViewComponent.d.ts +9 -0
  112. package/src/view/ViewComponent.d.ts.map +1 -1
  113. package/src/view/ViewComponent.js +142 -130
  114. package/src/view/ViewComponent.js.map +7 -1
  115. package/src/view/cloneChangeTrail.js +13 -11
  116. package/src/view/cloneChangeTrail.js.map +7 -1
  117. package/src/worker/MessageRouter.d.ts.map +1 -1
  118. package/src/worker/MessageRouter.js +78 -67
  119. package/src/worker/MessageRouter.js.map +7 -1
  120. package/src/worker/WorkerRuntime.js +22 -21
  121. package/src/worker/WorkerRuntime.js.map +7 -1
  122. package/tsconfig.lib.tsbuildinfo +0 -1
@@ -1,359 +1,338 @@
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 { ShaeElement } from './ShaeElement.js';
7
- import { ATTR_FORWARD_CUSTOM_EVENTS, ATTR_TOKEN, RequestEntParentEventName, ReRequestEntParentEventName } from './constants.js';
8
- export class ShaeEntElement extends ShaeElement {
9
- static { this.observedAttributes = [...ShaeElement.observedAttributes, ATTR_TOKEN, ATTR_FORWARD_CUSTOM_EVENTS]; }
10
- get componentContext() {
11
- return this.componentContext$.value;
12
- }
13
- get viewComponent() {
14
- return this.viewComponent$.value;
15
- }
16
- get uuid() {
17
- return this.viewComponent?.uuid;
18
- }
19
- get token() {
20
- return this.token$.value;
21
- }
22
- set token(token) {
23
- this.token$.set(token);
24
- }
25
- #parentObserver;
26
- constructor() {
27
- super();
28
- this.isShaeEntElement = true;
29
- this.componentContext$ = createSignal();
30
- this.viewComponent$ = createSignal();
31
- this.token$ = createSignal();
32
- this.forwardCustomEvents$ = createSignal(false);
33
- this.#shadowRootHostNeedsUpdate = true;
34
- this.#onSlotChange = () => {
35
- const shadowRootHost = this.findShadowRootHost();
36
- if (shadowRootHost == null)
37
- return;
38
- this.dispatchEvent(new CustomEvent(ReRequestEntParentEventName, {
39
- bubbles: true,
40
- composed: true,
41
- detail: { requester: this, shadowRootHost },
42
- }));
43
- };
44
- this.#onReRequestParent = (event) => {
45
- const requester = event.detail?.requester;
46
- if (requester === this)
47
- return;
48
- if (!requester?.isShaeEntElement)
49
- return;
50
- if (requester.ns !== this.ns)
51
- return;
52
- const shadowRootHost = event.detail?.shadowRootHost;
53
- if (shadowRootHost) {
54
- this.#dispatchRequestParent();
55
- }
56
- };
57
- this.#onRequestParent = (event) => {
58
- const requester = event.detail?.requester;
59
- if (requester === this)
60
- return;
61
- if (!requester?.isShaeEntElement)
62
- return;
63
- if (requester.ns !== this.ns)
64
- return;
65
- event.stopPropagation();
66
- requester.#setParent(this);
67
- };
68
- this.ns$.onChange((ns) => {
69
- this.componentContext$.set(ComponentContext.get(ns));
70
- if (this.isConnected) {
71
- this.#dispatchRequestParent();
72
- }
73
- });
74
- this.#updateTokenValue();
75
- this.token$.onChange((token) => {
76
- if (token == null) {
77
- this.removeAttribute(ATTR_TOKEN);
78
- }
79
- else if (this.getAttribute(ATTR_TOKEN) !== token) {
80
- this.setAttribute(ATTR_TOKEN, token);
81
- }
82
- });
83
- this.#updateForwardCustomEventsValue();
84
- this.forwardCustomEvents$.onChange((val) => {
85
- if (!val) {
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
- #destroyViewComponentEffect() {
182
- this.#unsubscribeViewComponentEffect?.();
183
- this.#unsubscribeViewComponentEffect = undefined;
184
- }
185
- #shadowRootHost;
186
- #shadowRootHostNeedsUpdate;
187
- findShadowRootHost() {
188
- if (this.#shadowRootHostNeedsUpdate) {
189
- this.#shadowRootHostNeedsUpdate = false;
190
- let current = this;
191
- while (current) {
192
- if (current.parentElement == null) {
193
- const root = current.parentNode;
194
- if (root) {
195
- this.#shadowRootHost = root.host;
196
- }
197
- break;
198
- }
199
- current = current.parentElement;
200
- }
201
- }
202
- return this.#shadowRootHost;
203
- }
204
- getParentNodeForObserver() {
205
- const parent = this.parentNode;
206
- if (parent)
207
- return parent;
208
- return parent.host ?? parent;
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
- // --- viewComponent.parent ---
224
- this.#dispatchRequestParent();
225
- // --- parents ---
226
- this.componentContext?.dispatchReRequestParentRoots();
227
- this.#createParentObserver();
228
- // --- sync! ---
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
- #createParentObserver() {
232
- this.#destroyParentObserver();
233
- const parent = this.getParentNodeForObserver();
234
- if (parent) {
235
- this.#parentObserver = new MutationObserver((mutations, _observer) => {
236
- for (const { target, removedNodes } of mutations) {
237
- if (target === parent) {
238
- for (const node of removedNodes) {
239
- if (node === this) {
240
- this.#destroyParentObserver();
241
- this.onParentChanged(this.getParentNodeForObserver(), parent);
242
- break;
243
- }
244
- }
245
- }
246
- }
247
- });
248
- this.#parentObserver.observe(parent, { childList: true, subtree: false, attributes: false });
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
- onParentChanged(_newParent, _oldParent) {
252
- this.#setParent(undefined);
253
- this.#dispatchRequestParent();
254
- }
255
- #destroyParentObserver() {
256
- this.#parentObserver?.disconnect();
257
- this.#parentObserver = undefined;
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
- attributeChangedCallback(name) {
260
- super.attributeChangedCallback(name);
261
- if (name === ATTR_TOKEN) {
262
- this.#updateTokenValue();
263
- }
264
- else if (name === ATTR_FORWARD_CUSTOM_EVENTS) {
265
- this.#updateForwardCustomEventsValue();
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
- disconnectedCallback() {
269
- this.#shadowRootHostNeedsUpdate = true;
270
- this.#destroyParentObserver();
271
- this.removeEventListener('slotchange', this.#onSlotChange, { capture: false });
272
- this.removeEventListener(RequestEntParentEventName, this.#onRequestParent, { capture: false });
273
- this.#setParent(undefined);
274
- this.componentContext$.set(undefined);
275
- this.syncShadowObjects();
276
- this.#destroyViewComponentEffect();
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
- #reReuestParentRoot() {
279
- if (this.isConnected) {
280
- this.#setParent(undefined);
281
- this.#dispatchRequestParent();
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
- #dispatchRequestParent() {
285
- // https://pm.dartus.fr/blog/a-complete-guide-on-shadow-dom-and-event-propagation/
286
- this.dispatchEvent(new CustomEvent(RequestEntParentEventName, {
287
- bubbles: true,
288
- composed: true,
289
- detail: { requester: this },
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
- #unsubscribeFromParent;
293
- #setParent(parent) {
294
- if (this.entParentNode === parent)
295
- return;
296
- if (this.entParentNode) {
297
- this.entParentNode.removeEventListener(ReRequestEntParentEventName, this.#onReRequestParent, { capture: false });
298
- }
299
- this.entParentNode = parent;
300
- if (this.entParentNode) {
301
- this.entParentNode.addEventListener(ReRequestEntParentEventName, this.#onReRequestParent, {
302
- capture: false,
303
- passive: false,
304
- });
305
- }
306
- this.#unsubscribeFromParent?.();
307
- this.#unsubscribeFromParent = undefined;
308
- if (parent) {
309
- const e = createEffect(() => {
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
- this.#unsubscribeFromParent = () => e.destroy();
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
- #onSlotChange;
333
- #onReRequestParent;
334
- #onRequestParent;
335
- #updateTokenValue() {
336
- if (this.hasAttribute(ATTR_TOKEN)) {
337
- const token = this.getAttribute(ATTR_TOKEN)?.trim() || undefined;
338
- this.token$.set(token);
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
- #updateForwardCustomEventsValue() {
342
- if (this.hasAttribute(ATTR_FORWARD_CUSTOM_EVENTS)) {
343
- const val = this.getAttribute(ATTR_FORWARD_CUSTOM_EVENTS);
344
- if (!val || val.trim().length === 0) {
345
- this.forwardCustomEvents$.set(true);
346
- }
347
- else {
348
- this.forwardCustomEvents$.set(new Set(val
349
- .split(',')
350
- .map((s) => s.trim())
351
- .filter((s) => s.length > 0)));
352
- }
353
- }
354
- else {
355
- this.forwardCustomEvents$.set(false);
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
- //# sourceMappingURL=ShaeEntElement.js.map
335
+ export {
336
+ ShaeEntElement
337
+ };
338
+ //# sourceMappingURL=ShaeEntElement.js.map