janvladimirmostert
03/26/2025, 7:05 PMopen external class HTMLElement
class BlahComponent : HTMLElement() { }
window.customElements.define("test-blah", BlahComponent::class.js as () -> dynamic)
val e = document.createElement("test-blah")
e.attachShadow(ShadowRootInit(ShadowRootMode.OPEN)).also {
it.asDynamic().innerHTML = "<p>BLAH!</p>"
}
doing something like this, I can get the callbacks working too
open external class HTMLElement
external interface WebComponent {
fun connectedCallback()
fun disconnectedCallback()
fun adoptedCallback()
fun attributeChangedCallback(name: String, oldValue: String, newValue: String)
}
class BlahComponent : WebComponent, HTMLElement() {
override fun connectedCallback() {
println("connectedCallback")
}
override fun disconnectedCallback() {
println("disconnectedCallback")
}
override fun adoptedCallback() {
println("adoptedCallback")
}
override fun attributeChangedCallback(name: String, oldValue: String, newValue: String) {
println("attributeChangedCallback: $name $oldValue $newValue")
}
}
but it feels like I'm re-implementing / wrapping something from scratch that is probably already there somewhereturansky
03/26/2025, 9:03 PMturansky
03/26/2025, 9:05 PMturansky
03/26/2025, 9:07 PMjanvladimirmostert
03/26/2025, 9:49 PMturansky
03/27/2025, 12:21 AM@JsStatic
is already available in Kotlin/JS ;)