index.mjs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { shallowRef, isVNode } from 'vue';
  2. import { flattedChildren } from '../../utils/vue/vnode.mjs';
  3. const getOrderedChildren = (vm, childComponentName, children) => {
  4. const nodes = flattedChildren(vm.subTree).filter((n) => {
  5. var _a;
  6. return isVNode(n) && ((_a = n.type) == null ? void 0 : _a.name) === childComponentName && !!n.component;
  7. });
  8. const uids = nodes.map((n) => n.component.uid);
  9. return uids.map((uid) => children[uid]).filter((p) => !!p);
  10. };
  11. const useOrderedChildren = (vm, childComponentName) => {
  12. const children = {};
  13. const orderedChildren = shallowRef([]);
  14. const addChild = (child) => {
  15. children[child.uid] = child;
  16. orderedChildren.value = getOrderedChildren(vm, childComponentName, children);
  17. };
  18. const removeChild = (uid) => {
  19. delete children[uid];
  20. orderedChildren.value = orderedChildren.value.filter((children2) => children2.uid !== uid);
  21. };
  22. return {
  23. children: orderedChildren,
  24. addChild,
  25. removeChild
  26. };
  27. };
  28. export { useOrderedChildren };
  29. //# sourceMappingURL=index.mjs.map