feat: support inspector on ws swapped elems

This commit is contained in:
Your Name 2025-01-20 12:53:52 -05:00
parent df42cd8a8b
commit ee0b9e597a

View file

@ -304,13 +304,33 @@ function bootstrapTemplateWithHTMXetc(
htmlString = $.html();
} else if (htmxRequest && blissRoute) {
const $ = cheerio.load(htmlString, null, false);
$.root().children().attr("data-bliss-route", blissRoute);
$.root().children().attr("data-bliss-clone", blissClone);
if (blissCopy) $.root().children().attr("data-bliss-copy", blissCopy);
const targets = [];
// 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();
if (htmxRequest) {
htmlString += `<div id="head" hx-oob-swap="before_end">${headInjection}</div>`;
htmlString += `<head id="head" hx-oob-swap="beforeend">${headInjection}</head>`;
}
}