@dooboostore/simple-web-component 1.0.23 → 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 (78) hide show
  1. package/README.md +238 -44
  2. package/dist/cjs/decorators/applyNode.js +129 -34
  3. package/dist/cjs/decorators/applyNode.js.map +2 -2
  4. package/dist/cjs/decorators/attribute.js +21 -2
  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 +60 -17
  8. package/dist/cjs/decorators/classList.js.map +2 -2
  9. package/dist/cjs/decorators/query.js +77 -2
  10. package/dist/cjs/decorators/query.js.map +2 -2
  11. package/dist/cjs/decorators/queryAll.js +77 -2
  12. package/dist/cjs/decorators/queryAll.js.map +2 -2
  13. package/dist/cjs/decorators/setAttribute.js +4 -4
  14. package/dist/cjs/decorators/setAttribute.js.map +2 -2
  15. package/dist/cjs/decorators/style.js +46 -15
  16. package/dist/cjs/decorators/style.js.map +2 -2
  17. package/dist/cjs/index.js +4 -4
  18. package/dist/cjs/index.js.map +2 -2
  19. package/dist/cjs/utils/Utils.js +140 -1
  20. package/dist/cjs/utils/Utils.js.map +2 -2
  21. package/dist/esm/decorators/applyNode.js +129 -34
  22. package/dist/esm/decorators/applyNode.js.map +2 -2
  23. package/dist/esm/decorators/attribute.js +21 -2
  24. package/dist/esm/decorators/attribute.js.map +2 -2
  25. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  26. package/dist/esm/decorators/classList.js +60 -17
  27. package/dist/esm/decorators/classList.js.map +2 -2
  28. package/dist/esm/decorators/query.js +77 -2
  29. package/dist/esm/decorators/query.js.map +2 -2
  30. package/dist/esm/decorators/queryAll.js +77 -2
  31. package/dist/esm/decorators/queryAll.js.map +2 -2
  32. package/dist/esm/decorators/setAttribute.js +4 -4
  33. package/dist/esm/decorators/setAttribute.js.map +2 -2
  34. package/dist/esm/decorators/style.js +46 -15
  35. package/dist/esm/decorators/style.js.map +2 -2
  36. package/dist/esm/index.js +4 -4
  37. package/dist/esm/index.js.map +2 -2
  38. package/dist/esm/utils/Utils.js +140 -1
  39. package/dist/esm/utils/Utils.js.map +2 -2
  40. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +542 -155
  41. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  42. package/dist/types/decorators/applyNode.d.ts +49 -27
  43. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  44. package/dist/types/decorators/attribute.d.ts +11 -4
  45. package/dist/types/decorators/attribute.d.ts.map +1 -1
  46. package/dist/types/decorators/classList.d.ts +15 -5
  47. package/dist/types/decorators/classList.d.ts.map +1 -1
  48. package/dist/types/decorators/query.d.ts +68 -4
  49. package/dist/types/decorators/query.d.ts.map +1 -1
  50. package/dist/types/decorators/queryAll.d.ts +70 -1
  51. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  52. package/dist/types/decorators/setAttribute.d.ts.map +1 -1
  53. package/dist/types/decorators/style.d.ts +17 -8
  54. package/dist/types/decorators/style.d.ts.map +1 -1
  55. package/dist/types/index.d.ts +1 -2
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/utils/Utils.d.ts +49 -0
  58. package/dist/types/utils/Utils.d.ts.map +1 -1
  59. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +542 -155
  60. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  61. package/package.json +3 -3
  62. package/src/decorators/applyNode.ts +179 -60
  63. package/src/decorators/attribute.ts +43 -10
  64. package/src/decorators/changedAttributeHost.ts +1 -1
  65. package/src/decorators/classList.ts +79 -17
  66. package/src/decorators/query.ts +147 -5
  67. package/src/decorators/queryAll.ts +148 -2
  68. package/src/decorators/setAttribute.ts +6 -5
  69. package/src/decorators/style.ts +67 -22
  70. package/src/index.ts +6 -6
  71. package/src/utils/Utils.ts +144 -0
  72. package/dist/cjs/utils/TemplateUtils.js +0 -109
  73. package/dist/cjs/utils/TemplateUtils.js.map +0 -7
  74. package/dist/esm/utils/TemplateUtils.js +0 -90
  75. package/dist/esm/utils/TemplateUtils.js.map +0 -7
  76. package/dist/types/utils/TemplateUtils.d.ts +0 -59
  77. package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
  78. package/src/utils/TemplateUtils.ts +0 -92
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -92,10 +92,10 @@
92
92
  "webpack": "^5.93.0",
