/** * Manages the selection of records. */ export default class Selection { private readonly onSelect; private readonly onUnselect; /** * The range of selected records. */ private range; /** * The actual selected records. */ private records; constructor(onSelect?: (index: number) => void, onUnselect?: (index: number) => void); /** * Marks the record as selected. * @param index The index of the record. */ select(index: number): void; /** * Un-marks the record as selected. * @param index The index of the record. */ unselect(index: number): void; /** * Resets the selection to an empty state. * * This will unselect all records and reset the range. */ reset(): void; /** * Resets the range of selected records, by unselecting all records in the range * and selecting the first one. */ reopenRange(): void; /** * Returns true if the record is selected. * @param index The index of the record. * @returns boolean */ has(index: number): boolean; /** * Returns all selected records. * @returns number[] The selected records. */ getAll(): number[]; /** * Returns true if no records are selected. * @returns boolean */ isEmpty(): boolean; /** * Returns true if a range is selected and is closed. * @returns boolean */ hasRange(): boolean; /** * Closes the range selection. * @param to The index of the record to close the range. */ closeRange(to: number): void; /** * Returns true if a range is initiated but not closed. */ hasOpenRange(): boolean; }