@dooboostore/simple-web-component 1.0.38 → 1.0.40

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 (91) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +88 -871
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +194 -111
  5. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  6. package/dist/cjs/decorators/applyNode.js +82 -80
  7. package/dist/cjs/decorators/applyNode.js.map +2 -2
  8. package/dist/cjs/decorators/applyProperty.js +213 -0
  9. package/dist/cjs/decorators/applyProperty.js.map +7 -0
  10. package/dist/cjs/decorators/applySlot.js +93 -82
  11. package/dist/cjs/decorators/applySlot.js.map +3 -3
  12. package/dist/cjs/decorators/changedAttributeThis.js.map +1 -1
  13. package/dist/cjs/decorators/elementDefine.js +14 -34
  14. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  15. package/dist/cjs/decorators/index.js +2 -2
  16. package/dist/cjs/decorators/index.js.map +2 -2
  17. package/dist/cjs/decorators/lifecycles.js +4 -4
  18. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  19. package/dist/cjs/decorators/state.js +0 -1
  20. package/dist/cjs/decorators/state.js.map +2 -2
  21. package/dist/cjs/elements/SwcApp.js.map +2 -2
  22. package/dist/cjs/types/index.js.map +1 -1
  23. package/dist/esm/SwcAppEngine.js.map +2 -2
  24. package/dist/esm/decorators/applyAttribute.js +196 -113
  25. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  26. package/dist/esm/decorators/applyNode.js +82 -80
  27. package/dist/esm/decorators/applyNode.js.map +2 -2
  28. package/dist/esm/decorators/applyProperty.js +194 -0
  29. package/dist/esm/decorators/applyProperty.js.map +7 -0
  30. package/dist/esm/decorators/applySlot.js +93 -82
  31. package/dist/esm/decorators/applySlot.js.map +3 -3
  32. package/dist/esm/decorators/changedAttributeThis.js.map +1 -1
  33. package/dist/esm/decorators/elementDefine.js +14 -34
  34. package/dist/esm/decorators/elementDefine.js.map +2 -2
  35. package/dist/esm/decorators/index.js +2 -2
  36. package/dist/esm/decorators/index.js.map +1 -1
  37. package/dist/esm/decorators/lifecycles.js +4 -4
  38. package/dist/esm/decorators/lifecycles.js.map +2 -2
  39. package/dist/esm/decorators/state.js +0 -1
  40. package/dist/esm/decorators/state.js.map +2 -2
  41. package/dist/esm/elements/SwcApp.js.map +2 -2
  42. package/dist/esm/types/index.js.map +1 -1
  43. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +525 -513
  44. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  45. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  46. package/dist/types/decorators/applyAttribute.d.ts +56 -15
  47. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  48. package/dist/types/decorators/applyNode.d.ts +28 -24
  49. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  50. package/dist/types/decorators/applyProperty.d.ts +61 -0
  51. package/dist/types/decorators/applyProperty.d.ts.map +1 -0
  52. package/dist/types/decorators/applySlot.d.ts +17 -15
  53. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  54. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  55. package/dist/types/decorators/index.d.ts +2 -2
  56. package/dist/types/decorators/index.d.ts.map +1 -1
  57. package/dist/types/decorators/lifecycles.d.ts +4 -4
  58. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  59. package/dist/types/decorators/state.d.ts.map +1 -1
  60. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  61. package/dist/types/types/index.d.ts +1 -6
  62. package/dist/types/types/index.d.ts.map +1 -1
  63. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +525 -513
  64. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  65. package/package.json +1 -1
  66. package/src/SwcAppEngine.ts +1 -0
  67. package/src/decorators/applyAttribute.ts +311 -126
  68. package/src/decorators/applyNode.ts +108 -105
  69. package/src/decorators/applyProperty.ts +302 -0
  70. package/src/decorators/applySlot.ts +112 -94
  71. package/src/decorators/changedAttributeThis.ts +1 -1
  72. package/src/decorators/elementDefine.ts +44 -33
  73. package/src/decorators/index.ts +2 -3
  74. package/src/decorators/lifecycles.ts +6 -6
  75. package/src/decorators/state.ts +0 -1
  76. package/src/elements/SwcApp.ts +0 -1
  77. package/src/types/index.ts +7 -7
  78. package/dist/cjs/decorators/attribute.js +0 -187
  79. package/dist/cjs/decorators/attribute.js.map +0 -7
  80. package/dist/cjs/decorators/setProperty.js +0 -109
  81. package/dist/cjs/decorators/setProperty.js.map +0 -7
  82. package/dist/esm/decorators/attribute.js +0 -168
  83. package/dist/esm/decorators/attribute.js.map +0 -7
  84. package/dist/esm/decorators/setProperty.js +0 -90
  85. package/dist/esm/decorators/setProperty.js.map +0 -7
  86. package/dist/types/decorators/attribute.d.ts +0 -31
  87. package/dist/types/decorators/attribute.d.ts.map +0 -1
  88. package/dist/types/decorators/setProperty.d.ts +0 -17
  89. package/dist/types/decorators/setProperty.d.ts.map +0 -1
  90. package/src/decorators/attribute.ts +0 -223
  91. package/src/decorators/setProperty.ts +0 -112
