import { type IfAny, isArray, isFunction } from '@vue/shared' import { type EffectScope, effectScope, isReactive, shallowReactive, } from '@vue/reactivity' import { type ComponentInternalInstance, currentInstance, setCurrentInstance, } from './component' import { type Block, type Fragment, fragmentKey } from './apiRender' import { firstEffect, renderEffect } from './renderEffect' import { createComment, createTextNode, insert, remove } from './dom/element' import { VaporErrorCodes, callWithAsyncErrorHandling } from './errorHandling' // TODO: SSR export type Slot = ( ...args: IfAny ) => Block export type InternalSlots = { [name: string]: Slot | undefined } export type Slots = Readonly export interface DynamicSlot { name: string fn: Slot key?: string } export type DynamicSlots = () => (DynamicSlot | DynamicSlot[])[] export function initSlots( instance: ComponentInternalInstance, rawSlots: InternalSlots | null = null, dynamicSlots: DynamicSlots | null = null, ) { let slots: InternalSlots = {} for (const key in rawSlots) { const slot = rawSlots[key] if (slot) { slots[key] = withCtx(slot) } } if (dynamicSlots) { slots = shallowReactive(slots) const dynamicSlotKeys: Record = {} firstEffect(instance, () => { const _dynamicSlots = callWithAsyncErrorHandling( dynamicSlots, instance, VaporErrorCodes.RENDER_FUNCTION, ) for (let i = 0; i < _dynamicSlots.length; i++) { const slot = _dynamicSlots[i] // array of dynamic slot generated by