Browse Source

fix

pull/5150/head
InsanusMokrassar 3 months ago
parent
commit
294e29a258
  1. 32
      html/internal-html-core-runtime/src/jsMain/kotlin/org/jetbrains/compose/web/internal/runtime/DomApplier.kt

32
html/internal-html-core-runtime/src/jsMain/kotlin/org/jetbrains/compose/web/internal/runtime/DomApplier.kt

@ -29,7 +29,7 @@ class DomApplier(
override fun onClear() { override fun onClear() {
// or current.node.clear()?; in all examples it calls 'clear' on the root // or current.node.clear()?; in all examples it calls 'clear' on the root
root.node.clear() root.clear()
} }
} }
@ -41,19 +41,25 @@ interface NamedEventListener : EventListener {
@ComposeWebInternalApi @ComposeWebInternalApi
open class DomNodeWrapper(open val node: Node) { open class DomNodeWrapper(open val node: Node) {
private val knownNodes: MutableList<DomNodeWrapper> = mutableListOf<DomNodeWrapper>()
fun insert(index: Int, nodeWrapper: DomNodeWrapper) { fun insert(index: Int, nodeWrapper: DomNodeWrapper) {
val length = node.childNodes.length val length = knownNodes.size
if (index < length) { if (index < length) {
node.insertBefore(nodeWrapper.node, node.childNodes[index]!!) val nodeOnIndex = knownNodes[index]
knownNodes.add(index, nodeWrapper)
node.insertBefore(nodeWrapper.node, nodeOnIndex.node)
} else { } else {
knownNodes.add(nodeWrapper)
node.appendChild(nodeWrapper.node) node.appendChild(nodeWrapper.node)
} }
} }
fun remove(index: Int, count: Int) { fun remove(index: Int, count: Int) {
repeat(count) { repeat(count) {
node.removeChild(node.childNodes[index]!!) val nodeToRemove = knownNodes.removeAt(index)
node.removeChild(nodeToRemove.node)
} }
} }
@ -67,8 +73,20 @@ open class DomNodeWrapper(open val node: Node) {
val fromIndex = if (from > to) from + i else from val fromIndex = if (from > to) from + i else from
val toIndex = if (from > to) to + i else to + count - 2 val toIndex = if (from > to) to + i else to + count - 2
val child = node.removeChild(node.childNodes[fromIndex]!!) val nodeOnIndex = knownNodes[toIndex]
node.insertBefore(child, node.childNodes[toIndex]!!)
val nodeToMove = knownNodes.removeAt(fromIndex)
node.removeChild(nodeToMove.node)
knownNodes.add(toIndex, nodeToMove)
node.insertBefore(nodeToMove.node, nodeOnIndex.node)
} }
} }
}
internal fun clear() {
knownNodes.forEach {
node.removeChild(it.node)
}
knownNodes.clear()
}
}

Loading…
Cancel
Save