{"version":3,"file":"pages/ModuleAnalyze/utils/hooks.mjs","sources":["../../../../src/pages/ModuleAnalyze/utils/hooks.tsx"],"sourcesContent":["import { SDK } from '@rsdoctor/types';\nimport { useMemo } from 'react';\nimport { formatSize, getShortPath } from 'src/utils';\nimport { getImporteds } from '.';\nimport { Lodash } from '@rsdoctor/utils/common';\n\nexport type NewTreeNodeType = {\n  __RESOURCEPATH__: string;\n  id: number;\n  key: string;\n  name: string;\n  level: number;\n  kind: number;\n  size?: string;\n  concatModules: number[] | undefined;\n  chunks?: string[];\n  getChildren?: () => NewTreeNodeType[];\n  dependencies?: number[];\n  fatherPath?: string;\n  children?: number[];\n  needExpand?: boolean | string;\n};\n\nexport function useCreateFileTreeData(\n  modules: SDK.ModuleData[],\n  importedModules: SDK.ModuleData[],\n  curModule: SDK.ModuleData,\n): { data: NewTreeNodeType[] } {\n  return useMemo(() => {\n    if (!importedModules || !importedModules?.length) {\n      return { filterData: [], data: [] };\n    }\n    const root = Lodash.compact(\n      importedModules?.map((imported, index) => {\n        return {\n          key: `0-${index}`,\n          name: getShortPath(imported.path),\n          __RESOURCEPATH__: imported.path,\n          id: imported.id,\n          level: 0,\n          chunks: imported.chunks,\n          size: formatSize(imported.size.parsedSize),\n          kind: imported.kind,\n          concatModules: imported.concatenationModules,\n          fatherPath: getShortPath(curModule.path),\n          dependencies: imported.dependencies,\n          getChildren: () => getLeafs(imported, modules, curModule, 0),\n          children: imported.imported,\n        };\n      }),\n    );\n    // getAllTreeData(root, modules, 2, importedModules);\n    return {\n      data: root,\n    };\n  }, [importedModules, curModule]);\n}\n\nfunction getLeafs(\n  imported: SDK.ModuleData,\n  modules: SDK.ModuleData[],\n  fatherModule: SDK.ModuleData,\n  parentLevel: number,\n) {\n  const leafModules = getImporteds(imported, modules);\n  const currentLevel = parentLevel + 1;\n\n  const leafs = leafModules?.map((_imported, index) => {\n    return {\n      key: `0-${index}`,\n      name: getShortPath(_imported.path),\n      __RESOURCEPATH__: _imported.path,\n      id: _imported.id,\n      level: currentLevel,\n      size: formatSize(_imported.size.parsedSize),\n      kind: _imported.kind,\n      chunks: _imported.chunks,\n      concatModules: _imported.concatenationModules,\n      fatherPath: getShortPath(fatherModule.path),\n      dependencies: _imported.dependencies,\n      getChildren: () => getLeafs(_imported, modules, imported, currentLevel),\n      children: _imported.imported,\n    };\n  });\n  return leafs;\n}\n\nexport function getContactMainModulePath(\n  concatModules: number[],\n  modules: SDK.ModuleData[],\n): string[] {\n  const concatModulesPath = concatModules?.map(\n    (cm) => modules.filter((m) => m.id === cm)?.[0],\n  );\n  return concatModulesPath?.map((m) => m.path);\n}\n"],"names":["useCreateFileTreeData","modules","importedModules","curModule","useMemo","root","Lodash","imported","index","getShortPath","formatSize","getLeafs","fatherModule","parentLevel","leafModules","getImporteds","currentLevel","leafs","_imported","getContactMainModulePath","concatModules","concatModulesPath","cm","m"],"mappings":";;;;AAuBO,SAASA,sBACdC,OAAyB,EACzBC,eAAiC,EACjCC,SAAyB;IAEzB,OAAOC,QAAQ;QACb,IAAI,CAACF,mBAAmB,CAACA,iBAAiB,QACxC,OAAO;YAAE,YAAY,EAAE;YAAE,MAAM,EAAE;QAAC;QAEpC,MAAMG,OAAOC,OAAO,OAAO,CACzBJ,iBAAiB,IAAI,CAACK,UAAUC,QACvB;gBACL,KAAK,CAAC,EAAE,EAAEA,OAAO;gBACjB,MAAMC,aAAaF,SAAS,IAAI;gBAChC,kBAAkBA,SAAS,IAAI;gBAC/B,IAAIA,SAAS,EAAE;gBACf,OAAO;gBACP,QAAQA,SAAS,MAAM;gBACvB,MAAMG,WAAWH,SAAS,IAAI,CAAC,UAAU;gBACzC,MAAMA,SAAS,IAAI;gBACnB,eAAeA,SAAS,oBAAoB;gBAC5C,YAAYE,aAAaN,UAAU,IAAI;gBACvC,cAAcI,SAAS,YAAY;gBACnC,aAAa,IAAMI,SAASJ,UAAUN,SAASE,WAAW;gBAC1D,UAAUI,SAAS,QAAQ;YAC7B;QAIJ,OAAO;YACL,MAAM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