BpmnInteractionEvents.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { is } from '../../util/ModelUtil';
  2. import { isExpanded } from '../../util/DiUtil';
  3. var LABEL_WIDTH = 30,
  4. LABEL_HEIGHT = 30;
  5. /**
  6. * BPMN-specific hit zones and interaction fixes.
  7. *
  8. * @param {EventBus} eventBus
  9. * @param {InteractionEvents} interactionEvents
  10. */
  11. export default function BpmnInteractionEvents(eventBus, interactionEvents) {
  12. this._interactionEvents = interactionEvents;
  13. var self = this;
  14. eventBus.on([
  15. 'interactionEvents.createHit',
  16. 'interactionEvents.updateHit'
  17. ], function(context) {
  18. var element = context.element,
  19. gfx = context.gfx;
  20. if (is(element, 'bpmn:Lane')) {
  21. return self.createParticipantHit(element, gfx);
  22. } else
  23. if (is(element, 'bpmn:Participant')) {
  24. if (isExpanded(element)) {
  25. return self.createParticipantHit(element, gfx);
  26. } else {
  27. return self.createDefaultHit(element, gfx);
  28. }
  29. } else
  30. if (is(element, 'bpmn:SubProcess')) {
  31. if (isExpanded(element)) {
  32. return self.createSubProcessHit(element, gfx);
  33. } else {
  34. return self.createDefaultHit(element, gfx);
  35. }
  36. }
  37. });
  38. }
  39. BpmnInteractionEvents.$inject = [
  40. 'eventBus',
  41. 'interactionEvents'
  42. ];
  43. BpmnInteractionEvents.prototype.createDefaultHit = function(element, gfx) {
  44. this._interactionEvents.removeHits(gfx);
  45. this._interactionEvents.createDefaultHit(element, gfx);
  46. // indicate that we created a hit
  47. return true;
  48. };
  49. BpmnInteractionEvents.prototype.createParticipantHit = function(element, gfx) {
  50. // remove existing hits
  51. this._interactionEvents.removeHits(gfx);
  52. // add outline hit
  53. this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
  54. width: element.width,
  55. height: element.height
  56. });
  57. // add label hit
  58. this._interactionEvents.createBoxHit(gfx, 'all', {
  59. width: LABEL_WIDTH,
  60. height: element.height
  61. });
  62. // indicate that we created a hit
  63. return true;
  64. };
  65. BpmnInteractionEvents.prototype.createSubProcessHit = function(element, gfx) {
  66. // remove existing hits
  67. this._interactionEvents.removeHits(gfx);
  68. // add outline hit
  69. this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
  70. width: element.width,
  71. height: element.height
  72. });
  73. // add label hit
  74. this._interactionEvents.createBoxHit(gfx, 'all', {
  75. width: element.width,
  76. height: LABEL_HEIGHT
  77. });
  78. // indicate that we created a hit
  79. return true;
  80. };