@dooboostore/simple-web-component 1.0.36 → 1.0.37

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 (210) hide show
  1. package/README.md +41 -4
  2. package/dist/cjs/{elements/SwcAppEngine.js → SwcAppEngine.js} +6 -6
  3. package/dist/cjs/SwcAppEngine.js.map +7 -0
  4. package/dist/cjs/decorators/applyNode.js +14 -13
  5. package/dist/cjs/decorators/applyNode.js.map +2 -2
  6. package/dist/cjs/decorators/applySlot.js +122 -0
  7. package/dist/cjs/decorators/applySlot.js.map +7 -0
  8. package/dist/cjs/decorators/elementDefine.js +38 -30
  9. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  10. package/dist/cjs/decorators/index.js +1 -0
  11. package/dist/cjs/decorators/index.js.map +2 -2
  12. package/dist/cjs/decorators/lifecycles.js +56 -8
  13. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  14. package/dist/cjs/elements/{SwcAppMixin.js → SwcApp.js} +107 -57
  15. package/dist/cjs/elements/SwcApp.js.map +7 -0
  16. package/dist/cjs/elements/index.js +21 -2
  17. package/dist/cjs/elements/index.js.map +3 -3
  18. package/dist/cjs/elements/tt/SwcAppMixin.js +1 -0
  19. package/dist/cjs/elements/tt/SwcAppMixin.js.map +7 -0
  20. package/dist/cjs/elements/tt/SwcAsync.js +1 -0
  21. package/dist/cjs/elements/tt/SwcAsync.js.map +7 -0
  22. package/dist/cjs/elements/tt/SwcAsyncTemplate.js +1 -0
  23. package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +7 -0
  24. package/dist/cjs/elements/tt/SwcChoose.js +1 -0
  25. package/dist/cjs/elements/tt/SwcChoose.js.map +7 -0
  26. package/dist/cjs/elements/tt/SwcChooseTemplate.js +1 -0
  27. package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +7 -0
  28. package/dist/cjs/elements/tt/SwcIf.js +1 -0
  29. package/dist/cjs/elements/tt/SwcIf.js.map +7 -0
  30. package/dist/cjs/elements/tt/SwcIfTemplate.js +1 -0
  31. package/dist/cjs/elements/tt/SwcIfTemplate.js.map +7 -0
  32. package/dist/cjs/elements/tt/SwcLoop.js +1 -0
  33. package/dist/cjs/elements/tt/SwcLoop.js.map +7 -0
  34. package/dist/cjs/elements/tt/SwcLoopTemplate.js +1 -0
  35. package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +7 -0
  36. package/dist/cjs/elements/tt/SwcSubTemplates.js +1 -0
  37. package/dist/cjs/elements/tt/SwcSubTemplates.js.map +7 -0
  38. package/dist/cjs/elements/tt/register.js +1 -0
  39. package/dist/cjs/elements/tt/register.js.map +7 -0
  40. package/dist/cjs/index.js +12 -8
  41. package/dist/cjs/index.js.map +2 -2
  42. package/dist/cjs/types/window.d.js +16 -0
  43. package/dist/cjs/types/window.d.js.map +7 -0
  44. package/dist/cjs/types.js.map +1 -1
  45. package/dist/cjs/utils/Utils.js +9 -6
  46. package/dist/cjs/utils/Utils.js.map +2 -2
  47. package/dist/esm/{elements/SwcAppEngine.js → SwcAppEngine.js} +4 -4
  48. package/dist/esm/SwcAppEngine.js.map +7 -0
  49. package/dist/esm/decorators/applyNode.js +14 -13
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applySlot.js +103 -0
  52. package/dist/esm/decorators/applySlot.js.map +7 -0
  53. package/dist/esm/decorators/elementDefine.js +41 -33
  54. package/dist/esm/decorators/elementDefine.js.map +2 -2
  55. package/dist/esm/decorators/index.js +1 -0
  56. package/dist/esm/decorators/index.js.map +2 -2
  57. package/dist/esm/decorators/lifecycles.js +56 -8
  58. package/dist/esm/decorators/lifecycles.js.map +2 -2
  59. package/dist/esm/elements/{SwcAppMixin.js → SwcApp.js} +102 -53
  60. package/dist/esm/elements/SwcApp.js.map +7 -0
  61. package/dist/esm/elements/index.js +7 -1
  62. package/dist/esm/elements/index.js.map +2 -2
  63. package/dist/esm/elements/tt/SwcAppMixin.js +1 -0
  64. package/dist/esm/elements/tt/SwcAppMixin.js.map +7 -0
  65. package/dist/esm/elements/tt/SwcAsync.js +1 -0
  66. package/dist/esm/elements/tt/SwcAsync.js.map +7 -0
  67. package/dist/esm/elements/tt/SwcAsyncTemplate.js +1 -0
  68. package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +7 -0
  69. package/dist/esm/elements/tt/SwcChoose.js +1 -0
  70. package/dist/esm/elements/tt/SwcChoose.js.map +7 -0
  71. package/dist/esm/elements/tt/SwcChooseTemplate.js +1 -0
  72. package/dist/esm/elements/tt/SwcChooseTemplate.js.map +7 -0
  73. package/dist/esm/elements/tt/SwcIf.js +1 -0
  74. package/dist/esm/elements/tt/SwcIf.js.map +7 -0
  75. package/dist/esm/elements/tt/SwcIfTemplate.js +1 -0
  76. package/dist/esm/elements/tt/SwcIfTemplate.js.map +7 -0
  77. package/dist/esm/elements/tt/SwcLoop.js +1 -0
  78. package/dist/esm/elements/tt/SwcLoop.js.map +7 -0
  79. package/dist/esm/elements/tt/SwcLoopTemplate.js +1 -0
  80. package/dist/esm/elements/tt/SwcLoopTemplate.js.map +7 -0
  81. package/dist/esm/elements/tt/SwcSubTemplates.js +1 -0
  82. package/dist/esm/elements/tt/SwcSubTemplates.js.map +7 -0
  83. package/dist/esm/elements/tt/register.js +1 -0
  84. package/dist/esm/elements/tt/register.js.map +7 -0
  85. package/dist/esm/index.js +13 -9
  86. package/dist/esm/index.js.map +2 -2
  87. package/dist/esm/types/window.d.js +1 -0
  88. package/dist/esm/types/window.d.js.map +7 -0
  89. package/dist/esm/types.js.map +1 -1
  90. package/dist/esm/utils/Utils.js +9 -6
  91. package/dist/esm/utils/Utils.js.map +2 -2
  92. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3867 -97
  93. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  94. package/dist/types/{elements/SwcAppEngine.d.ts → SwcAppEngine.d.ts} +9 -4
  95. package/dist/types/SwcAppEngine.d.ts.map +1 -0
  96. package/dist/types/decorators/applyNode.d.ts +7 -7
  97. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  98. package/dist/types/decorators/applySlot.d.ts +27 -0
  99. package/dist/types/decorators/applySlot.d.ts.map +1 -0
  100. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  101. package/dist/types/decorators/index.d.ts +1 -0
  102. package/dist/types/decorators/index.d.ts.map +1 -1
  103. package/dist/types/decorators/lifecycles.d.ts +21 -6
  104. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  105. package/dist/types/elements/SwcApp.d.ts +7 -0
  106. package/dist/types/elements/SwcApp.d.ts.map +1 -0
  107. package/dist/types/elements/index.d.ts +2 -1
  108. package/dist/types/elements/index.d.ts.map +1 -1
  109. package/dist/types/elements/tt/SwcAppMixin.d.ts +1 -0
  110. package/dist/types/elements/tt/SwcAppMixin.d.ts.map +1 -0
  111. package/dist/types/elements/tt/SwcAsync.d.ts +1 -0
  112. package/dist/types/elements/tt/SwcAsync.d.ts.map +1 -0
  113. package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +1 -0
  114. package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +1 -0
  115. package/dist/types/elements/tt/SwcChoose.d.ts +1 -0
  116. package/dist/types/elements/tt/SwcChoose.d.ts.map +1 -0
  117. package/dist/types/elements/tt/SwcChooseTemplate.d.ts +1 -0
  118. package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +1 -0
  119. package/dist/types/elements/tt/SwcIf.d.ts +1 -0
  120. package/dist/types/elements/{SwcIf.d.ts.map → tt/SwcIf.d.ts.map} +1 -1
  121. package/dist/types/elements/tt/SwcIfTemplate.d.ts +1 -0
  122. package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +1 -0
  123. package/dist/types/elements/tt/SwcLoop.d.ts +1 -0
  124. package/dist/types/elements/tt/SwcLoop.d.ts.map +1 -0
  125. package/dist/types/elements/tt/SwcLoopTemplate.d.ts +1 -0
  126. package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +1 -0
  127. package/dist/types/elements/tt/SwcSubTemplates.d.ts +1 -0
  128. package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +1 -0
  129. package/dist/types/elements/tt/register.d.ts +1 -0
  130. package/dist/types/elements/tt/register.d.ts.map +1 -0
  131. package/dist/types/index.d.ts +2 -2
  132. package/dist/types/index.d.ts.map +1 -1
  133. package/dist/types/types.d.ts +3 -3
  134. package/dist/types/types.d.ts.map +1 -1
  135. package/dist/types/utils/Utils.d.ts +6 -5
  136. package/dist/types/utils/Utils.d.ts.map +1 -1
  137. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3867 -97
  138. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  139. package/package.json +2 -2
  140. package/src/{elements/SwcAppEngine.ts → SwcAppEngine.ts} +12 -7
  141. package/src/decorators/applyNode.ts +15 -13
  142. package/src/decorators/applySlot.ts +228 -0
  143. package/src/decorators/elementDefine.ts +59 -37
  144. package/src/decorators/index.ts +1 -0
  145. package/src/decorators/lifecycles.ts +76 -11
  146. package/src/elements/{SwcAppMixin.ts → SwcApp.ts} +98 -31
  147. package/src/elements/index.ts +11 -1
  148. package/src/elements/tt/SwcAppMixin.ts +13 -0
  149. package/src/elements/tt/SwcAsync.ts +139 -0
  150. package/src/elements/tt/SwcAsyncTemplate.ts +126 -0
  151. package/src/elements/tt/SwcChoose.ts +182 -0
  152. package/src/elements/tt/SwcChooseTemplate.ts +229 -0
  153. package/src/elements/tt/SwcIf.ts +145 -0
  154. package/src/elements/tt/SwcIfTemplate.ts +158 -0
  155. package/src/elements/tt/SwcLoop.ts +222 -0
  156. package/src/elements/tt/SwcLoopTemplate.ts +255 -0
  157. package/src/elements/tt/SwcSubTemplates.ts +6 -0
  158. package/src/elements/tt/register.ts +720 -0
  159. package/src/index.ts +13 -9
  160. package/src/types/window.d.ts +43 -0
  161. package/src/types.ts +4 -3
  162. package/src/utils/Utils.ts +11 -6
  163. package/dist/cjs/elements/SwcAppEngine.js.map +0 -7
  164. package/dist/cjs/elements/SwcAppMixin.js.map +0 -7
  165. package/dist/cjs/elements/SwcAsync.js +0 -129
  166. package/dist/cjs/elements/SwcAsync.js.map +0 -7
  167. package/dist/cjs/elements/SwcChoose.js +0 -155
  168. package/dist/cjs/elements/SwcChoose.js.map +0 -7
  169. package/dist/cjs/elements/SwcIf.js +0 -117
  170. package/dist/cjs/elements/SwcIf.js.map +0 -7
  171. package/dist/cjs/elements/SwcLoop.js +0 -176
  172. package/dist/cjs/elements/SwcLoop.js.map +0 -7
  173. package/dist/cjs/elements/SwcSubTemplates.js +0 -13
  174. package/dist/cjs/elements/SwcSubTemplates.js.map +0 -7
  175. package/dist/cjs/elements/register.js +0 -1026
  176. package/dist/cjs/elements/register.js.map +0 -7
  177. package/dist/esm/elements/SwcAppEngine.js.map +0 -7
  178. package/dist/esm/elements/SwcAppMixin.js.map +0 -7
  179. package/dist/esm/elements/SwcAsync.js +0 -129
  180. package/dist/esm/elements/SwcAsync.js.map +0 -7
  181. package/dist/esm/elements/SwcChoose.js +0 -155
  182. package/dist/esm/elements/SwcChoose.js.map +0 -7
  183. package/dist/esm/elements/SwcIf.js +0 -117
  184. package/dist/esm/elements/SwcIf.js.map +0 -7
  185. package/dist/esm/elements/SwcLoop.js +0 -176
  186. package/dist/esm/elements/SwcLoop.js.map +0 -7
  187. package/dist/esm/elements/SwcSubTemplates.js +0 -13
  188. package/dist/esm/elements/SwcSubTemplates.js.map +0 -7
  189. package/dist/esm/elements/register.js +0 -1007
  190. package/dist/esm/elements/register.js.map +0 -7
  191. package/dist/types/elements/SwcAppEngine.d.ts.map +0 -1
  192. package/dist/types/elements/SwcAppMixin.d.ts +0 -386
  193. package/dist/types/elements/SwcAppMixin.d.ts.map +0 -1
  194. package/dist/types/elements/SwcAsync.d.ts +0 -2
  195. package/dist/types/elements/SwcAsync.d.ts.map +0 -1
  196. package/dist/types/elements/SwcChoose.d.ts +0 -2
  197. package/dist/types/elements/SwcChoose.d.ts.map +0 -1
  198. package/dist/types/elements/SwcIf.d.ts +0 -2
  199. package/dist/types/elements/SwcLoop.d.ts +0 -2
  200. package/dist/types/elements/SwcLoop.d.ts.map +0 -1
  201. package/dist/types/elements/SwcSubTemplates.d.ts +0 -13
  202. package/dist/types/elements/SwcSubTemplates.d.ts.map +0 -1
  203. package/dist/types/elements/register.d.ts +0 -4
  204. package/dist/types/elements/register.d.ts.map +0 -1
  205. package/src/elements/SwcAsync.ts +0 -126
  206. package/src/elements/SwcChoose.ts +0 -190
  207. package/src/elements/SwcIf.ts +0 -124
  208. package/src/elements/SwcLoop.ts +0 -205
  209. package/src/elements/SwcSubTemplates.ts +0 -6
  210. package/src/elements/register.ts +0 -1022
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -94,7 +94,7 @@
94
94
  "webpack-dev-server": "^5.2.0",
