@dooboostore/simple-web-component 1.0.48 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +387 -29
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +237 -437
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +140 -0
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +87 -0
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +388 -29
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +244 -444
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +3 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +141 -0
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +88 -0
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2565 -1474
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +84 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +0 -14
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +3 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +35 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +34 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2565 -1474
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -5
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +394 -34
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +281 -580
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +3 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +215 -39
- package/src/decorators/query.ts +168 -126
- package/src/decorators/resizeObserver.ts +152 -46
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
|
@@ -1,46 +1,33 @@
|
|
|
1
1
|
import {ReflectUtils, FunctionUtils, ActionExpression} from '@dooboostore/core';
|
|
2
2
|
import {ensureInit, getElementConfig} from './elementDefine';
|
|
3
3
|
import {SwcUtils} from '../utils/Utils';
|
|
4
|
-
import {SwcQueryOptions, HelperHostSet} from '../types';
|
|
4
|
+
import {SwcQueryOptions, HelperHostSet, SwcFnSelector, SwcSelector} from '../types';
|
|
5
5
|
import {ConvertUtils} from '@dooboostore/core-web';
|
|
6
6
|
|
|
7
7
|
// ============================================
|
|
8
8
|
// Types & Interfaces
|
|
9
9
|
// ============================================
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// 공통 옵션 — root 없음
|
|
12
|
+
export interface AttributeBaseOptions {
|
|
12
13
|
name?: string;
|
|
13
14
|
type?: typeof Number | typeof Boolean | typeof String;
|
|
14
15
|
filter?: (target: HTMLElement, value: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Custom key to extract value from return object.
|
|
17
|
-
* If not provided, uses ATTRIBUTE_METADATA_KEY by default.
|
|
18
|
-
* Useful when multiple @setAttribute decorators are on the same method.
|
|
19
|
-
*
|
|
20
|
-
* Example:
|
|
21
|
-
* @setAttribute('selector1', { valueKey: 'attr1' })
|
|
22
|
-
* @setAttribute('selector2', { valueKey: 'attr2' })
|
|
23
|
-
* myMethod() {
|
|
24
|
-
* return {
|
|
25
|
-
* attr1: 'value1',
|
|
26
|
-
* attr2: 'value2'
|
|
27
|
-
* };
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* Or with symbols:
|
|
31
|
-
* @setAttribute('selector1', { valueKey: Symbol.for('attr1') })
|
|
32
|
-
* @setAttribute('selector2', { valueKey: Symbol.for('attr2') })
|
|
33
|
-
* myMethod() {
|
|
34
|
-
* return {
|
|
35
|
-
* [Symbol.for('attr1')]: 'value1',
|
|
36
|
-
* [Symbol.for('attr2')]: 'value2'
|
|
37
|
-
* };
|
|
38
|
-
* }
|
|
39
|
-
*/
|
|
40
16
|
valueKey?: symbol | string;
|
|
41
17
|
}
|
|
42
18
|
|
|
43
|
-
|
|
19
|
+
// 문자열 셀렉터 전용 — root 허용 (컴포넌트 DOM 트리 안에서 탐색)
|
|
20
|
+
export type AttributeQueryOptions = AttributeBaseOptions & SwcQueryOptions;
|
|
21
|
+
// 함수 셀렉터 전용 — root 금지 (이미 요소를 직접 반환)
|
|
22
|
+
export type AttributeNonQueryOptions = AttributeBaseOptions;
|
|
23
|
+
// 내부 저장/해석용 — root optional이라 두 종류 모두 저장 가능
|
|
24
|
+
export type AttributeOptions = AttributeQueryOptions;
|
|
25
|
+
|
|
26
|
+
export type AttributeFnSelector = SwcFnSelector;
|
|
27
|
+
export type AttributeSelector = SwcSelector;
|
|
28
|
+
|
|
29
|
+
// 셀렉터 종류에 따라 옵션 타입 분기
|
|
30
|
+
export type AttributeOptionsOf<S extends AttributeSelector> = S extends string ? AttributeQueryOptions : AttributeNonQueryOptions;
|
|
44
31
|
|
|
45
32
|
export interface AttributeMetadata {
|
|
46
33
|
propertyKey: string | symbol;
|
|
@@ -143,7 +130,7 @@ export const resolveAttributeTargets = (inst: any, selector: AttributeSelector,
|
|
|
143
130
|
const results: HTMLElement[] = [];
|
|
144
131
|
|
|
145
132
|
// Resolve selector if it's a function
|
|
146
|
-
let resolvedSelector: string | Element | NodeList | Element[] | null = selector as any;
|
|
133
|
+
let resolvedSelector: string | Node | Element | NodeList | Element[] | null = selector as any;
|
|
147
134
|
if (typeof selector === 'function') {
|
|
148
135
|
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
|
|
149
136
|
resolvedSelector = selector(inst, hostSet);
|
|
@@ -223,9 +210,9 @@ export const resolveAttributeTargets = (inst: any, selector: AttributeSelector,
|
|
|
223
210
|
* - @applyAttribute((this, helper) => 'selector', 'attrName') - Function-based selector
|
|
224
211
|
* - Return null to remove attribute
|
|
225
212
|
*/
|
|
226
|
-
export function applyAttribute(selector:
|
|
227
|
-
export function applyAttribute(selector:
|
|
228
|
-
export function applyAttribute(selector: AttributeSelector, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator
|
|
213
|
+
export function applyAttribute<S extends AttributeSelector>(selector: S, targetAttributeName: string, options?: AttributeOptionsOf<S>): MethodDecorator & PropertyDecorator;
|
|
214
|
+
export function applyAttribute<S extends AttributeSelector>(selector: S, options?: AttributeOptionsOf<S>): MethodDecorator & PropertyDecorator;
|
|
215
|
+
export function applyAttribute(selector: AttributeSelector, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator {
|
|
229
216
|
return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
|
|
230
217
|
// ensureInit(target as any);
|
|
231
218
|
|
|
@@ -383,8 +370,9 @@ export function applyAttribute(selector: AttributeSelector, targetAttributeNameO
|
|
|
383
370
|
*/
|
|
384
371
|
export function attribute(target: Object, propertyKey: string | symbol): void;
|
|
385
372
|
export function attribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
386
|
-
export function attribute(attributeName: string, options?:
|
|
387
|
-
export function attribute(selector:
|
|
373
|
+
export function attribute(attributeName: string, options?: AttributeQueryOptions): PropertyDecorator;
|
|
374
|
+
export function attribute(selector: string, attributeName: string, options?: AttributeQueryOptions): PropertyDecorator;
|
|
375
|
+
export function attribute(selector: AttributeFnSelector, attributeName: string, options?: AttributeNonQueryOptions): PropertyDecorator;
|
|
388
376
|
export function attribute(selectorOrAttributeOrTarget?: AttributeSelector | Object, attributeNameOrOptions?: any, optionsOrDescriptor?: any): any {
|
|
389
377
|
// Bare decorator: @attribute
|
|
390
378
|
if (optionsOrDescriptor !== undefined && (typeof attributeNameOrOptions === 'string' || typeof attributeNameOrOptions === 'symbol')) {
|
|
@@ -434,9 +422,14 @@ export function attribute(selectorOrAttributeOrTarget?: AttributeSelector | Obje
|
|
|
434
422
|
* return 'active';
|
|
435
423
|
* }
|
|
436
424
|
*/
|
|
437
|
-
export function setAttribute(selector:
|
|
438
|
-
export function setAttribute(attributeName: string, options?:
|
|
425
|
+
export function setAttribute(selector: string, attributeName: string, options?: AttributeQueryOptions): MethodDecorator;
|
|
426
|
+
export function setAttribute(selector: AttributeFnSelector, attributeName: string, options?: AttributeNonQueryOptions): MethodDecorator;
|
|
427
|
+
export function setAttribute(attributeName: string, options?: AttributeQueryOptions): MethodDecorator;
|
|
439
428
|
export function setAttribute(selectorOrAttributeOrOptions?: AttributeSelector | AttributeOptions, attributeNameOrOptions?: any, optionsOrUndefined?: AttributeOptions): MethodDecorator {
|
|
429
|
+
// Function selector: @setAttribute((c, helper) => ..., 'attr', options?)
|
|
430
|
+
if (typeof selectorOrAttributeOrOptions === 'function') {
|
|
431
|
+
return applyAttribute(selectorOrAttributeOrOptions as AttributeSelector, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;
|
|
432
|
+
}
|
|
440
433
|
// With string as first parameter
|
|
441
434
|
if (typeof selectorOrAttributeOrOptions === 'string') {
|
|
442
435
|
// Check if first parameter is a CSS selector or attribute name
|
|
@@ -477,5 +470,26 @@ export const findAllAttributeApplyMetadata = (target: any): Map<string | symbol,
|
|
|
477
470
|
return result;
|
|
478
471
|
};
|
|
479
472
|
|
|
473
|
+
// ─── Aliases ───
|
|
474
|
+
// attribute(필드) / setAttribute(메서드)와 구분되는 일반 데코레이터 단축명
|
|
475
|
+
export const attr = applyAttribute;
|
|
476
|
+
|
|
477
|
+
// ─── 편의 헬퍼 (selector/root 생략) ───
|
|
478
|
+
|
|
479
|
+
export function attrThis(targetAttributeName?: string, options?: AttributeQueryOptions): MethodDecorator {
|
|
480
|
+
return applyAttribute('$this', targetAttributeName, options);
|
|
481
|
+
}
|
|
482
|
+
export function attrAppHost(targetAttributeName?: string, options?: AttributeQueryOptions): MethodDecorator {
|
|
483
|
+
return applyAttribute('$appHost', targetAttributeName, options);
|
|
484
|
+
}
|
|
485
|
+
export function attrLight(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {
|
|
486
|
+
return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'light'});
|
|
487
|
+
}
|
|
488
|
+
export function attrShadow(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {
|
|
489
|
+
return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'shadow'});
|
|
490
|
+
}
|
|
491
|
+
export function attrAll(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {
|
|
492
|
+
return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'all'});
|
|
493
|
+
}
|
|
480
494
|
|
|
481
495
|
export default applyAttribute;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
|
|
4
|
+
import { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';
|
|
5
5
|
|
|
6
6
|
export const CLASS_METADATA_KEY = Symbol.for('simple-web-component:class');
|
|
7
7
|
|
|
@@ -28,6 +28,9 @@ const resolveSelector = (selector: ClassSelector, inst: any, win: Window): strin
|
|
|
28
28
|
if (result === null) {
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
31
|
+
if (result instanceof win.Node) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
31
34
|
return result as string;
|
|
32
35
|
}
|
|
33
36
|
return selector as string;
|
|
@@ -74,17 +77,24 @@ const getTargetElements = (selector: ClassSelector, inst: any, win: Window, root
|
|
|
74
77
|
return targetEls;
|
|
75
78
|
};
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
// 공통 옵션 — root 없음
|
|
81
|
+
export interface ClassBaseOptions {
|
|
78
82
|
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Custom key to extract value from return object.
|
|
81
|
-
* If not provided, uses CLASS_METADATA_KEY by default.
|
|
82
|
-
* Useful when multiple @applyClass decorators are on the same method.
|
|
83
|
-
*/
|
|
84
83
|
valueKey?: symbol | string;
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
// 문자열 셀렉터 전용 — root 허용 (classMapOrOptions 판별을 위해 root 필요)
|
|
87
|
+
export type ClassQueryOptions = ClassBaseOptions & SwcQueryOptions;
|
|
88
|
+
// 함수 셀렉터 전용 — root 금지. 단, classMapOrOptions의 options 자리에 올 수 없음(root가 없어 classMap과 판별 불가)
|
|
89
|
+
export type ClassNonQueryOptions = ClassBaseOptions;
|
|
90
|
+
export type ClassApplyOptions = ClassQueryOptions;
|
|
91
|
+
|
|
92
|
+
export type ClassFnSelector = SwcFnSelector;
|
|
93
|
+
export type ClassSelector = SwcSelector;
|
|
94
|
+
export type ClassMapType = { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean };
|
|
95
|
+
|
|
96
|
+
// 셀렉터 종류에 따라 옵션 타입 분기
|
|
97
|
+
export type ClassOptionsOf<S extends ClassSelector> = S extends string ? ClassQueryOptions : ClassNonQueryOptions;
|
|
88
98
|
|
|
89
99
|
export interface ClassApplyMetadata {
|
|
90
100
|
propertyKey: string | symbol;
|
|
@@ -210,14 +220,15 @@ function createClassDecorator(action: ClassAction) {
|
|
|
210
220
|
}
|
|
211
221
|
|
|
212
222
|
export function applyClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
213
|
-
export function applyClass(selector:
|
|
223
|
+
export function applyClass(selector: string, action?: ClassAction, options?: ClassQueryOptions): MethodDecorator;
|
|
224
|
+
export function applyClass(selector: ClassFnSelector, action?: ClassAction, options?: ClassNonQueryOptions): MethodDecorator;
|
|
214
225
|
export function applyClass(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
215
226
|
// Bare decorator: @applyClass
|
|
216
|
-
if (optionsOrDescriptor !== undefined && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
|
|
227
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
|
|
217
228
|
return createClassDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
218
229
|
}
|
|
219
230
|
// With selector
|
|
220
|
-
if (typeof selectorOrTarget === 'string') {
|
|
231
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
221
232
|
const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as ClassAction;
|
|
222
233
|
const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as ClassApplyOptions | undefined;
|
|
223
234
|
return createClassDecorator(action)(selectorOrTarget, options);
|
|
@@ -229,14 +240,15 @@ export function applyClass(selectorOrTarget?: any, actionOrPropertyKey?: any, op
|
|
|
229
240
|
}
|
|
230
241
|
|
|
231
242
|
export function setClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
232
|
-
export function setClass(selector:
|
|
243
|
+
export function setClass(selector: string, classMapOrOptions?: string | ClassMapType | ClassQueryOptions, options?: ClassQueryOptions): MethodDecorator;
|
|
244
|
+
export function setClass(selector: ClassFnSelector, classMap: string | ClassMapType): MethodDecorator;
|
|
233
245
|
export function setClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
234
246
|
// Bare decorator: @setClass
|
|
235
|
-
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
247
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
236
248
|
return createClassDecorator('set')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
237
249
|
}
|
|
238
250
|
// With selector
|
|
239
|
-
if (typeof selectorOrTarget === 'string') {
|
|
251
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
240
252
|
return createClassDecorator('set')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
241
253
|
}
|
|
242
254
|
// Without selector (defaults to $this)
|
|
@@ -244,14 +256,15 @@ export function setClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?
|
|
|
244
256
|
}
|
|
245
257
|
|
|
246
258
|
export function updateClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
247
|
-
export function updateClass(selector:
|
|
259
|
+
export function updateClass(selector: string, classMapOrOptions?: string | ClassMapType | ClassQueryOptions, options?: ClassQueryOptions): MethodDecorator;
|
|
260
|
+
export function updateClass(selector: ClassFnSelector, classMap: string | ClassMapType): MethodDecorator;
|
|
248
261
|
export function updateClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
249
262
|
// Bare decorator: @updateClass
|
|
250
|
-
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
263
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
251
264
|
return createClassDecorator('update')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
252
265
|
}
|
|
253
266
|
// With selector
|
|
254
|
-
if (typeof selectorOrTarget === 'string') {
|
|
267
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
255
268
|
return createClassDecorator('update')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
256
269
|
}
|
|
257
270
|
// Without selector (defaults to $this)
|
|
@@ -259,14 +272,15 @@ export function updateClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyK
|
|
|
259
272
|
}
|
|
260
273
|
|
|
261
274
|
export function addClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
262
|
-
export function addClass(selector:
|
|
275
|
+
export function addClass(selector: string, classMapOrOptions?: string | ClassMapType | ClassQueryOptions, options?: ClassQueryOptions): MethodDecorator;
|
|
276
|
+
export function addClass(selector: ClassFnSelector, classMap: string | ClassMapType): MethodDecorator;
|
|
263
277
|
export function addClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
264
278
|
// Bare decorator: @addClass
|
|
265
|
-
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
279
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
266
280
|
return createClassDecorator('add')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
267
281
|
}
|
|
268
282
|
// With selector
|
|
269
|
-
if (typeof selectorOrTarget === 'string') {
|
|
283
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
270
284
|
return createClassDecorator('add')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
271
285
|
}
|
|
272
286
|
// Without selector (defaults to $this)
|
|
@@ -274,14 +288,15 @@ export function addClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?
|
|
|
274
288
|
}
|
|
275
289
|
|
|
276
290
|
export function removeClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
277
|
-
export function removeClass(selector:
|
|
291
|
+
export function removeClass(selector: string, classMapOrOptions?: string | ClassMapType | ClassQueryOptions, options?: ClassQueryOptions): MethodDecorator;
|
|
292
|
+
export function removeClass(selector: ClassFnSelector, classMap: string | ClassMapType): MethodDecorator;
|
|
278
293
|
export function removeClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
279
294
|
// Bare decorator: @removeClass
|
|
280
|
-
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
295
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
281
296
|
return createClassDecorator('remove')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
282
297
|
}
|
|
283
298
|
// With selector
|
|
284
|
-
if (typeof selectorOrTarget === 'string') {
|
|
299
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
285
300
|
return createClassDecorator('remove')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
286
301
|
}
|
|
287
302
|
// Without selector (defaults to $this)
|
|
@@ -289,20 +304,55 @@ export function removeClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyK
|
|
|
289
304
|
}
|
|
290
305
|
|
|
291
306
|
export function toggleClass(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
292
|
-
export function toggleClass(selector:
|
|
307
|
+
export function toggleClass(selector: string, classMapOrOptions?: string | ClassMapType | ClassQueryOptions, options?: ClassQueryOptions): MethodDecorator;
|
|
308
|
+
export function toggleClass(selector: ClassFnSelector, classMap: string | ClassMapType): MethodDecorator;
|
|
293
309
|
export function toggleClass(selectorOrTarget?: any, classMapOrOptionsOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
294
310
|
// Bare decorator: @toggleClass
|
|
295
|
-
if (optionsOrDescriptor !== undefined && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
311
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof classMapOrOptionsOrPropertyKey === 'string' || typeof classMapOrOptionsOrPropertyKey === 'symbol')) {
|
|
296
312
|
return createClassDecorator('toggle')('$this', {})(selectorOrTarget as Object, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
297
313
|
}
|
|
298
314
|
// With selector
|
|
299
|
-
if (typeof selectorOrTarget === 'string') {
|
|
315
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
300
316
|
return createClassDecorator('toggle')(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor as ClassApplyOptions);
|
|
301
317
|
}
|
|
302
318
|
// Without selector (defaults to $this)
|
|
303
319
|
return createClassDecorator('toggle')('$this', selectorOrTarget as ClassApplyOptions);
|
|
304
320
|
}
|
|
305
321
|
|
|
322
|
+
// ─── Aliases ───
|
|
323
|
+
// class는 예약어라 cls 사용
|
|
324
|
+
export const cls = applyClass;
|
|
325
|
+
|
|
326
|
+
// ─── 편의 헬퍼 (selector/root 생략) ───
|
|
327
|
+
|
|
328
|
+
export function clsThis(action?: ClassAction, options?: ClassQueryOptions): MethodDecorator {
|
|
329
|
+
return applyClass('$this', action, options);
|
|
330
|
+
}
|
|
331
|
+
export function clsAppHost(action?: ClassAction, options?: ClassQueryOptions): MethodDecorator {
|
|
332
|
+
return applyClass('$appHost', action, options);
|
|
333
|
+
}
|
|
334
|
+
export function clsLight(selector: string, action?: ClassAction, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
335
|
+
export function clsLight(selector: string, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
336
|
+
export function clsLight(selector: string, actionOrOptions?: ClassAction | Omit<ClassQueryOptions, 'root'>, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator {
|
|
337
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as ClassAction | undefined;
|
|
338
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<ClassQueryOptions, 'root'> | undefined;
|
|
339
|
+
return applyClass(selector, action, {...opts ?? {}, root: 'light'});
|
|
340
|
+
}
|
|
341
|
+
export function clsShadow(selector: string, action?: ClassAction, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
342
|
+
export function clsShadow(selector: string, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
343
|
+
export function clsShadow(selector: string, actionOrOptions?: ClassAction | Omit<ClassQueryOptions, 'root'>, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator {
|
|
344
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as ClassAction | undefined;
|
|
345
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<ClassQueryOptions, 'root'> | undefined;
|
|
346
|
+
return applyClass(selector, action, {...opts ?? {}, root: 'shadow'});
|
|
347
|
+
}
|
|
348
|
+
export function clsAll(selector: string, action?: ClassAction, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
349
|
+
export function clsAll(selector: string, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator;
|
|
350
|
+
export function clsAll(selector: string, actionOrOptions?: ClassAction | Omit<ClassQueryOptions, 'root'>, options?: Omit<ClassQueryOptions, 'root'>): MethodDecorator {
|
|
351
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as ClassAction | undefined;
|
|
352
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<ClassQueryOptions, 'root'> | undefined;
|
|
353
|
+
return applyClass(selector, action, {...opts ?? {}, root: 'all'});
|
|
354
|
+
}
|
|
355
|
+
|
|
306
356
|
export const findAllClassMetadata = (target: any): Map<string | symbol, ClassApplyMetadata> => {
|
|
307
357
|
const result = new Map<string | symbol, ClassApplyMetadata>();
|
|
308
358
|
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ClassApplyMetadata>>(CLASS_METADATA_KEY, target);
|