backstage-plugin-techdocs-addon-mermaid 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,10 +34,12 @@ Backstage v1.2+
34
34
  {techDocsPage}
35
35
  <TechDocsAddons>
36
36
  {/*...*/}
37
- <Mermaid config={{ theme: "forest", themeVariables: { lineColor: "#000000" } }} />
37
+ <Mermaid />
38
38
  </TechDocsAddons>
39
39
  ```
40
40
 
41
+ Diagrams follow the Backstage light/dark mode automatically. See [Mermaid Configuration](#mermaid-configuration) to customize them.
42
+
41
43
  - **New Frontend System**: Enable the addon module within `App.tsx`:
42
44
 
43
45
  ```typescript jsx
@@ -76,12 +78,16 @@ graph TD;
76
78
 
77
79
  ## Mermaid Configuration
78
80
 
81
+ Without any configuration, diagrams follow the Backstage theme: they use Mermaid's `default` theme in light mode and its `dark` theme in dark mode.
82
+
79
83
  The plugin supports customizing the Mermaid configuration for light and dark themes, as well as a shared base configuration. The available options are:
80
84
 
81
85
  - `lightConfig` — Mermaid configuration applied when the Backstage theme is set to light mode.
82
- - `darkConfig` — Mermaid configuration applied when the Backstage theme is set to dark mode.
86
+ - `darkConfig` — Mermaid configuration applied when the Backstage theme is set to dark mode. If it doesn't set a `theme`, Mermaid's `dark` theme is used.
83
87
  - `config` — Shared configuration that is deep-merged on top of the selected theme configuration. Values here take precedence over `lightConfig`/`darkConfig`.
84
88
 
89
+ > **Note:** Setting `theme` in `config` applies that theme in both light and dark mode, which turns off the automatic switching. To keep diagrams in step with the Backstage theme, set `theme` in `lightConfig` and `darkConfig` instead, and keep shared settings such as fonts in `config`.
90
+
85
91
  Each option follows this schema:
86
92
 
