Fixes
This commit is contained in:
@@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "nl.astraeus"
|
group = "nl.astraeus"
|
||||||
version = "1.0.6"
|
version = "1.0.7-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -127,9 +127,7 @@ internal fun Element.setKompEvent(name: String, event: (Event) -> Unit) {
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Komponent.updateMode.isUpdate) {
|
|
||||||
getKompEvents()[eventName] = event
|
getKompEvents()[eventName] = event
|
||||||
}
|
|
||||||
|
|
||||||
this.addEventListener(eventName, event)
|
this.addEventListener(eventName, event)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
@file:OptIn(ExperimentalStdlibApi::class)
|
|
||||||
|
|
||||||
package nl.astraeus.komp
|
package nl.astraeus.komp
|
||||||
|
|
||||||
import kotlinx.browser.document
|
import kotlinx.browser.document
|
||||||
@@ -157,14 +155,11 @@ class HtmlBuilder(
|
|||||||
//logReplace"onTagStart, currentElement1.1: $currentNode")
|
//logReplace"onTagStart, currentElement1.1: $currentNode")
|
||||||
currentPosition.currentParent().appendChild(currentNode!!)
|
currentPosition.currentParent().appendChild(currentNode!!)
|
||||||
} else if (
|
} else if (
|
||||||
Komponent.updateMode.isReplace ||
|
|
||||||
(
|
|
||||||
!currentNode?.asElement()?.tagName.equals(tag.tagName, true) ||
|
!currentNode?.asElement()?.tagName.equals(tag.tagName, true) ||
|
||||||
(
|
(
|
||||||
tag.namespace != null &&
|
tag.namespace != null &&
|
||||||
!currentNode?.asElement()?.namespaceURI.equals(tag.namespace, true)
|
!currentNode?.asElement()?.namespaceURI.equals(tag.namespace, true)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
logReplace { "onTagStart, currentElement, namespace: ${currentNode?.asElement()?.namespaceURI} -> ${tag.namespace}" }
|
logReplace { "onTagStart, currentElement, namespace: ${currentNode?.asElement()?.namespaceURI} -> ${tag.namespace}" }
|
||||||
logReplace { "onTagStart, currentElement, replace: ${currentNode?.asElement()?.tagName} -> ${tag.tagName}" }
|
logReplace { "onTagStart, currentElement, replace: ${currentNode?.asElement()?.tagName} -> ${tag.tagName}" }
|
||||||
@@ -186,22 +181,16 @@ class HtmlBuilder(
|
|||||||
root = currentNode as Element
|
root = currentNode as Element
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Komponent.updateMode.isUpdate) {
|
|
||||||
currentElement?.clearKompEvents()
|
currentElement?.clearKompEvents()
|
||||||
(currentElement as? HTMLInputElement)?.checked = false
|
(currentElement as? HTMLInputElement)?.checked = false
|
||||||
}
|
|
||||||
|
|
||||||
currentPosition.lastOrNull()?.setAttr?.clear()
|
currentPosition.lastOrNull()?.setAttr?.clear()
|
||||||
|
|
||||||
|
// if currentElement = checkbox make sure it's cleared
|
||||||
for (entry in tag.attributesEntries) {
|
for (entry in tag.attributesEntries) {
|
||||||
currentElement!!.setKompAttribute(entry.key, entry.value)
|
currentElement!!.setKompAttribute(entry.key, entry.value)
|
||||||
currentPosition.lastOrNull()?.setAttr?.add(entry.key)
|
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!!)
|
currentPosition.push(currentNode!!)
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import org.w3c.dom.Element
|
|||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
import org.w3c.dom.get
|
import org.w3c.dom.get
|
||||||
|
|
||||||
private val currentKomponents: MutableList<Komponent> = mutableListOf()
|
private var currentKomponent: Komponent? = null
|
||||||
|
|
||||||
fun FlowOrMetaDataOrPhrasingContent.currentKomponent(): Komponent =
|
fun FlowOrMetaDataOrPhrasingContent.currentKomponent(): Komponent =
|
||||||
currentKomponents.lastOrNull() ?: error("No current komponent defined! Only call from render code!")
|
currentKomponent ?: error("No current komponent defined! Only call from render code!")
|
||||||
|
|
||||||
enum class UnsafeMode {
|
enum class UnsafeMode {
|
||||||
UNSAFE_ALLOWED,
|
UNSAFE_ALLOWED,
|
||||||
@@ -16,15 +17,6 @@ enum class UnsafeMode {
|
|||||||
UNSAFE_SVG_ONLY
|
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?
|
var Element.memoizeHash: String?
|
||||||
get() {
|
get() {
|
||||||
return getAttribute("memoize-hash")
|
return getAttribute("memoize-hash")
|
||||||
@@ -52,12 +44,12 @@ abstract class Komponent {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
currentKomponents.add(this)
|
currentKomponent = this
|
||||||
builder.render()
|
builder.render()
|
||||||
} catch(e: KomponentException) {
|
} catch(e: KomponentException) {
|
||||||
errorHandler(e)
|
errorHandler(e)
|
||||||
} finally {
|
} finally {
|
||||||
currentKomponents.removeLast()
|
currentKomponent = null
|
||||||
}
|
}
|
||||||
|
|
||||||
element = builder.root
|
element = builder.root
|
||||||
@@ -148,12 +140,12 @@ abstract class Komponent {
|
|||||||
val builder = HtmlBuilder(this, parent, childIndex)
|
val builder = HtmlBuilder(this, parent, childIndex)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
currentKomponents.add(this)
|
currentKomponent = this
|
||||||
builder.render()
|
builder.render()
|
||||||
} catch(e: KomponentException) {
|
} catch(e: KomponentException) {
|
||||||
errorHandler(e)
|
errorHandler(e)
|
||||||
} finally {
|
} finally {
|
||||||
currentKomponents.removeLast()
|
currentKomponent = null
|
||||||
}
|
}
|
||||||
|
|
||||||
element = builder.root
|
element = builder.root
|
||||||
@@ -185,7 +177,6 @@ abstract class Komponent {
|
|||||||
var logRenderEvent = false
|
var logRenderEvent = false
|
||||||
var logReplaceEvent = false
|
var logReplaceEvent = false
|
||||||
var enableAssertions = false
|
var enableAssertions = false
|
||||||
var updateMode = UpdateMode.UPDATE
|
|
||||||
var unsafeMode = UnsafeMode.UNSAFE_DISABLED
|
var unsafeMode = UnsafeMode.UNSAFE_DISABLED
|
||||||
|
|
||||||
fun create(parent: HTMLElement, component: Komponent) {
|
fun create(parent: HTMLElement, component: Komponent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user