@dooboostore/simple-web-component 1.0.42 → 1.0.44
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 +689 -85
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +10 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +41 -30
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +66 -23
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +176 -107
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +21 -30
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +11 -2
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +48 -17
- package/dist/cjs/decorators/applyStyle.js.map +3 -3
- package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
- package/dist/cjs/decorators/changedAttribute.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +37 -6
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +58 -42
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js +37 -23
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/cjs/decorators/query.js +96 -145
- package/dist/cjs/decorators/query.js.map +3 -3
- package/dist/cjs/decorators/queryAll.js +104 -131
- package/dist/cjs/decorators/queryAll.js.map +3 -3
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +17 -2
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -0
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/esm/SwcAppEngine.js +3 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +10 -0
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +41 -30
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +66 -23
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +176 -107
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +21 -30
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +11 -2
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +48 -17
- package/dist/esm/decorators/applyStyle.js.map +3 -3
- package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
- package/dist/esm/decorators/changedAttribute.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +35 -4
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +58 -42
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/publishSwcAppMessage.js +37 -23
- package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/esm/decorators/query.js +96 -145
- package/dist/esm/decorators/query.js.map +3 -3
- package/dist/esm/decorators/queryAll.js +104 -131
- package/dist/esm/decorators/queryAll.js.map +3 -3
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +18 -3
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +4 -0
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +900 -578
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +22 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +61 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +22 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +178 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +53 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +6 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +13 -7
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +20 -10
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts +19 -0
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +3 -26
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +3 -20
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +4 -4
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +900 -578
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -9
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +35 -24
- package/src/decorators/applyAttribute.ts +167 -65
- package/src/decorators/applyClass.ts +113 -17
- package/src/decorators/applyNode.ts +383 -102
- package/src/decorators/applyProperty.ts +99 -65
- package/src/decorators/applySlot.ts +24 -10
- package/src/decorators/applyStyle.ts +83 -13
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +62 -35
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +71 -27
- package/src/decorators/query.ts +90 -159
- package/src/decorators/queryAll.ts +92 -134
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
- package/src/elements/SwcAppMixin.ts +43 -24
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/index.ts +2 -0
- package/src/router/ElementRouter.ts +4 -0
- package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
- package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
- package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
|
@@ -10,9 +10,25 @@ export interface PublishSwcAppMessageMetadata {
|
|
|
10
10
|
|
|
11
11
|
export interface PublishSwcAppMessageOptions {
|
|
12
12
|
messageType?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Custom key to extract value from return object.
|
|
15
|
+
* If not provided, uses PUBLISH_SWC_APP_MESSAGE_METADATA_KEY by default.
|
|
16
|
+
* Useful when multiple @publishSwcAppMessage decorators are on the same method.
|
|
17
|
+
*
|
|
18
|
+
* Example:
|
|
19
|
+
* @publishSwcAppMessage('event1', { valueKey: 'detail1' })
|
|
20
|
+
* @publishSwcAppMessage('event2', { valueKey: 'detail2' })
|
|
21
|
+
* myMethod() {
|
|
22
|
+
* return {
|
|
23
|
+
* detail1: { type: 'event1', data: 'value1' },
|
|
24
|
+
* detail2: { type: 'event2', data: 'value2' }
|
|
25
|
+
* };
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
valueKey?: symbol | string;
|
|
13
29
|
}
|
|
14
30
|
|
|
15
|
-
function createPublishSwcAppMessage(messageType?: string): MethodDecorator {
|
|
31
|
+
function createPublishSwcAppMessage(messageType?: string, options?: PublishSwcAppMessageOptions): MethodDecorator {
|
|
16
32
|
return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
|
|
17
33
|
const constructor = target.constructor;
|
|
18
34
|
let list = ReflectUtils.getOwnMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, constructor) as PublishSwcAppMessageMetadata[];
|
|
@@ -31,32 +47,47 @@ function createPublishSwcAppMessage(messageType?: string): MethodDecorator {
|
|
|
31
47
|
descriptor.value = function (...args: any[]) {
|
|
32
48
|
// 원본 메서드 실행
|
|
33
49
|
const result = originalMethod.apply(this, args);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Extract value for this decorator from method return value
|
|
53
|
+
*
|
|
54
|
+
* If return value is an object with this decorator's key,
|
|
55
|
+
* use that value. Otherwise use the entire return value.
|
|
56
|
+
*
|
|
57
|
+
* Uses valueKey from options if provided, otherwise uses PUBLISH_SWC_APP_MESSAGE_METADATA_KEY.
|
|
58
|
+
*/
|
|
59
|
+
const extractValue = (v: any) => {
|
|
60
|
+
const keyToUse = options?.valueKey ?? PUBLISH_SWC_APP_MESSAGE_METADATA_KEY;
|
|
61
|
+
if (v && typeof v === 'object' && keyToUse in v) {
|
|
62
|
+
return v[keyToUse];
|
|
63
|
+
}
|
|
64
|
+
return v;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const publishMessage = (data: any) => {
|
|
68
|
+
// appHost 찾아서 메시지 발행
|
|
69
|
+
const appHost = SwcUtils.getAppHost(this as HTMLElement);
|
|
70
|
+
if (appHost) {
|
|
71
|
+
appHost.publishMessage({
|
|
72
|
+
publisher: this,
|
|
73
|
+
data,
|
|
74
|
+
type: messageType
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
34
78
|
|
|
35
79
|
// Promise 체크
|
|
36
80
|
if (result instanceof Promise) {
|
|
37
81
|
result.then((data) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (appHost) {
|
|
41
|
-
appHost.publishMessage({
|
|
42
|
-
publisher: this,
|
|
43
|
-
data,
|
|
44
|
-
type: messageType
|
|
45
|
-
});
|
|
46
|
-
}
|
|
82
|
+
const extracted = extractValue(data);
|
|
83
|
+
publishMessage(extracted);
|
|
47
84
|
}).catch((err) => {
|
|
48
85
|
console.warn('publishSwcAppMessage async error:', err);
|
|
49
86
|
});
|
|
50
87
|
} else {
|
|
51
88
|
// 동기 호출 - 바로 메시지 발행
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
appHost.publishMessage({
|
|
55
|
-
publisher: this,
|
|
56
|
-
data: result,
|
|
57
|
-
type: messageType
|
|
58
|
-
});
|
|
59
|
-
}
|
|
89
|
+
const extracted = extractValue(result);
|
|
90
|
+
publishMessage(extracted);
|
|
60
91
|
}
|
|
61
92
|
|
|
62
93
|
return result;
|
|
@@ -71,27 +102,40 @@ export function publishSwcAppMessage(target: Object, propertyKey: string | symbo
|
|
|
71
102
|
// 오버로드 시그니처 - 함수 호출 (괄호 있음)
|
|
72
103
|
export function publishSwcAppMessage(): MethodDecorator;
|
|
73
104
|
export function publishSwcAppMessage(messageType: string): MethodDecorator;
|
|
105
|
+
export function publishSwcAppMessage(messageType: string, options: PublishSwcAppMessageOptions): MethodDecorator;
|
|
106
|
+
export function publishSwcAppMessage(options: PublishSwcAppMessageOptions): MethodDecorator;
|
|
74
107
|
|
|
75
|
-
export function publishSwcAppMessage(
|
|
108
|
+
export function publishSwcAppMessage(targetOrMessageTypeOrOptions?: any, propertyKeyOrOptions?: string | symbol | PublishSwcAppMessageOptions, descriptor?: PropertyDescriptor): any {
|
|
76
109
|
// 직접 데코레이터로 사용된 경우 (괄호 없음): @publishSwcAppMessage
|
|
77
|
-
if (
|
|
78
|
-
|
|
110
|
+
if (targetOrMessageTypeOrOptions && typeof targetOrMessageTypeOrOptions === 'object' &&
|
|
111
|
+
propertyKeyOrOptions && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol') &&
|
|
79
112
|
descriptor) {
|
|
80
|
-
const target =
|
|
81
|
-
return createPublishSwcAppMessage()(target,
|
|
113
|
+
const target = targetOrMessageTypeOrOptions;
|
|
114
|
+
return createPublishSwcAppMessage()(target, propertyKeyOrOptions, descriptor);
|
|
82
115
|
}
|
|
83
116
|
|
|
84
|
-
// 함수로 호출된 경우 (괄호 있음): @publishSwcAppMessage() / @publishSwcAppMessage('messageType')
|
|
117
|
+
// 함수로 호출된 경우 (괄호 있음): @publishSwcAppMessage() / @publishSwcAppMessage('messageType') / @publishSwcAppMessage({...})
|
|
85
118
|
let messageType: string | undefined;
|
|
119
|
+
let options: PublishSwcAppMessageOptions | undefined;
|
|
86
120
|
|
|
87
|
-
if (typeof
|
|
121
|
+
if (typeof targetOrMessageTypeOrOptions === 'string') {
|
|
88
122
|
// 메시지 타입 전달: @publishSwcAppMessage('messageType')
|
|
89
|
-
messageType =
|
|
123
|
+
messageType = targetOrMessageTypeOrOptions;
|
|
124
|
+
if (typeof propertyKeyOrOptions === 'object' && propertyKeyOrOptions !== null) {
|
|
125
|
+
options = propertyKeyOrOptions as PublishSwcAppMessageOptions;
|
|
126
|
+
}
|
|
127
|
+
} else if (typeof targetOrMessageTypeOrOptions === 'object' && targetOrMessageTypeOrOptions !== null) {
|
|
128
|
+
// 옵션 객체 전달: @publishSwcAppMessage({...})
|
|
129
|
+
options = targetOrMessageTypeOrOptions as PublishSwcAppMessageOptions;
|
|
130
|
+
messageType = options.messageType;
|
|
90
131
|
}
|
|
91
132
|
|
|
92
|
-
return createPublishSwcAppMessage(messageType);
|
|
133
|
+
return createPublishSwcAppMessage(messageType, options);
|
|
93
134
|
}
|
|
94
135
|
|
|
136
|
+
// --- Aliases: publish... ---
|
|
137
|
+
export const publishMessage = publishSwcAppMessage;
|
|
138
|
+
|
|
95
139
|
// Helper function to retrieve publish message metadata
|
|
96
140
|
export const getPublishSwcAppMessageMetadata = (target: any): PublishSwcAppMessageMetadata[] | undefined => {
|
|
97
141
|
const constructor = target instanceof Function ? target : target.constructor;
|
package/src/decorators/query.ts
CHANGED
|
@@ -11,173 +11,104 @@ export interface QueryMetadata {
|
|
|
11
11
|
|
|
12
12
|
export const QUERY_METADATA_KEY = Symbol.for('simple-web-component:query');
|
|
13
13
|
|
|
14
|
-
export function query(target:
|
|
14
|
+
export function query(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void;
|
|
15
15
|
export function query(selector: string, options?: SwcQueryOptions): PropertyDecorator;
|
|
16
|
+
export function query(options?: SwcQueryOptions): PropertyDecorator;
|
|
16
17
|
/**
|
|
17
18
|
* @query decorator to inject a single element into a class property.
|
|
18
19
|
*/
|
|
19
|
-
export function query(selectorOrTarget
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (r === 'shadow') return t.shadowRoot;
|
|
43
|
-
if (r === 'light') return t;
|
|
44
|
-
if (r === 'all') return t.shadowRoot || t;
|
|
45
|
-
return t;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// --- Special Selectors: HostSet ---
|
|
49
|
-
const hostSet = SwcUtils.getHostSet(this);
|
|
50
|
-
if (selector === '$this') return applyRoot(this);
|
|
51
|
-
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
52
|
-
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
53
|
-
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
54
|
-
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
55
|
-
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
56
|
-
if (selector === '$firstAppHost') return applyRoot(hostSet.$firstAppHost);
|
|
57
|
-
if (selector === '$lastAppHost') return applyRoot(hostSet.$lastAppHost);
|
|
58
|
-
|
|
59
|
-
// --- Special Selectors: Env ---
|
|
60
|
-
const config = getElementConfig(this);
|
|
61
|
-
const win = config?.window || window;
|
|
62
|
-
if (selector === '$window') return win;
|
|
63
|
-
if (selector === '$document') return win.document;
|
|
64
|
-
|
|
65
|
-
// --- Standard Selectors ---
|
|
66
|
-
if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
67
|
-
if (r === 'light') return this.querySelector(selector);
|
|
68
|
-
if (r === 'all') {
|
|
69
|
-
const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
70
|
-
return shadowMatch || this.querySelector(selector);
|
|
71
|
-
}
|
|
72
|
-
return (this.shadowRoot || this).querySelector(selector);
|
|
73
|
-
},
|
|
74
|
-
set(this: HTMLElement, nv: any) {
|
|
75
|
-
ensureInit(this);
|
|
76
|
-
if (nv === null || nv === undefined) {
|
|
20
|
+
export function query(selectorOrTarget?: string | Object, optionsOrPropertyKey?: SwcQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
21
|
+
// Bare decorator: @query
|
|
22
|
+
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
23
|
+
throw new Error(`@query decorator cannot be used on methods. (Method: ${String(optionsOrPropertyKey)})`);
|
|
24
|
+
}
|
|
25
|
+
// With selector
|
|
26
|
+
if (typeof selectorOrTarget === 'string') {
|
|
27
|
+
return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {
|
|
28
|
+
if (descriptor !== undefined) {
|
|
29
|
+
throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const constructor = targetObj.constructor;
|
|
33
|
+
let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);
|
|
34
|
+
if (!queries) {
|
|
35
|
+
queries = [];
|
|
36
|
+
ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
|
|
37
|
+
}
|
|
38
|
+
queries.push({ propertyKey, selector: selectorOrTarget, options: optionsOrPropertyKey as SwcQueryOptions || {} });
|
|
39
|
+
|
|
40
|
+
Object.defineProperty(targetObj, propertyKey, {
|
|
41
|
+
get(this: HTMLElement) {
|
|
42
|
+
ensureInit(this);
|
|
77
43
|
const selector = selectorOrTarget;
|
|
78
|
-
if (selector.startsWith('$') && selector !== '$this') return;
|
|
79
44
|
|
|
80
|
-
const r =
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
45
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
46
|
+
const applyRoot = (t: any) => {
|
|
47
|
+
if (!t || !(t instanceof HTMLElement)) return t;
|
|
48
|
+
if (r === 'auto') return t.shadowRoot || t;
|
|
49
|
+
if (r === 'shadow') return t.shadowRoot;
|
|
50
|
+
if (r === 'light') return t;
|
|
51
|
+
if (r === 'all') return t.shadowRoot || t;
|
|
52
|
+
return t;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// --- Special Selectors: HostSet ---
|
|
56
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
57
|
+
if (selector === '$this') return applyRoot(this);
|
|
58
|
+
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
59
|
+
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
60
|
+
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
61
|
+
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
62
|
+
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
63
|
+
if (selector === '$firstAppHost') return applyRoot(hostSet.$firstAppHost);
|
|
64
|
+
if (selector === '$lastAppHost') return applyRoot(hostSet.$lastAppHost);
|
|
65
|
+
|
|
66
|
+
// --- Special Selectors: Env ---
|
|
67
|
+
const config = getElementConfig(this);
|
|
68
|
+
const win = config?.window || window;
|
|
69
|
+
if (selector === '$window') return win;
|
|
70
|
+
if (selector === '$document') return win.document;
|
|
71
|
+
|
|
72
|
+
// --- Standard Selectors ---
|
|
73
|
+
if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
74
|
+
if (r === 'light') return this.querySelector(selector);
|
|
75
|
+
if (r === 'all') {
|
|
76
|
+
const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
77
|
+
return shadowMatch || this.querySelector(selector);
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export function queryWindow(options: SwcQueryOptions): PropertyDecorator;
|
|
125
|
-
export function queryWindow(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
126
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
127
|
-
return query('$window', {})(targetOrOptions, propertyKey);
|
|
128
|
-
}
|
|
129
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
130
|
-
return query('$window', targetOrOptions as SwcQueryOptions);
|
|
131
|
-
} else {
|
|
132
|
-
return query('$window', {});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function queryDocument(target: Object, propertyKey: string | symbol): void;
|
|
137
|
-
export function queryDocument(): PropertyDecorator;
|
|
138
|
-
export function queryDocument(options: SwcQueryOptions): PropertyDecorator;
|
|
139
|
-
export function queryDocument(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
140
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
141
|
-
return query('$document', {})(targetOrOptions, propertyKey);
|
|
142
|
-
}
|
|
143
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
144
|
-
return query('$document', targetOrOptions as SwcQueryOptions);
|
|
145
|
-
} else {
|
|
146
|
-
return query('$document', {});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @host - Query $host (Direct parent SWC component)
|
|
151
|
-
*/
|
|
152
|
-
export function queryHost(target: Object, propertyKey: string | symbol): void;
|
|
153
|
-
export function queryHost(): PropertyDecorator;
|
|
154
|
-
export function queryHost(options: SwcQueryOptions): PropertyDecorator;
|
|
155
|
-
export function queryHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
156
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
157
|
-
return query('$host', {})(targetOrOptions, propertyKey);
|
|
158
|
-
}
|
|
159
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
160
|
-
return query('$host', targetOrOptions as SwcQueryOptions);
|
|
161
|
-
} else {
|
|
162
|
-
return query('$host', {});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @appHost - Query $appHost (Nearest <swc-app>)
|
|
168
|
-
*/
|
|
169
|
-
export function queryAppHost(target: Object, propertyKey: string | symbol): void;
|
|
170
|
-
export function queryAppHost(): PropertyDecorator;
|
|
171
|
-
export function queryAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
172
|
-
export function queryAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
173
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
174
|
-
return query('$appHost', {})(targetOrOptions, propertyKey);
|
|
175
|
-
}
|
|
176
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
177
|
-
return query('$appHost', targetOrOptions as SwcQueryOptions);
|
|
178
|
-
} else {
|
|
179
|
-
return query('$appHost', {});
|
|
79
|
+
return (this.shadowRoot || this).querySelector(selector);
|
|
80
|
+
},
|
|
81
|
+
set(this: HTMLElement, nv: any) {
|
|
82
|
+
ensureInit(this);
|
|
83
|
+
if (nv === null || nv === undefined) {
|
|
84
|
+
const selector = selectorOrTarget;
|
|
85
|
+
if (selector.startsWith('$') && selector !== '$this') return;
|
|
86
|
+
|
|
87
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
88
|
+
const targets: Element[] = [];
|
|
89
|
+
|
|
90
|
+
if (r === 'shadow') {
|
|
91
|
+
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
92
|
+
} else if (r === 'light') {
|
|
93
|
+
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
94
|
+
} else if (r === 'all') {
|
|
95
|
+
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
96
|
+
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
97
|
+
} else {
|
|
98
|
+
const el = (this.shadowRoot || this).querySelector(selector);
|
|
99
|
+
if (el) targets.push(el);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
targets.forEach(t => t.remove());
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true
|
|
107
|
+
});
|
|
108
|
+
};
|
|
180
109
|
}
|
|
110
|
+
// Without selector (defaults to $this)
|
|
111
|
+
return query('$this', selectorOrTarget as SwcQueryOptions);
|
|
181
112
|
}
|
|
182
113
|
|
|
183
114
|
export const getQueryMetadata = (target: any): QueryMetadata[] => {
|