UNPKG

@ux-aspects/ux-aspects

Version:

Open source user interface framework for building modern, responsive, mobile big data applications

101 lines (100 loc) 3.92 kB
import { OnDestroy } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { SelectionStrategy } from './strategies/selection.strategy'; import * as i0 from "@angular/core"; export declare class SelectionService<T> implements OnDestroy { /** Store the current set of selectable items and ensure an item can be focused */ set dataset(dataset: ReadonlyArray<T>); /** Get the current set of selectable items */ get dataset(): ReadonlyArray<T>; /** The active selection strategy that defines how selections can be made */ strategy: SelectionStrategy<T>; /** Define if selections can be performed on any items */ isEnabled: boolean; /** Define if the mouse can be used to perform selections */ isClickEnabled: boolean; /** Define if the keyboard can be used to perform selections */ isKeyboardEnabled: boolean; /** Define the currently focused item */ readonly focus$: BehaviorSubject<T>; /** Define the currently active item */ readonly active$: BehaviorSubject<T>; /** Store the current list of selected items as an array */ readonly selection$: BehaviorSubject<T[]>; /** Store the active item */ private _active; /** Store the current set of selectable items */ private _dataset; /** Store the selection strategy that should be destroyed */ private _strategyToDestroy; /** Store the current selection in a set */ private readonly _selection; /** Store the current disabled items in a set */ private readonly _disabled; ngOnDestroy(): void; /** * If the item is not currently selected then add it * to the list of selected items */ select(...selections: T[]): void; /** * Deselect all currently selected items and replace with a new selection */ selectOnly(...selection: T[]): void; /** * Remove an item from the list of selected items */ deselect(...selections: T[]): void; /** * Remove all items from the list of selected items */ deselectAll(): void; /** * Toggle the selected state of any specified items */ toggle(...selections: T[]): void; /** * Determine whether or not a specific item is currently selected */ isSelected(data: T): boolean; /** * Return an observable specifically for notifying the subscriber * only when the selection state of a specific object has changed */ getSelectionState(data: T): Observable<boolean>; /** * Define how selections should be performed. * This allows us to use an strategy pattern to handle the various keyboard * and mouse interactions while keeping each mode separated and * easily extensible if we want to add more modes in future! */ setStrategy(mode: SelectionMode | SelectionStrategy<T>): void; /** * Set the current active item */ activate(data: T): void; /** * Deactive all items */ deactivate(): void; /** * Return the next or previous sibling of the current active item. * @param previous If true, the previous sibling will be returned. */ getSibling(previous?: boolean): T; /** * Activate the sibling of the current active item. * If previous is set to true the previous sibling will be activated * rather than the next sibling. This function will also return the * data of the newly activated sibling */ activateSibling(previous?: boolean): T; setDisabled(disabled: boolean): void; /** Store the disabled state of an item */ setItemDisabled(item: T, isDisabled: boolean): void; private selectionHasMutated; private setFirstItemFocusable; static ɵfac: i0.ɵɵFactoryDeclaration<SelectionService<any>, never>; static ɵprov: i0.ɵɵInjectableDeclaration<SelectionService<any>>; } export type SelectionMode = 'simple' | 'row' | 'row-alt';