import type { Ref } from 'vue' export function syncViewRowFromFlatList( viewRow: Ref, list: T[] ) { const current = viewRow.value if (!current?.id) return const updated = list.find(row => row.id === current.id) if (updated) viewRow.value = updated } export function findNodeInTreeById( nodes: T[], id: string | number ): T | undefined { for (const node of nodes) { if (node.id === id) return node if (node.children?.length) { const found = findNodeInTreeById(node.children, id) if (found) return found } } return undefined } export function syncViewRowFromTree( viewRow: Ref, roots: T[] ) { const current = viewRow.value if (!current?.id) return const updated = findNodeInTreeById(roots, current.id) if (updated) viewRow.value = updated }