@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
@@ -7,7 +7,7 @@ var __decorate = function(decorators, target, key, desc) {
7
7
  var __metadata = function(k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { getElementConfig, elementDefine, attributeHost, changedAttributeHost, getAttributeValue } from "../decorators/index.js";
10
+ import { getElementConfig, elementDefine, attributeThis, changedAttributeThis, getAttributeValue } from "../decorators/index.js";
11
11
  import { SwcAppMixin } from "./SwcAppMixin.js";
12
12
  import { SwcUtils } from "../utils/Utils.js";
13
13
  import { FunctionUtils, ActionExpression } from "@dooboostore/core";
@@ -111,22 +111,38 @@ const registerAllElements = (w) => {
111
111
  elementDefine("swc-app", { window: w })
112
112
  ], SwcApp);
113
113
  let SwcIf = class SwcIf extends HTMLTemplateElement {
114
- constructor() {
115
- super(...arguments);
116
- this._nodes = [];
117
- }
118
114
  get value() {
119
115
  return this._value;
120
116
  }
121
117
  set value(nv) {
122
118
  this.refresh(nv);
123
119
  }
120
+ constructor() {
121
+ super();
122
+ this._nodes = [];
123
+ }
124
+ setValue(value, o, n) {
125
+ this._value = value;
126
+ this.refresh(this._value);
127
+ }
128
+ // @changedAttributeThis('replace-wrap')
129
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
130
+ // this.refresh();
131
+ // }
124
132
  replaceExpressions(html, groupArgs, context, wrap) {
125
- const config = wrap ? { wrapExpression: wrap } : void 0;
133
+ let config = void 0;
134
+ if (wrap) {
135
+ config = {
136
+ expression: {
137
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
138
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
139
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
140
+ }
141
+ };
142
+ }
126
143
  const ae = new ActionExpression(html, config);
127
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
128
144
  const win = this.ownerDocument?.defaultView || window;
129
- for (const expr of ae.getExpressions(filterOptions)) {
145
+ for (const expr of ae.getExpressions("replace")) {
130
146
  try {
131
147
  const value = FunctionUtils.executeReturn({
132
148
  script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
@@ -140,30 +156,38 @@ const registerAllElements = (w) => {
140
156
  }
141
157
  return ae.getUnprocessedTemplate();
142
158
  }
143
- setValue(valueAttr) {
144
- this.refresh();
145
- }
146
- setReplaceWrap(replaceWrapAttr) {
147
- this.refresh();
148
- }
149
- refresh(value = this._value) {
159
+ refresh(value) {
160
+ const targetValue = value !== void 0 ? value : getAttributeValue(this, "value") ?? this._value;
161
+ if (this.hasAttribute("skip-if-same") && this._value === targetValue && this._nodes.length > 0) {
162
+ return;
163
+ }
150
164
  this.cleanup();
165
+ this._value = targetValue;
151
166
  const portal = this.parentElement;
152
- if (!portal || !value)
167
+ if (!portal || !this._value)
153
168
  return;
154
169
  const win = this.ownerDocument?.defaultView || window;
155
170
  const helperSet = SwcUtils.getHelperAndHostSet(win, this);
156
171
  let htmlString = this.innerHTML;
157
- const groupArgs = { ...helperSet, $value: value };
158
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
172
+ const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };
173
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
159
174
  const result = this.ownerDocument?.createElement("template") || document.createElement("template");
160
175
  result.innerHTML = htmlString;
161
176
  const processedFragment = result.content;
162
177
  this._nodes = Array.from(processedFragment.childNodes);
178
+ this._nodes.forEach((node) => {
179
+ if (node instanceof HTMLElement)
180
+ node.__swc_template_host = this;
181
+ });
163
182
  portal.insertBefore(processedFragment, this.nextSibling);
164
183
  }
165
184
  cleanup() {
166
- this._nodes.forEach((n) => n.parentElement?.removeChild(n));
185
+ this._nodes.forEach((n) => {
186
+ const realNode = n.__upgraded_instance || n;
187
+ if (realNode.parentElement) {
188
+ realNode.parentElement.removeChild(realNode);
189
+ }
190
+ });
167
191
  this._nodes = [];
168
192
  }
169
193
  disconnectedCallback() {
@@ -171,54 +195,68 @@ const registerAllElements = (w) => {
171
195
  }
172
196
  };
173
197
  __decorate([
174
- attributeHost("value"),
175
- __metadata("design:type", Object)
176
- ], SwcIf.prototype, "_value", void 0);
198
+ attributeThis("replace-wrap-start"),
199
+ __metadata("design:type", String)
200
+ ], SwcIf.prototype, "_replaceWrapStart", void 0);
177
201
  __decorate([
178
- attributeHost("replace-wrap"),
202
+ attributeThis("replace-wrap-end"),
179
203
  __metadata("design:type", String)
180
- ], SwcIf.prototype, "_replaceWrap", void 0);
204
+ ], SwcIf.prototype, "_replaceWrapEnd", void 0);
181
205
  __decorate([
182
- changedAttributeHost("value"),
183
- __metadata("design:type", Function),
184
- __metadata("design:paramtypes", [String]),
185
- __metadata("design:returntype", void 0)
186
- ], SwcIf.prototype, "setValue", null);
206
+ attributeThis("skip-if-same"),
207
+ __metadata("design:type", String)
208
+ ], SwcIf.prototype, "_skipIfSame", void 0);
187
209
  __decorate([
188
- changedAttributeHost("replace-wrap"),
210
+ changedAttributeThis("value"),
189
211
  __metadata("design:type", Function),
190
- __metadata("design:paramtypes", [String]),
212
+ __metadata("design:paramtypes", [Object, String, String]),
191
213
  __metadata("design:returntype", void 0)
192
- ], SwcIf.prototype, "setReplaceWrap", null);
214
+ ], SwcIf.prototype, "setValue", null);
193
215
  SwcIf = __decorate([
194
- elementDefine("swc-if", { extends: "template", window: w })
216
+ elementDefine("swc-if", { extends: "template", window: w }),
217
+ __metadata("design:paramtypes", [])
195
218
  ], SwcIf);
