Skip to content
12 changes: 12 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/DragDataItemKind.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.scalajs.dom

import scala.scalajs.js

/** Fetch APIs [[https://fetch.spec.whatwg.org/#requesttype RequestType enum]] */
@js.native
sealed trait DragDataItemKind extends js.Any

object DragDataItemKind {
val string: DragDataItemKind = "string".asInstanceOf[DragDataItemKind]
val file: DragDataItemKind = "file".asInstanceOf[DragDataItemKind]
}
13 changes: 13 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/DropEffectValue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
sealed trait DropEffectValue extends js.Any

object DropEffectValue {
val none: DropEffectValue = "none".asInstanceOf[DropEffectValue]
val copy: DropEffectValue = "copy".asInstanceOf[DropEffectValue]
val link: DropEffectValue = "link".asInstanceOf[DropEffectValue]
val move: DropEffectValue = "move".asInstanceOf[DropEffectValue]
}
18 changes: 18 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/EffectAllowedValue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
sealed trait EffectAllowedValue extends js.Any

object EffectAllowedValue{
val none: EffectAllowedValue = "none".asInstanceOf[EffectAllowedValue]
val copy: EffectAllowedValue = "copy".asInstanceOf[EffectAllowedValue]
val copyLink: EffectAllowedValue = "copyLink".asInstanceOf[EffectAllowedValue]
val copyMove: EffectAllowedValue = "copyMove".asInstanceOf[EffectAllowedValue]
val link: EffectAllowedValue = "link".asInstanceOf[EffectAllowedValue]
val linkMove: EffectAllowedValue = "linkMove".asInstanceOf[EffectAllowedValue]
val move: EffectAllowedValue = "move".asInstanceOf[EffectAllowedValue]
val all: EffectAllowedValue = "all".asInstanceOf[EffectAllowedValue]
val uninitialized: EffectAllowedValue = "uninitialized".asInstanceOf[EffectAllowedValue]
}
10 changes: 10 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/DragDataItemKind.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type DragDataItemKind <: String = String

object DragDataItemKind {
val string: DragDataItemKind = "string"
val file: DragDataItemKind = "file"
}
12 changes: 12 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/DropEffectValue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type DropEffectValue <: String = String

object DropEffectValue {
val none: DropEffectValue = "none"
val copy: DropEffectValue = "copy"
val link: DropEffectValue = "link"
val move: DropEffectValue = "move"
}
17 changes: 17 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/EffectAllowedValue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type EffectAllowedValue <: String = String

object EffectAllowedValue {
val none: EffectAllowedValue = "none"
val copy: EffectAllowedValue = "copy"
val copyLink: EffectAllowedValue = "copyLink"
val copyMove: EffectAllowedValue = "copyMove"
val link: EffectAllowedValue = "link"
val linkMove: EffectAllowedValue = "linkMove"
val move: EffectAllowedValue = "move"
val all: EffectAllowedValue = "all"
val uninitialized: EffectAllowedValue = "uninitialized"
}
16 changes: 7 additions & 9 deletions dom/src/main/scala/org/scalajs/dom/DataTransfer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ trait DataTransfer extends js.Object {
/** Specifies the effects that are allowed for this drag. You may set this in the dragstart event to set the desired
* effects for the source, and within the dragenter and dragover events to set the desired effects for the target.
* The value is not used for other events.
*
* See [[DragEffect]] for possible values.
*/
var effectAllowed: String = js.native
var effectAllowed: EffectAllowedValue = js.native

/** The actual effect that will be used, and should always be one of the possible values of effectAllowed.
*
* See [[DragEffect]] for possible values.
*/
var dropEffect: String = js.native
/** The actual effect that will be used, and should always be one of the possible values of effectAllowed. */
var dropEffect: DropEffectValue = js.native

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

/** Gives a DataTransferItemList object which is a list of all of the drag data. */
def items: DataTransferItemList = js.native

/** 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
* default image is created from the node that was dragged.
*
Expand Down Expand Up @@ -77,7 +75,7 @@ trait DataTransfer extends js.Object {
* The formats are Unicode strings giving the type or format of the data, generally given by a MIME type. Some values
* that are not MIME types are special-cased for legacy reasons (for example "text").
*/
def types: js.Array[String] = js.native
def types: FrozenArray[String] = js.native

def files: FileList = js.native
}
26 changes: 26 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/DataTransferItem.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js

/** Each DataTransferItem object is associated with a [[DataTransfer]] object. */
@js.native
trait DataTransferItem extends js.Object {

/** Returns the drag data item kind, one of: "string", "file". */
def kind: DragDataItemKind = js.native

/** Returns the drag data item type string. */
def `type`: String = js.native

/** Invokes the callback with the string data as the argument, if the drag data item kind is text. */
def getAsString(callback: () => String) = js.native

/** Returns a File object, if the drag data item kind is File. */
def getAsFile(): js.UndefOr[File] = js.native
}
39 changes: 39 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/DataTransferItemList.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js

@js.native
trait DataTransferItemList extends js.Object {

/** Returns the number of items in the drag data store. */
def length: Int = js.native

/** 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
* provided also.
*/
def add(data: String, `type`: String): Unit = js.native

/** 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
* provided also.
*/
def add(data: File): Unit = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDN says this has a defined return value :)

A DataTransferItem containing the specified data. If the drag item couldn't be created (for example, if the associated DataTransfer object has no data store), null is returned.

https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItemList/add#return_value


/** Removes the indexth entry in the drag data store. */
def remove(index: Int): Unit = js.native

/** Removes all the entries in the drag data store. */
def clear(): Unit = js.native

}

@js.native
object DataTransferItemList extends DataTransferItemList {
/** Returns the DataTransferItem object representing the indexth entry in the drag data store. */
def apply(index: Int): DataTransferItem = js.native
}