All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.symphony.GroupedSelectorBasedActionsBuilder.kt Maven / Gradle / Ivy

Go to download

A kotlin multiplatform library for representing headless collection based ui such as lists, tables and grids

The newest version!
@file:Suppress("NOTHING_TO_INLINE")

package symphony

import kevlar.Action0
import kevlar.builders.Actions0Builder
import symphony.selected.GroupedSelected
import symphony.selected.GroupedSelectedGlobal
import symphony.selected.GroupedSelectedItem
import symphony.selected.GroupedSelectedItems
import symphony.selected.GroupedSelectedNone
import kollections.MutableList
import kollections.MutableSet
import kollections.add
import kollections.component1
import kollections.component2
import kollections.addAll
import kollections.buildList
import kollections.entries
import kollections.flatMap
import kollections.forEach
import kollections.map
import kollections.mutableListOf
import kollections.mutableSetOf
import kollections.toList

class GroupedSelectorBasedActionsBuilder @PublishedApi internal constructor(
    primary: MutableList> = mutableListOf(),
    single: MutableList> = mutableListOf(),
    multi: MutableList> = mutableListOf(),
    global: MutableList> = mutableListOf(),
    filters: MutableSet = mutableSetOf()
) : AbstractSelectorBasedActionsBuilder>(primary, single, multi, global, filters) {


    @PublishedApi
    internal val globalActionsContainer = mutableListOf.(GroupedSelectedGlobal) -> Unit>()

    inline fun global(noinline builder: Actions0Builder.(GroupedSelectedGlobal) -> Unit) {
        globalActionsContainer.add(builder)
    }

    fun buildGlobalSelectActions(state: GroupedSelectedGlobal) = globalActions.apply {
        globalActionsContainer.forEach { builder -> builder(state) }
    }.actions.applyFilters()

    override fun buildActions(selected: GroupedSelected) = buildList> {
        addAll(buildPrimaryActions())
        when (selected) {
            is GroupedSelectedNone -> {}
            is GroupedSelectedItem -> addAll(buildSingleSelectActions(selected.row.item))
            is GroupedSelectedItems -> addAll(buildMultiSelectActions(selected.page.entries.flatMap { (_, v) -> v }.map { it.item }.toList()))
            is GroupedSelectedGlobal -> addAll(buildGlobalSelectActions(selected))
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy