17 lines
576 B
JavaScript
Raw Normal View History

2024-01-29 09:26:07 +08:00
import { warn } from "../naive/index.mjs";
2024-08-02 18:19:39 +08:00
import { flatten } from "./flatten.mjs";
2024-01-29 09:26:07 +08:00
export function getFirstSlotVNode(slots, slotName = 'default', props = undefined) {
const slot = slots[slotName];
if (!slot) {
warn('getFirstSlotVNode', `slot[${slotName}] is empty`);
return null;
}
const slotContent = flatten(slot(props));
// vue will normalize the slot, so slot must be an array
if (slotContent.length === 1) {
return slotContent[0];
} else {
warn('getFirstSlotVNode', `slot[${slotName}] should have exactly one child`);
return null;
}
}