<commit_before>var Diagram = require('../../Diagram'),
          _ = require('../../util/underscore');

/**
 * @namespace djs
 */

/**
 * @class
 *
 * A service that allow to drop an element
 */
function PaletteDragDrop(canvas, events, shapes, injector) {
  'use strict';

  var i = 0;
  var dragInProgress = false;

  events.on('standard.palette.init', function(event) {
    init();
  });

  function init() {
    // mouseenter does not work as chrome doesn't fire
    // the event if left button is pressed
    canvas.addListener('mousemove', paletteMoveListener);
    canvas.addListener('mouseup', canvasOnMouseUp);
    //TODO register canvasOnMouseUpAnywhere
  }

  /**
   * Handles what happen in the canvas.
   */
  var paletteMoveListener = function paletteMoveListener() {
    if(dragInProgress) {
      console.log('Move on canvas: ' + i++);
      // TODO dragging draw shape
    }
  };

  /**
   * What happens on mouseup event over canvas
   */
  var canvasOnMouseUp = function canvasOnMouseUp(mouseEvent) {
    if(dragInProgress && mouseEvent.button === 0) {
      var newShape = shapes.convertToShape({
        x: mouseEvent.clientX - 100 / 2.5,
        y: mouseEvent.clientY - 80,
        width: 100,
        height: 80
      });
      canvas.addShape(newShape);
    }
    dragInProgress = false;
  };

  var canvasOnMouseUpAnywhere = function canvasOnMouseUpAnywhere() {
    //TODO Stop interaction
  };

  /**
   * Must be called if a draggable button on palette is clicked
   * It is in the response of the palette to invoke this method.
   *
   * @return {boolean} true if dragStart was successful
   */
  var startDragAndDrop = function startDragAndDrop() {
    if(dragInProgress) {
      console.warn('Drag is still in progress');
      return false;
    }
    dragInProgress = true;
    return true;
  };

  return {
    startDragAndDrop: startDragAndDrop
  };
}

Diagram.plugin('paletteDragDrop', ['canvas', 'events', 'shapes', 'injector', PaletteDragDrop ]);

module.exports = PaletteDragDrop;<commit_msg>feat(palettedragdrop) stop add shape stop adding shape if mouse up occurs.<commit_after>var Diagram = require('../../Diagram'),
          _ = require('../../util/underscore');

/**
 * @namespace djs
 */

/**
 * @class
 *
 * A service that allow to drop an element
 */
function PaletteDragDrop(canvas, events, shapes, injector) {
  'use strict';

  var dragInProgress = false;

  events.on('standard.palette.init', function(event) {
    init();
  });

  function init() {
    // mouseenter does not work as chrome doesn't fire
    // the event if left button is pressed
    canvas.addListener('mousemove', paletteMoveListener);
    canvas.addListener('mouseup', canvasOnMouseUp);
    document.addEventListener('mouseup', canvasOnMouseUpAnywhere);
  }

  /**
   * Handles what happen in the canvas
   */
  var paletteMoveListener = function paletteMoveListener() {
    if(dragInProgress) {
      // TODO dragging draw shape
    }
  };

  /**
   * What happens on mouseup event over canvas
   */
  var canvasOnMouseUp = function canvasOnMouseUp(mouseEvent) {
    if(dragInProgress && mouseEvent.button === 0) {
      var newShape = shapes.convertToShape({
        x: mouseEvent.clientX - 100 / 2.5,
        y: mouseEvent.clientY - 80,
        width: 100,
        height: 80
      });
      canvas.addShape(newShape);
    }
    dragInProgress = false;
  };

  var canvasOnMouseUpAnywhere = function canvasOnMouseUpAnywhere() {
    dragInProgress = false;
  };

  /**
   * Must be called if a draggable button on palette is clicked
   * It is in the response of the palette to invoke this method.
   *
   * @return {boolean} true if dragStart was successful
   */
  var startDragAndDrop = function startDragAndDrop() {
    if(dragInProgress) {
      console.warn('Drag is still in progress');
      return false;
    }
    dragInProgress = true;
    return true;
  };

  return {
    startDragAndDrop: startDragAndDrop
  };
}

Diagram.plugin('paletteDragDrop', ['canvas', 'events', 'shapes', 'injector', PaletteDragDrop ]);

module.exports = PaletteDragDrop;
{'fraction_non_alphanumeric': 0.11884342073021319, 'fraction_numerical': 0.006616025483950012, 'mean_word_length': 2.932562620423892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613586', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1201, 'n_words': 338}