@dooboostore/simple-web-component 1.0.32 → 1.0.33

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.
Files changed (57) hide show
  1. package/README.md +280 -43
  2. package/dist/cjs/decorators/elementDefine.js +1 -1
  3. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  4. package/dist/cjs/decorators/index.js +3 -1
  5. package/dist/cjs/decorators/index.js.map +2 -2
  6. package/dist/cjs/decorators/publishSwcAppMessage.js +86 -0
  7. package/dist/cjs/decorators/publishSwcAppMessage.js.map +7 -0
  8. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +62 -0
  9. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +7 -0
  10. package/dist/cjs/decorators/{subscribeSwcAppRouteChange.js → subscribeSwcAppRouteChangeWhileConnected.js} +16 -16
  11. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +7 -0
  12. package/dist/cjs/elements/SwcAppMixin.js +31 -2
  13. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  14. package/dist/cjs/types.js.map +1 -1
  15. package/dist/esm/decorators/elementDefine.js +1 -1
  16. package/dist/esm/decorators/elementDefine.js.map +2 -2
  17. package/dist/esm/decorators/index.js +3 -1
  18. package/dist/esm/decorators/index.js.map +2 -2
  19. package/dist/esm/decorators/publishSwcAppMessage.js +67 -0
  20. package/dist/esm/decorators/publishSwcAppMessage.js.map +7 -0
  21. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +43 -0
  22. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +7 -0
  23. package/dist/esm/decorators/{subscribeSwcAppRouteChange.js → subscribeSwcAppRouteChangeWhileConnected.js} +13 -13
  24. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +7 -0
  25. package/dist/esm/elements/SwcAppMixin.js +31 -2
  26. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  27. package/dist/esm/types.js.map +1 -1
  28. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +119 -14
  29. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  30. package/dist/types/decorators/elementDefine.d.ts +1 -0
  31. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  32. package/dist/types/decorators/index.d.ts +3 -1
  33. package/dist/types/decorators/index.d.ts.map +1 -1
  34. package/dist/types/decorators/publishSwcAppMessage.d.ts +13 -0
  35. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -0
  36. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +16 -0
  37. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -0
  38. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +18 -0
  39. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -0
  40. package/dist/types/elements/SwcAppMixin.d.ts +3 -0
  41. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  42. package/dist/types/types.d.ts +6 -0
  43. package/dist/types/types.d.ts.map +1 -1
  44. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +119 -14
  45. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  46. package/package.json +4 -4
  47. package/src/decorators/elementDefine.ts +2 -1
  48. package/src/decorators/index.ts +3 -1
  49. package/src/decorators/publishSwcAppMessage.ts +100 -0
  50. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +73 -0
  51. package/src/decorators/{subscribeSwcAppRouteChange.ts → subscribeSwcAppRouteChangeWhileConnected.ts} +19 -19
  52. package/src/elements/SwcAppMixin.ts +42 -3
  53. package/src/types.ts +8 -0
  54. package/dist/cjs/decorators/subscribeSwcAppRouteChange.js.map +0 -7
  55. package/dist/esm/decorators/subscribeSwcAppRouteChange.js.map +0 -7
  56. package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts +0 -18
  57. package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -92,10 +92,10 @@
92
92
  "webpack": "^5.93.0",
93
93
  "webpack-cli": "^5.1.4",
94
94
  "webpack-dev-server": "^5.2.0",
95
- "@dooboostore/core": "1.0.30",
96
- "@dooboostore/core-node": "1.0.12",
97
95
  "@dooboostore/core-web": "1.0.10",
98
- "@dooboostore/simple-boot": "1.0.54"
96
+ "@dooboostore/core": "1.0.30",
97
+ "@dooboostore/simple-boot": "1.0.54",
98
+ "@dooboostore/core-node": "1.0.12"
99
99
  },
