mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Merge branch 'develop' of https://github.com/mermaid-js/mermaid into saurabh/refactor/convert-flowDb-to-class
This commit is contained in:
commit
f7fe8f2f59
8
.changeset/great-ghosts-rule.md
Normal file
8
.changeset/great-ghosts-rule.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
'mermaid': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Flowchart new syntax for node metadata bugs
|
||||||
|
|
||||||
|
- Incorrect label mapping for nodes when using `&`
|
||||||
|
- Syntax error when `}` with trailing spaces before new line
|
@ -1076,4 +1076,41 @@ end
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('New @ sytax for node metadata edge cases', () => {
|
||||||
|
it('should be possible to use @ syntax to add labels on multi nodes', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`flowchart TB
|
||||||
|
n2["label for n2"] & n4@{ label: "labe for n4"} & n5@{ label: "labe for n5"}
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('should be possible to use @ syntax to add labels with trail spaces and &', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`flowchart TB
|
||||||
|
n2["label for n2"] & n4@{ label: "labe for n4"} & n5@{ label: "labe for n5"}
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('should be possible to use @ syntax to add labels with trail spaces', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`flowchart TB
|
||||||
|
n2["label for n2"]
|
||||||
|
n4@{ label: "labe for n4"}
|
||||||
|
n5@{ label: "labe for n5"}
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('should be possible to use @ syntax to add labels with trail spaces and edge/link', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`flowchart TD
|
||||||
|
A["A"] --> B["for B"] & C@{ label: "for c"} & E@{label : "for E"}
|
||||||
|
D@{label: "for D"}
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,8 @@ import { setConfig } from '../../diagram-api/diagramAPI.js';
|
|||||||
import { FlowDB } from './flowDb.js';
|
import { FlowDB } from './flowDb.js';
|
||||||
import renderer from './flowRenderer-v3-unified.js';
|
import renderer from './flowRenderer-v3-unified.js';
|
||||||
// @ts-ignore: JISON doesn't support types
|
// @ts-ignore: JISON doesn't support types
|
||||||
import flowParser from './parser/flow.jison';
|
//import flowParser from './parser/flow.jison';
|
||||||
|
import flowParser from './parser/flowParser.ts';
|
||||||
import flowStyles from './styles.js';
|
import flowStyles from './styles.js';
|
||||||
|
|
||||||
export const diagram = {
|
export const diagram = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
import { cleanupComments } from '../../../diagram-api/comments.js';
|
import { cleanupComments } from '../../../diagram-api/comments.js';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
import { vi } from 'vitest';
|
import { vi } from 'vitest';
|
||||||
const spyOn = vi.spyOn;
|
const spyOn = vi.spyOn;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
@ -290,4 +290,43 @@ describe('when parsing directions', function () {
|
|||||||
expect(data4Layout.nodes[0].shape).toEqual('squareRect');
|
expect(data4Layout.nodes[0].shape).toEqual('squareRect');
|
||||||
expect(data4Layout.nodes[0].label).toEqual('This is a string with}');
|
expect(data4Layout.nodes[0].label).toEqual('This is a string with}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(' should be possible to use @ syntax to add labels on multi nodes', function () {
|
||||||
|
const res = flow.parser.parse(`flowchart TB
|
||||||
|
n2["label for n2"] & n4@{ label: "labe for n4"} & n5@{ label: "labe for n5"}
|
||||||
|
`);
|
||||||
|
|
||||||
|
const data4Layout = flow.parser.yy.getData();
|
||||||
|
expect(data4Layout.nodes.length).toBe(3);
|
||||||
|
expect(data4Layout.nodes[0].label).toEqual('label for n2');
|
||||||
|
expect(data4Layout.nodes[1].label).toEqual('labe for n4');
|
||||||
|
expect(data4Layout.nodes[2].label).toEqual('labe for n5');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be possible to use @ syntax to add labels on multi nodes with edge/link', function () {
|
||||||
|
const res = flow.parser.parse(`flowchart TD
|
||||||
|
A["A"] --> B["for B"] & C@{ label: "for c"} & E@{label : "for E"}
|
||||||
|
D@{label: "for D"}
|
||||||
|
`);
|
||||||
|
|
||||||
|
const data4Layout = flow.parser.yy.getData();
|
||||||
|
expect(data4Layout.nodes.length).toBe(5);
|
||||||
|
expect(data4Layout.nodes[0].label).toEqual('A');
|
||||||
|
expect(data4Layout.nodes[1].label).toEqual('for B');
|
||||||
|
expect(data4Layout.nodes[2].label).toEqual('for c');
|
||||||
|
expect(data4Layout.nodes[3].label).toEqual('for E');
|
||||||
|
expect(data4Layout.nodes[4].label).toEqual('for D');
|
||||||
|
});
|
||||||
|
it.skip(' should be possible to use @ syntax to add labels with trail spaces', function () {
|
||||||
|
const res = flow.parser.parse(
|
||||||
|
`flowchart TB
|
||||||
|
n2["label for n2"] & n4@{ label: "labe for n4"} & n5@{ label: "labe for n5"} `
|
||||||
|
);
|
||||||
|
|
||||||
|
const data4Layout = flow.parser.yy.getData();
|
||||||
|
expect(data4Layout.nodes.length).toBe(3);
|
||||||
|
expect(data4Layout.nodes[0].label).toEqual('label for n2');
|
||||||
|
expect(data4Layout.nodes[1].label).toEqual('labe for n4');
|
||||||
|
expect(data4Layout.nodes[2].label).toEqual('labe for n5');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
@ -399,7 +399,7 @@ shapeData:
|
|||||||
;
|
;
|
||||||
|
|
||||||
vertexStatement: vertexStatement link node shapeData
|
vertexStatement: vertexStatement link node shapeData
|
||||||
{ /* console.warn('vs shapeData',$vertexStatement.stmt,$node, $shapeData);*/ yy.addVertex($node[0],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData); yy.addLink($vertexStatement.stmt,$node,$link); $$ = { stmt: $node, nodes: $node.concat($vertexStatement.nodes) } }
|
{ /* console.warn('vs shapeData',$vertexStatement.stmt,$node, $shapeData);*/ yy.addVertex($node[$node.length-1],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData); yy.addLink($vertexStatement.stmt,$node,$link); $$ = { stmt: $node, nodes: $node.concat($vertexStatement.nodes) } }
|
||||||
| vertexStatement link node
|
| vertexStatement link node
|
||||||
{ /*console.warn('vs',$vertexStatement.stmt,$node);*/ yy.addLink($vertexStatement.stmt,$node,$link); $$ = { stmt: $node, nodes: $node.concat($vertexStatement.nodes) } }
|
{ /*console.warn('vs',$vertexStatement.stmt,$node);*/ yy.addLink($vertexStatement.stmt,$node,$link); $$ = { stmt: $node, nodes: $node.concat($vertexStatement.nodes) } }
|
||||||
| vertexStatement link node spaceList
|
| vertexStatement link node spaceList
|
||||||
@ -407,7 +407,7 @@ vertexStatement: vertexStatement link node shapeData
|
|||||||
|node spaceList { /*console.warn('vertexStatement: node spaceList', $node);*/ $$ = {stmt: $node, nodes:$node }}
|
|node spaceList { /*console.warn('vertexStatement: node spaceList', $node);*/ $$ = {stmt: $node, nodes:$node }}
|
||||||
|node shapeData {
|
|node shapeData {
|
||||||
/*console.warn('vertexStatement: node shapeData', $node[0], $shapeData);*/
|
/*console.warn('vertexStatement: node shapeData', $node[0], $shapeData);*/
|
||||||
yy.addVertex($node[0],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData);
|
yy.addVertex($node[$node.length-1],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData);
|
||||||
$$ = {stmt: $node, nodes:$node, shapeData: $shapeData}
|
$$ = {stmt: $node, nodes:$node, shapeData: $shapeData}
|
||||||
}
|
}
|
||||||
|node { /* console.warn('vertexStatement: single node', $node); */ $$ = {stmt: $node, nodes:$node }}
|
|node { /* console.warn('vertexStatement: single node', $node); */ $$ = {stmt: $node, nodes:$node }}
|
||||||
@ -416,7 +416,7 @@ vertexStatement: vertexStatement link node shapeData
|
|||||||
node: styledVertex
|
node: styledVertex
|
||||||
{ /*console.warn('nod', $styledVertex);*/ $$ = [$styledVertex];}
|
{ /*console.warn('nod', $styledVertex);*/ $$ = [$styledVertex];}
|
||||||
| node shapeData spaceList AMP spaceList styledVertex
|
| node shapeData spaceList AMP spaceList styledVertex
|
||||||
{ yy.addVertex($node[0],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData); $$ = $node.concat($styledVertex); /*console.warn('pip2', $node[0], $styledVertex, $$);*/ }
|
{ yy.addVertex($node[$node.length-1],undefined,undefined,undefined, undefined,undefined, undefined,$shapeData); $$ = $node.concat($styledVertex); /*console.warn('pip2', $node[0], $styledVertex, $$);*/ }
|
||||||
| node spaceList AMP spaceList styledVertex
|
| node spaceList AMP spaceList styledVertex
|
||||||
{ $$ = $node.concat($styledVertex); /*console.warn('pip', $node[0], $styledVertex, $$);*/ }
|
{ $$ = $node.concat($styledVertex); /*console.warn('pip', $node[0], $styledVertex, $$);*/ }
|
||||||
;
|
;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { cleanupComments } from '../../../diagram-api/comments.js';
|
import { cleanupComments } from '../../../diagram-api/comments.js';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
|
12
packages/mermaid/src/diagrams/flowchart/parser/flowParser.ts
Normal file
12
packages/mermaid/src/diagrams/flowchart/parser/flowParser.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// @ts-ignore: JISON doesn't support types
|
||||||
|
import flowJisonParser from './flow.jison';
|
||||||
|
|
||||||
|
const newParser = Object.assign({}, flowJisonParser);
|
||||||
|
|
||||||
|
newParser.parse = (src: string): unknown => {
|
||||||
|
// remove the trailing whitespace after closing curly braces when ending a line break
|
||||||
|
const newSrc = src.replace(/}\s*\n/g, '}\n');
|
||||||
|
return flowJisonParser.parse(newSrc);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default newParser;
|
@ -1,5 +1,5 @@
|
|||||||
import { FlowDB } from '../flowDb.js';
|
import { FlowDB } from '../flowDb.js';
|
||||||
import flow from './flow.jison';
|
import flow from './flowParser.ts';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user