aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/KVManager.kt5
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Component.kt20
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Style.kt78
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Widget.kt22
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt10
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt209
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelectInput.kt213
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt16
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt27
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt15
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt76
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/routing/Routing.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt10
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/StyleSpec.kt6
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt4
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/dropdown/HeaderSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/dropdown/SeparatorSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/FieldLabelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/HelpBlockSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/CheckBoxInputSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/CheckBoxSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/RadioGroupInputSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/RadioGroupSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/RadioInputSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/check/RadioSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/select/SimpleSelectInputSpec.kt51
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/select/SimpleSelectSpec.kt53
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/text/PasswordSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/text/TextAreaInputSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/text/TextAreaSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/text/TextInputSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/text/TextSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ButtonSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/CanvasSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/DivSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/FooterSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H1Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H2Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H3Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H4Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H5Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/H6Spec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/HeaderSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/IconSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/IframeSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ImageSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/LinkSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ListSpec.kt4
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/PSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/SectionSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/SpanSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt8
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/navbar/NavFormSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/navbar/NavSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/navbar/NavbarSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/RootSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/StackPanelSpec.kt8
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/TabPanelSpec.kt31
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/progress/ProgressBarSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/progress/ProgressIndicatorSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/table/CellSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/table/HeaderCellSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/toolbar/ButtonGroupSpec.kt2
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/toolbar/ToolbarSpec.kt2
82 files changed, 808 insertions, 192 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt b/src/main/kotlin/pl/treksoft/kvision/KVManager.kt
index faa0b77c..d1a4a8be 100644
--- a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/KVManager.kt
@@ -29,6 +29,7 @@ import com.github.snabbdom.datasetModule
import com.github.snabbdom.eventListenersModule
import com.github.snabbdom.propsModule
import com.github.snabbdom.styleModule
+import org.w3c.dom.HTMLElement
import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.utils.isIE11
import kotlin.browser.document
@@ -72,6 +73,10 @@ internal object KVManager {
return sdPatch(container, vnode)
}
+ internal fun patch(element: HTMLElement, vnode: VNode): VNode {
+ return sdPatch(element, vnode)
+ }
+
internal fun patch(oldVNode: VNode, newVNode: VNode): VNode {
return sdPatch(oldVNode, newVNode)
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt b/src/main/kotlin/pl/treksoft/kvision/core/Component.kt
index 411eae8d..fe5569d4 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Component.kt
@@ -97,6 +97,26 @@ interface Component {
fun removeSurroundingCssClass(css: Style): Component
/**
+ * Returns the value of an additional attribute.
+ * @param name the name of the attribute
+ * @return the value of the attribute
+ */
+ fun getAttribute(name: String): String?
+
+ /**
+ * Sets the value of additional attribute.
+ * @param name the name of the attribute
+ * @param value the value of the attribute
+ */
+ fun setAttribute(name: String, value: String): Component
+
+ /**
+ * Removes the value of additional attribute.
+ * @param name the name of the attribute
+ */
+ fun removeAttribute(name: String): Component
+
+ /**
* @suppress
* Internal function
* Renders current component as a Snabbdom vnode.
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
index 282d2e7e..ff91c429 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
@@ -21,11 +21,6 @@
*/
package pl.treksoft.kvision.core
-import com.github.snabbdom.VNode
-import com.github.snabbdom.h
-import org.w3c.dom.Node
-import pl.treksoft.jquery.JQuery
-import pl.treksoft.kvision.panel.Root
import kotlin.reflect.KProperty
/**
@@ -41,8 +36,6 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S
StyledComponent() {
private val propertyValues: MutableMap<String, Any?> = mutableMapOf()
- override var parent: Container? = Root.getFirstRoot()
-
private val newClassName: String = if (parentStyle == null) {
className ?: "kv_styleclass_${counter++}"
} else {
@@ -55,86 +48,19 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S
var className: String by refreshOnUpdate(newClassName)
init {
+ @Suppress("LeakingThis")
styles.add(this)
@Suppress("LeakingThis")
init?.invoke(this)
}
- override var visible: Boolean = true
- set(value) {
- val oldField = field
- field = value
- if (oldField != field) refresh()
- }
-
- override fun addCssClass(css: String): Component {
- return this
- }
-
- override fun removeCssClass(css: String): Component {
- return this
- }
-
- override fun addSurroundingCssClass(css: String): Component {
- return this
- }
-
- override fun removeSurroundingCssClass(css: String): Component {
- return this
- }
-
- override fun addCssClass(css: Style): Component {
- return this
- }
-
- override fun removeCssClass(css: Style): Component {
- return this
- }
-
- override fun addSurroundingCssClass(css: Style): Component {
- return this
- }
-
- override fun removeSurroundingCssClass(css: Style): Component {
- return this
- }
-
- override fun renderVNode(): VNode {
- return h("style", arrayOf(generateStyle()))
- }
-
internal fun generateStyle(): String {
- val styles = getSnStyle()
+ val styles = getSnStyleInternal()
return ".$className {\n" + styles.joinToString("\n") {
"${it.first}: ${it.second};"
} + "\n}"
}
- override fun getElement(): Node? {
- return null
- }
-
- override fun getElementJQuery(): JQuery? {
- return null
- }
-
- override fun getElementJQueryD(): dynamic {
- return null
- }
-
- override fun clearParent(): Component {
- this.parent = null
- return this
- }
-
- override fun getRoot(): Root? {
- return this.parent?.getRoot()
- }
-
- override fun dispose() {
- styles.remove(this)
- }
-
protected fun <T> refreshOnUpdate(refreshFunction: ((T) -> Unit) = { this.refresh() }) =
RefreshDelegateProvider<T>(null, refreshFunction)
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt b/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
index aa3f26bb..d9fa63fc 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
@@ -29,7 +29,7 @@ import kotlin.reflect.KProperty
* Base class for components supporting CSS styling.
*/
@Suppress("LargeClass")
-abstract class StyledComponent : Component {
+abstract class StyledComponent {
private val propertyValues: MutableMap<String, Any?> = mutableMapOf()
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
index 3388a011..fbcd89da 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
@@ -53,11 +53,12 @@ import kotlin.reflect.KProperty
* @param classes Set of CSS class names
*/
@Suppress("TooManyFunctions", "LargeClass")
-open class Widget(classes: Set<String> = setOf()) : StyledComponent() {
+open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component {
private val propertyValues: MutableMap<String, Any?> = mutableMapOf()
internal val classes = classes.toMutableSet()
internal val surroundingClasses: MutableSet<String> = mutableSetOf()
+ internal val attributes: MutableMap<String, String> = mutableMapOf()
internal val internalListeners = mutableListOf<SnOn<Widget>.() -> Unit>()
internal val listeners = mutableListOf<SnOn<Widget>.() -> Unit>()
@@ -243,6 +244,9 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() {
if (draggable == true) {
snattrs.add("draggable" to "true")
}
+ if (attributes.isNotEmpty()) {
+ snattrs += attributes.toList()
+ }
return snattrs
}
@@ -565,6 +569,22 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() {
return removeSurroundingCssClass(css.className)
}
+ override fun getAttribute(name: String): String? {
+ return this.attributes[name]
+ }
+
+ override fun setAttribute(name: String, value: String): Widget {
+ this.attributes[name] = value
+ refresh()
+ return this
+ }
+
+ override fun removeAttribute(name: String): Widget {
+ this.attributes.remove(name)
+ refresh()
+ return this
+ }
+
override fun getElement(): Node? {
return this.vnode?.elm
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt
index 57ce88eb..3019fb6f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt
@@ -47,6 +47,16 @@ interface FormInput : Component {
* The name attribute of the generated HTML input element.
*/
var name: String?
+
+ /**
+ * Makes the input element focused.
+ */
+ fun focus()
+
+ /**
+ * Makes the input element blur.
+ */
+ fun blur()
}
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
index 6973efe9..07b86b4c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
@@ -152,14 +152,14 @@ abstract class CheckInput(
/**
* Makes the input element focused.
*/
- open fun focus() {
+ override fun focus() {
getElementJQuery()?.focus()
}
/**
* Makes the input element blur.
*/
- open fun blur() {
+ override fun blur() {
getElementJQuery()?.blur()
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt
index 98839982..fca681f6 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt
@@ -150,11 +150,11 @@ open class RadioGroupInput(
}
}
- fun focus() {
+ override fun focus() {
getChildren().filterIsInstance<Radio>().firstOrNull()?.focus()
}
- fun blur() {
+ override fun blur() {
getChildren().filterIsInstance<Radio>().firstOrNull()?.blur()
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt
new file mode 100644
index 00000000..4d278ad2
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.form.select
+
+import pl.treksoft.kvision.core.Component
+import pl.treksoft.kvision.core.Container
+import pl.treksoft.kvision.core.StringBoolPair
+import pl.treksoft.kvision.core.StringPair
+import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.form.FieldLabel
+import pl.treksoft.kvision.form.HelpBlock
+import pl.treksoft.kvision.form.StringFormControl
+import pl.treksoft.kvision.panel.Simple