backstage-plugin-techdocs-addon-mermaid 0.19.0 → 0.20.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
|
@@ -74,6 +74,47 @@ graph TD;
|
|
|
74
74
|
|
|
75
75
|
~~~
|
|
76
76
|
|
|
77
|
+
## Zoom and Pan Functionality
|
|
78
|
+
|
|
79
|
+
The plugin supports interactive zoom and pan functionality for Mermaid diagrams. This allows users to:
|
|
80
|
+
- Zoom in/out using Ctrl/Cmd + mouse wheel
|
|
81
|
+
- Pan the diagram using Ctrl/Cmd + mouse drag
|
|
82
|
+
|
|
83
|
+
### Zoom Configuration Options
|
|
84
|
+
|
|
85
|
+
The zoom functionality can be configured using the following options:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface ZoomOptions {
|
|
89
|
+
/**
|
|
90
|
+
* Defines the minimum and maximum zoom scale limits.
|
|
91
|
+
* Example: [0.1, 10] allows zooming out to 10% and in to 1000%
|
|
92
|
+
* Default: [0.1, 10]
|
|
93
|
+
*/
|
|
94
|
+
scaleExtent?: [number, number];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Defines the boundaries for panning the diagram.
|
|
98
|
+
* Format: [[xmin, ymin], [xmax, ymax]]
|
|
99
|
+
* Example: [[-1000, -1000], [1000, 1000]] limits panning to a 2000x2000 area
|
|
100
|
+
* Default: No limits
|
|
101
|
+
*/
|
|
102
|
+
translateExtent?: [[number, number], [number, number]];
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
To enable zoom functionality, add the `enableZoom` prop and optionally configure the zoom behavior:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
<Mermaid
|
|
110
|
+
enableZoom
|
|
111
|
+
zoomOptions={{
|
|
112
|
+
scaleExtent: [0.1, 10], // Optional: Set min/max zoom scale
|
|
113
|
+
translateExtent: [[-1000, -1000], [1000, 1000]] // Optional: Set pan boundaries
|
|
114
|
+
}}
|
|
115
|
+
/>
|
|
116
|
+
```
|
|
117
|
+
|
|
77
118
|
## Auto-Detection vs. Manual Detection
|
|
78
119
|
|
|
79
120
|
By default, this plugin will autodetect diagrams based on the starting token of the code block. In some cases, however, this auto-detection is not sufficient, for example, because of an unrecognized
|
|
@@ -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"]);
|
|
@@ -43,7 +56,7 @@ const MermaidAddon = (properties) => {
|
|
|
43
56
|
}
|
|
44
57
|
mermaid.initialize(config);
|
|
45
58
|
setInitialized(true);
|
|
46
|
-
}, [initialized]);
|
|
59
|
+
}, [initialized, properties, theme.palette.type]);
|
|
47
60
|
useEffect(() => {
|
|
48
61
|
if (!initialized) {
|
|
49
62
|
return;
|
|
@@ -63,9 +76,9 @@ const MermaidAddon = (properties) => {
|
|
|
63
76
|
if (!isMermaidCode(diagramText)) {
|
|
64
77
|
return;
|
|
65
78
|
}
|
|
66
|
-
makeDiagram(highlightTable, diagramText);
|
|
79
|
+
makeDiagram(highlightTable, diagramText, properties);
|
|
67
80
|
});
|
|
68
|
-
}, [initialized, highlightTables]);
|
|
81
|
+
}, [initialized, highlightTables, properties]);
|
|
69
82
|
useEffect(() => {
|
|
70
83
|
if (!initialized) {
|
|
71
84
|
return;
|
|
@@ -89,9 +102,9 @@ const MermaidAddon = (properties) => {
|
|
|
89
102
|
if (!isMermaidCode(diagramText)) {
|
|
90
103
|
return;
|
|
91
104
|
}
|
|
92
|
-
makeDiagram(highlightDiv, diagramText);
|
|
105
|
+
makeDiagram(highlightDiv, diagramText, properties);
|
|
93
106
|
});
|
|
94
|
-
}, [initialized, highlightDivs]);
|
|
107
|
+
}, [initialized, highlightDivs, properties]);
|
|
95
108
|
useEffect(() => {
|
|
96
109
|
if (!initialized) {
|
|
97
110
|
return;
|
|
@@ -105,9 +118,9 @@ const MermaidAddon = (properties) => {
|
|
|
105
118
|
return;
|
|
106
119
|
}
|
|
107
120
|
const diagramText = codeBlock.textContent || "";
|
|
108
|
-
makeDiagram(mermaidPreBlock, diagramText);
|
|
121
|
+
makeDiagram(mermaidPreBlock, diagramText, properties);
|
|
109
122
|
});
|
|
110
|
-
}, [initialized, mermaidPreBlocks]);
|
|
123
|
+
}, [initialized, mermaidPreBlocks, properties]);
|
|
111
124
|
return null;
|
|
112
125
|
};
|
|
113
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, { MermaidConfig } from 'mermaid'\nimport { isMermaidCode } from './hooks';\nimport { MermaidProps } from './props';\nimport { BackstageTheme } from '@backstage/theme';\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 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]);\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":"
|
|
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';\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,E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AAY,WAAA,CAAA,eAAA,EAAiB,aAAa,UAAU,CAAA;AAAA,KACrD,CAAA;AAAA,GACA,EAAA,CAAC,WAAa,EAAA,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAE9C,EAAO,OAAA,IAAA;AACT;;;;"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a D3 zoom behavior with configured scale extent
|
|
33
|
+
* @returns Configured D3 zoom behavior
|
|
34
|
+
*/
|
|
35
|
+
createZoomBehavior() {
|
|
36
|
+
return zoom().scaleExtent(this.options.scaleExtent || [0.1, 10]).on("zoom", (event) => {
|
|
37
|
+
select(this.g).attr("transform", event.transform.toString());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Attaches the zoom behavior to the SVG element
|
|
42
|
+
* @param zb - The D3 zoom behavior to attach
|
|
43
|
+
*/
|
|
44
|
+
attachZoomBehavior(zb) {
|
|
45
|
+
select(this.svgEl).call(zb);
|
|
46
|
+
select(this.svgEl).on(".zoom", null);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets up all necessary event listeners for zoom and pan interactions
|
|
50
|
+
* @param zb - The D3 zoom behavior to use for transformations
|
|
51
|
+
*/
|
|
52
|
+
attachEventListeners(zb) {
|
|
53
|
+
this.attachWheelListener(zb);
|
|
54
|
+
this.attachMouseListeners(zb);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Attaches wheel event listener for zoom functionality
|
|
58
|
+
* Requires Ctrl/Cmd key to be pressed while scrolling
|
|
59
|
+
* @param zb - The D3 zoom behavior to use for scaling
|
|
60
|
+
*/
|
|
61
|
+
attachWheelListener(zb) {
|
|
62
|
+
this.svgEl.addEventListener("wheel", (event) => {
|
|
63
|
+
if (!(event.metaKey || event.ctrlKey)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
const factor = event.deltaY > 0 ? 0.9 : 1.1;
|
|
68
|
+
const [px, py] = pointer(event, this.svgEl);
|
|
69
|
+
select(this.svgEl).call(zb.scaleBy, factor, [px, py]);
|
|
70
|
+
}, { passive: false });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Attaches mouse event listeners for panning functionality
|
|
74
|
+
* @param zb - The D3 zoom behavior to use for transformations
|
|
75
|
+
*/
|
|
76
|
+
attachMouseListeners(zb) {
|
|
77
|
+
this.svgEl.addEventListener("mousedown", (event) => {
|
|
78
|
+
if (event.metaKey || event.ctrlKey) {
|
|
79
|
+
this.handleMouseDown(event);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
document.addEventListener("mousemove", (event) => {
|
|
83
|
+
if (this.state.isPanning) {
|
|
84
|
+
this.handleMouseMove(event, zb);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
document.addEventListener("mouseup", () => {
|
|
88
|
+
if (this.state.isPanning) {
|
|
89
|
+
this.handleMouseUp();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
document.addEventListener("mouseleave", () => {
|
|
93
|
+
if (this.state.isPanning) {
|
|
94
|
+
this.handleMouseUp();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Handles the start of a panning operation
|
|
100
|
+
* @param event - The mouse down event that triggered the pan
|
|
101
|
+
*/
|
|
102
|
+
handleMouseDown(event) {
|
|
103
|
+
this.state.isPanning = true;
|
|
104
|
+
this.state.startX = event.clientX;
|
|
105
|
+
this.state.startY = event.clientY;
|
|
106
|
+
const transform = select(this.g).attr("transform");
|
|
107
|
+
if (transform) {
|
|
108
|
+
const translateMatch = transform.match(/translate\(([^)]+)\)/);
|
|
109
|
+
if (translateMatch) {
|
|
110
|
+
const [x, y] = translateMatch[1].split(",").map(Number);
|
|
111
|
+
this.state.translateX = x;
|
|
112
|
+
this.state.translateY = y;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
this.svgEl.style.cursor = "grabbing";
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handles mouse movement during panning
|
|
119
|
+
* @param event - The mouse move event
|
|
120
|
+
* @param zb - The D3 zoom behavior to use for transformations
|
|
121
|
+
*/
|
|
122
|
+
handleMouseMove(event, zb) {
|
|
123
|
+
if (!event.metaKey && !event.ctrlKey) {
|
|
124
|
+
this.handleMouseUp();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const dx = event.clientX - this.state.startX;
|
|
129
|
+
const dy = event.clientY - this.state.startY;
|
|
130
|
+
const transform = select(this.g).attr("transform");
|
|
131
|
+
let currentScale = 1;
|
|
132
|
+
if (transform) {
|
|
133
|
+
const scaleMatch = transform.match(/scale\(([^)]+)\)/);
|
|
134
|
+
if (scaleMatch) {
|
|
135
|
+
currentScale = parseFloat(scaleMatch[1]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const newTranslateX = this.state.translateX + dx;
|
|
139
|
+
const newTranslateY = this.state.translateY + dy;
|
|
140
|
+
const newTransform = zoomIdentity.translate(newTranslateX, newTranslateY).scale(currentScale);
|
|
141
|
+
select(this.svgEl).call(zb.transform, newTransform);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Handles the end of a panning operation
|
|
145
|
+
*/
|
|
146
|
+
handleMouseUp() {
|
|
147
|
+
this.state.isPanning = false;
|
|
148
|
+
this.svgEl.style.cursor = "default";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { ZoomHandler };
|
|
153
|
+
//# 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 }\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 const dx = event.clientX - this.state.startX;\n const dy = event.clientY - this.state.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;AAAA;AAC9B;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,CAAA,CACjD,EAAG,CAAA,MAAA,EAAQ,CAAC,KAAU,KAAA;AACrB,MAAO,MAAA,CAAA,IAAA,CAAK,CAAC,CAAE,CAAA,IAAA,CAAK,aAAa,KAAM,CAAA,SAAA,CAAU,UAAU,CAAA;AAAA,KAC5D,CAAA;AAAA;AACL;AAAA;AAAA;AAAA;AAAA,EAMQ,mBAAmB,EAAgD,EAAA;AACzE,IAAA,MAAA,CAAO,IAAK,CAAA,KAAK,CAAE,CAAA,IAAA,CAAK,EAAE,CAA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B;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,44 @@ import { IconLoader } from 'mermaid/dist/rendering-util/icons';
|
|
|
4
4
|
import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
|
|
5
5
|
import { TechDocsAddonOptions } from '@backstage/plugin-techdocs-react/alpha';
|
|
6
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
|
+
*/
|
|
7
29
|
type MermaidProps = {
|
|
8
30
|
lightConfig?: MermaidConfig;
|
|
9
31
|
darkConfig?: MermaidConfig;
|
|
10
32
|
config?: MermaidConfig;
|
|
11
33
|
iconLoaders?: IconLoader[];
|
|
12
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;
|
|
13
45
|
};
|
|
14
46
|
|
|
15
47
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backstage-plugin-techdocs-addon-mermaid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"main": "dist/index.esm.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
"@material-ui/core": "^4.12.2",
|
|
41
41
|
"@material-ui/icons": "^4.11.3",
|
|
42
42
|
"@material-ui/lab": "4.0.0-alpha.61",
|
|
43
|
-
"
|
|
43
|
+
"d3": "^7.9.0",
|
|
44
|
+
"d3-selection": "^3.0.0",
|
|
45
|
+
"d3-zoom": "^3.0.0",
|
|
46
|
+
"mermaid": "^11.6.0",
|
|
44
47
|
"react-use": "^17.2.4"
|
|
45
48
|
},
|
|
46
49
|
"peerDependencies": {
|
|
@@ -60,6 +63,7 @@
|
|
|
60
63
|
"@testing-library/jest-dom": "^6.0.0",
|
|
61
64
|
"@testing-library/react": "^14.0.0",
|
|
62
65
|
"@testing-library/user-event": "^14.0.0",
|
|
66
|
+
"@types/d3": "^7.4.3",
|
|
63
67
|
"@types/jest": "*",
|
|
64
68
|
"@types/node": "*",
|
|
65
69
|
"@types/react": "^18.3.12",
|