2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
|
|
|
import { isExpanded } from '../../../util/DiUtil';
|
|
|
|
import { isLabel } from '../../../util/LabelUtil';
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unclaims model IDs on element deletion.
|
|
|
|
*
|
2019-11-14 15:40:20 +00:00
|
|
|
* @param {Canvas} canvas
|
|
|
|
* @param {Injector} injector
|
|
|
|
* @param {Moddle} moddle
|
2018-04-02 19:01:53 +00:00
|
|
|
* @param {Modeling} modeling
|
|
|
|
*/
|
2019-11-14 15:40:20 +00:00
|
|
|
export default function UnclaimIdBehavior(canvas, injector, moddle, modeling) {
|
|
|
|
injector.invoke(CommandInterceptor, this);
|
|
|
|
|
|
|
|
this.preExecute('shape.delete', function(event) {
|
|
|
|
var context = event.context,
|
|
|
|
shape = context.shape,
|
|
|
|
shapeBo = shape.businessObject;
|
|
|
|
|
|
|
|
if (isLabel(shape)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
if (is(shape, 'bpmn:Participant') && isExpanded(shape)) {
|
|
|
|
moddle.ids.unclaim(shapeBo.processRef.id);
|
|
|
|
}
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
modeling.unclaimId(shapeBo.id, shapeBo);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.preExecute('connection.delete', function(event) {
|
2016-04-18 14:15:00 +00:00
|
|
|
var context = event.context,
|
2019-11-14 15:40:20 +00:00
|
|
|
connection = context.connection,
|
|
|
|
connectionBo = connection.businessObject;
|
|
|
|
|
|
|
|
modeling.unclaimId(connectionBo.id, connectionBo);
|
|
|
|
});
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
this.preExecute('canvas.updateRoot', function() {
|
|
|
|
var rootElement = canvas.getRootElement(),
|
|
|
|
rootElementBo = rootElement.businessObject;
|
2016-04-18 14:15:00 +00:00
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
moddle.ids.unclaim(rootElementBo.id);
|
2016-04-18 14:15:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(UnclaimIdBehavior, CommandInterceptor);
|
|
|
|
|
2019-11-14 15:40:20 +00:00
|
|
|
UnclaimIdBehavior.$inject = [ 'canvas', 'injector', 'moddle', 'modeling' ];
|