backstage-plugin-techdocs-addon-mermaid 0.21.0 → 0.21.5

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.
@@ -3,6 +3,7 @@ import { useTheme } from '@material-ui/core';
3
3
  import { useShadowRootElements } from '@backstage/plugin-techdocs-react';
4
4
  import mermaid from 'mermaid';
5
5
  import { isMermaidCode } from './hooks.esm.js';
6
+ import { ZoomHandler } from './zoomHandler.esm.js';
6
7
 
7
8
  function selectConfig(backstagePalette, properties) {
8
9
  if (properties.config) {
@@ -14,7 +15,7 @@ function selectConfig(backstagePalette, properties) {
14
15
  return Object.assign({ theme: "dark" }, properties.darkConfig);
15
16
  }
16
17
  let diagramId = 0;
17
- const makeDiagram = async (el, diagramText) => {
18
+ const makeDiagram = async (el, diagramText, properties) => {
18
19
  el.style.display = "none";
19
20
  const diagramElement = document.createElement("div");
20
21
  diagramElement.className = "mermaid";
@@ -23,6 +24,18 @@ const makeDiagram = async (el, diagramText) => {
23
24
  const { svg, bindFunctions } = await mermaid.render(id, diagramText);
24
25
  diagramElement.innerHTML = svg;
25
26
  bindFunctions?.(diagramElement);
27
+ if (properties.enableZoom) {
28
+ const svgEl = diagramElement.querySelector("svg");
29
+ if (svgEl) {
30
+ const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
31
+ while (svgEl.firstChild) {
32
+ g.appendChild(svgEl.firstChild);
33
+ }
34
+ svgEl.appendChild(g);
35
+ const zoomHandler = new ZoomHandler(svgEl, g, properties.zoomOptions);
36
+ zoomHandler.initialize();
37
+ }
38
+ }
26
39
  };
27
40
  const MermaidAddon = (properties) => {
28
41
  const highlightTables = useShadowRootElements([".highlighttable"]);
@@ -35,9 +48,15 @@ const MermaidAddon = (properties) => {
35
48
  return;
36
49
  }
37
50
  const config = selectConfig(theme.palette.type, properties);
51
+ if (properties.iconLoaders) {
52
+ mermaid.registerIconPacks(properties.iconLoaders);
53
+ }
54
+ if (properties.layoutLoaders) {
55
+ mermaid.registerLayoutLoaders(properties.layoutLoaders);
56
+ }
38
57
  mermaid.initialize(config);
39
58
  setInitialized(true);
40
- }, [initialized]);
59
+ }, [initialized, properties, theme.palette.type]);
41
60
  useEffect(() => {
42
61
  if (!initialized) {
43
62
  return;
@@ -57,9 +76,9 @@ const MermaidAddon = (properties) => {
57
76
  if (!isMermaidCode(diagramText)) {
58
77
  return;
59
78
  }
60
- makeDiagram(highlightTable, diagramText);
79
+ makeDiagram(highlightTable, diagramText, properties);
61
80
  });
62
- }, [initialized, highlightTables]);
81
+ }, [initialized, highlightTables, properties]);
63
82
  useEffect(() => {
64
83
  if (!initialized) {
65
84
  return;
@@ -83,9 +102,9 @@ const MermaidAddon = (properties) => {
83
102
  if (!isMermaidCode(diagramText)) {
84
103
  return;
85
104
  }
86
- makeDiagram(highlightDiv, diagramText);
105
+ makeDiagram(highlightDiv, diagramText, properties);
87
106
  });
88
- }, [initialized, highlightDivs]);
107
+ }, [initialized, highlightDivs, properties]);
89
108
  useEffect(() => {
90
109
  if (!initialized) {
91
110
  return;
@@ -99,9 +118,9 @@ const MermaidAddon = (properties) => {
99
118
  return;
100
119
  }
101
120
  const diagramText = codeBlock.textContent || "";
102
- makeDiagram(mermaidPreBlock, diagramText);
121
+ makeDiagram(mermaidPreBlock, diagramText, properties);
103
122
  });
104
- }, [initialized, mermaidPreBlocks]);
123
+ }, [initialized, mermaidPreBlocks, properties]);
105
124
  return null;
106
125
  };
107
126
 
