tdesign-mobile-vue
Version:
tdesign-mobile-vue
53 lines (45 loc) • 2.03 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var vue = require('vue');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
function useChildSlots(childComponentName, childInSlots) {
var _recurChildren = function recurChildren(children) {
var result = [];
if (Array.isArray(children)) {
children.forEach(function (child) {
if (vue.isVNode(child)) {
var _child$component;
result.push(child);
if ((_child$component = child.component) !== null && _child$component !== void 0 && _child$component.subTree) {
result.push(child.component.subTree);
result.push.apply(result, _toConsumableArray__default["default"](_recurChildren(child.component.subTree.children)));
}
if (child.children) {
result.push.apply(result, _toConsumableArray__default["default"](_recurChildren(child.children)));
}
}
});
}
return result;
};
var targetChildren = [];
if (childInSlots !== void 0) {
targetChildren.push.apply(targetChildren, _toConsumableArray__default["default"](_recurChildren(childInSlots)));
} else {
var _getCurrentInstance;
targetChildren.push.apply(targetChildren, _toConsumableArray__default["default"](_recurChildren((_getCurrentInstance = vue.getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.subTree.children)));
}
return targetChildren.filter(function (child) {
var _child$type;
return ((_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name) === childComponentName;
});
}
exports.useChildSlots = useChildSlots;
//# sourceMappingURL=index.js.map