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