@dooboostore/simple-web-component 1.0.33 → 1.0.35

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 (150) hide show
  1. package/README.md +23 -30
  2. package/dist/cjs/decorators/addEventListener.js.map +1 -1
  3. package/dist/cjs/decorators/applyAttribute.js +67 -57
  4. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  5. package/dist/cjs/decorators/applyClass.js +80 -70
  6. package/dist/cjs/decorators/applyClass.js.map +2 -2
  7. package/dist/cjs/decorators/applyNode.js +5 -8
  8. package/dist/cjs/decorators/applyNode.js.map +2 -2
  9. package/dist/cjs/decorators/applyStyle.js +66 -56
  10. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  11. package/dist/cjs/decorators/attribute.js +35 -29
  12. package/dist/cjs/decorators/attribute.js.map +2 -2
  13. package/dist/cjs/decorators/changedAttributeHost.js +32 -12
  14. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  15. package/dist/cjs/decorators/elementDefine.js +238 -180
  16. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  17. package/dist/cjs/decorators/emitCustomEvent.js +67 -48
  18. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  19. package/dist/cjs/decorators/lifecycles.js +15 -17
  20. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  21. package/dist/cjs/decorators/setProperty.js +50 -39
  22. package/dist/cjs/decorators/setProperty.js.map +2 -2
  23. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  24. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  25. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  26. package/dist/cjs/elements/SwcAppEngine.js +14 -8
  27. package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
  28. package/dist/cjs/elements/SwcAppMixin.js +154 -81
  29. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  30. package/dist/cjs/elements/SwcAsync.js +28 -18
  31. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  32. package/dist/cjs/elements/SwcChoose.js +68 -45
  33. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  34. package/dist/cjs/elements/SwcIf.js +52 -30
  35. package/dist/cjs/elements/SwcIf.js.map +2 -2
  36. package/dist/cjs/elements/SwcLoop.js +109 -35
  37. package/dist/cjs/elements/SwcLoop.js.map +2 -2
  38. package/dist/cjs/elements/register.js +263 -131
  39. package/dist/cjs/elements/register.js.map +2 -2
  40. package/dist/cjs/router/ElementRouter.js +4 -2
  41. package/dist/cjs/router/ElementRouter.js.map +1 -1
  42. package/dist/cjs/types.js.map +1 -1
  43. package/dist/cjs/utils/Utils.js +25 -7
  44. package/dist/cjs/utils/Utils.js.map +2 -2
  45. package/dist/esm/decorators/addEventListener.js.map +1 -1
  46. package/dist/esm/decorators/applyAttribute.js +67 -57
  47. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  48. package/dist/esm/decorators/applyClass.js +80 -70
  49. package/dist/esm/decorators/applyClass.js.map +2 -2
  50. package/dist/esm/decorators/applyNode.js +5 -8
  51. package/dist/esm/decorators/applyNode.js.map +2 -2
  52. package/dist/esm/decorators/applyStyle.js +66 -56
  53. package/dist/esm/decorators/applyStyle.js.map +2 -2
  54. package/dist/esm/decorators/attribute.js +35 -29
  55. package/dist/esm/decorators/attribute.js.map +2 -2
  56. package/dist/esm/decorators/changedAttributeHost.js +32 -12
  57. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  58. package/dist/esm/decorators/elementDefine.js +240 -182
  59. package/dist/esm/decorators/elementDefine.js.map +2 -2
  60. package/dist/esm/decorators/emitCustomEvent.js +67 -48
  61. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  62. package/dist/esm/decorators/lifecycles.js +15 -17
  63. package/dist/esm/decorators/lifecycles.js.map +2 -2
  64. package/dist/esm/decorators/setProperty.js +50 -39
  65. package/dist/esm/decorators/setProperty.js.map +2 -2
  66. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  67. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  68. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  69. package/dist/esm/elements/SwcAppEngine.js +14 -7
  70. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  71. package/dist/esm/elements/SwcAppMixin.js +156 -82
  72. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  73. package/dist/esm/elements/SwcAsync.js +28 -18
  74. package/dist/esm/elements/SwcAsync.js.map +2 -2
  75. package/dist/esm/elements/SwcChoose.js +69 -46
  76. package/dist/esm/elements/SwcChoose.js.map +2 -2
  77. package/dist/esm/elements/SwcIf.js +53 -31
  78. package/dist/esm/elements/SwcIf.js.map +2 -2
  79. package/dist/esm/elements/SwcLoop.js +110 -36
  80. package/dist/esm/elements/SwcLoop.js.map +2 -2
  81. package/dist/esm/elements/register.js +264 -132
  82. package/dist/esm/elements/register.js.map +2 -2
  83. package/dist/esm/router/ElementRouter.js +5 -2
  84. package/dist/esm/router/ElementRouter.js.map +1 -1
  85. package/dist/esm/types.js.map +1 -1
  86. package/dist/esm/utils/Utils.js +25 -7
  87. package/dist/esm/utils/Utils.js.map +2 -2
  88. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
  89. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  90. package/dist/types/decorators/addEventListener.d.ts +4 -1
  91. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  92. package/dist/types/decorators/applyAttribute.d.ts +5 -1
  93. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  94. package/dist/types/decorators/applyClass.d.ts +4 -0
  95. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  96. package/dist/types/decorators/applyNode.d.ts +5 -1
  97. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  98. package/dist/types/decorators/applyStyle.d.ts +5 -1
  99. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  100. package/dist/types/decorators/attribute.d.ts +5 -0
  101. package/dist/types/decorators/attribute.d.ts.map +1 -1
  102. package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
  103. package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
  104. package/dist/types/decorators/elementDefine.d.ts +1 -1
  105. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  106. package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
  107. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  108. package/dist/types/decorators/lifecycles.d.ts +10 -7
  109. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  110. package/dist/types/decorators/setProperty.d.ts +5 -1
  111. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  112. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
  113. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  114. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
  115. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  116. package/dist/types/elements/SwcAppEngine.d.ts +9 -3
  117. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  118. package/dist/types/elements/SwcAppMixin.d.ts +12 -7
  119. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  120. package/dist/types/elements/register.d.ts.map +1 -1
  121. package/dist/types/types.d.ts +1 -0
  122. package/dist/types/types.d.ts.map +1 -1
  123. package/dist/types/utils/Utils.d.ts +4 -1
  124. package/dist/types/utils/Utils.d.ts.map +1 -1
  125. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  127. package/package.json +5 -5
  128. package/src/decorators/addEventListener.ts +1 -1
  129. package/src/decorators/applyAttribute.ts +74 -61
  130. package/src/decorators/applyClass.ts +91 -77
  131. package/src/decorators/applyNode.ts +16 -13
  132. package/src/decorators/applyStyle.ts +75 -61
  133. package/src/decorators/attribute.ts +55 -43
  134. package/src/decorators/changedAttributeHost.ts +49 -15
  135. package/src/decorators/elementDefine.ts +401 -340
  136. package/src/decorators/emitCustomEvent.ts +92 -62
  137. package/src/decorators/lifecycles.ts +11 -10
  138. package/src/decorators/setProperty.ts +58 -44
  139. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
  140. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
  141. package/src/elements/SwcAppEngine.ts +19 -13
  142. package/src/elements/SwcAppMixin.ts +214 -102
  143. package/src/elements/SwcAsync.ts +28 -17
  144. package/src/elements/SwcChoose.ts +94 -36
  145. package/src/elements/SwcIf.ts +59 -22
  146. package/src/elements/SwcLoop.ts +140 -27
  147. package/src/elements/register.ts +319 -100
  148. package/src/types.ts +1 -0
  149. package/src/utils/Utils.ts +38 -10
  150. package/tsconfig.json +2 -2
