import type { default as CellCoords } from '../../3rdparty/walkontable/src/cell/coords'; import type { default as CellRange } from '../../3rdparty/walkontable/src/cell/range'; import type { IndexMapper } from '../../translations'; import { Selection } from './../../3rdparty/walkontable/src'; interface VisualSelectionSettings { createCellRange: (highlight: CellCoords, from?: CellCoords, to?: CellCoords) => CellRange; createCellCoords: (row: number, column: number) => CellCoords; rowIndexMapper: IndexMapper; columnIndexMapper: IndexMapper; visualToRenderableCoords: (coords: CellCoords) => { row: number | null; col: number | null; }; renderableToVisualCoords: (coords: CellCoords) => CellCoords; selectionType?: string; [key: string]: unknown; } /** * Extends the Walkontable Selection class to operate on visual coordinates, translating them to * renderable indexes when committing the selection to the DOM. */ declare class VisualSelection extends Selection { /** * The settings object that includes index mappers and coordinate factory helpers specific to visual selection. */ settings: VisualSelectionSettings; /** * Range of selection visually. Visual representation may have representation in a rendered selection. * * @type {null|CellRange} */ visualCellRange: CellRange | null; /** * Initializes the visual selection with optional settings overrides and an initial visual cell range. */ constructor(settings: Record, visualCellRange?: CellRange | null); /** * Adds a cell coords to the selection. * * @param {CellCoords} coords Visual coordinates of a cell. * @returns {VisualSelection} */ add(coords: CellCoords | object): this; /** * Clears visual and renderable selection. * * @returns {VisualSelection} */ clear(): this; /** * Trims the passed cell range object by removing all coordinates that points to the hidden rows * or columns. The result is a new cell range object that points only to the visible indexes or `null`. * * @private * @param {CellRange} cellRange Cells range object to be trimmed. * @returns {CellRange} Visual non-hidden cells range coordinates. */ trimToVisibleCellsRangeOnly(cellRange: CellRange): CellRange | null; /** * Gets nearest coordinates that points to the visible row and column indexes. If there are no visible * rows and/or columns the `null` value is returned. * * @private * @param {CellCoords} coords The coords object as starting point for finding the nearest visible coordinates. * @param {1|-1} rowSearchDirection The search direction. For value 1, it means searching from top to bottom for * rows and from left to right for columns. For -1, it is the other way around. * @param {1|-1} columnSearchDirection The same as above but for rows. * @returns {CellCoords|null} Visual cell coordinates. */ getNearestNotHiddenCoords(coords: CellCoords, rowSearchDirection: 1 | -1, columnSearchDirection?: 1 | -1): CellCoords | null; /** * Gets nearest visual index. If there are no visible rows or columns the `null` value is returned. * * @private * @param {IndexMapper} indexMapper The IndexMapper instance for specific axis. * @param {number} visualIndex The index as starting point for finding the nearest visible index. * @param {1|-1} searchDirection The search direction. For value 1, it means searching from top to bottom for * rows and from left to right for columns. For -1, it is the other way around. * @returns {number|null} Visual row/column index. */ getNearestNotHiddenIndex(indexMapper: IndexMapper, visualIndex: number, searchDirection: 1 | -1): number | null; /** * Override internally stored visual indexes added by the Selection's `add` function. It should be executed * at the end of process of adding visual selection coordinates. * * @returns {VisualSelection} */ commit(): this; /** * Some selection may be a part of broader cell range. This function sync coordinates of current selection * and the broader cell range when needed (current selection can't be presented visually). * * @param {CellRange} broaderCellRange Visual range. Actual cell range may be contained in the broader cell range. * When there is no way to represent some cell range visually we try to find range containing just the first visible cell. * * Warn: Please keep in mind that this function may change coordinates of the handled broader range. * * @returns {VisualSelection} */ syncWith(broaderCellRange: CellRange): this; /** * Returns the top left (TL) and bottom right (BR) selection coordinates (renderable indexes). * The method overwrites the original method to support header selection for hidden cells. * To make the header selection working, the CellCoords and CellRange have to support not * complete coordinates (`null` values for example, `row: null`, `col: 2`). * * @returns {Array} Returns array of coordinates for example `[1, 1, 5, 5]`. */ getCorners(): [number, number, number, number]; /** * Returns the top left (or top right in RTL) and bottom right (or bottom left in RTL) selection * coordinates (visual indexes). * * @returns {Array} Returns array of coordinates for example `[1, 1, 5, 5]`. */ getVisualCorners(): (number | null)[]; /** * Creates a new CellRange object based on visual coordinates which before object creation are * translated to renderable indexes. * * @param {CellCoords} visualFromCoords The CellCoords object which contains coordinates that * points to the beginning of the selection. * @param {CellCoords} visualToCoords The CellCoords object which contains coordinates that * points to the end of the selection. * @returns {CellRange|null} */ createRenderableCellRange(visualFromCoords: CellCoords, visualToCoords: CellCoords): CellRange | null; } export default VisualSelection;