diff --git a/.scalafmt.conf b/.scalafmt.conf index dd74f0989..632748292 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.6.0 +version = 3.6.1 runner.dialect = scala213source3 project.git = true style = Scala.js diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index a96232668..3f80f8603 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -25158,7 +25168,7 @@ StyleSheetList[JC] def item(index: Int): StyleSheet StyleSheetList[JC] def length: Int StyleSheetList[JC] @scala.scalajs.js.annotation.JSBracketAccess def update(index: Int, v: StyleSheet): Unit SubtleCrypto[JT] def decrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): js.Promise[js.Any] -SubtleCrypto[JT] def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: Double): js.Promise[js.Any] +SubtleCrypto[JT] def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: Double): js.Promise[ArrayBuffer] SubtleCrypto[JT] def deriveKey(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, derivedKeyType: KeyAlgorithmIdentifier, extractable: Boolean, keyUsages: js.Array[KeyUsage]): js.Promise[js.Any] SubtleCrypto[JT] def digest(algorithm: HashAlgorithmIdentifier, data: BufferSource): js.Promise[js.Any] SubtleCrypto[JT] def encrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): js.Promise[js.Any] @@ -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 diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index a96232668..3f80f8603 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -25158,7 +25168,7 @@ StyleSheetList[JC] def item(index: Int): StyleSheet StyleSheetList[JC] def length: Int StyleSheetList[JC] @scala.scalajs.js.annotation.JSBracketAccess def update(index: Int, v: StyleSheet): Unit SubtleCrypto[JT] def decrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): js.Promise[js.Any] -SubtleCrypto[JT] def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: Double): js.Promise[js.Any] +SubtleCrypto[JT] def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: Double): js.Promise[ArrayBuffer] SubtleCrypto[JT] def deriveKey(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, derivedKeyType: KeyAlgorithmIdentifier, extractable: Boolean, keyUsages: js.Array[KeyUsage]): js.Promise[js.Any] SubtleCrypto[JT] def digest(algorithm: HashAlgorithmIdentifier, data: BufferSource): js.Promise[js.Any] SubtleCrypto[JT] def encrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): js.Promise[js.Any] @@ -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 diff --git a/build.sbt b/build.sbt index 4725f5357..507ef83ed 100644 --- a/build.sbt +++ b/build.sbt @@ -13,4 +13,5 @@ val testsChrome = Build.testsChrome val testsFirefox = Build.testsFirefox val testsNodeJsdom = Build.testsNodeJsdom val example = Build.example -val readme = Build.readme +val jsdocs = Build.jsdocs +val docs = Build.docs diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 000000000..166c4eb9a --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,183 @@ +## scala-js-dom + +--- + +#### Statically typed DOM API for Scala.js + +Scala-js-dom provides a nice statically typed interface to the DOM such that it can be called from Scala code without resorting to `js.Dynamic`. +All javascript globals functions, singletons and classes are members of the `org.scalajs.dom`, +`org.scalajs.dom.html`, `org.scalajs.dom.svg`, etc. packages. + +For example: + +```scala +import org.scalajs.dom + +def main() = dom.window.alert("Hi from scala-js-dom!") +``` + +## Usage + +Add the following to your sbt build definition: + +```scala +libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "@VERSION@" +``` + +then enjoy the types available in org.scalajs.dom. scalajs-dom @VERSION@ is built and published for Scala.js 1.5+ with Scala 2.11, 2.12, 2.13, and 3.0+. + +To begin with, scala-js-dom organizes the full-list of DOM APIs into a number of buckets: + +- dom.html: HTML element APIs +- dom.svg: SVG element APIs +- dom.idb: IndexedDB APIs +- dom.css: CSS APIs +- dom: Miscellanious, unclassified APIs + +Most names have been shortened from names of the raw browser APIs, since the namespacing avoids collisions. By convention these types are imported qualified: e.g. as `html.Canvas` instead of directly as `Canvas`. There is also the `dom.raw` namespace which contains everything with their full, un-shortened name. + +## Examples + +You can start using the bindings using the following import: + +```scala mdoc:js:shared +import org.scalajs.dom._ +``` + +### Appending a child to a `Node` + +```scala mdoc:js:shared +def appendElement(div: html.Div): Unit = { + val child = document.createElement("div") + child.textContent = "I can add elements to DOM elements!" + div.appendChild(child) +} +``` + +```scala mdoc:js:invisible +
+ +--- +document.getElementById("demo1").addEventListener("click", (ev: Event) => { + appendElement(document.getElementById("outer-container").asInstanceOf[html.Div]) +}) +``` + +### Add an EventListener for `onmousemove` + +```scala mdoc:js +def showOnMouseCoordinates(pre: html.Pre): Unit = { + pre.onmousemove = (ev: MouseEvent) => + pre.textContent = s""" + |ev.clientX: ${ev.clientX} + |ev.clientY: ${ev.clientY} + |ev.pageX: ${ev.pageX} + |ev.screenX: ${ev.screenX} + |ev.screenY: ${ev.screenY} + """.stripMargin +} +``` + +### Storing an item in `localStorage` + +```scala mdoc:js +def storeInputInLocalStorage(input: html.Input, box: html.Div) = { + val key = "myKey" + input.value = window.localStorage.getItem(key) + + input.onkeyup = { (e: Event) => + window.localStorage.setItem( + key, input.value + ) + + box.textContent = s"Saved: ${input.value} to local storage!" + } +} +``` + +### Using `Canvas` to draw + +```scala mdoc:js +type Context2D = CanvasRenderingContext2D + +def drawCuteSmiley(canvas: html.Canvas) = { + val context = canvas.getContext("2d").asInstanceOf[Context2D] + + val size = 300 + canvas.width = size + canvas.height = size + + context.strokeStyle = "red" + context.lineWidth = 3 + context.beginPath() + context.moveTo(size/3, 0) + context.lineTo(size/3, size/3) + context.moveTo(size*2/3, 0) + context.lineTo(size*2/3, size/3) + context.moveTo(size, size/2) + context.arc(size/2, size/2, size/2, 0, 3.14) + + context.stroke() +} +``` + +### Using `Fetch` to make API calls in the browser + +```scala mdoc:js +import scala.concurrent.ExecutionContext.Implicits.global + +def fetchBoredApi(element: html.Pre) = { + val url = + "https://www.boredapi.com/api/activity" + + val responseText = for { + response <- fetch(url).toFuture + text <- response.text().toFuture + } yield { + text + } + + for (text <- responseText) + element.textContent = text +} +``` + +### Using Websockets + +```scala mdoc:js +// TODO: currently crashes with an error +// def echoWebSocket(input: html.Input, pre: html.Pre) = { +// val echo = "wss://echo.websocket.org" +// val socket = new WebSocket(echo) + +// socket.onmessage = { +// (e: MessageEvent) => +// pre.textContent += +// e.data.toString +// } + +// socket.onopen = { (e: Event) => +// input.onkeyup = { (e: Event) => +// socket.send(input.value) +// } +// } +// } +``` + +### Styling an HTML element + +```scala mdoc:js +def changeColor(div: html.Div) = { + val colors = Seq("red", "green", "blue") + + val index = util.Random.nextInt(colors.length) + + div.style.color = colors(index) +} +``` + +## Contributing + +The DOM API is always evolving, and `scala-js-dom` tries to provide a thin-but-idiomatic Scala interface to modern browser APIs, without breaking the spec. + +If you see something that you think can be improved, feel free to send a pull request. See our [Contributing Guide](https://github.com/scala-js/scala-js-dom/blob/main/CONTRIBUTING.md) for a detailed overview for starting hacking on `scala-js-dom` and making a PR! diff --git a/dom/src/main/scala-2/org/scalajs/dom/PresentationStyle.scala b/dom/src/main/scala-2/org/scalajs/dom/PresentationStyle.scala new file mode 100644 index 000000000..0d1c69f69 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/PresentationStyle.scala @@ -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] +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/PresentationStyle.scala b/dom/src/main/scala-3/org/scalajs/dom/PresentationStyle.scala new file mode 100644 index 000000000..1c09ad1ab --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/PresentationStyle.scala @@ -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" +} \ No newline at end of file diff --git a/dom/src/main/scala/org/scalajs/dom/Body.scala b/dom/src/main/scala/org/scalajs/dom/Body.scala index 0b9cf0453..3e472ea70 100644 --- a/dom/src/main/scala/org/scalajs/dom/Body.scala +++ b/dom/src/main/scala/org/scalajs/dom/Body.scala @@ -22,9 +22,7 @@ trait Body extends js.Object { /** Takes a Response stream and reads it to completion. It returns a promise that resolves with a FormData object. */ def formData(): js.Promise[FormData] = js.native - /** Takes a Response stream and reads it to completion. It returns a promise that resolves with a JSON object. //todo: - * define the JSON type, and return a Promise[JSON] as per spec - */ + /** Takes a Response stream and reads it to completion. It returns a promise that resolves with a JSON object. */ def json(): js.Promise[js.Any] = js.native /** Takes a Response stream and reads it to completion. It returns a promise that resolves with a USVString (text). */ diff --git a/dom/src/main/scala/org/scalajs/dom/Clipboard.scala b/dom/src/main/scala/org/scalajs/dom/Clipboard.scala index e07c4ed6d..bdb6b0e92 100644 --- a/dom/src/main/scala/org/scalajs/dom/Clipboard.scala +++ b/dom/src/main/scala/org/scalajs/dom/Clipboard.scala @@ -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. @@ -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 diff --git a/dom/src/main/scala/org/scalajs/dom/ClipboardItem.scala b/dom/src/main/scala/org/scalajs/dom/ClipboardItem.scala new file mode 100644 index 000000000..bf7203759 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ClipboardItem.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._ + +/** 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 + +} diff --git a/dom/src/main/scala/org/scalajs/dom/ClipboardItemOptions.scala b/dom/src/main/scala/org/scalajs/dom/ClipboardItemOptions.scala new file mode 100644 index 000000000..04921d2a9 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ClipboardItemOptions.scala @@ -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 +} diff --git a/dom/src/main/scala/org/scalajs/dom/FrozenArray.scala b/dom/src/main/scala/org/scalajs/dom/FrozenArray.scala new file mode 100644 index 000000000..eb3848e15 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FrozenArray.scala @@ -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 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 +} diff --git a/dom/src/main/scala/org/scalajs/dom/SubtleCrypto.scala b/dom/src/main/scala/org/scalajs/dom/SubtleCrypto.scala index b4a224bb9..2b2349983 100644 --- a/dom/src/main/scala/org/scalajs/dom/SubtleCrypto.scala +++ b/dom/src/main/scala/org/scalajs/dom/SubtleCrypto.scala @@ -1,6 +1,7 @@ package org.scalajs.dom import scala.scalajs.js +import scala.scalajs.js.typedarray.ArrayBuffer /** [[http://www.w3.org/TR/WebCryptoAPI/#subtlecrypto-interface w3c ¶14 Subtle Crytpo interface]] * @@ -72,7 +73,8 @@ trait SubtleCrypto extends js.Object { * * Defined at [[http://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-deriveBits ¶14.3.8 The deriveBits method]] */ - def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: Double): js.Promise[js.Any] = js.native + def deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, + length: Double): js.Promise[ArrayBuffer] = js.native /** Returns a Promise of a CryptoKey corresponding to the format, the algorithm, the raw key data, the usages and the * extractability given as parameters. diff --git a/dom/src/main/scala/org/scalajs/dom/package.scala b/dom/src/main/scala/org/scalajs/dom/package.scala index a17cd5c33..95bf272d9 100644 --- a/dom/src/main/scala/org/scalajs/dom/package.scala +++ b/dom/src/main/scala/org/scalajs/dom/package.scala @@ -114,4 +114,6 @@ package object dom { val webcrypto: Crypto = js.native type BlobPart = BufferSource | Blob | String + + type ClipboardItemData = js.Promise[String | Blob] } diff --git a/prePR.sbt b/prePR.sbt index 100a174e9..03d67c7ec 100644 --- a/prePR.sbt +++ b/prePR.sbt @@ -41,7 +41,7 @@ ThisBuild / prePR_nonCross := Def.sequential( Def.taskDyn { if (scalaVersion.value.startsWith("2.12.")) - Def.task[Unit]((readme / Compile / compile).value) + Def.task[Unit]((docs / Compile / compile).value) else Def.task(()) }, diff --git a/project/Build.scala b/project/Build.scala index bab9374c2..c975d62fe 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -10,11 +10,14 @@ import org.scalajs.jsenv.selenium.SeleniumJSEnv import org.scalajs.sbtplugin.ScalaJSJUnitPlugin import org.scalajs.sbtplugin.ScalaJSPlugin import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ +import mdoc.MdocPlugin +import mdoc.MdocPlugin.autoImport._ import sbtbuildinfo.BuildInfoPlugin import sbtbuildinfo.BuildInfoPlugin.autoImport._ import scalafix.sbt.ScalafixPlugin import scalafix.sbt.ScalafixPlugin.autoImport._ import scalatex.ScalatexReadme +import sbtdynver.DynVerPlugin.autoImport.previousStableVersion import Dependencies._ import Lib._ @@ -141,18 +144,20 @@ object Build { .enablePlugins(ScalaJSPlugin) .configure(commonSettings, crossScala, preventPublication) - lazy val readme = - ScalatexReadme( - projectId = "readme", - wd = file(""), - url = "https://github.com/scala-js/scala-js-dom/tree/main", - source = "Index", - autoResources = Seq("example-opt.js"), - ) - .configure(commonSettings, preventPublication) + lazy val jsdocs = project + .in(file("mdocs-js")) + .dependsOn(dom) + .enablePlugins(ScalaJSPlugin) + .configure(commonSettings, crossScala, preventPublication) + + lazy val docs = project + .in(file("mdocs")) .settings( - scalaVersion := Ver.scala212, - Compile / resources += (example / Compile / fullOptJS).value.data, + mdocJS := Some(jsdocs), + mdocVariables := Map( + "VERSION" -> previousStableVersion.value.getOrElse("2.3.0") + ) ) - + .enablePlugins(MdocPlugin) + .configure(commonSettings, crossScala, preventPublication) } diff --git a/project/build.properties b/project/build.properties index 563a014da..8b9a0b0ab 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.7.2 +sbt.version=1.8.0 diff --git a/project/plugins.sbt b/project/plugins.sbt index 20bb8dc35..ca29f8d5d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,12 @@ libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0" libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "1.1.1" -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") -addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.6" ) +addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")