87
93
  ```typescript
@@ -301,6 +307,32 @@ config:
301
307
 
302
308
  This plugin can be developed in the context of an existing Backstage deployment or a [new local deployment](https://backstage.io/docs/getting-started/#1-create-your-backstage-app).
303
309
 
310
+ ### Releasing to npm
311
+
312
+ The `publish.yml` workflow uses [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
313
+ to authenticate with GitHub Actions OIDC, without an `NPM_TOKEN` secret.
314
+ Before the first automated release, a package maintainer must configure a GitHub Actions
315
+ trusted publisher in the npm package settings with:
316
+
317
+ - Organization or user: `johanneswuerbach`
318
+ - Repository: `backstage-plugin-techdocs-addon-mermaid`
319
+ - Workflow filename: `publish.yml`
320
+ - Environment name: leave empty
321
+ - Allow direct publishing with `npm publish`
322
+
323
+ Once trusted publishing is configured and verified, remove the old `NPM_TOKEN`
324
+ repository secret and revoke the token in npm.
325
+
326
+ To release, merge a version bump in `package.json`, tag that commit as `v<version>`
327
+ (for example, `v0.30.0`), and publish a GitHub release for that tag. Pushing a tag
328
+ alone or saving a draft release does not publish to npm. The workflow checks that
329
+ the tag matches the package version, runs type checks, builds, tests, and packs
330
+ with Yarn before publishing the tarball with npm. Node.js 24 supplies an npm CLI
331
+ that supports trusted publishing (npm 11.5.1 or later).
332
+
333
+ Regular releases use the npm `latest` dist-tag; GitHub prereleases use `next`.
334
+ Use a new package version for each release; npm versions cannot be overwritten.
335
+
304
336
  ### Setup for Deployment
305
337
 
306
338
  1. Fork and clone this repo into the plugins folder of your Backstage codebase.
@@ -1,8 +1,8 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import { useTheme } from '@material-ui/core';
3
3
  import { useShadowRootElements } from '@backstage/plugin-techdocs-react';
4
- import mermaid from 'mermaid';
5
4
  import { isMermaidCode } from './hooks.esm.js';
5
+ import { loadMermaid } from './loadMermaid.esm.js';
6
6
  import { ZoomHandler } from './zoomHandler.esm.js';
7
7
  import { deepMerge } from './utils.esm.js';
8
8
 
@@ -73,7 +73,26 @@ const outermostCandidates = (elements) => {
73
73
  (element) => unique.every((other) => other === element || !other.contains(element))
74
74
  );
75
75
  };
76
- const makeDiagram = async (el, diagramText, properties) => {
76
+ const bindActorMenus = (diagramElement) => {
77
+ diagramElement.querySelectorAll('g.actorPopupMenu[id$="_popup"]').forEach((popup) => {
78
+ if (popup.getAttribute("display") !== "none") {
79
+ return;
80
+ }
81
+ const lifelineId = popup.id.slice(0, -"_popup".length);
82
+ const actor = diagramElement.querySelector(
83
+ `[id="${lifelineId}"]`
84
+ )?.parentElement;
85
+ if (!actor) {
86
+ return;
87
+ }
88
+ actor.removeAttribute("onclick");
89
+ actor.style.cursor = "pointer";
90
+ actor.addEventListener("click", () => {
91
+ popup.style.display = popup.style.display === "block" ? "none" : "block";
92
+ });
93
+ });
94
+ };
95
+ const makeDiagram = async (mermaid, el, diagramText, properties) => {
77
96
  el.style.display = "none";
78
97
  const diagramElement = document.createElement("div");
79
98
  diagramElement.className = "mermaid";
@@ -85,6 +104,7 @@ const makeDiagram = async (el, diagramText, properties) => {
85
104
  const { svg, bindFunctions } = await mermaid.render(id, diagramText);
86
105
  diagramElement.innerHTML = svg;
87
106
  bindFunctions?.(diagramElement);
107
+ bindActorMenus(diagramElement);
88
108
  if (properties.enableZoom) {
89
109
  const svgEl = diagramElement.querySelector("svg");
90
110
  const zoomHandler = new ZoomHandler(
@@ -103,23 +123,40 @@ const makeDiagram = async (el, diagramText, properties) => {
103
123
  const MermaidAddon = (properties) => {
104
124
  const candidates = useShadowRootElements(candidateSelectors);
105
125
  const theme = useTheme();
106
- const [initialized, setInitialized] = useState(false);
126
+ const [mermaid, setMermaid] = useState();
107
127
  useEffect(() => {
108
- if (initialized) {
109
- return;
128
+ if (mermaid) {
129
+ return void 0;
110
130
  }
111
- const config = selectConfig(theme.palette.type, properties);
112
- if (properties.iconLoaders) {
113
- mermaid.registerIconPacks(properties.iconLoaders);
114
- }
115
- if (properties.layoutLoaders) {
116
- mermaid.registerLayoutLoaders(properties.layoutLoaders);
117
- }
118
- mermaid.initialize({ suppressErrorRendering: true, ...config });
119
- setInitialized(true);
120
- }, [initialized, properties, theme.palette.type]);
131
+ let cancelled = false;
132
+ loadMermaid().then(
133
+ (loaded) => {
134
+ if (cancelled) {
135
+ return;
136
+ }
137
+ const config = selectConfig(
138
+ theme.palette.type,
139
+ properties
140
+ );
141
+ if (properties.iconLoaders) {
142
+ loaded.registerIconPacks(properties.iconLoaders);
143
+ }
144
+ if (properties.layoutLoaders) {
145
+ loaded.registerLayoutLoaders(properties.layoutLoaders);
146
+ }
147
+ loaded.initialize({ suppressErrorRendering: true, ...config });
148
+ setMermaid(loaded);
149
+ },
150
+ (error) => {
151
+ console.error("Failed to load mermaid", error);
152
+ }
153
+ );
154
+ return () => {
155
+ cancelled = true;
156
+ };
157
+ }, [mermaid, properties, theme.palette.type]);
121
158
  useEffect(() => {
122
- if (!initialized) {
159
+ if (!mermaid) {
123
160
  return;
124
161
  }
125
162
  outermostCandidates(candidates).forEach((candidate) => {
@@ -136,13 +173,13 @@ const MermaidAddon = (properties) => {
136
173
  if (language && language !== "text") {
137
174
  return;
138
175
  }
139
- if (!isMermaidCode(diagramText)) {
176
+ if (!isMermaidCode(diagramText, mermaid)) {
140
177
  return;
141
178
  }
142
179
  }
143
- makeDiagram(candidate, diagramText, properties);
180
+ makeDiagram(mermaid, candidate, diagramText, properties);
144
181
  });
145
- }, [initialized, candidates, properties]);
182
+ }, [mermaid, candidates, properties]);
146
183
  return null;
147
184
  };
148
185
 
@@ -1 +1 @@
1
- {"version":3,"file":"Mermaid.esm.js","sources":["../../src/Mermaid/Mermaid.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from 'react';\nimport { PaletteType, useTheme } from '@material-ui/core';\n\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport mermaid, { MermaidConfig } from 'mermaid';\nimport { isMermaidCode } from './hooks';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\nimport { ZoomHandler } from './zoomHandler';\nimport { deepMerge } from './utils';\n\nexport function selectConfig(\n backstagePalette: PaletteType,\n properties: MermaidProps,\n): MermaidConfig {\n // Determine the default config based on palette\n const defaultConfig =\n backstagePalette === 'light'\n ? properties.lightConfig || {}\n : Object.assign({ theme: 'dark' }, properties.darkConfig);\n\n // If a config is provided, deep merge it with the default config (user values take precedence)\n if (properties.config) {\n return deepMerge(defaultConfig, properties.config);\n }\n\n return defaultConfig;\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0;\n\nconst candidateSelectors = [\n '.highlighttable',\n '.highlight',\n 'pre.mermaid',\n '.mermaid',\n '.language-mermaid',\n];\nconst lineNumberSelectors = '.linenos, .linenodiv, .lnt';\n\nconst stripLineNumberGutters = (text: string): string => {\n const lines = text.split('\\n');\n if (lines.length < 2) {\n return text.trim();\n }\n\n const stripped: string[] = [];\n for (let index = 0; index < lines.length; index += 1) {\n const expected = String(index + 1);\n const line = lines[index];\n if (line === expected) {\n stripped.push('');\n continue;\n }\n if (line.startsWith(`${expected} `) || line.startsWith(`${expected}\\t`)) {\n stripped.push(line.slice(expected.length + 1));\n continue;\n }\n const nextChar = line.charAt(expected.length);\n if (\n line.startsWith(expected) &&\n nextChar !== '' &&\n /[A-Za-z%]/.test(nextChar)\n ) {\n stripped.push(line.slice(expected.length));\n continue;\n }\n return text.trim();\n }\n return stripped.join('\\n').trim();\n};\n\nconst getDiagramSource = (element: HTMLElement): string => {\n const sourceRoot = element.matches('code')\n ? element\n : (element.querySelector('code') ?? element);\n const clone = sourceRoot.cloneNode(true);\n if (clone instanceof HTMLElement) {\n clone\n .querySelectorAll(lineNumberSelectors)\n .forEach((node) => node.remove());\n }\n return stripLineNumberGutters(clone.textContent ?? '');\n};\n\n/**\n * mkdocs tags a highlighted block with the fence language, either on the\n * wrapper or on the nested `pre`/`code`, e.g. `language-python`. Languages\n * pygments has no lexer for - `mermaid` among them, depending on the mkdocs\n * version - fall back to `language-text`.\n */\nconst languageClassPattern = /(?:^|\\s)language-([\\w-]+)/;\n\nconst declaredLanguage = (element: HTMLElement): string | undefined => {\n const carriers = [element, ...element.querySelectorAll('pre, code')];\n for (const carrier of carriers) {\n const match = languageClassPattern.exec(carrier.className);\n if (match) {\n return match[1];\n }\n }\n return undefined;\n};\n\nconst outermostCandidates = (elements: HTMLElement[]): HTMLElement[] => {\n const unique = [...new Set(elements)];\n return unique.filter((element) =>\n unique.every((other) => other === element || !other.contains(element)),\n );\n};\n\nconst makeDiagram = async (\n el: HTMLElement,\n diagramText: string,\n properties: MermaidProps,\n) => {\n el.style.display = 'none';\n\n const diagramElement = document.createElement('div');\n diagramElement.className = 'mermaid';\n diagramElement.dataset.mermaidRendered = 'true';\n // Clip the element when outside parent when panning\n diagramElement.style.overflow = 'hidden';\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`;\n try {\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg;\n bindFunctions?.(diagramElement);\n\n if (properties.enableZoom) {\n const svgEl = diagramElement.querySelector('svg');\n const zoomHandler = new ZoomHandler(\n diagramElement,\n svgEl as SVGSVGElement,\n properties.zoomOptions,\n );\n zoomHandler.initialize();\n }\n } catch (e) {\n el.style.display = '';\n diagramElement.remove();\n // eslint-disable-next-line no-console\n console.error('Failed to render mermaid diagram', e);\n }\n};\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const candidates = useShadowRootElements<HTMLElement>(candidateSelectors);\n const theme = useTheme<BackstageTheme>();\n\n const [initialized, setInitialized] = useState(false);\n\n useEffect(() => {\n if (initialized) {\n return;\n }\n const config: MermaidConfig = selectConfig(theme.palette.type, properties);\n if (properties.iconLoaders) {\n mermaid.registerIconPacks(properties.iconLoaders);\n }\n if (properties.layoutLoaders) {\n mermaid.registerLayoutLoaders(properties.layoutLoaders);\n }\n mermaid.initialize({ suppressErrorRendering: true, ...config });\n setInitialized(true);\n }, [initialized, properties, theme.palette.type]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n outermostCandidates(candidates).forEach((candidate) => {\n if (\n candidate.style.display === 'none' ||\n candidate.dataset.mermaidRendered === 'true'\n ) {\n return;\n }\n\n const diagramText = getDiagramSource(candidate);\n if (!diagramText) {\n return;\n }\n\n const language = declaredLanguage(candidate);\n const isExplicitMermaid =\n language === 'mermaid' || candidate.matches('pre.mermaid, .mermaid');\n\n if (!isExplicitMermaid) {\n // A block that declares a language is an ordinary code sample. Only\n // undeclared and `text` blocks are guessed at, otherwise snippets that\n // happen to start with `graph`, `info` or `pie` get mistaken for\n // diagrams.\n if (language && language !== 'text') {\n return;\n }\n if (!isMermaidCode(diagramText)) {\n return;\n }\n }\n\n makeDiagram(candidate, diagramText, properties);\n });\n }, [initialized, candidates, properties]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;;;AA2BO,SAAS,YAAA,CACd,kBACA,UAAA,EACe;AAEf,EAAA,MAAM,aAAA,GACJ,gBAAA,KAAqB,OAAA,GACjB,UAAA,CAAW,eAAe,EAAC,GAC3B,MAAA,CAAO,MAAA,CAAO,EAAE,KAAA,EAAO,MAAA,EAAO,EAAG,WAAW,UAAU,CAAA;AAG5D,EAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,IAAA,OAAO,SAAA,CAAU,aAAA,EAAe,UAAA,CAAW,MAAM,CAAA;AAAA,EACnD;AAEA,EAAA,OAAO,aAAA;AACT;AAMA,IAAI,SAAA,GAAY,CAAA;AAEhB,MAAM,kBAAA,GAAqB;AAAA,EACzB,iBAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AACA,MAAM,mBAAA,GAAsB,4BAAA;AAE5B,MAAM,sBAAA,GAAyB,CAAC,IAAA,KAAyB;AACvD,EAAA,MAAM,KAAA,GAAQ,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IAAY,aAAa,MAAA,EAAQ;AACnC,UAAA;AAAA,QACF;AACA,QAAA,IAAI,CAAC,aAAA,CAAc,WAAW,CAAA,EAAG;AAC/B,UAAA;AAAA,QACF;AAAA,MACF;AAEA,MAAA,WAAA,CAAY,SAAA,EAAW,aAAa,UAAU,CAAA;AAAA,IAChD,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,WAAA,EAAa,UAAA,EAAY,UAAU,CAAC,CAAA;AAExC,EAAA,OAAO,IAAA;AACT;;;;"}
1
+ {"version":3,"file":"Mermaid.esm.js","sources":["../../src/Mermaid/Mermaid.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from 'react';\nimport { PaletteType, useTheme } from '@material-ui/core';\n\nimport { useShadowRootElements } from '@backstage/plugin-techdocs-react';\nimport type { MermaidConfig } from 'mermaid';\nimport { isMermaidCode } from './hooks';\nimport { loadMermaid, MermaidApi } from './loadMermaid';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\nimport { ZoomHandler } from './zoomHandler';\nimport { deepMerge } from './utils';\n\nexport function selectConfig(\n backstagePalette: PaletteType,\n properties: MermaidProps,\n): MermaidConfig {\n // Determine the default config based on palette\n const defaultConfig =\n backstagePalette === 'light'\n ? properties.lightConfig || {}\n : Object.assign({ theme: 'dark' }, properties.darkConfig);\n\n // If a config is provided, deep merge it with the default config (user values take precedence)\n if (properties.config) {\n return deepMerge(defaultConfig, properties.config);\n }\n\n return defaultConfig;\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0;\n\nconst candidateSelectors = [\n '.highlighttable',\n '.highlight',\n 'pre.mermaid',\n '.mermaid',\n '.language-mermaid',\n];\nconst lineNumberSelectors = '.linenos, .linenodiv, .lnt';\n\nconst stripLineNumberGutters = (text: string): string => {\n const lines = text.split('\\n');\n if (lines.length < 2) {\n return text.trim();\n }\n\n const stripped: string[] = [];\n for (let index = 0; index < lines.length; index += 1) {\n const expected = String(index + 1);\n const line = lines[index];\n if (line === expected) {\n stripped.push('');\n continue;\n }\n if (line.startsWith(`${expected} `) || line.startsWith(`${expected}\\t`)) {\n stripped.push(line.slice(expected.length + 1));\n continue;\n }\n const nextChar = line.charAt(expected.length);\n if (\n line.startsWith(expected) &&\n nextChar !== '' &&\n /[A-Za-z%]/.test(nextChar)\n ) {\n stripped.push(line.slice(expected.length));\n continue;\n }\n return text.trim();\n }\n return stripped.join('\\n').trim();\n};\n\nconst getDiagramSource = (element: HTMLElement): string => {\n const sourceRoot = element.matches('code')\n ? element\n : (element.querySelector('code') ?? element);\n const clone = sourceRoot.cloneNode(true);\n if (clone instanceof HTMLElement) {\n clone\n .querySelectorAll(lineNumberSelectors)\n .forEach((node) => node.remove());\n }\n return stripLineNumberGutters(clone.textContent ?? '');\n};\n\n/**\n * mkdocs tags a highlighted block with the fence language, either on the\n * wrapper or on the nested `pre`/`code`, e.g. `language-python`. Languages\n * pygments has no lexer for - `mermaid` among them, depending on the mkdocs\n * version - fall back to `language-text`.\n */\nconst languageClassPattern = /(?:^|\\s)language-([\\w-]+)/;\n\nconst declaredLanguage = (element: HTMLElement): string | undefined => {\n const carriers = [element, ...element.querySelectorAll('pre, code')];\n for (const carrier of carriers) {\n const match = languageClassPattern.exec(carrier.className);\n if (match) {\n return match[1];\n }\n }\n return undefined;\n};\n\nconst outermostCandidates = (elements: HTMLElement[]): HTMLElement[] => {\n const unique = [...new Set(elements)];\n return unique.filter((element) =>\n unique.every((other) => other === element || !other.contains(element)),\n );\n};\n\n/**\n * Sequence diagram `links` open a popup menu through an inline `onclick` that\n * calls `document.getElementById`. Mermaid strips that handler unless\n * `securityLevel` is `loose`, and even then it can't reach elements inside the\n * TechDocs shadow root. Bind the toggles here instead, scoped to the diagram.\n */\nconst bindActorMenus = (diagramElement: HTMLElement) => {\n diagramElement\n .querySelectorAll<SVGGElement>('g.actorPopupMenu[id$=\"_popup\"]')\n .forEach((popup) => {\n // `sequence.forceMenus` renders the menus permanently open.\n if (popup.getAttribute('display') !== 'none') {\n return;\n }\n const lifelineId = popup.id.slice(0, -'_popup'.length);\n const actor = diagramElement.querySelector(\n `[id=\"${lifelineId}\"]`,\n )?.parentElement;\n if (!actor) {\n return;\n }\n actor.removeAttribute('onclick');\n actor.style.cursor = 'pointer';\n actor.addEventListener('click', () => {\n popup.style.display =\n popup.style.display === 'block' ? 'none' : 'block';\n });\n });\n};\n\nconst makeDiagram = async (\n mermaid: MermaidApi,\n el: HTMLElement,\n diagramText: string,\n properties: MermaidProps,\n) => {\n el.style.display = 'none';\n\n const diagramElement = document.createElement('div');\n diagramElement.className = 'mermaid';\n diagramElement.dataset.mermaidRendered = 'true';\n // Clip the element when outside parent when panning\n diagramElement.style.overflow = 'hidden';\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`;\n try {\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg;\n bindFunctions?.(diagramElement);\n bindActorMenus(diagramElement);\n\n if (properties.enableZoom) {\n const svgEl = diagramElement.querySelector('svg');\n const zoomHandler = new ZoomHandler(\n diagramElement,\n svgEl as SVGSVGElement,\n properties.zoomOptions,\n );\n zoomHandler.initialize();\n }\n } catch (e) {\n el.style.display = '';\n diagramElement.remove();\n // eslint-disable-next-line no-console\n console.error('Failed to render mermaid diagram', e);\n }\n};\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const candidates = useShadowRootElements<HTMLElement>(candidateSelectors);\n const theme = useTheme<BackstageTheme>();\n\n const [mermaid, setMermaid] = useState<MermaidApi>();\n\n useEffect(() => {\n if (mermaid) {\n return undefined;\n }\n let cancelled = false;\n loadMermaid().then(\n (loaded) => {\n if (cancelled) {\n return;\n }\n const config: MermaidConfig = selectConfig(\n theme.palette.type,\n properties,\n );\n if (properties.iconLoaders) {\n loaded.registerIconPacks(properties.iconLoaders);\n }\n if (properties.layoutLoaders) {\n loaded.registerLayoutLoaders(properties.layoutLoaders);\n }\n loaded.initialize({ suppressErrorRendering: true, ...config });\n setMermaid(loaded);\n },\n (error) => {\n // eslint-disable-next-line no-console\n console.error('Failed to load mermaid', error);\n },\n );\n return () => {\n cancelled = true;\n };\n }, [mermaid, properties, theme.palette.type]);\n\n useEffect(() => {\n if (!mermaid) {\n return;\n }\n\n outermostCandidates(candidates).forEach((candidate) => {\n if (\n candidate.style.display === 'none' ||\n candidate.dataset.mermaidRendered === 'true'\n ) {\n return;\n }\n\n const diagramText = getDiagramSource(candidate);\n if (!diagramText) {\n return;\n }\n\n const language = declaredLanguage(candidate);\n const isExplicitMermaid =\n language === 'mermaid' || candidate.matches('pre.mermaid, .mermaid');\n\n if (!isExplicitMermaid) {\n // A block that declares a language is an ordinary code sample. Only\n // undeclared and `text` blocks are guessed at, otherwise snippets that\n // happen to start with `graph`, `info` or `pie` get mistaken for\n // diagrams.\n if (language && language !== 'text') {\n return;\n }\n if (!isMermaidCode(diagramText, mermaid)) {\n return;\n }\n }\n\n makeDiagram(mermaid, candidate, diagramText, properties);\n });\n }, [mermaid, candidates, properties]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;;;AA4BO,SAAS,YAAA,CACd,kBACA,UAAA,EACe;AAEf,EAAA,MAAM,aAAA,GACJ,gBAAA,KAAqB,OAAA,GACjB,UAAA,CAAW,eAAe,EAAC,GAC3B,MAAA,CAAO,MAAA,CAAO,EAAE,KAAA,EAAO,MAAA,EAAO,EAAG,WAAW,UAAU,CAAA;AAG5D,EAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,IAAA,OAAO,SA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MAAM,WAAA,GAAc,iBAAiB,SAAS,CAAA;AAC9C,MAAA,IAAI,CAAC,WAAA,EAAa;AAChB,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,QAAA,GAAW,iBAAiB,SAAS,CAAA;AAC3C,MAAA,MAAM,iBAAA,GACJ,QAAA,KAAa,SAAA,IAAa,SAAA,CAAU,QAAQ,uBAAuB,CAAA;AAErE,MAAA,IAAI,CAAC,iBAAA,EAAmB;AAKtB,QAAA,IAAI,QAAA,IAAY,aAAa,MAAA,EAAQ;AACnC,UAAA;AAAA,QACF;AACA,QAAA,IAAI,CAAC,aAAA,CAAc,WAAA,EAAa,OAAO,CAAA,EAAG;AACxC,UAAA;AAAA,QACF;AAAA,MACF;AAEA,MAAA,WAAA,CAAY,OAAA,EAAS,SAAA,EAAW,WAAA,EAAa,UAAU,CAAA;AAAA,IACzD,CAAC,CAAA;AAAA,EACH,CAAA,EAAG,CAAC,OAAA,EAAS,UAAA,EAAY,UAAU,CAAC,CAAA;AAEpC,EAAA,OAAO,IAAA;AACT;;;;"}
@@ -1,6 +1,4 @@
1
- import mermaid from 'mermaid';
2
-
3
- const isMermaidCode = (code) => {
1
+ const isMermaidCode = (code, mermaid) => {
4
2
  try {
5
3
  mermaid.detectType(code);
6
4
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.esm.js","sources":["../../src/Mermaid/hooks.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport mermaid from 'mermaid'\n\nexport const isMermaidCode = (code: string): boolean => {\n try {\n mermaid.detectType(code)\n return true\n } catch (_) {\n return false\n }\n};\n"],"names":[],"mappings":";;AAkBO,MAAM,aAAA,GAAgB,CAAC,IAAA,KAA0B;AACtD,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,WAAW,IAAI,CAAA;AACvB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
1
+ {"version":3,"file":"hooks.esm.js","sources":["../../src/Mermaid/hooks.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MermaidApi } from './loadMermaid';\n\nexport const isMermaidCode = (code: string, mermaid: MermaidApi): boolean => {\n try {\n mermaid.detectType(code)\n return true\n } catch (_) {\n return false\n }\n};\n"],"names":[],"mappings":"AAkBO,MAAM,aAAA,GAAgB,CAAC,IAAA,EAAc,OAAA,KAAiC;AAC3E,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,WAAW,IAAI,CAAA;AACvB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
@@ -0,0 +1,14 @@
1
+ let mermaidPromise;
2
+ function loadMermaid() {
3
+ mermaidPromise ??= import('mermaid').then(
4
+ (module) => module.default,
5
+ (error) => {
6
+ mermaidPromise = void 0;
7
+ throw error;
8
+ }
9
+ );
10
+ return mermaidPromise;
11
+ }
12
+
13
+ export { loadMermaid };
14
+ //# sourceMappingURL=loadMermaid.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadMermaid.esm.js","sources":["../../src/Mermaid/loadMermaid.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\ntype MermaidApi = typeof import('mermaid').default;\n\nlet mermaidPromise: Promise<MermaidApi> | undefined;\n\n/**\n * Loads mermaid on first use. Importing it at module top level would put it,\n * at around 500 KB, in the startup bundle of every app that installs this\n * addon, though only TechDocs pages with diagrams need it.\n *\n * A failed load is not cached, so the next render can try again, for example\n * after a network blip.\n */\nexport function loadMermaid(): Promise<MermaidApi> {\n mermaidPromise ??= import('mermaid').then(\n (module) => module.default,\n (error) => {\n mermaidPromise = undefined;\n throw error;\n },\n );\n return mermaidPromise;\n}\n\nexport type { MermaidApi };\n"],"names":[],"mappings":"AAkBA,IAAI,cAAA;AAUG,SAAS,WAAA,GAAmC;AACjD,EAAA,cAAA,KAAmB,OAAO,SAAS,CAAA,CAAE,IAAA;AAAA,IACnC,CAAC,WAAW,MAAA,CAAO,OAAA;AAAA,IACnB,CAAC,KAAA,KAAU;AACT,MAAA,cAAA,GAAiB,MAAA;AACjB,MAAA,MAAM,KAAA;AAAA,IACR;AAAA,GACF;AACA,EAAA,OAAO,cAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backstage-plugin-techdocs-addon-mermaid",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "configSchema": "config.schema.json",
5
5
  "main": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,12 +61,13 @@
61
61
  "tsc:full": "tsc --skipLibCheck false --incremental false"
62
62
  },
63
63
  "dependencies": {
64
- "@backstage/config": "^1.3.8",
65
- "@backstage/core-components": "^0.18.13",
66
- "@backstage/core-plugin-api": "^1.12.9",
67
- "@backstage/frontend-plugin-api": "^0.18.0",
68
- "@backstage/plugin-techdocs-react": "^1.3.14",
69
- "@backstage/theme": "^0.7.3",
64
+ "@backstage/config": "^1.3.11",
65
+ "@backstage/core-components": "^0.18.16",
66
+ "@backstage/core-plugin-api": "^1.13.0",
67
+ "@backstage/frontend-plugin-api": "^1.0.0",
68
+ "@backstage/plugin-techdocs-react": "^1.5.0",
69
+ "@backstage/theme": "^0.7.4",
70
+ "@iconify/types": "^2.0.0",
70
71
  "@material-ui/core": "^4.12.2",
71
72
  "@material-ui/icons": "^4.11.3",
72
73
  "@material-ui/lab": "4.0.0-alpha.61",
@@ -88,14 +89,13 @@
88
89
  }
89
90
  },
90
91
  "devDependencies": {
91
- "@backstage/cli": "^0.36.5",
92
- "@backstage/core-app-api": "^1.20.4",
93
- "@backstage/dev-utils": "^1.1.26",
94
- "@backstage/frontend-test-utils": "^0.6.3",
95
- "@backstage/plugin-techdocs-addons-test-utils": "^2.0.8",
96
- "@backstage/test-utils": "^1.7.21",
92
+ "@backstage/cli": "^0.36.8",
93
+ "@backstage/core-app-api": "^1.20.7",
94
+ "@backstage/dev-utils": "^1.2.0",
95
+ "@backstage/frontend-test-utils": "^1.0.0",
96
+ "@backstage/plugin-techdocs-addons-test-utils": "^2.1.0",
97
+ "@backstage/test-utils": "^1.8.0",
97
98
  "@date-io/core": "^1.3.13",
98
- "@iconify/types": "^2.0.0",
99
99
  "@jest/environment-jsdom-abstract": "^30",
100
100
  "@svgr/core": "^6.0.0",
101
101
  "@testing-library/dom": "^10.0.0",
@@ -103,10 +103,13 @@
103
103
  "@testing-library/react": "^16.0.0",
104
104
  "@testing-library/user-event": "^14.0.0",
105
105
  "@types/d3": "^7.4.3",
106
+ "@types/d3-selection": "*",
107
+ "@types/d3-zoom": "*",
106
108
  "@types/jest": "^30",
107
109
  "@types/jsdom": "^27",
108
110
  "@types/node": "*",
109
111
  "@types/react": "^18.3.12",
112
+ "@types/webpack-env": "^1.15.2",
110
113
  "cross-fetch": "^3.1.5",
111
114
  "jest": "^30",
112
115
  "jsdom": "^27",
@@ -115,7 +118,7 @@
115
118
  "react-dom": "^18.3.1",
116
119
  "react-router-dom": "^6.3.0",
117
120
  "shadow-dom-testing-library": "^1.13.1",
118
- "typescript": "~5.6.0"
121
+ "typescript": "~5.9.0"
119
122
  },
120
123
  "files": [
121
124
  "dist",