@dooboostore/simple-web-component 1.0.22 → 1.0.24

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 (105) hide show
  1. package/README.md +568 -32
  2. package/dist/cjs/decorators/applyNode.js +195 -26
  3. package/dist/cjs/decorators/applyNode.js.map +2 -2
  4. package/dist/cjs/decorators/attribute.js +21 -3
  5. package/dist/cjs/decorators/attribute.js.map +2 -2
  6. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  7. package/dist/cjs/decorators/classList.js +82 -19
  8. package/dist/cjs/decorators/classList.js.map +2 -2
  9. package/dist/cjs/decorators/elementDefine.js +1 -2
  10. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  11. package/dist/cjs/decorators/index.js +0 -1
  12. package/dist/cjs/decorators/index.js.map +2 -2
  13. package/dist/cjs/decorators/lifecycles.js +25 -0
  14. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  15. package/dist/cjs/decorators/query.js +77 -2
  16. package/dist/cjs/decorators/query.js.map +2 -2
  17. package/dist/cjs/decorators/queryAll.js +77 -2
  18. package/dist/cjs/decorators/queryAll.js.map +2 -2
  19. package/dist/cjs/decorators/setAttribute.js +4 -4
  20. package/dist/cjs/decorators/setAttribute.js.map +2 -2
  21. package/dist/cjs/decorators/style.js +70 -13
  22. package/dist/cjs/decorators/style.js.map +2 -2
  23. package/dist/cjs/index.js +4 -4
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/utils/Utils.js +140 -1
  26. package/dist/cjs/utils/Utils.js.map +2 -2
  27. package/dist/esm/decorators/applyNode.js +195 -26
  28. package/dist/esm/decorators/applyNode.js.map +2 -2
  29. package/dist/esm/decorators/attribute.js +21 -3
  30. package/dist/esm/decorators/attribute.js.map +2 -2
  31. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  32. package/dist/esm/decorators/classList.js +82 -19
  33. package/dist/esm/decorators/classList.js.map +2 -2
  34. package/dist/esm/decorators/elementDefine.js +1 -2
  35. package/dist/esm/decorators/elementDefine.js.map +2 -2
  36. package/dist/esm/decorators/index.js +0 -1
  37. package/dist/esm/decorators/index.js.map +2 -2
  38. package/dist/esm/decorators/lifecycles.js +25 -0
  39. package/dist/esm/decorators/lifecycles.js.map +2 -2
  40. package/dist/esm/decorators/query.js +77 -2
  41. package/dist/esm/decorators/query.js.map +2 -2
  42. package/dist/esm/decorators/queryAll.js +77 -2
  43. package/dist/esm/decorators/queryAll.js.map +2 -2
  44. package/dist/esm/decorators/setAttribute.js +4 -4
  45. package/dist/esm/decorators/setAttribute.js.map +2 -2
  46. package/dist/esm/decorators/style.js +70 -13
  47. package/dist/esm/decorators/style.js.map +2 -2
  48. package/dist/esm/index.js +4 -4
  49. package/dist/esm/index.js.map +2 -2
  50. package/dist/esm/utils/Utils.js +140 -1
  51. package/dist/esm/utils/Utils.js.map +2 -2
  52. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +678 -168
  53. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  54. package/dist/types/decorators/applyNode.d.ts +107 -2
  55. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  56. package/dist/types/decorators/attribute.d.ts +11 -4
  57. package/dist/types/decorators/attribute.d.ts.map +1 -1
  58. package/dist/types/decorators/classList.d.ts +22 -10
  59. package/dist/types/decorators/classList.d.ts.map +1 -1
  60. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  61. package/dist/types/decorators/index.d.ts +0 -1
  62. package/dist/types/decorators/index.d.ts.map +1 -1
  63. package/dist/types/decorators/lifecycles.d.ts +14 -0
  64. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  65. package/dist/types/decorators/query.d.ts +68 -7
  66. package/dist/types/decorators/query.d.ts.map +1 -1
  67. package/dist/types/decorators/queryAll.d.ts +70 -1
  68. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  69. package/dist/types/decorators/setAttribute.d.ts.map +1 -1
  70. package/dist/types/decorators/style.d.ts +37 -3
  71. package/dist/types/decorators/style.d.ts.map +1 -1
  72. package/dist/types/index.d.ts +1 -2
  73. package/dist/types/index.d.ts.map +1 -1
  74. package/dist/types/utils/Utils.d.ts +49 -0
  75. package/dist/types/utils/Utils.d.ts.map +1 -1
  76. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +678 -168
  77. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  78. package/package.json +2 -2
  79. package/src/decorators/applyNode.ts +319 -37
  80. package/src/decorators/attribute.ts +44 -11
  81. package/src/decorators/changedAttributeHost.ts +1 -1
  82. package/src/decorators/classList.ts +107 -22
  83. package/src/decorators/elementDefine.ts +1 -2
  84. package/src/decorators/index.ts +0 -1
  85. package/src/decorators/lifecycles.ts +40 -0
  86. package/src/decorators/query.ts +147 -7
  87. package/src/decorators/queryAll.ts +148 -2
  88. package/src/decorators/setAttribute.ts +6 -5
  89. package/src/decorators/style.ts +109 -13
  90. package/src/index.ts +6 -6
  91. package/src/utils/Utils.ts +144 -0
  92. package/dist/cjs/decorators/onConnectedInnerHtml.js +0 -48
  93. package/dist/cjs/decorators/onConnectedInnerHtml.js.map +0 -7
  94. package/dist/cjs/utils/TemplateUtils.js +0 -103
  95. package/dist/cjs/utils/TemplateUtils.js.map +0 -7
  96. package/dist/esm/decorators/onConnectedInnerHtml.js +0 -29
  97. package/dist/esm/decorators/onConnectedInnerHtml.js.map +0 -7
  98. package/dist/esm/utils/TemplateUtils.js +0 -84
  99. package/dist/esm/utils/TemplateUtils.js.map +0 -7
  100. package/dist/types/decorators/onConnectedInnerHtml.d.ts +0 -15
  101. package/dist/types/decorators/onConnectedInnerHtml.d.ts.map +0 -1
  102. package/dist/types/utils/TemplateUtils.d.ts +0 -54
  103. package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
  104. package/src/decorators/onConnectedInnerHtml.ts +0 -42
  105. package/src/utils/TemplateUtils.ts +0 -83
