@dooboostore/simple-web-component 1.0.34 → 1.0.36

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 (170) hide show
  1. package/README.md +44 -51
  2. package/dist/cjs/decorators/addEventListener.js +12 -4
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +19 -18
  5. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  6. package/dist/cjs/decorators/applyClass.js +23 -22
  7. package/dist/cjs/decorators/applyClass.js.map +2 -2
  8. package/dist/cjs/decorators/applyNode.js +22 -17
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applyStyle.js +20 -19
  11. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  12. package/dist/cjs/decorators/attribute.js +17 -16
  13. package/dist/cjs/decorators/attribute.js.map +2 -2
  14. package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
  15. package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
  16. package/dist/cjs/decorators/elementDefine.js +234 -188
  17. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  18. package/dist/cjs/decorators/emitCustomEvent.js +24 -16
  19. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  20. package/dist/cjs/decorators/index.js +1 -1
  21. package/dist/cjs/decorators/index.js.map +1 -1
  22. package/dist/cjs/decorators/lifecycles.js +15 -17
  23. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  24. package/dist/cjs/decorators/query.js +38 -60
  25. package/dist/cjs/decorators/query.js.map +2 -2
  26. package/dist/cjs/decorators/queryAll.js +31 -63
  27. package/dist/cjs/decorators/queryAll.js.map +2 -2
  28. package/dist/cjs/decorators/setProperty.js +13 -12
  29. package/dist/cjs/decorators/setProperty.js.map +2 -2
  30. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  31. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  32. package/dist/cjs/elements/SwcAppEngine.js +8 -2
  33. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  34. package/dist/cjs/elements/SwcAppMixin.js +120 -65
  35. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  36. package/dist/cjs/elements/SwcAsync.js +31 -21
  37. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  38. package/dist/cjs/elements/SwcChoose.js +53 -34
  39. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  40. package/dist/cjs/elements/SwcIf.js +54 -32
  41. package/dist/cjs/elements/SwcIf.js.map +2 -2
  42. package/dist/cjs/elements/SwcLoop.js +111 -37
  43. package/dist/cjs/elements/SwcLoop.js.map +2 -2
  44. package/dist/cjs/elements/register.js +249 -122
  45. package/dist/cjs/elements/register.js.map +2 -2
  46. package/dist/cjs/router/ElementRouter.js +4 -2
  47. package/dist/cjs/router/ElementRouter.js.map +1 -1
  48. package/dist/cjs/types.js.map +1 -1
  49. package/dist/cjs/utils/Utils.js +31 -17
  50. package/dist/cjs/utils/Utils.js.map +2 -2
  51. package/dist/esm/decorators/addEventListener.js +12 -4
  52. package/dist/esm/decorators/addEventListener.js.map +2 -2
  53. package/dist/esm/decorators/applyAttribute.js +19 -18
  54. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  55. package/dist/esm/decorators/applyClass.js +23 -22
  56. package/dist/esm/decorators/applyClass.js.map +2 -2
  57. package/dist/esm/decorators/applyNode.js +22 -17
  58. package/dist/esm/decorators/applyNode.js.map +2 -2
  59. package/dist/esm/decorators/applyStyle.js +20 -19
  60. package/dist/esm/decorators/applyStyle.js.map +2 -2
  61. package/dist/esm/decorators/attribute.js +17 -16
  62. package/dist/esm/decorators/attribute.js.map +2 -2
  63. package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
  64. package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
  65. package/dist/esm/decorators/elementDefine.js +233 -187
  66. package/dist/esm/decorators/elementDefine.js.map +2 -2
  67. package/dist/esm/decorators/emitCustomEvent.js +24 -16
  68. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  69. package/dist/esm/decorators/index.js +1 -1
  70. package/dist/esm/decorators/index.js.map +1 -1
  71. package/dist/esm/decorators/lifecycles.js +15 -17
  72. package/dist/esm/decorators/lifecycles.js.map +2 -2
  73. package/dist/esm/decorators/query.js +38 -60
  74. package/dist/esm/decorators/query.js.map +2 -2
  75. package/dist/esm/decorators/queryAll.js +31 -63
  76. package/dist/esm/decorators/queryAll.js.map +2 -2
  77. package/dist/esm/decorators/setProperty.js +13 -12
  78. package/dist/esm/decorators/setProperty.js.map +2 -2
  79. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  80. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  81. package/dist/esm/elements/SwcAppEngine.js +9 -2
  82. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  83. package/dist/esm/elements/SwcAppMixin.js +122 -66
  84. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  85. package/dist/esm/elements/SwcAsync.js +32 -22
  86. package/dist/esm/elements/SwcAsync.js.map +2 -2
  87. package/dist/esm/elements/SwcChoose.js +54 -35
  88. package/dist/esm/elements/SwcChoose.js.map +2 -2
  89. package/dist/esm/elements/SwcIf.js +55 -33
  90. package/dist/esm/elements/SwcIf.js.map +2 -2
  91. package/dist/esm/elements/SwcLoop.js +112 -38
  92. package/dist/esm/elements/SwcLoop.js.map +2 -2
  93. package/dist/esm/elements/register.js +250 -123
  94. package/dist/esm/elements/register.js.map +2 -2
  95. package/dist/esm/router/ElementRouter.js +5 -2
  96. package/dist/esm/router/ElementRouter.js.map +1 -1
  97. package/dist/esm/types.js.map +1 -1
  98. package/dist/esm/utils/Utils.js +31 -17
  99. package/dist/esm/utils/Utils.js.map +2 -2
  100. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
  101. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  102. package/dist/types/decorators/addEventListener.d.ts +5 -7
  103. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  104. package/dist/types/decorators/applyAttribute.d.ts +4 -4
  105. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  106. package/dist/types/decorators/applyClass.d.ts +6 -6
  107. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  108. package/dist/types/decorators/applyNode.d.ts +7 -6
  109. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  110. package/dist/types/decorators/applyStyle.d.ts +4 -4
  111. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  112. package/dist/types/decorators/attribute.d.ts +5 -5
  113. package/dist/types/decorators/attribute.d.ts.map +1 -1
  114. package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
  115. package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
  116. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  117. package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
  118. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  119. package/dist/types/decorators/index.d.ts +1 -1
  120. package/dist/types/decorators/lifecycles.d.ts +10 -7
  121. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  122. package/dist/types/decorators/query.d.ts +17 -63
  123. package/dist/types/decorators/query.d.ts.map +1 -1
  124. package/dist/types/decorators/queryAll.d.ts +6 -63
  125. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  126. package/dist/types/decorators/setProperty.d.ts +1 -1
  127. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  128. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
  129. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  130. package/dist/types/elements/SwcAppEngine.d.ts +4 -1
  131. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  132. package/dist/types/elements/SwcAppMixin.d.ts +11 -8
  133. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  134. package/dist/types/elements/register.d.ts.map +1 -1
  135. package/dist/types/types.d.ts +3 -2
  136. package/dist/types/types.d.ts.map +1 -1
  137. package/dist/types/utils/Utils.d.ts +11 -8
  138. package/dist/types/utils/Utils.d.ts.map +1 -1
  139. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
  140. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  141. package/package.json +3 -3
  142. package/src/decorators/addEventListener.ts +11 -9
  143. package/src/decorators/applyAttribute.ts +16 -15
  144. package/src/decorators/applyClass.ts +18 -17
  145. package/src/decorators/applyNode.ts +34 -21
  146. package/src/decorators/applyStyle.ts +17 -16
  147. package/src/decorators/attribute.ts +21 -20
  148. package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
  149. package/src/decorators/elementDefine.ts +402 -358
  150. package/src/decorators/emitCustomEvent.ts +40 -31
  151. package/src/decorators/index.ts +1 -1
  152. package/src/decorators/lifecycles.ts +11 -10
  153. package/src/decorators/query.ts +51 -124
  154. package/src/decorators/queryAll.ts +30 -127
  155. package/src/decorators/setProperty.ts +12 -11
  156. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
  157. package/src/elements/SwcAppEngine.ts +10 -3
  158. package/src/elements/SwcAppMixin.ts +177 -97
  159. package/src/elements/SwcAsync.ts +32 -21
  160. package/src/elements/SwcChoose.ts +74 -37
  161. package/src/elements/SwcIf.ts +60 -23
  162. package/src/elements/SwcLoop.ts +141 -28
  163. package/src/elements/register.ts +300 -102
  164. package/src/types.ts +6 -5
  165. package/src/utils/Utils.ts +40 -23
  166. package/tsconfig.json +2 -2
  167. package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
  168. package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
  169. package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
  170. package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
