xdesign-vue-next
Version:
XDesign Component for vue-next
68 lines (60 loc) • 2.46 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _typeof = require('@babel/runtime/helpers/typeof');
var vue = require('vue');
var isArray = require('lodash/isArray');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
function useChildComponentSlots() {
var instance = vue.getCurrentInstance();
return function (childComponentName, slots) {
var _slots, _slots$default;
if (!slots) {
slots = instance.slots;
}
var content = ((_slots = slots) === null || _slots === void 0 || (_slots$default = _slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(_slots)) || [];
var childList = [];
var getChildren = function getChildren(content2) {
if (!isArray__default["default"](content2)) return;
content2.forEach(function (item) {
if (item.children && isArray__default["default"](item.children)) {
if (item.type !== vue.Fragment) return;
getChildren(item.children);
} else {
childList.push(item);
}
});
return childList;
};
return getChildren(content).filter(function (item) {
var _item$type$name;
return (_item$type$name = item.type.name) === null || _item$type$name === void 0 ? void 0 : _item$type$name.endsWith(childComponentName);
});
};
}
function useChildSlots() {
var instance = vue.getCurrentInstance();
return function () {
var _slots$default2;
var slots = instance.slots;
var content = (slots === null || slots === void 0 || (_slots$default2 = slots["default"]) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots)) || [];
return content.filter(function (item) {
if (_typeof__default["default"](item.type) === "symbol" && !item.children) {
return false;
}
return item.type !== vue.Comment;
}).map(function (item) {
if (item.children && isArray__default["default"](item.children) && item.type === vue.Fragment) return item.children;
return item;
}).flat();
};
}
exports.useChildComponentSlots = useChildComponentSlots;
exports.useChildSlots = useChildSlots;
//# sourceMappingURL=slot.js.map