@dooboostore/simple-web-component 1.0.34 → 1.0.36
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 +44 -51
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +22 -17
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -16
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +234 -188
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +24 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +1 -1
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -2
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +120 -65
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +31 -21
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +53 -34
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +54 -32
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +111 -37
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +249 -122
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -2
- package/dist/cjs/router/ElementRouter.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +31 -17
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +22 -17
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +17 -16
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +233 -187
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +24 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +9 -2
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +122 -66
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +32 -22
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -35
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +55 -33
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +112 -38
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +250 -123
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +5 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +31 -17
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +7 -6
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +4 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +11 -8
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +11 -8
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +34 -21
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +21 -20
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
- package/src/decorators/elementDefine.ts +402 -358
- package/src/decorators/emitCustomEvent.ts +40 -31
- package/src/decorators/index.ts +1 -1
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
- package/src/elements/SwcAppEngine.ts +10 -3
- package/src/elements/SwcAppMixin.ts +177 -97
- package/src/elements/SwcAsync.ts +32 -21
- package/src/elements/SwcChoose.ts +74 -37
- package/src/elements/SwcIf.ts +60 -23
- package/src/elements/SwcLoop.ts +141 -28
- package/src/elements/register.ts +300 -102
- package/src/types.ts +6 -5
- package/src/utils/Utils.ts +40 -23
- package/tsconfig.json +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
|
@@ -27,7 +27,7 @@ var import_core = require("@dooboostore/core");
|
|
|
27
27
|
var import_addEventListener = require("./addEventListener");
|
|
28
28
|
var import_lifecycles = require("./lifecycles");
|
|
29
29
|
var import_emitCustomEvent = require("./emitCustomEvent");
|
|
30
|
-
var
|
|
30
|
+
var import_changedAttributeThis = require("./changedAttributeThis");
|
|
31
31
|
var import_applyAttribute = require("./applyAttribute");
|
|
32
32
|
var import_attribute = require("./attribute");
|
|
33
33
|
var import_query = require("./query");
|
|
@@ -66,7 +66,7 @@ const ensureInit = (inst) => {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
const hostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
69
|
-
const appHosts = import_Utils.SwcUtils.
|
|
69
|
+
const appHosts = import_Utils.SwcUtils.findAllAppHostsIncludingSelfDirect(inst);
|
|
70
70
|
inst._executeSwcScript?.("swc-on-constructor", hostSet);
|
|
71
71
|
const cMethods = (0, import_lifecycles.findAllLifecycleMetadata)(inst, import_lifecycles.ON_INITIALIZE_METADATA_KEY);
|
|
72
72
|
if (cMethods) {
|
|
@@ -84,7 +84,7 @@ const handleGlobalSwcEvent = async (event) => {
|
|
|
84
84
|
if (!(node instanceof HTMLElement)) continue;
|
|
85
85
|
const script = node.getAttribute?.(attrName);
|
|
86
86
|
if (script && !getElementConfig(node)) {
|
|
87
|
-
const host = import_Utils.SwcUtils.
|
|
87
|
+
const host = import_Utils.SwcUtils.findNearestSwcHostIncludingSelf(node);
|
|
88
88
|
if (host && host.isConnected && typeof host.__swc_executeAttributeEvent === "function") {
|
|
89
89
|
await host.__swc_executeAttributeEvent(node, attrName, script, event);
|
|
90
90
|
event.__swc_handled = true;
|
|
@@ -128,7 +128,7 @@ const setupPrototype = (proto) => {
|
|
|
128
128
|
proto._resolveWindow = function(localConfig) {
|
|
129
129
|
ensureInit(this);
|
|
130
130
|
if (localConfig?.window) return localConfig.window;
|
|
131
|
-
const ancestors = import_Utils.SwcUtils.
|
|
131
|
+
const ancestors = import_Utils.SwcUtils.findAllSwcHostsIncludingSelf(this);
|
|
132
132
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
133
133
|
const aConf = getElementConfig(ancestors[i]);
|
|
134
134
|
if (aConf?.window) return aConf.window;
|
|
@@ -142,7 +142,13 @@ const setupPrototype = (proto) => {
|
|
|
142
142
|
const app = useHostSet?.$appHost?.simpleApplication;
|
|
143
143
|
if (app) {
|
|
144
144
|
const otherStorage = /* @__PURE__ */ new Map();
|
|
145
|
-
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({
|
|
145
|
+
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({
|
|
146
|
+
situationType: import_types.InjectSituationType.HOST,
|
|
147
|
+
data: useHostSet.$host
|
|
148
|
+
}), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.HOSTS, data: useHostSet.$hosts }), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.FIRST_HOST, data: useHostSet.$firstHost }), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.LAST_HOST, data: useHostSet.$lastHost }), new import_Inject.SituationTypeContainer({
|
|
149
|
+
situationType: import_types.InjectSituationType.FIRST_APP_HOST,
|
|
150
|
+
data: useHostSet.$firstAppHost
|
|
151
|
+
}), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
|
|
146
152
|
otherStorage.set(import_Inject.SituationTypeContainers, situations);
|
|
147
153
|
return app.simstanceManager.executeBindParameterSim(
|
|
148
154
|
{
|
|
@@ -226,212 +232,253 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
226
232
|
metadata.extends = extendsTagName;
|
|
227
233
|
}
|
|
228
234
|
const emitCustomEventList = (0, import_emitCustomEvent.getEmitCustomEventMetadataList)(constructor) || [];
|
|
229
|
-
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "
|
|
235
|
+
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
|
|
230
236
|
const addEventListenerList = (0, import_addEventListener.getAddEventListenerMetadata)(constructor) || [];
|
|
231
|
-
const attrChangeMap = (0,
|
|
237
|
+
const attrChangeMap = (0, import_changedAttributeThis.findAllAttributeChangedMetadata)(constructor);
|
|
232
238
|
const attributeList = (0, import_attribute.findAllAttributeMetadata)(constructor);
|
|
233
239
|
const applyAttributeMap = (0, import_applyAttribute.findAllAttributeApplyMetadata)(constructor);
|
|
234
240
|
const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
|
|
235
241
|
const swcOnEvents = import_config.DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
|
|
236
242
|
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.options.name).filter(Boolean);
|
|
237
|
-
const hostAttributes = attributeList.filter((it) => it.selector === "
|
|
238
|
-
const proto = constructor.prototype;
|
|
243
|
+
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.options.name || String(it.propertyKey));
|
|
239
244
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
240
|
-
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([
|
|
241
|
-
...metadata.observedAttributes ?? [],
|
|
242
|
-
...originalStaticObservedAttributes,
|
|
243
|
-
...attrChangeMap.keys(),
|
|
244
|
-
...attributeApplyNames,
|
|
245
|
-
...hostAttributes,
|
|
246
|
-
...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean),
|
|
247
|
-
...swcLifecycleAttributes,
|
|
248
|
-
...swcOnEvents
|
|
249
|
-
])];
|
|
245
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
250
246
|
const connectedInnerHtmlList = (0, import_lifecycles.getOnConnectedInnerHtmlMetadata)(constructor) || [];
|
|
247
|
+
const proto = constructor.prototype;
|
|
251
248
|
setupPrototype(proto);
|
|
249
|
+
let helperHostSet = null;
|
|
252
250
|
const originalConnected = proto.connectedCallback;
|
|
253
|
-
proto.connectedCallback = function() {
|
|
251
|
+
proto.connectedCallback = async function() {
|
|
254
252
|
ensureInit(this);
|
|
255
|
-
|
|
256
|
-
const appHost =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
this._executeSwcScript("swc-on-before-connected", hostSet);
|
|
265
|
-
const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
266
|
-
if (bMethods) {
|
|
267
|
-
for (const m of bMethods) this._invokeLifecycleMethod(m, hostSet);
|
|
268
|
-
}
|
|
269
|
-
if (connectedInnerHtmlList.length > 0) {
|
|
270
|
-
let sContent = "", lContent = "";
|
|
271
|
-
for (const meta of connectedInnerHtmlList) {
|
|
272
|
-
const res = this._invokeLifecycleMethod(meta.propertyKey, hostSet);
|
|
273
|
-
if (res !== void 0) {
|
|
274
|
-
if (meta.options.useShadow || conf?.useShadow) sContent += res;
|
|
275
|
-
else lContent += res;
|
|
276
|
-
}
|
|
253
|
+
helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
254
|
+
const appHost = helperHostSet.$appHost;
|
|
255
|
+
try {
|
|
256
|
+
if (appHost && typeof appHost._connected === "function") {
|
|
257
|
+
await appHost._connected(this);
|
|
258
|
+
} else if (appHost && typeof appHost) {
|
|
259
|
+
appHost._connected_safari ?? (appHost._connected_safari = []);
|
|
260
|
+
appHost._connected_safari.push(this);
|
|
277
261
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
const root = this.getRootNode();
|
|
286
|
-
if (!globalDelegatedRoots.has(root)) {
|
|
287
|
-
import_config.DOM_EVENT_NAMES.forEach((type) => {
|
|
288
|
-
root.addEventListener(type, handleGlobalSwcEvent);
|
|
289
|
-
});
|
|
290
|
-
globalDelegatedRoots.add(root);
|
|
291
|
-
}
|
|
292
|
-
const delegateListeners = [];
|
|
293
|
-
const nonDelegateListeners = [];
|
|
294
|
-
addEventListenerList.forEach((meta) => {
|
|
295
|
-
if (meta.options.delegate && meta.selector !== ":window" && meta.selector !== ":document" && meta.selector !== ":parentHost" && meta.selector !== ":appHost" && meta.selector !== ":firstHost" && meta.selector !== ":lastHost" && meta.selector !== ":firstAppHost" && meta.selector !== ":lastAppHost" && meta.selector !== ":hosts" && meta.selector !== ":appHosts" && meta.selector !== ":host" && meta.selector !== "") {
|
|
296
|
-
delegateListeners.push(meta);
|
|
297
|
-
} else {
|
|
298
|
-
nonDelegateListeners.push(meta);
|
|
262
|
+
const conf = getElementConfig(this);
|
|
263
|
+
const currentWin = this._resolveWindow(conf);
|
|
264
|
+
const shadowMode = conf?.useShadow || connectedInnerHtmlList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
265
|
+
if (shadowMode && !this.shadowRoot) {
|
|
266
|
+
const mode = shadowMode === true ? "open" : shadowMode;
|
|
267
|
+
this.attachShadow({ mode });
|
|
299
268
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const r = meta.options.root || "auto";
|
|
304
|
-
const rootKey = `${meta.type}:${r}`;
|
|
305
|
-
if (!delegatesByTypeAndRoot.has(rootKey)) {
|
|
306
|
-
delegatesByTypeAndRoot.set(rootKey, []);
|
|
269
|
+
const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_CONNECTED_METADATA_KEY);
|
|
270
|
+
if (bMethods) {
|
|
271
|
+
for (const m of bMethods) await this._invokeLifecycleMethod(m, helperHostSet);
|
|
307
272
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
273
|
+
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
274
|
+
if (connectedInnerHtmlList.length > 0) {
|
|
275
|
+
let sContent = "", lContent = "";
|
|
276
|
+
for (const meta of connectedInnerHtmlList) {
|
|
277
|
+
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
278
|
+
const actionExpression = new import_core.ActionExpression(res, {
|
|
279
|
+
expression: {
|
|
280
|
+
replace: {
|
|
281
|
+
start: meta.options.replaceWrap?.start || "{%{",
|
|
282
|
+
end: meta.options.replaceWrap?.end || "}%}"
|
|
283
|
+
},
|
|
284
|
+
callReturn: {
|
|
285
|
+
start: meta.options.replaceWrap?.start || "{%{=",
|
|
286
|
+
end: meta.options.replaceWrap?.end || "}%}"
|
|
287
|
+
},
|
|
288
|
+
call: {
|
|
289
|
+
start: meta.options.replaceWrap?.start || "{%{@",
|
|
290
|
+
end: meta.options.replaceWrap?.end || "}%}"
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
actionExpression.getExpressions().filter((it) => it.type === "replace").forEach((it) => {
|
|
295
|
+
try {
|
|
296
|
+
const sr = import_core.FunctionUtils.executeReturn({ script: it.script, context: this, args: helperHostSet });
|
|
297
|
+
actionExpression.replace(it, sr);
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.error(`[SWC] Failed to execute connectedInnerHTML:`, e);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
res = actionExpression.getUnprocessedTemplate();
|
|
303
|
+
if (res !== void 0) {
|
|
304
|
+
if (meta.options.useShadow || conf?.useShadow) sContent += res;
|
|
305
|
+
else lContent += res;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
if (this.shadowRoot) {
|
|
310
|
+
this.shadowRoot.innerHTML = sContent;
|
|
311
|
+
}
|
|
312
|
+
if (lContent) {
|
|
313
|
+
this.innerHTML = lContent;
|
|
314
|
+
}
|
|
315
|
+
} catch (e) {
|
|
316
|
+
console.error("[ElementDefine] innerHTML setting error:", e);
|
|
317
|
+
}
|
|
321
318
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return bStop - aStop;
|
|
319
|
+
const root = this.getRootNode();
|
|
320
|
+
if (!globalDelegatedRoots.has(root)) {
|
|
321
|
+
import_config.DOM_EVENT_NAMES.forEach((type) => {
|
|
322
|
+
root.addEventListener(type, handleGlobalSwcEvent);
|
|
327
323
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
324
|
+
globalDelegatedRoots.add(root);
|
|
325
|
+
}
|
|
326
|
+
const delegateListeners = [];
|
|
327
|
+
const nonDelegateListeners = [];
|
|
328
|
+
addEventListenerList.forEach((meta) => {
|
|
329
|
+
if (meta.options.delegate && meta.selector !== "$window" && meta.selector !== "$document" && meta.selector !== "$host" && meta.selector !== "$appHost" && meta.selector !== "$firstHost" && meta.selector !== "$lastHost" && meta.selector !== "$firstAppHost" && meta.selector !== "$lastAppHost" && meta.selector !== "$hosts" && meta.selector !== "$appHosts" && meta.selector !== "$this" && meta.selector !== "") {
|
|
330
|
+
delegateListeners.push(meta);
|
|
331
|
+
} else {
|
|
332
|
+
nonDelegateListeners.push(meta);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
|
|
336
|
+
delegateListeners.forEach((meta) => {
|
|
337
|
+
const r = meta.options.root || "auto";
|
|
338
|
+
const rootKey = `${meta.type}:${r}`;
|
|
339
|
+
if (!delegatesByTypeAndRoot.has(rootKey)) {
|
|
340
|
+
delegatesByTypeAndRoot.set(rootKey, []);
|
|
341
|
+
}
|
|
342
|
+
delegatesByTypeAndRoot.get(rootKey).push(meta);
|
|
343
|
+
});
|
|
344
|
+
delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
|
|
345
|
+
const [type, rStr] = typeRootKey.split(":");
|
|
346
|
+
const r = rStr === "auto" ? "auto" : rStr;
|
|
347
|
+
const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
|
|
348
|
+
const bindRoots = [];
|
|
349
|
+
if (r === "auto") bindRoots.push(this.shadowRoot || this);
|
|
350
|
+
else if (r === "light") bindRoots.push(this);
|
|
351
|
+
else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
352
|
+
else if (r === "all") {
|
|
353
|
+
bindRoots.push(this);
|
|
354
|
+
if (this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
355
|
+
}
|
|
356
|
+
bindRoots.forEach((br) => {
|
|
357
|
+
const sortedMetaList = [...metaList].sort((a, b) => {
|
|
358
|
+
const aStop = a.options.stopPropagation ? 1 : 0;
|
|
359
|
+
const bStop = b.options.stopPropagation ? 1 : 0;
|
|
360
|
+
return bStop - aStop;
|
|
361
|
+
});
|
|
362
|
+
const unifiedHandler = async (event) => {
|
|
363
|
+
for (const meta of sortedMetaList) {
|
|
364
|
+
const { selector, options } = meta;
|
|
365
|
+
const matchedEl = event.target.closest(selector);
|
|
366
|
+
if (matchedEl && br.contains(matchedEl)) {
|
|
367
|
+
if (options.filter) {
|
|
368
|
+
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
|
|
369
|
+
if (!options.filter(event, helper)) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
337
372
|
}
|
|
373
|
+
if (options.stopPropagation) event.stopPropagation();
|
|
374
|
+
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
375
|
+
if (options.preventDefault) event.preventDefault();
|
|
376
|
+
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
377
|
+
const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
|
|
378
|
+
await this[meta.propertyKey](event, { ...currentHostSet, $matchedElement: matchedEl }, args);
|
|
379
|
+
if (event.cancelBubble) break;
|
|
338
380
|
}
|
|
339
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
340
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
341
|
-
if (options.preventDefault) event.preventDefault();
|
|
342
|
-
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
343
|
-
const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
|
|
344
|
-
await this[meta.propertyKey](event, currentHostSet, matchedEl, args);
|
|
345
|
-
if (event.cancelBubble) break;
|
|
346
381
|
}
|
|
382
|
+
};
|
|
383
|
+
br.addEventListener(type, unifiedHandler, opts);
|
|
384
|
+
this._boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts });
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
nonDelegateListeners.forEach((meta) => {
|
|
388
|
+
const { selector, type, options } = meta;
|
|
389
|
+
const opts = { capture: options.capture, once: options.once, passive: options.passive };
|
|
390
|
+
const bindTargets = [];
|
|
391
|
+
const r = options.root || "auto";
|
|
392
|
+
const applyRootOption = (target) => {
|
|
393
|
+
if (!target) return;
|
|
394
|
+
if (r === "auto") {
|
|
395
|
+
bindTargets.push(target.shadowRoot || target);
|
|
396
|
+
} else {
|
|
397
|
+
if (r === "light" || r === "all") bindTargets.push(target);
|
|
398
|
+
if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
|
|
347
399
|
}
|
|
348
400
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (r === "
|
|
364
|
-
if (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
else if (selector === ":firstAppHost") applyRootOption(hostSet.$firstAppHost);
|
|
374
|
-
else if (selector === ":lastAppHost") applyRootOption(hostSet.$lastAppHost);
|
|
375
|
-
else if (selector === ":hosts") hostSet.$hosts.forEach(applyRootOption);
|
|
376
|
-
else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRootOption);
|
|
377
|
-
else if (selector === ":host" || !selector) applyRootOption(this);
|
|
378
|
-
else {
|
|
379
|
-
const searchRoots = [];
|
|
380
|
-
if (r === "auto") searchRoots.push(this.shadowRoot || this);
|
|
381
|
-
else if (r === "light") searchRoots.push(this);
|
|
382
|
-
else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
383
|
-
else if (r === "all") {
|
|
384
|
-
searchRoots.push(this);
|
|
385
|
-
if (this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
401
|
+
if (selector === "$window") bindTargets.push(currentWin);
|
|
402
|
+
else if (selector === "$document") bindTargets.push(currentWin.document);
|
|
403
|
+
else if (selector === "$host") applyRootOption(helperHostSet.$host);
|
|
404
|
+
else if (selector === "$parentHost") applyRootOption(helperHostSet.$parentHost);
|
|
405
|
+
else if (selector === "$appHost") applyRootOption(helperHostSet.$appHost);
|
|
406
|
+
else if (selector === "$firstHost") applyRootOption(helperHostSet.$firstHost);
|
|
407
|
+
else if (selector === "$lastHost") applyRootOption(helperHostSet.$lastHost);
|
|
408
|
+
else if (selector === "$firstAppHost") applyRootOption(helperHostSet.$firstAppHost);
|
|
409
|
+
else if (selector === "$lastAppHost") applyRootOption(helperHostSet.$lastAppHost);
|
|
410
|
+
else if (selector === "$hosts") helperHostSet.$hosts.forEach(applyRootOption);
|
|
411
|
+
else if (selector === "$appHosts") helperHostSet.$appHosts.forEach(applyRootOption);
|
|
412
|
+
else if (selector === "$this" || !selector) applyRootOption(this);
|
|
413
|
+
else {
|
|
414
|
+
const searchRoots = [];
|
|
415
|
+
if (r === "auto") searchRoots.push(this.shadowRoot || this);
|
|
416
|
+
else if (r === "light") searchRoots.push(this);
|
|
417
|
+
else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
418
|
+
else if (r === "all") {
|
|
419
|
+
searchRoots.push(this);
|
|
420
|
+
if (this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
421
|
+
}
|
|
422
|
+
searchRoots.forEach((sr) => {
|
|
423
|
+
sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
|
|
424
|
+
});
|
|
386
425
|
}
|
|
387
|
-
|
|
388
|
-
|
|
426
|
+
bindTargets.forEach((t) => {
|
|
427
|
+
const handler = async (event) => {
|
|
428
|
+
if (options.filter) {
|
|
429
|
+
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, t);
|
|
430
|
+
if (!options.filter(event, { currentThis: this, helper })) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (options.stopPropagation) event.stopPropagation();
|
|
435
|
+
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
436
|
+
if (options.preventDefault) event.preventDefault();
|
|
437
|
+
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
438
|
+
const args = { event, ...currentHostSet, $el: t, $root: t };
|
|
439
|
+
await this[meta.propertyKey](event, { currentHostSet, $$matchedElement: event.currentTarget }, args);
|
|
440
|
+
};
|
|
441
|
+
t.addEventListener(type, handler, opts);
|
|
442
|
+
if (options.removeOnDisconnected === true || t === currentWin || t === currentWin.document) {
|
|
443
|
+
this._boundListeners.push({ target: t, type, handler, options: opts });
|
|
444
|
+
}
|
|
389
445
|
});
|
|
446
|
+
});
|
|
447
|
+
if (originalConnected) await originalConnected.apply(this);
|
|
448
|
+
const aMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_CONNECTED_METADATA_KEY);
|
|
449
|
+
if (aMethods) {
|
|
450
|
+
for (const m of aMethods) await this._invokeLifecycleMethod(m, helperHostSet);
|
|
390
451
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
452
|
+
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
453
|
+
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
454
|
+
this.__swc_connected = true;
|
|
455
|
+
for (let [name2, metaList] of Array.from(attrChangeMap)) {
|
|
456
|
+
for (const meta of metaList) {
|
|
457
|
+
if (meta.options.while === "connected") {
|
|
458
|
+
const val = (0, import_attribute.getAttributeValue)(this, name2, { type: meta.options.type });
|
|
459
|
+
if (val !== null) {
|
|
460
|
+
await this[meta.propertyKey](val, null, name2, helperHostSet);
|
|
397
461
|
}
|
|
398
462
|
}
|
|
399
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
400
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
401
|
-
if (options.preventDefault) event.preventDefault();
|
|
402
|
-
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
403
|
-
const args = { event, ...currentHostSet, $el: t, $root: t };
|
|
404
|
-
await this[meta.propertyKey](event, currentHostSet, args);
|
|
405
|
-
};
|
|
406
|
-
t.addEventListener(type, handler, opts);
|
|
407
|
-
if (options.removeOnDisconnected === true || t === currentWin || t === currentWin.document) {
|
|
408
|
-
this._boundListeners.push({ target: t, type, handler, options: opts });
|
|
409
463
|
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m, hostSet);
|
|
416
|
-
}
|
|
417
|
-
this._executeSwcScript("swc-on-connected", hostSet);
|
|
418
|
-
this._executeSwcScript("swc-on-after-connected", hostSet);
|
|
419
|
-
this.__swc_connected = true;
|
|
420
|
-
const appHostss = import_Utils.SwcUtils.findAllParentAppHostsDirect(this);
|
|
421
|
-
if (appHost && typeof appHost._connected === "function") {
|
|
422
|
-
appHost._connected(this);
|
|
423
|
-
} else if (appHost && typeof appHost) {
|
|
424
|
-
appHost._connected_safari ?? (appHost._connected_safari = []);
|
|
425
|
-
appHost._connected_safari.push(this);
|
|
464
|
+
}
|
|
465
|
+
} finally {
|
|
466
|
+
if (appHost && typeof appHost._connectedDone === "function") {
|
|
467
|
+
await appHost._connectedDone(this);
|
|
468
|
+
}
|
|
426
469
|
}
|
|
427
470
|
};
|
|
428
471
|
const originalDisconnected = proto.disconnectedCallback;
|
|
429
472
|
proto.disconnectedCallback = function() {
|
|
430
|
-
|
|
431
|
-
|
|
473
|
+
console.log("disconnnnnnnnnnnnnnnnnnn", helperHostSet, this);
|
|
474
|
+
const appHost = helperHostSet.$appHost;
|
|
475
|
+
if (appHost && typeof appHost._disconnected === "function") {
|
|
476
|
+
appHost._disconnected(this);
|
|
477
|
+
}
|
|
478
|
+
this._executeSwcScript("swc-on-before-disconnected", helperHostSet);
|
|
432
479
|
const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_DISCONNECTED_METADATA_KEY);
|
|
433
480
|
if (bMethods) {
|
|
434
|
-
for (const m of bMethods) this._invokeLifecycleMethod(m,
|
|
481
|
+
for (const m of bMethods) this._invokeLifecycleMethod(m, helperHostSet);
|
|
435
482
|
}
|
|
436
483
|
if (this._boundListeners) {
|
|
437
484
|
this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
|
|
@@ -440,15 +487,11 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
440
487
|
if (originalDisconnected) originalDisconnected.apply(this);
|
|
441
488
|
const aMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_DISCONNECTED_METADATA_KEY);
|
|
442
489
|
if (aMethods) {
|
|
443
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m,
|
|
490
|
+
for (const m of aMethods) this._invokeLifecycleMethod(m, helperHostSet);
|
|
444
491
|
}
|
|
445
|
-
this._executeSwcScript("swc-on-disconnected",
|
|
446
|
-
this._executeSwcScript("swc-on-after-disconnected",
|
|
492
|
+
this._executeSwcScript("swc-on-disconnected", helperHostSet);
|
|
493
|
+
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
447
494
|
this.__swc_connected = false;
|
|
448
|
-
const appHost = hostSet.$appHost;
|
|
449
|
-
if (appHost && typeof appHost._disconnected === "function") {
|
|
450
|
-
appHost._disconnected(this);
|
|
451
|
-
}
|
|
452
495
|
};
|
|
453
496
|
const originalAdopted = proto.adoptedCallback;
|
|
454
497
|
proto.adoptedCallback = function() {
|
|
@@ -473,12 +516,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
473
516
|
let processedVal = newVal;
|
|
474
517
|
if (newVal !== null) {
|
|
475
518
|
const ae = new import_core.ActionExpression(newVal);
|
|
476
|
-
const expr = ae.getFirstExpression("
|
|
519
|
+
const expr = ae.getFirstExpression("callReturn");
|
|
477
520
|
if (expr) {
|
|
478
521
|
const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
|
|
479
522
|
const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win2, this);
|
|
523
|
+
const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
480
524
|
try {
|
|
481
|
-
const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
482
525
|
const result = import_core.FunctionUtils.executeReturn({
|
|
483
526
|
script,
|
|
484
527
|
context: this,
|
|
@@ -504,7 +547,10 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
504
547
|
const metaList = attrChangeMap.get(name2);
|
|
505
548
|
if (metaList && Array.isArray(metaList)) {
|
|
506
549
|
for (const meta of metaList) {
|
|
507
|
-
|
|
550
|
+
if (meta.options.while === "connected" && !this.__swc_connected) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const convertedVal = (0, import_changedAttributeThis.convertAttributeValue)(processedVal, meta.options.type);
|
|
508
554
|
this[meta.propertyKey](convertedVal, old, name2, hSet);
|
|
509
555
|
}
|
|
510
556
|
}
|