From 567c1e3857a998ad6be9bb3d0b20ebe8095ec0f0 Mon Sep 17 00:00:00 2001 From: zetashift Date: Sat, 20 Aug 2022 12:55:04 +0200 Subject: [PATCH 1/4] Add ScrollRestoration facade --- api-reports/2_12.txt | 4 ++++ api-reports/2_13.txt | 4 ++++ .../org/scalajs/dom/ScrollRestoration.scala | 15 +++++++++++++++ .../org/scalajs/dom/ScrollRestoration.scala | 14 ++++++++++++++ dom/src/main/scala/org/scalajs/dom/History.scala | 11 +++++++++++ 5 files changed, 48 insertions(+) create mode 100644 dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala create mode 100644 dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 0c7e86bb3..c60d6fe8f 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -14486,6 +14486,7 @@ History[JC] def pushState(statedata: js.Any, title: String): Unit History[JC] def pushState(statedata: js.Any, title: String, url: String): Unit History[JC] def replaceState(statedata: js.Any, title: String): Unit History[JC] def replaceState(statedata: js.Any, title: String, url: String): Unit +History[JC] var scrollRestoration: ScrollRestoration History[JC] def state: js.Any HkdfCtrParams[JT] val context: BufferSource HkdfCtrParams[JT] val hash: HashAlgorithmIdentifier @@ -24703,6 +24704,9 @@ Screen[JC] def colorDepth: Int Screen[JC] def height: Double Screen[JC] def pixelDepth: Int Screen[JC] def width: Double +ScrollRestoration[JT] +ScrollRestoration[SO] val auto: ScrollRestoration +ScrollRestoration[SO] val manual: ScrollRestoration Selection[JC] def addRange(range: Range): Unit Selection[JC] def anchorNode: Node Selection[JC] def anchorOffset: Int diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 0c7e86bb3..c60d6fe8f 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -14486,6 +14486,7 @@ History[JC] def pushState(statedata: js.Any, title: String): Unit History[JC] def pushState(statedata: js.Any, title: String, url: String): Unit History[JC] def replaceState(statedata: js.Any, title: String): Unit History[JC] def replaceState(statedata: js.Any, title: String, url: String): Unit +History[JC] var scrollRestoration: ScrollRestoration History[JC] def state: js.Any HkdfCtrParams[JT] val context: BufferSource HkdfCtrParams[JT] val hash: HashAlgorithmIdentifier @@ -24703,6 +24704,9 @@ Screen[JC] def colorDepth: Int Screen[JC] def height: Double Screen[JC] def pixelDepth: Int Screen[JC] def width: Double +ScrollRestoration[JT] +ScrollRestoration[SO] val auto: ScrollRestoration +ScrollRestoration[SO] val manual: ScrollRestoration Selection[JC] def addRange(range: Range): Unit Selection[JC] def anchorNode: Node Selection[JC] def anchorOffset: Int diff --git a/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala b/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala new file mode 100644 index 000000000..6e63ca0ed --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala @@ -0,0 +1,15 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait ScrollRestoration extends js.Any + +/** + * see [[https://html.spec.whatwg.org/multipage/history.html#the-history-interface]] + * which contains the spec for ScrollRestoration + */ +object ScrollRestoration { + val auto: ScrollRestoration = "auto".asInstanceOf[ScrollRestoration] + val manual: ScrollRestoration = "manual".asInstanceOf[ScrollRestoration] +} \ No newline at end of file diff --git a/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala new file mode 100644 index 000000000..f996902d1 --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala @@ -0,0 +1,14 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type ScrollRestoration <: String = String + +/** + * see [[https://html.spec.whatwg.org/multipage/history.html#the-history-interface]] + * which contains the spec for ScrollRestoration + */ +object ScrollRestoration { + val auto: ScrollRestoration = "auto" + val manual: ScrollRestoration = "manual" +} \ No newline at end of file diff --git a/dom/src/main/scala/org/scalajs/dom/History.scala b/dom/src/main/scala/org/scalajs/dom/History.scala index 83219f1d6..b2aad9920 100644 --- a/dom/src/main/scala/org/scalajs/dom/History.scala +++ b/dom/src/main/scala/org/scalajs/dom/History.scala @@ -71,4 +71,15 @@ class History extends js.Object { * safely passed. */ def pushState(statedata: js.Any, title: String): Unit = js.native + + /** The scrollRestoration property of History interface allows web applications to explicitly set default scroll + * restoration behavior on history navigation. + * + * Can have onne of the followings values: + * + * auto: The location on the page to which the user has scrolled will be restored. + * + * manual: The location on the page is not restored. The user will have to scroll to the location manually. + */ + var scrollRestoration: ScrollRestoration = js.native } From a64b7c28880a1de8b3ad5a10690cbe5bc6d08eae Mon Sep 17 00:00:00 2001 From: zetashift Date: Sat, 20 Aug 2022 13:10:53 +0200 Subject: [PATCH 2/4] Better doc comments for Scroll Restoration Co-authored-by: Arman Bilge --- dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala index f996902d1..d42dab8f3 100644 --- a/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala +++ b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala @@ -9,6 +9,8 @@ opaque type ScrollRestoration <: String = String * which contains the spec for ScrollRestoration */ object ScrollRestoration { + /** The location on the page to which the user has scrolled will be restored. */ val auto: ScrollRestoration = "auto" + /** The location on the page is not restored. The user will have to scroll to the location manually. */ val manual: ScrollRestoration = "manual" } \ No newline at end of file From 01d7e06d1d30dba6c88a7a8c6e2c25b6fb65cfde Mon Sep 17 00:00:00 2001 From: zetashift Date: Sat, 20 Aug 2022 13:11:21 +0200 Subject: [PATCH 3/4] Better doc comment for History.scrollRestoration Co-authored-by: Arman Bilge --- dom/src/main/scala/org/scalajs/dom/History.scala | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/dom/src/main/scala/org/scalajs/dom/History.scala b/dom/src/main/scala/org/scalajs/dom/History.scala index b2aad9920..0fcd918c4 100644 --- a/dom/src/main/scala/org/scalajs/dom/History.scala +++ b/dom/src/main/scala/org/scalajs/dom/History.scala @@ -72,14 +72,8 @@ class History extends js.Object { */ def pushState(statedata: js.Any, title: String): Unit = js.native - /** The scrollRestoration property of History interface allows web applications to explicitly set default scroll + /** The `scrollRestoration` property of [[History]] interface allows web applications to explicitly set default scroll * restoration behavior on history navigation. - * - * Can have onne of the followings values: - * - * auto: The location on the page to which the user has scrolled will be restored. - * - * manual: The location on the page is not restored. The user will have to scroll to the location manually. */ var scrollRestoration: ScrollRestoration = js.native } From c11aedf7bcd0a0c46c723246e99033ee28e3b086 Mon Sep 17 00:00:00 2001 From: zetashift Date: Sun, 21 Aug 2022 01:34:37 +0200 Subject: [PATCH 4/4] Also scaladoc comment for the scala 2 enum --- dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala | 4 +++- dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala b/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala index 6e63ca0ed..751cd4904 100644 --- a/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala +++ b/dom/src/main/scala-2/org/scalajs/dom/ScrollRestoration.scala @@ -10,6 +10,8 @@ sealed trait ScrollRestoration extends js.Any * which contains the spec for ScrollRestoration */ object ScrollRestoration { + /** The location on the page to which the user has scrolled will be restored. */ val auto: ScrollRestoration = "auto".asInstanceOf[ScrollRestoration] + /** The location on the page is not restored. The user will have to scroll to the location manually. */ val manual: ScrollRestoration = "manual".asInstanceOf[ScrollRestoration] -} \ No newline at end of file +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala index d42dab8f3..5eb2e14ee 100644 --- a/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala +++ b/dom/src/main/scala-3/org/scalajs/dom/ScrollRestoration.scala @@ -13,4 +13,4 @@ object ScrollRestoration { val auto: ScrollRestoration = "auto" /** The location on the page is not restored. The user will have to scroll to the location manually. */ val manual: ScrollRestoration = "manual" -} \ No newline at end of file +}