93
93
  "webpack-cli": "^5.1.4",
94
94
  "webpack-dev-server": "^5.2.0",
95
+ "@dooboostore/core": "1.0.30",
95
96
  "@dooboostore/core-web": "1.0.10",
96
97
  "@dooboostore/core-node": "1.0.12",
97
- "@dooboostore/simple-boot": "1.0.54",
98
- "@dooboostore/core": "1.0.30"
98
+ "@dooboostore/simple-boot": "1.0.54"
99
99
  },
100
100
  "scripts": {
101
101
  "clean": "rm -rf dist",
@@ -1,6 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit, getElementConfig } from './elementDefine';
3
3
  import { SwcRootType } from '../types';
4
+ import {SwcUtils} from "../utils/Utils";
4
5
 
5
6
  export type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';
6
7
 
@@ -74,14 +75,23 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
74
75
 
75
76
  const pos = options.position || 'beforeEnd';
76
77
  const r = options.root || 'auto';
77
-
78
- const getTargetRoot = () => {
79
- if (r === 'shadow') return this.shadowRoot;
80
- if (r === 'light') return this as any;
81
- if (r === 'all') return this.shadowRoot || (this as any);
82
- return this.shadowRoot || (this as any); // auto
78
+ const applyRoot = (t: any) => {
79
+ if (!t || !(t instanceof HTMLElement)) return t;
80
+ if (r === 'auto') return t.shadowRoot || t;
81
+ if (r === 'shadow') return t.shadowRoot;
82
+ if (r === 'light') return t;
83
+ if (r === 'all') return t.shadowRoot || t; // query only returns one, so shadow preferred
84
+ return t;
83
85
  };
84
86
 
87
+ const hostSet = SwcUtils.getHostSet(this);
88
+ // const getTargetRoot = () => {
89
+ // if (r === 'shadow') return this.shadowRoot;
90
+ // if (r === 'light') return this as any;
91
+ // if (r === 'all') return this.shadowRoot || (this as any);
92
+ // return this.shadowRoot || (this as any); // auto
93
+ // };
94
+
85
95
  if (pos === 'remove') {
86
96
  // Remove element(s) if returned value is truthy
87
97
  if (res) {
@@ -94,7 +104,7 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
94
104
  (this as any).remove();
95
105
  }
96
106
  } else {
97
- const targetRoot = getTargetRoot();
107
+ const targetRoot = applyRoot(this);
98
108
  if (targetRoot) {
99
109
  const targets = targetRoot.querySelectorAll(selector);
100
110
  targets.forEach((el: Element) => el.remove());
@@ -103,14 +113,23 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
103
113
  }
104
114
  } else {
105
115
  let targetEl: any = null;
106
- if (selector === ':host' || !selector) {
107
- if (r === 'shadow') {
108
- targetEl = this.shadowRoot; // Target shadow DOM root
109
- } else {
110
- targetEl = this as any; // Target the component itself
111
- }
116
+
117
+ if (selector === ':host') {
118
+ targetEl = applyRoot(this)
119
+ } else if (selector === ':parentHost') {
120
+ targetEl = applyRoot(hostSet.$parentHost)
121
+ } else if (selector === ':appHost') {
122
+ targetEl = applyRoot(hostSet.$appHost)
123
+ } else if (selector === ':firstHost') {
124
+ targetEl = applyRoot(hostSet.$firstHost)
125
+ } else if (selector === ':lastHost') {
126
+ targetEl = applyRoot(hostSet.$lastHost)
127
+ } else if (selector === ':firstAppHost') {
128
+ targetEl = applyRoot(hostSet.$firstHost)
129
+ } else if (selector === ':lastAppHost') {
130
+ targetEl = applyRoot(hostSet.$lastAppHost);
112
131
  } else {
113
- const targetRoot = getTargetRoot();
132
+ const targetRoot = applyRoot(this);
114
133
  targetEl = targetRoot ? targetRoot.querySelector(selector) : null;
115
134
  }
116
135
 
@@ -170,11 +189,28 @@ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, Appl
170
189
 
171
190
  /**
172
191
  * @applyNodeHost decorator - simplified version of @applyNode for :host selector
192
+ * Usage: @applyNodeHost addItem() { return '<li>New Item</li>'; }
173
193
  * Usage: @applyNodeHost() addItem() { return '<li>New Item</li>'; }
174
194
  * Usage: @applyNodeHost({ position: 'afterBegin' }) prependItem() { return '<h1>Title</h1>'; }
175
195
  */
176
- export function applyNodeHost(options: ApplyNodeOptions = { position: 'beforeEnd' }): MethodDecorator {
177
- return applyNode(':host', options);
196
+ export function applyNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
197
+ export function applyNodeHost(): MethodDecorator;
198
+ export function applyNodeHost(options: ApplyNodeOptions): MethodDecorator;
199
+ export function applyNodeHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
200
+ // Direct decorator usage: @applyNodeHost (no parentheses)
201
+ console.log('vvvvv')
202
+ if (propertyKey !== undefined && typeof propertyKey === 'string' || typeof propertyKey === 'symbol') {
203
+ return applyNode(':host', { position: 'beforeEnd' })(targetOrOptions, propertyKey, descriptor);
204
+ }
205
+
206
+ // @applyNodeHost() or @applyNodeHost(options)
207
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
208
+ const options = targetOrOptions as ApplyNodeOptions;
209
+ return applyNode(':host', { ...options, position: options.position || 'beforeEnd' });
210
+ } else {
211
+ // @applyNodeHost() - use default position
212
+ return applyNode(':host', { position: 'beforeEnd' });
213
+ }
178
214
  }
179
215
 
180
216
  // Convenience decorators for specific positions
@@ -182,109 +218,192 @@ export function applyNodeHost(options: ApplyNodeOptions = { position: 'beforeEnd
182
218
  /**
183
219
  * @applyBeforeBeginNode - Insert before target element
184
220
  */
185
- export const applyBeforeBeginNode = (selector: string, options: ApplyNodeOptions = {}) =>
186
- applyNode(selector, { ...options, position: 'beforeBegin' });
221
+ export function applyBeforeBeginNode(selector: string): MethodDecorator;
222
+ export function applyBeforeBeginNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
223
+ export function applyBeforeBeginNode(selector: string, options?: ApplyNodeOptions): any {
224
+ return applyNode(selector, { ...options, position: 'beforeBegin' });
225
+ }
187
226
 
188
227
  /**
189
228
  * @applyAfterBeginNode - Prepend to target element
190
229
  */
191
- export const applyAfterBeginNode = (selector: string, options: ApplyNodeOptions = {}) =>
192
- applyNode(selector, { ...options, position: 'afterBegin' });
230
+ export function applyAfterBeginNode(selector: string): MethodDecorator;
231
+ export function applyAfterBeginNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
232
+ export function applyAfterBeginNode(selector: string, options?: ApplyNodeOptions): any {
233
+ return applyNode(selector, { ...options, position: 'afterBegin' });
234
+ }
193
235
 
194
236
  /**
195
237
  * @applyBeforeEndNode - Append to target element (default)
196
238
  */
197
- export const applyBeforeEndNode = (selector: string, options: ApplyNodeOptions = {}) =>
198
- applyNode(selector, { ...options, position: 'beforeEnd' });
239
+ export function applyBeforeEndNode(selector: string): MethodDecorator;
240
+ export function applyBeforeEndNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
241
+ export function applyBeforeEndNode(selector: string, options?: ApplyNodeOptions): any {
242
+ return applyNode(selector, { ...options, position: 'beforeEnd' });
243
+ }
199
244
 
200
245
  /**
201
246
  * @applyAfterEndNode - Insert after target element
202
247
  */
203
- export const applyAfterEndNode = (selector: string, options: ApplyNodeOptions = {}) =>
204
- applyNode(selector, { ...options, position: 'afterEnd' });
248
+ export function applyAfterEndNode(selector: string): MethodDecorator;
249
+ export function applyAfterEndNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
250
+ export function applyAfterEndNode(selector: string, options?: ApplyNodeOptions): any {
251
+ return applyNode(selector, { ...options, position: 'afterEnd' });
252
+ }
205
253
 
206
254
  /**
207
255
  * @applyReplaceNode - Replace entire target element
208
256
  */
209
- export const applyReplaceNode = (selector: string, options: ApplyNodeOptions = {}) =>
210
- applyNode(selector, { ...options, position: 'replace' });
257
+ export function applyReplaceNode(selector: string): MethodDecorator;
258
+ export function applyReplaceNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
259
+ export function applyReplaceNode(selector: string, options?: ApplyNodeOptions): any {
260
+ return applyNode(selector, { ...options, position: 'replace' });
261
+ }
211
262
 
212
263
  /**
213
264
  * @applyReplaceChildrenNode - Replace all children of target element
214
265
  */
215
- export const applyReplaceChildrenNode = (selector: string, options: ApplyNodeOptions = {}) =>
216
- applyNode(selector, { ...options, position: 'replaceChildren' });
266
+ export function applyReplaceChildrenNode(selector: string): MethodDecorator;
267
+ export function applyReplaceChildrenNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
268
+ export function applyReplaceChildrenNode(selector: string, options?: ApplyNodeOptions): any {
269
+ return applyNode(selector, { ...options, position: 'replaceChildren' });
270
+ }
217
271
 
218
272
  /**
219
273
  * @applyInnerHtmlNode - Set target's innerHTML
220
274
  */
221
- export const applyInnerHtmlNode = (selector: string, options: ApplyNodeOptions = {}) =>
222
- applyNode(selector, { ...options, position: 'innerHtml' });
275
+ export function applyInnerHtmlNode(selector: string): MethodDecorator;
276
+ export function applyInnerHtmlNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
277
+ export function applyInnerHtmlNode(selector: string, options?: ApplyNodeOptions): any {
278
+ return applyNode(selector, { ...options, position: 'innerHtml' });
279
+ }
223
280
 
224
281
  /**
225
282
  * @applyInnerTextNode - Set target's innerText
226
283
  */
227
- export const applyInnerTextNode = (selector: string, options: ApplyNodeOptions = {}) =>
228
- applyNode(selector, { ...options, position: 'innerText' });
284
+ export function applyInnerTextNode(selector: string): MethodDecorator;
285
+ export function applyInnerTextNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
286
+ export function applyInnerTextNode(selector: string, options?: ApplyNodeOptions): any {
287
+ return applyNode(selector, { ...options, position: 'innerText' });
288
+ }
229
289
 
230
290
  /**
231
291
  * @applyRemoveNode - Remove target element if truthy
232
292
  */
233
- export const applyRemoveNode = (selector: string, options: ApplyNodeOptions = {}) =>
234
- applyNode(selector, { ...options, position: 'remove' });
293
+ export function applyRemoveNode(selector: string): MethodDecorator;
294
+ export function applyRemoveNode(selector: string, options: ApplyNodeOptions): MethodDecorator;
295
+ export function applyRemoveNode(selector: string, options?: ApplyNodeOptions): any {
296
+ return applyNode(selector, { ...options, position: 'remove' });
297
+ }
235
298
 
236
299
  // Host versions
237
300
 
238
301
  /**
239
302
  * @applyBeforeBeginNodeHost - Insert before :host
240
303
  */
241
- export const applyBeforeBeginNodeHost = (options: ApplyNodeOptions = {}) =>
242
- applyNode(':host', { ...options, position: 'beforeBegin' });
304
+ export function applyBeforeBeginNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
305
+ export function applyBeforeBeginNodeHost(): MethodDecorator;
306
+ export function applyBeforeBeginNodeHost(options: ApplyNodeOptions): MethodDecorator;
307
+ export function applyBeforeBeginNodeHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
308
+ if (propertyKey !== undefined) {
309
+ const decorator = applyNode(':host', { position: 'beforeBegin' });
310
+ return decorator(targetOrOptions, propertyKey, descriptor);
311
+ }
312
+ return applyNode(':host', { ...(targetOrOptions as ApplyNodeOptions || {}), position: 'beforeBegin' });
313
+ }
243
314
 
244
315
  /**
245
316
  * @applyAfterBeginNodeHost - Prepend to :host
246
- */
247
- export const applyAfterBeginNodeHost = (options: ApplyNodeOptions = {}) =>
248
- applyNode(':host', { ...options, position: 'afterBegin' });
317
+ */export function applyAfterBeginNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyAfterBeginNodeHost(): MethodDecorator;
318
+ export function applyAfterBeginNodeHost(options: ApplyNodeOptions): MethodDecorator;
319
+ export function applyAfterBeginNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
320
+ if (propertyKey !== undefined) {
321
+ const decorator = applyNode(':host', { position: 'afterBegin' });
322
+ return decorator(optionsOrTarget, propertyKey, descriptor);
323
+ }
324
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'afterBegin' });
325
+ }
249
326
 
