Skip to content

Commit c7b4424

Browse files
committed
0.9.1
1 parent 62595f9 commit c7b4424

File tree

11 files changed

+76
-30
lines changed

11 files changed

+76
-30
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-dnd",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"homepage": "https://github.com/gaearon/react-dnd",
55
"authors": [
66
"Dan Abramov <dan.abramov@me.com>"

dist-modules/backends/HTML5.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
55
NativeDragItemTypes = require("../constants/NativeDragItemTypes"),
66
EnterLeaveMonitor = require("../utils/EnterLeaveMonitor"),
77
isFileDragDropEvent = require("../utils/isFileDragDropEvent"),
8+
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
89
configureDataTransfer = require("../utils/configureDataTransfer"),
910
shallowEqual = require("react/lib/shallowEqual"),
1011
isWebkit = require("../utils/isWebkit");
@@ -41,8 +42,12 @@ function triggerDragEndIfDragSourceWasRemovedFromDOM() {
4142
_currentComponent.handleDragEnd(type, null);
4243
}
4344

44-
function preventDefaultFileDropAction(e) {
45-
if (isFileDragDropEvent(e)) {
45+
function isNativeDragDropEvent(e) {
46+
return isFileDragDropEvent(e) || isUrlDragDropEvent(e);
47+
}
48+
49+
function preventDefaultNativeDropAction(e) {
50+
if (isNativeDragDropEvent(e)) {
4651
e.preventDefault();
4752
}
4853
}
@@ -52,13 +57,17 @@ function handleTopDragEnter(e) {
5257
e.preventDefault();
5358

5459
var isFirstEnter = _monitor.enter(e.target);
55-
if (isFirstEnter && isFileDragDropEvent(e)) {
56-
DragDropActionCreators.startDragging(NativeDragItemTypes.FILE, null);
60+
if (isFirstEnter) {
61+
if (isFileDragDropEvent(e)) {
62+
DragDropActionCreators.startDragging(NativeDragItemTypes.FILE, null);
63+
} else if (isUrlDragDropEvent(e)) {
64+
DragDropActionCreators.startDragging(NativeDragItemTypes.URL, null);
65+
}
5766
}
5867
}
5968

6069
function handleTopDragOver(e) {
61-
preventDefaultFileDropAction(e);
70+
preventDefaultNativeDropAction(e);
6271

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

7887
function handleTopDragLeave(e) {
79-
preventDefaultFileDropAction(e);
88+
preventDefaultNativeDropAction(e);
8089

8190
var isLastLeave = _monitor.leave(e.target);
82-
if (isLastLeave && isFileDragDropEvent(e)) {
91+
if (isLastLeave && isNativeDragDropEvent(e)) {
8392
DragDropActionCreators.endDragging();
8493
}
8594
}
8695

8796
function handleTopDrop(e) {
88-
preventDefaultFileDropAction(e);
97+
preventDefaultNativeDropAction(e);
8998

9099
_monitor.reset();
91100

92-
if (isFileDragDropEvent(e)) {
101+
if (isNativeDragDropEvent(e)) {
93102
DragDropActionCreators.endDragging();
94103
}
95104

dist-modules/constants/NativeDragItemTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
var keyMirror = require("react/lib/keyMirror");
44

55
var NativeDragItemTypes = {
6-
FILE: "__NATIVE_FILE__"
6+
FILE: "__NATIVE_FILE__",
7+
URL: "__NATIVE_URL__"
78
};
89

910
module.exports = NativeDragItemTypes;

dist-modules/utils/DragDropContext.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ var DragDropContext = {
1111
x: currentOffset.x - initialOffset.x,
1212
y: currentOffset.y - initialOffset.y
1313
};
14+
},
15+
16+
getInitialOffsetFromClient: function getInitialOffsetFromClient() {
17+
return DragOffsetStore.getInitialOffsetFromClient();
18+
},
19+
20+
getCurrentOffsetFromClient: function getCurrentOffsetFromClient() {
21+
return DragOffsetStore.getCurrentOffsetFromClient();
1422
}
1523
};
1624

dist-modules/utils/createDragDropMixin.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
88
DefaultDragSource = require("./DefaultDragSource"),
99
DefaultDropTarget = require("./DefaultDropTarget"),
1010
isFileDragDropEvent = require("./isFileDragDropEvent"),
11+
isUrlDragDropEvent = require("../utils/isUrlDragDropEvent"),
12+
extractNativeItem = require("../utils/extractNativeItem"),
1113
invariant = require("react/lib/invariant"),
1214
assign = require("react/lib/Object.assign"),
1315
defaults = require("lodash/object/defaults"),
@@ -16,7 +18,8 @@ var DragDropActionCreators = require("../actions/DragDropActionCreators"),
1618
noop = require("lodash/utility/noop");
1719

1820
function checkValidType(component, type) {
19-
invariant(type && typeof type === "string", "Expected item type to be a non-empty string. See %s", component.constructor.displayName);
21+
/*jshint -W122 */
22+
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);
2023
}
2124

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

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

336-
if (isFileDragDropEvent(e)) {
337-
// We don't know file list until the `drop` event,
338-
// so we couldn't put `item` into the store.
339-
item = {
340-
files: Array.prototype.slice.call(e.dataTransfer.files)
341-
};
339+
// We don't know the exact list until the `drop` event,
340+
// so we couldn't put `item` into the store.
341+
342+
if (!item) {
343+
item = extractNativeItem(e);
342344
}
343345

344346
this._monitor.reset();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
3+
var isFileDragDropEvent = require("./isFileDragDropEvent"),
4+
isUrlDragDropEvent = require("./isUrlDragDropEvent");
5+
6+
function extractNativeItem(e) {
7+
if (isFileDragDropEvent(e)) {
8+
return {
9+
files: Array.prototype.slice.call(e.dataTransfer.files)
10+
};
11+
} else if (isUrlDragDropEvent(e)) {
12+
return {
13+
urls: (e.dataTransfer.getData("Url") || e.dataTransfer.getData("text/uri-list") || "").split("\n")
14+
};
15+
}
16+
}
17+
18+
module.exports = extractNativeItem;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
function isUrlDragDropEvent(e) {
4+
var types = Array.prototype.slice.call(e.dataTransfer.types);
5+
return types.indexOf("Url") !== -1 || types.indexOf("text/uri-list") !== -1;
6+
}
7+
8+
module.exports = isUrlDragDropEvent;

dist/ReactDND.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bundle.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)