Fix bug with ElementVisionRenderer having the same name

This commit is contained in:
Alexander Nozik 2024-03-14 09:04:54 +03:00
parent f0db286ce6
commit 1145483a90
9 changed files with 24 additions and 12 deletions

View File

@ -10,7 +10,7 @@ val dataforgeVersion by extra("0.8.0")
allprojects {
group = "space.kscience"
version = "0.4.0"
version = "0.4.1-dev-1"
}
subprojects {

View File

@ -23,6 +23,7 @@ kotlin {
dependencies {
api("app.softwork:bootstrap-compose:0.1.15")
api("app.softwork:bootstrap-compose-icons:0.1.15")
implementation(compose.html.svg)
api(compose.html.core)
}

View File

@ -36,6 +36,8 @@ public interface ElementVisionRenderer {
meta: Meta = Meta.EMPTY,
)
override fun toString(): String
public companion object {
public const val TYPE: String = "elementVisionRenderer"
public const val ZERO_RATING: Int = 0
@ -66,6 +68,8 @@ public class SingleTypeVisionRenderer<T : Vision>(
renderFunction(name, kClass.cast(vision), meta)
}
}
override fun toString(): String = "ElementVisionRender(${kClass.simpleName})"
}
public inline fun <reified T : Vision> ElementVisionRenderer(

View File

@ -41,16 +41,15 @@ private fun HTMLInputElement.subscribeToInput(inputVision: VisionOfHtmlInput) {
}
}
internal val htmlVisionRenderer: ElementVisionRenderer =
ElementVisionRenderer<VisionOfPlainHtml> { _, vision, _ ->
div().also { div ->
div.subscribeToVision(vision)
vision.useProperty(VisionOfPlainHtml::content) {
div.clear()
if (it != null) div.innerHTML = it
}
internal val htmlVisionRenderer: ElementVisionRenderer = ElementVisionRenderer<VisionOfPlainHtml> { _, vision, _ ->
div().also { div ->
div.subscribeToVision(vision)
vision.useProperty(VisionOfPlainHtml::content) {
div.clear()
if (it != null) div.innerHTML = it
}
}
}
internal val inputVisionRenderer: ElementVisionRenderer = ElementVisionRenderer<VisionOfHtmlInput>(
acceptRating = ElementVisionRenderer.DEFAULT_RATING - 1

View File

@ -31,7 +31,7 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
else -> ElementVisionRenderer.ZERO_RATING
}
override fun render(element: Element,name: Name, vision: Vision, meta: Meta) {
override fun render(element: Element, name: Name, vision: Vision, meta: Meta) {
require(vision is VisionOfMarkup) { "The vision is not a markup vision" }
val div = document.createElement("div")
val flavour = when (vision.format) {
@ -49,6 +49,8 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
element.append(div)
}
override fun toString(): String = "Markup"
override fun content(target: String): Map<Name, Any> = when (target) {
ElementVisionRenderer.TYPE -> mapOf("markup".asName() to this)
else -> super.content(target)

View File

@ -33,6 +33,8 @@ public actual class PlotlyPlugin : VisionPlugin(), ElementVisionRenderer {
element.plot(config, plot)
}
override fun toString(): String = "Plotly"
override fun content(target: String): Map<Name, Any> = when (target) {
ElementVisionRenderer.TYPE -> mapOf("plotly".asName() to this)
else -> super.content(target)

View File

@ -81,6 +81,8 @@ public class TableVisionJsPlugin : AbstractPlugin(), ElementVisionRenderer {
TabulatorFull(element as HTMLElement, tableOptions)
}
override fun toString(): String = "Table"
override fun content(target: String): Map<Name, Any> = when (target) {
ElementVisionRenderer.TYPE -> mapOf("table".asName() to this)
else -> super.content(target)

View File

@ -169,6 +169,8 @@ public class ThreePlugin : AbstractPlugin(), ComposeHtmlVisionRenderer {
override fun rateVision(vision: Vision): Int =
if (vision is Solid) ElementVisionRenderer.DEFAULT_RATING else ElementVisionRenderer.ZERO_RATING
override fun toString(): String = "ThreeJS"
/**
* Render the given [Solid] Vision in a [ThreeCanvas] attached
* to the [element]. Canvas objects are cached, so subsequent calls

View File

@ -32,8 +32,8 @@ kscience {
jsMain {
api(projects.visionforgeThreejs)
implementation(npm("file-saver", "2.0.5"))
implementation(npm("@types/file-saver", "2.0.7"))
api(npm("file-saver", "2.0.5"))
api(npm("@types/file-saver", "2.0.7"))
compileOnly(npm("webpack-bundle-analyzer", "4.5.0"))
}
}