Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Drawio not available with GROWI slides #8725

Merged
merged 44 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d9eb941
dont use slideviewer and renderers
reiji-h Apr 12, 2024
eaa7374
remove slide in renderer
reiji-h Apr 12, 2024
15f3bdc
slide presentation
reiji-h Apr 12, 2024
01d574a
add to switch slide type
reiji-h Apr 12, 2024
955f61b
global regexp
reiji-h Apr 12, 2024
cfda00d
use hook
reiji-h Apr 12, 2024
2129a1e
fix export problem
reiji-h Apr 12, 2024
1a20fd0
clean code export
reiji-h Apr 12, 2024
323d425
use presentation view options directly
reiji-h Apr 16, 2024
be5b1fd
fix typo
reiji-h Apr 16, 2024
cee266b
enable slide
reiji-h Apr 16, 2024
b606736
clean code
reiji-h Apr 16, 2024
9a2652d
Merge branch 'master' into fix/144087-144091-use-drawio-in-slide-view
reiji-h Apr 17, 2024
5bdbb4b
Merge branch 'master' into fix/144087-144091-use-drawio-in-slide-view
reiji-h Apr 23, 2024
ba9326f
use until now
reiji-h Apr 23, 2024
bfde8a9
fix import
reiji-h Apr 23, 2024
3906352
fix code
reiji-h Apr 23, 2024
b3e66b3
dont use parseFrontmatter
reiji-h Apr 23, 2024
83a0f2c
use from apps/app
reiji-h Apr 23, 2024
9b7abce
clean code
reiji-h Apr 23, 2024
092f4c0
fix code to use marp presentation
reiji-h Apr 23, 2024
72452bc
remove slideviewer switch in revisionrenderer
reiji-h Apr 26, 2024
d48b394
change to parse.ts path
reiji-h Apr 26, 2024
6323606
clean code
reiji-h Apr 26, 2024
6c0d128
switch slide or reactmarkdown
reiji-h Apr 30, 2024
b29832c
clean code
reiji-h Apr 30, 2024
2589ef1
clean code
reiji-h Apr 30, 2024
35bff91
clean code
reiji-h Apr 30, 2024
2ce8e5d
clean code
reiji-h Apr 30, 2024
4eec933
use dynamic
reiji-h Apr 30, 2024
7361a8b
Merge branch 'master' into fix/144087-144091-use-drawio-in-slide-view
reiji-h Apr 30, 2024
11b84ec
update SlideViewer path
reiji-h May 7, 2024
de93c14
Rename renderer
reiji-h May 7, 2024
555b450
use RevisionRenderer in pageviews
reiji-h May 7, 2024
7e1587a
Merge branch 'master' into fix/144087-144091-use-drawio-in-slide-view
reiji-h May 8, 2024
d6eff20
can render ssr
reiji-h May 8, 2024
a5a6d0a
Revert "can render ssr"
reiji-h May 8, 2024
d54f72f
wip: avoid ssr
reiji-h May 13, 2024
745fd8f
re-organize packages
yuki-takei May 13, 2024
4e3ea33
re-organize exports
yuki-takei May 13, 2024
bec2809
refactor SlideRenderer
yuki-takei May 13, 2024
0a4b382
fix lint error
yuki-takei May 13, 2024
074ef5a
implement as a hook
yuki-takei May 13, 2024
ce9679f
import packages dynamically
yuki-takei May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RevisionRenderer は Comment や CustomSidebar からも使われているので、このコンポーネントに SlideViewer との切り替え機能を持たせるのは不適切

Copy link
Contributor Author

@reiji-h reiji-h Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらの対応として現在次の方法を考えています。

  1. RevisionRenderer 内で切り替える
    • RendererOptions に新たに isEnableSlide: boolean 等のスライドを使用できるか判別する key を導入して、今回同様 RevisionRenderer で判別、切り替えを行う。
  2. RevisionRenderer を使用するコンポーネントで切り替える。
    • 例えば PageEditor, PageView 等は RevisionRenderer を使用しているが、スライドを使用できるため、これらに切り替えの機能をもたせる。Comment 等はそのまま SlideViewer を用いる。

どちらの方が良い or それ以外の方法の方が良い等教えていただければ幸いです。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2がよいです

Copy link
Contributor Author

@reiji-h reiji-h Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 で実装しました。
もともとスライドが使用可能だった rendererOptions は useViewOpitons と usePreviewOptions が返すものであり、前者は PageView.tsx と ShareLinkPageView.tsx が使用、後者は最終的に Preview.tsx のみにおいて使用されていました。よってこれら3つのファイルで切り替えをするようにしました。
ですが、PageView.tsx と ShareLinkPageView.tsx についてはこれらから直接 @growi/presentation を使用するとサーバーサイドからの import になるのかエラーが起こるので、dynamic import するコンポーネント ViewRenderer を噛ます形にしています。

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
Loading