Skip to content

Commit 976316c

Browse files
committed
Refresh DataTransfer API
1 parent 260fdf0 commit 976316c

File tree

9 files changed

+149
-9
lines changed

9 files changed

+149
-9
lines changed
Lines changed: 12 additions & 0 deletions
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+
/** Fetch APIs [[https://fetch.spec.whatwg.org/#requesttype RequestType enum]] */
6+
@js.native
7+
sealed trait DragDataItemKind extends js.Any
8+
9+
object DragDataItemKind {
10+
val string: DragDataItemKind = "string".asInstanceOf[DragDataItemKind]
11+
val file: DragDataItemKind = "file".asInstanceOf[DragDataItemKind]
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.scalajs.js
2+
3+
@js.native
4+
sealed trait DropEffectValue extends js.Any
5+
6+
object DropEffectValue {
7+
val none: DropEffectValue = "none".asInstanceOf[DropEffectValue]
8+
val copy: DropEffectValue = "copy".asInstanceOf[DropEffectValue]
9+
val link: DropEffectValue = "link".asInstanceOf[DropEffectValue]
10+
val move: DropEffectValue = "move".asInstanceOf[DropEffectValue]
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.scalajs.js
2+
3+
@js.native
4+
sealed trait EffectAllowedValue extends js.Any
5+
6+
object EffectAllowedValue{
7+
val none: EffectAllowedValue = "none".asInstanceOf[EffectAllowedValue]
8+
val copy: EffectAllowedValue = "copy".asInstanceOf[EffectAllowedValue]
9+
val copyLink: EffectAllowedValue = "copyLink".asInstanceOf[EffectAllowedValue]
10+
val copyMove: EffectAllowedValue = "copyMove".asInstanceOf[EffectAllowedValue]
11+
val link: EffectAllowedValue = "link".asInstanceOf[EffectAllowedValue]
12+
val linkMove: EffectAllowedValue = "linkMove".asInstanceOf[EffectAllowedValue]
13+
val move: EffectAllowedValue = "move".asInstanceOf[EffectAllowedValue]
14+
val all: EffectAllowedValue = "all".asInstanceOf[EffectAllowedValue]
15+
val uninitialized: EffectAllowedValue = "uninitialized".asInstanceOf[EffectAllowedValue]
16+
}
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 12 additions & 0 deletions
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 DropEffectValue <: String = String
6+
7+
object DropEffectValue {
8+
val none: DropEffectValue = "none"
9+
val copy: DropEffectValue = "copy"
10+
val link: DropEffectValue = "link"
11+
val move: DropEffectValue = "move"
12+
}
Lines changed: 17 additions & 0 deletions
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 EffectAllowedValue <: String = String
6+
7+
object EffectAllowedValue {
8+
val none: EffectAllowedValue = "none"
9+
val copy: EffectAllowedValue = "copy"
10+
val copyLink: EffectAllowedValue = "copyLink"
11+
val copyMove: EffectAllowedValue = "copyMove"
12+
val link: EffectAllowedValue = "link"
13+
val linkMove: EffectAllowedValue = "linkMove"
14+
val move: EffectAllowedValue = "move"
15+
val all: EffectAllowedValue = "all"
16+
val uninitialized: EffectAllowedValue = "uninitialized"
17+
}

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

Lines changed: 7 additions & 9 deletions
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: EffectAllowedValue = 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, and should always be one of the possible values of effectAllowed. */
26+
var dropEffect: DropEffectValue = 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
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
11+
/** Each DataTransferItem object is associated with a [[DataTransfer]] object. */
12+
@js.native
13+
trait DataTransferItem {
14+
15+
/** Returns the drag data item kind, one of: "string", "file". */
16+
def kind: DragDataItemKind = js.native
17+
18+
/** Returns the drag data item type string. */
19+
def `type`: String = js.native
20+
21+
/** Invokes the callback with the string data as the argument, if the drag data item kind is text. */
22+
def getAsString(callback: () => String) = js.native
23+
24+
/** Returns a File object, if the drag data item kind is File. */
25+
def getAsFile(): js.UndefOr[File] = js.native
26+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
11+
@js.native
12+
trait DataTransferItemList {
13+
14+
/** Returns the number of items in the drag data store. */
15+
def length: Int = js.native
16+
17+
/** 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
18+
* provided also.
19+
*/
20+
def add(data: String, `type`: String): Unit = 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: File): Unit = js.native
26+
27+
/** Removes the indexth entry in the drag data store. */
28+
def remove(index: Int): Unit = js.native
29+
30+
/** Removes all the entries in the drag data store. */
31+
def clear(): Unit = js.native
32+
}
33+
34+
object DataTransferItemList {
35+
36+
/** Returns the DataTransferItem object representing the indexth entry in the drag data store. */
37+
def apply(index: Int): DataTransferItem = js.native
38+
}

0 commit comments

Comments
 (0)