95
95
  "@dooboostore/core": "1.0.31",
96
96
  "@dooboostore/core-node": "1.0.12",
97
- "@dooboostore/core-web": "1.0.10",
97
+ "@dooboostore/core-web": "1.0.11",
98
98
  "@dooboostore/simple-boot": "1.0.55"
99
99
  },
100
100
  "scripts": {
@@ -1,22 +1,27 @@
1
- import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';
1
+ import { SimpleApplication } from '@dooboostore/simple-boot';
2
2
  import { HashRouter, PathRouter, Router, RouterEventType } from '@dooboostore/core-web';
3
- import { ElementRouter } from '../router/ElementRouter';
4
- import { SimOption } from '@dooboostore/simple-boot/SimOption';
3
+ import { ElementRouter } from './router/ElementRouter';
4
+ import { SimOption } from '@dooboostore/simple-boot';
5
5
  import { ConstructorType, OptionalType, Subscription } from '@dooboostore/core';
6
6
 
7
- import { SwcAppInterface } from '../types';
7
+ import { SwcAppInterface } from './types';
8
8
  import { SimConfig } from '@dooboostore/simple-boot';
9
9
 
10
10
  export type SwcConfigType = {
11
11
  routeType: 'path' | 'hash' | 'element';
12
- connectMode?: 'direct' | 'swap' | 'clear-swap';
12
+ connectMode?: 'direct' | 'swap' | 'clear-swap' | 'hydrate'; // hydrate 아직 개발중
13
13
  container?: symbol;
14
14
  otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>;
15
15
  path?: string;
16
16
  window: Window;
17
- onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => void;
17
+ onEngineStarted?: (sp: SimpleApplication, app: SwcAppInterface) => Promise<void> | void;
18
+ onConnectedChildAfter?: (swcEl: HTMLElement) => void;
19
+ onConnectedChildBefore?: (swcEl: HTMLElement) => void;
20
+ onDisconnectedChildAfter?: (swcEl: HTMLElement) => void;
21
+ onDisconnectedChildBefore?: (swcEl: HTMLElement) => void;
18
22
  onConnected?: (app: SwcAppInterface) => void;
19
23
  onDisconnected?: (app: SwcAppInterface) => void;
24
+ ssr?: boolean;
20
25
 
21
26
  onChildrenConnectedDone?: (app: SwcAppInterface) => void;
22
27
  // onChildrenSwcAppStartedDone?: (app: SwcAppInterface) => void;
@@ -71,7 +76,7 @@ export class SwcAppEngine {
71
76
  this.simpleApplication.run(otherInstanceSim);
72
77
 
73
78
  if (this._config.onEngineStarted) {
74
- this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
79
+ await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
75
80
  }
76
81
  } catch (e) {
77
82
  console.error('[SWC-APP-ENGINE] Init failed:', e, this._config);
@@ -4,7 +4,7 @@ import { HelperHostSet, SwcRootType } from '../types';
4
4
  import { SwcUtils } from "../utils/Utils";
5
5
  /*
6
6
  <!-- beforebegin -->
7
- <p>
7
+ <p> <-- it's me
8
8
  <!-- afterbegin -->
9
9
  foo
10
10
  <!-- beforeend -->
@@ -43,8 +43,10 @@ const normalizeNodes = (res: any, doc: Document): Node[] => {
43
43
  });
44
44
  };
45
45
 
46
- const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, doc: Document) => {
46
+ const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {
47
47
  if (!targetEl) return;
48
+
49
+ const doc = win.document;
48
50
 
49
51
  if (pos === 'innerHtml') {
50
52
  targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
@@ -58,7 +60,7 @@ const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, doc: Docume
58
60
  return;
59
61
  }
60
62
 
61
- const isShadowRoot = targetEl instanceof ShadowRoot;
63
+ const isShadowRoot = targetEl instanceof win.ShadowRoot;
62
64
  const nodes = normalizeNodes(res, doc);
63
65
  if (pos === 'replace') {
64
66
  if (!isShadowRoot) targetEl.replaceWith(...nodes);
@@ -124,7 +126,7 @@ export function applyNode(selector: string, options: ApplyNodeOptions = { positi
124
126
 
125
127
  // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
126
128
  if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
127
- applyToDom(target, val, pos, currentDoc);
129
+ applyToDom(target, val, pos, currentWin);
128
130
  }
129
131
  };
130
132
 
@@ -166,30 +168,30 @@ export function applyNodeThis(targetOrOptions?: any, propertyKey?: string | symb
166
168
  return applyNode('$this', { position: 'beforeEnd', ...opt });
167
169
  }
168
170
 
169
- export function applyReplaceChildrenNodeThis(options: ApplyNodeOptions): MethodDecorator;
170
- export function applyReplaceChildrenNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
171
- export function applyReplaceChildrenNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
171
+ export function applyNodeThisReplaceChildren(options: ApplyNodeOptions): MethodDecorator;
172
+ export function applyNodeThisReplaceChildren(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
173
+ export function applyNodeThisReplaceChildren(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
172
174
  if (propertyKey !== undefined) return applyNode('$this', { position: 'replaceChildren' })(targetOrOptions, propertyKey, descriptor);
173
175
  const opt = targetOrOptions || {};
174
176
  return applyNode('$this', { position: 'replaceChildren', ...opt });
175
177
  }
176
178
 
177
- export function applyInnerHtmlNodeThis(options: ApplyNodeOptions): MethodDecorator;
178
- export function applyInnerHtmlNodeThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
179
- export function applyInnerHtmlNodeThis(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
179
+ export function applyThisInnerHtmlNode(options: ApplyNodeOptions): MethodDecorator;
180
+ export function applyThisInnerHtmlNode(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;
181
+ export function applyThisInnerHtmlNode(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
180
182
  if (propertyKey !== undefined) return applyNode('$this', { position: 'innerHtml' })(targetOrOptions, propertyKey, descriptor);
181
183
  const opt = targetOrOptions || {};
182
184
  return applyNode('$this', { position: 'innerHtml', ...opt });
183
185
  }
184
186
 
185
- export function applyReplaceChildrenNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
187
+ export function applyNodeReplaceChildren(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
186
188
  return applyNode(selector, { ...options, position: 'replaceChildren' });
187
189
  }
188
190
 
189
- export function applyInnerHtmlNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
191
+ export function applyNodeInnerHtml(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
190
192
  return applyNode(selector, { ...options, position: 'innerHtml' });
191
193
  }
192
194
 
193
- export function applyInnerTextNode(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
195
+ export function applyNodeInnerText(selector: string, options: ApplyNodeOptions = {}): MethodDecorator {
194
196
  return applyNode(selector, { ...options, position: 'innerText' });
195
197
  }
@@ -0,0 +1,228 @@
1
+ import { ReflectUtils } from '@dooboostore/core';
2
+ import { ensureInit, getElementConfig } from './elementDefine';
3
+ import { HelperHostSet, SwcRootType } from '../types';
4
+ import { SwcUtils } from "../utils/Utils";
5
+ import {NodeSlot} from "@dooboostore/core-web";
6
+ /*
7
+ <!-- beforebegin -->
8
+ <p> <-- it's me
9
+ <!-- afterbegin -->
10
+ foo
11
+ <!-- beforeend -->
12
+ </p>
13
+ <!-- afterend -->
14
+ */
15
+ export type ApplySlotPosition = 'prependHtml' | 'prependText' | 'appendHtml' | 'appendText' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';
16
+
17
+ export interface ApplySlotOptions {
18
+ position?: ApplySlotPosition;
19
+ // root?: SwcRootType;
20
+ /**
21
+ * Filter function to determine whether to perform DOM operation.
22
+ * If it returns false, the operation is skipped.
23
+ */
24
+ // filter?: (target: HTMLElement | ShadowRoot, newValue: any, meta:{currentThis: any,helper: HelperHostSet}) => boolean;
25
+ /**
26
+ * Optional loading content to display while an async method is executing.
27
+ */
28
+ // loading?: (helper: HelperHostSet) => any;
29
+ }
30
+
31
+ export interface ApplySlotMetadata {
32
+ propertyKey: string | symbol;
33
+ id: string;
34
+ type: 'method' | 'property';
35
+ options: ApplySlotOptions;
36
+ }
37
+
38
+ export const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');
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 = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {
49
+ // if (!targetEl) return;
50
+ //
51
+ // const doc = win.document;
52
+ //
53
+ // if (pos === 'innerHtml') {
54
+ // targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';
55
+ // return;
56
+ // }
57
+ //
58
+ // if (pos === 'innerText') {
59
+ // if (targetEl.innerText !== undefined) {
60
+ // targetEl.innerText = res !== undefined && res !== null ? String(res) : '';
61
+ // }
62
+ // return;
63
+ // }
64
+ //
65
+ // const isShadowRoot = targetEl instanceof win.ShadowRoot;
66
+ // const nodes = normalizeNodes(res, doc);
67
+ // if (pos === 'replace') {
68
+ // if (!isShadowRoot) targetEl.replaceWith(...nodes);
69
+ // } else if (pos === 'replaceChildren') {
70
+ // targetEl.replaceChildren(...nodes);
71
+ // } else {
72
+ // if (pos === 'beforeEnd') targetEl.append(...nodes);
73
+ // else if (pos === 'afterBegin') targetEl.prepend(...nodes);
74
+ // else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);
75
+ // else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);
76
+ // }
77
+ // };
78
+
79
+ /**
80
+ * @applyNode decorator to surgically add/replace nodes to a target element.
81
+ */
82
+ export function applySlot(id: string, options: ApplySlotOptions = { position: 'replaceChildrenHtml' }): MethodDecorator & PropertyDecorator {
83
+ return (targetObj: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
84
+ const type = descriptor === undefined ? 'property' : 'method';
85
+
86
+ if (type === 'property') {
87
+ Object.defineProperty(targetObj, propertyKey, {
88
+ get(this: any) {
89
+ const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
90
+ return nodeSlot;
91
+ },
92
+ configurable: true,
93
+ enumerable: true,
94
+ })
95
+ // return nodeSlot;
96
+ // return;
97
+ }
98
+
99
+ const constructor = targetObj.constructor;
100
+ let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];
101
+ if (!metaList) {
102
+ metaList = []
103
+ ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);
104
+ }
105
+ metaList.push({ propertyKey, id, type, options });
106
+
107
+
108
+
109
+ if (type === 'method') {
110
+ const original = descriptor.value;
111
+ descriptor.value = function (...args: any[]) {
112
+ ensureInit(this);
113
+
114
+ const conf = getElementConfig(this);
115
+ const currentWin = (this as any)._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as Window);
116
+ const currentDoc = currentWin.document;
117
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, this);
118
+
119
+
120
+ // const getTarget = () => {
121
+ // const r = options.root || 'auto';
122
+ // const applyRoot = (t: any) => {
123
+ // if (!t) return t;
124
+ // if (r === 'auto') return t.shadowRoot || t;
125
+ // if (r === 'shadow') return t.shadowRoot;
126
+ // if (r === 'light') return t;
127
+ // if (r === 'all') return t.shadowRoot || t;
128
+ // return t;
129
+ // };
130
+ //
131
+ // if (selector === '$this') return applyRoot(this);
132
+ // if (selector === '$host') return applyRoot(hostSet.$host);
133
+ // if (selector === '$parentHost') return applyRoot(hostSet.$parentHost);
134
+ // if (selector === '$appHost') return applyRoot(hostSet.$appHost);
135
+ // if (selector === '$firstHost') return applyRoot(hostSet.$firstHost);
136
+ // if (selector === '$lastHost') return applyRoot(hostSet.$lastHost);
137
+ //
138
+ // const targetRoot = applyRoot(this);
139
+ // return targetRoot ? targetRoot.querySelector(selector) : null;
140
+ // };
141
+
142
+ // const targetEl = getTarget();
143
+ const res = original.apply(this, args);
144
+
145
+ // const runApply = (target: any, val: any) => {
146
+ // const pos = options.position || 'beforeEnd';
147
+ //
148
+ // // 사용자가 filter를 명시하면 그 조건으로, 아니면 항상 적용
149
+ // if (!options.filter || options.filter(target, val, {currentThis: this, helper: hostSet})) {
150
+ // applyToDom(target, val, pos, currentWin);
151
+ // }
152
+ // };
153
+
154
+ // if (res instanceof Promise) {
155
+ // // 비동기일 때만 로딩 표시
156
+ // if (targetEl && options.loading) {
157
+ // const loadingRes = options.loading.call(this, hostSet);
158
+ // applyToDom(targetEl, loadingRes, options.position || 'beforeEnd', currentDoc);
159
+ // }
160
+ //
161
+ // return res.then(finalRes => {
162
+ // if (finalRes !== undefined && targetEl) runApply(targetEl, finalRes);
163
+ // return finalRes;
164
+ // });
165
+ // } else {
166
+ // if (res !== undefined && targetEl) runApply(targetEl, res);
167
+ // return res;
168
+ // }
169
+ if (res) {
170
+ const nodeSlot = new NodeSlot(this, `${this._swcId}-${id}`);
171
+ const pos = options.position || 'replaceChildrenHtml';
172
+ const doc = currentWin.document;
173
+
174
+
175
+ // const isShadowRoot = targetEl instanceof win.ShadowRoot;
176
+ // const nodes = normalizeNodes(res, doc);
177
+ if (pos === 'replaceChildrenHtml') {
178
+ nodeSlot.replaceChildrenHtml(res);
179
+ } else if (pos === 'replaceChildrenText') {
180
+ nodeSlot.replaceChildrenText(res);
181
+ } else if (pos === 'appendHtml') {
182
+ nodeSlot.appendHtml(res);
183
+ } else if (pos === 'appendText') {
184
+ nodeSlot.appendText(res);
185
+ } else if (pos === 'prependHtml') {
186
+ nodeSlot.prependHtml(res);
187
+ } else if (pos === 'prependText') {
188
+ nodeSlot.prependText(res);
189
+ } else if (pos === 'clear') {
190
+ nodeSlot.clear();
191
+ }
192
+ }
193
+ return res;
194
+ };
195
+ }
196
+ };
197
+ }
198
+
199
+ // export const findAllApplySlotMetadata = (target: any): Map<string | symbol, ApplySlotMetadata> => {
200
+ export const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {
201
+ const constructor = target instanceof Function ? target : target.constructor;
202
+ return ReflectUtils.getMetadata(APPLY_SLOT_METADATA_KEY, constructor);
203
+ };
204
+
205
+ export function applySlotClear(id: string): MethodDecorator {
206
+ return applySlot(id, { position: 'clear' });
207
+ }
208
+ export function applySlotPrependHtml(id: string): MethodDecorator {
209
+ return applySlot(id, { position: 'prependHtml' });
210
+ }
211
+ export const applySlotPrepend = applySlotPrependHtml;
212
+ export function applySlotPrependText(id: string): MethodDecorator {
213
+ return applySlot(id, { position: 'prependText' });
214
+ }
215
+ export function applySlotAppendHtml(id: string): MethodDecorator {
216
+ return applySlot(id, { position: 'appendHtml' });
217
+ }
218
+ export function applySlotAppendText(id: string): MethodDecorator {
219
+ return applySlot(id, { position: 'appendText' });
220
+ }
221
+ export const applySlotAppend = applySlotAppendHtml;
222
+ export function applySlotReplaceChildrenHtml(id: string): MethodDecorator {
223
+ return applySlot(id, { position: 'replaceChildrenHtml' });
224
+ }
225
+ export const applySlotReplaceChildren = applySlotReplaceChildrenHtml;
226
+ export function applySlotReplaceChildrenText(id: string): MethodDecorator {
227
+ return applySlot(id, { position: 'replaceChildrenText' });
228
+ }
@@ -1,6 +1,6 @@
1
1
  import {ReflectUtils, FunctionUtils, ActionExpression} from '@dooboostore/core';
