From 736b80835f67c9c34657074ebcfbe0752bef1c18 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 17 Oct 2019 21:58:34 +0200 Subject: Move DSL builder functions out of the companion objects (#93) --- .../pl/treksoft/kvision/form/time/DateTime.kt | 28 ++-- .../pl/treksoft/kvision/form/time/DateTimeInput.kt | 32 ++-- .../treksoft/kvision/form/select/SelectRemote.kt | 54 +++--- .../kvision/form/select/SelectRemoteInput.kt | 41 +++-- .../pl/treksoft/kvision/form/select/Select.kt | 30 ++-- .../pl/treksoft/kvision/form/select/SelectInput.kt | 31 ++-- .../treksoft/kvision/form/select/SelectOptGroup.kt | 58 ++++--- .../treksoft/kvision/form/select/SelectOption.kt | 111 ++++++------- .../pl/treksoft/kvision/form/spinner/Spinner.kt | 56 +++---- .../treksoft/kvision/form/spinner/SpinnerInput.kt | 41 +++-- .../pl/treksoft/kvision/form/upload/Upload.kt | 40 ++--- .../pl/treksoft/kvision/form/upload/UploadInput.kt | 97 ++++++----- .../pl/treksoft/kvision/dropdown/ContextMenu.kt | 55 +++---- .../pl/treksoft/kvision/dropdown/DropDown.kt | 181 ++++++++++----------- .../kotlin/pl/treksoft/kvision/dropdown/Header.kt | 44 +++-- .../pl/treksoft/kvision/dropdown/Separator.kt | 43 +++-- .../main/kotlin/pl/treksoft/kvision/navbar/Nav.kt | 92 +++++------ .../kotlin/pl/treksoft/kvision/navbar/NavForm.kt | 26 ++- .../kotlin/pl/treksoft/kvision/navbar/Navbar.kt | 49 +++--- .../treksoft/kvision/panel/ResponsiveGridPanel.kt | 30 ++-- .../kotlin/pl/treksoft/kvision/panel/TabPanel.kt | 37 +++-- .../pl/treksoft/kvision/progress/ProgressBar.kt | 54 +++--- .../pl/treksoft/kvision/toolbar/ButtonGroup.kt | 57 ++++--- .../kotlin/pl/treksoft/kvision/toolbar/Toolbar.kt | 28 ++-- .../kotlin/pl/treksoft/kvision/window/Window.kt | 72 ++++---- .../treksoft/kvision/dropdown/ContextMenuSpec.kt | 4 +- .../test/pl/treksoft/kvision/navbar/NavbarSpec.kt | 4 +- .../main/kotlin/pl/treksoft/kvision/chart/Chart.kt | 33 ++-- .../pl/treksoft/kvision/data/DataContainer.kt | 76 +++++---- .../pl/treksoft/kvision/redux/StateBindingSpec.kt | 6 +- .../pl/treksoft/kvision/redux/StateBindingSpec.kt | 6 +- .../pl/treksoft/kvision/form/text/RichText.kt | 34 ++-- .../pl/treksoft/kvision/form/text/RichTextInput.kt | 26 ++- .../treksoft/kvision/tabulator/TabulatorRemote.kt | 39 ++--- .../pl/treksoft/kvision/tabulator/Tabulator.kt | 135 ++++++++------- src/main/kotlin/pl/treksoft/kvision/core/Style.kt | 39 +++-- src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 22 +-- .../pl/treksoft/kvision/core/WidgetWrapper.kt | 31 ++-- .../kotlin/pl/treksoft/kvision/form/FieldLabel.kt | 28 ++-- .../kotlin/pl/treksoft/kvision/form/FormPanel.kt | 32 ++-- .../pl/treksoft/kvision/form/check/CheckBox.kt | 28 ++-- .../treksoft/kvision/form/check/CheckBoxInput.kt | 29 ++-- .../kotlin/pl/treksoft/kvision/form/check/Radio.kt | 28 ++-- .../pl/treksoft/kvision/form/check/RadioGroup.kt | 28 ++-- .../treksoft/kvision/form/check/RadioGroupInput.kt | 28 ++-- .../pl/treksoft/kvision/form/check/RadioInput.kt | 29 ++-- .../treksoft/kvision/form/select/SimpleSelect.kt | 38 ++--- .../kvision/form/select/SimpleSelectInput.kt | 29 ++-- .../pl/treksoft/kvision/form/text/Password.kt | 36 ++-- .../kotlin/pl/treksoft/kvision/form/text/Text.kt | 28 ++-- .../pl/treksoft/kvision/form/text/TextArea.kt | 28 ++-- .../pl/treksoft/kvision/form/text/TextAreaInput.kt | 28 ++-- .../pl/treksoft/kvision/form/text/TextInput.kt | 28 ++-- src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 38 ++--- src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt | 30 ++-- src/main/kotlin/pl/treksoft/kvision/html/Div.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/Footer.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H1.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H2.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H3.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H4.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H5.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/H6.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/Header.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/Icon.kt | 26 ++- src/main/kotlin/pl/treksoft/kvision/html/Iframe.kt | 32 ++-- src/main/kotlin/pl/treksoft/kvision/html/Image.kt | 28 ++-- src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 28 ++-- src/main/kotlin/pl/treksoft/kvision/html/List.kt | 28 ++-- src/main/kotlin/pl/treksoft/kvision/html/P.kt | 34 ++-- .../kotlin/pl/treksoft/kvision/html/Section.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/Span.kt | 34 ++-- src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 30 ++-- .../kotlin/pl/treksoft/kvision/panel/DockPanel.kt | 22 ++- .../kotlin/pl/treksoft/kvision/panel/FlexPanel.kt | 30 ++-- .../kotlin/pl/treksoft/kvision/panel/GridPanel.kt | 40 +++-- .../kotlin/pl/treksoft/kvision/panel/HPanel.kt | 36 ++-- src/main/kotlin/pl/treksoft/kvision/panel/Root.kt | 47 +++--- .../pl/treksoft/kvision/panel/SimplePanel.kt | 22 ++- .../kotlin/pl/treksoft/kvision/panel/SplitPanel.kt | 28 ++-- .../kotlin/pl/treksoft/kvision/panel/StackPanel.kt | 26 +-- .../kotlin/pl/treksoft/kvision/panel/VPanel.kt | 28 ++-- .../pl/treksoft/kvision/state/StateBinding.kt | 48 +++--- src/main/kotlin/pl/treksoft/kvision/table/Cell.kt | 63 ++++--- .../kotlin/pl/treksoft/kvision/table/HeaderCell.kt | 35 ++-- src/main/kotlin/pl/treksoft/kvision/table/Row.kt | 28 ++-- src/main/kotlin/pl/treksoft/kvision/table/Table.kt | 32 ++-- .../test/pl/treksoft/kvision/core/StyleSpec.kt | 4 +- .../pl/treksoft/kvision/state/StateBindingSpec.kt | 6 +- .../test/pl/treksoft/kvision/table/RowSpec.kt | 2 +- .../test/pl/treksoft/kvision/table/TableSpec.kt | 4 +- 91 files changed, 1649 insertions(+), 1787 deletions(-) diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt index b7cf18ec..3170e462 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt @@ -267,19 +267,19 @@ open class DateTime( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dateTime( - value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null, - rich: Boolean = false, init: (DateTime.() -> Unit)? = null - ): DateTime { - val dateTime = DateTime(value, name, format, label, rich).apply { init?.invoke(this) } - this.add(dateTime) - return dateTime - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dateTime( + value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null, + rich: Boolean = false, init: (DateTime.() -> Unit)? = null +): DateTime { + val dateTime = DateTime(value, name, format, label, rich).apply { init?.invoke(this) } + this.add(dateTime) + return dateTime +} diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt index 626346b1..178fbeaa 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt @@ -28,8 +28,8 @@ import pl.treksoft.kvision.form.FormInput import pl.treksoft.kvision.form.text.TextInput import pl.treksoft.kvision.html.Div import pl.treksoft.kvision.html.Icon -import pl.treksoft.kvision.html.Icon.Companion.icon -import pl.treksoft.kvision.html.Span.Companion.span +import pl.treksoft.kvision.html.icon +import pl.treksoft.kvision.html.span import pl.treksoft.kvision.i18n.I18n import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.types.toDateF @@ -358,20 +358,18 @@ open class DateTimeInput( override fun blur() { input.blur() } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dateTimeInput( - value: Date? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set = setOf(), - init: (DateTimeInput.() -> Unit)? = null - ): DateTimeInput { - val dateTimeInput = DateTimeInput(value, format, classes).apply { init?.invoke(this) } - this.add(dateTimeInput) - return dateTimeInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dateTimeInput( + value: Date? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set = setOf(), + init: (DateTimeInput.() -> Unit)? = null +): DateTimeInput { + val dateTimeInput = DateTimeInput(value, format, classes).apply { init?.invoke(this) } + this.add(dateTimeInput) + return dateTimeInput } diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt index de823280..930bea32 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt @@ -245,32 +245,32 @@ open class SelectRemote( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.selectRemote( - value: String? = null, - serviceManager: KVServiceManager, - function: T.(String?, String?) -> List, name: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, - rich: Boolean = false, init: (SelectRemote.() -> Unit)? = null - ): SelectRemote { - val selectRemote = - SelectRemote( - value, - serviceManager, - function, - name, - multiple, - ajaxOptions, - label, - rich - ).apply { init?.invoke(this) } - this.add(selectRemote) - return selectRemote - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.selectRemote( + value: String? = null, + serviceManager: KVServiceManager, + function: T.(String?, String?) -> List, name: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, + rich: Boolean = false, init: (SelectRemote.() -> Unit)? = null +): SelectRemote { + val selectRemote = + SelectRemote( + value, + serviceManager, + function, + name, + multiple, + ajaxOptions, + label, + rich + ).apply { init?.invoke(this) } + this.add(selectRemote) + return selectRemote +} diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt index 4c891d30..5a795c9c 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt @@ -113,28 +113,25 @@ open class SelectRemoteInput( } } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.selectRemoteInput( - value: String? = null, - serviceManager: KVServiceManager, - function: T.(String?, String?) -> List, - multiple: Boolean = false, - ajaxOptions: AjaxOptions? = null, - classes: Set = setOf(), init: (SelectRemoteInput.() -> Unit)? = null - ): SelectRemoteInput { - val selectRemoteInput = - SelectRemoteInput(value, serviceManager, function, multiple, ajaxOptions, classes).apply { - init?.invoke(this) - } - this.add(selectRemoteInput) - return selectRemoteInput +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.selectRemoteInput( + value: String? = null, + serviceManager: KVServiceManager, + function: T.(String?, String?) -> List, + multiple: Boolean = false, + ajaxOptions: AjaxOptions? = null, + classes: Set = setOf(), init: (SelectRemoteInput.() -> Unit)? = null +): SelectRemoteInput { + val selectRemoteInput = + SelectRemoteInput(value, serviceManager, function, multiple, ajaxOptions, classes).apply { + init?.invoke(this) } - } - + this.add(selectRemoteInput) + return selectRemoteInput } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt index 4b2505d2..ea98e369 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt @@ -266,20 +266,20 @@ open class Select( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.select( - options: List? = null, value: String? = null, name: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, - rich: Boolean = false, init: (Select.() -> Unit)? = null - ): Select { - val select = Select(options, value, name, multiple, ajaxOptions, label, rich).apply { init?.invoke(this) } - this.add(select) - return select - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.select( + options: List? = null, value: String? = null, name: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, + rich: Boolean = false, init: (Select.() -> Unit)? = null +): Select { + val select = Select(options, value, name, multiple, ajaxOptions, label, rich).apply { init?.invoke(this) } + this.add(select) + return select +} diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt index 84eccaf7..b515ea3e 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt @@ -354,22 +354,19 @@ open class SelectInput( override fun blur() { getElementJQuery()?.blur() } +} - companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.selectInput( - options: List? = null, value: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, - classes: Set = setOf(), init: (SelectInput.() -> Unit)? = null - ): SelectInput { - val selectInput = SelectInput(options, value, multiple, ajaxOptions, classes).apply { init?.invoke(this) } - this.add(selectInput) - return selectInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.selectInput( + options: List? = null, value: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, + classes: Set = setOf(), init: (SelectInput.() -> Unit)? = null +): SelectInput { + val selectInput = SelectInput(options, value, multiple, ajaxOptions, classes).apply { init?.invoke(this) } + this.add(selectInput) + return selectInput } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt index 3f07a9bf..7893f891 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt @@ -88,36 +88,34 @@ open class SelectOptGroup( } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Select.selectOptGroup( - label: String, options: List? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null - ): SelectOptGroup { - val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } - this.add(selectOptGroup) - return selectOptGroup - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Select.selectOptGroup( + label: String, options: List? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null +): SelectOptGroup { + val selectOptGroup = + SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + this.add(selectOptGroup) + return selectOptGroup +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectInput.selectOptGroup( - label: String, options: List? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null - ): SelectOptGroup { - val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } - this.add(selectOptGroup) - return selectOptGroup - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectInput.selectOptGroup( + label: String, options: List? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null +): SelectOptGroup { + val selectOptGroup = + SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + this.add(selectOptGroup) + return selectOptGroup } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt index 91c269a8..a9c7eda5 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt @@ -104,67 +104,64 @@ open class SelectOption( } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Select.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Select.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } + this.add(selectOption) + return selectOption +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectInput.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectInput.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } + this.add(selectOption) + return selectOption +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectOptGroup.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectOptGroup.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } - - } + this.add(selectOption) + return selectOption } diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt index 7e3048d1..450d4466 100644 --- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt +++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt @@ -254,34 +254,34 @@ open class Spinner( companion object { internal var counter = 0 + } +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.spinner( - value: Number? = null, - name: String? = null, - min: Int? = null, - max: Int? = null, - step: Double = DEFAULT_STEP, - decimals: Int = 0, - buttonsType: ButtonsType = ButtonsType.VERTICAL, - forceType: ForceType = ForceType.NONE, - buttonStyle: ButtonStyle? = null, - label: String? = null, - rich: Boolean = false, - init: (Spinner.() -> Unit)? = null - ): Spinner { - val spinner = - Spinner(value, name, min, max, step, decimals, buttonsType, forceType, buttonStyle, label, rich).apply { - init?.invoke( - this - ) - } - this.add(spinner) - return spinner +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.spinner( + value: Number? = null, + name: String? = null, + min: Int? = null, + max: Int? = null, + step: Double = DEFAULT_STEP, + decimals: Int = 0, + buttonsType: ButtonsType = ButtonsType.VERTICAL, + forceType: ForceType = ForceType.NONE, + buttonStyle: ButtonStyle? = null, + label: String? = null, + rich: Boolean = false, + init: (Spinner.() -> Unit)? = null +): Spinner { + val spinner = + Spinner(value, name, min, max, step, decimals, buttonsType, forceType, buttonStyle, label, rich).apply { + init?.invoke( + this + ) } - } + this.add(spinner) + return spinner } diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt index c75bbfc4..c68df816 100644 --- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt +++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt @@ -313,28 +313,25 @@ open class SpinnerInput( override fun blur() { getElementJQuery()?.blur() } +} - companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.spinnerInput( - value: Number? = null, min: Int? = null, max: Int? = null, step: Double = DEFAULT_STEP, - decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL, - forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null, classes: Set = setOf(), - init: (SpinnerInput.() -> Unit)? = null - ): SpinnerInput { - val spinnerInput = - SpinnerInput(value, min, max, step, decimals, buttonsType, forceType, buttonStyle, classes).apply { - init?.invoke( - this - ) - } - this.add(spinnerInput) - return spinnerInput +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.spinnerInput( + value: Number? = null, min: Int? = null, max: Int? = null, step: Double = DEFAULT_STEP, + decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL, + forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null, classes: Set = setOf(), + init: (SpinnerInput.() -> Unit)? = null +): SpinnerInput { + val spinnerInput = + SpinnerInput(value, min, max, step, decimals, buttonsType, forceType, buttonStyle, classes).apply { + init?.invoke( + this + ) } - } + this.add(spinnerInput) + return spinnerInput } diff --git a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt index bd931127..67c660ea 100644 --- a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt +++ b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt @@ -308,26 +308,26 @@ open class Upload( companion object { internal var counter = 0 + } +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.upload( - uploadUrl: String? = null, - multiple: Boolean = false, - label: String? = null, - rich: Boolean = false, - init: (Upload.() -> Unit)? = null - ): Upload { - val upload = Upload(uploadUrl, multiple, label, rich).apply { - init?.invoke( - this - ) - } - this.add(upload) - return upload - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.upload( + uploadUrl: String? = null, + multiple: Boolean = false, + label: String? = null, + rich: Boolean = false, + init: (Upload.() -> Unit)? = null +): Upload { + val upload = Upload(uploadUrl, multiple, label, rich).apply { + init?.invoke( + this + ) } + this.add(upload) + return upload } diff --git a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt index faae5274..da05b04c 100644 --- a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt +++ b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt @@ -320,58 +320,55 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla this.language = language } } +} - companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.uploadInput( - uploadUrl: String? = null, - multiple: Boolean = false, - classes: Set = setOf(), - init: (UploadInput.() -> Unit)? = null - ): UploadInput { - val uploadInput = UploadInput(uploadUrl, multiple, classes).apply { - init?.invoke( - this - ) - } - this.add(uploadInput) - return uploadInput - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.uploadInput( + uploadUrl: String? = null, + multiple: Boolean = false, + classes: Set = setOf(), + init: (UploadInput.() -> Unit)? = null +): UploadInput { + val uploadInput = UploadInput(uploadUrl, multiple, classes).apply { + init?.invoke( + this + ) + } + this.add(uploadInput) + return uploadInput +} - /** - * Returns file with the content read. - * @param key key identifier of the control - * @param kFile object identifying the file - * @return KFile object - */ - suspend fun Form.getContent( - key: KProperty1?>, - kFile: KFile - ): KFile { - val control = getControl(key) as Upload - val content = control.getNativeFile(kFile)?.getContent() - return kFile.copy(content = content) - } +/** + * Returns file with the content read. + * @param key key identifier of the control + * @param kFile object identifying the file + * @return KFile object + */ +suspend fun Form.getContent( + key: KProperty1?>, + kFile: KFile +): KFile { + val control = getControl(key) as Upload + val content = control.getNativeFile(kFile)?.getContent() + return kFile.copy(content = content) +} - /** - * Returns file with the content read. - * @param key key identifier of the control - * @param kFile object identifying the file - * @return KFile object - */ - suspend fun FormPanel.getContent( - key: KProperty1?>, - kFile: KFile - ): KFile { - val control = getControl(key) as Upload - val content = control.getNativeFile(kFile)?.getContent() - return kFile.copy(content = content) - } - } +/** + * Returns file with the content read. + * @param key key identifier of the control + * @param kFile object identifying the file + * @return KFile object + */ +suspend fun FormPanel.getContent( + key: KProperty1?>, + kFile: KFile +): KFile { + val control = getControl(key) as Upload + val content = control.getNativeFile(kFile)?.getContent() + return kFile.copy(content = content) } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt index 4e20de81..656b63b5 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt @@ -76,37 +76,36 @@ open class ContextMenu( } companion object { - const val DEFAULT_FIXED_POS_X = 5 const val DEFAULT_FIXED_POS_Y = 5 + } +} - /** - * Sets context menu for the current widget. - * @param contextMenu a context menu - * @return current widget - */ - fun Widget.setContextMenu(contextMenu: ContextMenu): Widget { - this.setEventListener { - contextmenu = { e: MouseEvent -> - e.preventDefault() - contextMenu.positionMenu(e) - } - } - return this - } - - /** - * DSL builder extension function. - * - * 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(this, fixedPosition, classes).apply { init?.invoke(this) } - this.setContextMenu(contextMenu) - return contextMenu +/** + * Sets context menu for the current widget. + * @param contextMenu a context menu + * @return current widget + */ +fun Widget.setContextMenu(contextMenu: ContextMenu): Widget { + this.setEventListener { + contextmenu = { e: MouseEvent -> + e.preventDefault() + contextMenu.positionMenu(e) } } + return this +} + +/** + * DSL builder extension function. + * + * 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(this, fixedPosition, classes).apply { init?.invoke(this) } + this.setContextMenu(contextMenu) + return contextMenu } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index 609a0a27..342a8e84 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -242,103 +242,102 @@ open class DropDown( companion object { internal var counter = 0 + } +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dropDown( - text: String, elements: List? = null, icon: String? = null, - style: ButtonStyle = ButtonStyle.PRIMARY, direction: Direction = Direction.DROPDOWN, - disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false, - classes: Set = setOf(), init: (DropDown.() -> Unit)? = null - ): DropDown { - val dropDown = - DropDown( - text, - elements, - icon, - style, - direction, - disabled, - forNavbar, - forDropDown, - classes - ).apply { init?.invoke(this) } - this.add(dropDown) - return dropDown - } - - /** - * DSL builder extension function for a link in a dropdown list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun DropDown.ddLink( - label: String, url: String? = null, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, url, icon, image, classes + "dropdown-item").apply { - init?.invoke(this) - } - this.add(link) - return link - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dropDown( + text: String, elements: List? = null, icon: String? = null, + style: ButtonStyle = ButtonStyle.PRIMARY, direction: Direction = Direction.DROPDOWN, + disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false, + classes: Set = setOf(), init: (DropDown.() -> Unit)? = null +): DropDown { + val dropDown = + DropDown( + text, + elements, + icon, + style, + direction, + disabled, + forNavbar, + forDropDown, + classes + ).apply { init?.invoke(this) } + this.add(dropDown) + return dropDown +} - /** - * DSL builder extension function for a link in a context menu list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun ContextMenu.cmLink( - label: String, url: String? = null, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, url, icon, image, classes + "dropdown-item").apply { - init?.invoke(this) - } - this.add(link) - return link - } +/** + * DSL builder extension function for a link in a dropdown list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun DropDown.ddLink( + label: String, url: String? = null, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, url, icon, image, classes + "dropdown-item").apply { + init?.invoke(this) + } + this.add(link) + return link +} - /** - * DSL builder extension function for a disabled link in a dropdown list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun DropDown.ddLinkDisabled( - label: String, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply { - tabindex = -1 - setAttribute("aria-disabled", "true") - init?.invoke(this) - } - this.add(link) - return link - } +/** + * DSL builder extension function for a link in a context menu list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun ContextMenu.cmLink( + label: String, url: String? = null, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, url, icon, image, classes + "dropdown-item").apply { + init?.invoke(this) + } + this.add(link) + return link +} - /** - * DSL builder extension function for a disabled link in a context menu list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun ContextMenu.cmLinkDisabled( - label: String, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply { - tabindex = -1 - setAttribute("aria-disabled", "true") - init?.invoke(this) - } - this.add(link) - return link - } +/** + * DSL builder extension function for a disabled link in a dropdown list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun DropDown.ddLinkDisabled( + label: String, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply { + tabindex = -1 + setAttribute("aria-disabled", "true") + init?.invoke(this) + } + this.add(link) + return link +} +/** + * DSL builder extension function for a disabled link in a context menu list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun ContextMenu.cmLinkDisabled( + label: String, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply { + tabindex = -1 + setAttribute("aria-disabled", "true") + init?.invoke(this) } + this.add(link) + return link } internal class DropDownButton( diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt index 13e0b2e4..b88a5955 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt @@ -32,30 +32,26 @@ import pl.treksoft.kvision.html.Tag * @param classes a set of CSS class names */ open class Header(content: String? = null, classes: Set = setOf()) : - Tag(TAG.H6, content, classes = classes + "dropdown-header") { + Tag(TAG.H6, content, classes = classes + "dropdown-header") +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun ContextMenu.header(content: String? = null, classes: Set = setOf()): Header { + val header = Header(content, classes) + this.add(header) + return header +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun ContextMenu.header(content: String? = null, classes: Set = setOf()): Header { - val header = Header(content, classes) - this.add(header) - return header - } - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun DropDown.header(content: String? = null, classes: Set = setOf()): Header { - val header = Header(content, classes) - this.add(header) - return header - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun DropDown.header(content: String? = null, classes: Set = setOf()): Header { + val header = Header(content, classes) + this.add(header) + return header } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt index dd2344bd..62abe588 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt @@ -29,29 +29,26 @@ import pl.treksoft.kvision.html.Div * @constructor * @param classes a set of CSS class names */ -open class Separator(classes: Set = setOf()) : Div(classes = classes + "dropdown-divider") { +open class Separator(classes: Set = setOf()) : Div(classes = classes + "dropdown-divider") - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun ContextMenu.separator(classes: Set = setOf()): Separator { - val separator = Separator(classes) - this.add(separator) - return separator - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun ContextMenu.separator(classes: Set = setOf()): Separator { + val separator = Separator(classes) + this.add(separator) + return separator +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun DropDown.separator(classes: Set = setOf()): Separator { - val separator = Separator(classes) - this.add(separator) - return separator - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun DropDown.separator(classes: Set = setOf()): Separator { + val separator = Separator(classes) + this.add(separator) + return separator } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt index e0da480d..1254e0c9 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt @@ -55,56 +55,52 @@ open class Nav(rightAlign: Boolean = false, classes: Set = setOf(), init } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Navbar.nav( - rightAlign: Boolean = false, classes: Set = setOf(), init: (Nav.() -> Unit)? = null - ): Nav { - val nav = Nav(rightAlign, classes).apply { init?.invoke(this) } - this.add(nav) - return nav - } - +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Navbar.nav( + rightAlign: Boolean = false, classes: Set = setOf(), init: (Nav.() -> Unit)? = null +): Nav { + val nav = Nav(rightAlign, classes).apply { init?.invoke(this) } + this.add(nav) + return nav +} - /** - * DSL builder extension function for a link in a nav list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Nav.navLink( - label: String, url: String? = null, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, url, icon, image, classes + "nav-item" + "nav-link").apply { - init?.invoke(this) - } - this.add(link) - return link - } +/** + * DSL builder extension function for a link in a nav list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Nav.navLink( + label: String, url: String? = null, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, url, icon, image, classes + "nav-item" + "nav-link").apply { + init?.invoke(this) + } + this.add(link) + return link +} - /** - * DSL builder extension function for a disabled link in a nav list. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Nav.navLinkDisabled( - label: String, icon: String? = null, image: ResString? = null, - classes: Set = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = - Link(label, "javascript:void(0)", icon, image, classes + "nav-item" + "nav-link" + "disabled").apply { - tabindex = -1 - setAttribute("aria-disabled", "true") - init?.invoke(this) - } - this.add(link) - return link +/** + * DSL builder extension function for a disabled link in a nav list. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Nav.navLinkDisabled( + label: String, icon: String? = null, image: ResString? = null, + classes: Set = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = + Link(label, "javascript:void(0)", icon, image, classes + "nav-item" + "nav-link" + "disabled").apply { + tabindex = -1 + setAttribute("aria-disabled", "true") + init?.invoke(this) } - - } + this.add(link) + return link } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt index 45454cc8..6cbf6274 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt @@ -54,19 +54,17 @@ open class NavForm(rightAlign: Boolean = false, classes: Set = setOf(), } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Navbar.navForm( - rightAlign: Boolean = false, classes: Set = setOf(), init: (NavForm.() -> Unit)? = null - ): NavForm { - val navForm = NavForm(rightAlign, classes).apply { init?.invoke(this) } - this.add(navForm) - return navForm - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Navbar.navForm( + rightAlign: Boolean = false, classes: Set = setOf(), init: (NavForm.() -> Unit)? = null +): NavForm { + val navForm = NavForm(rightAlign, classes).apply { init?.invoke(this) } + this.add(navForm) + return navForm } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt index 34a9dbe2..92f8832d 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt @@ -29,7 +29,8 @@ import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.html.Link import pl.treksoft.kvision.html.Span -import pl.treksoft.kvision.html.Span.Companion.span +import pl.treksoft.kvision.html.div +import pl.treksoft.kvision.html.span import pl.treksoft.kvision.panel.SimplePanel /** @@ -173,31 +174,31 @@ open class Navbar( companion object { internal var counter = 0 + } +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.navbar( - label: String? = null, - type: NavbarType? = null, - expand: NavbarExpand? = NavbarExpand.LG, - nColor: NavbarColor = NavbarColor.LIGHT, - bgColor: BsBgColor = BsBgColor.LIGHT, - classes: Set = setOf(), init: (Navbar.() -> Unit)? = null - ): Navbar { - val navbar = Navbar(label, type, expand, nColor, bgColor, classes, init) - this.add(navbar) - return navbar - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.navbar( + label: String? = null, + type: NavbarType? = null, + expand: NavbarExpand? = NavbarExpand.LG, + nColor: NavbarColor = NavbarColor.LIGHT, + bgColor: BsBgColor = BsBgColor.LIGHT, + classes: Set = setOf(), init: (Navbar.() -> Unit)? = null +): Navbar { + val navbar = Navbar(label, type, expand, nColor, bgColor, classes, init) + this.add(navbar) + return navbar +} - fun Navbar.navText(label: String, classes: Set = setOf()): Span { - val text = Span(label, classes = classes + "navbar-text") - this.add(text) - return text - } - } +fun Navbar.navText(label: String, classes: Set = setOf()): Span { + val text = Span(label, classes = classes + "navbar-text") + this.add(text) + return text } /** diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt index 4736a27a..ec4cbc29 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt @@ -165,21 +165,19 @@ open class ResponsiveGridPanel( children.forEach { it.dispose() } removeAll() } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.responsiveGridPanel( - gridSize: GridSize = GridSize.MD, - rows: Int = 0, cols: Int = 0, align: Align? = null, - classes: Set = setOf(), init: (ResponsiveGridPanel.() -> Unit)? = null - ): ResponsiveGridPanel { - val responsiveGridPanel = ResponsiveGridPanel(gridSize, rows, cols, align, classes, init) - this.add(responsiveGridPanel) - return responsiveGridPanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.responsiveGridPanel( + gridSize: GridSize = GridSize.MD, + rows: Int = 0, cols: Int = 0, align: Align? = null, + classes: Set = setOf(), init: (ResponsiveGridPanel.() -> Unit)? = null +): ResponsiveGridPanel { + val responsiveGridPanel = ResponsiveGridPanel(gridSize, rows, cols, align, classes, init) + this.add(responsiveGridPanel) + return responsiveGridPanel } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt index 2009e4fc..de8d60e8 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt @@ -26,12 +26,12 @@ import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.core.WidgetWrapper import pl.treksoft.kvision.html.Icon -import pl.treksoft.kvision.html.Link.Companion.link import pl.treksoft.kvision.html.TAG import pl.treksoft.kvision.html.Tag +import pl.treksoft.kvision.html.link import pl.treksoft.kvision.routing.routing import pl.treksoft.kvision.utils.obj -import pl.treksoft.kvision.html.Icon.Companion.icon as cicon +import pl.treksoft.kvision.html.icon as cicon /** * Tab position. @@ -253,21 +253,22 @@ open class TabPanel( companion object { internal var counter = 0 - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.tabPanel( - tabPosition: TabPosition = TabPosition.TOP, - sideTabSize: SideTabSize = SideTabSize.SIZE_3, - scrollableTabs: Boolean = false, - classes: Set = setOf(), - init: (TabPanel.() -> Unit)? = null - ): TabPanel { - val tabPanel = TabPanel(tabPosition, sideTabSize, scrollableTabs, classes, init) - this.add(tabPanel) - return tabPanel - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.tabPanel( + tabPosition: TabPosition = TabPosition.TOP, + sideTabSize: SideTabSize = SideTabSize.SIZE_3, + scrollableTabs: Boolean = false, + classes: Set = setOf(), + init: (TabPanel.() -> Unit)? = null +): TabPanel { + val tabPanel = TabPanel(tabPosition, sideTabSize, scrollableTabs, classes, init) + this.add(tabPanel) + return tabPanel +} diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/progress/ProgressBar.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/progress/ProgressBar.kt index 4d0f4b93..45ea316c 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/progress/ProgressBar.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/progress/ProgressBar.kt @@ -130,33 +130,31 @@ open class ProgressBar( @Suppress("LeakingThis") init?.invoke(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.progressBar( - progress: Int, min: Int = DEFAULT_MIN, max: Int = DEFAULT_MAX, style: ProgressBarStyle? = null, - striped: Boolean = false, animated: Boolean = false, - content: String? = null, rich: Boolean = false, align: Align? = null, - classes: Set = setOf(), init: (ProgressBar.() -> Unit)? = null - ): ProgressBar { - val progressBar = ProgressBar( - progress, - min, - max, - style, - striped, - animated, - content, - rich, - align, - classes - ).apply { init?.invoke(this) } - this.add(progressBar) - return progressBar - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.progressBar( + progress: Int, min: Int = DEFAULT_MIN, max: Int = DEFAULT_MAX, style: ProgressBarStyle? = null, + striped: Boolean = false, animated: Boolean = false, + content: String? = null, rich: Boolean = false, align: Align? = null, + classes: Set = setOf(), init: (ProgressBar.() -> Unit)? = null +): ProgressBar { + val progressBar = ProgressBar( + progress, + min, + max, + style, + striped, + animated, + content, + rich, + align, + classes + ).apply { init?.invoke(this) } + this.add(progressBar) + return progressBar } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/ButtonGroup.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/ButtonGroup.kt index 2aef9e63..5d871a1c 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/ButtonGroup.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/ButtonGroup.kt @@ -75,35 +75,34 @@ open class ButtonGroup( } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.buttonGroup( - size: ButtonGroupSize? = null, vertical: Boolean = false, - classes: Set = setOf(), init: (ButtonGroup.() -> Unit)? = null - ): ButtonGroup { - val group = ButtonGroup(size, vertical, classes).apply { init?.invoke(this) } - this.add(group) - return group - } - /** - * DSL builder extension function for toolbar. - * - * It creates button groups with size and vertical parameters of the toolbar. - */ - fun Toolbar.buttonGroup( - classes: Set = setOf(), init: (ButtonGroup.() -> Unit)? = null - ): ButtonGroup { - val group = ButtonGroup(this.size, this.vertical, classes).apply { - marginRight = this@buttonGroup.spacing.px - init?.invoke(this) - } - this.add(group) - return group - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.buttonGroup( + size: ButtonGroupSize? = null, vertical: Boolean = false, + classes: Set = setOf(), init: (ButtonGroup.() -> Unit)? = null +): ButtonGroup { + val group = ButtonGroup(size, vertical, classes).apply { init?.invoke(this) } + this.add(group) + return group +} + +/** + * DSL builder extension function for toolbar. + * + * It creates button groups with size and vertical parameters of the toolbar. + */ +fun Toolbar.buttonGroup( + classes: Set = setOf(), init: (ButtonGroup.() -> Unit)? = null +): ButtonGroup { + val group = ButtonGroup(this.size, this.vertical, classes).apply { + marginRight = this@buttonGroup.spacing.px + init?.invoke(this) } + this.add(group) + return group } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/Toolbar.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/Toolbar.kt index 13ed8972..b942d1d5 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/Toolbar.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/toolbar/Toolbar.kt @@ -44,20 +44,18 @@ open class Toolbar( @Suppress("LeakingThis") init?.invoke(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.toolbar( - size: ButtonGroupSize? = null, spacing: Int = 2, vertical: Boolean = false, - classes: Set = setOf(), init: (Toolbar.() -> Unit)? = null - ): Toolbar { - val toolbar = Toolbar(size, spacing, vertical, classes).apply { init?.invoke(this) } - this.add(toolbar) - return toolbar - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.toolbar( + size: ButtonGroupSize? = null, spacing: Int = 2, vertical: Boolean = false, + classes: Set = setOf(), init: (Toolbar.() -> Unit)? = null +): Toolbar { + val toolbar = Toolbar(size, spacing, vertical, classes).apply { init?.invoke(this) } + this.add(toolbar) + return toolbar } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt index 83473858..b993b649 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt @@ -409,41 +409,41 @@ open class Window( companion object { internal var counter = 0 internal var zIndexCounter = DEFAULT_Z_INDEX - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.window( - caption: String? = null, - contentWidth: CssSize? = CssSize(0, UNIT.auto), - contentHeight: CssSize? = CssSize(0, UNIT.auto), - isResizable: Boolean = true, - isDraggable: Boolean = true, - closeButton: Boolean = false, - maximizeButton: Boolean = false, - minimizeButton: Boolean = false, - icon: String? = null, - classes: Set = setOf(), - init: (Window.() -> Unit)? = null - ): Window { - val window = - Window( - caption, - contentWidth, - contentHeight, - isResizable, - isDraggable, - closeButton, - maximizeButton, - minimizeButton, - icon, - classes, - init - ) - this.add(window) - return window - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.window( + caption: String? = null, + contentWidth: CssSize? = CssSize(0, UNIT.auto), + contentHeight: CssSize? = CssSize(0, UNIT.auto), + isResizable: Boolean = true, + isDraggable: Boolean = true, + closeButton: Boolean = false, + maximizeButton: Boolean = false, + minimizeButton: Boolean = false, + icon: String? = null, + classes: Set = setOf(), + init: (Window.() -> Unit)? = null +): Window { + val window = + Window( + caption, + contentWidth, + contentHeight, + isResizable, + isDraggable, + closeButton, + maximizeButton, + minimizeButton, + icon, + classes, + init + ) + this.add(window) + return window +} diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt index b467f1ff..5a2cb31b 100644 --- a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt @@ -22,8 +22,8 @@ package test.pl.treksoft.kvision.dropdown import pl.treksoft.kvision.dropdown.ContextMenu -import pl.treksoft.kvision.dropdown.ContextMenu.Companion.setContextMenu -import pl.treksoft.kvision.html.Link.Companion.link +import pl.treksoft.kvision.dropdown.setContextMenu +import pl.treksoft.kvision.html.link import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.utils.obj import test.pl.treksoft.kvision.DomSpec diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/navbar/NavbarSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/navbar/NavbarSpec.kt index 1658e63c..8cbc0af6 100644 --- a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/navbar/NavbarSpec.kt +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/navbar/NavbarSpec.kt @@ -21,9 +21,9 @@ */ package test.pl.treksoft.kvision.navbar -import pl.treksoft.kvision.html.Link.Companion.link import pl.treksoft.kvision.html.TAG -import pl.treksoft.kvision.html.Tag.Companion.tag +import pl.treksoft.kvision.html.link +import pl.treksoft.kvision.html.tag import pl.treksoft.kvision.navbar.Nav import pl.treksoft.kvision.navbar.Navbar import pl.treksoft.kvision.navbar.NavbarColor diff --git a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/Chart.kt b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/Chart.kt index 91658476..29cc80c2 100644 --- a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/Chart.kt +++ b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/Chart.kt @@ -110,22 +110,6 @@ open class Chart( } companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.chart( - configuration: Configuration, - chartWidth: Int? = null, - chartHeight: Int? = null, - classes: Set = setOf(), - init: (Chart.() -> Unit)? = null - ): Chart { - val chart = Chart(configuration, chartWidth, chartHeight, classes).apply { init?.invoke(this) } - this.add(chart) - return chart - } fun registerPlugin(plugin: dynamic) { JsChart.plugins.register(plugin) @@ -136,3 +120,20 @@ open class Chart( } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.chart( + configuration: Configuration, + chartWidth: Int? = null, + chartHeight: Int? = null, + classes: Set = setOf(), + init: (Chart.() -> Unit)? = null +): Chart { + val chart = Chart(configuration, chartWidth, chartHeight, classes).apply { init?.invoke(this) } + this.add(chart) + return chart +} diff --git a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index 24d8b974..84b30afa 100644 --- a/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/kvision-modules/kvision-datacontainer/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -174,45 +174,43 @@ class DataContainer( onUpdateHandler = null return this } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dataContainer( - model: MutableList, - factory: (M, Int, MutableList) -> C, - container: CONT, - containerAdd: (CONT.(C, M) -> Unit)? = null, - filter: ((M) -> Boolean)? = null, - sorter: ((M) -> Comparable<*>?)? = null, - sorterType: () -> SorterType = { SorterType.ASC }, - init: (DataContainer.() -> Unit)? = null - ): DataContainer { - val dataContainer = DataContainer(model, factory, container, containerAdd, filter, sorter, sorterType, init) - this.add(dataContainer) - return dataContainer - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dataContainer( + model: MutableList, + factory: (M, Int, MutableList) -> C, + container: CONT, + containerAdd: (CONT.(C, M) -> Unit)? = null, + filter: ((M) -> Boolean)? = null, + sorter: ((M) -> Comparable<*>?)? = null, + sorterType: () -> SorterType = { SorterType.ASC }, + init: (DataContainer.() -> Unit)? = null +): DataContainer { + val dataContainer = DataContainer(model, factory, container, containerAdd, filter, sorter, sorterType, init) + this.add(dataContainer) + return dataContainer +} - /** - * DSL builder extension function with VPanel default. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dataContainer( - model: MutableList, - factory: (M, Int, MutableList) -> C, - containerAdd: (VPanel.(C, M) -> Unit)? = null, - filter: ((M) -> Boolean)? = null, - sorter: ((M) -> Comparable<*>?)? = null, - sorterType: () -> SorterType = { SorterType.ASC }, - init: (DataContainer.() -> Unit)? = null - ): DataContainer { - val dataContainer = DataContainer(model, factory, VPanel(), containerAdd, filter, sorter, sorterType, init) - this.add(dataContainer) - return dataContainer - } - } +/** + * DSL builder extension function with VPanel default. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dataContainer( + model: MutableList, + factory: (M, Int, MutableList) -> C, + containerAdd: (VPanel.(C, M) -> Unit)? = null, + filter: ((M) -> Boolean)? = null, + sorter: ((M) -> Comparable<*>?)? = null, + sorterType: () -> SorterType = { SorterType.ASC }, + init: (DataContainer.() -> Unit)? = null +): DataContainer { + val dataContainer = DataContainer(model, factory, VPanel(), containerAdd, filter, sorter, sorterType, init) + this.add(dataContainer) + return dataContainer } diff --git a/kvision-modules/kvision-redux-kotlin/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt b/kvision-modules/kvision-redux-kotlin/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt index dee4daa9..ad90770f 100644 --- a/kvision-modules/kvision-redux-kotlin/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt +++ b/kvision-modules/kvision-redux-kotlin/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt @@ -21,13 +21,13 @@ */ package test.pl.treksoft.kvision.redux -import pl.treksoft.kvision.html.Div.Companion.div +import pl.treksoft.kvision.html.div import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.redux.RAction -import pl.treksoft.kvision.state.StateBinding.Companion.stateBinding -import pl.treksoft.kvision.state.StateBinding.Companion.stateUpdate import pl.treksoft.kvision.redux.createReduxStore +import pl.treksoft.kvision.state.stateBinding +import pl.treksoft.kvision.state.stateUpdate import test.pl.treksoft.kvision.DomSpec import kotlin.browser.document import kotlin.test.Test diff --git a/kvision-modules/kvision-redux/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt b/kvision-modules/kvision-redux/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt index 005a2da3..dea28ade 100644 --- a/kvision-modules/kvision-redux/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt +++ b/kvision-modules/kvision-redux/src/test/kotlin/test/pl/treksoft/kvision/redux/StateBindingSpec.kt @@ -21,12 +21,12 @@ */ package test.pl.treksoft.kvision.redux -import pl.treksoft.kvision.html.Div.Companion.div +import pl.treksoft.kvision.html.div import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.panel.SimplePanel -import pl.treksoft.kvision.state.StateBinding.Companion.stateBinding -import pl.treksoft.kvision.state.StateBinding.Companion.stateUpdate import pl.treksoft.kvision.redux.createReduxStore +import pl.treksoft.kvision.state.stateBinding +import pl.treksoft.kvision.state.stateUpdate import redux.RAction import test.pl.treksoft.kvision.DomSpec import kotlin.browser.document diff --git a/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt b/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt index 04a02279..4bf3948d 100644 --- a/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt +++ b/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt @@ -57,23 +57,21 @@ open class RichText( this.addInternal(input) this.addInternal(invalidFeedback) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.richText( - value: String? = null, - name: String? = null, - label: String? = null, - rich: Boolean = false, - init: (RichText.() -> Unit)? = null - ): RichText { - val richText = RichText(value, name, label, rich).apply { init?.invoke(this) } - this.add(richText) - return richText - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.richText( + value: String? = null, + name: String? = null, + label: String? = null, + rich: Boolean = false, + init: (RichText.() -> Unit)? = null +): RichText { + val richText = RichText(value, name, label, rich).apply { init?.invoke(this) } + this.add(richText) + return richText } diff --git a/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt b/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt index 43b018f4..8b58e272 100644 --- a/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt +++ b/kvision-modules/kvision-richtext/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt @@ -114,19 +114,17 @@ open class RichTextInput(value: String? = null, classes: Set = setOf()) override fun changeValue() { // disabled parent class functionality } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.richTextInput( - value: String? = null, classes: Set = setOf(), init: (RichTextInput.() -> Unit)? = null - ): RichTextInput { - val richTextInput = RichTextInput(value, classes).apply { init?.invoke(this) } - this.add(richTextInput) - return richTextInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.richTextInput( + value: String? = null, classes: Set = setOf(), init: (RichTextInput.() -> Unit)? = null +): RichTextInput { + val richTextInput = RichTextInput(value, classes).apply { init?.invoke(this) } + this.add(richTextInput) + return richTextInput } diff --git a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt index 4478b942..d37f3ea9 100644 --- a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt +++ b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt @@ -89,26 +89,23 @@ open class TabulatorRemote( } } } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.tabulatorRemote( - serviceManager: KVServiceManager, - function: E.(Int?, Int?, List?, List?) -> RemoteData, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (TabulatorRemote.() -> Unit)? = null - ): TabulatorRemote { - val tabulatorRemote = TabulatorRemote(serviceManager, function, options, types, classes) - init?.invoke(tabulatorRemote) - this.add(tabulatorRemote) - return tabulatorRemote - } - } - +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.tabulatorRemote( + serviceManager: KVServiceManager, + function: E.(Int?, Int?, List?, List?) -> RemoteData, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (TabulatorRemote.() -> Unit)? = null +): TabulatorRemote { + val tabulatorRemote = TabulatorRemote(serviceManager, function, options, types, classes) + init?.invoke(tabulatorRemote) + this.add(tabulatorRemote) + return tabulatorRemote } diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt index 16638012..0f5b48ae 100644 --- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt +++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt @@ -603,74 +603,6 @@ open class Tabulator( } companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.tabulator( - data: List? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(data, dataUpdateOnEdit, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for general redux store. - */ - fun Container.tabulator( - store: ReduxStore, - dataFactory: (S) -> List, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(store, dataFactory, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for dedicated redux store (backed with a list). - */ - fun Container.tabulator( - store: ReduxStore, A>, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(store, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for dynamic data (send within options parameter). - */ - fun Container.tabulator( - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - /** * A helper function to create a Tabulator object with correct serializer. */ @@ -727,3 +659,70 @@ open class Tabulator( } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.tabulator( + data: List? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(data, dataUpdateOnEdit, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for general redux store. + */ +fun Container.tabulator( + store: ReduxStore, + dataFactory: (S) -> List, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(store, dataFactory, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for dedicated redux store (backed with a list). + */ +fun Container.tabulator( + store: ReduxStore, A>, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(store, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for dynamic data (send within options parameter). + */ +fun Container.tabulator( + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt index ff91c429..7c650e6c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt @@ -96,26 +96,25 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S companion object { internal var counter = 0 internal var styles = mutableListOf