Skip to content

Commit ec6cee3

Browse files
committed
Render sequence diagram
1 parent d418ac7 commit ec6cee3

4 files changed

Lines changed: 113 additions & 7 deletions

File tree

package-lock.json

Lines changed: 66 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@
4040
},
4141
"devDependencies": {
4242
"@types/glob": "^7.1.1",
43+
"@types/jquery": "^3.3.30",
4344
"@types/mocha": "^5.2.6",
4445
"@types/node": "^10.12.21",
4546
"@types/vscode": "^1.36.0",
4647
"css-loader": "^3.1.0",
4748
"flowchart.js": "^1.12.2",
4849
"glob": "^7.1.4",
4950
"ignore-loader": "^0.1.2",
51+
"imports-loader": "^0.8.0",
5052
"jquery": "^3.4.1",
53+
"js-sequence-diagrams": "git+https://github.com/Moeditor/js-sequence-diagrams.git",
54+
"lodash": "^4.17.15",
5155
"mermaid": "^8.2.3",
5256
"mini-css-extract-plugin": "^0.8.0",
5357
"mocha": "^6.1.4",
58+
"raphael": "git+ssh://git@github.com/DmitryBaranovskiy/raphael.git#v2.2.7",
5459
"style-loader": "^0.23.1",
5560
"ts-loader": "^6.0.4",
5661
"tslint": "^5.12.1",

src/page.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import 'bootstrap3/dist/css/bootstrap.min.css';
44
import './mermaid.css';
55
import './style.css';
66

7-
import * as $ from 'jquery';
8-
97
import * as mermaid from 'mermaid';
108
import * as flowchart from 'flowchart.js';
9+
import 'js-sequence-diagrams';
1110
import * as S from 'string';
1211

1312
const mermaids = $('span.mermaid.raw');
@@ -54,3 +53,28 @@ flows.each((key, value) => {
5453
$ele.addClass('flow-chart')
5554
}
5655
})
56+
57+
const sequences = $('span.sequence-diagram.raw')
58+
sequences.removeClass('raw')
59+
sequences.each((key, value) => {
60+
try {
61+
var $value = $(value)
62+
var $ele = $(value).parent().parent()
63+
64+
const sequence = $value as any
65+
sequence.sequenceDiagram({
66+
theme: 'simple'
67+
})
68+
69+
$ele.addClass('sequence-diagram')
70+
$value.children().unwrap().unwrap()
71+
const svg = $ele.find('> svg')
72+
svg[0].setAttribute('viewBox', `0 0 ${svg.attr('width')} ${svg.attr('height')}`)
73+
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet')
74+
} catch (err) {
75+
// $value.unwrap()
76+
// $value.parent().append(`<div class="alert alert-warning">${S(err).escapeHTML().s}</div>`)
77+
// console.warn(err)
78+
$ele.addClass('sequence-diagram')
79+
}
80+
})

webpack.config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const path = require('path');
66
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
7+
const webpack = require('webpack')
78

89
/**@type {import('webpack').Configuration}*/
910
const extensionConfig = {
@@ -47,7 +48,10 @@ const pageConfig = {
4748
path: path.resolve(__dirname, 'dist')
4849
},
4950
resolve: {
50-
extensions: ['.ts', '.js']
51+
extensions: ['.ts', '.js'],
52+
alias: {
53+
raphaelmin: path.join(__dirname, 'node_modules/raphael/raphael.no-deps.min.js')
54+
}
5155
},
5256
module: {
5357
rules: [
@@ -70,10 +74,20 @@ const pageConfig = {
7074
{ test: /(\.woff|\.woff2)$/, loader: 'ignore-loader' },
7175
{ test: /\.ttf$/, loader: 'ignore-loader' },
7276
{ test: /\.eot$/, loader: 'ignore-loader' },
73-
{ test: /\.svg$/, loader: 'ignore-loader' }
77+
{ test: /\.svg$/, loader: 'ignore-loader' },
78+
{
79+
test: require.resolve('js-sequence-diagrams'),
80+
loader: 'imports-loader?Raphael=raphaelmin&_=lodash'
81+
}
7482
]
7583
},
84+
externals: 'fs',
7685
plugins: [
86+
new webpack.ProvidePlugin({
87+
$: 'jquery',
88+
jQuery: 'jquery',
89+
'window.jQuery': 'jquery',
90+
}),
7791
new MiniCssExtractPlugin({
7892
filename: "[name].css",
7993
chunkFilename: "[id].css"

0 commit comments

Comments
 (0)