@dooboostore/simple-web-component 1.0.48 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +387 -29
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +237 -437
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +140 -0
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +87 -0
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +388 -29
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +244 -444
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +141 -0
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +88 -0
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2565 -1474
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +84 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +0 -14
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +35 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +34 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2565 -1474
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -5
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +394 -34
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +281 -580
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +3 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +215 -39
- package/src/decorators/query.ts +168 -126
- package/src/decorators/resizeObserver.ts +152 -46
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
+
import { ElementDefineLifeCycler, HelperHostSet } from '../types';
|
|
3
|
+
|
|
4
|
+
export const SET_INTERVAL_METADATA_KEY = Symbol.for('simple-web-component:set-interval');
|
|
5
|
+
|
|
6
|
+
export interface SetIntervalOptions {
|
|
7
|
+
/** 매 tick마다 데코레이트된 메서드에 넘길 인자를 계산. 없으면 인자 없이 호출. */
|
|
8
|
+
parameter?: (set: HelperHostSet) => any[];
|
|
9
|
+
/** 타이머 등록 직후 1회 호출 (디버깅/로깅용). id는 실제 setInterval 반환값 - cleanup은 자동으로 처리되므로 직접 clear할 필요 없음. */
|
|
10
|
+
created?: (set: HelperHostSet, id: number) => void;
|
|
11
|
+
/**
|
|
12
|
+
* 매 tick마다 데코레이트된 메서드의 리턴값이 객체이고 이 키의 값이 함수이면 (id: number)로 호출한다.
|
|
13
|
+
* applyAttribute.ts의 valueKey와 동일한 컨벤션 - 리턴 객체에서 이 데코레이터 몫만 뽑아 쓴다.
|
|
14
|
+
*/
|
|
15
|
+
valueKey?: symbol | string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SetIntervalMetadata {
|
|
19
|
+
propertyKey: string | symbol;
|
|
20
|
+
interval: number;
|
|
21
|
+
options: SetIntervalOptions;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* connect 시 자동으로 setInterval을 걸고, disconnect 시 자동으로 clearInterval 한다.
|
|
26
|
+
*/
|
|
27
|
+
export function setInterval(interval: number, options: SetIntervalOptions = {}): MethodDecorator {
|
|
28
|
+
return (target: Object, propertyKey: string | symbol) => {
|
|
29
|
+
const constructor = target.constructor;
|
|
30
|
+
let metaList = ReflectUtils.getOwnMetadata(SET_INTERVAL_METADATA_KEY, constructor) as SetIntervalMetadata[];
|
|
31
|
+
if (!metaList) {
|
|
32
|
+
metaList = [];
|
|
33
|
+
ReflectUtils.defineMetadata(SET_INTERVAL_METADATA_KEY, metaList, constructor);
|
|
34
|
+
}
|
|
35
|
+
metaList.push({ propertyKey, interval, options });
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const findAllSetIntervalMetadata = (target: any): SetIntervalMetadata[] => {
|
|
40
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
41
|
+
return (ReflectUtils.findAllMetadata<SetIntervalMetadata[]>(SET_INTERVAL_METADATA_KEY, constructor) || []).flat();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class SetIntervalLifeCycler implements ElementDefineLifeCycler {
|
|
45
|
+
private readonly activeMap = new WeakMap<any, number[]>();
|
|
46
|
+
|
|
47
|
+
onConnected(helperHostSet: HelperHostSet): void {
|
|
48
|
+
const inst = helperHostSet.$this;
|
|
49
|
+
const ids: number[] = [];
|
|
50
|
+
for (const meta of findAllSetIntervalMetadata(inst)) {
|
|
51
|
+
const id = helperHostSet.$w.setInterval(() => {
|
|
52
|
+
const args = meta.options.parameter?.(helperHostSet) ?? [];
|
|
53
|
+
try {
|
|
54
|
+
const res = inst[meta.propertyKey](...args);
|
|
55
|
+
const vk = meta.options.valueKey;
|
|
56
|
+
if (vk && res && typeof res === 'object' && typeof res[vk] === 'function') {
|
|
57
|
+
res[vk](id);
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error('[SWC] setInterval tick error:', e);
|
|
61
|
+
}
|
|
62
|
+
}, meta.interval);
|
|
63
|
+
meta.options.created?.(helperHostSet, id);
|
|
64
|
+
ids.push(id);
|
|
65
|
+
}
|
|
66
|
+
this.activeMap.set(inst, ids);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onDisconnected(helperHostSet: HelperHostSet): void {
|
|
70
|
+
const inst = helperHostSet.$this;
|
|
71
|
+
for (const id of this.activeMap.get(inst) ?? []) {
|
|
72
|
+
try {
|
|
73
|
+
helperHostSet.$w.clearInterval(id);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error('[SWC] clearInterval error:', e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.activeMap.delete(inst);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ReflectUtils } from '@dooboostore/core';
|
|
2
|
+
import { ElementDefineLifeCycler, HelperHostSet } from '../types';
|
|
3
|
+
|
|
4
|
+
export const SET_TIMEOUT_METADATA_KEY = Symbol.for('simple-web-component:set-timeout');
|
|
5
|
+
|
|
6
|
+
export interface SetTimeoutOptions {
|
|
7
|
+
/** 실행 시 데코레이트된 메서드에 넘길 인자를 계산. 없으면 인자 없이 호출. */
|
|
8
|
+
parameter?: (set: HelperHostSet) => any[];
|
|
9
|
+
/** 타이머 등록 직후 1회 호출 (디버깅/로깅용). id는 실제 setTimeout 반환값 - cleanup은 자동으로 처리되므로 직접 clear할 필요 없음. */
|
|
10
|
+
created?: (set: HelperHostSet, id: number) => void;
|
|
11
|
+
/**
|
|
12
|
+
* fire 시 데코레이트된 메서드의 리턴값이 객체이고 이 키의 값이 함수이면 (id: number)로 호출한다.
|
|
13
|
+
* applyAttribute.ts의 valueKey와 동일한 컨벤션 - 리턴 객체에서 이 데코레이터 몫만 뽑아 쓴다.
|
|
14
|
+
*/
|
|
15
|
+
valueKey?: symbol | string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SetTimeoutMetadata {
|
|
19
|
+
propertyKey: string | symbol;
|
|
20
|
+
delay: number;
|
|
21
|
+
options: SetTimeoutOptions;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* connect 시 자동으로 setTimeout을 걸고, disconnect 시 (아직 실행 전이라면) 자동으로 clearTimeout 한다.
|
|
26
|
+
*/
|
|
27
|
+
export function setTimeout(delay: number, options: SetTimeoutOptions = {}): MethodDecorator {
|
|
28
|
+
return (target: Object, propertyKey: string | symbol) => {
|
|
29
|
+
const constructor = target.constructor;
|
|
30
|
+
let metaList = ReflectUtils.getOwnMetadata(SET_TIMEOUT_METADATA_KEY, constructor) as SetTimeoutMetadata[];
|
|
31
|
+
if (!metaList) {
|
|
32
|
+
metaList = [];
|
|
33
|
+
ReflectUtils.defineMetadata(SET_TIMEOUT_METADATA_KEY, metaList, constructor);
|
|
34
|
+
}
|
|
35
|
+
metaList.push({ propertyKey, delay, options });
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const findAllSetTimeoutMetadata = (target: any): SetTimeoutMetadata[] => {
|
|
40
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
41
|
+
return (ReflectUtils.findAllMetadata<SetTimeoutMetadata[]>(SET_TIMEOUT_METADATA_KEY, constructor) || []).flat();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class SetTimeoutLifeCycler implements ElementDefineLifeCycler {
|
|
45
|
+
private readonly activeMap = new WeakMap<any, number[]>();
|
|
46
|
+
|
|
47
|
+
onConnected(helperHostSet: HelperHostSet): void {
|
|
48
|
+
const inst = helperHostSet.$this;
|
|
49
|
+
const ids: number[] = [];
|
|
50
|
+
for (const meta of findAllSetTimeoutMetadata(inst)) {
|
|
51
|
+
const id = helperHostSet.$w.setTimeout(() => {
|
|
52
|
+
const args = meta.options.parameter?.(helperHostSet) ?? [];
|
|
53
|
+
try {
|
|
54
|
+
const res = inst[meta.propertyKey](...args);
|
|
55
|
+
const vk = meta.options.valueKey;
|
|
56
|
+
if (vk && res && typeof res === 'object' && typeof res[vk] === 'function') {
|
|
57
|
+
res[vk](id);
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error('[SWC] setTimeout fire error:', e);
|
|
61
|
+
}
|
|
62
|
+
}, meta.delay);
|
|
63
|
+
meta.options.created?.(helperHostSet, id);
|
|
64
|
+
ids.push(id);
|
|
65
|
+
}
|
|
66
|
+
this.activeMap.set(inst, ids);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onDisconnected(helperHostSet: HelperHostSet): void {
|
|
70
|
+
const inst = helperHostSet.$this;
|
|
71
|
+
for (const id of this.activeMap.get(inst) ?? []) {
|
|
72
|
+
try {
|
|
73
|
+
helperHostSet.$w.clearTimeout(id);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error('[SWC] clearTimeout error:', e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.activeMap.delete(inst);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -72,3 +72,20 @@ export const getSubscribeSwcAppMessageWhileConnectedMetadata = (target: any): Sw
|
|
|
72
72
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
73
73
|
return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY, constructor);
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
77
|
+
// MessageSubscribeLifeCycler
|
|
78
|
+
// NOTE: 실제 구독 로직은 SwcAppMixin._connected 에서 처리된다.
|
|
79
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
80
|
+
import { ElementDefineLifeCycler } from '../types';
|
|
81
|
+
|
|
82
|
+
export class MessageSubscribeLifeCycler implements ElementDefineLifeCycler {
|
|
83
|
+
onConnected(_helperHostSet: HelperHostSet): void {
|
|
84
|
+
// 실제 구독은 SwcAppMixin._connected 에서 처리
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** SwcAppMixin 이 구독 대상 메타를 꺼낼 때 사용 */
|
|
88
|
+
getMetadata(helperHostSet: HelperHostSet): SwcAppMessageSubscriberMetadata[] | undefined {
|
|
89
|
+
return getSubscribeSwcAppMessageWhileConnectedMetadata(helperHostSet.$this);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -86,3 +86,22 @@ export const getSubscribeSwcAppRouteChangeWhileConnectedMetadata = (target: any)
|
|
|
86
86
|
// Sort by order (default 0 if not specified)
|
|
87
87
|
return [...results].sort((a, b) => (a.options?.order ?? 0) - (b.options?.order ?? 0));
|
|
88
88
|
};
|
|
89
|
+
|
|
90
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
91
|
+
// RouteSubscribeLifeCycler
|
|
92
|
+
// NOTE: 실제 구독 로직은 SwcAppMixin._connected 에서 처리된다.
|
|
93
|
+
// 이 cycler 는 메타데이터 접근 진입점 역할만 하며,
|
|
94
|
+
// 향후 SwcAppMixin 에서 로직을 분리할 때 이 클래스로 이전한다.
|
|
95
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
96
|
+
import { ElementDefineLifeCycler } from '../types';
|
|
97
|
+
|
|
98
|
+
export class RouteSubscribeLifeCycler implements ElementDefineLifeCycler {
|
|
99
|
+
onConnected(_helperHostSet: HelperHostSet): void {
|
|
100
|
+
// 실제 구독은 SwcAppMixin._connected 에서 처리
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** SwcAppMixin 이 구독 대상 메타를 꺼낼 때 사용 */
|
|
104
|
+
getMetadata(helperHostSet: HelperHostSet): SwcAppRouteChangeSubscriberMetadata[] {
|
|
105
|
+
return getSubscribeSwcAppRouteChangeWhileConnectedMetadata(helperHostSet.$this);
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -44,6 +44,11 @@ export type HostSet = {
|
|
|
44
44
|
|
|
45
45
|
export type HelperHostSet = HelperSet & HostSet & {$this: any};
|
|
46
46
|
|
|
47
|
+
// 공통 셀렉터 함수 — 요소/노드를 직접 반환하는 함수 셀렉터 (query는 Node까지 반환 가능)
|
|
48
|
+
export type SwcFnSelector = (currentThis: any, helper: HelperHostSet) => Node | NodeList | Element | Element[] | null;
|
|
49
|
+
// 공통 셀렉터 — 문자열(CSS/특수) 또는 함수
|
|
50
|
+
export type SwcSelector = string | SwcFnSelector;
|
|
51
|
+
|
|
47
52
|
export type SwcAppMessage<T = any> = {
|
|
48
53
|
publisher?: any;
|
|
49
54
|
data?: T;
|
|
@@ -71,4 +76,140 @@ export interface SwcElement {
|
|
|
71
76
|
// createEaAttribute(id: string, attributeName: string): string
|
|
72
77
|
// createEaEvent(id: string, eventName: string): string
|
|
73
78
|
// createEaProperty(id: string, propertyName: string): string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
82
|
+
// ElementDefineLifeCycler
|
|
83
|
+
//
|
|
84
|
+
// 각 데코레이터 파일(addEventListener, mutationObserver, …)이 이 interface를
|
|
85
|
+
// 구현해 export 하고, elementDefine.ts는 cyclers 배열로 관리하며 위임만 한다.
|
|
86
|
+
//
|
|
87
|
+
// 시클러는 생성자에서 아무 인자도 받지 않는다. 상태는 인스턴스별로 관리해야 하므로,
|
|
88
|
+
// 각 라이프사이클 훅(onConnected 등)의 첫 번째 인자로 HelperHostSet 을 받아
|
|
89
|
+
// 그 안의 $this(현재 엘리먼트 인스턴스) / $w(window) 로 처리한다.
|
|
90
|
+
// elementDefine 은 elementDefine 시점에 시클러를 1회 생성하고 계속 재사용한다.
|
|
91
|
+
// 모든 메서드는 optional — 관심 있는 훅만 구현하면 된다.
|
|
92
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
95
|
+
// onConnected 반환 타입
|
|
96
|
+
//
|
|
97
|
+
// 각 cycler 가 "필요한 observer 정보"를 선언하면,
|
|
98
|
+
// elementDefine 이 수집해서 필요한 경우에만 observer 인스턴스를 생성한다.
|
|
99
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/** observer observe 대상 엔트리. delegate:true 이면 target 은 셀렉터 문자열이며, 실제 요소는 동적 추적으로 observe/unobserve 된다. */
|
|
102
|
+
export interface ObserverObserveTarget<TOptions> {
|
|
103
|
+
target: Element | ShadowRoot | string;
|
|
104
|
+
options?: TOptions;
|
|
105
|
+
delegate?: boolean;
|
|
106
|
+
/** delegate 동적 추적 시 observe/unobserve 를 실행할 루트(스코프). delegate:true 일 때만 의미 있다. */
|
|
107
|
+
delegateRoot?: SwcRootType;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** MutationObserver observe 대상 하나. 동일 루트의 여러 대상은 같은 callback 을 공유한다. */
|
|
111
|
+
export interface MutationObserverSetEntry {
|
|
112
|
+
target: Element | ShadowRoot | string;
|
|
113
|
+
options?: MutationObserverInit;
|
|
114
|
+
delegate?: boolean;
|
|
115
|
+
delegateRoot?: SwcRootType;
|
|
116
|
+
callback: (mutations: MutationRecord[], observer: MutationObserver) => void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** observe 할 대상 목록 (엔트리별 콜백 포함). elementDefine 이 하나의 MutationObserver 로 모두 observe 한다. */
|
|
120
|
+
export type MutationObserverSet = MutationObserverSetEntry[];
|
|
121
|
+
|
|
122
|
+
/** ResizeObserver observe 대상 하나. 동일 셀렉터의 여러 대상은 같은 callback 을 공유한다. */
|
|
123
|
+
export interface ResizeObserverSetEntry {
|
|
124
|
+
target: Element | ShadowRoot | string;
|
|
125
|
+
options?: ResizeObserverOptions;
|
|
126
|
+
delegate?: boolean;
|
|
127
|
+
delegateRoot?: SwcRootType;
|
|
128
|
+
callback: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** observe 할 대상 목록 (엔트리별 콜백 포함). elementDefine 이 하나의 ResizeObserver 로 모두 observe 한다. */
|
|
132
|
+
export type ResizeObserverSet = ResizeObserverSetEntry[];
|
|
133
|
+
|
|
134
|
+
/** IntersectionObserver observe 대상 하나. 같은 옵션 그룹의 여러 대상은 같은 callback 을 공유한다. */
|
|
135
|
+
export interface IntersectionObserverSetEntry {
|
|
136
|
+
target: Element | ShadowRoot | string;
|
|
137
|
+
delegate?: boolean;
|
|
138
|
+
delegateRoot?: SwcRootType;
|
|
139
|
+
callback: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** IntersectionObserver 그룹. observer 는 생성 시점에 옵션이 고정되므로 옵션별로 1개씩 생성된다. */
|
|
143
|
+
export interface IntersectionObserverGroup {
|
|
144
|
+
/** observer 생성 옵션 (threshold/rootMargin/root). 이 값이 같으면 같은 observer 를 공유한다. */
|
|
145
|
+
options: IntersectionObserverInit;
|
|
146
|
+
observeTargets: IntersectionObserverSetEntry[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** observe 할 옵션 그룹 목록. elementDefine 이 그룹마다 IntersectionObserver 를 생성한다. */
|
|
150
|
+
export type IntersectionObserverSet = IntersectionObserverGroup[];
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* onConnected 의 반환 타입.
|
|
154
|
+
* observer 가 필요 없는 cycler 는 undefined 를 반환해도 된다.
|
|
155
|
+
*/
|
|
156
|
+
export interface OnConnectedResult {
|
|
157
|
+
mutationObserverSet?: MutationObserverSet;
|
|
158
|
+
resizeObserverSet?: ResizeObserverSet;
|
|
159
|
+
intersectionObserverSet?: IntersectionObserverSet;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 각 데코레이터 파일이 구현하는 라이프사이클 위임 interface.
|
|
164
|
+
*
|
|
165
|
+
* 구현체는 상태를 갖지 않고, 각 훅의 첫 번째 인자로 HelperHostSet 을 받는다.
|
|
166
|
+
* 관심 있는 훅만 구현하면 된다 (전부 optional).
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* const eventCycler = new EventListenerLifeCycler();
|
|
170
|
+
* const cyclers: ElementDefineLifeCycler[] = [eventCycler, ...]; // elementDefine 시 1회 생성
|
|
171
|
+
*
|
|
172
|
+
* proto.connectedCallback = async function () {
|
|
173
|
+
* const helperHostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
174
|
+
* const results = await Promise.all(cyclers.map(c => c.onConnected?.(helperHostSet)));
|
|
175
|
+
* // results 에서 mutationObserverSet / resizeObserverSet 수집
|
|
176
|
+
* // → 필요한 경우에만 MutationObserver / ResizeObserver 생성
|
|
177
|
+
* };
|
|
178
|
+
* proto.disconnectedCallback = function () {
|
|
179
|
+
* for (const c of cyclers) c.onDisconnected?.(helperHostSet);
|
|
180
|
+
* };
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export interface ElementDefineLifeCycler {
|
|
184
|
+
/**
|
|
185
|
+
* connectedCallback 시 호출.
|
|
186
|
+
* observer 가 필요하면 OnConnectedResult 를 반환하고,
|
|
187
|
+
* 필요 없으면 void / undefined 를 반환한다.
|
|
188
|
+
* @param helperHostSet 현재 엘리먼트 인스턴스($this)를 포함한 컨텍스트
|
|
189
|
+
* @param resizeObserverSet 이전 시클러가 반환한 resize observer set (mutation 시클러가 주입받아 사용)
|
|
190
|
+
*/
|
|
191
|
+
onConnected?(helperHostSet: HelperHostSet, resizeObserverSet?: ResizeObserverSet): OnConnectedResult | void | Promise<OnConnectedResult | void>;
|
|
192
|
+
|
|
193
|
+
/** disconnectedCallback 시 호출. 등록한 리소스를 해제한다. */
|
|
194
|
+
onDisconnected?(helperHostSet: HelperHostSet): void;
|
|
195
|
+
|
|
196
|
+
/** adoptedCallback 시 호출 (선택적). */
|
|
197
|
+
onAdopted?(helperHostSet: HelperHostSet): void;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* attributeChangedCallback 시 호출 (선택적).
|
|
201
|
+
* @param helperHostSet 현재 엘리먼트 인스턴스($this)를 포함한 컨텍스트
|
|
202
|
+
* @param name 변경된 attribute 이름
|
|
203
|
+
* @param oldVal 이전 값
|
|
204
|
+
* @param newVal 새 값 (ActionExpression 처리 후)
|
|
205
|
+
*/
|
|
206
|
+
onAttributeChanged?(helperHostSet: HelperHostSet, name: string, oldVal: string | null, newVal: any): void;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* observedAttributes 에 포함해야 하는 attribute 이름 목록을 반환한다.
|
|
210
|
+
* elementDefine 이 define-time(constructor)에 호출해 수집한다.
|
|
211
|
+
* 관심 없으면 구현하지 않거나 빈 배열을 반환한다.
|
|
212
|
+
* @param target constructor 또는 element 인스턴스 (메타데이터 조회용)
|
|
213
|
+
*/
|
|
214
|
+
getObservedAttributeNames?(target: any): string[];
|
|
74
215
|
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var queryAll_exports = {};
|
|
19
|
-
__export(queryAll_exports, {
|
|
20
|
-
QUERY_ALL_METADATA_KEY: () => QUERY_ALL_METADATA_KEY,
|
|
21
|
-
getQueryAllMetadata: () => getQueryAllMetadata,
|
|
22
|
-
queryAll: () => queryAll
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(queryAll_exports);
|
|
25
|
-
var import_core = require("@dooboostore/core");
|
|
26
|
-
var import_elementDefine = require("./elementDefine");
|
|
27
|
-
var import_Utils = require("../utils/Utils");
|
|
28
|
-
const QUERY_ALL_METADATA_KEY = Symbol.for("simple-web-component:query-all");
|
|
29
|
-
function queryAll(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
30
|
-
if (descriptor !== void 0 && (typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol")) {
|
|
31
|
-
throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(optionsOrPropertyKey)})`);
|
|
32
|
-
}
|
|
33
|
-
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
34
|
-
return (targetObj, propertyKey, descriptor2) => {
|
|
35
|
-
if (descriptor2 !== void 0) {
|
|
36
|
-
throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
37
|
-
}
|
|
38
|
-
const constructor = targetObj.constructor;
|
|
39
|
-
let queries = import_core.ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
|
|
40
|
-
if (!queries) {
|
|
41
|
-
queries = [];
|
|
42
|
-
import_core.ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
|
|
43
|
-
}
|
|
44
|
-
queries.push({ propertyKey, selector: selectorOrTarget, options: optionsOrPropertyKey || {} });
|
|
45
|
-
Object.defineProperty(targetObj, propertyKey, {
|
|
46
|
-
get() {
|
|
47
|
-
(0, import_elementDefine.ensureInit)(this);
|
|
48
|
-
const config = (0, import_elementDefine.getElementConfig)(this);
|
|
49
|
-
const win = config?.window || window;
|
|
50
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
51
|
-
let resolvedSelector;
|
|
52
|
-
let resolvedElements = [];
|
|
53
|
-
if (typeof selectorOrTarget === "function") {
|
|
54
|
-
const result = selectorOrTarget(this, hostSet);
|
|
55
|
-
if (result instanceof win.NodeList) {
|
|
56
|
-
resolvedElements = Array.from(result).filter((el) => el instanceof win.HTMLElement);
|
|
57
|
-
} else if (Array.isArray(result)) {
|
|
58
|
-
resolvedElements = result.filter((el) => el instanceof win.HTMLElement);
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
resolvedSelector = selectorOrTarget;
|
|
62
|
-
const r = optionsOrPropertyKey?.root || "auto";
|
|
63
|
-
const applyRoot = (t) => {
|
|
64
|
-
if (!t)
|
|
65
|
-
return [];
|
|
66
|
-
const items = Array.isArray(t) ? t : [t];
|
|
67
|
-
const results = [];
|
|
68
|
-
items.forEach((it) => {
|
|
69
|
-
if (!(it instanceof HTMLElement)) {
|
|
70
|
-
results.push(it);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (r === "auto")
|
|
74
|
-
results.push(it.shadowRoot || it);
|
|
75
|
-
else {
|
|
76
|
-
if (r === "light" || r === "all")
|
|
77
|
-
results.push(it);
|
|
78
|
-
if ((r === "shadow" || r === "all") && it.shadowRoot)
|
|
79
|
-
results.push(it.shadowRoot);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return results;
|
|
83
|
-
};
|
|
84
|
-
if (resolvedSelector === "$hosts")
|
|
85
|
-
resolvedElements = applyRoot(hostSet.$hosts).filter((el) => el instanceof HTMLElement);
|
|
86
|
-
else if (resolvedSelector === "$appHosts")
|
|
87
|
-
resolvedElements = applyRoot(hostSet.$appHosts).filter((el) => el instanceof HTMLElement);
|
|
88
|
-
else if (resolvedSelector === "$host")
|
|
89
|
-
resolvedElements = applyRoot(hostSet.$host).filter((el) => el instanceof HTMLElement);
|
|
90
|
-
else if (resolvedSelector === "$parentHost")
|
|
91
|
-
resolvedElements = applyRoot(hostSet.$parentHost).filter((el) => el instanceof HTMLElement);
|
|
92
|
-
else if (resolvedSelector === "$appHost")
|
|
93
|
-
resolvedElements = applyRoot(hostSet.$appHost).filter((el) => el instanceof HTMLElement);
|
|
94
|
-
else if (resolvedSelector === "$firstHost")
|
|
95
|
-
resolvedElements = applyRoot(hostSet.$firstHost).filter((el) => el instanceof HTMLElement);
|
|
96
|
-
else if (resolvedSelector === "$lastHost")
|
|
97
|
-
resolvedElements = applyRoot(hostSet.$lastHost).filter((el) => el instanceof HTMLElement);
|
|
98
|
-
else if (resolvedSelector === "$firstAppHost")
|
|
99
|
-
resolvedElements = applyRoot(hostSet.$firstAppHost).filter((el) => el instanceof HTMLElement);
|
|
100
|
-
else if (resolvedSelector === "$lastAppHost")
|
|
101
|
-
resolvedElements = applyRoot(hostSet.$lastAppHost).filter((el) => el instanceof HTMLElement);
|
|
102
|
-
else if (resolvedSelector === "$window")
|
|
103
|
-
return [win];
|
|
104
|
-
else if (resolvedSelector === "$document")
|
|
105
|
-
return [win.document];
|
|
106
|
-
else if (resolvedSelector === "$this")
|
|
107
|
-
resolvedElements = applyRoot(this).filter((el) => el instanceof HTMLElement);
|
|
108
|
-
else {
|
|
109
|
-
if (r === "shadow")
|
|
110
|
-
resolvedElements = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];
|
|
111
|
-
else if (r === "light")
|
|
112
|
-
resolvedElements = Array.from(this.querySelectorAll(resolvedSelector));
|
|
113
|
-
else if (r === "all") {
|
|
114
|
-
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];
|
|
115
|
-
const lNodes = Array.from(this.querySelectorAll(resolvedSelector));
|
|
116
|
-
resolvedElements = [...sNodes, ...lNodes];
|
|
117
|
-
} else
|
|
118
|
-
resolvedElements = Array.from((this.shadowRoot || this).querySelectorAll(resolvedSelector));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (optionsOrPropertyKey?.filter) {
|
|
122
|
-
resolvedElements = resolvedElements.filter((el) => {
|
|
123
|
-
if (!(el instanceof win.HTMLElement))
|
|
124
|
-
return true;
|
|
125
|
-
return optionsOrPropertyKey.filter(el, { currentThis: this, helper: hostSet });
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return resolvedElements;
|
|
129
|
-
},
|
|
130
|
-
set(nv) {
|
|
131
|
-
(0, import_elementDefine.ensureInit)(this);
|
|
132
|
-
if (nv === null || nv === void 0 || Array.isArray(nv) && nv.length === 0) {
|
|
133
|
-
const config = (0, import_elementDefine.getElementConfig)(this);
|
|
134
|
-
const win = config?.window || window;
|
|
135
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
136
|
-
if (typeof selectorOrTarget === "function") {
|
|
137
|
-
const result = selectorOrTarget(this, hostSet);
|
|
138
|
-
if (result instanceof win.NodeList) {
|
|
139
|
-
Array.from(result).forEach((el) => {
|
|
140
|
-
if (el instanceof win.Element)
|
|
141
|
-
el.remove();
|
|
142
|
-
});
|
|
143
|
-
} else if (Array.isArray(result)) {
|
|
144
|
-
result.forEach((el) => {
|
|
145
|
-
if (el instanceof win.Element)
|
|
146
|
-
el.remove();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const resolvedSelector = selectorOrTarget;
|
|
152
|
-
if (resolvedSelector.startsWith("$") && resolvedSelector !== "$this")
|
|
153
|
-
return;
|
|
154
|
-
const r = optionsOrPropertyKey?.root || "auto";
|
|
155
|
-
let targets = [];
|
|
156
|
-
if (r === "shadow")
|
|
157
|
-
targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];
|
|
158
|
-
else if (r === "light")
|
|
159
|
-
targets = Array.from(this.querySelectorAll(resolvedSelector));
|
|
160
|
-
else if (r === "all") {
|
|
161
|
-
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];
|
|
162
|
-
const lNodes = Array.from(this.querySelectorAll(resolvedSelector));
|
|
163
|
-
targets = [...sNodes, ...lNodes];
|
|
164
|
-
} else {
|
|
165
|
-
targets = Array.from((this.shadowRoot || this).querySelectorAll(resolvedSelector));
|
|
166
|
-
}
|
|
167
|
-
targets.forEach((t) => t.remove());
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
enumerable: true,
|
|
171
|
-
configurable: true
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
return queryAll("$this", selectorOrTarget);
|
|
176
|
-
}
|
|
177
|
-
const getQueryAllMetadata = (target) => {
|
|
178
|
-
const constructor = target instanceof Function ? target : target.constructor;
|
|
179
|
-
return import_core.ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
|
|
180
|
-
};
|
|
181
|
-
//# sourceMappingURL=queryAll.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/decorators/queryAll.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { getElementConfig, ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface QueryAllOptions extends SwcQueryOptions {\n /**\n * Filter function to determine whether to include the element.\n * If it returns false, the element is skipped.\n */\n filter?: (target: HTMLElement, meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n}\n\nexport interface QueryAllMetadata {\n propertyKey: string | symbol;\n selector: string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);\n options: QueryAllOptions;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol.for('simple-web-component:query-all');\n\nexport function queryAll(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void;\nexport function queryAll(selector: string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null), options?: QueryAllOptions): PropertyDecorator;\nexport function queryAll(options?: QueryAllOptions): PropertyDecorator;\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n * \n * Supports both string selectors and function-based selectors:\n * - String selector: @queryAll('.item')\n * - Function selector: @queryAll((currentThis, helper) => currentThis.shadowRoot?.querySelectorAll('.item'))\n * \n * Supports filtering:\n * - @queryAll('.item', { filter: (target, meta) => target.hasAttribute('active') })\n */\nexport function queryAll(selectorOrTarget?: string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null) | Object, optionsOrPropertyKey?: QueryAllOptions | string | symbol, descriptor?: PropertyDescriptor): any {\n // Bare decorator: @queryAll\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(optionsOrPropertyKey)})`);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = targetObj.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ propertyKey, selector: selectorOrTarget as any, options: optionsOrPropertyKey as QueryAllOptions || {} });\n\n Object.defineProperty(targetObj, propertyKey, {\n get(this: HTMLElement) {\n ensureInit(this);\n const config = getElementConfig(this);\n const win = config?.window || window;\n const hostSet = SwcUtils.getHelperAndHostSet(win, this);\n \n // Resolve selector - can be string or function\n let resolvedSelector: string;\n let resolvedElements: HTMLElement[] = [];\n \n if (typeof selectorOrTarget === 'function') {\n const result = (selectorOrTarget as any)(this, hostSet);\n // If function returns NodeList or Element[], convert to array\n if (result instanceof win.NodeList) {\n resolvedElements = Array.from(result).filter(el => el instanceof win.HTMLElement) as HTMLElement[];\n } else if (Array.isArray(result)) {\n resolvedElements = result.filter(el => el instanceof win.HTMLElement) as HTMLElement[];\n }\n } else {\n resolvedSelector = selectorOrTarget;\n\n const r = (optionsOrPropertyKey as QueryAllOptions)?.root || 'auto';\n const applyRoot = (t: any): any[] => {\n if (!t) return [];\n const items = Array.isArray(t) ? t : [t];\n const results: any[] = [];\n items.forEach(it => {\n if (!(it instanceof HTMLElement)) {\n results.push(it);\n return;\n }\n if (r === 'auto') results.push(it.shadowRoot || it);\n else {\n if (r === 'light' || r === 'all') results.push(it);\n if ((r === 'shadow' || r === 'all') && it.shadowRoot) results.push(it.shadowRoot);\n }\n });\n return results;\n };\n\n // --- Special Selectors: HostSet ---\n if (resolvedSelector === '$hosts') resolvedElements = applyRoot(hostSet.$hosts).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$appHosts') resolvedElements = applyRoot(hostSet.$appHosts).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$host') resolvedElements = applyRoot(hostSet.$host).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$parentHost') resolvedElements = applyRoot(hostSet.$parentHost).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$appHost') resolvedElements = applyRoot(hostSet.$appHost).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$firstHost') resolvedElements = applyRoot(hostSet.$firstHost).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$lastHost') resolvedElements = applyRoot(hostSet.$lastHost).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$firstAppHost') resolvedElements = applyRoot(hostSet.$firstAppHost).filter(el => el instanceof HTMLElement);\n else if (resolvedSelector === '$lastAppHost') resolvedElements = applyRoot(hostSet.$lastAppHost).filter(el => el instanceof HTMLElement);\n // --- Special Selectors: Env ---\n else if (resolvedSelector === '$window') return [win];\n else if (resolvedSelector === '$document') return [win.document];\n else if (resolvedSelector === '$this') resolvedElements = applyRoot(this).filter(el => el instanceof HTMLElement);\n // --- Standard Selectors ---\n else {\n if (r === 'shadow') resolvedElements = this.shadowRoot ? (Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) as HTMLElement[]) : [];\n else if (r === 'light') resolvedElements = Array.from(this.querySelectorAll(resolvedSelector)) as HTMLElement[];\n else if (r === 'all') {\n const sNodes = this.shadowRoot ? (Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) as HTMLElement[]) : [];\n const lNodes = Array.from(this.querySelectorAll(resolvedSelector)) as HTMLElement[];\n resolvedElements = [...sNodes, ...lNodes];\n }\n else resolvedElements = (Array.from((this.shadowRoot || this).querySelectorAll(resolvedSelector)) as HTMLElement[]);\n }\n }\n\n // Apply filter if provided\n if ((optionsOrPropertyKey as QueryAllOptions)?.filter) {\n resolvedElements = resolvedElements.filter(el => {\n if (!(el instanceof win.HTMLElement)) return true;\n return (optionsOrPropertyKey as QueryAllOptions).filter!(el, { currentThis: this, helper: hostSet });\n });\n }\n\n return resolvedElements;\n },\n set(this: HTMLElement, nv: any) {\n ensureInit(this);\n if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {\n const config = getElementConfig(this);\n const win = config?.window || window;\n const hostSet = SwcUtils.getHelperAndHostSet(win, this);\n \n // Resolve selector - can be string or function\n if (typeof selectorOrTarget === 'function') {\n // Get elements from function and remove them\n const result = (selectorOrTarget as any)(this, hostSet);\n if (result instanceof win.NodeList) {\n Array.from(result).forEach(el => {\n if (el instanceof win.Element) (el as Element).remove();\n });\n } else if (Array.isArray(result)) {\n result.forEach(el => {\n if (el instanceof win.Element) (el as Element).remove();\n });\n }\n return;\n }\n \n const resolvedSelector = selectorOrTarget;\n \n if (resolvedSelector.startsWith('$') && resolvedSelector !== '$this') return;\n\n const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';\n let targets: (Element | Node)[] = [];\n if (r === 'shadow') targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];\n else if (r === 'light') targets = Array.from(this.querySelectorAll(resolvedSelector));\n else if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(resolvedSelector)) : [];\n const lNodes = Array.from(this.querySelectorAll(resolvedSelector));\n targets = [...sNodes, ...lNodes];\n } else {\n targets = Array.from((this.shadowRoot || this).querySelectorAll(resolvedSelector));\n }\n targets.forEach(t => (t as Element).remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n }\n // Without selector (defaults to $this)\n return queryAll('$this', selectorOrTarget as SwcQueryOptions);\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;kBAA6B;AAC7B,2BAA6C;AAC7C,mBAAyB;AAiBlB,MAAM,yBAAyB,OAAO,IAAI,gCAAgC;AAe3E,SAAU,SAAS,kBAA2H,sBAA0D,YAA+B;AAE3O,MAAI,eAAe,WAAc,OAAO,yBAAyB,YAAY,OAAO,yBAAyB,WAAW;AACtH,UAAM,IAAI,MAAM,2DAA2D,OAAO,oBAAoB,CAAC,GAAG;EAC5G;AAEA,MAAI,OAAO,qBAAqB,YAAY,OAAO,qBAAqB,YAAY;AAClF,WAAO,CAAC,WAAmB,aAA8BA,gBAA4B;AACnF,UAAIA,gBAAe,QAAW;AAC5B,cAAM,IAAI,MAAM,2DAA2D,OAAO,WAAW,CAAC,GAAG;MACnG;AAEA,YAAM,cAAc,UAAU;AAC9B,UAAI,UAAU,yBAAa,YAAgC,wBAAwB,WAAW;AAC9F,UAAI,CAAC,SAAS;AACZ,kBAAU,CAAA;AACV,iCAAa,eAAe,wBAAwB,SAAS,WAAW;MAC1E;AACA,cAAQ,KAAK,EAAE,aAAa,UAAU,kBAAyB,SAAS,wBAA2C,CAAA,EAAE,CAAE;AAEvH,aAAO,eAAe,WAAW,aAAa;QAC5C,MAAG;AACD,+CAAW,IAAI;AACf,gBAAM,aAAS,uCAAiB,IAAI;AACp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