33import type React from 'react'
44import { useEffect , useMemo , useRef , useState } from 'react'
55import useSWR from 'swr'
6- import { ImportChain } from '@/components/import-chain'
76import { ErrorState } from '@/components/error-state'
87import {
98 RouteTypeahead ,
109 type RouteTypeaheadRef ,
1110} from '@/components/route-typeahead'
11+ import { Sidebar } from '@/components/sidebar'
1212import { TreemapVisualizer } from '@/components/treemap-visualizer'
1313
1414import { Input } from '@/components/ui/input'
15- import { Skeleton , TreemapSkeleton } from '@/components/ui/skeleton'
15+ import { TreemapSkeleton } from '@/components/ui/skeleton'
1616import { ToggleGroup , ToggleGroupItem } from '@/components/ui/toggle-group'
1717import { AnalyzeData , ModulesData } from '@/lib/analyze-data'
1818import { computeActiveEntries , computeModuleDepthMap } from '@/lib/module-graph'
19- import { SpecialModule } from '@/lib/types'
20- import { getSpecialModuleType , fetchStrict } from '@/lib/utils'
21-
22- function formatBytes ( bytes : number ) : string {
23- if ( bytes === 0 ) return '0 B'
24- if ( bytes < 1024 ) return `${ bytes } B`
25- if ( bytes < 1024 * 1024 ) return `${ ( bytes / 1024 ) . toFixed ( 2 ) } KB`
26- if ( bytes < 1024 * 1024 * 1024 )
27- return `${ ( bytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) } MB`
28- return `${ ( bytes / ( 1024 * 1024 * 1024 ) ) . toFixed ( 2 ) } GB`
29- }
19+ import { fetchStrict } from '@/lib/utils'
3020
3121export default function Home ( ) {
3222 const [ selectedRoute , setSelectedRoute ] = useState < string | null > ( null )
@@ -153,11 +143,6 @@ export default function Home() {
153143 const isAnyLoading = isAnalyzeLoading || isModulesLoading
154144 const rootSourceIndex = getRootSourceIndex ( analyzeData )
155145
156- const specialModuleType = getSpecialModuleType (
157- analyzeData ,
158- selectedSourceIndex
159- )
160-
161146 return (
162147 < main
163148 className = "h-screen flex flex-col bg-background"
@@ -250,24 +235,15 @@ export default function Home() {
250235 aria-label = "Resize sidebar"
251236 />
252237
253- < div
254- className = "flex-none bg-muted border-l border-border overflow-y-auto"
255- style = { { width : `${ sidebarWidth } %` } }
256- >
257- < div className = "flex-1 p-3 space-y-4 overflow-y-auto" >
258- < h2 className = "text-xs font-semibold mb-2 text-foreground" >
259- Selected Source
260- </ h2 >
261- < Skeleton className = "h-4 w-3/4" />
262- < Skeleton className = "h-4 w-full" />
263- < Skeleton className = "h-4 w-5/6" />
264- < div className = "mt-4 space-y-2" >
265- < Skeleton className = "h-3 w-full" />
266- < Skeleton className = "h-3 w-full" />
267- < Skeleton className = "h-3 w-4/5" />
268- </ div >
269- </ div >
270- </ div >
238+ < Sidebar
239+ sidebarWidth = { sidebarWidth }
240+ analyzeData = { null }
241+ modulesData = { null }
242+ selectedSourceIndex = { null }
243+ moduleDepthMap = { new Map ( ) }
244+ environmentFilter = { environmentFilter }
245+ isLoading = { true }
246+ />
271247 </ >
272248 ) : analyzeData ? (
273249 < >
@@ -294,86 +270,14 @@ export default function Home() {
294270 aria-label = "Resize sidebar"
295271 />
296272
297- < div
298- className = "flex-none bg-muted border-l border-border overflow-y-auto"
299- style = { { width : `${ sidebarWidth } %` } }
300- >
301- < div className = "flex-1 p-3 space-y-4 overflow-y-auto" >
302- < h2 className = "text-xs font-semibold mb-2 text-foreground" >
303- Selected Source
304- </ h2 >
305-
306- { selectedSourceIndex != null &&
307- analyzeData . source ( selectedSourceIndex ) && (
308- < >
309- < dl className = "space-y-2" >
310- < div >
311- < dt className = "text-xs text-muted-foreground inline" >
312- Output Size:{ ' ' }
313- </ dt >
314- < dd className = "text-xs text-muted-foreground inline" >
315- { formatBytes (
316- analyzeData . getSourceOutputSize (
317- selectedSourceIndex
318- )
319- ) }
320- </ dd >
321- </ div >
322- { ( specialModuleType === SpecialModule . POLYFILL_MODULE ||
323- specialModuleType ===
324- SpecialModule . POLYFILL_NOMODULE ) && (
325- < div className = "flex items-center gap-2" >
326- < dt className = "inline-flex items-center rounded-md bg-polyfill/10 dark:bg-polyfill/30 px-2 py-1 text-xs font-medium text-polyfill dark:text-polyfill-foreground ring-1 ring-inset ring-polyfill/20 shrink-0" >
327- Polyfill
328- </ dt >
329- < dd className = "text-xs text-muted-foreground" >
330- Next.js built-in polyfills
331- { specialModuleType ===
332- SpecialModule . POLYFILL_NOMODULE ? (
333- < >
334- . < code > polyfill-nomodule.js</ code > is only
335- sent to legacy browsers.
336- </ >
337- ) : null }
338- </ dd >
339- </ div >
340- ) }
341- </ dl >
342- { modulesData && (
343- < ImportChain
344- key = { selectedSourceIndex }
345- startFileId = { selectedSourceIndex }
346- analyzeData = { analyzeData }
347- modulesData = { modulesData }
348- depthMap = { moduleDepthMap }
349- environmentFilter = { environmentFilter }
350- />
351- ) }
352- { ( ( ) => {
353- const chunks =
354- analyzeData . sourceChunks ( selectedSourceIndex )
355- if ( chunks . length > 0 ) {
356- return (
357- < div className = "mt-2" >
358- < p className = "text-xs font-semibold text-foreground" >
359- Output Chunks:
360- </ p >
361- < ul className = "text-xs text-muted-foreground font-mono mt-1 space-y-1" >
362- { chunks . map ( ( chunk ) => (
363- < li key = { chunk } className = "break-all" >
364- { chunk }
365- </ li >
366- ) ) }
367- </ ul >
368- </ div >
369- )
370- }
371- return null
372- } ) ( ) }
373- </ >
374- ) }
375- </ div >
376- </ div >
273+ < Sidebar
274+ sidebarWidth = { sidebarWidth }
275+ analyzeData = { analyzeData ?? null }
276+ modulesData = { modulesData ?? null }
277+ selectedSourceIndex = { selectedSourceIndex }
278+ moduleDepthMap = { moduleDepthMap }
279+ environmentFilter = { environmentFilter }
280+ />
377281 </ >
378282 ) : null }
379283 </ div >
0 commit comments