1 | import { IObjectWithKey, ISelection, SelectionMode } from './Selection.types';
|
2 |
|
3 |
|
4 |
|
5 | export interface ISelectionOptions<TItem = IObjectWithKey> {
|
6 | onSelectionChanged?: () => void;
|
7 | onItemsChanged?: () => void;
|
8 |
|
9 | getKey?: (item: TItem, index?: number) => string | number;
|
10 | canSelectItem?: (item: TItem, index?: number) => boolean;
|
11 | selectionMode?: SelectionMode;
|
12 | items?: TItem[];
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare type ISelectionOptionsWithRequiredGetKey<TItem> = ISelectionOptions<TItem> & Required<Pick<ISelectionOptions<TItem>, 'getKey'>>;
|
19 |
|
20 |
|
21 |
|
22 | export declare class Selection<TItem = IObjectWithKey> implements ISelection<TItem> {
|
23 |
|
24 | count: number;
|
25 | readonly mode: SelectionMode;
|
26 | private _getKey;
|
27 | private _canSelectItem;
|
28 | private _changeEventSuppressionCount;
|
29 | private _items;
|
30 | private _selectedItems;
|
31 | private _selectedIndices;
|
32 | private _isAllSelected;
|
33 | private _exemptedIndices;
|
34 | private _exemptedCount;
|
35 | private _keyToIndexMap;
|
36 | private _anchoredIndex;
|
37 | private _onSelectionChanged;
|
38 | private _onItemsChanged;
|
39 | private _hasChanged;
|
40 | private _unselectableIndices;
|
41 | private _unselectableCount;
|
42 | private _isModal;
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | constructor(...options: TItem extends IObjectWithKey ? [] | [ISelectionOptions<TItem>] : [ISelectionOptionsWithRequiredGetKey<TItem>]);
|
49 | canSelectItem(item: TItem, index?: number): boolean;
|
50 | getKey(item: TItem, index?: number): string;
|
51 | setChangeEvents(isEnabled: boolean, suppressChange?: boolean): void;
|
52 | isModal(): boolean;
|
53 | setModal(isModal: boolean): void;
|
54 | /**
|
55 | * Selection needs the items, call this method to set them. If the set
|
56 | * of items is the same, this will re-evaluate selection and index maps.
|
57 | * Otherwise, shouldClear should be set to true, so that selection is
|
58 | * cleared.
|
59 | */
|
60 | setItems(items: TItem[], shouldClear?: boolean): void;
|
61 | getItems(): TItem[];
|
62 | getSelection(): TItem[];
|
63 | getSelectedCount(): number;
|
64 | getSelectedIndices(): number[];
|
65 | getItemIndex(key: string): number;
|
66 | isRangeSelected(fromIndex: number, count: number): boolean;
|
67 | isAllSelected(): boolean;
|
68 | isKeySelected(key: string): boolean;
|
69 | isIndexSelected(index: number): boolean;
|
70 | setAllSelected(isAllSelected: boolean): void;
|
71 | setKeySelected(key: string, isSelected: boolean, shouldAnchor: boolean): void;
|
72 | setIndexSelected(index: number, isSelected: boolean, shouldAnchor: boolean): void;
|
73 | setRangeSelected(fromIndex: number, count: number, isSelected: boolean, shouldAnchor: boolean): void;
|
74 | selectToKey(key: string, clearSelection?: boolean): void;
|
75 | selectToRange(fromIndex: number, count: number, clearSelection?: boolean): void;
|
76 | selectToIndex(index: number, clearSelection?: boolean): void;
|
77 | toggleAllSelected(): void;
|
78 | toggleKeySelected(key: string): void;
|
79 | toggleIndexSelected(index: number): void;
|
80 | toggleRangeSelected(fromIndex: number, count: number): void;
|
81 | private _updateCount;
|
82 | private _setAllSelected;
|
83 | private _change;
|
84 | }
|