100
100
  "scripts": {
101
101
  "clean": "rm -rf dist",
@@ -22,6 +22,7 @@ export interface ElementConfig {
22
22
  observedAttributes?: string[];
23
23
  customElementRegistry?: any;
24
24
  window?: Window;
25
+ useShadow?: boolean;
25
26
  }
26
27
 
27
28
  export interface ElementMetadata extends Omit<ElementConfig, 'window'> {
@@ -316,7 +317,7 @@ export const elementDefine =
316
317
  const conf = getElementConfig(this);
317
318
  const currentWin = (this as any)._resolveWindow(conf);
318
319
 
319
- if (connectedInnerHtmlList.some(it => it.options.useShadow === true) && !this.shadowRoot) {
320
+ if ((connectedInnerHtmlList.some(it => it.options.useShadow === true) || conf?.useShadow === true) && !this.shadowRoot) {
320
321
  this.attachShadow({ mode: 'open' });
321
322
  }
322
323
 
@@ -11,4 +11,6 @@ export * from './applyClass';
11
11
  export * from './applyStyle';
12
12
  export * from './applyAttribute';
13
13
  export * from './setProperty';
14
- export * from './subscribeSwcAppRouteChange';
14
+ export * from './subscribeSwcAppRouteChangeWhileConnected';
15
+ export * from './subscribeSwcAppMessageWhileConnected';
16
+ export * from './publishSwcAppMessage';
@@ -0,0 +1,100 @@
1
+ import { ReflectUtils } from '@dooboostore/core';
2
+ import { SwcAppMessage } from '../types';
3
+ import { SwcUtils } from '../utils/Utils';
4
+
5
+ export const PUBLISH_SWC_APP_MESSAGE_METADATA_KEY = Symbol.for('simple-web-component:publish-swc-app-message');
6
+
7
+ export interface PublishSwcAppMessageMetadata {
8
+ propertyKey: string | symbol;
9
+ messageType?: string;
10
+ }
11
+
12
+ export interface PublishSwcAppMessageOptions {
13
+ messageType?: string;
14
+ }
15
+
16
+ function createPublishSwcAppMessage(messageType?: string): MethodDecorator {
17
+ return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
18
+ const constructor = target.constructor;
19
+ let list = ReflectUtils.getOwnMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, constructor) as PublishSwcAppMessageMetadata[];
20
+ if (!list) {
21
+ list = [];
22
+ ReflectUtils.defineMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, list, constructor);
23
+ }
24
+ list.push({ propertyKey, messageType });
25
+
26
+ if (!descriptor) {
27
+ return descriptor;
28
+ }
29
+
30
+ // 메서드 래핑 - 원본 메서드의 반환값을 캡처하여 메시지 발행
31
+ const originalMethod = descriptor.value;
32
+ descriptor.value = function (...args: any[]) {
33
+ // 원본 메서드 실행
34
+ const result = originalMethod.apply(this, args);
35
+
36
+ // Promise 체크
37
+ if (result instanceof Promise) {
38
+ result.then((data) => {
39
+ // appHost 찾아서 메시지 발행
40
+ const appHost = SwcUtils.getAppHost(this as HTMLElement);
41
+ if (appHost) {
42
+ appHost.publishMessage({
43
+ publisher: this,
44
+ data,
45
+ type: messageType
46
+ });
47
+ }
48
+ }).catch((err) => {
49
+ console.warn('publishSwcAppMessage async error:', err);
50
+ });
51
+ } else {
52
+ // 동기 호출 - 바로 메시지 발행
53
+ const appHost = SwcUtils.getAppHost(this as HTMLElement);
54
+ if (appHost) {
55
+ appHost.publishMessage({
56
+ publisher: this,
57
+ data: result,
58
+ type: messageType
59
+ });
60
+ }
61
+ }
62
+
63
+ return result;
64
+ };
65
+
66
+ return descriptor;
67
+ };
68
+ }
69
+
70
+ // 오버로드 시그니처 - 직접 사용 (괄호 없음)
71
+ export function publishSwcAppMessage(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
72
+ // 오버로드 시그니처 - 함수 호출 (괄호 있음)
73
+ export function publishSwcAppMessage(): MethodDecorator;
74
+ export function publishSwcAppMessage(messageType: string): MethodDecorator;
75
+
76
+ export function publishSwcAppMessage(targetOrMessageType?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
77
+ // 직접 데코레이터로 사용된 경우 (괄호 없음): @publishSwcAppMessage
78
+ if (targetOrMessageType && typeof targetOrMessageType === 'object' &&
79
+ propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol') &&
80
+ descriptor) {
81
+ const target = targetOrMessageType;
82
+ return createPublishSwcAppMessage()(target, propertyKey, descriptor);
83
+ }
84
+
85
+ // 함수로 호출된 경우 (괄호 있음): @publishSwcAppMessage() / @publishSwcAppMessage('messageType')
86
+ let messageType: string | undefined;
87
+
88
+ if (typeof targetOrMessageType === 'string') {
89
+ // 메시지 타입 전달: @publishSwcAppMessage('messageType')
90
+ messageType = targetOrMessageType;
91
+ }
92
+
93
+ return createPublishSwcAppMessage(messageType);
94
+ }
95
+
96
+ // Helper function to retrieve publish message metadata
97
+ export const getPublishSwcAppMessageMetadata = (target: any): PublishSwcAppMessageMetadata[] | undefined => {
98
+ const constructor = target instanceof Function ? target : target.constructor;
99
+ return ReflectUtils.getOwnMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, constructor);
100
+ };
@@ -0,0 +1,73 @@
1
+ import { ReflectUtils } from '@dooboostore/core';
2
+ import { SwcAppMessage } from '../types';
3
+
4
+ export const SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-message-while-connected');
5
+
6
+ export interface SwcAppMessageSubscriberMetadata {
7
+ propertyKey: string | symbol;
8
+ messageType?: string;
9
+ filter?: (message: SwcAppMessage) => boolean;
10
+ }
11
+
12
+ export interface SwcAppMessageOptions {
13
+ filter?: (message: SwcAppMessage) => boolean;
14
+ }
15
+
16
+ function createSubscribeSwcAppMessageWhileConnected(options?: SwcAppMessageOptions, messageType?: string): MethodDecorator {
17
+ return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
18
+ const filter = options?.filter;
19
+
20
+ const constructor = target.constructor;
21
+ let list = ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY, constructor) as SwcAppMessageSubscriberMetadata[];
22
+ if (!list) {
23
+ list = [];
24
+ ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY, list, constructor);
25
+ }
26
+ list.push({ propertyKey, messageType, filter });
27
+
28
+ return descriptor;
29
+ };
30
+ }
31
+
32
+ // 오버로드 시그니처 - 직접 사용 (괄호 없음)
33
+ export function subscribeSwcAppMessageWhileConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
34
+ // 오버로드 시그니처 - 함수 호출 (괄호 있음) - 메시지 타입만
35
+ export function subscribeSwcAppMessageWhileConnected(messageType: string): MethodDecorator;
36
+ // 오버로드 시그니처 - 함수 호출 (괄호 있음) - 옵션만
37
+ export function subscribeSwcAppMessageWhileConnected(options: SwcAppMessageOptions): MethodDecorator;
38
+ // 오버로드 시그니처 - 함수 호출 (괄호 있음) - 메시지 타입 + 옵션
39
+ export function subscribeSwcAppMessageWhileConnected(messageType: string, options: SwcAppMessageOptions): MethodDecorator;
40
+
41
+ export function subscribeSwcAppMessageWhileConnected(targetOrMessageTypeOrOptions?: any, optionsOrPropertyKey?: any, descriptor?: PropertyDescriptor): any {
42
+ // 직접 데코레이터로 사용된 경우 (괄호 없음): @subscribeSwcAppMessageWhileConnected
43
+ if (targetOrMessageTypeOrOptions && typeof targetOrMessageTypeOrOptions === 'object' &&
44
+ optionsOrPropertyKey && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') &&
45
+ descriptor) {
46
+ const target = targetOrMessageTypeOrOptions;
47
+ const propertyKey = optionsOrPropertyKey;
48
+ return createSubscribeSwcAppMessageWhileConnected({})(target, propertyKey, descriptor);
49
+ }
50
+
51
+ // 함수로 호출된 경우 (괄호 있음)
52
+ let messageType: string | undefined;
53
+ let options: SwcAppMessageOptions = {};
54
+
55
+ if (typeof targetOrMessageTypeOrOptions === 'string') {
56
+ // 메시지 타입 전달: @subscribeSwcAppMessageWhileConnected('messageType') 또는 @subscribeSwcAppMessageWhileConnected('messageType', options)
57
+ messageType = targetOrMessageTypeOrOptions;
58
+ if (optionsOrPropertyKey && typeof optionsOrPropertyKey === 'object') {
59
+ options = optionsOrPropertyKey;
60
+ }
61
+ } else if (targetOrMessageTypeOrOptions && typeof targetOrMessageTypeOrOptions === 'object') {
62
+ // 옵션만 전달: @subscribeSwcAppMessageWhileConnected({ filter: ... })
63
+ options = targetOrMessageTypeOrOptions;
64
+ }
65
+
66
+ return createSubscribeSwcAppMessageWhileConnected(options, messageType);
67
+ }
68
+
69
+ // Helper function to retrieve message subscribers metadata
70
+ export const getSubscribeSwcAppMessageWhileConnectedMetadata = (target: any): SwcAppMessageSubscriberMetadata[] | undefined => {
71
+ const constructor = target instanceof Function ? target : target.constructor;
72
+ return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY, constructor);
73
+ };
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { Router } from '@dooboostore/core-web';
3
3
 
