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.

35 lines
1.1 KiB

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