@@ -1,6 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
+ import { SwcQueryOptions } from '../types';
4
5
 
5
6
  export const CLASS_LIST_METADATA_KEY = Symbol('simple-web-component:class-list');
6
7
 
@@ -10,10 +11,11 @@ export interface ClassListMetadata {
10
11
  propertyKey: string | symbol;
11
12
  selector: string;
12
13
  action: ClassListAction;
14
+ options: SwcQueryOptions;
13
15
  }
14
16
 
15
17
  function createClassListDecorator(action: ClassListAction) {
16
- return (selector: string): MethodDecorator => {
18
+ return (selector: string, options: SwcQueryOptions = {}): MethodDecorator => {
17
19
  return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
18
20
  const constructor = target.constructor;
19
21
  let metaList = ReflectUtils.getOwnMetadata(CLASS_LIST_METADATA_KEY, constructor) as Map<string | symbol, ClassListMetadata>;
@@ -21,22 +23,60 @@ function createClassListDecorator(action: ClassListAction) {
21
23
  metaList = new Map<string | symbol, ClassListMetadata>();
22
24
  ReflectUtils.defineMetadata(CLASS_LIST_METADATA_KEY, metaList, constructor);
23
25
  }
24
- metaList.set(propertyKey, { propertyKey, selector, action });
26
+ metaList.set(propertyKey, { propertyKey, selector, action, options });
25
27
 
26
28
  const original = descriptor.value;
27
29
  descriptor.value = async function (...args: any[]) {
28
30
  ensureInit(this);
29
31
  const res = await original.apply(this, args);
30
32
  if (res !== undefined) {
33
+ const r = options.root || 'auto';
31
34
  const hostSet = SwcUtils.getHostSet(this as any);
35
+ const targetEls: HTMLElement[] = [];
36
+
37
+ const applyRoot = (t: any) => {
38
+ if (!t || !(t instanceof HTMLElement)) return;
39
+ if (r === 'auto') {
40
+ // Classes belong to the ELEMENT, not the ShadowRoot.
41
+ targetEls.push(t);
42
+ } else {
43
+ if (r === 'light' || r === 'all') targetEls.push(t);
44
+ if ((r === 'shadow' || r === 'all') && t.shadowRoot) {
45
+ // Technically ShadowRoot doesn't have classList, but user might have specified it.
46
+ // We'll skip adding shadowRoot to targetEls for class operations.
47
+ }
48
+ }
49
+ };
50
+
51
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
52
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
53
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
54
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
55
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
56
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
57
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
58
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
59
+ else if (selector === ':host' || !selector) applyRoot(this);
60
+ else {
61
+ if (r === 'shadow') {
62
+ const found = this.shadowRoot?.querySelectorAll(selector);
63
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
64
+ } else if (r === 'light') {
65
+ const found = (this as any).querySelectorAll(selector);
66
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
67
+ } else if (r === 'all') {
68
+ const sFound = this.shadowRoot?.querySelectorAll(selector);
69
+ const lFound = (this as any).querySelectorAll(selector);
70
+ if (sFound) targetEls.push(...(Array.from(sFound) as HTMLElement[]));
71
+ if (lFound) targetEls.push(...(Array.from(lFound) as HTMLElement[]));
72
+ } else {
73
+ // auto
74
+ const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);
75
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
76
+ }
77
+ }
32
78
 
33
- let targetEl: HTMLElement | null = null;
34
- if (selector === ':host' || !selector) targetEl = this as any;
35
- else if (selector === ':parentHost') targetEl = hostSet.$parentHost;
36
- else if (selector === ':appHost') targetEl = hostSet.$appHost;
37
- else targetEl = (this.shadowRoot || (this as any)).querySelector(selector);
38
-
39
- if (targetEl) {
79
+ targetEls.forEach(targetEl => {
40
80
  if (action === 'set') {
41
81
  let classes = '';
42
82
  if (typeof res === 'object' && res !== null && !Array.isArray(res)) {
@@ -51,7 +91,7 @@ function createClassListDecorator(action: ClassListAction) {
51
91
  } else if (action === 'update') {
52
92
  if (typeof res === 'object' && res !== null && !Array.isArray(res)) {
53
93
  Object.entries(res).forEach(([cls, force]) => {
54
- targetEl!.classList.toggle(cls, !!force);
94
+ targetEl.classList.toggle(cls, !!force);
55
95
  });
56
96
  } else if (res !== undefined && res !== null) {
57
97
  const classes = Array.isArray(res) ? res.map(String) : [String(res)];
@@ -65,9 +105,9 @@ function createClassListDecorator(action: ClassListAction) {
65
105
  targetEl.classList.remove(...classes);
66
106
  } else if (action === 'toggle') {
67
107
  const classes = Array.isArray(res) ? res.map(String) : [String(res)];
68
- classes.forEach(c => targetEl!.classList.toggle(c));
108
+ classes.forEach(c => targetEl.classList.toggle(c));
69
109
  }
70
- }
110
+ });
71
111
  }
72
112
  return res;
73
113
  };
@@ -79,31 +119,31 @@ function createClassListDecorator(action: ClassListAction) {
79
119
  * @setClassList decorator to surgically replace all classes on a target element.
80
120
  * Returns: string | string[]
81
121
  */
82
- export const setClassList = createClassListDecorator('set');
122
+ export const setClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('set')(selector, options);
83
123
 
84
124
  /**
85
125
  * @updateClassList decorator to surgically update specific classes.
86
126
  * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)
87
127
  */
88
- export const updateClassList = createClassListDecorator('update');
128
+ export const updateClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('update')(selector, options);
89
129
 
90
130
  /**
91
131
  * @addClassList decorator to surgically add classes to a target element.
92
132
  * Returns: string | string[]
93
133
  */
94
- export const addClassList = createClassListDecorator('add');
134
+ export const addClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('add')(selector, options);
95
135
 
96
136
  /**
97
137
  * @removeClassList decorator to surgically remove classes from a target element.
98
138
  * Returns: string | string[]
99
139
  */
100
- export const removeClassList = createClassListDecorator('remove');
140
+ export const removeClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('remove')(selector, options);
101
141
 
102
142
  /**
103
143
  * @toggleClassList decorator to surgically toggle classes on a target element.
104
144
  * Returns: string | string[]
105
145
  */
106
- export const toggleClassList = createClassListDecorator('toggle');
146
+ export const toggleClassList = (selector: string, options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(selector, options);
107
147
 
108
148
  // Host-specific versions (for :host selector)
109
149
 
@@ -111,31 +151,76 @@ export const toggleClassList = createClassListDecorator('toggle');
111
151
  * @setClassListHost decorator to set classes on :host element.
112
152
  * Returns: string | string[]
113
153
  */
114
- export const setClassListHost = createClassListDecorator('set').bind(null, ':host');
154
+ export function setClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
155
+ export function setClassListHost(): MethodDecorator;
156
+ export function setClassListHost(options: SwcQueryOptions): MethodDecorator;
157
+ export function setClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
158
+ if (propertyKey !== undefined) {
159
+ const decorator = createClassListDecorator('set')(':host', {});
160
+ return decorator(targetOrOptions, propertyKey, descriptor);
161
+ }
162
+ return createClassListDecorator('set')(':host', (targetOrOptions as SwcQueryOptions) || {});
163
+ }
115
164
 
116
165
  /**
117
166
  * @updateClassListHost decorator to update specific classes on :host.
118
167
  * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)
119
168
  */
120
- export const updateClassListHost = createClassListDecorator('update').bind(null, ':host');
169
+ export function updateClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
170
+ export function updateClassListHost(): MethodDecorator;
171
+ export function updateClassListHost(options: SwcQueryOptions): MethodDecorator;
172
+ export function updateClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
173
+ if (propertyKey !== undefined) {
174
+ const decorator = createClassListDecorator('update')(':host', {});
175
+ return decorator(targetOrOptions, propertyKey, descriptor);
176
+ }
177
+ return createClassListDecorator('update')(':host', (targetOrOptions as SwcQueryOptions) || {});
178
+ }
121
179
 
122
180
  /**
123
181
  * @addClassListHost decorator to add classes to :host element.
124
182
  * Returns: string | string[]
125
183
  */
126
- export const addClassListHost = createClassListDecorator('add').bind(null, ':host');
184
+ export function addClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
185
+ export function addClassListHost(): MethodDecorator;
186
+ export function addClassListHost(options: SwcQueryOptions): MethodDecorator;
187
+ export function addClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
188
+ if (propertyKey !== undefined) {
189
+ const decorator = createClassListDecorator('add')(':host', {});
190
+ return decorator(targetOrOptions, propertyKey, descriptor);
191
+ }
192
+ return createClassListDecorator('add')(':host', (targetOrOptions as SwcQueryOptions) || {});
193
+ }
127
194
 
128
195
  /**
129
196
  * @removeClassListHost decorator to remove classes from :host element.
130
197
  * Returns: string | string[]
131
198
  */
132
- export const removeClassListHost = createClassListDecorator('remove').bind(null, ':host');
199
+ export function removeClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
200
+ export function removeClassListHost(): MethodDecorator;
201
+ export function removeClassListHost(options: SwcQueryOptions): MethodDecorator;
202
+ export function removeClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
203
+ if (propertyKey !== undefined) {
204
+ const decorator = createClassListDecorator('remove')(':host', {});
205
+ return decorator(targetOrOptions, propertyKey, descriptor);
206
+ }
207
+ return createClassListDecorator('remove')(':host', (targetOrOptions as SwcQueryOptions) || {});
208
+ }
133
209
 
134
210
  /**
135
211
  * @toggleClassListHost decorator to toggle classes on :host element.
136
212
  * Returns: string | string[]
137
213
  */
138
- export const toggleClassListHost = createClassListDecorator('toggle').bind(null, ':host');
214
+ export function toggleClassListHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
215
+ export function toggleClassListHost(): MethodDecorator;
216
+ export function toggleClassListHost(options: SwcQueryOptions): MethodDecorator;
217
+ export function toggleClassListHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
218
+ if (propertyKey !== undefined) {
219
+ const decorator = createClassListDecorator('toggle')(':host', {});
220
+ return decorator(targetOrOptions, propertyKey, descriptor);
221
+ }
222
+ return createClassListDecorator('toggle')(':host', (targetOrOptions as SwcQueryOptions) || {});
223
+ }
139
224
 
140
225
  export const findAllClassListMetadata = (target: any): Map<string | symbol, ClassListMetadata> => {
141
226
  const result = new Map<string | symbol, ClassListMetadata>();
@@ -1,8 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { FunctionUtils } from '@dooboostore/core';
3
- import { getOnConnectedInnerHtmlMetadata } from './onConnectedInnerHtml';
4
3
  import { getAddEventListenerMetadata } from './addEventListener';
5
- import { ON_CONSTRUCTOR_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata } from './lifecycles';
4
+ import { ON_CONSTRUCTOR_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata } from './lifecycles';
6
5
  import { getEmitCustomEventMetadataList } from './emitCustomEvent';
7
6
  import { findAllAttributeChangedMetadata } from './changedAttributeHost';
8
7
  import { findAllSetAttributeMetadata } from './setAttribute';
@@ -8,6 +8,5 @@ export * from './applyNode';
8
8
  export * from './lifecycles';
9
9
  export * from './query';
10
10
  export * from './queryAll';
11
- export * from './onConnectedInnerHtml';
12
11
  export * from './classList';
13
12
  export * from './style';
@@ -10,9 +10,19 @@ export const ON_AFTER_DISCONNECTED_METADATA_KEY = Symbol('simple-web-component:o
10
10
  export const ON_BEFORE_ADOPTED_METADATA_KEY = Symbol('simple-web-component:on-before-adopted');
11
11
  export const ON_AFTER_ADOPTED_METADATA_KEY = Symbol('simple-web-component:on-after-adopted');
12
12
  export const ON_ADD_EVENT_LISTENER_METADATA_KEY = Symbol('simple-web-component:on-add-event-listener');
13
+ export const INNER_HTML_METADATA_KEY = Symbol('simple-web-component:inner-html');
13
14
 
14
15
  export const ATTRIBUTE_CHANGED_WILDCARD = '*';
15
16
 
17
+ export interface InnerHtmlOptions {
18
+ useShadow?: boolean;
19
+ }
20
+
21
+ export interface InnerHtmlMetadata {
22
+ propertyKey: string | symbol;
23
+ options: InnerHtmlOptions;
24
+ }
25
+
16
26
  function createLifecycleDecorator(metadataKey: symbol): MethodDecorator {
17
27
  return (target: Object, propertyKey: string | symbol) => {
18
28
  const constructor = target.constructor;
@@ -40,6 +50,31 @@ export const onAdopted = onAfterAdopted;
40
50
 
41
51
  export const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER_METADATA_KEY);
42
52
 
53
+ /**
54
+ * @onConnectedInnerHtml decorator to define the initial HTML content when connected.
55
+ */
56
+ export function onConnectedInnerHtml(options: InnerHtmlOptions): MethodDecorator;
57
+ export function onConnectedInnerHtml(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
58
+ export function onConnectedInnerHtml(arg1?: InnerHtmlOptions | Object, arg2?: string | symbol, arg3?: PropertyDescriptor): MethodDecorator | void {
59
+ const decorator = (options: InnerHtmlOptions, target: Object, propertyKey: string | symbol) => {
60
+ const constructor = target.constructor;
61
+ let list = ReflectUtils.getMetadata<InnerHtmlMetadata[]>(INNER_HTML_METADATA_KEY, constructor);
62
+ if (!list) {
63
+ list = [];
64
+ ReflectUtils.defineMetadata(INNER_HTML_METADATA_KEY, list, constructor);
65
+ }
66
+ list.push({ propertyKey, options });
67
+ };
68
+
69
+ if (arg2) {
70
+ return decorator({}, arg1!, arg2);
71
+ }
72
+
73
+ return (target: Object, propertyKey: string | symbol) => {
74
+ decorator((arg1 as InnerHtmlOptions) || {}, target, propertyKey);
75
+ };
76
+ }
77
+
43
78
  /**
44
79
  * 프로토타입 체인을 순회하며 모든 라이프사이클 메서드를 수집합니다.
45
80
  */
@@ -47,3 +82,8 @@ export const findAllLifecycleMetadata = <T = (string | symbol)[]>(target: any, m
47
82
  const results = ReflectUtils.findAllMetadataFlatten(metadataKey, target);
48
83
  return results.length > 0 ? (results as unknown as T) : undefined;
49
84
  };
85
+
86
+ export const getOnConnectedInnerHtmlMetadata = (target: any): InnerHtmlMetadata[] | undefined => {
87
+ const constructor = target instanceof Function ? target : target.constructor;
88
+ return ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
89
+ };
@@ -3,8 +3,6 @@ import { getElementConfig, ensureInit } from './elementDefine';
3
3
  import { SwcUtils } from '../utils/Utils';
4
4
  import { SpecialSelector, SwcQueryOptions } from '../types';
5
5
 
6
- export type QueryOptions = { root?: 'light' | 'shadow' | 'all' | 'auto' };
7
-
8
6
  export interface QueryMetadata {
9
7
  propertyKey: string | symbol;
10
8
  selector: string;
@@ -110,10 +108,152 @@ export const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {
110
108
  };
111
109
 
112
110
  /**
113
- * @hostQuery decorator - simplified version of @query for :host selector
114
- * Usage: @hostQuery()
115
- * Usage: @hostQuery({ root: 'shadow' })
111
+ * @queryHost decorator - simplified version of @query for :host selector
112
+ * Usage: @queryHost testzzs: HTMLElement | undefined;
113
+ * Usage: @queryHost() testzzs: HTMLElement | undefined;
114
+ * Usage: @queryHost({ root: 'shadow' }) testzzs: HTMLElement | undefined;
115
+ */
116
+ export function queryHost(target: Object, propertyKey: string | symbol): void;
117
+ export function queryHost(): PropertyDecorator;
118
+ export function queryHost(options: SwcQueryOptions): PropertyDecorator;
119
+ export function queryHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
120
+ // Direct decorator usage: @queryHost (no parentheses)
121
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
122
+ return query(':host', {})(targetOrOptions, propertyKey);
123
+ }
124
+
125
+ // @queryHost() or @queryHost(options)
126
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
127
+ return query(':host', targetOrOptions as SwcQueryOptions);
128
+ } else {
129
+ return query(':host', {});
130
+ }
131
+ }
132
+
133
+ /**
134
+ * @host - Alias for @queryHost decorator
135
+ * Usage: @host element: HTMLElement | undefined;
136
+ * Usage: @host() element: HTMLElement | undefined;
137
+ * Usage: @host({ root: 'shadow' }) element: HTMLElement | undefined;
138
+ */
139
+ export const host = queryHost;
140
+
141
+ /**
142
+ * @parentHost - Query :parentHost (Direct parent SWC component)
143
+ * Usage: @parentHost parent: HTMLElement | undefined;
144
+ * Usage: @parentHost() parent: HTMLElement | undefined;
145
+ * Usage: @parentHost({ root: 'shadow' }) parent: HTMLElement | undefined;
146
+ */
147
+ export function parentHost(target: Object, propertyKey: string | symbol): void;
148
+ export function parentHost(): PropertyDecorator;
149
+ export function parentHost(options: SwcQueryOptions): PropertyDecorator;
150
+ export function parentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
151
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
152
+ return query(':parentHost', {})(targetOrOptions, propertyKey);
153
+ }
154
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
155
+ return query(':parentHost', targetOrOptions as SwcQueryOptions);
156
+ } else {
157
+ return query(':parentHost', {});
158
+ }
159
+ }
160
+
161
+ /**
162
+ * @appHost - Query :appHost (Nearest <swc-app>)
163
+ * Usage: @appHost app: SwcAppInterface | undefined;
164
+ * Usage: @appHost() app: SwcAppInterface | undefined;
165
+ * Usage: @appHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
166
+ */
167
+ export function appHost(target: Object, propertyKey: string | symbol): void;
168
+ export function appHost(): PropertyDecorator;
169
+ export function appHost(options: SwcQueryOptions): PropertyDecorator;
170
+ export function appHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
171
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
172
+ return query(':appHost', {})(targetOrOptions, propertyKey);
173
+ }
174
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
175
+ return query(':appHost', targetOrOptions as SwcQueryOptions);
176
+ } else {
177
+ return query(':appHost', {});
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @firstHost - Query :firstHost (First component in hierarchy)
183
+ * Usage: @firstHost first: HTMLElement | undefined;
184
+ * Usage: @firstHost() first: HTMLElement | undefined;
185
+ * Usage: @firstHost({ root: 'shadow' }) first: HTMLElement | undefined;
186
+ */
187
+ export function firstHost(target: Object, propertyKey: string | symbol): void;
188
+ export function firstHost(): PropertyDecorator;
189
+ export function firstHost(options: SwcQueryOptions): PropertyDecorator;
190
+ export function firstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
191
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
192
+ return query(':firstHost', {})(targetOrOptions, propertyKey);
193
+ }
194
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
195
+ return query(':firstHost', targetOrOptions as SwcQueryOptions);
196
+ } else {
197
+ return query(':firstHost', {});
198
+ }
199
+ }
200
+
201
+ /**
202
+ * @lastHost - Query :lastHost (Last component in hierarchy)
203
+ * Usage: @lastHost last: HTMLElement | undefined;
204
+ * Usage: @lastHost() last: HTMLElement | undefined;
205
+ * Usage: @lastHost({ root: 'shadow' }) last: HTMLElement | undefined;
206
+ */
207
+ export function lastHost(target: Object, propertyKey: string | symbol): void;
208
+ export function lastHost(): PropertyDecorator;
209
+ export function lastHost(options: SwcQueryOptions): PropertyDecorator;
210
+ export function lastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
211
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
212
+ return query(':lastHost', {})(targetOrOptions, propertyKey);
213
+ }
214
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
215
+ return query(':lastHost', targetOrOptions as SwcQueryOptions);
216
+ } else {
217
+ return query(':lastHost', {});
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @firstAppHost - Query :firstAppHost (First <swc-app> in hierarchy)
223
+ * Usage: @firstAppHost app: SwcAppInterface | undefined;
224
+ * Usage: @firstAppHost() app: SwcAppInterface | undefined;
225
+ * Usage: @firstAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
226
+ */
227
+ export function firstAppHost(target: Object, propertyKey: string | symbol): void;
228
+ export function firstAppHost(): PropertyDecorator;
229
+ export function firstAppHost(options: SwcQueryOptions): PropertyDecorator;
230
+ export function firstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
231
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
232
+ return query(':firstAppHost', {})(targetOrOptions, propertyKey);
233
+ }
234
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
235
+ return query(':firstAppHost', targetOrOptions as SwcQueryOptions);
236
+ } else {
237
+ return query(':firstAppHost', {});
238
+ }
239
+ }
240
+
241
+ /**
242
+ * @lastAppHost - Query :lastAppHost (Last <swc-app> in hierarchy)
243
+ * Usage: @lastAppHost app: SwcAppInterface | undefined;
244
+ * Usage: @lastAppHost() app: SwcAppInterface | undefined;
245
+ * Usage: @lastAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
116
246
  */