@@ -1,24 +1,28 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { SpecialSelector, SwcQueryOptions } from '../types';
3
- import { ensureInit, getElementConfig } from './elementDefine';
4
- import { SwcUtils } from '../utils/Utils';
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {SpecialSelector, SwcQueryOptions, HelperHostSet} from '../types';
3
+ import {ensureInit, getElementConfig} from './elementDefine';
4
+ import {SwcUtils} from '../utils/Utils';
5
5
 
6
6
  export interface EmitCustomEventBaseOptions {
7
7
  bubbles?: boolean;
8
8
  composed?: boolean;
9
9
  cancelable?: boolean;
10
+ filter?: (target: EventTarget, detail: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
10
11
  }
11
12
 
13
+ type Options = (EmitCustomEventBaseOptions & SwcQueryOptions) | (EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string });
14
+
12
15
  export interface EmitCustomEventMetadata {
13
16
  propertyKey: string | symbol;
14
17
  selector: string;
15
18
  type: string;
16
- options: (EmitCustomEventBaseOptions & SwcQueryOptions) | (EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string });
19
+ options: Options;
17
20
  }
18
21
 
19
22
  export const EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol.for('simple-web-component:emit-custom-event');
20
- export function emitCustomEvent(target: SpecialSelector, type: string, options?: EmitCustomEventBaseOptions): MethodDecorator;
21
- export function emitCustomEvent(selector: string, type: string, options?: EmitCustomEventBaseOptions & SwcQueryOptions): MethodDecorator;
23
+
24
+ export function emitCustomEvent(target: SpecialSelector, type: string, options?: Options): MethodDecorator;
25
+ export function emitCustomEvent(selector: string, type: string, options?: Options): MethodDecorator;
22
26
  /**
23
27
  * @emitCustomEvent decorator to dispatch custom events to a target.
24
28
  */
