UNPKG

@blueprintjs/table

Version:

Scalable interactive table component

144 lines (143 loc) 6.78 kB
export declare const CLASSNAME_EXCLUDED_FROM_TEXT_MEASUREMENT = "bp-table-text-no-measure"; export interface KeyAllowlist<T> { include: Array<keyof T>; } export interface KeyDenylist<T> { exclude: Array<keyof T>; } export declare const Utils: { /** * Invokes the callback `n` times, collecting the results in an array, which * is the return value. Similar to _.times */ times<T>(n: number, callback: (i: number) => T): T[]; /** * Takes an array of numbers, returns an array of numbers of the same length in which each * value is the sum of current and previous values in the input array. * * Example input: [10, 20, 50] * output: [10, 30, 80] */ accumulate(numbers: number[]): number[]; /** * Returns traditional spreadsheet-style column names * e.g. (A, B, ..., Z, AA, AB, ..., ZZ, AAA, AAB, ...). * * Note that this isn't technically mathematically equivalent to base 26 since * there is no zero element. */ toBase26Alpha: (num: number) => string; /** * Returns traditional spreadsheet-style cell names * e.g. (A1, B2, ..., Z44, AA1) with rows 1-indexed. */ toBase26CellName: (rowIndex: number, columnIndex: number) => string; /** * Performs the binary search algorithm to find the index of the `value` * parameter in a sorted list of numbers. If `value` is not in the list, the * index where `value` can be inserted to maintain the sort is returned. * * Unlike a typical binary search implementation, we use a `lookup` * callback to access the sorted list of numbers instead of an array. This * avoids additional storage overhead. * * We use this to, for example, find the index of a row/col given its client * coordinate. * * Adapted from lodash https://github.com/lodash/lodash/blob/4.11.2/lodash.js#L3579 * * @param value - the query value * @param high - the length of the sorted list of numbers * @param lookup - returns the number from the list at the supplied index */ binarySearch(value: number, high: number, lookup: (index: number) => number): number; /** * Takes in one full array of values and one sparse array of the same * length and type. Returns a copy of the `defaults` array, where each * value is replaced with the corresponding non-null value at the same * index in `sparseOverrides`. * * @param defaults - the full array of default values * @param sparseOverrides - the sparse array of override values */ assignSparseValues<T_1>(defaults: T_1[], sparseOverrides: (T_1 | null | undefined)[]): T_1[]; /** * Measures the bounds of supplied element's textContent. * We use the computed font from the supplied element and a non-DOM canvas * context to measure the text. */ measureElementTextContent(element: Element): TextMetrics; /** * Given a number, returns a value that is clamped within a * minimum/maximum bounded range. The minimum and maximum are optional. If * either is missing, that extrema limit is not applied. * * Assumes max >= min. */ clamp(value: number, min?: number, max?: number): number; /** * When reordering a contiguous block of rows or columns to a new index, we show a preview guide * at the absolute index in the original ordering but emit the new index in the reordered list. * This function converts an absolute "guide" index to a relative "reordered" index. * * Example: Say we want to move the first three columns two spots to the right. While we drag, a * vertical guide is shown to preview where we'll be dropping the columns. (In the following * ASCII art, `*` denotes a selected column, `·` denotes a cell border, and `|` denotes a * vertical guide). * * Before mousedown: * · 0 · 1 · 2 · 3 · 4 · 5 · * * * * * * During mousemove two spots to the right: * · 0 · 1 · 2 · 3 · 4 | 5 · * * * * * * After mouseup: * · 3 · 4 · 0 · 1 · 2 · 5 · * * * * * * Note that moving the three columns beyond index 4 effectively moves them two spots rightward. * * In this case, the inputs to this function would be: * - oldIndex: 0 (the left-most index of the selected column range in the original ordering) * - newIndex: 5 (the index on whose left boundary the guide appears in the original ordering) * - length: 3 (the number of columns to move) * * The return value will then be 2, the left-most index of the columns in the new ordering. */ guideIndexToReorderedIndex(oldIndex: number, newIndex: number, length: number): number; /** * When reordering a contiguous block of rows or columns to a new index, we show a preview guide * at the absolute index in the original ordering but emit the new index in the reordered list. * This function converts a relative "reordered"" index to an absolute "guide" index. * * For the scenario in the example above, the inputs to this function would be: * - oldIndex: 0 (the left-most index of the selected column range in the original ordering) * - newIndex: 2 (the left-most index of the selected column range in the new ordering) * - length: 3 (the number of columns to move) * * The return value will then be 5, the index on whose left boundary the guide should appear in * the original ordering. */ reorderedIndexToGuideIndex(oldIndex: number, newIndex: number, length: number): number; /** * Returns a copy of the provided array with the `length` contiguous elements starting at the * `from` index reordered to start at the `to` index. * * For example, given the array [A,B,C,D,E,F], reordering the 3 contiguous elements starting at * index 1 (B, C, and D) to start at index 2 would yield [A,E,B,C,D,F]. */ reorderArray<T_2>(array: T_2[], from: number, to: number, length?: number): T_2[] | undefined; /** * Returns true if the mouse event was triggered by the left mouse button. */ isLeftClick(event: MouseEvent): boolean; getApproxCellHeight(cellText: string, columnWidth: number, approxCharWidth: number, approxLineHeight: number, horizontalPadding: number, numBufferLines: number): number; /** * Shallow comparison of potentially sparse arrays. * * @returns true if the array values are equal */ compareSparseArrays(a: Array<number | null | undefined> | undefined, b: Array<number | null | undefined> | undefined): boolean; };