Skip to content

Commit 59961de

Browse files
committed
added old data transfer interface
1 parent ead0053 commit 59961de

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

lib/js/tests/Webapi/Dom/Webapi__Dom__DataTransfer__test.js

+15
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,23 @@ var items = dataTransfer.items;
1111

1212
dataTransfer.setDragImage(document.createElement("div"), 10, 10);
1313

14+
var types = dataTransfer.types;
15+
16+
var data = dataTransfer.getData("text/plain");
17+
18+
dataTransfer.setData("text/plain", "text");
19+
20+
dataTransfer.clearData("text/plain");
21+
22+
dataTransfer.clearData();
23+
24+
var files = dataTransfer.files;
25+
1426
exports.dataTransfer = dataTransfer;
1527
exports.dropEffect = dropEffect;
1628
exports.effectAllowed = effectAllowed;
1729
exports.items = items;
30+
exports.types = types;
31+
exports.data = data;
32+
exports.files = files;
1833
/* dataTransfer Not a pure module */

src/Webapi.res

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Blob = Webapi__Blob
33
module Canvas = Webapi__Canvas
44
module Dom = Webapi__Dom
55
module File = Webapi__File
6+
module FileList = Webapi__FileList
67
module Fetch = Webapi__Fetch
78
module FormData = Webapi__FormData
89

src/Webapi/Dom/Webapi__Dom__DataTransfer.res

+8
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ type t = Dom.dataTransfer
66
@get external effectAllowed: t => string = "effectAllowed"
77
@get external items: t => Webapi__Dom__DataTransferItemList.t = "items"
88
@send external setDragImage: (t, Dom.element_like<'a>, int, int) => unit = "setDragImage"
9+
10+
// old interface
11+
@get external types: t => array<string> = "types"
12+
@send external getData: (t, string) => string = "getData"
13+
@send external setData: (t, string, string) => unit = "setData"
14+
@send external clearData: (t, string) => unit = "clearData"
15+
@send external clearAllData: t => unit = "clearData"
16+
@get external files: t => Webapi__FileList.t = "files"

src/Webapi/Webapi__FileList.res

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type t = {
2+
length: int
3+
}
4+
5+
@val external toArray: t => array<Webapi__File.t> = "Array.prototype.slice.call"
6+
7+
@get external length: t => int = "length"
8+
9+
@send @return(nullable) external item: (t, int) => option<Webapi__File.t> = "item"

tests/Webapi/Dom/Webapi__Dom__DataTransfer__test.res

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ open DataTransfer
33

44
let dataTransfer = make()
55

6-
let dropEffect = dataTransfer->dropEffect
7-
let effectAllowed = dataTransfer->effectAllowed
8-
let items = dataTransfer->items
6+
let dropEffect: string = dataTransfer->dropEffect
7+
let effectAllowed: string = dataTransfer->effectAllowed
8+
let items: Webapi__Dom__DataTransferItemList.t = dataTransfer->items
99
dataTransfer->setDragImage(document->Document.createElement("div"), 10, 10)
10+
11+
let types: array<string> = dataTransfer->types
12+
let data: string = dataTransfer->getData("text/plain")
13+
dataTransfer->setData("text/plain", "text")
14+
dataTransfer->clearData("text/plain")
15+
dataTransfer->clearAllData
16+
let files: Webapi__FileList.t = dataTransfer->files

0 commit comments

Comments
 (0)