feat: move first heading title extraction into an app extension

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-04-07 19:42:55 +02:00
parent d8c1e35819
commit 8de8a50bec
17 changed files with 126 additions and 168 deletions

View file

@ -73,16 +73,6 @@ export const IframeMarkdownRenderer: React.FC = () => {
}, [communicator])
)
const onFirstHeadingChange = useCallback(
(firstHeading?: string) => {
communicator.sendMessageToOtherSide({
type: CommunicationMessageType.ON_FIRST_HEADING_CHANGE,
firstHeading
})
},
[communicator]
)
const onMakeScrollSource = useCallback(() => {
sendScrolling.current = true
communicator.sendMessageToOtherSide({
@ -128,7 +118,6 @@ export const IframeMarkdownRenderer: React.FC = () => {
<MarkdownDocument
additionalOuterContainerClasses={'vh-100 bg-light'}
markdownContentLines={markdownContentLines}
onFirstHeadingChange={onFirstHeadingChange}
onMakeScrollSource={onMakeScrollSource}
scrollState={scrollState}
onScroll={onScroll}
@ -141,7 +130,6 @@ export const IframeMarkdownRenderer: React.FC = () => {
<SlideshowMarkdownRenderer
markdownContentLines={markdownContentLines}
baseUrl={baseConfiguration.baseUrl}
onFirstHeadingChange={onFirstHeadingChange}
scrollState={scrollState}
slideOptions={slideOptions}
/>
@ -159,16 +147,7 @@ export const IframeMarkdownRenderer: React.FC = () => {
default:
return null
}
}, [
baseConfiguration,
markdownContentLines,
onFirstHeadingChange,
onHeightChange,
onMakeScrollSource,
onScroll,
scrollState,
slideOptions
])
}, [baseConfiguration, markdownContentLines, onHeightChange, onMakeScrollSource, onScroll, scrollState, slideOptions])
const extensionEventEmitter = useMemo(() => new EventEmitter2({ wildcard: true }), [])

View file

@ -14,7 +14,6 @@ import type { MutableRefObject } from 'react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
export interface RendererProps extends ScrollProps {
onFirstHeadingChange?: (firstHeading: string | undefined) => void
documentRenderPaneRef?: MutableRefObject<HTMLDivElement | null>
markdownContentLines: string[]
onHeightChange?: (height: number) => void
@ -32,12 +31,9 @@ export interface MarkdownDocumentProps extends RendererProps {
*
* @param additionalOuterContainerClasses Additional classes given to the outer container directly
* @param additionalRendererClasses Additional classes given {@link DocumentMarkdownRenderer} directly
* @param onFirstHeadingChange The callback to call when the first heading changes.
* @param onMakeScrollSource The callback to call if a change of the scroll source is requested-
* @param onTaskCheckedChange The callback to call if a task get's checked or unchecked.
* @param baseUrl The base url for the renderer
* @param markdownContentLines The current content of the markdown document.
* @param onImageClick The callback to call if an image is clicked.
* @param onScroll The callback to call if the renderer is scrolling.
* @param scrollState The current {@link ScrollState}
* @param onHeightChange The callback to call if the height of the document changes
@ -47,7 +43,6 @@ export interface MarkdownDocumentProps extends RendererProps {
export const MarkdownDocument: React.FC<MarkdownDocumentProps> = ({
additionalOuterContainerClasses,
additionalRendererClasses,
onFirstHeadingChange,
onMakeScrollSource,
baseUrl,
markdownContentLines,
@ -94,7 +89,6 @@ export const MarkdownDocument: React.FC<MarkdownDocumentProps> = ({
outerContainerRef={rendererRef}
className={`mb-3 ${additionalRendererClasses ?? ''}`}
markdownContentLines={markdownContentLines}
onFirstHeadingChange={onFirstHeadingChange}
onLineMarkerPositionChanged={recalculateLineMarkers}
baseUrl={baseUrl}
newlinesAreBreaks={newlinesAreBreaks}

View file

@ -11,7 +11,6 @@ export enum CommunicationMessageType {
SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT',
RENDERER_READY = 'RENDERER_READY',
SET_DARKMODE = 'SET_DARKMODE',
ON_FIRST_HEADING_CHANGE = 'ON_FIRST_HEADING_CHANGE',
ENABLE_RENDERER_SCROLL_SOURCE = 'ENABLE_RENDERER_SCROLL_SOURCE',
DISABLE_RENDERER_SCROLL_SOURCE = 'DISABLE_RENDERER_SCROLL_SOURCE',
SET_SCROLL_STATE = 'SET_SCROLL_STATE',
@ -72,11 +71,6 @@ export interface SetScrollStateMessage {
scrollState: ScrollState
}
export interface OnFirstHeadingChangeMessage {
type: CommunicationMessageType.ON_FIRST_HEADING_CHANGE
firstHeading: string | undefined
}
export interface SetSlideOptionsMessage {
type: CommunicationMessageType.SET_SLIDE_OPTIONS
slideOptions: SlideOptions
@ -101,7 +95,6 @@ export type CommunicationMessages =
| GetWordCountMessage
| SetMarkdownContentMessage
| SetScrollStateMessage
| OnFirstHeadingChangeMessage
| SetSlideOptionsMessage
| OnHeightChangeMessage
| OnWordCountCalculatedMessage
@ -120,7 +113,6 @@ export type EditorToRendererMessageType =
export type RendererToEditorMessageType =
| CommunicationMessageType.RENDERER_READY
| CommunicationMessageType.ENABLE_RENDERER_SCROLL_SOURCE
| CommunicationMessageType.ON_FIRST_HEADING_CHANGE
| CommunicationMessageType.SET_SCROLL_STATE
| CommunicationMessageType.ON_HEIGHT_CHANGE
| CommunicationMessageType.ON_WORD_COUNT_CALCULATED