Skip to content

Commit

Permalink
0.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 10, 2015
1 parent 2451bb9 commit b09265b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 34 deletions.
57 changes: 36 additions & 21 deletions dist-modules/backends/HTML5.js
Expand Up @@ -6,6 +6,7 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
EnterLeaveMonitor = require("../utils/EnterLeaveMonitor"),
isFileDragDropEvent = require("../utils/isFileDragDropEvent"),
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
isNativeDraggedItemType = require("../utils/isNativeDraggedItemType"),
configureDataTransfer = require("../utils/configureDataTransfer"),
shallowEqual = require("react/lib/shallowEqual"),
isWebkit = require("../utils/isWebkit");
Expand Down Expand Up @@ -59,19 +60,21 @@ function triggerDragEndIfDragSourceWasRemovedFromDOM() {
_currentComponent.handleDragEnd(type, null);
}

function isNativeDragDropEvent(e) {
return isFileDragDropEvent(e) || isUrlDragDropEvent(e);
function isDraggingNativeItem() {
var itemType = DragOperationStore.getDraggedItemType();
return isNativeDraggedItemType(itemType);
}

function preventDefaultNativeDropAction(e) {
if (isNativeDragDropEvent(e)) {
e.preventDefault();
function handleTopDragStart(e) {
if (DragOperationStore.isDragging()) {
return;
}
}

function handleTopDragStart(e) {
// If by this time no drag source reacted, tell browser not to drag.
if (!isNativeDragDropEvent(e) && !DragOperationStore.isDragging()) {
if (isUrlDragDropEvent(e)) {
// URL dragged from inside the document
DragDropActionCreators.startDragging(NativeDragItemTypes.URL, null);
} else {
// If by this time no drag source reacted, tell browser not to drag.
e.preventDefault();
}
}
Expand All @@ -81,17 +84,23 @@ function handleTopDragEnter(e) {
e.preventDefault();

var isFirstEnter = _monitor.enter(e.target);
if (isFirstEnter) {
if (isFileDragDropEvent(e)) {
DragDropActionCreators.startDragging(NativeDragItemTypes.FILE, null);
} else if (isUrlDragDropEvent(e)) {
DragDropActionCreators.startDragging(NativeDragItemTypes.URL, null);
}
if (!isFirstEnter || DragOperationStore.isDragging()) {
return;
}

if (isFileDragDropEvent(e)) {
// File dragged from outside the document
DragDropActionCreators.startDragging(NativeDragItemTypes.FILE, null);
} else if (isUrlDragDropEvent(e)) {
// URL dragged from outside the document
DragDropActionCreators.startDragging(NativeDragItemTypes.URL, null);
}
}

function handleTopDragOver(e) {
preventDefaultNativeDropAction(e);
if (isDraggingNativeItem()) {
e.preventDefault();
}

var offsetFromClient = getClientOffset(e);
DragDropActionCreators.drag(offsetFromClient);
Expand All @@ -109,20 +118,26 @@ function handleTopDragOver(e) {
}

function handleTopDragLeave(e) {
preventDefaultNativeDropAction(e);
if (isDraggingNativeItem(e)) {
e.preventDefault();
}

var isLastLeave = _monitor.leave(e.target);
if (isLastLeave && isNativeDragDropEvent(e)) {
DragDropActionCreators.endDragging();
if (!isLastLeave || !isDraggingNativeItem()) {
return;
}

DragDropActionCreators.endDragging();
}

function handleTopDrop(e) {
preventDefaultNativeDropAction(e);
if (isDraggingNativeItem()) {
e.preventDefault();
}

_monitor.reset();

if (isNativeDragDropEvent(e)) {
if (isDraggingNativeItem()) {
DragDropActionCreators.endDragging();
}

Expand Down
6 changes: 3 additions & 3 deletions dist-modules/utils/createDragDropMixin.js
Expand Up @@ -7,9 +7,8 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
DropEffects = require("../constants/DropEffects"),
DefaultDragSource = require("./DefaultDragSource"),
DefaultDropTarget = require("./DefaultDropTarget"),
isFileDragDropEvent = require("./isFileDragDropEvent"),
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
extractNativeItem = require("../utils/extractNativeItem"),
isNativeDraggedItemType = require("../utils/isNativeDraggedItemType"),
invariant = require("react/lib/invariant"),
assign = require("react/lib/Object.assign"),
defaults = require("lodash/object/defaults"),
Expand Down Expand Up @@ -272,8 +271,9 @@ function createDragDropMixin(backend) {
var enter = _dropTargets$state$draggedItemType.enter;
var getDropEffect = _dropTargets$state$draggedItemType.getDropEffect;
var effectsAllowed = DragOperationStore.getEffectsAllowed();
var itemType = DragOperationStore.getDraggedItemType();

if (isFileDragDropEvent(e) || isUrlDragDropEvent(e)) {
if (isNativeDraggedItemType(itemType)) {
// Use Copy drop effect for dragging files or urls.
// Because browser gives no drag preview, "+" icon is useful.
effectsAllowed = [DropEffects.COPY];
Expand Down
15 changes: 15 additions & 0 deletions dist-modules/utils/isNativeDraggedItemType.js
@@ -0,0 +1,15 @@
"use strict";

var NativeDragItemTypes = require("../constants/NativeDragItemTypes");

function isNativeDraggedItemType(itemType) {
switch (itemType) {
case NativeDragItemTypes.FILE:
case NativeDragItemTypes.URL:
return true;
default:
return false;
}
}

module.exports = isNativeDraggedItemType;
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.3",
"version": "0.9.4",
"description": "Drag and drop for React with full DOM control",
"main": "dist-modules/index.js",
"scripts": {
Expand Down

0 comments on commit b09265b

Please sign in to comment.