Compare commits

..

51 Commits

Author SHA1 Message Date
Knut Sveidqvist
25c9e499b3 Merge branch 'develop' into layout-v3 2022-09-14 10:32:25 +02:00
Knut Sveidqvist
be5d9bd623 Pausing POC 2022-09-14 10:27:30 +02:00
dependabot[bot]
5c51ce1393 chore(deps-dev): bump eslint-plugin-jest from 27.0.1 to 27.0.4 (#3458) 2022-09-13 20:59:12 +00:00
dependabot[bot]
13809b5025 chore(deps-dev): bump @typescript-eslint/eslint-plugin (#3457) 2022-09-13 20:51:35 +00:00
dependabot[bot]
3cc898ca4c chore(deps-dev): bump concurrently from 7.3.0 to 7.4.0 (#3445) 2022-09-13 20:49:43 +00:00
dependabot[bot]
9394abce22 chore(deps-dev): bump @babel/preset-env from 7.18.10 to 7.19.0 (#3442)
Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.18.10 to 7.19.0.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.19.0/packages/babel-preset-env)

---
updated-dependencies:
- dependency-name: "@babel/preset-env"
  dependency-type: direct:development
  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-13 21:45:25 +01:00
dependabot[bot]
6312eb9dcf chore(deps-dev): bump @typescript-eslint/parser from 5.36.1 to 5.37.0 (#3451)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.36.1 to 5.37.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.37.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  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-13 21:39:53 +01:00
dependabot[bot]
c636b873e9 chore(deps-dev): bump @babel/core from 7.18.13 to 7.19.0 (#3447) 2022-09-13 18:42:54 +00:00
dependabot[bot]
ff971c8300 chore(deps-dev): bump jest-environment-jsdom from 29.0.2 to 29.0.3 (#3441)
Bumps [jest-environment-jsdom](https://github.com/facebook/jest/tree/HEAD/packages/jest-environment-jsdom) from 29.0.2 to 29.0.3.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v29.0.3/packages/jest-environment-jsdom)

---
updated-dependencies:
- dependency-name: jest-environment-jsdom
  dependency-type: direct:development
  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-13 19:19:54 +01:00
dependabot[bot]
0c0d37efb2 chore(deps-dev): bump babel-jest from 29.0.2 to 29.0.3 (#3448)
Bumps [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) from 29.0.2 to 29.0.3.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v29.0.3/packages/babel-jest)

---
updated-dependencies:
- dependency-name: babel-jest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-13 19:17:49 +01:00
dependabot[bot]
39081b6bfb chore(deps-dev): bump eslint from 8.23.0 to 8.23.1
Bumps [eslint](https://github.com/eslint/eslint) from 8.23.0 to 8.23.1.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.23.0...v8.23.1)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-13 19:12:12 +01:00
Knut Sveidqvist
d851cc63bf Renderer for flowcharts using cytoscape, WIP 2022-09-13 17:41:43 +02:00
dependabot[bot]
3d32280c49 chore(deps-dev): bump typescript from 4.8.2 to 4.8.3 (#3446)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.8.2 to 4.8.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.8.2...v4.8.3)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  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-12 19:30:43 +02:00
dependabot[bot]
07638f5505 chore(deps): bump actions/checkout from 2 to 3 (#3449)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

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-12 19:27:45 +02:00
Knut Sveidqvist
73620ebee9 Merge pull request #3431 from aloisklink/other/re-enable-coverage
Re-enable coverage upload to coveralls
2022-09-12 19:04:54 +02:00
Sidharth Vinod
8b534440a0 Merge pull request #3420 from weedySeaDragon/docs/3418_auto_generated_comment_html_files
Docs: add '..auto generated..' to .html documentation files
2022-09-12 21:52:40 +05:30
Ashley Engelund
7f56112f8e change wording of console log message (use comma)
Co-authored-by: Sidharth Vinod <sidharthv96@gmail.com>
2022-09-12 09:17:40 -07:00
Knut Sveidqvist
0edc2751f3 Merge pull request #3436 from mermaid-js/3061_decoupling
Creating detectors and moving out diagram specific code from the diag…
2022-09-12 12:56:55 +02:00
Knut Sveidqvist
885e69c809 Fix for issue with setting the loglevel via numbers 2022-09-12 10:53:45 +02:00
Ashley Engelund (weedySeaDragon @ github)
9cc7da09fc formatting 2022-09-11 14:10:34 -07:00
Ashley Engelund (weedySeaDragon @ github)
6ad9208119 eslint fixes 2022-09-11 11:37:23 -07:00
Ashley Engelund (weedySeaDragon @ github)
ad56a22277 Merge remote-tracking branch 'MERMAID/develop' into docs/3418_auto_generated_comment_html_files
# Conflicts:
#	src/docs.mts
2022-09-09 18:48:21 -07:00
Ashley Engelund (weedySeaDragon @ github)
8ca91d6303 add eslint-disable no-console for file 2022-09-09 18:32:26 -07:00
Sidharth Vinod
f8eaccb4c1 fix: Run precommit hook for doc.mts changes too 2022-09-08 21:54:51 +05:30
Sidharth Vinod
b0559df903 chore: Updated doc files 2022-09-08 21:52:41 +05:30
Sidharth Vinod
2826bf6823 fix: Formatting issue 2022-09-08 21:51:42 +05:30
Ashley Engelund (weedySeaDragon @ github)
9acf63f7d6 (formatting only) sort imports just to force a new CI lint check 2022-09-08 07:44:36 -07:00
Alois Klink
5d72585705 ci: re-enable coveralls coverage upload
Reverts commits:
  - Disabling coveralls temporarilly
    aedf066337
  - Tmo disabling of coveralls
    a6b4cb24b8

I'm not 100% sure whether the `parallel` option is needed,
but I've left it disabled for now, since it'd would mean that we need
to merge both the `test.yml` and the `e2e.yml` file together.
2022-09-08 04:03:57 +01:00
Alois Klink
b760e717d0 build(dev-deps): remove unused coveralls
This devDependency is currently unused, and seems to have been unused
for a while.
2022-09-08 03:39:27 +01:00
Alois Klink
fe8f52fb1b test: disable coverage for .jison files
Coverage for `.jison` files doesn't make sense, since most of the
created JS lines are auto-generated.

If jison ever adds a source-map feature, we can renable coverage for
jison.
2022-09-08 03:35:50 +01:00
Ashley Engelund (weedySeaDragon @ github)
fd567f833e (minor) clarify var names (file -> filename); comments 2022-09-07 14:15:54 -07:00
Ashley Engelund (weedySeaDragon @ github)
6376c9ae43 switch order of params so the last one can be omitted 2022-09-07 14:15:09 -07:00
Ashley Engelund (weedySeaDragon @ github)
48b0076ea5 Merge remote-tracking branch 'MERMAID/develop' into docs/3418_auto_generated_comment_html_files 2022-09-07 14:04:56 -07:00
Sidharth Vinod
a800cb6fe6 Update prettier 2022-09-07 14:04:35 -07:00
Sidharth Vinod
5f81e3d5ed chore: Run postbuild with prepare
As postbuild was not running with prepare, PR that updated `documentation` package was green,  although it should've failed.
2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
e690da638d (formatting) prettier fix 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
be28160a4a unmangle sentence about doc changes committed and showing up on docsify site 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
d18624bbe9 change references from /docs to /src/docs; rework doc section in CONTRIBUTING 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
7fe8f260fc minor cleanup, clarify var names, add @todos 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
73abcd869c fix: also check other files 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
d0074356e9 fix: cannot use __dirname with .mts and latest Node 2022-09-07 14:04:35 -07:00
Ashley Engelund (weedySeaDragon @ github)
c6ce5a80fa fix: pass in doCopy param 2022-09-07 11:00:59 -07:00
Ashley Engelund (weedySeaDragon @ github)
411d641aa2 simplfy method to copy transformation to /docs; extract logging
Extract the logging so that it if later we want to turn it on/off with a --verbose flag
2022-09-07 08:35:51 -07:00
Ashley Engelund (weedySeaDragon @ github)
a878edfb9b add and use constants; DRY glob patterns in main 2022-09-07 08:32:52 -07:00
Ashley Engelund (weedySeaDragon @ github)
1a0fe0abf6 (comments only) reword main docblock; clarify other comments; grammar etc. fixes 2022-09-07 08:30:13 -07:00
Ashley Engelund (weedySeaDragon @ github)
b534a5c2ff Merge remote-tracking branch 'MERMAID/develop' into docs/3418_auto_generated_comment_html_files 2022-09-07 06:52:02 -07:00
Ashley Engelund (weedySeaDragon @ github)
0832b24d66 use single quotes; use const instead of let (2); use const instead of function 2022-09-05 23:43:57 -07:00
Ashley Engelund (weedySeaDragon @ github)
6554a41f6d transform HTML (insert comment); add console msgs and clarify; add file doc 2022-09-05 18:39:36 -07:00
Ashley Engelund (weedySeaDragon @ github)
d38f0e9e03 adjust console log message if only verifying, if copied actually happened 2022-09-05 18:36:17 -07:00
Ashley Engelund (weedySeaDragon @ github)
703b7eb91d rename vars so intent is clearer, add doc, use constants 2022-09-05 18:33:17 -07:00
Ashley Engelund (weedySeaDragon @ github)
0c85e8ee53 eslint (mostly use double quotes) 2022-09-05 18:27:58 -07:00
61 changed files with 1280 additions and 520 deletions

View File

@@ -14,7 +14,7 @@ jobs:
name: check tests
if: github.repository_owner == 'mermaid-js'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: testomatio/check-tests@stable

View File

@@ -36,3 +36,9 @@ jobs:
run: yarn e2e
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
- name: Upload Coverage to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: e2e

View File

@@ -32,3 +32,12 @@ jobs:
- name: Run Unit Tests
run: |
yarn ci --coverage
- name: Upload Coverage to Coveralls
# it feels a bit weird to use @master, but that's what the docs use
# (coveralls also doesn't publish a @v1 we can use)
# https://github.com/marketplace/actions/coveralls-github-action
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: unit

View File

@@ -1,4 +1,5 @@
{
"src/docs/**": ["yarn docs:build --git"],
"*.{ts,js,json,html,md}": ["eslint --fix", "prettier --write"]
"src/docs.mts": ["yarn docs:build --git"],
"*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"]
}

View File

@@ -0,0 +1,92 @@
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet" />
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<link
href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap"
rel="stylesheet"
/>
<style>
body {
/* background: rgb(221, 208, 208); */
/* background:#333; */
font-family: 'Arial';
/* font-size: 18px !important; */
width: 100%;
/* display: flex; */
/* flex-direction: column; */
margin-left: 20px;
}
h1 {
color: grey;
}
.mermaid2,
.mermaid3 {
display: none;
}
.mermaid {
}
.mermaid svg {
border: 1px solid purple;
/* font-size: 18px !important; */
/* fontfamily: 'courier'; */
}
#cy {
width: 300px;
height: 300px;
display: block;
}
</style>
</head>
<body>
<div id="cy"></div>
<pre class="mermaid" style="width: 50%">
flowchart TD
id1 --> id2--> id3[I am number 3 and I<br/>am a gigantic node<br/>am a gigantic node<br/>am a gigantic node<br/>am a gigantic node<br/>am a gigantic node]--> id4--> id5 --> id1
id5 --> id4
id5 --> id4
</pre>
<pre class="mermaid2" style="width: 50%">
flowchart TD
id1 --> id2--> id3
id2 --> id1
</pre>
<script src="./mermaid.js"></script>
<script>
mermaid.parseError = function (err, hash) {
// console.error('Mermaid error: ', err);
};
mermaid.initialize({
maxTextSize: 900000,
startOnLoad: true,
securityLevel: 'loose',
logLevel: 0,
fontFamily: 'courier',
flowchart: {
// curve: 'curveLinear',
useMaxWidth: true,
htmlLabels: false,
fontFamily: 'courier',
defaultRenderer: 'cytoscape',
// defaultRenderer: 'dagre-wrapper',
},
});
function callback() {
alert('It worked');
}
function clickByFlow(elemName) {
const div = document.createElement('div');
div.className = 'created-by-click';
div.style = 'padding: 20px; background: green; color: white;';
div.innerText = 'Clicked By Flow';
document.getElementsByTagName('body')[0].appendChild(div);
}
</script>
</body>
</html>

View File

@@ -38,7 +38,7 @@
</style>
</head>
<body>
<pre class="mermaid" style="width: 50%">
<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;
@@ -71,10 +71,12 @@ flowchart TD
end
end
</pre>
--> id2 --> id3(I have a long text) --> id4 --> id5 --> id1
<pre class="mermaid" style="width: 50%">
flowchart TD
id
id1
</pre>
<pre id="cy" style="width: 50%"></pre>
<pre class="mermaid2" style="width: 50%">
flowchart LR
a["<strong>Haiya</strong>"]===>b
@@ -99,7 +101,7 @@ flowchart TD
class A someclass;
class C someclass;
</pre>
<pre class="mermaid" style="width: 50%">
<pre class="mermaid2" style="width: 50%">
sequenceDiagram
title: My Sequence Diagram Title
accTitle: My Acc Sequence Diagram
@@ -109,14 +111,14 @@ flowchart TD
John-->>Alice: Great!
Alice-)John: See you later!
</pre>
<pre class="mermaid" style="width: 50%">
<pre class="mermaid2" style="width: 50%">
graph TD
A -->|000| B
B -->|111| C
linkStyle 1 stroke:#ff3,stroke-width:4px,color:red;
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
journey
accTitle: My User Journey Diagram
accDescr: My User Journey Diagram Description
@@ -130,10 +132,10 @@ graph TD
Go downstairs: 5: Me
Sit down: 5: Me
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
info
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
requirementDiagram
accTitle: My req Diagram
accDescr: My req Diagram Description
@@ -174,7 +176,7 @@ requirementDiagram
test_req - contains -> test_req3
test_req <- copies - test_entity2
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
@@ -206,7 +208,7 @@ gantt
Add gantt diagram to demo page :20h
Add another diagram to demo page :48h
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
stateDiagram
state Active {
Idle
@@ -234,7 +236,7 @@ stateDiagram
end
B ->> A: Return
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
classDiagram
accTitle: My class diagram
accDescr: My class diagram Description
@@ -259,7 +261,7 @@ class Class10 {
A->>Bob: Hola
Bob-->A: Pasten !
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
gitGraph
commit id: "ZERO"
branch develop
@@ -288,7 +290,7 @@ flowchart TD
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
classDiagram
Animal "1" <|-- Duck
Animal <|-- Fish
@@ -311,7 +313,7 @@ flowchart TD
+run()
}
</pre>
<pre class="mermaid" style="width: 100%">
<pre class="mermaid2" style="width: 100%">
erDiagram
CAR ||--o{ NAMED-DRIVER : allows
CAR {
@@ -343,6 +345,8 @@ flowchart TD
useMaxWidth: true,
htmlLabels: false,
fontFamily: 'courier',
defaultRenderer: 'cytoscape',
// defaultRenderer: 'dagre-wrapper',
},
});
function callback() {

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Version 8.6.0 Changes

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Change Log

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Configuration

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# About Mermaid

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Summary

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Tutorials

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
- Getting started

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
- 📔 Introduction

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Accessibility Options

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Breaking changes

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# C4 Diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Class diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Configuration

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Development and Contribution 🙌

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
---

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Directives

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Entity Relationship Diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Examples

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Frequently Asked Questions

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Flowcharts - Basic Syntax

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Gantt diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Gitgraph Diagrams

View File

@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.--><head>
<meta charset="UTF-8" />
<title>
mermaid - Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams,

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Integrations

View File

@@ -1 +1 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.

View File

@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.--><head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
@@ -64,7 +64,7 @@
using Mermaid.js.
</p>
<a
href="https://www.amazon.com/Official-Guide-Mermaid-js-beautiful-flowcharts-dp-1801078025/dp/1801078025/ref=mt_other?_encoding=UTF8&me=&qid=1628153965"
href="https://www.amazon.com/Official-Guide-Mermaid-js-beautiful-flowcharts-dp-1801078025/dp/1801078025/ref=mt_other?_encoding=UTF8&amp;me=&amp;qid=1628153965"
>
<button
style="background: #ffa41c; border: 1px solid #ff8f00"
@@ -322,7 +322,7 @@
</p>
</h3>
<a
href="https://www.amazon.com/Official-Guide-Mermaid-js-beautiful-flowcharts-dp-1801078025/dp/1801078025/ref=mt_other?_encoding=UTF8&me=&qid=1628153965"
href="https://www.amazon.com/Official-Guide-Mermaid-js-beautiful-flowcharts-dp-1801078025/dp/1801078025/ref=mt_other?_encoding=UTF8&amp;me=&amp;qid=1628153965"
>
<button
style="background: #ffa41c; border: 1px solid #ff8f00"

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# mermaid CLI

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Mindmap

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Advanced n00b mermaid (Coming soon..)

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# A Mermaid User-Guide for Beginners

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Overview for Beginners

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Diagram Syntax

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Adding a New Diagram/Chart 📊

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Pie chart diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Requirement Diagram

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Security

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Sequence diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# State diagrams

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Theme Configuration

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Upgrading

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# Usage

View File

@@ -1,4 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in src/docs.
# User Journey Diagram

View File

@@ -12,6 +12,10 @@ module.exports = {
{ 'token-stack': true },
],
},
coveragePathIgnorePatterns: [
'/node_modules/',
'^.+\\.jison$', // might be able to fix in future if .jison adds source-map support
],
transformIgnorePatterns: ['/node_modules/(?!dagre-d3-renderer/lib|khroma).*\\.js'],
testPathIgnorePatterns: ['/node_modules/', '.cache', './cypress'],
moduleNameMapper: {

View File

@@ -64,6 +64,7 @@
},
"dependencies": {
"@braintree/sanitize-url": "^6.0.0",
"cytoscape": "^3.23.0",
"d3": "^7.0.0",
"dagre": "^0.8.5",
"dagre-d3": "^0.6.4",
@@ -77,9 +78,9 @@
},
"devDependencies": {
"@applitools/eyes-cypress": "^3.25.7",
"@babel/core": "^7.14.6",
"@babel/core": "^7.19.0",
"@babel/eslint-parser": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"@babel/preset-env": "^7.19.0",
"@babel/register": "^7.14.5",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.0.0",
@@ -87,21 +88,20 @@
"@types/dompurify": "^2.3.4",
"@types/jest": "^28.1.7",
"@types/stylis": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"babel-jest": "^29.0.2",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"babel-jest": "^29.0.3",
"babel-loader": "^8.2.2",
"concurrently": "^7.0.0",
"coveralls": "^3.0.2",
"concurrently": "^7.4.0",
"css-to-string-loader": "^0.1.3",
"cypress": "9.7.0",
"cypress-image-snapshot": "^4.0.1",
"documentation": "13.2.0",
"eslint": "^8.23.0",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-jest": "^27.0.1",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-markdown": "^3.0.0",
@@ -109,7 +109,7 @@
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.0.3",
"jest-environment-jsdom": "^29.0.2",
"jest-environment-jsdom": "^29.0.3",
"jison": "^0.4.18",
"js-base64": "3.7.2",
"lint-staged": "^13.0.0",
@@ -123,7 +123,7 @@
"ts-jest": "^28.0.8",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.2",
"typescript": "^4.8.3",
"unist-util-flatmap": "^1.0.0",
"webpack": "^5.53.0",
"webpack-cli": "^4.7.2",

View File

@@ -8,8 +8,6 @@ import note from './shapes/note';
import { parseMember } from '../diagrams/class/svgDraw';
import { evaluate, sanitizeText as sanitize } from '../diagrams/common/common';
const sanitizeText = (txt) => sanitize(txt, getConfig());
const question = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true);
@@ -1064,6 +1062,7 @@ export const insertNode = (elem, node, dir) => {
if (node.haveCallback) {
nodeElems[node.id].attr('class', nodeElems[node.id].attr('class') + ' clickable');
}
return newEl;
};
export const setNodeElem = (elem, node) => {
nodeElems[node.id] = elem;

View File

@@ -41,9 +41,11 @@ import erStyles from '../diagrams/er/styles';
import flowParser from '../diagrams/flowchart/parser/flow';
import { flowDetector } from '../diagrams/flowchart/flowDetector';
import { flowDetectorV2 } from '../diagrams/flowchart/flowDetector-v2';
import { flowDetectorV3 } from '../diagrams/flowchart/flowDetector-v3';
import flowDb from '../diagrams/flowchart/flowDb';
import flowRenderer from '../diagrams/flowchart/flowRenderer';
import flowRendererV2 from '../diagrams/flowchart/flowRenderer-v2';
import flowRendererV3 from '../diagrams/flowchart/flowRenderer-v3';
import flowStyles from '../diagrams/flowchart/styles';
// @ts-ignore: TODO Fix ts errors
@@ -305,6 +307,20 @@ export const addDiagrams = () => {
},
flowDetectorV2
);
registerDiagram(
'flowchart-v3',
{
parser: flowParser,
db: flowDb,
renderer: flowRendererV3,
styles: flowStyles,
init: () => {
flowDb.clear();
flowDb.setGen('gen-3');
},
},
flowDetectorV3
);
registerDiagram(
'gitGraph',
{ parser: gitGraphParser, db: gitGraphDb, renderer: gitGraphRenderer, styles: gitGraphStyles },

View File

@@ -1,8 +1,23 @@
import type { DiagramDetector } from '../../diagram-api/detectType';
import { log } from '../../diagram-api/diagramAPI';
export const flowDetectorV2: DiagramDetector = (txt, config) => {
log.info('Config in flowDetector-v2 defaultRenderer: ', config?.flowchart?.defaultRenderer);
// If we have confgured to use cytoscape then we should always return false here
if (config?.flowchart?.defaultRenderer === 'cytoscape') {
log.info('flowDetector-v2 returning false');
return false;
} else {
log.info('flowDetector-v2 not cytoscape');
}
// If we have confgured to use dagre-wrapper then we should return true in this function for graph code thus making it use the new flowchart diagram
if (config?.flowchart?.defaultRenderer === 'dagre-wrapper' && txt.match(/^\s*graph/) !== null)
return true;
log.info('Config in flowDetector-v2 returning', txt.match(/^\s*flowchart/) !== null);
return txt.match(/^\s*flowchart/) !== null;
};
/*
if (((_a = config === null || config === void 0 ? void 0 : config.flowchart) === null || _a === void 0 ? void 0 : _a.defaultRenderer) === 'dagre-wrapper1' && txt.match(/^\s*graph/) !== null)
*/

View File

@@ -0,0 +1,8 @@
import type { DiagramDetector } from '../../diagram-api/detectType';
export const flowDetectorV3: DiagramDetector = (txt, config) => {
// If we have confgured to use dagre-wrapper then we should return true in this function for graph code thus making it use the new flowchart diagram
if (config?.flowchart?.defaultRenderer === 'cytoscape' && txt.match(/^\s*graph/) !== null)
return true;
return txt.match(/^\s*flowchart/) !== null;
};

View File

@@ -12,7 +12,7 @@ import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import addSVGAccessibilityFields from '../../accessibility';
const conf = {};
let conf = {};
export const setConf = function (cnf) {
const keys = Object.keys(cnf);
for (let i = 0; i < keys.length; i++) {
@@ -351,6 +351,7 @@ export const getClasses = function (text, diagObj) {
*/
export const draw = function (text, id, _version, diagObj) {
// const conf = config.getConfig(_version);
log.info('Drawing flowchart');
diagObj.db.clear();
flowDb.setGen('gen-2');

View File

@@ -0,0 +1,549 @@
import graphlib from 'graphlib';
import { select, curveLinear, selectAll } from 'd3';
import flowDb from './flowDb';
import { getConfig } from '../../config';
import { insertNode } from '../../dagre-wrapper/nodes.js';
import { render } from '../../dagre-wrapper/index.js';
import addHtmlLabel from 'dagre-d3/lib/label/add-html-label.js';
import { log } from '../../logger';
import common, { evaluate } from '../common/common';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import addSVGAccessibilityFields from '../../accessibility';
import cytoscape from 'cytoscape';
const conf = {};
export const setConf = function (cnf) {
const keys = Object.keys(cnf);
for (let i = 0; i < keys.length; i++) {
conf[keys[i]] = cnf[keys[i]];
}
};
// /**
// * Function that adds the vertices found during parsing to the graph to be rendered.
// *
// * @param vert Object containing the vertices.
// * @param g The graph that is to be drawn.
// * @param svgId
// * @param root
// * @param doc
// * @param diagObj
// */
export const addVertices = function (vert, cy, svgId, root, doc, diagObj) {
const svg = root.select(`[id="${svgId}"]`);
const nodes = svg.insert('g').attr('class', 'nodes');
const keys = Object.keys(vert);
// Iterate through each item in the vertex object (containing all the vertices found) in the graph definition
keys.forEach(function (id) {
const vertex = vert[id];
/**
* Variable for storing the classes for the vertex
*
* @type {string}
*/
let classStr = 'default';
if (vertex.classes.length > 0) {
classStr = vertex.classes.join(' ');
}
const styles = getStylesFromArray(vertex.styles);
// Use vertex id as text in the box if no text is provided by the graph definition
let vertexText = vertex.text !== undefined ? vertex.text : vertex.id;
// We create a SVG label, either by delegating to addHtmlLabel or manually
let vertexNode;
if (evaluate(getConfig().flowchart.htmlLabels)) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
const node = {
label: vertexText.replace(
/fa[lrsb]?:fa-[\w-]+/g,
(s) => `<i class='${s.replace(':', ' ')}'></i>`
),
};
vertexNode = addHtmlLabel(svg, node).node();
vertexNode.parentNode.removeChild(vertexNode);
} else {
const svgLabel = doc.createElementNS('http://www.w3.org/2000/svg', 'text');
svgLabel.setAttribute('style', styles.labelStyle.replace('color:', 'fill:'));
const rows = vertexText.split(common.lineBreakRegex);
for (let j = 0; j < rows.length; j++) {
const tspan = doc.createElementNS('http://www.w3.org/2000/svg', 'tspan');
tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
tspan.setAttribute('dy', '1em');
tspan.setAttribute('x', '1');
tspan.textContent = rows[j];
svgLabel.appendChild(tspan);
}
vertexNode = svgLabel;
}
let radious = 0;
let _shape = '';
// Set the shape based parameters
switch (vertex.type) {
case 'round':
radious = 5;
_shape = 'rect';
break;
case 'square':
_shape = 'rect';
break;
case 'diamond':
_shape = 'question';
break;
case 'hexagon':
_shape = 'hexagon';
break;
case 'odd':
_shape = 'rect_left_inv_arrow';
break;
case 'lean_right':
_shape = 'lean_right';
break;
case 'lean_left':
_shape = 'lean_left';
break;
case 'trapezoid':
_shape = 'trapezoid';
break;
case 'inv_trapezoid':
_shape = 'inv_trapezoid';
break;
case 'odd_right':
_shape = 'rect_left_inv_arrow';
break;
case 'circle':
_shape = 'circle';
break;
case 'ellipse':
_shape = 'ellipse';
break;
case 'stadium':
_shape = 'stadium';
break;
case 'subroutine':
_shape = 'subroutine';
break;
case 'cylinder':
_shape = 'cylinder';
break;
case 'group':
_shape = 'rect';
break;
case 'doublecircle':
_shape = 'doublecircle';
break;
default:
_shape = 'rect';
}
// // Add the node
const node = {
labelStyle: styles.labelStyle,
shape: _shape,
labelText: vertexText,
rx: radious,
ry: radious,
class: classStr,
style: styles.style,
id: vertex.id,
link: vertex.link,
linkTarget: vertex.linkTarget,
tooltip: diagObj.db.getTooltip(vertex.id) || '',
domId: diagObj.db.lookUpDomId(vertex.id),
haveCallback: vertex.haveCallback,
width: vertex.type === 'group' ? 500 : undefined,
dir: vertex.dir,
type: vertex.type,
props: vertex.props,
padding: getConfig().flowchart.padding,
};
const nodeEl = insertNode(nodes, node, vertex.dir);
const boundingBox = nodeEl.node().getBBox();
cy.add({
group: 'nodes',
data: {
id: vertex.id,
labelStyle: styles.labelStyle,
shape: _shape,
labelText: vertexText,
rx: radious,
ry: radious,
class: classStr,
style: styles.style,
link: vertex.link,
linkTarget: vertex.linkTarget,
tooltip: diagObj.db.getTooltip(vertex.id) || '',
domId: diagObj.db.lookUpDomId(vertex.id),
haveCallback: vertex.haveCallback,
width: vertex.type === 'group' ? 500 : undefined,
dir: vertex.dir,
type: vertex.type,
props: vertex.props,
padding: getConfig().flowchart.padding,
boundingBox,
el: nodeEl,
},
});
log.trace('setNode', {
labelStyle: styles.labelStyle,
shape: _shape,
labelText: vertexText,
rx: radious,
ry: radious,
class: classStr,
style: styles.style,
id: vertex.id,
domId: diagObj.db.lookUpDomId(vertex.id),
width: vertex.type === 'group' ? 500 : undefined,
type: vertex.type,
dir: vertex.dir,
props: vertex.props,
padding: getConfig().flowchart.padding,
});
});
};
/**
* Add edges to graph based on parsed graph definition
*
* @param {object} edges The edges to add to the graph
* @param {object} g The graph object
* @param cy
* @param diagObj
*/
export const addEdges = function (edges, cy, diagObj) {
// log.info('abc78 edges = ', edges);
let cnt = 0;
let linkIdCnt = {};
let defaultStyle;
let defaultLabelStyle;
if (typeof edges.defaultStyle !== 'undefined') {
const defaultStyles = getStylesFromArray(edges.defaultStyle);
defaultStyle = defaultStyles.style;
defaultLabelStyle = defaultStyles.labelStyle;
}
edges.forEach(function (edge) {
cnt++;
// Identify Link
var linkIdBase = 'L-' + edge.start + '-' + edge.end;
// count the links from+to the same node to give unique id
if (typeof linkIdCnt[linkIdBase] === 'undefined') {
linkIdCnt[linkIdBase] = 0;
log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]);
} else {
linkIdCnt[linkIdBase]++;
log.info('abc78 new entry', linkIdBase, linkIdCnt[linkIdBase]);
}
let linkId = linkIdBase + '-' + linkIdCnt[linkIdBase];
log.info('abc78 new link id to be used is', linkIdBase, linkId, linkIdCnt[linkIdBase]);
var linkNameStart = 'LS-' + edge.start;
var linkNameEnd = 'LE-' + edge.end;
const edgeData = { style: '', labelStyle: '' };
edgeData.minlen = edge.length || 1;
//edgeData.id = 'id' + cnt;
// Set link type for rendering
if (edge.type === 'arrow_open') {
edgeData.arrowhead = 'none';
} else {
edgeData.arrowhead = 'normal';
}
// Check of arrow types, placed here in order not to break old rendering
edgeData.arrowTypeStart = 'arrow_open';
edgeData.arrowTypeEnd = 'arrow_open';
/* eslint-disable no-fallthrough */
switch (edge.type) {
case 'double_arrow_cross':
edgeData.arrowTypeStart = 'arrow_cross';
case 'arrow_cross':
edgeData.arrowTypeEnd = 'arrow_cross';
break;
case 'double_arrow_point':
edgeData.arrowTypeStart = 'arrow_point';
case 'arrow_point':
edgeData.arrowTypeEnd = 'arrow_point';
break;
case 'double_arrow_circle':
edgeData.arrowTypeStart = 'arrow_circle';
case 'arrow_circle':
edgeData.arrowTypeEnd = 'arrow_circle';
break;
}
let style = '';
let labelStyle = '';
switch (edge.stroke) {
case 'normal':
style = 'fill:none;';
if (typeof defaultStyle !== 'undefined') {
style = defaultStyle;
}
if (typeof defaultLabelStyle !== 'undefined') {
labelStyle = defaultLabelStyle;
}
edgeData.thickness = 'normal';
edgeData.pattern = 'solid';
break;
case 'dotted':
edgeData.thickness = 'normal';
edgeData.pattern = 'dotted';
edgeData.style = 'fill:none;stroke-width:2px;stroke-dasharray:3;';
break;
case 'thick':
edgeData.thickness = 'thick';
edgeData.pattern = 'solid';
edgeData.style = 'stroke-width: 3.5px;fill:none;';
break;
}
if (typeof edge.style !== 'undefined') {
const styles = getStylesFromArray(edge.style);
style = styles.style;
labelStyle = styles.labelStyle;
}
edgeData.style = edgeData.style += style;
edgeData.labelStyle = edgeData.labelStyle += labelStyle;
if (typeof edge.interpolate !== 'undefined') {
edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
} else if (typeof edges.defaultInterpolate !== 'undefined') {
edgeData.curve = interpolateToCurve(edges.defaultInterpolate, curveLinear);
} else {
edgeData.curve = interpolateToCurve(conf.curve, curveLinear);
}
if (typeof edge.text === 'undefined') {
if (typeof edge.style !== 'undefined') {
edgeData.arrowheadStyle = 'fill: #333';
}
} else {
edgeData.arrowheadStyle = 'fill: #333';
edgeData.labelpos = 'c';
}
edgeData.labelType = 'text';
edgeData.label = edge.text.replace(common.lineBreakRegex, '\n');
if (typeof edge.style === 'undefined') {
edgeData.style = edgeData.style || 'stroke: #333; stroke-width: 1.5px;fill:none;';
}
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');
edgeData.id = linkId;
edgeData.classes = 'flowchart-link ' + linkNameStart + ' ' + linkNameEnd;
// Add the edge to the graph
cy.add({ group: 'edges', data: { source: edge.start, target: edge.end, edgeData, id: cnt } });
});
};
/**
* Returns the all the styles from classDef statements in the graph definition.
*
* @param text
* @param diagObj
* @returns {object} ClassDef styles
*/
export const getClasses = function (text, diagObj) {
log.info('Extracting classes');
diagObj.db.clear();
try {
// Parse the graph definition
diagObj.parse(text);
return diagObj.db.getClasses();
} catch (e) {
return;
}
};
/**
* Draws a flowchart in the tag with id: id based on the graph definition in text.
*
* @param text
* @param id
*/
export const draw = function (text, id, _version, diagObj) {
return new Promise(function (resolve, reject) {
const cy = cytoscape({
// styleEnabled: false,
// animate: false,
// ready: function () {
// log.info('Ready', this);
// },
container: document.getElementById('cy'), // container to render in
elements: [
// list of graph elements to start with
// { // node a
// data: { id: 'a' }
// },
// { // node b
// data: { id: 'b' }
// },
// { // edge ab
// data: { id: 'ab', source: 'a', target: 'b' }
// }
],
style: [
// the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
label: 'data(labelText)',
},
},
{
selector: 'edge',
style: {
width: 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle',
'curve-style': 'bezier',
label: 'data(id)',
},
},
],
layout: {
name: 'breadthfirst',
rows: 1,
},
});
log.info('Drawing flowchart using v3 renderer');
// Fetch the default direction, use TD if none was found
let dir = diagObj.db.getDirection();
if (typeof dir === 'undefined') {
dir = 'TD';
}
const { securityLevel, flowchart: conf } = getConfig();
// const nodeSpacing = conf.nodeSpacing || 50;
// const rankSpacing = conf.rankSpacing || 50;
// Handle root and document for when rendering in sandbox mode
let sandboxElement;
if (securityLevel === 'sandbox') {
sandboxElement = select('#i' + id);
}
const root =
securityLevel === 'sandbox'
? select(sandboxElement.nodes()[0].contentDocument.body)
: select('body');
const doc = securityLevel === 'sandbox' ? sandboxElement.nodes()[0].contentDocument : document;
const svg = root.select(`[id="${id}"]`);
const edgesEl = svg.insert('g').attr('class', 'edges edgePath');
// Fetch the vertices/nodes and edges/links from the parsed graph definition
const vert = diagObj.db.getVertices();
addVertices(vert, cy, id, root, doc, diagObj);
// c.style();
// Make cytoscape care about the dimensisions of the nodes
cy.nodes().forEach(function (n) {
n.layoutDimensions = () => {
const boundingBox = n.data().boundingBox;
return { w: boundingBox.width, h: boundingBox.height };
};
});
const edges = diagObj.db.getEdges();
addEdges(edges, cy, diagObj);
cy.layout({
// name: 'grid',
// name: 'circle',
name: 'cose',
// name: 'breadthfirst',
headless: true,
styleEnabled: false,
animate: false,
}).run();
log.info('Positions', cy.nodes().positions());
window.cy = cy;
cy.ready((e) => {
log.info('Ready', e);
setTimeout(() => {
cy.nodes().map((node, id) => {
const data = node.data();
log.info('Position: (', node.position().x, ', ', node.position().y, ')', data);
data.el.attr('transform', `translate(${node.position().x}, ${node.position().y})`);
// document
// .querySelector(`[id="${data.domId}"]`)
// .setAttribute('transform', `translate(${node.position().x}, ${node.position().y})`);
log.info('Id = ', data.domId, svg.select(`[id="${data.domId}"]`), data.el.node());
});
cy.edges().map((edge, id) => {
const data = edge.data();
if (edge[0]._private.bodyBounds) {
const bounds = edge[0]._private.rscratch;
log.info(
id,
// 'x:',
// edge.controlPoints(),
// 'y:',
edge[0]._private.rscratch
// 'w:',
// edge.boundingbox().w,
// 'h:',
// edge.boundingbox().h,
// edge.midPoint()
);
// data.el.attr('transform', `translate(${node.position().x}, ${node.position().y})`);
// edgesEl
// .insert('line')
// .attr('x1', bounds.startX)
// .attr('y1', bounds.startY)
// .attr('x2', bounds.endX)
// .attr('y2', bounds.endY)
// .attr('class', 'path');
edgesEl
.insert('path')
// Todo use regular line function
.attr(
'd',
`M ${bounds.startX},${bounds.startY} L ${bounds.midX},${bounds.midY} L${bounds.endX},${bounds.endY} `
)
.attr('class', 'path')
.attr('fill', 'none');
}
});
log.info(cy.json());
setupGraphViewbox({}, svg, conf.diagramPadding, conf.useMaxWidth);
resolve();
}, 500);
});
});
};
export default {
// setConf,
// addVertices,
// addEdges,
getClasses,
draw,
};

View File

@@ -1,42 +1,152 @@
/* eslint-disable no-console */
import { remark } from 'remark';
import type { Code, Root } from 'mdast';
/**
* @file Transform documentation source files into files suitable for publishing
* and optionally copy the transformed files from the source directory to the
* directory used for the final, published documentation directory. The list
* of files transformed and copied to final documentation directory are logged
* to the console. If a file in the source directory has the same contents in
* the final directory, nothing is done (the final directory is up-to-date).
* @example
* docs
* Run with no option flags
*
* @example
* docs --verify
* If the --verify option is used, it only _verifies_ that the final directory has been updated with the transformed files in the source directory.
* No files will be copied to the final documentation directory, but the list of files to be changed is shown on the console.
* If the final documentation directory does not have the transformed files from source directory
* - a message to the console will show that this command should be run without the --verify flag so that the final directory is updated, and
* - it will return a fail exit code (1)
*
* @example
* docs --git
* If the --git option is used, the command `git add docs` will be run after all transformations (and/or verifications) have completed successfully
* If not files were transformed, the git command is not run.
*
* @todo Ensure that the documentation source and final paths are correct by
* using process.cwd() to get their absolute paths. Ensures that the location
* of those 2 directories is not dependent on where this file resides.
*
* @todo Write a test file for this. (Will need to be able to deal .mts file.
* Jest has trouble with it.)
*/
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
// @ts-ignore: no typings
import flatmap from 'unist-util-flatmap';
import { globby } from 'globby';
import { join, dirname } from 'path';
import { exec } from 'child_process';
import { globby } from 'globby';
import { JSDOM } from 'jsdom';
import type { Code, Root } from 'mdast';
import { join, dirname } from 'path';
import prettier from 'prettier';
import { remark } from 'remark';
// @ts-ignore No typescript declaration file
import flatmap from 'unist-util-flatmap';
const verify = process.argv.includes('--verify');
const git = process.argv.includes('--git');
let fileChanged = false;
// Possible Improvement: combine with lint-staged to only copy files that have changed
const prepareOutFile = (file: string): string => {
const outFile = join('docs', file.replace('src/docs/', ''));
mkdirSync(dirname(outFile), { recursive: true });
return outFile;
const SOURCE_DOCS_DIR = 'src/docs';
const FINAL_DOCS_DIR = 'docs';
const AUTOGENERATED_TEXT = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in ${SOURCE_DOCS_DIR}.`;
const LOGMSG_TRANSFORMED = 'transformed';
const LOGMSG_TO_BE_TRANSFORMED = 'to be transformed';
const LOGMSG_COPIED = `, and copied to ${FINAL_DOCS_DIR}`;
const WARN_DOCSDIR_DOESNT_MATCH = `Changed files were transformed in ${SOURCE_DOCS_DIR} but do not match the files in ${FINAL_DOCS_DIR}. Please run yarn docs:build after making changes to ${SOURCE_DOCS_DIR} to update the ${FINAL_DOCS_DIR} directory with the transformed files.`;
const verifyOnly: boolean = process.argv.includes('--verify');
const git: boolean = process.argv.includes('--git');
// TODO: Read from .prettierrc?
const prettierConfig: prettier.Config = {
useTabs: false,
tabWidth: 2,
endOfLine: 'auto',
printWidth: 100,
singleQuote: true,
};
const verifyAndCopy = (file: string, content?: string) => {
const outFile = prepareOutFile(file);
const existingBuffer = existsSync(outFile) ? readFileSync(outFile) : Buffer.from('#NEW FILE#');
const newBuffer = content ? Buffer.from(content) : readFileSync(file);
let filesWereTransformed = false;
/**
* Given a source file name and path, return the documentation destination full
* path and file name Create the destination path if it does not already exist.
*
* @param {string} file - Name of the file (including full path)
* @returns {string} Name of the file with the path changed from the source
* directory to final documentation directory
* @todo Possible Improvement: combine with lint-staged to only copy files that
* have changed
*/
const changeToFinalDocDir = (file: string): string => {
const newDir = file.replace(SOURCE_DOCS_DIR, FINAL_DOCS_DIR);
mkdirSync(dirname(newDir), { recursive: true });
return newDir;
};
/**
* Log messages to the console showing if the transformed file copied to the
* final documentation directory or still needs to be copied.
*
* @param {string} filename Name of the file that was transformed
* @param {boolean} wasCopied Whether or not the file was copied
*/
const logWasOrShouldBeTransformed = (filename: string, wasCopied: boolean) => {
const changeMsg = wasCopied ? LOGMSG_TRANSFORMED : LOGMSG_TO_BE_TRANSFORMED;
let logMsg: string;
logMsg = ` File ${changeMsg}: ${filename}`;
if (wasCopied) {
logMsg += LOGMSG_COPIED;
}
console.log(logMsg);
};
/**
* If the file contents were transformed, set the _filesWereTransformed_ flag to
* true and copy the transformed contents to the final documentation directory
* if the doCopy flag is true. Log messages to the console.
*
* @param {string} filename Name of the file that will be verified
* @param {boolean} [doCopy=false] Whether we should copy that
* transformedContents to the final documentation directory. Default is
* `false`. Default is `false`
* @param {string} [transformedContent] New contents for the file
*/
const copyTransformedContents = (filename: string, doCopy = false, transformedContent?: string) => {
const fileInFinalDocDir = changeToFinalDocDir(filename);
const existingBuffer = existsSync(fileInFinalDocDir)
? readFileSync(fileInFinalDocDir)
: Buffer.from('#NEW FILE#');
const newBuffer = transformedContent ? Buffer.from(transformedContent) : readFileSync(filename);
if (existingBuffer.equals(newBuffer)) {
// Files are same, skip.
return;
return; // Files are same, skip.
}
console.log(`File changed: ${outFile}`);
fileChanged = true;
if (!verify) {
writeFileSync(outFile, newBuffer);
filesWereTransformed = true;
if (doCopy) {
writeFileSync(fileInFinalDocDir, newBuffer);
}
logWasOrShouldBeTransformed(fileInFinalDocDir, doCopy);
};
const transform = (file: string) => {
const doc = readFileSync(file, 'utf8');
const readSyncedUTF8file = (filename: string): string => {
return readFileSync(filename, 'utf8');
};
/**
* Transform a markdown file and write the transformed file to the directory for
* published documentation
*
* 1. Add a `mermaid-example` block before every `mermaid` or `mmd` block On the
* docsify site (one place where the documentation is published), this will
* show the code used for the mermaid diagram
* 2. Add the text that says the file is automatically generated
* 3. Use prettier to format the file Verify that the file has been changed and
* write out the changes
*
* @param file {string} name of the file that will be verified
*/
const transformMarkdown = (file: string) => {
const doc = readSyncedUTF8file(file);
const ast: Root = remark.parse(doc);
const out = flatmap(ast, (c: Code) => {
if (c.type !== 'code' || !c.lang?.startsWith('mermaid')) {
@@ -48,38 +158,82 @@ const transform = (file: string) => {
return [c, Object.assign({}, c, { lang: 'mermaid' })];
});
const transformed = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit corresponding file in src/docs.\n${remark.stringify(
out
)}`;
verifyAndCopy(
file,
prettier.format(transformed, {
parser: 'markdown',
useTabs: false,
tabWidth: 2,
endOfLine: 'auto',
printWidth: 100,
singleQuote: true,
})
);
// Add the AUTOGENERATED_TEXT to the start of the file
const transformed = `${AUTOGENERATED_TEXT}\n${remark.stringify(out)}`;
const formatted = prettier.format(transformed, {
parser: 'markdown',
...prettierConfig,
});
copyTransformedContents(file, !verifyOnly, formatted);
};
(async () => {
const mdFiles = await globby(['./src/docs/**/*.md'], { dot: true });
mdFiles.forEach(transform);
const nonMDFiles = await globby(['src/docs/**', '!**/*.md'], { dot: true });
nonMDFiles.forEach((file) => {
verifyAndCopy(file);
/**
* Transform an HTML file and write the transformed file to the directory for
* published documentation
*
* - Add the text that says the file is automatically generated Verify that the
* file has been changed and write out the changes
*
* @param filename {string} name of the HTML file to transform
*/
const transformHtml = (filename: string) => {
/**
* Insert the '...auto generated...' comment into an HTML file after the<html> element
*
* @param fileName {string} file name that should have the comment inserted
* @returns {string} The contents of the file with the comment inserted
*/
const insertAutoGeneratedComment = (fileName: string): string => {
const fileContents = readSyncedUTF8file(fileName);
const jsdom = new JSDOM(fileContents);
const htmlDoc = jsdom.window.document;
const autoGeneratedComment = jsdom.window.document.createComment(AUTOGENERATED_TEXT);
const rootElement = htmlDoc.documentElement;
rootElement.prepend(autoGeneratedComment);
return jsdom.serialize();
};
const transformedHTML = insertAutoGeneratedComment(filename);
const formattedHTML = prettier.format(transformedHTML, {
parser: 'html',
...prettierConfig,
});
if (fileChanged) {
if (verify) {
console.log(
"Changes detected in files in `docs`. Please run `yarn docs:build` after making changes to 'src/docs' to update the `docs` folder."
);
copyTransformedContents(filename, !verifyOnly, formattedHTML);
};
/** Main method (entry point) */
(async () => {
const sourceDirGlob = join('.', SOURCE_DOCS_DIR, '**');
const includeFilesStartingWithDot = true;
console.log('Transforming markdown files...');
const mdFiles = await globby([join(sourceDirGlob, '*.md')], {
dot: includeFilesStartingWithDot,
});
mdFiles.forEach(transformMarkdown);
console.log('Transforming html files...');
const htmlFiles = await globby([join(sourceDirGlob, '*.html')], {
dot: includeFilesStartingWithDot,
});
htmlFiles.forEach(transformHtml);
console.log('Transforming all other files...');
const otherFiles = await globby([sourceDirGlob, '!**/*.md', '!**/*.html'], {
dot: includeFilesStartingWithDot,
});
otherFiles.forEach((file: string) => {
copyTransformedContents(file, !verifyOnly); // no transformation
});
if (filesWereTransformed) {
if (verifyOnly) {
console.log(WARN_DOCSDIR_DOESNT_MATCH);
process.exit(1);
}
if (git) {
console.log('Adding changes in docs folder to git');
console.log('Adding changes in ${FINAL_DOCS_DIR} folder to git');
exec('git add docs');
}
}

View File

@@ -36,6 +36,8 @@ export const setLogLevel = function (level: keyof typeof LEVELS | number | strin
if (level in LEVELS) {
numericLevel = LEVELS[level as keyof typeof LEVELS];
}
} else if (typeof level === 'number') {
numericLevel = level;
}
log.trace = () => {};
log.debug = () => {};

View File

@@ -118,12 +118,12 @@ export const decodeEntities = function (text: string): string {
* element will be removed when rendering is completed.
* @returns {void}
*/
const render = function (
const render = async function (
id: string,
text: string,
cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void,
container?: Element
): void {
): Promise<void> {
configApi.reset();
text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;;
const graphInit = utils.detectInit(text);
@@ -299,7 +299,7 @@ const render = function (
svg.insertBefore(style1, firstChild);
try {
diag.renderer.draw(text, id, pkg.version, diag);
await diag.renderer.draw(text, id, pkg.version, diag);
} catch (e) {
errorRenderer.draw(id, pkg.version);
throw e;

680
yarn.lock

File diff suppressed because it is too large Load Diff