/** * Discovers formulas **declaratively** — from column definitions and from row * data — and registers them with the {@link FormulaEngine}, so consumers never * have to call `GridApi.setCellFormula` to seed formulas at load time. * * It is deliberately framework-independent: it operates on the minimal * {@link FormulaColumnInfo}/{@link FormulaRowInfo} shapes rather than concrete * grid types, so it is unit-testable in isolation and reusable across wrappers * (per Photon Core's architecture rules). The grid layer adapts its * `ColumnModel`/`RowModel` to these shapes. * * ### Sources & precedence (lowest → highest) * 1. **Column formula** — {@link FormulaColumnInfo.formula}: applied to every row. * 2. **Row-data formula** — a `=`-prefixed string in a row's cell: overrides the * column formula for that one row. * 3. **Runtime API / manual edit** — a later `setFormula` overrides both (handled * by the engine's last-write-wins store, not here). * * @packageDocumentation */ import type { FormulaEngine } from './formula-engine'; /** The minimal column shape formula discovery needs. */ export interface FormulaColumnInfo { /** Immutable column identity. */ readonly colId: string; /** The column's data `field` (used to read row-data cell values). */ readonly field: string; /** Whether the column opted into the Formula Engine. */ readonly allowFormula?: boolean; /** A declared column-level formula applied to every row. */ readonly formula?: string; } /** The minimal row shape formula discovery needs. */ export interface FormulaRowInfo { /** Stable row identity. */ readonly nodeId: string; /** The row's data object. */ readonly data: Record; } /** Configuration for {@link FormulaInitializer}. */ export interface FormulaInitializerOptions { /** * When `true` (default), a `=`-prefixed value found in a column's row data * auto-opts that column into the Formula Engine — even if it did not set * `allowFormula` — via {@link markFormulaCapable}. When `false`, only columns * that explicitly opted in (`allowFormula` or a column `formula`) are scanned. * * @default true */ readonly autoDetectDataFormulas?: boolean; /** * Called when auto-detection promotes a column to formula-capable, so the grid * can flip `allowFormula` on the live column model before the engine (which * gates on it) registers the formula. */ readonly markFormulaCapable?: (colId: string) => void; } /** * Framework-independent declarative-formula discovery. One instance per grid, * driven by the grid layer on load and on structural row changes. Each method * returns the set of row `nodeId`s whose value changed, so the caller can repaint * precisely. */ export declare class FormulaInitializer { private readonly engine; private readonly autoDetect; private readonly markFormulaCapable; /** * @param engine - The formula engine to register discovered formulas with. * @param options - Discovery options. */ constructor(engine: FormulaEngine, options?: FormulaInitializerOptions); /** * Discovers and registers every formula for a full data load. Purges formulas * belonging to rows no longer present (so a data swap leaves no orphans), then * seeds the new set in a single recompute. * * @param columns - All columns in canonical order. * @param rows - All data rows. * @returns Row ids whose value changed. */ onLoad(columns: readonly FormulaColumnInfo[], rows: readonly FormulaRowInfo[]): ReadonlySet; /** * Discovers and registers formulas for newly-inserted rows (incremental — * existing rows are untouched). * * @param columns - All columns in canonical order. * @param newRows - Only the rows just added. * @returns Row ids whose value changed. */ onRowsAdded(columns: readonly FormulaColumnInfo[], newRows: readonly FormulaRowInfo[]): ReadonlySet; /** * Removes formulas belonging to deleted rows and recomputes dependents. * * @param nodeIds - Stable ids of the removed rows. * @returns Row ids whose value changed. */ onRowsRemoved(nodeIds: ReadonlySet): ReadonlySet; /** * Reacts to an in-place update of a single row's data: re-discovers any newly * introduced `=`-formula in the changed fields, then recomputes formula cells * that depend on the changed (literal) cells. * * @param columns - All columns in canonical order. * @param row - The updated row. * @param changedFields - The data fields that changed. * @returns Row ids whose value changed. */ onRowDataChanged(columns: readonly FormulaColumnInfo[], row: FormulaRowInfo, changedFields: readonly string[]): ReadonlySet; /** * Builds the seed list: for each row × column, a row-data `=`-formula wins over * the column formula (precedence), and auto-detection promotes columns as * needed so the engine will accept their formulas. */ private collectSeeds; /** Drops formula cells whose row is absent from `rows` (data-swap cleanup). */ private purgeStale; } //# sourceMappingURL=formula-initializer.d.ts.map