@dooboostore/simple-web-component 1.0.44 → 1.0.46

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 (95) hide show
  1. package/README.md +25 -25
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/applyAttribute.js +36 -15
  4. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  5. package/dist/cjs/decorators/applyClass.js +53 -22
  6. package/dist/cjs/decorators/applyClass.js.map +2 -2
  7. package/dist/cjs/decorators/applyNode.js +54 -24
  8. package/dist/cjs/decorators/applyNode.js.map +2 -2
  9. package/dist/cjs/decorators/applyProperty.js +38 -17
  10. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  11. package/dist/cjs/decorators/applyStyle.js +53 -22
  12. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  13. package/dist/cjs/decorators/elementDefine.js +49 -33
  14. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  15. package/dist/cjs/decorators/emitCustomEvent.js +61 -47
  16. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  17. package/dist/cjs/decorators/lifecycles.js +11 -36
  18. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  19. package/dist/cjs/decorators/query.js +91 -56
  20. package/dist/cjs/decorators/query.js.map +2 -2
  21. package/dist/cjs/decorators/queryAll.js +104 -66
  22. package/dist/cjs/decorators/queryAll.js.map +2 -2
  23. package/dist/cjs/elements/SwcAppMixin.js +6 -2
  24. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  25. package/dist/cjs/types/window.d.js.map +1 -1
  26. package/dist/esm/decorators/addEventListener.js.map +2 -2
  27. package/dist/esm/decorators/applyAttribute.js +36 -15
  28. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  29. package/dist/esm/decorators/applyClass.js +53 -22
  30. package/dist/esm/decorators/applyClass.js.map +2 -2
  31. package/dist/esm/decorators/applyNode.js +54 -24
  32. package/dist/esm/decorators/applyNode.js.map +2 -2
  33. package/dist/esm/decorators/applyProperty.js +38 -17
  34. package/dist/esm/decorators/applyProperty.js.map +2 -2
  35. package/dist/esm/decorators/applyStyle.js +53 -22
  36. package/dist/esm/decorators/applyStyle.js.map +2 -2
  37. package/dist/esm/decorators/elementDefine.js +50 -34
  38. package/dist/esm/decorators/elementDefine.js.map +2 -2
  39. package/dist/esm/decorators/emitCustomEvent.js +61 -47
  40. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  41. package/dist/esm/decorators/lifecycles.js +11 -36
  42. package/dist/esm/decorators/lifecycles.js.map +2 -2
  43. package/dist/esm/decorators/query.js +91 -56
  44. package/dist/esm/decorators/query.js.map +2 -2
  45. package/dist/esm/decorators/queryAll.js +104 -66
  46. package/dist/esm/decorators/queryAll.js.map +2 -2
  47. package/dist/esm/elements/SwcAppMixin.js +6 -2
  48. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  49. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +572 -320
  50. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +3 -3
  51. package/dist/types/decorators/addEventListener.d.ts +7 -6
  52. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  53. package/dist/types/decorators/applyAttribute.d.ts +13 -8
  54. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  55. package/dist/types/decorators/applyClass.d.ts +8 -7
  56. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  57. package/dist/types/decorators/applyNode.d.ts +18 -17
  58. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  59. package/dist/types/decorators/applyProperty.d.ts +14 -9
  60. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  61. package/dist/types/decorators/applyStyle.d.ts +6 -5
  62. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  63. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  64. package/dist/types/decorators/emitCustomEvent.d.ts +3 -2
  65. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  66. package/dist/types/decorators/lifecycles.d.ts +12 -13
  67. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  68. package/dist/types/decorators/query.d.ts +15 -5
  69. package/dist/types/decorators/query.d.ts.map +1 -1
  70. package/dist/types/decorators/queryAll.d.ts +15 -5
  71. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  72. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  73. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +572 -320
  74. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +3 -3
  75. package/package.json +3 -3
  76. package/src/decorators/addEventListener.ts +9 -7
  77. package/src/decorators/applyAttribute.ts +60 -27
  78. package/src/decorators/applyClass.ts +78 -32
  79. package/src/decorators/applyNode.ts +118 -73
  80. package/src/decorators/applyProperty.ts +63 -30
  81. package/src/decorators/applyStyle.ts +76 -30
  82. package/src/decorators/elementDefine.ts +57 -37
  83. package/src/decorators/emitCustomEvent.ts +63 -39
  84. package/src/decorators/lifecycles.ts +53 -52
  85. package/src/decorators/query.ts +111 -49
  86. package/src/decorators/queryAll.ts +121 -61
  87. package/src/elements/SwcAppMixin.ts +7 -3
  88. package/src/types/window.d.ts +3 -0
  89. package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
  90. package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
  91. package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
  92. package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
  93. package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
  94. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
  95. package/src/examples/RxJSOperatorsExample.ts +0 -279
