Arjan van Wieringen
12/01/2023, 11:00 AMArtem Kobzar
12/01/2023, 12:12 PMlit
library.
I will try to open-source it until the end of this year.turansky
12/01/2023, 12:49 PMHTMLElement
in Kotlin Wrappers with 0 abstract methods.
Single known problem - registration in customElementRegistry
, which is sideeffect, which must be applied, only if component used.Arjan van Wieringen
12/01/2023, 1:39 PMturansky
12/01/2023, 1:42 PMKotlin wrappers are additional to the Kotlin Js browser api right?It's full replacemant. To avoid redundant imports you can use this flag.
turansky
12/01/2023, 1:43 PMI can apply it like any normal function right?You can call registration in
main
function. As result - tree shaking won't workArjan van Wieringen
12/01/2023, 2:13 PM@JsExport
class HelloWorldElement : HTMLElement() {
init {
innerHTML = "Hello World"
}
}
fun main() {
window.customElements.define("hello-world", { HelloWorldElement() })
}
And the error is:
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
turansky
12/01/2023, 2:14 PMArjan van Wieringen
12/01/2023, 2:15 PMArjan van Wieringen
12/01/2023, 2:18 PMUncaught TypeError: Illegal constructor
at createExternalThis (coreRuntime.kt:242:24)
at HelloWorldElement.new_nl_avwie_webcomponent_HelloWorldElement_vllg41_k$ (compose-web-component.js:15:19)
at new main$lambda (App.kt:14:51)
createExternalThis @ coreRuntime.kt:242
new_nl_avwie_webcomponent_HelloWorldElement_vllg41_k$ @ compose-web-component.js:15
main$lambda @ App.kt:14
Arjan van Wieringen
12/01/2023, 2:19 PMturansky
12/01/2023, 2:19 PMinit
with constructor body?Arjan van Wieringen
12/01/2023, 2:23 PMArjan van Wieringen
12/01/2023, 2:24 PMturansky
12/01/2023, 2:24 PMturansky
12/01/2023, 2:24 PMturansky
12/01/2023, 2:25 PMcustomElements.define("hello-world", HelloWorldElement::class.js)
Arjan van Wieringen
12/01/2023, 2:26 PMclass HelloWorldElement : HTMLElement() {
}
fun main() {
window.customElements.define("hello-world", { HelloWorldElement::class.js })
}
However, then i get
Uncaught TypeError: Failed to construct 'CustomElement': The result must implement HTMLElement interface
๐turansky
12/01/2023, 2:27 PMturansky
12/01/2023, 2:27 PMturansky
12/01/2023, 2:28 PMArjan van Wieringen
12/01/2023, 2:29 PMcustomElements
and the normal one. However, this wont work:
```import web.html.HTMLElement
import web.html.customElements
class HelloWorldElement : HTMLElement() {
}
fun main() {
customElements.define("hello-world", HelloWorldElement::class.js)
}
Which results in a compiler error:
Type mismatch.
Required:
CustomElementConstructor /* = JsClass<HTMLElement> */
Found:
JsClass<HelloWorldElement>
turansky
12/01/2023, 2:29 PMkotlin-browser
you will find strict declarations for CustomElementRegistry
turansky
12/01/2023, 2:30 PMcustomElements.define("hello-world", HelloWorldElement::class.js.asDynamic())
Arjan van Wieringen
12/01/2023, 2:33 PMArjan van Wieringen
12/01/2023, 2:35 PMconnectedCallback
etc handlers are missing from the wrappers. Am I correct?Arjan van Wieringen
12/01/2023, 2:36 PM@JsExport
class HelloWorldElement : HTMLElement() {
@JsName("connectedCallback")
fun connectedCallback() {
innerHTML = "<h1>Hello World</h1>"
}
}
fun main() {
customElements.define("hello-world", HelloWorldElement::class.js.asDynamic())
}
Arjan van Wieringen
12/01/2023, 2:37 PMturansky
12/01/2023, 2:37 PMCustomElementConstructor
- https://github.com/JetBrains/kotlin-wrappers/commit/8b491da103de3094690d193fdd69f25523d7e025.
Release is comingArjan van Wieringen
12/01/2023, 2:37 PMArjan van Wieringen
12/01/2023, 2:38 PMturansky
12/01/2023, 2:41 PMHowever, nothing happens. TheIn TypeScrript it's also isn't declared ๐etc handlers are missing from the wrappers. Am I correct?connectedCallback
Arjan van Wieringen
12/01/2023, 2:41 PMturansky
12/01/2023, 2:43 PMturansky
12/01/2023, 2:43 PMArjan van Wieringen
12/01/2023, 2:44 PMturansky
12/01/2023, 2:44 PMHasConnectedCallback
Arjan van Wieringen
12/01/2023, 2:44 PMturansky
12/02/2023, 2:09 PMpre.654
release.
asDynamic()
call can be removed.