@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.
Files changed (146) hide show
  1. package/README.md +312 -63
  2. package/dist/cjs/SwcAppEngine.js +3 -1
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  5. package/dist/cjs/decorators/applyAttribute.js +66 -43
  6. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  7. package/dist/cjs/decorators/applyClass.js +110 -43
  8. package/dist/cjs/decorators/applyClass.js.map +3 -3
  9. package/dist/cjs/decorators/applyNode.js +200 -112
  10. package/dist/cjs/decorators/applyNode.js.map +2 -2
  11. package/dist/cjs/decorators/applyProperty.js +49 -45
  12. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  13. package/dist/cjs/decorators/applyStyle.js +92 -37
  14. package/dist/cjs/decorators/applyStyle.js.map +3 -3
  15. package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
  16. package/dist/cjs/decorators/changedAttribute.js.map +7 -0
  17. package/dist/cjs/decorators/elementDefine.js +81 -31
  18. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  19. package/dist/cjs/decorators/emitCustomEvent.js +80 -52
  20. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  21. package/dist/cjs/decorators/index.js +1 -1
  22. package/dist/cjs/decorators/index.js.map +2 -2
  23. package/dist/cjs/decorators/publishSwcAppMessage.js +5 -5
  24. package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
  25. package/dist/cjs/decorators/query.js +133 -147
  26. package/dist/cjs/decorators/query.js.map +3 -3
  27. package/dist/cjs/decorators/queryAll.js +143 -132
  28. package/dist/cjs/decorators/queryAll.js.map +3 -3
  29. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  30. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  31. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  32. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  33. package/dist/cjs/elements/SwcAppMixin.js +17 -2
  34. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  35. package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
  36. package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
  37. package/dist/cjs/index.js +1 -0
  38. package/dist/cjs/index.js.map +2 -2
  39. package/dist/cjs/router/ElementRouter.js +4 -0
  40. package/dist/cjs/router/ElementRouter.js.map +2 -2
  41. package/dist/cjs/types/window.d.js.map +1 -1
  42. package/dist/esm/SwcAppEngine.js +3 -1
  43. package/dist/esm/SwcAppEngine.js.map +2 -2
  44. package/dist/esm/decorators/addEventListener.js.map +2 -2
  45. package/dist/esm/decorators/applyAttribute.js +66 -43
  46. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  47. package/dist/esm/decorators/applyClass.js +110 -43
  48. package/dist/esm/decorators/applyClass.js.map +3 -3
  49. package/dist/esm/decorators/applyNode.js +200 -112
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applyProperty.js +49 -45
  52. package/dist/esm/decorators/applyProperty.js.map +2 -2
  53. package/dist/esm/decorators/applyStyle.js +92 -37
  54. package/dist/esm/decorators/applyStyle.js.map +3 -3
  55. package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
  56. package/dist/esm/decorators/changedAttribute.js.map +7 -0
  57. package/dist/esm/decorators/elementDefine.js +79 -29
  58. package/dist/esm/decorators/elementDefine.js.map +2 -2
  59. package/dist/esm/decorators/emitCustomEvent.js +80 -52
  60. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  61. package/dist/esm/decorators/index.js +1 -1
  62. package/dist/esm/decorators/index.js.map +1 -1
  63. package/dist/esm/decorators/publishSwcAppMessage.js +5 -5
  64. package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
  65. package/dist/esm/decorators/query.js +133 -147
  66. package/dist/esm/decorators/query.js.map +3 -3
  67. package/dist/esm/decorators/queryAll.js +143 -132
  68. package/dist/esm/decorators/queryAll.js.map +3 -3
  69. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  70. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  71. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  72. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  73. package/dist/esm/elements/SwcAppMixin.js +18 -3
  74. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  75. package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
  76. package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
  77. package/dist/esm/index.js +1 -0
  78. package/dist/esm/index.js.map +2 -2
  79. package/dist/esm/router/ElementRouter.js +4 -0
  80. package/dist/esm/router/ElementRouter.js.map +2 -2
  81. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1118 -633
  82. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  83. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  84. package/dist/types/decorators/addEventListener.d.ts +19 -15
  85. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  86. package/dist/types/decorators/applyAttribute.d.ts +45 -26
  87. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  88. package/dist/types/decorators/applyClass.d.ts +19 -38
  89. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  90. package/dist/types/decorators/applyNode.d.ts +175 -32
  91. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  92. package/dist/types/decorators/applyProperty.d.ts +38 -25
  93. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  94. package/dist/types/decorators/applyStyle.d.ts +10 -9
  95. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  96. package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
  97. package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
  98. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  99. package/dist/types/decorators/emitCustomEvent.d.ts +6 -12
  100. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  101. package/dist/types/decorators/index.d.ts +1 -1
  102. package/dist/types/decorators/index.d.ts.map +1 -1
  103. package/dist/types/decorators/publishSwcAppMessage.d.ts +1 -1
  104. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  105. package/dist/types/decorators/query.d.ts +16 -29
  106. package/dist/types/decorators/query.d.ts.map +1 -1
  107. package/dist/types/decorators/queryAll.d.ts +16 -23
  108. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  109. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
  110. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  111. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
  112. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  113. package/dist/types/elements/SwcAppMixin.d.ts +4 -4
  114. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  115. package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
  116. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
  117. package/dist/types/index.d.ts +1 -0
  118. package/dist/types/index.d.ts.map +1 -1
  119. package/dist/types/router/ElementRouter.d.ts.map +1 -1
  120. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1118 -633
  121. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  122. package/package.json +1 -1
  123. package/src/SwcAppEngine.ts +3 -1
  124. package/src/decorators/addEventListener.ts +31 -25
  125. package/src/decorators/applyAttribute.ts +164 -86
  126. package/src/decorators/applyClass.ts +161 -41
  127. package/src/decorators/applyNode.ts +408 -108
  128. package/src/decorators/applyProperty.ts +100 -89
  129. package/src/decorators/applyStyle.ts +131 -37
  130. package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
  131. package/src/decorators/elementDefine.ts +96 -30
  132. package/src/decorators/emitCustomEvent.ts +92 -60
  133. package/src/decorators/index.ts +1 -1
  134. package/src/decorators/publishSwcAppMessage.ts +1 -1
  135. package/src/decorators/query.ts +155 -162
  136. package/src/decorators/queryAll.ts +157 -139
  137. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
  138. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
  139. package/src/elements/SwcAppMixin.ts +43 -24
  140. package/src/examples/RxJSOperatorsExample.ts +279 -0
  141. package/src/index.ts +2 -0
  142. package/src/router/ElementRouter.ts +4 -0
  143. package/src/types/window.d.ts +3 -0
  144. package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
  145. package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
  146. package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
