pdf-preview-detached-root.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { createRoot } from 'react-dom/client'
  2. import PdfPreview from './pdf-preview'
  3. import useWaitForI18n from '../../../shared/hooks/use-wait-for-i18n'
  4. import { ReactContextRoot } from '@/features/ide-react/context/react-context-root'
  5. import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
  6. function PdfPreviewDetachedRoot() {
  7. const { isReady } = useWaitForI18n()
  8. if (!isReady) {
  9. return null
  10. }
  11. return (
  12. <ReactContextRoot>
  13. <EditorRedesignWrapper>
  14. <PdfPreview />
  15. </EditorRedesignWrapper>
  16. </ReactContextRoot>
  17. )
  18. }
  19. function EditorRedesignWrapper({ children }: { children: React.ReactNode }) {
  20. const newEditorEnabled = useIsNewEditorEnabled()
  21. if (!newEditorEnabled) {
  22. return <>{children}</>
  23. }
  24. // TODO ide-redesign-cleanup: this wrapper should not be required
  25. return <div className="ide-redesign-main">{children}</div>
  26. }
  27. export default PdfPreviewDetachedRoot // for testing
  28. const element = document.getElementById('pdf-preview-detached-root')
  29. if (element) {
  30. const root = createRoot(element)
  31. root.render(<PdfPreviewDetachedRoot />)
  32. }