BpmnInteractionEvents.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { is } from '../../util/ModelUtil';
  2. import { isExpanded } from '../../util/DiUtil';
  3. /**
  4. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  5. * @typedef {import('diagram-js/lib/features/interaction-events/InteractionEvents').default} InteractionEvents
  6. *
  7. * @typedef {import('../../model/Types').Element} Element
  8. * @typedef {import('../../model/Types').Shape} Shape
  9. */
  10. var LABEL_WIDTH = 30,
  11. LABEL_HEIGHT = 30;
  12. /**
  13. * BPMN-specific hit zones and interaction fixes.
  14. *
  15. * @param {EventBus} eventBus
  16. * @param {InteractionEvents} interactionEvents
  17. */
  18. export default function BpmnInteractionEvents(eventBus, interactionEvents) {
  19. this._interactionEvents = interactionEvents;
  20. var self = this;
  21. eventBus.on([
  22. 'interactionEvents.createHit',
  23. 'interactionEvents.updateHit'
  24. ], function(context) {
  25. var element = context.element,
  26. gfx = context.gfx;
  27. if (is(element, 'bpmn:Lane')) {
  28. return self._createParticipantHit(element, gfx);
  29. } else
  30. if (is(element, 'bpmn:Participant')) {
  31. if (isExpanded(element)) {
  32. return self._createParticipantHit(element, gfx);
  33. } else {
  34. return self._createDefaultHit(element, gfx);
  35. }
  36. } else
  37. if (is(element, 'bpmn:SubProcess')) {
  38. if (isExpanded(element)) {
  39. return self._createSubProcessHit(element, gfx);
  40. } else {
  41. return self._createDefaultHit(element, gfx);
  42. }
  43. }
  44. });
  45. }
  46. BpmnInteractionEvents.$inject = [
  47. 'eventBus',
  48. 'interactionEvents'
  49. ];
  50. /**
  51. * @param {Element} element
  52. * @param {SVGElement} gfx
  53. *
  54. * @return {boolean}
  55. */
  56. BpmnInteractionEvents.prototype._createDefaultHit = function(element, gfx) {
  57. this._interactionEvents.removeHits(gfx);
  58. this._interactionEvents.createDefaultHit(element, gfx);
  59. // indicate that we created a hit
  60. return true;
  61. };
  62. /**
  63. * @param {Shape} element
  64. * @param {SVGElement} gfx
  65. *
  66. * @return {boolean}
  67. */
  68. BpmnInteractionEvents.prototype._createParticipantHit = function(element, gfx) {
  69. // remove existing hits
  70. this._interactionEvents.removeHits(gfx);
  71. // add body hit
  72. this._interactionEvents.createBoxHit(gfx, 'no-move', {
  73. width: element.width,
  74. height: element.height
  75. });
  76. // add outline hit
  77. this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
  78. width: element.width,
  79. height: element.height
  80. });
  81. // add label hit
  82. this._interactionEvents.createBoxHit(gfx, 'all', {
  83. width: LABEL_WIDTH,
  84. height: element.height
  85. });
  86. // indicate that we created a hit
  87. return true;
  88. };
  89. /**
  90. * @param {Shape} element
  91. * @param {SVGElement} gfx
  92. *
  93. * @return {boolean}
  94. */
  95. BpmnInteractionEvents.prototype._createSubProcessHit = function(element, gfx) {
  96. // remove existing hits
  97. this._interactionEvents.removeHits(gfx);
  98. // add body hit
  99. this._interactionEvents.createBoxHit(gfx, 'no-move', {
  100. width: element.width,
  101. height: element.height
  102. });
  103. // add outline hit
  104. this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
  105. width: element.width,
  106. height: element.height
  107. });
  108. // add label hit
  109. this._interactionEvents.createBoxHit(gfx, 'all', {
  110. width: element.width,
  111. height: LABEL_HEIGHT
  112. });
  113. // indicate that we created a hit
  114. return true;
  115. };