@@ -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 { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
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: SwcQueryOptions ;
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: SpecialSelector): PropertyDecorator;
15
- export function query(selector: string, options?: SwcQueryOptions): PropertyDecorator;
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: string, options: any = {}): PropertyDecorator {
20
- return (targetObj: Object, propertyKey: string | symbol, descriptor?: never): void => {
21
- if (descriptor !== undefined) {
22
- throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
23
- }
24
-
25
- const constructor = targetObj.constructor;
26
- let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);
27
- if (!queries) {
28
- queries = [];
29
- ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
30
- }
31
- queries.push({ propertyKey, selector: selectorOrTarget, options });
32
-
33
- Object.defineProperty(targetObj, propertyKey, {
34
- get(this: HTMLElement) {
35
- ensureInit(this);
36
- const selector = selectorOrTarget;
37
-
38
- const r = options.root || 'auto';
39
- const applyRoot = (t: any) => {
40
- if (!t || !(t instanceof HTMLElement)) return t;
41
- if (r === 'auto') return t.shadowRoot || t;
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) {
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
- const el = (this.shadowRoot || this).querySelector(selector);
92
- if (el) targets.push(el);
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
- targets.forEach(t => t.remove());
96
- }
97
- },
98
- enumerable: true,
99
- configurable: true
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
- * @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', {});
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[] => {