tdesign-mobile-vue
Version:
tdesign-mobile-vue
45 lines (41 loc) • 1.67 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { getCurrentInstance, isVNode } from 'vue';
function useChildSlots(childComponentName, childInSlots) {
var _recurChildren = function recurChildren(children) {
var result = [];
if (Array.isArray(children)) {
children.forEach(function (child) {
if (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(_recurChildren(child.component.subTree.children)));
}
if (child.children) {
result.push.apply(result, _toConsumableArray(_recurChildren(child.children)));
}
}
});
}
return result;
};
var targetChildren = [];
if (childInSlots !== void 0) {
targetChildren.push.apply(targetChildren, _toConsumableArray(_recurChildren(childInSlots)));
} else {
var _getCurrentInstance;
targetChildren.push.apply(targetChildren, _toConsumableArray(_recurChildren((_getCurrentInstance = 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;
});
}
export { useChildSlots };
//# sourceMappingURL=index.js.map