4
- export const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change');
4
+ export const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change-while-connected');
5
5
 
6
6
  export interface SwcAppRouteChangeSubscriberMetadata {
7
7
  propertyKey: string | symbol;
@@ -14,16 +14,16 @@ export interface SwcAppRouteChangeOptions {
14
14
  filter?: (router: Router) => boolean;
15
15
  }
16
16
 
17
- function createSwcAppRouteChangeSubscriber(options?: SwcAppRouteChangeOptions): MethodDecorator {
17
+ function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
18
18
  return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
19
19
  const pathPattern = options?.path;
20
20
  const filter = options?.filter;
21
21
 
22
22
  const constructor = target.constructor;
23
- let list = ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor) as SwcAppRouteChangeSubscriberMetadata[];
23
+ let list = ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY, constructor) as SwcAppRouteChangeSubscriberMetadata[];
24
24
  if (!list) {
25
25
  list = [];
26
- ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, list, constructor);
26
+ ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY, list, constructor);
27
27
  }
28
28
  list.push({ propertyKey, pathPattern, filter });
29
29
 
@@ -32,40 +32,40 @@ function createSwcAppRouteChangeSubscriber(options?: SwcAppRouteChangeOptions):
32
32
  }
33
33
 
34
34
  // 오버로드 시그니처 - 직접 사용 (괄호 없음)
