63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
"use strict";
|
|||
|
|
|
||
|
|
exports.__esModule = true;
|
||
|
|
exports.ContentChanges = void 0;
|
||
|
|
var _Cell = require("./Cell");
|
||
|
|
var _SimpleRangeValue = require("./SimpleRangeValue");
|
||
|
|
/**
|
||
|
|
* @license
|
||
|
|
* Copyright (c) 2024 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;
|