250
327
  /**
251
328
  * @applyBeforeEndNodeHost - Append to :host
252
- */
253
- export const applyBeforeEndNodeHost = (options: ApplyNodeOptions = {}) =>
254
- applyNode(':host', { ...options, position: 'beforeEnd' });
329
+ */export function applyBeforeEndNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyBeforeEndNodeHost(): MethodDecorator;
330
+ export function applyBeforeEndNodeHost(options: ApplyNodeOptions): MethodDecorator;
331
+ export function applyBeforeEndNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
332
+ if (propertyKey !== undefined) {
333
+ const decorator = applyNode(':host', { position: 'beforeEnd' });
334
+ return decorator(optionsOrTarget, propertyKey, descriptor);
335
+ }
336
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'beforeEnd' });
337
+ }
255
338
 
256
339
  /**
257
340
  * @applyAfterEndNodeHost - Insert after :host
258
- */
259
- export const applyAfterEndNodeHost = (options: ApplyNodeOptions = {}) =>
260
- applyNode(':host', { ...options, position: 'afterEnd' });
341
+ */export function applyAfterEndNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyAfterEndNodeHost(): MethodDecorator;
342
+ export function applyAfterEndNodeHost(options: ApplyNodeOptions): MethodDecorator;
343
+ export function applyAfterEndNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
344
+ if (propertyKey !== undefined) {
345
+ const decorator = applyNode(':host', { position: 'afterEnd' });
346
+ return decorator(optionsOrTarget, propertyKey, descriptor);
347
+ }
348
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'afterEnd' });
349
+ }
261
350
 
