Remove markmap

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-09-09 23:13:10 +02:00
parent a3ba067e94
commit eea861a33e
12 changed files with 38 additions and 807 deletions

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -8,8 +8,6 @@ import type { MutableRefObject } from 'react'
import { useMemo, useRef } from 'react'
import { TableOfContentsMarkdownExtension } from '../markdown-extension/table-of-contents-markdown-extension'
import { VegaLiteMarkdownExtension } from '../markdown-extension/vega-lite/vega-lite-markdown-extension'
//TODO: fix dependency issues in markmap
//import { MarkmapMarkdownExtension } from '../markdown-extension/markmap/markmap-markdown-extension'
import { LinemarkerMarkdownExtension } from '../markdown-extension/linemarker/linemarker-markdown-extension'
import { GistMarkdownExtension } from '../markdown-extension/gist/gist-markdown-extension'
import { YoutubeMarkdownExtension } from '../markdown-extension/youtube/youtube-markdown-extension'
@ -70,7 +68,6 @@ export const useMarkdownExtensions = (
new TableOfContentsMarkdownExtension((ast?: TocAst) => (toc.current = ast)),
...additionalExtensions,
new VegaLiteMarkdownExtension(),
// new MarkmapMarkdownExtension(),
new LinemarkerMarkdownExtension(
currentLineMarkers ? (lineMarkers) => (currentLineMarkers.current = lineMarkers) : undefined
),

View file

@ -1,83 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { LockButton } from '../../../common/lock-button/lock-button'
import { Logger } from '../../../../utils/logger'
import { cypressId } from '../../../../utils/cypress-attribute'
import type { CodeProps } from '../../replace-components/code-block-component-replacer'
const log = new Logger('MarkmapFrame')
const blockHandler = (event: Event): void => {
event.stopPropagation()
}
/**
* Renders a markmap diagram.
*
* @param code The code for the diagram.
* @see https://markmap.js.org/
*/
export const MarkmapFrame: React.FC<CodeProps> = ({ code }) => {
const { t } = useTranslation()
const diagramContainer = useRef<HTMLDivElement>(null)
const [disablePanAndZoom, setDisablePanAndZoom] = useState(true)
useEffect(() => {
if (diagramContainer.current) {
if (disablePanAndZoom) {
diagramContainer.current.addEventListener('wheel', blockHandler, true)
diagramContainer.current.addEventListener('mousedown', blockHandler, true)
diagramContainer.current.addEventListener('click', blockHandler, true)
diagramContainer.current.addEventListener('dblclick', blockHandler, true)
diagramContainer.current.addEventListener('touchstart', blockHandler, true)
} else {
diagramContainer.current.removeEventListener('wheel', blockHandler, true)
diagramContainer.current.removeEventListener('mousedown', blockHandler, true)
diagramContainer.current.removeEventListener('click', blockHandler, true)
diagramContainer.current.removeEventListener('dblclick', blockHandler, true)
diagramContainer.current.removeEventListener('touchstart', blockHandler, true)
}
}
}, [diagramContainer, disablePanAndZoom])
useEffect(() => {
if (!diagramContainer.current) {
return
}
const actualContainer = diagramContainer.current
import(/* webpackChunkName: "markmap" */ './markmap-loader')
.then(({ markmapLoader }) => {
try {
const svg: SVGSVGElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.setAttribute('width', '100%')
actualContainer.querySelectorAll('svg').forEach((child) => child.remove())
actualContainer.appendChild(svg)
markmapLoader(svg, code)
} catch (error) {
log.error(error)
}
})
.catch((error: Error) => {
log.error('Error while loading markmap', error)
})
}, [code])
return (
<div {...cypressId('markmap')} className={'position-relative'}>
<div className={'svg-container'} ref={diagramContainer} />
<div className={'text-right button-inside'}>
<LockButton
locked={disablePanAndZoom}
onLockedChanged={(newState) => setDisablePanAndZoom(newState)}
title={disablePanAndZoom ? t('renderer.markmap.locked') : t('renderer.markmap.unlocked')}
/>
</div>
</div>
)
}

View file

@ -1,21 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Transformer } from 'markmap-lib/dist/index.esm'
import { Markmap } from 'markmap-view'
const transformer: Transformer = new Transformer()
/**
* Renders the given markdown code into the given Dom element using {@link Markmap markmap}.
*
* @param svg The dom element to render into.
* @param code The diagram code.
*/
export const markmapLoader = (svg: SVGSVGElement, code: string): void => {
const { root } = transformer.transform(code)
Markmap.create(svg, {}, root)
}

View file

@ -1,19 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { CodeBlockComponentReplacer } from '../../replace-components/code-block-component-replacer'
import type { ComponentReplacer } from '../../replace-components/component-replacer'
import { MarkmapFrame } from './markmap-frame'
import { CodeBlockMarkdownExtension } from '../code-block-markdown-extension/code-block-markdown-extension'
/**
* Adds support for markmap to the markdown rendering using code fences with "markmap" as language.
*/
export class MarkmapMarkdownExtension extends CodeBlockMarkdownExtension {
public buildReplacers(): ComponentReplacer[] {
return [new CodeBlockComponentReplacer(MarkmapFrame, 'markmap')]
}
}

View file

@ -1,9 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
declare module 'markmap-lib/dist/index.esm' {
export * from 'markmap-lib'
}

File diff suppressed because one or more lines are too long