@ricsam/formula-engine 0.2.9 → 0.2.11
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.
- package/README.md +40 -0
- package/dist/cjs/core/engine.cjs +79 -3
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/dependency-manager.cjs +151 -67
- package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/named-expression-manager.cjs +18 -16
- package/dist/cjs/core/managers/named-expression-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/workbook-manager.cjs +197 -1
- package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs.map +2 -2
- package/dist/cjs/core/workbook-renamer.cjs.map +1 -1
- package/dist/cjs/evaluator/formula-evaluator.cjs +22 -48
- package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
- package/dist/cjs/functions/math/sum/summation-utils.cjs +2 -2
- package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/parser/formatter.cjs +3 -4
- package/dist/cjs/parser/formatter.cjs.map +3 -3
- package/dist/cjs/parser/parser.cjs +24 -216
- package/dist/cjs/parser/parser.cjs.map +3 -3
- package/dist/mjs/core/engine.mjs +79 -3
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/dependency-manager.mjs +151 -67
- package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/named-expression-manager.mjs +18 -16
- package/dist/mjs/core/managers/named-expression-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/workbook-manager.mjs +197 -1
- package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs.map +2 -2
- package/dist/mjs/core/workbook-renamer.mjs.map +1 -1
- package/dist/mjs/evaluator/formula-evaluator.mjs +22 -48
- package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
- package/dist/mjs/functions/math/sum/summation-utils.mjs +2 -2
- package/dist/mjs/functions/math/sum/summation-utils.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/parser/formatter.mjs +3 -4
- package/dist/mjs/parser/formatter.mjs.map +3 -3
- package/dist/mjs/parser/parser.mjs +24 -216
- package/dist/mjs/parser/parser.mjs.map +3 -3
- package/dist/types/core/engine.d.ts +17 -1
- package/dist/types/core/managers/dependency-manager.d.ts +4 -0
- package/dist/types/core/managers/named-expression-manager.d.ts +1 -0
- package/dist/types/core/managers/workbook-manager.d.ts +23 -1
- package/dist/types/core/types.d.ts +35 -0
- package/dist/types/parser/parser.d.ts +4 -6
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Main FormulaEngine class
|
|
3
3
|
* Core API implementation for spreadsheet calculations
|
|
4
4
|
*/
|
|
5
|
-
import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type NamedExpression, type RangeAddress, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition } from "./types";
|
|
5
|
+
import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type NamedExpression, type RangeAddress, type ReplaceChange, type ReplaceTarget, type SearchMatch, type SearchOptions, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition } from "./types";
|
|
6
6
|
import type { FillDirection } from "@ricsam/selection-manager";
|
|
7
7
|
import { AutoFill } from "./autofill-utils";
|
|
8
8
|
import { WorkbookManager } from "./managers/workbook-manager";
|
|
@@ -55,6 +55,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
|
|
|
55
55
|
private getExistingSheetContent;
|
|
56
56
|
private getWorkbookResourceKeys;
|
|
57
57
|
private getSheetResourceKeys;
|
|
58
|
+
private assertNamedExpressionScopeExists;
|
|
58
59
|
getCellEvaluationResult(cellAddress: CellAddress): SingleEvaluationResult | undefined;
|
|
59
60
|
getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue;
|
|
60
61
|
/**
|
|
@@ -412,6 +413,20 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
|
|
|
412
413
|
sheetName: string;
|
|
413
414
|
workbookName: string;
|
|
414
415
|
}): Map<string, SerializedCellValue>;
|
|
416
|
+
/**
|
|
417
|
+
* Search raw stored string content without evaluating cell values.
|
|
418
|
+
*/
|
|
419
|
+
search(query: string, options?: SearchOptions): SearchMatch[];
|
|
420
|
+
/**
|
|
421
|
+
* Replace one specific search occurrence inside one addressed cell.
|
|
422
|
+
*/
|
|
423
|
+
replace(query: string, replacement: string, target: ReplaceTarget, options?: {
|
|
424
|
+
caseSensitive?: boolean;
|
|
425
|
+
}): ReplaceChange;
|
|
426
|
+
/**
|
|
427
|
+
* Replace all matching raw string occurrences within the requested scope.
|
|
428
|
+
*/
|
|
429
|
+
replaceAll(query: string, replacement: string, options?: SearchOptions): ReplaceChange[];
|
|
415
430
|
addWorkbook(workbookName: string): void;
|
|
416
431
|
removeWorkbook(workbookName: string): void;
|
|
417
432
|
/**
|
|
@@ -476,6 +491,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
|
|
|
476
491
|
};
|
|
477
492
|
onUpdate(listener: () => void): () => void;
|
|
478
493
|
private buildSerializedSnapshot;
|
|
494
|
+
private buildNamedExpressionSnapshot;
|
|
479
495
|
serializeEngine(): string;
|
|
480
496
|
resetToSerializedEngine(data: string): void;
|
|
481
497
|
}
|
|
@@ -59,6 +59,10 @@ export declare class DependencyManager {
|
|
|
59
59
|
private coverageWatchersBySheet;
|
|
60
60
|
private frontierWatchersBySheet;
|
|
61
61
|
constructor(cacheManager: CacheManager, workbookManager: WorkbookManager);
|
|
62
|
+
private getSnapshotEligibilityState;
|
|
63
|
+
private logSnapshotRestoreWarning;
|
|
64
|
+
private getLogicalNodeSnapshotId;
|
|
65
|
+
private resetRestoredNodeToColdState;
|
|
62
66
|
private getSheetWatcherKey;
|
|
63
67
|
private addReverseEdge;
|
|
64
68
|
private removeReverseEdge;
|
|
@@ -80,6 +80,7 @@ export declare class NamedExpressionManager {
|
|
|
80
80
|
resetNamedExpressions(namedExpressions: ReturnType<typeof this.getNamedExpressions>): void;
|
|
81
81
|
toSnapshot(): NamedExpressionManagerSnapshot;
|
|
82
82
|
restoreFromSnapshot(snapshot: NamedExpressionManagerSnapshot): void;
|
|
83
|
+
clear(): void;
|
|
83
84
|
/**
|
|
84
85
|
* When adding a sheet, we need to initialize the new maps
|
|
85
86
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CellAddress, type SerializedCellValue, type Sheet, type Workbook } from "../types";
|
|
1
|
+
import { type CellAddress, type ReplaceChange, type ReplaceTarget, type SearchMatch, type SearchOptions, type SerializedCellValue, type Sheet, type Workbook } from "../types";
|
|
2
2
|
import type { WorkbookManagerSnapshot } from "../engine-snapshot";
|
|
3
3
|
import type { RangeAddress } from "../types";
|
|
4
4
|
interface IndexEntry {
|
|
@@ -11,6 +11,18 @@ export interface SheetIndexes {
|
|
|
11
11
|
cellsSortedByRow: IndexEntry[];
|
|
12
12
|
cellsSortedByCol: IndexEntry[];
|
|
13
13
|
}
|
|
14
|
+
type PreparedReplace = {
|
|
15
|
+
address: CellAddress;
|
|
16
|
+
beforeContent: string;
|
|
17
|
+
afterContent: string;
|
|
18
|
+
change: ReplaceChange;
|
|
19
|
+
};
|
|
20
|
+
type PreparedCellReplaceAll = {
|
|
21
|
+
address: CellAddress;
|
|
22
|
+
beforeContent: string;
|
|
23
|
+
afterContent: string;
|
|
24
|
+
changes: ReplaceChange[];
|
|
25
|
+
};
|
|
14
26
|
/**
|
|
15
27
|
* Utility class for binary search operations on IndexEntry arrays
|
|
16
28
|
*/
|
|
@@ -84,6 +96,16 @@ export declare class WorkbookManager {
|
|
|
84
96
|
workbookName: string;
|
|
85
97
|
sheetName: string;
|
|
86
98
|
}): Map<string, SerializedCellValue>;
|
|
99
|
+
private resolveSearchScope;
|
|
100
|
+
private getStringContentKind;
|
|
101
|
+
private findMatchesInString;
|
|
102
|
+
private buildSearchMatchesInScope;
|
|
103
|
+
search(query: string, options?: SearchOptions): SearchMatch[];
|
|
104
|
+
private buildReplacedContent;
|
|
105
|
+
prepareReplace(query: string, replacement: string, target: ReplaceTarget, options?: {
|
|
106
|
+
caseSensitive?: boolean;
|
|
107
|
+
}): PreparedReplace;
|
|
108
|
+
prepareReplaceAll(query: string, replacement: string, options?: SearchOptions): PreparedCellReplaceAll[];
|
|
87
109
|
/**
|
|
88
110
|
* Add a cell to the grouped indexes
|
|
89
111
|
*/
|
|
@@ -80,6 +80,41 @@ export type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;
|
|
|
80
80
|
* any empty values are deleted from the sheet content
|
|
81
81
|
*/
|
|
82
82
|
export type SerializedCellValue = string | number | boolean | undefined;
|
|
83
|
+
export interface SearchOptions {
|
|
84
|
+
workbookName?: string;
|
|
85
|
+
sheetName?: string;
|
|
86
|
+
caseSensitive?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface SearchMatch {
|
|
89
|
+
workbookName: string;
|
|
90
|
+
sheetName: string;
|
|
91
|
+
cellReference: string;
|
|
92
|
+
cellContent: string;
|
|
93
|
+
contentKind: "formula" | "text";
|
|
94
|
+
occurrenceIndex: number;
|
|
95
|
+
startIndex: number;
|
|
96
|
+
endIndexExclusive: number;
|
|
97
|
+
matchedText: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ReplaceTarget {
|
|
100
|
+
workbookName: string;
|
|
101
|
+
sheetName: string;
|
|
102
|
+
cellReference: string;
|
|
103
|
+
occurrenceIndex: number;
|
|
104
|
+
}
|
|
105
|
+
export interface ReplaceChange {
|
|
106
|
+
workbookName: string;
|
|
107
|
+
sheetName: string;
|
|
108
|
+
cellReference: string;
|
|
109
|
+
contentKind: "formula" | "text";
|
|
110
|
+
occurrenceIndex: number;
|
|
111
|
+
startIndex: number;
|
|
112
|
+
endIndexExclusive: number;
|
|
113
|
+
matchedText: string;
|
|
114
|
+
replacementText: string;
|
|
115
|
+
beforeContent: string;
|
|
116
|
+
afterContent: string;
|
|
117
|
+
}
|
|
83
118
|
export interface NamedExpression {
|
|
84
119
|
name: string;
|
|
85
120
|
expression: string;
|
|
@@ -21,13 +21,15 @@ export declare class Parser {
|
|
|
21
21
|
private input;
|
|
22
22
|
constructor(tokens: Token[], input?: string);
|
|
23
23
|
/**
|
|
24
|
-
* Look ahead to determine if this is a workbook reference
|
|
24
|
+
* Look ahead to determine if this is a workbook reference like
|
|
25
|
+
* [Workbook]!Table[...] or [Workbook]Sheet...
|
|
25
26
|
*/
|
|
26
27
|
private lookAheadForWorkbookReference;
|
|
27
28
|
/**
|
|
28
|
-
* Parse workbook reference like [Workbook]
|
|
29
|
+
* Parse workbook reference like [Workbook]!Table[Column] or [Workbook]Sheet!A1
|
|
29
30
|
*/
|
|
30
31
|
private parseWorkbookReference;
|
|
32
|
+
private parseWorkbookQualifiedTableReference;
|
|
31
33
|
/**
|
|
32
34
|
* Parse bare column reference like [Column] or [Column1:Column2]
|
|
33
35
|
*/
|
|
@@ -136,10 +138,6 @@ export declare class Parser {
|
|
|
136
138
|
* Parse a range reference with workbook name
|
|
137
139
|
*/
|
|
138
140
|
private parseRangeWithWorkbook;
|
|
139
|
-
/**
|
|
140
|
-
* Parse table reference with workbook and sheet name
|
|
141
|
-
*/
|
|
142
|
-
private parseTableReferenceWithWorkbookAndSheet;
|
|
143
141
|
/**
|
|
144
142
|
* Parse a range reference (including infinite ranges)
|
|
145
143
|
*/
|