Preview.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { CSSProperties, JSX } from 'react';
  2. import { useEditorGuideModal } from '@growi/editor/dist/client/stores/use-editor-guide-modal';
  3. import { useSlidesByFrontmatter } from '@growi/presentation/dist/services';
  4. import RevisionRenderer from '~/components/PageView/RevisionRenderer';
  5. import type { RendererOptions } from '~/interfaces/renderer-options';
  6. import { useIsEnabledMarp } from '~/stores-universal/context';
  7. import { SlideRenderer } from '../Page/SlideRenderer';
  8. import { EditorGuideModal } from './EditorGuideModal';
  9. import styles from './Preview.module.scss';
  10. const moduleClass = styles['page-editor-preview-body'] ?? '';
  11. type Props = {
  12. rendererOptions: RendererOptions,
  13. markdown?: string,
  14. pagePath?: string | null,
  15. expandContentWidth?: boolean,
  16. style?: CSSProperties,
  17. onScroll?: (scrollTop: number) => void,
  18. }
  19. const Preview = (props: Props): JSX.Element => {
  20. const {
  21. rendererOptions,
  22. markdown, pagePath, style,
  23. expandContentWidth,
  24. } = props;
  25. const { data: isEnabledMarp } = useIsEnabledMarp();
  26. const isSlide = useSlidesByFrontmatter(markdown, isEnabledMarp);
  27. const fluidLayoutClass = expandContentWidth ? 'fluid-layout' : '';
  28. const { data: editorGuideModalStatus, close: closeEditorGuideModal } = useEditorGuideModal();
  29. return (
  30. <div
  31. data-testid="page-editor-preview-body"
  32. className={`${moduleClass} ${fluidLayoutClass} ${pagePath === '/Sidebar' ? 'preview-sidebar' : ''} position-relative`}
  33. style={style}
  34. >
  35. <EditorGuideModal
  36. isOpen={editorGuideModalStatus?.isOpened ?? false}
  37. onClose={closeEditorGuideModal}
  38. />
  39. { markdown != null
  40. && (
  41. isSlide != null
  42. ? <SlideRenderer marp={isSlide.marp} markdown={markdown} />
  43. : <RevisionRenderer rendererOptions={rendererOptions} markdown={markdown}></RevisionRenderer>
  44. )
  45. }
  46. </div>
  47. );
  48. };
  49. export default Preview;