35
- export function subscribeSwcAppRouteChange(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
35
+ export function subscribeSwcAppRouteChangeWhileConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
36
36
  // 오버로드 시그니처 - 함수 호출 (괄호 있음)
37
- export function subscribeSwcAppRouteChange(): MethodDecorator;
38
- export function subscribeSwcAppRouteChange(pathPattern: string): MethodDecorator;
39
- export function subscribeSwcAppRouteChange(pathPatterns: string[]): MethodDecorator;
40
- export function subscribeSwcAppRouteChange(options: SwcAppRouteChangeOptions): MethodDecorator;
37
+ export function subscribeSwcAppRouteChangeWhileConnected(): MethodDecorator;
38
+ export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: string): MethodDecorator;
39
+ export function subscribeSwcAppRouteChangeWhileConnected(pathPatterns: string[]): MethodDecorator;
40
+ export function subscribeSwcAppRouteChangeWhileConnected(options: SwcAppRouteChangeOptions): MethodDecorator;
41
41
 
42
42
  // 실제 구현 (이중 모드)
43
- export function subscribeSwcAppRouteChange(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
44
- // 직접 데코레이터로 사용된 경우 (괄호 없음): @subscribeSwcAppRouteChange
43
+ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
44
+ // 직접 데코레이터로 사용된 경우 (괄호 없음): @subscribeSwcAppRouteChangeWhileConnected
45
45
  // propertyKey가 string | symbol이고 descriptor가 있으면 직접 사용
46
46
  if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
47
- return createSwcAppRouteChangeSubscriber({})(targetOrOptions, propertyKey, descriptor);
47
+ return createSubscribeSwcAppRouteChangeWhileConnected({})(targetOrOptions, propertyKey, descriptor);
48
48
  }
49
49
 
50
- // 함수로 호출된 경우 (괄호 있음): @subscribeSwcAppRouteChange() / @subscribeSwcAppRouteChange('/path')
50
+ // 함수로 호출된 경우 (괄호 있음): @subscribeSwcAppRouteChangeWhileConnected() / @subscribeSwcAppRouteChangeWhileConnected('/path')
51
51
  let options: SwcAppRouteChangeOptions = {};
52
52
 
53
53
  if (Array.isArray(targetOrOptions)) {
54
- // 배열: @subscribeSwcAppRouteChange(['/path1', '/path2'])
54
+ // 배열: @subscribeSwcAppRouteChangeWhileConnected(['/path1', '/path2'])
55
55
  options.path = targetOrOptions;
56
56
  } else if (typeof targetOrOptions === 'string') {
57
- // 문자열: @subscribeSwcAppRouteChange('/path')
57
+ // 문자열: @subscribeSwcAppRouteChangeWhileConnected('/path')
58
58
  options.path = targetOrOptions;
59
59
  } else if (targetOrOptions && typeof targetOrOptions === 'object') {
60
- // 객체: @subscribeSwcAppRouteChange({ path: '/path', filter: ... })
60
+ // 객체: @subscribeSwcAppRouteChangeWhileConnected({ path: '/path', filter: ... })
61
61
  options = targetOrOptions;
62
62
  }