117
- export function queryHost(options?: SwcQueryOptions): PropertyDecorator {
118
- return query(':host', options);
247
+ export function lastAppHost(target: Object, propertyKey: string | symbol): void;
248
+ export function lastAppHost(): PropertyDecorator;
249
+ export function lastAppHost(options: SwcQueryOptions): PropertyDecorator;
250
+ export function lastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
251
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
252
+ return query(':lastAppHost', {})(targetOrOptions, propertyKey);
253
+ }
254
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
255
+ return query(':lastAppHost', targetOrOptions as SwcQueryOptions);
256
+ } else {
257
+ return query(':lastAppHost', {});
258
+ }
119
259
  }
@@ -113,6 +113,152 @@ export const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined
113
113
  * Usage: @hostQueryAll()
114
114
  * Usage: @hostQueryAll({ root: 'shadow' })
115
115
  */
116
- export function queryAllHost(options?: SwcQueryOptions): PropertyDecorator {
117
- return queryAll(':host', options);
116
+ /**
117
+ * @queryAllHost decorator - simplified version of @queryAll for :host selector
118
+ * Usage: @queryAllHost items: HTMLElement[];
119
+ * Usage: @queryAllHost() items: HTMLElement[];
120
+ * Usage: @queryAllHost({ root: 'shadow' }) items: HTMLElement[];
121
+ */
122
+ export function queryAllHost(target: Object, propertyKey: string | symbol): void;
123
+ export function queryAllHost(): PropertyDecorator;
124
+ export function queryAllHost(options: SwcQueryOptions): PropertyDecorator;
125
+ export function queryAllHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
126
+ // Direct decorator usage: @queryAllHost (no parentheses)
127
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
128
+ return queryAll(':host', {})(targetOrOptions, propertyKey);
129
+ }
130
+
131
+ // @queryAllHost() or @queryAllHost(options)
132
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
133
+ return queryAll(':host', targetOrOptions as SwcQueryOptions);
134
+ } else {
135
+ return queryAll(':host', {});
136
+ }
137
+ }
138
+
139
+ /**
140
+ * @allHost - Alias for @queryAllHost decorator
141
+ * Usage: @allHost items: HTMLElement[];
142
+ * Usage: @allHost() items: HTMLElement[];
143
+ * Usage: @allHost({ root: 'shadow' }) items: HTMLElement[];
144
+ */
145
+ export const allHost = queryAllHost;
146
+ /**
147
+ * @allParentHost - Query all :parentHost (All parent SWC components)
148
+ * Usage: @allParentHost parents: HTMLElement[];
149
+ * Usage: @allParentHost() parents: HTMLElement[];
150
+ * Usage: @allParentHost({ root: 'shadow' }) parents: HTMLElement[];
151
+ */
152
+ export function allParentHost(target: Object, propertyKey: string | symbol): void;
153
+ export function allParentHost(): PropertyDecorator;
154
+ export function allParentHost(options: SwcQueryOptions): PropertyDecorator;
155
+ export function allParentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
156
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
157
+ return queryAll(':parentHost', {})(targetOrOptions, propertyKey);
158
+ }
159
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
160
+ return queryAll(':parentHost', targetOrOptions as SwcQueryOptions);
161
+ } else {
162
+ return queryAll(':parentHost', {});
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @allAppHost - Query all :appHost (All <swc-app> instances)
168
+ * Usage: @allAppHost apps: SwcAppInterface[];
169
+ * Usage: @allAppHost() apps: SwcAppInterface[];
170
+ * Usage: @allAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
171
+ */
172
+ export function allAppHost(target: Object, propertyKey: string | symbol): void;
173
+ export function allAppHost(): PropertyDecorator;
174
+ export function allAppHost(options: SwcQueryOptions): PropertyDecorator;
175
+ export function allAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
176
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
177
+ return queryAll(':appHost', {})(targetOrOptions, propertyKey);
178
+ }
179
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
180
+ return queryAll(':appHost', targetOrOptions as SwcQueryOptions);
181
+ } else {
182
+ return queryAll(':appHost', {});
183
+ }
184
+ }
185
+
186
+ /**
187
+ * @allFirstHost - Query all :firstHost (All first components in hierarchy)
188
+ * Usage: @allFirstHost firsts: HTMLElement[];
189
+ * Usage: @allFirstHost() firsts: HTMLElement[];
190
+ * Usage: @allFirstHost({ root: 'shadow' }) firsts: HTMLElement[];
191
+ */
192
+ export function allFirstHost(target: Object, propertyKey: string | symbol): void;
193
+ export function allFirstHost(): PropertyDecorator;
194
+ export function allFirstHost(options: SwcQueryOptions): PropertyDecorator;
195
+ export function allFirstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
196
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
197
+ return queryAll(':firstHost', {})(targetOrOptions, propertyKey);
198
+ }
199
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
200
+ return queryAll(':firstHost', targetOrOptions as SwcQueryOptions);
201
+ } else {
202
+ return queryAll(':firstHost', {});
203
+ }
204
+ }
205
+
206
+ /**
207
+ * @allLastHost - Query all :lastHost (All last components in hierarchy)
208
+ * Usage: @allLastHost lasts: HTMLElement[];
209
+ * Usage: @allLastHost() lasts: HTMLElement[];
210
+ * Usage: @allLastHost({ root: 'shadow' }) lasts: HTMLElement[];
211
+ */
212
+ export function allLastHost(target: Object, propertyKey: string | symbol): void;
213
+ export function allLastHost(): PropertyDecorator;
214
+ export function allLastHost(options: SwcQueryOptions): PropertyDecorator;
215
+ export function allLastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
216
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
217
+ return queryAll(':lastHost', {})(targetOrOptions, propertyKey);
218
+ }
219
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
220
+ return queryAll(':lastHost', targetOrOptions as SwcQueryOptions);
221
+ } else {
222
+ return queryAll(':lastHost', {});
223
+ }
118
224
  }
