@dooboostore/simple-web-component 1.0.29 → 1.0.31
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 +651 -27
- package/dist/cjs/decorators/elementDefine.js +5 -3
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +1 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/setProperty.js +97 -0
- package/dist/cjs/decorators/setProperty.js.map +7 -0
- package/dist/cjs/elements/SwcAppEngine.js +3 -3
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +1 -8
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +37 -53
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +55 -60
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +31 -60
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +20 -43
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/SwcSubTemplates.js +0 -27
- package/dist/cjs/elements/SwcSubTemplates.js.map +2 -2
- package/dist/cjs/elements/register.js +216 -128
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +1 -8
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +26 -10
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +5 -3
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/setProperty.js +78 -0
- package/dist/esm/decorators/setProperty.js.map +7 -0
- package/dist/esm/elements/SwcAppEngine.js +3 -3
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +1 -8
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +37 -34
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +55 -41
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +31 -41
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +20 -24
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/SwcSubTemplates.js +0 -8
- package/dist/esm/elements/SwcSubTemplates.js.map +2 -2
- package/dist/esm/elements/register.js +216 -128
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +1 -8
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +26 -10
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +105 -13
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +1 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/setProperty.d.ts +13 -0
- package/dist/types/decorators/setProperty.d.ts.map +1 -0
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +1 -11
- package/dist/types/elements/SwcAsync.d.ts.map +1 -1
- package/dist/types/elements/SwcChoose.d.ts +1 -13
- package/dist/types/elements/SwcChoose.d.ts.map +1 -1
- package/dist/types/elements/SwcIf.d.ts +1 -13
- package/dist/types/elements/SwcIf.d.ts.map +1 -1
- package/dist/types/elements/SwcLoop.d.ts +1 -13
- package/dist/types/elements/SwcLoop.d.ts.map +1 -1
- package/dist/types/elements/SwcSubTemplates.d.ts +6 -6
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts +3 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +10 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +105 -13
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/elementDefine.ts +10 -3
- package/src/decorators/emitCustomEvent.ts +1 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/setProperty.ts +97 -0
- package/src/elements/SwcAppEngine.ts +3 -3
- package/src/elements/SwcAppMixin.ts +7 -28
- package/src/elements/SwcAsync.ts +46 -30
- package/src/elements/SwcChoose.ts +82 -38
- package/src/elements/SwcIf.ts +38 -38
- package/src/elements/SwcLoop.ts +24 -19
- package/src/elements/SwcSubTemplates.ts +6 -6
- package/src/elements/register.ts +261 -121
- package/src/index.ts +3 -1
- package/src/router/ElementRouter.ts +1 -12
- package/src/types.ts +3 -1
- package/src/utils/Utils.ts +40 -19
|
@@ -123,49 +123,34 @@ const registerAllElements = (w) => {
|
|
|
123
123
|
this._value = Boolean(nv);
|
|
124
124
|
this.render();
|
|
125
125
|
}
|
|
126
|
-
_resolvePortal() {
|
|
127
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
128
|
-
if (!portalScript)
|
|
129
|
-
return this.parentElement;
|
|
130
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
131
|
-
const res = FunctionUtils.executeReturn({
|
|
132
|
-
script: portalScript,
|
|
133
|
-
context: this,
|
|
134
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
135
|
-
});
|
|
136
|
-
if (res instanceof HTMLElement)
|
|
137
|
-
return res;
|
|
138
|
-
if (typeof res === "string")
|
|
139
|
-
return win.document.querySelector(res);
|
|
140
|
-
return this.parentElement;
|
|
141
|
-
}
|
|
142
126
|
_executeCloneCallback(attr, args) {
|
|
143
127
|
const script = this.getAttribute(attr);
|
|
144
128
|
if (!script)
|
|
145
129
|
return;
|
|
146
130
|
FunctionUtils.execute({ script, context: this, args });
|
|
147
131
|
}
|
|
148
|
-
refreshValue() {
|
|
149
|
-
|
|
150
|
-
if (
|
|
132
|
+
refreshValue(valueAttr) {
|
|
133
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
134
|
+
if (valueAttr === null) {
|
|
151
135
|
this.value = false;
|
|
152
136
|
return;
|
|
153
137
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
138
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
139
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
140
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
141
|
+
const result = FunctionUtils.executeReturn({
|
|
142
|
+
script,
|
|
143
|
+
context: this,
|
|
144
|
+
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
145
|
+
});
|
|
146
|
+
this.value = result;
|
|
162
147
|
} else {
|
|
163
|
-
this.value =
|
|
148
|
+
this.value = Boolean(valueAttr);
|
|
164
149
|
}
|
|
165
150
|
}
|
|
166
151
|
render() {
|
|
167
152
|
this.cleanup();
|
|
168
|
-
const portal = this.
|
|
153
|
+
const portal = this.parentElement;
|
|
169
154
|
if (!portal)
|
|
170
155
|
return;
|
|
171
156
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -185,16 +170,24 @@ const registerAllElements = (w) => {
|
|
|
185
170
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
186
171
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
187
172
|
this._nodes.forEach((node, nodeIdx) => {
|
|
188
|
-
if (node instanceof HTMLElement)
|
|
189
|
-
node.__swc_host = this;
|
|
190
173
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: node, $nodeIndex: nodeIdx, $isElement: node.nodeType === 1 });
|
|
174
|
+
if (node instanceof HTMLElement) {
|
|
175
|
+
Array.from(node.attributes).forEach((attr) => {
|
|
176
|
+
const value = attr.value || "";
|
|
177
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
178
|
+
const script = value.slice(2, -2).trim();
|
|
179
|
+
const result = FunctionUtils.executeReturn({
|
|
180
|
+
script,
|
|
181
|
+
context: node,
|
|
182
|
+
args: { ...groupArgs, $value: this._value }
|
|
183
|
+
});
|
|
184
|
+
node.setAttribute(attr.name, String(result));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
191
188
|
});
|
|
192
189
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
193
|
-
|
|
194
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
195
|
-
} else {
|
|
196
|
-
portal.appendChild(clone);
|
|
197
|
-
}
|
|
190
|
+
portal.insertBefore(clone, this.nextSibling);
|
|
198
191
|
}
|
|
199
192
|
}
|
|
200
193
|
cleanup() {
|
|
@@ -209,9 +202,9 @@ const registerAllElements = (w) => {
|
|
|
209
202
|
}
|
|
210
203
|
};
|
|
211
204
|
__decorate([
|
|
212
|
-
changedAttributeHost("
|
|
205
|
+
changedAttributeHost("value"),
|
|
213
206
|
__metadata("design:type", Function),
|
|
214
|
-
__metadata("design:paramtypes", []),
|
|
207
|
+
__metadata("design:paramtypes", [String]),
|
|
215
208
|
__metadata("design:returntype", void 0)
|
|
216
209
|
], SwcIf.prototype, "refreshValue", null);
|
|
217
210
|
SwcIf = __decorate([
|
|
@@ -230,22 +223,6 @@ const registerAllElements = (w) => {
|
|
|
230
223
|
this._value = Array.isArray(nv) ? [...nv] : [];
|
|
231
224
|
this.render();
|
|
232
225
|
}
|
|
233
|
-
_resolvePortal() {
|
|
234
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
235
|
-
if (!portalScript)
|
|
236
|
-
return this.parentElement;
|
|
237
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
238
|
-
const res = FunctionUtils.executeReturn({
|
|
239
|
-
script: portalScript,
|
|
240
|
-
context: this,
|
|
241
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
242
|
-
});
|
|
243
|
-
if (res instanceof HTMLElement)
|
|
244
|
-
return res;
|
|
245
|
-
if (typeof res === "string")
|
|
246
|
-
return win.document.querySelector(res);
|
|
247
|
-
return this.parentElement;
|
|
248
|
-
}
|
|
249
226
|
_executeCloneCallback(attr, args) {
|
|
250
227
|
const script = this.getAttribute(attr);
|
|
251
228
|
if (!script)
|
|
@@ -257,11 +234,14 @@ const registerAllElements = (w) => {
|
|
|
257
234
|
this._nodeGroups = [];
|
|
258
235
|
}
|
|
259
236
|
refreshValue() {
|
|
260
|
-
|
|
237
|
+
let script = this.getAttribute("value");
|
|
261
238
|
if (!script) {
|
|
262
239
|
this.value = [];
|
|
263
240
|
return;
|
|
264
241
|
}
|
|
242
|
+
if (script.startsWith("{{") && script.endsWith("}}")) {
|
|
243
|
+
script = script.slice(2, -2).trim();
|
|
244
|
+
}
|
|
265
245
|
const win = this.ownerDocument?.defaultView || window;
|
|
266
246
|
const res = FunctionUtils.executeReturn({
|
|
267
247
|
script,
|
|
@@ -276,7 +256,7 @@ const registerAllElements = (w) => {
|
|
|
276
256
|
}
|
|
277
257
|
render() {
|
|
278
258
|
this._cleanup();
|
|
279
|
-
const portal = this.
|
|
259
|
+
const portal = this.parentElement;
|
|
280
260
|
if (!portal)
|
|
281
261
|
return;
|
|
282
262
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -299,9 +279,21 @@ const registerAllElements = (w) => {
|
|
|
299
279
|
const elements = nodes.filter((n) => n.nodeType === 1);
|
|
300
280
|
const groupArgs = { ...helperSet, $item: item, $index: index, $value: this._value, $nodes: nodes, $elements: elements, $firstElement: elements[0] };
|
|
301
281
|
nodes.forEach((node, nodeIdx) => {
|
|
302
|
-
if (node instanceof HTMLElement)
|
|
303
|
-
node.__swc_host = this;
|
|
304
282
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: node, $nodeIndex: nodeIdx, $isElement: node.nodeType === 1 });
|
|
283
|
+
if (node instanceof HTMLElement) {
|
|
284
|
+
Array.from(node.attributes).forEach((attr) => {
|
|
285
|
+
const value = attr.value || "";
|
|
286
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
287
|
+
const script = value.slice(2, -2).trim();
|
|
288
|
+
const result = FunctionUtils.executeReturn({
|
|
289
|
+
script,
|
|
290
|
+
context: node,
|
|
291
|
+
args: groupArgs
|
|
292
|
+
});
|
|
293
|
+
node.setAttribute(attr.name, String(result));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
305
297
|
});
|
|
306
298
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
307
299
|
this._nodeGroups.push(nodes);
|
|
@@ -322,7 +314,7 @@ const registerAllElements = (w) => {
|
|
|
322
314
|
}
|
|
323
315
|
};
|
|
324
316
|
__decorate([
|
|
325
|
-
changedAttributeHost("
|
|
317
|
+
changedAttributeHost("value"),
|
|
326
318
|
__metadata("design:type", Function),
|
|
327
319
|
__metadata("design:paramtypes", []),
|
|
328
320
|
__metadata("design:returntype", void 0)
|
|
@@ -335,6 +327,7 @@ const registerAllElements = (w) => {
|
|
|
335
327
|
super(...arguments);
|
|
336
328
|
this._nodes = [];
|
|
337
329
|
this._value = null;
|
|
330
|
+
this._previousTemplate = null;
|
|
338
331
|
}
|
|
339
332
|
get value() {
|
|
340
333
|
return this._value;
|
|
@@ -343,70 +336,86 @@ const registerAllElements = (w) => {
|
|
|
343
336
|
this._value = nv;
|
|
344
337
|
this.render();
|
|
345
338
|
}
|
|
346
|
-
_resolvePortal() {
|
|
347
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
348
|
-
if (!portalScript)
|
|
349
|
-
return this.parentElement;
|
|
350
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
351
|
-
const res = FunctionUtils.executeReturn({
|
|
352
|
-
script: portalScript,
|
|
353
|
-
context: this,
|
|
354
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
355
|
-
});
|
|
356
|
-
if (res instanceof HTMLElement)
|
|
357
|
-
return res;
|
|
358
|
-
if (typeof res === "string")
|
|
359
|
-
return win.document.querySelector(res);
|
|
360
|
-
return this.parentElement;
|
|
361
|
-
}
|
|
362
339
|
_executeCloneCallback(attr, args) {
|
|
363
340
|
const script = this.getAttribute(attr);
|
|
364
341
|
if (!script)
|
|
365
342
|
return;
|
|
366
343
|
FunctionUtils.execute({ script, context: this, args });
|
|
367
344
|
}
|
|
368
|
-
refresh() {
|
|
369
|
-
|
|
370
|
-
if (
|
|
345
|
+
refresh(valueAttr) {
|
|
346
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
347
|
+
if (valueAttr === null) {
|
|
371
348
|
this.value = null;
|
|
372
349
|
return;
|
|
373
350
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
351
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
352
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
353
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
354
|
+
const helperAndHostSet = SwcUtils.getHelperAndHostSet(win, SwcUtils.findNearestSwcHost(this));
|
|
355
|
+
const result = FunctionUtils.executeReturn({ script, context: this, args: helperAndHostSet });
|
|
356
|
+
this.value = result;
|
|
357
|
+
} else {
|
|
358
|
+
this.value = valueAttr;
|
|
359
|
+
}
|
|
377
360
|
}
|
|
378
361
|
render() {
|
|
379
|
-
this.cleanup();
|
|
380
|
-
const portal = this._resolvePortal();
|
|
381
|
-
if (!portal)
|
|
382
|
-
return;
|
|
383
362
|
const win = this.ownerDocument?.defaultView || window;
|
|
384
363
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
385
364
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
386
365
|
let selected = null;
|
|
387
366
|
for (const t of templates) {
|
|
388
|
-
if (t.getAttribute("is") === "swc-when"
|
|
389
|
-
|
|
390
|
-
|
|
367
|
+
if (t.getAttribute("is") === "swc-when") {
|
|
368
|
+
let matches = false;
|
|
369
|
+
const value = t.getAttribute("value") || "";
|
|
370
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
371
|
+
const script = value.slice(2, -2).trim();
|
|
372
|
+
const result = FunctionUtils.executeReturn({
|
|
373
|
+
script,
|
|
374
|
+
context: t,
|
|
375
|
+
args: { ...helperSet, $value: this._value }
|
|
376
|
+
});
|
|
377
|
+
matches = result === true;
|
|
378
|
+
} else {
|
|
379
|
+
matches = String(value) === String(this._value);
|
|
380
|
+
}
|
|
381
|
+
if (matches) {
|
|
382
|
+
selected = t;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
391
385
|
}
|
|
392
386
|
}
|
|
393
387
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
388
|
+
const targetHasSkipIfSame = target?.hasAttribute("skip-if-same");
|
|
389
|
+
const shouldSkip = (this.hasAttribute("skip-if-same") || targetHasSkipIfSame) && this._previousTemplate === target;
|
|
390
|
+
if (shouldSkip) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.cleanup();
|
|
394
|
+
this._previousTemplate = target;
|
|
394
395
|
if (target) {
|
|
395
396
|
const clone = target.content.cloneNode(true);
|
|
396
397
|
this._nodes = Array.from(clone.childNodes);
|
|
397
398
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
398
399
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0] };
|
|
399
400
|
this._nodes.forEach((n, nodeIdx) => {
|
|
400
|
-
if (n instanceof HTMLElement)
|
|
401
|
-
n.__swc_host = this;
|
|
402
401
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
402
|
+
if (n instanceof HTMLElement) {
|
|
403
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
404
|
+
const value = attr.value || "";
|
|
405
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
406
|
+
const script = value.slice(2, -2).trim();
|
|
407
|
+
const result = FunctionUtils.executeReturn({
|
|
408
|
+
script,
|
|
409
|
+
context: n,
|
|
410
|
+
args: { ...groupArgs, $value: this._value }
|
|
411
|
+
});
|
|
412
|
+
n.setAttribute(attr.name, String(result));
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
403
416
|
});
|
|
404
417
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
405
|
-
|
|
406
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
407
|
-
} else {
|
|
408
|
-
portal.appendChild(clone);
|
|
409
|
-
}
|
|
418
|
+
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
410
419
|
}
|
|
411
420
|
}
|
|
412
421
|
cleanup() {
|
|
@@ -421,9 +430,9 @@ const registerAllElements = (w) => {
|
|
|
421
430
|
}
|
|
422
431
|
};
|
|
423
432
|
__decorate([
|
|
424
|
-
changedAttributeHost("
|
|
433
|
+
changedAttributeHost("value"),
|
|
425
434
|
__metadata("design:type", Function),
|
|
426
|
-
__metadata("design:paramtypes", []),
|
|
435
|
+
__metadata("design:paramtypes", [String]),
|
|
427
436
|
__metadata("design:returntype", void 0)
|
|
428
437
|
], SwcChoose.prototype, "refresh", null);
|
|
429
438
|
SwcChoose = __decorate([
|
|
@@ -435,34 +444,32 @@ const registerAllElements = (w) => {
|
|
|
435
444
|
this._nodes = [];
|
|
436
445
|
this._value = null;
|
|
437
446
|
}
|
|
438
|
-
_resolvePortal() {
|
|
439
|
-
const portalScript = this.getAttribute("on-get-portal");
|
|
440
|
-
if (!portalScript)
|
|
441
|
-
return this.parentElement;
|
|
442
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
443
|
-
const res = FunctionUtils.executeReturn({
|
|
444
|
-
script: portalScript,
|
|
445
|
-
context: this,
|
|
446
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
447
|
-
});
|
|
448
|
-
if (res instanceof HTMLElement)
|
|
449
|
-
return res;
|
|
450
|
-
if (typeof res === "string")
|
|
451
|
-
return win.document.querySelector(res);
|
|
452
|
-
return this.parentElement;
|
|
453
|
-
}
|
|
454
447
|
_executeCloneCallback(attr, args) {
|
|
455
448
|
const script = this.getAttribute(attr);
|
|
456
449
|
if (!script)
|
|
457
450
|
return;
|
|
458
451
|
FunctionUtils.execute({ script, context: this, args });
|
|
459
452
|
}
|
|
460
|
-
refresh() {
|
|
461
|
-
|
|
462
|
-
if (!
|
|
453
|
+
refresh(valueAttr) {
|
|
454
|
+
valueAttr ?? (valueAttr = this.getAttribute("value"));
|
|
455
|
+
if (!valueAttr) {
|
|
456
|
+
this.render("default");
|
|
463
457
|
return;
|
|
464
|
-
|
|
465
|
-
|
|
458
|
+
}
|
|
459
|
+
if (valueAttr.startsWith("{{") && valueAttr.endsWith("}}")) {
|
|
460
|
+
const script = valueAttr.slice(2, -2).trim();
|
|
461
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
462
|
+
const result = FunctionUtils.executeReturn({
|
|
463
|
+
script,
|
|
464
|
+
context: this,
|
|
465
|
+
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
466
|
+
});
|
|
467
|
+
this.executeAsync(result);
|
|
468
|
+
} else {
|
|
469
|
+
this.executeAsync(valueAttr);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
executeAsync(result) {
|
|
466
473
|
if (result instanceof Promise) {
|
|
467
474
|
this.render("loading");
|
|
468
475
|
result.then((v) => {
|
|
@@ -476,7 +483,7 @@ const registerAllElements = (w) => {
|
|
|
476
483
|
}
|
|
477
484
|
render(state) {
|
|
478
485
|
this.cleanup();
|
|
479
|
-
const portal = this.
|
|
486
|
+
const portal = this.parentElement;
|
|
480
487
|
if (!portal)
|
|
481
488
|
return;
|
|
482
489
|
const win = this.ownerDocument?.defaultView || window;
|
|
@@ -488,16 +495,24 @@ const registerAllElements = (w) => {
|
|
|
488
495
|
const elements = this._nodes.filter((n) => n.nodeType === 1);
|
|
489
496
|
const groupArgs = { ...helperSet, $value: this._value, $nodes: this._nodes, $elements: elements, $firstElement: elements[0], $state: state };
|
|
490
497
|
this._nodes.forEach((n, nodeIdx) => {
|
|
491
|
-
if (n instanceof HTMLElement)
|
|
492
|
-
n.__swc_host = this;
|
|
493
498
|
this._executeCloneCallback("on-clone-node", { ...groupArgs, $node: n, $nodeIndex: nodeIdx, $isElement: n.nodeType === 1 });
|
|
499
|
+
if (n instanceof HTMLElement) {
|
|
500
|
+
Array.from(n.attributes).forEach((attr) => {
|
|
501
|
+
const value = attr.value || "";
|
|
502
|
+
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
503
|
+
const script = value.slice(2, -2).trim();
|
|
504
|
+
const result = FunctionUtils.executeReturn({
|
|
505
|
+
script,
|
|
506
|
+
context: n,
|
|
507
|
+
args: groupArgs
|
|
508
|
+
});
|
|
509
|
+
n.setAttribute(attr.name, String(result));
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
494
513
|
});
|
|
495
514
|
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
496
|
-
|
|
497
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
498
|
-
} else {
|
|
499
|
-
portal.appendChild(clone);
|
|
500
|
-
}
|
|
515
|
+
portal.insertBefore(clone, this.nextSibling);
|
|
501
516
|
}
|
|
502
517
|
}
|
|
503
518
|
cleanup() {
|
|
@@ -512,9 +527,9 @@ const registerAllElements = (w) => {
|
|
|
512
527
|
}
|
|
513
528
|
};
|
|
514
529
|
__decorate([
|
|
515
|
-
changedAttributeHost("
|
|
530
|
+
changedAttributeHost("value"),
|
|
516
531
|
__metadata("design:type", Function),
|
|
517
|
-
__metadata("design:paramtypes", []),
|
|
532
|
+
__metadata("design:paramtypes", [String]),
|
|
518
533
|
__metadata("design:returntype", void 0)
|
|
519
534
|
], SwcAsync.prototype, "refresh", null);
|
|
520
535
|
SwcAsync = __decorate([
|
|
@@ -805,6 +820,79 @@ const registerAllElements = (w) => {
|
|
|
805
820
|
SwcAppBody = __decorate([
|
|
806
821
|
elementDefine("swc-app-body", { extends: "body", window: w })
|
|
807
822
|
], SwcAppBody);
|
|
823
|
+
return {
|
|
824
|
+
// Sub Templates
|
|
825
|
+
SwcLoading,
|
|
826
|
+
SwcError,
|
|
827
|
+
SwcSuccess,
|
|
828
|
+
SwcWhen,
|
|
829
|
+
SwcOtherwise,
|
|
830
|
+
SwcDefault,
|
|
831
|
+
// Core Elements
|
|
832
|
+
SwcApp,
|
|
833
|
+
SwcIf,
|
|
834
|
+
SwcLoop,
|
|
835
|
+
SwcChoose,
|
|
836
|
+
SwcAsync,
|
|
837
|
+
// App Elements
|
|
838
|
+
SwcAppAnchor,
|
|
839
|
+
SwcAppArea,
|
|
840
|
+
SwcAppAudio,
|
|
841
|
+
SwcAppBase,
|
|
842
|
+
SwcAppButton,
|
|
843
|
+
SwcAppCanvas,
|
|
844
|
+
SwcAppData,
|
|
845
|
+
SwcAppDataList,
|
|
846
|
+
SwcAppDetails,
|
|
847
|
+
SwcAppDialog,
|
|
848
|
+
SwcAppDiv,
|
|
849
|
+
SwcAppDList,
|
|
850
|
+
SwcAppEmbed,
|
|
851
|
+
SwcAppFieldSet,
|
|
852
|
+
SwcAppForm,
|
|
853
|
+
SwcAppHR,
|
|
854
|
+
SwcAppIFrame,
|
|
855
|
+
SwcAppImage,
|
|
856
|
+
SwcAppInput,
|
|
857
|
+
SwcAppLabel,
|
|
858
|
+
SwcAppLegend,
|
|
859
|
+
SwcAppLI,
|
|
860
|
+
SwcAppLink,
|
|
861
|
+
SwcAppMap,
|
|
862
|
+
SwcAppMeta,
|
|
863
|
+
SwcAppMeter,
|
|
864
|
+
SwcAppMod,
|
|
865
|
+
SwcAppObject,
|
|
866
|
+
SwcAppOList,
|
|
867
|
+
SwcAppOptGroup,
|
|
868
|
+
SwcAppOption,
|
|
869
|
+
SwcAppOutput,
|
|
870
|
+
SwcAppParagraph,
|
|
871
|
+
SwcAppParam,
|
|
872
|
+
SwcAppPicture,
|
|
873
|
+
SwcAppPre,
|
|
874
|
+
SwcAppProgress,
|
|
875
|
+
SwcAppQuote,
|
|
876
|
+
SwcAppScript,
|
|
877
|
+
SwcAppSelect,
|
|
878
|
+
SwcAppSlot,
|
|
879
|
+
SwcAppSource,
|
|
880
|
+
SwcAppSpan,
|
|
881
|
+
SwcAppStyle,
|
|
882
|
+
SwcAppTable,
|
|
883
|
+
SwcAppTableSection,
|
|
884
|
+
SwcAppTableCell,
|
|
885
|
+
SwcAppTemplate,
|
|
886
|
+
SwcAppTextArea,
|
|
887
|
+
SwcAppTime,
|
|
888
|
+
SwcAppTitle,
|
|
889
|
+
SwcAppTableRow,
|
|
890
|
+
SwcAppTrack,
|
|
891
|
+
SwcAppUList,
|
|
892
|
+
SwcAppVideo,
|
|
893
|
+
SwcAppHeading,
|
|
894
|
+
SwcAppBody
|
|
895
|
+
};
|
|
808
896
|
};
|
|
809
897
|
export {
|
|
810
898
|
registerAllElements
|