function MovePreview(eventBus, elementRegistry, canvas, styles, previewSupport) {

  function getVisualDragShapes(shapes) {
    var elements = getAllDraggedElements(shapes);

    var filteredElements = removeEdges(elements);

    return filteredElements;
  }

  function getAllDraggedElements(shapes) {
    var allShapes = Elements.selfAndAllChildren(shapes, true);

    var allConnections = map(allShapes, function(shape) {
      return (shape.incoming || []).concat(shape.outgoing || []);
    });

    return flatten(allShapes.concat(allConnections), true);
  }

  /**
   * Sets drop marker on an element.
   */
  function setMarker(element, marker) {

    [ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK, MARKER_NEW_PARENT ].forEach(function(m) {

      if (m === marker) {
        canvas.addMarker(element, m);
      } else {
        canvas.removeMarker(element, m);
      }
    });
  }

  function makeDraggable(context, element, addMarker) {

    previewSupport.addDragger(element, context.dragGroup);

    if (addMarker) {
      canvas.addMarker(element, MARKER_DRAGGING);
    }

    if (context.allDraggedElements) {
      context.allDraggedElements.push(element);
    } else {
      context.allDraggedElements = [ element ];
    }
  }

  // expose to other components
  // that plug into the drag behavior
  this.makeDraggable = makeDraggable;

  // add previews
  eventBus.on('shape.move.start', LOW_PRIORITY, function(event) {

    var context = event.context,
        dragShapes = context.shapes,
        allDraggedElements = context.allDraggedElements;

    var visuallyDraggedShapes = getVisualDragShapes(dragShapes);

    if (!context.dragGroup) {
      var dragGroup = svgCreate('g');
      svgAttr(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));

      var defaultLayer = canvas.getDefaultLayer();

      svgAppend(defaultLayer, dragGroup);

      context.dragGroup = dragGroup;
    }

    // add previews
    visuallyDraggedShapes.forEach(function(shape) {
      previewSupport.addDragger(shape, context.dragGroup);
    });

    // cache all dragged elements / gfx
    // so that we can quickly undo their state changes later
    if (!allDraggedElements) {
      allDraggedElements = getAllDraggedElements(dragShapes);
    } else {
      allDraggedElements = flatten(allDraggedElements, getAllDraggedElements(dragShapes));
    }

    // add dragging marker
    forEach(allDraggedElements, function(e) {
      canvas.addMarker(e, MARKER_DRAGGING);
    });

    context.allDraggedElements = allDraggedElements;

    // determine, if any of the dragged elements have different parents
    context.differentParents = haveDifferentParents(dragShapes);
  });

  // update previews
  eventBus.on('shape.move.move', LOW_PRIORITY, function(event) {

    var context = event.context,
        dragGroup = context.dragGroup,
        target = context.target,
        parent = context.shape.parent,
        canExecute = context.canExecute;

    if (target) {
      if (canExecute === 'attach') {
        setMarker(target, MARKER_ATTACH);
      } else if (context.canExecute && target && target.id !== parent.id) {
        setMarker(target, MARKER_NEW_PARENT);
      } else {
        setMarker(target, context.canExecute ? MARKER_OK : MARKER_NOT_OK);
      }
    }

    translate(dragGroup, event.dx, event.dy);
  });

  eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
    var context = event.context,
        target = context.target;

    if (target) {
      setMarker(target, null);
    }
  });

  // remove previews
  eventBus.on('shape.move.cleanup', function(event) {

    var context = event.context,
        allDraggedElements = context.allDraggedElements,
        dragGroup = context.dragGroup;


    // remove dragging marker
    forEach(allDraggedElements, function(e) {
      canvas.removeMarker(e, MARKER_DRAGGING);
    });

    if (dragGroup) {
      svgClear(dragGroup);
    }
  });
}
/**
 * Provides previews for moving shapes when moving.
 *
 * @param {EventBus} eventBus
 * @param {ElementRegistry} elementRegistry
 * @param {Canvas} canvas
 * @param {Styles} styles
 */
