Skip to content

Commit 126e8ed

Browse files
authored
Merge pull request #88 from scalafiddle/version-update
Version update
2 parents 89b8f0c + a05b5c7 commit 126e8ed

26 files changed

+355
-243
lines changed

.scalafmt.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version = 2.3.2
12
style = default
23
align = more
34
maxColumn = 125

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: scala
22
scala:
3-
- 2.12.4
3+
- 2.12.10
44
sudo: false
55
jdk:
6-
- oraclejdk8
6+
- openjdk8
77
script:
88
- sbt ++$TRAVIS_SCALA_VERSION server/test client/test
99
# Tricks to avoid unnecessary cache updates, from

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ You can now start the editor with
2323
which will launch the Play framework, waiting for a connection on 0.0.0.0:9000. At this point you can already navigate to http://localhost:9000 and use the
2424
editor.
2525

26+
If you get errors like `Cannot run program "node": Malformed argument has embedded quote`, you may need to add a
27+
JVM configuration option and restart `sbt`.
28+
```
29+
export JAVA_TOOL_OPTIONS=-Djdk.lang.Process.allowAmbiguousCommands=true
30+
```
31+
2632
Before you can compile anything, you must also start the `router` and `compilerServer` in the other `sbt` session. These are built on Akka-HTTP instead of Play,
2733
so you can run them in the background with
2834

build.sbt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import sbt.Keys._
22
import sbt.Project.projectToRef
3+
import org.scalajs.sbtplugin.ScalaJSPlugin
4+
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
5+
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
36

4-
scalafmtOnCompile in ThisBuild := true
5-
scalafmtVersion in ThisBuild := "1.3.0"
7+
ThisBuild / scalafmtOnCompile := true
68

79
resolvers in ThisBuild += Resolver.jcenterRepo
810

