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

96.97% Statements 32/33
94.44% Branches 17/18
100% Functions 4/4
96.97% Lines 32/33

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112

    1×

    1128×

    4×

    4×
    4×

    4×

    9×
    4×

    5×

    9×

    4×

    4×
    1×

    3×

    4×
    2×

    2×

    4×
    3×

    3×

    1128×

    347×
    347×
    347×
    347×

    347×
    317×

    30×
    26×

    4×

    1×

    1×import inherits from 'inherits';

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

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

    import {
      getChildLanes
    } from '../util/LaneUtil';

    import {
      eachElement
    } from 'diagram-js/lib/util/Elements';

    var LOW_PRIORITY = 500;

    /**
     * BPMN specific delete lane behavior
     */
    export default function DeleteLaneBehavior(eventBus, modeling, spaceTool) {

      CommandInterceptor.call(this, eventBus);

      function compensateLaneDelete(shape, oldParent) {

        var siblings = getChildLanes(oldParent);

        var topAffected = [];
        var bottomAffected = [];

        eachElement(siblings, function(element) {

          if (element.y > shape.y) {
            bottomAffected.push(element);
          } else {
            topAffected.push(element);
          }

          return element.children;
        });

        Iif (!siblings.length) {
          return;
        }

        var offset;

        if (bottomAffected.length && topAffected.length) {
          offset = shape.height / 2;
        } else {
          offset = shape.height;
        }

        var topAdjustments,
            bottomAdjustments;

        if (topAffected.length) {
          topAdjustments = spaceTool.calculateAdjustments(
            topAffected, 'y', offset, shape.y - 10);

          spaceTool.makeSpace(
            topAdjustments.movingShapes,
            topAdjustments.resizingShapes,
            { x: 0, y: offset }, 's');
        }

        if (bottomAffected.length) {
          bottomAdjustments = spaceTool.calculateAdjustments(
            bottomAffected, 'y', -offset, shape.y + shape.height + 10);

          spaceTool.makeSpace(
            bottomAdjustments.movingShapes,
            bottomAdjustments.resizingShapes,
            { x: 0, y: -offset }, 'n');
        }
      }

      /**
       * Adjust sizes of other lanes after lane deletion
       */
      this.postExecuted('shape.delete', LOW_PRIORITY, function(event) {

        var context = event.context,
            hints = context.hints,
            shape = context.shape,
            oldParent = context.oldParent;

        // only compensate lane deletes
        if (!is(shape, 'bpmn:Lane')) {
          return;
        }

        // compensate root deletes only
        if (hints && hints.nested) {
          return;
        }

        compensateLaneDelete(shape, oldParent);
      });
    }

    DeleteLaneBehavior.$inject = [
      'eventBus',
      'modeling',
      'spaceTool'
    ];

    inherits(DeleteLaneBehavior, CommandInterceptor);