2022-06-23 10:10:54 -05:00
|
|
|
const noop = () => {};
|
2022-03-18 17:35:45 -05:00
|
|
|
|
|
|
|
export default (target) => {
|
2022-06-23 10:10:54 -05:00
|
|
|
return (Component, props, slotted, { client }) => {
|
2022-05-31 11:29:36 -05:00
|
|
|
if (!target.hasAttribute('ssr')) return;
|
2022-06-23 10:10:54 -05:00
|
|
|
const slots = {};
|
|
|
|
for (const [key, value] of Object.entries(slotted)) {
|
|
|
|
slots[key] = createSlotDefinition(key, value);
|
|
|
|
}
|
2022-03-18 17:35:45 -05:00
|
|
|
try {
|
2022-06-23 10:10:54 -05:00
|
|
|
new Component({
|
2022-03-18 17:35:45 -05:00
|
|
|
target,
|
2022-06-23 10:12:46 -05:00
|
|
|
props: {
|
2022-06-23 10:10:54 -05:00
|
|
|
...props,
|
|
|
|
$$slots: slots,
|
2022-06-23 10:12:46 -05:00
|
|
|
$$scope: { ctx: [] },
|
2022-06-23 10:10:54 -05:00
|
|
|
},
|
2022-05-31 11:29:36 -05:00
|
|
|
hydrate: client !== 'only',
|
2022-06-23 10:10:54 -05:00
|
|
|
$$inline: true,
|
2022-03-18 17:35:45 -05:00
|
|
|
});
|
|
|
|
} catch (e) {}
|
|
|
|
};
|
|
|
|
};
|
2022-06-23 10:10:54 -05:00
|
|
|
|
|
|
|
function createSlotDefinition(key, children) {
|
2022-06-23 10:12:46 -05:00
|
|
|
return [
|
|
|
|
() => ({
|
2022-06-23 10:10:54 -05:00
|
|
|
// mount
|
|
|
|
m(target) {
|
2022-06-23 10:12:46 -05:00
|
|
|
target.insertAdjacentHTML(
|
|
|
|
'beforeend',
|
|
|
|
`<astro-slot${key === 'default' ? '' : ` name="${key}"`}>${children}</astro-slot>`
|
|
|
|
);
|
2022-06-23 10:10:54 -05:00
|
|
|
},
|
|
|
|
// create
|
|
|
|
c: noop,
|
|
|
|
// hydrate
|
|
|
|
l: noop,
|
|
|
|
// destroy
|
|
|
|
d: noop,
|
|
|
|
}),
|
2022-06-23 10:12:46 -05:00
|
|
|
noop,
|
|
|
|
noop,
|
|
|
|
];
|
2022-06-23 10:10:54 -05:00
|
|
|
}
|