UNPKG

hyperformula

Version:

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

57 lines 1.38 kB
/** * @license * Copyright (c) 2025 Handsoncode. All rights reserved. */ import { addressKey } from "./Cell.mjs"; import { SimpleRangeValue } from "./SimpleRangeValue.mjs"; export 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) { for (const cellAddress of value.effectiveAddressesFromData(address)) { this.changes.delete(addressKey(cellAddress)); } } this.changes.set(addressKey(address), change); } addInterpreterValue(value, address, oldValue) { this.add(address, { address, value, oldValue }); } }