From bfcb617eeb78996474e195da9fedcdcf6b7d8303 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Thu, 15 Apr 2021 22:04:04 +0200 Subject: [PATCH] Use module build of markmap-lib If we use the default import then webpack will use the "browser" bundle which relies on CDN lazy loading of dependencies. Signed-off-by: Tilman Vatteroth --- package.json | 3 ++- .../markmap/markmap-loader.ts | 21 +++++-------------- src/external-types/markmap-lib/index.d.ts | 9 ++++++++ yarn.lock | 9 +------- 4 files changed, 17 insertions(+), 25 deletions(-) create mode 100644 src/external-types/markmap-lib/index.d.ts diff --git a/package.json b/package.json index 5b09238f1..b2534cc93 100644 --- a/package.json +++ b/package.json @@ -176,6 +176,7 @@ "webpack-bundle-analyzer": "4.4.1" }, "resolutions": { - "cypress": "7.1.0" + "cypress": "7.1.0", + "katex": "0.13.2" } } diff --git a/src/components/markdown-renderer/replace-components/markmap/markmap-loader.ts b/src/components/markdown-renderer/replace-components/markmap/markmap-loader.ts index 282e9ae98..1af51d1a8 100644 --- a/src/components/markdown-renderer/replace-components/markmap/markmap-loader.ts +++ b/src/components/markdown-renderer/replace-components/markmap/markmap-loader.ts @@ -1,26 +1,15 @@ /* - SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - - SPDX-License-Identifier: AGPL-3.0-only + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only */ -import { loadCSS, loadJS } from 'markmap-common' -import { Transformer } from 'markmap-lib' +import { Transformer } from 'markmap-lib/dist/index.esm' import { Markmap } from 'markmap-view' const transformer: Transformer = new Transformer() export const markmapLoader = (svg: SVGSVGElement, code: string): void => { - const { root, features } = transformer.transform(code) - const { styles, scripts } = transformer.getUsedAssets(features) - - if (styles) { - loadCSS(styles) - } - if (scripts) { - loadJS(scripts) - .catch(console.log) - } - + const { root } = transformer.transform(code) Markmap.create(svg, {}, root) } diff --git a/src/external-types/markmap-lib/index.d.ts b/src/external-types/markmap-lib/index.d.ts new file mode 100644 index 000000000..392a025bb --- /dev/null +++ b/src/external-types/markmap-lib/index.d.ts @@ -0,0 +1,9 @@ +/* + * 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' +} diff --git a/yarn.lock b/yarn.lock index 09864ccf2..d8825b6b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9053,20 +9053,13 @@ jsprim@^1.2.2: array-includes "^3.1.2" object.assign "^4.1.2" -katex@0.13.2: +katex@0.13.2, katex@^0.12.0: version "0.13.2" resolved "https://registry.yarnpkg.com/katex/-/katex-0.13.2.tgz#4075b9144e6af992ec9a4b772fa3754763be5f26" integrity sha512-u/KhjFDhyPr+70aiBn9SL/9w/QlLagIXBi2NZSbNnBUp2tR8dCjQplyEMkEzniem5gOeSCBjlBUg4VaiWs1JJg== dependencies: commander "^6.0.0" -katex@^0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/katex/-/katex-0.12.0.tgz#2fb1c665dbd2b043edcf8a1f5c555f46beaa0cb9" - integrity sha512-y+8btoc/CK70XqcHqjxiGWBOeIL8upbS0peTPXTvgrh21n1RiWWcIpSWM+4uXq+IAgNh9YYQWdc7LVDPDAEEAg== - dependencies: - commander "^2.19.0" - khroma@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/khroma/-/khroma-1.3.0.tgz#1a0238ffcce1b049b8c733d5b07850a379aca04a"