UNPKG

hyperformula-dc

Version:

HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas

131 lines (118 loc) 4.34 kB
import "core-js/modules/es.array.concat.js"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * @license * Copyright (c) 2021 Handsoncode. All rights reserved. */ import { absoluteSheetReference, invalidSimpleRowAddress, simpleRowAddress } from '../Cell'; import { ReferenceType } from './ColumnAddress'; export var RowAddress = /*#__PURE__*/function () { function RowAddress(type, row, sheet) { _classCallCheck(this, RowAddress); this.type = type; this.row = row; this.sheet = sheet; } _createClass(RowAddress, [{ key: "isRowAbsolute", value: function isRowAbsolute() { return this.type === ReferenceType.ABSOLUTE; } }, { key: "isRowRelative", value: function isRowRelative() { return this.type === ReferenceType.RELATIVE; } }, { key: "isAbsolute", value: function isAbsolute() { return this.type === ReferenceType.ABSOLUTE && this.sheet !== undefined; } }, { key: "moved", value: function moved(toSheet, toRight, toBottom) { var newSheet = this.sheet === undefined ? undefined : toSheet; return new RowAddress(this.type, this.row + toBottom, newSheet); } }, { key: "shiftedByRows", value: function shiftedByRows(numberOfColumns) { return new RowAddress(this.type, this.row + numberOfColumns, this.sheet); } }, { key: "toSimpleRowAddress", value: function toSimpleRowAddress(baseAddress) { var sheet = absoluteSheetReference(this, baseAddress); var row = this.row; if (this.isRowRelative()) { row = baseAddress.row + this.row; } return simpleRowAddress(sheet, row); } }, { key: "shiftRelativeDimensions", value: function shiftRelativeDimensions(toRight, toBottom) { var row = this.isRowRelative() ? this.row + toBottom : this.row; return new RowAddress(this.type, row, this.sheet); } }, { key: "shiftAbsoluteDimensions", value: function shiftAbsoluteDimensions(toRight, toBottom) { var row = this.isRowAbsolute() ? this.row + toBottom : this.row; return new RowAddress(this.type, row, this.sheet); } }, { key: "withAbsoluteSheet", value: function withAbsoluteSheet(sheet) { return new RowAddress(this.type, this.row, sheet); } }, { key: "isInvalid", value: function isInvalid(baseAddress) { return this.toSimpleRowAddress(baseAddress).row < 0; } }, { key: "hash", value: function hash(withSheet) { var sheetPart = withSheet && this.sheet !== undefined ? "#".concat(this.sheet) : ''; switch (this.type) { case ReferenceType.RELATIVE: { return "".concat(sheetPart, "#ROWR").concat(this.row); } case ReferenceType.ABSOLUTE: { return "".concat(sheetPart, "#ROWA").concat(this.row); } } } }, { key: "unparse", value: function unparse(baseAddress) { var simpleAddress = this.toSimpleRowAddress(baseAddress); if (invalidSimpleRowAddress(simpleAddress)) { return undefined; } var dollar = this.type === ReferenceType.ABSOLUTE ? '$' : ''; return "".concat(dollar).concat(simpleAddress.row + 1); } }, { key: "exceedsSheetSizeLimits", value: function exceedsSheetSizeLimits(maxRows) { return this.row >= maxRows; } }], [{ key: "absolute", value: function absolute(row, sheet) { return new RowAddress(ReferenceType.ABSOLUTE, row, sheet); } }, { key: "relative", value: function relative(row, sheet) { return new RowAddress(ReferenceType.RELATIVE, row, sheet); } }]); return RowAddress; }();