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 { allprojects {
group = "space.kscience" group = "space.kscience"
version = "0.4.0" version = "0.4.1-dev-1"
} }
subprojects { subprojects {

View File

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

View File

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

View File

@ -41,8 +41,7 @@ private fun HTMLInputElement.subscribeToInput(inputVision: VisionOfHtmlInput) {
} }
} }
internal val htmlVisionRenderer: ElementVisionRenderer = internal val htmlVisionRenderer: ElementVisionRenderer = ElementVisionRenderer<VisionOfPlainHtml> { _, vision, _ ->
ElementVisionRenderer<VisionOfPlainHtml> { _, vision, _ ->
div().also { div -> div().also { div ->
div.subscribeToVision(vision) div.subscribeToVision(vision)
vision.useProperty(VisionOfPlainHtml::content) { vision.useProperty(VisionOfPlainHtml::content) {

View File

@ -49,6 +49,8 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
element.append(div) element.append(div)
} }
override fun toString(): String = "Markup"
override fun content(target: String): Map<Name, Any> = when (target) { override fun content(target: String): Map<Name, Any> = when (target) {
ElementVisionRenderer.TYPE -> mapOf("markup".asName() to this) ElementVisionRenderer.TYPE -> mapOf("markup".asName() to this)
else -> super.content(target) else -> super.content(target)

View File

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

View File

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

View File

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

View File

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