SubProcessStartEventBehavior.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import { is } from '../../../util/ModelUtil';
  4. import { isExpanded } from '../../../util/DiUtil.js';
  5. /**
  6. * @typedef {import('didi').Injector} Injector
  7. * @typedef {import('../Modeling').default} Modeling
  8. */
  9. /**
  10. * Add start event replacing element with expanded sub process.
  11. *
  12. * @param {Injector} injector
  13. * @param {Modeling} modeling
  14. */
  15. export default function SubProcessStartEventBehavior(injector, modeling) {
  16. injector.invoke(CommandInterceptor, this);
  17. this.postExecuted('shape.replace', function(event) {
  18. var oldShape = event.context.oldShape,
  19. newShape = event.context.newShape;
  20. if (
  21. !is(newShape, 'bpmn:SubProcess') ||
  22. ! (is(oldShape, 'bpmn:Task') || is(oldShape, 'bpmn:CallActivity')) ||
  23. !isExpanded(newShape)
  24. ) {
  25. return;
  26. }
  27. var position = getStartEventPosition(newShape);
  28. modeling.createShape({ type: 'bpmn:StartEvent' }, position, newShape);
  29. });
  30. }
  31. SubProcessStartEventBehavior.$inject = [
  32. 'injector',
  33. 'modeling'
  34. ];
  35. inherits(SubProcessStartEventBehavior, CommandInterceptor);
  36. // helpers //////////
  37. function getStartEventPosition(shape) {
  38. return {
  39. x: shape.x + shape.width / 6,
  40. y: shape.y + shape.height / 2
  41. };
  42. }