hyperformula
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
63 lines (61 loc) • 1.52 kB
JavaScript
;
exports.__esModule = true;
exports.ContentChanges = void 0;
var _Cell = require("./Cell");
var _SimpleRangeValue = require("./SimpleRangeValue");
/**
* @license
* Copyright (c) 2025 Handsoncode. All rights reserved.
*/
class ContentChanges {
constructor() {
this.changes = new Map();
}
static empty() {
return new ContentChanges();
}
addAll(other) {
for (const change of other.changes.values()) {
this.add(change.address, change);
}
return this;
}
addChange(newValue, address, oldValue) {
this.addInterpreterValue(newValue, address, oldValue);
}
exportChanges(exporter) {
let ret = [];
this.changes.forEach(e => {
const change = exporter.exportChange(e);
if (Array.isArray(change)) {
ret = ret.concat(change);
} else {
ret.push(change);
}
});
return ret;
}
getChanges() {
return Array.from(this.changes.values());
}
isEmpty() {
return this.changes.size === 0;
}
add(address, change) {
const value = change.value;
if (value instanceof _SimpleRangeValue.SimpleRangeValue) {
for (const cellAddress of value.effectiveAddressesFromData(address)) {
this.changes.delete((0, _Cell.addressKey)(cellAddress));
}
}
this.changes.set((0, _Cell.addressKey)(address), change);
}
addInterpreterValue(value, address, oldValue) {
this.add(address, {
address,
value,
oldValue
});
}
}
exports.ContentChanges = ContentChanges;