@wsxjs/wsx-core 0.0.22 → 0.0.24
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/dist/{chunk-OXFZ575O.mjs → chunk-5Q2VEEUH.mjs} +352 -186
- package/dist/index.js +418 -215
- package/dist/index.mjs +67 -30
- package/dist/jsx-runtime.js +352 -186
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx.js +352 -186
- package/dist/jsx.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
- package/src/base-component.ts +27 -0
- package/src/light-component.ts +20 -8
- package/src/render-context.ts +4 -0
- package/src/utils/cache-key.ts +27 -21
- package/src/utils/element-creation.ts +5 -0
- package/src/utils/element-update.ts +192 -309
- package/src/utils/update-children-helpers.ts +508 -0
- package/src/web-component.ts +72 -41
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createLogger,
|
|
5
5
|
h,
|
|
6
6
|
shouldPreserveElement
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5Q2VEEUH.mjs";
|
|
8
8
|
|
|
9
9
|
// src/styles/style-manager.ts
|
|
10
10
|
var StyleManager = class {
|
|
@@ -401,6 +401,12 @@ var BaseComponent = class extends HTMLElement {
|
|
|
401
401
|
* @internal
|
|
402
402
|
*/
|
|
403
403
|
this._isRendering = false;
|
|
404
|
+
/**
|
|
405
|
+
* 已调度渲染标志(防止在同一事件循环中重复注册 requestAnimationFrame)
|
|
406
|
+
* 用于批量更新:同一事件循环中的多个状态变化只触发一次渲染
|
|
407
|
+
* @internal
|
|
408
|
+
*/
|
|
409
|
+
this._hasScheduledRender = false;
|
|
404
410
|
/**
|
|
405
411
|
* 处理 blur 事件,在用户停止输入时执行待处理的重渲染
|
|
406
412
|
* @internal
|
|
@@ -507,6 +513,9 @@ var BaseComponent = class extends HTMLElement {
|
|
|
507
513
|
if (this._isRendering) {
|
|
508
514
|
return;
|
|
509
515
|
}
|
|
516
|
+
if (this._hasScheduledRender) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
510
519
|
const root = this.getActiveRoot();
|
|
511
520
|
let activeElement = null;
|
|
512
521
|
if (root instanceof ShadowRoot) {
|
|
@@ -532,8 +541,16 @@ var BaseComponent = class extends HTMLElement {
|
|
|
532
541
|
if (this._pendingRerender) {
|
|
533
542
|
this._pendingRerender = false;
|
|
534
543
|
}
|
|
544
|
+
this._hasScheduledRender = true;
|
|
535
545
|
requestAnimationFrame(() => {
|
|
546
|
+
console.warn("[scheduleRerender] RAF callback:", {
|
|
547
|
+
component: this.constructor.name,
|
|
548
|
+
connected: this.connected,
|
|
549
|
+
isRendering: this._isRendering
|
|
550
|
+
});
|
|
551
|
+
this._hasScheduledRender = false;
|
|
536
552
|
if (this.connected && !this._isRendering) {
|
|
553
|
+
console.warn("[scheduleRerender] calling _rerender()");
|
|
537
554
|
this._isRendering = true;
|
|
538
555
|
this._rerender();
|
|
539
556
|
} else if (!this.connected) {
|
|
@@ -790,6 +807,7 @@ var WebComponent = class extends BaseComponent {
|
|
|
790
807
|
(child) => child instanceof HTMLElement && child.style.color === "red" && child.textContent?.includes("Component Error")
|
|
791
808
|
);
|
|
792
809
|
const hasActualContent = allChildren.length > styleElements.length + slotElements.length;
|
|
810
|
+
this.onConnected?.();
|
|
793
811
|
if (hasActualContent && !hasErrorElement) {
|
|
794
812
|
} else {
|
|
795
813
|
this.shadowRoot.innerHTML = "";
|
|
@@ -801,7 +819,6 @@ var WebComponent = class extends BaseComponent {
|
|
|
801
819
|
this.shadowRoot.appendChild(content);
|
|
802
820
|
}
|
|
803
821
|
this.initializeEventListeners();
|
|
804
|
-
this.onConnected?.();
|
|
805
822
|
if (hasActualContent === false || hasErrorElement) {
|
|
806
823
|
requestAnimationFrame(() => {
|
|
807
824
|
this.onRendered?.();
|
|
@@ -853,8 +870,12 @@ var WebComponent = class extends BaseComponent {
|
|
|
853
870
|
const focusState = this.captureFocusState();
|
|
854
871
|
this._pendingFocusState = focusState;
|
|
855
872
|
const adoptedStyleSheets = this.shadowRoot.adoptedStyleSheets || [];
|
|
873
|
+
const hasActualAdoptedStyles = this.shadowRoot.adoptedStyleSheets && this.shadowRoot.adoptedStyleSheets.length > 0;
|
|
874
|
+
const hasFallbackStyleElement = Array.from(this.shadowRoot.children).some(
|
|
875
|
+
(child) => child instanceof HTMLStyleElement
|
|
876
|
+
);
|
|
856
877
|
try {
|
|
857
|
-
if (
|
|
878
|
+
if (!hasActualAdoptedStyles && !hasFallbackStyleElement) {
|
|
858
879
|
const stylesToApply = this._autoStyles || this.config.styles;
|
|
859
880
|
if (stylesToApply) {
|
|
860
881
|
const styleName = this.config.styleName || this.constructor.name;
|
|
@@ -872,31 +893,40 @@ var WebComponent = class extends BaseComponent {
|
|
|
872
893
|
}
|
|
873
894
|
}
|
|
874
895
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
requestAnimationFrame(() => {
|
|
896
|
+
const isContentAlreadyInShadowRoot = content.parentNode === this.shadowRoot;
|
|
897
|
+
if (!isContentAlreadyInShadowRoot) {
|
|
879
898
|
this.shadowRoot.appendChild(content);
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
oldChildren.forEach((child) => child.remove());
|
|
893
|
-
requestAnimationFrame(() => {
|
|
894
|
-
this.restoreFocusState(focusState);
|
|
895
|
-
this._pendingFocusState = null;
|
|
896
|
-
this.onRendered?.();
|
|
897
|
-
this._isRendering = false;
|
|
898
|
-
});
|
|
899
|
+
}
|
|
900
|
+
const oldChildren = Array.from(this.shadowRoot.children).filter((child) => {
|
|
901
|
+
if (child === content) {
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
if (child instanceof HTMLStyleElement) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
if (shouldPreserveElement(child)) {
|
|
908
|
+
return false;
|
|
909
|
+
}
|
|
910
|
+
return true;
|
|
899
911
|
});
|
|
912
|
+
oldChildren.forEach((child) => child.remove());
|
|
913
|
+
const hasStylesAfterDOM = this.shadowRoot.adoptedStyleSheets && this.shadowRoot.adoptedStyleSheets.length > 0;
|
|
914
|
+
const hasStyleElementAfterDOM = Array.from(this.shadowRoot.children).some(
|
|
915
|
+
(child) => child instanceof HTMLStyleElement
|
|
916
|
+
);
|
|
917
|
+
if (adoptedStyleSheets.length > 0) {
|
|
918
|
+
this.shadowRoot.adoptedStyleSheets = adoptedStyleSheets;
|
|
919
|
+
} else if (!hasStylesAfterDOM && !hasStyleElementAfterDOM) {
|
|
920
|
+
const stylesToApply = this._autoStyles || this.config.styles;
|
|
921
|
+
if (stylesToApply) {
|
|
922
|
+
const styleName = this.config.styleName || this.constructor.name;
|
|
923
|
+
StyleManager.applyStyles(this.shadowRoot, styleName, stylesToApply);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
this.restoreFocusState(focusState);
|
|
927
|
+
this._pendingFocusState = null;
|
|
928
|
+
this.onRendered?.();
|
|
929
|
+
this._isRendering = false;
|
|
900
930
|
} catch (error) {
|
|
901
931
|
logger3.error("Error in _rerender:", error);
|
|
902
932
|
this.renderError(error);
|
|
@@ -958,6 +988,7 @@ var LightComponent = class extends BaseComponent {
|
|
|
958
988
|
const hasActualContent = Array.from(this.children).some(
|
|
959
989
|
(child) => child !== styleElement && !(child instanceof HTMLSlotElement)
|
|
960
990
|
);
|
|
991
|
+
this.onConnected?.();
|
|
961
992
|
if (hasActualContent && !hasErrorElement) {
|
|
962
993
|
this.markJSXChildren();
|
|
963
994
|
if (styleElement && styleElement !== this.firstChild) {
|
|
@@ -975,7 +1006,6 @@ var LightComponent = class extends BaseComponent {
|
|
|
975
1006
|
}
|
|
976
1007
|
}
|
|
977
1008
|
this.initializeEventListeners();
|
|
978
|
-
this.onConnected?.();
|
|
979
1009
|
if (hasActualContent === false || hasErrorElement) {
|
|
980
1010
|
requestAnimationFrame(() => {
|
|
981
1011
|
this.onRendered?.();
|
|
@@ -1074,11 +1104,18 @@ var LightComponent = class extends BaseComponent {
|
|
|
1074
1104
|
return true;
|
|
1075
1105
|
});
|
|
1076
1106
|
oldChildren.forEach((child) => child.remove());
|
|
1077
|
-
if (stylesToApply
|
|
1078
|
-
|
|
1107
|
+
if (stylesToApply) {
|
|
1108
|
+
let styleElement = this.querySelector(
|
|
1079
1109
|
`style[data-wsx-light-component="${styleName}"]`
|
|
1080
1110
|
);
|
|
1081
|
-
if (styleElement
|
|
1111
|
+
if (!styleElement) {
|
|
1112
|
+
styleElement = document.createElement("style");
|
|
1113
|
+
styleElement.setAttribute("data-wsx-light-component", styleName);
|
|
1114
|
+
styleElement.textContent = stylesToApply;
|
|
1115
|
+
this.insertBefore(styleElement, this.firstChild);
|
|
1116
|
+
} else if (styleElement.textContent !== stylesToApply) {
|
|
1117
|
+
styleElement.textContent = stylesToApply;
|
|
1118
|
+
} else if (styleElement !== this.firstChild) {
|
|
1082
1119
|
this.insertBefore(styleElement, this.firstChild);
|
|
1083
1120
|
}
|
|
1084
1121
|
}
|