Skip to content

Refresh DataTransfer API #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 10, 2023
35 changes: 32 additions & 3 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1297,13 +1297,24 @@ 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: DropEffectValue
DataTransfer[JT] var effectAllowed: EffectAllowedValue
Copy link
Member

Choose a reason for hiding this comment

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

Ok, after many sleepless nights I propose:

  • DataTransferDropEffectKind
  • DataTransferEffectAllowedKind

Rationale:

  • Prefix with DataTransfer to "namespace" them. Since we are just making these names up, there's no guarantee that there won't be some other unrelated DropEffect or EffectAllowed API added in the future, that would clash with the name.
  • Postfix with Kind, because the spec describes it as "the kind of operation". Furthermore, looking through other enums we've facaded, we have various "kinds" but not any "values".

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The prefix to namespace sounds extremely meh, but I can't argue with that reasoning :P.
And yes postfixing with Kind sounds great!

Copy link
Member

Choose a reason for hiding this comment

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

The prefix to namespace sounds extremely me

Heh yeah, welcome to browsers where everything is in the global namespace 😛 anyway we have various precedents for doing that as well, some of which I think has been copied from spec/TS/something 🤔

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]
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
Expand Down Expand Up @@ -1625,6 +1636,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"
Expand Down Expand Up @@ -1666,6 +1680,11 @@ DragEvent[JT] def target: EventTarget
DragEvent[JT] def timeStamp: Double
DragEvent[JT] def `type`: String
DragEvent[JT] def view: Window
DropEffectValue[JT]
DropEffectValue[SO] val copy: DropEffectValue
DropEffectValue[SO] val link: DropEffectValue
DropEffectValue[SO] val move: DropEffectValue
DropEffectValue[SO] val none: DropEffectValue
DynamicsCompressorNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
DynamicsCompressorNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
DynamicsCompressorNode[JT] val attack: AudioParam
Expand Down Expand Up @@ -1711,6 +1730,16 @@ EcdsaParams[JT] val name: String
EcdsaParams[SO] def apply(name: String, hash: HashAlgorithmIdentifier): EcdsaParams (@deprecated in 2.0.0)
EcdsaParams[SO] val hash = hash0
EcdsaParams[SO] val name = name0
EffectAllowedValue[JT]
EffectAllowedValue[SO] val all: EffectAllowedValue
EffectAllowedValue[SO] val copy: EffectAllowedValue
EffectAllowedValue[SO] val copyLink: EffectAllowedValue
EffectAllowedValue[SO] val copyMove: EffectAllowedValue
EffectAllowedValue[SO] val link: EffectAllowedValue
EffectAllowedValue[SO] val linkMove: EffectAllowedValue
EffectAllowedValue[SO] val move: EffectAllowedValue
EffectAllowedValue[SO] val none: EffectAllowedValue
EffectAllowedValue[SO] val uninitialized: EffectAllowedValue
Element[JC] var accessKey: String
Element[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Element[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down
35 changes: 32 additions & 3 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1297,13 +1297,24 @@ 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: DropEffectValue
DataTransfer[JT] var effectAllowed: EffectAllowedValue
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]
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
Expand Down Expand Up @@ -1625,6 +1636,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"
Expand Down Expand Up @@ -1666,6 +1680,11 @@ DragEvent[JT] def target: EventTarget
DragEvent[JT] def timeStamp: Double
DragEvent[JT] def `type`: String
DragEvent[JT] def view: Window
DropEffectValue[JT]
DropEffectValue[SO] val copy: DropEffectValue
DropEffectValue[SO] val link: DropEffectValue
DropEffectValue[SO] val move: DropEffectValue
DropEffectValue[SO] val none: DropEffectValue
DynamicsCompressorNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
DynamicsCompressorNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
DynamicsCompressorNode[JT] val attack: AudioParam
Expand Down Expand Up @@ -1711,6 +1730,16 @@ EcdsaParams[JT] val name: String
EcdsaParams[SO] def apply(name: String, hash: HashAlgorithmIdentifier): EcdsaParams (@deprecated in 2.0.0)
EcdsaParams[SO] val hash = hash0
EcdsaParams[SO] val name = name0
EffectAllowedValue[JT]
EffectAllowedValue[SO] val all: EffectAllowedValue
EffectAllowedValue[SO] val copy: EffectAllowedValue
EffectAllowedValue[SO] val copyLink: EffectAllowedValue
EffectAllowedValue[SO] val copyMove: EffectAllowedValue
EffectAllowedValue[SO] val link: EffectAllowedValue
EffectAllowedValue[SO] val linkMove: EffectAllowedValue
EffectAllowedValue[SO] val move: EffectAllowedValue
EffectAllowedValue[SO] val none: EffectAllowedValue
EffectAllowedValue[SO] val uninitialized: EffectAllowedValue
Element[JC] var accessKey: String
Element[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Element[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down
11 changes: 11 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,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]
}
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. */
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
}
28 changes: 28 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,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
}
41 changes: 41 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,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
}