@@ -1,4 +1,4 @@
1
- var import_changedAttributeHost = require("../decorators/changedAttributeHost");
1
+ var import_changedAttributeThis = require("../decorators/changedAttributeThis");
2
2
  var import_Utils = require("../utils/Utils");
3
3
  var import_core = require("@dooboostore/core");
4
4
  var import_core_web = require("@dooboostore/core-web");
@@ -31,18 +31,28 @@ class SwcChoose extends HTMLTemplateElement {
31
31
  attributeChangedCallback(na, o, n) {
32
32
  }
33
33
  setValue(value, o, n) {
34
+ console.log("chooooooose value", value);
34
35
  this._value = value;
35
36
  this.refresh(this._value);
36
37
  }
37
- setReplaceWrap(replaceWrapAttr) {
38
- this.refresh();
39
- }
38
+ // @changedAttributeThis('replace-wrap')
39
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
40
+ // this.refresh();
41
+ // }
40
42
  replaceExpressions(html, groupArgs, context, wrap) {
41
- const config = wrap ? { wrapExpression: wrap } : void 0;
43
+ let config = void 0;
44
+ if (wrap) {
45
+ config = {
46
+ expression: {
47
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
48
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
49
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
50
+ }
51
+ };
52
+ }
42
53
  const ae = new import_core.ActionExpression(html, config);
43
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
44
54
  const win = this.ownerDocument?.defaultView || window;
45
- for (const expr of ae.getExpressions(filterOptions)) {
55
+ for (const expr of ae.getExpressions("replace")) {
46
56
  try {
47
57
  const value = import_core.FunctionUtils.executeReturn({
48
58
  script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
@@ -58,31 +68,27 @@ class SwcChoose extends HTMLTemplateElement {
58
68
  }
59
69
  refresh(value) {
60
70
  value = (0, import_decorators.getAttributeValue)(this, "value") ?? this._value;
61
- const portal = this.parentElement;
62
- if (!portal)
71
+ console.log("[DEBUG] SwcChoose.refresh called, value:", value);
72
+ const portal = import_Utils.SwcUtils.getParentContainer(this);
73
+ if (!portal) {
74
+ console.log("[DEBUG] SwcChoose portal is null!");
63
75
  return;
76
+ }
64
77
  const win = ((0, import_decorators.getElementConfig)(this).window ?? this.ownerDocument?.defaultView) || window;
65
78
  const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
66
- const groupArgs = { ...helperSet, $value: value };
79
+ const groupArgs = { ...helperSet, $value: value, $templateHost: this };
67
80
  const templates = Array.from(this.content.querySelectorAll("template"));
68
81
  let selected = null;
69
82
  for (const t of templates) {
70
83
  if (t.getAttribute("is") === "swc-when") {
71
- const attrVal = t.getAttribute("value") || "";
84
+ const attrVal = t.getAttribute("test") || "";
72
85
  let matches = false;
73
- const ae = new import_core.ActionExpression(attrVal);
74
- const expr = ae.getFirstExpression("replace");
75
- if (expr) {
76
- const decodedScript = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document);
77
- const result = import_core.FunctionUtils.executeReturn({
78
- script: decodedScript,
79
- context: t,
80
- args: groupArgs
81
- });
82
- matches = !!result;
83
- } else {
84
- matches = String(attrVal) === String(value);
85
- }
86
+ const result = import_core.FunctionUtils.executeReturn({
87
+ script: attrVal,
88
+ context: t,
89
+ args: groupArgs
90
+ });
91
+ matches = !!result;
86
92
  if (matches) {
87
93
  selected = t;
88
94
  break;
@@ -101,12 +107,27 @@ class SwcChoose extends HTMLTemplateElement {
101
107
  this._previousTemplate = target;
102
108
  if (target) {
103
109
  let htmlString = target.innerHTML;
104
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
110
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
105
111
  const result = this.ownerDocument?.createElement("template") || document.createElement("template");
106
112
  result.innerHTML = htmlString;
107
113
  const processedFragment = result.content;
108
114
  this._nodes = Array.from(processedFragment.childNodes);
115
+ const setTemplateHost = (element) => {
116
+ element.__swc_template_host = this;
117
+ Array.from(element.children).forEach((child) => {
118
+ if (child instanceof HTMLElement) {
119
+ setTemplateHost(child);
120
+ }
121
+ });
122
+ };
123
+ this._nodes.forEach((node) => {
124
+ if (node instanceof HTMLElement) {
125
+ setTemplateHost(node);
126
+ }
127
+ });
128
+ console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${portal?.isConnected}`);
109
129
  portal.insertBefore(processedFragment, this.nextSibling);
130
+ console.log("[DEBUG] SwcChoose after insertBefore");
110
131
  }
111
132
  }
112
133
  cleanup() {
@@ -118,19 +139,17 @@ class SwcChoose extends HTMLTemplateElement {
118
139
  }
119
140
  }
120
141
  __decorate([
121
- (0, import_decorators.attributeHost)("replace-wrap"),
142
+ (0, import_decorators.attributeThis)("replace-wrap-start"),
143
+ __metadata("design:type", String)
144
+ ], SwcChoose.prototype, "_replaceWrapStart", void 0);
145
+ __decorate([
146
+ (0, import_decorators.attributeThis)("replace-wrap-end"),
122
147
  __metadata("design:type", String)
123
- ], SwcChoose.prototype, "_replaceWrap", void 0);
148
+ ], SwcChoose.prototype, "_replaceWrapEnd", void 0);
124
149
  __decorate([
125
- (0, import_changedAttributeHost.changedAttributeHost)("value"),
150
+ (0, import_changedAttributeThis.changedAttributeThis)("value"),
126
151
  __metadata("design:type", Function),
127
152
  __metadata("design:paramtypes", [Object, String, String]),
128
153
  __metadata("design:returntype", void 0)
129
154
  ], SwcChoose.prototype, "setValue", null);
130
- __decorate([
131
- (0, import_changedAttributeHost.changedAttributeHost)("replace-wrap"),
132
- __metadata("design:type", Function),
133
- __metadata("design:paramtypes", [String]),
134
- __metadata("design:returntype", void 0)
135
- ], SwcChoose.prototype, "setReplaceWrap", null);
136
155
  //# 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, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcChooseInterface } from '../types';\nimport { attributeHost, getAttributeValue, getElementConfig } from '../decorators';\n\nclass SwcChoose extends HTMLTemplateElement implements SwcChooseInterface {\n // @attributeHost('value')\n // fetchValue: any;\n\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodes: Node[] = [];\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n this._value = nv;\n this.refresh(this._value);\n }\n\n constructor() {\n super();\n // console.log('swc chooooooooooooooooooooooooose constructor called!');\n // console.log('swc cccccccss', this.getAttribute('value'));\n }\n\n // static get observedAttributes() {\n // return ['value'];\n // }\n\n attributeChangedCallback(na, o, n) {\n // console.log('-----------------choooooooose attr origin', na, o, n);\n }\n\n @changedAttributeHost('value')\n private setValue(value: any, o: string, n: string) {\n // console.log('-----------------choooooooose attr setValue', value, o, n);\n this._value = value;\n this.refresh(this._value);\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap(replaceWrapAttr?: string | null) {\n this.refresh();\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value?: any) {\n value = getAttributeValue(this, 'value') ?? this._value;\n // console.log('chooooooooo refresh->', value);\n const portal = this.parentElement;\n if (!portal) return;\n\n const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const groupArgs = { ...helperSet, $value: value };\n\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 const attrVal = t.getAttribute('value') || '';\n let matches = false;\n\n // Use ActionExpression to parse and extract script from value attribute\n const ae = new ActionExpression(attrVal);\n const expr = ae.getFirstExpression('replace');\n\n if (expr) {\n const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n const result = FunctionUtils.executeReturn({\n script: decodedScript,\n context: t,\n args: groupArgs\n });\n matches = !!result;\n } else {\n matches = String(attrVal) === String(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 const skipValue = target?.getAttribute?.('skip-if-same');\n const skipValue2 = this._previousTemplate?.getAttribute?.('skip-if-same');\n const hasSkipIfSame = target?.hasAttribute?.('skip-if-same');\n const isSame = this._previousTemplate === target;\n // console.log('---rrrr---', this._previousTemplate, target, hasSkipIfSame, isSame, skipValue, skipValue2);\n if (hasSkipIfSame && isSame) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n let htmlString = target.innerHTML;\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
- "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAE7B,wBAAmE;;;;;;;;;;AAEnE,MAAM,kBAAkB,oBA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SAAS,CAAA;EAChB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAzIA,WAAA;MADC,iCAAc,cAAc;;;AA8BrB,WAAA;MADP,kDAAqB,OAAO;;;;;AAQrB,WAAA;MADP,kDAAqB,cAAc;;;;;",
4
+ "sourcesContent": ["import { changedAttributeThis } from '../decorators/changedAttributeThis';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcChooseInterface } from '../types';\nimport { attributeThis, getAttributeValue, getElementConfig } from '../decorators';\n\nclass SwcChoose extends HTMLTemplateElement implements SwcChooseInterface {\n _value: any;\n\n @attributeThis('replace-wrap-start')\n _replaceWrapStart: string | null;\n @attributeThis('replace-wrap-end')\n _replaceWrapEnd: string | null;\n\n private _nodes: Node[] = [];\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n this._value = nv;\n this.refresh(this._value);\n }\n\n constructor() {\n super();\n // console.log('swc chooooooooooooooooooooooooose constructor called!');\n // console.log('swc cccccccss', this.getAttribute('value'));\n }\n\n // static get observedAttributes() {\n // return ['value'];\n // }\n\n attributeChangedCallback(na, o, n) {\n // console.log('-----------------choooooooose attr origin', na, o, n);\n }\n\n @changedAttributeThis('value')\n private setValue(value: any, o: string, n: string) {\n console.log('chooooooose value', value)\n this._value = value;\n this.refresh(this._value);\n }\n\n // @changedAttributeThis('replace-wrap')\n // private setReplaceWrap(replaceWrapAttr?: string | null) {\n // this.refresh();\n // }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {\n let config: any = undefined;\n if (wrap) {\n config = {\n expression: {\n replace: { start: `${wrap.start}`, end: `${wrap.end}` },\n callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },\n call: { start: `${wrap.start}@`, end: `${wrap.end}` }\n }\n };\n }\n const ae = new ActionExpression(html, config);\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions('replace')) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value?: any) {\n value = getAttributeValue(this, 'value') ?? this._value;\n console.log('[DEBUG] SwcChoose.refresh called, value:', value);\n const portal = SwcUtils.getParentContainer(this);\n if (!portal) {\n console.log('[DEBUG] SwcChoose portal is null!');\n return;\n }\n\n const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const groupArgs = { ...helperSet, $value: value, $templateHost: this };\n\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 const attrVal = t.getAttribute('test') || '';\n let matches = false;\n\n\n\n const result = FunctionUtils.executeReturn({\n script: attrVal,\n context: t,\n args: groupArgs\n });\n matches = !!result;\n // Use ActionExpression to parse and extract script from value attribute\n // const ae = new ActionExpression(attrVal);\n // const expr = ae.getFirstExpression('replace');\n\n // if (expr) {\n // const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n // const result = FunctionUtils.executeReturn({\n // script: decodedScript,\n // context: t,\n // args: groupArgs\n // });\n // matches = !!result;\n // } else {\n // matches = String(attrVal) === String(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 const skipValue = target?.getAttribute?.('skip-if-same');\n const skipValue2 = this._previousTemplate?.getAttribute?.('skip-if-same');\n const hasSkipIfSame = target?.hasAttribute?.('skip-if-same');\n const isSame = this._previousTemplate === target;\n // console.log('---rrrr---', this._previousTemplate, target, hasSkipIfSame, isSame, skipValue, skipValue2);\n if (hasSkipIfSame && isSame) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n let htmlString = target.innerHTML;\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n // console.log('[DEBUG] SwcChoose processedFragment children:', processedFragment._childNodesInternal?.length);\n this._nodes = Array.from(processedFragment.childNodes);\n \n const setTemplateHost = (element: HTMLElement) => {\n (element as any).__swc_template_host = this;\n Array.from(element.children).forEach((child: any) => {\n if (child instanceof HTMLElement) {\n setTemplateHost(child);\n }\n });\n };\n \n this._nodes.forEach((node: any) => {\n if (node instanceof HTMLElement) {\n setTemplateHost(node as HTMLElement);\n }\n });\n\n console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${(portal as any)?.isConnected}`);\n portal.insertBefore(processedFragment, this.nextSibling);\n console.log('[DEBUG] SwcChoose after insertBefore');\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAE7B,wBAAmE;;;;;;;;;;AAEnE,MAAM,kBAAkB,oBAAmB;EAWzC,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AACf,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM;EAC1B;EAEA,cAAA;AACE,UAAK;AAbC,SAAA,SAAiB,CAAA;AACjB,SAAA,oBAAgD;EAexD;;;;EAMA,yBAAyB,IAAI,GAAG,GAAC;EAEjC;EAGQ,SAAS,OAAY,GAAW,GAAS;AAC/C,YAAQ,IAAI,qBAAqB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AAQ,OAAO,kBAAmB,QAAgB,WAAW,EAAE;AAC7H,aAAO,aAAa,mBAAmB,KAAK,WAAW;AACvD,cAAQ,IAAI,sCAAsC;IACpD;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAjLA,WAAA;MADC,iCAAc,oBAAoB;;;AAGnC,WAAA;MADC,iCAAc,kBAAkB;;;AA8BzB,WAAA;MADP,kDAAqB,OAAO;;;;;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- var import_changedAttributeHost = require("../decorators/changedAttributeHost");
1
+ var import_changedAttributeThis = require("../decorators/changedAttributeThis");
2
2
  var import_Utils = require("../utils/Utils");
3
3
  var import_core = require("@dooboostore/core");
4
4
  var import_core_web = require("@dooboostore/core-web");
@@ -13,22 +13,38 @@ var __metadata = function(k, v) {
13
13
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
14
14
  };
15
15
  class SwcIf extends HTMLTemplateElement {
16
- constructor() {
17
- super(...arguments);
18
- this._nodes = [];
19
- }
20
16
  get value() {
21
17
  return this._value;
22
18
  }
23
19
  set value(nv) {
24
20
  this.refresh(nv);
25
21
  }
22
+ constructor() {
23
+ super();
24
+ this._nodes = [];
25
+ }
26
+ setValue(value, o, n) {
27
+ this._value = value;
28
+ this.refresh(this._value);
29
+ }
30
+ // @changedAttributeThis('replace-wrap')
31
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
32
+ // this.refresh();
33
+ // }
26
34
  replaceExpressions(html, groupArgs, context, wrap) {
27
- const config = wrap ? { wrapExpression: wrap } : void 0;
35
+ let config = void 0;
36
+ if (wrap) {
37
+ config = {
38
+ expression: {
39
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
40
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
41
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
42
+ }
43
+ };
44
+ }
28
45
  const ae = new import_core.ActionExpression(html, config);
29
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
30
46
  const win = this.ownerDocument?.defaultView || window;
31
- for (const expr of ae.getExpressions(filterOptions)) {
47
+ for (const expr of ae.getExpressions("replace")) {
32
48
  try {
33
49
  const value = import_core.FunctionUtils.executeReturn({
34
50
  script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
@@ -42,30 +58,38 @@ class SwcIf extends HTMLTemplateElement {
42
58
  }
43
59
  return ae.getUnprocessedTemplate();
44
60
  }
45
- setValue(valueAttr) {
46
- this.refresh();
47
- }
48
- setReplaceWrap(replaceWrapAttr) {
49
- this.refresh();
50
- }
51
- refresh(value = this._value) {
61
+ refresh(value) {
62
+ const targetValue = value !== void 0 ? value : (0, import_decorators.getAttributeValue)(this, "value") ?? this._value;
63
+ if (this.hasAttribute("skip-if-same") && this._value === targetValue && this._nodes.length > 0) {
64
+ return;
65
+ }
52
66
  this.cleanup();
67
+ this._value = targetValue;
53
68
  const portal = this.parentElement;
54
- if (!portal || !value)
69
+ if (!portal || !this._value)
55
70
  return;
56
71
  const win = this.ownerDocument?.defaultView || window;
57
72
  const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
58
73
  let htmlString = this.innerHTML;
59
- const groupArgs = { ...helperSet, $value: value };
60
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
74
+ const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };
75
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
61
76
  const result = this.ownerDocument?.createElement("template") || document.createElement("template");
62
77
  result.innerHTML = htmlString;
63
78
  const processedFragment = result.content;
64
79
  this._nodes = Array.from(processedFragment.childNodes);
80
+ this._nodes.forEach((node) => {
81
+ if (node instanceof HTMLElement)
82
+ node.__swc_template_host = this;
83
+ });
65
84
  portal.insertBefore(processedFragment, this.nextSibling);
66
85
  }
67
86
  cleanup() {
68
- this._nodes.forEach((n) => n.parentElement?.removeChild(n));
87
+ this._nodes.forEach((n) => {
88
+ const realNode = n.__upgraded_instance || n;
89
+ if (realNode.parentElement) {
90
+ realNode.parentElement.removeChild(realNode);
91
+ }
92
+ });
69
93
  this._nodes = [];
70
94
  }
71
95
  disconnectedCallback() {
@@ -73,23 +97,21 @@ class SwcIf extends HTMLTemplateElement {
73
97
  }
74
98
  }
75
99
  __decorate([
76
- (0, import_decorators.attributeHost)("value"),
77
- __metadata("design:type", Object)
78
- ], SwcIf.prototype, "_value", void 0);
100
+ (0, import_decorators.attributeThis)("replace-wrap-start"),
101
+ __metadata("design:type", String)
102
+ ], SwcIf.prototype, "_replaceWrapStart", void 0);
79
103
  __decorate([
80
- (0, import_decorators.attributeHost)("replace-wrap"),
104
+ (0, import_decorators.attributeThis)("replace-wrap-end"),
81
105
  __metadata("design:type", String)
82
- ], SwcIf.prototype, "_replaceWrap", void 0);
106
+ ], SwcIf.prototype, "_replaceWrapEnd", void 0);
83
107
  __decorate([
84
- (0, import_changedAttributeHost.changedAttributeHost)("value"),
85
- __metadata("design:type", Function),
86
- __metadata("design:paramtypes", [String]),
87
- __metadata("design:returntype", void 0)
88
- ], SwcIf.prototype, "setValue", null);
108
+ (0, import_decorators.attributeThis)("skip-if-same"),
109
+ __metadata("design:type", String)
110
+ ], SwcIf.prototype, "_skipIfSame", void 0);
89
111
  __decorate([
90
- (0, import_changedAttributeHost.changedAttributeHost)("replace-wrap"),
112
+ (0, import_changedAttributeThis.changedAttributeThis)("value"),
91
113
  __metadata("design:type", Function),
92
- __metadata("design:paramtypes", [String]),
114
+ __metadata("design:paramtypes", [Object, String, String]),
93
115
  __metadata("design:returntype", void 0)
94
- ], SwcIf.prototype, "setReplaceWrap", null);
116
+ ], SwcIf.prototype, "setValue", null);
95
117
  //# sourceMappingURL=SwcIf.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcIf.ts"],
4
- "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcIfInterface } from '../types';\nimport { attributeHost } from '../decorators';\n\nclass SwcIf extends HTMLTemplateElement implements SwcIfInterface {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodes: Node[] = [];\n\n get value(): boolean {\n return this._value;\n }\n\n set value(nv: any) {\n // this._value = nv;\n this.refresh(nv);\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n \n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n @changedAttributeHost('value')\n private setValue(valueAttr?: string | null) {\n this.refresh();\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap(replaceWrapAttr?: string | null) {\n this.refresh();\n }\n\n refresh(value = this._value) {\n this.cleanup();\n const portal = this.parentElement;\n if (!portal || !value) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $value: value };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
- "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAE7B,wBAA8B;;;;;;;;;;AAE9B,MAAM,cAAc,oBAAmB;EAAvC,cAAA;;AAOU,SAAA,SAAiB,CAAA;EAwE3B;EAtEE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AAEf,SAAK,QAAQ,EAAE;EACjB;EAEQ,mBAAmB,MAAc,WAAgB,SAAc,MAAoB;AACzF,UAAM,SAAS,OAAO,EAAE,gBAAgB,KAAI,IAAK;AACjD,UAAM,KAAK,IAAI,6BAAiB,MAAM,MAAM;AAC5C,UAAM,gBAAgB,OAAO,EAAE,MAAM,WAAoB,KAAI,IAAK;AAClE,UAAM,MAAM,KAAK,eAAe,eAAe;AAG/C,eAAW,QAAQ,GAAG,eAAe,aAAa,GAAG;AACnD,UAAI;AACF,cAAM,QAAQ,0BAAc,cAAc;UACxC,QAAQ,6BAAa,iBAAiB,KAAK,QAAQ,IAAI,QAAQ;UAC/D;UACA,MAAM;SACP;AACD,WAAG,QAAQ,MAAM,OAAO,KAAK,CAAC;MAChC,SAAS,GAAG;AACV,gBAAQ,MAAM,2BAA2B,KAAK,QAAQ,KAAK,CAAC;MAC9D;IACF;AACA,WAAO,GAAG,uBAAsB;EAClC;EAGQ,SAAS,WAAyB;AACxC,SAAK,QAAO;EACd;EAGQ,eAAe,iBAA+B;AACpD,SAAK,QAAO;EACd;EAEA,QAAQ,QAAQ,KAAK,QAAM;AACzB,SAAK,QAAO;AACZ,UAAM,SAAS,KAAK;AACpB,QAAI,CAAC,UAAU,CAAC;AAAO;AAEvB,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,YAAY,sBAAS,oBAAoB,KAAK,IAAI;AAExD,QAAI,aAAa,KAAK;AACtB,UAAM,YAAY,EAAE,GAAG,WAAW,QAAQ,MAAK;AAE/C,iBAAa,KAAK,mBAAmB,YAAY,WAAW,MAAM,KAAK,YAAY;AAEnF,UAAM,SAAS,KAAK,eAAe,cAAc,UAAU,KAAK,SAAS,cAAc,UAAU;AACjG,WAAO,YAAY;AACnB,UAAM,oBAAoB,OAAO;AAEjC,SAAK,SAAS,MAAM,KAAK,kBAAkB,UAAU;AACrD,WAAO,aAAa,mBAAmB,KAAK,WAAW;EACzD;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AA5EA,WAAA;MADC,iCAAc,OAAO;;;AAItB,WAAA;MADC,iCAAc,cAAc;;;AAqCrB,WAAA;MADP,kDAAqB,OAAO;;;;;AAMrB,WAAA;MADP,kDAAqB,cAAc;;;;;",
4
+ "sourcesContent": ["import { changedAttributeThis } from '../decorators/changedAttributeThis';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcIfInterface } from '../types';\nimport { attributeThis, getAttributeValue } from '../decorators';\n\nclass SwcIf extends HTMLTemplateElement implements SwcIfInterface {\n // id =\n // @attributeThis('value')\n _value: any;\n\n @attributeThis('replace-wrap-start')\n _replaceWrapStart: string | null;\n @attributeThis('replace-wrap-end')\n _replaceWrapEnd: string | null;\n\n @attributeThis('skip-if-same')\n _skipIfSame: string | null;\n\n private _nodes: Node[] = [];\n\n get value(): boolean {\n return this._value;\n }\n\n set value(nv: any) {\n // this._value = nv;\n this.refresh(nv);\n }\n\n constructor() {\n super();\n }\n\n @changedAttributeThis('value')\n private setValue(value: any, o: string, n: string) {\n this._value = value;\n this.refresh(this._value);\n }\n\n // @changedAttributeThis('replace-wrap')\n // private setReplaceWrap(replaceWrapAttr?: string | null) {\n // this.refresh();\n // }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {\n let config: any = undefined;\n if (wrap) {\n config = {\n expression: {\n replace: { start: `${wrap.start}`, end: `${wrap.end}` },\n callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },\n call: { start: `${wrap.start}@`, end: `${wrap.end}` }\n }\n };\n }\n const ae = new ActionExpression(html, config);\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions('replace')) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value?: any) {\n const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value);\n\n // skip-if-same 속성이 존재하고(true/빈 문자열), 이전 값과 새로운 값이 완전히 동일하면 렌더링 스킵!\n if (this.hasAttribute('skip-if-same') && this._value === targetValue && this._nodes.length > 0) {\n return;\n }\n\n this.cleanup();\n this._value = targetValue;\n\n const portal = this.parentElement;\n if (!portal || !this._value) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n this._nodes.forEach((node: any) => {\n if (node instanceof HTMLElement) (node as any).__swc_template_host = this;\n });\n\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n const realNode = (n as any).__upgraded_instance || n;\n if (realNode.parentElement) {\n realNode.parentElement.removeChild(realNode);\n }\n });\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAE7B,wBAAiD;;;;;;;;;;AAEjD,MAAM,cAAc,oBAAmB;EAerC,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AAEf,SAAK,QAAQ,EAAE;EACjB;EAEA,cAAA;AACE,UAAK;AAZC,SAAA,SAAiB,CAAA;EAazB;EAGQ,SAAS,OAAY,GAAW,GAAS;AAC/C,SAAK,SAAS;AACd,SAAK,QAAQ,KAAK,MAAM;EAC1B;;;;;EAOQ,mBAAmB,MAAc,WAAgB,SAAc,MAAkC;AACvG,QAAI,SAAc;AAClB,QAAI,MAAM;AACR,eAAS;QACP,YAAY;UACV,SAAS,EAAE,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,GAAG,KAAK,GAAG,GAAE;UACrD,YAAY,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;UACzD,MAAM,EAAE,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,GAAE;;;IAGzD;AACA,UAAM,KAAK,IAAI,6BAAiB,MAAM,MAAM;AAC5C,UAAM,MAAM,KAAK,eAAe,eAAe;AAG/C,eAAW,QAAQ,GAAG,eAAe,SAAS,GAAG;AAC/C,UAAI;AACF,cAAM,QAAQ,0BAAc,cAAc;UACxC,QAAQ,6BAAa,iBAAiB,KAAK,QAAQ,IAAI,QAAQ;UAC/D;UACA,MAAM;SACP;AACD,WAAG,QAAQ,MAAM,OAAO,KAAK,CAAC;MAChC,SAAS,GAAG;A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CAAc,kBAAkB;;;AAIjC,WAAA;MADC,iCAAc,cAAc;;;AAmBrB,WAAA;MADP,kDAAqB,OAAO;;;;;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- var import_changedAttributeHost = require("../decorators/changedAttributeHost");
1
+ var import_changedAttributeThis = require("../decorators/changedAttributeThis");
2
2
  var import_Utils = require("../utils/Utils");
3
3
  var import_core = require("@dooboostore/core");
4
4
  var import_core_web = require("@dooboostore/core-web");
@@ -13,31 +13,46 @@ var __metadata = function(k, v) {
13
13
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
14
14
  };
15
15
  class SwcLoop extends HTMLTemplateElement {
16
- constructor() {
17
- super(...arguments);
18
- this._nodeGroups = [];
19
- }
20
16
  get value() {
21
17
  return this._value;
22
18
  }
23
19
  set value(nv) {
20
+ this._value = nv;
24
21
  this.refresh(nv);
25
22
  }
26
- setValue() {
27
- this.refresh();
23
+ getValue(index) {
24
+ return this._value?.[index];
25
+ }
26
+ constructor() {
27
+ super();
28
+ this._value = [];
29
+ this._nodeGroups = [];
28
30
  }
29
- setReplaceWrap() {
30
- this.refresh();
31
+ setValue(value, o, n) {
32
+ this._value = value;
33
+ this.refresh(this._value);
31
34
  }
35
+ // @changedAttributeThis('replace-wrap')
36
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
37
+ // this.refresh();
38
+ // }
32
39
  replaceExpressions(html, groupArgs, context, wrap) {
33
- const config = wrap ? { wrapExpression: wrap } : void 0;
40
+ let config = void 0;
41
+ config = {
42
+ expression: {
43
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
44
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
45
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
46
+ }
47
+ };
34
48
  const ae = new import_core.ActionExpression(html, config);
35
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
36
49
  const win = this.ownerDocument?.defaultView || window;
37
- for (const expr of ae.getExpressions(filterOptions)) {
50
+ const expressions = ae.getExpressions("replace");
51
+ for (const expr of expressions) {
52
+ const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document);
38
53
  try {
39
54
  const value = import_core.FunctionUtils.executeReturn({
40
- script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
55
+ script,
41
56
  context,
42
57
  args: groupArgs
43
58
  });
@@ -48,30 +63,95 @@ class SwcLoop extends HTMLTemplateElement {
48
63
  }
49
64
  return ae.getUnprocessedTemplate();
50
65
  }
51
- refresh(value = this._value) {
52
- this.cleanup();
53
- if (value?.length <= 0)
54
- return;
55
- const portal = this.parentElement;
56
- if (!portal)
57
- return;
66
+ createFragmentAndNodes(items, helperSet, startIndex = 0) {
58
67
  const win = this.ownerDocument?.defaultView || window;
59
- const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
60
68
  const fragment = win.document.createDocumentFragment();
61
- value.forEach((item, index) => {
69
+ const newNodesGroup = [];
70
+ items.forEach((item, i) => {
71
+ const index = startIndex + i;
62
72
  let htmlString = this.innerHTML;
63
73
  const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
64
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
74
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
65
75
  const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
66
76
  temp.innerHTML = htmlString;
67
77
  const content = temp.content;
68
78
  const nodes = Array.from(content.childNodes);
69
- this._nodeGroups.push(nodes);
79
+ const setTemplateHost = (element) => {
80
+ element.__swc_template_host = this;
81
+ Array.from(element.children).forEach((child) => {
82
+ if (child instanceof HTMLElement) {
83
+ setTemplateHost(child);
84
+ }
85
+ });
86
+ };
87
+ nodes.forEach((node) => {
88
+ if (node instanceof HTMLElement) {
89
+ setTemplateHost(node);
90
+ }
91
+ });
92
+ newNodesGroup.push(nodes);
70
93
  fragment.appendChild(content);
71
94
  });
95
+ return { fragment, newNodesGroup };
96
+ }
97
+ appendItem(...items) {
98
+ if (!items || items.length <= 0)
99
+ return;
100
+ const portal = import_Utils.SwcUtils.getParentContainer(this);
101
+ if (!portal)
102
+ return;
103
+ const win = this.ownerDocument?.defaultView || window;
104
+ const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
105
+ const startIndex = this._value ? this._value.length : 0;
106
+ if (this._value !== items) {
107
+ this._value = [...this._value || [], ...items];
108
+ }
109
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
110
+ this._nodeGroups.push(...newNodesGroup);
111
+ console.log("\uBB50\uC57C \uC528\uBC1C");
112
+ let insertReference = this.nextSibling;
113
+ if (this._nodeGroups.length > items.length) {
114
+ const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
115
+ if (lastExistingGroup && lastExistingGroup.length > 0) {
116
+ const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
117
+ insertReference = lastNode.nextSibling;
118
+ }
119
+ }
120
+ portal.insertBefore(fragment, insertReference);
121
+ }
122
+ async prependItem(...items) {
123
+ if (!items || items.length <= 0)
124
+ return;
125
+ const portal = import_Utils.SwcUtils.getParentContainer(this);
126
+ if (!portal)
127
+ return;
128
+ const win = this.ownerDocument?.defaultView || window;
129
+ const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
130
+ if (this._value !== items) {
131
+ this._value = [...items, ...this._value || []];
132
+ }
133
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
134
+ this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
72
135
  portal.insertBefore(fragment, this.nextSibling);
73
136
  }
137
+ refresh(value) {
138
+ const targetValue = value !== void 0 ? value : (0, import_decorators.getAttributeValue)(this, "value") ?? this._value ?? [];
139
+ this.cleanup();
140
+ this._value = targetValue;
141
+ if (!this._value || this._value.length <= 0)
142
+ return;
143
+ const win = this.ownerDocument?.defaultView || window;
144
+ const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
145
+ helperSet.$templateHost = this;
146
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
147
+ this._nodeGroups = newNodesGroup;
148
+ const portal = import_Utils.SwcUtils.getParentContainer(this);
149
+ if (portal) {
150
+ portal.insertBefore(fragment, this.nextSibling);
151
+ }
152
+ }
74
153
  cleanup() {
154
+ console.log("\uB204\uAC00 cleanup");
75
155
  this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
76
156
  this._nodeGroups = [];
77
157
  }
@@ -80,23 +160,17 @@ class SwcLoop extends HTMLTemplateElement {
80
160
  }
81
161
  }
82
162
  __decorate([
83
- (0, import_decorators.attributeHost)("value"),
84
- __metadata("design:type", Array)
85
- ], SwcLoop.prototype, "_value", void 0);
163
+ (0, import_decorators.attributeThis)("replace-wrap-start"),
164
+ __metadata("design:type", String)
165
+ ], SwcLoop.prototype, "_replaceWrapStart", void 0);
86
166
  __decorate([
87
- (0, import_decorators.attributeHost)("replace-wrap"),
167
+ (0, import_decorators.attributeThis)("replace-wrap-end"),
88
168
  __metadata("design:type", String)
89
- ], SwcLoop.prototype, "_replaceWrap", void 0);
169
+ ], SwcLoop.prototype, "_replaceWrapEnd", void 0);
90
170
  __decorate([
91
- (0, import_changedAttributeHost.changedAttributeHost)("value"),
171
+ (0, import_changedAttributeThis.changedAttributeThis)("value"),
92
172
  __metadata("design:type", Function),
93
- __metadata("design:paramtypes", []),
173
+ __metadata("design:paramtypes", [Object, String, String]),
94
174
  __metadata("design:returntype", void 0)
95
175
  ], SwcLoop.prototype, "setValue", null);
96
- __decorate([
97
- (0, import_changedAttributeHost.changedAttributeHost)("replace-wrap"),
98
- __metadata("design:type", Function),
99
- __metadata("design:paramtypes", []),
100
- __metadata("design:returntype", void 0)
101
- ], SwcLoop.prototype, "setReplaceWrap", null);
102
176
  //# sourceMappingURL=SwcLoop.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcLoop.ts"],
4
- "sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { attributeHost } from '../decorators';\n\nclass SwcLoop extends HTMLTemplateElement {\n @attributeHost('value')\n _value: any[];\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodeGroups: Node[][] = [];\n\n get value(): any[] {\n return this._value;\n }\n set value(nv: any[]) {\n // this._value = Array.isArray(nv) ? [...nv] : [];\n this.refresh(nv);\n }\n\n @changedAttributeHost('value')\n private setValue() {\n this.refresh();\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap() {\n this.refresh();\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value = this._value) {\n this.cleanup();\n if (value?.length<=0) return;\n const portal = this.parentElement;\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const fragment = win.document.createDocumentFragment();\n\n value.forEach((item, index) => {\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const temp = this.ownerDocument?.createElement('template') || document.createElement('template');\n temp.innerHTML = htmlString;\n\n const content = temp.content;\n const nodes = Array.from(content.childNodes);\n this._nodeGroups.push(nodes);\n fragment.appendChild(content);\n });\n\n portal.insertBefore(fragment, this.nextSibling);\n }\n\n private cleanup() {\n this._nodeGroups.forEach(nodes => nodes.forEach(n => n.parentElement?.removeChild(n)));\n this._nodeGroups = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
- "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAC7B,wBAA8B;;;;;;;;;;AAE9B,MAAM,gBAAgB,oBAAmB;EAAzC,cAAA;;AAOU,SAAA,cAAwB,CAAA;EA8ElC;EA5EE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EACA,IAAI,MAAM,IAAS;AAEjB,SAAK,QAAQ,EAAE;EACjB;EAGQ,WAAQ;AACd,SAAK,QAAO;EACd;EAGQ,iBAAc;AACpB,SAAK,QAAO;EACd;EAEQ,mBAAmB,MAAc,WAAgB,SAAc,MAAoB;AACzF,UAAM,SAAS,OAAO,EAAE,gBAAgB,KAAI,IAAK;AACjD,UAAM,KAAK,IAAI,6BAAiB,MAAM,MAAM;AAC5C,UAAM,gBAAgB,OAAO,EAAE,MAAM,WAAoB,KAAI,IAAK;AAClE,UAAM,MAAM,KAAK,eAAe,eAAe;AAG/C,eAAW,QAAQ,GAAG,eAAe,aAAa,GAAG;AACnD,UAAI;AACF,cAAM,QAAQ,0BAAc,cAAc;UACxC,QAAQ,6BAAa,iBAAiB,KAAK,QAAQ,IAAI,QAAQ;UAC/D;UACA,MAAM;SACP;AACD,WAAG,QAAQ,MAAM,OAAO,KAAK,CAAC;MAChC,SAAS,GAAG;AACV,gBAAQ,MAAM,2BAA2B,KAAK,QAAQ,KAAK,CAAC;MAC9D;IACF;AACA,WAAO,GAAG,uBAAsB;EAClC;EAEA,QAAQ,QAAQ,KAAK,QAAM;AACzB,SAAK,QAAO;AACZ,QAAI,OAAO,UAAQ;AAAG;AACtB,UAAM,SAAS,KAAK;AACpB,QAAI,CAAC;AAAQ;AAEb,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,YAAY,sBAAS,oBAAoB,KAAK,IAAI;AACxD,UAAM,WAAW,IAAI,SAAS,uBAAsB;AAEpD,UAAM,QAAQ,CAAC,MAAM,UAAS;AAC5B,UAAI,aAAa,KAAK;AACtB,YAAM,YAAY,EAAE,GAAG,WAAW,OAAO,MAAM,QAAQ,OAAO,QAAQ,KAAK,OAAM;AAEjF,mBAAa,KAAK,mBAAmB,YAAY,WAAW,MAAM,KAAK,YAAY;AAEnF,YAAM,OAAO,KAAK,eAAe,cAAc,UAAU,KAAK,SAAS,cAAc,UAAU;AAC/F,WAAK,YAAY;AAEjB,YAAM,UAAU,KAAK;AACrB,YAAM,QAAQ,MAAM,KAAK,QAAQ,UAAU;AAC3C,WAAK,YAAY,KAAK,KAAK;AAC3B,eAAS,YAAY,OAAO;IAC9B,CAAC;AAED,WAAO,aAAa,UAAU,KAAK,WAAW;EAChD;EAEQ,UAAO;AACb,SAAK,YAAY,QAAQ,WAAS,MAAM,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC,CAAC;AACrF,SAAK,cAAc,CAAA;EACrB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAlFA,WAAA;MADC,iCAAc,OAAO;;;AAItB,WAAA;MADC,iCAAc,cAAc;;;AAcrB,WAAA;MADP,kDAAqB,OAAO;;;;;AAMrB,WAAA;MADP,kDAAqB,cAAc;;;;;",
4
+ "sourcesContent": ["import { changedAttributeThis } from '../decorators/changedAttributeThis';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { attributeThis, getAttributeValue } from '../decorators';\n\nclass SwcLoop extends HTMLTemplateElement {\n _value: any[] = [];\n\n @attributeThis('replace-wrap-start')\n _replaceWrapStart: string | null;\n @attributeThis('replace-wrap-end')\n _replaceWrapEnd: string | null;\n\n private _nodeGroups: Node[][] = [];\n\n get value(): any[] {\n return this._value;\n }\n\n set value(nv: any[]) {\n this._value = nv;\n this.refresh(nv);\n }\n\n getValue(index: number) {\n return this._value?.[index];\n }\n\n constructor() {\n super();\n // console.log('swc SwcLoop constructor called!');\n // console.log('swc SwcLoop', this.getAttribute('value'));\n }\n\n @changedAttributeThis('value')\n private setValue(value: any, o: string, n: string) {\n this._value = value;\n this.refresh(this._value);\n }\n\n // @changedAttributeThis('replace-wrap')\n // private setReplaceWrap(replaceWrapAttr?: string | null) {\n // this.refresh();\n // }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap: {start: string, end: string}): string {\n let config: any = undefined;\n config = {\n expression: {\n replace: { start: `${wrap.start}`, end: `${wrap.end}` },\n callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },\n call: { start: `${wrap.start}@`, end: `${wrap.end}` }\n }\n };\n const ae = new ActionExpression(html, config);\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n const expressions = ae.getExpressions('replace');\n for (const expr of expressions) {\n const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n try {\n const value = FunctionUtils.executeReturn({\n script: script,\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n private createFragmentAndNodes(items: any[], helperSet: any, startIndex: number = 0): { fragment: DocumentFragment; newNodesGroup: Node[][] } {\n const win = this.ownerDocument?.defaultView || window;\n const fragment = win.document.createDocumentFragment();\n const newNodesGroup: Node[][] = [];\n\n items.forEach((item, i) => {\n const index = startIndex + i;\n let htmlString = this.innerHTML;\n const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, {start:this._replaceWrapStart ?? '{#{', end: this._replaceWrapEnd ?? '}#}'});\n\n const temp = this.ownerDocument?.createElement('template') || document.createElement('template');\n temp.innerHTML = htmlString;\n\n const content = temp.content;\n const nodes = Array.from(content.childNodes);\n\n const setTemplateHost = (element: HTMLElement) => {\n (element as any).__swc_template_host = this;\n Array.from(element.children).forEach((child: any) => {\n if (child instanceof HTMLElement) {\n setTemplateHost(child);\n }\n });\n };\n\n nodes.forEach((node: any) => {\n if (node instanceof HTMLElement) {\n setTemplateHost(node as HTMLElement);\n }\n });\n newNodesGroup.push(nodes);\n fragment.appendChild(content);\n });\n\n return { fragment, newNodesGroup };\n }\n\n appendItem(...items: any[]) {\n if (!items || items.length <= 0) return;\n const portal = SwcUtils.getParentContainer(this);\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const startIndex = this._value ? this._value.length : 0;\n\n // 내부 상태(value) 업데이트 (기존 배열에 새 아이템 추가)\n if (this._value !== items) {\n this._value = [...(this._value || []), ...items];\n }\n\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);\n this._nodeGroups.push(...newNodesGroup);\n\n console.log('뭐야 씨발');\n // append 위치 계산: 기존에 그려진 마지막 노드 뒤에 삽입, 없으면 템플릿 바로 뒤에 삽입\n let insertReference: Node | null = this.nextSibling;\n if (this._nodeGroups.length > items.length) {\n const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];\n if (lastExistingGroup && lastExistingGroup.length > 0) {\n const lastNode = lastExistingGroup[lastExistingGroup.length - 1];\n insertReference = lastNode.nextSibling;\n }\n }\n\n portal.insertBefore(fragment, insertReference);\n }\n\n async prependItem(...items: any[]) {\n if (!items || items.length <= 0) return;\n const portal = SwcUtils.getParentContainer(this);\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n // 내부 상태(value) 업데이트 (기존 배열의 앞쪽에 새 아이템 추가)\n if (this._value !== items) {\n this._value = [...items, ...(this._value || [])];\n }\n\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);\n\n // 기존의 nodeGroups 배열 맨 앞에 새로운 그룹들을 추가\n this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];\n\n // prepend 위치: 이 템플릿(SwcLoop) 노드의 바로 다음 위치 (가장 위)\n portal.insertBefore(fragment, this.nextSibling);\n }\n\n refresh(value?: any) {\n // 1. 그릴 대상 확정\n const targetValue = value !== undefined ? value : (getAttributeValue(this, 'value') ?? this._value ?? []);\n\n // 2. 화면 정리\n this.cleanup();\n\n // 3. 상태 완전 교체 (이어붙이지 않음!)\n this._value = targetValue;\n\n if (!this._value || this._value.length <= 0) return;\n\n // 4. 화면 다시 그리기 (appendItem을 쓰지 않고 바로 그리기)\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n helperSet.$templateHost = this;\n const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);\n\n this._nodeGroups = newNodesGroup;\n const portal = SwcUtils.getParentContainer(this);\n if (portal) {\n // console.log('append????!~~~~~!?',fragment)\n portal.insertBefore(fragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n console.log('누가 cleanup');\n this._nodeGroups.forEach(nodes => nodes.forEach(n => n.parentElement?.removeChild(n)));\n this._nodeGroups = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
5
+ "mappings": "AAAA,kCAAqC;AACrC,mBAAyB;AACzB,kBAAgD;AAChD,sBAA6B;AAC7B,wBAAiD;;;;;;;;;;AAEjD,MAAM,gBAAgB,oBAAmB;EAUvC,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAS;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,EAAE;EACjB;EAEA,SAAS,OAAa;AACpB,WAAO,KAAK,SAAS,KAAK;EAC5B;EAEA,cAAA;AACE,UAAK;AAvBP,SAAA,SAAgB,C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