63
63
 
64
- return createSwcAppRouteChangeSubscriber(options);
64
+ return createSubscribeSwcAppRouteChangeWhileConnected(options);
65
65
  }
66
66
 
67
67
  // Helper function to retrieve route change subscribers metadata
68
- export const getSubscribeSwcAppRouteChangeMetadata = (target: any): SwcAppRouteChangeSubscriberMetadata[] | undefined => {
68
+ export const getSubscribeSwcAppRouteChangeWhileConnectedMetadata = (target: any): SwcAppRouteChangeSubscriberMetadata[] | undefined => {
69
69
  const constructor = target instanceof Function ? target : target.constructor;
70
- return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor);
70
+ return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY, constructor);
71
71
  };
@@ -1,10 +1,11 @@
1
1
  import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';
2
- import { SwcAppInterface } from '../types';
2
+ import { SwcAppInterface, SwcAppMessage } from '../types';
3
3
  import { SwcUtils } from '../utils/Utils';
4
4
  import { FunctionUtils, Subscription } from '@dooboostore/core';
5
5
  import { Router, RouterEventType } from '@dooboostore/core-web';
6
6
  import { ON_CONNECTED_SWC_APP_METADATA_KEY, findAllLifecycleMetadata } from '../decorators/lifecycles';
7
- import { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';
7
+ import { getSubscribeSwcAppRouteChangeWhileConnectedMetadata } from '../decorators/subscribeSwcAppRouteChangeWhileConnected';
8
+ import { getSubscribeSwcAppMessageWhileConnectedMetadata } from '../decorators/subscribeSwcAppMessageWhileConnected';
8
9
 
9
10
  export function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {
10
11
  //@ts-ignore
@@ -29,7 +30,7 @@ export function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Bas
29
30
  }
30
31
 
31
32
  _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {
32
- const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);
33
+ const routeChangeSubscribers = getSubscribeSwcAppRouteChangeWhileConnectedMetadata(instance);
33
34
  if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {
34
35
  routeChangeSubscribers.forEach((metadata: any) => {
35
36
  const methodName = metadata.propertyKey || metadata;
@@ -221,5 +222,43 @@ export function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Bas
221
222
  reload(): void {
222
223
  this.router?.reload();
223
224
  }
225
+
226
+ publishMessage(message: SwcAppMessage): void {
227
+ // 메시지를 모든 connected component instances로 분배
228
+ this._swc_connected_instance.forEach((instance: any) => {
229
+ this._invokeMessageSubscribers(instance, message);
230
+ });
231
+ }
232
+
233
+ _invokeMessageSubscribers(instance: any, message: SwcAppMessage) {
234
+ const messageSubscribers = getSubscribeSwcAppMessageWhileConnectedMetadata(instance);
235
+ if (messageSubscribers && Array.isArray(messageSubscribers)) {
236
+ messageSubscribers.forEach((metadata: any) => {
237
+ const methodName = metadata.propertyKey;
238
+ const messageType = metadata.messageType;
239
+ const filter = metadata.filter;
240
+
241
+ // 메시지 타입 확인
242
+ let typeMatched = false;
243
+ if (!messageType) {
244
+ // messageType이 없으면 모든 메시지 매칭 (와일드카드)
245
+ typeMatched = true;
246
+ } else if (message.type === messageType) {
247
+ typeMatched = true;
248
+ }
249
+
250
+ // 필터 적용
251
+ let filterMatched = true;
252
+ if (filter && typeMatched) {
253
+ filterMatched = filter(message);
254
+ }
255
+
256
+ // 조건을 만족하면 메서드 호출
257
+ if (typeMatched && filterMatched && typeof instance[methodName] === 'function') {
258
+ instance[methodName](message);
259
+ }
260
+ });
261
+ }
262
+ }
224
263
  };
225
264
  }
package/src/types.ts CHANGED
@@ -42,6 +42,13 @@ export type HostSet = {
42
42
  };
43
43
 
44
44
  export type HelperHostSet = HelperSet & HostSet & {$this: any};
45
+
46
+ export type SwcAppMessage<T = any> = {
47
+ publisher?: any;
48
+ data?: T;
49
+ type?: string;
50
+ };
51
+
45
52
  export interface SwcChooseInterface extends HTMLTemplateElement {
46
53
  value: any;
47
54
  refresh(): void;
@@ -58,4 +65,5 @@ export interface SwcAppInterface extends HTMLElement {
58
65
  reload(): void;
59
66
  back(): void;
60
67
  forward(): void;
68
+ publishMessage(message: SwcAppMessage): void;
61
69
  }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/decorators/subscribeSwcAppRouteChange.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { Router } from '@dooboostore/core-web';\n\nexport const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change');\n\nexport interface SwcAppRouteChangeSubscriberMetadata {\n propertyKey: string | symbol;\n pathPattern?: string | string[];\n filter?: (router: Router) => boolean;\n}\n\nexport interface SwcAppRouteChangeOptions {\n path?: string | string[];\n filter?: (router: Router) => boolean;\n}\n\nfunction createSwcAppRouteChangeSubscriber(options?: SwcAppRouteChangeOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n const pathPattern = options?.path;\n const filter = options?.filter;\n\n const constructor = target.constructor;\n let list = ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor) as SwcAppRouteChangeSubscriberMetadata[];\n if (!list) {\n list = [];\n ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, list, constructor);\n }\n list.push({ propertyKey, pathPattern, filter });\n \n return descriptor;\n };\n}\n\n// \uC624\uBC84\uB85C\uB4DC \uC2DC\uADF8\uB2C8\uCC98 - \uC9C1\uC811 \uC0AC\uC6A9 (\uAD04\uD638 \uC5C6\uC74C)\nexport function subscribeSwcAppRouteChange(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\n// \uC624\uBC84\uB85C\uB4DC \uC2DC\uADF8\uB2C8\uCC98 - \uD568\uC218 \uD638\uCD9C (\uAD04\uD638 \uC788\uC74C)\nexport function subscribeSwcAppRouteChange(): MethodDecorator;\nexport function subscribeSwcAppRouteChange(pathPattern: string): MethodDecorator;\nexport function subscribeSwcAppRouteChange(pathPatterns: string[]): MethodDecorator;\nexport function subscribeSwcAppRouteChange(options: SwcAppRouteChangeOptions): MethodDecorator;\n\n// \uC2E4\uC81C \uAD6C\uD604 (\uC774\uC911 \uBAA8\uB4DC)\nexport function subscribeSwcAppRouteChange(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n // \uC9C1\uC811 \uB370\uCF54\uB808\uC774\uD130\uB85C \uC0AC\uC6A9\uB41C \uACBD\uC6B0 (\uAD04\uD638 \uC5C6\uC74C): @subscribeSwcAppRouteChange\n // propertyKey\uAC00 string | symbol\uC774\uACE0 descriptor\uAC00 \uC788\uC73C\uBA74 \uC9C1\uC811 \uC0AC\uC6A9\n if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return createSwcAppRouteChangeSubscriber({})(targetOrOptions, propertyKey, descriptor);\n }\n \n // \uD568\uC218\uB85C \uD638\uCD9C\uB41C \uACBD\uC6B0 (\uAD04\uD638 \uC788\uC74C): @subscribeSwcAppRouteChange() / @subscribeSwcAppRouteChange('/path')\n let options: SwcAppRouteChangeOptions = {};\n\n if (Array.isArray(targetOrOptions)) {\n // \uBC30\uC5F4: @subscribeSwcAppRouteChange(['/path1', '/path2'])\n options.path = targetOrOptions;\n } else if (typeof targetOrOptions === 'string') {\n // \uBB38\uC790\uC5F4: @subscribeSwcAppRouteChange('/path')\n options.path = targetOrOptions;\n } else if (targetOrOptions && typeof targetOrOptions === 'object') {\n // \uAC1D\uCCB4: @subscribeSwcAppRouteChange({ path: '/path', filter: ... })\n options = targetOrOptions;\n }\n\n return createSwcAppRouteChangeSubscriber(options);\n}\n\n// Helper function to retrieve route change subscribers metadata\nexport const getSubscribeSwcAppRouteChangeMetadata = (target: any): SwcAppRouteChangeSubscriberMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAGtB,MAAM,8CAA8C,OAAO,IAAI,qDAAqD;AAa3H,SAAS,kCAAkC,SAAqD;AAC9F,SAAO,CAAC,QAAgB,aAA8B,eAAoC;AACxF,UAAM,cAAc,SAAS;AAC7B,UAAM,SAAS,SAAS;AAExB,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,yBAAa,eAAe,6CAA6C,WAAW;AAC/F,QAAI,CAAC,MAAM;AACT,aAAO,CAAC;AACR,+BAAa,eAAe,6CAA6C,MAAM,WAAW;AAAA,IAC5F;AACA,SAAK,KAAK,EAAE,aAAa,aAAa,OAAO,CAAC;AAE9C,WAAO;AAAA,EACT;AACF;AAWO,SAAS,2BAA2B,iBAAuB,aAA+B,YAAsC;AAGrI,MAAI,gBAAgB,OAAO,gBAAgB,YAAY,OAAO,gBAAgB,WAAW;AACvF,WAAO,kCAAkC,CAAC,CAAC,EAAE,iBAAiB,aAAa,UAAU;AAAA,EACvF;AAGA,MAAI,UAAoC,CAAC;AAEzC,MAAI,MAAM,QAAQ,eAAe,GAAG;AAElC,YAAQ,OAAO;AAAA,EACjB,WAAW,OAAO,oBAAoB,UAAU;AAE9C,YAAQ,OAAO;AAAA,EACjB,WAAW,mBAAmB,OAAO,oBAAoB,UAAU;AAEjE,cAAU;AAAA,EACZ;AAEA,SAAO,kCAAkC,OAAO;AAClD;AAGO,MAAM,wCAAwC,CAAC,WAAmE;AACvH,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,eAAe,6CAA6C,WAAW;AAC7F;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/decorators/subscribeSwcAppRouteChange.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { Router } from '@dooboostore/core-web';\n\nexport const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY = Symbol.for('simple-web-component:subscribe-swc-app-route-change');\n\nexport interface SwcAppRouteChangeSubscriberMetadata {\n propertyKey: string | symbol;\n pathPattern?: string | string[];\n filter?: (router: Router) => boolean;\n}\n\nexport interface SwcAppRouteChangeOptions {\n path?: string | string[];\n filter?: (router: Router) => boolean;\n}\n\nfunction createSwcAppRouteChangeSubscriber(options?: SwcAppRouteChangeOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n const pathPattern = options?.path;\n const filter = options?.filter;\n\n const constructor = target.constructor;\n let list = ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor) as SwcAppRouteChangeSubscriberMetadata[];\n if (!list) {\n list = [];\n ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, list, constructor);\n }\n list.push({ propertyKey, pathPattern, filter });\n \n return descriptor;\n };\n}\n\n// \uC624\uBC84\uB85C\uB4DC \uC2DC\uADF8\uB2C8\uCC98 - \uC9C1\uC811 \uC0AC\uC6A9 (\uAD04\uD638 \uC5C6\uC74C)\nexport function subscribeSwcAppRouteChange(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\n// \uC624\uBC84\uB85C\uB4DC \uC2DC\uADF8\uB2C8\uCC98 - \uD568\uC218 \uD638\uCD9C (\uAD04\uD638 \uC788\uC74C)\nexport function subscribeSwcAppRouteChange(): MethodDecorator;\nexport function subscribeSwcAppRouteChange(pathPattern: string): MethodDecorator;\nexport function subscribeSwcAppRouteChange(pathPatterns: string[]): MethodDecorator;\nexport function subscribeSwcAppRouteChange(options: SwcAppRouteChangeOptions): MethodDecorator;\n\n// \uC2E4\uC81C \uAD6C\uD604 (\uC774\uC911 \uBAA8\uB4DC)\nexport function subscribeSwcAppRouteChange(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {\n // \uC9C1\uC811 \uB370\uCF54\uB808\uC774\uD130\uB85C \uC0AC\uC6A9\uB41C \uACBD\uC6B0 (\uAD04\uD638 \uC5C6\uC74C): @subscribeSwcAppRouteChange\n // propertyKey\uAC00 string | symbol\uC774\uACE0 descriptor\uAC00 \uC788\uC73C\uBA74 \uC9C1\uC811 \uC0AC\uC6A9\n if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {\n return createSwcAppRouteChangeSubscriber({})(targetOrOptions, propertyKey, descriptor);\n }\n \n // \uD568\uC218\uB85C \uD638\uCD9C\uB41C \uACBD\uC6B0 (\uAD04\uD638 \uC788\uC74C): @subscribeSwcAppRouteChange() / @subscribeSwcAppRouteChange('/path')\n let options: SwcAppRouteChangeOptions = {};\n\n if (Array.isArray(targetOrOptions)) {\n // \uBC30\uC5F4: @subscribeSwcAppRouteChange(['/path1', '/path2'])\n options.path = targetOrOptions;\n } else if (typeof targetOrOptions === 'string') {\n // \uBB38\uC790\uC5F4: @subscribeSwcAppRouteChange('/path')\n options.path = targetOrOptions;\n } else if (targetOrOptions && typeof targetOrOptions === 'object') {\n // \uAC1D\uCCB4: @subscribeSwcAppRouteChange({ path: '/path', filter: ... })\n options = targetOrOptions;\n }\n\n return createSwcAppRouteChangeSubscriber(options);\n}\n\n// Helper function to retrieve route change subscribers metadata\nexport const getSubscribeSwcAppRouteChangeMetadata = (target: any): SwcAppRouteChangeSubscriberMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getOwnMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY, constructor);\n};\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAGtB,MAAM,8CAA8C,OAAO,IAAI,qDAAqD;AAa3H,SAAS,kCAAkC,SAAqD;AAC9F,SAAO,CAAC,QAAgB,aAA8B,eAAoC;AACxF,UAAM,cAAc,SAAS;AAC7B,UAAM,SAAS,SAAS;AAExB,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,aAAa,eAAe,6CAA6C,WAAW;AAC/F,QAAI,CAAC,MAAM;AACT,aAAO,CAAC;AACR,mBAAa,eAAe,6CAA6C,MAAM,WAAW;AAAA,IAC5F;AACA,SAAK,KAAK,EAAE,aAAa,aAAa,OAAO,CAAC;AAE9C,WAAO;AAAA,EACT;AACF;AAWO,SAAS,2BAA2B,iBAAuB,aAA+B,YAAsC;AAGrI,MAAI,gBAAgB,OAAO,gBAAgB,YAAY,OAAO,gBAAgB,WAAW;AACvF,WAAO,kCAAkC,CAAC,CAAC,EAAE,iBAAiB,aAAa,UAAU;AAAA,EACvF;AAGA,MAAI,UAAoC,CAAC;AAEzC,MAAI,MAAM,QAAQ,eAAe,GAAG;AAElC,YAAQ,OAAO;AAAA,EACjB,WAAW,OAAO,oBAAoB,UAAU;AAE9C,YAAQ,OAAO;AAAA,EACjB,WAAW,mBAAmB,OAAO,oBAAoB,UAAU;AAEjE,cAAU;AAAA,EACZ;AAEA,SAAO,kCAAkC,OAAO;AAClD;AAGO,MAAM,wCAAwC,CAAC,WAAmE;AACvH,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,eAAe,6CAA6C,WAAW;AAC7F;",
6
- "names": []
7
- }
@@ -1,18 +0,0 @@
1
- import { Router } from '@dooboostore/core-web';
2
- export declare const SUBSCRIBE_SWC_APP_ROUTE_CHANGE_METADATA_KEY: unique symbol;
3
- export interface SwcAppRouteChangeSubscriberMetadata {
4
- propertyKey: string | symbol;
5
- pathPattern?: string | string[];
6
- filter?: (router: Router) => boolean;
7
- }
8
- export interface SwcAppRouteChangeOptions {
9
- path?: string | string[];
10
- filter?: (router: Router) => boolean;
11
- }
12
- export declare function subscribeSwcAppRouteChange(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
13
- export declare function subscribeSwcAppRouteChange(): MethodDecorator;
14
- export declare function subscribeSwcAppRouteChange(pathPattern: string): MethodDecorator;
15
- export declare function subscribeSwcAppRouteChange(pathPatterns: string[]): MethodDecorator;
16
- export declare function subscribeSwcAppRouteChange(options: SwcAppRouteChangeOptions): MethodDecorator;
17
- export declare const getSubscribeSwcAppRouteChangeMetadata: (target: any) => SwcAppRouteChangeSubscriberMetadata[] | undefined;
18
- //# sourceMappingURL=subscribeSwcAppRouteChange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscribeSwcAppRouteChange.d.ts","sourceRoot":"","sources":["../../../src/decorators/subscribeSwcAppRouteChange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,eAAO,MAAM,2CAA2C,eAAoE,CAAC;AAE7H,MAAM,WAAW,mCAAmC;IAClD,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACtC;AAoBD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAEpJ,wBAAgB,0BAA0B,IAAI,eAAe,CAAC;AAC9D,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,CAAC;AACjF,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,eAAe,CAAC;AACpF,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,wBAAwB,GAAG,eAAe,CAAC;AA4B/F,eAAO,MAAM,qCAAqC,GAAI,QAAQ,GAAG,KAAG,mCAAmC,EAAE,GAAG,SAG3G,CAAC"}