Skip to content

Commit 1f713b1

Browse files
authored
Merge pull request #736 from zetashift/fix/#730
Fixup `Clipboard` to use added `ClipboardItem`
2 parents fec5ef8 + 179cb77 commit 1f713b1

File tree

9 files changed

+125
-6
lines changed

9 files changed

+125
-6
lines changed

api-reports/2_12.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,11 @@ Clients[JT] def openWindow(url: String): js.Promise[WindowClient]
993993
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
994994
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
995995
Clipboard[JT] def dispatchEvent(evt: Event): Boolean
996-
Clipboard[JT] def read(): js.Promise[DataTransfer]
996+
Clipboard[JT] def read(): js.Promise[js.Array[ClipboardItem]]
997997
Clipboard[JT] def readText(): js.Promise[String]
998998
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
999999
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1000-
Clipboard[JT] def write(data: DataTransfer): js.Promise[Unit]
1000+
Clipboard[JT] def write(data: js.Array[ClipboardItem]): js.Promise[Unit]
10011001
Clipboard[JT] def writeText(newClipText: String): js.Promise[Unit]
10021002
ClipboardEvent[JC] def bubbles: Boolean
10031003
ClipboardEvent[JC] def cancelBubble: Boolean
@@ -1019,6 +1019,10 @@ ClipboardEventInit[JT] var composed: js.UndefOr[Boolean]
10191019
ClipboardEventInit[JT] var data: js.UndefOr[String]
10201020
ClipboardEventInit[JT] var dataType: js.UndefOr[String]
10211021
ClipboardEventInit[JT] var scoped: js.UndefOr[Boolean]
1022+
ClipboardItem[JC] def getType(`type`: String): js.Promise[Blob]
1023+
ClipboardItem[JC] def presentationStyle: PresentationStyle
1024+
ClipboardItem[JC] def types: FrozenArray[String]
1025+
ClipboardItemOptions[JT] def presentationStyle: js.UndefOr[PresentationStyle]
10221026
CloseEvent[JT] def bubbles: Boolean
10231027
CloseEvent[JT] def cancelBubble: Boolean
10241028
CloseEvent[JT] def cancelable: Boolean
@@ -2017,6 +2021,8 @@ FrameType[SO] val auxiliary: FrameType
20172021
FrameType[SO] val nested: FrameType
20182022
FrameType[SO] val none: FrameType
20192023
FrameType[SO] val `top-level` = "top-level".asInstanceOf[FrameType]
2024+
FrozenArray[JT] @js.annotation.JSBracketAccess def apply(index: Int): T
2025+
FrozenArray[JT] val length: Int
20202026
FullscreenOptions[JT] var navigationUI: js.UndefOr[String]
20212027
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
20222028
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -16226,6 +16232,10 @@ PositionError[JT] def message: String
1622616232
PositionOptions[JC] var enableHighAccuracy: Boolean
1622716233
PositionOptions[JC] var maximumAge: Int
1622816234
PositionOptions[JC] var timeout: Int
16235+
PresentationStyle[JT]
16236+
PresentationStyle[SO] val attachment: PresentationStyle
16237+
PresentationStyle[SO] val inline: PresentationStyle
16238+
PresentationStyle[SO] val unspecified: PresentationStyle
1622916239
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1623016240
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1623116241
ProcessingInstruction[JC] def appendChild(newChild: Node): Node
@@ -26946,6 +26956,7 @@ package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
2694626956
package[SO] type ByteString = String
2694726957
package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0)
2694826958
package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0)
26959+
package[SO] type ClipboardItemData = js.Promise[String | Blob]
2694926960
package[SO] type HashAlgorithmIdentifier = HashAlgorithm | String
2695026961
package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString]
2695126962
package[SO] type IDBKey = Any

