@dooboostore/simple-web-component 1.0.33 → 1.0.35

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 (150) hide show
  1. package/README.md +23 -30
  2. package/dist/cjs/decorators/addEventListener.js.map +1 -1
  3. package/dist/cjs/decorators/applyAttribute.js +67 -57
  4. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  5. package/dist/cjs/decorators/applyClass.js +80 -70
  6. package/dist/cjs/decorators/applyClass.js.map +2 -2
  7. package/dist/cjs/decorators/applyNode.js +5 -8
  8. package/dist/cjs/decorators/applyNode.js.map +2 -2
  9. package/dist/cjs/decorators/applyStyle.js +66 -56
  10. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  11. package/dist/cjs/decorators/attribute.js +35 -29
  12. package/dist/cjs/decorators/attribute.js.map +2 -2
  13. package/dist/cjs/decorators/changedAttributeHost.js +32 -12
  14. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  15. package/dist/cjs/decorators/elementDefine.js +238 -180
  16. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  17. package/dist/cjs/decorators/emitCustomEvent.js +67 -48
  18. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  19. package/dist/cjs/decorators/lifecycles.js +15 -17
  20. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  21. package/dist/cjs/decorators/setProperty.js +50 -39
  22. package/dist/cjs/decorators/setProperty.js.map +2 -2
  23. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  24. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  25. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  26. package/dist/cjs/elements/SwcAppEngine.js +14 -8
  27. package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
  28. package/dist/cjs/elements/SwcAppMixin.js +154 -81
  29. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  30. package/dist/cjs/elements/SwcAsync.js +28 -18
  31. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  32. package/dist/cjs/elements/SwcChoose.js +68 -45
  33. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  34. package/dist/cjs/elements/SwcIf.js +52 -30
  35. package/dist/cjs/elements/SwcIf.js.map +2 -2
  36. package/dist/cjs/elements/SwcLoop.js +109 -35
  37. package/dist/cjs/elements/SwcLoop.js.map +2 -2
  38. package/dist/cjs/elements/register.js +263 -131
  39. package/dist/cjs/elements/register.js.map +2 -2
  40. package/dist/cjs/router/ElementRouter.js +4 -2
  41. package/dist/cjs/router/ElementRouter.js.map +1 -1
  42. package/dist/cjs/types.js.map +1 -1
  43. package/dist/cjs/utils/Utils.js +25 -7
  44. package/dist/cjs/utils/Utils.js.map +2 -2
  45. package/dist/esm/decorators/addEventListener.js.map +1 -1
  46. package/dist/esm/decorators/applyAttribute.js +67 -57
  47. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  48. package/dist/esm/decorators/applyClass.js +80 -70
  49. package/dist/esm/decorators/applyClass.js.map +2 -2
  50. package/dist/esm/decorators/applyNode.js +5 -8
  51. package/dist/esm/decorators/applyNode.js.map +2 -2
  52. package/dist/esm/decorators/applyStyle.js +66 -56
  53. package/dist/esm/decorators/applyStyle.js.map +2 -2
  54. package/dist/esm/decorators/attribute.js +35 -29
  55. package/dist/esm/decorators/attribute.js.map +2 -2
  56. package/dist/esm/decorators/changedAttributeHost.js +32 -12
  57. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  58. package/dist/esm/decorators/elementDefine.js +240 -182
  59. package/dist/esm/decorators/elementDefine.js.map +2 -2
  60. package/dist/esm/decorators/emitCustomEvent.js +67 -48
  61. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  62. package/dist/esm/decorators/lifecycles.js +15 -17
  63. package/dist/esm/decorators/lifecycles.js.map +2 -2
  64. package/dist/esm/decorators/setProperty.js +50 -39
  65. package/dist/esm/decorators/setProperty.js.map +2 -2
  66. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  67. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  68. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  69. package/dist/esm/elements/SwcAppEngine.js +14 -7
  70. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  71. package/dist/esm/elements/SwcAppMixin.js +156 -82
  72. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  73. package/dist/esm/elements/SwcAsync.js +28 -18
  74. package/dist/esm/elements/SwcAsync.js.map +2 -2
  75. package/dist/esm/elements/SwcChoose.js +69 -46
  76. package/dist/esm/elements/SwcChoose.js.map +2 -2
  77. package/dist/esm/elements/SwcIf.js +53 -31
  78. package/dist/esm/elements/SwcIf.js.map +2 -2
  79. package/dist/esm/elements/SwcLoop.js +110 -36
  80. package/dist/esm/elements/SwcLoop.js.map +2 -2
  81. package/dist/esm/elements/register.js +264 -132
  82. package/dist/esm/elements/register.js.map +2 -2
  83. package/dist/esm/router/ElementRouter.js +5 -2
  84. package/dist/esm/router/ElementRouter.js.map +1 -1
  85. package/dist/esm/types.js.map +1 -1
  86. package/dist/esm/utils/Utils.js +25 -7
  87. package/dist/esm/utils/Utils.js.map +2 -2
  88. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
  89. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  90. package/dist/types/decorators/addEventListener.d.ts +4 -1
  91. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  92. package/dist/types/decorators/applyAttribute.d.ts +5 -1
  93. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  94. package/dist/types/decorators/applyClass.d.ts +4 -0
  95. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  96. package/dist/types/decorators/applyNode.d.ts +5 -1
  97. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  98. package/dist/types/decorators/applyStyle.d.ts +5 -1
  99. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  100. package/dist/types/decorators/attribute.d.ts +5 -0
  101. package/dist/types/decorators/attribute.d.ts.map +1 -1
  102. package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
  103. package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
  104. package/dist/types/decorators/elementDefine.d.ts +1 -1
  105. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  106. package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
  107. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  108. package/dist/types/decorators/lifecycles.d.ts +10 -7
  109. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  110. package/dist/types/decorators/setProperty.d.ts +5 -1
  111. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  112. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
  113. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  114. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
  115. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  116. package/dist/types/elements/SwcAppEngine.d.ts +9 -3
  117. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  118. package/dist/types/elements/SwcAppMixin.d.ts +12 -7
  119. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  120. package/dist/types/elements/register.d.ts.map +1 -1
  121. package/dist/types/types.d.ts +1 -0
  122. package/dist/types/types.d.ts.map +1 -1
  123. package/dist/types/utils/Utils.d.ts +4 -1
  124. package/dist/types/utils/Utils.d.ts.map +1 -1
  125. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  127. package/package.json +5 -5
  128. package/src/decorators/addEventListener.ts +1 -1
  129. package/src/decorators/applyAttribute.ts +74 -61
  130. package/src/decorators/applyClass.ts +91 -77
  131. package/src/decorators/applyNode.ts +16 -13
  132. package/src/decorators/applyStyle.ts +75 -61
  133. package/src/decorators/attribute.ts +55 -43
  134. package/src/decorators/changedAttributeHost.ts +49 -15
  135. package/src/decorators/elementDefine.ts +401 -340
  136. package/src/decorators/emitCustomEvent.ts +92 -62
  137. package/src/decorators/lifecycles.ts +11 -10
  138. package/src/decorators/setProperty.ts +58 -44
  139. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
  140. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
  141. package/src/elements/SwcAppEngine.ts +19 -13
  142. package/src/elements/SwcAppMixin.ts +214 -102
  143. package/src/elements/SwcAsync.ts +28 -17
  144. package/src/elements/SwcChoose.ts +94 -36
  145. package/src/elements/SwcIf.ts +59 -22
  146. package/src/elements/SwcLoop.ts +140 -27
  147. package/src/elements/register.ts +319 -100
  148. package/src/types.ts +1 -0
  149. package/src/utils/Utils.ts +38 -10
  150. package/tsconfig.json +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
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-web": "1.0.10",
96
- "@dooboostore/core": "1.0.30",
97
- "@dooboostore/simple-boot": "1.0.54",
98
- "@dooboostore/core-node": "1.0.12"
95
+ "@dooboostore/simple-boot": "1.0.55",
96
+ "@dooboostore/core-node": "1.0.12",
97
+ "@dooboostore/core": "1.0.31",
98
+ "@dooboostore/core-web": "1.0.10"
99
99
  },
