2022-03-18 22:35:45 +00:00
|
|
|
function check(Component) {
|
|
|
|
return Component['render'] && Component['$$render'];
|
|
|
|
}
|
|
|
|
|
2023-05-17 14:18:04 +00:00
|
|
|
function needsHydration(metadata) {
|
|
|
|
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
|
|
|
|
return metadata.astroStaticSlot ? !!metadata.hydrate : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function renderToStaticMarkup(Component, props, slotted, metadata) {
|
|
|
|
const tagName = needsHydration(metadata) ? 'astro-slot' : 'astro-static-slot';
|
2022-06-23 15:10:54 +00:00
|
|
|
const slots = {};
|
|
|
|
for (const [key, value] of Object.entries(slotted)) {
|
2022-06-23 15:12:46 +00:00
|
|
|
slots[key] = () =>
|
2023-05-17 14:18:04 +00:00
|
|
|
`<${tagName}${key === 'default' ? '' : ` name="${key}"`}>${value}</${tagName}>`;
|
2022-06-23 15:10:54 +00:00
|
|
|
}
|
|
|
|
const { html } = Component.render(props, { $$slots: slots });
|
2022-03-18 22:35:45 +00:00
|
|
|
return { html };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
2023-05-17 14:18:04 +00:00
|
|
|
supportsAstroStaticSlot: true,
|
2022-03-18 22:35:45 +00:00
|
|
|
};
|