911
// a special crossProject for configuring a JS/JVM/shared structure
10-
lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared"))
12+
lazy val shared = (crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure) in file("shared"))
1113
.settings(
1214
version := Settings.version,
1315
scalaVersion := Settings.versions.scala,

client/src/main/scala/scalafiddle/client/AppCircuit.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ object AppCircuit extends Circuit[AppModel] with ReactConnector[AppModel] {
1919
AppModel(Home, None, fiddleData, ScalaFiddleHelp(ScalaFiddleConfig.helpURL), LoginData(Empty, Empty))
2020

2121
override protected def actionHandler = composeHandlers(
22-
new FiddleHandler(zoomRW(_.fiddleData)((m, v) => m.copy(fiddleData = v)),
23-
zoomRW(_.fiddleId)((m, v) => m.copy(fiddleId = v))),
22+
new FiddleHandler(
23+
zoomRW(_.fiddleData)((m, v) => m.copy(fiddleData = v)),
24+
zoomRW(_.fiddleId)((m, v) => m.copy(fiddleId = v))
25+
),
2426
new CompilerHandler(zoomRW(_.outputData)((m, v) => m.copy(outputData = v))),
2527
new LoginHandler(zoomRW(_.loginData)((m, v) => m.copy(loginData = v))),
2628
navigationHandler
@@ -43,5 +45,5 @@ object AppCircuit extends Circuit[AppModel] with ReactConnector[AppModel] {
4345
Some(ModelUpdateSilent(model.copy(navLocation = page)))
4446
case _ =>
4547
None
46-
}
48+
}
4749
}

client/src/main/scala/scalafiddle/client/AppRouter.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ object AppRouter {
2424
import japgolly.scalajs.react.vdom.Implicits._
2525

2626
(staticRoute(root, Home) ~> render(
27-
fiddleData(d => FiddleEditor(d, None, AppCircuit.zoom(_.outputData), AppCircuit.zoom(_.loginData))))
27+
fiddleData(d => FiddleEditor(d, None, AppCircuit.zoom(_.outputData), AppCircuit.zoom(_.loginData)))
28+
)
2829
| dynamicRouteF(("sf" / string("\\w+") / string(".+")).pmap[EditorPage] { path =>
2930
Some(EditorPage(path._1, Try(path._2.takeWhile(_.isDigit).toInt).getOrElse(0)))
3031
}(page => (page.id, page.version.toString)))(p => Some(p.asInstanceOf[EditorPage])) ~> dynRender((p: EditorPage) => {

client/src/main/scala/scalafiddle/client/Utils.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ object Mousetrap extends js.Object {
8787
def bind(key: String | js.Array[String], f: js.Function1[dom.KeyboardEvent, Boolean], event: String = js.native): Unit =
8888
js.native
8989

90-
def bindGlobal(key: String | js.Array[String],
91-
f: js.Function1[dom.KeyboardEvent, Boolean],
92-
event: String = js.native): Unit = js.native
90+
def bindGlobal(
91+
key: String | js.Array[String],
92+
f: js.Function1[dom.KeyboardEvent, Boolean],
93+
event: String = js.native
94+
): Unit = js.native
9395

9496
def unbind(key: String): Unit = js.native
9597

client/src/main/scala/scalafiddle/client/component/EmbedEditor.scala

+10-6
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,21 @@ object EmbedEditor {
7171
label(`for` := "layout")("Direction"),
7272
div(cls := "field")(
7373
div(cls := "ui radio checkbox")(
74-
input.radio(name := "layout",
75-
checked := state.layout.isInstanceOf[Horizontal],
76-
onChange --> layoutChanged(Horizontal(state.layout.split))),
74+
input.radio(
75+
name := "layout",
76+
checked := state.layout.isInstanceOf[Horizontal],
77+
onChange --> layoutChanged(Horizontal(state.layout.split))
78+
),
7779
label("Horizontal")
7880
)
7981
),
8082
div(cls := "field")(
8183
div(cls := "ui radio checkbox")(
82-
input.radio(name := "layout",
83-
checked := state.layout.isInstanceOf[Vertical],
84-
onChange --> layoutChanged(Vertical(state.layout.split))),
84+
input.radio(
85+
name := "layout",
86+
checked := state.layout.isInstanceOf[Vertical],
87+
onChange --> layoutChanged(Vertical(state.layout.split))
88+
),
8589
label("Vertical")
8690
)
8791
)

client/src/main/scala/scalafiddle/client/component/FiddleEditor.scala

+62-43
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ object FiddleEditor {
2626

2727
case class EditorBinding(name: String, keys: String, action: () => Any)
2828

29-
case class Props(data: ModelProxy[FiddleData],
30-
fiddleId: Option[FiddleId],
31-
outputData: ModelR[AppModel, OutputData],
32-
loginData: ModelR[AppModel, LoginData]) {
29+
case class Props(
30+
data: ModelProxy[FiddleData],
31+
fiddleId: Option[FiddleId],
32+
outputData: ModelR[AppModel, OutputData],
33+
loginData: ModelR[AppModel, LoginData]
34+
) {
3335
def dispatch(a: Action) = data.dispatchCB(a)
3436
}
3537

@@ -96,15 +98,19 @@ object FiddleEditor {
9698
),
9799
div(cls := "ui basic button", onClick --> props.dispatch(SaveFiddle(reconstructSource(state))))(
98100
Icon.pencil,
99-
"Save").when(showSave),
101+
"Save"
102+
).when(showSave),
100103
div(cls := "ui basic button", onClick --> props.dispatch(UpdateFiddle(reconstructSource(state))))(
101104
Icon.pencil,
102-
"Update").when(showUpdate),
105+
"Update"
106+
).when(showUpdate),
103107
div(cls := "ui basic button", onClick --> props.dispatch(ForkFiddle(reconstructSource(state))))(
104108
Icon.codeFork,
105-
"Fork").when(fiddleHasId),
109+
"Fork"
110+
).when(fiddleHasId),
106111
Dropdown("top basic button embed-options", span("Embed", Icon.caretDown))(_ =>
107-
div(cls := "menu", display.block)(EmbedEditor(props.fiddleId.get))).when(fiddleHasId)
112+
div(cls := "menu", display.block)(EmbedEditor(props.fiddleId.get))
113+
).when(fiddleHasId)
108114
),
109115
div(cls := "right")(
110116
div(cls := "ui basic button", onClick --> props.dispatch(ShowHelp(ScalaFiddleConfig.helpURL)))(
@@ -128,7 +134,8 @@ object FiddleEditor {
128134
label("Show template")
129135
)
130136
)
131-
))
137+
)
138+
)
132139
),
133140
div.ref(editorRef = _)(id := "editor")
134141
),
@@ -143,7 +150,7 @@ object FiddleEditor {
143150
width := "100%",
144151
height := "100%",
145152
frameBorder := "0",
146-
sandbox := "allow-scripts allow-popups allow-popups-to-escape-sandbox",
153+
sandbox := "allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms",
147154
src := s"/resultframe?theme=light"
148155
)
149156
)
@@ -195,7 +202,7 @@ object FiddleEditor {
195202
width := "0%",
196203
height := "0%",
197204
frameBorder := "0",
198-
sandbox := "allow-scripts allow-popups allow-popups-to-escape-sandbox",
205+
sandbox := "allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms",
199206
src := s"/resultframe?theme=light"
200207
)
201208
)
@@ -345,26 +352,30 @@ object FiddleEditor {
345352
editor.updateDynamic("$blockScrolling")(Double.PositiveInfinity)
346353

347354
val globalBindings = Seq(
348-
EditorBinding("Compile",
349-
"enter",
350-
() =>
351-
beginCompilation().foreach(_ => {
352-
buildFullSource
353-
.flatMap { source =>
354-
props.dispatch(compile(source, FastOpt))
355-
}
356-
.runNow()
357-
})),
358-
EditorBinding("FullOptimize",
359-
"shift+enter",
360-
() =>
361-
beginCompilation().foreach(_ => {
362-
buildFullSource
363-
.flatMap { source =>
364-
props.dispatch(compile(source, FullOpt))
365-
}
366-
.runNow()
367-
})),
355+
EditorBinding(
356+
"Compile",
357+
"enter",
358+
() =>
359+
beginCompilation().foreach(_ => {
360+
buildFullSource
361+
.flatMap { source =>
362+
props.dispatch(compile(source, FastOpt))
363+
}
364+
.runNow()
365+
})
366+
),
367+
EditorBinding(
368+
"FullOptimize",
369+
"shift+enter",
370+
() =>
371+
beginCompilation().foreach(_ => {
372+
buildFullSource
373+
.flatMap { source =>
374+
props.dispatch(compile(source, FullOpt))
375+
}
376+
.runNow()
377+
})
378+
),
368379
EditorBinding("Show JavaScript", "j", () => $.state.map(state => showJSCode(state)).runNow()),
369380
EditorBinding(
370381
"Save",
@@ -407,7 +418,8 @@ object FiddleEditor {
407418
"sender" -> "editor|cli"
408419
),
409420
"exec" -> func
410-
))
421+
)
422+
)
411423
}
412424

