Skip to content

Commit

Permalink
Fix critical expect-actual suppress
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Mar 23, 2022
1 parent f55bf94 commit 913bd0a
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 72 deletions.
46 changes: 1 addition & 45 deletions build.gradle.kts
Expand Up @@ -14,7 +14,7 @@ plugins {
}

group = "org.jetbrains.kotlinx"
version = "0.7.3-SNAPSHOT"
version = "0.7.5-SNAPSHOT"

buildscript {
dependencies {
Expand Down Expand Up @@ -294,50 +294,6 @@ tasks.register<Copy>("jsPackagePrepare") {
}
}

tasks.register<Exec>("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 {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.4.31"
kotlin("jvm") version "1.6.10"
}

repositories {
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt
Expand Up @@ -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
Expand Down
Expand Up @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions 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)
}
23 changes: 23 additions & 0 deletions 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<EventTarget>

actual fun stopPropagation()
actual fun preventDefault()
actual fun initEvent(eventTypeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean)
}
1 change: 0 additions & 1 deletion src/jsMain/kotlin/dom-js.kt
Expand Up @@ -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
}
Expand Down
45 changes: 28 additions & 17 deletions src/jsMain/kotlin/injector.kt
Expand Up @@ -5,36 +5,41 @@ import kotlinx.html.dom.*
import org.w3c.dom.*
import kotlin.reflect.*

fun <F : Any, T : Any> F.injectTo(bean : T, field : KMutableProperty1<T, in F>) {
fun <F : Any, T : Any> F.injectTo(bean: T, field: KMutableProperty1<T, in F>) {
field.set(bean, this)
}

private fun <F : Any, T : Any> F.injectToUnsafe(bean : T, field : KMutableProperty1<T, out F>) {
private fun <F : Any, T : Any> F.injectToUnsafe(bean: T, field: KMutableProperty1<T, out F>) {
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<out T: Any>(val downstream : TagConsumer<HTMLElement>, val bean : T, rules : List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>) : TagConsumer<HTMLElement> by downstream {
class InjectorConsumer<out T : Any>(
val downstream: TagConsumer<HTMLElement>,
val bean: T,
rules: List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>
) : TagConsumer<HTMLElement> by downstream {

private val classesMap: Map<String, List<KMutableProperty1<T, out HTMLElement>>> = 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)
Expand All @@ -53,7 +58,7 @@ class InjectorConsumer<out T: Any>(val downstream : TagConsumer<HTMLElement>, 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)
}
}
Expand All @@ -68,10 +73,16 @@ class InjectorConsumer<out T: Any>(val downstream : TagConsumer<HTMLElement>, va
}
}

fun <T: Any> TagConsumer<HTMLElement>.inject(bean : T, rules : List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>) : TagConsumer<HTMLElement> = InjectorConsumer(this, bean, rules)
fun <T : Any> TagConsumer<HTMLElement>.inject(
bean: T,
rules: List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>
): TagConsumer<HTMLElement> = InjectorConsumer(this, bean, rules)

fun <T: Any> HTMLElement.appendAndInject(bean : T, rules : List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>, block : TagConsumer<HTMLElement>.() -> Unit) : List<HTMLElement> = append {
fun <T : Any> HTMLElement.appendAndInject(
bean: T,
rules: List<Pair<InjectCapture, KMutableProperty1<T, out HTMLElement>>>,
block: TagConsumer<HTMLElement>.() -> Unit
): List<HTMLElement> = append {
InjectorConsumer(this@append, bean, rules).block()
Unit
}

7 changes: 7 additions & 0 deletions 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)
}
12 changes: 12 additions & 0 deletions 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
)
}

0 comments on commit 913bd0a

Please sign in to comment.