From 7c33efa121df249caed630364775d196586efa76 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Feb 2022 23:54:59 +0600 Subject: [PATCH 1/4] start 0.0.39 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de37b16..ed475d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.0.39 + ## 0.0.38 * Add support of `Toggle` diff --git a/gradle.properties b/gradle.properties index bbe19b7..c867ca4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.38 +version=0.0.39 From 2e28334b41f8236a0a5277cc37e0f46e54d340bc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Feb 2022 23:55:09 +0600 Subject: [PATCH 2/4] add support of notifications --- CHANGELOG.md | 2 + .../dev/inmo/jsuikit/elements/Notification.kt | 15 ++++++ .../dev/inmo/jsuikit/modifiers/UIKit.kt | 6 ++- .../kotlin/dev/inmo/jsuikit/types/UIKit.kt | 5 ++ .../types/UIKitNotificationParameter.kt | 39 +++++++++++++++ .../inmo/jsuikit/types/UIKitNotifications.kt | 50 +++++++++++++++++++ 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotificationParameter.kt create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ed475d6..dd647b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.0.39 +* Add support of `Notifications` + ## 0.0.38 * Add support of `Toggle` diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt new file mode 100644 index 0000000..6e95fcf --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt @@ -0,0 +1,15 @@ +package dev.inmo.jsuikit.elements + +import dev.inmo.jsuikit.modifiers.UIKit +import dev.inmo.jsuikit.types.UIKitNotificationParameter +import dev.inmo.jsuikit.types.NotificationsGroup +import dev.inmo.jsuikit.types.invoke +import dev.inmo.jsuikit.utils.Milliseconds + +fun Notification( + message: String, + status: UIKitNotificationParameter.Style? = null, + timeout: Milliseconds? = null, + group: NotificationsGroup? = null, + position: UIKitNotificationParameter.Position? = null +) = UIKit.notification.invoke(message, status, timeout, group, position) diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKit.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKit.kt index 96882df..f39df8b 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKit.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKit.kt @@ -1,4 +1,6 @@ package dev.inmo.jsuikit.modifiers -inline val UIKit - get() = js("UIkit") +import dev.inmo.jsuikit.types.UIKit + +inline val UIKit: UIKit + get() = js("UIkit").unsafeCast() diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt new file mode 100644 index 0000000..dafeed0 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt @@ -0,0 +1,5 @@ +package dev.inmo.jsuikit.types + +external interface UIKit { + val notification: UIKitNotifications +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotificationParameter.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotificationParameter.kt new file mode 100644 index 0000000..15ab125 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotificationParameter.kt @@ -0,0 +1,39 @@ +package dev.inmo.jsuikit.types + +sealed class UIKitNotificationParameter { + abstract val parameterName: String + abstract val parameterValue: String + + sealed class Style(override val parameterValue: String) : UIKitNotificationParameter() { + override val parameterName: String + get() = "status" + + object Primary : Style("primary") + object Success : Style("success") + object Warning : Style("warning") + object Danger : Style("danger") + + } + + sealed class Position(override val parameterValue: String) : UIKitNotificationParameter() { + override val parameterName: String + get() = "pos" + + sealed class Top(parameterValue: String) : Position("top-$parameterValue") { + + object Left : Top("left") + object Center : Top("center") + object Right : Top("right") + + } + + sealed class Bottom(parameterValue: String) : Position("bottom-$parameterValue") { + + object Left : Bottom("left") + object Center : Bottom("center") + object Right : Bottom("right") + + } + + } +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt new file mode 100644 index 0000000..9aef644 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt @@ -0,0 +1,50 @@ +package dev.inmo.jsuikit.types + +import dev.inmo.jsuikit.utils.Milliseconds +import org.w3c.dom.Element +import kotlin.js.Json +import kotlin.js.json + +typealias NotificationsGroup = String + +external interface UIKitNotifications { + + fun closeAll(group: NotificationsGroup) + + operator fun invoke(message: String, parameters: Json) + + operator fun invoke(element: Element): UIKitNotification? +} + +external interface UIKitNotification { + fun close(immediate: Boolean) +} + +data class UIKitNotificationsParameters( + val status: UIKitNotificationParameter.Style? = null, + val timeout: Milliseconds? = null, + val group: NotificationsGroup? = null, + val position: UIKitNotificationParameter.Position? = null +) { + fun parametersJson() = json( + *listOfNotNull( + status ?.let { it.parameterName to it.parameterValue }, + timeout ?.let { "timeout" to timeout.toString() }, + group ?.let { "group" to it }, + position ?.let { it.parameterName to it.parameterValue }, + ).toTypedArray() + ) +} + +operator fun UIKitNotifications.invoke( + message: String, + parameters: UIKitNotificationsParameters +) = invoke(message, parameters.parametersJson()) + +operator fun UIKitNotifications.invoke( + message: String, + status: UIKitNotificationParameter.Style? = null, + timeout: Milliseconds? = null, + group: NotificationsGroup? = null, + position: UIKitNotificationParameter.Position? = null +) = invoke(message, UIKitNotificationsParameters(status, timeout, group, position)) From c81c1125a039f34af71cfdb2d515011ab8f5d11a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Mar 2022 00:14:17 +0600 Subject: [PATCH 3/4] add UIKitDialog --- .../dev/inmo/jsuikit/elements/Dialog.kt | 4 +- .../kotlin/dev/inmo/jsuikit/types/UIKit.kt | 1 + .../dev/inmo/jsuikit/types/UIKitDialog.kt | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt index f6df0e2..996e98c 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt @@ -99,9 +99,7 @@ fun Dialog( } htmlElement.addEventListener("hidden", wrapper) - val dialog = UIKit.modal("#${htmlElement.id}") - dialog.show() - Unit + UIKit.modal("#${htmlElement.id}").show() } } } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt index dafeed0..8dc1d93 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt @@ -2,4 +2,5 @@ package dev.inmo.jsuikit.types external interface UIKit { val notification: UIKitNotifications + val modal: UIKitDialogs } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt new file mode 100644 index 0000000..c45b373 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt @@ -0,0 +1,40 @@ +package dev.inmo.jsuikit.types + +import org.w3c.dom.Element +import kotlin.js.Promise + +external interface UIKitDialogs { + operator fun invoke(element: Element): UIKitDialog + operator fun invoke(selector: String): UIKitDialog + fun alert(text: String): UIKitDialogPromiseAlert + fun confirm(text: String): UIKitDialogPromiseConfirm + fun prompt(title: String): UIKitDialogPromisePrompt + fun prompt(title: String, preset: String): UIKitDialogPromisePrompt + fun dialog(element: Element): UIKitDialog +} + +external class UIKitDialogPromiseConfirm : Promise { + val dialog: UIKitDialog + + fun then( + onConfirm: () -> Unit = definedExternally, + onRejected: () -> Unit = definedExternally, + ) +} + +external class UIKitDialogPromisePrompt : Promise { + val dialog: UIKitDialog + + fun then(onResult: (data: String?) -> Unit) +} + +external class UIKitDialogPromiseAlert : Promise { + val dialog: UIKitDialog + + fun then(onClose: () -> Unit) +} + +external interface UIKitDialog { + fun show() + fun hide() +} From 3c7f17523b3fdb6be7401ce757d4239dc648e033 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Mar 2022 00:49:19 +0600 Subject: [PATCH 4/4] refactor invoke functions --- src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt | 4 ++-- src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt | 10 ++++++++++ .../kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt | 2 -- .../dev/inmo/jsuikit/types/UIKitNotifications.kt | 7 ++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt index 996e98c..0fa23ac 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt @@ -17,7 +17,7 @@ private class DialogDisposableEffectResult( ) : DisposableEffectResult { override fun dispose() { onDispose?.invoke() - js("UIkit").modal("#${element.id}") ?.hide() + UIKit.modal("#${element.id}") ?.hide() onDisposed?.invoke() } } @@ -99,7 +99,7 @@ fun Dialog( } htmlElement.addEventListener("hidden", wrapper) - UIKit.modal("#${htmlElement.id}").show() + UIKit.modal("#${htmlElement.id}") ?.show() } } } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt index 8dc1d93..3bf29fa 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt @@ -1,6 +1,16 @@ package dev.inmo.jsuikit.types +import org.w3c.dom.Element +import kotlin.js.Json + external interface UIKit { val notification: UIKitNotifications val modal: UIKitDialogs + + + fun notification(message: String, parameters: Json) + fun notification(element: Element): UIKitNotification? + + fun modal(element: Element): UIKitDialog + fun modal(selector: String): UIKitDialog? } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt index c45b373..93aa44e 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt @@ -4,8 +4,6 @@ import org.w3c.dom.Element import kotlin.js.Promise external interface UIKitDialogs { - operator fun invoke(element: Element): UIKitDialog - operator fun invoke(selector: String): UIKitDialog fun alert(text: String): UIKitDialogPromiseAlert fun confirm(text: String): UIKitDialogPromiseConfirm fun prompt(title: String): UIKitDialogPromisePrompt diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt index 9aef644..adff565 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitNotifications.kt @@ -1,5 +1,6 @@ package dev.inmo.jsuikit.types +import dev.inmo.jsuikit.modifiers.UIKit import dev.inmo.jsuikit.utils.Milliseconds import org.w3c.dom.Element import kotlin.js.Json @@ -10,10 +11,6 @@ typealias NotificationsGroup = String external interface UIKitNotifications { fun closeAll(group: NotificationsGroup) - - operator fun invoke(message: String, parameters: Json) - - operator fun invoke(element: Element): UIKitNotification? } external interface UIKitNotification { @@ -39,7 +36,7 @@ data class UIKitNotificationsParameters( operator fun UIKitNotifications.invoke( message: String, parameters: UIKitNotificationsParameters -) = invoke(message, parameters.parametersJson()) +) = UIKit.notification(message, parameters.parametersJson()) operator fun UIKitNotifications.invoke( message: String,