import CellCoords from './../cell/coords'; type DirectionType = 'NW-SE' | 'NE-SW' | 'SE-NW' | 'SW-NE'; /** * @description * * The `CellRange` class holds a set of cell coordinates ([`CellCoords`](@/api/cellCoords.md) instances) * that form a [selection range](@/guides/cell-features/selection/selection.md#select-ranges). * * A single `CellRange` instance represents a single unit of selection * that contains either a single cell or multiple adjacent cells. * * To import the `CellRange` class: * * ```js * import Handsontable, { CellRange } from '/handsontable'; * * // or, using modules * import Handsontable, { CellRange } from '/handsontable/base'; * ``` */ declare class CellRange { #private; /** * Used to draw bold border around a cell where selection was started and to edit the cell * when you press Enter. The highlight cannot point to headers (negative values) so its * coordinates object is normalized while assigning. * * @private * @type {CellCoords} */ highlight: CellCoords; /** * Usually the same as highlight, but in Excel there is distinction - one can change * highlight within a selection. * * @private * @type {CellCoords} */ from: CellCoords; /** * End selection. * * @private * @type {CellCoords} */ to: CellCoords; /** * Creates a new CellRange instance. * * @param {CellCoords} highlight The cell where selection was started. * @param {CellCoords} from The start of the range. * @param {CellCoords} to The end of the range. * @param {boolean} isRtl A flag indicating whether to use right-to-left (RTL) layout. */ constructor(highlight: CellCoords, from?: CellCoords, to?: CellCoords, isRtl?: boolean); /** * Highlights cell selection at the `coords` coordinates. * * @param {CellCoords} coords Coordinates to use. * @returns {CellRange} */ setHighlight(coords: CellCoords): CellRange; /** * Sets the `coords` coordinates as the start of your range. * * @param {CellCoords} coords Coordinates to use. * @returns {CellRange} */ setFrom(coords: CellCoords): CellRange; /** * Sets the `coords` coordinates as the end of your range. * * @param {CellCoords} coords Coordinates to use. * @returns {CellRange} */ setTo(coords: CellCoords): CellRange; /** * Normalizes the coordinates in your `CellRange` instance to the nearest valid position. * * Coordinates that point to headers (negative values) are normalized to `0`. * * @returns {CellRange} */ normalize(): CellRange; /** * Checks if the coordinates in your `CellRange` instance are valid * in the context of given table parameters. * * See the [`isValid()`](@/api/cellCoords.md#isvalid) method of the [`CellCoords`](@/api/cellCoords.md) class. * * @param {object} tableParams An object with a defined table size. * @param {number} tableParams.countRows The total number of rows. * @param {number} tableParams.countCols The total number of columns. * @param {number} tableParams.countRowHeaders A number of row headers. * @param {number} tableParams.countColHeaders A number of column headers. * @returns {boolean} */ isValid(tableParams: { countRows?: number; countCols?: number; countRowHeaders?: number; countColHeaders?: number; }): boolean; /** * Checks if your range is just a single cell or header. * * @returns {boolean} */ isSingle(): boolean; /** * Checks if your range is just a single cell. * * @returns {boolean} */ isSingleCell(): boolean; /** * Checks if your range is just a single header. * * @returns {boolean} */ isSingleHeader(): boolean; /** * Checks if your range covers only headers range (negative coordinates, without any cells). * * @returns {boolean} */ isHeader(): boolean; /** * Checks if your range overlaps headers range (negative coordinates). * * @returns {boolean} */ containsHeaders(): boolean; /** * Returns the height of your range (as a number of rows, including row headers). * * @returns {number} */ getOuterHeight(): number; /** * Returns the width of your range (as a number of columns, including column headers). * * @returns {number} */ getOuterWidth(): number; /** * Returns the height of your range (as a number of rows, excluding row headers). * * @returns {number} */ getHeight(): number; /** * Returns the width of your range (as a number of columns, excluding column headers). * * @returns {number} */ getWidth(): number; /** * Returns the number of cells within your range (excluding column and row headers). * * @returns {number} */ getCellsCount(): number; /** * Checks if another set of coordinates (`cellCoords`) * is within the `from` and `to` coordinates of your range. * * @param {CellCoords} cellCoords Coordinates to check. * @returns {boolean} */ includes(cellCoords: CellCoords): boolean; /** * Checks if another range (`cellRange`) is within your range. * * @param {CellRange} cellRange A range to check. * @returns {boolean} */ includesRange(cellRange: CellRange): boolean; /** * Checks if another range (`cellRange`) is equal to your range. * * @param {CellRange} cellRange A range to check. * @returns {boolean} */ isEqual(cellRange: CellRange): boolean; /** * Checks if another range (`cellRange`) overlaps your range. * * Range A overlaps range B if the intersection of A and B (or B and A) is not empty. * * @param {CellRange} cellRange A range to check. * @returns {boolean} */ overlaps(cellRange: CellRange): boolean; /** * Checks if coordinates point is south-east of your range. * * @param {CellCoords} cellCoords Coordinates to check. * @returns {boolean} */ isSouthEastOf(cellCoords: CellCoords): boolean; /** * Checks if coordinates point is north-west of your range. * * @param {CellRange} cellCoords Coordinates to check. * @returns {boolean} */ isNorthWestOf(cellCoords: CellCoords): boolean; /** * Checks if another range (`cellRange`) overlaps your range horizontally. * * For example: returns `true` if the last column of your range is `5` * and the first column of the `cellRange` range is `3`. * * @param {CellRange} cellRange A range to check. * @returns {boolean} */ isOverlappingHorizontally(cellRange: CellRange): boolean; /** * Checks if another range (`cellRange`) overlaps your range vertically. * * For example: returns `true` if the last row of your range is `5` * and the first row of the `cellRange` range is `3`. * * @param {CellRange} cellRange A range to check. * @returns {boolean} */ isOverlappingVertically(cellRange: CellRange): boolean; /** * Adds a cell to your range, at `cellCoords` coordinates. * * The `cellCoords` coordinates must exceed a corner of your range. * * @param {CellCoords} cellCoords A new cell's coordinates. * @param {boolean} [changeDirection=true] If `true`, the direction of your range is changed to the direction * of the `cellCoords` coordinates. * @returns {boolean} */ expand(cellCoords: CellCoords, changeDirection?: boolean): boolean; /** * Expand your range with another range (`expandingRange`). * * @param {CellRange} expandingRange A new range. * @param {boolean} [changeDirection=true] If `true`, the direction of your range is changed to the direction * of the `expandingRange` range. * @returns {boolean} */ expandByRange(expandingRange: CellRange, changeDirection?: boolean): boolean; /** * Gets the direction of the selection. * * @returns {string} Returns one of the values: `'NW-SE'`, `'NE-SW'`, `'SE-NW'`, `'SW-NE'`. */ getDirection(): DirectionType; /** * Sets the direction of the selection. * * @param {string} direction One of the values: `'NW-SE'`, `'NE-SW'`, `'SE-NW'`, `'SW-NE'`. */ setDirection(direction: DirectionType): void; /** * Gets the vertical direction of the selection. * * @returns {string} Returns one of the values: `N-S` (north->south), `S-N` (south->north). */ getVerticalDirection(): 'N-S' | 'S-N'; /** * Gets the horizontal direction of the selection. * * @returns {string} Returns one of the values: `W-E` (west->east), `E-W` (east->west). */ getHorizontalDirection(): 'W-E' | 'E-W'; /** * Gets the inline (horizontal) direction of the selection. * * @returns {string} Returns one of the values: `start-end`, `end-start`. */ getInlineDirection(): "start-end" | "end-start"; /** * Flips the direction of your range vertically (e.g., `NW-SE` changes to `SW-NE`). */ flipDirectionVertically(): void; /** * Flips the direction of your range horizontally (e.g., `NW-SE` changes to `NE-SW`). */ flipDirectionHorizontally(): void; /** * Gets the top-left (in LTR) or top-right (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getTopStartCorner(): CellCoords; /** * Gets the top-left corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getTopLeftCorner(): CellCoords; /** * Gets the bottom right (in LTR) or bottom left (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getBottomEndCorner(): CellCoords; /** * Gets the bottom right corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getBottomRightCorner(): CellCoords; /** * Gets the top right (in LTR) or top left (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getTopEndCorner(): CellCoords; /** * Gets the top right corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getTopRightCorner(): CellCoords; /** * Gets the bottom left (in LTR) or bottom right (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getBottomStartCorner(): CellCoords; /** * Gets the bottom left corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the corner coordinates are normalized to `0`. * * @returns {CellCoords} */ getBottomLeftCorner(): CellCoords; /** * Gets the top left (in LTR) or top right (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the top and start coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterTopStartCorner(): CellCoords; /** * Gets the top left corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the top and left coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterTopLeftCorner(): CellCoords; /** * Gets the bottom right (in LTR) or bottom left (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the top and start coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterBottomEndCorner(): CellCoords; /** * Gets the bottom right corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the top and left coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterBottomRightCorner(): CellCoords; /** * Gets the top right (in LTR) or top left (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the top and start coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterTopEndCorner(): CellCoords; /** * Gets the top right corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the top and left coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterTopRightCorner(): CellCoords; /** * Gets the bottom left (in LTR) or bottom right (in RTL) corner coordinates of your range. * * If the corner contains header coordinates (negative values), * the top and start coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterBottomStartCorner(): CellCoords; /** * Gets the bottom left corner coordinates of your range, * both in the LTR and RTL layout direction. * * If the corner contains header coordinates (negative values), * the top and left coordinates are pointed to that header. * * @returns {CellCoords} */ getOuterBottomLeftCorner(): CellCoords; /** * Checks if a set of coordinates (`coords`) matches one of the 4 corners of your range. * * @param {CellCoords} coords Coordinates to check. * @returns {boolean} */ isCorner(coords: CellCoords): boolean; /** * Gets the coordinates of a range corner opposite to the provided `coords`. * * For example: if the `coords` coordinates match the bottom-right corner of your range, * the coordinates of the top-left corner of your range are returned. * * @param {CellCoords} coords Coordinates to check. * @returns {CellCoords} */ getOppositeCorner(coords: CellCoords): CellCoords | undefined; /** * Indicates which borders (top, right, bottom, left) are shared between * your `CellRange`instance and another `range` that's within your range. * * @param {CellRange} range A range to compare with. * @returns {Array<'top' | 'right' | 'bottom' | 'left'>} */ getBordersSharedWith(range: CellRange): Array<'top' | 'right' | 'bottom' | 'left'>; /** * Gets the coordinates of the inner cells of your range. * * @returns {CellCoords[]} */ getInner(): CellCoords[]; /** * Gets the coordinates of all cells of your range. * * @returns {CellCoords[]} */ getAll(): CellCoords[]; /** * Runs a callback function on all cells within your range. * * You can break the iteration by returning `false` in the callback function. * * @param {function(number, number): boolean} callback A callback function. */ forAll(callback: (row: number, column: number) => boolean | void): void; /** * Clones your `CellRange` instance. * * @returns {CellRange} */ clone(): CellRange; /** * Converts your `CellRange` instance into an object literal with the following properties: * * - `from` * - `row` * - `col` * - `to` * - `row` * - `col` * * @returns {{from: {row: number, col: number}, to: {row: number, col: number}}} An object literal with `from` and `to` properties. */ toObject(): { from: { row: number | null; col: number | null; }; to: { row: number | null; col: number | null; }; }; /** * Creates and returns a new instance of the `CellCoords` class. * * The new `CellCoords` instance automatically inherits the LTR/RTL flag * from your `CellRange` instance. * * @private * @param {number | null} row A row index. * @param {number | null} column A column index. * @returns {CellCoords} */ _createCellCoords(row: number | null, column: number | null): CellCoords; } export default CellRange;