Skip to content

Commit

Permalink
0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 27, 2015
1 parent 62595f9 commit c7b4424
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dnd",
"version": "0.9.0",
"version": "0.9.1",
"homepage": "https://github.com/gaearon/react-dnd",
"authors": [
"Dan Abramov <dan.abramov@me.com>"
Expand Down
27 changes: 18 additions & 9 deletions dist-modules/backends/HTML5.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
NativeDragItemTypes = require("../constants/NativeDragItemTypes"),
EnterLeaveMonitor = require("../utils/EnterLeaveMonitor"),
isFileDragDropEvent = require("../utils/isFileDragDropEvent"),
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
configureDataTransfer = require("../utils/configureDataTransfer"),
shallowEqual = require("react/lib/shallowEqual"),
isWebkit = require("../utils/isWebkit");
Expand Down Expand Up @@ -41,8 +42,12 @@ function triggerDragEndIfDragSourceWasRemovedFromDOM() {
_currentComponent.handleDragEnd(type, null);
}

function preventDefaultFileDropAction(e) {
if (isFileDragDropEvent(e)) {
function isNativeDragDropEvent(e) {
return isFileDragDropEvent(e) || isUrlDragDropEvent(e);
}

function preventDefaultNativeDropAction(e) {
if (isNativeDragDropEvent(e)) {
e.preventDefault();
}
}
Expand All @@ -52,13 +57,17 @@ function handleTopDragEnter(e) {
e.preventDefault();

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

function handleTopDragOver(e) {
preventDefaultFileDropAction(e);
preventDefaultNativeDropAction(e);

var offsetFromClient = HTML5.getOffsetFromClient(_currentComponent, e);
DragDropActionCreators.drag(offsetFromClient);
Expand All @@ -76,20 +85,20 @@ function handleTopDragOver(e) {
}

function handleTopDragLeave(e) {
preventDefaultFileDropAction(e);
preventDefaultNativeDropAction(e);

var isLastLeave = _monitor.leave(e.target);
if (isLastLeave && isFileDragDropEvent(e)) {
if (isLastLeave && isNativeDragDropEvent(e)) {
DragDropActionCreators.endDragging();
}
}

function handleTopDrop(e) {
preventDefaultFileDropAction(e);
preventDefaultNativeDropAction(e);

_monitor.reset();

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

Expand Down
3 changes: 2 additions & 1 deletion dist-modules/constants/NativeDragItemTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var keyMirror = require("react/lib/keyMirror");

var NativeDragItemTypes = {
FILE: "__NATIVE_FILE__"
FILE: "__NATIVE_FILE__",
URL: "__NATIVE_URL__"
};

module.exports = NativeDragItemTypes;
8 changes: 8 additions & 0 deletions dist-modules/utils/DragDropContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var DragDropContext = {
x: currentOffset.x - initialOffset.x,
y: currentOffset.y - initialOffset.y
};
},

getInitialOffsetFromClient: function getInitialOffsetFromClient() {
return DragOffsetStore.getInitialOffsetFromClient();
},

getCurrentOffsetFromClient: function getCurrentOffsetFromClient() {
return DragOffsetStore.getCurrentOffsetFromClient();
}
};

Expand Down
20 changes: 11 additions & 9 deletions dist-modules/utils/createDragDropMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
DefaultDragSource = require("./DefaultDragSource"),
DefaultDropTarget = require("./DefaultDropTarget"),
isFileDragDropEvent = require("./isFileDragDropEvent"),
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
extractNativeItem = require("../utils/extractNativeItem"),
invariant = require("react/lib/invariant"),
assign = require("react/lib/Object.assign"),
defaults = require("lodash/object/defaults"),
Expand All @@ -16,7 +18,8 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
noop = require("lodash/utility/noop");

function checkValidType(component, type) {
invariant(type && typeof type === "string", "Expected item type to be a non-empty string. See %s", component.constructor.displayName);
/*jshint -W122 */
invariant(type && (typeof type === "string" || typeof type === "symbol"), "Expected item type to be a non-empty string or a symbol. See %s", component.constructor.displayName);
}

function checkDragSourceDefined(component, type) {
Expand Down Expand Up @@ -270,8 +273,8 @@ function createDragDropMixin(backend) {
var getDropEffect = _dropTargets$state$draggedItemType.getDropEffect;
var effectsAllowed = DragOperationStore.getEffectsAllowed();

if (isFileDragDropEvent(e)) {
// Use Copy drop effect for dragging files.
if (isFileDragDropEvent(e) || isUrlDragDropEvent(e)) {
// Use Copy drop effect for dragging files or urls.
// Because browser gives no drag preview, "+" icon is useful.
effectsAllowed = [DropEffects.COPY];
}
Expand Down Expand Up @@ -333,12 +336,11 @@ function createDragDropMixin(backend) {
var currentDropEffect = this.state.currentDropEffect;
var isHandled = !!DragOperationStore.getDropEffect();

if (isFileDragDropEvent(e)) {
// We don't know file list until the `drop` event,
// so we couldn't put `item` into the store.
item = {
files: Array.prototype.slice.call(e.dataTransfer.files)
};
// We don't know the exact list until the `drop` event,
// so we couldn't put `item` into the store.

if (!item) {
item = extractNativeItem(e);
}

this._monitor.reset();
Expand Down
18 changes: 18 additions & 0 deletions dist-modules/utils/extractNativeItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

var isFileDragDropEvent = require("./isFileDragDropEvent"),
isUrlDragDropEvent = require("./isUrlDragDropEvent");

function extractNativeItem(e) {
if (isFileDragDropEvent(e)) {
return {
files: Array.prototype.slice.call(e.dataTransfer.files)
};
} else if (isUrlDragDropEvent(e)) {
return {
urls: (e.dataTransfer.getData("Url") || e.dataTransfer.getData("text/uri-list") || "").split("\n")
};
}
}

module.exports = extractNativeItem;
8 changes: 8 additions & 0 deletions dist-modules/utils/isUrlDragDropEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

function isUrlDragDropEvent(e) {
var types = Array.prototype.slice.call(e.dataTransfer.types);
return types.indexOf("Url") !== -1 || types.indexOf("text/uri-list") !== -1;
}

module.exports = isUrlDragDropEvent;
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dnd",
"version": "0.9.0",
"version": "0.9.1",
"description": "Drag and drop for React with full DOM control",
"main": "dist-modules/index.js",
"scripts": {
Expand Down

0 comments on commit c7b4424

Please sign in to comment.