diff options
Diffstat (limited to 'kvision-modules')
35 files changed, 851 insertions, 899 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 +} |