@@ -34,9 +34,11 @@ export interface PropertyOptions extends SwcQueryOptions {
34
34
  valueKey?: symbol | string;
35
35
  }
36
36
 
37
+ export type PropertySelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);
38
+
37
39
  export interface PropertyMetadata {
38
40
  propertyKey: string | symbol;
39
- selector: string;
41
+ selector: PropertySelector;
40
42
  targetPropertyKey: string | symbol;
41
43
  options: PropertyOptions;
42
44
  type: 'property' | 'method';
@@ -50,15 +52,42 @@ export const PROPERTY_METADATA_KEY = Symbol.for('simple-web-component:property')
50
52
 
51
53
  /**
52
54
  * Resolve target elements based on selector and options
53
- * Handles special selectors ($this, $host, etc.) and CSS selectors
55
+ * Handles special selectors ($this, $host, etc.), CSS selectors, and function-based selectors
54
56
  * Returns HTMLElement[] but can include Window and Document for property access
55
57
  */
56
- export const resolvePropertyTargets = (inst: any, selector: string, options: PropertyOptions): any[] => {
58
+ export const resolvePropertyTargets = (inst: any, selector: PropertySelector, options: PropertyOptions): any[] => {
57
59
  const conf = getElementConfig(inst);
58
60
  const currentWin = conf.window;
59
61
  const r = options.root || 'auto';
60
62
  const results: any[] = [];
61
63
 
64
+ // Resolve selector if it's a function
65
+ let resolvedSelector: string | Element | NodeList | Element[] | null = selector as any;
66
+ if (typeof selector === 'function') {
67
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
68
+ resolvedSelector = selector(inst, hostSet);
69
+ }
70
+
71
+ // If selector function returned elements directly, use them
72
+ if (resolvedSelector instanceof currentWin.Element) {
73
+ results.push(resolvedSelector);
74
+ return results;
75
+ }
76
+ if (resolvedSelector instanceof currentWin.NodeList) {
77
+ results.push(...Array.from(resolvedSelector));
78
+ return results;
79
+ }
80
+ if (Array.isArray(resolvedSelector)) {
81
+ results.push(...resolvedSelector);
82
+ return results;
83
+ }
84
+ if (resolvedSelector === null) {
85
+ return results;
86
+ }
87
+
88
+ // Handle string selector
89
+ const stringSelector = resolvedSelector as string;
90
+
62
91
  const applyRoot = (target: any) => {
63
92
  if (!target) return;
64
93
  if (r === 'auto') {
@@ -69,37 +98,37 @@ export const resolvePropertyTargets = (inst: any, selector: string, options: Pro
69
98
  }
70
99
  };
71
100
 
72
- if (selector === '$this' || !selector) {
101
+ if (stringSelector === '$this' || !stringSelector) {
73
102
  applyRoot(inst);
74
- } else if (selector === '$window') {
103
+ } else if (stringSelector === '$window') {
75
104
  results.push(currentWin);
76
- } else if (selector === '$document') {
105
+ } else if (stringSelector === '$document') {
77
106
  results.push(currentWin.document);
78
107
  } else {
79
108
  const hostSet = SwcUtils.getHostSet(inst);
80
- if (selector === '$host') applyRoot(hostSet.$host);
81
- else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
82
- else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);
83
- else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
84
- else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
85
- else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
86
- else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
87
- else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
88
- else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
109
+ if (stringSelector === '$host') applyRoot(hostSet.$host);
110
+ else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);
111
+ else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost as any);
112
+ else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);
113
+ else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);
114
+ else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
115
+ else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
116
+ else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);
117
+ else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
89
118
  else {
90
119
  if (r === 'shadow') {
91
- const found = inst.shadowRoot?.querySelectorAll(selector);
120
+ const found = inst.shadowRoot?.querySelectorAll(stringSelector);
92
121
  if (found) results.push(...found);
93
122
  } else if (r === 'light') {
94
- const found = inst.querySelectorAll(selector);
123
+ const found = inst.querySelectorAll(stringSelector);
95
124
  if (found) results.push(...found);
96
125
  } else if (r === 'all') {
97
- const sMatch = inst.shadowRoot?.querySelectorAll(selector);
98
- const lMatch = inst.querySelectorAll(selector);
126
+ const sMatch = inst.shadowRoot?.querySelectorAll(stringSelector);
127
+ const lMatch = inst.querySelectorAll(stringSelector);
99
128
  if (sMatch) results.push(...sMatch);
100
129
  if (lMatch) results.push(...lMatch);
101
130
  } else {
102
- const found = (inst.shadowRoot || inst).querySelectorAll(selector);
131
+ const found = (inst.shadowRoot || inst).querySelectorAll(stringSelector);
103
132
  if (found) results.push(...found);
104
133
  }
105
134
  }