196
219
  let SwcLoop = class SwcLoop extends HTMLTemplateElement {
197
- constructor() {
198
- super(...arguments);
199
- this._nodeGroups = [];
200
- }
201
220
  get value() {
202
221
  return this._value;
203
222
  }
204
223
  set value(nv) {
224
+ this._value = nv;
205
225
  this.refresh(nv);
206
226
  }
207
- setValue() {
208
- this.refresh();
227
+ getValue(index) {
228
+ return this._value?.[index];
229
+ }
230
+ constructor() {
231
+ super();
232
+ this._value = [];
233
+ this._nodeGroups = [];
209
234
  }
210
- setReplaceWrap() {
211
- this.refresh();
235
+ setValue(value, o, n) {
236
+ this._value = value;
237
+ this.refresh(this._value);
212
238
  }
239
+ // @changedAttributeThis('replace-wrap')
240
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
241
+ // this.refresh();
242
+ // }
213
243
  replaceExpressions(html, groupArgs, context, wrap) {
214
- const config = wrap ? { wrapExpression: wrap } : void 0;
244
+ let config = void 0;
245
+ config = {
246
+ expression: {
247
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
248
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
249
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
250
+ }
251
+ };
215
252
  const ae = new ActionExpression(html, config);
216
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
217
253
  const win = this.ownerDocument?.defaultView || window;
218
- for (const expr of ae.getExpressions(filterOptions)) {
254
+ const expressions = ae.getExpressions("replace");
255
+ for (const expr of expressions) {
256
+ const script = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
219
257
  try {
220
258
  const value = FunctionUtils.executeReturn({
221
- script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
259
+ script,
222
260
  context,
223
261
  args: groupArgs
224
262
  });
@@ -229,30 +267,95 @@ const registerAllElements = (w) => {
229
267
  }
230
268
  return ae.getUnprocessedTemplate();
231
269
  }
232
- refresh(value = this._value) {
233
- this.cleanup();
234
- if (value?.length <= 0)
235
- return;
236
- const portal = this.parentElement;
237
- if (!portal)
238
- return;
270
+ createFragmentAndNodes(items, helperSet, startIndex = 0) {
239
271
  const win = this.ownerDocument?.defaultView || window;
240
- const helperSet = SwcUtils.getHelperAndHostSet(win, this);
241
272
  const fragment = win.document.createDocumentFragment();
242
- value.forEach((item, index) => {
273
+ const newNodesGroup = [];
274
+ items.forEach((item, i) => {
275
+ const index = startIndex + i;
243
276
  let htmlString = this.innerHTML;
244
277
  const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
245
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
278
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
246
279
  const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
247
280
  temp.innerHTML = htmlString;
248
281
  const content = temp.content;
249
282
  const nodes = Array.from(content.childNodes);
250
- this._nodeGroups.push(nodes);
283
+ const setTemplateHost = (element) => {
284
+ element.__swc_template_host = this;
285
+ Array.from(element.children).forEach((child) => {
286
+ if (child instanceof HTMLElement) {
287
+ setTemplateHost(child);
288
+ }
289
+ });
290
+ };
291
+ nodes.forEach((node) => {
292
+ if (node instanceof HTMLElement) {
293
+ setTemplateHost(node);
294
+ }
295
+ });
296
+ newNodesGroup.push(nodes);
251
297
  fragment.appendChild(content);
252
298
  });
299
+ return { fragment, newNodesGroup };
300
+ }
301
+ appendItem(...items) {
302
+ if (!items || items.length <= 0)
303
+ return;
304
+ const portal = SwcUtils.getParentContainer(this);
305
+ if (!portal)
306
+ return;
307
+ const win = this.ownerDocument?.defaultView || window;
308
+ const helperSet = SwcUtils.getHelperAndHostSet(win, this);
309
+ const startIndex = this._value ? this._value.length : 0;
310
+ if (this._value !== items) {
311
+ this._value = [...this._value || [], ...items];
312
+ }
313
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
314
+ this._nodeGroups.push(...newNodesGroup);
315
+ console.log("\uBB50\uC57C \uC528\uBC1C");
316
+ let insertReference = this.nextSibling;
317
+ if (this._nodeGroups.length > items.length) {
318
+ const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
319
+ if (lastExistingGroup && lastExistingGroup.length > 0) {
320
+ const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
321
+ insertReference = lastNode.nextSibling;
322
+ }
323
+ }
324
+ portal.insertBefore(fragment, insertReference);
325
+ }
326
+ async prependItem(...items) {
327
+ if (!items || items.length <= 0)
328
+ return;
329
+ const portal = SwcUtils.getParentContainer(this);
330
+ if (!portal)
331
+ return;
332
+ const win = this.ownerDocument?.defaultView || window;
333
+ const helperSet = SwcUtils.getHelperAndHostSet(win, this);
334
+ if (this._value !== items) {
335
+ this._value = [...items, ...this._value || []];
336
+ }
337
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
338
+ this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
253
339
  portal.insertBefore(fragment, this.nextSibling);
254
340
  }
341
+ refresh(value) {
342
+ const targetValue = value !== void 0 ? value : getAttributeValue(this, "value") ?? this._value ?? [];
343
+ this.cleanup();
344
+ this._value = targetValue;
345
+ if (!this._value || this._value.length <= 0)
346
+ return;
347
+ const win = this.ownerDocument?.defaultView || window;
348
+ const helperSet = SwcUtils.getHelperAndHostSet(win, this);
349
+ helperSet.$templateHost = this;
350
+ const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
351
+ this._nodeGroups = newNodesGroup;
352
+ const portal = SwcUtils.getParentContainer(this);
353
+ if (portal) {
354
+ portal.insertBefore(fragment, this.nextSibling);
355
+ }
356
+ }
255
357
  cleanup() {
358
+ console.log("\uB204\uAC00 cleanup");
256
359
  this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
257
360
  this._nodeGroups = [];
258
361
  }
@@ -261,27 +364,22 @@ const registerAllElements = (w) => {
261
364
  }
262
365
  };
263
366
  __decorate([
264
- attributeHost("value"),
265
- __metadata("design:type", Array)
266
- ], SwcLoop.prototype, "_value", void 0);
367
+ attributeThis("replace-wrap-start"),
368
+ __metadata("design:type", String)
369
+ ], SwcLoop.prototype, "_replaceWrapStart", void 0);
267
370
  __decorate([
268
- attributeHost("replace-wrap"),
371
+ attributeThis("replace-wrap-end"),
269
372
  __metadata("design:type", String)
270
- ], SwcLoop.prototype, "_replaceWrap", void 0);
373
+ ], SwcLoop.prototype, "_replaceWrapEnd", void 0);
271
374
  __decorate([
272
- changedAttributeHost("value"),
375
+ changedAttributeThis("value"),
273
376
  __metadata("design:type", Function),
274
- __metadata("design:paramtypes", []),
377
+ __metadata("design:paramtypes", [Object, String, String]),
275
378
  __metadata("design:returntype", void 0)
276
379
  ], SwcLoop.prototype, "setValue", null);
277
- __decorate([
278
- changedAttributeHost("replace-wrap"),
279
- __metadata("design:type", Function),
280
- __metadata("design:paramtypes", []),
281
- __metadata("design:returntype", void 0)
282
- ], SwcLoop.prototype, "setReplaceWrap", null);
283
380
  SwcLoop = __decorate([
284
- elementDefine("swc-loop", { extends: "template", window: w })
381
+ elementDefine("swc-loop", { extends: "template", window: w }),
382
+ __metadata("design:paramtypes", [])
285
383
  ], SwcLoop);
286
384
  let SwcChoose = class SwcChoose extends HTMLTemplateElement {
287
385
  get value() {
@@ -302,18 +400,28 @@ const registerAllElements = (w) => {
302
400
  attributeChangedCallback(na, o, n) {
303
401
  }
304
402
  setValue(value, o, n) {
403
+ console.log("chooooooose value", value);
305
404
  this._value = value;
306
405
  this.refresh(this._value);
307
406
  }
308
- setReplaceWrap(replaceWrapAttr) {
309
- this.refresh();
310
- }
407
+ // @changedAttributeThis('replace-wrap')
408
+ // private setReplaceWrap(replaceWrapAttr?: string | null) {
409
+ // this.refresh();
410
+ // }
311
411
  replaceExpressions(html, groupArgs, context, wrap) {
312
- const config = wrap ? { wrapExpression: wrap } : void 0;
412
+ let config = void 0;
413
+ if (wrap) {
414
+ config = {
415
+ expression: {
416
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
417
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
418
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
419
+ }
420
+ };
421
+ }
313
422
  const ae = new ActionExpression(html, config);
314
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
315
423
  const win = this.ownerDocument?.defaultView || window;
316
- for (const expr of ae.getExpressions(filterOptions)) {
424
+ for (const expr of ae.getExpressions("replace")) {
317
425
  try {
318
426
  const value = FunctionUtils.executeReturn({
319
427
  script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
@@ -329,31 +437,27 @@ const registerAllElements = (w) => {
329
437
  }
330
438
  refresh(value) {
331
439
  value = getAttributeValue(this, "value") ?? this._value;
332
- const portal = this.parentElement;
333
- if (!portal)
440
+ console.log("[DEBUG] SwcChoose.refresh called, value:", value);
441
+ const portal = SwcUtils.getParentContainer(this);
442
+ if (!portal) {
443
+ console.log("[DEBUG] SwcChoose portal is null!");
334
444
  return;
445
+ }
335
446
  const win = (getElementConfig(this).window ?? this.ownerDocument?.defaultView) || window;
336
447
  const helperSet = SwcUtils.getHelperAndHostSet(win, this);
337
- const groupArgs = { ...helperSet, $value: value };
448
+ const groupArgs = { ...helperSet, $value: value, $templateHost: this };
338
449
  const templates = Array.from(this.content.querySelectorAll("template"));
339
450
  let selected = null;
340
451
  for (const t of templates) {
341
452
  if (t.getAttribute("is") === "swc-when") {
342
- const attrVal = t.getAttribute("value") || "";
453
+ const attrVal = t.getAttribute("test") || "";
343
454
  let matches = false;
344
- const ae = new ActionExpression(attrVal);
345
- const expr = ae.getFirstExpression("replace");
346
- if (expr) {
347
- const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
348
- const result = FunctionUtils.executeReturn({
349
- script: decodedScript,
350
- context: t,
351
- args: groupArgs
352
- });
353
- matches = !!result;
354
- } else {
355
- matches = String(attrVal) === String(value);
356
- }
455
+ const result = FunctionUtils.executeReturn({
456
+ script: attrVal,
457
+ context: t,
458
+ args: groupArgs
459
+ });
460
+ matches = !!result;
357
461
  if (matches) {
358
462
  selected = t;
359
463
  break;
@@ -372,12 +476,27 @@ const registerAllElements = (w) => {
372
476
  this._previousTemplate = target;
373
477
  if (target) {
374
478
  let htmlString = target.innerHTML;
375
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
479
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
376
480
  const result = this.ownerDocument?.createElement("template") || document.createElement("template");
377
481
  result.innerHTML = htmlString;
378
482
  const processedFragment = result.content;
379
483
  this._nodes = Array.from(processedFragment.childNodes);
484
+ const setTemplateHost = (element) => {
485
+ element.__swc_template_host = this;
486
+ Array.from(element.children).forEach((child) => {
487
+ if (child instanceof HTMLElement) {
488
+ setTemplateHost(child);
489
+ }
490
+ });
491
+ };
492
+ this._nodes.forEach((node) => {
493
+ if (node instanceof HTMLElement) {
494
+ setTemplateHost(node);
495
+ }
496
+ });
497
+ console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${portal?.isConnected}`);
380
498
  portal.insertBefore(processedFragment, this.nextSibling);
499
+ console.log("[DEBUG] SwcChoose after insertBefore");
381
500
  }
382
501
  }
383
502
  cleanup() {
@@ -389,21 +508,19 @@ const registerAllElements = (w) => {
389
508
  }
390
509
  };
391
510
  __decorate([
392
- attributeHost("replace-wrap"),
511
+ attributeThis("replace-wrap-start"),
393
512
  __metadata("design:type", String)
394
- ], SwcChoose.prototype, "_replaceWrap", void 0);
513
+ ], SwcChoose.prototype, "_replaceWrapStart", void 0);
395
514
  __decorate([
396
- changedAttributeHost("value"),
515
+ attributeThis("replace-wrap-end"),
516
+ __metadata("design:type", String)
517
+ ], SwcChoose.prototype, "_replaceWrapEnd", void 0);
518
+ __decorate([
519
+ changedAttributeThis("value"),
397
520
  __metadata("design:type", Function),
398
521
  __metadata("design:paramtypes", [Object, String, String]),
399
522
  __metadata("design:returntype", void 0)
400
523
  ], SwcChoose.prototype, "setValue", null);
401
- __decorate([
402
- changedAttributeHost("replace-wrap"),
403
- __metadata("design:type", Function),
404
- __metadata("design:paramtypes", [String]),
405
- __metadata("design:returntype", void 0)
406
- ], SwcChoose.prototype, "setReplaceWrap", null);
407
524
  SwcChoose = __decorate([
408
525
  elementDefine("swc-choose", { extends: "template", window: w }),
409
526
  __metadata("design:paramtypes", [])
@@ -422,9 +539,10 @@ const registerAllElements = (w) => {
422
539
  setValue(valueAttr) {
423
540
  this.executeAsync(this._value);
424
541
  }
425
- setReplaceWrap() {
426
- this.executeAsync(this._value);
427
- }
542
+ // @changedAttributeThis('replace-wrap')
543
+ // private setReplaceWrap() {
544
+ // this.executeAsync(this._value);
545
+ // }
428
546
  executeAsync(result = this._value) {
429
547
  if (result === void 0 || result === null) {
430
548
  this.refresh("default");
@@ -446,11 +564,19 @@ const registerAllElements = (w) => {
446
564
  }
447
565
  }
448
566
  replaceExpressions(html, groupArgs, context, wrap) {
449
- const config = wrap ? { wrapExpression: wrap } : void 0;
567
+ let config = void 0;
568
+ if (wrap) {
569
+ config = {
570
+ expression: {
571
+ replace: { start: `${wrap.start}`, end: `${wrap.end}` },
572
+ callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
573
+ call: { start: `${wrap.start}@`, end: `${wrap.end}` }
574
+ }
575
+ };
576
+ }
450
577
  const ae = new ActionExpression(html, config);
451
- const filterOptions = wrap ? { type: "replace", wrap } : "replace";
452
578
  const win = this.ownerDocument?.defaultView || window;
453
- for (const expr of ae.getExpressions(filterOptions)) {
579
+ for (const expr of ae.getExpressions("replace")) {
454
580
  try {
455
581
  const value = FunctionUtils.executeReturn({
456
582
  script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
@@ -465,9 +591,8 @@ const registerAllElements = (w) => {
465
591
  return ae.getUnprocessedTemplate();
466
592
  }
467
593
  refresh(state = "default") {
468
- console.log("rrrrrrrrrrrrrrrrr", state);
469
594
  this.cleanup();
470
- const portal = this.parentElement;
595
+ const portal = SwcUtils.getParentContainer(this);
471
596
  if (!portal)
472
597
  return;
473
598
  const win = this.ownerDocument?.defaultView || window;
@@ -475,12 +600,16 @@ const registerAllElements = (w) => {
475
600
  const t = this.content.querySelector(`template[is="swc-${state}"]`);
476
601
  if (t) {
477
602
  let htmlString = t.innerHTML;
478
- const groupArgs = { ...helperSet, $value: this._value, $state: state };
479
- htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
603
+ const groupArgs = { ...helperSet, $value: this._value, $state: state, $templateHost: this };
604
+ htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
480
605
  const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
481
606
  temp.innerHTML = htmlString;
482
607
  const content = temp.content;
483
608
  this._nodes = Array.from(content.childNodes);
609
+ this._nodes.forEach((node) => {
610
+ if (node instanceof HTMLElement)
611
+ node.__template_swc_host = this;
612
+ });
484
613
  portal.insertBefore(content, this.nextSibling);
485
614
  }
486
615
  }
@@ -493,25 +622,23 @@ const registerAllElements = (w) => {
493
622
  }
494
623
  };
495
624
  __decorate([
496
- attributeHost("value"),
625
+ attributeThis("value"),
497
626
  __metadata("design:type", Object)
498
627
  ], SwcAsync.prototype, "_value", void 0);
499
628
  __decorate([
500
- attributeHost("replace-wrap"),
629
+ attributeThis("replace-wrap-start"),
630
+ __metadata("design:type", String)
631
+ ], SwcAsync.prototype, "_replaceWrapStart", void 0);
632
+ __decorate([
633
+ attributeThis("replace-wrap-end"),
501
634
  __metadata("design:type", String)
502
- ], SwcAsync.prototype, "_replaceWrap", void 0);
635
+ ], SwcAsync.prototype, "_replaceWrapEnd", void 0);
503
636
  __decorate([
504
- changedAttributeHost("value"),
637
+ changedAttributeThis("value"),
505
638
  __metadata("design:type", Function),
506
639
  __metadata("design:paramtypes", [String]),
507
640
  __metadata("design:returntype", void 0)
508
641
  ], SwcAsync.prototype, "setValue", null);
509
- __decorate([
510
- changedAttributeHost("replace-wrap"),
511
- __metadata("design:type", Function),
512
- __metadata("design:paramtypes", []),
513
- __metadata("design:returntype", void 0)
514
- ], SwcAsync.prototype, "setReplaceWrap", null);
515
642
  SwcAsync = __decorate([
516
643
  elementDefine("swc-async", { extends: "template", window: w })
517
644
  ], SwcAsync);