Compare commits

..

17 Commits

Author SHA1 Message Date
Knut Sveidqvist
9c88c785cb Fix for issues in errorhandling and class diagrams after refactoring 2022-09-16 14:05:15 +02:00
Knut Sveidqvist
2d9f25b163 Merge pull request #3469 from mermaid-js/sidv/mergeRelease
Merge release 9.1.7
2022-09-16 11:22:35 +02:00
Knut Sveidqvist
10d9b88965 Merge pull request #3466 from mermaid-js/sidv/removeGA
Replace GoogleAnalytics with Plausible
2022-09-16 08:54:38 +02:00
Knut Sveidqvist
207235ea83 Merge pull request #3464 from aloisklink/fix/3463-support-single-char-branch-names
fix(git): support single character branch names
2022-09-16 08:53:12 +02:00
Knut Sveidqvist
97ab62514c Merge pull request #3461 from mermaid-js/mindmap_warning
Cleanup unused variables and some commented out code
2022-09-16 08:44:01 +02:00
Sidharth Vinod
5c2a45cd4d Replace GoogleAnalytics with Plausible 2022-09-15 17:48:00 +05:30
dependabot[bot]
064c3134e5 chore(deps): bump dompurify from 2.3.10 to 2.4.0 (#3444)
Bumps [dompurify](https://github.com/cure53/DOMPurify) from 2.3.10 to 2.4.0.
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/2.3.10...2.4.0)

---
updated-dependencies:
- dependency-name: dompurify
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-15 07:42:28 +02:00
dependabot[bot]
6340c157e8 chore(deps): bump stylis from 4.1.1 to 4.1.2 (#3439)
Bumps [stylis](https://github.com/thysultan/stylis.js) from 4.1.1 to 4.1.2.
- [Release notes](https://github.com/thysultan/stylis.js/releases)
- [Commits](https://github.com/thysultan/stylis.js/compare/v4.1.1...v4.1.2)

---
updated-dependencies:
- dependency-name: stylis
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-15 07:42:13 +02:00
dependabot[bot]
e9239f83e9 chore(deps-dev): bump webpack-dev-server from 4.10.1 to 4.11.0 (#3450)
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 4.10.1 to 4.11.0.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v4.10.1...v4.11.0)

---
updated-dependencies:
- dependency-name: webpack-dev-server
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Tested-by: Alois Klink <19716675+aloisklink@users.noreply.github.com>
2022-09-15 01:55:27 +01:00
Alois Klink
59c69600e8 fix(git): support single character branch names
In gitGraph, add support branch names that only have a single
character.

The branch regex is checking for a starting character, and an
ending character, so it currently needs at least two characters.

I've wrapped everything except the first character in a `()?` to fix
this.

There are some really complicated regexes that do match what
valid git branches are (see https://stackoverflow.com/a/12093994), but
I'm reluctant to add them in, since it will be a pain to test all
the different edgecases.

Hopefully https://github.com/mermaid-js/mermaid/pull/3432 might be used
in the future to make a better gitgraph parser!
2022-09-15 01:05:11 +01:00
Sidharth Vinod
539ee49594 Merge remote-tracking branch 'origin/release/9.1.7' into sidv/mergeRelease
* origin/release/9.1.7:
  Release 9.1.7
  Fix for broken rendering test
  Fix for issue #3428, load the configured diagrams even when initialize has not been called.
2022-09-14 11:11:12 +05:30
Knut Sveidqvist
0c0468123f Release 9.1.7 2022-09-13 19:55:34 +02:00
ashishj
50da58afe0 Fix for broken rendering test 2022-09-13 19:18:12 +02:00
Knut Sveidqvist
0f56c9a85d Fix for issue #3428, load the configured diagrams even when initialize has not been called. 2022-09-09 13:37:37 +02:00
Knut Sveidqvist
e5212c25f5 Merge pull request #3398 from mermaid-js/3395_fix_error_handling
Re-enabling error graph
2022-09-05 15:13:49 +02:00
Knut Sveidqvist
5584fef1b0 #3395 Renabling the error graph which is rendered on error 2022-09-02 14:05:31 +02:00
Knut Sveidqvist
98f37d64ea #3395 Fix for lopp stopping at first failure 2022-09-02 12:45:22 +02:00
17 changed files with 157 additions and 58 deletions

View File

@@ -38,7 +38,15 @@
</style>
</head>
<body>
<pre class="mermaid2" style="width: 50%">
flowchart LR
a ---
</pre>
<pre class="mermaid" style="width: 50%">
flowchart LR
a2 ---
</pre>
<pre class="mermaid2" style="width: 50%">
flowchart LR
classDef aPID stroke:#4e4403,fill:#fdde29,color:#4e4403,rx:5px,ry:5px;
classDef crm stroke:#333333,fill:#DCDCDC,color:#333333,rx:5px,ry:5px;
@@ -73,7 +81,31 @@ flowchart TD
</pre>
<pre class="mermaid" style="width: 50%">
flowchart TD
id
release-branch[Create Release Branch]:::relClass
develop-branch[Update Develop Branch]:::relClass
github-release-draft[GitHub Release Draft]:::relClass
trigger-pipeline[Trigger Jenkins pipeline]:::fixClass
github-release[GitHub Release]:::postClass
build-ready --> release-branch
build-ready --> develop-branch
release-branch --> jenkins-release-build
jenkins-release-build --> github-release-draft
jenkins-release-build --> install-release
install-release --> verify-release
jenkins-release-build --> announce
github-release-draft --> github-release
verify-release --> verify-check
verify-check -- Yes --> github-release
verify-check -- No --> release-fix
release-fix --> release-branch-pr
verify-check -- No --> delete-artifacts
release-branch-pr --> trigger-pipeline
delete-artifacts --> trigger-pipeline
trigger-pipeline --> jenkins-release-build
</pre>
<pre class="mermaid2" style="width: 50%">
flowchart LR
@@ -357,6 +389,11 @@ flowchart TD
document.getElementsByTagName('body')[0].appendChild(div);
}
mermaid.parseError = function (err, hash) {
console.error('In parse error:');
console.error(err);
};
</script>
</body>
</html>

View File

@@ -47,9 +47,17 @@
<div>Security check</div>
<div class="flex">
<pre id="diagram" class="mermaid">
sequenceDiagram
Nothing:Valid;
</pre>
flowchart TD
A[myClass1] --> B[default] & C[default]
B[default] & C[default] --> D[myClass2]
classDef default stroke-width:2px,fill:none,stroke:silver
classDef node color:red
classDef myClass1 color:#0000ff
classDef myClass2 stroke:#0000ff,fill:#ccccff
class A myClass1
class D myClass2
</pre
>
<div id="res" class=""></div>
</div>
<script src="./mermaid.js"></script>
@@ -59,6 +67,7 @@ sequenceDiagram
};
mermaid.initialize({
startOnLoad: false,
logLevel: 0,
// themeVariables: {relationLabelColor: 'red'}
});
function callback() {

View File

@@ -21,22 +21,13 @@
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css"
/>
<script src="//cdn.jsdelivr.net/npm/mermaid@9.1.6/dist/mermaid.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script>
<!-- <script src="http://localhost:9000/mermaid.js"></script> -->
<script>
// prettier-ignore
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-153180559-1', 'auto');
if (location) {
ga('send', 'pageview', location.hash);
}
</script>
<script
defer
data-domain="mermaid-js.github.io"
src="https://plausible.io/js/plausible.js"
></script>
<script>
var require = {
paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.29.1/min/vs' },

View File

@@ -67,13 +67,13 @@
"d3": "^7.0.0",
"dagre": "^0.8.5",
"dagre-d3": "^0.6.4",
"dompurify": "2.3.10",
"dompurify": "2.4.0",
"fast-clone": "^1.5.13",
"graphlib": "^2.1.8",
"khroma": "^2.0.0",
"moment-mini": "^2.24.0",
"non-layered-tidy-tree-layout": "^2.0.2",
"stylis": "^4.0.10"
"stylis": "^4.1.2"
},
"devDependencies": {
"@applitools/eyes-cypress": "^3.25.7",
@@ -126,7 +126,7 @@
"unist-util-flatmap": "^1.0.0",
"webpack": "^5.53.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^4.10.1",
"webpack-dev-server": "^4.11.0",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0"
},

View File

@@ -119,7 +119,7 @@ const dependency = (elem, type) => {
.append('path')
.attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
};
const lollipop = (elem, type, id) => {
const lollipop = (elem, type) => {
elem
.append('defs')
.append('marker')

View File

@@ -228,9 +228,9 @@ const config: Partial<MermaidConfig> = {
* Decides which rendering engine that is to be used for the rendering. Legal values are:
* dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid
*
* Default value: 'dagre-d3'
* Default value: 'dagre-wrapper'
*/
defaultRenderer: 'dagre-d3',
defaultRenderer: 'dagre-wrapper',
},
/** The object containing configurations specific for sequence diagrams */
@@ -387,7 +387,8 @@ const config: Partial<MermaidConfig> = {
*
* **Notes:**
*
* This will display arrows that start and begin at the same node as right angles, rather than a curve
* This will display arrows that start and begin at the same node as right angles, rather than a
* curve
*
* Default value: false
*/
@@ -802,7 +803,8 @@ const config: Partial<MermaidConfig> = {
*
* **Notes:**
*
* This will display arrows that start and begin at the same node as right angles, rather than a curves
* This will display arrows that start and begin at the same node as right angles, rather than a
* curves
*
* Default value: false
*/

View File

@@ -97,7 +97,33 @@ import journeyDb from '../diagrams/user-journey/journeyDb';
import journeyRenderer from '../diagrams/user-journey/journeyRenderer';
import journeyStyles from '../diagrams/user-journey/styles';
import errorRenderer from '../diagrams/error/errorRenderer';
import errorStyles from '../diagrams/error/styles';
export const addDiagrams = () => {
registerDiagram(
'error',
// Special diagram with error messages but setup as a regular diagram
{
db: {
clear: () => {
// Quite ok, clear needs to be there for error to work as a regular diagram
},
},
styles: errorStyles,
renderer: errorRenderer,
parser: {
parser: { yy: {} },
parse: () => {
// no op
},
},
init: () => {
// no op
},
},
(text) => text.toLowerCase().trim() === 'error'
);
registerDiagram(
'c4',
{

View File

@@ -1,7 +1,7 @@
/** Created by knut on 14-12-11. */
import { select } from 'd3';
import { log } from './logger';
import { getErrorMessage } from './utils';
import { log } from '../../logger';
import { getErrorMessage } from '../../utils';
let conf = {};
@@ -17,10 +17,11 @@ export const setConf = function (cnf: any) {
/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
*
* @param text
* @param {string} id The text for the error
* @param {string} mermaidVersion The version
*/
export const draw = (id: string, mermaidVersion: string) => {
export const draw = (text: string, id: string, mermaidVersion: string) => {
try {
log.debug('Renering svg for syntax error\n');
@@ -72,22 +73,22 @@ export const draw = (id: string, mermaidVersion: string) => {
g.append('text') // text label for the x axis
.attr('class', 'error-text')
.attr('x', 1240)
.attr('x', 1440)
.attr('y', 250)
.attr('font-size', '150px')
.style('text-anchor', 'middle')
.text('Syntax error in graph');
g.append('text') // text label for the x axis
.attr('class', 'error-text')
.attr('x', 1050)
.attr('x', 1250)
.attr('y', 400)
.attr('font-size', '100px')
.style('text-anchor', 'middle')
.text('mermaid version ' + mermaidVersion);
svg.attr('height', 100);
svg.attr('width', 400);
svg.attr('viewBox', '768 0 512 512');
svg.attr('width', 500);
svg.attr('viewBox', '768 0 912 512');
} catch (e) {
log.error('Error while rendering info diagram');
log.error(getErrorMessage(e));

View File

@@ -0,0 +1,3 @@
const getStyles = () => ``;
export default getStyles;

View File

@@ -372,14 +372,16 @@ describe('when parsing a gitGraph', function () {
branch cherry-pick03
branch branch/example-branch
branch merge/test_merge
%% single character branch name
branch A
`;
parser.parse(str);
const commits = parser.yy.getCommits();
expect(Object.keys(commits).length).toBe(1);
expect(parser.yy.getCurrentBranch()).toBe('merge/test_merge');
expect(parser.yy.getCurrentBranch()).toBe('A');
expect(parser.yy.getDirection()).toBe('LR');
expect(Object.keys(parser.yy.getBranches()).length).toBe(6);
expect(Object.keys(parser.yy.getBranches()).length).toBe(7);
expect(Object.keys(parser.yy.getBranches())).toEqual(
expect.arrayContaining([
'branch01',
@@ -387,6 +389,7 @@ describe('when parsing a gitGraph', function () {
'cherry-pick03',
'branch/example-branch',
'merge/test_merge',
'A',
])
);
});

View File

@@ -91,7 +91,9 @@ const drawCommits = (svg, commits, modifyGraph) => {
if (modifyGraph) {
let typeClass;
let commitSymbolType =
typeof commit.customType !== 'undefined' ? commit.customType : commit.type;
typeof commit.customType !== 'undefined' && commit.customType !== ''
? commit.customType
: commit.type;
switch (commitSymbolType) {
case commitType.NORMAL:
typeClass = 'commit-normal';

View File

@@ -61,7 +61,7 @@ checkout(?=\s|$) return 'CHECKOUT';
<string>["] this.popState();
<string>[^"]* return 'STR';
[0-9]+(?=\s|$) return 'NUM';
\w[-\./\w]*[-\w] return 'ID'; // only a subset of https://git-scm.com/docs/git-check-ref-format
\w([-\./\w]*[-\w])? return 'ID'; // only a subset of https://git-scm.com/docs/git-check-ref-format
<<EOF>> return 'EOF';
\s+ /* skip all whitespace */ // lowest priority so we can use lookaheads in earlier regex

View File

@@ -95,9 +95,11 @@ const initThrowsErrors = function (
const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed);
let txt;
const errors = [];
// element is the current div with mermaid class
for (const element of Array.from(nodesToProcess)) {
log.info('Rendering diagram: ' + element.id);
/*! Check if previously processed */
if (element.getAttribute('data-processed')) {
continue;
@@ -135,10 +137,17 @@ const initThrowsErrors = function (
} catch (error) {
log.warn('Catching Error (bootstrap)', error);
// @ts-ignore: TODO Fix ts errors
// TODO: We should be throwing an error object.
throw { error, message: error.str };
const mermaidError = { error, str: error.str, hash: error.hash, message: error.str };
if (typeof mermaid.parseError === 'function') {
mermaid.parseError(mermaidError);
}
errors.push(mermaidError);
}
}
if (errors.length > 0) {
// TODO: We should be throwing an error object.
throw errors[0];
}
};
const initialize = function (config: MermaidConfig) {

View File

@@ -26,7 +26,7 @@ import flowDb from './diagrams/flowchart/flowDb';
import flowRenderer from './diagrams/flowchart/flowRenderer';
import ganttDb from './diagrams/gantt/ganttDb';
import Diagram from './Diagram';
import errorRenderer from './errorRenderer';
import errorRenderer from './diagrams/error/errorRenderer';
import { attachFunctions } from './interactionDb';
import { log, setLogLevel } from './logger';
import getStyles from './styles';
@@ -124,6 +124,10 @@ const render = function (
cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void,
container?: Element
): void {
if (!hasLoadedDiagrams) {
addDiagrams();
hasLoadedDiagrams = true;
}
configApi.reset();
text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;;
const graphInit = utils.detectInit(text);
@@ -228,7 +232,14 @@ const render = function (
text = encodeEntities(text);
// Important that we do not create the diagram until after the directives have been included
const diag = new Diagram(text);
let diag;
let parseEncounteredException;
try {
diag = new Diagram(text);
} catch (error) {
diag = new Diagram('error');
parseEncounteredException = error;
}
// Get the tmp element containing the the svg
const element = root.select('#d' + id).node();
const graphType = diag.type;
@@ -301,7 +312,7 @@ const render = function (
try {
diag.renderer.draw(text, id, pkg.version, diag);
} catch (e) {
errorRenderer.draw(id, pkg.version);
errorRenderer.draw(text, id, pkg.version);
throw e;
}
@@ -371,6 +382,10 @@ const render = function (
node.remove();
}
if (parseEncounteredException) {
throw parseEncounteredException;
}
return svgCode;
};

View File

@@ -1,5 +1,6 @@
import classDiagram from './diagrams/class/styles';
import er from './diagrams/er/styles';
import error from './diagrams/error/styles';
import flowchart from './diagrams/flowchart/styles';
import gantt from './diagrams/gantt/styles';
// import gitGraph from './diagrams/git/styles';
@@ -28,6 +29,7 @@ const themes: Record<string, any> = {
info,
pie,
er,
error,
journey,
requirement,
c4,

View File

@@ -71,7 +71,7 @@ const directiveWithoutOpen =
* g-->h
* ```
* @param {string} text The text defining the graph
* @param {any} cnf
* @param {any} config
* @returns {object} The json object representing the init passed to mermaid.initialize()
*/
export const detectInit = function (text: string, config?: MermaidConfig): MermaidConfig {
@@ -392,7 +392,6 @@ const calcTerminalLabelPosition = (terminalMarkerSize, position, _points) => {
}
points.forEach((point) => {
totalDistance += distance(point, prevPoint);
prevPoint = point;
});
@@ -746,7 +745,7 @@ let decoder;
* Decodes HTML, source: {@link https://github.com/shrpne/entity-decode/blob/v2.0.1/browser.js}
*
* @param {string} html HTML as a string
* @returns Unescaped HTML
* @returns {string} Unescaped HTML
*/
export const entityDecode = function (html) {
decoder = decoder || document.createElement('div');

View File

@@ -5370,10 +5370,10 @@ domhandler@^5.0.1, domhandler@^5.0.2:
dependencies:
domelementtype "^2.3.0"
dompurify@2.3.10:
version "2.3.10"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.3.10.tgz#901f7390ffe16a91a5a556b94043314cd4850385"
integrity sha512-o7Fg/AgC7p/XpKjf/+RC3Ok6k4St5F7Q6q6+Nnm3p2zGWioAY6dh0CbbuwOhH2UcSzKsdniE/YnE2/92JcsA+g==
dompurify@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.4.0.tgz#c9c88390f024c2823332615c9e20a453cf3825dd"
integrity sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==
domutils@^3.0.1:
version "3.0.1"
@@ -11270,10 +11270,10 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
stylis@^4.0.10:
version "4.1.1"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.1.1.tgz#e46c6a9bbf7c58db1e65bb730be157311ae1fe12"
integrity sha512-lVrM/bNdhVX2OgBFNa2YJ9Lxj7kPzylieHd3TNjuGE0Re9JB7joL5VUKOVH1kdNNJTgGPpT8hmwIAPLaSyEVFQ==
stylis@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.1.2.tgz#870b3c1c2275f51b702bb3da9e94eedad87bba41"
integrity sha512-Nn2CCrG2ZaFziDxaZPN43CXqn+j7tcdjPFCkRBkFue8QYXC2HdEwnw5TCBo4yQZ2WxKYeSi0fdoOrtEqgDrXbA==
subarg@^1.0.0:
version "1.0.0"
@@ -12299,10 +12299,10 @@ webpack-dev-middleware@^5.3.1:
range-parser "^1.2.1"
schema-utils "^4.0.0"
webpack-dev-server@^4.10.1:
version "4.10.1"
resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.10.1.tgz#124ac9ac261e75303d74d95ab6712b4aec3e12ed"
integrity sha512-FIzMq3jbBarz3ld9l7rbM7m6Rj1lOsgq/DyLGMX/fPEB1UBUPtf5iL/4eNfhx8YYJTRlzfv107UfWSWcBK5Odw==
webpack-dev-server@^4.11.0:
version "4.11.0"
resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.11.0.tgz#290ee594765cd8260adfe83b2d18115ea04484e7"
integrity sha512-L5S4Q2zT57SK7tazgzjMiSMBdsw+rGYIX27MgPgx7LDhWO0lViPrHKoLS7jo5In06PWYAhlYu3PbyoC6yAThbw==
dependencies:
"@types/bonjour" "^3.5.9"
"@types/connect-history-api-fallback" "^1.3.5"