@dooboostore/simple-web-component 1.0.28 → 1.0.30

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 (94) hide show
  1. package/README.md +437 -25
  2. package/dist/cjs/decorators/attribute.js +2 -1
  3. package/dist/cjs/decorators/attribute.js.map +2 -2
  4. package/dist/cjs/decorators/elementDefine.js +8 -2
  5. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  6. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  7. package/dist/cjs/decorators/index.js +1 -0
  8. package/dist/cjs/decorators/index.js.map +2 -2
  9. package/dist/cjs/decorators/lifecycles.js +4 -0
  10. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  11. package/dist/cjs/decorators/setProperty.js +97 -0
  12. package/dist/cjs/decorators/setProperty.js.map +7 -0
  13. package/dist/cjs/elements/SwcAppEngine.js +3 -3
  14. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  15. package/dist/cjs/elements/SwcAppMixin.js +44 -6
  16. package/dist/cjs/elements/SwcAppMixin.js.map +3 -3
  17. package/dist/cjs/elements/SwcAsync.js +4 -1
  18. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  19. package/dist/cjs/elements/SwcChoose.js +54 -38
  20. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  21. package/dist/cjs/elements/register.js +131 -39
  22. package/dist/cjs/elements/register.js.map +2 -2
  23. package/dist/cjs/index.js +2 -1
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils/Utils.js +30 -1
  27. package/dist/cjs/utils/Utils.js.map +2 -2
  28. package/dist/esm/decorators/attribute.js +2 -1
  29. package/dist/esm/decorators/attribute.js.map +2 -2
  30. package/dist/esm/decorators/elementDefine.js +8 -2
  31. package/dist/esm/decorators/elementDefine.js.map +2 -2
  32. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  33. package/dist/esm/decorators/index.js +1 -0
  34. package/dist/esm/decorators/index.js.map +2 -2
  35. package/dist/esm/decorators/lifecycles.js +4 -0
  36. package/dist/esm/decorators/lifecycles.js.map +2 -2
  37. package/dist/esm/decorators/setProperty.js +78 -0
  38. package/dist/esm/decorators/setProperty.js.map +7 -0
  39. package/dist/esm/elements/SwcAppEngine.js +3 -3
  40. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  41. package/dist/esm/elements/SwcAppMixin.js +44 -6
  42. package/dist/esm/elements/SwcAppMixin.js.map +3 -3
  43. package/dist/esm/elements/SwcAsync.js +4 -1
  44. package/dist/esm/elements/SwcAsync.js.map +2 -2
  45. package/dist/esm/elements/SwcChoose.js +54 -38
  46. package/dist/esm/elements/SwcChoose.js.map +2 -2
  47. package/dist/esm/elements/register.js +131 -39
  48. package/dist/esm/elements/register.js.map +2 -2
  49. package/dist/esm/index.js +2 -1
  50. package/dist/esm/index.js.map +2 -2
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils/Utils.js +30 -1
  53. package/dist/esm/utils/Utils.js.map +2 -2
  54. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +118 -4
  55. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  56. package/dist/types/decorators/attribute.d.ts.map +1 -1
  57. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  58. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  59. package/dist/types/decorators/index.d.ts +1 -0
  60. package/dist/types/decorators/index.d.ts.map +1 -1
  61. package/dist/types/decorators/lifecycles.d.ts +2 -0
  62. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  63. package/dist/types/decorators/setProperty.d.ts +13 -0
  64. package/dist/types/decorators/setProperty.d.ts.map +1 -0
  65. package/dist/types/elements/SwcAppMixin.d.ts +7 -2
  66. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  67. package/dist/types/elements/SwcAsync.d.ts.map +1 -1
  68. package/dist/types/elements/SwcChoose.d.ts +1 -1
  69. package/dist/types/elements/SwcChoose.d.ts.map +1 -1
  70. package/dist/types/elements/register.d.ts +3 -1
  71. package/dist/types/elements/register.d.ts.map +1 -1
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/index.d.ts.map +1 -1
  74. package/dist/types/types.d.ts +3 -0
  75. package/dist/types/types.d.ts.map +1 -1
  76. package/dist/types/utils/Utils.d.ts +13 -0
  77. package/dist/types/utils/Utils.d.ts.map +1 -1
  78. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +118 -4
  79. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  80. package/package.json +4 -4
  81. package/src/decorators/attribute.ts +6 -1
  82. package/src/decorators/elementDefine.ts +12 -4
  83. package/src/decorators/emitCustomEvent.ts +1 -0
  84. package/src/decorators/index.ts +1 -0
  85. package/src/decorators/lifecycles.ts +3 -0
  86. package/src/decorators/setProperty.ts +97 -0
  87. package/src/elements/SwcAppEngine.ts +3 -3
  88. package/src/elements/SwcAppMixin.ts +77 -14
  89. package/src/elements/SwcAsync.ts +5 -1
  90. package/src/elements/SwcChoose.ts +76 -37
  91. package/src/elements/register.ts +158 -39
  92. package/src/index.ts +3 -1
  93. package/src/types.ts +3 -0
  94. package/src/utils/Utils.ts +55 -1
@@ -23,6 +23,7 @@ module.exports = __toCommonJS(SwcAppMixin_exports);
23
23
  var import_SwcAppEngine = require("./SwcAppEngine");
24
24
  var import_Utils = require("../utils/Utils");
25
25
  var import_core = require("@dooboostore/core");
26
+ var import_lifecycles = require("../decorators/lifecycles");
26
27
  var import_subscribeSwcAppRouteChange = require("../decorators/subscribeSwcAppRouteChange");
