hyperformula
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
112 lines (111 loc) • 4.57 kB
TypeScript
/**
* @license
* Copyright (c) 2025 Handsoncode. All rights reserved.
*/
import { AbsoluteCellRange } from '../AbsoluteCellRange';
import { ArraySize } from '../ArraySize';
import { CellArray } from '../ArrayValue';
import { SimpleCellAddress } from '../Cell';
import { RawCellContent } from '../CellContentParser';
import { InternalScalarValue, InterpreterValue } from '../interpreter/InterpreterValue';
import { LazilyTransformingAstService } from '../LazilyTransformingAstService';
import { Maybe } from '../Maybe';
import { Ast } from '../parser';
import { ColumnsSpan, RowsSpan } from '../Span';
import { CellVertex } from './CellVertex';
/**
* Abstract base class for vertices that contain formulas in the dependency graph.
*
* Stores formula AST, cell address, and version for lazy transformation support.
* Has two concrete implementations: {@link ScalarFormulaVertex} for single-cell formulas
* and {@link ArrayFormulaVertex} for array formulas that span multiple cells.
*/
export declare abstract class FormulaVertex extends CellVertex {
protected formula: Ast;
protected cellAddress: SimpleCellAddress;
version: number;
protected constructor(formula: Ast, cellAddress: SimpleCellAddress, version: number);
get width(): number;
get height(): number;
static fromAst(formula: Ast, address: SimpleCellAddress, size: ArraySize, version: number): ArrayFormulaVertex | ScalarFormulaVertex;
/**
* Returns formula stored in this vertex
*/
getFormula(updatingService: LazilyTransformingAstService): Ast;
ensureRecentData(updatingService: LazilyTransformingAstService): void;
/**
* Returns address of the cell associated with vertex
*/
getAddress(updatingService: LazilyTransformingAstService): SimpleCellAddress;
/**
* Sets computed cell value stored in this vertex
*/
abstract setCellValue(cellValue: InterpreterValue): InterpreterValue;
/**
* Returns cell value stored in vertex
*/
abstract getCellValue(): InterpreterValue;
abstract valueOrUndef(): Maybe<InterpreterValue>;
abstract isComputed(): boolean;
}
/**
* Represents a formula vertex that produces an array result spanning multiple cells.
*
* Array formulas are transformed eagerly (unlike scalar formulas) and store their
* computed values in a {@link CellArray} structure.
*/
export declare class ArrayFormulaVertex extends FormulaVertex {
array: CellArray;
constructor(formula: Ast, cellAddress: SimpleCellAddress, size: ArraySize, version?: number);
get width(): number;
get height(): number;
get sheet(): number;
get leftCorner(): SimpleCellAddress;
setCellValue(value: InterpreterValue): InterpreterValue;
getCellValue(): InterpreterValue;
valueOrUndef(): Maybe<InterpreterValue>;
getArrayCellValue(address: SimpleCellAddress): InternalScalarValue;
getArrayCellRawValue(address: SimpleCellAddress): Maybe<RawCellContent>;
setArrayCellValue(address: SimpleCellAddress, value: number): void;
setNoSpace(): InterpreterValue;
getRange(): AbsoluteCellRange;
getRangeOrUndef(): Maybe<AbsoluteCellRange>;
setAddress(address: SimpleCellAddress): void;
setFormula(newFormula: Ast): void;
spansThroughSheetRows(sheet: number, startRow: number, endRow?: number): boolean;
spansThroughSheetColumn(sheet: number, col: number, columnEnd?: number): boolean;
isComputed(): boolean;
columnsFromArray(): ColumnsSpan;
rowsFromArray(): RowsSpan;
/**
* No-op as array vertices are transformed eagerly.
*/
ensureRecentData(_updatingService: LazilyTransformingAstService): void;
isLeftCorner(address: SimpleCellAddress): boolean;
private setErrorValue;
}
/**
* Represents a formula vertex that produces a single scalar value.
*
* Unlike {@link ArrayFormulaVertex}, scalar formulas are transformed lazily
* and cache their computed value for retrieval.
*/
export declare class ScalarFormulaVertex extends FormulaVertex {
/** Most recently computed value of this formula. */
private cachedCellValue?;
constructor(
/** Formula in AST format */
formula: Ast,
/** Address which this vertex represents */
address: SimpleCellAddress, version: number);
valueOrUndef(): Maybe<InterpreterValue>;
/**
* Sets computed cell value stored in this vertex
*/
setCellValue(cellValue: InterpreterValue): InterpreterValue;
/**
* Returns cell value stored in vertex
*/
getCellValue(): InterpreterValue;
isComputed(): boolean;
}