@@ -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 from 'mermaid'\nimport { isMermaidCode } from './hooks';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\nimport { MermaidConfig } from 'mermaid';\n\nexport function selectConfig(backstagePalette: PaletteType, properties: MermaidProps): MermaidConfig {\n // Theme set directly in the Mermaid configuration takes\n // precedence for backwards-compatibility\n if(properties.config) {\n return properties.config;\n }\n\n if(backstagePalette === 'light') {\n return properties.lightConfig || {};\n }\n\n return Object.assign({ theme: 'dark' }, properties.darkConfig);\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0\n\nconst makeDiagram = async (el: HTMLDivElement | HTMLPreElement, diagramText: string) => {\n el.style.display = 'none'\n\n const diagramElement = document.createElement('div')\n diagramElement.className = \"mermaid\"\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg\n bindFunctions?.(diagramElement);\n}\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const highlightTables = useShadowRootElements<HTMLDivElement>(['.highlighttable']);\n const highlightDivs = useShadowRootElements<HTMLDivElement>(['.highlight']);\n const mermaidPreBlocks = useShadowRootElements<HTMLPreElement>(['.mermaid']);\n const theme = useTheme<BackstageTheme>();\n \n\n const [ initialized, setInitialized ] = useState(false);\n\n useEffect(() => {\n if (initialized) {\n return;\n }\n const config = selectConfig(theme.palette.type, properties);\n mermaid.initialize(config);\n setInitialized(true);\n }, [initialized]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n highlightTables.forEach(highlightTable => {\n if (!highlightTable.classList.contains('language-text')) {\n return;\n }\n\n // Skip already processed\n if (highlightTable.style.display === 'none') {\n return\n }\n\n const codeBlock = highlightTable.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n makeDiagram(highlightTable, diagramText)\n });\n }, [initialized, highlightTables]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n highlightDivs.forEach(highlightDiv => {\n if (!highlightDiv.classList.contains('language-text')) {\n return;\n }\n\n // Skip already processed\n if (highlightDiv.style.display === 'none') {\n return\n }\n\n // skip mkdocs-material < 9 code blocks (handled above)\n const table = highlightDiv.querySelector('table')\n if (!table) {\n return\n }\n\n const codeBlock = highlightDiv.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n makeDiagram(highlightDiv, diagramText)\n });\n }, [initialized, highlightDivs]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n mermaidPreBlocks.forEach(mermaidPreBlock => {\n // Skip already processed\n if (mermaidPreBlock.style.display === 'none') {\n return\n }\n\n const codeBlock = mermaidPreBlock.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n makeDiagram(mermaidPreBlock, diagramText)\n });\n }, [initialized, mermaidPreBlocks]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;AA0BgB,SAAA,YAAA,CAAa,kBAA+B,UAAyC,EAAA;AAGnG,EAAA,IAAG,WAAW,MAAQ,EAAA;AACpB,IAAA,OAAO,UAAW,CAAA,MAAA,CAAA;AAAA,GACpB;AAEA,EAAA,IAAG,qBAAqB,OAAS,EAAA;AAC/B,IAAO,OAAA,UAAA,CAAW,eAAe,EAAC,CAAA;AAAA,GACpC;AAEA,EAAA,OAAO,OAAO,MAAO,CAAA,EAAE,OAAO,MAAO,EAAA,EAAG,WAAW,UAAU,CAAA,CAAA;AAC/D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../../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';\n\nexport function selectConfig(backstagePalette: PaletteType, properties: MermaidProps): MermaidConfig {\n // Theme set directly in the Mermaid configuration takes\n // precedence for backwards-compatibility\n if(properties.config) {\n return properties.config;\n }\n\n if(backstagePalette === 'light') {\n return properties.lightConfig || {};\n }\n\n return Object.assign({ theme: 'dark' }, properties.darkConfig);\n}\n\n/**\n * Show report issue button when text is highlighted\n */\n\nlet diagramId = 0\n\nconst makeDiagram = async (el: HTMLDivElement | HTMLPreElement, diagramText: string, properties: MermaidProps,) => {\n el.style.display = 'none'\n\n const diagramElement = document.createElement('div')\n diagramElement.className = \"mermaid\"\n\n el.parentNode?.insertBefore(diagramElement, el.nextSibling);\n\n const id = `mermaid-${diagramId++}`\n const { svg, bindFunctions } = await mermaid.render(id, diagramText);\n diagramElement.innerHTML = svg\n bindFunctions?.(diagramElement);\n \n // If zoom is enabled, wrap the SVG in a <g> and hook up D3.zoom()\n if (properties.enableZoom) {\n const svgEl = diagramElement.querySelector('svg');\n if (svgEl) {\n // 1) Move all existing nodes into one <g>\n const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');\n while (svgEl.firstChild) {\n g.appendChild(svgEl.firstChild);\n }\n svgEl.appendChild(g);\n\n // Initialize zoom handler\n const zoomHandler = new ZoomHandler(svgEl as SVGSVGElement, g, properties.zoomOptions);\n zoomHandler.initialize();\n }\n }\n}\n\nexport const MermaidAddon = (properties: MermaidProps) => {\n const highlightTables = useShadowRootElements<HTMLDivElement>(['.highlighttable']);\n const highlightDivs = useShadowRootElements<HTMLDivElement>(['.highlight']);\n const mermaidPreBlocks = useShadowRootElements<HTMLPreElement>(['.mermaid']);\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(config);\n setInitialized(true);\n }, [initialized, properties, theme.palette.type]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n highlightTables.forEach(highlightTable => {\n if (!highlightTable.classList.contains('language-text')) {\n return;\n }\n\n // Skip already processed\n if (highlightTable.style.display === 'none') {\n return\n }\n\n const codeBlock = highlightTable.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n makeDiagram(highlightTable, diagramText, properties)\n });\n }, [initialized, highlightTables, properties]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n highlightDivs.forEach(highlightDiv => {\n if (!highlightDiv.classList.contains('language-text')) {\n return;\n }\n\n // Skip already processed\n if (highlightDiv.style.display === 'none') {\n return\n }\n\n // skip mkdocs-material < 9 code blocks (handled above)\n const table = highlightDiv.querySelector('table')\n if (!table) {\n return\n }\n\n const codeBlock = highlightDiv.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n // Ideally we could detect mermaid based on some annotation, but use a regex for now\n if (!isMermaidCode(diagramText)) {\n return\n }\n\n makeDiagram(highlightDiv, diagramText, properties)\n });\n }, [initialized, highlightDivs, properties]);\n\n useEffect(() => {\n if (!initialized) {\n return;\n }\n\n mermaidPreBlocks.forEach(mermaidPreBlock => {\n // Skip already processed\n if (mermaidPreBlock.style.display === 'none') {\n return\n }\n\n const codeBlock = mermaidPreBlock.querySelector('code')\n if (!codeBlock) {\n return\n }\n\n const diagramText = codeBlock.textContent || ''\n\n makeDiagram(mermaidPreBlock, diagramText, properties)\n });\n }, [initialized, mermaidPreBlocks, properties]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;;;;AA0BgB,SAAA,YAAA,CAAa,kBAA+B,UAAyC,EAAA;AAGnG,EAAA,IAAG,WAAW,MAAQ,EAAA;AACpB,IAAA,OAAO,UAAW,CAAA,MAAA;AAAA;AAGpB,EAAA,IAAG,qBAAqB,OAAS,EAAA;AAC/B,IAAO,OAAA,UAAA,CAAW,eAAe,EAAC;AAAA;AAGpC,EAAA,OAAO,OAAO,MAAO,CAAA,EAAE,OAAO,MAAO,EAAA,EAAG,WAAW,UAAU,CAAA;AAC/D;AAMA,IAAI,SAAY,GAAA,CAAA;AAEhB,MAAM,WAAc,GAAA,OAAO,EAAqC,EAAA,WAAA,EAAqB,UAA8B,KAAA;AACjH,EAAA,EAAA,CAAG,MAAM,OAAU,GAAA,MAAA;AAEnB,EAAM,MAAA,cAAA,GAAiB,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA;AACnD,EAAA,cAAA,CAAe,SAAY,GAAA,SAAA;AAE3B,EAAA,EAAA,CAAG,UAAY,EAAA,YAAA,CAAa,cAAgB,EAAA,EAAA,CAAG,WAAW,CAAA;AAE1D,EAAM,MAAA,EAAA,GAAK,WAAW,SAAW,EAAA,CAAA,CAAA;AACjC,EAAM,MAAA,EAAE,KAAK,aAAc,EAAA,GAAI,MAAM,OAAQ,CAAA,MAAA,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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":";;AAkBa,MAAA,aAAA,GAAgB,CAAC,IAA0B,KAAA;AACtD,EAAI,IAAA;AACF,IAAA,OAAA,CAAQ,WAAW,IAAI,CAAA,CAAA;AACvB,IAAO,OAAA,IAAA,CAAA;AAAA,WACA,CAAG,EAAA;AACV,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;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 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":";;AAkBa,MAAA,aAAA,GAAgB,CAAC,IAA0B,KAAA;AACtD,EAAI,IAAA;AACF,IAAA,OAAA,CAAQ,WAAW,IAAI,CAAA;AACvB,IAAO,OAAA,IAAA;AAAA,WACA,CAAG,EAAA;AACV,IAAO,OAAA,KAAA;AAAA;AAEX;;;;"}
@@ -0,0 +1,156 @@
1
+ import { select, pointer } from 'd3-selection';
2
+ import { zoom, zoomIdentity } from 'd3-zoom';
3
+
4
+ class ZoomHandler {
5
+ /**
6
+ * Creates a new ZoomHandler instance
7
+ * @param svgEl - The SVG element to attach zoom behavior to
8
+ * @param g - The group element that will be transformed
9
+ * @param options - Optional configuration for zoom behavior
10
+ */
11
+ constructor(svgEl, g, options = {}) {
12
+ this.svgEl = svgEl;
13
+ this.g = g;
14
+ this.options = options;
15
+ }
16
+ state = {
17
+ isPanning: false,
18
+ startX: 0,
19
+ startY: 0,
20
+ translateX: 0,
21
+ translateY: 0
22
+ };
23
+ /**
24
+ * Initializes the zoom handler by setting up zoom behavior and event listeners
25
+ */
26
+ initialize() {
27
+ const zb = this.createZoomBehavior();
28
+ this.attachZoomBehavior(zb);
29
+ this.attachEventListeners(zb);
30
+ this.svgEl.style.userSelect = "none";
31
+ }
32
+ /**
33
+ * Creates a D3 zoom behavior with configured scale extent
34
+ * @returns Configured D3 zoom behavior
35
+ */
36
+ createZoomBehavior() {
37
+ return zoom().scaleExtent(this.options.scaleExtent || [0.1, 10]).on("zoom", (event) => {
38
+ select(this.g).attr("transform", event.transform.toString());
39
+ });
40
+ }
41
+ /**
42
+ * Attaches the zoom behavior to the SVG element
43
+ * @param zb - The D3 zoom behavior to attach
44
+ */
45
+ attachZoomBehavior(zb) {
46
+ select(this.svgEl).call(zb);
47
+ select(this.svgEl).on(".zoom", null);
48
+ }
49
+ /**
50
+ * Sets up all necessary event listeners for zoom and pan interactions
51
+ * @param zb - The D3 zoom behavior to use for transformations
52
+ */
53
+ attachEventListeners(zb) {
54
+ this.attachWheelListener(zb);
55
+ this.attachMouseListeners(zb);
56
+ }
57
+ /**
58
+ * Attaches wheel event listener for zoom functionality
59
+ * Requires Ctrl/Cmd key to be pressed while scrolling
60
+ * @param zb - The D3 zoom behavior to use for scaling
61
+ */
62
+ attachWheelListener(zb) {
63
+ this.svgEl.addEventListener("wheel", (event) => {
64
+ if (!(event.metaKey || event.ctrlKey)) {
65
+ return;
66
+ }
67
+ event.preventDefault();
68
+ const factor = event.deltaY > 0 ? 0.9 : 1.1;
69
+ const [px, py] = pointer(event, this.svgEl);
70
+ select(this.svgEl).call(zb.scaleBy, factor, [px, py]);
71
+ }, { passive: false });
72
+ }
73
+ /**
74
+ * Attaches mouse event listeners for panning functionality
75
+ * @param zb - The D3 zoom behavior to use for transformations
76
+ */
77
+ attachMouseListeners(zb) {
78
+ this.svgEl.addEventListener("mousedown", (event) => {
79
+ if (event.metaKey || event.ctrlKey) {
80
+ this.handleMouseDown(event);
81
+ }
82
+ });
83
+ document.addEventListener("mousemove", (event) => {
84
+ if (this.state.isPanning) {
85
+ this.handleMouseMove(event, zb);
86
+ }
87
+ });
88
+ document.addEventListener("mouseup", () => {
89
+ if (this.state.isPanning) {
90
+ this.handleMouseUp();
91
+ }
92
+ });
93
+ document.addEventListener("mouseleave", () => {
94
+ if (this.state.isPanning) {
95
+ this.handleMouseUp();
96
+ }
97
+ });
98
+ }
99
+ /**
100
+ * Handles the start of a panning operation
101
+ * @param event - The mouse down event that triggered the pan
102
+ */
103
+ handleMouseDown(event) {
104
+ this.state.isPanning = true;
105
+ this.state.startX = event.clientX;
106
+ this.state.startY = event.clientY;
107
+ const transform = select(this.g).attr("transform");
108
+ if (transform) {
109
+ const translateMatch = transform.match(/translate\(([^)]+)\)/);
110
+ if (translateMatch) {
111
+ const [x, y] = translateMatch[1].split(",").map(Number);
112
+ this.state.translateX = x;
113
+ this.state.translateY = y;
114
+ }
115
+ }
116
+ this.svgEl.style.cursor = "grabbing";
117
+ }
118
+ /**
119
+ * Handles mouse movement during panning
120
+ * @param event - The mouse move event
121
+ * @param zb - The D3 zoom behavior to use for transformations
122
+ */
123
+ handleMouseMove(event, zb) {
124
+ if (!event.metaKey && !event.ctrlKey) {
125
+ this.handleMouseUp();
126
+ return;
127
+ }
128
+ event.preventDefault();
129
+ const [currentX, currentY] = pointer(event, this.svgEl);
130
+ const [startX, startY] = pointer({ clientX: this.state.startX, clientY: this.state.startY }, this.svgEl);
131
+ const dx = currentX - startX;
132
+ const dy = currentY - startY;
133
+ const transform = select(this.g).attr("transform");
134
+ let currentScale = 1;
135
+ if (transform) {
136
+ const scaleMatch = transform.match(/scale\(([^)]+)\)/);
137
+ if (scaleMatch) {
138
+ currentScale = parseFloat(scaleMatch[1]);
139
+ }
140
+ }
141
+ const newTranslateX = this.state.translateX + dx;
142
+ const newTranslateY = this.state.translateY + dy;
143
+ const newTransform = zoomIdentity.translate(newTranslateX, newTranslateY).scale(currentScale);
144
+ select(this.svgEl).call(zb.transform, newTransform);
145
+ }
146
+ /**
147
+ * Handles the end of a panning operation
148
+ */
149
+ handleMouseUp() {
150
+ this.state.isPanning = false;
151
+ this.svgEl.style.cursor = "default";
152
+ }
153
+ }
154
+
155
+ export { ZoomHandler };
156
+ //# sourceMappingURL=zoomHandler.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoomHandler.esm.js","sources":["../../src/Mermaid/zoomHandler.ts"],"sourcesContent":["/**\n * A module that provides zoom and pan functionality for SVG elements using D3.js.\n * This is used to enhance the interaction capabilities of Mermaid diagrams in TechDocs.\n */\n\nimport { select } from 'd3-selection';\nimport { zoom } from 'd3-zoom';\nimport { pointer } from 'd3-selection';\nimport { zoomIdentity } from 'd3-zoom';\nimport type { ZoomBehavior } from 'd3-zoom';\nimport { ZoomOptions } from './props';\n\n/**\n * Represents the internal state of the zoom handler\n */\nexport interface ZoomState {\n /** Whether the user is currently panning the diagram */\n isPanning: boolean;\n /** X coordinate where the panning started */\n startX: number;\n /** Y coordinate where the panning started */\n startY: number;\n /** Current X translation offset */\n translateX: number;\n /** Current Y translation offset */\n translateY: number;\n}\n\n/**\n * Handles zoom and pan interactions for SVG elements.\n * Provides functionality for:\n * - Zooming with mouse wheel (Ctrl/Cmd + wheel)\n * - Panning with mouse drag (Ctrl/Cmd + drag)\n * - Maintaining zoom state and transformations\n */\nexport class ZoomHandler {\n private state: ZoomState = {\n isPanning: false,\n startX: 0,\n startY: 0,\n translateX: 0,\n translateY: 0,\n };\n\n /**\n * Creates a new ZoomHandler instance\n * @param svgEl - The SVG element to attach zoom behavior to\n * @param g - The group element that will be transformed\n * @param options - Optional configuration for zoom behavior\n */\n constructor(\n private svgEl: SVGSVGElement,\n private g: SVGGElement,\n private options: ZoomOptions = {}\n ) {}\n\n /**\n * Initializes the zoom handler by setting up zoom behavior and event listeners\n */\n public initialize(): void {\n const zb = this.createZoomBehavior();\n this.attachZoomBehavior(zb);\n this.attachEventListeners(zb);\n // Disable text selection permanently\n this.svgEl.style.userSelect = 'none';\n }\n\n /**\n * Creates a D3 zoom behavior with configured scale extent\n * @returns Configured D3 zoom behavior\n */\n private createZoomBehavior(): ZoomBehavior<SVGSVGElement, unknown> {\n return zoom<SVGSVGElement, unknown>()\n .scaleExtent(this.options.scaleExtent || [0.1, 10])\n .on('zoom', (event) => {\n select(this.g).attr('transform', event.transform.toString());\n });\n }\n\n /**\n * Attaches the zoom behavior to the SVG element\n * @param zb - The D3 zoom behavior to attach\n */\n private attachZoomBehavior(zb: ZoomBehavior<SVGSVGElement, unknown>): void {\n select(this.svgEl).call(zb);\n select(this.svgEl).on('.zoom', null);\n }\n\n /**\n * Sets up all necessary event listeners for zoom and pan interactions\n * @param zb - The D3 zoom behavior to use for transformations\n */\n private attachEventListeners(zb: ZoomBehavior<SVGSVGElement, unknown>): void {\n this.attachWheelListener(zb);\n this.attachMouseListeners(zb);\n }\n\n /**\n * Attaches wheel event listener for zoom functionality\n * Requires Ctrl/Cmd key to be pressed while scrolling\n * @param zb - The D3 zoom behavior to use for scaling\n */\n private attachWheelListener(zb: ZoomBehavior<SVGSVGElement, unknown>): void {\n this.svgEl.addEventListener('wheel', (event: WheelEvent) => {\n if (!(event.metaKey || event.ctrlKey)) {\n return;\n }\n event.preventDefault();\n const factor = event.deltaY > 0 ? 0.9 : 1.1;\n const [px, py] = pointer(event, this.svgEl);\n // @ts-ignore: scaleBy is available on the zoom behavior\n (select(this.svgEl) as any).call(zb.scaleBy, factor, [px, py]);\n }, { passive: false });\n }\n\n /**\n * Attaches mouse event listeners for panning functionality\n * @param zb - The D3 zoom behavior to use for transformations\n */\n private attachMouseListeners(zb: ZoomBehavior<SVGSVGElement, unknown>): void {\n this.svgEl.addEventListener('mousedown', (event) => {\n if (event.metaKey || event.ctrlKey) {\n this.handleMouseDown(event);\n }\n });\n\n document.addEventListener('mousemove', (event) => {\n if (this.state.isPanning) {\n this.handleMouseMove(event, zb);\n }\n });\n\n document.addEventListener('mouseup', () => {\n if (this.state.isPanning) {\n this.handleMouseUp();\n }\n });\n\n document.addEventListener('mouseleave', () => {\n if (this.state.isPanning) {\n this.handleMouseUp();\n }\n });\n }\n\n /**\n * Handles the start of a panning operation\n * @param event - The mouse down event that triggered the pan\n */\n private handleMouseDown(event: MouseEvent): void {\n this.state.isPanning = true;\n this.state.startX = event.clientX;\n this.state.startY = event.clientY;\n\n const transform = select(this.g).attr('transform');\n if (transform) {\n const translateMatch = transform.match(/translate\\(([^)]+)\\)/);\n if (translateMatch) {\n const [x, y] = translateMatch[1].split(',').map(Number);\n this.state.translateX = x;\n this.state.translateY = y;\n }\n }\n\n this.svgEl.style.cursor = 'grabbing';\n }\n\n /**\n * Handles mouse movement during panning\n * @param event - The mouse move event\n * @param zb - The D3 zoom behavior to use for transformations\n */\n private handleMouseMove(event: MouseEvent, zb: ZoomBehavior<SVGSVGElement, unknown>): void {\n if (!event.metaKey && !event.ctrlKey) {\n this.handleMouseUp();\n return;\n }\n\n event.preventDefault();\n\n // Convert current mouse position to SVG coordinates\n const [currentX, currentY] = pointer(event, this.svgEl);\n // Convert the starting mouse position to SVG coordinates\n const [startX, startY] = pointer({ clientX: this.state.startX, clientY: this.state.startY }, this.svgEl);\n\n // Calculate the movement delta in SVG coordinate space\n const dx = currentX - startX;\n const dy = currentY - startY;\n\n const transform = select(this.g).attr('transform');\n let currentScale = 1;\n\n if (transform) {\n const scaleMatch = transform.match(/scale\\(([^)]+)\\)/);\n if (scaleMatch) {\n currentScale = parseFloat(scaleMatch[1]);\n }\n }\n\n const newTranslateX = this.state.translateX + dx;\n const newTranslateY = this.state.translateY + dy;\n\n const newTransform = zoomIdentity\n .translate(newTranslateX, newTranslateY)\n .scale(currentScale);\n select(this.svgEl).call(zb.transform, newTransform);\n }\n\n /**\n * Handles the end of a panning operation\n */\n private handleMouseUp(): void {\n this.state.isPanning = false;\n this.svgEl.style.cursor = 'default';\n }\n} "],"names":[],"mappings":";;;AAmCO,MAAM,WAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAevB,WACU,CAAA,KAAA,EACA,CACA,EAAA,OAAA,GAAuB,EAC/B,EAAA;AAHQ,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AACA,IAAA,IAAA,CAAA,CAAA,GAAA,CAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA;AACP,EAlBK,KAAmB,GAAA;AAAA,IACzB,SAAW,EAAA,KAAA;AAAA,IACX,MAAQ,EAAA,CAAA;AAAA,IACR,MAAQ,EAAA,CAAA;AAAA,IACR,UAAY,EAAA,CAAA;AAAA,IACZ,UAAY,EAAA;AAAA,GACd;AAAA;AAAA;AAAA;AAAA,EAiBO,UAAmB,GAAA;AACxB,IAAM,MAAA,EAAA,GAAK,KAAK,kBAAmB,EAAA;AACnC,IAAA,IAAA,CAAK,mBAAmB,EAAE,CAAA;AAC1B,IAAA,IAAA,CAAK,qBAAqB,EAAE,CAAA;AAE5B,IAAK,IAAA,CAAA,KAAA,CAAM,MAAM,UAAa,GAAA,MAAA;AAAA;AAChC;AAAA;AAAA;AAAA;AAAA,EAMQ,kBAA2D,GAAA;AACjE,IAAA,OAAO,IAA6B,EAAA,CACjC,WAAY,CAAA,IAAA,CAAK,QAAQ,WAAe,IAAA,CAAC,GAAK,EAAA,EAAE,CAAC,CAA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C,CAAA;AAAA;AACzC;AAGF,IAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,KAAA,CAAM,UAAa,GAAA,EAAA;AAC9C,IAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,KAAA,CAAM,UAAa,GAAA,EAAA;AAE9C,IAAA,MAAM,eAAe,YAClB,CAAA,SAAA,CAAU,eAAe,aAAa,CAAA,CACtC,MAAM,YAAY,CAAA;AACrB,IAAA,MAAA,CAAO,KAAK,KAAK,CAAA,CAAE,IAAK,CAAA,EAAA,CAAG,WAAW,YAAY,CAAA;AAAA;AACpD;AAAA;AAAA;AAAA,EAKQ,aAAsB,GAAA;AAC5B,IAAA,IAAA,CAAK,MAAM,SAAY,GAAA,KAAA;AACvB,IAAK,IAAA,CAAA,KAAA,CAAM,MAAM,MAAS,GAAA,SAAA;AAAA;AAE9B;;;;"}
@@ -0,0 +1,20 @@
1
+ import { AddonBlueprint } from '@backstage/plugin-techdocs-react/alpha';
2
+ import { MermaidAddon } from './Mermaid/Mermaid.esm.js';
3
+ import { createFrontendModule } from '@backstage/frontend-plugin-api';
4
+
5
+ const mermaidAddonParams = {
6
+ name: "Mermaid",
7
+ location: "Content",
8
+ component: MermaidAddon
9
+ };
10
+ const techDocsMermaidAddon = AddonBlueprint.make({
11
+ name: "mermaid",
12
+ params: mermaidAddonParams
13
+ });
14
+ const techDocsMermaidAddonModule = createFrontendModule({
15
+ pluginId: "techdocs",
16
+ extensions: [techDocsMermaidAddon]
17
+ });
18
+
19
+ export { techDocsMermaidAddon, techDocsMermaidAddonModule };
20
+ //# sourceMappingURL=alpha.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpha.esm.js","sources":["../src/alpha.ts"],"sourcesContent":["import {\n AddonBlueprint,\n TechDocsAddonOptions,\n} from \"@backstage/plugin-techdocs-react/alpha\";\nimport { MermaidAddon } from \"./Mermaid\";\nimport { createFrontendModule } from \"@backstage/frontend-plugin-api\";\n\nconst mermaidAddonParams: TechDocsAddonOptions = {\n name: \"Mermaid\",\n location: \"Content\",\n component: MermaidAddon,\n};\n\nexport const techDocsMermaidAddon = AddonBlueprint.make({\n name: \"mermaid\",\n params: mermaidAddonParams,\n});\n\nexport const techDocsMermaidAddonModule = createFrontendModule({\n pluginId: \"techdocs\",\n extensions: [techDocsMermaidAddon],\n});\n"],"names":[],"mappings":";;;;AAOA,MAAM,kBAA2C,GAAA;AAAA,EAC/C,IAAM,EAAA,SAAA;AAAA,EACN,QAAU,EAAA,SAAA;AAAA,EACV,SAAW,EAAA;AACb,CAAA;AAEa,MAAA,oBAAA,GAAuB,eAAe,IAAK,CAAA;AAAA,EACtD,IAAM,EAAA,SAAA;AAAA,EACN,MAAQ,EAAA;AACV,CAAC;AAEM,MAAM,6BAA6B,oBAAqB,CAAA;AAAA,EAC7D,QAAU,EAAA,UAAA;AAAA,EACV,UAAA,EAAY,CAAC,oBAAoB;AACnC,CAAC;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,47 @@
1
- /// <reference types="react" />
2
1
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
3
- import { MermaidConfig } from 'mermaid';
2
+ import { MermaidConfig, LayoutLoaderDefinition } from 'mermaid';
3
+ import { IconLoader } from 'mermaid/dist/rendering-util/icons';
4
+ import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
5
+ import { TechDocsAddonOptions } from '@backstage/plugin-techdocs-react/alpha';
4
6
 
