Skip to content

Commit

Permalink
Merge pull request #8725 from weseek/fix/144087-144091-use-drawio-in-…
Browse files Browse the repository at this point in the history
…slide-view

fix: Drawio not available with GROWI slides
  • Loading branch information
yuki-takei committed May 13, 2024
2 parents d363770 + ce9679f commit 0bbe98b
Show file tree
Hide file tree
Showing 32 changed files with 271 additions and 361 deletions.
23 changes: 15 additions & 8 deletions apps/app/src/client/services/renderer/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from 'assert';

import { isClient } from '@growi/core/dist/utils/browser-utils';
import * as slides from '@growi/presentation';
import * as refsGrowiDirective from '@growi/remark-attachment-refs/dist/client';
import * as drawio from '@growi/remark-drawio';
// eslint-disable-next-line import/extensions
Expand All @@ -19,7 +18,6 @@ import { DrawioViewerWithEditButton } from '~/components/ReactMarkdownComponents
import { Header } from '~/components/ReactMarkdownComponents/Header';
import { LightBox } from '~/components/ReactMarkdownComponents/LightBox';
import { RichAttachment } from '~/components/ReactMarkdownComponents/RichAttachment';
import { SlideViewer } from '~/components/ReactMarkdownComponents/SlideViewer';
import { TableWithEditButton } from '~/components/ReactMarkdownComponents/TableWithEditButton';
import * as mermaid from '~/features/mermaid';
import { RehypeSanitizeOption } from '~/interfaces/rehype';
Expand Down Expand Up @@ -68,7 +66,6 @@ export const generateViewOptions = (
attachment.remarkPlugin,
lsxGrowiDirective.remarkPlugin,
refsGrowiDirective.remarkPlugin,
[slides.remarkPlugin, { isEnabledMarp: config.isEnabledMarp }],
);
if (config.isEnabledLinebreaks) {
remarkPlugins.push(breaks);
Expand All @@ -84,7 +81,6 @@ export const generateViewOptions = (
drawio.sanitizeOption,
mermaid.sanitizeOption,
attachment.sanitizeOption,
slides.sanitizeOption,
lsxGrowiDirective.sanitizeOption,
refsGrowiDirective.sanitizeOption,
)]
Expand Down Expand Up @@ -119,7 +115,6 @@ export const generateViewOptions = (
components.mermaid = mermaid.MermaidViewer;
components.attachment = RichAttachment;
components.img = LightBox;
components.slide = SlideViewer;
}

if (config.isEnabledXssPrevention) {
Expand Down Expand Up @@ -241,6 +236,21 @@ export const generatePresentationViewOptions = (
// based on simple view options
const options = generateSimpleViewOptions(config, pagePath);

const { rehypePlugins } = options;


const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
addLineNumberAttribute.sanitizeOption,
)]
: () => {};

// add rehype plugins
rehypePlugins.push(
addLineNumberAttribute.rehypePlugin,
rehypeSanitizePlugin,
);

if (config.isEnabledXssPrevention) {
verifySanitizePlugin(options, false);
}
Expand All @@ -262,7 +272,6 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
attachment.remarkPlugin,
lsxGrowiDirective.remarkPlugin,
refsGrowiDirective.remarkPlugin,
[slides.remarkPlugin, { isEnabledMarp: config.isEnabledMarp }],
);
if (config.isEnabledLinebreaks) {
remarkPlugins.push(breaks);
Expand All @@ -281,7 +290,6 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
lsxGrowiDirective.sanitizeOption,
refsGrowiDirective.sanitizeOption,
addLineNumberAttribute.sanitizeOption,
slides.sanitizeOption,
)]
: () => {};

Expand All @@ -306,7 +314,6 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
components.mermaid = mermaid.MermaidViewer;
components.attachment = RichAttachment;
components.img = LightBox;
components.slide = SlideViewer;
}

