tdesign-mobile-vue
Version:
tdesign-mobile-vue
46 lines (42 loc) • 1.72 kB
JavaScript
/**
* tdesign v1.9.3
* (c) 2025 TDesign Group
* @license MIT
*/
import { _ as _toConsumableArray } from '../_chunks/dep-fb4113ef.mjs';
import { isVNode, getCurrentInstance } from 'vue';
import '../_chunks/dep-a953013f.mjs';
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 as default };
//# sourceMappingURL=useChildSlots.mjs.map