27
28
  function SwcAppMixin(Base) {
28
29
  return class extends Base {
@@ -30,6 +31,7 @@ function SwcAppMixin(Base) {
30
31
  super(...arguments);
31
32
  this.__swc_engine = new import_SwcAppEngine.SwcAppEngine(this);
32
33
  this._swc_connected_instance = /* @__PURE__ */ new Set();
34
+ this._connected_safari = [];
33
35
  }
34
36
  get simpleApplication() {
35
37
  return this.__swc_engine.simpleApplication;
@@ -37,6 +39,10 @@ function SwcAppMixin(Base) {
37
39
  get router() {
38
40
  return this.__swc_engine.router;
39
41
  }
42
+ // constructor() {
43
+ // super();
44
+ // console.log('cccccccccccccccccccccc');
45
+ // }
40
46
  _invokeRouteChangeSubscribers(instance, re) {
41
47
  const routeChangeSubscribers = (0, import_subscribeSwcAppRouteChange.getSubscribeSwcAppRouteChangeMetadata)(instance);
42
48
  if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {
@@ -64,7 +70,7 @@ function SwcAppMixin(Base) {
64
70
  }
65
71
  const filterPassed = !filter || filter(this.router);
66
72
  if (pathMatched && filterPassed) {
67
- instance[methodName]?.(re, pathData || {});
73
+ instance[methodName]?.({ ...re, pathData });
68
74
  }
69
75
  });
70
76
  }
@@ -72,8 +78,11 @@ function SwcAppMixin(Base) {
72
78
  _connected(instance) {
73
79
  if (instance) {
74
80
  this._swc_connected_instance.add(instance);
75
- if (this.router && this._lastRouterEvent) {
76
- this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);
81
+ if (this.simpleApplication) {
82
+ this._invokeOnConnectedSwcAppStarted(instance);
83
+ if (this.router && this._lastRouterEvent) {
84
+ this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);
85
+ }
77
86
  }
78
87
  }
79
88
  }
@@ -120,14 +129,33 @@ function SwcAppMixin(Base) {
120
129
  throw e;
121
130
  }
122
131
  }
132
+ this._connected_safari.forEach((instance) => {
133
+ this._swc_connected_instance.add(instance);
134
+ });
135
+ this._swc_connected_instance.forEach((instance) => {
136
+ this._invokeOnConnectedSwcAppStarted(instance);
137
+ });
123
138
  if (!this._routerSubscription && this.router) {
124
139
  this._routerSubscription = this.router.observable.subscribe((route) => {
125
140
  this._handleRouteChange(route);
126
141
  });
142
+ const config2 = this.__swc_engine.config;
143
+ if (config2?.path) {
144
+ this.router.go(config2.path);
145
+ }
146
+ }
147
+ }
148
+ _invokeOnConnectedSwcAppStarted(instance) {
149
+ const startedMethods = (0, import_lifecycles.findAllLifecycleMetadata)(instance, import_lifecycles.ON_CONNECTED_SWC_APP_METADATA_KEY);
150
+ if (startedMethods) {
151
+ for (const m of startedMethods) {
152
+ instance._invokeLifecycleMethod(m);
153
+ }
127
154
  }
128
155
  }
129
156
  connectedCallback() {
130
- if (super.connectedCallback) super.connectedCallback();
157
+ if (super.connectedCallback)
158
+ super.connectedCallback();
131
159
  const configStr = this.getAttribute("swc-get-application-config");
132
160
  const win = this.ownerDocument?.defaultView || window;
133
161
  if (configStr && win) {
@@ -145,7 +173,8 @@ function SwcAppMixin(Base) {
145
173
  this.__swc_engine?.config?.onConnected?.(this);
146
174
  }
147
175
  disconnectedCallback() {
148
- if (super.disconnectedCallback) super.disconnectedCallback();
176
+ if (super.disconnectedCallback)
177
+ super.disconnectedCallback();
149
178
  this._routerSubscription?.unsubscribe();
150
179
  this._routerSubscription = void 0;
151
180
  this._lastRouterEvent = void 0;
@@ -153,7 +182,16 @@ function SwcAppMixin(Base) {
153
182
  this.__swc_engine?.config?.onDisconnected?.(this);
154
183
  }
155
184
  async routing(path) {
156
- await this.__swc_engine.router?.go(path);
185
+ await this.router?.go(path);
186
+ }
187
+ back() {
188
+ this.router?.back();
189
+ }
190
+ forward() {
191
+ this.router?.forward();
192
+ }
193
+ reload() {
194
+ this.router?.reload();
157
195
  }
158
196
  };
159
197
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcAppMixin.ts"],
4
- "sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { RouterEventType } from '@dooboostore/core-web';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n routeChangeSubscribers.forEach((metadata: any) => {\n const methodName = metadata.propertyKey || metadata;\n const pathPattern = metadata.pathPattern;\n const filter = metadata.filter;\n\n // Path pattern matching (support both string and array)\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n // pathPattern\uC774 \uC5C6\uC73C\uBA74 \uBAA8\uB4E0 \uACBD\uB85C \uB9E4\uCE6D (\uC640\uC77C\uB4DC\uCE74\uB4DC)\n pathMatched = true;\n pathData = {};\n } else if (Array.isArray(pathPattern)) {\n // \uBC30\uC5F4: \uD558\uB098\uB77C\uB3C4 \uB9E4\uCE6D\uB418\uBA74 OK\n for (const pattern of pathPattern) {\n const data = SwcUtils.parsePathPattern(pattern, re.path || '/');\n if (data !== null) {\n pathMatched = true;\n pathData = data;\n break;\n }\n }\n } else {\n // \uBB38\uC790\uC5F4\n pathData = SwcUtils.parsePathPattern(pathPattern, re.path || '/');\n pathMatched = pathData !== null;\n }\n\n // Filter validation\n const filterPassed = !filter || filter(this.router!);\n\n // Invoke method if conditions pass\n if (pathMatched && filterPassed) {\n instance[methodName]?.(re, pathData || {});\n }\n });\n }\n }\n\n _connected(instance: any) {\n // console.log('------------------>', instance);\n if (instance) {\n this._swc_connected_instance.add(instance);\n\n // Notify current route subscribers immediately after connection\n if (this.router && this._lastRouterEvent) {\n this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);\n }\n }\n }\n\n _disconnected(instance: any) {\n if (instance) {\n this._swc_connected_instance.delete(instance);\n }\n }\n\n _handleRouteChange(route: RouterEventType) {\n if (route.triggerPoint === 'end') {\n // Iterate through all connected component instances\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeRouteChangeSubscribers(instance, route);\n });\n }\n\n // Save last router event\n this._lastRouterEvent = route;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n const swcConfig = {\n routeType: 'element',\n window: config.window,\n ...config\n } as SwcConfigType;\n\n const mode = config?.connectMode || 'direct';\n\n if (mode === 'direct') {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n } else if (mode === 'swap' && !this.parentNode) {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n\n const clonedApp = this.cloneNode(true) as any;\n clonedApp.style.display = 'none';\n this.parentNode.insertBefore(clonedApp, this.nextSibling);\n\n try {\n await clonedApp.connect({ ...(config || {}), connectMode: 'direct' });\n if (this.parentNode) {\n this.parentNode.removeChild(this);\n }\n clonedApp.setAttribute('swc-connect-mode', 'swap');\n clonedApp.style.display = '';\n } catch (e) {\n if (clonedApp.parentNode) {\n clonedApp.parentNode.removeChild(clonedApp);\n }\n throw e;\n }\n }\n\n // console.log('vvvvvvv222222', this.router);\n // Subscribe to router changes after connect\n if (!this._routerSubscription && this.router) {\n this._routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n // console.log('Route changed:', route);\n this._handleRouteChange(route);\n });\n\n // Navigate to initial path if specified\n // const config = this.__swc_engine.config;\n // if (config?.path) {\n // this.router.go(config.path);\n // }\n }\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n\n const configStr = this.getAttribute('swc-get-application-config');\n const win = this.ownerDocument?.defaultView || window;\n if (configStr && win) {\n try {\n // console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))\n const userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, SwcUtils.findNearestSwcHost(this))\n });\n this.connect(userConfig);\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Script execution failed:', e);\n }\n }\n\n this.__swc_engine?.config?.onConnected?.(this);\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this._routerSubscription?.unsubscribe();\n this._routerSubscription = undefined;\n this._lastRouterEvent = undefined;\n this.__swc_engine.disconnect();\n this.__swc_engine?.config?.onDisconnected?.(this);\n }\n\n async routing(path: string) {\n await this.__swc_engine.router?.go(path);\n }\n };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAoE;AAEpE,mBAAyB;AACzB,kBAA4C;AAE5C,wCAAsD;AAE/C,SAAS,YAA6D,MAAS;AACpF,SAAO,cAAc,KAAgC;AAAA,IAA9C;AAAA;AACL,0BAAe,IAAI,iCAAa,IAAW;AAC3C,qCAA0B,oBAAI,IAAS;AAAA;AAAA,IAIvC,IAAI,oBAAoB;AACtB,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,IAAI,SAAS;AACX,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IAEA,8BAA8B,UAAe,IAAqB;AAChE,YAAM,6BAAyB,yEAAsC,QAAQ;AAC7E,UAAI,0BAA0B,MAAM,QAAQ,sBAAsB,GAAG;AACnE,+BAAuB,QAAQ,CAAC,aAAkB;AAChD,gBAAM,aAAa,SAAS,eAAe;AAC3C,gBAAM,cAAc,SAAS;AAC7B,gBAAM,SAAS,SAAS;AAGxB,cAAI,cAAc;AAClB,cAAI,WAAgB;AAEpB,cAAI,CAAC,aAAa;AAEhB,0BAAc;AACd,uBAAW,CAAC;AAAA,UACd,WAAW,MAAM,QAAQ,WAAW,GAAG;AAErC,uBAAW,WAAW,aAAa;AACjC,oBAAM,OAAO,sBAAS,iBAAiB,SAAS,GAAG,QAAQ,GAAG;AAC9D,kBAAI,S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,WAAK,cAAc,QAAQ,iBAAiB,IAAI;AAAA,IAClD;AAAA,IAEA,MAAM,QAAQ,MAAc;AAC1B,YAAM,KAAK,aAAa,QAAQ,GAAG,IAAI;AAAA,IACzC;AAAA,EACF;AACF;",
6
- "names": []
4
+ "sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { Router, RouterEventType } from '@dooboostore/core-web';\nimport { ON_CONNECTED_SWC_APP_METADATA_KEY, findAllLifecycleMetadata } from '../decorators/lifecycles';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n //@ts-ignore\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n /*\n 사파리 is 일경우\n <script src=\"https://unpkg.com/@ungap/custom-elements\"></script>\n 이걸사용하는데 is 대응하는거다 그런데 이때 처리되는 순서가 크롬이나 표준에서는 부모부터 만들어지고 자식들이 만들어지는데\n 저 polyfill에서는 자식부터 만들어지고 부모가 만들어진다 is일때 아 .. 이문제때문에 자식이 _connected_safari 에 강제로 자기자식넣어준다\n */\n _connected_safari = [];\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n // constructor() {\n // super();\n // console.log('cccccccccccccccccccccc');\n // }\n\n _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n routeChangeSubscribers.forEach((metadata: any) => {\n const methodName = metadata.propertyKey || metadata;\n const pathPattern = metadata.pathPattern;\n const filter = metadata.filter;\n\n // Path pattern matching (support both string and array)\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n // pathPattern이 없으면 모든 경로 매칭 (와일드카드)\n pathMatched = true;\n pathData = {};\n } else if (Array.isArray(pathPattern)) {\n // 배열: 하나라도 매칭되면 OK\n for (const pattern of pathPattern) {\n const data = SwcUtils.parsePathPattern(pattern, re.path || '/');\n if (data !== null) {\n pathMatched = true;\n pathData = data;\n break;\n }\n }\n } else {\n // 문자열\n pathData = SwcUtils.parsePathPattern(pathPattern, re.path || '/');\n pathMatched = pathData !== null;\n }\n\n // Filter validation\n const filterPassed = !filter || filter(this.router!);\n\n // Invoke method if conditions pass\n if (pathMatched && filterPassed) {\n instance[methodName]?.({...re, pathData: pathData});\n }\n });\n }\n }\n\n _connected(instance: any) {\n // console.log('appmixin--> connected', this, instance);\n if (instance) {\n this._swc_connected_instance.add(instance);\n if (this.simpleApplication) {\n this._invokeOnConnectedSwcAppStarted(instance);\n // Notify current route subscribers immediately after connection\n if (this.router && this._lastRouterEvent) {\n this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);\n }\n }\n }\n }\n\n _disconnected(instance: any) {\n if (instance) {\n this._swc_connected_instance.delete(instance);\n }\n }\n\n _handleRouteChange(route: RouterEventType) {\n if (route.triggerPoint === 'end') {\n // Iterate through all connected component instances\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeRouteChangeSubscribers(instance, route);\n });\n }\n\n // Save last router event\n this._lastRouterEvent = route;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n const swcConfig = {\n routeType: 'element',\n window: config.window,\n ...config\n } as SwcConfigType;\n\n const mode = config?.connectMode || 'direct';\n\n if (mode === 'direct') {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n } else if (mode === 'swap' && !this.parentNode) {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n\n const clonedApp = this.cloneNode(true) as any;\n clonedApp.style.display = 'none';\n this.parentNode.insertBefore(clonedApp, this.nextSibling);\n\n try {\n await clonedApp.connect({ ...(config || {}), connectMode: 'direct' });\n if (this.parentNode) {\n this.parentNode.removeChild(this);\n }\n clonedApp.setAttribute('swc-connect-mode', 'swap');\n clonedApp.style.display = '';\n } catch (e) {\n if (clonedApp.parentNode) {\n clonedApp.parentNode.removeChild(clonedApp);\n }\n throw e;\n }\n }\n\n // 사파리일떄 예외이다 is 일때 polyfill되는데 이떄 부모부터 만들어지는게 아니라 자식부터 만들어진다 그래서 부모가 만들어질때 자식들이 이미 만들어져있어서 부모가 자식들을 등록해주는 형태로 강제로 등록해준다\n this._connected_safari.forEach((instance: any) => {\n this._swc_connected_instance.add(instance);\n });\n // Invoke @onConnectedSwcApp lifecycle methods on all connected component instances\n // const hostSet = SwcUtils.getHostSet(this as any);\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeOnConnectedSwcAppStarted(instance);\n });\n\n // Safari fix: Manually scan DOM tree and register any SWC components that couldn't find parent\n // This handles the case where is=\"\" elements get upgraded in child-first order\n // const allElements = (this as any).querySelectorAll('*');\n // for (const el of allElements) {\n // const isConnected = (el as any).__swc_connected;\n // if (!isConnected && typeof (el as any)._resolveWindow === 'function') {\n // // Element is an SWC component but hasn't registered with app yet\n // try {\n // this._connected(el);\n // if ((el as any)._invokeOnConnectedSwcAppStarted) {\n // this._invokeOnConnectedSwcAppStarted(el);\n // }\n // } catch (e) {\n // console.warn('[SWC] Error registering discovered element:', el.tagName, e);\n // }\n // }\n // }\n\n // Subscribe to router changes after connect\n if (!this._routerSubscription && this.router) {\n this._routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n // console.log('Route changed:', route);\n this._handleRouteChange(route);\n });\n // Navigate to initial path if specified\n const config = this.__swc_engine.config;\n if (config?.path) {\n this.router.go(config.path);\n }\n }\n }\n\n _invokeOnConnectedSwcAppStarted(instance: any) {\n const startedMethods = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY);\n if (startedMethods) {\n for (const m of startedMethods) {\n instance._invokeLifecycleMethod(m);\n }\n }\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n\n const configStr = this.getAttribute('swc-get-application-config');\n const win = this.ownerDocument?.defaultView || window;\n if (configStr && win) {\n try {\n // console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))\n const userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, SwcUtils.findNearestSwcHost(this))\n });\n this.connect(userConfig);\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Script execution failed:', e);\n }\n }\n\n this.__swc_engine?.config?.onConnected?.(this);\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this._routerSubscription?.unsubscribe();\n this._routerSubscription = undefined;\n this._lastRouterEvent = undefined;\n this.__swc_engine.disconnect();\n this.__swc_engine?.config?.onDisconnected?.(this);\n }\n\n async routing(path: string) {\n await this.router?.go(path);\n }\n\n back(): void {\n this.router?.back();\n }\n\n forward(): void {\n this.router?.forward();\n }\n\n reload(): void {\n this.router?.reload();\n }\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;0BAAoE;AAEpE,mBAAyB;AACzB,kBAA4C;AAE5C,wBAA4E;AAC5E,wCAAsD;AAEhD,SAAU,YAA6D,MAAO;AAElF,SAAO,cAAc,KAAI;IAAlB,cAAA;;AACL,WAAA,eAAe,IAAI,iCAAa,IAAW;AAC3C,WAAA,0BAA0B,oBAAI,IAAG;AAUjC,WAAA,oBAAoB,CAAA;IA8NtB;IA7NE,IAAI,oBAAiB;AACnB,aAAO,KAAK,aAAa;IAC3B;IACA,IAAI,SAAM;AACR,aAAO,KAAK,aAAa;IAC3B;;;;;IAOA,8BAA8B,UAAe,IAAmB;AAC9D,YAAM,6BAAyB,yEA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BAAW,KAAK,gBAAgB;AAC9B,mBAAS,uBAAuB,CAAC;QACnC;MACF;IACF;IAEA,oBAAiB;AAEf,UAAI,MAAM;AAAmB,cAAM,kBAAiB;AAEpD,YAAM,YAAY,KAAK,aAAa,4BAA4B;AAChE,YAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAI,aAAa,KAAK;AACpB,YAAI;AAEF,gBAAM,aAAa,0BAAc,cAAc;YAC7C,QAAQ;YACR,SAAS;YACT,MAAM,sBAAS,oBAAoB,KAAK,sBAAS,mBAAmB,IAAI,CAAC;WAC1E;AACD,eAAK,QAAQ,UAAU;QACzB,SAAS,GAAG;AACV,kBAAQ,MAAM,6CAA6C,CAAC;QAC9D;MACF;AAEA,WAAK,cAAc,QAAQ,cAAc,IAAI;IAC/C;IAEA,uBAAoB;AAElB,UAAI,MAAM;AAAsB,cAAM,qBAAoB;AAC1D,WAAK,qBAAqB,YAAW;AACrC,WAAK,sBAAsB;AAC3B,WAAK,mBAAmB;AACxB,WAAK,aAAa,WAAU;AAC5B,WAAK,cAAc,QAAQ,iBAAiB,IAAI;IAClD;IAEA,MAAM,QAAQ,MAAY;AACxB,YAAM,KAAK,QAAQ,GAAG,IAAI;IAC5B;IAEA,OAAI;AACF,WAAK,QAAQ,KAAI;IACnB;IAEA,UAAO;AACL,WAAK,QAAQ,QAAO;IACtB;IAEA,SAAM;AACJ,WAAK,QAAQ,OAAM;IACrB;;AAEJ;",
6
+ "names": ["config"]
7
7
  }
@@ -62,8 +62,10 @@ class SwcAsync extends HTMLTemplateElement {
62
62
  }
63
63
  refresh() {
64
64
  const script = this.getAttribute("on-get-value");
65
- if (!script)
65
+ if (!script) {
66
+ this.render("default");
66
67
  return;
68
+ }
67
69
  const win = this.ownerDocument?.defaultView || window;
68
70
  const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
69
71
  if (result instanceof Promise) {
@@ -108,6 +110,7 @@ class SwcAsync extends HTMLTemplateElement {
108
110
  this._nodes = [];
109
111
  }
110
112
  connectedCallback() {
113
+ console.log("[SwcAsync] connectedCallback called");
111
114
  this.refresh();
112
115
  }
113
116
  disconnectedCallback() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcAsync.ts"],
4
- "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) return;\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n\n if (result instanceof Promise) {\n this.render('loading');\n result\n .then(v => {\n this._value = v;\n this.render('success');\n })\n .catch(e => this.render('error'));\n } else {\n this._value = result;\n this.render('success');\n }\n }\n\n private render(state: string) {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,iBAAiB,oBAAmB;EAAjD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EAsFxB;EApFU,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,sBAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,UAAO;AACb,UAAM,SAAS,KAAK,aAAa,cAAc;AAC/C,QAAI,CAA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AK;MAC1B;IACF;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA5DQ,WAAA;MADP,kDAAqB,cAAc;;;;;",
4
+ "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) {\n this.render('default');\n return;\n }\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n\n if (result instanceof Promise) {\n this.render('loading');\n result\n .then(v => {\n this._value = v;\n this.render('success');\n })\n .catch(e => this.render('error'));\n } else {\n this._value = result;\n this.render('success');\n }\n }\n\n private render(state: string) {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n const clone = t.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n console.log('[SwcAsync] connectedCallback called');\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,iBAAiB,oBAAmB;EAAjD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EA0FxB;EAxFU,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,sBAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,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B,kBAAkB,SAAS;AAEtD,UAAI,WAAW,KAAK,eAAe;AACjC,eAAO,aAAa,OAAO,KAAK,WAAW;MAC7C,OAAO;AACL,eAAO,YAAY,KAAK;MAC1B;IACF;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,YAAQ,IAAI,qCAAqC;AACjD,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAhEQ,WAAA;MADP,kDAAqB,cAAc;;;;;",
6
6
  "names": []
7
7
  }
@@ -37,6 +37,7 @@ class SwcChoose extends HTMLTemplateElement {
37
37
  super(...arguments);
38
38
  this._nodes = [];
39
39
  this._value = null;
40
+ this._previousTemplate = null;
40
41
  }
41
42
  get value() {
42
43
  return this._value;
@@ -45,70 +46,85 @@ class SwcChoose extends HTMLTemplateElement {
45
46
  this._value = nv;
46
47
  this.render();
47
48
  }
48
- _resolvePortal() {
49
- const portalScript = this.getAttribute("on-get-portal");
50
- if (!portalScript)
51
- return this.parentElement;
52
- const win = this.ownerDocument?.defaultView || window;
53
- const res = import_core.FunctionUtils.executeReturn({
54
- script: portalScript,
55
- context: this,
56
- args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
57
- });
58
- if (res instanceof HTMLElement)
59
- return res;
60
- if (typeof res === "string")
61
- return win.document.querySelector(res);
62
- return this.parentElement;
63
- }
64
49
  _executeCloneCallback(attr, args) {
65
50
  const script = this.getAttribute(attr);
66
51
  if (!script)
67
52
  return;
68
53
  import_core.FunctionUtils.execute({ script, context: this, args });
69
54
  }
70
- refresh() {
71
- const script = this.getAttribute("on-get-value");
72
- if (!script) {
55
+ refresh(valueAttr) {
56
+ valueAttr ?? (valueAttr = this.getAttribute("value"));
57
+ if (valueAttr === null) {
73
58
  this.value = null;
74
59
  return;
75
60
  }
76
- const win = this.ownerDocument?.defaultView || window;
77
- const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
78
- this.value = result;
61
+ if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
62
+ const script = valueAttr.slice(2, -2).trim();
63
+ const win = this.ownerDocument?.defaultView || window;
64
+ const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
65
+ this.value = result;
66
+ } else {
67
+ this.value = valueAttr;
68
+ }
79
69
  }
80
70
  render() {
81
- this.cleanup();
82
- const portal = this._resolvePortal();
83
- if (!portal)
84
- return;
85
71
  const win = this.ownerDocument?.defaultView || window;
86
72
  const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
87
73
  const templates = Array.from(this.content.querySelectorAll("template"));
88
74
  let selected = null;
89
75
  for (const t of templates) {
90
- if (t.getAttribute("is") === "swc-when" && String(t.getAttribute("value")) === String(this._value)) {
91
- selected = t;
92
- break;
76
+ if (t.getAttribute("is") === "swc-when") {
77
+ let matches = false;
78
+ const value = t.getAttribute("value") || "";
79
+ if (value.startsWith("{{") && value.endsWith("}}")) {
80
+ const script = value.slice(2, -2).trim();
81
+ const result = import_core.FunctionUtils.executeReturn({
82
+ script,
83
+ context: t,
84
+ args: { ...helperSet, $value: this._value }
85
+ });
86
+ matches = result === true;
87
+ } else {
88
+ matches = String(value) === String(this._value);
89
+ }
90
+ if (matches) {
91
+ selected = t;
92
+ break;
93
+ }
93
94
  }
94
95
  }
95
96
  const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
97
+ const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
98
+ const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
99
+ if (shouldSkip) {
100
+ return;
101
+ }
102
+ this.cleanup();
103
+ this._previousTemplate = target;
96
104
  if (target) {
97
105
  const clone = target.content.cloneNode(true);
98
106
  this._nodes = Array.from(clone.childNodes);
99
107
  const elements = this._nodes.filter((n) => n.nodeType === 1);
100
108
  const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
101
109
  this._nodes.forEach((n, nodeIdx) => {
102
- if (n instanceof HTMLElement)
103
- n.__swc_host = this;
104
110
  this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
111
+ if (n instanceof HTMLElement) {
112
+ Array.from(n.attributes).forEach((attr) => {
113
+ const value = attr.value || "";
114
+ if (value.startsWith("{{") && value.endsWith("}}")) {
115
+ const script = value.slice(2, -2).trim();
116
+ const result = import_core.FunctionUtils.executeReturn({
117
+ script,
118
+ context: n,
119
+ args: { ...groupArgs, $value: this._value }
120
+ });
121
+ n.setAttribute(attr.name, String(result));
122
+ }
123
+ });
124
+ }
105
125
  });
106
126
  this._executeCloneCallback("on-clone-nodes", groupArgs);
107
- if (portal === this.parentElement) {
108
- portal.insertBefore(clone, this.nextSibling);
109
- } else {
110
- portal.appendChild(clone);
111
- }
127
+ this.parentElement?.insertBefore(clone, this.nextSibling);
112
128
  }
113
129
  }
114
130
  cleanup() {
@@ -123,9 +139,9 @@ class SwcChoose extends HTMLTemplateElement {
123
139
  }
124
140
  }
125
141
  __decorate([
126
- (0, import_changedAttributeHost.changedAttributeHost)("on-get-value"),
142
+ (0, import_changedAttributeHost.changedAttributeHost)("value"),
127
143
  __metadata("design:type", Function),
128
- __metadata("design:paramtypes", []),
144
+ __metadata("design:paramtypes", [String]),
129
145
  __metadata("design:returntype", void 0)
130
146
  ], SwcChoose.prototype, "refresh", null);
131
147
  //# sourceMappingURL=SwcChoose.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcChoose.ts"],
4
- "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _resolvePortal(): Element | null {\n const portalScript = this.getAttribute('on-get-portal');\n if (!portalScript) return this.parentElement;\n\n const win = this.ownerDocument?.defaultView || window;\n const res = FunctionUtils.executeReturn({\n script: portalScript,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n\n if (res instanceof HTMLElement) return res;\n if (typeof res === 'string') return win.document.querySelector(res);\n return this.parentElement;\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('on-get-value')\n private refresh() {\n const script = this.getAttribute('on-get-value');\n if (!script) {\n this.value = null;\n return;\n }\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n this.value = result;\n }\n\n private render() {\n this.cleanup();\n const portal = this._resolvePortal();\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when' && String(t.getAttribute('value')) === String(this._value)) {\n selected = t;\n break;\n }\n }\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n if (target) {\n const clone = target.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n this._nodes.forEach((n, nodeIdx) => {\n if (n instanceof HTMLElement) (n as any).__swc_host = this;\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n if (portal === this.parentElement) {\n portal.insertBefore(clone, this.nextSibling);\n } else {\n portal.appendChild(clone);\n }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;EA8FxB;EA5FE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEQ,iBAAc;AACpB,UAAM,eAAe,KAAK,aAAa,eAAe;AACtD,QAAI,CAAC;AAAc,aAAO,KAAK;AAE/B,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,MAAM,0BAAc,cAAc;MACtC,QAAQ;MACR,SAAS;MACT,MAAM,sBAAS,oBAAoB,KAAK,IAAI;KAC7C;AAED,QAAI,eAAe;AAAa,aAAO;AACvC,QAAI,OAAO,QAAQ;AAAU,aAAO,IAAI,SAAS,cAAc,GAAG;AAClE,WAAO,KAAK;EACd;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,UAAO;AACb,UAAM,SAAS,KAAK,aAAa,cAAc;AAC/C,QAAI,CAAC,QAAQ;AACX,WAAK,QAAQ;AACb;IACF;AACA,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,SAAS,0BAAc,cAAc,EAAE,QAA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,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA5DQ,WAAA;MADP,kDAAqB,cAAc;;;;;",
4
+ "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\nexport class SwcChoose extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _value: any = null;\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n set value(nv: any) {\n this._value = nv;\n this.render();\n }\n\n private _executeCloneCallback(attr: string, args: any) {\n const script = this.getAttribute(attr);\n if (!script) return;\n FunctionUtils.execute({ script, context: this, args });\n }\n\n @changedAttributeHost('value')\n private refresh(valueAttr?: string | null) {\n valueAttr ??= this.getAttribute('value');\n if (valueAttr === null) {\n this.value = null;\n return;\n }\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (valueAttr.startsWith('{{') && valueAttr.endsWith('}}')) {\n const script = valueAttr.slice(2, -2).trim();\n const win = this.ownerDocument?.defaultView || window;\n const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });\n this.value = result;\n } else {\n // 일반 문자열 값\n this.value = valueAttr;\n }\n }\n\n private render() {\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when') {\n let matches = false;\n const value = t.getAttribute('value') || '';\n\n // {{ }} 브레이스로 감싸진 값은 스크립트 실행\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: t,\n args: { ...helperSet, $value: this._value }\n });\n // console.log('rrrrrrrrrrrrrr', result);\n matches = result === true;\n } else {\n // 일반 문자열 비교 (기존 방식)\n matches = String(value) === String(this._value);\n }\n\n if (matches) {\n selected = t;\n break;\n }\n }\n }\n\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n // skip-if-same attribute가 있고 이전과 같은 template이면 렌더링 스킵\n // 최상위 skip-if-same 또는 각 when/otherwise의 skip-if-same 체크\n const targetHasSkipIfSame = target?.hasAttribute('skip-if-same');\n const shouldSkip = (this.hasAttribute('skip-if-same') || targetHasSkipIfSame) && this._previousTemplate === target;\n if (shouldSkip) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n const clone = target.content.cloneNode(true) as DocumentFragment;\n this._nodes = Array.from(clone.childNodes);\n const elements = this._nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };\n\n // 복제된 최상위 요소들은 SwcChoose의 직접 자식이 될 것이므로 __swc_host 설정 안 함\n this._nodes.forEach((n, nodeIdx) => {\n // if (n instanceof HTMLElement) (n as any).__swc_host = this; // 제거: 부모 체인 유지\n this._executeCloneCallback('on-clone-node', { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });\n\n // Attribute {{ }} 치환 - HTML string 차원에서 동적 치환\n if (n instanceof HTMLElement) {\n Array.from(n.attributes).forEach(attr => {\n const value = attr.value || '';\n if (value.startsWith('{{') && value.endsWith('}}')) {\n const script = value.slice(2, -2).trim();\n const result = FunctionUtils.executeReturn({\n script,\n context: n,\n args: { ...groupArgs, $value: this._value }\n });\n n.setAttribute(attr.name, String(result));\n }\n });\n }\n });\n\n this._executeCloneCallback('on-clone-nodes', groupArgs);\n\n this.parentElement?.insertBefore(clone, this.nextSibling);\n // if (portal === this.parentElement) {\n // portal.insertBefore(clone, this.nextSibling);\n // } else {\n // portal.appendChild(clone);\n // }\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n connectedCallback() {\n this.refresh();\n }\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAA8B;;;;;;;;;;AAExB,MAAO,kBAAkB,oBAAmB;EAAlD,cAAA;;AACU,SAAA,SAAiB,CAAA;AACjB,SAAA,SAAc;AACd,SAAA,oBAAgD;EAoI1D;EAlIE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,OAAM;EACb;EAEQ,sBAAsB,MAAc,MAAS;AACnD,UAAM,SAAS,KAAK,aAAa,IAAI;AACrC,QAAI,CAAC;AAAQ;AACb,8BAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,KAAI,CAAE;EACvD;EAGQ,QAAQ,WAAyB;AACvC,kBAAA,YAAc,KAAK,aAAa,OAAO;AACvC,QAAI,cAAc,MAAM;AACtB,WAAK,QAAQ;AACb;IACF;AAGA,QAAI,UAAU,WAAW,IAAI,KAAK,UAAU,SAAS,IAAI,GAAG;AAC1D,YAAM,SAAS,UAAU,MAAM,GAAG,EAAE,EAAE,KAAI;AAC1C,YAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,YAAM,SAAS,0BAAc,cAAc,EAAE,QAAQ,SAAS,MAAM,MAAM,sBAAS,oBAAoB,KAAK,IAAI,EAAC,CAAE;AACnH,WAAK,QAAQ;IACf,OAAO;AAEL,WAAK,QAAQ;IACf;EACF;EAEQ,SAAM;AACZ,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,YAAY,sBAAS,oBAAoB,KAAK,IAAI;AACxD,UAAM,YAAY,MAAM,KAAK,KAAK,QAAQ,iBAAiB,UAAU,CAAC;AACtE,QAAI,WAAuC;AAE3C,eAAW,KAAK,WAAW;AACzB,UAAI,EAAE,aAAa,IA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,MAAM,SAAS,IAAI,GAAG;AAClD,oBAAM,SAAS,MAAM,MAAM,GAAG,EAAE,EAAE,KAAI;AACtC,oBAAM,SAAS,0BAAc,cAAc;gBACzC;gBACA,SAAS;gBACT,MAAM,EAAE,GAAG,WAAW,QAAQ,KAAK,OAAM;eAC1C;AACD,gBAAE,aAAa,KAAK,MAAM,OAAO,MAAM,CAAC;YAC1C;UACF,CAAC;QACH;MACF,CAAC;AAED,WAAK,sBAAsB,kBAAkB,SAAS;AAEtD,WAAK,eAAe,aAAa,OAAO,KAAK,WAAW;IAM1D;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EACA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAlHQ,WAAA;MADP,kDAAqB,OAAO;;;;;",
6
6
  "names": []
7
7
  }
@@ -357,6 +357,7 @@ const registerAllElements = (w) => {
357
357
  super(...arguments);
358
358
  this._nodes = [];
359
359
  this._value = null;
360
+ this._previousTemplate = null;
360
361
  }
361
362
  get value() {
362
363
  return this._value;
@@ -365,70 +366,85 @@ const registerAllElements = (w) => {
365
366
  this._value = nv;
366
367
  this.render();
367
368
  }
368
- _resolvePortal() {
369
- const portalScript = this.getAttribute("on-get-portal");
370
- if (!portalScript)
371
- return this.parentElement;
372
- const win = this.ownerDocument?.defaultView || window;
373
- const res = import_core.FunctionUtils.executeReturn({
374
- script: portalScript,
375
- context: this,
376
- args: import_Utils.SwcUtils.getHelperAndHostSet(win, this)
377
- });
378
- if (res instanceof HTMLElement)
379
- return res;
380
- if (typeof res === "string")
381
- return win.document.querySelector(res);
382
- return this.parentElement;
383
- }
384
369
  _executeCloneCallback(attr, args) {
385
370
  const script = this.getAttribute(attr);
386
371
  if (!script)
387
372
  return;
388
373
  import_core.FunctionUtils.execute({ script, context: this, args });
389
374
  }
390
- refresh() {
391
- const script = this.getAttribute("on-get-value");
392
- if (!script) {
375
+ refresh(valueAttr) {
376
+ valueAttr ?? (valueAttr = this.getAttribute("value"));
377
+ if (valueAttr === null) {
393
378
  this.value = null;
394
379
  return;
395
380
  }
396
- const win = this.ownerDocument?.defaultView || window;
397
- const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
398
- this.value = result;
381
+ if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
382
+ const script = valueAttr.slice(2, -2).trim();
383
+ const win = this.ownerDocument?.defaultView || window;
384
+ const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
385
+ this.value = result;
386
+ } else {
387
+ this.value = valueAttr;
388
+ }
399
389
  }
400
390
  render() {
401
- this.cleanup();
402
- const portal = this._resolvePortal();
403
- if (!portal)
404
- return;
405
391
  const win = this.ownerDocument?.defaultView || window;
406
392
  const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
407
393
  const templates = Array.from(this.content.querySelectorAll("template"));
408
394
  let selected = null;
409
395
  for (const t of templates) {
410
- if (t.getAttribute("is") === "swc-when" && String(t.getAttribute("value")) === String(this._value)) {
411
- selected = t;
412
- break;
396
+ if (t.getAttribute("is") === "swc-when") {
397
+ let matches = false;
398
+ const value = t.getAttribute("value") || "";
399
+ if (value.startsWith("{{") && value.endsWith("}}")) {
400
+ const script = value.slice(2, -2).trim();
401
+ const result = import_core.FunctionUtils.executeReturn({
402
+ script,
403
+ context: t,
404
+ args: { ...helperSet, $value: this._value }
405
+ });
406
+ matches = result === true;
407
+ } else {
408
+ matches = String(value) === String(this._value);
409
+ }
410
+ if (matches) {
411
+ selected = t;
412
+ break;
413
+ }
413
414
  }
414
415
  }
415
416
  const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
417
+ const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
418
+ const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
419
+ if (shouldSkip) {
420
+ return;
421
+ }
422
+ this.cleanup();
423
+ this._previousTemplate = target;
416
424
  if (target) {
417
425
  const clone = target.content.cloneNode(true);
418
426
  this._nodes = Array.from(clone.childNodes);
419
427
  const elements = this._nodes.filter((n) => n.nodeType === 1);
420
428
  const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
421
429
  this._nodes.forEach((n, nodeIdx) => {
422
- if (n instanceof HTMLElement)
423
- n.__swc_host = this;
424
430
  this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
431
+ if (n instanceof HTMLElement) {
432
+ Array.from(n.attributes).forEach((attr) => {
433
+ const value = attr.value || "";
434
+ if (value.startsWith("{{") && value.endsWith("}}")) {
435
+ const script = value.slice(2, -2).trim();
436
+ const result = import_core.FunctionUtils.executeReturn({
437
+ script,
438
+ context: n,
439
+ args: { ...groupArgs, $value: this._value }
440
+ });
441
+ n.setAttribute(attr.name, String(result));
442
+ }
443
+ });
444
+ }
425
445
  });
426
446
  this._executeCloneCallback("on-clone-nodes", groupArgs);
427
- if (portal === this.parentElement) {
428
- portal.insertBefore(clone, this.nextSibling);
429
- } else {
430
- portal.appendChild(clone);
431
- }
447
+ this.parentElement?.insertBefore(clone, this.nextSibling);
432
448
  }
433
449
  }
434
450
  cleanup() {
@@ -443,9 +459,9 @@ const registerAllElements = (w) => {
443
459
  }
444
460
  };
445
461
  __decorate([
446
- (0, import_changedAttributeHost.changedAttributeHost)("on-get-value"),
462
+ (0, import_changedAttributeHost.changedAttributeHost)("value"),
447
463
  __metadata("design:type", Function),
448
- __metadata("design:paramtypes", []),
464
+ __metadata("design:paramtypes", [String]),
449
465
  __metadata("design:returntype", void 0)
450
466
  ], SwcChoose.prototype, "refresh", null);
451
467
  SwcChoose = __decorate([
@@ -481,8 +497,10 @@ const registerAllElements = (w) => {
481
497
  }
482
498
  refresh() {
483
499
  const script = this.getAttribute("on-get-value");
484
- if (!script)
500
+ if (!script) {
501
+ this.render("default");
485
502
  return;
503
+ }
486
504
  const win = this.ownerDocument?.defaultView || window;
487
505
  const result = import_core.FunctionUtils.executeReturn({ script, context: this, args: import_Utils.SwcUtils.getHelperAndHostSet(win, this) });
488
506
  if (result instanceof Promise) {
@@ -527,6 +545,7 @@ const registerAllElements = (w) => {
527
545
  this._nodes = [];
528
546
  }
529
547
  connectedCallback() {
548
+ console.log("[SwcAsync] connectedCallback called");
530
549
  this.refresh();
531
550
  }
532
551
  disconnectedCallback() {
@@ -827,5 +846,78 @@ const registerAllElements = (w) => {
827
846
  SwcAppBody = __decorate([
828
847
  (0, import_elementDefine.elementDefine)("swc-app-body", { extends: "body", window: w })
829
848
  ], SwcAppBody);
849
+ return {
850
+ // Sub Templates
851
+ SwcLoading,
852
+ SwcError,
853
+ SwcSuccess,
854
+ SwcWhen,
855
+ SwcOtherwise,
856
+ SwcDefault,
857
+ // Core Elements
858
+ SwcApp,
859
+ SwcIf,
860
+ SwcLoop,
861
+ SwcChoose,
862
+ SwcAsync,
863
+ // App Elements
864
+ SwcAppAnchor,
865
+ SwcAppArea,
866
+ SwcAppAudio,
867
+ SwcAppBase,
868
+ SwcAppButton,
869
+ SwcAppCanvas,
870
+ SwcAppData,
871
+ SwcAppDataList,
872
+ SwcAppDetails,
873
+ SwcAppDialog,
874
+ SwcAppDiv,
875
+ SwcAppDList,
876
+ SwcAppEmbed,
877
+ SwcAppFieldSet,
878
+ SwcAppForm,
879
+ SwcAppHR,
880
+ SwcAppIFrame,
881
+ SwcAppImage,
882
+ SwcAppInput,
883
+ SwcAppLabel,
884
+ SwcAppLegend,
885
+ SwcAppLI,
886
+ SwcAppLink,
887
+ SwcAppMap,
888
+ SwcAppMeta,
889
+ SwcAppMeter,
890
+ SwcAppMod,
891
+ SwcAppObject,
892
+ SwcAppOList,
893
+ SwcAppOptGroup,
894
+ SwcAppOption,
895
+ SwcAppOutput,
896
+ SwcAppParagraph,
897
+ SwcAppParam,
898
+ SwcAppPicture,
899
+ SwcAppPre,
900
+ SwcAppProgress,
901
+ SwcAppQuote,
902
+ SwcAppScript,
903
+ SwcAppSelect,
904
+ SwcAppSlot,
905
+ SwcAppSource,
906
+ SwcAppSpan,
907
+ SwcAppStyle,
908
+ SwcAppTable,
909
+ SwcAppTableSection,
910
+ SwcAppTableCell,
911
+ SwcAppTemplate,
912
+ SwcAppTextArea,
913
+ SwcAppTime,
914
+ SwcAppTitle,
915
+ SwcAppTableRow,
916
+ SwcAppTrack,
917
+ SwcAppUList,
918
+ SwcAppVideo,
919
+ SwcAppHeading,
920
+ SwcAppBody
921
+ };
830
922
  };
831
923
  //# sourceMappingURL=register.js.map