import { ReactNode, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { ImperativePanelHandle, Panel, PanelGroup, } from 'react-resizable-panels' import { HorizontalResizeHandle } from '@/features/ide-react/components/resize/horizontal-resize-handle' import { HorizontalToggler } from '@/features/ide-react/components/resize/horizontal-toggler' import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel' import { useLayoutContext } from '@/shared/context/layout-context' import PdfPreview from '@/features/pdf-preview/components/pdf-preview' import { DefaultSynctexControl } from '@/features/pdf-preview/components/detach-synctex-control' import classnames from 'classnames' export type EditorProps = { shouldPersistLayout?: boolean editorContent: ReactNode } export default function EditorAndPdf({ shouldPersistLayout = false, editorContent, }: EditorProps) { const { t } = useTranslation() const { view, pdfLayout, changeLayout, detachRole, reattach } = useLayoutContext() const [resizing, setResizing] = useState(false) const pdfPanelRef = useRef(null) const isDualPane = pdfLayout === 'sideBySide' const editorIsVisible = isDualPane || view === 'editor' || view === 'file' const pdfIsOpen = isDualPane || view === 'pdf' useCollapsiblePanel(pdfIsOpen, pdfPanelRef) const historyIsOpen = view === 'history' function setPdfIsOpen(isOpen: boolean) { if (isOpen) { if (detachRole === 'detacher') { reattach() } changeLayout('sideBySide') } else { changeLayout('flat', 'editor') } } return ( {editorIsVisible ? (
{editorContent}
) : null} setPdfIsOpen(!pdfIsOpen)} onDragging={setResizing} > {isDualPane ? (
) : null}
setPdfIsOpen(!collapsed)} className="ide-react-panel" > {pdfIsOpen || resizing ? : null}
) }