mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-14 04:49:44 +02:00
Sequence Diagram: Removed eval from popup handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import common from '../common/common';
|
import common from '../common/common';
|
||||||
|
import { addFunction } from '../../interactionDb';
|
||||||
|
|
||||||
export const drawRect = function (elem, rectData) {
|
export const drawRect = function (elem, rectData) {
|
||||||
const rectElem = elem.append('rect');
|
const rectElem = elem.append('rect');
|
||||||
@@ -25,6 +26,17 @@ const sanitizeUrl = function (s) {
|
|||||||
.replace(/javascript:/g, '');
|
.replace(/javascript:/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addPopupInteraction = (id, actorCnt) => {
|
||||||
|
addFunction(() => {
|
||||||
|
const arr = document.querySelectorAll(id);
|
||||||
|
arr[0].addEventListener('mouseover', function () {
|
||||||
|
popupMenuUpFunc('actor' + actorCnt + '_popup');
|
||||||
|
});
|
||||||
|
arr[0].addEventListener('mouseout', function () {
|
||||||
|
popupMenuDownFunc('actor' + actorCnt + '_popup');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMenus) {
|
export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMenus) {
|
||||||
if (actor.links === undefined || actor.links === null || Object.keys(actor.links).length === 0) {
|
if (actor.links === undefined || actor.links === null || Object.keys(actor.links).length === 0) {
|
||||||
return { height: 0, width: 0 };
|
return { height: 0, width: 0 };
|
||||||
@@ -39,21 +51,11 @@ export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMe
|
|||||||
displayValue = 'block !important';
|
displayValue = 'block !important';
|
||||||
}
|
}
|
||||||
|
|
||||||
// const a = function () {
|
|
||||||
// popupMenuUpFunc('actor' + actorCnt + '_popup');
|
|
||||||
// };
|
|
||||||
// const b = function () {
|
|
||||||
// popupMenuDownFunc('actor' + actorCnt + '_popup');
|
|
||||||
// };
|
|
||||||
const g = elem.append('g');
|
const g = elem.append('g');
|
||||||
g.attr('id', 'actor' + actorCnt + '_popup');
|
g.attr('id', 'actor' + actorCnt + '_popup');
|
||||||
g.attr('class', 'actorPopupMenu');
|
g.attr('class', 'actorPopupMenu');
|
||||||
g.attr('display', displayValue);
|
g.attr('display', displayValue);
|
||||||
g.attr('onmouseover', popupMenu('actor' + actorCnt + '_popup'));
|
addPopupInteraction('#actor' + actorCnt + '_popup', actorCnt);
|
||||||
g.attr('onmouseout', popdownMenu('actor' + actorCnt + '_popup'));
|
|
||||||
// g.on('onmouseover', a);
|
|
||||||
// g.on('onmouseout', b);
|
|
||||||
|
|
||||||
var actorClass = '';
|
var actorClass = '';
|
||||||
if (typeof rectData.class !== 'undefined') {
|
if (typeof rectData.class !== 'undefined') {
|
||||||
actorClass = ' ' + rectData.class;
|
actorClass = ' ' + rectData.class;
|
||||||
@@ -342,15 +344,10 @@ const drawActorTypeParticipant = function (elem, actor, conf) {
|
|||||||
|
|
||||||
g = boxpluslineGroup.append('g');
|
g = boxpluslineGroup.append('g');
|
||||||
actor.actorCnt = actorCnt;
|
actor.actorCnt = actorCnt;
|
||||||
// const a = function () {
|
|
||||||
// popupMenuUpFunc('actor' + actorCnt + '_popup');
|
|
||||||
// };
|
|
||||||
// const b = function () {
|
|
||||||
// popupMenuDownFunc('actor' + actorCnt + '_popup');
|
|
||||||
// };
|
|
||||||
if (actor.links != null) {
|
if (actor.links != null) {
|
||||||
g.attr('onmouseover', popupMenu('actor' + actorCnt + '_popup'));
|
g.attr('id', 'root-' + actorCnt);
|
||||||
g.attr('onmouseout', popdownMenu('actor' + actorCnt + '_popup'));
|
addPopupInteraction('#root-' + actorCnt, actorCnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,6 +394,7 @@ const drawActorTypeParticipant = function (elem, actor, conf) {
|
|||||||
actor.height = bounds.height;
|
actor.height = bounds.height;
|
||||||
height = bounds.height;
|
height = bounds.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return height;
|
return height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
10
src/interactionDb.js
Normal file
10
src/interactionDb.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
let interactionFunctions = [];
|
||||||
|
export const addFunction = (func) => {
|
||||||
|
interactionFunctions.push(func);
|
||||||
|
};
|
||||||
|
export const attachFunctions = () => {
|
||||||
|
interactionFunctions.forEach((f) => {
|
||||||
|
f();
|
||||||
|
});
|
||||||
|
interactionFunctions = [];
|
||||||
|
};
|
@@ -54,6 +54,7 @@ import journeyDb from './diagrams/user-journey/journeyDb';
|
|||||||
import journeyRenderer from './diagrams/user-journey/journeyRenderer';
|
import journeyRenderer from './diagrams/user-journey/journeyRenderer';
|
||||||
import journeyParser from './diagrams/user-journey/parser/journey';
|
import journeyParser from './diagrams/user-journey/parser/journey';
|
||||||
import errorRenderer from './errorRenderer';
|
import errorRenderer from './errorRenderer';
|
||||||
|
import { attachFunctions } from './interactionDb';
|
||||||
|
|
||||||
// import * as configApi from './config';
|
// import * as configApi from './config';
|
||||||
// // , {
|
// // , {
|
||||||
@@ -483,6 +484,7 @@ const render = function (id, _txt, cb, container) {
|
|||||||
} else {
|
} else {
|
||||||
log.debug('CB = undefined!');
|
log.debug('CB = undefined!');
|
||||||
}
|
}
|
||||||
|
attachFunctions();
|
||||||
|
|
||||||
const node = select('#d' + id).node();
|
const node = select('#d' + id).node();
|
||||||
if (node !== null && typeof node.remove === 'function') {
|
if (node !== null && typeof node.remove === 'function') {
|
||||||
|
Reference in New Issue
Block a user