├── .Rhistory ├── project ├── build.properties ├── Versions.scala ├── plugins.sbt └── Dependencies.scala ├── preview ├── jvm │ └── src │ │ └── main │ │ ├── resources │ │ ├── logo.png │ │ └── Kappa.js │ │ ├── twirl │ │ ├── main.scala.html │ │ ├── index.scala.html │ │ ├── runner.scala.html │ │ ├── features.scala.html │ │ ├── sidebar.scala.html │ │ ├── libs.scala.html │ │ └── intro.scala.html │ │ └── scala │ │ └── org │ │ └── denigma │ │ └── preview │ │ ├── AppMessages.scala │ │ ├── Main.scala │ │ ├── templates │ │ ├── MyStyles.scala │ │ └── Twirl.scala │ │ ├── MainActor.scala │ │ └── Routes.scala └── js │ └── src │ └── main │ ├── scala │ └── org │ │ └── denigma │ │ └── preview │ │ ├── IntroView.scala │ │ ├── FrontEnd.scala │ │ ├── SidebarView.scala │ │ ├── ExampleData.scala │ │ └── FeaturesView.scala │ └── resources │ └── addons │ └── simple.js ├── .gitignore ├── facade └── src │ └── main │ └── scala │ └── org │ └── denigma │ └── codemirror │ ├── extensions.scala │ ├── extensions │ ├── Settings.scala │ └── package.scala │ └── Editor.scala ├── .travis.yml ├── README.md └── LICENSE /.Rhistory: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.15 2 | -------------------------------------------------------------------------------- /preview/jvm/src/main/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonkulaga/codemirror-facade/HEAD/preview/jvm/src/main/resources/logo.png -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/main.scala.html: -------------------------------------------------------------------------------- 1 | @(content:Option[Html] = None) 2 |
3 | @{content.getOrElse(intro())} 4 |
-------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/AppMessages.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | object AppMessages { 4 | 5 | case class Start(port:Int) 6 | case object Stop 7 | 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # sbt specific 5 | .cache/ 6 | .history/ 7 | .lib/ 8 | dist/* 9 | target/ 10 | lib_managed/ 11 | src_managed/ 12 | project/boot/ 13 | project/plugins/project/ 14 | 15 | # Scala-IDE specific 16 | .scala_dependencies 17 | .worksheet 18 | 19 | .idea 20 | -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/index.scala.html: -------------------------------------------------------------------------------- 1 | @(content:Option[Html] = None) 2 | 3 | 4 | @html.libs() 5 | @html.runner() 6 | 7 | 8 | @html.sidebar() 9 |
10 | @html.main(content) 11 |
12 | 13 | -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/runner.scala.html: -------------------------------------------------------------------------------- 1 | @(into:String = "main",leftSidebar:Boolean = true) 2 | 3 | 11 | -------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/Main.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import akka.actor.{ActorSystem, _} 4 | 5 | /** 6 | * For running as kernel 7 | */ 8 | object Main extends App 9 | { 10 | implicit val system = ActorSystem() 11 | 12 | sys.addShutdownHook(system.terminate()) 13 | var main: ActorRef = system.actorOf(Props[MainActor]) 14 | main ! AppMessages.Start(5554) 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/templates/MyStyles.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview.templates 2 | 3 | import scalacss.Defaults._ 4 | 5 | 6 | object MyStyles extends StyleSheet.Standalone { 7 | import dsl._ 8 | 9 | ".CodeMirror" -( 10 | height.auto 11 | ) 12 | 13 | ".CodeMirror-scroll" -( 14 | overflowX.auto,overflowY.hidden 15 | ) 16 | 17 | ".breakpoints" - ( 18 | width( 1 em) 19 | ) 20 | 21 | } -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/features.scala.html: -------------------------------------------------------------------------------- 1 | @() 2 |
3 |
4 | Some extra examples 5 |
6 |
7 |
8 |

Here if you type a comment with a link to pdf it will put this link as an icon

9 | 10 |
11 |
12 |
-------------------------------------------------------------------------------- /facade/src/main/scala/org/denigma/codemirror/extensions.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.codemirror 2 | 3 | /** 4 | * Created by antonkulaga on 25/02/16. 5 | */ 6 | package object extensions { 7 | 8 | implicit def editorExtended(editor: Editor): ExtendedEditor = new ExtendedEditor(editor) 9 | 10 | //implicit def editorExtended(editor: Editor): ExtendedEditor = new ExtendedEditor(editor) 11 | 12 | implicit def editorExtended(change: EditorChangeLike): ExtendedChange = new ExtendedChange(change) 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | scala: 7 | - 2.12.2 8 | 9 | sudo: false 10 | 11 | env: 12 | - TRAVIS_NODE_VERSION="5" 13 | 14 | before_install: 15 | - nvm install node 16 | 17 | install: 18 | - npm install jsdom 19 | 20 | cache: 21 | directories: 22 | - $HOME/.ivy2/cache 23 | - $HOME/.sbt/boot/ 24 | 25 | script: 26 | # Your normal script 27 | - sbt -J-XX:ReservedCodeCacheSize=256M +test 28 | 29 | # Tricks to avoid unnecessary cache updates 30 | - find $HOME/.sbt -name "*.lock" | xargs rm 31 | - find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm 32 | -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/sidebar.scala.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /project/Versions.scala: -------------------------------------------------------------------------------- 1 | object Versions extends WebJarsVersions with ScalaJSVersions with SharedVersions 2 | { 3 | val scala = "2.12.2" 4 | 5 | val akkaHttpExtensions = "0.0.15" 6 | 7 | } 8 | 9 | trait ScalaJSVersions { 10 | 11 | val facade = "5.13.2-0.8" 12 | 13 | val jqueryFacade = "1.0" 14 | 15 | val dom = "0.9.3" 16 | 17 | val bindingControls = "0.0.25" 18 | 19 | } 20 | 21 | //versions for libs that are shared between client and server 22 | trait SharedVersions 23 | { 24 | val scalaTags = "0.5.4" 25 | 26 | val scalaCSS = "0.5.3" 27 | 28 | val scalaTest = "3.0.3" 29 | 30 | val fastParse = "0.4.3" 31 | 32 | } 33 | 34 | 35 | trait WebJarsVersions{ 36 | 37 | val jquery = "3.2.1" 38 | 39 | val semanticUI = "2.2.10" 40 | 41 | val codemirror = "5.24.2" 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/templates/Twirl.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview.templates 2 | 3 | import akka.http.extensions.pjax.{PJaxMagnet, TemplateEngine} 4 | import akka.http.scaladsl.server.Directive 5 | 6 | /** 7 | * PJax Twirl support 8 | */ 9 | class Twirl extends TemplateEngine{ 10 | type Html = play.twirl.api.Html 11 | } 12 | 13 | import play.twirl.api.Html 14 | 15 | object Twirl{ 16 | implicit def apply(params:(Html,Html=>Html)):PJaxMagnet[Twirl] = 17 | PJaxMagnet[Twirl]( 18 | Directive[Tuple1[Html]] { inner ⇒ ctx ⇒ 19 | val (html, transform) = params 20 | if (ctx.request.headers.exists(h => h.lowercaseName() == "x-pjax")) 21 | inner(Tuple1(html))(ctx) 22 | else 23 | inner(Tuple1(transform(html)))(ctx) 24 | }) 25 | 26 | 27 | } -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.1") // advanced assets handling 2 | 3 | addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0") //live refresh 4 | 5 | addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.1") // packaging for production 6 | 7 | addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.0.5") 8 | 9 | addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.3") // templates 10 | 11 | addSbtPlugin("com.gilt" % "sbt-dependency-graph-sugar" % "0.7.5-1") // visual dependency management 12 | 13 | addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.1") // for monitoring dependency updates 14 | 15 | addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0") // for publishing 16 | 17 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0") 18 | 19 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18") 20 | 21 | addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.0") 22 | 23 | addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.2.0") 24 | -------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/MainActor.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import akka.actor._ 4 | import akka.http.scaladsl.{Http, _} 5 | import akka.stream.ActorMaterializer 6 | 7 | /** 8 | * Main actor that encapsulates main application logic and starts the server 9 | */ 10 | class MainActor extends Actor with ActorLogging with Routes 11 | { 12 | implicit val system = context.system 13 | implicit val materializer = ActorMaterializer() 14 | implicit val executionContext = system.dispatcher 15 | 16 | val server: HttpExt = Http(context.system) 17 | 18 | override def receive: Receive = { 19 | case AppMessages.Start(port)=> 20 | val host = "localhost" 21 | server.bindAndHandle(routes, host, port) 22 | log.info(s"starting server at $host:$port") 23 | 24 | 25 | case AppMessages.Stop=> onStop() 26 | } 27 | 28 | def onStop() = { 29 | log.info("Main actor has been stoped...") 30 | } 31 | 32 | override def postStop() = { 33 | onStop() 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/libs.scala.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /preview/js/src/main/scala/org/denigma/preview/IntroView.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import org.denigma.binding.views.BindableView 4 | import org.denigma.codemirror.{CodeMirror, EditorConfiguration} 5 | import org.denigma.codemirror.extensions.EditorConfig 6 | import org.scalajs.dom 7 | import org.scalajs.dom.raw.Element 8 | import org.scalajs.dom.raw.HTMLTextAreaElement 9 | 10 | class IntroView(val elem: Element) extends BindableView with ExampleData{ 11 | 12 | def activate(): Unit = { 13 | activate("scala", "text/x-scala",scalaCode) 14 | activate("html", "htmlmixed",htmlCode) 15 | activate("sparql", "sparql",sparqlCode) 16 | activate("turtle", "turtle",turtleCode) 17 | activate("r","r", rCode) 18 | activate("kappa","Kappa", kappaCode) 19 | } 20 | 21 | 22 | def activate(id: String, mode: String, code: String): Unit = { 23 | val params: EditorConfiguration = EditorConfig.mode(mode).lineNumbers(true).value(code)//.noMargin() 24 | val editor = dom.document.getElementById(id) match { 25 | case el:HTMLTextAreaElement => 26 | val m = CodeMirror.fromTextArea(el, params) 27 | m.getDoc().setValue(code) 28 | case _=> dom.console.error("cannot find text area for the code!") 29 | } 30 | } 31 | 32 | override def bindView(): Unit ={ 33 | super.bindView() 34 | activate() 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /preview/jvm/src/main/twirl/intro.scala.html: -------------------------------------------------------------------------------- 1 | @() 2 |
3 |
4 | ScalaJS interface for CodeMirror javascript lib 5 |
6 |

How to use:

7 |
8 |
9 |
Scala code:
10 | 11 |
12 |
13 |
Html with text-area:
14 | 15 |
16 |
17 |

Other examples:

18 |
19 |
20 |
Kappa code
21 | 22 |
23 |
24 |
TURTLE code
25 | 26 |
27 |
28 |
SPARQL code
29 | 30 |
31 |
32 |
R code
33 | 34 |
35 |
36 |
37 | -------------------------------------------------------------------------------- /preview/jvm/src/main/resources/Kappa.js: -------------------------------------------------------------------------------- 1 | /* Example definition of a simple mode that understands a subset of 2 | * JavaScript: 3 | */ 4 | 5 | CodeMirror.defineSimpleMode("Kappa", { 6 | // The start state contains the rules that are intially used 7 | start: [ 8 | {regex: /\#(.*)/, token: "comment"}, 9 | {regex: /(\%agent:|\%def:|\%var:|\%plot:|\%obs:|\%init:|\%mod:|\%token:|do|repeat|until)\s/, 10 | token: "keyword"}, 11 | {regex: /(\$ADD|\$DEL|\$SNAPSHOT|\$STOP|\$FLUX|\$TRACK|\$UPDATE|\$PRINT)\s/, 12 | token: "variable-2"}, 13 | {regex: /(\[not\]|\[log\]|\[sin\]|\[cos\]|\[tan\]|\[sqrt\]|\[mod\]|\[exp\]|\[int\])/, 14 | token: "atom"}, 15 | {regex: /(\[E\]|\[E\+\]|\[E\-\]|\[Emax\]|\[T\]|\[Tsim\]|\[Tmax\]|\[inf\]|\[pi\]|\[true\]|\[false\])/, 16 | token: "atom"}, 17 | {regex: /'([^'\s]+)'/, token: "atom"}, 18 | {regex: /(\?|\!|\~)/, 19 | token: "variable-2"}, 20 | {regex: /(\@|\,|\(|\)|\{|\}|\||\.|\+|\*|\-|\^|\/|\<|\>|\=|\%|\:|\!|\?|\:|\;)/, 21 | token: "variable-2"}, 22 | {regex: /0x[a-f\d]+|[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i, 23 | token: "number"}, 24 | {regex: /"(?:[^\\]|\\.)*?"/, token: "string"}, 25 | ], 26 | // The multi-line comment state. 27 | comment: [ ], 28 | // The meta property contains global information about the mode. It 29 | // can contain properties like lineComment, which are supported by 30 | // all modes, and also directives like dontIndentStates, which are 31 | // specific to simple modes. 32 | meta: { } 33 | }); 34 | -------------------------------------------------------------------------------- /project/Dependencies.scala: -------------------------------------------------------------------------------- 1 | import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ 2 | import sbt._ 3 | 4 | 5 | object Dependencies { 6 | 7 | //libs for testing 8 | lazy val testing = Def.setting(Seq( 9 | "org.scalatest" %%% "scalatest" % Versions.scalaTest % Test 10 | )) 11 | 12 | //akka-related libs 13 | lazy val akka = Def.setting(Seq( 14 | 15 | "org.denigma" %%% "akka-http-extensions" % Versions.akkaHttpExtensions 16 | )) 17 | 18 | 19 | lazy val facadeDependencies = Def.setting(Seq( 20 | "org.scala-js" %%% "scalajs-dom" % Versions.dom, 21 | 22 | "org.querki" %%% "jquery-facade" % Versions.jqueryFacade 23 | )) 24 | 25 | //scalajs libs 26 | lazy val sjsLibs= Def.setting(Seq( 27 | "org.scala-js" %%% "scalajs-dom" % Versions.dom, 28 | 29 | "org.querki" %%% "jquery-facade" % Versions.jqueryFacade, //scalajs facade for jQuery + jQuery extensions 30 | 31 | "org.denigma" %%% "binding-controls" % Versions.bindingControls, 32 | 33 | "com.lihaoyi" %%% "fastparse" % Versions.fastParse 34 | )) 35 | 36 | //dependencies on javascript libs 37 | lazy val webjars= Def.setting(Seq( 38 | 39 | "org.webjars" % "Semantic-UI" % Versions.semanticUI, //css theme, similar to bootstrap 40 | 41 | "org.webjars" % "codemirror" % Versions.codemirror, 42 | 43 | "org.webjars" % "jquery" % Versions.jquery 44 | )) 45 | 46 | //common purpose libs 47 | lazy val commonShared: Def.Initialize[Seq[ModuleID]] = Def.setting(Seq( 48 | "com.github.japgolly.scalacss" %%% "core" % Versions.scalaCSS, 49 | 50 | "com.github.japgolly.scalacss" %%% "ext-scalatags" % Versions.scalaCSS 51 | )) 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | org.denigma.codemirror facade 2 | ============================= 3 | 4 | This if a facade of org.denigma.codemirror library. All the code is inside org.denigma.codemirror subproject. 5 | 6 | Usage 7 | ===== 8 | 9 | In order to resolve a lib you should add a resolver:: 10 | ```scala 11 | resolvers += sbt.Resolver.bintrayRepo("denigma", "denigma-releases") //add resolver 12 | libraryDependencies += "org.denigma" %%% "codemirror-facade" % "5.13.2-0.8" //add dependency 13 | ``` 14 | 15 | Currently both Scala 2.11.x and Scala 2.12.x are supported. 16 | 17 | In your code: 18 | ------------- 19 | 20 | Add text area somewhere: 21 | 22 | ```html 23 | 24 | ``` 25 | 26 | Write some simple code 27 | 28 | ```scala 29 | import org.denigma.org.denigma.codemirror.extensions.EditorConfig 30 | import org.denigma.org.denigma.codemirror.{CodeMirror, EditorConfiguration} 31 | import org.scalajs.dom 32 | import org.scalajs.dom.raw.HTMLTextAreaElement 33 | 34 | val id = "scala" 35 | val code = println("hello Scala!") //code to add 36 | val mode = "clike" //language mode, some modes have weird names in org.denigma.codemirror 37 | val params: EditorConfiguration = EditorConfig.mode(mode).lineNumbers(true) //config 38 | val editor = dom.document.getElementById(id) match { 39 | case el:HTMLTextAreaElement => 40 | val m = CodeMirror.fromTextArea(el,params) 41 | m.getDoc().setValue(code) //add the code 42 | case _=> dom.console.error("cannot find text area for the code!") 43 | } 44 | ``` 45 | 46 | 47 | Preview 48 | ------- 49 | 50 | Preview subprojects are required to see some examples of using the facade. 51 | 52 | To run preview: 53 | ```sbt 54 | sbt //to opens sbt console 55 | re-start //Use this command **instead of** run to run the app 56 | Open localhost:5554 to see the result, it should reload whenever any sources are changed 57 | ``` 58 | 59 | Extensions 60 | ---------- 61 | 62 | In org.denigma.extensions package there are some methods that extend default codemirror functionality. 63 | -------------------------------------------------------------------------------- /preview/js/src/main/scala/org/denigma/preview/FrontEnd.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import org.denigma.binding.binders.{GeneralBinder, NavigationBinder} 4 | import org.denigma.binding.extensions.{sq, _} 5 | import org.denigma.binding.views.BindableView 6 | import org.denigma.controls.code.CodeBinder 7 | import org.querki.jquery._ 8 | import org.scalajs.dom 9 | import org.scalajs.dom.raw.HTMLElement 10 | 11 | import scala.scalajs.js 12 | import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel} 13 | 14 | /** 15 | * Just a simple view for the whole app, if interested ( see https://github.com/antonkulaga/scala-js-binding ) 16 | */ 17 | @JSExport("FrontEnd") 18 | @JSExportTopLevel("FrontEnd") 19 | object FrontEnd extends BindableView with scalajs.js.JSApp 20 | { 21 | 22 | lazy val elem: HTMLElement = dom.document.body 23 | 24 | lazy val sidebarParams = js.Dynamic.literal( 25 | exclusive = false, 26 | dimPage = false, 27 | closable = false, 28 | useLegacy = false 29 | ) 30 | /** 31 | * Register views 32 | */ 33 | override lazy val injector = defaultInjector 34 | .register("sidebar")((el, params) => new SidebarView(el).withBinder(new GeneralBinder(_))) 35 | .register("intro")((el, params) => new IntroView(el).withBinder(new CodeBinder(_))) 36 | .register("features")((el, params) => new FeaturesView(el)) 37 | 38 | 39 | @JSExport 40 | def main(): Unit = { 41 | this.bindView() 42 | } 43 | 44 | @JSExport 45 | def showLeftSidebar() = { 46 | $(".left.sidebar").dyn.sidebar(sidebarParams).sidebar("show") 47 | } 48 | 49 | @JSExport 50 | def load(content: String, into: String): Unit = { 51 | dom.document.getElementById(into).innerHTML = content 52 | } 53 | 54 | @JSExport 55 | def moveInto(from: String, into: String): Unit = { 56 | for { 57 | ins <- sq.byId(from) 58 | intoElement <- sq.byId(into) 59 | } { 60 | this.loadElementInto(intoElement, ins.innerHTML) 61 | ins.parentNode.removeChild(ins) 62 | } 63 | } 64 | 65 | 66 | withBinders(me => List(new CodeBinder(me), new NavigationBinder(me))) 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /preview/js/src/main/scala/org/denigma/preview/SidebarView.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import org.denigma.binding.binders.{GeneralBinder, NavigationBinder} 4 | import org.denigma.binding.extensions._ 5 | import org.denigma.binding.views.{BindableView, CollectionSeqView} 6 | import org.querki.jquery._ 7 | import org.scalajs.dom.Element 8 | import org.scalajs.dom.Element 9 | import org.scalajs.dom.raw.Element 10 | import rx._ 11 | 12 | import scala.collection.immutable.{Map, Seq} 13 | 14 | /** 15 | * Just a simple view for the sidebar, if interested ( see https://github.com/antonkulaga/scala-js-binding ) 16 | */ 17 | class SidebarView (val elem: Element) extends BindableView { 18 | 19 | 20 | val title = Var("CodeMirror facade") 21 | 22 | val logo = Var("/resources/logo.png") 23 | 24 | /*override def bindElement(el:HTMLElement) = { 25 | super.bindElement(el) 26 | $(".ui.accordion").dyn.accordion() 27 | }*/ 28 | 29 | 30 | 31 | 32 | override def bindView() = { 33 | super.bindView() 34 | $(".ui.accordion").dyn.accordion() 35 | } 36 | 37 | override lazy val injector = defaultInjector 38 | .register("menu"){ 39 | case (el, args) => new MenuView(el) 40 | .withBinder(new GeneralBinder(_)) 41 | .withBinder(new NavigationBinder(_)) 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | class MenuView(elem: Element) extends MapCollectionView(elem) { 49 | self => 50 | 51 | override val items: Rx[Seq[Map[String, Any]]] = Var( 52 | Seq( 53 | Map("uri" -> "pages/intro", "label" -> "Getting started"), 54 | Map("uri" -> "pages/features", "label" -> "Features") 55 | ) 56 | ) 57 | } 58 | 59 | import org.denigma.binding.binders.{MapItemsBinder, NavigationBinder} 60 | import org.scalajs.dom.Element 61 | import rx.Var 62 | 63 | import scala.collection.immutable._ 64 | 65 | object MapCollectionView { 66 | 67 | class JustMapView(val elem: Element, val params: Map[String, Any]) extends BindableView 68 | { 69 | val reactiveMap: Map[String, Var[String]] = params.map(kv => (kv._1, Var(kv._2.toString))) 70 | 71 | this.withBinders(m => new MapItemsBinder(m, reactiveMap)::new NavigationBinder(m)::Nil) 72 | } 73 | 74 | } 75 | 76 | 77 | 78 | abstract class MapCollectionView(val elem: Element) extends CollectionSeqView 79 | { 80 | override type Item = Map[String, Any] 81 | 82 | override type ItemView = BindableView 83 | 84 | def newItemView(item: Item): ItemView = this.constructItemView(item){ (el, mp) => new MapCollectionView.JustMapView(el, item) } 85 | 86 | } -------------------------------------------------------------------------------- /preview/jvm/src/main/scala/org/denigma/preview/Routes.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import akka.http.extensions.pjax.PJax 4 | import akka.http.extensions.resources.TextFilesDirectives 5 | import akka.http.scaladsl.model._ 6 | import akka.http.scaladsl.server._ 7 | import akka.http.scaladsl.server.Directives._ 8 | import org.denigma.preview.templates.{Twirl, MyStyles} 9 | import play.twirl.api.Html 10 | 11 | import scalacss.Defaults._ 12 | 13 | 14 | /** 15 | * Trait that countains routes and handlers 16 | */ 17 | trait Routes extends Directives with PJax with TextFilesDirectives 18 | { 19 | 20 | lazy val webjarsPrefix = "lib" 21 | 22 | lazy val resourcePrefix = "resources" 23 | 24 | lazy val sourcesPath = "js/src/main/scala/" 25 | 26 | def index = pathSingleSlash{ctx=> 27 | ctx.complete { 28 | HttpResponse( entity = HttpEntity(MediaTypes.`text/html`.withCharset(HttpCharsets.`UTF-8`), html.index(None).body )) 29 | } 30 | } 31 | 32 | def mystyles = path("styles" / "mystyles.css"){ 33 | complete { 34 | HttpResponse( entity = HttpEntity(MediaTypes.`text/css`.withCharset(HttpCharsets.`UTF-8`), MyStyles.render )) } 35 | } 36 | 37 | def loadResources = pathPrefix(resourcePrefix~Slash) { 38 | getFromResourceDirectory("") 39 | } 40 | 41 | def webjars =pathPrefix(webjarsPrefix ~ Slash) { getFromResourceDirectory(webjarsPrefix) } 42 | 43 | def defaultPage: Option[Html] = None 44 | 45 | lazy val loadPage: Html => Html = h => html.index( Some(h) ) 46 | 47 | 48 | def page(html:Html): Route = pjax[Twirl](html, loadPage){h=>c=> 49 | val resp = HttpResponse( entity = HttpEntity(MediaTypes.`text/html`.withCharset(HttpCharsets.`UTF-8`), h.body )) 50 | c.complete(resp) 51 | } 52 | 53 | def menu = pathPrefix("pages" ~ Slash){ ctx => 54 | ctx.unmatchedPath.toString() match { 55 | case "intro"=> page(html.intro())(ctx) 56 | case "features"=> page(html.features())(ctx) 57 | case other => ctx.complete(s"page $other not found!") 58 | } 59 | } 60 | 61 | /* def loadSources: Route = (pathPrefix("sources" ~ Slash) | pathPrefix("source" ~ Slash)){ 62 | extractUnmatchedPath { place ⇒ 63 | parameters("from", "to"){ 64 | case (from, to) => 65 | extractLog { case log=> 66 | filePath(sourcesPath,place,log,'/') match { 67 | case "" ⇒ 68 | reject() 69 | case resourceName ⇒ 70 | this.linesFromResource(resourceName, from, to) { case lines => 71 | complete(HttpResponse(entity = HttpEntity(MediaTypes.`text/css`.withCharset(HttpCharsets.`UTF-8`), lines.reduce(_+"\n"+_) ) )) 72 | } 73 | } 74 | } 75 | } 76 | } 77 | }*/ 78 | 79 | 80 | 81 | def routes = index ~ webjars ~ mystyles ~ loadResources ~ menu //~ loadSources 82 | } -------------------------------------------------------------------------------- /facade/src/main/scala/org/denigma/codemirror/extensions/Settings.scala: -------------------------------------------------------------------------------- 1 | package org.denigma 2 | package codemirror.extensions 3 | import org.denigma.codemirror.{Editor, EditorConfiguration} 4 | import org.querki.jsext._ 5 | import org.scalajs.dom.raw.Event 6 | 7 | import scala.scalajs.js 8 | /** 9 | * Builders for easier configuration 10 | */ 11 | object EditorConfig extends EditorConfigurationBuilder(noOpts) 12 | class EditorConfigurationBuilder(val dict:OptMap) 13 | extends JSOptionBuilder[EditorConfiguration, EditorConfigurationBuilder](new EditorConfigurationBuilder(_)) 14 | { 15 | def value(code:String) = jsOpt("value",code) 16 | def mode(modeValue:String) = jsOpt("mode",modeValue) 17 | def theme(themeValue:String) = jsOpt("theme",themeValue) 18 | def indentUnit(value:Double) = jsOpt("indentUnit",value) 19 | def smartIndent(value:Boolean) = jsOpt("smartIndent",value) 20 | def tabSize(value:Double) = jsOpt("tabSize",value) 21 | def indentWithTabs(value: Boolean) = jsOpt("indentWithTabs",value) 22 | def electricChars(value: Boolean) = jsOpt("electricChars",value) 23 | def rtlMoveVisually(value:Boolean) = jsOpt("rtlMoveVisually",value) 24 | def keyMap(value: String) = jsOpt("keyMap",value) 25 | def extraKeys(value: js.Any) = jsOpt("extraKeys",value) 26 | def lineNumbers(value:Boolean) = jsOpt("lineNumbers", value) 27 | def lineWrapping(value:Boolean) = jsOpt("lineWrapping", value) 28 | def firstLineNumber(value: Double) = jsOpt("firstLineNumber",value) 29 | def lineNumberFormatter(value: js.Function1[Double, String]) = jsOpt("lineNumberFormatter",value) 30 | def gutters(value: js.Array[String]) = jsOpt("gutters",value) 31 | def readOnly(value:Boolean) = jsOpt("readOnly",value) 32 | def readOnly(value:String) = jsOpt("readOnly",value) 33 | def fixedGutter(value: Boolean) = jsOpt("fixedGutter",value) 34 | def showCursorWhenSelecting(value: Boolean) = jsOpt("showCursorWhenSelecting",value) 35 | def undoDepth(depth:Double) = jsOpt("undoDepth",depth) 36 | def historyEventDelay(value: Double) = jsOpt("historyEventDelay",value) 37 | def tabindex(value: Double) = jsOpt("tabindex",value) 38 | def autofocus(value: Boolean) = jsOpt("autofocus",value) 39 | def dragDrop(value:Boolean) = jsOpt("dragDrop",value) 40 | def onDragEvent(dragEventHandler:js.Function2[Editor, Event, Boolean]) = jsOpt("onDragEvent",dragEventHandler) 41 | def onKeyEvent(keyEventHandler:js.Function2[Editor, Event, Boolean]) = jsOpt("onKeyEvent",keyEventHandler) 42 | def cursorBlinkRate(value: Double) = jsOpt("cursorBlinkRate",value) 43 | def cursorHeight(value: Double) = jsOpt("cursorHeight",value) 44 | def workTime(value: Double) = jsOpt("workTime",value) 45 | def workDelay(value: Double) = jsOpt("workDelay",value) 46 | def pollInterval(value: Double) = jsOpt("pollInterval",value) 47 | def flattenSpans(value: Boolean) = jsOpt("flattenSpans",value) 48 | def maxHighlightLength(value: Double) = jsOpt("maxHighlightLength",value) 49 | def viewportMargin(value: Integer) = jsOpt("viewportMargin",value) 50 | //def noMargin() = jsOpt("viewportMargin","Infinity") 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /facade/src/main/scala/org/denigma/codemirror/extensions/package.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.codemirror.extensions 2 | 3 | 4 | import org.denigma.codemirror.{EditorChangeLike, Editor} 5 | 6 | import scala.scalajs.js 7 | 8 | class ExtendedChange(val change: EditorChangeLike) extends AnyVal { 9 | 10 | def mergeSpans(other: (Int, Int)): (Int, Int) = (changedSpan, other) match { 11 | case ( (min1, max1), (min2, max2) ) => (Math.min(min1, min2), Math.max(max1, max2)) 12 | } 13 | 14 | def changedSpan = ( change.from.line, 15 | change.to.line -( if(change.removed.length > 1) change.removed.length -1 else 0 ) + ( if(change.text.length > 1) change.text.length -1 else 0 ) 16 | ) //NOTE IS BUGGY 17 | 18 | def newLines: Map[Int, String] = change.text.zipWithIndex.map{ 19 | case (s, i) => (i + change.from.line, s) 20 | } toMap 21 | 22 | //def changedLines: Seq[Int] = change.text.indices.map{ case i => change.from.line + i } ++ change.removed.indices.map{ case i => change.from.line -i } 23 | } 24 | 25 | class ExtendedEditor(val editor: Editor) extends AnyVal 26 | { 27 | def addOnGutterClick(fun: (Editor, Int)=> Unit) = { 28 | val handler: js.Function2[Editor, _, Unit] = fun 29 | editor.on("gutterClick", handler) 30 | } 31 | 32 | /** 33 | * @param fun handler to react on change 34 | * 35 | * Fires every time the content of the editor is changed. 36 | * The changeObj is a {from, to, text, removed, origin} object 37 | * containing information about the changes that occurred as second argument. 38 | * from and to are the positions (in the pre-change coordinate system) 39 | * where the change started and ended 40 | * (for example, it might be {ch:0, line:18} if the position is at the beginning of line #19). 41 | * text is an array of strings representing the text that replaced the changed range (split by line). 42 | * removed is the text that used to be between from and to, 43 | * which is overwritten by this change. 44 | * This event is fired before the end of an operation, before the DOM updates happen. 45 | */ 46 | def addOnChange(fun: (Editor, EditorChangeLike)=> Unit) = { 47 | val handler: js.Function2[Editor, _, Unit] = fun 48 | editor.on("change", handler) 49 | } 50 | 51 | def addOnChanges(fun: (Editor, js.Array[EditorChangeLike])=> Unit) = { 52 | val handler: js.Function2[Editor, _, Unit] = fun 53 | editor.on("changes", handler) 54 | } 55 | 56 | /** 57 | * @param fun handler to react BeforeChanges 58 | * This event is fired before a change is applied, 59 | * and its handler may choose to modify or cancel the change. 60 | * The changeObj object has from, to, and text properties, 61 | * as with the "change" event. It also has a cancel() method, 62 | * which can be called to cancel the change, and, 63 | * if the change isn't coming from an undo or redo event, 64 | * an update(from, to, text) method, which may be used to modify the change. 65 | */ 66 | def addBeforeChange(fun: (Editor, EditorChangeLike)=> Unit) = { 67 | val handler: js.Function2[Editor, _, Unit] = fun 68 | editor.on("change", handler) 69 | } 70 | 71 | def lineText(line: Int): String = { 72 | editor.lineInfo(line).text 73 | } 74 | 75 | def linesText(lines: Seq[Int]): Seq[(Int, String)] = lines.map(num => num-> editor.lineText(num)) 76 | 77 | } 78 | 79 | -------------------------------------------------------------------------------- /preview/js/src/main/scala/org/denigma/preview/ExampleData.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import org.denigma.codemirror.extensions.EditorConfig 4 | import org.denigma.codemirror.{CodeMirror, EditorConfiguration} 5 | import org.scalajs.dom 6 | import org.scalajs.dom.raw.HTMLTextAreaElement 7 | 8 | trait ExampleData extends ExampleKappaData { 9 | 10 | lazy val scalaCode = """ 11 | | import org.denigma.org.denigma.codemirror.extensions.EditorConfig 12 | | import org.denigma.org.denigma.codemirror.{CodeMirror, EditorConfiguration} 13 | | import org.scalajs.dom 14 | | import org.scalajs.dom.raw.HTMLTextAreaElement 15 | | 16 | | val id = "scala" 17 | | val code = println("hello Scala!") //code to add 18 | | val mode = "clike" //language mode, some modes have weird names in org.denigma.codemirror 19 | | val params:EditorConfiguration =EditorConfig.mode(mode).lineNumbers(true) //config 20 | | val editor = dom.document.getElementById(id) match { 21 | | case el:HTMLTextAreaElement => 22 | | val m = CodeMirror.fromTextArea(el,params) 23 | | m.getDoc().setValue(code) //add the code 24 | | case _=> dom.console.error("cannot find text area for the code!") 25 | | }""".stripMargin 26 | 27 | 28 | 29 | lazy val htmlCode ="""""".stripMargin 30 | 31 | lazy val rCode = 32 | """ 33 | |print("Hello R language!") 34 | |cat("Your height is ", X$height, " and your weight is ", X$weight, "\n") 35 | """.stripMargin 36 | 37 | lazy val turtleCode = 38 | """ 39 | |@prefix foaf: . 40 | |@prefix geo: . 41 | |@prefix rdf: . 42 | | 43 | | 44 | | a foaf:Person; 45 | | foaf:interest ; 46 | | foaf:based_near [ 47 | | geo:lat "34.0736111" ; 48 | | geo:lon "-118.3994444" 49 | | ] 50 | """.stripMargin 51 | 52 | 53 | lazy val sparqlCode = 54 | """ 55 | |PREFIX a: 56 | |PREFIX dc: 57 | |PREFIX foaf: 58 | |PREFIX rdfs: 59 | | 60 | |# Comment! 61 | | 62 | |SELECT ?given ?family 63 | |WHERE { 64 | | { 65 | | ?annot a:annotates . 66 | | ?annot dc:creator ?c . 67 | | OPTIONAL {?c foaf:givenName ?given ; 68 | | foaf:familyName ?family } 69 | | } UNION { 70 | | ?c !foaf:knows/foaf:knows? ?thing. 71 | | ?thing rdfs 72 | | } MINUS { 73 | | ?thing rdfs:label "剛柔流"@jp 74 | | } 75 | | FILTER isBlank(?c) 76 | |} 77 | """.stripMargin 78 | 79 | } 80 | 81 | trait ExampleKappaData{ 82 | 83 | 84 | lazy val kappaCode = 85 | """ 86 | | ####### TEMPLATE MODEL AS DESCRIBED IN THE MANUAL############# 87 | | 88 | |#### Signatures 89 | |%agent: A(x,c) # Declaration of agent A 90 | |%agent: B(x) # Declaration of B 91 | |%agent: C(x1~u~p,x2~u~p) # Declaration of C with 2 modifiable sites 92 | | 93 | |#### Rules 94 | |'a.b' A(x),B(x) <-> A(x!1),B(x!1) @ 'on_rate','off_rate' #A binds B 95 | |'ab.c' A(x!_,c),C(x1~u) ->A(x!_,c!2),C(x1~u!2) @ 'on_rate' #AB binds C 96 | |'mod x1' C(x1~u!1),A(c!1) ->C(x1~p),A(c) @ 'mod_rate' #AB modifies x1 97 | |'a.c' A(x,c),C(x1~p,x2~u) -> A(x,c!1),C(x1~p,x2~u!1) @ 'on_rate' #A binds C on x2 98 | |'mod x2' A(x,c!1),C(x1~p,x2~u!1) -> A(x,c),C(x1~p,x2~p) @ 'mod_rate' #A modifies x2 99 | | 100 | |#### Variables 101 | |%var: 'on_rate' 1.0E-4 # per molecule per second 102 | |%var: 'off_rate' 0.1 # per second 103 | |%var: 'mod_rate' 1 # per second 104 | |%obs: 'AB' A(x!x.B) 105 | |%obs: 'Cuu' C(x1~u?,x2~u?) 106 | |%obs: 'Cpu' C(x1~p?,x2~u?) 107 | |%obs: 'Cpp' C(x1~p?,x2~p?) 108 | | 109 | | 110 | |#### Initial conditions 111 | |%init: 1000 A(),B() 112 | |%init: 10000 C() 113 | | 114 | |%mod: [true] do $FLUX "flux.html" [true] 115 | |%mod: [T]>20 do $FLUX "flux.html" [false] 116 | |%def: "relativeFluxMaps" "true" 117 | """.stripMargin 118 | 119 | } -------------------------------------------------------------------------------- /preview/js/src/main/scala/org/denigma/preview/FeaturesView.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.preview 2 | 3 | import org.denigma.binding.binders.ReactiveBinder 4 | import org.denigma.binding.views.BindableView 5 | import org.denigma.codemirror.{LineInfo, Editor, CodeMirror, EditorConfiguration} 6 | import org.denigma.codemirror.extensions.EditorConfig 7 | import org.scalajs.dom 8 | import org.scalajs.dom.html.Anchor 9 | import org.scalajs.dom.raw.{Element, HTMLTextAreaElement} 10 | import rx.Var 11 | import scala.scalajs.js.JSConverters._ 12 | import scala.scalajs.js 13 | import org.denigma.codemirror._ 14 | import org.denigma.codemirror.extensions._ 15 | import scalatags.JsDom.all._ 16 | import org.denigma.binding.extensions._ 17 | import scalatags.JsDom.all._ 18 | import fastparse.all._ 19 | 20 | trait CommentsParser 21 | { 22 | val comment = P( "##" | "#^" | "#" ) 23 | val notComment = P( ! comment ).flatMap(v => AnyChar) 24 | val bracketsOrSpace = P("<" | ">" | " ") 25 | val notBracketsOrSpace = CharPred(ch => ch != '<' && ch != '>' && ch != ' ') 26 | val protocol = P( ("http" | "ftp" ) ~ "s".? ~ "://" ) 27 | val link: P[String] = P("<".? ~ (protocol ~ notBracketsOrSpace.rep).! ~ ">".? ) //map(_.toString) 28 | val linkAfterComment = P( notComment.rep ~ comment ~ " ".rep ~ link ) 29 | } 30 | 31 | case object FeaturesParser extends CommentsParser { 32 | def parse(str: String) = linkAfterComment.parse(str) 33 | } 34 | 35 | /** 36 | * Created by antonkulaga on 2/24/16. 37 | */ 38 | class FeaturesView(val elem: Element) extends BindableView with EditorView with ExampleKappaData{ 39 | 40 | //val linkParser = P( "a" ) 41 | 42 | 43 | val defaultText: String = kappaCode 44 | 45 | override def mode = "Kappa" 46 | 47 | override def addEditor(name: String, element: ViewElement, codeMode: String): Unit = element match { 48 | case area: HTMLTextAreaElement => 49 | val text = if (area.value == "") defaultText else area.value 50 | editor = this.makeEditor(area, area.value, codeMode) 51 | 52 | case _ => 53 | val message = "cannot find text area for the code!" 54 | throw new Exception(message) 55 | } 56 | 57 | protected def makeMarker(link: String): Anchor = { 58 | val tag = a(href := link, 59 | i(`class` := "file pdf outline icon") 60 | ) 61 | tag.render 62 | 63 | // 64 | } 65 | 66 | changes.onChange{ 67 | case changed => 68 | val (from, to) = changed.foldLeft( (Int.MaxValue, 0)) { 69 | case (acc, ch) => ch.mergeSpans(acc) 70 | } 71 | val lines = from to to 72 | //if(lines.nonEmpty) editor.clearGutter("breakpoints") 73 | for { 74 | (num, line) <- editor.linesText(lines) 75 | } { 76 | //val info: LineInfo = editor.lineInfo(num) 77 | //val markers: js.Array[String] = info.gutterMarkers 78 | FeaturesParser.parse(line) match { 79 | case Parsed.Success(result, index) => 80 | val marker = this.makeMarker(result) 81 | editor.setGutterMarker(num, "breakpoints", marker) 82 | 83 | case Parsed.Failure(parser, index, extra) => 84 | editor.setGutterMarker(num, "breakpoints", null) //test setting null 85 | } 86 | } 87 | } 88 | 89 | gutterClicks.onChange{ 90 | case line => 91 | // val marker = this.makeMarker("https://codemirror.net/demo/marker.html") 92 | // editor.setGutterMarker(line, "breakpoints", marker) 93 | 94 | } 95 | } 96 | 97 | trait EditorView extends BindableView with EditorMaker with WithMirrors{ 98 | 99 | def mode: String = "htmlmixed" 100 | 101 | private var _editor: Editor = null 102 | def editor: Editor = { 103 | if (_editor == null) dom.console.error("editor is NULL!") 104 | _editor 105 | } 106 | 107 | def editor_=(value: Editor): Unit = { 108 | _editor = value 109 | subscribeEditor(_editor) 110 | } 111 | 112 | protected def subscribeEditor(editor: Editor) = { 113 | def onChanges(ed: Editor, ch: js.Array[EditorChangeLike]): Unit = { 114 | changes() = ch 115 | } 116 | def onGutterClick(ed: Editor, line: Int): Unit = { 117 | gutterClicks() = line 118 | } 119 | //editor.addOnChange(onChange) 120 | editor.addOnGutterClick(onGutterClick) 121 | editor.addOnChanges(onChanges) 122 | } 123 | 124 | lazy val changes: Var[js.Array[EditorChangeLike]] = Var(js.Array()) 125 | lazy val gutterClicks: Var[Int] = Var(0) 126 | 127 | def contains(name: String): Boolean = if (_editor==null) false else { 128 | println("warning: editor view already contains an editor") 129 | true 130 | } 131 | 132 | withBinder(new EditorsBinder(_, mode)) 133 | 134 | } 135 | 136 | 137 | trait WithMirrors extends BindableView { 138 | 139 | def contains(name: String): Boolean 140 | 141 | def addEditor(name: String, element: Element, codeMode: String): Unit 142 | 143 | } 144 | 145 | 146 | trait EditorMaker { 147 | 148 | def makeEditor(area: HTMLTextAreaElement, textValue: String, codeMode: String, readOnly: Boolean = false): Editor = { 149 | val params = EditorConfig 150 | .mode(codeMode) 151 | .lineNumbers(true) 152 | .value(textValue) 153 | .readOnly(readOnly) 154 | .viewportMargin(Integer.MAX_VALUE) 155 | .gutters(js.Array("CodeMirror-linenumbers", "breakpoints")) 156 | // gutters: ["CodeMirror-linenumbers", "breakpoints"] 157 | 158 | CodeMirror.fromTextArea(area, params) 159 | } 160 | 161 | } 162 | 163 | class EditorsBinder(view: WithMirrors, defaultMode: String = "htmlmixed") extends ReactiveBinder 164 | { 165 | 166 | override def bindAttributes(el: Element, attributes: Map[String, String]): Boolean= { 167 | val ats = this.dataAttributesOnly(attributes) 168 | val fun: PartialFunction[(String, String), Unit] = elementPartial(el, ats).orElse{case other =>} 169 | ats.foreach(fun) 170 | true 171 | } 172 | 173 | override def elementPartial(el: Element, ats: Map[String, String]): PartialFunction[(String, String), Unit] = { 174 | case ("editor", v) if !view.contains(v) => 175 | //println(s"adding editor for name $value") 176 | view.addEditor(v, el, ats.getOrElse("mode", defaultMode)) 177 | 178 | } 179 | } -------------------------------------------------------------------------------- /preview/js/src/main/resources/addons/simple.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/org.denigma.codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/org.denigma.codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineSimpleMode = function(name, states) { 15 | CodeMirror.defineMode(name, function(config) { 16 | return CodeMirror.simpleMode(config, states); 17 | }); 18 | }; 19 | 20 | CodeMirror.simpleMode = function(config, states) { 21 | ensureState(states, "start"); 22 | var states_ = {}, meta = states.meta || {}, hasIndentation = false; 23 | for (var state in states) if (state != meta && states.hasOwnProperty(state)) { 24 | var list = states_[state] = [], orig = states[state]; 25 | for (var i = 0; i < orig.length; i++) { 26 | var data = orig[i]; 27 | list.push(new Rule(data, states)); 28 | if (data.indent || data.dedent) hasIndentation = true; 29 | } 30 | } 31 | var mode = { 32 | startState: function() { 33 | return {state: "start", pending: null, 34 | local: null, localState: null, 35 | indent: hasIndentation ? [] : null}; 36 | }, 37 | copyState: function(state) { 38 | var s = {state: state.state, pending: state.pending, 39 | local: state.local, localState: null, 40 | indent: state.indent && state.indent.slice(0)}; 41 | if (state.localState) 42 | s.localState = CodeMirror.copyState(state.local.mode, state.localState); 43 | if (state.stack) 44 | s.stack = state.stack.slice(0); 45 | for (var pers = state.persistentStates; pers; pers = pers.next) 46 | s.persistentStates = {mode: pers.mode, 47 | spec: pers.spec, 48 | state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state), 49 | next: s.persistentStates}; 50 | return s; 51 | }, 52 | token: tokenFunction(states_, config), 53 | innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; }, 54 | indent: indentFunction(states_, meta) 55 | }; 56 | if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop)) 57 | mode[prop] = meta[prop]; 58 | return mode; 59 | }; 60 | 61 | function ensureState(states, name) { 62 | if (!states.hasOwnProperty(name)) 63 | throw new Error("Undefined state " + name + " in simple mode"); 64 | } 65 | 66 | function toRegex(val, caret) { 67 | if (!val) return /(?:)/; 68 | var flags = ""; 69 | if (val instanceof RegExp) { 70 | if (val.ignoreCase) flags = "i"; 71 | val = val.source; 72 | } else { 73 | val = String(val); 74 | } 75 | return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags); 76 | } 77 | 78 | function asToken(val) { 79 | if (!val) return null; 80 | if (typeof val == "string") return val.replace(/\./g, " "); 81 | var result = []; 82 | for (var i = 0; i < val.length; i++) 83 | result.push(val[i] && val[i].replace(/\./g, " ")); 84 | return result; 85 | } 86 | 87 | function Rule(data, states) { 88 | if (data.next || data.push) ensureState(states, data.next || data.push); 89 | this.regex = toRegex(data.regex); 90 | this.token = asToken(data.token); 91 | this.data = data; 92 | } 93 | 94 | function tokenFunction(states, config) { 95 | return function(stream, state) { 96 | if (state.pending) { 97 | var pend = state.pending.shift(); 98 | if (state.pending.length == 0) state.pending = null; 99 | stream.pos += pend.text.length; 100 | return pend.token; 101 | } 102 | 103 | if (state.local) { 104 | if (state.local.end && stream.match(state.local.end)) { 105 | var tok = state.local.endToken || null; 106 | state.local = state.localState = null; 107 | return tok; 108 | } else { 109 | var tok = state.local.mode.token(stream, state.localState), m; 110 | if (state.local.endScan && (m = state.local.endScan.exec(stream.current()))) 111 | stream.pos = stream.start + m.index; 112 | return tok; 113 | } 114 | } 115 | 116 | var curState = states[state.state]; 117 | for (var i = 0; i < curState.length; i++) { 118 | var rule = curState[i]; 119 | var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex); 120 | if (matches) { 121 | if (rule.data.next) { 122 | state.state = rule.data.next; 123 | } else if (rule.data.push) { 124 | (state.stack || (state.stack = [])).push(state.state); 125 | state.state = rule.data.push; 126 | } else if (rule.data.pop && state.stack && state.stack.length) { 127 | state.state = state.stack.pop(); 128 | } 129 | 130 | if (rule.data.mode) 131 | enterLocalMode(config, state, rule.data.mode, rule.token); 132 | if (rule.data.indent) 133 | state.indent.push(stream.indentation() + config.indentUnit); 134 | if (rule.data.dedent) 135 | state.indent.pop(); 136 | if (matches.length > 2) { 137 | state.pending = []; 138 | for (var j = 2; j < matches.length; j++) 139 | if (matches[j]) 140 | state.pending.push({text: matches[j], token: rule.token[j - 1]}); 141 | stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0)); 142 | return rule.token[0]; 143 | } else if (rule.token && rule.token.join) { 144 | return rule.token[0]; 145 | } else { 146 | return rule.token; 147 | } 148 | } 149 | } 150 | stream.next(); 151 | return null; 152 | }; 153 | } 154 | 155 | function cmp(a, b) { 156 | if (a === b) return true; 157 | if (!a || typeof a != "object" || !b || typeof b != "object") return false; 158 | var props = 0; 159 | for (var prop in a) if (a.hasOwnProperty(prop)) { 160 | if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false; 161 | props++; 162 | } 163 | for (var prop in b) if (b.hasOwnProperty(prop)) props--; 164 | return props == 0; 165 | } 166 | 167 | function enterLocalMode(config, state, spec, token) { 168 | var pers; 169 | if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next) 170 | if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p; 171 | var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec); 172 | var lState = pers ? pers.state : CodeMirror.startState(mode); 173 | if (spec.persistent && !pers) 174 | state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates}; 175 | 176 | state.localState = lState; 177 | state.local = {mode: mode, 178 | end: spec.end && toRegex(spec.end), 179 | endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false), 180 | endToken: token && token.join ? token[token.length - 1] : token}; 181 | } 182 | 183 | function indexOf(val, arr) { 184 | for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true; 185 | } 186 | 187 | function indentFunction(states, meta) { 188 | return function(state, textAfter, line) { 189 | if (state.local && state.local.mode.indent) 190 | return state.local.mode.indent(state.localState, textAfter, line); 191 | if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1) 192 | return CodeMirror.Pass; 193 | 194 | var pos = state.indent.length - 1, rules = states[state.state]; 195 | scan: for (;;) { 196 | for (var i = 0; i < rules.length; i++) { 197 | var rule = rules[i]; 198 | if (rule.data.dedent && rule.data.dedentIfLineStart !== false) { 199 | var m = rule.regex.exec(textAfter); 200 | if (m && m[0]) { 201 | pos--; 202 | if (rule.next || rule.push) rules = states[rule.next || rule.push]; 203 | textAfter = textAfter.slice(m[0].length); 204 | continue scan; 205 | } 206 | } 207 | } 208 | break; 209 | } 210 | return pos < 0 ? 0 : state.indent[pos]; 211 | }; 212 | } 213 | }); 214 | -------------------------------------------------------------------------------- /facade/src/main/scala/org/denigma/codemirror/Editor.scala: -------------------------------------------------------------------------------- 1 | package org.denigma.codemirror 2 | 3 | import org.scalajs._ 4 | import org.scalajs.dom.raw.{Event, HTMLElement, HTMLTextAreaElement} 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js._ 8 | import scala.scalajs.js.annotation.{JSGlobal, JSName, ScalaJSDefined} 9 | 10 | @js.native 11 | trait LineInfo extends js.Object { 12 | 13 | val line: Int = js.native 14 | val handle: LineHandle = js.native 15 | val text: String = js.native 16 | val gutterMarkers: js.Array[String] = js.native 17 | val textClass: String = js.native 18 | val bgClass: String = js.native 19 | val wrapClass: String = js.native 20 | val widgets: js.Array[String] = js.native 21 | 22 | /* return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers, 23 | textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass, 24 | widgets: line.widgets};*/ 25 | } 26 | 27 | @js.native 28 | trait Editor extends js.Object { 29 | def hasFocus(): Boolean = js.native 30 | def findPosH(start: Position, amount: Double, unit: String, visually: Boolean): js.Any = js.native 31 | def findPosV(start: Position, amount: Double, unit: String): js.Any = js.native 32 | def setOption(option: String, value: js.Any): Unit = js.native 33 | def getOption(option: String): js.Dynamic = js.native 34 | def addKeyMap(map: js.Any, bottom: Boolean = js.native): Unit = js.native 35 | def removeKeyMap(map: js.Any): Unit = js.native 36 | def addOverlay(mode: js.Any, options: js.Any = js.native): Unit = js.native 37 | def removeOverlay(mode: js.Any): Unit = js.native 38 | def getDoc(): Doc = js.native 39 | def swapDoc(doc: Doc): Doc = js.native 40 | def setGutterMarker(line: Int, gutterID: String, value: HTMLElement): LineHandle = js.native 41 | def clearGutter(gutterID: String): Unit = js.native 42 | def addLineClass(line: js.Any, where: String, _clazz: String): LineHandle = js.native 43 | def removeLineClass(line: js.Any, where: String, clazz: String): LineHandle = js.native 44 | def lineInfo(line: Int): LineInfo = js.native 45 | 46 | def addWidget(pos: Position, node: HTMLElement, scrollIntoView: Boolean): Unit = js.native 47 | def addLineWidget(line: js.Any, node: HTMLElement, options: js.Any = js.native): LineWidget = js.native 48 | def setSize(width: js.Any, height: js.Any): Unit = js.native 49 | def scrollTo(x: Double, y: Double): Unit = js.native 50 | def getScrollInfo(): js.Any = js.native 51 | def scrollIntoView(pos: Position, margin: Double = js.native): Unit = js.native 52 | def cursorCoords(where: Boolean, mode: String): js.Any = js.native 53 | def charCoords(pos: Position, mode: String): js.Any = js.native 54 | def coordsChar(`object`: js.Any, mode: String = js.native): Position = js.native 55 | def defaultTextHeight(): Double = js.native 56 | def defaultCharWidth(): Double = js.native 57 | def getViewport(): js.Any = js.native 58 | def refresh(): Unit = js.native 59 | def getTokenAt(pos: Position): js.Any = js.native 60 | def getStateAfter(line: Double = js.native): js.Dynamic = js.native 61 | def operation[T](fn: js.Function0[T]): T = js.native 62 | def indentLine(line: Double, dir: String = js.native): Unit = js.native 63 | def focus(): Unit = js.native 64 | def getInputField(): HTMLTextAreaElement = js.native 65 | def getWrapperElement(): HTMLElement = js.native 66 | def getScrollerElement(): HTMLElement = js.native 67 | def getGutterElement(): HTMLElement = js.native 68 | def on(eventName: String, handler: js.Function1[Editor, Unit]): Unit = js.native 69 | def on(eventName: String, handler: js.Function2[Editor, _, Unit]): Unit = js.native //not sure if 70 | 71 | def off(eventName: String, handler: js.Function1[Editor, Unit]): Unit = js.native 72 | def off(eventName: String, handler: js.Function2[Editor, Any, Unit]): Unit = js.native 73 | 74 | } 75 | 76 | 77 | @js.native 78 | @JSGlobal("Doc") 79 | class Doc protected () extends js.Object { 80 | def this(text: String, mode: js.Any = js.native, firstLineNumber: Double = js.native) = this() 81 | def getValue(seperator: String = js.native): String = js.native 82 | def setValue(content: String): Unit = js.native 83 | def getRange(from: Position, to: Position, seperator: String = js.native): String = js.native 84 | def replaceRange(replacement: String, from: Position, to: Position): Unit = js.native 85 | def getLine(n: Double): String = js.native 86 | def setLine(n: Double, text: String): Unit = js.native 87 | def removeLine(n: Double): Unit = js.native 88 | def lineCount(): Double = js.native 89 | def firstLine(): Double = js.native 90 | def lastLine(): Double = js.native 91 | def getLineHandle(num: Double): LineHandle = js.native 92 | def getLineNumber(handle: LineHandle): Double = js.native 93 | def eachLine(f: js.Function1[LineHandle, Unit]): Unit = js.native 94 | def eachLine(start: Double, end: Double, f: js.Function1[LineHandle, Unit]): Unit = js.native 95 | def markClean(): Unit = js.native 96 | def isClean(): Boolean = js.native 97 | def getSelection(): String = js.native 98 | def replaceSelection(replacement: String, collapse: String = js.native): Unit = js.native 99 | def getCursor(start: String = js.native): Position = js.native 100 | def somethingSelected(): Boolean = js.native 101 | def setCursor(pos: Position): Unit = js.native 102 | def setSelection(anchor: Position, head: Position): Unit = js.native 103 | def extendSelection(from: Position, to: Position = js.native): Unit = js.native 104 | def setExtending(value: Boolean): Unit = js.native 105 | def getEditor(): Editor = js.native 106 | def copy(copyHistory: Boolean): Doc = js.native 107 | def linkedDoc(options: js.Any): Doc = js.native 108 | def unlinkDoc(doc: Doc): Unit = js.native 109 | def iterLinkedDocs(fn: js.Function2[Doc, Boolean, Unit]): Unit = js.native 110 | def undo(): Unit = js.native 111 | def redo(): Unit = js.native 112 | def historySize(): js.Any = js.native 113 | def clearHistory(): Unit = js.native 114 | def getHistory(): js.Dynamic = js.native 115 | def setHistory(history: js.Any): Unit = js.native 116 | def markText(from: Position, to: Position, options: TextMarkerOptions = js.native): TextMarker = js.native 117 | def setBookmark(pos: Position, options: js.Any = js.native): TextMarker = js.native 118 | def findMarksAt(pos: Position): js.Array[TextMarker] = js.native 119 | def getAllMarks(): js.Array[TextMarker] = js.native 120 | def getMode(): js.Dynamic = js.native 121 | def posFromIndex(index: Double): Position = js.native 122 | def indexFromPos(`object`: Position): Double = js.native 123 | } 124 | 125 | @js.native 126 | trait LineHandle extends js.Object { 127 | var text: String = js.native 128 | } 129 | 130 | @js.native 131 | trait TextMarker extends js.Object { 132 | def clear(): Unit = js.native 133 | def find(): Position = js.native 134 | def getOptions(copyWidget: Boolean): TextMarkerOptions = js.native 135 | } 136 | 137 | @js.native 138 | trait LineWidget extends js.Object { 139 | def clear(): Unit = js.native 140 | def changed(): Unit = js.native 141 | } 142 | 143 | object EditorChangeLike { 144 | lazy val empty: EditorChangeLike = new EditorChangeLike { 145 | val text: Array[String] = js.Array() 146 | val from: PositionLike = PositionLike.empty 147 | val to: PositionLike = PositionLike.empty 148 | val removed: js.Array[String] = js.Array() 149 | val origin: String = "" 150 | } 151 | } 152 | 153 | //an interface for editor changing events 154 | @ScalaJSDefined 155 | trait EditorChangeLike extends js.Object{ 156 | val from: PositionLike 157 | val to: PositionLike 158 | val text: js.Array[String] 159 | val removed: js.Array[String] 160 | val origin: String 161 | } 162 | 163 | @js.native 164 | trait EditorChange extends EditorChangeLike{ 165 | val from: Position = js.native 166 | val to: Position = js.native 167 | val text: js.Array[String] = js.native 168 | val removed: js.Array[String] = js.native 169 | val origin: String = js.native 170 | } 171 | 172 | @js.native 173 | trait EditorChangeLinkedList extends EditorChange { 174 | var next: EditorChangeLinkedList = js.native 175 | } 176 | 177 | @js.native 178 | trait EditorChangeCancellable extends EditorChange { 179 | def update(from: Position = js.native, to: Position = js.native, text: String = js.native): Unit = js.native 180 | def cancel(): Unit = js.native 181 | } 182 | 183 | object PositionLike { 184 | lazy val empty = new PositionLike { 185 | val ch = 0 186 | val line = 0 187 | } 188 | } 189 | //interface to deal zith Positions 190 | @ScalaJSDefined 191 | trait PositionLike extends js.Object{ 192 | val ch: Int 193 | val line: Int 194 | } 195 | 196 | @js.native 197 | trait Position extends PositionLike{ 198 | val ch: Int = js.native 199 | val line: Int = js.native 200 | } 201 | 202 | @js.native 203 | trait EditorConfiguration extends js.Object { 204 | var value: js.Any = js.native 205 | var mode: js.Any = js.native 206 | var theme: String = js.native 207 | var indentUnit: Double = js.native 208 | var smartIndent: Boolean = js.native 209 | var tabSize: Double = js.native 210 | var indentWithTabs: Boolean = js.native 211 | var electricChars: Boolean = js.native 212 | var rtlMoveVisually: Boolean = js.native 213 | var keyMap: String = js.native 214 | var extraKeys: js.Any = js.native 215 | var lineWrapping: Boolean = js.native 216 | var lineNumbers: Boolean = js.native 217 | var firstLineNumber: Int = js.native 218 | var lineNumberFormatter: js.Function1[Double, String] = js.native 219 | var gutters: js.Array[String] = js.native 220 | var fixedGutter: Boolean = js.native 221 | var readOnly: js.Any = js.native 222 | var showCursorWhenSelecting: Boolean = js.native 223 | var undoDepth: Int = js.native 224 | var historyEventDelay: Double = js.native 225 | var tabindex: Int = js.native 226 | var autofocus: Boolean = js.native 227 | var dragDrop: Boolean = js.native 228 | var onDragEvent: js.Function2[Editor, Event, Boolean] = js.native 229 | var onKeyEvent: js.Function2[Editor, Event, Boolean] = js.native 230 | var cursorBlinkRate: Double = js.native 231 | var cursorHeight: Double = js.native 232 | var workTime: Double = js.native 233 | var workDelay: Double = js.native 234 | var pollInterval: Double = js.native 235 | var flattenSpans: Boolean = js.native 236 | var maxHighlightLength: Double = js.native 237 | var viewportMargin: Double = js.native 238 | } 239 | 240 | @js.native 241 | trait TextMarkerOptions extends js.Object { 242 | var className: String = js.native 243 | var inclusiveLeft: Boolean = js.native 244 | var inclusiveRight: Boolean = js.native 245 | var atomic: Boolean = js.native 246 | var collapsed: Boolean = js.native 247 | var clearOnEnter: Boolean = js.native 248 | var replacedWith: HTMLElement = js.native 249 | var readOnly: Boolean = js.native 250 | var addToHistory: Boolean = js.native 251 | var startStyle: String = js.native 252 | var endStyle: String = js.native 253 | var shared: Boolean = js.native 254 | } 255 | 256 | @js.native 257 | @JSGlobal("CodeMirror") 258 | object CodeMirror extends js.Object { 259 | var Pass: js.Any = js.native 260 | def fromTextArea(host: HTMLTextAreaElement, options: EditorConfiguration = js.native): Editor = js.native 261 | //def fromTextArea(host: HTMLTextAreaElement, options: js.Any): Editor = js.native 262 | 263 | var version: String = js.native 264 | def defineExtension(name: String, value: js.Any): Unit = js.native 265 | def defineDocExtension(name: String, value: js.Any): Unit = js.native 266 | def defineOption(name: String, default: js.Any, updateFunc: js.Function): Unit = js.native 267 | def defineInitHook(func: js.Function): Unit = js.native 268 | def on(element: js.Any, eventName: String, handler: js.Function): Unit = js.native 269 | def off(element: js.Any, eventName: String, handler: js.Function): Unit = js.native 270 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License, version 2.0 2 | 3 | 1. Definitions 4 | 5 | 1.1. "Contributor" 6 | 7 | means each individual or legal entity that creates, contributes to the 8 | creation of, or owns Covered Software. 9 | 10 | 1.2. "Contributor Version" 11 | 12 | means the combination of the Contributions of others (if any) used by a 13 | Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | 17 | means Covered Software of a particular Contributor. 18 | 19 | 1.4. "Covered Software" 20 | 21 | means Source Code Form to which the initial Contributor has attached the 22 | notice in Exhibit A, the Executable Form of such Source Code Form, and 23 | Modifications of such Source Code Form, in each case including portions 24 | thereof. 25 | 26 | 1.5. "Incompatible With Secondary Licenses" 27 | means 28 | 29 | a. that the initial Contributor has attached the notice described in 30 | Exhibit B to the Covered Software; or 31 | 32 | b. that the Covered Software was made available under the terms of 33 | version 1.1 or earlier of the License, but not also under the terms of 34 | a Secondary License. 35 | 36 | 1.6. "Executable Form" 37 | 38 | means any form of the work other than Source Code Form. 39 | 40 | 1.7. "Larger Work" 41 | 42 | means a work that combines Covered Software with other material, in a 43 | separate file or files, that is not Covered Software. 44 | 45 | 1.8. "License" 46 | 47 | means this document. 48 | 49 | 1.9. "Licensable" 50 | 51 | means having the right to grant, to the maximum extent possible, whether 52 | at the time of the initial grant or subsequently, any and all of the 53 | rights conveyed by this License. 54 | 55 | 1.10. "Modifications" 56 | 57 | means any of the following: 58 | 59 | a. any file in Source Code Form that results from an addition to, 60 | deletion from, or modification of the contents of Covered Software; or 61 | 62 | b. any new file in Source Code Form that contains any Covered Software. 63 | 64 | 1.11. "Patent Claims" of a Contributor 65 | 66 | means any patent claim(s), including without limitation, method, 67 | process, and apparatus claims, in any patent Licensable by such 68 | Contributor that would be infringed, but for the grant of the License, 69 | by the making, using, selling, offering for sale, having made, import, 70 | or transfer of either its Contributions or its Contributor Version. 71 | 72 | 1.12. "Secondary License" 73 | 74 | means either the GNU General Public License, Version 2.0, the GNU Lesser 75 | General Public License, Version 2.1, the GNU Affero General Public 76 | License, Version 3.0, or any later versions of those licenses. 77 | 78 | 1.13. "Source Code Form" 79 | 80 | means the form of the work preferred for making modifications. 81 | 82 | 1.14. "You" (or "Your") 83 | 84 | means an individual or a legal entity exercising rights under this 85 | License. For legal entities, "You" includes any entity that controls, is 86 | controlled by, or is under common control with You. For purposes of this 87 | definition, "control" means (a) the power, direct or indirect, to cause 88 | the direction or management of such entity, whether by contract or 89 | otherwise, or (b) ownership of more than fifty percent (50%) of the 90 | outstanding shares or beneficial ownership of such entity. 91 | 92 | 93 | 2. License Grants and Conditions 94 | 95 | 2.1. Grants 96 | 97 | Each Contributor hereby grants You a world-wide, royalty-free, 98 | non-exclusive license: 99 | 100 | a. under intellectual property rights (other than patent or trademark) 101 | Licensable by such Contributor to use, reproduce, make available, 102 | modify, display, perform, distribute, and otherwise exploit its 103 | Contributions, either on an unmodified basis, with Modifications, or 104 | as part of a Larger Work; and 105 | 106 | b. under Patent Claims of such Contributor to make, use, sell, offer for 107 | sale, have made, import, and otherwise transfer either its 108 | Contributions or its Contributor Version. 109 | 110 | 2.2. Effective Date 111 | 112 | The licenses granted in Section 2.1 with respect to any Contribution 113 | become effective for each Contribution on the date the Contributor first 114 | distributes such Contribution. 115 | 116 | 2.3. Limitations on Grant Scope 117 | 118 | The licenses granted in this Section 2 are the only rights granted under 119 | this License. No additional rights or licenses will be implied from the 120 | distribution or licensing of Covered Software under this License. 121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 122 | Contributor: 123 | 124 | a. for any code that a Contributor has removed from Covered Software; or 125 | 126 | b. for infringements caused by: (i) Your and any other third party's 127 | modifications of Covered Software, or (ii) the combination of its 128 | Contributions with other software (except as part of its Contributor 129 | Version); or 130 | 131 | c. under Patent Claims infringed by Covered Software in the absence of 132 | its Contributions. 133 | 134 | This License does not grant any rights in the trademarks, service marks, 135 | or logos of any Contributor (except as may be necessary to comply with 136 | the notice requirements in Section 3.4). 137 | 138 | 2.4. Subsequent Licenses 139 | 140 | No Contributor makes additional grants as a result of Your choice to 141 | distribute the Covered Software under a subsequent version of this 142 | License (see Section 10.2) or under the terms of a Secondary License (if 143 | permitted under the terms of Section 3.3). 144 | 145 | 2.5. Representation 146 | 147 | Each Contributor represents that the Contributor believes its 148 | Contributions are its original creation(s) or it has sufficient rights to 149 | grant the rights to its Contributions conveyed by this License. 150 | 151 | 2.6. Fair Use 152 | 153 | This License is not intended to limit any rights You have under 154 | applicable copyright doctrines of fair use, fair dealing, or other 155 | equivalents. 156 | 157 | 2.7. Conditions 158 | 159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 160 | Section 2.1. 161 | 162 | 163 | 3. Responsibilities 164 | 165 | 3.1. Distribution of Source Form 166 | 167 | All distribution of Covered Software in Source Code Form, including any 168 | Modifications that You create or to which You contribute, must be under 169 | the terms of this License. You must inform recipients that the Source 170 | Code Form of the Covered Software is governed by the terms of this 171 | License, and how they can obtain a copy of this License. You may not 172 | attempt to alter or restrict the recipients' rights in the Source Code 173 | Form. 174 | 175 | 3.2. Distribution of Executable Form 176 | 177 | If You distribute Covered Software in Executable Form then: 178 | 179 | a. such Covered Software must also be made available in Source Code Form, 180 | as described in Section 3.1, and You must inform recipients of the 181 | Executable Form how they can obtain a copy of such Source Code Form by 182 | reasonable means in a timely manner, at a charge no more than the cost 183 | of distribution to the recipient; and 184 | 185 | b. You may distribute such Executable Form under the terms of this 186 | License, or sublicense it under different terms, provided that the 187 | license for the Executable Form does not attempt to limit or alter the 188 | recipients' rights in the Source Code Form under this License. 189 | 190 | 3.3. Distribution of a Larger Work 191 | 192 | You may create and distribute a Larger Work under terms of Your choice, 193 | provided that You also comply with the requirements of this License for 194 | the Covered Software. If the Larger Work is a combination of Covered 195 | Software with a work governed by one or more Secondary Licenses, and the 196 | Covered Software is not Incompatible With Secondary Licenses, this 197 | License permits You to additionally distribute such Covered Software 198 | under the terms of such Secondary License(s), so that the recipient of 199 | the Larger Work may, at their option, further distribute the Covered 200 | Software under the terms of either this License or such Secondary 201 | License(s). 202 | 203 | 3.4. Notices 204 | 205 | You may not remove or alter the substance of any license notices 206 | (including copyright notices, patent notices, disclaimers of warranty, or 207 | limitations of liability) contained within the Source Code Form of the 208 | Covered Software, except that You may alter any license notices to the 209 | extent required to remedy known factual inaccuracies. 210 | 211 | 3.5. Application of Additional Terms 212 | 213 | You may choose to offer, and to charge a fee for, warranty, support, 214 | indemnity or liability obligations to one or more recipients of Covered 215 | Software. However, You may do so only on Your own behalf, and not on 216 | behalf of any Contributor. You must make it absolutely clear that any 217 | such warranty, support, indemnity, or liability obligation is offered by 218 | You alone, and You hereby agree to indemnify every Contributor for any 219 | liability incurred by such Contributor as a result of warranty, support, 220 | indemnity or liability terms You offer. You may include additional 221 | disclaimers of warranty and limitations of liability specific to any 222 | jurisdiction. 223 | 224 | 4. Inability to Comply Due to Statute or Regulation 225 | 226 | If it is impossible for You to comply with any of the terms of this License 227 | with respect to some or all of the Covered Software due to statute, 228 | judicial order, or regulation then You must: (a) comply with the terms of 229 | this License to the maximum extent possible; and (b) describe the 230 | limitations and the code they affect. Such description must be placed in a 231 | text file included with all distributions of the Covered Software under 232 | this License. Except to the extent prohibited by statute or regulation, 233 | such description must be sufficiently detailed for a recipient of ordinary 234 | skill to be able to understand it. 235 | 236 | 5. Termination 237 | 238 | 5.1. The rights granted under this License will terminate automatically if You 239 | fail to comply with any of its terms. However, if You become compliant, 240 | then the rights granted under this License from a particular Contributor 241 | are reinstated (a) provisionally, unless and until such Contributor 242 | explicitly and finally terminates Your grants, and (b) on an ongoing 243 | basis, if such Contributor fails to notify You of the non-compliance by 244 | some reasonable means prior to 60 days after You have come back into 245 | compliance. Moreover, Your grants from a particular Contributor are 246 | reinstated on an ongoing basis if such Contributor notifies You of the 247 | non-compliance by some reasonable means, this is the first time You have 248 | received notice of non-compliance with this License from such 249 | Contributor, and You become compliant prior to 30 days after Your receipt 250 | of the notice. 251 | 252 | 5.2. If You initiate litigation against any entity by asserting a patent 253 | infringement claim (excluding declaratory judgment actions, 254 | counter-claims, and cross-claims) alleging that a Contributor Version 255 | directly or indirectly infringes any patent, then the rights granted to 256 | You by any and all Contributors for the Covered Software under Section 257 | 2.1 of this License shall terminate. 258 | 259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 260 | license agreements (excluding distributors and resellers) which have been 261 | validly granted by You or Your distributors under this License prior to 262 | termination shall survive termination. 263 | 264 | 6. Disclaimer of Warranty 265 | 266 | Covered Software is provided under this License on an "as is" basis, 267 | without warranty of any kind, either expressed, implied, or statutory, 268 | including, without limitation, warranties that the Covered Software is free 269 | of defects, merchantable, fit for a particular purpose or non-infringing. 270 | The entire risk as to the quality and performance of the Covered Software 271 | is with You. Should any Covered Software prove defective in any respect, 272 | You (not any Contributor) assume the cost of any necessary servicing, 273 | repair, or correction. This disclaimer of warranty constitutes an essential 274 | part of this License. No use of any Covered Software is authorized under 275 | this License except under this disclaimer. 276 | 277 | 7. Limitation of Liability 278 | 279 | Under no circumstances and under no legal theory, whether tort (including 280 | negligence), contract, or otherwise, shall any Contributor, or anyone who 281 | distributes Covered Software as permitted above, be liable to You for any 282 | direct, indirect, special, incidental, or consequential damages of any 283 | character including, without limitation, damages for lost profits, loss of 284 | goodwill, work stoppage, computer failure or malfunction, or any and all 285 | other commercial damages or losses, even if such party shall have been 286 | informed of the possibility of such damages. This limitation of liability 287 | shall not apply to liability for death or personal injury resulting from 288 | such party's negligence to the extent applicable law prohibits such 289 | limitation. Some jurisdictions do not allow the exclusion or limitation of 290 | incidental or consequential damages, so this exclusion and limitation may 291 | not apply to You. 292 | 293 | 8. Litigation 294 | 295 | Any litigation relating to this License may be brought only in the courts 296 | of a jurisdiction where the defendant maintains its principal place of 297 | business and such litigation shall be governed by laws of that 298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing 299 | in this Section shall prevent a party's ability to bring cross-claims or 300 | counter-claims. 301 | 302 | 9. Miscellaneous 303 | 304 | This License represents the complete agreement concerning the subject 305 | matter hereof. If any provision of this License is held to be 306 | unenforceable, such provision shall be reformed only to the extent 307 | necessary to make it enforceable. Any law or regulation which provides that 308 | the language of a contract shall be construed against the drafter shall not 309 | be used to construe this License against a Contributor. 310 | 311 | 312 | 10. Versions of the License 313 | 314 | 10.1. New Versions 315 | 316 | Mozilla Foundation is the license steward. Except as provided in Section 317 | 10.3, no one other than the license steward has the right to modify or 318 | publish new versions of this License. Each version will be given a 319 | distinguishing version number. 320 | 321 | 10.2. Effect of New Versions 322 | 323 | You may distribute the Covered Software under the terms of the version 324 | of the License under which You originally received the Covered Software, 325 | or under the terms of any subsequent version published by the license 326 | steward. 327 | 328 | 10.3. Modified Versions 329 | 330 | If you create software not governed by this License, and you want to 331 | create a new license for such software, you may create and use a 332 | modified version of this License if you rename the license and remove 333 | any references to the name of the license steward (except to note that 334 | such modified license differs from this License). 335 | 336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 337 | Licenses If You choose to distribute Source Code Form that is 338 | Incompatible With Secondary Licenses under the terms of this version of 339 | the License, the notice described in Exhibit B of this License must be 340 | attached. 341 | 342 | Exhibit A - Source Code Form License Notice 343 | 344 | This Source Code Form is subject to the 345 | terms of the Mozilla Public License, v. 346 | 2.0. If a copy of the MPL was not 347 | distributed with this file, You can 348 | obtain one at 349 | http://mozilla.org/MPL/2.0/. 350 | 351 | If it is not possible or desirable to put the notice in a particular file, 352 | then You may include the notice in a location (such as a LICENSE file in a 353 | relevant directory) where a recipient would be likely to look for such a 354 | notice. 355 | 356 | You may add additional accurate notices of copyright ownership. 357 | 358 | Exhibit B - "Incompatible With Secondary Licenses" Notice 359 | 360 | This Source Code Form is "Incompatible 361 | With Secondary Licenses", as defined by 362 | the Mozilla Public License, v. 2.0. 363 | 364 | --------------------------------------------------------------------------------