@@ -26,7 +30,7 @@ export function emitCustomEvent(selectorOrTarget: string, type: string, options:
26
30
  return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
27
31
  const constructor = targetObj.constructor;
28
32
 
29
- const fullOptions: any = { ...options, type };
33
+ const fullOptions: any = {...options, type};
30
34
 
31
35
  if (fullOptions.bubbles === undefined) fullOptions.bubbles = true;
32
36
  if (fullOptions.composed === undefined) fullOptions.composed = true;
@@ -36,62 +40,77 @@ export function emitCustomEvent(selectorOrTarget: string, type: string, options:
36
40
  list = [];
37
41
  ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
38
42
  }
39
- list.push({ propertyKey, selector: selectorOrTarget, type, options: fullOptions });
43
+ list.push({propertyKey, selector: selectorOrTarget, type, options: fullOptions});
40
44
 
41
45
  const original = descriptor.value;
42
- descriptor.value = async function (...args: any[]) {
46
+ descriptor.value = function (...args: any[]) {
43
47
  ensureInit(this);
44
- const detail = await original.apply(this, args);
45
- const event = new CustomEvent(type, {
46
- detail,
47
- bubbles: fullOptions.bubbles,
48
- composed: fullOptions.composed,
49
- cancelable: fullOptions.cancelable
50
- });
51
-
52
- const hostSet = SwcUtils.getHostSet(this as any);
53
- const conf = getElementConfig(this);
54
- const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
55
- // console.log('emitEEEEEEEEEEE', hostSet);
56
-
57
- const eventTargets: EventTarget[] = [];
58
- if (selectorOrTarget === ':window') eventTargets.push(currentWin);
59
- else if (selectorOrTarget === ':document') eventTargets.push(currentWin.document);
60
- else if (selectorOrTarget === ':parentHost') {
61
- if (hostSet.$parentHost) eventTargets.push(hostSet.$parentHost);
62
- } else if (selectorOrTarget === ':appHost') {
63
- if (hostSet.$appHost) eventTargets.push(hostSet.$appHost);
64
- } else if (selectorOrTarget === ':firstHost') {
65
- if (hostSet.$firstHost) eventTargets.push(hostSet.$firstHost);
66
- } else if (selectorOrTarget === ':lastHost') {
67
- if (hostSet.$lastHost) eventTargets.push(hostSet.$lastHost);
68
- } else if (selectorOrTarget === ':firstAppHost') {
69
- if (hostSet.$firstAppHost) eventTargets.push(hostSet.$firstAppHost);
70
- } else if (selectorOrTarget === ':lastAppHost') {
71
- if (hostSet.$lastAppHost) eventTargets.push(hostSet.$lastAppHost);
72
- } else if (selectorOrTarget === ':hosts') {
73
- hostSet.$hosts.forEach(h => eventTargets.push(h));
74
- } else if (selectorOrTarget === ':appHosts') {
75
- hostSet.$appHosts.forEach(h => eventTargets.push(h));
76
- } else if (selectorOrTarget === ':host' || !selectorOrTarget) eventTargets.push(this as any);
77
- else {
78
- const r = fullOptions.root || 'auto';
79
- const searchRoots: (HTMLElement | ShadowRoot)[] = [];
80
- if (r === 'auto') searchRoots.push(this.shadowRoot || (this as any));
81
- else if (r === 'light') searchRoots.push(this as any);
82
- else if (r === 'shadow' && this.shadowRoot) searchRoots.push(this.shadowRoot);
83
- else if (r === 'all') {
84
- searchRoots.push(this as any);
85
- if (this.shadowRoot) searchRoots.push(this.shadowRoot);
48
+ const res = original.apply(this, args);
49
+
50
+ const handleResult = (detail: any) => {
51
+ const event = new CustomEvent(type, {
52
+ detail,
53
+ bubbles: fullOptions.bubbles,
54
+ composed: fullOptions.composed,
55
+ cancelable: fullOptions.cancelable
56
+ });
57
+
58
+ const hostSet = SwcUtils.getHostSet(this as any);
59
+ const conf = getElementConfig(this);
60
+ const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
61
+
62
+ const eventTargets: EventTarget[] = [];
63
+ if (selectorOrTarget === ':window') eventTargets.push(currentWin);
64
+ else if (selectorOrTarget === ':document') eventTargets.push(currentWin.document);
65
+ else if (selectorOrTarget === ':parentHost') {
66
+ if (hostSet.$parentHost) eventTargets.push(hostSet.$parentHost);
67
+ } else if (selectorOrTarget === ':appHost') {
68
+ if (hostSet.$appHost) eventTargets.push(hostSet.$appHost);
69
+ } else if (selectorOrTarget === ':firstHost') {
70
+ if (hostSet.$firstHost) eventTargets.push(hostSet.$firstHost);
71
+ } else if (selectorOrTarget === ':lastHost') {
72
+ if (hostSet.$lastHost) eventTargets.push(hostSet.$lastHost);
73
+ } else if (selectorOrTarget === ':firstAppHost') {
74
+ if (hostSet.$firstAppHost) eventTargets.push(hostSet.$firstAppHost);
75
+ } else if (selectorOrTarget === ':lastAppHost') {
76
+ if (hostSet.$lastAppHost) eventTargets.push(hostSet.$lastAppHost);
77
+ } else if (selectorOrTarget === ':hosts') {
78
+ hostSet.$hosts.forEach(h => eventTargets.push(h));
79
+ } else if (selectorOrTarget === ':appHosts') {
80
+ hostSet.$appHosts.forEach(h => eventTargets.push(h));
81
+ } else if (selectorOrTarget === ':host' || !selectorOrTarget) {
82
+ eventTargets.push(this as any);
83
+ } else {
84
+ const r = fullOptions.root || 'auto';
85
+ const searchRoots: (HTMLElement | ShadowRoot)[] = [];
86
+ if (r === 'auto') searchRoots.push(this.shadowRoot || (this as any));
87
+ else if (r === 'light') searchRoots.push(this as any);
88
+ else if (r === 'shadow' && this.shadowRoot) searchRoots.push(this.shadowRoot);
89
+ else if (r === 'all') {
90
+ searchRoots.push(this as any);
91
+ if (this.shadowRoot) searchRoots.push(this.shadowRoot);
92
+ }
93
+
94
+ searchRoots.forEach(sr => {
95
+ sr.querySelectorAll(selectorOrTarget).forEach(el => eventTargets.push(el));
96
+ });
86
97
  }
87
98
 
88
- searchRoots.forEach(sr => {
89
- sr.querySelectorAll(selectorOrTarget).forEach(el => eventTargets.push(el));
99
+ eventTargets.forEach(t => {
100
+ if (fullOptions.filter && !fullOptions.filter(t, detail, {currentThis: this, helper: hostSet})) {
101
+ return;
102
+ }
103
+ t.dispatchEvent(event);
90
104
  });
91
- }
92
105
 
93
- eventTargets.forEach(t => t.dispatchEvent(event));
94
- return detail;
106
+ return detail;
107
+ };
108
+
109
+ if (res instanceof Promise) {
110
+ return res.then(handleResult);
111
+ } else {
112
+ return handleResult(res);
113
+ }
95
114
  };
96
115
  };
97
116
  }
@@ -105,13 +124,24 @@ export const getEmitCustomEventMetadataList = (target: any): EmitCustomEventMeta
105
124
  * @emitCustomEventHost decorator - simplified version of @emitCustomEvent for :host selector
106
125
  * Usage: @emitCustomEventHost('navigate') // default attributeName: 'on-emit-navigate'
107
126
  * Usage: @emitCustomEventHost('navigate', { attributeName: 'on-navigate' })
108
- *
127
+ *
109
128
  * The attributeName option is used to automatically observe attributes for this event.
110
129
  * For example, { attributeName: 'on-navigate' } will add 'on-navigate' to observedAttributes.
111
130
  */
112
- export function emitCustomEventHost(type: string, options: EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string } = {}): MethodDecorator {
113
- if (!options.attributeName) {
114
- options.attributeName = `on-emit-${type}`;
131
+ export function emitCustomEventHost(type: string, options: EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string }): MethodDecorator ;
132
+ export function emitCustomEventHost(type: string, attributeName: string): MethodDecorator ;
133
+ export function emitCustomEventHost(type: string): MethodDecorator;
134
+ export function emitCustomEventHost(type: string, optionsOrAttributeaName?: string | (EmitCustomEventBaseOptions & SwcQueryOptions & { attributeName?: string })): MethodDecorator {
135
+ if (optionsOrAttributeaName && typeof optionsOrAttributeaName === 'string') {
136
+ return emitCustomEventHost(type, {attributeName: optionsOrAttributeaName});
137
+ } else if (optionsOrAttributeaName && typeof optionsOrAttributeaName === 'object') {
138
+ if (!optionsOrAttributeaName.attributeName) {
139
+ optionsOrAttributeaName.attributeName = `on-emit-${type}`;
140
+ }
141
+ return emitCustomEvent(':host', type, optionsOrAttributeaName);
142
+ } else {
143
+ return emitCustomEvent(':host', type, {attributeName: `on-emit-${type}`});
115
144
  }
116
- return emitCustomEvent(':host', type, options);
145
+
146
+
117
147
  }
@@ -14,6 +14,7 @@ export const INNER_HTML_METADATA_KEY = Symbol.for('simple-web-component:inner-ht
14
14
  export const ATTRIBUTE_CHANGED_WILDCARD = '*';
15
15
 
16
16
  export interface InnerHtmlOptions {
17
+ replaceWrap?:{ start: string, end:string},
17
18
  useShadow?: boolean;
18
19
  }
19
20
 
@@ -35,21 +36,21 @@ function createLifecycleDecorator(metadataKey: symbol): MethodDecorator {
35
36
  }
36
37
 
37
38
  export const onInitialize = createLifecycleDecorator(ON_INITIALIZE_METADATA_KEY);
38
- export const onBeforeConnected = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
39
- export const onAfterConnected = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
40
- export const onConnected = onAfterConnected;
39
+ export const onConnectedBefore = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
40
+ export const onConnectedAfter = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
41
+ export const onConnected = onConnectedAfter;
41
42
 
42
- export const onBeforeDisconnected = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
43
- export const onAfterDisconnected = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
44
- export const onDisconnected = onAfterDisconnected;
43
+ export const onDisconnectedBefore = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
44
+ export const onDisconnectedAfter = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
45
+ export const onDisconnected = onDisconnectedAfter;
45
46
 
46
- export const onBeforeAdopted = createLifecycleDecorator(ON_BEFORE_ADOPTED_METADATA_KEY);
47
- export const onAfterAdopted = createLifecycleDecorator(ON_AFTER_ADOPTED_METADATA_KEY);
48
- export const onAdopted = onAfterAdopted;
47
+ export const onAdoptedBefore = createLifecycleDecorator(ON_BEFORE_ADOPTED_METADATA_KEY);
48
+ export const onAdoptedAfter = createLifecycleDecorator(ON_AFTER_ADOPTED_METADATA_KEY);
49
+ export const onAdopted = onAdoptedAfter;
49
50
 
50
51
  export const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER_METADATA_KEY);
51
52
 
52
- export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
53
+ // export const onConnectedSwcApp = createLifecycleDecorator(ON_CONNECTED_SWC_APP_METADATA_KEY);
53
54
 
54
55
  /**
55
56
  * @onConnectedInnerHtml decorator to define the initial HTML content when connected.
@@ -1,10 +1,11 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
- import { SwcQueryOptions } from '../types';
4
+ import { HelperHostSet, SwcQueryOptions } from '../types';
5
5
 
6
6
  export interface PropertySetOptions extends SwcQueryOptions {
7
7
  name?: string;
8
+ filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
8
9
  }
9
10
 
10
11
  export interface PropertySetMetadata {
@@ -38,55 +39,68 @@ export const setProperty = (selector: string, propertyNameOrOptions?: string | P
38
39
  });
39
40
 
40
41
  const original = descriptor.value;
41
- descriptor.value = async function (...args: any[]) {
42
+ descriptor.value = function (...args: any[]) {
42
43
  ensureInit(this);
43
- const res = await (original as any).apply(this, args);
44
- if (res !== undefined) {
45
- const win = (this as any).ownerDocument?.defaultView || window;
46
- const host = this as unknown as HTMLElement;
47
- const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
48
- const r = finalOptions.root || 'auto';
49
- const targetEls: HTMLElement[] = [];
44
+ const res = (original as any).apply(this, args);
50
45
 
51
- const applyRoot = (t: any) => {
52
- if (!t || !(t instanceof win.HTMLElement)) return;
53
- targetEls.push(t);
54
- };
46
+ const handleResult = (resolvedValue: any) => {
47
+ if (resolvedValue !== undefined) {
48
+ const win = (this as any).ownerDocument?.defaultView || window;
49
+ const host = this as unknown as HTMLElement;
50
+ const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
51
+ const r = finalOptions.root || 'auto';
52
+ const targetEls: HTMLElement[] = [];
55
53
 
56
- if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
57
- else if (selector === ':appHost') applyRoot(hostSet.$appHost);
58
- else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
59
- else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
60
- else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
61
- else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
62
- else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
63
- else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
64
- else if (selector === ':host' || !selector) applyRoot(host);
65
- else {
66
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
67
- if (targetRoot) {
68
- const found = targetRoot.querySelectorAll(selector);
69
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
54
+ const applyRoot = (t: any) => {
55
+ if (!t || !(t instanceof win.HTMLElement)) return;
56
+ targetEls.push(t);
57
+ };
58
+
59
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
60
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
61
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
62
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
63
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
64
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
65
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
66
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
67
+ else if (selector === ':host' || !selector) applyRoot(host);
68
+ else {
69
+ const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
70
+ if (targetRoot) {
71
+ const found = targetRoot.querySelectorAll(selector);
72
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
73
+ }
70
74
  }
71
- }
72
75
 
73
- targetEls.forEach(targetEl => {
74
- const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;
76
+ targetEls.forEach(targetEl => {
77
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
78
+ return;
79
+ }
80
+ const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
75
81
 
76
- if (propertyName) {
77
- // Case: @setProperty(selector, 'propertyName')
78
- (targetEl as any)[propertyName] = resolvedRes;
79
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
80
- // Case: @setProperty(selector) with Object return - assign multiple properties
81
- Object.entries(resolvedRes as any).forEach(([prop, val]) => {
82
- const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
83
- (targetEl as any)[prop] = finalVal;
84
- });
85
- } else {
86
- // Simple value - assign to 'value' property by default
87
- (targetEl as any).value = resolvedRes;
88
- }
89
- });
82
+ if (propertyName) {
83
+ // Case: @setProperty(selector, 'propertyName')
84
+ (targetEl as any)[propertyName] = resolvedRes;
85
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
86
+ // Case: @setProperty(selector) with Object return - assign multiple properties
87
+ Object.entries(resolvedRes as any).forEach(([prop, val]) => {
88
+ const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
89
+ (targetEl as any)[prop] = finalVal;
90
+ });
91
+ } else {
92
+ // Simple value - assign to 'value' property by default
93
+ (targetEl as any).value = resolvedRes;
94
+ }
95
+ });
96
+ }
97
+ return resolvedValue;
98
+ };
99
+
100
+ if (res instanceof Promise) {
101
+ return res.then(handleResult);
102
+ } else {
103
+ return handleResult(res);
90
104
  }
91
105
  };
92
106
  };
@@ -6,11 +6,11 @@ export const SUBSCRIBE_SWC_APP_MESSAGE_WHILE_CONNECTED_METADATA_KEY = Symbol.for
6
6
  export interface SwcAppMessageSubscriberMetadata {
7
7
  propertyKey: string | symbol;
8
8
  messageType?: string;
9
- filter?: (message: SwcAppMessage) => boolean;
9
+ filter?: (message: SwcAppMessage, currentThis: any) => boolean;
10
10
  }
11
11
 
12
12
  export interface SwcAppMessageOptions {
13
- filter?: (message: SwcAppMessage) => boolean;
13
+ filter?: (message: SwcAppMessage, currentThis: any) => boolean;
14
14
  }
15
15
 
16
16
  function createSubscribeSwcAppMessageWhileConnected(options?: SwcAppMessageOptions, messageType?: string): MethodDecorator {
@@ -3,15 +3,16 @@ import { Router } from '@dooboostore/core-web';
3
3
 
4
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
+ export type RoutePathType = string | string[] | ((currentThis: any) => string | string[]);
7
+
6
8
  export interface SwcAppRouteChangeSubscriberMetadata {
7
9
  propertyKey: string | symbol;
8
- pathPattern?: string | string[];
9
- filter?: (router: Router) => boolean;
10
+ options?: SwcAppRouteChangeOptions;
10
11
  }
11
12
 
12
13
  export interface SwcAppRouteChangeOptions {
13
- path?: string | string[];
14
- filter?: (router: Router) => boolean;
14
+ path?: RoutePathType;
15
+ filter?: (router: Router, currentThis: any) => boolean;
15
16
  }
16
17
 
17
18
  function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
@@ -25,8 +26,8 @@ function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteCha
25
26
  list = [];
26
27
  ReflectUtils.defineMetadata(SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY, list, constructor);
27
28
  }
28
- list.push({ propertyKey, pathPattern, filter });
29
-
29
+ list.push({ propertyKey, options });
30
+
30
31
  return descriptor;
31
32
  };
32
33
  }
@@ -35,8 +36,7 @@ function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteCha
35
36
  export function subscribeSwcAppRouteChangeWhileConnected(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
36
37
  // 오버로드 시그니처 - 함수 호출 (괄호 있음)
37
38
  export function subscribeSwcAppRouteChangeWhileConnected(): MethodDecorator;
38
- export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: string): MethodDecorator;
39
- export function subscribeSwcAppRouteChangeWhileConnected(pathPatterns: string[]): MethodDecorator;
39
+ export function subscribeSwcAppRouteChangeWhileConnected(pathPattern: RoutePathType): MethodDecorator;
40
40
  export function subscribeSwcAppRouteChangeWhileConnected(options: SwcAppRouteChangeOptions): MethodDecorator;
41
41
 
42
42
  // 실제 구현 (이중 모드)
@@ -46,15 +46,15 @@ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any,
46
46
  if (propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
47
47
  return createSubscribeSwcAppRouteChangeWhileConnected({})(targetOrOptions, propertyKey, descriptor);
48
48
  }
49
-
49
+
50
50
  // 함수로 호출된 경우 (괄호 있음): @subscribeSwcAppRouteChangeWhileConnected() / @subscribeSwcAppRouteChangeWhileConnected('/path')
51
51
  let options: SwcAppRouteChangeOptions = {};
52
52
 
53
53
  if (Array.isArray(targetOrOptions)) {
54
54
  // 배열: @subscribeSwcAppRouteChangeWhileConnected(['/path1', '/path2'])
55
55
  options.path = targetOrOptions;
56
- } else if (typeof targetOrOptions === 'string') {
57
- // 문자열: @subscribeSwcAppRouteChangeWhileConnected('/path')
56
+ } else if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'function') {
57
+ // 문자열 또는 함수: @subscribeSwcAppRouteChangeWhileConnected('/path')
58
58
  options.path = targetOrOptions;
59
59
  } else if (targetOrOptions && typeof targetOrOptions === 'object') {
60
60
  // 객체: @subscribeSwcAppRouteChangeWhileConnected({ path: '/path', filter: ... })
@@ -1,26 +1,29 @@
1
1
  import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';
2
- import { PathRouter } from '@dooboostore/core-web';
3
- import { HashRouter } from '@dooboostore/core-web';
2
+ import { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';
4
3
  import { ElementRouter } from '../router/ElementRouter';
5
4
  import { SimOption } from '@dooboostore/simple-boot/SimOption';
6
- import { Router, RouterEventType } from '@dooboostore/core-web';
7
- import { Subscription } from '@dooboostore/core';
8
- import { ConstructorType, OptionalType } from '@dooboostore/core';
9
- import { FunctionUtils } from '@dooboostore/core';
10
- import { SwcUtils } from '../utils/Utils';
5
+ import { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';
11
6
 
12
7
  import { SwcAppInterface } from '../types';
13
- import {Intent} from "@dooboostore/simple-boot";
8
+ import { SimConfig } from '@dooboostore/simple-boot';
14
9
 
15
10
  export type SwcConfigType = {
16
11
  routeType: 'path' | 'hash' | 'element';
17
- connectMode?: 'direct' | 'swap';
12
+ connectMode?: 'direct' | 'swap' | 'clear-swap';
18
13
  container?: symbol;
14
+ otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;
19
15
  path?: string;
20
16
  window: Window;
21
17
  onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => void;
22
18
  onConnected?: (app: SwcAppInterface) => void;
23
19
  onDisconnected?: (app: SwcAppInterface) => void;
20
+
21
+ onChildrenConnectedDone?: (app: SwcAppInterface) => void;
22
+ // onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;
23
+ // childrenSwcAppStartedDoneCheckIntervalTime?: number;
24
+ onChildrenRouteChanged?: (event: RouterEventType, app: SwcAppInterface) => void;
25
+ childrenRouteChangedCheckIntervalTime?: number; // 자식 연결 완료 이벤트 디바운스 타임 (ms)
26
+ childrenConnectedDoneCheckIntervalTime?: number;
24
27
  };
25
28
 
26
29
  export type SwcAttributeConfigType = OptionalType<SwcConfigType, 'routeType' | 'window'>;
@@ -36,6 +39,7 @@ export class SwcAppEngine {
36
39
  get config() {
37
40
  return this._config;
38
41
  }
42
+
39
43
  async connect(config: SwcConfigType) {
40
44
  try {
41
45
  this._config = config;
@@ -52,15 +56,17 @@ export class SwcAppEngine {
52
56
  // console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv', this.router)
53
57
 
54
58
  // App start
55
- const containerSymbol = this._config.container || (this.host as any).getContainerSymbol?.();
56
59
  this.simpleApplication = new SimpleApplication(
57
60
  new SimOption({
58
- excludeProxys: [Node],
59
- container: containerSymbol
61
+ excludeProxys: [(this._config.window as any).Node],
62
+ container: this._config.container
60
63
  })
61
64
  );
62
65
 
63
66
  const otherInstanceSim = new Map<any, any>();
67
+ this.config?.otherInstanceSim?.forEach((v, k) => {
68
+ otherInstanceSim.set(k, v);
69
+ });
64
70
  if (this.router) otherInstanceSim.set(Router, this.router);
65
71
  this.simpleApplication.run(otherInstanceSim);
66
72
 
@@ -68,7 +74,7 @@ export class SwcAppEngine {
68
74
  this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
69
75
  }
70
76
  } catch (e) {
71
- console.error('[SWC-APP-ENGINE] Init failed:', e);
77
+ console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);
72
78
  }
73
79
  }
74
80