@fe6/water-pro
Version:
An enterprise-class UI design language and Vue-based implementation
58 lines (46 loc) • 1.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSlot = getSlot;
exports.extendSlots = extendSlots;
var _shared = require("@fe6/shared");
/** @format */
/**
* @description: Get slot to prevent empty error
*/
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 (!(0, _shared.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
*/
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;
}
;