diff --git a/lib/features/modeling/behavior/TextAnnotationBehavior.js b/lib/features/modeling/behavior/TextAnnotationBehavior.js new file mode 100644 index 0000000000..495e053516 --- /dev/null +++ b/lib/features/modeling/behavior/TextAnnotationBehavior.js @@ -0,0 +1,30 @@ +import inherits from 'inherits-browser'; + +import { is } from '../../../util/ModelUtil'; + +import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; + +/** + * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus + */ + +export default function TextAnnotationBehavior(eventBus) { + + CommandInterceptor.call(this, eventBus); + + this.preExecute([ 'shape.create', 'shape.resize', 'elements.move' ], function(context) { + const shapes = context.shapes || [ context.shape ]; + + if (shapes.length === 1 && is(shapes[0], 'bpmn:TextAnnotation')) { + context.hints = context.hints || {}; + + context.hints.autoResize = false; + } + }, true); +} + +inherits(TextAnnotationBehavior, CommandInterceptor); + +TextAnnotationBehavior.$inject = [ + 'eventBus' +]; \ No newline at end of file diff --git a/lib/features/modeling/behavior/index.js b/lib/features/modeling/behavior/index.js index 81e7ac18a1..5e34c1a816 100644 --- a/lib/features/modeling/behavior/index.js +++ b/lib/features/modeling/behavior/index.js @@ -32,6 +32,7 @@ import RootElementReferenceBehavior from './RootElementReferenceBehavior'; import SpaceToolBehavior from './SpaceToolBehavior'; import SubProcessPlaneBehavior from './SubProcessPlaneBehavior'; import SubProcessStartEventBehavior from './SubProcessStartEventBehavior'; +import TextAnnotationBehavior from './TextAnnotationBehavior'; import ToggleCollapseConnectionBehaviour from './ToggleCollapseConnectionBehaviour'; import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour'; import UnclaimIdBehavior from './UnclaimIdBehavior'; @@ -77,6 +78,7 @@ export default { 'spaceToolBehavior', 'subProcessPlaneBehavior', 'subProcessStartEventBehavior', + 'textAnnotationBehavior', 'toggleCollapseConnectionBehaviour', 'toggleElementCollapseBehaviour', 'unclaimIdBehavior', @@ -117,6 +119,7 @@ export default { spaceToolBehavior: [ 'type', SpaceToolBehavior ], subProcessPlaneBehavior: [ 'type', SubProcessPlaneBehavior ], subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ], + textAnnotationBehavior: [ 'type', TextAnnotationBehavior ], toggleCollapseConnectionBehaviour: [ 'type', ToggleCollapseConnectionBehaviour ], toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ], unclaimIdBehavior: [ 'type', UnclaimIdBehavior ], diff --git a/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.bpmn b/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.bpmn new file mode 100644 index 0000000000..e199ca3170 --- /dev/null +++ b/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.bpmn @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.js b/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.js new file mode 100644 index 0000000000..be7d753413 --- /dev/null +++ b/test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.js @@ -0,0 +1,62 @@ +import { + bootstrapModeler, + inject +} from 'test/TestHelper'; + +import modelingModule from 'lib/features/modeling'; +import coreModule from 'lib/core'; +import autoResizeModule from 'lib/features/auto-resize'; + + +describe('features/modeling - TextAnnotationBehavior', function() { + + var testModules = [ coreModule, modelingModule, autoResizeModule ]; + + var processDiagramXML = require('./TextAnnotationBehaviorSpec.bpmn'); + + beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); + + var annotation, + task, + subprocess; + + beforeEach(inject(function(elementRegistry) { + annotation = elementRegistry.get('TextAnnotation_1'); + task = elementRegistry.get('Task_1'); + subprocess = elementRegistry.get('Subprocess_1'); + })); + + + it('should NOT resize Container on appending Text Annotation', inject(function(modeling) { + + // when + modeling.appendShape(task, { type: 'bpmn:TextAnnotation' }); + + // then + expect(subprocess.width).to.equal(350); + expect(subprocess.height).to.equal(200); + })); + + + it('should NOT resize Container on Text Annotation resize', inject(function(modeling) { + + // when + modeling.resizeShape(annotation, { x: 0, y: 0, width: 1000, height: 1000 }); + + // then + expect(subprocess.width).to.equal(350); + expect(subprocess.height).to.equal(200); + })); + + + it('should NOT resize Container on Text Annotation resize', inject(function(modeling) { + + // when + modeling.moveShape(annotation, { x: 250, y: 250 }); + + // then + expect(subprocess.width).to.equal(350); + expect(subprocess.height).to.equal(200); + })); + +});