@dooboostore/simple-web-component 1.0.43 → 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 +298 -49
- package/dist/cjs/SwcAppEngine.js +3 -1
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +30 -28
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +57 -21
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +165 -105
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +11 -28
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +39 -15
- 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 +56 -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 +5 -5
- 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.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +30 -28
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +57 -21
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +165 -105
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +11 -28
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +39 -15
- 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 +56 -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 +5 -5
- 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 +759 -512
- 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 +17 -14
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +35 -20
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +16 -36
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +172 -30
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +27 -18
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +7 -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 +3 -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 +1 -1
- 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 +759 -512
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +28 -24
- package/src/decorators/applyAttribute.ts +109 -63
- package/src/decorators/applyClass.ts +89 -15
- package/src/decorators/applyNode.ts +357 -100
- package/src/decorators/applyProperty.ts +42 -63
- package/src/decorators/applyStyle.ts +59 -11
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +47 -4
- package/src/decorators/emitCustomEvent.ts +44 -36
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +1 -1
- 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
package/src/decorators/query.ts
CHANGED
|
@@ -11,173 +11,104 @@ export interface QueryMetadata {
|
|
|
11
11
|
|
|
12
12
|
export const QUERY_METADATA_KEY = Symbol.for('simple-web-component:query');
|
|
13
13
|
|
|
14
|
-
export function query(target:
|
|
14
|
+
export function query(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void;
|
|
15
15
|
export function query(selector: string, options?: SwcQueryOptions): PropertyDecorator;
|
|
16
|
+
export function query(options?: SwcQueryOptions): PropertyDecorator;
|
|
16
17
|
/**
|
|
17
18
|
* @query decorator to inject a single element into a class property.
|
|
18
19
|
*/
|
|
19
|
-
export function query(selectorOrTarget
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (r === 'shadow') return t.shadowRoot;
|
|
43
|
-
if (r === 'light') return t;
|
|
44
|
-
if (r === 'all') return t.shadowRoot || t;
|
|
45
|
-
return t;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// --- Special Selectors: HostSet ---
|
|
49
|
-
const hostSet = SwcUtils.getHostSet(this);
|
|
50
|
-
if (selector === '$this') return applyRoot(this);
|
|
51
|
-
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
52
|
-
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
53
|
-
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
54
|
-
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
55
|
-
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
56
|
-
if (selector === '$firstAppHost') return applyRoot(hostSet.$firstAppHost);
|
|
57
|
-
if (selector === '$lastAppHost') return applyRoot(hostSet.$lastAppHost);
|
|
58
|
-
|
|
59
|
-
// --- Special Selectors: Env ---
|
|
60
|
-
const config = getElementConfig(this);
|
|
61
|
-
const win = config?.window || window;
|
|
62
|
-
if (selector === '$window') return win;
|
|
63
|
-
if (selector === '$document') return win.document;
|
|
64
|
-
|
|
65
|
-
// --- Standard Selectors ---
|
|
66
|
-
if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
67
|
-
if (r === 'light') return this.querySelector(selector);
|
|
68
|
-
if (r === 'all') {
|
|
69
|
-
const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
70
|
-
return shadowMatch || this.querySelector(selector);
|
|
71
|
-
}
|
|
72
|
-
return (this.shadowRoot || this).querySelector(selector);
|
|
73
|
-
},
|
|
74
|
-
set(this: HTMLElement, nv: any) {
|
|
75
|
-
ensureInit(this);
|
|
76
|
-
if (nv === null || nv === undefined) {
|
|
20
|
+
export function query(selectorOrTarget?: string | Object, optionsOrPropertyKey?: SwcQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
21
|
+
// Bare decorator: @query
|
|
22
|
+
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
23
|
+
throw new Error(`@query 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(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const constructor = targetObj.constructor;
|
|
33
|
+
let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);
|
|
34
|
+
if (!queries) {
|
|
35
|
+
queries = [];
|
|
36
|
+
ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
|
|
37
|
+
}
|
|
38
|
+
queries.push({ propertyKey, selector: selectorOrTarget, options: optionsOrPropertyKey as SwcQueryOptions || {} });
|
|
39
|
+
|
|
40
|
+
Object.defineProperty(targetObj, propertyKey, {
|
|
41
|
+
get(this: HTMLElement) {
|
|
42
|
+
ensureInit(this);
|
|
77
43
|
const selector = selectorOrTarget;
|
|
78
|
-
if (selector.startsWith('$') && selector !== '$this') return;
|
|
79
44
|
|
|
80
|
-
const r =
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
45
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
46
|
+
const applyRoot = (t: any) => {
|
|
47
|
+
if (!t || !(t instanceof HTMLElement)) return t;
|
|
48
|
+
if (r === 'auto') return t.shadowRoot || t;
|
|
49
|
+
if (r === 'shadow') return t.shadowRoot;
|
|
50
|
+
if (r === 'light') return t;
|
|
51
|
+
if (r === 'all') return t.shadowRoot || t;
|
|
52
|
+
return t;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// --- Special Selectors: HostSet ---
|
|
56
|
+
const hostSet = SwcUtils.getHostSet(this);
|
|
57
|
+
if (selector === '$this') return applyRoot(this);
|
|
58
|
+
if (selector === '$host') return applyRoot(hostSet.$host);
|
|
59
|
+
if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
|
|
60
|
+
if (selector === '$appHost') return applyRoot(hostSet.$appHost);
|
|
61
|
+
if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
|
|
62
|
+
if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
|
|
63
|
+
if (selector === '$firstAppHost') return applyRoot(hostSet.$firstAppHost);
|
|
64
|
+
if (selector === '$lastAppHost') return applyRoot(hostSet.$lastAppHost);
|
|
65
|
+
|
|
66
|
+
// --- Special Selectors: Env ---
|
|
67
|
+
const config = getElementConfig(this);
|
|
68
|
+
const win = config?.window || window;
|
|
69
|
+
if (selector === '$window') return win;
|
|
70
|
+
if (selector === '$document') return win.document;
|
|
71
|
+
|
|
72
|
+
// --- Standard Selectors ---
|
|
73
|
+
if (r === 'shadow') return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
74
|
+
if (r === 'light') return this.querySelector(selector);
|
|
75
|
+
if (r === 'all') {
|
|
76
|
+
const shadowMatch = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
|
|
77
|
+
return shadowMatch || this.querySelector(selector);
|
|
93
78
|
}
|
|
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
|
-
export function queryWindow(options: SwcQueryOptions): PropertyDecorator;
|
|
125
|
-
export function queryWindow(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
126
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
127
|
-
return query('$window', {})(targetOrOptions, propertyKey);
|
|
128
|
-
}
|
|
129
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
130
|
-
return query('$window', targetOrOptions as SwcQueryOptions);
|
|
131
|
-
} else {
|
|
132
|
-
return query('$window', {});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function queryDocument(target: Object, propertyKey: string | symbol): void;
|
|
137
|
-
export function queryDocument(): PropertyDecorator;
|
|
138
|
-
export function queryDocument(options: SwcQueryOptions): PropertyDecorator;
|
|
139
|
-
export function queryDocument(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
140
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
141
|
-
return query('$document', {})(targetOrOptions, propertyKey);
|
|
142
|
-
}
|
|
143
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
144
|
-
return query('$document', targetOrOptions as SwcQueryOptions);
|
|
145
|
-
} else {
|
|
146
|
-
return query('$document', {});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @host - Query $host (Direct parent SWC component)
|
|
151
|
-
*/
|
|
152
|
-
export function queryHost(target: Object, propertyKey: string | symbol): void;
|
|
153
|
-
export function queryHost(): PropertyDecorator;
|
|
154
|
-
export function queryHost(options: SwcQueryOptions): PropertyDecorator;
|
|
155
|
-
export function queryHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
156
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
157
|
-
return query('$host', {})(targetOrOptions, propertyKey);
|
|
158
|
-
}
|
|
159
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
160
|
-
return query('$host', targetOrOptions as SwcQueryOptions);
|
|
161
|
-
} else {
|
|
162
|
-
return query('$host', {});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @appHost - Query $appHost (Nearest <swc-app>)
|
|
168
|
-
*/
|
|
169
|
-
export function queryAppHost(target: Object, propertyKey: string | symbol): void;
|
|
170
|
-
export function queryAppHost(): PropertyDecorator;
|
|
171
|
-
export function queryAppHost(options: SwcQueryOptions): PropertyDecorator;
|
|
172
|
-
export function queryAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
173
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
174
|
-
return query('$appHost', {})(targetOrOptions, propertyKey);
|
|
175
|
-
}
|
|
176
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
177
|
-
return query('$appHost', targetOrOptions as SwcQueryOptions);
|
|
178
|
-
} else {
|
|
179
|
-
return query('$appHost', {});
|
|
79
|
+
return (this.shadowRoot || this).querySelector(selector);
|
|
80
|
+
},
|
|
81
|
+
set(this: HTMLElement, nv: any) {
|
|
82
|
+
ensureInit(this);
|
|
83
|
+
if (nv === null || nv === undefined) {
|
|
84
|
+
const selector = selectorOrTarget;
|
|
85
|
+
if (selector.startsWith('$') && selector !== '$this') return;
|
|
86
|
+
|
|
87
|
+
const r = (optionsOrPropertyKey as SwcQueryOptions)?.root || 'auto';
|
|
88
|
+
const targets: Element[] = [];
|
|
89
|
+
|
|
90
|
+
if (r === 'shadow') {
|
|
91
|
+
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
92
|
+
} else if (r === 'light') {
|
|
93
|
+
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
94
|
+
} else if (r === 'all') {
|
|
95
|
+
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
96
|
+
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
97
|
+
} else {
|
|
98
|
+
const el = (this.shadowRoot || this).querySelector(selector);
|
|
99
|
+
if (el) targets.push(el);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
targets.forEach(t => t.remove());
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true
|
|
107
|
+
});
|
|
108
|
+
};
|
|
180
109
|
}
|
|
110
|
+
// Without selector (defaults to $this)
|
|
111
|
+
return query('$this', selectorOrTarget as SwcQueryOptions);
|
|
181
112
|
}
|
|
182
113
|
|
|
183
114
|
export const getQueryMetadata = (target: any): QueryMetadata[] => {
|
|
@@ -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[] => {
|