feat(space-tool): ensure minimum size when resizing shapes

This commit is contained in:
Philipp Fromme 2020-01-19 10:07:52 +01:00 committed by Nico Rehwaldt
parent 035bb0c1fd
commit 7ee304f424
5 changed files with 117 additions and 3 deletions

View File

@ -6,9 +6,11 @@ import { getParticipantResizeConstraints } from './util/ResizeUtil';
var HIGH_PRIORITY = 1500;
var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 },
TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
export var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 };
export var SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };
export var TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
/**

View File

@ -0,0 +1,36 @@
import { forEach } from 'min-dash';
import { is } from '../../../util/ModelUtil';
import { isExpanded } from '../../../util/DiUtil';
import {
PARTICIPANT_MIN_DIMENSIONS,
SUB_PROCESS_MIN_DIMENSIONS,
TEXT_ANNOTATION_MIN_DIMENSIONS
} from './ResizeBehavior';
export default function SpaceToolBehavior(eventBus) {
eventBus.on('spaceTool.getMinDimensions', function(context) {
var shapes = context.shapes,
minDimensions = {};
forEach(shapes, function(shape) {
var id = shape.id;
if (is(shape, 'bpmn:Participant')) {
minDimensions[ id ] = PARTICIPANT_MIN_DIMENSIONS;
}
if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
minDimensions[ id ] = SUB_PROCESS_MIN_DIMENSIONS;
}
if (is(shape, 'bpmn:TextAnnotation')) {
minDimensions[ id ] = TEXT_ANNOTATION_MIN_DIMENSIONS;
}
});
return minDimensions;
});
}

View File

@ -25,6 +25,7 @@ import ReplaceElementBehaviour from './ReplaceElementBehaviour';
import ResizeBehavior from './ResizeBehavior';
import ResizeLaneBehavior from './ResizeLaneBehavior';
import RemoveElementBehavior from './RemoveElementBehavior';
import SpaceToolBehavior from './SpaceToolBehavior';
import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
import UnclaimIdBehavior from './UnclaimIdBehavior';
@ -61,6 +62,7 @@ export default {
'resizeBehavior',
'resizeLaneBehavior',
'toggleElementCollapseBehaviour',
'spaceToolBehavior',
'subProcessStartEventBehavior',
'unclaimIdBehavior',
'unsetDefaultFlowBehavior',
@ -94,6 +96,7 @@ export default {
resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
removeElementBehavior: [ 'type', RemoveElementBehavior ],
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
spaceToolBehavior: [ 'type', SpaceToolBehavior ],
subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],

View File

@ -0,0 +1,13 @@
<?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" id="Definitions_1ev9p7s" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<bpmn:process id="Process_1msk4wr" isExecutable="true">
<bpmn:subProcess id="SubProcess_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1msk4wr">
<bpmndi:BPMNShape id="SubProcess_04mmoqh_di" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds x="0" y="0" width="350" height="200" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,60 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';
import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';
import rulesModule from 'lib/features/rules';
import snappingModule from 'lib/features/snapping';
import spaceToolModule from 'diagram-js/lib/features/space-tool';
import {
createCanvasEvent as canvasEvent
} from '../../../../util/MockEvents';
import { SUB_PROCESS_MIN_DIMENSIONS } from 'lib/features/modeling/behavior/ResizeBehavior';
var testModules = [
coreModule,
modelingModule,
rulesModule,
snappingModule,
spaceToolModule
];
describe('features/modeling - space tool behavior', function() {
describe('participant', function() {
describe('minimum dimensions', function() {
var diagramXML = require('./SpaceToolBehaviorSpec.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should ensure minimum dimensions', inject(
function(dragging, elementRegistry, spaceTool) {
// given
var subProcess = elementRegistry.get('SubProcess_1');
// when
spaceTool.activateMakeSpace(canvasEvent({ x: 300, y: 0 }));
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
// then
expect(subProcess.width).to.equal(SUB_PROCESS_MIN_DIMENSIONS.width);
})
);
});
});
});