Skip to content

Commit

Permalink
fix: Alias Event to org.w3c.dom.events.Event #235
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Sep 18, 2023
1 parent 7f01c31 commit 150b3d8
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 378 deletions.
9 changes: 5 additions & 4 deletions api/kotlinx-html.api
Original file line number Diff line number Diff line change
Expand Up @@ -3350,10 +3350,11 @@ public final class kotlinx/html/impl/DelegatingMap : java/util/Map, kotlin/jvm/i
public final fun values ()Ljava/util/Collection;
}

public abstract interface class kotlinx/html/org/w3c/dom/events/Event {
public abstract fun initEvent (Ljava/lang/String;ZZ)V
public abstract fun preventDefault ()V
public abstract fun stopPropagation ()V
public class kotlinx/html/org/w3c/dom/events/Event {
public fun <init> ()V
public fun initEvent (Ljava/lang/String;ZZ)V
public fun preventDefault ()V
public fun stopPropagation ()V
}

public final class kotlinx/html/stream/HTMLStreamBuilder : kotlinx/html/TagConsumer {
Expand Down
908 changes: 584 additions & 324 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/commonMain/kotlin/Event.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kotlinx.html.org.w3c.dom.events

expect interface Event {
expect open class Event {
fun stopPropagation()
fun preventDefault()

fun initEvent(eventTypeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean)
fun initEvent(type: String, bubbles: Boolean, cancelable: Boolean)
}
7 changes: 5 additions & 2 deletions src/commonMain/kotlin/stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import kotlinx.html.*
import kotlinx.html.consumers.*
import kotlinx.html.org.w3c.dom.events.Event

class HTMLStreamBuilder<out O : Appendable>(val out: O, val prettyPrint: Boolean, val xhtmlCompatible: Boolean) :
TagConsumer<O> {
class HTMLStreamBuilder<out O : Appendable>(
val out: O,
val prettyPrint: Boolean,
val xhtmlCompatible: Boolean
) : TagConsumer<O> {
private var level = 0
private var ln = true

Expand Down
21 changes: 1 addition & 20 deletions src/jsMain/kotlin/EventJs.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
package kotlinx.html.org.w3c.dom.events // ktlint-disable filename

import org.w3c.dom.events.EventTarget

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)
}
actual typealias Event = org.w3c.dom.events.Event
9 changes: 5 additions & 4 deletions src/jvmMain/kotlin/EventJvm.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package kotlinx.html.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)
actual open class Event {
actual open fun stopPropagation() {}
actual open fun preventDefault() {}

actual open fun initEvent(type: String, bubbles: Boolean, cancelable: Boolean) {}
}
7 changes: 2 additions & 5 deletions src/jvmTest/kotlin/dom-trees.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class TestDOMTrees {
<html>
<body>
<h1>header</h1>
<div>
content<span>yo</span>
<div>content<span>yo</span>
</div>
</body>
</html>""".trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n"))
Expand Down Expand Up @@ -105,9 +104,7 @@ class TestDOMTrees {
<body>
<div id="content">
<p>p1</p>
<p>
p2
<p>p3</p>
<p>p2<p>p3</p>
</p>
</div>
</body>
Expand Down
29 changes: 20 additions & 9 deletions src/jvmTest/kotlin/html5-tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ class Html5TagsTest {

print(tree.serialize(true).trim().replace("\r\n", "\n"))

assertEquals("<!DOCTYPE html>\n<html><body><main class=\"main-test\" id=\"test-node\">content</main></body></html>", tree.serialize(false))
assertEquals("""
assertEquals(
"<!DOCTYPE html>\n<html><body><main class=\"main-test\" id=\"test-node\">content</main></body></html>",
tree.serialize(false)
)
assertEquals(
"""
<!DOCTYPE html>
<html>
<body>
<main class="main-test" id="test-node">content</main>
</body>
</html>""".trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n"))
</html>""".trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n")
)
}

@test fun `able to create complex tree and render it with pretty print`() {
@test
fun `able to create complex tree and render it with pretty print`() {
val tree = createHTMLDocument().html {
body {
h1 {
Expand All @@ -45,16 +51,21 @@ class Html5TagsTest {
}
}

assertEquals("<!DOCTYPE html>\n<html><body><h1>header</h1><div>content<span>yo</span></div></body></html>", tree.serialize(false))
assertEquals("""
assertEquals(
"<!DOCTYPE html>\n<html><body><h1>header</h1><div>content<span>yo</span></div></body></html>",
tree.serialize(false)
)
val serialize = tree.serialize(true)
assertEquals(
"""
<!DOCTYPE html>
<html>
<body>
<h1>header</h1>
<div>
content<span>yo</span>
<div>content<span>yo</span>
</div>
</body>
</html>""".trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n"))
</html>""".trimIndent(), serialize.trim().replace("\r\n", "\n")
)
}
}
12 changes: 4 additions & 8 deletions src/nativeMain/kotlin/EventNative.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package kotlinx.html.org.w3c.dom.events // ktlint-disable filename

actual interface Event {
actual fun stopPropagation()
actual fun preventDefault()
actual open class Event {
actual open fun stopPropagation() {}
actual open fun preventDefault() {}

actual fun initEvent(
eventTypeArg: String,
canBubbleArg: Boolean,
cancelableArg: Boolean
)
actual open fun initEvent(type: String, bubbles: Boolean, cancelable: Boolean) {}
}

0 comments on commit 150b3d8

Please sign in to comment.