diff options
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/utils')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt | 106 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt | 2 |
2 files changed, 107 insertions, 1 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 } + } +} diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt index 80a7c482..7ba01135 100644 --- a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt +++ b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt @@ -2,8 +2,8 @@ package pl.treksoft.kvision.utils +import pl.treksoft.kvision.KVManager import pl.treksoft.kvision.core.CssSize -import pl.treksoft.kvision.core.KVManager import pl.treksoft.kvision.core.UNIT import kotlin.js.Date |