@dooboostore/simple-web-component 1.0.48 → 1.0.50
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 +189 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +2373 -30
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +31 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +55 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +73 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +107 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +6 -5
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +42 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +61 -13
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +254 -439
- 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/eventMedia.js +84 -0
- package/dist/cjs/decorators/eventMedia.js.map +7 -0
- package/dist/cjs/decorators/index.js +6 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +200 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +186 -55
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/parameter.js +73 -0
- package/dist/cjs/decorators/parameter.js.map +7 -0
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +124 -0
- package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/cjs/decorators/resizeObserver.js +133 -55
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +114 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +117 -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/elements/SwcAppMixin.js +19 -3
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/window.d.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 +2374 -30
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +31 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +55 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +73 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +107 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +6 -5
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +42 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +62 -13
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +261 -446
- 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/eventMedia.js +66 -0
- package/dist/esm/decorators/eventMedia.js.map +7 -0
- package/dist/esm/decorators/index.js +6 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +182 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +187 -55
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/parameter.js +54 -0
- package/dist/esm/decorators/parameter.js.map +7 -0
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +105 -0
- package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/esm/decorators/resizeObserver.js +134 -55
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +95 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +98 -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/elements/SwcAppMixin.js +20 -4
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4961 -1628
- 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 +1046 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +24 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +36 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +32 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +27 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +12 -3
- 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/eventMedia.d.ts +25 -0
- package/dist/types/decorators/eventMedia.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +6 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +58 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +44 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +35 -0
- package/dist/types/decorators/parameter.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
- package/dist/types/decorators/resizeObserver.d.ts +43 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +41 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +41 -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/elements/SwcAppMixin.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 +4961 -1628
- 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 +1446 -34
- package/src/decorators/applyAttribute.ts +60 -36
- package/src/decorators/applyClass.ts +86 -26
- package/src/decorators/applyNode.ts +124 -36
- package/src/decorators/applyProperty.ts +172 -40
- package/src/decorators/applySlot.ts +6 -5
- package/src/decorators/applyStyle.ts +74 -17
- package/src/decorators/changedAttribute.ts +76 -15
- package/src/decorators/elementDefine.ts +310 -582
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/eventMedia.ts +78 -0
- package/src/decorators/index.ts +6 -1
- package/src/decorators/intersectionObserver.ts +275 -0
- package/src/decorators/mutationObserver.ts +282 -89
- package/src/decorators/parameter.ts +81 -0
- package/src/decorators/query.ts +168 -126
- package/src/decorators/requestAnimationFrame.ts +158 -0
- package/src/decorators/resizeObserver.ts +211 -89
- package/src/decorators/setInterval.ts +136 -0
- package/src/decorators/setTimeout.ts +139 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/elements/SwcAppMixin.ts +20 -5
- package/src/types/index.ts +141 -0
- package/src/types/window.d.ts +2 -18
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
- package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/examples/RxJSOperatorsExample.ts +0 -279
|
@@ -1,22 +1,28 @@
|
|
|
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";
|
|
14
|
+
import { buildSwcParameterArgs, getParameterMetadata } from "./parameter.js";
|
|
15
15
|
import { InjectSituationType } from "../types/index.js";
|
|
16
16
|
import { ConvertUtils, ElementApply } from "@dooboostore/core-web";
|
|
17
17
|
import { isSSR } from "../elements/SwcAppMixin.js";
|
|
18
18
|
import { findAllStateMetadata } from "./state.js";
|
|
19
19
|
import { findAllPropertyMetadata } from "./applyProperty.js";
|
|
20
|
+
import { MessageSubscribeLifeCycler } from "./subscribeSwcAppMessageWhileConnected.js";
|
|
21
|
+
import { RouteSubscribeLifeCycler } from "./subscribeSwcAppRouteChangeWhileConnected.js";
|
|
22
|
+
import { SetIntervalLifeCycler } from "./setInterval.js";
|
|
23
|
+
import { SetTimeoutLifeCycler } from "./setTimeout.js";
|
|
24
|
+
import { RequestAnimationFrameLifeCycler } from "./requestAnimationFrame.js";
|
|
25
|
+
import { EventMediaLifeCycler } from "./eventMedia.js";
|
|
20
26
|
const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
|
|
21
27
|
const getElementConfig = (target) => {
|
|
22
28
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -133,6 +139,9 @@ const setupPrototype = (proto, win) => {
|
|
|
133
139
|
if (typeof this[methodName] !== "function") return;
|
|
134
140
|
const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(win, this);
|
|
135
141
|
const app = useHostSet?.$appHost?.simpleApplication;
|
|
142
|
+
const helperSetValue = SwcUtils.getHelperSet(win);
|
|
143
|
+
const helperHostSetValue = { ...helperSetValue, ...useHostSet, $this: this };
|
|
144
|
+
const kindValues = { hostSet: useHostSet, helperHostSet: helperHostSetValue, helperSet: helperSetValue };
|
|
136
145
|
if (app) {
|
|
137
146
|
const otherStorage = /* @__PURE__ */ new Map();
|
|
138
147
|
const situations = new SituationTypeContainers([new SituationTypeContainer({ situationType: InjectSituationType.HOST_SET, data: useHostSet }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOST, data: useHostSet.$appHost }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOSTS, data: useHostSet.$appHosts }), new SituationTypeContainer({
|
|
@@ -143,16 +152,23 @@ const setupPrototype = (proto, win) => {
|
|
|
143
152
|
data: useHostSet.$firstAppHost
|
|
144
153
|
}), new SituationTypeContainer({ situationType: InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
|
|
145
154
|
otherStorage.set(SituationTypeContainers, situations);
|
|
155
|
+
const firstCheckMaker = ({ target, targetKey }, token, idx) => {
|
|
156
|
+
const saves = getParameterMetadata(target, targetKey);
|
|
157
|
+
const found = saves.find((s) => s.index === idx);
|
|
158
|
+
return found ? kindValues[found.kind] : void 0;
|
|
159
|
+
};
|
|
146
160
|
return app.simstanceManager.executeBindParameterSim(
|
|
147
161
|
{
|
|
148
162
|
target: this,
|
|
149
163
|
targetKey: methodName,
|
|
150
|
-
inputParameters: extraArgs
|
|
164
|
+
inputParameters: extraArgs,
|
|
165
|
+
firstCheckMaker: [firstCheckMaker]
|
|
151
166
|
},
|
|
152
167
|
otherStorage
|
|
153
168
|
);
|
|
154
169
|
} else {
|
|
155
|
-
|
|
170
|
+
const args = buildSwcParameterArgs(this, methodName, kindValues, extraArgs);
|
|
171
|
+
return this[methodName](...args);
|
|
156
172
|
}
|
|
157
173
|
};
|
|
158
174
|
proto._bindAttributeEvent = function(el, attrName, script, eventName) {
|
|
@@ -224,12 +240,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
224
240
|
}
|
|
225
241
|
metadata.extends = extendsTagName;
|
|
226
242
|
}
|
|
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
243
|
const attributeList = findAllAttributeMetadata(constructor);
|
|
234
244
|
const applyAttributeMap = findAllAttributeApplyMetadata(constructor);
|
|
235
245
|
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 +247,227 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
237
247
|
const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
|
|
238
248
|
const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
|
|
239
249
|
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
250
|
const proto = constructor.prototype;
|
|
242
251
|
setupPrototype(proto, win);
|
|
243
252
|
let helperHostSet = null;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
const eventCycler = new EventListenerLifeCycler();
|
|
254
|
+
const cyclers = [
|
|
255
|
+
eventCycler,
|
|
256
|
+
new ChangedAttributeLifeCycler(),
|
|
257
|
+
new EmitCustomEventLifeCycler(),
|
|
258
|
+
new ResizeObserverLifeCycler(),
|
|
259
|
+
new IntersectionObserverLifeCycler(),
|
|
260
|
+
new MutationObserverLifeCycler(),
|
|
261
|
+
new MessageSubscribeLifeCycler(),
|
|
262
|
+
new RouteSubscribeLifeCycler(),
|
|
263
|
+
new SetIntervalLifeCycler(),
|
|
264
|
+
new SetTimeoutLifeCycler(),
|
|
265
|
+
new RequestAnimationFrameLifeCycler(),
|
|
266
|
+
new EventMediaLifeCycler()
|
|
267
|
+
];
|
|
268
|
+
const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
|
|
269
|
+
const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
|
|
270
|
+
const buildObservers = async (helperHostSet2) => {
|
|
271
|
+
const inst = helperHostSet2.$this;
|
|
272
|
+
const observers = [];
|
|
273
|
+
let resizeObserverSet = [];
|
|
274
|
+
let mutationObserverSet = [];
|
|
275
|
+
let intersectionObserverSet = [];
|
|
276
|
+
const resolveDelegateRoots = (delegateRoot) => {
|
|
277
|
+
const r = delegateRoot || "auto";
|
|
278
|
+
const roots = [];
|
|
279
|
+
if (r === "auto") roots.push(inst.shadowRoot || inst);
|
|
280
|
+
else if (r === "light") roots.push(inst);
|
|
281
|
+
else if (r === "shadow" && inst.shadowRoot) roots.push(inst.shadowRoot);
|
|
282
|
+
else if (r === "all") {
|
|
283
|
+
roots.push(inst);
|
|
284
|
+
if (inst.shadowRoot) roots.push(inst.shadowRoot);
|
|
285
|
+
}
|
|
286
|
+
return roots;
|
|
287
|
+
};
|
|
288
|
+
for (const c of cyclers) {
|
|
289
|
+
const result = await c.onConnected?.(helperHostSet2, resizeObserverSet);
|
|
290
|
+
if (!result) continue;
|
|
291
|
+
if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
|
|
292
|
+
if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
|
|
293
|
+
if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
|
|
294
|
+
}
|
|
295
|
+
const resizeDelegates = (resizeObserverSet ?? []).filter((t) => t.delegate && typeof t.target === "string");
|
|
296
|
+
let resizeObserve;
|
|
297
|
+
let resizeUnobserve;
|
|
298
|
+
const resizeObserved = /* @__PURE__ */ new WeakSet();
|
|
299
|
+
if (resizeObserverSet?.length) {
|
|
300
|
+
const roCallbacks = [...new Set(resizeObserverSet.map((e) => e.callback))];
|
|
301
|
+
const ro = new win.ResizeObserver((entries, obs) => {
|
|
302
|
+
for (const cb of roCallbacks) cb(entries, obs);
|
|
303
|
+
});
|
|
304
|
+
for (const e of resizeObserverSet) {
|
|
305
|
+
if (e.delegate) continue;
|
|
306
|
+
if (typeof e.target === "string") {
|
|
307
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
308
|
+
for (const sr of scope) {
|
|
309
|
+
sr.querySelectorAll(e.target).forEach((el) => {
|
|
310
|
+
if (!resizeObserved.has(el)) {
|
|
311
|
+
ro.observe(el, e.options);
|
|
312
|
+
resizeObserved.add(el);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
ro.observe(e.target, e.options);
|
|
319
|
+
if (e.target instanceof Element) resizeObserved.add(e.target);
|
|
320
|
+
}
|
|
321
|
+
resizeObserve = (el, opts) => {
|
|
322
|
+
if (resizeObserved.has(el)) return;
|
|
323
|
+
ro.observe(el, opts);
|
|
324
|
+
resizeObserved.add(el);
|
|
325
|
+
};
|
|
326
|
+
resizeUnobserve = (el) => {
|
|
327
|
+
if (!resizeObserved.has(el)) return;
|
|
328
|
+
ro.unobserve(el);
|
|
329
|
+
resizeObserved.delete(el);
|
|
330
|
+
};
|
|
331
|
+
observers.push(ro);
|
|
332
|
+
}
|
|
333
|
+
const intersectionDelegates = [];
|
|
334
|
+
for (const group of intersectionObserverSet) {
|
|
335
|
+
const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
|
|
336
|
+
const io = new win.IntersectionObserver((entries, obs) => {
|
|
337
|
+
for (const cb of ioCallbacks) cb(entries, obs);
|
|
338
|
+
}, group.options);
|
|
339
|
+
const ioObserved = /* @__PURE__ */ new WeakSet();
|
|
340
|
+
for (const e of group.observeTargets) {
|
|
341
|
+
if (e.delegate) {
|
|
342
|
+
const target = e.target;
|
|
343
|
+
const observe = (el) => {
|
|
344
|
+
if (ioObserved.has(el)) return;
|
|
345
|
+
io.observe(el);
|
|
346
|
+
ioObserved.add(el);
|
|
347
|
+
};
|
|
348
|
+
const unobserve = (el) => {
|
|
349
|
+
if (!ioObserved.has(el)) return;
|
|
350
|
+
io.unobserve(el);
|
|
351
|
+
ioObserved.delete(el);
|
|
352
|
+
};
|
|
353
|
+
intersectionDelegates.push({ target, delegateRoot: e.delegateRoot, observe, unobserve });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (typeof e.target === "string") {
|
|
357
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
358
|
+
for (const sr of scope) {
|
|
359
|
+
sr.querySelectorAll(e.target).forEach((el) => {
|
|
360
|
+
if (!ioObserved.has(el)) {
|
|
361
|
+
io.observe(el);
|
|
362
|
+
ioObserved.add(el);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
io.observe(e.target);
|
|
369
|
+
if (e.target instanceof Element) ioObserved.add(e.target);
|
|
370
|
+
}
|
|
371
|
+
observers.push(io);
|
|
372
|
+
}
|
|
373
|
+
const handleResizeDelegate = (n, observe) => {
|
|
374
|
+
if (!resizeObserve || !resizeUnobserve || n.nodeType !== 1) return;
|
|
375
|
+
const el = n;
|
|
376
|
+
for (const d of resizeDelegates) {
|
|
377
|
+
const isThis = d.target === "$this" || d.target === "";
|
|
378
|
+
const matchesSel = (node) => {
|
|
379
|
+
if (!node || node.nodeType !== 1) return false;
|
|
380
|
+
if (isThis) return true;
|
|
381
|
+
return node.matches?.(d.target) || !!node.closest?.(d.target);
|
|
382
|
+
};
|
|
383
|
+
if (matchesSel(el)) {
|
|
384
|
+
observe ? resizeObserve(el, d.options) : resizeUnobserve(el);
|
|
385
|
+
} else if (!isThis) {
|
|
386
|
+
el.querySelectorAll(d.target).forEach((sub) => {
|
|
387
|
+
observe ? resizeObserve(sub, d.options) : resizeUnobserve(sub);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
const handleIntersectionDelegate = (n, observe) => {
|
|
393
|
+
if (n.nodeType !== 1) return;
|
|
394
|
+
const el = n;
|
|
395
|
+
for (const d of intersectionDelegates) {
|
|
396
|
+
const isThis = d.target === "$this" || d.target === "";
|
|
397
|
+
const matchesSel = (node) => {
|
|
398
|
+
if (!node || node.nodeType !== 1) return false;
|
|
399
|
+
if (isThis) return true;
|
|
400
|
+
return node.matches?.(d.target) || !!node.closest?.(d.target);
|
|
401
|
+
};
|
|
402
|
+
if (matchesSel(el)) {
|
|
403
|
+
observe ? d.observe(el) : d.unobserve(el);
|
|
404
|
+
} else if (!isThis) {
|
|
405
|
+
el.querySelectorAll(d.target).forEach((sub) => {
|
|
406
|
+
observe ? d.observe(sub) : d.unobserve(sub);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
if (mutationObserverSet?.length || resizeDelegates.length > 0 || intersectionDelegates.length > 0) {
|
|
412
|
+
const callbacks = [...new Set((mutationObserverSet ?? []).map((e) => e.callback))];
|
|
413
|
+
const mo = new win.MutationObserver((mutations, obs) => {
|
|
414
|
+
for (const mut of mutations) {
|
|
415
|
+
Array.from(mut.addedNodes || []).forEach((n) => {
|
|
416
|
+
handleResizeDelegate(n, true);
|
|
417
|
+
handleIntersectionDelegate(n, true);
|
|
418
|
+
});
|
|
419
|
+
Array.from(mut.removedNodes || []).forEach((n) => {
|
|
420
|
+
handleResizeDelegate(n, false);
|
|
421
|
+
handleIntersectionDelegate(n, false);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
for (const cb of callbacks) cb(mutations, obs);
|
|
425
|
+
});
|
|
426
|
+
const moObserveTargets = /* @__PURE__ */ new Map();
|
|
427
|
+
const mergeMutationInit = (existing, next) => {
|
|
428
|
+
if (!existing) return next;
|
|
429
|
+
const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
|
|
430
|
+
return {
|
|
431
|
+
childList: existing.childList || next.childList,
|
|
432
|
+
attributes: existing.attributes || next.attributes,
|
|
433
|
+
characterData: existing.characterData || next.characterData,
|
|
434
|
+
subtree: existing.subtree || next.subtree,
|
|
435
|
+
attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
|
|
436
|
+
characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
|
|
437
|
+
attributeFilter: mergedFilter
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
const addObserveTarget = (target, options) => {
|
|
441
|
+
moObserveTargets.set(target, mergeMutationInit(moObserveTargets.get(target), options));
|
|
442
|
+
};
|
|
443
|
+
for (const e of mutationObserverSet ?? []) {
|
|
444
|
+
if (e.delegate) continue;
|
|
445
|
+
const init = e.options ?? { childList: true };
|
|
446
|
+
if (typeof e.target === "string") {
|
|
447
|
+
const scope = resolveDelegateRoots(e.delegateRoot);
|
|
448
|
+
for (const sr of scope) {
|
|
449
|
+
sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
addObserveTarget(e.target, init);
|
|
454
|
+
}
|
|
455
|
+
for (const d of resizeDelegates) {
|
|
456
|
+
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
457
|
+
}
|
|
458
|
+
for (const d of intersectionDelegates) {
|
|
459
|
+
for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
|
|
460
|
+
}
|
|
461
|
+
for (const [target, options] of moObserveTargets) {
|
|
462
|
+
mo.observe(target, options);
|
|
463
|
+
}
|
|
464
|
+
observers.push(mo);
|
|
465
|
+
}
|
|
466
|
+
inst.__swc_observers = observers;
|
|
467
|
+
};
|
|
250
468
|
const originalConnected = proto.connectedCallback;
|
|
251
469
|
proto.connectedCallback = async function() {
|
|
252
470
|
ensureInit(this);
|
|
253
|
-
boundListeners = [];
|
|
254
|
-
resizeObservers = [];
|
|
255
|
-
removeObserverCallbacks = [];
|
|
256
471
|
helperHostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
257
472
|
const appHost = helperHostSet.$appHost;
|
|
258
473
|
const useSsr = isSSR(this);
|
|
@@ -265,14 +480,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
265
480
|
}
|
|
266
481
|
const conf = getElementConfig(this);
|
|
267
482
|
const currentWin = this._resolveWindow(conf);
|
|
268
|
-
const
|
|
269
|
-
for (const m of bMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
483
|
+
for (const m of findAllOnConnectedBeforeMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
270
484
|
this._executeSwcScript("swc-on-before-connected", helperHostSet);
|
|
271
485
|
const targetConnectedList = useSsr ? [] : findAllOnConnectedMetadata(constructor);
|
|
272
486
|
const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
|
|
273
487
|
if (shadowMode && !this.shadowRoot) {
|
|
274
488
|
const mode = shadowMode === true ? "open" : shadowMode;
|
|
275
|
-
console.log("tagName=", this.tagName, "mode", mode, this.shadowRoot);
|
|
276
489
|
this.attachShadow({ mode });
|
|
277
490
|
}
|
|
278
491
|
const stateContext = { ...helperHostSet };
|
|
@@ -281,7 +494,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
281
494
|
});
|
|
282
495
|
const shadowChildren = [];
|
|
283
496
|
const lightChildren = [];
|
|
284
|
-
console.log("targetConnectList", this.tagName, targetConnectedList.length);
|
|
285
497
|
if (targetConnectedList.length > 0) {
|
|
286
498
|
for (const meta of targetConnectedList) {
|
|
287
499
|
let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
|
|
@@ -322,366 +534,14 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
322
534
|
});
|
|
323
535
|
globalDelegatedRoots.add(root);
|
|
324
536
|
}
|
|
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
|
-
}
|
|
537
|
+
await buildObservers(SwcUtils.getHelperAndHostSet(win, this));
|
|
665
538
|
if (originalConnected) await originalConnected.apply(this);
|
|
666
|
-
const
|
|
667
|
-
for (const m of aMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
539
|
+
for (const m of findAllOnConnectedAfterMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
668
540
|
this._executeSwcScript("swc-on-connected", helperHostSet);
|
|
669
541
|
this._executeSwcScript("swc-on-after-connected", helperHostSet);
|
|
670
542
|
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
543
|
} finally {
|
|
682
|
-
for (
|
|
683
|
-
await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
684
|
-
}
|
|
544
|
+
for (const m of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
685
545
|
if (appHost && typeof appHost._connectedDone === "function") {
|
|
686
546
|
await appHost._connectedDone(this);
|
|
687
547
|
}
|
|
@@ -689,55 +549,24 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
689
549
|
};
|
|
690
550
|
const originalDisconnected = proto.disconnectedCallback;
|
|
691
551
|
proto.disconnectedCallback = function() {
|
|
692
|
-
const appHost = helperHostSet
|
|
552
|
+
const appHost = helperHostSet?.$appHost;
|
|
693
553
|
if (appHost && typeof appHost._disconnected === "function") {
|
|
694
554
|
appHost._disconnected(this);
|
|
695
555
|
}
|
|
696
556
|
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) {
|
|
557
|
+
for (const m of findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
558
|
+
for (const c of cyclers) c.onDisconnected?.(helperHostSet);
|
|
559
|
+
for (const o of this.__swc_observers ?? []) {
|
|
719
560
|
try {
|
|
720
561
|
o?.disconnect?.();
|
|
721
562
|
} catch (e) {
|
|
722
563
|
console.error("[SWC] observer disconnect error:", e);
|
|
723
564
|
}
|
|
724
565
|
}
|
|
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 = [];
|
|
566
|
+
this.__swc_observers = [];
|
|
737
567
|
new ElementApply(this, { id: this._swcId }).removeAllEventListener();
|
|
738
568
|
if (originalDisconnected) originalDisconnected.apply(this);
|
|
739
|
-
const
|
|
740
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
569
|
+
for (const m of findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
|
|
741
570
|
this._executeSwcScript("swc-on-disconnected", helperHostSet);
|
|
742
571
|
this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
|
|
743
572
|
this.__swc_connected = false;
|
|
@@ -746,35 +575,34 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
746
575
|
proto.adoptedCallback = function() {
|
|
747
576
|
const hostSet = SwcUtils.getHostSet(this);
|
|
748
577
|
this._executeSwcScript("swc-on-before-adopted", hostSet);
|
|
749
|
-
const
|
|
750
|
-
for (const
|
|
578
|
+
for (const m of findAllLifecycleMetadata(this, ON_BEFORE_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
579
|
+
for (const c of cyclers) c.onAdopted?.(helperHostSet);
|
|
751
580
|
if (originalAdopted) originalAdopted.apply(this);
|
|
752
|
-
const
|
|
753
|
-
for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
581
|
+
for (const m of findAllLifecycleMetadata(this, ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
|
|
754
582
|
this._executeSwcScript("swc-on-adopted", hostSet);
|
|
755
583
|
this._executeSwcScript("swc-on-after-adopted", hostSet);
|
|
756
584
|
};
|
|
757
585
|
const originalAttributeChanged = proto.attributeChangedCallback;
|
|
758
586
|
proto.attributeChangedCallback = function(name2, old, newVal) {
|
|
759
587
|
if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
|
|
760
|
-
const
|
|
588
|
+
const helperAndHostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
761
589
|
let processedVal = newVal;
|
|
762
590
|
if (newVal !== null) {
|
|
763
591
|
const ae = new ActionExpression(newVal);
|
|
764
592
|
const expr = ae.getFirstExpression("callReturn");
|
|
765
593
|
if (expr) {
|
|
766
594
|
const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
|
|
767
|
-
const
|
|
595
|
+
const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(win2, this);
|
|
768
596
|
const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
|
|
769
597
|
try {
|
|
770
598
|
const result = FunctionUtils.executeReturn({
|
|
771
599
|
script,
|
|
772
600
|
context: this,
|
|
773
|
-
args:
|
|
601
|
+
args: exprHelperAndHostSet
|
|
774
602
|
});
|
|
775
603
|
processedVal = result;
|
|
776
604
|
} catch (e) {
|
|
777
|
-
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${
|
|
605
|
+
console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${exprHelperAndHostSet}`, e);
|
|
778
606
|
processedVal = newVal;
|
|
779
607
|
}
|
|
780
608
|
}
|
|
@@ -785,20 +613,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
|
|
|
785
613
|
this._bindAttributeEvent(this, name2, newVal, eventName);
|
|
786
614
|
}
|
|
787
615
|
}
|
|
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
|
-
}
|
|
616
|
+
for (const c of cyclers) c.onAttributeChanged?.(helperAndHostSet, name2, old, processedVal);
|
|
802
617
|
};
|
|
803
618
|
Object.defineProperty(constructor, "observedAttributes", {
|
|
804
619
|
get: () => mergedObservedAttributes,
|