/
shapes.js
51 lines (41 loc) · 1.03 KB
/
shapes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
isArray,
isObject,
isString
} from 'min-dash';
/**
* Parses a list of spahes shape from a list of objects or a comma-separated string
*/
export default function ShapesParser(elementRegistry) {
return function(args, options) {
if (isString(args)) {
args = args.split(',');
} else
if (!isArray(args)) {
args = [ args ];
}
return args.map(function(arg) {
// assume element passed is shape already
if (isObject(arg)) {
return arg;
}
var e = elementRegistry.get(arg);
if (!e) {
if (options.optional) {
return null;
} else {
if (arg) {
throw new Error('element with id <' + arg + '> does not exist');
} else {
throw new Error('argument required');
}
}
}
if (e.waypoints) {
throw new Error('element <' + arg + '> is a connection');
}
return e;
}).filter(function(e) { return e; });
};
}
ShapesParser.$inject = [ 'elementRegistry' ];