2019-05-23 20:35:10 +00:00
|
|
|
import { getLanesRoot } from '../util/LaneUtil';
|
|
|
|
|
|
|
|
import { is } from '../../../util/ModelUtil';
|
|
|
|
|
|
|
|
import { isAny } from '../util/ModelingUtil';
|
|
|
|
|
|
|
|
var HIGH_PRIORITY = 1500;
|
|
|
|
|
|
|
|
/**
|
2019-06-14 11:24:09 +00:00
|
|
|
* Correct hover targets in certain situations to improve diagram interaction.
|
2019-05-23 20:35:10 +00:00
|
|
|
*
|
|
|
|
* @param {ElementRegistry} elementRegistry
|
|
|
|
* @param {EventBus} eventBus
|
2019-06-14 11:24:09 +00:00
|
|
|
* @param {Canvas} canvas
|
2019-05-23 20:35:10 +00:00
|
|
|
*/
|
2019-06-14 11:24:09 +00:00
|
|
|
export default function FixHoverBehavior(elementRegistry, eventBus, canvas) {
|
|
|
|
|
2019-05-23 20:35:10 +00:00
|
|
|
eventBus.on([
|
|
|
|
'create.hover',
|
|
|
|
'create.move',
|
|
|
|
'create.end',
|
|
|
|
'shape.move.hover',
|
|
|
|
'shape.move.move',
|
|
|
|
'shape.move.end'
|
|
|
|
], HIGH_PRIORITY, function(event) {
|
|
|
|
var context = event.context,
|
2019-06-14 11:24:09 +00:00
|
|
|
shape = context.shape || event.shape,
|
2019-05-23 20:35:10 +00:00
|
|
|
hover = event.hover;
|
|
|
|
|
2019-06-14 11:24:09 +00:00
|
|
|
// ensure elements are not dropped onto a bpmn:Lane but onto
|
|
|
|
// the underlying bpmn:Participant
|
2019-05-23 20:35:10 +00:00
|
|
|
if (is(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
|
|
|
|
event.hover = getLanesRoot(hover);
|
|
|
|
event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
|
|
|
}
|
2019-06-14 11:24:09 +00:00
|
|
|
|
|
|
|
var rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// ensure bpmn:Group and label elements are dropped
|
|
|
|
// always onto the root
|
|
|
|
if (hover !== rootElement && (shape.labelTarget || is(shape, 'bpmn:Group'))) {
|
|
|
|
event.hover = rootElement;
|
|
|
|
event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
|
|
|
}
|
2019-05-23 20:35:10 +00:00
|
|
|
});
|
2019-06-14 11:24:09 +00:00
|
|
|
|
2019-05-23 20:35:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 09:15:01 +00:00
|
|
|
FixHoverBehavior.$inject = [
|
2019-05-23 20:35:10 +00:00
|
|
|
'elementRegistry',
|
2019-06-14 11:24:09 +00:00
|
|
|
'eventBus',
|
|
|
|
'canvas'
|
2019-05-23 20:35:10 +00:00
|
|
|
];
|