import React from 'react' import { CodeBlock } from '~/components/Markdown' import { FileExplorer } from './FileExplorer' import { InteractiveSandbox } from './InteractiveSandbox' import { CodeExplorerTopBar } from './CodeExplorerTopBar' import type { GitHubFileNode } from '~/utils/documents.server' import type { Library } from '~/libraries' function overrideExtension(ext: string | undefined) { if (!ext) return 'txt' // Override some extensions if (['cts', 'mts'].includes(ext)) return 'ts' if (['cjs', 'mjs'].includes(ext)) return 'js' if (['prettierrc', 'babelrc', 'webmanifest'].includes(ext)) return 'json' if (['env', 'example'].includes(ext)) return 'sh' if ( [ 'gitignore', 'prettierignore', 'log', 'gitattributes', 'editorconfig', 'lock', 'opts', 'Dockerfile', 'dockerignore', 'npmrc', 'nvmrc', ].includes(ext) ) return 'txt' return ext } interface CodeExplorerProps { activeTab: 'code' | 'sandbox' codeSandboxUrl: string currentCode: string currentPath: string examplePath: string githubContents: GitHubFileNode[] | undefined library: Library prefetchFileContent: (path: string) => void setActiveTab: (tab: 'code' | 'sandbox') => void setCurrentPath: (path: string) => void stackBlitzUrl: string } export function CodeExplorer({ activeTab, codeSandboxUrl, currentCode, currentPath, examplePath, githubContents, library, prefetchFileContent, setActiveTab, setCurrentPath, stackBlitzUrl, }: CodeExplorerProps) { const [isFullScreen, setIsFullScreen] = React.useState(false) const [isSidebarOpen, setIsSidebarOpen] = React.useState(true) // Add escape key handler React.useEffect(() => { const handleEsc = (e: KeyboardEvent) => { if (e.key === 'Escape' && isFullScreen) { setIsFullScreen(false) } } window.addEventListener('keydown', handleEsc) return () => window.removeEventListener('keydown', handleEsc) }, [isFullScreen]) // Add sidebar close handler React.useEffect(() => { const handleCloseSidebar = () => { setIsSidebarOpen(false) } window.addEventListener('closeSidebar', handleCloseSidebar) return () => window.removeEventListener('closeSidebar', handleCloseSidebar) }, []) return (
{currentCode}
) }