import react, { useMemo, useRef } from 'react'; import { CodeMirrorEditorReadOnly, GlobalCodeMirrorEditorKey } from '@growi/editor'; import { throttle } from 'throttle-debounce'; import { useShouldExpandContent } from '~/client/services/layout'; import { useSWRxCurrentPage, useIsLatestRevision } from '~/stores/page'; import { usePreviewOptions } from '~/stores/renderer'; import { EditorNavbar } from './EditorNavbar'; import Preview from './Preview'; import { useScrollSync } from './ScrollSyncHelper'; type Props = { visibility?: boolean, } export const PageEditorReadOnly = react.memo(({ visibility }: Props): JSX.Element => { const previewRef = useRef(null); const { data: currentPage } = useSWRxCurrentPage(); const { data: rendererOptions } = usePreviewOptions(); const { data: isLatestRevision } = useIsLatestRevision(); const shouldExpandContent = useShouldExpandContent(currentPage); const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.READONLY, previewRef); const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]); const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]); const revisionBody = currentPage?.revision?.body; if (rendererOptions == null || isLatestRevision) { return <>; } return (
); });