api-reports/2_13.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,11 @@ Clients[JT] def openWindow(url: String): js.Promise[WindowClient]
993993
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
994994
Clipboard[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
995995
Clipboard[JT] def dispatchEvent(evt: Event): Boolean
996-
Clipboard[JT] def read(): js.Promise[DataTransfer]
996+
Clipboard[JT] def read(): js.Promise[js.Array[ClipboardItem]]
997997
Clipboard[JT] def readText(): js.Promise[String]
998998
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
999999
Clipboard[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1000-
Clipboard[JT] def write(data: DataTransfer): js.Promise[Unit]
1000+
Clipboard[JT] def write(data: js.Array[ClipboardItem]): js.Promise[Unit]
10011001
Clipboard[JT] def writeText(newClipText: String): js.Promise[Unit]
10021002
ClipboardEvent[JC] def bubbles: Boolean
10031003
ClipboardEvent[JC] def cancelBubble: Boolean
@@ -1019,6 +1019,10 @@ ClipboardEventInit[JT] var composed: js.UndefOr[Boolean]
10191019
ClipboardEventInit[JT] var data: js.UndefOr[String]
10201020
ClipboardEventInit[JT] var dataType: js.UndefOr[String]
10211021
ClipboardEventInit[JT] var scoped: js.UndefOr[Boolean]
1022+
ClipboardItem[JC] def getType(`type`: String): js.Promise[Blob]
1023+
ClipboardItem[JC] def presentationStyle: PresentationStyle
1024+
ClipboardItem[JC] def types: FrozenArray[String]
1025+
ClipboardItemOptions[JT] def presentationStyle: js.UndefOr[PresentationStyle]
10221026
CloseEvent[JT] def bubbles: Boolean
10231027
CloseEvent[JT] def cancelBubble: Boolean
10241028
CloseEvent[JT] def cancelable: Boolean
@@ -2017,6 +2021,8 @@ FrameType[SO] val auxiliary: FrameType
20172021
FrameType[SO] val nested: FrameType
20182022
FrameType[SO] val none: FrameType
20192023
FrameType[SO] val `top-level` = "top-level".asInstanceOf[FrameType]
2024+
FrozenArray[JT] @js.annotation.JSBracketAccess def apply(index: Int): T
2025+
FrozenArray[JT] val length: Int
20202026
FullscreenOptions[JT] var navigationUI: js.UndefOr[String]
20212027
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
20222028
GainNode[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -16226,6 +16232,10 @@ PositionError[JT] def message: String
1622616232
PositionOptions[JC] var enableHighAccuracy: Boolean
1622716233
PositionOptions[JC] var maximumAge: Int
1622816234
PositionOptions[JC] var timeout: Int
16235+
PresentationStyle[JT]
16236+
PresentationStyle[SO] val attachment: PresentationStyle
16237+
PresentationStyle[SO] val inline: PresentationStyle
16238+
PresentationStyle[SO] val unspecified: PresentationStyle
1622916239
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1623016240
ProcessingInstruction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1623116241
ProcessingInstruction[JC] def appendChild(newChild: Node): Node
@@ -26946,6 +26956,7 @@ package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
2694626956
package[SO] type ByteString = String
2694726957
package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0)
2694826958
package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0)
26959+
package[SO] type ClipboardItemData = js.Promise[String | Blob]
2694926960
package[SO] type HashAlgorithmIdentifier = HashAlgorithm | String
2695026961
package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString]
2695126962
package[SO] type IDBKey = Any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* 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.
7+
* See [[https://w3c.github.io/clipboard-apis/#enumdef-presentationstyle PresentationStyle enum]]
8+
*/
9+
@js.native
10+
sealed trait PresentationStyle extends js.Any
11+
12+
object PresentationStyle{
13+
val unspecified: PresentationStyle = "unspecified".asInstanceOf[PresentationStyle]
14+
val inline: PresentationStyle = "inline".asInstanceOf[PresentationStyle]
15+
val attachment: PresentationStyle = "attachment".asInstanceOf[PresentationStyle]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* 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.
7+
* See [[https://w3c.github.io/clipboard-apis/#enumdef-presentationstyle PresentationStyle enum]]
8+
*/
9+
opaque type PresentationStyle <: String = String
10+
11+
object PresentationStyle {
12+
val unspecified: PresentationStyle = "unspecified"
13+
val inline: PresentationStyle = "inline"
14+
val attachment: PresentationStyle = "attachment"
15+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait Clipboard extends EventTarget {
2525
*
2626
* To read from the clipboard, you must first have the "clipboard-read" permission.
2727
*/
28-
def read(): js.Promise[DataTransfer] = js.native
28+
def read(): js.Promise[js.Array[ClipboardItem]] = js.native
2929

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

4343
/** The writeText() method writes the specified text string to the system clipboard. */
4444
def writeText(newClipText: String): js.Promise[Unit] = js.native
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
import scala.scalajs.js.annotation._
11+
12+
/** A clipboard item is conceptually data that the user has expressed a desire to make shareable by invoking a "cut" or
13+
* "copy" command
14+
*/
15+
@js.native
16+
@JSGlobal
17+
class ClipboardItem(items: js.Dictionary[ClipboardItemData], options: ClipboardItemOptions = js.native)
18+
extends js.Object {
19+
def presentationStyle: PresentationStyle = js.native
20+
21+
/** Returns an Array of MIME types available within the ClipboardItem. */
22+
def types: FrozenArray[String] = js.native
23+
24+
/** Returns a Promise that resolves with a Blob of the requested MIME type, or an error if the MIME type is not found.
25+
*/
26+
def getType(`type`: String): js.Promise[Blob] = js.native
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
trait ClipboardItemOptions extends js.Object {
12+
def presentationStyle: js.UndefOr[PresentationStyle] = js.undefined
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
/** A frozen array type is a parameterized type whose values are references to objects that hold a fixed length array of
12+
* unmodifiable values. The values in the array are of type T.
13+
*
14+
* Since FrozenArray<T> values are references, they are unlike sequence types, which are lists of values that are
15+
* passed by value.
16+
*/
17+
@js.native
18+
trait FrozenArray[+T] extends js.Iterable[T] {
19+
val length: Int = js.native
20+
21+
@js.annotation.JSBracketAccess
22+
def apply(index: Int): T = js.native
23+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ package object dom {
114114
val webcrypto: Crypto = js.native
115115

116116
type BlobPart = BufferSource | Blob | String
117+
118+
type ClipboardItemData = js.Promise[String | Blob]
117119
}

0 commit comments

Comments
 (0)