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

100% Statements 24/24
100% Branches 14/14
100% Functions 4/4
100% Lines 24/24

    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71

    1128×

    1128×
    22×

    22×
    19×

    22×
    2×

    3×

    1128×

    22×
    22×

    22×
    139×
    139×
    139×

    139×

    6×

    6×
    4×

    2×

    6×

    6×

    1×

    1×import inherits from 'inherits';

    import {
      forEach
    } from 'min-dash';

    import { is } from '../../../util/ModelUtil';

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

    export default function CopyPasteBehavior(eventBus, modeling, canvas) {

      CommandInterceptor.call(this, eventBus);

      this.preExecute('elements.paste', 1500, function(context) {
        var topParent = context.topParent;

        // always grab the latest root
        if (!topParent.parent) {
          context.topParent = canvas.getRootElement();
        }

        if (is(topParent, 'bpmn:Lane')) {
          do {
            // unwrap Lane -> LaneSet -> (Lane | FlowElementsContainer)
            topParent = context.topParent = topParent.parent;

          } while (is(topParent, 'bpmn:Lane') || !is(topParent, 'bpmn:Participant'));
        }
      }, true);

      this.postExecute('elements.paste', function(context) {

        var tree = context.tree,
            createdElements = tree.createdElements;

        forEach(createdElements, function(data) {
          var element = data.element,
              businessObject = element.businessObject,
              descriptor = data.descriptor,
              defaultFlow;

          if ((is(businessObject, 'bpmn:ExclusiveGateway') || is(businessObject, 'bpmn:InclusiveGateway') ||
               is(businessObject, 'bpmn:Activity')) && descriptor.default) {

            defaultFlow = createdElements[descriptor.default];

            // if the default flow wasn't created, means that it wasn't copied
            if (defaultFlow) {
              defaultFlow = defaultFlow.element;
            } else {
              defaultFlow = undefined;
            }

            delete element.default;

            modeling.updateProperties(element, { default: defaultFlow });
          }
        });
      }, true);
    }

    CopyPasteBehavior.$inject = [
      'eventBus',
      'modeling',
      'canvas'
    ];

    inherits(CopyPasteBehavior, CommandInterceptor);