function insertShape(shape, targetFlow, position) {
    var waypoints = targetFlow.waypoints,
        waypointsBefore, waypointsAfter, dockingPoint, source, target, reconnected;

    var intersection = getApproxIntersection(waypoints, position);

    if (intersection) {
      waypointsBefore = waypoints.slice(0, intersection.index);
      waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));

      dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position;

      // if last waypointBefore is inside shape's bounds, ignore docking point
      if (!isPointInsideBBox(shape, waypointsBefore[waypointsBefore.length-1])) {
        waypointsBefore.push(copy(dockingPoint));
      }

      // if first waypointAfter is inside shape's bounds, ignore docking point
      if (!isPointInsideBBox(shape, waypointsAfter[0])) {
        waypointsAfter.unshift(copy(dockingPoint));
      }
    }

    source = targetFlow.source;
    target = targetFlow.target;

    if (bpmnRules.canConnect(source, shape, targetFlow)) {
      // reconnect source -> inserted shape
      modeling.reconnectEnd(targetFlow, shape, waypointsBefore || position);

      reconnected = true;
    }

    if (bpmnRules.canConnect(shape, target, targetFlow)) {

      if (!reconnected) {
        // reconnect inserted shape -> end
        modeling.reconnectStart(targetFlow, shape, waypointsAfter || position);
      } else {
        modeling.connect(shape, target, { type: targetFlow.type, waypoints: waypointsAfter });
      }
    }
  }
/**
   * Reconnect start / end of a connection after
   * dropping an element on a flow.
   */
Reconnect start / end of a connection after
dropping an element on a flow.
Reconnect start / end of a connection after dropping an element on a flow .
function insertShape(shape, targetFlow, position) {
    var waypoints = targetFlow.waypoints,
        waypointsBefore, waypointsAfter, dockingPoint, source, target, reconnected;
    var intersection = getApproxIntersection(waypoints, position);
    if (intersection) {
      waypointsBefore = waypoints.slice(0, intersection.index);
      waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));
      dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position;
      if (!isPointInsideBBox(shape, waypointsBefore[waypointsBefore.length-1])) {
        waypointsBefore.push(copy(dockingPoint));
      }
      if (!isPointInsideBBox(shape, waypointsAfter[0])) {
        waypointsAfter.unshift(copy(dockingPoint));
      }
    }
    source = targetFlow.source;
    target = targetFlow.target;
    if (bpmnRules.canConnect(source, shape, targetFlow)) {
      modeling.reconnectEnd(targetFlow, shape, waypointsBefore || position);
      reconnected = true;
    }
    if (bpmnRules.canConnect(shape, target, targetFlow)) {
      if (!reconnected) {
        modeling.reconnectStart(targetFlow, shape, waypointsAfter || position);
      } else {
        modeling.connect(shape, target, { type: targetFlow.type, waypoints: waypointsAfter });
      }
    }
  }
function insertShape ( shape , targetFlow , position ) { var waypoints = targetFlow . waypoints , waypointsBefore , waypointsAfter , dockingPoint , source , target , reconnected ; var intersection = getApproxIntersection ( waypoints , position ) ; if ( intersection ) { waypointsBefore = waypoints . slice ( 0 , intersection . index ) ; waypointsAfter = waypoints . slice ( intersection . index + ( intersection . bendpoint ? 1 : 0 ) ) ; dockingPoint = intersection . bendpoint ? waypoints [ intersection . index ] : position ; if ( ! isPointInsideBBox ( shape , waypointsBefore [ waypointsBefore . length - 1 ] ) ) { waypointsBefore . push ( copy ( dockingPoint ) ) ; } if ( ! isPointInsideBBox ( shape , waypointsAfter [ 0 ] ) ) { waypointsAfter . unshift ( copy ( dockingPoint ) ) ; } } source = targetFlow . source ; target = targetFlow . target ; if ( bpmnRules . canConnect ( source , shape , targetFlow ) ) { modeling . reconnectEnd ( targetFlow , shape , waypointsBefore || position ) ; reconnected = true ; } if ( bpmnRules . canConnect ( shape , target , targetFlow ) ) { if ( ! reconnected ) { modeling . reconnectStart ( targetFlow , shape , waypointsAfter || position ) ; } else { modeling . connect ( shape , target , { type : targetFlow . type , waypoints : waypointsAfter } ) ; } } }
Reconnect start / end of a connection after
 dropping an element on a flow.
Reconnect start / end of a connection after dropping an element on a flow .
// if last waypointBefore is inside shape's bounds, ignore docking point // if first waypointAfter is inside shape's bounds, ignore docking point // reconnect source -> inserted shape // reconnect inserted shape -> end