@yannosay/sinth 0.7.0 → 0.7.1
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/package.json +1 -1
- package/src/sinth.ts +19 -1
package/package.json
CHANGED
package/src/sinth.ts
CHANGED
|
@@ -2311,8 +2311,18 @@ depth: number,
|
|
|
2311
2311
|
const condId = registerExpr(ctx, ifBlock.condition);
|
|
2312
2312
|
const bodyHTML = ifBlock.body.map(c => renderChild(c, ctx, params, depth + 1)).join("");
|
|
2313
2313
|
const elseHTML = (ifBlock.elseBody ?? []).map(c => renderChild(c, ctx, params, depth + 1)).join("");
|
|
2314
|
+
let replaceAttr = "";
|
|
2315
|
+
const firstComp = ifBlock.body.find(c => c.kind === "use") as CompUse | undefined;
|
|
2316
|
+
if (firstComp) {
|
|
2317
|
+
const idAttr = firstComp.attrs.find(a => a.name === "id");
|
|
2318
|
+
const replAttr = firstComp.attrs.find(a => a.name === "replace");
|
|
2319
|
+
const wantsReplace = !replAttr || replAttr.value === null || (replAttr.value?.kind === "bool" && replAttr.value.value === true);
|
|
2320
|
+
if (idAttr && idAttr.value?.kind === "str" && wantsReplace) {
|
|
2321
|
+
replaceAttr = ` data-sinth-if-replace="${escAttr(idAttr.value.value)}"`;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2314
2324
|
return (
|
|
2315
|
-
`<template data-sinth-if-id="${tplId}" data-sinth-if-expr="${condId}">${bodyHTML}</template>` +
|
|
2325
|
+
`<template data-sinth-if-id="${tplId}" data-sinth-if-expr="${condId}"${replaceAttr}>${bodyHTML}</template>` +
|
|
2316
2326
|
(elseHTML ? `<template data-sinth-else data-sinth-if-id="${tplId}">${elseHTML}</template>` : "")
|
|
2317
2327
|
);
|
|
2318
2328
|
}
|
|
@@ -2746,6 +2756,10 @@ return `var ${v.name} = ${val};`;
|
|
|
2746
2756
|
|
|
2747
2757
|
_loopIdx++;
|
|
2748
2758
|
var _user = _v;
|
|
2759
|
+
if (t.dataset.sinthIfReplace) {
|
|
2760
|
+
var _rp = document.getElementById(t.dataset.sinthIfReplace);
|
|
2761
|
+
if (_rp) _rp.parentNode.removeChild(_rp);
|
|
2762
|
+
}
|
|
2749
2763
|
var frag = document.createRange().createContextualFragment(t.innerHTML);
|
|
2750
2764
|
frag.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
2751
2765
|
try {
|
|
@@ -2826,6 +2840,10 @@ return `var ${v.name} = ${val};`;
|
|
|
2826
2840
|
var condFn = __X[t.dataset.sinthIfExpr];
|
|
2827
2841
|
var cond = condFn ? condFn() : false;
|
|
2828
2842
|
if (cond) {
|
|
2843
|
+
if (t.dataset.sinthIfReplace) {
|
|
2844
|
+
var _rp = document.getElementById(t.dataset.sinthIfReplace);
|
|
2845
|
+
if (_rp) _rp.parentNode.removeChild(_rp);
|
|
2846
|
+
}
|
|
2829
2847
|
if (anchor) {
|
|
2830
2848
|
var cur = anchor.nextSibling;
|
|
2831
2849
|
while (cur && cur !== t) { var nx = cur.nextSibling; cur.remove(); cur = nx; }
|