413425
// register auto complete
@@ -439,7 +451,8 @@ object FiddleEditor {
439451
}
440452
}
441453
)
442-
.value)
454+
.value
455+
)
443456

444457
// focus to the editor
445458
editor.focus()
@@ -460,8 +473,9 @@ object FiddleEditor {
460473
props.dispatch(UpdateLoginInfo) >>
461474
updateFiddle(props.data()) >>
462475
Callback.when(props.fiddleId.isDefined)(
463-
props.dispatch(
464-
compile(addDeps(props.data().sourceCode, props.data().libraries, props.data().scalaVersion), FastOpt)))
476+
props
477+
.dispatch(compile(addDeps(props.data().sourceCode, props.data().libraries, props.data().scalaVersion), FastOpt))
478+
)
465479
}
466480

467481
val fiddleStart = """\s*// \$FiddleStart\s*$""".r
@@ -497,7 +511,8 @@ object FiddleEditor {
497511
val indent = main.filter(_.nonEmpty).map(_.takeWhile(_ == ' ').length).min
498512
editor.getSession().setValue(main.map(_.drop(indent)).mkString("\n"))
499513
$.setState(
500-
state.copy(preCode = pre, mainCode = main, postCode = post, indent = indent, lastModified = fiddle.modified))
514+
state.copy(preCode = pre, mainCode = main, postCode = post, indent = indent, lastModified = fiddle.modified)
515+
)
501516
}
502517
}
503518
}
@@ -590,9 +605,11 @@ object FiddleEditor {
590605
// start running the code after a short delay, to allow DOM to update in case the code is slow to complete
591606
js.timers.setTimeout(30) {
592607
// pass compiled data to the iframe
593-
val data = js.Dynamic.literal(code = jsCode,
594-
jsDeps = compilerData.jsDeps.toJSArray,
595-
cssDeps = compilerData.cssDeps.toJSArray)
608+
val data = js.Dynamic.literal(
609+
code = jsCode,
610+
jsDeps = compilerData.jsDeps.toJSArray,
611+
cssDeps = compilerData.cssDeps.toJSArray
612+
)
596613
sendFrameCmd("code", data)
597614
}
598615
}
@@ -617,9 +634,11 @@ object FiddleEditor {
617634
.componentWillReceiveProps(scope => scope.backend.updateProps(scope.nextProps, scope.state))
618635
.build
619636

620-
def apply(data: ModelProxy[FiddleData],
621-
fiddleId: Option[FiddleId],
622-
compilerData: ModelR[AppModel, OutputData],
623-
loginData: ModelR[AppModel, LoginData]) =
637+
def apply(
638+
data: ModelProxy[FiddleData],
639+
fiddleId: Option[FiddleId],
640+
compilerData: ModelR[AppModel, OutputData],
641+
loginData: ModelR[AppModel, LoginData]
642+
) =
624643
component(Props(data, fiddleId, compilerData, loginData))
625644
}

