Skip to content

Fixup Clipboard to use added ClipboardItem #736

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 2 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,11 @@ Clients[JT] def openWindow(url: String): js.Promise[WindowClient]
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Clipboard[JT] def dispatchEvent(evt: Event): Boolean
Clipboard[JT] def read(): js.Promise[DataTransfer]
Clipboard[JT] def read(): js.Promise[js.Array[ClipboardItem]]
Clipboard[JT] def readText(): js.Promise[String]
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Clipboard[JT] def write(data: DataTransfer): js.Promise[Unit]
Clipboard[JT] def write(data: js.Array[ClipboardItem]): js.Promise[Unit]
Clipboard[JT] def writeText(newClipText: String): js.Promise[Unit]
ClipboardEvent[JC] def bubbles: Boolean
ClipboardEvent[JC] def cancelBubble: Boolean
Expand All @@ -1019,6 +1019,10 @@ ClipboardEventInit[JT] var composed: js.UndefOr[Boolean]
ClipboardEventInit[JT] var data: js.UndefOr[String]
ClipboardEventInit[JT] var dataType: js.UndefOr[String]
ClipboardEventInit[JT] var scoped: js.UndefOr[Boolean]
ClipboardItem[JC] def getType(`type`: String): js.Promise[Blob]
ClipboardItem[JC] def presentationStyle: PresentationStyle
ClipboardItem[JC] def types: FrozenArray[String]
ClipboardItemOptions[JT] def presentationStyle: js.UndefOr[PresentationStyle]
CloseEvent[JT] def bubbles: Boolean
CloseEvent[JT] def cancelBubble: Boolean
CloseEvent[JT] def cancelable: Boolean
Expand Down Expand Up @@ -2017,6 +2021,8 @@ FrameType[SO] val auxiliary: FrameType
FrameType[SO] val nested: FrameType
FrameType[SO] val none: FrameType
FrameType[SO] val `top-level` = "top-level".asInstanceOf[FrameType]
FrozenArray[JT] @js.annotation.JSBracketAccess def apply(index: Int): T
FrozenArray[JT] val length: Int
FullscreenOptions[JT] var navigationUI: js.UndefOr[String]
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down Expand Up @@ -16226,6 +16232,10 @@ PositionError[JT] def message: String
PositionOptions[JC] var enableHighAccuracy: Boolean
PositionOptions[JC] var maximumAge: Int
PositionOptions[JC] var timeout: Int
PresentationStyle[JT]
PresentationStyle[SO] val attachment: PresentationStyle
PresentationStyle[SO] val inline: PresentationStyle
PresentationStyle[SO] val unspecified: PresentationStyle
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
ProcessingInstruction[JC] def appendChild(newChild: Node): Node
Expand Down Expand Up @@ -26946,6 +26956,7 @@ package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
package[SO] type ByteString = String
package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0)
package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0)
package[SO] type ClipboardItemData = js.Promise[String | Blob]
package[SO] type HashAlgorithmIdentifier = HashAlgorithm | String
package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString]
package[SO] type IDBKey = Any
Expand Down
15 changes: 13 additions & 2 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,11 @@ Clients[JT] def openWindow(url: String): js.Promise[WindowClient]
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Clipboard[JT] def dispatchEvent(evt: Event): Boolean
Clipboard[JT] def read(): js.Promise[DataTransfer]
Clipboard[JT] def read(): js.Promise[js.Array[ClipboardItem]]
Clipboard[JT] def readText(): js.Promise[String]
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Clipboard[JT] def write(data: DataTransfer): js.Promise[Unit]
Clipboard[JT] def write(data: js.Array[ClipboardItem]): js.Promise[Unit]
Clipboard[JT] def writeText(newClipText: String): js.Promise[Unit]
ClipboardEvent[JC] def bubbles: Boolean
ClipboardEvent[JC] def cancelBubble: Boolean
Expand All @@ -1019,6 +1019,10 @@ ClipboardEventInit[JT] var composed: js.UndefOr[Boolean]
ClipboardEventInit[JT] var data: js.UndefOr[String]
ClipboardEventInit[JT] var dataType: js.UndefOr[String]
ClipboardEventInit[JT] var scoped: js.UndefOr[Boolean]
ClipboardItem[JC] def getType(`type`: String): js.Promise[Blob]
ClipboardItem[JC] def presentationStyle: PresentationStyle
ClipboardItem[JC] def types: FrozenArray[String]
ClipboardItemOptions[JT] def presentationStyle: js.UndefOr[PresentationStyle]
CloseEvent[JT] def bubbles: Boolean
CloseEvent[JT] def cancelBubble: Boolean
CloseEvent[JT] def cancelable: Boolean
Expand Down Expand Up @@ -2017,6 +2021,8 @@ FrameType[SO] val auxiliary: FrameType
FrameType[SO] val nested: FrameType
FrameType[SO] val none: FrameType
FrameType[SO] val `top-level` = "top-level".asInstanceOf[FrameType]
FrozenArray[JT] @js.annotation.JSBracketAccess def apply(index: Int): T
FrozenArray[JT] val length: Int
FullscreenOptions[JT] var navigationUI: js.UndefOr[String]
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down Expand Up @@ -16226,6 +16232,10 @@ PositionError[JT] def message: String
PositionOptions[JC] var enableHighAccuracy: Boolean
PositionOptions[JC] var maximumAge: Int
PositionOptions[JC] var timeout: Int
PresentationStyle[JT]
PresentationStyle[SO] val attachment: PresentationStyle
PresentationStyle[SO] val inline: PresentationStyle
PresentationStyle[SO] val unspecified: PresentationStyle
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
ProcessingInstruction[JC] def appendChild(newChild: Node): Node
Expand Down Expand Up @@ -26946,6 +26956,7 @@ package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
package[SO] type ByteString = String
package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0)
package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0)
package[SO] type ClipboardItemData = js.Promise[String | Blob]
package[SO] type HashAlgorithmIdentifier = HashAlgorithm | String
package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString]
package[SO] type IDBKey = Any
Expand Down
16 changes: 16 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/PresentationStyle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.scalajs.dom