262
351
  /**
263
352
  * @applyReplaceNodeHost - Replace :host
264
- */
265
- export const applyReplaceNodeHost = (options: ApplyNodeOptions = {}) =>
266
- applyNode(':host', { ...options, position: 'replace' });
353
+ */export function applyReplaceNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyReplaceNodeHost(): MethodDecorator;
354
+ export function applyReplaceNodeHost(options: ApplyNodeOptions): MethodDecorator;
355
+ export function applyReplaceNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
356
+ if (propertyKey !== undefined) {
357
+ const decorator = applyNode(':host', { position: 'replace' });
358
+ return decorator(optionsOrTarget, propertyKey, descriptor);
359
+ }
360
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'replace' });
361
+ }
267
362
 
268
363
  /**
269
364
  * @applyReplaceChildrenNodeHost - Replace children of :host
270
- */
271
- export const applyReplaceChildrenNodeHost = (options: ApplyNodeOptions = {}) =>
272
- applyNode(':host', { ...options, position: 'replaceChildren' });
365
+ */export function applyReplaceChildrenNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyReplaceChildrenNodeHost(): MethodDecorator;
366
+ export function applyReplaceChildrenNodeHost(options: ApplyNodeOptions): MethodDecorator;
367
+ export function applyReplaceChildrenNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
368
+ if (propertyKey !== undefined) {
369
+ const decorator = applyNode(':host', { position: 'replaceChildren' });
370
+ return decorator(optionsOrTarget, propertyKey, descriptor);
371
+ }
372
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'replaceChildren' });
373
+ }
273
374
 
