Skip to content

Commit 4ee8bbc

Browse files
authored
Merge pull request #763 from zetashift/refresh-datatransfer-api
Refresh DataTransfer API
2 parents 8110fad + 95127c2 commit 4ee8bbc

11 files changed

+221
-15
lines changed

api-reports/2_12.txt

+32-3
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,39 @@ DOMTokenList[JC] def remove(token: String): Unit
15261526
DOMTokenList[JC] def toggle(token: String): Boolean
15271527
DOMTokenList[JC] def toggle(token: String, force: Boolean): Boolean
15281528
DataTransfer[JT] def clearData(format: String?): Unit
1529-
DataTransfer[JT] var dropEffect: String
1530-
DataTransfer[JT] var effectAllowed: String
1529+
DataTransfer[JT] var dropEffect: DataTransferDropEffectKind
1530+
DataTransfer[JT] var effectAllowed: DataTransferEffectAllowedKind
15311531
DataTransfer[JT] def files: FileList
15321532
DataTransfer[JT] def getData(format: String): String
1533+
DataTransfer[JT] def items: DataTransferItemList
15331534
DataTransfer[JT] def setData(format: String, data: String): Unit
15341535
DataTransfer[JT] def setDragImage(image: Element, x: Double, y: Double): Unit
1535-
DataTransfer[JT] def types: js.Array[String]
1536+
DataTransfer[JT] def types: FrozenArray[String]
1537+
DataTransferDropEffectKind[JT]
1538+
DataTransferDropEffectKind[SO] val copy: DataTransferDropEffectKind
1539+
DataTransferDropEffectKind[SO] val link: DataTransferDropEffectKind
1540+
DataTransferDropEffectKind[SO] val move: DataTransferDropEffectKind
1541+
DataTransferDropEffectKind[SO] val none: DataTransferDropEffectKind
1542+
DataTransferEffectAllowedKind[JT]
1543+
DataTransferEffectAllowedKind[SO] val all: DataTransferEffectAllowedKind
1544+
DataTransferEffectAllowedKind[SO] val copy: DataTransferEffectAllowedKind
1545+
DataTransferEffectAllowedKind[SO] val copyLink: DataTransferEffectAllowedKind
1546+
DataTransferEffectAllowedKind[SO] val copyMove: DataTransferEffectAllowedKind
1547+
DataTransferEffectAllowedKind[SO] val link: DataTransferEffectAllowedKind
1548+
DataTransferEffectAllowedKind[SO] val linkMove: DataTransferEffectAllowedKind
1549+
DataTransferEffectAllowedKind[SO] val move: DataTransferEffectAllowedKind
1550+
DataTransferEffectAllowedKind[SO] val none: DataTransferEffectAllowedKind
1551+
DataTransferEffectAllowedKind[SO] val uninitialized: DataTransferEffectAllowedKind
1552+
DataTransferItem[JC] def getAsFile(): File
1553+
DataTransferItem[JC] def getAsString(callback: js.Function1[String, Unit]): Unit
1554+
DataTransferItem[JC] def kind: DragDataItemKind
1555+
DataTransferItem[JC] def `type`: String
1556+
DataTransferItemList[JC] def add(data: File): DataTransferItem
1557+
DataTransferItemList[JC] def add(data: String, `type`: String): DataTransferItem
1558+
DataTransferItemList[JC] @js.annotation.JSBracketAccess def apply(index: Int): DataTransferItem
1559+
DataTransferItemList[JC] def clear(): Unit
1560+
DataTransferItemList[JC] def length: Int
1561+
DataTransferItemList[JC] def remove(index: Int): Unit
15361562
DedicatedWorkerGlobalScope[JO] def self: DedicatedWorkerGlobalScope
15371563
DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
15381564
DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -1854,6 +1880,9 @@ DocumentType[JC] def removeEventListener[T <: Event](`type`: String, listener: j
18541880
DocumentType[JC] def replaceChild(newChild: Node, oldChild: Node): Node
18551881
DocumentType[JC] def systemId: String
18561882
DocumentType[JC] var textContent: String
1883+
DragDataItemKind[JT]
1884+
DragDataItemKind[SO] val file: DragDataItemKind
1885+
DragDataItemKind[SO] val string: DragDataItemKind
18571886
DragEffect[SO] final val All = "all"
18581887
DragEffect[SO] final val Copy = "copy"
18591888
DragEffect[SO] final val CopyLink = "copyLink"

api-reports/2_13.txt

+32-3
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,39 @@ DOMTokenList[JC] def remove(token: String): Unit
15261526
DOMTokenList[JC] def toggle(token: String): Boolean
15271527
DOMTokenList[JC] def toggle(token: String, force: Boolean): Boolean
15281528
DataTransfer[JT] def clearData(format: String?): Unit
1529-
DataTransfer[JT] var dropEffect: String
1530-
DataTransfer[JT] var effectAllowed: String
1529+
DataTransfer[JT] var dropEffect: DataTransferDropEffectKind
1530+
DataTransfer[JT] var effectAllowed: DataTransferEffectAllowedKind
15311531
DataTransfer[JT] def files: FileList
15321532
DataTransfer[JT] def getData(format: String): String
1533+
DataTransfer[JT] def items: DataTransferItemList
15331534
DataTransfer[JT] def setData(format: String, data: String): Unit
15341535
DataTransfer[JT] def setDragImage(image: Element, x: Double, y: Double): Unit
1535-
DataTransfer[JT] def types: js.Array[String]
1536+
DataTransfer[JT] def types: FrozenArray[String]
1537+
DataTransferDropEffectKind[JT]
1538+
DataTransferDropEffectKind[SO] val copy: DataTransferDropEffectKind
1539+
DataTransferDropEffectKind[SO] val link: DataTransferDropEffectKind
1540+
DataTransferDropEffectKind[SO] val move: DataTransferDropEffectKind
1541+
DataTransferDropEffectKind[SO] val none: DataTransferDropEffectKind
1542+
DataTransferEffectAllowedKind[JT]
1543+
DataTransferEffectAllowedKind[SO] val all: DataTransferEffectAllowedKind
1544+
DataTransferEffectAllowedKind[SO] val copy: DataTransferEffectAllowedKind
1545+
DataTransferEffectAllowedKind[SO] val copyLink: DataTransferEffectAllowedKind
1546+
DataTransferEffectAllowedKind[SO] val copyMove: DataTransferEffectAllowedKind
1547+
DataTransferEffectAllowedKind[SO] val link: DataTransferEffectAllowedKind
1548+
DataTransferEffectAllowedKind[SO] val linkMove: DataTransferEffectAllowedKind
1549+
DataTransferEffectAllowedKind[SO] val move: DataTransferEffectAllowedKind
1550+
DataTransferEffectAllowedKind[SO] val none: DataTransferEffectAllowedKind
1551+
DataTransferEffectAllowedKind[SO] val uninitialized: DataTransferEffectAllowedKind
1552+
DataTransferItem[JC] def getAsFile(): File
1553+
DataTransferItem[JC] def getAsString(callback: js.Function1[String, Unit]): Unit
1554+
DataTransferItem[JC] def kind: DragDataItemKind
1555+
DataTransferItem[JC] def `type`: String
1556+
DataTransferItemList[JC] def add(data: File): DataTransferItem
1557+
DataTransferItemList[JC] def add(data: String, `type`: String): DataTransferItem
1558+
DataTransferItemList[JC] @js.annotation.JSBracketAccess def apply(index: Int): DataTransferItem
1559+
DataTransferItemList[JC] def clear(): Unit
1560+
DataTransferItemList[JC] def length: Int
1561+
DataTransferItemList[JC] def remove(index: Int): Unit
15361562
DedicatedWorkerGlobalScope[JO] def self: DedicatedWorkerGlobalScope
15371563
DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
15381564
DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -1854,6 +1880,9 @@ DocumentType[JC] def removeEventListener[T <: Event](`type`: String, listener: j
18541880
DocumentType[JC] def replaceChild(newChild: Node, oldChild: Node): Node
18551881
DocumentType[JC] def systemId: String
18561882
DocumentType[JC] var textContent: String
1883+
DragDataItemKind[JT]
1884+
DragDataItemKind[SO] val file: DragDataItemKind
1885+
DragDataItemKind[SO] val string: DragDataItemKind
18571886
DragEffect[SO] final val All = "all"
18581887
DragEffect[SO] final val Copy = "copy"
18591888
DragEffect[SO] final val CopyLink = "copyLink"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait DataTransferDropEffectKind extends js.Any
7+
8+
object DataTransferDropEffectKind {
9+
val none: DataTransferDropEffectKind = "none".asInstanceOf[DataTransferDropEffectKind]
10+
val copy: DataTransferDropEffectKind = "copy".asInstanceOf[DataTransferDropEffectKind]
11+
val link: DataTransferDropEffectKind = "link".asInstanceOf[DataTransferDropEffectKind]
12+
val move: DataTransferDropEffectKind = "move".asInstanceOf[DataTransferDropEffectKind]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait DataTransferEffectAllowedKind extends js.Any
7+
8+
object DataTransferEffectAllowedKind {
9+
val none: DataTransferEffectAllowedKind= "none".asInstanceOf[DataTransferEffectAllowedKind]
10+
val copy: DataTransferEffectAllowedKind= "copy".asInstanceOf[DataTransferEffectAllowedKind]
11+
val copyLink: DataTransferEffectAllowedKind= "copyLink".asInstanceOf[DataTransferEffectAllowedKind]
12+
val copyMove: DataTransferEffectAllowedKind= "copyMove".asInstanceOf[DataTransferEffectAllowedKind]
13+
val link: DataTransferEffectAllowedKind= "link".asInstanceOf[DataTransferEffectAllowedKind]
14+
val linkMove: DataTransferEffectAllowedKind= "linkMove".asInstanceOf[DataTransferEffectAllowedKind]
15+
val move: DataTransferEffectAllowedKind= "move".asInstanceOf[DataTransferEffectAllowedKind]
16+
val all: DataTransferEffectAllowedKind= "all".asInstanceOf[DataTransferEffectAllowedKind]
17+
val uninitialized: DataTransferEffectAllowedKind= "uninitialized".asInstanceOf[DataTransferEffectAllowedKind]
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait DragDataItemKind extends js.Any
7+
8+
object DragDataItemKind {
9+
val string: DragDataItemKind = "string".asInstanceOf[DragDataItemKind]
10+
val file: DragDataItemKind = "file".asInstanceOf[DragDataItemKind]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type DataTransferDropEffectKind <: String = String
6+
7+
object DataTransferDropEffectKind {
8+
val none: DataTransferDropEffectKind = "none"
9+
val copy: DataTransferDropEffectKind = "copy"
10+
val link: DataTransferDropEffectKind = "link"
11+
val move: DataTransferDropEffectKind = "move"
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type DataTransferEffectAllowedKind <: String = String
6+
7+
object DataTransferEffectAllowedKind {
8+
val none: DataTransferEffectAllowedKind = "none"
9+
val copy: DataTransferEffectAllowedKind = "copy"
10+
val copyLink: DataTransferEffectAllowedKind = "copyLink"
11+
val copyMove: DataTransferEffectAllowedKind = "copyMove"
12+
val link: DataTransferEffectAllowedKind = "link"
13+
val linkMove: DataTransferEffectAllowedKind = "linkMove"
14+
val move: DataTransferEffectAllowedKind = "move"
15+
val all: DataTransferEffectAllowedKind = "all"
16+
val uninitialized: DataTransferEffectAllowedKind = "uninitialized"
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type DragDataItemKind <: String = String
6+
7+
object DragDataItemKind {
8+
val string: DragDataItemKind = "string"
9+
val file: DragDataItemKind = "file"
10+
}

dom/src/main/scala/org/scalajs/dom/DataTransfer.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@ trait DataTransfer extends js.Object {
1919
/** Specifies the effects that are allowed for this drag. You may set this in the dragstart event to set the desired
2020
* effects for the source, and within the dragenter and dragover events to set the desired effects for the target.
2121
* The value is not used for other events.
22-
*
23-
* See [[DragEffect]] for possible values.
2422
*/
25-
var effectAllowed: String = js.native
23+
var effectAllowed: DataTransferEffectAllowedKind = js.native
2624

27-
/** The actual effect that will be used, and should always be one of the possible values of effectAllowed.
28-
*
29-
* See [[DragEffect]] for possible values.
30-
*/
31-
var dropEffect: String = js.native
25+
/** The actual effect that will be used. */
26+
var dropEffect: DataTransferDropEffectKind = js.native
3227

3328
/** Remove the data associated with a given type. The type argument is optional. If the type is empty or not
3429
* specified, the data associated with all types is removed. If data for the specified type does not exist, or the
@@ -42,6 +37,9 @@ trait DataTransfer extends js.Object {
4237
*/
4338
def setData(format: String, data: String): Unit = js.native
4439

40+
/** Gives a DataTransferItemList object which is a list of all of the drag data. */
41+
def items: DataTransferItemList = js.native
42+
4543
/** Set the image to be used for dragging if a custom one is desired. Most of the time, this would not be set, as a
4644
* default image is created from the node that was dragged.
4745
*
@@ -77,7 +75,7 @@ trait DataTransfer extends js.Object {
7775
* The formats are Unicode strings giving the type or format of the data, generally given by a MIME type. Some values
7876
* that are not MIME types are special-cased for legacy reasons (for example "text").
7977
*/
80-
def types: js.Array[String] = js.native
78+
def types: FrozenArray[String] = js.native
8179

8280
def files: FileList = js.native
8381
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation.JSGlobal
11+
12+
/** Each DataTransferItem object is associated with a [[DataTransfer]] object. */
13+
@js.native
14+
@JSGlobal
15+
class DataTransferItem private[this] extends js.Object {
16+
17+
/** Returns the drag data item kind, one of: "string", "file". */
18+
def kind: DragDataItemKind = js.native
19+
20+
/** Returns the drag data item type string. */
21+
def `type`: String = js.native
22+
23+
/** Invokes the callback with the string data as the argument, if the drag data item kind is text. */
24+
def getAsString(callback: js.Function1[String, Unit]): Unit = js.native
25+
26+
/** Returns a File object, if the drag data item kind is File. */
27+
def getAsFile(): File = js.native
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation.JSGlobal
11+
12+
/** A list of [[DataTransferItem]] objects representing items being dragged. During a drag operation, each DragEvent has
13+
* a dataTransfer property and that property is a DataTransferItemList.
14+
*/
15+
@js.native
16+
@JSGlobal
17+
class DataTransferItemList private[this] extends js.Object {
18+
19+
/** Returns the number of items in the drag data store. */
20+
def length: Int = js.native
21+
22+
/** Adds a new entry for the given data to the drag data store. If the data is plain text then a type string has to be
23+
* provided also.
24+
*/
25+
def add(data: String, `type`: String): DataTransferItem = js.native
26+
27+
/** Adds a new entry for the given data to the drag data store. If the data is plain text then a type string has to be
28+
* provided also.
29+
*/
30+
def add(data: File): DataTransferItem = js.native
31+
32+
/** Removes the indexth entry in the drag data store. */
33+
def remove(index: Int): Unit = js.native
34+
35+
/** Removes all the entries in the drag data store. */
36+
def clear(): Unit = js.native
37+
38+
/** Returns the DataTransferItem object representing the indexth entry in the drag data store. */
39+
@js.annotation.JSBracketAccess
40+
def apply(index: Int): DataTransferItem = js.native
41+
}

0 commit comments

Comments
 (0)