7
+ /**
8
+ * Configuration options for controlling D3 zoom and pan behavior in Mermaid diagrams.
9
+ * These options allow fine-tuning of the interactive zoom and pan capabilities.
10
+ */
11
+ interface ZoomOptions {
12
+ /**
13
+ * Defines the minimum and maximum zoom scale limits.
14
+ * Example: [0.1, 10] allows zooming out to 10% and in to 1000%
15
+ */
16
+ scaleExtent?: [number, number];
17
+ /**
18
+ * Defines the boundaries for panning the diagram.
19
+ * Format: [[xmin, ymin], [xmax, ymax]]
20
+ * Example: [[-1000, -1000], [1000, 1000]] limits panning to a 2000x2000 area
21
+ */
22
+ translateExtent?: [[number, number], [number, number]];
23
+ }
24
+ /**
25
+ * Configuration properties for the Mermaid diagram component.
26
+ * These props allow customization of the diagram's appearance and behavior
27
+ * in both light and dark themes, as well as control over zoom functionality.
28
+ */
5
29
  type MermaidProps = {
6
30
  lightConfig?: MermaidConfig;
7
31
  darkConfig?: MermaidConfig;
8
32
  config?: MermaidConfig;
33
+ iconLoaders?: IconLoader[];
34
+ layoutLoaders?: LayoutLoaderDefinition[];
35
+ /**
36
+ * Enables or disables pan and zoom functionality for all diagrams.
37
+ * When true, users can interact with diagrams using mouse/touch gestures.
38
+ */
39
+ enableZoom?: boolean;
40
+ /**
41
+ * Configuration options for zoom and pan behavior.
42
+ * Only used when enableZoom is set to true.
43
+ */
44
+ zoomOptions?: ZoomOptions;
9
45
  };
