# all files / bpmn-js/lib/features/modeling/behavior/ SubProcessStartEventBehavior.js

100% Statements 11/11
100% Branches 5/5
100% Functions 3/3
100% Lines 11/11

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50

    1189×

    1189×
    138×
    138×

    138×

    135×

    3×

    3×

    1×

    1×

    3×

     import inherits from 'inherits';

    import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

    import { is } from '../../../util/ModelUtil';
    import { isExpanded } from '../../../util/DiUtil.js';

    /**
     * Add start event replacing element with expanded sub process.
     *
     * @param {Injector} injector
     * @param {Modeling} modeling
     */
    export default function SubProcessStartEventBehavior(injector, modeling) {
      injector.invoke(CommandInterceptor, this);

      this.postExecuted('shape.replace', function(event) {
        var oldShape = event.context.oldShape,
            newShape = event.context.newShape;

        if (
          !is(newShape, 'bpmn:SubProcess') ||
          !is(oldShape, 'bpmn:Task') ||
          !isExpanded(newShape)
        ) {
          return;
        }

        var position = getStartEventPosition(newShape);

        modeling.createShape({ type: 'bpmn:StartEvent' }, position, newShape);
      });
    }

    SubProcessStartEventBehavior.$inject = [
      'injector',
      'modeling'
    ];

    inherits(SubProcessStartEventBehavior, CommandInterceptor);

    // helpers //////////

    function getStartEventPosition(shape) {
      return {
        x: shape.x + shape.width / 6,
        y: shape.y + shape.height / 2
      };
    }