p-elements-core 1.2.32-rc7 → 1.2.32-rc8
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/src/custom-element.ts
CHANGED
|
@@ -131,7 +131,7 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
131
131
|
*
|
|
132
132
|
* @returns {readonly PropertyOptionsWithName[]} Array of property metadata
|
|
133
133
|
*/
|
|
134
|
-
get properties()
|
|
134
|
+
get properties(): readonly PropertyOptionsWithName[] {
|
|
135
135
|
const ctor = this.constructor as ComponentConstructor;
|
|
136
136
|
if (!ctor._propertyInfo) {
|
|
137
137
|
return [];
|
|
@@ -241,6 +241,8 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
241
241
|
this.#updateResolve = resolve;
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
|
+
// this.#projector.
|
|
245
|
+
// render(this.shadowRoot, this.render());
|
|
244
246
|
this.#projector?.renderNow();
|
|
245
247
|
|
|
246
248
|
// Call updated() lifecycle hook after DOM updates are complete
|
|
@@ -372,11 +374,10 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
372
374
|
this.#initStylesheet(styleElement.textContent);
|
|
373
375
|
styleElement.remove();
|
|
374
376
|
}
|
|
375
|
-
|
|
377
|
+
window.addEventListener("updatecssapply", () => {
|
|
376
378
|
this.#polyfillCssApply();
|
|
377
379
|
});
|
|
378
380
|
|
|
379
|
-
|
|
380
381
|
return fragment;
|
|
381
382
|
}
|
|
382
383
|
|
|
@@ -391,9 +392,13 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
391
392
|
element: Element,
|
|
392
393
|
render: () => VNode,
|
|
393
394
|
): Promise<Projector> {
|
|
395
|
+
await new Promise((resolve) =>
|
|
396
|
+
requestAnimationFrame(() => requestAnimationFrame(resolve)),
|
|
397
|
+
);
|
|
398
|
+
return await this.#createProjector(element, render);
|
|
399
|
+
}
|
|
394
400
|
|
|
395
|
-
|
|
396
|
-
|
|
401
|
+
#createProjector(element: Element, render: () => VNode): Promise<Projector> {
|
|
397
402
|
return new Promise<Projector>((resolve, reject) => {
|
|
398
403
|
let projector: Projector;
|
|
399
404
|
const mode = this.#projectorMode ? this.#projectorMode : "append";
|
|
@@ -403,13 +408,11 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
403
408
|
if (eventName === "renderStart" || eventName === "renderDone") {
|
|
404
409
|
this.#invokeRenderLifecycleFn(eventName);
|
|
405
410
|
}
|
|
406
|
-
}
|
|
411
|
+
},
|
|
407
412
|
});
|
|
408
413
|
projector[mode](element, render.bind(this));
|
|
409
414
|
this.#projector = projector;
|
|
410
|
-
|
|
411
|
-
projector.renderNow();
|
|
412
|
-
});
|
|
415
|
+
projector.renderNow();
|
|
413
416
|
resolve(projector);
|
|
414
417
|
this.dispatchEvent(new CustomEvent("firstRender", {}));
|
|
415
418
|
});
|
|
@@ -428,13 +431,21 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
#invokeRenderLifecycleFn(eventName: string) {
|
|
431
|
-
if (this[eventName]){
|
|
432
|
-
this[eventName](
|
|
434
|
+
if (this[eventName]) {
|
|
435
|
+
this[eventName](
|
|
436
|
+
eventName === "renderStart"
|
|
437
|
+
? this.#isFirstRenderStart
|
|
438
|
+
: this.#isFirstRenderDone,
|
|
439
|
+
);
|
|
433
440
|
}
|
|
434
441
|
const controllerEventName = `host${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
|
|
435
442
|
this.#controllers.forEach((controller) => {
|
|
436
443
|
if (controller[controllerEventName]) {
|
|
437
|
-
controller[controllerEventName](
|
|
444
|
+
controller[controllerEventName](
|
|
445
|
+
eventName === "renderStart"
|
|
446
|
+
? this.#isFirstRenderStart
|
|
447
|
+
: this.#isFirstRenderDone,
|
|
448
|
+
);
|
|
438
449
|
}
|
|
439
450
|
});
|
|
440
451
|
if (eventName === "renderStart") {
|
|
@@ -491,18 +502,17 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
491
502
|
const div = document.createElement("div");
|
|
492
503
|
this.shadowRoot.appendChild(div);
|
|
493
504
|
requestAnimationFrame(() => {
|
|
494
|
-
this
|
|
505
|
+
this.#createProjector(div, (this as any).render).then(() => {
|
|
495
506
|
this.#upgradeProperties();
|
|
496
|
-
})
|
|
507
|
+
});
|
|
497
508
|
});
|
|
498
|
-
|
|
509
|
+
window.addEventListener("updatecssapply", () => {
|
|
499
510
|
this.#polyfillCssApply();
|
|
500
511
|
});
|
|
501
|
-
|
|
502
512
|
}
|
|
503
513
|
}
|
|
504
514
|
|
|
505
|
-
#polyfillCssApply(): string {
|
|
515
|
+
#polyfillCssApply(): string {
|
|
506
516
|
let style = replaceApplyToCssVars(this.#cssText);
|
|
507
517
|
if (this.#cssText !== style) {
|
|
508
518
|
this.#cssText = style;
|
|
@@ -513,14 +523,13 @@ export abstract class CustomElement extends HTMLElement {
|
|
|
513
523
|
URL.revokeObjectURL(this.#linkElement.href);
|
|
514
524
|
}
|
|
515
525
|
this.#linkElement.href = URL.createObjectURL(
|
|
516
|
-
new Blob([style], { type: "text/css" })
|
|
526
|
+
new Blob([style], { type: "text/css" }),
|
|
517
527
|
);
|
|
518
528
|
}
|
|
519
529
|
}
|
|
520
530
|
return style;
|
|
521
531
|
}
|
|
522
532
|
|
|
523
|
-
|
|
524
533
|
#initStylesheet(style: string) {
|
|
525
534
|
this.#cssText = style;
|
|
526
535
|
if (this.#useShadowRoot && this.shadowRoot) {
|
|
@@ -69,7 +69,12 @@ let createEventHandlerInterceptor = (
|
|
|
69
69
|
// modified event handler
|
|
70
70
|
return function(this: Node, evt: Event): boolean | undefined | void {
|
|
71
71
|
performanceLogger("domEvent", evt);
|
|
72
|
-
let projection = getProjection()
|
|
72
|
+
let projection = getProjection();
|
|
73
|
+
// Guard: projection may be undefined when an event handler is invoked synchronously
|
|
74
|
+
// during initial DOM creation (e.g. by a custom-element setter calling onchange).
|
|
75
|
+
if (!projection) {
|
|
76
|
+
return eventHandler.apply(this, arguments);
|
|
77
|
+
}
|
|
73
78
|
let parentNodePath = createParentNodePath(evt.currentTarget as Element, projection.domNode);
|
|
74
79
|
parentNodePath.reverse();
|
|
75
80
|
let matchingVNode = findVNodeByParentNodePath(projection.getLastRender(), parentNodePath);
|