diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 81d5249ec..d5e0adc91 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -1297,13 +1297,39 @@ DOMTokenList[JC] def remove(token: String): Unit DOMTokenList[JC] def toggle(token: String): Boolean DOMTokenList[JC] def toggle(token: String, force: Boolean): Boolean DataTransfer[JT] def clearData(format: String?): Unit -DataTransfer[JT] var dropEffect: String -DataTransfer[JT] var effectAllowed: String +DataTransfer[JT] var dropEffect: DataTransferDropEffectKind +DataTransfer[JT] var effectAllowed: DataTransferEffectAllowedKind DataTransfer[JT] def files: FileList DataTransfer[JT] def getData(format: String): String +DataTransfer[JT] def items: DataTransferItemList DataTransfer[JT] def setData(format: String, data: String): Unit DataTransfer[JT] def setDragImage(image: Element, x: Double, y: Double): Unit -DataTransfer[JT] def types: js.Array[String] +DataTransfer[JT] def types: FrozenArray[String] +DataTransferDropEffectKind[JT] +DataTransferDropEffectKind[SO] val copy: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val link: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val move: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val none: DataTransferDropEffectKind +DataTransferEffectAllowedKind[JT] +DataTransferEffectAllowedKind[SO] val all: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copy: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copyLink: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copyMove: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val link: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val linkMove: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val move: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val none: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val uninitialized: DataTransferEffectAllowedKind +DataTransferItem[JC] def getAsFile(): File +DataTransferItem[JC] def getAsString(callback: js.Function1[String, Unit]): Unit +DataTransferItem[JC] def kind: DragDataItemKind +DataTransferItem[JC] def `type`: String +DataTransferItemList[JC] def add(data: File): DataTransferItem +DataTransferItemList[JC] def add(data: String, `type`: String): DataTransferItem +DataTransferItemList[JC] @js.annotation.JSBracketAccess def apply(index: Int): DataTransferItem +DataTransferItemList[JC] def clear(): Unit +DataTransferItemList[JC] def length: Int +DataTransferItemList[JC] def remove(index: Int): Unit DedicatedWorkerGlobalScope[JO] def self: DedicatedWorkerGlobalScope DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -1625,6 +1651,9 @@ DocumentType[JC] def removeEventListener[T <: Event](`type`: String, listener: j DocumentType[JC] def replaceChild(newChild: Node, oldChild: Node): Node DocumentType[JC] def systemId: String DocumentType[JC] var textContent: String +DragDataItemKind[JT] +DragDataItemKind[SO] val file: DragDataItemKind +DragDataItemKind[SO] val string: DragDataItemKind DragEffect[SO] final val All = "all" DragEffect[SO] final val Copy = "copy" DragEffect[SO] final val CopyLink = "copyLink" diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 81d5249ec..d5e0adc91 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -1297,13 +1297,39 @@ DOMTokenList[JC] def remove(token: String): Unit DOMTokenList[JC] def toggle(token: String): Boolean DOMTokenList[JC] def toggle(token: String, force: Boolean): Boolean DataTransfer[JT] def clearData(format: String?): Unit -DataTransfer[JT] var dropEffect: String -DataTransfer[JT] var effectAllowed: String +DataTransfer[JT] var dropEffect: DataTransferDropEffectKind +DataTransfer[JT] var effectAllowed: DataTransferEffectAllowedKind DataTransfer[JT] def files: FileList DataTransfer[JT] def getData(format: String): String +DataTransfer[JT] def items: DataTransferItemList DataTransfer[JT] def setData(format: String, data: String): Unit DataTransfer[JT] def setDragImage(image: Element, x: Double, y: Double): Unit -DataTransfer[JT] def types: js.Array[String] +DataTransfer[JT] def types: FrozenArray[String] +DataTransferDropEffectKind[JT] +DataTransferDropEffectKind[SO] val copy: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val link: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val move: DataTransferDropEffectKind +DataTransferDropEffectKind[SO] val none: DataTransferDropEffectKind +DataTransferEffectAllowedKind[JT] +DataTransferEffectAllowedKind[SO] val all: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copy: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copyLink: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val copyMove: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val link: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val linkMove: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val move: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val none: DataTransferEffectAllowedKind +DataTransferEffectAllowedKind[SO] val uninitialized: DataTransferEffectAllowedKind +DataTransferItem[JC] def getAsFile(): File +DataTransferItem[JC] def getAsString(callback: js.Function1[String, Unit]): Unit +DataTransferItem[JC] def kind: DragDataItemKind +DataTransferItem[JC] def `type`: String +DataTransferItemList[JC] def add(data: File): DataTransferItem +DataTransferItemList[JC] def add(data: String, `type`: String): DataTransferItem +DataTransferItemList[JC] @js.annotation.JSBracketAccess def apply(index: Int): DataTransferItem +DataTransferItemList[JC] def clear(): Unit +DataTransferItemList[JC] def length: Int +DataTransferItemList[JC] def remove(index: Int): Unit DedicatedWorkerGlobalScope[JO] def self: DedicatedWorkerGlobalScope DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit DedicatedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -1625,6 +1651,9 @@ DocumentType[JC] def removeEventListener[T <: Event](`type`: String, listener: j DocumentType[JC] def replaceChild(newChild: Node, oldChild: Node): Node DocumentType[JC] def systemId: String DocumentType[JC] var textContent: String +DragDataItemKind[JT] +DragDataItemKind[SO] val file: DragDataItemKind +DragDataItemKind[SO] val string: DragDataItemKind DragEffect[SO] final val All = "all" DragEffect[SO] final val Copy = "copy" DragEffect[SO] final val CopyLink = "copyLink" diff --git a/dom/src/main/scala-2/org/scalajs/dom/DataTransferDropEffectKind.scala b/dom/src/main/scala-2/org/scalajs/dom/DataTransferDropEffectKind.scala new file mode 100644 index 000000000..8a264934f --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/DataTransferDropEffectKind.scala @@ -0,0 +1,13 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait DataTransferDropEffectKind extends js.Any + +object DataTransferDropEffectKind { + val none: DataTransferDropEffectKind = "none".asInstanceOf[DataTransferDropEffectKind] + val copy: DataTransferDropEffectKind = "copy".asInstanceOf[DataTransferDropEffectKind] + val link: DataTransferDropEffectKind = "link".asInstanceOf[DataTransferDropEffectKind] + val move: DataTransferDropEffectKind = "move".asInstanceOf[DataTransferDropEffectKind] +} diff --git a/dom/src/main/scala-2/org/scalajs/dom/DataTransferEffectAllowedKind.scala b/dom/src/main/scala-2/org/scalajs/dom/DataTransferEffectAllowedKind.scala new file mode 100644 index 000000000..8c99ec556 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/DataTransferEffectAllowedKind.scala @@ -0,0 +1,18 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait DataTransferEffectAllowedKind extends js.Any + +object DataTransferEffectAllowedKind { + val none: DataTransferEffectAllowedKind= "none".asInstanceOf[DataTransferEffectAllowedKind] + val copy: DataTransferEffectAllowedKind= "copy".asInstanceOf[DataTransferEffectAllowedKind] + val copyLink: DataTransferEffectAllowedKind= "copyLink".asInstanceOf[DataTransferEffectAllowedKind] + val copyMove: DataTransferEffectAllowedKind= "copyMove".asInstanceOf[DataTransferEffectAllowedKind] + val link: DataTransferEffectAllowedKind= "link".asInstanceOf[DataTransferEffectAllowedKind] + val linkMove: DataTransferEffectAllowedKind= "linkMove".asInstanceOf[DataTransferEffectAllowedKind] + val move: DataTransferEffectAllowedKind= "move".asInstanceOf[DataTransferEffectAllowedKind] + val all: DataTransferEffectAllowedKind= "all".asInstanceOf[DataTransferEffectAllowedKind] + val uninitialized: DataTransferEffectAllowedKind= "uninitialized".asInstanceOf[DataTransferEffectAllowedKind] +} diff --git a/dom/src/main/scala-2/org/scalajs/dom/DragDataItemKind.scala b/dom/src/main/scala-2/org/scalajs/dom/DragDataItemKind.scala new file mode 100644 index 000000000..5769b7043 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/DragDataItemKind.scala @@ -0,0 +1,11 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait DragDataItemKind extends js.Any + +object DragDataItemKind { + val string: DragDataItemKind = "string".asInstanceOf[DragDataItemKind] + val file: DragDataItemKind = "file".asInstanceOf[DragDataItemKind] +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/DataTransferDropEffectKind.scala b/dom/src/main/scala-3/org/scalajs/dom/DataTransferDropEffectKind.scala new file mode 100644 index 000000000..0594b6d18 --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/DataTransferDropEffectKind.scala @@ -0,0 +1,12 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type DataTransferDropEffectKind <: String = String + +object DataTransferDropEffectKind { + val none: DataTransferDropEffectKind = "none" + val copy: DataTransferDropEffectKind = "copy" + val link: DataTransferDropEffectKind = "link" + val move: DataTransferDropEffectKind = "move" +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/DataTransferEffectAllowedKind.scala b/dom/src/main/scala-3/org/scalajs/dom/DataTransferEffectAllowedKind.scala new file mode 100644 index 000000000..71a010f2f --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/DataTransferEffectAllowedKind.scala @@ -0,0 +1,17 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type DataTransferEffectAllowedKind <: String = String + +object DataTransferEffectAllowedKind { + val none: DataTransferEffectAllowedKind = "none" + val copy: DataTransferEffectAllowedKind = "copy" + val copyLink: DataTransferEffectAllowedKind = "copyLink" + val copyMove: DataTransferEffectAllowedKind = "copyMove" + val link: DataTransferEffectAllowedKind = "link" + val linkMove: DataTransferEffectAllowedKind = "linkMove" + val move: DataTransferEffectAllowedKind = "move" + val all: DataTransferEffectAllowedKind = "all" + val uninitialized: DataTransferEffectAllowedKind = "uninitialized" +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/DragDataItemKind.scala b/dom/src/main/scala-3/org/scalajs/dom/DragDataItemKind.scala new file mode 100644 index 000000000..f695f1c08 --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/DragDataItemKind.scala @@ -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" +} diff --git a/dom/src/main/scala/org/scalajs/dom/DataTransfer.scala b/dom/src/main/scala/org/scalajs/dom/DataTransfer.scala index e4971ece1..88f92c9b0 100644 --- a/dom/src/main/scala/org/scalajs/dom/DataTransfer.scala +++ b/dom/src/main/scala/org/scalajs/dom/DataTransfer.scala @@ -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: DataTransferEffectAllowedKind = 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. */ + var dropEffect: DataTransferDropEffectKind = 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 @@ -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. * @@ -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 } diff --git a/dom/src/main/scala/org/scalajs/dom/DataTransferItem.scala b/dom/src/main/scala/org/scalajs/dom/DataTransferItem.scala new file mode 100644 index 000000000..7efdfc77b --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/DataTransferItem.scala @@ -0,0 +1,28 @@ +/** 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 +import scala.scalajs.js.annotation.JSGlobal + +/** Each DataTransferItem object is associated with a [[DataTransfer]] object. */ +@js.native +@JSGlobal +class DataTransferItem private[this] 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: js.Function1[String, Unit]): Unit = js.native + + /** Returns a File object, if the drag data item kind is File. */ + def getAsFile(): File = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/DataTransferItemList.scala b/dom/src/main/scala/org/scalajs/dom/DataTransferItemList.scala new file mode 100644 index 000000000..423f308b6 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/DataTransferItemList.scala @@ -0,0 +1,41 @@ +/** 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 +import scala.scalajs.js.annotation.JSGlobal + +/** A list of [[DataTransferItem]] objects representing items being dragged. During a drag operation, each DragEvent has + * a dataTransfer property and that property is a DataTransferItemList. + */ +@js.native +@JSGlobal +class DataTransferItemList private[this] 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): DataTransferItem = 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): DataTransferItem = js.native + + /** 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 + + /** Returns the DataTransferItem object representing the indexth entry in the drag data store. */ + @js.annotation.JSBracketAccess + def apply(index: Int): DataTransferItem = js.native +}