27 lines
721 B
TypeScript
27 lines
721 B
TypeScript
|
import { Slot } from '../componentSlots'
|
||
|
import { isArray } from '@vue/shared'
|
||
|
|
||
|
interface CompiledSlotDescriptor {
|
||
|
name: string
|
||
|
fn: Slot
|
||
|
}
|
||
|
|
||
|
export function createSlots(
|
||
|
slots: Record<string, Slot>,
|
||
|
dynamicSlots: (CompiledSlotDescriptor | CompiledSlotDescriptor[])[]
|
||
|
): Record<string, Slot> {
|
||
|
for (let i = 0; i < dynamicSlots.length; i++) {
|
||
|
const slot = dynamicSlots[i]
|
||
|
// array of dynamic slot generated by <template v-for="..." #[...]>
|
||
|
if (isArray(slot)) {
|
||
|
for (let j = 0; j < slot.length; j++) {
|
||
|
slots[slot[i].name] = slot[i].fn
|
||
|
}
|
||
|
} else {
|
||
|
// conditional single slot generated by <template v-if="..." #foo>
|
||
|
slots[slot.name] = slot.fn
|
||
|
}
|
||
|
}
|
||
|
return slots
|
||
|
}
|