This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update markdown-it-anchor * Update markdown-it-types * Regenerate yarn.lock Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Update dependency vega-embed to v6.15.0 Signed-off-by: Renovate Bot <bot@renovateapp.com> started work on iframe for document-render-pane Signed-off-by: Philip Molares <philip.molares@udo.edu> Fix iframe condition Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add license header Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add render-page and adjust code for it Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add scrolling to toc Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add space to the top of document rendering Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Forward css extra classes in scrolling-document-render-pane.tsx Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> dont use portals to render Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Communicate with iframe Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Hide column if viewport is too small Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Fix rebase issue Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add ready event for child frame Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Simplify method Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add dark mode hook Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Send dark mode messages Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Rename file Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Remove import Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Extract code into hook Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Correct types Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add iswide and dummy log functions Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Add more events Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Open links always in new tabs and correct internal links Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Change iframe to sandbox which can only open one url Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Only open external links in new tab Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Rename component Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Improve path protection Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Lazy load router pages Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Regenerate yarn lock Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Fix callback dependency Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
- Loading branch information
1 parent
5095504
commit 261d80b
Showing
30 changed files
with
516 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/components/editor/document-renderer-pane/document-iframe.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file) | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
import React, { useCallback, useEffect, useRef } from 'react' | ||
import { useIsDarkModeActivated } from '../../../hooks/common/use-is-dark-mode-activated' | ||
import { | ||
EditorToRendererIframeMessage, | ||
postMessageToIframe, | ||
RendererToEditorIframeMessage, | ||
RenderIframeMessageType, | ||
SetDarkModeMessage, | ||
SetMarkdownContentMessage, | ||
SetScrollState, | ||
SetWideMessage | ||
} from '../../render-page/rendering-message' | ||
import { useWindowMessageEventListener } from '../../render-page/use-window-message-event-listener' | ||
import { ScrollingDocumentRenderPaneProps } from './scrolling-document-render-pane' | ||
|
||
export const DocumentIframe: React.FC<ScrollingDocumentRenderPaneProps> = ({ markdownContent, onTaskCheckedChange, onMetadataChange, scrollState, onFirstHeadingChange, wide,onScroll, onMakeScrollSource}) => { | ||
const frameReference = useRef<HTMLIFrameElement>(null) | ||
const darkMode = useIsDarkModeActivated() | ||
|
||
const postMessage = useCallback((message: EditorToRendererIframeMessage) => { | ||
if (!frameReference.current?.contentWindow) { | ||
return | ||
} | ||
postMessageToIframe(frameReference.current.contentWindow, message) | ||
}, []) | ||
|
||
const sendMarkdown = useCallback(() => { | ||
const message: SetMarkdownContentMessage = { | ||
type: RenderIframeMessageType.MARKDOWN_CONTENT, | ||
content: markdownContent | ||
} | ||
postMessage(message) | ||
}, [markdownContent, postMessage]) | ||
|
||
useEffect(() => { | ||
sendMarkdown() | ||
}, [markdownContent, sendMarkdown]) | ||
|
||
useEffect(() => { | ||
const message: SetDarkModeMessage = { | ||
type: RenderIframeMessageType.DARKMODE, | ||
activated: darkMode | ||
} | ||
postMessage(message) | ||
}, [darkMode, postMessage]) | ||
|
||
useEffect(() => { | ||
if (!scrollState) { | ||
return | ||
} | ||
const message: SetScrollState = { | ||
type: RenderIframeMessageType.SET_SCROLL_STATE, | ||
scrollState | ||
} | ||
postMessage(message) | ||
}, [postMessage, scrollState]) | ||
|
||
useEffect(() => { | ||
const message: SetWideMessage = { | ||
type: RenderIframeMessageType.SET_WIDE, | ||
activated: wide ?? false | ||
} | ||
postMessage(message) | ||
}, [wide, postMessage]) | ||
|
||
const processMessage = useCallback((event: MessageEvent<RendererToEditorIframeMessage>) => { | ||
const renderMessage = event.data | ||
switch (renderMessage.type) { | ||
case RenderIframeMessageType.RENDERER_READY: | ||
sendMarkdown() | ||
break | ||
case RenderIframeMessageType.ON_MAKE_SCROLL_SOURCE: | ||
if (onMakeScrollSource) { | ||
onMakeScrollSource(); | ||
} | ||
break; | ||
case RenderIframeMessageType.ON_FIRST_HEADING_CHANGE: | ||
if (onFirstHeadingChange) { | ||
onFirstHeadingChange(renderMessage.firstHeading); | ||
} | ||
break; | ||
case RenderIframeMessageType.ON_TASK_CHECKBOX_CHANGE: | ||
if (onTaskCheckedChange) { | ||
onTaskCheckedChange(renderMessage.lineInMarkdown, renderMessage.checked); | ||
} | ||
break; | ||
case RenderIframeMessageType.ON_META_DATA_CHANGE: | ||
if(onMetadataChange) { | ||
onMetadataChange(renderMessage.metaData); | ||
} | ||
break | ||
case RenderIframeMessageType.SET_SCROLL_STATE: | ||
if (onScroll) { | ||
onScroll(renderMessage.scrollState) | ||
} | ||
} | ||
}, [onFirstHeadingChange, onMakeScrollSource, onMetadataChange, onScroll, onTaskCheckedChange, sendMarkdown]) | ||
|
||
useWindowMessageEventListener(processMessage); | ||
|
||
const onLoad = useCallback(() => { | ||
if (!frameReference.current || !frameReference.current.contentWindow) { | ||
return | ||
} | ||
const frameWindow = frameReference.current.contentWindow; | ||
try { | ||
if (frameWindow.location.origin !== window.location.origin && frameWindow.location.pathname !== '/render') { | ||
frameReference.current.src = '/render' | ||
} | ||
} catch { | ||
frameReference.current.src = '/render' | ||
} | ||
}, []) | ||
|
||
return ( | ||
<iframe sandbox={'allow-same-origin allow-scripts allow-popups'} onLoad={onLoad} title="render" src={'/render'} ref={frameReference} className={"h-100 w-100 border-0"}/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.