@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.
- package/README.md +44 -51
- package/dist/cjs/decorators/addEventListener.js +12 -4
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +19 -18
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +23 -22
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +22 -17
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +20 -19
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -16
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/{changedAttributeHost.js → changedAttributeThis.js} +6 -6
- package/dist/cjs/decorators/changedAttributeThis.js.map +7 -0
- package/dist/cjs/decorators/elementDefine.js +234 -188
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js +24 -16
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -1
- package/dist/cjs/decorators/index.js.map +1 -1
- package/dist/cjs/decorators/lifecycles.js +15 -17
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/query.js +38 -60
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +31 -63
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +13 -12
- package/dist/cjs/decorators/setProperty.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +8 -2
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +120 -65
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +31 -21
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +53 -34
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +54 -32
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +111 -37
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/register.js +249 -122
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +4 -2
- package/dist/cjs/router/ElementRouter.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +31 -17
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +12 -4
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +19 -18
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +23 -22
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +22 -17
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +20 -19
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +17 -16
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/{changedAttributeHost.js → changedAttributeThis.js} +3 -3
- package/dist/esm/decorators/changedAttributeThis.js.map +7 -0
- package/dist/esm/decorators/elementDefine.js +233 -187
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js +24 -16
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -1
- package/dist/esm/decorators/index.js.map +1 -1
- package/dist/esm/decorators/lifecycles.js +15 -17
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/query.js +38 -60
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +31 -63
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +13 -12
- package/dist/esm/decorators/setProperty.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +9 -2
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +122 -66
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +32 -22
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +54 -35
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +55 -33
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +112 -38
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/register.js +250 -123
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +5 -2
- package/dist/esm/router/ElementRouter.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +31 -17
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +563 -557
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +5 -7
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +4 -4
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +6 -6
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +7 -6
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +4 -4
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/attribute.d.ts +5 -5
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/changedAttributeThis.d.ts +18 -0
- package/dist/types/decorators/changedAttributeThis.d.ts.map +1 -0
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +11 -12
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -1
- package/dist/types/decorators/lifecycles.d.ts +10 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +17 -63
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +6 -63
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +1 -1
- package/dist/types/decorators/setProperty.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +4 -5
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts +4 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +11 -8
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +11 -8
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +563 -557
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +11 -9
- package/src/decorators/applyAttribute.ts +16 -15
- package/src/decorators/applyClass.ts +18 -17
- package/src/decorators/applyNode.ts +34 -21
- package/src/decorators/applyStyle.ts +17 -16
- package/src/decorators/attribute.ts +21 -20
- package/src/decorators/{changedAttributeHost.ts → changedAttributeThis.ts} +13 -14
- package/src/decorators/elementDefine.ts +402 -358
- package/src/decorators/emitCustomEvent.ts +40 -31
- package/src/decorators/index.ts +1 -1
- package/src/decorators/lifecycles.ts +11 -10
- package/src/decorators/query.ts +51 -124
- package/src/decorators/queryAll.ts +30 -127
- package/src/decorators/setProperty.ts +12 -11
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +10 -10
- package/src/elements/SwcAppEngine.ts +10 -3
- package/src/elements/SwcAppMixin.ts +177 -97
- package/src/elements/SwcAsync.ts +32 -21
- package/src/elements/SwcChoose.ts +74 -37
- package/src/elements/SwcIf.ts +60 -23
- package/src/elements/SwcLoop.ts +141 -28
- package/src/elements/register.ts +300 -102
- package/src/types.ts +6 -5
- package/src/utils/Utils.ts +40 -23
- package/tsconfig.json +2 -2
- package/dist/cjs/decorators/changedAttributeHost.js.map +0 -7
- package/dist/esm/decorators/changedAttributeHost.js.map +0 -7
- package/dist/types/decorators/changedAttributeHost.d.ts +0 -19
- package/dist/types/decorators/changedAttributeHost.d.ts.map +0 -1
|
@@ -133,22 +133,38 @@ const registerAllElements = (w) => {
|
|
|
133
133
|
(0, import_decorators.elementDefine)("swc-app", { window: w })
|
|
134
134
|
], SwcApp);
|
|
135
135
|
let SwcIf = class SwcIf extends HTMLTemplateElement {
|
|
136
|
-
constructor() {
|
|
137
|
-
super(...arguments);
|
|
138
|
-
this._nodes = [];
|
|
139
|
-
}
|
|
140
136
|
get value() {
|
|
141
137
|
return this._value;
|
|
142
138
|
}
|
|
143
139
|
set value(nv) {
|
|
144
140
|
this.refresh(nv);
|
|
145
141
|
}
|
|
142
|
+
constructor() {
|
|
143
|
+
super();
|
|
144
|
+
this._nodes = [];
|
|
145
|
+
}
|
|
146
|
+
setValue(value, o, n) {
|
|
147
|
+
this._value = value;
|
|
148
|
+
this.refresh(this._value);
|
|
149
|
+
}
|
|
150
|
+
// @changedAttributeThis('replace-wrap')
|
|
151
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
152
|
+
// this.refresh();
|
|
153
|
+
// }
|
|
146
154
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
147
|
-
|
|
155
|
+
let config = void 0;
|
|
156
|
+
if (wrap) {
|
|
157
|
+
config = {
|
|
158
|
+
expression: {
|
|
159
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
160
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
161
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
148
165
|
const ae = new import_core.ActionExpression(html, config);
|
|
149
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
150
166
|
const win = this.ownerDocument?.defaultView || window;
|
|
151
|
-
for (const expr of ae.getExpressions(
|
|
167
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
152
168
|
try {
|
|
153
169
|
const value = import_core.FunctionUtils.executeReturn({
|
|
154
170
|
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -162,30 +178,38 @@ const registerAllElements = (w) => {
|
|
|
162
178
|
}
|
|
163
179
|
return ae.getUnprocessedTemplate();
|
|
164
180
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
refresh(value = this._value) {
|
|
181
|
+
refresh(value) {
|
|
182
|
+
const targetValue = value !== void 0 ? value : (0, import_decorators.getAttributeValue)(this, "value") ?? this._value;
|
|
183
|
+
if (this.hasAttribute("skip-if-same") && this._value === targetValue && this._nodes.length > 0) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
172
186
|
this.cleanup();
|
|
187
|
+
this._value = targetValue;
|
|
173
188
|
const portal = this.parentElement;
|
|
174
|
-
if (!portal || !
|
|
189
|
+
if (!portal || !this._value)
|
|
175
190
|
return;
|
|
176
191
|
const win = this.ownerDocument?.defaultView || window;
|
|
177
192
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
178
193
|
let htmlString = this.innerHTML;
|
|
179
|
-
const groupArgs = { ...helperSet, $value:
|
|
180
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
194
|
+
const groupArgs = { ...helperSet, $value: this._value, $templateHost: this };
|
|
195
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
181
196
|
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
182
197
|
result.innerHTML = htmlString;
|
|
183
198
|
const processedFragment = result.content;
|
|
184
199
|
this._nodes = Array.from(processedFragment.childNodes);
|
|
200
|
+
this._nodes.forEach((node) => {
|
|
201
|
+
if (node instanceof HTMLElement)
|
|
202
|
+
node.__swc_template_host = this;
|
|
203
|
+
});
|
|
185
204
|
portal.insertBefore(processedFragment, this.nextSibling);
|
|
186
205
|
}
|
|
187
206
|
cleanup() {
|
|
188
|
-
this._nodes.forEach((n) =>
|
|
207
|
+
this._nodes.forEach((n) => {
|
|
208
|
+
const realNode = n.__upgraded_instance || n;
|
|
209
|
+
if (realNode.parentElement) {
|
|
210
|
+
realNode.parentElement.removeChild(realNode);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
189
213
|
this._nodes = [];
|
|
190
214
|
}
|
|
191
215
|
disconnectedCallback() {
|
|
@@ -193,54 +217,68 @@ const registerAllElements = (w) => {
|
|
|
193
217
|
}
|
|
194
218
|
};
|
|
195
219
|
__decorate([
|
|
196
|
-
(0, import_decorators.
|
|
197
|
-
__metadata("design:type",
|
|
198
|
-
], SwcIf.prototype, "
|
|
220
|
+
(0, import_decorators.attributeThis)("replace-wrap-start"),
|
|
221
|
+
__metadata("design:type", String)
|
|
222
|
+
], SwcIf.prototype, "_replaceWrapStart", void 0);
|
|
199
223
|
__decorate([
|
|
200
|
-
(0, import_decorators.
|
|
224
|
+
(0, import_decorators.attributeThis)("replace-wrap-end"),
|
|
201
225
|
__metadata("design:type", String)
|
|
202
|
-
], SwcIf.prototype, "
|
|
226
|
+
], SwcIf.prototype, "_replaceWrapEnd", void 0);
|
|
203
227
|
__decorate([
|
|
204
|
-
(0, import_decorators.
|
|
205
|
-
__metadata("design:type",
|
|
206
|
-
|
|
207
|
-
__metadata("design:returntype", void 0)
|
|
208
|
-
], SwcIf.prototype, "setValue", null);
|
|
228
|
+
(0, import_decorators.attributeThis)("skip-if-same"),
|
|
229
|
+
__metadata("design:type", String)
|
|
230
|
+
], SwcIf.prototype, "_skipIfSame", void 0);
|
|
209
231
|
__decorate([
|
|
210
|
-
(0, import_decorators.
|
|
232
|
+
(0, import_decorators.changedAttributeThis)("value"),
|
|
211
233
|
__metadata("design:type", Function),
|
|
212
|
-
__metadata("design:paramtypes", [String]),
|
|
234
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
213
235
|
__metadata("design:returntype", void 0)
|
|
214
|
-
], SwcIf.prototype, "
|
|
236
|
+
], SwcIf.prototype, "setValue", null);
|
|
215
237
|
SwcIf = __decorate([
|
|
216
|
-
(0, import_decorators.elementDefine)("swc-if", { extends: "template", window: w })
|
|
238
|
+
(0, import_decorators.elementDefine)("swc-if", { extends: "template", window: w }),
|
|
239
|
+
__metadata("design:paramtypes", [])
|
|
217
240
|
], SwcIf);
|
|
218
241
|
let SwcLoop = class SwcLoop extends HTMLTemplateElement {
|
|
219
|
-
constructor() {
|
|
220
|
-
super(...arguments);
|
|
221
|
-
this._nodeGroups = [];
|
|
222
|
-
}
|
|
223
242
|
get value() {
|
|
224
243
|
return this._value;
|
|
225
244
|
}
|
|
226
245
|
set value(nv) {
|
|
246
|
+
this._value = nv;
|
|
227
247
|
this.refresh(nv);
|
|
228
248
|
}
|
|
229
|
-
|
|
230
|
-
this.
|
|
249
|
+
getValue(index) {
|
|
250
|
+
return this._value?.[index];
|
|
251
|
+
}
|
|
252
|
+
constructor() {
|
|
253
|
+
super();
|
|
254
|
+
this._value = [];
|
|
255
|
+
this._nodeGroups = [];
|
|
231
256
|
}
|
|
232
|
-
|
|
233
|
-
this.
|
|
257
|
+
setValue(value, o, n) {
|
|
258
|
+
this._value = value;
|
|
259
|
+
this.refresh(this._value);
|
|
234
260
|
}
|
|
261
|
+
// @changedAttributeThis('replace-wrap')
|
|
262
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
263
|
+
// this.refresh();
|
|
264
|
+
// }
|
|
235
265
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
236
|
-
|
|
266
|
+
let config = void 0;
|
|
267
|
+
config = {
|
|
268
|
+
expression: {
|
|
269
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
270
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
271
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
272
|
+
}
|
|
273
|
+
};
|
|
237
274
|
const ae = new import_core.ActionExpression(html, config);
|
|
238
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
239
275
|
const win = this.ownerDocument?.defaultView || window;
|
|
240
|
-
|
|
276
|
+
const expressions = ae.getExpressions("replace");
|
|
277
|
+
for (const expr of expressions) {
|
|
278
|
+
const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
241
279
|
try {
|
|
242
280
|
const value = import_core.FunctionUtils.executeReturn({
|
|
243
|
-
script
|
|
281
|
+
script,
|
|
244
282
|
context,
|
|
245
283
|
args: groupArgs
|
|
246
284
|
});
|
|
@@ -251,30 +289,95 @@ const registerAllElements = (w) => {
|
|
|
251
289
|
}
|
|
252
290
|
return ae.getUnprocessedTemplate();
|
|
253
291
|
}
|
|
254
|
-
|
|
255
|
-
this.cleanup();
|
|
256
|
-
if (value?.length <= 0)
|
|
257
|
-
return;
|
|
258
|
-
const portal = this.parentElement;
|
|
259
|
-
if (!portal)
|
|
260
|
-
return;
|
|
292
|
+
createFragmentAndNodes(items, helperSet, startIndex = 0) {
|
|
261
293
|
const win = this.ownerDocument?.defaultView || window;
|
|
262
|
-
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
263
294
|
const fragment = win.document.createDocumentFragment();
|
|
264
|
-
|
|
295
|
+
const newNodesGroup = [];
|
|
296
|
+
items.forEach((item, i) => {
|
|
297
|
+
const index = startIndex + i;
|
|
265
298
|
let htmlString = this.innerHTML;
|
|
266
299
|
const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value };
|
|
267
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
300
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
268
301
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
269
302
|
temp.innerHTML = htmlString;
|
|
270
303
|
const content = temp.content;
|
|
271
304
|
const nodes = Array.from(content.childNodes);
|
|
272
|
-
|
|
305
|
+
const setTemplateHost = (element) => {
|
|
306
|
+
element.__swc_template_host = this;
|
|
307
|
+
Array.from(element.children).forEach((child) => {
|
|
308
|
+
if (child instanceof HTMLElement) {
|
|
309
|
+
setTemplateHost(child);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
nodes.forEach((node) => {
|
|
314
|
+
if (node instanceof HTMLElement) {
|
|
315
|
+
setTemplateHost(node);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
newNodesGroup.push(nodes);
|
|
273
319
|
fragment.appendChild(content);
|
|
274
320
|
});
|
|
321
|
+
return { fragment, newNodesGroup };
|
|
322
|
+
}
|
|
323
|
+
appendItem(...items) {
|
|
324
|
+
if (!items || items.length <= 0)
|
|
325
|
+
return;
|
|
326
|
+
const portal = import_Utils.SwcUtils.getParentContainer(this);
|
|
327
|
+
if (!portal)
|
|
328
|
+
return;
|
|
329
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
330
|
+
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
331
|
+
const startIndex = this._value ? this._value.length : 0;
|
|
332
|
+
if (this._value !== items) {
|
|
333
|
+
this._value = [...this._value || [], ...items];
|
|
334
|
+
}
|
|
335
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, startIndex);
|
|
336
|
+
this._nodeGroups.push(...newNodesGroup);
|
|
337
|
+
console.log("\uBB50\uC57C \uC528\uBC1C");
|
|
338
|
+
let insertReference = this.nextSibling;
|
|
339
|
+
if (this._nodeGroups.length > items.length) {
|
|
340
|
+
const lastExistingGroup = this._nodeGroups[this._nodeGroups.length - items.length - 1];
|
|
341
|
+
if (lastExistingGroup && lastExistingGroup.length > 0) {
|
|
342
|
+
const lastNode = lastExistingGroup[lastExistingGroup.length - 1];
|
|
343
|
+
insertReference = lastNode.nextSibling;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
portal.insertBefore(fragment, insertReference);
|
|
347
|
+
}
|
|
348
|
+
async prependItem(...items) {
|
|
349
|
+
if (!items || items.length <= 0)
|
|
350
|
+
return;
|
|
351
|
+
const portal = import_Utils.SwcUtils.getParentContainer(this);
|
|
352
|
+
if (!portal)
|
|
353
|
+
return;
|
|
354
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
355
|
+
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
356
|
+
if (this._value !== items) {
|
|
357
|
+
this._value = [...items, ...this._value || []];
|
|
358
|
+
}
|
|
359
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(items, helperSet, 0);
|
|
360
|
+
this._nodeGroups = [...newNodesGroup, ...this._nodeGroups];
|
|
275
361
|
portal.insertBefore(fragment, this.nextSibling);
|
|
276
362
|
}
|
|
363
|
+
refresh(value) {
|
|
364
|
+
const targetValue = value !== void 0 ? value : (0, import_decorators.getAttributeValue)(this, "value") ?? this._value ?? [];
|
|
365
|
+
this.cleanup();
|
|
366
|
+
this._value = targetValue;
|
|
367
|
+
if (!this._value || this._value.length <= 0)
|
|
368
|
+
return;
|
|
369
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
370
|
+
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
371
|
+
helperSet.$templateHost = this;
|
|
372
|
+
const { fragment, newNodesGroup } = this.createFragmentAndNodes(this._value, helperSet, 0);
|
|
373
|
+
this._nodeGroups = newNodesGroup;
|
|
374
|
+
const portal = import_Utils.SwcUtils.getParentContainer(this);
|
|
375
|
+
if (portal) {
|
|
376
|
+
portal.insertBefore(fragment, this.nextSibling);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
277
379
|
cleanup() {
|
|
380
|
+
console.log("\uB204\uAC00 cleanup");
|
|
278
381
|
this._nodeGroups.forEach((nodes) => nodes.forEach((n) => n.parentElement?.removeChild(n)));
|
|
279
382
|
this._nodeGroups = [];
|
|
280
383
|
}
|
|
@@ -283,27 +386,22 @@ const registerAllElements = (w) => {
|
|
|
283
386
|
}
|
|
284
387
|
};
|
|
285
388
|
__decorate([
|
|
286
|
-
(0, import_decorators.
|
|
287
|
-
__metadata("design:type",
|
|
288
|
-
], SwcLoop.prototype, "
|
|
389
|
+
(0, import_decorators.attributeThis)("replace-wrap-start"),
|
|
390
|
+
__metadata("design:type", String)
|
|
391
|
+
], SwcLoop.prototype, "_replaceWrapStart", void 0);
|
|
289
392
|
__decorate([
|
|
290
|
-
(0, import_decorators.
|
|
393
|
+
(0, import_decorators.attributeThis)("replace-wrap-end"),
|
|
291
394
|
__metadata("design:type", String)
|
|
292
|
-
], SwcLoop.prototype, "
|
|
395
|
+
], SwcLoop.prototype, "_replaceWrapEnd", void 0);
|
|
293
396
|
__decorate([
|
|
294
|
-
(0, import_decorators.
|
|
397
|
+
(0, import_decorators.changedAttributeThis)("value"),
|
|
295
398
|
__metadata("design:type", Function),
|
|
296
|
-
__metadata("design:paramtypes", []),
|
|
399
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
297
400
|
__metadata("design:returntype", void 0)
|
|
298
401
|
], SwcLoop.prototype, "setValue", null);
|
|
299
|
-
__decorate([
|
|
300
|
-
(0, import_decorators.changedAttributeHost)("replace-wrap"),
|
|
301
|
-
__metadata("design:type", Function),
|
|
302
|
-
__metadata("design:paramtypes", []),
|
|
303
|
-
__metadata("design:returntype", void 0)
|
|
304
|
-
], SwcLoop.prototype, "setReplaceWrap", null);
|
|
305
402
|
SwcLoop = __decorate([
|
|
306
|
-
(0, import_decorators.elementDefine)("swc-loop", { extends: "template", window: w })
|
|
403
|
+
(0, import_decorators.elementDefine)("swc-loop", { extends: "template", window: w }),
|
|
404
|
+
__metadata("design:paramtypes", [])
|
|
307
405
|
], SwcLoop);
|
|
308
406
|
let SwcChoose = class SwcChoose extends HTMLTemplateElement {
|
|
309
407
|
get value() {
|
|
@@ -324,18 +422,28 @@ const registerAllElements = (w) => {
|
|
|
324
422
|
attributeChangedCallback(na, o, n) {
|
|
325
423
|
}
|
|
326
424
|
setValue(value, o, n) {
|
|
425
|
+
console.log("chooooooose value", value);
|
|
327
426
|
this._value = value;
|
|
328
427
|
this.refresh(this._value);
|
|
329
428
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
429
|
+
// @changedAttributeThis('replace-wrap')
|
|
430
|
+
// private setReplaceWrap(replaceWrapAttr?: string | null) {
|
|
431
|
+
// this.refresh();
|
|
432
|
+
// }
|
|
333
433
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
334
|
-
|
|
434
|
+
let config = void 0;
|
|
435
|
+
if (wrap) {
|
|
436
|
+
config = {
|
|
437
|
+
expression: {
|
|
438
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
439
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
440
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
335
444
|
const ae = new import_core.ActionExpression(html, config);
|
|
336
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
337
445
|
const win = this.ownerDocument?.defaultView || window;
|
|
338
|
-
for (const expr of ae.getExpressions(
|
|
446
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
339
447
|
try {
|
|
340
448
|
const value = import_core.FunctionUtils.executeReturn({
|
|
341
449
|
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -351,31 +459,27 @@ const registerAllElements = (w) => {
|
|
|
351
459
|
}
|
|
352
460
|
refresh(value) {
|
|
353
461
|
value = (0, import_decorators.getAttributeValue)(this, "value") ?? this._value;
|
|
354
|
-
|
|
355
|
-
|
|
462
|
+
console.log("[DEBUG] SwcChoose.refresh called, value:", value);
|
|
463
|
+
const portal = import_Utils.SwcUtils.getParentContainer(this);
|
|
464
|
+
if (!portal) {
|
|
465
|
+
console.log("[DEBUG] SwcChoose portal is null!");
|
|
356
466
|
return;
|
|
467
|
+
}
|
|
357
468
|
const win = ((0, import_decorators.getElementConfig)(this).window ?? this.ownerDocument?.defaultView) || window;
|
|
358
469
|
const helperSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
|
|
359
|
-
const groupArgs = { ...helperSet, $value: value };
|
|
470
|
+
const groupArgs = { ...helperSet, $value: value, $templateHost: this };
|
|
360
471
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
361
472
|
let selected = null;
|
|
362
473
|
for (const t of templates) {
|
|
363
474
|
if (t.getAttribute("is") === "swc-when") {
|
|
364
|
-
const attrVal = t.getAttribute("
|
|
475
|
+
const attrVal = t.getAttribute("test") || "";
|
|
365
476
|
let matches = false;
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
context: t,
|
|
373
|
-
args: groupArgs
|
|
374
|
-
});
|
|
375
|
-
matches = !!result;
|
|
376
|
-
} else {
|
|
377
|
-
matches = String(attrVal) === String(value);
|
|
378
|
-
}
|
|
477
|
+
const result = import_core.FunctionUtils.executeReturn({
|
|
478
|
+
script: attrVal,
|
|
479
|
+
context: t,
|
|
480
|
+
args: groupArgs
|
|
481
|
+
});
|
|
482
|
+
matches = !!result;
|
|
379
483
|
if (matches) {
|
|
380
484
|
selected = t;
|
|
381
485
|
break;
|
|
@@ -394,12 +498,27 @@ const registerAllElements = (w) => {
|
|
|
394
498
|
this._previousTemplate = target;
|
|
395
499
|
if (target) {
|
|
396
500
|
let htmlString = target.innerHTML;
|
|
397
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
501
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
398
502
|
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
399
503
|
result.innerHTML = htmlString;
|
|
400
504
|
const processedFragment = result.content;
|
|
401
505
|
this._nodes = Array.from(processedFragment.childNodes);
|
|
506
|
+
const setTemplateHost = (element) => {
|
|
507
|
+
element.__swc_template_host = this;
|
|
508
|
+
Array.from(element.children).forEach((child) => {
|
|
509
|
+
if (child instanceof HTMLElement) {
|
|
510
|
+
setTemplateHost(child);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
this._nodes.forEach((node) => {
|
|
515
|
+
if (node instanceof HTMLElement) {
|
|
516
|
+
setTemplateHost(node);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
console.log(`[DEBUG] SwcChoose before insertBefore, portal: ${portal?.tagName}, isConnected: ${portal?.isConnected}`);
|
|
402
520
|
portal.insertBefore(processedFragment, this.nextSibling);
|
|
521
|
+
console.log("[DEBUG] SwcChoose after insertBefore");
|
|
403
522
|
}
|
|
404
523
|
}
|
|
405
524
|
cleanup() {
|
|
@@ -411,21 +530,19 @@ const registerAllElements = (w) => {
|
|
|
411
530
|
}
|
|
412
531
|
};
|
|
413
532
|
__decorate([
|
|
414
|
-
(0, import_decorators.
|
|
533
|
+
(0, import_decorators.attributeThis)("replace-wrap-start"),
|
|
415
534
|
__metadata("design:type", String)
|
|
416
|
-
], SwcChoose.prototype, "
|
|
535
|
+
], SwcChoose.prototype, "_replaceWrapStart", void 0);
|
|
417
536
|
__decorate([
|
|
418
|
-
(0, import_decorators.
|
|
537
|
+
(0, import_decorators.attributeThis)("replace-wrap-end"),
|
|
538
|
+
__metadata("design:type", String)
|
|
539
|
+
], SwcChoose.prototype, "_replaceWrapEnd", void 0);
|
|
540
|
+
__decorate([
|
|
541
|
+
(0, import_decorators.changedAttributeThis)("value"),
|
|
419
542
|
__metadata("design:type", Function),
|
|
420
543
|
__metadata("design:paramtypes", [Object, String, String]),
|
|
421
544
|
__metadata("design:returntype", void 0)
|
|
422
545
|
], SwcChoose.prototype, "setValue", null);
|
|
423
|
-
__decorate([
|
|
424
|
-
(0, import_decorators.changedAttributeHost)("replace-wrap"),
|
|
425
|
-
__metadata("design:type", Function),
|
|
426
|
-
__metadata("design:paramtypes", [String]),
|
|
427
|
-
__metadata("design:returntype", void 0)
|
|
428
|
-
], SwcChoose.prototype, "setReplaceWrap", null);
|
|
429
546
|
SwcChoose = __decorate([
|
|
430
547
|
(0, import_decorators.elementDefine)("swc-choose", { extends: "template", window: w }),
|
|
431
548
|
__metadata("design:paramtypes", [])
|
|
@@ -444,9 +561,10 @@ const registerAllElements = (w) => {
|
|
|
444
561
|
setValue(valueAttr) {
|
|
445
562
|
this.executeAsync(this._value);
|
|
446
563
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
564
|
+
// @changedAttributeThis('replace-wrap')
|
|
565
|
+
// private setReplaceWrap() {
|
|
566
|
+
// this.executeAsync(this._value);
|
|
567
|
+
// }
|
|
450
568
|
executeAsync(result = this._value) {
|
|
451
569
|
if (result === void 0 || result === null) {
|
|
452
570
|
this.refresh("default");
|
|
@@ -468,11 +586,19 @@ const registerAllElements = (w) => {
|
|
|
468
586
|
}
|
|
469
587
|
}
|
|
470
588
|
replaceExpressions(html, groupArgs, context, wrap) {
|
|
471
|
-
|
|
589
|
+
let config = void 0;
|
|
590
|
+
if (wrap) {
|
|
591
|
+
config = {
|
|
592
|
+
expression: {
|
|
593
|
+
replace: { start: `${wrap.start}`, end: `${wrap.end}` },
|
|
594
|
+
callReturn: { start: `${wrap.start}=`, end: `${wrap.end}` },
|
|
595
|
+
call: { start: `${wrap.start}@`, end: `${wrap.end}` }
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
472
599
|
const ae = new import_core.ActionExpression(html, config);
|
|
473
|
-
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
474
600
|
const win = this.ownerDocument?.defaultView || window;
|
|
475
|
-
for (const expr of ae.getExpressions(
|
|
601
|
+
for (const expr of ae.getExpressions("replace")) {
|
|
476
602
|
try {
|
|
477
603
|
const value = import_core.FunctionUtils.executeReturn({
|
|
478
604
|
script: import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
@@ -487,9 +613,8 @@ const registerAllElements = (w) => {
|
|
|
487
613
|
return ae.getUnprocessedTemplate();
|
|
488
614
|
}
|
|
489
615
|
refresh(state = "default") {
|
|
490
|
-
console.log("rrrrrrrrrrrrrrrrr", state);
|
|
491
616
|
this.cleanup();
|
|
492
|
-
const portal = this
|
|
617
|
+
const portal = import_Utils.SwcUtils.getParentContainer(this);
|
|
493
618
|
if (!portal)
|
|
494
619
|
return;
|
|
495
620
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -497,12 +622,16 @@ const registerAllElements = (w) => {
|
|
|
497
622
|
const t = this.content.querySelector(`template[is="swc-${state}"]`);
|
|
498
623
|
if (t) {
|
|
499
624
|
let htmlString = t.innerHTML;
|
|
500
|
-
const groupArgs = { ...helperSet, $value: this._value, $state: state };
|
|
501
|
-
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this.
|
|
625
|
+
const groupArgs = { ...helperSet, $value: this._value, $state: state, $templateHost: this };
|
|
626
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, { start: this._replaceWrapStart ?? "{#{", end: this._replaceWrapEnd ?? "}#}" });
|
|
502
627
|
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
503
628
|
temp.innerHTML = htmlString;
|
|
504
629
|
const content = temp.content;
|
|
505
630
|
this._nodes = Array.from(content.childNodes);
|
|
631
|
+
this._nodes.forEach((node) => {
|
|
632
|
+
if (node instanceof HTMLElement)
|
|
633
|
+
node.__template_swc_host = this;
|
|
634
|
+
});
|
|
506
635
|
portal.insertBefore(content, this.nextSibling);
|
|
507
636
|
}
|
|
508
637
|
}
|
|
@@ -515,25 +644,23 @@ const registerAllElements = (w) => {
|
|
|
515
644
|
}
|
|
516
645
|
};
|
|
517
646
|
__decorate([
|
|
518
|
-
(0, import_decorators.
|
|
647
|
+
(0, import_decorators.attributeThis)("value"),
|
|
519
648
|
__metadata("design:type", Object)
|
|
520
649
|
], SwcAsync.prototype, "_value", void 0);
|
|
521
650
|
__decorate([
|
|
522
|
-
(0, import_decorators.
|
|
651
|
+
(0, import_decorators.attributeThis)("replace-wrap-start"),
|
|
652
|
+
__metadata("design:type", String)
|
|
653
|
+
], SwcAsync.prototype, "_replaceWrapStart", void 0);
|
|
654
|
+
__decorate([
|
|
655
|
+
(0, import_decorators.attributeThis)("replace-wrap-end"),
|
|
523
656
|
__metadata("design:type", String)
|
|
524
|
-
], SwcAsync.prototype, "
|
|
657
|
+
], SwcAsync.prototype, "_replaceWrapEnd", void 0);
|
|
525
658
|
__decorate([
|
|
526
|
-
(0, import_decorators.
|
|
659
|
+
(0, import_decorators.changedAttributeThis)("value"),
|
|
527
660
|
__metadata("design:type", Function),
|
|
528
661
|
__metadata("design:paramtypes", [String]),
|
|
529
662
|
__metadata("design:returntype", void 0)
|
|
530
663
|
], SwcAsync.prototype, "setValue", null);
|
|
531
|
-
__decorate([
|
|
532
|
-
(0, import_decorators.changedAttributeHost)("replace-wrap"),
|
|
533
|
-
__metadata("design:type", Function),
|
|
534
|
-
__metadata("design:paramtypes", []),
|
|
535
|
-
__metadata("design:returntype", void 0)
|
|
536
|
-
], SwcAsync.prototype, "setReplaceWrap", null);
|
|
537
664
|
SwcAsync = __decorate([
|
|
538
665
|
(0, import_decorators.elementDefine)("swc-async", { extends: "template", window: w })
|
|
539
666
|
], SwcAsync);
|