make it possible to connect modules in project
This commit is contained in:
@@ -2,6 +2,7 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
@@ -12,6 +13,8 @@ kotlin {
|
||||
dependencies {
|
||||
api project(":postssystem.features.content.binary.common")
|
||||
api project(":postssystem.features.common.client")
|
||||
api project(":postssystem.features.content.client")
|
||||
api libs.microutils.common.compose
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,44 @@
|
||||
package dev.inmo.postssystem.features.content.binary.client
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
import dev.inmo.jsuikit.elements.DefaultButton
|
||||
import dev.inmo.jsuikit.modifiers.UIKitWidth
|
||||
import dev.inmo.micro_utils.common.selectFile
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.content.client.ContentClientProvider
|
||||
import dev.inmo.postssystem.features.content.common.*
|
||||
import org.koin.core.module.Module
|
||||
|
||||
object LoadingClientModule : ModuleLoader {
|
||||
init {
|
||||
AdditionalModules.addModule(this)
|
||||
}
|
||||
|
||||
override fun Module.load() {
|
||||
singleWithRandomQualifier<ContentClientProvider> {
|
||||
BinaryContentClientProvider
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val loadingClientModuleForLoadingAtRuntime = LoadingClientModule
|
||||
|
||||
object BinaryContentClientProvider : ContentClientProvider {
|
||||
override fun contentTypeNameForUser(): String = "File"
|
||||
|
||||
@Composable
|
||||
override fun renderNewInstance(state: MutableState<Content?>) {
|
||||
console.log(state.value)
|
||||
val value = (state.value as? BinaryContent)
|
||||
if (value == null) {
|
||||
selectFile {
|
||||
state.value = it.binaryContent()
|
||||
}
|
||||
}
|
||||
DefaultButton(value ?.filename ?.name ?: "Select file", UIKitWidth.Expand) {
|
||||
selectFile {
|
||||
state.value = it.binaryContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.postssystem.features.content.client
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.w3c.dom.HTMLElement
|
||||
@@ -7,5 +8,6 @@ import org.w3c.dom.HTMLElement
|
||||
interface ContentClientProvider {
|
||||
fun contentTypeNameForUser(): String
|
||||
|
||||
fun drawNewContent(root: HTMLElement): StateFlow<Content>
|
||||
@Composable
|
||||
fun renderNewInstance(state: MutableState<Content?>)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
@@ -3,39 +3,37 @@ package dev.inmo.postssystem.features.content.text.client
|
||||
import androidx.compose.runtime.*
|
||||
import dev.inmo.jsuikit.modifiers.UIKitWidth
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.micro_utils.common.compose.renderComposableAndLinkToRoot
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.content.client.ContentClientProvider
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import dev.inmo.postssystem.features.content.text.common.TextContent
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.jetbrains.compose.web.dom.TextArea
|
||||
import org.jetbrains.compose.web.renderComposable
|
||||
import org.w3c.dom.HTMLElement
|
||||
import org.koin.core.module.Module
|
||||
|
||||
val loadingClientModule = ModuleLoader {
|
||||
singleWithRandomQualifier<ContentClientProvider> {
|
||||
TextContentClientProvider
|
||||
object LoadingClientModule : ModuleLoader {
|
||||
init {
|
||||
AdditionalModules.addModule(this)
|
||||
}
|
||||
|
||||
override fun Module.load() {
|
||||
singleWithRandomQualifier<ContentClientProvider> {
|
||||
TextContentClientProvider
|
||||
}
|
||||
}
|
||||
}.also {
|
||||
AdditionalModules.addModule(it)
|
||||
}
|
||||
|
||||
private val loadingClientModuleForLoadingAtRuntime = LoadingClientModule
|
||||
|
||||
object TextContentClientProvider : ContentClientProvider {
|
||||
override fun contentTypeNameForUser(): String = "Text"
|
||||
|
||||
override fun drawNewContent(root: HTMLElement): StateFlow<Content> {
|
||||
val flow = MutableStateFlow(TextContent(""))
|
||||
|
||||
renderComposableAndLinkToRoot(root) {
|
||||
val state = remember { flow.collectAsState() }
|
||||
TextArea(state.value.text) {
|
||||
include(UIKitWidth.Expand)
|
||||
onInput { flow.value = TextContent(it.value) }
|
||||
}
|
||||
@Composable
|
||||
override fun renderNewInstance(state: MutableState<Content?>) {
|
||||
console.log(state.value)
|
||||
val value = state.value as? TextContent
|
||||
TextArea(value ?.text) {
|
||||
include(UIKitWidth.Expand)
|
||||
onInput { state.value = TextContent(it.value) }
|
||||
}
|
||||
|
||||
return flow
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user