diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
commit | 736b80835f67c9c34657074ebcfbe0752bef1c18 (patch) | |
tree | 82d1e18a9ec07692dfe5dd31f470b842a9950a89 | |
parent | 53b325d52208bfd44ba6a524ce3dda5379aed699 (diff) | |
download | kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.gz kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.bz2 kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.zip |
Move DSL builder functions out of the companion objects (#93)
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<String> = 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<String> = 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<T : Any>( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <T : Any> Container.selectRemote( - value: String? = null, - serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteOption>, name: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, - rich: Boolean = false, init: (SelectRemote<T>.() -> Unit)? = null - ): SelectRemote<T> { - 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 <T : Any> Container.selectRemote( + value: String? = null, + serviceManager: KVServiceManager<T>, + function: T.(String?, String?) -> List<RemoteOption>, name: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, + rich: Boolean = false, init: (SelectRemote<T>.() -> Unit)? = null +): SelectRemote<T> { + 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<T : Any>( } } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <T : Any> Container.selectRemoteInput( - value: String? = null, - serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteOption>, - multiple: Boolean = false, - ajaxOptions: AjaxOptions? = null, - classes: Set<String> = setOf(), init: (SelectRemoteInput<T>.() -> Unit)? = null - ): SelectRemoteInput<T> { - 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 <T : Any> Container.selectRemoteInput( + value: String? = null, + serviceManager: KVServiceManager<T>, + function: T.(String?, String?) -> List<RemoteOption>, + multiple: Boolean = false, + ajaxOptions: AjaxOptions? = null, + classes: Set<String> = setOf(), init: (SelectRemoteInput<T>.() -> Unit)? = null +): SelectRemoteInput<T> { + 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<StringPair>? = 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<StringPair>? = 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<StringPair>? = null, value: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, - classes: Set<String> = 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<StringPair>? = null, value: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, + classes: Set<String> = 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<StringPair>? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set<String> = 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<StringPair>? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set<String> = 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<StringPair>? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set<String> = 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<StringPair>? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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 <K : Any> Form<K>.getContent( - key: KProperty1<K, List<KFile>?>, - 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 <K : Any> Form<K>.getContent( + key: KProperty1<K, List<KFile>?>, + 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 <K : Any> FormPanel<K>.getContent( - key: KProperty1<K, List<KFile>?>, - 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 <K : Any> FormPanel<K>.getContent( + key: KProperty1<K, List<KFile>?>, + 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<Widget> { - 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<String> = 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<Widget> { + 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<String> = 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<StringPair>? = null, icon: String? = null, - style: ButtonStyle = ButtonStyle.PRIMARY, direction: Direction = Direction.DROPDOWN, - disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false, - classes: Set<String> = 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<String> = 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<StringPair>? = null, icon: String? = null, + style: ButtonStyle = ButtonStyle.PRIMARY, direction: Direction = Direction.DROPDOWN, + disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false, + classes: Set<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = setOf()) : Div(classes = classes + "dropdown-divider") { +open class Separator(classes: Set<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = setOf()): Span { - val text = Span(label, classes = classes + "navbar-text") - this.add(text) - return text - } - } +fun Navbar.navText(label: String, classes: Set<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<M, C : Component, CONT : Container>( onUpdateHandler = null return this } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <M, C : Component, CONT : Container> Container.dataContainer( - model: MutableList<M>, - factory: (M, Int, MutableList<M>) -> C, - container: CONT, - containerAdd: (CONT.(C, M) -> Unit)? = null, - filter: ((M) -> Boolean)? = null, - sorter: ((M) -> Comparable<*>?)? = null, - sorterType: () -> SorterType = { SorterType.ASC }, - init: (DataContainer<M, C, CONT>.() -> Unit)? = null - ): DataContainer<M, C, CONT> { - 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 <M, C : Component, CONT : Container> Container.dataContainer( + model: MutableList<M>, + factory: (M, Int, MutableList<M>) -> C, + container: CONT, + containerAdd: (CONT.(C, M) -> Unit)? = null, + filter: ((M) -> Boolean)? = null, + sorter: ((M) -> Comparable<*>?)? = null, + sorterType: () -> SorterType = { SorterType.ASC }, + init: (DataContainer<M, C, CONT>.() -> Unit)? = null +): DataContainer<M, C, CONT> { + 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 <M, C : Component> Container.dataContainer( - model: MutableList<M>, - factory: (M, Int, MutableList<M>) -> C, - containerAdd: (VPanel.(C, M) -> Unit)? = null, - filter: ((M) -> Boolean)? = null, - sorter: ((M) -> Comparable<*>?)? = null, - sorterType: () -> SorterType = { SorterType.ASC }, - init: (DataContainer<M, C, VPanel>.() -> Unit)? = null - ): DataContainer<M, C, VPanel> { - 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 <M, C : Component> Container.dataContainer( + model: MutableList<M>, + factory: (M, Int, MutableList<M>) -> C, + containerAdd: (VPanel.(C, M) -> Unit)? = null, + filter: ((M) -> Boolean)? = null, + sorter: ((M) -> Comparable<*>?)? = null, + sorterType: () -> SorterType = { SorterType.ASC }, + init: (DataContainer<M, C, VPanel>.() -> Unit)? = null +): DataContainer<M, C, VPanel> { + 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<String> = 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<String> = 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<String> = 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<T : Any, E : Any>( } } } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <T : Any, E : Any> Container.tabulatorRemote( - serviceManager: KVServiceManager<E>, - function: E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (TabulatorRemote<T, E>.() -> Unit)? = null - ): TabulatorRemote<T, E> { - 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 <T : Any, E : Any> Container.tabulatorRemote( + serviceManager: KVServiceManager<E>, + function: E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (TabulatorRemote<T, E>.() -> Unit)? = null +): TabulatorRemote<T, E> { + 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<T : Any>( } companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <T : Any> Container.tabulator( - data: List<T>? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any, S : Any, A : RAction> Container.tabulator( - store: ReduxStore<S, A>, - dataFactory: (S) -> List<T>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any, A : RAction> Container.tabulator( - store: ReduxStore<List<T>, A>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any> Container.tabulator( - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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<T : Any>( } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun <T : Any> Container.tabulator( + data: List<T>? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any, S : Any, A : RAction> Container.tabulator( + store: ReduxStore<S, A>, + dataFactory: (S) -> List<T>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any, A : RAction> Container.tabulator( + store: ReduxStore<List<T>, A>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any> Container.tabulator( + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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<Style>() - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Widget.style(className: String? = null, init: (Style.() -> Unit)? = null): Style { - val style = Style(className, null, init) - this.addCssClass(style) - return style - } - - /** - * DSL builder extension function for cascading styles. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Style.style(className: String? = null, init: (Style.() -> Unit)? = null): Style { - return Style(className, this, init) - } } +} +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Widget.style(className: String? = null, init: (Style.() -> Unit)? = null): Style { + val style = Style(className, null, init) + this.addCssClass(style) + return style +} + +/** + * DSL builder extension function for cascading styles. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Style.style(className: String? = null, init: (Style.() -> Unit)? = null): Style { + return Style(className, this, init) } diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index 24543b1f..9b3e9226 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -810,16 +810,16 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component companion object { private var counter: Long = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.widget(classes: Set<String> = setOf(), init: (Widget.() -> Unit)? = null): Widget { - val widget = Widget(classes).apply { init?.invoke(this) } - this.add(widget) - return widget - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.widget(classes: Set<String> = setOf(), init: (Widget.() -> Unit)? = null): Widget { + val widget = Widget(classes).apply { init?.invoke(this) } + this.add(widget) + return widget +} diff --git a/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt b/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt index 739cb99e..1d5ada90 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt @@ -23,7 +23,6 @@ package pl.treksoft.kvision.core import com.github.snabbdom.VNode import pl.treksoft.kvision.panel.SimplePanel -import kotlin.Unit /** * This class allows to wrap a component into separately styled DIV element. @@ -55,21 +54,19 @@ open class WidgetWrapper(internal var wrapped: Component?, classes: Set<String> wrapped?.clearParent() wrapped = null } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.widgetWrapper( - wrapped: Component?, - classes: Set<String> = setOf(), - init: (WidgetWrapper.() -> Unit)? = null - ): WidgetWrapper { - val widgetWrapper = WidgetWrapper(wrapped, classes).apply { init?.invoke(this) } - this.add(widgetWrapper) - return widgetWrapper - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.widgetWrapper( + wrapped: Component?, + classes: Set<String> = setOf(), + init: (WidgetWrapper.() -> Unit)? = null +): WidgetWrapper { + val widgetWrapper = WidgetWrapper(wrapped, classes).apply { init?.invoke(this) } + this.add(widgetWrapper) + return widgetWrapper } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FieldLabel.kt b/src/main/kotlin/pl/treksoft/kvision/form/FieldLabel.kt index 4684b1be..8413eb3c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FieldLabel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FieldLabel.kt @@ -46,20 +46,18 @@ open class FieldLabel( override fun getSnAttrs(): List<StringPair> { return super.getSnAttrs() + ("for" to forId) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.fieldLabel( - forId: String, content: String? = null, rich: Boolean = false, - classes: Set<String> = setOf("control-label"), init: (FieldLabel.() -> Unit)? = null - ): FieldLabel { - val fieldLabel = FieldLabel(forId, content, rich, classes).apply { init?.invoke(this) } - this.add(fieldLabel) - return fieldLabel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.fieldLabel( + forId: String, content: String? = null, rich: Boolean = false, + classes: Set<String> = setOf("control-label"), init: (FieldLabel.() -> Unit)? = null +): FieldLabel { + val fieldLabel = FieldLabel(forId, content, rich, classes).apply { init?.invoke(this) } + this.add(fieldLabel) + return fieldLabel } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt index e8fa0a42..894ea4bc 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt @@ -28,6 +28,7 @@ import kotlinx.serialization.serializer import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.StringPair +import pl.treksoft.kvision.form.FormPanel.Companion.create import pl.treksoft.kvision.html.Div import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.types.KFile @@ -390,21 +391,6 @@ open class FormPanel<K : Any>( } companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - inline fun <reified K : Any> Container.formPanel( - method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, - type: FormType? = null, condensed: Boolean = false, classes: Set<String> = setOf(), - noinline init: (FormPanel<K>.() -> Unit)? = null - ): FormPanel<K> { - val formPanel = create<K>(method, action, enctype, type, condensed, classes) - init?.invoke(formPanel) - this.add(formPanel) - return formPanel - } @UseExperimental(ImplicitReflectionSerializer::class) inline fun <reified K : Any> create( @@ -419,3 +405,19 @@ open class FormPanel<K : Any>( } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +inline fun <reified K : Any> Container.formPanel( + method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, + type: FormType? = null, condensed: Boolean = false, classes: Set<String> = setOf(), + noinline init: (FormPanel<K>.() -> Unit)? = null +): FormPanel<K> { + val formPanel = create<K>(method, action, enctype, type, condensed, classes) + init?.invoke(formPanel) + this.add(formPanel) + return formPanel +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt index cb962850..ac25b30d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -191,19 +191,19 @@ open class CheckBox( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.checkBox( - value: Boolean = false, name: String? = null, label: String? = null, - rich: Boolean = false, init: (CheckBox.() -> Unit)? = null - ): CheckBox { - val checkBox = CheckBox(value, name, label, rich).apply { init?.invoke(this) } - this.add(checkBox) - return checkBox - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.checkBox( + value: Boolean = false, name: String? = null, label: String? = null, + rich: Boolean = false, init: (CheckBox.() -> Unit)? = null +): CheckBox { + val checkBox = CheckBox(value, name, label, rich).apply { init?.invoke(this) } + this.add(checkBox) + return checkBox +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt index ea58268d..ea8bf7db 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt @@ -33,21 +33,18 @@ import pl.treksoft.kvision.core.Container open class CheckBoxInput( value: Boolean = false, classes: Set<String> = setOf() -) : CheckInput(CheckInputType.CHECKBOX, value, classes) { +) : CheckInput(CheckInputType.CHECKBOX, value, classes) - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.checkBoxInput( - value: Boolean = false, - classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null - ): CheckBoxInput { - val checkBoxInput = CheckBoxInput(value, classes).apply { init?.invoke(this) } - this.add(checkBoxInput) - return checkBoxInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.checkBoxInput( + value: Boolean = false, + classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null +): CheckBoxInput { + val checkBoxInput = CheckBoxInput(value, classes).apply { init?.invoke(this) } + this.add(checkBoxInput) + return checkBoxInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt index e9551196..bb73da60 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -206,19 +206,19 @@ open class Radio( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radio( - value: Boolean = false, extraValue: String? = null, name: String? = null, label: String? = null, - rich: Boolean = false, init: (Radio.() -> Unit)? = null - ): Radio { - val radio = Radio(value, extraValue, name, label, rich).apply { init?.invoke(this) } - this.add(radio) - return radio - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radio( + value: Boolean = false, extraValue: String? = null, name: String? = null, label: String? = null, + rich: Boolean = false, init: (Radio.() -> Unit)? = null +): Radio { + val radio = Radio(value, extraValue, name, label, rich).apply { init?.invoke(this) } + this.add(radio) + return radio +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt index 14b426a3..bee57db4 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt @@ -227,19 +227,19 @@ open class RadioGroup( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioGroup( - options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, - label: String? = null, rich: Boolean = false, init: (RadioGroup.() -> Unit)? = null - ): RadioGroup { - val radioGroup = RadioGroup(options, value, name, inline, label, rich).apply { init?.invoke(this) } - this.add(radioGroup) - return radioGroup - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioGroup( + options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, + label: String? = null, rich: Boolean = false, init: (RadioGroup.() -> Unit)? = null +): RadioGroup { + val radioGroup = RadioGroup(options, value, name, inline, label, rich).apply { init?.invoke(this) } + this.add(radioGroup) + return radioGroup +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt index d4301709..5a47c3ce 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt @@ -174,19 +174,19 @@ open class RadioGroupInput( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioGroupInput( - options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, - init: (RadioGroupInput.() -> Unit)? = null - ): RadioGroupInput { - val radioGroupInput = RadioGroupInput(options, value, name, inline).apply { init?.invoke(this) } - this.add(radioGroupInput) - return radioGroupInput - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioGroupInput( + options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, + init: (RadioGroupInput.() -> Unit)? = null +): RadioGroupInput { + val radioGroupInput = RadioGroupInput(options, value, name, inline).apply { init?.invoke(this) } + this.add(radioGroupInput) + return radioGroupInput +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt index 9c6a1670..72bb4cd0 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt @@ -33,21 +33,18 @@ import pl.treksoft.kvision.core.Container open class RadioInput( value: Boolean = false, classes: Set<String> = setOf() -) : CheckInput(CheckInputType.RADIO, value, classes) { +) : CheckInput(CheckInputType.RADIO, value, classes) - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioInput( - value: Boolean = false, - classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null - ): RadioInput { - val checkBoxInput = RadioInput(value, classes).apply { init?.invoke(this) } - this.add(checkBoxInput) - return checkBoxInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioInput( + value: Boolean = false, + classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null +): RadioInput { + val checkBoxInput = RadioInput(value, classes).apply { init?.invoke(this) } + this.add(checkBoxInput) + return checkBoxInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt index bef14bfa..1bcef061 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt @@ -186,24 +186,24 @@ open class SimpleSelect( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.simpleSelect( - options: List<StringPair>? = null, - value: String? = null, - emptyOption: Boolean = false, - name: String? = null, - label: String? = null, - rich: Boolean = false, - init: (SimpleSelect.() -> Unit)? = null - ): SimpleSelect { - val simpleSelect = SimpleSelect(options, value, emptyOption, name, label, rich).apply { init?.invoke(this) } - this.add(simpleSelect) - return simpleSelect - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.simpleSelect( + options: List<StringPair>? = null, + value: String? = null, + emptyOption: Boolean = false, + name: String? = null, + label: String? = null, + rich: Boolean = false, + init: (SimpleSelect.() -> Unit)? = null +): SimpleSelect { + val simpleSelect = SimpleSelect(options, value, emptyOption, name, label, rich).apply { init?.invoke(this) } + this.add(simpleSelect) + return simpleSelect +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelectInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelectInput.kt index 31d32052..bc99f514 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelectInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelectInput.kt @@ -199,21 +199,18 @@ open class SimpleSelectInput( 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.simpleSelectInput( - options: List<StringPair>? = null, value: String? = null, emptyOption: Boolean = false, - classes: Set<String> = setOf(), init: (SimpleSelectInput.() -> Unit)? = null - ): SimpleSelectInput { - val simpleSelectInput = SimpleSelectInput(options, value, emptyOption, classes).apply { init?.invoke(this) } - this.add(simpleSelectInput) - return simpleSelectInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.simpleSelectInput( + options: List<StringPair>? = null, value: String? = null, emptyOption: Boolean = false, + classes: Set<String> = setOf(), init: (SimpleSelectInput.() -> Unit)? = null +): SimpleSelectInput { + val simpleSelectInput = SimpleSelectInput(options, value, emptyOption, classes).apply { init?.invoke(this) } + this.add(simpleSelectInput) + return simpleSelectInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt index 1d36516e..eb86f152 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt @@ -35,23 +35,21 @@ import pl.treksoft.kvision.core.Container open class Password(value: String? = null, name: String? = null, label: String? = null, rich: Boolean = false) : Text( TextInputType.PASSWORD, value, name, label, rich -) { - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.password( - value: String? = null, - name: String? = null, - label: String? = null, - rich: Boolean = false, - init: (Password.() -> Unit)? = null - ): Password { - val password = Password(value, name, label, rich).apply { init?.invoke(this) } - this.add(password) - return password - } - } +) + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.password( + value: String? = null, + name: String? = null, + label: String? = null, + rich: Boolean = false, + init: (Password.() -> Unit)? = null +): Password { + val password = Password(value, name, label, rich).apply { init?.invoke(this) } + this.add(password) + return password } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt index f493b06e..32fc1881 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt @@ -66,20 +66,18 @@ open class Text( 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.text( - type: TextInputType = TextInputType.TEXT, value: String? = null, name: String? = null, - label: String? = null, rich: Boolean = false, init: (Text.() -> Unit)? = null - ): Text { - val text = Text(type, value, name, label, rich).apply { init?.invoke(this) } - this.add(text) - return text - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.text( + type: TextInputType = TextInputType.TEXT, value: String? = null, name: String? = null, + label: String? = null, rich: Boolean = false, init: (Text.() -> Unit)? = null +): Text { + val text = Text(type, value, name, label, rich).apply { init?.invoke(this) } + this.add(text) + return text } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt index ccf17892..47b6870c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt @@ -75,20 +75,18 @@ open class TextArea( 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.textArea( - cols: Int? = null, rows: Int? = null, value: String? = null, name: String? = null, - label: String? = null, rich: Boolean = false, init: (TextArea.() -> Unit)? = null - ): TextArea { - val textArea = TextArea(cols, rows, value, name, label, rich).apply { init?.invoke(this) } - this.add(textArea) - return textArea - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.textArea( + cols: Int? = null, rows: Int? = null, value: String? = null, name: String? = null, + label: String? = null, rich: Boolean = false, init: (TextArea.() -> Unit)? = null +): TextArea { + val textArea = TextArea(cols, rows, value, name, label, rich).apply { init?.invoke(this) } + this.add(textArea) + return textArea } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt index 9fc89544..acad7853 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt @@ -69,20 +69,18 @@ open class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.textAreaInput( - cols: Int? = null, rows: Int? = null, value: String? = null, classes: Set<String> = setOf(), - init: (TextAreaInput.() -> Unit)? = null - ): TextAreaInput { - val textAreaInput = TextAreaInput(cols, rows, value, classes).apply { init?.invoke(this) } - this.add(textAreaInput) - return textAreaInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.textAreaInput( + cols: Int? = null, rows: Int? = null, value: String? = null, classes: Set<String> = setOf(), + init: (TextAreaInput.() -> Unit)? = null +): TextAreaInput { + val textAreaInput = TextAreaInput(cols, rows, value, classes).apply { init?.invoke(this) } + this.add(textAreaInput) + return textAreaInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt index bc6e178d..d057dcbd 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt @@ -77,20 +77,18 @@ open class TextInput(type: TextInputType = TextInputType.TEXT, value: String? = } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.textInput( - type: TextInputType = TextInputType.TEXT, value: String? = null, classes: Set<String> = setOf(), - init: (TextInput.() -> Unit)? = null - ): TextInput { - val textInput = TextInput(type, value, classes).apply { init?.invoke(this) } - this.add(textInput) - return textInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.textInput( + type: TextInputType = TextInputType.TEXT, value: String? = null, classes: Set<String> = setOf(), + init: (TextInput.() -> Unit)? = null +): TextInput { + val textInput = TextInput(type, value, classes).apply { init?.invoke(this) } + this.add(textInput) + return textInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt index aaa0f735..ec1d95f5 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt @@ -155,25 +155,23 @@ open class Button( } return this } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.button( - text: String, - icon: String? = null, - style: ButtonStyle = ButtonStyle.PRIMARY, - type: ButtonType = ButtonType.BUTTON, - disabled: Boolean = false, - classes: Set<String> = setOf(), - init: (Button.() -> Unit)? = null - ): Button { - val button = Button(text, icon, style, type, disabled, classes).apply { init?.invoke(this) } - this.add(button) - return button - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.button( + text: String, + icon: String? = null, + style: ButtonStyle = ButtonStyle.PRIMARY, + type: ButtonType = ButtonType.BUTTON, + disabled: Boolean = false, + classes: Set<String> = setOf(), + init: (Button.() -> Unit)? = null +): Button { + val button = Button(text, icon, style, type, disabled, classes).apply { init?.invoke(this) } + this.add(button) + return button } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt b/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt index feb9a970..840d5dc7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt @@ -75,20 +75,20 @@ open class Canvas( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.canvas( - canvasWidth: Int? = null, canvasHeight: Int? = null, classes: Set<String> = setOf(), - init: (Canvas.() -> Unit)? = null - ): Canvas { - val canvas = - Canvas(canvasWidth, canvasHeight, classes).apply { init?.invoke(this) } - this.add(canvas) - return canvas - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.canvas( + canvasWidth: Int? = null, canvasHeight: Int? = null, classes: Set<String> = setOf(), + init: (Canvas.() -> Unit)? = null +): Canvas { + val canvas = + Canvas(canvasWidth, canvasHeight, classes).apply { init?.invoke(this) } + this.add(canvas) + return canvas +} diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Div.kt b/src/main/kotlin/pl/treksoft/kvision/html/Div.kt index 42d6b496..2ffabe49 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Div.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Div.kt @@ -46,23 +46,21 @@ open class Div( @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.div( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (Div.() -> Unit)? = null - ): Div { - val div = Div(content, rich, align, classes).apply { init?.invoke(this) } - this.add(div) - return div - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.div( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (Div.() -> Unit)? = null +): Div { + val div = Div(content, rich, align, classes).apply { init?.invoke(this) } + this.add(div) + return div } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Footer.kt b/src/main/kotlin/pl/treksoft/kvision/html/Footer.kt index 8b44dfc0..c71e346f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Footer.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Footer.kt @@ -46,23 +46,21 @@ open class Footer( @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.footer( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (Footer.() -> Unit)? = null - ): Footer { - val footer = Footer(content, rich, align, classes).apply { init?.invoke(this) } - this.add(footer) - return footer - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.footer( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (Footer.() -> Unit)? = null +): Footer { + val footer = Footer(content, rich, align, classes).apply { init?.invoke(this) } + this.add(footer) + return footer } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H1.kt b/src/main/kotlin/pl/treksoft/kvision/html/H1.kt index 894baf72..6a3ac9cc 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H1.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H1.kt @@ -46,23 +46,21 @@ open class H1( @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.h1( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H1.() -> Unit)? = null - ): H1 { - val h1 = H1(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h1) - return h1 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h1( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H1.() -> Unit)? = null +): H1 { + val h1 = H1(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h1) + return h1 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H2.kt b/src/main/kotlin/pl/treksoft/kvision/html/H2.kt index 54e12b4a..7bdd3473 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H2.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H2.kt @@ -46,23 +46,21 @@ open class H2( @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.h2( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H2.() -> Unit)? = null - ): H2 { - val h2 = H2(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h2) - return h2 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h2( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H2.() -> Unit)? = null +): H2 { + val h2 = H2(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h2) + return h2 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H3.kt b/src/main/kotlin/pl/treksoft/kvision/html/H3.kt index af71cdc5..1a2efdbb 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H3.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H3.kt @@ -46,23 +46,21 @@ open class H3( @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.h3( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H3.() -> Unit)? = null - ): H3 { - val h3 = H3(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h3) - return h3 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h3( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H3.() -> Unit)? = null +): H3 { + val h3 = H3(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h3) + return h3 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H4.kt b/src/main/kotlin/pl/treksoft/kvision/html/H4.kt index 9c1b92ab..ae00b8a7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H4.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H4.kt @@ -46,23 +46,21 @@ open class H4( @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.h4( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H4.() -> Unit)? = null - ): H4 { - val h4 = H4(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h4) - return h4 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h4( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H4.() -> Unit)? = null +): H4 { + val h4 = H4(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h4) + return h4 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H5.kt b/src/main/kotlin/pl/treksoft/kvision/html/H5.kt index ac993c4d..c40a0658 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H5.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H5.kt @@ -46,23 +46,21 @@ open class H5( @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.h5( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H5.() -> Unit)? = null - ): H5 { - val h5 = H5(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h5) - return h5 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h5( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H5.() -> Unit)? = null +): H5 { + val h5 = H5(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h5) + return h5 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/H6.kt b/src/main/kotlin/pl/treksoft/kvision/html/H6.kt index eaef18ff..048ab5df 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/H6.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/H6.kt @@ -46,23 +46,21 @@ open class H6( @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.h6( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (H6.() -> Unit)? = null - ): H6 { - val h6 = H6(content, rich, align, classes).apply { init?.invoke(this) } - this.add(h6) - return h6 - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.h6( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (H6.() -> Unit)? = null +): H6 { + val h6 = H6(content, rich, align, classes).apply { init?.invoke(this) } + this.add(h6) + return h6 } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Header.kt b/src/main/kotlin/pl/treksoft/kvision/html/Header.kt index 94a9c079..e62e884e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Header.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Header.kt @@ -46,23 +46,21 @@ open class Header( @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.header( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (Header.() -> Unit)? = null - ): Header { - val header = Header(content, rich, align, classes).apply { init?.invoke(this) } - this.add(header) - return header - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.header( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (Header.() -> Unit)? = null +): Header { + val header = Header(content, rich, align, classes).apply { init?.invoke(this) } + this.add(header) + return header } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Icon.kt b/src/main/kotlin/pl/treksoft/kvision/html/Icon.kt index a9fb03db..a54df1d6 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Icon.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Icon.kt @@ -42,19 +42,17 @@ open class Icon(icon: String) : Tag(TAG.SPAN) { icon.split(" ").forEach { cl.add(it to true) } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.icon( - icon: String, init: (Icon.() -> Unit)? = null - ): Icon { - val i = Icon(icon).apply { init?.invoke(this) } - this.add(i) - return i - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.icon( + icon: String, init: (Icon.() -> Unit)? = null +): Icon { + val i = Icon(icon).apply { init?.invoke(this) } + this.add(i) + return i } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Iframe.kt b/src/main/kotlin/pl/treksoft/kvision/html/Iframe.kt index a3a067ba..dad33ed4 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Iframe.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Iframe.kt @@ -132,22 +132,20 @@ open class Iframe( open fun getIframeWindow(): Window { return getElementJQueryD()[0].contentWindow } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.iframe( - src: String? = null, srcdoc: String? = null, name: String? = null, iframeWidth: Int? = null, - iframeHeight: Int? = null, sandbox: Set<Sandbox>? = null, classes: Set<String> = setOf(), - init: (Iframe.() -> Unit)? = null - ): Iframe { - val iframe = - Iframe(src, srcdoc, name, iframeWidth, iframeHeight, sandbox, classes).apply { init?.invoke(this) } - this.add(iframe) - return iframe - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.iframe( + src: String? = null, srcdoc: String? = null, name: String? = null, iframeWidth: Int? = null, + iframeHeight: Int? = null, sandbox: Set<Sandbox>? = null, classes: Set<String> = setOf(), + init: (Iframe.() -> Unit)? = null +): Iframe { + val iframe = + Iframe(src, srcdoc, name, iframeWidth, iframeHeight, sandbox, classes).apply { init?.invoke(this) } + this.add(iframe) + return iframe } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt index 81873088..6496b042 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt @@ -99,20 +99,18 @@ open class Image( } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.image( - src: ResString, alt: String? = null, responsive: Boolean = false, shape: ImageShape? = null, - centered: Boolean = false, classes: Set<String> = setOf(), init: (Image.() -> Unit)? = null - ): Image { - val image = Image(src, alt, responsive, shape, centered, classes).apply { init?.invoke(this) } - this.add(image) - return image - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.image( + src: ResString, alt: String? = null, responsive: Boolean = false, shape: ImageShape? = null, + centered: Boolean = false, classes: Set<String> = setOf(), init: (Image.() -> Unit)? = null +): Image { + val image = Image(src, alt, responsive, shape, centered, classes).apply { init?.invoke(this) } + this.add(image) + return image } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt index 63104248..2c2f1723 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt @@ -83,20 +83,18 @@ open class Link( } return this } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.link( - label: String, url: String? = null, icon: String? = null, image: ResString? = null, - classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null - ): Link { - val link = Link(label, url, icon, image, classes).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.link( + label: String, url: String? = null, icon: String? = null, image: ResString? = null, + classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null +): Link { + val link = Link(label, url, icon, image, classes).apply { init?.invoke(this) } + this.add(link) + return link } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/List.kt b/src/main/kotlin/pl/treksoft/kvision/html/List.kt index cf3f8be6..1d26007c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/List.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/List.kt @@ -133,20 +133,18 @@ open class ListTag( } return cl } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.listTag( - type: ListType, elements: List<String>? = null, rich: Boolean = false, - classes: Set<String> = setOf(), init: (ListTag.() -> Unit)? = null - ): ListTag { - val listTag = ListTag(type, elements, rich, classes, init) - this.add(listTag) - return listTag - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.listTag( + type: ListType, elements: List<String>? = null, rich: Boolean = false, + classes: Set<String> = setOf(), init: (ListTag.() -> Unit)? = null +): ListTag { + val listTag = ListTag(type, elements, rich, classes, init) + this.add(listTag) + return listTag } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/P.kt b/src/main/kotlin/pl/treksoft/kvision/html/P.kt index feadc54a..d5bb2c4d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/P.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/P.kt @@ -46,23 +46,21 @@ open class P( @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.p( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (P.() -> Unit)? = null - ): P { - val p = P(content, rich, align, classes).apply { init?.invoke(this) } - this.add(p) - return p - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.p( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (P.() -> Unit)? = null +): P { + val p = P(content, rich, align, classes).apply { init?.invoke(this) } + this.add(p) + return p } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Section.kt b/src/main/kotlin/pl/treksoft/kvision/html/Section.kt index 94413943..43dd8fcf 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Section.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Section.kt @@ -46,23 +46,21 @@ open class Section( @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.section( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (Section.() -> Unit)? = null - ): Section { - val section = Section(content, rich, align, classes).apply { init?.invoke(this) } - this.add(section) - return section - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.section( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (Section.() -> Unit)? = null +): Section { + val section = Section(content, rich, align, classes).apply { init?.invoke(this) } + this.add(section) + return section } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Span.kt b/src/main/kotlin/pl/treksoft/kvision/html/Span.kt index bc5e93cd..862d0b2f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Span.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Span.kt @@ -46,23 +46,21 @@ open class Span( @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.span( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), - init: (Span.() -> Unit)? = null - ): Span { - val span = Span(content, rich, align, classes).apply { init?.invoke(this) } - this.add(span) - return span - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.span( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), + init: (Span.() -> Unit)? = null +): Span { + val span = Span(content, rich, align, classes).apply { init?.invoke(this) } + this.add(span) + return span } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index a5e855ae..aefd3730 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -192,21 +192,19 @@ open class Tag( else content += translate(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.tag( - type: TAG, content: String? = null, rich: Boolean = false, align: Align? = null, - classes: Set<String> = setOf(), attributes: Map<String, String> = mapOf(), - init: (Tag.() -> Unit)? = null - ): Tag { - val tag = Tag(type, content, rich, align, classes, attributes, init) - this.add(tag) - return tag - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.tag( + type: TAG, content: String? = null, rich: Boolean = false, align: Align? = null, + classes: Set<String> = setOf(), attributes: Map<String, String> = mapOf(), + init: (Tag.() -> Unit)? = null +): Tag { + val tag = Tag(type, content, rich, align, classes, attributes, init) + this.add(tag) + return tag } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt index b871abfa..59c61637 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt @@ -197,17 +197,15 @@ open class DockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit removeAt(Side.DOWN) return this } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.dockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null): DockPanel { - val dockPanel = DockPanel(classes, init) - this.add(dockPanel) - return dockPanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.dockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null): DockPanel { + val dockPanel = DockPanel(classes, init) + this.add(dockPanel) + return dockPanel } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt index 010f7cba..436ade22 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt @@ -218,23 +218,21 @@ open class FlexPanel( } return snstyle } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.flexPanel( - direction: FlexDir? = null, wrap: FlexWrap? = null, justify: FlexJustify? = null, - alignItems: FlexAlignItems? = null, alignContent: FlexAlignContent? = null, - spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null - ): FlexPanel { - val flexPanel = FlexPanel(direction, wrap, justify, alignItems, alignContent, spacing, classes, init) - this.add(flexPanel) - return flexPanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.flexPanel( + direction: FlexDir? = null, wrap: FlexWrap? = null, justify: FlexJustify? = null, + alignItems: FlexAlignItems? = null, alignContent: FlexAlignContent? = null, + spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null +): FlexPanel { + val flexPanel = FlexPanel(direction, wrap, justify, alignItems, alignContent, spacing, classes, init) + this.add(flexPanel) + return flexPanel } /** diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt index 1f5efbb4..1598753b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt @@ -255,28 +255,26 @@ open class GridPanel( } return snstyle } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.gridPanel( - autoColumns: String? = null, autoRows: String? = null, autoFlow: GridFlow? = null, - templateColumns: String? = null, templateRows: String? = null, templateAreas: List<String>? = null, - columnGap: Int? = null, rowGap: Int? = null, justifyItems: GridJustify? = null, - alignItems: GridAlign? = null, justifyContent: GridJustifyContent? = null, - alignContent: GridAlignContent? = null, classes: Set<String> = setOf(), init: (GridPanel.() -> Unit)? = null - ): GridPanel { - val gridPanel = GridPanel( - autoColumns, autoRows, autoFlow, templateColumns, templateRows, templateAreas, - columnGap, rowGap, justifyItems, alignItems, justifyContent, alignContent, classes, init - ) - this.add(gridPanel) - return gridPanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.gridPanel( + autoColumns: String? = null, autoRows: String? = null, autoFlow: GridFlow? = null, + templateColumns: String? = null, templateRows: String? = null, templateAreas: List<String>? = null, + columnGap: Int? = null, rowGap: Int? = null, justifyItems: GridJustify? = null, + alignItems: GridAlign? = null, justifyContent: GridJustifyContent? = null, + alignContent: GridAlignContent? = null, classes: Set<String> = setOf(), init: (GridPanel.() -> Unit)? = null +): GridPanel { + val gridPanel = GridPanel( + autoColumns, autoRows, autoFlow, templateColumns, templateRows, templateAreas, + columnGap, rowGap, justifyItems, alignItems, justifyContent, alignContent, classes, init + ) + this.add(gridPanel) + return gridPanel } class GridWrapper( diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt index 0700e88a..ccc77b0f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt @@ -47,24 +47,22 @@ open class HPanel( @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.hPanel( - wrap: FlexWrap? = null, - justify: FlexJustify? = null, - alignItems: FlexAlignItems? = null, - spacing: Int? = null, - classes: Set<String> = setOf(), - init: (HPanel.() -> Unit)? = null - ): HPanel { - val hpanel = HPanel(wrap, justify, alignItems, spacing, classes, init) - this.add(hpanel) - return hpanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.hPanel( + wrap: FlexWrap? = null, + justify: FlexJustify? = null, + alignItems: FlexAlignItems? = null, + spacing: Int? = null, + classes: Set<String> = setOf(), + init: (HPanel.() -> Unit)? = null +): HPanel { + val hpanel = HPanel(wrap, justify, alignItems, spacing, classes, init) + this.add(hpanel) + return hpanel } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt index 7d06428a..111d4738 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt @@ -211,30 +211,29 @@ class Root : SimplePanel { fun removeModal(modal: Widget) { modals.remove(modal) } + } +} - /** - * Create new Root container based on ID - * @param id ID attribute of element in the main HTML file - * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class, - * otherwise it's rendered with "container" class (default is false) - * @param init an initializer extension function - * @return the created Root container - */ - fun Application.root(id: String, fixed: Boolean = false, init: Root.() -> Unit): Root { - return Root(id, fixed, init) - } - - /** - * Create new Root container based on HTML element - * @param element HTML element in the DOM tree - * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class, - * otherwise it's rendered with "container" class (default is false) - * @param init an initializer extension function - * @return the created Root container - */ - fun Application.root(element: HTMLElement, fixed: Boolean = false, init: Root.() -> Unit): Root { - return Root(element, fixed, init) - } +/** + * Create new Root container based on ID + * @param id ID attribute of element in the main HTML file + * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class, + * otherwise it's rendered with "container" class (default is false) + * @param init an initializer extension function + * @return the created Root container + */ +fun Application.root(id: String, fixed: Boolean = false, init: Root.() -> Unit): Root { + return Root(id, fixed, init) +} - } +/** + * Create new Root container based on HTML element + * @param element HTML element in the DOM tree + * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class, + * otherwise it's rendered with "container" class (default is false) + * @param init an initializer extension function + * @return the created Root container + */ +fun Application.root(element: HTMLElement, fixed: Boolean = false, init: Root.() -> Unit): Root { + return Root(element, fixed, init) } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt index 91eeda80..915fa6a7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt @@ -101,17 +101,15 @@ open class SimplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> 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.simplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null): SimplePanel { - val simplePanel = SimplePanel(classes, init) - this.add(simplePanel) - return simplePanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.simplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null): SimplePanel { + val simplePanel = SimplePanel(classes, init) + this.add(simplePanel) + return simplePanel } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index 8b46ae0b..c7f4b3ac 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -98,22 +98,20 @@ open class SplitPanel( arrayOf() } } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.splitPanel( - direction: Direction = Direction.VERTICAL, - classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null - ): SplitPanel { - val splitPanel = SplitPanel(direction, classes, init) - this.add(splitPanel) - return splitPanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.splitPanel( + direction: Direction = Direction.VERTICAL, + classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null +): SplitPanel { + val splitPanel = SplitPanel(direction, classes, init) + this.add(splitPanel) + return splitPanel } internal class Splitter(private val splitPanel: SplitPanel, direction: Direction) : Tag( diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt index 37dd449b..26bfcb8c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt @@ -118,18 +118,18 @@ open class StackPanel( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.stackPanel( - activateLast: Boolean = true, classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null - ): StackPanel { - val stackPanel = StackPanel(activateLast, classes, init) - this.add(stackPanel) - return stackPanel - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.stackPanel( + activateLast: Boolean = true, classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null +): StackPanel { + val stackPanel = StackPanel(activateLast, classes, init) + this.add(stackPanel) + return stackPanel +} diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt index eb9c138e..e5d275d4 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt @@ -46,20 +46,18 @@ open class VPanel( @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.vPanel( - justify: FlexJustify? = null, alignItems: FlexAlignItems? = null, spacing: Int? = null, - classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null - ): VPanel { - val vpanel = VPanel(justify, alignItems, spacing, classes, init) - this.add(vpanel) - return vpanel - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.vPanel( + justify: FlexJustify? = null, alignItems: FlexAlignItems? = null, spacing: Int? = null, + classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null +): VPanel { + val vpanel = VPanel(justify, alignItems, spacing, classes, init) + this.add(vpanel) + return vpanel } diff --git a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt index adb7d3be..20cb2d8e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt +++ b/src/main/kotlin/pl/treksoft/kvision/state/StateBinding.kt @@ -49,7 +49,7 @@ class StateBinding<S : Any, CONT : Container, CONTENT>( } } - private fun setUpdateState(updateState: (S, CONTENT) -> Unit) { + internal fun setUpdateState(updateState: (S, CONTENT) -> Unit) { this.updateState = updateState } @@ -57,32 +57,30 @@ class StateBinding<S : Any, CONT : Container, CONTENT>( unsubscribe() super.dispose() } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <S : Any, CONT : Container> CONT.stateBinding( - observableState: ObservableState<S>, - factory: (CONT.(S) -> Unit) - ): StateBinding<S, CONT, Unit> { - return StateBinding(observableState, this, factory) - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun <S : Any, CONT : Container> CONT.stateBinding( + observableState: ObservableState<S>, + factory: (CONT.(S) -> Unit) +): StateBinding<S, CONT, Unit> { + return StateBinding(observableState, this, factory) +} - /** - * DSL builder extension function for updateable redux content. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <S : Any, CONT : Container, CONTENT> CONT.stateUpdate( - observableState: ObservableState<S>, - factory: (CONT.(S) -> CONTENT) - ): Updateable<S, CONTENT> { - return Updateable(StateBinding(observableState, this, factory)::setUpdateState) - } - } +/** + * DSL builder extension function for updateable redux content. + * + * It takes the same parameters as the constructor of the built component. + */ +fun <S : Any, CONT : Container, CONTENT> CONT.stateUpdate( + observableState: ObservableState<S>, + factory: (CONT.(S) -> CONTENT) +): Updateable<S, CONTENT> { + return Updateable(StateBinding(observableState, this, factory)::setUpdateState) } /** diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt index 44646897..4cf72f77 100644 --- a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt +++ b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt @@ -47,39 +47,36 @@ open class Cell( @Suppress("LeakingThis") init?.invoke(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Row.cell( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), init: (Cell.() -> Unit)? = null - ): Cell { - val cell = Cell(content, rich, align, classes, init) - this.add(cell) - return cell - } - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Row.thcell( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null - ): HeaderCell { - val headerCell = HeaderCell(content, rich, align, Scope.ROW, classes, init) - this.add(headerCell) - return headerCell - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Row.cell( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), init: (Cell.() -> Unit)? = null +): Cell { + val cell = Cell(content, rich, align, classes, init) + this.add(cell) + return cell +} +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Row.thcell( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null +): HeaderCell { + val headerCell = HeaderCell(content, rich, align, Scope.ROW, classes, init) + this.add(headerCell) + return headerCell } diff --git a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt index 14527f0f..f7f45784 100644 --- a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt +++ b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt @@ -57,24 +57,21 @@ open class HeaderCell( @Suppress("LeakingThis") init?.invoke(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Row.headerCell( - content: String? = null, - rich: Boolean = false, - align: Align? = null, - scope: Scope? = null, - classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null - ): HeaderCell { - val cell = HeaderCell(content, rich, align, scope, classes, init) - this.add(cell) - return cell - } - } - +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Row.headerCell( + content: String? = null, + rich: Boolean = false, + align: Align? = null, + scope: Scope? = null, + classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null +): HeaderCell { + val cell = HeaderCell(content, rich, align, scope, classes, init) + this.add(cell) + return cell } diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Row.kt b/src/main/kotlin/pl/treksoft/kvision/table/Row.kt index 34ce3471..0681953f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/table/Row.kt +++ b/src/main/kotlin/pl/treksoft/kvision/table/Row.kt @@ -34,25 +34,21 @@ import pl.treksoft.kvision.html.Tag open class Row(classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null) : Tag( TAG.TR, classes = classes ) { - init { @Suppress("LeakingThis") init?.invoke(this) } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Table.row( - classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null - ): Row { - val row = Row(classes, init) - this.add(row) - return row - } - } - +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Table.row( + classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null +): Row { + val row = Row(classes, init) + this.add(row) + return row } diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt index 6d7c9b6e..114e3dfa 100644 --- a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt +++ b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt @@ -200,22 +200,20 @@ open class Table( override fun getChildren(): List<Component> { return tbody.getChildren() } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.table( - headerNames: List<String>? = null, - types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null, - theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null - ): Table { - val table = - Table(headerNames, types, caption, responsiveType, theadType, classes, init) - this.add(table) - return table - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.table( + headerNames: List<String>? = null, + types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null, + theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null +): Table { + val table = + Table(headerNames, types, caption, responsiveType, theadType, classes, init) + this.add(table) + return table } diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/StyleSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/StyleSpec.kt index 4fbe3d59..cf7c21b2 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/core/StyleSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/core/StyleSpec.kt @@ -24,8 +24,8 @@ package test.pl.treksoft.kvision.core import pl.treksoft.kvision.core.Col import pl.treksoft.kvision.core.Color import pl.treksoft.kvision.core.Overflow -import pl.treksoft.kvision.core.Style.Companion.style -import pl.treksoft.kvision.core.Widget.Companion.widget +import pl.treksoft.kvision.core.style +import pl.treksoft.kvision.core.widget import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.utils.px import test.pl.treksoft.kvision.DomSpec diff --git a/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt index f5416748..c0de7c6f 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt @@ -21,12 +21,12 @@ */ package test.pl.treksoft.kvision.state -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.state.observableListOf +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/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt index d9a6fdfa..8f80f465 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt @@ -22,8 +22,8 @@ package test.pl.treksoft.kvision.table import pl.treksoft.kvision.panel.Root -import pl.treksoft.kvision.table.Cell.Companion.cell import pl.treksoft.kvision.table.Row +import pl.treksoft.kvision.table.cell import test.pl.treksoft.kvision.DomSpec import kotlin.browser.document import kotlin.test.Test diff --git a/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt index 69dc05d3..e81e539d 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt @@ -22,11 +22,11 @@ package test.pl.treksoft.kvision.table import pl.treksoft.kvision.panel.Root -import pl.treksoft.kvision.table.Cell.Companion.cell import pl.treksoft.kvision.table.ResponsiveType -import pl.treksoft.kvision.table.Row.Companion.row import pl.treksoft.kvision.table.Table import pl.treksoft.kvision.table.TableType +import pl.treksoft.kvision.table.cell +import pl.treksoft.kvision.table.row import test.pl.treksoft.kvision.DomSpec import kotlin.browser.document import kotlin.test.Test |