{"version":3,"file":"utils.mjs","sources":["../../../../../../packages/components/tree-select/src/utils.ts"],"sourcesContent":["import type { TreeNodeData } from '@element-plus/components/tree/src/tree.type'\n\nexport function isValidValue(val: any) {\n return val || val === 0\n}\n\nexport function isValidArray(val: any) {\n return Array.isArray(val) && val.length\n}\n\nexport function toValidArray(val: any) {\n return Array.isArray(val) ? val : isValidValue(val) ? [val] : []\n}\n\ntype TreeCallback = (\n data: T,\n index: number,\n array: T[],\n parent?: T\n) => R\n\ntype TreeFindCallback = TreeCallback\n\nexport function treeFind(\n treeData: T[],\n findCallback: TreeFindCallback,\n getChildren: (data: T) => T[]\n): T | undefined\nexport function treeFind(\n treeData: T[],\n findCallback: TreeFindCallback,\n getChildren: (data: T) => T[],\n resultCallback?: TreeCallback,\n parent?: T\n): R | undefined\nexport function treeFind(\n treeData: T[],\n findCallback: TreeFindCallback,\n getChildren: (data: T) => T[],\n resultCallback?: TreeCallback,\n parent?: T\n): T | R | undefined {\n for (let i = 0; i < treeData.length; i++) {\n const data = treeData[i]\n if (findCallback(data, i, treeData, parent)) {\n return resultCallback ? resultCallback(data, i, treeData, parent) : data\n } else {\n const children = getChildren(data)\n if (isValidArray(children)) {\n const find = treeFind(\n children,\n findCallback,\n getChildren,\n resultCallback,\n data\n )\n if (find) return find\n }\n }\n }\n}\n\nexport function treeEach(\n treeData: T[],\n callback: TreeCallback,\n getChildren: (data: T) => T[],\n parent?: T\n) {\n for (let i = 0; i < treeData.length; i++) {\n const data = treeData[i]\n callback(data, i, treeData, parent)\n\n const children = getChildren(data)\n if (isValidArray(children)) {\n treeEach(children, callback, getChildren, data)\n }\n }\n}\n"],"names":[],"mappings":"AAAO,SAAS,YAAY,CAAC,GAAG,EAAE;AAClC,EAAE,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC;AAC1B,CAAC;AACM,SAAS,YAAY,CAAC,GAAG,EAAE;AAClC,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAA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