From c73d7f9113b7667551c4e83ce0a2384c2bcce1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Petu=C5=A1ka?= Date: Wed, 29 Dec 2021 15:10:27 +0000 Subject: [PATCH] Module cleanup --- buildSrc/src/main/kotlin/_global.kt | 9 ++++++ .../kotlin/plugin.library-compose.gradle.kts | 8 ++++- gradle.properties | 1 - kmdc/build.gradle.kts | 4 ++- kmdc/kmdc-button/build.gradle.kts | 5 ++- kmdc/kmdc-card/build.gradle.kts | 4 ++- kmdc/kmdc-checkbox/build.gradle.kts | 4 ++- kmdc/kmdc-chips/build.gradle.kts | 4 ++- kmdc/kmdc-core/build.gradle.kts | 2 +- kmdc/kmdc-core/src/jsMain/kotlin/MDCDsl.kt | 11 +++++++ kmdc/kmdc-core/src/jsMain/kotlin/util.kt | 32 +++++++++++-------- kmdc/kmdc-drawer/build.gradle.kts | 4 ++- kmdc/kmdc-form-field/build.gradle.kts | 4 ++- kmdc/kmdc-icon-button/build.gradle.kts | 4 ++- kmdc/kmdc-layout-grid/build.gradle.kts | 4 ++- kmdc/kmdc-linear-progress/build.gradle.kts | 4 ++- kmdc/kmdc-list/build.gradle.kts | 4 ++- kmdc/kmdc-radio/build.gradle.kts | 4 ++- kmdc/kmdc-ripple/build.gradle.kts | 4 ++- kmdc/kmdc-segmented-button/build.gradle.kts | 4 ++- kmdc/kmdc-snackbar/build.gradle.kts | 4 ++- kmdc/kmdc-switch/build.gradle.kts | 4 ++- kmdc/kmdc-textfield/build.gradle.kts | 4 ++- kmdc/kmdc-tooltip/build.gradle.kts | 4 ++- kmdc/kmdc-top-app-bar/build.gradle.kts | 4 ++- kmdc/kmdc-typography/build.gradle.kts | 4 ++- kmdcx/build.gradle.kts | 4 ++- kmdcx/kmdcx-icons/build.gradle.kts | 2 +- test/build.gradle.kts | 2 +- 29 files changed, 113 insertions(+), 39 deletions(-) create mode 100644 buildSrc/src/main/kotlin/_global.kt create mode 100644 kmdc/kmdc-core/src/jsMain/kotlin/MDCDsl.kt diff --git a/buildSrc/src/main/kotlin/_global.kt b/buildSrc/src/main/kotlin/_global.kt new file mode 100644 index 00000000..302e5ecb --- /dev/null +++ b/buildSrc/src/main/kotlin/_global.kt @@ -0,0 +1,9 @@ +import org.gradle.api.NamedDomainObjectProvider +import org.gradle.kotlin.dsl.named +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +val org.gradle.api.NamedDomainObjectContainer.jsMain: NamedDomainObjectProvider + get() = named("jsMain") + +val org.gradle.api.NamedDomainObjectContainer.jsTest: NamedDomainObjectProvider + get() = named("jsTest") diff --git a/buildSrc/src/main/kotlin/plugin.library-compose.gradle.kts b/buildSrc/src/main/kotlin/plugin.library-compose.gradle.kts index 71106b14..fa4cf6a2 100644 --- a/buildSrc/src/main/kotlin/plugin.library-compose.gradle.kts +++ b/buildSrc/src/main/kotlin/plugin.library-compose.gradle.kts @@ -5,7 +5,13 @@ plugins { kotlin { sourceSets { - named("jsTest") { + all { + languageSettings { + optIn("dev.petuska.kmdc.core.MDCInternalDsl") + optIn("kotlin.RequiresOptIn") + } + } + jsTest { dependencies { implementation(compose.web.testUtils) } diff --git a/gradle.properties b/gradle.properties index d520779a..a68d17b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,6 @@ gh.owner.name=Martynas Petuska gh.owner.email=martynas@petuska.dev #======================================= Project ======================================== group=dev.petuska -description=Kotlin wrappers for material-components-web version=0.0.0 #======================================== Build ========================================= # linux | macos | windows diff --git a/kmdc/build.gradle.kts b/kmdc/build.gradle.kts index bc887650..5abcf884 100644 --- a/kmdc/build.gradle.kts +++ b/kmdc/build.gradle.kts @@ -3,9 +3,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/material-components-web" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { subprojects.forEach(::api) } diff --git a/kmdc/kmdc-button/build.gradle.kts b/kmdc/kmdc-button/build.gradle.kts index 61bb60e4..192e639b 100644 --- a/kmdc/kmdc-button/build.gradle.kts +++ b/kmdc/kmdc-button/build.gradle.kts @@ -5,9 +5,12 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/button" + kotlin { sourceSets { - named("jsMain") { + commonMain + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-card/build.gradle.kts b/kmdc/kmdc-card/build.gradle.kts index 4d5b7b8b..c56601d4 100644 --- a/kmdc/kmdc-card/build.gradle.kts +++ b/kmdc/kmdc-card/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/card" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-button")) diff --git a/kmdc/kmdc-checkbox/build.gradle.kts b/kmdc/kmdc-checkbox/build.gradle.kts index 8db365db..841e5ca4 100644 --- a/kmdc/kmdc-checkbox/build.gradle.kts +++ b/kmdc/kmdc-checkbox/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/checkbox" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(compose.web.svg) api(project(":kmdc:kmdc-core")) diff --git a/kmdc/kmdc-chips/build.gradle.kts b/kmdc/kmdc-chips/build.gradle.kts index aa2be635..02d136aa 100644 --- a/kmdc/kmdc-chips/build.gradle.kts +++ b/kmdc/kmdc-chips/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/chips" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/chips", mdcVersion)) diff --git a/kmdc/kmdc-core/build.gradle.kts b/kmdc/kmdc-core/build.gradle.kts index 17b80fe7..b5fc2bb2 100644 --- a/kmdc/kmdc-core/build.gradle.kts +++ b/kmdc/kmdc-core/build.gradle.kts @@ -5,7 +5,7 @@ plugins { kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(compose.runtime) api(compose.web.core) diff --git a/kmdc/kmdc-core/src/jsMain/kotlin/MDCDsl.kt b/kmdc/kmdc-core/src/jsMain/kotlin/MDCDsl.kt new file mode 100644 index 00000000..66b6a01a --- /dev/null +++ b/kmdc/kmdc-core/src/jsMain/kotlin/MDCDsl.kt @@ -0,0 +1,11 @@ +package dev.petuska.kmdc.core + +@DslMarker +public annotation class MDCDsl + +@DslMarker +public annotation class MDCAttrsDsl + +@DslMarker +@RequiresOptIn("Marks DSL that's used internally by KMDC modules and does not provide any stability guarantees.") +public annotation class MDCInternalDsl diff --git a/kmdc/kmdc-core/src/jsMain/kotlin/util.kt b/kmdc/kmdc-core/src/jsMain/kotlin/util.kt index 044078d7..3fad891e 100644 --- a/kmdc/kmdc-core/src/jsMain/kotlin/util.kt +++ b/kmdc/kmdc-core/src/jsMain/kotlin/util.kt @@ -1,17 +1,11 @@ package dev.petuska.kmdc.core import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffectScope import org.jetbrains.compose.web.attributes.AttrsBuilder import org.w3c.dom.Element -import org.w3c.dom.HTMLElement import org.w3c.dom.events.Event -@DslMarker -public annotation class MDCDsl - -@DslMarker -public annotation class MDCAttrsDsl - public typealias Builder = T.() -> Unit public typealias ComposableBuilder = @Composable Builder @@ -23,28 +17,40 @@ public abstract external class MDCEvent : Event { public var detail: T } +@MDCInternalDsl public var Element.mdc: dynamic get() = asDynamic().mdc set(value) { asDynamic().mdc = value } +@MDCInternalDsl public fun Element.mdc(action: Builder? = null): T? = mdc.unsafeCast()?.also { action?.invoke(it) } +@MDCInternalDsl public inline fun jsObject(builder: Builder = { }): T = js("({})").unsafeCast().apply(builder) -@MDCAttrsDsl -public fun AttrsBuilder.initialiseMDC(mdcInit: (HTMLElement) -> T, onDispose: Builder? = null) { +@MDCInternalDsl +public fun AttrsBuilder.initialiseMDC( + mdcInit: (E) -> T, + onDispose: Builder? = null, + postInit: (DisposableEffectScope.(el: E, mdc: T) -> Unit)? = null, +) { ref { - it.mdc = mdcInit(it) + it.mdc = mdcInit(it).also { mdc -> + postInit?.invoke(this, it, mdc) + } onDispose { it.mdc(onDispose) } } } -@MDCAttrsDsl -public fun AttrsBuilder.initialiseMDC(mdcInit: (HTMLElement) -> T) { - initialiseMDC(mdcInit, Destroyable::destroy) +@MDCInternalDsl +public fun AttrsBuilder.initialiseMDC( + mdcInit: (E) -> T, + postInit: (DisposableEffectScope.(el: E, mdc: T) -> Unit)? = null, +) { + initialiseMDC(mdcInit, Destroyable::destroy, postInit) } diff --git a/kmdc/kmdc-drawer/build.gradle.kts b/kmdc/kmdc-drawer/build.gradle.kts index c45185d3..916850b2 100644 --- a/kmdc/kmdc-drawer/build.gradle.kts +++ b/kmdc/kmdc-drawer/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/drawer" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/drawer", mdcVersion)) diff --git a/kmdc/kmdc-form-field/build.gradle.kts b/kmdc/kmdc-form-field/build.gradle.kts index 15fb6682..9632fb6a 100644 --- a/kmdc/kmdc-form-field/build.gradle.kts +++ b/kmdc/kmdc-form-field/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/form-field" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-icon-button/build.gradle.kts b/kmdc/kmdc-icon-button/build.gradle.kts index c284dab3..564bd646 100644 --- a/kmdc/kmdc-icon-button/build.gradle.kts +++ b/kmdc/kmdc-icon-button/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/icon-button" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-layout-grid/build.gradle.kts b/kmdc/kmdc-layout-grid/build.gradle.kts index 4e597cee..7f3c2768 100644 --- a/kmdc/kmdc-layout-grid/build.gradle.kts +++ b/kmdc/kmdc-layout-grid/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/layout-grid" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/layout-grid", mdcVersion)) diff --git a/kmdc/kmdc-linear-progress/build.gradle.kts b/kmdc/kmdc-linear-progress/build.gradle.kts index 444e3332..c126d060 100644 --- a/kmdc/kmdc-linear-progress/build.gradle.kts +++ b/kmdc/kmdc-linear-progress/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/linear-progress" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/linear-progress", mdcVersion)) diff --git a/kmdc/kmdc-list/build.gradle.kts b/kmdc/kmdc-list/build.gradle.kts index aa830195..0c841861 100644 --- a/kmdc/kmdc-list/build.gradle.kts +++ b/kmdc/kmdc-list/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/list" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-radio/build.gradle.kts b/kmdc/kmdc-radio/build.gradle.kts index b1eaa130..6e480312 100644 --- a/kmdc/kmdc-radio/build.gradle.kts +++ b/kmdc/kmdc-radio/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/radio" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-form-field")) diff --git a/kmdc/kmdc-ripple/build.gradle.kts b/kmdc/kmdc-ripple/build.gradle.kts index d3403f68..57416bf7 100644 --- a/kmdc/kmdc-ripple/build.gradle.kts +++ b/kmdc/kmdc-ripple/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/ripple" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/ripple", mdcVersion)) diff --git a/kmdc/kmdc-segmented-button/build.gradle.kts b/kmdc/kmdc-segmented-button/build.gradle.kts index 7757d9c9..ecb19e3c 100644 --- a/kmdc/kmdc-segmented-button/build.gradle.kts +++ b/kmdc/kmdc-segmented-button/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/segmented-button" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-snackbar/build.gradle.kts b/kmdc/kmdc-snackbar/build.gradle.kts index d7cb33ce..30536487 100644 --- a/kmdc/kmdc-snackbar/build.gradle.kts +++ b/kmdc/kmdc-snackbar/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/snackbar" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-button")) diff --git a/kmdc/kmdc-switch/build.gradle.kts b/kmdc/kmdc-switch/build.gradle.kts index 3625e58f..79ce2b5f 100644 --- a/kmdc/kmdc-switch/build.gradle.kts +++ b/kmdc/kmdc-switch/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/switch" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-textfield/build.gradle.kts b/kmdc/kmdc-textfield/build.gradle.kts index 71c4bcc5..cc63d390 100644 --- a/kmdc/kmdc-textfield/build.gradle.kts +++ b/kmdc/kmdc-textfield/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/textfield" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-ripple")) api(npm("@material/textfield", mdcVersion)) diff --git a/kmdc/kmdc-tooltip/build.gradle.kts b/kmdc/kmdc-tooltip/build.gradle.kts index b6223dc0..335c9654 100644 --- a/kmdc/kmdc-tooltip/build.gradle.kts +++ b/kmdc/kmdc-tooltip/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/tooltip" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-ripple")) diff --git a/kmdc/kmdc-top-app-bar/build.gradle.kts b/kmdc/kmdc-top-app-bar/build.gradle.kts index 6d3d92ed..78e9875b 100644 --- a/kmdc/kmdc-top-app-bar/build.gradle.kts +++ b/kmdc/kmdc-top-app-bar/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/top-app-bar" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(project(":kmdc:kmdc-icon-button")) diff --git a/kmdc/kmdc-typography/build.gradle.kts b/kmdc/kmdc-typography/build.gradle.kts index 13368944..ab680434 100644 --- a/kmdc/kmdc-typography/build.gradle.kts +++ b/kmdc/kmdc-typography/build.gradle.kts @@ -5,9 +5,11 @@ plugins { id("plugin.publishing-mpp") } +description = "Compose Multiplatform Kotlin/JS wrappers for @material/typography" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { api(project(":kmdc:kmdc-core")) api(npm("@material/typography", mdcVersion)) diff --git a/kmdcx/build.gradle.kts b/kmdcx/build.gradle.kts index bc887650..ea3ec681 100644 --- a/kmdcx/build.gradle.kts +++ b/kmdcx/build.gradle.kts @@ -3,9 +3,11 @@ plugins { id("plugin.publishing-mpp") } +description = "All KMDC extensions" + kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { subprojects.forEach(::api) } diff --git a/kmdcx/kmdcx-icons/build.gradle.kts b/kmdcx/kmdcx-icons/build.gradle.kts index ba89fc00..7fc5ec98 100644 --- a/kmdcx/kmdcx-icons/build.gradle.kts +++ b/kmdcx/kmdcx-icons/build.gradle.kts @@ -7,7 +7,7 @@ plugins { kotlin { sourceSets { - named("jsMain") { + jsMain { dependencies { val mdcIconsVersion = versionFor("version.npm.material-icons") api(project(":kmdc:kmdc-core")) diff --git a/test/build.gradle.kts b/test/build.gradle.kts index 30912aa6..7f3cfd90 100644 --- a/test/build.gradle.kts +++ b/test/build.gradle.kts @@ -15,7 +15,7 @@ kotlin { api("org.jetbrains.kotlinx:kotlinx-coroutines-test:_") } } - named("jsMain") { + jsMain { dependencies { api(kotlin("test-js")) implementation(devNpm("sass", "^1.42.1"))