2023-03-20 21:47:06 +00:00
|
|
|
import type { defineAsyncComponent } from 'vue'
|
2023-04-07 16:02:47 +00:00
|
|
|
import { createVNode, defineComponent } from 'vue'
|
2022-11-24 12:24:14 +00:00
|
|
|
|
2023-04-14 12:53:21 +00:00
|
|
|
// @ts-expect-error virtual file
|
2022-11-24 12:24:14 +00:00
|
|
|
import * as islandComponents from '#build/components.islands.mjs'
|
2023-02-09 06:26:41 +00:00
|
|
|
import { createError } from '#app/composables/error'
|
2022-11-24 12:24:14 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
context: {
|
|
|
|
type: Object as () => { name: string, props?: Record<string, any> },
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2023-03-20 21:47:06 +00:00
|
|
|
setup (props) {
|
|
|
|
const component = islandComponents[props.context.name] as ReturnType<typeof defineAsyncComponent>
|
2022-11-24 12:24:14 +00:00
|
|
|
|
|
|
|
if (!component) {
|
|
|
|
throw createError({
|
|
|
|
statusCode: 404,
|
|
|
|
statusMessage: `Island component not found: ${JSON.stringify(component)}`
|
|
|
|
})
|
|
|
|
}
|
2023-03-20 21:47:06 +00:00
|
|
|
return () => createVNode(component || 'span', props.context.props)
|
2022-11-24 12:24:14 +00:00
|
|
|
}
|
|
|
|
})
|