editor-sidebar.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Panel, PanelGroup } from 'react-resizable-panels'
  2. import { VerticalResizeHandle } from '@/features/ide-react/components/resize/vertical-resize-handle'
  3. import { FileTree } from '@/features/ide-react/components/file-tree'
  4. import classNames from 'classnames'
  5. import { useLayoutContext } from '@/shared/context/layout-context'
  6. import { OutlineContainer } from '@/features/outline/components/outline-container'
  7. import { useOutlinePane } from '@/features/ide-react/hooks/use-outline-pane'
  8. import React, { ElementType } from 'react'
  9. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  10. const editorSidebarComponents = importOverleafModules(
  11. 'editorSidebarComponents'
  12. ) as { import: { default: ElementType }; path: string }[]
  13. export default function EditorSidebar() {
  14. const { view } = useLayoutContext()
  15. const { outlineEnabled, outlinePanelRef } = useOutlinePane()
  16. return (
  17. <aside
  18. className={classNames('ide-react-editor-sidebar', {
  19. hidden: view === 'history',
  20. })}
  21. >
  22. {editorSidebarComponents.map(
  23. ({ import: { default: Component }, path }) => (
  24. <Component key={path} />
  25. )
  26. )}
  27. <PanelGroup autoSaveId="ide-editor-sidebar-layout" direction="vertical">
  28. <Panel
  29. defaultSize={50}
  30. minSize={25}
  31. className="ide-react-file-tree-panel"
  32. id="panel-file-tree"
  33. order={1}
  34. >
  35. <FileTree />
  36. </Panel>
  37. <VerticalResizeHandle disabled={!outlineEnabled} />
  38. <Panel
  39. defaultSize={50}
  40. maxSize={75}
  41. id="panel-outline"
  42. order={2}
  43. collapsible
  44. ref={outlinePanelRef}
  45. style={{ minHeight: 32 }} // keep the header visible
  46. >
  47. <OutlineContainer />
  48. </Panel>
  49. </PanelGroup>
  50. </aside>
  51. )
  52. }