# all files / Github/diagram-js/lib/features/modeling/cmd/ SpaceToolHandler.js

100% Statements 17/17
100% Branches 0/0
83.33% Functions 5/6
100% Lines 17/17

    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

    1128×

    1×

    1×

    24×
    24×
    24×
    24×

    24×
    34×

    34×

    1×

    24×
    24×
    24×

    24×

    1×
    1×
     import { forEach } from 'min-dash';

    import {
      resizeBounds
    } from '../../space-tool/SpaceUtil';

    /**
     * A handler that implements reversible creating and removing of space.
     *
     * It executes in two phases:
     *
     *  (1) resize all affected resizeShapes
     *  (2) move all affected moveElements
     */
    export default function SpaceToolHandler(modeling) {
      this._modeling = modeling;
    }

    SpaceToolHandler.$inject = [ 'modeling' ];

    SpaceToolHandler.prototype.preExecute = function(context) {

      // resize
      var modeling = this._modeling,
          resizingShapes = context.resizingShapes,
          delta = context.delta,
          direction = context.direction;

      forEach(resizingShapes, function(shape) {
        var newBounds = resizeBounds(shape, direction, delta);

        modeling.resizeShape(shape, newBounds);
      });
    };

    SpaceToolHandler.prototype.postExecute = function(context) {
      // move
      var modeling = this._modeling,
          movingShapes = context.movingShapes,
          delta = context.delta;

      modeling.moveElements(movingShapes, delta, undefined, { autoResize: false, attach: false });
    };

    SpaceToolHandler.prototype.execute = function(context) {};
    SpaceToolHandler.prototype.revert = function(context) {};