client/src/main/scala/scalafiddle/client/component/Sidebar.scala

+23-14
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,23 @@ object Sidebar {
8686
),
8787
div(cls := "title", "Libraries", i(cls := "icon dropdown")),
8888
div(cls := "content")(
89-
div(cls := "ui horizontal divider header",
90-
(style := js.Dynamic.literal(display = "none")).when(fd.libraries.isEmpty),
91-
"Selected"),
89+
div(
90+
cls := "ui horizontal divider header",
91+
(style := js.Dynamic.literal(display = "none")).when(fd.libraries.isEmpty),
92+
"Selected"
93+
),
9294
div(cls := "liblist", (style := js.Dynamic.literal(display = "none")).when(fd.libraries.isEmpty))(
9395
div(cls := "ui middle aligned divided list")(
94-
fd.libraries.toTagMod(renderLibrary(_, SelectedLib, fd.scalaVersion, props.dispatch)))
96+
fd.libraries.toTagMod(renderLibrary(_, SelectedLib, fd.scalaVersion, props.dispatch))
97+
)
9598
),
9699
div(cls := "ui horizontal divider header", "Available"),
97100
div(cls := "ui checkbox")(
98-
input.checkbox(name := "all-versions",
99-
checked := state.showAllVersions,
100-
onChange --> $.modState(s => s.copy(showAllVersions = !s.showAllVersions))),
101+
input.checkbox(
102+
name := "all-versions",
103+
checked := state.showAllVersions,
104+
onChange --> $.modState(s => s.copy(showAllVersions = !s.showAllVersions))
105+
),
101106
label("Show all versions")
102107
),
103108
div(cls := "liblist")(
@@ -159,11 +164,13 @@ object Sidebar {
159164
div(cls := "item")(
160165
div(cls := "right floated")(
161166
lib.exampleUrl
162-
.map(
163-
url =>
164-
button(cls := s"mini ui icon basic button",
165-
title := s"Load example fiddle for ${lib.name}",
166-
onClick --> dispatch(LoadFiddle(url)))(i(cls := "file code outline icon codeicon")))
167+
.map(url =>
168+
button(
169+
cls := s"mini ui icon basic button",
170+
title := s"Load a sample fiddle for ${lib.name}",
171+
onClick --> dispatch(LoadFiddle(url))
172+
)(i(cls := "file code outline icon codeicon"))
173+
)
167174
.whenDefined
168175
.when(mode == SelectedLib),
169176
button(cls := s"mini ui icon basic button", onClick --> dispatch(action))(icon)
@@ -172,7 +179,8 @@ object Sidebar {
172179
div(cls := "content left floated")(
173180
b(lib.name),
174181
" ",
175-
span(cls := (if (lib.scalaVersions.contains(scalaVersion)) "text grey" else "text red"), lib.version))
182+
span(cls := (if (lib.scalaVersions.contains(scalaVersion)) "text grey" else "text red"), lib.version)
183+
)
176184
)
177185
)
178186
}
@@ -185,7 +193,8 @@ object Sidebar {
185193
.componentDidMount(_ =>
186194
Callback {
187195
JQueryStatic(accordionRef).accordion(js.Dynamic.literal(exclusive = true, animateChildren = false))
188-
})
196+
}
197+
)
189198
.build
190199

191200
def apply(data: ModelProxy[FiddleData]) = component(Props(data))

0 commit comments

Comments
 (0)