From 107481f9ad5783daed68de8dadea65be57a6266b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 1 Mar 2018 14:21:24 +0100 Subject: Site initial commit --- src/main/kotlin/pl/treksoft/kvision/KVManager.kt | 157 ------ .../kotlin/pl/treksoft/kvision/core/Component.kt | 116 ---- .../kotlin/pl/treksoft/kvision/core/Container.kt | 69 --- src/main/kotlin/pl/treksoft/kvision/core/Css.kt | 455 ---------------- .../pl/treksoft/kvision/core/StyledComponent.kt | 349 ------------ src/main/kotlin/pl/treksoft/kvision/core/Types.kt | 44 -- src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 585 --------------------- .../pl/treksoft/kvision/core/WidgetWrapper.kt | 74 --- .../pl/treksoft/kvision/data/DataComponent.kt | 54 -- .../pl/treksoft/kvision/data/DataContainer.kt | 144 ----- .../pl/treksoft/kvision/data/DataUpdatable.kt | 29 - .../pl/treksoft/kvision/dropdown/DropDown.kt | 276 ---------- .../kotlin/pl/treksoft/kvision/form/FieldLabel.kt | 49 -- src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 212 -------- .../kotlin/pl/treksoft/kvision/form/FormControl.kt | 163 ------ .../kotlin/pl/treksoft/kvision/form/FormPanel.kt | 234 --------- .../kotlin/pl/treksoft/kvision/form/HelpBlock.kt | 37 -- .../pl/treksoft/kvision/form/check/CheckBox.kt | 207 -------- .../pl/treksoft/kvision/form/check/CheckInput.kt | 170 ------ .../kotlin/pl/treksoft/kvision/form/check/Radio.kt | 227 -------- .../pl/treksoft/kvision/form/check/RadioGroup.kt | 171 ------ .../pl/treksoft/kvision/form/select/AjaxOptions.kt | 125 ----- .../pl/treksoft/kvision/form/select/Select.kt | 291 ---------- .../pl/treksoft/kvision/form/select/SelectInput.kt | 349 ------------ .../treksoft/kvision/form/select/SelectOptGroup.kt | 91 ---- .../treksoft/kvision/form/select/SelectOption.kt | 103 ---- .../pl/treksoft/kvision/form/spinner/Spinner.kt | 262 --------- .../treksoft/kvision/form/spinner/SpinnerInput.kt | 307 ----------- .../pl/treksoft/kvision/form/text/AbstractText.kt | 183 ------- .../kvision/form/text/AbstractTextInput.kt | 172 ------ .../pl/treksoft/kvision/form/text/Password.kt | 52 -- .../pl/treksoft/kvision/form/text/RichText.kt | 71 --- .../pl/treksoft/kvision/form/text/RichTextInput.kt | 127 ----- .../kotlin/pl/treksoft/kvision/form/text/Text.kt | 81 --- .../pl/treksoft/kvision/form/text/TextArea.kt | 90 ---- .../pl/treksoft/kvision/form/text/TextAreaInput.kt | 88 ---- .../pl/treksoft/kvision/form/text/TextInput.kt | 96 ---- .../pl/treksoft/kvision/form/time/DateTime.kt | 252 --------- .../pl/treksoft/kvision/form/time/DateTimeInput.kt | 272 ---------- .../pl/treksoft/kvision/hmr/ApplicationBase.kt | 41 -- src/main/kotlin/pl/treksoft/kvision/hmr/HMR.kt | 47 -- src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 150 ------ src/main/kotlin/pl/treksoft/kvision/html/Div.kt | 65 --- src/main/kotlin/pl/treksoft/kvision/html/Image.kt | 118 ----- src/main/kotlin/pl/treksoft/kvision/html/Label.kt | 48 -- src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 85 --- src/main/kotlin/pl/treksoft/kvision/html/List.kt | 150 ------ src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 155 ------ src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt | 121 ----- .../kotlin/pl/treksoft/kvision/modal/CloseIcon.kt | 48 -- .../kotlin/pl/treksoft/kvision/modal/Confirm.kt | 143 ----- src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt | 282 ---------- .../kotlin/pl/treksoft/kvision/panel/DockPanel.kt | 202 ------- .../kotlin/pl/treksoft/kvision/panel/FlexPanel.kt | 269 ---------- .../kotlin/pl/treksoft/kvision/panel/GridPanel.kt | 316 ----------- .../kotlin/pl/treksoft/kvision/panel/HPanel.kt | 70 --- .../treksoft/kvision/panel/ResponsiveGridPanel.kt | 185 ------- src/main/kotlin/pl/treksoft/kvision/panel/Root.kt | 96 ---- .../pl/treksoft/kvision/panel/SimplePanel.kt | 116 ---- .../kotlin/pl/treksoft/kvision/panel/SplitPanel.kt | 137 ----- .../kotlin/pl/treksoft/kvision/panel/StackPanel.kt | 115 ---- .../kotlin/pl/treksoft/kvision/panel/TabPanel.kt | 152 ------ .../kotlin/pl/treksoft/kvision/panel/VPanel.kt | 65 --- .../kotlin/pl/treksoft/kvision/routing/Routing.kt | 51 -- src/main/kotlin/pl/treksoft/kvision/utils/Keys.kt | 31 -- .../kotlin/pl/treksoft/kvision/utils/Snabbdom.kt | 163 ------ src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt | 201 ------- .../kotlin/pl/treksoft/kvision/window/Window.kt | 312 ----------- src/main/resources/css/style.css | 133 ----- src/main/resources/img/placeholder.png | 0 src/main/resources/js/bootstrap-select-i18n.min.js | 1 - src/main/resources/js/bootstrap.config.js | 64 --- src/main/resources/js/bootstrap.config.less | 0 src/main/web/index.html | 40 -- 74 files changed, 11006 deletions(-) delete mode 100644 src/main/kotlin/pl/treksoft/kvision/KVManager.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Component.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Container.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Css.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Types.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Widget.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataComponent.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataUpdatable.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/FieldLabel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/Form.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/HelpBlock.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/select/AjaxOptions.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/hmr/ApplicationBase.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/hmr/HMR.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Button.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Div.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Image.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Label.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Link.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/List.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Tag.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/modal/CloseIcon.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/Root.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/routing/Routing.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/utils/Keys.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/window/Window.kt delete mode 100644 src/main/resources/css/style.css delete mode 100644 src/main/resources/img/placeholder.png delete mode 100644 src/main/resources/js/bootstrap-select-i18n.min.js delete mode 100644 src/main/resources/js/bootstrap.config.js delete mode 100644 src/main/resources/js/bootstrap.config.less delete mode 100644 src/main/web/index.html (limited to 'src/main') diff --git a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt b/src/main/kotlin/pl/treksoft/kvision/KVManager.kt deleted file mode 100644 index 0030cf9d..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/KVManager.kt +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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 - -import com.github.snabbdom.Snabbdom -import com.github.snabbdom.VNode -import com.github.snabbdom.attributesModule -import com.github.snabbdom.classModule -import com.github.snabbdom.datasetModule -import com.github.snabbdom.eventListenersModule -import com.github.snabbdom.propsModule -import com.github.snabbdom.styleModule -import pl.treksoft.kvision.core.Component -import pl.treksoft.kvision.utils.isIE11 -import kotlin.browser.document -import kotlin.dom.clear - -/** - * @suppress - * External function for loading CommonJS modules. - */ -external fun require(name: String): dynamic - -/** - * Internal singleton object which initializes and configures KVision framework. - */ -@Suppress("EmptyCatchBlock") -internal object KVManager { - internal const val AJAX_REQUEST_DELAY = 300 - internal const val KVNULL = "#kvnull" - - private val bootstrapWebpack = try { - require("bootstrap-webpack") - } catch (e: Throwable) { - } - private val fontAwesomeWebpack = try { - require("font-awesome-webpack") - } catch (e: Throwable) { - } - private val awesomeBootstrapCheckbox = try { - require("awesome-bootstrap-checkbox") - } catch (e: Throwable) { - } - private val bootstrapSelectCss = try { - require("bootstrap-select/dist/css/bootstrap-select.min.css") - } catch (e: Throwable) { - } - private val bootstrapSelect = try { - require("bootstrap-select/dist/js/bootstrap-select.min.js") - } catch (e: Throwable) { - } - private val bootstrapSelectI18n = try { - require("./js/bootstrap-select-i18n.min.js") - } catch (e: Throwable) { - } - private val bootstrapSelectAjaxCss = try { - require("ajax-bootstrap-select/dist/css/ajax-bootstrap-select.min.css") - } catch (e: Throwable) { - } - private val bootstrapSelectAjax = try { - require("ajax-bootstrap-select/dist/js/ajax-bootstrap-select.min.js") - } catch (e: Throwable) { - } - private val trixCss = try { - require("trix/dist/trix.css") - } catch (e: Throwable) { - } - private val trix = try { - require("trix") - } catch (e: Throwable) { - } - private val bootstrapDateTimePickerCss = try { - require("bootstrap-datetime-picker/css/bootstrap-datetimepicker.min.css") - } catch (e: Throwable) { - } - private val bootstrapDateTimePicker = try { - require("bootstrap-datetime-picker/js/bootstrap-datetimepicker.min.js") - } catch (e: Throwable) { - } - private val bootstrapTouchspinCss = try { - require("bootstrap-touchspin/dist/jquery.bootstrap-touchspin.min.css") - } catch (e: Throwable) { - } - private val bootstrapTouchspin = try { - require("bootstrap-touchspin/dist/jquery.bootstrap-touchspin.min.js") - } catch (e: Throwable) { - } - private val elementResizeEvent = try { - require("element-resize-event") - } catch (e: Throwable) { - } - - private val resizable = require("jquery-resizable-dom") - internal val fecha = require("fecha") - private val sdPatch = Snabbdom.init( - arrayOf( - classModule, attributesModule, propsModule, styleModule, - eventListenersModule, datasetModule - ) - ) - private val sdVirtualize = require("snabbdom-virtualize/strings").default - private val styleCss = require("./css/style.css") - - internal fun patch(id: String, vnode: VNode): VNode { - val container = document.getElementById(id) - container?.clear() - return sdPatch(container, vnode) - } - - internal fun patch(oldVNode: VNode, newVNode: VNode): VNode { - return sdPatch(oldVNode, newVNode) - } - - @Suppress("UnsafeCastFromDynamic") - internal fun virtualize(html: String): VNode { - return sdVirtualize(html) - } - - @Suppress("UnsafeCastFromDynamic") - internal fun setResizeEvent(component: Component, callback: () -> Unit) { - if (!isIE11()) { - component.getElement()?.let { - elementResizeEvent(it, callback) - } - } - } - - @Suppress("UnsafeCastFromDynamic") - internal fun clearResizeEvent(component: Component) { - if (!isIE11()) { - if (component.getElement()?.asDynamic()?.__resizeTrigger__?.contentDocument != null) { - component.getElement()?.let { - elementResizeEvent.unbind(it) - } - } - } - } -} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt b/src/main/kotlin/pl/treksoft/kvision/core/Component.kt deleted file mode 100644 index 7125536a..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.core - -import com.github.snabbdom.VNode -import org.w3c.dom.Node -import pl.treksoft.jquery.JQuery -import pl.treksoft.kvision.panel.Root - -/** - * Base interface for all components. - */ -interface Component { - /** - * Parent of the current component. - */ - var parent: Component? - /** - * Visibility state of the current component. - */ - var visible: Boolean - - /** - * Adds given value to the set of CSS classes generated in html code of current component. - * @param css CSS class name - * @return current component - */ - fun addCssClass(css: String): Component - - /** - * Removes given value from the set of CSS classes generated in html code of current component. - * @param css CSS class name - * @return current component - */ - fun removeCssClass(css: String): Component - - /** - * Adds given value to the set of CSS classes generated in html code of parent component. - * @param css CSS class name - * @return current component - */ - fun addSurroundingCssClass(css: String): Component - - /** - * Removes given value from the set of CSS classes generated in html code of parent component. - * @param css CSS class name - * @return current component - */ - fun removeSurroundingCssClass(css: String): Component - - /** - * @suppress - * Internal function - * Renders current component as a Snabbdom vnode. - * @return Snabbdom vnode - */ - fun renderVNode(): VNode - - /** - * Returns DOM element bound to the current component. - * @return DOM element - */ - fun getElement(): Node? - - /** - * Returns JQuery element bound to the current component. - * @return JQuery element - */ - fun getElementJQuery(): JQuery? - - /** - * Returns JQuery element bound to the current component as a *dynamic* type. - * @return JQuery element as a *dynamic* type - */ - fun getElementJQueryD(): dynamic - - /** - * @suppress - * Internal function. - * Sets **parent** property of current component to null. - * @return current component - */ - fun clearParent(): Component - /** - * @suppress - * Internal function. - * Returns root component - the root node of components tree - * @return root component - */ - fun getRoot(): Root? - /** - * @suppress - * Internal function - * Cleans resources allocated by the current component. - */ - fun dispose() -} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Container.kt b/src/main/kotlin/pl/treksoft/kvision/core/Container.kt deleted file mode 100644 index 653f4a79..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/Container.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.core - -/** - * Base interface for all containers. - */ -interface Container : Component { - /** - * Adds given component to the current container. - * @param child child component - * @return current container - */ - fun add(child: Component): Container - - /** - * Adds a list of components to the current container. - * @param children list of child components - * @return current container - */ - fun addAll(children: List): Container - - /** - * Operator function for adding children in a DSL style. - * @param children children components - * @return current container - */ - operator fun invoke(vararg children: Component): Container { - return addAll(children.asList()) - } - - /** - * Removes given component from the current container. - * @param child child component - * @return current container - */ - fun remove(child: Component): Container - - /** - * Removes all children from the current container. - * @return current container - */ - fun removeAll(): Container - - /** - * Returns a list of children of the current container. - * @return list of children - */ - fun getChildren(): List -} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt b/src/main/kotlin/pl/treksoft/kvision/core/Css.kt deleted file mode 100644 index ff01cc9f..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt +++ /dev/null @@ -1,455 +0,0 @@ -/* - * 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.core - -import pl.treksoft.kvision.utils.asString -import pl.treksoft.kvision.utils.toHexString - -/** - * Definitions of CSS units. - */ -@Suppress("EnumNaming", "EnumEntryName") -enum class UNIT(internal val unit: String) { - px("px"), - pt("pt"), - em("em"), - cm("cm"), - mm("mm"), - `in`("in"), - pc("pc"), - ch("ch"), - rem("rem"), - vw("vw"), - vh("vh"), - vmin("vmin"), - vmax("vmax"), - perc("%"), - auto("auto") -} - -/** - * Definitions of CSS border styles. - */ -enum class BorderStyle(internal val borderStyle: String) { - NONE("none"), - HIDDEN("hidden"), - DOTTED("dotted"), - DASHED("dashed"), - SOLID("solid"), - DOUBLE("double"), - GROOVE("groove"), - RIDGE("ridge"), - INSET("inset"), - OUTSET("outset"), - INITIAL("initial"), - INHERIT("inherit") -} - -/** - * Definitions of CSS color names. - */ -enum class Col(internal val color: String) { - ALICEBLUE("aliceblue"), - ANTIQUEWHITE("antiquewhite"), - AQUA("aqua"), - AQUAMARINE("aquamarine"), - AZURE("azure"), - BEIGE("beige"), - BISQUE("bisque"), - BLACK("black"), - BLANCHEDALMOND("blanchedalmond"), - BLUE("blue"), - BLUEVIOLET("blueviolet"), - BROWN("brown"), - BURLYWOOD("burlywood"), - CADETBLUE("cadetblue"), - CHARTREUSE("chartreuse"), - CHOCOLATE("chocolate"), - CORAL("coral"), - CORNFLOWERBLUE("cornflowerblue"), - CORNSILK("cornsilk"), - CRIMSON("crimson"), - CYAN("cyan"), - DARKBLUE("darkblue"), - DARKCYAN("darkcyan"), - DARKGOLDENROD("darkgoldenrod"), - DARKGRAY("darkgray"), - DARKGREEN("darkgreen"), - DARKKHAKI("darkkhaki"), - DARKMAGENTA("darkmagenta"), - DARKOLIVEGREEN("darkolivegreen"), - DARKORANGE("darkorange"), - DARKORCHID("darkorchid"), - DARKRED("darkred"), - DARKSALMON("darksalmon"), - DARKSEAGREEN("darkseagreen"), - DARKSLATEBLUE("darkslateblue"), - DARKSLATEGRAY("darkslategray"), - DARKTURQUOISE("darkturquoise"), - DARKVIOLET("darkviolet"), - DEEPPINK("deeppink"), - DEEPSKYBLUE("deepskyblue"), - DIMGRAY("dimgray"), - DODGERBLUE("dodgerblue"), - FIREBRICK("firebrick"), - FLORALWHITE("floralwhite"), - FORESTGREEN("forestgreen"), - FUCHSIA("fuchsia"), - GAINSBORO("gainsboro"), - GHOSTWHITE("ghostwhite"), - GOLD("gold"), - GOLDENROD("goldenrod"), - GRAY("gray"), - GREEN("green"), - GREENYELLOW("greenyellow"), - HONEYDEW("honeydew"), - HOTPINK("hotpink"), - INDIANRED("indianred"), - INDIGO("indigo"), - IVORY("ivory"), - KHAKI("khaki"), - LAVENDER("lavender"), - LAVENDERBLUSH("lavenderblush"), - LAWNGREEN("lawngreen"), - LEMONCHIFFON("lemonchiffon"), - LIGHTBLUE("lightblue"), - LIGHTCORAL("lightcoral"), - LIGHTCYAN("lightcyan"), - LIGHTGOLDENRODYELLOW("lightgoldenrodyellow"), - LIGHTGRAY("lightgray"), - LIGHTGREEN("lightgreen"), - LIGHTPINK("lightpink"), - LIGHTSALMON("lightsalmon"), - LIGHTSEAGREEN("lightseagreen"), - LIGHTSKYBLUE("lightskyblue"), - LIGHTSLATEGRAY("lightslategray"), - LIGHTSTEELBLUE("lightsteelblue"), - LIGHTYELLOW("lightyellow"), - LIME("lime"), - LIMEGREEN("limegreen"), - LINEN("linen"), - MAGENTA("magenta"), - MAROON("maroon"), - MEDIUMAQUAMARINE("mediumaquamarine"), - MEDIUMBLUE("mediumblue"), - MEDIUMORCHID("mediumorchid"), - MEDIUMPURPLE("mediumpurple"), - MEDIUMSEAGREEN("mediumseagreen"), - MEDIUMSLATEBLUE("mediumslateblue"), - MEDIUMSPRINGGREEN("mediumspringgreen"), - MEDIUMTURQUOISE("mediumturquoise"), - MEDIUMVIOLETRED("mediumvioletred"), - MIDNIGHTBLUE("midnightblue"), - MINTCREAM("mintcream"), - MISTYROSE("mistyrose"), - MOCCASIN("moccasin"), - NAVAJOWHITE("navajowhite"), - NAVY("navy"), - OLDLACE("oldlace"), - OLIVE("olive"), - OLIVEDRAB("olivedrab"), - ORANGE("orange"), - ORANGERED("orangered"), - ORCHID("orchid"), - PALEGOLDENROD("palegoldenrod"), - PALEGREEN("palegreen"), - PALETURQUOISE("paleturquoise"), - PALEVIOLETRED("palevioletred"), - PAPAYAWHIP("papayawhip"), - PEACHPUFF("peachpuff"), - PERU("peru"), - PINK("pink"), - PLUM("plum"), - POWDERBLUE("powderblue"), - PURPLE("purple"), - REBECCAPURPLE("rebeccapurple"), - RED("red"), - ROSYBROWN("rosybrown"), - ROYALBLUE("royalblue"), - SADDLEBROWN("saddlebrown"), - SALMON("salmon"), - SANDYBROWN("sandybrown"), - SEAGREEN("seagreen"), - SEASHELL("seashell"), - SIENNA("sienna"), - SILVER("silver"), - SKYBLUE("skyblue"), - SLATEBLUE("slateblue"), - SLATEGRAY("slategray"), - SNOW("snow"), - SPRINGGREEN("springgreen"), - STEELBLUE("steelblue"), - TAN("tan"), - TEAL("teal"), - THISTLE("thistle"), - TOMATO("tomato"), - TURQUOISE("turquoise"), - VIOLET("violet"), - WHEAT("wheat"), - WHITE("white"), - WHITESMOKE("whitesmoke"), - YELLOW("yellow"), - YELLOWGREEN("yellowgreen") -} - -/** - * Definitions of CSS background size. - */ -enum class BgSize(internal val size: String) { - COVER("cover"), - CONTAIN("contain") -} - -/** - * Definitions of CSS background repeat options. - */ -enum class BgRepeat(internal val repeat: String) { - REPEAT("repeat"), - REPEATX("repeat-x"), - REPEATY("repeat-y"), - NOREPEAT("no-repeat") -} - -/** - * Definitions of CSS background attachment options. - */ -enum class BgAttach(internal val attachment: String) { - SCROLL("scroll"), - FIXED("fixed"), - LOCAL("local") -} - -/** - * Definitions of CSS background origin options. - */ -enum class BgOrigin(internal val origin: String) { - PADDING("padding-box"), - BORDER("border-box"), - CONTENT("content-box") -} - -/** - * Definitions of CSS background clipping options. - */ -enum class BgClip(internal val clip: String) { - PADDING("padding-box"), - BORDER("border-box"), - CONTENT("content-box") -} - -/** - * Definitions of CSS position options. - */ -enum class Position(internal val position: String) { - STATIC("static"), - RELATIVE("relative"), - FIXED("fixed"), - ABSOLUTE("absolute"), - STICKY("sticky") -} - -/** - * Definitions of CSS overflow options. - */ -enum class Overflow(internal val overflow: String) { - VISIBLE("visible"), - HIDDEN("hidden"), - SCROLL("scroll"), - AUTO("auto"), - INITIAL("initial"), - INHERIT("inherit") -} - -/** - * Definitions of CSS resize options. - */ -enum class Resize(internal val resize: String) { - NONE("none"), - BOTH("both"), - HORIZONTAL("horizontal"), - VERTICAL("vertical"), - INITIAL("initial"), - INHERIT("inherit") -} - -/** - * Type-safe definition of CSS border. - */ -class Border private constructor( - private val width: CssSize? = null, private val style: BorderStyle? = null, - private val color: String? = null -) { - /** - * Creates CSS Border with given width and style. - * @param width width of the border - * @param style style of the border - */ - constructor(width: CssSize? = null, style: BorderStyle? = null) : this(width, style, null) - - /** - * Creates CSS Border with given width, style and color given in hex format. - * @param width width of the border - * @param style style of the border - * @param color color in hex format - */ - constructor(width: CssSize? = null, style: BorderStyle? = null, color: Int) : this( - width, style, - "#" + color.toHexString() - ) - - /** - * Creates CSS Border with given width, style and color given with named constant. - * @param width width of the border - * @param style style of the border - * @param color color named constant - */ - constructor(width: CssSize? = null, style: BorderStyle? = null, color: Col) : this(width, style, color.color) - - internal fun asString(): String { - val w = width?.asString() - return w.orEmpty() + " " + (style?.borderStyle).orEmpty() + " " + color.orEmpty() - } -} - -/** - * Type-safe definition of CSS color. - */ -class Color private constructor(private val color: String? = null) { - /** - * Creates CSS Color with color given in hex format. - * @param color color in hex format - */ - constructor(color: Int) : this("#" + color.toHexString()) - - /** - * Creates CSS Color with color given with named constant. - * @param color color named constant - */ - constructor(color: Col) : this(color.color) - - internal fun asString(): String { - return color.orEmpty() - } -} - -/** - * Type-safe definition of CSS background. - */ -class Background private constructor( - private val color: String? = null, private val image: ResString? = null, - private val positionX: CssSize? = null, private val positionY: CssSize? = null, - private val sizeX: CssSize? = null, private val sizeY: CssSize? = null, - private val size: BgSize? = null, private val repeat: BgRepeat? = null, - private val origin: BgOrigin? = null, private val clip: BgClip? = null, - private val attachment: BgAttach? = null -) { - /** - * Creates CSS Background with given parameters. - * @param image background image - * @param positionX horizontal position of the background image - * @param positionY vertical position of the background image - * @param sizeX horizontal size of the background image - * @param sizeY vertical size of the background image - * @param size resize of the background image - * @param repeat repeat option of the background image - * @param origin origin option of the background image - * @param clip clipping option of the background image - * @param attachment attachment option of the background image - */ - constructor( - image: ResString? = null, positionX: CssSize? = null, positionY: CssSize? = null, - sizeX: CssSize? = null, sizeY: CssSize? = null, size: BgSize? = null, - repeat: BgRepeat? = null, origin: BgOrigin? = null, clip: BgClip? = null, - attachment: BgAttach? = null - ) : this( - null, - image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip, attachment - ) - - /** - * Creates CSS Background with given parameters. - * @param color color of the background in hex format - * @param image background image - * @param positionX horizontal position of the background image - * @param positionY vertical position of the background image - * @param sizeX horizontal size of the background image - * @param sizeY vertical size of the background image - * @param size resize of the background image - * @param repeat repeat option of the background image - * @param origin origin option of the background image - * @param clip clipping option of the background image - * @param attachment attachment option of the background image - */ - constructor( - color: Int, image: ResString? = null, positionX: CssSize? = null, - positionY: CssSize? = null, - sizeX: CssSize? = null, sizeY: CssSize? = null, size: BgSize? = null, - repeat: BgRepeat? = null, origin: BgOrigin? = null, clip: BgClip? = null, - attachment: BgAttach? = null - ) : this( - "#" + - color.toHexString(), image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip, - attachment - ) - - /** - * Creates CSS Background with given parameters. - * @param color color of the background with named constant - * @param image background image - * @param positionX horizontal position of the background image - * @param positionY vertical position of the background image - * @param sizeX horizontal size of the background image - * @param sizeY vertical size of the background image - * @param size resize of the background image - * @param repeat repeat option of the background image - * @param origin origin option of the background image - * @param clip clipping option of the background image - * @param attachment attachment option of the background image - */ - constructor( - color: Col, image: ResString? = null, positionX: CssSize? = null, - positionY: CssSize? = null, sizeX: CssSize? = null, sizeY: CssSize? = null, - size: BgSize? = null, repeat: BgRepeat? = null, origin: BgOrigin? = null, clip: BgClip? = null, - attachment: BgAttach? = null - ) : this( - color.color, image, - positionX, positionY, sizeX, sizeY, size, repeat, origin, clip, attachment - ) - - internal fun asString(): String { - val img = image?.let { - "url($image)" - } - val posX = positionX?.asString() - val posY = positionY?.asString() - val sX = sizeX?.asString() - val sY = sizeY?.asString() - return color.orEmpty() + " " + img.orEmpty() + " " + posX.orEmpty() + " " + posY.orEmpty() + - if (sX != null || sY != null || size != null) { - (if (posX != null || posY != null) " / " else " 0px 0px / ") + - sX.orEmpty() + " " + sY.orEmpty() + " " + (size?.size).orEmpty() - } else { - "" - } + " " + (repeat?.repeat).orEmpty() + " " + (origin?.origin).orEmpty() + " " + - (clip?.clip).orEmpty() + " " + (attachment?.attachment).orEmpty() - } -} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt b/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt deleted file mode 100644 index d871ff60..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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.core - -import pl.treksoft.kvision.utils.asString -import kotlin.Unit -import kotlin.reflect.KProperty - -/** - * Base class for components supporting CSS styling. - */ -abstract class StyledComponent : Component { - private val propertyValues: MutableMap = mutableMapOf() - - /** - * Width of the current component. - */ - open var width: CssSize? by refreshOnUpdate() - /** - * Minimal width of the current component. - */ - var minWidth: CssSize? by refreshOnUpdate() - /** - * Maximal width of the current component. - */ - var maxWidth: CssSize? by refreshOnUpdate() - /** - * Height of the current component. - */ - var height: CssSize? by refreshOnUpdate() - /** - * Minimal height of the current component. - */ - var minHeight: CssSize? by refreshOnUpdate() - /** - * Maximal height of the current component. - */ - var maxHeight: CssSize? by refreshOnUpdate() - /** - * CSS position of the current component. - */ - var position: Position? by refreshOnUpdate() - /** - * Top edge of the current component. - */ - var top: CssSize? by refreshOnUpdate() - /** - * Left edge of the current component. - */ - var left: CssSize? by refreshOnUpdate() - /** - * Right edge of the current component. - */ - var right: CssSize? by refreshOnUpdate() - /** - * Bottom edge of the current component. - */ - var bottom: CssSize? by refreshOnUpdate() - /** - * Z-index of the current component. - */ - var zIndex: Int? by refreshOnUpdate() - /** - * CSS overflow of the current component. - */ - var overflow: Overflow? by refreshOnUpdate() - /** - * CSS resize of the current component. - */ - var resize: Resize? by refreshOnUpdate() - /** - * Border of the current component. - */ - var border: Border? by refreshOnUpdate() - /** - * Top border of the current component. - */ - var borderTop: Border? by refreshOnUpdate() - /** - * Right border of the current component. - */ - var borderRight: Border? by refreshOnUpdate() - /** - * Bottom border of the current component. - */ - var borderBottom: Border? by refreshOnUpdate() - /** - * Left border of the current component. - */ - var borderLeft: Border? by refreshOnUpdate() - /** - * Margin of the current component. - */ - var margin: CssSize? by refreshOnUpdate() - /** - * Top margin of the current component. - */ - var marginTop: CssSize? by refreshOnUpdate() - /** - * Right margin of the current component. - */ - var marginRight: CssSize? by refreshOnUpdate() - /** - * Bottom margin of the current component. - */ - var marginBottom: CssSize? by refreshOnUpdate() - /** - * Left margin of the current component. - */ - var marginLeft: CssSize? by refreshOnUpdate() - /** - * Padding of the current component. - */ - var padding: CssSize? by refreshOnUpdate() - /** - * Top padding of the current component. - */ - var paddingTop: CssSize? by refreshOnUpdate() - /** - * Right padding of the current component. - */ - var paddingRight: CssSize? by refreshOnUpdate() - /** - * Bottom padding of the current component. - */ - var paddingBottom: CssSize? by refreshOnUpdate() - /** - * Left padding of the current component. - */ - var paddingLeft: CssSize? by refreshOnUpdate() - /** - * Text color for the current component. - */ - var color: Color? by refreshOnUpdate() - /** - * Text color for the current component given in hex format (write only). - * - * This property gives a convenient way to set the value of [color] property e.g.: - * - * c.colorHex = 0x00ff00 - * - * The value read from this property is always null. - */ - var colorHex: Int? - get() = null - set(value) { - color = if (value != null) Color(value) else null - } - /** - * Text color for the current component given with named constant (write only). - * - * This property gives a convenient way to set the value of [color] property e.g.: - * - * c.colorName = Col.GREEN - * - * The value read from this property is always null. - */ - var colorName: Col? - get() = null - set(value) { - color = if (value != null) Color(value) else null - } - /** - * Opacity of the current component. - */ - var opacity: Double? by refreshOnUpdate() - /** - * Background of the current component. - */ - var background: Background? by refreshOnUpdate() - - private var snStyleCache: List? = null - - /** - * @suppress - * Internal function - * Re-renders the current component. - * @return current component - */ - open fun refresh(): StyledComponent { - snStyleCache = null - return this - } - - internal fun getSnStyleInternal(): List { - return snStyleCache ?: { - val s = getSnStyle() - snStyleCache = s - s - }() - } - - /** - * Returns the list of String pairs defining CSS style attributes and their values. - * @return the list of attributes and their values - */ - @Suppress("ComplexMethod", "LongMethod") - protected open fun getSnStyle(): List { - val snstyle = mutableListOf() - width?.let { - snstyle.add("width" to it.asString()) - } - minWidth?.let { - snstyle.add("min-width" to it.asString()) - } - maxWidth?.let { - snstyle.add("max-width" to it.asString()) - } - height?.let { - snstyle.add("height" to it.asString()) - } - minHeight?.let { - snstyle.add("min-height" to it.asString()) - } - maxHeight?.let { - snstyle.add("max-height" to it.asString()) - } - position?.let { - snstyle.add("position" to it.position) - } - top?.let { - snstyle.add("top" to it.asString()) - } - left?.let { - snstyle.add("left" to it.asString()) - } - right?.let { - snstyle.add("right" to it.asString()) - } - bottom?.let { - snstyle.add("bottom" to it.asString()) - } - zIndex?.let { - snstyle.add("z-index" to it.toString()) - } - overflow?.let { - snstyle.add("overflow" to it.toString()) - } - resize?.let { - snstyle.add("resize" to it.toString()) - } - border?.let { - snstyle.add("border" to it.asString()) - } - borderTop?.let { - snstyle.add("border-top" to it.asString()) - } - borderRight?.let { - snstyle.add("border-right" to it.asString()) - } - borderBottom?.let { - snstyle.add("border-bottom" to it.asString()) - } - borderLeft?.let { - snstyle.add("border-left" to it.asString()) - } - margin?.let { - snstyle.add("margin" to it.asString()) - } - marginTop?.let { - snstyle.add("margin-top" to it.asString()) - } - marginRight?.let { - snstyle.add("margin-right" to it.asString()) - } - marginBottom?.let { - snstyle.add("margin-bottom" to it.asString()) - } - marginLeft?.let { - snstyle.add("margin-left" to it.asString()) - } - padding?.let { - snstyle.add("padding" to it.asString()) - } - paddingTop?.let { - snstyle.add("padding-top" to it.asString()) - } - paddingRight?.let { - snstyle.add("padding-right" to it.asString()) - } - paddingBottom?.let { - snstyle.add("padding-bottom" to it.asString()) - } - paddingLeft?.let { - snstyle.add("padding-left" to it.asString()) - } - color?.let { - snstyle.add("color" to it.asString()) - } - opacity?.let { - snstyle.add("opacity" to it.toString()) - } - background?.let { - snstyle.add("background" to it.asString()) - } - return snstyle - } - - internal fun refreshOnUpdate(refreshFunction: ((T) -> Unit) = { this.refresh() }) = - RefreshDelegateProvider(null, refreshFunction) - - internal fun refreshOnUpdate(initialValue: T, refreshFunction: ((T) -> Unit) = { this.refresh() }) = - RefreshDelegateProvider(initialValue, refreshFunction) - - internal inner class RefreshDelegateProvider( - private val initialValue: T?, private val refreshFunction: (T) -> Unit - ) { - operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): RefreshDelegate { - if (initialValue != null) propertyValues[prop.name] = initialValue - return RefreshDelegate(refreshFunction) - } - } - - internal inner class RefreshDelegate(private val refreshFunction: ((T) -> Unit)) { - @Suppress("UNCHECKED_CAST") - operator fun getValue(thisRef: StyledComponent, property: KProperty<*>): T { - val value = propertyValues[property.name] - return if (value != null) { - value as T - } else { - null as T - } - } - - operator fun setValue(thisRef: StyledComponent, property: KProperty<*>, value: T) { - propertyValues[property.name] = value - refreshFunction(value) - } - } -} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Types.kt b/src/main/kotlin/pl/treksoft/kvision/core/Types.kt deleted file mode 100644 index 0817b3ae..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/Types.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.core - - /** - * This type is used for accessing resources with CommonJS **require** function. - * - * e.g. require("./img/picture.png") - */ -typealias ResString = String - - /** - * Helper type used to define CSS style attributes. - */ -typealias StringPair = Pair - - /** - * Helper type used to define CSS classes. - */ -typealias StringBoolPair = Pair - - /** - * This type is used for defining CSS dimensions (width, heights, margins, paddings, etc.). - */ -typealias CssSize = Pair diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt deleted file mode 100644 index ac3ba143..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ /dev/null @@ -1,585 +0,0 @@ -/* - * 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.core - -import com.github.snabbdom.VNode -import com.github.snabbdom.VNodeData -import com.github.snabbdom.h -import org.w3c.dom.CustomEventInit -import org.w3c.dom.DragEvent -import org.w3c.dom.Node -import pl.treksoft.jquery.JQuery -import pl.treksoft.jquery.jQuery -import pl.treksoft.kvision.KVManager -import pl.treksoft.kvision.panel.Root -import pl.treksoft.kvision.utils.SnOn -import pl.treksoft.kvision.utils.hooks -import pl.treksoft.kvision.utils.on -import pl.treksoft.kvision.utils.snAttrs -import pl.treksoft.kvision.utils.snClasses -import pl.treksoft.kvision.utils.snOpt -import pl.treksoft.kvision.utils.snStyle - -/** - * Base widget class. The parent of all component classes. - * - * A simple widget is rendered as HTML DIV element. - * - * @constructor Creates basic Widget with given CSS class names. - * @param classes Set of CSS class names - */ -@Suppress("TooManyFunctions", "LargeClass") -open class Widget(classes: Set = setOf()) : StyledComponent() { - - internal val classes = classes.toMutableSet() - internal val surroundingClasses: MutableSet = mutableSetOf() - internal val internalListeners = mutableListOf.() -> Unit>() - internal val listeners = mutableListOf.() -> Unit>() - - override var parent: Component? = null - - override var visible: Boolean = true - set(value) { - val oldField = field - field = value - if (oldField != field) refresh() - } - /** - * A title attribute of generated HTML element. - */ - var title: String? by refreshOnUpdate() - /** - * An ID attribute of generated HTML element. - */ - var id: String? by refreshOnUpdate() - /** - * A role attribute of generated HTML element. - */ - var role: String? by refreshOnUpdate() - /** - * Determines if the current widget is draggable. - */ - var draggable: Boolean? by refreshOnUpdate() - - internal var surroundingSpan by refreshOnUpdate(false) - - internal var eventTarget: Widget? = null - - private var vnode: VNode? = null - - private var snAttrsCache: List? = null - private var snClassCache: List? = null - private var snOnCache: com.github.snabbdom.On? = null - private var snHooksCache: com.github.snabbdom.Hooks? = null - - internal fun singleRender(block: () -> T): T { - getRoot()?.renderDisabled = true - val t = block() - getRoot()?.renderDisabled = false - getRoot()?.reRender() - return t - } - - override fun renderVNode(): VNode { - return if (surroundingClasses.isEmpty()) { - if (surroundingSpan) { - h("span", arrayOf(render())) - } else { - render() - } - } else { - val opt = snOpt { - `class` = snClasses(surroundingClasses.map { c -> c to true }) - } - if (surroundingSpan) { - h("div", opt, arrayOf(h("span", arrayOf(render())))) - } else { - h("div", opt, arrayOf(render())) - } - } - } - - /** - * Renders current component as a Snabbdom vnode. - * @return Snabbdom vnode - */ - protected open fun render(): VNode { - return render("div") - } - - /** - * Renders current component as a Snabbdom vnode. - * @param elementName HTML element name - * @return Snabbdom vnode - */ - protected open fun render(elementName: String): VNode { - return h(elementName, getSnOpt()) - } - - /** - * Renders current component as a Snabbdom vnode. - * @param elementName HTML element name - * @param children array of children nodes - * @return Snabbdom vnode - */ - protected open fun render(elementName: String, children: Array): VNode { - return h(elementName, getSnOpt(), children) - } - - /** - * Generates VNodeData to creating Snabbdom VNode. - * - * Optimizes creating process by keeping configuration attributes in a cache. - */ - private fun getSnOpt(): VNodeData { - return snOpt { - attrs = snAttrs(getSnAttrsInternal()) - style = snStyle(getSnStyleInternal()) - `class` = snClasses(getSnClassInternal()) - on = getSnOn() - hook = getSnHooksInternal() - } - } - - private fun getSnAttrsInternal(): List { - return snAttrsCache ?: { - val s = getSnAttrs() - snAttrsCache = s - s - }() - } - - private fun getSnClassInternal(): List { - return snClassCache ?: { - val s = getSnClass() - snClassCache = s - s - }() - } - - private fun getSnHooksInternal(): com.github.snabbdom.Hooks? { - return snHooksCache ?: { - val s = getSnHooks() - snHooksCache = s - s - }() - } - - /** - * Returns list of CSS class names for current widget in the form of a List. - * @return list of CSS class names - */ - protected open fun getSnClass(): List { - return classes.map { c -> c to true } + if (visible) listOf() else listOf("hidden" to true) - } - - /** - * Returns list of element attributes in the form of a List. - * @return list of element attributes - */ - protected open fun getSnAttrs(): List { - val snattrs = mutableListOf() - id?.let { - snattrs.add("id" to it) - } - title?.let { - snattrs.add("title" to it) - } - role?.let { - snattrs.add("role" to it) - } - if (draggable == true) { - snattrs.add("draggable" to "true") - } - return snattrs - } - - /** - * Returns list of event handlers in the form of a Snabbdom *On* object. - * @return list of event handlers - */ - protected open fun getSnOn(): com.github.snabbdom.On? { - return if (internalListeners.size > 0 || listeners.size > 0) { - val internalHandlers = on(this) - internalListeners.forEach { l -> (internalHandlers::apply)(l) } - val handlers = on(eventTarget ?: this) - listeners.forEach { l -> (handlers::apply)(l) } - if (internalHandlers.click != null) { - if (handlers.click == null) { - handlers.click = internalHandlers.click - } else { - val intc = internalHandlers.click - val c = handlers.click - handlers.click = { e -> - intc?.invoke(e) - c?.invoke(e) - } - } - } - if (internalHandlers.change != null) { - if (handlers.change == null) { - handlers.change = internalHandlers.change - } else { - val intc = internalHandlers.change - val c = handlers.change - handlers.change = { e -> - intc?.invoke(e) - c?.invoke(e) - } - } - } - if (internalHandlers.input != null) { - if (handlers.input == null) { - handlers.input = internalHandlers.input - } else { - val intc = internalHandlers.input - val c = handlers.input - handlers.input = { e -> - intc?.invoke(e) - c?.invoke(e) - } - } - } - handlers - } else { - null - } - } - - /** - * Returns list of hooks in the form of a Snabbdom *Hooks* object. - * @return list of hooks - */ - protected open fun getSnHooks(): com.github.snabbdom.Hooks? { - val hooks = hooks() - hooks.apply { - create = { _, v -> - vnode = v - afterCreate(v) - } - insert = { v -> - vnode = v - afterInsert(v) - } - postpatch = { ov, v -> - vnode = v - if (ov.elm !== v.elm) { - afterInsert(v) - } else { - afterPostpatch(v) - } - } - destroy = { _ -> - afterDestroy() - vnode = null - vnode - } - } - return hooks - } - - /** - * @suppress - * Internal function - */ - @Suppress("UNCHECKED_CAST") - protected fun setInternalEventListener(block: SnOn.() -> Unit): Widget { - internalListeners.add(block as SnOn.() -> Unit) - refresh() - return this - } - - /** - * @suppress - * Internal function - */ - protected fun setInternalEventListener(block: SnOn.() -> Unit): Widget { - internalListeners.add(block) - refresh() - return this - } - - /** - * Sets an event listener for current widget, keeping the actual type of component. - * @param T widget type - * @param block event handler - * @return current widget - * - * Example: - * - * button.setEventListener