feat: support inspector on ws swapped elems
This commit is contained in:
parent
df42cd8a8b
commit
ee0b9e597a
1 changed files with 24 additions and 4 deletions
28
index.js
28
index.js
|
|
@ -304,13 +304,33 @@ function bootstrapTemplateWithHTMXetc(
|
||||||
htmlString = $.html();
|
htmlString = $.html();
|
||||||
} else if (htmxRequest && blissRoute) {
|
} else if (htmxRequest && blissRoute) {
|
||||||
const $ = cheerio.load(htmlString, null, false);
|
const $ = cheerio.load(htmlString, null, false);
|
||||||
$.root().children().attr("data-bliss-route", blissRoute);
|
const targets = [];
|
||||||
$.root().children().attr("data-bliss-clone", blissClone);
|
|
||||||
if (blissCopy) $.root().children().attr("data-bliss-copy", blissCopy);
|
// when we return an oob thing from htmx, we'll lose all the attrs when it swaps
|
||||||
|
// so this adds those attrs to the children of the swap if possible
|
||||||
|
for (let child of $.root().children()) {
|
||||||
|
if (child.attribs && child.attribs["hx-swap-oob"]) {
|
||||||
|
for (let childchild of child.children) {
|
||||||
|
if (childchild.attribs) {
|
||||||
|
targets.push(childchild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
targets.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Directly update attributes without wrapping in Cheerio
|
||||||
|
for (let target of targets) {
|
||||||
|
target.attribs["data-bliss-route"] = blissRoute;
|
||||||
|
target.attribs["data-bliss-clone"] = blissClone;
|
||||||
|
if (blissCopy) target.attribs["data-bliss-copy"] = blissCopy;
|
||||||
|
}
|
||||||
|
|
||||||
htmlString = $.html();
|
htmlString = $.html();
|
||||||
|
|
||||||
if (htmxRequest) {
|
if (htmxRequest) {
|
||||||
htmlString += `<div id="head" hx-oob-swap="before_end">${headInjection}</div>`;
|
htmlString += `<head id="head" hx-oob-swap="beforeend">${headInjection}</head>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue