2023-03-20 21:47:06 +00:00
|
|
|
import type { defineAsyncComponent } from 'vue'
|
2023-11-18 20:47:55 +00:00
|
|
|
import { createVNode, defineComponent, onErrorCaptured } from 'vue'
|
2022-11-24 12:24:14 +00:00
|
|
|
|
2023-10-30 21:05:02 +00:00
|
|
|
import { createError } from '../composables/error'
|
|
|
|
|
2023-04-14 12:53:21 +00:00
|
|
|
// @ts-expect-error virtual file
|
2023-11-28 22:06:32 +00:00
|
|
|
import { islandComponents } from '#build/components.islands.mjs'
|
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,
|
2023-08-02 10:17:27 +00:00
|
|
|
statusMessage: `Island component not found: ${props.context.name}`
|
2022-11-24 12:24:14 +00:00
|
|
|
})
|
|
|
|
}
|
2023-05-15 22:43:53 +00:00
|
|
|
|
2023-11-18 20:47:55 +00:00
|
|
|
onErrorCaptured((e) => {
|
|
|
|
console.log(e)
|
|
|
|
})
|
|
|
|
|
2024-01-16 13:22:50 +00:00
|
|
|
return () => createVNode(component || 'span', { ...props.context.props, 'data-island-uid': '' })
|
2022-11-24 12:24:14 +00:00
|
|
|
}
|
|
|
|
})
|