Skip to content

Commit 384afc1

Browse files
committed
Merge branch '2654_sandbox' into release/8.14.0
2 parents 0185a74 + fa55b7c commit 384afc1

File tree

8 files changed

+138
-32
lines changed

8 files changed

+138
-32
lines changed

cypress/platform/knsv.html

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
</style>
2626
</head>
2727
<body>
28-
<div id="apa" style="background: aliceblue; width: 150px; height: 75px;">APA</div>
2928
<div class="mermaid2" style="width: 100%;">
3029
pie title Pets adopted by volunteers
3130
"Dogs" : 386
3231
"Cats" : 85
3332
"Rats" : 15
3433
</div>
35-
<div class="mermaid" style="width: 100%;">
34+
<div class="mermaid2" style="width: 100%;">
3635
gantt
3736
title Adding GANTT diagram functionality to mermaid
3837
excludes :excludes the named dates/days from being included in a charted task..
@@ -64,7 +63,7 @@
6463
commit
6564
merge newbranch
6665
</div>
67-
<div class="mermaid" style="width: 100%;">
66+
<div class="mermaid2" style="width: 100%;">
6867
sequenceDiagram
6968
participant a as Alice
7069
participant j as John
@@ -146,6 +145,76 @@
146145
end
147146
</div>
148147
<div class="mermaid2" style="width: 100%;">
148+
flowchart TB
149+
Function-->URL
150+
click Function clickByFlow "Add a div"
151+
click URL "https://mermaid-js.github.io/mermaid/#/" "Visit <strong>mermaid docs</strong>" _blank
152+
</div>
153+
<div class="mermaid2" style="width: 100%;">
154+
classDiagram-v2
155+
class Test
156+
class ShapeLink
157+
link ShapeLink "https://mermaid-js.github.io/mermaid/#/" "This is a tooltip for a link"
158+
class ShapeCallback
159+
callback ShapeCallback "clickByClass" "This is a tooltip for a callback"
160+
</div>
161+
<div class="mermaid" style="width: 100%;">
162+
gantt
163+
dateFormat YYYY-MM-DD
164+
axisFormat %d/%m
165+
title Adding GANTT diagram to mermaid
166+
excludes weekdays 2014-01-10
167+
168+
section A section
169+
Completed task :done, des1, 2014-01-06,2014-01-08
170+
Active task :active, des2, 2014-01-09, 3d
171+
Future task : des3, after des2, 5d
172+
Future task2 : des4, after des3, 5d
173+
174+
section Critical tasks
175+
Completed task in the critical line :crit, done, 2014-01-06,24h
176+
Implement parser and jison :crit, done, after des1, 2d
177+
Create tests for parser :crit, active, 3d
178+
Future task in critical line :crit, 5d
179+
Create tests for renderer :2d
180+
Add to mermaid :1d
181+
182+
section Documentation
183+
Describe gantt syntax :active, a1, after des1, 3d
184+
Add gantt diagram to demo page :after a1 , 20h
185+
Add another diagram to demo page :doc1, after a1 , 48h
186+
187+
section Clickable
188+
Visit mermaidjs :active, cl1, 2014-01-07,2014-01-10
189+
Calling a Callback (look at the console log) :cl2, after cl1, 3d
190+
Calling a Callback with args :cl3, after cl1, 3d
191+
192+
click cl1 href "https://mermaid-js.github.io/mermaid/#/"
193+
click cl2 call clickByGantt()
194+
click cl3 call clickByGantt("test1", test2, test3)
195+
196+
section Last section
197+
Describe gantt syntax :after doc1, 3d
198+
Add gantt diagram to demo page : 20h
199+
Add another diagram to demo page : 48h
200+
</div>
201+
<div class="mermaid2" style="width: 100%;">
202+
classDiagram
203+
Class01 <|-- AveryLongClass : Cool
204+
Class09 --> C2 : Where am i?
205+
Class09 --* C3
206+
Class09 --|> Class07
207+
Class07 : equals()
208+
Class07 : Object[] elementData
209+
Class01 : size()
210+
Class01 : int chimp
211+
Class01 : int gorilla
212+
class Class10 {
213+
int id
214+
size()
215+
}
216+
</div>
217+
<div class="mermaid2" style="width: 100%;">
149218
stateDiagram
150219
[*] --> S1
151220
state "Some long name" as S1
@@ -181,7 +250,7 @@
181250
};
182251
mermaid.initialize({
183252
// theme: 'dark',
184-
theme: 'forest',
253+
// theme: 'forest',
185254
// arrowMarkerAbsolute: true,
186255
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
187256
flowchart: {
@@ -192,6 +261,7 @@
192261
},
193262
class: {
194263
defaultRenderer: 'dagre-d3',
264+
htmlLabels: true,
195265
},
196266
// gantt: { axisFormat: '%m/%d/%Y' },
197267
sequence: { actorFontFamily: 'courier', actorMargin: 50, showSequenceNumbers: false },
@@ -212,6 +282,15 @@
212282
function callback() {
213283
alert('It worked');
214284
}
285+
286+
function clickByFlow(elemName) {
287+
const div = document.createElement('div');
288+
div.className = 'created-by-click';
289+
div.style = 'padding: 20px; background: green; color: white;';
290+
div.innerText = 'Clicked By Flow';
291+
292+
document.getElementsByTagName('body')[0].appendChild(div);
293+
}
215294
</script>
216295
</body>
217296
</html>

src/dagre-wrapper/nodes.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,13 @@ export const insertNode = (elem, node, dir) => {
967967

968968
// Add link when appropriate
969969
if (node.link) {
970-
newEl = elem
971-
.insert('svg:a')
972-
.attr('xlink:href', node.link)
973-
.attr('target', node.linkTarget || '_blank');
970+
let target;
971+
if (getConfig().securityLevel === 'sandbox') {
972+
target = '_top';
973+
} else if (node.linkTarget) {
974+
target = node.linkTarget || '_blank';
975+
}
976+
newEl = elem.insert('svg:a').attr('xlink:href', node.link).attr('target', target);
974977
el = shapes[node.shape](newEl, node, dir);
975978
} else {
976979
el = shapes[node.shape](elem, node, dir);

src/diagrams/class/classDb.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ export const setLink = function (ids, linkStr, target) {
213213
if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
214214
if (typeof classes[id] !== 'undefined') {
215215
classes[id].link = utils.formatUrl(linkStr, config);
216-
if (typeof target === 'string') {
216+
if (config.securityLevel === 'sandbox') {
217+
classes[id].linkTarget = '_top';
218+
} else if (typeof target === 'string') {
217219
classes[id].linkTarget = target;
218220
} else {
219221
classes[id].linkTarget = '_blank';

src/diagrams/flowchart/flowRenderer-v2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ export const draw = function (text, id) {
496496
link.setAttributeNS('http://www.w3.org/2000/svg', 'class', vertex.classes.join(' '));
497497
link.setAttributeNS('http://www.w3.org/2000/svg', 'href', vertex.link);
498498
link.setAttributeNS('http://www.w3.org/2000/svg', 'rel', 'noopener');
499-
if (vertex.linkTarget) {
499+
if (securityLevel === 'sandbox') {
500+
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', '_top');
501+
} else if (vertex.linkTarget) {
500502
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', vertex.linkTarget);
501503
}
502504

src/diagrams/flowchart/flowRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,9 @@ export const draw = function (text, id) {
506506
link.setAttributeNS('http://www.w3.org/2000/svg', 'class', vertex.classes.join(' '));
507507
link.setAttributeNS('http://www.w3.org/2000/svg', 'href', vertex.link);
508508
link.setAttributeNS('http://www.w3.org/2000/svg', 'rel', 'noopener');
509-
if (vertex.linkTarget) {
509+
if (securityLevel === 'sandbox') {
510+
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', '_top');
511+
} else if (vertex.linkTarget) {
510512
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', vertex.linkTarget);
511513
}
512514

src/diagrams/gantt/ganttDb.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let axisFormat = '';
1010
let todayMarker = '';
1111
let includes = [];
1212
let excludes = [];
13+
let links = {};
1314
let title = '';
1415
let sections = [];
1516
let tasks = [];
@@ -44,6 +45,7 @@ export const clear = function () {
4445
inclusiveEndDates = false;
4546
topAxis = false;
4647
lastOrder = 0;
48+
links = {};
4749
};
4850

4951
export const setAxisFormat = function (txt) {
@@ -101,6 +103,10 @@ export const getExcludes = function () {
101103
return excludes;
102104
};
103105

106+
export const getLinks = function () {
107+
return links;
108+
};
109+
104110
export const setTitle = function (txt) {
105111
title = txt;
106112
};
@@ -505,6 +511,7 @@ export const setLink = function (ids, _linkStr) {
505511
pushFun(id, () => {
506512
window.open(linkStr, '_self');
507513
});
514+
links[id] = linkStr;
508515
}
509516
});
510517
setClass(ids, 'clickable');
@@ -642,6 +649,7 @@ export default {
642649
getExcludes,
643650
setClickEvent,
644651
setLink,
652+
getLinks,
645653
bindFunctions,
646654
durationToDate,
647655
isInvalidDate,

src/diagrams/gantt/ganttRenderer.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export const draw = function (text, id) {
185185
// Draw the rects representing the tasks
186186
const rectangles = svg.append('g').selectAll('rect').data(theArray).enter();
187187

188+
const links = ganttDb.getLinks();
189+
190+
// Render the tasks with links
191+
// Render the other tasks
188192
rectangles
189193
.append('rect')
190194
.attr('id', function (d) {
@@ -381,6 +385,32 @@ export const draw = function (text, id) {
381385
return classStr + ' taskText taskText' + secNum + ' ' + taskType + ' width-' + textWidth;
382386
}
383387
});
388+
389+
const securityLevel = getConfig().securityLevel;
390+
391+
// Wrap the tasks in an a tag for working links without javascript
392+
if (securityLevel === 'sandbox') {
393+
let sandboxElement;
394+
sandboxElement = select('#i' + id);
395+
const root = select(sandboxElement.nodes()[0].contentDocument.body);
396+
const doc = sandboxElement.nodes()[0].contentDocument;
397+
398+
rectangles
399+
.filter(function (d) {
400+
return typeof links[d.id] !== 'undefined';
401+
})
402+
.each(function (o) {
403+
var taskRect = doc.querySelector('#' + o.id);
404+
var taskText = doc.querySelector('#' + o.id + '-text');
405+
const oldParent = taskRect.parentNode;
406+
var Link = doc.createElement('a');
407+
Link.setAttribute('xlink:href', links[o.id]);
408+
Link.setAttribute('target', '_top');
409+
oldParent.appendChild(Link);
410+
Link.appendChild(taskRect);
411+
Link.appendChild(taskText);
412+
});
413+
}
384414
}
385415
/**
386416
* @param theGap

src/mermaidAPI.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -518,32 +518,12 @@ const render = function (id, _txt, cb, container) {
518518
svgCode = svgCode.replace(/marker-end="url\(.*?#/g, 'marker-end="url(#', 'g');
519519
}
520520

521-
// const iframe = document.createElement('iframe');
522-
// iframe.setAttribute('frameBorder', '0');
523-
// iframe.setAttribute('id', id);
524-
// iframe.setAttribute('sanbox', '');
525-
// iframe.setAttribute('src', 'about:blank');
526-
// iframe.contentWindow.document.body = svgCode;
527-
// element.innerHTML = '';
528-
// // element.appendChild(iframe);
529-
// // element.innerHTML = '<iframe sandbox>' + svgCode + '</iframe>';
530-
531521
svgCode = decodeEntities(svgCode);
532522

533523
// Fix for when the br tag is used
534524
svgCode = svgCode.replace(/<br>/g, '<br/>');
535525

536526
if (cnf.securityLevel === 'sandbox') {
537-
// const newSvgCode =
538-
// '<iframe id="' +
539-
// id +
540-
// '" sandbox src="data:text/html;base64,' +
541-
// btoa(btoa(unescape(encodeURIComponent(svgCode)))) +
542-
// '"></iframe>';
543-
// svgCode = newSvgCode;
544-
// svgCode = `<iframe src="data:text/html;base64,V2VsY29tZSB0byA8Yj5iYXNlNjQuZ3VydTwvYj4h">
545-
// The “iframe” tag is not supported by your browser.
546-
// </iframe>`;
547527
let svgEl = root.select('#d' + id + ' svg').node();
548528
let width = '100%';
549529
let height = '100%';
@@ -553,7 +533,7 @@ const render = function (id, _txt, cb, container) {
553533
}
554534
svgCode = `<iframe style="width:${width};height:${height};border:0;margin:0;" src="data:text/html;base64,${btoa(
555535
'<body style="margin:0">' + svgCode + '</body>'
556-
)}" sandbox>
536+
)}" sandbox="allow-top-navigation-by-user-activation allow-popups">
557537
The “iframe” tag is not supported by your browser.
558538
</iframe>`;
559539
}

0 commit comments

Comments
 (0)