@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
|
@@ -16,16 +16,18 @@ import { InjectSituationType } from "../types/index.js";
|
|
|
16
16
|
import { ConvertUtils, ElementApply } from "@dooboostore/core-web";
|
|
17
17
|
import { isSSR } from "../elements/SwcAppMixin.js";
|
|
18
18
|
import { findAllStateMetadata } from "./state.js";
|
|
19
|
+
import { findAllAroundMetadata } from "./around.js";
|
|
19
20
|
import { findAllPropertyMetadata } from "./applyProperty.js";
|
|
20
|
-
import { MessageSubscribeLifeCycler } from "./
|
|
21
|
-
import { RouteSubscribeLifeCycler } from "./
|
|
21
|
+
import { MessageSubscribeLifeCycler } from "./subscribeSwcAppMessage.js";
|
|
22
|
+
import { RouteSubscribeLifeCycler } from "./subscribeSwcAppRouteChange.js";
|
|
22
23
|
import { SetIntervalLifeCycler } from "./setInterval.js";
|
|
23
24
|
import { SetTimeoutLifeCycler } from "./setTimeout.js";
|
|
24
25
|
import { RequestAnimationFrameLifeCycler } from "./requestAnimationFrame.js";
|
|
25
26
|
import { EventMediaLifeCycler } from "./eventMedia.js";
|
|
27
|
+
import { FetchLifeCycler } from "./fetch.js";
|
|
26
28
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
27
29
|
const getElementConfig = (target) => {
|
|
28
|
-
const constructor = target
|
|
30
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
29
31
|
return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
|
|
30
32
|
};
|
|
31
33
|
const ensureInit = (inst) => {
|
|
@@ -33,7 +35,7 @@ const ensureInit = (inst) => {
|
|
|
33
35
|
inst._swcId = inst?.getAttribute?.("swc-use-ssr") ?? "s" + Math.random().toString(36).substring(2, 11).toLowerCase();
|
|
34
36
|
inst._emitHandlers = /* @__PURE__ */ new Map();
|
|
35
37
|
inst.__swc_initialized = true;
|
|
36
|
-
const target = inst
|
|
38
|
+
const target = typeof inst === "function" ? inst : inst.constructor;
|
|
37
39
|
const attributeAllList = findAllAttributeMetadata(target).filter((it) => it.type === "property");
|
|
38
40
|
if (attributeAllList) {
|
|
39
41
|
attributeAllList.forEach((meta) => {
|
|
@@ -55,15 +57,40 @@ const ensureInit = (inst) => {
|
|
|
55
57
|
const propertyAllList = findAllPropertyMetadata(target).filter((it) => it.type === "property");
|
|
56
58
|
if (propertyAllList) {
|
|
57
59
|
propertyAllList.forEach((meta) => {
|
|
60
|
+
let proto = Object.getPrototypeOf(inst);
|
|
61
|
+
let hasGetter = false;
|
|
62
|
+
while (proto && proto !== Object.prototype) {
|
|
63
|
+
const d = Object.getOwnPropertyDescriptor(proto, meta.propertyKey);
|
|
64
|
+
if (d) {
|
|
65
|
+
hasGetter = typeof d.get === "function";
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
proto = Object.getPrototypeOf(proto);
|
|
69
|
+
}
|
|
70
|
+
if (!hasGetter) return;
|
|
58
71
|
delete inst[meta.propertyKey];
|
|
59
72
|
});
|
|
60
73
|
}
|
|
61
74
|
const stateAllList = findAllStateMetadata(target);
|
|
62
75
|
if (stateAllList) {
|
|
63
76
|
stateAllList.forEach((meta) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
|
|
78
|
+
if (own && "value" in own) {
|
|
79
|
+
const initUserData = own.value;
|
|
80
|
+
delete inst[meta.propertyKey];
|
|
81
|
+
inst[meta.propertyKey] = initUserData;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const aroundAllList = findAllAroundMetadata(target);
|
|
86
|
+
if (aroundAllList) {
|
|
87
|
+
aroundAllList.forEach((meta) => {
|
|
88
|
+
const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
|
|
89
|
+
if (own && "value" in own) {
|
|
90
|
+
const initUserData = own.value;
|
|
91
|
+
delete inst[meta.propertyKey];
|
|
92
|
+
inst[meta.propertyKey] = initUserData;
|
|
93
|
+
}
|
|
67
94
|
});
|
|
68
95
|
}
|
|
69
96
|
const hostSet = SwcUtils.getHostSet(inst);
|
|
@@ -83,7 +110,7 @@ const handleGlobalSwcEvent = async (event) => {
|
|
|
83
110
|
if (!(node instanceof HTMLElement)) continue;
|
|
84
111
|
const script = node.getAttribute?.(attrName);
|
|
85
112
|
if (script && !getElementConfig(node)) {
|
|
86
|
-
const host = SwcUtils.
|
|
113
|
+
const host = SwcUtils.findNearestSwcAncestorHost(node);
|
|
87
114
|
if (host && host.isConnected && typeof host.__swc_executeAttributeEvent === "function") {
|
|
88
115
|
await host.__swc_executeAttributeEvent(node, attrName, script, event);
|
|
89
116
|
event.__swc_handled = true;
|
|
@@ -114,8 +141,7 @@ const setupPrototype = (proto, win) => {
|
|
|
114
141
|
const script = this.getAttribute(attrName);
|
|
115
142
|
if (script) {
|
|
116
143
|
try {
|
|
117
|
-
const
|
|
118
|
-
const currentWin = this._resolveWindow(conf);
|
|
144
|
+
const currentWin = SwcUtils.resolveWindow(this);
|
|
119
145
|
const helpers = SwcUtils.getHelperSet(currentWin);
|
|
120
146
|
const args = { ...hostSet, ...helpers, ...extraArgs, $el: this, $root: this.getRootNode() };
|
|
121
147
|
FunctionUtils.execute({ script, context: this, args });
|
|
@@ -124,20 +150,10 @@ const setupPrototype = (proto, win) => {
|
|
|
124
150
|
}
|
|
125
151
|
}
|
|
126
152
|
};
|
|
127
|
-
proto._resolveWindow = function(localConfig) {
|
|
128
|
-
ensureInit(this);
|
|
129
|
-
if (localConfig?.window) return localConfig.window;
|
|
130
|
-
const ancestors = SwcUtils.findAllSwcHostsIncludingSelf(this);
|
|
131
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
132
|
-
const aConf = getElementConfig(ancestors[i]);
|
|
133
|
-
if (aConf?.window) return aConf.window;
|
|
134
|
-
}
|
|
135
|
-
return getElementConfig(this).window ?? (typeof window !== "undefined" ? window : void 0);
|
|
136
|
-
};
|
|
137
153
|
proto._invokeLifecycleMethod = function(methodName, hostSet, extraArgs = []) {
|
|
138
154
|
ensureInit(this);
|
|
139
155
|
if (typeof this[methodName] !== "function") return;
|
|
140
|
-
const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(
|
|
156
|
+
const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(this);
|
|
141
157
|
const app = useHostSet?.$appHost?.simpleApplication;
|
|
142
158
|
const helperSetValue = SwcUtils.getHelperSet(win);
|
|
143
159
|
const helperHostSetValue = { ...helperSetValue, ...useHostSet, $this: this };
|
|
@@ -155,7 +171,7 @@ const setupPrototype = (proto, win) => {
|
|
|
155
171
|
const firstCheckMaker = ({ target, targetKey }, token, idx) => {
|
|
156
172
|
const saves = getParameterMetadata(target, targetKey);
|
|
157
173
|
const found = saves.find((s) => s.index === idx);
|
|
158
|
-
return found ? kindValues[found.kind] : void 0;
|
|
174
|
+
return found ? kindValues[found.kind] ?? null : void 0;
|
|
159
175
|
};
|
|
160
176
|
return app.simstanceManager.executeBindParameterSim(
|
|
161
177
|
{
|
|
@@ -187,8 +203,7 @@ const setupPrototype = (proto, win) => {
|
|
|
187
203
|
if (oldHandler) el.removeEventListener(eventName, oldHandler);
|
|
188
204
|
const handler = async (event) => {
|
|
189
205
|
const hostSet = SwcUtils.getHostSet(el);
|
|
190
|
-
const
|
|
191
|
-
const currentWin = this._resolveWindow(conf);
|
|
206
|
+
const currentWin = SwcUtils.resolveWindow(this);
|
|
192
207
|
const helpers = SwcUtils.getHelperSet(currentWin);
|
|
193
208
|
const args = {
|
|
194
209
|
event,
|
|
@@ -206,8 +221,7 @@ const setupPrototype = (proto, win) => {
|
|
|
206
221
|
proto.__swc_executeAttributeEvent = async function(el, attrName, script, event) {
|
|
207
222
|
ensureInit(this);
|
|
208
223
|
const hostSet = SwcUtils.getHostSet(el);
|
|
209
|
-
const
|
|
210
|
-
const currentWin = this._resolveWindow(conf);
|
|
224
|
+
const currentWin = SwcUtils.resolveWindow(this);
|
|
211
225
|
const currentHelpers = SwcUtils.getHelperSet(currentWin);
|
|
212
226
|
const detail = event.detail;
|
|
213
227
|
const args = {
|
|
@@ -223,6 +237,8 @@ const setupPrototype = (proto, win) => {
|
|
|
223
237
|
await FunctionUtils.execute({ script, context: el, args });
|
|
224
238
|
};
|
|
225
239
|
};
|
|
240
|
+
const SWC_ORIGINAL_CALLBACK = Symbol.for("simple-web-component:original-callback");
|
|
241
|
+
const userCallback = (fn) => typeof fn === "function" && SWC_ORIGINAL_CALLBACK in fn ? fn[SWC_ORIGINAL_CALLBACK] : fn;
|
|
226
242
|
const elementDefine = (name, config = {}) => (constructor) => {
|
|
227
243
|
const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
|
|
228
244
|
const metadata = { ...config, name, window: win };
|
|
@@ -249,30 +265,60 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
249
265
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
250
266
|
const proto = constructor.prototype;
|
|
251
267
|
setupPrototype(proto, win);
|
|
252
|
-
|
|
268
|
+
const connectedHelperHostSet = (inst) => inst.__swc_helperHostSet ?? SwcUtils.getHelperAndHostSet(inst);
|
|
253
269
|
const eventCycler = new EventListenerLifeCycler();
|
|
270
|
+
const resizeCycler = new ResizeObserverLifeCycler();
|
|
271
|
+
const intersectionCycler = new IntersectionObserverLifeCycler();
|
|
272
|
+
const mutationCycler = new MutationObserverLifeCycler();
|
|
254
273
|
const cyclers = [
|
|
255
274
|
eventCycler,
|
|
256
275
|
new ChangedAttributeLifeCycler(),
|
|
257
276
|
new EmitCustomEventLifeCycler(),
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
277
|
+
resizeCycler,
|
|
278
|
+
intersectionCycler,
|
|
279
|
+
mutationCycler,
|
|
261
280
|
new MessageSubscribeLifeCycler(),
|
|
262
281
|
new RouteSubscribeLifeCycler(),
|
|
263
282
|
new SetIntervalLifeCycler(),
|
|
264
283
|
new SetTimeoutLifeCycler(),
|
|
265
284
|
new RequestAnimationFrameLifeCycler(),
|
|
266
|
-
new EventMediaLifeCycler()
|
|
285
|
+
new EventMediaLifeCycler(),
|
|
286
|
+
new FetchLifeCycler()
|
|
267
287
|
];
|
|
268
288
|
const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
|
|
269
289
|
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
290
|
+
const newObserverState = () => ({
|
|
291
|
+
observers: [],
|
|
292
|
+
roCallbacks: /* @__PURE__ */ new Set(),
|
|
293
|
+
roObserved: /* @__PURE__ */ new WeakSet(),
|
|
294
|
+
resizeDelegates: [],
|
|
295
|
+
intersectionDelegates: [],
|
|
296
|
+
moCallbacks: /* @__PURE__ */ new Set(),
|
|
297
|
+
moTargets: /* @__PURE__ */ new Map()
|
|
298
|
+
});
|
|
299
|
+
const mergeMutationInit = (existing, next) => {
|
|
300
|
+
if (!existing) return next;
|
|
301
|
+
const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
|
|
302
|
+
return {
|
|
303
|
+
childList: existing.childList || next.childList,
|
|
304
|
+
attributes: existing.attributes || next.attributes,
|
|
305
|
+
characterData: existing.characterData || next.characterData,
|
|
306
|
+
subtree: existing.subtree || next.subtree,
|
|
307
|
+
attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
|
|
308
|
+
characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
|
|
309
|
+
attributeFilter: mergedFilter
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
const forDelegateMatches = (n, selector, fn) => {
|
|
313
|
+
if (n.nodeType !== 1) return;
|
|
314
|
+
const el = n;
|
|
315
|
+
const isThis = selector === "$this" || selector === "";
|
|
316
|
+
if (isThis || el.matches?.(selector) || el.closest?.(selector)) fn(el);
|
|
317
|
+
else el.querySelectorAll(selector).forEach(fn);
|
|
318
|
+
};
|
|
319
|
+
const buildObservers = async (helperHostSet, scope, st, alive) => {
|
|
320
|
+
const inst = helperHostSet.$this;
|
|
321
|
+
const activeCyclers = scope === "self" ? [resizeCycler, mutationCycler] : cyclers;
|
|
276
322
|
const resolveDelegateRoots = (delegateRoot) => {
|
|
277
323
|
const r = delegateRoot || "auto";
|
|
278
324
|
const roots = [];
|
|
@@ -285,202 +331,139 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
285
331
|
}
|
|
286
332
|
return roots;
|
|
287
333
|
};
|
|
288
|
-
|
|
289
|
-
|
|
334
|
+
let resizeObserverSet = [];
|
|
335
|
+
let mutationObserverSet = [];
|
|
336
|
+
let intersectionObserverSet = [];
|
|
337
|
+
for (const c of activeCyclers) {
|
|
338
|
+
const result = await c.onConnected?.(helperHostSet, resizeObserverSet, scope);
|
|
339
|
+
if (!alive()) return;
|
|
290
340
|
if (!result) continue;
|
|
291
341
|
if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
|
|
292
342
|
if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
|
|
293
343
|
if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
|
|
294
344
|
}
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
345
|
+
const resizeObserve = (el, opts) => {
|
|
346
|
+
if (!st.ro || st.roObserved.has(el)) return;
|
|
347
|
+
st.ro.observe(el, opts);
|
|
348
|
+
st.roObserved.add(el);
|
|
349
|
+
};
|
|
350
|
+
const resizeUnobserve = (el) => {
|
|
351
|
+
if (!st.ro || !st.roObserved.has(el)) return;
|
|
352
|
+
st.ro.unobserve(el);
|
|
353
|
+
st.roObserved.delete(el);
|
|
354
|
+
};
|
|
355
|
+
const newResizeDelegates = [];
|
|
356
|
+
if (resizeObserverSet.length) {
|
|
357
|
+
if (!st.ro) {
|
|
358
|
+
st.ro = new win.ResizeObserver((entries, obs) => {
|
|
359
|
+
for (const cb of st.roCallbacks) cb(entries, obs);
|
|
360
|
+
});
|
|
361
|
+
st.observers.push(st.ro);
|
|
362
|
+
}
|
|
304
363
|
for (const e of resizeObserverSet) {
|
|
305
|
-
|
|
364
|
+
st.roCallbacks.add(e.callback);
|
|
365
|
+
if (e.delegate) {
|
|
366
|
+
if (typeof e.target === "string") newResizeDelegates.push(e);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
306
369
|
if (typeof e.target === "string") {
|
|
307
|
-
const
|
|
308
|
-
for (const sr of scope) {
|
|
309
|
-
sr.querySelectorAll(e.target).forEach((el) => {
|
|
310
|
-
if (!resizeObserved.has(el)) {
|
|
311
|
-
ro.observe(el, e.options);
|
|
312
|
-
resizeObserved.add(el);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
370
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => resizeObserve(el, e.options));
|
|
316
371
|
continue;
|
|
317
372
|
}
|
|
318
|
-
ro.observe(e.target, e.options);
|
|
319
|
-
if (e.target instanceof Element)
|
|
373
|
+
st.ro.observe(e.target, e.options);
|
|
374
|
+
if (e.target instanceof Element) st.roObserved.add(e.target);
|
|
320
375
|
}
|
|
321
|
-
|
|
322
|
-
if (resizeObserved.has(el)) return;
|
|
323
|
-
ro.observe(el, opts);
|
|
324
|
-
resizeObserved.add(el);
|
|
325
|
-
};
|
|
326
|
-
resizeUnobserve = (el) => {
|
|
327
|
-
if (!resizeObserved.has(el)) return;
|
|
328
|
-
ro.unobserve(el);
|
|
329
|
-
resizeObserved.delete(el);
|
|
330
|
-
};
|
|
331
|
-
observers.push(ro);
|
|
376
|
+
st.resizeDelegates.push(...newResizeDelegates);
|
|
332
377
|
}
|
|
333
|
-
const
|
|
378
|
+
const newIntersectionDelegates = [];
|
|
334
379
|
for (const group of intersectionObserverSet) {
|
|
335
380
|
const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
|
|
336
381
|
const io = new win.IntersectionObserver((entries, obs) => {
|
|
337
382
|
for (const cb of ioCallbacks) cb(entries, obs);
|
|
338
383
|
}, group.options);
|
|
339
384
|
const ioObserved = /* @__PURE__ */ new WeakSet();
|
|
385
|
+
const observe = (el) => {
|
|
386
|
+
if (ioObserved.has(el)) return;
|
|
387
|
+
io.observe(el);
|
|
388
|
+
ioObserved.add(el);
|
|
389
|
+
};
|
|
390
|
+
const unobserve = (el) => {
|
|
391
|
+
if (!ioObserved.has(el)) return;
|
|
392
|
+
io.unobserve(el);
|
|
393
|
+
ioObserved.delete(el);
|
|
394
|
+
};
|
|
340
395
|
for (const e of group.observeTargets) {
|
|
341
396
|
if (e.delegate) {
|
|
342
|
-
|
|
343
|
-
const observe = (el) => {
|
|
344
|
-
if (ioObserved.has(el)) return;
|
|
345
|
-
io.observe(el);
|
|
346
|
-
ioObserved.add(el);
|
|
347
|
-
};
|
|
348
|
-
const unobserve = (el) => {
|
|
349
|
-
if (!ioObserved.has(el)) return;
|
|
350
|
-
io.unobserve(el);
|
|
351
|
-
ioObserved.delete(el);
|
|
352
|
-
};
|
|
353
|
-
intersectionDelegates.push({ target, delegateRoot: e.delegateRoot, observe, unobserve });
|
|
397
|
+
newIntersectionDelegates.push({ target: e.target, delegateRoot: e.delegateRoot, observe, unobserve });
|
|
354
398
|
continue;
|
|
355
399
|
}
|
|
356
400
|
if (typeof e.target === "string") {
|
|
357
|
-
const
|
|
358
|
-
for (const sr of scope) {
|
|
359
|
-
sr.querySelectorAll(e.target).forEach((el) => {
|
|
360
|
-
if (!ioObserved.has(el)) {
|
|
361
|
-
io.observe(el);
|
|
362
|
-
ioObserved.add(el);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
401
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach(observe);
|
|
366
402
|
continue;
|
|
367
403
|
}
|
|
368
|
-
|
|
369
|
-
if (e.target instanceof Element) ioObserved.add(e.target);
|
|
404
|
+
observe(e.target);
|
|
370
405
|
}
|
|
371
|
-
observers.push(io);
|
|
406
|
+
st.observers.push(io);
|
|
372
407
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
const handleIntersectionDelegate = (n, observe) => {
|
|
393
|
-
if (n.nodeType !== 1) return;
|
|
394
|
-
const el = n;
|
|
395
|
-
for (const d of intersectionDelegates) {
|
|
396
|
-
const isThis = d.target === "$this" || d.target === "";
|
|
397
|
-
const matchesSel = (node) => {
|
|
398
|
-
if (!node || node.nodeType !== 1) return false;
|
|
399
|
-
if (isThis) return true;
|
|
400
|
-
return node.matches?.(d.target) || !!node.closest?.(d.target);
|
|
401
|
-
};
|
|
402
|
-
if (matchesSel(el)) {
|
|
403
|
-
observe ? d.observe(el) : d.unobserve(el);
|
|
404
|
-
} else if (!isThis) {
|
|
405
|
-
el.querySelectorAll(d.target).forEach((sub) => {
|
|
406
|
-
observe ? d.observe(sub) : d.unobserve(sub);
|
|
407
|
-
});
|
|
408
|
-
}
|
|
408
|
+
st.intersectionDelegates.push(...newIntersectionDelegates);
|
|
409
|
+
if (mutationObserverSet.length || newResizeDelegates.length || newIntersectionDelegates.length) {
|
|
410
|
+
if (!st.mo) {
|
|
411
|
+
st.mo = new win.MutationObserver((mutations, obs) => {
|
|
412
|
+
for (const mut of mutations) {
|
|
413
|
+
for (const [nodes, on] of [[mut.addedNodes, true], [mut.removedNodes, false]]) {
|
|
414
|
+
for (const n of Array.from(nodes)) {
|
|
415
|
+
for (const d of st.resizeDelegates) forDelegateMatches(n, d.target, (el) => on ? resizeObserve(el, d.options) : resizeUnobserve(el));
|
|
416
|
+
for (const d of st.intersectionDelegates) forDelegateMatches(n, d.target, (el) => on ? d.observe(el) : d.unobserve(el));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
for (const cb of st.moCallbacks) cb(mutations, obs);
|
|
421
|
+
});
|
|
422
|
+
st.observers.push(st.mo);
|
|
409
423
|
}
|
|
410
|
-
};
|
|
411
|
-
if (mutationObserverSet?.length || resizeDelegates.length > 0 || intersectionDelegates.length > 0) {
|
|
412
|
-
const callbacks = [...new Set((mutationObserverSet ?? []).map((e) => e.callback))];
|
|
413
|
-
const mo = new win.MutationObserver((mutations, obs) => {
|
|
414
|
-
for (const mut of mutations) {
|
|
415
|
-
Array.from(mut.addedNodes || []).forEach((n) => {
|
|
416
|
-
handleResizeDelegate(n, true);
|
|
417
|
-
handleIntersectionDelegate(n, true);
|
|
418
|
-
});
|
|
419
|
-
Array.from(mut.removedNodes || []).forEach((n) => {
|
|
420
|
-
handleResizeDelegate(n, false);
|
|
421
|
-
handleIntersectionDelegate(n, false);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
for (const cb of callbacks) cb(mutations, obs);
|
|
425
|
-
});
|
|
426
|
-
const moObserveTargets = /* @__PURE__ */ new Map();
|
|
427
|
-
const mergeMutationInit = (existing, next) => {
|
|
428
|
-
if (!existing) return next;
|
|
429
|
-
const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
|
|
430
|
-
return {
|
|
431
|
-
childList: existing.childList || next.childList,
|
|
432
|
-
attributes: existing.attributes || next.attributes,
|
|
433
|
-
characterData: existing.characterData || next.characterData,
|
|
434
|
-
subtree: existing.subtree || next.subtree,
|
|
435
|
-
attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
|
|
436
|
-
characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
|
|
437
|
-
attributeFilter: mergedFilter
|
|
438
|
-
};
|
|
439
|
-
};
|
|
440
424
|
const addObserveTarget = (target, options) => {
|
|
441
|
-
|
|
425
|
+
st.moTargets.set(target, mergeMutationInit(st.moTargets.get(target), options));
|
|
442
426
|
};
|
|
443
|
-
for (const e of mutationObserverSet
|
|
427
|
+
for (const e of mutationObserverSet) {
|
|
428
|
+
st.moCallbacks.add(e.callback);
|
|
444
429
|
if (e.delegate) continue;
|
|
445
430
|
const init = e.options ?? { childList: true };
|
|
446
431
|
if (typeof e.target === "string") {
|
|
447
|
-
const
|
|
448
|
-
for (const sr of scope) {
|
|
449
|
-
sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
450
|
-
}
|
|
432
|
+
for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
451
433
|
continue;
|
|
452
434
|
}
|
|
453
435
|
addObserveTarget(e.target, init);
|
|
454
436
|
}
|
|
455
|
-
for (const d of
|
|
437
|
+
for (const d of [...newResizeDelegates, ...newIntersectionDelegates]) {
|
|
456
438
|
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
457
439
|
}
|
|
458
|
-
for (const
|
|
459
|
-
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
460
|
-
}
|
|
461
|
-
for (const [target, options] of moObserveTargets) {
|
|
462
|
-
mo.observe(target, options);
|
|
463
|
-
}
|
|
464
|
-
observers.push(mo);
|
|
440
|
+
for (const [target, options] of st.moTargets) st.mo.observe(target, options);
|
|
465
441
|
}
|
|
466
|
-
inst.__swc_observers = observers;
|
|
442
|
+
inst.__swc_observers = st.observers;
|
|
467
443
|
};
|
|
468
|
-
const originalConnected = proto.connectedCallback;
|
|
444
|
+
const originalConnected = userCallback(proto.connectedCallback);
|
|
469
445
|
proto.connectedCallback = async function() {
|
|
470
446
|
ensureInit(this);
|
|
471
|
-
helperHostSet = SwcUtils.getHelperAndHostSet(
|
|
447
|
+
const helperHostSet = SwcUtils.getHelperAndHostSet(this);
|
|
448
|
+
this.__swc_helperHostSet = helperHostSet;
|
|
472
449
|
const appHost = helperHostSet.$appHost;
|
|
473
450
|
const useSsr = isSSR(this);
|
|
451
|
+
const gen = this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
|
|
452
|
+
const alive = () => this.__swc_connectGen === gen;
|
|
453
|
+
const obsState = newObserverState();
|
|
474
454
|
try {
|
|
475
455
|
if (appHost && typeof appHost._connected === "function") {
|
|
476
456
|
await appHost._connected(this);
|
|
457
|
+
if (!alive()) return;
|
|
477
458
|
} else if (appHost && typeof appHost) {
|
|
478
459
|
appHost._connected_safari_and_standby ?? (appHost._connected_safari_and_standby = []);
|
|
479
460
|
appHost._connected_safari_and_standby.push(this);
|
|
480
461
|
}
|
|
481
462
|
const conf = getElementConfig(this);
|
|
482
|
-
const
|
|
483
|
-
|
|
463
|
+
for (const m of findAllOnConnectedBeforeMetadata(this)) {
|
|
464
|
+
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
465
|
+
if (!alive()) return;
|
|
466
|
+
}
|
|
484
467
|
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
485
468
|
const targetConnectedList = useSsr ? [] : findAllOnConnectedMetadata(constructor);
|
|
486
469
|
const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
@@ -488,6 +471,8 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
488
471
|
const mode = shadowMode === true ? "open" : shadowMode;
|
|
489
472
|
this.attachShadow({ mode });
|
|
490
473
|
}
|
|
474
|
+
await buildObservers(helperHostSet, "self", obsState, alive);
|
|
475
|
+
if (!alive()) return;
|
|
491
476
|
const stateContext = { ...helperHostSet };
|
|
492
477
|
findAllStateMetadata(this).forEach((it) => {
|
|
493
478
|
stateContext[it.name] = this[it.propertyKey];
|
|
@@ -495,8 +480,39 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
495
480
|
const shadowChildren = [];
|
|
496
481
|
const lightChildren = [];
|
|
497
482
|
if (targetConnectedList.length > 0) {
|
|
483
|
+
const toNodes = (value) => {
|
|
484
|
+
if (!value) return [];
|
|
485
|
+
if (typeof value === "string") {
|
|
486
|
+
const htmlTemplateElement = doc.createElement("template");
|
|
487
|
+
htmlTemplateElement.innerHTML = value;
|
|
488
|
+
return Array.from(htmlTemplateElement.content.childNodes);
|
|
489
|
+
}
|
|
490
|
+
if (Array.isArray(value)) return value;
|
|
491
|
+
return [value];
|
|
492
|
+
};
|
|
493
|
+
const shownFallbacks = [];
|
|
494
|
+
const removeFallbacks = () => shownFallbacks.splice(0).forEach((n) => n.remove());
|
|
498
495
|
for (const meta of targetConnectedList) {
|
|
496
|
+
const useShadowRoot = meta.options.useShadow || conf?.useShadow;
|
|
497
|
+
if (meta.options.fallback) {
|
|
498
|
+
const fb = typeof meta.options.fallback === "function" ? meta.options.fallback(helperHostSet) : meta.options.fallback;
|
|
499
|
+
const fallbackNodes = toNodes(fb);
|
|
500
|
+
const parent = useShadowRoot ? this.shadowRoot : this;
|
|
501
|
+
if (fallbackNodes.length && parent) {
|
|
502
|
+
try {
|
|
503
|
+
const processed = SwcUtils.projectProcessHtml(this._swcId, fallbackNodes, doc);
|
|
504
|
+
parent.append(...processed);
|
|
505
|
+
shownFallbacks.push(...processed);
|
|
506
|
+
} catch (e) {
|
|
507
|
+
console.error("[ElementDefine] fallback setting error:", e);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
499
511
|
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
512
|
+
if (!alive()) {
|
|
513
|
+
removeFallbacks();
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
500
516
|
if (typeof res === "string") {
|
|
501
517
|
const htmlTemplateElement = doc.createElement("template");
|
|
502
518
|
htmlTemplateElement.innerHTML = res;
|
|
@@ -511,6 +527,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
511
527
|
}
|
|
512
528
|
}
|
|
513
529
|
}
|
|
530
|
+
removeFallbacks();
|
|
514
531
|
try {
|
|
515
532
|
if (this.shadowRoot) {
|
|
516
533
|
const applyShadowChildren = SwcUtils.projectProcessHtml(this._swcId, shadowChildren, doc);
|
|
@@ -534,22 +551,30 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
534
551
|
});
|
|
535
552
|
globalDelegatedRoots.add(root);
|
|
536
553
|
}
|
|
537
|
-
await buildObservers(
|
|
554
|
+
await buildObservers(helperHostSet, "rest", obsState, alive);
|
|
555
|
+
if (!alive()) return;
|
|
538
556
|
if (originalConnected) await originalConnected.apply(this);
|
|
539
|
-
|
|
557
|
+
if (!alive()) return;
|
|
558
|
+
for (const m of findAllOnConnectedAfterMetadata(this)) {
|
|
559
|
+
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
560
|
+
if (!alive()) return;
|
|
561
|
+
}
|
|
540
562
|
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
541
563
|
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
542
564
|
this.__swc_connected = true;
|
|
543
565
|
} finally {
|
|
544
|
-
|
|
566
|
+
const aborted = !alive();
|
|
567
|
+
if (!aborted) for (const m of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
545
568
|
if (appHost && typeof appHost._connectedDone === "function") {
|
|
546
|
-
await appHost._connectedDone(this);
|
|
569
|
+
await appHost._connectedDone(this, { aborted });
|
|
547
570
|
}
|
|
548
571
|
}
|
|
549
572
|
};
|
|
550
|
-
const originalDisconnected = proto.disconnectedCallback;
|
|
573
|
+
const originalDisconnected = userCallback(proto.disconnectedCallback);
|
|
551
574
|
proto.disconnectedCallback = function() {
|
|
552
|
-
|
|
575
|
+
this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
|
|
576
|
+
const helperHostSet = connectedHelperHostSet(this);
|
|
577
|
+
const appHost = helperHostSet.$appHost;
|
|
553
578
|
if (appHost && typeof appHost._disconnected === "function") {
|
|
554
579
|
appHost._disconnected(this);
|
|
555
580
|
}
|
|
@@ -571,28 +596,28 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
571
596
|
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
572
597
|
this.__swc_connected = false;
|
|
573
598
|
};
|
|
574
|
-
const originalAdopted = proto.adoptedCallback;
|
|
599
|
+
const originalAdopted = userCallback(proto.adoptedCallback);
|
|
575
600
|
proto.adoptedCallback = function() {
|
|
576
601
|
const hostSet = SwcUtils.getHostSet(this);
|
|
577
602
|
this._executeSwcScript("swc-on-before-adopted", hostSet);
|
|
578
603
|
for (const m of findAllLifecycleMetadata(this, ON_BEFORE_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
579
|
-
for (const c of cyclers) c.onAdopted?.(
|
|
604
|
+
for (const c of cyclers) c.onAdopted?.(connectedHelperHostSet(this));
|
|
580
605
|
if (originalAdopted) originalAdopted.apply(this);
|
|
581
606
|
for (const m of findAllLifecycleMetadata(this, ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
582
607
|
this._executeSwcScript("swc-on-adopted", hostSet);
|
|
583
608
|
this._executeSwcScript("swc-on-after-adopted", hostSet);
|
|
584
609
|
};
|
|
585
|
-
const originalAttributeChanged = proto.attributeChangedCallback;
|
|
610
|
+
const originalAttributeChanged = userCallback(proto.attributeChangedCallback);
|
|
586
611
|
proto.attributeChangedCallback = function(name2, old, newVal) {
|
|
587
612
|
if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
|
|
588
|
-
const helperAndHostSet = SwcUtils.getHelperAndHostSet(
|
|
613
|
+
const helperAndHostSet = SwcUtils.getHelperAndHostSet(this);
|
|
589
614
|
let processedVal = newVal;
|
|
590
615
|
if (newVal !== null) {
|
|
591
616
|
const ae = new ActionExpression(newVal);
|
|
592
617
|
const expr = ae.getFirstExpression("callReturn");
|
|
593
618
|
if (expr) {
|
|
594
|
-
const win2 =
|
|
595
|
-
const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(
|
|
619
|
+
const win2 = SwcUtils.resolveWindow(this);
|
|
620
|
+
const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(this);
|
|
596
621
|
const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
597
622
|
try {
|
|
598
623
|
const result = FunctionUtils.executeReturn({
|
|
@@ -619,6 +644,10 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
619
644
|
get: () => mergedObservedAttributes,
|
|
620
645
|
configurable: true
|
|
621
646
|
});
|
|
647
|
+
proto.connectedCallback[SWC_ORIGINAL_CALLBACK] = originalConnected;
|
|
648
|
+
proto.disconnectedCallback[SWC_ORIGINAL_CALLBACK] = originalDisconnected;
|
|
649
|
+
proto.adoptedCallback[SWC_ORIGINAL_CALLBACK] = originalAdopted;
|
|
650
|
+
proto.attributeChangedCallback[SWC_ORIGINAL_CALLBACK] = originalAttributeChanged;
|
|
622
651
|
ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, metadata, constructor);
|
|
623
652
|
const registry = metadata.customElementRegistry || win?.customElements;
|
|
624
653
|
if (registry && !registry.get(metadata.name)) {
|