From 251720d08e2bff212da9e2037bacf344dc782e36 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 9 Aug 2021 12:09:45 +0200 Subject: [PATCH] feat: make elementFactory._getDefaultSize public This has the benefit of using the public API method across our code base. --- lib/features/modeling/ElementFactory.js | 36 +++++++++++-------- .../ToggleElementCollapseBehaviour.js | 2 +- lib/features/replace/BpmnReplace.js | 6 ++-- .../behavior/CreateParticipantBehaviorSpec.js | 7 ++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 31ae257f..17abb051 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -6,7 +6,11 @@ import { import inherits from 'inherits'; -import { is } from '../../util/ModelUtil'; +import { + getBusinessObject, + getDi, + is +} from '../../util/ModelUtil'; import { isExpanded @@ -127,7 +131,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { delete attrs.eventDefinitionType; } - size = this._getDefaultSize(businessObject); + size = this.getDefaultSize(businessObject, di); attrs = assign({ businessObject: businessObject, @@ -139,54 +143,56 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { }; -ElementFactory.prototype._getDefaultSize = function(semantic) { +ElementFactory.prototype.getDefaultSize = function(element, di) { - if (is(semantic, 'bpmn:SubProcess')) { + var bo = getBusinessObject(element); + di = di || getDi(element); - if (isExpanded(semantic)) { + if (is(bo, 'bpmn:SubProcess')) { + if (isExpanded(bo, di)) { return { width: 350, height: 200 }; } else { return { width: 100, height: 80 }; } } - if (is(semantic, 'bpmn:Task')) { + if (is(bo, 'bpmn:Task')) { return { width: 100, height: 80 }; } - if (is(semantic, 'bpmn:Gateway')) { + if (is(bo, 'bpmn:Gateway')) { return { width: 50, height: 50 }; } - if (is(semantic, 'bpmn:Event')) { + if (is(bo, 'bpmn:Event')) { return { width: 36, height: 36 }; } - if (is(semantic, 'bpmn:Participant')) { - if (isExpanded(semantic)) { + if (is(bo, 'bpmn:Participant')) { + if (isExpanded(bo, di)) { return { width: 600, height: 250 }; } else { return { width: 400, height: 60 }; } } - if (is(semantic, 'bpmn:Lane')) { + if (is(bo, 'bpmn:Lane')) { return { width: 400, height: 100 }; } - if (is(semantic, 'bpmn:DataObjectReference')) { + if (is(bo, 'bpmn:DataObjectReference')) { return { width: 36, height: 50 }; } - if (is(semantic, 'bpmn:DataStoreReference')) { + if (is(bo, 'bpmn:DataStoreReference')) { return { width: 50, height: 50 }; } - if (is(semantic, 'bpmn:TextAnnotation')) { + if (is(bo, 'bpmn:TextAnnotation')) { return { width: 100, height: 30 }; } - if (is(semantic, 'bpmn:Group')) { + if (is(bo, 'bpmn:Group')) { return { width: 300, height: 300 }; } diff --git a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js index afcb405f..c0393ad6 100644 --- a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js +++ b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js @@ -110,7 +110,7 @@ export default function ToggleElementCollapseBehaviour( this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY, function(e) { var shape = e.context.shape, - defaultSize = elementFactory._getDefaultSize(shape), + defaultSize = elementFactory.getDefaultSize(shape), newBounds; if (shape.collapsed) { diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index cc1a28e6..7a1dc3ba 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -207,12 +207,12 @@ export default function BpmnReplace( // apply same width and default height newElement.width = element.width; - newElement.height = elementFactory._getDefaultSize(newBusinessObject).height; + newElement.height = elementFactory.getDefaultSize(newElement).height; } if (!rules.allowed('shape.resize', { shape: newBusinessObject })) { - newElement.height = elementFactory._getDefaultSize(newBusinessObject).height; - newElement.width = elementFactory._getDefaultSize(newBusinessObject).width; + newElement.height = elementFactory.getDefaultSize(newElement).height; + newElement.width = elementFactory.getDefaultSize(newElement).width; } newBusinessObject.name = oldBusinessObject.name; diff --git a/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js b/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js index 3e8f4a98..01bcfa57 100644 --- a/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js @@ -335,7 +335,6 @@ describe('features/modeling - create participant', function() { beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); var participant, - participantBo, process, processGfx; @@ -346,7 +345,6 @@ describe('features/modeling - create participant', function() { processGfx = canvas.getGraphics(process); participant = elementFactory.createParticipantShape(); - participantBo = participant.businessObject; create.start(canvasEvent({ x: 100, y: 100 }), participant); @@ -357,7 +355,7 @@ describe('features/modeling - create participant', function() { it('should fit participant', inject(function(elementFactory) { // then - var defaultSize = elementFactory._getDefaultSize(participantBo); + var defaultSize = elementFactory.getDefaultSize(participant); expect(participant.width).to.equal(defaultSize.width); expect(participant.height).to.equal(defaultSize.height); @@ -423,7 +421,6 @@ describe('features/modeling - create participant', function() { var process = canvas.getRootElement(), processGfx = canvas.getGraphics(process), participant = elementFactory.createParticipantShape(), - participantBo = participant.businessObject, groupElement = elementFactory.createShape({ type: 'bpmn:Group' }); modeling.createShape(groupElement, { x: 100, y: 100 }, process); @@ -433,7 +430,7 @@ describe('features/modeling - create participant', function() { dragging.hover({ element: process, gfx: processGfx }); // then - var defaultSize = elementFactory._getDefaultSize(participantBo); + var defaultSize = elementFactory.getDefaultSize(participant); expect(participant.width).to.equal(defaultSize.width); expect(participant.height).to.equal(defaultSize.height);