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.
1 line
2.7 KiB
1 line
2.7 KiB
{"version":3,"file":"index.js","sources":["../../../../../packages/hooks/use-ordered-children/index.ts"],"sourcesContent":["import { shallowRef } from 'vue'\nimport { flattedChildren, isVNode } from '@element-plus/utils'\n\nimport type { ComponentInternalInstance, VNode } from 'vue'\n\nconst getOrderedChildren = <T>(\n vm: ComponentInternalInstance,\n childComponentName: string,\n children: Record<number, T>\n): T[] => {\n const nodes = flattedChildren(vm.subTree).filter(\n (n): n is VNode =>\n isVNode(n) &&\n (n.type as any)?.name === childComponentName &&\n !!n.component\n )\n const uids = nodes.map((n) => n.component!.uid)\n return uids.map((uid) => children[uid]).filter((p) => !!p)\n}\n\nexport const useOrderedChildren = <T extends { uid: number }>(\n vm: ComponentInternalInstance,\n childComponentName: string\n) => {\n const children: Record<number, T> = {}\n const orderedChildren = shallowRef<T[]>([])\n\n // TODO: split into two functions: addChild and sortChildren\n const addChild = (child: T) => {\n children[child.uid] = child\n orderedChildren.value = getOrderedChildren(vm, childComponentName, children)\n }\n const removeChild = (uid: number) => {\n delete children[uid]\n orderedChildren.value = orderedChildren.value.filter(\n (children) => children.uid !== uid\n )\n }\n\n return {\n children: orderedChildren,\n addChild,\n removeChild,\n }\n}\n"],"names":["flattedChildren","isVNode","shallowRef"],"mappings":";;;;;;;;AAEA,MAAM,kBAAkB,GAAG,CAAC,EAAE,EAAE,kBAAkB,EAAE,QAAQ,KAAK;AACjE,EAAE,MAAM,KAAK,GAAGA,qBAAe,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;AAC1D,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,OAAOC,WAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,MAAM,kBAAkB,IAAI,CAA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