hyperformula-dc
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
145 lines (125 loc) • 4.83 kB
JavaScript
"use strict";
exports.__esModule = true;
exports.ColumnAddress = exports.ReferenceType = void 0;
require("core-js/modules/es.array.concat.js");
var _Cell = require("../Cell");
var _addressRepresentationConverters = require("./addressRepresentationConverters");
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; }
var ReferenceType;
exports.ReferenceType = ReferenceType;
(function (ReferenceType) {
ReferenceType["RELATIVE"] = "RELATIVE";
ReferenceType["ABSOLUTE"] = "ABSOLUTE";
})(ReferenceType || (exports.ReferenceType = ReferenceType = {}));
var ColumnAddress = /*#__PURE__*/function () {
function ColumnAddress(type, col, sheet) {
_classCallCheck(this, ColumnAddress);
this.type = type;
this.col = col;
this.sheet = sheet;
}
_createClass(ColumnAddress, [{
key: "isColumnAbsolute",
value: function isColumnAbsolute() {
return this.type === ReferenceType.ABSOLUTE;
}
}, {
key: "isColumnRelative",
value: function isColumnRelative() {
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 ColumnAddress(this.type, this.col + toRight, newSheet);
}
}, {
key: "shiftedByColumns",
value: function shiftedByColumns(numberOfColumns) {
return new ColumnAddress(this.type, this.col + numberOfColumns, this.sheet);
}
}, {
key: "toSimpleColumnAddress",
value: function toSimpleColumnAddress(baseAddress) {
var sheet = (0, _Cell.absoluteSheetReference)(this, baseAddress);
var column = this.col;
if (this.isColumnRelative()) {
column = baseAddress.col + this.col;
}
return (0, _Cell.simpleColumnAddress)(sheet, column);
}
}, {
key: "shiftRelativeDimensions",
value: function shiftRelativeDimensions(toRight, _toBottom) {
var col = this.isColumnRelative() ? this.col + toRight : this.col;
return new ColumnAddress(this.type, col, this.sheet);
}
}, {
key: "shiftAbsoluteDimensions",
value: function shiftAbsoluteDimensions(toRight, _toBottom) {
var col = this.isColumnAbsolute() ? this.col + toRight : this.col;
return new ColumnAddress(this.type, col, this.sheet);
}
}, {
key: "withAbsoluteSheet",
value: function withAbsoluteSheet(sheet) {
return new ColumnAddress(this.type, this.col, sheet);
}
}, {
key: "isInvalid",
value: function isInvalid(baseAddress) {
return this.toSimpleColumnAddress(baseAddress).col < 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, "#COLR").concat(this.col);
}
case ReferenceType.ABSOLUTE:
{
return "".concat(sheetPart, "#COLA").concat(this.col);
}
}
}
}, {
key: "unparse",
value: function unparse(baseAddress) {
var simpleAddress = this.toSimpleColumnAddress(baseAddress);
if ((0, _Cell.invalidSimpleColumnAddress)(simpleAddress)) {
return undefined;
}
var column = (0, _addressRepresentationConverters.columnIndexToLabel)(simpleAddress.col);
var dollar = this.type === ReferenceType.ABSOLUTE ? '$' : '';
return "".concat(dollar).concat(column);
}
}, {
key: "exceedsSheetSizeLimits",
value: function exceedsSheetSizeLimits(maxColumns) {
return this.col >= maxColumns;
}
}], [{
key: "absolute",
value: function absolute(column, sheet) {
return new ColumnAddress(ReferenceType.ABSOLUTE, column, sheet);
}
}, {
key: "relative",
value: function relative(column, sheet) {
return new ColumnAddress(ReferenceType.RELATIVE, column, sheet);
}
}]);
return ColumnAddress;
}();
exports.ColumnAddress = ColumnAddress;