10
46
 
11
47
  /**
@@ -21,4 +57,15 @@ declare const techdocsAddonMermaidPlugin: _backstage_core_plugin_api.BackstagePl
21
57
  */
22
58
  declare const Mermaid: (props: MermaidProps) => JSX.Element | null;
23
59
 
24
- export { Mermaid, techdocsAddonMermaidPlugin };
60
+ declare const techDocsMermaidAddon: _backstage_frontend_plugin_api.ExtensionDefinition<{
61
+ kind: "addon";
62
+ name: "mermaid";
63
+ config: {};
64
+ configInput: {};
65
+ output: _backstage_frontend_plugin_api.ConfigurableExtensionDataRef<TechDocsAddonOptions, "techdocs.addon", {}>;
66
+ inputs: {};
67
+ params: TechDocsAddonOptions;
68
+ }>;
69
+ declare const techDocsMermaidAddonModule: _backstage_frontend_plugin_api.FrontendModule;
70
+
71
+ export { Mermaid, techDocsMermaidAddon, techDocsMermaidAddonModule, techdocsAddonMermaidPlugin };
package/dist/index.esm.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Mermaid, techdocsAddonMermaidPlugin } from './plugin.esm.js';
2
+ export { techDocsMermaidAddon, techDocsMermaidAddonModule } from './alpha.esm.js';
2
3
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.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 */\nimport { createPlugin } from '@backstage/core-plugin-api';\nimport {\n createTechDocsAddonExtension,\n TechDocsAddonLocations,\n} from '@backstage/plugin-techdocs-react';\n\nimport { MermaidAddon } from './Mermaid';\nimport type { MermaidProps } from './Mermaid';\n\n/**\n * The TechDocs addons mermaid plugin\n *\n * @public\n */\n\n\nexport const techdocsAddonMermaidPlugin = createPlugin({\n id: 'techdocs-addon-mermaid',\n});\n\n/**\n * TechDocs addon that lets you render Mermaid diagrams\n *\n * @public\n */\n\n export const Mermaid = techdocsAddonMermaidPlugin.provide(\n createTechDocsAddonExtension<MermaidProps>({\n name: 'MermaidDiagram',\n location: TechDocsAddonLocations.Content,\n component: MermaidAddon,\n }),\n);\n"],"names":[],"mappings":";;;;AA+BO,MAAM,6BAA6B,YAAa,CAAA;AAAA,EACrD,EAAI,EAAA,wBAAA;AACN,CAAC,EAAA;AAQO,MAAM,UAAU,0BAA2B,CAAA,OAAA;AAAA,EACjD,4BAA2C,CAAA;AAAA,IACzC,IAAM,EAAA,gBAAA;AAAA,IACN,UAAU,sBAAuB,CAAA,OAAA;AAAA,IACjC,SAAW,EAAA,YAAA;AAAA,GACZ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.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 */\nimport { createPlugin } from '@backstage/core-plugin-api';\nimport {\n createTechDocsAddonExtension,\n TechDocsAddonLocations,\n} from '@backstage/plugin-techdocs-react';\n\nimport { MermaidAddon } from './Mermaid';\nimport type { MermaidProps } from './Mermaid';\n\n/**\n * The TechDocs addons mermaid plugin\n *\n * @public\n */\n\n\nexport const techdocsAddonMermaidPlugin = createPlugin({\n id: 'techdocs-addon-mermaid',\n});\n\n/**\n * TechDocs addon that lets you render Mermaid diagrams\n *\n * @public\n */\n\n export const Mermaid = techdocsAddonMermaidPlugin.provide(\n createTechDocsAddonExtension<MermaidProps>({\n name: 'MermaidDiagram',\n location: TechDocsAddonLocations.Content,\n component: MermaidAddon,\n }),\n);\n"],"names":[],"mappings":";;;;AA+BO,MAAM,6BAA6B,YAAa,CAAA;AAAA,EACrD,EAAI,EAAA;AACN,CAAC;AAQO,MAAM,UAAU,0BAA2B,CAAA,OAAA;AAAA,EACjD,4BAA2C,CAAA;AAAA,IACzC,IAAM,EAAA,gBAAA;AAAA,IACN,UAAU,sBAAuB,CAAA,OAAA;AAAA,IACjC,SAAW,EAAA;AAAA,GACZ;AACH;;;;"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "backstage-plugin-techdocs-addon-mermaid",
3
- "version": "0.21.0",
3
+ "version": "0.21.5",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
8
8
  "access": "public",
9
9
  "main": "dist/index.esm.js",
10
- "types": "dist/index.d.ts"
10
+ "types": "dist/index.d.ts",
11
+ "registry": "https://registry.npmjs.org"
11
12
  },
12
13
  "backstage": {
13
14
  "role": "frontend-plugin",