mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-17 15:29:25 +02:00
feat: Add tooltip for MermaidChart links
This commit is contained in:
@@ -2,8 +2,10 @@
|
|||||||
Ashish Jain
|
Ashish Jain
|
||||||
cpettitt
|
cpettitt
|
||||||
Dong Cai
|
Dong Cai
|
||||||
|
knsv
|
||||||
|
Knut Sveidqvist
|
||||||
Nikolay Rozhkov
|
Nikolay Rozhkov
|
||||||
Peng Xiao
|
Peng Xiao
|
||||||
Per Brolin
|
Per Brolin
|
||||||
|
Sidharth Vinod
|
||||||
subhash-halder
|
subhash-halder
|
||||||
Vinod Sidharth
|
|
||||||
|
@@ -13,11 +13,11 @@ gitgraph
|
|||||||
gzipped
|
gzipped
|
||||||
handDrawn
|
handDrawn
|
||||||
kanban
|
kanban
|
||||||
knsv
|
|
||||||
Knut
|
|
||||||
marginx
|
marginx
|
||||||
marginy
|
marginy
|
||||||
Markdownish
|
Markdownish
|
||||||
|
mermaidchart
|
||||||
|
mermaidchart
|
||||||
mermaidjs
|
mermaidjs
|
||||||
mindmap
|
mindmap
|
||||||
mindmaps
|
mindmaps
|
||||||
@@ -35,7 +35,6 @@ sandboxed
|
|||||||
siebling
|
siebling
|
||||||
statediagram
|
statediagram
|
||||||
substate
|
substate
|
||||||
Sveidqvist
|
|
||||||
unfixable
|
unfixable
|
||||||
Viewbox
|
Viewbox
|
||||||
viewports
|
viewports
|
||||||
|
@@ -17,6 +17,81 @@ import Theme from 'vitepress/theme';
|
|||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
import '../style/main.css';
|
import '../style/main.css';
|
||||||
|
|
||||||
|
// Add tooltips to Mermaid Chart buttons
|
||||||
|
const addMermaidChartTooltips = () => {
|
||||||
|
const tooltipStyle = document.createElement('style');
|
||||||
|
tooltipStyle.textContent = `
|
||||||
|
.mermaid-chart-tooltip {
|
||||||
|
position: absolute;
|
||||||
|
background: black;
|
||||||
|
color: white;
|
||||||
|
padding: 0.3rem 0.6rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 1000;
|
||||||
|
max-width: 20rem;
|
||||||
|
text-align: center;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease, transform 0.3s ease;
|
||||||
|
transform: translateY(-90%);
|
||||||
|
margin-top: -0.5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.375rem;
|
||||||
|
}
|
||||||
|
.mermaid-chart-tooltip.visible {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(-100%);
|
||||||
|
}
|
||||||
|
.mermaid-chart-tooltip svg {
|
||||||
|
width: 1.25rem;
|
||||||
|
height: 1.25rem;
|
||||||
|
fill: currentColor;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
document.head.appendChild(tooltipStyle);
|
||||||
|
|
||||||
|
const tooltip = document.createElement('div');
|
||||||
|
tooltip.className = 'mermaid-chart-tooltip';
|
||||||
|
document.body.appendChild(tooltip);
|
||||||
|
|
||||||
|
let currentTarget: HTMLElement | null = null;
|
||||||
|
|
||||||
|
const showTooltip = (target: HTMLElement) => {
|
||||||
|
currentTarget = target;
|
||||||
|
const rect = target.getBoundingClientRect();
|
||||||
|
tooltip.innerHTML = `
|
||||||
|
<span class="mdi mdi-open-in-new"></span>
|
||||||
|
Opens in MermaidChart.com
|
||||||
|
`;
|
||||||
|
tooltip.style.left = rect.left + rect.width / 2 - tooltip.offsetWidth / 2 + 'px';
|
||||||
|
tooltip.style.top = rect.top + 'px';
|
||||||
|
tooltip.classList.add('visible');
|
||||||
|
};
|
||||||
|
|
||||||
|
const hideTooltip = () => {
|
||||||
|
currentTarget = null;
|
||||||
|
tooltip.classList.remove('visible');
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('mouseover', (e) => {
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
if (
|
||||||
|
target.matches('a[href*="mermaidchart.com"]') ||
|
||||||
|
target.matches('button[onclick*="mermaidchart.com"]')
|
||||||
|
) {
|
||||||
|
showTooltip(target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('mouseout', (e) => {
|
||||||
|
if (!currentTarget?.contains(e.relatedTarget as HTMLElement)) {
|
||||||
|
hideTooltip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...DefaultTheme,
|
...DefaultTheme,
|
||||||
Layout() {
|
Layout() {
|
||||||
@@ -31,6 +106,14 @@ export default {
|
|||||||
// register global components
|
// register global components
|
||||||
app.component('Mermaid', Mermaid);
|
app.component('Mermaid', Mermaid);
|
||||||
app.component('Contributors', Contributors);
|
app.component('Contributors', Contributors);
|
||||||
|
|
||||||
|
// Add tooltips after app is mounted
|
||||||
|
app.mixin({
|
||||||
|
mounted() {
|
||||||
|
addMermaidChartTooltips();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
router.onBeforeRouteChange = (to) => {
|
router.onBeforeRouteChange = (to) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(window.location.origin + to);
|
const url = new URL(window.location.origin + to);
|
||||||
|
Reference in New Issue
Block a user