|
|
@@ -1,20 +1,14 @@
|
|
|
import React, {
|
|
|
- useCallback, useEffect, useMemo, useState, SyntheticEvent, RefObject,
|
|
|
+ SyntheticEvent, RefObject,
|
|
|
} from 'react';
|
|
|
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
|
|
|
|
|
-// import AppContainer from '~/client/services/AppContainer';
|
|
|
-import InterceptorManager from '~/services/interceptor-manager';
|
|
|
import { RendererOptions } from '~/services/renderer/renderer';
|
|
|
import { useEditorSettings } from '~/stores/editor';
|
|
|
|
|
|
import RevisionBody from '../Page/RevisionBody';
|
|
|
-// import { withUnstatedContainers } from '../UnstatedUtils';
|
|
|
-
|
|
|
-
|
|
|
-// declare const interceptorManager: InterceptorManager;
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
@@ -34,60 +28,8 @@ const Preview = React.forwardRef((props: Props, ref: RefObject<HTMLDivElement>):
|
|
|
markdown, pagePath,
|
|
|
} = props;
|
|
|
|
|
|
- const [html, setHtml] = useState('');
|
|
|
-
|
|
|
const { data: editorSettings } = useEditorSettings();
|
|
|
|
|
|
- const context = useMemo(() => {
|
|
|
- return {
|
|
|
- markdown,
|
|
|
- pagePath,
|
|
|
- renderDrawioInRealtime: editorSettings?.renderDrawioInRealtime,
|
|
|
- currentPathname: decodeURIComponent(window.location.pathname),
|
|
|
- // parsedHTML: null,
|
|
|
- parsedHTML: 'dummy text',
|
|
|
- };
|
|
|
- }, [markdown, pagePath, editorSettings?.renderDrawioInRealtime]);
|
|
|
-
|
|
|
- const renderPreview = useCallback(async() => {
|
|
|
-
|
|
|
- // TODO: use ReactMarkdown
|
|
|
-
|
|
|
- // if (interceptorManager != null) {
|
|
|
- // await interceptorManager.process('preRenderPreview', context);
|
|
|
- // await interceptorManager.process('prePreProcess', context);
|
|
|
- // context.markdown = rendererOptions.preProcess(context.markdown, context);
|
|
|
- // await interceptorManager.process('postPreProcess', context);
|
|
|
- // context.parsedHTML = rendererOptions.process(context.markdown, context);
|
|
|
- // await interceptorManager.process('prePostProcess', context);
|
|
|
- // context.parsedHTML = rendererOptions.postProcess(context.parsedHTML, context);
|
|
|
- // await interceptorManager.process('postPostProcess', context);
|
|
|
- // await interceptorManager.process('preRenderPreviewHtml', context);
|
|
|
- // }
|
|
|
-
|
|
|
- setHtml(context.parsedHTML ?? '');
|
|
|
- }, [context, rendererOptions]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- if (markdown == null) {
|
|
|
- setHtml('');
|
|
|
- }
|
|
|
-
|
|
|
- renderPreview();
|
|
|
- }, [markdown, renderPreview]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- if (html == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // if (interceptorManager != null) {
|
|
|
- // interceptorManager.process('postRenderPreviewHtml', {
|
|
|
- // ...context,
|
|
|
- // parsedHTML: html,
|
|
|
- // });
|
|
|
- // }
|
|
|
- }, [context, html]);
|
|
|
|
|
|
return (
|
|
|
<div
|
|
|
@@ -99,7 +41,7 @@ const Preview = React.forwardRef((props: Props, ref: RefObject<HTMLDivElement>):
|
|
|
}
|
|
|
}}
|
|
|
>
|
|
|
- <ReactMarkdown {...rendererOptions} >{html}</ReactMarkdown>
|
|
|
+ <ReactMarkdown {...rendererOptions} >{markdown || ''}</ReactMarkdown>
|
|
|
{/* <RevisionBody
|
|
|
{...props}
|
|
|
html={html}
|
|
|
@@ -112,11 +54,6 @@ const Preview = React.forwardRef((props: Props, ref: RefObject<HTMLDivElement>):
|
|
|
|
|
|
Preview.displayName = 'Preview';
|
|
|
|
|
|
-/**
|
|
|
- * Wrapper component for using unstated
|
|
|
- */
|
|
|
-// const PreviewWrapper = withUnstatedContainers(Preview, [AppContainer]);
|
|
|
-
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
const PreviewWrapper = React.forwardRef((props: Props, ref: RefObject<HTMLDivElement>): JSX.Element => {
|
|
|
return <Preview ref={ref} {...props} />;
|