274
375
  /**
275
376
  * @applyInnerHtmlNodeHost - Set :host innerHTML
276
- */
277
- export const applyInnerHtmlNodeHost = (options: ApplyNodeOptions = {}) =>
278
- applyNode(':host', { ...options, position: 'innerHtml' });
377
+ */export function applyInnerHtmlNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyInnerHtmlNodeHost(): MethodDecorator;
378
+ export function applyInnerHtmlNodeHost(options: ApplyNodeOptions): MethodDecorator;
379
+ export function applyInnerHtmlNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
380
+ if (propertyKey !== undefined) {
381
+ const decorator = applyNode(':host', { position: 'innerHtml' });
382
+ return decorator(optionsOrTarget, propertyKey, descriptor);
383
+ }
384
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'innerHtml' });
385
+ }
279
386
 
280
387
  /**
281
388
  * @applyInnerTextNodeHost - Set :host innerText
282
- */
283
- export const applyInnerTextNodeHost = (options: ApplyNodeOptions = {}) =>
284
- applyNode(':host', { ...options, position: 'innerText' });
389
+ */export function applyInnerTextNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyInnerTextNodeHost(): MethodDecorator;
390
+ export function applyInnerTextNodeHost(options: ApplyNodeOptions): MethodDecorator;
391
+ export function applyInnerTextNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
392
+ if (propertyKey !== undefined) {
393
+ const decorator = applyNode(':host', { position: 'innerText' });
394
+ return decorator(optionsOrTarget, propertyKey, descriptor);
395
+ }
396
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'innerText' });
397
+ }
285
398
 
