You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
2 months ago
|
import { isVNode, shallowRef } from 'vue';
|
||
|
import '../../utils/index.mjs';
|
||
|
import { flattedChildren } from '../../utils/vue/vnode.mjs';
|
||
|
|
||
|
const getOrderedChildren = (vm, childComponentName, children) => {
|
||
|
const nodes = flattedChildren(vm.subTree).filter((n) => {
|
||
|
var _a;
|
||
|
return isVNode(n) && ((_a = n.type) == null ? void 0 : _a.name) === childComponentName && !!n.component;
|
||
|
});
|
||
|
const uids = nodes.map((n) => n.component.uid);
|
||
|
return uids.map((uid) => children[uid]).filter((p) => !!p);
|
||
|
};
|
||
|
const useOrderedChildren = (vm, childComponentName) => {
|
||
|
const children = {};
|
||
|
const orderedChildren = shallowRef([]);
|
||
|
const addChild = (child) => {
|
||
|
children[child.uid] = child;
|
||
|
orderedChildren.value = getOrderedChildren(vm, childComponentName, children);
|
||
|
};
|
||
|
const removeChild = (uid) => {
|
||
|
delete children[uid];
|
||
|
orderedChildren.value = orderedChildren.value.filter((children2) => children2.uid !== uid);
|
||
|
};
|
||
|
return {
|
||
|
children: orderedChildren,
|
||
|
addChild,
|
||
|
removeChild
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export { useOrderedChildren };
|
||
|
//# sourceMappingURL=index.mjs.map
|