From 3480edae2b4bb165f3002dfdfd0d736c02b5fa1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 11 Feb 2024 18:11:07 +0000 Subject: [PATCH 1/3] Update scala-js-dom [Cherry-picked 5e0dfba9374f4d20a68fc1f849ded694bb6a5ee8] --- project/Build.scala | 4 ++-- .../content-contributors/ContentContributors.scala | 13 +++++++------ .../main/src/searchbar/SearchbarComponent.scala | 8 ++++---- .../searchbar/engine/InkuireJSSearchEngine.scala | 1 - .../src/versions-dropdown/DropdownHandler.scala | 7 ++++--- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 3c3c04408b84..50f2cc8cb6f3 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1476,7 +1476,7 @@ object Build { lazy val `scaladoc-js-common` = project.in(file("scaladoc-js/common")). enablePlugins(DottyJSPlugin). dependsOn(`scala3-library-bootstrappedJS`). - settings(libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)) + settings(libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "2.8.0")) lazy val `scaladoc-js-main` = project.in(file("scaladoc-js/main")). enablePlugins(DottyJSPlugin). @@ -1492,7 +1492,7 @@ object Build { settings( Test / fork := false, scalaJSUseMainModuleInitializer := true, - libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13) + libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "2.8.0") ) def generateDocumentation(configTask: Def.Initialize[Task[GenerationConfig]]) = diff --git a/scaladoc-js/contributors/src/content-contributors/ContentContributors.scala b/scaladoc-js/contributors/src/content-contributors/ContentContributors.scala index 2e10e4fae0fa..1db7973b3129 100644 --- a/scaladoc-js/contributors/src/content-contributors/ContentContributors.scala +++ b/scaladoc-js/contributors/src/content-contributors/ContentContributors.scala @@ -5,9 +5,10 @@ import org.scalajs.dom.ext._ import scala.util.matching.Regex._ import scala.util.matching._ -import org.scalajs.dom.ext.Ajax -import scala.scalajs.js.JSON +import org.scalajs.dom._ import scala.scalajs.js +import scala.scalajs.js.JSON +import scala.scalajs.js.Thenable.Implicits.thenable2future import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future @@ -55,8 +56,8 @@ class ContentContributors: def linkForFilename(filename: String) = githubContributorsUrl() + s"/commits?path=$filename" def getAuthorsForFilename(filename: String): Future[List[FullAuthor]] = { val link = linkForFilename(filename) - Ajax.get(link).map(_.responseText).flatMap { json => - val res = JSON.parse(json).asInstanceOf[Commits] + fetch(link).flatMap(_.json()).flatMap { json => + val res = json.asInstanceOf[Commits] val authors = res.map { commit => commit.author match case null => @@ -79,8 +80,8 @@ class ContentContributors: } } def findRename(link: String, filename: String): Future[Option[String]] = { - Ajax.get(link).map(_.responseText).map { json => - val res = JSON.parse(json).asInstanceOf[CommitDescription] + fetch(link).flatMap(_.json()).map { json => + val res = json.asInstanceOf[CommitDescription] val files = res.files files .find(_.filename == filename) diff --git a/scaladoc-js/main/src/searchbar/SearchbarComponent.scala b/scaladoc-js/main/src/searchbar/SearchbarComponent.scala index 010129eb9f59..02473ecccd55 100644 --- a/scaladoc-js/main/src/searchbar/SearchbarComponent.scala +++ b/scaladoc-js/main/src/searchbar/SearchbarComponent.scala @@ -148,7 +148,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc val htmlEntries = results.map(result => result.pageEntry.toHTML(result.indices)) val loadMoreElement = createLoadMoreElement - def loadMoreResults(entries: List[raw.HTMLElement]): Unit = { + def loadMoreResults(entries: List[HTMLElement]): Unit = { loadMoreElement.onclick = (event: Event) => { entries.take(resultsChunkSize).foreach(_.classList.remove("hidden")) val nextElems = entries.drop(resultsChunkSize) @@ -192,7 +192,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc } } - def createLoadingAnimation: raw.HTMLElement = + def createLoadingAnimation: HTMLElement = div(cls := "loading-wrapper")( div(cls := "loading") ) @@ -346,7 +346,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc val selectedElement = resultsDiv.querySelector("[selected]") if selectedElement != null then { selectedElement.removeAttribute("selected") - def recur(elem: raw.Element): raw.Element = { + def recur(elem: Element): Element = { val prev = elem.previousElementSibling if prev == null then null else { @@ -366,7 +366,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc } private def handleArrowDown() = { val selectedElement = resultsDiv.querySelector("[selected]") - def recur(elem: raw.Element): raw.Element = { + def recur(elem: Element): Element = { val next = elem.nextElementSibling if next == null then null else { diff --git a/scaladoc-js/main/src/searchbar/engine/InkuireJSSearchEngine.scala b/scaladoc-js/main/src/searchbar/engine/InkuireJSSearchEngine.scala index 2dde7178e3f7..75cf6f43a907 100644 --- a/scaladoc-js/main/src/searchbar/engine/InkuireJSSearchEngine.scala +++ b/scaladoc-js/main/src/searchbar/engine/InkuireJSSearchEngine.scala @@ -2,7 +2,6 @@ package dotty.tools.scaladoc import scala.io.Source import dotty.tools.scaladoc.PageEntry -import org.scalajs.dom.webworkers.Worker import org.scalajs.dom._ import scala.scalajs.js.{ JSON, Dynamic } import scala.collection.mutable.ListBuffer diff --git a/scaladoc-js/main/src/versions-dropdown/DropdownHandler.scala b/scaladoc-js/main/src/versions-dropdown/DropdownHandler.scala index 465ee44d1ad4..3551b207a246 100644 --- a/scaladoc-js/main/src/versions-dropdown/DropdownHandler.scala +++ b/scaladoc-js/main/src/versions-dropdown/DropdownHandler.scala @@ -7,9 +7,10 @@ import scala.util.{Success,Failure} import org.scalajs.dom._ import org.scalajs.dom.ext._ import scala.scalajs.js.annotation.JSExportTopLevel -import org.scalajs.dom.ext.Ajax +import org.scalajs.dom._ import scala.scalajs.js import scala.scalajs.js.JSON +import scala.scalajs.js.Thenable.Implicits.thenable2future import utils.HTML._ @@ -33,7 +34,7 @@ class DropdownHandler: btn.classList.add("disabled") btn.classList.add("hidden") - private def getURLContent(url: String): Future[String] = Ajax.get(url).map(_.responseText) + private def getURLContent(url: String): Future[String] = fetch(url).flatMap(_.text()) window.sessionStorage.getItem(KEY) match case null => // If no key, returns null @@ -68,7 +69,7 @@ end DropdownHandler def dropdownHandler(e: Event) = e.stopPropagation() if document.getElementById("version-dropdown").getElementsByTagName("a").size > 0 && - window.getSelection.toString.length == 0 then + window.getSelection().toString.length == 0 then document.getElementById("version-dropdown").classList.toggle("expanded") document.getElementById("dropdown-trigger").classList.toggle("selected") From 7c49a900b3e5b9e7fdb6a519ff4a73b6be1b06e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 11 Feb 2024 18:11:34 +0000 Subject: [PATCH 2/3] Load search bar if defined in the query param [Cherry-picked e6b8e75d80597ab02ea2513ce11d37cf9c6bce01] --- .../main/src/searchbar/SearchbarComponent.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scaladoc-js/main/src/searchbar/SearchbarComponent.scala b/scaladoc-js/main/src/searchbar/SearchbarComponent.scala index 02473ecccd55..842b1cb44c23 100644 --- a/scaladoc-js/main/src/searchbar/SearchbarComponent.scala +++ b/scaladoc-js/main/src/searchbar/SearchbarComponent.scala @@ -17,6 +17,9 @@ import java.net.URI class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearchEngine, parser: QueryParser): val initialChunkSize = 5 val resultsChunkSize = 20 + + val querySearch = Option(URLSearchParams(window.location.search).get("search")).filter(_.nonEmpty) + def pathToRoot() = window.document.documentElement.getAttribute("data-pathToRoot") extension (p: PageEntry) def toHTML(boldChars: Set[Int]) = @@ -262,7 +265,8 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc document.body.addEventListener("keydown", (e: KeyboardEvent) => handleGlobalKeyDown(e)) private val inputElem: html.Input = - input(cls := "scaladoc-searchbar-input", `type` := "search", `placeholder`:= "Find anything").tap { element => + val initialValue = querySearch.getOrElse("") + input(cls := "scaladoc-searchbar-input", `type` := "search", `placeholder`:= "Find anything", value := initialValue).tap { element => element.addEventListener("input", { e => clearTimeout(timeoutHandle) val inputValue = e.target.asInstanceOf[html.Input].value @@ -453,3 +457,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc } inputElem.dispatchEvent(new Event("input")) + if (querySearch.isDefined && !document.body.contains(rootDiv)) { + document.body.appendChild(rootDiv) + inputElem.focus() + } From 88142e1c50836699e63cf978180d522f1e2aceac Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 2 Jul 2024 00:37:51 +0200 Subject: [PATCH 3/3] Remove test requiring publicInBinary annotation from LTS backport --- tests/pos-macros/i19526b/Macro.scala | 15 --------------- tests/pos-macros/i19526b/Test.scala | 16 ---------------- 2 files changed, 31 deletions(-) delete mode 100644 tests/pos-macros/i19526b/Macro.scala delete mode 100644 tests/pos-macros/i19526b/Test.scala diff --git a/tests/pos-macros/i19526b/Macro.scala b/tests/pos-macros/i19526b/Macro.scala deleted file mode 100644 index e6861c1986ef..000000000000 --- a/tests/pos-macros/i19526b/Macro.scala +++ /dev/null @@ -1,15 +0,0 @@ -package crash.test - -import scala.language.dynamics - -import scala.quoted.* - -object Export extends Dynamic: - inline def applyDynamic(name: "apply")(inline args: Any*): Stack = ${ - applyDynamicImpl('args) - } - - def applyDynamicImpl(args: Expr[Seq[Any]])(using Quotes): Expr[Stack] = - import quotes.reflect.* - - '{ Stack("", Vector.empty) } diff --git a/tests/pos-macros/i19526b/Test.scala b/tests/pos-macros/i19526b/Test.scala deleted file mode 100644 index 1cc037298e01..000000000000 --- a/tests/pos-macros/i19526b/Test.scala +++ /dev/null @@ -1,16 +0,0 @@ -package crash.test - -case class Stack private[crash] ( - exports: String, - dependsOn: Vector[Int] -) - -object Stack: - @annotation.publicInBinary - private[crash] def apply(exports: String, dependsOn: Vector[Int]): Stack = new Stack(exports, dependsOn) - -trait StackFactory: - val exports: Export.type = Export - - def apply(dependsOn: Int*): Stack = - Export().copy(dependsOn = dependsOn.toVector)