2
2
  import {getAddEventListenerMetadata} from './addEventListener';
3
- import {ON_INITIALIZE_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata} from './lifecycles';
3
+ import {ON_INITIALIZE_METADATA_KEY, ON_BEFORE_CONNECTED_METADATA_KEY, ON_AFTER_CONNECTED_METADATA_KEY, ON_BEFORE_DISCONNECTED_METADATA_KEY, ON_AFTER_DISCONNECTED_METADATA_KEY, ON_BEFORE_ADOPTED_METADATA_KEY, ON_AFTER_ADOPTED_METADATA_KEY, findAllLifecycleMetadata, getOnConnectedInnerHtmlMetadata, getOnConnectedBeforeMetadata, getOnConnectedAfterMetadata, ON_CONNECTED_COMPLETED_METADATA_KEY} from './lifecycles';
4
4
  import {getEmitCustomEventMetadataList} from './emitCustomEvent';
5
5
  import {findAllAttributeChangedMetadata, convertAttributeValue} from './changedAttributeThis';
6
6
  import {findAllAttributeApplyMetadata} from './applyAttribute';
@@ -10,8 +10,10 @@ import {getQueryAllMetadata} from './queryAll';
10
10
  import {SwcUtils} from '../utils/Utils';
11
11
  import {HTML_TAG_ENTRIES, DOM_EVENT_NAMES} from '../config/config';