Provides previews for moving shapes when moving.
Provides previews for moving shapes when moving .
function MovePreview(eventBus, elementRegistry, canvas, styles, previewSupport) {
  function getVisualDragShapes(shapes) {
    var elements = getAllDraggedElements(shapes);
    var filteredElements = removeEdges(elements);
    return filteredElements;
  }
  function getAllDraggedElements(shapes) {
    var allShapes = Elements.selfAndAllChildren(shapes, true);
    var allConnections = map(allShapes, function(shape) {
      return (shape.incoming || []).concat(shape.outgoing || []);
    });
    return flatten(allShapes.concat(allConnections), true);
  }
  function setMarker(element, marker) {
    [ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK, MARKER_NEW_PARENT ].forEach(function(m) {
      if (m === marker) {
        canvas.addMarker(element, m);
      } else {
        canvas.removeMarker(element, m);
      }
    });
  }
  function makeDraggable(context, element, addMarker) {
    previewSupport.addDragger(element, context.dragGroup);
    if (addMarker) {
      canvas.addMarker(element, MARKER_DRAGGING);
    }
    if (context.allDraggedElements) {
      context.allDraggedElements.push(element);
    } else {
      context.allDraggedElements = [ element ];
    }
  }
  this.makeDraggable = makeDraggable;
  eventBus.on('shape.move.start', LOW_PRIORITY, function(event) {
    var context = event.context,
        dragShapes = context.shapes,
        allDraggedElements = context.allDraggedElements;
    var visuallyDraggedShapes = getVisualDragShapes(dragShapes);
    if (!context.dragGroup) {
      var dragGroup = svgCreate('g');
      svgAttr(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
      var defaultLayer = canvas.getDefaultLayer();
      svgAppend(defaultLayer, dragGroup);
      context.dragGroup = dragGroup;
    }
    visuallyDraggedShapes.forEach(function(shape) {
      previewSupport.addDragger(shape, context.dragGroup);
    });
    if (!allDraggedElements) {
      allDraggedElements = getAllDraggedElements(dragShapes);
    } else {
      allDraggedElements = flatten(allDraggedElements, getAllDraggedElements(dragShapes));
    }
    forEach(allDraggedElements, function(e) {
      canvas.addMarker(e, MARKER_DRAGGING);
    });
    context.allDraggedElements = allDraggedElements;
    context.differentParents = haveDifferentParents(dragShapes);
  });
  eventBus.on('shape.move.move', LOW_PRIORITY, function(event) {
    var context = event.context,
        dragGroup = context.dragGroup,
        target = context.target,
        parent = context.shape.parent,
        canExecute = context.canExecute;
    if (target) {
      if (canExecute === 'attach') {
        setMarker(target, MARKER_ATTACH);
      } else if (context.canExecute && target && target.id !== parent.id) {
        setMarker(target, MARKER_NEW_PARENT);
      } else {
        setMarker(target, context.canExecute ? MARKER_OK : MARKER_NOT_OK);
      }
    }
    translate(dragGroup, event.dx, event.dy);
  });
  eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
    var context = event.context,
        target = context.target;
    if (target) {
      setMarker(target, null);
    }
  });
  eventBus.on('shape.move.cleanup', function(event) {
    var context = event.context,
        allDraggedElements = context.allDraggedElements,
        dragGroup = context.dragGroup;
    forEach(allDraggedElements, function(e) {
      canvas.removeMarker(e, MARKER_DRAGGING);
    });
    if (dragGroup) {
      svgClear(dragGroup);
    }
  });
}
function MovePreview ( eventBus , elementRegistry , canvas , styles , previewSupport ) { function getVisualDragShapes ( shapes ) { var elements = getAllDraggedElements ( shapes ) ; var filteredElements = removeEdges ( elements ) ; return filteredElements ; } function getAllDraggedElements ( shapes ) { var allShapes = Elements . selfAndAllChildren ( shapes , true ) ; var allConnections = map ( allShapes , function ( shape ) { return ( shape . incoming || [ ] ) . concat ( shape . outgoing || [ ] ) ; } ) ; return flatten ( allShapes . concat ( allConnections ) , true ) ; } function setMarker ( element , marker ) { [ MARKER_ATTACH , MARKER_OK , MARKER_NOT_OK , MARKER_NEW_PARENT ] . forEach ( function ( m ) { if ( m === marker ) { canvas . addMarker ( element , m ) ; } else { canvas . removeMarker ( element , m ) ; } } ) ; } function makeDraggable ( context , element , addMarker ) { previewSupport . addDragger ( element , context . dragGroup ) ; if ( addMarker ) { canvas . addMarker ( element , MARKER_DRAGGING ) ; } if ( context . allDraggedElements ) { context . allDraggedElements . push ( element ) ; } else { context . allDraggedElements = [ element ] ; } } this . makeDraggable = makeDraggable ; eventBus . on ( 'shape.move.start' , LOW_PRIORITY , function ( event ) { var context = event . context , dragShapes = context . shapes , allDraggedElements = context . allDraggedElements ; var visuallyDraggedShapes = getVisualDragShapes ( dragShapes ) ; if ( ! context . dragGroup ) { var dragGroup = svgCreate ( 'g' ) ; svgAttr ( dragGroup , styles . cls ( 'djs-drag-group' , [ 'no-events' ] ) ) ; var defaultLayer = canvas . getDefaultLayer ( ) ; svgAppend ( defaultLayer , dragGroup ) ; context . dragGroup = dragGroup ; } visuallyDraggedShapes . forEach ( function ( shape ) { previewSupport . addDragger ( shape , context . dragGroup ) ; } ) ; if ( ! allDraggedElements ) { allDraggedElements = getAllDraggedElements ( dragShapes ) ; } else { allDraggedElements = flatten ( allDraggedElements , getAllDraggedElements ( dragShapes ) ) ; } forEach ( allDraggedElements , function ( e ) { canvas . addMarker ( e , MARKER_DRAGGING ) ; } ) ; context . allDraggedElements = allDraggedElements ; context . differentParents = haveDifferentParents ( dragShapes ) ; } ) ; eventBus . on ( 'shape.move.move' , LOW_PRIORITY , function ( event ) { var context = event . context , dragGroup = context . dragGroup , target = context . target , parent = context . shape . parent , canExecute = context . canExecute ; if ( target ) { if ( canExecute === 'attach' ) { setMarker ( target , MARKER_ATTACH ) ; } else if ( context . canExecute && target && target . id !== parent . id ) { setMarker ( target , MARKER_NEW_PARENT ) ; } else { setMarker ( target , context . canExecute ? MARKER_OK : MARKER_NOT_OK ) ; } } translate ( dragGroup , event . dx , event . dy ) ; } ) ; eventBus . on ( [ 'shape.move.out' , 'shape.move.cleanup' ] , function ( event ) { var context = event . context , target = context . target ; if ( target ) { setMarker ( target , null ) ; } } ) ; eventBus . on ( 'shape.move.cleanup' , function ( event ) { var context = event . context , allDraggedElements = context . allDraggedElements , dragGroup = context . dragGroup ; forEach ( allDraggedElements , function ( e ) { canvas . removeMarker ( e , MARKER_DRAGGING ) ; } ) ; if ( dragGroup ) { svgClear ( dragGroup ) ; } } ) ; }
Provides previews for moving shapes when moving.
Provides previews for moving shapes when moving .
/**
   * Sets drop marker on an element.
   */ // expose to other components // that plug into the drag behavior // add previews // add previews // cache all dragged elements / gfx // so that we can quickly undo their state changes later // add dragging marker // determine, if any of the dragged elements have different parents // update previews // remove previews // remove dragging marker