UNPKG

@fe6/water-pro

Version:

An enterprise-class UI design language and Vue-based implementation

48 lines (40 loc) 1.01 kB
/** @format */ import { isFunction } from '@fe6/shared'; /** * @description: Get slot to prevent empty error */ export function getSlot(slots) { var slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default'; var data = arguments.length > 2 ? arguments[2] : undefined; if (!slots || !Reflect.has(slots, slot)) { return null; } if (!isFunction(slots[slot])) { console.error("".concat(slot, " is not a function!")); return null; } var slotFn = slots[slot]; if (!slotFn) { return null; } return slotFn(data); } /** * extends slots * @param slots * @param excludeKeys */ export function extendSlots(slots) { var excludeKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var slotKeys = Object.keys(slots); var ret = {}; slotKeys.map(function (key) { if (excludeKeys.includes(key)) { return null; } ret[key] = function () { return getSlot(slots, key); }; }); return ret; }