import type React from 'react'; import GridRange, { type GridRangeIndex } from './GridRange'; import { type BoxCoordinates, type Coordinate, type CoordinateMap, type VisibleIndex, type VisibleToModelMap, type ModelIndex, type ModelSizeMap, type MoveOperation, type SizeMap, type GridMetrics } from './GridMetrics'; import { type GridTheme } from './GridTheme'; import { type GridWheelEvent } from './GridMouseHandler'; import { type AxisRange, type BoundedAxisRange, type Range } from './GridAxisRange'; import { type GridRenderState } from './GridRendererTypes'; import type GridModel from './GridModel'; export type GridPoint = { x: Coordinate; y: Coordinate; column: GridRangeIndex; row: GridRangeIndex; columnHeaderDepth?: number; }; export interface CellInfo { row: VisibleIndex | null; column: VisibleIndex | null; modelRow: ModelIndex | null; modelColumn: ModelIndex | null; left: Coordinate | null; top: Coordinate | null; columnWidth: number | null; rowHeight: number | null; } export type Token = { value: string; type: string; start: number; end: number; isLink?: boolean; }; export type LinkToken = Token & { href: string; }; export type URLToken = Token & { type: 'url'; }; export type EmailToken = Token & { type: 'email'; }; export declare function isLinkToken(token: Token): token is LinkToken; export type TokenBox = BoxCoordinates & { token: Token; }; export type IndexCallback = (itemIndex: VisibleIndex) => T | undefined; export declare class GridUtils { static PIXELS_PER_LINE: number; /** * Get the GridPoint for the coordinates provided * @param x The grid x coordinate * @param y The grid y coordinate * @param metrics The grid metrics * @returns The GridPoint including the column/row information */ static getGridPointFromXY(x: Coordinate, y: Coordinate, metrics: GridMetrics): GridPoint; static getCellInfoFromXY(x: Coordinate, y: Coordinate, metrics: GridMetrics): CellInfo; static getColumnHeaderDepthAtY(y: Coordinate, metrics: GridMetrics): number | undefined; /** * Iterate through each floating item at the start and call a callback, returning the first result * @param start The count of floating items at the start * @param total The total number of items * @param callback Function to call for each item * @returns The result from the callback */ static iterateFloatingStart(start: number, total: number, callback: IndexCallback): T | undefined; /** * Iterate through floating items at the end. Iterates in increasing order. * @param end The count of floating items at the end * @param total The total number of items * @param callback Function to call for each item * @returns The result from the callback */ static iterateFloatingEnd(end: number, total: number, callback: IndexCallback): T | undefined; /** * Iterate through all floating items in increasing order, starting with the top items. * @param start Count of start floating rows, e.g. floatingTopRowCount * @param end Count of end floating rows, e.g. floatingBottomRowCount * @param total Total number of items * @param callback Callback called for each value, stopping the iterating and returning the value if one is returned */ static iterateFloating(start: number, end: number, total: number, callback: IndexCallback): T | undefined; /** * Iterate through all items in one dimension on the grid - first floating, then visible. * Call the callback for each item, break if a result is returned and return that result. * @param visibleStart Index of the start of the visible viewport * @param visibleEnd Index of the end of the visible viewport * @param floatingStartCount Number of items floating at the start * @param floatingEndCount Number of items floating at the end * @param totalCount Total number of items * @param callback Callback to call for each item * @returns The first result from the callback called, or undefined */ static iterateAllItems(visibleStart: VisibleIndex, visibleEnd: VisibleIndex, floatingStartCount: number, floatingEndCount: number, totalCount: number, callback: IndexCallback): T | undefined; /** * Check if the coordinate is within the item specified in this dimension * @param itemIndex Index of the item to check * @param itemCoordinatess Coordinate of all items in this dimension * @param itemSizes Size of all items in this dimension * @param coordinate The coordinate to check * @returns True if the coordinate is within the item specified, false otherwise */ static isInItem(itemIndex: VisibleIndex, itemCoordinates: CoordinateMap, itemSizes: SizeMap, coordinate: Coordinate): boolean; /** * Get the Index of the item at the provided offset * @param offset Coordinate of the offset to get the item of * @param itemCount The total count of items * @param floatingStart Count of floating items at the start * @param floatingEnd Count of floating items at the end * @param items Index of all items * @param itemCoordinates The coordinate of each item * @param itemSizes The size of each item * @returns The item index, or null if no item matches */ static getItemAtOffset(offset: Coordinate, itemCount: number, floatingStart: number, floatingEnd: number, items: readonly VisibleIndex[], itemCoordinates: CoordinateMap, itemSizes: SizeMap, ignoreFloating?: boolean): VisibleIndex | null; /** * Get the index of the column at the specified x coordinate * @param x Coordinate to get the item of * @param metrics Grid metrics * @returns Index of the column at that coordinate, or null if no column matches */ static getColumnAtX(x: Coordinate, metrics: GridMetrics, ignoreFloating?: boolean): VisibleIndex | null; /** * Get the index of the row at the specified y coordinate * @param y Coordinate to get the item of * @param metrics Grid metrics * @returns Index of the row at that coordinate, or null if no row matches */ static getRowAtY(y: Coordinate, metrics: GridMetrics): VisibleIndex | null; /** * Iterate backward through the visible items until a shown item is hit * @param startIndex The index to start from * @param modelIndexes The mapping of model indexes * @param visibleItems The visible items * @param userSizes The user set sizes * @returns Index of the next visible item, or null if no more are visible */ static getNextShownItem(startIndex: VisibleIndex, modelIndexes: VisibleToModelMap, visibleItems: readonly VisibleIndex[], userSizes: ModelSizeMap): VisibleIndex | null; /** * Iterate backward through the visible columns until a shown column is hit * @param columnIndex The column index to start iterating backward from * @param metrics The GridMetricCalculator metrics * @returns Index of the next visible item, or null if no more are visible */ static getNextShownColumn(startIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex | null; /** * Iterate backward through the visible rows until a shown row is hit * @param rowIndex The row index to start iterating backward from * @param metrics The GridMetricCalculator metrics * @returns Index of the next visible item, or null if no more are visible */ static getNextShownRow(startIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex | null; /** * Determine whether two adjacent columns belong to the same column-header group * at the given depth. * * - When the model exposes group instances via `getColumnHeaderGroup`, identity * decides: two distinct group instances that happen to share a display name * (e.g. pivot Totals groups) are treated as different groups. * - When only one side has a declared group, they are different groups. * - When neither side has a declared group, fall back to header-text equality so * plain grouped-header models (which express grouping only through repeated * text) keep their existing behavior. * * @param model The grid model * @param depth The header depth to check at * @param columnIndex The first model column index * @param otherColumnIndex The second model column index * @returns true if both columns are part of the same group at this depth */ static isSameColumnGroupAtDepth(model: GridModel, depth: number, columnIndex: ModelIndex, otherColumnIndex: ModelIndex): boolean; /** * Check if a separator exists between the column at `visibleIndex` and the * column immediately after it at a given header depth. * * - At leaf depth (0), every model column has a separator on its trailing edge. * - At deeper depths, separator existence follows column-header-group identity * (see {@link isSameColumnGroupAtDepth}). Distinct group instances that share a * display name (e.g. pivot Totals groups) are correctly treated as separate. * - The true trailing edge of the table (the last column) always has a separator. * * The next model column is resolved from `visibleIndex + 1` so that an off-screen * neighbor is handled correctly and is not mistaken for the table's trailing edge. * * @param model The grid model * @param depth The header depth to check at * @param visibleIndex The visible index of the current column * @param columnCount The total number of columns in the model * @param movedColumns The current column-move operations * @returns true if a separator should be shown, false otherwise */ static hasColumnSeparatorAtDepth(model: GridModel, depth: number | undefined, visibleIndex: VisibleIndex | undefined, columnCount: number, movedColumns: readonly MoveOperation[]): boolean; /** * Gets the column index if the x/y coordinates provided are close enough to the separator, otherwise null * @param x Mouse x coordinate * @param y Mouse y coordinate * @param metrics The grid metrics * @param theme The grid theme with potential user overrides * @param model The grid model * @returns Index of the column separator at the coordinates provided, or null if none match */ static getColumnSeparatorIndex(x: Coordinate, y: Coordinate, metrics: GridMetrics, theme: GridTheme, model: GridModel): VisibleIndex | null; /** * Check if the item specified is hidden * @param itemIndex Index of the item to check * @param visibleSizes Sizes of all visible items * @returns True if the item is hidden, false otherwise */ static isItemHidden(itemIndex: VisibleIndex, visibleSizes: SizeMap): boolean; /** * Check if the column specified is hidden * @param columnIndex Index of the column to check * @param metrics Grid metrics * @returns True if the column is hidden, false otherwise */ static isColumnHidden(columnIndex: VisibleIndex, metrics: GridMetrics): boolean; /** * Check if the provided row is a floating row * @param row The row index to check * @param metrics The grid metrics to check against * @returns True if it's a floating row, false otherwise */ static isFloatingRow(row: VisibleIndex, metrics: GridMetrics): boolean; /** * Check if the provided column is a floating column * @param column The column index to check * @param metrics The grid metrics to check against * @returns True if it's a floating column, false otherwise */ static isFloatingColumn(column: VisibleIndex, metrics: GridMetrics): boolean; /** * Get all the items that are hidden under the same Index * E.g. If columns are 1, 2, 3, 4, 5, and column 2, 3, 4 are hidden, and we check for item 4, the return will be [2, 3, 4] * @param itemIndex Index of the item to start at * @param visibleSizes Visible size map * @param visibleItems Visible items * @returns Array of items that are hidden */ static getHiddenItems(itemIndex: VisibleIndex, visibleSizes: SizeMap, visibleItems: readonly VisibleIndex[]): VisibleIndex[]; /** * Get all the columns that are hidden under the same Index * @param columnIndex Index of the item to start at * @param metrics Grid metrics * @returns Array of items that are hidden */ static getHiddenColumns(columnIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex[]; /** * Returns the row index if the x/y coordinates provided are close enough to the separator, otherwise null * @param x X coordinate to check * @param y Y coordinate to check * @param metrics The grid metrics * @param theme The grid theme * @returns Index of the row separator at the coordinates provided, or null if none match */ static getRowSeparatorIndex(x: Coordinate, y: Coordinate, metrics: GridMetrics, theme: GridTheme): VisibleIndex | null; /** * Check if the row specified is hidden * @param rowIndex Index of the row to check * @param metrics Grid metrics * @returns True if the row is hidden, false otherwise */ static isRowHidden(rowIndex: VisibleIndex, metrics: GridMetrics): boolean; /** * Get all the rows that are hidden under the same Index * @param rowIndex Index of the item to start at * @param metrics Grid metrics * @returns Array of items that are hidden */ static getHiddenRows(rowIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex[]; /** * Set a new order for items in the grid * @param from The visible index to move from * @param to The visible index to move the item to * @param oldMovedItems The old reordered items * @returns The new reordered items. The original array if the operation is a no-op. */ static moveItem(from: VisibleIndex, to: VisibleIndex, oldMovedItems: MoveOperation[]): MoveOperation[]; static moveItem(from: VisibleIndex, to: VisibleIndex, oldMovedItems: readonly MoveOperation[]): readonly MoveOperation[]; /** * Move a visible range in the grid * * This will effectively slice the range out of the grid, * re-index the remaining columns, * then insert the range with the first element at the provided index * * @param from The visible axis range to move * @param to The visible index to move the start of the range to * @param oldMovedItems The old reordered items * @param isPreMoveTo If toParam is the index before the movement * If true, this will account for the shift when moving * a range before the drop positin * E.g. Move range [0, 2] 1 item down (after element 3) * The move is [0, 2] -> 1 if this is false. [0, 2] -> 3 if this is true * Both will result in [0, 2] -> 1 * @returns The new reordered items. The original array if the operation is a no-op. */ static moveRange(from: BoundedAxisRange, to: VisibleIndex, oldMovedItems: MoveOperation[], isPreMoveTo?: boolean): MoveOperation[]; static moveRange(from: BoundedAxisRange, toParam: VisibleIndex, oldMovedItems: readonly MoveOperation[], isPreMoveTo?: boolean): readonly MoveOperation[]; static moveItemOrRange(from: VisibleIndex | BoundedAxisRange, to: VisibleIndex, oldMovedItems: MoveOperation[], isPreMoveTo?: boolean): MoveOperation[]; static moveItemOrRange(from: VisibleIndex | BoundedAxisRange, to: VisibleIndex, oldMovedItems: readonly MoveOperation[], isPreMoveTo?: boolean): readonly MoveOperation[]; /** * Applies the items moves to the AxisRange * @param start The start index of the range * @param end The end index of the range * @param movedItems The move operations to apply * @param reverse If the moved items should be applied in reverse (this reverses the effects of the moves) * @returns A list of AxisRanges in the translated space. Possibly multiple non-continuous ranges */ static applyItemMoves(start: T, end: T, movedItems: readonly MoveOperation[], reverse?: boolean): Range[]; /** * Applies the items moves to the givengrid range * @param range The grid range to translate * @param movedColumns The moved columns * @param movedRows The moved rows * @param reverse If the moved items should be reversed (i.e. visible to model range) * @returns A list of grid ranges in the translated space. Possibly multiple non-continuous ranges */ static translateRange(range: GridRange, movedColumns: readonly MoveOperation[], movedRows: readonly MoveOperation[], reverse: boolean): GridRange[]; /** * Retrieve the model index given the currently moved items * @param visibleIndex The visible index of the item to get the model index for * @param movedItems The moved items * @returns The model index of the item */ static getModelIndex(visibleIndex: VisibleIndex, movedItems: readonly MoveOperation[]): ModelIndex; /** * Retrieve the model indexes given the currently moved items * @param visibleIndexes The visible indexes of the item to get the model indexes for * @param movedItems The moved items * @returns The model indexes of the item */ static getModelIndexes(visibleIndexes: ModelIndex[], movedItems: MoveOperation[]): VisibleIndex[]; /** * Translate the provided UI start/end indexes to the model start/end indexes by applying the `movedItems` transformations. * Since moved items can split apart a range, multiple pairs of indexes are returned * * @param start Start item in one dimension * @param end End item in one dimension * @param movedItems Moved item pairs in this dimension * @returns Array of start/end pairs of the indexes after transformations applied. */ static getModelRangeIndexes(start: GridRangeIndex, end: GridRangeIndex, movedItems: readonly MoveOperation[]): AxisRange[]; /** * Translate the provided UI range into model range, using the `movedColumns` and `movedRows` to apply the necessary transforms. * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items * * @param uiRange The currently selected UI ranges * @param movedColumns The moved column pairs * @param movedRows The moved row pairs * @returns The model ranges after translation. */ static getModelRange(uiRange: GridRange, movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[]; /** * Translate the provided UI range into model ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms. * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items * * @param uiRanges The currently selected UI ranges * @param movedColumns The moved column pairs * @param movedRows The moved row pairs * @returns The model ranges after translation. */ static getModelRanges(uiRanges: readonly GridRange[], movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[]; /** * Translate the provided UI start/end indexes to the visible start/end indexes by applying the `movedItems` transformations. * Since moved items can split apart a range, multiple pairs of indexes are returned * * @param start Start item in one dimension * @param end End item in one dimension * @param movedItems Moved item pairs in this dimension * @returns Array of start/end pairs of the indexes after transformations applied. */ static getVisibleRangeIndexes(start: GridRangeIndex, end: GridRangeIndex, movedItems: readonly MoveOperation[]): AxisRange[]; /** * Translate the provided UI range into visible range, using the `movedColumns` and `movedRows` to apply the necessary transforms. * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items * * @param uiRange The currently selected UI ranges * @param movedColumns The moved column pairs * @param movedRows The moved row pairs * @returns The model ranges after translation. */ static getVisibleRange(modelRange: GridRange, movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[]; /** * Translate the provided model ranges into visible ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms. * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items * * @param modelRanges The model ranges * @param movedColumns The moved column pairs * @param movedRows The moved row pairs * @returns The model ranges after translation. */ static getVisibleRanges(modelRanges: readonly GridRange[], movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[]; /** * Retrieve the visible index given the currently moved items * @param modelIndex The model index to get the visible index for * @param movedItems Moved items * @returns The visible index of the item */ static getVisibleIndex(modelIndex: ModelIndex, movedItems: readonly MoveOperation[]): VisibleIndex; /** * Retrieve the visible indexes given the currently moved items * @param modelIndexes The model indexes to get the visible indexes for * @param movedItems Moved items * @returns The visible indexes of the item */ static getVisibleIndexes(modelIndexes: readonly ModelIndex[], movedItems: readonly MoveOperation[]): VisibleIndex[]; /** * Check if the current platform is Mac * @returns True if this platform is a Mac, false otherwise */ static isMacPlatform(): boolean; /** * Get the modifier key for the current platform * @returns The modifier key for the current platform */ static getModifierKey(): 'metaKey' | 'ctrlKey'; /** * Check if the modifier key is down for the given event * @param event The event to check * @returns True if the modifier key is down, false otherwise */ static isModifierKeyDown(event: MouseEvent | KeyboardEvent | React.KeyboardEvent | React.MouseEvent): boolean; /** * Check if the user has hidden the specified column * @param modelIndex The model index to check * @param userColumnWidths The user set column widths * @returns True if the user has hidden the column */ static checkColumnHidden(modelIndex: ModelIndex, userColumnWidths: ModelSizeMap): boolean; /** * Check if all the columns specified are hidden * @param columns Columns to check * @param userColumnWidths The user set column widths * @returns True if the user has hidden all of the columns */ static checkAllColumnsHidden(columns: readonly ModelIndex[], userColumnWidths: ModelSizeMap): boolean; /** * Get the bounds the mouse needs to be dragged outside of from an initial selection before scrolling occurs. * Taking into account any floating rows that may be covering the viewport. * @param metrics Grid metrics * @param row The row they started dragging in * @param column The column they started the drag from * @returns Dimensions of the drag area in relation to the canvas they need to drag outside of to start scrolling */ static getScrollDragBounds(metrics: GridMetrics, row: GridRangeIndex, column: GridRangeIndex): BoxCoordinates; /** * Converts the delta coordinates from the provided wheel event to pixels * Different platforms have different ways of providing the delta so this normalizes it * @param wheelEvent The mouse wheel event to get the scrolling delta for * @param pageWidth The width of the page that is scrolling * @param pageHeight The height of the page that is scrolling * @param lineWidth The width of the line scrolling in line mode * @param lineHeight The height of the line scrolling in line mode * @returns The delta coordinates normalized to pixels */ static getScrollDelta(wheelEvent: GridWheelEvent, pageWidth?: number, pageHeight?: number, lineWidth?: number, lineHeight?: number): { deltaX: number; deltaY: number; }; static compareRanges(range1: AxisRange, range2: AxisRange): number; static mergeSortedRanges(ranges: BoundedAxisRange[]): BoundedAxisRange[]; /** * Translates coordinates that are relative to gridX/gridY to be translated by gridX and gridY * @param tokenBox The token box to translate * @param metrics The grid metrics * @returns The token box with translated coordinates */ static translateTokenBox(tokenBox: TokenBox, metrics: GridMetrics): TokenBox; /** * Gets textWidth and X-Y position for a specific cell * The textWidth returned is the width that the text can occupy accounting for any other cell markings * The width accounts for tree table indents and cell padding, so it is the width the text may consume * * @param state GridRenderState to get the text metrics for * @param column Column of cell to get text metrics for * @param row Row of cell to get text metrics for * @returns Object with width, x, and y of the text */ static getTextRenderMetrics(state: GridRenderState, column: VisibleIndex, row: VisibleIndex): { width: number; x: number; y: number; }; /** * Finds tokens in text (urls, emails) that start with https:// or http:// * @param text The text to search in * @returns An array of tokens */ static findTokensWithProtocolInText(text: string): Token[]; } export default GridUtils; //# sourceMappingURL=GridUtils.d.ts.map