@@ -114,11 +143,12 @@ export const resolvePropertyTargets = (inst: any, selector: string, options: Pro
114
143
  * - @applyProperty('selector', 'propertyName') - Set property with explicit name
115
144
  * - @applyProperty('selector') - Use property name as target property name
116
145
  * - @applyProperty('selector', { name: 'propertyName' }) - Set property via options
146
+ * - @applyProperty((this, helper) => 'selector', 'propertyName') - Function-based selector
117
147
  * - Return null/undefined to skip setting
118
148
  */
119
- export function applyProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
120
- export function applyProperty(selector: string, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
121
- export function applyProperty(selector: string, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
149
+ export function applyProperty(selector: PropertySelector, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
150
+ export function applyProperty(selector: PropertySelector, options?: PropertyOptions): MethodDecorator & PropertyDecorator;
151
+ export function applyProperty(selector: PropertySelector, targetPropertyKeyOrOptions?: string | symbol | PropertyOptions, options?: PropertyOptions): MethodDecorator & PropertyDecorator {
122
152
  return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
123
153
  // ensureInit(target as any);
124
154
 
@@ -150,7 +180,7 @@ export function applyProperty(selector: string, targetPropertyKeyOrOptions?: str
150
180
  }
151
181
  metaList.push({
152
182
  propertyKey,
153
- selector,
183
+ selector: selector as PropertySelector,
154
184
  targetPropertyKey,
155
185
  options: finalOptions,
156
186
  type: metaType
@@ -266,14 +296,16 @@ export function applyProperty(selector: string, targetPropertyKeyOrOptions?: str
266
296
  * - @property('selector', 'propertyName') - Bind to specific property
267
297
  * - @property('selector') - Use field name as property name
268
298
  * - @property('selector', options) - Bind with options
299
+ * - @property((this, helper) => 'selector', 'propertyName') - Function-based selector
269
300
  * - @property - Bare decorator (binds to $this with field name)
270
301
  *
271
302
  * Note: This decorator is for FIELDS ONLY. For methods, use @setProperty.
272
303
  */
304
+ export function property(target: Object, propertyKey: string | symbol): void;
273
305
  export function property(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
274
- export function property(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): PropertyDecorator;
275
- export function property(selector: string, options?: PropertyOptions): PropertyDecorator;
276
- export function property(selectorOrTarget?: string | Object, targetPropertyKeyOrOptions?: any, optionsOrDescriptor?: any): any {
306
+ export function property(selector: PropertySelector, targetPropertyKey: string | symbol, options?: PropertyOptions): PropertyDecorator;
307
+ export function property(selector: PropertySelector, options?: PropertyOptions): PropertyDecorator;
308
+ export function property(selectorOrTarget?: PropertySelector | Object, targetPropertyKeyOrOptions?: any, optionsOrDescriptor?: any): any {
277
309
  // Bare decorator: @property
278
310
  if (optionsOrDescriptor !== undefined && (typeof targetPropertyKeyOrOptions === 'string' || typeof targetPropertyKeyOrOptions === 'symbol')) {
279
311
  return applyProperty('$this', undefined as any, {})(selectorOrTarget as Object, targetPropertyKeyOrOptions, optionsOrDescriptor as PropertyDescriptor);
@@ -293,6 +325,7 @@ export function property(selectorOrTarget?: string | Object, targetPropertyKeyOr
293
325
  * - @setProperty('selector', 'propertyName') - Set specific property
294
326
  * - @setProperty('selector') - Use method name as property name
295
327
  * - @setProperty('selector', options) - Set with options
328
+ * - @setProperty((this, helper) => 'selector', 'propertyName') - Function-based selector
296
329
  * - @setProperty - Bare decorator (sets on $this with method name)
297
330
  *
298
331
  * Note: This decorator is for METHODS ONLY. For fields, use @property.
@@ -303,9 +336,9 @@ export function property(selectorOrTarget?: string | Object, targetPropertyKeyOr
303
336
  * return true;
304
337
  * }
305
338
  */
306
- export function setProperty(selector: string, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
307
- export function setProperty(selector: string, options?: PropertyOptions): MethodDecorator;
308
- export function setProperty(selectorOrOptions?: string | PropertyOptions, targetPropertyKeyOrOptions?: any, optionsOrUndefined?: PropertyOptions): MethodDecorator {
339
+ export function setProperty(selector: PropertySelector, targetPropertyKey: string | symbol, options?: PropertyOptions): MethodDecorator;
340
+ export function setProperty(selector: PropertySelector, options?: PropertyOptions): MethodDecorator;
341
+ export function setProperty(selectorOrOptions?: PropertySelector | PropertyOptions, targetPropertyKeyOrOptions?: any, optionsOrUndefined?: PropertyOptions): MethodDecorator {
309
342
  // With selector
310
343
  if (typeof selectorOrOptions === 'string') {
311
344
  return applyProperty(selectorOrOptions, targetPropertyKeyOrOptions as any, optionsOrUndefined as PropertyOptions) as MethodDecorator;
@@ -15,17 +15,86 @@ export interface StyleApplyOptions extends SwcQueryOptions {
15
15
  valueKey?: symbol | string;
16
16
  }
17
17
 
18
+ export type StyleSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);
19
+
18
20
  export interface StyleApplyMetadata {
19
21
  propertyKey: string | symbol;
20
- selector: string;
22
+ selector: StyleSelector;
21
23
  action: StyleAction;
22
24
  options: StyleApplyOptions;
23
25
  }
24
26
 
25
27
  export const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');
26
28
 
29
+ /**
30
+ * Resolve selector to string or elements
31
+ * Handles function-based selectors and returns elements if applicable
32
+ */
33
+ const resolveSelector = (selector: StyleSelector, inst: any, win: Window): string | HTMLElement[] => {
34
+ if (typeof selector === 'function') {
35
+ const hostSet = SwcUtils.getHelperAndHostSet(win, inst);
36
+ const result = selector(inst, hostSet);
37
+
38
+ if (result instanceof win.Element) {
39
+ return [result as HTMLElement];
40
+ }
41
+ if (result instanceof win.NodeList) {
42
+ return Array.from(result) as HTMLElement[];
43
+ }
44
+ if (Array.isArray(result)) {
45
+ return result as HTMLElement[];
46
+ }
47
+ if (result === null) {
48
+ return [];
49
+ }
50
+ return result as string;
51
+ }
52
+ return selector as string;
53
+ };
54
+
55
+ /**
56
+ * Get target elements from selector
57
+ */
58
+ const getTargetElements = (selector: StyleSelector, inst: any, win: Window, root: string): HTMLElement[] => {
59
+ const resolved = resolveSelector(selector, inst, win);
60
+
61
+ if (Array.isArray(resolved)) {
62
+ return resolved;
63
+ }
64
+
65
+ const stringSelector = resolved as string;
66
+ const targetEls: HTMLElement[] = [];
67
+ const host = inst as unknown as HTMLElement;
68
+ const hostSet = SwcUtils.getHelperAndHostSet(win, inst);
69
+
70
+ const applyRoot = (t: any) => {
71
+ if (!t || !(t instanceof win.HTMLElement)) return;
72
+ targetEls.push(t);
73
+ };
74
+
75
+ if (stringSelector === '$this' || !stringSelector) applyRoot(host);
76
+ else if (stringSelector === '$host') applyRoot(hostSet.$host);
77
+ else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);
78
+ else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost);
79
+ else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);
80
+ else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);
81
+ else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
82
+ else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
83
+ else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);
84
+ else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
85
+ else {
86
+ const targetRoot = root === 'auto' ? (host.shadowRoot || host) : (root === 'shadow' ? host.shadowRoot : host);
87
+ if (targetRoot) {
88
+ const found = targetRoot.querySelectorAll(stringSelector);
89
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
90
+ }
91
+ }
92
+
93
+ return targetEls;
94
+ };
95
+
27
96
  function createStyleDecorator(action: StyleAction) {
28
- return (selector: string, options: StyleApplyOptions = {}): MethodDecorator => {
97
+ return (selector: StyleSelector, options: StyleApplyOptions = {}): MethodDecorator => {
29
98
  return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
30
99
  const constructor = target.constructor;
31
100
  let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleApplyMetadata>;
@@ -62,30 +131,7 @@ function createStyleDecorator(action: StyleAction) {
62
131
  const host = this as unknown as HTMLElement;
63
132
  const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
64
133
  const r = options.root || 'auto';
65
- const targetEls: HTMLElement[] = [];
66
-
67
- const applyRoot = (t: any) => {
68
- if (!t || !(t instanceof win.HTMLElement)) return;
69
- targetEls.push(t);
70
- };
71
-
72
- if (selector === '$this' || !selector) applyRoot(host);
73
- else if (selector === '$host') applyRoot(hostSet.$host);
74
- else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
75
- else if (selector === '$appHost') applyRoot(hostSet.$appHost);
76
- else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
77
- else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
78
- else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);
79
- else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);
80
- else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
81
- else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
82
- else {
83
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
84
- if (targetRoot) {
85
- const found = targetRoot.querySelectorAll(selector);
86
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
87
- }
88
- }
134
+ const targetEls = getTargetElements(selector, this, win, r);
89
135
 
90
136
  targetEls.forEach(targetEl => {
91
137
  if (options.filter && !options.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
@@ -138,7 +184,7 @@ function createStyleDecorator(action: StyleAction) {
138
184
  }
139
185
 
140
186
  export function applyStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
141
- export function applyStyle(selector: string, action?: StyleAction, options?: StyleApplyOptions): MethodDecorator;
187
+ export function applyStyle(selector: StyleSelector, action?: StyleAction, options?: StyleApplyOptions): MethodDecorator;
142
188
  export function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {
143
189
  // Bare decorator: @applyStyle
144
190
  if (optionsOrDescriptor !== undefined && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {
@@ -157,7 +203,7 @@ export function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, op
157
203
  }
158
204
 
159
205
  export function setStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
160
- export function setStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;
206
+ export function setStyle(selector: StyleSelector, options?: StyleApplyOptions): MethodDecorator;
161
207
  export function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
162
208
  // Bare decorator: @setStyle
163
209
  if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
@@ -172,7 +218,7 @@ export function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, des
172
218
  }
173
219
 
174
220
  export function updateStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
175
- export function updateStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;
221
+ export function updateStyle(selector: StyleSelector, options?: StyleApplyOptions): MethodDecorator;
176
222
  export function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
177
223
  // Bare decorator: @updateStyle
178
224
  if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
@@ -187,7 +233,7 @@ export function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any,
187
233
  }
188
234
 
189
235
  export function removeStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
190
- export function removeStyle(selector: string, options?: StyleApplyOptions): MethodDecorator;
236
+ export function removeStyle(selector: StyleSelector, options?: StyleApplyOptions): MethodDecorator;
191
237
  export function removeStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {
192
238
  // Bare decorator: @removeStyle
193
239
  if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {
@@ -1,6 +1,5 @@
1
- import {ActionExpression, FunctionUtils, ReflectUtils} from '@dooboostore/core';
2
- import {Observable, Subject} from '@dooboostore/core';
3
- import {debounceTime, throttleTime, distinctUntilChanged} from '@dooboostore/core/message/operators';
1
+ import {ActionExpression, FunctionUtils, ReflectUtils, Subject} from '@dooboostore/core';
2
+ import {debounceTime, distinctUntilChanged, throttleTime} from '@dooboostore/core/message/operators';
4
3
  import {getAddEventListenerMetadata} from './addEventListener';
5
4
  import {findAllLifecycleMetadata, findAllOnConnectedAfterMetadata, findAllOnConnectedBeforeMetadata, findAllOnConnectedMetadata, ON_AFTER_ADOPTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_CONNECTED_COMPLETED_METADATA_KEY, ON_INITIALIZE_METADATA_KEY} from './lifecycles';
6
5
  import {getEmitCustomEventMetadataList} from './emitCustomEvent';
@@ -12,9 +11,8 @@ import {SwcUtils} from '../utils/Utils';
12
11
  import {DOM_EVENT_NAMES, HTML_TAG_ENTRIES} from '../config/config';
13
12
  import {SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot/decorators/inject/Inject';
14
13
  import {HelperHostSet, HostSet, InjectSituationType} from '../types';
15
- import {ConvertUtils, ElementApply, NodeSlot} from '@dooboostore/core-web';
14
+ import {ConvertUtils, ElementApply} from '@dooboostore/core-web';
16
15
  import {isSSR} from "../elements/SwcAppMixin";
17
- import {findAllApplySlotMetadata} from "./applySlot";
18
16
  import {findAllStateMetadata} from "./state";
19
17
  import {findAllPropertyMetadata} from "./applyProperty";
20
18
 
@@ -385,14 +383,15 @@ export const elementDefine =
385
383
  const conf = getElementConfig(this);
386
384
  const currentWin = (this as any)._resolveWindow(conf);
387
385
 
388
- const bMethods = findAllOnConnectedBeforeMetadata(this).filter(it => useSsr ? !it.options.ssrFirst : true);
386
+ const bMethods = findAllOnConnectedBeforeMetadata(this);//.filter(it => useSsr ? !it.options.ssrFirst : true);
389
387
  // console.log('beforeConnected', bMethods)
390
388
  for (const m of bMethods) await (this as any)._invokeLifecycleMethod(m.propertyKey, helperHostSet);
391
389
  (this as any)._executeSwcScript('swc-on-before-connected', helperHostSet);
392
390
 
393
391
  // console.log('vvvvvvvvvvvvvvvu-seSsr-vvvvvvvvvv>', useSsr, this.tagName, this.getAttribute('seq'))
394
392
  // // ssr 처리라서 이미 내려준거그대로 상요하면된다 따라서 호출안한다
395
- const targetConnectedList = findAllOnConnectedMetadata(constructor).filter(it => useSsr ? !it.options.ssrFirst : true);
393
+ // const targetConnectedList = findAllOnConnectedMetadata(constructor).filter(it => useSsr ? !it.options.ssrFirst : true);
394
+ const targetConnectedList = useSsr ? [] : findAllOnConnectedMetadata(constructor);
396
395
  const shadowMode = conf?.useShadow || targetConnectedList.find(it => it.options.useShadow)?.options.useShadow;
397
396
  // console.log('--------->', this.tagName, shadowMode && !this.shadowRoot)
398
397
  if (shadowMode && !this.shadowRoot) {
@@ -467,7 +466,9 @@ export const elementDefine =
467
466
  const nonDelegateListeners: typeof addEventListenerList = [];
468
467
 
469
468
  addEventListenerList.forEach(meta => {
470
- if (meta.options.delegate && meta.selector !== '$window' && meta.selector !== '$document' && meta.selector !== '$host' && meta.selector !== '$appHost' && meta.selector !== '$firstHost' && meta.selector !== '$lastHost' && meta.selector !== '$firstAppHost' && meta.selector !== '$lastAppHost' && meta.selector !== '$hosts' && meta.selector !== '$appHosts' && meta.selector !== '$this' && meta.selector !== '') {
469
+ // Function-based selectors cannot be used with delegate listeners
470
+ const isStringSelector = typeof meta.selector === 'string';
471
+ if (meta.options.delegate && isStringSelector && meta.selector !== '$window' && meta.selector !== '$document' && meta.selector !== '$host' && meta.selector !== '$appHost' && meta.selector !== '$firstHost' && meta.selector !== '$lastHost' && meta.selector !== '$firstAppHost' && meta.selector !== '$lastAppHost' && meta.selector !== '$hosts' && meta.selector !== '$appHosts' && meta.selector !== '$this' && meta.selector !== '') {
471
472
  delegateListeners.push(meta);
472
473
  } else {
473
474
  nonDelegateListeners.push(meta);
@@ -508,7 +509,7 @@ export const elementDefine =
508
509
  const unifiedHandler = async (event: Event) => {
509
510
  for (const meta of sortedMetaList) {
510
511
  const {selector, options} = meta;
511
- const matchedEl = (event.target as HTMLElement).closest(selector);
512
+ const matchedEl = (event.target as HTMLElement)?.closest(selector);
512
513
  if (matchedEl && (br as any).contains(matchedEl)) {
513
514
  // Apply filter if specified
514
515
  if (options.filter) {
@@ -537,6 +538,25 @@ export const elementDefine =
537
538
  const opts = {capture: options.capture, once: options.once, passive: options.passive};
538
539
  const bindTargets: EventTarget[] = [];
539
540
  const r = options.root || 'auto';
541
+
542
+ // Resolve selector if it's a function
543
+ let resolvedSelector: string | null = null;
544
+ if (typeof selector === 'function') {
545
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
546
+ const result = selector(this, hostSet);
547
+ if (typeof result === 'string') {
548
+ resolvedSelector = result;
549
+ } else if (result instanceof currentWin.Element) {
550
+ bindTargets.push(result as EventTarget);
551
+ } else if (result instanceof currentWin.NodeList) {
552
+ bindTargets.push(...Array.from(result as EventTarget[]));
553
+ } else if (Array.isArray(result)) {
554
+ bindTargets.push(...(result as EventTarget[]));
555
+ }
556
+ } else {
557
+ resolvedSelector = selector;
558
+ }
559
+
540
560
  const applyRootOption = (target: any) => {
541
561
  if (!target) return;
542
562
  if (r === 'auto') {
@@ -547,31 +567,33 @@ export const elementDefine =
547
567
  }
548
568
  };
549
569
 
550
- if (selector === '$window') bindTargets.push(currentWin);
551
- else if (selector === '$document') bindTargets.push(currentWin.document);
552
- else if (selector === '$host') applyRootOption(helperHostSet.$host);
553
- else if (selector === '$parentHost') applyRootOption(helperHostSet.$parentHost);
554
- else if (selector === '$appHost') applyRootOption(helperHostSet.$appHost);
555
- else if (selector === '$firstHost') applyRootOption(helperHostSet.$firstHost);
556
- else if (selector === '$lastHost') applyRootOption(helperHostSet.$lastHost);
557
- else if (selector === '$firstAppHost') applyRootOption(helperHostSet.$firstAppHost);
558
- else if (selector === '$lastAppHost') applyRootOption(helperHostSet.$lastAppHost);
559
- else if (selector === '$hosts') helperHostSet.$hosts.forEach(applyRootOption);
560
- else if (selector === '$appHosts') helperHostSet.$appHosts.forEach(applyRootOption);
561
- else if (selector === '$this' || !selector) applyRootOption(this);
562
- else {
563
- const searchRoots: (HTMLElement | ShadowRoot)[] = [];
564
- if (r === 'auto') searchRoots.push(this.shadowRoot || (this as any));
565
- else if (r === 'light') searchRoots.push(this as any);
566
- else if (r === 'shadow' && this.shadowRoot) searchRoots.push(this.shadowRoot);
567
- else if (r === 'all') {
568
- searchRoots.push(this as any);
569
- if (this.shadowRoot) searchRoots.push(this.shadowRoot);
570
- }
570
+ if (resolvedSelector) {
571
+ if (resolvedSelector === '$window') bindTargets.push(currentWin);
572
+ else if (resolvedSelector === '$document') bindTargets.push(currentWin.document);
573
+ else if (resolvedSelector === '$host') applyRootOption(helperHostSet.$host);
574
+ else if (resolvedSelector === '$parentHost') applyRootOption(helperHostSet.$parentHost);
575
+ else if (resolvedSelector === '$appHost') applyRootOption(helperHostSet.$appHost);
576
+ else if (resolvedSelector === '$firstHost') applyRootOption(helperHostSet.$firstHost);
577
+ else if (resolvedSelector === '$lastHost') applyRootOption(helperHostSet.$lastHost);
578
+ else if (resolvedSelector === '$firstAppHost') applyRootOption(helperHostSet.$firstAppHost);
579
+ else if (resolvedSelector === '$lastAppHost') applyRootOption(helperHostSet.$lastAppHost);
580
+ else if (resolvedSelector === '$hosts') helperHostSet.$hosts.forEach(applyRootOption);
581
+ else if (resolvedSelector === '$appHosts') helperHostSet.$appHosts.forEach(applyRootOption);
582
+ else if (resolvedSelector === '$this' || !resolvedSelector) applyRootOption(this);
583
+ else {
584
+ const searchRoots: (HTMLElement | ShadowRoot)[] = [];
585
+ if (r === 'auto') searchRoots.push(this.shadowRoot || (this as any));
586
+ else if (r === 'light') searchRoots.push(this as any);
587
+ else if (r === 'shadow' && this.shadowRoot) searchRoots.push(this.shadowRoot);
588
+ else if (r === 'all') {
589
+ searchRoots.push(this as any);
590
+ if (this.shadowRoot) searchRoots.push(this.shadowRoot);
591
+ }
571
592
 
572
- searchRoots.forEach(sr => {
573
- sr.querySelectorAll(selector).forEach(el => bindTargets.push(el));
574
- });
593
+ searchRoots.forEach(sr => {
594
+ sr.querySelectorAll(resolvedSelector).forEach(el => bindTargets.push(el));
595
+ });
596
+ }
575
597
  }
576
598
 
577
599
  bindTargets.forEach(t => {
@@ -588,7 +610,7 @@ export const elementDefine =
588
610
  if (options.preventDefault) event.preventDefault();
589
611
  const currentHostSet = SwcUtils.getHostSet(this as any);
590
612
  const args = {event, ...currentHostSet, $el: t, $root: t};
591
- await (this as any)[meta.propertyKey](event, {currentHostSet, $$matchedElement: event.currentTarget}, args);
613
+ await (this as any)[meta.propertyKey](event, {currentHostSet, $matchedElement: event.currentTarget}, args);
592
614
  };
593
615
 
594
616
  // Create event stream with Observable-based operators
@@ -632,9 +654,7 @@ export const elementDefine =
632
654
 
633
655
  if (originalConnected) await (originalConnected.apply(this));
634
656
 
635
- const aMethods = findAllOnConnectedAfterMetadata(this).filter(it => {
636
- return useSsr ? !it.options.ssrFirst : true;
637
- });
657
+ const aMethods = findAllOnConnectedAfterMetadata(this); //.filter(it => { return useSsr ? !it.options.ssrFirst : true; });
638
658
  // console.log('afterConnected', this.tagName, aMethods, getOnConnectedAfterMetadata(this))
639
659
  for (const m of aMethods) await (this as any)._invokeLifecycleMethod(m.propertyKey, helperHostSet);
640
660
  (this as any)._executeSwcScript('swc-on-connected', helperHostSet);