diff --git a/build.gradle b/build.gradle index bb779b3..a0545ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.1.14-SNAPSHOT' +version '0.1.15-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' diff --git a/build.gradle b/build.gradle index bb779b3..a0545ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.1.14-SNAPSHOT' +version '0.1.15-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' diff --git a/komp.iml b/komp.iml index 60dae77..c4732cc 100644 --- a/komp.iml +++ b/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index bb779b3..a0545ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.1.14-SNAPSHOT' +version '0.1.15-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' diff --git a/komp.iml b/komp.iml index 60dae77..c4732cc 100644 --- a/komp.iml +++ b/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt b/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt index 5c0994b..b6415df 100644 --- a/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt +++ b/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt @@ -11,6 +11,7 @@ import org.w3c.dom.asList import org.w3c.dom.css.CSSStyleDeclaration import org.w3c.dom.events.Event +import kotlin.browser.document @Suppress("NOTHING_TO_INLINE") private inline fun HTMLElement.setEvent(name: String, noinline callback : (Event) -> Unit) : Unit { @@ -139,7 +140,7 @@ // stupid hack as browsers doesn't support createEntityReference val s = document.createElement("span") as HTMLElement s.innerHTML = entity.text - path.last().appendChild(s.childNodes.asList().filter { it.nodeType == Node.TEXT_NODE }.first()) + path.last().appendChild(s.childNodes.asList().first { it.nodeType == Node.TEXT_NODE }) // other solution would be // pathLast().innerHTML += entity.text @@ -170,4 +171,11 @@ @Suppress("UNCHECKED_CAST") private fun HTMLElement.asR(): HTMLElement = this.asDynamic() + companion object { + fun create(content: HtmlBuilder.() -> Unit) : HTMLElement { + val consumer = HtmlBuilder(DummyKomponent(), document) + content.invoke(consumer) + return consumer.finalize() + } + } } diff --git a/build.gradle b/build.gradle index bb779b3..a0545ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.1.14-SNAPSHOT' +version '0.1.15-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' diff --git a/komp.iml b/komp.iml index 60dae77..c4732cc 100644 --- a/komp.iml +++ b/komp.iml @@ -1,5 +1,5 @@ - + diff --git a/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt b/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt index 5c0994b..b6415df 100644 --- a/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt +++ b/src/main/kotlin/nl/astraeus/komp/HtmlBuilder.kt @@ -11,6 +11,7 @@ import org.w3c.dom.asList import org.w3c.dom.css.CSSStyleDeclaration import org.w3c.dom.events.Event +import kotlin.browser.document @Suppress("NOTHING_TO_INLINE") private inline fun HTMLElement.setEvent(name: String, noinline callback : (Event) -> Unit) : Unit { @@ -139,7 +140,7 @@ // stupid hack as browsers doesn't support createEntityReference val s = document.createElement("span") as HTMLElement s.innerHTML = entity.text - path.last().appendChild(s.childNodes.asList().filter { it.nodeType == Node.TEXT_NODE }.first()) + path.last().appendChild(s.childNodes.asList().first { it.nodeType == Node.TEXT_NODE }) // other solution would be // pathLast().innerHTML += entity.text @@ -170,4 +171,11 @@ @Suppress("UNCHECKED_CAST") private fun HTMLElement.asR(): HTMLElement = this.asDynamic() + companion object { + fun create(content: HtmlBuilder.() -> Unit) : HTMLElement { + val consumer = HtmlBuilder(DummyKomponent(), document) + content.invoke(consumer) + return consumer.finalize() + } + } } diff --git a/src/main/kotlin/nl/astraeus/komp/Komponent.kt b/src/main/kotlin/nl/astraeus/komp/Komponent.kt index 28b4921..e0fdb42 100644 --- a/src/main/kotlin/nl/astraeus/komp/Komponent.kt +++ b/src/main/kotlin/nl/astraeus/komp/Komponent.kt @@ -1,6 +1,7 @@ package nl.astraeus.komp import kotlinx.html.Tag +import kotlinx.html.div import org.w3c.dom.HTMLDivElement import org.w3c.dom.HTMLElement import org.w3c.dom.Node @@ -20,6 +21,14 @@ } } +class DummyKomponent: Komponent() { + override fun HtmlBuilder.render() { + div { + + "dummy" + } + } +} + abstract class Komponent { var element: Node? = null val declaredStyles: MutableMap = HashMap()