mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-02-08 23:25:04 +00:00
feat(space-tool): ensure minimum size when resizing shapes
This commit is contained in:
parent
035bb0c1fd
commit
7ee304f424
@ -6,9 +6,11 @@ import { getParticipantResizeConstraints } from './util/ResizeUtil';
|
|||||||
|
|
||||||
var HIGH_PRIORITY = 1500;
|
var HIGH_PRIORITY = 1500;
|
||||||
|
|
||||||
var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
|
export 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 SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };
|
||||||
|
|
||||||
|
export var TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
36
lib/features/modeling/behavior/SpaceToolBehavior.js
Normal file
36
lib/features/modeling/behavior/SpaceToolBehavior.js
Normal 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;
|
||||||
|
});
|
||||||
|
}
|
@ -25,6 +25,7 @@ import ReplaceElementBehaviour from './ReplaceElementBehaviour';
|
|||||||
import ResizeBehavior from './ResizeBehavior';
|
import ResizeBehavior from './ResizeBehavior';
|
||||||
import ResizeLaneBehavior from './ResizeLaneBehavior';
|
import ResizeLaneBehavior from './ResizeLaneBehavior';
|
||||||
import RemoveElementBehavior from './RemoveElementBehavior';
|
import RemoveElementBehavior from './RemoveElementBehavior';
|
||||||
|
import SpaceToolBehavior from './SpaceToolBehavior';
|
||||||
import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
|
import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
|
||||||
import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
|
import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
|
||||||
import UnclaimIdBehavior from './UnclaimIdBehavior';
|
import UnclaimIdBehavior from './UnclaimIdBehavior';
|
||||||
@ -61,6 +62,7 @@ export default {
|
|||||||
'resizeBehavior',
|
'resizeBehavior',
|
||||||
'resizeLaneBehavior',
|
'resizeLaneBehavior',
|
||||||
'toggleElementCollapseBehaviour',
|
'toggleElementCollapseBehaviour',
|
||||||
|
'spaceToolBehavior',
|
||||||
'subProcessStartEventBehavior',
|
'subProcessStartEventBehavior',
|
||||||
'unclaimIdBehavior',
|
'unclaimIdBehavior',
|
||||||
'unsetDefaultFlowBehavior',
|
'unsetDefaultFlowBehavior',
|
||||||
@ -94,6 +96,7 @@ export default {
|
|||||||
resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
|
resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
|
||||||
removeElementBehavior: [ 'type', RemoveElementBehavior ],
|
removeElementBehavior: [ 'type', RemoveElementBehavior ],
|
||||||
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
|
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
|
||||||
|
spaceToolBehavior: [ 'type', SpaceToolBehavior ],
|
||||||
subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
|
subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
|
||||||
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
|
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
|
||||||
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
|
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
|
||||||
|
@ -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>
|
@ -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);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user