pdf-preview-detached-root.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { useDetachCompileContext as useCompileContext } from '@/shared/context/detach-compile-context'
  6. import { useEffect } from 'react'
  7. function PdfPreviewDetachedRoot() {
  8. const { isReady } = useWaitForI18n()
  9. if (!isReady) {
  10. return null
  11. }
  12. return (
  13. <ReactContextRoot>
  14. <PdfPreviewDetachedRootContent />
  15. </ReactContextRoot>
  16. )
  17. }
  18. function PdfPreviewDetachedRootContent() {
  19. const { activeOverallTheme } = useCompileContext()
  20. useEffect(() => {
  21. // NOTE: We cannot use useThemedPage here because we need to read the
  22. // activeOverallTheme value from the compile context
  23. document.body.dataset.theme =
  24. activeOverallTheme === 'dark' ? 'default' : 'light'
  25. }, [activeOverallTheme])
  26. return (
  27. <EditorRedesignWrapper>
  28. <PdfPreview />
  29. </EditorRedesignWrapper>
  30. )
  31. }
  32. function EditorRedesignWrapper({ children }: { children: React.ReactNode }) {
  33. // TODO ide-redesign-cleanup: this wrapper should not be required
  34. return <div className="ide-redesign-main">{children}</div>
  35. }
  36. export default PdfPreviewDetachedRoot // for testing
  37. const element = document.getElementById('pdf-preview-detached-root')
  38. if (element) {
  39. const root = createRoot(element)
  40. root.render(<PdfPreviewDetachedRoot />)
  41. }