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