aboutsummaryrefslogtreecommitdiff
path: root/examples/todomvc/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/todomvc/src')
-rw-r--r--examples/todomvc/src/main/kotlin/com/example/Main.kt40
-rw-r--r--examples/todomvc/src/main/kotlin/com/example/Todomvc.kt242
-rw-r--r--examples/todomvc/src/main/web/index.html22
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-app-css/index.css376
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-app-css/package.json58
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-app-css/readme.md28
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-common/base.css141
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-common/base.js249
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-common/package.json54
-rw-r--r--examples/todomvc/src/main/web/node_modules/todomvc-common/readme.md15
-rw-r--r--examples/todomvc/src/main/web/package-lock.json16
-rw-r--r--examples/todomvc/src/main/web/package.json7
-rw-r--r--examples/todomvc/src/test/kotlin/test/com/example/TestUtil.kt32
13 files changed, 1280 insertions, 0 deletions
diff --git a/examples/todomvc/src/main/kotlin/com/example/Main.kt b/examples/todomvc/src/main/kotlin/com/example/Main.kt
new file mode 100644
index 00000000..d8894a4c
--- /dev/null
+++ b/examples/todomvc/src/main/kotlin/com/example/Main.kt
@@ -0,0 +1,40 @@
+package com.example
+
+import pl.treksoft.kvision.ApplicationBase
+import pl.treksoft.kvision.core.KVManager
+import pl.treksoft.kvision.module
+import kotlin.browser.document
+
+fun main(args: Array<String>) {
+ var application: ApplicationBase? = null
+
+ val state: dynamic = module.hot?.let { hot ->
+ hot.accept()
+
+ hot.dispose { data ->
+ data.appState = application?.dispose()
+ KVManager.shutdown()
+ application = null
+ }
+
+ hot.data
+ }
+
+ if (document.body != null) {
+ KVManager.start()
+ application = start(state)
+ } else {
+ KVManager.init()
+ application = null
+ document.addEventListener("DOMContentLoaded", { application = start(state) })
+ }
+}
+
+fun start(state: dynamic): ApplicationBase? {
+ if (document.getElementById("todomvc") == null) return null
+ val application = Todomvc()
+ @Suppress("UnsafeCastFromDynamic")
+ application.start(state?.appState ?: emptyMap())
+ return application
+}
+
diff --git a/examples/todomvc/src/main/kotlin/com/example/Todomvc.kt b/examples/todomvc/src/main/kotlin/com/example/Todomvc.kt
new file mode 100644
index 00000000..76d90716
--- /dev/null
+++ b/examples/todomvc/src/main/kotlin/com/example/Todomvc.kt
@@ -0,0 +1,242 @@
+package com.example
+
+import com.lightningkite.kotlin.observable.list.observableListOf
+import org.w3c.dom.get
+import org.w3c.dom.set
+import pl.treksoft.kvision.ApplicationBase
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.data.DataComponent
+import pl.treksoft.kvision.data.DataContainer
+import pl.treksoft.kvision.form.FieldLabel
+import pl.treksoft.kvision.form.check.CHECKINPUTTYPE
+import pl.treksoft.kvision.form.check.CheckInput
+import pl.treksoft.kvision.form.text.TextInput
+import pl.treksoft.kvision.html.Button
+import pl.treksoft.kvision.html.LIST
+import pl.treksoft.kvision.html.Link
+import pl.treksoft.kvision.html.ListTag
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
+import pl.treksoft.kvision.routing.routing
+import kotlin.browser.localStorage
+
+const val ENTER_KEY = 13
+const val ESCAPE_KEY = 27
+
+class Todo(completed: Boolean, title: String, hidden: Boolean) : DataComponent() {
+ var completed: Boolean by obs(completed)
+ var title: String by obs(title)
+ var hidden: Boolean by obs(hidden)
+}
+
+enum class LISTMODE {
+ ALL,
+ ACTIVE,
+ COMPLETED
+}
+
+class Todomvc : ApplicationBase() {
+
+ private val model = observableListOf<Todo>()
+
+ private val checkAllInput = CheckInput(classes = setOf("toggle-all")).apply {
+ id = "toggle-all"
+ onClick {
+ val value = this.value
+ model.forEach { it.completed = value }
+ }
+ }
+ private val allLink = Link("All", "#!/", classes = setOf("selected"))
+ private val activeLink = Link("Active", "#!/active")
+ private val completedLink = Link("Completed", "#!/completed")
+ private val clearCompletedButton = Button("Clear completed", classes = setOf("clear-completed")).onClick {
+ model.filter { it.completed }.forEach { model.remove(it) }
+ }
+
+ private val countTag = Tag(TAG.STRONG, "0")
+ private val itemsLeftTag = Tag(TAG.SPAN, " items left", classes = setOf("todo-count")).apply {
+ add(countTag)
+ }
+ private var mode: LISTMODE = LISTMODE.ALL
+
+ private val header = genHeader()
+ private val main = genMain()
+ private val footer = genFooter()
+
+ override fun start(state: Map<String, Any>) {
+ val root = Root("todomvc")
+ val section = Tag(TAG.SECTION, classes = setOf("todoapp"))
+ section.add(this.header)
+ section.add(this.main)
+ section.add(this.footer)
+ root.add(section)
+ loadModel()
+ checkModel()
+ routing.on("/", { _ -> all() })
+ .on("/active", { _ -> active() })
+ .on("/completed", { _ -> completed() })
+ .resolve()
+ }
+
+ private fun loadModel() {
+ localStorage.get("todos-kvision")?.let {
+ JSON.parse<Array<dynamic>>(it).map { Todo(it.completed, it.title, false) }.forEach {
+ model.add(it)
+ }
+ }
+ }
+
+ private fun saveModel() {
+ val jsonString = model.map {
+ val array = listOf("title" to it.title, "completed" to it.completed).toTypedArray()
+ JSON.stringify(kotlin.js.json(*array))
+ }.toString()
+ localStorage.set("todos-kvision", jsonString)
+ }
+
+ private fun checkModel() {
+ val countActive = model.filter { !it.completed }.size
+ val countCompleted = model.filter { it.completed }.size
+ this.main.visible = model.isNotEmpty()
+ this.footer.visible = model.isNotEmpty()
+ this.countTag.text = countActive.toString()
+ this.itemsLeftTag.text = when (countActive) {
+ 1 -> " item left"
+ else -> " items left"
+ }
+ this.checkAllInput.value = (countActive == 0)
+ this.clearCompletedButton.visible = countCompleted > 0
+ saveModel()
+ }
+
+ private fun all() {
+ this.mode = LISTMODE.ALL
+ this.allLink.addCssClass("selected")
+ this.activeLink.removeCssClass("selected")
+ this.completedLink.removeCssClass("selected")
+ this.model.forEach { it.hidden = false }
+ }
+
+ private fun active() {
+ this.mode = LISTMODE.ACTIVE
+ this.allLink.removeCssClass("selected")
+ this.activeLink.addCssClass("selected")
+ this.completedLink.removeCssClass("selected")
+ this.model.forEach { it.hidden = it.completed }
+ }
+
+ private fun completed() {
+ this.mode = LISTMODE.COMPLETED
+ this.allLink.removeCssClass("selected")
+ this.activeLink.removeCssClass("selected")
+ this.completedLink.addCssClass("selected")
+ this.model.forEach { it.hidden = !it.completed }
+ }
+
+ private fun genHeader(): Tag {
+ return Tag(TAG.HEADER, classes = setOf("header")).apply {
+ add(Tag(TAG.H1, "todos"))
+ add(TextInput(classes = setOf("new-todo")).apply {
+ placeholder = "What needs to be done?"
+ autofocus = true
+ setEventListener<TextInput> {
+ keydown = { e ->
+ if (e.keyCode == ENTER_KEY) {
+ addTodo(self.value)
+ self.value = null
+ }
+ }
+ }
+ })
+ }
+ }
+
+ private fun addTodo(value: String?) {
+ val v = value?.trim() ?: ""
+ if (v.isNotEmpty()) {
+ model.add(Todo(false, v, mode == LISTMODE.COMPLETED))
+ }
+ }
+
+ private fun editTodo(index: Int, value: String?) {
+ val v = value?.trim() ?: ""
+ if (v.isNotEmpty()) {
+ model[index].title = v
+ } else {
+ model.removeAt(index)
+ }
+ }
+
+ private fun genMain(): Tag {
+ return Tag(TAG.SECTION, classes = setOf("main")).apply {
+ add(checkAllInput)
+ add(FieldLabel("toggle-all", "Mark all as complete"))
+ add(DataContainer(model, { index ->
+ val li = Tag(TAG.LI)
+ li.apply {
+ if (model[index].completed) addCssClass("completed")
+ if (model[index].hidden) addCssClass("hidden")
+ val edit = TextInput(classes = setOf("edit"))
+ val view = Tag(TAG.DIV, classes = setOf("view")).apply {
+ add(CheckInput(
+ CHECKINPUTTYPE.CHECKBOX, model[index].completed, classes = setOf("toggle")
+ ).onClick {
+ model[index].completed = this.value
+ model[index].hidden =
+ mode == LISTMODE.ACTIVE && this.value || mode == LISTMODE.COMPLETED && !this.value
+ })
+ add(Tag(TAG.LABEL, model[index].title).apply {
+ setEventListener<Tag> {
+ dblclick = {
+ li.getElementJQuery()?.addClass("editing")
+ edit.value = model[index].title
+ edit.getElementJQuery()?.focus()
+ }
+ }
+ })
+ add(Button("", classes = setOf("destroy")).onClick {
+ model.removeAt(index)
+ })
+ }
+ edit.setEventListener<TextInput> {
+ blur = {
+ if (li.getElementJQuery()?.hasClass("editing") == true) {
+ li.getElementJQuery()?.removeClass("editing")
+ editTodo(index, self.value)
+ }
+ }
+ keydown = { e ->
+ if (e.keyCode == ENTER_KEY) {
+ li.getElementJQuery()?.removeClass("editing")
+ editTodo(index, self.value)
+ }
+ if (e.keyCode == ESCAPE_KEY) {
+ li.getElementJQuery()?.removeClass("editing")
+ }
+ }
+ }
+ add(view)
+ add(edit)
+ }
+ }, Tag(TAG.UL, classes = setOf("todo-list"))).onUpdate {
+ checkModel()
+ })
+ }
+ }
+
+ private fun genFooter(): Tag {
+ return Tag(TAG.FOOTER, classes = setOf("footer")).apply {
+ add(itemsLeftTag)
+ add(ListTag(LIST.UL, classes = setOf("filters")).apply {
+ add(allLink)
+ add(activeLink)
+ add(completedLink)
+ })
+ add(clearCompletedButton)
+ }
+ }
+
+ override fun dispose(): Map<String, Any> {
+ return mapOf()
+ }
+}
diff --git a/examples/todomvc/src/main/web/index.html b/examples/todomvc/src/main/web/index.html
new file mode 100644
index 00000000..e5ba8812
--- /dev/null
+++ b/examples/todomvc/src/main/web/index.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>KVision • TodoMVC</title>
+ <link rel="stylesheet" href="node_modules/todomvc-common/base.css">
+ <link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
+</head>
+<body>
+<div id="todomvc"></div>
+<footer class="info">
+ <p>Double-click to edit a todo</p>
+ <p>Created by <a href="https://github.com/rjaros">Robert Jaros</a></p>
+ <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
+</footer>
+<!-- Scripts here. Don't remove ↓ -->
+<script src="node_modules/todomvc-common/base.js"></script>
+<script>var KV_NO_BOOTSTRAP_CSS = true;</script>
+<script src="main.bundle.js"></script>
+</body>
+</html>
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-app-css/index.css b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/index.css
new file mode 100644
index 00000000..d8be205a
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/index.css
@@ -0,0 +1,376 @@
+html,
+body {
+ margin: 0;
+ padding: 0;
+}
+
+button {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ background: none;
+ font-size: 100%;
+ vertical-align: baseline;
+ font-family: inherit;
+ font-weight: inherit;
+ color: inherit;
+ -webkit-appearance: none;
+ appearance: none;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
+
+body {
+ font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ line-height: 1.4em;
+ background: #f5f5f5;
+ color: #4d4d4d;
+ min-width: 230px;
+ max-width: 550px;
+ margin: 0 auto;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ font-weight: 300;
+}
+
+:focus {
+ outline: 0;
+}
+
+.hidden {
+ display: none;
+}
+
+.todoapp {
+ background: #fff;
+ margin: 130px 0 40px 0;
+ position: relative;
+ box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
+ 0 25px 50px 0 rgba(0, 0, 0, 0.1);
+}
+
+.todoapp input::-webkit-input-placeholder {
+ font-style: italic;
+ font-weight: 300;
+ color: #e6e6e6;
+}
+
+.todoapp input::-moz-placeholder {
+ font-style: italic;
+ font-weight: 300;
+ color: #e6e6e6;
+}
+
+.todoapp input::input-placeholder {
+ font-style: italic;
+ font-weight: 300;
+ color: #e6e6e6;
+}
+
+.todoapp h1 {
+ position: absolute;
+ top: -155px;
+ width: 100%;
+ font-size: 100px;
+ font-weight: 100;
+ text-align: center;
+ color: rgba(175, 47, 47, 0.15);
+ -webkit-text-rendering: optimizeLegibility;
+ -moz-text-rendering: optimizeLegibility;
+ text-rendering: optimizeLegibility;
+}
+
+.new-todo,
+.edit {
+ position: relative;
+ margin: 0;
+ width: 100%;
+ font-size: 24px;
+ font-family: inherit;
+ font-weight: inherit;
+ line-height: 1.4em;
+ border: 0;
+ color: inherit;
+ padding: 6px;
+ border: 1px solid #999;
+ box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
+ box-sizing: border-box;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
+
+.new-todo {
+ padding: 16px 16px 16px 60px;
+ border: none;
+ background: rgba(0, 0, 0, 0.003);
+ box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
+}
+
+.main {
+ position: relative;
+ z-index: 2;
+ border-top: 1px solid #e6e6e6;
+}
+
+.toggle-all {
+ text-align: center;
+ border: none; /* Mobile Safari */
+ opacity: 0;
+ position: absolute;
+}
+
+.toggle-all + label {
+ width: 60px;
+ height: 34px;
+ font-size: 0;
+ position: absolute;
+ top: -52px;
+ left: -13px;
+ -webkit-transform: rotate(90deg);
+ transform: rotate(90deg);
+}
+
+.toggle-all + label:before {
+ content: '❯';
+ font-size: 22px;
+ color: #e6e6e6;
+ padding: 10px 27px 10px 27px;
+}
+
+.toggle-all:checked + label:before {
+ color: #737373;
+}
+
+.todo-list {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+
+.todo-list li {
+ position: relative;
+ font-size: 24px;
+ border-bottom: 1px solid #ededed;
+}
+
+.todo-list li:last-child {
+ border-bottom: none;
+}
+
+.todo-list li.editing {
+ border-bottom: none;
+ padding: 0;
+}
+
+.todo-list li.editing .edit {
+ display: block;
+ width: 506px;
+ padding: 12px 16px;
+ margin: 0 0 0 43px;
+}
+
+.todo-list li.editing .view {
+ display: none;
+}
+
+.todo-list li .toggle {
+ text-align: center;
+ width: 40px;
+ /* auto, since non-WebKit browsers doesn't support input styling */
+ height: auto;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ margin: auto 0;
+ border: none; /* Mobile Safari */
+ -webkit-appearance: none;
+ appearance: none;
+}
+
+.todo-list li .toggle {
+ opacity: 0;
+}
+
+.todo-list li .toggle + label {
+ /*
+ Firefox requires `#` to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id=922433
+ IE and Edge requires *everything* to be escaped to render, so we do that instead of just the `#` - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7157459/
+ */
+ background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E');
+ background-repeat: no-repeat;
+ background-position: center left;
+}
+
+.todo-list li .toggle:checked + label {
+ background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E');
+}
+
+.todo-list li label {
+ word-break: break-all;
+ padding: 15px 15px 15px 60px;
+ display: block;
+ line-height: 1.2;
+ transition: color 0.4s;
+}
+
+.todo-list li.completed label {
+ color: #d9d9d9;
+ text-decoration: line-through;
+}
+
+.todo-list li .destroy {
+ display: none;
+ position: absolute;
+ top: 0;
+ right: 10px;
+ bottom: 0;
+ width: 40px;
+ height: 40px;
+ margin: auto 0;
+ font-size: 30px;
+ color: #cc9a9a;
+ margin-bottom: 11px;
+ transition: color 0.2s ease-out;
+}
+
+.todo-list li .destroy:hover {
+ color: #af5b5e;
+}
+
+.todo-list li .destroy:after {
+ content: '×';
+}
+
+.todo-list li:hover .destroy {
+ display: block;
+}
+
+.todo-list li .edit {
+ display: none;
+}
+
+.todo-list li.editing:last-child {
+ margin-bottom: -1px;
+}
+
+.footer {
+ color: #777;
+ padding: 10px 15px;
+ height: 20px;
+ text-align: center;
+ border-top: 1px solid #e6e6e6;
+}
+
+.footer:before {
+ content: '';
+ position: absolute;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ height: 50px;
+ overflow: hidden;
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
+ 0 8px 0 -3px #f6f6f6,
+ 0 9px 1px -3px rgba(0, 0, 0, 0.2),
+ 0 16px 0 -6px #f6f6f6,
+ 0 17px 2px -6px rgba(0, 0, 0, 0.2);
+}
+
+.todo-count {
+ float: left;
+ text-align: left;
+}
+
+.todo-count strong {
+ font-weight: 300;
+}
+
+.filters {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ position: absolute;
+ right: 0;
+ left: 0;
+}
+
+.filters li {
+ display: inline;
+}
+
+.filters li a {
+ color: inherit;
+ margin: 3px;
+ padding: 3px 7px;
+ text-decoration: none;
+ border: 1px solid transparent;
+ border-radius: 3px;
+}
+
+.filters li a:hover {
+ border-color: rgba(175, 47, 47, 0.1);
+}
+
+.filters li a.selected {
+ border-color: rgba(175, 47, 47, 0.2);
+}
+
+.clear-completed,
+html .clear-completed:active {
+ float: right;
+ position: relative;
+ line-height: 20px;
+ text-decoration: none;
+ cursor: pointer;
+}
+
+.clear-completed:hover {
+ text-decoration: underline;
+}
+
+.info {
+ margin: 65px auto 0;
+ color: #bfbfbf;
+ font-size: 10px;
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
+ text-align: center;
+}
+
+.info p {
+ line-height: 1;
+}
+
+.info a {
+ color: inherit;
+ text-decoration: none;
+ font-weight: 400;
+}
+
+.info a:hover {
+ text-decoration: underline;
+}
+
+/*
+ Hack to remove background from Mobile Safari.
+ Can't use it globally since it destroys checkboxes in Firefox
+*/
+@media screen and (-webkit-min-device-pixel-ratio:0) {
+ .toggle-all,
+ .todo-list li .toggle {
+ background: none;
+ }
+
+ .todo-list li .toggle {
+ height: 40px;
+ }
+}
+
+@media (max-width: 430px) {
+ .footer {
+ height: 50px;
+ }
+
+ .filters {
+ bottom: 10px;
+ }
+}
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-app-css/package.json b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/package.json
new file mode 100644
index 00000000..72831e7b
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/package.json
@@ -0,0 +1,58 @@
+{
+ "_from": "todomvc-app-css@^2.0.0",
+ "_id": "todomvc-app-css@2.1.0",
+ "_inBundle": false,
+ "_integrity": "sha1-tvJxbTOa+i5feZNH0qSLBTliQqU=",
+ "_location": "/todomvc-app-css",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "todomvc-app-css@^2.0.0",
+ "name": "todomvc-app-css",
+ "escapedName": "todomvc-app-css",
+ "rawSpec": "^2.0.0",
+ "saveSpec": null,
+ "fetchSpec": "^2.0.0"
+ },
+ "_requiredBy": [
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/todomvc-app-css/-/todomvc-app-css-2.1.0.tgz",
+ "_shasum": "b6f2716d339afa2e5f799347d2a48b05396242a5",
+ "_spec": "todomvc-app-css@^2.0.0",
+ "_where": "/home/rjaros/git/kvision/examples/todomvc/src/main/web",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "bugs": {
+ "url": "https://github.com/tastejs/todomvc-app-css/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "CSS for TodoMVC apps",
+ "files": [
+ "index.css"
+ ],
+ "homepage": "https://github.com/tastejs/todomvc-app-css#readme",
+ "keywords": [
+ "todomvc",
+ "tastejs",
+ "app",
+ "todo",
+ "template",
+ "css",
+ "style",
+ "stylesheet"
+ ],
+ "license": "CC-BY-4.0",
+ "name": "todomvc-app-css",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/tastejs/todomvc-app-css.git"
+ },
+ "style": "index.css",
+ "version": "2.1.0"
+}
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-app-css/readme.md b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/readme.md
new file mode 100644
index 00000000..6ddbebf0
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-app-css/readme.md
@@ -0,0 +1,28 @@
+# todomvc-app-css
+
+> CSS for TodoMVC apps
+
+![](screenshot.png)
+
+
+## Install
+
+
+```
+$ npm install --save todomvc-app-css
+```
+
+
+## Getting started
+
+```html
+<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
+```
+
+See the [TodoMVC app template](https://github.com/tastejs/todomvc-app-template).
+
+
+
+## License
+
+<a rel="license" href="http://creativecommons.org/licenses/by/4.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/4.0/80x15.png" /></a><br />This <span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/InteractiveResource" rel="dct:type">work</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://sindresorhus.com" property="cc:attributionName" rel="cc:attributionURL">Sindre Sorhus</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/deed.en_US">Creative Commons Attribution 4.0 International License</a>.
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-common/base.css b/examples/todomvc/src/main/web/node_modules/todomvc-common/base.css
new file mode 100644
index 00000000..da65968a
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-common/base.css
@@ -0,0 +1,141 @@
+hr {
+ margin: 20px 0;
+ border: 0;
+ border-top: 1px dashed #c5c5c5;
+ border-bottom: 1px dashed #f7f7f7;
+}
+
+.learn a {
+ font-weight: normal;
+ text-decoration: none;
+ color: #b83f45;
+}
+
+.learn a:hover {
+ text-decoration: underline;
+ color: #787e7e;
+}
+
+.learn h3,
+.learn h4,
+.learn h5 {
+ margin: 10px 0;
+ font-weight: 500;
+ line-height: 1.2;
+ color: #000;
+}
+
+.learn h3 {
+ font-size: 24px;
+}
+
+.learn h4 {
+ font-size: 18px;
+}
+
+.learn h5 {
+ margin-bottom: 0;
+ font-size: 14px;
+}
+
+.learn ul {
+ padding: 0;
+ margin: 0 0 30px 25px;
+}
+
+.learn li {
+ line-height: 20px;
+}
+
+.learn p {
+ font-size: 15px;
+ font-weight: 300;
+ line-height: 1.3;
+ margin-top: 0;
+ margin-bottom: 0;
+}
+
+#issue-count {
+ display: none;
+}
+
+.quote {
+ border: none;
+ margin: 20px 0 60px 0;
+}
+
+.quote p {
+ font-style: italic;
+}
+
+.quote p:before {
+ content: '“';
+ font-size: 50px;
+ opacity: .15;
+ position: absolute;
+ top: -20px;
+ left: 3px;
+}
+
+.quote p:after {
+ content: '”';
+ font-size: 50px;
+ opacity: .15;
+ position: absolute;
+ bottom: -42px;
+ right: 3px;
+}
+
+.quote footer {
+ position: absolute;
+ bottom: -40px;
+ right: 0;
+}
+
+.quote footer img {
+ border-radius: 3px;
+}
+
+.quote footer a {
+ margin-left: 5px;
+ vertical-align: middle;
+}
+
+.speech-bubble {
+ position: relative;
+ padding: 10px;
+ background: rgba(0, 0, 0, .04);
+ border-radius: 5px;
+}
+
+.speech-bubble:after {
+ content: '';
+ position: absolute;
+ top: 100%;
+ right: 30px;
+ border: 13px solid transparent;
+ border-top-color: rgba(0, 0, 0, .04);
+}
+
+.learn-bar > .learn {
+ position: absolute;
+ width: 272px;
+ top: 8px;
+ left: -300px;
+ padding: 10px;
+ border-radius: 5px;
+ background-color: rgba(255, 255, 255, .6);
+ transition-property: left;
+ transition-duration: 500ms;
+}
+
+@media (min-width: 899px) {
+ .learn-bar {
+ width: auto;
+ padding-left: 300px;
+ }
+
+ .learn-bar > .learn {
+ left: 8px;
+ }
+}
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-common/base.js b/examples/todomvc/src/main/web/node_modules/todomvc-common/base.js
new file mode 100644
index 00000000..a56b5aac
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-common/base.js
@@ -0,0 +1,249 @@
+/* global _ */
+(function () {
+ 'use strict';
+
+ /* jshint ignore:start */
+ // Underscore's Template Module
+ // Courtesy of underscorejs.org
+ var _ = (function (_) {
+ _.defaults = function (object) {
+ if (!object) {
+ return object;
+ }
+ for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {
+ var iterable = arguments[argsIndex];
+ if (iterable) {
+ for (var key in iterable) {
+ if (object[key] == null) {
+ object[key] = iterable[key];
+ }
+ }
+ }
+ }
+ return object;
+ };
+
+ // By default, Underscore uses ERB-style template delimiters, change the
+ // following template settings to use alternative delimiters.
+ _.templateSettings = {
+ evaluate : /<%([\s\S]+?)%>/g,
+ interpolate : /<%=([\s\S]+?)%>/g,
+ escape : /<%-([\s\S]+?)%>/g
+ };
+
+ // When customizing `templateSettings`, if you don't want to define an
+ // interpolation, evaluation or escaping regex, we need one that is
+ // guaranteed not to match.
+ var noMatch = /(.)^/;
+
+ // Certain characters need to be escaped so that they can be put into a
+ // string literal.
+ var escapes = {
+ "'": "'",
+ '\\': '\\',
+ '\r': 'r',
+ '\n': 'n',
+ '\t': 't',
+ '\u2028': 'u2028',
+ '\u2029': 'u2029'
+ };
+
+ var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
+
+ // JavaScript micro-templating, similar to John Resig's implementation.
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
+ // and correctly escapes quotes within interpolated code.
+ _.template = function(text, data, settings) {
+ var render;
+ settings = _.defaults({}, settings, _.templateSettings);
+
+ // Combine delimiters into one regular expression via alternation.
+ var matcher = new RegExp([
+ (settings.escape || noMatch).source,
+ (settings.interpolate || noMatch).source,
+ (settings.evaluate || noMatch).source
+ ].join('|') + '|$', 'g');
+
+ // Compile the template source, escaping string literals appropriately.
+ var index = 0;
+ var source = "__p+='";
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
+ source += text.slice(index, offset)
+ .replace(escaper, function(match) { return '\\' + escapes[match]; });
+
+ if (escape) {
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
+ }
+ if (interpolate) {
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
+ }
+ if (evaluate) {
+ source += "';\n" + evaluate + "\n__p+='";
+ }
+ index = offset + match.length;
+ return match;
+ });
+ source += "';\n";
+
+ // If a variable is not specified, place data values in local scope.
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
+
+ source = "var __t,__p='',__j=Array.prototype.join," +
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
+ source + "return __p;\n";
+
+ try {
+ render = new Function(settings.variable || 'obj', '_', source);
+ } catch (e) {
+ e.source = source;
+ throw e;
+ }
+
+ if (data) return render(data, _);
+ var template = function(data) {
+ return render.call(this, data, _);
+ };
+
+ // Provide the compiled function source as a convenience for precompilation.
+ template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
+
+ return template;
+ };
+
+ return _;
+ })({});
+
+ if (location.hostname === 'todomvc.com') {
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
+ ga('create', 'UA-31081062-1', 'auto');
+ ga('send', 'pageview');
+ }
+ /* jshint ignore:end */
+
+ function redirect() {
+ if (location.hostname === 'tastejs.github.io') {
+ location.href = location.href.replace('tastejs.github.io/todomvc', 'todomvc.com');
+ }
+ }
+
+ function findRoot() {
+ var base = location.href.indexOf('examples/');
+ return location.href.substr(0, base);
+ }
+
+ function getFile(file, callback) {
+ if (!location.host) {
+ return console.info('Miss the info bar? Run TodoMVC from a server to avoid a cross-origin error.');
+ }
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.open('GET', findRoot() + file, true);
+ xhr.send();
+
+ xhr.onload = function () {
+ if (xhr.status === 200 && callback) {
+ callback(xhr.responseText);
+ }
+ };
+ }
+
+ function Learn(learnJSON, config) {
+ if (!(this instanceof Learn)) {
+ return new Learn(learnJSON, config);
+ }
+
+ var template, framework;
+
+ if (typeof learnJSON !== 'object') {
+ try {
+ learnJSON = JSON.parse(learnJSON);
+ } catch (e) {
+ return;
+ }
+ }
+
+ if (config) {
+ template = config.template;
+ framework = config.framework;
+ }
+
+ if (!template && learnJSON.templates) {
+ template = learnJSON.templates.todomvc;
+ }
+
+ if (!framework && document.querySelector('[data-framework]')) {
+ framework = document.querySelector('[data-framework]').dataset.framework;
+ }
+
+ this.template = template;
+
+ if (learnJSON.backend) {
+ this.frameworkJSON = learnJSON.backend;
+ this.frameworkJSON.issueLabel = framework;
+ this.append({
+ backend: true
+ });
+ } else if (learnJSON[framework]) {
+ this.frameworkJSON = learnJSON[framework];
+ this.frameworkJSON.issueLabel = framework;
+ this.append();
+ }
+
+ this.fetchIssueCount();
+ }
+
+ Learn.prototype.append = function (opts) {
+ var aside = document.createElement('aside');
+ aside.innerHTML = _.template(this.template, this.frameworkJSON);
+ aside.className = 'learn';
+
+ if (opts && opts.backend) {
+ // Remove demo link
+ var sourceLinks = aside.querySelector('.source-links');
+ var heading = sourceLinks.firstElementChild;
+ var sourceLink = sourceLinks.lastElementChild;
+ // Correct link path
+ var href = sourceLink.getAttribute('href');
+ sourceLink.setAttribute('href', href.substr(href.lastIndexOf('http')));
+ sourceLinks.innerHTML = heading.outerHTML + sourceLink.outerHTML;
+ } else {
+ // Localize demo links
+ var demoLinks = aside.querySelectorAll('.demo-link');
+ Array.prototype.forEach.call(demoLinks, function (demoLink) {
+ if (demoLink.getAttribute('href').substr(0, 4) !== 'http') {
+ demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href'));
+ }
+ });
+ }
+
+ document.body.className = (document.body.className + ' learn-bar').trim();
+ document.body.insertAdjacentHTML('afterBegin', aside.outerHTML);
+ };
+
+ Learn.prototype.fetchIssueCount = function () {
+ var issueLink = document.getElementById('issue-count-link');
+ if (issueLink) {
+ var url = issueLink.href.replace('https://github.com', 'https://api.github.com/repos');
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url, true);
+ xhr.onload = function (e) {
+ var parsedResponse = JSON.parse(e.target.responseText);
+ if (parsedResponse instanceof Array) {
+ var count = parsedResponse.length;
+ if (count !== 0) {
+ issueLink.innerHTML = 'This app has ' + count + ' open issues';
+ document.getElementById('issue-count').style.display = 'inline';
+ }
+ }
+ };
+ xhr.send();
+ }
+ };
+
+ redirect();
+ getFile('learn.json', Learn);
+})();
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-common/package.json b/examples/todomvc/src/main/web/node_modules/todomvc-common/package.json
new file mode 100644
index 00000000..a267618e
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-common/package.json
@@ -0,0 +1,54 @@
+{
+ "_from": "todomvc-common@^1.0.0",
+ "_id": "todomvc-common@1.0.4",
+ "_inBundle": false,
+ "_integrity": "sha512-AA0Z4exovEqubhbZCrzzn9roVT4zvOncS319p2zIc4CsNe5B9TLL7Sei1NIV6d+WrgR5rOi+y0I9Y6GE7xgNOw==",
+ "_location": "/todomvc-common",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "todomvc-common@^1.0.0",
+ "name": "todomvc-common",
+ "escapedName": "todomvc-common",
+ "rawSpec": "^1.0.0",
+ "saveSpec": null,
+ "fetchSpec": "^1.0.0"
+ },
+ "_requiredBy": [
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/todomvc-common/-/todomvc-common-1.0.4.tgz",
+ "_shasum": "23099af886c2f0525bfd4537e078f12d0074309e",
+ "_spec": "todomvc-common@^1.0.0",
+ "_where": "/home/rjaros/git/kvision/examples/todomvc/src/main/web",
+ "author": {
+ "name": "TasteJS"
+ },
+ "bugs": {
+ "url": "https://github.com/tastejs/todomvc-common/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "Common TodoMVC utilities used by our apps",
+ "files": [
+ "base.js",
+ "base.css"
+ ],
+ "homepage": "https://github.com/tastejs/todomvc-common#readme",
+ "keywords": [
+ "todomvc",
+ "tastejs",
+ "util",
+ "utilities"
+ ],
+ "license": "MIT",
+ "main": "base.js",
+ "name": "todomvc-common",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/tastejs/todomvc-common.git"
+ },
+ "style": "base.css",
+ "version": "1.0.4"
+}
diff --git a/examples/todomvc/src/main/web/node_modules/todomvc-common/readme.md b/examples/todomvc/src/main/web/node_modules/todomvc-common/readme.md
new file mode 100644
index 00000000..7a5de511
--- /dev/null
+++ b/examples/todomvc/src/main/web/node_modules/todomvc-common/readme.md
@@ -0,0 +1,15 @@
+# todomvc-common
+
+> Common TodoMVC utilities used by our apps
+
+
+## Install
+
+```
+$ npm install --save todomvc-common
+```
+
+
+## License
+
+MIT © [TasteJS](http://tastejs.com)
diff --git a/examples/todomvc/src/main/web/package-lock.json b/examples/todomvc/src/main/web/package-lock.json
new file mode 100644
index 00000000..244ffb88
--- /dev/null
+++ b/examples/todomvc/src/main/web/package-lock.json
@@ -0,0 +1,16 @@
+{
+ "requires": true,
+ "lockfileVersion": 1,
+ "dependencies": {
+ "todomvc-app-css": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/todomvc-app-css/-/todomvc-app-css-2.1.0.tgz",
+ "integrity": "sha1-tvJxbTOa+i5feZNH0qSLBTliQqU="
+ },
+ "todomvc-common": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/todomvc-common/-/todomvc-common-1.0.4.tgz",
+ "integrity": "sha512-AA0Z4exovEqubhbZCrzzn9roVT4zvOncS319p2zIc4CsNe5B9TLL7Sei1NIV6d+WrgR5rOi+y0I9Y6GE7xgNOw=="
+ }
+ }
+}
diff --git a/examples/todomvc/src/main/web/package.json b/examples/todomvc/src/main/web/package.json
new file mode 100644
index 00000000..e939a50f
--- /dev/null
+++ b/examples/todomvc/src/main/web/package.json
@@ -0,0 +1,7 @@
+{
+ "private": true,
+ "dependencies": {
+ "todomvc-app-css": "^2.0.0",
+ "todomvc-common": "^1.0.0"
+ }
+}
diff --git a/examples/todomvc/src/test/kotlin/test/com/example/TestUtil.kt b/examples/todomvc/src/test/kotlin/test/com/example/TestUtil.kt
new file mode 100644
index 00000000..c5ec014f
--- /dev/null
+++ b/examples/todomvc/src/test/kotlin/test/com/example/TestUtil.kt
@@ -0,0 +1,32 @@
+package test.com.example
+
+import pl.treksoft.jquery.jQuery
+import kotlin.browser.document
+
+interface TestSpec {
+ fun beforeTest()
+
+ fun afterTest()
+
+ fun run(code: () -> Unit) {
+ beforeTest()
+ code()
+ afterTest()
+ }
+}
+
+interface DomSpec : TestSpec {
+
+ override fun beforeTest() {
+ val fixture = "<div style=\"display: none\" id=\"pretest\">" +
+ "<div id=\"helloworld\"></div></div>"
+ document.body?.insertAdjacentHTML("afterbegin", fixture)
+ }
+
+ override fun afterTest() {
+ val div = document.getElementById("pretest")
+ div?.remove()
+ jQuery(`object` = ".modal-backdrop").remove()
+ }
+
+}