|
|
|
@ -4,8 +4,9 @@ import androidx.compose.runtime.*
|
|
|
|
|
import org.jetbrains.compose.web.attributes.AttrsBuilder |
|
|
|
|
import org.jetbrains.compose.web.ExperimentalComposeWebApi |
|
|
|
|
import org.jetbrains.compose.web.css.StyleHolder |
|
|
|
|
import org.jetbrains.compose.web.internal.runtime.DomElementWrapper |
|
|
|
|
import org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi |
|
|
|
|
import org.jetbrains.compose.web.internal.runtime.DomNodeWrapper |
|
|
|
|
import org.jetbrains.compose.web.internal.runtime.NamedEventListener |
|
|
|
|
import org.w3c.dom.Element |
|
|
|
|
import org.w3c.dom.HTMLElement |
|
|
|
|
import org.w3c.dom.css.ElementCSSInlineStyle |
|
|
|
@ -35,44 +36,57 @@ private inline fun <TScope, T> ComposeDomNode(
|
|
|
|
|
currentComposer.endNode() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
|
private class DomElementWrapper(override val node: Element): DomNodeWrapper(node) { |
|
|
|
|
private var currentListeners = emptyList<NamedEventListener>() |
|
|
|
|
|
|
|
|
|
@OptIn(ComposeWebInternalApi::class) |
|
|
|
|
private fun DomElementWrapper.updateProperties(applicators: List<Pair<(Element, Any) -> Unit, Any>>) { |
|
|
|
|
node.removeAttribute("class") |
|
|
|
|
fun updateEventListeners(list: List<NamedEventListener>) { |
|
|
|
|
currentListeners.forEach { |
|
|
|
|
node.removeEventListener(it.name, it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
applicators.forEach { (applicator, item) -> |
|
|
|
|
applicator(node, item) |
|
|
|
|
currentListeners = list |
|
|
|
|
|
|
|
|
|
currentListeners.forEach { |
|
|
|
|
node.addEventListener(it.name, it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@OptIn(ComposeWebInternalApi::class) |
|
|
|
|
private fun DomElementWrapper.updateStyleDeclarations(styleApplier: StyleHolder) { |
|
|
|
|
when (node) { |
|
|
|
|
is HTMLElement, is SVGElement -> { |
|
|
|
|
node.removeAttribute("style") |
|
|
|
|
fun updateProperties(applicators: List<Pair<(Element, Any) -> Unit, Any>>) { |
|
|
|
|
node.removeAttribute("class") |
|
|
|
|
|
|
|
|
|
applicators.forEach { (applicator, item) -> |
|
|
|
|
applicator(node, item) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val style = node.unsafeCast<ElementCSSInlineStyle>().style |
|
|
|
|
fun updateStyleDeclarations(styleApplier: StyleHolder) { |
|
|
|
|
when (node) { |
|
|
|
|
is HTMLElement, is SVGElement -> { |
|
|
|
|
node.removeAttribute("style") |
|
|
|
|
|
|
|
|
|
styleApplier.properties.forEach { (name, value) -> |
|
|
|
|
style.setProperty(name, value.toString()) |
|
|
|
|
} |
|
|
|
|
val style = node.unsafeCast<ElementCSSInlineStyle>().style |
|
|
|
|
|
|
|
|
|
styleApplier.variables.forEach { (name, value) -> |
|
|
|
|
style.setProperty(name, value.toString()) |
|
|
|
|
styleApplier.properties.forEach { (name, value) -> |
|
|
|
|
style.setProperty(name, value.toString()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
styleApplier.variables.forEach { (name, value) -> |
|
|
|
|
style.setProperty(name, value.toString()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@OptIn(ComposeWebInternalApi::class) |
|
|
|
|
fun DomElementWrapper.updateAttrs(attrs: Map<String, String>) { |
|
|
|
|
node.getAttributeNames().forEach { name -> |
|
|
|
|
if (name == "style") return@forEach |
|
|
|
|
node.removeAttribute(name) |
|
|
|
|
} |
|
|
|
|
fun updateAttrs(attrs: Map<String, String>) { |
|
|
|
|
node.getAttributeNames().forEach { name -> |
|
|
|
|
if (name == "style") return@forEach |
|
|
|
|
node.removeAttribute(name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
attrs.forEach { |
|
|
|
|
node.setAttribute(it.key, it.value) |
|
|
|
|
attrs.forEach { |
|
|
|
|
node.setAttribute(it.key, it.value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|