@radishland/runtime 0.4.0 → 0.4.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/client/index.d.ts +2 -2
- package/client/index.js +26 -10
- package/package.json +1 -1
package/client/index.d.ts
CHANGED
@@ -62,7 +62,7 @@ declare class HandlerRegistry extends HTMLElement implements AutonomousCustomEle
|
|
62
62
|
*/
|
63
63
|
lookup(identifier: string): any;
|
64
64
|
hydrateElement(element: Element): void;
|
65
|
-
|
65
|
+
hydrate(node?: Node): void;
|
66
66
|
connectedCallback(): void;
|
67
67
|
disconnectedCallback(): void;
|
68
68
|
}
|
@@ -104,4 +104,4 @@ declare const effect: (cb: EffectCallback, options?: EffectOptions) => Destructo
|
|
104
104
|
*/
|
105
105
|
declare const reactive: <T>(thing: T) => T;
|
106
106
|
|
107
|
-
export { HandlerRegistry, computed, effect, isState, reactive, signal };
|
107
|
+
export { type AutonomousCustomElement, HandlerRegistry, computed, effect, isState, reactive, signal };
|
package/client/index.js
CHANGED
@@ -128,7 +128,7 @@ var object = (init) => {
|
|
128
128
|
};
|
129
129
|
|
130
130
|
// src/handler-registry.ts
|
131
|
-
var HandlerRegistry = class
|
131
|
+
var HandlerRegistry = class extends HTMLElement {
|
132
132
|
#cleanup = [];
|
133
133
|
/**
|
134
134
|
* References the handler's `AbortController`.
|
@@ -230,7 +230,11 @@ var HandlerRegistry = class _HandlerRegistry extends HTMLElement {
|
|
230
230
|
if (identifier in this && property in target) {
|
231
231
|
const ref = this.lookup(identifier);
|
232
232
|
this.effect(() => {
|
233
|
-
target[property]
|
233
|
+
if (isState(target[property])) {
|
234
|
+
target[property].value = ref.valueOf();
|
235
|
+
} else {
|
236
|
+
target[property] = ref.valueOf();
|
237
|
+
}
|
234
238
|
});
|
235
239
|
e.stopPropagation();
|
236
240
|
}
|
@@ -417,21 +421,18 @@ var HandlerRegistry = class _HandlerRegistry extends HTMLElement {
|
|
417
421
|
element.dispatchEvent(useRequest);
|
418
422
|
}
|
419
423
|
}
|
420
|
-
|
424
|
+
// TODO: tree aware hydration that filters out HandlerRegistries and parallelize
|
425
|
+
hydrate(node = this) {
|
421
426
|
if (node instanceof Element) {
|
422
427
|
this.hydrateElement(node);
|
423
428
|
if (node.shadowRoot && node.shadowRoot.mode === "open") {
|
424
429
|
console.log("entering shadow root");
|
425
|
-
this.
|
430
|
+
this.hydrate(node.shadowRoot);
|
426
431
|
console.log("exiting shadow root");
|
427
432
|
}
|
428
433
|
let child = node.firstElementChild;
|
429
434
|
while (child) {
|
430
|
-
|
431
|
-
this.walkDOM(child);
|
432
|
-
} else {
|
433
|
-
console.log(`skipping handler registry ${child.tagName}`);
|
434
|
-
}
|
435
|
+
this.hydrate(child);
|
435
436
|
child = child.nextElementSibling;
|
436
437
|
}
|
437
438
|
}
|
@@ -448,7 +449,6 @@ var HandlerRegistry = class _HandlerRegistry extends HTMLElement {
|
|
448
449
|
this.addEventListener("rad::prop", this.#handleProp, { signal: signal2 });
|
449
450
|
this.addEventListener("rad::text", this.#handleText, { signal: signal2 });
|
450
451
|
this.addEventListener("rad::use", this.#handleUse, { signal: signal2 });
|
451
|
-
this.walkDOM(this);
|
452
452
|
}
|
453
453
|
disconnectedCallback() {
|
454
454
|
this.abortController.abort();
|
@@ -460,5 +460,21 @@ var HandlerRegistry = class _HandlerRegistry extends HTMLElement {
|
|
460
460
|
if (window && !customElements.get("handler-registry")) {
|
461
461
|
customElements?.define("handler-registry", HandlerRegistry);
|
462
462
|
}
|
463
|
+
customElements?.whenDefined("handler-registry").then(() => {
|
464
|
+
const tw = document.createTreeWalker(
|
465
|
+
document,
|
466
|
+
NodeFilter.SHOW_ELEMENT,
|
467
|
+
(node) => {
|
468
|
+
return node instanceof HandlerRegistry ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
469
|
+
}
|
470
|
+
);
|
471
|
+
let current = tw.currentNode;
|
472
|
+
while (current && !(current instanceof HandlerRegistry)) {
|
473
|
+
current = tw.nextNode();
|
474
|
+
}
|
475
|
+
if (current) {
|
476
|
+
current.hydrate();
|
477
|
+
}
|
478
|
+
});
|
463
479
|
|
464
480
|
export { HandlerRegistry, computed, effect, isState, reactive, signal };
|