Skip to content

Commit

Permalink
add builders for html field
Browse files Browse the repository at this point in the history
  • Loading branch information
altavir committed Dec 3, 2023
1 parent c877fcb commit fbb402d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ public inline fun VisionOfPlainHtml.content(block: TagConsumer<*>.() -> Unit) {
content = createHTML().apply(block).finalize()
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.html(
block: VisionOfPlainHtml.() -> Unit,
): VisionOfPlainHtml = VisionOfPlainHtml().apply(block)

@Serializable
public enum class InputFeedbackMode{
public enum class InputFeedbackMode {
/**
* Fire feedback event on `onchange` event
*/
Expand All @@ -47,32 +52,53 @@ public enum class InputFeedbackMode{
@SerialName("html.input")
public open class VisionOfHtmlInput(
public val inputType: String,
public val feedbackMode: InputFeedbackMode = InputFeedbackMode.ONCHANGE
public val feedbackMode: InputFeedbackMode = InputFeedbackMode.ONCHANGE,
) : VisionOfHtml() {
public var value: Value? by properties.value()
public var disabled: Boolean by properties.boolean { false }
public var fieldName: String? by properties.string()
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.htmlInput(
inputType: String,
block: VisionOfHtmlInput.() -> Unit = {},
): VisionOfHtmlInput = VisionOfHtmlInput(inputType).apply(block)

@Serializable
@SerialName("html.text")
public class VisionOfTextField : VisionOfHtmlInput(InputType.text.realValue) {
public var text: String? by properties.string(key = VisionOfHtmlInput::value.name.asName())
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.htmlTextField(
block: VisionOfTextField.() -> Unit = {},
): VisionOfTextField = VisionOfTextField().apply(block)


@Serializable
@SerialName("html.checkbox")
public class VisionOfCheckbox : VisionOfHtmlInput(InputType.checkBox.realValue) {
public var checked: Boolean? by properties.boolean(key = VisionOfHtmlInput::value.name.asName())
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.htmlCheckBox(
block: VisionOfCheckbox.() -> Unit = {},
): VisionOfCheckbox = VisionOfCheckbox().apply(block)

@Serializable
@SerialName("html.number")
public class VisionOfNumberField : VisionOfHtmlInput(InputType.number.realValue) {
public var number: Number? by properties.number(key = VisionOfHtmlInput::value.name.asName())
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.htmlNumberField(
block: VisionOfNumberField.() -> Unit = {},
): VisionOfNumberField = VisionOfNumberField().apply(block)

@Serializable
@SerialName("html.range")
public class VisionOfRangeField(
Expand All @@ -83,3 +109,11 @@ public class VisionOfRangeField(
public var number: Number? by properties.number(key = VisionOfHtmlInput::value.name.asName())
}

@Suppress("UnusedReceiverParameter")
public inline fun VisionOutput.htmlRangeField(
min: Double,
max: Double,
step: Double = 1.0,
block: VisionOfRangeField.() -> Unit = {},
): VisionOfRangeField = VisionOfRangeField(min, max, step).apply(block)

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package space.kscience.visionforge.meta

import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.take
Expand All @@ -24,7 +23,6 @@ private class TestScheme : Scheme() {
companion object : SchemeSpec<TestScheme>(::TestScheme)
}

@OptIn(ExperimentalCoroutinesApi::class)
internal class VisionPropertyTest {

private val manager = Global.request(VisionManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal fun FormData.toMeta(): Meta {
}

internal val formVisionRenderer: ElementVisionRenderer =
ElementVisionRenderer<VisionOfHtmlForm> { visionName, vision, _ ->
ElementVisionRenderer<VisionOfHtmlForm> { _, vision, _ ->

val form = document.getElementById(vision.formId) as? HTMLFormElement
?: error("An element with id = '${vision.formId} is not a form")
Expand Down

0 comments on commit fbb402d

Please sign in to comment.