@dooboostore/simple-web-component 1.0.42 → 1.0.44
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 +689 -85
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +10 -0
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +41 -30
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +66 -23
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +176 -107
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +21 -30
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +11 -2
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +48 -17
- package/dist/cjs/decorators/applyStyle.js.map +3 -3
- package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
- package/dist/cjs/decorators/changedAttribute.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +37 -6
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +58 -42
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js +37 -23
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/cjs/decorators/query.js +96 -145
- package/dist/cjs/decorators/query.js.map +3 -3
- package/dist/cjs/decorators/queryAll.js +104 -131
- package/dist/cjs/decorators/queryAll.js.map +3 -3
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +17 -2
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -0
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/esm/SwcAppEngine.js +3 -1
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +10 -0
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +41 -30
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +66 -23
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +176 -107
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +21 -30
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +11 -2
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +48 -17
- package/dist/esm/decorators/applyStyle.js.map +3 -3
- package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
- package/dist/esm/decorators/changedAttribute.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +35 -4
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +58 -42
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/publishSwcAppMessage.js +37 -23
- package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
- package/dist/esm/decorators/query.js +96 -145
- package/dist/esm/decorators/query.js.map +3 -3
- package/dist/esm/decorators/queryAll.js +104 -131
- package/dist/esm/decorators/queryAll.js.map +3 -3
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +18 -3
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +4 -0
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +900 -578
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +22 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +61 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +22 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +178 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +53 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts +6 -0
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +13 -7
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +20 -10
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts +19 -0
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +3 -26
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +3 -20
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +4 -4
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +900 -578
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +7 -9
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +35 -24
- package/src/decorators/applyAttribute.ts +167 -65
- package/src/decorators/applyClass.ts +113 -17
- package/src/decorators/applyNode.ts +383 -102
- package/src/decorators/applyProperty.ts +99 -65
- package/src/decorators/applySlot.ts +24 -10
- package/src/decorators/applyStyle.ts +83 -13
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +62 -35
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +71 -27
- package/src/decorators/query.ts +90 -159
- package/src/decorators/queryAll.ts +92 -134
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
- package/src/elements/SwcAppMixin.ts +43 -24
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/index.ts +2 -0
- package/src/router/ElementRouter.ts +4 -0
- package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
- package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
- package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
|
@@ -11,155 +11,113 @@ export interface QueryAllMetadata {
|
|
|
11
11
|
|
|
12
12
|
export const QUERY_ALL_METADATA_KEY = Symbol.for('simple-web-component:query-all');
|
|
13
13
|
|
|
14
|
-
export function queryAll(target:
|
|
14
|
+
export function queryAll(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void;
|
|
15
15
|
export function queryAll(selector: string, options?: SwcQueryOptions): PropertyDecorator;
|
|
16
|
+
export function queryAll(options?: SwcQueryOptions): PropertyDecorator;
|
|
16
17
|
/**
|
|
17
18
|
* @queryAll decorator to inject a list of elements into a class property.
|
|
18
19
|
*/
|
|
19
|
-
export function queryAll(selectorOrTarget
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
queries.push({ propertyKey, selector: selectorOrTarget, options });
|
|
20
|
+
export function queryAll(selectorOrTarget?: string | Object, optionsOrPropertyKey?: SwcQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
21
|
+
// Bare decorator: @queryAll
|
|
22
|
+
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
23
|
+
throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(optionsOrPropertyKey)})`);
|
|
24
|
+
}
|
|
25
|
+
// With selector
|
|
26
|
+
if (typeof selectorOrTarget === 'string') {
|
|
27
|
+
return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {
|
|
28
|
+
if (descriptor !== undefined) {
|
|
29
|
+
throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
30
|
+
}
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const constructor = targetObj.constructor;
|
|
33
|
+
let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);
|
|
34
|
+
if (!queries) {
|
|
35
|
+
queries = [];
|
|
36
|
+
ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
|
|
37
|
+
}
|
|
38
|
+
queries.push({ propertyKey, selector: selectorOrTarget, options: optionsOrPropertyKey as SwcQueryOptions || {} });
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const results: any[] = [];
|
|
43
|
-
items.forEach(it => {
|
|
44
|
-
if (!(it instanceof HTMLElement)) {
|
|
45
|
-
results.push(it);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (r === 'auto') results.push(it.shadowRoot || it);
|
|
49
|
-
else {
|
|
50
|
-
if (r === 'light' || r === 'all') results.push(it);
|
|
51
|
-
if ((r === 'shadow' || r === 'all') && it.shadowRoot) results.push(it.shadowRoot);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return results;
|
|
55
|
-
};
|
|
40
|
+
Object.defineProperty(targetObj, propertyKey, {
|
|
41
|
+
get(this: HTMLElement) {
|
|
42
|
+
ensureInit(this);
|
|
43
|
+
const selector = selectorOrTarget;
|
|
56
44
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
46
|
+
const applyRoot = (t: any): any[] => {
|
|
47
|
+
if (!t) return [];
|
|
48
|
+
const items = Array.isArray(t) ? t : [t];
|
|
49
|
+
const results: any[] = [];
|
|
50
|
+
items.forEach(it => {
|
|
51
|
+
if (!(it instanceof HTMLElement)) {
|
|
52
|
+
results.push(it);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (r === 'auto') results.push(it.shadowRoot || it);
|
|
56
|
+
else {
|
|
57
|
+
if (r === 'light' || r === 'all') results.push(it);
|
|
58
|
+
if ((r === 'shadow' || r === 'all') && it.shadowRoot) results.push(it.shadowRoot);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return results;
|
|
62
|
+
};
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
// --- Special Selectors: HostSet ---
|
|
65
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
66
|
+
if (selector === '$hosts') return applyRoot(hostSet.$hosts);
|
|
67
|
+
if (selector === '$appHosts') return applyRoot(hostSet.$appHosts);
|
|
68
|
+
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
69
|
+
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
70
|
+
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
71
|
+
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
72
|
+
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
73
|
+
if (selector === '$firstAppHost') return applyRoot(hostSet.$firstAppHost);
|
|
74
|
+
if (selector === '$lastAppHost') return applyRoot(hostSet.$lastAppHost);
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return [...sNodes, ...lNodes];
|
|
83
|
-
}
|
|
84
|
-
const root = this.shadowRoot || this;
|
|
85
|
-
return Array.from(root.querySelectorAll(selector));
|
|
86
|
-
},
|
|
87
|
-
set(this: HTMLElement, nv: any) {
|
|
88
|
-
ensureInit(this);
|
|
89
|
-
if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {
|
|
90
|
-
const selector = selectorOrTarget;
|
|
91
|
-
if (selector.startsWith('$') && selector !== '$this') return;
|
|
76
|
+
// --- Special Selectors: Env ---
|
|
77
|
+
const config = getElementConfig(this);
|
|
78
|
+
const win = config?.window || window;
|
|
79
|
+
if (selector === '$window') return [win];
|
|
80
|
+
if (selector === '$document') return [win.document];
|
|
81
|
+
if (selector === '$this') return applyRoot(this);
|
|
92
82
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (r === '
|
|
96
|
-
|
|
97
|
-
else if (r === 'all') {
|
|
83
|
+
// --- Standard Selectors ---
|
|
84
|
+
if (r === 'shadow') return this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
85
|
+
if (r === 'light') return Array.from(this.querySelectorAll(selector));
|
|
86
|
+
if (r === 'all') {
|
|
98
87
|
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
99
88
|
const lNodes = Array.from(this.querySelectorAll(selector));
|
|
100
|
-
|
|
101
|
-
} else {
|
|
102
|
-
targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
|
|
89
|
+
return [...sNodes, ...lNodes];
|
|
103
90
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
91
|
+
const root = this.shadowRoot || this;
|
|
92
|
+
return Array.from(root.querySelectorAll(selector));
|
|
93
|
+
},
|
|
94
|
+
set(this: HTMLElement, nv: any) {
|
|
95
|
+
ensureInit(this);
|
|
96
|
+
if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {
|
|
97
|
+
const selector = selectorOrTarget;
|
|
98
|
+
if (selector.startsWith('$') && selector !== '$this') return;
|
|
112
99
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @allParentHost - Query all parent SWC components
|
|
133
|
-
*/
|
|
134
|
-
export function allParentHost(target: Object, propertyKey: string | symbol): void;
|
|
135
|
-
export function allParentHost(): PropertyDecorator;
|
|
136
|
-
export function allParentHost(options: SwcQueryOptions): PropertyDecorator;
|
|
137
|
-
export function allParentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
138
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
139
|
-
return queryAll('$host', {})(targetOrOptions, propertyKey);
|
|
140
|
-
}
|
|
141
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
142
|
-
return queryAll('$host', targetOrOptions as SwcQueryOptions);
|
|
143
|
-
} else {
|
|
144
|
-
return queryAll('$host', {});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @allAppHost - Query all $appHost (All <swc-app> instances)
|
|
150
|
-
*/
|
|
151
|
-
export function allAppHost(target: Object, propertyKey: string | symbol): void;
|
|
152
|
-
export function allAppHost(): PropertyDecorator;
|
|
153
|
-
export function allAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
154
|
-
export function allAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
155
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
156
|
-
return queryAll('$appHost', {})(targetOrOptions, propertyKey);
|
|
157
|
-
}
|
|
158
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
159
|
-
return queryAll('$appHost', targetOrOptions as SwcQueryOptions);
|
|
160
|
-
} else {
|
|
161
|
-
return queryAll('$appHost', {});
|
|
100
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
101
|
+
let targets: (Element | Node)[] = [];
|
|
102
|
+
if (r === 'shadow') targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
103
|
+
else if (r === 'light') targets = Array.from(this.querySelectorAll(selector));
|
|
104
|
+
else if (r === 'all') {
|
|
105
|
+
const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
|
|
106
|
+
const lNodes = Array.from(this.querySelectorAll(selector));
|
|
107
|
+
targets = [...sNodes, ...lNodes];
|
|
108
|
+
} else {
|
|
109
|
+
targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
|
|
110
|
+
}
|
|
111
|
+
targets.forEach(t => (t as Element).remove());
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
};
|
|
162
118
|
}
|
|
119
|
+
// Without selector (defaults to $this)
|
|
120
|
+
return queryAll('$this', selectorOrTarget as SwcQueryOptions);
|
|
163
121
|
}
|
|
164
122
|
|
|
165
123
|
export const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {
|
|
@@ -66,6 +66,7 @@ export function subscribeSwcAppMessageWhileConnected(targetOrMessageTypeOrOption
|
|
|
66
66
|
return createSubscribeSwcAppMessageWhileConnected(options, messageType);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export const receiveMessage = subscribeSwcAppMessageWhileConnected;
|
|
69
70
|
// Helper function to retrieve message subscribers metadata
|
|
70
71
|
export const getSubscribeSwcAppMessageWhileConnectedMetadata = (target: any): SwcAppMessageSubscriberMetadata[] | undefined => {
|
|
71
72
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -13,8 +13,9 @@ export interface SwcAppRouteChangeSubscriberMetadata {
|
|
|
13
13
|
|
|
14
14
|
export interface SwcAppRouteChangeOptions {
|
|
15
15
|
path?: RoutePathType;
|
|
16
|
-
filter?: (router: Router, meta: {currentThis: any
|
|
16
|
+
filter?: (router: Router, meta: { currentThis: any; helper: HelperHostSet }) => boolean;
|
|
17
17
|
order?: number;
|
|
18
|
+
valueKey?: symbol | string;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
function createSubscribeSwcAppRouteChangeWhileConnected(options?: SwcAppRouteChangeOptions): MethodDecorator {
|
|
@@ -74,6 +75,7 @@ export function subscribeSwcAppRouteChangeWhileConnected(targetOrOptions?: any,
|
|
|
74
75
|
|
|
75
76
|
return createSubscribeSwcAppRouteChangeWhileConnected(options);
|
|
76
77
|
}
|
|
78
|
+
export const changedRoute = subscribeSwcAppRouteChangeWhileConnected;
|
|
77
79
|
|
|
78
80
|
// Helper function to retrieve route change subscribers metadata
|
|
79
81
|
export const getSubscribeSwcAppRouteChangeWhileConnectedMetadata = (target: any): SwcAppRouteChangeSubscriberMetadata[] => {
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {SwcAppInterface, SwcAppMessage} from
|
|
2
|
-
import {findAllLifecycleMetadata, getSubscribeSwcAppMessageWhileConnectedMetadata, getSubscribeSwcAppRouteChangeWhileConnectedMetadata, ON_CONNECTED_SWC_APP_METADATA_KEY} from
|
|
3
|
-
import {SwcAppEngine, SwcAttributeConfigType, SwcConfigType} from
|
|
4
|
-
import {debounceTimeIntervalLock, FunctionUtils, Subscription} from
|
|
5
|
-
import {RouterEventType} from
|
|
6
|
-
import {SwcUtils} from
|
|
1
|
+
import { SwcAppInterface, SwcAppMessage } from '../types';
|
|
2
|
+
import { APPLY_NODE_METADATA_KEY, findAllLifecycleMetadata, getSubscribeSwcAppMessageWhileConnectedMetadata, getSubscribeSwcAppRouteChangeWhileConnectedMetadata, ON_CONNECTED_SWC_APP_METADATA_KEY, SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY } from '../decorators';
|
|
3
|
+
import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from '../SwcAppEngine';
|
|
4
|
+
import { debounceTimeIntervalLock, FunctionUtils, Subscription } from '@dooboostore/core';
|
|
5
|
+
import { RouterEventType } from '@dooboostore/core-web';
|
|
6
|
+
import { SwcUtils } from '../utils/Utils';
|
|
7
7
|
|
|
8
8
|
export const isSSR = (i: HTMLElement) => {
|
|
9
9
|
return i.hasAttribute('swc-use-ssr');
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
export const setSSRAttribute = (i: HTMLElement) => {
|
|
12
12
|
i.setAttribute('swc-use-ssr', (i as any)._swcId ?? '');
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
export const removeSSRAttribute = (i: HTMLElement) => {
|
|
15
15
|
i.removeAttribute('swc-use-ssr');
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* SwcAppMixin: SwcApp 기능을 모든 HTMLElement에 추가할 수 있는 Mixin
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
21
|
* 사용 예:
|
|
22
22
|
* @elementDefine('custom-app', { window: w })
|
|
23
23
|
* class CustomApp extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {
|
|
24
24
|
* // 추가 기능 구현
|
|
25
25
|
* }
|
|
26
26
|
*/
|
|
27
|
-
export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base: T) {
|
|
27
|
+
export function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {
|
|
28
28
|
return class SwcAppMixinClass extends Base implements SwcAppInterface {
|
|
29
29
|
__swc_engine = new SwcAppEngine(this as any);
|
|
30
30
|
_swc_connected_instance = new Set<any>();
|
|
@@ -45,7 +45,7 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
45
45
|
|
|
46
46
|
constructor(...args: any[]) {
|
|
47
47
|
super(...args);
|
|
48
|
-
console.log('[SWC-APP-MIXIN] constructor')
|
|
48
|
+
console.log('[SWC-APP-MIXIN] constructor');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
get simpleApplication() {
|
|
@@ -68,12 +68,12 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
68
68
|
if (this._childrenRouteChangedInterval) {
|
|
69
69
|
this.config.window.clearInterval(this._childrenRouteChangedInterval);
|
|
70
70
|
}
|
|
71
|
-
const intervalConfig = {setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window)};
|
|
71
|
+
const intervalConfig = { setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window) };
|
|
72
72
|
this._childrenRouteChangedInterval = debounceTimeIntervalLock(
|
|
73
73
|
() => this._routeChangeInvocations === 0,
|
|
74
74
|
() => {
|
|
75
75
|
this._childrenRouteChangedInterval = null;
|
|
76
|
-
this.config.onChildrenRouteChanged?.(re, this)
|
|
76
|
+
this.config.onChildrenRouteChanged?.(re, this);
|
|
77
77
|
},
|
|
78
78
|
this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,
|
|
79
79
|
intervalConfig
|
|
@@ -81,15 +81,23 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
81
81
|
|
|
82
82
|
try {
|
|
83
83
|
const routeChangeSubscribers = getSubscribeSwcAppRouteChangeWhileConnectedMetadata(instance);
|
|
84
|
+
|
|
84
85
|
if (routeChangeSubscribers.length > 0) {
|
|
85
|
-
console.log('[SWC-MIXIN] Route change subscribers found')
|
|
86
|
-
|
|
86
|
+
console.log('[SWC-MIXIN] Route change subscribers found');
|
|
87
|
+
|
|
87
88
|
// Subscribers are already sorted by order from getSubscribeSwcAppRouteChangeWhileConnectedMetadata
|
|
88
89
|
// Execute subscribers in order, stop if one returns a value
|
|
89
90
|
for (const metadata of routeChangeSubscribers) {
|
|
90
91
|
const methodName = metadata.propertyKey;
|
|
91
92
|
let pathPattern = metadata.options?.path as any;
|
|
92
93
|
const filter = metadata.options?.filter;
|
|
94
|
+
const extractValue = (v: any) => {
|
|
95
|
+
const keyToUse = metadata.options?.valueKey ?? SUBSCRIBE_SWC_APP_ROUTE_CHANGE_WHILE_CONNECTED_METADATA_KEY;
|
|
96
|
+
if (v && typeof v === 'object' && keyToUse in v) {
|
|
97
|
+
return v[keyToUse];
|
|
98
|
+
}
|
|
99
|
+
return v;
|
|
100
|
+
};
|
|
93
101
|
|
|
94
102
|
if (typeof pathPattern === 'function') {
|
|
95
103
|
pathPattern = (pathPattern as Function)(instance);
|
|
@@ -116,10 +124,11 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
const hostSet = SwcUtils.getHelperAndHostSet(this.config.window, this);
|
|
119
|
-
const filterPassed = !filter || filter(this.router!, {helper:hostSet, currentThis:instance});
|
|
127
|
+
const filterPassed = !filter || filter(this.router!, { helper: hostSet, currentThis: instance });
|
|
120
128
|
|
|
121
129
|
if (pathMatched && filterPassed && instance[methodName]) {
|
|
122
|
-
const result = await instance[methodName]({...re, pathData: pathData});
|
|
130
|
+
const result = extractValue(await instance[methodName]({ ...re, pathData: pathData }));
|
|
131
|
+
// if (typeof result === 'object'
|
|
123
132
|
// If handler returns a value, stop propagation to next handlers
|
|
124
133
|
if (result !== undefined && result !== null) {
|
|
125
134
|
break;
|
|
@@ -158,12 +167,12 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
158
167
|
if (this._childrenConnectedDoneInterval) {
|
|
159
168
|
this.config.window.clearInterval(this._childrenConnectedDoneInterval);
|
|
160
169
|
}
|
|
161
|
-
const intervalConfig = {setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window)};
|
|
170
|
+
const intervalConfig = { setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window) };
|
|
162
171
|
this._childrenConnectedDoneInterval = debounceTimeIntervalLock(
|
|
163
172
|
() => this._connectedInvocations === 0,
|
|
164
173
|
() => {
|
|
165
174
|
this._childrenConnectedDoneInterval = null;
|
|
166
|
-
this.config.onChildrenConnectedDone?.(this)
|
|
175
|
+
this.config.onChildrenConnectedDone?.(this);
|
|
167
176
|
},
|
|
168
177
|
this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,
|
|
169
178
|
intervalConfig
|
|
@@ -213,7 +222,7 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
213
222
|
}
|
|
214
223
|
|
|
215
224
|
async connect(config?: SwcAttributeConfigType) {
|
|
216
|
-
console.log('[SWC-MIXIN] connect')
|
|
225
|
+
console.log('[SWC-MIXIN] connect');
|
|
217
226
|
const swcConfig = {
|
|
218
227
|
routeType: 'element',
|
|
219
228
|
window: config?.window,
|
|
@@ -224,7 +233,7 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
224
233
|
|
|
225
234
|
// Safari is 속성 처리
|
|
226
235
|
this._connected_safari_and_standby.forEach((instance: any) => {
|
|
227
|
-
this._connected(instance, {noIncrements: true});
|
|
236
|
+
this._connected(instance, { noIncrements: true });
|
|
228
237
|
});
|
|
229
238
|
|
|
230
239
|
// 라우터 변경 구독
|
|
@@ -258,7 +267,17 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
258
267
|
context: this,
|
|
259
268
|
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
260
269
|
});
|
|
261
|
-
|
|
270
|
+
if (userConfig instanceof Promise) {
|
|
271
|
+
userConfig
|
|
272
|
+
.then(resolvedConfig => {
|
|
273
|
+
this.connect(resolvedConfig);
|
|
274
|
+
})
|
|
275
|
+
.catch(e => {
|
|
276
|
+
console.error('[SWC-MIXIN] Script execution failed:', e);
|
|
277
|
+
});
|
|
278
|
+
} else {
|
|
279
|
+
this.connect(userConfig);
|
|
280
|
+
}
|
|
262
281
|
} catch (e) {
|
|
263
282
|
console.error('[SWC-MIXIN] Script execution failed:', e);
|
|
264
283
|
}
|
|
@@ -273,7 +292,7 @@ export function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base
|
|
|
273
292
|
// 부모 클래스의 disconnectedCallback 호출
|
|
274
293
|
// @ts-ignore
|
|
275
294
|
super.disconnectedCallback?.();
|
|
276
|
-
|
|
295
|
+
|
|
277
296
|
this._routerSubscription?.unsubscribe();
|
|
278
297
|
this._routerSubscription = undefined;
|
|
279
298
|
this._lastRouterEvent = undefined;
|