286
399
  /**
287
400
  * @applyRemoveNodeHost - Remove :host if truthy
288
- */
289
- export const applyRemoveNodeHost = (options: ApplyNodeOptions = {}) =>
290
- applyNode(':host', { ...options, position: 'remove' });
401
+ */export function applyRemoveNodeHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;export function applyRemoveNodeHost(): MethodDecorator;
402
+ export function applyRemoveNodeHost(options: ApplyNodeOptions): MethodDecorator;
403
+ export function applyRemoveNodeHost(optionsOrTarget?: ApplyNodeOptions | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
404
+ if (propertyKey !== undefined) {
405
+ const decorator = applyNode(':host', { position: 'remove' });
406
+ return decorator(optionsOrTarget, propertyKey, descriptor);
407
+ }
408
+ return applyNode(':host', { ...(optionsOrTarget as ApplyNodeOptions || {}), position: 'remove' });
409
+ }
@@ -1,7 +1,7 @@
1
- import { ReflectUtils } from '@dooboostore/core';
2
- import { ensureInit, getElementConfig } from './elementDefine';
3
- import { SwcUtils } from '../utils/Utils';
4
- import { SpecialSelector, SwcQueryOptions } from '../types';
1
+ import {ReflectUtils} from '@dooboostore/core';
2
+ import {ensureInit, getElementConfig} from './elementDefine';
3
+ import {SwcUtils} from '../utils/Utils';
4
+ import {SpecialSelector, SwcQueryOptions} from '../types';
5
5
 
