@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.
Files changed (153) hide show
  1. package/README.md +689 -85
  2. package/dist/cjs/SwcAppEngine.js +3 -1
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js +10 -0
  5. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  6. package/dist/cjs/decorators/applyAttribute.js +41 -30
  7. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  8. package/dist/cjs/decorators/applyClass.js +66 -23
  9. package/dist/cjs/decorators/applyClass.js.map +3 -3
  10. package/dist/cjs/decorators/applyNode.js +176 -107
  11. package/dist/cjs/decorators/applyNode.js.map +2 -2
  12. package/dist/cjs/decorators/applyProperty.js +21 -30
  13. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  14. package/dist/cjs/decorators/applySlot.js +11 -2
  15. package/dist/cjs/decorators/applySlot.js.map +2 -2
  16. package/dist/cjs/decorators/applyStyle.js +48 -17
  17. package/dist/cjs/decorators/applyStyle.js.map +3 -3
  18. package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
  19. package/dist/cjs/decorators/changedAttribute.js.map +7 -0
  20. package/dist/cjs/decorators/elementDefine.js +37 -6
  21. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  22. package/dist/cjs/decorators/emitCustomEvent.js +58 -42
  23. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  24. package/dist/cjs/decorators/index.js +1 -1
  25. package/dist/cjs/decorators/index.js.map +2 -2
  26. package/dist/cjs/decorators/publishSwcAppMessage.js +37 -23
  27. package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
  28. package/dist/cjs/decorators/query.js +96 -145
  29. package/dist/cjs/decorators/query.js.map +3 -3
  30. package/dist/cjs/decorators/queryAll.js +104 -131
  31. package/dist/cjs/decorators/queryAll.js.map +3 -3
  32. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  33. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  34. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  35. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  36. package/dist/cjs/elements/SwcAppMixin.js +17 -2
  37. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  38. package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
  39. package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
  40. package/dist/cjs/index.js +1 -0
  41. package/dist/cjs/index.js.map +2 -2
  42. package/dist/cjs/router/ElementRouter.js +4 -0
  43. package/dist/cjs/router/ElementRouter.js.map +2 -2
  44. package/dist/esm/SwcAppEngine.js +3 -1
  45. package/dist/esm/SwcAppEngine.js.map +2 -2
  46. package/dist/esm/decorators/addEventListener.js +10 -0
  47. package/dist/esm/decorators/addEventListener.js.map +2 -2
  48. package/dist/esm/decorators/applyAttribute.js +41 -30
  49. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  50. package/dist/esm/decorators/applyClass.js +66 -23
  51. package/dist/esm/decorators/applyClass.js.map +3 -3
  52. package/dist/esm/decorators/applyNode.js +176 -107
  53. package/dist/esm/decorators/applyNode.js.map +2 -2
  54. package/dist/esm/decorators/applyProperty.js +21 -30
  55. package/dist/esm/decorators/applyProperty.js.map +2 -2
  56. package/dist/esm/decorators/applySlot.js +11 -2
  57. package/dist/esm/decorators/applySlot.js.map +2 -2
  58. package/dist/esm/decorators/applyStyle.js +48 -17
  59. package/dist/esm/decorators/applyStyle.js.map +3 -3
  60. package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
  61. package/dist/esm/decorators/changedAttribute.js.map +7 -0
  62. package/dist/esm/decorators/elementDefine.js +35 -4
  63. package/dist/esm/decorators/elementDefine.js.map +2 -2
  64. package/dist/esm/decorators/emitCustomEvent.js +58 -42
  65. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  66. package/dist/esm/decorators/index.js +1 -1
  67. package/dist/esm/decorators/index.js.map +1 -1
  68. package/dist/esm/decorators/publishSwcAppMessage.js +37 -23
  69. package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
  70. package/dist/esm/decorators/query.js +96 -145
  71. package/dist/esm/decorators/query.js.map +3 -3
  72. package/dist/esm/decorators/queryAll.js +104 -131
  73. package/dist/esm/decorators/queryAll.js.map +3 -3
  74. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  75. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  76. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  77. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  78. package/dist/esm/elements/SwcAppMixin.js +18 -3
  79. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  80. package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
  81. package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
  82. package/dist/esm/index.js +1 -0
  83. package/dist/esm/index.js.map +2 -2
  84. package/dist/esm/router/ElementRouter.js +4 -0
  85. package/dist/esm/router/ElementRouter.js.map +2 -2
  86. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +900 -578
  87. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  88. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  89. package/dist/types/decorators/addEventListener.d.ts +22 -14
  90. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  91. package/dist/types/decorators/applyAttribute.d.ts +61 -20
  92. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  93. package/dist/types/decorators/applyClass.d.ts +22 -36
  94. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  95. package/dist/types/decorators/applyNode.d.ts +178 -30
  96. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  97. package/dist/types/decorators/applyProperty.d.ts +53 -18
  98. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  99. package/dist/types/decorators/applySlot.d.ts +6 -0
  100. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  101. package/dist/types/decorators/applyStyle.d.ts +13 -7
  102. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  103. package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
  104. package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
  105. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  106. package/dist/types/decorators/emitCustomEvent.d.ts +20 -10
  107. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  108. package/dist/types/decorators/index.d.ts +1 -1
  109. package/dist/types/decorators/index.d.ts.map +1 -1
  110. package/dist/types/decorators/publishSwcAppMessage.d.ts +19 -0
  111. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  112. package/dist/types/decorators/query.d.ts +3 -26
  113. package/dist/types/decorators/query.d.ts.map +1 -1
  114. package/dist/types/decorators/queryAll.d.ts +3 -20
  115. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  116. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
  117. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  118. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
  119. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  120. package/dist/types/elements/SwcAppMixin.d.ts +4 -4
  121. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  122. package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
  123. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
  124. package/dist/types/index.d.ts +1 -0
  125. package/dist/types/index.d.ts.map +1 -1
  126. package/dist/types/router/ElementRouter.d.ts.map +1 -1
  127. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +900 -578
  128. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  129. package/package.json +7 -9
  130. package/src/SwcAppEngine.ts +3 -1
  131. package/src/decorators/addEventListener.ts +35 -24
  132. package/src/decorators/applyAttribute.ts +167 -65
  133. package/src/decorators/applyClass.ts +113 -17
  134. package/src/decorators/applyNode.ts +383 -102
  135. package/src/decorators/applyProperty.ts +99 -65
  136. package/src/decorators/applySlot.ts +24 -10
  137. package/src/decorators/applyStyle.ts +83 -13
  138. package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
  139. package/src/decorators/elementDefine.ts +47 -4
  140. package/src/decorators/emitCustomEvent.ts +62 -35
  141. package/src/decorators/index.ts +1 -1
  142. package/src/decorators/publishSwcAppMessage.ts +71 -27
  143. package/src/decorators/query.ts +90 -159
  144. package/src/decorators/queryAll.ts +92 -134
  145. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
  146. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
  147. package/src/elements/SwcAppMixin.ts +43 -24
  148. package/src/examples/RxJSOperatorsExample.ts +279 -0
  149. package/src/index.ts +2 -0
  150. package/src/router/ElementRouter.ts +4 -0
  151. package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
  152. package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
  153. package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
