hightable
Version:
A dynamic windowed scrolling table component for react
126 lines (125 loc) • 4.9 kB
TypeScript
import { DataFrame } from './dataframe.js';
import { OrderBy } from './sort.js';
/**
* A selection is modelled as an array of ordered and non-overlapping ranges.
* The ranges are separated, ie. the end of one range is strictly less than the start of the next range.
*/
interface Range {
start: number;
end: number;
}
export type Ranges = Range[];
export interface Selection {
ranges: Ranges;
anchor?: number;
}
export declare function isValidIndex(index: number): boolean;
export declare function isValidRange(range: Range): boolean;
export declare function areValidRanges(ranges: Ranges): boolean;
export declare function isSelected({ ranges, index }: {
ranges: Ranges;
index: number;
}): boolean;
export declare function areAllSelected({ ranges, length }: {
ranges: Ranges;
length: number;
}): boolean;
export declare function toggleAll({ ranges, length }: {
ranges: Ranges;
length: number;
}): Ranges;
export declare function selectRange({ ranges, range }: {
ranges: Ranges;
range: Range;
}): Ranges;
export declare function selectIndex({ ranges, index }: {
ranges: Ranges;
index: number;
}): Ranges;
export declare function unselectRange({ ranges, range }: {
ranges: Ranges;
range: Range;
}): Ranges;
/**
* Extend selection state from anchor to index (selecting or unselecting the range).
* Both bounds are inclusive.
* It will handle the shift+click behavior. anchor is the first index clicked, index is the last index clicked.
*/
export declare function extendFromAnchor({ ranges, anchor, index }: {
ranges: Ranges;
anchor?: number;
index: number;
}): Ranges;
export declare function toggleIndex({ ranges, index }: {
ranges: Ranges;
index: number;
}): Ranges;
export declare function toggleIndexInSelection({ selection, index }: {
selection: Selection;
index: number;
}): Selection;
export declare function toggleRangeInSelection({ selection, index }: {
selection: Selection;
index: number;
}): Selection;
/**
* Compute the table indexes from the data indexes.
*
* @param {number[]} permutationIndexes - The data frame index of each row of the sorted table (dataIndexes[tableIndex] = dataIndex).
*
* @returns {number[]} The index of each row in the sorted table (tableIndexes[dataIndex] = tableIndex).
*/
export declare function invertPermutationIndexes(permutationIndexes: number[]): number[];
/**
* Get an element from an array, or raise if it's outside of the range.
*
* @param {Object} params
* @param {number} params.index - The index of the element.
* @param {T[]} params.array - The array of elements (array[index] = element).
*
* @returns {T} The element.
*/
export declare function getElement<T>({ index, array }: {
index: number;
array: T[];
}): T;
/**
* Convert a selection between two domains, using a permutation array.
*
* @param {Object} params
* @param {Selection} params.selection - A selection of indexes.
* @param {number[]} params.permutationIndexes - An array that maps every index to another index (permutationIndexes[index] = permutedIndex).
*
* @returns {Selection} A selection of permuted indexes.
*/
export declare function convertSelection({ selection, permutationIndexes }: {
selection: Selection;
permutationIndexes: number[];
}): Selection;
/**
* Compute the new selection state after a shift-click (range toggle) on the row with the given table index
* when the rows are sorted.
*
* The selection is extended from the anchor to the index. This
* range is done in the visual space of the user, ie: between the rows as they appear in the table.
* As the rows are sorted, the indexes are converted from data domain to table domain and vice versa,
* which requires the sort index of the data frame. If not available, it must be computed, which is
* an async operation that can be expensive.
*
* @param {Object} params
* @param {number} params.tableIndex - The index of the row in the table (table domain, sorted row indexes).
* @param {Selection} params.selection - The current selection state (data domain, row indexes).
* @param {OrderBy} params.orderBy - The order if the rows are sorted.
* @param {DataFrame} params.data - The data frame.
* @param {Map<string,number[]>} params.ranks - The map of ranks for each column of the data frame (they can be missing, if so thay will be populated in this function).
* @param {function} params.setColumnRanks - A function to update the map of column ranks.
*/
export declare function toggleRangeInTable({ tableIndex, selection, orderBy, data, ranksMap, setRanksMap, }: {
tableIndex: number;
selection: Selection;
orderBy: OrderBy;
data: DataFrame;
ranksMap: Map<string, Promise<number[]>>;
setRanksMap: (setter: (ranksMap: Map<string, Promise<number[]>>) => Map<string, Promise<number[]>>) => void;
}): Promise<Selection>;
export {};