This commit is contained in:
2022-08-10 20:53:06 +02:00
parent 5f7fde44c6
commit 1b93c54cf4
4 changed files with 11 additions and 33 deletions

View File

@@ -6,7 +6,7 @@ plugins {
}
group = "nl.astraeus"
version = "1.0.6"
version = "1.0.7-SNAPSHOT"
repositories {
mavenCentral()

View File

@@ -127,9 +127,7 @@ internal fun Element.setKompEvent(name: String, event: (Event) -> Unit) {
name
}
if (Komponent.updateMode.isUpdate) {
getKompEvents()[eventName] = event
}
getKompEvents()[eventName] = event
this.addEventListener(eventName, event)
}

View File

@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalStdlibApi::class)
package nl.astraeus.komp
import kotlinx.browser.document
@@ -55,7 +53,7 @@ private fun ArrayList<ElementIndex>.currentPosition(): ElementIndex? {
return if (this.size < 2) {
null
} else {
this[this.size-2]
this[this.size - 2]
}
}
@@ -157,13 +155,10 @@ class HtmlBuilder(
//logReplace"onTagStart, currentElement1.1: $currentNode")
currentPosition.currentParent().appendChild(currentNode!!)
} else if (
Komponent.updateMode.isReplace ||
!currentNode?.asElement()?.tagName.equals(tag.tagName, true) ||
(
!currentNode?.asElement()?.tagName.equals(tag.tagName, true) ||
(
tag.namespace != null &&
!currentNode?.asElement()?.namespaceURI.equals(tag.namespace, true)
)
tag.namespace != null &&
!currentNode?.asElement()?.namespaceURI.equals(tag.namespace, true)
)
) {
logReplace { "onTagStart, currentElement, namespace: ${currentNode?.asElement()?.namespaceURI} -> ${tag.namespace}" }
@@ -186,22 +181,16 @@ class HtmlBuilder(
root = currentNode as Element
}
if (Komponent.updateMode.isUpdate) {
currentElement?.clearKompEvents()
(currentElement as? HTMLInputElement)?.checked = false
}
currentElement?.clearKompEvents()
(currentElement as? HTMLInputElement)?.checked = false
currentPosition.lastOrNull()?.setAttr?.clear()
// if currentElement = checkbox make sure it's cleared
for (entry in tag.attributesEntries) {
currentElement!!.setKompAttribute(entry.key, entry.value)
currentPosition.lastOrNull()?.setAttr?.add(entry.key)
}
if (tag.namespace != null && Komponent.updateMode.isReplace) {
//logReplace"onTagStart, same node type")
(currentNode as? Element)?.innerHTML = ""
}
}
currentPosition.push(currentNode!!)

View File

@@ -7,6 +7,7 @@ import org.w3c.dom.HTMLElement
import org.w3c.dom.get
private var currentKomponent: Komponent? = null
fun FlowOrMetaDataOrPhrasingContent.currentKomponent(): Komponent =
currentKomponent ?: error("No current komponent defined! Only call from render code!")
@@ -16,15 +17,6 @@ enum class UnsafeMode {
UNSAFE_SVG_ONLY
}
enum class UpdateMode {
REPLACE,
UPDATE,
;
val isReplace: Boolean get() { return this == REPLACE }
val isUpdate: Boolean get() { return this == UPDATE }
}
var Element.memoizeHash: String?
get() {
return getAttribute("memoize-hash")
@@ -185,7 +177,6 @@ abstract class Komponent {
var logRenderEvent = false
var logReplaceEvent = false
var enableAssertions = false
var updateMode = UpdateMode.UPDATE
var unsafeMode = UnsafeMode.UNSAFE_DISABLED
fun create(parent: HTMLElement, component: Komponent) {