Skip to content

Commit

Permalink
0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 1, 2015
1 parent 43a9802 commit 2c34aaa
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "react-dnd",
"version": "0.9.1",
"version": "0.9.2",
"homepage": "https://github.com/gaearon/react-dnd",
"authors": [
"Dan Abramov <dan.abramov@me.com>"
Expand Down
29 changes: 21 additions & 8 deletions dist-modules/backends/HTML5.js
Expand Up @@ -24,6 +24,13 @@ function getElementRect(el) {
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
}

function getClientOffset(e) {
return {
x: e.clientX,
y: e.clientY
};
}

function checkIfCurrentDragTargetRectChanged() {
if (!_dragTargetRectDidChange) {
var currentRect = getElementRect(_currentDragTarget);
Expand Down Expand Up @@ -52,6 +59,13 @@ function preventDefaultNativeDropAction(e) {
}
}

function handleTopDragStart(e) {
// If by this time no drag source reacted, tell browser not to drag.
if (!DragOperationStore.isDragging()) {
e.preventDefault();
}
}

function handleTopDragEnter(e) {
// IE requires this to not show a nodrag icon over the container
e.preventDefault();
Expand All @@ -69,7 +83,7 @@ function handleTopDragEnter(e) {
function handleTopDragOver(e) {
preventDefaultNativeDropAction(e);

var offsetFromClient = HTML5.getOffsetFromClient(_currentComponent, e);
var offsetFromClient = getClientOffset(e);
DragDropActionCreators.drag(offsetFromClient);

// At the top level of event bubbling, use previously set drop effect and reset it.
Expand Down Expand Up @@ -106,22 +120,24 @@ function handleTopDrop(e) {
}

var HTML5 = {
setup: function setup(component) {
setup: function setup() {
if (typeof window === "undefined") {
return;
}

window.addEventListener("dragstart", handleTopDragStart);
window.addEventListener("dragenter", handleTopDragEnter);
window.addEventListener("dragover", handleTopDragOver);
window.addEventListener("dragleave", handleTopDragLeave);
window.addEventListener("drop", handleTopDrop);
},

teardown: function teardown(component) {
teardown: function teardown() {
if (typeof window === "undefined") {
return;
}

window.removeEventListener("dragstart", handleTopDragStart);
window.removeEventListener("dragenter", handleTopDragEnter);
window.removeEventListener("dragover", handleTopDragOver);
window.removeEventListener("dragleave", handleTopDragLeave);
Expand All @@ -145,7 +161,7 @@ var HTML5 = {
window.addEventListener("mousemove", triggerDragEndIfDragSourceWasRemovedFromDOM, true);
},

endDrag: function endDrag(component) {
endDrag: function endDrag() {
_currentDragTarget = null;
_currentComponent = null;
_initialDragTargetRect = null;
Expand Down Expand Up @@ -179,10 +195,7 @@ var HTML5 = {
},

getOffsetFromClient: function getOffsetFromClient(component, e) {
return {
x: e.clientX,
y: e.clientY
};
return getClientOffset(e);
}
};

Expand Down
2 changes: 0 additions & 2 deletions dist-modules/constants/NativeDragItemTypes.js
@@ -1,7 +1,5 @@
"use strict";

var keyMirror = require("react/lib/keyMirror");

var NativeDragItemTypes = {
FILE: "__NATIVE_FILE__",
URL: "__NATIVE_URL__"
Expand Down
18 changes: 8 additions & 10 deletions dist-modules/utils/createDragDropMixin.js
Expand Up @@ -14,8 +14,7 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
assign = require("react/lib/Object.assign"),
defaults = require("lodash/object/defaults"),
isArray = require("lodash/lang/isArray"),
isObject = require("lodash/lang/isObject"),
noop = require("lodash/utility/noop");
isObject = require("lodash/lang/isObject");

function checkValidType(component, type) {
/*jshint -W122 */
Expand Down Expand Up @@ -174,10 +173,7 @@ function createDragDropMixin(backend) {
var _dragSources$type = this._dragSources[type];
var canDrag = _dragSources$type.canDrag;
var beginDrag = _dragSources$type.beginDrag;


if (!canDrag(this)) {
e.preventDefault();
if (DragOperationStore.isDragging() || !canDrag(this)) {
return;
}

Expand All @@ -197,6 +193,10 @@ function createDragDropMixin(backend) {
y: offsetFromClient.y - containerRect.top
};

if (!dragPreview) {
dragPreview = containerNode;
}

if (!effectsAllowed) {
// Move is a sensible default drag effect.
// Browser shows a drag preview anyway so we usually don't want "+" icon.
Expand All @@ -222,7 +222,7 @@ function createDragDropMixin(backend) {
});
},

handleDragEnd: function handleDragEnd(type, e) {
handleDragEnd: function handleDragEnd(type) {
backend.endDrag(this);

var endDrag = this._dragSources[type].endDrag;
Expand Down Expand Up @@ -298,9 +298,7 @@ function createDragDropMixin(backend) {

e.preventDefault();

var _dropTargets$state$draggedItemType = this._dropTargets[this.state.draggedItemType];
var over = _dropTargets$state$draggedItemType.over;
var getDropEffect = _dropTargets$state$draggedItemType.getDropEffect;
var over = this._dropTargets[this.state.draggedItemType].over;
over(this, this.state.draggedItem);

// Don't use `none` because this will prevent browser from firing `dragend`
Expand Down
2 changes: 1 addition & 1 deletion dist/ReactDND.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-dnd",
"version": "0.9.1",
"version": "0.9.2",
"description": "Drag and drop for React with full DOM control",
"main": "dist-modules/index.js",
"scripts": {
Expand Down

0 comments on commit 2c34aaa

Please sign in to comment.