aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-02-04 21:49:23 +0100
committerRobert Jaros <rjaros@finn.pl>2018-02-04 21:49:23 +0100
commit70d2f14d4a34f841a3161482eec5d355cbd755f6 (patch)
tree847cb461a2f261f6f2b3a6b0ebbc6918f1da0467 /src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
parent9665fe692681bc958e55d00cc0d0b238b7aee694 (diff)
downloadkvision-70d2f14d4a34f841a3161482eec5d355cbd755f6.tar.gz
kvision-70d2f14d4a34f841a3161482eec5d355cbd755f6.tar.bz2
kvision-70d2f14d4a34f841a3161482eec5d355cbd755f6.zip
Refactoring packages layout
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
new file mode 100644
index 00000000..269fa6cb
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
@@ -0,0 +1,106 @@
+package pl.treksoft.kvision.utils
+
+import com.github.snabbdom.Attrs
+import com.github.snabbdom.Classes
+import com.github.snabbdom.Hooks
+import com.github.snabbdom.On
+import com.github.snabbdom.Props
+import com.github.snabbdom.VNodeData
+import com.github.snabbdom.VNodeStyle
+import org.w3c.dom.CustomEvent
+import org.w3c.dom.CustomEventInit
+import pl.treksoft.jquery.JQueryEventObject
+import pl.treksoft.kvision.core.StringBoolPair
+import pl.treksoft.kvision.core.StringPair
+import pl.treksoft.kvision.core.Widget
+
+external class Object
+
+fun obj(init: dynamic.() -> Unit): dynamic {
+ return (Object()).apply(init)
+}
+
+@Suppress("UnsafeCastFromDynamic")
+private fun vNodeData(): VNodeData = js("({})")
+
+interface KvJQueryEventObject : JQueryEventObject {
+ val clickedIndex: Int
+}
+
+@Suppress("UnsafeCastFromDynamic")
+class KvEvent(type: String, eventInitDict: CustomEventInit) : CustomEvent(type, eventInitDict) {
+ override val detail: KvJQueryEventObject = obj {}
+}
+
+interface BtOn : On {
+ var showBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var shownBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var hideBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var hiddenBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var showBsModal: ((KvEvent) -> kotlin.Unit)?
+ var shownBsModal: ((KvEvent) -> kotlin.Unit)?
+ var hideBsModal: ((KvEvent) -> kotlin.Unit)?
+ var hiddenBsModal: ((KvEvent) -> kotlin.Unit)?
+ var dragSplitPanel: ((KvEvent) -> kotlin.Unit)?
+ var dragEndSplitPanel: ((KvEvent) -> kotlin.Unit)?
+ var showBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var shownBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var hideBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var hiddenBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var loadedBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var renderedBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var refreshedBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var changedBsSelect: ((KvEvent) -> kotlin.Unit)?
+ var changeDate: ((KvEvent) -> kotlin.Unit)?
+ var showBsDateTime: ((KvEvent) -> kotlin.Unit)?
+ var hideBsDateTime: ((KvEvent) -> kotlin.Unit)?
+ var onMinBsSpinner: ((KvEvent) -> kotlin.Unit)?
+ var onMaxBsSpinner: ((KvEvent) -> kotlin.Unit)?
+ var updateModel: ((KvEvent) -> kotlin.Unit)?
+}
+
+interface SnOn<T> : BtOn {
+ var self: T
+}
+
+fun snOpt(block: VNodeData.() -> Unit) = (vNodeData()::apply)(block)
+
+@Suppress("UnsafeCastFromDynamic")
+internal fun on(widget: Widget): SnOn<Widget> {
+ val obj = js("({})")
+ obj["self"] = widget
+ return obj
+}
+
+@Suppress("UnsafeCastFromDynamic")
+internal fun hooks(): Hooks {
+ return js("({})")
+}
+
+@Suppress("UnsafeCastFromDynamic")
+fun snStyle(pairs: List<StringPair>): VNodeStyle {
+ return obj {
+ pairs.forEach { (key, value) -> this[key] = value }
+ }
+}
+
+@Suppress("UnsafeCastFromDynamic")
+fun snProps(pairs: List<StringPair>): Props {
+ return obj {
+ pairs.forEach { (key, value) -> this[key] = value }
+ }
+}
+
+@Suppress("UnsafeCastFromDynamic")
+fun snClasses(pairs: List<StringBoolPair>): Classes {
+ return obj {
+ pairs.forEach { (key, value) -> this[key] = value }
+ }
+}
+
+@Suppress("UnsafeCastFromDynamic")
+fun snAttrs(pairs: List<StringPair>): Attrs {
+ return obj {
+ pairs.forEach { (key, value) -> this[key] = value }
+ }
+}