2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
assign
|
|
|
|
} from 'min-dash';
|
2015-09-08 12:38:50 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2015-09-08 12:38:50 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import BpmnElementFactory from 'lib/features/modeling/ElementFactory';
|
2015-09-08 12:38:50 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
DEFAULT_LABEL_SIZE
|
|
|
|
} from 'lib/util/LabelUtil';
|
|
|
|
|
|
|
|
|
|
|
|
export default function CustomElementFactory(injector) {
|
2016-06-21 22:42:54 +00:00
|
|
|
injector.invoke(BpmnElementFactory, this);
|
2015-09-08 12:38:50 +00:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.create = function(elementType, attrs) {
|
|
|
|
var type = attrs.type,
|
|
|
|
businessObject,
|
|
|
|
size;
|
|
|
|
|
|
|
|
if (elementType === 'label') {
|
2018-04-02 19:01:53 +00:00
|
|
|
return self.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE, attrs));
|
2015-09-08 12:38:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 13:32:52 +00:00
|
|
|
if (/^custom:/.test(type)) {
|
|
|
|
type = attrs.type.replace(/^custom:/, '');
|
2015-09-08 12:38:50 +00:00
|
|
|
|
|
|
|
businessObject = {};
|
|
|
|
|
|
|
|
size = self._getCustomElementSize(type);
|
|
|
|
|
|
|
|
return self.baseCreate(elementType,
|
|
|
|
assign({ type: elementType, businessObject: businessObject }, attrs, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.createBpmnElement(elementType, attrs);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(CustomElementFactory, BpmnElementFactory);
|
|
|
|
|
2016-06-21 22:42:54 +00:00
|
|
|
CustomElementFactory.$inject = [ 'injector' ];
|
2015-09-08 12:38:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the *width* and *height* for custom shapes.
|
|
|
|
*
|
|
|
|
* The following example shows an interface on how
|
|
|
|
* to setup the custom element's dimensions.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
2015-12-07 16:46:53 +00:00
|
|
|
* var shapes = {
|
|
|
|
* triangle: { width: 40, height: 40 },
|
|
|
|
* rectangle: { width: 100, height: 20 }
|
2015-09-08 12:38:50 +00:00
|
|
|
* };
|
|
|
|
*
|
2015-12-07 16:46:53 +00:00
|
|
|
* return shapes[type];
|
2015-09-08 12:38:50 +00:00
|
|
|
*
|
|
|
|
*
|
2020-04-03 13:51:45 +00:00
|
|
|
* @param {string} type
|
2015-09-08 12:38:50 +00:00
|
|
|
*
|
|
|
|
* @return {Bounds} { width, height}
|
|
|
|
*/
|
2016-06-07 06:46:45 +00:00
|
|
|
CustomElementFactory.prototype._getCustomElementSize = function(type) {
|
2015-09-08 12:38:50 +00:00
|
|
|
if (!type) {
|
|
|
|
return { width: 100, height: 80 };
|
|
|
|
}
|
|
|
|
|
|
|
|
var shapes = {
|
|
|
|
triangle: { width: 40, height: 40 },
|
|
|
|
circle: { width: 140, height: 140 }
|
|
|
|
};
|
|
|
|
|
|
|
|
return shapes[type];
|
|
|
|
};
|