import scala.scalajs.js

/**
* Helps distinguish whether apps "pasting" a clipboard item should insert the contents of an appropriate representation inline at the point of paste or if it should be treated as an attachment.
* See [[https://w3c.github.io/clipboard-apis/#enumdef-presentationstyle PresentationStyle enum]]
*/
@js.native
sealed trait PresentationStyle extends js.Any

object PresentationStyle{
val unspecified: PresentationStyle = "unspecified".asInstanceOf[PresentationStyle]
val inline: PresentationStyle = "inline".asInstanceOf[PresentationStyle]
val attachment: PresentationStyle = "attachment".asInstanceOf[PresentationStyle]
}
15 changes: 15 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/PresentationStyle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.scalajs.dom

import scala.scalajs.js

/**
* Helps distinguish whether apps "pasting" a clipboard item should insert the contents of an appropriate representation inline at the point of paste or if it should be treated as an attachment.
* See [[https://w3c.github.io/clipboard-apis/#enumdef-presentationstyle PresentationStyle enum]]
*/
opaque type PresentationStyle <: String = String

object PresentationStyle {
val unspecified: PresentationStyle = "unspecified"
val inline: PresentationStyle = "inline"
val attachment: PresentationStyle = "attachment"
}
4 changes: 2 additions & 2 deletions dom/src/main/scala/org/scalajs/dom/Clipboard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait Clipboard extends EventTarget {
*
* To read from the clipboard, you must first have the "clipboard-read" permission.
*/
def read(): js.Promise[DataTransfer] = js.native
def read(): js.Promise[js.Array[ClipboardItem]] = js.native

/** The readText() method returns a Promise which resolves with a copy of the textual contents of the system
* clipboard.
Expand All @@ -38,7 +38,7 @@ trait Clipboard extends EventTarget {
* Before you can write to the clipboard, you need to use the Permissions API to get the "clipboard-write"
* permission.
*/
def write(data: DataTransfer): js.Promise[Unit] = js.native
def write(data: js.Array[ClipboardItem]): js.Promise[Unit] = js.native

/** The writeText() method writes the specified text string to the system clipboard. */
def writeText(newClipText: String): js.Promise[Unit] = js.native
Expand Down
28 changes: 28 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ClipboardItem.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._

/** A clipboard item is conceptually data that the user has expressed a desire to make shareable by invoking a "cut" or
* "copy" command
*/
@js.native
@JSGlobal
class ClipboardItem(items: js.Dictionary[ClipboardItemData], options: ClipboardItemOptions = js.native)
extends js.Object {
def presentationStyle: PresentationStyle = js.native

/** Returns an Array of MIME types available within the ClipboardItem. */
def types: FrozenArray[String] = js.native

/** Returns a Promise that resolves with a Blob of the requested MIME type, or an error if the MIME type is not found.
*/
def getType(`type`: String): js.Promise[Blob] = js.native

}
13 changes: 13 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ClipboardItemOptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** 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

trait ClipboardItemOptions extends js.Object {
def presentationStyle: js.UndefOr[PresentationStyle] = js.undefined
}
23 changes: 23 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/FrozenArray.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** 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

/** A frozen array type is a parameterized type whose values are references to objects that hold a fixed length array of
* unmodifiable values. The values in the array are of type T.
*
* Since FrozenArray<T> values are references, they are unlike sequence types, which are lists of values that are
* passed by value.
*/
@js.native
trait FrozenArray[+T] extends js.Iterable[T] {
val length: Int = js.native

@js.annotation.JSBracketAccess
def apply(index: Int): T = js.native
}
2 changes: 2 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ package object dom {
val webcrypto: Crypto = js.native

type BlobPart = BufferSource | Blob | String

type ClipboardItemData = js.Promise[String | Blob]
}