Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
(build): update deps (#28)
Browse files Browse the repository at this point in the history
* update deps (mainly ce3 and javafx)
* async IO for jfx ops

Co-authored-by: Andreas Drobisch <[email protected]>
  • Loading branch information
adrobisch and Andreas Drobisch authored Nov 13, 2021
1 parent eed5543 commit dedca09
Show file tree
Hide file tree
Showing 29 changed files with 351 additions and 267 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ Issues

from JavaFX: https://bugs.openjdk.java.net/browse/JDK-8251240
workaround for that: `-Djdk.gtk.version=2`

10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ lazy val editor = (crossProject(JVMPlatform, JSPlatform) in file(".") / "editor"
"io.circe" %%% "circe-generic",
"io.circe" %%% "circe-parser"
).map(_ % circeVersion),
libraryDependencies += "org.typelevel" %%% "cats-effect" % "2.5.1",
libraryDependencies += "org.typelevel" %%% "cats-effect" % "3.2.9",
libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.9.4",
libraryDependencies += "com.codecommit" %% "cats-effect-testing-scalatest" % "0.5.4" % Test
libraryDependencies += "org.typelevel" %% "cats-effect-testing-scalatest" % "1.3.0" % Test
).dependsOn(core, graphml, json, cats)

lazy val editorJS = editor.js.settings(
Expand All @@ -138,13 +138,13 @@ lazy val osName = System.getProperty("os.name") match {
lazy val javaFXModules = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")

lazy val editorJVM = editor.jvm.settings(
libraryDependencies += "org.scalafx" %% "scalafx" % "14-R19",
libraryDependencies += "org.scalafx" %% "scalafx" % "15.0.1-R21",
libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "0.10.5",
libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.14.0",
libraryDependencies += "org.apache.logging.log4j" % "log4j-core" % "2.14.0",
libraryDependencies += "org.apache.xmlgraphics" % "batik-rasterizer" % "1.13",
libraryDependencies += "org.apache.xmlgraphics" % "batik-rasterizer" % "1.14",
libraryDependencies ++= javaFXModules.map( m =>
"org.openjfx" % s"javafx-$m" % "14.0.1" classifier osName
"org.openjfx" % s"javafx-$m" % "15.0.1" classifier osName
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.flowtick.graphs.editor

import scala.scalajs.js.annotation.JSExport
import cats.effect.unsafe.implicits.global

class EditorInstanceJs(val messageBus: EditorMessageBus) {
@JSExport
def execute(commandJson: String): Unit =
io.circe.parser.decode[EditorCommand](commandJson) match {
case Right(command) => messageBus.publish(command).unsafeRunSync()
case Right(command) => messageBus.publish(command).unsafeToFuture()
case Left(error) =>
println("unable to execute command:", error)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.flowtick.graphs.editor

import cats.effect.IO
import cats.effect.unsafe.implicits.global

import org.scalajs.dom.Event

import scala.scalajs.js
import scala.scalajs.js.{JSON, undefined}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.concurrent.Future

@JSExportTopLevel("graphs")
object EditorMainJs extends EditorMain {
Expand All @@ -16,7 +19,7 @@ object EditorMainJs extends EditorMain {
optionsObj: js.UndefOr[js.Object],
menuContainerId: js.UndefOr[String] = undefined,
paletteContainerId: js.UndefOr[String] = undefined
): EditorInstanceJs = (for {
): Future[EditorInstanceJs] = (for {
options <- optionsObj.toOption
.map(obj => IO.fromEither(EditorConfiguration.decode(obj.toString)))
.getOrElse(IO.pure(EditorConfiguration()))
Expand Down Expand Up @@ -47,7 +50,7 @@ object EditorMainJs extends EditorMain {
),
IO.pure
)
.unsafeRunSync()
.unsafeToFuture()

def main(args: Array[String]): Unit = {
println("graphs loaded...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scalatags.JsDom.all._
import scala.scalajs.js

class EditorMenuJs(menuContainerId: String)(val messageBus: EditorMessageBus) extends EditorMenu {
import cats.effect.unsafe.implicits.global

override def order: Double = 0.6

Expand Down Expand Up @@ -118,7 +119,7 @@ class EditorMenuJs(menuContainerId: String)(val messageBus: EditorMessageBus) ex
reader.onload = (_: Event) =>
messageBus
.publish(Load(reader.result.toString, format))
.unsafeRunSync()
.unsafeToFuture()
reader.readAsText(file)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.effect.IO
import com.flowtick.graphs.editor.view._
import org.scalajs.dom
import org.scalajs.dom.raw._
import cats.effect.unsafe.implicits.global

object EditorDomEventLike extends EventLike[Event, dom.Element] {
override def target(event: Event): dom.Element =
Expand Down Expand Up @@ -71,46 +72,56 @@ object EditorPageJs {
renderer.graphSVG.root.addEventListener(
"mousedown",
(e: MouseEvent) => {
page.startDrag(e) match {
case Some(_) => // we already have a selection
case None =>
page.click(e).foreach { clicked =>
handleSelect(clicked)(e.ctrlKey).unsafeRunSync()
}
}
page
.startDrag(e)
.flatMap {
case Some(_) => IO.unit // we already have a selection
case None =>
page.click(e).flatMap {
case Some(clicked) => handleSelect(clicked)(e.ctrlKey)
case None => IO.unit
}
}
.unsafeToFuture()
}
)

renderer.graphSVG.root.addEventListener("mousemove", page.drag)
renderer.graphSVG.root.addEventListener(
"mouseup",
(e: MouseEvent) => {
val drag = page.endDrag(e)
handleDrag(drag).unsafeRunSync()

// handle up as a selection if we did not drag more the one pixel
drag match {
case Some(drag) if Math.abs(drag.deltaX) < 2 && Math.abs(drag.deltaY) < 2 =>
page.click(e).foreach { element =>
handleSelect(element)(false).unsafeRunSync()
(e: MouseEvent) =>
{
for {
drag <- page.endDrag(e)
_ <- handleDrag(drag).attempt
result <- drag match {
case Some(drag) if Math.abs(drag.deltaX) < 2 && Math.abs(drag.deltaY) < 2 =>
page.click(e).flatMap {
case Some(element) => handleSelect(element)(false)
case None => IO.unit
}
case _ => IO.unit
}
case _ =>
}
}
} yield result
}.unsafeToFuture()
)

renderer.graphSVG.root.addEventListener(
"mouseleave",
(e: MouseEvent) => {
page.stopPan(e)
handleDrag(page.endDrag(e))
}
(e: MouseEvent) =>
{
for {
_ <- page.stopPan(e)
drag <- page.endDrag(e)
result <- handleDrag(drag)
} yield result
}.unsafeToFuture()
)

renderer.graphSVG.root.addEventListener(
"dblclick",
(e: MouseEvent) => {
handleDoubleClick(e).unsafeRunSync()
handleDoubleClick(e).unsafeToFuture()
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.flowtick.graphs.style.ImageSpec
import org.scalajs.dom.html.{Button, Div, UList}
import org.scalajs.dom.raw.{Event, HTMLElement}
import scalatags.JsDom.all._
import cats.effect.unsafe.implicits.global

class EditorPaletteJs(paletteElementId: String)(
val messageBus: EditorMessageBus
Expand Down Expand Up @@ -119,7 +120,7 @@ class EditorPaletteJs(paletteElementId: String)(
onclick := ((_: Event) =>
messageBus
.publish(EditorToggle(EditorToggle.paletteKey, Some(false)))
.unsafeRunSync()
.unsafeToFuture()
)
).render

Expand Down
Loading

0 comments on commit dedca09

Please sign in to comment.