if (config.isEnabledXssPrevention) {
Expand Down
90 changes: 0 additions & 90 deletions apps/app/src/client/services/renderer/slide-viewer-renderer.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CustomizePresentationSetting = (props: Props): JSX.Element => {
href={`${t('admin:customize_settings.presentation_options.marp_in_gorwi_link')}`}
target="_blank"
rel="noopener noreferrer"
>{`${t('admin:customize_settings.presenattion_options.marp_in_growi')}`}
>{`${t('admin:customize_settings.presentation_options.marp_in_growi')}`}
</a>
</p>
</CustomizePresentationOption>
Expand Down
15 changes: 13 additions & 2 deletions apps/app/src/components/Page/PageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {

import type { IPagePopulatedToShowRevision } from '@growi/core';
import { isUsersHomepage } from '@growi/core/dist/utils/page-path-utils';
import { useSlidesByFrontmatter } from '@growi/presentation/dist/services';
import dynamic from 'next/dynamic';

import { useShouldExpandContent } from '~/client/services/layout';
Expand Down Expand Up @@ -40,6 +41,7 @@ const Comments = dynamic<CommentsProps>(() => import('../Comments').then(mod =>
const UsersHomepageFooter = dynamic<UsersHomepageFooterProps>(() => import('../UsersHomepageFooter')
.then(mod => mod.UsersHomepageFooter), { ssr: false });
const IdenticalPathPage = dynamic(() => import('../IdenticalPathPage').then(mod => mod.IdenticalPathPage), { ssr: false });
const SlideRenderer = dynamic(() => import('./SlideRenderer').then(mod => mod.SlideRenderer), { ssr: false });


type Props = {
Expand Down Expand Up @@ -74,6 +76,10 @@ export const PageView = (props: Props): JSX.Element => {
const shouldExpandContent = useShouldExpandContent(page);


const markdown = page?.revision?.body;
const isSlide = useSlidesByFrontmatter(markdown, rendererConfig.isEnabledMarp);


// *************************** Auto Scroll ***************************
useEffect(() => {
// do nothing if hash is empty
Expand All @@ -90,6 +96,7 @@ export const PageView = (props: Props): JSX.Element => {
}, [isCommentsLoaded]);
// ******************************* end *******************************


const specialContents = useMemo(() => {
if (isIdenticalPathPage) {
return <IdenticalPathPage />;
Expand Down Expand Up @@ -128,15 +135,19 @@ export const PageView = (props: Props): JSX.Element => {
return <NotFoundPage path={pagePath} />;
}

const rendererOptions = viewOptions ?? generateSSRViewOptions(rendererConfig, pagePath);
const markdown = page.revision.body;
const rendererOptions = viewOptions ?? generateSSRViewOptions(rendererConfig, pagePath);

return (
<>
<PageContentsUtilities />

<div className="flex-expand-vert justify-content-between">
<RevisionRenderer rendererOptions={rendererOptions} markdown={markdown} />

{ isSlide != null
? <SlideRenderer marp={isSlide.marp} markdown={markdown} />
: <RevisionRenderer rendererOptions={rendererOptions} markdown={markdown} />
}

{ !isIdenticalPathPage && !isNotFound && (
<div id="comments-container" ref={commentsContainerRef}>
Expand Down
4 changes: 3 additions & 1 deletion apps/app/src/components/Page/RevisionRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
import type { FallbackProps } from 'react-error-boundary';
import { ErrorBoundary } from 'react-error-boundary';
import ReactMarkdown from 'react-markdown';

import type { RendererOptions } from '~/interfaces/renderer-options';
import loggerFactory from '~/utils/logger';

import 'katex/dist/katex.min.css';


const logger = loggerFactory('components:Page:RevisionRenderer');

type Props = {
Expand Down
26 changes: 26 additions & 0 deletions apps/app/src/components/Page/SlideRenderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';

import { usePresentationViewOptions } from '~/stores/renderer';

import { Slides } from '../Presentation/Slides';

type SlideRendererProps = {
markdown: string,
marp?: boolean,
};

export const SlideRenderer = (props: SlideRendererProps): JSX.Element => {

const { markdown, marp = false } = props;

const { data: rendererOptions } = usePresentationViewOptions();

return (
<Slides
hasMarpFlag={marp}
options={{ rendererOptions: rendererOptions as ReactMarkdownOptions }}
>
{markdown}
</Slides>
);
};
20 changes: 15 additions & 5 deletions apps/app/src/components/PageEditor/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { CSSProperties } from 'react';
import React from 'react';

import { useSlidesByFrontmatter } from '@growi/presentation/dist/services';

import type { RendererOptions } from '~/interfaces/renderer-options';
import { useIsEnabledMarp } from '~/stores/context';

import RevisionRenderer from '../Page/RevisionRenderer';

import { SlideRenderer } from '../Page/SlideRenderer';

import styles from './Preview.module.scss';

Expand All @@ -28,17 +30,25 @@ const Preview = (props: Props): JSX.Element => {
expandContentWidth,
} = props;

const { data: isEnabledMarp } = useIsEnabledMarp();
const isSlide = useSlidesByFrontmatter(markdown, isEnabledMarp);

const fluidLayoutClass = expandContentWidth ? 'fluid-layout' : '';


return (
<div
data-testid="page-editor-preview-body"
className={`${moduleClass} ${fluidLayoutClass} ${pagePath === '/Sidebar' ? 'preview-sidebar' : ''}`}
style={style}
>
{ markdown != null && (
<RevisionRenderer rendererOptions={rendererOptions} markdown={markdown}></RevisionRenderer>
) }
{ markdown != null
&& (
isSlide != null
? <SlideRenderer marp={isSlide.marp} markdown={markdown} />
: <RevisionRenderer rendererOptions={rendererOptions} markdown={markdown}></RevisionRenderer>
)
}
</div>
);

Expand Down
11 changes: 7 additions & 4 deletions apps/app/src/components/PagePresentationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback } from 'react';

import type { PresentationProps } from '@growi/presentation';
import type { PresentationProps } from '@growi/presentation/dist/client';
import { useSlidesByFrontmatter } from '@growi/presentation/dist/services';
import { LoadingSpinner } from '@growi/ui/dist/components';
import { useFullScreen } from '@growi/ui/dist/utils';
import dynamic from 'next/dynamic';
Expand Down Expand Up @@ -39,6 +40,10 @@ const PagePresentationModal = (): JSX.Element => {

const { data: isEnabledMarp } = useIsEnabledMarp();

const markdown = currentPage?.revision?.body;

const isSlide = useSlidesByFrontmatter(markdown, isEnabledMarp);

const toggleFullscreenHandler = useCallback(() => {
if (fullscreen.active) {
fullscreen.exit();
Expand All @@ -61,8 +66,6 @@ const PagePresentationModal = (): JSX.Element => {
return <></>;
}

const markdown = currentPage?.revision?.body;

return (
<Modal
isOpen={isOpen}
Expand Down Expand Up @@ -92,7 +95,7 @@ const PagePresentationModal = (): JSX.Element => {
},
isDarkMode,
}}
isEnabledMarp={isEnabledMarp}
marp={isSlide?.marp}
>
{markdown}
</Presentation>
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/Presentation/Presentation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Presentation as PresentationSubstance, type PresentationProps } from '@growi/presentation';
import { Presentation as PresentationSubstance, type PresentationProps } from '@growi/presentation/dist/client';

import '@growi/presentation/dist/style.css';

Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/Presentation/Slides.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Slides as SlidesSubstance, type SlidesProps } from '@growi/presentation';
import { Slides as SlidesSubstance, type SlidesProps } from '@growi/presentation/dist/client';

import '@growi/presentation/dist/style.css';

Expand Down
Loading

0 comments on commit 0bbe98b

Please sign in to comment.