mirror of
https://github.com/bpmn-io/bpmn-js.git
synced 2025-08-26 04:32:44 +08:00
feat(modeling): copy and paste boundary events
* allow copying boundary events without host * remove CreateBoundaryEventBehavior in favor of AttachEventBehavior Closes #1154 Closes #1202 Closes #1204 Closes #1205
This commit is contained in:
@ -1,35 +1,31 @@
|
||||
import inherits from 'inherits';
|
||||
|
||||
import { forEach } from 'min-dash';
|
||||
|
||||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
||||
|
||||
import {
|
||||
forEach
|
||||
} from 'min-dash';
|
||||
|
||||
import {
|
||||
isEventSubProcess
|
||||
} from '../../../util/DiUtil';
|
||||
|
||||
import { is } from '../../../util/ModelUtil';
|
||||
import { isEventSubProcess } from '../../../util/DiUtil';
|
||||
|
||||
|
||||
/**
|
||||
* Defines the behaviour of what happens to the elements inside a container
|
||||
* that morphs into another BPMN element
|
||||
* BPMN-specific replace behavior.
|
||||
*/
|
||||
export default function ReplaceElementBehaviour(
|
||||
eventBus, bpmnReplace, bpmnRules,
|
||||
elementRegistry, selection, modeling) {
|
||||
|
||||
CommandInterceptor.call(this, eventBus);
|
||||
bpmnReplace,
|
||||
bpmnRules,
|
||||
elementRegistry,
|
||||
injector,
|
||||
modeling,
|
||||
selection
|
||||
) {
|
||||
injector.invoke(CommandInterceptor, this);
|
||||
|
||||
this._bpmnReplace = bpmnReplace;
|
||||
this._elementRegistry = elementRegistry;
|
||||
this._selection = selection;
|
||||
this._modeling = modeling;
|
||||
|
||||
// replace elements on move
|
||||
this.postExecuted([ 'elements.move' ], 500, function(event) {
|
||||
|
||||
var context = event.context,
|
||||
target = context.newParent,
|
||||
newHost = context.newHost,
|
||||
@ -43,7 +39,7 @@ export default function ReplaceElementBehaviour(
|
||||
}
|
||||
});
|
||||
|
||||
// Change target to host when the moving element is a `bpmn:BoundaryEvent`
|
||||
// set target to host if attaching
|
||||
if (elements.length === 1 && newHost) {
|
||||
target = newHost;
|
||||
}
|
||||
@ -55,9 +51,8 @@ export default function ReplaceElementBehaviour(
|
||||
}
|
||||
}, this);
|
||||
|
||||
// update attachments if the host is replaced
|
||||
// update attachments on host replace
|
||||
this.postExecute([ 'shape.replace' ], 1500, function(e) {
|
||||
|
||||
var context = e.context,
|
||||
oldShape = context.oldShape,
|
||||
newShape = context.newShape,
|
||||
@ -72,6 +67,7 @@ export default function ReplaceElementBehaviour(
|
||||
|
||||
}, this);
|
||||
|
||||
// keep ID on shape replace
|
||||
this.postExecuted([ 'shape.replace' ], 1500, function(e) {
|
||||
var context = e.context,
|
||||
oldShape = context.oldShape,
|
||||
@ -84,32 +80,21 @@ export default function ReplaceElementBehaviour(
|
||||
|
||||
inherits(ReplaceElementBehaviour, CommandInterceptor);
|
||||
|
||||
|
||||
ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElements, newHost) {
|
||||
ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElements) {
|
||||
var elementRegistry = this._elementRegistry,
|
||||
bpmnReplace = this._bpmnReplace,
|
||||
selection = this._selection,
|
||||
modeling = this._modeling;
|
||||
selection = this._selection;
|
||||
|
||||
forEach(newElements, function(replacement) {
|
||||
|
||||
var newElement = {
|
||||
type: replacement.newElementType
|
||||
};
|
||||
|
||||
var oldElement = elementRegistry.get(replacement.oldElementId);
|
||||
|
||||
if (newHost && is(oldElement, 'bpmn:BoundaryEvent')) {
|
||||
modeling.updateAttachment(oldElement, null);
|
||||
}
|
||||
|
||||
var idx = elements.indexOf(oldElement);
|
||||
|
||||
elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
|
||||
|
||||
if (newHost && is(elements[idx], 'bpmn:BoundaryEvent')) {
|
||||
modeling.updateAttachment(elements[idx], newHost);
|
||||
}
|
||||
});
|
||||
|
||||
if (newElements) {
|
||||
@ -118,10 +103,10 @@ ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElemen
|
||||
};
|
||||
|
||||
ReplaceElementBehaviour.$inject = [
|
||||
'eventBus',
|
||||
'bpmnReplace',
|
||||
'bpmnRules',
|
||||
'elementRegistry',
|
||||
'selection',
|
||||
'modeling'
|
||||
'injector',
|
||||
'modeling',
|
||||
'selection'
|
||||
];
|
||||
|
Reference in New Issue
Block a user