2024-07-17 18:54:46 +00:00
|
|
|
import { useStore } from '@nanostores/react';
|
2024-07-18 21:07:04 +00:00
|
|
|
import { memo } from 'react';
|
2024-07-17 18:54:46 +00:00
|
|
|
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
|
2024-07-18 21:07:04 +00:00
|
|
|
import type { FileMap } from '../../lib/stores/files';
|
2024-07-17 18:54:46 +00:00
|
|
|
import { themeStore } from '../../lib/stores/theme';
|
2024-07-18 21:07:04 +00:00
|
|
|
import { renderLogger } from '../../utils/logger';
|
|
|
|
import { isMobile } from '../../utils/mobile';
|
|
|
|
import {
|
|
|
|
CodeMirrorEditor,
|
|
|
|
type EditorDocument,
|
|
|
|
type OnChangeCallback as OnEditorChange,
|
|
|
|
type OnScrollCallback as OnEditorScroll,
|
|
|
|
} from '../editor/codemirror/CodeMirrorEditor';
|
2024-07-17 18:54:46 +00:00
|
|
|
import { FileTreePanel } from './FileTreePanel';
|
|
|
|
|
2024-07-18 21:07:04 +00:00
|
|
|
interface EditorPanelProps {
|
|
|
|
files?: FileMap;
|
|
|
|
editorDocument?: EditorDocument;
|
|
|
|
selectedFile?: string | undefined;
|
|
|
|
isStreaming?: boolean;
|
|
|
|
onEditorChange?: OnEditorChange;
|
|
|
|
onEditorScroll?: OnEditorScroll;
|
|
|
|
onFileSelect?: (value?: string) => void;
|
2024-07-17 18:54:46 +00:00
|
|
|
}
|
2024-07-18 21:07:04 +00:00
|
|
|
|
|
|
|
export const EditorPanel = memo(
|
|
|
|
({ files, editorDocument, selectedFile, onFileSelect, onEditorChange, onEditorScroll }: EditorPanelProps) => {
|
|
|
|
renderLogger.trace('EditorPanel');
|
|
|
|
|
|
|
|
const theme = useStore(themeStore);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PanelGroup direction="horizontal">
|
|
|
|
<Panel defaultSize={25} minSize={10} collapsible={true}>
|
|
|
|
<FileTreePanel files={files} selectedFile={selectedFile} onFileSelect={onFileSelect} />
|
|
|
|
</Panel>
|
|
|
|
<PanelResizeHandle />
|
|
|
|
<Panel defaultSize={75} minSize={20}>
|
|
|
|
<CodeMirrorEditor
|
|
|
|
theme={theme}
|
|
|
|
editable={true}
|
|
|
|
settings={{ tabSize: 2 }}
|
|
|
|
doc={editorDocument}
|
|
|
|
autoFocusOnDocumentChange={!isMobile()}
|
|
|
|
onScroll={onEditorScroll}
|
|
|
|
onChange={onEditorChange}
|
|
|
|
/>
|
|
|
|
</Panel>
|
|
|
|
</PanelGroup>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|