diff --git a/lib/features/di-ordering/BpmnDiOrdering.js b/lib/features/di-ordering/BpmnDiOrdering.js index 86e8df94..9b345a15 100644 --- a/lib/features/di-ordering/BpmnDiOrdering.js +++ b/lib/features/di-ordering/BpmnDiOrdering.js @@ -2,6 +2,7 @@ import { getDi } from '../../util/ModelUtil'; import { filter, + forEach, map } from 'min-dash'; @@ -15,21 +16,24 @@ export default function BpmnDiOrdering(eventBus, canvas) { eventBus.on('saveXML.start', HIGH_PRIORITY, orderDi); function orderDi() { - var root = canvas.getRootElement(), - rootDi = getDi(root), - elements, - diElements; + var rootElements = canvas.getRootElements(); - elements = selfAndAllChildren([ root ], false); + forEach(rootElements, function(root) { + var rootDi = getDi(root), + elements, + diElements; - // only bpmndi:Shape and bpmndi:Edge can be direct children of bpmndi:Plane - elements = filter(elements, function(element) { - return element !== root && !element.labelTarget; + elements = selfAndAllChildren([ root ], false); + + // only bpmndi:Shape and bpmndi:Edge can be direct children of bpmndi:Plane + elements = filter(elements, function(element) { + return element !== root && !element.labelTarget; + }); + + diElements = map(elements, getDi); + + rootDi.set('planeElement', diElements); }); - - diElements = map(elements, getDi); - - rootDi.set('planeElement', diElements); } } diff --git a/test/spec/features/ordering/BpmnDiOrderingSpec.js b/test/spec/features/ordering/BpmnDiOrderingSpec.js index 665cdfb0..450da69d 100644 --- a/test/spec/features/ordering/BpmnDiOrderingSpec.js +++ b/test/spec/features/ordering/BpmnDiOrderingSpec.js @@ -109,6 +109,33 @@ describe('features/modeling - di ordering', function() { task1.id, ]); }); + + it('should order subprocess planes', function() { + + // given + var canvas = getBpmnJS().get('canvas'), + root; + + // when + var subProcess = add( + { type: 'bpmn:SubProcess', isExpanded: false, width: 300, height: 200 }, { x: 300, y: 200 } + ); + + var participant = add({ type: 'bpmn:Participant', width: 500, height: 300 }, { x: 300, y: 200 }), + task1 = add({ type: 'bpmn:Task' }, { x: 250, y: 200 }, subProcess.id + '_plane'); + + root = canvas.getRootElement(); + + // then + // subProcess id exists twice: once as collapsed shape and once as plane element + return expectDiOrder([ + root.id, + participant.id, + subProcess.id, + subProcess.id, + task1.id, + ]); + }); });