@dooboostore/simple-web-component 1.0.37 → 1.0.39
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 +280 -791
- package/dist/cjs/SwcAppEngine.js +3 -0
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +20 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js.map +1 -1
- package/dist/cjs/decorators/applyClass.js.map +1 -1
- package/dist/cjs/decorators/applyNode.js +104 -35
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +69 -57
- package/dist/cjs/decorators/applySlot.js.map +3 -3
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js.map +1 -1
- package/dist/cjs/decorators/elementDefine.js +65 -42
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +1 -1
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +47 -31
- package/dist/cjs/decorators/lifecycles.js.map +3 -3
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/cjs/decorators/query.js +1 -1
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js.map +1 -1
- package/dist/cjs/decorators/setProperty.js.map +1 -1
- package/dist/cjs/decorators/state.js +83 -0
- package/dist/cjs/decorators/state.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcApp.js +193 -305
- package/dist/cjs/elements/SwcApp.js.map +3 -3
- package/dist/cjs/elements/SwcAppMixin.js +291 -0
- package/dist/cjs/elements/SwcAppMixin.js.map +7 -0
- package/dist/cjs/elements/index.js +3 -21
- package/dist/cjs/elements/index.js.map +3 -3
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/{types.js → types/index.js} +1 -1
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/cjs/utils/Utils.js +159 -20
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/SwcAppEngine.js +3 -0
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +20 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js.map +1 -1
- package/dist/esm/decorators/applyClass.js.map +1 -1
- package/dist/esm/decorators/applyNode.js +104 -35
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +69 -57
- package/dist/esm/decorators/applySlot.js.map +3 -3
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js.map +1 -1
- package/dist/esm/decorators/elementDefine.js +69 -46
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +47 -31
- package/dist/esm/decorators/lifecycles.js.map +3 -3
- package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/esm/decorators/query.js +1 -1
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js.map +1 -1
- package/dist/esm/decorators/setProperty.js.map +1 -1
- package/dist/esm/decorators/state.js +64 -0
- package/dist/esm/decorators/state.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcApp.js +195 -307
- package/dist/esm/elements/SwcApp.js.map +3 -3
- package/dist/esm/elements/SwcAppMixin.js +273 -0
- package/dist/esm/elements/SwcAppMixin.js.map +7 -0
- package/dist/esm/elements/index.js +2 -7
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/{types.js → types/index.js} +1 -1
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/Utils.js +159 -20
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3448 -2584
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts +1 -1
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +5 -2
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +23 -7
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +14 -12
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -14
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +1 -1
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts +9 -0
- package/dist/types/decorators/state.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcApp.d.ts +35 -6
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +405 -0
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +2 -2
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/Utils.d.ts +14 -2
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3431 -2567
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +4 -4
- package/src/SwcAppEngine.ts +6 -2
- package/src/decorators/addEventListener.ts +21 -5
- package/src/decorators/applyAttribute.ts +1 -1
- package/src/decorators/applyClass.ts +1 -1
- package/src/decorators/applyNode.ts +183 -73
- package/src/decorators/applySlot.ts +99 -128
- package/src/decorators/applyStyle.ts +4 -4
- package/src/decorators/attribute.ts +1 -1
- package/src/decorators/elementDefine.ts +112 -60
- package/src/decorators/emitCustomEvent.ts +1 -1
- package/src/decorators/index.ts +2 -0
- package/src/decorators/lifecycles.ts +50 -26
- package/src/decorators/publishSwcAppMessage.ts +2 -3
- package/src/decorators/query.ts +4 -4
- package/src/decorators/queryAll.ts +1 -1
- package/src/decorators/setProperty.ts +1 -1
- package/src/decorators/state.ts +83 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
- package/src/elements/SwcApp.ts +239 -441
- package/src/elements/SwcAppMixin.ts +328 -0
- package/src/elements/index.ts +2 -9
- package/src/index.ts +2 -4
- package/src/{types.ts → types/index.ts} +13 -10
- package/src/types/window.d.ts +3 -0
- package/src/utils/Utils.ts +205 -20
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/types.js.map +0 -7
- package/dist/types/types.d.ts.map +0 -1
package/src/elements/SwcApp.ts
CHANGED
|
@@ -1,443 +1,241 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export const tagName = 'swc-app';
|
|
20
|
-
export default async (w: Window) => {
|
|
21
|
-
const existing = w.customElements.get(tagName);
|
|
1
|
+
import {elementDefine} from "../decorators";
|
|
2
|
+
import {SwcAppInterface} from "../types";
|
|
3
|
+
import {SwcAppMixin} from "./SwcAppMixin";
|
|
4
|
+
import {SwcUtils, createElement, CreateElementConfig} from "../utils/Utils";
|
|
5
|
+
|
|
6
|
+
// ============================================
|
|
7
|
+
// SwcApp (HTMLElement)
|
|
8
|
+
// ============================================
|
|
9
|
+
export const swcAppTagName = 'swc-app';
|
|
10
|
+
|
|
11
|
+
export const SwcApp = (w: Window, data?: CreateElementConfig) => {
|
|
12
|
+
return createElement<SwcAppInterface>(w, swcAppTagName, data);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const defineSwcApp = async (w: Window) => {
|
|
16
|
+
const existing = w.customElements.get(swcAppTagName);
|
|
22
17
|
if (existing) return existing;
|
|
23
18
|
|
|
24
|
-
@elementDefine(
|
|
25
|
-
class
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
await this.__swc_engine.connect(swcConfig);
|
|
248
|
-
} else if (mode === 'swap' || mode === 'clear-swap') {
|
|
249
|
-
if (!this.parentNode) {
|
|
250
|
-
// 부모가 없으면 swap을 할 수 없으므로 direct로 폴백합니다.
|
|
251
|
-
await this.__swc_engine.connect(swcConfig);
|
|
252
|
-
this.setAttribute('swc-connect-mode', 'direct');
|
|
253
|
-
} else {
|
|
254
|
-
// 1. 현재 SSR 상태(화면)를 그대로 유지한 채로, 백그라운드용 클론을 만듭니다.
|
|
255
|
-
const clonedApp = this.cloneNode(mode === 'swap') as any; // clear-swap 모드면 자식 노드를 클론하지 않음(false)
|
|
256
|
-
clonedApp.style.display = 'none';
|
|
257
|
-
|
|
258
|
-
// 2. DOM에 클론을 몰래 붙입니다.
|
|
259
|
-
this.parentNode.insertBefore(clonedApp, this.nextSibling);
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
// 3. 클론을 direct 모드로 연결(초기화/렌더링) 시킵니다.
|
|
263
|
-
await clonedApp.connect({...(config || {}), connectMode: 'direct'});
|
|
264
|
-
|
|
265
|
-
// 4. 클론의 렌더링이 완전히 끝나면, 기존 SSR 화면(this)을 지우고 클론을 보여줍니다.
|
|
266
|
-
if (this.parentNode) {
|
|
267
|
-
this.parentNode.removeChild(this);
|
|
268
|
-
}
|
|
269
|
-
clonedApp.style.display = '';
|
|
270
|
-
clonedApp.setAttribute('swc-connect-mode', mode);
|
|
271
|
-
|
|
272
|
-
// ★ 매우 중요: 교체가 완료되었으므로 기존 앱(this)은 여기서 즉시 종료하여 불필요한 라우터/이벤트 구독을 막아야 합니다!
|
|
273
|
-
return;
|
|
274
|
-
} catch (e) {
|
|
275
|
-
// 실패 시 클론을 지우고 원본을 direct로 강제 연결합니다.
|
|
276
|
-
if (clonedApp.parentNode) {
|
|
277
|
-
clonedApp.parentNode.removeChild(clonedApp);
|
|
278
|
-
}
|
|
279
|
-
await this.__swc_engine.connect(swcConfig);
|
|
280
|
-
this.setAttribute('swc-connect-mode', 'direct');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// 사파리일떄 예외이다 is 일때 polyfill되는데 이떄 부모부터 만들어지는게 아니라 자식부터 만들어진다 그래서 부모가 만들어질때 자식들이 이미 만들어져있어서 부모가 자식들을 등록해주는 형태로 강제로 등록해준다
|
|
286
|
-
this._connected_safari_and_standby.forEach((instance: any) => {
|
|
287
|
-
// console.log('safari!!!!!!!!!!', instance)
|
|
288
|
-
this._connected(instance, {noIncrements: true});
|
|
289
|
-
// this._swc_connected_instance.add(instance);
|
|
290
|
-
});
|
|
291
|
-
// Invoke @onConnectedSwcApp lifecycle methods on all connected component instances
|
|
292
|
-
// const hostSet = SwcUtils.getHostSet(this as any);
|
|
293
|
-
|
|
294
|
-
// const scis = Array.from(this._swc_connected_instance);
|
|
295
|
-
// await Promise.allSettled(scis.map(instance => this._invokeOnConnectedSwcAppStarted(instance)));
|
|
296
|
-
|
|
297
|
-
// this._swc_connected_instance.forEach((instance: any) => {
|
|
298
|
-
// this._invokeOnConnectedSwcAppStarted(instance);
|
|
299
|
-
// });
|
|
300
|
-
|
|
301
|
-
// Subscribe to router changes after connect
|
|
302
|
-
if (!this._routerSubscription && this.router) {
|
|
303
|
-
const config = this.__swc_engine.config;
|
|
304
|
-
|
|
305
|
-
this._routerSubscription = this.router.observable.subscribe(async (route: RouterEventType) => {
|
|
306
|
-
console.log('[SWC] Router event received:', route.triggerPoint);
|
|
307
|
-
if (route.triggerPoint === 'end') {
|
|
308
|
-
// 1. 모든 기존 연결된 자식들에게 라우트 이벤트 알림
|
|
309
|
-
await this._handleRouteChange(route);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
// Navigate to initial path if specified
|
|
314
|
-
if (config?.path) {
|
|
315
|
-
console.log('[DEBUG] Navigating to initial path:', config.path);
|
|
316
|
-
// this.router.go(config.path);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// async _invokeOnConnectedSwcAppStarted(instance: any) {
|
|
322
|
-
// this._swcAppStartedInvocations++;
|
|
323
|
-
// try {
|
|
324
|
-
// // 이미 시작된 인스턴스라면 스킵 (비동기 병렬 중복 호출 방지)
|
|
325
|
-
// if (this._swc_started_instances.has(instance)) return;
|
|
326
|
-
// this._swc_started_instances.add(instance);
|
|
327
|
-
//
|
|
328
|
-
// const startedMethods = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY);
|
|
329
|
-
// if (startedMethods) {
|
|
330
|
-
// const ps = startedMethods.map(m => instance._invokeLifecycleMethod(m));
|
|
331
|
-
// await Promise.allSettled(ps);
|
|
332
|
-
// }
|
|
333
|
-
// } finally {
|
|
334
|
-
// this._swcAppStartedInvocations--;
|
|
335
|
-
// }
|
|
336
|
-
// }
|
|
337
|
-
|
|
338
|
-
connectedCallback() {
|
|
339
|
-
// this.innerHTML='';
|
|
340
|
-
// @ts-ignore
|
|
341
|
-
if (super.connectedCallback) super.connectedCallback();
|
|
342
|
-
|
|
343
|
-
const configStr = this.getAttribute('swc-get-application-config');
|
|
344
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
345
|
-
if (configStr && win) {
|
|
346
|
-
try {
|
|
347
|
-
// console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))
|
|
348
|
-
const userConfig = FunctionUtils.executeReturn({
|
|
349
|
-
script: configStr,
|
|
350
|
-
context: this,
|
|
351
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
352
|
-
});
|
|
353
|
-
this.connect(userConfig);
|
|
354
|
-
} catch (e) {
|
|
355
|
-
console.error('[SWC-APP-ENGINE] Script execution failed:', e);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// 자기자신은 apphost로 포함이 도지않으니(부모) 내자신은 self로 넣는다
|
|
360
|
-
this._connected(this);
|
|
361
|
-
this.__swc_engine?.config?.onConnected?.(this);
|
|
362
|
-
this._connectedDone(this);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
disconnectedCallback() {
|
|
366
|
-
// @ts-ignore
|
|
367
|
-
if (super.disconnectedCallback) super.disconnectedCallback();
|
|
368
|
-
this._routerSubscription?.unsubscribe();
|
|
369
|
-
this._routerSubscription = undefined;
|
|
370
|
-
this._lastRouterEvent = undefined;
|
|
371
|
-
this.__swc_engine.disconnect();
|
|
372
|
-
this.__swc_engine?.config?.onDisconnected?.(this);
|
|
373
|
-
this._disconnected(this);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
async routing(path: string) {
|
|
377
|
-
await this.router?.go(path);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
back(): void {
|
|
381
|
-
this.router?.back();
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
forward(): void {
|
|
385
|
-
this.router?.forward();
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
reload(): void {
|
|
389
|
-
this.router?.reload();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// async completedSwcApp() {
|
|
393
|
-
// const ss = Array.from(this._swc_connected_instance).flatMap((it) => {
|
|
394
|
-
// const ms = findAllLifecycleMetadata(it, ON_CONNECTED_COMPLETED_SWC_APP_METADATA_KEY) ?? [];
|
|
395
|
-
// return ms.map((sit) => it[sit](this));
|
|
396
|
-
// });
|
|
397
|
-
// await Promise.allSettled(ss);
|
|
398
|
-
// }
|
|
399
|
-
|
|
400
|
-
publishMessage(message: SwcAppMessage): void {
|
|
401
|
-
// 메시지를 모든 connected component instances로 분배
|
|
402
|
-
this._swc_connected_instance.forEach((instance: any) => {
|
|
403
|
-
this._invokeMessageSubscribers(instance, message);
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
_invokeMessageSubscribers(instance: any, message: SwcAppMessage) {
|
|
408
|
-
const messageSubscribers = getSubscribeSwcAppMessageWhileConnectedMetadata(instance);
|
|
409
|
-
if (messageSubscribers && Array.isArray(messageSubscribers)) {
|
|
410
|
-
messageSubscribers.forEach(metadata => {
|
|
411
|
-
const methodName = metadata.propertyKey;
|
|
412
|
-
const messageType = metadata.messageType;
|
|
413
|
-
const filter = metadata.filter;
|
|
414
|
-
|
|
415
|
-
// 메시지 타입 확인
|
|
416
|
-
let typeMatched = false;
|
|
417
|
-
if (!messageType) {
|
|
418
|
-
// messageType이 없으면 모든 메시지 매칭 (와일드카드)
|
|
419
|
-
typeMatched = true;
|
|
420
|
-
} else if (message.type === messageType) {
|
|
421
|
-
typeMatched = true;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// 필터 적용
|
|
425
|
-
let filterMatched = true;
|
|
426
|
-
if (filter && typeMatched) {
|
|
427
|
-
filterMatched = filter(message, instance);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// 조건을 만족하면 메서드 호출
|
|
431
|
-
if (typeMatched && filterMatched && typeof instance[methodName] === 'function') {
|
|
432
|
-
instance[methodName](message);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return w.customElements.whenDefined(tagName);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
19
|
+
@elementDefine(swcAppTagName, {window: w})
|
|
20
|
+
class SwcAppImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
21
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return w.customElements.whenDefined(swcAppTagName);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// ============================================
|
|
28
|
+
// SwcAppBody (HTMLBodyElement)
|
|
29
|
+
// ============================================
|
|
30
|
+
export const swcAppBodyTagName = 'swc-app-body';
|
|
31
|
+
|
|
32
|
+
export const SwcAppBody = (w: Window, data?: CreateElementConfig) => {
|
|
33
|
+
return createElement<SwcAppInterface & HTMLBodyElement>(w, swcAppBodyTagName, data);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const defineSwcAppBody = async (w: Window) => {
|
|
37
|
+
const existing = w.customElements.get(swcAppBodyTagName);
|
|
38
|
+
if (existing) return existing;
|
|
39
|
+
|
|
40
|
+
@elementDefine(swcAppBodyTagName, {window: w, extends: 'body'})
|
|
41
|
+
class SwcAppBodyImpl extends SwcAppMixin(w.HTMLBodyElement) implements SwcAppInterface {
|
|
42
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return w.customElements.whenDefined(swcAppBodyTagName);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ============================================
|
|
49
|
+
// SwcAppDiv (HTMLDivElement)
|
|
50
|
+
// ============================================
|
|
51
|
+
export const swcAppDivTagName = 'swc-app-div';
|
|
52
|
+
|
|
53
|
+
export const SwcAppDiv = (w: Window, data?: CreateElementConfig) => {
|
|
54
|
+
return createElement<SwcAppInterface & HTMLDivElement>(w, swcAppDivTagName, data);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const defineSwcAppDiv = async (w: Window) => {
|
|
58
|
+
const existing = w.customElements.get(swcAppDivTagName);
|
|
59
|
+
if (existing) return existing;
|
|
60
|
+
|
|
61
|
+
@elementDefine(swcAppDivTagName, {window: w, extends: 'div'})
|
|
62
|
+
class SwcAppDivImpl extends SwcAppMixin(w.HTMLDivElement) implements SwcAppInterface {
|
|
63
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return w.customElements.whenDefined(swcAppDivTagName);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ============================================
|
|
70
|
+
// SwcAppSection (HTMLElement)
|
|
71
|
+
// ============================================
|
|
72
|
+
export const swcAppSectionTagName = 'swc-app-section';
|
|
73
|
+
|
|
74
|
+
export const SwcAppSection = (w: Window, data?: CreateElementConfig) => {
|
|
75
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppSectionTagName, data);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const defineSwcAppSection = async (w: Window) => {
|
|
79
|
+
const existing = w.customElements.get(swcAppSectionTagName);
|
|
80
|
+
if (existing) return existing;
|
|
81
|
+
|
|
82
|
+
@elementDefine(swcAppSectionTagName, {window: w, extends: 'section'})
|
|
83
|
+
class SwcAppSectionImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
84
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return w.customElements.whenDefined(swcAppSectionTagName);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// ============================================
|
|
91
|
+
// SwcAppMain (HTMLElement)
|
|
92
|
+
// ============================================
|
|
93
|
+
export const swcAppMainTagName = 'swc-app-main';
|
|
94
|
+
|
|
95
|
+
export const SwcAppMain = (w: Window, data?: CreateElementConfig) => {
|
|
96
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppMainTagName, data);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const defineSwcAppMain = async (w: Window) => {
|
|
100
|
+
const existing = w.customElements.get(swcAppMainTagName);
|
|
101
|
+
if (existing) return existing;
|
|
102
|
+
|
|
103
|
+
@elementDefine(swcAppMainTagName, {window: w, extends: 'main'})
|
|
104
|
+
class SwcAppMainImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
105
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return w.customElements.whenDefined(swcAppMainTagName);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// ============================================
|
|
112
|
+
// SwcAppArticle (HTMLElement)
|
|
113
|
+
// ============================================
|
|
114
|
+
export const swcAppArticleTagName = 'swc-app-article';
|
|
115
|
+
|
|
116
|
+
export const SwcAppArticle = (w: Window, data?: CreateElementConfig) => {
|
|
117
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppArticleTagName, data);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const defineSwcAppArticle = async (w: Window) => {
|
|
121
|
+
const existing = w.customElements.get(swcAppArticleTagName);
|
|
122
|
+
if (existing) return existing;
|
|
123
|
+
|
|
124
|
+
@elementDefine(swcAppArticleTagName, {window: w, extends: 'article'})
|
|
125
|
+
class SwcAppArticleImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
126
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return w.customElements.whenDefined(swcAppArticleTagName);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ============================================
|
|
133
|
+
// SwcAppHeader (HTMLElement)
|
|
134
|
+
// ============================================
|
|
135
|
+
export const swcAppHeaderTagName = 'swc-app-header';
|
|
136
|
+
|
|
137
|
+
export const SwcAppHeader = (w: Window, data?: CreateElementConfig) => {
|
|
138
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppHeaderTagName, data);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const defineSwcAppHeader = async (w: Window) => {
|
|
142
|
+
const existing = w.customElements.get(swcAppHeaderTagName);
|
|
143
|
+
if (existing) return existing;
|
|
144
|
+
|
|
145
|
+
@elementDefine(swcAppHeaderTagName, {window: w, extends: 'header'})
|
|
146
|
+
class SwcAppHeaderImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
147
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return w.customElements.whenDefined(swcAppHeaderTagName);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// ============================================
|
|
154
|
+
// SwcAppFooter (HTMLElement)
|
|
155
|
+
// ============================================
|
|
156
|
+
export const swcAppFooterTagName = 'swc-app-footer';
|
|
157
|
+
|
|
158
|
+
export const SwcAppFooter = (w: Window, data?: CreateElementConfig) => {
|
|
159
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppFooterTagName, data);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export const defineSwcAppFooter = async (w: Window) => {
|
|
163
|
+
const existing = w.customElements.get(swcAppFooterTagName);
|
|
164
|
+
if (existing) return existing;
|
|
165
|
+
|
|
166
|
+
@elementDefine(swcAppFooterTagName, {window: w, extends: 'footer'})
|
|
167
|
+
class SwcAppFooterImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
168
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return w.customElements.whenDefined(swcAppFooterTagName);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// ============================================
|
|
175
|
+
// SwcAppNav (HTMLElement)
|
|
176
|
+
// ============================================
|
|
177
|
+
export const swcAppNavTagName = 'swc-app-nav';
|
|
178
|
+
|
|
179
|
+
export const SwcAppNav = (w: Window, data?: CreateElementConfig) => {
|
|
180
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppNavTagName, data);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const defineSwcAppNav = async (w: Window) => {
|
|
184
|
+
const existing = w.customElements.get(swcAppNavTagName);
|
|
185
|
+
if (existing) return existing;
|
|
186
|
+
|
|
187
|
+
@elementDefine(swcAppNavTagName, {window: w, extends: 'nav'})
|
|
188
|
+
class SwcAppNavImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
189
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return w.customElements.whenDefined(swcAppNavTagName);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// ============================================
|
|
196
|
+
// SwcAppAside (HTMLElement)
|
|
197
|
+
// ============================================
|
|
198
|
+
export const swcAppAsideTagName = 'swc-app-aside';
|
|
199
|
+
|
|
200
|
+
export const SwcAppAside = (w: Window, data?: CreateElementConfig) => {
|
|
201
|
+
return createElement<SwcAppInterface & HTMLElement>(w, swcAppAsideTagName, data);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const defineSwcAppAside = async (w: Window) => {
|
|
205
|
+
const existing = w.customElements.get(swcAppAsideTagName);
|
|
206
|
+
if (existing) return existing;
|
|
207
|
+
|
|
208
|
+
@elementDefine(swcAppAsideTagName, {window: w, extends: 'aside'})
|
|
209
|
+
class SwcAppAsideImpl extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
210
|
+
// SwcAppMixin에서 모든 기능을 상속받음
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return w.customElements.whenDefined(swcAppAsideTagName);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// ============================================
|
|
217
|
+
// Factory Array
|
|
218
|
+
// ============================================
|
|
219
|
+
export const swcAppFactories = [
|
|
220
|
+
defineSwcApp,
|
|
221
|
+
defineSwcAppBody,
|
|
222
|
+
defineSwcAppDiv,
|
|
223
|
+
defineSwcAppSection,
|
|
224
|
+
defineSwcAppMain,
|
|
225
|
+
defineSwcAppArticle,
|
|
226
|
+
defineSwcAppHeader,
|
|
227
|
+
defineSwcAppFooter,
|
|
228
|
+
defineSwcAppNav,
|
|
229
|
+
defineSwcAppAside
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
// ============================================
|
|
233
|
+
// Define All SwcApp Elements
|
|
234
|
+
// ============================================
|
|
235
|
+
export const defineSwcAppAll = async (w: Window) => {
|
|
236
|
+
await Promise.all(swcAppFactories.map(factory => factory(w)));
|
|
237
|
+
return w.customElements.whenDefined(swcAppTagName);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// Default export for backward compatibility
|
|
241
|
+
export default defineSwcAppAll;
|