@ricsam/formula-engine 0.2.9 → 0.2.10

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.
Files changed (41) hide show
  1. package/README.md +40 -0
  2. package/dist/cjs/core/engine.cjs +37 -1
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs +151 -67
  5. package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
  6. package/dist/cjs/core/managers/workbook-manager.cjs +197 -1
  7. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  8. package/dist/cjs/core/types.cjs.map +2 -2
  9. package/dist/cjs/core/workbook-renamer.cjs.map +1 -1
  10. package/dist/cjs/evaluator/formula-evaluator.cjs +22 -48
  11. package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
  12. package/dist/cjs/functions/math/sum/summation-utils.cjs +2 -2
  13. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
  14. package/dist/cjs/package.json +1 -1
  15. package/dist/cjs/parser/formatter.cjs +3 -4
  16. package/dist/cjs/parser/formatter.cjs.map +3 -3
  17. package/dist/cjs/parser/parser.cjs +24 -216
  18. package/dist/cjs/parser/parser.cjs.map +3 -3
  19. package/dist/mjs/core/engine.mjs +37 -1
  20. package/dist/mjs/core/engine.mjs.map +3 -3
  21. package/dist/mjs/core/managers/dependency-manager.mjs +151 -67
  22. package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
  23. package/dist/mjs/core/managers/workbook-manager.mjs +197 -1
  24. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  25. package/dist/mjs/core/types.mjs.map +2 -2
  26. package/dist/mjs/core/workbook-renamer.mjs.map +1 -1
  27. package/dist/mjs/evaluator/formula-evaluator.mjs +22 -48
  28. package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
  29. package/dist/mjs/functions/math/sum/summation-utils.mjs +2 -2
  30. package/dist/mjs/functions/math/sum/summation-utils.mjs.map +2 -2
  31. package/dist/mjs/package.json +1 -1
  32. package/dist/mjs/parser/formatter.mjs +3 -4
  33. package/dist/mjs/parser/formatter.mjs.map +3 -3
  34. package/dist/mjs/parser/parser.mjs +24 -216
  35. package/dist/mjs/parser/parser.mjs.map +3 -3
  36. package/dist/types/core/engine.d.ts +15 -1
  37. package/dist/types/core/managers/dependency-manager.d.ts +4 -0
  38. package/dist/types/core/managers/workbook-manager.d.ts +23 -1
  39. package/dist/types/core/types.d.ts +35 -0
  40. package/dist/types/parser/parser.d.ts +4 -6
  41. 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";
@@ -412,6 +412,20 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
412
412
  sheetName: string;
413
413
  workbookName: string;
414
414
  }): Map<string, SerializedCellValue>;
415
+ /**
416
+ * Search raw stored string content without evaluating cell values.
417
+ */
418
+ search(query: string, options?: SearchOptions): SearchMatch[];
419
+ /**
420
+ * Replace one specific search occurrence inside one addressed cell.
421
+ */
422
+ replace(query: string, replacement: string, target: ReplaceTarget, options?: {
423
+ caseSensitive?: boolean;
424
+ }): ReplaceChange;
425
+ /**
426
+ * Replace all matching raw string occurrences within the requested scope.
427
+ */
428
+ replaceAll(query: string, replacement: string, options?: SearchOptions): ReplaceChange[];
415
429
  addWorkbook(workbookName: string): void;
416
430
  removeWorkbook(workbookName: string): void;
417
431
  /**
@@ -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;
@@ -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 [Workbook]Sheet
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]Sheet or [Workbook]Sheet!A1
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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",