diff --git a/build.gradle.kts b/build.gradle.kts index b02fa547..9eca9a0b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ plugins { } group = "org.jetbrains.kotlinx" -version = "0.7.3-SNAPSHOT" +version = "0.7.5-SNAPSHOT" buildscript { dependencies { @@ -294,50 +294,6 @@ tasks.register("jsPackagePrepare") { } } -tasks.register("publishNpm") { - dependsOn("jsPackagePrepare") - dependsOn("kotlinNodeJsSetup") - - group = "publishing" - description = "Publishes ${project.name} NPM module to 'registry.npmjs.org'." - - val kotlinNodeJsSetupTask = tasks["kotlinNodeJsSetup"] as NodeJsSetupTask - - // For some unknown reason, the node distributive's structure is different on Windows and UNIX. - val node = if (Os.isFamily(Os.FAMILY_WINDOWS)) { - kotlinNodeJsSetupTask.destination - .resolve("node.exe") - } else { - kotlinNodeJsSetupTask.destination - .resolve("bin") - .resolve("node") - } - - val npm = if (Os.isFamily(Os.FAMILY_WINDOWS)) { - kotlinNodeJsSetupTask.destination - .resolve("node_modules") - .resolve("npm") - .resolve("bin") - .resolve("npm-cli.js") - } else { - kotlinNodeJsSetupTask.destination - .resolve("lib") - .resolve("node_modules") - .resolve("npm") - .resolve("bin") - .resolve("npm-cli.js") - } - - commandLine( - node, - npm, - "publish", - "$buildDir/tmp/jsPackage", - "--//registry.npmjs.org/:_authToken=${System.getenv("NPMJS_AUTH")}", - "--access=public" - ) -} - publishing { publications { configureEach { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index fcb1018e..5d9cb3e4 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") version "1.4.31" + kotlin("jvm") version "1.6.10" } repositories { diff --git a/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt index 3c709217..570478b6 100644 --- a/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt @@ -95,7 +95,8 @@ private fun String.makeCamelCaseByDictionary() : String { var unprocessedStart = 0 allRanges.forEachIndexed { i, mr -> if (mr.range.start >= unprocessedStart) { - val startClash = allRanges.safeSubList(i + 1).asSequence().takeWhile { it.range.start == mr.range.start }.maxBy { it.value.length } + val startClash = allRanges.safeSubList(i + 1).asSequence().takeWhile { it.range.start == mr.range.start } + .maxByOrNull { it.value.length } if (startClash == null || startClash.value.length <= mr.value.length) { val possibleTail = when { mr.value.endsWith("ing") -> 3 diff --git a/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt index f975b94a..619fe087 100644 --- a/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt @@ -34,7 +34,8 @@ fun Appendable.htmlTagBuilders(receiver : String, tag : TagInfo) { htmlTagBuilderMethod(receiver, tag, false) } - val someEnumAttribute = tag.attributes.filter { it.type == AttributeType.ENUM }.maxBy { it.enumValues.size } // ?? + val someEnumAttribute = + tag.attributes.filter { it.type == AttributeType.ENUM }.maxByOrNull { it.enumValues.size } // ?? if (someEnumAttribute != null && someEnumAttribute.enumValues.size < 25) { htmlTagEnumBuilderMethod(receiver, tag, true, someEnumAttribute, 0) if (probablyContentOnly) { diff --git a/src/commonMain/kotlin/Event.kt b/src/commonMain/kotlin/Event.kt index 3909dbef..6585f7b1 100644 --- a/src/commonMain/kotlin/Event.kt +++ b/src/commonMain/kotlin/Event.kt @@ -1,13 +1,8 @@ package org.w3c.dom.events -@Suppress("HEADER_WITHOUT_IMPLEMENTATION", "NO_ACTUAL_FOR_EXPECT") expect interface Event { fun stopPropagation() fun preventDefault() - fun initEvent( - eventTypeArg: String, - canBubbleArg: Boolean, - cancelableArg: Boolean - ) + fun initEvent(eventTypeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean) } diff --git a/src/jsMain/kotlin/EventJs.kt b/src/jsMain/kotlin/EventJs.kt new file mode 100644 index 00000000..a2e8a5d7 --- /dev/null +++ b/src/jsMain/kotlin/EventJs.kt @@ -0,0 +1,23 @@ +package org.w3c.dom.events // ktlint-disable filename + +import org.w3c.dom.* + +public actual external interface Event { + val type: String + val target: EventTarget? + val currentTarget: EventTarget? + val eventPhase: Short + val bubbles: Boolean + val cancelable: Boolean + val defaultPrevented: Boolean + val composed: Boolean + val isTrusted: Boolean + val timeStamp: Number + + fun stopImmediatePropagation() + fun composedPath(): Array + + actual fun stopPropagation() + actual fun preventDefault() + actual fun initEvent(eventTypeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean) +} diff --git a/src/jsMain/kotlin/dom-js.kt b/src/jsMain/kotlin/dom-js.kt index 7892cbe1..182dfe60 100644 --- a/src/jsMain/kotlin/dom-js.kt +++ b/src/jsMain/kotlin/dom-js.kt @@ -5,7 +5,6 @@ import kotlinx.html.consumers.* import org.w3c.dom.* import org.w3c.dom.events.* -@Suppress("NOTHING_TO_INLINE") private inline fun HTMLElement.setEvent(name: String, noinline callback : (Event) -> Unit) : Unit { asDynamic()[name] = callback } diff --git a/src/jsMain/kotlin/injector.kt b/src/jsMain/kotlin/injector.kt index 4ce85a25..746db5d9 100644 --- a/src/jsMain/kotlin/injector.kt +++ b/src/jsMain/kotlin/injector.kt @@ -5,36 +5,41 @@ import kotlinx.html.dom.* import org.w3c.dom.* import kotlin.reflect.* -fun F.injectTo(bean : T, field : KMutableProperty1) { +fun F.injectTo(bean: T, field: KMutableProperty1) { field.set(bean, this) } -private fun F.injectToUnsafe(bean : T, field : KMutableProperty1) { +private fun F.injectToUnsafe(bean: T, field: KMutableProperty1) { injectTo(bean, field.asDynamic()) } interface InjectCapture -class InjectByClassName(val className : String) : InjectCapture -class InjectByTagName(val tagName : String) : InjectCapture +class InjectByClassName(val className: String) : InjectCapture +class InjectByTagName(val tagName: String) : InjectCapture object InjectRoot : InjectCapture interface CustomCapture : InjectCapture { - fun apply(element : HTMLElement) : Boolean + fun apply(element: HTMLElement): Boolean } -class InjectorConsumer(val downstream : TagConsumer, val bean : T, rules : List>>) : TagConsumer by downstream { +class InjectorConsumer( + val downstream: TagConsumer, + val bean: T, + rules: List>> +) : TagConsumer by downstream { private val classesMap: Map>> = rules - .filter { it.first is InjectByClassName } - .map { it.first as InjectByClassName to it.second } - .groupBy ({ it.first.className }, { it.second }) + .filter { it.first is InjectByClassName } + .map { it.first as InjectByClassName to it.second } + .groupBy({ it.first.className }, { it.second }) private val tagNamesMap = rules - .filter { it.first is InjectByTagName } - .map { it.first as InjectByTagName to it.second } - .groupBy({ it.first.tagName.toLowerCase() }, { it.second }) + .filter { it.first is InjectByTagName } + .map { it.first as InjectByTagName to it.second } + .groupBy({ it.first.tagName.toLowerCase() }, { it.second }) private val rootCaptures = rules.filter { it.first == InjectRoot }.map { it.second } - private val customCaptures = rules.filter {it.first is CustomCapture}.map {it.first as CustomCapture to it.second} + private val customCaptures = + rules.filter { it.first is CustomCapture }.map { it.first as CustomCapture to it.second } override fun onTagEnd(tag: Tag) { downstream.onTagEnd(tag) @@ -53,7 +58,7 @@ class InjectorConsumer(val downstream : TagConsumer, va } } - customCaptures.filter { it.first.apply(node) }.map {it.second}.forEach { field -> + customCaptures.filter { it.first.apply(node) }.map { it.second }.forEach { field -> node.injectToUnsafe(bean, field) } } @@ -68,10 +73,16 @@ class InjectorConsumer(val downstream : TagConsumer, va } } -fun TagConsumer.inject(bean : T, rules : List>>) : TagConsumer = InjectorConsumer(this, bean, rules) +fun TagConsumer.inject( + bean: T, + rules: List>> +): TagConsumer = InjectorConsumer(this, bean, rules) -fun HTMLElement.appendAndInject(bean : T, rules : List>>, block : TagConsumer.() -> Unit) : List = append { +fun HTMLElement.appendAndInject( + bean: T, + rules: List>>, + block: TagConsumer.() -> Unit +): List = append { InjectorConsumer(this@append, bean, rules).block() Unit } - diff --git a/src/jvmMain/kotlin/EventJvm.kt b/src/jvmMain/kotlin/EventJvm.kt new file mode 100644 index 00000000..be5a8429 --- /dev/null +++ b/src/jvmMain/kotlin/EventJvm.kt @@ -0,0 +1,7 @@ +package org.w3c.dom.events // ktlint-disable filename + +actual interface Event { + actual fun stopPropagation() + actual fun preventDefault() + actual fun initEvent(eventTypeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean) +} diff --git a/src/nativeMain/kotlin/EventNative.kt b/src/nativeMain/kotlin/EventNative.kt new file mode 100644 index 00000000..8036c98c --- /dev/null +++ b/src/nativeMain/kotlin/EventNative.kt @@ -0,0 +1,12 @@ +package org.w3c.dom.events // ktlint-disable filename + +actual interface Event { + actual fun stopPropagation() + actual fun preventDefault() + + actual fun initEvent( + eventTypeArg: String, + canBubbleArg: Boolean, + cancelableArg: Boolean + ) +}