@dooboostore/simple-web-component 1.0.47 → 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 +223 -27
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +412 -16
- 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 +244 -225
- 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 +5 -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 +244 -0
- package/dist/cjs/decorators/mutationObserver.js.map +7 -0
- package/dist/cjs/decorators/query.js +129 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +191 -0
- package/dist/cjs/decorators/resizeObserver.js.map +7 -0
- 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/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- 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 +413 -16
- 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 +249 -230
- 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 +5 -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 +226 -0
- package/dist/esm/decorators/mutationObserver.js.map +7 -0
- package/dist/esm/decorators/query.js +129 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +173 -0
- package/dist/esm/decorators/resizeObserver.js.map +7 -0
- 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/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2413 -889
- 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 +93 -23
- 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.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 +5 -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 +46 -0
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +63 -8
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +48 -0
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -0
- 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/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- 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 +2413 -889
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +426 -23
- 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 +301 -317
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +5 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +304 -0
- package/src/decorators/query.ts +182 -117
- package/src/decorators/resizeObserver.ts +235 -0
- 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/examples/RxJSOperatorsExample.ts +279 -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/cjs/elements/tt/SwcAppMixin.js +0 -1
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsync.js +0 -1
- package/dist/cjs/elements/tt/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChoose.js +0 -1
- package/dist/cjs/elements/tt/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIf.js +0 -1
- package/dist/cjs/elements/tt/SwcIf.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoop.js +0 -1
- package/dist/cjs/elements/tt/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/tt/register.js +0 -1
- package/dist/cjs/elements/tt/register.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/elements/tt/SwcAppMixin.js +0 -1
- package/dist/esm/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsync.js +0 -1
- package/dist/esm/elements/tt/SwcAsync.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcChoose.js +0 -1
- package/dist/esm/elements/tt/SwcChoose.js.map +0 -7
- package/dist/esm/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcIf.js +0 -1
- package/dist/esm/elements/tt/SwcIf.js.map +0 -7
- package/dist/esm/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoop.js +0 -1
- package/dist/esm/elements/tt/SwcLoop.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/tt/register.js +0 -1
- package/dist/esm/elements/tt/register.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/tt/register.d.ts +0 -1
- package/dist/types/elements/tt/register.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/elements/tt/SwcAppMixin.ts +0 -13
- package/src/elements/tt/SwcAsync.ts +0 -139
- package/src/elements/tt/SwcAsyncTemplate.ts +0 -126
- package/src/elements/tt/SwcChoose.ts +0 -182
- package/src/elements/tt/SwcChooseTemplate.ts +0 -229
- package/src/elements/tt/SwcIf.ts +0 -145
- package/src/elements/tt/SwcIfTemplate.ts +0 -158
- package/src/elements/tt/SwcLoop.ts +0 -222
- package/src/elements/tt/SwcLoopTemplate.ts +0 -255
- package/src/elements/tt/SwcSubTemplates.ts +0 -6
- package/src/elements/tt/register.ts +0 -720
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ActionExpression, FunctionUtils, ReflectUtils
|
|
2
|
-
import {
|
|
3
|
-
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";
|
|
4
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";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { findAllAttributeApplyMetadata, findAllAttributeMetadata
|
|
8
|
-
import { getQueryMetadata } from "./query.js";
|
|
9
|
-
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";
|
|
10
11
|
import { SwcUtils } from "../utils/Utils.js";
|
|
11
12
|
import { DOM_EVENT_NAMES, HTML_TAG_ENTRIES } from "../config/config.js";
|
|
12
13
|
import { SituationTypeContainer, SituationTypeContainers } from "@dooboostore/simple-boot/decorators/inject/Inject";
|
|
@@ -15,6 +16,10 @@ import { ConvertUtils, ElementApply } from "@dooboostore/core-web";
|
|
|
15
16
|
import { isSSR } from "../elements/SwcAppMixin.js";
|
|
16
17
|
import { findAllStateMetadata } from "./state.js";
|
|
17
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";
|
|
18
23
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
19
24
|
const getElementConfig = (target) => {
|
|
20
25
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -24,7 +29,6 @@ const ensureInit = (inst) => {
|
|
|
24
29
|
if (!inst.__swc_initialized) {
|
|
25
30
|
inst._swcId = inst?.getAttribute?.("swc-use-ssr") ?? "s" + Math.random().toString(36).substring(2, 11).toLowerCase();
|
|
26
31
|
inst._emitHandlers = /* @__PURE__ */ new Map();
|
|
27
|
-
inst._boundListeners = [];
|
|
28
32
|
inst.__swc_initialized = true;
|
|
29
33
|
const target = inst instanceof Function ? inst : inst.constructor;
|
|
30
34
|
const attributeAllList = findAllAttributeMetadata(target).filter((it) => it.type === "property");
|
|
@@ -223,10 +227,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
223
227
|
}
|
|
224
228
|
metadata.extends = extendsTagName;
|
|
225
229
|
}
|
|
226
|
-
const emitCustomEventList = getEmitCustomEventMetadataList(constructor) || [];
|
|
227
|
-
const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
|
|
228
|
-
const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
|
|
229
|
-
const attrChangeMap = findAllAttributeChangedMetadata(constructor);
|
|
230
230
|
const attributeList = findAllAttributeMetadata(constructor);
|
|
231
231
|
const applyAttributeMap = findAllAttributeApplyMetadata(constructor);
|
|
232
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"];
|
|
@@ -234,10 +234,222 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
234
234
|
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
|
|
235
235
|
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
|
|
236
236
|
const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
|
|
237
|
-
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
238
237
|
const proto = constructor.prototype;
|
|
239
238
|
setupPrototype(proto, win);
|
|
240
239
|
let helperHostSet = null;
|
|
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
|
+
};
|
|
241
453
|
const originalConnected = proto.connectedCallback;
|
|
242
454
|
proto.connectedCallback = async function() {
|
|
243
455
|
ensureInit(this);
|
|
@@ -253,14 +465,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
253
465
|
}
|
|
254
466
|
const conf = getElementConfig(this);
|
|
255
467
|
const currentWin = this._resolveWindow(conf);
|
|
256
|
-
const
|
|
257
|
-
for (const m of bMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
468
|
+
for (const m of findAllOnConnectedBeforeMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
258
469
|
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
259
470
|
const targetConnectedList = useSsr ? [] : findAllOnConnectedMetadata(constructor);
|
|
260
471
|
const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
261
472
|
if (shadowMode && !this.shadowRoot) {
|
|
262
473
|
const mode = shadowMode === true ? "open" : shadowMode;
|
|
263
|
-
console.log("tagName=", this.tagName, "mode", mode, this.shadowRoot);
|
|
264
474
|
this.attachShadow({ mode });
|
|
265
475
|
}
|
|
266
476
|
const stateContext = { ...helperHostSet };
|
|
@@ -269,7 +479,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
269
479
|
});
|
|
270
480
|
const shadowChildren = [];
|
|
271
481
|
const lightChildren = [];
|
|
272
|
-
console.log("targetConnectList", this.tagName, targetConnectedList.length);
|
|
273
482
|
if (targetConnectedList.length > 0) {
|
|
274
483
|
for (const meta of targetConnectedList) {
|
|
275
484
|
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
@@ -310,188 +519,14 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
310
519
|
});
|
|
311
520
|
globalDelegatedRoots.add(root);
|
|
312
521
|
}
|
|
313
|
-
|
|
314
|
-
const nonDelegateListeners = [];
|
|
315
|
-
addEventListenerList.forEach((meta) => {
|
|
316
|
-
const isStringSelector = typeof meta.selector === "string";
|
|
317
|
-
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 !== "") {
|
|
318
|
-
delegateListeners.push(meta);
|
|
319
|
-
} else {
|
|
320
|
-
nonDelegateListeners.push(meta);
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
|
|
324
|
-
delegateListeners.forEach((meta) => {
|
|
325
|
-
const r = meta.options.root || "auto";
|
|
326
|
-
const rootKey = `${meta.type}:${r}`;
|
|
327
|
-
if (!delegatesByTypeAndRoot.has(rootKey)) {
|
|
328
|
-
delegatesByTypeAndRoot.set(rootKey, []);
|
|
329
|
-
}
|
|
330
|
-
delegatesByTypeAndRoot.get(rootKey).push(meta);
|
|
331
|
-
});
|
|
332
|
-
delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
|
|
333
|
-
const [type, rStr] = typeRootKey.split(":");
|
|
334
|
-
const r = rStr === "auto" ? "auto" : rStr;
|
|
335
|
-
const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
|
|
336
|
-
const bindRoots = [];
|
|
337
|
-
if (r === "auto") bindRoots.push(this.shadowRoot || this);
|
|
338
|
-
else if (r === "light") bindRoots.push(this);
|
|
339
|
-
else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
340
|
-
else if (r === "all") {
|
|
341
|
-
bindRoots.push(this);
|
|
342
|
-
if (this.shadowRoot) bindRoots.push(this.shadowRoot);
|
|
343
|
-
}
|
|
344
|
-
bindRoots.forEach((br) => {
|
|
345
|
-
const sortedMetaList = [...metaList].sort((a, b) => {
|
|
346
|
-
const aStop = a.options.stopPropagation ? 1 : 0;
|
|
347
|
-
const bStop = b.options.stopPropagation ? 1 : 0;
|
|
348
|
-
return bStop - aStop;
|
|
349
|
-
});
|
|
350
|
-
const unifiedHandler = async (event) => {
|
|
351
|
-
for (const meta of sortedMetaList) {
|
|
352
|
-
const { selector, options } = meta;
|
|
353
|
-
const matchedEl = event.target?.closest(selector);
|
|
354
|
-
if (matchedEl && br.contains(matchedEl)) {
|
|
355
|
-
if (options.filter) {
|
|
356
|
-
const helper = SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
|
|
357
|
-
if (!options.filter(event, helper)) {
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
362
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
363
|
-
if (options.preventDefault) event.preventDefault();
|
|
364
|
-
const currentHostSet = SwcUtils.getHostSet(this);
|
|
365
|
-
const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
|
|
366
|
-
await this[meta.propertyKey](event, { ...currentHostSet, $matchedElement: matchedEl }, args);
|
|
367
|
-
if (event.cancelBubble) break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
br.addEventListener(type, unifiedHandler, opts);
|
|
372
|
-
this._boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts });
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
nonDelegateListeners.forEach((meta) => {
|
|
376
|
-
const { selector, type, options } = meta;
|
|
377
|
-
const opts = { capture: options.capture, once: options.once, passive: options.passive };
|
|
378
|
-
const bindTargets = [];
|
|
379
|
-
const r = options.root || "auto";
|
|
380
|
-
let resolvedSelector = null;
|
|
381
|
-
if (typeof selector === "function") {
|
|
382
|
-
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
|
|
383
|
-
const result = selector(this, hostSet);
|
|
384
|
-
if (typeof result === "string") {
|
|
385
|
-
resolvedSelector = result;
|
|
386
|
-
} else if (result instanceof currentWin.Element) {
|
|
387
|
-
bindTargets.push(result);
|
|
388
|
-
} else if (result instanceof currentWin.NodeList) {
|
|
389
|
-
bindTargets.push(...Array.from(result));
|
|
390
|
-
} else if (Array.isArray(result)) {
|
|
391
|
-
bindTargets.push(...result);
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
resolvedSelector = selector;
|
|
395
|
-
}
|
|
396
|
-
const applyRootOption = (target) => {
|
|
397
|
-
if (!target) return;
|
|
398
|
-
if (r === "auto") {
|
|
399
|
-
bindTargets.push(target.shadowRoot || target);
|
|
400
|
-
} else {
|
|
401
|
-
if (r === "light" || r === "all") bindTargets.push(target);
|
|
402
|
-
if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
if (resolvedSelector) {
|
|
406
|
-
if (resolvedSelector === "$window") bindTargets.push(currentWin);
|
|
407
|
-
else if (resolvedSelector === "$document") bindTargets.push(currentWin.document);
|
|
408
|
-
else if (resolvedSelector === "$host") applyRootOption(helperHostSet.$host);
|
|
409
|
-
else if (resolvedSelector === "$parentHost") applyRootOption(helperHostSet.$parentHost);
|
|
410
|
-
else if (resolvedSelector === "$appHost") applyRootOption(helperHostSet.$appHost);
|
|
411
|
-
else if (resolvedSelector === "$firstHost") applyRootOption(helperHostSet.$firstHost);
|
|
412
|
-
else if (resolvedSelector === "$lastHost") applyRootOption(helperHostSet.$lastHost);
|
|
413
|
-
else if (resolvedSelector === "$firstAppHost") applyRootOption(helperHostSet.$firstAppHost);
|
|
414
|
-
else if (resolvedSelector === "$lastAppHost") applyRootOption(helperHostSet.$lastAppHost);
|
|
415
|
-
else if (resolvedSelector === "$hosts") helperHostSet.$hosts.forEach(applyRootOption);
|
|
416
|
-
else if (resolvedSelector === "$appHosts") helperHostSet.$appHosts.forEach(applyRootOption);
|
|
417
|
-
else if (resolvedSelector === "$this" || !resolvedSelector) applyRootOption(this);
|
|
418
|
-
else {
|
|
419
|
-
const searchRoots = [];
|
|
420
|
-
if (r === "auto") searchRoots.push(this.shadowRoot || this);
|
|
421
|
-
else if (r === "light") searchRoots.push(this);
|
|
422
|
-
else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
423
|
-
else if (r === "all") {
|
|
424
|
-
searchRoots.push(this);
|
|
425
|
-
if (this.shadowRoot) searchRoots.push(this.shadowRoot);
|
|
426
|
-
}
|
|
427
|
-
searchRoots.forEach((sr) => {
|
|
428
|
-
sr.querySelectorAll(resolvedSelector).forEach((el) => bindTargets.push(el));
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
bindTargets.forEach((t) => {
|
|
433
|
-
const handler = async (event) => {
|
|
434
|
-
if (options.filter) {
|
|
435
|
-
const helper = SwcUtils.getHelperAndHostSet(currentWin, t);
|
|
436
|
-
if (!options.filter(event, { currentThis: this, helper })) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
if (options.stopPropagation) event.stopPropagation();
|
|
441
|
-
if (options.stopImmediatePropagation) event.stopImmediatePropagation();
|
|
442
|
-
if (options.preventDefault) event.preventDefault();
|
|
443
|
-
const currentHostSet = SwcUtils.getHostSet(this);
|
|
444
|
-
const args = { event, ...currentHostSet, $el: t, $root: t };
|
|
445
|
-
await this[meta.propertyKey](event, { currentHostSet, $matchedElement: event.currentTarget }, args);
|
|
446
|
-
};
|
|
447
|
-
const eventSubject = new Subject();
|
|
448
|
-
let eventStream = eventSubject;
|
|
449
|
-
if (options.debounceTime !== void 0 && options.debounceTime > 0) {
|
|
450
|
-
eventStream = eventStream.pipe(debounceTime(options.debounceTime));
|
|
451
|
-
}
|
|
452
|
-
if (options.throttleTime !== void 0 && options.throttleTime > 0) {
|
|
453
|
-
eventStream = eventStream.pipe(throttleTime(options.throttleTime));
|
|
454
|
-
}
|
|
455
|
-
if (options.distinctUntilChanged !== void 0 && options.distinctUntilChanged !== false) {
|
|
456
|
-
if (typeof options.distinctUntilChanged === "function") {
|
|
457
|
-
eventStream = eventStream.pipe(distinctUntilChanged(options.distinctUntilChanged));
|
|
458
|
-
} else {
|
|
459
|
-
eventStream = eventStream.pipe(distinctUntilChanged());
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
const subscription = eventStream.subscribe({
|
|
463
|
-
next: (event) => {
|
|
464
|
-
handler(event).catch((err) => console.error("Event handler error:", err));
|
|
465
|
-
},
|
|
466
|
-
error: (err) => console.error("Event stream error:", err)
|
|
467
|
-
});
|
|
468
|
-
const wrappedHandler = (event) => {
|
|
469
|
-
eventSubject.next(event);
|
|
470
|
-
};
|
|
471
|
-
t.addEventListener(type, wrappedHandler, opts);
|
|
472
|
-
this._boundListeners.push({ target: t, type, handler: wrappedHandler, options: opts, subscription });
|
|
473
|
-
});
|
|
474
|
-
});
|
|
522
|
+
await buildObservers(SwcUtils.getHelperAndHostSet(win, this));
|
|
475
523
|
if (originalConnected) await originalConnected.apply(this);
|
|
476
|
-
const
|
|
477
|
-
for (const m of aMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
524
|
+
for (const m of findAllOnConnectedAfterMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
478
525
|
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
479
526
|
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
480
527
|
this.__swc_connected = true;
|
|
481
|
-
for (let [name2, metaList] of Array.from(attrChangeMap)) {
|
|
482
|
-
for (const meta of metaList) {
|
|
483
|
-
if (meta.options.while === "connected") {
|
|
484
|
-
const val = getAttributeValue(this, name2, { type: meta.options.type });
|
|
485
|
-
if (val !== null) {
|
|
486
|
-
await this[meta.propertyKey](val, null, name2, helperHostSet);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
528
|
} finally {
|
|
492
|
-
for (
|
|
493
|
-
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
494
|
-
}
|
|
529
|
+
for (const m of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
495
530
|
if (appHost && typeof appHost._connectedDone === "function") {
|
|
496
531
|
await appHost._connectedDone(this);
|
|
497
532
|
}
|
|
@@ -499,26 +534,24 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
499
534
|
};
|
|
500
535
|
const originalDisconnected = proto.disconnectedCallback;
|
|
501
536
|
proto.disconnectedCallback = function() {
|
|
502
|
-
const appHost = helperHostSet
|
|
537
|
+
const appHost = helperHostSet?.$appHost;
|
|
503
538
|
if (appHost && typeof appHost._disconnected === "function") {
|
|
504
539
|
appHost._disconnected(this);
|
|
505
540
|
}
|
|
506
541
|
this._executeSwcScript("swc-on-before-disconnected", helperHostSet);
|
|
507
|
-
const
|
|
508
|
-
for (const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
});
|
|
516
|
-
this._boundListeners = [];
|
|
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 ?? []) {
|
|
545
|
+
try {
|
|
546
|
+
o?.disconnect?.();
|
|
547
|
+
} catch (e) {
|
|
548
|
+
console.error("[SWC] observer disconnect error:", e);
|
|
549
|
+
}
|
|
517
550
|
}
|
|
551
|
+
this.__swc_observers = [];
|
|
518
552
|
new ElementApply(this, { id: this._swcId }).removeAllEventListener();
|
|
519
553
|
if (originalDisconnected) originalDisconnected.apply(this);
|
|
520
|
-
const
|
|
521
|
-
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);
|
|
522
555
|
this._executeSwcScript("swc-on-disconnected", helperHostSet);
|
|
523
556
|
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
524
557
|
this.__swc_connected = false;
|
|
@@ -527,35 +560,34 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
527
560
|
proto.adoptedCallback = function() {
|
|
528
561
|
const hostSet = SwcUtils.getHostSet(this);
|
|
529
562
|
this._executeSwcScript("swc-on-before-adopted", hostSet);
|
|
530
|
-
const
|
|
531
|
-
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);
|
|
532
565
|
if (originalAdopted) originalAdopted.apply(this);
|
|
533
|
-
const
|
|
534
|
-
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);
|
|
535
567
|
this._executeSwcScript("swc-on-adopted", hostSet);
|
|
536
568
|
this._executeSwcScript("swc-on-after-adopted", hostSet);
|
|
537
569
|
};
|
|
538
570
|
const originalAttributeChanged = proto.attributeChangedCallback;
|
|
539
571
|
proto.attributeChangedCallback = function(name2, old, newVal) {
|
|
540
572
|
if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
|
|
541
|
-
const
|
|
573
|
+
const helperAndHostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
542
574
|
let processedVal = newVal;
|
|
543
575
|
if (newVal !== null) {
|
|
544
576
|
const ae = new ActionExpression(newVal);
|
|
545
577
|
const expr = ae.getFirstExpression("callReturn");
|
|
546
578
|
if (expr) {
|
|
547
579
|
const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
|
|
548
|
-
const
|
|
580
|
+
const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(win2, this);
|
|
549
581
|
const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
550
582
|
try {
|
|
551
583
|
const result = FunctionUtils.executeReturn({
|
|
552
584
|
script,
|
|
553
585
|
context: this,
|
|
554
|
-
args:
|
|
586
|
+
args: exprHelperAndHostSet
|
|
555
587
|
});
|
|
556
588
|
processedVal = result;
|
|
557
589
|
} catch (e) {
|
|
558
|
-
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);
|
|
559
591
|
processedVal = newVal;
|
|
560
592
|
}
|
|
561
593
|
}
|
|
@@ -566,20 +598,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
566
598
|
this._bindAttributeEvent(this, name2, newVal, eventName);
|
|
567
599
|
}
|
|
568
600
|
}
|
|
569
|
-
const
|
|
570
|
-
if (hostCustomEventMeta && newVal !== null) {
|
|
571
|
-
this._bindAttributeEvent(this, name2, newVal, hostCustomEventMeta.type);
|
|
572
|
-
}
|
|
573
|
-
const metaList = attrChangeMap.get(name2);
|
|
574
|
-
if (metaList && Array.isArray(metaList)) {
|
|
575
|
-
for (const meta of metaList) {
|
|
576
|
-
if (meta.options.while === "connected" && !this.__swc_connected) {
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
const convertedVal = convertAttributeValue(processedVal, meta.options.type);
|
|
580
|
-
this[meta.propertyKey](convertedVal, old, name2, hSet);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
601
|
+
for (const c of cyclers) c.onAttributeChanged?.(helperAndHostSet, name2, old, processedVal);
|
|
583
602
|
};
|
|
584
603
|
Object.defineProperty(constructor, "observedAttributes", {
|
|
585
604
|
get: () => mergedObservedAttributes,
|