SubProcessStartEventBehavior.js 1.1 KB

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