FixHoverBehavior.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { getLanesRoot } from '../util/LaneUtil';
  2. import { is } from '../../../util/ModelUtil';
  3. import { isAny } from '../util/ModelingUtil';
  4. var HIGH_PRIORITY = 1500;
  5. var HIGHEST_PRIORITY = 2000;
  6. /**
  7. * Correct hover targets in certain situations to improve diagram interaction.
  8. *
  9. * @param {ElementRegistry} elementRegistry
  10. * @param {EventBus} eventBus
  11. * @param {Canvas} canvas
  12. */
  13. export default function FixHoverBehavior(elementRegistry, eventBus, canvas) {
  14. eventBus.on([
  15. 'create.hover',
  16. 'create.move',
  17. 'create.end',
  18. 'shape.move.hover',
  19. 'shape.move.move',
  20. 'shape.move.end'
  21. ], HIGH_PRIORITY, function(event) {
  22. var context = event.context,
  23. shape = context.shape || event.shape,
  24. hover = event.hover;
  25. // ensure elements are not dropped onto a bpmn:Lane but onto
  26. // the underlying bpmn:Participant
  27. if (is(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
  28. event.hover = getLanesRoot(hover);
  29. event.hoverGfx = elementRegistry.getGraphics(event.hover);
  30. }
  31. var rootElement = canvas.getRootElement();
  32. // ensure bpmn:Group and label elements are dropped
  33. // always onto the root
  34. if (hover !== rootElement && (shape.labelTarget || is(shape, 'bpmn:Group'))) {
  35. event.hover = rootElement;
  36. event.hoverGfx = elementRegistry.getGraphics(event.hover);
  37. }
  38. });
  39. eventBus.on([
  40. 'connect.hover',
  41. 'connect.out',
  42. 'connect.end',
  43. 'connect.cleanup',
  44. 'global-connect.hover',
  45. 'global-connect.out',
  46. 'global-connect.end',
  47. 'global-connect.cleanup'
  48. ], HIGH_PRIORITY, function(event) {
  49. var hover = event.hover;
  50. // ensure connections start/end on bpmn:Participant,
  51. // not the underlying bpmn:Lane
  52. if (is(hover, 'bpmn:Lane')) {
  53. event.hover = getLanesRoot(hover) || hover;
  54. event.hoverGfx = elementRegistry.getGraphics(event.hover);
  55. }
  56. });
  57. eventBus.on([
  58. 'bendpoint.move.hover'
  59. ], HIGH_PRIORITY, function(event) {
  60. var context = event.context,
  61. hover = event.hover,
  62. type = context.type;
  63. // ensure reconnect start/end on bpmn:Participant,
  64. // not the underlying bpmn:Lane
  65. if (is(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
  66. event.hover = getLanesRoot(hover) || hover;
  67. event.hoverGfx = elementRegistry.getGraphics(event.hover);
  68. }
  69. });
  70. eventBus.on([
  71. 'connect.start'
  72. ], HIGH_PRIORITY, function(event) {
  73. var context = event.context,
  74. start = context.start;
  75. // ensure connect start on bpmn:Participant,
  76. // not the underlying bpmn:Lane
  77. if (is(start, 'bpmn:Lane')) {
  78. context.start = getLanesRoot(start) || start;
  79. }
  80. });
  81. // allow movement of participants from lanes
  82. eventBus.on('shape.move.start', HIGHEST_PRIORITY, function(event) {
  83. var shape = event.shape;
  84. if (is(shape, 'bpmn:Lane')) {
  85. event.shape = getLanesRoot(shape) || shape;
  86. }
  87. });
  88. }
  89. FixHoverBehavior.$inject = [
  90. 'elementRegistry',
  91. 'eventBus',
  92. 'canvas'
  93. ];