100
100
  "scripts": {
101
101
  "clean": "rm -rf dist",
@@ -10,7 +10,7 @@ export interface AddEventListenerBaseOptions extends EventListenerOptions {
10
10
  preventDefault?: boolean;
11
11
  removeOnDisconnected?: boolean;
12
12
  delegate?: boolean;
13
- filter?: (target: Event | CustomEvent, helper: HelperHostSet) => boolean;
13
+ filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;
14
14
  }
15
15
 
16
16
  export interface AddEventListenerMetadata {
@@ -7,6 +7,7 @@ export type AttributeAction = 'set' | 'update' | 'remove';
7
7
 
8
8
  export interface AttributeApplyOptions extends SwcQueryOptions {
9
9
  name?: string;
10
+ filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
10
11
  }
11
12
 
12
13
  export interface AttributeApplyMetadata {
@@ -43,76 +44,88 @@ function createAttributeDecorator(action: AttributeAction) {
43
44
  });
44
45
 
45
46
  const original = descriptor.value;
46
- descriptor.value = async function (...args: any[]) {
47
+ descriptor.value = function (...args: any[]) {
47
48
  ensureInit(this);
48
- const res = await (original as any).apply(this, args);
49
- if (res !== undefined) {
50
- const win = (this as any).ownerDocument?.defaultView || window;
51
- const host = this as unknown as HTMLElement;
52
- const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
53
- const r = finalOptions.root || 'auto';
54
- const targetEls: HTMLElement[] = [];
55
-
56
- const applyRoot = (t: any) => {
57
- if (!t || !(t instanceof win.HTMLElement)) return;
58
- targetEls.push(t);
59
- };
60
-
61
- if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
62
- else if (selector === ':appHost') applyRoot(hostSet.$appHost);
63
- else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
64
- else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
65
- else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
66
- else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
67
- else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
68
- else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
69
- else if (selector === ':host' || !selector) applyRoot(host);
70
- else {
71
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
72
- if (targetRoot) {
73
- const found = targetRoot.querySelectorAll(selector);
74
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
49
+ const res = (original as any).apply(this, args);
50
+
51
+ const handleResult = (resolvedValue: any) => {
52
+ if (resolvedValue !== undefined) {
53
+ const win = (this as any).ownerDocument?.defaultView || window;
54
+ const host = this as unknown as HTMLElement;
55
+ const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
56
+ const r = finalOptions.root || 'auto';
57
+ const targetEls: HTMLElement[] = [];
58
+
59
+ const applyRoot = (t: any) => {
60
+ if (!t || !(t instanceof win.HTMLElement)) return;
61
+ targetEls.push(t);
62
+ };
63
+
64
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
65
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
66
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
67
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
68
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
69
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
70
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
71
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
72
+ else if (selector === ':host' || !selector) applyRoot(host);
73
+ else {
74
+ const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
75
+ if (targetRoot) {
76
+ const found = targetRoot.querySelectorAll(selector);
77
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
78
+ }
75
79
  }
76
- }
77
80
 
78
- targetEls.forEach(targetEl => {
79
- const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;
81
+ targetEls.forEach(targetEl => {
82
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
83
+ return;
84
+ }
85
+ const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
80
86
 
81
- if (action === 'set' || action === 'update') {
82
- if (attributeName) {
83
- // Case: @setAttribute(selector, 'name')
84
- if (resolvedRes === null || resolvedRes === undefined || resolvedRes === false) {
87
+ if (action === 'set' || action === 'update') {
88
+ if (attributeName) {
89
+ // Case: @setAttribute(selector, 'name')
90
+ if (resolvedRes === null || resolvedRes === undefined || resolvedRes === false) {
91
+ targetEl.removeAttribute(attributeName);
92
+ } else {
93
+ targetEl.setAttribute(attributeName, resolvedRes === true ? '' : String(resolvedRes));
94
+ }
95
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
96
+ // Case: @applyAttribute(selector) with Object return
97
+ Object.entries(resolvedRes as any).forEach(([attr, val]) => {
98
+ const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
99
+ if (finalVal === null || finalVal === undefined || finalVal === false) {
100
+ targetEl.removeAttribute(attr);
101
+ } else {
102
+ targetEl.setAttribute(attr, finalVal === true ? '' : String(finalVal));
103
+ }
104
+ });
105
+ }
106
+ } else if (action === 'remove') {
107
+ if (attributeName) {
85
108
  targetEl.removeAttribute(attributeName);
109
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
110
+ Object.entries(resolvedRes as any).forEach(([attr, val]) => {
111
+ const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;
112
+ if (shouldRemove) targetEl.removeAttribute(attr);
113
+ });
86
114
  } else {
87
- targetEl.setAttribute(attributeName, resolvedRes === true ? '' : String(resolvedRes));
115
+ const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
116
+ attrs.forEach(a => targetEl.removeAttribute(String(a)));
88
117
  }
89
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
90
- // Case: @applyAttribute(selector) with Object return
91
- Object.entries(resolvedRes as any).forEach(([attr, val]) => {
92
- const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
93
- if (finalVal === null || finalVal === undefined || finalVal === false) {
94
- targetEl.removeAttribute(attr);
95
- } else {
96
- targetEl.setAttribute(attr, finalVal === true ? '' : String(finalVal));
97
- }
98
- });
99
- }
100
- } else if (action === 'remove') {
101
- if (attributeName) {
102
- targetEl.removeAttribute(attributeName);
103
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
104
- Object.entries(resolvedRes as any).forEach(([attr, val]) => {
105
- const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;
106
- if (shouldRemove) targetEl.removeAttribute(attr);
107
- });
108
- } else {
109
- const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
110
- attrs.forEach(a => targetEl.removeAttribute(String(a)));
111
118
  }
112
- }
113
- });
119
+ });
120
+ }
121
+ return resolvedValue;
122
+ };
123
+
124
+ if (res instanceof Promise) {
125
+ return res.then(handleResult);
126
+ } else {
127
+ return handleResult(res);
114
128
  }
115
- return res;
116
129
  };
117
130
  return descriptor;
118
131
  };
@@ -7,7 +7,9 @@ export const CLASS_METADATA_KEY = Symbol.for('simple-web-component:class');
7
7
 
8
8
  export type ClassAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';
9
9
 
10
- export interface ClassApplyOptions extends SwcQueryOptions {}
10
+ export interface ClassApplyOptions extends SwcQueryOptions {
11
+ filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
12
+ }
11
13
 
12
14
  export interface ClassApplyMetadata {
13
15
  propertyKey: string | symbol;
@@ -38,88 +40,100 @@ function createClassDecorator(action: ClassAction) {
38
40
  metaList.set(propertyKey, { propertyKey, selector, action, options: finalOptions });
39
41
 
40
42
  const original = descriptor.value;
41
- descriptor.value = async function (...args: any[]) {
43
+ descriptor.value = function (...args: any[]) {
42
44
  ensureInit(this);
43
- const res = await (original as any).apply(this, args);
44
- if (res !== undefined) {
45
- const win = (this as any).ownerDocument?.defaultView || window;
46
- const host = this as unknown as HTMLElement;
47
- const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
48
- const r = finalOptions.root || 'auto';
49
- const targetEls: HTMLElement[] = [];
50
-
51
- const applyRoot = (t: any) => {
52
- if (!t || !(t instanceof win.HTMLElement)) return;
53
- targetEls.push(t);
54
- };
55
-
56
- if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
57
- else if (selector === ':appHost') applyRoot(hostSet.$appHost);
58
- else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
59
- else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
60
- else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
61
- else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
62
- else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
63
- else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
64
- else if (selector === ':host' || !selector) applyRoot(host);
65
- else {
66
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
67
- if (targetRoot) {
68
- const found = targetRoot.querySelectorAll(selector);
69
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
45
+ const res = (original as any).apply(this, args);
46
+
47
+ const handleResult = (resolvedValue: any) => {
48
+ if (resolvedValue !== undefined) {
49
+ const win = (this as any).ownerDocument?.defaultView || window;
50
+ const host = this as unknown as HTMLElement;
51
+ const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
52
+ const r = finalOptions.root || 'auto';
53
+ const targetEls: HTMLElement[] = [];
54
+
55
+ const applyRoot = (t: any) => {
56
+ if (!t || !(t instanceof win.HTMLElement)) return;
57
+ targetEls.push(t);
58
+ };
59
+
60
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
61
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
62
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
63
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
64
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
65
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
66
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
67
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
68
+ else if (selector === ':host' || !selector) applyRoot(host);
69
+ else {
70
+ const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
71
+ if (targetRoot) {
72
+ const found = targetRoot.querySelectorAll(selector);
73
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
74
+ }
70
75
  }
71
- }
72
76
 
73
- targetEls.forEach(targetEl => {
74
- const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;
75
-
76
- if (action === 'set') {
77
- let classes = '';
78
- if (classMap && typeof classMap === 'string') {
79
- classes = resolvedRes ? classMap : '';
80
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
81
- classes = Object.entries(resolvedRes as any)
82
- .filter(([_, force]) => typeof force === 'function' ? force(targetEl, hostSet) : !!force)
83
- .map(([cls]) => cls)
84
- .join(' ');
85
- } else {
86
- classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).join(' ') : String(resolvedRes);
87
- }
88
- targetEl.className = classes;
89
- } else if (action === 'update' || action === 'toggle') {
90
- if (classMap && typeof classMap === 'string') {
91
- targetEl.classList.toggle(classMap, !!resolvedRes);
92
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
93
- Object.entries(resolvedRes as any).forEach(([cls, force]) => {
94
- const isActive = typeof force === 'function' ? force(targetEl, hostSet) : !!force;
95
- targetEl.classList.toggle(cls, isActive);
96
- });
97
- } else {
98
- const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];
99
- if (action === 'update') targetEl.classList.add(...classes);
100
- else classes.forEach(c => targetEl.classList.toggle(c));
77
+ targetEls.forEach(targetEl => {
78
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
79
+ return;
101
80
  }
102
- } else if (action === 'add' || action === 'remove') {
103
- if (classMap && typeof classMap === 'string' && !!resolvedRes) {
104
- if (action === 'add') targetEl.classList.add(classMap);
105
- else targetEl.classList.remove(classMap);
106
- } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
107
- Object.entries(resolvedRes as any).forEach(([cls, force]) => {
108
- const shouldExecute = typeof force === 'function' ? force(targetEl, hostSet) : !!force;
109
- if (shouldExecute) {
110
- if (action === 'add') targetEl.classList.add(cls);
111
- else targetEl.classList.remove(cls);
112
- }
113
- });
114
- } else {
115
- const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];
116
- if (action === 'add') targetEl.classList.add(...classes);
117
- else targetEl.classList.remove(...classes);
81
+ const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
82
+
83
+ if (action === 'set') {
84
+ let classes = '';
85
+ if (classMap && typeof classMap === 'string') {
86
+ classes = resolvedRes ? classMap : '';
87
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
88
+ classes = Object.entries(resolvedRes as any)
89
+ .filter(([_, force]) => typeof force === 'function' ? force(targetEl, hostSet) : !!force)
90
+ .map(([cls]) => cls)
91
+ .join(' ');
92
+ } else {
93
+ classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).join(' ') : String(resolvedRes);
94
+ }
95
+ targetEl.className = classes;
96
+ } else if (action === 'update' || action === 'toggle') {
97
+ if (classMap && typeof classMap === 'string') {
98
+ targetEl.classList.toggle(classMap, !!resolvedRes);
99
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
100
+ Object.entries(resolvedRes as any).forEach(([cls, force]) => {
101
+ const isActive = typeof force === 'function' ? force(targetEl, hostSet) : !!force;
102
+ targetEl.classList.toggle(cls, isActive);
103
+ });
104
+ } else {
105
+ const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];
106
+ if (action === 'update') targetEl.classList.add(...classes);
107
+ else classes.forEach(c => targetEl.classList.toggle(c));
108
+ }
109
+ } else if (action === 'add' || action === 'remove') {
110
+ if (classMap && typeof classMap === 'string' && !!resolvedRes) {
111
+ if (action === 'add') targetEl.classList.add(classMap);
112
+ else targetEl.classList.remove(classMap);
113
+ } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
114
+ Object.entries(resolvedRes as any).forEach(([cls, force]) => {
115
+ const shouldExecute = typeof force === 'function' ? force(targetEl, hostSet) : !!force;
116
+ if (shouldExecute) {
117
+ if (action === 'add') targetEl.classList.add(cls);
118
+ else targetEl.classList.remove(cls);
119
+ }
120
+ });
121
+ } else {
122
+ const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];
123
+ if (action === 'add') targetEl.classList.add(...classes);
124
+ else targetEl.classList.remove(...classes);
125
+ }
118
126
  }
119
- }
120
- });
127
+ });
128
+ }
129
+ return resolvedValue;
130
+ };
131
+
132
+ if (res instanceof Promise) {
133
+ return res.then(handleResult);
134
+ } else {
135
+ return handleResult(res);
121
136
  }
122
- return res;
123
137
  };
124
138
  return descriptor;
125
139
  };
@@ -2,7 +2,15 @@ import { ReflectUtils } from '@dooboostore/core';
2
2
  import { ensureInit, getElementConfig } from './elementDefine';
3
3
  import { HelperHostSet, SwcRootType } from '../types';
4
4
  import { SwcUtils } from "../utils/Utils";
5
-
5
+ /*
6
+ <!-- beforebegin -->
7
+ <p>
8
+ <!-- afterbegin -->
9
+ foo
10
+ <!-- beforeend -->
11
+ </p>
12
+ <!-- afterend -->
13
+ */
6
14
  export type ApplyNodePosition = 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd' | 'replace' | 'replaceChildren' | 'innerHtml' | 'innerText' | 'remove';
7
15
 
8
16
  export interface ApplyNodeOptions {
@@ -12,7 +20,7 @@ export interface ApplyNodeOptions {
12
20
  * Filter function to determine whether to perform DOM operation.
13
21
  * If it returns false, the operation is skipped.
14
22
  */
15
- filter?: (target: HTMLElement | ShadowRoot, newValue: any, helper: HelperHostSet) => boolean;
23
+ filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;
16
24
  /**
17
25
  * Optional loading content to display while an async method is executing.
18
26
  */
@@ -113,17 +121,8 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
113
121
  const runApply = (target: any, val: any) => {
114
122
  const pos = options.position || 'beforeEnd';
115
123
 
116
- // Intelligent Default Filter
117
- const defaultFilter = (t: any, v: any) => {
118
- if (v instanceof Node) return !t.contains(v);
119
- if (pos === 'innerHtml' && typeof v === 'string') return t.innerHTML !== v;
120
- if (pos === 'replaceChildren' && v instanceof Node) return !t.contains(v);
121
- return true;
122
- };
123
-
124
- const activeFilter = options.filter || defaultFilter;
125
-
126
- if (activeFilter(target, val, hostSet)) {
124
+ // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
125
+ if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
127
126
  applyToDom(target, val, pos, currentDoc);
128
127
  }
129
128
  };
@@ -189,3 +188,7 @@ export function applyReplaceChildrenNode(selector: string, options: ApplyNodeOpt
189
188
  export function applyInnerHtmlNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
190
189
  return applyNode(selector, { ...options, position: 'innerHtml' });
191
190
  }
191
+
192
+ export function applyInnerTextNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
193
+ return applyNode(selector, { ...options, position: 'innerText' });
194
+ }
@@ -5,7 +5,9 @@ import { SwcQueryOptions, HelperHostSet } from '../types';
5
5
 
6
6
  export type StyleAction = 'set' | 'update' | 'remove';
7
7
 
8
- export interface StyleApplyOptions extends SwcQueryOptions {}
8
+ export interface StyleApplyOptions extends SwcQueryOptions {
9
+ filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;
10
+ }
9
11
 
10
12
  export interface StyleApplyMetadata {
11
13
  propertyKey: string | symbol;
@@ -28,72 +30,84 @@ function createStyleDecorator(action: StyleAction) {
28
30
  metaList.set(propertyKey, { propertyKey, selector, action, options });
29
31
 
30
32
  const original = descriptor.value;
31
- descriptor.value = async function (...args: any[]) {
33
+ descriptor.value = function (...args: any[]) {
32
34
  ensureInit(this);
33
- const res = await (original as any).apply(this, args);
34
- if (res !== undefined) {
35
- const win = (this as any).ownerDocument?.defaultView || window;
36
- const host = this as unknown as HTMLElement;
37
- const hostSet = SwcUtils.getHelperAndHostSet(win, host);
38
- const r = options.root || 'auto';
39
- const targetEls: HTMLElement[] = [];
40
-
41
- const applyRoot = (t: any) => {
42
- if (!t || !(t instanceof win.HTMLElement)) return;
43
- targetEls.push(t);
44
- };
45
-
46
- if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
47
- else if (selector === ':appHost') applyRoot(hostSet.$appHost);
48
- else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
49
- else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
50
- else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
51
- else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
52
- else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
53
- else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
54
- else if (selector === ':host' || !selector) applyRoot(host);
55
- else {
56
- const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
57
- if (targetRoot) {
58
- const found = targetRoot.querySelectorAll(selector);
59
- if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
35
+ const res = (original as any).apply(this, args);
36
+
37
+ const handleResult = (resolvedValue: any) => {
38
+ if (resolvedValue !== undefined) {
39
+ const win = (this as any).ownerDocument?.defaultView || window;
40
+ const host = this as unknown as HTMLElement;
41
+ const hostSet = SwcUtils.getHelperAndHostSet(win, host);
42
+ const r = options.root || 'auto';
43
+ const targetEls: HTMLElement[] = [];
44
+
45
+ const applyRoot = (t: any) => {
46
+ if (!t || !(t instanceof win.HTMLElement)) return;
47
+ targetEls.push(t);
48
+ };
49
+
50
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
51
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
52
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
53
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
54
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
55
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
56
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
57
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
58
+ else if (selector === ':host' || !selector) applyRoot(host);
59
+ else {
60
+ const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);
61
+ if (targetRoot) {
62
+ const found = targetRoot.querySelectorAll(selector);
63
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
64
+ }
60
65
  }
61
- }
62
66
 
63
- targetEls.forEach(targetEl => {
64
- const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;
65
-
66
- if (action === 'set' || action === 'update') {
67
- if (action === 'set') targetEl.style.cssText = '';
68
-
69
- if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
70
- Object.entries(resolvedRes as any).forEach(([prop, val]) => {
71
- const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
72
- if (finalVal === null || finalVal === undefined) {
73
- targetEl.style.removeProperty(prop);
74
- } else {
75
- targetEl.style[prop as any] = String(finalVal);
76
- }
77
- });
78
- } else if (typeof resolvedRes === 'string') {
79
- targetEl.style.cssText = resolvedRes;
67
+ targetEls.forEach(targetEl => {
68
+ if (options.filter && !options.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {
69
+ return;
80
70
  }
81
- } else if (action === 'remove') {
82
- if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
83
- Object.entries(resolvedRes as any).forEach(([prop, val]) => {
84
- const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;
85
- if (shouldRemove) {
86
- targetEl.style.removeProperty(prop);
87
- }
88
- });
89
- } else {
90
- const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
91
- props.forEach(p => targetEl.style.removeProperty(String(p)));
71
+ const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;
72
+
73
+ if (action === 'set' || action === 'update') {
74
+ if (action === 'set') targetEl.style.cssText = '';
75
+
76
+ if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
77
+ Object.entries(resolvedRes as any).forEach(([prop, val]) => {
78
+ const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;
79
+ if (finalVal === null || finalVal === undefined) {
80
+ targetEl.style.removeProperty(prop);
81
+ } else {
82
+ targetEl.style[prop as any] = String(finalVal);
83
+ }
84
+ });
85
+ } else if (typeof resolvedRes === 'string') {
86
+ targetEl.style.cssText = resolvedRes;
87
+ }
88
+ } else if (action === 'remove') {
89
+ if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {
90
+ Object.entries(resolvedRes as any).forEach(([prop, val]) => {
91
+ const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;
92
+ if (shouldRemove) {
93
+ targetEl.style.removeProperty(prop);
94
+ }
95
+ });
96
+ } else {
97
+ const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
98
+ props.forEach(p => targetEl.style.removeProperty(String(p)));
99
+ }
92
100
  }
93
- }
94
- });
101
+ });
102
+ }
103
+ return resolvedValue;
104
+ };
105
+
106
+ if (res instanceof Promise) {
107
+ return res.then(handleResult);
108
+ } else {
109
+ return handleResult(res);
95
110
  }
96
- return res;
97
111
  };
98
112
  return descriptor;
99
113
  };