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