225
+
226
+ /**
227
+ * @allFirstAppHost - Query all :firstAppHost (All first <swc-app> in hierarchy)
228
+ * Usage: @allFirstAppHost apps: SwcAppInterface[];
229
+ * Usage: @allFirstAppHost() apps: SwcAppInterface[];
230
+ * Usage: @allFirstAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
231
+ */
232
+ export function allFirstAppHost(target: Object, propertyKey: string | symbol): void;
233
+ export function allFirstAppHost(): PropertyDecorator;
234
+ export function allFirstAppHost(options: SwcQueryOptions): PropertyDecorator;
235
+ export function allFirstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
236
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
237
+ return queryAll(':firstAppHost', {})(targetOrOptions, propertyKey);
238
+ }
239
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
240
+ return queryAll(':firstAppHost', targetOrOptions as SwcQueryOptions);
241
+ } else {
242
+ return queryAll(':firstAppHost', {});
243
+ }
244
+ }
245
+
246
+ /**
247
+ * @allLastAppHost - Query all :lastAppHost (All last <swc-app> in hierarchy)
248
+ * Usage: @allLastAppHost apps: SwcAppInterface[];
249
+ * Usage: @allLastAppHost() apps: SwcAppInterface[];
250
+ * Usage: @allLastAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
251
+ */
252
+ export function allLastAppHost(target: Object, propertyKey: string | symbol): void;
253
+ export function allLastAppHost(): PropertyDecorator;
254
+ export function allLastAppHost(options: SwcQueryOptions): PropertyDecorator;
255
+ export function allLastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
256
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
257
+ return queryAll(':lastAppHost', {})(targetOrOptions, propertyKey);
258
+ }
259
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
260
+ return queryAll(':lastAppHost', targetOrOptions as SwcQueryOptions);
261
+ } else {
262
+ return queryAll(':lastAppHost', {});
263
+ }
264
+ }
@@ -44,11 +44,12 @@ export function setAttribute(selector: string, name: string, options: SwcQueryOp
44
44
  const applyRoot = (t: any) => {
45
45
  if (!t) return;
46
46
  if (r === 'auto') {
47
- targetEls.push((t as any).shadowRoot || t);
48
- return;
47
+ // Attributes belong to the ELEMENT, not the ShadowRoot.
48
+ targetEls.push(t);
49
+ } else {
50
+ if (r === 'light' || r === 'all') targetEls.push(t);
51
+ if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);
49
52
  }
50
- if (r === 'light' || r === 'all') targetEls.push(t);
51
- if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);
52
53
  };
53
54
 
54
55
  if (selector === ':window') targetEls.push(currentWin);
@@ -81,7 +82,7 @@ export function setAttribute(selector: string, name: string, options: SwcQueryOp
81
82
  if (!targetEl || typeof (targetEl as any).setAttribute !== 'function') return;
82
83
  if (res === null) (targetEl as any).removeAttribute(name);
83
84
  else (targetEl as any).setAttribute(name, String(res));
84
- })
85
+ });
85
86
  }
86
87
  return res;
87
88
  };