@dooboostore/simple-web-component 1.0.47 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -27
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +412 -16
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +244 -225
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +5 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +244 -0
- package/dist/cjs/decorators/mutationObserver.js.map +7 -0
- package/dist/cjs/decorators/query.js +129 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +191 -0
- package/dist/cjs/decorators/resizeObserver.js.map +7 -0
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +413 -16
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +249 -230
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +5 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +226 -0
- package/dist/esm/decorators/mutationObserver.js.map +7 -0
- package/dist/esm/decorators/query.js +129 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +173 -0
- package/dist/esm/decorators/resizeObserver.js.map +7 -0
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2413 -889
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +93 -23
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +5 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +46 -0
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +63 -8
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +48 -0
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -0
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2413 -889
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +426 -23
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +301 -317
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +5 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +304 -0
- package/src/decorators/query.ts +182 -117
- package/src/decorators/resizeObserver.ts +235 -0
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAppMixin.js +0 -1
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsync.js +0 -1
- package/dist/cjs/elements/tt/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChoose.js +0 -1
- package/dist/cjs/elements/tt/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIf.js +0 -1
- package/dist/cjs/elements/tt/SwcIf.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoop.js +0 -1
- package/dist/cjs/elements/tt/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/tt/register.js +0 -1
- package/dist/cjs/elements/tt/register.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/elements/tt/SwcAppMixin.js +0 -1
- package/dist/esm/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsync.js +0 -1
- package/dist/esm/elements/tt/SwcAsync.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcChoose.js +0 -1
- package/dist/esm/elements/tt/SwcChoose.js.map +0 -7
- package/dist/esm/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcIf.js +0 -1
- package/dist/esm/elements/tt/SwcIf.js.map +0 -7
- package/dist/esm/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoop.js +0 -1
- package/dist/esm/elements/tt/SwcLoop.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/tt/register.js +0 -1
- package/dist/esm/elements/tt/register.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/tt/register.d.ts +0 -1
- package/dist/types/elements/tt/register.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/elements/tt/SwcAppMixin.ts +0 -13
- package/src/elements/tt/SwcAsync.ts +0 -139
- package/src/elements/tt/SwcAsyncTemplate.ts +0 -126
- package/src/elements/tt/SwcChoose.ts +0 -182
- package/src/elements/tt/SwcChooseTemplate.ts +0 -229
- package/src/elements/tt/SwcIf.ts +0 -145
- package/src/elements/tt/SwcIfTemplate.ts +0 -158
- package/src/elements/tt/SwcLoop.ts +0 -222
- package/src/elements/tt/SwcLoopTemplate.ts +0 -255
- package/src/elements/tt/SwcSubTemplates.ts +0 -6
- package/src/elements/tt/register.ts +0 -720
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { ensureInit, getElementConfig } from './elementDefine';
|
|
3
|
-
import {SpecialSelector, SwcQueryOptions, HelperHostSet, SwcRootType} from '../types';
|
|
3
|
+
import {SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet, SwcRootType} from '../types';
|
|
4
4
|
import { SwcUtils} from "../utils/Utils";
|
|
5
5
|
import {findAllStateMetadata} from "./state";
|
|
6
6
|
import {ElementApply} from "@dooboostore/core-web";
|
|
@@ -15,28 +15,26 @@ import {ElementApply} from "@dooboostore/core-web";
|
|
|
15
15
|
*/
|
|
16
16
|
export type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove' | 'clearChildren';
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type ApplyNodeFnSelector = SwcFnSelector;
|
|
19
|
+
export type ApplyNodeSelector = SwcSelector;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
// 공통 옵션 — root 없음
|
|
22
|
+
export interface ApplyNodeBaseOptions {
|
|
21
23
|
position?: ApplyNodePosition;
|
|
22
|
-
root?: SwcRootType;
|
|
23
|
-
/**
|
|
24
|
-
* Filter function to determine whether to perform DOM operation.
|
|
25
|
-
* If it returns false, the operation is skipped.
|
|
26
|
-
*/
|
|
27
24
|
filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Optional loading content to display while an async method is executing.
|
|
30
|
-
*/
|
|
31
25
|
fallback?: (helper: HelperHostSet) => any;
|
|
32
|
-
/**
|
|
33
|
-
* Custom key to extract value from return object.
|
|
34
|
-
* If not provided, uses APPLY_NODE_METADATA_KEY by default.
|
|
35
|
-
* Useful when multiple @applyNode decorators are on the same method.
|
|
36
|
-
*/
|
|
37
26
|
valueKey?: symbol | string;
|
|
38
27
|
}
|
|
39
28
|
|
|
29
|
+
// 문자열 셀렉터 전용 — root 허용
|
|
30
|
+
export type ApplyNodeQueryOptions = ApplyNodeBaseOptions & { root?: SwcRootType };
|
|
31
|
+
// 함수 셀렉터 전용 — root 금지
|
|
32
|
+
export type ApplyNodeNonQueryOptions = ApplyNodeBaseOptions;
|
|
33
|
+
export type ApplyNodeOptions = ApplyNodeQueryOptions;
|
|
34
|
+
|
|
35
|
+
// 셀렉터 종류에 따라 옵션 타입 분기
|
|
36
|
+
export type ApplyNodeOptionsOf<S extends ApplyNodeSelector> = S extends string ? ApplyNodeQueryOptions : ApplyNodeNonQueryOptions;
|
|
37
|
+
|
|
40
38
|
export interface ApplyNodeMetadata {
|
|
41
39
|
propertyKey: string | symbol;
|
|
42
40
|
selector: ApplyNodeSelector;
|
|
@@ -141,8 +139,9 @@ const applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string,
|
|
|
141
139
|
* - applyNode(selector, options) - Apply to specific selector
|
|
142
140
|
* - applyNode(options) - Apply to $this (current element)
|
|
143
141
|
*/
|
|
144
|
-
export function applyNode(selector:
|
|
145
|
-
export function applyNode(
|
|
142
|
+
export function applyNode(selector: string, options?: ApplyNodeQueryOptions): MethodDecorator;
|
|
143
|
+
export function applyNode(selector: ApplyNodeFnSelector, options?: ApplyNodeNonQueryOptions): MethodDecorator;
|
|
144
|
+
export function applyNode(options: ApplyNodeQueryOptions): MethodDecorator;
|
|
146
145
|
export function applyNode(selectorOrOptions: ApplyNodeSelector | ApplyNodeOptions, maybeOptions?: ApplyNodeOptions): MethodDecorator {
|
|
147
146
|
// Determine selector and options based on overload
|
|
148
147
|
let selector: ApplyNodeSelector;
|
|
@@ -278,8 +277,13 @@ export function applyNode(selectorOrOptions: ApplyNodeSelector | ApplyNodeOption
|
|
|
278
277
|
* - replaceChildrenNode(options) - Replace children of $this (current element)
|
|
279
278
|
* - @replaceChildrenNode - Bare decorator, replaces children of $this
|
|
280
279
|
*/
|
|
281
|
-
export
|
|
282
|
-
export
|
|
280
|
+
export type ApplyNodeQueryOptionsNoPos = Omit<ApplyNodeQueryOptions, 'position'>;
|
|
281
|
+
export type ApplyNodeNonQueryOptionsNoPos = Omit<ApplyNodeNonQueryOptions, 'position'>;
|
|
282
|
+
export type ApplyNodeOptionsOfNoPos<S extends ApplyNodeSelector> = S extends string ? ApplyNodeQueryOptionsNoPos : ApplyNodeNonQueryOptionsNoPos;
|
|
283
|
+
|
|
284
|
+
export function replaceChildren(selector: string, options?: ApplyNodeQueryOptionsNoPos): MethodDecorator;
|
|
285
|
+
export function replaceChildren(selector: ApplyNodeFnSelector, options?: ApplyNodeNonQueryOptionsNoPos): MethodDecorator;
|
|
286
|
+
export function replaceChildren(options: ApplyNodeQueryOptionsNoPos): MethodDecorator;
|
|
283
287
|
export function replaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
284
288
|
export function replaceChildren(selectorOrOptions?: ApplyNodeSelector | Omit<ApplyNodeOptions, 'position'> | Object, maybeOptions?: Omit<ApplyNodeOptions, 'position'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | PropertyDescriptor | void {
|
|
285
289
|
// Bare decorator usage: @replaceChildrenNode
|
|
@@ -288,7 +292,7 @@ export function replaceChildren(selectorOrOptions?: ApplyNodeSelector | Omit<App
|
|
|
288
292
|
}
|
|
289
293
|
|
|
290
294
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
291
|
-
return applyNode(selectorOrOptions as
|
|
295
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'replaceChildren'});
|
|
292
296
|
}
|
|
293
297
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'replaceChildren'});
|
|
294
298
|
}
|
|
@@ -311,7 +315,7 @@ export function clearChildrenNode(selectorOrOptions?: ApplyNodeSelector | Omit<A
|
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
314
|
-
return applyNode(selectorOrOptions as
|
|
318
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'clearChildren'});
|
|
315
319
|
}
|
|
316
320
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'clearChildren'});
|
|
317
321
|
}
|
|
@@ -337,7 +341,7 @@ export function innerHtml(selectorOrOptions?: ApplyNodeSelector | Omit<ApplyNode
|
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
340
|
-
return applyNode(selectorOrOptions as
|
|
344
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'innerHtml'});
|
|
341
345
|
}
|
|
342
346
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'innerHtml'});
|
|
343
347
|
}
|
|
@@ -363,7 +367,7 @@ export function innerHtmlLight(selectorOrOptions?: ApplyNodeSelector | Omit<Appl
|
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
366
|
-
return applyNode(selectorOrOptions as
|
|
370
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerHtml', root: 'light'});
|
|
367
371
|
}
|
|
368
372
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerHtml', root: 'light'});
|
|
369
373
|
}
|
|
@@ -387,7 +391,7 @@ export function innerHtmlShadow(selectorOrOptions?: ApplyNodeSelector | Omit<App
|
|
|
387
391
|
}
|
|
388
392
|
|
|
389
393
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
390
|
-
return applyNode(selectorOrOptions as
|
|
394
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerHtml', root: 'shadow'});
|
|
391
395
|
}
|
|
392
396
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerHtml', root: 'shadow'});
|
|
393
397
|
}
|
|
@@ -411,7 +415,7 @@ export function innerText(selectorOrOptions?: ApplyNodeSelector | Omit<ApplyNode
|
|
|
411
415
|
}
|
|
412
416
|
|
|
413
417
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
414
|
-
return applyNode(selectorOrOptions as
|
|
418
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'innerText'});
|
|
415
419
|
}
|
|
416
420
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'innerText'});
|
|
417
421
|
}
|
|
@@ -435,7 +439,7 @@ export function innerTextLight(selectorOrOptions?: ApplyNodeSelector | Omit<Appl
|
|
|
435
439
|
}
|
|
436
440
|
|
|
437
441
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
438
|
-
return applyNode(selectorOrOptions as
|
|
442
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerText', root: 'light'});
|
|
439
443
|
}
|
|
440
444
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerText', root: 'light'});
|
|
441
445
|
}
|
|
@@ -458,7 +462,7 @@ export function innerTextShadow(selectorOrOptions?: ApplyNodeSelector | Omit<App
|
|
|
458
462
|
}
|
|
459
463
|
|
|
460
464
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
461
|
-
return applyNode(selectorOrOptions as
|
|
465
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerText', root: 'shadow'});
|
|
462
466
|
}
|
|
463
467
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'innerText', root: 'shadow'});
|
|
464
468
|
}
|
|
@@ -481,7 +485,7 @@ export function insertBeforeEnd(selectorOrOptions?: ApplyNodeSelector | Omit<App
|
|
|
481
485
|
}
|
|
482
486
|
|
|
483
487
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
484
|
-
return applyNode(selectorOrOptions as
|
|
488
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'beforeEnd'});
|
|
485
489
|
}
|
|
486
490
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'beforeEnd'});
|
|
487
491
|
}
|
|
@@ -505,7 +509,7 @@ export function insertBeforeEndLight(selectorOrOptions?: ApplyNodeSelector | Omi
|
|
|
505
509
|
}
|
|
506
510
|
|
|
507
511
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
508
|
-
return applyNode(selectorOrOptions as
|
|
512
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'beforeEnd', root: 'light'});
|
|
509
513
|
}
|
|
510
514
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'beforeEnd', root: 'light'});
|
|
511
515
|
}
|
|
@@ -529,7 +533,7 @@ export function insertBeforeEndShadow(selectorOrOptions?: ApplyNodeSelector | Om
|
|
|
529
533
|
}
|
|
530
534
|
|
|
531
535
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
532
|
-
return applyNode(selectorOrOptions as
|
|
536
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'beforeEnd', root: 'shadow'});
|
|
533
537
|
}
|
|
534
538
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'beforeEnd', root: 'shadow'});
|
|
535
539
|
}
|
|
@@ -553,7 +557,7 @@ export function insertAfterBegin(selectorOrOptions?: ApplyNodeSelector | Omit<Ap
|
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
556
|
-
return applyNode(selectorOrOptions as
|
|
560
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position'>, position: 'afterBegin'});
|
|
557
561
|
}
|
|
558
562
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position'>, position: 'afterBegin'});
|
|
559
563
|
}
|
|
@@ -577,7 +581,7 @@ export function insertAfterBeginLight(selectorOrOptions?: ApplyNodeSelector | Om
|
|
|
577
581
|
}
|
|
578
582
|
|
|
579
583
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
580
|
-
return applyNode(selectorOrOptions as
|
|
584
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'afterBegin', root: 'light'});
|
|
581
585
|
}
|
|
582
586
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'afterBegin', root: 'light'});
|
|
583
587
|
}
|
|
@@ -601,7 +605,7 @@ export function replaceChildrenLight(selectorOrOptions?: ApplyNodeSelector | Omi
|
|
|
601
605
|
}
|
|
602
606
|
|
|
603
607
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
604
|
-
return applyNode(selectorOrOptions as
|
|
608
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'replaceChildren', root: 'light'});
|
|
605
609
|
}
|
|
606
610
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'replaceChildren', root: 'light'});
|
|
607
611
|
}
|
|
@@ -624,7 +628,7 @@ export function clearChildrenLight(selectorOrOptions?: ApplyNodeSelector | Omit<
|
|
|
624
628
|
}
|
|
625
629
|
|
|
626
630
|
if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {
|
|
627
|
-
return applyNode(selectorOrOptions as
|
|
631
|
+
return applyNode(selectorOrOptions as any, {...maybeOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'clearChildren', root: 'light'});
|
|
628
632
|
}
|
|
629
633
|
return applyNode({...selectorOrOptions as Omit<ApplyNodeOptions, 'position' | 'root'>, position: 'clearChildren', root: 'light'});
|
|
630
634
|
}
|
|
@@ -632,6 +636,28 @@ export function clearChildrenLight(selectorOrOptions?: ApplyNodeSelector | Omit<
|
|
|
632
636
|
|
|
633
637
|
|
|
634
638
|
|
|
639
|
+
// ─── Aliases ───
|
|
640
|
+
export const apply = applyNode;
|
|
641
|
+
export const node = applyNode;
|
|
642
|
+
|
|
643
|
+
// ─── 편의 헬퍼 (selector/root 생략) ───
|
|
644
|
+
|
|
645
|
+
export function applyThis(options?: ApplyNodeQueryOptions): MethodDecorator {
|
|
646
|
+
return applyNode('$this', options);
|
|
647
|
+
}
|
|
648
|
+
export function applyAppHost(options?: ApplyNodeQueryOptions): MethodDecorator {
|
|
649
|
+
return applyNode('$appHost', options);
|
|
650
|
+
}
|
|
651
|
+
export function applyLight(selector: string, options?: Omit<ApplyNodeQueryOptions, 'root'>): MethodDecorator {
|
|
652
|
+
return applyNode(selector, {...options ?? {}, root: 'light'});
|
|
653
|
+
}
|
|
654
|
+
export function applyShadow(selector: string, options?: Omit<ApplyNodeQueryOptions, 'root'>): MethodDecorator {
|
|
655
|
+
return applyNode(selector, {...options ?? {}, root: 'shadow'});
|
|
656
|
+
}
|
|
657
|
+
export function applyAll(selector: string, options?: Omit<ApplyNodeQueryOptions, 'root'>): MethodDecorator {
|
|
658
|
+
return applyNode(selector, {...options ?? {}, root: 'all'});
|
|
659
|
+
}
|
|
660
|
+
|
|
635
661
|
export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {
|
|
636
662
|
const result = new Map<string | symbol, ApplyNodeMetadata>();
|
|
637
663
|
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);
|
|
@@ -641,4 +667,56 @@ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, Appl
|
|
|
641
667
|
}
|
|
642
668
|
});
|
|
643
669
|
return result;
|
|
644
|
-
};
|
|
670
|
+
};
|
|
671
|
+
// ─── filter 유틸 (applyNode/replace*/innerHtml* options.filter용) ───
|
|
672
|
+
// filter는 true 반환 시 적용, false 반환 시 스킵.
|
|
673
|
+
|
|
674
|
+
const filterScopeOf = (target: HTMLElement | ShadowRoot): Element | null => {
|
|
675
|
+
if (target && typeof (target as HTMLElement).querySelector === 'function') {
|
|
676
|
+
return target as unknown as Element;
|
|
677
|
+
}
|
|
678
|
+
const host = (target as ShadowRoot)?.host as unknown as Element | undefined;
|
|
679
|
+
return host && typeof host.querySelector === 'function' ? host : null;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
const tagNameOf = (node: any): string | null => {
|
|
683
|
+
const tag = node?.tagName;
|
|
684
|
+
return typeof tag === 'string' ? tag.toLowerCase() : null;
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// 새 노드와 같은 태그가 target 안에 이미 있으면 스킵 (SSR adopting용).
|
|
688
|
+
export const skipIfSameTagPresent = (target: HTMLElement | ShadowRoot, newValue: any): boolean => {
|
|
689
|
+
const nodes = (Array.isArray(newValue) ? newValue : [newValue]).filter((n) => tagNameOf(n) !== null);
|
|
690
|
+
if (nodes.length === 0) return true;
|
|
691
|
+
const scope = filterScopeOf(target);
|
|
692
|
+
if (!scope) return true;
|
|
693
|
+
return !nodes.some((n) => scope.querySelector(tagNameOf(n)!));
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
// 지정 selector가 target 안에 이미 있으면 스킵 (같은 path 쿼리 변경 시 페이지 재생성 방지용).
|
|
697
|
+
// 사용: @innerHtmlLight({ filter: skipIfExists('center-math-page') })
|
|
698
|
+
export const skipIfExists = (selector: string) =>
|
|
699
|
+
(target: HTMLElement | ShadowRoot): boolean => {
|
|
700
|
+
const scope = filterScopeOf(target);
|
|
701
|
+
if (!scope) return true;
|
|
702
|
+
return !scope.querySelector(selector);
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
// 새 값이 비어있으면 스킵 (null/''/빈 배열).
|
|
706
|
+
export const skipIfEmpty = (_target: HTMLElement | ShadowRoot, newValue: any): boolean => {
|
|
707
|
+
if (newValue === null || newValue === undefined || newValue === false) return false;
|
|
708
|
+
if (typeof newValue === 'string') return newValue.trim().length > 0;
|
|
709
|
+
if (Array.isArray(newValue)) return newValue.length > 0;
|
|
710
|
+
return true;
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// 텍스트가 달라질 때만 적용 (폴링 갱신용).
|
|
714
|
+
export const applyIfChanged = (target: HTMLElement | ShadowRoot, newValue: any): boolean => {
|
|
715
|
+
const textOf = (v: any): string => {
|
|
716
|
+
if (typeof v === 'string') return v;
|
|
717
|
+
if (Array.isArray(v)) return v.map(textOf).join('');
|
|
718
|
+
return typeof v?.textContent === 'string' ? v.textContent : '';
|
|
719
|
+
};
|
|
720
|
+
const current = typeof (target as HTMLElement)?.textContent === 'string' ? (target as HTMLElement).textContent! : '';
|
|
721
|
+
return current !== textOf(newValue);
|
|
722
|
+
};
|
|
@@ -1,40 +1,31 @@
|
|
|
1
1
|
import { ReflectUtils } 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
|
|
|
6
|
-
|
|
6
|
+
// 공통 옵션 — root 없음
|
|
7
|
+
export interface PropertyBaseOptions {
|
|
7
8
|
name?: string | symbol;
|
|
8
9
|
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Custom key to extract value from return object.
|
|
11
|
-
* If not provided, uses PROPERTY_METADATA_KEY by default.
|
|
12
|
-
* Useful when multiple @setProperty decorators are on the same method.
|
|
13
|
-
*
|
|
14
|
-
* Example:
|
|
15
|
-
* @setProperty('selector1', { valueKey: 'prop1' })
|
|
16
|
-
* @setProperty('selector2', { valueKey: 'prop2' })
|
|
17
|
-
* myMethod() {
|
|
18
|
-
* return {
|
|
19
|
-
* prop1: 'value1',
|
|
20
|
-
* prop2: 'value2'
|
|
21
|
-
* };
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* Or with symbols:
|
|
25
|
-
* @setProperty('selector1', { valueKey: Symbol.for('prop1') })
|
|
26
|
-
* @setProperty('selector2', { valueKey: Symbol.for('prop2') })
|
|
27
|
-
* myMethod() {
|
|
28
|
-
* return {
|
|
29
|
-
* [Symbol.for('prop1')]: 'value1',
|
|
30
|
-
* [Symbol.for('prop2')]: 'value2'
|
|
31
|
-
* };
|
|
32
|
-
* }
|
|
33
|
-
*/
|
|
34
10
|
valueKey?: symbol | string;
|
|
11
|
+
/** 읽기 방식: 'get' 타깃 프로퍼티 읽기 (기본), 'call' 타깃 호출 후 리턴 사용 */
|
|
12
|
+
getType?: 'get' | 'call';
|
|
13
|
+
/** 쓰기 방식: 'set' 타깃 프로퍼티 대입 (기본), 'call' 타깃 호출 (배열이면 spread) */
|
|
14
|
+
setType?: 'set' | 'call';
|
|
35
15
|
}
|
|
36
16
|
|
|
37
|
-
|
|
17
|
+
// 문자열 셀렉터 전용 — root 허용
|
|
18
|
+
export type PropertyQueryOptions = PropertyBaseOptions & SwcQueryOptions;
|
|
19
|
+
// 함수 셀렉터 전용 — root 금지
|
|
20
|
+
export type PropertyNonQueryOptions = PropertyBaseOptions;
|
|
21
|
+
// 내부 저장/해석용 — root optional이라 두 종류 모두 저장 가능
|
|
22
|
+
export type PropertyOptions = PropertyQueryOptions;
|
|
23
|
+
|
|
24
|
+
export type PropertyFnSelector = SwcFnSelector;
|
|
25
|
+
export type PropertySelector = SwcSelector;
|
|
26
|
+
|
|
27
|
+
// 셀렉터 종류에 따라 옵션 타입 분기
|
|
28
|
+
export type PropertyOptionsOf<S extends PropertySelector> = S extends string ? PropertyQueryOptions : PropertyNonQueryOptions;
|
|
38
29
|
|
|
39
30
|
export interface PropertyMetadata {
|
|
40
31
|
propertyKey: string | symbol;
|
|
@@ -62,7 +53,7 @@ export const resolvePropertyTargets = (inst: any, selector: PropertySelector, op
|
|
|
62
53
|
const results: any[] = [];
|
|
63
54
|
|
|
64
55
|
// Resolve selector if it's a function
|
|
65
|
-
let resolvedSelector: string | Element | NodeList | Element[] | null = selector as any;
|
|
56
|
+
let resolvedSelector: string | Node | Element | NodeList | Element[] | null = selector as any;
|
|
66
57
|
if (typeof selector === 'function') {
|
|
67
58
|
const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
|
|
68
59
|
resolvedSelector = selector(inst, hostSet);
|
|
@@ -146,9 +137,9 @@ export const resolvePropertyTargets = (inst: any, selector: PropertySelector, op
|
|
|
146
137
|
* - @applyProperty((this, helper) => 'selector', 'propertyName') - Function-based selector
|
|
147
138
|
* - Return null/undefined to skip setting
|
|
148
139
|
*/
|
|
149
|
-
export function applyProperty(selector:
|
|
150
|
-
export function applyProperty(selector:
|
|
151
|
-
export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator
|
|
140
|
+
export function applyProperty<S extends PropertySelector>(selector: S, targetPropertyKey: string | symbol, options?: PropertyOptionsOf<S>): MethodDecorator & PropertyDecorator;
|
|
141
|
+
export function applyProperty<S extends PropertySelector>(selector: S, options?: PropertyOptionsOf<S>): MethodDecorator & PropertyDecorator;
|
|
142
|
+
export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator {
|
|
152
143
|
return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
|
|
153
144
|
// ensureInit(target as any);
|
|
154
145
|
|
|
@@ -186,7 +177,7 @@ export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOpt
|
|
|
186
177
|
type: metaType
|
|
187
178
|
});
|
|
188
179
|
|
|
189
|
-
// Helper: apply resolved value to targets
|
|
180
|
+
// Helper: apply resolved value to targets (setType 'call'이면 타깃 호출 — 배열은 spread)
|
|
190
181
|
const applyValueToTargets = (inst: any, resolvedValue: any) => {
|
|
191
182
|
if (resolvedValue === undefined) return resolvedValue;
|
|
192
183
|
|
|
@@ -202,6 +193,12 @@ export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOpt
|
|
|
202
193
|
}
|
|
203
194
|
|
|
204
195
|
const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
|
|
196
|
+
if (finalOptions.setType === 'call') {
|
|
197
|
+
if (typeof (targetEl as any)[targetPropertyKey] !== 'function') return;
|
|
198
|
+
if (Array.isArray(resolvedRes)) (targetEl as any)[targetPropertyKey].apply(targetEl, resolvedRes);
|
|
199
|
+
else (targetEl as any)[targetPropertyKey].call(targetEl, resolvedRes);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
205
202
|
(targetEl as any)[targetPropertyKey] = resolvedRes;
|
|
206
203
|
});
|
|
207
204
|
|
|
@@ -274,7 +271,12 @@ export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOpt
|
|
|
274
271
|
return true;
|
|
275
272
|
});
|
|
276
273
|
|
|
277
|
-
const values = filtered.map(el =>
|
|
274
|
+
const values = filtered.map(el => {
|
|
275
|
+
const raw = (el as any)[targetPropertyKey];
|
|
276
|
+
// getType 'call'이면 타깃 호출 후 리턴 사용
|
|
277
|
+
if (finalOptions.getType === 'call' && typeof raw === 'function') return raw.call(el);
|
|
278
|
+
return raw;
|
|
279
|
+
});
|
|
278
280
|
return values.length === 1 ? values[0] : values;
|
|
279
281
|
},
|
|
280
282
|
set(this: any, value: any) {
|
|
@@ -301,19 +303,28 @@ export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOpt
|
|
|
301
303
|
*
|
|
302
304
|
* Note: This decorator is for FIELDS ONLY. For methods, use @setProperty.
|
|
303
305
|
*/
|
|
306
|
+
export function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyQueryOptions): PropertyDecorator;
|
|
307
|
+
export function property(selector: PropertyFnSelector, targetPropertyKey: string | symbol, options?: PropertyNonQueryOptions): PropertyDecorator;
|
|
308
|
+
export function property(selector: string, options?: PropertyQueryOptions): PropertyDecorator;
|
|
309
|
+
export function property(selector: PropertyFnSelector, options?: PropertyNonQueryOptions): PropertyDecorator;
|
|
304
310
|
export function property(target: Object, propertyKey: string | symbol): void;
|
|
305
311
|
export function property(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
306
|
-
export function property(selector: PropertySelector, targetPropertyKey: string | symbol, options?: PropertyOptions): PropertyDecorator;
|
|
307
|
-
export function property(selector: PropertySelector, options?: PropertyOptions): PropertyDecorator;
|
|
308
312
|
export function property(selectorOrTarget?: PropertySelector | Object, targetPropertyKeyOrOptions?: any, optionsOrDescriptor?: any): any {
|
|
309
|
-
// Bare decorator: @property
|
|
310
|
-
|
|
313
|
+
// Bare decorator direct invocation: @property on field/method passes (target, key[, descriptor]).
|
|
314
|
+
// NOTE: (selector-string, key, options) factory form must NOT enter here — target is never string/function.
|
|
315
|
+
if (optionsOrDescriptor !== undefined
|
|
316
|
+
&& typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function'
|
|
317
|
+
&& (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol')) {
|
|
311
318
|
return applyProperty('$this', undefined as any, {})(selectorOrTarget as Object, targetPropertyKeyOrOptions, optionsOrDescriptor as PropertyDescriptor);
|
|
312
319
|
}
|
|
313
320
|
// With selector
|
|
314
321
|
if (typeof selectorOrTarget === 'string') {
|
|
315
322
|
return applyProperty(selectorOrTarget, targetPropertyKeyOrOptions as any, optionsOrDescriptor as PropertyOptions);
|
|
316
323
|
}
|
|
324
|
+
// Function selector
|
|
325
|
+
if (typeof selectorOrTarget === 'function') {
|
|
326
|
+
return applyProperty(selectorOrTarget as PropertyFnSelector, targetPropertyKeyOrOptions as any, optionsOrDescriptor as PropertyOptions);
|
|
327
|
+
}
|
|
317
328
|
// Without selector (defaults to $this)
|
|
318
329
|
return applyProperty('$this', undefined as any, selectorOrTarget as PropertyOptions);
|
|
319
330
|
}
|
|
@@ -336,17 +347,69 @@ export function property(selectorOrTarget?: PropertySelector | Object, targetPro
|
|
|
336
347
|
* return true;
|
|
337
348
|
* }
|
|
338
349
|
*/
|
|
339
|
-
export function setProperty(selector:
|
|
340
|
-
export function setProperty(selector:
|
|
350
|
+
export function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyQueryOptions): MethodDecorator;
|
|
351
|
+
export function setProperty(selector: PropertyFnSelector, targetPropertyKey: string | symbol, options?: PropertyNonQueryOptions): MethodDecorator;
|
|
352
|
+
export function setProperty(selector: string, options?: PropertyQueryOptions): MethodDecorator;
|
|
353
|
+
export function setProperty(selector: PropertyFnSelector, options?: PropertyNonQueryOptions): MethodDecorator;
|
|
341
354
|
export function setProperty(selectorOrOptions?: PropertySelector | PropertyOptions, targetPropertyKeyOrOptions?: any, optionsOrUndefined?: PropertyOptions): MethodDecorator {
|
|
342
355
|
// With selector
|
|
343
356
|
if (typeof selectorOrOptions === 'string') {
|
|
344
357
|
return applyProperty(selectorOrOptions, targetPropertyKeyOrOptions as any, optionsOrUndefined as PropertyOptions) as MethodDecorator;
|
|
345
358
|
}
|
|
359
|
+
// Function selector
|
|
360
|
+
if (typeof selectorOrOptions === 'function') {
|
|
361
|
+
return applyProperty(selectorOrOptions as PropertyFnSelector, targetPropertyKeyOrOptions as any, optionsOrUndefined as PropertyOptions) as MethodDecorator;
|
|
362
|
+
}
|
|
346
363
|
// Without selector (defaults to $this)
|
|
347
364
|
return applyProperty('$this', undefined as any, selectorOrOptions as PropertyOptions) as MethodDecorator;
|
|
348
365
|
}
|
|
349
366
|
|
|
367
|
+
/**
|
|
368
|
+
* @callProperty - Method decorator for calling a method on matched elements.
|
|
369
|
+
* - @callProperty('selector', 'methodName') - 메서드 리턴값으로 타깃 메서드 호출
|
|
370
|
+
* - @callProperty('selector') - 메서드 이름과 같은 타깃 메서드 호출
|
|
371
|
+
* - 리턴값이 배열이면 spread 인자로 호출, 아니면 단일 인자로 호출
|
|
372
|
+
*
|
|
373
|
+
* Example:
|
|
374
|
+
* @event('#popup', 'open-request')
|
|
375
|
+
* @callProperty('#popup', 'show')
|
|
376
|
+
* onPopupOpen() {
|
|
377
|
+
* return [this.rows]; // popup.show(this.rows)
|
|
378
|
+
* }
|
|
379
|
+
*/
|
|
380
|
+
export function callProperty(selector: string, targetMethodKey?: string | symbol, options?: PropertyQueryOptions): MethodDecorator;
|
|
381
|
+
export function callProperty(selector: PropertyFnSelector, targetMethodKey?: string | symbol, options?: PropertyNonQueryOptions): MethodDecorator;
|
|
382
|
+
export function callProperty(selector: string, options?: PropertyQueryOptions): MethodDecorator;
|
|
383
|
+
export function callProperty(selectorOrTarget?: PropertySelector | PropertyOptions, targetMethodKeyOrOptions?: any, optionsOrUndefined?: PropertyOptions): MethodDecorator {
|
|
384
|
+
// setType 'call' 위임 — 메서드 리턴값을 타깃 메서드 호출로 전달 (배열이면 spread)
|
|
385
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
386
|
+
if (typeof targetMethodKeyOrOptions === 'string' || typeof targetMethodKeyOrOptions === 'symbol') {
|
|
387
|
+
return applyProperty(selectorOrTarget as any, targetMethodKeyOrOptions, { ...optionsOrUndefined ?? {}, setType: 'call' }) as MethodDecorator;
|
|
388
|
+
}
|
|
389
|
+
return applyProperty(selectorOrTarget as any, { ...optionsOrUndefined ?? targetMethodKeyOrOptions ?? {}, setType: 'call' }) as MethodDecorator;
|
|
390
|
+
}
|
|
391
|
+
return applyProperty('$this', undefined as any, { ...selectorOrTarget ?? {}, setType: 'call' }) as MethodDecorator;
|
|
392
|
+
}
|
|
393
|
+
export function callPropertyLight(selector: string, targetMethodKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator;
|
|
394
|
+
export function callPropertyLight(selector: string, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator;
|
|
395
|
+
export function callPropertyLight(selector: string, targetMethodKeyOrOptions?: any, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
396
|
+
if (targetMethodKeyOrOptions != null && typeof targetMethodKeyOrOptions !== 'string' && typeof targetMethodKeyOrOptions !== 'symbol') {
|
|
397
|
+
return callProperty(selector, undefined, { ...targetMethodKeyOrOptions ?? {}, root: 'light' });
|
|
398
|
+
}
|
|
399
|
+
return callProperty(selector, targetMethodKeyOrOptions as any, { ...options ?? {}, root: 'light' });
|
|
400
|
+
}
|
|
401
|
+
export function callPropertyShadow(selector: string, targetMethodKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator;
|
|
402
|
+
export function callPropertyShadow(selector: string, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator;
|
|
403
|
+
export function callPropertyShadow(selector: string, targetMethodKeyOrOptions?: any, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
404
|
+
if (targetMethodKeyOrOptions != null && typeof targetMethodKeyOrOptions !== 'string' && typeof targetMethodKeyOrOptions !== 'symbol') {
|
|
405
|
+
return callProperty(selector, undefined, { ...targetMethodKeyOrOptions ?? {}, root: 'shadow' });
|
|
406
|
+
}
|
|
407
|
+
return callProperty(selector, targetMethodKeyOrOptions as any, { ...options ?? {}, root: 'shadow' });
|
|
408
|
+
}
|
|
409
|
+
export function callPropertyAll(selector: string, targetMethodKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
410
|
+
return callProperty(selector, targetMethodKey as any, { ...options ?? {}, root: 'all' });
|
|
411
|
+
}
|
|
412
|
+
|
|
350
413
|
// ============================================
|
|
351
414
|
// Metadata Helpers
|
|
352
415
|
// ============================================
|
|
@@ -365,5 +428,54 @@ export const findAllPropertyApplyMetadata = (target: any): Map<string | symbol,
|
|
|
365
428
|
return result;
|
|
366
429
|
};
|
|
367
430
|
|
|
431
|
+
// ─── Aliases ───
|
|
432
|
+
// property(필드) / setProperty(메서드)와 구분되는 일반 데코레이터 단축명
|
|
433
|
+
export const prop = applyProperty;
|
|
434
|
+
|
|
435
|
+
// ─── 편의 헬퍼 (selector/root 생략) ───
|
|
436
|
+
|
|
437
|
+
export function propThis(targetPropertyKey?: string | symbol, options?: PropertyQueryOptions): MethodDecorator {
|
|
438
|
+
return applyProperty('$this', targetPropertyKey, options);
|
|
439
|
+
}
|
|
440
|
+
export function propAppHost(targetPropertyKey?: string | symbol, options?: PropertyQueryOptions): MethodDecorator {
|
|
441
|
+
return applyProperty('$appHost', targetPropertyKey, options);
|
|
442
|
+
}
|
|
443
|
+
export function propWindow(targetPropertyKey?: string | symbol, options?: PropertyQueryOptions): MethodDecorator {
|
|
444
|
+
return applyProperty('$window', targetPropertyKey, options);
|
|
445
|
+
}
|
|
446
|
+
export function propDocument(targetPropertyKey?: string | symbol, options?: PropertyQueryOptions): MethodDecorator {
|
|
447
|
+
return applyProperty('$document', targetPropertyKey, options);
|
|
448
|
+
}
|
|
449
|
+
export function propLight(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
450
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'light'});
|
|
451
|
+
}
|
|
452
|
+
export function propShadow(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
453
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'shadow'});
|
|
454
|
+
}
|
|
455
|
+
export function propAll(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
456
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'all'});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ─── setProperty root 별칭 (메서드 리턴값 → 타깃 프로퍼티) ───
|
|
460
|
+
export function setPropertyLight(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
461
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'light'});
|
|
462
|
+
}
|
|
463
|
+
export function setPropertyShadow(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
464
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'shadow'});
|
|
465
|
+
}
|
|
466
|
+
export function setPropertyAll(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): MethodDecorator {
|
|
467
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'all'});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// ─── property root 별칭 (필드 프록시) ───
|
|
471
|
+
export function propertyLight(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): PropertyDecorator {
|
|
472
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'light'});
|
|
473
|
+
}
|
|
474
|
+
export function propertyShadow(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): PropertyDecorator {
|
|
475
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'shadow'});
|
|
476
|
+
}
|
|
477
|
+
export function propertyAll(selector: string, targetPropertyKey?: string | symbol, options?: Omit<PropertyQueryOptions, 'root'>): PropertyDecorator {
|
|
478
|
+
return applyProperty(selector, targetPropertyKey, {...options ?? {}, root: 'all'});
|
|
479
|
+
}
|
|
368
480
|
|
|
369
481
|
export default applyProperty;
|