Skip to content

Commit

Permalink
feat(modeling): disable autoResize for annotation changes
Browse files Browse the repository at this point in the history
closes #2049
  • Loading branch information
marstamm committed Jan 11, 2024
1 parent 89e5c29 commit f113184
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/features/modeling/behavior/TextAnnotationBehavior.js
Original file line number Diff line number Diff line change
@@ -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'
];
3 changes: 3 additions & 0 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -77,6 +78,7 @@ export default {
'spaceToolBehavior',
'subProcessPlaneBehavior',
'subProcessStartEventBehavior',
'textAnnotationBehavior',
'toggleCollapseConnectionBehaviour',
'toggleElementCollapseBehaviour',
'unclaimIdBehavior',
Expand Down Expand Up @@ -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 ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0sumicc" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.19.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="Process_00kwner" isExecutable="true">
<bpmn:subProcess id="Subprocess_1">
<bpmn:task id="Task_1" />
<bpmn:textAnnotation id="TextAnnotation_1" />
</bpmn:subProcess>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_00kwner">
<bpmndi:BPMNShape id="Activity_0oq21yg_di" bpmnElement="Subprocess_1" isExpanded="true">
<dc:Bounds x="160" y="70" width="350" height="200" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="TextAnnotation_1beb5hp_di" bpmnElement="TextAnnotation_1">
<dc:Bounds x="380" y="80" width="100" height="30" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0stlo9y_di" bpmnElement="Task_1">
<dc:Bounds x="290" y="130" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
62 changes: 62 additions & 0 deletions test/spec/features/modeling/behavior/TextAnnotationBehaviorSpec.js
Original file line number Diff line number Diff line change
@@ -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);
}));

});

0 comments on commit f113184

Please sign in to comment.