@libregrid/formulas 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ import { BeanStub } from 'ag-grid-community';
2
+ /**
3
+ * The `formulaInputManager` bean — coordinates formula-aware editors so only
4
+ * one active formula input exists at a time (the cell editor registers itself
5
+ * on open with its own id and unregisters on close; other formula surfaces
6
+ * consult `isActiveEditor` before capturing input).
7
+ *
8
+ * @feature Formulas
9
+ */
10
+ export class FormulaInputManager extends BeanStub {
11
+ beanName = 'formulaInputManager';
12
+ activeEditors = new Map();
13
+ registerActiveEditor(editorId, onDeactivate) {
14
+ if (this.activeEditors.has(editorId))
15
+ return false;
16
+ this.activeEditors.set(editorId, { onDeactivate });
17
+ return true;
18
+ }
19
+ unregisterActiveEditor(editorId, onDeactivate) {
20
+ if (!this.activeEditors.has(editorId))
21
+ return;
22
+ this.activeEditors.delete(editorId);
23
+ onDeactivate();
24
+ }
25
+ isActiveEditor(editorId) {
26
+ return this.activeEditors.has(editorId);
27
+ }
28
+ /** Drop every registration without running their callbacks (grid teardown). */
29
+ clear() {
30
+ this.activeEditors.clear();
31
+ }
32
+ destroy() {
33
+ this.clear();
34
+ super.destroy();
35
+ }
36
+ }
37
+ //# sourceMappingURL=formulaInputManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formulaInputManager.js","sourceRoot":"","sources":["../src/formulaInputManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoD,MAAM,mBAAmB,CAAC;AAM/F;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/B,QAAQ,GAAG,qBAA8B,CAAC;IAElD,aAAa,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEjD,oBAAoB,CAAC,QAAgB,EAAE,YAAwB;QACpE,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;QACnD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,sBAAsB,CAAC,QAAgB,EAAE,YAAwB;QACtE,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO;QAC9C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACpC,YAAY,EAAE,CAAC;IACjB,CAAC;IAEM,cAAc,CAAC,QAAgB;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,+EAA+E;IACxE,KAAK;QACV,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAEe,OAAO;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,154 @@
1
+ import { BeanStub, type AgColumn, type FormulaFunctionParams, type IFormulaService, type NamedBean } from 'ag-grid-community';
2
+ import { FormulaError, type ValidateOptions } from './expression';
3
+ type FormulaColumn = Parameters<IFormulaService['resolveValue']>[0];
4
+ type FormulaRow = Parameters<IFormulaService['resolveValue']>[1];
5
+ /**
6
+ * The canonical `formula` bean — Community's formula seam, implementing both
7
+ * gap-plan A2 (calculated columns) and gap-plan A1 (per-cell formulas).
8
+ *
9
+ * `@libregrid/calculated-columns` and `@libregrid/formulas` both declare this
10
+ * class in their module `beans` arrays; the context collects module beans into
11
+ * a `Set`, so exactly one instance serves both features regardless of
12
+ * registration order.
13
+ *
14
+ * - **Calculated-column mode** (`colDef.calculatedExpression`): same-row
15
+ * `[colId]` expressions evaluated in `ValueService.getValueFromData`
16
+ * (Phase 18 behaviour, unchanged).
17
+ * - **Per-cell mode** (`colDef.allowFormula`): `=...` strings resolved from the
18
+ * row-data field or the external `formulaDataSource` (via the
19
+ * `formulaDataSvc` bean), A1-notation references, ranges, `$` anchors,
20
+ * `formulaFuncs` custom functions, and the fill-handle offset contract
21
+ * (`updateFormulaByOffset`).
22
+ *
23
+ * `active` mirrors the docs' compatibility table: per-cell formulas are a
24
+ * Client Row Model feature — tree data, pivot mode and active row grouping
25
+ * keep the flag off so Community's soft-filter stage path never engages.
26
+ *
27
+ * @feature Formulas
28
+ */
29
+ export declare class FormulaService extends BeanStub implements IFormulaService, NamedBean {
30
+ readonly beanName: "formula";
31
+ /** Per-cell formulas active (drives Community's soft-filter + error display paths). */
32
+ active: boolean;
33
+ /** Parsed-AST cache for calculated-column expressions, keyed by column instance. */
34
+ private astCache;
35
+ /** Parsed-AST cache for per-cell formulas, keyed by the formula text itself. */
36
+ private cellAstCache;
37
+ /**
38
+ * External formula text cache (`rowId:colId` → formula string | undefined).
39
+ * `getFormula` is lazy and cached per the docs; invalidated by edits, row
40
+ * refreshes, column changes and `api.refreshFormulas()`.
41
+ */
42
+ private textCache;
43
+ /** Evaluation errors per cell, keyed `${rowId}:${colId}`. */
44
+ private cellErrors;
45
+ /** Active calculated-column resolution chain (colIds) for `#CIRCREF!`. */
46
+ private chain;
47
+ /** Active per-cell resolution chain (`rowId:colId` keys) for `#CIRCREF!`. */
48
+ private cellChain;
49
+ /** Bumped whenever the column/row layout may have changed; keys the format map. */
50
+ private formatGen;
51
+ private formatCache?;
52
+ destroy(): void;
53
+ resolveValue(column: FormulaColumn, row: FormulaRow): unknown;
54
+ /** Last evaluation error for the cell, evaluating on demand. */
55
+ getFormulaError(column: FormulaColumn, row: FormulaRow): FormulaError | null;
56
+ /** Parse-only check (dialog deferred mode + validation events). */
57
+ validateExpression(expression: string, options?: ValidateOptions): FormulaError | null;
58
+ hasCachedRows(): boolean;
59
+ isEvaluationActive(): boolean;
60
+ refreshFormulas(refreshRows: boolean): void;
61
+ refreshRow(row: FormulaRow | string): boolean;
62
+ onRowsChanged(_changedRowNodes: unknown, _newData: boolean | undefined): void;
63
+ isFormula(value: unknown): value is `=${string}`;
64
+ /**
65
+ * Column-model build hook: decides whether per-cell formulas are active and
66
+ * drops caches that depended on the previous column set.
67
+ */
68
+ setFormulasActive(colDefList: {
69
+ allowFormula?: boolean;
70
+ }[]): void;
71
+ /**
72
+ * Drop the cached external-store text for one cell. The data service calls
73
+ * this whenever a formula is written (or cleared) through
74
+ * `formulaDataSource`, so the next read — including Community's immediate
75
+ * re-evaluation inside the commit path — sees the new store entry.
76
+ */
77
+ invalidateCellFormula(row: FormulaRow, column: FormulaColumn): void;
78
+ getDataSourceFormula(row: FormulaRow, column: FormulaColumn): string | undefined;
79
+ /**
80
+ * Convert between the long-hand storage form (col/row IDs) and the shorthand
81
+ * display form (A1). `shorthand: true` converts long-hand → shorthand (the
82
+ * display/export direction Community's `useRawFormula` path uses);
83
+ * `false` converts shorthand → long-hand. Non-formulas yield `null`.
84
+ */
85
+ normaliseFormula(value: string, shorthand: boolean): string | null;
86
+ /**
87
+ * The formula text an editor should display for this cell: the external
88
+ * store's entry when a `formulaDataSource` holds it (Community routes
89
+ * formula commits into the store even for field columns), else the raw
90
+ * cell value.
91
+ */
92
+ getEditableFormula(column: FormulaColumn, row: FormulaRow): string | undefined;
93
+ getColByRef(ref: string): AgColumn | null;
94
+ getColRef(col: FormulaColumn): string | null;
95
+ /** Fill-handle/bulk-edit hook: shift a formula's relative references. */
96
+ updateFormulaByOffset(params: {
97
+ value: string;
98
+ rowDelta?: number;
99
+ columnDelta?: number;
100
+ useRefFormat?: boolean;
101
+ }): string;
102
+ private hasLongHandRef;
103
+ /**
104
+ * Grid positions of every reference in a formula, for editor range
105
+ * highlighting. Cells become 1×1 descriptors; ranges their normalised
106
+ * bounds. `[]` when the formula does not parse or the layout is unmappable.
107
+ */
108
+ formulaRangeDescriptors(formula: string): {
109
+ rowStart: number;
110
+ rowEnd: number;
111
+ columnStart: string;
112
+ columnEnd: string;
113
+ }[];
114
+ getFunction(name: string): ((params: FormulaFunctionParams) => unknown) | undefined;
115
+ getFunctionNames(): string[];
116
+ private resolveCalculated;
117
+ /** Forget a column's AST when its expression is removed (column removed). */
118
+ forgetColumn(column: AgColumn | null | undefined): void;
119
+ private getCalculatedAst;
120
+ private resolveCellFormula;
121
+ /** The cell's raw (unresolved) value: pending edit, external store, or data field. */
122
+ private rawValue;
123
+ private getCellAst;
124
+ /** Resolve one cell reference to its evaluated value. */
125
+ private resolveCellRef;
126
+ /** Resolve a rectangular range to bounds + row-major values. */
127
+ private resolveCellRange;
128
+ /** Read one cell: referenced formula cells re-resolve; plain cells read committed data. */
129
+ private readCell;
130
+ /**
131
+ * Column letters map over the displayed columns (left + centre + right,
132
+ * excluding `ag-Grid-*` service columns); row numbers map over the displayed
133
+ * rows. Rebuilt lazily whenever `formatGen` changes.
134
+ */
135
+ private format;
136
+ private formatFrom;
137
+ private formatOrNull;
138
+ private customFunction;
139
+ private builtInFunction;
140
+ /**
141
+ * Per-cell formulas are a CSR feature (docs compatibility table): server-side,
142
+ * infinite and viewport row models, tree data, pivot mode and active row
143
+ * grouping all keep `active` off.
144
+ */
145
+ private eligible;
146
+ private fail;
147
+ private columnModel;
148
+ private valueService;
149
+ private formulaDataSvc;
150
+ private key;
151
+ private storeCellError;
152
+ private clearCellError;
153
+ }
154
+ export {};