From 0c647a465b708829166010218fe0ae61f01de934 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 22 Jun 2019 20:18:56 +0200 Subject: An advanced option to strictly bind a component to the DOM element. --- src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index fbcd89da..414356ce 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -86,6 +86,10 @@ open class Widget(classes: Set = setOf()) : StyledComponent(), Component * Determines if the current widget is draggable. */ var draggable: Boolean? by refreshOnUpdate() + /** + * Determines if the current widget is strictly bound to the DOM. + */ + var strictDOM: Boolean by refreshOnUpdate(false) protected var surroundingSpan by refreshOnUpdate(false) @@ -184,7 +188,11 @@ open class Widget(classes: Set = setOf()) : StyledComponent(), Component */ private fun getSnOpt(): VNodeData { return snOpt { - if (vnkey != null) key = vnkey + if (vnkey != null) { + key = vnkey + } else if (strictDOM) { + key = hashCode().toString() + } attrs = snAttrs(getSnAttrsInternal()) style = snStyle(getSnStyleInternal()) `class` = snClasses(getSnClassInternal()) -- cgit From 1fb687a051d37d6d13bfdcc8f84e6cf1165cadc7 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 23 Jun 2019 02:18:06 +0200 Subject: Fixed positioning of the context menu for use inside a Tabulator component. --- .../kotlin/pl/treksoft/kvision/tabulator/Options.kt | 2 ++ .../kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt index f5f58010..a6f9c740 100644 --- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt +++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt @@ -369,6 +369,7 @@ fun ColumnDefinition.toJs( { cell: Tabulator.CellComponent, onRendered: (callback: () -> Unit) -> Unit, success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, _: dynamic -> + cell.getElement().style.asDynamic().overflow = "visible" var onRenderedCallback: (() -> Unit)? = null @Suppress("UNCHECKED_CAST") val data = cell.getData() as T val component = it(cell, { callback -> @@ -404,6 +405,7 @@ fun ColumnDefinition.toJs( val tmpFormatterFunction = formatterComponentFunction?.let { { cell: Tabulator.CellComponent, _: dynamic, onRendered: (callback: () -> Unit) -> Unit -> + cell.getElement().style.asDynamic().overflow = "visible" var onRenderedCallback: (() -> Unit)? = null @Suppress("UNCHECKED_CAST") val data = cell.getData() as T val component = it(cell, { callback -> diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt index f376de5a..c09737f2 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt @@ -33,9 +33,13 @@ import pl.treksoft.kvision.utils.px * Context menu component. * * @constructor + * @param element an element to bind + * @param fixedPosition use fixed positioning * @param classes a set of CSS class names */ open class ContextMenu( + element: Widget? = null, + protected val fixedPosition: Boolean = false, classes: Set = setOf(), init: (ContextMenu.() -> Unit)? = null ) : ListTag(ListType.UL, classes = classes + "dropdown-menu") { @@ -44,7 +48,7 @@ open class ContextMenu( hide() @Suppress("LeakingThis") display = Display.BLOCK - val root = Root.getLastRoot() + val root = element?.getRoot() ?: Root.getLastRoot() if (root != null) { @Suppress("LeakingThis") root.addContextMenu(this) @@ -61,8 +65,13 @@ open class ContextMenu( * @return current context menu */ open fun positionMenu(mouseEvent: MouseEvent): ContextMenu { - this.top = mouseEvent.pageY.toInt().px - this.left = mouseEvent.pageX.toInt().px + if (fixedPosition) { + this.top = 5.px + this.left = 5.px + } else { + this.top = mouseEvent.pageY.toInt().px + this.left = mouseEvent.pageX.toInt().px + } this.show() return this } @@ -74,9 +83,10 @@ open class ContextMenu( * It takes the same parameters as the constructor of the built component. */ fun Widget.contextMenu( + fixedPosition: Boolean = false, classes: Set = setOf(), init: (ContextMenu.() -> Unit)? = null ): ContextMenu { - val contextMenu = ContextMenu(classes).apply { init?.invoke(this) } + val contextMenu = ContextMenu(this, fixedPosition, classes).apply { init?.invoke(this) } this.setContextMenu(contextMenu) return contextMenu } -- cgit From e342615c0e9b126cce1b0e81129a8d3b5967a2ce Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 23 Jun 2019 12:53:29 +0200 Subject: Style fix. --- src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt index c09737f2..5fac0494 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt @@ -66,8 +66,8 @@ open class ContextMenu( */ open fun positionMenu(mouseEvent: MouseEvent): ContextMenu { if (fixedPosition) { - this.top = 5.px - this.left = 5.px + this.top = DEFAULT_FIXED_POS_Y.px + this.left = DEFAULT_FIXED_POS_X.px } else { this.top = mouseEvent.pageY.toInt().px this.left = mouseEvent.pageX.toInt().px @@ -77,6 +77,10 @@ open class ContextMenu( } companion object { + + const val DEFAULT_FIXED_POS_X = 5 + const val DEFAULT_FIXED_POS_Y = 5 + /** * DSL builder extension function. * -- cgit