@@ -10,9 +10,25 @@ export interface PublishSwcAppMessageMetadata {
10
10
 
11
11
  export interface PublishSwcAppMessageOptions {
12
12
  messageType?: string;
13
+ /**
14
+ * Custom key to extract value from return object.
15
+ * If not provided, uses PUBLISH_SWC_APP_MESSAGE_METADATA_KEY by default.
16
+ * Useful when multiple @publishSwcAppMessage decorators are on the same method.
17
+ *
18
+ * Example:
19
+ * @publishSwcAppMessage('event1', { valueKey: 'detail1' })
20
+ * @publishSwcAppMessage('event2', { valueKey: 'detail2' })
21
+ * myMethod() {
22
+ * return {
23
+ * detail1: { type: 'event1', data: 'value1' },
24
+ * detail2: { type: 'event2', data: 'value2' }
25
+ * };
26
+ * }
27
+ */
28
+ valueKey?: symbol | string;
13
29
  }
14
30
 
15
- function createPublishSwcAppMessage(messageType?: string): MethodDecorator {
31
+ function createPublishSwcAppMessage(messageType?: string, options?: PublishSwcAppMessageOptions): MethodDecorator {
16
32
  return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
17
33
  const constructor = target.constructor;
18
34
  let list = ReflectUtils.getOwnMetadata(PUBLISH_SWC_APP_MESSAGE_METADATA_KEY, constructor) as PublishSwcAppMessageMetadata[];
@@ -31,32 +47,47 @@ function createPublishSwcAppMessage(messageType?: string): MethodDecorator {
31
47
  descriptor.value = function (...args: any[]) {
32
48
  // 원본 메서드 실행
33
49
  const result = originalMethod.apply(this, args);
50
+
51
+ /**
52
+ * Extract value for this decorator from method return value
53
+ *
54
+ * If return value is an object with this decorator's key,
55
+ * use that value. Otherwise use the entire return value.
56
+ *
57
+ * Uses valueKey from options if provided, otherwise uses PUBLISH_SWC_APP_MESSAGE_METADATA_KEY.
58
+ */
59
+ const extractValue = (v: any) => {
60
+ const keyToUse = options?.valueKey ?? PUBLISH_SWC_APP_MESSAGE_METADATA_KEY;
61
+ if (v && typeof v === 'object' && keyToUse in v) {
62
+ return v[keyToUse];
63
+ }
64
+ return v;
65
+ };
66
+
67
+ const publishMessage = (data: any) => {
68
+ // appHost 찾아서 메시지 발행
69
+ const appHost = SwcUtils.getAppHost(this as HTMLElement);
70
+ if (appHost) {
71
+ appHost.publishMessage({
72
+ publisher: this,
73
+ data,
74
+ type: messageType
75
+ });
76
+ }
77
+ };
34
78
 
35
79
  // Promise 체크
36
80
  if (result instanceof Promise) {
37
81
  result.then((data) => {
38
- // appHost 찾아서 메시지 발행
39
- const appHost = SwcUtils.getAppHost(this as HTMLElement);
40
- if (appHost) {
41
- appHost.publishMessage({
42
- publisher: this,
43
- data,
44
- type: messageType
45
- });
46
- }
82
+ const extracted = extractValue(data);
83
+ publishMessage(extracted);
47
84
  }).catch((err) => {
48
85
  console.warn('publishSwcAppMessage async error:', err);
49
86
  });
50
87
  } else {
51
88
  // 동기 호출 - 바로 메시지 발행
52
- const appHost = SwcUtils.getAppHost(this as HTMLElement);
53
- if (appHost) {
54
- appHost.publishMessage({
55
- publisher: this,
56
- data: result,
57
- type: messageType
58
- });
59
- }
89
+ const extracted = extractValue(result);
90
+ publishMessage(extracted);
60
91
  }
61
92
 
62
93
  return result;
@@ -71,27 +102,40 @@ export function publishSwcAppMessage(target: Object, propertyKey: string | symbo
71
102
  // 오버로드 시그니처 - 함수 호출 (괄호 있음)
72
103
  export function publishSwcAppMessage(): MethodDecorator;
73
104
  export function publishSwcAppMessage(messageType: string): MethodDecorator;
105
+ export function publishSwcAppMessage(messageType: string, options: PublishSwcAppMessageOptions): MethodDecorator;
106
+ export function publishSwcAppMessage(options: PublishSwcAppMessageOptions): MethodDecorator;
74
107
 
75
- export function publishSwcAppMessage(targetOrMessageType?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
108
+ export function publishSwcAppMessage(targetOrMessageTypeOrOptions?: any, propertyKeyOrOptions?: string | symbol | PublishSwcAppMessageOptions, descriptor?: PropertyDescriptor): any {
76
109
  // 직접 데코레이터로 사용된 경우 (괄호 없음): @publishSwcAppMessage
77
- if (targetOrMessageType && typeof targetOrMessageType === 'object' &&
78
- propertyKey && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol') &&
110
+ if (targetOrMessageTypeOrOptions && typeof targetOrMessageTypeOrOptions === 'object' &&
111
+ propertyKeyOrOptions && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol') &&
79
112
  descriptor) {
80
- const target = targetOrMessageType;
81
- return createPublishSwcAppMessage()(target, propertyKey, descriptor);
113
+ const target = targetOrMessageTypeOrOptions;
114
+ return createPublishSwcAppMessage()(target, propertyKeyOrOptions, descriptor);
82
115
  }
83
116
 
84
- // 함수로 호출된 경우 (괄호 있음): @publishSwcAppMessage() / @publishSwcAppMessage('messageType')
117
+ // 함수로 호출된 경우 (괄호 있음): @publishSwcAppMessage() / @publishSwcAppMessage('messageType') / @publishSwcAppMessage({...})
85
118
  let messageType: string | undefined;
119
+ let options: PublishSwcAppMessageOptions | undefined;
86
120
 
87
- if (typeof targetOrMessageType === 'string') {
121
+ if (typeof targetOrMessageTypeOrOptions === 'string') {
88
122
  // 메시지 타입 전달: @publishSwcAppMessage('messageType')
89
- messageType = targetOrMessageType;
123
+ messageType = targetOrMessageTypeOrOptions;
124
+ if (typeof propertyKeyOrOptions === 'object' && propertyKeyOrOptions !== null) {
125
+ options = propertyKeyOrOptions as PublishSwcAppMessageOptions;
126
+ }
127
+ } else if (typeof targetOrMessageTypeOrOptions === 'object' && targetOrMessageTypeOrOptions !== null) {
128
+ // 옵션 객체 전달: @publishSwcAppMessage({...})
129
+ options = targetOrMessageTypeOrOptions as PublishSwcAppMessageOptions;
130
+ messageType = options.messageType;
90
131
  }
91
132
 
92
- return createPublishSwcAppMessage(messageType);
133
+ return createPublishSwcAppMessage(messageType, options);
93
134
  }
94
135
 
136
+ // --- Aliases: publish... ---
137
+ export const publishMessage = publishSwcAppMessage;
138
+
95
139
  // Helper function to retrieve publish message metadata
96
140
  export const getPublishSwcAppMessageMetadata = (target: any): PublishSwcAppMessageMetadata[] | undefined => {
97
141
  const constructor = target instanceof Function ? target : target.constructor;
@@ -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: SpecialSelector): PropertyDecorator;
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: 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) {
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 = 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)!);
90
- } else {
91
- const el = (this.shadowRoot || this).querySelector(selector);
92
- if (el) targets.push(el);
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
- 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
- }
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[] => {