Skip to content

Commit

Permalink
Exclude named slots from children
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyuly committed Oct 19, 2024
1 parent 13ae5c0 commit 9849cca
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,28 @@ async function applyImportsToDomElement(domElement, context) {
);

const importDom = new JSDOM(importRendering);
const importSlots = importDom.window.document.querySelectorAll("slot");

for (const importSlot of importSlots) {
if (importSlot.hasAttribute("name")) {
const importedChild = Array.from(importedElement.children).find(
(child) =>
child.getAttribute("slot") === importSlot.getAttribute("name")
);

if (importedChild) {
importSlot.replaceWith(importedChild);
}
} else {
importSlot.replaceWith(...importedElement.childNodes);

const namedSlots =
importDom.window.document.querySelectorAll("slot[name]");

for (const namedSlot of namedSlots) {
const importedChild = Array.from(importedElement.children).find(
(child) =>
child.getAttribute("slot") === namedSlot.getAttribute("name")
);

if (importedChild) {
namedSlot.replaceWith(importedChild);
}
}

const childrenSlots =
importDom.window.document.querySelectorAll("slot:not([name])");

for (const importSlot of childrenSlots) {
importSlot.replaceWith(...importedElement.childNodes);
}

importedElement.replaceWith(...importDom.window.document.body.childNodes);
await applyImportsToDomElement(importDom.window.document.body, context);
}
Expand Down

0 comments on commit 9849cca

Please sign in to comment.