12
12
  import {SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot/decorators/inject/Inject';
13
- import {InjectSituationType, HostSet, HelperHostSet} from '../types';
14
- import {ConvertUtils} from '@dooboostore/core-web';
13
+ import {InjectSituationType, HostSet, HelperHostSet, SwcAppInterface} from '../types';
14
+ import {ConvertUtils, NodeSlot} from '@dooboostore/core-web';
15
+ import {isSSR} from "../elements/SwcApp";
16
+ import {findAllApplySlotMetadata} from "./applySlot";
15
17
 
16
18
  // --- Core Interfaces & Types ---
17
19
 
@@ -35,9 +37,9 @@ export const getElementConfig = (target: any): ElementMetadata | undefined => {
35
37
  return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
36
38
  };
37
39
 
38
- export const ensureInit = (inst: any) => {
40
+ export const ensureInit = (inst: any) => { // HTMLElement
39
41
  if (!inst.__swc_initialized) {
40
- inst._swcId = Math.random().toString(36).substring(2, 11);
42
+ inst._swcId = inst?.getAttribute?.('swc-use-ssr') ?? Math.random().toString(36).substring(2, 11);
41
43
  inst._emitHandlers = new Map();
42
44
  inst._boundListeners = [];
43
45
  inst.__swc_initialized = true;
@@ -89,6 +91,12 @@ export const ensureInit = (inst: any) => {
89
91
  delete (inst as any)[meta.propertyKey];
90
92
  });
91
93
  }
94
+ const slotAllList = findAllApplySlotMetadata(target);
95
+ if (slotAllList) {
96
+ slotAllList.filter(it=>it.type === 'property').forEach(meta => {
97
+ delete (inst as any)[meta.propertyKey];
98
+ });
99
+ }
92
100
 
93
101
  // Call constructor script if present
94
102
  const hostSet = SwcUtils.getHostSet(inst);
@@ -143,7 +151,7 @@ const getHandlers = (inst: any) => {
143
151
  return inst.__swc_attributeEventHandlers;
144
152
  };
145
153
 
146
- const setupPrototype = (proto: any) => {
154
+ const setupPrototype = (proto: any, win: Window) => {
147
155
  if (proto.__swc_proto_setup) return;
148
156
  proto.__swc_proto_setup = true;
149
157
 
@@ -177,7 +185,7 @@ const setupPrototype = (proto: any) => {
177
185
  proto._invokeLifecycleMethod = function (methodName: string | symbol, hostSet?: HostSet, extraArgs: any[] = []) {
178
186
  ensureInit(this);
179
187
  if (typeof (this as any)[methodName] !== 'function') return;
180
- const useHostSet = hostSet ?? SwcUtils.getHostSet(this);
188
+ const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(win, this);
181
189
  const app = useHostSet?.$appHost?.simpleApplication;
182
190
  // console.log('---->hh',app, this, methodName);
183
191
  if (app) {
@@ -301,10 +309,10 @@ export const elementDefine =
301
309
  // Get original static observedAttributes before they're overwritten by Object.defineProperty
302
310
  const originalStaticObservedAttributes = (constructor.observedAttributes ?? []) as string[];
303
311
  const mergedObservedAttributes = [...new Set([...(metadata.observedAttributes ?? []), ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map(it => (it.options as any).attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
304
- const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
312
+ // const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
305
313
 
306
314
  const proto = constructor.prototype;
307
- setupPrototype(proto);
315
+ setupPrototype(proto, win);
308
316
 
309
317
  // 값을 기대하지않는다.
310
318
  let helperHostSet: HelperHostSet | null = null;
@@ -314,61 +322,69 @@ export const elementDefine =
314
322
  // connected 됐을시 최신화
315
323
  helperHostSet = SwcUtils.getHelperAndHostSet(win, this as any);
316
324
  const appHost = helperHostSet.$appHost;
325
+ const useSsr = isSSR(this);
326
+ // console.log('isSsr', useSsr, this);
327
+ // console.log('----helperHostSet--->', this, helperHostSet, useSsr)
328
+ // let connectedApp: SwcAppInterface |undefined;
317
329
  try {
318
330
  if (appHost && typeof (appHost as any)._connected === 'function') {
319
- await (appHost as any)._connected(this);
331
+ await (appHost as any)._connected(this);
320
332
  } else if (appHost && typeof (appHost as any)) {
321
- (appHost as any)._connected_safari ??= [];
322
- (appHost as any)._connected_safari.push(this);
333
+ (appHost as any)._connected_safari_and_standby ??= [];
334
+ (appHost as any)._connected_safari_and_standby.push(this);
323
335
  }
324
336
 
325
337
  // const hostSet = SwcUtils.getHostSet(this as any);
326
338
  const conf = getElementConfig(this);
327
339
  const currentWin = (this as any)._resolveWindow(conf);
328
340
 
329
- const shadowMode = conf?.useShadow || connectedInnerHtmlList.find(it => it.options.useShadow)?.options.useShadow;
341
+ const bMethods = getOnConnectedBeforeMetadata(this).filter(it => useSsr ? !it.options.ssrFirst : true);
342
+ // console.log('beforeConnected', bMethods)
343
+ if (bMethods) {
344
+ for (const m of bMethods) await (this as any)._invokeLifecycleMethod(m.propertyKey, helperHostSet);
345
+ }
346
+ (this as any)._executeSwcScript('swc-on-before-connected', helperHostSet);
347
+
348
+ // console.log('vvvvvvvvvvvvvvvu-seSsr-vvvvvvvvvv>', useSsr, this.tagName, this.getAttribute('seq'))
349
+ // // ssr 처리라서 이미 내려준거그대로 상요하면된다 따라서 호출안한다
350
+ const targetConnectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor).filter(it => useSsr ? !it.options.ssrFirst : true);
351
+ const shadowMode = conf?.useShadow || targetConnectedInnerHtmlList.find(it => it.options.useShadow)?.options.useShadow;
330
352
  if (shadowMode && !this.shadowRoot) {
331
353
  const mode = shadowMode === true ? 'open' : shadowMode;
332
354
  this.attachShadow({mode: mode as ShadowRootMode});
333
355
  }
334
356
 
335
- const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
336
- if (bMethods) {
337
- for (const m of bMethods) await (this as any)._invokeLifecycleMethod(m, helperHostSet);
338
- }
339
- (this as any)._executeSwcScript('swc-on-before-connected', helperHostSet);
340
-
341
- if (connectedInnerHtmlList.length > 0) {
357
+ if (targetConnectedInnerHtmlList.length > 0) {
342
358
  let sContent = '',
343
359
  lContent = '';
344
- for (const meta of connectedInnerHtmlList) {
360
+ for (const meta of targetConnectedInnerHtmlList) {
345
361
  // const res = (this as any)[meta.propertyKey]();
346
362
  let res = await (this as any)._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
347
363
  const actionExpression = new ActionExpression(res, {
348
364
  expression: {
349
365
  replace: {
350
- start: meta.options.replaceWrap?.start || '{%{',
351
- end: meta.options.replaceWrap?.end || '}%}'
366
+ start: meta.options.replaceWrap?.start || '[[',
367
+ end: meta.options.replaceWrap?.end || ']]'
352
368
  },
353
369
  callReturn: {
354
- start: meta.options.replaceWrap?.start || '{%{=',
355
- end: meta.options.replaceWrap?.end || '}%}'
370
+ start: meta.options.replaceWrap?.start || '[[=',
371
+ end: meta.options.replaceWrap?.end || ']]'
356
372
  },
357
373
  call: {
358
- start: meta.options.replaceWrap?.start || '{%{@',
359
- end: meta.options.replaceWrap?.end || '}%}'
374
+ start: meta.options.replaceWrap?.start || '[[@',
375
+ end: meta.options.replaceWrap?.end || ']]'
360
376
  }
361
377
  }
362
378
  });
363
379
 
364
380
  actionExpression.getExpressions().filter(it => it.type === 'replace').forEach(it => {
365
- try {
366
- // const helperHostSet22 = SwcUtils.getHelperAndHostSet(win, this as any);
367
- const sr = FunctionUtils.executeReturn({script: it.script, context: this, args: helperHostSet});
368
- actionExpression.replace(it, sr);
369
- } catch (e) {
370
- console.error(`[SWC] Failed to execute connectedInnerHTML:`, e);
371
- }
381
+ actionExpression.replace(it, NodeSlot.slot(`${this._swcId}-${it.script}`));
382
+ // try {
383
+ // const sr = FunctionUtils.executeReturn({script: it.script, context: this, args: helperHostSet});
384
+ // actionExpression.replace(it, sr);
385
+ // } catch (e) {
386
+ // console.error(`[SWC] Failed to execute connectedInnerHTML:`, e);
387
+ // }
372
388
  });
373
389
  res = actionExpression.getUnprocessedTemplate();
374
390
 
@@ -534,9 +550,12 @@ export const elementDefine =
534
550
 
535
551
  if (originalConnected) await (originalConnected.apply(this));
536
552
 
537
- const aMethods = findAllLifecycleMetadata(this, ON_AFTER_CONNECTED_METADATA_KEY);
553
+ const aMethods = getOnConnectedAfterMetadata(this).filter(it => {
554
+ return useSsr ? !it.options.ssrFirst : true;
555
+ });
556
+ // console.log('afterConnected', this.tagName, aMethods, getOnConnectedAfterMetadata(this))
538
557
  if (aMethods) {
539
- for (const m of aMethods) await (this as any)._invokeLifecycleMethod(m, helperHostSet);
558
+ for (const m of aMethods) await (this as any)._invokeLifecycleMethod(m.propertyKey, helperHostSet);
540
559
  }
541
560
  (this as any)._executeSwcScript('swc-on-connected', helperHostSet);
542
561
  (this as any)._executeSwcScript('swc-on-after-connected', helperHostSet);
@@ -554,6 +573,9 @@ export const elementDefine =
554
573
  }
555
574
  }
556
575
  } finally {
576
+ for (let mPropertyKey of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) {
577
+ await (this as any)._invokeLifecycleMethod(mPropertyKey, helperHostSet);
578
+ }
557
579
  if (appHost && typeof (appHost as any)._connectedDone === 'function') {
558
580
  await (appHost as any)._connectedDone(this);
559
581
  }
@@ -564,7 +586,7 @@ export const elementDefine =
564
586
  proto.disconnectedCallback = function () {
565
587
  // const helperHostSet = SwcUtils.getHelperAndHostSet(win, this as any);
566
588
  // Remove from appHost LAST when disconnected
567
- console.log('disconnnnnnnnnnnnnnnnnnn', helperHostSet, this)
589
+ // console.log('disconnnnnnnnnnnnnnnnnnn', helperHostSet, this)
568
590
  const appHost = helperHostSet.$appHost;
569
591
  if (appHost && typeof (appHost as any)._disconnected === 'function') {
570
592
  (appHost as any)._disconnected(this);
@@ -14,3 +14,4 @@ export * from './setProperty';
14
14
  export * from './subscribeSwcAppRouteChangeWhileConnected';
15
15
  export * from './subscribeSwcAppMessageWhileConnected';
16
16
  export * from './publishSwcAppMessage';
17
+ export * from './applySlot';