Skip to content

Commit 8bdb5e5

Browse files
committed
add example how to use Drawflow in a custom element
1 parent 998ddb8 commit 8bdb5e5

7 files changed

+3175
-1434
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ Example of exported data:
387387
```
388388

389389
## Example
390-
View the complete example in folder [docs](https://github.com/jerosoler/Drawflow/tree/master/docs).
390+
View the complete example in folder [docs](https://github.com/jerosoler/Drawflow/tree/master/docs).
391+
There is also an [example](docs/drawflow-element.html) how to use Drawflow in a custom element. (based on [LitElement](https://lit-element.polymer-project.org)).
391392

392393
## License
393394
MIT License

docs/drawflow-element.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script type="module" src="drawflow-element.js"></script>
5+
<title>Drawflow Element</title>
6+
</head>
7+
<body>
8+
<drawflow-element></drawflow-element>
9+
</body>
10+
</html>

docs/drawflow-element.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { css, LitElement, html } from 'lit-element';
2+
import { style } from '../dist/drawflow.style';
3+
import '../dist/drawflow.min';
4+
5+
class DrawflowElement extends LitElement {
6+
static get styles() {
7+
return [
8+
style,
9+
css`
10+
#drawflow {
11+
display: block;
12+
position: relative;
13+
width: 100%;
14+
height: 800px;
15+
}
16+
`
17+
];
18+
}
19+
20+
render() {
21+
return html`
22+
<div id="drawflow"></div>
23+
`;
24+
}
25+
26+
firstUpdated() {
27+
const container = this.shadowRoot?.getElementById('drawflow');
28+
const editor = new Drawflow(container);
29+
30+
editor.reroute = true;
31+
editor.reroute_fix_curvature = true;
32+
33+
editor.start();
34+
35+
const data = {
36+
name: ''
37+
};
38+
39+
editor.addNode('foo', 1, 1, 100, 200, 'foo', data, 'Foo');
40+
editor.addNode('bar', 1, 1, 400, 100, 'bar', data, 'Bar A');
41+
editor.addNode('bar', 1, 1, 400, 300, 'bar', data, 'Bar B');
42+
43+
editor.addConnection(1, 2, "output_1", "input_1");
44+
editor.addConnection(1, 3, "output_1", "input_1");
45+
}
46+
}
47+
48+
customElements.define("drawflow-element", DrawflowElement);

gulpfile.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
const gulp = require('gulp');
2-
const minify = require('gulp-minify');
32
const concat = require('gulp-concat');
43
const minifyCSS = require('gulp-minify-css');
4+
const replace = require('gulp-replace');
55

6-
7-
8-
/*
9-
gulp.task('js', done => {
10-
return gulp.src('src/*.js')
11-
.pipe(minify({noSource: true}))
12-
.pipe(concat('drawflow.min.js'))
6+
gulp.task('style', () => {
7+
return gulp.src('dist/drawflow.min.css')
8+
.pipe(replace(/^(.*)$/, 'import {css} from "lit-element"; export const style = css`$1`;'))
9+
.pipe(concat('drawflow.style.js'))
1310
.pipe(gulp.dest('dist/'))
14-
1511
});
16-
*/
17-
1812

19-
gulp.task('css', done => {
13+
gulp.task('css', () => {
2014
return gulp.src('src/*.css')
2115
.pipe(minifyCSS())
2216
.pipe(concat('drawflow.min.css'))
2317
.pipe(gulp.dest('dist/'))
2418
});
2519

26-
gulp.task('default', gulp.parallel(
27-
/*'js',*/
28-
'css'
20+
gulp.task('default', gulp.series(
21+
'css',
22+
'style'
2923
)
3024
);

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title>Drawflow</title>
88
</head>
99
<body>
10-
<script src="drawflow.min.js"></script>
10+
<script src="dist/drawflow.min.js"></script>
1111
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js" integrity="sha256-KzZiKy0DWYsnwMF+X1DvQngQ2/FxF7MF3Ff72XcpuPs=" crossorigin="anonymous"></script>
1212
<link rel="stylesheet" type="text/css" href="src/drawflow.css" />
1313
<link rel="stylesheet" type="text/css" href="docs/beautiful.css" />

0 commit comments

Comments
 (0)