@dooboostore/simple-web-component 1.0.50 → 1.0.51
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/README.md +735 -354
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +64 -146
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +36 -48
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +9 -12
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +14 -22
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +12 -42
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +3 -3
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +9 -12
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/around.js +124 -0
- package/dist/cjs/decorators/around.js.map +7 -0
- package/dist/cjs/decorators/changedAttribute.js +40 -12
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +224 -195
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +14 -12
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/eventMedia.js +36 -8
- package/dist/cjs/decorators/eventMedia.js.map +2 -2
- package/dist/cjs/decorators/fetch.js +278 -0
- package/dist/cjs/decorators/fetch.js.map +7 -0
- package/dist/cjs/decorators/index.js +5 -2
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +33 -13
- package/dist/cjs/decorators/intersectionObserver.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +11 -11
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/mutationObserver.js +55 -39
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/parameter.js +92 -9
- package/dist/cjs/decorators/parameter.js.map +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/cjs/decorators/query.js +11 -5
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +7 -16
- package/dist/cjs/decorators/requestAnimationFrame.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +41 -17
- package/dist/cjs/decorators/resizeObserver.js.map +3 -3
- package/dist/cjs/decorators/setInterval.js +36 -25
- package/dist/cjs/decorators/setInterval.js.map +2 -2
- package/dist/cjs/decorators/setTimeout.js +36 -25
- package/dist/cjs/decorators/setTimeout.js.map +2 -2
- package/dist/cjs/decorators/state.js +13 -10
- package/dist/cjs/decorators/state.js.map +2 -2
- package/dist/cjs/decorators/{subscribeSwcAppMessageWhileConnected.js → subscribeSwcAppMessage.js} +20 -21
- package/dist/cjs/decorators/subscribeSwcAppMessage.js.map +7 -0
- package/dist/cjs/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +23 -19
- package/dist/cjs/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/cjs/decorators/swcAppRoute.js +149 -0
- package/dist/cjs/decorators/swcAppRoute.js.map +7 -0
- package/dist/cjs/elements/SwcApp.js +70 -0
- package/dist/cjs/elements/SwcApp.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +256 -83
- package/dist/cjs/elements/SwcAppMixin.js.map +3 -3
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/cjs/utils/Utils.js +36 -15
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +64 -146
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +36 -48
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +9 -12
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +15 -23
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +12 -42
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +3 -3
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +9 -12
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/around.js +105 -0
- package/dist/esm/decorators/around.js.map +7 -0
- package/dist/esm/decorators/changedAttribute.js +40 -12
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +222 -193
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +15 -13
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/eventMedia.js +36 -8
- package/dist/esm/decorators/eventMedia.js.map +2 -2
- package/dist/esm/decorators/fetch.js +259 -0
- package/dist/esm/decorators/fetch.js.map +7 -0
- package/dist/esm/decorators/index.js +5 -2
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +33 -13
- package/dist/esm/decorators/intersectionObserver.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +11 -11
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/mutationObserver.js +55 -39
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/parameter.js +92 -9
- package/dist/esm/decorators/parameter.js.map +2 -2
- package/dist/esm/decorators/publishSwcAppMessage.js +2 -2
- package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/esm/decorators/query.js +11 -5
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +8 -17
- package/dist/esm/decorators/requestAnimationFrame.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +41 -17
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +37 -26
- package/dist/esm/decorators/setInterval.js.map +2 -2
- package/dist/esm/decorators/setTimeout.js +37 -26
- package/dist/esm/decorators/setTimeout.js.map +2 -2
- package/dist/esm/decorators/state.js +13 -10
- package/dist/esm/decorators/state.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessage.js +53 -0
- package/dist/esm/decorators/subscribeSwcAppMessage.js.map +7 -0
- package/dist/esm/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +20 -16
- package/dist/esm/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/esm/decorators/swcAppRoute.js +130 -0
- package/dist/esm/decorators/swcAppRoute.js.map +7 -0
- package/dist/esm/elements/SwcApp.js +70 -0
- package/dist/esm/elements/SwcApp.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +258 -85
- package/dist/esm/elements/SwcAppMixin.js.map +3 -3
- package/dist/esm/types/index.js +5 -1
- package/dist/esm/types/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +36 -15
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1886 -999
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts +1 -0
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +923 -960
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +26 -38
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +1 -3
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +15 -17
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +25 -45
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +1 -3
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/around.d.ts +87 -0
- package/dist/types/decorators/around.d.ts.map +1 -0
- package/dist/types/decorators/changedAttribute.d.ts +21 -1
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +0 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/eventMedia.d.ts +24 -1
- package/dist/types/decorators/eventMedia.d.ts.map +1 -1
- package/dist/types/decorators/fetch.d.ts +139 -0
- package/dist/types/decorators/fetch.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +5 -2
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +24 -11
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +8 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/mutationObserver.d.ts +26 -13
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +84 -6
- package/dist/types/decorators/parameter.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts +0 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +7 -7
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +26 -13
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +10 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -1
- package/dist/types/decorators/setTimeout.d.ts +10 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts +44 -0
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts +60 -0
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts.map +1 -0
- package/dist/types/decorators/swcAppRoute.d.ts +94 -0
- package/dist/types/decorators/swcAppRoute.d.ts.map +1 -0
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +423 -388
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +43 -4
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +15 -5
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1886 -999
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/addEventListener.ts +102 -96
- package/src/decorators/applyAttribute.ts +76 -138
- package/src/decorators/applyClass.ts +8 -14
- package/src/decorators/applyNode.ts +33 -41
- package/src/decorators/applyProperty.ts +51 -99
- package/src/decorators/applySlot.ts +3 -3
- package/src/decorators/applyStyle.ts +8 -14
- package/src/decorators/around.ts +196 -0
- package/src/decorators/changedAttribute.ts +39 -15
- package/src/decorators/elementDefine.ts +270 -219
- package/src/decorators/emitCustomEvent.ts +17 -13
- package/src/decorators/eventMedia.ts +50 -9
- package/src/decorators/fetch.ts +454 -0
- package/src/decorators/index.ts +5 -2
- package/src/decorators/intersectionObserver.ts +38 -24
- package/src/decorators/lifecycles.ts +24 -22
- package/src/decorators/mutationObserver.ts +71 -52
- package/src/decorators/parameter.ts +145 -14
- package/src/decorators/publishSwcAppMessage.ts +3 -4
- package/src/decorators/query.ts +22 -14
- package/src/decorators/requestAnimationFrame.ts +10 -19
- package/src/decorators/resizeObserver.ts +50 -29
- package/src/decorators/setInterval.ts +37 -26
- package/src/decorators/setTimeout.ts +37 -26
- package/src/decorators/state.ts +19 -13
- package/src/decorators/subscribeSwcAppMessage.ts +106 -0
- package/src/decorators/subscribeSwcAppRouteChange.ts +131 -0
- package/src/decorators/swcAppRoute.ts +231 -0
- package/src/elements/SwcApp.ts +40 -10
- package/src/elements/SwcAppMixin.ts +330 -101
- package/src/types/index.ts +38 -5
- package/src/utils/Utils.ts +50 -18
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +0 -54
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +0 -23
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +0 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +0 -31
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +0 -1
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +0 -91
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +0 -107
|
@@ -41,16 +41,18 @@ var import_types = require("../types");
|
|
|
41
41
|
var import_core_web = require("@dooboostore/core-web");
|
|
42
42
|
var import_SwcAppMixin = require("../elements/SwcAppMixin");
|
|
43
43
|
var import_state = require("./state");
|
|
44
|
+
var import_around = require("./around");
|
|
44
45
|
var import_applyProperty = require("./applyProperty");
|
|
45
|
-
var
|
|
46
|
-
var
|
|
46
|
+
var import_subscribeSwcAppMessage = require("./subscribeSwcAppMessage");
|
|
47
|
+
var import_subscribeSwcAppRouteChange = require("./subscribeSwcAppRouteChange");
|
|
47
48
|
var import_setInterval = require("./setInterval");
|
|
48
49
|
var import_setTimeout = require("./setTimeout");
|
|
49
50
|
var import_requestAnimationFrame = require("./requestAnimationFrame");
|
|
50
51
|
var import_eventMedia = require("./eventMedia");
|
|
52
|
+
var import_fetch = require("./fetch");
|
|
51
53
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
52
54
|
const getElementConfig = (target) => {
|
|
53
|
-
const constructor = target
|
|
55
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
54
56
|
return import_core.ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
55
57
|
};
|
|
56
58
|
const ensureInit = (inst) => {
|
|
@@ -58,7 +60,7 @@ const ensureInit = (inst) => {
|
|
|
58
60
|
inst._swcId = inst?.getAttribute?.("swc-use-ssr") ?? "s" + Math.random().toString(36).substring(2, 11).toLowerCase();
|
|
59
61
|
inst._emitHandlers = /* @__PURE__ */ new Map();
|
|
60
62
|
inst.__swc_initialized = true;
|
|
61
|
-
const target = inst
|
|
63
|
+
const target = typeof inst === "function" ? inst : inst.constructor;
|
|
62
64
|
const attributeAllList = (0, import_applyAttribute.findAllAttributeMetadata)(target).filter((it) => it.type === "property");
|
|
63
65
|
if (attributeAllList) {
|
|
64
66
|
attributeAllList.forEach((meta) => {
|
|
@@ -80,15 +82,40 @@ const ensureInit = (inst) => {
|
|
|
80
82
|
const propertyAllList = (0, import_applyProperty.findAllPropertyMetadata)(target).filter((it) => it.type === "property");
|
|
81
83
|
if (propertyAllList) {
|
|
82
84
|
propertyAllList.forEach((meta) => {
|
|
85
|
+
let proto = Object.getPrototypeOf(inst);
|
|
86
|
+
let hasGetter = false;
|
|
87
|
+
while (proto && proto !== Object.prototype) {
|
|
88
|
+
const d = Object.getOwnPropertyDescriptor(proto, meta.propertyKey);
|
|
89
|
+
if (d) {
|
|
90
|
+
hasGetter = typeof d.get === "function";
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
proto = Object.getPrototypeOf(proto);
|
|
94
|
+
}
|
|
95
|
+
if (!hasGetter) return;
|
|
83
96
|
delete inst[meta.propertyKey];
|
|
84
97
|
});
|
|
85
98
|
}
|
|
86
99
|
const stateAllList = (0, import_state.findAllStateMetadata)(target);
|
|
87
100
|
if (stateAllList) {
|
|
88
101
|
stateAllList.forEach((meta) => {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
|
|
103
|
+
if (own && "value" in own) {
|
|
104
|
+
const initUserData = own.value;
|
|
105
|
+
delete inst[meta.propertyKey];
|
|
106
|
+
inst[meta.propertyKey] = initUserData;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const aroundAllList = (0, import_around.findAllAroundMetadata)(target);
|
|
111
|
+
if (aroundAllList) {
|
|
112
|
+
aroundAllList.forEach((meta) => {
|
|
113
|
+
const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
|
|
114
|
+
if (own && "value" in own) {
|
|
115
|
+
const initUserData = own.value;
|
|
116
|
+
delete inst[meta.propertyKey];
|
|
117
|
+
inst[meta.propertyKey] = initUserData;
|
|
118
|
+
}
|
|
92
119
|
});
|
|
93
120
|
}
|
|
94
121
|
const hostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
@@ -108,7 +135,7 @@ const handleGlobalSwcEvent = async (event) => {
|
|
|
108
135
|
if (!(node instanceof HTMLElement)) continue;
|
|
109
136
|
const script = node.getAttribute?.(attrName);
|
|
110
137
|
if (script && !getElementConfig(node)) {
|
|
111
|
-
const host = import_Utils.SwcUtils.
|
|
138
|
+
const host = import_Utils.SwcUtils.findNearestSwcAncestorHost(node);
|
|
112
139
|
if (host && host.isConnected && typeof host.__swc_executeAttributeEvent === "function") {
|
|
113
140
|
await host.__swc_executeAttributeEvent(node, attrName, script, event);
|
|
114
141
|
event.__swc_handled = true;
|
|
@@ -139,8 +166,7 @@ const setupPrototype = (proto, win) => {
|
|
|
139
166
|
const script = this.getAttribute(attrName);
|
|
140
167
|
if (script) {
|
|
141
168
|
try {
|
|
142
|
-
const
|
|
143
|
-
const currentWin = this._resolveWindow(conf);
|
|
169
|
+
const currentWin = import_Utils.SwcUtils.resolveWindow(this);
|
|
144
170
|
const helpers = import_Utils.SwcUtils.getHelperSet(currentWin);
|
|
145
171
|
const args = { ...hostSet, ...helpers, ...extraArgs, $el: this, $root: this.getRootNode() };
|
|
146
172
|
import_core.FunctionUtils.execute({ script, context: this, args });
|
|
@@ -149,20 +175,10 @@ const setupPrototype = (proto, win) => {
|
|
|
149
175
|
}
|
|
150
176
|
}
|
|
151
177
|
};
|
|
152
|
-
proto._resolveWindow = function(localConfig) {
|
|
153
|
-
ensureInit(this);
|
|
154
|
-
if (localConfig?.window) return localConfig.window;
|
|
155
|
-
const ancestors = import_Utils.SwcUtils.findAllSwcHostsIncludingSelf(this);
|
|
156
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
157
|
-
const aConf = getElementConfig(ancestors[i]);
|
|
158
|
-
if (aConf?.window) return aConf.window;
|
|
159
|
-
}
|
|
160
|
-
return getElementConfig(this).window ?? (typeof window !== "undefined" ? window : void 0);
|
|
161
|
-
};
|
|
162
178
|
proto._invokeLifecycleMethod = function(methodName, hostSet, extraArgs = []) {
|
|
163
179
|
ensureInit(this);
|
|
164
180
|
if (typeof this[methodName] !== "function") return;
|
|
165
|
-
const useHostSet = hostSet ?? import_Utils.SwcUtils.getHelperAndHostSet(
|
|
181
|
+
const useHostSet = hostSet ?? import_Utils.SwcUtils.getHelperAndHostSet(this);
|
|
166
182
|
const app = useHostSet?.$appHost?.simpleApplication;
|
|
167
183
|
const helperSetValue = import_Utils.SwcUtils.getHelperSet(win);
|
|
168
184
|
const helperHostSetValue = { ...helperSetValue, ...useHostSet, $this: this };
|
|
@@ -180,7 +196,7 @@ const setupPrototype = (proto, win) => {
|
|
|
180
196
|
const firstCheckMaker = ({ target, targetKey }, token, idx) => {
|
|
181
197
|
const saves = (0, import_parameter.getParameterMetadata)(target, targetKey);
|
|
182
198
|
const found = saves.find((s) => s.index === idx);
|
|
183
|
-
return found ? kindValues[found.kind] : void 0;
|
|
199
|
+
return found ? kindValues[found.kind] ?? null : void 0;
|
|
184
200
|
};
|
|
185
201
|
return app.simstanceManager.executeBindParameterSim(
|
|
186
202
|
{
|
|
@@ -212,8 +228,7 @@ const setupPrototype = (proto, win) => {
|
|
|
212
228
|
if (oldHandler) el.removeEventListener(eventName, oldHandler);
|
|
213
229
|
const handler = async (event) => {
|
|
214
230
|
const hostSet = import_Utils.SwcUtils.getHostSet(el);
|
|
215
|
-
const
|
|
216
|
-
const currentWin = this._resolveWindow(conf);
|
|
231
|
+
const currentWin = import_Utils.SwcUtils.resolveWindow(this);
|
|
217
232
|
const helpers = import_Utils.SwcUtils.getHelperSet(currentWin);
|
|
218
233
|
const args = {
|
|
219
234
|
event,
|
|
@@ -231,8 +246,7 @@ const setupPrototype = (proto, win) => {
|
|
|
231
246
|
proto.__swc_executeAttributeEvent = async function(el, attrName, script, event) {
|
|
232
247
|
ensureInit(this);
|
|
233
248
|
const hostSet = import_Utils.SwcUtils.getHostSet(el);
|
|
234
|
-
const
|
|
235
|
-
const currentWin = this._resolveWindow(conf);
|
|
249
|
+
const currentWin = import_Utils.SwcUtils.resolveWindow(this);
|
|
236
250
|
const currentHelpers = import_Utils.SwcUtils.getHelperSet(currentWin);
|
|
237
251
|
const detail = event.detail;
|
|
238
252
|
const args = {
|
|
@@ -248,6 +262,8 @@ const setupPrototype = (proto, win) => {
|
|
|
248
262
|
await import_core.FunctionUtils.execute({ script, context: el, args });
|
|
249
263
|
};
|
|
250
264
|
};
|
|
265
|
+
const SWC_ORIGINAL_CALLBACK = Symbol.for("simple-web-component:original-callback");
|
|
266
|
+
const userCallback = (fn) => typeof fn === "function" && SWC_ORIGINAL_CALLBACK in fn ? fn[SWC_ORIGINAL_CALLBACK] : fn;
|
|
251
267
|
const elementDefine = (name, config = {}) => (constructor) => {
|
|
252
268
|
const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
|
|
253
269
|
const metadata = { ...config, name, window: win };
|
|
@@ -274,30 +290,60 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
274
290
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
275
291
|
const proto = constructor.prototype;
|
|
276
292
|
setupPrototype(proto, win);
|
|
277
|
-
|
|
293
|
+
const connectedHelperHostSet = (inst) => inst.__swc_helperHostSet ?? import_Utils.SwcUtils.getHelperAndHostSet(inst);
|
|
278
294
|
const eventCycler = new import_addEventListener.EventListenerLifeCycler();
|
|
295
|
+
const resizeCycler = new import_resizeObserver.ResizeObserverLifeCycler();
|
|
296
|
+
const intersectionCycler = new import_intersectionObserver.IntersectionObserverLifeCycler();
|
|
297
|
+
const mutationCycler = new import_mutationObserver.MutationObserverLifeCycler();
|
|
279
298
|
const cyclers = [
|
|
280
299
|
eventCycler,
|
|
281
300
|
new import_changedAttribute.ChangedAttributeLifeCycler(),
|
|
282
301
|
new import_emitCustomEvent.EmitCustomEventLifeCycler(),
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
new
|
|
287
|
-
new
|
|
302
|
+
resizeCycler,
|
|
303
|
+
intersectionCycler,
|
|
304
|
+
mutationCycler,
|
|
305
|
+
new import_subscribeSwcAppMessage.MessageSubscribeLifeCycler(),
|
|
306
|
+
new import_subscribeSwcAppRouteChange.RouteSubscribeLifeCycler(),
|
|
288
307
|
new import_setInterval.SetIntervalLifeCycler(),
|
|
289
308
|
new import_setTimeout.SetTimeoutLifeCycler(),
|
|
290
309
|
new import_requestAnimationFrame.RequestAnimationFrameLifeCycler(),
|
|
291
|
-
new import_eventMedia.EventMediaLifeCycler()
|
|
310
|
+
new import_eventMedia.EventMediaLifeCycler(),
|
|
311
|
+
new import_fetch.FetchLifeCycler()
|
|
292
312
|
];
|
|
293
313
|
const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
|
|
294
314
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
315
|
+
const newObserverState = () => ({
|
|
316
|
+
observers: [],
|
|
317
|
+
roCallbacks: /* @__PURE__ */ new Set(),
|
|
318
|
+
roObserved: /* @__PURE__ */ new WeakSet(),
|
|
319
|
+
resizeDelegates: [],
|
|
320
|
+
intersectionDelegates: [],
|
|
321
|
+
moCallbacks: /* @__PURE__ */ new Set(),
|
|
322
|
+
moTargets: /* @__PURE__ */ new Map()
|
|
323
|
+
});
|
|
324
|
+
const mergeMutationInit = (existing, next) => {
|
|
325
|
+
if (!existing) return next;
|
|
326
|
+
const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
|
|
327
|
+
return {
|
|
328
|
+
childList: existing.childList || next.childList,
|
|
329
|
+
attributes: existing.attributes || next.attributes,
|
|
330
|
+
characterData: existing.characterData || next.characterData,
|
|
331
|
+
subtree: existing.subtree || next.subtree,
|
|
332
|
+
attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
|
|
333
|
+
characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
|
|
334
|
+
attributeFilter: mergedFilter
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
const forDelegateMatches = (n, selector, fn) => {
|
|
338
|
+
if (n.nodeType !== 1) return;
|
|
339
|
+
const el = n;
|
|
340
|
+
const isThis = selector === "$this" || selector === "";
|
|
341
|
+
if (isThis || el.matches?.(selector) || el.closest?.(selector)) fn(el);
|
|
342
|
+
else el.querySelectorAll(selector).forEach(fn);
|
|
343
|
+
};
|
|
344
|
+
const buildObservers = async (helperHostSet, scope, st, alive) => {
|
|
345
|
+
const inst = helperHostSet.$this;
|
|
346
|
+
const activeCyclers = scope === "self" ? [resizeCycler, mutationCycler] : cyclers;
|
|
301
347
|
const resolveDelegateRoots = (delegateRoot) => {
|
|
302
348
|
const r = delegateRoot || "auto";
|
|
303
349
|
const roots = [];
|
|
@@ -310,202 +356,139 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
310
356
|
}
|
|
311
357
|
return roots;
|
|
312
358
|
};
|
|
313
|
-
|
|
314
|
-
|
|
359
|
+
let resizeObserverSet = [];
|
|
360
|
+
let mutationObserverSet = [];
|
|
361
|
+
let intersectionObserverSet = [];
|
|
362
|
+
for (const c of activeCyclers) {
|
|
363
|
+
const result = await c.onConnected?.(helperHostSet, resizeObserverSet, scope);
|
|
364
|
+
if (!alive()) return;
|
|
315
365
|
if (!result) continue;
|
|
316
366
|
if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
|
|
317
367
|
if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
|
|
318
368
|
if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
|
|
319
369
|
}
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
370
|
+
const resizeObserve = (el, opts) => {
|
|
371
|
+
if (!st.ro || st.roObserved.has(el)) return;
|
|
372
|
+
st.ro.observe(el, opts);
|
|
373
|
+
st.roObserved.add(el);
|
|
374
|
+
};
|
|
375
|
+
const resizeUnobserve = (el) => {
|
|
376
|
+
if (!st.ro || !st.roObserved.has(el)) return;
|
|
377
|
+
st.ro.unobserve(el);
|
|
378
|
+
st.roObserved.delete(el);
|
|
379
|
+
};
|
|
380
|
+
const newResizeDelegates = [];
|
|
381
|
+
if (resizeObserverSet.length) {
|
|
382
|
+
if (!st.ro) {
|
|
383
|
+
st.ro = new win.ResizeObserver((entries, obs) => {
|
|
384
|
+
for (const cb of st.roCallbacks) cb(entries, obs);
|
|
385
|
+
});
|
|
386
|
+
st.observers.push(st.ro);
|
|
387
|
+
}
|
|
329
388
|
for (const e of resizeObserverSet) {
|
|
330
|
-
|
|
389
|
+
st.roCallbacks.add(e.callback);
|
|
390
|
+
if (e.delegate) {
|
|
391
|
+
if (typeof e.target === "string") newResizeDelegates.push(e);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
331
394
|
if (typeof e.target === "string") {
|
|
332
|
-
const
|
|
333
|
-
for (const sr of scope) {
|
|
334
|
-
sr.querySelectorAll(e.target).forEach((el) => {
|
|
335
|
-
if (!resizeObserved.has(el)) {
|
|
336
|
-
ro.observe(el, e.options);
|
|
337
|
-
resizeObserved.add(el);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
395
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => resizeObserve(el, e.options));
|
|
341
396
|
continue;
|
|
342
397
|
}
|
|
343
|
-
ro.observe(e.target, e.options);
|
|
344
|
-
if (e.target instanceof Element)
|
|
398
|
+
st.ro.observe(e.target, e.options);
|
|
399
|
+
if (e.target instanceof Element) st.roObserved.add(e.target);
|
|
345
400
|
}
|
|
346
|
-
|
|
347
|
-
if (resizeObserved.has(el)) return;
|
|
348
|
-
ro.observe(el, opts);
|
|
349
|
-
resizeObserved.add(el);
|
|
350
|
-
};
|
|
351
|
-
resizeUnobserve = (el) => {
|
|
352
|
-
if (!resizeObserved.has(el)) return;
|
|
353
|
-
ro.unobserve(el);
|
|
354
|
-
resizeObserved.delete(el);
|
|
355
|
-
};
|
|
356
|
-
observers.push(ro);
|
|
401
|
+
st.resizeDelegates.push(...newResizeDelegates);
|
|
357
402
|
}
|
|
358
|
-
const
|
|
403
|
+
const newIntersectionDelegates = [];
|
|
359
404
|
for (const group of intersectionObserverSet) {
|
|
360
405
|
const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
|
|
361
406
|
const io = new win.IntersectionObserver((entries, obs) => {
|
|
362
407
|
for (const cb of ioCallbacks) cb(entries, obs);
|
|
363
408
|
}, group.options);
|
|
364
409
|
const ioObserved = /* @__PURE__ */ new WeakSet();
|
|
410
|
+
const observe = (el) => {
|
|
411
|
+
if (ioObserved.has(el)) return;
|
|
412
|
+
io.observe(el);
|
|
413
|
+
ioObserved.add(el);
|
|
414
|
+
};
|
|
415
|
+
const unobserve = (el) => {
|
|
416
|
+
if (!ioObserved.has(el)) return;
|
|
417
|
+
io.unobserve(el);
|
|
418
|
+
ioObserved.delete(el);
|
|
419
|
+
};
|
|
365
420
|
for (const e of group.observeTargets) {
|
|
366
421
|
if (e.delegate) {
|
|
367
|
-
|
|
368
|
-
const observe = (el) => {
|
|
369
|
-
if (ioObserved.has(el)) return;
|
|
370
|
-
io.observe(el);
|
|
371
|
-
ioObserved.add(el);
|
|
372
|
-
};
|
|
373
|
-
const unobserve = (el) => {
|
|
374
|
-
if (!ioObserved.has(el)) return;
|
|
375
|
-
io.unobserve(el);
|
|
376
|
-
ioObserved.delete(el);
|
|
377
|
-
};
|
|
378
|
-
intersectionDelegates.push({ target, delegateRoot: e.delegateRoot, observe, unobserve });
|
|
422
|
+
newIntersectionDelegates.push({ target: e.target, delegateRoot: e.delegateRoot, observe, unobserve });
|
|
379
423
|
continue;
|
|
380
424
|
}
|
|
381
425
|
if (typeof e.target === "string") {
|
|
382
|
-
const
|
|
383
|
-
for (const sr of scope) {
|
|
384
|
-
sr.querySelectorAll(e.target).forEach((el) => {
|
|
385
|
-
if (!ioObserved.has(el)) {
|
|
386
|
-
io.observe(el);
|
|
387
|
-
ioObserved.add(el);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
}
|
|
426
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach(observe);
|
|
391
427
|
continue;
|
|
392
428
|
}
|
|
393
|
-
|
|
394
|
-
if (e.target instanceof Element) ioObserved.add(e.target);
|
|
429
|
+
observe(e.target);
|
|
395
430
|
}
|
|
396
|
-
observers.push(io);
|
|
431
|
+
st.observers.push(io);
|
|
397
432
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
const handleIntersectionDelegate = (n, observe) => {
|
|
418
|
-
if (n.nodeType !== 1) return;
|
|
419
|
-
const el = n;
|
|
420
|
-
for (const d of intersectionDelegates) {
|
|
421
|
-
const isThis = d.target === "$this" || d.target === "";
|
|
422
|
-
const matchesSel = (node) => {
|
|
423
|
-
if (!node || node.nodeType !== 1) return false;
|
|
424
|
-
if (isThis) return true;
|
|
425
|
-
return node.matches?.(d.target) || !!node.closest?.(d.target);
|
|
426
|
-
};
|
|
427
|
-
if (matchesSel(el)) {
|
|
428
|
-
observe ? d.observe(el) : d.unobserve(el);
|
|
429
|
-
} else if (!isThis) {
|
|
430
|
-
el.querySelectorAll(d.target).forEach((sub) => {
|
|
431
|
-
observe ? d.observe(sub) : d.unobserve(sub);
|
|
432
|
-
});
|
|
433
|
-
}
|
|
433
|
+
st.intersectionDelegates.push(...newIntersectionDelegates);
|
|
434
|
+
if (mutationObserverSet.length || newResizeDelegates.length || newIntersectionDelegates.length) {
|
|
435
|
+
if (!st.mo) {
|
|
436
|
+
st.mo = new win.MutationObserver((mutations, obs) => {
|
|
437
|
+
for (const mut of mutations) {
|
|
438
|
+
for (const [nodes, on] of [[mut.addedNodes, true], [mut.removedNodes, false]]) {
|
|
439
|
+
for (const n of Array.from(nodes)) {
|
|
440
|
+
for (const d of st.resizeDelegates) forDelegateMatches(n, d.target, (el) => on ? resizeObserve(el, d.options) : resizeUnobserve(el));
|
|
441
|
+
for (const d of st.intersectionDelegates) forDelegateMatches(n, d.target, (el) => on ? d.observe(el) : d.unobserve(el));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
for (const cb of st.moCallbacks) cb(mutations, obs);
|
|
446
|
+
});
|
|
447
|
+
st.observers.push(st.mo);
|
|
434
448
|
}
|
|
435
|
-
};
|
|
436
|
-
if (mutationObserverSet?.length || resizeDelegates.length > 0 || intersectionDelegates.length > 0) {
|
|
437
|
-
const callbacks = [...new Set((mutationObserverSet ?? []).map((e) => e.callback))];
|
|
438
|
-
const mo = new win.MutationObserver((mutations, obs) => {
|
|
439
|
-
for (const mut of mutations) {
|
|
440
|
-
Array.from(mut.addedNodes || []).forEach((n) => {
|
|
441
|
-
handleResizeDelegate(n, true);
|
|
442
|
-
handleIntersectionDelegate(n, true);
|
|
443
|
-
});
|
|
444
|
-
Array.from(mut.removedNodes || []).forEach((n) => {
|
|
445
|
-
handleResizeDelegate(n, false);
|
|
446
|
-
handleIntersectionDelegate(n, false);
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
for (const cb of callbacks) cb(mutations, obs);
|
|
450
|
-
});
|
|
451
|
-
const moObserveTargets = /* @__PURE__ */ new Map();
|
|
452
|
-
const mergeMutationInit = (existing, next) => {
|
|
453
|
-
if (!existing) return next;
|
|
454
|
-
const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
|
|
455
|
-
return {
|
|
456
|
-
childList: existing.childList || next.childList,
|
|
457
|
-
attributes: existing.attributes || next.attributes,
|
|
458
|
-
characterData: existing.characterData || next.characterData,
|
|
459
|
-
subtree: existing.subtree || next.subtree,
|
|
460
|
-
attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
|
|
461
|
-
characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
|
|
462
|
-
attributeFilter: mergedFilter
|
|
463
|
-
};
|
|
464
|
-
};
|
|
465
449
|
const addObserveTarget = (target, options) => {
|
|
466
|
-
|
|
450
|
+
st.moTargets.set(target, mergeMutationInit(st.moTargets.get(target), options));
|
|
467
451
|
};
|
|
468
|
-
for (const e of mutationObserverSet
|
|
452
|
+
for (const e of mutationObserverSet) {
|
|
453
|
+
st.moCallbacks.add(e.callback);
|
|
469
454
|
if (e.delegate) continue;
|
|
470
455
|
const init = e.options ?? { childList: true };
|
|
471
456
|
if (typeof e.target === "string") {
|
|
472
|
-
const
|
|
473
|
-
for (const sr of scope) {
|
|
474
|
-
sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
475
|
-
}
|
|
457
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
476
458
|
continue;
|
|
477
459
|
}
|
|
478
460
|
addObserveTarget(e.target, init);
|
|
479
461
|
}
|
|
480
|
-
for (const d of
|
|
462
|
+
for (const d of [...newResizeDelegates, ...newIntersectionDelegates]) {
|
|
481
463
|
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
482
464
|
}
|
|
483
|
-
for (const
|
|
484
|
-
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
485
|
-
}
|
|
486
|
-
for (const [target, options] of moObserveTargets) {
|
|
487
|
-
mo.observe(target, options);
|
|
488
|
-
}
|
|
489
|
-
observers.push(mo);
|
|
465
|
+
for (const [target, options] of st.moTargets) st.mo.observe(target, options);
|
|
490
466
|
}
|
|
491
|
-
inst.__swc_observers = observers;
|
|
467
|
+
inst.__swc_observers = st.observers;
|
|
492
468
|
};
|
|
493
|
-
const originalConnected = proto.connectedCallback;
|
|
469
|
+
const originalConnected = userCallback(proto.connectedCallback);
|
|
494
470
|
proto.connectedCallback = async function() {
|
|
495
471
|
ensureInit(this);
|
|
496
|
-
helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
472
|
+
const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(this);
|
|
473
|
+
this.__swc_helperHostSet = helperHostSet;
|
|
497
474
|
const appHost = helperHostSet.$appHost;
|
|
498
475
|
const useSsr = (0, import_SwcAppMixin.isSSR)(this);
|
|
476
|
+
const gen = this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
|
|
477
|
+
const alive = () => this.__swc_connectGen === gen;
|
|
478
|
+
const obsState = newObserverState();
|
|
499
479
|
try {
|
|
500
480
|
if (appHost && typeof appHost._connected === "function") {
|
|
501
481
|
await appHost._connected(this);
|
|
482
|
+
if (!alive()) return;
|
|
502
483
|
} else if (appHost && typeof appHost) {
|
|
503
484
|
appHost._connected_safari_and_standby ?? (appHost._connected_safari_and_standby = []);
|
|
504
485
|
appHost._connected_safari_and_standby.push(this);
|
|
505
486
|
}
|
|
506
487
|
const conf = getElementConfig(this);
|
|
507
|
-
const
|
|
508
|
-
|
|
488
|
+
for (const m of (0, import_lifecycles.findAllOnConnectedBeforeMetadata)(this)) {
|
|
489
|
+
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
490
|
+
if (!alive()) return;
|
|
491
|
+
}
|
|
509
492
|
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
510
493
|
const targetConnectedList = useSsr ? [] : (0, import_lifecycles.findAllOnConnectedMetadata)(constructor);
|
|
511
494
|
const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
@@ -513,6 +496,8 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
513
496
|
const mode = shadowMode === true ? "open" : shadowMode;
|
|
514
497
|
this.attachShadow({ mode });
|
|
515
498
|
}
|
|
499
|
+
await buildObservers(helperHostSet, "self", obsState, alive);
|
|
500
|
+
if (!alive()) return;
|
|
516
501
|
const stateContext = { ...helperHostSet };
|
|
517
502
|
(0, import_state.findAllStateMetadata)(this).forEach((it) => {
|
|
518
503
|
stateContext[it.name] = this[it.propertyKey];
|
|
@@ -520,8 +505,39 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
520
505
|
const shadowChildren = [];
|
|
521
506
|
const lightChildren = [];
|
|
522
507
|
if (targetConnectedList.length > 0) {
|
|
508
|
+
const toNodes = (value) => {
|
|
509
|
+
if (!value) return [];
|
|
510
|
+
if (typeof value === "string") {
|
|
511
|
+
const htmlTemplateElement = doc.createElement("template");
|
|
512
|
+
htmlTemplateElement.innerHTML = value;
|
|
513
|
+
return Array.from(htmlTemplateElement.content.childNodes);
|
|
514
|
+
}
|
|
515
|
+
if (Array.isArray(value)) return value;
|
|
516
|
+
return [value];
|
|
517
|
+
};
|
|
518
|
+
const shownFallbacks = [];
|
|
519
|
+
const removeFallbacks = () => shownFallbacks.splice(0).forEach((n) => n.remove());
|
|
523
520
|
for (const meta of targetConnectedList) {
|
|
521
|
+
const useShadowRoot = meta.options.useShadow || conf?.useShadow;
|
|
522
|
+
if (meta.options.fallback) {
|
|
523
|
+
const fb = typeof meta.options.fallback === "function" ? meta.options.fallback(helperHostSet) : meta.options.fallback;
|
|
524
|
+
const fallbackNodes = toNodes(fb);
|
|
525
|
+
const parent = useShadowRoot ? this.shadowRoot : this;
|
|
526
|
+
if (fallbackNodes.length && parent) {
|
|
527
|
+
try {
|
|
528
|
+
const processed = import_Utils.SwcUtils.projectProcessHtml(this._swcId, fallbackNodes, doc);
|
|
529
|
+
parent.append(...processed);
|
|
530
|
+
shownFallbacks.push(...processed);
|
|
531
|
+
} catch (e) {
|
|
532
|
+
console.error("[ElementDefine] fallback setting error:", e);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
524
536
|
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
537
|
+
if (!alive()) {
|
|
538
|
+
removeFallbacks();
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
525
541
|
if (typeof res === "string") {
|
|
526
542
|
const htmlTemplateElement = doc.createElement("template");
|
|
527
543
|
htmlTemplateElement.innerHTML = res;
|
|
@@ -536,6 +552,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
536
552
|
}
|
|
537
553
|
}
|
|
538
554
|
}
|
|
555
|
+
removeFallbacks();
|
|
539
556
|
try {
|
|
540
557
|
if (this.shadowRoot) {
|
|
541
558
|
const applyShadowChildren = import_Utils.SwcUtils.projectProcessHtml(this._swcId, shadowChildren, doc);
|
|
@@ -559,22 +576,30 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
559
576
|
});
|
|
560
577
|
globalDelegatedRoots.add(root);
|
|
561
578
|
}
|
|
562
|
-
await buildObservers(
|
|
579
|
+
await buildObservers(helperHostSet, "rest", obsState, alive);
|
|
580
|
+
if (!alive()) return;
|
|
563
581
|
if (originalConnected) await originalConnected.apply(this);
|
|
564
|
-
|
|
582
|
+
if (!alive()) return;
|
|
583
|
+
for (const m of (0, import_lifecycles.findAllOnConnectedAfterMetadata)(this)) {
|
|
584
|
+
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
585
|
+
if (!alive()) return;
|
|
586
|
+
}
|
|
565
587
|
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
566
588
|
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
567
589
|
this.__swc_connected = true;
|
|
568
590
|
} finally {
|
|
569
|
-
|
|
591
|
+
const aborted = !alive();
|
|
592
|
+
if (!aborted) for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
570
593
|
if (appHost && typeof appHost._connectedDone === "function") {
|
|
571
|
-
await appHost._connectedDone(this);
|
|
594
|
+
await appHost._connectedDone(this, { aborted });
|
|
572
595
|
}
|
|
573
596
|
}
|
|
574
597
|
};
|
|
575
|
-
const originalDisconnected = proto.disconnectedCallback;
|
|
598
|
+
const originalDisconnected = userCallback(proto.disconnectedCallback);
|
|
576
599
|
proto.disconnectedCallback = function() {
|
|
577
|
-
|
|
600
|
+
this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
|
|
601
|
+
const helperHostSet = connectedHelperHostSet(this);
|
|
602
|
+
const appHost = helperHostSet.$appHost;
|
|
578
603
|
if (appHost && typeof appHost._disconnected === "function") {
|
|
579
604
|
appHost._disconnected(this);
|
|
580
605
|
}
|
|
@@ -596,28 +621,28 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
596
621
|
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
597
622
|
this.__swc_connected = false;
|
|
598
623
|
};
|
|
599
|
-
const originalAdopted = proto.adoptedCallback;
|
|
624
|
+
const originalAdopted = userCallback(proto.adoptedCallback);
|
|
600
625
|
proto.adoptedCallback = function() {
|
|
601
626
|
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
602
627
|
this._executeSwcScript("swc-on-before-adopted", hostSet);
|
|
603
628
|
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
604
|
-
for (const c of cyclers) c.onAdopted?.(
|
|
629
|
+
for (const c of cyclers) c.onAdopted?.(connectedHelperHostSet(this));
|
|
605
630
|
if (originalAdopted) originalAdopted.apply(this);
|
|
606
631
|
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
607
632
|
this._executeSwcScript("swc-on-adopted", hostSet);
|
|
608
633
|
this._executeSwcScript("swc-on-after-adopted", hostSet);
|
|
609
634
|
};
|
|
610
|
-
const originalAttributeChanged = proto.attributeChangedCallback;
|
|
635
|
+
const originalAttributeChanged = userCallback(proto.attributeChangedCallback);
|
|
611
636
|
proto.attributeChangedCallback = function(name2, old, newVal) {
|
|
612
637
|
if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
|
|
613
|
-
const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
638
|
+
const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(this);
|
|
614
639
|
let processedVal = newVal;
|
|
615
640
|
if (newVal !== null) {
|
|
616
641
|
const ae = new import_core.ActionExpression(newVal);
|
|
617
642
|
const expr = ae.getFirstExpression("callReturn");
|
|
618
643
|
if (expr) {
|
|
619
|
-
const win2 =
|
|
620
|
-
const exprHelperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
644
|
+
const win2 = import_Utils.SwcUtils.resolveWindow(this);
|
|
645
|
+
const exprHelperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(this);
|
|
621
646
|
const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
622
647
|
try {
|
|
623
648
|
const result = import_core.FunctionUtils.executeReturn({
|
|
@@ -644,6 +669,10 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
644
669
|
get: () => mergedObservedAttributes,
|
|
645
670
|
configurable: true
|
|
646
671
|
});
|
|
672
|
+
proto.connectedCallback[SWC_ORIGINAL_CALLBACK] = originalConnected;
|
|
673
|
+
proto.disconnectedCallback[SWC_ORIGINAL_CALLBACK] = originalDisconnected;
|
|
674
|
+
proto.adoptedCallback[SWC_ORIGINAL_CALLBACK] = originalAdopted;
|
|
675
|
+
proto.attributeChangedCallback[SWC_ORIGINAL_CALLBACK] = originalAttributeChanged;
|
|
647
676
|
import_core.ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, metadata, constructor);
|
|
648
677
|
const registry = metadata.customElementRegistry || win?.customElements;
|
|
649
678
|
if (registry && !registry.get(metadata.name)) {
|