editor-and-pdf.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React, { FC, useState } from 'react'
  2. import { Panel, PanelGroup } from 'react-resizable-panels'
  3. import NoSelectionPane from '@/features/ide-react/components/editor/no-selection-pane'
  4. import FileView from '@/features/file-view/components/file-view'
  5. import { fileViewFile } from '@/features/ide-react/hooks/use-file-tree'
  6. import MultipleSelectionPane from '@/features/ide-react/components/editor/multiple-selection-pane'
  7. import { HorizontalResizeHandle } from '@/features/ide-react/components/resize/horizontal-resize-handle'
  8. import { HorizontalToggler } from '@/features/ide-react/components/resize/horizontal-toggler'
  9. import { DefaultSynctexControl } from '@/features/pdf-preview/components/detach-synctex-control'
  10. import PdfPreview from '@/features/pdf-preview/components/pdf-preview'
  11. import { usePdfPane } from '@/features/ide-react/hooks/use-pdf-pane'
  12. import { useLayoutContext } from '@/shared/context/layout-context'
  13. import { useTranslation } from 'react-i18next'
  14. import classNames from 'classnames'
  15. export const EditorAndPdf: FC<{
  16. editorPane: React.ReactNode
  17. selectedEntityCount: number
  18. openEntity: any // TODO
  19. }> = ({ editorPane, selectedEntityCount, openEntity }) => {
  20. const [resizing, setResizing] = useState(false)
  21. const { t } = useTranslation()
  22. const {
  23. togglePdfPane,
  24. handlePdfPaneExpand,
  25. handlePdfPaneCollapse,
  26. setPdfIsOpen,
  27. pdfIsOpen,
  28. pdfPanelRef,
  29. } = usePdfPane()
  30. const { view, pdfLayout } = useLayoutContext()
  31. const editorIsOpen =
  32. view === 'editor' || view === 'file' || pdfLayout === 'sideBySide'
  33. return (
  34. <PanelGroup autoSaveId="ide-editor-pdf-layout" direction="horizontal">
  35. {/* main */}
  36. {editorIsOpen && (
  37. <>
  38. <Panel
  39. id="panel-main"
  40. order={1}
  41. defaultSizePercentage={50}
  42. minSizePercentage={25}
  43. className={classNames('ide-react-panel', {
  44. 'ide-panel-group-resizing': resizing,
  45. })}
  46. >
  47. {selectedEntityCount === 0 && <NoSelectionPane />}
  48. {selectedEntityCount === 1 && openEntity?.type === 'fileRef' && (
  49. <FileView file={fileViewFile(openEntity.entity)} />
  50. )}
  51. {selectedEntityCount === 1 && editorPane}
  52. {selectedEntityCount > 1 && (
  53. <MultipleSelectionPane
  54. selectedEntityCount={selectedEntityCount}
  55. />
  56. )}
  57. </Panel>
  58. <HorizontalResizeHandle
  59. resizable={pdfLayout === 'sideBySide'}
  60. onDoubleClick={togglePdfPane}
  61. onDragging={setResizing}
  62. >
  63. <HorizontalToggler
  64. id="editor-pdf"
  65. togglerType="east"
  66. isOpen={pdfIsOpen}
  67. setIsOpen={setPdfIsOpen}
  68. tooltipWhenOpen={t('tooltip_hide_pdf')}
  69. tooltipWhenClosed={t('tooltip_show_pdf')}
  70. />
  71. {pdfLayout === 'sideBySide' && (
  72. <div className="synctex-controls">
  73. <DefaultSynctexControl />
  74. </div>
  75. )}
  76. </HorizontalResizeHandle>
  77. </>
  78. )}
  79. {/* pdf */}
  80. <Panel
  81. ref={pdfPanelRef}
  82. id="panel-pdf"
  83. order={2}
  84. defaultSizePercentage={50}
  85. minSizePercentage={25}
  86. collapsible
  87. onCollapse={handlePdfPaneCollapse}
  88. onExpand={handlePdfPaneExpand}
  89. className="ide-react-panel"
  90. >
  91. {pdfIsOpen && <PdfPreview />}
  92. </Panel>
  93. </PanelGroup>
  94. )
  95. }