UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

125 lines (124 loc) 3.98 kB
import { SelectionMode } from './enums'; /** * Range of cells * Rectangular area in the grid. Defined by: * - fromCell: CellPosition - starting cell. * - toCell: CellPosition - ending cell. */ var CellRange = /** @class */ (function () { function CellRange(fromCell) { this.fromCell = fromCell; this.toCell = null; } Object.defineProperty(CellRange.prototype, "fromRow", { /** * Always lower row index */ get: function () { if (this.toCell !== null && this.toCell.rowIndex < this.fromCell.rowIndex) { return this.toCell.rowIndex; } return this.fromCell.rowIndex; }, enumerable: true, configurable: true }); Object.defineProperty(CellRange.prototype, "toRow", { /** * Always higher row index */ get: function () { if (this.toCell !== null && this.toCell.rowIndex < this.fromCell.rowIndex) { return this.fromCell.rowIndex; } return this.toCell !== null ? this.toCell.rowIndex : this.fromCell.rowIndex; }, enumerable: true, configurable: true }); Object.defineProperty(CellRange.prototype, "fromField", { // Column indices are unknown get: function () { return this.fromCell.fieldName; }, enumerable: true, configurable: true }); Object.defineProperty(CellRange.prototype, "toField", { // Column indices are unknown get: function () { if (this.toCell === null) { return this.fromCell.fieldName; } return this.toCell.fieldName; }, enumerable: true, configurable: true }); CellRange.prototype.equals = function (range, sm) { if (sm === SelectionMode.ROW || sm === SelectionMode.ROW_AND_RANGE) { if (this.fromCell.row === range.fromCell.row) { if (this.toCell === null && range.toCell === null) { return true; } } } if (this.fromCell.row !== range.fromCell.row) { return false; } if (this.fromCell.fieldName !== range.fromCell.fieldName) { return false; } if (this.toCell === null && range.toCell !== null) { return false; } if (this.toCell !== null && range.toCell === null) { return false; } if (!this.toCell.equals(range.toCell)) { return false; } return true; }; CellRange.prototype.clone = function () { var res = new CellRange(this.fromCell.clone()); if (this.toCell !== null) { res.toCell = this.toCell.clone(); } return res; }; /** * Extends range to a given cell position. * @param pos Cell position. * @return Is range changed. */ CellRange.prototype.extend = function (pos) { if (pos.fieldName === this.fromCell.fieldName && pos.rowIndex === this.fromCell.rowIndex) { var res = this.toCell !== null; this.toCell = null; return res; } if (!this.toCell && !pos) { return false; } if (!this.toCell && pos) { this.toCell = pos; return true; } if (this.toCell && !pos) { this.toCell = null; return true; } if (this.toCell.row !== pos.row || this.toCell.rowIndex !== pos.rowIndex || this.toCell.fieldName !== pos.fieldName) { this.toCell = pos; return true; } // Not changed return false; }; return CellRange; }()); export { CellRange };