@dooboostore/simple-web-component 1.0.43 → 1.0.45
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 +312 -63
- 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 +66 -43
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +110 -43
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +200 -112
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +49 -45
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +92 -37
- 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 +81 -31
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +80 -52
- 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 +133 -147
- package/dist/cjs/decorators/query.js.map +3 -3
- package/dist/cjs/decorators/queryAll.js +143 -132
- 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/cjs/types/window.d.js.map +1 -1
- 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 +66 -43
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +110 -43
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +200 -112
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +49 -45
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +92 -37
- 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 +79 -29
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +80 -52
- 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 +133 -147
- package/dist/esm/decorators/query.js.map +3 -3
- package/dist/esm/decorators/queryAll.js +143 -132
- 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 +1118 -633
- 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 +19 -15
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +45 -26
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +19 -38
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +175 -32
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +38 -25
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +10 -9
- 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 +6 -12
- 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 +16 -29
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +16 -23
- 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 +1118 -633
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +1 -1
- package/src/SwcAppEngine.ts +3 -1
- package/src/decorators/addEventListener.ts +31 -25
- package/src/decorators/applyAttribute.ts +164 -86
- package/src/decorators/applyClass.ts +161 -41
- package/src/decorators/applyNode.ts +408 -108
- package/src/decorators/applyProperty.ts +100 -89
- package/src/decorators/applyStyle.ts +131 -37
- package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
- package/src/decorators/elementDefine.ts +96 -30
- package/src/decorators/emitCustomEvent.ts +92 -60
- package/src/decorators/index.ts +1 -1
- package/src/decorators/publishSwcAppMessage.ts +1 -1
- package/src/decorators/query.ts +155 -162
- package/src/decorators/queryAll.ts +157 -139
- 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/src/types/window.d.ts +3 -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
|
@@ -1,183 +1,176 @@
|
|
|
1
1
|
import { ReflectUtils } from '@dooboostore/core';
|
|
2
2
|
import { getElementConfig, ensureInit } from './elementDefine';
|
|
3
3
|
import { SwcUtils } from '../utils/Utils';
|
|
4
|
-
import {
|
|
4
|
+
import { SwcQueryOptions, HelperHostSet } from '../types';
|
|
5
|
+
|
|
6
|
+
export interface QueryOptions extends SwcQueryOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Filter function to determine whether to include the element.
|
|
9
|
+
* If it returns false, the element is skipped.
|
|
10
|
+
*/
|
|
11
|
+
filter?: (target: HTMLElement, meta: { currentThis: any, helper: HelperHostSet }) => boolean;
|
|
12
|
+
}
|
|
5
13
|
|
|
6
14
|
export interface QueryMetadata {
|
|
7
15
|
propertyKey: string | symbol;
|
|
8
|
-
selector: string;
|
|
9
|
-
options:
|
|
16
|
+
selector: string | ((currentThis: any, helper: HelperHostSet) => Node | NodeList | Element | Element[] | null);
|
|
17
|
+
options: QueryOptions ;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
export const QUERY_METADATA_KEY = Symbol.for('simple-web-component:query');
|
|
13
21
|
|
|
14
|
-
export function query(target:
|
|
15
|
-
export function query(selector: string, options?:
|
|
22
|
+
export function query(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void;
|
|
23
|
+
export function query(selector: string | ((currentThis: any, helper: HelperHostSet) => Node | NodeList | Element | Element[] | null), options?: QueryOptions): PropertyDecorator;
|
|
24
|
+
export function query(options?: QueryOptions): PropertyDecorator;
|
|
16
25
|
/**
|
|
17
26
|
* @query decorator to inject a single element into a class property.
|
|
27
|
+
*
|
|
28
|
+
* Supports both string selectors and function-based selectors:
|
|
29
|
+
* - String selector: @query('#my-element')
|
|
30
|
+
* - Function selector: @query((currentThis, helper) => currentThis.shadowRoot?.querySelector('.item'))
|
|
31
|
+
*
|
|
32
|
+
* Supports filtering:
|
|
33
|
+
* - @query('#my-element', { filter: (target, meta) => target.hasAttribute('active') })
|
|
18
34
|
*/
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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) {
|
|
77
|
-
const selector = selectorOrTarget;
|
|
78
|
-
if (selector.startsWith('$') && selector !== '$this') return;
|
|
79
|
-
|
|
80
|
-
const r = options.root || 'auto';
|
|
81
|
-
const targets: Element[] = [];
|
|
82
|
-
|
|
83
|
-
if (r === 'shadow') {
|
|
84
|
-
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
85
|
-
} else if (r === 'light') {
|
|
86
|
-
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
87
|
-
} else if (r === 'all') {
|
|
88
|
-
if (this.shadowRoot?.querySelector(selector)) targets.push(this.shadowRoot.querySelector(selector)!);
|
|
89
|
-
if (this.querySelector(selector)) targets.push(this.querySelector(selector)!);
|
|
35
|
+
export function query(selectorOrTarget?: string | ((currentThis: any, helper: HelperHostSet) => Node | NodeList | Element | Element[] | null) | Object, optionsOrPropertyKey?: QueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {
|
|
36
|
+
// Bare decorator: @query
|
|
37
|
+
if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
|
|
38
|
+
throw new Error(`@query decorator cannot be used on methods. (Method: ${String(optionsOrPropertyKey)})`);
|
|
39
|
+
}
|
|
40
|
+
// With selector
|
|
41
|
+
if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {
|
|
42
|
+
return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {
|
|
43
|
+
if (descriptor !== undefined) {
|
|
44
|
+
throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const constructor = targetObj.constructor;
|
|
48
|
+
let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);
|
|
49
|
+
if (!queries) {
|
|
50
|
+
queries = [];
|
|
51
|
+
ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
|
|
52
|
+
}
|
|
53
|
+
queries.push({ propertyKey, selector: selectorOrTarget as any, options: optionsOrPropertyKey as QueryOptions || {} });
|
|
54
|
+
|
|
55
|
+
Object.defineProperty(targetObj, propertyKey, {
|
|
56
|
+
get(this: HTMLElement) {
|
|
57
|
+
ensureInit(this);
|
|
58
|
+
const config = getElementConfig(this);
|
|
59
|
+
const win = config?.window || window;
|
|
60
|
+
const hostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
61
|
+
|
|
62
|
+
// Resolve selector - can be string or function
|
|
63
|
+
let resolvedSelector: string;
|
|
64
|
+
let resolvedElement: HTMLElement | null = null;
|
|
65
|
+
|
|
66
|
+
if (typeof selectorOrTarget === 'function') {
|
|
67
|
+
const result = (selectorOrTarget as any)(this, hostSet);
|
|
68
|
+
// If function returns a Node/Element, return it directly
|
|
69
|
+
if (result instanceof win.Node || result instanceof win.Element) {
|
|
70
|
+
resolvedElement = result instanceof win.HTMLElement ? (result as HTMLElement) : null;
|
|
71
|
+
}
|
|
72
|
+
// If function returns NodeList or Element[], return first element
|
|
73
|
+
else if (result instanceof win.NodeList || Array.isArray(result)) {
|
|
74
|
+
resolvedElement = result.length > 0 && result[0] instanceof win.HTMLElement ? (result[0] as HTMLElement) : null;
|
|
75
|
+
}
|
|
90
76
|
} else {
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
resolvedSelector = selectorOrTarget;
|
|
78
|
+
|
|
79
|
+
const r = (optionsOrPropertyKey as QueryOptions)?.root || 'auto';
|
|
80
|
+
const applyRoot = (t: any) => {
|
|
81
|
+
if (!t || !(t instanceof HTMLElement)) return t;
|
|
82
|
+
if (r === 'auto') return t.shadowRoot || t;
|
|
83
|
+
if (r === 'shadow') return t.shadowRoot;
|
|
84
|
+
if (r === 'light') return t;
|
|
85
|
+
if (r === 'all') return t.shadowRoot || t;
|
|
86
|
+
return t;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// --- Special Selectors: HostSet ---
|
|
90
|
+
if (resolvedSelector === '$this') resolvedElement = applyRoot(this);
|
|
91
|
+
else if (resolvedSelector === '$host') resolvedElement = applyRoot(hostSet.$host);
|
|
92
|
+
else if (resolvedSelector === '$parentHost') resolvedElement = applyRoot(hostSet.$parentHost);
|
|
93
|
+
else if (resolvedSelector === '$appHost') resolvedElement = applyRoot(hostSet.$appHost);
|
|
94
|
+
else if (resolvedSelector === '$firstHost') resolvedElement = applyRoot(hostSet.$firstHost);
|
|
95
|
+
else if (resolvedSelector === '$lastHost') resolvedElement = applyRoot(hostSet.$lastHost);
|
|
96
|
+
else if (resolvedSelector === '$firstAppHost') resolvedElement = applyRoot(hostSet.$firstAppHost);
|
|
97
|
+
else if (resolvedSelector === '$lastAppHost') resolvedElement = applyRoot(hostSet.$lastAppHost);
|
|
98
|
+
// --- Special Selectors: Env ---
|
|
99
|
+
else if (resolvedSelector === '$window') return win;
|
|
100
|
+
else if (resolvedSelector === '$document') return win.document;
|
|
101
|
+
// --- Standard Selectors ---
|
|
102
|
+
else {
|
|
103
|
+
if (r === 'shadow') resolvedElement = this.shadowRoot ? (this.shadowRoot.querySelector(resolvedSelector) as HTMLElement | null) : null;
|
|
104
|
+
else if (r === 'light') resolvedElement = this.querySelector(resolvedSelector) as HTMLElement | null;
|
|
105
|
+
else if (r === 'all') {
|
|
106
|
+
const shadowMatch = this.shadowRoot ? (this.shadowRoot.querySelector(resolvedSelector) as HTMLElement | null) : null;
|
|
107
|
+
resolvedElement = shadowMatch || (this.querySelector(resolvedSelector) as HTMLElement | null);
|
|
108
|
+
}
|
|
109
|
+
else resolvedElement = ((this.shadowRoot || this).querySelector(resolvedSelector) as HTMLElement | null);
|
|
110
|
+
}
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @queryThis decorator - simplified version of @query for $this selector
|
|
106
|
-
*/
|
|
107
|
-
export function queryThis(target: Object, propertyKey: string | symbol): void;
|
|
108
|
-
export function queryThis(): PropertyDecorator;
|
|
109
|
-
export function queryThis(options: SwcQueryOptions): PropertyDecorator;
|
|
110
|
-
export function queryThis(targetOrOptions?: any, propertyKey?: string | symbol): any {
|
|
111
|
-
if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
|
|
112
|
-
return query('$this', {})(targetOrOptions, propertyKey);
|
|
113
|
-
}
|
|
114
|
-
if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
|
|
115
|
-
return query('$this', targetOrOptions as SwcQueryOptions);
|
|
116
|
-
} else {
|
|
117
|
-
return query('$this', {});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
export function queryWindow(target: Object, propertyKey: string | symbol): void;
|
|
123
|
-
export function queryWindow(): PropertyDecorator;
|
|
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
|
-
}
|
|
113
|
+
// Apply filter if provided
|
|
114
|
+
if (resolvedElement instanceof win.HTMLElement && (optionsOrPropertyKey as QueryOptions)?.filter) {
|
|
115
|
+
const shouldInclude = (optionsOrPropertyKey as QueryOptions).filter!(resolvedElement, { currentThis: this, helper: hostSet });
|
|
116
|
+
if (!shouldInclude) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
165
120
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
121
|
+
return resolvedElement;
|
|
122
|
+
},
|
|
123
|
+
set(this: HTMLElement, nv: any) {
|
|
124
|
+
ensureInit(this);
|
|
125
|
+
if (nv === null || nv === undefined) {
|
|
126
|
+
const config = getElementConfig(this);
|
|
127
|
+
const win = config?.window || window;
|
|
128
|
+
const hostSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
129
|
+
|
|
130
|
+
// Resolve selector - can be string or function
|
|
131
|
+
if (typeof selectorOrTarget === 'function') {
|
|
132
|
+
// Get the element from function and remove it
|
|
133
|
+
const result = (selectorOrTarget as any)(this, hostSet);
|
|
134
|
+
if (result instanceof win.Element) {
|
|
135
|
+
(result as Element).remove();
|
|
136
|
+
} else if (result instanceof win.NodeList || Array.isArray(result)) {
|
|
137
|
+
const el = result.length > 0 ? result[0] : null;
|
|
138
|
+
if (el instanceof win.Element) {
|
|
139
|
+
(el as Element).remove();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const resolvedSelector = selectorOrTarget;
|
|
146
|
+
|
|
147
|
+
if (resolvedSelector.startsWith('$') && resolvedSelector !== '$this') return;
|
|
148
|
+
|
|
149
|
+
const r = (optionsOrPropertyKey as QueryOptions)?.root || 'auto';
|
|
150
|
+
const targets: Element[] = [];
|
|
151
|
+
|
|
152
|
+
if (r === 'shadow') {
|
|
153
|
+
if (this.shadowRoot?.querySelector(resolvedSelector)) targets.push(this.shadowRoot.querySelector(resolvedSelector)!);
|
|
154
|
+
} else if (r === 'light') {
|
|
155
|
+
if (this.querySelector(resolvedSelector)) targets.push(this.querySelector(resolvedSelector)!);
|
|
156
|
+
} else if (r === 'all') {
|
|
157
|
+
if (this.shadowRoot?.querySelector(resolvedSelector)) targets.push(this.shadowRoot.querySelector(resolvedSelector)!);
|
|
158
|
+
if (this.querySelector(resolvedSelector)) targets.push(this.querySelector(resolvedSelector)!);
|
|
159
|
+
} else {
|
|
160
|
+
const el = (this.shadowRoot || this).querySelector(resolvedSelector);
|
|
161
|
+
if (el) targets.push(el);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
targets.forEach(t => t.remove());
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true
|
|
169
|
+
});
|
|
170
|
+
};
|
|
180
171
|
}
|
|
172
|
+
// Without selector (defaults to $this)
|
|
173
|
+
return query('$this', selectorOrTarget as SwcQueryOptions);
|
|
181
174
|
}
|
|
182
175
|
|
|
183
176
|
export const getQueryMetadata = (target: any): QueryMetadata[] => {
|