IsHorizontalFix.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import {
  4. getBusinessObject,
  5. getDi
  6. } from '../../../util/ModelUtil';
  7. import {
  8. isAny
  9. } from '../util/ModelingUtil';
  10. /**
  11. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  12. */
  13. /**
  14. * A component that makes sure that each created or updated
  15. * Pool and Lane is assigned an isHorizontal property set to true.
  16. *
  17. * @param {EventBus} eventBus
  18. */
  19. export default function IsHorizontalFix(eventBus) {
  20. CommandInterceptor.call(this, eventBus);
  21. var elementTypesToUpdate = [
  22. 'bpmn:Participant',
  23. 'bpmn:Lane'
  24. ];
  25. this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) {
  26. var shape = event.context.shape,
  27. bo = getBusinessObject(shape),
  28. di = getDi(shape);
  29. if (isAny(bo, elementTypesToUpdate)) {
  30. var isHorizontal = di.get('isHorizontal');
  31. if (isHorizontal === undefined) {
  32. isHorizontal = true;
  33. }
  34. // set attribute directly to avoid modeling#updateProperty side effects
  35. di.set('isHorizontal', isHorizontal);
  36. }
  37. });
  38. }
  39. IsHorizontalFix.$inject = [ 'eventBus' ];
  40. inherits(IsHorizontalFix, CommandInterceptor);