@dooboostore/simple-web-component 1.0.48 → 1.0.49
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 +117 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +387 -29
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +237 -437
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +140 -0
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +87 -0
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +388 -29
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +244 -444
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +141 -0
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +88 -0
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2565 -1474
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +84 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +0 -14
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +35 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +34 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2565 -1474
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -5
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +394 -34
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +281 -580
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +3 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +215 -39
- package/src/decorators/query.ts +168 -126
- package/src/decorators/resizeObserver.ts +152 -46
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
|
@@ -24,16 +24,15 @@ __export(elementDefine_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(elementDefine_exports);
|
|
26
26
|
var import_core = require("@dooboostore/core");
|
|
27
|
-
var import_operators = require("@dooboostore/core/message/operators");
|
|
28
27
|
var import_addEventListener = require("./addEventListener");
|
|
29
28
|
var import_mutationObserver = require("./mutationObserver");
|
|
30
29
|
var import_resizeObserver = require("./resizeObserver");
|
|
30
|
+
var import_intersectionObserver = require("./intersectionObserver");
|
|
31
31
|
var import_lifecycles = require("./lifecycles");
|
|
32
32
|
var import_emitCustomEvent = require("./emitCustomEvent");
|
|
33
33
|
var import_changedAttribute = require("./changedAttribute");
|
|
34
34
|
var import_applyAttribute = require("./applyAttribute");
|
|
35
35
|
var import_query = require("./query");
|
|
36
|
-
var import_queryAll = require("./queryAll");
|
|
37
36
|
var import_Utils = require("../utils/Utils");
|
|
38
37
|
var import_config = require("../config/config");
|
|
39
38
|
var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject");
|
|
@@ -42,6 +41,10 @@ var import_core_web = require("@dooboostore/core-web");
|
|
|
42
41
|
var import_SwcAppMixin = require("../elements/SwcAppMixin");
|
|
43
42
|
var import_state = require("./state");
|
|
44
43
|
var import_applyProperty = require("./applyProperty");
|
|
44
|
+
var import_subscribeSwcAppMessageWhileConnected = require("./subscribeSwcAppMessageWhileConnected");
|
|
45
|
+
var import_subscribeSwcAppRouteChangeWhileConnected = require("./subscribeSwcAppRouteChangeWhileConnected");
|
|
46
|
+
var import_setInterval = require("./setInterval");
|
|
47
|
+
var import_setTimeout = require("./setTimeout");
|
|
45
48
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
46
49
|
const getElementConfig = (target) => {
|
|
47
50
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -65,7 +68,7 @@ const ensureInit = (inst) => {
|
|
|
65
68
|
delete inst[meta.propertyKey];
|
|
66
69
|
});
|
|
67
70
|
}
|
|
68
|
-
const queryAllList = (0,
|
|
71
|
+
const queryAllList = (0, import_query.getQueryAllMetadata)(target);
|
|
69
72
|
if (queryAllList) {
|
|
70
73
|
queryAllList.forEach((meta) => {
|
|
71
74
|
delete inst[meta.propertyKey];
|
|
@@ -249,12 +252,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
249
252
|
}
|
|
250
253
|
metadata.extends = extendsTagName;
|
|
251
254
|
}
|
|
252
|
-
const emitCustomEventList = (0, import_emitCustomEvent.getEmitCustomEventMetadataList)(constructor) || [];
|
|
253
|
-
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
|
|
254
|
-
const addEventListenerList = (0, import_addEventListener.getAddEventListenerMetadata)(constructor) || [];
|
|
255
|
-
const mutationObserverList = (0, import_mutationObserver.getMutationObserverMetadata)(constructor) || [];
|
|
256
|
-
const resizeObserverList = (0, import_resizeObserver.getResizeObserverMetadata)(constructor) || [];
|
|
257
|
-
const attrChangeMap = (0, import_changedAttribute.findAllAttributeChangedMetadata)(constructor);
|
|
258
255
|
const attributeList = (0, import_applyAttribute.findAllAttributeMetadata)(constructor);
|
|
259
256
|
const applyAttributeMap = (0, import_applyAttribute.findAllAttributeApplyMetadata)(constructor);
|
|
260
257
|
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"];
|
|
@@ -262,22 +259,225 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
262
259
|
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
|
|
263
260
|
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
|
|
264
261
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
265
|
-
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
266
262
|
const proto = constructor.prototype;
|
|
267
263
|
setupPrototype(proto, win);
|
|
268
264
|
let helperHostSet = null;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
265
|
+
const eventCycler = new import_addEventListener.EventListenerLifeCycler();
|
|
266
|
+
const cyclers = [
|
|
267
|
+
eventCycler,
|
|
268
|
+
new import_changedAttribute.ChangedAttributeLifeCycler(),
|
|
269
|
+
new import_emitCustomEvent.EmitCustomEventLifeCycler(),
|
|
270
|
+
new import_resizeObserver.ResizeObserverLifeCycler(),
|
|
271
|
+
new import_intersectionObserver.IntersectionObserverLifeCycler(),
|
|
272
|
+
new import_mutationObserver.MutationObserverLifeCycler(),
|
|
273
|
+
new import_subscribeSwcAppMessageWhileConnected.MessageSubscribeLifeCycler(),
|
|
274
|
+
new import_subscribeSwcAppRouteChangeWhileConnected.RouteSubscribeLifeCycler(),
|
|
275
|
+
new import_setInterval.SetIntervalLifeCycler(),
|
|
276
|
+
new import_setTimeout.SetTimeoutLifeCycler()
|
|
277
|
+
];
|
|
278
|
+
const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
|
|
279
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
280
|
+
const buildObservers = async (helperHostSet2) => {
|
|
281
|
+
const inst = helperHostSet2.$this;
|
|
282
|
+
const observers = [];
|
|
283
|
+
let resizeObserverSet = [];
|
|
284
|
+
let mutationObserverSet = [];
|
|
285
|
+
let intersectionObserverSet = [];
|
|
286
|
+
const resolveDelegateRoots = (delegateRoot) => {
|
|
287
|
+
const r = delegateRoot || "auto";
|
|
288
|
+
const roots = [];
|
|
289
|
+
if (r === "auto") roots.push(inst.shadowRoot || inst);
|
|
290
|
+
else if (r === "light") roots.push(inst);
|
|
291
|
+
else if (r === "shadow" && inst.shadowRoot) roots.push(inst.shadowRoot);
|
|
292
|
+
else if (r === "all") {
|
|
293
|
+
roots.push(inst);
|
|
294
|
+
if (inst.shadowRoot) roots.push(inst.shadowRoot);
|
|
295
|
+
}
|
|
296
|
+
return roots;
|
|
297
|
+
};
|
|
298
|
+
for (const c of cyclers) {
|
|
299
|
+
const result = await c.onConnected?.(helperHostSet2, resizeObserverSet);
|
|
300
|
+
if (!result) continue;
|
|
301
|
+
if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
|
|
302
|
+
if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
|
|
303
|
+
if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
|
|
304
|
+
}
|
|
305
|
+
const resizeDelegates = (resizeObserverSet ?? []).filter((t) => t.delegate && typeof t.target === "string");
|
|
306
|
+
let resizeObserve;
|
|
307
|
+
let resizeUnobserve;
|
|
308
|
+
const resizeObserved = /* @__PURE__ */ new WeakSet();
|
|
309
|
+
if (resizeObserverSet?.length) {
|
|
310
|
+
const roCallbacks = [...new Set(resizeObserverSet.map((e) => e.callback))];
|
|
311
|
+
const ro = new win.ResizeObserver((entries, obs) => {
|
|
312
|
+
for (const cb of roCallbacks) cb(entries, obs);
|
|
313
|
+
});
|
|
314
|
+
for (const e of resizeObserverSet) {
|
|
315
|
+
if (e.delegate) continue;
|
|
316
|
+
if (typeof e.target === "string") {
|
|
317
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
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
|
+
}
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
ro.observe(e.target, e.options);
|
|
329
|
+
if (e.target instanceof Element) resizeObserved.add(e.target);
|
|
330
|
+
}
|
|
331
|
+
resizeObserve = (el, opts) => {
|
|
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);
|
|
342
|
+
}
|
|
343
|
+
const intersectionDelegates = [];
|
|
344
|
+
for (const group of intersectionObserverSet) {
|
|
345
|
+
const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
|
|
346
|
+
const io = new win.IntersectionObserver((entries, obs) => {
|
|
347
|
+
for (const cb of ioCallbacks) cb(entries, obs);
|
|
348
|
+
}, group.options);
|
|
349
|
+
const ioObserved = /* @__PURE__ */ new WeakSet();
|
|
350
|
+
for (const e of group.observeTargets) {
|
|
351
|
+
if (e.delegate) {
|
|
352
|
+
const target = e.target;
|
|
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 });
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (typeof e.target === "string") {
|
|
367
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
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
|
+
}
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
io.observe(e.target);
|
|
379
|
+
if (e.target instanceof Element) ioObserved.add(e.target);
|
|
380
|
+
}
|
|
381
|
+
observers.push(io);
|
|
382
|
+
}
|
|
383
|
+
const handleResizeDelegate = (n, observe) => {
|
|
384
|
+
if (!resizeObserve || !resizeUnobserve || n.nodeType !== 1) return;
|
|
385
|
+
const el = n;
|
|
386
|
+
for (const d of resizeDelegates) {
|
|
387
|
+
const isThis = d.target === "$this" || d.target === "";
|
|
388
|
+
const matchesSel = (node) => {
|
|
389
|
+
if (!node || node.nodeType !== 1) return false;
|
|
390
|
+
if (isThis) return true;
|
|
391
|
+
return node.matches?.(d.target) || !!node.closest?.(d.target);
|
|
392
|
+
};
|
|
393
|
+
if (matchesSel(el)) {
|
|
394
|
+
observe ? resizeObserve(el, d.options) : resizeUnobserve(el);
|
|
395
|
+
} else if (!isThis) {
|
|
396
|
+
el.querySelectorAll(d.target).forEach((sub) => {
|
|
397
|
+
observe ? resizeObserve(sub, d.options) : resizeUnobserve(sub);
|
|
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
|
+
}
|
|
419
|
+
}
|
|
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
|
+
const addObserveTarget = (target, options) => {
|
|
451
|
+
moObserveTargets.set(target, mergeMutationInit(moObserveTargets.get(target), options));
|
|
452
|
+
};
|
|
453
|
+
for (const e of mutationObserverSet ?? []) {
|
|
454
|
+
if (e.delegate) continue;
|
|
455
|
+
const init = e.options ?? { childList: true };
|
|
456
|
+
if (typeof e.target === "string") {
|
|
457
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
458
|
+
for (const sr of scope) {
|
|
459
|
+
sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
460
|
+
}
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
addObserveTarget(e.target, init);
|
|
464
|
+
}
|
|
465
|
+
for (const d of resizeDelegates) {
|
|
466
|
+
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
467
|
+
}
|
|
468
|
+
for (const d of intersectionDelegates) {
|
|
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);
|
|
475
|
+
}
|
|
476
|
+
inst.__swc_observers = observers;
|
|
477
|
+
};
|
|
275
478
|
const originalConnected = proto.connectedCallback;
|
|
276
479
|
proto.connectedCallback = async function() {
|
|
277
480
|
ensureInit(this);
|
|
278
|
-
boundListeners = [];
|
|
279
|
-
resizeObservers = [];
|
|
280
|
-
removeObserverCallbacks = [];
|
|
281
481
|
helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
282
482
|
const appHost = helperHostSet.$appHost;
|
|
283
483
|
const useSsr = (0, import_SwcAppMixin.isSSR)(this);
|
|
@@ -290,14 +490,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
290
490
|
}
|
|
291
491
|
const conf = getElementConfig(this);
|
|
292
492
|
const currentWin = this._resolveWindow(conf);
|
|
293
|
-
const
|
|
294
|
-
for (const m of bMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
493
|
+
for (const m of (0, import_lifecycles.findAllOnConnectedBeforeMetadata)(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
295
494
|
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
296
495
|
const targetConnectedList = useSsr ? [] : (0, import_lifecycles.findAllOnConnectedMetadata)(constructor);
|
|
297
496
|
const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
298
497
|
if (shadowMode && !this.shadowRoot) {
|
|
299
498
|
const mode = shadowMode === true ? "open" : shadowMode;
|
|
300
|
-
console.log("tagName=", this.tagName, "mode", mode, this.shadowRoot);
|
|
301
499
|
this.attachShadow({ mode });
|
|
302
500
|
}
|
|
303
501
|
const stateContext = { ...helperHostSet };
|
|
@@ -306,7 +504,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
306
504
|
});
|
|
307
505
|
const shadowChildren = [];
|
|
308
506
|
const lightChildren = [];
|
|
309
|
-
console.log("targetConnectList", this.tagName, targetConnectedList.length);
|
|
310
507
|
if (targetConnectedList.length > 0) {
|
|
311
508
|
for (const meta of targetConnectedList) {
|
|
312
509
|
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
@@ -347,366 +544,14 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
347
544
|
});
|
|
348
545
|
globalDelegatedRoots.add(root);
|
|
349
546
|
}
|
|
350
|
-
|
|
351
|
-
const nonDelegateListeners = [];
|
|
352
|
-
addEventListenerList.forEach((meta) => {
|
|
353
|
-
const isStringSelector = typeof meta.selector === "string";
|
|
354
|
-
if (meta.options.delegate && isStringSelector && 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 !== "") {
|
|
355
|
-
delegateListeners.push(meta);
|
|
356
|
-
} else {
|
|
357
|
-
nonDelegateListeners.push(meta);
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
|
|
361
|
-
delegateListeners.forEach((meta) => {
|
|
362
|
-
const r = meta.options.root || "auto";
|
|
363
|
-
const rootKey = `${meta.type}:${r}`;
|
|
364
|
-
if (!delegatesByTypeAndRoot.has(rootKey)) {
|
|
365
|
-
delegatesByTypeAndRoot.set(rootKey, []);
|
|
366
|
-
}
|
|
367
|
-
delegatesByTypeAndRoot.get(rootKey).push(meta);
|
|
368
|
-
});
|
|
369
|
-
delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
|
|
370
|
-
const [type, rStr] = typeRootKey.split(":");
|
|
371
|
-
const r = rStr === "auto" ? "auto" : rStr;
|
|
372
|
-
const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
|
|
373
|
-
const bindRoots = [];
|
|
374
|
-
if (r === "auto") bindRoots.push(this.shadowRoot || this);
|
|
375
|
-
else if (r === "light") bindRoots.push(this);
|
|
376
|
-
else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
377
|
-
else if (r === "all") {
|
|
378
|
-
bindRoots.push(this);
|
|
379
|
-
if (this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
380
|
-
}
|
|
381
|
-
bindRoots.forEach((br) => {
|
|
382
|
-
const sortedMetaList = [...metaList].sort((a, b) => {
|
|
383
|
-
const aStop = a.options.stopPropagation ? 1 : 0;
|
|
384
|
-
const bStop = b.options.stopPropagation ? 1 : 0;
|
|
385
|
-
return bStop - aStop;
|
|
386
|
-
});
|
|
387
|
-
const unifiedHandler = async (event) => {
|
|
388
|
-
for (const meta of sortedMetaList) {
|
|
389
|
-
const { selector, options } = meta;
|
|
390
|
-
const matchedEl = event.target?.closest(selector);
|
|
391
|
-
if (matchedEl && br.contains(matchedEl)) {
|
|
392
|
-
if (options.filter) {
|
|
393
|
-
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
|
|
394
|
-
if (!options.filter(event, helper)) {
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
399
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
400
|
-
if (options.preventDefault) event.preventDefault();
|
|
401
|
-
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
402
|
-
const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
|
|
403
|
-
await this[meta.propertyKey](event, { ...currentHostSet, $matchedElement: matchedEl }, args);
|
|
404
|
-
if (event.cancelBubble) break;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
br.addEventListener(type, unifiedHandler, opts);
|
|
409
|
-
const onRemoves = [];
|
|
410
|
-
for (const m of sortedMetaList) {
|
|
411
|
-
if (m.options.removeListener) {
|
|
412
|
-
onRemoves.push({ fn: m.options.removeListener, opts: m.options });
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts, onRemoves });
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
nonDelegateListeners.forEach((meta) => {
|
|
419
|
-
const { selector, type, options } = meta;
|
|
420
|
-
const opts = { capture: options.capture, once: options.once, passive: options.passive };
|
|
421
|
-
const bindTargets = [];
|
|
422
|
-
const r = options.root || "auto";
|
|
423
|
-
let resolvedSelector = null;
|
|
424
|
-
if (typeof selector === "function") {
|
|
425
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
426
|
-
const result = selector(this, hostSet);
|
|
427
|
-
if (typeof result === "string") {
|
|
428
|
-
resolvedSelector = result;
|
|
429
|
-
} else if (result instanceof currentWin.Element) {
|
|
430
|
-
bindTargets.push(result);
|
|
431
|
-
} else if (result instanceof currentWin.NodeList) {
|
|
432
|
-
bindTargets.push(...Array.from(result));
|
|
433
|
-
} else if (Array.isArray(result)) {
|
|
434
|
-
bindTargets.push(...result);
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
resolvedSelector = selector;
|
|
438
|
-
}
|
|
439
|
-
const applyRootOption = (target) => {
|
|
440
|
-
if (!target) return;
|
|
441
|
-
if (r === "auto") {
|
|
442
|
-
bindTargets.push(target.shadowRoot || target);
|
|
443
|
-
} else {
|
|
444
|
-
if (r === "light" || r === "all") bindTargets.push(target);
|
|
445
|
-
if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
if (resolvedSelector) {
|
|
449
|
-
if (resolvedSelector === "$window") bindTargets.push(currentWin);
|
|
450
|
-
else if (resolvedSelector === "$document") bindTargets.push(currentWin.document);
|
|
451
|
-
else if (resolvedSelector === "$host") applyRootOption(helperHostSet.$host);
|
|
452
|
-
else if (resolvedSelector === "$parentHost") applyRootOption(helperHostSet.$parentHost);
|
|
453
|
-
else if (resolvedSelector === "$appHost") applyRootOption(helperHostSet.$appHost);
|
|
454
|
-
else if (resolvedSelector === "$firstHost") applyRootOption(helperHostSet.$firstHost);
|
|
455
|
-
else if (resolvedSelector === "$lastHost") applyRootOption(helperHostSet.$lastHost);
|
|
456
|
-
else if (resolvedSelector === "$firstAppHost") applyRootOption(helperHostSet.$firstAppHost);
|
|
457
|
-
else if (resolvedSelector === "$lastAppHost") applyRootOption(helperHostSet.$lastAppHost);
|
|
458
|
-
else if (resolvedSelector === "$hosts") helperHostSet.$hosts.forEach(applyRootOption);
|
|
459
|
-
else if (resolvedSelector === "$appHosts") helperHostSet.$appHosts.forEach(applyRootOption);
|
|
460
|
-
else if (resolvedSelector === "$this" || !resolvedSelector) applyRootOption(this);
|
|
461
|
-
else {
|
|
462
|
-
const searchRoots = [];
|
|
463
|
-
if (r === "auto") searchRoots.push(this.shadowRoot || this);
|
|
464
|
-
else if (r === "light") searchRoots.push(this);
|
|
465
|
-
else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
466
|
-
else if (r === "all") {
|
|
467
|
-
searchRoots.push(this);
|
|
468
|
-
if (this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
469
|
-
}
|
|
470
|
-
searchRoots.forEach((sr) => {
|
|
471
|
-
sr.querySelectorAll(resolvedSelector).forEach((el) => bindTargets.push(el));
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
bindTargets.forEach((t) => {
|
|
476
|
-
const handler = async (event) => {
|
|
477
|
-
if (options.filter) {
|
|
478
|
-
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, t);
|
|
479
|
-
if (!options.filter(event, { currentThis: this, helper })) {
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
484
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
485
|
-
if (options.preventDefault) event.preventDefault();
|
|
486
|
-
const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
487
|
-
const args = { event, ...currentHostSet, $el: t, $root: t };
|
|
488
|
-
await this[meta.propertyKey](event, { currentHostSet, $matchedElement: event.currentTarget }, args);
|
|
489
|
-
};
|
|
490
|
-
const eventSubject = new import_core.Subject();
|
|
491
|
-
let eventStream = eventSubject;
|
|
492
|
-
if (options.debounceTime !== void 0 && options.debounceTime > 0) {
|
|
493
|
-
eventStream = eventStream.pipe((0, import_operators.debounceTime)(options.debounceTime));
|
|
494
|
-
}
|
|
495
|
-
if (options.throttleTime !== void 0 && options.throttleTime > 0) {
|
|
496
|
-
eventStream = eventStream.pipe((0, import_operators.throttleTime)(options.throttleTime));
|
|
497
|
-
}
|
|
498
|
-
if (options.distinctUntilChanged !== void 0 && options.distinctUntilChanged !== false) {
|
|
499
|
-
if (typeof options.distinctUntilChanged === "function") {
|
|
500
|
-
eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)(options.distinctUntilChanged));
|
|
501
|
-
} else {
|
|
502
|
-
eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)());
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const subscription = eventStream.subscribe({
|
|
506
|
-
next: (event) => {
|
|
507
|
-
handler(event).catch((err) => console.error("Event handler error:", err));
|
|
508
|
-
},
|
|
509
|
-
error: (err) => console.error("Event stream error:", err)
|
|
510
|
-
});
|
|
511
|
-
const wrappedHandler = (event) => {
|
|
512
|
-
eventSubject.next(event);
|
|
513
|
-
};
|
|
514
|
-
t.addEventListener(type, wrappedHandler, opts);
|
|
515
|
-
const onRemoves = options.removeListener ? [{ fn: options.removeListener, opts }] : [];
|
|
516
|
-
boundListeners.push({ target: t, type, handler: wrappedHandler, options: opts, subscription, onRemoves });
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
shadowMutationObserver = null;
|
|
520
|
-
lightMutationObserver = null;
|
|
521
|
-
resizeObserver = null;
|
|
522
|
-
if (resizeObserverList.length > 0) {
|
|
523
|
-
const root2 = this.shadowRoot || this;
|
|
524
|
-
resizeObserver = new ResizeObserver((entries, obs) => {
|
|
525
|
-
for (const m of resizeObserverList) {
|
|
526
|
-
let matchedEls = [];
|
|
527
|
-
if (m.options.delegate && typeof m.selector === "string") {
|
|
528
|
-
const isThis = m.selector === "$this" || m.selector === "";
|
|
529
|
-
const matchesSel = (node) => {
|
|
530
|
-
if (!node || node.nodeType !== 1) return false;
|
|
531
|
-
if (isThis) return true;
|
|
532
|
-
const el = node;
|
|
533
|
-
return el.matches?.(m.selector) || !!el.closest?.(m.selector);
|
|
534
|
-
};
|
|
535
|
-
matchedEls = entries.map((e) => e.target).filter(matchesSel);
|
|
536
|
-
} else {
|
|
537
|
-
matchedEls = entries.map((e) => e.target).filter((t) => t && t.nodeType === 1);
|
|
538
|
-
}
|
|
539
|
-
if (matchedEls.length === 0) continue;
|
|
540
|
-
if (m.options.filter) {
|
|
541
|
-
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
542
|
-
if (!m.options.filter(matchedEls, { currentThis: this, helper })) continue;
|
|
543
|
-
}
|
|
544
|
-
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
545
|
-
this[m.propertyKey](matchedEls, entries, obs, { ...hostSet, $root: root2 });
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
resizeObservers.push(resizeObserver);
|
|
549
|
-
for (const m of resizeObserverList) {
|
|
550
|
-
if (m.options.removeObserver) {
|
|
551
|
-
removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root2, opts: m.options });
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
const shadowMetas = mutationObserverList.filter((m) => {
|
|
556
|
-
const r = m.options.root || "auto";
|
|
557
|
-
return this.shadowRoot && (r === "shadow" || r === "all" || r === "auto");
|
|
558
|
-
});
|
|
559
|
-
const lightMetas = mutationObserverList.filter((m) => {
|
|
560
|
-
const r = m.options.root || "auto";
|
|
561
|
-
return r === "light" || r === "all" || !this.shadowRoot && r === "auto";
|
|
562
|
-
});
|
|
563
|
-
const setupMutationObserver = (root2, metas, resizeDelegates = []) => {
|
|
564
|
-
if (metas.length === 0) return null;
|
|
565
|
-
const initFrom = (o) => {
|
|
566
|
-
const init = {
|
|
567
|
-
childList: o.childList,
|
|
568
|
-
attributes: o.attributes,
|
|
569
|
-
characterData: o.characterData,
|
|
570
|
-
subtree: o.subtree,
|
|
571
|
-
attributeFilter: o.attributeFilter,
|
|
572
|
-
attributeOldValue: o.attributeOldValue,
|
|
573
|
-
characterDataOldValue: o.characterDataOldValue
|
|
574
|
-
};
|
|
575
|
-
if (!init.childList && !init.attributes && !init.characterData) init.childList = true;
|
|
576
|
-
return init;
|
|
577
|
-
};
|
|
578
|
-
const observer = new MutationObserver((mutations, obs) => {
|
|
579
|
-
for (const meta of metas) {
|
|
580
|
-
const { selector, options } = meta;
|
|
581
|
-
let matchedEls = [];
|
|
582
|
-
if (options.delegate && typeof selector === "string") {
|
|
583
|
-
const isThis = selector === "$this" || selector === "";
|
|
584
|
-
const matchesSel = (node) => {
|
|
585
|
-
if (!node || node.nodeType !== 1) return false;
|
|
586
|
-
if (isThis) return true;
|
|
587
|
-
const el = node;
|
|
588
|
-
return el.matches?.(selector) || !!el.closest?.(selector);
|
|
589
|
-
};
|
|
590
|
-
matchedEls = mutations.flatMap((m) => {
|
|
591
|
-
const els = [];
|
|
592
|
-
if (matchesSel(m.target)) els.push(m.target);
|
|
593
|
-
Array.from(m.addedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
|
|
594
|
-
Array.from(m.removedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
|
|
595
|
-
return els;
|
|
596
|
-
});
|
|
597
|
-
} else if (typeof selector === "string") {
|
|
598
|
-
const isThis = selector === "$this" || selector === "";
|
|
599
|
-
const matchesSel = (node) => {
|
|
600
|
-
if (!node || node.nodeType !== 1) return false;
|
|
601
|
-
if (isThis) return true;
|
|
602
|
-
return node.matches?.(selector);
|
|
603
|
-
};
|
|
604
|
-
matchedEls = mutations.flatMap((m) => {
|
|
605
|
-
const els = [];
|
|
606
|
-
if (matchesSel(m.target)) els.push(m.target);
|
|
607
|
-
Array.from(m.addedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
|
|
608
|
-
Array.from(m.removedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
|
|
609
|
-
return els;
|
|
610
|
-
});
|
|
611
|
-
} else {
|
|
612
|
-
matchedEls = mutations.map((m) => m.target).filter((t) => t && t.nodeType === 1);
|
|
613
|
-
}
|
|
614
|
-
if (matchedEls.length === 0) continue;
|
|
615
|
-
if (options.filter) {
|
|
616
|
-
const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
617
|
-
if (!options.filter(matchedEls, { currentThis: this, helper })) continue;
|
|
618
|
-
}
|
|
619
|
-
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
620
|
-
this[meta.propertyKey](matchedEls, mutations, obs, { ...hostSet, $root: root2 });
|
|
621
|
-
}
|
|
622
|
-
if (resizeDelegates.length > 0 && resizeObserver) {
|
|
623
|
-
const handle = (n, observe) => {
|
|
624
|
-
if (n.nodeType !== 1) return;
|
|
625
|
-
const el = n;
|
|
626
|
-
for (const m of resizeDelegates) {
|
|
627
|
-
if (typeof m.selector !== "string") continue;
|
|
628
|
-
const isThis = m.selector === "$this" || m.selector === "";
|
|
629
|
-
const matchesSel = (node) => {
|
|
630
|
-
if (!node || node.nodeType !== 1) return false;
|
|
631
|
-
if (isThis) return true;
|
|
632
|
-
const e = node;
|
|
633
|
-
return e.matches?.(m.selector) || !!e.closest?.(m.selector);
|
|
634
|
-
};
|
|
635
|
-
if (matchesSel(el)) {
|
|
636
|
-
if (observe) resizeObserver.observe(el, m.options.box ? { box: m.options.box } : void 0);
|
|
637
|
-
else resizeObserver.unobserve(el);
|
|
638
|
-
} else if (!isThis) {
|
|
639
|
-
el.querySelectorAll(m.selector).forEach((sub) => {
|
|
640
|
-
if (observe) resizeObserver.observe(sub, m.options.box ? { box: m.options.box } : void 0);
|
|
641
|
-
else resizeObserver.unobserve(sub);
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
for (const m of mutations) {
|
|
647
|
-
Array.from(m.addedNodes || []).forEach((n) => handle(n, true));
|
|
648
|
-
Array.from(m.removedNodes || []).forEach((n) => handle(n, false));
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
const hasDelegate = metas.some((m) => m.options.delegate) || resizeDelegates.some((m) => m.options.delegate);
|
|
653
|
-
if (hasDelegate) {
|
|
654
|
-
observer.observe(root2, { childList: true, subtree: true });
|
|
655
|
-
}
|
|
656
|
-
const nonDelegateMetas = metas.filter((m) => !m.options.delegate);
|
|
657
|
-
for (const m of nonDelegateMetas) {
|
|
658
|
-
const { selector, options } = m;
|
|
659
|
-
const mInit = initFrom(options);
|
|
660
|
-
if (typeof selector === "string") {
|
|
661
|
-
if (selector === "$this" || selector === "") {
|
|
662
|
-
observer.observe(root2, mInit);
|
|
663
|
-
} else {
|
|
664
|
-
root2.querySelectorAll(selector).forEach((el) => observer.observe(el, mInit));
|
|
665
|
-
}
|
|
666
|
-
} else if (typeof selector === "function") {
|
|
667
|
-
observer.observe(root2, mInit);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return observer;
|
|
671
|
-
};
|
|
672
|
-
const shadowResizeDelegateMetas = resizeObserverList.filter((m) => {
|
|
673
|
-
if (!m.options.delegate) return false;
|
|
674
|
-
const r = m.options.root || "auto";
|
|
675
|
-
return this.shadowRoot && (r === "shadow" || r === "all" || r === "auto");
|
|
676
|
-
});
|
|
677
|
-
const lightResizeDelegateMetas = resizeObserverList.filter((m) => {
|
|
678
|
-
if (!m.options.delegate) return false;
|
|
679
|
-
const r = m.options.root || "auto";
|
|
680
|
-
return r === "light" || r === "all" || !this.shadowRoot && r === "auto";
|
|
681
|
-
});
|
|
682
|
-
if (this.shadowRoot) shadowMutationObserver = setupMutationObserver(this.shadowRoot, shadowMetas, shadowResizeDelegateMetas);
|
|
683
|
-
lightMutationObserver = setupMutationObserver(this, lightMetas, lightResizeDelegateMetas);
|
|
684
|
-
for (const m of mutationObserverList) {
|
|
685
|
-
if (m.options.removeObserver) {
|
|
686
|
-
const rootForM = this.shadowRoot && (m.options.root === "shadow" || m.options.root === "all" || m.options.root === "auto" && this.shadowRoot) ? this.shadowRoot : this;
|
|
687
|
-
removeObserverCallbacks.push({ fn: m.options.removeObserver, target: rootForM, opts: m.options });
|
|
688
|
-
}
|
|
689
|
-
}
|
|
547
|
+
await buildObservers(import_Utils.SwcUtils.getHelperAndHostSet(win, this));
|
|
690
548
|
if (originalConnected) await originalConnected.apply(this);
|
|
691
|
-
const
|
|
692
|
-
for (const m of aMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
549
|
+
for (const m of (0, import_lifecycles.findAllOnConnectedAfterMetadata)(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
693
550
|
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
694
551
|
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
695
552
|
this.__swc_connected = true;
|
|
696
|
-
for (let [name2, metaList] of Array.from(attrChangeMap)) {
|
|
697
|
-
for (const meta of metaList) {
|
|
698
|
-
if (meta.options.while === "connected") {
|
|
699
|
-
const val = (0, import_applyAttribute.getAttributeValue)(this, name2, { type: meta.options.type });
|
|
700
|
-
if (val !== null) {
|
|
701
|
-
await this[meta.propertyKey](val, null, name2, helperHostSet);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
553
|
} finally {
|
|
707
|
-
for (
|
|
708
|
-
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
709
|
-
}
|
|
554
|
+
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
710
555
|
if (appHost && typeof appHost._connectedDone === "function") {
|
|
711
556
|
await appHost._connectedDone(this);
|
|
712
557
|
}
|
|
@@ -714,55 +559,24 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
714
559
|
};
|
|
715
560
|
const originalDisconnected = proto.disconnectedCallback;
|
|
716
561
|
proto.disconnectedCallback = function() {
|
|
717
|
-
const appHost = helperHostSet
|
|
562
|
+
const appHost = helperHostSet?.$appHost;
|
|
718
563
|
if (appHost && typeof appHost._disconnected === "function") {
|
|
719
564
|
appHost._disconnected(this);
|
|
720
565
|
}
|
|
721
566
|
this._executeSwcScript("swc-on-before-disconnected", helperHostSet);
|
|
722
|
-
const
|
|
723
|
-
for (const
|
|
724
|
-
|
|
725
|
-
boundListeners.forEach((l) => {
|
|
726
|
-
l.target.removeEventListener(l.type, l.handler, l.options);
|
|
727
|
-
if (l.subscription && typeof l.subscription.unsubscribe === "function") {
|
|
728
|
-
l.subscription.unsubscribe();
|
|
729
|
-
}
|
|
730
|
-
if (Array.isArray(l.onRemoves)) {
|
|
731
|
-
for (const r of l.onRemoves) {
|
|
732
|
-
try {
|
|
733
|
-
r.fn(l.target, r.opts);
|
|
734
|
-
} catch (e) {
|
|
735
|
-
console.error("[SWC] removeListener error:", e);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
boundListeners = [];
|
|
741
|
-
}
|
|
742
|
-
const _obs = [shadowMutationObserver, lightMutationObserver, resizeObserver, ...resizeObservers];
|
|
743
|
-
for (const o of _obs) {
|
|
567
|
+
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
568
|
+
for (const c of cyclers) c.onDisconnected?.(helperHostSet);
|
|
569
|
+
for (const o of this.__swc_observers ?? []) {
|
|
744
570
|
try {
|
|
745
571
|
o?.disconnect?.();
|
|
746
572
|
} catch (e) {
|
|
747
573
|
console.error("[SWC] observer disconnect error:", e);
|
|
748
574
|
}
|
|
749
575
|
}
|
|
750
|
-
|
|
751
|
-
lightMutationObserver = null;
|
|
752
|
-
resizeObserver = null;
|
|
753
|
-
resizeObservers = [];
|
|
754
|
-
for (const cb of removeObserverCallbacks) {
|
|
755
|
-
try {
|
|
756
|
-
cb.fn(cb.target, cb.opts);
|
|
757
|
-
} catch (e) {
|
|
758
|
-
console.error("[SWC] removeObserver error:", e);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
removeObserverCallbacks = [];
|
|
576
|
+
this.__swc_observers = [];
|
|
762
577
|
new import_core_web.ElementApply(this, { id: this._swcId }).removeAllEventListener();
|
|
763
578
|
if (originalDisconnected) originalDisconnected.apply(this);
|
|
764
|
-
const
|
|
765
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
579
|
+
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
766
580
|
this._executeSwcScript("swc-on-disconnected", helperHostSet);
|
|
767
581
|
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
768
582
|
this.__swc_connected = false;
|
|
@@ -771,35 +585,34 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
771
585
|
proto.adoptedCallback = function() {
|
|
772
586
|
const hostSet = import_Utils.SwcUtils.getHostSet(this);
|
|
773
587
|
this._executeSwcScript("swc-on-before-adopted", hostSet);
|
|
774
|
-
const
|
|
775
|
-
for (const
|
|
588
|
+
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?.(helperHostSet);
|
|
776
590
|
if (originalAdopted) originalAdopted.apply(this);
|
|
777
|
-
const
|
|
778
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
591
|
+
for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
779
592
|
this._executeSwcScript("swc-on-adopted", hostSet);
|
|
780
593
|
this._executeSwcScript("swc-on-after-adopted", hostSet);
|
|
781
594
|
};
|
|
782
595
|
const originalAttributeChanged = proto.attributeChangedCallback;
|
|
783
596
|
proto.attributeChangedCallback = function(name2, old, newVal) {
|
|
784
597
|
if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
|
|
785
|
-
const
|
|
598
|
+
const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
786
599
|
let processedVal = newVal;
|
|
787
600
|
if (newVal !== null) {
|
|
788
601
|
const ae = new import_core.ActionExpression(newVal);
|
|
789
602
|
const expr = ae.getFirstExpression("callReturn");
|
|
790
603
|
if (expr) {
|
|
791
604
|
const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
|
|
792
|
-
const
|
|
605
|
+
const exprHelperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win2, this);
|
|
793
606
|
const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
794
607
|
try {
|
|
795
608
|
const result = import_core.FunctionUtils.executeReturn({
|
|
796
609
|
script,
|
|
797
610
|
context: this,
|
|
798
|
-
args:
|
|
611
|
+
args: exprHelperAndHostSet
|
|
799
612
|
});
|
|
800
613
|
processedVal = result;
|
|
801
614
|
} catch (e) {
|
|
802
|
-
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${
|
|
615
|
+
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${exprHelperAndHostSet}`, e);
|
|
803
616
|
processedVal = newVal;
|
|
804
617
|
}
|
|
805
618
|
}
|
|
@@ -810,20 +623,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
810
623
|
this._bindAttributeEvent(this, name2, newVal, eventName);
|
|
811
624
|
}
|
|
812
625
|
}
|
|
813
|
-
const
|
|
814
|
-
if (hostCustomEventMeta && newVal !== null) {
|
|
815
|
-
this._bindAttributeEvent(this, name2, newVal, hostCustomEventMeta.type);
|
|
816
|
-
}
|
|
817
|
-
const metaList = attrChangeMap.get(name2);
|
|
818
|
-
if (metaList && Array.isArray(metaList)) {
|
|
819
|
-
for (const meta of metaList) {
|
|
820
|
-
if (meta.options.while === "connected" && !this.__swc_connected) {
|
|
821
|
-
continue;
|
|
822
|
-
}
|
|
823
|
-
const convertedVal = (0, import_changedAttribute.convertAttributeValue)(processedVal, meta.options.type);
|
|
824
|
-
this[meta.propertyKey](convertedVal, old, name2, hSet);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
626
|
+
for (const c of cyclers) c.onAttributeChanged?.(helperAndHostSet, name2, old, processedVal);
|
|
827
627
|
};
|
|
828
628
|
Object.defineProperty(constructor, "observedAttributes", {
|
|
829
629
|
get: () => mergedObservedAttributes,
|