{"version":3,"file":"ordered-children.mjs","names":[],"sources":["../../../../../../packages/components/resizable-columns/src/ordered-children.ts"],"sourcesContent":["import { isVNode, shallowRef } from 'vue'\nimport { flattedChildren } 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"],"mappings":";;;AAKA,MAAM,sBACJ,IACA,oBACA,aACQ;CAQR,OAPc,gBAAgB,GAAG,OAAO,CAAC,CAAC,QACvC,MACC,QAAQ,CAAC,KACR,EAAE,MAAc,SAAS,sBAC1B,CAAC,CAAC,EAAE,SAES,CAAC,CAAC,KAAK,MAAM,EAAE,UAAW,GACjC,CAAC,CAAC,KAAK,QAAQ,SAAS,IAAI,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC;AAC3D;AAEA,MAAa,sBACX,IACA,uBACG;CACH,MAAM,WAA8B,CAAC;CACrC,MAAM,kBAAkB,WAAgB,CAAC,CAAC;CAG1C,MAAM,YAAY,UAAa;EAC7B,SAAS,MAAM,OAAO;EACtB,gBAAgB,QAAQ,mBAAmB,IAAI,oBAAoB,QAAQ;CAC7E;CACA,MAAM,eAAe,QAAgB;EACnC,OAAO,SAAS;EAChB,gBAAgB,QAAQ,gBAAgB,MAAM,QAC3C,aAAa,SAAS,QAAQ,GACjC;CACF;CAEA,OAAO;EACL,UAAU;EACV;EACA;CACF;AACF"}