Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Carlos Quiroz <carlos.m.quiroz@gmail.com>
- Loading branch information
0 parents
commit 33367be
Showing
11 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
updates: | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "monthly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: [main] | ||
tags: ["*"] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2.3.4 | ||
- uses: olafurpg/setup-scala@v10 | ||
- uses: olafurpg/setup-gpg@v3 | ||
- name: Publish | ||
run: | | ||
git status | ||
sbt ci-release | ||
env: | ||
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} | ||
PGP_SECRET: ${{ secrets.PGP_SECRET }} | ||
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2.3.4 | ||
- name: Set up JDK 1.8 | ||
uses: olafurpg/setup-scala@v10 | ||
with: | ||
java-version: 1.8 | ||
- name: Cache dependencies | ||
uses: actions/cache@v2.1.3 | ||
with: | ||
path: ~/.cache/coursier/v1 | ||
key: ${{ runner.os }}-coursier-${{ hashFiles('build.sbt') }}-${{ hashFiles('project/*.scala') }} | ||
restore-keys: ${{ runner.os }}-coursier- | ||
- name: Cache .sbt | ||
uses: actions/cache@v2.1.3 | ||
with: | ||
path: ~/.sbt | ||
key: ${{ runner.os }}-sbt-${{ hashFiles('build.sbt') }}-${{ hashFiles('project/*.scala') }} | ||
restore-keys: ${{ runner.os }}-sbt- | ||
- name: Run compile | ||
run: csbt +compile +test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
*.class | ||
*.log | ||
*.bsp | ||
|
||
# sbt specific | ||
.cache | ||
.history | ||
.lib/ | ||
dist/* | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
project/boot/ | ||
project/plugins/project/ | ||
|
||
# Scala-IDE specific | ||
.scala_dependencies | ||
.worksheet | ||
.idea/ | ||
.vscode/ | ||
.bloop/ | ||
.metals/ | ||
project/metals.sbt | ||
|
||
# Mac OS | ||
.DS_Store | ||
._.DS_Store | ||
**/.DS_Store | ||
**/._.DS_Store | ||
|
||
# Hydra | ||
.hydra/ | ||
gnupg-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
pull_request_rules: | ||
- name: automatically merge scala-steward's PRs | ||
conditions: | ||
- author=geminihlswadmin | ||
- body~=labels:.*semver-patch.* | ||
- status-success=build | ||
actions: | ||
merge: | ||
method: merge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version = "2.7.3" | ||
style = default | ||
|
||
maxColumn = 100 | ||
|
||
// Vertical alignment is pretty, but leads to bigger diffs | ||
align.preset = most | ||
|
||
rewrite.rules = [ | ||
AvoidInfix | ||
RedundantBraces | ||
RedundantParens | ||
AsciiSortImports | ||
PreferCurlyFors | ||
] | ||
|
||
align.tokens.add = [{code = "=>", owner = "Case"}] | ||
align.tokens.add = [{code = ":", owner = "Term.Param"}, "=", "shouldBe", "<-", "^"] | ||
align.openParenCallSite = true | ||
spaces.inImportCurlyBraces = true | ||
|
||
continuationIndent.defnSite = 2 | ||
|
||
docstrings.style = Asterisk | ||
|
||
rewrite.neverInfix.excludeFilters = [until | ||
to | ||
by | ||
eq | ||
ne | ||
"should.*" | ||
"contain.*" | ||
"must.*" | ||
in | ||
be | ||
taggedAs | ||
thrownBy | ||
synchronized | ||
have | ||
when | ||
size | ||
theSameElementsAs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# lucuma-mousetrap | ||
|
||
Facade for [mousetrap](https://github.com/ccampbell/mousetrap) using [ScalablyTyped](https://scalablytyped.org/docs/library-developer) | ||
|
||
It includes a scala.js React component for easier integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* ScalablyTyped configuration */ | ||
enablePlugins(ScalablyTypedConverterGenSourcePlugin) | ||
|
||
Global / onChangedBuildSource := ReloadOnSourceChanges | ||
|
||
inThisBuild( | ||
Seq( | ||
homepage := Some(url("https://github.com/gemini-hlsw/lucuma-mousetrap")), | ||
Global / onChangedBuildSource := ReloadOnSourceChanges | ||
) ++ lucumaPublishSettings | ||
) | ||
|
||
lazy val root = project | ||
.in(file(".")) | ||
.settings(name := "lucuma-mousetrap") | ||
.settings( | ||
// shade into another package | ||
stOutputPackage := "lucuma.mt", | ||
/* javascript / typescript deps */ | ||
Compile / npmDependencies ++= Seq( | ||
"mousetrap" -> "1.6.5", | ||
"@types/mousetrap" -> "1.6.5" | ||
), | ||
stSourceGenMode := SourceGenMode.ResourceGenerator, | ||
/* disabled because it somehow triggers many warnings */ | ||
scalaJSLinkerConfig ~= (_.withSourceMap(false)), | ||
// because npm is slow | ||
useYarn := true, | ||
stUseScalaJsDom := true, | ||
scalacOptions ~= (_.filterNot( | ||
Set( | ||
// By necessity facades will have unused params | ||
"-Wdead-code", | ||
"-Wunused:params", | ||
"-Wunused:imports", | ||
"-Wunused:explicits" | ||
) | ||
)), | ||
sources in (Compile, doc) := Seq(), | ||
// focus only on these libraries | ||
stMinimize := Selection.AllExcept("mousetrap"), | ||
libraryDependencies ++= Seq( | ||
"com.github.japgolly.scalajs-react" %%% "core" % "1.7.7", | ||
"io.github.cquiroz.react" %%% "common" % "0.11.2" | ||
) | ||
) | ||
.settings(lucumaScalaJsSettings: _*) | ||
.enablePlugins(ScalablyTypedConverterGenSourcePlugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 1.4.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resolvers += Resolver.bintrayRepo("oyvindberg", "converter") | ||
|
||
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta29") | ||
|
||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") | ||
|
||
addSbtPlugin("edu.gemini" % "sbt-lucuma" % "0.3.3") | ||
|
||
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package lucuma | ||
|
||
import japgolly.scalajs.react._ | ||
import japgolly.scalajs.react.vdom.html_<^._ | ||
import react.common._ | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSImport | ||
import lucuma.mt.mousetrap.mod.ExtendedKeyboardEvent | ||
|
||
package object mousetrap { | ||
|
||
val Mousetrap = lucuma.mt.mousetrap.mod.^ | ||
type CallbackFn = js.Function2[ /* e */ ExtendedKeyboardEvent, /* combo */ String, Unit] | ||
|
||
implicit class CallbackOps(cb: Callback) { | ||
def toCBF: CallbackFn = (_: ExtendedKeyboardEvent, _: String) => cb.runNow() | ||
} | ||
} | ||
|
||
package mousetrap { | ||
|
||
/** | ||
* Wraps a component in some keyboard bindings | ||
*/ | ||
final case class ReactMousetrap( | ||
bindings: Map[String, Callback] | ||
) extends ReactPropsWithChildren[ReactMousetrap](ReactMousetrap.component) { | ||
@inline def render: Seq[CtorType.ChildArg] => VdomElement = | ||
ReactMousetrap.component(this) | ||
} | ||
|
||
object ReactMousetrap { | ||
type Props = ReactMousetrap | ||
|
||
val component = ScalaComponent | ||
.builder[Props] | ||
.stateless | ||
.render_C(c => c) | ||
.componentDidMount { $ => | ||
Callback($.props.bindings.foreach { case (k, cb) => Mousetrap.bind(k, cb.toCBF) }) | ||
} | ||
.componentWillUnmount { $ => | ||
Callback($.props.bindings.foreach { case (k, _) => Mousetrap.unbind(k) }) | ||
} | ||
.build | ||
} | ||
} |