@@ -37,69 +37,60 @@ export interface ApplyNodeMetadata {
37
37
 
38
38
  export const APPLY_NODE_METADATA_KEY = Symbol.for('simple-web-component:apply-node');
39
39
 
40
- const normalizeNodes = (res: any, doc: Document): Node[] => {
41
- const items = Array.isArray(res) ? res : [res];
42
- return items.map(it => {
43
- if (it instanceof Node) return it;
44
- return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
45
- });
46
- };
47
-
48
- const applyToDom = (currentThis: any, targetEl: HTMLElement, res: any, pos: ApplyNodePosition, win: Window, host?: any) => {
40
+ // const normalizeNodes = (res: any, doc: Document): Node[] => {
41
+ // const items = Array.isArray(res) ? res : [res];
42
+ // return items.map(it => {
43
+ // if (it instanceof Node) return it;
44
+ // return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');
45
+ // });
46
+ // };
47
+
48
+ const applyToDom = (currentThis: any, targetEl: HTMLElement, res: Node | string, pos: ApplyNodePosition, win: Window, host?: any) => {
49
49
  if (!targetEl) return;
50
-
51
- // console.log('------------',currentThis.tagName, res)
52
50
  const doc = win.document;
53
51
  const hostSet = SwcUtils.getHelperAndHostSet(win, currentThis);
54
52
  const id = currentThis._swcId;
55
- // Allow processHtml to run here so all DOM insertions go through a single
56
- // processing point. processHtml may mutate Node[] in-place or return a
57
- // transformed string result for text processing.
58
- try {
59
- if (typeof res === 'string') {
60
- const processed = SwcUtils.projectProcessHtml(id, res as string, doc);
61
- if (processed !== undefined) res = processed;
62
- } else if (res) {
63
- SwcUtils.projectProcessHtml(id, res, doc);
64
- }
65
- } catch (e) {
66
- // swallow and proceed with original res
67
- }
68
53
 
69
- if (pos === 'innerHtml') {
70
- targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
71
- return;
72
- }
73
54
 
74
- if (pos === 'innerText') {
75
- if (targetEl.innerText !== undefined) {
76
- targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
77
- }
78
- return;
55
+ const nodes: Node[] = [];
56
+
57
+ if (typeof res === 'string' && pos === 'innerHtml') {
58
+ const t = win.document.createElement('template');
59
+ t.innerHTML = res;
60
+ nodes.push(...Array.from(t.content.childNodes));
61
+ } else if (typeof res === 'string' && pos === 'innerText') {
62
+ nodes.push(win.document.createTextNode(res));
79
63
  }
80
64
 
81
- const stateContext: any = {...hostSet};
82
- findAllStateMetadata(currentThis).forEach(it => {
83
- stateContext[it.name] = currentThis[it.propertyKey]
84
- })
85
- new ElementApply(currentThis, {id: currentThis._swcId}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
65
+ SwcUtils.projectProcessHtml(id, nodes, doc);
66
+
86
67
 
87
68
 
88
69
  const isShadowRoot = targetEl instanceof win.ShadowRoot;
89
- const nodes = normalizeNodes(res, doc);
70
+ // const nodes = normalizeNodes(res, doc);
90
71
  if (pos === 'replace') {
91
72
  if (!isShadowRoot) targetEl.replaceWith(...nodes);
73
+ } else if (pos === 'innerHtml') {
74
+ targetEl.replaceChildren(...nodes);
75
+ } else if (pos === 'innerText') {
76
+ targetEl.replaceChildren(...nodes);
92
77
  } else if (pos === 'replaceChildren') {
93
78
  targetEl.replaceChildren(...nodes);
94
79
  } else {
95
80
  if (pos === 'beforeEnd') {
96
- console.log('tarbbbbbbbbbbbbbb')
97
81
  targetEl.append(...nodes)
98
82
  }
99
83
  else if (pos === 'afterBegin') targetEl.prepend(...nodes);
100
84
  else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
101
85
  else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
102
86
  }
87
+
88
+ const stateContext: any = {...hostSet};
89
+ findAllStateMetadata(currentThis).forEach(it => {
90
+ stateContext[it.name] = currentThis[it.propertyKey]
91
+ })
92
+ new ElementApply(targetEl, {id: id}).apply({target: 'noInitialized', context: stateContext, bind: currentThis});
93
+ return nodes;
103
94
  };
104
95
 
105
96
  /**
@@ -146,8 +137,6 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
146
137
  return targetRoot ? targetRoot.querySelector(selector) : null;
147
138
  };
148
139
 
149
-
150
- console.log('fffffffffff')
151
140
  const targetEl = getTarget();
152
141
  const res = original.apply(this, args);
153
142
 
@@ -164,16 +153,17 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
164
153
  }
165
154
  };
166
155
 
167
- if (res instanceof Promise) {
168
- // 비동기일 때만 로딩 표시
169
- if (targetEl && options.fallback) {
170
- const loadingRes = options.fallback.call(this, hostSet);
171
- // applyToDom expects a Window as the 4th argument
172
- applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin);
173
- }
174
156
 
157
+ const fallbackNodes: Node[] = [];
158
+ if (targetEl && options.fallback) {
159
+ const loadingRes = options.fallback.call(this, hostSet);
160
+ // applyToDom expects a Window as the 4th argument
161
+ fallbackNodes.push(...applyToDom(this, targetEl, loadingRes, options.position || 'beforeEnd', currentWin));
162
+ }
163
+
164
+ if (res instanceof Promise) {
175
165
  return res.then(finalRes => {
176
- console.log('amnkj')
166
+ fallbackNodes.forEach((it: any)=>it.remove());
177
167
  if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
178
168
  return finalRes;
179
169
  });
@@ -185,17 +175,6 @@ export function applyNode(selector: string, options: ApplyNodeOptions = {positio
185
175
  };
186
176
  }
187
177
 
188
- export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {
189
- const result = new Map<string | symbol, ApplyNodeMetadata>();
190
- const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);
191
- maps.forEach(map => {
192
- if (map instanceof Map) {
193
- map.forEach((v, k) => result.set(k, v));
194
- }
195
- });
196
- return result;
197
- };
198
-
199
178
  export function applyNodeThis(options: ApplyNodeOptions): MethodDecorator;
200
179
  export function applyNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
201
180
  export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
@@ -205,111 +184,135 @@ export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symb
205
184
  return applyNode('$this', {...option, ...opt});
206
185
  }
207
186
 
208
- export function applyNodeThisReplaceChildren(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
209
- export function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
210
- export function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
187
+ export function replaceChildrenNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
188
+ export function replaceChildrenNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
189
+ export function replaceChildrenNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
211
190
  const option: ApplyNodeOptions = {position: 'replaceChildren'};
212
191
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
213
192
  const opt = targetOrOptions || {};
214
193
  return applyNode('$this', {...opt, ...option});
215
194
  }
216
195
 
217
- export function applyNodeThisReplaceChildrenLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
218
- export function applyNodeThisReplaceChildrenLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
219
- export function applyNodeThisReplaceChildrenLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
220
- const options: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
221
- if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
222
- const opt = targetOrOptions || {};
223
- return applyNode('$this', {...opt, ...options});
224
- }
225
196
 
226
- export function applyNodeThisBeforeEnd(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
227
- export function applyNodeThisBeforeEnd(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
228
- export function applyNodeThisBeforeEnd(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
197
+
198
+ export function beforeEndNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
199
+ export function beforeEndNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
200
+ export function beforeEndNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
229
201
  const options: ApplyNodeOptions = {position: 'beforeEnd'};
230
202
  if (propertyKey !== undefined) return applyNode('$this', options)(targetOrOptions, propertyKey, descriptor);
231
203
  const opt = targetOrOptions || {};
232
204
  return applyNode('$this', {...opt, ...options});
233
205
  }
234
206
 
235
- export function applyNodeThisBeforeEndLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
236
- export function applyNodeThisBeforeEndLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
237
- export function applyNodeThisBeforeEndLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
207
+ export function beforeEndLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
208
+ export function beforeEndLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
209
+ export function beforeEndLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
238
210
  const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'light'}
239
211
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
240
212
  const opt = targetOrOptions || {};
241
213
  return applyNode('$this', {...opt, ...option});
242
214
  }
243
- export function applyNodeThisBeforeEndShadow(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
244
- export function applyNodeThisBeforeEndShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
245
- export function applyNodeThisBeforeEndShadow(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
215
+
216
+ export function beforeEndShadowNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
217
+ export function beforeEndShadowNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
218
+ export function beforeEndShadowNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
246
219
  const option: ApplyNodeOptions = {position: 'beforeEnd', root: 'shadow'}
247
220
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
248
221
  const opt = targetOrOptions || {};
249
222
  return applyNode('$this', {...opt, ...option});
250
223
  }
251
224
 
252
- export function applyNodeThisAfterBegin(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
253
- export function applyNodeThisAfterBegin(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
254
- export function applyNodeThisAfterBegin(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
225
+ export function afterBeginNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
226
+ export function afterBeginNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
227
+ export function afterBeginNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
255
228
  const option: ApplyNodeOptions = {position: 'afterBegin'};
256
229
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
257
230
  const opt = targetOrOptions || {};
258
231
  return applyNode('$this', {...opt, ...option});
259
232
  }
260
233
 
261
- export function applyNodeThisAfterBeginLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
262
- export function applyNodeThisAfterBeginLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
263
- export function applyNodeThisAfterBeginLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
234
+ export function afterBeginLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
235
+ export function afterBeginLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
236
+ export function afterBeginLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
264
237
  const option: ApplyNodeOptions = {position: 'afterBegin', root: 'light'}
265
238
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
266
239
  const opt = targetOrOptions || {};
267
240
  return applyNode('$this', {...opt, ...option});
268
241
  }
269
242
 
270
- export function applyThisInnerHtmlNode(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
271
- export function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
272
- export function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
243
+ export function innerHtmlNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
244
+ export function innerHtmlNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
245
+ export function innerHtmlNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
273
246
  const option: ApplyNodeOptions = {position: 'innerHtml'}
274
247
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
275
248
  const opt = targetOrOptions || {};
276
249
  return applyNode('$this', {...opt, ...option});
277
250
  }
278
251
 
279
- export function applyThisInnerHtmlNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
280
- export function applyThisInnerHtmlNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
281
- export function applyThisInnerHtmlNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
252
+ export function innerTextNodeThis(options: Omit<ApplyNodeOptions, 'position'>): MethodDecorator;
253
+ export function innerTextNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
254
+ export function innerTextNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
255
+ const option: ApplyNodeOptions = {position: 'innerText'}
256
+ if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
257
+ const opt = targetOrOptions || {};
258
+ return applyNode('$this', {...opt, ...option});
259
+ }
260
+
261
+ export function innerHtmlLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
262
+ export function innerHtmlLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
263
+ export function innerHtmlLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
282
264
  const option: ApplyNodeOptions = {position: 'innerHtml', root: 'light'};
283
265
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
284
266
  const opt = targetOrOptions || {};
285
267
  return applyNode('$this', {...opt, ...option});
286
268
  }
287
269
 
288
- export function applyThisReplaceChildrenNodeLightDom(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
289
- export function applyThisReplaceChildrenNodeLightDom(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
290
- export function applyThisReplaceChildrenNodeLightDom(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
270
+ export function replaceChildrenLightNodeThis(options: Omit<ApplyNodeOptions, 'position' | 'root'>): MethodDecorator;
271
+ export function replaceChildrenLightNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
272
+ export function replaceChildrenLightNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
291
273
  const option: ApplyNodeOptions = {position: 'replaceChildren', root: 'light'};
292
274
  if (propertyKey !== undefined) return applyNode('$this', option)(targetOrOptions, propertyKey, descriptor);
293
275
  const opt = targetOrOptions || {};
294
276
  return applyNode('$this', {...opt, ...option});
295
277
  }
296
278
 
297
- export function applyNodeReplaceChildren(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
279
+ export function replaceChildrenNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
298
280
  return applyNode(selector, {...options, position: 'replaceChildren'});
299
281
  }
300
282
 
301
- export function applyNodeInnerHtml(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
283
+ export function innerHtmlNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
302
284
  return applyNode(selector, {...options, position: 'innerHtml'});
303
285
  }
304
286
 
305
- // export function applyNodeInnerHtmlLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
306
- // return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});
307
- // }
287
+ export function innerHtmlLightNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
288
+ return applyNode(selector, {...options, position: 'innerHtml', root: 'light'});
289
+ }
308
290
 
309
- export function applyNodeInnerText(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
291
+ export function innerHtmlShadowNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
292
+ return applyNode(selector, {...options, position: 'innerHtml', root: 'shadow'});
293
+ }
294
+
295
+ export function innerTextNode(selector: string, options: Omit<ApplyNodeOptions, 'position'> = {}): MethodDecorator {
310
296
  return applyNode(selector, {...options, position: 'innerText'});
311
297
  }
312
298
 
313
- // export function applyNodeInnerTextLightDom(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
314
- // return applyNode(selector, {...options, position: 'innerText', root: 'light'});
315
- // }
299
+ export function innerTextLightNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
300
+ return applyNode(selector, {...options, position: 'innerText', root: 'light'});
301
+ }
302
+
303
+ export function innerTextShadowNode(selector: string, options: Omit<ApplyNodeOptions, 'position' | 'root'> = {}): MethodDecorator {
304
+ return applyNode(selector, {...options, position: 'innerText', root: 'shadow'});
305
+ }
306
+
307
+
308
+
309
+ export const findAllApplyNodeMetadata = (target: any): Map<string | symbol, ApplyNodeMetadata> => {
310
+ const result = new Map<string | symbol, ApplyNodeMetadata>();
311
+ const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ApplyNodeMetadata>>(APPLY_NODE_METADATA_KEY, target);
312
+ maps.forEach(map => {
313
+ if (map instanceof Map) {
314
+ map.forEach((v, k) => result.set(k, v));
315
+ }
316
+ });
317
+ return result;
318
+ };
@@ -0,0 +1,302 @@
1
+ import { ReflectUtils } from '@dooboostore/core';
2
+ import { ensureInit, getElementConfig } from './elementDefine';
3
+ import { SwcUtils } from '../utils/Utils';
4
+ import { SwcQueryOptions, HelperHostSet } from '../types';
5
+
6
+ export interface PropertyOptions extends SwcQueryOptions {
7
+ name?: string | symbol;
8
+ filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
9
+ }
10
+
11
+ export interface PropertyMetadata {
12
+ propertyKey: string | symbol;
13
+ selector: string;
14
+ targetPropertyKey: string | symbol;
15
+ options: PropertyOptions;
16
+ type: 'property' | 'method';
17
+ }
18
+
19
+ export const PROPERTY_METADATA_KEY = Symbol.for('simple-web-component:property');
20
+
21
+ // ============================================
22
+ // Utilities
23
+ // ============================================
24
+
25
+ /**
26
+ * Resolve target elements based on selector and options
27
+ * Handles special selectors ($this, $host, etc.) and CSS selectors
28
+ * Returns HTMLElement[] but can include Window and Document for property access
29
+ */
30
+ export const resolvePropertyTargets = (inst: any, selector: string, options: PropertyOptions): any[] => {
31
+ const conf = getElementConfig(inst);
32
+ const currentWin = conf.window;
33
+ const r = options.root || 'auto';
34
+ const results: any[] = [];
35
+
36
+ const applyRoot = (target: any) => {
37
+ if (!target) return;
38
+ if (r === 'auto') {
39
+ results.push(target);
40
+ } else {
41
+ if (r === 'light' || r === 'all') results.push(target);
42
+ if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);
43
+ }
44
+ };
45
+
46
+ if (selector === '$this' || !selector) {
47
+ applyRoot(inst);
48
+ } else if (selector === '$window') {
49
+ results.push(currentWin);
50
+ } else if (selector === '$document') {
51
+ results.push(currentWin.document);
52
+ } else {
53
+ const hostSet = SwcUtils.getHostSet(inst);
54
+ if (selector === '$host') applyRoot(hostSet.$host);
55
+ else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
56
+ else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);
57
+ else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
58
+ else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
59
+ else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
60
+ else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
61
+ else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
62
+ else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
63
+ else {
64
+ if (r === 'shadow') {
65
+ const found = inst.shadowRoot?.querySelectorAll(selector);
66
+ if (found) results.push(...found);
67
+ } else if (r === 'light') {
68
+ const found = inst.querySelectorAll(selector);
69
+ if (found) results.push(...found);
70
+ } else if (r === 'all') {
71
+ const sMatch = inst.shadowRoot?.querySelectorAll(selector);
72
+ const lMatch = inst.querySelectorAll(selector);
73
+ if (sMatch) results.push(...sMatch);
74
+ if (lMatch) results.push(...lMatch);
75
+ } else {
76
+ const found = (inst.shadowRoot || inst).querySelectorAll(selector);
77
+ if (found) results.push(...found);
78
+ }
79
+ }
80
+ }
81
+ return results;
82
+ };
83
+
84
+ /**
85
+ * @applyProperty decorator - set/get element properties
86
+ *
87
+ * Usage:
88
+ * - @applyProperty('selector', 'propertyName') - Set property with explicit name
89
+ * - @applyProperty('selector') - Use property name as target property name
90
+ * - @applyProperty('selector', { name: 'propertyName' }) - Set property via options
91
+ * - Return null/undefined to skip setting
92
+ */
93
+ export function applyProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
94
+ export function applyProperty(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
95
+ export function applyProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
96
+ return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
97
+ // ensureInit(target as any);
98
+
99
+ const constructor = target.constructor;
100
+ const metaType: 'property' | 'method' = descriptor && typeof descriptor.value === 'function' ? 'method' : 'property';
101
+
102
+ // Parse arguments
103
+ let finalOptions: PropertyOptions = {};
104
+ let targetPropertyKey: string | symbol;
105
+
106
+ if (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol') {
107
+ // applyProperty('selector', 'propertyName', options?)
108
+ targetPropertyKey = targetPropertyKeyOrOptions;
109
+ finalOptions = options || {};
110
+ } else if (targetPropertyKeyOrOptions) {
111
+ // applyProperty('selector', options)
112
+ finalOptions = targetPropertyKeyOrOptions;
113
+ targetPropertyKey = finalOptions.name || propertyKey;
114
+ } else {
115
+ // applyProperty('selector')
116
+ targetPropertyKey = propertyKey;
117
+ }
118
+
119
+ // Store metadata
120
+ let metaList = ReflectUtils.getOwnMetadata(PROPERTY_METADATA_KEY, constructor) as PropertyMetadata[];
121
+ if (!metaList) {
122
+ metaList = [];
123
+ ReflectUtils.defineMetadata(PROPERTY_METADATA_KEY, metaList, constructor);
124
+ }
125
+ metaList.push({
126
+ propertyKey,
127
+ selector,
128
+ targetPropertyKey,
129
+ options: finalOptions,
130
+ type: metaType
131
+ });
132
+
133
+ // Helper: apply resolved value to targets
134
+ const applyValueToTargets = (inst: any, resolvedValue: any) => {
135
+ if (resolvedValue === undefined) return resolvedValue;
136
+
137
+ const targetEls = resolvePropertyTargets(inst, selector, finalOptions);
138
+ const conf = getElementConfig(inst);
139
+ const currentWin = conf.window;
140
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
141
+
142
+ targetEls.forEach(targetEl => {
143
+ // Apply filter if provided
144
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: inst, helper: hostSet })) {
145
+ return;
146
+ }
147
+
148
+ const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
149
+ (targetEl as any)[targetPropertyKey] = resolvedRes;
150
+ });
151
+
152
+ return resolvedValue;
153
+ };
154
+
155
+ // Method decorator: wrap method to apply its return value to properties
156
+ if (descriptor && typeof descriptor.value === 'function') {
157
+ const original = descriptor.value;
158
+ descriptor.value = function (...args: any[]) {
159
+ ensureInit(this);
160
+ const res = (original as any).apply(this, args);
161
+
162
+ if (res instanceof Promise) {
163
+ return res.then((v: any) => { applyValueToTargets(this, v); return v; });
164
+ } else {
165
+ applyValueToTargets(this, res);
166
+ return res;
167
+ }
168
+ };
169
+ return;
170
+ }
171
+
172
+ // Property decorator: define getter/setter to proxy to element properties
173
+ Object.defineProperty(target, propertyKey, {
174
+ configurable: true,
175
+ enumerable: true,
176
+ get(this: any) {
177
+ ensureInit(this);
178
+ // Read from matched elements
179
+ const targetEls = resolvePropertyTargets(this, selector, finalOptions);
180
+ const conf = getElementConfig(this);
181
+ const currentWin = conf.window;
182
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
183
+
184
+ // Apply filter
185
+ const filtered = targetEls.filter(el => {
186
+ if (finalOptions.filter && !finalOptions.filter(el, (el as any)[targetPropertyKey], { currentThis: this, helper: hostSet })) {
187
+ return false;
188
+ }
189
+ return true;
190
+ });
191
+
192
+ const values = filtered.map(el => (el as any)[targetPropertyKey]);
193
+ return values.length === 1 ? values[0] : values;
194
+ },
195
+ set(this: any, value: any) {
196
+ ensureInit(this);
197
+ applyValueToTargets(this, value);
198
+ }
199
+ });
200
+ };
201
+ }
202
+
203
+ // ============================================
204
+ // Convenience Aliases
205
+ // ============================================
206
+
207
+ /**
208
+ * @property - Alias for @applyProperty
209
+ */
210
+ export function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
211
+ export function property(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
212
+ export function property(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
213
+ return applyProperty(selector, targetPropertyKeyOrOptions as any, options);
214
+ }
215
+
216
+ /**
217
+ * @propertyThis - Apply property on $this element
218
+ * Can be used as: @propertyThis or @propertyThis('propertyName') or @propertyThis({ name: 'propertyName' })
219
+ */
220
+ export function propertyThis(target: Object, propertyKey: string | symbol): void;
221
+ export function propertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
222
+ export function propertyThis(options?: PropertyOptions): MethodDecorator & PropertyDecorator;
223
+ export function propertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
224
+ // Direct decorator usage: @propertyThis
225
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
226
+ (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
227
+ // Called as @propertyThis (target, propertyKey)
228
+ return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
229
+ }
230
+
231
+ // Called with parameters
232
+ if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {
233
+ // @propertyThis('propertyName', options?)
234
+ return applyProperty('$this', targetOrOptions, propertyKeyOrOptions);
235
+ } else if (targetOrOptions && typeof targetOrOptions === 'object') {
236
+ // @propertyThis({ name: 'propertyName' })
237
+ return applyProperty('$this', undefined as any, targetOrOptions);
238
+ } else {
239
+ // @propertyThis() or @propertyThis
240
+ return applyProperty('$this', undefined as any, {});
241
+ }
242
+ }
243
+
244
+ /**
245
+ * @setProperty - Alias for @applyProperty (method-decorator semantics)
246
+ */
247
+ export function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
248
+ export function setProperty(selector: string, options?: PropertyOptions): MethodDecorator;
249
+ export function setProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator {
250
+ return applyProperty(selector, targetPropertyKeyOrOptions as any, options) as MethodDecorator;
251
+ }
252
+
253
+ /**
254
+ * @setPropertyThis - Set property on $this element
255
+ * Can be used as: @setPropertyThis or @setPropertyThis('propertyName') or @setPropertyThis({ name: 'propertyName' })
256
+ */
257
+ export function setPropertyThis(target: Object, propertyKey: string | symbol): void;
258
+ export function setPropertyThis(targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
259
+ export function setPropertyThis(options?: PropertyOptions): MethodDecorator;
260
+ export function setPropertyThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
261
+ // Direct decorator usage: @setPropertyThis
262
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
263
+ (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
264
+ // Called as @setPropertyThis (target, propertyKey)
265
+ return applyProperty('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
266
+ }
267
+
268
+ // Called with parameters
269
+ if (typeof targetOrOptions === 'string' || typeof targetOrOptions === 'symbol') {
270
+ // @setPropertyThis('propertyName', options?)
271
+ return applyProperty('$this', targetOrOptions, propertyKeyOrOptions) as MethodDecorator;
272
+ } else if (targetOrOptions && typeof targetOrOptions === 'object') {
273
+ // @setPropertyThis({ name: 'propertyName' })
274
+ return applyProperty('$this', undefined as any, targetOrOptions) as MethodDecorator;
275
+ } else {
276
+ // @setPropertyThis() or @setPropertyThis
277
+ return applyProperty('$this', undefined as any, {}) as MethodDecorator;
278
+ }
279
+ }
280
+
281
+
282
+
283
+ // ============================================
284
+ // Metadata Helpers
285
+ // ============================================
286
+
287
+ export const findAllPropertyMetadata = (target: any): PropertyMetadata[] => {
288
+ const actualTarget = target instanceof Function ? target : target.constructor;
289
+ return ReflectUtils.findAllMetadata<PropertyMetadata[]>(PROPERTY_METADATA_KEY, actualTarget).flat();
290
+ };
291
+
292
+ // Backward compatibility alias
293
+ export const findAllPropertyApplyMetadata = (target: any): Map<string | symbol, PropertyMetadata> => {
294
+ const result = new Map<string | symbol, PropertyMetadata>();
295
+ findAllPropertyMetadata(target).forEach(meta => {
296
+ result.set(meta.propertyKey, meta);
297
+ });
298
+ return result;
299
+ };
300
+
301
+
302
+ export default applyProperty;