6
6
  export interface AttributeOptions extends SwcQueryOptions {
7
7
  name?: string;
@@ -97,7 +97,7 @@ export function attribute(selector: string, options: AttributeOptions = {}): Pro
97
97
  metaList = [];
98
98
  ReflectUtils.defineMetadata(ATTRIBUTE_METADATA_KEY, metaList, constructor);
99
99
  }
100
- metaList.push({ propertyKey, selector, options, privateKey });
100
+ metaList.push({propertyKey, selector, options, privateKey});
101
101
 
102
102
  // Helper function to apply setAttribute to targets
103
103
  const applySetAttribute = (inst: any, targets: HTMLElement[], attrName: string, nv: any) => {
@@ -183,10 +183,43 @@ export const findAllAttributeMetadata = (target: any): AttributeMetadata[] => {
183
183
  };
184
184
 
185
185
  /**
186
- * @hostAttribute decorator - simplified version of @attribute for :host selector
187
- * Usage: @hostAttribute('data-product-id')
188
- * Usage: @hostAttribute('disabled', { type: Boolean })
186
+ * @attributeHost decorator - simplified version of @attribute for :host selector
187
+ * Usage: @attributeHost - uses field name as attribute name
188
+ * Usage: @attributeHost() - uses field name as attribute name
189
+ * Usage: @attributeHost('data-id') - uses custom attribute name
190
+ * Usage: @attributeHost({ type: Boolean }) - uses field name with options
191
+ * Usage: @attributeHost('data-id', { type: Boolean }) - uses custom name with options
189
192
  */
190
- export function attributeHost(attrName: string, options: AttributeOptions = {}): PropertyDecorator {
191
- return attribute(':host', { ...options, name: attrName });
193
+ export function attributeHost(target: Object, propertyKey: string | symbol): void;
194
+ export function attributeHost(): PropertyDecorator;
195
+ export function attributeHost(options: AttributeOptions): PropertyDecorator;
196
+ export function attributeHost(attrName: string): PropertyDecorator;
197
+ export function attributeHost(attrName: string, options: AttributeOptions): PropertyDecorator;
198
+ export function attributeHost(targetOrAttrOrOptions?: any, propertyKeyOrOptions?: any): any {
199
+ // Direct decorator usage: @attributeHost (no parentheses)
200
+ if (propertyKeyOrOptions !== undefined && (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
201
+ const fieldName = String(propertyKeyOrOptions);
202
+ return attribute(':host', { name: fieldName })(targetOrAttrOrOptions, propertyKeyOrOptions);
203
+ }
204
+
205
+ // @attributeHost() or @attributeHost(options) or @attributeHost('name')
206
+ if (typeof targetOrAttrOrOptions === 'string') {
207
+ // @attributeHost('customName') or @attributeHost('customName', options)
208
+ const attrName = targetOrAttrOrOptions;
209
+ const options = (typeof propertyKeyOrOptions === 'object' ? propertyKeyOrOptions : {}) as AttributeOptions;
210
+ return attribute(':host', { ...options, name: attrName });
211
+ } else if (typeof targetOrAttrOrOptions === 'object') {
212
+ // @attributeHost(options) - use field name as attribute name
213
+ const options = targetOrAttrOrOptions as AttributeOptions;
214
+ return (target: Object, propertyKey: string | symbol) => {
215
+ const fieldName = String(propertyKey);
216
+ return attribute(':host', { ...options, name: fieldName })(target, propertyKey);
217
+ };
218
+ } else {
219
+ // @attributeHost() - use field name as attribute name
220
+ return (target: Object, propertyKey: string | symbol) => {
221
+ const fieldName = String(propertyKey);
222
+ return attribute(':host', { name: fieldName })(target, propertyKey);
223
+ };
224
+ }
192
225
  }
@@ -1,4 +1,4 @@
1
- import { ReflectUtils } from '@dooboostore/core';
1
+ import {ReflectUtils} from '@dooboostore/core';
2
2
 
3
3
  export const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol('simple-web-component:on-attribute-changed');
4
4
 
@@ -34,28 +34,45 @@ function createClassListDecorator(action: ClassListAction) {
34
34
  const hostSet = SwcUtils.getHostSet(this as any);
35
35
  const targetEls: HTMLElement[] = [];
36
36
 
37
- if (selector === ':host' || !selector) {
38
- targetEls.push(this as any);
39
- } else if (selector === ':parentHost') {
40
- if (hostSet.$parentHost) targetEls.push(hostSet.$parentHost);
41
- } else if (selector === ':appHost') {
42
- if (hostSet.$appHost) targetEls.push(hostSet.$appHost);
43
- } else {
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 {
44
61
  if (r === 'shadow') {
45
62
  const found = this.shadowRoot?.querySelectorAll(selector);
46
- if (found) targetEls.push(...found);
63
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
47
64
  } else if (r === 'light') {
48
65
  const found = (this as any).querySelectorAll(selector);
49
- if (found) targetEls.push(...found);
66
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
50
67
  } else if (r === 'all') {
51
68
  const sFound = this.shadowRoot?.querySelectorAll(selector);
52
69
  const lFound = (this as any).querySelectorAll(selector);
53
- if (sFound) targetEls.push(...sFound);
54
- if (lFound) targetEls.push(...lFound);
70
+ if (sFound) targetEls.push(...(Array.from(sFound) as HTMLElement[]));
71
+ if (lFound) targetEls.push(...(Array.from(lFound) as HTMLElement[]));
55
72
  } else {
56
73
  // auto
57
74
  const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);
58
- if (found) targetEls.push(...found);
75
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
59
76
  }
60
77
  }
61
78
 
@@ -134,31 +151,76 @@ export const toggleClassList = (selector: string, options: SwcQueryOptions = {})
134
151
  * @setClassListHost decorator to set classes on :host element.
135
152
  * Returns: string | string[]
136
153
  */
137
- export const setClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('set')(':host', options);
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
+ }
138
164
 
139
165
  /**
140
166
  * @updateClassListHost decorator to update specific classes on :host.
141
167
  * Returns: Record<string, boolean> (toggle with force) | string | string[] (add)
142
168
  */
143
- export const updateClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('update')(':host', options);
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
+ }
144
179
 
145
180
  /**
146
181
  * @addClassListHost decorator to add classes to :host element.
147
182
  * Returns: string | string[]
148
183
  */
149
- export const addClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('add')(':host', options);
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
+ }
150
194
 
151
195
  /**
152
196
  * @removeClassListHost decorator to remove classes from :host element.
153
197
  * Returns: string | string[]
154
198
  */
155
- export const removeClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('remove')(':host', options);
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
+ }
156
209
 
157
210
  /**
158
211
  * @toggleClassListHost decorator to toggle classes on :host element.
159
212
  * Returns: string | string[]
160
213
  */
161
- export const toggleClassListHost = (options: SwcQueryOptions = {}) => createClassListDecorator('toggle')(':host', options);
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
+ }
162
224
 
163
225
  export const findAllClassListMetadata = (target: any): Map<string | symbol, ClassListMetadata> => {
164
226
  const result = new Map<string | symbol, ClassListMetadata>();