@dooboostore/simple-web-component 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -19
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +2373 -30
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +31 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +55 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +73 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +107 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +6 -5
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +42 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +61 -13
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +254 -439
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/eventMedia.js +84 -0
- package/dist/cjs/decorators/eventMedia.js.map +7 -0
- package/dist/cjs/decorators/index.js +6 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +200 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +186 -55
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/parameter.js +73 -0
- package/dist/cjs/decorators/parameter.js.map +7 -0
- package/dist/cjs/decorators/query.js +117 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +124 -0
- package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/cjs/decorators/resizeObserver.js +133 -55
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +114 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +117 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +19 -3
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +2374 -30
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +31 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +55 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +73 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +107 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +6 -5
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +42 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +62 -13
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +261 -446
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/eventMedia.js +66 -0
- package/dist/esm/decorators/eventMedia.js.map +7 -0
- package/dist/esm/decorators/index.js +6 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +182 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +187 -55
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/parameter.js +54 -0
- package/dist/esm/decorators/parameter.js.map +7 -0
- package/dist/esm/decorators/query.js +117 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +105 -0
- package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/esm/decorators/resizeObserver.js +134 -55
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +95 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +98 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +20 -4
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4961 -1628
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +1046 -33
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +24 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +36 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +32 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +61 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +27 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +12 -3
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts +0 -14
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/eventMedia.d.ts +25 -0
- package/dist/types/decorators/eventMedia.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +6 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +58 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +44 -25
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +35 -0
- package/dist/types/decorators/parameter.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +57 -14
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
- package/dist/types/decorators/resizeObserver.d.ts +43 -23
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +41 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +41 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4961 -1628
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -5
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +1446 -34
- package/src/decorators/applyAttribute.ts +60 -36
- package/src/decorators/applyClass.ts +86 -26
- package/src/decorators/applyNode.ts +124 -36
- package/src/decorators/applyProperty.ts +172 -40
- package/src/decorators/applySlot.ts +6 -5
- package/src/decorators/applyStyle.ts +74 -17
- package/src/decorators/changedAttribute.ts +76 -15
- package/src/decorators/elementDefine.ts +310 -582
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/eventMedia.ts +78 -0
- package/src/decorators/index.ts +6 -1
- package/src/decorators/intersectionObserver.ts +275 -0
- package/src/decorators/mutationObserver.ts +282 -89
- package/src/decorators/parameter.ts +81 -0
- package/src/decorators/query.ts +168 -126
- package/src/decorators/requestAnimationFrame.ts +158 -0
- package/src/decorators/resizeObserver.ts +211 -89
- package/src/decorators/setInterval.ts +136 -0
- package/src/decorators/setTimeout.ts +139 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/elements/SwcAppMixin.ts +20 -5
- package/src/types/index.ts +141 -0
- package/src/types/window.d.ts +2 -18
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
- package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/examples/RxJSOperatorsExample.ts +0 -279
|
@@ -1,21 +1,28 @@
|
|
|
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 type StyleAction = 'set' | 'update' | 'remove';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// 공통 옵션 — root 없음
|
|
9
|
+
export interface StyleBaseOptions {
|
|
9
10
|
filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Custom key to extract value from return object.
|
|
12
|
-
* If not provided, uses STYLE_METADATA_KEY by default.
|
|
13
|
-
* Useful when multiple @applyStyle decorators are on the same method.
|
|
14
|
-
*/
|
|
15
11
|
valueKey?: symbol | string;
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
// 문자열 셀렉터 전용 — root 허용
|
|
15
|
+
export type StyleQueryOptions = StyleBaseOptions & SwcQueryOptions;
|
|
16
|
+
// 함수 셀렉터 전용 — root 금지
|
|
17
|
+
export type StyleNonQueryOptions = StyleBaseOptions;
|
|
18
|
+
// 내부 저장/해석용
|
|
19
|
+
export type StyleApplyOptions = StyleQueryOptions;
|
|
20
|
+
|
|
21
|
+
export type StyleFnSelector = SwcFnSelector;
|
|
22
|
+
export type StyleSelector = SwcSelector;
|
|
23
|
+
|
|
24
|
+
// 셀렉터 종류에 따라 옵션 타입 분기
|
|
25
|
+
export type StyleOptionsOf<S extends StyleSelector> = S extends string ? StyleQueryOptions : StyleNonQueryOptions;
|
|
19
26
|
|
|
20
27
|
export interface StyleApplyMetadata {
|
|
21
28
|
propertyKey: string | symbol;
|
|
@@ -47,6 +54,9 @@ const resolveSelector = (selector: StyleSelector, inst: any, win: Window): strin
|
|
|
47
54
|
if (result === null) {
|
|
48
55
|
return [];
|
|
49
56
|
}
|
|
57
|
+
if (result instanceof win.Node) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
50
60
|
return result as string;
|
|
51
61
|
}
|
|
52
62
|
return selector as string;
|
|
@@ -184,14 +194,15 @@ function createStyleDecorator(action: StyleAction) {
|
|
|
184
194
|
}
|
|
185
195
|
|
|
186
196
|
export function applyStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
187
|
-
export function applyStyle(selector:
|
|
197
|
+
export function applyStyle(selector: string, action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;
|
|
198
|
+
export function applyStyle(selector: StyleFnSelector, action?: StyleAction, options?: StyleNonQueryOptions): MethodDecorator;
|
|
188
199
|
export function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {
|
|
189
200
|
// Bare decorator: @applyStyle
|
|
190
|
-
if (optionsOrDescriptor !== undefined && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
|
|
201
|
+
if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
|
|
191
202
|
return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);
|
|
192
203
|
}
|
|
193
204
|
// With selector
|
|
194
|
-
if (typeof selectorOrTarget === 'string') {
|
|
205
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
195
206
|
const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as StyleAction;
|
|
196
207
|
const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as StyleApplyOptions | undefined;
|
|
197
208
|
return createStyleDecorator(action)(selectorOrTarget, options);
|
|
@@ -203,14 +214,15 @@ export function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, op
|
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
export function setStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
206
|
-
export function setStyle(selector:
|
|
217
|
+
export function setStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;
|
|
218
|
+
export function setStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;
|
|
207
219
|
export function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
|
|
208
220
|
// Bare decorator: @setStyle
|
|
209
221
|
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
210
222
|
return createStyleDecorator('set')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);
|
|
211
223
|
}
|
|
212
224
|
// With selector
|
|
213
|
-
if (typeof selectorOrTarget === 'string') {
|
|
225
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
214
226
|
return createStyleDecorator('set')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);
|
|
215
227
|
}
|
|
216
228
|
// Without selector (defaults to $this)
|
|
@@ -218,14 +230,15 @@ export function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, des
|
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
export function updateStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
221
|
-
export function updateStyle(selector:
|
|
233
|
+
export function updateStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;
|
|
234
|
+
export function updateStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;
|
|
222
235
|
export function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
|
|
223
236
|
// Bare decorator: @updateStyle
|
|
224
237
|
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
225
238
|
return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);
|
|
226
239
|
}
|
|
227
240
|
// With selector
|
|
228
|
-
if (typeof selectorOrTarget === 'string') {
|
|
241
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
229
242
|
return createStyleDecorator('update')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);
|
|
230
243
|
}
|
|
231
244
|
// Without selector (defaults to $this)
|
|
@@ -233,20 +246,64 @@ export function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any,
|
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
export function removeStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
236
|
-
export function removeStyle(selector:
|
|
249
|
+
export function removeStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;
|
|
250
|
+
export function removeStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;
|
|
237
251
|
export function removeStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
|
|
238
252
|
// Bare decorator: @removeStyle
|
|
239
253
|
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
240
254
|
return createStyleDecorator('remove')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);
|
|
241
255
|
}
|
|
242
256
|
// With selector
|
|
243
|
-
if (typeof selectorOrTarget === 'string') {
|
|
257
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
244
258
|
return createStyleDecorator('remove')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);
|
|
245
259
|
}
|
|
246
260
|
// Without selector (defaults to $this)
|
|
247
261
|
return createStyleDecorator('remove')('$this', selectorOrTarget as StyleApplyOptions);
|
|
248
262
|
}
|
|
249
263
|
|
|
264
|
+
// ─── Aliases ───
|
|
265
|
+
export const style = applyStyle;
|
|
266
|
+
|
|
267
|
+
// ─── 편의 헬퍼 (selector/root 생략) ───
|
|
268
|
+
|
|
269
|
+
export function styleThis(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;
|
|
270
|
+
export function styleThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
271
|
+
export function styleThis(actionOrTarget?: StyleAction | Object, optionsOrPropertyKey?: StyleQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
272
|
+
if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {
|
|
273
|
+
return (applyStyle('$this', undefined as any, {}) as any)(actionOrTarget, optionsOrPropertyKey, descriptor);
|
|
274
|
+
}
|
|
275
|
+
return applyStyle('$this', actionOrTarget as any, optionsOrPropertyKey as StyleQueryOptions);
|
|
276
|
+
}
|
|
277
|
+
export function styleAppHost(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;
|
|
278
|
+
export function styleAppHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
|
|
279
|
+
export function styleAppHost(actionOrTarget?: StyleAction | Object, optionsOrPropertyKey?: StyleQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
280
|
+
if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {
|
|
281
|
+
return (applyStyle('$appHost', undefined as any, {}) as any)(actionOrTarget, optionsOrPropertyKey, descriptor);
|
|
282
|
+
}
|
|
283
|
+
return applyStyle('$appHost', actionOrTarget as any, optionsOrPropertyKey as StyleQueryOptions);
|
|
284
|
+
}
|
|
285
|
+
export function styleLight(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
286
|
+
export function styleLight(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
287
|
+
export function styleLight(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {
|
|
288
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;
|
|
289
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;
|
|
290
|
+
return applyStyle(selector, action, {...opts ?? {}, root: 'light'});
|
|
291
|
+
}
|
|
292
|
+
export function styleShadow(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
293
|
+
export function styleShadow(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
294
|
+
export function styleShadow(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {
|
|
295
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;
|
|
296
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;
|
|
297
|
+
return applyStyle(selector, action, {...opts ?? {}, root: 'shadow'});
|
|
298
|
+
}
|
|
299
|
+
export function styleAll(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
300
|
+
export function styleAll(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;
|
|
301
|
+
export function styleAll(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {
|
|
302
|
+
const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;
|
|
303
|
+
const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;
|
|
304
|
+
return applyStyle(selector, action, {...opts ?? {}, root: 'all'});
|
|
305
|
+
}
|
|
306
|
+
|
|
250
307
|
export const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {
|
|
251
308
|
const result = new Map<string | symbol, StyleApplyMetadata>();
|
|
252
309
|
const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(STYLE_METADATA_KEY, target);
|
|
@@ -20,24 +20,39 @@ const convertValue = (val: any, type: any): any => {
|
|
|
20
20
|
return val;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const applyChangedAttribute = (attributeName: string | undefined, options: ChangedAttributeThisOptions, target: Object, propertyKey: string | symbol): void => {
|
|
24
|
+
const constructor = target.constructor;
|
|
25
|
+
let metaList = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as ChangedAttributeThisMetadata[];
|
|
26
|
+
if (!metaList) {
|
|
27
|
+
metaList = [];
|
|
28
|
+
ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const name = attributeName || String(propertyKey);
|
|
32
|
+
metaList.push({
|
|
33
|
+
attributeName: name,
|
|
34
|
+
propertyKey,
|
|
35
|
+
options
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function changedAttribute(attributeName?: string, options?: ChangedAttributeThisOptions): MethodDecorator;
|
|
40
|
+
export function changedAttribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
|
|
23
41
|
/**
|
|
24
|
-
* @changedAttributeThis decorator - fires when any attribute on $this changes
|
|
42
|
+
* @changedAttributeThis decorator - fires when any attribute on $this changes.
|
|
43
|
+
* 옵션 없이 `@changedAttribute` 그대로 붙여도 되고, `@changedAttribute(...)`처럼 이름/옵션을 줄 수도 있다.
|
|
25
44
|
*/
|
|
26
|
-
export function changedAttribute(
|
|
45
|
+
export function changedAttribute(attributeNameOrTarget?: string | Object, optionsOrPropertyKey?: ChangedAttributeThisOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {
|
|
46
|
+
if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {
|
|
47
|
+
// 옵션 없이: @changedAttribute
|
|
48
|
+
applyChangedAttribute(undefined, {}, attributeNameOrTarget as Object, optionsOrPropertyKey);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// 옵션과 함께: @changedAttribute() / @changedAttribute('name', options?)
|
|
52
|
+
const attributeName = attributeNameOrTarget as string | undefined;
|
|
53
|
+
const options = (optionsOrPropertyKey as ChangedAttributeThisOptions) ?? {};
|
|
27
54
|
return (target: Object, propertyKey: string | symbol) => {
|
|
28
|
-
|
|
29
|
-
let metaList = ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) as ChangedAttributeThisMetadata[];
|
|
30
|
-
if (!metaList) {
|
|
31
|
-
metaList = [];
|
|
32
|
-
ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const name = attributeName || String(propertyKey);
|
|
36
|
-
metaList.push({
|
|
37
|
-
attributeName: name,
|
|
38
|
-
propertyKey,
|
|
39
|
-
options
|
|
40
|
-
});
|
|
55
|
+
applyChangedAttribute(attributeName, options, target, propertyKey);
|
|
41
56
|
};
|
|
42
57
|
}
|
|
43
58
|
|
|
@@ -65,3 +80,49 @@ export const findAllAttributeChangedMetadata = (target: any): Map<string, Change
|
|
|
65
80
|
export const convertAttributeValue = (val: any, type?: typeof Number | typeof Boolean | typeof String): any => {
|
|
66
81
|
return convertValue(val, type);
|
|
67
82
|
};
|
|
83
|
+
|
|
84
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
85
|
+
// ChangedAttributeLifeCycler
|
|
86
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
87
|
+
import { ElementDefineLifeCycler, HelperHostSet } from '../types';
|
|
88
|
+
import { getAttributeValue } from './applyAttribute';
|
|
89
|
+
|
|
90
|
+
export class ChangedAttributeLifeCycler implements ElementDefineLifeCycler {
|
|
91
|
+
private attrChangeMap: Map<string, ChangedAttributeThisMetadata[]> | null = null;
|
|
92
|
+
|
|
93
|
+
/** 클래스 메타데이터 기반 attrChangeMap 을 lazy 로드한다 (공유 시클러 캐시). */
|
|
94
|
+
private getAttrChangeMap(inst: any): Map<string, ChangedAttributeThisMetadata[]> {
|
|
95
|
+
if (!this.attrChangeMap) this.attrChangeMap = findAllAttributeChangedMetadata(inst);
|
|
96
|
+
return this.attrChangeMap;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** observedAttributes 에 포함할 attribute 이름 목록 */
|
|
100
|
+
getObservedAttributeNames(inst: any): string[] {
|
|
101
|
+
return Array.from(this.getAttrChangeMap(inst).keys());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
onConnected(helperHostSet: HelperHostSet): void {
|
|
105
|
+
const inst = helperHostSet.$this;
|
|
106
|
+
|
|
107
|
+
// while:'connected' 옵션 — connected 시점 현재 값으로 초기 실행
|
|
108
|
+
for (const [name, metaList] of this.getAttrChangeMap(inst)) {
|
|
109
|
+
for (const meta of metaList) {
|
|
110
|
+
if (meta.options.while === 'connected') {
|
|
111
|
+
const val = getAttributeValue(inst, name, { type: meta.options.type });
|
|
112
|
+
if (val !== null) inst[meta.propertyKey](val, null, name, helperHostSet);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** attributeChangedCallback 에서 elementDefine 이 직접 호출 */
|
|
119
|
+
onAttributeChanged(helperHostSet: HelperHostSet, name: string, old: string | null, newVal: any): void {
|
|
120
|
+
const inst = helperHostSet.$this;
|
|
121
|
+
const metaList = this.getAttrChangeMap(inst).get(name);
|
|
122
|
+
if (!metaList) return;
|
|
123
|
+
for (const meta of metaList) {
|
|
124
|
+
if (meta.options.while === 'connected' && !inst.__swc_connected) continue;
|
|
125
|
+
inst[meta.propertyKey](convertAttributeValue(newVal, meta.options.type), old, name, helperHostSet);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|